Methods
|
ngOnDestroy
|
ngOnDestroy()
|
|
|
|
|
|
triggerResize
|
triggerResize()
|
|
|
|
|
|
autoinstallFormControl
|
Type : unknown
|
Default value : new FormControl('')
|
|
|
|
autosize
|
Type : CdkTextareaAutosize
|
Decorators :
@ViewChild('autosize')
|
|
|
|
Private
cobblerApiService
|
Type : unknown
|
Default value : inject(CobblerApiService)
|
|
|
|
Private
ngUnsubscribe
|
Type : unknown
|
Default value : new Subject<void>()
|
|
|
|
Private
route
|
Type : unknown
|
Default value : inject(ActivatedRoute)
|
|
|
|
Private
router
|
Type : unknown
|
Default value : inject(Router)
|
|
|
import { CdkTextareaAutosize } from '@angular/cdk/text-field';
import { Component, OnDestroy, OnInit, ViewChild, inject } 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',
imports: [
MatFormFieldModule,
MatInputModule,
ReactiveFormsModule,
MatIconModule,
MatButtonModule,
MatTooltipModule,
],
templateUrl: './view-autoinstall.component.html',
styleUrl: './view-autoinstall.component.scss',
})
export class ViewAutoinstallComponent implements OnInit, OnDestroy {
private router = inject(Router);
private route = inject(ActivatedRoute);
private cobblerApiService = inject(CobblerApiService);
// Unsubscribe
private ngUnsubscribe = new Subject<void>();
// Data
type: string;
name: string;
autoinstallFormControl = new FormControl('');
@ViewChild('autosize') autosize: CdkTextareaAutosize;
constructor() {
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]);
}
}
<h1 i18n="@@common.view-autoinstall.title">
Rendered auto-installation template
</h1>
<p i18n="@@common.view-autoinstall.description">
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 i18n="@@common.view-autoinstall.label.content"
>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 }}"
i18n-matTooltip="@@common.view-autoinstall.tooltip.back"
(click)="backToItem()"
>
<mat-icon>arrow_back</mat-icon>
</button>
</div>
.full-width {
width: 100%;
}
.content {
white-space: pre-line;
width: 100%;
}
.fab-positioning {
position: fixed;
right: 1%;
bottom: 1%;
}
Legend
Html element with directive