Skip to content

Commit

Permalink
Merge pull request #2040 from DSD-DBS/t4c-token-in-session-viewer
Browse files Browse the repository at this point in the history
feat: Allow users to copy t4c token from session viewer
  • Loading branch information
MoritzWeber0 authored Nov 29, 2024
2 parents bb822af + 45d0db3 commit 39d0574
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,35 @@
}
</div>

@if ((sessionViewerService.allSessions$ | async)!.length > 1) {
<button
class="m-0 flex items-center"
(click)="sessionViewerService.toggleFullscreen(session)"
>
@if (session.fullscreen) {
<mat-icon>fullscreen_exit</mat-icon>
} @else {
<mat-icon>fullscreen</mat-icon>
}
</button>
}
<div class="flex items-center gap-2">
@if (session.t4cToken) {
<button
class="m-0 flex items-center"
matTooltip="Copy TeamForCapella token"
[cdkCopyToClipboard]="session.t4cToken"
(click)="
toastService.showSuccess(
'T4C Token copied',
'The T4C Token was copied to your clipboard.'
)
"
>
<mat-icon>key</mat-icon>
</button>
}
@if ((sessionViewerService.allSessions$ | async)!.length > 1) {
<button
class="m-0 flex items-center"
(click)="sessionViewerService.toggleFullscreen(session)"
>
@if (session.fullscreen) {
<mat-icon>fullscreen_exit</mat-icon>
} @else {
<mat-icon>fullscreen</mat-icon>
}
</button>
}
</div>
</div>

<app-session-iframe class="flex h-full" [session]="session" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
* SPDX-FileCopyrightText: Copyright DB InfraGO AG and contributors
* SPDX-License-Identifier: Apache-2.0
*/
import { CdkCopyToClipboard } from '@angular/cdk/clipboard';
import { CdkDrag, CdkDragHandle } from '@angular/cdk/drag-drop';
import { NgClass, AsyncPipe } from '@angular/common';
import { Component, OnInit } from '@angular/core';
import { MatIcon } from '@angular/material/icon';
import { MatTooltip } from '@angular/material/tooltip';
import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy';
import { debounceTime, fromEvent } from 'rxjs';
import { ToastService } from '../../../helpers/toast/toast.service';
import { SessionIFrameComponent } from '../session-iframe/session-iframe.component';
import { SessionViewerService, ViewerSession } from '../session-viewer.service';

Expand All @@ -22,11 +25,16 @@ import { SessionViewerService, ViewerSession } from '../session-viewer.service';
MatIcon,
SessionIFrameComponent,
AsyncPipe,
MatTooltip,
CdkCopyToClipboard,
],
})
@UntilDestroy()
export class FloatingWindowManagerComponent implements OnInit {
constructor(public sessionViewerService: SessionViewerService) {}
constructor(
public sessionViewerService: SessionViewerService,
public toastService: ToastService,
) {}

ngOnInit(): void {
fromEvent(window, 'resize')
Expand Down
9 changes: 8 additions & 1 deletion frontend/src/app/sessions/session/session-viewer.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ export class SessionViewerService {
connectionInfo.redirect_url,
);

this.updateOrInsertSession(session, safeResourceURL);
this.updateOrInsertSession(
session,
safeResourceURL,
connectionInfo.t4c_token ?? undefined,
);
}

focusSession(session: Session): void {
Expand Down Expand Up @@ -178,13 +182,15 @@ export class SessionViewerService {
private updateOrInsertSession(
session: Session,
safeResourceURL?: SafeResourceUrl,
t4cToken?: string,
): void {
const currentSessions = this._sessions.value;

const viewerSession: ViewerSession = {
...session,
focused: false,
safeResourceURL: safeResourceURL,
t4cToken: t4cToken,
reloadToResize: false,
fullscreen: false,
disabled: false,
Expand Down Expand Up @@ -218,6 +224,7 @@ export class SessionViewerService {

export type ViewerSession = Session & {
safeResourceURL?: SafeResourceUrl;
t4cToken?: string;
focused: boolean;
reloadToResize: boolean;
fullscreen: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const mockPersistentViewerSession: ViewerSession = {
reloadToResize: false,
fullscreen: false,
disabled: false,
t4cToken: 'token',
};

const mockReadOnlyViewerSession: ViewerSession = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,22 @@
</div>

<div class="flex items-center gap-2">
@if (session.t4cToken) {
<button
class="m-0 flex items-center"
matTooltip="Copy TeamForCapella token"
[cdkCopyToClipboard]="session.t4cToken"
(click)="
toastService.showSuccess(
'T4C Token copied',
'The T4C Token was copied to your clipboard.'
)
"
>
<mat-icon>key</mat-icon>
</button>
}

<div class="flex items-center gap-1">
@if (session.index !== 0) {
<button class="m-0" (click)="onLeftArrowClick(session)">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,29 @@
* SPDX-FileCopyrightText: Copyright DB InfraGO AG and contributors
* SPDX-License-Identifier: Apache-2.0
*/
import { CdkCopyToClipboard } from '@angular/cdk/clipboard';
import { AsyncPipe, NgClass } from '@angular/common';
import { Component, HostListener, OnInit } from '@angular/core';
import { MatIcon } from '@angular/material/icon';
import { MatTooltip } from '@angular/material/tooltip';
import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy';
import { filter } from 'rxjs';
import { ToastService } from '../../../helpers/toast/toast.service';
import { SessionIFrameComponent } from '../session-iframe/session-iframe.component';
import { SessionViewerService, ViewerSession } from '../session-viewer.service';

@Component({
selector: 'app-tiling-window-manager',
templateUrl: './tiling-window-manager.component.html',
standalone: true,
imports: [MatIcon, SessionIFrameComponent, NgClass, AsyncPipe],
imports: [
MatIcon,
SessionIFrameComponent,
NgClass,
AsyncPipe,
MatTooltip,
CdkCopyToClipboard,
],
})
@UntilDestroy()
export class TilingWindowManagerComponent implements OnInit {
Expand All @@ -28,7 +38,10 @@ export class TilingWindowManagerComponent implements OnInit {

private minimumSessionWidth = 0;

constructor(public sessionViewerService: SessionViewerService) {}
constructor(
public sessionViewerService: SessionViewerService,
public toastService: ToastService,
) {}

ngOnInit(): void {
this.sessionViewerService.sessions$
Expand Down

0 comments on commit 39d0574

Please sign in to comment.