| import { Component, OnDestroy, OnInit, Input, Output, EventEmitter, AfterViewChecked, SimpleChanges, OnChanges } from '@angular/core'; |
| import { NotificationService } from '../../services/notification.service'; |
| import { ReminderService } from '../../services/reminder.service'; |
| import { Notification } from '../../model/notification'; |
| import { SessionContext } from '../../common/session-context'; |
| import { DaterangepickerConfig } from 'ng2-daterangepicker'; |
| import { Router } from '@angular/router'; |
| import { StatusEn } from '../../common/enums'; |
| import { Globals } from '../../common/globals'; |
| import { TerritoryResponsibility } from '../../model/territory-responsibility'; |
| import { NotificationSearchFilter } from '../../model/notification-search-filter'; |
| import { ResponsibilitySearchFilter } from '../../model/responsibility-search-filter'; |
| import { NotificationHistoryExpansionState } from '../../model/notificationhistoryexpansionstate'; |
| import { ResponsibilityService } from '../../services/responsibility.service'; |
| import { User } from '../../model/user'; |
| import { MessageService, MessageDefines } from '../../services/message.service'; |
| |
| |
| declare var $: any; |
| declare var toastr: any; |
| window['$'] = $; |
| window['jQuery'] = $; |
| |
| |
| @Component({ |
| selector: 'app-abstract-list', |
| templateUrl: './abstract-list.component.html', |
| styleUrls: ['./abstract-list.component.css'] |
| }) |
| |
| export class AbstractListComponent implements OnInit, AfterViewChecked, OnChanges, OnDestroy { |
| @Output() onEditNotification = new EventEmitter<Notification>(); |
| @Output() onLookUpNotification = new EventEmitter<Notification>(); |
| @Input() shiftChangeTransactionId: number; |
| @Input() withCheckboxes = false; |
| @Input() withDatePicker = true; |
| @Input() withEditButtons = true; |
| @Input() isCollapsible = true; |
| @Input() stayHidden = true; |
| |
| showSpinner: boolean = false; |
| globals = Globals; |
| router: Router; |
| selectAll = false; |
| defaultList: Notification[]; |
| notifications: Notification[]; |
| currentDate = new Date(); |
| responsibilitySearchFilter = new ResponsibilitySearchFilter(); |
| notificationSearchFilter = new NotificationSearchFilter(); |
| endDate: Date; |
| startDate: Date; |
| user: User = null; |
| column: string; |
| |
| pager: any = {}; |
| pagedItems: any[]; |
| |
| private isDesc: boolean; |
| private notificationHistoryExpansionStates: NotificationHistoryExpansionState[] = new Array<NotificationHistoryExpansionState>(); |
| private subscriptions: Array<any>; |
| constructor( |
| protected messageService: MessageService, |
| protected notificationService: NotificationService, |
| protected reminderService: ReminderService, |
| protected sessionContext: SessionContext, |
| protected daterangepickerConfig: DaterangepickerConfig |
| ) { } |
| |
| ngOnChanges(changes: SimpleChanges) { |
| if (changes['shiftChangeTransactionId'] !== undefined && changes['shiftChangeTransactionId'].currentValue !== undefined) { |
| this.onShiftChangeTransactionChanged(); |
| } |
| } |
| |
| ngAfterViewChecked() { |
| $('[data-toggle="tooltip"]').tooltip({ container: 'body', html: true, trigger: 'hover' }); |
| } |
| |
| ngOnDestroy() { |
| this.subscriptions.forEach(item => item.unsubscribe()); |
| } |
| |
| ngOnInit() { |
| this.init(); |
| } |
| setPage(page: number) { |
| if (page < 1 || page > this.pager.totalPages) { |
| return; |
| } |
| |
| // get pager object from service |
| this.pager = this.notificationService.getPager(this.notifications.length, page); |
| |
| // get current page of items |
| this.pagedItems = this.notifications.slice(this.pager.startIndex, this.pager.endIndex + 1); |
| } |
| |
| public setDefaultList(setDefault: boolean) { |
| this.notifications = Object.assign(new Array<Notification>(), this.defaultList); |
| } |
| protected init() { |
| this.setDefaultDateRange(); |
| this.user = this.sessionContext.getCurrUser(); |
| let subscription: any; |
| this.subscriptions = new Array<any>(); |
| subscription = this.messageService.matrixFilterChanged$.subscribe(filterList => { |
| this.onFilterSelectionChanged(filterList); |
| }); |
| this.subscriptions.push(subscription); |
| |
| subscription = this.notificationService.itemAdded$.subscribe(item => this.onItemAdded(item)); |
| this.subscriptions.push(subscription); |
| |
| subscription = this.notificationService.itemChanged$.subscribe(item => this.onItemChanged(item)); |
| this.subscriptions.push(subscription); |
| |
| subscription = this.reminderService.itemAdded$.subscribe(item => this.onItemAdded(item)); |
| this.subscriptions.push(subscription); |
| |
| subscription = this.reminderService.itemChanged$.subscribe(item => this.onItemChanged(item)); |
| this.subscriptions.push(subscription); |
| |
| this.daterangepickerConfig.settings = { |
| timePicker: true, |
| timePicker24Hour: true, |
| timePickerSeconds: false, |
| timePickerIncrement: 1, |
| useCurrent: true, |
| locale: { |
| format: 'DD.MM.YYYY HH:mm', |
| applyLabel: 'Übernehmen', |
| cancelLabel: 'Abbrechen', |
| daysOfWeek: ['So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa'], |
| monthNames: ['Januar', 'Februar', 'März', 'April', 'Mai', 'Juni', 'Juli', |
| 'August', 'September', 'Oktober', 'November', 'Dezember'], |
| firstDay: 1 |
| } |
| }; |
| } |
| |
| protected setDefaultDateRange(): void { |
| |
| } |
| |
| protected onShiftChangeTransactionChanged() { |
| this.notificationSearchFilter = new NotificationSearchFilter(); |
| this.notificationSearchFilter.historicalFlag = true; |
| this.notificationSearchFilter.shiftChangeTransactionId = this.shiftChangeTransactionId; |
| this.getHistoricalNotifications(); |
| } |
| |
| protected onFilterSelectionChanged(responsibilityFilterList: number[]) { |
| this.notificationSearchFilter = new NotificationSearchFilter(); |
| this.notificationSearchFilter.responsibilityFilterList = responsibilityFilterList; |
| this.getNotifications(); |
| } |
| |
| protected onItemChanged(changedNotification: Notification): void { |
| |
| } |
| |
| |
| onItemAdded(newNotification: Notification): void { |
| |
| } |
| |
| protected setNotifications(newNotifications: Notification[]) { |
| this.notifications = newNotifications; |
| this.setPage(1); |
| newNotifications.forEach(notification => { |
| notification.historyOpen = this.getNotificationHistoryExpansionStateById(notification.incidentId); |
| if (notification.historyOpen) { |
| this.retrieveNotificationVersions(notification); |
| } |
| }); |
| this.defaultList = Object.assign(new Array<Notification>(), newNotifications); |
| } |
| |
| protected setNotificationVersions(newNotificationsVersions: Notification[], notification: Notification) { |
| notification.decoratorNotificationVersions = |
| newNotificationsVersions.filter(notificationsVersion => notificationsVersion.id !== notification.id); |
| } |
| |
| protected setError(showErr: boolean) { |
| } |
| |
| getNotifications(): void { |
| |
| } |
| getHistoricalNotifications(): void { |
| |
| } |
| |
| retrieveNotificationVersions(notification: Notification): void { |
| this.notificationService.getNotificationVersions(notification.incidentId).subscribe( |
| nots => this.setNotificationVersions(nots, notification), |
| error => { |
| console.log(error); |
| this.setError(error); |
| } |
| ); |
| } |
| |
| getNotificationVersions(notification: Notification): Notification[] { |
| return notification.decoratorNotificationVersions; |
| } |
| |
| editNotification(notification: Notification) { |
| this.onEditNotification.emit(notification); |
| } |
| |
| toggleHistoryTab(notification: Notification) { |
| notification.historyOpen = !notification.historyOpen; |
| this.setNotificationHistoryExpansionStateById(notification.incidentId, notification.historyOpen); |
| if (notification.historyOpen) { |
| this.retrieveNotificationVersions(notification); |
| } |
| } |
| |
| getNotificationHistoryExpansionStateById(id: number): boolean { |
| if (this.notificationHistoryExpansionStates) { |
| const notificationHistoryExpansionState = this.notificationHistoryExpansionStates |
| .filter(s => (s.incidentId === id) && (s.historyOpen === true))[0]; |
| |
| if (notificationHistoryExpansionState) { |
| return true; |
| } else { |
| return false; |
| } |
| } |
| return false; |
| } |
| |
| setNotificationHistoryExpansionStateById(id: number, newState: boolean): void { |
| const currentNotificationHistoryState = this.notificationHistoryExpansionStates.filter(item => item.incidentId === id)[0]; |
| if (currentNotificationHistoryState) { |
| currentNotificationHistoryState.historyOpen = newState; |
| } else { |
| const newNotificationHistoryExpansionState = new NotificationHistoryExpansionState(); |
| newNotificationHistoryExpansionState.incidentId = id; |
| newNotificationHistoryExpansionState.historyOpen = newState; |
| this.notificationHistoryExpansionStates.push(newNotificationHistoryExpansionState); |
| } |
| } |
| lookUpNotification(notification: Notification) { |
| this.onLookUpNotification.emit(notification); |
| } |
| |
| changeAllSelection(): void { |
| if (this.selectAll) { |
| for (const info of this.notifications) { |
| info.selected = true; |
| } |
| } else { |
| for (const info of this.notifications) { |
| info.selected = false; |
| } |
| } |
| } |
| |
| selectionChanged(): void { |
| if (this.notifications) { |
| let allSelected = true; |
| for (const info of this.notifications) { |
| if (!info.selected) { |
| allSelected = false; |
| break; |
| } |
| } |
| this.selectAll = allSelected; |
| } |
| } |
| |
| isSpecialUser(): boolean { |
| return this.user && this.user.specialUser; |
| } |
| |
| sort(property) { |
| this.column = property; |
| this.isDesc = !this.isDesc; |
| let direction = this.isDesc ? 1 : -1; |
| |
| this.pagedItems.sort(function (a, b) { |
| if (a[property] < b[property]) { |
| return -1 * direction; |
| } |
| else if (a[property] > b[property]) { |
| return 1 * direction; |
| } |
| else { |
| return 0; |
| } |
| }); |
| }; |
| } |