Adding identify of external shows

This commit is contained in:
Zoe Roux 2020-05-03 03:05:36 +02:00
parent 65563611f4
commit 0b49518b0b
8 changed files with 75 additions and 18 deletions

View File

@ -1,6 +1,6 @@
@import "~bootstrap//scss/functions"; @import "~bootstrap/scss/functions";
@import "~bootstrap/scss/variables"; @import "~bootstrap/scss/variables";
@import "~bootstrap/scss//mixins/breakpoints"; @import "~bootstrap/scss/mixins/breakpoints";
.root .root
{ {

View File

@ -84,15 +84,22 @@
<mat-panel-title>Identify show</mat-panel-title> <mat-panel-title>Identify show</mat-panel-title>
<mat-panel-description>Search on metadata providers</mat-panel-description> <mat-panel-description>Search on metadata providers</mat-panel-description>
</mat-expansion-panel-header> </mat-expansion-panel-header>
<mat-form-field class="w-100 mx-5"> <mat-form-field class="w-100 mx-2">
<mat-label>Search for</mat-label> <mat-label>Search for</mat-label>
<input matInput value="{{show.title}}" (input)="this.reIdentify($event.target.value)"> <input matInput value="{{show.title}}" (input)="this.reIdentify($event.target.value)">
</mat-form-field> </mat-form-field>
<app-show-grid #identifyGrid [externalShows]="true"></app-show-grid> <mat-form-field *ngFor="let provider of this.providers" class="provider px-1">
<mat-label>{{provider.name}} ID</mat-label>
<input matInput [value]="this.getMetadataID(show, provider)?.dataID" (input)="this.setMetadataID(show, provider, $event.target.value)" >
</mat-form-field>
<app-show-grid #identifyGrid [externalShows]="true" (clickCallback)="this.identifyID($event)"></app-show-grid>
</mat-expansion-panel> </mat-expansion-panel>
</mat-accordion> </mat-accordion>
</div> </div>
<div mat-dialog-actions align="end"> <div mat-dialog-actions align="end">
<button mat-button mat-dialog-close>Cancel</button> <button mat-button mat-dialog-close>Cancel</button>
<button mat-button (click)="apply()">Apply</button> <button mat-button (click)="apply()">
<mat-icon *ngIf="this.metadataChanged" style="color: red;" class="mr-2" matTooltip="You changed an external id, the whole show's metadata will be refreshed. Individual changes made won't last." matTooltipPosition="above">warning</mat-icon>
Apply
</button>
</div> </div>

View File

@ -0,0 +1,18 @@
@import "~bootstrap/scss/functions";
@import "~bootstrap/scss/variables";
@import "~bootstrap/scss/mixins/breakpoints";
.provider
{
width: 100%;
@include media-breakpoint-up(md)
{
width: 33%;
}
@include media-breakpoint-up(lg)
{
width: 25%;
}
}

View File

@ -9,22 +9,25 @@ import {Observable, of} from "rxjs";
import {tap} from "rxjs/operators"; import {tap} from "rxjs/operators";
import {Studio} from "../../models/studio"; import {Studio} from "../../models/studio";
import {ShowGridComponent} from "../show-grid/show-grid.component"; import {ShowGridComponent} from "../show-grid/show-grid.component";
import {Provider} from "../../models/provider";
@Component({ @Component({
selector: 'app-metadata-edit', selector: 'app-metadata-edit',
templateUrl: './metadata-edit.component.html', templateUrl: './metadata-edit.component.html',
styleUrls: ['./metadata-edit.component.scss'] styleUrls: ['./metadata-edit.component.scss']
}) })
export class MetadataEditComponent implements OnInit export class MetadataEditComponent
{ {
@ViewChild("genreInput") genreInput: ElementRef<HTMLInputElement>; @ViewChild("genreInput") private genreInput: ElementRef<HTMLInputElement>;
private allGenres: Genre[]; private allGenres: Genre[];
private allStudios: Studio[]; private allStudios: Studio[];
@ViewChild("identifyGrid") private identifyGrid: ShowGridComponent;
private identifing: Observable<Show[]>; private identifing: Observable<Show[]>;
private identifiedShows: [string, Show[]]; private identifiedShows: [string, Show[]];
@ViewChild("identifyGrid") private identifyGrid: ShowGridComponent; private providers: Provider[];
public metadataChanged: boolean = false;
constructor(public dialogRef: MatDialogRef<MetadataEditComponent>, @Inject(MAT_DIALOG_DATA) public show: Show, private http: HttpClient) constructor(public dialogRef: MatDialogRef<MetadataEditComponent>, @Inject(MAT_DIALOG_DATA) public show: Show, private http: HttpClient)
{ {
@ -36,14 +39,14 @@ export class MetadataEditComponent implements OnInit
{ {
this.allStudios = result; this.allStudios = result;
}); });
this.http.get<Provider[]>("/api/providers").subscribe(result =>
{
this.providers = result;
});
this.reIdentify(this.show.title); this.reIdentify(this.show.title);
} }
ngOnInit(): void
{
}
apply(): void apply(): void
{ {
this.http.post("/api/show/edit/" + this.show.slug, this.show).subscribe(() => this.http.post("/api/show/edit/" + this.show.slug, this.show).subscribe(() =>
@ -103,7 +106,28 @@ export class MetadataEditComponent implements OnInit
reIdentify(search: string) reIdentify(search: string)
{ {
console.log("Searching for " + search);
this.identityShow(search).subscribe(x => this.identifyGrid.shows = x); this.identityShow(search).subscribe(x => this.identifyGrid.shows = x);
} }
getMetadataID(show: Show, provider: Provider)
{
return show.externalIDs.find(x => x.provider.name == provider.name);
}
setMetadataID(show: Show, provider: Provider, id: string)
{
let i = show.externalIDs.findIndex(x => x.provider.name == provider.name);
this.metadataChanged = true;
if (i != -1)
show.externalIDs[i].dataID = id;
else
show.externalIDs.push({provider: provider, dataID: id, link: undefined});
}
identifyID(show: Show)
{
for (let id of show.externalIDs)
this.setMetadataID(this.show, id.provider, id.dataID);
}
} }

View File

@ -1,7 +1,7 @@
<div class="container-fluid"> <div class="container-fluid">
<div *ngFor="let show of this.shows" class="show-container"> <div *ngFor="let show of this.shows" class="show-container">
<mat-card class="show"> <mat-card class="show">
<a [href]="getLink(show)" [routerLink]="getLink(show)" class="d-flex"> <a [href]="getLink(show)" [routerLink]="getLink(show)" class="d-flex" (click)="this.clickCallback.emit(show)">
<div class="thumb"> <div class="thumb">
<div [style.background-image]="getThumb(show)"> </div> <div [style.background-image]="getThumb(show)"> </div>
</div> </div>

View File

@ -1,4 +1,4 @@
import {AfterViewInit, Component, Input, OnInit} from '@angular/core'; import {AfterViewInit, Component, EventEmitter, Input, OnInit, Output} from '@angular/core';
import {Show} from "../../models/show"; import {Show} from "../../models/show";
import {DomSanitizer} from "@angular/platform-browser"; import {DomSanitizer} from "@angular/platform-browser";
@ -11,6 +11,7 @@ export class ShowGridComponent
{ {
@Input() shows: Show[] @Input() shows: Show[]
@Input() externalShows: boolean = false; @Input() externalShows: boolean = false;
@Output() clickCallback: EventEmitter<Show> = new EventEmitter();
constructor(private sanitizer: DomSanitizer) { } constructor(private sanitizer: DomSanitizer) { }

View File

@ -1,6 +1,8 @@
import {Provider} from "./provider"
export interface ExternalID export interface ExternalID
{ {
provider: {name: string, logo: string}; provider: Provider;
id: string; dataID: string;
link: string; link: string;
} }

5
src/models/provider.ts Normal file
View File

@ -0,0 +1,5 @@
export interface Provider
{
name: string;
logo: string;
}