add admin timetable

This commit is contained in:
2019-10-23 08:49:40 +02:00
committed by Roland Schneider
parent 1300bfc752
commit bf85c737d5
32 changed files with 1037 additions and 120 deletions

View File

@@ -3,17 +3,19 @@ import { HttpInterceptor, HttpRequest, HttpHandler, HttpEvent } from "@angular/c
import { Observable, throwError } from "rxjs";
import { catchError } from "rxjs/operators";
import { AuthenticationService} from "../services/authentication.service";
import {NavigationService} from "../services/navigation.service";
/*
Http error interceptor works with the calling service and the API's
It intercepts the responses from the API and check for the status codes (if there were any errors).
Error Status 401: Unauthorized Response - the user will be automatically logged out
All other errors are RE-THROWN to be caught by the calling service so an alert can be displayed to the user
All other errors are RE-THROWN to be caught by the calling service so an alert can be displayed to the user
*/
@Injectable()
export class ErrorInterceptor implements HttpInterceptor{
constructor(private authenticationService: AuthenticationService){}
constructor(private authenticationService: AuthenticationService,
private navigationService: NavigationService){}
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>>{
return next.handle(request)
@@ -22,7 +24,8 @@ All other errors are RE-THROWN to be caught by the calling service so an alert c
if(err.status === 401){
// auto logout on unauthorized response
this.authenticationService.logout();
location.reload(true);
this.navigationService.navigateToLogin();
// location.reload(true);
}
const error = err.error.message || err.statusText;

View File

@@ -76,6 +76,7 @@ export class FakeBackendInterceptor implements HttpInterceptor {
let reservedAt = id % 2 ? this.createEventDate(0, 1) : null;
events.push(
{
room: undefined,
id: id,
name: 'esemény ' + id,
start: this.createEventDate(dayIndex, hourIndex),
@@ -84,7 +85,7 @@ export class FakeBackendInterceptor implements HttpInterceptor {
eventType: eventTypes[id % eventTypes.length],
reservedAt: reservedAt,
reservationCount: id % 11,
seatCount: 10,
seatCount: 10
}
)
}

View File

@@ -1,7 +1,6 @@
import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core';
import {Event} from "../../services/event.service";
import * as moment from "moment";
import {MonthCalendarEvent} from "../month-calendar/month-calendar.component";
import {dateToMoment, MonthCalendarEvent} from "../month-calendar/month-calendar.component";
@Component({
selector: 'app-month-calendar-event',
@@ -23,7 +22,7 @@ export class MonthCalendarEventComponent implements OnInit {
}
formatTime() {
return moment(this.event.start).format('HH:mm');
return dateToMoment(this.event.start).utc().format('HH:mm');
}
hasTrainer() {

View File

@@ -6,7 +6,7 @@
</div>
</header>
<div *ngIf="eventsAvailableResponse" class="row border border-right-0 border-bottom-0">
<ng-container *ngFor="let day of eventsAvailableResponse.days; let i = index">
<ng-container *ngFor="let day of eventsAvailableResponse.dates; let i = index">
<div app-month-calendar-day [day]="day" (onEvent)="handleEvent($event)" ></div>
<div *ngIf="i > 0 && ( ((i+1) % 7) == 0)" class="w-100"></div>
</ng-container>

View File

@@ -1,6 +1,6 @@
import {Component, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges} from '@angular/core';
import {Component, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges} from '@angular/core';
import {Event, EventsAvailableResponse} from "../../services/event.service";
import * as moment from "moment";
import * as moment from "moment";
@Component({
selector: 'app-month-calendar',
@@ -20,59 +20,52 @@ export class MonthCalendarComponent implements OnInit, OnChanges {
@Output()
onEvent: EventEmitter<MonthCalendarEvent> = new EventEmitter<MonthCalendarEvent>();
constructor( ) { }
constructor() {
}
ngOnInit() {
moment.locale('hu');
//
this.fillDaysOfWeek();
//
// let firstDay = moment().startOf('week');
//
// this.days = [];
// if ( this.eventsAvailableResponse ){
//
// for ( let i = 0; i < this.eventsAvailableResponse.days.length; i++){
// this.days.push({
// date: this.eventsAvailableResponse.days[i],
// events: [],
// active: true
// })
// }
// }
}
fillDaysOfWeek(){
fillDaysOfWeek() {
this.daysOfWeek = [];
let startOfWeek = moment().startOf("week");
for ( let i = 0; i < 7 ; i++ ){
let momWeekDay = startOfWeek.clone().add(i,'d');
const dayOfWeek = {
name: momWeekDay.format("dddd"),
};
this.daysOfWeek.push(dayOfWeek);
if ( this.eventsAvailableResponse) {
for (let i = 0; i < this.eventsAvailableResponse.dates.length && i < 7; i++) {
const date = moment.unix(this.eventsAvailableResponse.dates[i].date);
const dayOfWeek = {
name: date.format("dddd"),
};
this.daysOfWeek.push(dayOfWeek);
}
}else{
let startOfWeek = moment().startOf("week");
for ( let i = 0; i < 7 ; i++ ){
let momWeekDay = startOfWeek.clone().add(i,'d');
const dayOfWeek = {
name: momWeekDay.format("dddd"),
};
this.daysOfWeek.push(dayOfWeek);
}
}
}
ngOnChanges(changes: SimpleChanges): void {
console.info(changes);
if ( changes.hasOwnProperty('eventsAvailableResponse')){
if (changes.hasOwnProperty('eventsAvailableResponse')) {
this.fillDaysOfWeek();
}
}
handleEvent($event){
handleEvent($event) {
this.onEvent.emit($event);
}
}
export interface Day {
date: number;
date: unixTime;
events: Event[];
active: boolean;
}
@@ -82,9 +75,15 @@ export interface DayOfWeek {
}
export function dateToMoment(date: number) {
return moment(date);
return moment.unix(date);
}
/**
* Unix time is the number of seconds that have elapsed since the Unix epoch,
* that is the time 00:00:00 UTC on 1 January 1970
*/
type unixTime= number;
export interface MonthCalendarEvent {
type: string; // type of the month calendar event
event: Event; // the fitness event

View File

@@ -25,6 +25,5 @@ export class HomeComponent implements OnInit {
handleEvent($event: MonthCalendarEvent) {
console.info($event);
this.navigationService.navigateToEventDetails($event.event.id);
}
}

View File

@@ -31,7 +31,7 @@ export class Endpoints {
public static GET_EVENTS_AVAILABLE(){
return `${this.baseUrl}/events/available`;
return `${this.baseUrl}/event/available`;
}
}

View File

@@ -73,7 +73,7 @@ export interface DayToDisplay {
}
export interface EventsAvailableResponse {
days: DayToDisplay[];
dates: DayToDisplay[];
events: Event[];
}

View File

@@ -20,5 +20,9 @@ export class NavigationService {
this.navigate(['/home' ])
}
public navigateToLogin(){
this.navigate(['/login' ])
}
}