fire
This commit is contained in:
parent
a62708441e
commit
6d6a817a47
2101
package-lock.json
generated
2101
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -14,12 +14,14 @@
|
|||||||
"@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"
|
||||||
|
@ -3,7 +3,24 @@ 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: [provideZoneChangeDetection({ eventCoalescing: true }), provideRouter(routes), provideHttpClient()]
|
providers: [
|
||||||
|
provideZoneChangeDetection({eventCoalescing: true}),
|
||||||
|
provideRouter(routes),
|
||||||
|
provideHttpClient(),
|
||||||
|
provideFirebaseApp(() => initializeApp(firebaseConfig)),
|
||||||
|
provideFirestore(() => getFirestore())
|
||||||
|
]
|
||||||
};
|
};
|
||||||
|
@ -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 [shows]="shows" (selectedShow)="onSelectedShow($event)"></app-show-list>
|
<app-show-list (selectedShow)="onSelectedShow($event)"></app-show-list>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-5">
|
<div class="col-md-5">
|
||||||
@if (isShowSelected) {
|
@if (isShowSelected) {
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
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';
|
||||||
@ -13,21 +12,18 @@ 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, ""))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
pattern="^\d+$"
|
pattern="^\d+$"
|
||||||
name="newShowID"
|
name="newShowID"
|
||||||
type="text"
|
type="text"
|
||||||
[(ngModel)]="show.id"
|
[(ngModel)]="show.uid"
|
||||||
placeholder="Hier die ID der Serie eingeben!"
|
placeholder="Hier die ID der Serie eingeben!"
|
||||||
required
|
required
|
||||||
>
|
>
|
||||||
|
@ -2,6 +2,7 @@ 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';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-show-form',
|
selector: 'app-show-form',
|
||||||
@ -15,10 +16,10 @@ import {FormsModule} from '@angular/forms';
|
|||||||
export class ShowFormComponent {
|
export class ShowFormComponent {
|
||||||
showService: ShowService = inject(ShowService);
|
showService: ShowService = inject(ShowService);
|
||||||
show: Show = new Show(0, "");
|
show: Show = new Show(0, "");
|
||||||
shows: Show[] = this.showService.getShows();
|
shows: Observable<Show[]> = this.showService.getShows();
|
||||||
|
|
||||||
save() {
|
save() {
|
||||||
this.shows.push(this.show);
|
// this.shows.push(this.show);
|
||||||
|
|
||||||
this.show = new Show(0, "");
|
this.show = new Show(0, "");
|
||||||
}
|
}
|
||||||
|
@ -6,16 +6,16 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@for (show of shows; track show.id) {
|
@for (show of shows | async; track show.uid) {
|
||||||
@if (isToEdit(show)) {
|
@if (isToEdit(show)) {
|
||||||
<td><input class="form-control" id="newShowId" name="newShowId" type="number" [(ngModel)]="show.id"></td>
|
<td><input class="form-control" id="newShowId" name="newShowId" type="number" [(ngModel)]="show.uid"></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.id }}</td>
|
<td>{{ show.uid }}</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>
|
||||||
|
@ -1,18 +1,24 @@
|
|||||||
import {Component, EventEmitter, Input, Output} from '@angular/core';
|
import {Component, EventEmitter, inject, 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';
|
||||||
|
|
||||||
@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 {
|
||||||
@Input() shows: Show[] = [];
|
showService: ShowService = inject(ShowService);
|
||||||
|
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, "");
|
||||||
|
|
||||||
@ -31,13 +37,13 @@ export class ShowListComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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));
|
// this.shows.sort((a, b) => (a.uid ?? 0) - (b.uid ?? 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 {
|
isToEdit(show: Show): boolean {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
export class Show {
|
export class Show {
|
||||||
constructor(public id?: number, public title?: string, public image?: string, public summary?: string) {
|
constructor(public uid?: number, public title?: string, public image?: string, public summary?: string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,21 +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} from '@angular/fire/firestore';
|
||||||
|
import {Observable} from 'rxjs';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
})
|
})
|
||||||
export class ShowService {
|
export class ShowService {
|
||||||
private shows: Show[] = [];
|
private readonly shows$!: Observable<Show[]>;
|
||||||
|
private seriesCollection = 'table_show';
|
||||||
|
|
||||||
constructor() {
|
constructor(private firestore: Firestore) {
|
||||||
this.shows.push(new Show(1, 'Vikings'));
|
const showsRef = collection(this.firestore, this.seriesCollection);
|
||||||
this.shows.push(new Show(2, 'Friends'));
|
this.shows$ = collectionData(showsRef, {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$;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user