2020-08-14 08:46:34 +02:00
|
|
|
import loading from '../../../../components/loading/loading';
|
|
|
|
import libraryMenu from '../../../../scripts/libraryMenu';
|
|
|
|
import dom from '../../../../scripts/dom';
|
|
|
|
import globalize from '../../../../scripts/globalize';
|
|
|
|
import '../../../../components/cardbuilder/card.css';
|
|
|
|
import '../../../../elements/emby-button/emby-button';
|
2020-10-12 23:08:55 +01:00
|
|
|
import Dashboard from '../../../../scripts/clientUtils';
|
2020-07-26 22:25:54 +02:00
|
|
|
|
|
|
|
function deletePlugin(page, uniqueid, name) {
|
|
|
|
const msg = globalize.translate('UninstallPluginConfirmation', name);
|
|
|
|
|
2020-08-14 08:46:34 +02:00
|
|
|
import('../../../../components/confirm/confirm').then((confirm) => {
|
2020-07-26 22:25:54 +02:00
|
|
|
confirm.default({
|
2020-08-07 23:58:21 +02:00
|
|
|
title: globalize.translate('HeaderUninstallPlugin'),
|
2020-07-26 22:25:54 +02:00
|
|
|
text: msg,
|
|
|
|
primary: 'delete',
|
2020-08-07 23:58:30 +02:00
|
|
|
confirmText: globalize.translate('HeaderUninstallPlugin')
|
2020-07-26 22:25:54 +02:00
|
|
|
}).then(function () {
|
|
|
|
loading.show();
|
|
|
|
ApiClient.uninstallPlugin(uniqueid).then(function () {
|
|
|
|
reloadList(page);
|
2019-11-06 13:43:39 +03:00
|
|
|
});
|
|
|
|
});
|
2020-07-26 22:25:54 +02:00
|
|
|
});
|
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
|
2020-07-26 22:25:54 +02:00
|
|
|
function showNoConfigurationMessage() {
|
|
|
|
Dashboard.alert({
|
2020-08-07 23:58:01 +02:00
|
|
|
message: globalize.translate('MessageNoPluginConfiguration')
|
2020-07-26 22:25:54 +02:00
|
|
|
});
|
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
|
2020-07-26 22:25:54 +02:00
|
|
|
function showConnectMessage() {
|
|
|
|
Dashboard.alert({
|
|
|
|
message: globalize.translate('MessagePluginConfigurationRequiresLocalAccess')
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function getPluginCardHtml(plugin, pluginConfigurationPages) {
|
|
|
|
const configPage = pluginConfigurationPages.filter(function (pluginConfigurationPage) {
|
|
|
|
return pluginConfigurationPage.PluginId == plugin.Id;
|
|
|
|
})[0];
|
2020-09-02 20:50:32 +09:00
|
|
|
const configPageUrl = configPage ? Dashboard.getPluginUrl(configPage.Name) : null;
|
2020-07-26 22:25:54 +02:00
|
|
|
let html = '';
|
|
|
|
html += "<div data-id='" + plugin.Id + "' data-name='" + plugin.Name + "' data-removable='" + plugin.CanUninstall + "' class='card backdropCard'>";
|
|
|
|
html += '<div class="cardBox visualCardBox">';
|
|
|
|
html += '<div class="cardScalable">';
|
|
|
|
html += '<div class="cardPadder cardPadder-backdrop"></div>';
|
|
|
|
html += configPageUrl ? '<a class="cardContent cardImageContainer" is="emby-linkbutton" href="' + configPageUrl + '">' : '<div class="cardContent noConfigPluginCard noHoverEffect cardImageContainer emby-button">';
|
|
|
|
html += '<span class="cardImageIcon material-icons folder"></span>';
|
|
|
|
html += configPageUrl ? '</a>' : '</div>';
|
|
|
|
html += '</div>';
|
|
|
|
html += '<div class="cardFooter">';
|
|
|
|
|
|
|
|
if (configPage || plugin.CanUninstall) {
|
|
|
|
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>';
|
|
|
|
html += '</div>';
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
2020-07-26 22:25:54 +02:00
|
|
|
html += "<div class='cardText'>";
|
|
|
|
html += configPage && configPage.DisplayName ? configPage.DisplayName : plugin.Name;
|
|
|
|
html += '</div>';
|
|
|
|
html += "<div class='cardText cardText-secondary'>";
|
|
|
|
html += plugin.Version;
|
|
|
|
html += '</div>';
|
|
|
|
html += '</div>';
|
|
|
|
html += '</div>';
|
|
|
|
html += '</div>';
|
|
|
|
return html;
|
|
|
|
}
|
|
|
|
|
|
|
|
function renderPlugins(page, plugins) {
|
|
|
|
ApiClient.getJSON(ApiClient.getUrl('web/configurationpages') + '?pageType=PluginConfiguration').then(function (configPages) {
|
|
|
|
populateList(page, plugins, configPages);
|
|
|
|
});
|
|
|
|
}
|
2020-06-22 10:14:13 +01:00
|
|
|
|
2020-07-26 22:25:54 +02:00
|
|
|
function populateList(page, plugins, pluginConfigurationPages) {
|
|
|
|
plugins = plugins.sort(function (plugin1, plugin2) {
|
|
|
|
if (plugin1.Name > plugin2.Name) {
|
|
|
|
return 1;
|
2020-06-22 10:14:13 +01:00
|
|
|
}
|
|
|
|
|
2020-07-26 22:25:54 +02:00
|
|
|
return -1;
|
|
|
|
});
|
|
|
|
|
|
|
|
let html = plugins.map(function (p) {
|
|
|
|
return getPluginCardHtml(p, pluginConfigurationPages);
|
|
|
|
}).join('');
|
|
|
|
|
|
|
|
const installedPluginsElement = page.querySelector('.installedPlugins');
|
|
|
|
installedPluginsElement.removeEventListener('click', onInstalledPluginsClick);
|
|
|
|
installedPluginsElement.addEventListener('click', onInstalledPluginsClick);
|
|
|
|
|
|
|
|
if (plugins.length) {
|
|
|
|
installedPluginsElement.classList.add('itemsContainer');
|
|
|
|
installedPluginsElement.classList.add('vertical-wrap');
|
|
|
|
} else {
|
|
|
|
html += '<div class="centerMessage">';
|
|
|
|
html += '<h1>' + globalize.translate('MessageNoPluginsInstalled') + '</h1>';
|
|
|
|
html += '<p><a is="emby-linkbutton" class="button-link" href="availableplugins.html">';
|
2020-08-07 23:58:14 +02:00
|
|
|
html += globalize.translate('MessageBrowsePluginCatalog');
|
2020-07-26 22:25:54 +02:00
|
|
|
html += '</a></p>';
|
2020-05-04 12:44:12 +02:00
|
|
|
html += '</div>';
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
2020-07-26 22:25:54 +02:00
|
|
|
installedPluginsElement.innerHTML = html;
|
|
|
|
loading.hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
function showPluginMenu(page, elem) {
|
|
|
|
const card = dom.parentWithClass(elem, 'card');
|
|
|
|
const id = card.getAttribute('data-id');
|
|
|
|
const name = card.getAttribute('data-name');
|
|
|
|
const removable = card.getAttribute('data-removable');
|
|
|
|
const configHref = card.querySelector('.cardContent').getAttribute('href');
|
|
|
|
const menuItems = [];
|
|
|
|
|
|
|
|
if (configHref) {
|
|
|
|
menuItems.push({
|
2020-08-24 08:20:29 +09:00
|
|
|
name: globalize.translate('Settings'),
|
2020-07-26 22:25:54 +02:00
|
|
|
id: 'open',
|
|
|
|
icon: 'mode_edit'
|
2019-04-02 15:16:51 -07:00
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
2020-07-26 22:25:54 +02:00
|
|
|
if (removable === 'true') {
|
|
|
|
menuItems.push({
|
|
|
|
name: globalize.translate('ButtonUninstall'),
|
|
|
|
id: 'delete',
|
|
|
|
icon: 'delete'
|
2018-10-23 01:05:09 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-08-14 08:46:34 +02:00
|
|
|
import('../../../../components/actionSheet/actionSheet').then((actionsheet) => {
|
2020-07-26 22:25:54 +02:00
|
|
|
actionsheet.show({
|
|
|
|
items: menuItems,
|
|
|
|
positionTo: elem,
|
|
|
|
callback: function (resultId) {
|
|
|
|
switch (resultId) {
|
|
|
|
case 'open':
|
|
|
|
Dashboard.navigate(configHref);
|
|
|
|
break;
|
|
|
|
case 'delete':
|
|
|
|
deletePlugin(page, id, name);
|
|
|
|
break;
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2020-07-26 22:25:54 +02:00
|
|
|
}
|
2019-04-02 15:16:51 -07:00
|
|
|
});
|
2020-07-26 22:25:54 +02:00
|
|
|
});
|
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
|
2020-07-26 22:25:54 +02:00
|
|
|
function reloadList(page) {
|
|
|
|
loading.show();
|
|
|
|
ApiClient.getInstalledPlugins().then(function (plugins) {
|
|
|
|
renderPlugins(page, plugins);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function getTabs() {
|
|
|
|
return [{
|
|
|
|
href: 'installedplugins.html',
|
|
|
|
name: globalize.translate('TabMyPlugins')
|
|
|
|
}, {
|
|
|
|
href: 'availableplugins.html',
|
|
|
|
name: globalize.translate('TabCatalog')
|
|
|
|
}, {
|
|
|
|
href: 'repositories.html',
|
|
|
|
name: globalize.translate('TabRepositories')
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
|
|
|
function onInstalledPluginsClick(e) {
|
|
|
|
if (dom.parentWithClass(e.target, 'noConfigPluginCard')) {
|
|
|
|
showNoConfigurationMessage();
|
|
|
|
} else if (dom.parentWithClass(e.target, 'connectModePluginCard')) {
|
|
|
|
showConnectMessage();
|
|
|
|
} else {
|
|
|
|
const btnCardMenu = dom.parentWithClass(e.target, 'btnCardMenu');
|
|
|
|
if (btnCardMenu) {
|
|
|
|
showPluginMenu(dom.parentWithClass(btnCardMenu, 'page'), btnCardMenu);
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
}
|
2020-07-26 22:25:54 +02:00
|
|
|
}
|
2019-04-02 15:16:51 -07:00
|
|
|
|
2020-07-26 22:25:54 +02:00
|
|
|
pageIdOn('pageshow', 'pluginsPage', function () {
|
|
|
|
libraryMenu.setTabs('plugins', 0, getTabs);
|
|
|
|
reloadList(this);
|
2019-02-26 21:12:58 +00:00
|
|
|
});
|
2020-07-26 22:25:54 +02:00
|
|
|
|
|
|
|
window.PluginsPage = {
|
|
|
|
renderPlugins: renderPlugins
|
|
|
|
};
|