summaryrefslogtreecommitdiffstats
path: root/src/app/vnfs/myvnfs/myvnfs.component.ts
blob: 49f4f42fd3578b41867f1d0ca1ea1bece07b96df (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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
/*
============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';
import { appConstants } from '../../../constants/app-constants'

@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;
    vnfcRequired: boolean = false;
    errorMessage = '';
    invalid = true;
    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) {
    }

    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) {
        let tempObj: any;
        this.ngProgress.start();
        this.httpUtil.post({
            url: environment.getDesigns,
            data: data
        })
            .subscribe(resp => {
                if (resp.output.data.block !== undefined && resp.output.data.block !== null && resp.output.data.block.length !== 0) {
                    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.status.message;
                } else {
                    this.noData = false;
                }
                this.ngProgress.done();
            });

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



    getData() {
    }

    buildNewDesign(response) {

        // this.modalService.open(content).result.then(res => {
        //     if(res=='yes'){
        //         sessionStorage.setItem('vnfParams', JSON.stringify({ vnfType: this.vnfType}));
        //         sessionStorage.setItem("vnfcSelectionFlag",''+this.vnfcRequired+'')
        //     } else{
        //         sessionStorage.setItem('vnfParams',"")
        //     }

        //     this.mappingEditorService.referenceNameObjects = undefined;
        //     this.mappingEditorService.identifier = '';
        //     //this.mappingEditorService.newObject = {};
        //     this.router.navigate([
        //             'vnfs', 'design', 'references'
        //     ]);

        // });

        if (response == 'yes') {
            sessionStorage.setItem('vnfParams', JSON.stringify({ vnfType: this.vnfType }));
            sessionStorage.setItem("vnfcSelectionFlag", '' + this.vnfcRequired + '')
        } else {
            sessionStorage.setItem('vnfParams', "")
        }

        this.mappingEditorService.referenceNameObjects = undefined;
        this.mappingEditorService.identifier = '';
        //this.mappingEditorService.newObject = {};
        this.router.navigate([
            'vnfs', 'design', 'references'
        ]);
    }

    validateVnfName(name) {
        if (!name.trim() || name.length < 1) {
            this.errorMessage = '';
            this.invalid = true;
        } else if (name.startsWith(' ') || name.endsWith(' ')) {
            this.errorMessage = 'Leading and trailing spaces are not allowed';
            this.invalid = true;
        } else if (name.includes('  ')) {
            this.errorMessage = 'More than one space is not allowed in VNF Type';
            this.invalid = true;
        } else if (name.length > 150) {
            this.errorMessage = 'VNF Type should be of minimum one character and maximum 150 character';
            this.invalid = true;
        } else {
            this.invalid = false;
            this.errorMessage = '';
        }
    }

    navigateToReference(item) {
        sessionStorage.setItem('updateParams', JSON.stringify(item));
        this.mappingEditorService.referenceNameObjects = undefined;
        sessionStorage.setItem('vnfParams', JSON.stringify({ vnfType: item.vnfType, vnfcType: item.vnfcType }));
        this.mappingEditorService.identifier = '';
        if (this.mappingEditorService.newObject && this.mappingEditorService.newObject.vnfc != undefined) {
            this.mappingEditorService.newObject.vnfc = '';
        }
        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.
        sessionStorage.setItem("vnfcSelectionFlag", '' + this.vnfcRequired + '')
        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);
    }
    defineData(item) {
        let artVnfc = item['artifact-name'].substring(this.lastIndexofEnd("AllAction_", item['artifact-name']), item['artifact-name'].lastIndexOf("_"))
        if (item['vnf-type'] == artVnfc && item['vnfc-type'] == 'null') {

            return item['vnfc-type']
        } else {
            return ""
        }

    }
    lastIndexofEnd(str, originlStr) {
        var io = originlStr.lastIndexOf(str);
        return io == -1 ? -1 : io + str.length;
    }


}