mirror of
https://github.com/janishutz/libreevent.git
synced 2025-11-25 13:24:24 +00:00
fix some things with event loading
This commit is contained in:
@@ -161,7 +161,9 @@ export default {
|
||||
}
|
||||
},
|
||||
loadTickets () {
|
||||
// TODO: Load from server
|
||||
fetch( '/getAPI/getEvent?event=' + sessionStorage.getItem( 'selectedTicket' ) ).then( res => {
|
||||
|
||||
} );
|
||||
}
|
||||
},
|
||||
created () {
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
<div class="order-app" v-if="events">
|
||||
<ul v-for="timeframe in eventList">
|
||||
<h3>{{ timeframe.name }}</h3>
|
||||
<li v-for="event in timeframe.content">
|
||||
<li v-for="event in timeframe.content" @contextmenu="( e ) => { e.preventDefault(); openRightClickMenu( event.eventID, e ); }">
|
||||
<router-link to="/admin/events/view" class="ticket" @click="setActiveTicket( event.eventID );" v-if="new Date( event.date ).getTime() > currentDate || timeframe.name === 'Drafts'">
|
||||
<div class="ticket-name">
|
||||
<h3>{{ event.name }}</h3>
|
||||
@@ -119,26 +119,29 @@
|
||||
methods: {
|
||||
loadData () {
|
||||
fetch( '/admin/getAPI/getAllEvents' ).then( res => {
|
||||
res.json().then( dat => {
|
||||
this.events = dat[ 'live' ] ?? {};
|
||||
this.eventList.drafts[ 'content' ] = dat[ 'drafts' ] ?? {};
|
||||
let sortable = [];
|
||||
for ( let event in this.events ) {
|
||||
sortable.push( [ this.events[ event ][ 'eventID' ], new Date( this.events[ event ][ 'date' ] ).getTime() ] );
|
||||
}
|
||||
sortable.sort( function( a, b ) {
|
||||
return a[ 1 ] - b[ 1 ];
|
||||
} );
|
||||
|
||||
for ( let element in sortable ) {
|
||||
if ( sortable[ element ][ 1 ] > this.currentDate ) {
|
||||
this.eventList.upcoming.content[ sortable[ element ][ 0 ] ] = this.events[ sortable[ element ][ 0 ] ];
|
||||
} else {
|
||||
this.eventList.past.content[ sortable[ element ][ 0 ] ] = this.events[ sortable[ element ][ 0 ] ];
|
||||
res.json().then( dat => {
|
||||
this.events = dat[ 'live' ] ?? {};
|
||||
this.eventList.drafts[ 'content' ] = dat[ 'drafts' ] ?? {};
|
||||
let sortable = [];
|
||||
for ( let event in this.events ) {
|
||||
sortable.push( [ this.events[ event ][ 'eventID' ], new Date( this.events[ event ][ 'date' ] ).getTime() ] );
|
||||
}
|
||||
}
|
||||
sortable.sort( function( a, b ) {
|
||||
return a[ 1 ] - b[ 1 ];
|
||||
} );
|
||||
|
||||
for ( let element in sortable ) {
|
||||
if ( this.eventList.drafts[ 'content' ][ sortable[ element ][ 0 ] ] ) {
|
||||
delete this.eventList.drafts[ 'content' ][ sortable[ element ][ 0 ] ];
|
||||
}
|
||||
if ( sortable[ element ][ 1 ] > this.currentDate ) {
|
||||
this.eventList.upcoming.content[ sortable[ element ][ 0 ] ] = this.events[ sortable[ element ][ 0 ] ];
|
||||
} else {
|
||||
this.eventList.past.content[ sortable[ element ][ 0 ] ] = this.events[ sortable[ element ][ 0 ] ];
|
||||
}
|
||||
}
|
||||
} );
|
||||
} );
|
||||
} );
|
||||
},
|
||||
openRightClickMenu( id, event ) {
|
||||
this.$refs.rclk.openRightClickMenu( event, { 'edit': { 'command': 'editEvent', 'symbol': 'edit', 'display': 'Edit event' }, 'delete': { 'command': 'deleteEvent', 'symbol': 'delete', 'display': 'Delete event' } } )
|
||||
@@ -161,12 +164,7 @@
|
||||
sessionStorage.setItem( 'selectedTicket', id );
|
||||
},
|
||||
handleData ( data ) {
|
||||
if ( this.currentPopup === 'delete' ) {
|
||||
this.currentPopup = '';
|
||||
if ( data.status === 'ok' ) {
|
||||
delete this.events[ this.currentlyOpenMenu ];
|
||||
}
|
||||
} else if ( this.currentPopup === 'add' ) {
|
||||
if ( this.currentPopup === 'add' ) {
|
||||
if ( data.status === 'ok' ) {
|
||||
const options = {
|
||||
method: 'post',
|
||||
@@ -188,10 +186,11 @@
|
||||
} );
|
||||
}
|
||||
} else if ( this.currentPopup === 'delete' ) {
|
||||
console.log( data );
|
||||
if ( data.status === 'ok' ) {
|
||||
const options = {
|
||||
method: 'post',
|
||||
body: JSON.stringify( { 'event': data.data } ),
|
||||
body: JSON.stringify( { 'event': this.currentlyOpenMenu } ),
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'charset': 'utf-8'
|
||||
@@ -199,9 +198,9 @@
|
||||
};
|
||||
fetch( localStorage.getItem( 'url' ) + '/admin/api/deleteEvent', options ).then( res => {
|
||||
if ( res.status === 200 ) {
|
||||
res.text().then( text => {
|
||||
res.text().then( () => {
|
||||
this.currentlyOpenMenu = '';
|
||||
console.log( text );
|
||||
this.loadData();
|
||||
} );
|
||||
}
|
||||
} );
|
||||
|
||||
@@ -271,35 +271,47 @@
|
||||
currency: 'USD',
|
||||
hasLiveVersion: false,
|
||||
hasSeatPlan: true,
|
||||
totalSeats: 0,
|
||||
}
|
||||
},
|
||||
created () {
|
||||
if ( !sessionStorage.getItem( 'selectedTicket' ) ) {
|
||||
this.$router.push( '/admin/events' );
|
||||
}
|
||||
this.eventID = sessionStorage.getItem( 'selectedTicket' );
|
||||
fetch( localStorage.getItem( 'url' ) + '/admin/getAPI/getLocations' ).then( res => {
|
||||
res.json().then( data => {
|
||||
this.locations = data;
|
||||
fetch( localStorage.getItem( 'url' ) + '/admin/getAPI/getEvent?event=' + this.eventID ).then( res => {
|
||||
if ( res.status === 200 ) {
|
||||
res.json().then( data => {
|
||||
this.event = data;
|
||||
this.currentLocation = this.event.location;
|
||||
this.hasSeatPlan = this.locations[ this.event.location ] ? ( this.locations[ this.event.location ][ 'seatplan-enabled' ] ?? false ) : false;
|
||||
} ).catch( error => {
|
||||
console.error( error );
|
||||
} );
|
||||
} else if ( res.status === 404 ) {
|
||||
this.$router.push( '/admin/events' );
|
||||
}
|
||||
} );
|
||||
} ).catch( error => {
|
||||
console.error( error );
|
||||
} );
|
||||
} );
|
||||
this.loadData();
|
||||
},
|
||||
methods: {
|
||||
loadData () {
|
||||
fetch( localStorage.getItem( 'url' ) + '/admin/getAPI/getCurrency' ).then( res => {
|
||||
res.text().then( currency => {
|
||||
this.currency = currency;
|
||||
} );
|
||||
} );
|
||||
if ( !sessionStorage.getItem( 'selectedTicket' ) ) {
|
||||
this.$router.push( '/admin/events' );
|
||||
}
|
||||
this.eventID = sessionStorage.getItem( 'selectedTicket' );
|
||||
fetch( localStorage.getItem( 'url' ) + '/admin/getAPI/getLocations' ).then( res => {
|
||||
res.json().then( data => {
|
||||
this.locations = data;
|
||||
fetch( localStorage.getItem( 'url' ) + '/admin/getAPI/getEvent?event=' + this.eventID ).then( res => {
|
||||
if ( res.status === 200 ) {
|
||||
res.json().then( data => {
|
||||
this.event = data;
|
||||
this.currentLocation = this.event.location;
|
||||
const dt = this.event.date.split( 'T' );
|
||||
this.event.date = dt[ 0 ];
|
||||
this.event.time = dt[ 1 ].slice( 0, dt[ 1 ].length - 1 );
|
||||
this.hasSeatPlan = this.locations[ this.event.location ] ? ( this.locations[ this.event.location ][ 'seatplan-enabled' ] ?? false ) : false;
|
||||
} ).catch( error => {
|
||||
console.error( error );
|
||||
} );
|
||||
} else if ( res.status === 404 ) {
|
||||
this.$router.push( '/admin/events' );
|
||||
}
|
||||
} );
|
||||
} ).catch( error => {
|
||||
console.error( error );
|
||||
} );
|
||||
} );
|
||||
},
|
||||
saveImages() {
|
||||
if ( this.$refs.logo.file && this.$refs.banner.file ) {
|
||||
let fd = new FormData();
|
||||
@@ -312,7 +324,9 @@
|
||||
body: fd,
|
||||
};
|
||||
fetch( localStorage.getItem( 'url' ) + '/admin/events/uploadImages?event=' + sessionStorage.getItem( 'selectedTicket' ) + '&image=' + 'logo', fetchOptions ).then( res => {
|
||||
console.log( res );
|
||||
if ( res.status === 200 ) {
|
||||
this.$refs.notification.createNotification( 'Images saved successfully!', 5, 'ok', 'normal' );
|
||||
}
|
||||
} ).catch( err => {
|
||||
console.error( err );
|
||||
} );
|
||||
@@ -328,16 +342,29 @@
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
let lowestPrice = 1000000;
|
||||
for ( let category in this.event.categories ) {
|
||||
for ( let price in this.event.categories[ category ].price ) {
|
||||
if ( this.event.categories[ category ].price[ price ] < 0.5 || ( !this.event.categories[ category ].ticketCount && this.hasSeatPlan ) ) {
|
||||
this.$refs.popups.openPopup( 'At least one of the prices for at least one of the categories is below the minimum of ' + this.currency + ' 0.5', {}, 'string' );
|
||||
return;
|
||||
}
|
||||
if ( this.event.categories[ category ].price[ price ] < lowestPrice ) {
|
||||
lowestPrice = this.event.categories[ category ].price[ price ];
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
this.event[ 'startingPrice' ] = lowestPrice;
|
||||
this.event[ 'currency' ] = this.currency;
|
||||
this.event[ 'isDraft' ] = true;
|
||||
this.event[ 'locationName' ] = this.locations[ this.event.location ].name;
|
||||
this.event[ 'hasSeatplan' ] = this.hasSeatPlan;
|
||||
const fullDate = new Date( this.event.date + 'T' + this.event.time +'Z' );
|
||||
this.event.date = fullDate.toISOString();
|
||||
if ( !this.event.maxTickets ) {
|
||||
this.event.maxTickets = this.totalSeats;
|
||||
}
|
||||
this.event.maxTickets = this.specialSettings[ 'maxTickets' ].value;
|
||||
let url = localStorage.getItem( 'url' ) + '/admin/api/saveEvent';
|
||||
if ( action === 'deploy' ) {
|
||||
@@ -354,11 +381,12 @@
|
||||
fetch( url, options ).then( res => {
|
||||
if ( res.status === 200 ) {
|
||||
if ( action === 'deploy' ) {
|
||||
this.$refs.notification.createNotification( 'Your event has been set to be live successfully!', 5, 'ok', 'normal' );
|
||||
this.$refs.notification.createNotification( 'Your event has been published successfully.', 5, 'ok', 'normal' );
|
||||
this.hasLiveVersion = true;
|
||||
} else {
|
||||
this.$refs.notification.createNotification( 'Saved as draft successfully!', 5, 'ok', 'normal' );
|
||||
}
|
||||
this.loadData();
|
||||
}
|
||||
} );
|
||||
} else {
|
||||
@@ -434,6 +462,8 @@
|
||||
res.json().then( json => {
|
||||
this.hasSeatPlan = this.locations[ this.event.location ][ 'seatplan-enabled' ] ?? false;
|
||||
this.event.categories = {};
|
||||
this.totalSeats = json.seatInfo.count;
|
||||
// TODO: Make sure ticket counting actually works from the seat plan editor
|
||||
for ( let element in json.data ) {
|
||||
if ( json.data[ element ][ 'type' ] === 'seat' || json.data[ element ][ 'type' ] === 'stand' ) {
|
||||
this.event.categories[ json.data[ element ][ 'category' ] ] = { 'price': {}, 'bg': '#FFFFFF', 'fg': '#000000', 'name': 'Category ' + json.data[ element ][ 'category' ], 'id': json.data[ element ][ 'category' ], 'ticketCount': 1 };
|
||||
|
||||
@@ -19,8 +19,8 @@
|
||||
<p>{{ event.description }}</p>
|
||||
</div>
|
||||
<div class="ticket-info">
|
||||
<p>Free seats: {{ event.freeSeats }} / {{ event.maxSeats }}</p>
|
||||
<p>{{ event.location }}, {{ event.dateString }}</p>
|
||||
<p>Free seats: {{ event.free }} / {{ event.maxTickets }}</p>
|
||||
<p>{{ event.locationName }}, {{ event.dateString }}</p>
|
||||
<h4>Starting at {{ event.currency }} {{ event.startingPrice }}</h4>
|
||||
</div>
|
||||
<img :src="event.logo" alt="event logo" class="ticket-logo">
|
||||
@@ -91,12 +91,26 @@
|
||||
methods: {
|
||||
setActiveTicket ( id ) {
|
||||
sessionStorage.setItem( 'selectedTicket', id );
|
||||
},
|
||||
loadEvents () {
|
||||
fetch( '/getAPI/getAllEvents' ).then( res => {
|
||||
res.json().then( dat => {
|
||||
this.events = dat ?? {};
|
||||
for ( let event in dat ) {
|
||||
this.events[ event ][ 'logo' ] = new URL( location.protocol + '//' + location.hostname + ':' + location.port + '/eventAssets/' + this.events[ event ].eventID + 'Logo.jpg' );
|
||||
}
|
||||
} );
|
||||
} );
|
||||
}
|
||||
},
|
||||
created() {
|
||||
this.loadEvents();
|
||||
},
|
||||
data () {
|
||||
return {
|
||||
events: { 'test':{ 'name': 'TestEvent', 'description': 'This is a description for the TestEvent to test multiline support and proper positioning of the Fields', 'freeSeats': 2, 'maxSeats': 2, 'date':'2023-08-31T09:00:00Z', 'startingPrice':15, 'location': 'TestLocation', 'eventID': 'test', 'currency': 'CHF', 'logo': new URL( '/src/assets/logo.png', import.meta.url ).href }, 'test2':{ 'name': 'TestEvent2', 'description': 'This is a description for the TestEvent to test multiline support and proper positioning of the Fields', 'freeSeats': 2, 'maxSeats': 2, 'date':'2023-08-15T09:00:00Z', 'startingPrice':15, 'location': 'TestLocation', 'eventID': 'test2', 'currency': 'CHF', 'logo': new URL( '/src/assets/logo.png', import.meta.url ).href } },
|
||||
today: new Date().getTime()
|
||||
events: { 'test':{ 'name': 'TestEvent', 'description': 'This is a description for the TestEvent to test multiline support and proper positioning of the Fields', 'free': 2, 'maxTickets': 2, 'date':'2023-08-31T09:00:00Z', 'startingPrice':15, 'location': 'TestLocation', 'eventID': 'test', 'currency': 'CHF', 'logo': new URL( '/src/assets/logo.png', import.meta.url ).href }, 'test2':{ 'name': 'TestEvent2', 'description': 'This is a description for the TestEvent to test multiline support and proper positioning of the Fields', 'freeSeats': 2, 'maxSeats': 2, 'date':'2023-08-15T09:00:00Z', 'startingPrice':15, 'location': 'TestLocation', 'eventID': 'test2', 'currency': 'CHF', 'logo': new URL( '/src/assets/logo.png', import.meta.url ).href } },
|
||||
today: new Date().getTime(),
|
||||
locations: {},
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
|
||||
Reference in New Issue
Block a user