From d12086c28592acef26855c2211f3b0ae23216fd1 Mon Sep 17 00:00:00 2001 From: Katharina Keitel Date: Fri, 19 Jul 2024 18:41:55 +0200 Subject: [PATCH] add mkloaders view --- .../src/lib/cobbler-api.service.ts | 15 +++++++ .../mkloaders/mkloaders.component.html | 3 ++ .../mkloaders/mkloaders.component.scss | 0 .../mkloaders/mkloaders.component.spec.ts | 23 ++++++++++ .../actions/mkloaders/mkloaders.component.ts | 45 +++++++++++++++++++ .../src/app/app-routing.module.ts | 2 + .../manage-menu/manage-menu.component.html | 3 ++ 7 files changed, 91 insertions(+) create mode 100644 projects/cobbler-frontend/src/app/actions/mkloaders/mkloaders.component.html create mode 100644 projects/cobbler-frontend/src/app/actions/mkloaders/mkloaders.component.scss create mode 100644 projects/cobbler-frontend/src/app/actions/mkloaders/mkloaders.component.spec.ts create mode 100644 projects/cobbler-frontend/src/app/actions/mkloaders/mkloaders.component.ts diff --git a/projects/cobbler-api/src/lib/cobbler-api.service.ts b/projects/cobbler-api/src/lib/cobbler-api.service.ts index 86b930fb..a7e2f170 100644 --- a/projects/cobbler-api/src/lib/cobbler-api.service.ts +++ b/projects/cobbler-api/src/lib/cobbler-api.service.ts @@ -172,6 +172,21 @@ export class CobblerApiService { }) ); } + backgroundMkloaders(token: string): Observable { + const mkloadersOptions: XmlRpcStruct = {members: []} + return this.client + .methodCall('background_mkloaders', [mkloadersOptions, token]) + .pipe( + map((data: MethodResponse | MethodFault) => { + if (AngularXmlrpcService.instanceOfMethodResponse(data)) { + return data.value as string; + } else if (AngularXmlrpcService.instanceOfMethodFault(data)) { + throw new Error('Mkloading files on the server in the background failed with code "' + data.faultCode + + '" and error message "' + data.faultString + '"'); + } + }) + ); + } background_validate_autoinstall_files(token: string): Observable { const validateAutoinstallOptions: XmlRpcStruct = {members: []} diff --git a/projects/cobbler-frontend/src/app/actions/mkloaders/mkloaders.component.html b/projects/cobbler-frontend/src/app/actions/mkloaders/mkloaders.component.html new file mode 100644 index 00000000..59c87843 --- /dev/null +++ b/projects/cobbler-frontend/src/app/actions/mkloaders/mkloaders.component.html @@ -0,0 +1,3 @@ +

MKLOADERS

+ + diff --git a/projects/cobbler-frontend/src/app/actions/mkloaders/mkloaders.component.scss b/projects/cobbler-frontend/src/app/actions/mkloaders/mkloaders.component.scss new file mode 100644 index 00000000..e69de29b diff --git a/projects/cobbler-frontend/src/app/actions/mkloaders/mkloaders.component.spec.ts b/projects/cobbler-frontend/src/app/actions/mkloaders/mkloaders.component.spec.ts new file mode 100644 index 00000000..a5d84d21 --- /dev/null +++ b/projects/cobbler-frontend/src/app/actions/mkloaders/mkloaders.component.spec.ts @@ -0,0 +1,23 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { MkloadersComponent } from './mkloaders.component'; + +describe('MkloadersComponent', () => { + let component: MkloadersComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [MkloadersComponent] + }) + .compileComponents(); + + fixture = TestBed.createComponent(MkloadersComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/projects/cobbler-frontend/src/app/actions/mkloaders/mkloaders.component.ts b/projects/cobbler-frontend/src/app/actions/mkloaders/mkloaders.component.ts new file mode 100644 index 00000000..a5504780 --- /dev/null +++ b/projects/cobbler-frontend/src/app/actions/mkloaders/mkloaders.component.ts @@ -0,0 +1,45 @@ +import { Component, inject, OnDestroy } from '@angular/core'; +import { UserService } from '../../services/user.service'; +import { CobblerApiService } from 'cobbler-api'; +import { Subscription } from 'rxjs'; +import { MatSnackBar } from '@angular/material/snack-bar'; +import { MatButton } from '@angular/material/button'; + +@Component({ + selector: 'cobbler-mkloaders', + standalone: true, + imports: [MatButton], + templateUrl: './mkloaders.component.html', + styleUrl: './mkloaders.component.scss', +}) +export class MkloadersComponent implements OnDestroy { + private userSvc = inject(UserService); + private cobblerApiSvc = inject(CobblerApiService); + + private subs: Subscription = new Subscription(); + + constructor(private _snackBar: MatSnackBar) {} + + ngOnDestroy(): void { + this.subs.unsubscribe(); + } + runMkloaders(): void { + this.subs.add( + this.cobblerApiSvc.background_hardlink(this.userSvc.token).subscribe({ + next:(value) => { + // TODO + }, + error:(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/app-routing.module.ts b/projects/cobbler-frontend/src/app/app-routing.module.ts index 95abd4fa..1ecc88a6 100644 --- a/projects/cobbler-frontend/src/app/app-routing.module.ts +++ b/projects/cobbler-frontend/src/app/app-routing.module.ts @@ -26,6 +26,7 @@ import { AuthGuardService } from './services/auth-guard.service'; import { SettingsViewComponent } from './settings/view/settings-view.component'; import { UnauthorizedComponent } from './unauthorized/unauthorized.component'; import {SignaturesComponent} from "./signatures/signatures.component"; +import { MkloadersComponent } from './actions/mkloaders/mkloaders.component'; export const routes: Routes = [ @@ -52,6 +53,7 @@ export const routes: Routes = [ {path: 'check', component: CheckSysComponent, canActivate: [AuthGuardService]}, {path: 'status', component: StatusComponent, canActivate: [AuthGuardService]}, {path: 'hardlink', component: HardlinkComponent, canActivate: [AuthGuardService]}, + {path: 'mkloaders', component: MkloadersComponent, canActivate: [AuthGuardService]}, {path: 'events', component: AppEventsComponent, canActivate: [AuthGuardService]}, {path: 'signatures', component: SignaturesComponent, canActivate: [AuthGuardService]}, {path: 'validate-autoinstalls', component: ValidateAutoinstallsComponent, canActivate: [AuthGuardService]}, diff --git a/projects/cobbler-frontend/src/app/manage-menu/manage-menu.component.html b/projects/cobbler-frontend/src/app/manage-menu/manage-menu.component.html index 2d5e6b7c..20b8cac4 100644 --- a/projects/cobbler-frontend/src/app/manage-menu/manage-menu.component.html +++ b/projects/cobbler-frontend/src/app/manage-menu/manage-menu.component.html @@ -135,6 +135,9 @@

Actions

Hardlink + + Mkloaders Validate Autoinstalls