1 import {Injectable} from "@angular/core";
2 import {NgRedux} from "@angular-redux/store";
3 import {AppState} from "../../../shared/store/reducers";
4 import {ServiceInstanceActions} from "../../../shared/models/serviceInstanceActions";
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 {DrawingBoardModes} from "../drawing-board.modes";
9 import {AuditInfoModalComponent} from "../../../shared/components/auditInfoModal/auditInfoModal.component";
10 import {VnfModelInfo} from "./models/vnf/vnf.model.info";
11 import {ILevelNodeInfo} from "./models/basic.model.info";
12 import {ComponentInfoModel, ComponentInfoType} from "../component-info/component-info-model";
13 import {ModelInformationItem} from "../../../shared/components/model-information/model-information.component";
16 export class SharedTreeService {
17 private _sharedTreeService: SharedTreeService;
18 constructor(private _store: NgRedux<AppState>) {
21 /***********************************************************
22 * return if instance has missing data
23 * @param instance - vnf instance
24 * @param dynamicInputs - from the instance
25 * @param isEcompGeneratedNaming
26 ************************************************************/
27 selectedVNF: string = null;
30 getSelectedVNF(): string {
31 return this.selectedVNF;
34 setSelectedVNF(node): void {
35 if (_.isNil(node) || node.data.type !== 'VF') {
36 this.selectedVNF = null;
38 this.selectedVNF = node.data.vnfStoreKey;
42 hasMissingData(instance, dynamicInputs: any, isEcompGeneratedNaming: boolean, requiredFields: string[]): boolean {
43 if (!isEcompGeneratedNaming && _.isEmpty(instance.instanceName)) {
47 for (let field of requiredFields) {
48 if (_.isEmpty(instance[field])) {
53 for (let field of dynamicInputs) {
54 if (field.isRequired && !_.isNil(instance.instanceParams) && _.isEmpty(instance.instanceParams[0][field.id])) {
62 addingStatusProperty(node) {
63 node['statusProperties'] = [];
64 node['statusProperties'].push({key: 'Prov Status:', value: node.provStatus, testId: 'provStatus'});
65 node['statusProperties'].push({key: 'Orch Status:', value: node.orchStatus, testId: 'orchStatus'});
67 node['statusProperties'].push({key: 'In-maintenance', value: '', testId: 'inMaint'});
72 /**********************************************
73 * should delete or remove child instance's
74 "new" -> should remove
75 !new" -> should change action status
76 **********************************************/
77 removeDeleteAllChild(node, serviceModelId: string, callback): void {
78 for (let nodeChild of node.children) {
79 if (nodeChild.data.action === ServiceInstanceActions.Create) {
80 if (!_.isNil(nodeChild.data) && !_.isNil(nodeChild.data.menuActions) && !_.isNil(nodeChild.data.menuActions['remove'])) {
81 nodeChild.data.menuActions['remove']['method'](nodeChild, serviceModelId);
84 if (!_.isNil(nodeChild.data) && !_.isNil(nodeChild.data.menuActions) && !_.isNil(nodeChild.data.menuActions['delete'])) {
85 nodeChild.data.menuActions['delete']['method'](nodeChild, serviceModelId);
89 callback(node, serviceModelId);
93 /**********************************************
94 * should undo delete child instance's
95 **********************************************/
96 undoDeleteAllChild(node, serviceModelId: string, callback): void {
97 for (let nodeChild of node.children) {
98 if (!_.isNil(nodeChild.data) && !_.isNil(nodeChild.data.menuActions) && !_.isNil(nodeChild.data.menuActions['undoDelete'])) {
99 nodeChild.data.menuActions['undoDelete']['method'](nodeChild, serviceModelId);
102 callback(node, serviceModelId);
105 /**********************************************
106 * should return true if can delete
107 **********************************************/
108 shouldShowDelete(node): boolean {
109 const mode = this._store.getState().global.drawingBoardStatus;
110 if (!_.isNil(node) && !_.isNil(node.data) && !_.isNil(node.data.action) && !_.isNil(node.data.menuActions['delete'])) {
111 if (mode !== DrawingBoardModes.EDIT || node.data.action === ServiceInstanceActions.Create) {
113 } else if (node.data.action === ServiceInstanceActions.None) {
121 /**********************************************
122 * should return true if can undo delete
123 **********************************************/
124 shouldShowUndoDelete(node): boolean {
125 const mode = this._store.getState().global.drawingBoardStatus;
126 if (mode === DrawingBoardModes.EDIT && !_.isNil(node.data.action) && !_.isNil(node.data.menuActions['undoDelete'])) {
127 if (node.data.action === ServiceInstanceActions.Create || node.data.action === ServiceInstanceActions.Delete) {
129 } else if (node.data.action.split('_').pop() === 'Delete') {
136 /**********************************************
137 * should return true if can remove or edit
138 * enabled only on edit/design mode and for new instances
139 **********************************************/
140 shouldShowRemoveAndEdit(node): boolean {
141 const mode = this._store.getState().global.drawingBoardStatus;
142 if (!_.isNil(node) && !_.isNil(node.data) && !_.isNil(node.data.action) && node.data.action === ServiceInstanceActions.Create &&
143 mode !== DrawingBoardModes.VIEW && mode !== DrawingBoardModes.RETRY) {
148 /**********************************************
149 * should return true if can duplicate by mode
150 **********************************************/
151 shouldShowDuplicate(node): boolean {
152 const mode = this._store.getState().global.drawingBoardStatus;
153 return !mode.includes('RETRY');
156 /**********************************************
157 * should return true if can audit info
158 **********************************************/
159 shouldShowAuditInfo(node): boolean {
160 return this.isRetryMode() || (!_.isNil(node.data) && !_.isNil(node.data.action) && node.data.action !== ServiceInstanceActions.Create);
164 isRetryMode(): boolean {
165 const mode = this._store.getState().global.drawingBoardStatus;
166 return mode.includes('RETRY');
170 /**********************************************
171 * should return true if can add node instances
172 **********************************************/
173 shouldShowAddIcon(): boolean{
174 const mode = this._store.getState().global.drawingBoardStatus;
175 return mode === DrawingBoardModes.EDIT || mode=== DrawingBoardModes.CREATE;
177 /************************************************
178 return number of instances with action Delete
179 @type: vnfs networks, vngGroups (not vfModule)
180 @node : node model from the left tree
181 ************************************************/
182 getExistingInstancesWithDeleteMode(node, serviceModelId: string, type: string): number {
184 const existingInstances = this._store.getState().service.serviceInstance[serviceModelId][type];
185 const modelUniqueId = node.data.modelUniqueId;
186 if (!_.isNil(existingInstances)) {
187 for (let instanceKey in existingInstances) {
188 if (!_.isNil(existingInstances[instanceKey].action)) {
189 if (existingInstances[instanceKey].modelInfo.modelUniqueId === modelUniqueId && existingInstances[instanceKey].action.split('_').pop() === 'Delete') {
199 isServiceOnDeleteMode(serviceId: string): boolean {
200 return this._store.getState().service.serviceInstance[serviceId].action === ServiceInstanceActions.Delete;
204 openModal(node : any | any[] , serviceModelId : string, cb : Function) : void {
205 let type: string = _.isArray(node) ? 'Service' : node.data.typeName;
206 let messageBoxData: MessageBoxData = new MessageBoxData(
208 `You are about to mark for delete this ${type} this will also mark all its children and remove all new instances just added`,
213 text: "Mark and remove",
215 callback: cb.bind(this, node, serviceModelId),
218 {text: "Don’t Remove", size: "medium", closeModal: true}
221 MessageBoxService.openModal.next(messageBoxData);
224 someChildHasCreateAction(nodes: any | any[]) : boolean {
225 let nodesArr = _.isArray(nodes) ? nodes : [nodes];
226 for(const node of nodesArr){
227 if(node.action === ServiceInstanceActions.Create) {return true;}
229 for (let nodeChild of node.children) {
230 if (nodeChild.action === ServiceInstanceActions.Create) {
233 if(nodeChild.children && nodeChild.children.length > 0){
234 for(let child of nodeChild.children){
235 let hasCreateAction = this.someChildHasCreateAction(child);
236 if(hasCreateAction) {
247 shouldShowDeleteInstanceWithChildrenModal(node : any | any[] , serviceModelId : string, cb : Function) : void {
248 if(this.someChildHasCreateAction(node)){
249 this.openModal(node , serviceModelId, cb);
251 cb(node, serviceModelId)
256 isFailed(node): boolean {
257 return !_.isNil(node.data) ? node.data.isFailed : false;
260 /************************************************
261 in a case the node is failed e.g. not instantiated correctly
262 the function will call to openRetryInstanceAuditInfoModal
263 @node : node model from the left tree
264 @serviceModelId : serviceModelId
266 @instanceType: instanceType
267 @modelInfoService : the model (vnf, vfmodule, network, vnfgroup)object that call to the function (this)
268 ************************************************/
269 openAuditInfoModal(node, serviceModelId, instance, instanceType, modelInfoService : ILevelNodeInfo){
270 AuditInfoModalComponent.openInstanceAuditInfoModal.next({
271 instanceId: serviceModelId,
273 model: modelInfoService.getModel(node.data.modelName, instance, this._store.getState().service.serviceHierarchy[serviceModelId]),
279 addGeneralInfoItems(modelInfoSpecificItems: ModelInformationItem[], type: ComponentInfoType, model, instance):ComponentInfoModel {
280 let modelInfoItems: ModelInformationItem[] = [
281 ModelInformationItem.createInstance("Model version", model ? model.version : null),
282 ModelInformationItem.createInstance("Model customization ID", model ? model.customizationUuid : null),
283 ModelInformationItem.createInstance("Instance ID", instance ? instance.instanceId : null),
284 ModelInformationItem.createInstance("Instance type", instance ? instance.instanceType : null),
285 ModelInformationItem.createInstance("In maintenance", instance? instance.inMaint : null),
287 modelInfoItems = modelInfoItems.concat(modelInfoSpecificItems);
288 return this.getComponentInfoModelByModelInformationItems(modelInfoItems, type, instance);
291 getComponentInfoModelByModelInformationItems(modelInfoItems: ModelInformationItem[], type: ComponentInfoType, instance){
292 const modelInfoItemsWithoutEmpty = _.filter(modelInfoItems, function(item){ return !item.values.every(_.isNil)});
293 return new ComponentInfoModel(type, modelInfoItemsWithoutEmpty, [], instance != null);