Merge pull request #968 from GNS3/web-console-future-enhacements

Option to resize console
This commit is contained in:
piotrpekala7 2020-09-03 13:51:51 +02:00 committed by GitHub
commit 94ce514cfe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 83 additions and 17 deletions

View File

@ -3,7 +3,7 @@
(document:mousemove)="dragWidget($event)" (document:mousemove)="dragWidget($event)"
(document:mouseup)="toggleDragging(false)"> (document:mouseup)="toggleDragging(false)">
</div> </div>
<!-- Option with resizing <!-- Option with resizing -->
<div <div
class="consoleWrapper" class="consoleWrapper"
[ngClass]="{lightTheme: isLightThemeEnabled}" [ngClass]="{lightTheme: isLightThemeEnabled}"
@ -14,12 +14,12 @@
[resizeEdges]="{ right: true, left: true, bottom: true, top: true }" [resizeEdges]="{ right: true, left: true, bottom: true, top: true }"
[enableGhostResize]="true" [enableGhostResize]="true"
(resizeStart)="toggleDragging(false)" (resizeStart)="toggleDragging(false)"
(resizeEnd)="onResizeEnd($event)"> --> (resizeEnd)="onResizeEnd($event)">
<div <!-- <div
class="consoleWrapper" class="consoleWrapper"
[ngClass]="{lightTheme: isLightThemeEnabled}" [ngClass]="{lightTheme: isLightThemeEnabled}"
(mousedown)="toggleDragging(true)" (mousedown)="toggleDragging(true)"
[ngStyle]="style"> [ngStyle]="style"> -->
<div class="consoleHeader"> <div class="consoleHeader">
<mat-tab-group class="tabs" [selectedIndex]="selected.value" (selectedIndexChange)="selected.setValue($event)"> <mat-tab-group class="tabs" [selectedIndex]="selected.value" (selectedIndexChange)="selected.setValue($event)">
@ -53,7 +53,7 @@
<app-log-console [hidden]="!(selected.value===0) || isMinimized" [server]="server" [project]="project"></app-log-console> <app-log-console [hidden]="!(selected.value===0) || isMinimized" [server]="server" [project]="project"></app-log-console>
<div [hidden]="isMinimized" *ngFor="let node of nodes; let index = index"> <div class="xterm-console" [hidden]="isMinimized" *ngFor="let node of nodes; let index = index">
<app-web-console [hidden]="!(selected.value===(index+1))" [server]="server" [node]="nodes[index]"></app-web-console> <app-web-console [hidden]="!(selected.value===(index+1))" [server]="server" [node]="nodes[index]"></app-web-console>
</div> </div>
</div> </div>

View File

