blob: 3b34a42d5ae4a04d5fc1aab0d042c036a059413e [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 Show content modal
20 */
Barath Kumar Ra22c8632021-04-09 20:16:00 +053021import { HttpHeaders } from '@angular/common/http';
kumaran.m3b4814a2020-05-01 19:48:54 +053022import { Component, Injector, Input, OnInit } from '@angular/core';
23import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
Barath Kumar Ra22c8632021-04-09 20:16:00 +053024import { ERRORDATA, GETAPIURLHEADER, URLPARAMS } from 'CommonModel';
kumaran.m3b4814a2020-05-01 19:48:54 +053025import { environment } from 'environment';
Barath Kumar Ra22c8632021-04-09 20:16:00 +053026import * as jsyaml from 'js-yaml';
kumaran.m3b4814a2020-05-01 19:48:54 +053027import { RestService } from 'RestService';
28
29/** Shows json data in the information modal */
30const 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 */
42export class ShowContentComponent implements OnInit {
43 /** To inject services @public */
44 public injector: Injector;
45
Barath Kumar Ra22c8632021-04-09 20:16:00 +053046 /** Check the loading results @public */
47 public isLoadingResults: boolean = false;
48
kumaran.m3b4814a2020-05-01 19:48:54 +053049 /** 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 Ra22c8632021-04-09 20:16:00 +053061 /** Controls the header form @private */
62 private headers: HttpHeaders;
63
kumaran.m3b4814a2020-05-01 19:48:54 +053064 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 Ra22c8632021-04-09 20:16:00 +053074 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.m3b4814a2020-05-01 19:48:54 +053079 if (this.params.page === 'nsd') {
Barath Kumar Ra22c8632021-04-09 20:16:00 +053080 this.getContent(environment.NSDESCRIPTORS_URL + '/' + this.params.id + '/artifacts');
kumaran.m3b4814a2020-05-01 19:48:54 +053081 } else if (this.params.page === 'vnfd') {
Barath Kumar Ra22c8632021-04-09 20:16:00 +053082 this.getContent(environment.VNFPACKAGES_URL + '/' + this.params.id + '/artifacts');
kumaran.m3b4814a2020-05-01 19:48:54 +053083 }
84 }
Barath Kumar Ra22c8632021-04-09 20:16:00 +053085 /** 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.m3b4814a2020-05-01 19:48:54 +0530101}