1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

update fetch

This commit is contained in:
Luke Pulverenti 2015-11-27 23:53:56 -05:00
parent dd09b038d5
commit ee899a7332
21 changed files with 209 additions and 260 deletions

View file

@ -132,12 +132,21 @@
Events.trigger(self, 'requestfail', [
{
url: this.url,
type: this.type,
status: e.status,
errorCode: e.getResponseHeader("X-Application-Error-Code")
}]);
}
function onFetchFail(url, response) {
Events.trigger(self, 'requestfail', [
{
url: url,
status: response.status,
errorCode: response.headers ? response.headers["X-Application-Error-Code"] : null
}]);
}
function onRetryRequestFail(request) {
Events.trigger(self, 'requestfail', [
@ -195,6 +204,13 @@
return deferred.promise();
};
function getFetchPromise(request) {
return fetch(request.url, {
headers: request.headers,
method: request.type
});
}
/**
* Wraps around jQuery ajax methods to add additional info to the request.
*/
@ -213,15 +229,28 @@
if (self.enableAutomaticNetworking === false || request.type != "GET") {
logger.log('Requesting url without automatic networking: ' + request.url);
return fetch(request.url, {
headers: request.headers,
method: request.type
return new Promise(function (resolve, reject) {
getFetchPromise(request).then(function (response) {
if (response.status < 400) {
resolve(response);
} else {
onFetchFail(request.url, response);
reject();
}
}, function () {
onFetchFail(request.url, {});
reject();
});
});
}
var deferred = DeferredBuilder.Deferred();
self.ajaxWithFailover(request, deferred, true);
return deferred.promise();
return new Promise(function (resolve, reject) {
self.fetchWithFailover(request, resolve, reject, true);
});
};
self.fetchJSON = function (url, includeAuthorization) {
@ -318,6 +347,56 @@
return deferred.promise();
}
self.fetchWithFailover = function (request, resolve, reject, enableReconnection) {
logger.log("Requesting " + request.url);
request.timeout = 30000;
getFetchPromise(request).then(function (response) {
if (response.status < 400) {
resolve(response);
} else {
onFetchFail(request.url, response);
reject();
}
}, function () {
logger.log("Request failed to " + request.url);
// http://api.jquery.com/jQuery.ajax/
if (enableReconnection) {
logger.log("Attempting reconnection");
var previousServerAddress = self.serverAddress();
tryReconnect().done(function () {
logger.log("Reconnect succeesed");
request.url = request.url.replace(previousServerAddress, self.serverAddress());
self.fetchWithFailover(request, resolve, reject, false);
}).fail(function () {
logger.log("Reconnect failed");
onFetchFail(request.url, {});
reject();
});
} else {
logger.log("Reporting request failure");
onFetchFail(request.url, {});
reject();
}
});
};
self.ajaxWithFailover = function (request, deferred, enableReconnection) {
logger.log("Requesting " + request.url);
@ -1170,7 +1249,7 @@
client: app
});
return self.getJSON(url);
return self.fetchJSON(url);
};
self.updateDisplayPreferences = function (id, obj, userId, app) {

View file

@ -30,6 +30,6 @@
"commit": "14d2ca3df97da64c820829a8310f9198fbafbcfa"
},
"_source": "git://github.com/desandro/eventie.git",
"_target": "~1.0.3",
"_target": "^1",
"_originalSource": "eventie"
}

View file

@ -29,14 +29,14 @@
"webcomponentsjs": "webcomponents/webcomponentsjs#^0.7.0"
},
"ignore": [],
"homepage": "https://github.com/PolymerElements/iron-behaviors",
"homepage": "https://github.com/polymerelements/iron-behaviors",
"_release": "1.0.11",
"_resolution": {
"type": "version",
"tag": "v1.0.11",
"commit": "084fbc7f60343d717bb2208f350774f4c9899777"
},
"_source": "git://github.com/PolymerElements/iron-behaviors.git",
"_source": "git://github.com/polymerelements/iron-behaviors.git",
"_target": "^1.0.0",
"_originalSource": "PolymerElements/iron-behaviors"
"_originalSource": "polymerelements/iron-behaviors"
}

View file

@ -36,7 +36,7 @@
"tag": "v1.0.8",
"commit": "e9a66727f3da0446f04956d4e4f1dcd51cdec2ff"
},
"_source": "git://github.com/polymerelements/iron-selector.git",
"_source": "git://github.com/PolymerElements/iron-selector.git",
"_target": "^1.0.0",
"_originalSource": "polymerelements/iron-selector"
"_originalSource": "PolymerElements/iron-selector"
}

View file

