1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00
jellyfin-web/src/scripts/plugincatalogpage.js

234 lines
7.8 KiB
JavaScript
Raw Normal View History

2019-01-10 21:37:02 +01:00
define(["loading", "libraryMenu", "globalize", "cardStyle", "emby-linkbutton", "emby-checkbox", "emby-select"], function (loading, libraryMenu, globalize) {
2018-10-23 01:05:09 +03:00
"use strict";
function reloadList(page) {
2019-01-10 21:37:02 +01:00
loading.show();
query.IsAppStoreSafe = true;
var promise1 = ApiClient.getAvailablePlugins(query);
var promise2 = ApiClient.getInstalledPlugins();
Promise.all([promise1, promise2]).then(function (responses) {
2018-10-23 01:05:09 +03:00
populateList({
catalogElement: page.querySelector("#pluginTiles"),
noItemsElement: page.querySelector("#noPlugins"),
availablePlugins: responses[0],
installedPlugins: responses[1]
2019-01-10 21:37:02 +01:00
});
});
2018-10-23 01:05:09 +03:00
}
function populateList(options) {
2019-01-10 21:37:02 +01:00
populateListInternal(options);
2018-10-23 01:05:09 +03:00
}
function getHeaderText(category) {
2019-01-14 22:52:33 +01:00
category = category.replace(" ", "");
2019-01-15 22:45:39 +01:00
2019-01-10 21:37:02 +01:00
if ("Channel" === category) {
category = "Channels";
2019-01-12 20:06:26 +01:00
} 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
}
function isUserInstalledPlugin(plugin) {
2019-01-10 21:37:02 +01:00
return -1 === ["02528C96-F727-44D7-BE87-9EEF040758C3", "0277E613-3EC0-4360-A3DE-F8AF0AABB5E9", "4DCB591C-0FA2-4C5D-A7E5-DABE37164C8B"].indexOf(plugin.guid);
2018-10-23 01:05:09 +03:00
}
function populateListInternal(options) {
2019-01-10 21:37:02 +01:00
var availablePlugins = options.availablePlugins;
var installedPlugins = options.installedPlugins;
2019-01-10 22:10:45 +01:00
var allPlugins = availablePlugins.filter(function (plugin) {
plugin.category = plugin.category || "General";
plugin.categoryDisplayName = getHeaderText(plugin.category);
2019-01-10 21:37:02 +01:00
2019-01-10 22:10:45 +01:00
if (!options.categories || -1 != options.categories.indexOf(plugin.category)) {
if (!options.targetSystem || plugin.targetSystem == options.targetSystem) {
return "UserInstalled" == plugin.type;
2019-01-10 21:37:02 +01:00
}
return false;
}
return false;
});
availablePlugins = allPlugins.sort(function (a__e, b__r) {
var aName = a__e.category;
var bName = b__r.category;
if (aName > bName) {
return 1;
}
if (bName > aName) {
return -1;
}
aName = a__e.name;
bName = b__r.name;
if (aName > bName) {
return 1;
}
if (bName > aName) {
return -1;
}
return 0;
2018-10-23 01:05:09 +03:00
});
2019-01-10 21:37:02 +01:00
var i__q;
var length;
var plugin;
var currentCategory;
var html = "";
2018-10-23 01:05:09 +03:00
if (!options.categories) {
2019-01-10 21:37:02 +01:00
currentCategory = globalize.translate("HeaderTopPlugins");
html += '<div class="verticalSection">';
html += '<h2 class="sectionTitle sectionTitle-cards">' + currentCategory + "</h2>";
var topPlugins = allPlugins.slice(0).sort(function (a__t, b__y) {
if (a__t.installs > b__y.installs) {
return -1;
}
if (b__y.installs > a__t.installs) {
return 1;
}
var aName = a__t.name;
var bName = b__y.name;
if (aName > bName) {
return 1;
}
if (bName > aName) {
return -1;
}
return 0;
2018-10-23 01:05:09 +03:00
}).filter(isUserInstalledPlugin);
html += '<div class="itemsContainer vertical-wrap">';
var limit = screen.availWidth >= 1920 ? 15 : 12;
2019-01-10 21:37:02 +01:00
for (i__q = 0, length = Math.min(topPlugins.length, limit); i__q < length; i__q++) {
html += getPluginHtml(topPlugins[i__q], options, installedPlugins);
}
html += "</div>";
html += "</div>";
2018-10-23 01:05:09 +03:00
}
2019-01-10 21:37:02 +01:00
var hasOpenTag = false;
for (currentCategory = null, false === options.showCategory && (html += '<div class="itemsContainer vertical-wrap">', hasOpenTag = true), i__q = 0, length = availablePlugins.length; i__q < length; i__q++) {
plugin = availablePlugins[i__q];
2018-10-23 01:05:09 +03:00
var category = plugin.categoryDisplayName;
2019-01-10 21:37:02 +01:00
if (category != currentCategory) {
if (false !== options.showCategory) {
if (currentCategory) {
hasOpenTag = false;
html += "</div>";
html += "</div>";
}
html += '<div class="verticalSection">';
html += '<h2 class="sectionTitle sectionTitle-cards">' + category + "</h2>";
html += '<div class="itemsContainer vertical-wrap">';
hasOpenTag = true;
}
currentCategory = category;
}
html += getPluginHtml(plugin, options, installedPlugins);
2018-10-23 01:05:09 +03:00
}
2019-01-10 21:37:02 +01:00
if (hasOpenTag) {
html += "</div>";
html += "</div>";
}
if (!availablePlugins.length && options.noItemsElement) {
options.noItemsElement.classList.add("hide");
}
options.catalogElement.innerHTML = html;
loading.hide();
2018-10-23 01:05:09 +03:00
}
function getPluginHtml(plugin, options, installedPlugins) {
2019-01-10 21:37:02 +01:00
var html = "";
var href = plugin.externalUrl ? plugin.externalUrl : "addplugin.html?name=" + encodeURIComponent(plugin.name) + "&guid=" + plugin.guid;
if (options.context) {
href += "&context=" + options.context;
}
2018-10-23 01:05:09 +03: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>';
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">&#xE2C7;</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;
2018-10-23 01:05:09 +03:00
})[0];
2019-01-10 21:37:02 +01:00
html += "<div class='cardText cardText-secondary'>";
html += installedPlugin ? globalize.translate("LabelVersionInstalled").replace("{0}", installedPlugin.Version) : "&nbsp;";
html += "</div>";
html += "</div>";
html += "</div>";
return html += "</div>";
2018-10-23 01:05:09 +03:00
}
function getTabs() {
return [{
href: "plugins.html",
name: globalize.translate("TabMyPlugins")
}, {
href: "plugincatalog.html",
name: globalize.translate("TabCatalog")
2019-01-10 21:37:02 +01:00
}];
2018-10-23 01:05:09 +03:00
}
2019-01-10 21:37:02 +01:00
2018-10-23 01:05:09 +03:00
var query = {
TargetSystems: "Server",
2019-01-10 21:37:02 +01:00
IsAdult: false
2018-10-23 01:05:09 +03:00
};
2019-01-10 21:37:02 +01:00
window.PluginCatalog = {
renderCatalog: populateList
};
return function (view, params) {
view.querySelector("#selectSystem").addEventListener("change", function () {
query.TargetSystems = this.value;
reloadList(view);
});
view.addEventListener("viewshow", function () {
libraryMenu.setTabs("plugins", 1, getTabs);
reloadList(this);
});
};
});