From a82b011ae340907be6470648f9342930711caa48 Mon Sep 17 00:00:00 2001 From: Jamie Rees Date: Wed, 30 May 2018 14:25:17 +0100 Subject: [PATCH] Added the subscribe button to the search page if we have an existing request. --- src/Ombi.Core/Engine/MovieSearchEngine.cs | 24 ++++++++++++++++++- .../Models/Search/SearchTvShowViewModel.cs | 1 - .../Models/Search/SearchViewModel.cs | 8 ++++++- .../Rule/Rules/Search/ExistingRule.cs | 3 ++- .../app/interfaces/ISearchMovieResult.ts | 3 +++ .../app/search/moviesearch.component.html | 8 ++++++- .../app/search/moviesearch.component.ts | 16 +++++++++++++ .../ClientApp/app/search/search.module.ts | 3 ++- 8 files changed, 60 insertions(+), 6 deletions(-) diff --git a/src/Ombi.Core/Engine/MovieSearchEngine.cs b/src/Ombi.Core/Engine/MovieSearchEngine.cs index 915eefe02..39fd88f5a 100644 --- a/src/Ombi.Core/Engine/MovieSearchEngine.cs +++ b/src/Ombi.Core/Engine/MovieSearchEngine.cs @@ -9,6 +9,7 @@ using System.Collections.Generic; using System.Linq; using System.Security.Principal; using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore; using Ombi.Core.Rule.Interfaces; using Microsoft.Extensions.Caching.Memory; using Ombi.Core.Authentication; @@ -166,10 +167,31 @@ namespace Ombi.Core.Engine viewMovie.TheMovieDbId = viewMovie.Id.ToString(); await RunSearchRules(viewMovie); - + + // This requires the rules to be run first to populate the RequestId property + await CheckForSubscription(viewMovie); + return viewMovie; } + private async Task CheckForSubscription(SearchMovieViewModel viewModel) + { + // Check if this user requested it + var user = await GetUser(); + var request = await RequestService.MovieRequestService.GetAll() + .AnyAsync(x => x.RequestedUserId.Equals(user.Id) && x.Id == viewModel.Id); + if (request) + { + viewModel.ShowSubscribe = false; + } + else + { + viewModel.ShowSubscribe = true; + var sub = await _subscriptionRepository.GetAll().FirstOrDefaultAsync(s => s.UserId == user.Id + && s.RequestId == viewModel.RequestId && s.RequestType == RequestType.Movie); + viewModel.Subscribed = sub != null; + } + } private async Task ProcessSingleMovie(MovieSearchResult movie) { diff --git a/src/Ombi.Core/Models/Search/SearchTvShowViewModel.cs b/src/Ombi.Core/Models/Search/SearchTvShowViewModel.cs index a91d75d65..c421af45f 100644 --- a/src/Ombi.Core/Models/Search/SearchTvShowViewModel.cs +++ b/src/Ombi.Core/Models/Search/SearchTvShowViewModel.cs @@ -56,7 +56,6 @@ namespace Ombi.Core.Models.Search public bool FullyAvailable { get; set; } // We only have some episodes public bool PartlyAvailable { get; set; } - public override RequestType Type => RequestType.TvShow; } } \ No newline at end of file diff --git a/src/Ombi.Core/Models/Search/SearchViewModel.cs b/src/Ombi.Core/Models/Search/SearchViewModel.cs index 0de295a69..a388ccfff 100644 --- a/src/Ombi.Core/Models/Search/SearchViewModel.cs +++ b/src/Ombi.Core/Models/Search/SearchViewModel.cs @@ -8,13 +8,13 @@ namespace Ombi.Core.Models.Search public int Id { get; set; } public bool Approved { get; set; } public bool Requested { get; set; } + public int RequestId { get; set; } public bool Available { get; set; } public string PlexUrl { get; set; } public string EmbyUrl { get; set; } public string Quality { get; set; } public abstract RequestType Type { get; } - /// /// This is used for the PlexAvailabilityCheck/EmbyAvailabilityRule rule /// @@ -27,5 +27,11 @@ namespace Ombi.Core.Models.Search public string TheTvDbId { get; set; } [NotMapped] public string TheMovieDbId { get; set; } + + + [NotMapped] + public bool Subscribed { get; set; } + [NotMapped] + public bool ShowSubscribe { get; set; } } } \ No newline at end of file diff --git a/src/Ombi.Core/Rule/Rules/Search/ExistingRule.cs b/src/Ombi.Core/Rule/Rules/Search/ExistingRule.cs index 2118e2a96..6ca0b966b 100644 --- a/src/Ombi.Core/Rule/Rules/Search/ExistingRule.cs +++ b/src/Ombi.Core/Rule/Rules/Search/ExistingRule.cs @@ -29,6 +29,7 @@ namespace Ombi.Core.Rule.Rules.Search { obj.Requested = true; + obj.RequestId = movieRequests.Id; obj.Approved = movieRequests.Approved; obj.Available = movieRequests.Available; @@ -67,6 +68,7 @@ namespace Ombi.Core.Rule.Rules.Search existingRequestChildRequest.SeasonRequests.FirstOrDefault(x => x.SeasonNumber == season.SeasonNumber); if (existingSeason == null) continue; + foreach (var ep in existingSeason.Episodes) { // Find the episode from what we are searching @@ -92,7 +94,6 @@ namespace Ombi.Core.Rule.Rules.Search request.PartlyAvailable = true; } - return Task.FromResult(Success()); } } diff --git a/src/Ombi/ClientApp/app/interfaces/ISearchMovieResult.ts b/src/Ombi/ClientApp/app/interfaces/ISearchMovieResult.ts index ee66598fd..3ea282351 100644 --- a/src/Ombi/ClientApp/app/interfaces/ISearchMovieResult.ts +++ b/src/Ombi/ClientApp/app/interfaces/ISearchMovieResult.ts @@ -19,11 +19,14 @@ imdbId: string; approved: boolean; requested: boolean; + requestId: number; available: boolean; plexUrl: string; embyUrl: string; quality: string; digitalReleaseDate: Date; + subscribed: boolean; + showSubscribe: boolean; // for the UI requestProcessing: boolean; diff --git a/src/Ombi/ClientApp/app/search/moviesearch.component.html b/src/Ombi/ClientApp/app/search/moviesearch.component.html index a2b59df79..44dc345bc 100644 --- a/src/Ombi/ClientApp/app/search/moviesearch.component.html +++ b/src/Ombi/ClientApp/app/search/moviesearch.component.html @@ -65,7 +65,13 @@
- +
+
+ + + +
+
diff --git a/src/Ombi/ClientApp/app/search/moviesearch.component.ts b/src/Ombi/ClientApp/app/search/moviesearch.component.ts index c8c7514a7..a89a11b84 100644 --- a/src/Ombi/ClientApp/app/search/moviesearch.component.ts +++ b/src/Ombi/ClientApp/app/search/moviesearch.component.ts @@ -162,6 +162,22 @@ export class MovieSearchComponent implements OnInit { this.getExtraInfo(); }); } + + public subscribe(r: ISearchMovieResult) { + r.subscribed = true; + this.requestService.subscribeToMovie(r.requestId) + .subscribe(x => { + this.notificationService.success("Subscribed To Movie!"); + }); + } + + public unSubscribe(r: ISearchMovieResult) { + r.subscribed = false; + this.requestService.unSubscribeToMovie(r.requestId) + .subscribe(x => { + this.notificationService.success("Unsubscribed Movie!"); + }); + } private getExtraInfo() { diff --git a/src/Ombi/ClientApp/app/search/search.module.ts b/src/Ombi/ClientApp/app/search/search.module.ts index 1b7f1310f..d5b8669ef 100644 --- a/src/Ombi/ClientApp/app/search/search.module.ts +++ b/src/Ombi/ClientApp/app/search/search.module.ts @@ -11,7 +11,7 @@ import { SearchComponent } from "./search.component"; import { SeriesInformationComponent } from "./seriesinformation.component"; import { TvSearchComponent } from "./tvsearch.component"; -import { SidebarModule, TreeTableModule } from "primeng/primeng"; +import { SidebarModule, TooltipModule, TreeTableModule } from "primeng/primeng"; import { RequestService } from "../services"; import { SearchService } from "../services"; @@ -33,6 +33,7 @@ const routes: Routes = [ TreeTableModule, SharedModule, SidebarModule, + TooltipModule, ], declarations: [ SearchComponent,