From 9f164e4098387fa255e037dd184c80db879162d3 Mon Sep 17 00:00:00 2001 From: "Jamie.Rees" Date: Mon, 18 Sep 2017 14:40:22 +0100 Subject: [PATCH] Fixed the issue with the tv search not working #1463 --- .../Engine/Interfaces/ITvSearchEngine.cs | 15 +++--- src/Ombi.Core/Engine/TreeNode.cs | 14 +++++ src/Ombi.Core/Engine/TvSearchEngine.cs | 53 +++++++++++++++---- .../app/search/moviesearch.component.html | 17 +++--- .../search/seriesinformation.component.html | 14 ++--- .../app/search/seriesinformation.component.ts | 1 - .../app/search/tvsearch.component.html | 7 +-- .../app/search/tvsearch.component.ts | 48 ++++++----------- .../ClientApp/app/services/search.service.ts | 16 ++++-- src/Ombi/Controllers/SearchController.cs | 32 +++++++++-- src/Ombi/Ombi.csproj | 2 +- src/Ombi/wwwroot/loading.css | 1 + 12 files changed, 132 insertions(+), 88 deletions(-) create mode 100644 src/Ombi.Core/Engine/TreeNode.cs diff --git a/src/Ombi.Core/Engine/Interfaces/ITvSearchEngine.cs b/src/Ombi.Core/Engine/Interfaces/ITvSearchEngine.cs index 5e02d4409..06a419214 100644 --- a/src/Ombi.Core/Engine/Interfaces/ITvSearchEngine.cs +++ b/src/Ombi.Core/Engine/Interfaces/ITvSearchEngine.cs @@ -7,15 +7,12 @@ namespace Ombi.Core.Engine.Interfaces public interface ITvSearchEngine { Task> Search(string searchTerm); - + Task>> SearchTreeNode(string searchTerm); + Task> GetShowInformationTreeNode(int tvdbid); Task GetShowInformation(int tvdbid); - - Task> Popular(); - - Task> Anticipated(); - - Task> MostWatches(); - - Task> Trending(); + Task>> Popular(); + Task>> Anticipated(); + Task>> MostWatches(); + Task>> Trending(); } } \ No newline at end of file diff --git a/src/Ombi.Core/Engine/TreeNode.cs b/src/Ombi.Core/Engine/TreeNode.cs new file mode 100644 index 000000000..1744b8ffd --- /dev/null +++ b/src/Ombi.Core/Engine/TreeNode.cs @@ -0,0 +1,14 @@ +using System.Collections.Generic; + +namespace Ombi.Core.Engine +{ + + public class TreeNode + { + public string Label { get; set; } + public T Data { get; set; } + public List> Children { get; set; } + public bool Leaf { get; set; } + public bool Expanded { get; set; } + } +} \ No newline at end of file diff --git a/src/Ombi.Core/Engine/TvSearchEngine.cs b/src/Ombi.Core/Engine/TvSearchEngine.cs index 54ca37a33..d54f00a93 100644 --- a/src/Ombi.Core/Engine/TvSearchEngine.cs +++ b/src/Ombi.Core/Engine/TvSearchEngine.cs @@ -54,6 +54,11 @@ namespace Ombi.Core.Engine return null; } + public async Task>> SearchTreeNode(string searchTerm) + { + var result = await Search(searchTerm); + return result.Select(ParseIntoTreeNode).ToList(); + } public async Task GetShowInformation(int tvdbid) { var show = await TvMazeApi.ShowLookupByTheTvDbId(tvdbid); @@ -77,7 +82,7 @@ namespace Ombi.Core.Engine Title = e.name, AirDate = DateTime.Parse(e.airstamp), EpisodeNumber = e.number, - + }); mapped.SeasonRequests.Add(newSeason); } @@ -100,29 +105,55 @@ namespace Ombi.Core.Engine return await ProcessResult(mapped, existingRequests, plexSettings, embySettings); } - public async Task> Popular() + public async Task> GetShowInformationTreeNode(int tvdbid) + { + var result = await GetShowInformation(tvdbid); + return ParseIntoTreeNode(result); + } + + public async Task>> Popular() { var result = await TraktApi.GetPopularShows(); - return await ProcessResults(result); + var processed = await ProcessResults(result); + return processed.Select(ParseIntoTreeNode).ToList(); } - public async Task> Anticipated() + public async Task>> Anticipated() { var result = await TraktApi.GetAnticipatedShows(); - return await ProcessResults(result); + var processed= await ProcessResults(result); + return processed.Select(ParseIntoTreeNode).ToList(); } - public async Task> MostWatches() + public async Task>> MostWatches() { var result = await TraktApi.GetMostWatchesShows(); - return await ProcessResults(result); + var processed = await ProcessResults(result); + return processed.Select(ParseIntoTreeNode).ToList(); } - public async Task> Trending() + public async Task>> Trending() { var result = await TraktApi.GetTrendingShows(); - return await ProcessResults(result); + var processed = await ProcessResults(result); + return processed.Select(ParseIntoTreeNode).ToList(); } + private static TreeNode ParseIntoTreeNode(SearchTvShowViewModel result) + { + return new TreeNode + { + Data = result, + Children = new List> + { + new TreeNode + { + Data = result, Leaf = true + } + }, + Leaf = false + }; + } + private async Task> ProcessResults(IEnumerable items) { @@ -180,13 +211,13 @@ namespace Ombi.Core.Engine // Find the existing request season var existingSeason = existingRequestChildRequest.SeasonRequests.FirstOrDefault(x => x.SeasonNumber == season.SeasonNumber); - if(existingSeason == null) continue; + if (existingSeason == null) continue; foreach (var ep in existingSeason.Episodes) { // Find the episode from what we are searching var episodeSearching = season.Episodes.FirstOrDefault(x => x.EpisodeNumber == ep.EpisodeNumber); - if(episodeSearching == null) + if (episodeSearching == null) { continue; } diff --git a/src/Ombi/ClientApp/app/search/moviesearch.component.html b/src/Ombi/ClientApp/app/search/moviesearch.component.html index c3c8ed468..6d4bbd10e 100644 --- a/src/Ombi/ClientApp/app/search/moviesearch.component.html +++ b/src/Ombi/ClientApp/app/search/moviesearch.component.html @@ -51,17 +51,12 @@ Trailer Available {{result.quality}}p - Processing Request - - - - Pending Approval - - - - Not Yet Requested - - + + Available + Processing Request + Pending Approval + Not Requested + diff --git a/src/Ombi/ClientApp/app/search/seriesinformation.component.html b/src/Ombi/ClientApp/app/search/seriesinformation.component.html index 3748c3452..ce71207be 100644 --- a/src/Ombi/ClientApp/app/search/seriesinformation.component.html +++ b/src/Ombi/ClientApp/app/search/seriesinformation.component.html @@ -54,16 +54,10 @@ {{ep.airDate | date: 'dd/MM/yyyy' }} - Available - Processing Request -
- - Pending Approval - - - - Not Yet Requested - + Available + Processing Request + Pending Approval + Not Requested diff --git a/src/Ombi/ClientApp/app/search/seriesinformation.component.ts b/src/Ombi/ClientApp/app/search/seriesinformation.component.ts index 014047c42..c4c8de00f 100644 --- a/src/Ombi/ClientApp/app/search/seriesinformation.component.ts +++ b/src/Ombi/ClientApp/app/search/seriesinformation.component.ts @@ -39,7 +39,6 @@ export class SeriesInformationComponent implements OnInit, OnDestroy { }); } - public submitRequests() { this.series.requested = true; diff --git a/src/Ombi/ClientApp/app/search/tvsearch.component.html b/src/Ombi/ClientApp/app/search/tvsearch.component.html index 5120fee8b..68bea84d5 100644 --- a/src/Ombi/ClientApp/app/search/tvsearch.component.html +++ b/src/Ombi/ClientApp/app/search/tvsearch.component.html @@ -43,7 +43,7 @@
- poster + poster
@@ -56,10 +56,7 @@ {{node.data.status}} - Air Date: {{node.data.firstAired}} - - - Release Date: {{node.data.releaseDate | date: 'dd/MM/yyyy'}} + Air Date: {{node.data.firstAired | date: 'dd/MM/yyyy'}} Available Processing Request diff --git a/src/Ombi/ClientApp/app/search/tvsearch.component.ts b/src/Ombi/ClientApp/app/search/tvsearch.component.ts index bac0f50cb..f5b526f6a 100644 --- a/src/Ombi/ClientApp/app/search/tvsearch.component.ts +++ b/src/Ombi/ClientApp/app/search/tvsearch.component.ts @@ -9,7 +9,7 @@ import { NotificationService } from '../services/notification.service'; import { ISearchTvResult } from '../interfaces/ISearchTvResult'; import { IRequestEngineResult } from '../interfaces/IRequestEngineResult'; -import { TreeNode } from "primeng/primeng"; +import { TreeNode } from 'primeng/primeng'; @Component({ selector: 'tv-search', @@ -21,7 +21,7 @@ export class TvSearchComponent implements OnInit, OnDestroy { private subscriptions = new Subject(); searchText: string; searchChanged = new Subject(); - tvResults: ISearchTvResult[]; + tvResults: TreeNode[]; result: IRequestEngineResult; searchApplied = false; @@ -38,16 +38,16 @@ export class TvSearchComponent implements OnInit, OnDestroy { this.clearResults(); return; } - this.searchService.searchTv(this.searchText) + this.searchService.searchTvTreeNode(this.searchText) .takeUntil(this.subscriptions) .subscribe(x => { - this.tvResults = this.transformData(x); + this.tvResults = x; this.searchApplied = true; }); }); } openClosestTab(el: any): void { - var rowclass = "undefined"; + let rowclass = "undefined"; el = el.toElement; while (el.className != rowclass) { // Increment the loop to the parent node until we find the row we need @@ -59,9 +59,9 @@ export class TvSearchComponent implements OnInit, OnDestroy { // the class you specified // Then we loop through the children to find the caret which we want to click - var caretright = "ui-treetable-toggler fa fa-fw ui-clickable fa-caret-right"; - var caretdown = "ui-treetable-toggler fa fa-fw ui-clickable fa-caret-down"; - for (var value of el.children) { + let caretright = "ui-treetable-toggler fa fa-fw ui-clickable fa-caret-right"; + let caretdown = "ui-treetable-toggler fa fa-fw ui-clickable fa-caret-down"; + for (let value of el.children) { // the caret from the ui has 2 class selectors depending on if expanded or not // we search for both since we want to still toggle the clicking if (value.className === caretright || value.className === caretdown) { @@ -72,20 +72,7 @@ export class TvSearchComponent implements OnInit, OnDestroy { } }; } - transformData(datain: ISearchTvResult[]): any { - var temp: TreeNode[] = []; - datain.forEach(function (value) { - temp.push({ - "data": value, - "children": [{ - "data": value, leaf: true - }], - leaf: false - }); - }, this) - return temp; - } - + ngOnInit(): void { this.searchText = ""; this.tvResults = []; @@ -143,12 +130,11 @@ export class TvSearchComponent implements OnInit, OnDestroy { getExtraInfo() { this.tvResults.forEach((val, index) => { - this.searchService.getShowInformation(val.id) + this.searchService.getShowInformationTreeNode(val.data.id) .takeUntil(this.subscriptions) .subscribe(x => { - this.updateItem(val, x); + this.updateItem(val.data, x); }); - }); } @@ -161,7 +147,6 @@ export class TvSearchComponent implements OnInit, OnDestroy { .takeUntil(this.subscriptions) .subscribe(x => { this.result = x; - if (this.result.requestAdded) { this.notificationService.success("Request Added", `Request for ${searchResult.title} has been added successfully`); @@ -171,7 +156,6 @@ export class TvSearchComponent implements OnInit, OnDestroy { }); } - allSeasons(searchResult: ISearchTvResult) { searchResult.requestAll = true; this.request(searchResult); @@ -191,11 +175,11 @@ export class TvSearchComponent implements OnInit, OnDestroy { this.route.navigate(['/search/show', searchResult.id]); } - private updateItem(key: ISearchTvResult, updated: ISearchTvResult) { - var index = this.tvResults.indexOf(key, 0); - if (index > -1) { - this.tvResults[index] = updated; - } + private updateItem(key: TreeNode, updated: TreeNode) { + let item = this.tvResults.filter((val) => { + return val.data == key; + }); + item[0].data = updated.data; } private clearResults() { diff --git a/src/Ombi/ClientApp/app/services/search.service.ts b/src/Ombi/ClientApp/app/services/search.service.ts index e5330d477..bb0627bf8 100644 --- a/src/Ombi/ClientApp/app/services/search.service.ts +++ b/src/Ombi/ClientApp/app/services/search.service.ts @@ -5,6 +5,7 @@ import { Observable } from 'rxjs/Rx'; import { ServiceAuthHelpers } from './service.helpers'; import { ISearchMovieResult } from '../interfaces/ISearchMovieResult'; import { ISearchTvResult } from '../interfaces/ISearchTvResult'; +import { TreeNode } from "primeng/primeng"; @Injectable() export class SearchService extends ServiceAuthHelpers { @@ -37,21 +38,28 @@ export class SearchService extends ServiceAuthHelpers { searchTv(searchTerm: string): Observable { return this.http.get(`${this.url}/Tv/` + searchTerm).map(this.extractData); } + searchTvTreeNode(searchTerm: string): Observable { + return this.http.get(`${this.url}/Tv/${searchTerm}/tree`).map(this.extractData); + } + + getShowInformationTreeNode(theTvDbId: number): Observable { + return this.http.get(`${this.url}/Tv/info/${theTvDbId}/Tree`).map(this.extractData); + } getShowInformation(theTvDbId: number): Observable { return this.http.get(`${this.url}/Tv/info/${theTvDbId}`).map(this.extractData); } - popularTv(): Observable { + popularTv(): Observable { return this.http.get(`${this.url}/Tv/popular`).map(this.extractData); } - mostWatchedTv(): Observable { + mostWatchedTv(): Observable { return this.http.get(`${this.url}/Tv/mostwatched`).map(this.extractData); } - anticipatedTv(): Observable { + anticipatedTv(): Observable { return this.http.get(`${this.url}/Tv/anticipated`).map(this.extractData); } - trendingTv(): Observable { + trendingTv(): Observable { return this.http.get(`${this.url}/Tv/trending`).map(this.extractData); } } \ No newline at end of file diff --git a/src/Ombi/Controllers/SearchController.cs b/src/Ombi/Controllers/SearchController.cs index dd31f8392..0cbfe0d69 100644 --- a/src/Ombi/Controllers/SearchController.cs +++ b/src/Ombi/Controllers/SearchController.cs @@ -113,6 +113,30 @@ namespace Ombi.Controllers return await TvEngine.Search(searchTerm); } + /// + /// Searches for a Tv Show. + /// + /// The search term. + /// We use TvMaze as the Provider + /// + [HttpGet("tv/{searchTerm}/tree")] + public async Task>> SearchTvTreeNode(string searchTerm) + { + return await TvEngine.SearchTreeNode(searchTerm); + } + + /// + /// Gets extra show information. + /// + /// The TVDB identifier. + /// We use TvMaze as the Provider + /// + [HttpGet("tv/info/{tvdbId}/tree")] + public async Task> GetShowInfoTreeNode(int tvdbId) + { + return await TvEngine.GetShowInformationTreeNode(tvdbId); + } + /// /// Gets extra show information. /// @@ -131,7 +155,7 @@ namespace Ombi.Controllers /// We use Trakt.tv as the Provider /// [HttpGet("tv/popular")] - public async Task> PopularTv() + public async Task>> PopularTv() { return await TvEngine.Popular(); } @@ -141,7 +165,7 @@ namespace Ombi.Controllers /// We use Trakt.tv as the Provider /// [HttpGet("tv/anticipated")] - public async Task> AnticiplatedTv() + public async Task>> AnticiplatedTv() { return await TvEngine.Anticipated(); } @@ -151,7 +175,7 @@ namespace Ombi.Controllers /// We use Trakt.tv as the Provider /// [HttpGet("tv/mostwatched")] - public async Task> MostWatched() + public async Task>> MostWatched() { return await TvEngine.MostWatches(); } @@ -161,7 +185,7 @@ namespace Ombi.Controllers /// We use Trakt.tv as the Provider /// [HttpGet("tv/trending")] - public async Task> Trending() + public async Task>> Trending() { return await TvEngine.Trending(); } diff --git a/src/Ombi/Ombi.csproj b/src/Ombi/Ombi.csproj index 1eb73eca6..f606c96dc 100644 --- a/src/Ombi/Ombi.csproj +++ b/src/Ombi/Ombi.csproj @@ -4,7 +4,7 @@ netcoreapp2.0 win10-x64;osx.10.12-x64;ubuntu.16.04-x64;debian.8-x64;centos.7-x64; false - 2.5 + 2.3 $(SemVer) $(SemVer) $(FullVer) diff --git a/src/Ombi/wwwroot/loading.css b/src/Ombi/wwwroot/loading.css index 5acaa528f..a8f5b39d6 100644 --- a/src/Ombi/wwwroot/loading.css +++ b/src/Ombi/wwwroot/loading.css @@ -9,6 +9,7 @@ bottom: 0; left: 0; right: 0; + background-color: #1f1f1f; } .app-loading {