From 7450dd6731fed05e549cbfdc626cc130b783c820 Mon Sep 17 00:00:00 2001 From: Piotr Pekala Date: Wed, 4 Sep 2019 05:14:29 -0700 Subject: [PATCH] Ability to change symbol by context menu added --- src/app/app.module.ts | 9 +++- .../common/symbols/symbols.component.html | 11 ++++- .../common/symbols/symbols.component.scss | 4 ++ .../change-symbol-dialog.component.html | 12 ++++++ .../change-symbol-dialog.component.scss | 19 +++++++++ .../change-symbol-dialog.component.ts | 41 +++++++++++++++++++ .../change-symbol-action.component.html | 4 ++ .../change-symbol-action.component.spec.ts | 0 .../change-symbol-action.component.ts | 29 +++++++++++++ .../context-menu/context-menu.component.html | 5 +++ src/app/services/node.service.ts | 6 +++ 11 files changed, 136 insertions(+), 4 deletions(-) create mode 100644 src/app/components/project-map/change-symbol-dialog/change-symbol-dialog.component.html create mode 100644 src/app/components/project-map/change-symbol-dialog/change-symbol-dialog.component.scss create mode 100644 src/app/components/project-map/change-symbol-dialog/change-symbol-dialog.component.ts create mode 100644 src/app/components/project-map/context-menu/actions/change-symbol/change-symbol-action.component.html create mode 100644 src/app/components/project-map/context-menu/actions/change-symbol/change-symbol-action.component.spec.ts create mode 100644 src/app/components/project-map/context-menu/actions/change-symbol/change-symbol-action.component.ts diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 9145d6f3..f928860d 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -204,6 +204,8 @@ import { BringToFrontActionComponent } from './components/project-map/context-me import { ExportConfigActionComponent } from './components/project-map/context-menu/actions/export-config/export-config-action.component'; import { ImportConfigActionComponent } from './components/project-map/context-menu/actions/import-config/import-config-action.component'; import { ConsoleDeviceActionBrowserComponent } from './components/project-map/context-menu/actions/console-device-action-browser/console-device-action-browser.component'; +import { ChangeSymbolDialogComponent } from './components/project-map/change-symbol-dialog/change-symbol-dialog.component'; +import { ChangeSymbolActionComponent } from './components/project-map/context-menu/actions/change-symbol/change-symbol-action.component'; if (environment.production) { Raven.config('https://b2b1cfd9b043491eb6b566fd8acee358@sentry.io/842726', { @@ -336,7 +338,9 @@ if (environment.production) { BringToFrontActionComponent, ExportConfigActionComponent, ImportConfigActionComponent, - ConsoleDeviceActionBrowserComponent + ConsoleDeviceActionBrowserComponent, + ChangeSymbolDialogComponent, + ChangeSymbolActionComponent ], imports: [ BrowserModule, @@ -433,7 +437,8 @@ if (environment.production) { StartCaptureDialogComponent, ConfigEditorDialogComponent, SaveProjectDialogComponent, - InfoDialogComponent + InfoDialogComponent, + ChangeSymbolDialogComponent ], bootstrap: [AppComponent] }) diff --git a/src/app/components/preferences/common/symbols/symbols.component.html b/src/app/components/preferences/common/symbols/symbols.component.html index 21f0882b..01c65e22 100644 --- a/src/app/components/preferences/common/symbols/symbols.component.html +++ b/src/app/components/preferences/common/symbols/symbols.component.html @@ -15,8 +15,15 @@ add Add symbol -
-