@ -11,12 +11,12 @@
switch (evt.target.error.code) {
case evt.target.error.NOT_FOUND_ERR:
Dashboard.showError(Globalize.translate('MessageFileNotFound'));
Dashboard.alert(Globalize.translate('MessageFileNotFound'));
break;
case evt.target.error.ABORT_ERR:
break; // noop
default:
Dashboard.showError(Globalize.translate('MessageFileReadError'));
Dashboard.alert(Globalize.translate('MessageFileReadError'));
break;
};
}

View file

@ -31,7 +31,7 @@
}).fail(function () {
Dashboard.showError(Globalize.translate('ErrorAddingMediaPathToVirtualFolder'));
Dashboard.alert(Globalize.translate('ErrorAddingMediaPathToVirtualFolder'));
});
return false;

View file

@ -17,7 +17,7 @@
}).fail(function () {
Dashboard.showError(Globalize.translate('ErrorAddingMediaPathToVirtualFolder'));
Dashboard.alert(Globalize.translate('ErrorAddingMediaPathToVirtualFolder'));
});
}
@ -43,7 +43,7 @@
}).fail(function () {
Dashboard.showError(Globalize.translate('DefaultErrorMessage'));
Dashboard.alert(Globalize.translate('DefaultErrorMessage'));
});
}
});

View file

@ -1562,14 +1562,6 @@ progress {
user-drag: none;
}
.nativeApp input {
-webkit-user-select: auto !important;
-khtml-user-select: auto !important;
-moz-user-select: auto !important;
-ms-user-select: auto !important;
user-select: auto !important;
}
.supporterMembershipDisabled .tabSupporterMembership {
display: none;
}

View file

