other transport medium is saved locally and remotely
This commit is contained in:
1 parent
99fbe44d5a
commit
6f79590ec2
5 files changed
+195
-134
No files matched your search
@@ -152,19 +152,11 @@ export class CoronatransportPage implements OnInit {
|
||||
* @param id unique id of the selected bus.
|
||||
*/
|
||||
public selectArrivalBusSchedule(id: number) {
|
||||
if (!this.busService.isBusSelected(this.date, BusDirection.ToPSI)) {
|
||||
this.busService.selectBusAsync(this.date, id, BusDirection.ToPSI)
|
||||
.then(_ => {
|
||||
this.updateSelection();
|
||||
this.loadBusesStatus();
|
||||
}).catch(error => SoapApiHelper.handleError(this.toastController, error));
|
||||
} else {
|
||||
this.busService.changeSelectionAsync(this.date, id, BusDirection.ToPSI)
|
||||
.then(_ => {
|
||||
this.updateSelection();
|
||||
this.loadBusesStatus();
|
||||
}).catch(error => SoapApiHelper.handleError(this.toastController, error));
|
||||
}
|
||||
this.busService.selectBusAsync(this.date, id, BusDirection.ToPSI)
|
||||
.then(_ => {
|
||||
this.updateSelection();
|
||||
this.loadBusesStatus();
|
||||
}).catch(error => SoapApiHelper.handleError(this.toastController, error));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -173,19 +165,11 @@ export class CoronatransportPage implements OnInit {
|
||||
* @param id unique id of the selected bus.
|
||||
*/
|
||||
public selectDepartureBusSchedule(id: number) {
|
||||
if (!this.busService.isBusSelected(this.date, BusDirection.FromPSI)) {
|
||||
this.busService.selectBusAsync(this.date, id, BusDirection.FromPSI)
|
||||
.then(_ => {
|
||||
this.updateSelection();
|
||||
this.loadBusesStatus();
|
||||
}).catch(error => SoapApiHelper.handleError(this.toastController, error));
|
||||
} else {
|
||||
this.busService.changeSelectionAsync(this.date, id, BusDirection.FromPSI)
|
||||
.then(_ => {
|
||||
this.updateSelection();
|
||||
this.loadBusesStatus();
|
||||
}).catch(error => SoapApiHelper.handleError(this.toastController, error));
|
||||
}
|
||||
this.busService.selectBusAsync(this.date, id, BusDirection.FromPSI)
|
||||
.then(_ => {
|
||||
this.updateSelection();
|
||||
this.loadBusesStatus();
|
||||
}).catch(error => SoapApiHelper.handleError(this.toastController, error));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -217,18 +201,22 @@ export class CoronatransportPage implements OnInit {
|
||||
let arrivalSelection = this.getArrivalSelection();
|
||||
if (arrivalSelection) {
|
||||
let bus = this.getArrivalBus(arrivalSelection.id);
|
||||
let startDate = new Date(this.date.toDateString() + ' ' + bus.start_time);
|
||||
this.arrivalForm.controls['time'].setValue(startDate.toISOString());
|
||||
this.arrivalForm.controls['from'].setValue(bus.start_station);
|
||||
this.arrivalForm.controls['to'].setValue('e');
|
||||
if (bus) {
|
||||
let startDate = new Date(this.date.toDateString() + ' ' + bus.start_time);
|
||||
this.arrivalForm.controls['time'].setValue(startDate.toISOString());
|
||||
this.arrivalForm.controls['from'].setValue(bus.start_station);
|
||||
this.arrivalForm.controls['to'].setValue('e');
|
||||
}
|
||||
}
|
||||
let departureSelection = this.getDepartureSelection();
|
||||
if (departureSelection) {
|
||||
let bus = this.getDepartureBus(departureSelection.id);
|
||||
let startDate = new Date(this.date.toDateString() + ' ' + bus.start_time_east);
|
||||
this.departureForm.controls['time'].setValue(startDate.toISOString());
|
||||
this.departureForm.controls['from'].setValue('e');
|
||||
this.departureForm.controls['to'].setValue(bus.end_station);
|
||||
if (bus) {
|
||||
let startDate = new Date(this.date.toDateString() + ' ' + bus.start_time_east);
|
||||
this.departureForm.controls['time'].setValue(startDate.toISOString());
|
||||
this.departureForm.controls['from'].setValue('e');
|
||||
this.departureForm.controls['to'].setValue(bus.end_station);
|
||||
}
|
||||
}
|
||||
this.filterBusschedule();
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
<ion-button size="small" slot="start" fill="clear" color="dark" (click)="presentHelpModal()">
|
||||
<ion-icon name="help-circle-outline"></ion-icon>
|
||||
</ion-button>
|
||||
<img alt="PSI logo" slot="end" class="titleicon" [src]="assets + '/psi_logo.svg'" width="80px" routerLink="/home"/>
|
||||
<img alt="PSI logo" slot="end" class="titleicon" [src]="assets + '/psi_logo.svg'" width="80px" routerLink="/home" />
|
||||
</ion-toolbar>
|
||||
</ion-header>
|
||||
|
||||
@@ -25,11 +25,13 @@
|
||||
</ion-card-header>
|
||||
<ion-card-content>
|
||||
<h3>Please choose an option bellow</h3>
|
||||
<ion-button [color]="allSelectionsCheckedToday ? 'success' : 'dark'" fill="outline" (click)="selectDay('today');goToSlide(1)">
|
||||
<ion-button [color]="allSelectionsCheckedToday ? 'success' : 'dark'" fill="outline"
|
||||
(click)="selectDay('today');goToSlide(1)">
|
||||
Today
|
||||
<ion-icon *ngIf="allSelectionsCheckedToday" name="checkmark"></ion-icon>
|
||||
</ion-button>
|
||||
<ion-button [color]="allSelectionsCheckedTomorrow ? 'success' : 'dark'" fill="outline" (click)="selectDay('tomorrow');goToSlide(1)">
|
||||
<ion-button [color]="allSelectionsCheckedTomorrow ? 'success' : 'dark'" fill="outline"
|
||||
(click)="selectDay('tomorrow');goToSlide(1)">
|
||||
Tomorrow
|
||||
<ion-icon *ngIf="allSelectionsCheckedTomorrow" name="checkmark"></ion-icon>
|
||||
</ion-button>
|
||||
@@ -50,7 +52,7 @@
|
||||
<h3>Please choose an option bellow</h3>
|
||||
<ion-button fill="outline" color="dark" (click)="presentTransportModal()">Public Transport
|
||||
</ion-button>
|
||||
<ion-button fill="outline" color="dark" (click)="goToSlide(2)">Other</ion-button>
|
||||
<ion-button fill="outline" color="dark" (click)="selectOther()">Other</ion-button>
|
||||
</ion-card-content>
|
||||
</ion-card>
|
||||
</ion-slide>
|
||||
@@ -77,4 +79,4 @@
|
||||
</ion-card>
|
||||
</ion-slide>
|
||||
</ion-slides>
|
||||
</ion-content>
|
||||
</ion-content>
|
||||
@@ -1,14 +1,15 @@
|
||||
import {Component, OnInit, ViewChild} from '@angular/core';
|
||||
import {IonSlides, ModalController, ToastController} from '@ionic/angular';
|
||||
import {environment} from '../../../environments/environment';
|
||||
import {CoronarestaurantPage} from '../coronarestaurant/coronarestaurant.page';
|
||||
import {CoronatransportPage} from '../coronatransport/coronatransport.page';
|
||||
import {FormBuilder, FormGroup, Validators} from '@angular/forms';
|
||||
import {Restaurant} from 'src/app/interfaces/catering-schedule';
|
||||
import {JsonFormatter} from 'tslint/lib/formatters';
|
||||
import {CoronaCateringService} from '../../services/corona-catering.service';
|
||||
import {CoronaBusService} from '../../services/corona-bus.service';
|
||||
import { Component, OnInit, ViewChild } from '@angular/core';
|
||||
import { IonSlides, ModalController, ToastController } from '@ionic/angular';
|
||||
import { environment } from '../../../environments/environment';
|
||||
import { CoronarestaurantPage } from '../coronarestaurant/coronarestaurant.page';
|
||||
import { CoronatransportPage } from '../coronatransport/coronatransport.page';
|
||||
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
|
||||
import { Restaurant } from 'src/app/interfaces/catering-schedule';
|
||||
import { JsonFormatter } from 'tslint/lib/formatters';
|
||||
import { CoronaCateringService } from '../../services/corona-catering.service';
|
||||
import { CoronaBusService } from '../../services/corona-bus.service';
|
||||
import { CoronahelppageComponent } from 'src/app/components/coronahelppage/coronahelppage.component';
|
||||
import { SoapApiHelper } from 'src/app/classes/api-helper';
|
||||
|
||||
|
||||
@Component({
|
||||
@@ -29,10 +30,10 @@ export class PsicheckinPage implements OnInit {
|
||||
public allSelectionsCheckedTomorrow: boolean;
|
||||
|
||||
constructor(private toastController: ToastController,
|
||||
private _FB: FormBuilder,
|
||||
private modalController: ModalController,
|
||||
private cateringService: CoronaCateringService,
|
||||
private transportService: CoronaBusService) {
|
||||
private _FB: FormBuilder,
|
||||
private modalController: ModalController,
|
||||
private cateringService: CoronaCateringService,
|
||||
private transportService: CoronaBusService) {
|
||||
this.userGuidance = _FB.group({
|
||||
'date': ['', Validators.required]
|
||||
});
|
||||
@@ -65,10 +66,10 @@ export class PsicheckinPage implements OnInit {
|
||||
backdropDismiss: false
|
||||
});
|
||||
modal.onDidDismiss()
|
||||
.then((data) => {
|
||||
let slide = data.data;
|
||||
this.goToSlide(slide);
|
||||
});
|
||||
.then((data) => {
|
||||
let slide = data.data;
|
||||
this.goToSlide(slide);
|
||||
});
|
||||
return await modal.present();
|
||||
}
|
||||
|
||||
@@ -82,13 +83,13 @@ export class PsicheckinPage implements OnInit {
|
||||
backdropDismiss: false
|
||||
});
|
||||
let promise = modal.onDidDismiss()
|
||||
.then((data) => {
|
||||
let cateringSelection = this.cateringService.getSelection(this.selectedDate);
|
||||
if (cateringSelection != undefined) {
|
||||
let slide = data.data;
|
||||
this.goToSlide(slide);
|
||||
}
|
||||
});
|
||||
.then((data) => {
|
||||
let cateringSelection = this.cateringService.getSelection(this.selectedDate);
|
||||
if (cateringSelection != undefined) {
|
||||
let slide = data.data;
|
||||
this.goToSlide(slide);
|
||||
}
|
||||
});
|
||||
return await modal.present();
|
||||
}
|
||||
|
||||
@@ -108,6 +109,12 @@ export class PsicheckinPage implements OnInit {
|
||||
}
|
||||
}
|
||||
|
||||
public selectOther(): void {
|
||||
this.transportService.selectOtherAsync(this.selectedDate)
|
||||
.then(_ => this.goToSlide(2))
|
||||
.catch(error => SoapApiHelper.handleError(this.toastController, error));
|
||||
}
|
||||
|
||||
async presentHelpModal() {
|
||||
const modal = await this.modalController.create({
|
||||
component: CoronahelppageComponent
|
||||
|
||||
@@ -3,9 +3,9 @@ import { HttpClient, HttpHeaders } from '@angular/common/http';
|
||||
import { BusInformationDTO, BusSelection, BusDirection, BusInformation, BusStatus } from '../interfaces/bus-schedule';
|
||||
import { Observable } from 'rxjs';
|
||||
import { environment } from 'src/environments/environment';
|
||||
import { map, switchMap } from 'rxjs/operators';
|
||||
import { map, switchMap, subscribeOn } from 'rxjs/operators';
|
||||
import { SoapApiHelper } from '../classes/api-helper';
|
||||
import {TimeframeSelection} from '../interfaces/catering-schedule';
|
||||
import { TimeframeSelection } from '../interfaces/catering-schedule';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -26,57 +26,69 @@ export class CoronaBusService {
|
||||
public async selectBusAsync(date: Date, id: number, direction: BusDirection): Promise<any> {
|
||||
date = new Date(date.toDateString());
|
||||
return new Promise<any>((resolve, reject) => {
|
||||
if (this.isBusSelected(date, direction)) {
|
||||
reject('A bus is already selected for this date and direction.');
|
||||
return;
|
||||
}
|
||||
|
||||
this.addPersonToBus(date, id)
|
||||
.subscribe(
|
||||
_ => {
|
||||
if (this.isOtherSelected(date)) {
|
||||
this.removePersonToNonBus(date)
|
||||
.subscribe(_ => {
|
||||
this.addPersonToBus(date, id)
|
||||
.subscribe(__ => {
|
||||
this.removeSelection(date, BusDirection.ToPSI);
|
||||
this.removeSelection(date, BusDirection.FromPSI);
|
||||
this.saveSelection(date, id, direction);
|
||||
resolve();
|
||||
}, error => reject(error));
|
||||
}, error => reject(error));
|
||||
} else if (this.isBusSelected(date, direction)) {
|
||||
let selected = this.loadSelections().find(bus => bus.date.getTime() === date.getTime() && bus.direction === direction);
|
||||
this.removePersonToBus(date, selected.id)
|
||||
.subscribe(_ => {
|
||||
this.addPersonToBus(date, id)
|
||||
.subscribe(__ => {
|
||||
this.saveSelection(date, id, direction);
|
||||
resolve();
|
||||
}, error => reject(error));
|
||||
}, error => reject(error));
|
||||
} else {
|
||||
this.addPersonToBus(date, id)
|
||||
.subscribe(_ => {
|
||||
this.saveSelection(date, id, direction);
|
||||
resolve();
|
||||
}, error => {
|
||||
reject(error);
|
||||
}
|
||||
);
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// TODO: Select Others
|
||||
/*public async selectOtherAsync(date: Date): Promise<any> {
|
||||
date = new Date(date.toDateString());
|
||||
return new Promise<any>((resolve, reject) => {
|
||||
if(this.isOtherSelected(date)){}
|
||||
})
|
||||
}*/
|
||||
|
||||
/**
|
||||
* Changes the bus selection for a specific date and direction.
|
||||
* Saves the other selection and does increment the counter if it is not already selected.
|
||||
*
|
||||
* @param date date of travel without hours, minutes and seconds
|
||||
* @param newIid unique id of the currently selected bus
|
||||
* @param direction direction of the previously selected bus
|
||||
* @param date date of travel
|
||||
*/
|
||||
public async changeSelectionAsync(date: Date, newId: number, direction: BusDirection): Promise<any> {
|
||||
public async selectOtherAsync(date: Date): Promise<any> {
|
||||
date = new Date(date.toDateString());
|
||||
return new Promise<any>((resolve, reject) => {
|
||||
if (!this.isBusSelected(date, direction)) {
|
||||
reject('Can not cange selection. No bus is selected for this direction and date.');
|
||||
if (this.isOtherSelected(date)) {
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
|
||||
let selected = this.loadSelections().find(bus => bus.date.getTime() === date.getTime() && bus.direction === direction);
|
||||
/**
|
||||
* !!!ATTENTION!!! unsafe operation
|
||||
* The non bus counter will be increased even if those bus decrements failed.
|
||||
*/
|
||||
let selections = this.getSelection(date);
|
||||
for (let selection of selections) {
|
||||
this.removePersonToBus(date, selection.id)
|
||||
.subscribe();
|
||||
}
|
||||
|
||||
this.changePersonsBus(date, selected.id, newId)
|
||||
.subscribe(
|
||||
_ => {
|
||||
this.saveSelection(date, newId, direction);
|
||||
resolve();
|
||||
}, error => {
|
||||
reject(error);
|
||||
}
|
||||
);
|
||||
this.addPersonToNonBus(date)
|
||||
.subscribe(__ => {
|
||||
this.saveSelection(date, 0, BusDirection.ToPSI);
|
||||
this.saveSelection(date, 0, BusDirection.FromPSI);
|
||||
resolve();
|
||||
}, error => reject(error));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -97,39 +109,19 @@ export class CoronaBusService {
|
||||
return this.loadSelections().filter(selection => selection.date.getTime() === date.getTime());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Loads the selected buses from the local storage.
|
||||
*/
|
||||
private loadSelections(): BusSelection[] {
|
||||
let busStorage = localStorage.getItem(CoronaBusService.STORAGE_NAME);
|
||||
if (!busStorage) {
|
||||
return [];
|
||||
}
|
||||
let selections = <BusSelection[]>JSON.parse(busStorage);
|
||||
selections = selections.map(row => <BusSelection>{ id: row.id, date: new Date(row.date), direction: row.direction });
|
||||
return selections;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the bus selction to the local storage.
|
||||
* If a bus is already selected on this date it will update this selection.
|
||||
* Checks if other is selected.
|
||||
* This is the case if the bus id of the arrival and departure is zero.
|
||||
*
|
||||
* @param date date of travel without hours, minutes and seconds
|
||||
* @param id id of the bus course
|
||||
* @param date date of travel
|
||||
*/
|
||||
private saveSelection(date: Date, id: number, direction: BusDirection): void {
|
||||
date = new Date(date.toDateString()); // make sure the date has no time
|
||||
const today = new Date(new Date().toDateString());
|
||||
let selections = this.loadSelections();
|
||||
selections = selections.filter(selection => selection.date.getTime() >= today.getTime());
|
||||
let index = selections.findIndex(selection => selection.date.getTime() === date.getTime() && selection.direction === direction);
|
||||
if (index >= 0) {
|
||||
selections[index].id = id;
|
||||
} else {
|
||||
selections.push({ date, id, direction });
|
||||
public isOtherSelected(date: Date): boolean {
|
||||
let selections = this.loadSelections()
|
||||
.filter(row => row.date.getTime() === date.getTime());
|
||||
if (selections.length === 0) {
|
||||
return false;
|
||||
}
|
||||
localStorage.setItem(CoronaBusService.STORAGE_NAME, JSON.stringify(selections));
|
||||
return selections.every(row => row.id === 0);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -142,10 +134,52 @@ export class CoronaBusService {
|
||||
return this.loadSelections().findIndex(bus => bus.date.getTime() === date.getTime() && bus.direction === direction) >= 0;
|
||||
}
|
||||
|
||||
// TODO: Select Others
|
||||
/*public isOtherSelected(date: Date): boolean {
|
||||
// return this.loadSelections().findIndex(bus => bus.date.getTime() === date.getTime() && bus.direction === direction) >= 0;
|
||||
}*/
|
||||
/**
|
||||
* Loads the selected buses from the local storage.
|
||||
*/
|
||||
private loadSelections(): BusSelection[] {
|
||||
const today = new Date(new Date().toDateString());
|
||||
let busStorage = localStorage.getItem(CoronaBusService.STORAGE_NAME);
|
||||
if (!busStorage) {
|
||||
return [];
|
||||
}
|
||||
let selections = <BusSelection[]>JSON.parse(busStorage);
|
||||
selections = selections.map(row => <BusSelection>{ id: row.id, date: new Date(row.date), direction: row.direction })
|
||||
.filter(selection => selection.date.getTime() >= today.getTime());
|
||||
return selections;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the bus selction to the local storage.
|
||||
* If a bus is already selected on this date it will update this selection.
|
||||
*
|
||||
* @param date date of travel without hours, minutes and seconds
|
||||
* @param id id of the bus course
|
||||
*/
|
||||
private saveSelection(date: Date, id: number, direction: BusDirection): void {
|
||||
date = new Date(date.toDateString()); // make sure the date has no time
|
||||
let selections = this.loadSelections();
|
||||
let index = selections.findIndex(selection => selection.date.getTime() === date.getTime() && selection.direction === direction);
|
||||
if (index >= 0) {
|
||||
selections[index].id = id;
|
||||
} else {
|
||||
selections.push({ id, date, direction });
|
||||
}
|
||||
localStorage.setItem(CoronaBusService.STORAGE_NAME, JSON.stringify(selections));
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a specific selction from the local storage.
|
||||
*
|
||||
* @param date date of travel
|
||||
* @param direction direction of travel
|
||||
*/
|
||||
private removeSelection(date: Date, direction: BusDirection): void {
|
||||
let selections = this.loadSelections();
|
||||
let index = selections.findIndex(row => row.date.getTime() === date.getTime() && row.direction === direction);
|
||||
selections = selections.splice(index, 1);
|
||||
localStorage.setItem(CoronaBusService.STORAGE_NAME, JSON.stringify(selections));
|
||||
}
|
||||
|
||||
/**
|
||||
* Increments the number of persons on the backend.
|
||||
@@ -168,6 +202,36 @@ export class CoronaBusService {
|
||||
return SoapApiHelper.call(this.http, environment.corona_bus_api + '/ChangePersonsBus', { date, oldId, newId });
|
||||
}
|
||||
|
||||
/**
|
||||
* Decrements the number of persons the the bus.
|
||||
*
|
||||
* @param date date of travel without hours, minutes and seconds
|
||||
* @param id unique id of the bus
|
||||
*/
|
||||
private removePersonToBus(date: Date, oldId: number): Observable<void> {
|
||||
return SoapApiHelper.call(this.http, environment.corona_bus_api + '/RemovePersonToBus', { date, oldId });
|
||||
}
|
||||
|
||||
/**
|
||||
* Increments the non bus counter.
|
||||
* This counter represents any non public transport medium.
|
||||
*
|
||||
* @param date date of travel
|
||||
*/
|
||||
private addPersonToNonBus(date: Date): Observable<void> {
|
||||
return SoapApiHelper.call(this.http, environment.corona_bus_api + '/AddPersonToNonBus', { date });
|
||||
}
|
||||
|
||||
/**
|
||||
* Decrements the non bus counter.
|
||||
* This counter represents any non public transport medium.
|
||||
*
|
||||
* @param date date of travel
|
||||
*/
|
||||
private removePersonToNonBus(date: Date): Observable<void> {
|
||||
return SoapApiHelper.call(this.http, environment.corona_bus_api + '/RemovePersonToNonBus', { date });
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the status of a specific bus from the backend.
|
||||
*
|
||||
|
||||
+1
-1
@@ -78,7 +78,7 @@
|
||||
"check-else",
|
||||
"check-whitespace"
|
||||
],
|
||||
"prefer-const": true,
|
||||
"prefer-const": false,
|
||||
"quotemark": [
|
||||
true,
|
||||
"single"
|
||||
|
||||
Reference in new issue
Block a user