mirror of
https://github.com/GNS3/gns3-web-ui.git
synced 2025-04-14 05:36:35 +00:00
DrawingsDataSource
This commit is contained in:
parent
1dc911fc92
commit
3d42d46987
@ -53,12 +53,13 @@ import { ApplianceListDialogComponent } from './appliance/appliance-list-dialog/
|
||||
import { NodeSelectInterfaceComponent } from './shared/node-select-interface/node-select-interface.component';
|
||||
import { CartographyModule } from './cartography/cartography.module';
|
||||
import { ToasterService } from './shared/services/toaster.service';
|
||||
import {ProjectWebServiceHandler} from "./shared/handlers/project-web-service-handler";
|
||||
import {LinksDataSource} from "./cartography/shared/datasources/links-datasource";
|
||||
import {NodesDataSource} from "./cartography/shared/datasources/nodes-datasource";
|
||||
import {SymbolsDataSource} from "./cartography/shared/datasources/symbols-datasource";
|
||||
import {SelectionManager} from "./cartography/shared/managers/selection-manager";
|
||||
import {InRectangleHelper} from "./cartography/map/helpers/in-rectangle-helper";
|
||||
import { ProjectWebServiceHandler } from "./shared/handlers/project-web-service-handler";
|
||||
import { LinksDataSource } from "./cartography/shared/datasources/links-datasource";
|
||||
import { NodesDataSource } from "./cartography/shared/datasources/nodes-datasource";
|
||||
import { SymbolsDataSource } from "./cartography/shared/datasources/symbols-datasource";
|
||||
import { SelectionManager } from "./cartography/shared/managers/selection-manager";
|
||||
import { InRectangleHelper } from "./cartography/map/helpers/in-rectangle-helper";
|
||||
import { DrawingsDataSource } from "./cartography/shared/datasources/drawings-datasource";
|
||||
|
||||
|
||||
@NgModule({
|
||||
@ -120,7 +121,8 @@ import {InRectangleHelper} from "./cartography/map/helpers/in-rectangle-helper";
|
||||
NodesDataSource,
|
||||
SymbolsDataSource,
|
||||
SelectionManager,
|
||||
InRectangleHelper
|
||||
InRectangleHelper,
|
||||
DrawingsDataSource
|
||||
],
|
||||
entryComponents: [
|
||||
AddServerDialogComponent,
|
||||
|
@ -1,4 +1,4 @@
|
||||
import {DataSource} from "./datasource";
|
||||
import { DataSource } from "./datasource";
|
||||
|
||||
class Item {
|
||||
constructor(public id: string, public property1?: string, public property2?: string) {}
|
||||
@ -12,7 +12,6 @@ class TestDataSource extends DataSource<Item> {
|
||||
};
|
||||
|
||||
|
||||
|
||||
describe('TestDataSource', () => {
|
||||
let dataSource: TestDataSource;
|
||||
let data: Item[];
|
||||
|
@ -1,4 +1,4 @@
|
||||
import {BehaviorSubject} from "rxjs/BehaviorSubject";
|
||||
import { BehaviorSubject } from "rxjs/BehaviorSubject";
|
||||
|
||||
export abstract class DataSource<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 {Link} from "../models/link";
|
||||
import { LinksDataSource } from "./links-datasource";
|
||||
import { Link } from "../models/link";
|
||||
|
||||
|
||||
describe('LinksDataSource', () => {
|
||||
|
@ -1,7 +1,7 @@
|
||||
import {Injectable} from "@angular/core";
|
||||
import { Injectable } from "@angular/core";
|
||||
|
||||
import {DataSource} from "./datasource";
|
||||
import {Link} from "../models/link";
|
||||
import { DataSource } from "./datasource";
|
||||
import { Link} from "../models/link";
|
||||
|
||||
|
||||
@Injectable()
|
||||
|
@ -1,5 +1,5 @@
|
||||
import {NodesDataSource} from "./nodes-datasource";
|
||||
import {Node} from "../models/node";
|
||||
import { NodesDataSource } from "./nodes-datasource";
|
||||
import { Node } from "../models/node";
|
||||
|
||||
|
||||
describe('NodesDataSource', () => {
|
||||
|
@ -1,6 +1,7 @@
|
||||
import {Node} from "../models/node";
|
||||
import {DataSource} from "./datasource";
|
||||
import {Injectable} from "@angular/core";
|
||||
import { Injectable } from "@angular/core";
|
||||
|
||||
import { Node } from "../models/node";
|
||||
import { DataSource } from "./datasource";
|
||||
|
||||
|
||||
@Injectable()
|
||||
|
@ -1,5 +1,5 @@
|
||||
import {SymbolsDataSource} from "./symbols-datasource";
|
||||
import {Symbol} from "../models/symbol";
|
||||
import { SymbolsDataSource } from "./symbols-datasource";
|
||||
import { Symbol } from "../models/symbol";
|
||||
|
||||
|
||||
describe('SymbolsDataSource', () => {
|
||||
|
@ -1,7 +1,7 @@
|
||||
import {Node} from "../models/node";
|
||||
import {DataSource} from "./datasource";
|
||||
import {Injectable} from "@angular/core";
|
||||
import {Symbol} from "../models/symbol";
|
||||
import { Injectable } from "@angular/core";
|
||||
|
||||
import { DataSource } from "./datasource";
|
||||
import { Symbol } from "../models/symbol";
|
||||
|
||||
|
||||
@Injectable()
|
||||
|
@ -101,7 +101,6 @@ export class LinksWidget implements Widget {
|
||||
const link = view
|
||||
.selectAll<SVGGElement, Link>("g.link")
|
||||
.data((layer: Layer) => {
|
||||
console.log(layer.links);
|
||||
if (layer.links) {
|
||||
const layer_links = layer.links.filter((l: Link) => {
|
||||
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 { Observable } from 'rxjs/Observable';
|
||||
@ -19,7 +19,7 @@ import { MapComponent } from "../cartography/map/map.component";
|
||||
import { ServerService } from "../shared/services/server.service";
|
||||
import { ProjectService } from '../shared/services/project.service';
|
||||
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 { Snapshot } from "../shared/models/snapshot";
|
||||
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 { LinksDataSource } from "../cartography/shared/datasources/links-datasource";
|
||||
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 { InRectangleHelper } from "../cartography/map/helpers/in-rectangle-helper";
|
||||
import { DrawingsDataSource } from "../cartography/shared/datasources/drawings-datasource";
|
||||
|
||||
|
||||
@Component({
|
||||
@ -81,6 +81,7 @@ export class ProjectMapComponent implements OnInit {
|
||||
private projectWebServiceHandler: ProjectWebServiceHandler,
|
||||
protected nodesDataSource: NodesDataSource,
|
||||
protected linksDataSource: LinksDataSource,
|
||||
protected drawingsDataSource: DrawingsDataSource
|
||||
) {
|
||||
}
|
||||
|
||||
@ -114,6 +115,13 @@ export class ProjectMapComponent implements OnInit {
|
||||
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.nodes = nodes;
|
||||
if (this.mapChild) {
|
||||
@ -136,7 +144,7 @@ export class ProjectMapComponent implements OnInit {
|
||||
return this.projectService.drawings(this.server, project.project_id);
|
||||
})
|
||||
.flatMap((drawings: Drawing[]) => {
|
||||
this.drawings = drawings;
|
||||
this.drawingsDataSource.set(drawings);
|
||||
return this.projectService.links(this.server, project.project_id);
|
||||
})
|
||||
.flatMap((links: Link[]) => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user