aboutsummaryrefslogtreecommitdiffstats
path: root/src/app/vnfs/myvnfs/myvnfs.component.ts
blob: 1a27135ec7c856978a2b38d0db6761892983c07b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/*
============LICENSE_START==========================================
===================================================================
Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
===================================================================
Copyright (C) 2018 IBM.
===================================================================
Unless otherwise specified, all software contained herein is licensed
under the Apache License, Version 2.0 (the License);
you may not use this software except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

============LICENSE_END============================================
*/

import { Component, OnInit, OnDestroy } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { HttpUtilService } from '../../shared/services/httpUtil/http-util.service';
import { Subscription } from 'rxjs/Subscription';
import { MappingEditorService } from '../../shared/services/mapping-editor.service';
import { ParamShareService } from '../../shared/services/paramShare.service';
import { environment } from '../../../environments/environment';
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
import { NgProgress } from 'ngx-progressbar';
import { NotificationsService } from 'angular2-notifications';

@Component({ selector: 'app-myvnfs', templateUrl: './myvnfs.component.html', styleUrls: ['./myvnfs.component.css'] })
export class MyvnfsComponent implements OnInit, OnDestroy {
    vnfData: Array<Object> = [];
    sortOrder = false;
    noData = true;
    sortBy: string;
    filter: Object = {};
    noDataMsg: string;
    vnfType: any;
    vnfcType: any;
    options = {
        timeOut: 1000,
        showProgressBar: true,
        pauseOnHover: true,
        clickToClose: true,
        maxLength: 200
    }
    subscription: Subscription;

    constructor(private paramShareService: ParamShareService, private ngProgress: NgProgress, private httpUtil: HttpUtilService, private router: Router, private activeROute: ActivatedRoute,
        private mappingEditorService: MappingEditorService, private modalService: NgbModal, private nService: NotificationsService) {
    }

    ngOnInit() {

        sessionStorage.setItem('updateParams', undefined);
        this.mappingEditorService.latestAction = undefined;
        const apiToken = localStorage['apiToken'];

        const data = {
            'input': {
                'design-request': {
                    'request-id': apiToken,
                    'action': 'getDesigns',
                    'payload': '{"userID": "","filter":"reference"}'
                }
            }
        };
        const x = JSON.parse(data.input['design-request']['payload']);
        x.userID = localStorage['userId'];
        data.input['design-request']['payload'] = JSON.stringify(x);
        // console.log("input to payload====", JSON.stringify(data));
        this.getArtifacts(data);
        this.clearCache();
    }

    ngOnDestroy() {
        if (this.subscription) { this.subscription.unsubscribe() };
    }

    getArtifacts(data) {
        this.ngProgress.start();
        this.subscription = this.httpUtil.post({
            url: environment.getDesigns,
            data: data
        })
            .subscribe(resp => {
                console.log("resp:", resp);
                const tempObj = JSON.parse(resp.output.data.block);
                this.vnfData = tempObj.designInfo;
                if (this.vnfData == undefined || this.vnfData == null || this.vnfData.length == 0) {
                    this.noData = true;

                    this.noDataMsg = resp.output.data.status.message;
                } else {
                    this.noData = false;
                }
                console.log(this.noData);
                this.ngProgress.done();
            }
                ,
                error => {

                    this.nService.error("Error", "Error in connecting to APPC Server")
                }

            );

        this.filter = ['vnf-type', 'vnfc-type', 'artifact-name'];
        setTimeout(() => {
            this.ngProgress.done();
        }, 3500);
    }



    getData() {
    }

    buildNewDesign(content) {

        this.modalService.open(content).result.then(res => {
            this.mappingEditorService.referenceNameObjects = undefined;
            sessionStorage.setItem('vnfParams', JSON.stringify({ vnfType: this.vnfType, vnfcType: this.vnfcType }));
            this
                .router
                .navigate([
                    'vnfs', 'design', 'references'
                ]);
        });


    }

    navigateToReference(item) {
        sessionStorage.setItem('updateParams', JSON.stringify(item));
        this.mappingEditorService.referenceNameObjects = undefined;

        this
            .router
            .navigate(['../design/references'], {
                relativeTo: this.activeROute,
                queryParams: {
                    id: item.id
                }
            });
    }

    navigateToRefrenceUpdate() {

        this
            .router
            .navigate(['../design/references/update'], {
                relativeTo: this.activeROute,
                queryParams: {
                    id: '10'
                }
            });
    }

    clearCache() {
        // get the value and save the userid and persist it.

        this.mappingEditorService.setTemplateMappingDataFromStore(undefined);
        localStorage['paramsContent'] = '{}';
        this.mappingEditorService.setParamContent(undefined);
        this.paramShareService.setSessionParamData(undefined);
        const appData = { reference: {}, template: { templateData: {}, nameValueData: {} }, pd: {} };
        const downloadData = {
            reference: {},
            template: { templateData: {}, nameValueData: {}, templateFileName: '', nameValueFileName: '' },
            pd: { pdData: '', pdFileName: '' }
        };
        this.mappingEditorService.changeNavAppData(appData);
        this.mappingEditorService.changeNavDownloadData(downloadData);
    }


}