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

406 lines
15 KiB
JavaScript
Raw Normal View History

2020-08-14 08:46:34 +02:00
import 'jquery';
import taskButton from '../../scripts/taskbutton';
import loading from '../../components/loading/loading';
import libraryMenu from '../../scripts/libraryMenu';
import globalize from '../../scripts/globalize';
import dom from '../../scripts/dom';
import imageHelper from '../../scripts/imagehelper';
import '../../components/cardbuilder/card.css';
import '../../elements/emby-itemrefreshindicator/emby-itemrefreshindicator';
import Dashboard from '../../scripts/clientUtils';
import confirm from '../../components/confirm/confirm';
2020-07-08 20:24:44 +01:00
/* eslint-disable indent */
2018-10-23 01:05:09 +03:00
function addVirtualFolder(page) {
import('../../components/mediaLibraryCreator/mediaLibraryCreator').then(({default: medialibrarycreator}) => {
new medialibrarycreator({
2019-09-08 01:11:27 +03:00
collectionTypeOptions: getCollectionTypeOptions().filter(function (f) {
2019-05-06 17:26:18 -07:00
return !f.hidden;
2018-10-23 01:05:09 +03:00
}),
refresh: shouldRefreshLibraryAfterChanges(page)
2019-09-08 01:11:27 +03:00
}).then(function (hasChanges) {
if (hasChanges) {
reloadLibrary(page);
}
});
});
2018-10-23 01:05:09 +03:00
}
function editVirtualFolder(page, virtualFolder) {
import('../../components/mediaLibraryEditor/mediaLibraryEditor').then(({default: medialibraryeditor}) => {
new medialibraryeditor({
2018-10-23 01:05:09 +03:00
refresh: shouldRefreshLibraryAfterChanges(page),
library: virtualFolder
2019-09-08 01:11:27 +03:00
}).then(function (hasChanges) {
if (hasChanges) {
reloadLibrary(page);
}
});
});
2018-10-23 01:05:09 +03:00
}
function deleteVirtualFolder(page, virtualFolder) {
let msg = globalize.translate('MessageAreYouSureYouWishToRemoveMediaFolder');
2019-09-08 01:11:27 +03:00
2019-05-06 17:26:18 -07:00
if (virtualFolder.Locations.length) {
2020-05-04 12:44:12 +02:00
msg += '<br/><br/>' + globalize.translate('MessageTheFollowingLocationWillBeRemovedFromLibrary') + '<br/><br/>';
msg += virtualFolder.Locations.join('<br/>');
2019-05-06 17:26:18 -07:00
}
2019-09-08 01:11:27 +03:00
confirm({
text: msg,
title: globalize.translate('HeaderRemoveMediaFolder'),
confirmText: globalize.translate('Delete'),
primary: 'delete'
}).then(function () {
const refreshAfterChange = shouldRefreshLibraryAfterChanges(page);
ApiClient.removeVirtualFolder(virtualFolder.Name, refreshAfterChange).then(function () {
reloadLibrary(page);
2019-09-08 01:11:27 +03:00
});
});
2018-10-23 01:05:09 +03:00
}
function refreshVirtualFolder(page, virtualFolder) {
import('../../components/refreshdialog/refreshdialog').then(({default: refreshDialog}) => {
2018-10-23 01:05:09 +03:00
new refreshDialog({
itemIds: [virtualFolder.ItemId],
serverId: ApiClient.serverId(),
2020-05-04 12:44:12 +02:00
mode: 'scan'
2019-05-06 17:26:18 -07:00
}).show();
});
2018-10-23 01:05:09 +03:00
}
function renameVirtualFolder(page, virtualFolder) {
import('../../components/prompt/prompt').then(({default: prompt}) => {
2018-10-23 01:05:09 +03:00
prompt({
2020-05-04 12:44:12 +02:00
label: globalize.translate('LabelNewName'),
confirmText: globalize.translate('ButtonRename')
2019-09-08 01:11:27 +03:00
}).then(function (newName) {
2018-10-23 01:05:09 +03:00
if (newName && newName != virtualFolder.Name) {
const refreshAfterChange = shouldRefreshLibraryAfterChanges(page);
2019-09-08 01:11:27 +03:00
ApiClient.renameVirtualFolder(virtualFolder.Name, newName, refreshAfterChange).then(function () {
2019-05-06 17:26:18 -07:00
reloadLibrary(page);
});
2018-10-23 01:05:09 +03:00
}
2019-05-06 17:26:18 -07:00
});
});
2018-10-23 01:05:09 +03:00
}
function showCardMenu(page, elem, virtualFolders) {
const card = dom.parentWithClass(elem, 'card');
const index = parseInt(card.getAttribute('data-index'));
const virtualFolder = virtualFolders[index];
const menuItems = [];
2019-05-06 17:26:18 -07:00
menuItems.push({
2020-08-16 20:34:39 +09:00
name: globalize.translate('EditImages'),
2020-05-04 12:44:12 +02:00
id: 'editimages',
icon: 'photo'
2019-05-06 17:26:18 -07:00
});
menuItems.push({
2020-05-04 12:44:12 +02:00
name: globalize.translate('ManageLibrary'),
id: 'edit',
icon: 'folder_open'
2019-05-06 17:26:18 -07:00
});
menuItems.push({
2020-05-04 12:44:12 +02:00
name: globalize.translate('ButtonRemove'),
id: 'delete',
icon: 'delete'
2019-05-06 17:26:18 -07:00
});
menuItems.push({
2020-05-04 12:44:12 +02:00
name: globalize.translate('ButtonRename'),
id: 'rename',
icon: 'mode_edit'
2019-05-06 17:26:18 -07:00
});
menuItems.push({
2020-05-04 12:44:12 +02:00
name: globalize.translate('ScanLibrary'),
id: 'refresh',
icon: 'refresh'
2019-05-06 17:26:18 -07:00
});
2019-09-08 01:11:27 +03:00
2020-08-14 08:46:34 +02:00
import('../../components/actionSheet/actionSheet').then((actionsheet) => {
2018-10-23 01:05:09 +03:00
actionsheet.show({
items: menuItems,
positionTo: elem,
2019-09-08 01:11:27 +03:00
callback: function (resultId) {
2018-10-23 01:05:09 +03:00
switch (resultId) {
2020-05-04 12:44:12 +02:00
case 'edit':
2018-10-23 01:05:09 +03:00
editVirtualFolder(page, virtualFolder);
break;
2019-09-08 01:11:27 +03:00
2020-05-04 12:44:12 +02:00
case 'editimages':
2018-10-23 01:05:09 +03:00
editImages(page, virtualFolder);
break;
2019-09-08 01:11:27 +03:00
2020-05-04 12:44:12 +02:00
case 'rename':
2018-10-23 01:05:09 +03:00
renameVirtualFolder(page, virtualFolder);
break;
2019-09-08 01:11:27 +03:00
2020-05-04 12:44:12 +02:00
case 'delete':
2018-10-23 01:05:09 +03:00
deleteVirtualFolder(page, virtualFolder);
break;
2019-09-08 01:11:27 +03:00
2020-05-04 12:44:12 +02:00
case 'refresh':
2019-05-06 17:26:18 -07:00
refreshVirtualFolder(page, virtualFolder);
2018-10-23 01:05:09 +03:00
}
}
2019-05-06 17:26:18 -07:00
});
});
2018-10-23 01:05:09 +03:00
}
function reloadLibrary(page) {
2019-05-06 17:26:18 -07:00
loading.show();
2019-09-08 01:11:27 +03:00
ApiClient.getVirtualFolders().then(function (result) {
2019-05-06 17:26:18 -07:00
reloadVirtualFolders(page, result);
});
2018-10-23 01:05:09 +03:00
}
function shouldRefreshLibraryAfterChanges(page) {
2020-07-30 16:07:13 +02:00
return page.id === 'mediaLibraryPage';
2018-10-23 01:05:09 +03:00
}
function reloadVirtualFolders(page, virtualFolders) {
let html = '';
2018-10-23 01:05:09 +03:00
virtualFolders.push({
2020-05-04 12:44:12 +02:00
Name: globalize.translate('ButtonAddMediaLibrary'),
icon: 'add_circle',
2018-10-23 01:05:09 +03:00
Locations: [],
2019-05-06 19:47:02 -07:00
showType: false,
showLocations: false,
showMenu: false,
2020-07-09 21:44:49 +01:00
showNameWithIcon: false
2018-10-23 01:05:09 +03:00
});
2019-05-06 19:47:02 -07:00
for (let i = 0; i < virtualFolders.length; i++) {
const virtualFolder = virtualFolders[i];
2019-09-08 01:11:27 +03:00
html += getVirtualFolderHtml(page, virtualFolder, i);
2018-10-23 01:05:09 +03:00
}
2019-09-08 01:11:27 +03:00
const divVirtualFolders = page.querySelector('#divVirtualFolders');
2019-05-06 17:26:18 -07:00
divVirtualFolders.innerHTML = html;
2020-05-04 12:44:12 +02:00
divVirtualFolders.classList.add('itemsContainer');
divVirtualFolders.classList.add('vertical-wrap');
$('.btnCardMenu', divVirtualFolders).on('click', function () {
2019-05-06 17:26:18 -07:00
showCardMenu(page, this, virtualFolders);
});
2020-07-09 21:44:49 +01:00
divVirtualFolders.querySelector('#addLibrary').addEventListener('click', function () {
2019-05-06 17:26:18 -07:00
addVirtualFolder(page);
});
2020-05-04 12:44:12 +02:00
$('.editLibrary', divVirtualFolders).on('click', function () {
const card = $(this).parents('.card')[0];
const index = parseInt(card.getAttribute('data-index'));
const virtualFolder = virtualFolders[index];
2019-09-08 01:11:27 +03:00
if (virtualFolder.ItemId) {
editVirtualFolder(page, virtualFolder);
}
2019-05-06 17:26:18 -07:00
});
loading.hide();
2018-10-23 01:05:09 +03:00
}
function editImages(page, virtualFolder) {
2020-08-14 08:46:34 +02:00
import('../../components/imageeditor/imageeditor').then((imageEditor) => {
2018-10-23 01:05:09 +03:00
imageEditor.show({
itemId: virtualFolder.ItemId,
serverId: ApiClient.serverId()
2019-09-08 01:11:27 +03:00
}).then(function () {
2019-05-06 17:26:18 -07:00
reloadLibrary(page);
});
2019-09-08 01:11:27 +03:00
});
2018-10-23 01:05:09 +03:00
}
function getLink(text, url) {
2020-05-04 12:44:12 +02:00
return globalize.translate(text, '<a is="emby-linkbutton" class="button-link" href="' + url + '" target="_blank" data-autohide="true">', '</a>');
2018-10-23 01:05:09 +03:00
}
function getCollectionTypeOptions() {
return [{
2020-05-04 12:44:12 +02:00
name: '',
value: ''
2018-10-23 01:05:09 +03:00
}, {
name: globalize.translate('Movies'),
2020-05-04 12:44:12 +02:00
value: 'movies',
message: getLink('MovieLibraryHelp', 'https://docs.jellyfin.org/general/server/media/movies.html')
2018-10-23 01:05:09 +03:00
}, {
name: globalize.translate('TabMusic'),
2020-05-04 12:44:12 +02:00
value: 'music',
message: getLink('MusicLibraryHelp', 'https://docs.jellyfin.org/general/server/media/music.html')
2018-10-23 01:05:09 +03:00
}, {
name: globalize.translate('Shows'),
2020-05-04 12:44:12 +02:00
value: 'tvshows',
message: getLink('TvLibraryHelp', 'https://docs.jellyfin.org/general/server/media/shows.html')
2018-10-23 01:05:09 +03:00
}, {
name: globalize.translate('Books'),
2020-05-04 12:44:12 +02:00
value: 'books',
message: getLink('BookLibraryHelp', 'https://docs.jellyfin.org/general/server/media/books.html')
2018-10-23 01:05:09 +03:00
}, {
name: globalize.translate('Photos'),
2020-05-04 12:44:12 +02:00
value: 'homevideos'
2018-10-23 01:05:09 +03:00
}, {
name: globalize.translate('MusicVideos'),
2020-05-04 12:44:12 +02:00
value: 'musicvideos'
2018-10-23 01:05:09 +03:00
}, {
name: globalize.translate('Other'),
2020-05-04 12:44:12 +02:00
value: 'mixed',
message: globalize.translate('MessageUnsetContentHelp')
2019-09-08 01:11:27 +03:00
}];
2018-10-23 01:05:09 +03:00
}
function getVirtualFolderHtml(page, virtualFolder, index) {
let html = '';
let style = '';
2019-09-08 01:11:27 +03:00
2020-05-04 12:44:12 +02:00
if (page.classList.contains('wizardPage')) {
style += 'min-width:33.3%;';
2019-09-08 01:11:27 +03:00
}
2020-07-09 21:44:49 +01:00
if (virtualFolder.Locations.length == 0) {
html += '<div id="addLibrary" class="card backdropCard scalableCard backdropCard-scalable" style="' + style + '" data-index="' + index + '" data-id="' + virtualFolder.ItemId + '">';
} else {
2020-07-09 22:19:00 +01:00
html += '<div class="card backdropCard scalableCard backdropCard-scalable" style="' + style + '" data-index="' + index + '" data-id="' + virtualFolder.ItemId + '">';
2020-07-09 21:44:49 +01:00
}
2019-05-06 17:26:18 -07:00
html += '<div class="cardBox visualCardBox">';
html += '<div class="cardScalable visualCardBox-cardScalable">';
html += '<div class="cardPadder cardPadder-backdrop"></div>';
html += '<div class="cardContent">';
let imgUrl = '';
2019-09-08 01:11:27 +03:00
2019-05-06 17:26:18 -07:00
if (virtualFolder.PrimaryImageItemId) {
imgUrl = ApiClient.getScaledImageUrl(virtualFolder.PrimaryImageItemId, {
2020-03-09 21:02:08 +01:00
maxWidth: Math.round(dom.getScreenWidth() * 0.40),
2020-05-04 12:44:12 +02:00
type: 'Primary'
2019-05-06 17:26:18 -07:00
});
}
2019-09-08 01:11:27 +03:00
let hasCardImageContainer;
2019-09-08 01:11:27 +03:00
2019-05-06 17:26:18 -07:00
if (imgUrl) {
html += '<div class="cardImageContainer editLibrary" style="cursor:pointer;background-image:url(\'' + imgUrl + "');\">";
hasCardImageContainer = true;
} else if (!virtualFolder.showNameWithIcon) {
html += '<div class="cardImageContainer editLibrary" style="cursor:pointer;">';
2020-04-26 02:37:28 +03:00
html += '<span class="cardImageIcon-small material-icons ' + (virtualFolder.icon || imageHelper.getLibraryIcon(virtualFolder.CollectionType)) + '"></span>';
2019-05-06 17:26:18 -07:00
hasCardImageContainer = true;
}
2019-09-08 01:11:27 +03:00
2019-05-06 17:26:18 -07:00
if (hasCardImageContainer) {
2018-10-23 01:05:09 +03:00
html += '<div class="cardIndicators backdropCardIndicators">';
2020-07-30 16:07:13 +02:00
html += '<div is="emby-itemrefreshindicator"' + (virtualFolder.RefreshProgress || virtualFolder.RefreshStatus && virtualFolder.RefreshStatus !== 'Idle' ? '' : ' class="hide"') + ' data-progress="' + (virtualFolder.RefreshProgress || 0) + '" data-status="' + virtualFolder.RefreshStatus + '"></div>';
2020-05-04 12:44:12 +02:00
html += '</div>';
html += '</div>';
2018-10-23 01:05:09 +03:00
}
2019-09-08 01:11:27 +03:00
2019-05-06 17:26:18 -07:00
if (!imgUrl && virtualFolder.showNameWithIcon) {
html += '<h3 class="cardImageContainer addLibrary" style="position:absolute;top:0;left:0;right:0;bottom:0;cursor:pointer;flex-direction:column;">';
2020-04-26 02:37:28 +03:00
html += '<span class="cardImageIcon-small material-icons ' + (virtualFolder.icon || imageHelper.getLibraryIcon(virtualFolder.CollectionType)) + '"></span>';
2019-09-08 01:11:27 +03:00
if (virtualFolder.showNameWithIcon) {
html += '<div style="margin:1em 0;position:width:100%;">';
html += virtualFolder.Name;
2020-05-04 12:44:12 +02:00
html += '</div>';
2019-09-08 01:11:27 +03:00
}
2020-05-04 12:44:12 +02:00
html += '</h3>';
2018-10-23 01:05:09 +03:00
}
2019-09-08 01:11:27 +03:00
2020-05-04 12:44:12 +02:00
html += '</div>';
html += '</div>';
2019-09-08 01:11:27 +03:00
html += '<div class="cardFooter visualCardBox-cardFooter">'; // always show menu unless explicitly hidden
if (virtualFolder.showMenu !== false) {
2019-05-06 17:26:18 -07:00
html += '<div style="text-align:right; float:right;padding-top:5px;">';
html += '<button type="button" is="paper-icon-button-light" class="btnCardMenu autoSize"><span class="material-icons more_vert"></span></button>';
2020-05-04 12:44:12 +02:00
html += '</div>';
2019-05-06 17:26:18 -07:00
}
2019-09-08 01:11:27 +03:00
2019-05-06 17:26:18 -07:00
html += "<div class='cardText'>";
2019-09-08 01:11:27 +03:00
if (virtualFolder.showNameWithIcon) {
2020-05-04 12:44:12 +02:00
html += '&nbsp;';
2019-09-08 01:11:27 +03:00
} else {
html += virtualFolder.Name;
}
2020-05-04 12:44:12 +02:00
html += '</div>';
let typeName = getCollectionTypeOptions().filter(function (t) {
2019-09-08 01:11:27 +03:00
return t.value == virtualFolder.CollectionType;
2018-10-23 01:05:09 +03:00
})[0];
typeName = typeName ? typeName.name : globalize.translate('Other');
2019-05-06 17:26:18 -07:00
html += "<div class='cardText cardText-secondary'>";
2019-09-08 01:11:27 +03:00
if (virtualFolder.showType === false) {
2020-05-04 12:44:12 +02:00
html += '&nbsp;';
2019-09-08 01:11:27 +03:00
} else {
html += typeName;
}
2020-05-04 12:44:12 +02:00
html += '</div>';
2019-09-08 01:11:27 +03:00
2019-05-06 17:26:18 -07:00
if (virtualFolder.showLocations === false) {
html += "<div class='cardText cardText-secondary'>";
2020-05-04 12:44:12 +02:00
html += '&nbsp;';
html += '</div>';
2019-05-06 17:26:18 -07:00
} else if (virtualFolder.Locations.length && virtualFolder.Locations.length === 1) {
2019-05-16 01:54:01 +03:00
html += "<div class='cardText cardText-secondary'>";
html += virtualFolder.Locations[0];
2020-05-04 12:44:12 +02:00
html += '</div>';
2019-05-06 17:26:18 -07:00
} else {
html += "<div class='cardText cardText-secondary'>";
2020-05-04 12:44:12 +02:00
html += globalize.translate('NumLocationsValue', virtualFolder.Locations.length);
html += '</div>';
2019-05-06 17:26:18 -07:00
}
2019-09-08 01:11:27 +03:00
2020-05-04 12:44:12 +02:00
html += '</div>';
html += '</div>';
html += '</div>';
2019-05-06 17:26:18 -07:00
return html;
2018-10-23 01:05:09 +03:00
}
function getTabs() {
return [{
2020-05-04 12:44:12 +02:00
href: 'library.html',
name: globalize.translate('HeaderLibraries')
2018-10-23 01:05:09 +03:00
}, {
2020-05-04 12:44:12 +02:00
href: 'librarydisplay.html',
name: globalize.translate('Display')
2018-10-23 01:05:09 +03:00
}, {
2020-05-04 12:44:12 +02:00
href: 'metadataimages.html',
name: globalize.translate('Metadata')
2018-10-23 01:05:09 +03:00
}, {
2020-05-04 12:44:12 +02:00
href: 'metadatanfo.html',
name: globalize.translate('TabNfoSettings')
2019-09-08 01:11:27 +03:00
}];
2018-10-23 01:05:09 +03:00
}
2019-06-10 14:44:52 -07:00
2018-10-23 01:05:09 +03:00
window.WizardLibraryPage = {
2019-09-08 01:11:27 +03:00
next: function () {
2020-05-04 12:44:12 +02:00
Dashboard.navigate('wizardsettings.html');
2018-10-23 01:05:09 +03:00
}
2019-05-06 17:26:18 -07:00
};
2020-05-04 12:44:12 +02:00
pageClassOn('pageshow', 'mediaLibraryPage', function () {
2019-05-06 17:26:18 -07:00
reloadLibrary(this);
});
2020-05-04 12:44:12 +02:00
pageIdOn('pageshow', 'mediaLibraryPage', function () {
libraryMenu.setTabs('librarysetup', 0, getTabs);
const page = this;
2018-10-23 01:05:09 +03:00
taskButton({
2020-05-04 12:44:12 +02:00
mode: 'on',
progressElem: page.querySelector('.refreshProgress'),
taskKey: 'RefreshLibrary',
button: page.querySelector('.btnRefresh')
2019-05-06 17:26:18 -07:00
});
});
2020-05-04 12:44:12 +02:00
pageIdOn('pagebeforehide', 'mediaLibraryPage', function () {
const page = this;
2018-10-23 01:05:09 +03:00
taskButton({
2020-05-04 12:44:12 +02:00
mode: 'off',
progressElem: page.querySelector('.refreshProgress'),
taskKey: 'RefreshLibrary',
button: page.querySelector('.btnRefresh')
2019-05-06 17:26:18 -07:00
});
});
2020-07-08 20:24:44 +01:00
/* eslint-enable indent */