X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=src%2Fapp%2Fpackages%2Fshow-content%2FShowContentComponent.ts;h=3b34a42d5ae4a04d5fc1aab0d042c036a059413e;hb=a22c8631bb481d0bfcf39d72630d57a5846d20ff;hp=e2431e8ba26b133f2af9674f2605238c95ae84b5;hpb=07698abcf56f875e53734a29dd4092a53461cc1a;p=osm%2FNG-UI.git diff --git a/src/app/packages/show-content/ShowContentComponent.ts b/src/app/packages/show-content/ShowContentComponent.ts index e2431e8..3b34a42 100644 --- a/src/app/packages/show-content/ShowContentComponent.ts +++ b/src/app/packages/show-content/ShowContentComponent.ts @@ -18,10 +18,12 @@ /** * @file Show content modal */ +import { HttpHeaders } from '@angular/common/http'; import { Component, Injector, Input, OnInit } from '@angular/core'; import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'; -import { ERRORDATA, URLPARAMS } from 'CommonModel'; +import { ERRORDATA, GETAPIURLHEADER, URLPARAMS } from 'CommonModel'; import { environment } from 'environment'; +import * as jsyaml from 'js-yaml'; import { RestService } from 'RestService'; /** Shows json data in the information modal */ @@ -41,6 +43,9 @@ export class ShowContentComponent implements OnInit { /** To inject services @public */ public injector: Injector; + /** Check the loading results @public */ + public isLoadingResults: boolean = false; + /** Instance for active modal service @public */ public activeModal: NgbActiveModal; @@ -53,6 +58,9 @@ export class ShowContentComponent implements OnInit { /** Instance of the rest service @private */ private restService: RestService; + /** Controls the header form @private */ + private headers: HttpHeaders; + constructor(injector: Injector) { this.injector = injector; this.restService = this.injector.get(RestService); @@ -63,20 +71,31 @@ export class ShowContentComponent implements OnInit { * Lifecyle Hooks the trigger before component is instantiate @public */ public ngOnInit(): void { + this.headers = new HttpHeaders({ + 'Content-Type': 'application/json', + Accept: 'text/plain', + 'Cache-Control': 'no-cache, no-store, must-revalidate, max-age=0' + }); if (this.params.page === 'nsd') { - this.restService.getResource(environment.NSDESCRIPTORS_URL + '/' + this.params.id + '/artifacts/artifactPath') - .subscribe((nsd: {}[]) => { - this.contents = nsd; - }, (error: ERRORDATA) => { - this.restService.handleError(error, 'get'); - }); + this.getContent(environment.NSDESCRIPTORS_URL + '/' + this.params.id + '/artifacts'); } else if (this.params.page === 'vnfd') { - this.restService.getResource(environment.VNFPACKAGES_URL + '/' + this.params.id + '/artifacts/artifactPath') - .subscribe((vnfd: {}[]) => { - this.contents = vnfd; - }, (error: ERRORDATA) => { - this.restService.handleError(error, 'get'); - }); + this.getContent(environment.VNFPACKAGES_URL + '/' + this.params.id + '/artifacts'); } } + /** Get the NSD Content List @public */ + public getContent(URL: string): void { + this.isLoadingResults = true; + const httpOptions: GETAPIURLHEADER = { + headers: this.headers, + responseType: 'text' + }; + this.restService.getResource(URL, httpOptions).subscribe((content: {}[]): void => { + const getJson: string[] = jsyaml.load(content.toString(), { json: true }); + this.contents = getJson; + this.isLoadingResults = false; + }, (error: ERRORDATA): void => { + this.restService.handleError(error, 'get'); + this.isLoadingResults = false; + }); + } }