From 0d7c36d69a99728e1661e9dfe96fa447cb65fee3 Mon Sep 17 00:00:00 2001 From: Mark Drilling Date: Thu, 12 Jul 2018 17:38:26 -0500 Subject: [PATCH] Fixes mvn build and tests --- .../connections/shared/connection.service.ts | 2 +- .../src/app/dataservices/shared/path-utils.ts | 6 ++-- .../command/command-factory.spec.ts | 31 ++++++++++--------- .../view-editor/command/command.ts | 1 - .../view-editor/view-canvas/canvas.service.ts | 18 ++++++----- .../view-canvas/models/canvas-graph.ts | 16 +++++----- .../view-canvas/models/canvas-node.ts | 8 ++--- .../view-canvas/view-canvas.component.spec.ts | 6 ++++ .../view-canvas/view-canvas.component.ts | 8 ++--- .../visuals/graph/graph-visual.component.ts | 20 +++++++----- .../visuals/node/node-visual.component.ts | 4 +-- .../view-editor/view-editor.component.spec.ts | 10 ++++++ 12 files changed, 77 insertions(+), 53 deletions(-) diff --git a/ngapp/src/app/connections/shared/connection.service.ts b/ngapp/src/app/connections/shared/connection.service.ts index 2222863e..b6938484 100644 --- a/ngapp/src/app/connections/shared/connection.service.ts +++ b/ngapp/src/app/connections/shared/connection.service.ts @@ -32,7 +32,7 @@ import { VdbService } from "@dataservices/shared/vdb.service"; import { environment } from "@environments/environment"; import { Observable } from "rxjs/Observable"; import { Subscription } from "rxjs/Subscription"; -import {VdbsConstants} from "@dataservices/shared/vdbs-constants"; +import { VdbsConstants } from "@dataservices/shared/vdbs-constants"; @Injectable() export class ConnectionService extends ApiService { diff --git a/ngapp/src/app/dataservices/shared/path-utils.ts b/ngapp/src/app/dataservices/shared/path-utils.ts index 374ad29b..69b2a33d 100644 --- a/ngapp/src/app/dataservices/shared/path-utils.ts +++ b/ngapp/src/app/dataservices/shared/path-utils.ts @@ -27,7 +27,7 @@ export class PathUtils { const arrayLength = fqnArray.length; const connectionSegment = fqnArray[0]; - let parts = connectionSegment.split("=", 2); + const parts = connectionSegment.split("=", 2); const connName = parts[1]; return connName; @@ -43,7 +43,7 @@ export class PathUtils { const arrayLength = fqnArray.length; const nodeSeqment = fqnArray[arrayLength - 1]; - let parts = nodeSeqment.split("=", 2); + const parts = nodeSeqment.split("=", 2); const nodeName = parts[1]; return nodeName; @@ -59,7 +59,7 @@ export class PathUtils { const arrayLength = fqnArray.length; const nodeSeqment = fqnArray[arrayLength - 1]; - let parts = nodeSeqment.split("=", 2); + const parts = nodeSeqment.split("=", 2); const nodeType = parts[0]; return nodeType; diff --git a/ngapp/src/app/dataservices/virtualization/view-editor/command/command-factory.spec.ts b/ngapp/src/app/dataservices/virtualization/view-editor/command/command-factory.spec.ts index 080a244c..b24239fb 100644 --- a/ngapp/src/app/dataservices/virtualization/view-editor/command/command-factory.spec.ts +++ b/ngapp/src/app/dataservices/virtualization/view-editor/command/command-factory.spec.ts @@ -15,17 +15,19 @@ describe( "Command Factory Tests", () => { const path2 = "table=node2"; const node1 = SchemaNode.create( { connectionName: conn1, path: path1 } ); const node2 = SchemaNode.create( { connectionName: conn2, path: path2 } ); - const tempCmd = CommandFactory.createAddSourcesCommand( [ node1, node2 ] ); + const tempCmd = CommandFactory.createAddSourcesCommand( [ node1, node2 ], "ident" ); expect( tempCmd instanceof AddSourcesCommand ).toBe( true ); const cmd = tempCmd as AddSourcesCommand; expect( cmd.id ).toBe( AddSourcesCommand.id ); expect( cmd.args ).not.toBeNull(); - expect( cmd.args.size ).toBe( 1 ); + expect( cmd.args.size ).toBe( 2 ); - const expected = "connection=" + conn1 + "/" + path1 + ", connection=" + conn2 + "/" + path2; - expect( cmd.getArg( AddSourcesCommand.addedSourcePaths ) ).toEqual( expected ); - expect( cmd.toString() ).toBe( "AddSourcesCommand, addedSourcePaths=" + expected ); + const expectedSrcPaths = "connection=" + conn1 + "/" + path1 + ", connection=" + conn2 + "/" + path2; + const expectedFull = expectedSrcPaths + ", ObjectId=ident"; + const actual = cmd.getArg( AddSourcesCommand.addedSourcePaths ); + expect( cmd.getArg( AddSourcesCommand.addedSourcePaths ) ).toEqual( expectedSrcPaths ); + expect( cmd.toString() ).toBe( "AddSourcesCommand, addedSourcePaths=" + expectedFull ); expect( cmd.isUndoable() ).toBe( true ); const json = cmd.toJSON(); @@ -41,7 +43,7 @@ describe( "Command Factory Tests", () => { it("AddSourcesCommand Undo Test", () => { const node1 = SchemaNode.create( { connectionName: "conn1", path: "table=node1" } ); const node2 = SchemaNode.create( { connectionName: "conn2", path: "table=node2" } ); - const tempCmd = CommandFactory.createAddSourcesCommand( [ node1, node2 ] ); + const tempCmd = CommandFactory.createAddSourcesCommand( [ node1, node2 ], "ident" ); expect( tempCmd instanceof AddSourcesCommand ).toBe( true ); const cmd = tempCmd as AddSourcesCommand; @@ -51,7 +53,7 @@ describe( "Command Factory Tests", () => { const undoCmd = tempUndoCmd as RemoveSourcesCommand; expect( undoCmd ).not.toBeNull(); expect( undoCmd.id ).toBe( RemoveSourcesCommand.id ); - expect( undoCmd.args.size ).toBe( 1 ); + expect( undoCmd.args.size ).toBe( 2 ); expect( undoCmd.getArg( RemoveSourcesCommand.removedSourcePaths ) ).toEqual( cmd.getArg( AddSourcesCommand.addedSourcePaths ) ); }); @@ -77,17 +79,18 @@ describe( "Command Factory Tests", () => { const path2 = "table=node2"; const node1 = SchemaNode.create( { connectionName: "conn1", path: path1 } ); const node2 = SchemaNode.create( { connectionName: "conn2", path: path2 } ); - const temp = CommandFactory.createRemoveSourcesCommand( [ node1, node2 ] ); + const temp = CommandFactory.createRemoveSourcesCommand( [ node1, node2 ], "ident" ); expect( temp instanceof RemoveSourcesCommand ).toBe( true ); const cmd = temp as RemoveSourcesCommand; expect( cmd.id ).toBe( RemoveSourcesCommand.id ); expect( cmd.args ).not.toBeNull(); - expect( cmd.args.size ).toBe( 1 ); + expect( cmd.args.size ).toBe( 2 ); - const expected = "connection=" + conn1 + "/" + path1 + ", connection=" + conn2 + "/" + path2; - expect( cmd.getArg( RemoveSourcesCommand.removedSourcePaths ) ).toEqual( expected ); - expect( cmd.toString() ).toEqual( "RemoveSourcesCommand, removedSourcePaths=" + expected ); + const expectedSrcPaths = "connection=" + conn1 + "/" + path1 + ", connection=" + conn2 + "/" + path2; + const expectedFull = expectedSrcPaths + ", ObjectId=ident"; + expect( cmd.getArg( RemoveSourcesCommand.removedSourcePaths ) ).toEqual( expectedSrcPaths ); + expect( cmd.toString() ).toEqual( "RemoveSourcesCommand, removedSourcePaths=" + expectedFull ); expect( cmd.isUndoable() ).toBe( true ); const json = cmd.toJSON(); @@ -103,7 +106,7 @@ describe( "Command Factory Tests", () => { it("RemoveSourcesCommand Undo Test", () => { const node1 = SchemaNode.create( { connectionName: "conn1", path: "table=node1" } ); const node2 = SchemaNode.create( { connectionName: "conn2", path: "table=node2" } ); - const tempCmd = CommandFactory.createRemoveSourcesCommand( [ node1, node2 ] ); + const tempCmd = CommandFactory.createRemoveSourcesCommand( [ node1, node2 ], "ident" ); expect( tempCmd instanceof RemoveSourcesCommand ).toBe( true ); const cmd = tempCmd as RemoveSourcesCommand; @@ -113,7 +116,7 @@ describe( "Command Factory Tests", () => { const undoCmd = tempUndoCmd as AddSourcesCommand; expect( undoCmd ).not.toBeNull(); expect( undoCmd.id ).toBe( AddSourcesCommand.id ); - expect( undoCmd.args.size ).toBe( 1 ); + expect( undoCmd.args.size ).toBe( 2 ); expect( undoCmd.getArg( AddSourcesCommand.addedSourcePaths ) ).toEqual( cmd.getArg( RemoveSourcesCommand.removedSourcePaths ) ); }); diff --git a/ngapp/src/app/dataservices/virtualization/view-editor/command/command.ts b/ngapp/src/app/dataservices/virtualization/view-editor/command/command.ts index 9011793f..059c0e0e 100644 --- a/ngapp/src/app/dataservices/virtualization/view-editor/command/command.ts +++ b/ngapp/src/app/dataservices/virtualization/view-editor/command/command.ts @@ -42,7 +42,6 @@ export abstract class Command { */ public static readonly idPropJson = "id"; - /** * The identifier used for the id argument */ diff --git a/ngapp/src/app/dataservices/virtualization/view-editor/view-canvas/canvas.service.ts b/ngapp/src/app/dataservices/virtualization/view-editor/view-canvas/canvas.service.ts index 68bd93a4..bf85e80a 100644 --- a/ngapp/src/app/dataservices/virtualization/view-editor/view-canvas/canvas.service.ts +++ b/ngapp/src/app/dataservices/virtualization/view-editor/view-canvas/canvas.service.ts @@ -40,13 +40,15 @@ export class CanvasService { * This service will provide methods to enable user interaction with elements * while maintaining the d3 simulations physics */ - constructor() {} + constructor() { + // Nothing to do + } /** * The interactable graph. * This method does not interact with the document, purely physical calculations with d3 */ - public newCanvasGraph(options: { width, height }, changeDetectorRef: ChangeDetectorRef): CanvasGraph { + public newCanvasGraph(options: { width: number, height: number }, changeDetectorRef: ChangeDetectorRef): CanvasGraph { this.viewReference = changeDetectorRef; this.canvasGraph = new CanvasGraph(this, options); @@ -123,14 +125,14 @@ export class CanvasService { this.stopPropagation(); } - private removeNodeCallback(node: CanvasNode) { - let eventType = ViewCanvasEventType.DELETE_NODE; + private removeNodeCallback(node: CanvasNode): void { + const eventType = ViewCanvasEventType.DELETE_NODE; const args = []; // // Send the decoded id so that it can be parsed // and the source path extracted from it if required // - args.push(node.decodedId) + args.push(node.decodedId); const event = ViewCanvasEvent.create(eventType, args); this.canvasEvent.emit(event); @@ -226,7 +228,7 @@ export class CanvasService { const selection = d3.select('#' + elementId); if (selection) - return (selection.node()).getBBox(); + return (selection.node() as SVGGraphicsElement).getBBox(); return null; } @@ -235,7 +237,7 @@ export class CanvasService { * @returns the icon for the command type provided. If depressed then * returns the depressed version of the icon */ - public commandIcon(cmdType: string, depressed: boolean) { + public commandIcon(cmdType: string, depressed: boolean): string { if (depressed) return "/assets/iconfinder/Aha-soft/" + cmdType + "-depressed.png"; @@ -256,7 +258,7 @@ export class CanvasService { /** * Delete the node with the given id */ - public deleteNode(nodeId: string, refresh?: boolean) { + public deleteNode(nodeId: string, refresh?: boolean): void { if (! this.canvasGraph) throw new Error("A canvas graph is required before removing a node"); diff --git a/ngapp/src/app/dataservices/virtualization/view-editor/view-canvas/models/canvas-graph.ts b/ngapp/src/app/dataservices/virtualization/view-editor/view-canvas/models/canvas-graph.ts index 7e337c9f..3cf9bed1 100644 --- a/ngapp/src/app/dataservices/virtualization/view-editor/view-canvas/models/canvas-graph.ts +++ b/ngapp/src/app/dataservices/virtualization/view-editor/view-canvas/models/canvas-graph.ts @@ -26,22 +26,21 @@ import * as _ from "lodash"; const FORCES = { LINKS: 0.2, COLLISION: 1 -} +}; export class CanvasGraph { private canvasService: CanvasService; - private options: any + private options: any; private _nodes: CanvasNode[] = []; private _links: CanvasLink[] = []; - public ticker: EventEmitter = new EventEmitter(); public nodesSelected: EventEmitter = new EventEmitter(); private layout: cola.Layout; - constructor(canvasService: CanvasService, options: { width, height }) { + constructor(canvasService: CanvasService, options: { width: number, height: number }) { this.canvasService = canvasService; this.options = options; @@ -98,7 +97,6 @@ export class CanvasGraph { .nodes(this.nodes) .links(this.links); - // Connecting the d3 ticker to an angular event emitter this.layout.on('tick', function() { ticker.emit(this); @@ -111,7 +109,7 @@ export class CanvasGraph { * This will stop the layout and will require an update * to be called after it. */ - public setOptions(options: any) { + public setOptions(options: any): void { this.options = options; if (this.layout) { this.layout.stop(); @@ -122,7 +120,7 @@ export class CanvasGraph { /** * Callback for conducting a (de)selection of nodes */ - public selectionCallback(node: CanvasNode) { + public selectionCallback(node: CanvasNode): void { const append = d3.event.shiftKey; if (! node) { @@ -164,7 +162,7 @@ export class CanvasGraph { /** * @returns the collection of nodes */ - public get nodes() { + public get nodes(): CanvasNode[] { return this._nodes; } @@ -273,7 +271,7 @@ export class CanvasGraph { this.canvasService.update(true); } - public get links() { + public get links(): CanvasLink[] { return this._links; } diff --git a/ngapp/src/app/dataservices/virtualization/view-editor/view-canvas/models/canvas-node.ts b/ngapp/src/app/dataservices/virtualization/view-editor/view-canvas/models/canvas-node.ts index c6a45eb4..a45edd80 100644 --- a/ngapp/src/app/dataservices/virtualization/view-editor/view-canvas/models/canvas-node.ts +++ b/ngapp/src/app/dataservices/virtualization/view-editor/view-canvas/models/canvas-node.ts @@ -30,11 +30,11 @@ export class CanvasNode implements cola.Node { fx?: number | null; fy?: number | null; - private _id: string; - private _type: string; + private readonly _id: string; + private readonly _type: string; private _label: string; - private _selected: boolean = false; - private _root: boolean = false; + private _selected = false; + private _root = false; public static encodeId(id: string): string { return btoa(id); diff --git a/ngapp/src/app/dataservices/virtualization/view-editor/view-canvas/view-canvas.component.spec.ts b/ngapp/src/app/dataservices/virtualization/view-editor/view-canvas/view-canvas.component.spec.ts index 4f9ef228..f06c2460 100644 --- a/ngapp/src/app/dataservices/virtualization/view-editor/view-canvas/view-canvas.component.spec.ts +++ b/ngapp/src/app/dataservices/virtualization/view-editor/view-canvas/view-canvas.component.spec.ts @@ -21,6 +21,8 @@ import { MockVdbService } from "@dataservices/shared/mock-vdb.service"; import { NotifierService } from "@dataservices/shared/notifier.service"; import { ViewPropertyEditorsComponent } from "@dataservices/virtualization/view-editor/view-property-editors/view-property-editors.component"; import { TabsModule } from "ngx-bootstrap"; +import { GraphVisualComponent, LinkVisualComponent, NodeVisualComponent } from "@dataservices/virtualization/view-editor/view-canvas/visuals"; +import { CanvasService } from "@dataservices/virtualization/view-editor/view-canvas/canvas.service"; describe('ViewCanvasComponent', () => { let component: ViewCanvasComponent; @@ -42,12 +44,16 @@ describe('ViewCanvasComponent', () => { TabsModule.forRoot() ], declarations: [ + GraphVisualComponent, + LinkVisualComponent, + NodeVisualComponent, SelectedNodeComponent, ViewCanvasComponent, ViewPropertyEditorsComponent ], providers: [ { provide: AppSettingsService, useClass: MockAppSettingsService }, + CanvasService, LoggerService, NotifierService, { provide: VdbService, useClass: MockVdbService }, diff --git a/ngapp/src/app/dataservices/virtualization/view-editor/view-canvas/view-canvas.component.ts b/ngapp/src/app/dataservices/virtualization/view-editor/view-canvas/view-canvas.component.ts index 2f389529..f3973770 100644 --- a/ngapp/src/app/dataservices/virtualization/view-editor/view-canvas/view-canvas.component.ts +++ b/ngapp/src/app/dataservices/virtualization/view-editor/view-canvas/view-canvas.component.ts @@ -80,7 +80,7 @@ export class ViewCanvasComponent implements OnInit, AfterViewInit, OnDestroy { const srcPaths = cmd.getSourcePaths(); for (let i = 0; i < srcPaths.length; ++i) { const srcPath = srcPaths[i]; - const update = (i == (srcPaths.length - 1)); + const update = (i === (srcPaths.length - 1)); const id = cmd.getId(srcPath); this.canvasService.createNode(id, CanvasConstants.SOURCE_TYPE, srcPath, update); } @@ -89,7 +89,7 @@ export class ViewCanvasComponent implements OnInit, AfterViewInit, OnDestroy { const srcPaths = cmd.getSourcePaths(); for (let i = 0; i < srcPaths.length; ++i) { const srcPath = srcPaths[i]; - const update = (i == (srcPaths.length - 1)); + const update = (i === (srcPaths.length - 1)); const id = cmd.getId(srcPath); this.canvasService.deleteNode(id, update); } @@ -188,7 +188,7 @@ export class ViewCanvasComponent implements OnInit, AfterViewInit, OnDestroy { this.canvasSubscription = this.canvasService.canvasEvent.subscribe((event) => this.handleCanvasEvent(event)); } - public ngAfterViewInit() { + public ngAfterViewInit(): void { // const labels:string[] = ['Employee', 'Admin', 'Payroll', 'EmployeeAdmin', 'EmployeePayDay']; // const type:string[] = [ // CanvasConstants.SOURCE_TYPE, @@ -216,7 +216,7 @@ export class ViewCanvasComponent implements OnInit, AfterViewInit, OnDestroy { return; } - for (let node of nodes) { + for (const node of nodes) { console.log("Node " + node.label + " selected"); } }); diff --git a/ngapp/src/app/dataservices/virtualization/view-editor/view-canvas/visuals/graph/graph-visual.component.ts b/ngapp/src/app/dataservices/virtualization/view-editor/view-canvas/visuals/graph/graph-visual.component.ts index e787e653..63053cf9 100644 --- a/ngapp/src/app/dataservices/virtualization/view-editor/view-canvas/visuals/graph/graph-visual.component.ts +++ b/ngapp/src/app/dataservices/virtualization/view-editor/view-canvas/visuals/graph/graph-visual.component.ts @@ -75,31 +75,37 @@ import * as _ from "lodash"; export class GraphVisualComponent implements OnInit { public canvasGraph: CanvasGraph; - private _options: { width, height } = { width: 800, height: 600 }; + public _options: { width: number, height: number } = { width: 800, height: 600 }; + + private canvasService: CanvasService; + private ref: ChangeDetectorRef; @HostListener('window:resize', ['$event']) - onResize(event) { + public onResize(event): void { this.canvasService.update(true, this.options); } - constructor(private canvasService: CanvasService, private ref: ChangeDetectorRef) {} + constructor(canvasService: CanvasService, ref: ChangeDetectorRef) { + this.canvasService = canvasService; + this.ref = ref; + } - public get nodes() { + public get nodes(): CanvasNode[] { return this.canvasService.nodes(); } - public get links() { + public get links(): CanvasLink[] { return this.canvasService.links(); } - public ngOnInit() { + public ngOnInit(): void { console.log("graph-visual: ngOnInit"); /** Receiving an initialized simulated graph from our custom canvas.service */ this.canvasGraph = this.canvasService.newCanvasGraph(this.options, this.ref); } - public get options() { + public get options(): any { return this._options = { width: window.innerWidth, height: window.innerHeight diff --git a/ngapp/src/app/dataservices/virtualization/view-editor/view-canvas/visuals/node/node-visual.component.ts b/ngapp/src/app/dataservices/virtualization/view-editor/view-canvas/visuals/node/node-visual.component.ts index f10ee7f4..457abad2 100644 --- a/ngapp/src/app/dataservices/virtualization/view-editor/view-canvas/visuals/node/node-visual.component.ts +++ b/ngapp/src/app/dataservices/virtualization/view-editor/view-canvas/visuals/node/node-visual.component.ts @@ -67,7 +67,7 @@ export class NodeVisualComponent { * @return an id for the object type * based on the node's own id */ - public id(type: string) { + public id(type: string): string { return this.node.id + '-' + type; } @@ -75,7 +75,7 @@ export class NodeVisualComponent { if (this.node.type === CanvasConstants.SOURCE_TYPE) return "/assets/graphicsfuel/database-64.png"; else if (this.node.type === CanvasConstants.COMPONENT_TYPE) - return "/assets/component.png" + return "/assets/component.png"; return "/assets/iconfinder/Natalya-Skidan/question-mark.png"; } diff --git a/ngapp/src/app/dataservices/virtualization/view-editor/view-editor.component.spec.ts b/ngapp/src/app/dataservices/virtualization/view-editor/view-editor.component.spec.ts index 47aa3ab8..9dad7992 100644 --- a/ngapp/src/app/dataservices/virtualization/view-editor/view-editor.component.spec.ts +++ b/ngapp/src/app/dataservices/virtualization/view-editor/view-editor.component.spec.ts @@ -33,6 +33,12 @@ import { TableModule, ToolbarModule, WizardModule } from "patternfly-ng"; +import { + GraphVisualComponent, + LinkVisualComponent, + NodeVisualComponent +} from "@dataservices/virtualization/view-editor/view-canvas/visuals"; +import { CanvasService } from "@dataservices/virtualization/view-editor/view-canvas/canvas.service"; describe('ViewEditorComponent', () => { let component: ViewEditorComponent; @@ -61,6 +67,9 @@ describe('ViewEditorComponent', () => { ConnectionTableDialogComponent, ConnectionTreeSelectorComponent, EditorViewsComponent, + GraphVisualComponent, + LinkVisualComponent, + NodeVisualComponent, MessageLogComponent, SelectedNodeComponent, ViewCanvasComponent, @@ -71,6 +80,7 @@ describe('ViewEditorComponent', () => { ], providers: [ { provide: AppSettingsService, useClass: MockAppSettingsService }, + CanvasService, { provide: ConnectionService, useClass: MockConnectionService }, NotifierService, SelectionService,