Add another Network to the new view/edit screen
[vid.git] / vid-webpack-master / src / app / drawingBoard / service-planning / drawing-board-tree / drawing-board-tree.component.ts
index 6be5036..18c3f72 100644 (file)
@@ -11,9 +11,8 @@ import {IframeService} from "../../../shared/utils/iframe.service";
 import {DuplicateService} from '../duplicate/duplicate.service';
 import {DrawingBoardTreeService, TreeNodeContextMenuModel} from "./drawing-board-tree.service";
 import {NetworkPopupService} from "../../../shared/components/genericFormPopup/genericFormServices/network/network.popup.service";
-import {VfModulePopuopService} from "../../../shared/components/genericFormPopup/genericFormServices/vfModule/vfModule.popuop.service";
+import {VfModulePopupService} from "../../../shared/components/genericFormPopup/genericFormServices/vfModule/vfModule.popup.service";
 import {VnfPopupService} from "../../../shared/components/genericFormPopup/genericFormServices/vnf/vnf.popup.service";
-import {SdcUiServices} from "onap-ui-angular";
 import {HighlightPipe} from "../../../shared/pipes/highlight/highlight-filter.pipe";
 import {VnfGroupPopupService} from "../../../shared/components/genericFormPopup/genericFormServices/vnfGroup/vnfGroup.popup.service";
 import {ObjectToInstanceTreeService} from "../objectsToTree/objectToInstanceTree/objectToInstanceTree.service";
@@ -28,6 +27,8 @@ import {ComponentInfoService} from "../component-info/component-info.service";
 import {ComponentInfoModel} from "../component-info/component-info-model";
 import {ObjectToModelTreeService} from "../objectsToTree/objectToModelTree/objectToModelTree.service";
 import {DrawingBoardModes} from "../drawing-board.modes";
