Structure Taskgroups in Hierarchies

This commit is contained in:
Sebastian 2023-10-01 21:22:04 +02:00
parent 5a02e40345
commit 33b8163d21
16 changed files with 361 additions and 24 deletions

View File

@ -5,12 +5,25 @@
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="3a869f59-290a-4ab2-b036-a878ce801bc4" name="Changes" comment=""> <list default="true" id="3a869f59-290a-4ab2-b036-a878ce801bc4" name="Changes" comment="">
<change beforePath="$PROJECT_DIR$/.idea/.gitignore" beforeDir="false" /> <change afterPath="$PROJECT_DIR$/../frontend/src/app/taskgroups/taskgroup-creation/TaskgroupCreationData.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/misc.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/uiDesigner.xml" beforeDir="false" /> <change beforePath="$PROJECT_DIR$/src/main/java/core/api/controller/TaskgroupController.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/core/api/controller/TaskgroupController.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.mvn/wrapper/maven-wrapper.properties" beforeDir="false" /> <change beforePath="$PROJECT_DIR$/src/main/java/core/api/models/timemanager/taskgroup/TaskgroupEntityInfo.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/core/api/models/timemanager/taskgroup/TaskgroupEntityInfo.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/resources/application.properties" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/resources/application.properties" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/main/java/core/api/models/timemanager/taskgroup/TaskgroupFieldInfo.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/core/api/models/timemanager/taskgroup/TaskgroupFieldInfo.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/core/entities/timemanager/Taskgroup.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/core/entities/timemanager/Taskgroup.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/core/repositories/timemanager/TaskgroupRepository.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/core/repositories/timemanager/TaskgroupRepository.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/core/services/TaskgroupService.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/core/services/TaskgroupService.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../frontend/src/api/api.module.ts" beforeDir="false" afterPath="$PROJECT_DIR$/../frontend/src/api/api.module.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../frontend/src/api/api/api.ts" beforeDir="false" afterPath="$PROJECT_DIR$/../frontend/src/api/api/api.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../frontend/src/api/api/taskgroup.service.ts" beforeDir="false" afterPath="$PROJECT_DIR$/../frontend/src/api/api/taskgroup.service.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../frontend/src/api/model/models.ts" beforeDir="false" afterPath="$PROJECT_DIR$/../frontend/src/api/model/models.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../frontend/src/api/model/taskgroupEntityInfo.ts" beforeDir="false" afterPath="$PROJECT_DIR$/../frontend/src/api/model/taskgroupEntityInfo.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../frontend/src/api/model/taskgroupFieldInfo.ts" beforeDir="false" afterPath="$PROJECT_DIR$/../frontend/src/api/model/taskgroupFieldInfo.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../frontend/src/app/app-routing.module.ts" beforeDir="false" afterPath="$PROJECT_DIR$/../frontend/src/app/app-routing.module.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../frontend/src/app/taskgroups/taskgroup-creation/taskgroup-creation.component.ts" beforeDir="false" afterPath="$PROJECT_DIR$/../frontend/src/app/taskgroups/taskgroup-creation/taskgroup-creation.component.ts" afterDir="false" /> <change beforePath="$PROJECT_DIR$/../frontend/src/app/taskgroups/taskgroup-creation/taskgroup-creation.component.ts" beforeDir="false" afterPath="$PROJECT_DIR$/../frontend/src/app/taskgroups/taskgroup-creation/taskgroup-creation.component.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../frontend/src/app/taskgroups/taskgroup-dashboard/taskgroup-dashboard.component.html" beforeDir="false" afterPath="$PROJECT_DIR$/../frontend/src/app/taskgroups/taskgroup-dashboard/taskgroup-dashboard.component.html" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../frontend/src/app/taskgroups/taskgroup-dashboard/taskgroup-dashboard.component.ts" beforeDir="false" afterPath="$PROJECT_DIR$/../frontend/src/app/taskgroups/taskgroup-dashboard/taskgroup-dashboard.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" />
@ -69,11 +82,22 @@
<option name="presentableId" value="Default" /> <option name="presentableId" value="Default" />
<updated>1695647243767</updated> <updated>1695647243767</updated>
<workItem from="1695647249321" duration="397000" /> <workItem from="1695647249321" duration="397000" />
<workItem from="1696183811713" duration="179000" /> <workItem from="1696183811713" duration="3909000" />
</task> </task>
<servers /> <servers />
</component> </component>
<component name="TypeScriptGeneratedFilesManager"> <component name="TypeScriptGeneratedFilesManager">
<option name="version" value="3" /> <option name="version" value="3" />
</component> </component>
<component name="XDebuggerManager">
<breakpoint-manager>
<breakpoints>
<line-breakpoint enabled="true" type="java-line">
<url>file://$PROJECT_DIR$/src/main/java/core/services/TaskgroupService.java</url>
<line>52</line>
<option name="timeStamp" value="1" />
</line-breakpoint>
</breakpoints>
</breakpoint-manager>
</component>
</project> </project>

