projects/cobbler-frontend/src/app/actions/check-sys/check-sys.component.ts

Implements

OnInit OnDestroy

Metadata

Relationships

Used by

No results matching.

Depends on

Index

Properties
Methods

Methods

ngOnDestroy
ngOnDestroy()
Returns : void
ngOnInit
ngOnInit()
Returns : void
updateChecks
updateChecks()
Returns : void

Properties

Private _snackBar
Type : unknown
Default value : inject(MatSnackBar)
Private cobblerApiService
Type : unknown
Default value : inject(CobblerApiService)
Public data
Type : Observable<Array<string>>
Default value : of([])
Public isLoading
Type : unknown
Default value : true
Private ngUnsubscribe
Type : unknown
Default value : new Subject<void>()
userService
Type : unknown
Default value : inject(UserService)
import { CommonModule } from '@angular/common';
import { Component, OnDestroy, OnInit, inject } from '@angular/core';
import { MatIconButton } from '@angular/material/button';
import { MatIcon } from '@angular/material/icon';
import { MatListModule } from '@angular/material/list';
import { MatProgressSpinner } from '@angular/material/progress-spinner';
import { MatSnackBar } from '@angular/material/snack-bar';
import { RouterOutlet } from '@angular/router';
import { CobblerApiService } from 'cobbler-api';
import { Observable, of, Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { UserService } from '../../services/user.service';
import Utils from '../../utils';

@Component({
  selector: 'cobbler-check-sys',
  templateUrl: './check-sys.component.html',
  styleUrls: ['./check-sys.component.scss'],
  imports: [
    RouterOutlet,
    MatListModule,
    CommonModule,
    MatIconButton,
    MatIcon,
    MatProgressSpinner,
  ],
})
export class CheckSysComponent implements OnInit, OnDestroy {
  userService = inject(UserService);
  private cobblerApiService = inject(CobblerApiService);
  private _snackBar = inject(MatSnackBar);

  // Unsubscribe
  private ngUnsubscribe = new Subject<void>();

  // Data
  public data: Observable<Array<string>> = of([]);
  public isLoading = true;

  ngOnInit(): void {
    this.updateChecks();
  }

  ngOnDestroy(): void {
    this.ngUnsubscribe.next();
    this.ngUnsubscribe.complete();
  }

  updateChecks(): void {
    this.isLoading = true;
    this.cobblerApiService
      .check(this.userService.token)
      .pipe(takeUntil(this.ngUnsubscribe))
      .subscribe(
        (data) => {
          this.data = of(data);
          this.isLoading = false;
        },
        (error) => {
          // HTML encode the error message since it originates from XML
          this._snackBar.open(
            Utils.toHTML(error.message),
            $localize`:@@snackbar.action.close:Close`,
          );
          this.isLoading = false;
        },
      );
  }
}
<div class="right-column" id="dataScreen">
  <router-outlet></router-outlet>
  <div class="CheckSys-div">
    <div class="title-table">
      <div class="title-row">
        <h1 class="title title-cell-text" i18n="@@action.check.title">CHECK</h1>
        <span class="title-cell-button">
          <button mat-icon-button (click)="this.updateChecks()">
            <mat-icon>refresh</mat-icon>
          </button>
        </span>
      </div>
    </div>
    <div class="list-group">
      @if (isLoading) {
        <mat-spinner style="margin: 0 auto"></mat-spinner>
      }
      @if (!isLoading) {
        <mat-list>
          @for (element of this.data | async; track element) {
            <mat-list-item>{{ element }}</mat-list-item>
          }
        </mat-list>
      }
    </div>
  </div>
</div>

./check-sys.component.scss

.title-table {
  display: table;
  width: 100%;
}

.title-row {
  display: table-cell;
  width: 100%;
}

.title-cell-text {
  display: table-cell;
  width: 100%;
  vertical-align: middle;
}

.title-cell-button {
  display: table-cell;
}
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""