diff --git a/angular/e2e/dashboard.e2e.ts b/angular/e2e/dashboard.e2e.ts index b4bad40ce..cbbe6e912 100644 --- a/angular/e2e/dashboard.e2e.ts +++ b/angular/e2e/dashboard.e2e.ts @@ -1,15 +1,20 @@ -import { browser, by, protractor, $, element, ProtractorExpectedConditions } from 'protractor'; +import { + browser, + by, + protractor, + $, + element, + ProtractorExpectedConditions, +} from 'protractor'; describe('basic e2e test with loading', function(): void { - let EC: ProtractorExpectedConditions = protractor.ExpectedConditions; + const EC: ProtractorExpectedConditions = protractor.ExpectedConditions; describe('home', function(): void { browser.get('/'); it('should load home page', function(): void { expect(browser.getTitle()).toBe('My Thai Star'); // Waits for the element 'td-loading' to not be present on the dom. - browser.wait(EC.not(EC.presenceOf($('td-loading'))), 10000) - .then(() => { - + browser.wait(EC.not(EC.presenceOf($('td-loading'))), 10000).then(() => { // checks if elements were rendered expect(element(by.id('homeCard')).isPresent()).toBe(true); }); diff --git a/angular/src/app/app.component.ts b/angular/src/app/app.component.ts index 2f7357499..4f5c2e5d8 100644 --- a/angular/src/app/app.component.ts +++ b/angular/src/app/app.component.ts @@ -16,7 +16,7 @@ import * as moment from 'moment'; animations: [fadeAnimation], // register the animation }) export class AppComponent { - mobileSidenavOpened: boolean = false; + mobileSidenavOpened = false; year: string = moment().format('YYYY'); constructor( public router: Router, diff --git a/angular/src/app/book-table/shared/book-table.service.ts b/angular/src/app/book-table/shared/book-table.service.ts index c270d83c6..802c413f5 100644 --- a/angular/src/app/book-table/shared/book-table.service.ts +++ b/angular/src/app/book-table/shared/book-table.service.ts @@ -18,7 +18,7 @@ export class BookTableService { } composeBooking(invitationData: any, type: number): BookingInfo { - let composedBooking: BookingInfo = { + const composedBooking: BookingInfo = { booking: { bookingDate: invitationData.bookingDate, name: invitationData.name, @@ -28,7 +28,7 @@ export class BookTableService { }; if (type) { - composedBooking.invitedGuests = map(invitationData.invitedGuests, (email: string) => { return { email: email }; }); + composedBooking.invitedGuests = map(invitationData.invitedGuests, (email: string) => ({ email: email })); } else { composedBooking.booking.assistants = invitationData.assistants; } diff --git a/angular/src/app/cockpit-area/order-cockpit/order-cockpit.component.spec.ts b/angular/src/app/cockpit-area/order-cockpit/order-cockpit.component.spec.ts index b6306f5e6..c5662f9dd 100644 --- a/angular/src/app/cockpit-area/order-cockpit/order-cockpit.component.spec.ts +++ b/angular/src/app/cockpit-area/order-cockpit/order-cockpit.component.spec.ts @@ -17,10 +17,13 @@ import { TranslateService } from '@ngx-translate/core'; describe('OrderCockpitComponent', () => { let component: OrderCockpitComponent; // let fixture: ComponentFixture; + // tslint:disable-next-line:prefer-const let http: HttpClient; let priceCalculator: PriceCalculatorService; let waiterCockpitService: WaiterCockpitService; + // tslint:disable-next-line:prefer-const let translate: TranslateService; + // tslint:disable-next-line:prefer-const let dialog: MatDialog; // beforeEach(async(() => { diff --git a/angular/src/app/cockpit-area/order-cockpit/order-cockpit.component.ts b/angular/src/app/cockpit-area/order-cockpit/order-cockpit.component.ts index 724852c28..e92966bd3 100644 --- a/angular/src/app/cockpit-area/order-cockpit/order-cockpit.component.ts +++ b/angular/src/app/cockpit-area/order-cockpit/order-cockpit.component.ts @@ -20,7 +20,6 @@ import * as moment from 'moment'; styleUrls: ['./order-cockpit.component.scss'], }) export class OrderCockpitComponent implements OnInit { - private pageable: Pageable = { pageSize: 8, pageNumber: 0, @@ -28,7 +27,7 @@ export class OrderCockpitComponent implements OnInit { }; private sorting: any[] = []; - pageSize: number = 8; + pageSize = 8; orders: OrderListView[]; totalOrders: number; @@ -43,9 +42,11 @@ export class OrderCockpitComponent implements OnInit { bookingToken: undefined, }; - constructor(private dialog: MatDialog, + constructor( + private dialog: MatDialog, private translate: TranslateService, - private waiterCockpitService: WaiterCockpitService) { } + private waiterCockpitService: WaiterCockpitService, + ) {} ngOnInit(): void { this.applyFilters(); @@ -67,10 +68,11 @@ export class OrderCockpitComponent implements OnInit { } applyFilters(): void { - this.waiterCockpitService.getOrders(this.pageable, this.sorting, this.filters) + this.waiterCockpitService + .getOrders(this.pageable, this.sorting, this.filters) .subscribe((data: any) => { if (!data) { - this.orders = []; + this.orders = []; } else { this.orders = data.content; } diff --git a/angular/src/app/cockpit-area/order-cockpit/order-dialog/order-dialog.component.ts b/angular/src/app/cockpit-area/order-cockpit/order-dialog/order-dialog.component.ts index e3e4119d5..64791ec67 100644 --- a/angular/src/app/cockpit-area/order-cockpit/order-dialog/order-dialog.component.ts +++ b/angular/src/app/cockpit-area/order-cockpit/order-dialog/order-dialog.component.ts @@ -1,5 +1,9 @@ import { Component, OnInit, Inject } from '@angular/core'; -import { IPageChangeEvent, ITdDataTableColumn, TdDataTableService } from '@covalent/core'; +import { + IPageChangeEvent, + ITdDataTableColumn, + TdDataTableService, +} from '@covalent/core'; import { OrderView, BookingView } from '../../../shared/viewModels/interfaces'; import { WaiterCockpitService } from '../../shared/waiter-cockpit.service'; import { MAT_DIALOG_DATA } from '@angular/material'; @@ -13,11 +17,10 @@ import { LangChangeEvent } from '@ngx-translate/core'; styleUrls: ['./order-dialog.component.scss'], }) export class OrderDialogComponent implements OnInit { + private fromRow = 1; + private currentPage = 1; - private fromRow: number = 1; - private currentPage: number = 1; - - pageSize: number = 4; + pageSize = 4; data: any; datat: BookingView[] = []; @@ -30,21 +33,24 @@ export class OrderDialogComponent implements OnInit { filteredData: OrderView[] = this.datao; totalPrice: number; - constructor(private _dataTableService: TdDataTableService, + constructor( + private _dataTableService: TdDataTableService, private waiterCockpitService: WaiterCockpitService, private translate: TranslateService, - @Inject(MAT_DIALOG_DATA) dialogData: any) { + @Inject(MAT_DIALOG_DATA) dialogData: any, + ) { this.data = dialogData.row; } ngOnInit(): void { - this.setTableHeaders(); this.translate.onLangChange.subscribe((event: LangChangeEvent) => { this.setTableHeaders(); }); - this.totalPrice = this.waiterCockpitService.getTotalPrice(this.data.orderLines); + this.totalPrice = this.waiterCockpitService.getTotalPrice( + this.data.orderLines, + ); this.datao = this.waiterCockpitService.orderComposer(this.data.orderLines); this.datat.push(this.data.booking); this.filter(); @@ -67,7 +73,12 @@ export class OrderDialogComponent implements OnInit { { name: 'orderLine.comment', label: res.commentsH }, { name: 'extras', label: res.extrasH }, { name: 'orderLine.amount', label: res.quantityH }, - { name: 'dish.price', label: res.priceH, numeric: true, format: (v: number) => v.toFixed(2) }, + { + name: 'dish.price', + label: res.priceH, + numeric: true, + format: (v: number) => v.toFixed(2), + }, ]; }); } @@ -81,7 +92,11 @@ export class OrderDialogComponent implements OnInit { filter(): void { let newData: any[] = this.datao; - newData = this._dataTableService.pageData(newData, this.fromRow, this.currentPage * this.pageSize); - setTimeout(() => this.filteredData = newData); + newData = this._dataTableService.pageData( + newData, + this.fromRow, + this.currentPage * this.pageSize, + ); + setTimeout(() => (this.filteredData = newData)); } } diff --git a/angular/src/app/cockpit-area/reservation-cockpit/reservation-cockpit.component.spec.ts b/angular/src/app/cockpit-area/reservation-cockpit/reservation-cockpit.component.spec.ts index 59d89b94b..44a3b8fe5 100644 --- a/angular/src/app/cockpit-area/reservation-cockpit/reservation-cockpit.component.spec.ts +++ b/angular/src/app/cockpit-area/reservation-cockpit/reservation-cockpit.component.spec.ts @@ -17,10 +17,13 @@ import { TranslateService } from '@ngx-translate/core'; describe('ReservationCockpitComponent', () => { let component: ReservationCockpitComponent; // let fixture: ComponentFixture; + // tslint:disable-next-line:prefer-const let http: HttpClient; let priceCalculator: PriceCalculatorService; let waiterCockpitService: WaiterCockpitService; + // tslint:disable-next-line:prefer-const let translate: TranslateService; + // tslint:disable-next-line:prefer-const let dialog: MatDialog; // beforeEach(async(() => { diff --git a/angular/src/app/cockpit-area/reservation-cockpit/reservation-dialog/reservation-dialog.component.ts b/angular/src/app/cockpit-area/reservation-cockpit/reservation-dialog/reservation-dialog.component.ts index c91dc868b..6b87405f7 100644 --- a/angular/src/app/cockpit-area/reservation-cockpit/reservation-dialog/reservation-dialog.component.ts +++ b/angular/src/app/cockpit-area/reservation-cockpit/reservation-dialog/reservation-dialog.component.ts @@ -1,6 +1,13 @@ import { Component, OnInit, Inject } from '@angular/core'; -import { IPageChangeEvent, ITdDataTableColumn, TdDataTableService } from '@covalent/core'; -import { FriendsInvite, ReservationView } from '../../../shared/viewModels/interfaces'; +import { + IPageChangeEvent, + ITdDataTableColumn, + TdDataTableService, +} from '@covalent/core'; +import { + FriendsInvite, + ReservationView, +} from '../../../shared/viewModels/interfaces'; import { MAT_DIALOG_DATA } from '@angular/material'; import { config } from '../../../config'; import { TranslateService } from '@ngx-translate/core'; @@ -12,11 +19,10 @@ import { LangChangeEvent } from '@ngx-translate/core'; styleUrls: ['./reservation-dialog.component.scss'], }) export class ReservationDialogComponent implements OnInit { - datao: FriendsInvite[] = []; - fromRow: number = 1; - currentPage: number = 1; - pageSize: number = 4; + fromRow = 1; + currentPage = 1; + pageSize = 4; data: any; columnso: ITdDataTableColumn[] = [ @@ -29,9 +35,11 @@ export class ReservationDialogComponent implements OnInit { filteredData: any[] = this.datao; - constructor(private _dataTableService: TdDataTableService, + constructor( + private _dataTableService: TdDataTableService, private translate: TranslateService, - @Inject(MAT_DIALOG_DATA) dialogData: any) { + @Inject(MAT_DIALOG_DATA) dialogData: any, + ) { this.data = dialogData.row; this.pageSizes = config.pageSizesDialog; } @@ -58,16 +66,21 @@ export class ReservationDialogComponent implements OnInit { ]; }); - this.translate.get('cockpit.reservations.dialogTable').subscribe((res: any) => { - this.columnso = [ - { name: 'email', label: res.guestEmailH }, - { name: 'accepted', label: res.acceptanceH }, - ]; + this.translate + .get('cockpit.reservations.dialogTable') + .subscribe((res: any) => { + this.columnso = [ + { name: 'email', label: res.guestEmailH }, + { name: 'accepted', label: res.acceptanceH }, + ]; - if (this.data.booking.assistants) { - this.columnst.push({ name: 'booking.assistants', label: res.assistantsH }); - } - }); + if (this.data.booking.assistants) { + this.columnst.push({ + name: 'booking.assistants', + label: res.assistantsH, + }); + } + }); } page(pagingEvent: IPageChangeEvent): void { @@ -79,8 +92,11 @@ export class ReservationDialogComponent implements OnInit { filter(): void { let newData: any[] = this.datao; - newData = this._dataTableService.pageData(newData, this.fromRow, this.currentPage * this.pageSize); - setTimeout(() => this.filteredData = newData); + newData = this._dataTableService.pageData( + newData, + this.fromRow, + this.currentPage * this.pageSize, + ); + setTimeout(() => (this.filteredData = newData)); } - } diff --git a/angular/src/app/cockpit-area/shared/waiter-cockpit.service.ts b/angular/src/app/cockpit-area/shared/waiter-cockpit.service.ts index fcd515dbc..d3c73f037 100644 --- a/angular/src/app/cockpit-area/shared/waiter-cockpit.service.ts +++ b/angular/src/app/cockpit-area/shared/waiter-cockpit.service.ts @@ -1,23 +1,40 @@ import { Injectable } from '@angular/core'; import { Observable } from 'rxjs'; import { PriceCalculatorService } from '../../sidenav/shared/price-calculator.service'; -import { BookingResponse, OrderResponse, OrderView, OrderViewResult } from '../../shared/viewModels/interfaces'; +import { + BookingResponse, + OrderResponse, + OrderView, + OrderViewResult, +} from '../../shared/viewModels/interfaces'; import { map, cloneDeep } from 'lodash'; -import { Pageable, Sort, FilterCockpit } from 'app/shared/backendModels/interfaces'; +import { + Pageable, + Sort, + FilterCockpit, +} from 'app/shared/backendModels/interfaces'; import { HttpClient } from '@angular/common/http'; import { environment } from './../../../environments/environment'; @Injectable() export class WaiterCockpitService { + private readonly getReservationsRestPath: string = + 'bookingmanagement/v1/booking/search'; + private readonly getOrdersRestPath: string = + 'ordermanagement/v1/order/search'; + private readonly filterOrdersRestPath: string = + 'ordermanagement/v1/order/search'; - private readonly getReservationsRestPath: string = 'bookingmanagement/v1/booking/search'; - private readonly getOrdersRestPath: string = 'ordermanagement/v1/order/search'; - private readonly filterOrdersRestPath: string = 'ordermanagement/v1/order/search'; + constructor( + private http: HttpClient, + private priceCalculator: PriceCalculatorService, + ) {} - constructor(private http: HttpClient, - private priceCalculator: PriceCalculatorService) { } - - getOrders(pageable: Pageable, sorting: Sort[], filters: FilterCockpit): Observable { + getOrders( + pageable: Pageable, + sorting: Sort[], + filters: FilterCockpit, + ): Observable { let path: string; filters.pageable = pageable; filters.pageable.sort = sorting; @@ -28,17 +45,27 @@ export class WaiterCockpitService { delete filters.bookingToken; path = this.getOrdersRestPath; } - return this.http.post(`${environment.restServiceRoot}${path}`, filters); + return this.http.post( + `${environment.restServiceRoot}${path}`, + filters, + ); } - getReservations(pageable: Pageable, sorting: Sort[], filters: FilterCockpit): Observable { + getReservations( + pageable: Pageable, + sorting: Sort[], + filters: FilterCockpit, + ): Observable { filters.pageable = pageable; filters.pageable.sort = sorting; - return this.http.post(`${environment.restServiceRoot}${this.getReservationsRestPath}`, filters); + return this.http.post( + `${environment.restServiceRoot}${this.getReservationsRestPath}`, + filters, + ); } orderComposer(orderList: OrderView[]): OrderView[] { - let orders: OrderView[] = cloneDeep(orderList); + const orders: OrderView[] = cloneDeep(orderList); map(orders, (o: OrderViewResult) => { o.dish.price = this.priceCalculator.getPrice(o); o.extras = map(o.extras, 'name').join(', '); @@ -49,5 +76,4 @@ export class WaiterCockpitService { getTotalPrice(orderLines: OrderView[]): number { return this.priceCalculator.getTotalPrice(orderLines); } - } diff --git a/angular/src/app/core/authentication/auth-guard.service.ts b/angular/src/app/core/authentication/auth-guard.service.ts index 0c734bc0e..15848cb4a 100644 --- a/angular/src/app/core/authentication/auth-guard.service.ts +++ b/angular/src/app/core/authentication/auth-guard.service.ts @@ -1,31 +1,35 @@ -import { Injectable } from '@angular/core'; +import { Injectable } from '@angular/core'; import { - CanActivate, Router, + CanActivate, + Router, ActivatedRouteSnapshot, RouterStateSnapshot, -} from '@angular/router'; -import { AuthService } from './auth.service'; +} from '@angular/router'; +import { AuthService } from './auth.service'; import { SnackBarService } from '../snackService/snackService.service'; import { TranslateService } from '@ngx-translate/core'; @Injectable() export class AuthGuardService implements CanActivate { - constructor(public snackBar: SnackBarService, - private authService: AuthService, - private translate: TranslateService, - private router: Router) {} - - canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean { + constructor( + public snackBar: SnackBarService, + private authService: AuthService, + private translate: TranslateService, + private router: Router, + ) {} + canActivate( + route: ActivatedRouteSnapshot, + state: RouterStateSnapshot, + ): boolean { if (this.authService.isLogged() && this.authService.isPermited('WAITER')) { return true; } if (!this.authService.isLogged()) { - this.translate.get('alerts.accessError') - .subscribe( (text: string) => { - this.snackBar.openSnack(text, 4000, 'red'); - }); + this.translate.get('alerts.accessError').subscribe((text: string) => { + this.snackBar.openSnack(text, 4000, 'red'); + }); } if (this.router.url === '/') { diff --git a/angular/src/app/core/authentication/auth.service.ts b/angular/src/app/core/authentication/auth.service.ts index 99ae2765a..24e6ee7ed 100644 --- a/angular/src/app/core/authentication/auth.service.ts +++ b/angular/src/app/core/authentication/auth.service.ts @@ -5,45 +5,47 @@ import { Role } from '../../shared/viewModels/interfaces'; @Injectable() export class AuthService { - private logged: boolean = false; - private user: string = ''; - private currentRole: string = 'CUSTOMER'; - private token: string; - - public isLogged(): boolean { - return this.logged; - } - - public setLogged(login: boolean): void { - this.logged = login; - } - - public getUser(): string { - return this.user; - } - - public setUser(username: string): void { - this.user = username; - } - - public getToken(): string { - return this.token; - } - - public setToken(token: string): void { - this.token = token; - } - - public setRole(role: string): void { - this.currentRole = role; - } - - public getPermission(roleName: string): number { - let role: Role = find(config.roles, { name: roleName }); - return role.permission; - } - - public isPermited(userRole: string): boolean { - return this.getPermission(this.currentRole) === this.getPermission(userRole); - } + private logged = false; + private user = ''; + private currentRole = 'CUSTOMER'; + private token: string; + + public isLogged(): boolean { + return this.logged; + } + + public setLogged(login: boolean): void { + this.logged = login; + } + + public getUser(): string { + return this.user; + } + + public setUser(username: string): void { + this.user = username; + } + + public getToken(): string { + return this.token; + } + + public setToken(token: string): void { + this.token = token; + } + + public setRole(role: string): void { + this.currentRole = role; + } + + public getPermission(roleName: string): number { + const role: Role = find(config.roles, { name: roleName }); + return role.permission; + } + + public isPermited(userRole: string): boolean { + return ( + this.getPermission(this.currentRole) === this.getPermission(userRole) + ); + } } diff --git a/angular/src/app/core/core.module.ts b/angular/src/app/core/core.module.ts index af4b6b7b5..85dd042ea 100644 --- a/angular/src/app/core/core.module.ts +++ b/angular/src/app/core/core.module.ts @@ -71,8 +71,8 @@ import 'moment/locale/ca'; // Default text strings for OwlDateTime export class DefaultIntl extends OwlDateTimeIntl { - cancelBtnLabel: string = '\u{2716}'; - setBtnLabel: string = '\u{2714}'; + cancelBtnLabel = '\u{2716}'; + setBtnLabel = '\u{2714}'; } @NgModule({ diff --git a/angular/src/app/core/windowService/windowService.service.spec.ts b/angular/src/app/core/windowService/windowService.service.spec.ts index 1c0cd628d..3d40b1b41 100644 --- a/angular/src/app/core/windowService/windowService.service.spec.ts +++ b/angular/src/app/core/windowService/windowService.service.spec.ts @@ -1,11 +1,11 @@ import { TestBed, inject } from '@angular/core/testing'; -import { HttpModule } from '@angular/http'; +import { HttpClientModule } from '@angular/common/http'; import { WindowService } from './windowService.service'; describe('WindowService', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [HttpModule], + imports: [HttpClientModule], providers: [WindowService], }); }); diff --git a/angular/src/app/header/header.component.ts b/angular/src/app/header/header.component.ts index 201d789a1..eee2bf366 100644 --- a/angular/src/app/header/header.component.ts +++ b/angular/src/app/header/header.component.ts @@ -23,8 +23,7 @@ export class HeaderComponent { selectableLangs: any[]; flag: string; - @Output('openCloseSidenavMobile') - sidenavNavigationEmitter: EventEmitter = new EventEmitter(); + @Output() openCloseSidenavMobile = new EventEmitter(); constructor( public window: WindowService, @@ -46,12 +45,12 @@ export class HeaderComponent { } openCloseNavigationSideNav(): void { - this.sidenavNavigationEmitter.emit(); + this.openCloseSidenavMobile.emit(); } navigateTo(route: string): void { this.router.navigate([route]); - this.sidenavNavigationEmitter.emit(); + this.openCloseSidenavMobile.emit(); } changeLanguage(lang: string): void { diff --git a/angular/src/app/home/home-card/home-card.component.ts b/angular/src/app/home/home-card/home-card.component.ts index 31f734919..c65b968c6 100644 --- a/angular/src/app/home/home-card/home-card.component.ts +++ b/angular/src/app/home/home-card/home-card.component.ts @@ -6,13 +6,11 @@ import { Component, Input, Output, EventEmitter } from '@angular/core'; styleUrls: ['./home-card.component.scss'], }) export class HomeCardComponent { - @Input() - tile: Tile; - @Output('buttonClick') - buttonEmitter: EventEmitter = new EventEmitter(); + @Input() tile: Tile; + @Output() buttonClick: EventEmitter = new EventEmitter(); onButtonClick(event: Event): void { - this.buttonEmitter.emit(event); + this.buttonClick.emit(event); } } diff --git a/angular/src/app/menu/menu-card/menu-card-details/menu-card-details.component.ts b/angular/src/app/menu/menu-card/menu-card-details/menu-card-details.component.ts index 0cfe6cbce..30288c633 100644 --- a/angular/src/app/menu/menu-card/menu-card-details/menu-card-details.component.ts +++ b/angular/src/app/menu/menu-card/menu-card-details/menu-card-details.component.ts @@ -7,12 +7,8 @@ import { DishView, ExtraView } from '../../../shared/viewModels/interfaces'; styleUrls: ['./menu-card-details.component.scss'], }) export class MenuCardDetailsComponent { - - @Input() - menuInfo: DishView; - - @Output('clickOrder') - orderEmitter: EventEmitter = new EventEmitter(); + @Input() menuInfo: DishView; + @Output() clickOrder: EventEmitter = new EventEmitter(); onSelectExtra(extra: ExtraView): void { // extra.selected = !extra.selected; @@ -20,12 +16,11 @@ export class MenuCardDetailsComponent { const oldExtra: ExtraView = this.menuInfo.extras[modifiedExtraIndex]; this.menuInfo.extras[modifiedExtraIndex] = { ...oldExtra, - ...{selected: !oldExtra.selected }, + ...{ selected: !oldExtra.selected }, }; - } onClickOrder(): void { - this.orderEmitter.emit(this.menuInfo); + this.clickOrder.emit(this.menuInfo); } } diff --git a/angular/src/app/menu/menu-card/menu-card.component.ts b/angular/src/app/menu/menu-card/menu-card.component.ts index b8abbdffa..2c2967171 100644 --- a/angular/src/app/menu/menu-card/menu-card.component.ts +++ b/angular/src/app/menu/menu-card/menu-card.component.ts @@ -10,14 +10,13 @@ import { AuthService } from '../../core/authentication/auth.service'; styleUrls: ['./menu-card.component.scss'], }) export class MenuCardComponent { - - @Input('menu') menuInfo: DishView; + @Input() menuInfo: DishView; constructor( private menuService: MenuService, public auth: AuthService, private sidenav: SidenavService, - ) { } + ) {} addOrderMenu(): void { this.sidenav.addOrder(this.menuService.menuToOrder(this.menuInfo)); @@ -32,5 +31,4 @@ export class MenuCardComponent { selectedOption(extra: ExtraView): void { extra.selected = !extra.selected; } - } diff --git a/angular/src/app/menu/menu-filters/menu-filters.component.ts b/angular/src/app/menu/menu-filters/menu-filters.component.ts index 2e50f7dc3..33b05d86e 100644 --- a/angular/src/app/menu/menu-filters/menu-filters.component.ts +++ b/angular/src/app/menu/menu-filters/menu-filters.component.ts @@ -30,12 +30,9 @@ export class MenuFiltersComponent implements OnInit { }; filtersForm: FormGroup; - @Output('applyForm') - applyFormEmitter: EventEmitter = new EventEmitter(); + @Output() applyForm: EventEmitter = new EventEmitter(); - constructor( - private fb: FormBuilder, - ) {} + constructor(private fb: FormBuilder) {} ngOnInit(): void { // Hint: formDefaults work here nicely as form builder is used and API is consistent @@ -49,7 +46,7 @@ export class MenuFiltersComponent implements OnInit { if (event) { event.preventDefault(); } - this.applyFormEmitter.emit(this.filtersForm.value); + this.applyForm.emit(this.filtersForm.value); } clearFilters(event: Event, form: FormGroup): void { @@ -60,18 +57,18 @@ export class MenuFiltersComponent implements OnInit { export class FilterFormData { searchBy: string; - sort: { property: string, direction: string }; + sort: { property: string; direction: string }; maxPrice: number; minLikes: number; categories: { - mainDishes: boolean, - starters: boolean, - desserts: boolean, - noodle: boolean, - rice: boolean, - curry: boolean, - vegan: boolean, - vegetarian: boolean, - favourites: boolean, + mainDishes: boolean; + starters: boolean; + desserts: boolean; + noodle: boolean; + rice: boolean; + curry: boolean; + vegan: boolean; + vegetarian: boolean; + favourites: boolean; }; } diff --git a/angular/src/app/menu/menu.component.html b/angular/src/app/menu/menu.component.html index 761925c59..3b69421c5 100644 --- a/angular/src/app/menu/menu.component.html +++ b/angular/src/app/menu/menu.component.html @@ -1,13 +1,13 @@ - + -
- -
+
+ +
- - - - + + + + diff --git a/angular/src/app/menu/menu.component.spec.ts b/angular/src/app/menu/menu.component.spec.ts index c804e3e3c..2f6b41a37 100644 --- a/angular/src/app/menu/menu.component.spec.ts +++ b/angular/src/app/menu/menu.component.spec.ts @@ -25,6 +25,7 @@ import { TranslateModule } from '@ngx-translate/core'; describe('MenuComponent', () => { let component: MenuComponent; // let fixture: ComponentFixture; + // tslint:disable-next-line:prefer-const let http: HttpClient; let menuService: MenuService; diff --git a/angular/src/app/menu/menu.component.ts b/angular/src/app/menu/menu.component.ts index 3d9431eee..e805f3528 100644 --- a/angular/src/app/menu/menu.component.ts +++ b/angular/src/app/menu/menu.component.ts @@ -21,30 +21,32 @@ export interface Filters { styleUrls: ['./menu.component.scss'], }) export class MenuComponent { - dishes$: Observable; - constructor( - private menuService: MenuService, - ) {} + constructor(private menuService: MenuService) {} onFilterChange(filters: FilterFormData): void { - let pageable: Pageable = { + const pageable: Pageable = { pageSize: 8, pageNumber: 0, - sort: [{ - property: filters.sort.property, - direction: filters.sort.direction, - }], + sort: [ + { + property: filters.sort.property, + direction: filters.sort.direction, + }, + ], }; - const composedFilters: Filter = this.menuService.composeFilters(pageable, filters); + const composedFilters: Filter = this.menuService.composeFilters( + pageable, + filters, + ); this.dishes$ = this.menuService.getDishes(composedFilters).pipe( map((res) => { if (!res) { - return []; - } else { - return res.content; - } + return []; + } else { + return res.content; + } }), ); } diff --git a/angular/src/app/shared/directives/email-validator.directive.ts b/angular/src/app/shared/directives/email-validator.directive.ts index a8acdbc4b..00f321e49 100644 --- a/angular/src/app/shared/directives/email-validator.directive.ts +++ b/angular/src/app/shared/directives/email-validator.directive.ts @@ -4,22 +4,30 @@ import { Validator, AbstractControl } from '@angular/forms'; // Function exported to be used in this directive and unit tests export function emailValidator(c: string): boolean { - let regExp: RegExp = /^(([^<>()\[\]\.,;:\s@\"]+(\.[^<>()\[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i; - return regExp.test(c); + // tslint:disable-next-line:max-line-length + const regExp: RegExp = /^(([^<>()\[\]\.,;:\s@\"]+(\.[^<>()\[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i; + return regExp.test(c); } @Directive({ - selector: '[validateEmail][formControlName], [validateEmail][formControl],[validateEmail][ngModel]', - providers: [ - { provide: NG_VALIDATORS, useExisting: forwardRef(() => EmailValidatorDirective), multi: true }, - ], + selector: + '[validateEmail][formControlName], [validateEmail][formControl],[validateEmail][ngModel]', + providers: [ + { + provide: NG_VALIDATORS, + useExisting: forwardRef(() => EmailValidatorDirective), + multi: true, + }, + ], }) export class EmailValidatorDirective implements Validator { - validate(c: AbstractControl): { [key: string]: any } { - return emailValidator(c.value) ? undefined : { - validateEmail: { - valid: false, - }, + validate(c: AbstractControl): { [key: string]: any } { + return emailValidator(c.value) + ? undefined + : { + validateEmail: { + valid: false, + }, }; - } + } } diff --git a/angular/src/app/shared/directives/equal-validator.directive.ts b/angular/src/app/shared/directives/equal-validator.directive.ts index 923c49310..410b519e2 100644 --- a/angular/src/app/shared/directives/equal-validator.directive.ts +++ b/angular/src/app/shared/directives/equal-validator.directive.ts @@ -2,53 +2,56 @@ import { Directive, forwardRef, Input } from '@angular/core'; import { Validator, AbstractControl, NG_VALIDATORS } from '@angular/forms'; @Directive({ - selector: '[validateEqual][formControlName],[validateEqual][formControl],[validateEqual][ngModel]', - providers: [ - { provide: NG_VALIDATORS, useExisting: forwardRef(() => EqualValidatorDirective), multi: true }, - ], + selector: + '[validateEqual][formControlName],[validateEqual][formControl],[validateEqual][ngModel]', + providers: [ + { + provide: NG_VALIDATORS, + useExisting: forwardRef(() => EqualValidatorDirective), + multi: true, + }, + ], }) export class EqualValidatorDirective implements Validator { + @Input() public validateEqual: string; + // reverse property is to check if both fields are equal not matter which one is modified first + @Input() public reverse: string; - @Input('validateEqual') public validateEqual: string; - // reverse property is to check if both fields are equal not matter which one is modified first - @Input('reverse') public reverse: string; + validate(control: AbstractControl): { [key: string]: any } { + // control value + const controlValue: AbstractControl = control.root.get(this.validateEqual); - validate(control: AbstractControl): { [key: string]: any } { - - // control value - let controlValue: AbstractControl = control.root.get(this.validateEqual); - - if (!controlValue) { - return undefined; - } + if (!controlValue) { + return undefined; + } - if (this.isReverse()) { - if (this.isValueEqual(control, controlValue)) { - delete controlValue.errors.validateEqual; - if (!Object.keys(controlValue.errors).length) { - controlValue.setErrors(undefined); - } - } else { - controlValue.setErrors({ - validateEqual: false, - }); - } - } else { - if (!this.isValueEqual(control, controlValue)) { - return { - validateEqual: false, - }; - } + if (this.isReverse()) { + if (this.isValueEqual(control, controlValue)) { + delete controlValue.errors.validateEqual; + if (!Object.keys(controlValue.errors).length) { + controlValue.setErrors(undefined); } - - return undefined; + } else { + controlValue.setErrors({ + validateEqual: false, + }); + } + } else { + if (!this.isValueEqual(control, controlValue)) { + return { + validateEqual: false, + }; + } } - private isValueEqual(c1: AbstractControl, c2: AbstractControl): boolean { - return c1.value === c2.value; - } + return undefined; + } - private isReverse(): boolean { - return this.reverse && this.reverse === 'true'; - } + private isValueEqual(c1: AbstractControl, c2: AbstractControl): boolean { + return c1.value === c2.value; + } + + private isReverse(): boolean { + return this.reverse && this.reverse === 'true'; + } } diff --git a/angular/src/app/sidenav/shared/sidenav.service.ts b/angular/src/app/sidenav/shared/sidenav.service.ts index 3fd274035..f47b38967 100644 --- a/angular/src/app/sidenav/shared/sidenav.service.ts +++ b/angular/src/app/sidenav/shared/sidenav.service.ts @@ -19,7 +19,7 @@ export class SidenavService { private readonly saveOrdersPath: string = 'ordermanagement/v1/order'; private orders: OrderView[] = []; - opened: boolean = false; + opened = false; constructor(private http: HttpClient) {} @@ -44,7 +44,7 @@ export class SidenavService { } public addOrder(order: OrderView): void { - let addOrder: OrderView = cloneDeep(order); + const addOrder: OrderView = cloneDeep(order); addOrder.extras = filter( addOrder.extras, (extra: ExtraView) => extra.selected, @@ -74,7 +74,7 @@ export class SidenavService { } public sendOrders(token: string): Observable { - let orderList: OrderListInfo = { + const orderList: OrderListInfo = { booking: { bookingToken: token }, orderLines: this.composeOrders(this.orders), }; @@ -87,9 +87,9 @@ export class SidenavService { } composeOrders(orders: OrderView[]): OrderInfo[] { - let composedOrders: OrderInfo[] = []; + const composedOrders: OrderInfo[] = []; orders.forEach((order: OrderView) => { - let extras: any[] = []; + const extras: any[] = []; order.extras .filter((extra: ExtraView) => extra.selected) .forEach((extra: ExtraView) => extras.push({ id: extra.id })); diff --git a/angular/src/app/sidenav/sidenav-order/sidenav-order.component.ts b/angular/src/app/sidenav/sidenav-order/sidenav-order.component.ts index 31981d06d..17246416c 100644 --- a/angular/src/app/sidenav/sidenav-order/sidenav-order.component.ts +++ b/angular/src/app/sidenav/sidenav-order/sidenav-order.component.ts @@ -13,26 +13,28 @@ import { map } from 'lodash'; styleUrls: ['./sidenav-order.component.scss'], }) export class SidenavOrderComponent implements OnInit { - extras: string; - @Input('order') order: OrderView; + @Input() order: OrderView; - constructor(private sidenav: SidenavService, - public dialog: MatDialog, - private _dialogService: TdDialogService, - private calculator: PriceCalculatorService, + constructor( + private sidenav: SidenavService, + public dialog: MatDialog, + private _dialogService: TdDialogService, + private calculator: PriceCalculatorService, ) {} ngOnInit(): void { this.extras = map(this.order.extras, 'name').join(', '); - } + } removeComment(): void { this.order.orderLine.comment = undefined; } addComment(): void { - let dialogRef: MatDialogRef = this.dialog.open(CommentDialogComponent); + const dialogRef: MatDialogRef = this.dialog.open( + CommentDialogComponent, + ); dialogRef.afterClosed().subscribe((content: string) => { this.order.orderLine.comment = content; }); @@ -61,5 +63,4 @@ export class SidenavOrderComponent implements OnInit { closeButton: 'Close', }); } - } diff --git a/angular/src/app/sidenav/sidenav.component.html b/angular/src/app/sidenav/sidenav.component.html index 74d32bfea..5dcbf4264 100644 --- a/angular/src/app/sidenav/sidenav.component.html +++ b/angular/src/app/sidenav/sidenav.component.html @@ -1,4 +1,9 @@ -
+
@@ -6,40 +11,106 @@ clear shopping_basket - {{'sidenav.title' | translate}} + {{ + 'sidenav.title' | translate + }}
-

{{'sidenav.header' | translate}}

-
- {{'sidenav.noSelection' | translate}} - +

+ {{ 'sidenav.header' | translate }} +

+
+ {{ 'sidenav.noSelection' | translate }} +
- +
-
-

{{'formFields.total' | translate}}

-

{{calculateTotal() | number : '1.2-2'}} €

+
+

{{ 'formFields.total' | translate }}

+

{{ calculateTotal() | number: '1.2-2' }} €

- -
+ +
report_problem - {{'alerts.orderID' | translate}} - + {{ 'alerts.orderID' | translate }} + +
- + - {{'formFields.terms' | translate}} + {{ + 'formFields.terms' | translate + }}
- - + +
-
\ No newline at end of file +
diff --git a/angular/tslint.json b/angular/tslint.json index 3a23fb2c3..dc3a255fe 100644 --- a/angular/tslint.json +++ b/angular/tslint.json @@ -1,154 +1,101 @@ { - "rulesDirectory": ["./node_modules/codelyzer"], + "rulesDirectory": [ + "node_modules/codelyzer" + ], "rules": { - "align": [ - true, - "statements" - ], - "array-type": [ - true, - "array" - ], - "arrow-parens": true, - "ban": [ - true, - [] - ], + "arrow-return-shorthand": true, + "callable-types": true, "class-name": true, "comment-format": [ true, "check-space" ], "curly": true, + "deprecation": { + "severity": "warn" + }, "eofline": true, - "forin": false, + "forin": true, + "import-blacklist": [ + true, + "rxjs/Rx" + ], + "import-spacing": true, "indent": [ true, "spaces" ], - "interface-name": [ - false, - "always-prefix" - ], - "jsdoc-format": true, + "interface-over-type-literal": true, "label-position": true, - "max-line-length": [true, 150], - "member-access": [ - false + "max-line-length": [ + true, + 140 ], + "member-access": false, "member-ordering": [ true, { - "order" : [ - "private-static-field", - "protected-static-field", - "public-static-field", - "private-instance-field", - "protected-instance-field", - "public-instance-field", - "constructor", - "public-static-method", - "protected-static-method", - "private-static-method", - "public-instance-method", - "protected-instance-method", - "private-instance-method" + "order": [ + "static-field", + "instance-field", + "static-method", + "instance-method" ] } ], - "new-parens": true, - "no-angle-bracket-type-assertion": false, - "no-any": false, "no-arg": true, "no-bitwise": true, - "no-conditional-assignment": true, - "no-consecutive-blank-lines": [true], "no-console": [ true, - "assert", - "count", "debug", - "dir", - "dirxml", - "error", - "group", - "groupCollapsed", - "groupEnd", "info", - "log", - "profile", - "profileEnd", - "table", "time", "timeEnd", - "timeStamp", - "trace", - "warn" + "trace" ], "no-construct": true, "no-debugger": true, - "no-default-export": true, - "no-duplicate-variable": true, - "no-empty": true, - "no-empty-interface": false, + "no-duplicate-super": true, + "no-empty": false, + "no-empty-interface": true, "no-eval": true, "no-inferrable-types": [ - false, + true, "ignore-params" ], - "no-internal-module": true, - "no-invalid-this": true, - "no-magic-numbers": false, //TODO_LINT (we should lint for this) - "no-namespace": true, - "no-null-keyword": true, - "no-reference": true, - "no-require-imports": true, + "no-misused-new": true, + "no-non-null-assertion": true, + "no-redundant-jsdoc": true, "no-shadowed-variable": true, - "no-string-literal": true, + "no-string-literal": false, "no-string-throw": true, "no-switch-case-fall-through": true, "no-trailing-whitespace": true, + "no-unnecessary-initializer": true, "no-unused-expression": true, - "no-unused-variable": true, "no-use-before-declare": true, "no-var-keyword": true, - "no-var-requires": true, "object-literal-sort-keys": false, "one-line": [ true, + "check-open-brace", "check-catch", - "check-finally", "check-else", - "check-open-brace", "check-whitespace" ], - "one-variable-per-declaration": [true], + "prefer-const": true, "quotemark": [ true, - "single", - "avoid-escape" + "single" ], "radix": true, "semicolon": [ true, "always" ], - "switch-default": true, - "trailing-comma": [ - true, - { - "multiline": "always", - "single": "always" - } - ], - "triple-equals": true, - "typedef": [ + "triple-equals": [ true, - "call-signature", - "parameter", - "property-declaration", - "variable-declaration", - "member-variable-declaration" + "allow-null-check" ], "typedef-whitespace": [ true, @@ -158,48 +105,27 @@ "parameter": "nospace", "property-declaration": "nospace", "variable-declaration": "nospace" - }, - { - "call-signature": "onespace", - "index-signature": "onespace", - "parameter": "onespace", - "property-declaration": "onespace", - "variable-declaration": "onespace" } ], - "use-isnan": true, - "variable-name": [ - true, - "ban-keywords", - "check-format", - "allow-leading-underscore" - ], + "unified-signatures": true, + "variable-name": false, "whitespace": [ true, "check-branch", "check-decl", "check-operator", - "check-module", "check-separator", "check-type" ], - // ANGULAR 2 Rules - "directive-selector": [true, "attribute", [""], "camelCase"], - "component-selector": [true, "element", ["public", "cockpit", "own"], "kebab-case"], - "component-class-suffix": true, - "directive-class-suffix": true, + "no-output-on-prefix": true, "use-input-property-decorator": true, "use-output-property-decorator": true, "use-host-property-decorator": true, - "no-attribute-parameter-decorator": true, - "no-input-rename": false, // so we can rename @Input so we can change API easier -> @Input('rename') name - "no-output-rename": false, // same but for @Output - "no-forward-ref" : false, + "no-input-rename": true, + "no-output-rename": true, "use-life-cycle-interface": true, "use-pipe-transform-interface": true, - "pipe-naming": [ - true, - "camelCase" - ] + "component-class-suffix": true, + "directive-class-suffix": true } -} +} \ No newline at end of file