Initial Commit - NG UI
[osm/NG-UI.git] / src / app / utilities / netslice-packages-action / NetslicePackagesActionComponent.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 Netslice-packagesAction 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 { InstantiateNetSliceTemplateComponent } from 'InstantiateNetSliceTemplate';
27 import { NetworkSliceData } from 'NetworkSliceModel';
28 import { SharedService } from 'SharedService';
29 import { ShowInfoComponent } from 'ShowInfoComponent';
30
31 /**
32  * Creating component
33  * @Component takes NetslicePackagesActionComponent.html as template url
34  */
35 @Component({
36     selector: 'app-netslice-packages-action',
37     templateUrl: './NetslicePackagesActionComponent.html',
38     styleUrls: ['./NetslicePackagesActionComponent.scss']
39 })
40 /** Exporting a class @exports NetslicePackagesActionComponent */
41 export class NetslicePackagesActionComponent {
42     /** To get the value from the vnfpackage via valuePrepareFunction default Property of ng-smarttable @public */
43     public value: NetworkSliceData;
44
45     /** To inject services @public */
46     public injector: Injector;
47
48     /** Instance of the modal service @private */
49     private modalService: NgbModal;
50
51     /** Contains instance ID @private */
52     private instanceID: string;
53
54     /** Service holds the router information @private */
55     private router: Router;
56
57     /** Contains all methods related to shared @private */
58     private sharedService: SharedService;
59
60     constructor(injector: Injector) {
61         this.injector = injector;
62         this.modalService = this.injector.get(NgbModal);
63         this.router = this.injector.get(Router);
64         this.sharedService = this.injector.get(SharedService);
65     }
66
67     /** Lifecyle Hooks the trigger before component is instantiate @public */
68     public ngOnInit(): void {
69         this.instanceID = this.value.identifier;
70     }
71
72     /** Delete NetSliceTemplate packages @public */
73     public deleteNetSliceTemplate(): void {
74         const modalRef: NgbModalRef = this.modalService.open(DeleteComponent, {backdrop: 'static'});
75         modalRef.result.then((result: MODALCLOSERESPONSEDATA) => {
76             if (result) {
77                 this.sharedService.callData();
78             }
79         }).catch();
80     }
81
82     /** Shows information using modalservice @public */
83     public infoNetSlice(): void {
84         this.modalService.open(ShowInfoComponent, { backdrop: 'static' }).componentInstance.params = {
85             id: this.instanceID,
86             page: 'net-slice-package',
87             titleName: 'PAGE.NETSLICETEMPLATE.NETSLICETEMPLATEDETAILS'
88         };
89     }
90
91     /** Set Edit for the  @public */
92     public netSliceEdit(): void {
93         this.router.navigate(['/packages/netslice/edit/', this.instanceID]).catch(() => {
94             // Catch Navigation Error
95         });
96     }
97
98     /** Instantiate Net Slice using modalservice @public */
99     public instantiateNetSlice(): void {
100         this.modalService.open(InstantiateNetSliceTemplateComponent, { backdrop: 'static' });
101     }
102 }