mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-21 05:43:19 -07:00
#114 first pass at choosing quality profile when approving + focus search input by default and when switching tabs
This commit is contained in:
parent
96fde83488
commit
9ac949a67c
16 changed files with 325 additions and 77 deletions
|
@ -59,7 +59,7 @@ namespace PlexRequests.UI.Modules
|
|||
SickRageApi = srApi;
|
||||
SickRageSettings = srSettings;
|
||||
|
||||
Post["/approve"] = parameters => Approve((int)Request.Form.requestid);
|
||||
Post["/approve"] = parameters => Approve((int)Request.Form.requestid, (string)Request.Form.qualityId);
|
||||
Post["/approveall"] = x => ApproveAll();
|
||||
Post["/approveallmovies"] = x => ApproveAllMovies();
|
||||
Post["/approvealltvshows"] = x => ApproveAllTVShows();
|
||||
|
@ -80,7 +80,7 @@ namespace PlexRequests.UI.Modules
|
|||
/// </summary>
|
||||
/// <param name="requestId">The request identifier.</param>
|
||||
/// <returns></returns>
|
||||
private Response Approve(int requestId)
|
||||
private Response Approve(int requestId, string qualityId)
|
||||
{
|
||||
Log.Info("approving request {0}", requestId);
|
||||
if (!Context.CurrentUser.IsAuthenticated())
|
||||
|
@ -99,15 +99,15 @@ namespace PlexRequests.UI.Modules
|
|||
switch (request.Type)
|
||||
{
|
||||
case RequestType.Movie:
|
||||
return RequestMovieAndUpdateStatus(request);
|
||||
return RequestMovieAndUpdateStatus(request, qualityId);
|
||||
case RequestType.TvShow:
|
||||
return RequestTvAndUpdateStatus(request);
|
||||
return RequestTvAndUpdateStatus(request, qualityId);
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(request));
|
||||
}
|
||||
}
|
||||
|
||||
private Response RequestTvAndUpdateStatus(RequestedModel request)
|
||||
private Response RequestTvAndUpdateStatus(RequestedModel request, string qualityId)
|
||||
{
|
||||
var sender = new TvSender(SonarrApi, SickRageApi);
|
||||
|
||||
|
@ -115,7 +115,7 @@ namespace PlexRequests.UI.Modules
|
|||
if (sonarrSettings.Enabled)
|
||||
{
|
||||
Log.Trace("Sending to Sonarr");
|
||||
var result = sender.SendToSonarr(sonarrSettings, request);
|
||||
var result = sender.SendToSonarr(sonarrSettings, request, qualityId);
|
||||
Log.Trace("Sonarr Result: ");
|
||||
Log.Trace(result.DumpJson());
|
||||
if (!string.IsNullOrEmpty(result.title))
|
||||
|
@ -141,7 +141,7 @@ namespace PlexRequests.UI.Modules
|
|||
if (srSettings.Enabled)
|
||||
{
|
||||
Log.Trace("Sending to SickRage");
|
||||
var result = sender.SendToSickRage(srSettings, request);
|
||||
var result = sender.SendToSickRage(srSettings, request, qualityId);
|
||||
Log.Trace("SickRage Result: ");
|
||||
Log.Trace(result.DumpJson());
|
||||
if (result?.result == "success")
|
||||
|
@ -169,7 +169,7 @@ namespace PlexRequests.UI.Modules
|
|||
});
|
||||
}
|
||||
|
||||
private Response RequestMovieAndUpdateStatus(RequestedModel request)
|
||||
private Response RequestMovieAndUpdateStatus(RequestedModel request, string qualityId)
|
||||
{
|
||||
var cpSettings = CpService.GetSettings();
|
||||
var cp = new CouchPotatoApi();
|
||||
|
@ -190,7 +190,8 @@ namespace PlexRequests.UI.Modules
|
|||
Message = "We could not approve this request. Please try again or check the logs."
|
||||
});
|
||||
}
|
||||
var result = cp.AddMovie(request.ImdbId, cpSettings.ApiKey, request.Title, cpSettings.FullUri, cpSettings.ProfileId);
|
||||
|
||||
var result = cp.AddMovie(request.ImdbId, cpSettings.ApiKey, request.Title, cpSettings.FullUri, string.IsNullOrEmpty(qualityId) ? cpSettings.ProfileId : qualityId);
|
||||
Log.Trace("Adding movie to CP result {0}", result);
|
||||
if (result)
|
||||
{
|
||||
|
|
|
@ -41,17 +41,36 @@ using PlexRequests.Services.Notification;
|
|||
using PlexRequests.Store;
|
||||
using PlexRequests.UI.Models;
|
||||
using PlexRequests.Helpers;
|
||||
using System.Collections.Generic;
|
||||
using PlexRequests.Api.Interfaces;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PlexRequests.UI.Modules
|
||||
{
|
||||
public class RequestsModule : BaseModule
|
||||
{
|
||||
public RequestsModule(IRequestService service, ISettingsService<PlexRequestSettings> prSettings, ISettingsService<PlexSettings> plex, INotificationService notify) : base("requests")
|
||||
public RequestsModule(
|
||||
IRequestService service,
|
||||
ISettingsService<PlexRequestSettings> prSettings,
|
||||
ISettingsService<PlexSettings> plex,
|
||||
INotificationService notify,
|
||||
ISettingsService<SonarrSettings> sonarrSettings,
|
||||
ISettingsService<SickRageSettings> sickRageSettings,
|
||||
ISettingsService<CouchPotatoSettings> cpSettings,
|
||||
ICouchPotatoApi cpApi,
|
||||
ISonarrApi sonarrApi,
|
||||
ISickRageApi sickRageApi) : base("requests")
|
||||
{
|
||||
Service = service;
|
||||
PrSettings = prSettings;
|
||||
PlexSettings = plex;
|
||||
NotificationService = notify;
|
||||
SonarrSettings = sonarrSettings;
|
||||
SickRageSettings = sickRageSettings;
|
||||
CpSettings = cpSettings;
|
||||
SonarrApi = sonarrApi;
|
||||
SickRageApi = sickRageApi;
|
||||
CpApi = cpApi;
|
||||
|
||||
Get["/"] = _ => LoadRequests();
|
||||
Get["/movies"] = _ => GetMovies();
|
||||
|
@ -71,6 +90,12 @@ namespace PlexRequests.UI.Modules
|
|||
private INotificationService NotificationService { get; }
|
||||
private ISettingsService<PlexRequestSettings> PrSettings { get; }
|
||||
private ISettingsService<PlexSettings> PlexSettings { get; }
|
||||
private ISettingsService<SonarrSettings> SonarrSettings { get; }
|
||||
private ISettingsService<SickRageSettings> SickRageSettings { get; }
|
||||
private ISettingsService<CouchPotatoSettings> CpSettings { get; }
|
||||
private ISonarrApi SonarrApi { get; }
|
||||
private ISickRageApi SickRageApi { get; }
|
||||
private ICouchPotatoApi CpApi { get; }
|
||||
|
||||
private Negotiator LoadRequests()
|
||||
{
|
||||
|
@ -78,17 +103,51 @@ namespace PlexRequests.UI.Modules
|
|||
return View["Index", settings];
|
||||
}
|
||||
|
||||
private Response GetMovies()
|
||||
private Response GetMovies() // TODO: async await the API calls
|
||||
{
|
||||
var settings = PrSettings.GetSettings();
|
||||
var isAdmin = Context.CurrentUser.IsAuthenticated();
|
||||
var dbMovies = Service.GetAll().Where(x => x.Type == RequestType.Movie);
|
||||
if (settings.UsersCanViewOnlyOwnRequests && !isAdmin)
|
||||
|
||||
List<Task> taskList = new List<Task>();
|
||||
|
||||
List<RequestedModel> dbMovies = new List<RequestedModel>();
|
||||
taskList.Add(Task.Factory.StartNew(() =>
|
||||
{
|
||||
dbMovies = dbMovies.Where(x => x.UserHasRequested(Username));
|
||||
return Service.GetAll().Where(x => x.Type == RequestType.Movie);
|
||||
|
||||
}).ContinueWith((t) =>
|
||||
{
|
||||
dbMovies = t.Result.ToList();
|
||||
|
||||
if (settings.UsersCanViewOnlyOwnRequests && !isAdmin)
|
||||
{
|
||||
dbMovies = dbMovies.Where(x => x.UserHasRequested(Username)).ToList();
|
||||
}
|
||||
}));
|
||||
|
||||
|
||||
|
||||
List<QualityModel> qualities = new List<QualityModel>();
|
||||
|
||||
if (isAdmin)
|
||||
{
|
||||
var cpSettings = CpSettings.GetSettings();
|
||||
if (cpSettings.Enabled)
|
||||
{
|
||||
taskList.Add(Task.Factory.StartNew(() =>
|
||||
{
|
||||
return CpApi.GetProfiles(cpSettings.FullUri, cpSettings.ApiKey).list.Select(x => new QualityModel() { Id = x._id, Name = x.label }); // TODO: cache this!
|
||||
}).ContinueWith((t) =>
|
||||
{
|
||||
qualities = t.Result.ToList();
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
var viewModel = dbMovies.Select(movie => {
|
||||
Task.WaitAll(taskList.ToArray());
|
||||
|
||||
var viewModel = dbMovies.Select(movie =>
|
||||
{
|
||||
return new RequestViewModel
|
||||
{
|
||||
ProviderId = movie.ProviderId,
|
||||
|
@ -111,23 +170,69 @@ namespace PlexRequests.UI.Modules
|
|||
Issues = movie.Issues.Humanize(LetterCasing.Title),
|
||||
OtherMessage = movie.OtherMessage,
|
||||
AdminNotes = movie.AdminNote,
|
||||
Qualities = qualities.ToArray()
|
||||
};
|
||||
}).ToList();
|
||||
|
||||
return Response.AsJson(viewModel);
|
||||
}
|
||||
|
||||
private Response GetTvShows()
|
||||
private Response GetTvShows() // TODO: async await the API calls
|
||||
{
|
||||
var settings = PrSettings.GetSettings();
|
||||
var isAdmin = Context.CurrentUser.IsAuthenticated();
|
||||
var dbTv = Service.GetAll().Where(x => x.Type == RequestType.TvShow);
|
||||
if (settings.UsersCanViewOnlyOwnRequests && !isAdmin)
|
||||
|
||||
List<Task> taskList = new List<Task>();
|
||||
|
||||
List<RequestedModel> dbTv = new List<RequestedModel>();
|
||||
taskList.Add(Task.Factory.StartNew(() =>
|
||||
{
|
||||
dbTv = dbTv.Where(x => x.UserHasRequested(Username));
|
||||
return Service.GetAll().Where(x => x.Type == RequestType.TvShow);
|
||||
|
||||
}).ContinueWith((t) =>
|
||||
{
|
||||
dbTv = t.Result.ToList();
|
||||
|
||||
if (settings.UsersCanViewOnlyOwnRequests && !isAdmin)
|
||||
{
|
||||
dbTv = dbTv.Where(x => x.UserHasRequested(Username)).ToList();
|
||||
}
|
||||
}));
|
||||
|
||||
List<QualityModel> qualities = new List<QualityModel>();
|
||||
if (isAdmin)
|
||||
{
|
||||
var sonarrSettings = SonarrSettings.GetSettings();
|
||||
if (sonarrSettings.Enabled)
|
||||
{
|
||||
taskList.Add(Task.Factory.StartNew(() =>
|
||||
{
|
||||
return SonarrApi.GetProfiles(sonarrSettings.ApiKey, sonarrSettings.FullUri).Select(x => new QualityModel() { Id = x.id.ToString(), Name = x.name }); // TODO: cache this!
|
||||
}).ContinueWith((t) =>
|
||||
{
|
||||
qualities = t.Result.ToList();
|
||||
}));
|
||||
}
|
||||
else {
|
||||
var sickRageSettings = SickRageSettings.GetSettings();
|
||||
if (sickRageSettings.Enabled)
|
||||
{
|
||||
taskList.Add(Task.Factory.StartNew(() =>
|
||||
{
|
||||
return sickRageSettings.Qualities.Select(x => new QualityModel() { Id = x.Key, Name = x.Value }); // TODO: cache this!
|
||||
}).ContinueWith((t) =>
|
||||
{
|
||||
qualities = t.Result.ToList();
|
||||
}));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
var viewModel = dbTv.Select(tv => {
|
||||
Task.WaitAll(taskList.ToArray());
|
||||
|
||||
var viewModel = dbTv.Select(tv =>
|
||||
{
|
||||
return new RequestViewModel
|
||||
{
|
||||
ProviderId = tv.ProviderId,
|
||||
|
@ -150,7 +255,8 @@ namespace PlexRequests.UI.Modules
|
|||
Issues = tv.Issues.Humanize(LetterCasing.Title),
|
||||
OtherMessage = tv.OtherMessage,
|
||||
AdminNotes = tv.AdminNote,
|
||||
TvSeriesRequestType = tv.SeasonsRequested
|
||||
TvSeriesRequestType = tv.SeasonsRequested,
|
||||
Qualities = qualities.ToArray()
|
||||
};
|
||||
}).ToList();
|
||||
|
||||
|
@ -167,7 +273,8 @@ namespace PlexRequests.UI.Modules
|
|||
dbAlbum = dbAlbum.Where(x => x.UserHasRequested(Username));
|
||||
}
|
||||
|
||||
var viewModel = dbAlbum.Select(album => {
|
||||
var viewModel = dbAlbum.Select(album =>
|
||||
{
|
||||
return new RequestViewModel
|
||||
{
|
||||
ProviderId = album.ProviderId,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue