| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame^] | 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 | mode: this.modeDefault, |
| 85 | showCursorWhenSelecting: true, |
| 86 | autofocus: true, |
| 87 | lineNumbers: true, |
| 88 | lineWrapping: true, |
| 89 | foldGutter: true, |
| 90 | gutters: ['CodeMirror-linenumbers', 'CodeMirror-foldgutter'], |
| 91 | autoCloseBrackets: true, |
| 92 | matchBrackets: true, |
| 93 | theme: 'neat', |
| 94 | keyMap: 'sublime' |
| 95 | }; |
| 96 | |
| 97 | /** Reading the page Name @public */ |
| 98 | public titleName: string; |
| 99 | |
| 100 | /** Check the loading results @public */ |
| 101 | public isLoadingResults: Boolean = false; |
| 102 | |
| 103 | /** Give the message for the loading @public */ |
| 104 | public message: string = 'PLEASEWAIT'; |
| 105 | |
| 106 | /** Input contains component objects @private */ |
| 107 | @Input() private params: URLPARAMS; |
| 108 | |
| 109 | /** Instance of the rest service @private */ |
| 110 | private restService: RestService; |
| 111 | |
| 112 | constructor(injector: Injector) { |
| 113 | this.injector = injector; |
| 114 | this.dataService = this.injector.get(DataService); |
| 115 | this.restService = this.injector.get(RestService); |
| 116 | this.activeModal = this.injector.get(NgbActiveModal); |
| 117 | } |
| 118 | |
| 119 | /** |
| 120 | * Lifecyle Hooks the trigger before component is instantiate |
| 121 | */ |
| 122 | public ngOnInit(): void { |
| 123 | this.isLoadingResults = true; |
| 124 | this.defaults['text/json'] = ''; |
| 125 | this.titleName = this.params.titleName; |
| 126 | // Checks page and assign URL |
| 127 | if (this.params.page === 'ns-instance') { |
| 128 | this.restService.getResource(environment.NSINSTANCESCONTENT_URL + '/' + this.params.id).subscribe((nsData: NSDDetails[]) => { |
| 129 | this.defaults['text/json'] = JSON.stringify(nsData, null, '\t'); |
| 130 | }, (error: ERRORDATA) => { |
| 131 | this.isLoadingResults = false; |
| 132 | this.restService.handleError(error, 'get'); |
| 133 | }, () => { |
| 134 | this.isLoadingResults = false; |
| 135 | }); |
| 136 | } else if (this.params.page === 'ns-history-operation') { |
| 137 | this.restService.getResource(environment.NSHISTORYOPERATIONS_URL + '/' + |
| 138 | this.params.id).subscribe((nsHistoryOpn: {}[]) => { |
| 139 | this.defaults['text/json'] = JSON.stringify(nsHistoryOpn, null, '\t'); |
| 140 | }, (error: ERRORDATA) => { |
| 141 | this.isLoadingResults = false; |
| 142 | this.restService.handleError(error, 'get'); |
| 143 | }, () => { |
| 144 | this.isLoadingResults = false; |
| 145 | }); |
| 146 | } else if (this.params.page === 'vnf-instance') { |
| 147 | this.restService.getResource(environment.VNFINSTANCES_URL + '/' + this.params.id).subscribe((vnfData: {}[]) => { |
| 148 | this.defaults['text/json'] = JSON.stringify(vnfData, null, '\t'); |
| 149 | }, (error: ERRORDATA) => { |
| 150 | this.isLoadingResults = false; |
| 151 | this.restService.handleError(error, 'get'); |
| 152 | }, () => { |
| 153 | this.isLoadingResults = false; |
| 154 | }); |
| 155 | } else if (this.params.page === 'net-slice-package') { |
| 156 | this.restService.getResource(environment.NETWORKSLICETEMPLATECONTENT_URL + '/' + this.params.id).subscribe((netSliceData: {}[]) => { |
| 157 | this.defaults['text/json'] = JSON.stringify(netSliceData, null, '\t'); |
| 158 | }, (error: ERRORDATA) => { |
| 159 | this.isLoadingResults = false; |
| 160 | this.restService.handleError(error, 'get'); |
| 161 | }, () => { |
| 162 | this.isLoadingResults = false; |
| 163 | }); |
| 164 | } else if (this.params.page === 'net-slice-instance') { |
| 165 | this.restService.getResource(environment.NETWORKSLICEINSTANCESCONTENT_URL + '/' + this.params.id) |
| 166 | .subscribe((netSliceInstanceData: {}[]) => { |
| 167 | this.defaults['text/json'] = JSON.stringify(netSliceInstanceData, null, '\t'); |
| 168 | }, (error: ERRORDATA) => { |
| 169 | this.isLoadingResults = false; |
| 170 | this.restService.handleError(error, 'get'); |
| 171 | }, () => { |
| 172 | this.isLoadingResults = false; |
| 173 | }); |
| 174 | } else if (this.params.page === 'nst-history-operation') { |
| 175 | this.restService.getResource(environment.NSTHISTORYOPERATIONS_URL + '/' + |
| 176 | this.params.id).subscribe((nstHistoryOpn: {}[]) => { |
| 177 | this.defaults['text/json'] = JSON.stringify(nstHistoryOpn, null, '\t'); |
| 178 | }, (error: ERRORDATA) => { |
| 179 | this.isLoadingResults = false; |
| 180 | this.restService.handleError(error, 'get'); |
| 181 | }, () => { |
| 182 | this.isLoadingResults = false; |
| 183 | }); |
| 184 | } else if (this.params.page === 'pdu-instances') { |
| 185 | this.restService.getResource(environment.PDUINSTANCE_URL + '/' + |
| 186 | this.params.id).subscribe((pduInstanceOpn: {}[]) => { |
| 187 | this.defaults['text/json'] = JSON.stringify(pduInstanceOpn, null, '\t'); |
| 188 | }, (error: ERRORDATA) => { |
| 189 | this.isLoadingResults = false; |
| 190 | this.restService.handleError(error, 'get'); |
| 191 | }, () => { |
| 192 | this.isLoadingResults = false; |
| 193 | }); |
| 194 | } else if (this.params.page === 'k8s-cluster') { |
| 195 | this.restService.getResource(environment.K8SCLUSTER_URL + '/' + |
| 196 | this.params.id).subscribe((k8sclusterOpn: {}[]) => { |
| 197 | this.defaults['text/json'] = JSON.stringify(k8sclusterOpn, null, '\t'); |
| 198 | }, (error: ERRORDATA) => { |
| 199 | this.isLoadingResults = false; |
| 200 | this.restService.handleError(error, 'get'); |
| 201 | }, () => { |
| 202 | this.isLoadingResults = false; |
| 203 | }); |
| 204 | } else if (this.params.page === 'k8s-repo') { |
| 205 | this.restService.getResource(environment.K8REPOS_URL + '/' + |
| 206 | this.params.id).subscribe((k8srepoOpn: {}[]) => { |
| 207 | this.defaults['text/json'] = JSON.stringify(k8srepoOpn, null, '\t'); |
| 208 | }, (error: ERRORDATA) => { |
| 209 | this.isLoadingResults = false; |
| 210 | this.restService.handleError(error, 'get'); |
| 211 | }, () => { |
| 212 | this.isLoadingResults = false; |
| 213 | }); |
| 214 | } |
| 215 | } |
| 216 | } |