mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
Move Dashboard to a new module
This commit is contained in:
parent
d4fbe300d1
commit
81c6dc6907
4 changed files with 266 additions and 225 deletions
|
@ -1,4 +1,4 @@
|
|||
function getWindowLocationSearch(win) {
|
||||
window.getWindowLocationSearch = function(win) {
|
||||
'use strict';
|
||||
|
||||
var search = (win || window).location.search;
|
||||
|
@ -12,9 +12,9 @@ function getWindowLocationSearch(win) {
|
|||
}
|
||||
|
||||
return search || '';
|
||||
}
|
||||
};
|
||||
|
||||
window.getParameterByName = function (name, url) {
|
||||
window.getParameterByName = function(name, url) {
|
||||
'use strict';
|
||||
|
||||
name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
|
||||
|
@ -29,7 +29,7 @@ window.getParameterByName = function (name, url) {
|
|||
return decodeURIComponent(results[1].replace(/\+/g, ' '));
|
||||
};
|
||||
|
||||
function pageClassOn(eventName, className, fn) {
|
||||
window.pageClassOn = function(eventName, className, fn) {
|
||||
'use strict';
|
||||
|
||||
document.addEventListener(eventName, function (event) {
|
||||
|
@ -39,7 +39,7 @@ function pageClassOn(eventName, className, fn) {
|
|||
fn.call(target, event);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
window.pageIdOn = function(eventName, id, fn) {
|
||||
'use strict';
|
||||
|
@ -53,187 +53,6 @@ window.pageIdOn = function(eventName, id, fn) {
|
|||
});
|
||||
};
|
||||
|
||||
var Dashboard = {
|
||||
getCurrentUser: function () {
|
||||
return window.ApiClient.getCurrentUser(false);
|
||||
},
|
||||
|
||||
//TODO: investigate url prefix support for serverAddress function
|
||||
serverAddress: function () {
|
||||
if (AppInfo.isNativeApp) {
|
||||
var apiClient = window.ApiClient;
|
||||
|
||||
if (apiClient) {
|
||||
return apiClient.serverAddress();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
var urlLower = window.location.href.toLowerCase();
|
||||
var index = urlLower.lastIndexOf('/web');
|
||||
|
||||
if (index != -1) {
|
||||
return urlLower.substring(0, index);
|
||||
}
|
||||
|
||||
var loc = window.location;
|
||||
var address = loc.protocol + '//' + loc.hostname;
|
||||
|
||||
if (loc.port) {
|
||||
address += ':' + loc.port;
|
||||
}
|
||||
|
||||
return address;
|
||||
},
|
||||
getCurrentUserId: function () {
|
||||
var apiClient = window.ApiClient;
|
||||
|
||||
if (apiClient) {
|
||||
return apiClient.getCurrentUserId();
|
||||
}
|
||||
|
||||
return null;
|
||||
},
|
||||
onServerChanged: function (userId, accessToken, apiClient) {
|
||||
apiClient = apiClient || window.ApiClient;
|
||||
window.ApiClient = apiClient;
|
||||
},
|
||||
logout: function () {
|
||||
ConnectionManager.logout().then(function () {
|
||||
var loginPage;
|
||||
|
||||
if (AppInfo.isNativeApp) {
|
||||
loginPage = 'selectserver.html';
|
||||
window.ApiClient = null;
|
||||
} else {
|
||||
loginPage = 'login.html';
|
||||
}
|
||||
|
||||
Dashboard.navigate(loginPage);
|
||||
});
|
||||
},
|
||||
getConfigurationPageUrl: function (name) {
|
||||
return 'configurationpage?name=' + encodeURIComponent(name);
|
||||
},
|
||||
getConfigurationResourceUrl: function (name) {
|
||||
if (AppInfo.isNativeApp) {
|
||||
return ApiClient.getUrl('web/ConfigurationPage', {
|
||||
name: name
|
||||
});
|
||||
}
|
||||
|
||||
return Dashboard.getConfigurationPageUrl(name);
|
||||
},
|
||||
navigate: function (url, preserveQueryString) {
|
||||
if (!url) {
|
||||
throw new Error('url cannot be null or empty');
|
||||
}
|
||||
|
||||
var queryString = getWindowLocationSearch();
|
||||
|
||||
if (preserveQueryString && queryString) {
|
||||
url += queryString;
|
||||
}
|
||||
|
||||
return new Promise(function (resolve, reject) {
|
||||
require(['appRouter'], function (appRouter) {
|
||||
return appRouter.show(url).then(resolve, reject);
|
||||
});
|
||||
});
|
||||
},
|
||||
navigate_direct: function (path) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
require(['appRouter'], function (appRouter) {
|
||||
return appRouter.showDirect(path).then(resolve, reject);
|
||||
});
|
||||
});
|
||||
},
|
||||
processPluginConfigurationUpdateResult: function () {
|
||||
require(['loading', 'toast'], function (loading, toast) {
|
||||
loading.hide();
|
||||
toast.default(Globalize.translate('MessageSettingsSaved'));
|
||||
});
|
||||
},
|
||||
processServerConfigurationUpdateResult: function (result) {
|
||||
require(['loading', 'toast'], function (loading, toast) {
|
||||
loading.hide();
|
||||
toast.default(Globalize.translate('MessageSettingsSaved'));
|
||||
});
|
||||
},
|
||||
processErrorResponse: function (response) {
|
||||
require(['loading'], function (loading) {
|
||||
loading.hide();
|
||||
});
|
||||
|
||||
var status = '' + response.status;
|
||||
|
||||
if (response.statusText) {
|
||||
status = response.statusText;
|
||||
}
|
||||
|
||||
Dashboard.alert({
|
||||
title: status,
|
||||
message: response.headers ? response.headers.get('X-Application-Error-Code') : null
|
||||
});
|
||||
},
|
||||
alert: function (options) {
|
||||
if (typeof options == 'string') {
|
||||
return void require(['toast'], function (toast) {
|
||||
toast.default({
|
||||
text: options
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
require(['alert'], function (alert) {
|
||||
alert.default({
|
||||
title: options.title || Globalize.translate('HeaderAlert'),
|
||||
text: options.message
|
||||
}).then(options.callback || function () {});
|
||||
});
|
||||
},
|
||||
capabilities: function (appHost) {
|
||||
var capabilities = {
|
||||
PlayableMediaTypes: ['Audio', 'Video'],
|
||||
SupportedCommands: ['MoveUp', 'MoveDown', 'MoveLeft', 'MoveRight', 'PageUp', 'PageDown', 'PreviousLetter', 'NextLetter', 'ToggleOsd', 'ToggleContextMenu', 'Select', 'Back', 'SendKey', 'SendString', 'GoHome', 'GoToSettings', 'VolumeUp', 'VolumeDown', 'Mute', 'Unmute', 'ToggleMute', 'SetVolume', 'SetAudioStreamIndex', 'SetSubtitleStreamIndex', 'DisplayContent', 'GoToSearch', 'DisplayMessage', 'SetRepeatMode', 'SetShuffleQueue', 'ChannelUp', 'ChannelDown', 'PlayMediaSource', 'PlayTrailers'],
|
||||
SupportsPersistentIdentifier: self.appMode === 'cordova' || self.appMode === 'android',
|
||||
SupportsMediaControl: true
|
||||
};
|
||||
appHost.getPushTokenInfo();
|
||||
return capabilities = Object.assign(capabilities, appHost.getPushTokenInfo());
|
||||
},
|
||||
selectServer: function () {
|
||||
if (window.NativeShell && typeof window.NativeShell.selectServer === 'function') {
|
||||
window.NativeShell.selectServer();
|
||||
} else {
|
||||
Dashboard.navigate('selectserver.html');
|
||||
}
|
||||
},
|
||||
hideLoadingMsg: function() {
|
||||
'use strict';
|
||||
require(['loading'], function(loading) {
|
||||
loading.hide();
|
||||
});
|
||||
},
|
||||
showLoadingMsg: function() {
|
||||
'use strict';
|
||||
require(['loading'], function(loading) {
|
||||
loading.show();
|
||||
});
|
||||
},
|
||||
confirm: function(message, title, callback) {
|
||||
'use strict';
|
||||
require(['confirm'], function(confirm) {
|
||||
confirm(message, title).then(function() {
|
||||
callback(!0);
|
||||
}).catch(function() {
|
||||
callback(!1);
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
var AppInfo = {};
|
||||
|
||||
function initClient() {
|
||||
|
@ -289,7 +108,7 @@ function initClient() {
|
|||
if (!AppInfo.isNativeApp) {
|
||||
console.debug('loading ApiClient singleton');
|
||||
|
||||
return require(['apiclient'], function (apiClientFactory) {
|
||||
return require(['apiclient', 'clientUtils'], function (apiClientFactory, clientUtils) {
|
||||
console.debug('creating ApiClient singleton');
|
||||
|
||||
var apiClient = new apiClientFactory(Dashboard.serverAddress(), apphost.appName(), apphost.appVersion(), apphost.deviceName(), apphost.deviceId());
|
||||
|
@ -376,36 +195,12 @@ function initClient() {
|
|||
}
|
||||
}
|
||||
|
||||
function initRequireWithBrowser() {
|
||||
var componentsPath = getComponentsPath();
|
||||
var scriptsPath = getScriptsPath();
|
||||
|
||||
define('filesystem', [scriptsPath + '/filesystem'], returnFirstDependency);
|
||||
|
||||
define('lazyLoader', [componentsPath + '/lazyLoader/lazyLoaderIntersectionObserver'], returnFirstDependency);
|
||||
define('shell', [scriptsPath + '/shell'], returnFirstDependency);
|
||||
|
||||
define('alert', [componentsPath + '/alert'], returnFirstDependency);
|
||||
|
||||
defineResizeObserver();
|
||||
|
||||
define('dialog', [componentsPath + '/dialog/dialog'], returnFirstDependency);
|
||||
|
||||
define('confirm', [componentsPath + '/confirm/confirm'], returnFirstDependency);
|
||||
|
||||
define('prompt', [componentsPath + '/prompt/prompt'], returnFirstDependency);
|
||||
|
||||
define('loading', [componentsPath + '/loading/loading'], returnFirstDependency);
|
||||
define('multi-download', [scriptsPath + '/multiDownload'], returnFirstDependency);
|
||||
define('fileDownloader', [scriptsPath + '/fileDownloader'], returnFirstDependency);
|
||||
|
||||
define('castSenderApiLoader', [componentsPath + '/castSenderApi'], returnFirstDependency);
|
||||
}
|
||||
|
||||
function init() {
|
||||
define('livetvcss', ['css!assets/css/livetv.css'], returnFirstDependency);
|
||||
define('detailtablecss', ['css!assets/css/detailtable.css'], returnFirstDependency);
|
||||
|
||||
require(['clientUtils']);
|
||||
|
||||
var promises = [];
|
||||
if (!window.fetch) {
|
||||
promises.push(require(['fetch']));
|
||||
|
@ -605,7 +400,29 @@ function initClient() {
|
|||
}
|
||||
|
||||
function onWebComponentsReady() {
|
||||
initRequireWithBrowser();
|
||||
var componentsPath = getComponentsPath();
|
||||
var scriptsPath = getScriptsPath();
|
||||
|
||||
define('filesystem', [scriptsPath + '/filesystem'], returnFirstDependency);
|
||||
|
||||
define('lazyLoader', [componentsPath + '/lazyLoader/lazyLoaderIntersectionObserver'], returnFirstDependency);
|
||||
define('shell', [scriptsPath + '/shell'], returnFirstDependency);
|
||||
|
||||
define('alert', [componentsPath + '/alert'], returnFirstDependency);
|
||||
|
||||
defineResizeObserver();
|
||||
|
||||
define('dialog', [componentsPath + '/dialog/dialog'], returnFirstDependency);
|
||||
|
||||
define('confirm', [componentsPath + '/confirm/confirm'], returnFirstDependency);
|
||||
|
||||
define('prompt', [componentsPath + '/prompt/prompt'], returnFirstDependency);
|
||||
|
||||
define('loading', [componentsPath + '/loading/loading'], returnFirstDependency);
|
||||
define('multi-download', [scriptsPath + '/multiDownload'], returnFirstDependency);
|
||||
define('fileDownloader', [scriptsPath + '/fileDownloader'], returnFirstDependency);
|
||||
|
||||
define('castSenderApiLoader', [componentsPath + '/castSenderApi'], returnFirstDependency);
|
||||
|
||||
if (self.appMode === 'cordova' || self.appMode === 'android' || self.appMode === 'standalone') {
|
||||
AppInfo.isNativeApp = true;
|
||||
|
@ -617,7 +434,7 @@ function initClient() {
|
|||
var localApiClient;
|
||||
let promise;
|
||||
|
||||
(function () {
|
||||
function initRequireJs() {
|
||||
var urlArgs = 'v=' + (window.dashboardVersion || new Date().getDate());
|
||||
|
||||
var bowerPath = getBowerPath();
|
||||
|
@ -648,7 +465,8 @@ function initClient() {
|
|||
nowPlayingHelper: componentsPath + '/playback/nowplayinghelper',
|
||||
pluginManager: componentsPath + '/pluginManager',
|
||||
packageManager: componentsPath + '/packageManager',
|
||||
screensaverManager: componentsPath + '/screensavermanager'
|
||||
screensaverManager: componentsPath + '/screensavermanager',
|
||||
clientUtils: scriptsPath + '/clientUtils'
|
||||
};
|
||||
|
||||
requirejs.onError = onRequireJsError;
|
||||
|
@ -1106,7 +924,9 @@ function initClient() {
|
|||
appRouter.showItem = showItem;
|
||||
return appRouter;
|
||||
});
|
||||
})();
|
||||
}
|
||||
|
||||
initRequireJs();
|
||||
|
||||
promise.then(onWebComponentsReady);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue