Initial Commit - NG UI
[osm/NG-UI.git] / src / app / packages / show-content / ShowContentComponent.ts
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  */
21 import { Component, Injector, Input, OnInit } from '@angular/core';
22 import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
23 import { ERRORDATA, URLPARAMS } from 'CommonModel';
24 import { environment } from 'environment';
25 import { RestService } from 'RestService';
26
27 /** Shows json data in the information modal */
28 const defaults: {} = { 'text/json': '' };
29
30 /**
31  * Creating component
32  * @Component takes ShowContentComponent.html as template url
33  */
34 @Component({
35   selector: 'app-show-content',
36   templateUrl: './ShowContentComponent.html',
37   styleUrls: ['./ShowContentComponent.scss']
38 })
39 /** Exporting a class @exports ShowContentComponent */
40 export class ShowContentComponent implements OnInit {
41   /** To inject services @public */
42   public injector: Injector;
43
44   /** Instance for active modal service @public */
45   public activeModal: NgbActiveModal;
46
47   /** Contains files information @public */
48   public contents: {}[];
49
50   /** Input contains component objects @public */
51   @Input() public params: URLPARAMS;
52
53   /** Instance of the rest service @private */
54   private restService: RestService;
55
56   constructor(injector: Injector) {
57     this.injector = injector;
58     this.restService = this.injector.get(RestService);
59     this.activeModal = this.injector.get(NgbActiveModal);
60   }
61
62   /**
63    * Lifecyle Hooks the trigger before component is instantiate @public
64    */
65   public ngOnInit(): void {
66     if (this.params.page === 'nsd') {
67       this.restService.getResource(environment.NSDESCRIPTORS_URL + '/' + this.params.id + '/artifacts/artifactPath')
68         .subscribe((nsd: {}[]) => {
69           this.contents = nsd;
70         }, (error: ERRORDATA) => {
71           this.restService.handleError(error, 'get');
72         });
73     } else if (this.params.page === 'vnfd') {
74       this.restService.getResource(environment.VNFPACKAGES_URL + '/' + this.params.id + '/artifacts/artifactPath')
75         .subscribe((vnfd: {}[]) => {
76           this.contents = vnfd;
77         }, (error: ERRORDATA) => {
78           this.restService.handleError(error, 'get');
79         });
80     }
81   }
82 }