1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00
jellyfin-web/src/components/indicators/indicators.js

184 lines
6.6 KiB
JavaScript
Raw Normal View History

2020-05-04 16:08:52 +05:30
import datetime from 'datetime';
import itemHelper from 'itemHelper';
import 'emby-progressbar';
import 'css!./indicators.css';
import 'material-icons';
export function enableProgressIndicator(item) {
if (item.MediaType === 'Video' && item.Type !== 'TvChannel') {
return true;
}
if (item.Type === 'AudioBook' || item.Type === 'AudioPodcast') {
return true;
}
return false;
2018-10-23 01:05:09 +03:00
}
2020-05-04 16:08:52 +05:30
export function getProgressHtml(pct, options) {
2020-05-10 21:35:30 +05:30
let containerClass = 'itemProgressBar';
2020-05-10 14:46:28 +05:30
if(options && options.containerClass) {
2020-05-10 21:35:30 +05:30
containerClass += ' ' + options.containerClass
2020-05-10 14:46:28 +05:30
}
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) {
2020-05-10 21:35:30 +05:30
let containerClass = 'itemProgressBar';
2020-05-10 14:46:28 +05:30
if(options && options.containerClass) {
2020-05-10 21:35:30 +05:30
containerClass += ' ' + options.containerClass
2020-05-10 14:46:28 +05:30
}
2020-05-10 21:35:30 +05:30
let foregroundClass = 'itemProgressBarForeground';
2020-05-10 14:46:28 +05:30
if (isRecording) {
2020-05-10 21:35:30 +05:30
foregroundClass += ' itemProgressBarForeground-recording';
2020-05-10 14:46:28 +05:30
}
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
}
2020-05-04 16:08:52 +05:30
export function getProgressBarHtml(item, options) {
2020-05-10 14:46:28 +05:30
let pct;
if (enableProgressIndicator(item) && item.Type !== "Recording") {
const userData = options && options.userData ? options.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) {
2020-05-10 14:46:28 +05:30
let startDate = 0;
let 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);
}
2020-05-10 14:46:28 +05:30
const now = new Date().getTime();
const total = endDate - startDate;
pct = 100 * ((now - startDate) / total);
if (pct > 0 && pct < 100) {
2020-05-10 14:46:28 +05:30
const 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
}
2020-05-04 16:08:52 +05:30
export function enablePlayedIndicator(item) {
return itemHelper.canMarkPlayed(item);
2018-10-23 01:05:09 +03:00
}
2020-05-04 16:08:52 +05:30
export function getPlayedIndicatorHtml(item) {
2018-10-23 01:05:09 +03:00
if (enablePlayedIndicator(item)) {
2020-05-10 14:46:28 +05:30
let userData = item.UserData || {};
if (userData.UnplayedItemCount) {
return '<div class="countIndicator indicator">' + userData.UnplayedItemCount + '</div>';
}
2020-05-10 14:57:47 +05:30
if (userData.PlayedPercentage && userData.PlayedPercentage >= 100 || (userData.Played)) {
2020-04-26 02:37:28 +03:00
return '<div class="playedIndicator indicator"><span class="material-icons indicatorIcon check"></span></div>';
}
2018-10-23 01:05:09 +03:00
}
return '';
2018-10-23 01:05:09 +03:00
}
2020-05-04 16:08:52 +05:30
export function getChildCountIndicatorHtml(item, options) {
2020-05-10 14:46:28 +05:30
const minCount = options && options.minCount ? options.minCount : 0;
if (item.ChildCount && item.ChildCount > minCount) {
2020-05-04 16:08:52 +05:30
return '<div class="countIndicator indicator">' + item.ChildCount + '</div>';
}
return '';
2018-10-23 01:05:09 +03:00
}
2020-05-04 16:08:52 +05:30
export function getTimerIndicator(item) {
2020-05-10 14:46:28 +05:30
let status;
if (item.Type === 'SeriesTimer') {
2020-05-04 16:35:36 +05:30
return '<span class="material-icons timerIndicator indicatorIcon fiber_smart_record"></span>';
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') {
2020-05-04 16:35:36 +05:30
return '<span class="material-icons timerIndicator indicatorIcon fiber_smart_record"></span>';
}
2020-05-04 16:35:36 +05:30
return '<span class="material-icons timerIndicator timerIndicator-inactive indicatorIcon fiber_smart_record"></span>';
2018-10-23 01:05:09 +03:00
}
2020-05-04 16:35:36 +05:30
return '<span class="material-icons timerIndicator indicatorIcon fiber_manual_record"></span>';
2018-10-23 01:05:09 +03:00
}
2020-05-04 16:08:52 +05:30
export function getSyncIndicator(item) {
if (item.SyncPercent === 100) {
2020-05-04 16:35:36 +05:30
return '<div class="syncIndicator indicator fullSyncIndicator"><span class="material-icons indicatorIcon file_download"></span></div>';
} else if (item.SyncPercent != null) {
2020-05-04 16:35:36 +05:30
return '<div class="syncIndicator indicator emptySyncIndicator"><span class="material-icons indicatorIcon file_download"></span></div>';
}
return '';
2018-10-23 01:05:09 +03:00
}
2020-05-04 16:08:52 +05:30
export function getTypeIndicator(item) {
2020-05-04 16:35:36 +05:30
const iconT = {
'Video' : 'videocam',
'Folder' : 'folder',
'PhotoAlbum' : 'photo_album',
'Photo' : 'photo'
}
2020-05-10 21:35:30 +05:30
const icon = iconT[item.Type];
2020-05-10 14:46:28 +05:30
return icon ? '<div class="indicator videoIndicator"><span class="material-icons indicatorIcon '+ icon +'"></span></div>' : '';
2018-10-23 01:05:09 +03:00
}
2020-05-04 16:08:52 +05:30
export function getMissingIndicator(item) {
if (item.Type === 'Episode' && item.LocationType === 'Virtual') {
if (item.PremiereDate) {
try {
2020-05-10 14:46:28 +05:30
const 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
}
2020-05-04 16:08:52 +05:30
export default {
getProgressHtml: getProgressHtml,
2018-10-23 01:05:09 +03:00
getProgressBarHtml: getProgressBarHtml,
2020-05-04 16:08:52 +05:30
getPlayedIndicatorHtml: getPlayedIndicatorHtml,
2018-10-23 01:05:09 +03:00
getChildCountIndicatorHtml: getChildCountIndicatorHtml,
enableProgressIndicator: enableProgressIndicator,
getTimerIndicator: getTimerIndicator,
enablePlayedIndicator: enablePlayedIndicator,
getSyncIndicator: getSyncIndicator,
getTypeIndicator: getTypeIndicator,
getMissingIndicator: getMissingIndicator
};