mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-18 17:47:54 +08:00
Merge
--HG-- branch : dev
This commit is contained in:
@@ -61,12 +61,15 @@ namespace Orchard.Tests.Data.Builders {
|
||||
new Dictionary<string, object> {{"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<string, object> {{"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);
|
||||
|
||||
|
||||
|
||||
|
@@ -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<BodyTypePartSettings>();
|
||||
return (typePartSettings != null && !string.IsNullOrWhiteSpace(typePartSettings.Flavor))
|
||||
? typePartSettings.Flavor
|
||||
: part.PartDefinition.Settings.GetModel<BodyPartSettings>().FlavorDefault;
|
||||
}
|
||||
|
||||
class PathBuilder {
|
||||
private readonly IContent _content;
|
||||
private string _path;
|
||||
|
67
src/Orchard.Web/Core/Common/Settings/BodySettings.cs
Normal file
67
src/Orchard.Web/Core/Common/Settings/BodySettings.cs
Normal file
@@ -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<TemplateViewModel> TypePartEditor(ContentTypeDefinition.Part definition) {
|
||||
if (definition.PartDefinition.Name != "BodyAspect")
|
||||
yield break;
|
||||
|
||||
var model = definition.Settings.GetModel<BodyTypePartSettings>();
|
||||
|
||||
if (string.IsNullOrWhiteSpace(model.Flavor)) {
|
||||
var partModel = definition.PartDefinition.Settings.GetModel<BodyPartSettings>();
|
||||
model.Flavor = partModel.FlavorDefault;
|
||||
}
|
||||
|
||||
yield return DefinitionTemplate(model);
|
||||
}
|
||||
|
||||
public override IEnumerable<TemplateViewModel> PartEditor(ContentPartDefinition definition) {
|
||||
if (definition.Name != "BodyAspect")
|
||||
yield break;
|
||||
|
||||
var model = definition.Settings.GetModel<BodyPartSettings>();
|
||||
yield return DefinitionTemplate(model);
|
||||
}
|
||||
|
||||
public override IEnumerable<TemplateViewModel> 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<TemplateViewModel> 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);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<Orchard.Core.Common.Settings.BodyPartSettings>" %>
|
||||
<fieldset>
|
||||
<label for="<%:Html.FieldIdFor(m => m.FlavorDefault) %>"><%:T("Default flavor") %></label>
|
||||
<%:Html.EditorFor(m => m.FlavorDefault)%>
|
||||
<%:Html.ValidationMessageFor(m => m.FlavorDefault)%>
|
||||
</fieldset>
|
@@ -0,0 +1,6 @@
|
||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<Orchard.Core.Common.Settings.BodyTypePartSettings>" %>
|
||||
<fieldset>
|
||||
<label for="<%:Html.FieldIdFor(m => m.Flavor) %>"><%:T("Flavor") %></label>
|
||||
<%:Html.EditorFor(m => m.Flavor) %>
|
||||
<%:Html.ValidationMessageFor(m => m.Flavor) %>
|
||||
</fieldset>
|
@@ -0,0 +1,3 @@
|
||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<BodyEditorViewModel>" %>
|
||||
<%@ Import Namespace="Orchard.Core.Common.ViewModels"%>
|
||||
<%: Html.TextArea("Text", Model.Text, 25, 80, new { @class = Model.Format }) %>
|
@@ -69,6 +69,7 @@
|
||||
<Compile Include="Common\Drivers\TextFieldDriver.cs" />
|
||||
<Compile Include="Common\Fields\TextField.cs" />
|
||||
<Compile Include="Common\Handlers\RoutableAspectHandler.cs" />
|
||||
<Compile Include="Common\Settings\BodySettings.cs" />
|
||||
<Compile Include="Common\ViewModels\ContainerEditorViewModel.cs" />
|
||||
<Compile Include="Common\ViewModels\TextContentFieldDisplayViewModel.cs" />
|
||||
<Compile Include="Common\ViewModels\TextContentFieldEditorViewModel.cs" />
|
||||
@@ -202,11 +203,13 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Common\Module.txt" />
|
||||
<Content Include="Common\Views\DefinitionTemplates\BodyTypePartSettings.ascx" />
|
||||
<Content Include="Common\Views\DefinitionTemplates\BodyPartSettings.ascx" />
|
||||
<Content Include="Common\Views\DisplayTemplates\Fields\Common.TextField.ascx" />
|
||||
<Content Include="Common\Views\EditorTemplates\Fields\Common.TextField.ascx" />
|
||||
<Content Include="Common\Views\EditorTemplates\Parts\Common.Container.ascx" />
|
||||
<Content Include="Common\Views\EditorTemplates\PlainTextEditor.ascx" />
|
||||
<Content Include="Contents\Module.txt" />
|
||||
<Content Include="Contents\Styles\admin.css" />
|
||||
<Content Include="Contents\Views\Admin\List.aspx" />
|
||||
<Content Include="Contents\Views\Admin\Edit.aspx" />
|
||||
<Content Include="Contents\Views\Admin\CreatableTypeList.aspx" />
|
||||
|
@@ -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 {
|
||||
|
@@ -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<string, string> _prefix = x => x;
|
||||
|
||||
public bool TryUpdateModel<TModel>(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,56 @@ 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 });
|
||||
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);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
[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 +142,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 +163,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 +261,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<string, string> _prefix = x => x;
|
||||
|
||||
public bool TryUpdateModel<TModel>(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());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -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
|
@@ -83,6 +83,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Module.txt" />
|
||||
<Content Include="Styles\admin.css" />
|
||||
<Content Include="Views\Admin\AddFieldTo.ascx" />
|
||||
<Content Include="Views\Admin\Create.ascx" />
|
||||
<Content Include="Views\Admin\EditPart.ascx" />
|
||||
@@ -108,7 +109,6 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="App_Data\" />
|
||||
<Folder Include="Helpers\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\Orchard\Orchard.Framework.csproj">
|
||||
@@ -136,9 +136,8 @@
|
||||
<IISUrl>
|
||||
</IISUrl>
|
||||
<NTLMAuthentication>False</NTLMAuthentication>
|
||||
<UseCustomServer>False</UseCustomServer>
|
||||
<CustomServerUrl>
|
||||
</CustomServerUrl>
|
||||
<UseCustomServer>True</UseCustomServer>
|
||||
<CustomServerUrl>http://orchard.codeplex.com</CustomServerUrl>
|
||||
<SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
|
||||
</WebProjectProperties>
|
||||
</FlavorProperties>
|
||||
|
@@ -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) {
|
||||
|
@@ -6,7 +6,7 @@ namespace Orchard.ContentTypes.Services {
|
||||
public interface IContentDefinitionService : IDependency {
|
||||
IEnumerable<ContentTypeDefinition> GetTypeDefinitions();
|
||||
ContentTypeDefinition GetTypeDefinition(string name);
|
||||
void AddTypeDefinition(ContentTypeDefinition contentTypeDefinition);
|
||||
void AddTypeDefinition(string displayName);
|
||||
void AlterTypeDefinition(ContentTypeDefinition contentTypeDefinition);
|
||||
void RemoveTypeDefinition(string name);
|
||||
|
||||
|
@@ -66,6 +66,7 @@ namespace Orchard.ContentTypes.ViewModels {
|
||||
}
|
||||
|
||||
public string Name { get; set; }
|
||||
public IEnumerable<TemplateViewModel> Templates { get; set; }
|
||||
public IEnumerable<EditPartFieldViewModel> Fields { get; set; }
|
||||
public SettingsDictionary Settings { get; set; }
|
||||
}
|
||||
@@ -81,6 +82,7 @@ namespace Orchard.ContentTypes.ViewModels {
|
||||
}
|
||||
|
||||
public string Name { get; set; }
|
||||
public IEnumerable<TemplateViewModel> Templates { get; set; }
|
||||
public EditFieldViewModel FieldDefinition { get; set; }
|
||||
public SettingsDictionary Settings { get; set; }
|
||||
}
|
||||
|
@@ -1,7 +1,5 @@
|
||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<Orchard.ContentTypes.ViewModels.EditTypeViewModel>" %>
|
||||
<%@ Import Namespace="Orchard.Core.Contents.ViewModels" %>
|
||||
<%@ Import Namespace="Orchard.ContentTypes.ViewModels" %><%
|
||||
Html.RegisterStyle("admin.css"); %>
|
||||
<% Html.RegisterStyle("admin.css"); %>
|
||||
<h1><%:Html.TitleForPage(T("Edit Content Type").ToString())%></h1>
|
||||
<p class="breadcrumb"><%:Html.ActionLink(T("Content Types").Text, "index") %><%:T(" > ") %><%:T("Edit Content Type") %></p><%
|
||||
using (Html.BeginFormAntiForgeryPost()) { %>
|
||||
@@ -24,4 +22,4 @@ using (Html.BeginFormAntiForgeryPost()) { %>
|
||||
<fieldset>
|
||||
<button class="primaryAction" type="submit"><%:T("Save") %></button>
|
||||
</fieldset><%
|
||||
} %>
|
||||
} %>
|
@@ -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"}) %>
|
||||
</fieldset>
|
||||
<%:Html.EditorFor(m => m.Settings, "Settings", "") %>
|
||||
<% Html.RenderTemplates(Model.Templates); %>
|
||||
<h2><%:T("Fields") %></h2>
|
||||
<div class="manage add-to-type"><%: Html.ActionLink(T("Add").Text, "AddFieldTo", new { area = "Orchard.ContentTypes", id = Model.Name }, new { @class = "button" }) %></div>
|
||||
<%:Html.EditorFor(m => m.Fields, "Fields", "") %>
|
||||
|
@@ -1,5 +1,4 @@
|
||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<Orchard.ContentTypes.ViewModels.EditPartFieldViewModel>" %>
|
||||
<%@ Import Namespace="Orchard.Core.Contents.ViewModels" %>
|
||||
<dt><%:Model.Name %> <span>(<%:Model.FieldDefinition.Name %>)</span></dt>
|
||||
<dd>
|
||||
<%:Html.DisplayFor(m => m.Settings, "Settings", "") %>
|
||||
|
@@ -1,5 +1,5 @@
|
||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<IEnumerable<Orchard.ContentTypes.ViewModels.EditPartFieldViewModel>>" %>
|
||||
<%@ Import Namespace="Orchard.Core.Contents.ViewModels" %><%
|
||||
<%
|
||||
if (Model.Any()) { %>
|
||||
<dl><%
|
||||
foreach (var field in Model) {
|
||||
|
@@ -1,5 +1,4 @@
|
||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<Orchard.ContentTypes.ViewModels.EditPartFieldViewModel>" %>
|
||||
<%@ Import Namespace="Orchard.Core.Contents.ViewModels" %>
|
||||
<fieldset class="manage-field">
|
||||
<h3><%:Model.Name %> <span>(<%:Model.FieldDefinition.Name %>)</span></h3>
|
||||
<div class="manage">
|
||||
@@ -11,7 +10,7 @@
|
||||
<button type="submit" title="<%:T("Remove") %>"><%:T("Remove") %></button>
|
||||
<% } %> --%>
|
||||
</div>
|
||||
<%:Html.EditorFor(m => m.Settings, "Settings", "") %>
|
||||
<% Html.RenderTemplates(Model.Templates); %>
|
||||
<%:Html.HiddenFor(m => m.Name) %>
|
||||
<%:Html.HiddenFor(m => m.FieldDefinition.Name) %>
|
||||
</fieldset>
|
@@ -1,5 +1,5 @@
|
||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<IEnumerable<Orchard.ContentTypes.ViewModels.EditPartFieldViewModel>>" %>
|
||||
<%@ Import Namespace="Orchard.Core.Contents.ViewModels" %><%
|
||||
<%
|
||||
if (Model.Any()) { %>
|
||||
<fieldset><%
|
||||
var fi = 0;
|
||||
|
@@ -1,6 +1,4 @@
|
||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<Orchard.ContentTypes.ViewModels.EditTypePartViewModel>" %>
|
||||
<%@ Import Namespace="Orchard.Core.Contents.ViewModels" %>
|
||||
<%@ Import Namespace="Orchard.ContentTypes.ViewModels" %>
|
||||
<fieldset class="manage-part">
|
||||
<h3><%:Model.PartDefinition.Name %></h3>
|
||||
<div class="manage">
|
||||
|
@@ -1,5 +1,5 @@
|
||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<IEnumerable<Orchard.ContentTypes.ViewModels.EditTypePartViewModel>>" %>
|
||||
<%@ Import Namespace="Orchard.Core.Contents.ViewModels" %><%
|
||||
<%
|
||||
if (Model.Any()) { %>
|
||||
<fieldset><%
|
||||
var pi = 0;
|
||||
|
@@ -1,6 +1,6 @@
|
||||
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Orchard.DevTools.Settings.DevToolsSettings>" %>
|
||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<Orchard.DevTools.Settings.DevToolsSettings>" %>
|
||||
<fieldset>
|
||||
<%:Html.LabelFor(m=>m.ShowDebugLinks) %>
|
||||
<%:Html.EditorFor(m=>m.ShowDebugLinks) %>
|
||||
<label for="<%:Html.FieldIdFor(m => m.ShowDebugLinks) %>" class="forcheckbox"><%:T("Show debug links") %></label>
|
||||
<%:Html.ValidationMessageFor(m=>m.ShowDebugLinks) %>
|
||||
</fieldset>
|
||||
|
@@ -56,6 +56,7 @@
|
||||
<ItemGroup>
|
||||
<Content Include="Module.txt" />
|
||||
<Content Include="Views\Admin\Index.ascx" />
|
||||
<Content Include="Views\DefinitionTemplates\IndexingSettings.ascx" />
|
||||
<Content Include="Web.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
@@ -78,6 +79,7 @@
|
||||
<Compile Include="Models\LuceneSearchHit.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Services\IndexService.cs" />
|
||||
<Compile Include="Settings\IndexingSettings.cs" />
|
||||
<Compile Include="ViewModels\IndexViewModel.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
@@ -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<TemplateViewModel> PartFieldEditor(ContentPartDefinition.Field definition) {
|
||||
var model = definition.Settings.GetModel<IndexingSettings>();
|
||||
yield return DefinitionTemplate(model);
|
||||
}
|
||||
|
||||
public override IEnumerable<TemplateViewModel> 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);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<Orchard.Indexing.Settings.IndexingSettings>" %>
|
||||
<%@ Import Namespace="Orchard.Mvc.Html" %>
|
||||
<fieldset>
|
||||
<%:Html.EditorFor(m=>m.IncludeInIndex) %>
|
||||
<label for="<%:Html.FieldIdFor(m => m.IncludeInIndex) %>" class="forcheckbox"><%:T("Include in the index") %></label>
|
||||
<%:Html.ValidationMessageFor(m => m.IncludeInIndex)%>
|
||||
</fieldset>
|
@@ -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;
|
||||
@@ -172,6 +173,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);
|
||||
|
@@ -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<ContentField> Fields { get { return _fields; } }
|
||||
|
||||
|
@@ -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<TField> : 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) {
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
|
@@ -25,6 +25,8 @@ namespace Orchard.ContentManagement.MetaData.Builders {
|
||||
}
|
||||
}
|
||||
|
||||
public string Name { get { return _name; } }
|
||||
|
||||
public ContentPartDefinition Build() {
|
||||
return new ContentPartDefinition(_name, _fields, _settings);
|
||||
}
|
||||
@@ -35,7 +37,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);
|
||||
}
|
||||
|
@@ -9,9 +9,13 @@ namespace Orchard.ContentManagement.MetaData {
|
||||
public interface IContentDefinitionEditorEvents : IEventHandler {
|
||||
IEnumerable<TemplateViewModel> TypeEditor(ContentTypeDefinition definition);
|
||||
IEnumerable<TemplateViewModel> TypePartEditor(ContentTypeDefinition.Part definition);
|
||||
IEnumerable<TemplateViewModel> PartEditor(ContentPartDefinition definition);
|
||||
IEnumerable<TemplateViewModel> PartFieldEditor(ContentPartDefinition.Field definition);
|
||||
|
||||
IEnumerable<TemplateViewModel> TypeEditorUpdate(ContentTypeDefinitionBuilder builder, IUpdateModel updateModel);
|
||||
IEnumerable<TemplateViewModel> TypePartEditorUpdate(ContentTypeDefinitionBuilder.PartConfigurer builder, IUpdateModel updateModel);
|
||||
IEnumerable<TemplateViewModel> PartEditorUpdate(ContentPartDefinitionBuilder builder, IUpdateModel updateModel);
|
||||
IEnumerable<TemplateViewModel> PartFieldEditorUpdate(ContentPartDefinitionBuilder builder, IUpdateModel updateModel);
|
||||
}
|
||||
|
||||
public abstract class ContentDefinitionEditorEventsBase : IContentDefinitionEditorEvents {
|
||||
@@ -23,6 +27,14 @@ namespace Orchard.ContentManagement.MetaData {
|
||||
return Enumerable.Empty<TemplateViewModel>();
|
||||
}
|
||||
|
||||
public virtual IEnumerable<TemplateViewModel> PartEditor(ContentPartDefinition definition) {
|
||||
return Enumerable.Empty<TemplateViewModel>();
|
||||
}
|
||||
|
||||
public virtual IEnumerable<TemplateViewModel> PartFieldEditor(ContentPartDefinition.Field definition) {
|
||||
return Enumerable.Empty<TemplateViewModel>();
|
||||
}
|
||||
|
||||
public virtual IEnumerable<TemplateViewModel> TypeEditorUpdate(ContentTypeDefinitionBuilder builder, IUpdateModel updateModel) {
|
||||
return Enumerable.Empty<TemplateViewModel>();
|
||||
}
|
||||
@@ -31,6 +43,14 @@ namespace Orchard.ContentManagement.MetaData {
|
||||
return Enumerable.Empty<TemplateViewModel>();
|
||||
}
|
||||
|
||||
public virtual IEnumerable<TemplateViewModel> PartEditorUpdate(ContentPartDefinitionBuilder builder, IUpdateModel updateModel) {
|
||||
return Enumerable.Empty<TemplateViewModel>();
|
||||
}
|
||||
|
||||
public virtual IEnumerable<TemplateViewModel> PartFieldEditorUpdate(ContentPartDefinitionBuilder builder, IUpdateModel updateModel) {
|
||||
return Enumerable.Empty<TemplateViewModel>();
|
||||
}
|
||||
|
||||
protected static TemplateViewModel DefinitionTemplate<TModel>(TModel model) {
|
||||
return new TemplateViewModel(model, typeof(TModel).Name) {
|
||||
TemplateName = "DefinitionTemplates/" + typeof(TModel).Name
|
||||
|
@@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,15 +1,6 @@
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -13,7 +13,6 @@ using Orchard.Logging;
|
||||
namespace Orchard.Data {
|
||||
public interface ISessionFactoryHolder : ISingletonDependency {
|
||||
ISessionFactory GetSessionFactory();
|
||||
SessionFactoryParameters CreateSessionFactoryParameters(bool createDatabase, bool updateSchema);
|
||||
void CreateDatabase();
|
||||
void UpdateSchema();
|
||||
}
|
||||
@@ -68,7 +67,7 @@ namespace Orchard.Data {
|
||||
public ISessionFactory GetSessionFactory() {
|
||||
lock (this) {
|
||||
if (_sessionFactory == null) {
|
||||
_sessionFactory = BuildSessionFactory(false /*createDatabase*/, false /*updateSchema*/);
|
||||
_sessionFactory = BuildSessionFactory(false /*createDatabase*/, true /*updateSchema*/);
|
||||
}
|
||||
}
|
||||
return _sessionFactory;
|
||||
@@ -77,17 +76,12 @@ namespace Orchard.Data {
|
||||
private ISessionFactory BuildSessionFactory(bool createDatabase, bool updateSchema) {
|
||||
Logger.Debug("Building session factory");
|
||||
|
||||
var sessionFactory = _dataServicesProviderFactory.BuildSessionFactory(CreateSessionFactoryParameters(createDatabase, updateSchema));
|
||||
return sessionFactory;
|
||||
}
|
||||
|
||||
public SessionFactoryParameters CreateSessionFactoryParameters(bool createDatabase, bool updateSchema) {
|
||||
var shellPath = _appDataFolder.Combine("Sites", _shellSettings.Name);
|
||||
_appDataFolder.CreateDirectory(shellPath);
|
||||
|
||||
var shellFolder = _appDataFolder.MapPath(shellPath);
|
||||
|
||||
return new SessionFactoryParameters {
|
||||
var parameters = new SessionFactoryParameters {
|
||||
Provider = _shellSettings.DataProvider,
|
||||
DataFolder = shellFolder,
|
||||
ConnectionString = _shellSettings.DataConnectionString,
|
||||
@@ -95,6 +89,15 @@ namespace Orchard.Data {
|
||||
UpdateSchema = updateSchema,
|
||||
RecordDescriptors = _shellBlueprint.Records,
|
||||
};
|
||||
|
||||
var sessionFactory = _dataServicesProviderFactory
|
||||
.CreateProvider(parameters)
|
||||
.BuildSessionFactory(parameters);
|
||||
|
||||
return sessionFactory;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user