diff options
author | Michael Lando <ml636r@att.com> | 2018-07-29 16:13:45 +0300 |
---|---|---|
committer | Michael Lando <ml636r@att.com> | 2018-07-29 16:20:34 +0300 |
commit | 5b593496b8f1b8e8be8d7d2dbcc223332e65a49b (patch) | |
tree | 2f9dfc45191e723da69cf74be7829784e9741b94 /catalog-ui/src/app/models/graph/zones/policy-instance.ts | |
parent | 9200382f2ce7b4bb729aa287d0878004b2d2b4f9 (diff) |
re base code
Change-Id: I12a5ca14a6d8a87e9316b9ff362eb131105f98a5
Issue-ID: SDC-1566
Signed-off-by: Michael Lando <ml636r@att.com>
Diffstat (limited to 'catalog-ui/src/app/models/graph/zones/policy-instance.ts')
-rw-r--r-- | catalog-ui/src/app/models/graph/zones/policy-instance.ts | 103 |
1 files changed, 99 insertions, 4 deletions
diff --git a/catalog-ui/src/app/models/graph/zones/policy-instance.ts b/catalog-ui/src/app/models/graph/zones/policy-instance.ts index 63136e6e21..c0a6678b21 100644 --- a/catalog-ui/src/app/models/graph/zones/policy-instance.ts +++ b/catalog-ui/src/app/models/graph/zones/policy-instance.ts @@ -1,8 +1,48 @@ import { PropertyModel } from "app/models"; import { CommonUtils } from "app/utils"; +import {IZoneInstanceMethod, IZoneInstanceAssignment} from "./zone-instance"; +import {GroupInstance} from "./group-instance"; +import {ComponentInstance} from "../../componentsInstances/componentInstance"; +import {TargetUiObject} from "../../ui-models/ui-target-object"; +import {TargetOrMemberType} from "../../../utils/constants"; +/* The request and response should be same model, need to fix in BE */ +export class PolicyTargetsMap { + COMPONENT_INSTANCES:Array<string>; + GROUPS:Array<string>; +} +//TODO remove this +export class PolicyTargetsRequest { -export class PolicyInstance { + requestItems:Array<PolicyTargetsRequestItem>; + + constructor(groups:Array<string>,instances:Array<string>){ + + this.requestItems = []; + + if (instances && instances.length>0) { + let instancesObj:PolicyTargetsRequestItem = { + type: "component_Instances", + uniqueIds: instances + }; + this.requestItems.push(instancesObj); + } + if (groups && groups.length>0) { + let groupsObj:PolicyTargetsRequestItem = { + type: "groups", + uniqueIds: groups + }; + this.requestItems.push(groupsObj); + } + } +} + +export class PolicyTargetsRequestItem { + type: string; + uniqueIds:Array<String>; +} + +export class PolicyInstance implements IZoneInstanceMethod { componentName:string; description:string; empty:boolean; @@ -12,13 +52,17 @@ export class PolicyInstance { name:string; normalizedName:string; - policyTypeName:string; + type:string; policyTypeUid:string; policyUUID:string; properties:Array<PropertyModel>; - targets:Array<string>; + targets:PolicyTargetsMap; uniqueId:string; version:string; + iconSprite:string; + icon:string; + originArchived:boolean; + constructor(policy?:PolicyInstance) { this.componentName = policy.componentName; @@ -30,7 +74,7 @@ export class PolicyInstance { this.name = policy.name; this.normalizedName =policy.normalizedName; - this.policyTypeName = policy.policyTypeName; + this.type = policy.type; this.policyTypeUid = policy.policyTypeUid; this.policyUUID = policy.policyUUID; this.properties = CommonUtils.initProperties(policy.properties); @@ -38,6 +82,57 @@ export class PolicyInstance { this.uniqueId = policy.uniqueId; this.version = policy.version; + this.iconSprite = ''; + this.icon = 'icon-policy'; + } + + public getTargetsAsUiObject(componentInstances?:Array<ComponentInstance>, groupInstances?:Array<GroupInstance>):Array<TargetUiObject> { + let savedItems:Array<TargetUiObject> = []; + + //get all targets from component instances + if (!_.isEmpty(this.targets.COMPONENT_INSTANCES)) { + this.targets.COMPONENT_INSTANCES.forEach((targetInstanceId:string)=> { + let componentInstance:ComponentInstance; + if (componentInstances) { + componentInstance = _.find(componentInstances, function (_componentInstance:ComponentInstance) { + return _componentInstance.uniqueId === targetInstanceId; + }) + } + savedItems.push(new TargetUiObject(targetInstanceId, TargetOrMemberType.COMPONENT_INSTANCES, componentInstance ? componentInstance.name : undefined)); + }); + } + + //get all targets from groupInstances + if (!_.isEmpty(this.targets.GROUPS)) { + this.targets.GROUPS.forEach((groupsTargetId:string)=> { + let groupInstance:GroupInstance; + if (groupInstances) { + groupInstance = _.find(groupInstances, function (_groupInstance:GroupInstance) { + return _groupInstance.uniqueId === groupsTargetId; + }) + } + savedItems.push(new TargetUiObject(groupsTargetId, TargetOrMemberType.GROUPS, groupInstance? groupInstance.name : undefined)); + }); + } + return savedItems; + }; + + public saveTargets = (newTargets:Array<TargetUiObject>):void => { + this.targets.COMPONENT_INSTANCES = newTargets.filter(target => target.type === TargetOrMemberType.COMPONENT_INSTANCES).map(target => target.uniqueId); + this.targets.GROUPS = newTargets.filter(target => target.type === TargetOrMemberType.GROUPS).map(target => target.uniqueId); + } + + // This function is used for the zone to get and set the assignment + public getSavedAssignments = ():Array<IZoneInstanceAssignment> => { + return this.getTargetsAsUiObject(); + }; + + public setSavedAssignments = (newMembers:Array<IZoneInstanceAssignment>):void => { + this.saveTargets(newMembers); + } + + public get iconClass() { + return this.iconSprite + ' ' + this.icon; } }
\ No newline at end of file |