jellyfish-web/src/components/indicators/indicators.js

238 lines
8.2 KiB
JavaScript
Raw Normal View History

define(['datetime', 'itemHelper', 'css!./indicators.css', 'material-icons'], function (datetime, itemHelper) {
'use strict';
2018-10-23 01:05:09 +03:00
function enableProgressIndicator(item) {
if (item.MediaType === 'Video') {
if (item.Type !== 'TvChannel') {
return true;
}
}
if (item.Type === 'AudioBook' || item.Type === 'AudioPodcast') {
return true;
}
return false;
2018-10-23 01:05:09 +03:00
}
function getProgressHtml(pct, options) {
var containerClass = 'itemProgressBar';
if (options) {
if (options.containerClass) {
containerClass += ' ' + options.containerClass;
}
}
return '<div class="' + containerClass + '"><div class="itemProgressBarForeground" style="width:' + pct + '%;"></div></div>';
2018-10-23 01:05:09 +03:00
}
function getAutoTimeProgressHtml(pct, options, isRecording, start, end) {
var containerClass = 'itemProgressBar';
if (options) {
if (options.containerClass) {
containerClass += ' ' + options.containerClass;
}
}
var foregroundClass = 'itemProgressBarForeground';
if (isRecording) {
foregroundClass += ' itemProgressBarForeground-recording';
}
return '<div is="emby-progressbar" data-automode="time" data-starttime="' + start + '" data-endtime="' + end + '" class="' + containerClass + '"><div class="' + foregroundClass + '" style="width:' + pct + '%;"></div></div>';
2018-10-23 01:05:09 +03:00
}
function getProgressBarHtml(item, options) {
var pct;
if (enableProgressIndicator(item) && item.Type !== "Recording") {
var userData = options ? (options.userData || item.UserData) : item.UserData;
if (userData) {
pct = userData.PlayedPercentage;
if (pct && pct < 100) {
return getProgressHtml(pct, options);
}
}
2018-10-23 01:05:09 +03:00
}
if ((item.Type === 'Program' || item.Type === 'Timer' || item.Type === 'Recording') && item.StartDate && item.EndDate) {
var startDate = 0;
var endDate = 1;
2018-10-23 01:05:09 +03:00
try {
startDate = datetime.parseISO8601Date(item.StartDate).getTime();
endDate = datetime.parseISO8601Date(item.EndDate).getTime();
} catch (err) {
2020-02-16 03:44:43 +01:00
console.error(err);
}
var now = new Date().getTime();
var total = endDate - startDate;
pct = 100 * ((now - startDate) / total);
if (pct > 0 && pct < 100) {
var isRecording = item.Type === 'Timer' || item.Type === 'Recording' || item.TimerId;
return getAutoTimeProgressHtml(pct, options, isRecording, startDate, endDate);
2018-10-23 01:05:09 +03:00
}
}
return '';
2018-10-23 01:05:09 +03:00
}
function enablePlayedIndicator(item) {
return itemHelper.canMarkPlayed(item);
2018-10-23 01:05:09 +03:00
}
function getPlayedIndicator(item) {
if (enablePlayedIndicator(item)) {
var userData = item.UserData || {};
if (userData.UnplayedItemCount) {
return '<div class="countIndicator indicator">' + userData.UnplayedItemCount + '</div>';
}
if (userData.PlayedPercentage && userData.PlayedPercentage >= 100 || (userData.Played)) {
return '<div class="playedIndicator indicator"><i class="material-icons indicatorIcon">check</i></div>';
}
2018-10-23 01:05:09 +03:00
}
return '';
2018-10-23 01:05:09 +03:00
}
function getCountIndicatorHtml(count) {
return '<div class="countIndicator indicator">' + count + '</div>';
2018-10-23 01:05:09 +03:00
}
function getChildCountIndicatorHtml(item, options) {
var minCount = 0;
if (options) {
minCount = options.minCount || minCount;
}
if (item.ChildCount && item.ChildCount > minCount) {
return getCountIndicatorHtml(item.ChildCount);
}
return '';
2018-10-23 01:05:09 +03:00
}
function getTimerIndicator(item) {
var status;
if (item.Type === 'SeriesTimer') {
return '<i class="material-icons timerIndicator indicatorIcon fiber_smart_record"></i>';
2019-05-02 16:03:52 -07:00
} else if (item.TimerId || item.SeriesTimerId) {
status = item.Status || 'Cancelled';
2019-05-02 16:03:52 -07:00
} else if (item.Type === 'Timer') {
status = item.Status;
2019-05-02 16:03:52 -07:00
} else {
return '';
}
if (item.SeriesTimerId) {
if (status !== 'Cancelled') {
return '<i class="material-icons timerIndicator indicatorIcon fiber_smart_record"></i>';
}
return '<i class="material-icons timerIndicator timerIndicator-inactive indicatorIcon fiber_smart_record"></i>';
2018-10-23 01:05:09 +03:00
}
return '<i class="material-icons timerIndicator indicatorIcon fiber_manual_record"></i>';
2018-10-23 01:05:09 +03:00
}
function getSyncIndicator(item) {
if (item.SyncPercent === 100) {
return '<div class="syncIndicator indicator fullSyncIndicator"><i class="material-icons indicatorIcon file_download"></i></div>';
} else if (item.SyncPercent != null) {
return '<div class="syncIndicator indicator emptySyncIndicator"><i class="material-icons indicatorIcon file_download"></i></div>';
}
return '';
2018-10-23 01:05:09 +03:00
}
function getTypeIndicator(item) {
if (item.Type === 'Video') {
return '<div class="indicator videoIndicator"><i class="material-icons indicatorIcon">videocam</i></div>';
}
2020-02-16 02:34:40 +01:00
if (item.Type === 'Folder') {
return '<div class="indicator videoIndicator"><i class="material-icons indicatorIcon">folder</i></div>';
}
2020-02-16 02:34:40 +01:00
if (item.Type === 'PhotoAlbum') {
return '<div class="indicator videoIndicator"><i class="material-icons indicatorIcon photo_album"></i></div>';
}
if (item.Type === 'Photo') {
return '<div class="indicator videoIndicator"><i class="material-icons indicatorIcon">photo</i></div>';
}
return '';
2018-10-23 01:05:09 +03:00
}
function getMissingIndicator(item) {
if (item.Type === 'Episode' && item.LocationType === 'Virtual') {
if (item.PremiereDate) {
try {
var premiereDate = datetime.parseISO8601Date(item.PremiereDate).getTime();
if (premiereDate > new Date().getTime()) {
return '<div class="unairedIndicator">Unaired</div>';
}
} catch (err) {
2020-02-16 03:44:43 +01:00
console.error(err);
}
}
return '<div class="missingIndicator">Missing</div>';
2018-10-23 01:05:09 +03:00
}
return '';
2018-10-23 01:05:09 +03:00
}
var ProgressBarPrototype = Object.create(HTMLDivElement.prototype);
2018-10-23 01:05:09 +03:00
function onAutoTimeProgress() {
var start = parseInt(this.getAttribute('data-starttime'));
var end = parseInt(this.getAttribute('data-endtime'));
var now = new Date().getTime();
var total = end - start;
var pct = 100 * ((now - start) / total);
pct = Math.min(100, pct);
pct = Math.max(0, pct);
var itemProgressBarForeground = this.querySelector('.itemProgressBarForeground');
itemProgressBarForeground.style.width = pct + '%';
2018-10-23 01:05:09 +03:00
}
ProgressBarPrototype.attachedCallback = function () {
if (this.timeInterval) {
clearInterval(this.timeInterval);
}
if (this.getAttribute('data-automode') === 'time') {
this.timeInterval = setInterval(onAutoTimeProgress.bind(this), 60000);
}
};
ProgressBarPrototype.detachedCallback = function () {
if (this.timeInterval) {
clearInterval(this.timeInterval);
this.timeInterval = null;
}
};
document.registerElement('emby-progressbar', {
2018-10-23 01:05:09 +03:00
prototype: ProgressBarPrototype,
extends: 'div'
});
return {
getProgressHtml: getProgressHtml,
2018-10-23 01:05:09 +03:00
getProgressBarHtml: getProgressBarHtml,
getPlayedIndicatorHtml: getPlayedIndicator,
getChildCountIndicatorHtml: getChildCountIndicatorHtml,
enableProgressIndicator: enableProgressIndicator,
getTimerIndicator: getTimerIndicator,
enablePlayedIndicator: enablePlayedIndicator,
getSyncIndicator: getSyncIndicator,
getTypeIndicator: getTypeIndicator,
getMissingIndicator: getMissingIndicator
};
});