Skip to content

Commit

Permalink
#1 refactor, fetch event info from event endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
syjer committed Mar 29, 2019
1 parent 3714ded commit cd180d5
Show file tree
Hide file tree
Showing 24 changed files with 105 additions and 31 deletions.
6 changes: 3 additions & 3 deletions src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { EventListComponent } from './event-list/event-list.component';
import { EventDisplayComponent } from './event-display/event-display.component';
import { BookingComponent } from './booking/booking.component';
import { OverviewComponent } from './overview/overview.component';
import { SuccessComponent } from './success/success.component';
import { BookingComponent } from './reservation/booking/booking.component';
import { OverviewComponent } from './reservation/overview/overview.component';
import { SuccessComponent } from './reservation/success/success.component';
import { ReservationComponent } from './reservation/reservation.component';

const routes: Routes = [
Expand Down
10 changes: 6 additions & 4 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ import { FontAwesomeModule } from '@fortawesome/angular-fontawesome';
import { library } from '@fortawesome/fontawesome-svg-core';
import { faInfoCircle, faGift, faTicketAlt } from '@fortawesome/free-solid-svg-icons'
import { faCalendarAlt, faCalendarPlus, faCalendarCheck, faCompass, faClock } from '@fortawesome/free-regular-svg-icons';
import { BookingComponent } from './booking/booking.component';
import { OverviewComponent } from './overview/overview.component';
import { SuccessComponent } from './success/success.component';
import { BookingComponent } from './reservation/booking/booking.component';
import { OverviewComponent } from './reservation/overview/overview.component';
import { SuccessComponent } from './reservation/success/success.component';
import { ReservationComponent } from './reservation/reservation.component';
import { EventHeaderComponent } from './event-header/event-header.component';

@NgModule({
declarations: [
Expand All @@ -25,7 +26,8 @@ import { ReservationComponent } from './reservation/reservation.component';
BookingComponent,
OverviewComponent,
SuccessComponent,
ReservationComponent
ReservationComponent,
EventHeaderComponent
],
imports: [
BrowserModule,
Expand Down
14 changes: 6 additions & 8 deletions src/app/event-display/event-display.component.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
<div *ngIf="event">
<app-event-header [event]="event"></app-event-header>
</div>
<div *ngIf="tmpEvent">
<div>
<img
[alt]="event.event.displayName"
[src]="event.event.fileBlobIdIsPresent ? ('/file/'+event.event.fileBlobId) : event.event.imageUrl">
<img [src]="tmpEvent.locationDescriptor.mapUrl">
</div>
<div>
<img [src]="event.locationDescriptor.mapUrl">
</div>
<form [formGroup]="reservationForm" (submit)="submitForm(event.event.shortName, reservationForm.value)">
<form [formGroup]="reservationForm" (submit)="submitForm(tmpEvent.event.shortName, reservationForm.value)">
<div>
<ul>
<li *ngFor="let category of event.ticketCategories;let counter = index"
<li *ngFor="let category of tmpEvent.ticketCategories;let counter = index"
formArrayName="reservation">
<div [formGroupName]="counter">
<p>{{category.name}}</p>
Expand Down
18 changes: 14 additions & 4 deletions src/app/event-display/event-display.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { EventService } from '../shared/event.service';
import { ActivatedRoute, Router } from '@angular/router';
import { FormGroup, FormBuilder } from '@angular/forms';
import { ReservationService } from '../shared/reservation.service';
import { Event } from '../model/event';

@Component({
selector: 'app-event-display',
Expand All @@ -11,7 +12,8 @@ import { ReservationService } from '../shared/reservation.service';
})
export class EventDisplayComponent implements OnInit {

event: any;
event: Event;
tmpEvent: any;
reservationForm: FormGroup;

//https://alligator.io/angular/reactive-forms-formarray-dynamic-fields/
Expand All @@ -25,12 +27,20 @@ export class EventDisplayComponent implements OnInit {

ngOnInit() {
this.route.params.subscribe(params => {
this.eventService.getEventTicketsInfo(params['eventShortName']).subscribe(e => {

const eventShortName = params['eventShortName'];

this.eventService.getEvent(eventShortName).subscribe(e => {
console.log(e);
this.event = e;
});

this.eventService.getEventTicketsInfo(eventShortName).subscribe(e => {
this.reservationForm = this.formBuilder.group({
reservation: this.formBuilder.array(this.createItems(e))
});
this.event = e;
})
this.tmpEvent = e;
});
})
}

Expand Down
3 changes: 3 additions & 0 deletions src/app/event-header/event-header.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div>
<img [alt]="event.displayName" [src]="event.fileBlobIdIsPresent ? ('/file/'+event.fileBlobId) : event.imageUrl">
</div>
File renamed without changes.
25 changes: 25 additions & 0 deletions src/app/event-header/event-header.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { EventHeaderComponent } from './event-header.component';

describe('EventHeaderComponent', () => {
let component: EventHeaderComponent;
let fixture: ComponentFixture<EventHeaderComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ EventHeaderComponent ]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(EventHeaderComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
19 changes: 19 additions & 0 deletions src/app/event-header/event-header.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Component, OnInit, Input } from '@angular/core';
import { Event } from '../model/event';

@Component({
selector: 'app-event-header',
templateUrl: './event-header.component.html',
styleUrls: ['./event-header.component.scss']
})
export class EventHeaderComponent implements OnInit {

@Input()
event: Event;

constructor() { }

ngOnInit() {
}

}
6 changes: 6 additions & 0 deletions src/app/model/event.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export class Event {
displayName: string;
fileBlobIdIsPresent: boolean;
fileBlobId: string;
imageUrl: string;
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component, OnInit } from '@angular/core';
import { ReservationService } from '../shared/reservation.service';
import { ReservationService } from '../../shared/reservation.service';
import { ActivatedRoute, Router } from '@angular/router';
import { FormBuilder, FormGroup } from '@angular/forms';

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { ReservationService } from '../shared/reservation.service';
import { ReservationService } from '../../shared/reservation.service';
import { FormBuilder, FormGroup } from '@angular/forms';

@Component({
Expand Down
9 changes: 4 additions & 5 deletions src/app/reservation/reservation.component.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<p>
reservation works!
</p>

<router-outlet></router-outlet>
<div *ngIf="event">
<app-event-header [event]="event"></app-event-header>
<router-outlet></router-outlet>
</div>
14 changes: 13 additions & 1 deletion src/app/reservation/reservation.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { Component, OnInit } from '@angular/core';
import { Event } from '../model/event';
import { ActivatedRoute } from '@angular/router';
import { EventService } from '../shared/event.service';

@Component({
selector: 'app-reservation',
Expand All @@ -7,9 +10,18 @@ import { Component, OnInit } from '@angular/core';
})
export class ReservationComponent implements OnInit {

constructor() { }
event: Event;

constructor(
private route: ActivatedRoute,
private eventService: EventService) { }

ngOnInit() {
this.route.params.subscribe(params => {
this.eventService.getEvent(params['eventShortName']).subscribe(event => {
this.event = event;
})
});
}

}
File renamed without changes.
Empty file.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component, OnInit } from '@angular/core';
import { ReservationService } from '../shared/reservation.service';
import { ReservationService } from '../../shared/reservation.service';
import { ActivatedRoute, Router } from '@angular/router';

@Component({
Expand Down
6 changes: 3 additions & 3 deletions src/app/shared/event.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Injectable } from '@angular/core';
import { HttpClient } from "@angular/common/http";
import { Observable } from 'rxjs';
import { Event } from '../model/event'

@Injectable({
providedIn: 'root'
Expand All @@ -13,9 +14,8 @@ export class EventService {
return this.http.get('/api/v2/public/tmp/events');
}


public getEvent(eventShortName: string): Observable<any> {
return this.http.get(`/api/v2/public/event/${eventShortName}`);
public getEvent(eventShortName: string): Observable<Event> {
return this.http.get<Event>(`/api/v2/public/event/${eventShortName}`);
}

public getEventTicketsInfo(eventShortName: string) : Observable<any> {
Expand Down

0 comments on commit cd180d5

Please sign in to comment.