Skip to content

Commit

Permalink
Distro: Enable edit functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
SchoolGuy committed Nov 5, 2024
1 parent 5bd023e commit 166a71f
Show file tree
Hide file tree
Showing 14 changed files with 235 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<h1 mat-dialog-title>Cancel Edit?</h1>
<div mat-dialog-content class="content">
Are you sure you want to cancel the edit for the item &quot;
{{ data.name }}&quot;? All changes will be lost!
</div>
<div mat-dialog-actions>
<button mat-button [mat-dialog-close]="true">Yes</button>
<button mat-button [mat-dialog-close]="false">No</button>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { DialogModule } from '@angular/cdk/dialog';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { MAT_DIALOG_DATA } from '@angular/material/dialog';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';

import { DialogBoxConfirmCancelEditComponent } from './dialog-box-confirm-cancel-edit.component';

describe('DialogBoxConfirmCancelEditComponent', () => {
let component: DialogBoxConfirmCancelEditComponent;
let fixture: ComponentFixture<DialogBoxConfirmCancelEditComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [
DialogBoxConfirmCancelEditComponent,
DialogModule,
NoopAnimationsModule,
],
providers: [
{
provide: MAT_DIALOG_DATA,
useValue: { name: '' },
},
],
}).compileComponents();

fixture = TestBed.createComponent(DialogBoxConfirmCancelEditComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Component, Inject } from '@angular/core';
import { MatButton, MatButtonModule } from '@angular/material/button';
import {
MAT_DIALOG_DATA,
MatDialogActions,
MatDialogClose,
MatDialogContent,
MatDialogModule,
MatDialogTitle,
} from '@angular/material/dialog';

export interface DialogConfirmCancelData {
name: string;
}

