Add IMDb movie importer feature and unify header
Introduces a new movie importer feature allowing admins to search and import movies from IMDb, including new components for search, result display, and error handling. Replaces the schedule header with a reusable menu header component. Updates routing, navigation, and HTTP service to support the new importer. Adds a poster placeholder image and improves poster error handling.
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
import { Component, inject, input } from '@angular/core';
|
||||
import { Film, OmdbMovie } from '@infinimotion/model-frontend';
|
||||
import { HttpService } from '../http.service';
|
||||
import { LoadingService } from '../loading.service';
|
||||
import { catchError, EMPTY, of, switchMap, tap } from 'rxjs';
|
||||
|
||||
@Component({
|
||||
selector: 'app-movie-import-search-info',
|
||||
standalone: false,
|
||||
templateUrl: './movie-import-search-info.component.html',
|
||||
styleUrl: './movie-import-search-info.component.css'
|
||||
})
|
||||
export class MovieImportSearchInfoComponent {
|
||||
readonly movie = input.required<OmdbMovie>();
|
||||
|
||||
importedMovie: Film | undefined;
|
||||
buttonDisabled = false;
|
||||
buttonText: string = "Film von IMDb importieren";
|
||||
buttonIcon: string = "cloud_download"
|
||||
|
||||
private http = inject(HttpService)
|
||||
private loading = inject(LoadingService)
|
||||
|
||||
importMovie(imdbId: string, title: string) {
|
||||
this.buttonDisabled = true;
|
||||
this.loading.show();
|
||||
|
||||
const filter = this.generateTitleFilter(title);
|
||||
|
||||
this.http.getMoviesByFilter(filter).pipe(
|
||||
switchMap(movies => {
|
||||
if (movies.length !== 0) {
|
||||
this.loading.showError(`Dublette erkannt! Film '${title}' existiert bereits.`);
|
||||
console.warn('Dublette erkannt. Import abgebrochen.');
|
||||
this.buttonText = 'Film existiert bereits'
|
||||
this.buttonIcon = 'file_present';
|
||||
return EMPTY;
|
||||
}
|
||||
return this.http.importMovie(imdbId);
|
||||
}),
|
||||
tap(importedMovie => {
|
||||
this.importedMovie = importedMovie;
|
||||
this.buttonText = `Film erfolgreich importiert (Id: ${importedMovie.id})`;
|
||||
this.buttonIcon = 'cloud_done';
|
||||
this.loading.hide();
|
||||
}),
|
||||
catchError(err => {
|
||||
this.buttonDisabled = false;
|
||||
this.loading.showError(err);
|
||||
console.error('Fehler beim Import oder bei der Dublettenprüfung', err);
|
||||
return of([]);
|
||||
})
|
||||
).subscribe();
|
||||
}
|
||||
|
||||
private generateTitleFilter(title: string): string[] {
|
||||
return [`eq;title;string;${title}`]
|
||||
}
|
||||
|
||||
onPosterError(event: Event) {
|
||||
const img = event.target as HTMLImageElement;
|
||||
const placeholder = 'assets/poster_placeholder.png';
|
||||
|
||||
if (img.src !== window.location.origin + placeholder) {
|
||||
img.src = placeholder;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user