VID - Feature flag for PNF in modern UI
[vid.git] / vid-webpack-master / src / app / drawingBoard / service-planning / objectsToTree / objectToInstanceTree / objectToInstanceTree.service.ts
index 8ddb4ba..cabf806 100644 (file)
@@ -8,10 +8,12 @@ import {ErrorMsgService} from "../../../../shared/components/error-msg/error-msg
 import {FeatureFlagsService, Features} from "../../../../shared/services/featureFlag/feature-flags.service";
 import {NgRedux} from "@angular-redux/store";
 import {AppState} from "../../../../shared/store/reducers";
+import {SharedTreeService} from "../shared.tree.service";
 
 @Injectable()
 export class ObjectToInstanceTreeService {
-  constructor(private _objectToTreeService: ObjectToTreeService, private _errorMsgService: ErrorMsgService, private store: NgRedux<AppState>) {
+  constructor(private _objectToTreeService: ObjectToTreeService, private _errorMsgService: ErrorMsgService,
+              private store: NgRedux<AppState>, private _sharedTreeService: SharedTreeService) {
     this.numberOfFailed = 0;
     this.numberOfElements = 0;
 
@@ -34,10 +36,11 @@ export class ObjectToInstanceTreeService {
     this.numberOfFailed = 0;
     this.numberOfElements = 0;
     let _this = this;
-    const firstLevelOptions: ILevelNodeInfo[] = _this._objectToTreeService.getFirstLevelOptions();
+    const serviceModelId:string = serviceInstance.modelInfo.modelVersionId;
+    const firstLevelOptions: ILevelNodeInfo[] = _this._objectToTreeService.getFirstLevelOptions(serviceInstance.isAlaCarte);
     for (let option of firstLevelOptions) {
       _.forOwn(serviceInstance[option.name], function (instance, modelName) {
-        nodes.push(_this.getNodeInstance(modelName, null, instance, serviceHierarchy, option));
+        nodes.push(_this.getNodeInstance(modelName, null, instance, serviceHierarchy, option, serviceModelId));
       });
     }
     return this.sortElementsByPosition(nodes);
@@ -71,18 +74,23 @@ export class ObjectToInstanceTreeService {
    * @param instance
    * @param serviceHierarchy - The service Hierarchy store
    * @param option
+   * @param serviceModelId
    * @param parentType
    ****************************************************************/
-  getNodeInstance(modelName: string, parentModel: any, instance: any, serviceHierarchy, option: ILevelNodeInfo, parentType ?: string) {
-    const model = option.getModel(modelName, instance, serviceHierarchy);
-
-    let optionalNodes = option.createInstanceTreeNode(instance, model, parentModel, modelName);
+  getNodeInstance(modelName: string, parentModel: any, instance: any, serviceHierarchy, option: ILevelNodeInfo, serviceModelId: string, parentType ?: string) {
+    const instanceModel = this._sharedTreeService.modelByIdentifiers(
+      serviceHierarchy, option.name,
+      this._sharedTreeService.modelUniqueNameOrId(instance), modelName
+    );
+    const model = option.getModel(instanceModel);
+
+    let optionalNodes = option.createInstanceTreeNode(instance, model, parentModel, modelName, serviceModelId);
     this.increaseNumberOfFailed(optionalNodes);
     this.increaseNumberOfExcitingElements();
     let nodes: any[] = _.isArray(optionalNodes) ? optionalNodes : [optionalNodes];
     for (let node of nodes) {
       node = this.addingExtraDataToNode(node, modelName, parentModel, instance, serviceHierarchy, option, parentType);
-      let children = this.addNextInstanceTreeNode(instance, model, option, node, serviceHierarchy);
+      let children = this.addNextInstanceTreeNode(instance, model, option, node, serviceHierarchy, serviceModelId);
       if (!_.isNil(children) && children.length > 0) {
         node.children = this.sortElementsByPosition(children);
       }
@@ -97,6 +105,7 @@ export class ObjectToInstanceTreeService {
       node.parentType = !_.isNil(parentType) ? parentType : "";
       node.updatePoistionFunction = option.updatePosition;
       node.position = option.getNodePosition(instance, node.dynamicModelName);
+      node.modelTypeName = option.name;
       node.getModel = option.getModel.bind(option);
       node.getInfo = !_.isNil(option.getInfo) ? option.getInfo.bind(option) : ()=>{};
       node.componentInfoType = option.componentInfoType;
@@ -119,8 +128,9 @@ export class ObjectToInstanceTreeService {
    * @param levelNodeInfo
    * @param parentNode
    * @param serviceHierarchy - The service Hierarchy store
+   * @param serviceModelId
    ****************************************************************/
-  addNextInstanceTreeNode(parentInstance, parentModel, levelNodeInfo: ILevelNodeInfo, parentNode, serviceHierarchy): any[] {
+  addNextInstanceTreeNode(parentInstance, parentModel, levelNodeInfo: ILevelNodeInfo, parentNode, serviceHierarchy, serviceModelId: string): any[] {
     if (!_.isNil(levelNodeInfo.childNames)&& levelNodeInfo.childNames.length > 0) {
       const that = this;
       parentNode.children = [];
@@ -130,7 +140,7 @@ export class ObjectToInstanceTreeService {
           let nextLevelNodeInfo = levelNodeInfo.getNextLevelObject.apply(that, [childName]);
           Object.keys(parentInstance[childName]).map((modelName) => {
             let nextLevelInstance = parentInstance[childName][modelName];
-            let nodes: any[] | any = that.getNodeInstance(modelName, parentModel, nextLevelInstance, serviceHierarchy, nextLevelNodeInfo, parentType);
+            let nodes: any[] | any = that.getNodeInstance(modelName, parentModel, nextLevelInstance, serviceHierarchy, nextLevelNodeInfo, serviceModelId, parentType);
             if (_.isArray(nodes)) {
               parentNode.children = parentNode.children.concat(nodes);
             } else {