@ -5,7 +5,7 @@
left: 20px; left: 20px;
height: 180px; height: 180px;
width: 600px; width: 600px;
background: #263238; background: #000000!important;
color: white; color: white;
overflow: hidden; overflow: hidden;
font-size: 12px; font-size: 12px;
@ -38,10 +38,26 @@
display: flex; display: flex;
padding: 2px; padding: 2px;
justify-content: space-between; justify-content: space-between;
background: #263238!important;
}
:host ::ng-deep .mat-tab-label {
height: 3rem !important;
min-width: 8rem !important;
}
:host ::ng-deep .mat-tab-label.mat-tab-label-active {
border-bottom: 2px solid #0097a7;
box-sizing: border-box;
font-weight: 1200;
}
:host ::ng-deep .mat-ink-bar {
display: none !important;
} }
.tabs { .tabs {
width: 630px; width: 80%;
} }
.console { .console {
@ -54,6 +70,10 @@
scrollbar-width: thin; scrollbar-width: thin;
} }
.xterm-console {
background: black;
}
.consoleInput { .consoleInput {
width: 100%; width: 100%;
height: 30px; height: 30px;

View File

@ -24,12 +24,13 @@ export class ConsoleWrapperComponent implements OnInit {
public style: object = {}; public style: object = {};
public styleInside: object = { height: `120px` }; public styleInside: object = { height: `120px` };
public isDraggingEnabled: boolean = false; public isDraggingEnabled: boolean = false;
public isLightThemeEnabled: boolean = false; public isLightThemeEnabled: boolean = false;
public isMinimized: boolean = false; public isMinimized: boolean = false;
public resizedWidth: number = 720;
public resizedHeight: number = 480;
constructor( constructor(
private consoleService: NodeConsoleService, private consoleService: NodeConsoleService,
private themeService: ThemeService private themeService: ThemeService
@ -55,9 +56,9 @@ export class ConsoleWrapperComponent implements OnInit {
minimize(value: boolean) { minimize(value: boolean) {
this.isMinimized = value; this.isMinimized = value;
if (!value) { if (!value) {
this.style = { bottom: '20px', left: '20px', width: '720px', height: '460px'}; this.style = { bottom: '20px', left: '20px', width: `${this.resizedWidth}px`, height: `${this.resizedHeight}px`}
} else { } else {
this.style = { bottom: '20px', left: '20px', width: '720px', height: '56px'}; this.style = { bottom: '20px', left: '20px', width: `${this.resizedWidth}px`, height: '56px'};
} }
} }
@ -113,8 +114,8 @@ export class ConsoleWrapperComponent implements OnInit {
if ( if (
event.rectangle.width && event.rectangle.width &&
event.rectangle.height && event.rectangle.height &&
(event.rectangle.width < 720 || (event.rectangle.width < 500 ||
event.rectangle.height < 460) event.rectangle.height < 100)
) { ) {
return false; return false;
} }
@ -134,6 +135,14 @@ export class ConsoleWrapperComponent implements OnInit {
height: `${event.rectangle.height - 60}px`, height: `${event.rectangle.height - 60}px`,
width: `${event.rectangle.width}px` width: `${event.rectangle.width}px`
}; };
this.consoleService.consoleResized.next({
width: event.rectangle.width,
height: event.rectangle.height - 53
});
this.resizedWidth = event.rectangle.width;
this.resizedHeight = event.rectangle.height;
} }
close() { close() {

View File

@ -16,6 +16,7 @@ import { ResizeEvent } from 'angular-resizable-element';
import { ThemeService } from '../../../services/theme.service'; import { ThemeService } from '../../../services/theme.service';
import { FormControl } from '@angular/forms'; import { FormControl } from '@angular/forms';
import { version } from '../../../version'; import { version } from '../../../version';
import { NodeConsoleService } from '../../../services/nodeConsole.service';
@Component({ @Component({
@ -63,10 +64,17 @@ export class LogConsoleComponent implements OnInit, AfterViewInit, OnDestroy {
private logEventsDataSource: LogEventsDataSource, private logEventsDataSource: LogEventsDataSource,
private httpService: HttpServer, private httpService: HttpServer,
private themeService: ThemeService, private themeService: ThemeService,
private cd: ChangeDetectorRef private cd: ChangeDetectorRef,
private nodeConsoleService: NodeConsoleService,
private changeDetectorRef: ChangeDetectorRef
) {} ) {}
ngOnInit() { ngOnInit() {
this.nodeConsoleService.consoleResized.subscribe(ev => {
this.style = { bottom: '20px', left: '20px', width: `${ev.width}px`, height: `${ev.height - 70}px`};
this.changeDetectorRef.detectChanges();
});
this.themeService.getActualTheme() === 'light' ? this.isLightThemeEnabled = true : this.isLightThemeEnabled = false this.themeService.getActualTheme() === 'light' ? this.isLightThemeEnabled = true : this.isLightThemeEnabled = false
this.style = { bottom: '20px', left: '20px', width: '720px', height: '340px'}; this.style = { bottom: '20px', left: '20px', width: '720px', height: '340px'};

View File

@ -31,8 +31,18 @@ export class WebConsoleComponent implements OnInit, AfterViewInit {
ngOnInit() { ngOnInit() {
this.consoleService.consoleResized.subscribe(ev => { this.consoleService.consoleResized.subscribe(ev => {
this.fitAddon.fit(); let numberOfColumns = Math.floor(ev.width / 9);
let numberOfRows = Math.floor(ev.height / 17);
this.consoleService.setNumberOfColumns(numberOfColumns);
this.consoleService.setNumberOfRows(numberOfRows);
this.term.resize(numberOfColumns, numberOfRows);
}); });
if (this.consoleService.getNumberOfColumns() && this.consoleService.getNumberOfRows()){
this.term.resize(this.consoleService.getNumberOfColumns(), this.consoleService.getNumberOfRows());
}
} }
ngAfterViewInit() { ngAfterViewInit() {

View File

@ -15,8 +15,27 @@ export class NodeConsoleService {
public readonly defaultNumberOfColumns = 80; public readonly defaultNumberOfColumns = 80;
public readonly defaultNumberOfRows = 24; public readonly defaultNumberOfRows = 24;
private lastNumberOfColumns: number;
private lastNumberOfRows: number;
constructor() {} constructor() {}
getNumberOfColumns() {
return this.lastNumberOfColumns;
}
getNumberOfRows() {
return this.lastNumberOfRows;
}
setNumberOfColumns(value: number) {
this.lastNumberOfColumns = value;
}
setNumberOfRows(value: number) {
this.lastNumberOfRows = value;
}
openConsoleForNode(node: Node) { openConsoleForNode(node: Node) {
this.nodeConsoleTrigger.emit(node); this.nodeConsoleTrigger.emit(node);
} }
@ -39,6 +58,6 @@ export class NodeConsoleService {
} }
export interface ConsoleResizedEvent { export interface ConsoleResizedEvent {
numberOfColumns: number, width: number,
numberOfRows: number height: number
} }