From 9f86414210d6c9717d9999378e24dc909920ee89 Mon Sep 17 00:00:00 2001 From: ziajka Date: Mon, 26 Mar 2018 10:25:30 +0200 Subject: [PATCH] Merge when updates items in datasource --- .../shared/datasources/datasource.spec.ts | 40 ++++++++++++------- .../shared/datasources/datasource.ts | 2 +- src/app/project-map/project-map.component.css | 4 +- src/app/project-map/project-map.component.ts | 1 - 4 files changed, 28 insertions(+), 19 deletions(-) diff --git a/src/app/cartography/shared/datasources/datasource.spec.ts b/src/app/cartography/shared/datasources/datasource.spec.ts index 1ee9d4b1..f60e6572 100644 --- a/src/app/cartography/shared/datasources/datasource.spec.ts +++ b/src/app/cartography/shared/datasources/datasource.spec.ts @@ -1,63 +1,73 @@ import {DataSource} from "./datasource"; -class TestDataSource extends DataSource { - protected findIndex(item: string) { - return this.data.findIndex((i: string) => i === item); +class Item { + constructor(public id: string, public property1?: string, public property2?: string) {} +} + + +class TestDataSource extends DataSource { + protected findIndex(item: Item) { + return this.data.findIndex((i: Item) => i.id === item.id); } }; + describe('TestDataSource', () => { let dataSource: TestDataSource; - let data: string[]; + let data: Item[]; beforeEach(() => { dataSource = new TestDataSource(); - dataSource.connect().subscribe((updated: string[]) => { + dataSource.connect().subscribe((updated: Item[]) => { data = updated; }); }); describe('Item can be added', () => { beforeEach(() => { - dataSource.add("test"); + dataSource.add(new Item("test1", "property1")); }); it('item should be in data', () => { - expect(data).toEqual(["test"]); + expect(data).toEqual([new Item("test1", "property1")]); }); }); describe('Items can be set', () => { beforeEach(() => { - dataSource.set(["test", "test2"]); + dataSource.set([new Item("test1", "property1"), new Item("test2", "property2")]); }); it('items should be in data', () => { - expect(data).toEqual(["test", "test2"]); + expect(data).toEqual([new Item("test1", "property1"), new Item("test2", "property2")]); }); }); describe('Items can be removed', () => { beforeEach(() => { - dataSource.set(["test", "test2"]); - dataSource.remove("test"); + dataSource.set([new Item("test1", "property1"), new Item("test2", "property2")]); + dataSource.remove(new Item("test1", "property1")); }); it('item should not be in data', () => { - expect(data).toEqual(["test2"]); + expect(data).toEqual([new Item("test2", "property2")]); }); }); describe('Item can be updated', () => { beforeEach(() => { - dataSource.set(["test", "test2"]); - dataSource.update("test"); + dataSource.set([new Item("test1", "property1", "another"), new Item("test2", "property2")]); + dataSource.update(new Item("test1", "property3")); }); it('item should be updated', () => { - expect(data).toEqual(["test", "test2"]); + expect(data).toEqual([ + new Item("test1", "property3"), + new Item("test2", "property2") + ]); }); + }); }); diff --git a/src/app/cartography/shared/datasources/datasource.ts b/src/app/cartography/shared/datasources/datasource.ts index 924d7474..97e31304 100644 --- a/src/app/cartography/shared/datasources/datasource.ts +++ b/src/app/cartography/shared/datasources/datasource.ts @@ -21,7 +21,7 @@ export abstract class DataSource { public update(item: T) { const index = this.findIndex(item); if (index >= 0) { - this.data[index] = item; + this.data[index] = Object.assign(this.data[index], item); this.dataChange.next(this.data); } } diff --git a/src/app/project-map/project-map.component.css b/src/app/project-map/project-map.component.css index 1c5070b8..0fb72dce 100644 --- a/src/app/project-map/project-map.component.css +++ b/src/app/project-map/project-map.component.css @@ -43,11 +43,11 @@ g.node text { } -svg image:hover, svg image.chosen, g.selectable.selected { +svg image:hover, svg image.chosen, g.selected { filter: grayscale(100%); } -path.selectable.selected { +path.selected { stroke: darkred; } diff --git a/src/app/project-map/project-map.component.ts b/src/app/project-map/project-map.component.ts index d4c2ef9a..78e4236a 100644 --- a/src/app/project-map/project-map.component.ts +++ b/src/app/project-map/project-map.component.ts @@ -169,7 +169,6 @@ export class ProjectMapComponent implements OnInit { this.mapChild.graphLayout.getNodesWidget().setOnNodeClickedCallback((event: any, node: Node) => { selectionManager.setSelectedNodes([node]); - if (this.drawLineMode) { this.nodeSelectInterfaceMenu.open(node, event.clientY, event.clientX); }