Simple Managment webapp [LLM]
This commit is contained in:
@@ -0,0 +1,143 @@
|
||||
import { Component, inject, signal, OnInit } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { Router } from '@angular/router';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
import { NzTableModule } from 'ng-zorro-antd/table';
|
||||
import { NzButtonModule } from 'ng-zorro-antd/button';
|
||||
import { NzIconModule } from 'ng-zorro-antd/icon';
|
||||
import { NzTagModule } from 'ng-zorro-antd/tag';
|
||||
import { NzBadgeModule } from 'ng-zorro-antd/badge';
|
||||
import { NzEmptyModule } from 'ng-zorro-antd/empty';
|
||||
import { NzCardModule } from 'ng-zorro-antd/card';
|
||||
import { NzRadioModule } from 'ng-zorro-antd/radio';
|
||||
import { NzModalModule, NzModalService } from 'ng-zorro-antd/modal';
|
||||
import { NzFormModule } from 'ng-zorro-antd/form';
|
||||
import { NzInputModule } from 'ng-zorro-antd/input';
|
||||
import { NzCheckboxModule } from 'ng-zorro-antd/checkbox';
|
||||
import { NzToolTipModule } from 'ng-zorro-antd/tooltip';
|
||||
import { ApiService } from '../../../core/services/api.service';
|
||||
import { AuthService } from '../../../core/services/auth.service';
|
||||
import { NotificationService } from '../../../core/services/notification.service';
|
||||
import { ChannelWithSubscription, ChannelSelector } from '../../../core/models';
|
||||
import { RelativeTimePipe } from '../../../shared/pipes/relative-time.pipe';
|
||||
|
||||
@Component({
|
||||
selector: 'app-channel-list',
|
||||
standalone: true,
|
||||
imports: [
|
||||
CommonModule,
|
||||
FormsModule,
|
||||
NzTableModule,
|
||||
NzButtonModule,
|
||||
NzIconModule,
|
||||
NzTagModule,
|
||||
NzBadgeModule,
|
||||
NzEmptyModule,
|
||||
NzCardModule,
|
||||
NzRadioModule,
|
||||
NzModalModule,
|
||||
NzFormModule,
|
||||
NzInputModule,
|
||||
NzCheckboxModule,
|
||||
NzToolTipModule,
|
||||
RelativeTimePipe,
|
||||
],
|
||||
templateUrl: './channel-list.component.html',
|
||||
styleUrl: './channel-list.component.scss'
|
||||
})
|
||||
export class ChannelListComponent implements OnInit {
|
||||
private apiService = inject(ApiService);
|
||||
private authService = inject(AuthService);
|
||||
private notification = inject(NotificationService);
|
||||
private modal = inject(NzModalService);
|
||||
private router = inject(Router);
|
||||
|
||||
channels = signal<ChannelWithSubscription[]>([]);
|
||||
loading = signal(false);
|
||||
selector: ChannelSelector = 'all';
|
||||
|
||||
// Create channel modal
|
||||
showCreateModal = signal(false);
|
||||
newChannelName = '';
|
||||
newChannelSubscribe = true;
|
||||
creating = signal(false);
|
||||
|
||||
ngOnInit(): void {
|
||||
this.loadChannels();
|
||||
}
|
||||
|
||||
loadChannels(): void {
|
||||
const userId = this.authService.getUserId();
|
||||
if (!userId) return;
|
||||
|
||||
this.loading.set(true);
|
||||
this.apiService.getChannels(userId, this.selector).subscribe({
|
||||
next: (response) => {
|
||||
this.channels.set(response.channels);
|
||||
this.loading.set(false);
|
||||
},
|
||||
error: () => {
|
||||
this.loading.set(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
onSelectorChange(): void {
|
||||
this.loadChannels();
|
||||
}
|
||||
|
||||
viewChannel(channel: ChannelWithSubscription): void {
|
||||
this.router.navigate(['/channels', channel.channel_id]);
|
||||
}
|
||||
|
||||
openCreateModal(): void {
|
||||
this.newChannelName = '';
|
||||
this.newChannelSubscribe = true;
|
||||
this.showCreateModal.set(true);
|
||||
}
|
||||
|
||||
closeCreateModal(): void {
|
||||
this.showCreateModal.set(false);
|
||||
}
|
||||
|
||||
createChannel(): void {
|
||||
const userId = this.authService.getUserId();
|
||||
if (!userId || !this.newChannelName.trim()) return;
|
||||
|
||||
this.creating.set(true);
|
||||
this.apiService.createChannel(userId, {
|
||||
name: this.newChannelName.trim(),
|
||||
subscribe: this.newChannelSubscribe
|
||||
}).subscribe({
|
||||
next: (channel) => {
|
||||
this.notification.success('Channel created successfully');
|
||||
this.closeCreateModal();
|
||||
this.creating.set(false);
|
||||
this.loadChannels();
|
||||
},
|
||||
error: () => {
|
||||
this.creating.set(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
getSubscriptionStatus(channel: ChannelWithSubscription): { label: string; color: string } {
|
||||
const userId = this.authService.getUserId();
|
||||
|
||||
if (channel.owner_user_id === userId) {
|
||||
if (channel.subscription) {
|
||||
return { label: 'Owned & Subscribed', color: 'green' };
|
||||
}
|
||||
return { label: 'Owned', color: 'blue' };
|
||||
}
|
||||
|
||||
if (channel.subscription) {
|
||||
if (channel.subscription.confirmed) {
|
||||
return { label: 'Subscribed', color: 'green' };
|
||||
}
|
||||
return { label: 'Pending', color: 'orange' };
|
||||
}
|
||||
|
||||
return { label: 'Not Subscribed', color: 'default' };
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user