2020-08-14 08:46:34 +02:00
|
|
|
import 'jquery';
|
2021-11-10 00:09:56 -05:00
|
|
|
import { marked } from 'marked';
|
2021-09-05 00:58:39 -04:00
|
|
|
import DOMPurify from 'dompurify';
|
2020-08-14 08:46:34 +02:00
|
|
|
import loading from '../../../../components/loading/loading';
|
|
|
|
import globalize from '../../../../scripts/globalize';
|
|
|
|
import '../../../../elements/emby-button/emby-button';
|
2022-04-10 02:22:13 -04:00
|
|
|
import Dashboard from '../../../../utils/dashboard';
|
2020-10-18 15:18:15 +01:00
|
|
|
import alert from '../../../../components/alert';
|
|
|
|
import confirm from '../../../../components/confirm/confirm';
|
2020-07-26 22:25:54 +02:00
|
|
|
|
|
|
|
function populateHistory(packageInfo, page) {
|
|
|
|
let html = '';
|
|
|
|
const length = Math.min(packageInfo.versions.length, 10);
|
|
|
|
|
|
|
|
for (let i = 0; i < length; i++) {
|
2020-08-08 21:07:21 +02:00
|
|
|
const version = packageInfo.versions[i];
|
2020-07-26 22:25:54 +02:00
|
|
|
html += '<h2 style="margin:.5em 0;">' + version.version + '</h2>';
|
2021-09-05 00:58:39 -04:00
|
|
|
html += '<div style="margin-bottom:1.5em;">' + DOMPurify.sanitize(marked(version.changelog)) + '</div>';
|
2018-10-22 02:12:47 +03:00
|
|
|
}
|
|
|
|
|
2020-07-26 22:25:54 +02:00
|
|
|
$('#revisionHistory', page).html(html);
|
|
|
|
}
|
2018-10-22 02:12:47 +03:00
|
|
|
|
2020-07-26 22:25:54 +02:00
|
|
|
function populateVersions(packageInfo, page, installedPlugin) {
|
|
|
|
let html = '';
|
2020-07-28 23:08:27 +01:00
|
|
|
|
2021-02-25 19:59:57 +09:00
|
|
|
packageInfo.versions.sort((a, b) => {
|
2021-03-06 13:41:23 +09:00
|
|
|
return b.timestamp < a.timestamp ? -1 : 1;
|
2021-02-25 19:59:57 +09:00
|
|
|
});
|
|
|
|
|
2020-07-26 22:25:54 +02:00
|
|
|
for (let i = 0; i < packageInfo.versions.length; i++) {
|
|
|
|
const version = packageInfo.versions[i];
|
2020-11-21 13:21:01 +00:00
|
|
|
html += '<option value="' + version.version + '">' + globalize.translate('PluginFromRepo', version.version, version.repositoryName) + '</option>';
|
2020-07-26 22:25:54 +02:00
|
|
|
}
|
2019-11-06 13:43:39 +03:00
|
|
|
|
2020-07-26 22:25:54 +02:00
|
|
|
const selectmenu = $('#selectVersion', page).html(html);
|
2019-11-06 13:43:39 +03:00
|
|
|
|
2020-07-26 22:25:54 +02:00
|
|
|
if (!installedPlugin) {
|
|
|
|
$('#pCurrentVersion', page).hide().html('');
|
2018-10-22 02:12:47 +03:00
|
|
|
}
|
|
|
|
|
2021-03-06 13:41:43 +09:00
|
|
|
const packageVersion = packageInfo.versions[0];
|
2020-07-26 22:25:54 +02:00
|
|
|
if (packageVersion) {
|
|
|
|
selectmenu.val(packageVersion.version);
|
|
|
|
}
|
|
|
|
}
|
2019-11-06 13:43:39 +03:00
|
|
|
|
2020-07-26 22:25:54 +02:00
|
|
|
function renderPackage(pkg, installedPlugins, page) {
|
|
|
|
const installedPlugin = installedPlugins.filter(function (ip) {
|
|
|
|
return ip.Name == pkg.name;
|
|
|
|
})[0];
|
2019-11-06 13:43:39 +03:00
|
|
|
|
2020-07-26 22:25:54 +02:00
|
|
|
populateVersions(pkg, page, installedPlugin);
|
|
|
|
populateHistory(pkg, page);
|
2019-11-06 13:43:39 +03:00
|
|
|
|
2020-07-26 22:25:54 +02:00
|
|
|
$('.pluginName', page).html(pkg.name);
|
|
|
|
$('#btnInstallDiv', page).removeClass('hide');
|
|
|
|
$('#pSelectVersion', page).removeClass('hide');
|
2019-11-06 13:43:39 +03:00
|
|
|
|
2020-07-26 22:25:54 +02:00
|
|
|
if (pkg.overview) {
|
|
|
|
$('#overview', page).show().html(pkg.overview);
|
|
|
|
} else {
|
|
|
|
$('#overview', page).hide();
|
2018-10-22 02:12:47 +03:00
|
|
|
}
|
|
|
|
|
2020-07-26 22:25:54 +02:00
|
|
|
$('#description', page).html(pkg.description);
|
|
|
|
$('#developer', page).html(pkg.owner);
|
2020-04-11 20:32:39 +09:00
|
|
|
|
2020-07-26 22:25:54 +02:00
|
|
|
if (installedPlugin) {
|
|
|
|
const currentVersionText = globalize.translate('MessageYouHaveVersionInstalled', '<strong>' + installedPlugin.Version + '</strong>');
|
|
|
|
$('#pCurrentVersion', page).show().html(currentVersionText);
|
|
|
|
} else {
|
|
|
|
$('#pCurrentVersion', page).hide().html('');
|
2018-10-22 02:12:47 +03:00
|
|
|
}
|
2019-11-06 13:43:39 +03:00
|
|
|
|
2020-07-26 22:25:54 +02:00
|
|
|
loading.hide();
|
|
|
|
}
|
2019-11-06 13:43:39 +03:00
|
|
|
|
2020-07-26 22:25:54 +02:00
|
|
|
function alertText(options) {
|
2020-10-18 15:18:15 +01:00
|
|
|
alert(options);
|
2020-07-26 22:25:54 +02:00
|
|
|
}
|
2019-11-06 13:43:39 +03:00
|
|
|
|
2020-07-26 22:25:54 +02:00
|
|
|
function performInstallation(page, name, guid, version) {
|
|
|
|
const developer = $('#developer', page).html().toLowerCase();
|
2019-11-06 13:43:39 +03:00
|
|
|
|
2020-07-26 22:25:54 +02:00
|
|
|
const alertCallback = function () {
|
|
|
|
loading.show();
|
|
|
|
page.querySelector('#btnInstall').disabled = true;
|
|
|
|
ApiClient.installPlugin(name, guid, version).then(() => {
|
2018-10-22 02:12:47 +03:00
|
|
|
loading.hide();
|
2020-07-26 22:25:54 +02:00
|
|
|
alertText(globalize.translate('MessagePluginInstalled'));
|
|
|
|
}).catch(() => {
|
2020-08-08 18:51:27 +02:00
|
|
|
alertText(globalize.translate('MessagePluginInstallError'));
|
2020-07-26 22:25:54 +02:00
|
|
|
});
|
|
|
|
};
|
2019-11-06 13:43:39 +03:00
|
|
|
|
2020-07-26 22:25:54 +02:00
|
|
|
if (developer !== 'jellyfin') {
|
2019-02-05 21:36:09 +09:00
|
|
|
loading.hide();
|
2020-07-26 22:25:54 +02:00
|
|
|
let msg = globalize.translate('MessagePluginInstallDisclaimer');
|
|
|
|
msg += '<br/>';
|
|
|
|
msg += '<br/>';
|
|
|
|
msg += globalize.translate('PleaseConfirmPluginInstallation');
|
|
|
|
|
2020-10-18 15:18:15 +01:00
|
|
|
confirm(msg, globalize.translate('HeaderConfirmPluginInstallation')).then(function () {
|
|
|
|
alertCallback();
|
|
|
|
}).catch(() => {
|
|
|
|
console.debug('plugin not installed');
|
2019-11-06 13:43:39 +03:00
|
|
|
});
|
2020-07-26 22:25:54 +02:00
|
|
|
} else {
|
|
|
|
alertCallback();
|
2018-10-22 02:12:47 +03:00
|
|
|
}
|
2020-07-26 22:25:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export default function(view, params) {
|
|
|
|
$('.addPluginForm', view).on('submit', function () {
|
|
|
|
loading.show();
|
|
|
|
const page = $(this).parents('#addPluginPage')[0];
|
|
|
|
const name = params.name;
|
|
|
|
const guid = params.guid;
|
|
|
|
ApiClient.getInstalledPlugins().then(function (plugins) {
|
|
|
|
const installedPlugin = plugins.filter(function (plugin) {
|
|
|
|
return plugin.Name == name;
|
|
|
|
})[0];
|
|
|
|
|
|
|
|
const version = $('#selectVersion', page).val();
|
2020-08-08 16:48:25 +02:00
|
|
|
if (installedPlugin && installedPlugin.Version === version) {
|
2019-04-02 21:54:00 -07:00
|
|
|
loading.hide();
|
2020-08-08 16:48:25 +02:00
|
|
|
Dashboard.alert({
|
|
|
|
message: globalize.translate('MessageAlreadyInstalled'),
|
|
|
|
title: globalize.translate('HeaderPluginInstallation')
|
2019-04-02 21:54:00 -07:00
|
|
|
});
|
2020-07-26 22:25:54 +02:00
|
|
|
} else {
|
|
|
|
performInstallation(page, name, guid, version);
|
|
|
|
}
|
|
|
|
}).catch(() => {
|
|
|
|
alertText(globalize.translate('MessageGetInstalledPluginsError'));
|
2019-04-02 21:54:00 -07:00
|
|
|
});
|
2020-07-26 22:25:54 +02:00
|
|
|
return false;
|
|
|
|
});
|
|
|
|
view.addEventListener('viewshow', function () {
|
|
|
|
const page = this;
|
|
|
|
loading.show();
|
|
|
|
const name = params.name;
|
|
|
|
const guid = params.guid;
|
|
|
|
const promise1 = ApiClient.getPackageInfo(name, guid);
|
|
|
|
const promise2 = ApiClient.getInstalledPlugins();
|
|
|
|
Promise.all([promise1, promise2]).then(function (responses) {
|
|
|
|
renderPackage(responses[0], responses[1], page);
|
2019-11-06 13:43:39 +03:00
|
|
|
});
|
2020-07-26 22:25:54 +02:00
|
|
|
});
|
|
|
|
}
|