2 Copyright 2020 TATA ELXSI
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
8 http://www.apache.org/licenses/LICENSE-2.0
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.
16 Author: KUMARAN M (kumaran.m@tataelxsi.co.in), RAJESH S (rajesh.s@tataelxsi.co.in), BARATH KUMAR R (barath.r@tataelxsi.co.in)
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: {} = {
50 * @Component takes ShowInfoComponent.html as template url
53 templateUrl: './ShowInfoComponent.html',
54 styleUrls: ['./ShowInfoComponent.scss']
56 /** Exporting a class @exports ShowInfoComponent */
57 export class ShowInfoComponent implements OnInit {
58 /** Invoke service injectors @public */
59 public injector: Injector;
61 /** dataService to pass the data from one component to another @public */
62 public dataService: DataService;
64 /** Default variables holds NS data @public */
65 public defaults: {} = defaults;
67 /** Varaibles to hold http client @public */
68 public httpClient: HttpClient;
70 /** Instance for active modal service @public */
71 public activeModal: NgbActiveModal;
73 /** variables readOnly holds boolean @public */
74 public readOnly: boolean = true;
76 /** variables to hold mode changes of editor @public */
77 public mode: string = 'text/json';
79 /** To Set Mode @public */
80 public modeDefault: string = 'javascript';
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,
91 gutters: ['CodeMirror-linenumbers', 'CodeMirror-foldgutter'],
92 autoCloseBrackets: true,
98 /** Reading the page Name @public */
99 public titleName: string;
101 /** Check the loading results @public */
102 public isLoadingResults: Boolean = false;
104 /** Give the message for the loading @public */
105 public message: string = 'PLEASEWAIT';
107 /** Input contains component objects @private */
108 @Input() private params: URLPARAMS;
110 /** Instance of the rest service @private */
111 private restService: RestService;
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);
121 * Lifecyle Hooks the trigger before component is instantiate
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');
135 this.isLoadingResults = false;
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');
145 this.isLoadingResults = false;
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');
154 this.isLoadingResults = false;
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');
163 this.isLoadingResults = false;
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');
173 this.isLoadingResults = false;
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');
183 this.isLoadingResults = false;
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');
193 this.isLoadingResults = false;
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');
203 this.isLoadingResults = false;
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');
213 this.isLoadingResults = false;