Skip to content

Commit

Permalink
Merge pull request #3849 from tidusjar/themoviedbkeywords
Browse files Browse the repository at this point in the history
Themoviedbkeywords
  • Loading branch information
tidusjar authored Nov 3, 2020
2 parents 535b419 + 3aa28a5 commit 1104bd4
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 136 deletions.
12 changes: 7 additions & 5 deletions src/Ombi.Core.Tests/Rule/Search/EmbyAvailabilityRuleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,15 @@ public async Task Movie_Has_Custom_Url_When_Specified_In_Settings()
{
new EmbyServers
{
ServerHostname = "http://test.com/"
ServerHostname = "http://test.com/",
ServerId = "8"
}
}
});
ContextMock.Setup(x => x.GetByTheMovieDbId(It.IsAny<string>())).ReturnsAsync(new EmbyContent
{
ProviderId = "123",
EmbyId = 1.ToString()
EmbyId = 1.ToString(),
});
var search = new SearchMovieViewModel()
{
Expand All @@ -70,7 +71,7 @@ public async Task Movie_Has_Custom_Url_When_Specified_In_Settings()
var result = await Rule.Execute(search);

Assert.True(result.Success);
Assert.That(search.EmbyUrl, Is.EqualTo("http://test.com/#!/item?id=1"));
Assert.That(search.EmbyUrl, Is.EqualTo("http://test.com/web/index.html#!/item?id=1&serverId=8"));
}

[Test]
Expand All @@ -83,7 +84,8 @@ public async Task Movie_Uses_Default_Url_When()
{
new EmbyServers
{
ServerHostname = string.Empty
ServerHostname = string.Empty,
ServerId = "8"
}
}
});
Expand All @@ -99,7 +101,7 @@ public async Task Movie_Uses_Default_Url_When()
var result = await Rule.Execute(search);

Assert.True(result.Success);
Assert.That(search.EmbyUrl, Is.EqualTo("https://app.emby.media/#!/item?id=1"));
Assert.That(search.EmbyUrl, Is.EqualTo("https://app.emby.media/web/index.html#!/item?id=1&serverId=8"));
}

