More webapp changes+fixes
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { Component, inject, signal, OnInit } from '@angular/core';
|
||||
import { Component, inject, signal, OnInit, computed } from '@angular/core';
|
||||
import { CommonModule, DatePipe } from '@angular/common';
|
||||
import { ActivatedRoute, Router, RouterLink } from '@angular/router';
|
||||
import { NzCardModule } from 'ng-zorro-antd/card';
|
||||
@@ -6,10 +6,15 @@ import { NzButtonModule } from 'ng-zorro-antd/button';
|
||||
import { NzIconModule } from 'ng-zorro-antd/icon';
|
||||
import { NzTagModule } from 'ng-zorro-antd/tag';
|
||||
import { NzSpinModule } from 'ng-zorro-antd/spin';
|
||||
import { NzPopconfirmModule } from 'ng-zorro-antd/popconfirm';
|
||||
import { NzTableModule } from 'ng-zorro-antd/table';
|
||||
import { ApiService } from '../../../core/services/api.service';
|
||||
import { AuthService } from '../../../core/services/auth.service';
|
||||
import { NotificationService } from '../../../core/services/notification.service';
|
||||
import { SettingsService } from '../../../core/services/settings.service';
|
||||
import { KeyCacheService, ResolvedKey } from '../../../core/services/key-cache.service';
|
||||
import { Message } from '../../../core/models';
|
||||
import { UserCacheService, ResolvedUser } from '../../../core/services/user-cache.service';
|
||||
import { Message, Delivery } from '../../../core/models';
|
||||
import { RelativeTimePipe } from '../../../shared/pipes/relative-time.pipe';
|
||||
import { MetadataGridComponent, MetadataValueComponent } from '../../../shared/components/metadata-grid';
|
||||
|
||||
@@ -24,6 +29,8 @@ import { MetadataGridComponent, MetadataValueComponent } from '../../../shared/c
|
||||
NzIconModule,
|
||||
NzTagModule,
|
||||
NzSpinModule,
|
||||
NzPopconfirmModule,
|
||||
NzTableModule,
|
||||
RouterLink,
|
||||
RelativeTimePipe,
|
||||
MetadataGridComponent,
|
||||
@@ -36,13 +43,28 @@ export class MessageDetailComponent implements OnInit {
|
||||
private route = inject(ActivatedRoute);
|
||||
private router = inject(Router);
|
||||
private apiService = inject(ApiService);
|
||||
private authService = inject(AuthService);
|
||||
private notification = inject(NotificationService);
|
||||
private settingsService = inject(SettingsService);
|
||||
private keyCacheService = inject(KeyCacheService);
|
||||
private userCacheService = inject(UserCacheService);
|
||||
|
||||
message = signal<Message | null>(null);
|
||||
resolvedKey = signal<ResolvedKey | null>(null);
|
||||
resolvedChannelOwner = signal<ResolvedUser | null>(null);
|
||||
deliveries = signal<Delivery[]>([]);
|
||||
loading = signal(true);
|
||||
deleting = signal(false);
|
||||
loadingDeliveries = signal(false);
|
||||
expertMode = this.settingsService.expertMode;
|
||||
|
||||
isChannelOwner = computed(() => {
|
||||
const msg = this.message();
|
||||
const userId = this.authService.getUserId();
|
||||
return msg !== null && userId !== null && msg.channel_owner_user_id === userId;
|
||||
});
|
||||
|
||||
showDeliveries = computed(() => this.expertMode() && this.isChannelOwner());
|
||||
|
||||
ngOnInit(): void {
|
||||
const messageId = this.route.snapshot.paramMap.get('id');
|
||||
@@ -58,6 +80,8 @@ export class MessageDetailComponent implements OnInit {
|
||||
this.message.set(message);
|
||||
this.loading.set(false);
|
||||
this.resolveKey(message.used_key_id);
|
||||
this.resolveChannelOwner(message.channel_owner_user_id);
|
||||
this.loadDeliveries(messageId);
|
||||
},
|
||||
error: () => {
|
||||
this.loading.set(false);
|
||||
@@ -65,12 +89,34 @@ export class MessageDetailComponent implements OnInit {
|
||||
});
|
||||
}
|
||||
|
||||
private loadDeliveries(messageId: string): void {
|
||||
if (!this.showDeliveries()) {
|
||||
return;
|
||||
}
|
||||
this.loadingDeliveries.set(true);
|
||||
this.apiService.getDeliveries(messageId).subscribe({
|
||||
next: (response) => {
|
||||
this.deliveries.set(response.deliveries);
|
||||
this.loadingDeliveries.set(false);
|
||||
},
|
||||
error: () => {
|
||||
this.loadingDeliveries.set(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private resolveKey(keyId: string): void {
|
||||
this.keyCacheService.resolveKey(keyId).subscribe({
|
||||
next: (resolved) => this.resolvedKey.set(resolved)
|
||||
});
|
||||
}
|
||||
|
||||
private resolveChannelOwner(userId: string): void {
|
||||
this.userCacheService.resolveUser(userId).subscribe({
|
||||
next: (resolved) => this.resolvedChannelOwner.set(resolved)
|
||||
});
|
||||
}
|
||||
|
||||
goBack(): void {
|
||||
this.router.navigate(['/messages']);
|
||||
}
|
||||
@@ -108,4 +154,13 @@ export class MessageDetailComponent implements OnInit {
|
||||
default: return 'default';
|
||||
}
|
||||
}
|
||||
|
||||
getStatusColor(status: string): string {
|
||||
switch (status) {
|
||||
case 'SUCCESS': return 'green';
|
||||
case 'FAILED': return 'red';
|
||||
case 'RETRY': return 'orange';
|
||||
default: return 'default';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user