From b976eec51a4ab77bb57968a6648e1ceb4a528b47 Mon Sep 17 00:00:00 2001
From: Phan Huy Tran
Date: Wed, 20 Nov 2024 10:42:43 +0100
Subject: [PATCH] Edit
---
.../show-list/show-list.component.html | 26 ++++++++++++-------
.../show-list/show-list.component.ts | 25 +++++++++++++++++-
2 files changed, 41 insertions(+), 10 deletions(-)
diff --git a/src/app/components/show-list/show-list.component.html b/src/app/components/show-list/show-list.component.html
index e5c99cd..0f4cacb 100644
--- a/src/app/components/show-list/show-list.component.html
+++ b/src/app/components/show-list/show-list.component.html
@@ -7,16 +7,24 @@
@for (show of shows; track show.id) {
-
- {{ show.id }} |
- {{ show.title }} |
-
-
+ @if (isToEdit(show)) {
+ | |
+ |
+
+
|
-
-
- |
-
+ } @else {
+
+ {{ show.id }} |
+ {{ show.title }} |
+
+
+ |
+
+
+ |
+
+ }
}
diff --git a/src/app/components/show-list/show-list.component.ts b/src/app/components/show-list/show-list.component.ts
index a055cdb..707929e 100644
--- a/src/app/components/show-list/show-list.component.ts
+++ b/src/app/components/show-list/show-list.component.ts
@@ -1,24 +1,47 @@
import {Component, inject, Input} from '@angular/core';
import {Show} from '../../model/show';
import {ShowService} from '../../services/show.service';
+import {FormsModule} from '@angular/forms';
@Component({
selector: 'app-show-list',
standalone: true,
- imports: [],
+ imports: [
+ FormsModule
+ ],
templateUrl: './show-list.component.html',
styleUrl: './show-list.component.css'
})
export class ShowListComponent {
showService: ShowService = inject(ShowService);
shows: Show[] = this.showService.getShows();
+ editShow: Show = new Show(null, null);
+
+ edit(show: Show) {
+ this.editShow = show;
+ }
+
+ saveEdit() {
+ this.updateShow(this.editShow);
+
+ this.editShow = new Show(null, null);
+ }
updateShow(show: Show) {
this.shows = this.shows.filter(s => s !== show);
this.shows.push(show);
+ this.shows.sort((a, b) => (a.id ?? 0) - (b.id ?? 0));
}
delete(show: Show) {
this.shows = this.shows.filter(s => s !== show);
}
+
+ isToEdit(show: Show): boolean {
+ if (!this.editShow) {
+ return false;
+ } else {
+ return this.editShow === show;
+ }
+ }
}