2023-10-01 02:49:36 -04:00
|
|
|
import globalize from 'scripts/globalize';
|
2023-10-02 12:22:36 -04:00
|
|
|
import { DEFAULT_SECTIONS, HomeSectionType } from 'types/homeSectionType';
|
2023-10-01 02:49:36 -04:00
|
|
|
import Dashboard from 'utils/dashboard';
|
|
|
|
|
2023-10-02 12:22:36 -04:00
|
|
|
import { loadRecordings } from './sections/activeRecordings';
|
|
|
|
import { loadLibraryButtons } from './sections/libraryButtons';
|
|
|
|
import { loadLibraryTiles } from './sections/libraryTiles';
|
|
|
|
import { loadLiveTV } from './sections/liveTv';
|
|
|
|
import { loadNextUp } from './sections/nextUp';
|
|
|
|
import { loadRecentlyAdded } from './sections/recentlyAdded';
|
|
|
|
import { loadResume } from './sections/resume';
|
2020-07-14 13:50:37 +01:00
|
|
|
|
2023-10-01 02:49:36 -04:00
|
|
|
import 'elements/emby-button/paper-icon-button-light';
|
|
|
|
import 'elements/emby-itemscontainer/emby-itemscontainer';
|
|
|
|
import 'elements/emby-scroller/emby-scroller';
|
|
|
|
import 'elements/emby-button/emby-button';
|
|
|
|
|
|
|
|
import './homesections.scss';
|
|
|
|
|
2023-04-19 01:56:05 -04:00
|
|
|
export function getDefaultSection(index) {
|
2023-10-02 12:22:36 -04:00
|
|
|
if (index < 0 || index > DEFAULT_SECTIONS.length) return '';
|
|
|
|
return DEFAULT_SECTIONS[index];
|
2023-04-19 01:56:05 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function getAllSectionsToShow(userSettings, sectionCount) {
|
|
|
|
const sections = [];
|
|
|
|
for (let i = 0, length = sectionCount; i < length; i++) {
|
|
|
|
let section = userSettings.get('homesection' + i) || getDefaultSection(i);
|
|
|
|
if (section === 'folders') {
|
|
|
|
section = getDefaultSection(0);
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2023-04-19 01:56:05 -04:00
|
|
|
|
|
|
|
sections.push(section);
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
2023-04-19 01:56:05 -04:00
|
|
|
return sections;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function loadSections(elem, apiClient, user, userSettings) {
|
|
|
|
return getUserViews(apiClient, user.Id).then(function (userViews) {
|
|
|
|
let html = '';
|
|
|
|
|
|
|
|
if (userViews.length) {
|
|
|
|
const sectionCount = 7;
|
|
|
|
for (let i = 0; i < sectionCount; i++) {
|
|
|
|
html += '<div class="verticalSection section' + i + '"></div>';
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
|
|
|
|
2023-04-19 01:56:05 -04:00
|
|
|
elem.innerHTML = html;
|
|
|
|
elem.classList.add('homeSectionsContainer');
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2023-04-19 01:56:05 -04:00
|
|
|
const promises = [];
|
|
|
|
const sections = getAllSectionsToShow(userSettings, sectionCount);
|
|
|
|
for (let i = 0; i < sections.length; i++) {
|
|
|
|
promises.push(loadSection(elem, apiClient, user, userSettings, userViews, sections, i));
|
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
|
2023-09-18 02:14:51 +03:00
|
|
|
return Promise.all(promises)
|
|
|
|
// Timeout for polyfilled CustomElements (webOS 1.2)
|
|
|
|
.then(() => new Promise((resolve) => setTimeout(resolve, 0)))
|
|
|
|
.then(() => {
|
|
|
|
return resume(elem, {
|
|
|
|
refresh: true
|
|
|
|
});
|
2019-01-10 15:39:37 +03:00
|
|
|
});
|
2023-04-19 01:56:05 -04:00
|
|
|
} else {
|
|
|
|
let noLibDescription;
|
2023-07-06 13:39:48 -04:00
|
|
|
if (user.Policy?.IsAdministrator) {
|
2023-04-19 01:56:05 -04:00
|
|
|
noLibDescription = globalize.translate('NoCreatedLibraries', '<br><a id="button-createLibrary" class="button-link">', '</a>');
|
2020-02-19 15:42:48 +01:00
|
|
|
} else {
|
2023-04-19 01:56:05 -04:00
|
|
|
noLibDescription = globalize.translate('AskAdminToCreateLibrary');
|
2020-02-19 15:42:48 +01:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2023-04-19 01:56:05 -04:00
|
|
|
html += '<div class="centerMessage padded-left padded-right">';
|
|
|
|
html += '<h2>' + globalize.translate('MessageNothingHere') + '</h2>';
|
|
|
|
html += '<p>' + noLibDescription + '</p>';
|
|
|
|
html += '</div>';
|
|
|
|
elem.innerHTML = html;
|
2018-10-23 01:05:09 +03:00
|
|
|
|
2023-04-19 01:56:05 -04:00
|
|
|
const createNowLink = elem.querySelector('#button-createLibrary');
|
|
|
|
if (createNowLink) {
|
|
|
|
createNowLink.addEventListener('click', function () {
|
2023-09-25 00:00:36 -04:00
|
|
|
Dashboard.navigate('dashboard/libraries');
|
2023-04-19 01:56:05 -04:00
|
|
|
});
|
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
2023-04-19 01:56:05 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export function destroySections(elem) {
|
|
|
|
const elems = elem.querySelectorAll('.itemsContainer');
|
2023-04-30 19:15:14 +01:00
|
|
|
for (const e of elems) {
|
|
|
|
e.fetchData = null;
|
|
|
|
e.parentContainer = null;
|
|
|
|
e.getItemsHtml = null;
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
2023-04-19 01:56:05 -04:00
|
|
|
elem.innerHTML = '';
|
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2023-04-19 01:56:05 -04:00
|
|
|
export function pause(elem) {
|
|
|
|
const elems = elem.querySelectorAll('.itemsContainer');
|
2023-04-30 19:15:14 +01:00
|
|
|
for (const e of elems) {
|
|
|
|
e.pause();
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2023-04-19 01:56:05 -04:00
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
|
2023-04-19 01:56:05 -04:00
|
|
|
export function resume(elem, options) {
|
|
|
|
const elems = elem.querySelectorAll('.itemsContainer');
|
|
|
|
const promises = [];
|
2018-10-23 01:05:09 +03:00
|
|
|
|
2023-04-19 01:56:05 -04:00
|
|
|
for (let i = 0, length = elems.length; i < length; i++) {
|
|
|
|
promises.push(elems[i].resume(options));
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
2023-04-19 01:56:05 -04:00
|
|
|
return Promise.all(promises);
|
|
|
|
}
|
|
|
|
|
|
|
|
function loadSection(page, apiClient, user, userSettings, userViews, allSections, index) {
|
|
|
|
const section = allSections[index];
|
|
|
|
const elem = page.querySelector('.section' + index);
|
2023-10-02 12:22:36 -04:00
|
|
|
const options = { enableOverflow: enableScrollX() };
|
|
|
|
|
|
|
|
switch (section) {
|
|
|
|
case HomeSectionType.ActiveRecordings:
|
|
|
|
loadRecordings(elem, true, apiClient, options);
|
|
|
|
break;
|
|
|
|
case HomeSectionType.LatestMedia:
|
|
|
|
loadRecentlyAdded(elem, apiClient, user, userViews, options);
|
|
|
|
break;
|
|
|
|
case HomeSectionType.LibraryButtons:
|
|
|
|
loadLibraryButtons(elem, userViews);
|
|
|
|
break;
|
|
|
|
case HomeSectionType.LiveTv:
|
|
|
|
return loadLiveTV(elem, apiClient, user, options);
|
|
|
|
case HomeSectionType.NextUp:
|
|
|
|
loadNextUp(elem, apiClient, userSettings, options);
|
|
|
|
break;
|
|
|
|
case HomeSectionType.Resume:
|
|
|
|
return loadResume(elem, apiClient, 'HeaderContinueWatching', 'Video', userSettings, options);
|
|
|
|
case HomeSectionType.ResumeAudio:
|
|
|
|
return loadResume(elem, apiClient, 'HeaderContinueListening', 'Audio', userSettings, options);
|
|
|
|
case HomeSectionType.ResumeBook:
|
|
|
|
return loadResume(elem, apiClient, 'HeaderContinueReading', 'Book', userSettings, options);
|
|
|
|
case HomeSectionType.SmallLibraryTiles:
|
|
|
|
loadLibraryTiles(elem, userViews, options);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
elem.innerHTML = '';
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2023-10-02 12:22:36 -04:00
|
|
|
|
2023-04-19 01:56:05 -04:00
|
|
|
return Promise.resolve();
|
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
|
2023-04-19 01:56:05 -04:00
|
|
|
function getUserViews(apiClient, userId) {
|
|
|
|
return apiClient.getUserViews({}, userId || apiClient.getCurrentUserId()).then(function (result) {
|
|
|
|
return result.Items;
|
|
|
|
});
|
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
|
2023-04-19 01:56:05 -04:00
|
|
|
function enableScrollX() {
|
|
|
|
return true;
|
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
|
2020-07-14 13:50:37 +01:00
|
|
|
export default {
|
2023-10-02 12:22:36 -04:00
|
|
|
getDefaultSection,
|
|
|
|
loadSections,
|
|
|
|
destroySections,
|
|
|
|
pause,
|
|
|
|
resume
|
2020-07-14 13:50:37 +01:00
|
|
|
};
|
|
|
|
|