+ +
+ + + +
+ +
diff --git a/src/app/components/project-map/change-symbol-dialog/change-symbol-dialog.component.scss b/src/app/components/project-map/change-symbol-dialog/change-symbol-dialog.component.scss new file mode 100644 index 00000000..6deef2c4 --- /dev/null +++ b/src/app/components/project-map/change-symbol-dialog/change-symbol-dialog.component.scss @@ -0,0 +1,19 @@ +.symbolsWrapper { + height: 350px; + overflow-y: scroll; + scrollbar-color: darkgrey #263238; + scrollbar-width: thin; +} + +::-webkit-scrollbar { + width: 0.5em; +} + +::-webkit-scrollbar-track { + -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3); +} + +::-webkit-scrollbar-thumb { + background-color: darkgrey; + outline: 1px solid #263238; +} diff --git a/src/app/components/project-map/change-symbol-dialog/change-symbol-dialog.component.ts b/src/app/components/project-map/change-symbol-dialog/change-symbol-dialog.component.ts new file mode 100644 index 00000000..6fbd4bdb --- /dev/null +++ b/src/app/components/project-map/change-symbol-dialog/change-symbol-dialog.component.ts @@ -0,0 +1,41 @@ +import { Component, Input, OnInit } from '@angular/core'; +import { MatDialogRef } from '@angular/material'; +import { Message } from '../../../models/message'; +import { Server } from '../../../models/server'; +import { Node } from '../../../cartography/models/node'; +import { Symbol } from '../../../models/symbol'; +import { NodeService } from '../../../services/node.service'; + +@Component({ + selector: 'app-change-symbol-dialog', + templateUrl: './change-symbol-dialog.component.html', + styleUrls: ['./change-symbol-dialog.component.scss'] +}) +export class ChangeSymbolDialogComponent implements OnInit { + @Input() server: Server; + @Input() node: Node; + symbol: string; + + constructor( + public dialogRef: MatDialogRef, + private nodeService: NodeService + ) {} + + ngOnInit() { + this.symbol = this.node.symbol; + } + + symbolChanged(chosenSymbol: string) { + this.symbol = chosenSymbol; + } + + onCloseClick() { + this.dialogRef.close(); + } + + onSelectClick() { + this.nodeService.updateSymbol(this.server, this.node, this.symbol).subscribe(() => { + this.onCloseClick() + }); + } +} diff --git a/src/app/components/project-map/context-menu/actions/change-symbol/change-symbol-action.component.html b/src/app/components/project-map/context-menu/actions/change-symbol/change-symbol-action.component.html new file mode 100644 index 00000000..71a7851e --- /dev/null +++ b/src/app/components/project-map/context-menu/actions/change-symbol/change-symbol-action.component.html @@ -0,0 +1,4 @@ + diff --git a/src/app/components/project-map/context-menu/actions/change-symbol/change-symbol-action.component.spec.ts b/src/app/components/project-map/context-menu/actions/change-symbol/change-symbol-action.component.spec.ts new file mode 100644 index 00000000..e69de29b diff --git a/src/app/components/project-map/context-menu/actions/change-symbol/change-symbol-action.component.ts b/src/app/components/project-map/context-menu/actions/change-symbol/change-symbol-action.component.ts new file mode 100644 index 00000000..af4f8d67 --- /dev/null +++ b/src/app/components/project-map/context-menu/actions/change-symbol/change-symbol-action.component.ts @@ -0,0 +1,29 @@ +import { Component, OnInit, Input } from '@angular/core'; +import { Server } from '../../../../../models/server'; +import { Node } from '../../../../../cartography/models/node'; +import { MatDialog } from '@angular/material'; +import { ChangeSymbolDialogComponent } from '../../../change-symbol-dialog/change-symbol-dialog.component'; + +@Component({ + selector: 'app-change-symbol-action', + templateUrl: './change-symbol-action.component.html' +}) +export class ChangeSymbolActionComponent implements OnInit { + @Input() server: Server; + @Input() node: Node; + + constructor(private dialog: MatDialog) {} + + ngOnInit() {} + + changeSymbol() { + const dialogRef = this.dialog.open(ChangeSymbolDialogComponent, { + width: '1000px', + height: '500px', + autoFocus: false + }); + let instance = dialogRef.componentInstance; + instance.server = this.server; + instance.node = this.node; + } +} diff --git a/src/app/components/project-map/context-menu/context-menu.component.html b/src/app/components/project-map/context-menu/context-menu.component.html index 63d75132..91962af5 100644 --- a/src/app/components/project-map/context-menu/context-menu.component.html +++ b/src/app/components/project-map/context-menu/context-menu.component.html @@ -16,6 +16,11 @@ *ngIf="!projectService.isReadOnly(project) && nodes.length===1 && !isElectronApp && nodes[0].console_type!=='none'" [node]="nodes[0]" > + { + return this.httpServer.put(server, `/projects/${node.project_id}/nodes/${node.node_id}`, { + symbol: changedSymbol + }); + } + update(server: Server, node: Node): Observable { return this.httpServer.put(server, `/projects/${node.project_id}/nodes/${node.node_id}`, { x: Math.round(node.x),