Compare commits

..

No commits in common. "ae74e61e2047c23fe3874e892e423db500420954" and "a62708441e2ae59ba4daf8e77c52c4a57c520fb5" have entirely different histories.

11 changed files with 137 additions and 2062 deletions

2101
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -14,14 +14,12 @@
"@angular/common": "^18.2.0", "@angular/common": "^18.2.0",
"@angular/compiler": "^18.2.0", "@angular/compiler": "^18.2.0",
"@angular/core": "^18.2.0", "@angular/core": "^18.2.0",
"@angular/fire": "^18.0.1",
"@angular/forms": "^18.2.0", "@angular/forms": "^18.2.0",
"@angular/platform-browser": "^18.2.0", "@angular/platform-browser": "^18.2.0",
"@angular/platform-browser-dynamic": "^18.2.0", "@angular/platform-browser-dynamic": "^18.2.0",
"@angular/router": "^18.2.0", "@angular/router": "^18.2.0",
"bootstrap": "^5.3.3", "bootstrap": "^5.3.3",
"bootstrap-icons": "^1.11.3", "bootstrap-icons": "^1.11.3",
"firebase": "^11.0.2",
"rxjs": "~7.8.0", "rxjs": "~7.8.0",
"tslib": "^2.3.0", "tslib": "^2.3.0",
"zone.js": "~0.14.10" "zone.js": "~0.14.10"

View File

@ -1,26 +1,9 @@
import {ApplicationConfig, provideZoneChangeDetection} from '@angular/core'; import { ApplicationConfig, provideZoneChangeDetection } from '@angular/core';
import {provideRouter} from '@angular/router'; import { provideRouter } from '@angular/router';
import {routes} from './app.routes'; import { routes } from './app.routes';
import {provideHttpClient} from '@angular/common/http'; import {provideHttpClient} from '@angular/common/http';
import {initializeApp, provideFirebaseApp} from '@angular/fire/app';
import {getFirestore, provideFirestore} from '@angular/fire/firestore';
const firebaseConfig = {
apiKey: "AIzaSyDh7OjqpUdoVPzzzdPa8t_Pm4_UsanJC-c",
authDomain: "tv-serien-ff0ce.firebaseapp.com",
projectId: "tv-serien-ff0ce",
storageBucket: "tv-serien-ff0ce.firebasestorage.app",
messagingSenderId: "38528604508",
appId: "1:38528604508:web:e4070052d0495cf28e4999"
};
export const appConfig: ApplicationConfig = { export const appConfig: ApplicationConfig = {
providers: [ providers: [provideZoneChangeDetection({ eventCoalescing: true }), provideRouter(routes), provideHttpClient()]
provideZoneChangeDetection({eventCoalescing: true}),
provideRouter(routes),
provideHttpClient(),
provideFirebaseApp(() => initializeApp(firebaseConfig)),
provideFirestore(() => getFirestore())
]
}; };

View File

