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.js

143 lines
5 KiB
JavaScript
Raw Normal View History

2020-05-04 12:44:12 +02:00
define(['loading', 'libraryMenu', 'globalize', 'cardStyle', 'emby-button', 'emby-checkbox', 'emby-select'], function (loading, libraryMenu, globalize) {
'use strict';
2018-10-23 01:05:09 +03:00
function reloadList(page) {
2019-01-10 21:37:02 +01:00
loading.show();
var promise1 = ApiClient.getAvailablePlugins();
2019-01-10 21:37:02 +01:00
var promise2 = ApiClient.getInstalledPlugins();
Promise.all([promise1, promise2]).then(function (responses) {
2018-10-23 01:05:09 +03:00
populateList({
2020-05-04 12:44:12 +02:00
catalogElement: page.querySelector('#pluginTiles'),
noItemsElement: page.querySelector('#noPlugins'),
2018-10-23 01:05:09 +03:00
availablePlugins: responses[0],
installedPlugins: responses[1]
2019-01-10 21:37:02 +01:00
});
});
2018-10-23 01:05:09 +03:00
}
function getHeaderText(category) {
2020-05-04 12:44:12 +02:00
category = category.replace(' ', '');
if ('Channel' === category) {
category = 'Channels';
} else if ('Theme' === category) {
category = 'Themes';
} else if ('LiveTV' === category) {
category = 'HeaderLiveTV';
} else if ('ScreenSaver' === category) {
category = 'HeaderScreenSavers';
2019-01-10 21:37:02 +01:00
}
return globalize.translate(category);
2018-10-23 01:05:09 +03:00
}
2019-02-26 03:15:12 +09:00
function populateList(options) {
2019-01-10 21:37:02 +01:00
var availablePlugins = options.availablePlugins;
var installedPlugins = options.installedPlugins;
var categories = [];
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) {
2019-01-10 21:37:02 +01:00
return 1;
} else if (b.category > a.category) {
2019-01-10 21:37:02 +01:00
return -1;
}
if (a.name > b.name) {
2019-01-10 21:37:02 +01:00
return 1;
} else if (b.name > a.name) {
2019-01-10 21:37:02 +01:00
return -1;
}
return 0;
2018-10-23 01:05:09 +03:00
});
var currentCategory = null;
2020-05-04 12:44:12 +02:00
var html = '';
2019-01-10 21:37:02 +01:00
2019-03-09 11:37:40 +09:00
for (var i = 0; i < availablePlugins.length; i++) {
var plugin = availablePlugins[i];
2018-10-23 01:05:09 +03:00
var category = plugin.categoryDisplayName;
2019-01-10 21:37:02 +01:00
if (category != currentCategory) {
if (currentCategory) {
2020-05-04 12:44:12 +02:00
html += '</div>';
html += '</div>';
2019-01-10 21:37:02 +01:00
}
html += '<div class="verticalSection">';
2020-05-04 12:44:12 +02:00
html += '<h2 class="sectionTitle sectionTitle-cards">' + category + '</h2>';
html += '<div class="itemsContainer vertical-wrap">';
2019-01-10 21:37:02 +01:00
currentCategory = category;
}
html += getPluginHtml(plugin, options, installedPlugins);
2018-10-23 01:05:09 +03:00
}
2020-05-04 12:44:12 +02:00
html += '</div>';
html += '</div>';
2019-01-10 21:37:02 +01:00
if (!availablePlugins.length && options.noItemsElement) {
2020-05-04 12:44:12 +02:00
options.noItemsElement.classList.remove('hide');
2019-01-10 21:37:02 +01:00
}
options.catalogElement.innerHTML = html;
loading.hide();
2018-10-23 01:05:09 +03:00
}
function getPluginHtml(plugin, options, installedPlugins) {
2020-05-04 12:44:12 +02:00
var html = '';
var href = plugin.externalUrl ? plugin.externalUrl : 'addplugin.html?name=' + encodeURIComponent(plugin.name) + '&guid=' + plugin.guid;
2019-01-10 21:37:02 +01:00
if (options.context) {
2020-05-04 12:44:12 +02:00
href += '&context=' + options.context;
2019-01-10 21:37:02 +01:00
}
2020-05-04 12:44:12 +02:00
var target = plugin.externalUrl ? ' target="_blank"' : '';
2019-01-10 21:37:02 +01:00
html += "<div class='card backdropCard'>";
html += '<div class="cardBox visualCardBox">';
html += '<div class="cardScalable visualCardBox-cardScalable">';
html += '<div class="cardPadder cardPadder-backdrop"></div>';
2020-05-04 12:44:12 +02:00
html += '<a class="cardContent cardImageContainer" is="emby-linkbutton" href="' + href + '"' + target + '>';
html += '<span class="cardImageIcon material-icons folder"></span>';
2020-05-04 12:44:12 +02:00
html += '</a>';
html += '</div>';
2019-01-10 21:37:02 +01:00
html += '<div class="cardFooter">';
html += "<div class='cardText'>";
html += plugin.name;
2020-05-04 12:44:12 +02:00
html += '</div>';
var installedPlugin = installedPlugins.filter(function (ip) {
2019-01-10 21:37:02 +01:00
return ip.Id == plugin.guid;
2018-10-23 01:05:09 +03:00
})[0];
2019-01-10 21:37:02 +01:00
html += "<div class='cardText cardText-secondary'>";
2020-05-04 12:44:12 +02:00
html += installedPlugin ? globalize.translate('LabelVersionInstalled', installedPlugin.Version) : '&nbsp;';
html += '</div>';
html += '</div>';
html += '</div>';
return html += '</div>';
2018-10-23 01:05:09 +03:00
}
function getTabs() {
return [{
2020-05-04 12:44:12 +02:00
href: 'installedplugins.html',
name: globalize.translate('TabMyPlugins')
2018-10-23 01:05:09 +03:00
}, {
2020-05-04 12:44:12 +02:00
href: 'availableplugins.html',
name: globalize.translate('TabCatalog')
}, {
href: 'repositories.html',
name: globalize.translate('TabRepositories')
2019-01-10 21:37:02 +01:00
}];
2018-10-23 01:05:09 +03:00
}
2019-01-10 21:37:02 +01:00
window.PluginCatalog = {
renderCatalog: populateList
};
2019-02-26 03:15:12 +09:00
2019-01-10 21:37:02 +01:00
return function (view, params) {
2020-05-04 12:44:12 +02:00
view.addEventListener('viewshow', function () {
libraryMenu.setTabs('plugins', 1, getTabs);
2019-01-10 21:37:02 +01:00
reloadList(this);
});
};
});