add more checks

This commit is contained in:
2023-09-17 17:19:40 +02:00
parent daba3332e8
commit cd9d6d5027
5 changed files with 189 additions and 5 deletions

View File

@@ -92,6 +92,66 @@ export default {
} }
} }
}, },
seatChecks () {
let self = this;
let allSeatsAvailable = true;
fetch( localStorage.getItem( 'url' ) + '/getAPI/getReservedSeats?event=' + this.event.eventID ).then( res => {
if ( res.status === 200 ) {
let unavailableSeats = {};
res.json().then( data => {
for ( let seat in data.reserved ) {
if ( data.reserved[ seat ] ) {
if ( !unavailableSeats[ data.reserved[ seat ].component ] ) {
unavailableSeats[ data.reserved[ seat ].component ] = {};
}
unavailableSeats[ data.reserved[ seat ].component ][ data.reserved[ seat ].id ] = 'nav';
}
}
for ( let seat in data.user ) {
if ( data.user[ seat ] ) {
if ( !unavailableSeats[ data.user[ seat ].component ] ) {
unavailableSeats[ data.user[ seat ].component ] = {};
}
unavailableSeats[ data.user[ seat ].component ][ data.user[ seat ].id ] = 'sel';
}
}
let tickets = {};
if ( this.cart[ this.event.eventID ] ) {
tickets = this.cart[ this.event.eventID ][ 'tickets' ];
}
if ( data.user ) {
for ( let element in tickets ) {
if ( !data.user[ element ] ) {
allSeatsAvailable = false;
if ( Object.keys( this.cart[ this.event.eventID ][ 'tickets' ] ).length > 1 ) {
delete this.cart[ this.event.eventID ][ 'tickets' ][ element ];
} else {
delete this.cart[ this.event.eventID ];
}
}
}
} else {
delete this.cart[ this.event.eventID ];
allSeatsAvailable = false;
}
this.unavailableSeats = unavailableSeats;
if ( !allSeatsAvailable ) {
setTimeout( () => {
self.$refs.popups.openPopup( 'We are sorry to tell you that since the last time the seat plan was refreshed, one or more of the seats you have selected has/have been taken.', {}, 'string' );
}, 500 );
localStorage.setItem( 'cart', JSON.stringify( this.cart ) );
}
} );
} else {
console.error( 'unable to load' );
}
} );
},
cartHandling () { cartHandling () {
for ( let ticket in this.selectedTickets ) { for ( let ticket in this.selectedTickets ) {
let category = ''; let category = '';
@@ -183,6 +243,7 @@ export default {
}, 1 ); }, 1 );
this.cart = localStorage.getItem( 'cart' ) ? JSON.parse( localStorage.getItem( 'cart' ) ): {}; this.cart = localStorage.getItem( 'cart' ) ? JSON.parse( localStorage.getItem( 'cart' ) ): {};
this.loadTickets(); this.loadTickets();
this.seatChecks();
} }
} }
</script> </script>

View File

@@ -105,7 +105,6 @@ export default {
this.style += ` background-color: ${this.color}; color: ${this.color}`; this.style += ` background-color: ${this.color}; color: ${this.color}`;
this.circularStyle += ` background-color: ${this.color}; color: ${this.color}`; this.circularStyle += ` background-color: ${this.color}; color: ${this.color}`;
this.trapezoidStyle += ` background-color: ${this.color}; color: ${this.color}`; this.trapezoidStyle += ` background-color: ${this.color}; color: ${this.color}`;
console.log( this.style );
}, },
}, },
watch: { watch: {

View File

@@ -147,7 +147,6 @@
} ); } );
}, },
prepSeatplan ( seatInfo ) { prepSeatplan ( seatInfo ) {
console.log( seatInfo );
// Mark all selected seats + all unavailable seats // Mark all selected seats + all unavailable seats
let categoryDetails = {}; let categoryDetails = {};
for ( let category in this.event.categories ) { for ( let category in this.event.categories ) {

View File

@@ -139,8 +139,65 @@
} }
localStorage.setItem( 'cart', JSON.stringify( this.cart ) ); localStorage.setItem( 'cart', JSON.stringify( this.cart ) );
}, },
logs ( message ) { seatChecks ( event ) {
console.log( message ); let self = this;
let allSeatsAvailable = true;
fetch( localStorage.getItem( 'url' ) + '/getAPI/getReservedSeats?event=' + event ).then( res => {
if ( res.status === 200 ) {
let unavailableSeats = {};
res.json().then( data => {
for ( let seat in data.reserved ) {
if ( data.reserved[ seat ] ) {
if ( !unavailableSeats[ data.reserved[ seat ].component ] ) {
unavailableSeats[ data.reserved[ seat ].component ] = {};
}
unavailableSeats[ data.reserved[ seat ].component ][ data.reserved[ seat ].id ] = 'nav';
}
}
for ( let seat in data.user ) {
if ( data.user[ seat ] ) {
if ( !unavailableSeats[ data.user[ seat ].component ] ) {
unavailableSeats[ data.user[ seat ].component ] = {};
}
unavailableSeats[ data.user[ seat ].component ][ data.user[ seat ].id ] = 'sel';
}
}
let tickets = {};
if ( this.cart[ event ] ) {
tickets = this.cart[ event ][ 'tickets' ];
}
if ( data.user ) {
for ( let element in tickets ) {
if ( !data.user[ element ] ) {
allSeatsAvailable = false;
if ( Object.keys( this.cart[ event ][ 'tickets' ] ).length > 1 ) {
delete this.cart[ event ][ 'tickets' ][ element ];
} else {
delete this.cart[ event ];
}
}
}
} else {
delete this.cart[ event ];
allSeatsAvailable = false;
}
this.unavailableSeats = unavailableSeats;
if ( !allSeatsAvailable ) {
setTimeout( () => {
self.$refs.popups.openPopup( 'We are sorry to tell you that since the last time the seat plan was refreshed, one or more of the seats you have selected has/have been taken.', {}, 'string' );
}, 500 );
localStorage.setItem( 'cart', JSON.stringify( this.cart ) );
}
} );
} else {
console.error( 'unable to load' );
}
} );
}, },
}, },
created () { created () {
@@ -150,6 +207,9 @@
}, 1 ); }, 1 );
this.cart = localStorage.getItem( 'cart' ) ? JSON.parse( localStorage.getItem( 'cart' ) ): {}; this.cart = localStorage.getItem( 'cart' ) ? JSON.parse( localStorage.getItem( 'cart' ) ): {};
this.calculateTotal(); this.calculateTotal();
for ( let event in this.cart ) {
this.seatChecks( event );
}
} }
} }
</script> </script>

View File

@@ -76,6 +76,7 @@
</div> </div>
</div> </div>
<notifications ref="notification" location="topleft" size="bigger"></notifications> <notifications ref="notification" location="topleft" size="bigger"></notifications>
<popups ref="popups" size="small" @data="data => { verifyTicketDelete( data.status ) }"></popups>
</div> </div>
</template> </template>
@@ -216,6 +217,7 @@ import { useUserStore } from '@/stores/userStore';
import { useBackendStore } from '@/stores/backendStore'; import { useBackendStore } from '@/stores/backendStore';
import { mapStores } from 'pinia'; import { mapStores } from 'pinia';
import notifications from '@/components/notifications/notifications.vue'; import notifications from '@/components/notifications/notifications.vue';
import popups from '@/components/notifications/popups.vue';
export default { export default {
name: 'PurchaseView', name: 'PurchaseView',
@@ -231,6 +233,7 @@ export default {
}, },
components: { components: {
notifications, notifications,
popups,
}, },
computed: { computed: {
...mapStores( useUserStore ), ...mapStores( useUserStore ),
@@ -238,7 +241,6 @@ export default {
}, },
methods: { methods: {
loadData () { loadData () {
// TODO: FUTURE Also load the customer data from server!
this.cartNotEmpty = false; this.cartNotEmpty = false;
let cart = JSON.parse( localStorage.getItem( 'cart' ) ); let cart = JSON.parse( localStorage.getItem( 'cart' ) );
@@ -256,6 +258,69 @@ export default {
} else { } else {
this.$router.push( '/tickets' ); this.$router.push( '/tickets' );
} }
for ( let event in this.cart ) {
this.seatChecks( event );
}
},
seatChecks ( event ) {
let self = this;
let allSeatsAvailable = true;
fetch( localStorage.getItem( 'url' ) + '/getAPI/getReservedSeats?event=' + event ).then( res => {
if ( res.status === 200 ) {
let unavailableSeats = {};
res.json().then( data => {
for ( let seat in data.reserved ) {
if ( data.reserved[ seat ] ) {
if ( !unavailableSeats[ data.reserved[ seat ].component ] ) {
unavailableSeats[ data.reserved[ seat ].component ] = {};
}
unavailableSeats[ data.reserved[ seat ].component ][ data.reserved[ seat ].id ] = 'nav';
}
}
for ( let seat in data.user ) {
if ( data.user[ seat ] ) {
if ( !unavailableSeats[ data.user[ seat ].component ] ) {
unavailableSeats[ data.user[ seat ].component ] = {};
}
unavailableSeats[ data.user[ seat ].component ][ data.user[ seat ].id ] = 'sel';
}
}
let tickets = {};
if ( this.cart[ event ] ) {
tickets = this.cart[ event ][ 'tickets' ];
}
if ( data.user ) {
for ( let element in tickets ) {
if ( !data.user[ element ] ) {
allSeatsAvailable = false;
if ( Object.keys( this.cart[ event ][ 'tickets' ] ).length > 1 ) {
delete this.cart[ event ][ 'tickets' ][ element ];
} else {
delete this.cart[ event ];
}
}
}
} else {
delete this.cart[ event ];
allSeatsAvailable = false;
}
this.unavailableSeats = unavailableSeats;
if ( !allSeatsAvailable ) {
setTimeout( () => {
self.$refs.popups.openPopup( 'We are sorry to tell you that an error occurred in the system and all sessions have been reset. You will need to pick the seats again. We are very sorry for the inconvenience', {}, 'string' );
}, 500 );
localStorage.setItem( 'cart', JSON.stringify( this.cart ) );
}
} );
} else {
console.error( 'unable to load' );
}
} );
}, },
calculateTotal () { calculateTotal () {
this.backend[ 'total' ] = 0; this.backend[ 'total' ] = 0;