2025-11-24 19:52:35 +00:00
|
|
|
import { Component, inject, signal, OnInit } from '@angular/core';
|
2025-11-18 00:03:24 +00:00
|
|
|
import { FormsModule } from '@angular/forms';
|
2025-11-24 19:52:35 +00:00
|
|
|
import { ApiService } from '../../core/services/api.service';
|
|
|
|
|
import { ToastService } from '../../core/services/toast.service';
|
|
|
|
|
import { IRegistry, IRegistryCreate } from '../../core/types/api.types';
|
|
|
|
|
import {
|
|
|
|
|
CardComponent,
|
|
|
|
|
CardHeaderComponent,
|
|
|
|
|
CardTitleComponent,
|
|
|
|
|
CardDescriptionComponent,
|
|
|
|
|
CardContentComponent,
|
|
|
|
|
} from '../../ui/card/card.component';
|
|
|
|
|
import { ButtonComponent } from '../../ui/button/button.component';
|
|
|
|
|
import { InputComponent } from '../../ui/input/input.component';
|
|
|
|
|
import { LabelComponent } from '../../ui/label/label.component';
|
|
|
|
|
import {
|
|
|
|
|
TableComponent,
|
|
|
|
|
TableHeaderComponent,
|
|
|
|
|
TableBodyComponent,
|
|
|
|
|
TableRowComponent,
|
|
|
|
|
TableHeadComponent,
|
|
|
|
|
TableCellComponent,
|
|
|
|
|
} from '../../ui/table/table.component';
|
|
|
|
|
import { SkeletonComponent } from '../../ui/skeleton/skeleton.component';
|
|
|
|
|
import {
|
|
|
|
|
DialogComponent,
|
|
|
|
|
DialogHeaderComponent,
|
|
|
|
|
DialogTitleComponent,
|
|
|
|
|
DialogDescriptionComponent,
|
|
|
|
|
DialogFooterComponent,
|
|
|
|
|
} from '../../ui/dialog/dialog.component';
|
2025-11-18 00:03:24 +00:00
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'app-registries',
|
|
|
|
|
standalone: true,
|
2025-11-24 19:52:35 +00:00
|
|
|
imports: [
|
|
|
|
|
FormsModule,
|
|
|
|
|
CardComponent,
|
|
|
|
|
CardHeaderComponent,
|
|
|
|
|
CardTitleComponent,
|
|
|
|
|
CardDescriptionComponent,
|
|
|
|
|
CardContentComponent,
|
|
|
|
|
ButtonComponent,
|
|
|
|
|
InputComponent,
|
|
|
|
|
LabelComponent,
|
|
|
|
|
TableComponent,
|
|
|
|
|
TableHeaderComponent,
|
|
|
|
|
TableBodyComponent,
|
|
|
|
|
TableRowComponent,
|
|
|
|
|
TableHeadComponent,
|
|
|
|
|
TableCellComponent,
|
|
|
|
|
SkeletonComponent,
|
|
|
|
|
DialogComponent,
|
|
|
|
|
DialogHeaderComponent,
|
|
|
|
|
DialogTitleComponent,
|
|
|
|
|
DialogDescriptionComponent,
|
|
|
|
|
DialogFooterComponent,
|
|
|
|
|
],
|
2025-11-18 00:03:24 +00:00
|
|
|
template: `
|
2025-11-24 19:52:35 +00:00
|
|
|
<div class="space-y-6">
|
|
|
|
|
<div>
|
|
|
|
|
<h1 class="text-3xl font-bold tracking-tight">Docker Registries</h1>
|
|
|
|
|
<p class="text-muted-foreground">Manage Docker registry credentials</p>
|
|
|
|
|
</div>
|
2025-11-18 00:03:24 +00:00
|
|
|
|
|
|
|
|
<!-- Add Registry Form -->
|
2025-11-24 19:52:35 +00:00
|
|
|
<ui-card>
|
|
|
|
|
<ui-card-header class="flex flex-col space-y-1.5">
|
|
|
|
|
<ui-card-title>Add Registry</ui-card-title>
|
|
|
|
|
<ui-card-description>Add credentials for a private Docker registry</ui-card-description>
|
|
|
|
|
</ui-card-header>
|
|
|
|
|
<ui-card-content>
|
|
|
|
|
<form (ngSubmit)="addRegistry()" class="grid gap-4 md:grid-cols-4">
|
|
|
|
|
<div class="space-y-2">
|
|
|
|
|
<label uiLabel>Registry URL</label>
|
|
|
|
|
<input uiInput [(ngModel)]="form.url" name="url" placeholder="registry.example.com" required />
|
|
|
|
|
</div>
|
|
|
|
|
<div class="space-y-2">
|
|
|
|
|
<label uiLabel>Username</label>
|
|
|
|
|
<input uiInput [(ngModel)]="form.username" name="username" required />
|
|
|
|
|
</div>
|
|
|
|
|
<div class="space-y-2">
|
|
|
|
|
<label uiLabel>Password</label>
|
|
|
|
|
<input uiInput type="password" [(ngModel)]="form.password" name="password" required />
|
|
|
|
|
</div>
|
|
|
|
|
<div class="flex items-end">
|
|
|
|
|
<button uiButton type="submit" [disabled]="loading()">Add Registry</button>
|
|
|
|
|
</div>
|
|
|
|
|
</form>
|
|
|
|
|
</ui-card-content>
|
|
|
|
|
</ui-card>
|
2025-11-18 00:03:24 +00:00
|
|
|
|
|
|
|
|
<!-- Registries List -->
|
2025-11-24 19:52:35 +00:00
|
|
|
<ui-card>
|
|
|
|
|
<ui-card-header class="flex flex-col space-y-1.5">
|
|
|
|
|
<ui-card-title>Registered Registries</ui-card-title>
|
|
|
|
|
</ui-card-header>
|
|
|
|
|
<ui-card-content class="p-0">
|
|
|
|
|
@if (loading() && registries().length === 0) {
|
|
|
|
|
<div class="p-6 space-y-4">
|
|
|
|
|
@for (_ of [1,2]; track $index) {
|
|
|
|
|
<ui-skeleton class="h-12 w-full" />
|
2025-11-18 00:03:24 +00:00
|
|
|
}
|
2025-11-24 19:52:35 +00:00
|
|
|
</div>
|
|
|
|
|
} @else if (registries().length === 0) {
|
|
|
|
|
<div class="p-12 text-center">
|
|
|
|
|
<p class="text-muted-foreground">No registries configured</p>
|
|
|
|
|
</div>
|
|
|
|
|
} @else {
|
|
|
|
|
<ui-table>
|
|
|
|
|
<ui-table-header>
|
|
|
|
|
<ui-table-row>
|
|
|
|
|
<ui-table-head>URL</ui-table-head>
|
|
|
|
|
<ui-table-head>Username</ui-table-head>
|
|
|
|
|
<ui-table-head>Created</ui-table-head>
|
|
|
|
|
<ui-table-head class="text-right">Actions</ui-table-head>
|
|
|
|
|
</ui-table-row>
|
|
|
|
|
</ui-table-header>
|
|
|
|
|
<ui-table-body>
|
|
|
|
|
@for (registry of registries(); track registry.id) {
|
|
|
|
|
<ui-table-row>
|
|
|
|
|
<ui-table-cell class="font-medium">{{ registry.url }}</ui-table-cell>
|
|
|
|
|
<ui-table-cell>{{ registry.username }}</ui-table-cell>
|
|
|
|
|
<ui-table-cell>{{ formatDate(registry.createdAt) }}</ui-table-cell>
|
|
|
|
|
<ui-table-cell class="text-right">
|
|
|
|
|
<button uiButton variant="destructive" size="sm" (click)="confirmDelete(registry)">
|
|
|
|
|
Delete
|
|
|
|
|
</button>
|
|
|
|
|
</ui-table-cell>
|
|
|
|
|
</ui-table-row>
|
|
|
|
|
}
|
|
|
|
|
</ui-table-body>
|
|
|
|
|
</ui-table>
|
|
|
|
|
}
|
|
|
|
|
</ui-card-content>
|
|
|
|
|
</ui-card>
|
2025-11-18 00:03:24 +00:00
|
|
|
</div>
|
2025-11-24 19:52:35 +00:00
|
|
|
|
|
|
|
|
<ui-dialog [open]="deleteDialogOpen()" (openChange)="deleteDialogOpen.set($event)">
|
|
|
|
|
<ui-dialog-header>
|
|
|
|
|
<ui-dialog-title>Delete Registry</ui-dialog-title>
|
|
|
|
|
<ui-dialog-description>
|
|
|
|
|
Are you sure you want to delete "{{ registryToDelete()?.url }}"?
|
|
|
|
|
</ui-dialog-description>
|
|
|
|
|
</ui-dialog-header>
|
|
|
|
|
<ui-dialog-footer>
|
|
|
|
|
<button uiButton variant="outline" (click)="deleteDialogOpen.set(false)">Cancel</button>
|
|
|
|
|
<button uiButton variant="destructive" (click)="deleteRegistry()">Delete</button>
|
|
|
|
|
</ui-dialog-footer>
|
|
|
|
|
</ui-dialog>
|
2025-11-18 00:03:24 +00:00
|
|
|
`,
|
|
|
|
|
})
|
|
|
|
|
export class RegistriesComponent implements OnInit {
|
2025-11-24 19:52:35 +00:00
|
|
|
private api = inject(ApiService);
|
|
|
|
|
private toast = inject(ToastService);
|
|
|
|
|
|
|
|
|
|
registries = signal<IRegistry[]>([]);
|
|
|
|
|
loading = signal(false);
|
|
|
|
|
deleteDialogOpen = signal(false);
|
|
|
|
|
registryToDelete = signal<IRegistry | null>(null);
|
|
|
|
|
|
|
|
|
|
form: IRegistryCreate = { url: '', username: '', password: '' };
|
2025-11-18 00:03:24 +00:00
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
|
|
|
|
this.loadRegistries();
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-24 19:52:35 +00:00
|
|
|
async loadRegistries(): Promise<void> {
|
|
|
|
|
this.loading.set(true);
|
|
|
|
|
try {
|
|
|
|
|
const response = await this.api.getRegistries();
|
|
|
|
|
if (response.success && response.data) {
|
|
|
|
|
this.registries.set(response.data);
|
|
|
|
|
}
|
|
|
|
|
} catch {
|
|
|
|
|
this.toast.error('Failed to load registries');
|
|
|
|
|
} finally {
|
|
|
|
|
this.loading.set(false);
|
|
|
|
|
}
|
2025-11-18 00:03:24 +00:00
|
|
|
}
|
|
|
|
|
|
2025-11-24 19:52:35 +00:00
|
|
|
async addRegistry(): Promise<void> {
|
|
|
|
|
if (!this.form.url || !this.form.username || !this.form.password) {
|
|
|
|
|
this.toast.error('Please fill in all fields');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.loading.set(true);
|
|
|
|
|
try {
|
|
|
|
|
const response = await this.api.createRegistry(this.form);
|
|
|
|
|
if (response.success) {
|
|
|
|
|
this.toast.success('Registry added');
|
|
|
|
|
this.form = { url: '', username: '', password: '' };
|
2025-11-18 00:03:24 +00:00
|
|
|
this.loadRegistries();
|
2025-11-24 19:52:35 +00:00
|
|
|
} else {
|
|
|
|
|
this.toast.error(response.error || 'Failed to add registry');
|
|
|
|
|
}
|
|
|
|
|
} catch {
|
|
|
|
|
this.toast.error('Failed to add registry');
|
|
|
|
|
} finally {
|
|
|
|
|
this.loading.set(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
confirmDelete(registry: IRegistry): void {
|
|
|
|
|
this.registryToDelete.set(registry);
|
|
|
|
|
this.deleteDialogOpen.set(true);
|
2025-11-18 00:03:24 +00:00
|
|
|
}
|
|
|
|
|
|
2025-11-24 19:52:35 +00:00
|
|
|
async deleteRegistry(): Promise<void> {
|
|
|
|
|
const registry = this.registryToDelete();
|
|
|
|
|
if (!registry?.id) return;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const response = await this.api.deleteRegistry(registry.id);
|
|
|
|
|
if (response.success) {
|
|
|
|
|
this.toast.success('Registry deleted');
|
|
|
|
|
this.loadRegistries();
|
|
|
|
|
} else {
|
|
|
|
|
this.toast.error(response.error || 'Failed to delete registry');
|
|
|
|
|
}
|
|
|
|
|
} catch {
|
|
|
|
|
this.toast.error('Failed to delete registry');
|
|
|
|
|
} finally {
|
|
|
|
|
this.deleteDialogOpen.set(false);
|
|
|
|
|
this.registryToDelete.set(null);
|
2025-11-18 00:03:24 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
formatDate(timestamp: number): string {
|
|
|
|
|
return new Date(timestamp).toLocaleDateString();
|
|
|
|
|
}
|
|
|
|
|
}
|