chore: Fix editing
This commit is contained in:
parent
28c0420354
commit
bb67052158
6 changed files with 30 additions and 17 deletions
|
@ -1,9 +1,8 @@
|
|||
import { DatePipe } from '@angular/common';
|
||||
import { Component, Input, input, ResourceRef } from '@angular/core';
|
||||
import { Component, Input, ResourceRef, signal } from '@angular/core';
|
||||
import {
|
||||
FormControl,
|
||||
FormGroup,
|
||||
FormsModule,
|
||||
ReactiveFormsModule,
|
||||
Validators,
|
||||
} from '@angular/forms';
|
||||
|
@ -17,7 +16,9 @@ import {
|
|||
export class CreateTodo {
|
||||
public form!: FormGroup;
|
||||
private datePipe = new DatePipe('en-US');
|
||||
public isEditing = signal(false);
|
||||
@Input({ required: true }) tasks!: ResourceRef<any>;
|
||||
@Input() editTodo: number = -1;
|
||||
|
||||
submit() {
|
||||
if (this.form.valid) {
|
||||
|
@ -30,8 +31,9 @@ export class CreateTodo {
|
|||
}
|
||||
}
|
||||
|
||||
editTask(task: Task) {
|
||||
this.form.patchValue({ id: task.id });
|
||||
stopEdit() {
|
||||
this.isEditing.set(false);
|
||||
this.form.controls['id'].setValue(-1);
|
||||
}
|
||||
|
||||
updateTask(task: Task) {
|
||||
|
@ -44,6 +46,7 @@ export class CreateTodo {
|
|||
}).then(() => {
|
||||
this.tasks.reload();
|
||||
});
|
||||
this.isEditing.set(false);
|
||||
}
|
||||
|
||||
createTask(task: Task) {
|
||||
|
@ -58,6 +61,15 @@ export class CreateTodo {
|
|||
});
|
||||
}
|
||||
|
||||
editTask(task: Task) {
|
||||
this.form.controls['id'].setValue(task.id);
|
||||
this.form.controls['title'].setValue(task.title);
|
||||
this.form.controls['dueDate'].setValue(
|
||||
this.datePipe.transform(task.dueDate, 'yyyy-MM-dd'),
|
||||
);
|
||||
this.isEditing.set(true);
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.form = new FormGroup({
|
||||
id: new FormControl(-1),
|
||||
|
@ -65,6 +77,7 @@ export class CreateTodo {
|
|||
dueDate: new FormControl(
|
||||
this.datePipe.transform(new Date(), 'yyyy-MM-dd'),
|
||||
),
|
||||
done: new FormControl(false),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue