mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +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.Web.Mvc;
|
||||
using Orchard.Data.Migration;
|
||||
using Orchard.DisplayManagement;
|
||||
using Orchard.Environment.Descriptor.Models;
|
||||
using Orchard.Environment.Extensions;
|
||||
using Orchard.Environment.Extensions.Models;
|
||||
@@ -15,6 +16,7 @@ using Orchard.Modules.Services;
|
||||
using Orchard.Modules.ViewModels;
|
||||
using Orchard.Reports.Services;
|
||||
using Orchard.Security;
|
||||
using Orchard.UI.Navigation;
|
||||
using Orchard.UI.Notify;
|
||||
using Orchard.Utility.Extensions;
|
||||
|
||||
@@ -36,7 +38,8 @@ namespace Orchard.Modules.Controllers {
|
||||
IReportsCoordinator reportsCoordinator,
|
||||
IExtensionManager extensionManager,
|
||||
IFeatureManager featureManager,
|
||||
ShellDescriptor shellDescriptor)
|
||||
ShellDescriptor shellDescriptor,
|
||||
IShapeFactory shapeFactory)
|
||||
{
|
||||
Services = services;
|
||||
_extensionDisplayEventHandler = extensionDisplayEventHandlers.FirstOrDefault();
|
||||
@@ -46,6 +49,7 @@ namespace Orchard.Modules.Controllers {
|
||||
_extensionManager = extensionManager;
|
||||
_featureManager = featureManager;
|
||||
_shellDescriptor = shellDescriptor;
|
||||
Shape = shapeFactory;
|
||||
|
||||
T = NullLocalizer.Instance;
|
||||
Logger = NullLogger.Instance;
|
||||
@@ -54,13 +58,18 @@ namespace Orchard.Modules.Controllers {
|
||||
public Localizer T { get; set; }
|
||||
public IOrchardServices Services { 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")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
Pager pager = new Pager(Services.WorkContext.CurrentSite, pagerParameters);
|
||||
|
||||
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 => {
|
||||
ModuleEntry moduleEntry = new ModuleEntry {
|
||||
Descriptor = extensionDescriptor,
|
||||
@@ -76,9 +85,17 @@ namespace Orchard.Modules.Controllers {
|
||||
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,
|
||||
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 bool InstallModules { 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");
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
@if (Model.InstallModules) {
|
||||
<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>
|
||||
}
|
||||
@using (Html.BeginFormAntiForgeryPost(Url.Action("Index", "Admin"))) {
|
||||
<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) {
|
||||
<ul class="contentItems">
|
||||
@foreach (ModuleEntry module in Model.Modules.OrderBy(m => m.Descriptor.Name)) {
|
||||
<li>@Display.ModuleEntry(ContentPart: module)</li>
|
||||
<fieldset class="search-actions">
|
||||
<input type="text" id="searchText" name="@Html.NameOf(m => m.Options.SearchText)" value="@Model.Options.SearchText" />
|
||||
|
||||
<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 {
|
||||
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) {
|
||||
<li>
|
||||
@{
|
||||
string extensionClass = "iconThumbnail";
|
||||
string iconUrl = @item.IconUrl;
|
||||
if (!string.IsNullOrWhiteSpace(@item.FirstScreenshot)) {
|
||||
iconUrl = @item.FirstScreenshot;
|
||||
extensionClass = "screenshotThumbnail";
|
||||
} else if (string.IsNullOrWhiteSpace(iconUrl)) {
|
||||
iconUrl = Href("../../Content/Images/imagePlaceholder.png");
|
||||
extensionClass = "screenshotThumbnail";
|
||||
}
|
||||
string extensionClass = "iconThumbnail";
|
||||
string iconUrl = @item.IconUrl;
|
||||
if (!string.IsNullOrWhiteSpace(@item.FirstScreenshot)) {
|
||||
iconUrl = @item.FirstScreenshot;
|
||||
extensionClass = "screenshotThumbnail";
|
||||
} else if (string.IsNullOrWhiteSpace(iconUrl)) {
|
||||
iconUrl = Href("../../Content/Images/imagePlaceholder.png");
|
||||
extensionClass = "screenshotThumbnail";
|
||||
}
|
||||
}
|
||||
|
||||
<div class="@extensionClass">
|
||||
@@ -107,6 +107,8 @@
|
||||
</div>
|
||||
</li>}
|
||||
</ul>
|
||||
} else {
|
||||
<p>@T("No themes available.").ToString()</p>
|
||||
}
|
||||
|
||||
@Display(Model.Pager)
|
||||
|
Reference in New Issue
Block a user