import { Component, inject, signal } from '@angular/core'; import { CommonModule } from '@angular/common'; import { FormsModule } from '@angular/forms'; import { Router } from '@angular/router'; import { ApiService } from '../../core/services/api.service'; interface EnvVar { key: string; value: string; } @Component({ selector: 'app-service-create', standalone: true, imports: [CommonModule, FormsModule], template: `

Deploy New Service

Lowercase letters, numbers, and hyphens only

Format: image:tag or registry/image:tag

Port that your application listens on

Leave empty to skip automatic DNS & SSL

@for (env of envVars(); track $index) {
}
@if (error()) {

{{ error() }}

}
`, }) export class ServiceCreateComponent { private apiService = inject(ApiService); private router = inject(Router); name = ''; image = ''; port = 80; domain = ''; autoDNS = true; autoSSL = true; envVars = signal([]); loading = signal(false); error = signal(''); addEnvVar(): void { this.envVars.update((vars) => [...vars, { key: '', value: '' }]); } removeEnvVar(index: number): void { this.envVars.update((vars) => vars.filter((_, i) => i !== index)); } onSubmit(): void { this.error.set(''); this.loading.set(true); // Convert env vars to object const envVarsObj: Record = {}; for (const env of this.envVars()) { if (env.key && env.value) { envVarsObj[env.key] = env.value; } } const data = { name: this.name, image: this.image, port: this.port, domain: this.domain || undefined, envVars: envVarsObj, autoDNS: this.autoDNS, autoSSL: this.autoSSL, }; this.apiService.createService(data).subscribe({ next: (response) => { this.loading.set(false); if (response.success) { this.router.navigate(['/services']); } else { this.error.set(response.error || 'Failed to deploy service'); } }, error: (err) => { this.loading.set(false); this.error.set(err.error?.error || 'An error occurred'); }, }); } cancel(): void { this.router.navigate(['/services']); } }