/*-------------------------------------------------------------------------------------------------------------- * Copyright (c) insite-gmbh. All rights reserved. * Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------------------------*/ import { Component, OnInit, OnDestroy } from '@angular/core'; import { ActivatedRoute } from '@angular/router'; import { InaxAlarmService, AlarmListChangeEvent, IHmiAlarmEntry } from '../../../../@inax/alarm'; import { InaxTranslateService } from '../../../../@inax/translate'; import { Subscription } from 'rxjs/Rx'; export abstract class AlarmListComponent implements OnInit, OnDestroy { private _translateSubscription : Subscription; private _alarmSubscription : Subscription; protected _filter: string = ""; protected _currentSortOrder: string = ""; private _entriesPerPage: number = 20; private _currentPage: number = 1; public title: string = ""; public firstPage: number = 1; public numberOfAlarms: number = 0; public alarms: Array = []; public columnTitle: Map = new Map(); public get dataChangeIsAvailable():boolean{ return this._inaxAlarm.dataChangeIsAvailable; } public get currentPage():number{ return this._currentPage; } public get skip(): number{ return (this.currentPage-1)*this._entriesPerPage; } public get entriesPerPage(): number{ return this._entriesPerPage; } public get numberOfPages():number{ return Math.floor(this.numberOfAlarms / this._entriesPerPage) + 1; } constructor(protected _inaxAlarm: InaxAlarmService, protected _inaxTranslate: InaxTranslateService) { } ngOnInit() { //subscribe to the services this._translateSubscription = this._inaxTranslate.ChangeEvent.subscribe( lng => this.updateAlarms()); this._alarmSubscription = this._inaxAlarm.ChangeEvent.subscribe( (alarmListEvent: AlarmListChangeEvent) =>{ this.updateAlarms(); }); this.updateAlarms(); } ngOnDestroy() { //unsubscribe from the services if(this._alarmSubscription != null) this._alarmSubscription.unsubscribe(); if(this._translateSubscription != null) this._translateSubscription.unsubscribe(); } public sortBy(propertyName:string){ if(propertyName == null) return; if (this._currentSortOrder.indexOf(propertyName) > -1) { if (this._currentSortOrder.indexOf("desc") > -1) { this._currentSortOrder = ""; this.columnTitle[propertyName] = ""; } else { this._currentSortOrder = propertyName + " desc"; this.columnTitle[propertyName] = " (desc)"; } } else { var val = this._currentSortOrder.replace(' desc', ''); this.columnTitle[val] = ""; this._currentSortOrder = propertyName; this.columnTitle[propertyName] = " (asc)"; } this.updateAlarms(); } public onpageChanged(page:number){ this._currentPage = page; this.updateAlarms(); } public abstract async updateAlarms(): Promise; public lineColor(entry:IHmiAlarmEntry):string{ return entry.LineColore; } }