Started some dynamic scrolling.

pull/284/head
tidusjar 9 years ago
parent a728becc32
commit e9d74a3d76

@ -514,8 +514,10 @@ function mixItUpConfig(activeState) {
return conf; return conf;
}; };
var position = 0;
function initLoad() { function initLoad() {
movieLoad(); //movieLoad();
movieLoadWithPosition(0);
tvLoad(); tvLoad();
albumLoad(); 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() { function tvLoad() {
var $tvl = $('#tvList'); var $tvl = $('#tvList');
if ($tvl.mixItUp('isLoaded')) { if ($tvl.mixItUp('isLoaded')) {

@ -74,7 +74,8 @@ namespace PlexRequests.UI.Modules
Cache = cache; Cache = cache;
Get["/"] = _ => LoadRequests(); 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["/tvshows"] = _ => GetTvShows();
Get["/albums"] = _ => GetAlbumRequests(); Get["/albums"] = _ => GetAlbumRequests();
Post["/delete"] = _ => DeleteRequest((int)Request.Form.id); Post["/delete"] = _ => DeleteRequest((int)Request.Form.id);
@ -105,27 +106,19 @@ namespace PlexRequests.UI.Modules
return View["Index", settings]; return View["Index", settings];
} }
private Response GetMovies() // TODO: async await the API calls private async Task<Response> GetMovies()
{ {
var settings = PrSettings.GetSettings(); 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>(); var dbMovies = allRequests.ToList();
taskList.Add(Task.Factory.StartNew(() =>
{
return Service.GetAll().Where(x => x.Type == RequestType.Movie);
}).ContinueWith((t) =>
{
dbMovies = t.Result.ToList();
if (settings.UsersCanViewOnlyOwnRequests && !IsAdmin) if (settings.UsersCanViewOnlyOwnRequests && !IsAdmin)
{ {
dbMovies = dbMovies.Where(x => x.UserHasRequested(Username)).ToList(); dbMovies = dbMovies.Where(x => x.UserHasRequested(Username)).ToList();
} }
}));
List<QualityModel> qualities = new List<QualityModel>(); List<QualityModel> qualities = new List<QualityModel>();
@ -134,24 +127,17 @@ namespace PlexRequests.UI.Modules
var cpSettings = CpSettings.GetSettings(); var cpSettings = CpSettings.GetSettings();
if (cpSettings.Enabled) 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 = result.list.Select(x => new QualityModel() { Id = x._id, Name = x.label }).ToList();
qualities = t.Result.list.Select(x => new QualityModel() { Id = x._id, Name = x.label }).ToList();
}));
} }
} }
Task.WaitAll(taskList.ToArray()); var viewModel = dbMovies.Select(movie => new RequestViewModel
var viewModel = dbMovies.Select(movie =>
{
return new RequestViewModel
{ {
ProviderId = movie.ProviderId, ProviderId = movie.ProviderId,
Type = movie.Type, Type = movie.Type,
@ -175,7 +161,6 @@ namespace PlexRequests.UI.Modules
OtherMessage = movie.OtherMessage, OtherMessage = movie.OtherMessage,
AdminNotes = movie.AdminNote, AdminNotes = movie.AdminNote,
Qualities = qualities.ToArray() Qualities = qualities.ToArray()
};
}).ToList(); }).ToList();
return Response.AsJson(viewModel); 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(); qualities = t.Result.Select(x => new QualityModel() { Id = x.id.ToString(), Name = x.name }).ToList();
})); }));
} }
else { else
{
var sickRageSettings = SickRageSettings.GetSettings(); var sickRageSettings = SickRageSettings.GetSettings();
if (sickRageSettings.Enabled) if (sickRageSettings.Enabled)
{ {
@ -310,7 +296,7 @@ namespace PlexRequests.UI.Modules
private Response DeleteRequest(int requestid) private Response DeleteRequest(int requestid)
{ {
this.RequiresClaims (UserClaims.Admin); this.RequiresClaims(UserClaims.Admin);
var currentEntity = Service.Get(requestid); var currentEntity = Service.Get(requestid);
Service.DeleteRequest(currentEntity); Service.DeleteRequest(currentEntity);
@ -357,7 +343,7 @@ namespace PlexRequests.UI.Modules
private Response ClearIssue(int requestId) private Response ClearIssue(int requestId)
{ {
this.RequiresClaims ( UserClaims.Admin); this.RequiresClaims(UserClaims.Admin);
var originalRequest = Service.Get(requestId); var originalRequest = Service.Get(requestId);
if (originalRequest == null) if (originalRequest == null)
@ -375,7 +361,7 @@ namespace PlexRequests.UI.Modules
private Response ChangeRequestAvailability(int requestId, bool available) private Response ChangeRequestAvailability(int requestId, bool available)
{ {
this.RequiresClaims (UserClaims.Admin); this.RequiresClaims(UserClaims.Admin);
var originalRequest = Service.Get(requestId); var originalRequest = Service.Get(requestId);
if (originalRequest == null) if (originalRequest == null)
{ {
@ -392,7 +378,7 @@ namespace PlexRequests.UI.Modules
private Response AddNote(int requestId, string noteArea) private Response AddNote(int requestId, string noteArea)
{ {
this.RequiresClaims (UserClaims.Admin); this.RequiresClaims(UserClaims.Admin);
var originalRequest = Service.Get(requestId); var originalRequest = Service.Get(requestId);
if (originalRequest == null) if (originalRequest == null)
{ {
@ -406,5 +392,65 @@ namespace PlexRequests.UI.Modules
? new JsonResponseModel { Result = true } ? new JsonResponseModel { Result = true }
: new JsonResponseModel { Result = false, Message = "Could not update the notes, please try again or check the logs" }); : 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…
Cancel
Save