2020-03-19 22:33:41 +01:00
|
|
|
/* eslint-disable indent */
|
2020-03-21 03:30:21 +09:00
|
|
|
|
2020-03-19 21:16:40 +01:00
|
|
|
/**
|
2020-03-22 17:12:34 +01:00
|
|
|
* Module for building cards from item data.
|
|
|
|
* @module components/cardBuilder/cardBuilder
|
2020-03-19 21:16:40 +01:00
|
|
|
*/
|
2020-03-21 03:30:21 +09:00
|
|
|
|
2020-03-19 21:15:38 +01:00
|
|
|
import datetime from 'datetime';
|
|
|
|
import imageLoader from 'imageLoader';
|
|
|
|
import connectionManager from 'connectionManager';
|
|
|
|
import itemHelper from 'itemHelper';
|
|
|
|
import focusManager from 'focusManager';
|
|
|
|
import indicators from 'indicators';
|
|
|
|
import globalize from 'globalize';
|
|
|
|
import layoutManager from 'layoutManager';
|
|
|
|
import dom from 'dom';
|
|
|
|
import browser from 'browser';
|
|
|
|
import playbackManager from 'playbackManager';
|
|
|
|
import itemShortcuts from 'itemShortcuts';
|
|
|
|
import imageHelper from 'scripts/imagehelper';
|
|
|
|
import 'css!./card';
|
|
|
|
import 'paper-icon-button-light';
|
|
|
|
import 'programStyles';
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-03-19 22:33:41 +01:00
|
|
|
const enableFocusTransform = !browser.slow && !browser.edge;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-03-19 21:16:40 +01:00
|
|
|
/**
|
2020-03-21 03:30:21 +09:00
|
|
|
* Generate the HTML markup for cards for a set of items.
|
|
|
|
* @param items - The items used to generate cards.
|
2020-03-19 21:16:40 +01:00
|
|
|
* @param options - The options of the cards.
|
2020-03-21 03:30:21 +09:00
|
|
|
* @returns {string} The HTML markup for the cards.
|
2020-03-19 21:16:40 +01:00
|
|
|
*/
|
2020-03-19 21:15:38 +01:00
|
|
|
export function getCardsHtml(items, options) {
|
2019-01-10 15:39:37 +03:00
|
|
|
if (arguments.length === 1) {
|
|
|
|
options = arguments[0];
|
|
|
|
items = options.items;
|
|
|
|
}
|
|
|
|
|
2019-05-13 12:56:44 -07:00
|
|
|
return buildCardsHtmlInternal(items, options);
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
|
|
|
|
2020-03-19 21:16:40 +01:00
|
|
|
/**
|
|
|
|
* Computes the number of posters per row.
|
|
|
|
* @param {string} shape - Shape of the cards.
|
|
|
|
* @param {number} screenWidth - Width of the screen.
|
|
|
|
* @param {boolean} isOrientationLandscape - Flag for the orientation of the screen.
|
2020-03-21 03:30:21 +09:00
|
|
|
* @returns {number} Number of cards per row for an itemsContainer.
|
2020-03-19 21:16:40 +01:00
|
|
|
*/
|
2019-01-10 15:39:37 +03:00
|
|
|
function getPostersPerRow(shape, screenWidth, isOrientationLandscape) {
|
|
|
|
switch (shape) {
|
|
|
|
case 'portrait':
|
|
|
|
if (layoutManager.tv) {
|
|
|
|
return 100 / 16.66666667;
|
|
|
|
}
|
|
|
|
if (screenWidth >= 2200) {
|
|
|
|
return 100 / 10;
|
|
|
|
}
|
|
|
|
if (screenWidth >= 1920) {
|
|
|
|
return 100 / 11.1111111111;
|
|
|
|
}
|
|
|
|
if (screenWidth >= 1600) {
|
|
|
|
return 100 / 12.5;
|
|
|
|
}
|
|
|
|
if (screenWidth >= 1400) {
|
|
|
|
return 100 / 14.28571428571;
|
|
|
|
}
|
|
|
|
if (screenWidth >= 1200) {
|
|
|
|
return 100 / 16.66666667;
|
|
|
|
}
|
|
|
|
if (screenWidth >= 800) {
|
|
|
|
return 5;
|
|
|
|
}
|
|
|
|
if (screenWidth >= 700) {
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
if (screenWidth >= 500) {
|
|
|
|
return 100 / 33.33333333;
|
|
|
|
}
|
|
|
|
return 100 / 33.33333333;
|
|
|
|
case 'square':
|
|
|
|
if (layoutManager.tv) {
|
|
|
|
return 100 / 16.66666667;
|
|
|
|
}
|
|
|
|
if (screenWidth >= 2200) {
|
|
|
|
return 100 / 10;
|
|
|
|
}
|
|
|
|
if (screenWidth >= 1920) {
|
|
|
|
return 100 / 11.1111111111;
|
|
|
|
}
|
|
|
|
if (screenWidth >= 1600) {
|
|
|
|
return 100 / 12.5;
|
|
|
|
}
|
|
|
|
if (screenWidth >= 1400) {
|
|
|
|
return 100 / 14.28571428571;
|
|
|
|
}
|
|
|
|
if (screenWidth >= 1200) {
|
|
|
|
return 100 / 16.66666667;
|
|
|
|
}
|
|
|
|
if (screenWidth >= 800) {
|
|
|
|
return 5;
|
|
|
|
}
|
|
|
|
if (screenWidth >= 700) {
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
if (screenWidth >= 500) {
|
|
|
|
return 100 / 33.33333333;
|
|
|
|
}
|
|
|
|
return 2;
|
|
|
|
case 'banner':
|
|
|
|
if (screenWidth >= 2200) {
|
|
|
|
return 100 / 25;
|
|
|
|
}
|
|
|
|
if (screenWidth >= 1200) {
|
|
|
|
return 100 / 33.33333333;
|
|
|
|
}
|
|
|
|
if (screenWidth >= 800) {
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
case 'backdrop':
|
|
|
|
if (layoutManager.tv) {
|
|
|
|
return 100 / 25;
|
|
|
|
}
|
|
|
|
if (screenWidth >= 2500) {
|
|
|
|
return 6;
|
|
|
|
}
|
|
|
|
if (screenWidth >= 1600) {
|
|
|
|
return 5;
|
|
|
|
}
|
|
|
|
if (screenWidth >= 1200) {
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
if (screenWidth >= 770) {
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
if (screenWidth >= 420) {
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
case 'smallBackdrop':
|
|
|
|
if (screenWidth >= 1600) {
|
|
|
|
return 100 / 12.5;
|
|
|
|
}
|
|
|
|
if (screenWidth >= 1400) {
|
|
|
|
return 100 / 14.2857142857;
|
|
|
|
}
|
|
|
|
if (screenWidth >= 1200) {
|
|
|
|
return 100 / 16.666666666666666666;
|
|
|
|
}
|
|
|
|
if (screenWidth >= 1000) {
|
|
|
|
return 5;
|
|
|
|
}
|
|
|
|
if (screenWidth >= 800) {
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
if (screenWidth >= 500) {
|
|
|
|
return 100 / 33.33333333;
|
|
|
|
}
|
|
|
|
return 2;
|
|
|
|
case 'overflowSmallBackdrop':
|
|
|
|
if (layoutManager.tv) {
|
|
|
|
return 100 / 18.9;
|
|
|
|
}
|
|
|
|
if (isOrientationLandscape) {
|
|
|
|
if (screenWidth >= 800) {
|
|
|
|
return 100 / 15.5;
|
|
|
|
}
|
|
|
|
return 100 / 23.3;
|
|
|
|
} else {
|
|
|
|
if (screenWidth >= 540) {
|
|
|
|
return 100 / 30;
|
|
|
|
}
|
|
|
|
return 100 / 72;
|
|
|
|
}
|
|
|
|
case 'overflowPortrait':
|
|
|
|
|
|
|
|
if (layoutManager.tv) {
|
|
|
|
return 100 / 15.5;
|
|
|
|
}
|
|
|
|
if (isOrientationLandscape) {
|
|
|
|
if (screenWidth >= 1700) {
|
|
|
|
return 100 / 11.6;
|
|
|
|
}
|
|
|
|
return 100 / 15.5;
|
|
|
|
} else {
|
|
|
|
if (screenWidth >= 1400) {
|
|
|
|
return 100 / 15;
|
|
|
|
}
|
|
|
|
if (screenWidth >= 1200) {
|
|
|
|
return 100 / 18;
|
|
|
|
}
|
|
|
|
if (screenWidth >= 760) {
|
|
|
|
return 100 / 23;
|
|
|
|
}
|
|
|
|
if (screenWidth >= 400) {
|
|
|
|
return 100 / 31.5;
|
|
|
|
}
|
|
|
|
return 100 / 42;
|
|
|
|
}
|
|
|
|
case 'overflowSquare':
|
|
|
|
if (layoutManager.tv) {
|
|
|
|
return 100 / 15.5;
|
|
|
|
}
|
|
|
|
if (isOrientationLandscape) {
|
|
|
|
if (screenWidth >= 1700) {
|
|
|
|
return 100 / 11.6;
|
|
|
|
}
|
|
|
|
return 100 / 15.5;
|
|
|
|
} else {
|
|
|
|
if (screenWidth >= 1400) {
|
|
|
|
return 100 / 15;
|
|
|
|
}
|
|
|
|
if (screenWidth >= 1200) {
|
|
|
|
return 100 / 18;
|
|
|
|
}
|
|
|
|
if (screenWidth >= 760) {
|
|
|
|
return 100 / 23;
|
|
|
|
}
|
|
|
|
if (screenWidth >= 540) {
|
|
|
|
return 100 / 31.5;
|
|
|
|
}
|
|
|
|
return 100 / 42;
|
|
|
|
}
|
|
|
|
case 'overflowBackdrop':
|
|
|
|
if (layoutManager.tv) {
|
|
|
|
return 100 / 23.3;
|
|
|
|
}
|
|
|
|
if (isOrientationLandscape) {
|
|
|
|
if (screenWidth >= 1700) {
|
|
|
|
return 100 / 18.5;
|
|
|
|
}
|
|
|
|
return 100 / 23.3;
|
|
|
|
} else {
|
|
|
|
if (screenWidth >= 1800) {
|
|
|
|
return 100 / 23.5;
|
|
|
|
}
|
|
|
|
if (screenWidth >= 1400) {
|
|
|
|
return 100 / 30;
|
|
|
|
}
|
|
|
|
if (screenWidth >= 760) {
|
|
|
|
return 100 / 40;
|
|
|
|
}
|
|
|
|
if (screenWidth >= 640) {
|
|
|
|
return 100 / 56;
|
|
|
|
}
|
|
|
|
return 100 / 72;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-19 21:16:40 +01:00
|
|
|
/**
|
|
|
|
* Checks if the window is resizable.
|
2020-03-21 03:30:21 +09:00
|
|
|
* @param {number} windowWidth - Width of the device's screen.
|
2020-03-19 21:16:40 +01:00
|
|
|
* @returns {boolean} - Result of the check.
|
|
|
|
*/
|
2019-01-10 15:39:37 +03:00
|
|
|
function isResizable(windowWidth) {
|
2020-03-19 22:33:41 +01:00
|
|
|
const screen = window.screen;
|
2019-01-10 15:39:37 +03:00
|
|
|
if (screen) {
|
2020-03-19 22:33:41 +01:00
|
|
|
const screenWidth = screen.availWidth;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
if ((screenWidth - windowWidth) > 20) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-03-19 21:16:40 +01:00
|
|
|
/**
|
|
|
|
* Gets the width of a card's image according to the shape and amount of cards per row.
|
|
|
|
* @param {string} shape - Shape of the card.
|
|
|
|
* @param {number} screenWidth - Width of the screen.
|
|
|
|
* @param {boolean} isOrientationLandscape - Flag for the orientation of the screen.
|
|
|
|
* @returns {number} Width of the image for a card.
|
|
|
|
*/
|
2019-01-10 15:39:37 +03:00
|
|
|
function getImageWidth(shape, screenWidth, isOrientationLandscape) {
|
2020-03-19 22:33:41 +01:00
|
|
|
const imagesPerRow = getPostersPerRow(shape, screenWidth, isOrientationLandscape);
|
2020-03-19 21:16:40 +01:00
|
|
|
return Math.round(screenWidth / imagesPerRow) * 2;
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
|
|
|
|
2020-03-19 21:16:40 +01:00
|
|
|
/**
|
2020-03-21 03:30:21 +09:00
|
|
|
* Normalizes the options for a card.
|
2020-03-19 21:16:40 +01:00
|
|
|
* @param {Object} items - A set of items.
|
|
|
|
* @param {Object} options - Options for handling the items.
|
|
|
|
*/
|
2019-01-10 15:39:37 +03:00
|
|
|
function setCardData(items, options) {
|
2020-05-04 12:44:12 +02:00
|
|
|
options.shape = options.shape || 'auto';
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-03-19 22:33:41 +01:00
|
|
|
const primaryImageAspectRatio = imageLoader.getPrimaryImageAspectRatio(items);
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-03-19 22:33:41 +01:00
|
|
|
if (['auto', 'autohome', 'autooverflow', 'autoVertical'].includes(options.shape)) {
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-03-19 22:33:41 +01:00
|
|
|
const requestedShape = options.shape;
|
2019-01-10 15:39:37 +03:00
|
|
|
options.shape = null;
|
|
|
|
|
|
|
|
if (primaryImageAspectRatio) {
|
|
|
|
|
|
|
|
if (primaryImageAspectRatio >= 3) {
|
|
|
|
options.shape = 'banner';
|
|
|
|
options.coverImage = true;
|
|
|
|
} else if (primaryImageAspectRatio >= 1.33) {
|
|
|
|
options.shape = requestedShape === 'autooverflow' ? 'overflowBackdrop' : 'backdrop';
|
|
|
|
} else if (primaryImageAspectRatio > 0.71) {
|
|
|
|
options.shape = requestedShape === 'autooverflow' ? 'overflowSquare' : 'square';
|
|
|
|
} else {
|
|
|
|
options.shape = requestedShape === 'autooverflow' ? 'overflowPortrait' : 'portrait';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!options.shape) {
|
|
|
|
options.shape = options.defaultShape || (requestedShape === 'autooverflow' ? 'overflowSquare' : 'square');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.preferThumb === 'auto') {
|
|
|
|
options.preferThumb = options.shape === 'backdrop' || options.shape === 'overflowBackdrop';
|
|
|
|
}
|
|
|
|
|
|
|
|
options.uiAspect = getDesiredAspect(options.shape);
|
|
|
|
options.primaryImageAspectRatio = primaryImageAspectRatio;
|
|
|
|
|
|
|
|
if (!options.width && options.widths) {
|
|
|
|
options.width = options.widths[options.shape];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.rows && typeof (options.rows) !== 'number') {
|
|
|
|
options.rows = options.rows[options.shape];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!options.width) {
|
2020-03-19 22:33:41 +01:00
|
|
|
let screenWidth = dom.getWindowSize().innerWidth;
|
|
|
|
const screenHeight = dom.getWindowSize().innerHeight;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
if (isResizable(screenWidth)) {
|
2020-03-19 22:33:41 +01:00
|
|
|
const roundScreenTo = 100;
|
2019-01-10 15:39:37 +03:00
|
|
|
screenWidth = Math.floor(screenWidth / roundScreenTo) * roundScreenTo;
|
|
|
|
}
|
|
|
|
|
|
|
|
options.width = getImageWidth(options.shape, screenWidth, screenWidth > (screenHeight * 1.3));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-19 21:16:40 +01:00
|
|
|
/**
|
|
|
|
* Generates the internal HTML markup for cards.
|
|
|
|
* @param {Object} items - Items for which to generate the markup.
|
|
|
|
* @param {Object} options - Options for generating the markup.
|
|
|
|
* @returns {string} The internal HTML markup of the cards.
|
|
|
|
*/
|
2019-01-10 15:39:37 +03:00
|
|
|
function buildCardsHtmlInternal(items, options) {
|
2020-03-19 22:33:41 +01:00
|
|
|
let isVertical = false;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
if (options.shape === 'autoVertical') {
|
|
|
|
isVertical = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
setCardData(items, options);
|
|
|
|
|
2020-03-19 22:33:41 +01:00
|
|
|
let html = '';
|
|
|
|
let itemsInRow = 0;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-03-19 22:33:41 +01:00
|
|
|
let currentIndexValue;
|
|
|
|
let hasOpenRow;
|
|
|
|
let hasOpenSection;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-03-19 22:33:41 +01:00
|
|
|
let sectionTitleTagName = options.sectionTitleTagName || 'div';
|
|
|
|
let apiClient;
|
|
|
|
let lastServerId;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-03-19 22:33:41 +01:00
|
|
|
for (let i = 0; i < items.length; i++) {
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-03-19 22:33:41 +01:00
|
|
|
let item = items[i];
|
|
|
|
let serverId = item.ServerId || options.serverId;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
if (serverId !== lastServerId) {
|
|
|
|
lastServerId = serverId;
|
|
|
|
apiClient = connectionManager.getApiClient(lastServerId);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.indexBy) {
|
2020-03-19 22:33:41 +01:00
|
|
|
let newIndexValue = '';
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
if (options.indexBy === 'PremiereDate') {
|
|
|
|
if (item.PremiereDate) {
|
|
|
|
try {
|
|
|
|
newIndexValue = datetime.toLocaleDateString(datetime.parseISO8601Date(item.PremiereDate), { weekday: 'long', month: 'long', day: 'numeric' });
|
2020-03-19 22:33:41 +01:00
|
|
|
} catch (error) {
|
|
|
|
console.error('error parsing timestamp for premiere date', error);
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
|
|
|
}
|
2019-11-23 00:29:38 +09:00
|
|
|
} else if (options.indexBy === 'ProductionYear') {
|
2019-01-10 15:39:37 +03:00
|
|
|
newIndexValue = item.ProductionYear;
|
2019-11-23 00:29:38 +09:00
|
|
|
} else if (options.indexBy === 'CommunityRating') {
|
2019-01-10 15:39:37 +03:00
|
|
|
newIndexValue = item.CommunityRating ? (Math.floor(item.CommunityRating) + (item.CommunityRating % 1 >= 0.5 ? 0.5 : 0)) + '+' : null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (newIndexValue !== currentIndexValue) {
|
|
|
|
|
|
|
|
if (hasOpenRow) {
|
|
|
|
html += '</div>';
|
|
|
|
hasOpenRow = false;
|
|
|
|
itemsInRow = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hasOpenSection) {
|
|
|
|
|
|
|
|
html += '</div>';
|
|
|
|
|
|
|
|
if (isVertical) {
|
|
|
|
html += '</div>';
|
|
|
|
}
|
|
|
|
hasOpenSection = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isVertical) {
|
|
|
|
html += '<div class="verticalSection">';
|
|
|
|
} else {
|
|
|
|
html += '<div class="horizontalSection">';
|
|
|
|
}
|
|
|
|
html += '<' + sectionTitleTagName + ' class="sectionTitle">' + newIndexValue + '</' + sectionTitleTagName + '>';
|
|
|
|
if (isVertical) {
|
|
|
|
html += '<div class="itemsContainer vertical-wrap">';
|
|
|
|
}
|
|
|
|
currentIndexValue = newIndexValue;
|
|
|
|
hasOpenSection = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.rows && itemsInRow === 0) {
|
|
|
|
|
|
|
|
if (hasOpenRow) {
|
|
|
|
html += '</div>';
|
|
|
|
hasOpenRow = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
html += '<div class="cardColumn">';
|
|
|
|
hasOpenRow = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
html += buildCard(i, item, apiClient, options);
|
|
|
|
|
|
|
|
itemsInRow++;
|
|
|
|
|
|
|
|
if (options.rows && itemsInRow >= options.rows) {
|
|
|
|
html += '</div>';
|
|
|
|
hasOpenRow = false;
|
|
|
|
itemsInRow = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hasOpenRow) {
|
|
|
|
html += '</div>';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hasOpenSection) {
|
|
|
|
html += '</div>';
|
|
|
|
|
|
|
|
if (isVertical) {
|
|
|
|
html += '</div>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return html;
|
|
|
|
}
|
|
|
|
|
2020-03-19 21:16:40 +01:00
|
|
|
/**
|
2020-03-21 03:30:21 +09:00
|
|
|
* Computes the aspect ratio for a card given its shape.
|
2020-03-19 21:16:40 +01:00
|
|
|
* @param {string} shape - Shape for which to get the aspect ratio.
|
|
|
|
* @returns {null|number} Ratio of the shape.
|
|
|
|
*/
|
2019-01-10 15:39:37 +03:00
|
|
|
function getDesiredAspect(shape) {
|
|
|
|
if (shape) {
|
|
|
|
shape = shape.toLowerCase();
|
|
|
|
if (shape.indexOf('portrait') !== -1) {
|
|
|
|
return (2 / 3);
|
|
|
|
}
|
|
|
|
if (shape.indexOf('backdrop') !== -1) {
|
|
|
|
return (16 / 9);
|
|
|
|
}
|
|
|
|
if (shape.indexOf('square') !== -1) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (shape.indexOf('banner') !== -1) {
|
|
|
|
return (1000 / 185);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2020-03-22 18:00:03 +01:00
|
|
|
/** Get the URL of the card's image.
|
2020-03-19 21:16:40 +01:00
|
|
|
* @param {Object} item - Item for which to generate a card.
|
2020-03-21 03:30:21 +09:00
|
|
|
* @param {Object} apiClient - API client object.
|
|
|
|
* @param {Object} options - Options of the card.
|
2020-03-19 21:16:40 +01:00
|
|
|
* @param {string} shape - Shape of the desired image.
|
2020-03-22 17:12:34 +01:00
|
|
|
* @returns {Object} Object representing the URL of the card's image.
|
2020-03-19 21:16:40 +01:00
|
|
|
*/
|
2019-01-10 15:39:37 +03:00
|
|
|
function getCardImageUrl(item, apiClient, options, shape) {
|
2020-03-19 22:33:41 +01:00
|
|
|
item = item.ProgramInfo || item;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-03-19 22:33:41 +01:00
|
|
|
const width = options.width;
|
|
|
|
let height = null;
|
|
|
|
const primaryImageAspectRatio = item.PrimaryImageAspectRatio;
|
|
|
|
let forceName = false;
|
|
|
|
let imgUrl = null;
|
2020-05-26 01:29:29 +03:00
|
|
|
let imgTag = null;
|
2020-03-19 22:33:41 +01:00
|
|
|
let coverImage = false;
|
|
|
|
let uiAspect = null;
|
2020-05-27 19:24:51 +02:00
|
|
|
let imgType = null;
|
2020-06-02 22:02:13 +02:00
|
|
|
let itemId = null;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
if (options.preferThumb && item.ImageTags && item.ImageTags.Thumb) {
|
2020-05-26 01:29:29 +03:00
|
|
|
imgType = 'Thumb';
|
2020-05-26 14:03:59 +02:00
|
|
|
imgTag = item.ImageTags.Thumb;
|
2019-01-10 15:39:37 +03:00
|
|
|
} else if ((options.preferBanner || shape === 'banner') && item.ImageTags && item.ImageTags.Banner) {
|
2020-05-26 01:29:29 +03:00
|
|
|
imgType = 'Banner';
|
2020-05-26 14:03:59 +02:00
|
|
|
imgTag = item.ImageTags.Banner;
|
2019-01-10 15:39:37 +03:00
|
|
|
} else if (options.preferDisc && item.ImageTags && item.ImageTags.Disc) {
|
2020-05-26 01:29:29 +03:00
|
|
|
imgType = 'Disc';
|
2020-05-26 14:03:59 +02:00
|
|
|
imgTag = item.ImageTags.Disc;
|
2019-01-10 15:39:37 +03:00
|
|
|
} else if (options.preferLogo && item.ImageTags && item.ImageTags.Logo) {
|
2020-05-26 01:29:29 +03:00
|
|
|
imgType = 'Logo';
|
2020-05-26 14:03:59 +02:00
|
|
|
imgTag = item.ImageTags.Logo;
|
2019-01-10 15:39:37 +03:00
|
|
|
} else if (options.preferLogo && item.ParentLogoImageTag && item.ParentLogoItemId) {
|
2020-05-26 01:29:29 +03:00
|
|
|
imgType = 'Logo';
|
|
|
|
imgTag = item.ParentLogoImageTag;
|
2020-06-02 22:02:13 +02:00
|
|
|
itemId = item.ParentLogoItemId;
|
2019-01-10 15:39:37 +03:00
|
|
|
} else if (options.preferThumb && item.SeriesThumbImageTag && options.inheritThumb !== false) {
|
2020-05-26 01:29:29 +03:00
|
|
|
imgType = 'Thumb';
|
|
|
|
imgTag = item.SeriesThumbImageTag;
|
2020-06-02 22:02:13 +02:00
|
|
|
itemId = item.SeriesId;
|
2019-01-10 15:39:37 +03:00
|
|
|
} else if (options.preferThumb && item.ParentThumbItemId && options.inheritThumb !== false && item.MediaType !== 'Photo') {
|
2020-05-26 01:29:29 +03:00
|
|
|
imgType = 'Thumb';
|
|
|
|
imgTag = item.ParentThumbImageTag;
|
2020-06-02 22:02:13 +02:00
|
|
|
itemId = item.ParentThumbItemId;
|
2019-01-10 15:39:37 +03:00
|
|
|
} else if (options.preferThumb && item.BackdropImageTags && item.BackdropImageTags.length) {
|
2020-05-26 01:29:29 +03:00
|
|
|
imgType = 'Backdrop';
|
|
|
|
imgTag = item.BackdropImageTags[0];
|
2019-01-10 15:39:37 +03:00
|
|
|
forceName = true;
|
|
|
|
} else if (options.preferThumb && item.ParentBackdropImageTags && item.ParentBackdropImageTags.length && options.inheritThumb !== false && item.Type === 'Episode') {
|
2020-05-26 01:29:29 +03:00
|
|
|
imgType = 'Backdrop';
|
|
|
|
imgTag = item.ParentBackdropImageTags[0];
|
2020-06-02 22:02:13 +02:00
|
|
|
itemId = item.ParentBackdropItemId;
|
2019-01-10 15:39:37 +03:00
|
|
|
} else if (item.ImageTags && item.ImageTags.Primary) {
|
2020-05-26 01:29:29 +03:00
|
|
|
imgType = 'Primary';
|
2020-05-26 14:03:59 +02:00
|
|
|
imgTag = item.ImageTags.Primary;
|
2019-01-10 15:39:37 +03:00
|
|
|
height = width && primaryImageAspectRatio ? Math.round(width / primaryImageAspectRatio) : null;
|
|
|
|
|
|
|
|
if (options.preferThumb && options.showTitle !== false) {
|
|
|
|
forceName = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (primaryImageAspectRatio) {
|
|
|
|
uiAspect = getDesiredAspect(shape);
|
|
|
|
if (uiAspect) {
|
|
|
|
coverImage = (Math.abs(primaryImageAspectRatio - uiAspect) / uiAspect) <= 0.2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (item.PrimaryImageTag) {
|
2020-05-26 01:29:29 +03:00
|
|
|
imgType = 'Primary';
|
|
|
|
imgTag = item.PrimaryImageTag;
|
2020-06-02 22:02:13 +02:00
|
|
|
itemId = item.PrimaryImageItemId;
|
2019-01-10 15:39:37 +03:00
|
|
|
height = width && primaryImageAspectRatio ? Math.round(width / primaryImageAspectRatio) : null;
|
|
|
|
|
|
|
|
if (options.preferThumb && options.showTitle !== false) {
|
|
|
|
forceName = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (primaryImageAspectRatio) {
|
|
|
|
uiAspect = getDesiredAspect(shape);
|
|
|
|
if (uiAspect) {
|
|
|
|
coverImage = (Math.abs(primaryImageAspectRatio - uiAspect) / uiAspect) <= 0.2;
|
|
|
|
}
|
|
|
|
}
|
2019-11-23 00:29:38 +09:00
|
|
|
} else if (item.ParentPrimaryImageTag) {
|
2020-05-26 01:29:29 +03:00
|
|
|
imgType = 'Primary';
|
|
|
|
imgTag = item.ParentPrimaryImageTag;
|
2020-06-02 22:02:13 +02:00
|
|
|
itemId = item.ParentPrimaryImageItemId;
|
2019-11-23 00:29:38 +09:00
|
|
|
} else if (item.SeriesPrimaryImageTag) {
|
2020-05-26 01:29:29 +03:00
|
|
|
imgType = 'Primary';
|
|
|
|
imgTag = item.SeriesPrimaryImageTag;
|
2020-06-02 22:02:13 +02:00
|
|
|
itemId = item.SeriesId;
|
2019-11-23 00:29:38 +09:00
|
|
|
} else if (item.AlbumId && item.AlbumPrimaryImageTag) {
|
2020-05-26 01:29:29 +03:00
|
|
|
imgType = 'Primary';
|
|
|
|
imgTag = item.AlbumPrimaryImageTag;
|
2020-06-02 22:02:13 +02:00
|
|
|
itemId = item.AlbumId;
|
2020-03-11 21:31:04 +01:00
|
|
|
height = width && primaryImageAspectRatio ? Math.round(width / primaryImageAspectRatio) : null;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
if (primaryImageAspectRatio) {
|
|
|
|
uiAspect = getDesiredAspect(shape);
|
|
|
|
if (uiAspect) {
|
|
|
|
coverImage = (Math.abs(primaryImageAspectRatio - uiAspect) / uiAspect) <= 0.2;
|
|
|
|
}
|
|
|
|
}
|
2019-11-23 00:29:38 +09:00
|
|
|
} else if (item.Type === 'Season' && item.ImageTags && item.ImageTags.Thumb) {
|
2020-05-26 01:29:29 +03:00
|
|
|
imgType = 'Thumb';
|
2020-05-26 14:03:59 +02:00
|
|
|
imgTag = item.ImageTags.Thumb;
|
2019-11-23 00:29:38 +09:00
|
|
|
} else if (item.BackdropImageTags && item.BackdropImageTags.length) {
|
2020-05-26 01:29:29 +03:00
|
|
|
imgType = 'Backdrop';
|
|
|
|
imgTag = item.BackdropImageTags[0];
|
2019-01-10 15:39:37 +03:00
|
|
|
} else if (item.ImageTags && item.ImageTags.Thumb) {
|
2020-05-26 01:29:29 +03:00
|
|
|
imgType = 'Thumb';
|
2020-05-26 14:03:59 +02:00
|
|
|
imgTag = item.ImageTags.Thumb;
|
2019-01-10 15:39:37 +03:00
|
|
|
} else if (item.SeriesThumbImageTag && options.inheritThumb !== false) {
|
2020-05-26 01:29:29 +03:00
|
|
|
imgType = 'Thumb';
|
|
|
|
imgTag = item.SeriesThumbImageTag;
|
2020-06-02 22:02:13 +02:00
|
|
|
itemId = item.SeriesId;
|
2019-01-10 15:39:37 +03:00
|
|
|
} else if (item.ParentThumbItemId && options.inheritThumb !== false) {
|
2020-05-26 01:29:29 +03:00
|
|
|
imgType = 'Thumb';
|
|
|
|
imgTag = item.ParentThumbImageTag;
|
2020-06-02 22:02:13 +02:00
|
|
|
itemId = item.ParentThumbItemId;
|
2019-01-10 15:39:37 +03:00
|
|
|
} else if (item.ParentBackdropImageTags && item.ParentBackdropImageTags.length && options.inheritThumb !== false) {
|
2020-05-26 01:29:29 +03:00
|
|
|
imgType = 'Backdrop';
|
|
|
|
imgTag = item.ParentBackdropImageTags[0];
|
2020-06-02 22:02:13 +02:00
|
|
|
itemId = item.ParentBackdropItemId;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (itemId === null) {
|
|
|
|
itemId = item.Id;
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
|
|
|
|
2020-05-26 14:48:34 +02:00
|
|
|
if (imgTag && imgType) {
|
2020-06-02 22:02:13 +02:00
|
|
|
imgUrl = apiClient.getScaledImageUrl(itemId, {
|
2020-05-26 14:48:34 +02:00
|
|
|
type: imgType,
|
|
|
|
maxHeight: height,
|
|
|
|
maxWidth: width,
|
|
|
|
tag: imgTag
|
|
|
|
});
|
|
|
|
}
|
2020-05-23 18:35:34 +02:00
|
|
|
|
2020-05-27 19:19:33 +03:00
|
|
|
let blurHashes = options.imageBlurhashes || item.ImageBlurHashes || {};
|
|
|
|
|
2019-01-10 15:39:37 +03:00
|
|
|
return {
|
|
|
|
imgUrl: imgUrl,
|
2020-05-27 19:24:51 +02:00
|
|
|
blurhash: (blurHashes[imgType] || {})[imgTag],
|
2019-01-10 15:39:37 +03:00
|
|
|
forceName: forceName,
|
|
|
|
coverImage: coverImage
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-03-19 21:16:40 +01:00
|
|
|
/**
|
2020-03-21 03:30:21 +09:00
|
|
|
* Generates a random integer in a given range.
|
2020-03-19 21:16:40 +01:00
|
|
|
* @param {number} min - Minimum of the range.
|
|
|
|
* @param {number} max - Maximum of the range.
|
|
|
|
* @returns {number} Randomly generated number.
|
|
|
|
*/
|
2019-01-10 15:39:37 +03:00
|
|
|
function getRandomInt(min, max) {
|
|
|
|
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
|
|
}
|
|
|
|
|
2020-03-19 21:16:40 +01:00
|
|
|
/**
|
2020-03-21 03:30:21 +09:00
|
|
|
* Generates an index used to select the default color of a card based on a string.
|
2020-03-19 21:16:40 +01:00
|
|
|
* @param {string} str - String to use for generating the index.
|
|
|
|
* @returns {number} Index of the color.
|
|
|
|
*/
|
2019-01-10 15:39:37 +03:00
|
|
|
function getDefaultColorIndex(str) {
|
2020-03-19 22:33:41 +01:00
|
|
|
const numRandomColors = 5;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
if (str) {
|
2020-03-19 22:33:41 +01:00
|
|
|
const charIndex = Math.floor(str.length / 2);
|
|
|
|
const character = String(str.substr(charIndex, 1).charCodeAt());
|
|
|
|
let sum = 0;
|
|
|
|
for (let i = 0; i < character.length; i++) {
|
2019-01-10 15:39:37 +03:00
|
|
|
sum += parseInt(character.charAt(i));
|
|
|
|
}
|
2020-03-19 22:33:41 +01:00
|
|
|
let index = String(sum).substr(-1);
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
return (index % numRandomColors) + 1;
|
|
|
|
} else {
|
|
|
|
return getRandomInt(1, numRandomColors);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-19 21:16:40 +01:00
|
|
|
/**
|
|
|
|
* Generates the HTML markup for a card's text.
|
|
|
|
* @param {Array} lines - Array containing the text lines.
|
|
|
|
* @param {string} cssClass - Base CSS class to use for the lines.
|
|
|
|
* @param {boolean} forceLines - Flag to force the rendering of all lines.
|
|
|
|
* @param {boolean} isOuterFooter - Flag to mark the text lines as outer footer.
|
|
|
|
* @param {string} cardLayout - DEPRECATED
|
|
|
|
* @param {boolean} addRightMargin - Flag to add a right margin to the text.
|
|
|
|
* @param {number} maxLines - Maximum number of lines to render.
|
2020-03-21 03:30:21 +09:00
|
|
|
* @returns {string} HTML markup for the card's text.
|
2020-03-19 21:16:40 +01:00
|
|
|
*/
|
2019-01-10 15:39:37 +03:00
|
|
|
function getCardTextLines(lines, cssClass, forceLines, isOuterFooter, cardLayout, addRightMargin, maxLines) {
|
2020-03-19 22:33:41 +01:00
|
|
|
let html = '';
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-03-19 22:33:41 +01:00
|
|
|
let valid = 0;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-03-19 22:33:41 +01:00
|
|
|
for (let i = 0; i < lines.length; i++) {
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-03-19 22:33:41 +01:00
|
|
|
let currentCssClass = cssClass;
|
|
|
|
let text = lines[i];
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
if (valid > 0 && isOuterFooter) {
|
|
|
|
currentCssClass += ' cardText-secondary';
|
|
|
|
} else if (valid === 0 && isOuterFooter) {
|
|
|
|
currentCssClass += ' cardText-first';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (addRightMargin) {
|
|
|
|
currentCssClass += ' cardText-rightmargin';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (text) {
|
|
|
|
html += "<div class='" + currentCssClass + "'>";
|
|
|
|
html += text;
|
2020-05-04 12:44:12 +02:00
|
|
|
html += '</div>';
|
2019-01-10 15:39:37 +03:00
|
|
|
valid++;
|
|
|
|
|
|
|
|
if (maxLines && valid >= maxLines) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (forceLines) {
|
|
|
|
|
2020-03-19 22:33:41 +01:00
|
|
|
let linesLength = maxLines || Math.min(lines.length, maxLines || lines.length);
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-03-19 22:33:41 +01:00
|
|
|
while (valid < linesLength) {
|
2019-01-10 15:39:37 +03:00
|
|
|
html += "<div class='" + cssClass + "'> </div>";
|
|
|
|
valid++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return html;
|
|
|
|
}
|
|
|
|
|
2020-03-19 21:16:40 +01:00
|
|
|
/**
|
2020-03-21 03:30:21 +09:00
|
|
|
* Determines if the item is live TV.
|
|
|
|
* @param {Object} item - Item to use for the check.
|
|
|
|
* @returns {boolean} Flag showing if the item is live TV.
|
2020-03-19 21:16:40 +01:00
|
|
|
*/
|
2019-01-10 15:39:37 +03:00
|
|
|
function isUsingLiveTvNaming(item) {
|
|
|
|
return item.Type === 'Program' || item.Type === 'Timer' || item.Type === 'Recording';
|
|
|
|
}
|
|
|
|
|
2020-03-19 21:16:40 +01:00
|
|
|
/**
|
|
|
|
* Returns the air time text for the item based on the given times.
|
|
|
|
* @param {object} item - Item used to generate the air time text.
|
|
|
|
* @param {string} showAirDateTime - ISO8601 date for the start of the show.
|
|
|
|
* @param {string} showAirEndTime - ISO8601 date for the end of the show.
|
2020-03-21 03:30:21 +09:00
|
|
|
* @returns {string} The air time text for the item based on the given dates.
|
2020-03-19 21:16:40 +01:00
|
|
|
*/
|
2019-01-10 15:39:37 +03:00
|
|
|
function getAirTimeText(item, showAirDateTime, showAirEndTime) {
|
2020-03-19 22:33:41 +01:00
|
|
|
let airTimeText = '';
|
|
|
|
|
2019-01-10 15:39:37 +03:00
|
|
|
if (item.StartDate) {
|
|
|
|
|
|
|
|
try {
|
2020-03-19 22:33:41 +01:00
|
|
|
let date = datetime.parseISO8601Date(item.StartDate);
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
if (showAirDateTime) {
|
|
|
|
airTimeText += datetime.toLocaleDateString(date, { weekday: 'short', month: 'short', day: 'numeric' }) + ' ';
|
|
|
|
}
|
|
|
|
|
|
|
|
airTimeText += datetime.getDisplayTime(date);
|
|
|
|
|
|
|
|
if (item.EndDate && showAirEndTime) {
|
|
|
|
date = datetime.parseISO8601Date(item.EndDate);
|
|
|
|
airTimeText += ' - ' + datetime.getDisplayTime(date);
|
|
|
|
}
|
2019-11-23 00:29:38 +09:00
|
|
|
} catch (e) {
|
2020-05-04 12:44:12 +02:00
|
|
|
console.error('error parsing date: ' + item.StartDate);
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return airTimeText;
|
|
|
|
}
|
|
|
|
|
2020-03-19 21:16:40 +01:00
|
|
|
/**
|
|
|
|
* Generates the HTML markup for the card's footer text.
|
|
|
|
* @param {Object} item - Item used to generate the footer text.
|
2020-03-21 03:30:21 +09:00
|
|
|
* @param {Object} apiClient - API client instance.
|
2020-03-19 21:16:40 +01:00
|
|
|
* @param {Object} options - Options used to generate the footer text.
|
2020-03-22 17:12:34 +01:00
|
|
|
* @param {string} showTitle - Flag to show the title in the footer.
|
2020-03-19 21:16:40 +01:00
|
|
|
* @param {boolean} forceName - Flag to force showing the name of the item.
|
|
|
|
* @param {boolean} overlayText - Flag to show overlay text.
|
2020-03-22 17:12:34 +01:00
|
|
|
* @param {Object} imgUrl - Object representing the card's image URL.
|
|
|
|
* @param {string} footerClass - CSS classes of the footer element.
|
|
|
|
* @param {string} progressHtml - HTML markup of the progress bar element.
|
2020-03-19 21:16:40 +01:00
|
|
|
* @param {string} logoUrl - URL of the logo for the item.
|
|
|
|
* @param {boolean} isOuterFooter - Flag to mark the text as outer footer.
|
2020-03-22 17:12:34 +01:00
|
|
|
* @returns {string} HTML markup of the card's footer text element.
|
2020-03-19 21:16:40 +01:00
|
|
|
*/
|
2019-01-10 15:39:37 +03:00
|
|
|
function getCardFooterText(item, apiClient, options, showTitle, forceName, overlayText, imgUrl, footerClass, progressHtml, logoUrl, isOuterFooter) {
|
2020-03-19 22:33:41 +01:00
|
|
|
let html = '';
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
if (logoUrl) {
|
|
|
|
html += '<div class="lazy cardFooterLogo" data-src="' + logoUrl + '"></div>';
|
|
|
|
}
|
|
|
|
|
2020-03-19 22:33:41 +01:00
|
|
|
const showOtherText = isOuterFooter ? !overlayText : overlayText;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
if (isOuterFooter && options.cardLayout && layoutManager.mobile) {
|
|
|
|
|
|
|
|
if (options.cardFooterAside !== 'none') {
|
2020-05-16 18:07:32 +02:00
|
|
|
html += '<button is="paper-icon-button-light" class="itemAction btnCardOptions cardText-secondary" data-action="menu"><span class="material-icons more_vert"></span></button>';
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-04 12:44:12 +02:00
|
|
|
const cssClass = options.centerText ? 'cardText cardTextCentered' : 'cardText';
|
2020-03-19 22:33:41 +01:00
|
|
|
const serverId = item.ServerId || options.serverId;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-03-19 22:33:41 +01:00
|
|
|
let lines = [];
|
|
|
|
const parentTitleUnderneath = item.Type === 'MusicAlbum' || item.Type === 'Audio' || item.Type === 'MusicVideo';
|
|
|
|
let titleAdded;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
if (showOtherText) {
|
|
|
|
if ((options.showParentTitle || options.showParentTitleOrTitle) && !parentTitleUnderneath) {
|
|
|
|
|
|
|
|
if (isOuterFooter && item.Type === 'Episode' && item.SeriesName) {
|
|
|
|
|
|
|
|
if (item.SeriesId) {
|
|
|
|
lines.push(getTextActionButton({
|
|
|
|
Id: item.SeriesId,
|
2019-01-12 07:54:05 +01:00
|
|
|
ServerId: serverId,
|
2019-01-10 15:39:37 +03:00
|
|
|
Name: item.SeriesName,
|
|
|
|
Type: 'Series',
|
|
|
|
IsFolder: true
|
|
|
|
}));
|
|
|
|
} else {
|
|
|
|
lines.push(item.SeriesName);
|
|
|
|
}
|
2019-11-23 00:29:38 +09:00
|
|
|
} else {
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
if (isUsingLiveTvNaming(item)) {
|
|
|
|
|
|
|
|
lines.push(item.Name);
|
|
|
|
|
|
|
|
if (!item.EpisodeTitle) {
|
|
|
|
titleAdded = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
2020-05-04 12:44:12 +02:00
|
|
|
const parentTitle = item.SeriesName || item.Series || item.Album || item.AlbumArtist || '';
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
if (parentTitle || showTitle) {
|
|
|
|
lines.push(parentTitle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-19 22:33:41 +01:00
|
|
|
let showMediaTitle = (showTitle && !titleAdded) || (options.showParentTitleOrTitle && !lines.length);
|
2019-01-10 15:39:37 +03:00
|
|
|
if (!showMediaTitle && !titleAdded && (showTitle || forceName)) {
|
|
|
|
showMediaTitle = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (showMediaTitle) {
|
|
|
|
|
2020-03-19 22:33:41 +01:00
|
|
|
const name = options.showTitle === 'auto' && !item.IsFolder && item.MediaType === 'Photo' ? '' : itemHelper.getDisplayName(item, {
|
2019-01-10 15:39:37 +03:00
|
|
|
includeParentInfo: options.includeParentInfoInTitle
|
|
|
|
});
|
2019-01-27 22:10:07 +01:00
|
|
|
|
2019-01-12 07:54:05 +01:00
|
|
|
lines.push(getTextActionButton({
|
|
|
|
Id: item.Id,
|
|
|
|
ServerId: serverId,
|
|
|
|
Name: name,
|
|
|
|
Type: item.Type,
|
2019-01-12 19:40:12 +01:00
|
|
|
CollectionType: item.CollectionType,
|
2019-01-12 07:58:01 +01:00
|
|
|
IsFolder: item.IsFolder
|
2019-01-12 07:54:05 +01:00
|
|
|
}));
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (showOtherText) {
|
|
|
|
if (options.showParentTitle && parentTitleUnderneath) {
|
|
|
|
|
|
|
|
if (isOuterFooter && item.AlbumArtists && item.AlbumArtists.length) {
|
|
|
|
item.AlbumArtists[0].Type = 'MusicArtist';
|
|
|
|
item.AlbumArtists[0].IsFolder = true;
|
2019-01-12 07:54:05 +01:00
|
|
|
lines.push(getTextActionButton(item.AlbumArtists[0], null, serverId));
|
2019-01-10 15:39:37 +03:00
|
|
|
} else {
|
2020-05-04 12:44:12 +02:00
|
|
|
lines.push(isUsingLiveTvNaming(item) ? item.Name : (item.SeriesName || item.Series || item.Album || item.AlbumArtist || ''));
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.showItemCounts) {
|
2020-03-19 22:33:41 +01:00
|
|
|
lines.push(getItemCountsHtml(options, item));
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (options.textLines) {
|
2020-03-19 22:33:41 +01:00
|
|
|
const additionalLines = options.textLines(item);
|
|
|
|
for (let i = 0; i < additionalLines.length; i++) {
|
2019-01-10 15:39:37 +03:00
|
|
|
lines.push(additionalLines[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.showSongCount) {
|
2020-03-19 22:33:41 +01:00
|
|
|
let songLine = '';
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
if (item.SongCount) {
|
|
|
|
songLine = item.SongCount === 1 ?
|
2019-02-03 02:41:16 +09:00
|
|
|
globalize.translate('ValueOneSong') :
|
|
|
|
globalize.translate('ValueSongCount', item.SongCount);
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
lines.push(songLine);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.showPremiereDate) {
|
|
|
|
|
|
|
|
if (item.PremiereDate) {
|
|
|
|
try {
|
2020-02-26 02:26:18 -05:00
|
|
|
lines.push(datetime.toLocaleDateString(
|
|
|
|
datetime.parseISO8601Date(item.PremiereDate),
|
|
|
|
{ weekday: 'long', month: 'long', day: 'numeric' }
|
|
|
|
));
|
2019-01-10 15:39:37 +03:00
|
|
|
} catch (err) {
|
|
|
|
lines.push('');
|
|
|
|
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
lines.push('');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.showYear || options.showSeriesYear) {
|
|
|
|
|
|
|
|
if (item.Type === 'Series') {
|
2020-05-04 12:44:12 +02:00
|
|
|
if (item.Status === 'Continuing') {
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2019-02-03 02:41:16 +09:00
|
|
|
lines.push(globalize.translate('SeriesYearToPresent', item.ProductionYear || ''));
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if (item.EndDate && item.ProductionYear) {
|
2020-03-19 22:33:41 +01:00
|
|
|
const endYear = datetime.parseISO8601Date(item.EndDate).getFullYear();
|
2019-12-26 21:30:56 +01:00
|
|
|
lines.push(item.ProductionYear + ((endYear === item.ProductionYear) ? '' : (' - ' + endYear)));
|
2019-01-10 15:39:37 +03:00
|
|
|
} else {
|
|
|
|
lines.push(item.ProductionYear || '');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
lines.push(item.ProductionYear || '');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.showRuntime) {
|
|
|
|
|
|
|
|
if (item.RunTimeTicks) {
|
|
|
|
|
|
|
|
lines.push(datetime.getDisplayRunningTime(item.RunTimeTicks));
|
|
|
|
} else {
|
|
|
|
lines.push('');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.showAirTime) {
|
|
|
|
|
|
|
|
lines.push(getAirTimeText(item, options.showAirDateTime, options.showAirEndTime) || '');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.showChannelName) {
|
|
|
|
|
|
|
|
if (item.ChannelId) {
|
|
|
|
|
|
|
|
lines.push(getTextActionButton({
|
|
|
|
|
|
|
|
Id: item.ChannelId,
|
2019-01-12 07:54:05 +01:00
|
|
|
ServerId: serverId,
|
2019-01-10 15:39:37 +03:00
|
|
|
Name: item.ChannelName,
|
|
|
|
Type: 'TvChannel',
|
|
|
|
MediaType: item.MediaType,
|
|
|
|
IsFolder: false
|
|
|
|
|
|
|
|
}, item.ChannelName));
|
|
|
|
} else {
|
|
|
|
lines.push(item.ChannelName || ' ');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.showCurrentProgram && item.Type === 'TvChannel') {
|
|
|
|
|
|
|
|
if (item.CurrentProgram) {
|
|
|
|
lines.push(item.CurrentProgram.Name);
|
|
|
|
} else {
|
|
|
|
lines.push('');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.showCurrentProgramTime && item.Type === 'TvChannel') {
|
|
|
|
|
|
|
|
if (item.CurrentProgram) {
|
|
|
|
lines.push(getAirTimeText(item.CurrentProgram, false, true) || '');
|
|
|
|
} else {
|
|
|
|
lines.push('');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.showSeriesTimerTime) {
|
|
|
|
if (item.RecordAnyTime) {
|
|
|
|
|
2019-02-03 02:41:16 +09:00
|
|
|
lines.push(globalize.translate('Anytime'));
|
2019-01-10 15:39:37 +03:00
|
|
|
} else {
|
|
|
|
lines.push(datetime.getDisplayTime(item.StartDate));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.showSeriesTimerChannel) {
|
|
|
|
if (item.RecordAnyChannel) {
|
2019-02-03 02:41:16 +09:00
|
|
|
lines.push(globalize.translate('AllChannels'));
|
2019-11-23 00:29:38 +09:00
|
|
|
} else {
|
2019-02-03 02:41:16 +09:00
|
|
|
lines.push(item.ChannelName || globalize.translate('OneChannel'));
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.showPersonRoleOrType) {
|
|
|
|
if (item.Role) {
|
2020-03-24 22:27:01 +01:00
|
|
|
lines.push(globalize.translate('PersonRole', item.Role));
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((showTitle || !imgUrl) && forceName && overlayText && lines.length === 1) {
|
|
|
|
lines = [];
|
|
|
|
}
|
|
|
|
|
2020-03-19 22:33:41 +01:00
|
|
|
const addRightTextMargin = isOuterFooter && options.cardLayout && !options.centerText && options.cardFooterAside !== 'none' && layoutManager.mobile;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
html += getCardTextLines(lines, cssClass, !options.overlayText, isOuterFooter, options.cardLayout, addRightTextMargin, options.lines);
|
|
|
|
|
|
|
|
if (progressHtml) {
|
|
|
|
html += progressHtml;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (html) {
|
|
|
|
|
|
|
|
if (!isOuterFooter || logoUrl || options.cardLayout) {
|
|
|
|
html = '<div class="' + footerClass + '">' + html;
|
|
|
|
|
|
|
|
//cardFooter
|
2020-05-04 12:44:12 +02:00
|
|
|
html += '</div>';
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return html;
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
2020-03-19 21:16:40 +01:00
|
|
|
/**
|
|
|
|
* Generates the HTML markup for the action button.
|
|
|
|
* @param {Object} item - Item used to generate the action button.
|
|
|
|
* @param {string} text - Text of the action button.
|
|
|
|
* @param {string} serverId - ID of the server.
|
|
|
|
* @returns {string} HTML markup of the action button.
|
|
|
|
*/
|
2019-01-10 15:39:37 +03:00
|
|
|
function getTextActionButton(item, text, serverId) {
|
|
|
|
if (!text) {
|
|
|
|
text = itemHelper.getDisplayName(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (layoutManager.tv) {
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
2020-03-19 22:33:41 +01:00
|
|
|
let html = '<button ' + itemShortcuts.getShortcutAttributesHtml(item, serverId) + ' type="button" class="itemAction textActionButton" title="' + text + '" data-action="link">';
|
2019-01-10 15:39:37 +03:00
|
|
|
html += text;
|
|
|
|
html += '</button>';
|
|
|
|
|
|
|
|
return html;
|
|
|
|
}
|
|
|
|
|
2020-03-19 21:16:40 +01:00
|
|
|
/**
|
|
|
|
* Generates HTML markup for the item count indicator.
|
|
|
|
* @param {Object} options - Options used to generate the item count.
|
|
|
|
* @param {Object} item - Item used to generate the item count.
|
|
|
|
* @returns {string} HTML markup for the item count indicator.
|
|
|
|
*/
|
2019-01-10 15:39:37 +03:00
|
|
|
function getItemCountsHtml(options, item) {
|
2020-03-19 22:33:41 +01:00
|
|
|
let counts = [];
|
|
|
|
let childText;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
if (item.Type === 'Playlist') {
|
|
|
|
|
|
|
|
childText = '';
|
|
|
|
|
|
|
|
if (item.RunTimeTicks) {
|
|
|
|
|
2020-03-19 22:33:41 +01:00
|
|
|
let minutes = item.RunTimeTicks / 600000000;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
minutes = minutes || 1;
|
|
|
|
|
2019-02-03 02:41:16 +09:00
|
|
|
childText += globalize.translate('ValueMinutes', Math.round(minutes));
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
} else {
|
2019-02-03 02:41:16 +09:00
|
|
|
childText += globalize.translate('ValueMinutes', 0);
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
counts.push(childText);
|
|
|
|
|
2019-11-23 00:29:38 +09:00
|
|
|
} else if (item.Type === 'Genre' || item.Type === 'Studio') {
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
if (item.MovieCount) {
|
|
|
|
|
|
|
|
childText = item.MovieCount === 1 ?
|
2019-02-03 02:41:16 +09:00
|
|
|
globalize.translate('ValueOneMovie') :
|
|
|
|
globalize.translate('ValueMovieCount', item.MovieCount);
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
counts.push(childText);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (item.SeriesCount) {
|
|
|
|
|
|
|
|
childText = item.SeriesCount === 1 ?
|
2019-02-03 02:41:16 +09:00
|
|
|
globalize.translate('ValueOneSeries') :
|
|
|
|
globalize.translate('ValueSeriesCount', item.SeriesCount);
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
counts.push(childText);
|
|
|
|
}
|
|
|
|
if (item.EpisodeCount) {
|
|
|
|
|
|
|
|
childText = item.EpisodeCount === 1 ?
|
2019-02-03 02:41:16 +09:00
|
|
|
globalize.translate('ValueOneEpisode') :
|
|
|
|
globalize.translate('ValueEpisodeCount', item.EpisodeCount);
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
counts.push(childText);
|
|
|
|
}
|
|
|
|
|
2020-05-04 12:44:12 +02:00
|
|
|
} else if (item.Type === 'MusicGenre' || options.context === 'MusicArtist') {
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
if (item.AlbumCount) {
|
|
|
|
|
|
|
|
childText = item.AlbumCount === 1 ?
|
2019-02-03 02:41:16 +09:00
|
|
|
globalize.translate('ValueOneAlbum') :
|
|
|
|
globalize.translate('ValueAlbumCount', item.AlbumCount);
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
counts.push(childText);
|
|
|
|
}
|
|
|
|
if (item.SongCount) {
|
|
|
|
|
|
|
|
childText = item.SongCount === 1 ?
|
2019-02-03 02:41:16 +09:00
|
|
|
globalize.translate('ValueOneSong') :
|
|
|
|
globalize.translate('ValueSongCount', item.SongCount);
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
counts.push(childText);
|
|
|
|
}
|
|
|
|
if (item.MusicVideoCount) {
|
|
|
|
|
|
|
|
childText = item.MusicVideoCount === 1 ?
|
2019-02-03 02:41:16 +09:00
|
|
|
globalize.translate('ValueOneMusicVideo') :
|
|
|
|
globalize.translate('ValueMusicVideoCount', item.MusicVideoCount);
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
counts.push(childText);
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (item.Type === 'Series') {
|
|
|
|
|
|
|
|
childText = item.RecursiveItemCount === 1 ?
|
2019-02-03 02:41:16 +09:00
|
|
|
globalize.translate('ValueOneEpisode') :
|
|
|
|
globalize.translate('ValueEpisodeCount', item.RecursiveItemCount);
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
counts.push(childText);
|
|
|
|
}
|
|
|
|
|
|
|
|
return counts.join(', ');
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-03-19 22:33:41 +01:00
|
|
|
let refreshIndicatorLoaded;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-03-19 21:16:40 +01:00
|
|
|
/**
|
|
|
|
* Imports the refresh indicator element.
|
|
|
|
*/
|
|
|
|
function requireRefreshIndicator() {
|
2019-01-10 15:39:37 +03:00
|
|
|
if (!refreshIndicatorLoaded) {
|
|
|
|
refreshIndicatorLoaded = true;
|
|
|
|
require(['emby-itemrefreshindicator']);
|
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-03-19 21:16:40 +01:00
|
|
|
/**
|
|
|
|
* Returns the default background class for a card based on a string.
|
|
|
|
* @param {string} str - Text used to generate the background class.
|
|
|
|
* @returns {string} CSS classes for default card backgrounds.
|
|
|
|
*/
|
2020-03-19 21:15:38 +01:00
|
|
|
export function getDefaultBackgroundClass(str) {
|
2019-01-10 15:39:37 +03:00
|
|
|
return 'defaultCardBackground defaultCardBackground' + getDefaultColorIndex(str);
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-03-19 21:16:40 +01:00
|
|
|
/**
|
|
|
|
* Builds the HTML markup for an individual card.
|
|
|
|
* @param {number} index - Index of the card
|
|
|
|
* @param {object} item - Item used to generate the card.
|
2020-03-21 03:30:21 +09:00
|
|
|
* @param {object} apiClient - API client instance.
|
2020-03-19 21:16:40 +01:00
|
|
|
* @param {object} options - Options used to generate the card.
|
|
|
|
* @returns {string} HTML markup for the generated card.
|
|
|
|
*/
|
2019-01-10 15:39:37 +03:00
|
|
|
function buildCard(index, item, apiClient, options) {
|
2020-03-19 22:33:41 +01:00
|
|
|
let action = options.action || 'link';
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
if (action === 'play' && item.IsFolder) {
|
|
|
|
// If this hard-coding is ever removed make sure to test nested photo albums
|
|
|
|
action = 'link';
|
2019-11-23 00:29:38 +09:00
|
|
|
} else if (item.MediaType === 'Photo') {
|
2019-01-10 15:39:37 +03:00
|
|
|
action = 'play';
|
|
|
|
}
|
|
|
|
|
2020-03-19 22:33:41 +01:00
|
|
|
let shape = options.shape;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
if (shape === 'mixed') {
|
|
|
|
|
|
|
|
shape = null;
|
|
|
|
|
2020-03-19 22:33:41 +01:00
|
|
|
const primaryImageAspectRatio = item.PrimaryImageAspectRatio;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
if (primaryImageAspectRatio) {
|
|
|
|
|
|
|
|
if (primaryImageAspectRatio >= 1.33) {
|
|
|
|
shape = 'mixedBackdrop';
|
|
|
|
} else if (primaryImageAspectRatio > 0.71) {
|
|
|
|
shape = 'mixedSquare';
|
|
|
|
} else {
|
|
|
|
shape = 'mixedPortrait';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
shape = shape || 'mixedSquare';
|
|
|
|
}
|
|
|
|
|
2019-11-11 12:28:27 +03:00
|
|
|
// TODO move card creation code to Card component
|
|
|
|
|
2020-03-19 22:33:41 +01:00
|
|
|
let className = 'card';
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
if (shape) {
|
|
|
|
className += ' ' + shape + 'Card';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.cardCssClass) {
|
|
|
|
className += ' ' + options.cardCssClass;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.cardClass) {
|
2020-05-04 12:44:12 +02:00
|
|
|
className += ' ' + options.cardClass;
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (layoutManager.desktop) {
|
|
|
|
className += ' card-hoverable';
|
|
|
|
}
|
|
|
|
|
2019-11-11 12:28:27 +03:00
|
|
|
if (layoutManager.tv) {
|
|
|
|
className += ' show-focus';
|
|
|
|
|
|
|
|
if (enableFocusTransform) {
|
|
|
|
className += ' show-animation';
|
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
|
|
|
|
2020-03-19 22:33:41 +01:00
|
|
|
const imgInfo = getCardImageUrl(item, apiClient, options, shape);
|
|
|
|
const imgUrl = imgInfo.imgUrl;
|
2020-05-23 18:35:34 +02:00
|
|
|
const blurhash = imgInfo.blurhash;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-03-19 22:33:41 +01:00
|
|
|
const forceName = imgInfo.forceName;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-03-19 22:33:41 +01:00
|
|
|
const showTitle = options.showTitle === 'auto' ? true : (options.showTitle || item.Type === 'PhotoAlbum' || item.Type === 'Folder');
|
|
|
|
const overlayText = options.overlayText;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-03-19 22:33:41 +01:00
|
|
|
let cardImageContainerClass = 'cardImageContainer';
|
|
|
|
const coveredImage = options.coverImage || imgInfo.coverImage;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
if (coveredImage) {
|
|
|
|
cardImageContainerClass += ' coveredImage';
|
|
|
|
|
|
|
|
if (item.MediaType === 'Photo' || item.Type === 'PhotoAlbum' || item.Type === 'Folder' || item.ProgramInfo || item.Type === 'Program' || item.Type === 'Recording') {
|
|
|
|
cardImageContainerClass += ' coveredImage-noScale';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!imgUrl) {
|
|
|
|
cardImageContainerClass += ' ' + getDefaultBackgroundClass(item.Name);
|
|
|
|
}
|
|
|
|
|
2020-03-19 22:33:41 +01:00
|
|
|
let cardBoxClass = options.cardLayout ? 'cardBox visualCardBox' : 'cardBox';
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-03-19 22:33:41 +01:00
|
|
|
let footerCssClass;
|
|
|
|
let progressHtml = indicators.getProgressBarHtml(item);
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-03-19 22:33:41 +01:00
|
|
|
let innerCardFooter = '';
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-03-19 22:33:41 +01:00
|
|
|
let footerOverlayed = false;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-03-19 22:33:41 +01:00
|
|
|
let logoUrl;
|
|
|
|
const logoHeight = 40;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
if (options.showChannelLogo && item.ChannelPrimaryImageTag) {
|
|
|
|
logoUrl = apiClient.getScaledImageUrl(item.ChannelId, {
|
2020-05-04 12:44:12 +02:00
|
|
|
type: 'Primary',
|
2019-01-10 15:39:37 +03:00
|
|
|
height: logoHeight,
|
|
|
|
tag: item.ChannelPrimaryImageTag
|
|
|
|
});
|
2019-11-23 00:29:38 +09:00
|
|
|
} else if (options.showLogo && item.ParentLogoImageTag) {
|
2019-01-10 15:39:37 +03:00
|
|
|
logoUrl = apiClient.getScaledImageUrl(item.ParentLogoItemId, {
|
2020-05-04 12:44:12 +02:00
|
|
|
type: 'Logo',
|
2019-01-10 15:39:37 +03:00
|
|
|
height: logoHeight,
|
|
|
|
tag: item.ParentLogoImageTag
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (overlayText) {
|
|
|
|
|
|
|
|
logoUrl = null;
|
|
|
|
|
|
|
|
footerCssClass = progressHtml ? 'innerCardFooter fullInnerCardFooter' : 'innerCardFooter';
|
|
|
|
innerCardFooter += getCardFooterText(item, apiClient, options, showTitle, forceName, overlayText, imgUrl, footerCssClass, progressHtml, logoUrl, false);
|
|
|
|
footerOverlayed = true;
|
2019-11-23 00:29:38 +09:00
|
|
|
} else if (progressHtml) {
|
2019-01-10 15:39:37 +03:00
|
|
|
innerCardFooter += '<div class="innerCardFooter fullInnerCardFooter innerCardFooterClear">';
|
|
|
|
innerCardFooter += progressHtml;
|
|
|
|
innerCardFooter += '</div>';
|
|
|
|
|
|
|
|
progressHtml = '';
|
|
|
|
}
|
|
|
|
|
2020-03-19 22:33:41 +01:00
|
|
|
const mediaSourceCount = item.MediaSourceCount || 1;
|
2019-01-10 15:39:37 +03:00
|
|
|
if (mediaSourceCount > 1) {
|
|
|
|
innerCardFooter += '<div class="mediaSourceIndicator">' + mediaSourceCount + '</div>';
|
|
|
|
}
|
|
|
|
|
2020-03-19 22:33:41 +01:00
|
|
|
let outerCardFooter = '';
|
2019-01-10 15:39:37 +03:00
|
|
|
if (!overlayText && !footerOverlayed) {
|
|
|
|
footerCssClass = options.cardLayout ? 'cardFooter' : 'cardFooter cardFooter-transparent';
|
|
|
|
|
|
|
|
if (logoUrl) {
|
|
|
|
footerCssClass += ' cardFooter-withlogo';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!options.cardLayout) {
|
|
|
|
logoUrl = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
outerCardFooter = getCardFooterText(item, apiClient, options, showTitle, forceName, overlayText, imgUrl, footerCssClass, progressHtml, logoUrl, true);
|
|
|
|
}
|
|
|
|
|
2019-05-13 12:56:44 -07:00
|
|
|
if (outerCardFooter && !options.cardLayout) {
|
2019-01-10 15:39:37 +03:00
|
|
|
cardBoxClass += ' cardBox-bottompadded';
|
|
|
|
}
|
|
|
|
|
2020-03-19 22:33:41 +01:00
|
|
|
let overlayButtons = '';
|
2019-01-10 15:39:37 +03:00
|
|
|
if (layoutManager.mobile) {
|
2020-03-19 22:33:41 +01:00
|
|
|
let overlayPlayButton = options.overlayPlayButton;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
if (overlayPlayButton == null && !options.overlayMoreButton && !options.overlayInfoButton && !options.cardLayout) {
|
|
|
|
overlayPlayButton = item.MediaType === 'Video';
|
|
|
|
}
|
|
|
|
|
2020-03-19 22:33:41 +01:00
|
|
|
const btnCssClass = 'cardOverlayButton cardOverlayButton-br itemAction';
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
if (options.centerPlayButton) {
|
2020-04-26 02:37:28 +03:00
|
|
|
overlayButtons += '<button is="paper-icon-button-light" class="' + btnCssClass + ' cardOverlayButton-centered" data-action="play"><span class="material-icons cardOverlayButtonIcon play_arrow"></span></button>';
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (overlayPlayButton && !item.IsPlaceHolder && (item.LocationType !== 'Virtual' || !item.MediaType || item.Type === 'Program') && item.Type !== 'Person') {
|
2020-04-26 02:37:28 +03:00
|
|
|
overlayButtons += '<button is="paper-icon-button-light" class="' + btnCssClass + '" data-action="play"><span class="material-icons cardOverlayButtonIcon play_arrow"></span></button>';
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (options.overlayMoreButton) {
|
2020-05-16 18:07:32 +02:00
|
|
|
overlayButtons += '<button is="paper-icon-button-light" class="' + btnCssClass + '" data-action="menu"><span class="material-icons cardOverlayButtonIcon more_vert"></span></button>';
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.showChildCountIndicator && item.ChildCount) {
|
|
|
|
className += ' groupedCard';
|
|
|
|
}
|
|
|
|
|
|
|
|
// cardBox can be it's own separate element if an outer footer is ever needed
|
2020-03-19 22:33:41 +01:00
|
|
|
let cardImageContainerOpen;
|
|
|
|
let cardImageContainerClose = '';
|
|
|
|
let cardBoxClose = '';
|
|
|
|
let cardScalableClose = '';
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-03-19 22:33:41 +01:00
|
|
|
let cardContentClass = 'cardContent';
|
2019-01-10 15:39:37 +03:00
|
|
|
if (!options.cardLayout) {
|
|
|
|
cardContentClass += ' cardContent-shadow';
|
|
|
|
}
|
|
|
|
|
2020-05-23 18:35:34 +02:00
|
|
|
let blurhashAttrib = '';
|
|
|
|
if (blurhash && blurhash.length > 0) {
|
|
|
|
blurhashAttrib = 'data-blurhash="' + blurhash + '"';
|
|
|
|
}
|
|
|
|
|
2019-01-10 15:39:37 +03:00
|
|
|
if (layoutManager.tv) {
|
|
|
|
|
|
|
|
// Don't use the IMG tag with safari because it puts a white border around it
|
2020-05-23 18:35:34 +02:00
|
|
|
cardImageContainerOpen = imgUrl ? ('<div class="' + cardImageContainerClass + ' ' + cardContentClass + ' lazy" data-src="' + imgUrl + '" ' + blurhashAttrib + '>') : ('<div class="' + cardImageContainerClass + ' ' + cardContentClass + '">');
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
cardImageContainerClose = '</div>';
|
|
|
|
} else {
|
|
|
|
// Don't use the IMG tag with safari because it puts a white border around it
|
2020-05-23 18:35:34 +02:00
|
|
|
cardImageContainerOpen = imgUrl ? ('<button data-action="' + action + '" class="cardContent-button ' + cardImageContainerClass + ' ' + cardContentClass + ' itemAction lazy" data-src="' + imgUrl + '" ' + blurhashAttrib + '>') : ('<button data-action="' + action + '" class="cardContent-button ' + cardImageContainerClass + ' ' + cardContentClass + ' itemAction">');
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
cardImageContainerClose = '</button>';
|
|
|
|
}
|
|
|
|
|
2020-03-19 22:33:41 +01:00
|
|
|
let cardScalableClass = 'cardScalable';
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
cardImageContainerOpen = '<div class="' + cardBoxClass + '"><div class="' + cardScalableClass + '"><div class="cardPadder-' + shape + '"></div>' + cardImageContainerOpen;
|
|
|
|
cardBoxClose = '</div>';
|
|
|
|
cardScalableClose = '</div>';
|
|
|
|
|
2020-03-19 22:33:41 +01:00
|
|
|
let indicatorsHtml = '';
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
if (options.missingIndicator !== false) {
|
|
|
|
indicatorsHtml += indicators.getMissingIndicator(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
indicatorsHtml += indicators.getSyncIndicator(item);
|
|
|
|
indicatorsHtml += indicators.getTimerIndicator(item);
|
|
|
|
|
|
|
|
indicatorsHtml += indicators.getTypeIndicator(item);
|
|
|
|
|
|
|
|
if (options.showGroupCount) {
|
|
|
|
|
|
|
|
indicatorsHtml += indicators.getChildCountIndicatorHtml(item, {
|
|
|
|
minCount: 1
|
|
|
|
});
|
2019-11-23 00:29:38 +09:00
|
|
|
} else {
|
2019-01-10 15:39:37 +03:00
|
|
|
indicatorsHtml += indicators.getPlayedIndicatorHtml(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (item.Type === 'CollectionFolder' || item.CollectionType) {
|
2020-03-19 22:33:41 +01:00
|
|
|
const refreshClass = item.RefreshProgress ? '' : ' class="hide"';
|
2019-01-10 15:39:37 +03:00
|
|
|
indicatorsHtml += '<div is="emby-itemrefreshindicator"' + refreshClass + ' data-progress="' + (item.RefreshProgress || 0) + '" data-status="' + item.RefreshStatus + '"></div>';
|
|
|
|
requireRefreshIndicator();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (indicatorsHtml) {
|
|
|
|
cardImageContainerOpen += '<div class="cardIndicators">' + indicatorsHtml + '</div>';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!imgUrl) {
|
2020-01-29 18:59:18 +01:00
|
|
|
cardImageContainerOpen += getDefaultText(item, options);
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
|
|
|
|
2020-03-19 22:33:41 +01:00
|
|
|
const tagName = (layoutManager.tv) && !overlayButtons ? 'button' : 'div';
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-03-19 22:33:41 +01:00
|
|
|
const nameWithPrefix = (item.SortName || item.Name || '');
|
|
|
|
let prefix = nameWithPrefix.substring(0, Math.min(3, nameWithPrefix.length));
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
if (prefix) {
|
|
|
|
prefix = prefix.toUpperCase();
|
|
|
|
}
|
|
|
|
|
2020-03-19 22:33:41 +01:00
|
|
|
let timerAttributes = '';
|
2019-01-10 15:39:37 +03:00
|
|
|
if (item.TimerId) {
|
|
|
|
timerAttributes += ' data-timerid="' + item.TimerId + '"';
|
|
|
|
}
|
|
|
|
if (item.SeriesTimerId) {
|
|
|
|
timerAttributes += ' data-seriestimerid="' + item.SeriesTimerId + '"';
|
|
|
|
}
|
|
|
|
|
2020-03-19 22:33:41 +01:00
|
|
|
let actionAttribute;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
if (tagName === 'button') {
|
2020-05-04 12:44:12 +02:00
|
|
|
className += ' itemAction';
|
2019-01-10 15:39:37 +03:00
|
|
|
actionAttribute = ' data-action="' + action + '"';
|
|
|
|
} else {
|
|
|
|
actionAttribute = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (item.Type !== 'MusicAlbum' && item.Type !== 'MusicArtist' && item.Type !== 'Audio') {
|
|
|
|
className += ' card-withuserdata';
|
|
|
|
}
|
|
|
|
|
2020-03-19 22:33:41 +01:00
|
|
|
const positionTicksData = item.UserData && item.UserData.PlaybackPositionTicks ? (' data-positionticks="' + item.UserData.PlaybackPositionTicks + '"') : '';
|
|
|
|
const collectionIdData = options.collectionId ? (' data-collectionid="' + options.collectionId + '"') : '';
|
|
|
|
const playlistIdData = options.playlistId ? (' data-playlistid="' + options.playlistId + '"') : '';
|
|
|
|
const mediaTypeData = item.MediaType ? (' data-mediatype="' + item.MediaType + '"') : '';
|
|
|
|
const collectionTypeData = item.CollectionType ? (' data-collectiontype="' + item.CollectionType + '"') : '';
|
|
|
|
const channelIdData = item.ChannelId ? (' data-channelid="' + item.ChannelId + '"') : '';
|
|
|
|
const contextData = options.context ? (' data-context="' + options.context + '"') : '';
|
|
|
|
const parentIdData = options.parentId ? (' data-parentid="' + options.parentId + '"') : '';
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-03-19 22:33:41 +01:00
|
|
|
let additionalCardContent = '';
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
if (layoutManager.desktop) {
|
|
|
|
additionalCardContent += getHoverMenuHtml(item, action);
|
|
|
|
}
|
|
|
|
|
|
|
|
return '<' + tagName + ' data-index="' + index + '"' + timerAttributes + actionAttribute + ' data-isfolder="' + (item.IsFolder || false) + '" data-serverid="' + (item.ServerId || options.serverId) + '" data-id="' + (item.Id || item.ItemId) + '" data-type="' + item.Type + '"' + mediaTypeData + collectionTypeData + channelIdData + positionTicksData + collectionIdData + playlistIdData + contextData + parentIdData + ' data-prefix="' + prefix + '" class="' + className + '">' + cardImageContainerOpen + innerCardFooter + cardImageContainerClose + overlayButtons + additionalCardContent + cardScalableClose + outerCardFooter + cardBoxClose + '</' + tagName + '>';
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-03-19 21:16:40 +01:00
|
|
|
/**
|
|
|
|
* Generates HTML markup for the card overlay.
|
|
|
|
* @param {object} item - Item used to generate the card overlay.
|
|
|
|
* @param {string} action - Action assigned to the overlay.
|
|
|
|
* @returns {string} HTML markup of the card overlay.
|
|
|
|
*/
|
2019-01-10 15:39:37 +03:00
|
|
|
function getHoverMenuHtml(item, action) {
|
2020-03-19 22:33:41 +01:00
|
|
|
let html = '';
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
html += '<div class="cardOverlayContainer itemAction" data-action="' + action + '">';
|
|
|
|
|
2020-03-19 22:33:41 +01:00
|
|
|
const btnCssClass = 'cardOverlayButton cardOverlayButton-hover itemAction paper-icon-button-light';
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
if (playbackManager.canPlay(item)) {
|
2020-04-26 02:37:28 +03:00
|
|
|
html += '<button is="paper-icon-button-light" class="' + btnCssClass + ' cardOverlayFab-primary" data-action="resume"><span class="material-icons cardOverlayButtonIcon cardOverlayButtonIcon-hover play_arrow"></span></button>';
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
|
|
|
|
2020-03-04 18:44:25 +01:00
|
|
|
html += '<div class="cardOverlayButton-br flex">';
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-03-19 22:33:41 +01:00
|
|
|
const userData = item.UserData || {};
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
if (itemHelper.canMarkPlayed(item)) {
|
|
|
|
require(['emby-playstatebutton']);
|
2020-04-26 02:37:28 +03:00
|
|
|
html += '<button is="emby-playstatebutton" type="button" data-action="none" class="' + btnCssClass + '" data-id="' + item.Id + '" data-serverid="' + item.ServerId + '" data-itemtype="' + item.Type + '" data-played="' + (userData.Played) + '"><span class="material-icons cardOverlayButtonIcon cardOverlayButtonIcon-hover check"></span></button>';
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (itemHelper.canRate(item)) {
|
|
|
|
|
2020-03-19 22:33:41 +01:00
|
|
|
const likes = userData.Likes == null ? '' : userData.Likes;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
require(['emby-ratingbutton']);
|
2020-04-26 02:37:28 +03:00
|
|
|
html += '<button is="emby-ratingbutton" type="button" data-action="none" class="' + btnCssClass + '" data-id="' + item.Id + '" data-serverid="' + item.ServerId + '" data-itemtype="' + item.Type + '" data-likes="' + likes + '" data-isfavorite="' + (userData.IsFavorite) + '"><span class="material-icons cardOverlayButtonIcon cardOverlayButtonIcon-hover favorite"></span></button>';
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
|
|
|
|
2020-05-16 18:07:32 +02:00
|
|
|
html += '<button is="paper-icon-button-light" class="' + btnCssClass + '" data-action="menu"><span class="material-icons cardOverlayButtonIcon cardOverlayButtonIcon-hover more_vert"></span></button>';
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
html += '</div>';
|
|
|
|
html += '</div>';
|
|
|
|
|
|
|
|
return html;
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-03-19 21:16:40 +01:00
|
|
|
/**
|
2020-03-21 03:30:21 +09:00
|
|
|
* Generates the text or icon used for default card backgrounds.
|
2020-03-19 21:16:40 +01:00
|
|
|
* @param {object} item - Item used to generate the card overlay.
|
|
|
|
* @param {object} options - Options used to generate the card overlay.
|
|
|
|
* @returns {string} HTML markup of the card overlay.
|
|
|
|
*/
|
2020-03-19 21:15:38 +01:00
|
|
|
export function getDefaultText(item, options) {
|
2019-07-01 14:49:34 -07:00
|
|
|
if (item.CollectionType) {
|
2020-04-26 02:37:28 +03:00
|
|
|
return '<span class="cardImageIcon material-icons ' + imageHelper.getLibraryIcon(item.CollectionType) + '"></span>';
|
2019-05-16 04:33:57 +03:00
|
|
|
}
|
2020-01-29 18:59:18 +01:00
|
|
|
|
|
|
|
switch (item.Type) {
|
|
|
|
case 'MusicAlbum':
|
2020-04-26 02:37:28 +03:00
|
|
|
return '<span class="cardImageIcon material-icons album"></span>';
|
2020-01-29 18:59:18 +01:00
|
|
|
case 'MusicArtist':
|
|
|
|
case 'Person':
|
2020-04-26 02:37:28 +03:00
|
|
|
return '<span class="cardImageIcon material-icons person"></span>';
|
2020-01-29 18:59:18 +01:00
|
|
|
case 'Movie':
|
2020-04-26 02:37:28 +03:00
|
|
|
return '<span class="cardImageIcon material-icons movie"></span>';
|
2020-01-29 18:59:18 +01:00
|
|
|
case 'Series':
|
2020-04-26 02:37:28 +03:00
|
|
|
return '<span class="cardImageIcon material-icons tv"></span>';
|
2020-02-15 22:15:17 +01:00
|
|
|
case 'Book':
|
2020-04-26 02:37:28 +03:00
|
|
|
return '<span class="cardImageIcon material-icons book"></span>';
|
2020-02-15 22:15:17 +01:00
|
|
|
case 'Folder':
|
2020-04-26 02:37:28 +03:00
|
|
|
return '<span class="cardImageIcon material-icons folder"></span>';
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
2020-01-29 18:59:18 +01:00
|
|
|
|
|
|
|
if (options && options.defaultCardImageIcon) {
|
2020-04-26 02:37:28 +03:00
|
|
|
return '<span class="cardImageIcon material-icons ' + options.defaultCardImageIcon + '"></span>';
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
|
|
|
|
2020-03-19 22:33:41 +01:00
|
|
|
const defaultName = isUsingLiveTvNaming(item) ? item.Name : itemHelper.getDisplayName(item);
|
2019-01-10 15:39:37 +03:00
|
|
|
return '<div class="cardText cardDefaultText">' + defaultName + '</div>';
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
2020-03-19 21:16:40 +01:00
|
|
|
/**
|
2020-03-22 18:00:03 +01:00
|
|
|
* Builds a set of cards and inserts them into the page.
|
2020-03-22 17:12:34 +01:00
|
|
|
* @param {Array} items - Array of items used to build the cards.
|
2020-03-19 21:16:40 +01:00
|
|
|
* @param {options} options - Options of the cards to build.
|
|
|
|
*/
|
2020-03-19 21:15:38 +01:00
|
|
|
export function buildCards(items, options) {
|
2019-01-10 15:39:37 +03:00
|
|
|
// Abort if the container has been disposed
|
|
|
|
if (!document.body.contains(options.itemsContainer)) {
|
|
|
|
return;
|
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
|
|
|
|
if (options.parentContainer) {
|
2019-01-10 15:39:37 +03:00
|
|
|
if (items.length) {
|
|
|
|
options.parentContainer.classList.remove('hide');
|
|
|
|
} else {
|
|
|
|
options.parentContainer.classList.add('hide');
|
|
|
|
return;
|
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-03-19 22:33:41 +01:00
|
|
|
const html = buildCardsHtmlInternal(items, options);
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
if (html) {
|
|
|
|
|
|
|
|
if (options.itemsContainer.cardBuilderHtml !== html) {
|
|
|
|
options.itemsContainer.innerHTML = html;
|
|
|
|
|
|
|
|
if (items.length < 50) {
|
|
|
|
options.itemsContainer.cardBuilderHtml = html;
|
|
|
|
} else {
|
|
|
|
options.itemsContainer.cardBuilderHtml = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
imageLoader.lazyChildren(options.itemsContainer);
|
|
|
|
} else {
|
|
|
|
|
|
|
|
options.itemsContainer.innerHTML = html;
|
|
|
|
options.itemsContainer.cardBuilderHtml = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.autoFocus) {
|
|
|
|
focusManager.autoFocus(options.itemsContainer, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-19 21:16:40 +01:00
|
|
|
/**
|
2020-03-21 03:30:21 +09:00
|
|
|
* Ensures the indicators for a card exist and creates them if they don't exist.
|
2020-03-22 17:12:34 +01:00
|
|
|
* @param {HTMLDivElement} card - DOM element of the card.
|
|
|
|
* @param {HTMLDivElement} indicatorsElem - DOM element of the indicators.
|
|
|
|
* @returns {HTMLDivElement} - DOM element of the indicators.
|
2020-03-19 21:16:40 +01:00
|
|
|
*/
|
2019-01-10 15:39:37 +03:00
|
|
|
function ensureIndicators(card, indicatorsElem) {
|
|
|
|
if (indicatorsElem) {
|
|
|
|
return indicatorsElem;
|
|
|
|
}
|
|
|
|
|
|
|
|
indicatorsElem = card.querySelector('.cardIndicators');
|
|
|
|
|
|
|
|
if (!indicatorsElem) {
|
|
|
|
|
2020-03-19 22:33:41 +01:00
|
|
|
const cardImageContainer = card.querySelector('.cardImageContainer');
|
2019-01-10 15:39:37 +03:00
|
|
|
indicatorsElem = document.createElement('div');
|
|
|
|
indicatorsElem.classList.add('cardIndicators');
|
|
|
|
cardImageContainer.appendChild(indicatorsElem);
|
|
|
|
}
|
|
|
|
|
|
|
|
return indicatorsElem;
|
|
|
|
}
|
|
|
|
|
2020-03-19 21:16:40 +01:00
|
|
|
/**
|
2020-03-21 03:30:21 +09:00
|
|
|
* Adds user data to the card such as progress indicators and played status.
|
2020-03-22 17:12:34 +01:00
|
|
|
* @param {HTMLDivElement} card - DOM element of the card.
|
2020-03-19 21:16:40 +01:00
|
|
|
* @param {Object} userData - User data to apply to the card.
|
|
|
|
*/
|
2019-01-10 15:39:37 +03:00
|
|
|
function updateUserData(card, userData) {
|
2020-03-19 22:33:41 +01:00
|
|
|
const type = card.getAttribute('data-type');
|
|
|
|
const enableCountIndicator = type === 'Series' || type === 'BoxSet' || type === 'Season';
|
|
|
|
let indicatorsElem = null;
|
|
|
|
let playedIndicator = null;
|
|
|
|
let countIndicator = null;
|
|
|
|
let itemProgressBar = null;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
if (userData.Played) {
|
|
|
|
|
|
|
|
playedIndicator = card.querySelector('.playedIndicator');
|
|
|
|
|
|
|
|
if (!playedIndicator) {
|
|
|
|
|
|
|
|
playedIndicator = document.createElement('div');
|
|
|
|
playedIndicator.classList.add('playedIndicator');
|
|
|
|
playedIndicator.classList.add('indicator');
|
|
|
|
indicatorsElem = ensureIndicators(card, indicatorsElem);
|
|
|
|
indicatorsElem.appendChild(playedIndicator);
|
|
|
|
}
|
2020-04-26 02:37:28 +03:00
|
|
|
playedIndicator.innerHTML = '<span class="material-icons indicatorIcon check"></span>';
|
2019-01-10 15:39:37 +03:00
|
|
|
} else {
|
|
|
|
|
|
|
|
playedIndicator = card.querySelector('.playedIndicator');
|
|
|
|
if (playedIndicator) {
|
|
|
|
|
|
|
|
playedIndicator.parentNode.removeChild(playedIndicator);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (userData.UnplayedItemCount) {
|
|
|
|
countIndicator = card.querySelector('.countIndicator');
|
|
|
|
|
|
|
|
if (!countIndicator) {
|
|
|
|
|
|
|
|
countIndicator = document.createElement('div');
|
|
|
|
countIndicator.classList.add('countIndicator');
|
|
|
|
indicatorsElem = ensureIndicators(card, indicatorsElem);
|
|
|
|
indicatorsElem.appendChild(countIndicator);
|
|
|
|
}
|
|
|
|
countIndicator.innerHTML = userData.UnplayedItemCount;
|
|
|
|
} else if (enableCountIndicator) {
|
|
|
|
|
|
|
|
countIndicator = card.querySelector('.countIndicator');
|
|
|
|
if (countIndicator) {
|
|
|
|
|
|
|
|
countIndicator.parentNode.removeChild(countIndicator);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-19 22:33:41 +01:00
|
|
|
const progressHtml = indicators.getProgressBarHtml({
|
2019-01-10 15:39:37 +03:00
|
|
|
Type: type,
|
|
|
|
UserData: userData,
|
|
|
|
MediaType: 'Video'
|
|
|
|
});
|
|
|
|
|
|
|
|
if (progressHtml) {
|
|
|
|
|
|
|
|
itemProgressBar = card.querySelector('.itemProgressBar');
|
|
|
|
|
|
|
|
if (!itemProgressBar) {
|
|
|
|
itemProgressBar = document.createElement('div');
|
|
|
|
itemProgressBar.classList.add('itemProgressBar');
|
|
|
|
|
2020-03-19 22:33:41 +01:00
|
|
|
let innerCardFooter = card.querySelector('.innerCardFooter');
|
2019-01-10 15:39:37 +03:00
|
|
|
if (!innerCardFooter) {
|
|
|
|
innerCardFooter = document.createElement('div');
|
|
|
|
innerCardFooter.classList.add('innerCardFooter');
|
2020-03-19 22:33:41 +01:00
|
|
|
const cardImageContainer = card.querySelector('.cardImageContainer');
|
2019-01-10 15:39:37 +03:00
|
|
|
cardImageContainer.appendChild(innerCardFooter);
|
|
|
|
}
|
|
|
|
innerCardFooter.appendChild(itemProgressBar);
|
|
|
|
}
|
|
|
|
|
|
|
|
itemProgressBar.innerHTML = progressHtml;
|
2019-11-23 00:29:38 +09:00
|
|
|
} else {
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
itemProgressBar = card.querySelector('.itemProgressBar');
|
|
|
|
if (itemProgressBar) {
|
|
|
|
itemProgressBar.parentNode.removeChild(itemProgressBar);
|
|
|
|
}
|
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-03-19 21:16:40 +01:00
|
|
|
/**
|
|
|
|
* Handles when user data has changed.
|
|
|
|
* @param {Object} userData - User data to apply to the card.
|
2020-03-21 03:30:21 +09:00
|
|
|
* @param {HTMLElement} scope - DOM element to use as a scope when selecting cards.
|
2020-03-19 21:16:40 +01:00
|
|
|
*/
|
2020-03-19 21:15:38 +01:00
|
|
|
export function onUserDataChanged(userData, scope) {
|
2020-03-19 22:33:41 +01:00
|
|
|
const cards = (scope || document.body).querySelectorAll('.card-withuserdata[data-id="' + userData.ItemId + '"]');
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-03-19 22:33:41 +01:00
|
|
|
for (let i = 0, length = cards.length; i < length; i++) {
|
2019-01-10 15:39:37 +03:00
|
|
|
updateUserData(cards[i], userData);
|
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-03-19 21:16:40 +01:00
|
|
|
/**
|
2020-03-21 03:30:21 +09:00
|
|
|
* Handles when a timer has been created.
|
2020-03-19 21:16:40 +01:00
|
|
|
* @param {string} programId - ID of the program.
|
|
|
|
* @param {string} newTimerId - ID of the new timer.
|
2020-03-21 03:30:21 +09:00
|
|
|
* @param {HTMLElement} itemsContainer - DOM element of the itemsContainer.
|
2020-03-19 21:16:40 +01:00
|
|
|
*/
|
2020-03-19 21:15:38 +01:00
|
|
|
export function onTimerCreated(programId, newTimerId, itemsContainer) {
|
2020-03-19 22:33:41 +01:00
|
|
|
const cells = itemsContainer.querySelectorAll('.card[data-id="' + programId + '"]');
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-03-19 22:33:41 +01:00
|
|
|
for (let i = 0, length = cells.length; i < length; i++) {
|
|
|
|
let cell = cells[i];
|
|
|
|
const icon = cell.querySelector('.timerIndicator');
|
2019-01-10 15:39:37 +03:00
|
|
|
if (!icon) {
|
2020-03-19 22:33:41 +01:00
|
|
|
const indicatorsElem = ensureIndicators(cell);
|
2020-04-26 02:37:28 +03:00
|
|
|
indicatorsElem.insertAdjacentHTML('beforeend', '<span class="material-icons timerIndicator indicatorIcon fiber_manual_record"></span>');
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
|
|
|
cell.setAttribute('data-timerid', newTimerId);
|
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
2020-03-19 21:16:40 +01:00
|
|
|
/**
|
2020-03-21 03:30:21 +09:00
|
|
|
* Handles when a timer has been cancelled.
|
2020-03-19 21:16:40 +01:00
|
|
|
* @param {string} timerId - ID of the cancelled timer.
|
2020-03-22 17:12:34 +01:00
|
|
|
* @param {HTMLElement} itemsContainer - DOM element of the itemsContainer.
|
2020-03-19 21:16:40 +01:00
|
|
|
*/
|
|
|
|
export function onTimerCancelled(timerId, itemsContainer) {
|
2020-03-19 22:33:41 +01:00
|
|
|
const cells = itemsContainer.querySelectorAll('.card[data-timerid="' + timerId + '"]');
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-03-19 22:33:41 +01:00
|
|
|
for (let i = 0; i < cells.length; i++) {
|
|
|
|
let cell = cells[i];
|
|
|
|
let icon = cell.querySelector('.timerIndicator');
|
2019-01-10 15:39:37 +03:00
|
|
|
if (icon) {
|
|
|
|
icon.parentNode.removeChild(icon);
|
|
|
|
}
|
|
|
|
cell.removeAttribute('data-timerid');
|
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
2020-03-19 21:16:40 +01:00
|
|
|
/**
|
2020-03-21 03:30:21 +09:00
|
|
|
* Handles when a series timer has been cancelled.
|
2020-03-22 17:12:34 +01:00
|
|
|
* @param {string} cancelledTimerId - ID of the cancelled timer.
|
|
|
|
* @param {HTMLElement} itemsContainer - DOM element of the itemsContainer.
|
2020-03-19 21:16:40 +01:00
|
|
|
*/
|
2020-03-22 17:12:34 +01:00
|
|
|
export function onSeriesTimerCancelled(cancelledTimerId, itemsContainer) {
|
|
|
|
const cells = itemsContainer.querySelectorAll('.card[data-seriestimerid="' + cancelledTimerId + '"]');
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-03-19 22:33:41 +01:00
|
|
|
for (let i = 0; i < cells.length; i++) {
|
|
|
|
let cell = cells[i];
|
|
|
|
let icon = cell.querySelector('.timerIndicator');
|
2019-01-10 15:39:37 +03:00
|
|
|
if (icon) {
|
|
|
|
icon.parentNode.removeChild(icon);
|
|
|
|
}
|
|
|
|
cell.removeAttribute('data-seriestimerid');
|
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2020-03-29 00:06:27 +03:00
|
|
|
|
2020-04-02 23:45:45 +02:00
|
|
|
/* eslint-enable indent */
|
|
|
|
|
2020-03-29 00:06:27 +03:00
|
|
|
export default {
|
|
|
|
getCardsHtml: getCardsHtml,
|
|
|
|
getDefaultBackgroundClass: getDefaultBackgroundClass,
|
|
|
|
getDefaultText: getDefaultText,
|
|
|
|
buildCards: buildCards,
|
|
|
|
onUserDataChanged: onUserDataChanged,
|
|
|
|
onTimerCreated: onTimerCreated,
|
|
|
|
onTimerCancelled: onTimerCancelled,
|
|
|
|
onSeriesTimerCancelled: onSeriesTimerCancelled
|
|
|
|
};
|