blob: 145ee19dad5154f89fcc1863a3564ca64942d876 [file] [log] [blame]
Ittay Stern6f900cc2018-08-29 17:01:32 +03001import {Component, EventEmitter, Output, ViewChild} from '@angular/core';
2import {ITreeOptions, TreeComponent} from 'angular-tree-component';
3import {IDType, ITreeNode} from 'angular-tree-component/dist/defs/api';
4import {DialogService} from 'ng2-bootstrap-modal';
5import {AvailableModelsTreeService} from './available-models-tree.service';
6import {NgRedux} from "@angular-redux/store";
7import {ActivatedRoute} from '@angular/router';
8import {AppState} from '../../../shared/store/reducers';
9import {AaiService} from '../../../shared/services/aaiService/aai.service';
10import {ServiceNodeTypes} from '../../../shared/models/ServiceNodeTypes';
11import {IframeService} from "../../../shared/utils/iframe.service";
12import {DefaultDataGeneratorService} from "../../../shared/services/defaultDataServiceGenerator/default.data.generator.service";
13import {VfModulePopuopService} from "../../../shared/components/genericFormPopup/genericFormServices/vfModule/vfModule.popuop.service";
14import {NetworkPopupService} from "../../../shared/components/genericFormPopup/genericFormServices/network/network.popup.service";
15import {createVFModuleInstance} from "../../../shared/storeUtil/utils/vfModule/vfModule.actions";
16import {VnfPopupService} from "../../../shared/components/genericFormPopup/genericFormServices/vnf/vnf.popup.service";
17import {DrawingBoardModes} from "../drawing-board.modes";
18import {DrawingBoardTreeService} from "../drawing-board-tree/drawing-board-tree.service";
19import {ObjectToModelTreeService} from "../objectsToTree/objectToModelTree/objectToModelTree.service";
20import {VnfGroupPopupService} from "../../../shared/components/genericFormPopup/genericFormServices/vnfGroup/vnfGroup.popup.service";
21import {SharedTreeService} from "../objectsToTree/shared.tree.service";
22import {changeInstanceCounter} from "../../../shared/storeUtil/utils/general/general.actions";
23import {createVnfGroupInstance} from "../../../shared/storeUtil/utils/vnfGroup/vnfGroup.actions";
24import {VnfGroupControlGenerator} from "../../../shared/components/genericForm/formControlsServices/vnfGroupGenerator/vnfGroup.control.generator";
25import {HighlightPipe} from "../../../shared/pipes/highlight/highlight-filter.pipe";
26import * as _ from 'lodash';
27import {DrawingBoardTreeComponent} from "../drawing-board-tree/drawing-board-tree.component";
Ittay Sternf7926712019-07-07 19:23:03 +030028import {ComponentInfoModel} from "../component-info/component-info-model";
29import {ComponentInfoService} from "../component-info/component-info.service";
30import {FeatureFlagsService, Features} from "../../../shared/services/featureFlag/feature-flags.service";
Ittay Stern6f900cc2018-08-29 17:01:32 +030031
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
40export 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 Sternf7926712019-07-07 19:23:03 +030078 this.shouldOpenVRFModal(this.nodes);
Ittay Stern6f900cc2018-08-29 17:01:32 +030079 },
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 Sternf7926712019-07-07 19:23:03 +0300109 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 Stern6f900cc2018-08-29 17:01:32 +0300116 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 Sternf7926712019-07-07 19:23:03 +0300133 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 Stern6f900cc2018-08-29 17:01:32 +0300140 }
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 Sternf7926712019-07-07 19:23:03 +0300148 let isAlaCarte: boolean = this.serviceHierarchy.service.vidNotions.instantiationType == 'ALaCarte';
Ittay Stern6f900cc2018-08-29 17:01:32 +0300149 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 Sternf7926712019-07-07 19:23:03 +0300171 const modelUniqueId = existVnf[vnfKey]['modelInfo'].modelCustomizationId || existVnf[vnfKey]['modelInfo'].modelInvariantId;
172 if(modelUniqueId === node.parent.data.id){
Ittay Stern6f900cc2018-08-29 17:01:32 +0300173 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}