jellyfin-web/dashboard-ui/bower_components/emby-webcomponents/indicators/indicators.js

168 lines
4.6 KiB
JavaScript
Raw Normal View History

2016-06-09 23:54:03 -07:00
define(['css!./indicators.css', 'material-icons'], function () {
2016-10-12 11:23:09 -07:00
'use strict';
2016-05-28 11:03:38 -07:00
function enableProgressIndicator(item) {
2016-10-12 11:23:09 -07:00
if (item.MediaType === 'Video') {
if (item.Type !== 'TvChannel') {
2016-05-28 11:03:38 -07:00
return true;
}
}
return false;
}
2016-08-07 11:46:11 -07:00
function getProgressHtml(pct, options) {
2016-05-28 11:03:38 -07:00
2016-08-07 11:46:11 -07:00
var containerClass = 'itemProgressBar';
if (options) {
if (options.containerClass) {
containerClass += ' ' + options.containerClass;
}
}
return '<div class="' + containerClass + '"><div class="itemProgressBarForeground" style="width:' + pct + '%;"></div></div>';
2016-05-28 11:03:38 -07:00
}
2016-08-07 11:46:11 -07:00
function getProgressBarHtml(item, options) {
2016-05-28 11:03:38 -07:00
if (enableProgressIndicator(item)) {
2016-10-12 11:23:09 -07:00
if (item.Type === "Recording" && item.CompletionPercentage) {
2016-05-28 11:03:38 -07:00
2016-08-07 11:46:11 -07:00
return getProgressHtml(item.CompletionPercentage, options);
2016-05-28 11:03:38 -07:00
}
2016-08-29 21:33:24 -07:00
var userData = options ? (options.userData || item.UserData) : item.UserData;
2016-05-28 11:03:38 -07:00
if (userData) {
var pct = userData.PlayedPercentage;
if (pct && pct < 100) {
2016-08-07 11:46:11 -07:00
return getProgressHtml(pct, options);
2016-05-28 11:03:38 -07:00
}
}
}
return '';
}
function enablePlayedIndicator(item) {
2016-12-11 22:41:24 -07:00
if (item.MediaType === 'Video') {
2016-10-12 11:23:09 -07:00
if (item.Type !== 'TvChannel') {
2016-05-28 11:03:38 -07:00
return true;
}
}
2016-12-11 22:41:24 -07:00
if (item.MediaType === 'Audio') {
if (item.Type === 'AudioPodcast') {
return true;
}
if (item.Type === 'AudioBook') {
return true;
}
}
if (item.Type === "Series" ||
item.Type === "Season" ||
item.Type === "BoxSet" ||
item.MediaType === "Game" ||
item.MediaType === "Book" ||
item.MediaType === "Recording") {
return true;
}
2016-05-28 11:03:38 -07:00
return false;
}
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)) {
2016-08-03 13:14:39 -07:00
return '<div class="playedIndicator indicator"><i class="md-icon indicatorIcon">&#xE5CA;</i></div>';
2016-05-28 11:03:38 -07:00
}
}
return '';
}
function getCountIndicatorHtml(count) {
return '<div class="countIndicator indicator">' + count + '</div>';
}
function getChildCountIndicatorHtml(item, options) {
var minCount = 0;
if (options) {
minCount = options.minCount || minCount;
}
if (item.ChildCount && item.ChildCount > minCount) {
return getCountIndicatorHtml(item.ChildCount);
}
return '';
}
function getTimerIndicator(item) {
2016-08-02 23:38:19 -07:00
2016-10-03 22:15:39 -07:00
var status;
2016-10-12 11:23:09 -07:00
if (item.Type === 'SeriesTimer') {
2016-10-03 22:15:39 -07:00
return '<i class="md-icon timerIndicator indicatorIcon">&#xE062;</i>';
}
2016-10-10 23:46:59 -07:00
else if (item.TimerId || item.SeriesTimerId) {
2016-10-03 22:15:39 -07:00
2016-10-10 23:46:59 -07:00
status = item.Status || 'Cancelled';
2016-10-03 22:15:39 -07:00
}
2016-10-12 11:23:09 -07:00
else if (item.Type === 'Timer') {
2016-10-03 22:15:39 -07:00
status = item.Status;
}
else {
return '';
}
if (item.SeriesTimerId) {
2016-10-12 11:23:09 -07:00
if (status !== 'Cancelled') {
2016-09-21 23:57:31 -07:00
return '<i class="md-icon timerIndicator indicatorIcon">&#xE062;</i>';
}
2016-10-03 22:15:39 -07:00
return '<i class="md-icon timerIndicator timerIndicator-inactive indicatorIcon">&#xE062;</i>';
2016-05-28 11:03:38 -07:00
}
2016-10-03 22:15:39 -07:00
return '<i class="md-icon timerIndicator indicatorIcon">&#xE061;</i>';
2016-05-28 11:03:38 -07:00
}
2016-08-02 23:38:19 -07:00
function getSyncIndicator(item) {
2016-10-12 11:23:09 -07:00
if (item.SyncPercent === 100) {
2016-08-16 22:29:05 -07:00
return '<div class="syncIndicator indicator fullSyncIndicator"><i class="md-icon indicatorIcon">file_download</i></div>';
2016-08-02 23:38:19 -07:00
} else if (item.SyncPercent != null) {
2016-08-03 13:14:39 -07:00
return '<div class="syncIndicator indicator emptySyncIndicator"><i class="md-icon indicatorIcon">file_download</i></div>';
2016-08-02 23:38:19 -07:00
}
return '';
}
2016-05-28 11:03:38 -07:00
return {
getProgressBarHtml: getProgressBarHtml,
getPlayedIndicatorHtml: getPlayedIndicator,
getChildCountIndicatorHtml: getChildCountIndicatorHtml,
enableProgressIndicator: enableProgressIndicator,
getTimerIndicator: getTimerIndicator,
2016-08-02 23:38:19 -07:00
enablePlayedIndicator: enablePlayedIndicator,
getSyncIndicator: getSyncIndicator
2016-05-28 11:03:38 -07:00
};
});