feat: Added grade color directive

This commit is contained in:
2025-06-14 11:02:41 +02:00
parent 3b3f4fd3b1
commit 4007dff254
6 changed files with 47 additions and 23 deletions

View File

@@ -2,7 +2,7 @@
<app-room-chooser [rooms]="rooms" (room)="roomNumber($event)"/> <app-room-chooser [rooms]="rooms" (room)="roomNumber($event)"/>
<form [formGroup]="form"> <form [formGroup]="form">
<p>Czystość pokoju {{room}} na {{_date.toFormat("cccc, D")}}</p> <p>Czystość pokoju {{room}} na {{_date.toFormat("cccc, D")}}</p>
<p>Ocena: {{grade}}</p> <p>Ocena: <span [appGradeColor]="grade">{{grade}}</span></p>
<div id="buttons"> <div id="buttons">
<button mat-mini-fab (click)="downloadData()" color="accent"><mat-icon>cancel</mat-icon></button> <button mat-mini-fab (click)="downloadData()" color="accent"><mat-icon>cancel</mat-icon></button>
<button mat-mini-fab (click)="attendence()" color="accent"><mat-icon>overview</mat-icon></button> <button mat-mini-fab (click)="attendence()" color="accent"><mat-icon>overview</mat-icon></button>
@@ -31,4 +31,4 @@
<mat-label>Dodatkowe uwagi</mat-label> <mat-label>Dodatkowe uwagi</mat-label>
<textarea matNativeControl cdkTextareaAutosize formControlName="tips"></textarea> <textarea matNativeControl cdkTextareaAutosize formControlName="tips"></textarea>
</mat-form-field> </mat-form-field>
</form> </form>

View File

@@ -1,7 +1,7 @@
<h1 mat-dialog-title>Czystość</h1> <h1 mat-dialog-title>Czystość</h1>
<mat-dialog-content> <mat-dialog-content>
@if (grade) { @if (grade) {
<h1>Twoja ocena: <span [ngStyle]="gradeColor()">{{grade}}</span></h1> <h1>Twoja ocena: <span [appGradeColor]="grade">{{grade}}</span></h1>
} }
@else { @else {
<h1>Nie oceniono</h1> <h1>Nie oceniono</h1>
@@ -21,4 +21,4 @@
</mat-dialog-content> </mat-dialog-content>
<mat-dialog-actions align="end"> <mat-dialog-actions align="end">
<button mat-icon-button mat-dialog-close><mat-icon>close</mat-icon></button> <button mat-icon-button mat-dialog-close><mat-icon>close</mat-icon></button>
</mat-dialog-actions> </mat-dialog-actions>

View File

@@ -38,23 +38,4 @@ export class CleanComponent implements OnInit {
} }
}) })
} }
protected gradeColor() {
switch (this.grade) {
case 1:
return { color: 'red' }
case 2:
return { color: 'darkorange' }
case 3:
return { color: 'orange' }
case 4:
return { color: 'olive' }
case 5:
return { color: 'green' }
case 6:
return { color: 'springgreen' }
default:
return { color: 'inherit' }
}
}
} }

View File

@@ -87,6 +87,7 @@ import { UserSearchComponent } from './commonComponents/user-search/user-search.
import { StartAdminComponent } from './admin-view/start/start.component' import { StartAdminComponent } from './admin-view/start/start.component'
import { provideLuxonDateAdapter } from '@angular/material-luxon-adapter'; import { provideLuxonDateAdapter } from '@angular/material-luxon-adapter';
import { LoadShadeComponent } from './commonComponents/load-shade/load-shade.component' import { LoadShadeComponent } from './commonComponents/load-shade/load-shade.component'
import { GradeColorDirective } from './grade-color.directive'
@NgModule({ @NgModule({
declarations: [ declarations: [
@@ -139,6 +140,7 @@ import { LoadShadeComponent } from './commonComponents/load-shade/load-shade.com
UserSearchComponent, UserSearchComponent,
StartAdminComponent, StartAdminComponent,
LoadShadeComponent, LoadShadeComponent,
GradeColorDirective,
], ],
bootstrap: [AppComponent], bootstrap: [AppComponent],
imports: [ imports: [

View File

@@ -0,0 +1,8 @@
import { GradeColorDirective } from './grade-color.directive';
describe('GradeColorDirective', () => {
it('should create an instance', () => {
const directive = new GradeColorDirective();
expect(directive).toBeTruthy();
});
});

View File

@@ -0,0 +1,33 @@
import { Directive, HostBinding, input } from '@angular/core';
@Directive({
selector: 'span[appGradeColor]',
standalone: false
})
export class GradeColorDirective {
appGradeColor = input<number>()
constructor() { }
@HostBinding("style")
get gc() {
switch (this.appGradeColor()) {
case 1:
return { color: 'red' }
case 2:
return { color: 'darkorange' }
case 3:
return { color: 'orange' }
case 4:
return { color: 'olive' }
case 5:
return { color: 'green' }
case 6:
return { color: 'springgreen' }
default:
return { color: 'inherit' }
}
}
}