import { Component, inject, OnDestroy } from '@angular/core';
import { FormBuilder, FormsModule, ReactiveFormsModule } from '@angular/forms';
import { MatButton } from '@angular/material/button';
import { MatFormField, MatLabel } from '@angular/material/form-field';
import { MatInput } from '@angular/material/input';
import { MatSnackBar } from '@angular/material/snack-bar';
import { CobblerApiService, BackgroundImportOptions } from 'cobbler-api';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { UserService } from '../../services/user.service';
import Utils from '../../utils';
@Component({
selector: 'cobbler-import-dvd',
templateUrl: './import-dvd.component.html',
styleUrls: ['./import-dvd.component.scss'],
imports: [
FormsModule,
MatFormField,
MatInput,
MatLabel,
ReactiveFormsModule,
MatButton,
],
})
export class ImportDVDComponent implements OnDestroy {
userService = inject(UserService);
private cobblerApiService = inject(CobblerApiService);
private _snackBar = inject(MatSnackBar);
// Unsubscribe
private ngUnsubscribe = new Subject<void>();
// Form
private readonly _formBuilder = inject(FormBuilder);
importFormGroup = this._formBuilder.group({
path: '',
name: '',
available_as: '',
autoinstall_file: '',
rsync_flags: '',
arch: '',
breed: '',
os_version: '',
});
ngOnDestroy(): void {
this.ngUnsubscribe.next();
this.ngUnsubscribe.complete();
}
runImport(): void {
const importOptions: BackgroundImportOptions = {
path: this.importFormGroup.controls.path.value,
name: this.importFormGroup.controls.name.value,
available_as: this.importFormGroup.controls.available_as.value,
autoinstall_file: this.importFormGroup.controls.autoinstall_file.value,
rsync_flags: this.importFormGroup.controls.rsync_flags.value,
arch: this.importFormGroup.controls.arch.value,
breed: this.importFormGroup.controls.breed.value,
os_version: this.importFormGroup.controls.os_version.value,
};
if (this.importFormGroup.invalid) {
this._snackBar.open(
$localize`:@@validation.system-name-required:Please give all inputs a system name!`,
$localize`:@@snackbar.action.close:Close`,
{ duration: 2000 },
);
return;
}
this.cobblerApiService
.background_import(importOptions, this.userService.token)
.pipe(takeUntil(this.ngUnsubscribe))
.subscribe(
(value) => {
// TODO
},
(error) => {
// HTML encode the error message since it originates from XML
this._snackBar.open(
Utils.toHTML(error.message),
$localize`:@@snackbar.action.close:Close`,
);
},
);
}
}
<h1 class="title" i18n="@@action.import-dvd.title">IMPORT DVD</h1>
<form class="form-replicate" [formGroup]="importFormGroup">
<mat-form-field class="form-field-full-width">
<mat-label i18n="@@action.import-dvd.label.path">Path</mat-label>
<input
matInput
type="text"
required
formControlName="path"
placeholder="/mnt/cobbler-mounted/leap-15-4/"
/>
</mat-form-field>
<mat-form-field class="form-field-full-width">
<mat-label i18n="@@action.import-dvd.label.name">Name</mat-label>
<input
matInput
type="text"
required
formControlName="name"
placeholder="my-distro"
/>
</mat-form-field>
<mat-form-field class="form-field-full-width">
<mat-label i18n="@@action.import-dvd.label.available-as"
>Available as</mat-label
>
<input
matInput
type="text"
formControlName="available_as"
placeholder="my-distro"
/>
</mat-form-field>
<mat-form-field class="form-field-full-width">
<mat-label i18n="@@action.import-dvd.label.autoinstall-file"
>Autoinstallation file</mat-label
>
<input
matInput
type="text"
formControlName="autoinstall_file"
placeholder="autoyast.xml"
/>
</mat-form-field>
<mat-form-field class="form-field-full-width">
<mat-label i18n="@@action.import-dvd.label.rsync-flags"
>rsync flags</mat-label
>
<input
matInput
type="text"
formControlName="rsync_flags"
placeholder="-v"
/>
</mat-form-field>
<mat-form-field class="form-field-full-width">
<mat-label i18n="@@action.import-dvd.label.architecture"
>Architecture</mat-label
>
<input matInput type="text" formControlName="arch" placeholder="x86_64" />
</mat-form-field>
<mat-form-field class="form-field-full-width">
<mat-label i18n="@@action.import-dvd.label.os-breed"
>Operating System Breed</mat-label
>
<input matInput type="text" formControlName="breed" placeholder="suse" />
</mat-form-field>
<mat-form-field class="form-field-full-width">
<mat-label i18n="@@action.import-dvd.label.os-version"
>Operating System Version</mat-label
>
<input
matInput
type="text"
formControlName="os_version"
placeholder="15.4"
/>
</mat-form-field>
<button mat-button (click)="runImport()" i18n="@@button.run">Run</button>
</form>