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 { 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 { 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 { SnapshotsComponent } from './components/snapshots/snapshots.component';
import { SnapshotMenuItemComponent } from './components/snapshots/snapshot-menu-item/snapshot-menu-item.component';
import { MATERIAL_IMPORTS } from './material.imports';
if (environment.production) {
@ -135,28 +116,11 @@ if (environment.production) {
FormsModule,
BrowserAnimationsModule,
CdkTableModule,
MatButtonModule,
MatMenuModule,
MatCardModule,
MatToolbarModule,
MatIconModule,
MatFormFieldModule,
MatInputModule,
MatTableModule,
MatDialogModule,
MatProgressBarModule,
MatProgressSpinnerModule,
MatSnackBarModule,
MatCheckboxModule,
MatListModule,
MatExpansionModule,
MatSortModule,
MatSelectModule,
MatTooltipModule,
CartographyModule,
HotkeyModule.forRoot(),
PersistenceModule,
NgxElectronModule
NgxElectronModule,
...MATERIAL_IMPORTS
],
providers: [
SettingsService,

View File

@ -1,12 +1,28 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
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({
imports: [
CommonModule
],
declarations: [MapComponent],
declarations: [
MapComponent,
],
providers: [
CssFixer,
FontFixer,
MultiLinkCalculatorHelper,
SvgToDrawingConverter,
QtDasharrayFixer,
LayersManager
],
exports: [MapComponent]
})
export class CartographyModule { }

View File

@ -34,6 +34,10 @@ export class MapComponent implements OnInit, OnChanges, OnDestroy {
public graphLayout: GraphLayout;
protected settings = {
'show_interface_labels': true
};
constructor(protected element: ElementRef,
protected d3Service: D3Service
) {
@ -41,6 +45,11 @@ export class MapComponent implements OnInit, OnChanges, OnDestroy {
this.parentNativeElement = element.nativeElement;
}
@Input('show-interface-labels')
set showInterfaceLabels(value) {
this.settings.show_interface_labels = value;
}
ngOnChanges(changes: { [propKey: string]: SimpleChange }) {
if (
(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> {
protected data: T[] = [];
protected dataChange: BehaviorSubject<T[]> = new BehaviorSubject<T[]>([]);
protected itemUpdated: Subject<T> = new Subject<T>();
public getItems(): T[] {
return this.data;
@ -26,8 +27,10 @@ export abstract class DataSource<T> {
public update(item: T) {
const index = this.findIndex(item);
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.itemUpdated.next(updated);
}
}
@ -43,6 +46,10 @@ export abstract class DataSource<T> {
return this.dataChange;
}
public get itemChanged() {
return this.itemUpdated;
}
public clear() {
this.data = [];
this.dataChange.next(this.data);

View File

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

View File

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

View File

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

View File

@ -28,7 +28,7 @@ export class InterfaceLabelWidget {
const sourceInterface = new InterfaceLabel(
l.link_id,
'source',
Math.round( l.source.x + l.nodes[0].label.x),
Math.round(l.source.x + l.nodes[0].label.x),
Math.round(l.source.y + l.nodes[0].label.y),
l.nodes[0].label.text,
l.nodes[0].label.style,

View File

@ -37,6 +37,10 @@ g.node:hover {
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%);
}

View File

@ -1,5 +1,13 @@
<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">
<mat-toolbar color="primary" class="project-toolbar">
@ -29,7 +37,11 @@
<mat-menu #viewMenu="matMenu" [overlapTrigger]="false">
<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>
</mat-menu>
@ -53,7 +65,10 @@
</mat-toolbar-row>
<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>
@ -65,4 +80,9 @@
<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();
});
it('should create', () => {
expect(component).toBeTruthy();
});
// it('should create', () => {
// 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,
];