Edit
This commit is contained in:
parent
ed06f5d1ca
commit
b976eec51a
@ -7,16 +7,24 @@
|
|||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@for (show of shows; track show.id) {
|
@for (show of shows; track show.id) {
|
||||||
|
@if (isToEdit(show)) {
|
||||||
|
<td><input class="form-control" id="newShowId" name="newShowId" type="number" [(ngModel)]="show.id"></td>
|
||||||
|
<td><input class="form-control" id="newShowTitle" name="newShowTitle" type="text" [(ngModel)]="show.title"></td>
|
||||||
|
<td colspan="2">
|
||||||
|
<button class="material-icons" (click)="saveEdit()">save</button>
|
||||||
|
</td>
|
||||||
|
} @else {
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ show.id }}</td>
|
<td>{{ show.id }}</td>
|
||||||
<td>{{ show.title }}</td>
|
<td>{{ show.title }}</td>
|
||||||
<td>
|
<td>
|
||||||
<button class="btn btn-secondary">Bearbeiten</button>
|
<button class="btn btn-secondary" (click)="edit(show)">Bearbeiten</button>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<button class="btn btn-danger" (click)="delete(show)">Löschen</button>
|
<button class="btn btn-danger" (click)="delete(show)">Löschen</button>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
}
|
}
|
||||||
|
}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
@ -1,24 +1,47 @@
|
|||||||
import {Component, inject, Input} from '@angular/core';
|
import {Component, inject, Input} from '@angular/core';
|
||||||
import {Show} from '../../model/show';
|
import {Show} from '../../model/show';
|
||||||
import {ShowService} from '../../services/show.service';
|
import {ShowService} from '../../services/show.service';
|
||||||
|
import {FormsModule} from '@angular/forms';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-show-list',
|
selector: 'app-show-list',
|
||||||
standalone: true,
|
standalone: true,
|
||||||
imports: [],
|
imports: [
|
||||||
|
FormsModule
|
||||||
|
],
|
||||||
templateUrl: './show-list.component.html',
|
templateUrl: './show-list.component.html',
|
||||||
styleUrl: './show-list.component.css'
|
styleUrl: './show-list.component.css'
|
||||||
})
|
})
|
||||||
export class ShowListComponent {
|
export class ShowListComponent {
|
||||||
showService: ShowService = inject(ShowService);
|
showService: ShowService = inject(ShowService);
|
||||||
shows: Show[] = this.showService.getShows();
|
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) {
|
updateShow(show: Show) {
|
||||||
this.shows = this.shows.filter(s => s !== show);
|
this.shows = this.shows.filter(s => s !== show);
|
||||||
this.shows.push(show);
|
this.shows.push(show);
|
||||||
|
this.shows.sort((a, b) => (a.id ?? 0) - (b.id ?? 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
delete(show: Show) {
|
delete(show: Show) {
|
||||||
this.shows = this.shows.filter(s => s !== show);
|
this.shows = this.shows.filter(s => s !== show);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isToEdit(show: Show): boolean {
|
||||||
|
if (!this.editShow) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return this.editShow === show;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user