@Component({
selector: 'cobbler-dialog-box-confirm-cancel-edit',
standalone: true,
imports: [MatButtonModule, MatDialogModule],
templateUrl: './dialog-box-confirm-cancel-edit.component.html',
styleUrl: './dialog-box-confirm-cancel-edit.component.scss',
})
export class DialogBoxConfirmCancelEditComponent {
constructor(@Inject(MAT_DIALOG_DATA) public data: DialogConfirmCancelData) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ <h1 class="title title-cell-text">Name: {{ name }}</h1>
<span class="title-cell-button">
<button
mat-icon-button
[disabled]="isEditMode"
(click)="this.refreshData()"
matTooltip="Refresh data"
>
Expand All @@ -13,22 +14,44 @@ <h1 class="title title-cell-text">Name: {{ name }}</h1>
<span class="title-cell-button">
<button
mat-icon-button
[disabled]="isEditMode"
(click)="this.copyDistro(this.distro.uid, this.distro.name)"
matTooltip="Copy"
>
<mat-icon>content_copy</mat-icon>
</button>
</span>
<span class="title-cell-button">
<button mat-icon-button (click)="this.editDistro()" matTooltip="Edit">
<button
mat-icon-button
[disabled]="isEditMode"
(click)="this.editDistro()"
matTooltip="Edit"
>
<mat-icon>edit</mat-icon>
</button>
</span>
<span class="title-cell-button">
<button mat-icon-button (click)="this.removeDistro()" matTooltip="Delete">
<button
mat-icon-button
[disabled]="isEditMode"
(click)="this.removeDistro()"
matTooltip="Delete"
>
<mat-icon>delete</mat-icon>
</button>
</span>
@if (isEditMode) {
<span class="title-cell-button">
<button
mat-icon-button
(click)="this.cancelEdit()"
matTooltip="Cancel edit"
>
<mat-icon>cancel</mat-icon>
</button>
</span>
}
</div>
</div>

Expand Down Expand Up @@ -90,7 +113,7 @@ <h1 class="title title-cell-text">Name: {{ name }}</h1>
[multiSelectOptions]="['ipxe', 'grub', 'pxe']"
formControlName="boot_loaders"
></cobbler-multi-select>
<mat-checkbox formControlName="bootloader_inherited"
<mat-checkbox formControlName="boot_loaders_inherited"
>Inherited</mat-checkbox
>
</ng-container>
Expand Down Expand Up @@ -181,16 +204,16 @@ <h1 class="title title-cell-text">Name: {{ name }}</h1>
<mat-label>RedHat Management Key</mat-label>
<input matInput type="text" formControlName="redhat_management_key" />
</mat-form-field>
<ng-container class="form-field-full-width">
<div class="form-field-full-width">
<cobbler-key-value-editor
label="Template Files"
[keyValueOptions]="distroTemplateFiles"
formControlName="template_files"
></cobbler-key-value-editor>
<mat-checkbox formControlName="template_files_inherited"
>Inherited</mat-checkbox
>
</ng-container>
<mat-checkbox formControlName="template_files_inherited">
Inherited
</mat-checkbox>
</div>
@if (isEditMode) {
<button mat-button (click)="saveDistro()">Save Distro</button>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Component, Inject, inject, OnDestroy, OnInit } from '@angular/core';
import {
FormBuilder,
FormControl,
FormGroup,
FormsModule,
ReactiveFormsModule,
} from '@angular/forms';
Expand All @@ -16,9 +17,11 @@ import { MatSnackBar } from '@angular/material/snack-bar';
import { MatTooltip } from '@angular/material/tooltip';
import { ActivatedRoute, Router } from '@angular/router';
import { CobblerApiService, Distro } from 'cobbler-api';
import { Subject } from 'rxjs';
import { combineLatest, forkJoin, Observable, Subject, zip } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { DialogBoxConfirmCancelEditComponent } from '../../../common/dialog-box-confirm-cancel-edit/dialog-box-confirm-cancel-edit.component';

Check failure on line 22 in projects/cobbler-frontend/src/app/items/distro/edit/distro-edit.component.ts

View workflow job for this annotation

GitHub Actions / lint-frontend (18.x)

This line has a length of 142. Maximum allowed is 120
import { DialogItemCopyComponent } from '../../../common/dialog-item-copy/dialog-item-copy.component';
import { DialogItemRenameComponent } from '../../../common/dialog-item-rename/dialog-item-rename.component';
import { KeyValueEditorComponent } from '../../../common/key-value-editor/key-value-editor.component';
import { MultiSelectComponent } from '../../../common/multi-select/multi-select.component';
import { UserService } from '../../../services/user.service';
Expand Down Expand Up @@ -74,7 +77,7 @@ export class DistroEditComponent implements OnInit, OnDestroy {
os_version: new FormControl({ value: '', disabled: true }),
redhat_management_key: new FormControl({ value: '', disabled: true }),
boot_loaders: new FormControl({ value: [], disabled: true }),
bootloader_inherited: new FormControl({ value: false, disabled: true }),
boot_loaders_inherited: new FormControl({ value: false, disabled: true }),
owners: new FormControl({ value: [], disabled: true }),
owners_inherited: new FormControl({ value: false, disabled: true }),
mgmt_classes: new FormControl({ value: [], disabled: true }),
Expand Down Expand Up @@ -169,9 +172,11 @@ export class DistroEditComponent implements OnInit, OnDestroy {
this.distro.redhat_management_key,
);
if (typeof this.distro.boot_loaders === 'string') {
this.distroFormGroup.controls.bootloader_inherited.setValue(true);
this.distroFormGroup.controls.boot_loaders_inherited.setValue(true);
} else {
this.distroFormGroup.controls.bootloader_inherited.setValue(false);
this.distroFormGroup.controls.boot_loaders_inherited.setValue(
false,
);
this.distroFormGroup.controls.boot_loaders.setValue(
this.distro.boot_loaders,
);
Expand Down Expand Up @@ -273,8 +278,26 @@ export class DistroEditComponent implements OnInit, OnDestroy {
}

editDistro(): void {
// TODO
this._snackBar.open('Not implemented at the moment!', 'Close');
this.isEditMode = true;
this.distroFormGroup.enable();
}

cancelEdit(): void {
const dialogRef = this.dialog.open(DialogBoxConfirmCancelEditComponent, {
data: {
name: this.distro.name,
},
});

dialogRef.afterClosed().subscribe((dialogResult) => {
if (dialogResult === false) {
// False means the user want's to continue
return;
}
this.isEditMode = false;
this.distroFormGroup.disable();
this.refreshData();
});
}

copyDistro(uid: string, name: string): void {
Expand Down Expand Up @@ -318,6 +341,39 @@ export class DistroEditComponent implements OnInit, OnDestroy {
}

saveDistro(): void {
let dirtyValues = Utils.deduplicateDirtyValues(
this.distroFormGroup,
Utils.getDirtyValues(this.distroFormGroup),
);
console.log(dirtyValues);
this.cobblerApiService
.get_distro_handle(this.name, this.userService.token)
.pipe(takeUntil(this.ngUnsubscribe))
.subscribe((distroHandle) => {
let modifyObservables: Observable<boolean>[] = [];
for (const key in dirtyValues) {
// TODO: Convert objects and lists inside the XML-RPC client
modifyObservables.push(
this.cobblerApiService.modify_distro(
distroHandle,
key,
dirtyValues[key],
this.userService.token,
),
);
console.log(key + ': ' + this.distroFormGroup.get(key).value);
}
combineLatest(modifyObservables).subscribe((value) => {
this.cobblerApiService
.save_distro(distroHandle, this.userService.token)
.subscribe((value1) => {
this.distroFormGroup.disable();
this.isEditMode = false;
this.refreshData();
});
});
});

// TODO
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ <h1 class="title title-cell-text">Name: {{ name }}</h1>
[multiSelectOptions]="['ipxe', 'grub', 'pxe']"
formControlName="boot_loaders"
></cobbler-multi-select>
<mat-checkbox formControlName="bootloader_inherited"
<mat-checkbox formControlName="boot_loaders_inherited"
>Inherited</mat-checkbox
>
</ng-container>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export class ImageEditComponent implements OnInit, OnDestroy {
image_type: new FormControl({ value: '', disabled: true }),
os_version: new FormControl({ value: '', disabled: true }),
boot_loaders: new FormControl({ value: [], disabled: true }),
bootloader_inherited: new FormControl({ value: false, disabled: true }),
boot_loaders_inherited: new FormControl({ value: false, disabled: true }),
owners: new FormControl({ value: [], disabled: true }),
owners_inherited: new FormControl({ value: false, disabled: true }),
});
Expand Down Expand Up @@ -134,9 +134,9 @@ export class ImageEditComponent implements OnInit, OnDestroy {
this.image.os_version,
);
if (typeof this.image.boot_loaders === 'string') {
this.imageFormGroup.controls.bootloader_inherited.setValue(true);
this.imageFormGroup.controls.boot_loaders_inherited.setValue(true);
} else {
this.imageFormGroup.controls.bootloader_inherited.setValue(false);
this.imageFormGroup.controls.boot_loaders_inherited.setValue(false);
this.imageFormGroup.controls.boot_loaders.setValue(
this.image.boot_loaders,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ <h1 class="title title-cell-text">Name: {{ name }}</h1>
[multiSelectOptions]="['ipxe', 'grub', 'pxe']"
formControlName="boot_loaders"
></cobbler-multi-select>
<mat-checkbox formControlName="bootloader_inherited"
<mat-checkbox formControlName="boot_loaders_inherited"
>Inherited</mat-checkbox
>
</ng-container>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class ProfileEditComponent implements OnInit, OnDestroy {
proxy: new FormControl({ value: '', disabled: true }),
server: new FormControl({ value: '', disabled: true }),
boot_loaders: new FormControl({ value: [], disabled: true }),
bootloader_inherited: new FormControl({ value: false, disabled: true }),
boot_loaders_inherited: new FormControl({ value: false, disabled: true }),
owners: new FormControl({ value: [], disabled: true }),
owners_inherited: new FormControl({ value: false, disabled: true }),
autoinstall_meta: new FormControl({ value: {}, disabled: true }),
Expand Down Expand Up @@ -183,9 +183,13 @@ export class ProfileEditComponent implements OnInit, OnDestroy {
);
this.profileFormGroup.controls.repos.setValue(this.profile.repos);
if (typeof this.profile.boot_loaders === 'string') {
this.profileFormGroup.controls.bootloader_inherited.setValue(true);
this.profileFormGroup.controls.boot_loaders_inherited.setValue(
true,
);
} else {
this.profileFormGroup.controls.bootloader_inherited.setValue(false);
this.profileFormGroup.controls.boot_loaders_inherited.setValue(
false,
);
this.profileFormGroup.controls.boot_loaders.setValue(
this.profile.boot_loaders,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ <h1 class="title title-cell-text">Name: {{ name }}</h1>
[multiSelectOptions]="['ipxe', 'grub', 'pxe']"
formControlName="boot_loaders"
></cobbler-multi-select>
<mat-checkbox formControlName="bootloader_inherited"
<mat-checkbox formControlName="boot_loaders_inherited"
>Inherited</mat-checkbox
>
</ng-container>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export class SystemEditComponent implements OnInit, OnDestroy {
virt_path: new FormControl({ value: '', disabled: true }),
virt_type: new FormControl({ value: '', disabled: true }),
boot_loaders: new FormControl({ value: [], disabled: true }),
bootloader_inherited: new FormControl({ value: false, disabled: true }),
boot_loaders_inherited: new FormControl({ value: false, disabled: true }),
ipv6_autoconfiguration: new FormControl({ value: false, disabled: true }),
repos_enabled: new FormControl({ value: false, disabled: true }),
netboot_enabled: new FormControl({ value: false, disabled: true }),
Expand Down Expand Up @@ -270,9 +270,11 @@ export class SystemEditComponent implements OnInit, OnDestroy {
this.system.name_servers_search,
);
if (typeof this.system.boot_loaders === 'string') {
this.systemFormGroup.controls.bootloader_inherited.setValue(true);
this.systemFormGroup.controls.boot_loaders_inherited.setValue(true);
} else {
this.systemFormGroup.controls.bootloader_inherited.setValue(false);
this.systemFormGroup.controls.boot_loaders_inherited.setValue(
false,
);
this.systemFormGroup.controls.boot_loaders.setValue(
this.system.boot_loaders,
);
Expand Down
15 changes: 15 additions & 0 deletions projects/cobbler-frontend/src/app/utils.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import Utils from './utils';

describe('Utils', () => {
it('Should return the correct values', () => {
const result = Utils.deduplicateDirtyValues(undefined, {
redhat_management_key: '<<inherit>>',
boot_loaders: ['grub', 'pxe', 'ipxe'],
boot_loaders_inherited: true,
});
expect(result).toBe({
redhat_management_key: '<<inherit>>',
boot_loaders: true,
});
});
});
Loading

0 comments on commit 166a71f

Please sign in to comment.