diff --git a/projects/cobbler-api/src/lib/cobbler-api.service.spec.ts b/projects/cobbler-api/src/lib/cobbler-api.service.spec.ts
index b6a0d123..48a656a1 100644
--- a/projects/cobbler-api/src/lib/cobbler-api.service.spec.ts
+++ b/projects/cobbler-api/src/lib/cobbler-api.service.spec.ts
@@ -1,6 +1,6 @@
import {TestBed} from '@angular/core/testing';
import {HttpClientTestingModule, HttpTestingController} from '@angular/common/http/testing';
-import {BackgroundReplicateOptions} from 'cobbler-api';
+import {BackgroundImportOptions, BackgroundReplicateOptions} from 'cobbler-api';
import {Event, ExtendedVersion, InstallationStatus} from './custom-types/misc';
import {COBBLER_URL} from './lib.config';
import {AngularXmlrpcService} from 'typescript-xmlrpc';
@@ -153,9 +153,25 @@ describe('CobblerApiService', () => {
mockRequest.flush(methodResponse);
});
- xit('should execute the background_import action on the Cobbler Server', () => {
- service.background_import(undefined, '');
- expect(service).toBeFalsy();
+ it('should execute the background_import action on the Cobbler Server', () => {
+ // eslint-disable-next-line max-len
+ const methodResponse = `2023-01-24_103639_Media import_dd297121f7bc412e9ce4d80f05de4b3f`
+ const result = "2023-01-24_103639_Media import_dd297121f7bc412e9ce4d80f05de4b3f"
+ const importOptions: BackgroundImportOptions = {
+ path: '',
+ name: '',
+ available_as: '',
+ autoinstall_file: '',
+ rsync_flags: '',
+ arch: '',
+ breed: '',
+ os_version: '',
+ }
+ service.background_import(importOptions, '').subscribe(value => {
+ expect(value).toEqual(result)
+ });
+ const mockRequest = httpTestingController.expectOne('http://localhost/cobbler_api');
+ mockRequest.flush(methodResponse);
});
xit('should execute the background_reposync action on the Cobbler Server', () => {
diff --git a/projects/cobbler-frontend/src/app/actions/import-dvd/import-dvd.component.css b/projects/cobbler-frontend/src/app/actions/import-dvd/import-dvd.component.css
deleted file mode 100644
index e69de29b..00000000
diff --git a/projects/cobbler-frontend/src/app/actions/import-dvd/import-dvd.component.html b/projects/cobbler-frontend/src/app/actions/import-dvd/import-dvd.component.html
index 7803134e..731fc3a0 100644
--- a/projects/cobbler-frontend/src/app/actions/import-dvd/import-dvd.component.html
+++ b/projects/cobbler-frontend/src/app/actions/import-dvd/import-dvd.component.html
@@ -1,13 +1,37 @@
-
-
-
-
IMPORT DVD
-
-
- data 01
- data 02
- data 03
-
-
-
-
+IMPORT DVD
+
+
diff --git a/projects/cobbler-frontend/src/app/actions/import-dvd/import-dvd.component.scss b/projects/cobbler-frontend/src/app/actions/import-dvd/import-dvd.component.scss
new file mode 100644
index 00000000..e6b6c704
--- /dev/null
+++ b/projects/cobbler-frontend/src/app/actions/import-dvd/import-dvd.component.scss
@@ -0,0 +1,9 @@
+.form-replicate {
+ min-width: 150px;
+ max-width: 600px;
+ width: 100%;
+}
+
+.form-field-full-width {
+ width: 100%;
+}
diff --git a/projects/cobbler-frontend/src/app/actions/import-dvd/import-dvd.component.spec.ts b/projects/cobbler-frontend/src/app/actions/import-dvd/import-dvd.component.spec.ts
index e6d6cc6a..f6b286b1 100644
--- a/projects/cobbler-frontend/src/app/actions/import-dvd/import-dvd.component.spec.ts
+++ b/projects/cobbler-frontend/src/app/actions/import-dvd/import-dvd.component.spec.ts
@@ -1,6 +1,13 @@
+import {provideHttpClient} from '@angular/common/http';
+import {provideHttpClientTesting} from '@angular/common/http/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
+import {ReactiveFormsModule} from '@angular/forms';
+import {MatButtonModule} from '@angular/material/button';
+import {MatFormFieldModule} from '@angular/material/form-field';
+import {MatInputModule} from '@angular/material/input';
import { MatListModule } from '@angular/material/list';
-import {provideRouter} from '@angular/router';
+import {NoopAnimationsModule} from '@angular/platform-browser/animations';
+import {COBBLER_URL} from 'cobbler-api';
import { ImportDVDComponent } from './import-dvd.component';
@@ -10,9 +17,21 @@ describe('ImportDVDComponent', () => {
beforeEach(async () => {
await TestBed.configureTestingModule({
- imports: [MatListModule, ImportDVDComponent],
+ imports: [
+ ImportDVDComponent,
+ NoopAnimationsModule,
+ ReactiveFormsModule,
+ MatFormFieldModule,
+ MatInputModule,
+ MatButtonModule,
+ ],
providers: [
- provideRouter([]),
+ provideHttpClient(),
+ provideHttpClientTesting(),
+ {
+ provide: COBBLER_URL,
+ useValue: new URL('http://localhost/cobbler_api')
+ },
]
}).compileComponents();
});
diff --git a/projects/cobbler-frontend/src/app/actions/import-dvd/import-dvd.component.ts b/projects/cobbler-frontend/src/app/actions/import-dvd/import-dvd.component.ts
index 58b45ed9..52b66649 100644
--- a/projects/cobbler-frontend/src/app/actions/import-dvd/import-dvd.component.ts
+++ b/projects/cobbler-frontend/src/app/actions/import-dvd/import-dvd.component.ts
@@ -1,16 +1,73 @@
-import {Component} from '@angular/core';
-import { MatListModule } from '@angular/material/list';
-import { RouterOutlet } from '@angular/router';
+import {Component, inject} 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 {UserService} from '../../services/user.service';
@Component({
selector: 'cobbler-import-dvd',
templateUrl: './import-dvd.component.html',
- styleUrls: ['./import-dvd.component.css'], standalone: true,
- imports: [RouterOutlet, MatListModule],
+ styleUrls: ['./import-dvd.component.scss'], standalone: true,
+ imports: [
+ FormsModule,
+ MatFormField,
+ MatInput,
+ MatLabel,
+ ReactiveFormsModule,
+ MatButton
+ ],
})
export class ImportDVDComponent {
+ private readonly _formBuilder = inject(FormBuilder);
+ importFormGroup = this._formBuilder.group({
+ path: '',
+ name: '',
+ available_as: '',
+ autoinstall_file: '',
+ rsync_flags: '',
+ arch: '',
+ breed: '',
+ os_version: '',
+ })
- constructor() {
+ constructor(
+ public userService: UserService,
+ private cobblerApiService: CobblerApiService,
+ private _snackBar: MatSnackBar
+ ) {
+ }
+
+ 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("Please give all inputs a system name!", "Close", {duration: 2000})
+ return;
+ }
+ this.cobblerApiService.background_import(importOptions, this.userService.token).subscribe(
+ value => {
+ // TODO
+ },
+ error => {
+ // HTML encode the error message since it originates from XML
+ this._snackBar.open(this.toHTML(error.message), 'Close');
+ });
+ }
+
+ toHTML(input: string): any {
+ // FIXME: Deduplicate method
+ return new DOMParser().parseFromString(input, 'text/html').documentElement.textContent;
}
}
diff --git a/projects/cobbler-frontend/src/app/actions/replicate/replicate.component.ts b/projects/cobbler-frontend/src/app/actions/replicate/replicate.component.ts
index 500d9a47..17aba350 100644
--- a/projects/cobbler-frontend/src/app/actions/replicate/replicate.component.ts
+++ b/projects/cobbler-frontend/src/app/actions/replicate/replicate.component.ts
@@ -66,7 +66,6 @@ export class ReplicateComponent {
sync_all: this.replicateFormGroup.controls.sync_all.value,
use_ssl: this.replicateFormGroup.controls.use_ssl.value,
}
- console.log(replicateOptions)
this.cobblerApiService.background_replicate(replicateOptions, this.userService.token).subscribe(
value => {
// TODO