|
|
@ -1,8 +1,8 @@
|
|
|
|
import {COMMA, ENTER} from "@angular/cdk/keycodes";
|
|
|
|
import {COMMA, ENTER, K} from "@angular/cdk/keycodes";
|
|
|
|
import { Component, OnInit, ElementRef, ViewChild } from "@angular/core";
|
|
|
|
import { Component, OnInit, ElementRef, ViewChild } from "@angular/core";
|
|
|
|
import { MatAutocomplete } from "@angular/material/autocomplete";
|
|
|
|
import { MatAutocomplete } from "@angular/material/autocomplete";
|
|
|
|
|
|
|
|
|
|
|
|
import { ITheMovieDbSettings, IMovieDbKeyword, IMovieDbGenre } from "../../interfaces";
|
|
|
|
import { ITheMovieDbSettings, IMovieDbKeyword } from "../../interfaces";
|
|
|
|
import { NotificationService } from "../../services";
|
|
|
|
import { NotificationService } from "../../services";
|
|
|
|
import { SettingsService } from "../../services";
|
|
|
|
import { SettingsService } from "../../services";
|
|
|
|
import { TheMovieDbService } from "../../services";
|
|
|
|
import { TheMovieDbService } from "../../services";
|
|
|
@ -15,12 +15,6 @@ interface IKeywordTag {
|
|
|
|
initial: boolean;
|
|
|
|
initial: boolean;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
interface IGenres {
|
|
|
|
|
|
|
|
id: number;
|
|
|
|
|
|
|
|
name: string;
|
|
|
|
|
|
|
|
initial: boolean;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
@Component({
|
|
|
|
templateUrl: "./themoviedb.component.html",
|
|
|
|
templateUrl: "./themoviedb.component.html",
|
|
|
|
styleUrls: ["./themoviedb.component.scss"]
|
|
|
|
styleUrls: ["./themoviedb.component.scss"]
|
|
|
@ -29,12 +23,12 @@ export class TheMovieDbComponent implements OnInit {
|
|
|
|
|
|
|
|
|
|
|
|
public settings: ITheMovieDbSettings;
|
|
|
|
public settings: ITheMovieDbSettings;
|
|
|
|
public excludedKeywords: IKeywordTag[];
|
|
|
|
public excludedKeywords: IKeywordTag[];
|
|
|
|
public excludedMovieGenres: IGenres[];
|
|
|
|
public excludedMovieGenres: IKeywordTag[];
|
|
|
|
public excludedTvGenres: IGenres[];
|
|
|
|
public excludedTvGenres: IKeywordTag[];
|
|
|
|
public tagForm: FormGroup;
|
|
|
|
public tagForm: FormGroup;
|
|
|
|
public filteredTags: IMovieDbKeyword[];
|
|
|
|
public filteredTags: IMovieDbKeyword[];
|
|
|
|
public filteredMovieGenres: IMovieDbGenre[];
|
|
|
|
public filteredMovieGenres: IMovieDbKeyword[];
|
|
|
|
public filteredTvGenres: IMovieDbGenre[];
|
|
|
|
public filteredTvGenres: IMovieDbKeyword[];
|
|
|
|
|
|
|
|
|
|
|
|
@ViewChild('fruitInput') public fruitInput: ElementRef<HTMLInputElement>;
|
|
|
|
@ViewChild('fruitInput') public fruitInput: ElementRef<HTMLInputElement>;
|
|
|
|
|
|
|
|
|
|
|
@ -46,6 +40,8 @@ export class TheMovieDbComponent implements OnInit {
|
|
|
|
public ngOnInit() {
|
|
|
|
public ngOnInit() {
|
|
|
|
this.tagForm = this.fb.group({
|
|
|
|
this.tagForm = this.fb.group({
|
|
|
|
input: null,
|
|
|
|
input: null,
|
|
|
|
|
|
|
|
excludedMovieGenres: null,
|
|
|
|
|
|
|
|
excludedTvGenres: null,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
this.settingsService.getTheMovieDbSettings().subscribe(settings => {
|
|
|
|
this.settingsService.getTheMovieDbSettings().subscribe(settings => {
|
|
|
|
this.settings = settings;
|
|
|
|
this.settings = settings;
|
|
|
@ -77,14 +73,16 @@ export class TheMovieDbComponent implements OnInit {
|
|
|
|
: [];
|
|
|
|
: [];
|
|
|
|
|
|
|
|
|
|
|
|
this.tmdbService.getGenres("movie").subscribe(results => {
|
|
|
|
this.tmdbService.getGenres("movie").subscribe(results => {
|
|
|
|
results.forEach(genre => {
|
|
|
|
this.filteredMovieGenres = results;
|
|
|
|
this.excludedMovieGenres.forEach(key => {
|
|
|
|
|
|
|
|
this.excludedMovieGenres.filter((val, idx) => {
|
|
|
|
this.excludedMovieGenres.forEach(genre => {
|
|
|
|
val.name = genre.name
|
|
|
|
results.forEach(result => {
|
|
|
|
})
|
|
|
|
if (genre.id == result.id) {
|
|
|
|
})
|
|
|
|
genre.name = result.name;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// Map Tv Genre ids -> genre name
|
|
|
|
// Map Tv Genre ids -> genre name
|
|
|
|
this.excludedTvGenres = settings.excludedTvGenreIds
|
|
|
|
this.excludedTvGenres = settings.excludedTvGenreIds
|
|
|
@ -96,13 +94,15 @@ export class TheMovieDbComponent implements OnInit {
|
|
|
|
: [];
|
|
|
|
: [];
|
|
|
|
|
|
|
|
|
|
|
|
this.tmdbService.getGenres("tv").subscribe(results => {
|
|
|
|
this.tmdbService.getGenres("tv").subscribe(results => {
|
|
|
|
results.forEach(genre => {
|
|
|
|
this.filteredTvGenres = results;
|
|
|
|
this.excludedTvGenres.forEach(key => {
|
|
|
|
|
|
|
|
this.excludedTvGenres.filter((val, idx) => {
|
|
|
|
this.excludedTvGenres.forEach(genre => {
|
|
|
|
val.name = genre.name
|
|
|
|
results.forEach(result => {
|
|
|
|
})
|
|
|
|
if (genre.id == result.id) {
|
|
|
|
})
|
|
|
|
genre.name = result.name;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
@ -119,16 +119,46 @@ export class TheMovieDbComponent implements OnInit {
|
|
|
|
.subscribe((r) => (this.filteredTags = r));
|
|
|
|
.subscribe((r) => (this.filteredTags = r));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public remove(tag: IKeywordTag): void {
|
|
|
|
public remove(tag: IKeywordTag, tag_type: string): void {
|
|
|
|
const index = this.excludedKeywords.indexOf(tag);
|
|
|
|
var exclusion_list;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch (tag_type) {
|
|
|
|
|
|
|
|
case "keyword":
|
|
|
|
|
|
|
|
exclusion_list = this.excludedKeywords;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "movieGenre":
|
|
|
|
|
|
|
|
exclusion_list = this.excludedMovieGenres;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "tvGenre":
|
|
|
|
|
|
|
|
exclusion_list = this.excludedTvGenres;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const index = exclusion_list.indexOf(tag);
|
|
|
|
|
|
|
|
|
|
|
|
if (index >= 0) {
|
|
|
|
if (index >= 0) {
|
|
|
|
this.excludedKeywords.splice(index, 1);
|
|
|
|
exclusion_list.splice(index, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public save() {
|
|
|
|
public save() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var selectedMovieGenres: number[] = this.tagForm.controls.excludedMovieGenres.value ?? [];
|
|
|
|
|
|
|
|
var selectedTvGenres: number[] = this.tagForm.controls.excludedTvGenres.value ?? [];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var movieIds: number[] = this.excludedMovieGenres.map(k => k.id);
|
|
|
|
|
|
|
|
var tvIds: number[] = this.excludedTvGenres.map(k => k.id)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Concat and dedup already excluded genres + newly selected ones
|
|
|
|
|
|
|
|
selectedMovieGenres = movieIds.concat(selectedMovieGenres.filter(item => movieIds.indexOf(item) < 0));
|
|
|
|
|
|
|
|
selectedTvGenres = tvIds.concat(selectedTvGenres.filter(item => tvIds.indexOf(item) < 0));
|
|
|
|
|
|
|
|
|
|
|
|
this.settings.excludedKeywordIds = this.excludedKeywords.map(k => k.id);
|
|
|
|
this.settings.excludedKeywordIds = this.excludedKeywords.map(k => k.id);
|
|
|
|
|
|
|
|
this.settings.excludedMovieGenreIds = selectedMovieGenres;
|
|
|
|
|
|
|
|
this.settings.excludedTvGenreIds = selectedTvGenres;
|
|
|
|
|
|
|
|
|
|
|
|
this.settingsService.saveTheMovieDbSettings(this.settings).subscribe(x => {
|
|
|
|
this.settingsService.saveTheMovieDbSettings(this.settings).subscribe(x => {
|
|
|
|
if (x) {
|
|
|
|
if (x) {
|
|
|
|
this.notificationService.success("Successfully saved The Movie Database settings");
|
|
|
|
this.notificationService.success("Successfully saved The Movie Database settings");
|
|
|
|