View File

@ -10,11 +10,13 @@ import core.services.ServiceResult;
import core.services.TaskgroupService; import core.services.TaskgroupService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.scheduling.config.Task;
import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.validation.Valid; import javax.validation.Valid;
import java.util.List; import java.util.List;
import java.util.Set;
@CrossOrigin(origins = "*", maxAge = 3600) @CrossOrigin(origins = "*", maxAge = 3600)
@RestController @RestController
@ -74,8 +76,23 @@ public class TaskgroupController {
@GetMapping("/taskgroups") @GetMapping("/taskgroups")
public ResponseEntity<List<TaskgroupEntityInfo>> listTaskgroupsOfUser() { public ResponseEntity<List<TaskgroupEntityInfo>> listTaskgroupsOfUser() {
List<Taskgroup> taskgroups = taskgroupService.getTaskgroupsByUser(SecurityContextHolder.getContext().getAuthentication().getName()); List<Taskgroup> taskgroups = taskgroupService.getTopTaskgroupsByUser(SecurityContextHolder.getContext().getAuthentication().getName());
List<TaskgroupEntityInfo> taskgroupEntityInfos = taskgroups.stream().map(TaskgroupEntityInfo::new).toList(); List<TaskgroupEntityInfo> taskgroupEntityInfos = taskgroups.stream().map(TaskgroupEntityInfo::new).toList();
return ResponseEntity.ok(taskgroupEntityInfos); return ResponseEntity.ok(taskgroupEntityInfos);
} }
@GetMapping("/taskgroups/{taskgroupID}")
public ResponseEntity<?> getDetails(@PathVariable long taskgroupID) {
PermissionResult<Taskgroup> taskgroupPermissionResult = taskgroupService.getTaskgroupByIDAndUsername(taskgroupID, SecurityContextHolder.getContext().getAuthentication().getName());
if(!taskgroupPermissionResult.isHasPermissions()) {
return ResponseEntity.status(403).body(new SimpleStatusResponse("failed"));
}
if(taskgroupPermissionResult.getExitCode() == ServiceExitCode.MISSING_ENTITY) {
return ResponseEntity.status(404).body(new SimpleStatusResponse("failed"));
}
Set<Taskgroup> children = taskgroupPermissionResult.getResult().getChildren();
return ResponseEntity.ok(children.stream().map(TaskgroupEntityInfo::new));
}
} }

View File

