mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Adding tabs to Alias admin UI for Managed/Unmanaged aliases.
This commit is contained in:
@@ -3,6 +3,7 @@ using Orchard.Localization;
|
||||
using Orchard.Security;
|
||||
using Orchard.UI.Navigation;
|
||||
|
||||
|
||||
namespace Orchard.Alias {
|
||||
[OrchardFeature("Orchard.Alias.UI")]
|
||||
public class AdminMenu : INavigationProvider {
|
||||
@@ -11,8 +12,13 @@ namespace Orchard.Alias {
|
||||
public string MenuName { get { return "admin"; } }
|
||||
|
||||
public void GetNavigation(NavigationBuilder builder) {
|
||||
builder
|
||||
.Add(T("Aliases"), "4", item => item.Action("Index", "Admin", new { area = "Orchard.Alias" }).Permission(StandardPermissions.SiteOwner));
|
||||
builder.AddImageSet("aliases");
|
||||
builder.Add(T("Aliases"), "1.4.1", menu => {
|
||||
menu.LinkToFirstChild(true);
|
||||
|
||||
menu.Add(T("Unmanaged"), "1", item => item.Action("IndexUnmanaged", "Admin", new { area = "Orchard.Alias" }).Permission(StandardPermissions.SiteOwner).LocalNav());
|
||||
menu.Add(T("Managed"), "2", item => item.Action("IndexManaged", "Admin", new { area = "Orchard.Alias" }).Permission(StandardPermissions.SiteOwner).LocalNav());
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@@ -35,7 +35,7 @@ namespace Orchard.Alias.Controllers {
|
||||
public Localizer T { get; set; }
|
||||
public ILogger Logger { get; set; }
|
||||
|
||||
public ActionResult Index(AdminIndexOptions options, PagerParameters pagerParameters) {
|
||||
public ActionResult IndexUnmanaged(AdminIndexOptions options, PagerParameters pagerParameters) {
|
||||
if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to manage aliases")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
@@ -46,7 +46,7 @@ namespace Orchard.Alias.Controllers {
|
||||
options = new AdminIndexOptions();
|
||||
|
||||
|
||||
var aliases = _aliasHolder.GetMaps().SelectMany(x => x.GetAliases());
|
||||
var aliases = _aliasHolder.GetMaps().SelectMany(x => x.GetAliases()).Where(x => !x.IsManaged);
|
||||
|
||||
if (!String.IsNullOrWhiteSpace(options.Search)) {
|
||||
var invariantSearch = options.Search.ToLowerInvariant();
|
||||
@@ -54,19 +54,6 @@ namespace Orchard.Alias.Controllers {
|
||||
}
|
||||
|
||||
aliases = aliases.ToList();
|
||||
|
||||
switch (options.Filter) {
|
||||
case AliasFilter.Managed:
|
||||
aliases = aliases.Where(x => x.IsManaged);
|
||||
break;
|
||||
case AliasFilter.Unmanaged:
|
||||
aliases = aliases.Where(x => !x.IsManaged);
|
||||
break;
|
||||
case AliasFilter.All:
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
var pagerShape = Services.New.Pager(pager).TotalItemCount(aliases.Count());
|
||||
|
||||
switch (options.Order) {
|
||||
@@ -82,7 +69,7 @@ namespace Orchard.Alias.Controllers {
|
||||
var model = new AdminIndexViewModel {
|
||||
Options = options,
|
||||
Pager = pagerShape,
|
||||
AliasEntries = aliases.Select(x => new AliasEntry() { Alias = x, IsChecked = false }).OrderBy(x => x.Alias.IsManaged).ToList()
|
||||
AliasEntries = aliases.Select(x => new AliasEntry() { Alias = x, IsChecked = false }).ToList()
|
||||
};
|
||||
|
||||
return View(model);
|
||||
@@ -90,7 +77,7 @@ namespace Orchard.Alias.Controllers {
|
||||
|
||||
[HttpPost]
|
||||
[FormValueRequired("submit.BulkEdit")]
|
||||
public ActionResult Index(FormCollection input) {
|
||||
public ActionResult IndexUnmanaged(FormCollection input) {
|
||||
if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to manage aliases")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
@@ -111,7 +98,48 @@ namespace Orchard.Alias.Controllers {
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
return RedirectToAction("Index");
|
||||
return RedirectToAction("IndexUnmanaged");
|
||||
}
|
||||
|
||||
public ActionResult IndexManaged(AdminIndexOptions options, PagerParameters pagerParameters) {
|
||||
if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to manage aliases")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
var pager = new Pager(Services.WorkContext.CurrentSite, pagerParameters);
|
||||
|
||||
// default options
|
||||
if (options == null)
|
||||
options = new AdminIndexOptions();
|
||||
|
||||
|
||||
var aliases = _aliasHolder.GetMaps().SelectMany(x => x.GetAliases()).Where(x => x.IsManaged);
|
||||
|
||||
if (!String.IsNullOrWhiteSpace(options.Search)) {
|
||||
var invariantSearch = options.Search.ToLowerInvariant();
|
||||
aliases = aliases.Where(x => x.Path.ToLowerInvariant().Contains(invariantSearch));
|
||||
}
|
||||
|
||||
aliases = aliases.ToList();
|
||||
|
||||
var pagerShape = Services.New.Pager(pager).TotalItemCount(aliases.Count());
|
||||
|
||||
switch (options.Order) {
|
||||
case AliasOrder.Path:
|
||||
aliases = aliases.OrderBy(x => x.Path);
|
||||
break;
|
||||
}
|
||||
|
||||
if (pager.PageSize != 0) {
|
||||
aliases = aliases.Skip(pager.GetStartIndex()).Take(pager.PageSize);
|
||||
}
|
||||
|
||||
var model = new AdminIndexViewModel {
|
||||
Options = options,
|
||||
Pager = pagerShape,
|
||||
AliasEntries = aliases.Select(x => new AliasEntry() { Alias = x, IsChecked = false }).ToList()
|
||||
};
|
||||
|
||||
return View(model);
|
||||
}
|
||||
|
||||
public ActionResult Add() {
|
||||
@@ -160,7 +188,7 @@ namespace Orchard.Alias.Controllers {
|
||||
|
||||
Services.Notifier.Information(T("Alias {0} created", aliasPath));
|
||||
|
||||
return RedirectToAction("Index");
|
||||
return RedirectToAction("IndexUnmanaged");
|
||||
}
|
||||
|
||||
public ActionResult Edit(string path) {
|
||||
@@ -230,7 +258,7 @@ namespace Orchard.Alias.Controllers {
|
||||
|
||||
Services.Notifier.Information(T("Alias {0} updated", path));
|
||||
|
||||
return RedirectToAction("Index");
|
||||
return RedirectToAction("IndexUnmanaged");
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
@@ -246,7 +274,7 @@ namespace Orchard.Alias.Controllers {
|
||||
|
||||
Services.Notifier.Information(T("Alias {0} deleted", path));
|
||||
|
||||
return this.RedirectLocal(returnUrl, Url.Action("Index"));
|
||||
return this.RedirectLocal(returnUrl, Url.Action("IndexUnmanaged"));
|
||||
}
|
||||
|
||||
private string GetExistingPathForAlias(string aliasPath) {
|
||||
|
@@ -75,7 +75,7 @@
|
||||
<Content Include="Views\Admin\Add.cshtml" />
|
||||
<Content Include="Views\Admin\Delete.cshtml" />
|
||||
<Content Include="Views\Admin\Edit.cshtml" />
|
||||
<Content Include="Views\Admin\Index.cshtml" />
|
||||
<Content Include="Views\Admin\IndexUnmanaged.cshtml" />
|
||||
<Content Include="Web.config" />
|
||||
<Compile Include="Implementation\Updater\AliasHolderUpdater.cs" />
|
||||
<Compile Include="Implementation\Updater\AliasUpdateCursor.cs" />
|
||||
@@ -117,7 +117,9 @@
|
||||
<Compile Include="Routes.cs" />
|
||||
<Compile Include="ViewModels\AdminIndexViewModel.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<ItemGroup>
|
||||
<Content Include="Views\Admin\IndexManaged.cshtml" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
|
||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||
|
@@ -0,0 +1,74 @@
|
||||
@model AdminIndexViewModel
|
||||
|
||||
@using Orchard.Alias
|
||||
@using Orchard.Alias.ViewModels
|
||||
@using Orchard.Environment.Configuration
|
||||
@using Orchard.Utility.Extensions
|
||||
|
||||
@{
|
||||
var urlPrefix = WorkContext.Resolve<ShellSettings>().RequestUrlPrefix;
|
||||
|
||||
Layout.Title = T("Manage Aliases").Text;
|
||||
var aliasService = WorkContext.Resolve<IAliasService>();
|
||||
AdminIndexOptions options = Model.Options;
|
||||
int index = -1;
|
||||
|
||||
var pageSizes = new List<int?>() { 10, 50, 100 };
|
||||
var defaultPageSize = WorkContext.CurrentSite.PageSize;
|
||||
if (!pageSizes.Contains(defaultPageSize)) {
|
||||
pageSizes.Add(defaultPageSize);
|
||||
}
|
||||
}
|
||||
|
||||
@using (Html.BeginFormAntiForgeryPost()) {
|
||||
@Html.ValidationSummary()
|
||||
|
||||
<fieldset class="bulk-actions">
|
||||
<label for="filterResults">@T("Sort by:")</label>
|
||||
<select id="filterResults" name="@Html.NameOf(m => m.Options.Order)">
|
||||
@Html.SelectOption(options.Order, AliasOrder.Path, T("Path").ToString())
|
||||
</select>
|
||||
<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" name="submit.Filter" value="@T("Filter")">@T("Filter")</button>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<table class="items">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">@T("Alias")</th>
|
||||
<th scope="col">@T("Route")</th>
|
||||
<th scope="col"> </th>
|
||||
</tr>
|
||||
</thead>
|
||||
@foreach (var aliasEntry in Model.AliasEntries) {
|
||||
var alias = aliasEntry.Alias;
|
||||
index++;
|
||||
var virtualPathData = aliasService.LookupVirtualPaths(alias.RouteValues.ToRouteValueDictionary(), ViewContext.HttpContext).FirstOrDefault();
|
||||
|
||||
if (virtualPathData == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
var url = virtualPathData.VirtualPath;
|
||||
<tr>
|
||||
<td>
|
||||
<input type="hidden" value="@alias.Path" name="@Html.FieldNameFor(m => Model.AliasEntries[index].Alias.Path)" />
|
||||
@Html.Link(alias.Path == String.Empty ? "/" : alias.Path, Href("~/" + urlPrefix + alias.Path))
|
||||
</td>
|
||||
<td>
|
||||
@Html.Link(url, Href("~/" + urlPrefix + "/" + url))
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</table>
|
||||
|
||||
@Display(Model.Pager)
|
||||
</fieldset>
|
||||
}
|
@@ -1,106 +1,91 @@
|
||||
@model AdminIndexViewModel
|
||||
|
||||
@using Orchard.Alias
|
||||
@using Orchard.Alias.ViewModels
|
||||
@using Orchard.Environment.Configuration
|
||||
@using Orchard.Utility.Extensions
|
||||
|
||||
@{
|
||||
var urlPrefix = WorkContext.Resolve<ShellSettings>().RequestUrlPrefix;
|
||||
|
||||
Layout.Title = T("Manage Aliases").Text;
|
||||
var aliasService = WorkContext.Resolve<IAliasService>();
|
||||
AdminIndexOptions options = Model.Options;
|
||||
int index = -1;
|
||||
|
||||
var pageSizes = new List<int?>() { 10, 50, 100 };
|
||||
var defaultPageSize = WorkContext.CurrentSite.PageSize;
|
||||
if (!pageSizes.Contains(defaultPageSize)) {
|
||||
pageSizes.Add(defaultPageSize);
|
||||
}
|
||||
}
|
||||
|
||||
@using (Html.BeginFormAntiForgeryPost()) {
|
||||
@Html.ValidationSummary()
|
||||
<div class="manage">@Html.ActionLink(T("Add new Alias").Text, "Add", new { returnurl = HttpContext.Current.Request.RawUrl }, new { @class = "button primaryAction" })</div>
|
||||
|
||||
<fieldset class="bulk-actions">
|
||||
<label for="publishActions">@T("Actions:")</label>
|
||||
<select id="publishActions" name="@Html.NameOf(m => m.Options.BulkAction)">
|
||||
@Html.SelectOption(options.BulkAction, AliasBulkAction.None, T("Choose action...").ToString())
|
||||
@Html.SelectOption(options.BulkAction, AliasBulkAction.Delete, T("Delete").ToString())
|
||||
</select>
|
||||
<button type="submit" name="submit.BulkEdit" value="@T("Apply")">@T("Apply")</button>
|
||||
</fieldset>
|
||||
<fieldset class="bulk-actions">
|
||||
<label for="filterResults">@T("Sort by:")</label>
|
||||
<select id="filterResults" name="@Html.NameOf(m => m.Options.Order)">
|
||||
@Html.SelectOption(options.Order, AliasOrder.Path, T("Path").ToString())
|
||||
</select>
|
||||
<label for="filterResults">@T("Filter:")</label>
|
||||
<select id="filterResults" name="@Html.NameOf(m => m.Options.Filter)">
|
||||
@Html.SelectOption(Model.Options.Filter, AliasFilter.All, T("All").ToString())
|
||||
@Html.SelectOption(Model.Options.Filter, AliasFilter.Managed, T("Managed").ToString())
|
||||
@Html.SelectOption(Model.Options.Filter, AliasFilter.Unmanaged, T("Unmanaged").ToString())
|
||||
</select>
|
||||
<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" name="submit.Filter" value="@T("Filter")">@T("Filter")</button>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<table class="items">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col" class="checkbox"><input type="checkbox" class="check-all" /></th>
|
||||
<th scope="col">@T("Alias")</th>
|
||||
<th scope="col">@T("Route")</th>
|
||||
<th scope="col">@T("Managed")</th>
|
||||
<th scope="col"> </th>
|
||||
</tr>
|
||||
</thead>
|
||||
@foreach (var aliasEntry in Model.AliasEntries) {
|
||||
var alias = aliasEntry.Alias;
|
||||
index++;
|
||||
var virtualPathData = aliasService.LookupVirtualPaths(alias.RouteValues.ToRouteValueDictionary(), ViewContext.HttpContext).FirstOrDefault();
|
||||
|
||||
if (virtualPathData == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
var url = virtualPathData.VirtualPath;
|
||||
<tr>
|
||||
<td>
|
||||
<input type="hidden" value="@alias.Path" name="@Html.FieldNameFor(m => Model.AliasEntries[index].Alias.Path)" />
|
||||
@if (!alias.IsManaged) {
|
||||
<input type="checkbox" value="true" name="@Html.FieldNameFor(m => Model.AliasEntries[index].IsChecked)" />
|
||||
}
|
||||
</td>
|
||||
<td>
|
||||
@Html.Link(alias.Path == String.Empty ? "/" : alias.Path, Href("~/" + urlPrefix + alias.Path))
|
||||
</td>
|
||||
<td>
|
||||
@Html.Link(url, Href("~/" + urlPrefix + "/" + url))
|
||||
</td>
|
||||
<td>
|
||||
<input type="checkbox" checked="@alias.IsManaged" value="true" name="@Html.FieldNameFor(m => Model.AliasEntries[index].Alias.IsManaged)" disabled="disabled" />
|
||||
</td>
|
||||
<td>
|
||||
@if (!alias.IsManaged) {
|
||||
@Html.ActionLink(T("Edit").Text, "Edit", new { path = alias.Path == String.Empty ? "/" : alias.Path })
|
||||
<text>|</text>
|
||||
@Html.ActionLink(T("Delete").Text, "Delete", new { path = alias.Path }, new { itemprop = "UnsafeUrl RemoveUrl" })
|
||||
}
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</table>
|
||||
|
||||
@Display(Model.Pager)
|
||||
</fieldset>
|
||||
@model AdminIndexViewModel
|
||||
|
||||
@using Orchard.Alias
|
||||
@using Orchard.Alias.ViewModels
|
||||
@using Orchard.Environment.Configuration
|
||||
@using Orchard.Utility.Extensions
|
||||
|
||||
@{
|
||||
var urlPrefix = WorkContext.Resolve<ShellSettings>().RequestUrlPrefix;
|
||||
|
||||
Layout.Title = T("Manage Aliases").Text;
|
||||
var aliasService = WorkContext.Resolve<IAliasService>();
|
||||
AdminIndexOptions options = Model.Options;
|
||||
int index = -1;
|
||||
|
||||
var pageSizes = new List<int?>() { 10, 50, 100 };
|
||||
var defaultPageSize = WorkContext.CurrentSite.PageSize;
|
||||
if (!pageSizes.Contains(defaultPageSize)) {
|
||||
pageSizes.Add(defaultPageSize);
|
||||
}
|
||||
}
|
||||
|
||||
@using (Html.BeginFormAntiForgeryPost()) {
|
||||
@Html.ValidationSummary()
|
||||
<div class="manage">@Html.ActionLink(T("Add new Alias").Text, "Add", new { returnurl = HttpContext.Current.Request.RawUrl }, new { @class = "button primaryAction" })</div>
|
||||
|
||||
<fieldset class="bulk-actions">
|
||||
<label for="publishActions">@T("Actions:")</label>
|
||||
<select id="publishActions" name="@Html.NameOf(m => m.Options.BulkAction)">
|
||||
@Html.SelectOption(options.BulkAction, AliasBulkAction.None, T("Choose action...").ToString())
|
||||
@Html.SelectOption(options.BulkAction, AliasBulkAction.Delete, T("Delete").ToString())
|
||||
</select>
|
||||
<button type="submit" name="submit.BulkEdit" value="@T("Apply")">@T("Apply")</button>
|
||||
</fieldset>
|
||||
<fieldset class="bulk-actions">
|
||||
<label for="filterResults">@T("Sort by:")</label>
|
||||
<select id="filterResults" name="@Html.NameOf(m => m.Options.Order)">
|
||||
@Html.SelectOption(options.Order, AliasOrder.Path, T("Path").ToString())
|
||||
</select>
|
||||
<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" name="submit.Filter" value="@T("Filter")">@T("Filter")</button>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<table class="items">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col" class="checkbox"><input type="checkbox" class="check-all" /></th>
|
||||
<th scope="col">@T("Alias")</th>
|
||||
<th scope="col">@T("Route")</th>
|
||||
<th scope="col"> </th>
|
||||
</tr>
|
||||
</thead>
|
||||
@foreach (var aliasEntry in Model.AliasEntries) {
|
||||
var alias = aliasEntry.Alias;
|
||||
index++;
|
||||
var virtualPathData = aliasService.LookupVirtualPaths(alias.RouteValues.ToRouteValueDictionary(), ViewContext.HttpContext).FirstOrDefault();
|
||||
|
||||
if (virtualPathData == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
var url = virtualPathData.VirtualPath;
|
||||
<tr>
|
||||
<td>
|
||||
<input type="hidden" value="@alias.Path" name="@Html.FieldNameFor(m => Model.AliasEntries[index].Alias.Path)" />
|
||||
<input type="checkbox" value="true" name="@Html.FieldNameFor(m => Model.AliasEntries[index].IsChecked)" />
|
||||
</td>
|
||||
<td>
|
||||
@Html.Link(alias.Path == String.Empty ? "/" : alias.Path, Href("~/" + urlPrefix + alias.Path))
|
||||
</td>
|
||||
<td>
|
||||
@Html.Link(url, Href("~/" + urlPrefix + "/" + url))
|
||||
</td>
|
||||
<td>
|
||||
@Html.ActionLink(T("Edit").Text, "Edit", new { path = alias.Path == String.Empty ? "/" : alias.Path })
|
||||
@Html.ActionLink(T("Delete").Text, "Delete", new { path = alias.Path }, new { itemprop = "UnsafeUrl RemoveUrl" })
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</table>
|
||||
|
||||
@Display(Model.Pager)
|
||||
</fieldset>
|
||||
}
|
Reference in New Issue
Block a user