projects/cobbler-frontend/src/app/items/distro/overview/distros-overview.component.ts
OnInit
OnDestroy
AfterViewInit
| selector | cobbler-distro-overview |
| imports |
MatButtonModule
MatTableModule
MatIconModule
MatMenuModule
MatTooltipModule
MatPaginatorModule
MatFormFieldModule
MatInputModule
MatSort
RouterLink
|
| styleUrls | ./distros-overview.component.scss |
| templateUrl | ./distros-overview.component.html |
Properties |
|
Methods |
| addDistro |
addDistro()
|
|
Returns :
void
|
| applyFilter | ||||||
applyFilter(event: Event)
|
||||||
|
Parameters :
Returns :
void
|
| deleteDistro |
deleteDistro(uid: string, name: string)
|
|
Returns :
void
|
| ngAfterViewInit |
ngAfterViewInit()
|
|
Returns :
void
|
| ngOnDestroy |
ngOnDestroy()
|
|
Returns :
void
|
| ngOnInit |
ngOnInit()
|
|
Returns :
void
|
| renameDistro |
renameDistro(uid: string, name: string)
|
|
Returns :
void
|
| Private retrieveDistros |
retrieveDistros()
|
|
Returns :
void
|
| showDistro |
showDistro(uid: string, name: string)
|
|
Returns :
void
|
| Private _snackBar |
Type : unknown
|
Default value : inject(MatSnackBar)
|
| Private cobblerApiService |
Type : unknown
|
Default value : inject(CobblerApiService)
|
| dataSource |
Type : unknown
|
Default value : new MatTableDataSource<Distro>([])
|
| Readonly dialog |
Type : unknown
|
Default value : inject<MatDialog>(MatDialog)
|
| displayedColumns |
Type : string[]
|
Default value : ['name', 'breed', 'os_version', 'actions']
|
| filterField |
Type : ElementRef<HTMLInputElement>
|
Decorators :
@ViewChild('input')
|
| Private ngUnsubscribe |
Type : unknown
|
Default value : new Subject<void>()
|
| paginator |
Type : MatPaginator
|
Decorators :
@ViewChild(MatPaginator)
|
| Private route |
Type : unknown
|
Default value : inject(ActivatedRoute)
|
| Private router |
Type : unknown
|
Default value : inject(Router)
|
| sort |
Type : MatSort
|
Decorators :
@ViewChild(MatSort)
|
| table |
Type : MatTable<Distro>
|
Decorators :
@ViewChild(MatTable)
|
| Private targetDistro |
Type : string | null
|
Default value : null
|
| userService |
Type : unknown
|
Default value : inject(UserService)
|
import {
AfterViewInit,
Component,
ElementRef,
OnDestroy,
OnInit,
ViewChild,
inject,
} from '@angular/core';
import { MatButtonModule } from '@angular/material/button';
import { MatDialog } from '@angular/material/dialog';
import { MatIconModule } from '@angular/material/icon';
import { MatMenuModule } from '@angular/material/menu';
import { MatSnackBar } from '@angular/material/snack-bar';
import {
MatTable,
MatTableDataSource,
MatTableModule,
} from '@angular/material/table';
import { MatTooltipModule } from '@angular/material/tooltip';
import {
ActivatedRoute,
Router,
RouterLink,
RouterOutlet,
} from '@angular/router';
import { CobblerApiService, Distro } from 'cobbler-api';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { DialogItemRenameComponent } from '../../../common/dialog-item-rename/dialog-item-rename.component';
import { UserService } from '../../../services/user.service';
import Utils from '../../../utils';
import { DistroCreateComponent } from '../create/distro-create.component';
import { MatPaginator, MatPaginatorModule } from '@angular/material/paginator';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatSort } from '@angular/material/sort';
import { MatInputModule } from '@angular/material/input';
@Component({
selector: 'cobbler-distro-overview',
templateUrl: './distros-overview.component.html',
styleUrls: ['./distros-overview.component.scss'],
imports: [
MatButtonModule,
MatTableModule,
MatIconModule,
MatMenuModule,
MatTooltipModule,
MatPaginatorModule,
MatFormFieldModule,
MatInputModule,
MatSort,
RouterLink,
],
})
export class DistrosOverviewComponent
implements OnInit, OnDestroy, AfterViewInit
{
userService = inject(UserService);
private cobblerApiService = inject(CobblerApiService);
private _snackBar = inject(MatSnackBar);
private router = inject(Router);
readonly dialog = inject<MatDialog>(MatDialog);
private route = inject(ActivatedRoute);
private targetDistro: string | null = null;
// Unsubscribe
private ngUnsubscribe = new Subject<void>();
// Table
displayedColumns: string[] = ['name', 'breed', 'os_version', 'actions'];
dataSource = new MatTableDataSource<Distro>([]);
@ViewChild(MatTable) table!: MatTable<Distro>;
@ViewChild(MatPaginator) paginator!: MatPaginator;
@ViewChild(MatSort) sort!: MatSort;
@ViewChild('input') filterField!: ElementRef<HTMLInputElement>;
ngOnInit(): void {
this.retrieveDistros();
this.targetDistro = this.route.snapshot.queryParamMap.get('distro');
}
ngAfterViewInit(): void {
this.dataSource.paginator = this.paginator;
this.dataSource.sort = this.sort;
if (this.targetDistro) {
this.filterField.nativeElement.value = this.targetDistro;
this.dataSource.filter = this.targetDistro;
} else {
this.filterField.nativeElement.value = '';
}
}
ngOnDestroy(): void {
this.ngUnsubscribe.next();
this.ngUnsubscribe.complete();
}
applyFilter(event: Event) {
const filterValue = (event.target as HTMLInputElement).value;
this.dataSource.filter = filterValue.trim().toLowerCase();
if (this.dataSource.paginator) {
this.dataSource.paginator.firstPage();
}
// Remove query param on URL when filtering
this.router.navigate([], {
relativeTo: this.route,
queryParams: { distro: null },
queryParamsHandling: 'merge',
});
}
private retrieveDistros(): void {
this.cobblerApiService
.get_distros()
.pipe(takeUntil(this.ngUnsubscribe))
.subscribe({
next: (value) => {
this.dataSource.data = value;
},
error: (error) => {
// HTML encode the error message since it originates from XML
this._snackBar.open(
Utils.toHTML(error.message),
$localize`:@@snackbar.action.close:Close`,
);
},
});
}
addDistro(): void {
const dialogRef = this.dialog.open(DistroCreateComponent, { width: '40%' });
dialogRef.afterClosed().subscribe((result) => {
if (typeof result === 'string') {
this.router.navigate(['/items', 'distro', result]);
}
});
}
showDistro(uid: string, name: string): void {
this.router.navigate(['/items', 'distro', name]);
}
renameDistro(uid: string, name: string): void {
const dialogRef = this.dialog.open(DialogItemRenameComponent, {
data: {
itemType: 'Distro',
itemName: name,
itemUid: uid,
},
});
dialogRef.afterClosed().subscribe((newItemName) => {
if (newItemName === undefined) {
// Cancel means we don't need to rename the distro
return;
}
this.cobblerApiService
.get_distro_handle(name, this.userService.token)
.pipe(takeUntil(this.ngUnsubscribe))
.subscribe({
next: (distroHandle) => {
this.cobblerApiService
.rename_distro(distroHandle, newItemName, this.userService.token)
.pipe(takeUntil(this.ngUnsubscribe))
.subscribe({
next: (value) => {
this.retrieveDistros();
},
error: (error) => {
// HTML encode the error message since it originates from XML
this._snackBar.open(
Utils.toHTML(error.message),
$localize`:@@snackbar.action.close:Close`,
);
},
});
},
error: (error) => {
// HTML encode the error message since it originates from XML
this._snackBar.open(
Utils.toHTML(error.message),
$localize`:@@snackbar.action.close:Close`,
);
},
});
});
}
deleteDistro(uid: string, name: string): void {
this.cobblerApiService
.remove_distro(name, this.userService.token, false)
.pipe(takeUntil(this.ngUnsubscribe))
.subscribe({
next: (value) => {
this.retrieveDistros();
},
error: (error) => {
// HTML encode the error message since it originates from XML
this._snackBar.open(
Utils.toHTML(error.message),
$localize`:@@snackbar.action.close:Close`,
);
},
});
}
}
<div class="title-table">
<div class="title-row">
<h1 class="title title-cell-text" i18n="@@distro.overview.title">
DISTROS
</h1>
<span class="title-cell-button">
<button
mat-icon-button
data-testid="item-add-button"
(click)="this.addDistro()"
matTooltip="Add Distribution"
i18n-matTooltip="@@distro.overview.add-tooltip"
>
<mat-icon>add</mat-icon>
</button></span
>
</div>
</div>
<mat-form-field appearance="fill">
<mat-label i18n="@@filter.label">Filter</mat-label>
<input
matInput
(keyup)="applyFilter($event)"
placeholder="Ex. aarch64:SLE-Micro-5.2-GM"
i18n-placeholder="@@distro.overview.filter-placeholder"
#input
/>
</mat-form-field>
<table mat-table [dataSource]="dataSource" class="mat-elevation-z8" matSort>
<!-- Name Column -->
<ng-container matColumnDef="name">
<th mat-header-cell *matHeaderCellDef i18n="@@table.col.name">Name</th>
<td mat-cell *matCellDef="let element">
<a (click)="showDistro(element.uid, element.name)"
>{{ element.name }}
<mat-icon class="link-icon" aria-hidden="true"
>arrow_outward</mat-icon
></a
>
</td>
</ng-container>
<!-- Breed Column -->
<ng-container matColumnDef="breed">
<th mat-header-cell *matHeaderCellDef i18n="@@distro.overview.col.breed">
Breed
</th>
<td mat-cell *matCellDef="let element">
<a [routerLink]="['/signatures']" [queryParams]="{ breed: element.breed }"
>{{ element.breed }}
<mat-icon class="link-icon" aria-hidden="true"
>arrow_outward</mat-icon
></a
>
</td>
</ng-container>
<!-- OsVersion Column -->
<ng-container matColumnDef="os_version">
<th
mat-header-cell
*matHeaderCellDef
i18n="@@distro.overview.col.os-version"
>
Operating System Version
</th>
<td mat-cell *matCellDef="let element">
@if (element.os_version) {
<a
class="os_version_link"
[routerLink]="['/signatures']"
[queryParams]="{
breed: element.breed,
osVersion: element.os_version,
}"
>{{ element.os_version }}
<mat-icon class="link-icon" aria-hidden="true"
>arrow_outward</mat-icon
></a
>
}
</td>
</ng-container>
<ng-container matColumnDef="actions">
<th mat-header-cell *matHeaderCellDef></th>
<td mat-cell *matCellDef="let element">
<button mat-icon-button [matMenuTriggerFor]="menu">
<mat-icon>more_vert</mat-icon>
</button>
<mat-menu #menu="matMenu">
<button mat-menu-item (click)="showDistro(element.uid, element.name)">
<mat-icon>visibility</mat-icon>
<span i18n="@@item.action.show-details">Show details</span>
</button>
<button mat-menu-item (click)="renameDistro(element.uid, element.name)">
<mat-icon>edit</mat-icon>
<span i18n="@@item.action.rename">Rename</span>
</button>
<button mat-menu-item (click)="deleteDistro(element.uid, element.name)">
<mat-icon>delete</mat-icon>
<span i18n="@@item.action.delete">Delete</span>
</button>
</mat-menu>
</td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns"></tr>
</table>
<mat-paginator
[length]="100"
[pageSize]="10"
[pageSizeOptions]="[5, 10, 25, 100]"
aria-label="Select page"
i18n-aria-label="@@paginator.select-page"
>
</mat-paginator>
./distros-overview.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;
}
.form-replicate {
min-width: 150px;
max-width: 600px;
width: 100%;
}
.form-field-full-width {
width: 100%;
}
a {
display: flex;
align-items: center;
text-decoration: none;
color: black;
cursor: pointer;
width: fit-content;
}
.link-icon {
margin-left: 5px;
font-size: 16px;
width: 20px;
height: 20px;
color: #0000004b;
}
table.mat-mdc-table {
border-radius: 14px 14px 0 0;
box-shadow: none;
overflow: hidden;
background-color: white;
}
// Table cell
.mat-mdc-header-cell {
border-bottom: 1px solid #cbcbcb;
}
.mat-mdc-cell {
border-bottom: 1px solid #cbcbcb;
}
.mat-mdc-paginator {
border-radius: 0 0 12px 12px;
background-color: white;
}
:host-context(.dark-theme) .mat-mdc-table {
background-color: #1a1b1f;
}
:host-context(.dark-theme) .mat-mdc-paginator {
background-color: #1a1b1f;
}
:host-context(.dark-theme) .mat-mdc-header-cell {
border-bottom: 1px solid #555555;
}
:host-context(.dark-theme) .mat-mdc-cell {
border-bottom: 1px solid #555555;
}
:host-context(.dark-theme) a {
color: white;
}
:host-context(.dark-theme) .link-icon {
color: rgba(255, 255, 255, 0.372);
}