@ -7,9 +7,17 @@ public class TaskgroupEntityInfo {
private long taskgroupID; private long taskgroupID;
private String taskgroupName; private String taskgroupName;
private TaskgroupEntityInfo parentTaskgroup;
public TaskgroupEntityInfo(Taskgroup taskgroup) { public TaskgroupEntityInfo(Taskgroup taskgroup) {
this.taskgroupID = taskgroup.getTaskgroupID(); this.taskgroupID = taskgroup.getTaskgroupID();
this.taskgroupName = taskgroup.getTaskgroupName(); this.taskgroupName = taskgroup.getTaskgroupName();
if(taskgroup.getParent() == null) {
this.parentTaskgroup = null;
} else {
this.parentTaskgroup = new TaskgroupEntityInfo(taskgroup.getParent());
}
} }
public long getTaskgroupID() { public long getTaskgroupID() {
@ -27,4 +35,12 @@ public class TaskgroupEntityInfo {
public void setTaskgroupName(String taskgroupName) { public void setTaskgroupName(String taskgroupName) {
this.taskgroupName = taskgroupName; this.taskgroupName = taskgroupName;
} }
public TaskgroupEntityInfo getParentTaskgroup() {
return parentTaskgroup;
}
public void setParentTaskgroup(TaskgroupEntityInfo parentTaskgroup) {
this.parentTaskgroup = parentTaskgroup;
}
} }

View File

@ -13,6 +13,8 @@ public class TaskgroupFieldInfo {
@Length(max = 255) @Length(max = 255)
private String name; private String name;
private long parentID;
public String getName() { public String getName() {
return name; return name;
} }
@ -20,4 +22,12 @@ public class TaskgroupFieldInfo {
public void setName(String name) { public void setName(String name) {
this.name = name; this.name = name;
} }
public long getParentID() {
return parentID;
}
public void setParentID(long parentID) {
this.parentID = parentID;
}
} }

View File

@ -4,6 +4,7 @@ import core.entities.User;
import javax.persistence.*; import javax.persistence.*;
import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotBlank;
import java.util.Set;
@Entity @Entity
@Table(name= "taskgroups") @Table(name= "taskgroups")
@ -21,6 +22,13 @@ public class Taskgroup {
@JoinColumn(name = "taskgroupuser", nullable = false) @JoinColumn(name = "taskgroupuser", nullable = false)
private User user; private User user;
@OneToMany(mappedBy = "parent", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
private Set<Taskgroup> children;
@ManyToOne
@JoinColumn(name = "parent_id")
private Taskgroup parent;
public Taskgroup(String taskgroupName, User user) { public Taskgroup(String taskgroupName, User user) {
this.taskgroupName = taskgroupName; this.taskgroupName = taskgroupName;
this.user = user; this.user = user;
@ -52,4 +60,20 @@ public class Taskgroup {
public void setUser(User user) { public void setUser(User user) {
this.user = user; this.user = user;
} }
public Set<Taskgroup> getChildren() {
return children;
}
public void setChildren(Set<Taskgroup> children) {
this.children = children;
}
public Taskgroup getParent() {
return parent;
}
public void setParent(Taskgroup parent) {
this.parent = parent;
}
} }

View File

@ -18,6 +18,9 @@ public interface TaskgroupRepository extends CrudRepository<Taskgroup, Long> {
@Query("SELECT tg FROM Taskgroup tg WHERE tg.user.username = ?1") @Query("SELECT tg FROM Taskgroup tg WHERE tg.user.username = ?1")
List<Taskgroup> findAllByUser(String username); List<Taskgroup> findAllByUser(String username);
@Query("SELECT tg FROM Taskgroup tg WHERE tg.user.username = ?1 AND tg.parent IS NULL")
List<Taskgroup> findAllTopTaskgroupsByUser(String username);
@Modifying @Modifying
@Transactional @Transactional
void deleteAllByUser(User user); void deleteAllByUser(User user);

View File

@ -40,8 +40,20 @@ public class TaskgroupService {
} }
if(!taskgroupRepository.existsByTaskgroupNameAndUser(taskData.getName(), user.get())) { if(!taskgroupRepository.existsByTaskgroupNameAndUser(taskData.getName(), user.get())) {
Taskgroup taskgroup;
if(taskData.getParentID() < 0) {
taskgroup = new Taskgroup(taskData.getName(), user.get());
} else {
Optional<Taskgroup> parentTaskgroup = taskgroupRepository.findById(taskData.getParentID());
if(parentTaskgroup.isEmpty()) {
return new ServiceResult<>(ServiceExitCode.MISSING_ENTITY);
} else {
taskgroup = new Taskgroup(taskData.getName(), user.get());
taskgroup.setParent(parentTaskgroup.get());
parentTaskgroup.get().getChildren().add(taskgroup);
}
}
Taskgroup taskgroup = new Taskgroup(taskData.getName(), user.get());
taskgroupRepository.save(taskgroup); taskgroupRepository.save(taskgroup);
return new ServiceResult<>(taskgroup); return new ServiceResult<>(taskgroup);
} else { } else {
@ -72,6 +84,10 @@ public class TaskgroupService {
return taskgroupRepository.findAllByUser(username); return taskgroupRepository.findAllByUser(username);
} }
public List<Taskgroup> getTopTaskgroupsByUser(String username) {
return taskgroupRepository.findAllTopTaskgroupsByUser(username);
}
public void deleteTaskgroupByUser(User user) { public void deleteTaskgroupByUser(User user) {
taskgroupRepository.deleteAllByUser(user); taskgroupRepository.deleteAllByUser(user);
} }

View File

@ -94,6 +94,61 @@ export class TaskgroupService {
* @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body. * @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. * @param reportProgress flag to report request and response progress.
*/ */
public taskgroupsAllGet(observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<Array<TaskgroupEntityInfo>>;
public taskgroupsAllGet(observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<HttpResponse<Array<TaskgroupEntityInfo>>>;
public taskgroupsAllGet(observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<HttpEvent<Array<TaskgroupEntityInfo>>>;
public taskgroupsAllGet(observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<any> {
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.get<Array<TaskgroupEntityInfo>>(`${this.configuration.basePath}/taskgroups/all`,
{
context: localVarHttpContext,
responseType: <any>responseType_,
withCredentials: this.configuration.withCredentials,
headers: localVarHeaders,
observe: observe,
reportProgress: reportProgress
}
);
}
/**
* list all top level taskgroups of authorized user
* list all taskgroups of authorized user
* @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 taskgroupsGet(observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<Array<TaskgroupEntityInfo>>; public taskgroupsGet(observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<Array<TaskgroupEntityInfo>>;
public taskgroupsGet(observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<HttpResponse<Array<TaskgroupEntityInfo>>>; public taskgroupsGet(observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<HttpResponse<Array<TaskgroupEntityInfo>>>;
public taskgroupsGet(observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<HttpEvent<Array<TaskgroupEntityInfo>>>; public taskgroupsGet(observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<HttpEvent<Array<TaskgroupEntityInfo>>>;
@ -268,6 +323,65 @@ export class TaskgroupService {
); );
} }
/**
* get details of an existing taskgroup
* get details of an existing taskgroup
* @param taskgroupID internal id of taskgroup
* @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 taskgroupsTaskgroupIDGet(taskgroupID: number, observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<Array<TaskgroupEntityInfo>>;
public taskgroupsTaskgroupIDGet(taskgroupID: number, observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<HttpResponse<Array<TaskgroupEntityInfo>>>;
public taskgroupsTaskgroupIDGet(taskgroupID: number, observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<HttpEvent<Array<TaskgroupEntityInfo>>>;
public taskgroupsTaskgroupIDGet(taskgroupID: number, observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<any> {
if (taskgroupID === null || taskgroupID === undefined) {
throw new Error('Required parameter taskgroupID was null or undefined when calling taskgroupsTaskgroupIDGet.');
}
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.get<Array<TaskgroupEntityInfo>>(`${this.configuration.basePath}/taskgroups/${encodeURIComponent(String(taskgroupID))}`,
{
context: localVarHttpContext,
responseType: <any>responseType_,
withCredentials: this.configuration.withCredentials,
headers: localVarHeaders,
observe: observe,
reportProgress: reportProgress
}
);
}
/** /**
* edits taskgroup * edits taskgroup
* edits taskgroup * edits taskgroup

View File

@ -20,5 +20,6 @@ export interface TaskgroupEntityInfo {
* name of taskgroup * name of taskgroup
*/ */
taskgroupName: string; taskgroupName: string;
parentTaskgroup: TaskgroupEntityInfo;
} }

View File

@ -16,5 +16,9 @@ export interface TaskgroupFieldInfo {
* name of taskgroup * name of taskgroup
*/ */
name: string; name: string;
/**
* internal id of parent Taskgroup
*/
parentID: number;
} }

View File

@ -10,7 +10,8 @@ const routes: Routes = [
{path: '', component: MainComponent}, {path: '', component: MainComponent},
{path: 'admin', component: AdminDashboardComponent}, {path: 'admin', component: AdminDashboardComponent},
{path: 'user/settings', component: UserSettingsComponent}, {path: 'user/settings', component: UserSettingsComponent},
{path: 'taskgroups', component: TaskgroupDashboardComponent} {path: 'taskgroups', component: TaskgroupDashboardComponent},
{path: 'taskgroups/:taskgroupID', component: TaskgroupDashboardComponent}
]; ];
@NgModule({ @NgModule({

View File

@ -0,0 +1,6 @@
import {TaskgroupEntityInfo} from "../../../api";
export interface TaskgroupCreationData {
taskgroup: TaskgroupEntityInfo | undefined,
taskgroupID: number
}

View File

@ -4,6 +4,8 @@ import {MAT_DIALOG_DATA, MatDialogRef} from "@angular/material/dialog";
import {TaskgroupEntityInfo, TaskgroupService} from "../../../api"; import {TaskgroupEntityInfo, TaskgroupService} from "../../../api";
import {error} from "@angular/compiler/src/util"; import {error} from "@angular/compiler/src/util";
import {MatSnackBar} from "@angular/material/snack-bar"; import {MatSnackBar} from "@angular/material/snack-bar";
import {ActivatedRoute} from "@angular/router";
import {TaskgroupCreationData} from "./TaskgroupCreationData";
@Component({ @Component({
selector: 'app-taskgroup-creation', selector: 'app-taskgroup-creation',
@ -18,11 +20,12 @@ export class TaskgroupCreationComponent implements OnInit {
constructor(private dialogRef: MatDialogRef<TaskgroupCreationComponent>, constructor(private dialogRef: MatDialogRef<TaskgroupCreationComponent>,
private taskgroupService: TaskgroupService, private taskgroupService: TaskgroupService,
private snackbar: MatSnackBar, private snackbar: MatSnackBar,
@Inject(MAT_DIALOG_DATA) public data: TaskgroupEntityInfo | undefined) { } @Inject(MAT_DIALOG_DATA) public data: TaskgroupCreationData,
private activatedRoute: ActivatedRoute) { }
ngOnInit(): void { ngOnInit(): void {
if(this.data != undefined) { if(this.data.taskgroup != undefined) {
this.nameCtrl.setValue(this.data!.taskgroupName) this.nameCtrl.setValue(this.data.taskgroup!.taskgroupName)
} }
} }
@ -32,9 +35,10 @@ export class TaskgroupCreationComponent implements OnInit {
save() { save() {
this.pending = true; this.pending = true;
if(this.data == undefined) { if(this.data.taskgroup == undefined) {
this.taskgroupService.taskgroupsPut({ this.taskgroupService.taskgroupsPut({
name: this.nameCtrl.value name: this.nameCtrl.value,
parentID: this.data.taskgroupID,
}).subscribe({ }).subscribe({
next: resp => { next: resp => {
this.pending = false; this.pending = false;
@ -51,11 +55,12 @@ export class TaskgroupCreationComponent implements OnInit {
}) })
} else { } else {
this.taskgroupService.taskgroupsTaskgroupIDPost(this.data.taskgroupID, { this.taskgroupService.taskgroupsTaskgroupIDPost(this.data.taskgroupID, {
name: this.nameCtrl.value name: this.nameCtrl.value,
parentID: this.data.taskgroup!.parentTaskgroup.taskgroupID
}).subscribe({ }).subscribe({
next: resp => { next: resp => {
this.pending = false; this.pending = false;
this.data!.taskgroupName = this.nameCtrl.value this.data.taskgroup!.taskgroupName = this.nameCtrl.value
this.dialogRef.close(true); this.dialogRef.close(true);
}, },
error: err => { error: err => {

View File

@ -9,7 +9,7 @@
<mat-card *ngFor="let taskgroup of taskgroups"> <mat-card *ngFor="let taskgroup of taskgroups">
<mat-card-content> <mat-card-content>
<h1>{{taskgroup.taskgroupName}}</h1> <h1>{{taskgroup.taskgroupName}}</h1>
<button mat-raised-button color="primary">Detail</button> <button mat-raised-button color="primary" [routerLink]="['/taskgroups', taskgroup.taskgroupID]">Detail</button>
<button mat-raised-button class="edit-btn" (click)="openTaskgroupEditor(taskgroup)">Rename</button> <button mat-raised-button class="edit-btn" (click)="openTaskgroupEditor(taskgroup)">Rename</button>
<button mat-raised-button color="warn" (click)="openTaskgroupDeletion(taskgroup)">Delete</button> <button mat-raised-button color="warn" (click)="openTaskgroupDeletion(taskgroup)">Delete</button>
</mat-card-content> </mat-card-content>

View File

@ -3,6 +3,7 @@ import {MatDialog} from "@angular/material/dialog";
import {TaskgroupCreationComponent} from "../taskgroup-creation/taskgroup-creation.component"; import {TaskgroupCreationComponent} from "../taskgroup-creation/taskgroup-creation.component";
import {TaskgroupEntityInfo, TaskgroupService} from "../../../api"; import {TaskgroupEntityInfo, TaskgroupService} from "../../../api";
import {TaskgroupDeletionComponent} from "../taskgroup-deletion/taskgroup-deletion.component"; import {TaskgroupDeletionComponent} from "../taskgroup-deletion/taskgroup-deletion.component";
import {ActivatedRoute} from "@angular/router";
@Component({ @Component({
selector: 'app-taskgroup-dashboard', selector: 'app-taskgroup-dashboard',
@ -12,20 +13,34 @@ import {TaskgroupDeletionComponent} from "../taskgroup-deletion/taskgroup-deleti
export class TaskgroupDashboardComponent implements OnInit { export class TaskgroupDashboardComponent implements OnInit {
constructor(private dialog: MatDialog, constructor(private dialog: MatDialog,
private taskgroupService: TaskgroupService) { } private taskgroupService: TaskgroupService,
private activatedRoute: ActivatedRoute) { }
taskgroups: TaskgroupEntityInfo[] = [] taskgroups: TaskgroupEntityInfo[] = []
taskgroupID: number = -1;
ngOnInit(): void { ngOnInit(): void {
this.activatedRoute.paramMap.subscribe(params => {
if(params.has('taskgroupID')) {
this.taskgroupID = Number(params.get('taskgroupID'));
this.taskgroupService.taskgroupsTaskgroupIDGet(this.taskgroupID).subscribe({
next: resp => {
this.taskgroups = resp
}
})
} else {
this.taskgroupService.taskgroupsGet().subscribe({ this.taskgroupService.taskgroupsGet().subscribe({
next: resp => { next: resp => {
this.taskgroups = resp; this.taskgroups = resp;
} }
}) })
} }
})
}
openTaskgroupCreation() { openTaskgroupCreation() {
const dialogRef = this.dialog.open(TaskgroupCreationComponent, {minWidth: "400px"}) const dialogRef = this.dialog.open(TaskgroupCreationComponent, {data: {taskgroup: undefined, taskgroupID: this.taskgroupID}, minWidth: "400px"})
dialogRef.afterClosed().subscribe(res => { dialogRef.afterClosed().subscribe(res => {
if(res != undefined) { if(res != undefined) {
this.taskgroups.push(res); this.taskgroups.push(res);

View File

@ -564,7 +564,7 @@ paths:
example: "failed" example: "failed"
enum: enum:
- "failed" - "failed"
/taskgroups: /taskgroups/all:
get: get:
security: security:
- API_TOKEN: [] - API_TOKEN: []
@ -581,6 +581,23 @@ paths:
type: array type: array
items: items:
$ref: '#/components/schemas/TaskgroupEntityInfo' $ref: '#/components/schemas/TaskgroupEntityInfo'
/taskgroups:
get:
security:
- API_TOKEN: []
tags:
- taskgroup
summary: list all top level taskgroups of authorized user
description: list all taskgroups of authorized user
responses:
200:
description: Anfrage erfolgreich
content:
'application/json':
schema:
type: array
items:
$ref: '#/components/schemas/TaskgroupEntityInfo'
put: put:
security: security:
- API_TOKEN: [] - API_TOKEN: []
@ -616,6 +633,60 @@ paths:
enum: enum:
- "failed" - "failed"
/taskgroups/{taskgroupID}: /taskgroups/{taskgroupID}:
get:
security:
- API_TOKEN: []
tags:
- taskgroup
summary: get details of an existing taskgroup
description: get details of an existing taskgroup
parameters:
- name: taskgroupID
in: path
description: internal id of taskgroup
required: true
schema:
type: number
example: 1
responses:
200:
description: Anfrage erfolgreich
content:
'application/json':
schema:
type: array
items:
$ref: '#/components/schemas/TaskgroupEntityInfo'
403:
description: No permission
content:
'application/json':
schema:
type: object
required:
- status
properties:
status:
type: string
description: Status
example: "failed"
enum:
- "failed"
404:
description: Taskgroup does not exist
content:
'application/json':
schema:
type: object
required:
- status
properties:
status:
type: string
description: Status
example: "failed"
enum:
- "failed"
post: post:
security: security:
- API_TOKEN: [] - API_TOKEN: []
@ -948,6 +1019,7 @@ components:
required: required:
- taskgroupID - taskgroupID
- taskgroupName - taskgroupName
- parentTaskgroup
additionalProperties: false additionalProperties: false
properties: properties:
taskgroupID: taskgroupID:
@ -960,9 +1032,13 @@ components:
example: Taskgroup 1 example: Taskgroup 1
maxLength: 255 maxLength: 255
minLength: 1 minLength: 1
parentTaskgroup:
type: object
$ref: '#/components/schemas/TaskgroupEntityInfo'
TaskgroupFieldInfo: TaskgroupFieldInfo:
required: required:
- name - name
- parentID
additionalProperties: false additionalProperties: false
properties: properties:
name: name:
@ -971,3 +1047,8 @@ components:
example: Taskgroup 1 example: Taskgroup 1
maxLength: 255 maxLength: 255
minLength: 1 minLength: 1
parentID:
type: number
description: internal id of parent Taskgroup
example: 1