Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 1 | import {Injectable} from '@angular/core'; |
| 2 | import {DefaultDataGeneratorService} from "../../../shared/services/defaultDataServiceGenerator/default.data.generator.service"; |
| 3 | import {NgRedux} from "@angular-redux/store"; |
| 4 | import {AppState} from "../../../shared/store/reducers"; |
| 5 | import {MessageBoxData} from "../../../shared/components/messageBox/messageBox.data"; |
| 6 | import {MessageBoxService} from "../../../shared/components/messageBox/messageBox.service"; |
| 7 | import * as _ from "lodash"; |
| 8 | import { SdcUiCommon} from "onap-ui-angular"; |
| 9 | import {SharedTreeService} from "../objectsToTree/shared.tree.service"; |
Ittay Stern | f792671 | 2019-07-07 19:23:03 +0300 | [diff] [blame] | 10 | import {VrfModel} from "../../../shared/models/vrfModel"; |
| 11 | import {clearAllGenericModalhelper} from "../../../shared/storeUtil/utils/global/global.actions"; |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 12 | |
| 13 | export 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 Stern | f792671 | 2019-07-07 19:23:03 +0300 | [diff] [blame] | 21 | |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 22 | } |
| 23 | |
| 24 | @Injectable() |
| 25 | export 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 Stern | f792671 | 2019-07-07 19:23:03 +0300 | [diff] [blame] | 79 | 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 Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 95 | } |