mirror of
https://github.com/GNS3/gns3-web-ui.git
synced 2025-05-02 16:52:50 +00:00
Update project-web-service-handler
This commit is contained in:
parent
d11413d10e
commit
430107c065
@ -50,6 +50,7 @@ import { InterfaceLabelWidget } from '../../cartography/widgets/interface-label'
|
|||||||
import { LabelWidget } from '../../cartography/widgets/label';
|
import { LabelWidget } from '../../cartography/widgets/label';
|
||||||
import { MapLinkNodeToLinkNodeConverter } from '../../cartography/converters/map/map-link-node-to-link-node-converter';
|
import { MapLinkNodeToLinkNodeConverter } from '../../cartography/converters/map/map-link-node-to-link-node-converter';
|
||||||
import { ProjectMapMenuComponent } from './project-map-menu/project-map-menu.component';
|
import { ProjectMapMenuComponent } from './project-map-menu/project-map-menu.component';
|
||||||
|
import { ToasterService } from '../../services/toaster.service';
|
||||||
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
@ -65,7 +66,7 @@ export class ProjectMapComponent implements OnInit, OnDestroy {
|
|||||||
public symbols: Symbol[] = [];
|
public symbols: Symbol[] = [];
|
||||||
public project: Project;
|
public project: Project;
|
||||||
public server: Server;
|
public server: Server;
|
||||||
private ws: Subject<any>;
|
private ws: WebSocket;
|
||||||
public isProjectMapMenuVisible: boolean = false;
|
public isProjectMapMenuVisible: boolean = false;
|
||||||
|
|
||||||
tools = {
|
tools = {
|
||||||
@ -113,7 +114,8 @@ export class ProjectMapComponent implements OnInit, OnDestroy {
|
|||||||
private recentlyOpenedProjectService: RecentlyOpenedProjectService,
|
private recentlyOpenedProjectService: RecentlyOpenedProjectService,
|
||||||
private movingEventSource: MovingEventSource,
|
private movingEventSource: MovingEventSource,
|
||||||
private mapScaleService: MapScaleService,
|
private mapScaleService: MapScaleService,
|
||||||
private nodeCreatedLabelStylesFixer: NodeCreatedLabelStylesFixer
|
private nodeCreatedLabelStylesFixer: NodeCreatedLabelStylesFixer,
|
||||||
|
private toasterService: ToasterService
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
@ -228,9 +230,15 @@ export class ProjectMapComponent implements OnInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setUpWS(project: Project) {
|
setUpWS(project: Project) {
|
||||||
this.ws = webSocket(this.projectService.notificationsPath(this.server, project.project_id));
|
this.ws = new WebSocket(this.projectService.notificationsPath(this.server, project.project_id));
|
||||||
|
|
||||||
this.subscriptions.push(this.projectWebServiceHandler.connect(this.ws));
|
this.ws.onmessage = (ev: MessageEvent) => {
|
||||||
|
this.projectWebServiceHandler.handleMessage(ev);
|
||||||
|
};
|
||||||
|
|
||||||
|
this.ws.onerror = (ev: MessageEvent) => {
|
||||||
|
this.toasterService.error('Connection to host lost.');
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
setUpMapCallbacks() {
|
setUpMapCallbacks() {
|
||||||
@ -405,8 +413,8 @@ export class ProjectMapComponent implements OnInit, OnDestroy {
|
|||||||
this.nodesDataSource.clear();
|
this.nodesDataSource.clear();
|
||||||
this.linksDataSource.clear();
|
this.linksDataSource.clear();
|
||||||
|
|
||||||
if (this.ws) {
|
if (this.ws.OPEN) {
|
||||||
this.ws.unsubscribe();
|
this.ws.close();
|
||||||
}
|
}
|
||||||
this.subscriptions.forEach((subscription: Subscription) => subscription.unsubscribe());
|
this.subscriptions.forEach((subscription: Subscription) => subscription.unsubscribe());
|
||||||
}
|
}
|
||||||
|
@ -21,36 +21,36 @@ export class ProjectWebServiceHandler {
|
|||||||
private drawingsDataSource: DrawingsDataSource
|
private drawingsDataSource: DrawingsDataSource
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
public connect(ws: Subject<WebServiceMessage>) {
|
public handleMessage(event: MessageEvent) {
|
||||||
const subscription = ws.subscribe((message: WebServiceMessage) => {
|
console.log(event);
|
||||||
if (message.action === 'node.updated') {
|
let message = event.data;
|
||||||
this.nodesDataSource.update(message.event as Node);
|
if (message.action === 'node.updated') {
|
||||||
}
|
console.log('should work');
|
||||||
if (message.action === 'node.created') {
|
this.nodesDataSource.update(message.event as Node);
|
||||||
this.nodesDataSource.add(message.event as Node);
|
}
|
||||||
}
|
if (message.action === 'node.created') {
|
||||||
if (message.action === 'node.deleted') {
|
this.nodesDataSource.add(message.event as Node);
|
||||||
this.nodesDataSource.remove(message.event as Node);
|
}
|
||||||
}
|
if (message.action === 'node.deleted') {
|
||||||
if (message.action === 'link.created') {
|
this.nodesDataSource.remove(message.event as Node);
|
||||||
this.linksDataSource.add(message.event as Link);
|
}
|
||||||
}
|
if (message.action === 'link.created') {
|
||||||
if (message.action === 'link.updated') {
|
this.linksDataSource.add(message.event as Link);
|
||||||
this.linksDataSource.update(message.event as Link);
|
}
|
||||||
}
|
if (message.action === 'link.updated') {
|
||||||
if (message.action === 'link.deleted') {
|
this.linksDataSource.update(message.event as Link);
|
||||||
this.linksDataSource.remove(message.event as Link);
|
}
|
||||||
}
|
if (message.action === 'link.deleted') {
|
||||||
if (message.action === 'drawing.created') {
|
this.linksDataSource.remove(message.event as Link);
|
||||||
this.drawingsDataSource.add(message.event as Drawing);
|
}
|
||||||
}
|
if (message.action === 'drawing.created') {
|
||||||
if (message.action === 'drawing.updated') {
|
this.drawingsDataSource.add(message.event as Drawing);
|
||||||
this.drawingsDataSource.update(message.event as Drawing);
|
}
|
||||||
}
|
if (message.action === 'drawing.updated') {
|
||||||
if (message.action === 'drawing.deleted') {
|
this.drawingsDataSource.update(message.event as Drawing);
|
||||||
this.drawingsDataSource.remove(message.event as Drawing);
|
}
|
||||||
}
|
if (message.action === 'drawing.deleted') {
|
||||||
});
|
this.drawingsDataSource.remove(message.event as Drawing);
|
||||||
return subscription;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user