Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Allow users to copy t4c token from session viewer #2040

Merged
merged 1 commit into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Loading