blob: 39a3c507028723522d9f3211a2525135d35b9d9b [file] [log] [blame]
Ittay Stern6f900cc2018-08-29 17:01:32 +03001import {Injectable} from '@angular/core';
2import {DefaultDataGeneratorService} from "../../../shared/services/defaultDataServiceGenerator/default.data.generator.service";
3import {NgRedux} from "@angular-redux/store";
4import {AppState} from "../../../shared/store/reducers";
5import {MessageBoxData} from "../../../shared/components/messageBox/messageBox.data";
6import {MessageBoxService} from "../../../shared/components/messageBox/messageBox.service";
7import * as _ from "lodash";
8import { SdcUiCommon} from "onap-ui-angular";
9import {SharedTreeService} from "../objectsToTree/shared.tree.service";
Ittay Sternf7926712019-07-07 19:23:03 +030010import {VrfModel} from "../../../shared/models/vrfModel";
11import {clearAllGenericModalhelper} from "../../../shared/storeUtil/utils/global/global.actions";
Ittay Stern6f900cc2018-08-29 17:01:32 +030012
13export class AvailableNodeIcons {
14 addIcon: boolean;
15 vIcon: boolean;
16
17 constructor(addIcon: boolean, vIcon: boolean) {
18 this.addIcon = addIcon;
19 this.vIcon = vIcon;
20 }
Ittay Sternf7926712019-07-07 19:23:03 +030021
Ittay Stern6f900cc2018-08-29 17:01:32 +030022}
23
24@Injectable()
25export class AvailableModelsTreeService {
26 constructor(private _defaultDataGeneratorService: DefaultDataGeneratorService,
27 private store: NgRedux<AppState>,
28 public _shareTreeService : SharedTreeService) {
29 }
30
31
32
33 shouldOpenDialog(type: string, dynamicInputs: any, isEcompGeneratedNaming: boolean): boolean {
34 if (!isEcompGeneratedNaming || this._defaultDataGeneratorService.requiredFields[type].length > 0) {
35 return true;
36 }
37
38 if (dynamicInputs) {
39 for(let input of dynamicInputs) {
40 if (input.isRequired && _.isEmpty(input.value)) {
41 return true;
42 }
43 }
44 }
45 return false;
46 }
47
48 getOptionalVNFs(serviceUUID: string, vnfOriginalModelName : string) : any[] {
49 let result = [];
50 if(!_.isNil(this.store.getState().service.serviceInstance) && !_.isNil(this.store.getState().service.serviceInstance[serviceUUID])){
51 const serviceVNFsInstances = this.store.getState().service.serviceInstance[serviceUUID].vnfs;
52 for(let vnfKey in serviceVNFsInstances){
53 if(serviceVNFsInstances[vnfKey].originalName === vnfOriginalModelName){
54 serviceVNFsInstances[vnfKey].vnfStoreKey = vnfKey;
55 result.push(serviceVNFsInstances[vnfKey]);
56 }
57 }
58 }
59
60
61 return result;
62 }
63
64
65
66 addingAlertAddingNewVfModuleModal() : void {
67 let messageBoxData : MessageBoxData = new MessageBoxData(
68 "Select a parent", // modal title
69 "There are multiple instances on the right side that can contain this vf-module Please select the VNF instance, to add this vf-module to, on the right side and then click the + sign",
70 SdcUiCommon.ModalType.warning,
71 SdcUiCommon.ModalSize.medium,
72 [
73 {text:"Close", size:"medium", closeModal:true}
74 ]);
75
76 MessageBoxService.openModal.next(messageBoxData);
77 }
78
Ittay Sternf7926712019-07-07 19:23:03 +030079 shouldOpenVRFModal(nodes, serviceModelId: string , service) {
80 for(const node of nodes){
81 if(node.type === 'VRF' && service.serviceInstance[serviceModelId].existingVRFCounterMap && !service.serviceInstance[serviceModelId].existingVRFCounterMap[node.modelUniqueId]){
82 const vrfModel : VrfModel = node.getModel(node.name, node, service.serviceInstance[serviceModelId]);
83 const vrfCounter : number = service.serviceInstance[serviceModelId].existingVRFCounterMap[node.modelUniqueId];
84 console.log('vrfCounter', vrfCounter);
85 if(vrfModel.min > 0 && (_.isNil(vrfCounter) || vrfCounter === 0)){
86 node.data = node;
87 this.store.dispatch(clearAllGenericModalhelper());
88 return node;
89 }
90 }
91 }
92 return null;
93 }
94
Ittay Stern6f900cc2018-08-29 17:01:32 +030095}