From a4c3bd254b9fed0d5bf732e93f84021c43c6bc1c Mon Sep 17 00:00:00 2001 From: ziajka Date: Fri, 26 Apr 2019 15:15:40 +0200 Subject: [PATCH] NodeCreatedLabelStylesFixer prepartion --- .../node-created-label-styles-fixer.spec.ts | 36 +++++++++++++++++++ .../node-created-label-styles-fixer.ts | 16 +++++++++ .../project-map/project-map.component.ts | 9 ++++- 3 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 src/app/components/project-map/helpers/node-created-label-styles-fixer.spec.ts create mode 100644 src/app/components/project-map/helpers/node-created-label-styles-fixer.ts diff --git a/src/app/components/project-map/helpers/node-created-label-styles-fixer.spec.ts b/src/app/components/project-map/helpers/node-created-label-styles-fixer.spec.ts new file mode 100644 index 00000000..f2c38e17 --- /dev/null +++ b/src/app/components/project-map/helpers/node-created-label-styles-fixer.spec.ts @@ -0,0 +1,36 @@ +import { NodeCreatedLabelStylesFixer } from "./node-created-label-styles-fixer"; +import { MapNode } from '../../../cartography/models/map/map-node'; +import { Node } from '../../../cartography/models/node'; +import { Label } from '../../../cartography/models/label'; + +describe('NodeCreatedLabelStylesFixer', () => { + let fixer: NodeCreatedLabelStylesFixer; + let nodeToMapNodeConverter; + + beforeEach(() => { + nodeToMapNodeConverter = { + convert: (node) => { + const n = new MapNode(); + n.width = node.width; + n.height = node.height; + return n; + } + }; + + fixer = new NodeCreatedLabelStylesFixer( + nodeToMapNodeConverter + ); + }); + + it('should fix label styles and position', () => { + const node = new Node(); + node.width = 100; + node.height = 100; + node.label = new Label(); + node.label.text = "my new label"; + + const fixed = fixer.fix(node); + + expect(fixed.label.style).toEqual('font-family: TypeWriter;font-size: 10.0;font-weight: bold;fill: #000000;fill-opacity: 1.0;'); + }); +}); diff --git a/src/app/components/project-map/helpers/node-created-label-styles-fixer.ts b/src/app/components/project-map/helpers/node-created-label-styles-fixer.ts new file mode 100644 index 00000000..aa0607eb --- /dev/null +++ b/src/app/components/project-map/helpers/node-created-label-styles-fixer.ts @@ -0,0 +1,16 @@ +import { Injectable } from '@angular/core'; +import { Node } from '../../../cartography/models/node'; +import { NodeToMapNodeConverter } from '../../../cartography/converters/map/node-to-map-node-converter'; + +@Injectable() +export class NodeCreatedLabelStylesFixer { + constructor( + private nodeToMapNodeConverter: NodeToMapNodeConverter + ) {} + + fix(node: Node): Node { + const mapNode = this.nodeToMapNodeConverter.convert(node); + + return node; + } +} diff --git a/src/app/components/project-map/project-map.component.ts b/src/app/components/project-map/project-map.component.ts index 67f88fb5..350c2199 100644 --- a/src/app/components/project-map/project-map.component.ts +++ b/src/app/components/project-map/project-map.component.ts @@ -43,6 +43,7 @@ import { RecentlyOpenedProjectService } from '../../services/recentlyOpenedProje import { MapLink } from '../../cartography/models/map/map-link'; import { MapLinkToLinkConverter } from '../../cartography/converters/map/map-link-to-link-converter'; import { LinkWidget } from '../../cartography/widgets/link'; +import { NodeCreatedLabelStylesFixer } from './helpers/node-created-label-styles-fixer'; @Component({ @@ -108,7 +109,8 @@ export class ProjectMapComponent implements OnInit, OnDestroy { private toolsService: ToolsService, private selectionManager: SelectionManager, private selectionTool: SelectionTool, - private recentlyOpenedProjectService: RecentlyOpenedProjectService + private recentlyOpenedProjectService: RecentlyOpenedProjectService, + private nodeCreatedLabelStylesFixer: NodeCreatedLabelStylesFixer ) {} ngOnInit() { @@ -274,6 +276,11 @@ export class ProjectMapComponent implements OnInit, OnDestroy { this.nodeService.createFromTemplate(this.server, this.project, template, 0, 0, 'local').subscribe(() => { this.projectService.nodes(this.server, this.project.project_id).subscribe((nodes: Node[]) => { + + nodes.filter((node) => node.label.style === null).forEach((node) => { + const fixedNode = this.nodeCreatedLabelStylesFixer.fix(node); + }); + this.nodesDataSource.set(nodes); }); });