mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Adding paging and search to installed modules.
--HG-- branch : dev
This commit is contained in:
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
using Orchard.Data.Migration;
|
using Orchard.Data.Migration;
|
||||||
|
using Orchard.DisplayManagement;
|
||||||
using Orchard.Environment.Descriptor.Models;
|
using Orchard.Environment.Descriptor.Models;
|
||||||
using Orchard.Environment.Extensions;
|
using Orchard.Environment.Extensions;
|
||||||
using Orchard.Environment.Extensions.Models;
|
using Orchard.Environment.Extensions.Models;
|
||||||
@@ -15,6 +16,7 @@ using Orchard.Modules.Services;
|
|||||||
using Orchard.Modules.ViewModels;
|
using Orchard.Modules.ViewModels;
|
||||||
using Orchard.Reports.Services;
|
using Orchard.Reports.Services;
|
||||||
using Orchard.Security;
|
using Orchard.Security;
|
||||||
|
using Orchard.UI.Navigation;
|
||||||
using Orchard.UI.Notify;
|
using Orchard.UI.Notify;
|
||||||
using Orchard.Utility.Extensions;
|
using Orchard.Utility.Extensions;
|
||||||
|
|
||||||
@@ -36,7 +38,8 @@ namespace Orchard.Modules.Controllers {
|
|||||||
IReportsCoordinator reportsCoordinator,
|
IReportsCoordinator reportsCoordinator,
|
||||||
IExtensionManager extensionManager,
|
IExtensionManager extensionManager,
|
||||||
IFeatureManager featureManager,
|
IFeatureManager featureManager,
|
||||||
ShellDescriptor shellDescriptor)
|
ShellDescriptor shellDescriptor,
|
||||||
|
IShapeFactory shapeFactory)
|
||||||
{
|
{
|
||||||
Services = services;
|
Services = services;
|
||||||
_extensionDisplayEventHandler = extensionDisplayEventHandlers.FirstOrDefault();
|
_extensionDisplayEventHandler = extensionDisplayEventHandlers.FirstOrDefault();
|
||||||
@@ -46,6 +49,7 @@ namespace Orchard.Modules.Controllers {
|
|||||||
_extensionManager = extensionManager;
|
_extensionManager = extensionManager;
|
||||||
_featureManager = featureManager;
|
_featureManager = featureManager;
|
||||||
_shellDescriptor = shellDescriptor;
|
_shellDescriptor = shellDescriptor;
|
||||||
|
Shape = shapeFactory;
|
||||||
|
|
||||||
T = NullLocalizer.Instance;
|
T = NullLocalizer.Instance;
|
||||||
Logger = NullLogger.Instance;
|
Logger = NullLogger.Instance;
|
||||||
@@ -54,13 +58,18 @@ namespace Orchard.Modules.Controllers {
|
|||||||
public Localizer T { get; set; }
|
public Localizer T { get; set; }
|
||||||
public IOrchardServices Services { get; set; }
|
public IOrchardServices Services { get; set; }
|
||||||
public ILogger Logger { get; set; }
|
public ILogger Logger { get; set; }
|
||||||
|
public dynamic Shape { get; set; }
|
||||||
|
|
||||||
public ActionResult Index() {
|
public ActionResult Index(ModulesIndexOptions options, PagerParameters pagerParameters) {
|
||||||
if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not allowed to manage modules")))
|
if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not allowed to manage modules")))
|
||||||
return new HttpUnauthorizedResult();
|
return new HttpUnauthorizedResult();
|
||||||
|
|
||||||
|
Pager pager = new Pager(Services.WorkContext.CurrentSite, pagerParameters);
|
||||||
|
|
||||||
IEnumerable<ModuleEntry> modules = _extensionManager.AvailableExtensions()
|
IEnumerable<ModuleEntry> modules = _extensionManager.AvailableExtensions()
|
||||||
.Where(x => DefaultExtensionTypes.IsModule(x.ExtensionType))
|
.Where(extensionDescriptor => DefaultExtensionTypes.IsModule(extensionDescriptor.ExtensionType) &&
|
||||||
|
(string.IsNullOrEmpty(options.SearchText) || extensionDescriptor.Name.ToLowerInvariant().Contains(options.SearchText.ToLowerInvariant())))
|
||||||
|
.OrderBy(extensionDescriptor => extensionDescriptor.Name)
|
||||||
.Select(extensionDescriptor => {
|
.Select(extensionDescriptor => {
|
||||||
ModuleEntry moduleEntry = new ModuleEntry {
|
ModuleEntry moduleEntry = new ModuleEntry {
|
||||||
Descriptor = extensionDescriptor,
|
Descriptor = extensionDescriptor,
|
||||||
@@ -76,9 +85,17 @@ namespace Orchard.Modules.Controllers {
|
|||||||
return moduleEntry;
|
return moduleEntry;
|
||||||
});
|
});
|
||||||
|
|
||||||
return View(new ModulesIndexViewModel {
|
int totalItemCount = modules.Count();
|
||||||
|
|
||||||
|
if (pager.PageSize != 0) {
|
||||||
|
modules = modules.Skip((pager.Page - 1) * pager.PageSize).Take(pager.PageSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
return View(new ModulesIndexViewModel {
|
||||||
Modules = modules,
|
Modules = modules,
|
||||||
InstallModules = _featureManager.GetEnabledFeatures().FirstOrDefault(f => f.Id == "PackagingServices") != null
|
InstallModules = _featureManager.GetEnabledFeatures().FirstOrDefault(f => f.Id == "PackagingServices") != null,
|
||||||
|
Options = options,
|
||||||
|
Pager = Shape.Pager(pager).TotalItemCount(totalItemCount)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,5 +5,12 @@ namespace Orchard.Modules.ViewModels {
|
|||||||
public class ModulesIndexViewModel {
|
public class ModulesIndexViewModel {
|
||||||
public bool InstallModules { get; set; }
|
public bool InstallModules { get; set; }
|
||||||
public IEnumerable<ModuleEntry> Modules { get; set; }
|
public IEnumerable<ModuleEntry> Modules { get; set; }
|
||||||
|
|
||||||
|
public ModulesIndexOptions Options { get; set; }
|
||||||
|
public dynamic Pager { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ModulesIndexOptions {
|
||||||
|
public string SearchText { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -8,17 +8,47 @@
|
|||||||
@{
|
@{
|
||||||
Style.Require("ModulesAdmin");
|
Style.Require("ModulesAdmin");
|
||||||
|
|
||||||
|
var pageSizes = new List<int?>() { 10, 50, 100 };
|
||||||
|
var defaultPageSize = WorkContext.CurrentSite.PageSize;
|
||||||
|
if (!pageSizes.Contains(defaultPageSize)) {
|
||||||
|
pageSizes.Add(defaultPageSize);
|
||||||
|
}
|
||||||
|
|
||||||
Layout.Title = T("Modules").ToString();
|
Layout.Title = T("Modules").ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@if (Model.InstallModules) {
|
@using (Html.BeginFormAntiForgeryPost(Url.Action("Index", "Admin"))) {
|
||||||
<div class="manage">@Html.ActionLink(T("Install a module").ToString(), "AddModule", "PackagingServices", new { area = "Orchard.Packaging", returnUrl = HttpContext.Current.Request.RawUrl }, new { @class = "button primaryAction" })</div>
|
<fieldset class="bulk-actions">
|
||||||
}
|
<input type="hidden" name="Page" value="1" />
|
||||||
|
<label for="pageSize">@T("Show:")</label>
|
||||||
|
<select id="pageSize" name="PageSize">
|
||||||
|
@Html.SelectOption((int)Model.Pager.PageSize, 0, T("All").ToString())
|
||||||
|
@foreach (int size in pageSizes.OrderBy(p => p)) {
|
||||||
|
@Html.SelectOption((int)Model.Pager.PageSize, size, size.ToString())
|
||||||
|
}
|
||||||
|
</select>
|
||||||
|
<button type="submit">@T("Apply")</button>
|
||||||
|
</fieldset>
|
||||||
|
|
||||||
@if (Model.Modules.Count() > 0) {
|
<fieldset class="search-actions">
|
||||||
<ul class="contentItems">
|
<input type="text" id="searchText" name="@Html.NameOf(m => m.Options.SearchText)" value="@Model.Options.SearchText" />
|
||||||
@foreach (ModuleEntry module in Model.Modules.OrderBy(m => m.Descriptor.Name)) {
|
|
||||||
<li>@Display.ModuleEntry(ContentPart: module)</li>
|
<button type="submit">@T("Search").ToString()</button>
|
||||||
|
|
||||||
|
@if (Model.InstallModules) {
|
||||||
|
@Html.ActionLink(T("Install a module").ToString(), "AddModule", "PackagingServices", new { area = "Orchard.Packaging", returnUrl = HttpContext.Current.Request.RawUrl }, new { @class = "button primaryAction" })
|
||||||
}
|
}
|
||||||
</ul>
|
</fieldset>
|
||||||
|
|
||||||
|
if (Model.Modules.Count() > 0) {
|
||||||
|
<ul class="contentItems">
|
||||||
|
@foreach (ModuleEntry module in Model.Modules.OrderBy(m => m.Descriptor.Name)) {
|
||||||
|
<li>@Display.ModuleEntry(ContentPart: module)</li>
|
||||||
|
}
|
||||||
|
</ul>
|
||||||
|
} else {
|
||||||
|
<p>@T("No modules available").ToString()</p>
|
||||||
|
}
|
||||||
|
|
||||||
|
@Display(Model.Pager)
|
||||||
}
|
}
|
||||||
@@ -148,4 +148,14 @@
|
|||||||
}
|
}
|
||||||
.updateAvailable {
|
.updateAvailable {
|
||||||
background-color: #f1f0cb;
|
background-color: #f1f0cb;
|
||||||
|
}
|
||||||
|
.search-actions {
|
||||||
|
float: right;
|
||||||
|
display: inline;
|
||||||
|
height: auto;
|
||||||
|
margin: 0 1.4em 0 0;
|
||||||
|
padding-top: 0;
|
||||||
|
}
|
||||||
|
.manage {
|
||||||
|
float: right;
|
||||||
}
|
}
|
||||||
@@ -54,15 +54,15 @@
|
|||||||
@foreach (var item in Model.Extensions) {
|
@foreach (var item in Model.Extensions) {
|
||||||
<li>
|
<li>
|
||||||
@{
|
@{
|
||||||
string extensionClass = "iconThumbnail";
|
string extensionClass = "iconThumbnail";
|
||||||
string iconUrl = @item.IconUrl;
|
string iconUrl = @item.IconUrl;
|
||||||
if (!string.IsNullOrWhiteSpace(@item.FirstScreenshot)) {
|
if (!string.IsNullOrWhiteSpace(@item.FirstScreenshot)) {
|
||||||
iconUrl = @item.FirstScreenshot;
|
iconUrl = @item.FirstScreenshot;
|
||||||
extensionClass = "screenshotThumbnail";
|
extensionClass = "screenshotThumbnail";
|
||||||
} else if (string.IsNullOrWhiteSpace(iconUrl)) {
|
} else if (string.IsNullOrWhiteSpace(iconUrl)) {
|
||||||
iconUrl = Href("../../Content/Images/imagePlaceholder.png");
|
iconUrl = Href("../../Content/Images/imagePlaceholder.png");
|
||||||
extensionClass = "screenshotThumbnail";
|
extensionClass = "screenshotThumbnail";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
<div class="@extensionClass">
|
<div class="@extensionClass">
|
||||||
@@ -107,6 +107,8 @@
|
|||||||
</div>
|
</div>
|
||||||
</li>}
|
</li>}
|
||||||
</ul>
|
</ul>
|
||||||
|
} else {
|
||||||
|
<p>@T("No themes available.").ToString()</p>
|
||||||
}
|
}
|
||||||
|
|
||||||
@Display(Model.Pager)
|
@Display(Model.Pager)
|
||||||
|
|||||||
Reference in New Issue
Block a user