change file structure
Reviewed-on: #21 Reviewed-by: Get in my car i have candy <huydw@proton.me>
This commit is contained in:
0
src/app/qualification/table/table.component.css
Normal file
0
src/app/qualification/table/table.component.css
Normal file
42
src/app/qualification/table/table.component.html
Normal file
42
src/app/qualification/table/table.component.html
Normal file
@ -0,0 +1,42 @@
|
||||
<div class="flex">
|
||||
<h1 class="text-2xl font-semibold">Qualifications</h1>
|
||||
<button mat-flat-button class="ml-auto bg-blue-600" (click)="openCreateModal()">
|
||||
<mat-icon class="mr-2">add</mat-icon>
|
||||
Create qualification
|
||||
</button>
|
||||
</div>
|
||||
|
||||
@if (qualifications$ | async; as qualifications) {
|
||||
@if (qualifications) {
|
||||
<table
|
||||
mat-table
|
||||
[dataSource]="qualifications"
|
||||
class="mat-elevation-z8"
|
||||
>
|
||||
<ng-container matColumnDef="id">
|
||||
<th mat-header-cell *matHeaderCellDef>ID</th>
|
||||
<td mat-cell *matCellDef="let qualification">{{ qualification.id }}</td>
|
||||
</ng-container>
|
||||
|
||||
<ng-container matColumnDef="skill">
|
||||
<th mat-header-cell *matHeaderCellDef>Skill</th>
|
||||
<td mat-cell *matCellDef="let qualification">{{ qualification.skill }}</td>
|
||||
</ng-container>
|
||||
|
||||
<ng-container matColumnDef="actions">
|
||||
<th mat-header-cell *matHeaderCellDef>Actions</th>
|
||||
<td mat-cell *matCellDef="let qualification">
|
||||
<button mat-icon-button color="primary" (click)="openEditModal(qualification)">
|
||||
<mat-icon>edit</mat-icon>
|
||||
</button>
|
||||
<button mat-icon-button color="warn">
|
||||
<mat-icon>delete</mat-icon>
|
||||
</button>
|
||||
</td>
|
||||
</ng-container>
|
||||
|
||||
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
|
||||
<tr mat-row *matRowDef="let row; columns: displayedColumns"></tr>
|
||||
</table>
|
||||
}
|
||||
}
|
78
src/app/qualification/table/table.component.ts
Normal file
78
src/app/qualification/table/table.component.ts
Normal file
@ -0,0 +1,78 @@
|
||||
import {Component, inject, OnInit} from '@angular/core';
|
||||
import {Observable} from "rxjs";
|
||||
import {Qualification} from "../Qualification";
|
||||
import {AsyncPipe} from "@angular/common";
|
||||
import {
|
||||
MatCell, MatCellDef,
|
||||
MatColumnDef,
|
||||
MatHeaderCell,
|
||||
MatHeaderCellDef,
|
||||
MatHeaderRow, MatHeaderRowDef,
|
||||
MatRow, MatRowDef,
|
||||
MatTable
|
||||
} from "@angular/material/table";
|
||||
import QualificationService from "../../services/qualification.service";
|
||||
import {MatDialog} from "@angular/material/dialog";
|
||||
import {CreateComponent} from "../create/create.component";
|
||||
import {MatIcon} from "@angular/material/icon";
|
||||
import {MatButton, MatIconButton} from "@angular/material/button";
|
||||
import {EditComponent} from "../edit/edit.component";
|
||||
|
||||
@Component({
|
||||
selector: 'app-qualifications',
|
||||
imports: [
|
||||
AsyncPipe,
|
||||
MatTable,
|
||||
MatHeaderCell,
|
||||
MatColumnDef,
|
||||
MatCell,
|
||||
MatHeaderRow,
|
||||
MatRow,
|
||||
MatHeaderCellDef,
|
||||
MatCellDef,
|
||||
MatHeaderRowDef,
|
||||
MatRowDef,
|
||||
MatIcon,
|
||||
MatIconButton,
|
||||
MatButton
|
||||
],
|
||||
templateUrl: './table.component.html',
|
||||
styleUrl: './table.component.css'
|
||||
})
|
||||
export class QualificationsComponent implements OnInit{
|
||||
public qualifications$!: Observable<Qualification[]>;
|
||||
public readonly displayedColumns: string[] = ['id', 'skill', 'actions'];
|
||||
|
||||
private readonly dialog: MatDialog = inject(MatDialog);
|
||||
private readonly qualificationService: QualificationService = inject(QualificationService);
|
||||
|
||||
ngOnInit() {
|
||||
this.loadQualifications();
|
||||
}
|
||||
|
||||
private loadQualifications() {
|
||||
this.qualifications$ = this.qualificationService.getAll();
|
||||
}
|
||||
|
||||
openCreateModal() {
|
||||
const dialogRef = this.dialog.open(CreateComponent);
|
||||
|
||||
dialogRef.afterClosed().subscribe(result => {
|
||||
if (result) {
|
||||
this.loadQualifications();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
openEditModal(qualification: Qualification) {
|
||||
const dialogRef = this.dialog.open(EditComponent, {
|
||||
data: qualification
|
||||
});
|
||||
|
||||
dialogRef.afterClosed().subscribe(result => {
|
||||
if (result) {
|
||||
this.loadQualifications();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user