[Test]
Expand Down
2 changes: 1 addition & 1 deletion src/Ombi.Helpers/EmbyHelper.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Ombi.Helpers
{
public class EmbyHelper
public static class EmbyHelper
{
public static string GetEmbyMediaUrl(string mediaId, string serverId, string customerServerUrl = null, bool isJellyfin = false)
{
Expand Down
4 changes: 3 additions & 1 deletion src/Ombi.Store/Context/Sqlite/SettingsSqliteContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ private void Upgrade()
Database.ExecuteSqlRaw(@"INSERT OR IGNORE INTO __EFMigrationsHistory (MigrationId,ProductVersion)
VALUES('20191103205204_Inital', '2.2.6-servicing-10079'); ");
}
catch (Exception)
#pragma warning disable RCS1075 // Avoid empty catch clause that catches System.Exception.
catch (Exception)
#pragma warning restore RCS1075 // Avoid empty catch clause that catches System.Exception.
{
// ignored
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,76 +1,55 @@
<settings-menu></settings-menu>
<div class="small-middle-container">
<fieldset *ngIf="settings">
<legend>The Movie Database</legend>
<div class="md-form-field" style="margin-top:1em;">
<div class="form-group">
<div class="checkbox">
<mat-checkbox id="showAdultMovies" name="showAdultMovies" [(ngModel)]="settings.showAdultMovies" matTooltip="Include adult movies (pornography) in results">
Show Adult Movies</mat-checkbox>
Upgraded <fieldset *ngIf="settings">
<legend>The Movie Database</legend>
<div class="md-form-field" style="margin-top:1em;">
<div class="form-group">
<div class="checkbox">
<mat-slide-toggle id="showAdultMovies" name="showAdultMovies" [(ngModel)]="settings.showAdultMovies"
matTooltip="Include adult movies (pornography) in results">
Show Adult Movies</mat-slide-toggle>
</div>
</div>
</div>

<div class="form-group">
<label class="control-label" matTooltip="Prevent movies with certain keywords from being suggested. May require a restart to take effect.">
Excluded Keyword IDs for Movie Suggestions
</label>
<form [formGroup]='tagForm'>
<mat-form-field class="example-chip-list">
<mat-chip-list #chipList>
<mat-chip *ngFor="let fruit of excludedKeywords" [selectable]="false"
[removable]="true" (removed)="remove(fruit)">
{{fruit.name}}
<mat-icon matChipRemove >cancel</mat-icon>
</mat-chip>
<input placeholder="New Keyword"
#fruitInput
formControlName='input'
[matChipInputFor]="chipList"
[matChipInputSeparatorKeyCodes]="separatorKeysCodes"
[matChipInputAddOnBlur]="true"
>
</mat-chip-list>
<mat-autocomplete #auto="matAutocomplete" (optionSelected)="selected($event)">
<mat-option *ngFor="let fruit of filteredTags" [value]="fruit">
{{fruit.name}}
</mat-option>
</mat-autocomplete>
</mat-form-field>
</form>
<!-- <tag-input #input
[(ngModel)]="excludedKeywords"
[identifyBy]="'id'" [displayBy]="'name'"
[placeholder]="'Search by keyword'"
[secondaryPlaceholder]="'Search by keyword'"
[theme]="'dark'"
[onTextChangeDebounce]="500"
[onAdding]="onAddingKeyword"
(onSelect)="onKeywordSelect($event)">
<ng-template item-template let-item="item" let-index="index">
<span class="fa fa-cloud-download" *ngIf="item.initial"></span>
<span>{{item.id}}</span>
<span *ngIf="!item.initial">&nbsp;({{item.name}})</span>
<delete-icon aria-label="Remove tag" role="button"
(click)="input.removeItem(item, index)">
</delete-icon>
</ng-template>
<tag-input-dropdown [autocompleteObservable]="autocompleteKeyword"
[identifyBy]="'id'" [displayBy]="'name'"
[limitItemsTo]="6"
[minimumTextLength]="1"
[showDropdownIfEmpty]="false"
[keepOpen]="false">
</tag-input-dropdown>
</tag-input> -->
</div>
<div class="form-group">
<form [formGroup]='tagForm'>

<mat-form-field class="example-full-width">
<input type="text" placeholder="Excluded Keyword IDs for Movie Suggestions" matInput
formControlName="input" [matAutocomplete]="auto"
matTooltip="Prevent movies with certain keywords from being suggested. May require a restart to take effect.">
<mat-autocomplete (optionSelected)="optionSelected($event.option.value)" autoActiveFirstOption
#auto="matAutocomplete">
<mat-option *ngFor="let option of filteredTags" [value]="option">
{{option.name}}
</mat-option>
</mat-autocomplete>
</mat-form-field>

<mat-chip-list #chipList>
<mat-chip *ngFor="let key of excludedKeywords" [selectable]="false" [removable]="true"
(removed)="remove(key)">
{{key.name}}
<mat-icon matChipRemove>cancel</mat-icon>
</mat-chip>
</mat-chip-list>

</form>
</div>

<div class="form-group">
<div>
<button mat-raised-button (click)="save()" type="submit" id="save" class="mat-focus-indicator mat-stroked-button accent mat-accent mat-raised-button mat-button-base" ng-reflect-disabled="false">
<span class="mat-button-wrapper">Submit</span><div matripple="" class="mat-ripple mat-button-ripple" ng-reflect-disabled="false" ng-reflect-centered="false" ng-reflect-trigger="[object HTMLButtonElement]"></div>
<div class="mat-button-focus-overlay"></div></button><div class="md-form-field" style="margin-top:1em;"></div>
<div class="form-group">
<div>
<button mat-raised-button (click)="save()" type="submit" id="save"
class="mat-focus-indicator mat-stroked-button accent mat-accent mat-raised-button mat-button-base"
ng-reflect-disabled="false">
<span class="mat-button-wrapper">Submit</span>
<div matripple="" class="mat-ripple mat-button-ripple" ng-reflect-disabled="false"
ng-reflect-centered="false" ng-reflect-trigger="[object HTMLButtonElement]"></div>
<div class="mat-button-focus-overlay"></div>
</button>
<div class="md-form-field" style="margin-top:1em;"></div>
</div>
</div>
</div>
</div>
</fieldset>
</fieldset>
</div>
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import {COMMA, ENTER} from "@angular/cdk/keycodes";
import { Component, OnInit, ElementRef, ViewChild } from "@angular/core";
import { MatChipInputEvent } from "@angular/material/chips";
import { MatAutocompleteSelectedEvent, MatAutocomplete } from "@angular/material/autocomplete";
import { empty, of, Observable } from "rxjs";
import { MatAutocomplete } from "@angular/material/autocomplete";

import { ITheMovieDbSettings, IMovieDbKeyword } from "../../interfaces";
import { NotificationService } from "../../services";
import { SettingsService } from "../../services";
import { TheMovieDbService } from "../../services";
import { FormControl, FormBuilder, FormGroup } from "@angular/forms";
import { startWith, map, debounceTime, tap, switchMap, finalize } from "rxjs/operators";
import { FormBuilder, FormGroup } from "@angular/forms";
import { debounceTime, switchMap } from "rxjs/operators";

interface IKeywordTag {
id: number;
Expand All @@ -28,9 +26,6 @@ export class TheMovieDbComponent implements OnInit {
public tagForm: FormGroup;
public filteredTags: IMovieDbKeyword[];
@ViewChild('fruitInput') public fruitInput: ElementRef<HTMLInputElement>;
@ViewChild('auto') public matAutocomplete: MatAutocomplete;

private readonly separatorKeysCodes: number[] = [ENTER, COMMA];

constructor(private settingsService: SettingsService,
private notificationService: NotificationService,
Expand All @@ -50,6 +45,13 @@ export class TheMovieDbComponent implements OnInit {
initial: true,
}))
: [];
this.excludedKeywords.forEach(key => {
this.tmdbService.getKeyword(key.id).subscribe(keyResult => {
this.excludedKeywords.filter((val, idx) => {
val.name = keyResult.name;
})
});
});
});

this.tagForm
Expand All @@ -64,61 +66,8 @@ export class TheMovieDbComponent implements OnInit {
)
.subscribe((r) => (this.filteredTags = r));

// this.tagForm.controls.input.valueChanges
// .pipe(
// debounceTime(500),
// switchMap(value => this.tmdbService.getKeywords(value))
// )
// .subscribe((data: IMovieDbKeyword[]) => {
// this.filteredTags = data;
// });
}

public async selected(event: MatAutocompleteSelectedEvent) {
const keywordId = await this.tmdbService.getKeyword(+event.option.value).toPromise();
this.excludedKeywords.push({ id: keywordId.id, name: keywordId.name, initial: false});
this.fruitInput.nativeElement.value = '';
this.tagForm.controls.input.setValue(null);
}

public autocompleteKeyword = (text: string) => this.tmdbService.getKeywords(text);

public onAddingKeyword = (tag: string | IKeywordTag) => {
if (typeof tag === "string") {
const id = Number(tag);
return isNaN(id) ? empty() : this.tmdbService.getKeyword(id);
} else {
return of(tag);
}
}

public onKeywordSelect = (keyword: IKeywordTag) => {
if (keyword.initial) {
this.tmdbService.getKeyword(keyword.id)
.subscribe(k => {
keyword.name = k.name;
keyword.initial = false;
});
}
}

public async add(event: MatChipInputEvent) {
const input = event.input;
const value = event.value;

// Add our fruit
if ((value || '').trim()) {
const keyword = await this.tmdbService.getKeywords(value).toPromise();
this.excludedKeywords.push({ id: keyword[0].id, name: keyword[0].name, initial: false });
}

// Reset the input value
if (input) {
input.value = '';
}
this.tagForm.controls.input.setValue(null);
}

public remove(tag: IKeywordTag): void {
const index = this.excludedKeywords.indexOf(tag);

Expand All @@ -137,4 +86,13 @@ export class TheMovieDbComponent implements OnInit {
}
});
}

public async optionSelected(item: IMovieDbKeyword) {

if ((item.name || '').trim()) {
this.excludedKeywords.push({ id: item.id, name: item.name, initial: false });
}

this.tagForm.controls.input.setValue(null);
}
}

0 comments on commit 1104bd4

Please sign in to comment.