issue-96: Fix TaskStatus #104

Merged
sebastian merged 2 commits from issue-96 into master 2024-03-15 07:22:53 +01:00
6 changed files with 73 additions and 23 deletions

View File

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

View File

@ -29,7 +29,7 @@
<ng-container matColumnDef="finished">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Finished </th>
<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>
</ng-container>
<ng-container matColumnDef="status">

View File

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

View File

@ -16,6 +16,7 @@ import {TaskEditorComponent} from "../task-editor/task-editor.component";
import {TaskEditorData} from "../task-editor/TaskEditorData";
import * as moment from "moment";
import {ScheduleDashboardComponent} from "../../schedules/schedule-dashboard/schedule-dashboard.component";
import {TaskStatusService} from "../task-status.service";
@Component({
selector: 'app-task-detail-overview',
@ -53,7 +54,8 @@ export class TaskDetailOverviewComponent implements OnInit {
private taskService: TaskService,
private dialog: MatDialog,
private scheduleService: ScheduleService,
private router: Router) {
private router: Router,
private taskStatusService: TaskStatusService) {
}
ngOnInit(): void {
@ -102,13 +104,8 @@ export class TaskDetailOverviewComponent implements OnInit {
}
getStatusOfTask(task: TaskEntityInfo ) {
if(moment(task.deadline, 'YYYY-MM-DDTHH:mm:ss.SSSZ').isBefore(moment())) {
return "🔴";
} else if(this.schedules.length == 0 && this.schedulesLoaded){
return "🟠";
} else {
return "🟢";
}
const taskStatus = this.taskStatusService.computeTaskStatus(task);
return this.taskStatusService.convertTaskStatusToColor(taskStatus);
}
calcProgress() {

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 "⚫";
}
}
}