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

Migration of itemhelper to ES6 module

This commit is contained in:
Cameron 2020-07-29 10:05:16 +01:00
parent da5eb9ccc4
commit f93c93f870
2 changed files with 314 additions and 305 deletions

View file

@ -119,6 +119,7 @@
"src/components/imageUploader/imageUploader.js",
"src/components/indicators/indicators.js",
"src/components/itemContextMenu.js",
"src/components/itemHelper.js",
"src/components/itemidentifier/itemidentifier.js",
"src/components/itemMediaInfo/itemMediaInfo.js",
"src/components/lazyLoader/lazyLoaderIntersectionObserver.js",

View file

@ -1,7 +1,7 @@
define(['apphost', 'globalize'], function (appHost, globalize) {
'use strict';
import appHost from 'apphost';
import globalize from 'globalize';
function getDisplayName(item, options = {}) {
export function getDisplayName(item, options = {}) {
if (!item) {
throw new Error('null item passed into getDisplayName');
}
@ -10,7 +10,7 @@ define(['apphost', 'globalize'], function (appHost, globalize) {
item = item.ProgramInfo || item;
}
var name = ((item.Type === 'Program' || item.Type === 'Recording') && (item.IsSeries || item.EpisodeTitle) ? item.EpisodeTitle : item.Name) || '';
let name = ((item.Type === 'Program' || item.Type === 'Recording') && (item.IsSeries || item.EpisodeTitle) ? item.EpisodeTitle : item.Name) || '';
if (item.Type === 'TvChannel') {
if (item.ChannelNumber) {
@ -21,10 +21,10 @@ define(['apphost', 'globalize'], function (appHost, globalize) {
if (item.Type === 'Episode' && item.ParentIndexNumber === 0) {
name = globalize.translate('ValueSpecialEpisodeName', name);
} else if ((item.Type === 'Episode' || item.Type === 'Program') && item.IndexNumber != null && item.ParentIndexNumber != null && options.includeIndexNumber !== false) {
var displayIndexNumber = item.IndexNumber;
let displayIndexNumber = item.IndexNumber;
var number = displayIndexNumber;
var nameSeparator = ' - ';
let number = displayIndexNumber;
let nameSeparator = ' - ';
if (options.includeParentInfo !== false) {
number = 'S' + item.ParentIndexNumber + ':E' + number;
@ -43,10 +43,10 @@ define(['apphost', 'globalize'], function (appHost, globalize) {
}
return name;
}
}
function supportsAddingToCollection(item) {
var invalidTypes = ['Genre', 'MusicGenre', 'Studio', 'UserView', 'CollectionFolder', 'Audio', 'Program', 'Timer', 'SeriesTimer'];
export function supportsAddingToCollection(item) {
const invalidTypes = ['Genre', 'MusicGenre', 'Studio', 'UserView', 'CollectionFolder', 'Audio', 'Program', 'Timer', 'SeriesTimer'];
if (item.Type === 'Recording') {
if (item.Status !== 'Completed') {
@ -55,9 +55,9 @@ define(['apphost', 'globalize'], function (appHost, globalize) {
}
return !item.CollectionType && invalidTypes.indexOf(item.Type) === -1 && item.MediaType !== 'Photo' && !isLocalItem(item);
}
}
function supportsAddingToPlaylist(item) {
export function supportsAddingToPlaylist(item) {
if (item.Type === 'Program') {
return false;
}
@ -88,10 +88,10 @@ define(['apphost', 'globalize'], function (appHost, globalize) {
}
return item.MediaType || item.IsFolder || item.Type === 'Genre' || item.Type === 'MusicGenre' || item.Type === 'MusicArtist';
}
}
function canEdit(user, item) {
var itemType = item.Type;
export function canEdit(user, item) {
const itemType = item.Type;
if (itemType === 'UserRootFolder' || itemType === 'UserView') {
return false;
@ -120,24 +120,18 @@ define(['apphost', 'globalize'], function (appHost, globalize) {
}
return user.Policy.IsAdministrator;
}
}
function isLocalItem(item) {
export function isLocalItem(item) {
if (item && item.Id && item.Id.indexOf('local') === 0) {
return true;
}
return false;
}
}
return {
getDisplayName: getDisplayName,
supportsAddingToCollection: supportsAddingToCollection,
supportsAddingToPlaylist: supportsAddingToPlaylist,
isLocalItem: isLocalItem,
canIdentify: function (user, item) {
var itemType = item.Type;
export function canIdentify (user, item) {
const itemType = item.Type;
if (itemType === 'Movie' ||
itemType === 'Trailer' ||
@ -156,12 +150,10 @@ define(['apphost', 'globalize'], function (appHost, globalize) {
}
return false;
},
}
canEdit: canEdit,
canEditImages: function (user, item) {
var itemType = item.Type;
export function canEditImages (user, item) {
const itemType = item.Type;
if (item.MediaType === 'Photo') {
return false;
@ -182,9 +174,9 @@ define(['apphost', 'globalize'], function (appHost, globalize) {
}
return itemType !== 'Timer' && itemType !== 'SeriesTimer' && canEdit(user, item) && !isLocalItem(item);
},
}
canSync: function (user, item) {
export function canSync (user, item) {
if (user && !user.Policy.EnableContentDownloading) {
return false;
}
@ -194,9 +186,9 @@ define(['apphost', 'globalize'], function (appHost, globalize) {
}
return item.SupportsSync;
},
}
canShare: function (item, user) {
export function canShare (item, user) {
if (item.Type === 'Program') {
return false;
}
@ -218,13 +210,13 @@ define(['apphost', 'globalize'], function (appHost, globalize) {
return false;
}
return user.Policy.EnablePublicSharing && appHost.supports('sharing');
},
}
enableDateAddedDisplay: function (item) {
export function enableDateAddedDisplay (item) {
return !item.IsFolder && item.MediaType && item.Type !== 'Program' && item.Type !== 'TvChannel' && item.Type !== 'Trailer';
},
}
canMarkPlayed: function (item) {
export function canMarkPlayed (item) {
if (item.Type === 'Program') {
return false;
}
@ -251,9 +243,9 @@ define(['apphost', 'globalize'], function (appHost, globalize) {
}
return false;
},
}
canRate: function (item) {
export function canRate (item) {
if (item.Type === 'Program'
|| item.Type === 'Timer'
|| item.Type === 'SeriesTimer'
@ -265,9 +257,9 @@ define(['apphost', 'globalize'], function (appHost, globalize) {
}
return true;
},
}
canConvert: function (item, user) {
export function canConvert (item, user) {
if (!user.Policy.EnableMediaConversion) {
return false;
}
@ -276,17 +268,17 @@ define(['apphost', 'globalize'], function (appHost, globalize) {
return false;
}
var mediaType = item.MediaType;
const mediaType = item.MediaType;
if (mediaType === 'Book' || mediaType === 'Photo' || mediaType === 'Audio') {
return false;
}
var collectionType = item.CollectionType;
const collectionType = item.CollectionType;
if (collectionType === 'livetv') {
return false;
}
var type = item.Type;
const type = item.Type;
if (type === 'Channel' || type === 'Person' || type === 'Year' || type === 'Program' || type === 'Timer' || type === 'SeriesTimer') {
return false;
}
@ -300,11 +292,11 @@ define(['apphost', 'globalize'], function (appHost, globalize) {
}
return true;
},
}
canRefreshMetadata: function (item, user) {
export function canRefreshMetadata (item, user) {
if (user.Policy.IsAdministrator) {
var collectionType = item.CollectionType;
const collectionType = item.CollectionType;
if (collectionType === 'livetv') {
return false;
}
@ -317,9 +309,9 @@ define(['apphost', 'globalize'], function (appHost, globalize) {
}
return false;
},
}
supportsMediaSourceSelection: function (item) {
export function supportsMediaSourceSelection (item) {
if (item.MediaType !== 'Video') {
return false;
}
@ -337,6 +329,22 @@ define(['apphost', 'globalize'], function (appHost, globalize) {
}
return true;
}
};
});
}
export default {
getDisplayName: getDisplayName,
supportsAddingToCollection: supportsAddingToCollection,
supportsAddingToPlaylist: supportsAddingToPlaylist,
isLocalItem: isLocalItem,
canIdentify: canIdentify,
canEdit: canEdit,
canEditImages: canEditImages,
canSync: canSync,
canShare: canShare,
enableDateAddedDisplay: enableDateAddedDisplay,
canMarkPlayed: canMarkPlayed,
canRate: canRate,
canConvert: canConvert,
canRefreshMetadata: canRefreshMetadata,
supportsMediaSourceSelection: supportsMediaSourceSelection
};