mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-10 07:22:35 -07:00
Started some dynamic scrolling.
This commit is contained in:
parent
a728becc32
commit
e9d74a3d76
2 changed files with 160 additions and 66 deletions
|
@ -514,8 +514,10 @@ function mixItUpConfig(activeState) {
|
|||
return conf;
|
||||
};
|
||||
|
||||
var position = 0;
|
||||
function initLoad() {
|
||||
movieLoad();
|
||||
//movieLoad();
|
||||
movieLoadWithPosition(0);
|
||||
tvLoad();
|
||||
albumLoad();
|
||||
}
|
||||
|
@ -544,6 +546,52 @@ function movieLoad() {
|
|||
});
|
||||
};
|
||||
|
||||
function movieLoadWithPosition(pos) {
|
||||
var $ml = $('#movieList');
|
||||
if ($ml.mixItUp('isLoaded')) {
|
||||
activeState = $ml.mixItUp('getState');
|
||||
$ml.mixItUp('destroy');
|
||||
}
|
||||
|
||||
var url = createBaseUrl(base, '/requests/movies/'+pos);
|
||||
$.ajax(url).success(function (results) {
|
||||
if (results.length > 0) {
|
||||
position++;
|
||||
results.forEach(function (result) {
|
||||
var context = buildRequestContext(result, "movie");
|
||||
var html = searchTemplate(context);
|
||||
$ml.append(html);
|
||||
});
|
||||
}
|
||||
else {
|
||||
$ml.append(noResultsHtml.format("movie"));
|
||||
}
|
||||
$ml.mixItUp(mixItUpConfig());
|
||||
});
|
||||
};
|
||||
|
||||
var win = $(window);
|
||||
|
||||
$(win).scroll(function () {
|
||||
if ($(win).scrollTop() + $(win).height() >= $(document).height() - 100) {
|
||||
// Debounce the scroll event
|
||||
if (this.timeoutId)
|
||||
win.clearTimeout(this.timeoutId);
|
||||
this.timeoutId = win.setTimeout(function () {
|
||||
movieLoadWithPosition(position);
|
||||
}, 200);
|
||||
}
|
||||
});
|
||||
//// Each time the user scrolls
|
||||
//win.scroll(function () {
|
||||
// // End of the document reached?
|
||||
// if ($(document).height() - win.height() == win.scrollTop()) {
|
||||
// $('#loading').show();
|
||||
|
||||
// movieLoadWithPosition(position);
|
||||
// }
|
||||
//});
|
||||
|
||||
function tvLoad() {
|
||||
var $tvl = $('#tvList');
|
||||
if ($tvl.mixItUp('isLoaded')) {
|
||||
|
|
|
@ -74,7 +74,8 @@ namespace PlexRequests.UI.Modules
|
|||
Cache = cache;
|
||||
|
||||
Get["/"] = _ => LoadRequests();
|
||||
Get["/movies"] = _ => GetMovies();
|
||||
Get["/movies", true] = async (x, ct) => await GetMovies();
|
||||
Get["/movies/{position}", true] = async (x, ct) => await GetMovies(x.position);
|
||||
Get["/tvshows"] = _ => GetTvShows();
|
||||
Get["/albums"] = _ => GetAlbumRequests();
|
||||
Post["/delete"] = _ => DeleteRequest((int)Request.Form.id);
|
||||
|
@ -105,27 +106,19 @@ namespace PlexRequests.UI.Modules
|
|||
return View["Index", settings];
|
||||
}
|
||||
|
||||
private Response GetMovies() // TODO: async await the API calls
|
||||
private async Task<Response> GetMovies()
|
||||
{
|
||||
var settings = PrSettings.GetSettings();
|
||||
|
||||
List<Task> taskList = new List<Task>();
|
||||
var allRequests = await Service.GetAllAsync();
|
||||
allRequests = allRequests.Where(x => x.Type == RequestType.Movie);
|
||||
|
||||
List<RequestedModel> dbMovies = new List<RequestedModel>();
|
||||
taskList.Add(Task.Factory.StartNew(() =>
|
||||
{
|
||||
return Service.GetAll().Where(x => x.Type == RequestType.Movie);
|
||||
|
||||
}).ContinueWith((t) =>
|
||||
{
|
||||
dbMovies = t.Result.ToList();
|
||||
var dbMovies = allRequests.ToList();
|
||||
|
||||
if (settings.UsersCanViewOnlyOwnRequests && !IsAdmin)
|
||||
{
|
||||
dbMovies = dbMovies.Where(x => x.UserHasRequested(Username)).ToList();
|
||||
}
|
||||
}));
|
||||
|
||||
|
||||
List<QualityModel> qualities = new List<QualityModel>();
|
||||
|
||||
|
@ -134,24 +127,17 @@ namespace PlexRequests.UI.Modules
|
|||
var cpSettings = CpSettings.GetSettings();
|
||||
if (cpSettings.Enabled)
|
||||
{
|
||||
taskList.Add(Task.Factory.StartNew(() =>
|
||||
|
||||
var result = await Cache.GetOrSetAsync(CacheKeys.CouchPotatoQualityProfiles, async () =>
|
||||
{
|
||||
return Cache.GetOrSet(CacheKeys.CouchPotatoQualityProfiles, () =>
|
||||
{
|
||||
return CpApi.GetProfiles(cpSettings.FullUri, cpSettings.ApiKey); // TODO: cache this!
|
||||
return await Task.Run(() => CpApi.GetProfiles(cpSettings.FullUri, cpSettings.ApiKey)).ConfigureAwait(false);
|
||||
});
|
||||
}).ContinueWith((t) =>
|
||||
{
|
||||
qualities = t.Result.list.Select(x => new QualityModel() { Id = x._id, Name = x.label }).ToList();
|
||||
}));
|
||||
|
||||
qualities = result.list.Select(x => new QualityModel() { Id = x._id, Name = x.label }).ToList();
|
||||
}
|
||||
}
|
||||
|
||||
Task.WaitAll(taskList.ToArray());
|
||||
|
||||
var viewModel = dbMovies.Select(movie =>
|
||||
{
|
||||
return new RequestViewModel
|
||||
var viewModel = dbMovies.Select(movie => new RequestViewModel
|
||||
{
|
||||
ProviderId = movie.ProviderId,
|
||||
Type = movie.Type,
|
||||
|
@ -175,7 +161,6 @@ namespace PlexRequests.UI.Modules
|
|||
OtherMessage = movie.OtherMessage,
|
||||
AdminNotes = movie.AdminNote,
|
||||
Qualities = qualities.ToArray()
|
||||
};
|
||||
}).ToList();
|
||||
|
||||
return Response.AsJson(viewModel);
|
||||
|
@ -220,7 +205,8 @@ namespace PlexRequests.UI.Modules
|
|||
qualities = t.Result.Select(x => new QualityModel() { Id = x.id.ToString(), Name = x.name }).ToList();
|
||||
}));
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
var sickRageSettings = SickRageSettings.GetSettings();
|
||||
if (sickRageSettings.Enabled)
|
||||
{
|
||||
|
@ -406,5 +392,65 @@ namespace PlexRequests.UI.Modules
|
|||
? new JsonResponseModel { Result = true }
|
||||
: new JsonResponseModel { Result = false, Message = "Could not update the notes, please try again or check the logs" });
|
||||
}
|
||||
|
||||
private async Task<Response> GetMovies(int position)
|
||||
{
|
||||
var settings = PrSettings.GetSettings();
|
||||
|
||||
var allRequests = await Service.GetAllAsync();
|
||||
allRequests = allRequests.Where(x => x.Type == RequestType.Movie).OrderByDescending(x => x.RequestedDate).Skip(position == 0 ? 0 : position * 3).Take(3);
|
||||
|
||||
var dbMovies = allRequests.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)
|
||||
{
|
||||
|
||||
var result = await Cache.GetOrSetAsync(CacheKeys.CouchPotatoQualityProfiles, async () =>
|
||||
{
|
||||
return await Task.Run(() => CpApi.GetProfiles(cpSettings.FullUri, cpSettings.ApiKey)).ConfigureAwait(false);
|
||||
});
|
||||
|
||||
qualities = result.list.Select(x => new QualityModel() { Id = x._id, Name = x.label }).ToList();
|
||||
}
|
||||
}
|
||||
|
||||
var viewModel = dbMovies.Select(movie => new RequestViewModel
|
||||
{
|
||||
ProviderId = movie.ProviderId,
|
||||
Type = movie.Type,
|
||||
Status = movie.Status,
|
||||
ImdbId = movie.ImdbId,
|
||||
Id = movie.Id,
|
||||
PosterPath = movie.PosterPath,
|
||||
ReleaseDate = movie.ReleaseDate,
|
||||
ReleaseDateTicks = movie.ReleaseDate.Ticks,
|
||||
RequestedDate = movie.RequestedDate,
|
||||
Released = DateTime.Now > movie.ReleaseDate,
|
||||
RequestedDateTicks = DateTimeHelper.OffsetUTCDateTime(movie.RequestedDate, DateTimeOffset).Ticks,
|
||||
Approved = movie.Available || movie.Approved,
|
||||
Title = movie.Title,
|
||||
Overview = movie.Overview,
|
||||
RequestedUsers = IsAdmin ? movie.AllUsers.ToArray() : new string[] { },
|
||||
ReleaseYear = movie.ReleaseDate.Year.ToString(),
|
||||
Available = movie.Available,
|
||||
Admin = IsAdmin,
|
||||
Issues = movie.Issues.ToString().CamelCaseToWords(),
|
||||
OtherMessage = movie.OtherMessage,
|
||||
AdminNotes = movie.AdminNote,
|
||||
Qualities = qualities.ToArray()
|
||||
}).ToList();
|
||||
|
||||
return Response.AsJson(viewModel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue