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';
|
2021-01-25 02:50:15 +09:00
|
|
|
import * as cardBuilder from '../../../../components/cardbuilder/cardBuilder.js';
|
2021-01-26 16:25:38 -05:00
|
|
|
import '../../../../components/cardbuilder/card.scss';
|
2020-08-14 08:46:34 +02:00
|
|
|
import '../../../../elements/emby-button/emby-button';
|
2022-04-10 02:22:13 -04:00
|
|
|
import Dashboard, { pageIdOn } from '../../../../utils/dashboard';
|
2020-10-18 15:18:15 +01:00
|
|
|
import confirm from '../../../../components/confirm/confirm';
|
2020-07-26 22:25:54 +02:00
|
|
|
|
2020-12-14 22:54:21 +00:00
|
|
|
function deletePlugin(page, uniqueid, version, name) {
|
2020-07-26 22:25:54 +02:00
|
|
|
const msg = globalize.translate('UninstallPluginConfirmation', name);
|
|
|
|
|
2020-11-19 17:38:49 -05:00
|
|
|
confirm({
|
2020-10-18 15:18:15 +01:00
|
|
|
title: globalize.translate('HeaderUninstallPlugin'),
|
|
|
|
text: msg,
|
|
|
|
primary: 'delete',
|
|
|
|
confirmText: globalize.translate('HeaderUninstallPlugin')
|
|
|
|
}).then(function () {
|
|
|
|
loading.show();
|
2020-12-15 15:52:43 +00:00
|
|
|
ApiClient.uninstallPluginByVersion(uniqueid, version).then(function () {
|
2020-10-18 15:18:15 +01:00
|
|
|
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-12-14 22:54:21 +00:00
|
|
|
function enablePlugin(page, uniqueid, version) {
|
2020-12-13 22:12:41 +00:00
|
|
|
loading.show();
|
2020-12-14 22:54:21 +00:00
|
|
|
ApiClient.enablePlugin(uniqueid, version).then(function () {
|
2020-12-13 22:12:41 +00:00
|
|
|
reloadList(page);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-12-14 22:54:21 +00:00
|
|
|
function disablePlugin(page, uniqueid, version) {
|
2020-12-13 22:12:41 +00:00
|
|
|
loading.show();
|
2020-12-14 22:54:21 +00:00
|
|
|
ApiClient.disablePlugin(uniqueid, version).then(function () {
|
2020-12-13 22:12:41 +00:00
|
|
|
reloadList(page);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
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];
|
2021-02-07 00:16:45 +09:00
|
|
|
|
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 = '';
|
2021-02-07 00:16:45 +09:00
|
|
|
|
2020-12-30 15:29:51 +00:00
|
|
|
html += `<div data-id='${plugin.Id}' data-version='${plugin.Version}' data-name='${plugin.Name}' data-removable='${plugin.CanUninstall}' data-status='${plugin.Status}' class='card backdropCard'>`;
|
2020-07-26 22:25:54 +02:00
|
|
|
html += '<div class="cardBox visualCardBox">';
|
|
|
|
html += '<div class="cardScalable">';
|
|
|
|
html += '<div class="cardPadder cardPadder-backdrop"></div>';
|
2021-02-17 12:11:21 +09:00
|
|
|
html += '<div class="cardContent">';
|
2021-01-25 02:50:15 +09:00
|
|
|
if (configPageUrl) {
|
2021-02-17 12:07:42 +09:00
|
|
|
html += `<a class="cardImageContainer" is="emby-linkbutton" style="margin:0;padding:0" href="${configPageUrl}">`;
|
2020-12-13 22:12:41 +00:00
|
|
|
} else {
|
2021-02-24 00:06:53 +09:00
|
|
|
html += '<div class="cardImageContainer noConfigPluginCard noHoverEffect emby-button" style="margin:0;padding:0">';
|
2020-12-13 22:12:41 +00:00
|
|
|
}
|
2021-01-25 02:50:15 +09:00
|
|
|
|
|
|
|
if (plugin.HasImage) {
|
2021-11-05 23:18:51 +03:00
|
|
|
const imageUrl = ApiClient.getUrl(`/Plugins/${plugin.Id}/${plugin.Version}/Image`);
|
|
|
|
html += `<img src="${imageUrl}" style="width:100%" />`;
|
2021-02-07 00:16:45 +09:00
|
|
|
} else {
|
2021-02-17 12:07:42 +09:00
|
|
|
html += `<div class="cardImage flex align-items-center justify-content-center ${cardBuilder.getDefaultBackgroundClass()}">`;
|
2022-02-24 20:15:24 +03:00
|
|
|
html += '<span class="cardImageIcon material-icons extension" aria-hidden="true"></span>';
|
2021-02-17 12:07:42 +09:00
|
|
|
html += '</div>';
|
2021-01-25 02:50:15 +09:00
|
|
|
}
|
2020-07-26 22:25:54 +02:00
|
|
|
html += configPageUrl ? '</a>' : '</div>';
|
|
|
|
html += '</div>';
|
2021-01-25 02:50:15 +09:00
|
|
|
html += '</div>';
|
2020-07-26 22:25:54 +02:00
|
|
|
html += '<div class="cardFooter">';
|
|
|
|
|
|
|
|
if (configPage || plugin.CanUninstall) {
|
2023-09-12 17:29:03 -04:00
|
|
|
if (globalize.getIsRTL()) {
|
2022-07-14 17:59:23 -04:00
|
|
|
html += '<div style="text-align:left; float:left;padding-top:5px;">';
|
2023-09-12 17:29:03 -04:00
|
|
|
} else {
|
2022-07-14 17:59:23 -04:00
|
|
|
html += '<div style="text-align:right; float:right;padding-top:5px;">';
|
2023-09-12 17:29:03 -04:00
|
|
|
}
|
2022-02-24 20:15:24 +03:00
|
|
|
html += '<button type="button" is="paper-icon-button-light" class="btnCardMenu autoSize"><span class="material-icons more_vert" aria-hidden="true"></span></button>';
|
2020-07-26 22:25:54 +02:00
|
|
|
html += '</div>';
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
2021-02-24 00:11:53 +09:00
|
|
|
html += '<div class="cardText">';
|
2021-02-24 00:06:53 +09:00
|
|
|
html += `${plugin.Name}<span class='cardText cardText-secondary'>${plugin.Version}</span>`;
|
2020-07-26 22:25:54 +02:00
|
|
|
html += '</div>';
|
2021-02-24 00:06:53 +09:00
|
|
|
html += `<div class="cardText">${globalize.translate('LabelStatus')} ${plugin.Status}</div>`;
|
2020-07-26 22:25:54 +02:00
|
|
|
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>';
|
2022-06-09 14:54:39 -04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-10-21 00:06:23 +02:00
|
|
|
// add search box listener
|
|
|
|
const searchBar = page.querySelector('#txtSearchPlugins');
|
|
|
|
if (searchBar) {
|
|
|
|
searchBar.addEventListener('input', () => onFilterType(page, searchBar));
|
|
|
|
}
|
|
|
|
|
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');
|
2021-02-07 00:16:45 +09:00
|
|
|
const configHref = card.querySelector('.cardImageContainer').getAttribute('href');
|
2020-12-13 22:12:41 +00:00
|
|
|
const status = card.getAttribute('data-status');
|
2020-12-14 22:54:21 +00:00
|
|
|
const version = card.getAttribute('data-version');
|
2020-07-26 22:25:54 +02:00
|
|
|
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') {
|
2020-12-13 22:12:41 +00:00
|
|
|
if (status === 'Disabled') {
|
|
|
|
menuItems.push({
|
|
|
|
name: globalize.translate('EnablePlugin'),
|
|
|
|
id: 'enable',
|
2021-02-24 00:06:53 +09:00
|
|
|
icon: 'check_circle_outline'
|
2020-12-13 22:12:41 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status === 'Active') {
|
|
|
|
menuItems.push({
|
|
|
|
name: globalize.translate('DisablePlugin'),
|
|
|
|
id: 'disable',
|
2021-02-24 00:06:53 +09:00
|
|
|
icon: 'do_not_disturb'
|
2020-12-13 22:12:41 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-07-26 22:25:54 +02:00
|
|
|
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':
|
2020-12-14 22:54:21 +00:00
|
|
|
deletePlugin(page, id, version, name);
|
2020-07-26 22:25:54 +02:00
|
|
|
break;
|
2020-12-13 22:12:41 +00:00
|
|
|
case 'enable':
|
2020-12-14 22:54:21 +00:00
|
|
|
enablePlugin(page, id, version);
|
2020-12-13 22:12:41 +00:00
|
|
|
break;
|
|
|
|
case 'disable':
|
2020-12-14 22:54:21 +00:00
|
|
|
disablePlugin(page, id, version);
|
2020-12-13 22:12:41 +00:00
|
|
|
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 [{
|
2022-06-09 14:54:39 -04:00
|
|
|
href: '#/installedplugins.html',
|
2020-07-26 22:25:54 +02:00
|
|
|
name: globalize.translate('TabMyPlugins')
|
|
|
|
}, {
|
2022-06-09 14:54:39 -04:00
|
|
|
href: '#/availableplugins.html',
|
2020-07-26 22:25:54 +02:00
|
|
|
name: globalize.translate('TabCatalog')
|
|
|
|
}, {
|
2022-06-09 14:54:39 -04:00
|
|
|
href: '#/repositories.html',
|
2020-07-26 22:25:54 +02:00
|
|
|
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
|
|
|
|
2022-10-21 00:06:23 +02:00
|
|
|
function onFilterType(page, searchBar) {
|
|
|
|
const filter = searchBar.value.toLowerCase();
|
|
|
|
for (const card of page.querySelectorAll('.card')) {
|
|
|
|
if (filter && filter != '' && !card.textContent.toLowerCase().includes(filter)) {
|
|
|
|
card.style.display = 'none';
|
|
|
|
} else {
|
|
|
|
card.style.display = 'unset';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
};
|