APPC CDT to Support Multiple Templates for VNFCs
[appc/cdt.git] / src / app / vnfs / build-artifacts / build-artifacts.component.ts
1 /*
2 ============LICENSE_START==========================================
3 ===================================================================
4 Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
5
6 Copyright (C) 2018 IBM Intellectual Property. All rights reserved.
7 ===================================================================
8
9 Unless otherwise specified, all software contained herein is licensed
10 under the Apache License, Version 2.0 (the License);
11 you may not use this software except in compliance with the License.
12 You may obtain a copy of the License at
13
14     http://www.apache.org/licenses/LICENSE-2.0
15
16 Unless required by applicable law or agreed to in writing, software
17 distributed under the License is distributed on an "AS IS" BASIS,
18 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 See the License for the specific language governing permissions and
20 limitations under the License.
21
22 ============LICENSE_END============================================
23 */
24
25 import { Component, OnInit } from '@angular/core';
26 import { Router } from '@angular/router';
27 import * as _ from 'underscore';
28 import { NotificationsService } from 'angular2-notifications';
29 import { appConstants } from '../../../constants/app-constants';
30
31 export const ACTIONS_REQUIRED_DROPDOWN = ['Configure', 'ConfigModify', 'ConfigScaleOut'];
32
33 @Component({ selector: 'app-build-design', templateUrl: './build-artifacts.component.html', styleUrls: ['./build-artifacts.component.css'] })
34 export class BuildDesignComponent implements OnInit {
35     tabs: Array<Object> = [];
36     private allowOtherUpdates: boolean = true;
37     public refDataRequiredFiels: boolean = false;
38     public refList;
39
40     constructor(private router: Router, private notificationsService: NotificationsService) {
41     }
42
43     ngOnInit() {
44         this.tabs = appConstants.tabs;
45     }
46
47     public setAllowOtherUpdates(allowOtherUpdates: boolean) {
48         this.allowOtherUpdates = allowOtherUpdates;
49     }
50
51     // Allow / block access to the update pages of GT and PD if no reference data present
52     public updateAccessUpdatePages(selectedAction, referenceList) {
53         // Disable/enable the menu items for update pages of GT and PD.
54         if (this.isReferenceFound(selectedAction, referenceList)) {
55             this.setAllowOtherUpdates(true);
56         } else {
57             //alert("false")
58             this.setAllowOtherUpdates(false);
59         }
60     }
61
62     public isReferenceFound(selectedAction, referenceList) {
63         let selectedActioneObject = _.find(referenceList, function (obj) {
64             return obj['action'] == selectedAction;
65         });
66         if (selectedActioneObject) {
67             return true;
68         } else {
69             return false;
70         }
71     }
72
73     public getRefData( referenceList, reqObj?) {
74         console.log( "getRefData: start: referenceList.action:["+
75           referenceList.action+"]");
76         this.refList = referenceList;
77         if( referenceList.action !== '' &&
78             referenceList.scope['vnf-type'] !== '' &&
79             referenceList['device-protocol'] !== '' )
80         {
81           if( ACTIONS_REQUIRED_DROPDOWN.indexOf(referenceList.action) > -1)
82           {
83             if( referenceList.action == 'ConfigScaleOut')
84             {
85               if( reqObj != undefined && reqObj.hasOwnProperty('reqField') &&
86                   reqObj.reqField != ''
87               )
88                 this.refDataRequiredFiels = true;
89               else
90                 this.refDataRequiredFiels = false;
91             }
92             else
93               this.refDataRequiredFiels = true;
94           }
95           else
96             this.refDataRequiredFiels = true;
97         }
98         else {
99           this.refDataRequiredFiels = false;
100         }
101     }
102
103     public checkRefDataReqFields() {
104         if (this.refList.action == appConstants.Actions.blank && this.refList.scope['vnf-type'] == '' && this.refList['device-protocol'] == appConstants.DeviceProtocols.blank) {
105             this.notificationsService.error(appConstants.errors.error, appConstants.errors.noActionVnfProtocolError);
106         }
107         else if (this.refList.action == appConstants.Actions.blank) {
108             this.notificationsService.error(appConstants.errors.error, appConstants.errors.noActionError);
109         }
110         else if (this.refList.scope['vnf-type'] == '') {
111             this.notificationsService.error(appConstants.errors.error, appConstants.errors.noVnfTypeError);
112         }
113         else if (this.refList['device-protocol'] == appConstants.DeviceProtocols.blank) {
114             this.notificationsService.error(appConstants.errors.error, appConstants.errors.noDeviceProtocolError);
115         }
116         else if (this.refList.action === appConstants.Actions.configScaleOut) {
117             this.notificationsService.error(appConstants.errors.error, appConstants.errors.noValidTemplateIdentifierError);
118         }
119     }
120
121 }