-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cobbler-Frontend: Implement viewer for rendered auto-installations
- Loading branch information
Showing
9 changed files
with
257 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
projects/cobbler-frontend/src/app/common/view-autoinstall/view-autoinstall.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<h1>Rendered auto-installation template</h1> | ||
|
||
<p>This is the rendered template for {{ name }}.</p> | ||
|
||
<form class="full-width full-height" (window:resize)="triggerResize()"> | ||
<mat-form-field class="full-width full-height"> | ||
<mat-label>Auto-installation content</mat-label> | ||
<textarea | ||
matInput | ||
[formControl]="autoinstallFormControl" | ||
readonly | ||
class="content" | ||
cdkTextareaAutosize | ||
#autosize="cdkTextareaAutosize" | ||
cdkAutosizeMinRows="10" | ||
cdkAutosizeMaxRows="40" | ||
></textarea> | ||
</mat-form-field> | ||
</form> | ||
|
||
<div> | ||
<button | ||
mat-fab | ||
class="fab-positioning" | ||
color="primary" | ||
matTooltip="Back to {{ name }}" | ||
(click)="backToItem()" | ||
> | ||
<mat-icon>arrow_back</mat-icon> | ||
</button> | ||
</div> |
14 changes: 14 additions & 0 deletions
14
projects/cobbler-frontend/src/app/common/view-autoinstall/view-autoinstall.component.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
.full-width { | ||
width: 100%; | ||
} | ||
|
||
.content { | ||
white-space: pre-line; | ||
width: 100%; | ||
} | ||
|
||
.fab-positioning { | ||
position: fixed; | ||
right: 1%; | ||
bottom: 1%; | ||
} |
48 changes: 48 additions & 0 deletions
48
projects/cobbler-frontend/src/app/common/view-autoinstall/view-autoinstall.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<ViewAutoinstallComponent>; | ||
|
||
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(); | ||
}); | ||
}); |
81 changes: 81 additions & 0 deletions
81
projects/cobbler-frontend/src/app/common/view-autoinstall/view-autoinstall.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<void>(); | ||
|
||
// 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]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.