mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Made blog and page menu dynamic to hide the manage links when there are no items yet
--HG-- branch : dev
This commit is contained in:
@@ -18,13 +18,14 @@ namespace Orchard.Blogs {
|
||||
|
||||
private void BuildMenu(NavigationItemBuilder menu) {
|
||||
var blogs = _blogService.Get();
|
||||
var singleBlog = blogs.Count() == 1 ? blogs.ElementAt(0) : null;
|
||||
var blogCount = blogs.Count();
|
||||
var singleBlog = blogCount == 1 ? blogs.ElementAt(0) : null;
|
||||
|
||||
if (singleBlog == null)
|
||||
if (blogCount > 0 && singleBlog == null)
|
||||
menu.Add("Manage Blogs", "1.0",
|
||||
item =>
|
||||
item.Action("List", "BlogAdmin", new {area = "Orchard.Blogs"}).Permission(Permissions.MetaListBlogs));
|
||||
else
|
||||
else if (singleBlog != null)
|
||||
menu.Add("Manage Blog", "1.0",
|
||||
item =>
|
||||
item.Action("Item", "BlogAdmin", new {area = "Orchard.Blogs", blogSlug = singleBlog.Slug}).Permission(Permissions.MetaListBlogs));
|
||||
|
@@ -1,14 +1,29 @@
|
||||
using Orchard.UI.Navigation;
|
||||
using Orchard.Pages.Services;
|
||||
using Orchard.UI.Navigation;
|
||||
|
||||
namespace Orchard.Pages {
|
||||
public class AdminMenu : INavigationProvider {
|
||||
private readonly IPageService _pageService;
|
||||
|
||||
public AdminMenu(IPageService pageService) {
|
||||
_pageService = pageService;
|
||||
}
|
||||
|
||||
public string MenuName { get { return "admin"; } }
|
||||
|
||||
public void GetNavigation(NavigationBuilder builder) {
|
||||
builder.Add("Pages", "1",
|
||||
menu => menu
|
||||
.Add("Manage Pages", "1.0", item => item.Action("List", "Admin", new { area = "Orchard.Pages" }).Permission(Permissions.MetaListPages))
|
||||
.Add("Add New Page", "1.1", item => item.Action("Create", "Admin", new { area = "Orchard.Pages" }).Permission(Permissions.EditPages)));
|
||||
builder.Add("Pages", "1", BuildMenu);
|
||||
}
|
||||
|
||||
private void BuildMenu(NavigationItemBuilder menu) {
|
||||
if (_pageService.GetCount() > 0)
|
||||
menu.Add("Manage Pages", "1.0",
|
||||
item =>
|
||||
item.Action("List", "Admin", new {area = "Orchard.Pages"}).Permission(Permissions.MetaListPages));
|
||||
|
||||
menu.Add("Add New Page", "1.1",
|
||||
item =>
|
||||
item.Action("Create", "Admin", new {area = "Orchard.Pages"}).Permission(Permissions.EditPages));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -4,6 +4,7 @@ using Orchard.Pages.Models;
|
||||
|
||||
namespace Orchard.Pages.Services {
|
||||
public interface IPageService : IDependency {
|
||||
int GetCount();
|
||||
IEnumerable<Page> Get();
|
||||
IEnumerable<Page> Get(PageStatus status);
|
||||
Page Get(string slug);
|
||||
|
@@ -23,6 +23,11 @@ namespace Orchard.Pages.Services {
|
||||
_slugConstraint = slugConstraint;
|
||||
}
|
||||
|
||||
public int GetCount() {
|
||||
//TODO: (erikpo) Need to add a count method to IContentQuery so it doesn't need to pull out all pages to get a count
|
||||
return _contentManager.Query<Page>(VersionOptions.Latest).List().Count();
|
||||
}
|
||||
|
||||
public IEnumerable<Page> Get() {
|
||||
return Get(PageStatus.All);
|
||||
}
|
||||
|
Reference in New Issue
Block a user