| import { Component, AfterViewInit, ViewChildren, QueryList, OnInit, EventEmitter, HostBinding } from '@angular/core'; |
| import { SessionContext } from '../../common/session-context'; |
| import { LogoutComponent } from '../../dialogs/logout/logout.component'; |
| import { ResponsibilityComponent } from '../../dialogs/responsibility/responsibility.component'; |
| import { EntryComponent } from '../../dialogs/entry/entry.component'; |
| import { ShiftChangeComponent } from '../../dialogs/shift-change/shift-change.component'; |
| import { ShiftChangeProtocolComponent } from '../../dialogs/shift-change-protocol/shift-change-protocol.component'; |
| import { MdDialog, MdDialogConfig } from '@angular/material'; |
| import { User } from '../../model/user'; |
| import { Notification } from '../../model/notification'; |
| import { AbstractListComponent } from '../../lists/abstract-list/abstract-list.component'; |
| import { FinishedNotificationsComponent } from '../../lists/finished-notifications/finished-notifications.component'; |
| import { FutureNotificationsComponent } from '../../lists/future-notifications/future-notifications.component'; |
| import { OpenNotificationsComponent } from '../../lists/open-notifications/open-notifications.component'; |
| import { StatusEn, BannerMessageStatusEn } from '../../common/enums'; |
| import { BannerMessage } from '../../common/banner-message'; |
| import { TerritoryResponsibility } from '../../model/territory-responsibility'; |
| import { ResponsibilityService } from '../../services/responsibility.service'; |
| import { FilterComponent } from '../../filter/filter.component'; |
| |
| import { slideInOpacity } from '../../common/router.animations'; |
| |
| @Component({ |
| selector: 'app-overview', |
| templateUrl: './overview.component.html', |
| styleUrls: ['./overview.component.css'], |
| animations: [slideInOpacity()] |
| }) |
| |
| export class OverviewComponent implements OnInit { |
| |
| @HostBinding('@slideInOpacity') get slideInOpacity(){ |
| return ''; |
| } |
| private dialogConfig = new MdDialogConfig(); |
| private bannerMessageStatus = BannerMessageStatusEn; |
| private notifications = null; |
| |
| |
| showReminder = true; |
| user: User = null; |
| responsiblitiesRetrieveDone = false; |
| |
| bannerMessage: BannerMessage = new BannerMessage(); |
| responsibilitiesContainer: TerritoryResponsibility[]; |
| shiftChangeClosed = false; |
| shiftChangeOpened = false; |
| filterExpanded_ = false; |
| |
| constructor( |
| public dialog: MdDialog, |
| public sessionContext: SessionContext, |
| private responsibilityService: ResponsibilityService |
| ) { } |
| |
| ngOnInit() { |
| this.dialogConfig.disableClose = true; |
| this.user = this.sessionContext.getCurrUser(); |
| this.filterExpanded_ = this.sessionContext.getFilterExpansionState(); |
| this.getResponsibilities(); |
| } |
| |
| private getResponsibilities(): void { |
| this.responsibilityService.getPlannedResponsibilities().subscribe(resps => { |
| this.responsiblitiesRetrieveDone = true; |
| if (resps.length > 0) { |
| this.responsibilitiesContainer = resps; |
| this.openDialogShiftChangeProtocol(resps); |
| } else { |
| this.responsibilityService.getResponsibilities().subscribe(respsCurrent => { |
| this.responsibilitiesContainer = respsCurrent; |
| }, |
| error => { |
| console.log(error); |
| this.setError(error); |
| this.responsiblitiesRetrieveDone = true; |
| }); |
| } |
| }, |
| error => { |
| console.log(error); |
| this.setError(error); |
| this.responsiblitiesRetrieveDone = true; |
| } |
| ); |
| } |
| |
| openDialogNewEntry() { |
| const dialogRef = this.dialog.open(EntryComponent, this.dialogConfig); |
| dialogRef.componentInstance.isInstructionDialog = false; |
| dialogRef.componentInstance.user = this.user; |
| dialogRef.componentInstance.isEditDialog = false; |
| dialogRef.afterClosed().subscribe(result => { |
| }); |
| } |
| |
| openInstructionDialogNewEntry() { |
| const dialogRef = this.dialog.open(EntryComponent, this.dialogConfig); |
| dialogRef.componentInstance.isInstructionDialog = true; |
| dialogRef.componentInstance.user = this.user; |
| dialogRef.componentInstance.isEditDialog = false; |
| dialogRef.afterClosed().subscribe(result => { |
| }); |
| } |
| |
| openDialogEditEntry(notification: Notification) { |
| const dialogRef = this.dialog.open(EntryComponent, this.dialogConfig); |
| dialogRef.componentInstance.user = this.user; |
| dialogRef.componentInstance.isInstructionDialog = notification.adminFlag; |
| dialogRef.componentInstance.setNotification(notification); |
| dialogRef.componentInstance.isEditDialog = true; |
| dialogRef.afterClosed().subscribe(result => { |
| }); |
| } |
| |
| openDialogLookUpEntry(notification: Notification) { |
| const dialogRef = this.dialog.open(EntryComponent, this.dialogConfig); |
| dialogRef.componentInstance.user = this.user; |
| dialogRef.componentInstance.setNotification(notification); |
| dialogRef.componentInstance.isReadOnlyDialog = true; |
| dialogRef.afterClosed().subscribe(result => { |
| }); |
| } |
| |
| openDialogShiftChange() { |
| const dialogRef = this.dialog.open(ShiftChangeComponent, this.dialogConfig); |
| dialogRef.afterClosed().subscribe(result => { |
| if (dialogRef.componentInstance.isChangingShift) { |
| this.openDialogLogout(); |
| } |
| }); |
| } |
| |
| openDialogShiftChangeProtocol(responsibilitiesContainer: TerritoryResponsibility[]) { |
| const dialogRef = this.dialog.open(ShiftChangeProtocolComponent, this.dialogConfig); |
| this.shiftChangeOpened = true; |
| const self = this; |
| dialogRef.componentInstance.setResponsibilitiesContainer(responsibilitiesContainer); |
| dialogRef.afterClosed().subscribe(result => { |
| this.shiftChangeClosed = true; |
| this.shiftChangeOpened = false; |
| }); |
| } |
| |
| openDialogDataImport() { |
| /* |
| const dialogRef = this.dialog.open(ShiftChangeComponent, this.dialogConfig); |
| dialogRef.afterClosed().subscribe(result => { |
| if (dialogRef.componentInstance.isChangingShift) { |
| this.openDialogLogout(); |
| } |
| }); |
| */ |
| } |
| |
| openDialogLogout() { |
| this.dialogConfig.data = this; |
| const dialogRef = this.dialog.open(LogoutComponent, this.dialogConfig); |
| dialogRef.afterClosed().subscribe(result => { |
| }); |
| } |
| |
| isSpecialUser(): boolean { |
| return this.user && this.user.specialUser; |
| } |
| |
| private setError(errorMessage: string) { |
| this.bannerMessage.isActive = true; |
| this.bannerMessage.status = BannerMessageStatusEn.error; |
| this.bannerMessage.text = 'Es ist ein Fehler aufgetreten. Bitte kontaktieren Sie den Administrator'; |
| console.log(errorMessage); |
| } |
| } |