From ffe345bfe07fee4d531bb7349ba805387933a7e2 Mon Sep 17 00:00:00 2001 From: Sipke Schoorstra Date: Mon, 11 Mar 2013 19:30:42 +0100 Subject: [PATCH] #19094: Moving "Content Types" and "Content Parts" tabs from "Content" into a new admin menu which has two tabs: Content Types and Content Parts. Work Item: 19094 --HG-- branch : 1.x extra : rebase_source : 7ac0edb9f01094222e52b82f5f8eda9f3f6d926a --- .../Modules/Orchard.ContentTypes/AdminMenu.cs | 13 ++++--- .../Orchard.ContentTypes.csproj | 5 +++ .../Services/DefaultStereotypesProvider.cs | 18 +++++++++ .../Services/IStereotypesProvider.cs | 12 ++++++ .../Services/StereotypeService.cs | 36 ++++++++++++++++++ .../Styles/Images/menu.contenttypes.png | Bin 0 -> 1175 bytes .../Styles/menu.contenttypes-admin.css | 6 +++ .../Styles/orchard-contenttypes-admin.css | 10 ++++- .../DisplayTemplates/EditTypeViewModel.cshtml | 7 +++- 9 files changed, 99 insertions(+), 8 deletions(-) create mode 100644 src/Orchard.Web/Modules/Orchard.ContentTypes/Services/DefaultStereotypesProvider.cs create mode 100644 src/Orchard.Web/Modules/Orchard.ContentTypes/Services/IStereotypesProvider.cs create mode 100644 src/Orchard.Web/Modules/Orchard.ContentTypes/Services/StereotypeService.cs create mode 100644 src/Orchard.Web/Modules/Orchard.ContentTypes/Styles/Images/menu.contenttypes.png create mode 100644 src/Orchard.Web/Modules/Orchard.ContentTypes/Styles/menu.contenttypes-admin.css diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/AdminMenu.cs b/src/Orchard.Web/Modules/Orchard.ContentTypes/AdminMenu.cs index 2010cae4c..5616de8c9 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentTypes/AdminMenu.cs +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/AdminMenu.cs @@ -7,13 +7,14 @@ namespace Orchard.ContentTypes { public Localizer T { get; set; } public string MenuName { get { return "admin"; } } - public void GetNavigation(NavigationBuilder builder) - { - builder.Add(T("Content"), - menu => menu - .Add(T("Content Types"), "3", item => item.Action("Index", "Admin", new {area = "Orchard.ContentTypes"}).LocalNav()) - .Add(T("Content Parts"), "4", item => item.Action("ListParts", "Admin", new {area = "Orchard.ContentTypes"}).LocalNav())); + public void GetNavigation(NavigationBuilder builder) { + builder.AddImageSet("contenttypes"); + builder.Add(T("Content Schema"), "1.4.1", menu => { + menu.LinkToFirstChild(true); + menu.Add(T("Content Types"), "1", item => item.Action("Index", "Admin", new { area = "Orchard.ContentTypes" }).LocalNav()); + menu.Add(T("Content Parts"), "2", item => item.Action("ListParts", "Admin", new { area = "Orchard.ContentTypes" }).LocalNav()); + }); } } } \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/Orchard.ContentTypes.csproj b/src/Orchard.Web/Modules/Orchard.ContentTypes/Orchard.ContentTypes.csproj index aa7266286..cf517764d 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentTypes/Orchard.ContentTypes.csproj +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/Orchard.ContentTypes.csproj @@ -64,8 +64,11 @@ + + + @@ -93,7 +96,9 @@ + + diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/Services/DefaultStereotypesProvider.cs b/src/Orchard.Web/Modules/Orchard.ContentTypes/Services/DefaultStereotypesProvider.cs new file mode 100644 index 000000000..426043ba3 --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/Services/DefaultStereotypesProvider.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Orchard.ContentTypes.Services { + public class DefaultStereotypesProvider : IStereotypesProvider { + private readonly Lazy _contentDefinitionService; + public DefaultStereotypesProvider(Lazy contentDefinitionService) { + _contentDefinitionService = contentDefinitionService; + } + + public IEnumerable GetStereotypes() { + // Harvest all available stereotypes by finding out about the stereotype of all content types + var stereotypes = _contentDefinitionService.Value.GetTypes().Where(x => x.Settings.ContainsKey("Stereotype")).Select(x => x.Settings["Stereotype"]).Distinct(); + return stereotypes.Select(x => new StereotypeDescription {DisplayName = x, Stereotype = x}); + } + } +} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/Services/IStereotypesProvider.cs b/src/Orchard.Web/Modules/Orchard.ContentTypes/Services/IStereotypesProvider.cs new file mode 100644 index 000000000..f5e3db796 --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/Services/IStereotypesProvider.cs @@ -0,0 +1,12 @@ +using System.Collections.Generic; + +namespace Orchard.ContentTypes.Services { + public interface IStereotypesProvider : IDependency { + IEnumerable GetStereotypes(); + } + + public class StereotypeDescription { + public string Stereotype { get; set; } + public string DisplayName { get; set; } + } +} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/Services/StereotypeService.cs b/src/Orchard.Web/Modules/Orchard.ContentTypes/Services/StereotypeService.cs new file mode 100644 index 000000000..c00221328 --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/Services/StereotypeService.cs @@ -0,0 +1,36 @@ +using System.Collections.Generic; +using System.Linq; +using Orchard.Caching; +using Orchard.Services; + +namespace Orchard.ContentTypes.Services { + public interface IStereotypeService : IDependency { + IEnumerable GetStereotypes(); + } + + public class StereotypeService : IStereotypeService { + private readonly IEnumerable _providers; + private readonly ICacheManager _cacheManager; + private readonly ISignals _signals; + private readonly IClock _clock; + + public StereotypeService(IEnumerable providers, ICacheManager cacheManager, ISignals signals, IClock clock) { + _providers = providers; + _cacheManager = cacheManager; + _signals = signals; + _clock = clock; + } + + public IEnumerable GetStereotypes() { + return _cacheManager.Get("ContentType.Stereotypes", context => { + + // TODO: Implement a signal in ContentDefinitionManager that gets raised whenever a type definition is updated. + // For now, we'll just cache the stereotypes for 1 minute. + //context.Monitor(_signals.When("ContentType.Stereotypes")); + context.Monitor(_clock.WhenUtc(_clock.UtcNow.AddMinutes(1))); + return _providers.SelectMany(x => x.GetStereotypes()); + }); + + } + } +} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/Styles/Images/menu.contenttypes.png b/src/Orchard.Web/Modules/Orchard.ContentTypes/Styles/Images/menu.contenttypes.png new file mode 100644 index 0000000000000000000000000000000000000000..70b140395675da0da4264333e65edf895d8f0d99 GIT binary patch literal 1175 zcmeAS@N?(olHy`uVBq!ia0vp^0zhoQ!3HEH;(vt$DajJoh?3y^w370~qErUQl>DSr z1<%~X^wgl##FWaylc_cg49rTIArU1JzCKpT`MG+DAT@dwxdlMo3=B5*6$OdO*{LN8 zNvY|XdA3ULckfqH$V{%1*XSQL?vFu&J;D8jzb> zlBiITo0C^;Rbi_HHrEQs1_|pcDS(xfWZNo192Makpx~Tel&WB=XRMoSU}&gdW~OIo zVrph)sH0$HU}&Uo07PcGh9*{~W>!Y#3Q(W~w5=#5%__*n4QdyVXRDM^Qc_^0uU}qX zu2*iXmtT~wZ)j<02{OaTNEfI=x41H|B(Xv_uUHvof=g;~a#3bMNoIbY0?5R~r2Ntn zTP2`NAzsKWfE$}v3=Jk=fazBx7U&!58GyV5Q|Rl9UukYGTy=3tP%6T`SPd=?sVqp< z4@xc0FD*(2MqHXQ$f^P>=c3falKi5O{QMkPCEkVuXiC`{KbCjl+L=feJ;&W?nfFOghT({m?SEB@Sr3U zn+s2Mm~h#;6a0rCXSQ9I=U>3&!8NVPFyA2|IskGUk){PVnCj*hbV zljgD-P1-YY&64f2-1w9jS24`oKJD1VXC-WLotNIGZ!l__GxhG&9UTszS6pSDVlVtr zy7yxAIc~1br!%$dLOW+|Qfc4+y_qY3QOkk#Le#9~wvAVX6OZ2bZWo|*^P62lu|Tll zt)=UFY6?DCPJH@U@{G=eiBH}t&%V5v(); + var creatable = settings.Creatable; + var stereotype = Model.Settings.ContainsKey("Stereotype") ? Model.Settings["Stereotype"] : default(string); +}
-

@Model.DisplayName

@{ var creatable = Model.Settings.GetModel().Creatable; } +

@Model.DisplayName

@if (!string.IsNullOrWhiteSpace(stereotype)) { - @stereotype} @if (creatable) {

@Html.ActionLink(T("Create New {0}", Model.DisplayName).Text, "Create", new {area = "Contents", id = Model.Name})

}