@ -3,7 +3,7 @@
}
.viewMenuBar.semiTransparent {
background-color: rgba(15, 15, 15, .35);
background-color: rgba(15, 15, 15, .3);
}
.background-theme-b, paper-dialog.background-theme-b {

View file

@ -1276,7 +1276,7 @@ $(document).on('pageshow', "#dashboardPage", DashboardPage.onPageShow).on('pageb
function dismissWelcome(page, userId) {
ApiClient.getDisplayPreferences('dashboard', userId, 'dashboard').done(function (result) {
ApiClient.getDisplayPreferences('dashboard', userId, 'dashboard').then(function (result) {
result.CustomPrefs[welcomeTourKey] = welcomeDismissValue;
ApiClient.updateDisplayPreferences('dashboard', result, userId, 'dashboard');
@ -1289,7 +1289,7 @@ $(document).on('pageshow', "#dashboardPage", DashboardPage.onPageShow).on('pageb
var userId = Dashboard.getCurrentUserId();
apiClient.getDisplayPreferences('dashboard', userId, 'dashboard').done(function (result) {
apiClient.getDisplayPreferences('dashboard', userId, 'dashboard').then(function (result) {
if (result.CustomPrefs[welcomeTourKey] == welcomeDismissValue) {
$('.welcomeMessage', page).hide();

View file

@ -90,87 +90,6 @@ if (!Array.prototype.filter) {
};
}
var WebNotifications = {
show: function (data) {
if (window.Notification) {
var level = Notification.permissionLevel ? Notification.permissionLevel() : Notification.permission;
if (level === "granted") {
var notif = new Notification(data.title, data);
if (notif.show) {
notif.show();
}
if (data.timeout) {
setTimeout(function () {
if (notif.close) {
notif.close();
}
else if (notif.cancel) {
notif.cancel();
}
}, data.timeout);
}
return notif;
} else if (level === "default") {
Notification.requestPermission(function () {
return WebNotifications.show(data);
});
}
}
else if (window.webkitNotifications) {
if (!webkitNotifications.checkPermission()) {
var notif = webkitNotifications.createNotification(data.icon, data.title, data.body);
notif.show();
if (data.timeout) {
setTimeout(function () {
if (notif.close) {
notif.close();
}
else if (notif.cancel) {
notif.cancel();
}
}, data.timeout);
}
return notif;
} else {
webkitNotifications.requestPermission(function () {
return WebNotifications.show(data);
});
}
}
},
requestPermission: function () {
if (window.webkitNotifications) {
if (!webkitNotifications.checkPermission()) {
} else {
webkitNotifications.requestPermission(function () {
});
}
}
else if (window.Notification) {
var level = Notification.permissionLevel ? Notification.permissionLevel() : Notification.permission;
if (level === "default") {
Notification.requestPermission(function () {
});
}
}
}
};
/*
* Javascript Humane Dates
* Copyright (c) 2008 Dean Landolt (deanlandolt.com)
@ -229,30 +148,6 @@ function humane_date(date_str) {
return date_str;
}
function humane_elapsed(firstDateStr, secondDateStr) {
var dt1 = new Date(firstDateStr);
var dt2 = new Date(secondDateStr);
var seconds = (dt2.getTime() - dt1.getTime()) / 1000;
var numdays = Math.floor((seconds % 31536000) / 86400);
var numhours = Math.floor(((seconds % 31536000) % 86400) / 3600);
var numminutes = Math.floor((((seconds % 31536000) % 86400) % 3600) / 60);
var numseconds = Math.round((((seconds % 31536000) % 86400) % 3600) % 60);
var elapsedStr = '';
elapsedStr += numdays == 1 ? numdays + ' day ' : '';
elapsedStr += numdays > 1 ? numdays + ' days ' : '';
elapsedStr += numhours == 1 ? numhours + ' hour ' : '';
elapsedStr += numhours > 1 ? numhours + ' hours ' : '';
elapsedStr += numminutes == 1 ? numminutes + ' minute ' : '';
elapsedStr += numminutes > 1 ? numminutes + ' minutes ' : '';
elapsedStr += elapsedStr.length > 0 ? 'and ' : '';
elapsedStr += numseconds == 1 ? numseconds + ' second' : '';
elapsedStr += numseconds == 0 || numseconds > 1 ? numseconds + ' seconds' : '';
return elapsedStr;
}
function getWindowUrl(win) {
return (win || window).location.href;
}
@ -359,25 +254,6 @@ function parseISO8601Date(s, options) {
return new Date(ms);
}
//convert Ticks to human hr:min:sec format
function ticks_to_human(str) {
var in_seconds = (str / 10000000);
var hours = Math.floor(in_seconds / 3600);
var minutes = Math.floor((in_seconds - (hours * 3600)) / 60);
var seconds = '0' + Math.round(in_seconds - (hours * 3600) - (minutes * 60));
var time = '';
if (hours > 0) time += hours + ":";
if (minutes < 10 && hours == 0) time += minutes;
else time += ('0' + minutes).substr(-2);
time += ":" + seconds.substr(-2);
return time;
};
// This only exists because the polymer elements get distorted when using regular jquery show/hide
$.fn.visible = function (visible) {

View file

@ -133,7 +133,7 @@
function dismissWelcome(page, userId) {
getDisplayPreferences('home', userId).done(function (result) {
getDisplayPreferences('home', userId).then(function (result) {
result.CustomPrefs[homePageTourKey] = homePageDismissValue;
ApiClient.updateDisplayPreferences('home', result, userId, AppSettings.displayPreferencesKey());
@ -201,11 +201,11 @@
Dashboard.showLoadingMsg();
getDisplayPreferences('home', userId).done(function (result) {
getDisplayPreferences('home', userId).then(function (result) {
Dashboard.getCurrentUser().then(function (user) {
loadSections(tabContent, user, result).done(function () {
loadSections(tabContent, user, result).then(function () {
if (!AppInfo.isNativeApp) {
showWelcomeIfNeeded(page, result);
@ -307,9 +307,7 @@
function getDisplayPreferences(key, userId) {
return ApiClient.getDisplayPreferences(key, userId, AppSettings.displayPreferencesKey()).done(function (result) {
});
return ApiClient.getDisplayPreferences(key, userId, AppSettings.displayPreferencesKey());
}
window.HomePage = {

View file

@ -271,7 +271,7 @@
function fadeOutLeft(elem, iterations) {
var keyframes = [{ opacity: '1', transform: 'none', offset: 0 },
{ opacity: '0', transform: 'translate3d(-100%, 0, 0)', offset: 1 }];
var timing = { duration: 400, iterations: iterations };
var timing = { duration: 300, iterations: iterations };
return elem.animate(keyframes, timing);
}
if (!LibraryBrowser.navigateOnLibraryTabSelect()) {
@ -279,6 +279,7 @@
var animateTab = !$.browser.safari;
animateTab = false;
var selected = pages.selected;
if (selected != null && animateTab) {
var newValue = this.selected;

View file

@ -948,8 +948,6 @@
Events.on(apiClient, 'websocketmessage', onWebSocketMessage);
}
Dashboard.ready(function () {
if (window.ApiClient) {
initializeApiClient(window.ApiClient);
}
@ -977,7 +975,6 @@
var mainDrawerPanel = document.querySelector('.mainDrawerPanel');
mainDrawerPanel.addEventListener('iron-select', onMainDrawerSelect);
});
})(window, document, jQuery, window.devicePixelRatio);

View file

@ -121,7 +121,7 @@
Dashboard.hideLoadingMsg();
setTimeout(function () {
Dashboard.showError(Globalize.translate('MessageInvalidUser'));
Dashboard.alert(Globalize.translate('MessageInvalidUser'));
}, 300);
});

View file

@ -220,7 +220,7 @@
ApiClient.getUser(userId).done(function (user) {
ApiClient.getDisplayPreferences('home', user.Id, AppSettings.displayPreferencesKey()).done(function (displayPreferences) {
ApiClient.getDisplayPreferences('home', user.Id, AppSettings.displayPreferencesKey()).then(function (displayPreferences) {
saveUser(page, user, displayPreferences);
@ -285,7 +285,7 @@
ApiClient.getUser(userId).done(function (user) {
ApiClient.getDisplayPreferences('home', user.Id, AppSettings.displayPreferencesKey()).done(function (result) {
ApiClient.getDisplayPreferences('home', user.Id, AppSettings.displayPreferencesKey()).then(function (result) {
loadForm(page, user, result);

View file

@ -72,15 +72,15 @@
switch (evt.target.error.code) {
case evt.target.error.NOT_FOUND_ERR:
Dashboard.showError(Globalize.translate('FileNotFound'));
Dashboard.alert(Globalize.translate('FileNotFound'));
break;
case evt.target.error.NOT_READABLE_ERR:
Dashboard.showError(Globalize.translate('FileReadError'));
Dashboard.alert(Globalize.translate('FileReadError'));
break;
case evt.target.error.ABORT_ERR:
break; // noop
default:
Dashboard.showError(Globalize.translate('FileReadError'));
Dashboard.alert(Globalize.translate('FileReadError'));
};
}
@ -92,7 +92,7 @@
function onFileReaderAbort(evt) {
Dashboard.hideLoadingMsg();
Dashboard.showError(Globalize.translate('FileReadCancelled'));
Dashboard.alert(Globalize.translate('FileReadCancelled'));
}
function setFiles(page, files) {
@ -317,7 +317,7 @@
if ($('#txtNewPassword', page).val() != $('#txtNewPasswordConfirm', page).val()) {
Dashboard.showError(Globalize.translate('PasswordMatchError'));
Dashboard.alert(Globalize.translate('PasswordMatchError'));
} else {
Dashboard.showLoadingMsg();

View file

@ -92,6 +92,30 @@
divScheduledTasks.innerHTML = html;
}
function humane_elapsed(firstDateStr, secondDateStr) {
var dt1 = new Date(firstDateStr);
var dt2 = new Date(secondDateStr);
var seconds = (dt2.getTime() - dt1.getTime()) / 1000;
var numdays = Math.floor((seconds % 31536000) / 86400);
var numhours = Math.floor(((seconds % 31536000) % 86400) / 3600);
var numminutes = Math.floor((((seconds % 31536000) % 86400) % 3600) / 60);
var numseconds = Math.round((((seconds % 31536000) % 86400) % 3600) % 60);
var elapsedStr = '';
elapsedStr += numdays == 1 ? numdays + ' day ' : '';
elapsedStr += numdays > 1 ? numdays + ' days ' : '';
elapsedStr += numhours == 1 ? numhours + ' hour ' : '';
elapsedStr += numhours > 1 ? numhours + ' hours ' : '';
elapsedStr += numminutes == 1 ? numminutes + ' minute ' : '';
elapsedStr += numminutes > 1 ? numminutes + ' minutes ' : '';
elapsedStr += elapsedStr.length > 0 ? 'and ' : '';
elapsedStr += numseconds == 1 ? numseconds + ' second' : '';
elapsedStr += numseconds == 0 || numseconds > 1 ? numseconds + ' seconds' : '';
return elapsedStr;
}
function getTaskProgressHtml(task) {
var html = '';

View file

@ -16,50 +16,18 @@
$.support.cors = true;
function onOneDocumentClick() {
document.removeEventListener('click', onOneDocumentClick);
WebNotifications.requestPermission();
if (window.Notification) {
Notification.requestPermission();
}
}
document.addEventListener('click', onOneDocumentClick);
})();
var Dashboard = {
jQueryMobileInit: function () {
// Page
//$.mobile.page.prototype.options.theme = "a";
//$.mobile.page.prototype.options.headerTheme = "a";
//$.mobile.page.prototype.options.contentTheme = "a";
//$.mobile.page.prototype.options.footerTheme = "a";
//$.mobile.button.prototype.options.theme = "c";
//$.mobile.listview.prototype.options.dividerTheme = "b";
//$.mobile.popup.prototype.options.theme = "c";
//$.mobile.popup.prototype.options.transition = "none";
if ($.browser.mobile) {
$.mobile.defaultPageTransition = "none";
} else {
$.mobile.defaultPageTransition = "none";
}
//$.mobile.collapsible.prototype.options.contentTheme = "a";
// Make panels a little larger than the defaults
//$.event.special.swipe.verticalDistanceThreshold = 40;
//$.mobile.page.prototype.options.domCache = true;
$.mobile.hideUrlBar = false;
$.mobile.autoInitializePage = false;
$.mobile.changePage.defaults.showLoadMsg = false;
// These are not needed. Nulling them out can help reduce dom querying when pages are loaded
$.mobile.nojs = null;
$.mobile.degradeInputsWithin = null;
$.mobile.filterHtml = Dashboard.filterHtml;
},
filterHtml: function (html) {
@ -282,11 +250,6 @@ var Dashboard = {
}
},
showError: function (message) {
Dashboard.alert(message);
},
updateSystemInfo: function (info) {
Dashboard.lastSystemInfo = info;
@ -578,11 +541,9 @@ var Dashboard = {
Dashboard.hideLoadingMsg();
Dashboard.alert("Settings saved.");
Dashboard.alert(Globalize.translate('MessageSettingsSaved'));
},
defaultErrorMessage: Globalize.translate('DefaultErrorMessage'),
processServerConfigurationUpdateResult: function (result) {
Dashboard.hideLoadingMsg();
@ -1364,7 +1325,7 @@ var Dashboard = {
var newItems = data.ItemsAdded;
if (!newItems.length || AppInfo.isNativeApp) {
if (!newItems.length || AppInfo.isNativeApp || !window.Notification) {
return;
}
@ -1389,7 +1350,8 @@ var Dashboard = {
var notification = {
title: "New " + item.Type,
body: item.Name,
timeout: 5000
timeout: 5000,
vibrate: true
};
var imageTags = item.ImageTags || {};
@ -1403,6 +1365,26 @@ var Dashboard = {
});
}
if (Notification.permission === "granted") {
var notif = new Notification(notification.title, notification);
if (notif.show) {
notif.show();
}
if (notification.timeout) {
setTimeout(function () {
if (notif.close) {
notif.close();
}
else if (notif.cancel) {
notif.cancel();
}
}, notification.timeout);
}
}
WebNotifications.show(notification);
}
});
@ -1727,17 +1709,6 @@ var Dashboard = {
exit: function () {
Dashboard.logout();
},
loadDragula: function (callback) {
require(['dragula'], function (dragula) {
Dashboard.importCss('bower_components/dragula.js/dist/dragula.min.css');
callback(dragula);
});
}
};
@ -2215,6 +2186,8 @@ var AppInfo = {};
deps.push('bower_components/fetch/fetch');
}
deps.push('scripts/mediacontroller');
require(deps, function () {
loadImageCache();
@ -2247,8 +2220,12 @@ var AppInfo = {};
require(['cordova/android/logging']);
}
deps.push('scripts/librarybrowser');
deps.push('scripts/globalize');
deps.push('appstorage');
deps.push('scripts/mediaplayer');
deps.push('scripts/appsettings');
deps.push('apiclient/connectionmanager');
require(deps, function () {
@ -2382,6 +2359,11 @@ var AppInfo = {};
deps.push('scripts/librarylist');
deps.push('scripts/notifications');
deps.push('scripts/alphapicker');
deps.push('thirdparty/jquery.unveil-custom.js');
deps.push('scripts/playlistmanager');
deps.push('scripts/sync');
deps.push('scripts/backdrops');
deps.push('scripts/librarymenu');
require(deps, function () {
@ -2605,4 +2587,4 @@ window.addEventListener("beforeunload", function () {
}
});
Dashboard.jQueryMobileInit();
$.mobile.filterHtml = Dashboard.filterHtml;

View file

@ -85,7 +85,7 @@
if (result.Success) {
Dashboard.alert(Globalize.translate('MessageKeysLinked'));
} else {
Dashboard.showError(result.ErrorMessage);
Dashboard.alert(result.ErrorMessage);
}
Logger.log(result);
@ -109,7 +109,7 @@
if (result.Success) {
Dashboard.alert(Globalize.translate('MessageKeyEmailedTo').replace("{0}", email));
} else {
Dashboard.showError(result.ErrorMessage);
Dashboard.alert(result.ErrorMessage);
}
Logger.log(result);

View file

@ -109,7 +109,7 @@
}).fail(function() {
Dashboard.showError(Globalize.translate('DefaultErrorMessage'));
Dashboard.alert(Globalize.translate('DefaultErrorMessage'));
Dashboard.hideLoadingMsg();
});
}