@ -2,7 +2,7 @@
<div class="row mt-3"><h1>TV-Serien</h1></div> <div class="row mt-3"><h1>TV-Serien</h1></div>
<div class="row mt-1"> <div class="row mt-1">
<div class="col-md-7 mb-3"> <div class="col-md-7 mb-3">
<app-show-list (selectedShow)="onSelectedShow($event)"></app-show-list> <app-show-list [shows]="shows" (selectedShow)="onSelectedShow($event)"></app-show-list>
</div> </div>
<div class="col-md-5"> <div class="col-md-5">
@if (isShowSelected) { @if (isShowSelected) {

View File

@ -1,6 +1,7 @@
import {Component, inject} from '@angular/core'; import {Component, inject} from '@angular/core';
import {ShowListComponent} from '../show-list/show-list.component'; import {ShowListComponent} from '../show-list/show-list.component';
import {Show} from '../../model/show'; import {Show} from '../../model/show';
import {ShowService} from '../../services/show.service';
import {ShowFormComponent} from '../show-form/show-form.component'; import {ShowFormComponent} from '../show-form/show-form.component';
import {BehaviorSubject} from 'rxjs'; import {BehaviorSubject} from 'rxjs';
import {ApiService} from '../../services/api-service'; import {ApiService} from '../../services/api-service';
@ -12,18 +13,21 @@ import {ShowDetailsComponent} from '../show-details/show-details.component';
imports: [ imports: [
ShowListComponent, ShowListComponent,
ShowFormComponent, ShowFormComponent,
ShowDetailsComponent, ShowDetailsComponent
], ],
templateUrl: './main-view.component.html', templateUrl: './main-view.component.html',
styleUrl: './main-view.component.css' styleUrl: './main-view.component.css'
}) })
export class MainViewComponent { export class MainViewComponent {
private dataService: ShowService = inject(ShowService);
private apiService: ApiService = inject(ApiService); private apiService: ApiService = inject(ApiService);
public shows: Show[] = [];
selectedShow$: BehaviorSubject<Show>; selectedShow$: BehaviorSubject<Show>;
isShowSelected = false; isShowSelected = false;
constructor() { constructor() {
this.shows = this.dataService.getShows();
this.selectedShow$ = new BehaviorSubject<Show>(new Show(0, "")) this.selectedShow$ = new BehaviorSubject<Show>(new Show(0, ""))
} }

View File

@ -9,7 +9,7 @@
pattern="^\d+$" pattern="^\d+$"
name="newShowID" name="newShowID"
type="text" type="text"
[(ngModel)]="show.uid" [(ngModel)]="show.id"
placeholder="Hier die ID der Serie eingeben!" placeholder="Hier die ID der Serie eingeben!"
required required
> >

View File

@ -2,8 +2,6 @@ import {Component, inject} from '@angular/core';
import {ShowService} from '../../services/show.service'; import {ShowService} from '../../services/show.service';
import {Show} from '../../model/show'; import {Show} from '../../model/show';
import {FormsModule} from '@angular/forms'; import {FormsModule} from '@angular/forms';
import {Observable} from 'rxjs';
import {addDoc, collection, Firestore} from '@angular/fire/firestore';
@Component({ @Component({
selector: 'app-show-form', selector: 'app-show-form',
@ -15,12 +13,13 @@ import {addDoc, collection, Firestore} from '@angular/fire/firestore';
styleUrl: './show-form.component.css' styleUrl: './show-form.component.css'
}) })
export class ShowFormComponent { export class ShowFormComponent {
fireStore: Firestore = inject(Firestore); showService: ShowService = inject(ShowService);
private seriesCollection = 'table_show';
show: Show = new Show(0, ""); show: Show = new Show(0, "");
shows: Show[] = this.showService.getShows();
save() { save() {
const showsRef = collection(this.fireStore, this.seriesCollection); this.shows.push(this.show);
addDoc(showsRef, {id: this.show.uid, title: this.show.title,});
this.show = new Show(0, "");
} }
} }

View File

@ -6,16 +6,16 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@for (show of shows | async; track show.uid) { @for (show of shows; track show.id) {
@if (isToEdit(show)) { @if (isToEdit(show)) {
<td><input class="form-control" id="newShowId" name="newShowId" type="number" [(ngModel)]="show.uid"></td> <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><input class="form-control" id="newShowTitle" name="newShowTitle" type="text" [(ngModel)]="show.title"></td>
<td colspan="2"> <td colspan="2">
<button class="material-icons" (click)="saveEdit()">save</button> <button class="material-icons" (click)="saveEdit()">save</button>
</td> </td>
} @else { } @else {
<tr> <tr>
<td>{{ show.uid }}</td> <td>{{ show.id }}</td>
<td>{{ show.title }}</td> <td>{{ show.title }}</td>
<td> <td>
<button class="btn btn-primary" (click)="showDetails(show)">Details</button> <button class="btn btn-primary" (click)="showDetails(show)">Details</button>

View File

@ -1,27 +1,18 @@
import {Component, EventEmitter, inject, Input, Output} from '@angular/core'; import {Component, EventEmitter, Input, Output} from '@angular/core';
import {Show} from '../../model/show'; import {Show} from '../../model/show';
import {FormsModule} from '@angular/forms'; import {FormsModule} from '@angular/forms';
import {ShowService} from '../../services/show.service';
import {Observable} from 'rxjs';
import {AsyncPipe} from '@angular/common';
import {deleteDoc, doc, Firestore, updateDoc} from '@angular/fire/firestore';
@Component({ @Component({
selector: 'app-show-list', selector: 'app-show-list',
standalone: true, standalone: true,
imports: [ imports: [
FormsModule, FormsModule
AsyncPipe
], ],
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); @Input() shows: Show[] = [];
fireStore: Firestore = inject(Firestore);
private seriesCollection = 'table_show';
shows: Observable<Show[]> = this.showService.getShows();
@Output() selectedShow = new EventEmitter<Show>(); @Output() selectedShow = new EventEmitter<Show>();
editShow: Show = new Show(0, ""); editShow: Show = new Show(0, "");
@ -40,13 +31,13 @@ export class ShowListComponent {
} }
updateShow(show: Show) { updateShow(show: Show) {
const showDocRef = doc(this.fireStore, `${this.seriesCollection}/${show.uid}`); this.shows = this.shows.filter(s => s !== show);
updateDoc(showDocRef, {id: show.uid, title: show.title,}); this.shows.push(show);
this.shows.sort((a, b) => (a.id ?? 0) - (b.id ?? 0));
} }
delete(show: Show) { delete(show: Show) {
const showDocRef = doc(this.fireStore, `${this.seriesCollection}/${show.uid}`); this.shows = this.shows.filter(s => s !== show);
deleteDoc(showDocRef);
} }
isToEdit(show: Show): boolean { isToEdit(show: Show): boolean {

View File

@ -1,4 +1,4 @@
export class Show { export class Show {
constructor(public uid?: number, public title?: string, public image?: string, public summary?: string) { constructor(public id?: number, public title?: string, public image?: string, public summary?: string) {
} }
} }

View File

@ -1,22 +1,21 @@
import {Injectable} from '@angular/core'; import { Injectable } from '@angular/core';
import {Show} from '../model/show'; import {Show} from '../model/show';
import {collection, collectionData, Firestore, orderBy, query} from '@angular/fire/firestore';
import {Observable} from 'rxjs';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
}) })
export class ShowService { export class ShowService {
private readonly shows$!: Observable<Show[]>; private shows: Show[] = [];
private seriesCollection = 'table_show';
constructor(private firestore: Firestore) { constructor() {
const showsRef = collection(this.firestore, this.seriesCollection); this.shows.push(new Show(1, 'Vikings'));
const showsQuery = query(showsRef, orderBy('id')); this.shows.push(new Show(2, 'Friends'));
this.shows$ = collectionData(showsQuery, {idField: 'uid'}) as Observable<Show[]>; this.shows.push(new Show(3, 'Downtown Abbey'));
this.shows.push(new Show(4, 'The Witcher'));
this.shows.push(new Show(5, 'Versuch'));
} }
getShows() { getShows() {
return this.shows$; return this.shows;
} }
} }