mirror of
https://github.com/GNS3/gns3-web-ui.git
synced 2025-06-17 06:18:09 +00:00
Calculating node position updated
This commit is contained in:
@ -7,6 +7,7 @@ import { Template } from '../../models/template';
|
|||||||
import { Project } from '../../models/project';
|
import { Project } from '../../models/project';
|
||||||
import { TemplateService } from '../../services/template.service';
|
import { TemplateService } from '../../services/template.service';
|
||||||
import { MapScaleService } from '../../services/mapScale.service';
|
import { MapScaleService } from '../../services/mapScale.service';
|
||||||
|
import { SymbolService } from '../../services/symbol.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-template',
|
selector: 'app-template',
|
||||||
@ -27,10 +28,14 @@ export class TemplateComponent implements OnInit {
|
|||||||
movementX: number;
|
movementX: number;
|
||||||
movementY: number;
|
movementY: number;
|
||||||
|
|
||||||
|
startX: number;
|
||||||
|
startY: number;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private dialog: MatDialog,
|
private dialog: MatDialog,
|
||||||
private templateService: TemplateService,
|
private templateService: TemplateService,
|
||||||
private scaleService: MapScaleService
|
private scaleService: MapScaleService,
|
||||||
|
private symbolService: SymbolService
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
@ -38,6 +43,7 @@ export class TemplateComponent implements OnInit {
|
|||||||
this.filteredTemplates = listOfTemplates;
|
this.filteredTemplates = listOfTemplates;
|
||||||
this.templates = listOfTemplates;
|
this.templates = listOfTemplates;
|
||||||
});
|
});
|
||||||
|
this.symbolService.list(this.server);
|
||||||
}
|
}
|
||||||
|
|
||||||
filterTemplates(event) {
|
filterTemplates(event) {
|
||||||
@ -55,20 +61,27 @@ export class TemplateComponent implements OnInit {
|
|||||||
dragStart(ev) {
|
dragStart(ev) {
|
||||||
let elemRect = (event.target as HTMLElement).getBoundingClientRect();
|
let elemRect = (event.target as HTMLElement).getBoundingClientRect();
|
||||||
|
|
||||||
|
this.startX = (event as MouseEvent).clientX;
|
||||||
|
this.startY = (event as MouseEvent).clientY;
|
||||||
|
|
||||||
this.movementY = elemRect.top - (event as MouseEvent).clientY;
|
this.movementY = elemRect.top - (event as MouseEvent).clientY;
|
||||||
this.movementX = elemRect.left - (event as MouseEvent).clientX;
|
this.movementX = elemRect.left - (event as MouseEvent).clientX;
|
||||||
}
|
}
|
||||||
|
|
||||||
dragEnd(ev, template) {
|
dragEnd(ev, template: Template) {
|
||||||
|
this.symbolService.raw(this.server, template.symbol.substring(1)).subscribe((symbolSvg: string) => {
|
||||||
|
let width = +symbolSvg.split("width=\"")[1].split("\"")[0];
|
||||||
let scale = this.scaleService.getScale();
|
let scale = this.scaleService.getScale();
|
||||||
|
|
||||||
let nodeAddedEvent: NodeAddedEvent = {
|
let nodeAddedEvent: NodeAddedEvent = {
|
||||||
template: template,
|
template: template,
|
||||||
server: 'local',
|
server: 'local',
|
||||||
numberOfNodes: 1,
|
numberOfNodes: 1,
|
||||||
x: ((event as MouseEvent).clientX - this.project.scene_width/2 + window.scrollX + this.movementX) * scale, //template.width
|
x: this.startX + ev.x - this.project.scene_width/2 - (width/2) + window.scrollX ,
|
||||||
y: ((event as MouseEvent).clientY - this.project.scene_height/2 + window.scrollY + this.movementY) * scale
|
y: this.startY + ev.y - this.project.scene_height/2 + window.scrollY
|
||||||
};
|
};
|
||||||
this.onNodeCreation.emit(nodeAddedEvent);
|
this.onNodeCreation.emit(nodeAddedEvent);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
openDialog() {
|
openDialog() {
|
||||||
|
@ -19,6 +19,10 @@ export class SymbolService {
|
|||||||
return this.symbols.getValue().find((symbol: Symbol) => symbol.symbol_id === symbol_id);
|
return this.symbols.getValue().find((symbol: Symbol) => symbol.symbol_id === symbol_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getByFilename(symbol_filename: string) {
|
||||||
|
return this.symbols.getValue().find((symbol: Symbol) => symbol.filename === symbol_filename);
|
||||||
|
}
|
||||||
|
|
||||||
add(server: Server, symbolName: string, symbol: string) {
|
add(server: Server, symbolName: string, symbol: string) {
|
||||||
this.cache = null;
|
this.cache = null;
|
||||||
return this.httpServer.post(server, `/symbols/${symbolName}/raw`, symbol)
|
return this.httpServer.post(server, `/symbols/${symbolName}/raw`, symbol)
|
||||||
|
Reference in New Issue
Block a user