mirror of
https://github.com/GNS3/gns3-web-ui.git
synced 2024-12-21 22:07:48 +00:00
NodeCreatedLabelStylesFixer prepartion
This commit is contained in:
parent
092789eecc
commit
a4c3bd254b
@ -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;');
|
||||
});
|
||||
});
|
@ -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;
|
||||
}
|
||||
}
|
@ -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);
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user