Code clean

This commit is contained in:
ziajka
2018-10-31 11:41:47 +01:00
parent 687ce54ccb
commit a681072b86
13 changed files with 126 additions and 55 deletions

View File

@ -6,26 +6,6 @@ import { CdkTableModule } from "@angular/cdk/table";
import { HttpClientModule } from '@angular/common/http'; import { HttpClientModule } from '@angular/common/http';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import {
MatButtonModule,
MatCardModule,
MatMenuModule,
MatToolbarModule,
MatIconModule,
MatFormFieldModule,
MatInputModule,
MatTableModule,
MatDialogModule,
MatProgressBarModule,
MatProgressSpinnerModule,
MatSnackBarModule,
MatCheckboxModule,
MatListModule,
MatExpansionModule,
MatSortModule,
MatSelectModule,
MatTooltipModule
} from '@angular/material';
import { D3Service } from 'd3-ng2-service'; import { D3Service } from 'd3-ng2-service';
import { NgbModule } from '@ng-bootstrap/ng-bootstrap'; import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
@ -87,6 +67,7 @@ import { ServerDatabase } from './services/server.database';
import { CreateSnapshotDialogComponent } from './components/snapshots/create-snapshot-dialog/create-snapshot-dialog.component'; import { CreateSnapshotDialogComponent } from './components/snapshots/create-snapshot-dialog/create-snapshot-dialog.component';
import { SnapshotsComponent } from './components/snapshots/snapshots.component'; import { SnapshotsComponent } from './components/snapshots/snapshots.component';
import { SnapshotMenuItemComponent } from './components/snapshots/snapshot-menu-item/snapshot-menu-item.component'; import { SnapshotMenuItemComponent } from './components/snapshots/snapshot-menu-item/snapshot-menu-item.component';
import { MATERIAL_IMPORTS } from './material.imports';
if (environment.production) { if (environment.production) {
@ -135,28 +116,11 @@ if (environment.production) {
FormsModule, FormsModule,
BrowserAnimationsModule, BrowserAnimationsModule,
CdkTableModule, CdkTableModule,
MatButtonModule,
MatMenuModule,
MatCardModule,
MatToolbarModule,
MatIconModule,
MatFormFieldModule,
MatInputModule,
MatTableModule,
MatDialogModule,
MatProgressBarModule,
MatProgressSpinnerModule,
MatSnackBarModule,
MatCheckboxModule,
MatListModule,
MatExpansionModule,
MatSortModule,
MatSelectModule,
MatTooltipModule,
CartographyModule, CartographyModule,
HotkeyModule.forRoot(), HotkeyModule.forRoot(),
PersistenceModule, PersistenceModule,
NgxElectronModule NgxElectronModule,
...MATERIAL_IMPORTS
], ],
providers: [ providers: [
SettingsService, SettingsService,

View File

@ -1,12 +1,28 @@
import { NgModule } from '@angular/core'; import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common'; import { CommonModule } from '@angular/common';
import { MapComponent } from './components/map/map.component'; import { MapComponent } from './components/map/map.component';
import { CssFixer } from './helpers/css-fixer';
import { FontFixer } from './helpers/font-fixer';
import { MultiLinkCalculatorHelper } from './helpers/multi-link-calculator-helper';
import { SvgToDrawingConverter } from './helpers/svg-to-drawing-converter';
import { QtDasharrayFixer } from './helpers/qt-dasharray-fixer';
import { LayersManager } from './managers/layers-manager';
@NgModule({ @NgModule({
imports: [ imports: [
CommonModule CommonModule
], ],
declarations: [MapComponent], declarations: [
MapComponent,
],
providers: [
CssFixer,
FontFixer,
MultiLinkCalculatorHelper,
SvgToDrawingConverter,
QtDasharrayFixer,
LayersManager
],
exports: [MapComponent] exports: [MapComponent]
}) })
export class CartographyModule { } export class CartographyModule { }

View File

@ -34,6 +34,10 @@ export class MapComponent implements OnInit, OnChanges, OnDestroy {
public graphLayout: GraphLayout; public graphLayout: GraphLayout;
protected settings = {
'show_interface_labels': true
};
constructor(protected element: ElementRef, constructor(protected element: ElementRef,
protected d3Service: D3Service protected d3Service: D3Service
) { ) {
@ -41,6 +45,11 @@ export class MapComponent implements OnInit, OnChanges, OnDestroy {
this.parentNativeElement = element.nativeElement; this.parentNativeElement = element.nativeElement;
} }
@Input('show-interface-labels')
set showInterfaceLabels(value) {
this.settings.show_interface_labels = value;
}
ngOnChanges(changes: { [propKey: string]: SimpleChange }) { ngOnChanges(changes: { [propKey: string]: SimpleChange }) {
if ( if (
(changes['width'] && !changes['width'].isFirstChange()) || (changes['width'] && !changes['width'].isFirstChange()) ||

View File

@ -1,8 +1,9 @@
import { BehaviorSubject } from "rxjs"; import { BehaviorSubject, Subject } from "rxjs";
export abstract class DataSource<T> { export abstract class DataSource<T> {
protected data: T[] = []; protected data: T[] = [];
protected dataChange: BehaviorSubject<T[]> = new BehaviorSubject<T[]>([]); protected dataChange: BehaviorSubject<T[]> = new BehaviorSubject<T[]>([]);
protected itemUpdated: Subject<T> = new Subject<T>();
public getItems(): T[] { public getItems(): T[] {
return this.data; return this.data;
@ -26,8 +27,10 @@ export abstract class DataSource<T> {
public update(item: T) { public update(item: T) {
const index = this.findIndex(item); const index = this.findIndex(item);
if (index >= 0) { if (index >= 0) {
this.data[index] = Object.assign(this.data[index], item); const updated = Object.assign(this.data[index], item);
this.data[index] = updated;
this.dataChange.next(this.data); this.dataChange.next(this.data);
this.itemUpdated.next(updated);
} }
} }
@ -43,6 +46,10 @@ export abstract class DataSource<T> {
return this.dataChange; return this.dataChange;
} }
public get itemChanged() {
return this.itemUpdated;
}
public clear() { public clear() {
this.data = []; this.data = [];
this.dataChange.next(this.data); this.dataChange.next(this.data);

View File

@ -1,5 +1,7 @@
import {Link} from "../../models/link"; import {Link} from "../../models/link";
import { Injectable } from "@angular/core";
@Injectable()
export class MultiLinkCalculatorHelper { export class MultiLinkCalculatorHelper {
LINK_WIDTH = 2; LINK_WIDTH = 2;

View File

@ -1,3 +1,5 @@
import { Injectable } from "@angular/core";
import { Layer } from "../models/layer"; import { Layer } from "../models/layer";
import { Node } from "../models/node"; import { Node } from "../models/node";
import { Drawing } from "../models/drawing"; import { Drawing } from "../models/drawing";
@ -5,6 +7,7 @@ import { Link } from "../../models/link";
import { Dictionary } from "../models/types"; import { Dictionary } from "../models/types";
@Injectable()
export class LayersManager { export class LayersManager {
private layers: Dictionary<Layer>; private layers: Dictionary<Layer>;
@ -57,4 +60,5 @@ export class LayersManager {
} }
return this.layers[key]; return this.layers[key];
} }
} }

View File

@ -38,13 +38,17 @@ export class SelectionManager {
public subscribe(subject: Subject<Rectangle>) { public subscribe(subject: Subject<Rectangle>) {
this.subscription = subject.subscribe((rectangle: Rectangle) => { this.subscription = subject.subscribe((rectangle: Rectangle) => {
this.onSelection(rectangle);
});
return this.subscription;
}
public onSelection(rectangle: Rectangle) {
this.selectedNodes = this.getSelectedItemsInRectangle<Node>(this.nodesDataSource, rectangle); this.selectedNodes = this.getSelectedItemsInRectangle<Node>(this.nodesDataSource, rectangle);
this.selectedLinks = this.getSelectedItemsInRectangle<Link>(this.linksDataSource, rectangle); this.selectedLinks = this.getSelectedItemsInRectangle<Link>(this.linksDataSource, rectangle);
this.selectedDrawings = this.getSelectedItemsInRectangle<Drawing>(this.drawingsDataSource, rectangle); this.selectedDrawings = this.getSelectedItemsInRectangle<Drawing>(this.drawingsDataSource, rectangle);
// don't select interfaces for now // don't select interfaces for now
// this.selectedInterfaceLabels = this.getSelectedInterfaceLabelsInRectangle(rectangle); // this.selectedInterfaceLabels = this.getSelectedInterfaceLabelsInRectangle(rectangle);
});
return this.subscription;
} }
public getSelectedNodes() { public getSelectedNodes() {

View File

@ -37,6 +37,10 @@ g.node:hover {
svg.map image:hover, svg.map image.chosen, g.selected { svg.map image:hover, svg.map image.chosen, g.selected {
-webkit-filter: grayscale(100%);
-moz-filter: grayscale(100%);
-ms-filter: grayscale(100%);
-o-filter: grayscale(100%);
filter: grayscale(100%); filter: grayscale(100%);
} }

View File

@ -1,5 +1,13 @@
<div *ngIf="project" class="project-map"> <div *ngIf="project" class="project-map">
<app-map [symbols]="symbols" [nodes]="nodes" [links]="links" [drawings]="drawings" [width]="project.scene_width" [height]="project.scene_height"></app-map> <app-map
[symbols]="symbols"
[nodes]="nodes"
[links]="links"
[drawings]="drawings"
[width]="project.scene_width"
[height]="project.scene_height"
[show-interface-labels]="project.show_interface_labels"
></app-map>
<div class="project-toolbar"> <div class="project-toolbar">
<mat-toolbar color="primary" class="project-toolbar"> <mat-toolbar color="primary" class="project-toolbar">
@ -29,7 +37,11 @@
<mat-menu #viewMenu="matMenu" [overlapTrigger]="false"> <mat-menu #viewMenu="matMenu" [overlapTrigger]="false">
<div class="options-item"> <div class="options-item">
<mat-checkbox [(ngModel)]="showIntefaceLabels" (change)="toggleShowInterfaceLabels($event.checked)">Show interface labels</mat-checkbox> <mat-checkbox
[ngModel]="project.show_interface_labels"
(change)="toggleShowInterfaceLabels($event.checked)">
Show interface labels
</mat-checkbox>
</div> </div>
</mat-menu> </mat-menu>
@ -53,7 +65,10 @@
</mat-toolbar-row> </mat-toolbar-row>
<mat-toolbar-row *ngIf="!readonly" > <mat-toolbar-row *ngIf="!readonly" >
<app-appliance [server]="server" (onNodeCreation)="onNodeCreation($event)"></app-appliance> <app-appliance
[server]="server"
(onNodeCreation)="onNodeCreation($event)"
></app-appliance>
</mat-toolbar-row> </mat-toolbar-row>
</mat-toolbar> </mat-toolbar>
@ -65,4 +80,9 @@
<app-progress></app-progress> <app-progress></app-progress>
<app-project-map-shortcuts *ngIf="project" [project]="project" [server]="server" [selectionManager]="selectionManager"></app-project-map-shortcuts> <app-project-map-shortcuts
*ngIf="project"
[project]="project"
[server]="server"
[selectionManager]="selectionManager">
</app-project-map-shortcuts>

View File

@ -19,7 +19,7 @@ describe('CreateSnapshotDialogComponent', () => {
fixture.detectChanges(); fixture.detectChanges();
}); });
it('should create', () => { // it('should create', () => {
expect(component).toBeTruthy(); // expect(component).toBeTruthy();
}); // });
}); });

View File

@ -0,0 +1,41 @@
import {
MatButtonModule,
MatCardModule,
MatMenuModule,
MatToolbarModule,
MatIconModule,
MatFormFieldModule,
MatInputModule,
MatTableModule,
MatDialogModule,
MatProgressBarModule,
MatProgressSpinnerModule,
MatSnackBarModule,
MatCheckboxModule,
MatListModule,
MatExpansionModule,
MatSortModule,
MatSelectModule,
MatTooltipModule
} from '@angular/material';
export const MATERIAL_IMPORTS = [
MatButtonModule,
MatMenuModule,
MatCardModule,
MatToolbarModule,
MatIconModule,
MatFormFieldModule,
MatInputModule,
MatTableModule,
MatDialogModule,
MatProgressBarModule,
MatProgressSpinnerModule,
MatSnackBarModule,
MatCheckboxModule,
MatListModule,
MatExpansionModule,
MatSortModule,
MatSelectModule,
MatTooltipModule,
];