mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
move around half the dashboard controllers to a subdirectory
This commit is contained in:
parent
e108997376
commit
34c0d6019e
12 changed files with 64 additions and 69 deletions
172
src/controllers/dashboard/plugins/add.js
Normal file
172
src/controllers/dashboard/plugins/add.js
Normal file
|
@ -0,0 +1,172 @@
|
|||
define(["jQuery", "loading", "libraryMenu", "globalize", "connectionManager", "emby-button"], function ($, loading, libraryMenu, globalize, connectionManager) {
|
||||
"use strict";
|
||||
|
||||
function populateHistory(packageInfo, page) {
|
||||
var html = "";
|
||||
var length = Math.min(packageInfo.versions.length, 10);
|
||||
|
||||
for (var i = 0; i < length; i++) {
|
||||
var version = packageInfo.versions[i];
|
||||
html += '<h2 style="margin:.5em 0;">' + version.versionStr + " (" + version.classification + ")</h2>";
|
||||
html += '<div style="margin-bottom:1.5em;">' + version.description + "</div>";
|
||||
}
|
||||
|
||||
$("#revisionHistory", page).html(html);
|
||||
}
|
||||
|
||||
function populateVersions(packageInfo, page, installedPlugin) {
|
||||
var html = "";
|
||||
|
||||
for (var i = 0; i < packageInfo.versions.length; i++) {
|
||||
var version = packageInfo.versions[i];
|
||||
html += '<option value="' + version.versionStr + "|" + version.classification + '">' + version.versionStr + " (" + version.classification + ")</option>";
|
||||
}
|
||||
|
||||
var selectmenu = $("#selectVersion", page).html(html);
|
||||
|
||||
if (!installedPlugin) {
|
||||
$("#pCurrentVersion", page).hide().html("");
|
||||
}
|
||||
|
||||
var packageVersion = packageInfo.versions.filter(function (current) {
|
||||
return "Release" == current.classification;
|
||||
})[0];
|
||||
packageVersion = packageVersion || packageInfo.versions.filter(function (current) {
|
||||
return "Beta" == current.classification;
|
||||
})[0];
|
||||
|
||||
if (packageVersion) {
|
||||
var val = packageVersion.versionStr + "|" + packageVersion.classification;
|
||||
selectmenu.val(val);
|
||||
}
|
||||
}
|
||||
|
||||
function renderPackage(pkg, installedPlugins, page) {
|
||||
var installedPlugin = installedPlugins.filter(function (ip) {
|
||||
return ip.Name == pkg.name;
|
||||
})[0];
|
||||
populateVersions(pkg, page, installedPlugin);
|
||||
populateHistory(pkg, page);
|
||||
$(".pluginName", page).html(pkg.name);
|
||||
|
||||
if ("Server" == pkg.targetSystem) {
|
||||
$("#btnInstallDiv", page).removeClass("hide");
|
||||
$("#nonServerMsg", page).hide();
|
||||
$("#pSelectVersion", page).removeClass("hide");
|
||||
} else {
|
||||
$("#btnInstallDiv", page).addClass("hide");
|
||||
$("#pSelectVersion", page).addClass("hide");
|
||||
var msg = globalize.translate("MessageInstallPluginFromApp");
|
||||
$("#nonServerMsg", page).html(msg).show();
|
||||
}
|
||||
|
||||
if (pkg.shortDescription) {
|
||||
$("#tagline", page).show().html(pkg.shortDescription);
|
||||
} else {
|
||||
$("#tagline", page).hide();
|
||||
}
|
||||
|
||||
$("#overview", page).html(pkg.overview || "");
|
||||
$("#developer", page).html(pkg.owner);
|
||||
|
||||
if (pkg.richDescUrl) {
|
||||
$("#pViewWebsite", page).show();
|
||||
$("#pViewWebsite a", page).attr("href", pkg.richDescUrl);
|
||||
} else {
|
||||
$("#pViewWebsite", page).hide();
|
||||
}
|
||||
|
||||
if (pkg.previewImage || pkg.thumbImage) {
|
||||
var img = pkg.previewImage ? pkg.previewImage : pkg.thumbImage;
|
||||
$("#pPreviewImage", page).show().html("<img class='pluginPreviewImg' src='" + img + "' style='max-width: 100%;' />");
|
||||
} else {
|
||||
$("#pPreviewImage", page).hide().html("");
|
||||
}
|
||||
|
||||
if (installedPlugin) {
|
||||
var currentVersionText = globalize.translate("MessageYouHaveVersionInstalled").replace("{0}", "<strong>" + installedPlugin.Version + "</strong>");
|
||||
$("#pCurrentVersion", page).show().html(currentVersionText);
|
||||
} else {
|
||||
$("#pCurrentVersion", page).hide().html("");
|
||||
}
|
||||
|
||||
loading.hide();
|
||||
}
|
||||
|
||||
function alertText(options) {
|
||||
require(["alert"], function (alert) {
|
||||
alert(options);
|
||||
});
|
||||
}
|
||||
|
||||
function performInstallation(page, packageName, guid, updateClass, version) {
|
||||
var developer = $("#developer", page).html().toLowerCase();
|
||||
|
||||
var alertCallback = function () {
|
||||
loading.show();
|
||||
page.querySelector("#btnInstall").disabled = true;
|
||||
ApiClient.installPlugin(packageName, guid, updateClass, version).then(function () {
|
||||
loading.hide();
|
||||
alertText(globalize.translate("PluginInstalledMessage"));
|
||||
});
|
||||
};
|
||||
|
||||
if (developer !== 'jellyfin') {
|
||||
loading.hide();
|
||||
var msg = globalize.translate("MessagePluginInstallDisclaimer");
|
||||
msg += "<br/>";
|
||||
msg += "<br/>";
|
||||
msg += globalize.translate("PleaseConfirmPluginInstallation");
|
||||
|
||||
require(["confirm"], function (confirm) {
|
||||
confirm(msg, globalize.translate("HeaderConfirmPluginInstallation")).then(function () {
|
||||
alertCallback();
|
||||
}, function () {
|
||||
console.log('plugin not installed');
|
||||
});
|
||||
});
|
||||
} else {
|
||||
alertCallback();
|
||||
}
|
||||
}
|
||||
|
||||
return function (view, params) {
|
||||
$(".addPluginForm", view).on("submit", function () {
|
||||
loading.show();
|
||||
var page = $(this).parents("#addPluginPage")[0];
|
||||
var name = params.name;
|
||||
var guid = params.guid;
|
||||
ApiClient.getInstalledPlugins().then(function (plugins) {
|
||||
var installedPlugin = plugins.filter(function (plugin) {
|
||||
return plugin.Name == name;
|
||||
})[0];
|
||||
var vals = $("#selectVersion", page).val().split("|");
|
||||
var version = vals[0];
|
||||
|
||||
if (installedPlugin) {
|
||||
if (installedPlugin.Version === version) {
|
||||
loading.hide();
|
||||
Dashboard.alert({
|
||||
message: globalize.translate("MessageAlreadyInstalled"),
|
||||
title: globalize.translate("HeaderPluginInstallation")
|
||||
});
|
||||
}
|
||||
} else {
|
||||
performInstallation(page, name, guid, vals[1], version);
|
||||
}
|
||||
});
|
||||
return false;
|
||||
});
|
||||
view.addEventListener("viewshow", function () {
|
||||
var page = this;
|
||||
loading.show();
|
||||
var name = params.name;
|
||||
var guid = params.guid;
|
||||
var promise1 = ApiClient.getPackageInfo(name, guid);
|
||||
var promise2 = ApiClient.getInstalledPlugins();
|
||||
Promise.all([promise1, promise2]).then(function (responses) {
|
||||
renderPackage(responses[0], responses[1], page);
|
||||
});
|
||||
});
|
||||
};
|
||||
});
|
146
src/controllers/dashboard/plugins/available.js
Normal file
146
src/controllers/dashboard/plugins/available.js
Normal file
|
@ -0,0 +1,146 @@
|
|||
define(["loading", "libraryMenu", "globalize", "cardStyle", "emby-button", "emby-checkbox", "emby-select"], function (loading, libraryMenu, globalize) {
|
||||
"use strict";
|
||||
|
||||
function reloadList(page) {
|
||||
loading.show();
|
||||
var promise1 = ApiClient.getAvailablePlugins();
|
||||
var 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]
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function getHeaderText(category) {
|
||||
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";
|
||||
}
|
||||
|
||||
return globalize.translate(category);
|
||||
}
|
||||
|
||||
function populateList(options) {
|
||||
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;
|
||||
});
|
||||
|
||||
availablePlugins.sort(function (a, b) {
|
||||
if (a.category > b.category) {
|
||||
return 1;
|
||||
} else if (b.category > a.category) {
|
||||
return -1;
|
||||
}
|
||||
if (a.name > b.name) {
|
||||
return 1;
|
||||
} else if (b.name > a.name) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
|
||||
var currentCategory = null;
|
||||
var html = "";
|
||||
|
||||
for (var i = 0; i < availablePlugins.length; i++) {
|
||||
var plugin = availablePlugins[i];
|
||||
var 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);
|
||||
}
|
||||
html += "</div>";
|
||||
html += "</div>";
|
||||
|
||||
if (!availablePlugins.length && options.noItemsElement) {
|
||||
options.noItemsElement.classList.remove("hide");
|
||||
}
|
||||
|
||||
options.catalogElement.innerHTML = html;
|
||||
loading.hide();
|
||||
}
|
||||
|
||||
function getPluginHtml(plugin, options, installedPlugins) {
|
||||
var html = "";
|
||||
var href = plugin.externalUrl ? plugin.externalUrl : "addplugin.html?name=" + encodeURIComponent(plugin.name) + "&guid=" + plugin.guid;
|
||||
|
||||
if (options.context) {
|
||||
href += "&context=" + options.context;
|
||||
}
|
||||
|
||||
var 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 + ">";
|
||||
|
||||
if (plugin.thumbImage) {
|
||||
html += '<div class="cardImage coveredImage" style="background-image:url(\'' + plugin.thumbImage + "');\">";
|
||||
html += "</div>";
|
||||
} else {
|
||||
html += '<i class="cardImageIcon md-icon">folder</i>';
|
||||
}
|
||||
|
||||
html += "</a>";
|
||||
html += "</div>";
|
||||
html += '<div class="cardFooter">';
|
||||
html += "<div class='cardText'>";
|
||||
html += plugin.name;
|
||||
html += "</div>";
|
||||
var installedPlugin = plugin.isApp ? null : installedPlugins.filter(function (ip) {
|
||||
return ip.Id == plugin.guid;
|
||||
})[0];
|
||||
html += "<div class='cardText cardText-secondary'>";
|
||||
html += installedPlugin ? globalize.translate("LabelVersionInstalled").replace("{0}", installedPlugin.Version) : " ";
|
||||
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")
|
||||
}];
|
||||
}
|
||||
|
||||
window.PluginCatalog = {
|
||||
renderCatalog: populateList
|
||||
};
|
||||
|
||||
return function (view, params) {
|
||||
view.addEventListener("viewshow", function () {
|
||||
libraryMenu.setTabs("plugins", 1, getTabs);
|
||||
reloadList(this);
|
||||
});
|
||||
};
|
||||
});
|
185
src/controllers/dashboard/plugins/installed.js
Normal file
185
src/controllers/dashboard/plugins/installed.js
Normal file
|
@ -0,0 +1,185 @@
|
|||
define(["loading", "libraryMenu", "dom", "globalize", "cardStyle", "emby-button"], function (loading, libraryMenu, dom, globalize) {
|
||||
"use strict";
|
||||
|
||||
function deletePlugin(page, uniqueid, name) {
|
||||
var msg = globalize.translate("UninstallPluginConfirmation").replace("{0}", name);
|
||||
|
||||
require(["confirm"], function (confirm) {
|
||||
confirm({
|
||||
title: globalize.translate("UninstallPluginHeader"),
|
||||
text: msg,
|
||||
primary: "delete",
|
||||
confirmText: globalize.translate("UninstallPluginHeader")
|
||||
}).then(function () {
|
||||
loading.show();
|
||||
ApiClient.uninstallPlugin(uniqueid).then(function () {
|
||||
reloadList(page);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function showNoConfigurationMessage() {
|
||||
Dashboard.alert({
|
||||
message: globalize.translate("NoPluginConfigurationMessage")
|
||||
});
|
||||
}
|
||||
|
||||
function showConnectMessage() {
|
||||
Dashboard.alert({
|
||||
message: globalize.translate("MessagePluginConfigurationRequiresLocalAccess")
|
||||
});
|
||||
}
|
||||
|
||||
function getPluginCardHtml(plugin, pluginConfigurationPages) {
|
||||
var configPage = pluginConfigurationPages.filter(function (pluginConfigurationPage) {
|
||||
return pluginConfigurationPage.PluginId == plugin.Id;
|
||||
})[0];
|
||||
var configPageUrl = configPage ? Dashboard.getConfigurationPageUrl(configPage.Name) : null;
|
||||
var html = "";
|
||||
html += "<div data-id='" + plugin.Id + "' data-name='" + plugin.Name + "' 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">';
|
||||
|
||||
if (plugin.ImageUrl) {
|
||||
html += '<div class="cardImage coveredImage" style="background-image:url(\'' + plugin.ImageUrl + "');\">";
|
||||
html += "</div>";
|
||||
} else {
|
||||
html += '<i class="cardImageIcon md-icon">folder</i>';
|
||||
}
|
||||
|
||||
html += configPageUrl ? "</a>" : "</div>";
|
||||
html += "</div>";
|
||||
html += '<div class="cardFooter">';
|
||||
html += '<div style="text-align:right; float:right;padding-top:5px;">';
|
||||
html += '<button type="button" is="paper-icon-button-light" class="btnCardMenu autoSize"><i class="md-icon">more_horiz</i></button>';
|
||||
html += "</div>";
|
||||
html += "<div class='cardText'>";
|
||||
html += configPage ? configPage.DisplayName || plugin.Name : 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);
|
||||
});
|
||||
}
|
||||
|
||||
function populateList(page, plugins, pluginConfigurationPages) {
|
||||
plugins = plugins.sort(function (plugin1, plugin2) {
|
||||
if (plugin1.Name > plugin2.Name) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return -1;
|
||||
});
|
||||
var html = plugins.map(function (p) {
|
||||
return getPluginCardHtml(p, pluginConfigurationPages);
|
||||
}).join("");
|
||||
var 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 style="padding:5px;">';
|
||||
html += "<p>" + globalize.translate("MessageNoPluginsInstalled") + "</p>";
|
||||
html += '<p><a is="emby-linkbutton" class="button-link" href="availableplugins.html">';
|
||||
html += globalize.translate("BrowsePluginCatalogMessage");
|
||||
html += "</a></p>";
|
||||
html += "</div>";
|
||||
}
|
||||
|
||||
installedPluginsElement.innerHTML = html;
|
||||
loading.hide();
|
||||
}
|
||||
|
||||
function showPluginMenu(page, elem) {
|
||||
var card = dom.parentWithClass(elem, "card");
|
||||
var id = card.getAttribute("data-id");
|
||||
var name = card.getAttribute("data-name");
|
||||
var configHref = card.querySelector(".cardContent").getAttribute("href");
|
||||
var menuItems = [];
|
||||
|
||||
if (configHref) {
|
||||
menuItems.push({
|
||||
name: globalize.translate("ButtonSettings"),
|
||||
id: "open",
|
||||
icon: "mode_edit"
|
||||
});
|
||||
}
|
||||
|
||||
menuItems.push({
|
||||
name: globalize.translate("ButtonUninstall"),
|
||||
id: "delete",
|
||||
icon: "delete"
|
||||
});
|
||||
|
||||
require(["actionsheet"], function (actionsheet) {
|
||||
actionsheet.show({
|
||||
items: menuItems,
|
||||
positionTo: elem,
|
||||
callback: function (resultId) {
|
||||
switch (resultId) {
|
||||
case "open":
|
||||
Dashboard.navigate(configHref);
|
||||
break;
|
||||
|
||||
case "delete":
|
||||
deletePlugin(page, id, name);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
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")
|
||||
}];
|
||||
}
|
||||
|
||||
function onInstalledPluginsClick(e) {
|
||||
if (dom.parentWithClass(e.target, "noConfigPluginCard")) {
|
||||
showNoConfigurationMessage();
|
||||
} else if (dom.parentWithClass(e.target, "connectModePluginCard")) {
|
||||
showConnectMessage();
|
||||
} else {
|
||||
var btnCardMenu = dom.parentWithClass(e.target, "btnCardMenu");
|
||||
|
||||
if (btnCardMenu) {
|
||||
showPluginMenu(dom.parentWithClass(btnCardMenu, "page"), btnCardMenu);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pageIdOn("pageshow", "pluginsPage", function () {
|
||||
libraryMenu.setTabs("plugins", 0, getTabs);
|
||||
reloadList(this);
|
||||
});
|
||||
window.PluginsPage = {
|
||||
renderPlugins: renderPlugins
|
||||
};
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue