Skip to content

Commit

Permalink
Merge pull request #359 from intersective/task/av2-292/Event-single-b…
Browse files Browse the repository at this point in the history
…ooking-feature

Task/av2 292/event single booking feature
  • Loading branch information
shawnm0705 authored Apr 17, 2019
2 parents 9a56119 + 86312f9 commit 84033f9
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 19 deletions.
63 changes: 48 additions & 15 deletions src/app/event-detail/event-detail.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,25 @@ export class EventDetailComponent {
confirmed() {
switch (this.buttonText()) {
case 'Book':
this.eventDetailService.bookEvent(this.event).subscribe(response => {
if (response.success) {
this.notificationService.alert({
message: 'Booked Successfully!',
buttons: [
{
text: 'OK',
role: 'cancel'
if (this.event.singleBooking) {
this.notificationService.alert({
message: 'Booking this event will cancel your booking for other events within the same activity, do you still wanna book?',
buttons: [
{
text: 'OK',
handler: () => {
this._bookEvent();
}
]
});
// update the event list & activity detail page
this.utils.broadcastEvent('update-event', null);
}
});
},
{
text: 'Cancel',
role: 'cancel'
}
]
});
} else {
this._bookEvent();
}
break;

case 'Cancel Booking':
Expand Down Expand Up @@ -67,10 +71,39 @@ export class EventDetailComponent {
this.modalController.dismiss();
}

private _bookEvent() {
this.eventDetailService.bookEvent(this.event).subscribe(
response => {
this.notificationService.alert({
message: 'Booked Successfully!',
buttons: [
{
text: 'OK',
role: 'cancel'
}
]
});
// update the event list & activity detail page
this.utils.broadcastEvent('update-event', null);
},
error => {
this.notificationService.alert({
message: 'Booking failed, please try again later!',
buttons: [
{
text: 'OK',
role: 'cancel'
}
]
});
}
);
}

buttonText() {
// for not booked event
if (!this.event.isBooked) {
if (!this.event.isPast && this.event.remainingCapacity > 0) {
if (!this.event.isPast && this.event.remainingCapacity > 0 && this.event.canBook) {
return 'Book';
}
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/app/event-detail/event-detail.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class EventDetailService {
bookEvent(event: Event) {
return this.request.post(api.post.book, {
event_id: event.id,
delete_previous: 'no'
delete_previous: event.singleBooking
});
}

Expand Down
8 changes: 6 additions & 2 deletions src/app/events/events.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ export class EventsComponent extends RouterEnter {
// group all past events as one group named "Expired"
if (compareDate !== 'Expired') {
compareDate = 'Expired';
events.push(eventGroup);
if (!this.utils.isEmpty(eventGroup.events)) {
events.push(eventGroup);
}
eventGroup = {
date: compareDate,
events: []
Expand All @@ -146,7 +148,9 @@ export class EventsComponent extends RouterEnter {
eventGroup.events.push(event);
} else {
// create a new group for this date
events.push(eventGroup);
if (!this.utils.isEmpty(eventGroup.events)) {
events.push(eventGroup);
}
compareDate = this.utils.utcToLocal(event.startTime, 'date');
eventGroup = {
date: compareDate,
Expand Down
8 changes: 7 additions & 1 deletion src/app/events/events.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export interface Event {
capacity: number;
remainingCapacity: number;
isBooked: boolean;
singleBooking: boolean;
canBook: boolean;
isPast?: boolean;
assessment?: {
id: number;
Expand Down Expand Up @@ -93,7 +95,9 @@ export class EventsService {
!this.utils.has(event, 'end') ||
!this.utils.has(event, 'capacity') ||
!this.utils.has(event, 'remaining_capacity') ||
!this.utils.has(event, 'is_booked')) {
!this.utils.has(event, 'is_booked') ||
!this.utils.has(event, 'can_book') ||
!this.utils.has(event, 'single_booking')) {
return this.request.apiResponseFormatError('Event object format error');
}
events.push({
Expand All @@ -108,6 +112,8 @@ export class EventsService {
capacity: event.capacity,
remainingCapacity: event.remaining_capacity,
isBooked: event.is_booked,
singleBooking: event.single_booking,
canBook: event.can_book,
isPast: this.utils.timeComparer(event.start) < 0,
assessment: this.utils.has(event, 'assessment.id') ? {
id: event.assessment.id,
Expand Down

0 comments on commit 84033f9

Please sign in to comment.