mirror of
https://github.com/GNS3/gns3-web-ui.git
synced 2025-02-20 17:52:46 +00:00
Update project-map.component.ts
This commit is contained in:
parent
edb7aefba2
commit
0f4890fd10
@ -169,56 +169,16 @@ export class ProjectMapComponent implements OnInit, OnDestroy {
|
||||
this.mapSettingsService.logConsoleSubject.subscribe(value => this.isConsoleVisible = value);
|
||||
|
||||
this.progressService.activate();
|
||||
const routeSub = this.route.paramMap.subscribe((paramMap: ParamMap) => {
|
||||
const server_id = parseInt(paramMap.get('server_id'), 10);
|
||||
|
||||
from(this.serverService.get(server_id))
|
||||
.pipe(
|
||||
mergeMap((server: Server) => {
|
||||
this.server = server;
|
||||
return this.projectService.get(server, paramMap.get('project_id')).pipe(
|
||||
map(project => {
|
||||
return project;
|
||||
})
|
||||
);
|
||||
}),
|
||||
mergeMap((project: Project) => {
|
||||
this.project = project;
|
||||
this.projectService.open(this.server, this.project.project_id);
|
||||
this.title.setTitle(this.project.name);
|
||||
|
||||
if (this.mapSettingsService.interfaceLabels.has(project.project_id)) {
|
||||
this.isInterfaceLabelVisible = this.mapSettingsService.interfaceLabels.get(project.project_id);
|
||||
} else {
|
||||
this.isInterfaceLabelVisible = this.project.show_interface_labels;
|
||||
}
|
||||
|
||||
this.recentlyOpenedProjectService.setServerId(this.server.id.toString());
|
||||
this.recentlyOpenedProjectService.setProjectId(this.project.project_id);
|
||||
|
||||
if (this.project.status === 'opened') {
|
||||
return new Observable<Project>(observer => {
|
||||
observer.next(this.project);
|
||||
});
|
||||
} else {
|
||||
return this.projectService.open(this.server, this.project.project_id);
|
||||
}
|
||||
})
|
||||
)
|
||||
.subscribe(
|
||||
(project: Project) => {
|
||||
this.onProjectLoad(project);
|
||||
},
|
||||
error => {
|
||||
this.progressService.setError(error);
|
||||
},
|
||||
() => {
|
||||
this.progressService.deactivate();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
this.projectMapSubscription.add(routeSub);
|
||||
if (this.serverService.isServiceInitialized) {
|
||||
this.getData();
|
||||
} else {
|
||||
this.projectMapSubscription.add(
|
||||
this.serverService.serviceInitialized.subscribe((val) => {
|
||||
if (val) this.getData();
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
this.projectMapSubscription.add(
|
||||
this.mapSettingsService.mapRenderedEmitter.subscribe((value: boolean) => {
|
||||
@ -272,6 +232,63 @@ export class ProjectMapComponent implements OnInit, OnDestroy {
|
||||
this.addKeyboardListeners();
|
||||
}
|
||||
|
||||
getData() {
|
||||
const routeSub = this.route.paramMap.subscribe((paramMap: ParamMap) => {
|
||||
const server_id = parseInt(paramMap.get('server_id'), 10);
|
||||
|
||||
from(this.serverService.get(server_id))
|
||||
.pipe(
|
||||
mergeMap((server: Server) => {
|
||||
if (!server ) this.router.navigate(['/servers']);
|
||||
|
||||
this.server = server;
|
||||
return this.projectService.get(server, paramMap.get('project_id')).pipe(
|
||||
map(project => {
|
||||
return project;
|
||||
})
|
||||
);
|
||||
}),
|
||||
mergeMap((project: Project) => {
|
||||
this.project = project;
|
||||
if (!project ) this.router.navigate(['/servers']);
|
||||
|
||||
this.projectService.open(this.server, this.project.project_id);
|
||||
this.title.setTitle(this.project.name);
|
||||
|
||||
if (this.mapSettingsService.interfaceLabels.has(project.project_id)) {
|
||||
this.isInterfaceLabelVisible = this.mapSettingsService.interfaceLabels.get(project.project_id);
|
||||
} else {
|
||||
this.isInterfaceLabelVisible = this.project.show_interface_labels;
|
||||
}
|
||||
|
||||
this.recentlyOpenedProjectService.setServerId(this.server.id.toString());
|
||||
this.recentlyOpenedProjectService.setProjectId(this.project.project_id);
|
||||
|
||||
if (this.project.status === 'opened') {
|
||||
return new Observable<Project>(observer => {
|
||||
observer.next(this.project);
|
||||
});
|
||||
} else {
|
||||
return this.projectService.open(this.server, this.project.project_id);
|
||||
}
|
||||
})
|
||||
)
|
||||
.subscribe(
|
||||
(project: Project) => {
|
||||
this.onProjectLoad(project);
|
||||
},
|
||||
error => {
|
||||
this.progressService.setError(error);
|
||||
},
|
||||
() => {
|
||||
this.progressService.deactivate();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
this.projectMapSubscription.add(routeSub);
|
||||
}
|
||||
|
||||
addKeyboardListeners() {
|
||||
Mousetrap.bind('ctrl++', (event: Event) => {
|
||||
event.preventDefault();
|
||||
|
Loading…
x
Reference in New Issue
Block a user