mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
Migration of Favorites and Hometab to ES6 modules
This commit is contained in:
parent
287cc06963
commit
3658b4471a
4 changed files with 97 additions and 82 deletions
|
@ -190,6 +190,8 @@
|
||||||
"src/controllers/dashboard/users/userpasswordpage.js",
|
"src/controllers/dashboard/users/userpasswordpage.js",
|
||||||
"src/controllers/dashboard/users/userprofilespage.js",
|
"src/controllers/dashboard/users/userprofilespage.js",
|
||||||
"src/controllers/edititemmetadata.js",
|
"src/controllers/edititemmetadata.js",
|
||||||
|
"src/controllers/favorites.js",
|
||||||
|
"src/controllers/hometab.js",
|
||||||
"src/controllers/playback/nowplaying.js",
|
"src/controllers/playback/nowplaying.js",
|
||||||
"src/controllers/playback/videoosd.js",
|
"src/controllers/playback/videoosd.js",
|
||||||
"src/controllers/searchpage.js",
|
"src/controllers/searchpage.js",
|
||||||
|
|
|
@ -1,5 +1,15 @@
|
||||||
define(['appRouter', 'cardBuilder', 'dom', 'globalize', 'connectionManager', 'apphost', 'layoutManager', 'focusManager', 'emby-itemscontainer', 'emby-scroller'], function (appRouter, cardBuilder, dom, globalize, connectionManager, appHost, layoutManager, focusManager) {
|
import appRouter from 'appRouter';
|
||||||
'use strict';
|
import cardBuilder from 'cardBuilder';
|
||||||
|
import dom from 'dom';
|
||||||
|
import globalize from 'globalize';
|
||||||
|
import connectionManager from 'connectionManager';
|
||||||
|
import appHost from 'apphost';
|
||||||
|
import layoutManager from 'layoutManager';
|
||||||
|
import focusManager from 'focusManager';
|
||||||
|
import 'emby-itemscontainer';
|
||||||
|
import 'emby-scroller';
|
||||||
|
|
||||||
|
/* eslint-disable indent */
|
||||||
|
|
||||||
function enableScrollX() {
|
function enableScrollX() {
|
||||||
return true;
|
return true;
|
||||||
|
@ -133,8 +143,8 @@ define(['appRouter', 'cardBuilder', 'dom', 'globalize', 'connectionManager', 'ap
|
||||||
|
|
||||||
function getFetchDataFn(section) {
|
function getFetchDataFn(section) {
|
||||||
return function () {
|
return function () {
|
||||||
var apiClient = this.apiClient;
|
const apiClient = this.apiClient;
|
||||||
var options = {
|
const options = {
|
||||||
SortBy: (section.types, 'SeriesName,SortName'),
|
SortBy: (section.types, 'SeriesName,SortName'),
|
||||||
SortOrder: 'Ascending',
|
SortOrder: 'Ascending',
|
||||||
Filters: 'IsFavorite',
|
Filters: 'IsFavorite',
|
||||||
|
@ -145,7 +155,7 @@ define(['appRouter', 'cardBuilder', 'dom', 'globalize', 'connectionManager', 'ap
|
||||||
EnableTotalRecordCount: false
|
EnableTotalRecordCount: false
|
||||||
};
|
};
|
||||||
options.Limit = 20;
|
options.Limit = 20;
|
||||||
var userId = apiClient.getCurrentUserId();
|
const userId = apiClient.getCurrentUserId();
|
||||||
|
|
||||||
if ('MusicArtist' === section.types) {
|
if ('MusicArtist' === section.types) {
|
||||||
return apiClient.getArtists(userId, options);
|
return apiClient.getArtists(userId, options);
|
||||||
|
@ -170,17 +180,17 @@ define(['appRouter', 'cardBuilder', 'dom', 'globalize', 'connectionManager', 'ap
|
||||||
|
|
||||||
function getItemsHtmlFn(section) {
|
function getItemsHtmlFn(section) {
|
||||||
return function (items) {
|
return function (items) {
|
||||||
var supportsImageAnalysis = appHost.supports('imageanalysis');
|
const supportsImageAnalysis = appHost.supports('imageanalysis');
|
||||||
var cardLayout = (appHost.preferVisualCards || supportsImageAnalysis) && section.autoCardLayout && section.showTitle;
|
let cardLayout = (appHost.preferVisualCards || supportsImageAnalysis) && section.autoCardLayout && section.showTitle;
|
||||||
cardLayout = false;
|
cardLayout = false;
|
||||||
var serverId = this.apiClient.serverId();
|
const serverId = this.apiClient.serverId();
|
||||||
var leadingButtons = layoutManager.tv ? [{
|
const leadingButtons = layoutManager.tv ? [{
|
||||||
name: globalize.translate('All'),
|
name: globalize.translate('All'),
|
||||||
id: 'more',
|
id: 'more',
|
||||||
icon: 'favorite',
|
icon: 'favorite',
|
||||||
routeUrl: getRouteUrl(section, serverId)
|
routeUrl: getRouteUrl(section, serverId)
|
||||||
}] : null;
|
}] : null;
|
||||||
var lines = 0;
|
let lines = 0;
|
||||||
|
|
||||||
if (section.showTitle) {
|
if (section.showTitle) {
|
||||||
lines++;
|
lines++;
|
||||||
|
@ -216,23 +226,12 @@ define(['appRouter', 'cardBuilder', 'dom', 'globalize', 'connectionManager', 'ap
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function FavoritesTab(view, params) {
|
|
||||||
this.view = view;
|
|
||||||
this.params = params;
|
|
||||||
this.apiClient = connectionManager.currentApiClient();
|
|
||||||
this.sectionsContainer = view.querySelector('.sections');
|
|
||||||
createSections(this, this.sectionsContainer, this.apiClient);
|
|
||||||
}
|
|
||||||
|
|
||||||
function createSections(instance, elem, apiClient) {
|
function createSections(instance, elem, apiClient) {
|
||||||
var i;
|
const sections = getSections();
|
||||||
var length;
|
let html = '';
|
||||||
var sections = getSections();
|
|
||||||
var html = '';
|
|
||||||
|
|
||||||
for (i = 0, length = sections.length; i < length; i++) {
|
for (const section of sections) {
|
||||||
var section = sections[i];
|
let sectionClass = 'verticalSection';
|
||||||
var sectionClass = 'verticalSection';
|
|
||||||
|
|
||||||
if (!section.showTitle) {
|
if (!section.showTitle) {
|
||||||
sectionClass += ' verticalSection-extrabottompadding';
|
sectionClass += ' verticalSection-extrabottompadding';
|
||||||
|
@ -258,23 +257,32 @@ define(['appRouter', 'cardBuilder', 'dom', 'globalize', 'connectionManager', 'ap
|
||||||
}
|
}
|
||||||
|
|
||||||
elem.innerHTML = html;
|
elem.innerHTML = html;
|
||||||
var elems = elem.querySelectorAll('.itemsContainer');
|
const elems = elem.querySelectorAll('.itemsContainer');
|
||||||
|
|
||||||
for (i = 0, length = elems.length; i < length; i++) {
|
for (let i = 0, length = elems.length; i < length; i++) {
|
||||||
var itemsContainer = elems[i];
|
const itemsContainer = elems[i];
|
||||||
itemsContainer.fetchData = getFetchDataFn(sections[i]).bind(instance);
|
itemsContainer.fetchData = getFetchDataFn(sections[i]).bind(instance);
|
||||||
itemsContainer.getItemsHtml = getItemsHtmlFn(sections[i]).bind(instance);
|
itemsContainer.getItemsHtml = getItemsHtmlFn(sections[i]).bind(instance);
|
||||||
itemsContainer.parentContainer = dom.parentWithClass(itemsContainer, 'verticalSection');
|
itemsContainer.parentContainer = dom.parentWithClass(itemsContainer, 'verticalSection');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FavoritesTab.prototype.onResume = function (options) {
|
class FavoritesTab {
|
||||||
var promises = (this.apiClient, []);
|
constructor(view, params) {
|
||||||
var view = this.view;
|
this.view = view;
|
||||||
var elems = this.sectionsContainer.querySelectorAll('.itemsContainer');
|
this.params = params;
|
||||||
|
this.apiClient = connectionManager.currentApiClient();
|
||||||
|
this.sectionsContainer = view.querySelector('.sections');
|
||||||
|
createSections(this, this.sectionsContainer, this.apiClient);
|
||||||
|
}
|
||||||
|
|
||||||
for (var i = 0, length = elems.length; i < length; i++) {
|
onResume(options) {
|
||||||
promises.push(elems[i].resume(options));
|
const promises = (this.apiClient, []);
|
||||||
|
const view = this.view;
|
||||||
|
const elems = this.sectionsContainer.querySelectorAll('.itemsContainer');
|
||||||
|
|
||||||
|
for (const elem of elems) {
|
||||||
|
promises.push(elem.resume(options));
|
||||||
}
|
}
|
||||||
|
|
||||||
Promise.all(promises).then(function () {
|
Promise.all(promises).then(function () {
|
||||||
|
@ -282,30 +290,32 @@ define(['appRouter', 'cardBuilder', 'dom', 'globalize', 'connectionManager', 'ap
|
||||||
focusManager.autoFocus(view);
|
focusManager.autoFocus(view);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
|
||||||
FavoritesTab.prototype.onPause = function () {
|
onPause() {
|
||||||
var elems = this.sectionsContainer.querySelectorAll('.itemsContainer');
|
const elems = this.sectionsContainer.querySelectorAll('.itemsContainer');
|
||||||
|
|
||||||
for (var i = 0, length = elems.length; i < length; i++) {
|
for (const elem of elems) {
|
||||||
elems[i].pause();
|
elem.pause();
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
FavoritesTab.prototype.destroy = function () {
|
destroy() {
|
||||||
this.view = null;
|
this.view = null;
|
||||||
this.params = null;
|
this.params = null;
|
||||||
this.apiClient = null;
|
this.apiClient = null;
|
||||||
var elems = this.sectionsContainer.querySelectorAll('.itemsContainer');
|
const elems = this.sectionsContainer.querySelectorAll('.itemsContainer');
|
||||||
|
|
||||||
for (var i = 0, length = elems.length; i < length; i++) {
|
for (const elem of elems) {
|
||||||
elems[i].fetchData = null;
|
elem.fetchData = null;
|
||||||
elems[i].getItemsHtml = null;
|
elem.getItemsHtml = null;
|
||||||
elems[i].parentContainer = null;
|
elem.parentContainer = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.sectionsContainer = null;
|
this.sectionsContainer = null;
|
||||||
};
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return FavoritesTab;
|
export default FavoritesTab;
|
||||||
});
|
|
||||||
|
/* eslint-enable indent */
|
||||||
|
|
|
@ -40,7 +40,7 @@ define(['tabbedView', 'globalize', 'require', 'emby-tabs', 'emby-button', 'emby-
|
||||||
var controller = instance.tabControllers[index];
|
var controller = instance.tabControllers[index];
|
||||||
|
|
||||||
if (!controller) {
|
if (!controller) {
|
||||||
controller = new controllerFactory(instance.view.querySelector(".tabContent[data-index='" + index + "']"), instance.params);
|
controller = new controllerFactory.default(instance.view.querySelector(".tabContent[data-index='" + index + "']"), instance.params);
|
||||||
instance.tabControllers[index] = controller;
|
instance.tabControllers[index] = controller;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,27 +1,23 @@
|
||||||
define(['userSettings', 'loading', 'connectionManager', 'apphost', 'layoutManager', 'focusManager', 'homeSections', 'emby-itemscontainer'], function (userSettings, loading, connectionManager, appHost, layoutManager, focusManager, homeSections) {
|
import * as userSettings from 'userSettings';
|
||||||
'use strict';
|
import loading from 'loading';
|
||||||
|
import connectionManager from 'connectionManager';
|
||||||
|
import appHost from 'apphost';
|
||||||
|
import layoutManager from 'layoutManager';
|
||||||
|
import focusManager from 'focusManager';
|
||||||
|
import homeSections from 'homeSections';
|
||||||
|
import 'emby-itemscontainer';
|
||||||
|
|
||||||
function HomeTab(view, params) {
|
class HomeTab {
|
||||||
|
constructor(view, params) {
|
||||||
this.view = view;
|
this.view = view;
|
||||||
this.params = params;
|
this.params = params;
|
||||||
this.apiClient = connectionManager.currentApiClient();
|
this.apiClient = connectionManager.currentApiClient();
|
||||||
this.sectionsContainer = view.querySelector('.sections');
|
this.sectionsContainer = view.querySelector('.sections');
|
||||||
view.querySelector('.sections').addEventListener('settingschange', onHomeScreenSettingsChanged.bind(this));
|
view.querySelector('.sections').addEventListener('settingschange', onHomeScreenSettingsChanged.bind(this));
|
||||||
}
|
}
|
||||||
|
onResume(options) {
|
||||||
function onHomeScreenSettingsChanged() {
|
|
||||||
this.sectionsRendered = false;
|
|
||||||
|
|
||||||
if (!this.paused) {
|
|
||||||
this.onResume({
|
|
||||||
refresh: true
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
HomeTab.prototype.onResume = function (options) {
|
|
||||||
if (this.sectionsRendered) {
|
if (this.sectionsRendered) {
|
||||||
var sectionsContainer = this.sectionsContainer;
|
const sectionsContainer = this.sectionsContainer;
|
||||||
|
|
||||||
if (sectionsContainer) {
|
if (sectionsContainer) {
|
||||||
return homeSections.resume(sectionsContainer, options);
|
return homeSections.resume(sectionsContainer, options);
|
||||||
|
@ -31,8 +27,8 @@ define(['userSettings', 'loading', 'connectionManager', 'apphost', 'layoutManage
|
||||||
}
|
}
|
||||||
|
|
||||||
loading.show();
|
loading.show();
|
||||||
var view = this.view;
|
const view = this.view;
|
||||||
var apiClient = this.apiClient;
|
const apiClient = this.apiClient;
|
||||||
this.destroyHomeSections();
|
this.destroyHomeSections();
|
||||||
this.sectionsRendered = true;
|
this.sectionsRendered = true;
|
||||||
return apiClient.getCurrentUser().then(function (user) {
|
return apiClient.getCurrentUser().then(function (user) {
|
||||||
|
@ -44,31 +40,38 @@ define(['userSettings', 'loading', 'connectionManager', 'apphost', 'layoutManage
|
||||||
loading.hide();
|
loading.hide();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
onPause() {
|
||||||
HomeTab.prototype.onPause = function () {
|
const sectionsContainer = this.sectionsContainer;
|
||||||
var sectionsContainer = this.sectionsContainer;
|
|
||||||
|
|
||||||
if (sectionsContainer) {
|
if (sectionsContainer) {
|
||||||
homeSections.pause(sectionsContainer);
|
homeSections.pause(sectionsContainer);
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
destroy() {
|
||||||
HomeTab.prototype.destroy = function () {
|
|
||||||
this.view = null;
|
this.view = null;
|
||||||
this.params = null;
|
this.params = null;
|
||||||
this.apiClient = null;
|
this.apiClient = null;
|
||||||
this.destroyHomeSections();
|
this.destroyHomeSections();
|
||||||
this.sectionsContainer = null;
|
this.sectionsContainer = null;
|
||||||
};
|
}
|
||||||
|
destroyHomeSections() {
|
||||||
HomeTab.prototype.destroyHomeSections = function () {
|
const sectionsContainer = this.sectionsContainer;
|
||||||
var sectionsContainer = this.sectionsContainer;
|
|
||||||
|
|
||||||
if (sectionsContainer) {
|
if (sectionsContainer) {
|
||||||
homeSections.destroySections(sectionsContainer);
|
homeSections.destroySections(sectionsContainer);
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return HomeTab;
|
function onHomeScreenSettingsChanged() {
|
||||||
});
|
this.sectionsRendered = false;
|
||||||
|
|
||||||
|
if (!this.paused) {
|
||||||
|
this.onResume({
|
||||||
|
refresh: true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default HomeTab;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue