diff --git a/dashboard-ui/scripts/plugincatalogpage.js b/dashboard-ui/scripts/plugincatalogpage.js index d786a2e2a6..73b6215611 100644 --- a/dashboard-ui/scripts/plugincatalogpage.js +++ b/dashboard-ui/scripts/plugincatalogpage.js @@ -45,7 +45,7 @@ var availablePlugins = options.availablePlugins; var installedPlugins = options.installedPlugins; - availablePlugins = availablePlugins.filter(function (p) { + var allPlugins = availablePlugins.filter(function (p) { p.category = p.category || "General"; p.categoryDisplayName = Globalize.translate('PluginCategory' + p.category.replace(' ', '')); @@ -64,21 +64,74 @@ return p.type == "UserInstalled"; - }).sort(function (a, b) { - - var aName = (a.category) + " " + a.name; - var bame = (b.category) + " " + b.name; - - return aName > bame ? 1 : -1; }); - var pluginhtml = ''; + availablePlugins = allPlugins.sort(function (a, b) { - var currentCategory; + var aName = (a.category); + var bName = (b.category); - for (var i = 0, length = availablePlugins.length; i < length; i++) { - var html = ''; - var plugin = availablePlugins[i]; + if (aName > bName) { + return 1; + } + if (bName > aName) { + return -1; + } + + aName = (a.name); + bName = (b.name); + + if (aName > bName) { + return 1; + } + if (bName > aName) { + return -1; + } + + if (a.installs > b.installs) { + return 1; + } + if (b.installs > a.installs) { + return -1; + } + + return 0; + }); + + var html = ''; + var i, length, plugin; + + var currentCategory = Globalize.translate('HeaderTopPlugins'); + html += '
' + currentCategory + '
'; + var topPlugins = allPlugins.slice(0).sort(function (a, b) { + + if (a.installs > b.installs) { + return 1; + } + if (b.installs > a.installs) { + return -1; + } + + var aName = (a.name); + var bName = (b.name); + + if (aName > bName) { + return 1; + } + if (bName > aName) { + return -1; + } + + return 0; + }); + + for (i = 0, length = Math.min(topPlugins.length, 12) ; i < length; i++) { + html += getPluginHtml(topPlugins[i], options, installedPlugins); + } + + for (i = 0, length = availablePlugins.length; i < length; i++) { + + plugin = availablePlugins[i]; var category = plugin.categoryDisplayName; @@ -97,83 +150,7 @@ currentCategory = category; } - 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 += "
"; - - html += '
'; - html += '
'; - - html += '
'; - - html += ''; - if (plugin.thumbImage) { - html += '"; - - html += '
'; - - html += "
"; - html += plugin.name; - html += "
"; - - if (!plugin.isExternal) { - html += "
"; - html += plugin.price > 0 ? "$" + plugin.price.toFixed(2) : Globalize.translate('LabelFree'); - html += RatingHelpers.getStoreRatingHtml(plugin.avgRating, plugin.id, plugin.name, true); - - html += ""; - html += " " + Globalize.translate('LabelNumberReviews').replace("{0}", plugin.totalRatings); - html += ""; - - html += "
"; - } - - var installedPlugin = plugin.isApp ? null : installedPlugins.filter(function (ip) { - return ip.Id == plugin.guid; - })[0]; - - html += "
"; - - if (installedPlugin) { - html += Globalize.translate('LabelVersionInstalled').replace("{0}", installedPlugin.Version); - } else { - html += ' '; - } - html += "
"; - - // cardFooter - html += "
"; - - // cardBox - html += "
"; - - // card - html += "
"; - - pluginhtml += html; + html += getPluginHtml(plugin, options, installedPlugins); } @@ -181,11 +158,94 @@ $(options.noItemsElement).hide(); } - $(options.catalogElement).html(pluginhtml); + $(options.catalogElement).html(html); Dashboard.hideLoadingMsg(); } + 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 += "
"; + + html += '
'; + html += '
'; + + html += '
'; + + html += ''; + if (plugin.thumbImage) { + html += '"; + + html += '
'; + + html += "
"; + html += plugin.name; + html += "
"; + + if (!plugin.isExternal) { + html += "
"; + html += plugin.price > 0 ? "$" + plugin.price.toFixed(2) : Globalize.translate('LabelFree'); + html += RatingHelpers.getStoreRatingHtml(plugin.avgRating, plugin.id, plugin.name, true); + + html += ""; + html += " " + Globalize.translate('LabelNumberReviews').replace("{0}", plugin.totalRatings); + html += ""; + + html += "
"; + } + + var installedPlugin = plugin.isApp ? null : installedPlugins.filter(function (ip) { + return ip.Id == plugin.guid; + })[0]; + + html += "
"; + + if (installedPlugin) { + html += Globalize.translate('LabelVersionInstalled').replace("{0}", installedPlugin.Version); + } else { + html += ' '; + } + html += "
"; + + // cardFooter + html += "
"; + + // cardBox + html += "
"; + + // card + html += "
"; + + return html; + } + $(document).on('pageinitdepends', "#pluginCatalogPage", function () { var page = this; diff --git a/dashboard-ui/strings/javascript/javascript.json b/dashboard-ui/strings/javascript/javascript.json index 4f68e3a0fb..0143627c7c 100644 --- a/dashboard-ui/strings/javascript/javascript.json +++ b/dashboard-ui/strings/javascript/javascript.json @@ -847,6 +847,6 @@ "OptionBanner": "Banner", "NoSlideshowContentFound": "No slideshow images were found.", "OptionPhotoSlideshow": "Photo slideshow", - "OptionBackdropSlideshow": "Backdrop slideshow" - + "OptionBackdropSlideshow": "Backdrop slideshow", + "HeaderTopPlugins": "Top Plugins" }