File

projects/cobbler-frontend/src/app/common/view-autoinstall/view-autoinstall.component.ts

Implements

OnInit OnDestroy

Metadata

Index

Properties
Methods

Constructor

constructor(router: Router, route: ActivatedRoute, cobblerApiService: CobblerApiService)
Parameters :
Name Type Optional
router Router No
route ActivatedRoute No
cobblerApiService CobblerApiService No

Methods

backToItem
backToItem()
Returns : void
ngOnDestroy
ngOnDestroy()
Returns : void
ngOnInit
ngOnInit()
Returns : void
triggerResize
triggerResize()
Returns : void

Properties

autoinstallFormControl
Default value : new FormControl('')
autosize
Type : CdkTextareaAutosize
Decorators :
@ViewChild('autosize')
name
Type : string
Private ngUnsubscribe
Default value : new Subject<void>()
type
Type : string
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]);
  }
}
<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>
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""