From aadde50df4ad0e946bf887acf135d4c8dc58b764 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Fri, 25 Jun 2010 15:03:42 -0700 Subject: [PATCH 01/10] Adding template sorting by optional position parameter --HG-- branch : dev --- src/Orchard/Mvc/Html/TemplateViewModelExtensions.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Orchard/Mvc/Html/TemplateViewModelExtensions.cs b/src/Orchard/Mvc/Html/TemplateViewModelExtensions.cs index 24cbb667f..ba22edfbc 100644 --- a/src/Orchard/Mvc/Html/TemplateViewModelExtensions.cs +++ b/src/Orchard/Mvc/Html/TemplateViewModelExtensions.cs @@ -1,7 +1,9 @@ using System.Collections.Generic; +using System.Linq; using System.Web.Mvc; using System.Web.Mvc.Html; using Orchard.ContentManagement.ViewModels; +using Orchard.UI.Navigation; namespace Orchard.Mvc.Html { public static class TemplateViewModelExtensions { @@ -9,7 +11,7 @@ namespace Orchard.Mvc.Html { if (templates == null) return; - foreach (var template in templates) { + foreach (var template in templates.OrderByDescending(t => t.Position, new PositionComparer())) { html.RenderTemplates(template); } } From 3d1fc3bbc5a25473b872b3831977a39326642b54 Mon Sep 17 00:00:00 2001 From: Nathan Heskew Date: Mon, 28 Jun 2010 09:33:46 -0700 Subject: [PATCH 02/10] A little post Contents -> ContentTypes move view assembly import cleanup --HG-- branch : dev --- .../Modules/Orchard.ContentTypes/Views/Admin/Edit.ascx | 4 +--- .../Orchard.ContentTypes/Views/DisplayTemplates/Field.ascx | 1 - .../Orchard.ContentTypes/Views/DisplayTemplates/Fields.ascx | 3 +-- .../Orchard.ContentTypes/Views/EditorTemplates/Field.ascx | 1 - .../Orchard.ContentTypes/Views/EditorTemplates/Fields.ascx | 3 +-- .../Orchard.ContentTypes/Views/EditorTemplates/Part.ascx | 2 -- .../Orchard.ContentTypes/Views/EditorTemplates/Parts.ascx | 3 +-- 7 files changed, 4 insertions(+), 13 deletions(-) diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/Admin/Edit.ascx b/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/Admin/Edit.ascx index 25b341ceb..69dbbae50 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/Admin/Edit.ascx +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/Admin/Edit.ascx @@ -1,6 +1,4 @@ -<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl" %> -<%@ Import Namespace="Orchard.Core.Contents.ViewModels" %> -<%@ Import Namespace="Orchard.ContentTypes.ViewModels" %><% +<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl" %><% Html.RegisterStyle("admin.css"); %>

<%:Html.TitleForPage(T("Edit Content Type").ToString())%>

<% diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/DisplayTemplates/Field.ascx b/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/DisplayTemplates/Field.ascx index bab26afb7..75a1fa21f 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/DisplayTemplates/Field.ascx +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/DisplayTemplates/Field.ascx @@ -1,5 +1,4 @@ <%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl" %> -<%@ Import Namespace="Orchard.Core.Contents.ViewModels" %>
<%:Model.Name %> (<%:Model.FieldDefinition.Name %>)
<%:Html.DisplayFor(m => m.Settings, "Settings", "") %> diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/DisplayTemplates/Fields.ascx b/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/DisplayTemplates/Fields.ascx index c98cfb107..3295ed35a 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/DisplayTemplates/Fields.ascx +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/DisplayTemplates/Fields.ascx @@ -1,5 +1,4 @@ -<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl>" %> -<%@ Import Namespace="Orchard.Core.Contents.ViewModels" %><% +<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl>" %><% if (Model.Any()) { %>
<% foreach (var field in Model) { diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/Field.ascx b/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/Field.ascx index 45ab564bd..fba1ccaf2 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/Field.ascx +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/Field.ascx @@ -1,5 +1,4 @@ <%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl" %> -<%@ Import Namespace="Orchard.Core.Contents.ViewModels" %>

<%:Model.Name %> (<%:Model.FieldDefinition.Name %>)

diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/Fields.ascx b/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/Fields.ascx index 6fcb47ed5..6982868ee 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/Fields.ascx +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/Fields.ascx @@ -1,5 +1,4 @@ -<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl>" %> -<%@ Import Namespace="Orchard.Core.Contents.ViewModels" %><% +<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl>" %><% if (Model.Any()) { %>
<% var fi = 0; diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/Part.ascx b/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/Part.ascx index 7134ac5c4..c66916f20 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/Part.ascx +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/Part.ascx @@ -1,6 +1,4 @@ <%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl" %> -<%@ Import Namespace="Orchard.Core.Contents.ViewModels" %> -<%@ Import Namespace="Orchard.ContentTypes.ViewModels" %>

<%:Model.PartDefinition.Name %>

diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/Parts.ascx b/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/Parts.ascx index b0158b24b..b821e2d1e 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/Parts.ascx +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/Parts.ascx @@ -1,5 +1,4 @@ -<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl>" %> -<%@ Import Namespace="Orchard.Core.Contents.ViewModels" %><% +<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl>" %><% if (Model.Any()) { %>
<% var pi = 0; From 41849b20679691b4624d4bcfefd50c03e2a244ee Mon Sep 17 00:00:00 2001 From: Nathan Heskew Date: Mon, 28 Jun 2010 10:08:17 -0700 Subject: [PATCH 03/10] Changed Orchard.ContentTypes feature category. Developer -> Content ("Custom Content" or "Site Builder" could also work) --HG-- branch : dev --- src/Orchard.Web/Modules/Orchard.ContentTypes/Module.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/Module.txt b/src/Orchard.Web/Modules/Orchard.ContentTypes/Module.txt index 417c9d7d8..5b4367f7a 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentTypes/Module.txt +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/Module.txt @@ -7,4 +7,4 @@ orchardversion: 0.1.2010.0312 features: Orchard.ContentTypes: Description: ContentTypes modules enables the creation and alteration of content types not based on code. - Category: Developer + Category: Content \ No newline at end of file From 0a38ebc8c41240cbcbae94eaafde4b90e19fedb4 Mon Sep 17 00:00:00 2001 From: Nathan Heskew Date: Mon, 28 Jun 2010 10:13:48 -0700 Subject: [PATCH 04/10] Moved the CSS for Orchard.Content types to the new proj --HG-- branch : dev --- src/Orchard.Web/Core/Orchard.Core.csproj | 1 - .../Orchard.ContentTypes/Orchard.ContentTypes.csproj | 1 + .../Orchard.ContentTypes}/Styles/admin.css | 0 .../Modules/Orchard.ContentTypes/Views/Admin/Edit.ascx | 6 +++--- .../Orchard.ContentTypes/Views/DisplayTemplates/Fields.ascx | 3 ++- .../Orchard.ContentTypes/Views/EditorTemplates/Fields.ascx | 3 ++- .../Orchard.ContentTypes/Views/EditorTemplates/Parts.ascx | 3 ++- 7 files changed, 10 insertions(+), 7 deletions(-) rename src/Orchard.Web/{Core/Contents => Modules/Orchard.ContentTypes}/Styles/admin.css (100%) diff --git a/src/Orchard.Web/Core/Orchard.Core.csproj b/src/Orchard.Web/Core/Orchard.Core.csproj index e01c2e49b..85758fffe 100644 --- a/src/Orchard.Web/Core/Orchard.Core.csproj +++ b/src/Orchard.Web/Core/Orchard.Core.csproj @@ -201,7 +201,6 @@ - diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/Orchard.ContentTypes.csproj b/src/Orchard.Web/Modules/Orchard.ContentTypes/Orchard.ContentTypes.csproj index 1b4a2bc2b..248a7c49d 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentTypes/Orchard.ContentTypes.csproj +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/Orchard.ContentTypes.csproj @@ -83,6 +83,7 @@ + diff --git a/src/Orchard.Web/Core/Contents/Styles/admin.css b/src/Orchard.Web/Modules/Orchard.ContentTypes/Styles/admin.css similarity index 100% rename from src/Orchard.Web/Core/Contents/Styles/admin.css rename to src/Orchard.Web/Modules/Orchard.ContentTypes/Styles/admin.css diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/Admin/Edit.ascx b/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/Admin/Edit.ascx index 69dbbae50..13f50be98 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/Admin/Edit.ascx +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/Admin/Edit.ascx @@ -1,5 +1,5 @@ -<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl" %><% -Html.RegisterStyle("admin.css"); %> +<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl" %> +<% Html.RegisterStyle("admin.css"); %>

<%:Html.TitleForPage(T("Edit Content Type").ToString())%>

<% using (Html.BeginFormAntiForgeryPost()) { %> @@ -22,4 +22,4 @@ using (Html.BeginFormAntiForgeryPost()) { %>
<% -} %> +} %> \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/DisplayTemplates/Fields.ascx b/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/DisplayTemplates/Fields.ascx index 3295ed35a..34a7b9c56 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/DisplayTemplates/Fields.ascx +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/DisplayTemplates/Fields.ascx @@ -1,4 +1,5 @@ -<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl>" %><% +<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl>" %> +<% if (Model.Any()) { %>
<% foreach (var field in Model) { diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/Fields.ascx b/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/Fields.ascx index 6982868ee..dba3f94eb 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/Fields.ascx +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/Fields.ascx @@ -1,4 +1,5 @@ -<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl>" %><% +<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl>" %> +<% if (Model.Any()) { %>
<% var fi = 0; diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/Parts.ascx b/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/Parts.ascx index b821e2d1e..8f6e4b0ff 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/Parts.ascx +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/Parts.ascx @@ -1,4 +1,5 @@ -<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl>" %><% +<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl>" %> +<% if (Model.Any()) { %>
<% var pi = 0; From 6d310fe3f1c920fe10956106d03a0c85ac6b6bbd Mon Sep 17 00:00:00 2001 From: Nathan Heskew Date: Mon, 28 Jun 2010 13:22:34 -0700 Subject: [PATCH 05/10] Small update to not weld a content type's (implicit) part on twice Also updated the Orchard.ContentTypes proj to not spin up cassini --HG-- branch : dev --- .../Orchard.ContentTypes/Orchard.ContentTypes.csproj | 6 ++---- .../ContentManagement/Drivers/ContentFieldDriver.cs | 3 +-- .../ContentManagement/Handlers/ContentItemBuilder.cs | 10 +++++----- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/Orchard.ContentTypes.csproj b/src/Orchard.Web/Modules/Orchard.ContentTypes/Orchard.ContentTypes.csproj index 248a7c49d..77e7c5269 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentTypes/Orchard.ContentTypes.csproj +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/Orchard.ContentTypes.csproj @@ -109,7 +109,6 @@ - @@ -137,9 +136,8 @@ False - False - - + True + http://orchard.codeplex.com False diff --git a/src/Orchard/ContentManagement/Drivers/ContentFieldDriver.cs b/src/Orchard/ContentManagement/Drivers/ContentFieldDriver.cs index 7338874c1..64139d934 100644 --- a/src/Orchard/ContentManagement/Drivers/ContentFieldDriver.cs +++ b/src/Orchard/ContentManagement/Drivers/ContentFieldDriver.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Linq; using Orchard.ContentManagement.Handlers; using Orchard.ContentManagement.MetaData; -using Orchard.ContentManagement.MetaData.Models; namespace Orchard.ContentManagement.Drivers { public abstract class ContentFieldDriver : IContentFieldDriver where TField : ContentField, new() { @@ -15,7 +14,7 @@ namespace Orchard.ContentManagement.Drivers { } DriverResult IContentFieldDriver.BuildEditorModel(BuildEditorModelContext context) { - return Process(context.ContentItem, (part, field) => Editor(part, field)); + return Process(context.ContentItem, Editor); } DriverResult IContentFieldDriver.UpdateEditorModel(UpdateEditorModelContext context) { diff --git a/src/Orchard/ContentManagement/Handlers/ContentItemBuilder.cs b/src/Orchard/ContentManagement/Handlers/ContentItemBuilder.cs index 1d0a2d428..f7af0e21b 100644 --- a/src/Orchard/ContentManagement/Handlers/ContentItemBuilder.cs +++ b/src/Orchard/ContentManagement/Handlers/ContentItemBuilder.cs @@ -26,12 +26,12 @@ namespace Orchard.ContentManagement.Handlers { typePartDefinition = new ContentTypeDefinition.Part( new ContentPartDefinition(partName), new SettingsDictionary()); - } - var part = new TPart { - TypePartDefinition = typePartDefinition - }; - _item.Weld(part); + var part = new TPart { + TypePartDefinition = typePartDefinition + }; + _item.Weld(part); + } return this; } From 35fe587b6d0b2c1b091bf3a7752f44f4289f2d49 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Mon, 28 Jun 2010 14:57:49 -0700 Subject: [PATCH 06/10] Removing unneeded extension method --HG-- branch : dev --- .../Data/Builders/SessionFactoryBuilderTests.cs | 14 ++++++++++---- .../Data/Providers/IDataServicesProviderFactory.cs | 9 --------- src/Orchard/Data/SessionFactoryHolder.cs | 8 ++++++-- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/Orchard.Tests/Data/Builders/SessionFactoryBuilderTests.cs b/src/Orchard.Tests/Data/Builders/SessionFactoryBuilderTests.cs index 4eab56b43..a841c1ef8 100644 --- a/src/Orchard.Tests/Data/Builders/SessionFactoryBuilderTests.cs +++ b/src/Orchard.Tests/Data/Builders/SessionFactoryBuilderTests.cs @@ -61,12 +61,15 @@ namespace Orchard.Tests.Data.Builders { new Dictionary {{"ProviderName", "SQLite"}}) }); - var sessionFactory = manager.BuildSessionFactory(new SessionFactoryParameters { + var parameters = new SessionFactoryParameters { Provider = "SQLite", DataFolder = _tempDataFolder, UpdateSchema = true, RecordDescriptors = recordDescriptors - }); + }; + var sessionFactory = manager + .CreateProvider(parameters) + .BuildSessionFactory(parameters); var session = sessionFactory.OpenSession(); @@ -95,13 +98,16 @@ namespace Orchard.Tests.Data.Builders { (dataFolder, connectionString) => new SqlServerDataServicesProvider(dataFolder, connectionString), new Dictionary {{"ProviderName", "SqlServer"}}) }); - var sessionFactory = manager.BuildSessionFactory(new SessionFactoryParameters { + var parameters = new SessionFactoryParameters { Provider = "SqlServer", DataFolder = _tempDataFolder, ConnectionString = "Data Source=.\\SQLEXPRESS;AttachDbFileName=" + databasePath + ";Integrated Security=True;User Instance=True;", UpdateSchema = true, RecordDescriptors = recordDescriptors, - }); + }; + var sessionFactory = manager + .CreateProvider(parameters) + .BuildSessionFactory(parameters); diff --git a/src/Orchard/Data/Providers/IDataServicesProviderFactory.cs b/src/Orchard/Data/Providers/IDataServicesProviderFactory.cs index 8b47d40dd..082c98dce 100644 --- a/src/Orchard/Data/Providers/IDataServicesProviderFactory.cs +++ b/src/Orchard/Data/Providers/IDataServicesProviderFactory.cs @@ -1,14 +1,5 @@ -using NHibernate; - namespace Orchard.Data.Providers { public interface IDataServicesProviderFactory : IDependency { IDataServicesProvider CreateProvider(DataServiceParameters sessionFactoryParameters); } - - public static class IDataServicesProviderSelectorExtensions { - public static ISessionFactory BuildSessionFactory(this IDataServicesProviderFactory factory, SessionFactoryParameters sessionFactoryParameters) { - var provider = factory.CreateProvider(sessionFactoryParameters); - return provider != null ? provider.BuildSessionFactory(sessionFactoryParameters) : null; - } - } } diff --git a/src/Orchard/Data/SessionFactoryHolder.cs b/src/Orchard/Data/SessionFactoryHolder.cs index aa5daeccb..8e1e811ae 100644 --- a/src/Orchard/Data/SessionFactoryHolder.cs +++ b/src/Orchard/Data/SessionFactoryHolder.cs @@ -81,14 +81,18 @@ namespace Orchard.Data { var shellFolder = _appDataFolder.MapPath(shellPath); - var sessionFactory = _dataServicesProviderFactory.BuildSessionFactory(new SessionFactoryParameters { + var parameters = new SessionFactoryParameters { Provider = _shellSettings.DataProvider, DataFolder = shellFolder, ConnectionString = _shellSettings.DataConnectionString, CreateDatabase = createDatabase, UpdateSchema = updateSchema, RecordDescriptors = _shellBlueprint.Records, - }); + }; + + var sessionFactory = _dataServicesProviderFactory + .CreateProvider(parameters) + .BuildSessionFactory(parameters); return sessionFactory; } From b22e156d07a0a0443387d73406bb32933f228251 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Mon, 28 Jun 2010 15:30:08 -0700 Subject: [PATCH 07/10] Adding to metadata reader Provides ability to remove parts and fields on merge/import of content definitions Fixes some fieldname/fieldtypename issues on persistence --HG-- branch : dev --- .../Metadata/ContentDefinitionManager.cs | 4 +- .../Builders/ContentPartDefinitionBuilder.cs | 2 +- .../Services/ContentDefinitionReader.cs | 54 +++++++++++++------ 3 files changed, 40 insertions(+), 20 deletions(-) diff --git a/src/Orchard.Web/Core/Settings/Metadata/ContentDefinitionManager.cs b/src/Orchard.Web/Core/Settings/Metadata/ContentDefinitionManager.cs index e907a9d62..37a63908b 100644 --- a/src/Orchard.Web/Core/Settings/Metadata/ContentDefinitionManager.cs +++ b/src/Orchard.Web/Core/Settings/Metadata/ContentDefinitionManager.cs @@ -115,7 +115,7 @@ namespace Orchard.Core.Settings.Metadata { record.Settings = _settingsWriter.Map(model.Settings).ToString(); var toRemove = record.ContentPartFieldDefinitionRecords - .Where(partFieldDefinitionRecord => model.Fields.Any(partField => partFieldDefinitionRecord.Name == partField.Name)) + .Where(partFieldDefinitionRecord => !model.Fields.Any(partField => partFieldDefinitionRecord.Name == partField.Name)) .ToList(); foreach (var remove in toRemove) { @@ -123,7 +123,7 @@ namespace Orchard.Core.Settings.Metadata { } foreach (var field in model.Fields) { - var fieldName = field.FieldDefinition.Name; + var fieldName = field.Name; var partFieldRecord = record.ContentPartFieldDefinitionRecords.SingleOrDefault(r => r.Name == fieldName); if (partFieldRecord == null) { partFieldRecord = new ContentPartFieldDefinitionRecord { diff --git a/src/Orchard/ContentManagement/MetaData/Builders/ContentPartDefinitionBuilder.cs b/src/Orchard/ContentManagement/MetaData/Builders/ContentPartDefinitionBuilder.cs index eb61fbfa2..2b7a0ad73 100644 --- a/src/Orchard/ContentManagement/MetaData/Builders/ContentPartDefinitionBuilder.cs +++ b/src/Orchard/ContentManagement/MetaData/Builders/ContentPartDefinitionBuilder.cs @@ -35,7 +35,7 @@ namespace Orchard.ContentManagement.MetaData.Builders { } public ContentPartDefinitionBuilder RemoveField(string fieldName) { - var existingField = _fields.SingleOrDefault(x => x.FieldDefinition.Name == fieldName); + var existingField = _fields.SingleOrDefault(x => x.Name == fieldName); if (existingField != null) { _fields.Remove(existingField); } diff --git a/src/Orchard/ContentManagement/MetaData/Services/ContentDefinitionReader.cs b/src/Orchard/ContentManagement/MetaData/Services/ContentDefinitionReader.cs index d287ccbdc..44ec15de7 100644 --- a/src/Orchard/ContentManagement/MetaData/Services/ContentDefinitionReader.cs +++ b/src/Orchard/ContentManagement/MetaData/Services/ContentDefinitionReader.cs @@ -1,4 +1,5 @@ -using System.Xml; +using System.Linq; +using System.Xml; using System.Xml.Linq; using Orchard.ContentManagement.MetaData.Builders; using Orchard.ContentManagement.MetaData.Models; @@ -18,13 +19,22 @@ namespace Orchard.ContentManagement.MetaData.Services { } foreach (var iter in source.Elements()) { var partElement = iter; - builder.WithPart( - XmlConvert.DecodeName(partElement.Name.LocalName), - partBuilder => { - foreach (var setting in _settingsReader.Map(partElement)) { - partBuilder.WithSetting(setting.Key, setting.Value); - } - }); + var partName = XmlConvert.DecodeName(partElement.Name.LocalName); + if (partName == "remove") { + var nameAttribute = partElement.Attribute("name"); + if (nameAttribute != null) { + builder.RemovePart(nameAttribute.Value); + } + } + else { + builder.WithPart( + partName, + partBuilder => { + foreach (var setting in _settingsReader.Map(partElement)) { + partBuilder.WithSetting(setting.Key, setting.Value); + } + }); + } } } @@ -36,15 +46,25 @@ namespace Orchard.ContentManagement.MetaData.Services { foreach (var iter in source.Elements()) { var fieldElement = iter; - var fieldParameters = XmlConvert.DecodeName(fieldElement.Name.LocalName).Split('.'); - builder.WithField( - fieldParameters[0], - fieldBuilder => { - fieldBuilder.OfType(fieldParameters[1]); - foreach (var setting in _settingsReader.Map(fieldElement)) { - fieldBuilder.WithSetting(setting.Key, setting.Value); - } - }); + var fieldParameters = XmlConvert.DecodeName(fieldElement.Name.LocalName).Split(new[] { '.' }, 2); + var fieldName = fieldParameters.FirstOrDefault(); + var fieldType = fieldParameters.Skip(1).FirstOrDefault(); + if (fieldName == "remove") { + var nameAttribute = fieldElement.Attribute("name"); + if (nameAttribute != null) { + builder.RemoveField(nameAttribute.Value); + } + } + else { + builder.WithField( + fieldName, + fieldBuilder => { + fieldBuilder.OfType(fieldType); + foreach (var setting in _settingsReader.Map(fieldElement)) { + fieldBuilder.WithSetting(setting.Key, setting.Value); + } + }); + } } } } From 21328875f3811d1065bc142ff2d03415be7e9745 Mon Sep 17 00:00:00 2001 From: Nathan Heskew Date: Mon, 28 Jun 2010 15:43:36 -0700 Subject: [PATCH 08/10] Made the DevTools content type setting UI a little more friendly - also a friendly reminder to myself (or anyone reading this) that I need to hook up an overloaded Html.Label that takes a for value and label text --HG-- branch : dev --- .../Views/DefinitionTemplates/DevToolsSettings.ascx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Orchard.Web/Modules/Orchard.DevTools/Views/DefinitionTemplates/DevToolsSettings.ascx b/src/Orchard.Web/Modules/Orchard.DevTools/Views/DefinitionTemplates/DevToolsSettings.ascx index 0e80c365d..ca3f5368c 100644 --- a/src/Orchard.Web/Modules/Orchard.DevTools/Views/DefinitionTemplates/DevToolsSettings.ascx +++ b/src/Orchard.Web/Modules/Orchard.DevTools/Views/DefinitionTemplates/DevToolsSettings.ascx @@ -1,6 +1,6 @@ -<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %> +<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl" %>
- <%:Html.LabelFor(m=>m.ShowDebugLinks) %> <%:Html.EditorFor(m=>m.ShowDebugLinks) %> + <%:Html.ValidationMessageFor(m=>m.ShowDebugLinks) %>
From d6158e316bb629fb3d98bdaba135729b82af6b48 Mon Sep 17 00:00:00 2001 From: Nathan Heskew Date: Tue, 29 Jun 2010 15:07:40 -0700 Subject: [PATCH 09/10] Hooking up part setting management when editing content types/parts --HG-- branch : dev --- .../Core/Common/Drivers/BodyDriver.cs | 19 +- .../Core/Common/Settings/BodySettings.cs | 67 +++++++ .../DefinitionTemplates/BodyPartSettings.ascx | 6 + .../BodyTypePartSettings.ascx | 6 + .../EditorTemplates/PlainTextEditor.ascx | 3 + src/Orchard.Web/Core/Orchard.Core.csproj | 4 + .../Controllers/AdminController.cs | 172 +++++------------- .../Services/ContentDefinitionService.cs | 18 +- .../Services/IContentDefinitionService.cs | 2 +- .../ViewModels/EditTypeViewModel.cs | 1 + .../Views/Admin/EditPart.ascx | 2 +- .../Orchard.Setup/Services/SetupService.cs | 2 + src/Orchard/ContentManagement/ContentPart.cs | 1 + .../Builders/ContentPartDefinitionBuilder.cs | 2 + .../IContentDefinitionEditorEvents.cs | 10 + 15 files changed, 175 insertions(+), 140 deletions(-) create mode 100644 src/Orchard.Web/Core/Common/Settings/BodySettings.cs create mode 100644 src/Orchard.Web/Core/Common/Views/DefinitionTemplates/BodyPartSettings.ascx create mode 100644 src/Orchard.Web/Core/Common/Views/DefinitionTemplates/BodyTypePartSettings.ascx create mode 100644 src/Orchard.Web/Core/Common/Views/EditorTemplates/PlainTextEditor.ascx diff --git a/src/Orchard.Web/Core/Common/Drivers/BodyDriver.cs b/src/Orchard.Web/Core/Common/Drivers/BodyDriver.cs index f7a0a0264..4d5437b42 100644 --- a/src/Orchard.Web/Core/Common/Drivers/BodyDriver.cs +++ b/src/Orchard.Web/Core/Common/Drivers/BodyDriver.cs @@ -4,6 +4,7 @@ using Orchard.ContentManagement; using Orchard.ContentManagement.Aspects; using Orchard.ContentManagement.Drivers; using Orchard.Core.Common.Models; +using Orchard.Core.Common.Settings; using Orchard.Core.Common.ViewModels; namespace Orchard.Core.Common.Drivers { @@ -12,6 +13,7 @@ namespace Orchard.Core.Common.Drivers { public IOrchardServices Services { get; set; } private const string TemplateName = "Parts/Common.Body"; private const string DefaultTextEditorTemplate = "TinyMceTextEditor"; + private const string PlainTextEditorTemplate = "PlainTextEditor"; public BodyDriver(IOrchardServices services) { Services = services; @@ -21,7 +23,7 @@ namespace Orchard.Core.Common.Drivers { get { return "Body"; } } - // \/\/ Haackalicious on many accounts - don't copy what has been done here for the wrapper \/\/ + // \/\/ Hackalicious on many accounts - don't copy what has been done here for the wrapper \/\/ protected override DriverResult Display(BodyAspect part, string displayType) { var model = new BodyDisplayViewModel { BodyAspect = part, Text = BbcodeReplace(part.Text) }; @@ -40,16 +42,29 @@ namespace Orchard.Core.Common.Drivers { protected override DriverResult Editor(BodyAspect part, IUpdateModel updater) { var model = BuildEditorViewModel(part); updater.TryUpdateModel(model, Prefix, null, null); + + // only set the format if it has not yet been set to preserve the initial format type - might want to change this later to support changing body formats but...later + if (string.IsNullOrWhiteSpace(model.Format)) + model.Format = GetFlavor(part); + return ContentPartTemplate(model, TemplateName, Prefix).Location("primary", "5"); } private static BodyEditorViewModel BuildEditorViewModel(BodyAspect part) { return new BodyEditorViewModel { BodyAspect = part, - TextEditorTemplate = DefaultTextEditorTemplate, + TextEditorTemplate = GetFlavor(part) == "html" ? DefaultTextEditorTemplate : PlainTextEditorTemplate, AddMediaPath= new PathBuilder(part).AddContentType().AddContainerSlug().AddSlug().ToString() }; } + + private static string GetFlavor(BodyAspect part) { + var typePartSettings = part.Settings.GetModel(); + return (typePartSettings != null && !string.IsNullOrWhiteSpace(typePartSettings.Flavor)) + ? typePartSettings.Flavor + : part.PartDefinition.Settings.GetModel().FlavorDefault; + } + class PathBuilder { private readonly IContent _content; private string _path; diff --git a/src/Orchard.Web/Core/Common/Settings/BodySettings.cs b/src/Orchard.Web/Core/Common/Settings/BodySettings.cs new file mode 100644 index 000000000..2e951ee00 --- /dev/null +++ b/src/Orchard.Web/Core/Common/Settings/BodySettings.cs @@ -0,0 +1,67 @@ +using System.Collections.Generic; +using Orchard.ContentManagement; +using Orchard.ContentManagement.MetaData; +using Orchard.ContentManagement.MetaData.Builders; +using Orchard.ContentManagement.MetaData.Models; +using Orchard.ContentManagement.ViewModels; + +namespace Orchard.Core.Common.Settings { + public class BodyPartSettings { + public const string FlavorDefaultDefault = "html"; + private string _flavorDefault; + public string FlavorDefault { + get { return !string.IsNullOrWhiteSpace(_flavorDefault) + ? _flavorDefault + : FlavorDefaultDefault; } + set { _flavorDefault = value; } + } + } + + public class BodyTypePartSettings { + public string Flavor { get; set; } + } + + public class BodySettingsHooks : ContentDefinitionEditorEventsBase { + public override IEnumerable TypePartEditor(ContentTypeDefinition.Part definition) { + if (definition.PartDefinition.Name != "BodyAspect") + yield break; + + var model = definition.Settings.GetModel(); + + if (string.IsNullOrWhiteSpace(model.Flavor)) { + var partModel = definition.PartDefinition.Settings.GetModel(); + model.Flavor = partModel.FlavorDefault; + } + + yield return DefinitionTemplate(model); + } + + public override IEnumerable PartEditor(ContentPartDefinition definition) { + if (definition.Name != "BodyAspect") + yield break; + + var model = definition.Settings.GetModel(); + yield return DefinitionTemplate(model); + } + + public override IEnumerable TypePartEditorUpdate(ContentTypeDefinitionBuilder.PartConfigurer builder, IUpdateModel updateModel) { + if (builder.Name != "BodyAspect") + yield break; + + var model = new BodyTypePartSettings(); + updateModel.TryUpdateModel(model, "BodyTypePartSettings", null, null); + builder.WithSetting("BodyTypePartSettings.Flavor", !string.IsNullOrWhiteSpace(model.Flavor) ? model.Flavor : null); + yield return DefinitionTemplate(model); + } + + public override IEnumerable PartEditorUpdate(ContentPartDefinitionBuilder builder, IUpdateModel updateModel) { + if (builder.Name != "BodyAspect") + yield break; + + var model = new BodyPartSettings(); + updateModel.TryUpdateModel(model, "BodyPartSettings", null, null); + builder.WithSetting("BodyPartSettings.FlavorDefault", !string.IsNullOrWhiteSpace(model.FlavorDefault) ? model.FlavorDefault : null); + yield return DefinitionTemplate(model); + } + } +} diff --git a/src/Orchard.Web/Core/Common/Views/DefinitionTemplates/BodyPartSettings.ascx b/src/Orchard.Web/Core/Common/Views/DefinitionTemplates/BodyPartSettings.ascx new file mode 100644 index 000000000..b4a75d0f0 --- /dev/null +++ b/src/Orchard.Web/Core/Common/Views/DefinitionTemplates/BodyPartSettings.ascx @@ -0,0 +1,6 @@ +<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl" %> +
+ + <%:Html.EditorFor(m => m.FlavorDefault)%> + <%:Html.ValidationMessageFor(m => m.FlavorDefault)%> +
diff --git a/src/Orchard.Web/Core/Common/Views/DefinitionTemplates/BodyTypePartSettings.ascx b/src/Orchard.Web/Core/Common/Views/DefinitionTemplates/BodyTypePartSettings.ascx new file mode 100644 index 000000000..e1b503fa4 --- /dev/null +++ b/src/Orchard.Web/Core/Common/Views/DefinitionTemplates/BodyTypePartSettings.ascx @@ -0,0 +1,6 @@ +<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl" %> +
+ + <%:Html.EditorFor(m => m.Flavor) %> + <%:Html.ValidationMessageFor(m => m.Flavor) %> +
diff --git a/src/Orchard.Web/Core/Common/Views/EditorTemplates/PlainTextEditor.ascx b/src/Orchard.Web/Core/Common/Views/EditorTemplates/PlainTextEditor.ascx new file mode 100644 index 000000000..fa8ace6e0 --- /dev/null +++ b/src/Orchard.Web/Core/Common/Views/EditorTemplates/PlainTextEditor.ascx @@ -0,0 +1,3 @@ +<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl" %> +<%@ Import Namespace="Orchard.Core.Common.ViewModels"%> +<%: Html.TextArea("Text", Model.Text, 25, 80, new { @class = Model.Format }) %> \ No newline at end of file diff --git a/src/Orchard.Web/Core/Orchard.Core.csproj b/src/Orchard.Web/Core/Orchard.Core.csproj index 85758fffe..430850584 100644 --- a/src/Orchard.Web/Core/Orchard.Core.csproj +++ b/src/Orchard.Web/Core/Orchard.Core.csproj @@ -68,6 +68,7 @@ + @@ -197,9 +198,12 @@
+ + + diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/Controllers/AdminController.cs b/src/Orchard.Web/Modules/Orchard.ContentTypes/Controllers/AdminController.cs index 9bfc9cf20..88c6810cb 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentTypes/Controllers/AdminController.cs +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/Controllers/AdminController.cs @@ -1,50 +1,34 @@ using System; -using System.Collections.Generic; using System.Linq; using System.Web.Mvc; using Orchard.ContentManagement; using Orchard.ContentManagement.MetaData; using Orchard.ContentManagement.MetaData.Models; -using Orchard.ContentManagement.ViewModels; using Orchard.ContentTypes.Services; using Orchard.ContentTypes.ViewModels; -using Orchard.Data; using Orchard.Localization; -using Orchard.Logging; using Orchard.Mvc.Results; -using Orchard.UI.Notify; namespace Orchard.ContentTypes.Controllers { public class AdminController : Controller { - private readonly INotifier _notifier; private readonly IContentDefinitionService _contentDefinitionService; private readonly IContentDefinitionManager _contentDefinitionManager; - private readonly IContentManager _contentManager; - private readonly ITransactionManager _transactionManager; private readonly IContentDefinitionEditorEvents _extendViewModels; public AdminController( IOrchardServices orchardServices, - INotifier notifier, IContentDefinitionService contentDefinitionService, IContentDefinitionManager contentDefinitionManager, - IContentManager contentManager, - ITransactionManager transactionManager, IContentDefinitionEditorEvents extendViewModels) { Services = orchardServices; - _notifier = notifier; _contentDefinitionService = contentDefinitionService; _contentDefinitionManager = contentDefinitionManager; - _contentManager = contentManager; - _transactionManager = transactionManager; _extendViewModels = extendViewModels; T = NullLocalizer.Instance; - Logger = NullLogger.Instance; } public IOrchardServices Services { get; private set; } public Localizer T { get; set; } - public ILogger Logger { get; set; } public ActionResult Index() { return List(); } @@ -69,32 +53,14 @@ namespace Orchard.ContentTypes.Controllers { if (!Services.Authorizer.Authorize(Permissions.CreateContentTypes, T("Not allowed to create a content type."))) return new HttpUnauthorizedResult(); - var model = new ContentTypeDefinition(""); - TryUpdateModel(model); - - if (!ModelState.IsValid) { - Services.TransactionManager.Cancel(); + if (!ModelState.IsValid) return View(viewModel); - } - _contentDefinitionService.AddTypeDefinition(model); + _contentDefinitionService.AddTypeDefinition(viewModel.DisplayName); return RedirectToAction("Index"); } - class Updater : IUpdateModel { - public AdminController Thunk { get; set; } - public Func _prefix = x => x; - - public bool TryUpdateModel(TModel model, string prefix, string[] includeProperties, string[] excludeProperties) where TModel : class { - return Thunk.TryUpdateModel(model, _prefix(prefix), includeProperties, excludeProperties); - } - - public void AddModelError(string key, LocalizedString errorMessage) { - Thunk.ModelState.AddModelError(_prefix(key), errorMessage.ToString()); - } - } - public ActionResult Edit(string id) { if (!Services.Authorizer.Authorize(Permissions.CreateContentTypes, T("Not allowed to edit a content type."))) return new HttpUnauthorizedResult(); @@ -106,36 +72,30 @@ namespace Orchard.ContentTypes.Controllers { var viewModel = new EditTypeViewModel(contentTypeDefinition); viewModel.Parts = viewModel.Parts.ToArray(); - viewModel.Templates = _extendViewModels.TypeEditor(contentTypeDefinition); + var entries = viewModel.Parts.Join(contentTypeDefinition.Parts, - m => m.PartDefinition.Name, - d => d.PartDefinition.Name, - (model, definition) => new { model, definition }); - foreach (var entry in entries) { + m => m.PartDefinition.Name, + d => d.PartDefinition.Name, + (model, definition) => new {model, definition}); + foreach (var entry in entries) entry.model.Templates = _extendViewModels.TypePartEditor(entry.definition); - } return View(viewModel); } [HttpPost, ActionName("Edit")] - public ActionResult EditPOST(string id) { + public ActionResult EditPOST(EditTypeViewModel viewModel) { if (!Services.Authorizer.Authorize(Permissions.CreateContentTypes, T("Not allowed to edit a content type."))) return new HttpUnauthorizedResult(); - var contentTypeDefinition = _contentDefinitionService.GetTypeDefinition(id); + var contentTypeDefinition = _contentDefinitionService.GetTypeDefinition(viewModel.Name); if (contentTypeDefinition == null) return new NotFoundResult(); - var updater = new Updater { Thunk = this }; - - var viewModel = new EditTypeViewModel(); - TryUpdateModel(viewModel); - - - _contentDefinitionManager.AlterTypeDefinition(id, typeBuilder => { + var updater = new Updater(this); + _contentDefinitionManager.AlterTypeDefinition(viewModel.Name, typeBuilder => { typeBuilder.DisplayedAs(viewModel.DisplayName); @@ -156,63 +116,14 @@ namespace Orchard.ContentTypes.Controllers { } }); - if (!ModelState.IsValid) { - _transactionManager.Cancel(); + Services.TransactionManager.Cancel(); return View(viewModel); } - //var contentTypeDefinitionParts = viewModel.Parts.Select(GenerateTypePart).ToList(); - //if (viewModel.Fields.Any()) - // contentTypeDefinitionParts.Add(GenerateTypePart(viewModel)); - - ////todo: apply the changes along the lines of but definately not resembling - //// for now this _might_ just get a little messy -> - //_contentDefinitionService.AlterTypeDefinition( - // new ContentTypeDefinition( - // viewModel.Name, - // viewModel.DisplayName, - // contentTypeDefinitionParts, - // viewModel.Settings - // ) - // ); - return RedirectToAction("Index"); } - private static ContentTypeDefinition.Part GenerateTypePart(EditTypePartViewModel viewModel) { - return new ContentTypeDefinition.Part( - new ContentPartDefinition( - viewModel.PartDefinition.Name, - viewModel.PartDefinition.Fields.Select( - f => new ContentPartDefinition.Field( - new ContentFieldDefinition(f.FieldDefinition.Name), - f.Name, - f.Settings - ) - ), - viewModel.PartDefinition.Settings - ), - viewModel.Settings - ); - } - - private static ContentTypeDefinition.Part GenerateTypePart(EditTypeViewModel viewModel) { - return new ContentTypeDefinition.Part( - new ContentPartDefinition( - viewModel.Name, - viewModel.Fields.Select( - f => new ContentPartDefinition.Field( - new ContentFieldDefinition(f.FieldDefinition.Name), - f.Name, - f.Settings - ) - ), - null - ), - null - ); - } #endregion #region Parts @@ -226,28 +137,33 @@ namespace Orchard.ContentTypes.Controllers { if (contentPartDefinition == null) return new NotFoundResult(); - return View(new EditPartViewModel(contentPartDefinition)); + var viewModel = new EditPartViewModel(contentPartDefinition) { + Templates = _extendViewModels.PartEditor(contentPartDefinition) + }; + + return View(viewModel); } [HttpPost, ActionName("EditPart")] - public ActionResult EditPartPOST(string id) { + public ActionResult EditPartPOST(EditPartViewModel viewModel) { if (!Services.Authorizer.Authorize(Permissions.CreateContentTypes, T("Not allowed to edit a part."))) return new HttpUnauthorizedResult(); - var contentPartDefinition = _contentDefinitionService.GetPartDefinition(id); + var contentPartDefinition = _contentDefinitionService.GetPartDefinition(viewModel.Name); if (contentPartDefinition == null) return new NotFoundResult(); - var viewModel = new EditPartViewModel(); - TryUpdateModel(viewModel); + var updater = new Updater(this); + _contentDefinitionManager.AlterPartDefinition(viewModel.Name, partBuilder => { + // allow extensions to alter part configuration + viewModel.Templates = _extendViewModels.PartEditorUpdate(partBuilder, updater); + }); - if (!ModelState.IsValid) - return EditPart(id); - - //todo: apply the changes along the lines of but definately not resembling - // for now this _might_ just get a little messy -> - _contentDefinitionService.AlterPartDefinition(GeneratePart(viewModel)); + if (!ModelState.IsValid) { + Services.TransactionManager.Cancel(); + return View(viewModel); + } return RedirectToAction("Index"); } @@ -319,21 +235,25 @@ namespace Orchard.ContentTypes.Controllers { return RedirectToAction("EditPart", new { id }); } - private static ContentPartDefinition GeneratePart(EditPartViewModel viewModel) { - return new ContentPartDefinition( - viewModel.Name, - viewModel.Fields.Select( - f => new ContentPartDefinition.Field( - new ContentFieldDefinition(f.FieldDefinition.Name), - f.Name, - f.Settings - ) - ), - viewModel.Settings - ); - } - #endregion + class Updater : IUpdateModel { + private readonly AdminController _thunk; + + public Updater(AdminController thunk) { + _thunk = thunk; + } + + public Func _prefix = x => x; + + public bool TryUpdateModel(TModel model, string prefix, string[] includeProperties, string[] excludeProperties) where TModel : class { + return _thunk.TryUpdateModel(model, _prefix(prefix), includeProperties, excludeProperties); + } + + public void AddModelError(string key, LocalizedString errorMessage) { + _thunk.ModelState.AddModelError(_prefix(key), errorMessage.ToString()); + } + } + } } diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/Services/ContentDefinitionService.cs b/src/Orchard.Web/Modules/Orchard.ContentTypes/Services/ContentDefinitionService.cs index 5b1eb378f..fa33692d8 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentTypes/Services/ContentDefinitionService.cs +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/Services/ContentDefinitionService.cs @@ -31,23 +31,21 @@ namespace Orchard.ContentTypes.Services { return _contentDefinitionManager.GetTypeDefinition(name); } - public void AddTypeDefinition(ContentTypeDefinition contentTypeDefinition) { - var typeName = string.IsNullOrWhiteSpace(contentTypeDefinition.Name) - ? GenerateTypeName(contentTypeDefinition.DisplayName) - : contentTypeDefinition.Name; + public void AddTypeDefinition(string displayName) { + var name = GenerateTypeName(displayName); - while (_contentDefinitionManager.GetTypeDefinition(typeName) != null) - typeName = VersionTypeName(typeName); + while (_contentDefinitionManager.GetTypeDefinition(name) != null) + name = VersionTypeName(name); //just giving the new type some default parts for now + _contentDefinitionManager.StoreTypeDefinition(new ContentTypeDefinition(name) {DisplayName = displayName}); _contentDefinitionManager.AlterTypeDefinition( - typeName, - cfg => cfg.DisplayedAs(contentTypeDefinition.DisplayName) - .WithPart("CommonAspect") + name, + cfg => cfg.WithPart("CommonAspect") //.WithPart("RoutableAspect") //need to go the new routable route .WithPart("BodyAspect")); - Services.Notifier.Information(T("Created content type: {0}", contentTypeDefinition.DisplayName)); + Services.Notifier.Information(T("Created content type: {0}", displayName)); } public void AlterTypeDefinition(ContentTypeDefinition contentTypeDefinition) { diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/Services/IContentDefinitionService.cs b/src/Orchard.Web/Modules/Orchard.ContentTypes/Services/IContentDefinitionService.cs index 575c8fd4e..4f4da54ec 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentTypes/Services/IContentDefinitionService.cs +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/Services/IContentDefinitionService.cs @@ -6,7 +6,7 @@ namespace Orchard.ContentTypes.Services { public interface IContentDefinitionService : IDependency { IEnumerable GetTypeDefinitions(); ContentTypeDefinition GetTypeDefinition(string name); - void AddTypeDefinition(ContentTypeDefinition contentTypeDefinition); + void AddTypeDefinition(string displayName); void AlterTypeDefinition(ContentTypeDefinition contentTypeDefinition); void RemoveTypeDefinition(string name); diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/ViewModels/EditTypeViewModel.cs b/src/Orchard.Web/Modules/Orchard.ContentTypes/ViewModels/EditTypeViewModel.cs index 89203c4aa..f3f4d9e86 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentTypes/ViewModels/EditTypeViewModel.cs +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/ViewModels/EditTypeViewModel.cs @@ -66,6 +66,7 @@ namespace Orchard.ContentTypes.ViewModels { } public string Name { get; set; } + public IEnumerable Templates { get; set; } public IEnumerable Fields { get; set; } public SettingsDictionary Settings { get; set; } } diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/Admin/EditPart.ascx b/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/Admin/EditPart.ascx index 34901350b..c79f8fc14 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/Admin/EditPart.ascx +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/Admin/EditPart.ascx @@ -9,7 +9,7 @@ using (Html.BeginFormAntiForgeryPost()) { %> <%--// has unintended consequences (renamging the part) - changing the name creates a new part of that name--%> <%:Html.TextBoxFor(m => m.Name, new {@class = "textMedium"}) %>
- <%:Html.EditorFor(m => m.Settings, "Settings", "") %> + <% Html.RenderTemplates(Model.Templates); %>

<%:T("Fields") %>

<%: Html.ActionLink(T("Add").Text, "AddFieldTo", new { area = "Orchard.ContentTypes", id = Model.Name }, new { @class = "button" }) %>
<%:Html.EditorFor(m => m.Fields, "Fields", "") %> diff --git a/src/Orchard.Web/Modules/Orchard.Setup/Services/SetupService.cs b/src/Orchard.Web/Modules/Orchard.Setup/Services/SetupService.cs index 01d642d17..e95419513 100644 --- a/src/Orchard.Web/Modules/Orchard.Setup/Services/SetupService.cs +++ b/src/Orchard.Web/Modules/Orchard.Setup/Services/SetupService.cs @@ -5,6 +5,7 @@ using Orchard.Comments.Models; using Orchard.ContentManagement; using Orchard.ContentManagement.MetaData; using Orchard.Core.Common.Models; +using Orchard.Core.Common.Settings; using Orchard.Core.Navigation.Models; using Orchard.Core.Settings.Models; using Orchard.Data; @@ -150,6 +151,7 @@ namespace Orchard.Setup.Services { contentDefinitionManager.AlterTypeDefinition("BlogPost", cfg => cfg.DisplayedAs("Blog Post").WithPart("HasComments").WithPart("HasTags").WithPart("Localized")); contentDefinitionManager.AlterTypeDefinition("Page", cfg => cfg.DisplayedAs("Page").WithPart("HasComments").WithPart("HasTags").WithPart("Localized")); contentDefinitionManager.AlterTypeDefinition("SandboxPage", cfg => cfg.DisplayedAs("Sandbox Page").WithPart("HasComments").WithPart("HasTags").WithPart("Localized")); + contentDefinitionManager.AlterPartDefinition("BodyAspect", cfg => cfg.WithSetting("BodyPartSettings.FlavorDefault", BodyPartSettings.FlavorDefaultDefault)); // create home page as a CMS page var page = contentManager.Create("Page", VersionOptions.Draft); diff --git a/src/Orchard/ContentManagement/ContentPart.cs b/src/Orchard/ContentManagement/ContentPart.cs index 47e3d903c..76f90f8eb 100644 --- a/src/Orchard/ContentManagement/ContentPart.cs +++ b/src/Orchard/ContentManagement/ContentPart.cs @@ -16,6 +16,7 @@ namespace Orchard.ContentManagement { public ContentTypeDefinition TypeDefinition { get { return ContentItem.TypeDefinition; } } public ContentTypeDefinition.Part TypePartDefinition { get; set; } public ContentPartDefinition PartDefinition { get { return TypePartDefinition.PartDefinition; } } + public SettingsDictionary Settings { get { return TypePartDefinition.Settings; } } public IEnumerable Fields { get { return _fields; } } diff --git a/src/Orchard/ContentManagement/MetaData/Builders/ContentPartDefinitionBuilder.cs b/src/Orchard/ContentManagement/MetaData/Builders/ContentPartDefinitionBuilder.cs index 2b7a0ad73..98f8e71cf 100644 --- a/src/Orchard/ContentManagement/MetaData/Builders/ContentPartDefinitionBuilder.cs +++ b/src/Orchard/ContentManagement/MetaData/Builders/ContentPartDefinitionBuilder.cs @@ -25,6 +25,8 @@ namespace Orchard.ContentManagement.MetaData.Builders { } } + public string Name { get { return _name; } } + public ContentPartDefinition Build() { return new ContentPartDefinition(_name, _fields, _settings); } diff --git a/src/Orchard/ContentManagement/MetaData/IContentDefinitionEditorEvents.cs b/src/Orchard/ContentManagement/MetaData/IContentDefinitionEditorEvents.cs index fdcd05a87..7c25981d4 100644 --- a/src/Orchard/ContentManagement/MetaData/IContentDefinitionEditorEvents.cs +++ b/src/Orchard/ContentManagement/MetaData/IContentDefinitionEditorEvents.cs @@ -9,9 +9,11 @@ namespace Orchard.ContentManagement.MetaData { public interface IContentDefinitionEditorEvents : IEventHandler { IEnumerable TypeEditor(ContentTypeDefinition definition); IEnumerable TypePartEditor(ContentTypeDefinition.Part definition); + IEnumerable PartEditor(ContentPartDefinition definition); IEnumerable TypeEditorUpdate(ContentTypeDefinitionBuilder builder, IUpdateModel updateModel); IEnumerable TypePartEditorUpdate(ContentTypeDefinitionBuilder.PartConfigurer builder, IUpdateModel updateModel); + IEnumerable PartEditorUpdate(ContentPartDefinitionBuilder builder, IUpdateModel updateModel); } public abstract class ContentDefinitionEditorEventsBase : IContentDefinitionEditorEvents { @@ -23,6 +25,10 @@ namespace Orchard.ContentManagement.MetaData { return Enumerable.Empty(); } + public virtual IEnumerable PartEditor(ContentPartDefinition definition) { + return Enumerable.Empty(); + } + public virtual IEnumerable TypeEditorUpdate(ContentTypeDefinitionBuilder builder, IUpdateModel updateModel) { return Enumerable.Empty(); } @@ -31,6 +37,10 @@ namespace Orchard.ContentManagement.MetaData { return Enumerable.Empty(); } + public virtual IEnumerable PartEditorUpdate(ContentPartDefinitionBuilder builder, IUpdateModel updateModel) { + return Enumerable.Empty(); + } + protected static TemplateViewModel DefinitionTemplate(TModel model) { return new TemplateViewModel(model, typeof(TModel).Name) { TemplateName = "DefinitionTemplates/" + typeof(TModel).Name From cce58c6a11153cfa9d3f337ad1fc48997118972b Mon Sep 17 00:00:00 2001 From: Nathan Heskew Date: Tue, 29 Jun 2010 16:00:01 -0700 Subject: [PATCH 10/10] Getting field setting editors displayed in the content type editor (still need to hook up update...and refactor relevant actions) --HG-- branch : dev --- .../Controllers/AdminController.cs | 28 ++++++++++++++++++- .../ViewModels/EditTypeViewModel.cs | 1 + .../Views/EditorTemplates/Field.ascx | 2 +- .../Orchard.Indexing/Orchard.Indexing.csproj | 2 ++ .../Settings/IndexingSettings.cs | 26 +++++++++++++++++ .../DefinitionTemplates/IndexingSettings.ascx | 7 +++++ .../IContentDefinitionEditorEvents.cs | 10 +++++++ 7 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 src/Orchard.Web/Modules/Orchard.Indexing/Settings/IndexingSettings.cs create mode 100644 src/Orchard.Web/Modules/Orchard.Indexing/Views/DefinitionTemplates/IndexingSettings.ascx diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/Controllers/AdminController.cs b/src/Orchard.Web/Modules/Orchard.ContentTypes/Controllers/AdminController.cs index 88c6810cb..308c2a4c9 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentTypes/Controllers/AdminController.cs +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/Controllers/AdminController.cs @@ -78,9 +78,35 @@ namespace Orchard.ContentTypes.Controllers { m => m.PartDefinition.Name, d => d.PartDefinition.Name, (model, definition) => new {model, definition}); - foreach (var entry in entries) + foreach (var entry in entries) { entry.model.Templates = _extendViewModels.TypePartEditor(entry.definition); + var fields = entry.model.PartDefinition.Fields.Join(entry.definition.PartDefinition.Fields, + m => m.FieldDefinition.Name, + d => d.FieldDefinition.Name, + (model, definition) => new { model, definition }); + + foreach (var field in fields) { + field.model.Templates = _extendViewModels.PartFieldEditor(field.definition); + } + } + + + //Oy, this action is getting massive :( + //todo: put this action on a diet + var contentPartDefinition = _contentDefinitionService.GetPartDefinition(id); + if (contentPartDefinition != null) { + viewModel.Fields = viewModel.Fields.ToArray(); + var fields = viewModel.Fields.Join(contentPartDefinition.Fields, + m => m.FieldDefinition.Name, + d => d.FieldDefinition.Name, + (model, definition) => new { model, definition }); + + foreach (var field in fields) { + field.model.Templates = _extendViewModels.PartFieldEditor(field.definition); + } + } + return View(viewModel); } diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/ViewModels/EditTypeViewModel.cs b/src/Orchard.Web/Modules/Orchard.ContentTypes/ViewModels/EditTypeViewModel.cs index f3f4d9e86..f912eb7f1 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentTypes/ViewModels/EditTypeViewModel.cs +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/ViewModels/EditTypeViewModel.cs @@ -82,6 +82,7 @@ namespace Orchard.ContentTypes.ViewModels { } public string Name { get; set; } + public IEnumerable Templates { get; set; } public EditFieldViewModel FieldDefinition { get; set; } public SettingsDictionary Settings { get; set; } } diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/Field.ascx b/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/Field.ascx index fba1ccaf2..af061a2a1 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/Field.ascx +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/Field.ascx @@ -10,7 +10,7 @@ <% } %> --%>
- <%:Html.EditorFor(m => m.Settings, "Settings", "") %> + <% Html.RenderTemplates(Model.Templates); %> <%:Html.HiddenFor(m => m.Name) %> <%:Html.HiddenFor(m => m.FieldDefinition.Name) %>
\ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Indexing/Orchard.Indexing.csproj b/src/Orchard.Web/Modules/Orchard.Indexing/Orchard.Indexing.csproj index 179e2bb84..85e922562 100644 --- a/src/Orchard.Web/Modules/Orchard.Indexing/Orchard.Indexing.csproj +++ b/src/Orchard.Web/Modules/Orchard.Indexing/Orchard.Indexing.csproj @@ -56,6 +56,7 @@ + @@ -77,6 +78,7 @@ + diff --git a/src/Orchard.Web/Modules/Orchard.Indexing/Settings/IndexingSettings.cs b/src/Orchard.Web/Modules/Orchard.Indexing/Settings/IndexingSettings.cs new file mode 100644 index 000000000..1a1146b5b --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.Indexing/Settings/IndexingSettings.cs @@ -0,0 +1,26 @@ +using System.Collections.Generic; +using Orchard.ContentManagement; +using Orchard.ContentManagement.MetaData; +using Orchard.ContentManagement.MetaData.Builders; +using Orchard.ContentManagement.MetaData.Models; +using Orchard.ContentManagement.ViewModels; + +namespace Orchard.Indexing.Settings { + public class IndexingSettings { + public bool IncludeInIndex { get; set; } + } + + public class IndexingSettingsHooks : ContentDefinitionEditorEventsBase { + public override IEnumerable PartFieldEditor(ContentPartDefinition.Field definition) { + var model = definition.Settings.GetModel(); + yield return DefinitionTemplate(model); + } + + public override IEnumerable PartFieldEditorUpdate(ContentPartDefinitionBuilder builder, IUpdateModel updateModel) { + var model = new IndexingSettings(); + updateModel.TryUpdateModel(model, "IndexingSettings", null, null); + builder.WithSetting("IndexingSettings.IncludeInIndex", model.IncludeInIndex ? true.ToString() : null); + yield return DefinitionTemplate(model); + } + } +} diff --git a/src/Orchard.Web/Modules/Orchard.Indexing/Views/DefinitionTemplates/IndexingSettings.ascx b/src/Orchard.Web/Modules/Orchard.Indexing/Views/DefinitionTemplates/IndexingSettings.ascx new file mode 100644 index 000000000..b68c8f08c --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.Indexing/Views/DefinitionTemplates/IndexingSettings.ascx @@ -0,0 +1,7 @@ +<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl" %> +<%@ Import Namespace="Orchard.Mvc.Html" %> +
+ <%:Html.EditorFor(m=>m.IncludeInIndex) %> + + <%:Html.ValidationMessageFor(m => m.IncludeInIndex)%> +
diff --git a/src/Orchard/ContentManagement/MetaData/IContentDefinitionEditorEvents.cs b/src/Orchard/ContentManagement/MetaData/IContentDefinitionEditorEvents.cs index 7c25981d4..f7e5cac93 100644 --- a/src/Orchard/ContentManagement/MetaData/IContentDefinitionEditorEvents.cs +++ b/src/Orchard/ContentManagement/MetaData/IContentDefinitionEditorEvents.cs @@ -10,10 +10,12 @@ namespace Orchard.ContentManagement.MetaData { IEnumerable TypeEditor(ContentTypeDefinition definition); IEnumerable TypePartEditor(ContentTypeDefinition.Part definition); IEnumerable PartEditor(ContentPartDefinition definition); + IEnumerable PartFieldEditor(ContentPartDefinition.Field definition); IEnumerable TypeEditorUpdate(ContentTypeDefinitionBuilder builder, IUpdateModel updateModel); IEnumerable TypePartEditorUpdate(ContentTypeDefinitionBuilder.PartConfigurer builder, IUpdateModel updateModel); IEnumerable PartEditorUpdate(ContentPartDefinitionBuilder builder, IUpdateModel updateModel); + IEnumerable PartFieldEditorUpdate(ContentPartDefinitionBuilder builder, IUpdateModel updateModel); } public abstract class ContentDefinitionEditorEventsBase : IContentDefinitionEditorEvents { @@ -29,6 +31,10 @@ namespace Orchard.ContentManagement.MetaData { return Enumerable.Empty(); } + public virtual IEnumerable PartFieldEditor(ContentPartDefinition.Field definition) { + return Enumerable.Empty(); + } + public virtual IEnumerable TypeEditorUpdate(ContentTypeDefinitionBuilder builder, IUpdateModel updateModel) { return Enumerable.Empty(); } @@ -41,6 +47,10 @@ namespace Orchard.ContentManagement.MetaData { return Enumerable.Empty(); } + public virtual IEnumerable PartFieldEditorUpdate(ContentPartDefinitionBuilder builder, IUpdateModel updateModel) { + return Enumerable.Empty(); + } + protected static TemplateViewModel DefinitionTemplate(TModel model) { return new TemplateViewModel(model, typeof(TModel).Name) { TemplateName = "DefinitionTemplates/" + typeof(TModel).Name