2025-01-15 20:19:44 +00:00
|
|
|
import { Component, inject, OnDestroy, OnInit } from '@angular/core';
|
2024-10-17 08:48:15 +00:00
|
|
|
import { FormsModule } from '@angular/forms';
|
|
|
|
import { MatInputModule } from '@angular/material/input';
|
|
|
|
import { MatSelectModule } from '@angular/material/select';
|
|
|
|
import { MatFormFieldModule } from '@angular/material/form-field';
|
|
|
|
import { MatButtonModule } from '@angular/material/button';
|
2025-01-07 17:56:11 +00:00
|
|
|
import EventService from '../../shared/services/EventService';
|
2025-03-20 12:33:27 +00:00
|
|
|
import { ActivatedRoute } from '@angular/router';
|
2025-01-15 20:19:44 +00:00
|
|
|
import { first, Subscription, timeout } from 'rxjs';
|
2025-01-07 17:56:11 +00:00
|
|
|
import { HermesClientService } from '../../hermes-client.service';
|
2025-01-15 20:19:44 +00:00
|
|
|
import { MatCardModule } from '@angular/material/card';
|
|
|
|
import { ApiKeyService } from '../../shared/services/api/api-key.service';
|
2024-10-17 08:48:15 +00:00
|
|
|
|
|
|
|
@Component({
|
2025-01-08 21:50:18 +00:00
|
|
|
selector: 'tts-login',
|
|
|
|
standalone: true,
|
|
|
|
imports: [MatButtonModule, MatCardModule, MatFormFieldModule, MatSelectModule, MatInputModule, FormsModule],
|
|
|
|
templateUrl: './tts-login.component.html',
|
|
|
|
styleUrl: './tts-login.component.scss'
|
2024-10-17 08:48:15 +00:00
|
|
|
})
|
|
|
|
export class TtsLoginComponent implements OnInit, OnDestroy {
|
2025-03-20 12:33:27 +00:00
|
|
|
private readonly client = inject(HermesClientService);
|
|
|
|
private readonly keyService = inject(ApiKeyService);
|
|
|
|
private readonly events = inject(EventService);
|
|
|
|
private readonly route = inject(ActivatedRoute);
|
2025-01-15 20:19:44 +00:00
|
|
|
|
|
|
|
api_keys: { id: string, label: string }[] = [];
|
2025-01-08 21:50:18 +00:00
|
|
|
selected_api_key: string | undefined;
|
2024-10-17 08:48:15 +00:00
|
|
|
|
2025-01-15 20:19:44 +00:00
|
|
|
private subscriptions: Subscription[] = [];
|
2024-10-17 08:48:15 +00:00
|
|
|
|
|
|
|
|
2025-01-08 21:50:18 +00:00
|
|
|
ngOnInit(): void {
|
2025-01-15 20:19:44 +00:00
|
|
|
this.route.data.subscribe(d => this.api_keys = d['keys']);
|
2024-10-17 08:48:15 +00:00
|
|
|
|
2025-01-15 20:19:44 +00:00
|
|
|
this.subscriptions.push(this.events.listen('tts_logoff', async _ => {
|
2025-01-08 21:50:18 +00:00
|
|
|
this.selected_api_key = undefined;
|
2025-01-15 20:19:44 +00:00
|
|
|
}));
|
|
|
|
this.subscriptions.push(this.events.listen('impersonation', _ => {
|
2025-01-08 21:50:18 +00:00
|
|
|
this.selected_api_key = undefined;
|
2024-10-31 05:33:11 +00:00
|
|
|
|
2025-01-15 20:19:44 +00:00
|
|
|
this.keyService.fetch(true)
|
|
|
|
.pipe(timeout(3000), first())
|
|
|
|
.subscribe(d => this.api_keys = d);
|
|
|
|
}));
|
2025-01-08 21:50:18 +00:00
|
|
|
}
|
2024-10-17 08:48:15 +00:00
|
|
|
|
2025-01-08 21:50:18 +00:00
|
|
|
ngOnDestroy(): void {
|
2025-01-15 20:45:26 +00:00
|
|
|
this.subscriptions.forEach(s => s.unsubscribe());
|
2025-01-08 21:50:18 +00:00
|
|
|
}
|
2024-10-17 08:48:15 +00:00
|
|
|
|
2025-03-20 12:33:27 +00:00
|
|
|
login(): void {
|
2025-01-08 21:50:18 +00:00
|
|
|
if (!this.selected_api_key)
|
|
|
|
return;
|
2024-10-17 08:48:15 +00:00
|
|
|
|
2025-03-20 12:33:27 +00:00
|
|
|
this.client.login(this.selected_api_key);
|
2025-01-08 21:50:18 +00:00
|
|
|
}
|
2024-10-17 08:48:15 +00:00
|
|
|
}
|