mcp
This commit is contained in:
@@ -1,11 +1,9 @@
|
||||
import { Component, DestroyRef, inject, signal } from '@angular/core';
|
||||
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
||||
import { Component, inject } from '@angular/core';
|
||||
import { Router } from '@angular/router';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { MatCardModule } from '@angular/material/card';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
|
||||
import { finalize } from 'rxjs';
|
||||
import { AuthService } from '../auth/auth.service';
|
||||
import { OnboardingService } from '../onboarding/onboarding.service';
|
||||
|
||||
@@ -18,107 +16,14 @@ import { OnboardingService } from '../onboarding/onboarding.service';
|
||||
export class AccountComponent {
|
||||
protected readonly auth = inject(AuthService);
|
||||
protected readonly onboarding = inject(OnboardingService);
|
||||
protected readonly mcpApiKeyCreatedAt = signal<string | null>(null);
|
||||
protected readonly generatedMcpApiKey = signal<string | null>(null);
|
||||
protected readonly mcpApiKeyLoading = signal(false);
|
||||
protected readonly mcpApiKeySaving = signal(false);
|
||||
protected readonly mcpApiKeyMessage = signal<string | null>(null);
|
||||
private readonly destroyRef = inject(DestroyRef);
|
||||
private readonly router = inject(Router);
|
||||
|
||||
constructor() {
|
||||
this.loadMcpApiKeyStatus();
|
||||
}
|
||||
|
||||
resetOnboarding(): void {
|
||||
this.onboarding.resetForCurrentUser();
|
||||
}
|
||||
|
||||
createMcpApiKey(): void {
|
||||
this.mcpApiKeySaving.set(true);
|
||||
this.mcpApiKeyMessage.set(null);
|
||||
this.generatedMcpApiKey.set(null);
|
||||
|
||||
this.auth
|
||||
.createMcpApiKey()
|
||||
.pipe(
|
||||
takeUntilDestroyed(this.destroyRef),
|
||||
finalize(() => this.mcpApiKeySaving.set(false)),
|
||||
)
|
||||
.subscribe({
|
||||
next: (response) => {
|
||||
this.mcpApiKeyCreatedAt.set(response.createdAt ?? null);
|
||||
this.generatedMcpApiKey.set(response.apiKey);
|
||||
this.mcpApiKeyMessage.set('MCP-Key wurde erzeugt.');
|
||||
},
|
||||
error: () => {
|
||||
this.mcpApiKeyMessage.set('MCP-Key konnte nicht erzeugt werden.');
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
revokeMcpApiKey(): void {
|
||||
this.mcpApiKeySaving.set(true);
|
||||
this.mcpApiKeyMessage.set(null);
|
||||
this.generatedMcpApiKey.set(null);
|
||||
|
||||
this.auth
|
||||
.revokeMcpApiKey()
|
||||
.pipe(
|
||||
takeUntilDestroyed(this.destroyRef),
|
||||
finalize(() => this.mcpApiKeySaving.set(false)),
|
||||
)
|
||||
.subscribe({
|
||||
next: () => {
|
||||
this.mcpApiKeyCreatedAt.set(null);
|
||||
this.mcpApiKeyMessage.set('MCP-Key wurde widerrufen.');
|
||||
},
|
||||
error: () => {
|
||||
this.mcpApiKeyMessage.set('MCP-Key konnte nicht widerrufen werden.');
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
copyMcpApiKey(): void {
|
||||
const apiKey = this.generatedMcpApiKey();
|
||||
|
||||
if (!apiKey || typeof navigator === 'undefined' || !navigator.clipboard) {
|
||||
return;
|
||||
}
|
||||
|
||||
void navigator.clipboard.writeText(apiKey).then(() => {
|
||||
this.mcpApiKeyMessage.set('MCP-Key wurde kopiert.');
|
||||
});
|
||||
}
|
||||
|
||||
logout(): void {
|
||||
this.auth.logout();
|
||||
void this.router.navigateByUrl('/login');
|
||||
}
|
||||
|
||||
protected formatDate(value: string): string {
|
||||
return new Date(value).toLocaleString('de-DE', {
|
||||
dateStyle: 'medium',
|
||||
timeStyle: 'short',
|
||||
});
|
||||
}
|
||||
|
||||
private loadMcpApiKeyStatus(): void {
|
||||
this.mcpApiKeyLoading.set(true);
|
||||
|
||||
this.auth
|
||||
.getMcpApiKeyStatus()
|
||||
.pipe(
|
||||
takeUntilDestroyed(this.destroyRef),
|
||||
finalize(() => this.mcpApiKeyLoading.set(false)),
|
||||
)
|
||||
.subscribe({
|
||||
next: (status) => {
|
||||
this.mcpApiKeyCreatedAt.set(status.createdAt ?? null);
|
||||
},
|
||||
error: () => {
|
||||
this.mcpApiKeyMessage.set('MCP-Key-Status konnte nicht geladen werden.');
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user