issue-18 #28

Merged
sebastian merged 55 commits from issue-18 into master 2023-10-28 19:36:14 +02:00
8 changed files with 184 additions and 14 deletions
Showing only changes of commit 00a15e91ea - Show all commits

View File

@ -4,8 +4,16 @@
<option name="autoReloadType" value="SELECTIVE" /> <option name="autoReloadType" value="SELECTIVE" />
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="3a869f59-290a-4ab2-b036-a878ce801bc4" name="Changes" comment="Remove update spamming in console"> <list default="true" id="3a869f59-290a-4ab2-b036-a878ce801bc4" name="Changes" comment="Start task now from Taskoverview in Dashboard">
<change beforePath="$PROJECT_DIR$/src/main/java/core/api/controller/ScheduleController.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/core/api/controller/ScheduleController.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/core/api/controller/TaskController.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/core/api/controller/TaskController.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/core/entities/timemanager/BasicTaskSchedule.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/core/entities/timemanager/BasicTaskSchedule.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/core/entities/timemanager/Task.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/core/entities/timemanager/Task.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/core/services/TaskScheduleService.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/core/services/TaskScheduleService.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/core/services/TaskService.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/core/services/TaskService.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../frontend/src/app/dashboard/task-overview/task-overview.component.html" beforeDir="false" afterPath="$PROJECT_DIR$/../frontend/src/app/dashboard/task-overview/task-overview.component.html" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../frontend/src/app/dashboard/task-overview/task-overview.component.ts" beforeDir="false" afterPath="$PROJECT_DIR$/../frontend/src/app/dashboard/task-overview/task-overview.component.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../openapi.yaml" beforeDir="false" afterPath="$PROJECT_DIR$/../openapi.yaml" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -102,7 +110,7 @@
<workItem from="1698298897364" duration="4242000" /> <workItem from="1698298897364" duration="4242000" />
<workItem from="1698426430946" duration="665000" /> <workItem from="1698426430946" duration="665000" />
<workItem from="1698474363766" duration="3686000" /> <workItem from="1698474363766" duration="3686000" />
<workItem from="1698499063683" duration="646000" /> <workItem from="1698499063683" duration="4869000" />
</task> </task>
<task id="LOCAL-00001" summary="Structure Taskgroups in Hierarchies"> <task id="LOCAL-00001" summary="Structure Taskgroups in Hierarchies">
<option name="closed" value="true" /> <option name="closed" value="true" />
@ -208,7 +216,15 @@
<option name="project" value="LOCAL" /> <option name="project" value="LOCAL" />
<updated>1698306889808</updated> <updated>1698306889808</updated>
</task> </task>
<option name="localTasksCounter" value="14" /> <task id="LOCAL-00014" summary="Start task now from Taskoverview in Dashboard">
<option name="closed" value="true" />
<created>1698500028161</created>
<option name="number" value="00014" />
<option name="presentableId" value="LOCAL-00014" />
<option name="project" value="LOCAL" />
<updated>1698500028161</updated>
</task>
<option name="localTasksCounter" value="15" />
<servers /> <servers />
</component> </component>
<component name="TypeScriptGeneratedFilesManager"> <component name="TypeScriptGeneratedFilesManager">
@ -230,7 +246,8 @@
<MESSAGE value="Include TaskScheduleStopResponse" /> <MESSAGE value="Include TaskScheduleStopResponse" />
<MESSAGE value="Fix starting schedule and returning active time of schedule after stop" /> <MESSAGE value="Fix starting schedule and returning active time of schedule after stop" />
<MESSAGE value="Remove update spamming in console" /> <MESSAGE value="Remove update spamming in console" />
<option name="LAST_COMMIT_MESSAGE" value="Remove update spamming in console" /> <MESSAGE value="Start task now from Taskoverview in Dashboard" />
<option name="LAST_COMMIT_MESSAGE" value="Start task now from Taskoverview in Dashboard" />
</component> </component>
<component name="XDebuggerManager"> <component name="XDebuggerManager">
<breakpoint-manager> <breakpoint-manager>

View File

@ -1,6 +1,7 @@
package core.api.controller; package core.api.controller;
import core.api.models.auth.SimpleStatusResponse; import core.api.models.auth.SimpleStatusResponse;
import core.api.models.timemanager.taskSchedule.ScheduleInfo;
import core.api.models.timemanager.tasks.TaskEntityInfo; import core.api.models.timemanager.tasks.TaskEntityInfo;
import core.api.models.timemanager.tasks.TaskFieldInfo; import core.api.models.timemanager.tasks.TaskFieldInfo;
import core.entities.timemanager.Task; import core.entities.timemanager.Task;
@ -110,4 +111,19 @@ public class TaskController {
return ResponseEntity.ok(new TaskEntityInfo(taskPermissionResult.getResult())); return ResponseEntity.ok(new TaskEntityInfo(taskPermissionResult.getResult()));
} }
@PostMapping("/tasks/{taskID}/finish")
public ResponseEntity<?> finishTask(@PathVariable long taskID) {
PermissionResult<Task> taskPermissionResult = taskService.getTaskPermissions(taskID, SecurityContextHolder.getContext().getAuthentication().getName());
if (!taskPermissionResult.isHasPermissions()) {
return ResponseEntity.status(403).body(new SimpleStatusResponse("failed"));
}
if (taskPermissionResult.getExitCode() == ServiceExitCode.MISSING_ENTITY) {
return ResponseEntity.status(404).body(new SimpleStatusResponse("failed"));
}
taskService.finishTask(taskPermissionResult.getResult());
return ResponseEntity.ok(new SimpleStatusResponse("success"));
}
} }

View File

@ -2,6 +2,8 @@ package core.entities.timemanager;
import javax.persistence.*; import javax.persistence.*;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.Set; import java.util.Set;
@ -27,7 +29,7 @@ public class Task {
private boolean finished; private boolean finished;
@OneToMany(mappedBy = "task", cascade = CascadeType.ALL, fetch = FetchType.EAGER) @OneToMany(mappedBy = "task", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
private Set<BasicTaskSchedule> basicTaskSchedules; private List<BasicTaskSchedule> basicTaskSchedules;
private int workTime; private int workTime;
@ -128,11 +130,11 @@ public class Task {
this.taskID = taskID; this.taskID = taskID;
} }
public Set<BasicTaskSchedule> getBasicTaskSchedules() { public List<BasicTaskSchedule> getBasicTaskSchedules() {
return basicTaskSchedules; return basicTaskSchedules;
} }
public void setBasicTaskSchedules(Set<BasicTaskSchedule> basicTaskSchedules) { public void setBasicTaskSchedules(List<BasicTaskSchedule> basicTaskSchedules) {
this.basicTaskSchedules = basicTaskSchedules; this.basicTaskSchedules = basicTaskSchedules;
} }

View File

@ -1,6 +1,7 @@
package core.services; package core.services;
import core.api.models.timemanager.tasks.TaskFieldInfo; import core.api.models.timemanager.tasks.TaskFieldInfo;
import core.entities.timemanager.BasicTaskSchedule;
import core.entities.timemanager.Task; import core.entities.timemanager.Task;
import core.entities.timemanager.Taskgroup; import core.entities.timemanager.Taskgroup;
import core.repositories.timemanager.BasicTaskScheduleRepository; import core.repositories.timemanager.BasicTaskScheduleRepository;
@ -9,8 +10,8 @@ import core.repositories.timemanager.TaskgroupRepository;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Collection; import java.time.LocalDateTime;
import java.util.Optional; import java.util.*;
@Service @Service
public class TaskService { public class TaskService {
@ -75,4 +76,26 @@ public class TaskService {
public void clearTasks(Taskgroup taskgroup) { public void clearTasks(Taskgroup taskgroup) {
taskRepository.deleteAllByTaskgroup(taskgroup); taskRepository.deleteAllByTaskgroup(taskgroup);
} }
public void finishTask(Task task) {
//Mark task as finished and remove all unstarted schedules as well as finish all started schedules
task.finish();
taskRepository.save(task);
List<BasicTaskSchedule> removedBasicTaskSchedules = new LinkedList<>();
for(BasicTaskSchedule basicTaskSchedule : task.getBasicTaskSchedules()) {
if(basicTaskSchedule.getStartTime() == null) {
removedBasicTaskSchedules.add(basicTaskSchedule);
} else if(basicTaskSchedule.getFinishedTime() == null) {
ServiceResult<?> result = taskScheduleService.stopSchedule(basicTaskSchedule, true);
System.out.println(result);
}
}
for(BasicTaskSchedule deletedTaskSchedule: removedBasicTaskSchedules) {
task.getBasicTaskSchedules().remove(deletedTaskSchedule);
taskRepository.save(task);
taskScheduleService.deleteBasicSchedule(deletedTaskSchedule);
}
}
} }

View File

@ -147,6 +147,66 @@ export class TaskService {
); );
} }
/**
* finishs task
* finish tasks
* @param taskID internal id of task
* @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body.
* @param reportProgress flag to report request and response progress.
*/
public tasksTaskIDFinishPost(taskID: number, observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<SimpleStatusResponse>;
public tasksTaskIDFinishPost(taskID: number, observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<HttpResponse<SimpleStatusResponse>>;
public tasksTaskIDFinishPost(taskID: number, observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<HttpEvent<SimpleStatusResponse>>;
public tasksTaskIDFinishPost(taskID: number, observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<any> {
if (taskID === null || taskID === undefined) {
throw new Error('Required parameter taskID was null or undefined when calling tasksTaskIDFinishPost.');
}
let localVarHeaders = this.defaultHeaders;
let localVarCredential: string | undefined;
// authentication (API_TOKEN) required
localVarCredential = this.configuration.lookupCredential('API_TOKEN');
if (localVarCredential) {
localVarHeaders = localVarHeaders.set('Authorization', 'Bearer ' + localVarCredential);
}
let localVarHttpHeaderAcceptSelected: string | undefined = options && options.httpHeaderAccept;
if (localVarHttpHeaderAcceptSelected === undefined) {
// to determine the Accept header
const httpHeaderAccepts: string[] = [
'application/json'
];
localVarHttpHeaderAcceptSelected = this.configuration.selectHeaderAccept(httpHeaderAccepts);
}
if (localVarHttpHeaderAcceptSelected !== undefined) {
localVarHeaders = localVarHeaders.set('Accept', localVarHttpHeaderAcceptSelected);
}
let localVarHttpContext: HttpContext | undefined = options && options.context;
if (localVarHttpContext === undefined) {
localVarHttpContext = new HttpContext();
}
let responseType_: 'text' | 'json' = 'json';
if(localVarHttpHeaderAcceptSelected && localVarHttpHeaderAcceptSelected.startsWith('text')) {
responseType_ = 'text';
}
return this.httpClient.post<SimpleStatusResponse>(`${this.configuration.basePath}/tasks/${encodeURIComponent(String(taskID))}/finish`,
null,
{
context: localVarHttpContext,
responseType: <any>responseType_,
withCredentials: this.configuration.withCredentials,
headers: localVarHeaders,
observe: observe,
reportProgress: reportProgress
}
);
}
/** /**
* gets taskdetails * gets taskdetails
* loads information about a given task * loads information about a given task

View File

@ -9,6 +9,6 @@
<mat-card-actions> <mat-card-actions>
<button mat-raised-button color="primary" class="btn-without-radius" (click)="startTaskNow(task)">Start now</button> <button mat-raised-button color="primary" class="btn-without-radius" (click)="startTaskNow(task)">Start now</button>
<button mat-raised-button class="yellowBtn btn-without-radius">Schedule</button> <button mat-raised-button class="yellowBtn btn-without-radius">Schedule</button>
<button mat-raised-button class="greenBtn btn-without-radius">Finish</button> <button mat-raised-button class="greenBtn btn-without-radius" (click)="finishTask(task)">Finish</button>
</mat-card-actions> </mat-card-actions>
</mat-card> </mat-card>

View File

@ -1,5 +1,5 @@
import {Component, EventEmitter, Input, Output} from '@angular/core'; import {Component, EventEmitter, Input, Output} from '@angular/core';
import {BasicScheduleEntityInfo, ScheduleInfo, ScheduleService, TaskOverviewInfo} from "../../../api"; import {BasicScheduleEntityInfo, ScheduleInfo, ScheduleService, TaskOverviewInfo, TaskService} from "../../../api";
import {MatSnackBar} from "@angular/material/snack-bar"; import {MatSnackBar} from "@angular/material/snack-bar";
@Component({ @Component({
@ -13,7 +13,8 @@ export class TaskOverviewComponent {
@Output('onStartNow') startNowEmitter: EventEmitter<ScheduleInfo> = new EventEmitter<ScheduleInfo>(); @Output('onStartNow') startNowEmitter: EventEmitter<ScheduleInfo> = new EventEmitter<ScheduleInfo>();
constructor(private scheduleService: ScheduleService, constructor(private scheduleService: ScheduleService,
private snackbar: MatSnackBar) { private snackbar: MatSnackBar,
private taskService: TaskService) {
} }
startTaskNow(task: TaskOverviewInfo) { startTaskNow(task: TaskOverviewInfo) {
@ -36,6 +37,19 @@ export class TaskOverviewComponent {
} }
finishTask(task: TaskOverviewInfo) { finishTask(task: TaskOverviewInfo) {
this.taskService.tasksTaskIDFinishPost(task.taskID).subscribe({
next: resp => {
},
error: err => {
if(err.status == 403) {
this.snackbar.open("No permission", "", {duration: 2000});
} else if(err.status == 404) {
this.snackbar.open("Task not found", "", {duration: 2000});
} else {
this.snackbar.open("Unexpected error", "", {duration: 2000});
}
}
})
} }
} }

View File

@ -1171,6 +1171,44 @@ paths:
schema: schema:
type: object type: object
$ref: "#/components/schemas/SimpleStatusResponse" $ref: "#/components/schemas/SimpleStatusResponse"
/tasks/{taskID}/finish:
post:
security:
- API_TOKEN: []
tags:
- task
summary: finishs task
description: finish tasks
parameters:
- name: taskID
in: path
description: internal id of task
required: true
schema:
type: number
example: 1
responses:
200:
description: Anfrage erfolgreich
content:
'application/json':
schema:
type: object
$ref: "#/components/schemas/SimpleStatusResponse"
403:
description: No permission
content:
'application/json':
schema:
type: object
$ref: "#/components/schemas/SimpleStatusResponse"
404:
description: Taskgroup does not exist
content:
'application/json':
schema:
type: object
$ref: "#/components/schemas/SimpleStatusResponse"
/schedules: /schedules:
get: get:
security: security: