diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 33c35af8..6e94648d 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -246,6 +246,8 @@ import { ResizableModule } from 'angular-resizable-element'; import { DragAndDropModule } from 'angular-draggable-droppable'; import { DragDropModule } from '@angular/cdk/drag-drop'; import { PageNotFoundComponent } from './components/page-not-found/page-not-found.component'; +import { AlignHorizontallyActionComponent } from './components/project-map/context-menu/actions/align-horizontally/align-horizontally.component'; +import { AlignVerticallyActionComponent } from './components/project-map/context-menu/actions/align_vertically/align-vertically.component'; if (environment.production) { Raven.config('https://b2b1cfd9b043491eb6b566fd8acee358@sentry.io/842726', { @@ -414,7 +416,9 @@ if (environment.production) { LockActionComponent, NavigationDialogComponent, ScreenshotDialogComponent, - PageNotFoundComponent + PageNotFoundComponent, + AlignHorizontallyActionComponent, + AlignVerticallyActionComponent ], imports: [ BrowserModule, diff --git a/src/app/components/project-map/context-menu/actions/align-horizontally/align-horizontally.component.html b/src/app/components/project-map/context-menu/actions/align-horizontally/align-horizontally.component.html new file mode 100644 index 00000000..92cd8c3e --- /dev/null +++ b/src/app/components/project-map/context-menu/actions/align-horizontally/align-horizontally.component.html @@ -0,0 +1,4 @@ + diff --git a/src/app/components/project-map/context-menu/actions/align-horizontally/align-horizontally.component.spec.ts b/src/app/components/project-map/context-menu/actions/align-horizontally/align-horizontally.component.spec.ts new file mode 100644 index 00000000..e69de29b diff --git a/src/app/components/project-map/context-menu/actions/align-horizontally/align-horizontally.component.ts b/src/app/components/project-map/context-menu/actions/align-horizontally/align-horizontally.component.ts new file mode 100644 index 00000000..6f0aeb63 --- /dev/null +++ b/src/app/components/project-map/context-menu/actions/align-horizontally/align-horizontally.component.ts @@ -0,0 +1,36 @@ +import { Component, OnInit, Input } from '@angular/core'; +import { Server } from '../../../../../models/server'; +import { Node } from '../../../../../cartography/models/node'; +import { NodesDataSource } from '../../../../../cartography/datasources/nodes-datasource'; +import { NodeService } from '../../../../../services/node.service'; + +@Component({ + selector: 'app-align-horizontally-action', + templateUrl: './align-horizontally.component.html' +}) +export class AlignHorizontallyActionComponent implements OnInit { + @Input() server: Server; + @Input() nodes: Node[]; + + constructor( + private nodesDataSource: NodesDataSource, + private nodeService: NodeService + ) {} + + ngOnInit() {} + + alignHorizontally() { + let averageY: number = 0; + this.nodes.forEach((node) => { + averageY += node.y; + }); + averageY = averageY/this.nodes.length; + + this.nodes.forEach((node) => { + node.y = averageY; + this.nodesDataSource.update(node); + + this.nodeService.update(this.server, node).subscribe((node: Node) => {}); + }); + } +} diff --git a/src/app/components/project-map/context-menu/actions/align_vertically/align-vertically.component.html b/src/app/components/project-map/context-menu/actions/align_vertically/align-vertically.component.html new file mode 100644 index 00000000..8ee5e162 --- /dev/null +++ b/src/app/components/project-map/context-menu/actions/align_vertically/align-vertically.component.html @@ -0,0 +1,4 @@ + diff --git a/src/app/components/project-map/context-menu/actions/align_vertically/align-vertically.component.spec.ts b/src/app/components/project-map/context-menu/actions/align_vertically/align-vertically.component.spec.ts new file mode 100644 index 00000000..e69de29b diff --git a/src/app/components/project-map/context-menu/actions/align_vertically/align-vertically.component.ts b/src/app/components/project-map/context-menu/actions/align_vertically/align-vertically.component.ts new file mode 100644 index 00000000..2633f783 --- /dev/null +++ b/src/app/components/project-map/context-menu/actions/align_vertically/align-vertically.component.ts @@ -0,0 +1,36 @@ +import { Component, OnInit, Input } from '@angular/core'; +import { Server } from '../../../../../models/server'; +import { Node } from '../../../../../cartography/models/node'; +import { NodesDataSource } from '../../../../../cartography/datasources/nodes-datasource'; +import { NodeService } from '../../../../../services/node.service'; + +@Component({ + selector: 'app-align-vertically-action', + templateUrl: './align-vertically.component.html' +}) +export class AlignVerticallyActionComponent implements OnInit { + @Input() server: Server; + @Input() nodes: Node[]; + + constructor( + private nodesDataSource: NodesDataSource, + private nodeService: NodeService + ) {} + + ngOnInit() {} + + alignVertically() { + let averageX: number = 0; + this.nodes.forEach((node) => { + averageX += node.x; + }); + averageX = averageX/this.nodes.length; + + this.nodes.forEach((node) => { + node.x = averageX; + this.nodesDataSource.update(node); + + this.nodeService.update(this.server, node).subscribe((node: 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 49904db0..397b7bf7 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 @@ -9,9 +9,9 @@ [server]="server" [node]="nodes[0]" > - - - + + + @@ -68,19 +68,19 @@ [node]="nodes[0]" > --> + +