mirror of
https://github.com/GNS3/gns3-web-ui.git
synced 2025-06-18 06:48:09 +00:00
DrawingsDataSource
This commit is contained in:
@ -53,12 +53,13 @@ import { ApplianceListDialogComponent } from './appliance/appliance-list-dialog/
|
|||||||
import { NodeSelectInterfaceComponent } from './shared/node-select-interface/node-select-interface.component';
|
import { NodeSelectInterfaceComponent } from './shared/node-select-interface/node-select-interface.component';
|
||||||
import { CartographyModule } from './cartography/cartography.module';
|
import { CartographyModule } from './cartography/cartography.module';
|
||||||
import { ToasterService } from './shared/services/toaster.service';
|
import { ToasterService } from './shared/services/toaster.service';
|
||||||
import {ProjectWebServiceHandler} from "./shared/handlers/project-web-service-handler";
|
import { ProjectWebServiceHandler } from "./shared/handlers/project-web-service-handler";
|
||||||
import {LinksDataSource} from "./cartography/shared/datasources/links-datasource";
|
import { LinksDataSource } from "./cartography/shared/datasources/links-datasource";
|
||||||
import {NodesDataSource} from "./cartography/shared/datasources/nodes-datasource";
|
import { NodesDataSource } from "./cartography/shared/datasources/nodes-datasource";
|
||||||
import {SymbolsDataSource} from "./cartography/shared/datasources/symbols-datasource";
|
import { SymbolsDataSource } from "./cartography/shared/datasources/symbols-datasource";
|
||||||
import {SelectionManager} from "./cartography/shared/managers/selection-manager";
|
import { SelectionManager } from "./cartography/shared/managers/selection-manager";
|
||||||
import {InRectangleHelper} from "./cartography/map/helpers/in-rectangle-helper";
|
import { InRectangleHelper } from "./cartography/map/helpers/in-rectangle-helper";
|
||||||
|
import { DrawingsDataSource } from "./cartography/shared/datasources/drawings-datasource";
|
||||||
|
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
@ -120,7 +121,8 @@ import {InRectangleHelper} from "./cartography/map/helpers/in-rectangle-helper";
|
|||||||
NodesDataSource,
|
NodesDataSource,
|
||||||
SymbolsDataSource,
|
SymbolsDataSource,
|
||||||
SelectionManager,
|
SelectionManager,
|
||||||
InRectangleHelper
|
InRectangleHelper,
|
||||||
|
DrawingsDataSource
|
||||||
],
|
],
|
||||||
entryComponents: [
|
entryComponents: [
|
||||||
AddServerDialogComponent,
|
AddServerDialogComponent,
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import {DataSource} from "./datasource";
|
import { DataSource } from "./datasource";
|
||||||
|
|
||||||
class Item {
|
class Item {
|
||||||
constructor(public id: string, public property1?: string, public property2?: string) {}
|
constructor(public id: string, public property1?: string, public property2?: string) {}
|
||||||
@ -12,7 +12,6 @@ class TestDataSource extends DataSource<Item> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
describe('TestDataSource', () => {
|
describe('TestDataSource', () => {
|
||||||
let dataSource: TestDataSource;
|
let dataSource: TestDataSource;
|
||||||
let data: Item[];
|
let data: Item[];
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import {BehaviorSubject} from "rxjs/BehaviorSubject";
|
import { BehaviorSubject } from "rxjs/BehaviorSubject";
|
||||||
|
|
||||||
export abstract class DataSource<T> {
|
export abstract class DataSource<T> {
|
||||||
protected data: T[] = [];
|
protected data: T[] = [];
|
||||||
|
@ -0,0 +1,33 @@
|
|||||||
|
import { DrawingsDataSource } from "./drawings-datasource";
|
||||||
|
import { Drawing } from "../models/drawing";
|
||||||
|
|
||||||
|
|
||||||
|
describe('DrawingsDataSource', () => {
|
||||||
|
let dataSource: DrawingsDataSource;
|
||||||
|
let data: Drawing[];
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
dataSource = new DrawingsDataSource();
|
||||||
|
dataSource.connect().subscribe((drawings: Drawing[]) => {
|
||||||
|
data = drawings;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Drawing can be updated', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
const drawing = new Drawing();
|
||||||
|
drawing.drawing_id = "1";
|
||||||
|
drawing.project_id = "project1";
|
||||||
|
dataSource.add(drawing);
|
||||||
|
|
||||||
|
drawing.project_id = "project2";
|
||||||
|
dataSource.update(drawing);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('project_id should change', () => {
|
||||||
|
expect(data[0].drawing_id).toEqual("1");
|
||||||
|
expect(data[0].project_id).toEqual("project2");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
@ -0,0 +1,12 @@
|
|||||||
|
import { Injectable } from "@angular/core";
|
||||||
|
|
||||||
|
import { Drawing } from "../models/drawing";
|
||||||
|
import { DataSource } from "./datasource";
|
||||||
|
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class DrawingsDataSource extends DataSource<Drawing> {
|
||||||
|
protected findIndex(drawing: Drawing) {
|
||||||
|
return this.data.findIndex((d: Drawing) => d.drawing_id === drawing.drawing_id);
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,5 @@
|
|||||||
import {LinksDataSource} from "./links-datasource";
|
import { LinksDataSource } from "./links-datasource";
|
||||||
import {Link} from "../models/link";
|
import { Link } from "../models/link";
|
||||||
|
|
||||||
|
|
||||||
describe('LinksDataSource', () => {
|
describe('LinksDataSource', () => {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import {Injectable} from "@angular/core";
|
import { Injectable } from "@angular/core";
|
||||||
|
|
||||||
import {DataSource} from "./datasource";
|
import { DataSource } from "./datasource";
|
||||||
import {Link} from "../models/link";
|
import { Link} from "../models/link";
|
||||||
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import {NodesDataSource} from "./nodes-datasource";
|
import { NodesDataSource } from "./nodes-datasource";
|
||||||
import {Node} from "../models/node";
|
import { Node } from "../models/node";
|
||||||
|
|
||||||
|
|
||||||
describe('NodesDataSource', () => {
|
describe('NodesDataSource', () => {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import {Node} from "../models/node";
|
import { Injectable } from "@angular/core";
|
||||||
import {DataSource} from "./datasource";
|
|
||||||
import {Injectable} from "@angular/core";
|
import { Node } from "../models/node";
|
||||||
|
import { DataSource } from "./datasource";
|
||||||
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import {SymbolsDataSource} from "./symbols-datasource";
|
import { SymbolsDataSource } from "./symbols-datasource";
|
||||||
import {Symbol} from "../models/symbol";
|
import { Symbol } from "../models/symbol";
|
||||||
|
|
||||||
|
|
||||||
describe('SymbolsDataSource', () => {
|
describe('SymbolsDataSource', () => {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import {Node} from "../models/node";
|
import { Injectable } from "@angular/core";
|
||||||
import {DataSource} from "./datasource";
|
|
||||||
import {Injectable} from "@angular/core";
|
import { DataSource } from "./datasource";
|
||||||
import {Symbol} from "../models/symbol";
|
import { Symbol } from "../models/symbol";
|
||||||
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
|
@ -101,7 +101,6 @@ export class LinksWidget implements Widget {
|
|||||||
const link = view
|
const link = view
|
||||||
.selectAll<SVGGElement, Link>("g.link")
|
.selectAll<SVGGElement, Link>("g.link")
|
||||||
.data((layer: Layer) => {
|
.data((layer: Layer) => {
|
||||||
console.log(layer.links);
|
|
||||||
if (layer.links) {
|
if (layer.links) {
|
||||||
const layer_links = layer.links.filter((l: Link) => {
|
const layer_links = layer.links.filter((l: Link) => {
|
||||||
return l.target && l.source;
|
return l.target && l.source;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import {Component, Inject, OnInit, ViewChild, ViewEncapsulation} from '@angular/core';
|
import {Component, Inject, OnInit, ViewChild, ViewEncapsulation } from '@angular/core';
|
||||||
import { ActivatedRoute, ParamMap } from '@angular/router';
|
import { ActivatedRoute, ParamMap } from '@angular/router';
|
||||||
|
|
||||||
import { Observable } from 'rxjs/Observable';
|
import { Observable } from 'rxjs/Observable';
|
||||||
@ -19,7 +19,7 @@ import { MapComponent } from "../cartography/map/map.component";
|
|||||||
import { ServerService } from "../shared/services/server.service";
|
import { ServerService } from "../shared/services/server.service";
|
||||||
import { ProjectService } from '../shared/services/project.service';
|
import { ProjectService } from '../shared/services/project.service';
|
||||||
import { Server } from "../shared/models/server";
|
import { Server } from "../shared/models/server";
|
||||||
import { MAT_DIALOG_DATA, MatDialog, MatDialogRef} from "@angular/material";
|
import { MAT_DIALOG_DATA, MatDialog, MatDialogRef } from "@angular/material";
|
||||||
import { SnapshotService } from "../shared/services/snapshot.service";
|
import { SnapshotService } from "../shared/services/snapshot.service";
|
||||||
import { Snapshot } from "../shared/models/snapshot";
|
import { Snapshot } from "../shared/models/snapshot";
|
||||||
import { ProgressDialogService } from "../shared/progress-dialog/progress-dialog.service";
|
import { ProgressDialogService } from "../shared/progress-dialog/progress-dialog.service";
|
||||||
@ -36,9 +36,9 @@ import { ToasterService } from '../shared/services/toaster.service';
|
|||||||
import { NodesDataSource } from "../cartography/shared/datasources/nodes-datasource";
|
import { NodesDataSource } from "../cartography/shared/datasources/nodes-datasource";
|
||||||
import { LinksDataSource } from "../cartography/shared/datasources/links-datasource";
|
import { LinksDataSource } from "../cartography/shared/datasources/links-datasource";
|
||||||
import { ProjectWebServiceHandler } from "../shared/handlers/project-web-service-handler";
|
import { ProjectWebServiceHandler } from "../shared/handlers/project-web-service-handler";
|
||||||
import { Rectangle } from "../cartography/shared/models/rectangle";
|
|
||||||
import { SelectionManager } from "../cartography/shared/managers/selection-manager";
|
import { SelectionManager } from "../cartography/shared/managers/selection-manager";
|
||||||
import { InRectangleHelper } from "../cartography/map/helpers/in-rectangle-helper";
|
import { InRectangleHelper } from "../cartography/map/helpers/in-rectangle-helper";
|
||||||
|
import { DrawingsDataSource } from "../cartography/shared/datasources/drawings-datasource";
|
||||||
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
@ -81,6 +81,7 @@ export class ProjectMapComponent implements OnInit {
|
|||||||
private projectWebServiceHandler: ProjectWebServiceHandler,
|
private projectWebServiceHandler: ProjectWebServiceHandler,
|
||||||
protected nodesDataSource: NodesDataSource,
|
protected nodesDataSource: NodesDataSource,
|
||||||
protected linksDataSource: LinksDataSource,
|
protected linksDataSource: LinksDataSource,
|
||||||
|
protected drawingsDataSource: DrawingsDataSource
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,6 +115,13 @@ export class ProjectMapComponent implements OnInit {
|
|||||||
this.symbols = symbols;
|
this.symbols = symbols;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.drawingsDataSource.connect().subscribe((drawings: Drawing[]) => {
|
||||||
|
this.drawings = drawings;
|
||||||
|
if (this.mapChild) {
|
||||||
|
this.mapChild.reload();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
this.nodesDataSource.connect().subscribe((nodes: Node[]) => {
|
this.nodesDataSource.connect().subscribe((nodes: Node[]) => {
|
||||||
this.nodes = nodes;
|
this.nodes = nodes;
|
||||||
if (this.mapChild) {
|
if (this.mapChild) {
|
||||||
@ -136,7 +144,7 @@ export class ProjectMapComponent implements OnInit {
|
|||||||
return this.projectService.drawings(this.server, project.project_id);
|
return this.projectService.drawings(this.server, project.project_id);
|
||||||
})
|
})
|
||||||
.flatMap((drawings: Drawing[]) => {
|
.flatMap((drawings: Drawing[]) => {
|
||||||
this.drawings = drawings;
|
this.drawingsDataSource.set(drawings);
|
||||||
return this.projectService.links(this.server, project.project_id);
|
return this.projectService.links(this.server, project.project_id);
|
||||||
})
|
})
|
||||||
.flatMap((links: Link[]) => {
|
.flatMap((links: Link[]) => {
|
||||||
|
Reference in New Issue
Block a user