Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop pagination and adding a library from being able to trigger multiple times #27

Merged
merged 5 commits into from
Jan 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 74 additions & 34 deletions src/components/medialibrarycreator/medialibrarycreator.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,48 @@ define(["loading", "dialogHelper", "dom", "jQuery", "components/libraryoptionsed
"use strict";

function onSubmit(e) {
if (e.preventDefault(), e.stopPropagation(), 0 == pathInfos.length) return require(["alert"], function(alert) {
alert({
text: Globalize.translate("PleaseAddAtLeastOneFolder"),
type: "error"
})
}), !1;
var form = this,
dlg = $(form).parents(".dialog")[0],
name = $("#txtValue", form).val(),
type = $("#selectCollectionType", form).val();
"mixed" == type && (type = null);
var libraryOptions = libraryoptionseditor.getLibraryOptions(dlg.querySelector(".libraryOptions"));
return libraryOptions.PathInfos = pathInfos, ApiClient.addVirtualFolder(name, type, currentOptions.refresh, libraryOptions).then(function() {
hasChanges = !0, dialogHelper.close(dlg)
}, function() {
require(["toast"], function(toast) {
toast(Globalize.translate("ErrorAddingMediaPathToVirtualFolder"))
})
}), !1
e.preventDefault();
e.stopPropagation();

if (isCreating) return false;

if (pathInfos.length == 0) {
require(["alert"], function(alert) {
alert({
text: Globalize.translate("PleaseAddAtLeastOneFolder"),
type: "error"
})
});
} else {
isCreating = true;
loading.show();

var form = this,
dlg = $(form).parents(".dialog")[0],
name = $("#txtValue", form).val(),
type = $("#selectCollectionType", form).val();
if (type == "mixed") type = null;
var libraryOptions = libraryoptionseditor.getLibraryOptions(dlg.querySelector(".libraryOptions"));
libraryOptions.PathInfos = pathInfos;
ApiClient.addVirtualFolder(name, type, currentOptions.refresh, libraryOptions).then(function() {
hasChanges = true;
isCreating = false;
loading.hide();
dialogHelper.close(dlg);
}, function() {
require(["toast"], function(toast) {
toast(Globalize.translate("ErrorAddingMediaPathToVirtualFolder"))
})
isCreating = false;
loading.hide();
});
}
return false;
}

function getCollectionTypeOptionsHtml(collectionTypeOptions) {
return collectionTypeOptions.filter(function(i) {
return !1 !== i.isSelectable
return i.isSelectable
}).map(function(i) {
return '<option value="' + i.value + '">' + i.name + "</option>"
}).join("")
Expand All @@ -35,9 +53,15 @@ define(["loading", "dialogHelper", "dom", "jQuery", "components/libraryoptionsed
$("#selectCollectionType", page).html(getCollectionTypeOptionsHtml(collectionTypeOptions)).val("").on("change", function() {
var value = this.value,
dlg = $(this).parents(".dialog")[0];
if (libraryoptionseditor.setContentType(dlg.querySelector(".libraryOptions"), "mixed" == value ? "" : value), value ? dlg.querySelector(".libraryOptions").classList.remove("hide") : dlg.querySelector(".libraryOptions").classList.add("hide"), "mixed" != value) {
libraryoptionseditor.setContentType(dlg.querySelector(".libraryOptions"), value == "mixed" ? "" : value);
if (value)
dlg.querySelector(".libraryOptions").classList.remove("hide");
else
dlg.querySelector(".libraryOptions").classList.add("hide");

if (value != "mixed") {
var index = this.selectedIndex;
if (-1 != index) {
if (index != -1) {
var name = this.options[index].innerHTML.replace("*", "").replace("&amp;", "&");
$("#txtValue", dlg).val(name);
var folderOption = collectionTypeOptions.filter(function(i) {
Expand All @@ -59,7 +83,7 @@ define(["loading", "dialogHelper", "dom", "jQuery", "components/libraryoptionsed
require(["directorybrowser"], function(directoryBrowser) {
var picker = new directoryBrowser;
picker.show({
enableNetworkSharePath: !0,
enableNetworkSharePath: true,
callback: function(path, networkSharePath) {
path && addMediaLocation(page, path, networkSharePath), picker.close()
}
Expand Down Expand Up @@ -101,7 +125,10 @@ define(["loading", "dialogHelper", "dom", "jQuery", "components/libraryoptionsed
}

function onDialogClosed() {
loading.hide(), currentResolve(hasChanges)
// I can't see any corresponding call to loading.show,
// so I think this is not supposed to be here.
loading.hide();
JustAMan marked this conversation as resolved.
Show resolved Hide resolved
currentResolve(hasChanges);
}

function initLibraryOptions(dlg) {
Expand All @@ -113,23 +140,36 @@ define(["loading", "dialogHelper", "dom", "jQuery", "components/libraryoptionsed
function editor() {
this.show = function(options) {
return new Promise(function(resolve, reject) {
currentOptions = options, currentResolve = resolve, hasChanges = !1;
currentOptions = options, currentResolve = resolve, hasChanges = false;
var xhr = new XMLHttpRequest;
xhr.open("GET", "components/medialibrarycreator/medialibrarycreator.template.html", !0), xhr.onload = function(e) {
xhr.open("GET", "components/medialibrarycreator/medialibrarycreator.template.html", true);
xhr.onload = function(e) {
var template = this.response,
dlg = dialogHelper.createDialog({
size: "medium-tall",
modal: !1,
removeOnClose: !0,
scrollY: !1
modal: false,
removeOnClose: true,
scrollY: false
});
dlg.classList.add("ui-body-a"), dlg.classList.add("background-theme-a"), dlg.classList.add("dlg-librarycreator"), dlg.classList.add("formDialog"), dlg.innerHTML = Globalize.translateDocument(template), initEditor(dlg, options.collectionTypeOptions), dlg.addEventListener("close", onDialogClosed), dialogHelper.open(dlg), dlg.querySelector(".btnCancel").addEventListener("click", function() {
dlg.classList.add("ui-body-a");
dlg.classList.add("background-theme-a");
dlg.classList.add("dlg-librarycreator");
dlg.classList.add("formDialog");
dlg.innerHTML = Globalize.translateDocument(template);
initEditor(dlg, options.collectionTypeOptions);
dlg.addEventListener("close", onDialogClosed);
dialogHelper.open(dlg);
dlg.querySelector(".btnCancel").addEventListener("click", function() {
dialogHelper.close(dlg)
}), pathInfos = [], renderPaths(dlg), initLibraryOptions(dlg)
}, xhr.send()
});
pathInfos = [];
renderPaths(dlg);
initLibraryOptions(dlg);
};
xhr.send();
})
}
}
var currentResolve, hasChanges, currentOptions, pathInfos = [];
var currentResolve, hasChanges, currentOptions, pathInfos = [], isCreating = false;
return editor
});
});
32 changes: 23 additions & 9 deletions src/scripts/episodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,21 @@ define(["loading", "events", "libraryBrowser", "imageLoader", "listView", "cardB

function reloadItems(page) {
loading.show();
isLoading = true;
var query = getQuery(page);
ApiClient.getItems(Dashboard.getCurrentUserId(), query).then(function(result) {
function onNextPageClick() {
query.StartIndex += query.Limit, reloadItems(tabContent)
if (isLoading) return;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From a UX perspective I would honestly expect repeated clicks to cancel the previous request and move forward.

Example: You are on Page 4 and click Next 3 times. Once it's done loading you are now on page 7.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I disagree. When you're on page 4, "next" means "go to page 5", so if you repeatedly click "go to page 5" you should end on page 5 IMHO.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's how I wanted to fix it initially, but there's no good way of stopping you from going past the last page. Instead I opted to basically make a locking mechanism. This will also stop impatiently clicking from going too far...
I think a relevant improvement would be to make it possible to go directly to page N

Copy link
Member

@cvium cvium Jan 15, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A future improvement might be pre-loading prev and next pages. That also solves the problem somewhat.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually like both having an ability to choose N and to keep prev and next pages preloaded.

query.StartIndex += query.Limit;
reloadItems(tabContent)
}

function onPreviousPageClick() {
query.StartIndex -= query.Limit, reloadItems(tabContent)
if (isLoading) return;
query.StartIndex -= query.Limit;
reloadItems(tabContent)
}

window.scrollTo(0, 0);
var html, pagingHtml = libraryBrowser.getQueryPagingHtml({
startIndex: query.StartIndex,
Expand Down Expand Up @@ -80,16 +86,24 @@ define(["loading", "events", "libraryBrowser", "imageLoader", "listView", "cardB
scalable: !0,
overlayPlayButton: !0
});
var i, length, elems = tabContent.querySelectorAll(".paging");
for (i = 0, length = elems.length; i < length; i++) elems[i].innerHTML = pagingHtml;
for (elems = tabContent.querySelectorAll(".btnNextPage"), i = 0, length = elems.length; i < length; i++) elems[i].addEventListener("click", onNextPageClick);
for (elems = tabContent.querySelectorAll(".btnPreviousPage"), i = 0, length = elems.length; i < length; i++) elems[i].addEventListener("click", onPreviousPageClick);
itemsContainer.innerHTML = html, imageLoader.lazyChildren(itemsContainer), libraryBrowser.saveQueryValues(getSavedQueryKey(page), query), loading.hide()
var i, length, elems;
for (elems = tabContent.querySelectorAll(".paging"), i = 0, length = elems.length; i < length; i++)
elems[i].innerHTML = pagingHtml;
for (elems = tabContent.querySelectorAll(".btnNextPage"), i = 0, length = elems.length; i < length; i++)
elems[i].addEventListener("click", onNextPageClick);
for (elems = tabContent.querySelectorAll(".btnPreviousPage"), i = 0, length = elems.length; i < length; i++)
elems[i].addEventListener("click", onPreviousPageClick);
itemsContainer.innerHTML = html;
imageLoader.lazyChildren(itemsContainer);
libraryBrowser.saveQueryValues(getSavedQueryKey(page), query);
loading.hide();
isLoading = false;
})
}
var self = this,
pageSize = 100,
data = {};
data = {},
isLoading = false;
self.showFilterMenu = function() {
require(["components/filterdialog/filterdialog"], function(filterDialogFactory) {
var filterDialog = new filterDialogFactory({
Expand Down Expand Up @@ -152,4 +166,4 @@ define(["loading", "events", "libraryBrowser", "imageLoader", "listView", "cardB
reloadItems(tabContent)
}, self.destroy = function() {}
}
});
});
11 changes: 8 additions & 3 deletions src/scripts/livetvchannels.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ define(["cardBuilder", "imageLoader", "libraryBrowser", "loading", "events", "em

function renderChannels(context, result) {
function onNextPageClick() {
if (isLoading) return;
query.StartIndex += query.Limit, reloadItems(context)
}

function onPreviousPageClick() {
if (isLoading) return;
query.StartIndex -= query.Limit, reloadItems(context)
}
var query = getQuery();
Expand Down Expand Up @@ -68,17 +70,20 @@ define(["cardBuilder", "imageLoader", "libraryBrowser", "loading", "events", "em

function reloadItems(context, save) {
loading.show();
isLoading = true;
var query = getQuery(),
apiClient = ApiClient;
query.UserId = apiClient.getCurrentUserId(), apiClient.getLiveTvChannels(query).then(function(result) {
renderChannels(context, result), loading.hide()
renderChannels(context, result);
loading.hide();
isLoading = false;
})
}
var pageData, self = this;
var pageData, self = this, isLoading = false;
tabContent.querySelector(".btnFilter").addEventListener("click", function() {
showFilterMenu(tabContent)
}), self.renderTab = function() {
reloadItems(tabContent)
}
}
});
});
47 changes: 30 additions & 17 deletions src/scripts/moviecollections.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,25 @@ define(["loading", "events", "libraryBrowser", "imageLoader", "listView", "cardB
function getPageData(context) {
var key = getSavedQueryKey(context),
pageData = data[key];
return pageData || (pageData = data[key] = {
query: {
SortBy: "SortName",
SortOrder: "Ascending",
IncludeItemTypes: "BoxSet",
Recursive: !0,
Fields: "PrimaryImageAspectRatio,SortName",
ImageTypeLimit: 1,
EnableImageTypes: "Primary,Backdrop,Banner,Thumb",
StartIndex: 0,
Limit: pageSize
},
view: libraryBrowser.getSavedView(key) || "Poster"
}, pageData.query.ParentId = params.topParentId, libraryBrowser.loadSavedQueryValues(key, pageData.query)), pageData
if (!pageData) {
pageData = data[key] = {
query: {
SortBy: "SortName",
SortOrder: "Ascending",
IncludeItemTypes: "BoxSet",
Recursive: true,
Fields: "PrimaryImageAspectRatio,SortName",
ImageTypeLimit: 1,
EnableImageTypes: "Primary,Backdrop,Banner,Thumb",
StartIndex: 0,
Limit: pageSize
},
view: libraryBrowser.getSavedView(key) || "Poster"
};
pageData.query.ParentId = params.topParentId;
libraryBrowser.loadSavedQueryValues(key, pageData.query);
}
return pageData;
}

function getQuery(context) {
Expand All @@ -36,13 +41,16 @@ define(["loading", "events", "libraryBrowser", "imageLoader", "listView", "cardB

function reloadItems(page) {
loading.show();
isLoading = true;
var query = getQuery(page);
ApiClient.getItems(ApiClient.getCurrentUserId(), query).then(function(result) {
function onNextPageClick() {
if (isLoading) return;
query.StartIndex += query.Limit, reloadItems(tabContent)
}

function onPreviousPageClick() {
if (isLoading) return;
query.StartIndex -= query.Limit, reloadItems(tabContent)
}
window.scrollTo(0, 0);
Expand Down Expand Up @@ -106,12 +114,17 @@ define(["loading", "events", "libraryBrowser", "imageLoader", "listView", "cardB
for (elems = tabContent.querySelectorAll(".btnPreviousPage"), i = 0, length = elems.length; i < length; i++) elems[i].addEventListener("click", onPreviousPageClick);
result.Items.length || (html = '<p style="text-align:center;">' + Globalize.translate("MessageNoCollectionsAvailable") + "</p>");
var itemsContainer = tabContent.querySelector(".itemsContainer");
itemsContainer.innerHTML = html, imageLoader.lazyChildren(itemsContainer), libraryBrowser.saveQueryValues(getSavedQueryKey(page), query), loading.hide()
itemsContainer.innerHTML = html;
imageLoader.lazyChildren(itemsContainer);
libraryBrowser.saveQueryValues(getSavedQueryKey(page), query);
loading.hide();
isLoading = false;
})
}
var self = this,
pageSize = 100,
data = {};
data = {},
isLoading = false;
self.getCurrentViewStyle = function() {
return getPageData(tabContent).view
},
Expand Down Expand Up @@ -160,4 +173,4 @@ define(["loading", "events", "libraryBrowser", "imageLoader", "listView", "cardB
reloadItems(tabContent)
}, self.destroy = function() {}
}
});
});
Loading