issue-96: Fix TaskStatus #104

Merged
sebastian merged 2 commits from issue-96 into master 2024-03-15 07:22:53 +01:00
5 changed files with 68 additions and 15 deletions
Showing only changes of commit 313d329636 - Show all commits

View File

@ -7220,9 +7220,9 @@
"dev": true "dev": true
}, },
"node_modules/follow-redirects": { "node_modules/follow-redirects": {
"version": "1.15.3", "version": "1.15.6",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.3.tgz", "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.6.tgz",
"integrity": "sha512-1VzOtuEM8pC9SFU1E+8KfTjZyMztRsgEfwQl44z8A25uy13jSzTj6dyK2Df52iV0vgHCfBwLhDWevLn95w5v6Q==", "integrity": "sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA==",
"dev": true, "dev": true,
"funding": [ "funding": [
{ {
@ -8103,9 +8103,9 @@
} }
}, },
"node_modules/ip": { "node_modules/ip": {
"version": "2.0.0", "version": "2.0.1",
"resolved": "https://registry.npmjs.org/ip/-/ip-2.0.0.tgz", "resolved": "https://registry.npmjs.org/ip/-/ip-2.0.1.tgz",
"integrity": "sha512-WKa+XuLG1A1R0UWhl2+1XQSi+fZWMsYKffMZTTYsiZaUD8k2yDAj5atimTUD2TZkyCkNEeYE5NhFZmupOGtjYQ==", "integrity": "sha512-lJUL9imLTNi1ZfXT+DU6rBBdbiKGBuay9B6xGSPVjUeQwaH1RIGqef8RZkUtHioLmSNpPR5M4HVKJGm1j8FWVQ==",
"dev": true "dev": true
}, },
"node_modules/ipaddr.js": { "node_modules/ipaddr.js": {

View File

@ -29,7 +29,7 @@
<ng-container matColumnDef="finished"> <ng-container matColumnDef="finished">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Finished </th> <th mat-header-cell *matHeaderCellDef mat-sort-header> Finished </th>
<td mat-cell *matCellDef="let task"> <td mat-cell *matCellDef="let task">
<mat-checkbox [checked]="task.finished" [contentEditable]="false" disableRipple="true" (click)="$event.preventDefault()"></mat-checkbox> <mat-checkbox [checked]="task.finished" [contentEditable]="false" (click)="$event.preventDefault()"></mat-checkbox>
</td> </td>
</ng-container> </ng-container>
<ng-container matColumnDef="status"> <ng-container matColumnDef="status">

View File

@ -9,6 +9,7 @@ import {MatDialog} from "@angular/material/dialog";
import {MatSnackBar} from "@angular/material/snack-bar"; import {MatSnackBar} from "@angular/material/snack-bar";
import {ClearTaskDialogComponent, ClearTaskDialogData} from "../clear-task-dialog/clear-task-dialog.component"; import {ClearTaskDialogComponent, ClearTaskDialogData} from "../clear-task-dialog/clear-task-dialog.component";
import * as moment from "moment/moment"; import * as moment from "moment/moment";
import {TaskStatus, TaskStatusService} from "../task-status.service";
@Component({ @Component({
selector: 'app-task-dashboard', selector: 'app-task-dashboard',
@ -39,7 +40,8 @@ export class TaskDashboardComponent implements OnChanges{
constructor(private taskService: TaskService, constructor(private taskService: TaskService,
private dialog: MatDialog, private dialog: MatDialog,
private snackbar: MatSnackBar) { private snackbar: MatSnackBar,
public taskStatusService: TaskStatusService) {
} }
@ -53,13 +55,8 @@ export class TaskDashboardComponent implements OnChanges{
} }
getStatusOfTask(task: TaskEntityInfo) { getStatusOfTask(task: TaskEntityInfo) {
if(moment(task.deadline, 'YYYY-MM-DDTHH:mm:ss.SSSZ').isBefore(moment())) { const taskStatus = this.taskStatusService.computeTaskStatus(task);
return "🔴"; return this.taskStatusService.convertTaskStatusToColor(taskStatus);
} else if(task.finishable && !task.hasPlannedSchedules){
return "🟠";
} else {
return "🟢";
}
} }
deleteTask(deletedTask: TaskEntityInfo) { deleteTask(deletedTask: TaskEntityInfo) {
@ -108,4 +105,6 @@ export class TaskDashboardComponent implements OnChanges{
data.push(task) data.push(task)
this.datasource.data = data; this.datasource.data = data;
} }
protected readonly TaskStatus = TaskStatus;
} }

View File

@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';
import { TaskStatusService } from './task-status.service';
describe('TaskStatusService', () => {
let service: TaskStatusService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(TaskStatusService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});

View File

@ -0,0 +1,38 @@
import { Injectable } from '@angular/core';
import {TaskEntityInfo} from "../../api";
import * as moment from "moment";
export enum TaskStatus {
OK,
WARNING,
ATTENTION,
DEAD
}
@Injectable({
providedIn: 'root'
})
export class TaskStatusService {
constructor() { }
computeTaskStatus(task: TaskEntityInfo): TaskStatus {
if(!task.finished && task.deadline != null && moment(task.deadline, 'YYYY-MM-DDTHH:mm:ss.SSSZ').isBefore(moment())) {
return TaskStatus.DEAD;
} else if(!task.finished && task.deadline != null && !task.hasPlannedSchedules) {
return TaskStatus.ATTENTION
} else if(!task.finished && !task.hasPlannedSchedules) {
return TaskStatus.WARNING
} else {
return TaskStatus.OK;
}
}
convertTaskStatusToColor(taskStatus: TaskStatus) {
switch (taskStatus) {
case TaskStatus.OK: return "🟢";
case TaskStatus.WARNING: return "🟠";
case TaskStatus.ATTENTION: return "🔴";
case TaskStatus.DEAD: return "⚫";
}
}
}