Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 1 | import {Component, EventEmitter, Output, ViewChild} from '@angular/core'; |
| 2 | import {ITreeOptions, TreeComponent} from 'angular-tree-component'; |
| 3 | import {IDType, ITreeNode} from 'angular-tree-component/dist/defs/api'; |
| 4 | import {DialogService} from 'ng2-bootstrap-modal'; |
| 5 | import {AvailableModelsTreeService} from './available-models-tree.service'; |
| 6 | import {NgRedux} from "@angular-redux/store"; |
| 7 | import {ActivatedRoute} from '@angular/router'; |
| 8 | import {AppState} from '../../../shared/store/reducers'; |
| 9 | import {AaiService} from '../../../shared/services/aaiService/aai.service'; |
| 10 | import {ServiceNodeTypes} from '../../../shared/models/ServiceNodeTypes'; |
| 11 | import {IframeService} from "../../../shared/utils/iframe.service"; |
| 12 | import {DefaultDataGeneratorService} from "../../../shared/services/defaultDataServiceGenerator/default.data.generator.service"; |
| 13 | import {VfModulePopuopService} from "../../../shared/components/genericFormPopup/genericFormServices/vfModule/vfModule.popuop.service"; |
| 14 | import {NetworkPopupService} from "../../../shared/components/genericFormPopup/genericFormServices/network/network.popup.service"; |
| 15 | import {createVFModuleInstance} from "../../../shared/storeUtil/utils/vfModule/vfModule.actions"; |
| 16 | import {VnfPopupService} from "../../../shared/components/genericFormPopup/genericFormServices/vnf/vnf.popup.service"; |
| 17 | import {DrawingBoardModes} from "../drawing-board.modes"; |
| 18 | import {DrawingBoardTreeService} from "../drawing-board-tree/drawing-board-tree.service"; |
| 19 | import {ObjectToModelTreeService} from "../objectsToTree/objectToModelTree/objectToModelTree.service"; |
| 20 | import {VnfGroupPopupService} from "../../../shared/components/genericFormPopup/genericFormServices/vnfGroup/vnfGroup.popup.service"; |
| 21 | import {SharedTreeService} from "../objectsToTree/shared.tree.service"; |
| 22 | import {changeInstanceCounter} from "../../../shared/storeUtil/utils/general/general.actions"; |
| 23 | import {createVnfGroupInstance} from "../../../shared/storeUtil/utils/vnfGroup/vnfGroup.actions"; |
| 24 | import {VnfGroupControlGenerator} from "../../../shared/components/genericForm/formControlsServices/vnfGroupGenerator/vnfGroup.control.generator"; |
| 25 | import {HighlightPipe} from "../../../shared/pipes/highlight/highlight-filter.pipe"; |
| 26 | import * as _ from 'lodash'; |
| 27 | import {DrawingBoardTreeComponent} from "../drawing-board-tree/drawing-board-tree.component"; |
Ittay Stern | f792671 | 2019-07-07 19:23:03 +0300 | [diff] [blame^] | 28 | import {ComponentInfoModel} from "../component-info/component-info-model"; |
| 29 | import {ComponentInfoService} from "../component-info/component-info.service"; |
| 30 | import {FeatureFlagsService, Features} from "../../../shared/services/featureFlag/feature-flags.service"; |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 31 | |
| 32 | |
| 33 | @Component({ |
| 34 | selector: 'available-models-tree', |
| 35 | templateUrl: './available-models-tree.component.html', |
| 36 | styleUrls: ['./available-models-tree.component.scss'], |
| 37 | providers : [HighlightPipe] |
| 38 | }) |
| 39 | |
| 40 | export class AvailableModelsTreeComponent { |
| 41 | filterValue : string = ''; |
| 42 | serviceModelId: string; |
| 43 | serviceHierarchy; |
| 44 | parentElementClassName = 'content'; |
| 45 | _store: NgRedux<AppState>; |
| 46 | isNewObject: boolean; |
| 47 | availableModelsTreeService: AvailableModelsTreeService; |
| 48 | drawingBoardTreeService: DrawingBoardTreeService; |
| 49 | |
| 50 | constructor(private _iframeService: IframeService, |
| 51 | private _aaiService: AaiService, |
| 52 | private route: ActivatedRoute, |
| 53 | private dialogService: DialogService, |
| 54 | private _availableModelsTreeService: AvailableModelsTreeService, |
| 55 | private _drawingBoardTreeService: DrawingBoardTreeService, |
| 56 | private _defaultDataGeneratorService: DefaultDataGeneratorService, |
| 57 | private _vnfGroupControlGenerator: VnfGroupControlGenerator, |
| 58 | private _vfModulePopuopService: VfModulePopuopService, |
| 59 | private _vnfGroupPopupService: VnfGroupPopupService, |
| 60 | private _vnfPopupService: VnfPopupService, |
| 61 | private _networkPopupService: NetworkPopupService, |
| 62 | private store: NgRedux<AppState>, |
| 63 | private _objectToModelTreeService : ObjectToModelTreeService, |
| 64 | private _sharedTreeService : SharedTreeService, |
| 65 | private _highlightPipe : HighlightPipe) { |
| 66 | this.availableModelsTreeService = _availableModelsTreeService; |
| 67 | this.drawingBoardTreeService = _drawingBoardTreeService; |
| 68 | |
| 69 | this._store = store; |
| 70 | this.route |
| 71 | .queryParams |
| 72 | .subscribe(params => { |
| 73 | this.serviceModelId = params['serviceModelId']; |
| 74 | this._aaiService.getServiceModelById(this.serviceModelId).subscribe( |
| 75 | value => { |
| 76 | this.serviceHierarchy = value; |
| 77 | this.nodes = this._objectToModelTreeService.convertServiceHierarchyModelToTreeNodes(this.serviceHierarchy); |
Ittay Stern | f792671 | 2019-07-07 19:23:03 +0300 | [diff] [blame^] | 78 | this.shouldOpenVRFModal(this.nodes); |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 79 | }, |
| 80 | error => { |
| 81 | console.log('error is ', error) |
| 82 | } |
| 83 | ); |
| 84 | }); |
| 85 | |
| 86 | } |
| 87 | |
| 88 | @Output() |
| 89 | highlightInstances: EventEmitter<number> = new EventEmitter<number>(); |
| 90 | @ViewChild('tree') tree: TreeComponent; |
| 91 | |
| 92 | nodes = []; |
| 93 | service = {name: ''}; |
| 94 | |
| 95 | options: ITreeOptions = { |
| 96 | nodeHeight: 36, |
| 97 | dropSlotHeight: 0, |
| 98 | nodeClass: (node: ITreeNode) => { |
| 99 | if (node.data.type === ServiceNodeTypes.VFmodule && ! node.parent.data['getNodeCount'](node.parent, this.serviceModelId) && this.store.getState().global.drawingBoardStatus !== DrawingBoardModes.VIEW) { |
| 100 | node.data.disabled = true; |
| 101 | return 'tree-node tree-node-disabled'; |
| 102 | } |
| 103 | node.data.disabled = false; |
| 104 | return 'tree-node'; |
| 105 | } |
| 106 | }; |
| 107 | |
| 108 | |
Ittay Stern | f792671 | 2019-07-07 19:23:03 +0300 | [diff] [blame^] | 109 | shouldOpenVRFModal(nodes) :void { |
| 110 | const node = this._availableModelsTreeService.shouldOpenVRFModal(nodes, this.serviceModelId, this.store.getState().service); |
| 111 | if(!_.isNil(node)){ |
| 112 | this.onClickAdd(node, this.serviceModelId); |
| 113 | } |
| 114 | } |
| 115 | |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 116 | getNodeName(node : ITreeNode, filter : string) { |
| 117 | return this._highlightPipe.transform(node.data.name ,filter ? filter : ''); |
| 118 | } |
| 119 | |
| 120 | expandParentByNodeId(id: IDType): void { |
| 121 | this.tree.treeModel.getNodeById(id).parent.expand(); |
| 122 | } |
| 123 | |
| 124 | updateNodes(updateData : {nodes : any, filterValue : string}) : void { |
| 125 | this.nodes = updateData.nodes; |
| 126 | this.filterValue = updateData.filterValue; |
| 127 | } |
| 128 | |
| 129 | selectNode(node: ITreeNode): void { |
| 130 | node.expand(); |
| 131 | this._sharedTreeService.setSelectedVNF(null); |
| 132 | this.highlightInstances.emit(node.data.modelUniqueId); |
Ittay Stern | f792671 | 2019-07-07 19:23:03 +0300 | [diff] [blame^] | 133 | if (FeatureFlagsService.getFlagState(Features.FLAG_1906_COMPONENT_INFO, this.store)) { |
| 134 | const serviceHierarchy = this._store.getState().service.serviceHierarchy[this.serviceModelId]; |
| 135 | const model = node.data.getModel(node.data.name, node.data, serviceHierarchy); |
| 136 | const modelInfoItems = node.data.getInfo(model, null); |
| 137 | const componentInfoModel :ComponentInfoModel = this._sharedTreeService.addGeneralInfoItems(modelInfoItems, node.data.componentInfoType, model, null); |
| 138 | ComponentInfoService.triggerComponentInfoChange.next(componentInfoModel); |
| 139 | } |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | |
| 143 | |
| 144 | onClickAdd(node: ITreeNode, serviceId: string , isNewObject: boolean = false): void { |
| 145 | this.isNewObject = isNewObject; |
| 146 | let data = node.data; |
| 147 | let dynamicInputs = data.dynamicInputs; |
Ittay Stern | f792671 | 2019-07-07 19:23:03 +0300 | [diff] [blame^] | 148 | let isAlaCarte: boolean = this.serviceHierarchy.service.vidNotions.instantiationType == 'ALaCarte'; |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 149 | let isEcompGeneratedNaming: boolean = data.isEcompGeneratedNaming; |
| 150 | let type: string = data.type; |
| 151 | if (!this.store.getState().global.flags['FLAG_SETTING_DEFAULTS_IN_DRAWING_BOARD'] || node.data.type === ServiceNodeTypes.VF || |
| 152 | this._availableModelsTreeService.shouldOpenDialog(type, dynamicInputs, isEcompGeneratedNaming)) { |
| 153 | this._iframeService.addClassOpenModal(this.parentElementClassName); |
| 154 | node.data.onAddClick(node, serviceId); |
| 155 | } else { |
| 156 | if (node.data.type === ServiceNodeTypes.VnfGroup) { |
| 157 | let instanceName = this._vnfGroupControlGenerator.getDefaultInstanceName(null, serviceId, node.data.name); |
| 158 | let vnfGroup = this._defaultDataGeneratorService.generateVnfGroupInstance(this.serviceHierarchy.vnfGroups[node.data.name], isEcompGeneratedNaming, isAlaCarte, instanceName); |
| 159 | this._store.dispatch(changeInstanceCounter(node.data.modelUniqueId, serviceId, 1 , <any> {data: {type: 'VnfGroup'}})); |
| 160 | this._store.dispatch(createVnfGroupInstance(vnfGroup, node.data.name, serviceId, node.data.name)); |
| 161 | DrawingBoardTreeComponent.triggerreCalculateIsDirty.next(this.serviceModelId); |
| 162 | } else { |
| 163 | let vfModule = this._defaultDataGeneratorService.generateVFModule(this.serviceHierarchy.vnfs[node.parent.data.name].vfModules[node.data.name], dynamicInputs, isEcompGeneratedNaming, isAlaCarte); |
| 164 | if (this._sharedTreeService.selectedVNF) { |
| 165 | this.store.dispatch(createVFModuleInstance(vfModule, node.data.name, this.serviceModelId, null, this._sharedTreeService.selectedVNF)); |
| 166 | DrawingBoardTreeComponent.triggerreCalculateIsDirty.next(this.serviceModelId); |
| 167 | } else if (this._availableModelsTreeService.getOptionalVNFs(this.serviceModelId, node.parent.data.name).length === 1) { |
| 168 | let existVnf = this._store.getState().service.serviceInstance[this.serviceModelId].vnfs; |
| 169 | if(!_.isNil(existVnf)){ |
| 170 | for(let vnfKey in existVnf){ |
Ittay Stern | f792671 | 2019-07-07 19:23:03 +0300 | [diff] [blame^] | 171 | const modelUniqueId = existVnf[vnfKey]['modelInfo'].modelCustomizationId || existVnf[vnfKey]['modelInfo'].modelInvariantId; |
| 172 | if(modelUniqueId === node.parent.data.id){ |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 173 | this.store.dispatch(createVFModuleInstance(vfModule, node.data.name, this.serviceModelId, null, vnfKey)); |
| 174 | DrawingBoardTreeComponent.triggerreCalculateIsDirty.next(this.serviceModelId); |
| 175 | } |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | |
| 180 | } else { |
| 181 | this._availableModelsTreeService.addingAlertAddingNewVfModuleModal(); |
| 182 | } |
| 183 | } |
| 184 | } |
| 185 | } |
| 186 | } |