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

370 lines
13 KiB
JavaScript
Raw Normal View History

2020-05-04 12:44:12 +02:00
define(['connectionManager', 'listView', 'cardBuilder', 'imageLoader', 'libraryBrowser', 'globalize', 'emby-itemscontainer', 'emby-button'], function (connectionManager, listView, cardBuilder, imageLoader, libraryBrowser, globalize) {
'use strict';
2018-10-23 01:05:09 +03:00
function renderItems(page, item) {
var sections = [];
2019-10-08 00:57:40 +03:00
if (item.ArtistCount) {
sections.push({
name: globalize.translate('Artists'),
2020-05-04 12:44:12 +02:00
type: 'MusicArtist'
2019-10-08 00:57:40 +03:00
});
}
2020-07-30 16:07:13 +02:00
if (item.ProgramCount && item.Type == 'Person') {
2019-10-08 00:57:40 +03:00
sections.push({
2020-05-04 12:44:12 +02:00
name: globalize.translate('HeaderUpcomingOnTV'),
type: 'Program'
2019-10-08 00:57:40 +03:00
});
}
if (item.MovieCount) {
sections.push({
2020-05-04 12:44:12 +02:00
name: globalize.translate('TabMovies'),
type: 'Movie'
2019-10-08 00:57:40 +03:00
});
}
if (item.SeriesCount) {
sections.push({
2020-05-04 12:44:12 +02:00
name: globalize.translate('TabShows'),
type: 'Series'
2019-10-08 00:57:40 +03:00
});
}
if (item.EpisodeCount) {
sections.push({
2020-05-04 12:44:12 +02:00
name: globalize.translate('TabEpisodes'),
type: 'Episode'
2019-10-08 00:57:40 +03:00
});
}
if (item.TrailerCount) {
sections.push({
2020-05-04 12:44:12 +02:00
name: globalize.translate('TabTrailers'),
type: 'Trailer'
2019-10-08 00:57:40 +03:00
});
}
if (item.AlbumCount) {
sections.push({
2020-05-04 12:44:12 +02:00
name: globalize.translate('TabAlbums'),
type: 'MusicAlbum'
2019-10-08 00:57:40 +03:00
});
}
if (item.MusicVideoCount) {
sections.push({
2020-05-04 12:44:12 +02:00
name: globalize.translate('TabMusicVideos'),
type: 'MusicVideo'
2019-10-08 00:57:40 +03:00
});
}
2020-05-04 12:44:12 +02:00
var elem = page.querySelector('#childrenContent');
2019-10-08 00:57:40 +03:00
elem.innerHTML = sections.map(function (section) {
2020-05-04 12:44:12 +02:00
var html = '';
var sectionClass = 'verticalSection';
2019-10-08 00:57:40 +03:00
2020-07-30 16:07:13 +02:00
if (section.type === 'Audio') {
2020-05-04 12:44:12 +02:00
sectionClass += ' verticalSection-extrabottompadding';
2019-10-08 00:57:40 +03:00
}
html += '<div class="' + sectionClass + '" data-type="' + section.type + '">';
html += '<div class="sectionTitleContainer sectionTitleContainer-cards">';
html += '<h2 class="sectionTitle sectionTitle-cards">';
2019-10-08 00:57:40 +03:00
html += section.name;
2020-05-04 12:44:12 +02:00
html += '</h2>';
html += '<a is="emby-linkbutton" href="#" class="clearLink hide" style="margin-left:1em;vertical-align:middle;"><button is="emby-button" type="button" class="raised more raised-mini noIcon">' + globalize.translate('ButtonMore') + '</button></a>';
html += '</div>';
html += '<div is="emby-itemscontainer" class="itemsContainer padded-right">';
2020-05-04 12:44:12 +02:00
html += '</div>';
return html += '</div>';
}).join('');
var sectionElems = elem.querySelectorAll('.verticalSection');
2019-10-08 00:57:40 +03:00
for (var i = 0, length = sectionElems.length; i < length; i++) {
2020-05-04 12:44:12 +02:00
renderSection(page, item, sectionElems[i], sectionElems[i].getAttribute('data-type'));
2019-10-08 00:57:40 +03:00
}
2018-10-23 01:05:09 +03:00
}
function renderSection(page, item, element, type) {
switch (type) {
2020-05-04 12:44:12 +02:00
case 'Program':
2018-10-23 01:05:09 +03:00
loadItems(element, item, type, {
2020-05-04 12:44:12 +02:00
MediaTypes: '',
IncludeItemTypes: 'Program',
PersonTypes: '',
ArtistIds: '',
AlbumArtistIds: '',
2018-10-23 01:05:09 +03:00
Limit: 10,
2020-05-04 12:44:12 +02:00
SortBy: 'StartDate'
2018-10-23 01:05:09 +03:00
}, {
2020-05-04 12:44:12 +02:00
shape: 'overflowBackdrop',
2019-10-08 00:57:40 +03:00
showTitle: true,
centerText: true,
overlayMoreButton: true,
preferThumb: true,
overlayText: false,
showAirTime: true,
showAirDateTime: true,
showChannelName: true
2018-10-23 01:05:09 +03:00
});
break;
2019-10-08 00:57:40 +03:00
2020-05-04 12:44:12 +02:00
case 'Movie':
2018-10-23 01:05:09 +03:00
loadItems(element, item, type, {
2020-05-04 12:44:12 +02:00
MediaTypes: '',
IncludeItemTypes: 'Movie',
PersonTypes: '',
ArtistIds: '',
AlbumArtistIds: '',
2018-10-23 01:05:09 +03:00
Limit: 10,
2020-05-04 12:44:12 +02:00
SortBy: 'SortName'
2018-10-23 01:05:09 +03:00
}, {
2020-05-04 12:44:12 +02:00
shape: 'overflowPortrait',
2019-10-08 00:57:40 +03:00
showTitle: true,
centerText: true,
overlayMoreButton: true,
overlayText: false,
showYear: true
2018-10-23 01:05:09 +03:00
});
break;
2019-10-08 00:57:40 +03:00
2020-05-04 12:44:12 +02:00
case 'MusicVideo':
2018-10-23 01:05:09 +03:00
loadItems(element, item, type, {
2020-05-04 12:44:12 +02:00
MediaTypes: '',
IncludeItemTypes: 'MusicVideo',
PersonTypes: '',
ArtistIds: '',
AlbumArtistIds: '',
2018-10-23 01:05:09 +03:00
Limit: 10,
2020-05-04 12:44:12 +02:00
SortBy: 'SortName'
2018-10-23 01:05:09 +03:00
}, {
2020-05-04 12:44:12 +02:00
shape: 'overflowPortrait',
2019-10-08 00:57:40 +03:00
showTitle: true,
centerText: true,
overlayPlayButton: true
2018-10-23 01:05:09 +03:00
});
break;
2019-10-08 00:57:40 +03:00
2020-05-04 12:44:12 +02:00
case 'Trailer':
2018-10-23 01:05:09 +03:00
loadItems(element, item, type, {
2020-05-04 12:44:12 +02:00
MediaTypes: '',
IncludeItemTypes: 'Trailer',
PersonTypes: '',
ArtistIds: '',
AlbumArtistIds: '',
2018-10-23 01:05:09 +03:00
Limit: 10,
2020-05-04 12:44:12 +02:00
SortBy: 'SortName'
2018-10-23 01:05:09 +03:00
}, {
2020-05-04 12:44:12 +02:00
shape: 'overflowPortrait',
2019-10-08 00:57:40 +03:00
showTitle: true,
centerText: true,
overlayPlayButton: true
2018-10-23 01:05:09 +03:00
});
break;
2019-10-08 00:57:40 +03:00
2020-05-04 12:44:12 +02:00
case 'Series':
2018-10-23 01:05:09 +03:00
loadItems(element, item, type, {
2020-05-04 12:44:12 +02:00
MediaTypes: '',
IncludeItemTypes: 'Series',
PersonTypes: '',
ArtistIds: '',
AlbumArtistIds: '',
2018-10-23 01:05:09 +03:00
Limit: 10,
2020-05-04 12:44:12 +02:00
SortBy: 'SortName'
2018-10-23 01:05:09 +03:00
}, {
2020-05-04 12:44:12 +02:00
shape: 'overflowPortrait',
2019-10-08 00:57:40 +03:00
showTitle: true,
centerText: true,
overlayMoreButton: true
2018-10-23 01:05:09 +03:00
});
break;
2019-10-08 00:57:40 +03:00
2020-05-04 12:44:12 +02:00
case 'MusicAlbum':
2018-10-23 01:05:09 +03:00
loadItems(element, item, type, {
2020-05-04 12:44:12 +02:00
MediaTypes: '',
IncludeItemTypes: 'MusicAlbum',
PersonTypes: '',
ArtistIds: '',
AlbumArtistIds: '',
SortOrder: 'Descending',
SortBy: 'ProductionYear,Sortname'
2018-10-23 01:05:09 +03:00
}, {
2020-05-04 12:44:12 +02:00
shape: 'overflowSquare',
2019-10-08 00:57:40 +03:00
playFromHere: true,
showTitle: true,
showYear: true,
coverImage: true,
centerText: true,
overlayPlayButton: true
2018-10-23 01:05:09 +03:00
});
break;
2019-10-08 00:57:40 +03:00
2020-05-04 12:44:12 +02:00
case 'MusicArtist':
2018-10-23 01:05:09 +03:00
loadItems(element, item, type, {
2020-05-04 12:44:12 +02:00
MediaTypes: '',
IncludeItemTypes: 'MusicArtist',
PersonTypes: '',
ArtistIds: '',
AlbumArtistIds: '',
2018-10-23 01:05:09 +03:00
Limit: 8,
2020-05-04 12:44:12 +02:00
SortBy: 'SortName'
2018-10-23 01:05:09 +03:00
}, {
2020-05-04 12:44:12 +02:00
shape: 'overflowSquare',
2019-10-08 00:57:40 +03:00
playFromHere: true,
showTitle: true,
showParentTitle: true,
coverImage: true,
centerText: true,
overlayPlayButton: true
2018-10-23 01:05:09 +03:00
});
break;
2019-10-08 00:57:40 +03:00
2020-05-04 12:44:12 +02:00
case 'Episode':
2018-10-23 01:05:09 +03:00
loadItems(element, item, type, {
2020-05-04 12:44:12 +02:00
MediaTypes: '',
IncludeItemTypes: 'Episode',
PersonTypes: '',
ArtistIds: '',
AlbumArtistIds: '',
2018-10-23 01:05:09 +03:00
Limit: 6,
2020-05-04 12:44:12 +02:00
SortBy: 'SortName'
2018-10-23 01:05:09 +03:00
}, {
2020-05-04 12:44:12 +02:00
shape: 'overflowBackdrop',
2019-10-08 00:57:40 +03:00
showTitle: true,
showParentTitle: true,
centerText: true,
overlayPlayButton: true
2018-10-23 01:05:09 +03:00
});
break;
2019-10-08 00:57:40 +03:00
2020-05-04 12:44:12 +02:00
case 'Audio':
2018-10-23 01:05:09 +03:00
loadItems(element, item, type, {
2020-05-04 12:44:12 +02:00
MediaTypes: '',
IncludeItemTypes: 'Audio',
PersonTypes: '',
ArtistIds: '',
AlbumArtistIds: '',
SortBy: 'AlbumArtist,Album,SortName'
2018-10-23 01:05:09 +03:00
}, {
2019-10-08 00:57:40 +03:00
playFromHere: true,
2020-05-04 12:44:12 +02:00
action: 'playallfromhere',
2019-10-08 00:57:40 +03:00
smallIcon: true,
artist: true
});
2018-10-23 01:05:09 +03:00
}
}
function loadItems(element, item, type, query, listOptions) {
2019-10-08 00:57:40 +03:00
query = getQuery(query, item);
getItemsFunction(query, item)(query.StartIndex, query.Limit, query.Fields).then(function (result) {
2020-05-04 12:44:12 +02:00
var html = '';
2019-10-08 00:57:40 +03:00
2018-10-23 01:05:09 +03:00
if (query.Limit && result.TotalRecordCount > query.Limit) {
2020-05-04 12:44:12 +02:00
var link = element.querySelector('a');
link.classList.remove('hide');
link.setAttribute('href', getMoreItemsHref(item, type));
2019-10-08 00:57:40 +03:00
} else {
2020-05-04 12:44:12 +02:00
element.querySelector('a').classList.add('hide');
2019-10-08 00:57:40 +03:00
}
2018-10-23 01:05:09 +03:00
listOptions.items = result.Items;
2020-05-04 12:44:12 +02:00
var itemsContainer = element.querySelector('.itemsContainer');
2019-10-08 00:57:40 +03:00
2020-07-30 16:07:13 +02:00
if (type == 'Audio') {
2019-10-08 00:57:40 +03:00
html = listView.getListViewHtml(listOptions);
2020-05-04 12:44:12 +02:00
itemsContainer.classList.remove('vertical-wrap');
itemsContainer.classList.add('vertical-list');
2019-10-08 00:57:40 +03:00
} else {
html = cardBuilder.getCardsHtml(listOptions);
2020-05-04 12:44:12 +02:00
itemsContainer.classList.add('vertical-wrap');
itemsContainer.classList.remove('vertical-list');
2019-10-08 00:57:40 +03:00
}
itemsContainer.innerHTML = html;
imageLoader.lazyChildren(itemsContainer);
});
2018-10-23 01:05:09 +03:00
}
function getMoreItemsHref(item, type) {
2020-07-30 16:07:13 +02:00
if (item.Type == 'Genre') {
2020-05-04 12:44:12 +02:00
return 'list.html?type=' + type + '&genreId=' + item.Id + '&serverId=' + item.ServerId;
2019-10-08 00:57:40 +03:00
}
2020-07-30 16:07:13 +02:00
if (item.Type == 'MusicGenre') {
2020-05-04 12:44:12 +02:00
return 'list.html?type=' + type + '&musicGenreId=' + item.Id + '&serverId=' + item.ServerId;
2019-10-08 00:57:40 +03:00
}
2020-07-30 16:07:13 +02:00
if (item.Type == 'Studio') {
2020-05-04 12:44:12 +02:00
return 'list.html?type=' + type + '&studioId=' + item.Id + '&serverId=' + item.ServerId;
2019-10-08 00:57:40 +03:00
}
2020-07-30 16:07:13 +02:00
if (item.Type == 'MusicArtist') {
2020-05-04 12:44:12 +02:00
return 'list.html?type=' + type + '&artistId=' + item.Id + '&serverId=' + item.ServerId;
2019-10-08 00:57:40 +03:00
}
2020-07-30 16:07:13 +02:00
if (item.Type == 'Person') {
2020-05-04 12:44:12 +02:00
return 'list.html?type=' + type + '&personId=' + item.Id + '&serverId=' + item.ServerId;
2019-10-08 00:57:40 +03:00
}
2020-05-04 12:44:12 +02:00
return 'list.html?type=' + type + '&parentId=' + item.Id + '&serverId=' + item.ServerId;
2018-10-23 01:05:09 +03:00
}
function addCurrentItemToQuery(query, item) {
2020-05-04 12:44:12 +02:00
if (item.Type == 'Person') {
2019-10-08 00:57:40 +03:00
query.PersonIds = item.Id;
2020-05-04 12:44:12 +02:00
} else if (item.Type == 'Genre') {
2019-10-08 19:54:02 +03:00
query.Genres = item.Name;
2020-05-04 12:44:12 +02:00
} else if (item.Type == 'MusicGenre') {
2019-10-08 19:54:02 +03:00
query.Genres = item.Name;
2020-05-04 12:44:12 +02:00
} else if (item.Type == 'GameGenre') {
2019-10-08 19:54:02 +03:00
query.Genres = item.Name;
2020-05-04 12:44:12 +02:00
} else if (item.Type == 'Studio') {
2019-10-08 19:54:02 +03:00
query.StudioIds = item.Id;
2020-05-04 12:44:12 +02:00
} else if (item.Type == 'MusicArtist') {
2019-10-10 20:43:04 +03:00
query.AlbumArtistIds = item.Id;
2019-10-08 00:57:40 +03:00
}
2018-10-23 01:05:09 +03:00
}
function getQuery(options, item) {
var query = {
2020-05-04 12:44:12 +02:00
SortOrder: 'Ascending',
IncludeItemTypes: '',
2019-10-08 00:57:40 +03:00
Recursive: true,
2020-05-04 12:44:12 +02:00
Fields: 'AudioInfo,SeriesInfo,ParentId,PrimaryImageAspectRatio,BasicSyncInfo',
2018-10-23 01:05:09 +03:00
Limit: 100,
StartIndex: 0,
2019-10-08 00:57:40 +03:00
CollapseBoxSetItems: false
2018-10-23 01:05:09 +03:00
};
2019-10-08 00:57:40 +03:00
query = Object.assign(query, options || {});
addCurrentItemToQuery(query, item);
return query;
2018-10-23 01:05:09 +03:00
}
function getItemsFunction(options, item) {
var query = getQuery(options, item);
2019-10-08 00:57:40 +03:00
return function (index, limit, fields) {
query.StartIndex = index;
query.Limit = limit;
if (fields) {
2020-05-04 12:44:12 +02:00
query.Fields += ',' + fields;
2019-10-08 00:57:40 +03:00
}
2018-10-23 01:05:09 +03:00
var apiClient = connectionManager.getApiClient(item.ServerId);
2019-10-08 00:57:40 +03:00
2020-07-30 16:07:13 +02:00
if (query.IncludeItemTypes === 'MusicArtist') {
2019-10-08 00:57:40 +03:00
query.IncludeItemTypes = null;
return apiClient.getAlbumArtists(apiClient.getCurrentUserId(), query);
}
return apiClient.getItems(apiClient.getCurrentUserId(), query);
};
2018-10-23 01:05:09 +03:00
}
2019-10-08 00:57:40 +03:00
2018-10-23 01:05:09 +03:00
window.ItemsByName = {
renderItems: renderItems
2019-10-08 00:57:40 +03:00
};
2019-01-27 22:10:07 +01:00
});