Use node names in HTTP console tabs

This commit is contained in:
piotrpekala7
2020-04-27 18:02:33 +02:00
parent 72b6be6862
commit 18f7f350f7
2 changed files with 22 additions and 4 deletions

View File

@ -8,6 +8,8 @@ import { FitAddon } from 'xterm-addon-fit';
import { NodeConsoleService } from '../../services/nodeConsole.service'; import { NodeConsoleService } from '../../services/nodeConsole.service';
import { ActivatedRoute } from '@angular/router'; import { ActivatedRoute } from '@angular/router';
import { ServerService } from '../../services/server.service'; import { ServerService } from '../../services/server.service';
import { Title } from '@angular/platform-browser';
import { NodeService } from '../../services/node.service';
@Component({ @Component({
@ -21,6 +23,9 @@ export class WebConsoleFullWindowComponent implements OnInit, AfterViewInit {
private projectId: string; private projectId: string;
private nodeId: string; private nodeId: string;
private server: Server;
private node: Node;
public term: Terminal = new Terminal(); public term: Terminal = new Terminal();
public fitAddon: FitAddon = new FitAddon(); public fitAddon: FitAddon = new FitAddon();
@ -29,7 +34,9 @@ export class WebConsoleFullWindowComponent implements OnInit, AfterViewInit {
constructor( constructor(
private consoleService: NodeConsoleService, private consoleService: NodeConsoleService,
private serverService: ServerService, private serverService: ServerService,
private route: ActivatedRoute private route: ActivatedRoute,
private title: Title,
private nodeService: NodeService
) {} ) {}
ngOnInit() { ngOnInit() {
@ -40,6 +47,14 @@ export class WebConsoleFullWindowComponent implements OnInit, AfterViewInit {
this.consoleService.consoleResized.subscribe(ev => { this.consoleService.consoleResized.subscribe(ev => {
this.fitAddon.fit(); this.fitAddon.fit();
}); });
this.serverService.get(+this.serverId).then((server: Server) => {
this.server = server;
this.nodeService.getNodeById(this.server, this.projectId, this.nodeId).subscribe((node: Node) => {
this.node = node;
this.title.setTitle(this.node.name);
});
})
} }
async ngAfterViewInit() { async ngAfterViewInit() {
@ -76,7 +91,6 @@ export class WebConsoleFullWindowComponent implements OnInit, AfterViewInit {
} }
async getUrl() { async getUrl() {
let server: Server = await this.serverService.get(+this.serverId); return `ws://${this.server.host}:${this.server.port}/v2/projects/${this.projectId}/nodes/${this.nodeId}/console/ws`
return `ws://${server.host}:${server.port}/v2/projects/${this.projectId}/nodes/${this.nodeId}/console/ws`
} }
} }

View File

@ -13,6 +13,10 @@ import { Label } from '../cartography/models/label';
export class NodeService { export class NodeService {
constructor(private httpServer: HttpServer) {} constructor(private httpServer: HttpServer) {}
getNodeById(server: Server, projectId: string, nodeId: string) {
return this.httpServer.get(server, `/projects/${projectId}/nodes/${nodeId}`);
}
start(server: Server, node: Node) { start(server: Server, node: Node) {
return this.httpServer.post<Node>(server, `/projects/${node.project_id}/nodes/${node.node_id}/start`, {}); return this.httpServer.post<Node>(server, `/projects/${node.project_id}/nodes/${node.node_id}/start`, {});
} }
@ -138,7 +142,7 @@ export class NodeService {
} }
getNode(server: Server, node: Node) { getNode(server: Server, node: Node) {
return this.httpServer.get(server, `/projects/${node.project_id}/nodes/${node.node_id}`) return this.httpServer.get(server, `/projects/${node.project_id}/nodes/${node.node_id}`);
} }
getDefaultCommand(): string { getDefaultCommand(): string {