mirror of
https://github.com/GNS3/gns3-web-ui.git
synced 2025-04-20 16:20:48 +00:00
Code cleaned up
This commit is contained in:
parent
740a042b0e
commit
9925b49725
@ -48,7 +48,7 @@ import { TextElementFactory } from './helpers/drawings-factory/text-element-fact
|
||||
import { EllipseElementFactory } from './helpers/drawings-factory/ellipse-element-factory';
|
||||
import { RectangleElementFactory } from './helpers/drawings-factory/rectangle-element-factory';
|
||||
import { LineElementFactory } from './helpers/drawings-factory/line-element-factory';
|
||||
import { TemporaryTextElementComponent } from './components/temporary-text-element/temporary-text-element.component';
|
||||
import { TextEditorComponent } from './components/text-editor/text-editor.component';
|
||||
import { DrawingAddingComponent } from './components/drawing-adding/drawing-adding.component';
|
||||
|
||||
|
||||
@ -63,7 +63,7 @@ import { DrawingAddingComponent } from './components/drawing-adding/drawing-addi
|
||||
ExperimentalMapComponent,
|
||||
DrawingAddingComponent,
|
||||
DrawingResizingComponent,
|
||||
TemporaryTextElementComponent,
|
||||
TextEditorComponent,
|
||||
...ANGULAR_MAP_DECLARATIONS,
|
||||
SelectionControlComponent,
|
||||
SelectionSelectComponent,
|
||||
|
@ -12,5 +12,5 @@
|
||||
<app-drawing-resizing></app-drawing-resizing>
|
||||
<app-selection-control></app-selection-control>
|
||||
<app-selection-select></app-selection-select>
|
||||
<app-temporary-text-element #temporaryTextElement [svg]="svg"></app-temporary-text-element>
|
||||
<app-text-editor #textEditor [svg]="svg"></app-text-editor>
|
||||
<app-draggable-selection [svg]="svg"></app-draggable-selection>
|
||||
|
Before Width: | Height: | Size: 518 B After Width: | Height: | Size: 486 B |
@ -20,7 +20,7 @@ import { GraphDataManager } from '../../managers/graph-data-manager';
|
||||
import { MapSettingsManager } from '../../managers/map-settings-manager';
|
||||
import { Server } from '../../../models/server';
|
||||
import { ToolsService } from '../../../services/tools.service';
|
||||
import { TemporaryTextElementComponent } from '../temporary-text-element/temporary-text-element.component';
|
||||
import { TextEditorComponent } from '../text-editor/text-editor.component';
|
||||
|
||||
|
||||
@Component({
|
||||
@ -39,7 +39,7 @@ export class D3MapComponent implements OnInit, OnChanges, OnDestroy {
|
||||
@Input() height = 600;
|
||||
|
||||
@ViewChild('svg') svgRef: ElementRef;
|
||||
@ViewChild('temporaryTextElement') temporaryTextElement: TemporaryTextElementComponent;
|
||||
@ViewChild('textEditor') textEditor: TextEditorComponent;
|
||||
|
||||
private parentNativeElement: any;
|
||||
private svg: Selection<SVGSVGElement, any, null, undefined>;
|
||||
@ -168,7 +168,7 @@ export class D3MapComponent implements OnInit, OnChanges, OnDestroy {
|
||||
this.graphDataManager.setLinks(this.links);
|
||||
this.graphDataManager.setDrawings(this.drawings);
|
||||
this.graphLayout.draw(this.svg, this.context);
|
||||
this.temporaryTextElement.activateTextEditing();
|
||||
this.textEditor.activateTextEditing();
|
||||
}
|
||||
|
||||
@HostListener('window:resize', ['$event'])
|
||||
|
@ -1,23 +0,0 @@
|
||||
import { TemporaryTextElementComponent } from "./temporary-text-element.component";
|
||||
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
|
||||
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
||||
|
||||
describe('TemporaryTextElementComponent', () => {
|
||||
let component: TemporaryTextElementComponent;
|
||||
let fixture: ComponentFixture<TemporaryTextElementComponent>;
|
||||
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
NoopAnimationsModule
|
||||
],
|
||||
providers: [
|
||||
|
||||
],
|
||||
declarations: [
|
||||
TemporaryTextElementComponent
|
||||
]
|
||||
});
|
||||
}));
|
||||
});
|
@ -0,0 +1,40 @@
|
||||
import { TextEditorComponent } from "./text-editor.component";
|
||||
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
|
||||
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
||||
import { DrawingsEventSource } from '../../events/drawings-event-source';
|
||||
import { ToolsService } from '../../../services/tools.service';
|
||||
import { Context } from '../../models/context';
|
||||
import { Renderer2 } from '@angular/core';
|
||||
|
||||
describe('TemporaryTextElementComponent', () => {
|
||||
let component: TextEditorComponent;
|
||||
let fixture: ComponentFixture<TextEditorComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
NoopAnimationsModule
|
||||
],
|
||||
providers: [
|
||||
{ provide: DrawingsEventSource, useClass: DrawingsEventSource },
|
||||
{ provide: ToolsService, useClass: ToolsService },
|
||||
{ provide: Context, useClass: Context },
|
||||
{ provide: Renderer2, useClass: Renderer2 }
|
||||
],
|
||||
declarations: [
|
||||
TextEditorComponent
|
||||
]
|
||||
})
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(TextEditorComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
@ -9,18 +9,16 @@ import { Subscription } from 'rxjs';
|
||||
|
||||
|
||||
@Component({
|
||||
selector: 'app-temporary-text-element',
|
||||
templateUrl: './temporary-text-element.component.html',
|
||||
styleUrls: ['./temporary-text-element.component.scss']
|
||||
selector: 'app-text-editor',
|
||||
templateUrl: './text-editor.component.html',
|
||||
styleUrls: ['./text-editor.component.scss']
|
||||
})
|
||||
export class TemporaryTextElementComponent implements OnInit, OnDestroy {
|
||||
export class TextEditorComponent implements OnInit, OnDestroy {
|
||||
@ViewChild('temporaryTextElement') temporaryTextElement: ElementRef;
|
||||
@Input('svg') svg: SVGSVGElement;
|
||||
|
||||
private isActive: boolean = true;
|
||||
private leftPosition: string = '0px';
|
||||
private topPosition: string = '0px';
|
||||
private display: string = 'none';
|
||||
private innerText: string = '';
|
||||
|
||||
private editingDrawingId: string;
|
||||
@ -40,39 +38,36 @@ export class TemporaryTextElementComponent implements OnInit, OnDestroy {
|
||||
|
||||
ngOnInit(){
|
||||
this.textAddingSubscription = this.toolsService.isTextAddingToolActivated.subscribe((isActive: boolean) => {
|
||||
isActive ? this.activate() : this.deactivate()
|
||||
isActive ? this.activateTextAdding() : this.deactivateTextAdding()
|
||||
});
|
||||
|
||||
this.activateTextEditing();
|
||||
}
|
||||
|
||||
activate(){
|
||||
activateTextAdding(){
|
||||
let addTextListener = (event: MouseEvent) => {
|
||||
this.leftPosition = event.clientX.toString() + 'px';
|
||||
this.topPosition = (event.clientY + window.pageYOffset).toString() + 'px';
|
||||
this.renderer.setStyle(this.temporaryTextElement.nativeElement, 'display', 'initial');
|
||||
|
||||
this.temporaryTextElement.nativeElement.focus();
|
||||
// //this.renderer.selectRootElement('#temporaryElement').focus();
|
||||
|
||||
let textListener = () => {
|
||||
this.drawingsEventSource.textAdded.emit(new TextAddedDataEvent(this.temporaryTextElement.nativeElement.innerText.replace(/\n$/, ""), event.clientX, event.clientY));
|
||||
this.deactivate();
|
||||
this.deactivateTextAdding();
|
||||
this.innerText = '';
|
||||
this.temporaryTextElement.nativeElement.removeEventListener("focusout", this.textListener);
|
||||
this.renderer.setStyle(this.temporaryTextElement.nativeElement, 'display', 'none');
|
||||
this.display = 'none';
|
||||
}
|
||||
this.textListener = textListener;
|
||||
this.temporaryTextElement.nativeElement.addEventListener('focusout', this.textListener);
|
||||
}
|
||||
|
||||
this.deactivate();
|
||||
this.deactivateTextAdding();
|
||||
this.mapListener = addTextListener;
|
||||
this.svg.addEventListener('click', this.mapListener as EventListenerOrEventListenerObject);
|
||||
}
|
||||
|
||||
deactivate(){
|
||||
deactivateTextAdding(){
|
||||
this.svg.removeEventListener('click', this.mapListener as EventListenerOrEventListenerObject);
|
||||
}
|
||||
|
||||
@ -119,6 +114,6 @@ export class TemporaryTextElementComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
ngOnDestroy(){
|
||||
this.toolsService.isTextAddingToolActivated.unsubscribe();
|
||||
this.textAddingSubscription.unsubscribe();
|
||||
}
|
||||
}
|
@ -147,7 +147,7 @@
|
||||
[server]="server"
|
||||
[project]="project"
|
||||
[selectedDrawing]="selectedDrawing"
|
||||
(drawingSaved)="onDrawingSaved($event)">
|
||||
(drawingSaved)="onDrawingSaved()">
|
||||
</app-drawing-added>
|
||||
<app-drawing-dragged [server]="server"></app-drawing-dragged>
|
||||
<app-drawing-resized [server]="server"></app-drawing-resized>
|
||||
@ -158,6 +158,6 @@
|
||||
<app-text-added
|
||||
[server]="server"
|
||||
[project]="project"
|
||||
(drawingSaved)="onDrawingSaved($event)">
|
||||
(drawingSaved)="onDrawingSaved()">
|
||||
</app-text-added>
|
||||
<app-text-edited [server]="server"></app-text-edited>
|
||||
|
Loading…
x
Reference in New Issue
Block a user