summaryrefslogtreecommitdiffstats
path: root/catalog-ui/src/app/directives/graphs-v2/composition-graph/utils/composition-graph-zone-utils.ts
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-ui/src/app/directives/graphs-v2/composition-graph/utils/composition-graph-zone-utils.ts')
-rw-r--r--catalog-ui/src/app/directives/graphs-v2/composition-graph/utils/composition-graph-zone-utils.ts198
1 files changed, 169 insertions, 29 deletions
diff --git a/catalog-ui/src/app/directives/graphs-v2/composition-graph/utils/composition-graph-zone-utils.ts b/catalog-ui/src/app/directives/graphs-v2/composition-graph/utils/composition-graph-zone-utils.ts
index 28f2dc85d2..bcf0cb7bb9 100644
--- a/catalog-ui/src/app/directives/graphs-v2/composition-graph/utils/composition-graph-zone-utils.ts
+++ b/catalog-ui/src/app/directives/graphs-v2/composition-graph/utils/composition-graph-zone-utils.ts
@@ -1,55 +1,195 @@
-import { PolicyInstance } from "app/models/graph/zones/policy-instance";
-import { ZoneConfig, ZoneInstanceConfig } from "app/models/graph/zones/zone-child";
-import { DynamicComponentService } from "app/ng2/services/dynamic-component.service";
-import { PaletteAnimationComponent } from "app/ng2/components/ui/palette-animation/palette-animation.component";
-import { Point } from "../../../../models";
+import {PolicyInstance} from "app/models/graph/zones/policy-instance";
+import {ZoneInstance, ZoneInstanceType, ZoneInstanceAssignmentType} from "app/models/graph/zones/zone-instance";
+import {Zone} from "app/models/graph/zones/zone";
+import {DynamicComponentService} from "app/ng2/services/dynamic-component.service";
+import {PaletteAnimationComponent} from "app/ng2/components/ui/palette-animation/palette-animation.component";
+import {Point, LeftPaletteMetadataTypes, Component} from "../../../../models";
+import {CanvasHandleTypes} from "app/utils";
+import {PoliciesService} from "../../../../ng2/services/policies.service";
+import {Observable} from "rxjs";
+import {GroupsService} from "../../../../ng2/services/groups.service";
+import {GroupInstance} from "app/models/graph/zones/group-instance";
+
export class CompositionGraphZoneUtils {
- constructor(private dynamicComponentService: DynamicComponentService) {}
+ constructor(private dynamicComponentService:DynamicComponentService,
+ private policiesService:PoliciesService,
+ private groupsService:GroupsService) {
+ }
+
+
+ public createCompositionZones = ():Array<Zone> => {
+ let zones:Array<Zone> = [];
+
+ zones[ZoneInstanceType.POLICY] = new Zone('Policies', 'P', ZoneInstanceType.POLICY);
+ zones[ZoneInstanceType.GROUP] = new Zone('Groups', 'G', ZoneInstanceType.GROUP);
- public createCompositionZones(){
- let zones = {
- 'policy': new ZoneConfig('Policies', 'P', 'policy', false),
- 'group': new ZoneConfig('Groups', 'G', 'group', false)
- };
return zones;
}
- public initPolicyInstances(policyZone:ZoneConfig, policies:Array<PolicyInstance>) {
- if(policies && policies.length){
- policyZone.showZone = true;
+ public showZone = (zone:Zone):void => {
+ zone.visible = true;
+ zone.minimized = false;
+ }
+
+ public getZoneTypeForPaletteComponent = (componentCategory:LeftPaletteMetadataTypes) => {
+ if (componentCategory == LeftPaletteMetadataTypes.Group) {
+ return ZoneInstanceType.GROUP;
+ } else if (componentCategory == LeftPaletteMetadataTypes.Policy) {
+ return ZoneInstanceType.POLICY;
+ }
+ };
+
+ public initZoneInstances(zones:Array<Zone>, component:Component) {
+ if (component.groupInstances && component.groupInstances.length) {
+ this.showZone(zones[ZoneInstanceType.GROUP]);
+ _.forEach(component.groupInstances, (group:GroupInstance) => {
+ let newInstance = new ZoneInstance(group, component);
+ this.addInstanceToZone(zones[ZoneInstanceType.GROUP], newInstance);
+ });
+ }
+
+ if (component.policies && component.policies.length) {
+ this.showZone(zones[ZoneInstanceType.POLICY]);
+ _.forEach(component.policies, (policy:PolicyInstance) => {
+ let newInstance = new ZoneInstance(policy, component);
+ this.addInstanceToZone(zones[ZoneInstanceType.POLICY], newInstance);
+
+ });
}
- _.forEach(policies, (policy:PolicyInstance) => {
- policyZone.instances.push(new ZoneInstanceConfig(policy));
+ }
+
+ public findAndUpdateZoneInstanceData (zones: Array<Zone>, instanceData:PolicyInstance | GroupInstance) {
+ _.forEach(zones, (zone:Zone) => {
+ _.forEach(zone.instances, (zoneInstance:ZoneInstance) => {
+ if(zoneInstance.instanceData.uniqueId === instanceData.uniqueId){
+ zoneInstance.updateInstanceData(instanceData);
+ }
+ });
});
}
- public addInstanceToZone(zone:ZoneConfig, instance:PolicyInstance){
- zone.instances.push(new ZoneInstanceConfig(instance));
+ public updateTargetsOrMembersOnCanvasDelete = (canvasNodeID:string, zones:Array<Zone>, type:ZoneInstanceAssignmentType):void => {
+ _.forEach(zones, (zone) => {
+ _.forEach(zone.instances, (zoneInstance:ZoneInstance) => {
+ if (zoneInstance.isAlreadyAssigned(canvasNodeID)) {
+ zoneInstance.addOrRemoveAssignment(canvasNodeID, type);
+ //remove it from our list of BE targets and members as well (so that it will not be sent in future calls to BE).
+ zoneInstance.instanceData.setSavedAssignments(zoneInstance.assignments);
+ }
+ });
+ });
+ };
+
+ public createZoneInstanceFromLeftPalette = (zoneType:ZoneInstanceType, component:Component, paletteComponentType:string):Observable<ZoneInstance> => {
+ if (zoneType === ZoneInstanceType.POLICY) {
+ return this.policiesService.createPolicyInstance(component.componentType, component.uniqueId, paletteComponentType).map(response => {
+ let newInstance = new PolicyInstance(response);
+ component.policies.push(newInstance);
+ return new ZoneInstance(newInstance, component);
+ });
+ } else if (zoneType === ZoneInstanceType.GROUP) {
+ return this.groupsService.createGroupInstance(component.componentType, component.uniqueId, paletteComponentType).map(response => {
+ let newInstance = new GroupInstance(response);
+ component.groupInstances.push(newInstance);
+ return new ZoneInstance(newInstance, component);
+ });
+ }
+ }
+
+ public addInstanceToZone(zone:Zone, instance:ZoneInstance, hide?:boolean) {
+ if(hide){
+ instance.hidden = true;
+ }
+ zone.instances.push(instance);
+
};
- private findZoneCoordinates(zoneType):Point{
- let point:Point = new Point(0,0);
+ private findZoneCoordinates(zoneType):Point {
+ let point:Point = new Point(0, 0);
let zone = angular.element(document.querySelector('.' + zoneType + '-zone'));
- let wrapperZone = zone.offsetParent();
- point.x = zone.prop('offsetLeft') + wrapperZone.prop('offsetLeft');
- point.y = zone.prop('offsetTop') + wrapperZone.prop('offsetTop');
+ let wrapperZone = zone.offsetParent();
+ point.x = zone.prop('offsetLeft') + wrapperZone.prop('offsetLeft');
+ point.y = zone.prop('offsetTop') + wrapperZone.prop('offsetTop');
return point;
}
- public showAnimationToZone = (startPoint:Point, zoneType:string) => {
-
+ public createPaletteToZoneAnimation = (startPoint:Point, zoneType:ZoneInstanceType, newInstance:ZoneInstance) => {
+ let zoneTypeName = ZoneInstanceType[zoneType].toLowerCase();
let paletteToZoneAnimation = this.dynamicComponentService.createDynamicComponent(PaletteAnimationComponent);
paletteToZoneAnimation.instance.from = startPoint;
- paletteToZoneAnimation.instance.to = this.findZoneCoordinates(zoneType);
- paletteToZoneAnimation.instance.iconName = zoneType;
+ paletteToZoneAnimation.instance.type = zoneType;
+ paletteToZoneAnimation.instance.to = this.findZoneCoordinates(zoneTypeName);
+ paletteToZoneAnimation.instance.zoneInstance = newInstance;
+ paletteToZoneAnimation.instance.iconName = zoneTypeName;
paletteToZoneAnimation.instance.runAnimation();
}
-
+ public startCyTagMode = (cy:Cy.Instance) => {
+ cy.autolock(true);
+ cy.nodes().unselectify();
+ cy.emit('tagstart'); //dont need to show handles because they're already visible bcz of hover event
+
+ };
+
+ public endCyTagMode = (cy:Cy.Instance) => {
+ cy.emit('tagend');
+ cy.nodes().selectify();
+ cy.autolock(false);
+ };
+
+ public handleTagClick = (cy:Cy.Instance, zoneInstance:ZoneInstance, nodeId:string) => {
+ zoneInstance.addOrRemoveAssignment(nodeId, ZoneInstanceAssignmentType.COMPONENT_INSTANCES);
+ this.showZoneTagIndicationForNode(nodeId, zoneInstance, cy);
+ };
+
+ public showGroupZoneIndications = (groupInstances:Array<ZoneInstance>, policyInstance:ZoneInstance) => {
+ groupInstances.forEach((groupInstance:ZoneInstance)=> {
+ let handle:string = this.getCorrectHandleForNode(groupInstance.instanceData.uniqueId, policyInstance);
+ groupInstance.showHandle(handle);
+ })
+ };
+
+ public hideGroupZoneIndications = (instances:Array<ZoneInstance>) => {
+ instances.forEach((instance) => {
+ instance.hideHandle();
+ })
+ }
+
+ public showZoneTagIndications = (cy:Cy.Instance, zoneInstance:ZoneInstance) => {
+
+ cy.nodes().forEach(node => {
+ let handleType:string = this.getCorrectHandleForNode(node.id(), zoneInstance);
+ cy.emit('showhandle', [node, handleType]);
+ });
+ };
+
+ public showZoneTagIndicationForNode = (nodeId:string, zoneInstance:ZoneInstance, cy:Cy.Instance) => {
+ let node = cy.getElementById(nodeId);
+ let handleType:string = this.getCorrectHandleForNode(nodeId, zoneInstance);
+ cy.emit('showhandle', [node, handleType]);
+ }
+
+ public hideZoneTagIndications = (cy:Cy.Instance) => {
+ cy.emit('hidehandles');
+ };
+
+ public getCorrectHandleForNode = (nodeId:string, zoneInstance:ZoneInstance):string => {
+ if (zoneInstance.isAlreadyAssigned(nodeId)) {
+ if (zoneInstance.type == ZoneInstanceType.POLICY) {
+ return CanvasHandleTypes.TAGGED_POLICY;
+ } else {
+ return CanvasHandleTypes.TAGGED_GROUP;
+ }
+ } else {
+ return CanvasHandleTypes.TAG_AVAILABLE;
+ }
+ };
}
CompositionGraphZoneUtils.$inject = [
- 'DynamicComponentService'
+ 'DynamicComponentService',
+ 'PoliciesServiceNg2',
+ 'GroupsServiceNg2'
]; \ No newline at end of file