Initial Commit - NG UI
[osm/NG-UI.git] / src / app / utilities / pdu-instances-action / PDUInstancesActionComponent.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: KUMARAN M (kumaran.m@tataelxsi.co.in), RAJESH S (rajesh.s@tataelxsi.co.in), BARATH KUMAR R (barath.r@tataelxsi.co.in)
17 */
18 /**
19  * @file PDUInstancesActionComponent Component
20  */
21 import { Component, Injector } from '@angular/core';
22 import { Router } from '@angular/router';
23 import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
24 import { MODALCLOSERESPONSEDATA } from 'CommonModel';
25 import { DeleteComponent } from 'DeleteComponent';
26 import { PDUInstanceDetails } from 'PDUInstanceModel';
27 import { SharedService } from 'SharedService';
28 import { ShowInfoComponent } from 'ShowInfoComponent';
29
30 /**
31  * Creating component
32  * @Component takes PDUInstancesActionComponent.html as template url
33  */
34 @Component({
35     templateUrl: './PDUInstancesActionComponent.html',
36     styleUrls: ['./PDUInstancesActionComponent.scss']
37 })
38 /** Exporting a class @exports PDUInstancesActionComponent */
39 export class PDUInstancesActionComponent {
40     /** To get the value from the PDU Instances via valuePrepareFunction default Property of ng-smarttable @public */
41     public value: PDUInstanceDetails;
42
43     /** To inject services @public */
44     public injector: Injector;
45
46     /** Instance of the modal service @private */
47     private modalService: NgbModal;
48
49     /** Contains PDU Instance ID @private */
50     private pduInstanceID: string;
51
52     /** Service holds the router information @private */
53     private router: Router;
54
55     /** Contains all methods related to shared @private */
56     private sharedService: SharedService;
57
58     constructor(injector: Injector) {
59         this.injector = injector;
60         this.modalService = this.injector.get(NgbModal);
61         this.router = this.injector.get(Router);
62         this.sharedService = this.injector.get(SharedService);
63     }
64
65     /** Lifecyle Hooks the trigger before component is instantiate @public */
66     public ngOnInit(): void {
67         this.pduInstanceID = this.value.identifier;
68     }
69
70     /** Delete PDU Instances @public */
71     public deletePDUInstance(): void {
72         const modalRef: NgbModalRef = this.modalService.open(DeleteComponent, {backdrop: 'static'});
73         modalRef.result.then((result: MODALCLOSERESPONSEDATA) => {
74             if (result) {
75                 this.sharedService.callData();
76             }
77         }).catch();
78     }
79
80     /** Shows PDU Instances information using modalservice @public */
81     public showInfo(): void {
82         this.modalService.open(ShowInfoComponent, { backdrop: 'static' }).componentInstance.params = {
83             id: this.pduInstanceID,
84             page: 'pdu-instances',
85             titleName: 'INSTANCEDETAILS'
86         };
87     }
88 }