Skip to content

Commit

Permalink
fix(webapp): active session connection status in menu (#1115)
Browse files Browse the repository at this point in the history
Issue: DGW-231
  • Loading branch information
kristahouse authored Nov 21, 2024
1 parent 4cf1e1e commit 45f396a
Show file tree
Hide file tree
Showing 9 changed files with 152 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,10 @@ export class WebClientArdComponent extends WebClientBaseComponent implements OnI
@ViewChild('ironGuiElementVnc') ironGuiElement: ElementRef;

screenScale = ScreenScale;
currentStatus: ComponentStatus;
formData: ArdFormDataInput;
ardError: { kind: string; backtrace: string };
isFullScreenMode = false;
showToolbarDiv = true;
loading = true;

middleToolbarButtons = [
{
Expand Down Expand Up @@ -111,7 +109,6 @@ export class WebClientArdComponent extends WebClientBaseComponent implements OnI

ngOnInit(): void {
this.removeWebClientGuiElement();
this.initializeStatus();
}

ngAfterViewInit(): void {
Expand Down Expand Up @@ -159,7 +156,7 @@ export class WebClientArdComponent extends WebClientBaseComponent implements OnI
private initializeStatus(): void {
this.currentStatus = {
id: this.webSessionId,
isInitialized: false,
isInitialized: true,
isDisabled: false,
isDisabledByUser: false,
};
Expand Down Expand Up @@ -354,7 +351,7 @@ export class WebClientArdComponent extends WebClientBaseComponent implements OnI

private handleSessionStarted(event: SessionEvent): void {
this.handleIronRDPConnectStarted();
this.currentStatus.isInitialized = true;
this.initializeStatus();
}

private handleSessionEndedOrError(event: SessionEvent): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,10 @@ export class WebClientRdpComponent extends WebClientBaseComponent implements OnI
@ViewChild('ironGuiElement') ironGuiElement: ElementRef;

screenScale = ScreenScale;
currentStatus: ComponentStatus;
formData: RdpFormDataInput;
rdpError: { kind: string; backtrace: string };
isFullScreenMode = false;
showToolbarDiv = true;
loading = true;

leftToolbarButtons = [
{
Expand Down Expand Up @@ -124,7 +122,6 @@ export class WebClientRdpComponent extends WebClientBaseComponent implements OnI

ngOnInit(): void {
this.removeWebClientGuiElement();
this.initializeStatus();
}

ngAfterViewInit(): void {
Expand Down Expand Up @@ -184,7 +181,7 @@ export class WebClientRdpComponent extends WebClientBaseComponent implements OnI
private initializeStatus(): void {
this.currentStatus = {
id: this.webSessionId,
isInitialized: false,
isInitialized: true,
isDisabled: false,
isDisabledByUser: false,
};
Expand Down Expand Up @@ -381,7 +378,7 @@ export class WebClientRdpComponent extends WebClientBaseComponent implements OnI

private handleSessionStarted(event: SessionEvent): void {
this.handleIronRDPConnectStarted();
this.currentStatus.isInitialized = true;
this.initializeStatus();
}

private handleSessionEndedOrError(event: SessionEvent): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { EMPTY, Observable, Subject, from, of, throwError } from 'rxjs';
import { catchError, map, switchMap, takeUntil } from 'rxjs/operators';
import { v4 as uuidv4 } from 'uuid';

import { WebClientBaseComponent } from '@shared/bases/base-web-client.component';
import { WebClientBaseComponent, WebComponentReady } from '@shared/bases/base-web-client.component';
import { GatewayAlertMessageService } from '@shared/components/gateway-alert-message/gateway-alert-message.service';
import { SshConnectionParameters } from '@shared/interfaces/connection-params.interfaces';
import { SSHFormDataInput } from '@shared/interfaces/forms.interfaces';
Expand All @@ -34,22 +34,21 @@ import { AnalyticService, ProtocolString } from '@gateway/shared/services/analyt
import { ExtractedHostnamePort } from '@shared/services/utils/string.service';

@Component({
selector: 'gateway-web-client-ssh',
templateUrl: 'web-client-ssh.component.html',
styleUrls: ['web-client-ssh.component.scss'],
providers: [MessageService],
})
export class WebClientSshComponent extends WebClientBaseComponent implements OnInit, OnDestroy {
export class WebClientSshComponent extends WebClientBaseComponent implements WebComponentReady, OnInit, OnDestroy {
@Input() webSessionId: string;
@Output() componentStatus: EventEmitter<ComponentStatus> = new EventEmitter<ComponentStatus>();
@Output() sizeChange: EventEmitter<void> = new EventEmitter<void>();

@ViewChild('sessionSshContainer') sessionContainerElement: ElementRef;
@ViewChild('webSSHGuiTerminal') webGuiTerminal: ElementRef;

currentStatus: ComponentStatus;
formData: SSHFormDataInput;
clientError: string;
loading = true;

rightToolbarButtons = [
{ label: 'Close Session', icon: 'dvl-icon dvl-icon-close', action: () => this.startTerminationProcess() },
Expand All @@ -73,9 +72,6 @@ export class WebClientSshComponent extends WebClientBaseComponent implements OnI
ngOnInit(): void {
sshLoggingService.setLevel(LoggingLevel.DEBUG);
this.removeWebClientGuiElement();
this.initializeStatus();

this.initiateRemoteClientListener();
}

ngOnDestroy(): void {
Expand All @@ -89,6 +85,16 @@ export class WebClientSshComponent extends WebClientBaseComponent implements OnI
super.ngOnDestroy();
}

webComponentReady(event: CustomEvent, webSessionId: string): void {
if (this.currentStatus.isInitialized || webSessionId !== this.webSessionId) {
return;
}

this.remoteTerminal = event.detail.sshTerminal;
this.initSessionEventHandler();
this.startConnectionProcess();
}

startTerminationProcess(): void {
this.currentStatus.isDisabledByUser = true;
this.handleSessionEndedOrError(TerminalConnectionStatus.failed);
Expand All @@ -100,7 +106,6 @@ export class WebClientSshComponent extends WebClientBaseComponent implements OnI
if (!this.currentStatus.isInitialized) {
return;
}
this.currentStatus.isInitialized = false;
void this.remoteTerminal.close();
}

Expand All @@ -126,32 +131,21 @@ export class WebClientSshComponent extends WebClientBaseComponent implements OnI
private initializeStatus(): void {
this.currentStatus = {
id: this.webSessionId,
isInitialized: false,
isInitialized: true,
isDisabled: false,
isDisabledByUser: false,
};
}

private disableComponentStatus(): void {
if (this.currentStatus.isDisabled) {
return;
}

this.currentStatus.isDisabled = true;
this.componentStatus.emit(this.currentStatus);
}

private initiateRemoteClientListener(): void {
this.remoteTerminalEventListener = this.renderer.listen('window', 'sshInitialized', (event) => {
if (this.currentStatus.isInitialized) {
return;
}
this.webComponentReady(event);
});
}

private webComponentReady(event): void {
this.remoteTerminal = event.detail.sshTerminal;
this.initSessionEventHandler();
this.startConnectionProcess();
}

private startConnectionProcess(): void {
if (!this.remoteTerminal) {
return;
Expand Down Expand Up @@ -197,6 +191,7 @@ export class WebClientSshComponent extends WebClientBaseComponent implements OnI

private getFormData(): Observable<void> {
return from(this.webSessionService.getWebSession(this.webSessionId)).pipe(
takeUntil(this.destroyed$),
map((currentWebSession) => {
this.formData = currentWebSession.data as SSHFormDataInput;
}),
Expand Down Expand Up @@ -248,7 +243,7 @@ export class WebClientSshComponent extends WebClientBaseComponent implements OnI

private handleSessionStarted(): void {
this.handleClientConnectStarted();
this.currentStatus.isInitialized = true;
this.initializeStatus();
}

private handleSessionEndedOrError(status: TerminalConnectionStatus): void {
Expand All @@ -267,7 +262,6 @@ export class WebClientSshComponent extends WebClientBaseComponent implements OnI
this.clientError = this.getMessage(status);

const icon: string = status !== TerminalConnectionStatus.connected ? DVL_WARNING_ICON : DVL_SSH_ICON;

void this.webSessionService.updateWebSessionIcon(this.webSessionId, icon);
}

Expand All @@ -285,7 +279,6 @@ export class WebClientSshComponent extends WebClientBaseComponent implements OnI
this.clientError = typeof error === 'string' ? error : this.getMessage(error);
console.error(error);
this.disableComponentStatus();

void this.webSessionService.updateWebSessionIcon(this.webSessionId, DVL_WARNING_ICON);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,8 @@ export class WebClientTelnetComponent extends WebClientBaseComponent implements
@ViewChild('sessionTelnetContainer') sessionContainerElement: ElementRef;
@ViewChild('webTelnetGuiTerminal') webGuiTerminal: ElementRef;

currentStatus: ComponentStatus;
formData: TelnetFormDataInput;
clientError: string;
loading = true;

rightToolbarButtons = [
{ label: 'Close Session', icon: 'dvl-icon dvl-icon-close', action: () => this.startTerminationProcess() },
Expand All @@ -73,9 +71,6 @@ export class WebClientTelnetComponent extends WebClientBaseComponent implements
ngOnInit(): void {
telnetLoggingService.setLevel(LoggingLevel.FATAL);
this.removeWebClientGuiElement();
this.initializeStatus();

this.initiateRemoteClientListener();
}

ngOnDestroy(): void {
Expand All @@ -89,6 +84,16 @@ export class WebClientTelnetComponent extends WebClientBaseComponent implements
super.ngOnDestroy();
}

webComponentReady(event: CustomEvent, webSessionId: string): void {
if (this.currentStatus.isInitialized || webSessionId !== this.webSessionId) {
return;
}

this.remoteTerminal = event.detail.telnetTerminal;
this.initSessionEventHandler();
this.startConnectionProcess();
}

startTerminationProcess(): void {
this.currentStatus.isDisabledByUser = true;
this.sendTerminateSessionCmd();
Expand Down Expand Up @@ -125,32 +130,21 @@ export class WebClientTelnetComponent extends WebClientBaseComponent implements
private initializeStatus(): void {
this.currentStatus = {
id: this.webSessionId,
isInitialized: false,
isInitialized: true,
isDisabled: false,
isDisabledByUser: false,
};
}

private disableComponentStatus(): void {
if (this.currentStatus.isDisabled) {
return;
}

this.currentStatus.isDisabled = true;
this.componentStatus.emit(this.currentStatus);
}

private initiateRemoteClientListener(): void {
this.remoteTerminalEventListener = this.renderer.listen('window', 'telnetInitialized', (event) => {
if (this.currentStatus.isInitialized) {
return;
}
this.webComponentReady(event);
});
}

private webComponentReady(event): void {
this.remoteTerminal = event.detail.telnetTerminal;
this.initSessionEventHandler();
this.startConnectionProcess();
}

private startConnectionProcess(): void {
if (!this.remoteTerminal) {
return;
Expand Down Expand Up @@ -241,8 +235,7 @@ export class WebClientTelnetComponent extends WebClientBaseComponent implements

private handleSessionStarted(): void {
this.handleClientConnectStarted();
this.currentStatus.isInitialized = true;
super.webClientConnectionSuccess();
this.initializeStatus();
}

private handleSessionEndedOrError(status: TerminalConnectionStatus): void {
Expand Down Expand Up @@ -272,6 +265,7 @@ export class WebClientTelnetComponent extends WebClientBaseComponent implements
private handleClientConnectStarted(): void {
this.loading = false;
void this.webSessionService.updateWebSessionIcon(this.webSessionId, DVL_TELNET_ICON);
super.webClientConnectionSuccess();
}

private handleTelnetError(error: string): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,10 @@ export class WebClientVncComponent extends WebClientBaseComponent implements OnI
@ViewChild('ironGuiElementVnc') ironGuiElement: ElementRef;

screenScale = ScreenScale;
currentStatus: ComponentStatus;
formData: VncFormDataInput;
clientError: { kind: string; backtrace: string };
isFullScreenMode = false;
showToolbarDiv = true;
loading = true;

leftToolbarButtons = [
{
Expand Down Expand Up @@ -124,7 +122,6 @@ export class WebClientVncComponent extends WebClientBaseComponent implements OnI

ngOnInit(): void {
this.removeWebClientGuiElement();
this.initializeStatus();
}

ngAfterViewInit(): void {
Expand Down Expand Up @@ -184,7 +181,7 @@ export class WebClientVncComponent extends WebClientBaseComponent implements OnI
private initializeStatus(): void {
this.currentStatus = {
id: this.webSessionId,
isInitialized: false,
isInitialized: true,
isDisabled: false,
isDisabledByUser: false,
};
Expand Down Expand Up @@ -380,7 +377,7 @@ export class WebClientVncComponent extends WebClientBaseComponent implements OnI

private handleSessionStarted(event: SessionEvent): void {
this.handleIronRDPConnectStarted();
this.currentStatus.isInitialized = true;
this.initializeStatus();
}

private handleSessionEndedOrError(event: SessionEvent): void {
Expand Down
14 changes: 13 additions & 1 deletion webapp/src/client/app/shared/bases/base-web-client.component.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
import { Directive } from '@angular/core';
import { BaseComponent } from '@shared/bases/base.component';
import { GatewayAlertMessageService } from '@shared/components/gateway-alert-message/gateway-alert-message.service';
import { ComponentStatus } from '@shared/models/component-status.model';
import { BaseSessionComponent } from '../models/web-session.model';
import { AnalyticService, ConnectionIdentifier, ProtocolString } from '../services/analytic.service';

export interface WebComponentReady {
webComponentReady(event: Event, webSessionId: string): void;
}

@Directive()
export abstract class WebClientBaseComponent extends BaseSessionComponent {
hideSpinnerOnly = false;
error: string;
loading = true;

analyticHandle: ConnectionIdentifier;

currentStatus: ComponentStatus = {
id: undefined,
isInitialized: false,
isDisabled: false,
isDisabledByUser: false,
};

protected constructor(
protected gatewayAlertMessageService: GatewayAlertMessageService,
protected analyticService: AnalyticService,
Expand Down
Loading

0 comments on commit 45f396a

Please sign in to comment.