+import {ServiceInstanceActions} from "../../../shared/models/serviceInstanceActions";
+import {ModalService} from "../../../shared/components/customModal/services/modal.service";
 
 @Component({
   selector: 'drawing-board-tree',
@@ -50,8 +51,7 @@ export class DrawingBoardTreeComponent implements OnInit, AfterViewInit {
   @Input() pageMode : DrawingBoardModes;
   static triggerDeleteActionService: Subject<string> = new Subject<string>();
   static triggerUndoDeleteActionService: Subject<string> = new Subject<string>();
-  static triggerreCalculateIsDirty: Subject<string> = new Subject<string>();
-  @ViewChild(ContextMenuComponent) public contextMenu: ContextMenuComponent;
+  @ViewChild(ContextMenuComponent, {static: false}) public contextMenu: ContextMenuComponent;
 
   constructor(private _contextMenuService: ContextMenuService,
               private _iframeService: IframeService,
@@ -59,10 +59,10 @@ export class DrawingBoardTreeComponent implements OnInit, AfterViewInit {
               private store: NgRedux<AppState>,
               private route: ActivatedRoute,
               private _duplicateService: DuplicateService,
-              private modalService: SdcUiServices.ModalService,
+              private modalService: ModalService,
               private _drawingBoardTreeService: DrawingBoardTreeService,
               private _networkPopupService: NetworkPopupService,
-              private _vfModulePopuopService: VfModulePopuopService,
+              private _vfModulePopuopService: VfModulePopupService,
               private _vnfPopupService: VnfPopupService,
               private _vnfGroupPopupService: VnfGroupPopupService,
               private _errorMsgService: ErrorMsgService,
@@ -86,12 +86,12 @@ export class DrawingBoardTreeComponent implements OnInit, AfterViewInit {
       });
     });
 
-    DrawingBoardTreeComponent.triggerUndoDeleteActionService.subscribe((serviceModelId) => {
-      this.drawingBoardTreeService.undoDeleteActionService(this.nodes, serviceModelId);
+    DrawingBoardTreeService.triggerCheckIsDirty.subscribe((serviceModelId)=>{
       this.store.dispatch(changeServiceIsDirty(this.nodes, serviceModelId));
-    });
+    })
 
-    DrawingBoardTreeComponent.triggerreCalculateIsDirty.subscribe((serviceModelId) => {
+    DrawingBoardTreeComponent.triggerUndoDeleteActionService.subscribe((serviceModelId) => {
+      this.drawingBoardTreeService.undoDeleteActionService(this.nodes, serviceModelId);
       this.store.dispatch(changeServiceIsDirty(this.nodes, serviceModelId));
     });
 
@@ -119,18 +119,18 @@ export class DrawingBoardTreeComponent implements OnInit, AfterViewInit {
   @Output()
   highlightNode: EventEmitter<number> = new EventEmitter<number>();
 
-  @ViewChild('tree') tree: TreeComponent;
+  @ViewChild('tree', {static: false}) tree: TreeComponent;
   missingDataTooltip: string = Constants.Error.MISSING_VNF_DETAILS;
   currentNode: ITreeNode = null;
   flags: any;
   nodes = [];
   serviceModelId: string;
   options = {
-    allowDrag: this._dragAndDropService.isAllow(),
+    allowDrag: this._dragAndDropService.isFlagOn(),
     actionMapping: {
       mouse: {
         drop: (tree:TreeModel, node:TreeNode, $event:any, {from, to}) => {
-          this._dragAndDropService.drag(this.store, this.serviceModelId, this.nodes, {from, to});
+          this._dragAndDropService.drop(this.store, this.serviceModelId, this.nodes, {from, to});
         }
       }
     },
@@ -203,13 +203,37 @@ export class DrawingBoardTreeComponent implements OnInit, AfterViewInit {
     return false;
   }
 
+
+
+  isUpgraded(node: ITreeNode): boolean {
+    return this.isLabeledAsAction(node, "Upgrade");
+  }
+
+  isDeleted(node: ITreeNode): boolean {
+    return this.isLabeledAsAction(node, "Delete");
+  }
+
+  private isLabeledAsAction(node: ITreeNode, action) {
+    let nodeAction = node.data.action.split('_').pop();
+    if (!_.isNil(nodeAction)) {
+      return nodeAction === action;
+    }
+    return false;
+  }
+
   public selectNode(node: ITreeNode): void {
     node.expand();
     this._sharedTreeService.setSelectedVNF(node);
     this.highlightNode.emit(node.data.modelUniqueId);
     if (FeatureFlagsService.getFlagState(Features.FLAG_1906_COMPONENT_INFO, this.store)) {
       const serviceHierarchy = this._store.getState().service.serviceHierarchy[this.serviceModelId];
-      const model = node.data.getModel(node.data.modelName, node.data, serviceHierarchy);
+
+      const instanceModel = this._sharedTreeService.modelByIdentifiers(
+        serviceHierarchy, node.data.modelTypeName,
+        this._sharedTreeService.modelUniqueNameOrId(node.data), node.data.modelName
+      );
+
+      const model = node.data.getModel(instanceModel);
       const modelInfoItems = node.data.getInfo(model, node.data);
       const componentInfoModel: ComponentInfoModel = this._sharedTreeService.addGeneralInfoItems(modelInfoItems, node.data.componentInfoType, model, node.data);
       ComponentInfoService.triggerComponentInfoChange.next(componentInfoModel);
@@ -220,6 +244,13 @@ export class DrawingBoardTreeComponent implements OnInit, AfterViewInit {
     this.tree.treeModel.getNodeById(id).parent.expand();
   }
 
+  getcontextMenuOptionLabel(contextMenuOption: TreeNodeContextMenuModel): string{
+    let optionLabel = contextMenuOption.label;
+    if(contextMenuOption.label === ServiceInstanceActions.Upgrade) {
+      return optionLabel.concat(" to V" + this._store.getState().service.serviceInstance[this.serviceModelId].latestAvailableVersion);
+    }
+    return optionLabel;
+  }
 }