feat: migrate updateTask functionality to Django Rest
This commit is contained in:
parent
0be9f98cca
commit
8f79b0cf76
5 changed files with 51 additions and 15 deletions
|
|
@ -282,7 +282,7 @@
|
||||||
[img]="'check'"
|
[img]="'check'"
|
||||||
[imgFilter]="'none'"
|
[imgFilter]="'none'"
|
||||||
[value]="
|
[value]="
|
||||||
['', 'none', 'todo', 'inprogress', 'awaitfeedback', 'done'].includes(
|
['', 'todo', 'inprogress', 'awaitfeedback', 'done'].includes(
|
||||||
overlayData.toString()
|
overlayData.toString()
|
||||||
)
|
)
|
||||||
? ('addTask.create' | translate)
|
? ('addTask.create' | translate)
|
||||||
|
|
|
||||||
|
|
@ -84,8 +84,10 @@ export class AddTaskComponent implements OnInit {
|
||||||
|
|
||||||
async loadExistingTaskData() {
|
async loadExistingTaskData() {
|
||||||
if (this.overlayType === 'newTaskOverlay') {
|
if (this.overlayType === 'newTaskOverlay') {
|
||||||
|
// OverlayData = Status "todo"
|
||||||
this.taskData.status = this.overlayData;
|
this.taskData.status = this.overlayData;
|
||||||
} else if (this.overlayData) {
|
} else if (this.overlayData) {
|
||||||
|
// OverlayData = Current TaskId
|
||||||
const taskData = await firstValueFrom(this.getTaskData(this.overlayData));
|
const taskData = await firstValueFrom(this.getTaskData(this.overlayData));
|
||||||
if (taskData) {
|
if (taskData) {
|
||||||
this.taskData = { ...this.taskData, ...taskData };
|
this.taskData = { ...this.taskData, ...taskData };
|
||||||
|
|
@ -258,21 +260,46 @@ export class AddTaskComponent implements OnInit {
|
||||||
|
|
||||||
onSubmit(ngForm: NgForm) {
|
onSubmit(ngForm: NgForm) {
|
||||||
if (ngForm.submitted && ngForm.form.valid) {
|
if (ngForm.submitted && ngForm.form.valid) {
|
||||||
this.apiService.saveNewTask(this.taskData).subscribe({
|
// OverlayData = Current TaskId
|
||||||
next: (response) => {
|
if (this.overlayData) {
|
||||||
this.toastNotificationService.createTaskSuccessToast();
|
this.updateTask(ngForm);
|
||||||
this.updateNotifierService.notifyUpdate('task');
|
} else {
|
||||||
this.clearTaskData(ngForm);
|
this.createTask(ngForm);
|
||||||
this.closeOverlay();
|
}
|
||||||
this.router.navigate(['/board']);
|
|
||||||
},
|
|
||||||
error: (error) => {
|
|
||||||
console.error('Fehler beim Speichern:', error);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
createTask(ngForm: NgForm) {
|
||||||
|
this.apiService.saveNewTask(this.taskData).subscribe({
|
||||||
|
next: (response) => {
|
||||||
|
this.toastNotificationService.createTaskSuccessToast();
|
||||||
|
this.updateNotifierService.notifyUpdate('task');
|
||||||
|
this.clearTaskData(ngForm);
|
||||||
|
this.closeOverlay();
|
||||||
|
this.router.navigate(['/board']);
|
||||||
|
},
|
||||||
|
error: (error) => {
|
||||||
|
console.error('Fehler beim Speichern:', error);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
updateTask(ngForm: NgForm) {
|
||||||
|
// OverlayData = Current TaskId
|
||||||
|
this.apiService.updateTask(this.taskData, this.overlayData).subscribe({
|
||||||
|
next: (response) => {
|
||||||
|
this.toastNotificationService.updateTaskSuccessToast();
|
||||||
|
this.updateNotifierService.notifyUpdate('task');
|
||||||
|
this.clearTaskData(ngForm);
|
||||||
|
this.closeOverlay();
|
||||||
|
this.router.navigate(['/board']);
|
||||||
|
},
|
||||||
|
error: (error) => {
|
||||||
|
console.error('Fehler beim Speichern:', error);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sanitizes the task data by removing any potential cross-site scripting characters.
|
* Sanitizes the task data by removing any potential cross-site scripting characters.
|
||||||
* This ensures that the task data is safe to be stored in the Firebase Realtime Database.
|
* This ensures that the task data is safe to be stored in the Firebase Realtime Database.
|
||||||
|
|
@ -293,6 +320,7 @@ export class AddTaskComponent implements OnInit {
|
||||||
* @returns {void}
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
deleteTask(overlayData: string) {
|
deleteTask(overlayData: string) {
|
||||||
|
// OverlayData = Current TaskId
|
||||||
this.apiService.deleteTaskById(overlayData);
|
this.apiService.deleteTaskById(overlayData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ import { ApiService } from '../../services/api.service';
|
||||||
import { Task } from '../../interfaces/task.interface';
|
import { Task } from '../../interfaces/task.interface';
|
||||||
import { TaskService } from '../../services/task.service';
|
import { TaskService } from '../../services/task.service';
|
||||||
import { LoadingSpinnerComponent } from '../../shared/components/loading-spinner/loading-spinner.component';
|
import { LoadingSpinnerComponent } from '../../shared/components/loading-spinner/loading-spinner.component';
|
||||||
import { finalize, Subject, takeUntil } from 'rxjs';
|
import { debounceTime, finalize, Subject, takeUntil } from 'rxjs';
|
||||||
import { UpdateNotifierService } from '../../services/update-notifier.service';
|
import { UpdateNotifierService } from '../../services/update-notifier.service';
|
||||||
import { ToastNotificationService } from '../../services/toast-notification.service';
|
import { ToastNotificationService } from '../../services/toast-notification.service';
|
||||||
import { ResizeService } from '../../services/resize.service';
|
import { ResizeService } from '../../services/resize.service';
|
||||||
|
|
@ -96,7 +96,7 @@ export class BoardComponent {
|
||||||
|
|
||||||
private subscribeToTaskUpdates() {
|
private subscribeToTaskUpdates() {
|
||||||
this.updateNotifierService.taskUpdated$
|
this.updateNotifierService.taskUpdated$
|
||||||
.pipe(takeUntil(this.destroy$))
|
.pipe(debounceTime(50), takeUntil(this.destroy$))
|
||||||
.subscribe(() => {
|
.subscribe(() => {
|
||||||
this.loadAllTasks();
|
this.loadAllTasks();
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -69,6 +69,10 @@ export class ApiService {
|
||||||
return this.request<Task>('POST', '/api/tasks/', task);
|
return this.request<Task>('POST', '/api/tasks/', task);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateTask(task: Task, taskId: string): Observable<Task> {
|
||||||
|
return this.request<Task>('PATCH', `/api/tasks/${taskId}/`, task);
|
||||||
|
}
|
||||||
|
|
||||||
deleteTaskById(taskId: string): Observable<Task> {
|
deleteTaskById(taskId: string): Observable<Task> {
|
||||||
return this.request<Task>('DELETE', `/api/tasks/${taskId}/`);
|
return this.request<Task>('DELETE', `/api/tasks/${taskId}/`);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -63,6 +63,10 @@ export class ToastNotificationService {
|
||||||
this.createInfoToast('Task successfully moved!', 'Task Moved');
|
this.createInfoToast('Task successfully moved!', 'Task Moved');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateTaskSuccessToast(): void {
|
||||||
|
this.createSuccessToast('Task updated successfully!', 'Task Updated');
|
||||||
|
}
|
||||||
|
|
||||||
// Subtask
|
// Subtask
|
||||||
|
|
||||||
updateSubtaskSuccessToast(): void {
|
updateSubtaskSuccessToast(): void {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue