From b60bf5a377bbf1e675390db77e79bee89ed07384 Mon Sep 17 00:00:00 2001 From: Roland Schneider Date: Thu, 11 Jul 2019 16:32:17 +0200 Subject: [PATCH] add events page to customer frontend --- .../fit-event-types.component.html | 27 ++++++++ .../fit-event-types.component.scss | 8 +++ .../fit-event-types.component.spec.ts | 25 +++++++ .../fit-event-types.component.ts | 68 +++++++++++++++++++ .../app/src/app/services/event.service.ts | 45 ++++++++++++ .../src/app/services/reservation.service.ts | 12 ++++ 6 files changed, 185 insertions(+) create mode 100644 customer/app/src/app/components/fit-event-types/fit-event-types.component.html create mode 100644 customer/app/src/app/components/fit-event-types/fit-event-types.component.scss create mode 100644 customer/app/src/app/components/fit-event-types/fit-event-types.component.spec.ts create mode 100644 customer/app/src/app/components/fit-event-types/fit-event-types.component.ts create mode 100644 customer/app/src/app/services/event.service.ts create mode 100644 customer/app/src/app/services/reservation.service.ts diff --git a/customer/app/src/app/components/fit-event-types/fit-event-types.component.html b/customer/app/src/app/components/fit-event-types/fit-event-types.component.html new file mode 100644 index 0000000..bc32f41 --- /dev/null +++ b/customer/app/src/app/components/fit-event-types/fit-event-types.component.html @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/customer/app/src/app/components/fit-event-types/fit-event-types.component.scss b/customer/app/src/app/components/fit-event-types/fit-event-types.component.scss new file mode 100644 index 0000000..b33e18e --- /dev/null +++ b/customer/app/src/app/components/fit-event-types/fit-event-types.component.scss @@ -0,0 +1,8 @@ +select.form-control{ + border: 1px solid #e5ce48; + background-color: black; + color: #e5ce48; + option:hover{ + background-color: #e5ce48; + } +} diff --git a/customer/app/src/app/components/fit-event-types/fit-event-types.component.spec.ts b/customer/app/src/app/components/fit-event-types/fit-event-types.component.spec.ts new file mode 100644 index 0000000..712e439 --- /dev/null +++ b/customer/app/src/app/components/fit-event-types/fit-event-types.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { FitEventTypesComponent } from './fit-event-types.component'; + +describe('FitEventTypesComponent', () => { + let component: FitEventTypesComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ FitEventTypesComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(FitEventTypesComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/customer/app/src/app/components/fit-event-types/fit-event-types.component.ts b/customer/app/src/app/components/fit-event-types/fit-event-types.component.ts new file mode 100644 index 0000000..8c7632c --- /dev/null +++ b/customer/app/src/app/components/fit-event-types/fit-event-types.component.ts @@ -0,0 +1,68 @@ +import {Component, forwardRef, OnInit} from '@angular/core'; +import {EventService, EventType} from "../../services/event.service"; +import {ControlValueAccessor, FormControl, FormGroup, NG_VALUE_ACCESSOR} from "@angular/forms"; + +const FIT_EVENT_TYPES_VALUE_ACCESSOR: any = { + provide: NG_VALUE_ACCESSOR, + useExisting: forwardRef(() => FitEventTypesComponent), + multi: true, +}; + +@Component({ + selector: 'app-fit-event-types', + templateUrl: './fit-event-types.component.html', + styleUrls: ['./fit-event-types.component.scss'], + providers: [FIT_EVENT_TYPES_VALUE_ACCESSOR], + +}) +export class FitEventTypesComponent implements OnInit, ControlValueAccessor { + + types: EventType[]; + selected: any; + + private onChange: Function; + private onTouched: Function; + + private value: string; + + + constructor(private eventService: EventService) { + this.onChange = (_: any) => { }; + this.onTouched = () => { }; + } + + ngOnInit() { + this.eventService.findAllEventTypes() + .subscribe(value => { + this.types = [{ id: -1, name: 'Minden Típus'}].concat( value); + this._setValue(this.types[0].id); + } + ); + } + + private _setValue(value) { + this.value = value; + this.onChange(this.value); + this.onTouched(); + } + + setValue($event: Event) { + console.info($event); + this._setValue(($event.target).value); + } + + registerOnChange(fn: any): void { + this.onChange = fn; + } + + registerOnTouched(fn: any): void { + this.onTouched = fn; + } + + setDisabledState(isDisabled: boolean): void { + } + + writeValue(obj: any): void { + this.value = obj; + } +} diff --git a/customer/app/src/app/services/event.service.ts b/customer/app/src/app/services/event.service.ts new file mode 100644 index 0000000..1e4c210 --- /dev/null +++ b/customer/app/src/app/services/event.service.ts @@ -0,0 +1,45 @@ +import { Injectable } from '@angular/core'; +import {HttpClient} from "@angular/common/http"; +import {Endpoints} from "./endpoints"; +import {Observable} from "rxjs"; + +@Injectable({ + providedIn: 'root' +}) +export class EventService { + + constructor(private http: HttpClient) { } + + findAllEventTypes(): Observable{ + return this.http.get(Endpoints.GET_EVENT_TYPES()) as Observable; + } + + findEvents(idEventType?:number): Observable { + return this.http.get(Endpoints.GET_EVENTS(idEventType)) as Observable; + } + +} + +export interface Trainer { + id: number; + name: string; +} + +export interface Event { + id: number; + name: string; + start: number; + end: number; + trainer?: Trainer; + seatCount: number; + reservationCount: number; + eventType: EventType; + reservedAt: number; +} + +export interface EventType { + id: number; + name: string; +} + + diff --git a/customer/app/src/app/services/reservation.service.ts b/customer/app/src/app/services/reservation.service.ts new file mode 100644 index 0000000..60ba9c2 --- /dev/null +++ b/customer/app/src/app/services/reservation.service.ts @@ -0,0 +1,12 @@ +import { Injectable } from '@angular/core'; +import {HttpClient} from "@angular/common/http"; + +@Injectable({ + providedIn: 'root' +}) +export class ReservationService { + + constructor(private http: HttpClient) { } + + +}