summaryrefslogtreecommitdiffstats
path: root/vid-webpack-master/src/app/drawingBoard/service-planning/objectsToTree/objectToModelTree/objectToModelTree.service.ts
diff options
context:
space:
mode:
authorIttay Stern <ittay.stern@att.com>2018-08-29 17:01:32 +0300
committerIttay Stern <ittay.stern@att.com>2019-02-18 18:35:30 +0200
commit6f900cc45d7dd7f97430812b86b5c1d1693c8ae3 (patch)
tree936005c364dc5a7264d6304d4777c3d83494db22 /vid-webpack-master/src/app/drawingBoard/service-planning/objectsToTree/objectToModelTree/objectToModelTree.service.ts
parent67d99f816cc583643c35193197594cf78d8ce60a (diff)
merge from ecomp a88f0072 - Modern UI
Issue-ID: VID-378 Change-Id: Ibcb23dd27f550cf32ce2fe0239f0f496ae014ff6 Signed-off-by: Ittay Stern <ittay.stern@att.com>
Diffstat (limited to 'vid-webpack-master/src/app/drawingBoard/service-planning/objectsToTree/objectToModelTree/objectToModelTree.service.ts')
-rw-r--r--vid-webpack-master/src/app/drawingBoard/service-planning/objectsToTree/objectToModelTree/objectToModelTree.service.ts98
1 files changed, 98 insertions, 0 deletions
diff --git a/vid-webpack-master/src/app/drawingBoard/service-planning/objectsToTree/objectToModelTree/objectToModelTree.service.ts b/vid-webpack-master/src/app/drawingBoard/service-planning/objectsToTree/objectToModelTree/objectToModelTree.service.ts
new file mode 100644
index 000000000..e941faad3
--- /dev/null
+++ b/vid-webpack-master/src/app/drawingBoard/service-planning/objectsToTree/objectToModelTree/objectToModelTree.service.ts
@@ -0,0 +1,98 @@
+import {Injectable} from "@angular/core";
+import {ILevelNodeInfo} from "../models/basic.model.info";
+import {ObjectToTreeService} from "../objectToTree.service";
+import * as _ from "lodash";
+
+@Injectable()
+export class ObjectToModelTreeService {
+ constructor(private _objectToTreeService: ObjectToTreeService) {
+ }
+
+ /***********************************************************
+ * return array of first level node with there child's
+ * @param serviceModel - The serviceHierarchy object
+ ************************************************************/
+ convertServiceHierarchyModelToTreeNodes(serviceModel): any[] {
+ let _this = this;
+ const firstLevelOptions: ILevelNodeInfo[] = _this._objectToTreeService.getFirstLevelOptions();
+ let nodes = [];
+ for (let option of firstLevelOptions) {
+ _.forOwn(serviceModel[option.name], function (item, key) {
+ nodes.push(_this.addFirstLevelModel(serviceModel.service.uuid, key, item, item.type, serviceModel, option));
+ });
+ }
+ console.log('nodes', nodes);
+ return nodes;
+ }
+
+
+ /***********************************************************
+ * return node with all his child's
+ * @param name - Model name
+ * @param serviceId - service id
+ * @param currentModel - current Model object
+ * @param type - current Model type
+ * @param parentModel - current parent Model object
+ * @param levelNodeInfo - current level node information
+ ************************************************************/
+ private addFirstLevelModel(serviceId: string, name, currentModel, type, parentModel, levelNodeInfo: ILevelNodeInfo) {
+ let node = ObjectToModelTreeService.convertItemToTreeNode(serviceId, name, currentModel, type, null, levelNodeInfo);
+ node.children = this.addNextLevelNodes(serviceId, currentModel, parentModel, levelNodeInfo, node);
+ return node;
+ }
+
+ /***********************************************************
+ * return all the child's of node (is child exist)
+ * else return empty array.
+ * @param currentModel - current Model object
+ * @param parentModel - current parent Model object
+ * @param levelNodeInfo - current level node information
+ * @param parentNode - parent node.
+ ************************************************************/
+ addNextLevelNodes(serviceId: string, currentModel, parentModel, levelNodeInfo: ILevelNodeInfo, parentNode): any[] {
+ if (!_.isNil(levelNodeInfo.childName)) {
+ if (!_.isNil(currentModel[levelNodeInfo.childName])) {
+ let nextLevelNodeInfo = levelNodeInfo.getNextLevelObject.apply(this);
+ parentNode.children = Object.keys(currentModel[levelNodeInfo.childName]).map((key) =>
+ ObjectToModelTreeService.convertItemToTreeNode(serviceId, key, currentModel[levelNodeInfo.childName][key], levelNodeInfo.childName, currentModel, nextLevelNodeInfo));
+
+ }
+ }
+ return parentNode.children;
+ }
+
+
+ /***********************************************************
+ * return node with his properties
+ * @param serviceId
+ * @param name - model name
+ * @param currentModel - current model from serviceHierarchy
+ * @param valueType - model type
+ * @param parentModel - current parent model
+ * @param levelNodeInfo - current levelNodeInfo object
+ ************************************************************/
+ static convertItemToTreeNode(serviceId: string, name: string, currentModel: any, valueType: string, parentModel: string, levelNodeInfo: ILevelNodeInfo) {
+ let node = {
+ id: currentModel.customizationUuid || currentModel.uuid,
+ modelCustomizationId : currentModel.customizationUuid,
+ modelVersionId: currentModel.uuid,
+ modelUniqueId : currentModel.customizationUuid || currentModel.uuid,
+ name: name,
+ tooltip: levelNodeInfo.getTooltip(),
+ type: levelNodeInfo.getType(),
+ count: currentModel.count || 0,
+ max: currentModel.max || 1,
+ children: [],
+ disabled: false,
+ dynamicInputs: levelNodeInfo.updateDynamicInputsDataFromModel(currentModel),
+ isEcompGeneratedNaming: levelNodeInfo.isEcompGeneratedNaming(currentModel, parentModel)
+ };
+
+ node['onAddClick'] = (node, serviceId) => levelNodeInfo.onClickAdd(node, serviceId);
+ node['getNodeCount'] = (node, serviceId) => levelNodeInfo.getNodeCount(node, serviceId);
+ node['getMenuAction'] = (node, serviceId) => levelNodeInfo.getMenuAction(node, serviceId);
+ node['showNodeIcons'] = (node, serviceId) => levelNodeInfo.showNodeIcons(node, serviceId);
+ node['typeName'] = levelNodeInfo['typeName'];
+ return node;
+ }
+}