mirror of
https://github.com/GNS3/gns3-web-ui.git
synced 2025-06-21 16:09:55 +00:00
Fix label of added node (when GUI is not running). Fixes #292
This commit is contained in:
@ -182,6 +182,7 @@ import { ResumeLinkActionComponent } from './components/project-map/context-menu
|
|||||||
import { StopCaptureActionComponent } from './components/project-map/context-menu/actions/stop-capture/stop-capture-action.component';
|
import { StopCaptureActionComponent } from './components/project-map/context-menu/actions/stop-capture/stop-capture-action.component';
|
||||||
import { ConsoleService } from './services/settings/console.service';
|
import { ConsoleService } from './services/settings/console.service';
|
||||||
import { DefaultConsoleService } from './services/settings/default-console.service';
|
import { DefaultConsoleService } from './services/settings/default-console.service';
|
||||||
|
import { NodeCreatedLabelStylesFixer } from './components/project-map/helpers/node-created-label-styles-fixer';
|
||||||
|
|
||||||
if (environment.production) {
|
if (environment.production) {
|
||||||
Raven.config('https://b2b1cfd9b043491eb6b566fd8acee358@sentry.io/842726', {
|
Raven.config('https://b2b1cfd9b043491eb6b566fd8acee358@sentry.io/842726', {
|
||||||
@ -369,7 +370,8 @@ if (environment.production) {
|
|||||||
RecentlyOpenedProjectService,
|
RecentlyOpenedProjectService,
|
||||||
ServerManagementService,
|
ServerManagementService,
|
||||||
ConsoleService,
|
ConsoleService,
|
||||||
DefaultConsoleService
|
DefaultConsoleService,
|
||||||
|
NodeCreatedLabelStylesFixer
|
||||||
],
|
],
|
||||||
entryComponents: [
|
entryComponents: [
|
||||||
AddServerDialogComponent,
|
AddServerDialogComponent,
|
||||||
|
@ -1,24 +1,23 @@
|
|||||||
import { NodeCreatedLabelStylesFixer } from "./node-created-label-styles-fixer";
|
import { NodeCreatedLabelStylesFixer } from "./node-created-label-styles-fixer";
|
||||||
import { MapNode } from '../../../cartography/models/map/map-node';
|
|
||||||
import { Node } from '../../../cartography/models/node';
|
import { Node } from '../../../cartography/models/node';
|
||||||
import { Label } from '../../../cartography/models/label';
|
import { Label } from '../../../cartography/models/label';
|
||||||
|
|
||||||
describe('NodeCreatedLabelStylesFixer', () => {
|
describe('NodeCreatedLabelStylesFixer', () => {
|
||||||
let fixer: NodeCreatedLabelStylesFixer;
|
let fixer: NodeCreatedLabelStylesFixer;
|
||||||
let nodeToMapNodeConverter;
|
let calculator;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
nodeToMapNodeConverter = {
|
calculator = {
|
||||||
convert: (node) => {
|
calculate: (text, styles) => {
|
||||||
const n = new MapNode();
|
return {
|
||||||
n.width = node.width;
|
width: 50,
|
||||||
n.height = node.height;
|
height: 10
|
||||||
return n;
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
fixer = new NodeCreatedLabelStylesFixer(
|
fixer = new NodeCreatedLabelStylesFixer(
|
||||||
nodeToMapNodeConverter
|
calculator
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -32,5 +31,7 @@ describe('NodeCreatedLabelStylesFixer', () => {
|
|||||||
const fixed = fixer.fix(node);
|
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;');
|
expect(fixed.label.style).toEqual('font-family: TypeWriter;font-size: 10.0;font-weight: bold;fill: #000000;fill-opacity: 1.0;');
|
||||||
|
expect(fixed.label.x).toEqual(25);
|
||||||
|
expect(fixed.label.y).toEqual(-18);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,16 +1,24 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { Node } from '../../../cartography/models/node';
|
import { Node } from '../../../cartography/models/node';
|
||||||
import { NodeToMapNodeConverter } from '../../../cartography/converters/map/node-to-map-node-converter';
|
import { FontBBoxCalculator } from '../../../cartography/helpers/font-bbox-calculator';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class NodeCreatedLabelStylesFixer {
|
export class NodeCreatedLabelStylesFixer {
|
||||||
|
MARGIN_BETWEEN_NODE_AND_LABEL = 8;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private nodeToMapNodeConverter: NodeToMapNodeConverter
|
private fontBBCalculator: FontBBoxCalculator
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
fix(node: Node): Node {
|
fix(node: Node): Node {
|
||||||
const mapNode = this.nodeToMapNodeConverter.convert(node);
|
node.label.style = 'font-family: TypeWriter;font-size: 10.0;font-weight: bold;fill: #000000;fill-opacity: 1.0;';
|
||||||
|
const bb = this.fontBBCalculator.calculate(node.label.text, node.label.style);
|
||||||
|
|
||||||
|
// center label
|
||||||
|
node.label.x = node.width / 2 - bb.width / 2;
|
||||||
|
|
||||||
|
// move above the node
|
||||||
|
node.label.y = -bb.height - this.MARGIN_BETWEEN_NODE_AND_LABEL;
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,6 +42,7 @@ import { Link } from '../../models/link';
|
|||||||
import { Project } from '../../models/project';
|
import { Project } from '../../models/project';
|
||||||
import { CapturingSettings } from '../../models/capturingSettings';
|
import { CapturingSettings } from '../../models/capturingSettings';
|
||||||
import { LinkWidget } from '../../cartography/widgets/link';
|
import { LinkWidget } from '../../cartography/widgets/link';
|
||||||
|
import { NodeCreatedLabelStylesFixer } from './helpers/node-created-label-styles-fixer';
|
||||||
|
|
||||||
export class MockedProgressService {
|
export class MockedProgressService {
|
||||||
public activate() {}
|
public activate() {}
|
||||||
@ -182,8 +183,13 @@ describe('ProjectMapComponent', () => {
|
|||||||
let drawingsDataSource = new MockedDrawingsDataSource();
|
let drawingsDataSource = new MockedDrawingsDataSource();
|
||||||
let nodesDataSource = new MockedNodesDataSource();
|
let nodesDataSource = new MockedNodesDataSource();
|
||||||
let linksDataSource = new MockedLinksDataSource();
|
let linksDataSource = new MockedLinksDataSource();
|
||||||
|
let nodeCreatedLabelStylesFixer;
|
||||||
|
|
||||||
beforeEach(async(() => {
|
beforeEach(async(() => {
|
||||||
|
nodeCreatedLabelStylesFixer = {
|
||||||
|
fix: (node) => node
|
||||||
|
};
|
||||||
|
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
imports: [MatIconModule, MatToolbarModule, MatMenuModule, MatCheckboxModule, CommonModule, NoopAnimationsModule],
|
imports: [MatIconModule, MatToolbarModule, MatMenuModule, MatCheckboxModule, CommonModule, NoopAnimationsModule],
|
||||||
providers: [
|
providers: [
|
||||||
@ -214,6 +220,7 @@ describe('ProjectMapComponent', () => {
|
|||||||
provide: RecentlyOpenedProjectService,
|
provide: RecentlyOpenedProjectService,
|
||||||
useClass: RecentlyOpenedProjectService
|
useClass: RecentlyOpenedProjectService
|
||||||
},
|
},
|
||||||
|
{ provide: NodeCreatedLabelStylesFixer, useValue: nodeCreatedLabelStylesFixer}
|
||||||
],
|
],
|
||||||
declarations: [ProjectMapComponent, D3MapComponent, ...ANGULAR_MAP_DECLARATIONS],
|
declarations: [ProjectMapComponent, D3MapComponent, ...ANGULAR_MAP_DECLARATIONS],
|
||||||
schemas: [NO_ERRORS_SCHEMA]
|
schemas: [NO_ERRORS_SCHEMA]
|
||||||
|
@ -279,6 +279,7 @@ export class ProjectMapComponent implements OnInit, OnDestroy {
|
|||||||
|
|
||||||
nodes.filter((node) => node.label.style === null).forEach((node) => {
|
nodes.filter((node) => node.label.style === null).forEach((node) => {
|
||||||
const fixedNode = this.nodeCreatedLabelStylesFixer.fix(node);
|
const fixedNode = this.nodeCreatedLabelStylesFixer.fix(node);
|
||||||
|
this.nodeService.updateLabel(this.server, node, fixedNode.label).subscribe();
|
||||||
});
|
});
|
||||||
|
|
||||||
this.nodesDataSource.set(nodes);
|
this.nodesDataSource.set(nodes);
|
||||||
|
Reference in New Issue
Block a user