From 86b5455b46f524dc3ab25b1ef498074c5e900c81 Mon Sep 17 00:00:00 2001 From: Jamie Rees Date: Wed, 2 May 2018 14:02:55 +0100 Subject: [PATCH] Fixed the filter on the Requests page #2219 and added the default sort to be most recent requests --- .../Engine/Interfaces/IMovieRequestEngine.cs | 2 +- src/Ombi.Core/Engine/MovieRequestEngine.cs | 20 +++++++++---- src/Ombi.Core/Engine/TvRequestEngine.cs | 4 +-- src/Ombi.Core/Models/Requests/FilterResult.cs | 10 +++++++ .../Models/Requests/FilterViewModel.cs | 2 ++ .../ClientApp/app/interfaces/IRequestModel.ts | 7 +++++ .../app/requests/movierequests.component.ts | 30 ++++++++++++++----- .../ClientApp/app/services/request.service.ts | 6 ++-- src/Ombi/Controllers/RequestController.cs | 2 +- 9 files changed, 64 insertions(+), 19 deletions(-) create mode 100644 src/Ombi.Core/Models/Requests/FilterResult.cs diff --git a/src/Ombi.Core/Engine/Interfaces/IMovieRequestEngine.cs b/src/Ombi.Core/Engine/Interfaces/IMovieRequestEngine.cs index 2f765fede..08ec9b594 100644 --- a/src/Ombi.Core/Engine/Interfaces/IMovieRequestEngine.cs +++ b/src/Ombi.Core/Engine/Interfaces/IMovieRequestEngine.cs @@ -17,7 +17,7 @@ namespace Ombi.Core.Engine.Interfaces Task ApproveMovie(MovieRequests request); Task ApproveMovieById(int requestId); Task DenyMovieById(int modelId); - Task> Filter(FilterViewModel vm); + Task> Filter(FilterViewModel vm); } } \ No newline at end of file diff --git a/src/Ombi.Core/Engine/MovieRequestEngine.cs b/src/Ombi.Core/Engine/MovieRequestEngine.cs index 0e47a28f6..3d88b7230 100644 --- a/src/Ombi.Core/Engine/MovieRequestEngine.cs +++ b/src/Ombi.Core/Engine/MovieRequestEngine.cs @@ -131,11 +131,11 @@ namespace Ombi.Core.Engine List allRequests; if (shouldHide.Hide) { - allRequests = await MovieRepository.GetWithUser(shouldHide.UserId).Skip(position).Take(count).ToListAsync(); + allRequests = await MovieRepository.GetWithUser(shouldHide.UserId).Skip(position).Take(count).OrderByDescending(x => x.ReleaseDate).ToListAsync(); } else { - allRequests = await MovieRepository.GetWithUser().Skip(position).Take(count).ToListAsync(); + allRequests = await MovieRepository.GetWithUser().Skip(position).Take(count).OrderByDescending(x => x.ReleaseDate).ToListAsync(); } allRequests.ForEach(x => { @@ -380,10 +380,13 @@ namespace Ombi.Core.Engine return new RequestEngineResult { Result = true, Message = $"{movieName} has been successfully added!" }; } - public async Task> Filter(FilterViewModel vm) + public async Task> Filter(FilterViewModel vm) { var shouldHide = await HideFromOtherUsers(); - var requests = shouldHide.Hide ? MovieRepository.GetWithUser(shouldHide.UserId) : MovieRepository.GetWithUser(); + var requests = shouldHide.Hide + ? MovieRepository.GetWithUser(shouldHide.UserId) + : MovieRepository.GetWithUser(); + switch (vm.AvailabilityFilter) { case FilterType.None: @@ -415,7 +418,14 @@ namespace Ombi.Core.Engine throw new ArgumentOutOfRangeException(); } - return requests; + var count = await requests.CountAsync(); + requests = requests.Skip(vm.Position).Take(vm.Count); + var retVal = new FilterResult + { + Total = count, + Collection = requests + }; + return retVal; } } } \ No newline at end of file diff --git a/src/Ombi.Core/Engine/TvRequestEngine.cs b/src/Ombi.Core/Engine/TvRequestEngine.cs index c3f1139bf..2ce4da292 100644 --- a/src/Ombi.Core/Engine/TvRequestEngine.cs +++ b/src/Ombi.Core/Engine/TvRequestEngine.cs @@ -141,7 +141,7 @@ namespace Ombi.Core.Engine .Include(x => x.ChildRequests) .ThenInclude(x => x.SeasonRequests) .ThenInclude(x => x.Episodes) - .Skip(position).Take(count).ToListAsync(); + .Skip(position).Take(count).OrderByDescending(x => x.ReleaseDate).ToListAsync(); // Filter out children @@ -153,7 +153,7 @@ namespace Ombi.Core.Engine .Include(x => x.ChildRequests) .ThenInclude(x => x.SeasonRequests) .ThenInclude(x => x.Episodes) - .Skip(position).Take(count).ToListAsync(); + .Skip(position).Take(count).OrderByDescending(x => x.ReleaseDate).ToListAsync(); } return allRequests; diff --git a/src/Ombi.Core/Models/Requests/FilterResult.cs b/src/Ombi.Core/Models/Requests/FilterResult.cs new file mode 100644 index 000000000..467b9731a --- /dev/null +++ b/src/Ombi.Core/Models/Requests/FilterResult.cs @@ -0,0 +1,10 @@ +using System.Collections.Generic; + +namespace Ombi.Core.Models.Requests +{ + public class FilterResult + { + public int Total { get; set; } + public IEnumerable Collection { get; set; } + } +} \ No newline at end of file diff --git a/src/Ombi.Core/Models/Requests/FilterViewModel.cs b/src/Ombi.Core/Models/Requests/FilterViewModel.cs index 27ccc39d6..25a9d5ef1 100644 --- a/src/Ombi.Core/Models/Requests/FilterViewModel.cs +++ b/src/Ombi.Core/Models/Requests/FilterViewModel.cs @@ -4,6 +4,8 @@ { public FilterType AvailabilityFilter { get; set; } public FilterType StatusFilter { get; set; } + public int Position { get; set; } + public int Count { get; set; } } public enum FilterType diff --git a/src/Ombi/ClientApp/app/interfaces/IRequestModel.ts b/src/Ombi/ClientApp/app/interfaces/IRequestModel.ts index 31a98e8e2..e744aea31 100644 --- a/src/Ombi/ClientApp/app/interfaces/IRequestModel.ts +++ b/src/Ombi/ClientApp/app/interfaces/IRequestModel.ts @@ -18,6 +18,11 @@ export interface IMovieRequests extends IFullBaseRequest { qualityOverrideTitle: string; } +export interface IFilterResult { + total: number; + collection: T[]; +} + export interface IMovieUpdateModel { id: number; } @@ -103,6 +108,8 @@ export interface IMovieRequestModel { export interface IFilter { availabilityFilter: FilterType; statusFilter: FilterType; + position: number; + count: number; } export enum FilterType { diff --git a/src/Ombi/ClientApp/app/requests/movierequests.component.ts b/src/Ombi/ClientApp/app/requests/movierequests.component.ts index 3339b6941..eb53af829 100644 --- a/src/Ombi/ClientApp/app/requests/movierequests.component.ts +++ b/src/Ombi/ClientApp/app/requests/movierequests.component.ts @@ -37,7 +37,7 @@ export class MovieRequestsComponent implements OnInit { public filterType = FilterType; public order: string = "requestedDate"; - public reverse = false; + public reverse = true; public totalMovies: number = 100; private currentlyLoaded: number; @@ -72,7 +72,10 @@ export class MovieRequestsComponent implements OnInit { this.isAdmin = this.auth.hasRole("admin") || this.auth.hasRole("poweruser"); this.filter = { availabilityFilter: FilterType.None, - statusFilter: FilterType.None}; + statusFilter: FilterType.None, + count: this.amountToLoad, + position: 0, + }; } public paginate(event: IPagenator) { @@ -174,8 +177,9 @@ export class MovieRequestsComponent implements OnInit { this.filter.availabilityFilter = filter; this.requestService.filterMovies(this.filter) .subscribe(x => { - this.setOverrides(x); - this.movieRequests = x; + this.totalMovies = x.total; + this.setOverrides(x.collection); + this.movieRequests = x.collection; }); } @@ -184,8 +188,9 @@ export class MovieRequestsComponent implements OnInit { this.filter.statusFilter = filter; this.requestService.filterMovies(this.filter) .subscribe(x => { - this.setOverrides(x); - this.movieRequests = x; + this.totalMovies = x.total; + this.setOverrides(x.collection); + this.movieRequests = x.collection; }); } @@ -223,7 +228,8 @@ export class MovieRequestsComponent implements OnInit { } private loadRequests(amountToLoad: number, currentlyLoaded: number) { - this.requestService.getMovieRequests(amountToLoad, currentlyLoaded + 1) + if(this.filter.availabilityFilter === FilterType.None && this.filter.statusFilter === FilterType.None) { + this.requestService.getMovieRequests(amountToLoad, currentlyLoaded + 1) .subscribe(x => { this.setOverrides(x); if(!this.movieRequests) { @@ -232,6 +238,16 @@ export class MovieRequestsComponent implements OnInit { this.movieRequests = x; this.currentlyLoaded = currentlyLoaded + amountToLoad; }); + } else { + this.filter.position = currentlyLoaded; + this.requestService.filterMovies(this.filter) + .subscribe(x => { + this.setOverrides(x.collection); + this.totalMovies = x.total; + this.movieRequests = x.collection; + this.currentlyLoaded = currentlyLoaded + amountToLoad; + }); + } } private updateRequest(request: IMovieRequests) { diff --git a/src/Ombi/ClientApp/app/services/request.service.ts b/src/Ombi/ClientApp/app/services/request.service.ts index c06b39434..acbe319ab 100644 --- a/src/Ombi/ClientApp/app/services/request.service.ts +++ b/src/Ombi/ClientApp/app/services/request.service.ts @@ -6,7 +6,7 @@ import { Observable } from "rxjs/Rx"; import { TreeNode } from "primeng/primeng"; import { IRequestEngineResult } from "../interfaces"; -import { IChildRequests, IFilter, IMovieRequestModel, IMovieRequests, IMovieUpdateModel, ITvRequests, ITvUpdateModel } from "../interfaces"; +import { IChildRequests, IFilter, IFilterResult, IMovieRequestModel, IMovieRequests, IMovieUpdateModel, ITvRequests,ITvUpdateModel } from "../interfaces"; import { ITvRequestViewModel } from "../interfaces"; import { ServiceHelpers } from "./service.helpers"; @@ -114,7 +114,7 @@ export class RequestService extends ServiceHelpers { public deleteChild(child: IChildRequests): Observable { return this.http.delete(`${this.url}tv/child/${child.id}`, {headers: this.headers}); } - public filterMovies(filter: IFilter): Observable { - return this.http.post(`${this.url}movie/filter`, JSON.stringify(filter), {headers: this.headers}); + public filterMovies(filter: IFilter): Observable> { + return this.http.post>(`${this.url}movie/filter`, JSON.stringify(filter), {headers: this.headers}); } } diff --git a/src/Ombi/Controllers/RequestController.cs b/src/Ombi/Controllers/RequestController.cs index 5b83a7981..5f38f3435 100644 --- a/src/Ombi/Controllers/RequestController.cs +++ b/src/Ombi/Controllers/RequestController.cs @@ -352,7 +352,7 @@ namespace Ombi.Controllers /// /// [HttpPost("movie/filter")] - public async Task> Filter([FromBody] FilterViewModel vm) + public async Task> Filter([FromBody] FilterViewModel vm) { return await MovieRequestEngine.Filter(vm); }