Fix Bug 2121: NG-UI uses unmaintained Chokidar version
[osm/NG-UI.git] / src / app / utilities / show-info / ShowInfoComponent.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 Info Ns Model
20  */
21 import { HttpClient } from '@angular/common/http';
22 import { Component, Injector, Input, OnInit } from '@angular/core';
23 import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
24 import 'codemirror/addon/dialog/dialog';
25 import 'codemirror/addon/display/autorefresh';
26 import 'codemirror/addon/display/fullscreen';
27 import 'codemirror/addon/edit/closebrackets';
28 import 'codemirror/addon/edit/matchbrackets';
29 import 'codemirror/addon/fold/brace-fold';
30 import 'codemirror/addon/fold/foldcode';
31 import 'codemirror/addon/fold/foldgutter';
32 import 'codemirror/addon/search/search';
33 import 'codemirror/addon/search/searchcursor';
34 import 'codemirror/keymap/sublime';
35 import 'codemirror/lib/codemirror';
36 import 'codemirror/mode/javascript/javascript';
37 import 'codemirror/mode/markdown/markdown';
38 import 'codemirror/mode/yaml/yaml';
39 import { ERRORDATA, URLPARAMS } from 'CommonModel';
40 import { DataService } from 'DataService';
41 import { environment } from 'environment';
42 import { NSDDetails } from 'NSDModel';
43 import { RestService } from 'RestService';
44 /** Set defaults json as type in information modal @constant */
45 const defaults: {} = {
46   'text/json': ''
47 };
48 /**
49  * Creating component
50  * @Component takes ShowInfoComponent.html as template url
51  */
52 @Component({
53   templateUrl: './ShowInfoComponent.html',
54   styleUrls: ['./ShowInfoComponent.scss']
55 })
56 /** Exporting a class @exports ShowInfoComponent */
57 export class ShowInfoComponent implements OnInit {
58   /** Invoke service injectors @public */
59   public injector: Injector;
60
61   /** dataService to pass the data from one component to another @public */
62   public dataService: DataService;
63
64   /** Default variables holds NS data @public */
65   public defaults: {} = defaults;
66
67   /** Varaibles to hold http client @public */
68   public httpClient: HttpClient;
69
70   /** Instance for active modal service @public */
71   public activeModal: NgbActiveModal;
72
73   /** variables readOnly holds boolean @public */
74   public readOnly: boolean = true;
75
76   /** variables to hold mode changes of editor @public */
77   public mode: string = 'text/json';
78
79   /** To Set Mode @public */
80   public modeDefault: string = 'javascript';
81
82   /** variables to hold options of editor @public */
83   public options: {} = {
84     // eslint-disable-next-line no-invalid-this
85     mode: this.modeDefault,
86     showCursorWhenSelecting: true,
87     autofocus: true,
88     lineNumbers: true,
89     lineWrapping: true,
90     foldGutter: true,
91     gutters: ['CodeMirror-linenumbers', 'CodeMirror-foldgutter'],
92     autoCloseBrackets: true,
93     matchBrackets: true,
94     theme: 'neat',
95     keyMap: 'sublime'
96   };
97
98   /** Reading the page Name @public */
99   public titleName: string;
100
101   /** Check the loading results @public */
102   public isLoadingResults: Boolean = false;
103
104   /** Give the message for the loading @public */
105   public message: string = 'PLEASEWAIT';
106
107   /** Input contains component objects @private */
108   @Input() private params: URLPARAMS;
109
110   /** Instance of the rest service @private */
111   private restService: RestService;
112
113   constructor(injector: Injector) {
114     this.injector = injector;
115     this.dataService = this.injector.get(DataService);
116     this.restService = this.injector.get(RestService);
117     this.activeModal = this.injector.get(NgbActiveModal);
118   }
119
120   /**
121    * Lifecyle Hooks the trigger before component is instantiate
122    */
123   public ngOnInit(): void {
124     this.isLoadingResults = true;
125     this.defaults['text/json'] = '';
126     this.titleName = this.params.titleName;
127     // Checks page and assign URL
128     if (this.params.page === 'ns-instance') {
129       this.restService.getResource(environment.NSINSTANCESCONTENT_URL + '/' + this.params.id).subscribe((nsData: NSDDetails[]) => {
130         this.defaults['text/json'] = JSON.stringify(nsData, null, '\t');
131       }, (error: ERRORDATA) => {
132         this.isLoadingResults = false;
133         this.restService.handleError(error, 'get');
134       }, () => {
135         this.isLoadingResults = false;
136       });
137     } else if (this.params.page === 'ns-history-operation') {
138       this.restService.getResource(environment.NSHISTORYOPERATIONS_URL + '/' +
139         this.params.id).subscribe((nsHistoryOpn: {}[]) => {
140           this.defaults['text/json'] = JSON.stringify(nsHistoryOpn, null, '\t');
141         }, (error: ERRORDATA) => {
142           this.isLoadingResults = false;
143           this.restService.handleError(error, 'get');
144         }, () => {
145           this.isLoadingResults = false;
146         });
147     } else if (this.params.page === 'vnf-instance') {
148       this.restService.getResource(environment.VNFINSTANCES_URL + '/' + this.params.id).subscribe((vnfData: {}[]) => {
149         this.defaults['text/json'] = JSON.stringify(vnfData, null, '\t');
150       }, (error: ERRORDATA) => {
151         this.isLoadingResults = false;
152         this.restService.handleError(error, 'get');
153       }, () => {
154         this.isLoadingResults = false;
155       });
156     } else if (this.params.page === 'net-slice-package') {
157       this.restService.getResource(environment.NETWORKSLICETEMPLATECONTENT_URL + '/' + this.params.id).subscribe((netSliceData: {}[]) => {
158         this.defaults['text/json'] = JSON.stringify(netSliceData, null, '\t');
159       }, (error: ERRORDATA) => {
160         this.isLoadingResults = false;
161         this.restService.handleError(error, 'get');
162       }, () => {
163         this.isLoadingResults = false;
164       });
165     } else if (this.params.page === 'net-slice-instance') {
166       this.restService.getResource(environment.NETWORKSLICEINSTANCESCONTENT_URL + '/' + this.params.id)
167         .subscribe((netSliceInstanceData: {}[]) => {
168           this.defaults['text/json'] = JSON.stringify(netSliceInstanceData, null, '\t');
169         }, (error: ERRORDATA) => {
170           this.isLoadingResults = false;
171           this.restService.handleError(error, 'get');
172         }, () => {
173           this.isLoadingResults = false;
174         });
175     } else if (this.params.page === 'nst-history-operation') {
176       this.restService.getResource(environment.NSTHISTORYOPERATIONS_URL + '/' +
177         this.params.id).subscribe((nstHistoryOpn: {}[]) => {
178           this.defaults['text/json'] = JSON.stringify(nstHistoryOpn, null, '\t');
179         }, (error: ERRORDATA) => {
180           this.isLoadingResults = false;
181           this.restService.handleError(error, 'get');
182         }, () => {
183           this.isLoadingResults = false;
184         });
185     } else if (this.params.page === 'pdu-instances') {
186       this.restService.getResource(environment.PDUINSTANCE_URL + '/' +
187         this.params.id).subscribe((pduInstanceOpn: {}[]) => {
188           this.defaults['text/json'] = JSON.stringify(pduInstanceOpn, null, '\t');
189         }, (error: ERRORDATA) => {
190           this.isLoadingResults = false;
191           this.restService.handleError(error, 'get');
192         }, () => {
193           this.isLoadingResults = false;
194         });
195     } else if (this.params.page === 'k8s-cluster') {
196       this.restService.getResource(environment.K8SCLUSTER_URL + '/' +
197         this.params.id).subscribe((k8sclusterOpn: {}[]) => {
198           this.defaults['text/json'] = JSON.stringify(k8sclusterOpn, null, '\t');
199         }, (error: ERRORDATA) => {
200           this.isLoadingResults = false;
201           this.restService.handleError(error, 'get');
202         }, () => {
203           this.isLoadingResults = false;
204         });
205     } else if (this.params.page === 'k8s-repo') {
206       this.restService.getResource(environment.K8REPOS_URL + '/' +
207         this.params.id).subscribe((k8srepoOpn: {}[]) => {
208           this.defaults['text/json'] = JSON.stringify(k8srepoOpn, null, '\t');
209         }, (error: ERRORDATA) => {
210           this.isLoadingResults = false;
211           this.restService.handleError(error, 'get');
212         }, () => {
213           this.isLoadingResults = false;
214         });
215     }
216   }
217 }