mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-22 20:13:50 +08:00
- Pages: Filtering and bulk actions (delete/publish etc)...
--HG-- extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4045156
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Web.Mvc;
|
||||
using Orchard.Data;
|
||||
using Orchard.Localization;
|
||||
@@ -32,15 +34,71 @@ namespace Orchard.Pages.Controllers {
|
||||
public IOrchardServices Services { get; set; }
|
||||
private Localizer T { get; set; }
|
||||
|
||||
public ActionResult List() {
|
||||
IEnumerable<Page> pages = _pageService.Get();
|
||||
var model = new PagesViewModel {
|
||||
Pages = pages
|
||||
};
|
||||
public ActionResult List(PagesOptions options) {
|
||||
// Default options
|
||||
if (options == null)
|
||||
options = new PagesOptions();
|
||||
|
||||
IEnumerable<Page> pages;
|
||||
// Filtering
|
||||
switch (options.Filter) {
|
||||
case PagesFilter.All:
|
||||
pages = _pageService.Get();
|
||||
break;
|
||||
case PagesFilter.Published:
|
||||
pages = _pageService.Get(PageStatus.Published);
|
||||
break;
|
||||
case PagesFilter.Offline:
|
||||
pages = _pageService.Get(PageStatus.Offline);
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
var entries = pages.Select(page => CreatePageEntry(page)).ToList();
|
||||
var model = new PagesViewModel { Options = options, PageEntries = entries };
|
||||
return View(model);
|
||||
}
|
||||
|
||||
[HttpPost, ActionName("List")]
|
||||
[FormValueRequired("submit.BulkEdit")]
|
||||
public ActionResult ListPOST(PagesOptions options, IList<PageEntry> pageEntries) {
|
||||
IEnumerable<PageEntry> checkedEntries = pageEntries.Where(p => p.IsChecked);
|
||||
switch (options.BulkAction) {
|
||||
case PagesBulkAction.None:
|
||||
break;
|
||||
case PagesBulkAction.PublishNow:
|
||||
if (!Services.Authorizer.Authorize(Permissions.PublishPages, T("Couldn't publish page")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
foreach (PageEntry entry in checkedEntries) {
|
||||
var page = _pageService.GetLatest(entry.PageId);
|
||||
_pageService.Publish(page);
|
||||
}
|
||||
break;
|
||||
case PagesBulkAction.Delete:
|
||||
if (!Services.Authorizer.Authorize(Permissions.DeletePages, T("Couldn't delete page")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
foreach (PageEntry entry in checkedEntries) {
|
||||
var page = _pageService.GetLatest(entry.PageId);
|
||||
_pageService.Delete(page);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
|
||||
return RedirectToAction("List");
|
||||
}
|
||||
|
||||
private static PageEntry CreatePageEntry(Page page) {
|
||||
return new PageEntry {
|
||||
Page = page,
|
||||
IsChecked = false,
|
||||
PageId = page.Id
|
||||
};
|
||||
}
|
||||
|
||||
public ActionResult Create() {
|
||||
if (!Services.Authorizer.Authorize(Permissions.CreatePages, T("Not allowed to create a page")))
|
||||
return new HttpUnauthorizedResult();
|
||||
@@ -149,5 +207,18 @@ namespace Orchard.Pages.Controllers {
|
||||
void IUpdateModel.AddModelError(string key, LocalizedString errorMessage) {
|
||||
ModelState.AddModelError(key, errorMessage.ToString());
|
||||
}
|
||||
|
||||
public class FormValueRequiredAttribute : ActionMethodSelectorAttribute {
|
||||
private readonly string _submitButtonName;
|
||||
|
||||
public FormValueRequiredAttribute(string submitButtonName) {
|
||||
_submitButtonName = submitButtonName;
|
||||
}
|
||||
|
||||
public override bool IsValidForRequest(ControllerContext controllerContext, MethodInfo methodInfo) {
|
||||
var value = controllerContext.HttpContext.Request.Form[_submitButtonName];
|
||||
return !string.IsNullOrEmpty(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -65,16 +65,7 @@ namespace Orchard.Pages.Models {
|
||||
set { Record.Published = value; }
|
||||
}
|
||||
|
||||
//public Page() {
|
||||
// Revisions = new List<PageRevision>();
|
||||
// Scheduled = new List<Scheduled>();
|
||||
//}
|
||||
//[CascadeAllDeleteOrphan]
|
||||
//public virtual IList<PageRevision> Revisions { get; protected set; }
|
||||
|
||||
//[CascadeAllDeleteOrphan]
|
||||
//public virtual IList<Scheduled> Scheduled { get; protected set; }
|
||||
|
||||
//public virtual Published Published { get; set; }
|
||||
}
|
||||
}
|
||||
|
@@ -4,11 +4,19 @@ using Orchard.Pages.Models;
|
||||
namespace Orchard.Pages.Services {
|
||||
public interface IPageService : IDependency {
|
||||
IEnumerable<Page> Get();
|
||||
IEnumerable<Page> Get(PageStatus status);
|
||||
Page Get(string slug);
|
||||
Page GetPageOrDraft(string slug);
|
||||
Page GetLatest(int id);
|
||||
Page New();
|
||||
Page Create(bool publishNow);
|
||||
void Delete(Page page);
|
||||
void Publish(Page page);
|
||||
}
|
||||
|
||||
public enum PageStatus {
|
||||
All,
|
||||
Published,
|
||||
Offline
|
||||
}
|
||||
}
|
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Orchard.Pages.Models;
|
||||
using Orchard.Core.Common.Records;
|
||||
@@ -13,7 +14,27 @@ namespace Orchard.Pages.Services {
|
||||
}
|
||||
|
||||
public IEnumerable<Page> Get() {
|
||||
return _contentManager.Query<Page, PageRecord>(VersionOptions.Latest).List();
|
||||
return Get(PageStatus.All);
|
||||
}
|
||||
|
||||
public IEnumerable<Page> Get(PageStatus status) {
|
||||
switch (status) {
|
||||
case PageStatus.All:
|
||||
return _contentManager.Query<Page, PageRecord>(VersionOptions.Latest).List();
|
||||
case PageStatus.Published:
|
||||
return _contentManager.Query<Page, PageRecord>(VersionOptions.Published).List();
|
||||
case PageStatus.Offline:
|
||||
IEnumerable<Page> allPages = _contentManager.Query<Page, PageRecord>(VersionOptions.Latest).List();
|
||||
List<Page> offlinePages = new List<Page>();
|
||||
foreach (var page in allPages) {
|
||||
if (page.ContentItem.VersionRecord.Published == false) {
|
||||
offlinePages.Add(page);
|
||||
}
|
||||
}
|
||||
return offlinePages;
|
||||
default:
|
||||
return new List<Page>();
|
||||
}
|
||||
}
|
||||
|
||||
public Page Get(string slug) {
|
||||
@@ -22,6 +43,10 @@ namespace Orchard.Pages.Services {
|
||||
.List().FirstOrDefault();
|
||||
}
|
||||
|
||||
public Page GetLatest(int id) {
|
||||
return _contentManager.Get<Page>(id, VersionOptions.Latest);
|
||||
}
|
||||
|
||||
public Page GetPageOrDraft(string slug) {
|
||||
Page page = _contentManager.Query<Page, PageRecord>(VersionOptions.Latest)
|
||||
.Join<RoutableRecord>().Where(rr => rr.Slug == slug)
|
||||
|
@@ -4,6 +4,30 @@ using Orchard.Pages.Models;
|
||||
|
||||
namespace Orchard.Pages.ViewModels {
|
||||
public class PagesViewModel : AdminViewModel {
|
||||
public IEnumerable<Page> Pages { get; set; }
|
||||
public IList<PageEntry> PageEntries { get; set; }
|
||||
public PagesOptions Options { get; set; }
|
||||
}
|
||||
|
||||
public class PageEntry {
|
||||
public Page Page { get; set; }
|
||||
public int PageId { get; set; }
|
||||
public bool IsChecked { get; set; }
|
||||
}
|
||||
|
||||
public class PagesOptions {
|
||||
public PagesFilter Filter { get; set; }
|
||||
public PagesBulkAction BulkAction { get; set; }
|
||||
}
|
||||
|
||||
public enum PagesFilter {
|
||||
All,
|
||||
Published,
|
||||
Offline
|
||||
}
|
||||
|
||||
public enum PagesBulkAction {
|
||||
None,
|
||||
PublishNow,
|
||||
Delete
|
||||
}
|
||||
}
|
@@ -7,6 +7,24 @@
|
||||
<p>Possible text about setting up a page goes here. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla erat turpis, blandit eget feugiat nec, tempus vel quam. Mauris et neque eget justo suscipit blandit.</p>
|
||||
<% using (Html.BeginFormAntiForgeryPost()) { %>
|
||||
<%=Html.ValidationSummary() %>
|
||||
<fieldset class="actions bulk">
|
||||
<label for="publishActions">Actions: </label>
|
||||
<select id="publishActions" name="<%=Html.NameOf(m => m.Options.BulkAction) %>">
|
||||
<%=Html.SelectOption(Model.Options.BulkAction, PagesBulkAction.None, "Choose action...") %>
|
||||
<%=Html.SelectOption(Model.Options.BulkAction, PagesBulkAction.PublishNow, "Publish Now") %>
|
||||
<%=Html.SelectOption(Model.Options.BulkAction, PagesBulkAction.Delete, "Delete") %>
|
||||
</select>
|
||||
<input class="button" type="submit" name="submit.BulkEdit" value="Apply" />
|
||||
</fieldset>
|
||||
<fieldset class="actions bulk">
|
||||
<label for="filterResults">Filter: </label>
|
||||
<select id="filterResults" name="<%=Html.NameOf(m => m.Options.Filter) %>">
|
||||
<%=Html.SelectOption(Model.Options.Filter, PagesFilter.All, "All Pages") %>
|
||||
<%=Html.SelectOption(Model.Options.Filter, PagesFilter.Published, "Published Pages") %>
|
||||
<%=Html.SelectOption(Model.Options.Filter, PagesFilter.Offline, "Offline Pages") %>
|
||||
</select>
|
||||
<input class="button" type="submit" name="submit.Filter" value="Apply"/>
|
||||
</fieldset>
|
||||
<div class="manage"><%=Html.ActionLink("Add a page", "Create", new {}, new { @class = "button" }) %></div>
|
||||
<fieldset>
|
||||
<table class="items" summary="This is a table of the PageEntries currently available for use in your application.">
|
||||
@@ -33,35 +51,41 @@
|
||||
<th scope="col"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<% foreach (var page in Model.Pages) { %>
|
||||
<%
|
||||
int pageIndex = 0;
|
||||
foreach (var pageEntry in Model.PageEntries) { %>
|
||||
<tr>
|
||||
<td>
|
||||
<input type="hidden" value="<%=Model.PageEntries[pageIndex].PageId %>" name="<%=Html.NameOf(m => m.PageEntries[pageIndex].PageId) %>"/>
|
||||
<input type="checkbox" value="true" name="<%=Html.NameOf(m => m.PageEntries[pageIndex].IsChecked) %>"/>
|
||||
</td>
|
||||
<td>
|
||||
<% if (page.HasPublished) {%>
|
||||
<% if (pageEntry.Page.HasPublished) {%>
|
||||
<img src="<%=ResolveUrl("~/Packages/Orchard.Pages/Content/Admin/images/online.gif")%>" alt="Online" title="The page is currently online" />
|
||||
<% } else { %>
|
||||
<img src="<%=ResolveUrl("~/Packages/Orchard.Pages/Content/Admin/images/offline.gif")%>" alt="Offline" title="The page is currently offline" />
|
||||
<% } %>
|
||||
</td>
|
||||
<td><%=page.Title ?? "(no title)" %></td>
|
||||
<td><% if (page.HasPublished) {%>
|
||||
<%=Html.ActionLink(page.Slug ?? "(no slug)", "Item", new {controller = "Page", slug = page.PublishedSlug})%>
|
||||
<td><%=pageEntry.Page.Title ?? "(no title)" %></td>
|
||||
<td><% if (pageEntry.Page.HasPublished) {%>
|
||||
<%=Html.ActionLink(pageEntry.Page.Slug ?? "(no slug)", "Item", new {controller = "Page", slug = pageEntry.Page.PublishedSlug})%>
|
||||
<% } else {%>
|
||||
<%= page.Slug ?? "(no slug)" %>
|
||||
<%= pageEntry.Page.Slug ?? "(no slug)" %>
|
||||
<% } %>
|
||||
</td>
|
||||
<td>By <%= page.Creator.UserName %></td>
|
||||
<td>By <%= pageEntry.Page.Creator.UserName %></td>
|
||||
<td></td>
|
||||
<td>
|
||||
<% if (page.HasDraft) { %>
|
||||
<% if (pageEntry.Page.HasDraft) { %>
|
||||
<img src="<%=ResolveUrl("~/Packages/Orchard.Pages/Content/Admin/images/draft.gif") %>" alt="Draft" title="The page has a draft" />
|
||||
<% } %>
|
||||
</td>
|
||||
<td></td>
|
||||
<td><%=Html.ActionLink("Edit", "Edit", new { pageSlug = page.Slug }) %></td>
|
||||
<td><%=Html.ActionLink("Edit", "Edit", new { pageSlug = pageEntry.Page.Slug }) %></td>
|
||||
</tr>
|
||||
<% }%>
|
||||
<%
|
||||
pageIndex++;
|
||||
} %>
|
||||
</table>
|
||||
</fieldset>
|
||||
<div class="manage"><%=Html.ActionLink("Add a page", "Create", new {}, new { @class = "button"}) %></div>
|
||||
|
Reference in New Issue
Block a user