mirror of
https://github.com/GNS3/gns3-web-ui.git
synced 2025-01-03 19:44:12 +00:00
Support of 2.2 symbols API, Fixes: #218
This commit is contained in:
parent
e389e12181
commit
8ee33a0c07
@ -18,6 +18,7 @@ import { Drawing } from '../../models/drawing';
|
|||||||
import { Symbol } from '../../../models/symbol';
|
import { Symbol } from '../../../models/symbol';
|
||||||
import { GraphDataManager } from '../../managers/graph-data-manager';
|
import { GraphDataManager } from '../../managers/graph-data-manager';
|
||||||
import { MapSettingsManager } from '../../managers/map-settings-manager';
|
import { MapSettingsManager } from '../../managers/map-settings-manager';
|
||||||
|
import { Server } from '../../../models/server';
|
||||||
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
@ -30,6 +31,7 @@ export class D3MapComponent implements OnInit, OnChanges, OnDestroy {
|
|||||||
@Input() links: Link[] = [];
|
@Input() links: Link[] = [];
|
||||||
@Input() drawings: Drawing[] = [];
|
@Input() drawings: Drawing[] = [];
|
||||||
@Input() symbols: Symbol[] = [];
|
@Input() symbols: Symbol[] = [];
|
||||||
|
@Input() server: Server;
|
||||||
|
|
||||||
@Input() width = 1500;
|
@Input() width = 1500;
|
||||||
@Input() height = 600;
|
@Input() height = 600;
|
||||||
|
@ -5,9 +5,6 @@ import { MapNode } from "../../models/map/map-node";
|
|||||||
import { MapLabelToLabelConverter } from "./map-label-to-label-converter";
|
import { MapLabelToLabelConverter } from "./map-label-to-label-converter";
|
||||||
import { MapPortToPortConverter } from "./map-port-to-port-converter";
|
import { MapPortToPortConverter } from "./map-port-to-port-converter";
|
||||||
import { Node } from "../../models/node";
|
import { Node } from "../../models/node";
|
||||||
import { FontBBoxCalculator } from '../../helpers/font-bbox-calculator';
|
|
||||||
import { CssFixer } from '../../helpers/css-fixer';
|
|
||||||
import { FontFixer } from '../../helpers/font-fixer';
|
|
||||||
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
@ -36,6 +33,7 @@ export class MapNodeToNodeConverter implements Converter<MapNode, Node> {
|
|||||||
node.project_id = mapNode.projectId;
|
node.project_id = mapNode.projectId;
|
||||||
node.status = mapNode.status;
|
node.status = mapNode.status;
|
||||||
node.symbol = mapNode.symbol;
|
node.symbol = mapNode.symbol;
|
||||||
|
node.symbol_url = mapNode.symbolUrl;
|
||||||
node.width = mapNode.width;
|
node.width = mapNode.width;
|
||||||
node.x = mapNode.x;
|
node.x = mapNode.x;
|
||||||
node.y = mapNode.y;
|
node.y = mapNode.y;
|
||||||
|
@ -39,6 +39,7 @@ export class NodeToMapNodeConverter implements Converter<Node, MapNode> {
|
|||||||
mapNode.projectId = node.project_id;
|
mapNode.projectId = node.project_id;
|
||||||
mapNode.status = node.status;
|
mapNode.status = node.status;
|
||||||
mapNode.symbol = node.symbol;
|
mapNode.symbol = node.symbol;
|
||||||
|
mapNode.symbolUrl = node.symbol_url;
|
||||||
mapNode.width = node.width;
|
mapNode.width = node.width;
|
||||||
mapNode.x = node.x;
|
mapNode.x = node.x;
|
||||||
mapNode.y = node.y;
|
mapNode.y = node.y;
|
||||||
|
@ -21,6 +21,7 @@ export class MapNode implements Indexed {
|
|||||||
projectId: string;
|
projectId: string;
|
||||||
status: string;
|
status: string;
|
||||||
symbol: string;
|
symbol: string;
|
||||||
|
symbolUrl: string;
|
||||||
width: number;
|
width: number;
|
||||||
x: number;
|
x: number;
|
||||||
y: number;
|
y: number;
|
||||||
|
@ -21,6 +21,7 @@ export class Node {
|
|||||||
project_id: string;
|
project_id: string;
|
||||||
status: string;
|
status: string;
|
||||||
symbol: string;
|
symbol: string;
|
||||||
|
symbol_url: string; // @TODO: full URL to symbol, move to MapNode once converters are moved to app module
|
||||||
width: number;
|
width: number;
|
||||||
x: number;
|
x: number;
|
||||||
y: number;
|
y: number;
|
||||||
|
@ -4,7 +4,6 @@ import { Widget } from "./widget";
|
|||||||
import { SVGSelection } from "../models/types";
|
import { SVGSelection } from "../models/types";
|
||||||
import { NodeContextMenu, NodeClicked } from "../events/nodes";
|
import { NodeContextMenu, NodeClicked } from "../events/nodes";
|
||||||
import { select, event } from "d3-selection";
|
import { select, event } from "d3-selection";
|
||||||
import { MapSymbol } from "../models/map/map-symbol";
|
|
||||||
import { MapNode } from "../models/map/map-node";
|
import { MapNode } from "../models/map/map-node";
|
||||||
import { GraphDataManager } from "../managers/graph-data-manager";
|
import { GraphDataManager } from "../managers/graph-data-manager";
|
||||||
import { SelectionManager } from "../managers/selection-manager";
|
import { SelectionManager } from "../managers/selection-manager";
|
||||||
@ -47,20 +46,12 @@ export class NodeWidget implements Widget {
|
|||||||
})
|
})
|
||||||
.on('click', (node: MapNode) => {
|
.on('click', (node: MapNode) => {
|
||||||
this.nodesEventSource.clicked.emit(new ClickedDataEvent<MapNode>(node, event.clientX, event.clientY))
|
this.nodesEventSource.clicked.emit(new ClickedDataEvent<MapNode>(node, event.clientX, event.clientY))
|
||||||
// this.onNodeClicked.emit(new NodeClicked(event, n));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// update image of node
|
// update image of node
|
||||||
node_body_merge
|
node_body_merge
|
||||||
.select<SVGImageElement>('image')
|
.select<SVGImageElement>('image')
|
||||||
.attr('xnode:href', (n: MapNode) => {
|
.attr('xnode:href', (n: MapNode) => n.symbolUrl)
|
||||||
const symbol = this.graphDataManager.getSymbols().find((s: MapSymbol) => s.id === n.symbol);
|
|
||||||
if (symbol) {
|
|
||||||
return 'data:image/svg+xml;base64,' + btoa(symbol.raw);
|
|
||||||
}
|
|
||||||
// @todo; we need to have default image
|
|
||||||
return 'data:image/svg+xml;base64,none';
|
|
||||||
})
|
|
||||||
.attr('width', (n: MapNode) => n.width)
|
.attr('width', (n: MapNode) => n.width)
|
||||||
.attr('height', (n: MapNode) => n.height)
|
.attr('height', (n: MapNode) => n.height)
|
||||||
.attr('x', (n: MapNode) => 0)
|
.attr('x', (n: MapNode) => 0)
|
||||||
|
@ -7,7 +7,6 @@ import { map, mergeMap } from "rxjs/operators";
|
|||||||
|
|
||||||
import { Project } from '../../models/project';
|
import { Project } from '../../models/project';
|
||||||
import { Node } from '../../cartography/models/node';
|
import { Node } from '../../cartography/models/node';
|
||||||
import { SymbolService } from '../../services/symbol.service';
|
|
||||||
import { Link } from "../../models/link";
|
import { Link } from "../../models/link";
|
||||||
import { ServerService } from "../../services/server.service";
|
import { ServerService } from "../../services/server.service";
|
||||||
import { ProjectService } from '../../services/project.service';
|
import { ProjectService } from '../../services/project.service';
|
||||||
@ -53,8 +52,7 @@ export class ProjectMapComponent implements OnInit, OnDestroy {
|
|||||||
public links: Link[] = [];
|
public links: Link[] = [];
|
||||||
public drawings: Drawing[] = [];
|
public drawings: Drawing[] = [];
|
||||||
public symbols: Symbol[] = [];
|
public symbols: Symbol[] = [];
|
||||||
|
public project: Project;
|
||||||
project: Project;
|
|
||||||
public server: Server;
|
public server: Server;
|
||||||
|
|
||||||
private ws: Subject<any>;
|
private ws: Subject<any>;
|
||||||
@ -64,6 +62,7 @@ export class ProjectMapComponent implements OnInit, OnDestroy {
|
|||||||
'moving': false,
|
'moving': false,
|
||||||
'draw_link': false
|
'draw_link': false
|
||||||
};
|
};
|
||||||
|
|
||||||
protected settings: Settings;
|
protected settings: Settings;
|
||||||
|
|
||||||
private inReadOnlyMode = false;
|
private inReadOnlyMode = false;
|
||||||
@ -71,11 +70,11 @@ export class ProjectMapComponent implements OnInit, OnDestroy {
|
|||||||
@ViewChild(NodeContextMenuComponent) nodeContextMenu: NodeContextMenuComponent;
|
@ViewChild(NodeContextMenuComponent) nodeContextMenu: NodeContextMenuComponent;
|
||||||
|
|
||||||
private subscriptions: Subscription[] = [];
|
private subscriptions: Subscription[] = [];
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private route: ActivatedRoute,
|
private route: ActivatedRoute,
|
||||||
private serverService: ServerService,
|
private serverService: ServerService,
|
||||||
private projectService: ProjectService,
|
private projectService: ProjectService,
|
||||||
private symbolService: SymbolService,
|
|
||||||
private nodeService: NodeService,
|
private nodeService: NodeService,
|
||||||
private linkService: LinkService,
|
private linkService: LinkService,
|
||||||
private drawingService: DrawingService,
|
private drawingService: DrawingService,
|
||||||
@ -133,12 +132,6 @@ export class ProjectMapComponent implements OnInit, OnDestroy {
|
|||||||
|
|
||||||
this.subscriptions.push(routeSub);
|
this.subscriptions.push(routeSub);
|
||||||
|
|
||||||
this.subscriptions.push(
|
|
||||||
this.symbolService.symbols.subscribe((symbols: Symbol[]) => {
|
|
||||||
this.symbols = symbols;
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
this.subscriptions.push(
|
this.subscriptions.push(
|
||||||
this.drawingsDataSource.changes.subscribe((drawings: Drawing[]) => {
|
this.drawingsDataSource.changes.subscribe((drawings: Drawing[]) => {
|
||||||
this.drawings = drawings;
|
this.drawings = drawings;
|
||||||
@ -148,6 +141,10 @@ export class ProjectMapComponent implements OnInit, OnDestroy {
|
|||||||
|
|
||||||
this.subscriptions.push(
|
this.subscriptions.push(
|
||||||
this.nodesDataSource.changes.subscribe((nodes: Node[]) => {
|
this.nodesDataSource.changes.subscribe((nodes: Node[]) => {
|
||||||
|
nodes.forEach((node: Node) => {
|
||||||
|
node.symbol_url = `http://${this.server.ip}:${this.server.port}/v2/symbols/${node.symbol}/raw`;
|
||||||
|
});
|
||||||
|
|
||||||
this.nodes = nodes;
|
this.nodes = nodes;
|
||||||
this.mapChangeDetectorRef.detectChanges();
|
this.mapChangeDetectorRef.detectChanges();
|
||||||
})
|
})
|
||||||
@ -184,12 +181,9 @@ export class ProjectMapComponent implements OnInit, OnDestroy {
|
|||||||
onProjectLoad(project: Project) {
|
onProjectLoad(project: Project) {
|
||||||
this.readonly = this.projectService.isReadOnly(project);
|
this.readonly = this.projectService.isReadOnly(project);
|
||||||
|
|
||||||
const subscription = this.symbolService
|
const subscription = this.projectService
|
||||||
.load(this.server)
|
.nodes(this.server, project.project_id)
|
||||||
.pipe(
|
.pipe(
|
||||||
mergeMap(() => {
|
|
||||||
return this.projectService.nodes(this.server, project.project_id);
|
|
||||||
}),
|
|
||||||
mergeMap((nodes: Node[]) => {
|
mergeMap((nodes: Node[]) => {
|
||||||
this.nodesDataSource.set(nodes);
|
this.nodesDataSource.set(nodes);
|
||||||
return this.projectService.links(this.server, project.project_id);
|
return this.projectService.links(this.server, project.project_id);
|
||||||
|
@ -7,3 +7,5 @@
|
|||||||
<button mat-button (click)="accept(discoveredServer)">YES</button>
|
<button mat-button (click)="accept(discoveredServer)">YES</button>
|
||||||
</mat-card-actions>
|
</mat-card-actions>
|
||||||
</mat-card>
|
</mat-card>
|
||||||
|
|
||||||
|
<mat-divider *ngIf="discoveredServer"></mat-divider>
|
@ -1,5 +1,5 @@
|
|||||||
import {async, ComponentFixture, fakeAsync, TestBed, tick} from '@angular/core/testing';
|
import {async, ComponentFixture, fakeAsync, TestBed, tick} from '@angular/core/testing';
|
||||||
import { MatCardModule } from "@angular/material";
|
import { MatCardModule, MatDividerModule } from "@angular/material";
|
||||||
|
|
||||||
import { Observable } from "rxjs/Rx";
|
import { Observable } from "rxjs/Rx";
|
||||||
|
|
||||||
@ -23,7 +23,7 @@ describe('ServerDiscoveryComponent', () => {
|
|||||||
mockedServerService = new MockedServerService();
|
mockedServerService = new MockedServerService();
|
||||||
mockedVersionService = new MockedVersionService();
|
mockedVersionService = new MockedVersionService();
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
imports: [ MatCardModule ],
|
imports: [ MatCardModule, MatDividerModule ],
|
||||||
providers: [
|
providers: [
|
||||||
{ provide: VersionService, useFactory: () => mockedVersionService },
|
{ provide: VersionService, useFactory: () => mockedVersionService },
|
||||||
{ provide: ServerService, useFactory: () => mockedServerService },
|
{ provide: ServerService, useFactory: () => mockedServerService },
|
||||||
|
@ -5,8 +5,6 @@
|
|||||||
<div class="default-content">
|
<div class="default-content">
|
||||||
<app-server-discovery></app-server-discovery>
|
<app-server-discovery></app-server-discovery>
|
||||||
|
|
||||||
<mat-divider></mat-divider>
|
|
||||||
|
|
||||||
<div class="example-container mat-elevation-z8">
|
<div class="example-container mat-elevation-z8">
|
||||||
<mat-table #table [dataSource]="dataSource">
|
<mat-table #table [dataSource]="dataSource">
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import { Component, Inject, OnInit, Injectable } from '@angular/core';
|
import { Component, Inject, OnInit } from '@angular/core';
|
||||||
import { DataSource } from "@angular/cdk/collections";
|
import { DataSource } from "@angular/cdk/collections";
|
||||||
import { MatDialog, MatDialogRef, MAT_DIALOG_DATA } from '@angular/material';
|
import { MatDialog, MatDialogRef, MAT_DIALOG_DATA } from '@angular/material';
|
||||||
|
|
||||||
import { Observable, BehaviorSubject, merge } from "rxjs";
|
import { Observable, merge } from "rxjs";
|
||||||
import { map } from "rxjs/operators";
|
import { map } from "rxjs/operators";
|
||||||
|
|
||||||
import { Server } from "../../models/server";
|
import { Server } from "../../models/server";
|
||||||
|
Loading…
Reference in New Issue
Block a user