mirror of
https://github.com/GNS3/gns3-web-ui.git
synced 2025-04-09 03:24:13 +00:00
Node as Element, Ref: 154
This commit is contained in:
parent
06269bf2a2
commit
cde77ab232
@ -51,11 +51,13 @@
|
||||
"npm-check-updates": "^2.14.1",
|
||||
"raven-js": "^3.24.1",
|
||||
"rxjs": "^6.2.1",
|
||||
"rxjs-compat": "^6.2.1",
|
||||
"typeface-roboto": "^0.0.54",
|
||||
"yargs": "^12.0.1",
|
||||
"zone.js": "^0.8.26"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@angular-devkit/build-angular": "~0.6.8",
|
||||
"@angular/cli": "^6.0.8",
|
||||
"@angular/compiler-cli": "^6.0.7",
|
||||
"@angular/language-service": "^6.0.7",
|
||||
@ -81,8 +83,7 @@
|
||||
"ts-mockito": "^2.3.0",
|
||||
"ts-node": "~7.0.0",
|
||||
"tslint": "~5.10.0",
|
||||
"typescript": "^2.9.2",
|
||||
"@angular-devkit/build-angular": "~0.6.8"
|
||||
"typescript": "^2.9.2"
|
||||
},
|
||||
"greenkeeper": {
|
||||
"ignore": [
|
||||
|
@ -9,18 +9,18 @@ describe('EllipseConverter', () => {
|
||||
});
|
||||
|
||||
it('should parse attributes', () => {
|
||||
const node = document.createElement("ellipse");
|
||||
node.setAttribute("fill", "#ffffff");
|
||||
node.setAttribute("fill-opacity", "1.0");
|
||||
node.setAttribute("stroke", "#000000");
|
||||
node.setAttribute("stroke-width", "2");
|
||||
node.setAttribute("stroke-dasharray", "5,25,25");
|
||||
node.setAttribute("cx", "63");
|
||||
node.setAttribute("cy", "59");
|
||||
node.setAttribute("rx", "63");
|
||||
node.setAttribute("ry", "59");
|
||||
const element = document.createElement("ellipse");
|
||||
element.setAttribute("fill", "#ffffff");
|
||||
element.setAttribute("fill-opacity", "1.0");
|
||||
element.setAttribute("stroke", "#000000");
|
||||
element.setAttribute("stroke-width", "2");
|
||||
element.setAttribute("stroke-dasharray", "5,25,25");
|
||||
element.setAttribute("cx", "63");
|
||||
element.setAttribute("cy", "59");
|
||||
element.setAttribute("rx", "63");
|
||||
element.setAttribute("ry", "59");
|
||||
|
||||
const drawing = ellipseConverter.convert(node);
|
||||
const drawing = ellipseConverter.convert(element);
|
||||
expect(drawing.fill).toEqual("#ffffff");
|
||||
expect(drawing.fill_opacity).toEqual(1.0);
|
||||
expect(drawing.stroke).toEqual("#000000");
|
||||
@ -33,9 +33,9 @@ describe('EllipseConverter', () => {
|
||||
});
|
||||
|
||||
it('should parse with no attributes', () => {
|
||||
const node = document.createElement("ellipse");
|
||||
const element = document.createElement("ellipse");
|
||||
|
||||
const drawing = ellipseConverter.convert(node);
|
||||
const drawing = ellipseConverter.convert(element);
|
||||
expect(drawing.fill).toBeUndefined();
|
||||
expect(drawing.fill_opacity).toBeUndefined();
|
||||
expect(drawing.stroke).toBeUndefined();
|
||||
|
@ -3,50 +3,50 @@ import { EllipseElement } from "../../models/drawings/ellipse-element";
|
||||
|
||||
|
||||
export class EllipseConverter implements SvgConverter {
|
||||
convert(node: Node): EllipseElement {
|
||||
convert(element: Element): EllipseElement {
|
||||
const drawing = new EllipseElement();
|
||||
|
||||
const fill = node.attributes.getNamedItem("fill");
|
||||
const fill = element.attributes.getNamedItem("fill");
|
||||
if (fill) {
|
||||
drawing.fill = fill.value;
|
||||
}
|
||||
|
||||
const fill_opacity = node.attributes.getNamedItem("fill-opacity");
|
||||
const fill_opacity = element.attributes.getNamedItem("fill-opacity");
|
||||
if (fill) {
|
||||
drawing.fill_opacity = parseFloat(fill_opacity.value);
|
||||
}
|
||||
|
||||
const stroke = node.attributes.getNamedItem("stroke");
|
||||
const stroke = element.attributes.getNamedItem("stroke");
|
||||
if (stroke) {
|
||||
drawing.stroke = stroke.value;
|
||||
}
|
||||
|
||||
const stroke_width = node.attributes.getNamedItem("stroke-width");
|
||||
const stroke_width = element.attributes.getNamedItem("stroke-width");
|
||||
if (stroke) {
|
||||
drawing.stroke_width = parseInt(stroke_width.value, 10);
|
||||
}
|
||||
|
||||
const stroke_dasharray = node.attributes.getNamedItem("stroke-dasharray");
|
||||
const stroke_dasharray = element.attributes.getNamedItem("stroke-dasharray");
|
||||
if (stroke_dasharray) {
|
||||
drawing.stroke_dasharray = stroke_dasharray.value;
|
||||
}
|
||||
|
||||
const cx = node.attributes.getNamedItem('cx');
|
||||
const cx = element.attributes.getNamedItem('cx');
|
||||
if (cx) {
|
||||
drawing.cx = parseInt(cx.value, 10);
|
||||
}
|
||||
|
||||
const cy = node.attributes.getNamedItem('cy');
|
||||
const cy = element.attributes.getNamedItem('cy');
|
||||
if (cy) {
|
||||
drawing.cy = parseInt(cy.value, 10);
|
||||
}
|
||||
|
||||
const rx = node.attributes.getNamedItem('rx');
|
||||
const rx = element.attributes.getNamedItem('rx');
|
||||
if (rx) {
|
||||
drawing.rx = parseInt(rx.value, 10);
|
||||
}
|
||||
|
||||
const ry = node.attributes.getNamedItem('ry');
|
||||
const ry = element.attributes.getNamedItem('ry');
|
||||
if (ry) {
|
||||
drawing.ry = parseInt(ry.value, 10);
|
||||
}
|
||||
|
@ -9,21 +9,21 @@ describe('ImageConverter', () => {
|
||||
});
|
||||
|
||||
it('should parse attributes', () => {
|
||||
const node = document.createElement("image");
|
||||
node.setAttribute("xlink:href", "data:image/png");
|
||||
node.setAttribute("width", "100px");
|
||||
node.setAttribute("height", "200px");
|
||||
const element = document.createElement("image");
|
||||
element.setAttribute("xlink:href", "data:image/png");
|
||||
element.setAttribute("width", "100px");
|
||||
element.setAttribute("height", "200px");
|
||||
|
||||
const drawing = imageConverter.convert(node);
|
||||
const drawing = imageConverter.convert(element);
|
||||
expect(drawing.data).toEqual("data:image/png");
|
||||
expect(drawing.width).toEqual(100);
|
||||
expect(drawing.height).toEqual(200);
|
||||
});
|
||||
|
||||
it('should parse with no attributes', () => {
|
||||
const node = document.createElement("image");
|
||||
const element = document.createElement("image");
|
||||
|
||||
const drawing = imageConverter.convert(node);
|
||||
const drawing = imageConverter.convert(element);
|
||||
expect(drawing.data).toBeUndefined();
|
||||
expect(drawing.width).toBeUndefined();
|
||||
expect(drawing.height).toBeUndefined();
|
||||
|
@ -3,20 +3,20 @@ import { ImageElement } from "../../models/drawings/image-element";
|
||||
|
||||
|
||||
export class ImageConverter implements SvgConverter {
|
||||
convert(node: Node): ImageElement {
|
||||
convert(element: Element): ImageElement {
|
||||
const drawing = new ImageElement();
|
||||
|
||||
const data = node.attributes.getNamedItem("xlink:href");
|
||||
const data = element.attributes.getNamedItem("xlink:href");
|
||||
if (data) {
|
||||
drawing.data = data.value;
|
||||
}
|
||||
|
||||
const width = node.attributes.getNamedItem('width');
|
||||
const width = element.attributes.getNamedItem('width');
|
||||
if (width) {
|
||||
drawing.width = parseInt(width.value, 10);
|
||||
}
|
||||
|
||||
const height = node.attributes.getNamedItem('height');
|
||||
const height = element.attributes.getNamedItem('height');
|
||||
if (height) {
|
||||
drawing.height = parseInt(height.value, 10);
|
||||
}
|
||||
|
@ -9,16 +9,16 @@ describe('LineConverter', () => {
|
||||
});
|
||||
|
||||
it('should parse attributes', () => {
|
||||
const node = document.createElement("line");
|
||||
node.setAttribute("stroke", "#000000");
|
||||
node.setAttribute("stroke-width", "2");
|
||||
node.setAttribute("stroke-dasharray", "5,25,25");
|
||||
node.setAttribute("x1", "10.10");
|
||||
node.setAttribute("x2", "20");
|
||||
node.setAttribute("y1", "30");
|
||||
node.setAttribute("y2", "40");
|
||||
const element = document.createElement("line");
|
||||
element.setAttribute("stroke", "#000000");
|
||||
element.setAttribute("stroke-width", "2");
|
||||
element.setAttribute("stroke-dasharray", "5,25,25");
|
||||
element.setAttribute("x1", "10.10");
|
||||
element.setAttribute("x2", "20");
|
||||
element.setAttribute("y1", "30");
|
||||
element.setAttribute("y2", "40");
|
||||
|
||||
const drawing = lineConverter.convert(node);
|
||||
const drawing = lineConverter.convert(element);
|
||||
expect(drawing.stroke).toEqual("#000000");
|
||||
expect(drawing.stroke_width).toEqual(2.0);
|
||||
expect(drawing.stroke_dasharray).toEqual("5,25,25");
|
||||
@ -29,9 +29,9 @@ describe('LineConverter', () => {
|
||||
});
|
||||
|
||||
it('should parse with no attributes', () => {
|
||||
const node = document.createElement("line");
|
||||
const element = document.createElement("line");
|
||||
|
||||
const drawing = lineConverter.convert(node);
|
||||
const drawing = lineConverter.convert(element);
|
||||
expect(drawing.stroke).toBeUndefined();
|
||||
expect(drawing.stroke_width).toBeUndefined();
|
||||
expect(drawing.stroke_dasharray).toBeUndefined();
|
||||
|
@ -3,40 +3,40 @@ import { LineElement } from "../../models/drawings/line-element";
|
||||
|
||||
|
||||
export class LineConverter implements SvgConverter {
|
||||
convert(node: Node): LineElement {
|
||||
convert(element: Element): LineElement {
|
||||
const drawing = new LineElement();
|
||||
|
||||
const stroke = node.attributes.getNamedItem("stroke");
|
||||
const stroke = element.attributes.getNamedItem("stroke");
|
||||
if (stroke) {
|
||||
drawing.stroke = stroke.value;
|
||||
}
|
||||
|
||||
const stroke_width = node.attributes.getNamedItem("stroke-width");
|
||||
const stroke_width = element.attributes.getNamedItem("stroke-width");
|
||||
if (stroke) {
|
||||
drawing.stroke_width = parseInt(stroke_width.value, 10);
|
||||
}
|
||||
|
||||
const stroke_dasharray = node.attributes.getNamedItem("stroke-dasharray");
|
||||
const stroke_dasharray = element.attributes.getNamedItem("stroke-dasharray");
|
||||
if (stroke_dasharray) {
|
||||
drawing.stroke_dasharray = stroke_dasharray.value;
|
||||
}
|
||||
|
||||
const x1 = node.attributes.getNamedItem('x1');
|
||||
const x1 = element.attributes.getNamedItem('x1');
|
||||
if (x1) {
|
||||
drawing.x1 = parseInt(x1.value, 10);
|
||||
}
|
||||
|
||||
const x2 = node.attributes.getNamedItem('x2');
|
||||
const x2 = element.attributes.getNamedItem('x2');
|
||||
if (x2) {
|
||||
drawing.x2 = parseInt(x2.value, 10);
|
||||
}
|
||||
|
||||
const y1 = node.attributes.getNamedItem('y1');
|
||||
const y1 = element.attributes.getNamedItem('y1');
|
||||
if (y1) {
|
||||
drawing.y1 = parseInt(y1.value, 10);
|
||||
}
|
||||
|
||||
const y2 = node.attributes.getNamedItem('y2');
|
||||
const y2 = element.attributes.getNamedItem('y2');
|
||||
if (y2) {
|
||||
drawing.y2 = parseInt(y2.value, 10);
|
||||
}
|
||||
|
@ -9,17 +9,17 @@ describe('RectConverter', () => {
|
||||
});
|
||||
|
||||
it('should parse attributes', () => {
|
||||
const node = document.createElement("rect");
|
||||
node.setAttribute("fill", "#ffffff");
|
||||
node.setAttribute("fill-opacity", "0.7");
|
||||
node.setAttribute("stroke", "#000000");
|
||||
node.setAttribute("stroke-width", "2");
|
||||
node.setAttribute("stroke-dasharray", "5,25,25");
|
||||
const element = document.createElement("rect");
|
||||
element.setAttribute("fill", "#ffffff");
|
||||
element.setAttribute("fill-opacity", "0.7");
|
||||
element.setAttribute("stroke", "#000000");
|
||||
element.setAttribute("stroke-width", "2");
|
||||
element.setAttribute("stroke-dasharray", "5,25,25");
|
||||
|
||||
node.setAttribute("width", "100px");
|
||||
node.setAttribute("height", "200px");
|
||||
element.setAttribute("width", "100px");
|
||||
element.setAttribute("height", "200px");
|
||||
|
||||
const drawing = rectConverter.convert(node);
|
||||
const drawing = rectConverter.convert(element);
|
||||
expect(drawing.fill).toEqual("#ffffff");
|
||||
expect(drawing.fill_opacity).toEqual(0.7);
|
||||
expect(drawing.stroke).toEqual("#000000");
|
||||
@ -29,9 +29,9 @@ describe('RectConverter', () => {
|
||||
});
|
||||
|
||||
it('should parse with no attributes', () => {
|
||||
const node = document.createElement("rect");
|
||||
const element = document.createElement("rect");
|
||||
|
||||
const drawing = rectConverter.convert(node);
|
||||
const drawing = rectConverter.convert(element);
|
||||
expect(drawing.fill).toBeUndefined();
|
||||
expect(drawing.fill_opacity).toBeUndefined();
|
||||
expect(drawing.stroke).toBeUndefined();
|
||||
|
@ -3,40 +3,40 @@ import { RectElement } from "../../models/drawings/rect-element";
|
||||
|
||||
|
||||
export class RectConverter implements SvgConverter {
|
||||
convert(node: Node): RectElement {
|
||||
convert(element: Element): RectElement {
|
||||
const drawing = new RectElement();
|
||||
|
||||
const fill = node.attributes.getNamedItem("fill");
|
||||
const fill = element.attributes.getNamedItem("fill");
|
||||
if (fill) {
|
||||
drawing.fill = fill.value;
|
||||
}
|
||||
|
||||
const fill_opacity = node.attributes.getNamedItem("fill-opacity");
|
||||
const fill_opacity = element.attributes.getNamedItem("fill-opacity");
|
||||
if (fill) {
|
||||
drawing.fill_opacity = parseFloat(fill_opacity.value);
|
||||
}
|
||||
|
||||
const stroke = node.attributes.getNamedItem("stroke");
|
||||
const stroke = element.attributes.getNamedItem("stroke");
|
||||
if (stroke) {
|
||||
drawing.stroke = stroke.value;
|
||||
}
|
||||
|
||||
const stroke_width = node.attributes.getNamedItem("stroke-width");
|
||||
const stroke_width = element.attributes.getNamedItem("stroke-width");
|
||||
if (stroke) {
|
||||
drawing.stroke_width = parseInt(stroke_width.value, 10);
|
||||
}
|
||||
|
||||
const stroke_dasharray = node.attributes.getNamedItem("stroke-dasharray");
|
||||
const stroke_dasharray = element.attributes.getNamedItem("stroke-dasharray");
|
||||
if (stroke_dasharray) {
|
||||
drawing.stroke_dasharray = stroke_dasharray.value;
|
||||
}
|
||||
|
||||
const width = node.attributes.getNamedItem('width');
|
||||
const width = element.attributes.getNamedItem('width');
|
||||
if (width) {
|
||||
drawing.width = parseInt(width.value, 10);
|
||||
}
|
||||
|
||||
const height = node.attributes.getNamedItem('height');
|
||||
const height = element.attributes.getNamedItem('height');
|
||||
if (height) {
|
||||
drawing.height = parseInt(height.value, 10);
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { DrawingElement } from "../../models/drawings/drawing-element";
|
||||
|
||||
export interface SvgConverter {
|
||||
convert(node: Node): DrawingElement;
|
||||
convert(element: Element): DrawingElement;
|
||||
}
|
||||
|
@ -9,16 +9,16 @@ describe('TextConverter', () => {
|
||||
});
|
||||
|
||||
it('should parse attributes', () => {
|
||||
const node = document.createElement("text");
|
||||
node.innerText = "Text";
|
||||
node.setAttribute("fill", "#00000");
|
||||
node.setAttribute("fill-opacity", "1.0");
|
||||
node.setAttribute("font-family", "TypeWriter");
|
||||
node.setAttribute("font-size", "10.0");
|
||||
node.setAttribute("font-weight", "bold");
|
||||
node.setAttribute("text-decoration", "line-through");
|
||||
const element = document.createElement("text");
|
||||
element.innerText = "Text";
|
||||
element.setAttribute("fill", "#00000");
|
||||
element.setAttribute("fill-opacity", "1.0");
|
||||
element.setAttribute("font-family", "TypeWriter");
|
||||
element.setAttribute("font-size", "10.0");
|
||||
element.setAttribute("font-weight", "bold");
|
||||
element.setAttribute("text-decoration", "line-through");
|
||||
|
||||
const drawing = textConverter.convert(node);
|
||||
const drawing = textConverter.convert(element);
|
||||
expect(drawing.text).toEqual("Text");
|
||||
expect(drawing.fill).toEqual("#00000");
|
||||
expect(drawing.fill_opacity).toEqual(1.0);
|
||||
@ -29,9 +29,9 @@ describe('TextConverter', () => {
|
||||
});
|
||||
|
||||
it('should parse with no attributes', () => {
|
||||
const node = document.createElement("text");
|
||||
const element = document.createElement("text");
|
||||
|
||||
const drawing = textConverter.convert(node);
|
||||
const drawing = textConverter.convert(element);
|
||||
expect(drawing.text).toEqual("");
|
||||
expect(drawing.fill).toBeUndefined();
|
||||
expect(drawing.fill_opacity).toBeUndefined();
|
||||
|
@ -3,37 +3,37 @@ import { TextElement } from "../../models/drawings/text-element";
|
||||
|
||||
|
||||
export class TextConverter implements SvgConverter {
|
||||
convert(node: Node): TextElement {
|
||||
convert(element: Element): TextElement {
|
||||
const drawing = new TextElement();
|
||||
|
||||
drawing.text = node.textContent;
|
||||
drawing.text = element.textContent;
|
||||
|
||||
const fill = node.attributes.getNamedItem('fill');
|
||||
const fill = element.attributes.getNamedItem('fill');
|
||||
if (fill) {
|
||||
drawing.fill = fill.value;
|
||||
}
|
||||
|
||||
const fill_opacity = node.attributes.getNamedItem('fill-opacity');
|
||||
const fill_opacity = element.attributes.getNamedItem('fill-opacity');
|
||||
if (fill_opacity) {
|
||||
drawing.fill_opacity = parseFloat(fill_opacity.value);
|
||||
}
|
||||
|
||||
const font_family = node.attributes.getNamedItem('font-family');
|
||||
const font_family = element.attributes.getNamedItem('font-family');
|
||||
if (font_family) {
|
||||
drawing.font_family = font_family.value;
|
||||
}
|
||||
|
||||
const font_size = node.attributes.getNamedItem('font-size');
|
||||
const font_size = element.attributes.getNamedItem('font-size');
|
||||
if (font_size) {
|
||||
drawing.font_size = +font_size.value;
|
||||
}
|
||||
|
||||
const font_weight = node.attributes.getNamedItem('font-weight');
|
||||
const font_weight = element.attributes.getNamedItem('font-weight');
|
||||
if (font_weight) {
|
||||
drawing.font_weight = font_weight.value;
|
||||
}
|
||||
|
||||
const text_decoration = node.attributes.getNamedItem('text-decoration');
|
||||
const text_decoration = element.attributes.getNamedItem('text-decoration');
|
||||
if (text_decoration) {
|
||||
drawing.text_decoration = text_decoration.value;
|
||||
}
|
||||
|
@ -80,10 +80,10 @@ describe('InterfaceLabelsWidget', () => {
|
||||
|
||||
expect(drew.nodes().length).toEqual(2);
|
||||
|
||||
const sourceInterface = drew.nodes()[0];
|
||||
const sourceInterface = drew.nodes()[0] as Element;
|
||||
|
||||
expect(sourceInterface.getAttribute('transform')).toEqual('translate(110, 220) rotate(5, 110, 220)');
|
||||
const sourceIntefaceRect = sourceInterface.firstChild;
|
||||
const sourceIntefaceRect = sourceInterface.firstChild as Element;
|
||||
expect(sourceIntefaceRect.attributes.getNamedItem('class').value).toEqual('interface_label_border');
|
||||
const sourceIntefaceText = sourceInterface.children[1];
|
||||
expect(sourceIntefaceText.attributes.getNamedItem('class').value).toEqual('interface_label noselect');
|
||||
@ -92,9 +92,9 @@ describe('InterfaceLabelsWidget', () => {
|
||||
const targetInterface = drew.nodes()[1];
|
||||
|
||||
expect(targetInterface.getAttribute('transform')).toEqual('translate(270, 360) rotate(0, 270, 360)');
|
||||
const targetIntefaceRect = targetInterface.firstChild;
|
||||
const targetIntefaceRect = targetInterface.firstChild as Element;
|
||||
expect(targetIntefaceRect.attributes.getNamedItem('class').value).toEqual('interface_label_border');
|
||||
const targetIntefaceText = targetInterface.children[1];
|
||||
const targetIntefaceText = targetInterface.children[1] as Element;
|
||||
expect(targetIntefaceText.attributes.getNamedItem('class').value).toEqual('interface_label noselect');
|
||||
expect(targetIntefaceText.attributes.getNamedItem('style').value).toEqual('');
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user