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/plugins/available/index.js

143 lines
4.7 KiB
JavaScript
Raw Normal View History

2020-08-14 08:46:34 +02:00
import loading from '../../../../components/loading/loading';
import libraryMenu from '../../../../scripts/libraryMenu';
import globalize from '../../../../scripts/globalize';
import '../../../../components/cardbuilder/card.css';
import '../../../../elements/emby-button/emby-button';
import '../../../../elements/emby-checkbox/emby-checkbox';
import '../../../../elements/emby-select/emby-select';
function reloadList(page) {
loading.show();
const promise1 = ApiClient.getAvailablePlugins();
const promise2 = ApiClient.getInstalledPlugins();
Promise.all([promise1, promise2]).then(function (responses) {
populateList({
catalogElement: page.querySelector('#pluginTiles'),
noItemsElement: page.querySelector('#noPlugins'),
availablePlugins: responses[0],
installedPlugins: responses[1]
2019-01-10 21:37:02 +01:00
});
});
}
function getHeaderText(category) {
category = category.replace(' ', '');
2020-08-06 23:02:00 +02:00
// TODO: Replace with switch
if (category === 'Channel') {
category = 'Channels';
2020-08-06 23:02:00 +02:00
} else if (category === 'Theme') {
category = 'Themes';
2020-08-06 23:02:00 +02:00
} else if (category === 'LiveTV') {
2020-08-13 21:56:01 +09:00
category = 'LiveTV';
2020-08-06 23:02:00 +02:00
} else if (category === 'ScreenSaver') {
category = 'HeaderScreenSavers';
2018-10-23 01:05:09 +03:00
}
return globalize.translate(category);
}
2019-01-10 21:37:02 +01:00
function populateList(options) {
const availablePlugins = options.availablePlugins;
const installedPlugins = options.installedPlugins;
availablePlugins.forEach(function (plugin, index, array) {
plugin.category = plugin.category || 'General';
plugin.categoryDisplayName = getHeaderText(plugin.category);
array[index] = plugin;
});
2019-01-10 21:37:02 +01:00
availablePlugins.sort(function (a, b) {
if (a.category > b.category) {
return 1;
} else if (b.category > a.category) {
return -1;
2018-10-23 01:05:09 +03:00
}
if (a.name > b.name) {
return 1;
} else if (b.name > a.name) {
return -1;
2019-01-10 21:37:02 +01:00
}
return 0;
});
let currentCategory = null;
let html = '';
for (let i = 0; i < availablePlugins.length; i++) {
const plugin = availablePlugins[i];
const category = plugin.categoryDisplayName;
if (category != currentCategory) {
if (currentCategory) {
html += '</div>';
html += '</div>';
}
html += '<div class="verticalSection">';
html += '<h2 class="sectionTitle sectionTitle-cards">' + category + '</h2>';
html += '<div class="itemsContainer vertical-wrap">';
currentCategory = category;
}
html += getPluginHtml(plugin, options, installedPlugins);
2018-10-23 01:05:09 +03:00
}
html += '</div>';
html += '</div>';
2018-10-23 01:05:09 +03:00
if (!availablePlugins.length && options.noItemsElement) {
options.noItemsElement.classList.remove('hide');
}
2019-01-10 21:37:02 +01:00
options.catalogElement.innerHTML = html;
loading.hide();
}
2019-01-10 21:37:02 +01:00
function getPluginHtml(plugin, options, installedPlugins) {
let html = '';
let href = plugin.externalUrl ? plugin.externalUrl : 'addplugin.html?name=' + encodeURIComponent(plugin.name) + '&guid=' + plugin.guid;
2018-10-23 01:05:09 +03:00
if (options.context) {
href += '&context=' + options.context;
2018-10-23 01:05:09 +03:00
}
2019-01-10 21:37:02 +01:00
const target = plugin.externalUrl ? ' target="_blank"' : '';
html += "<div class='card backdropCard'>";
html += '<div class="cardBox visualCardBox">';
html += '<div class="cardScalable visualCardBox-cardScalable">';
html += '<div class="cardPadder cardPadder-backdrop"></div>';
html += '<a class="cardContent cardImageContainer" is="emby-linkbutton" href="' + href + '"' + target + '>';
html += '<span class="cardImageIcon material-icons folder"></span>';
html += '</a>';
html += '</div>';
html += '<div class="cardFooter">';
html += "<div class='cardText'>";
html += plugin.name;
html += '</div>';
const installedPlugin = installedPlugins.filter(function (ip) {
return ip.Id == plugin.guid;
})[0];
html += "<div class='cardText cardText-secondary'>";
html += installedPlugin ? globalize.translate('LabelVersionInstalled', installedPlugin.Version) : '&nbsp;';
html += '</div>';
html += '</div>';
html += '</div>';
return html += '</div>';
}
function getTabs() {
return [{
href: 'installedplugins.html',
name: globalize.translate('TabMyPlugins')
}, {
href: 'availableplugins.html',
name: globalize.translate('TabCatalog')
}, {
href: 'repositories.html',
name: globalize.translate('TabRepositories')
}];
}
export default function (view) {
view.addEventListener('viewshow', function () {
libraryMenu.setTabs('plugins', 1, getTabs);
reloadList(this);
});
}