Merge pull request #1757 from matjaz321/migrated-itembydetailpage-to-es6-moduel

Migrated itembydetailpage to es6 moduel
This commit is contained in:
Anthony Lavado 2020-08-10 15:09:03 -04:00 committed by GitHub
commit f492bf4558
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 360 additions and 354 deletions

View File

@ -318,6 +318,7 @@
"src/scripts/filesystem.js",
"src/scripts/globalize.js",
"src/scripts/imagehelper.js",
"src/scripts/itembynamedetailpage.js",
"src/scripts/inputManager.js",
"src/scripts/autoThemes.js",
"src/scripts/themeManager.js",

View File

@ -1,8 +1,13 @@
define(['connectionManager', 'listView', 'cardBuilder', 'imageLoader', 'libraryBrowser', 'globalize', 'emby-itemscontainer', 'emby-button'], function (connectionManager, listView, cardBuilder, imageLoader, libraryBrowser, globalize) {
'use strict';
import connectionManager from 'connectionManager';
import listView from 'listView';
import cardBuilder from 'cardBuilder';
import imageLoader from 'imageLoader';
import globalize from 'globalize';
import 'emby-itemscontainer';
import 'emby-button';
function renderItems(page, item) {
var sections = [];
function renderItems(page, item) {
const sections = [];
if (item.ArtistCount) {
sections.push({
@ -11,7 +16,7 @@ define(['connectionManager', 'listView', 'cardBuilder', 'imageLoader', 'libraryB
});
}
if (item.ProgramCount && item.Type == 'Person') {
if (item.ProgramCount && item.Type === 'Person') {
sections.push({
name: globalize.translate('HeaderUpcomingOnTV'),
type: 'Program'
@ -60,10 +65,10 @@ define(['connectionManager', 'listView', 'cardBuilder', 'imageLoader', 'libraryB
});
}
var elem = page.querySelector('#childrenContent');
const elem = page.querySelector('#childrenContent');
elem.innerHTML = sections.map(function (section) {
var html = '';
var sectionClass = 'verticalSection';
let html = '';
let sectionClass = 'verticalSection';
if (section.type === 'Audio') {
sectionClass += ' verticalSection-extrabottompadding';
@ -78,16 +83,17 @@ define(['connectionManager', 'listView', 'cardBuilder', 'imageLoader', 'libraryB
html += '</div>';
html += '<div is="emby-itemscontainer" class="itemsContainer padded-right">';
html += '</div>';
return html += '</div>';
html += '</div>';
return html;
}).join('');
var sectionElems = elem.querySelectorAll('.verticalSection');
const sectionElems = elem.querySelectorAll('.verticalSection');
for (var i = 0, length = sectionElems.length; i < length; i++) {
for (let i = 0, length = sectionElems.length; i < length; i++) {
renderSection(page, item, sectionElems[i], sectionElems[i].getAttribute('data-type'));
}
}
}
function renderSection(page, item, element, type) {
function renderSection(page, item, element, type) {
switch (type) {
case 'Program':
loadItems(element, item, type, {
@ -254,15 +260,15 @@ define(['connectionManager', 'listView', 'cardBuilder', 'imageLoader', 'libraryB
artist: true
});
}
}
}
function loadItems(element, item, type, query, listOptions) {
function loadItems(element, item, type, query, listOptions) {
query = getQuery(query, item);
getItemsFunction(query, item)(query.StartIndex, query.Limit, query.Fields).then(function (result) {
var html = '';
let html = '';
if (query.Limit && result.TotalRecordCount > query.Limit) {
var link = element.querySelector('a');
const link = element.querySelector('a');
link.classList.remove('hide');
link.setAttribute('href', getMoreItemsHref(item, type));
} else {
@ -270,9 +276,9 @@ define(['connectionManager', 'listView', 'cardBuilder', 'imageLoader', 'libraryB
}
listOptions.items = result.Items;
var itemsContainer = element.querySelector('.itemsContainer');
const itemsContainer = element.querySelector('.itemsContainer');
if (type == 'Audio') {
if (type === 'Audio') {
html = listView.getListViewHtml(listOptions);
itemsContainer.classList.remove('vertical-wrap');
itemsContainer.classList.add('vertical-list');
@ -285,50 +291,50 @@ define(['connectionManager', 'listView', 'cardBuilder', 'imageLoader', 'libraryB
itemsContainer.innerHTML = html;
imageLoader.lazyChildren(itemsContainer);
});
}
}
function getMoreItemsHref(item, type) {
if (item.Type == 'Genre') {
function getMoreItemsHref(item, type) {
if (item.Type === 'Genre') {
return 'list.html?type=' + type + '&genreId=' + item.Id + '&serverId=' + item.ServerId;
}
if (item.Type == 'MusicGenre') {
if (item.Type === 'MusicGenre') {
return 'list.html?type=' + type + '&musicGenreId=' + item.Id + '&serverId=' + item.ServerId;
}
if (item.Type == 'Studio') {
if (item.Type === 'Studio') {
return 'list.html?type=' + type + '&studioId=' + item.Id + '&serverId=' + item.ServerId;
}
if (item.Type == 'MusicArtist') {
if (item.Type === 'MusicArtist') {
return 'list.html?type=' + type + '&artistId=' + item.Id + '&serverId=' + item.ServerId;
}
if (item.Type == 'Person') {
if (item.Type === 'Person') {
return 'list.html?type=' + type + '&personId=' + item.Id + '&serverId=' + item.ServerId;
}
return 'list.html?type=' + type + '&parentId=' + item.Id + '&serverId=' + item.ServerId;
}
}
function addCurrentItemToQuery(query, item) {
if (item.Type == 'Person') {
function addCurrentItemToQuery(query, item) {
if (item.Type === 'Person') {
query.PersonIds = item.Id;
} else if (item.Type == 'Genre') {
} else if (item.Type === 'Genre') {
query.Genres = item.Name;
} else if (item.Type == 'MusicGenre') {
} else if (item.Type === 'MusicGenre') {
query.Genres = item.Name;
} else if (item.Type == 'GameGenre') {
} else if (item.Type === 'GameGenre') {
query.Genres = item.Name;
} else if (item.Type == 'Studio') {
} else if (item.Type === 'Studio') {
query.StudioIds = item.Id;
} else if (item.Type == 'MusicArtist') {
} else if (item.Type === 'MusicArtist') {
query.AlbumArtistIds = item.Id;
}
}
}
function getQuery(options, item) {
var query = {
function getQuery(options, item) {
let query = {
SortOrder: 'Ascending',
IncludeItemTypes: '',
Recursive: true,
@ -340,10 +346,10 @@ define(['connectionManager', 'listView', 'cardBuilder', 'imageLoader', 'libraryB
query = Object.assign(query, options || {});
addCurrentItemToQuery(query, item);
return query;
}
}
function getItemsFunction(options, item) {
var query = getQuery(options, item);
function getItemsFunction(options, item) {
const query = getQuery(options, item);
return function (index, limit, fields) {
query.StartIndex = index;
query.Limit = limit;
@ -352,7 +358,7 @@ define(['connectionManager', 'listView', 'cardBuilder', 'imageLoader', 'libraryB
query.Fields += ',' + fields;
}
var apiClient = connectionManager.getApiClient(item.ServerId);
const apiClient = connectionManager.getApiClient(item.ServerId);
if (query.IncludeItemTypes === 'MusicArtist') {
query.IncludeItemTypes = null;
@ -361,9 +367,8 @@ define(['connectionManager', 'listView', 'cardBuilder', 'imageLoader', 'libraryB
return apiClient.getItems(apiClient.getCurrentUserId(), query);
};
}
}
window.ItemsByName = {
window.ItemsByName = {
renderItems: renderItems
};
});
};