Feature-9904: Enhancing NG-UI to enable Juju operational view dashboard
[osm/NG-UI.git] / src / app / operational-view / operational-view-app-executed-actions / OperationalViewAppExecutedActionsComponent.ts
1 /*
2  Copyright 2020 TATA ELXSI
3
4  Licensed under the Apache License, Version 2.0 (the 'License');
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7
8     http://www.apache.org/licenses/LICENSE-2.0
9
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15
16  Author: BARATH KUMAR R (barath.r@tataelxsi.co.in)
17 */
18
19 /**
20  * @file Page for Operational View App Executed actions Component
21  */
22 import { Component, Injector, Input, OnInit } from '@angular/core';
23 import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
24 import { URLPARAMS } from 'CommonModel';
25 import { EXECUTEDACTIONS } from 'OperationalModel';
26 import { isNullOrUndefined } from 'util';
27 /**
28  * Creating component
29  * @Component takes OperationalViewAppExecutedActionsComponent.html as template url
30  */
31 @Component({
32   selector: 'app-operational-view-executed-app-actions',
33   templateUrl: './OperationalViewAppExecutedActionsComponent.html'
34 })
35 /** Exporting a class @exports OperationalViewAppExecutedActionsComponent */
36 export class OperationalViewAppExecutedActionsComponent implements OnInit {
37   /** Invoke service injectors @public */
38   public injector: Injector;
39
40   /** Get the Executed actions data @public */
41   public executedActionsData: EXECUTEDACTIONS[];
42
43   /** Instance for active modal service @public */
44   public activeModal: NgbActiveModal;
45
46   /** Is executed action not available @public */
47   public isExecutedActionNotAvailable: boolean = false;
48
49   /** Input contains component objects @private */
50   @Input() private params: URLPARAMS;
51
52   /** creates Operational view app executed actions component */
53   constructor(injector: Injector) {
54     this.injector = injector;
55     this.activeModal = this.injector.get(NgbActiveModal);
56   }
57
58   /**
59    * Lifecyle Hooks the trigger before component is instantiate
60    */
61   public ngOnInit(): void {
62     if (!isNullOrUndefined(this.params.executedActions) && this.params.executedActions.length > 0) {
63       this.params.executedActions.sort((a: EXECUTEDACTIONS, b: EXECUTEDACTIONS): number => (+a.id > +b.id ? 1 : +a.id < +b.id ? -1 : 0));
64       this.executedActionsData = this.params.executedActions;
65     } else {
66       this.isExecutedActionNotAvailable = true;
67     }
68   }
69 }