blob: 6c21ac5aa6861dc3f4e9f21e7a51706d28bd45bc [file] [log] [blame]
kumaran.m3b4814a2020-05-01 19:48:54 +05301/*
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 */
21import { HttpClient } from '@angular/common/http';
22import { Component, Injector, Input, OnInit } from '@angular/core';
23import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
24import 'codemirror/addon/dialog/dialog';
25import 'codemirror/addon/display/autorefresh';
26import 'codemirror/addon/display/fullscreen';
27import 'codemirror/addon/edit/closebrackets';
28import 'codemirror/addon/edit/matchbrackets';
29import 'codemirror/addon/fold/brace-fold';
30import 'codemirror/addon/fold/foldcode';
31import 'codemirror/addon/fold/foldgutter';
32import 'codemirror/addon/search/search';
33import 'codemirror/addon/search/searchcursor';
34import 'codemirror/keymap/sublime';
35import 'codemirror/lib/codemirror';
36import 'codemirror/mode/javascript/javascript';
37import 'codemirror/mode/markdown/markdown';
38import 'codemirror/mode/yaml/yaml';
39import { ERRORDATA, URLPARAMS } from 'CommonModel';
40import { DataService } from 'DataService';
41import { environment } from 'environment';
42import { NSDDetails } from 'NSDModel';
43import { RestService } from 'RestService';
44/** Set defaults json as type in information modal @constant */
45const 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 */
57export 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: {} = {
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +053084 // eslint-disable-next-line no-invalid-this
kumaran.m3b4814a2020-05-01 19:48:54 +053085 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
SANDHYA.JSb772de02024-12-10 15:21:03 +0530101 /** Contains url @public */
102 public url: string;
103
kumaran.m3b4814a2020-05-01 19:48:54 +0530104 /** Check the loading results @public */
105 public isLoadingResults: Boolean = false;
106
107 /** Give the message for the loading @public */
108 public message: string = 'PLEASEWAIT';
109
110 /** Input contains component objects @private */
111 @Input() private params: URLPARAMS;
112
113 /** Instance of the rest service @private */
114 private restService: RestService;
115
116 constructor(injector: Injector) {
117 this.injector = injector;
118 this.dataService = this.injector.get(DataService);
119 this.restService = this.injector.get(RestService);
120 this.activeModal = this.injector.get(NgbActiveModal);
121 }
122
123 /**
124 * Lifecyle Hooks the trigger before component is instantiate
125 */
126 public ngOnInit(): void {
127 this.isLoadingResults = true;
128 this.defaults['text/json'] = '';
129 this.titleName = this.params.titleName;
130 // Checks page and assign URL
131 if (this.params.page === 'ns-instance') {
132 this.restService.getResource(environment.NSINSTANCESCONTENT_URL + '/' + this.params.id).subscribe((nsData: NSDDetails[]) => {
133 this.defaults['text/json'] = JSON.stringify(nsData, null, '\t');
134 }, (error: ERRORDATA) => {
135 this.isLoadingResults = false;
136 this.restService.handleError(error, 'get');
137 }, () => {
138 this.isLoadingResults = false;
139 });
140 } else if (this.params.page === 'ns-history-operation') {
141 this.restService.getResource(environment.NSHISTORYOPERATIONS_URL + '/' +
142 this.params.id).subscribe((nsHistoryOpn: {}[]) => {
143 this.defaults['text/json'] = JSON.stringify(nsHistoryOpn, null, '\t');
144 }, (error: ERRORDATA) => {
145 this.isLoadingResults = false;
146 this.restService.handleError(error, 'get');
147 }, () => {
148 this.isLoadingResults = false;
149 });
150 } else if (this.params.page === 'vnf-instance') {
151 this.restService.getResource(environment.VNFINSTANCES_URL + '/' + this.params.id).subscribe((vnfData: {}[]) => {
152 this.defaults['text/json'] = JSON.stringify(vnfData, null, '\t');
153 }, (error: ERRORDATA) => {
154 this.isLoadingResults = false;
155 this.restService.handleError(error, 'get');
156 }, () => {
157 this.isLoadingResults = false;
158 });
159 } else if (this.params.page === 'net-slice-package') {
160 this.restService.getResource(environment.NETWORKSLICETEMPLATECONTENT_URL + '/' + this.params.id).subscribe((netSliceData: {}[]) => {
161 this.defaults['text/json'] = JSON.stringify(netSliceData, null, '\t');
162 }, (error: ERRORDATA) => {
163 this.isLoadingResults = false;
164 this.restService.handleError(error, 'get');
165 }, () => {
166 this.isLoadingResults = false;
167 });
168 } else if (this.params.page === 'net-slice-instance') {
169 this.restService.getResource(environment.NETWORKSLICEINSTANCESCONTENT_URL + '/' + this.params.id)
170 .subscribe((netSliceInstanceData: {}[]) => {
171 this.defaults['text/json'] = JSON.stringify(netSliceInstanceData, null, '\t');
172 }, (error: ERRORDATA) => {
173 this.isLoadingResults = false;
174 this.restService.handleError(error, 'get');
175 }, () => {
176 this.isLoadingResults = false;
177 });
178 } else if (this.params.page === 'nst-history-operation') {
179 this.restService.getResource(environment.NSTHISTORYOPERATIONS_URL + '/' +
180 this.params.id).subscribe((nstHistoryOpn: {}[]) => {
181 this.defaults['text/json'] = JSON.stringify(nstHistoryOpn, null, '\t');
182 }, (error: ERRORDATA) => {
183 this.isLoadingResults = false;
184 this.restService.handleError(error, 'get');
185 }, () => {
186 this.isLoadingResults = false;
187 });
188 } else if (this.params.page === 'pdu-instances') {
189 this.restService.getResource(environment.PDUINSTANCE_URL + '/' +
190 this.params.id).subscribe((pduInstanceOpn: {}[]) => {
191 this.defaults['text/json'] = JSON.stringify(pduInstanceOpn, null, '\t');
192 }, (error: ERRORDATA) => {
193 this.isLoadingResults = false;
194 this.restService.handleError(error, 'get');
195 }, () => {
196 this.isLoadingResults = false;
197 });
198 } else if (this.params.page === 'k8s-cluster') {
SANDHYA.JSb772de02024-12-10 15:21:03 +0530199 if (this.params.createdbyosm === 'true') {
200 this.url = environment.K8SCREATECLUSTER_URL + '/' + this.params.id;
201 } else {
202 if (this.params.bootstrap === true) {
203 this.url = environment.K8SCREATECLUSTER_URL + '/' + this.params.id;
204 } else if (this.params.bootstrap === false && this.params.key === false) {
205 this.url = environment.K8SCREATECLUSTER_URL + '/' + this.params.id;
206 } else if (this.params.bootstrap === false && this.params.key === true) {
207 this.url = environment.K8SCLUSTER_URL + '/' + this.params.id;
208 }
209 }
210 this.restService.getResource(this.url).subscribe((k8sclusterOpn: {}[]) => {
211 this.defaults['text/json'] = JSON.stringify(k8sclusterOpn, null, '\t');
212 }, (error: ERRORDATA) => {
213 this.isLoadingResults = false;
214 this.restService.handleError(error, 'get');
215 }, () => {
216 this.isLoadingResults = false;
217 });
kumaran.m3b4814a2020-05-01 19:48:54 +0530218 } else if (this.params.page === 'k8s-repo') {
219 this.restService.getResource(environment.K8REPOS_URL + '/' +
220 this.params.id).subscribe((k8srepoOpn: {}[]) => {
221 this.defaults['text/json'] = JSON.stringify(k8srepoOpn, null, '\t');
222 }, (error: ERRORDATA) => {
223 this.isLoadingResults = false;
224 this.restService.handleError(error, 'get');
225 }, () => {
226 this.isLoadingResults = false;
227 });
228 }
229 }
230}