add new action configscalein for cdt
[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', 'DistributeTraffic', 'DistributeTrafficCheck', 'ConfigScaleIn']
32
33
34 @Component({ selector: 'app-build-design', templateUrl: './build-artifacts.component.html', styleUrls: ['./build-artifacts.component.css'] })
35 export class BuildDesignComponent implements OnInit {
36     tabs: Array<Object> = [];
37     private allowOtherUpdates: boolean = true;
38     public refDataRequiredFiels: boolean = false;
39     public refList;
40
41     constructor (private router: Router, private notificationsService: NotificationsService) {
42     }
43
44     ngOnInit() {
45         this.tabs = appConstants.tabs;
46     }
47
48     public setAllowOtherUpdates(allowOtherUpdates: boolean) {
49         this.allowOtherUpdates = allowOtherUpdates;
50     }
51
52     // Allow / block access to the update pages of GT and PD if no reference data present
53     public updateAccessUpdatePages(selectedAction, referenceList) {
54         // Disable/enable the menu items for update pages of GT and PD.
55         if (this.isReferenceFound(selectedAction, referenceList)) {
56             this.setAllowOtherUpdates(true);
57         } else {
58             //alert("false")
59             this.setAllowOtherUpdates(false);
60         }
61     }
62
63     public isReferenceFound(selectedAction, referenceList) {
64         let selectedActioneObject = _.find(referenceList, function (obj) {
65             return obj['action'] == selectedAction;
66         });
67         if (selectedActioneObject) {
68             return true;
69         } else {
70             return false;
71         }
72     }
73
74     public getRefData(referenceList, reqObj?) {
75         this.refList = referenceList;
76         if (referenceList.action !== '' && referenceList.scope['vnf-type'] !== '' && referenceList['device-protocol'] !== '') {
77             if(ACTIONS_REQUIRED_DROPDOWN.indexOf(referenceList.action) > -1) {
78             //if (referenceList.action === 'ConfigScaleOut') {
79                 //console.log(typeof reqObj, selectedIdentifier)
80                 // if (referenceList.hasOwnProperty('template-id') && referenceList['template-id'] !== undefined && referenceList['template-id'] != '')
81                 //     this.refDataRequiredFiels = true;
82                 // else this.refDataRequiredFiels = false;
83                 if(referenceList.action == 'ConfigScaleOut' || referenceList.action == 'ConfigScaleIn') {
84                     if(reqObj != undefined && reqObj.hasOwnProperty('reqField') && reqObj.reqField != '') this.refDataRequiredFiels = true;
85                     else this.refDataRequiredFiels = false;
86                 }
87
88                 // else if( referenceList.action == 'Configure' || referenceList.action == 'ConfigModify' ) {
89                 //     if(referenceList.displayVnfc == 'false') this.refDataRequiredFiels = true;
90                 //     else if( referenceList.displayVnfc != 'false' && referenceList.vnfcIdentifier ) this.refDataRequiredFiels = true;
91                 // }
92                 
93                 else this.refDataRequiredFiels = true;
94             }
95             else this.refDataRequiredFiels = true;
96         }
97         else {
98             this.refDataRequiredFiels = false;
99         }
100     }
101
102     public checkRefDataReqFields() {
103         if (this.refList.action == appConstants.Actions.blank && this.refList.scope['vnf-type'] == '' && this.refList['device-protocol'] == appConstants.DeviceProtocols.blank) {
104             this.notificationsService.error(appConstants.errors.error, appConstants.errors.noActionVnfProtocolError);
105         }
106         else if (this.refList.action == appConstants.Actions.blank) {
107             this.notificationsService.error(appConstants.errors.error, appConstants.errors.noActionError);
108         }
109         else if (this.refList.scope['vnf-type'] == '') {
110             this.notificationsService.error(appConstants.errors.error, appConstants.errors.noVnfTypeError);
111         }
112         else if (this.refList['device-protocol'] == appConstants.DeviceProtocols.blank) {
113             this.notificationsService.error(appConstants.errors.error, appConstants.errors.noDeviceProtocolError);
114         }
115         else if (this.refList.action === appConstants.Actions.configScaleOut || this.refList.action === appConstants.Actions.configScaleIn) {
116             this.notificationsService.error(appConstants.errors.error, appConstants.errors.noValidTemplateIdentifierError);
117         }
118     }
119
120 }