| 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 Show content modal |
| 20 | */ |
| Barath Kumar R | a22c863 | 2021-04-09 20:16:00 +0530 | [diff] [blame] | 21 | import { HttpHeaders } from '@angular/common/http'; |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 22 | import { Component, Injector, Input, OnInit } from '@angular/core'; |
| 23 | import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'; |
| Barath Kumar R | a22c863 | 2021-04-09 20:16:00 +0530 | [diff] [blame] | 24 | import { ERRORDATA, GETAPIURLHEADER, URLPARAMS } from 'CommonModel'; |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 25 | import { environment } from 'environment'; |
| Barath Kumar R | a22c863 | 2021-04-09 20:16:00 +0530 | [diff] [blame] | 26 | import * as jsyaml from 'js-yaml'; |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 27 | import { RestService } from 'RestService'; |
| 28 | |
| 29 | /** Shows json data in the information modal */ |
| 30 | const defaults: {} = { 'text/json': '' }; |
| 31 | |
| 32 | /** |
| 33 | * Creating component |
| 34 | * @Component takes ShowContentComponent.html as template url |
| 35 | */ |
| 36 | @Component({ |
| 37 | selector: 'app-show-content', |
| 38 | templateUrl: './ShowContentComponent.html', |
| 39 | styleUrls: ['./ShowContentComponent.scss'] |
| 40 | }) |
| 41 | /** Exporting a class @exports ShowContentComponent */ |
| 42 | export class ShowContentComponent implements OnInit { |
| 43 | /** To inject services @public */ |
| 44 | public injector: Injector; |
| 45 | |
| Barath Kumar R | a22c863 | 2021-04-09 20:16:00 +0530 | [diff] [blame] | 46 | /** Check the loading results @public */ |
| 47 | public isLoadingResults: boolean = false; |
| 48 | |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 49 | /** Instance for active modal service @public */ |
| 50 | public activeModal: NgbActiveModal; |
| 51 | |
| 52 | /** Contains files information @public */ |
| 53 | public contents: {}[]; |
| 54 | |
| 55 | /** Input contains component objects @public */ |
| 56 | @Input() public params: URLPARAMS; |
| 57 | |
| 58 | /** Instance of the rest service @private */ |
| 59 | private restService: RestService; |
| 60 | |
| Barath Kumar R | a22c863 | 2021-04-09 20:16:00 +0530 | [diff] [blame] | 61 | /** Controls the header form @private */ |
| 62 | private headers: HttpHeaders; |
| 63 | |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 64 | constructor(injector: Injector) { |
| 65 | this.injector = injector; |
| 66 | this.restService = this.injector.get(RestService); |
| 67 | this.activeModal = this.injector.get(NgbActiveModal); |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Lifecyle Hooks the trigger before component is instantiate @public |
| 72 | */ |
| 73 | public ngOnInit(): void { |
| Barath Kumar R | a22c863 | 2021-04-09 20:16:00 +0530 | [diff] [blame] | 74 | this.headers = new HttpHeaders({ |
| 75 | 'Content-Type': 'application/json', |
| 76 | Accept: 'text/plain', |
| 77 | 'Cache-Control': 'no-cache, no-store, must-revalidate, max-age=0' |
| 78 | }); |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 79 | if (this.params.page === 'nsd') { |
| Barath Kumar R | a22c863 | 2021-04-09 20:16:00 +0530 | [diff] [blame] | 80 | this.getContent(environment.NSDESCRIPTORS_URL + '/' + this.params.id + '/artifacts'); |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 81 | } else if (this.params.page === 'vnfd') { |
| Barath Kumar R | a22c863 | 2021-04-09 20:16:00 +0530 | [diff] [blame] | 82 | this.getContent(environment.VNFPACKAGES_URL + '/' + this.params.id + '/artifacts'); |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 83 | } |
| 84 | } |
| Barath Kumar R | a22c863 | 2021-04-09 20:16:00 +0530 | [diff] [blame] | 85 | /** Get the NSD Content List @public */ |
| 86 | public getContent(URL: string): void { |
| 87 | this.isLoadingResults = true; |
| 88 | const httpOptions: GETAPIURLHEADER = { |
| 89 | headers: this.headers, |
| 90 | responseType: 'text' |
| 91 | }; |
| 92 | this.restService.getResource(URL, httpOptions).subscribe((content: {}[]): void => { |
| 93 | const getJson: string[] = jsyaml.load(content.toString(), { json: true }); |
| 94 | this.contents = getJson; |
| 95 | this.isLoadingResults = false; |
| 96 | }, (error: ERRORDATA): void => { |
| 97 | this.restService.handleError(error, 'get'); |
| 98 | this.isLoadingResults = false; |
| 99 | }); |
| 100 | } |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 101 | } |