FM GUI as an NPM library for GUI 2

* added dynamic loading of external modules
* new commands on Alarm to allow create/updating/delete
* new fields in alarm gui

Change-Id: I9a7f4d665618a7949bb02039374974dabf6e5363
diff --git a/apps/faultmanagement/fm-gui2-lib/projects/fm-gui2-lib/src/lib/alarmtable/alarmtable.component.css b/apps/faultmanagement/fm-gui2-lib/projects/fm-gui2-lib/src/lib/alarmtable/alarmtable.component.css
new file mode 100644
index 0000000..c7af5aa
--- /dev/null
+++ b/apps/faultmanagement/fm-gui2-lib/projects/fm-gui2-lib/src/lib/alarmtable/alarmtable.component.css
@@ -0,0 +1,21 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* css for alarm table view */
+
+#ov-alarm-table h2 {
+    display: inline-block;
+}
diff --git a/apps/faultmanagement/fm-gui2-lib/projects/fm-gui2-lib/src/lib/alarmtable/alarmtable.component.html b/apps/faultmanagement/fm-gui2-lib/projects/fm-gui2-lib/src/lib/alarmtable/alarmtable.component.html
new file mode 100644
index 0000000..534819e
--- /dev/null
+++ b/apps/faultmanagement/fm-gui2-lib/projects/fm-gui2-lib/src/lib/alarmtable/alarmtable.component.html
@@ -0,0 +1,87 @@
+<!--
+~ Copyright 2018-present Open Networking Foundation
+~
+~ Licensed under the Apache License, Version 2.0 (the "License");
+~ you may not use this file except in compliance with the License.
+~ You may obtain a copy of the License at
+~
+~     http://www.apache.org/licenses/LICENSE-2.0
+~
+~ Unless required by applicable law or agreed to in writing, software
+~ distributed under the License is distributed on an "AS IS" BASIS,
+~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+~ See the License for the specific language governing permissions and
+~ limitations under the License.
+-->
+<div id="ov-alarm-table">
+  <div class="tabular-header">
+    <h2>Alarms  for {{ "all devices."}} ({{ tableData.length }} total)</h2>
+    <div class="ctrl-btns">
+      <div class="refresh" (click)="toggleRefresh()">
+        <!-- See icon.theme.css for the defintions of the classes active and refresh-->
+        <onos-icon classes="{{ autoRefresh?'active refresh':'refresh' }}" iconId="refresh" iconSize="36" toolTip="{{ autoRefreshTip }}"></onos-icon>
+      </div>
+      <!--div class="separator"></div>
+      <div (click)="(!!selId) ? confirmAction(AlarmActionEnum.ACKNOWLEDGE) : ''">
+        <onos-icon classes="{{ ctrlBtnState.acknowledged?'active-rect play':'play' }}"
+                   iconId="play" iconSize="42" toolTip="{{ acknowledgeTip }}"></onos-icon>
+      </div>
+      <div (click)="(!!selId) ? confirmAction(AlarmActionEnum.CLEAR) : ''">
+        <onos-icon classes="{{ ctrlBtnState.cleared?'active-rect stop':'stop' }}"
+                   iconId="stop" iconSize="42" toolTip="{{ clearTip }}"></onos-icon>
+      </div-->
+    </div>
+  </div>
+
+  <div class="summary-list" class="summary-list" onosTableResize>
+
+    <div class="table-header">
+      <table>
+        <tr>
+          <td colId="alarmId" (click)="onSort('id')">Id
+              <onos-icon classes="active-sort" [iconSize]="10" [iconId]="sortIcon('id')"></onos-icon>
+          </td>
+          <td colId="alarmDeviceId" (click)="onSort('alarmDeviceId')">Device
+              <onos-icon classes="active-sort" [iconSize]="10" [iconId]="sortIcon('alarmDeviceId')"></onos-icon>
+          </td>
+          <td colId="alarmDesc" (click)="onSort('alarmDesc')">Description
+              <onos-icon classes="active-sort" [iconSize]="10" [iconId]="sortIcon('alarmDesc')"></onos-icon>
+          </td>
+          <td colId="alarmSource" (click)="onSort('alarmSource')">Source
+              <onos-icon classes="active-sort" [iconSize]="10" [iconId]="sortIcon('alarmSource')"></onos-icon>
+          </td>
+          <td colId="alarmTimeRaised" (click)="onSort('alarmTimeRaised')">Time Raised
+              <onos-icon classes="active-sort" [iconSize]="10" [iconId]="sortIcon('alarmTimeRaised')"></onos-icon>
+          </td>
+          <td colId="alarmSeverity" (click)="onSort('alarmSeverity')">Severity
+              <onos-icon classes="active-sort" [iconSize]="10" [iconId]="sortIcon('alarmSeverity')"></onos-icon>
+          </td>
+          <td colId="alarmAcknowledged" (click)="onSort('alarmAcknowledged')">Acknowledged
+              <onos-icon classes="active-sort" [iconSize]="10" [iconId]="sortIcon('alarmAcknowledged')"></onos-icon>
+          </td>
+        </tr>
+      </table>
+    </div>
+
+    <div class="table-body">
+      <table>
+        <tr class="table-body" *ngIf="tableData.length === 0" class="no-data">
+          <td colspan="9">{{ annots.noRowsMsg }}</td>
+        </tr>
+        <tr *ngFor="let item of tableData | filter : tableDataFilter" (click)="selectCallback($event, item)" [ngClass]="{selected: item.id === selId, 'data-change': isChanged(item.id)}">
+          <td>{{ item.id }}</td>
+          <td>{{ item.alarmDeviceId }}</td>
+          <td>{{ item.alarmDesc }}</td>
+          <td>{{ item.alarmSource }}</td>
+          <td>{{ item.alarmTimeRaised }}</td>
+          <td>{{ item.alarmSeverity }}</td>
+          <td class="table-icon">
+            <onos-icon [iconId]="ackIcon(item.alarmAcknowledged)"></onos-icon>
+          </td>
+        </tr>
+      </table>
+    </div>
+  </div>
+
+  <onos-alarmdetails class="floatpanels" id="{{ selId }}" (closeEvent)="deselectRow($event)"></onos-alarmdetails>
+</div>
diff --git a/apps/faultmanagement/fm-gui2-lib/projects/fm-gui2-lib/src/lib/alarmtable/alarmtable.component.spec.ts b/apps/faultmanagement/fm-gui2-lib/projects/fm-gui2-lib/src/lib/alarmtable/alarmtable.component.spec.ts
new file mode 100644
index 0000000..ccad204
--- /dev/null
+++ b/apps/faultmanagement/fm-gui2-lib/projects/fm-gui2-lib/src/lib/alarmtable/alarmtable.component.spec.ts
@@ -0,0 +1,111 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+import { async, ComponentFixture, TestBed } from '@angular/core/testing';
+import { ActivatedRoute, Params } from '@angular/router';
+import { DebugElement } from '@angular/core';
+import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
+import { FormsModule } from '@angular/forms';
+import { By } from '@angular/platform-browser';
+import { AlarmTableComponent } from './alarmtable.component';
+import { AlarmDetailsComponent } from '../alarmdetails/alarmdetails.component';
+import {
+    FnService,
+    IconService,
+    GlyphService,
+    IconComponent,
+    LoadingService,
+    LogService,
+    NavService,
+    MastService,
+    TableFilterPipe,
+    ThemeService,
+    WebSocketService
+} from 'gui2-fw-lib';
+
+import { of } from 'rxjs';
+import { } from 'jasmine';
+import { RouterTestingModule } from '@angular/router/testing';
+
+class MockActivatedRoute extends ActivatedRoute {
+    constructor(params: Params) {
+        super();
+        this.queryParams = of(params);
+    }
+}
+
+class MockIconService {
+    loadIconDef() { }
+}
+
+class MockLoadingService {
+    startAnim() { }
+    stop() { }
+    waiting() { }
+}
+
+describe('AlarmTableComponent', () => {
+    let fs: FnService;
+    let ar: MockActivatedRoute;
+    let windowMock: Window;
+    let logServiceSpy: jasmine.SpyObj<LogService>;
+    let component: AlarmTableComponent;
+    let fixture: ComponentFixture<AlarmTableComponent>;
+
+    beforeEach(async(() => {
+        const logSpy = jasmine.createSpyObj('LogService', ['info', 'debug', 'warn', 'error']);
+        ar = new MockActivatedRoute({ 'debug': 'txrx' });
+
+        windowMock = <any>{
+            location: <any>{
+                hostname: 'foo',
+                host: 'foo',
+                port: '80',
+                protocol: 'http',
+                search: { debug: 'true' },
+                href: 'ws://foo:123/onos/ui/websock/path',
+                absUrl: 'ws://foo:123/onos/ui/websock/path'
+            }
+        };
+        fs = new FnService(ar, logSpy, windowMock);
+
+        TestBed.configureTestingModule({
+            imports: [BrowserAnimationsModule, FormsModule, RouterTestingModule],
+            declarations: [
+                AlarmTableComponent, AlarmDetailsComponent,
+                IconComponent, TableFilterPipe
+             ],
+            providers: [
+                { provide: FnService, useValue: fs },
+                { provide: LogService, useValue: logSpy },
+                { provide: LoadingService, useClass: MockLoadingService },
+                { provide: IconService, useClass: MockIconService },
+                { provide: 'Window', useValue: windowMock },
+            ]
+        })
+        .compileComponents();
+        logServiceSpy = TestBed.get(LogService);
+    }));
+
+    beforeEach(() => {
+        fixture = TestBed.createComponent(AlarmTableComponent);
+        component = fixture.componentInstance;
+        fixture.detectChanges();
+    });
+
+    it('should create', () => {
+        expect(component).toBeTruthy();
+    });
+});
diff --git a/apps/faultmanagement/fm-gui2-lib/projects/fm-gui2-lib/src/lib/alarmtable/alarmtable.component.ts b/apps/faultmanagement/fm-gui2-lib/projects/fm-gui2-lib/src/lib/alarmtable/alarmtable.component.ts
new file mode 100644
index 0000000..d2e46b2
--- /dev/null
+++ b/apps/faultmanagement/fm-gui2-lib/projects/fm-gui2-lib/src/lib/alarmtable/alarmtable.component.ts
@@ -0,0 +1,185 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+import { Component, Input, Inject, OnInit, OnDestroy } from '@angular/core';
+import { ActivatedRoute } from '@angular/router';
+import {
+    FnService,
+    LoadingService,
+    LogService,
+    WebSocketService,
+    SortDir, TableBaseImpl, TableResponse
+} from 'gui2-fw-lib';
+
+/**
+ * Model of the response from the WebSocket
+ */
+export interface AlarmTableResponse extends TableResponse {
+    alarmTables: Alarm[];
+}
+
+/**
+ * Model of the alarms returned from the WebSocket
+ */
+export interface Alarm {
+    id: string;
+    alarmDesc: string;
+    alarmDeviceId: string;
+    alarmSource: string;
+    alarmTimeRaised: string;
+    alarmTimeUpdated: string;
+    alarmTimeCleared: string;
+    alarmSeverity: string;
+}
+
+export enum AlarmAction {
+    NONE = 0,
+    ACKNOWLEDGE = 1,
+    CLEAR = 2,
+}
+
+/**
+ * Model of the Control Button
+ */
+export interface CtrlBtnState {
+    acknowledged: boolean;
+    cleared: boolean;
+    selection: string;
+}
+
+const ACKNOWLEDGED = 'ACKNOWLEDGED';
+const CLEARED = 'CLEARED';
+
+/**
+* ONOS GUI -- Alarm Table Component extends TableBaseImpl
+*/
+@Component({
+    selector: 'onos-alarmtable',
+    templateUrl: './alarmtable.component.html',
+    styleUrls: ['./alarmtable.component.css', '../../../fw/widget/table.css', '../../../fw/widget/table.theme.css']
+})
+export class AlarmTableComponent extends TableBaseImpl implements OnInit, OnDestroy {
+    devId: string;
+    selRowAlarmId: string;
+    // TODO Add in LION translations
+    acknowledgeTip: string = 'Acknowledge';
+    clearTip: string = 'Clear';
+    AlarmActionEnum: any = AlarmAction;
+    alarmAction: AlarmAction = AlarmAction.NONE;
+    confirmMsg: string = '';
+    ctrlBtnState: CtrlBtnState;
+
+    constructor(
+        private route: ActivatedRoute,
+        @Inject('Window') private w: any,
+        protected log: LogService,
+        protected ls: LoadingService,
+        protected fs: FnService,
+        protected wss: WebSocketService,
+    ) {
+        super(fs, ls, log, wss, 'alarmTable');
+
+        this.route.queryParams.subscribe(params => {
+            this.devId = params['devId'];
+
+        });
+
+        this.payloadParams = {
+            devId: this.devId
+        };
+
+        this.responseCallback = this.alarmResponseCb;
+
+        this.sortParams = {
+            firstCol: 'alarmTimeRaised',
+            firstDir: SortDir.desc,
+            secondCol: 'alarmDeviceId',
+            secondDir: SortDir.asc,
+        };
+
+        this.ctrlBtnState = <CtrlBtnState>{
+            acknowledged: false,
+            cleared: false
+        };
+        this.log.debug('AlarmTableComponent constructed');
+    }
+
+    ngOnInit() {
+        this.init();
+        this.log.debug('AlarmTableComponent initialized');
+    }
+
+    ngOnDestroy() {
+        this.destroy();
+        this.log.debug('AlarmTableComponent destroyed');
+    }
+
+    alarmResponseCb(data: AlarmTableResponse) {
+        this.log.debug('Alarm response received for ', data.alarmTables.length, 'alarm');
+    }
+
+    rowSelection(event: any, selRow: any) {
+        this.ctrlBtnState.acknowledged = this.selId && selRow && selRow.state === ACKNOWLEDGED;
+        this.ctrlBtnState.cleared = this.selId && selRow && selRow.cleared === CLEARED;
+        this.ctrlBtnState.selection = this.selId;
+        this.selRowAlarmId = selRow.appId;
+        this.log.debug('Row ', this.selId, 'selected', this.ctrlBtnState);
+    }
+
+    /**
+     * Perform one of the alarm actions - acknowledge or clear
+     * Raises a dialog which calls back the dOk() below
+     */
+    confirmAction(action: AlarmAction): void {
+        this.alarmAction = action;
+        const alarmActionLc = (<string>AlarmAction[this.alarmAction]).toLowerCase();
+
+        this.confirmMsg = alarmActionLc + ' ' + this.selId + '?';
+
+        this.log.debug('Initiating', this.alarmAction, 'of', this.selId);
+    }
+
+    /**
+     * Callback when the Confirm dialog is shown and a choice is made
+     */
+    dOk(choice: boolean) {
+        const alarmActionLc = (<string>AlarmAction[this.alarmAction]).toLowerCase();
+        if (choice) {
+            this.log.debug('Confirmed', alarmActionLc, 'on', this.selId);
+
+            /** commented out until backend is implemented
+            this.wss.sendEvent(APPMGMTREQ, {
+                action: alarmActionLc,
+                name: this.selId,
+                sortCol: this.sortParams.firstCol,
+                sortDir: SortDir[this.sortParams.firstDir],
+            });
+
+            this.wss.sendEvent(DETAILSREQ, { id: this.selId });
+            */
+        } else {
+            this.log.debug('Cancelled', alarmActionLc, 'on', this.selId);
+        }
+        this.confirmMsg = '';
+    }
+
+    ackIcon(acknowledged: string): string {
+        if (acknowledged === 'true') {
+            return 'active';
+        } else {
+            return 'appInactive';
+        }
+    }
+}