diff --git a/projects/cobbler-frontend/src/app/app-routing.module.ts b/projects/cobbler-frontend/src/app/app-routing.module.ts index 3ed2fe5f..81ca2f19 100644 --- a/projects/cobbler-frontend/src/app/app-routing.module.ts +++ b/projects/cobbler-frontend/src/app/app-routing.module.ts @@ -11,6 +11,7 @@ import { SyncComponent } from './actions/sync/sync.component'; import { ValidateAutoinstallsComponent } from './actions/validate-autoinstalls/validate-autoinstalls.component'; import { AppEventsComponent } from './app-events/app-events.component'; import { AppManageComponent } from './appManage'; +import { ViewAutoinstallComponent } from './common/view-autoinstall/view-autoinstall.component'; import { DistroEditComponent } from './items/distro/edit/distro-edit.component'; import { DistrosOverviewComponent } from './items/distro/overview/distros-overview.component'; import { FileEditComponent } from './items/file/edit/file-edit.component'; @@ -72,6 +73,11 @@ export const routes: Routes = [ component: ProfileEditComponent, canActivate: [AuthGuardService], }, + { + path: 'profile/:name/autoinstall', + component: ViewAutoinstallComponent, + canActivate: [AuthGuardService], + }, { path: 'system', component: SystemOverviewComponent, @@ -82,6 +88,11 @@ export const routes: Routes = [ component: SystemEditComponent, canActivate: [AuthGuardService], }, + { + path: 'system/:name/autoinstall', + component: ViewAutoinstallComponent, + canActivate: [AuthGuardService], + }, { path: 'repository', component: RepositoryOverviewComponent, diff --git a/projects/cobbler-frontend/src/app/common/view-autoinstall/view-autoinstall.component.html b/projects/cobbler-frontend/src/app/common/view-autoinstall/view-autoinstall.component.html new file mode 100644 index 00000000..676e3e15 --- /dev/null +++ b/projects/cobbler-frontend/src/app/common/view-autoinstall/view-autoinstall.component.html @@ -0,0 +1,25 @@ +

Rendered auto-installation template

+ +

+ This is the rendered template for {{ name }}. +

+ +
+ + Auto-installation content + + +
+ +
+ +
diff --git a/projects/cobbler-frontend/src/app/common/view-autoinstall/view-autoinstall.component.scss b/projects/cobbler-frontend/src/app/common/view-autoinstall/view-autoinstall.component.scss new file mode 100644 index 00000000..6be81931 --- /dev/null +++ b/projects/cobbler-frontend/src/app/common/view-autoinstall/view-autoinstall.component.scss @@ -0,0 +1,14 @@ +.full-width { + width: 100%; +} + +.content { + white-space: pre-line; + width: 100%; +} + +.fab-positioning { + position: fixed; + right: 1%; + bottom: 1%; +} diff --git a/projects/cobbler-frontend/src/app/common/view-autoinstall/view-autoinstall.component.spec.ts b/projects/cobbler-frontend/src/app/common/view-autoinstall/view-autoinstall.component.spec.ts new file mode 100644 index 00000000..96299cfc --- /dev/null +++ b/projects/cobbler-frontend/src/app/common/view-autoinstall/view-autoinstall.component.spec.ts @@ -0,0 +1,48 @@ +import { provideHttpClient } from '@angular/common/http'; +import { provideHttpClientTesting } from '@angular/common/http/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { NoopAnimationsModule } from '@angular/platform-browser/animations'; +import { ActivatedRoute, provideRouter } from '@angular/router'; +import { COBBLER_URL } from 'cobbler-api'; +import { routes } from '../../app-routing.module'; + +import { ViewAutoinstallComponent } from './view-autoinstall.component'; + +describe('ViewAutoinstallComponent', () => { + let component: ViewAutoinstallComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [ViewAutoinstallComponent, NoopAnimationsModule], + providers: [ + provideRouter(routes), + provideHttpClient(), + provideHttpClientTesting(), + { + provide: COBBLER_URL, + useValue: new URL('http://localhost/cobbler_api'), + }, + { + provide: ActivatedRoute, + useValue: { + snapshot: { + url: [{ path: 'profile' }], + paramMap: { + get: () => 'testprof', + }, + }, + }, + }, + ], + }).compileComponents(); + + fixture = TestBed.createComponent(ViewAutoinstallComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/projects/cobbler-frontend/src/app/common/view-autoinstall/view-autoinstall.component.ts b/projects/cobbler-frontend/src/app/common/view-autoinstall/view-autoinstall.component.ts new file mode 100644 index 00000000..6092c3c6 --- /dev/null +++ b/projects/cobbler-frontend/src/app/common/view-autoinstall/view-autoinstall.component.ts @@ -0,0 +1,81 @@ +import { CdkTextareaAutosize } from '@angular/cdk/text-field'; +import { Component, OnDestroy, OnInit, ViewChild } from '@angular/core'; +import { FormControl, ReactiveFormsModule } from '@angular/forms'; +import { MatButtonModule } from '@angular/material/button'; +import { MatFormFieldModule } from '@angular/material/form-field'; +import { MatIconModule } from '@angular/material/icon'; +import { MatInputModule } from '@angular/material/input'; +import { MatTooltipModule } from '@angular/material/tooltip'; +import { ActivatedRoute, Router } from '@angular/router'; +import { CobblerApiService } from 'cobbler-api'; +import { Subject } from 'rxjs'; +import { takeUntil } from 'rxjs/operators'; + +@Component({ + selector: 'cobbler-view-autoinstall', + standalone: true, + imports: [ + MatFormFieldModule, + MatInputModule, + ReactiveFormsModule, + MatIconModule, + MatButtonModule, + MatTooltipModule, + ], + templateUrl: './view-autoinstall.component.html', + styleUrl: './view-autoinstall.component.scss', +}) +export class ViewAutoinstallComponent implements OnInit, OnDestroy { + // Unsubscribe + private ngUnsubscribe = new Subject(); + + // Data + type: string; + name: string; + autoinstallFormControl = new FormControl(''); + @ViewChild('autosize') autosize: CdkTextareaAutosize; + + constructor( + private router: Router, + private route: ActivatedRoute, + private cobblerApiService: CobblerApiService, + ) { + this.type = this.route.snapshot.url[0].path; + this.name = this.route.snapshot.paramMap.get('name'); + } + + ngOnInit(): void { + if (this.type === 'profile') { + this.cobblerApiService + .generate_autoinstall(this.name, '') + .pipe(takeUntil(this.ngUnsubscribe)) + .subscribe((value) => { + this.autoinstallFormControl.setValue(value); + this.autosize.resizeToFitContent(true); + }); + } else if (this.type === 'system') { + this.cobblerApiService + .generate_autoinstall('', this.name) + .pipe(takeUntil(this.ngUnsubscribe)) + .subscribe((value) => { + this.autoinstallFormControl.setValue(value); + this.autosize.resizeToFitContent(true); + }); + } else { + throw new Error('Object type was neither profile nor system!'); + } + } + + ngOnDestroy(): void { + this.ngUnsubscribe.next(); + this.ngUnsubscribe.complete(); + } + + triggerResize() { + this.autosize.resizeToFitContent(true); + } + + backToItem() { + this.router.navigate(['/items', this.type, this.name]); + } +} diff --git a/projects/cobbler-frontend/src/app/items/profile/edit/profile-edit.component.html b/projects/cobbler-frontend/src/app/items/profile/edit/profile-edit.component.html index 6f07901b..a0acb512 100644 --- a/projects/cobbler-frontend/src/app/items/profile/edit/profile-edit.component.html +++ b/projects/cobbler-frontend/src/app/items/profile/edit/profile-edit.component.html @@ -11,6 +11,16 @@

Name: {{ name }}

refresh + + + + + +