From efcab999f23288fa04fd8707f370ea13dc2eb37b Mon Sep 17 00:00:00 2001 From: Sebastian Date: Mon, 25 Sep 2023 13:06:49 +0200 Subject: [PATCH] List and Edit Taskgroups --- .../taskgroup-creation.component.ts | 67 +++++++++++++------ .../taskgroup-dashboard.component.css | 13 ++++ .../taskgroup-dashboard.component.html | 13 +++- .../taskgroup-dashboard.component.ts | 25 ++++++- 4 files changed, 96 insertions(+), 22 deletions(-) diff --git a/frontend/src/app/taskgroups/taskgroup-creation/taskgroup-creation.component.ts b/frontend/src/app/taskgroups/taskgroup-creation/taskgroup-creation.component.ts index 45bc353..5cefc1d 100644 --- a/frontend/src/app/taskgroups/taskgroup-creation/taskgroup-creation.component.ts +++ b/frontend/src/app/taskgroups/taskgroup-creation/taskgroup-creation.component.ts @@ -1,7 +1,7 @@ -import { Component, OnInit } from '@angular/core'; +import {Component, Inject, OnInit} from '@angular/core'; import {FormControl, Validators} from "@angular/forms"; -import {MatDialogRef} from "@angular/material/dialog"; -import {TaskgroupService} from "../../../api"; +import {MAT_DIALOG_DATA, MatDialogRef} from "@angular/material/dialog"; +import {TaskgroupEntityInfo, TaskgroupService} from "../../../api"; import {error} from "@angular/compiler/src/util"; import {MatSnackBar} from "@angular/material/snack-bar"; @@ -17,9 +17,13 @@ export class TaskgroupCreationComponent implements OnInit { constructor(private dialogRef: MatDialogRef, private taskgroupService: TaskgroupService, - private snackbar: MatSnackBar) { } + private snackbar: MatSnackBar, + @Inject(MAT_DIALOG_DATA) public data: TaskgroupEntityInfo | undefined) { } ngOnInit(): void { + if(this.data != undefined) { + this.nameCtrl.setValue(this.data!.taskgroupName) + } } cancel() { @@ -28,22 +32,47 @@ export class TaskgroupCreationComponent implements OnInit { save() { this.pending = true; - this.taskgroupService.taskgroupsPut({ - name: this.nameCtrl.value - }).subscribe({ - next: resp => { - this.pending = false; - this.dialogRef.close(resp); - }, - error: err => { - this.pending = false; - if(err.status == 409) { - this.snackbar.open("Taskgroup already exists", "", {duration: 2000}); - } else { - this.snackbar.open("An unexpected error occured", ""); + if(this.data == undefined) { + this.taskgroupService.taskgroupsPut({ + name: this.nameCtrl.value + }).subscribe({ + next: resp => { + this.pending = false; + this.dialogRef.close(resp); + }, + error: err => { + this.pending = false; + if(err.status == 409) { + this.snackbar.open("Taskgroup already exists", "", {duration: 2000}); + } else { + this.snackbar.open("An unexpected error occured", ""); + } } - } - }) + }) + } else { + this.taskgroupService.taskgroupsTaskgroupIDPost(this.data.taskgroupID, { + name: this.nameCtrl.value + }).subscribe({ + next: resp => { + this.pending = false; + this.data!.taskgroupName = this.nameCtrl.value + this.dialogRef.close(true); + }, + error: err => { + this.pending = false; + if(err.status == 409) { + this.snackbar.open("Taskgroup already exists", "", {duration: 2000}); + } else if(err.status == 403) { + this.snackbar.open("No permission", "", {duration: 2000}) + } else if(err.status == 404) { + this.snackbar.open("Not found", "", {duration: 2000}); + } else { + this.snackbar.open("An unexpected error occured", ""); + } + } + }) + } + } } diff --git a/frontend/src/app/taskgroups/taskgroup-dashboard/taskgroup-dashboard.component.css b/frontend/src/app/taskgroups/taskgroup-dashboard/taskgroup-dashboard.component.css index 01e110f..a1970b1 100644 --- a/frontend/src/app/taskgroups/taskgroup-dashboard/taskgroup-dashboard.component.css +++ b/frontend/src/app/taskgroups/taskgroup-dashboard/taskgroup-dashboard.component.css @@ -26,3 +26,16 @@ color: grey; } + +.navLink-bar { + margin-bottom: 20px; +} + +#addTaskgroupBtn { + margin-top: 20px; +} + +.edit-btn { + background-color: #6e6e6e; + color: white; +} diff --git a/frontend/src/app/taskgroups/taskgroup-dashboard/taskgroup-dashboard.component.html b/frontend/src/app/taskgroups/taskgroup-dashboard/taskgroup-dashboard.component.html index f98e1c7..03ec6d5 100644 --- a/frontend/src/app/taskgroups/taskgroup-dashboard/taskgroup-dashboard.component.html +++ b/frontend/src/app/taskgroups/taskgroup-dashboard/taskgroup-dashboard.component.html @@ -1,10 +1,19 @@
- + Dashboard / Taskgroups - + + +

{{taskgroup.taskgroupName}}

+ + + +
+ +
+
diff --git a/frontend/src/app/taskgroups/taskgroup-dashboard/taskgroup-dashboard.component.ts b/frontend/src/app/taskgroups/taskgroup-dashboard/taskgroup-dashboard.component.ts index 8b46a98..005ea39 100644 --- a/frontend/src/app/taskgroups/taskgroup-dashboard/taskgroup-dashboard.component.ts +++ b/frontend/src/app/taskgroups/taskgroup-dashboard/taskgroup-dashboard.component.ts @@ -1,6 +1,7 @@ import { Component, OnInit } from '@angular/core'; import {MatDialog} from "@angular/material/dialog"; import {TaskgroupCreationComponent} from "../taskgroup-creation/taskgroup-creation.component"; +import {TaskgroupEntityInfo, TaskgroupService} from "../../../api"; @Component({ selector: 'app-taskgroup-dashboard', @@ -9,12 +10,34 @@ import {TaskgroupCreationComponent} from "../taskgroup-creation/taskgroup-creati }) export class TaskgroupDashboardComponent implements OnInit { - constructor(private dialog: MatDialog) { } + constructor(private dialog: MatDialog, + private taskgroupService: TaskgroupService) { } + + taskgroups: TaskgroupEntityInfo[] = [] ngOnInit(): void { + this.taskgroupService.taskgroupsGet().subscribe({ + next: resp => { + this.taskgroups = resp; + } + }) } openTaskgroupCreation() { const dialogRef = this.dialog.open(TaskgroupCreationComponent, {minWidth: "400px"}) + dialogRef.afterClosed().subscribe(res => { + if(res != undefined) { + this.taskgroups.push(res); + } + }) + } + + openTaskgroupEditor(taskgroup: TaskgroupEntityInfo) { + const dialogRef = this.dialog.open(TaskgroupCreationComponent, {data: taskgroup, minWidth: "400px"}); + dialogRef.afterClosed().subscribe(res => { + if(res) { + const data = this.taskgroups + } + }) } }