Skip to content

Commit

Permalink
implement delete func
Browse files Browse the repository at this point in the history
  • Loading branch information
kcinay055679 committed Jan 27, 2025
1 parent a725be5 commit 5f7962a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
FormGroup,
FormGroupDirective
} from '@angular/forms';
import { Observable } from 'rxjs';

export type FormControlsOf<T> = {
[P in keyof T]: AbstractControl<T[P]>;
Expand All @@ -35,7 +36,7 @@ export interface Item {
export class ActionPlanComponent implements AfterContentInit {
form?: FormGroup;

@Input() onDelete: (index: number) => void = () => {};
@Input() onDelete: (index: number) => Observable<any> = () => new Observable();

@ViewChildren('listItem')
listItems!: QueryList<ElementRef>;
Expand Down Expand Up @@ -78,7 +79,8 @@ export class ActionPlanComponent implements AfterContentInit {
this.getFormControlArray()
.removeAt(index);

this.onDelete(index);
this.onDelete(itemId)
.subscribe();
}
});
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ export class CheckInFormComponent implements OnInit {
}

setDefaultValues() {
const itemList = actionListToItemList(this.keyResult.actionList);
this.dialogForm.controls.actionList.setValue(itemList);
actionListToItemList(this.keyResult.actionList)
.forEach((e) => {
this.addNewItem(e);
});
if (this.data.checkIn != null) {
this.checkIn = this.data.checkIn;
this.dialogForm.controls.value.setValue(this.getCheckInValue());
Expand Down Expand Up @@ -164,4 +166,13 @@ export class CheckInFormComponent implements OnInit {
closeActionEdit() {
this.isAddingAction = false;
}

addNewItem(item: Item) {
const newFormGroup = new FormGroup({
item: new FormControl<string>(item.item),
id: new FormControl<number | undefined>(item.id),
isChecked: new FormControl<boolean>(item.isChecked)
} as FormControlsOf<Item>);
(this.dialogForm.get('actionList') as FormArray)?.push(newFormGroup);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@


<div formArrayName="actionList">
<app-action-plan [onDelete]="actionService.deleteAction"></app-action-plan>
<app-action-plan [onDelete]="actionPlanOnDelete"></app-action-plan>
</div>

</form>
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export class KeyResultFormComponent implements OnInit {

filteredUsers$: Observable<User[]> = of([]);

actionPlanOnDelete = (index: number): Observable<any> => this.actionService.deleteAction(index);

protected readonly formInputCheck = formInputCheck;

Expand Down Expand Up @@ -82,8 +83,8 @@ export class KeyResultFormComponent implements OnInit {
addNewItem(item: Item) {
const newFormGroup = new FormGroup({
item: new FormControl<string>(item.item),
id: new FormControl<number | undefined>(undefined),
isChecked: new FormControl<boolean>(false)
id: new FormControl<number | undefined>(item.id),
isChecked: new FormControl<boolean>(item.isChecked)
} as FormControlsOf<Item>);
(this.keyResultForm.get('actionList') as FormArray)?.push(newFormGroup);
}
Expand Down

0 comments on commit 5f7962a

Please sign in to comment.