Retiring ContentItemViewModel

...and all that entails
- things like IZone and IZoneCollection are barely roughed in

--HG--
branch : theming
This commit is contained in:
Nathan Heskew
2010-09-03 16:04:42 -07:00
parent 0d91cf30ac
commit 043bcf54ee
76 changed files with 419 additions and 357 deletions

View File

@@ -103,7 +103,7 @@ namespace Orchard.Core.Tests.Common.Providers {
var item = contentManager.Create<ICommonPart>("test-item", VersionOptions.Draft, init => { }); var item = contentManager.Create<ICommonPart>("test-item", VersionOptions.Draft, init => { });
var viewModel = new OwnerEditorViewModel() { Owner = "User" }; var viewModel = new OwnerEditorViewModel() { Owner = "User" };
updateModel.Setup(x => x.TryUpdateModel(viewModel, "", null, null)).Returns(true); updateModel.Setup(x => x.TryUpdateModel(viewModel, "", null, null)).Returns(true);
contentManager.UpdateEditorShape(item.ContentItem, updateModel.Object); contentManager.UpdateEditorModel(item.ContentItem, updateModel.Object);
} }
class UpdatModelStub : IUpdateModel { class UpdatModelStub : IUpdateModel {
@@ -142,7 +142,7 @@ namespace Orchard.Core.Tests.Common.Providers {
var updater = new UpdatModelStub() { Owner = null }; var updater = new UpdatModelStub() { Owner = null };
contentManager.UpdateEditorShape(item.ContentItem, updater); contentManager.UpdateEditorModel(item.ContentItem, updater);
} }
[Test, Ignore("Fix pending")] [Test, Ignore("Fix pending")]
@@ -160,7 +160,7 @@ namespace Orchard.Core.Tests.Common.Providers {
var updater = new UpdatModelStub() {Owner = ""}; var updater = new UpdatModelStub() {Owner = ""};
contentManager.UpdateEditorShape(item.ContentItem, updater); contentManager.UpdateEditorModel(item.ContentItem, updater);
Assert.That(updater.ModelErrors.ContainsKey("CommonPart.Owner"), Is.True); Assert.That(updater.ModelErrors.ContainsKey("CommonPart.Owner"), Is.True);
} }

View File

@@ -7,12 +7,10 @@ using Orchard.ContentManagement;
using Orchard.ContentManagement.Drivers; using Orchard.ContentManagement.Drivers;
using Orchard.ContentManagement.Drivers.Coordinators; using Orchard.ContentManagement.Drivers.Coordinators;
using Orchard.ContentManagement.Handlers; using Orchard.ContentManagement.Handlers;
using Orchard.ContentManagement.MetaData;
using Orchard.DisplayManagement; using Orchard.DisplayManagement;
using Orchard.DisplayManagement.Implementation; using Orchard.DisplayManagement.Implementation;
using Orchard.Environment.AutofacUtil; using Orchard.Environment.AutofacUtil;
using Orchard.Mvc.ViewModels;
using Orchard.Tests.Utility;
using Orchard.UI.Zones;
namespace Orchard.Tests.ContentManagement.Handlers.Coordinators { namespace Orchard.Tests.ContentManagement.Handlers.Coordinators {
[TestFixture] [TestFixture]
@@ -25,7 +23,8 @@ namespace Orchard.Tests.ContentManagement.Handlers.Coordinators {
//builder.RegisterModule(new ImplicitCollectionSupportModule()); //builder.RegisterModule(new ImplicitCollectionSupportModule());
builder.RegisterType<ContentPartDriverCoordinator>().As<IContentHandler>(); builder.RegisterType<ContentPartDriverCoordinator>().As<IContentHandler>();
builder.RegisterType<ShapeHelperFactory>().As<IShapeHelperFactory>(); builder.RegisterType<ShapeHelperFactory>().As<IShapeHelperFactory>();
builder.RegisterAutoMocking(MockBehavior.Loose); builder.RegisterType<DefaultShapeFactory>().As<IShapeFactory>();
builder.RegisterInstance(new Mock<IContentDefinitionManager>().Object);
_container = builder.Build(); _container = builder.Build();
} }
@@ -44,20 +43,18 @@ namespace Orchard.Tests.ContentManagement.Handlers.Coordinators {
builder.RegisterInstance(driver2.Object); builder.RegisterInstance(driver2.Object);
builder.Update(_container); builder.Update(_container);
var contentHandler = _container.Resolve<IContentHandler>(); var contentHandler = _container.Resolve<IContentHandler>();
var shapeHelperFactory = _container.Resolve<IShapeHelperFactory>();
var shape = shapeHelperFactory.CreateHelper(); var contentItem = new ContentItem();
ContentItem foo = shape.Foo(); var context = new BuildDisplayModelContext(contentItem, "");
var ctx = new BuildDisplayModelContext(new ContentItemViewModel(foo), "");
driver1.Verify(x => x.BuildDisplayShape(ctx), Times.Never()); driver1.Verify(x => x.BuildDisplayShape(context), Times.Never());
driver2.Verify(x => x.BuildDisplayShape(ctx), Times.Never()); driver2.Verify(x => x.BuildDisplayShape(context), Times.Never());
contentHandler.BuildDisplayShape(ctx); contentHandler.BuildDisplayShape(context);
driver1.Verify(x => x.BuildDisplayShape(ctx)); driver1.Verify(x => x.BuildDisplayShape(context));
driver2.Verify(x => x.BuildDisplayShape(ctx)); driver2.Verify(x => x.BuildDisplayShape(context));
} }
[Test] [Test, Ignore("no implementation for IZoneCollection")]
public void TestDriverCanAddDisplay() { public void TestDriverCanAddDisplay() {
var driver = new StubPartDriver(); var driver = new StubPartDriver();
var builder = new ContainerBuilder(); var builder = new ContainerBuilder();
@@ -69,16 +66,12 @@ namespace Orchard.Tests.ContentManagement.Handlers.Coordinators {
var contentItem = new ContentItem(); var contentItem = new ContentItem();
contentItem.Weld(new StubPart { Foo = new[] { "a", "b", "c" } }); contentItem.Weld(new StubPart { Foo = new[] { "a", "b", "c" } });
var shape = shapeHelperFactory.CreateHelper(); var ctx = new BuildDisplayModelContext(contentItem, "");
var item = shape.Item(contentItem); var context = shapeHelperFactory.CreateHelper().Context(ctx);
Assert.That(context.TopMeta, Is.Null);
var ctx = new BuildDisplayModelContext(new ContentItemViewModel(item), "");
Assert.That(ctx.ViewModel.Zones.Count(), Is.EqualTo(0));
contentHandler.BuildDisplayShape(ctx); contentHandler.BuildDisplayShape(ctx);
Assert.That(ctx.ViewModel.Zones.Count(), Is.EqualTo(1)); Assert.That(context.TopMeta, Is.Not.Null);
Assert.That(ctx.ViewModel.Zones.Single().Key, Is.EqualTo("topmeta")); Assert.That(context.TopMeta.Count == 1);
Assert.That(ctx.ViewModel.Zones.Single().Value.Items.OfType<ContentPartDisplayZoneItem>().Single().Prefix, Is.EqualTo("Stub"));
} }
public class StubPartDriver : ContentPartDriver<StubPart> { public class StubPartDriver : ContentPartDriver<StubPart> {
@@ -89,9 +82,9 @@ namespace Orchard.Tests.ContentManagement.Handlers.Coordinators {
protected override DriverResult Display(StubPart part, string displayType) { protected override DriverResult Display(StubPart part, string displayType) {
var viewModel = new StubViewModel { Foo = string.Join(",", part.Foo) }; var viewModel = new StubViewModel { Foo = string.Join(",", part.Foo) };
if (displayType.StartsWith("Summary")) if (displayType.StartsWith("Summary"))
return ContentPartTemplate(viewModel, "StubViewModelTerse").Location("topmeta"); return ContentPartTemplate(viewModel, "StubViewModelTerse").Location("TopMeta");
return ContentPartTemplate(viewModel).Location("topmeta"); return ContentPartTemplate(viewModel).Location("TopMeta");
} }
protected override DriverResult Editor(StubPart part) { protected override DriverResult Editor(StubPart part) {

View File

@@ -1,10 +1,9 @@
using Orchard.ContentManagement.Handlers; using Orchard.ContentManagement.Handlers;
using Orchard.ContentManagement.ViewModels;
namespace Orchard.Tests.ContentManagement.Models { namespace Orchard.Tests.ContentManagement.Models {
public class AlphaHandler : ContentHandler { public class AlphaHandler : ContentHandler {
public AlphaHandler() { public AlphaHandler() {
OnGetDisplayShape<Alpha>((ctx, part) => ctx.AddDisplay(new TemplateViewModel(part) { Position = "3" })); OnGetDisplayShape<Alpha>((ctx, part) => ctx.ContentItem.Zones["Main"].Add(part, "3"));
} }
protected override void Activating(ActivatingContentContext context) { protected override void Activating(ActivatingContentContext context) {

View File

@@ -1,10 +1,9 @@
using Orchard.ContentManagement.Handlers; using Orchard.ContentManagement.Handlers;
using Orchard.ContentManagement.ViewModels;
namespace Orchard.Tests.ContentManagement.Models { namespace Orchard.Tests.ContentManagement.Models {
public class FlavoredHandler : ContentHandler { public class FlavoredHandler : ContentHandler {
public FlavoredHandler() { public FlavoredHandler() {
OnGetDisplayShape<Flavored>((ctx, part) => ctx.AddDisplay(new TemplateViewModel(part))); OnGetDisplayShape<Flavored>((ctx, part) => ctx.ContentItem.Zones["Main"].Add(part));
} }
protected override void Activating(ActivatingContentContext context) { protected override void Activating(ActivatingContentContext context) {
if (context.ContentType == "beta" || context.ContentType == "alpha") { if (context.ContentType == "beta" || context.ContentType == "alpha") {

View File

@@ -1,10 +1,9 @@
using Orchard.ContentManagement.Handlers; using Orchard.ContentManagement.Handlers;
using Orchard.ContentManagement.ViewModels;
namespace Orchard.Tests.ContentManagement.Models { namespace Orchard.Tests.ContentManagement.Models {
public class StyledHandler : ContentHandler { public class StyledHandler : ContentHandler {
public StyledHandler() { public StyledHandler() {
OnGetDisplayShape<Styled>((ctx, part) => ctx.AddDisplay(new TemplateViewModel(part) { Position = "10" })); OnGetDisplayShape<Styled>((ctx, part) => ctx.ContentItem.Zones["Main"].Add(part, "10"));
} }
protected override void Activating(ActivatingContentContext context) { protected override void Activating(ActivatingContentContext context) {

View File

@@ -4,7 +4,6 @@ using System.Web.Routing;
using Moq; using Moq;
using NUnit.Framework; using NUnit.Framework;
using Orchard.Localization; using Orchard.Localization;
using Orchard.Mvc.ViewModels;
using Orchard.Security; using Orchard.Security;
using Orchard.Tests.Stubs; using Orchard.Tests.Stubs;
using Orchard.UI.Admin; using Orchard.UI.Admin;

View File

@@ -3,7 +3,6 @@ using System.Web.Routing;
using Moq; using Moq;
using NUnit.Framework; using NUnit.Framework;
using Orchard.Localization; using Orchard.Localization;
using Orchard.Mvc.ViewModels;
using Orchard.Tests.Stubs; using Orchard.Tests.Stubs;
using Orchard.UI.Notify; using Orchard.UI.Notify;

View File

@@ -1,6 +1,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Web;
using JetBrains.Annotations; using JetBrains.Annotations;
using Orchard.ContentManagement; using Orchard.ContentManagement;
using Orchard.ContentManagement.Aspects; using Orchard.ContentManagement.Aspects;
@@ -37,7 +38,7 @@ namespace Orchard.Core.Common.Drivers {
// \/\/ Hackalicious 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(BodyPart part, string displayType) { protected override DriverResult Display(BodyPart part, string displayType) {
var bodyText = _htmlFilters.Aggregate(part.Text, (text, filter) => filter.ProcessContent(text)); var bodyText = _htmlFilters.Aggregate(part.Text, (text, filter) => filter.ProcessContent(text));
var model = new BodyDisplayViewModel { BodyPart = part, Text = bodyText }; var model = new BodyDisplayViewModel { BodyPart = part, Html = new HtmlString(bodyText) };
var location = part.GetLocation(displayType); var location = part.GetLocation(displayType);
return Combined( return Combined(

View File

@@ -1,8 +1,9 @@
using Orchard.Core.Common.Models; using System.Web;
using Orchard.Core.Common.Models;
namespace Orchard.Core.Common.ViewModels { namespace Orchard.Core.Common.ViewModels {
public class BodyDisplayViewModel { public class BodyDisplayViewModel {
public BodyPart BodyPart { get; set; } public BodyPart BodyPart { get; set; }
public string Text { get; set; } public IHtmlString Html { get; set; }
} }
} }

View File

@@ -12,10 +12,10 @@ using Orchard.Core.Common.Models;
using Orchard.Core.Contents.Settings; using Orchard.Core.Contents.Settings;
using Orchard.Core.Contents.ViewModels; using Orchard.Core.Contents.ViewModels;
using Orchard.Data; using Orchard.Data;
using Orchard.DisplayManagement;
using Orchard.Localization; using Orchard.Localization;
using Orchard.Logging; using Orchard.Logging;
using Orchard.Mvc.Results; using Orchard.Mvc.Results;
using Orchard.Mvc.ViewModels;
using Orchard.UI.Notify; using Orchard.UI.Notify;
namespace Orchard.Core.Contents.Controllers { namespace Orchard.Core.Contents.Controllers {
@@ -29,15 +29,18 @@ namespace Orchard.Core.Contents.Controllers {
IOrchardServices orchardServices, IOrchardServices orchardServices,
IContentManager contentManager, IContentManager contentManager,
IContentDefinitionManager contentDefinitionManager, IContentDefinitionManager contentDefinitionManager,
ITransactionManager transactionManager) { ITransactionManager transactionManager,
IShapeHelperFactory shapeHelperFactory) {
Services = orchardServices; Services = orchardServices;
_contentManager = contentManager; _contentManager = contentManager;
_contentDefinitionManager = contentDefinitionManager; _contentDefinitionManager = contentDefinitionManager;
_transactionManager = transactionManager; _transactionManager = transactionManager;
T = NullLocalizer.Instance; T = NullLocalizer.Instance;
Logger = NullLogger.Instance; Logger = NullLogger.Instance;
Shape = shapeHelperFactory.CreateHelper();
} }
dynamic Shape { get; set; }
public IOrchardServices Services { get; private set; } public IOrchardServices Services { get; private set; }
public Localizer T { get; set; } public Localizer T { get; set; }
public ILogger Logger { get; set; } public ILogger Logger { get; set; }
@@ -110,7 +113,7 @@ namespace Orchard.Core.Contents.Controllers {
.Select(ctd => new KeyValuePair<string, string>(ctd.Name, ctd.DisplayName)) .Select(ctd => new KeyValuePair<string, string>(ctd.Name, ctd.DisplayName))
.ToList().OrderBy(kvp => kvp.Key); .ToList().OrderBy(kvp => kvp.Key);
return View("List", model); return View(Shape.Model(model));
} }
private IEnumerable<ContentTypeDefinition> GetCreatableTypes() { private IEnumerable<ContentTypeDefinition> GetCreatableTypes() {
@@ -188,9 +191,8 @@ namespace Orchard.Core.Contents.Controllers {
private ListContentsViewModel.Entry BuildEntry(ContentItem contentItem) { private ListContentsViewModel.Entry BuildEntry(ContentItem contentItem) {
var entry = new ListContentsViewModel.Entry { var entry = new ListContentsViewModel.Entry {
ContentItem = contentItem, ContentItem = _contentManager.BuildDisplayModel(contentItem, "SummaryAdmin"),
ContentItemMetadata = _contentManager.GetItemMetadata(contentItem), ContentItemMetadata = _contentManager.GetItemMetadata(contentItem),
ViewModel = _contentManager.BuildDisplayShape(contentItem, "SummaryAdmin"),
}; };
if (string.IsNullOrEmpty(entry.ContentItemMetadata.DisplayText)) { if (string.IsNullOrEmpty(entry.ContentItemMetadata.DisplayText)) {
entry.ContentItemMetadata.DisplayText = string.Format("[{0}#{1}]", contentItem.ContentType, contentItem.Id); entry.ContentItemMetadata.DisplayText = string.Format("[{0}#{1}]", contentItem.ContentType, contentItem.Id);
@@ -207,11 +209,7 @@ namespace Orchard.Core.Contents.Controllers {
} }
ActionResult CreatableTypeList() { ActionResult CreatableTypeList() {
var model = new ListContentTypesViewModel { return View(Shape.Model(Types: GetCreatableTypes()));
Types = GetCreatableTypes()
};
return View("CreatableTypeList", model);
} }
public ActionResult Create(string id) { public ActionResult Create(string id) {
@@ -223,35 +221,32 @@ namespace Orchard.Core.Contents.Controllers {
if (!Services.Authorizer.Authorize(Permissions.PublishContent, contentItem, T("Cannot create content"))) if (!Services.Authorizer.Authorize(Permissions.PublishContent, contentItem, T("Cannot create content")))
return new HttpUnauthorizedResult(); return new HttpUnauthorizedResult();
var model = new CreateItemViewModel { var model = _contentManager.BuildEditorModel(contentItem);
Id = id, return View(Shape.Model(Content: model));
Content = _contentManager.BuildEditorShape(contentItem)
};
PrepareEditorViewModel(model.Content);
return View("Create", model);
} }
[HttpPost] [HttpPost, ActionName("Create")]
public ActionResult Create(CreateItemViewModel model) { public ActionResult CreatePOST(string id) {
var contentItem = _contentManager.New(model.Id); var contentItem = _contentManager.New(id);
if (!Services.Authorizer.Authorize(Permissions.PublishContent, contentItem, T("Couldn't create content"))) if (!Services.Authorizer.Authorize(Permissions.PublishContent, contentItem, T("Couldn't create content")))
return new HttpUnauthorizedResult(); return new HttpUnauthorizedResult();
_contentManager.Create(contentItem, VersionOptions.Draft); _contentManager.Create(contentItem, VersionOptions.Draft);
model.Content = _contentManager.UpdateEditorShape(contentItem, this); var model = _contentManager.UpdateEditorModel(contentItem, this);
if (!ModelState.IsValid) { if (!ModelState.IsValid) {
_transactionManager.Cancel(); _transactionManager.Cancel();
PrepareEditorViewModel(model.Content); return View(Shape.Model(Content: model));
return View("Create", model);
} }
if (!contentItem.Has<IPublishingControlAspect>()) if (!contentItem.Has<IPublishingControlAspect>())
_contentManager.Publish(contentItem); _contentManager.Publish(contentItem);
Services.Notifier.Information(string.IsNullOrWhiteSpace(model.Content.Item.TypeDefinition.DisplayName) ? T("Your content has been created.") : T("Your {0} has been created.", model.Content.Item.TypeDefinition.DisplayName)); Services.Notifier.Information(string.IsNullOrWhiteSpace(model.TypeDefinition.DisplayName)
? T("Your content has been created.")
: T("Your {0} has been created.", model.TypeDefinition.DisplayName));
return RedirectToAction("Edit", new RouteValueDictionary { { "Id", contentItem.Id } }); return RedirectToAction("Edit", new RouteValueDictionary { { "Id", contentItem.Id } });
} }
@@ -264,19 +259,14 @@ namespace Orchard.Core.Contents.Controllers {
if (!Services.Authorizer.Authorize(Permissions.EditOthersContent, contentItem, T("Cannot edit content"))) if (!Services.Authorizer.Authorize(Permissions.EditOthersContent, contentItem, T("Cannot edit content")))
return new HttpUnauthorizedResult(); return new HttpUnauthorizedResult();
var model = new EditItemViewModel { var model = _contentManager.BuildEditorModel(contentItem);
Id = id,
Content = _contentManager.BuildEditorShape(contentItem)
};
PrepareEditorViewModel(model.Content); return View(Shape.Model(Content: model));
return View("Edit", model);
} }
[HttpPost] [HttpPost, ActionName("Edit")]
public ActionResult Edit(EditItemViewModel model) { public ActionResult EditPOST(int id) {
var contentItem = _contentManager.Get(model.Id, VersionOptions.DraftRequired); var contentItem = _contentManager.Get(id, VersionOptions.DraftRequired);
if (contentItem == null) if (contentItem == null)
return new NotFoundResult(); return new NotFoundResult();
@@ -284,18 +274,19 @@ namespace Orchard.Core.Contents.Controllers {
if (!Services.Authorizer.Authorize(Permissions.EditOthersContent, contentItem, T("Couldn't edit content"))) if (!Services.Authorizer.Authorize(Permissions.EditOthersContent, contentItem, T("Couldn't edit content")))
return new HttpUnauthorizedResult(); return new HttpUnauthorizedResult();
model.Content = _contentManager.UpdateEditorShape(contentItem, this); var model = _contentManager.UpdateEditorModel(contentItem, this);
if (!ModelState.IsValid) { if (!ModelState.IsValid) {
_transactionManager.Cancel(); _transactionManager.Cancel();
PrepareEditorViewModel(model.Content); return View("Edit", Shape.Model(Content: model));
return View("Edit", model);
} }
//need to go about this differently - to know when to publish (IPlublishableAspect ?) //need to go about this differently - to know when to publish (IPlublishableAspect ?)
if (!contentItem.Has<IPublishingControlAspect>()) if (!contentItem.Has<IPublishingControlAspect>())
_contentManager.Publish(contentItem); _contentManager.Publish(contentItem);
Services.Notifier.Information(string.IsNullOrWhiteSpace(model.Content.Item.TypeDefinition.DisplayName) ? T("Your content has been saved.") : T("Your {0} has been saved.", model.Content.Item.TypeDefinition.DisplayName)); Services.Notifier.Information(string.IsNullOrWhiteSpace(model.TypeDefinition.DisplayName)
? T("Your content has been saved.")
: T("Your {0} has been saved.", model.TypeDefinition.DisplayName));
return RedirectToAction("Edit", new RouteValueDictionary { { "Id", contentItem.Id } }); return RedirectToAction("Edit", new RouteValueDictionary { { "Id", contentItem.Id } });
} }
@@ -308,7 +299,9 @@ namespace Orchard.Core.Contents.Controllers {
if (contentItem != null) { if (contentItem != null) {
_contentManager.Remove(contentItem); _contentManager.Remove(contentItem);
Services.Notifier.Information(string.IsNullOrWhiteSpace(contentItem.TypeDefinition.DisplayName) ? T("That content has been removed.") : T("That {0} has been removed.", contentItem.TypeDefinition.DisplayName)); Services.Notifier.Information(string.IsNullOrWhiteSpace(contentItem.TypeDefinition.DisplayName)
? T("That content has been removed.")
: T("That {0} has been removed.", contentItem.TypeDefinition.DisplayName));
} }
if (!String.IsNullOrEmpty(returnUrl)) if (!String.IsNullOrEmpty(returnUrl))
@@ -355,12 +348,6 @@ namespace Orchard.Core.Contents.Controllers {
return RedirectToAction("List"); return RedirectToAction("List");
} }
private static void PrepareEditorViewModel(ContentItemViewModel itemViewModel) {
if (string.IsNullOrEmpty(itemViewModel.TemplateName)) {
itemViewModel.TemplateName = "Items/Contents.Item";
}
}
bool IUpdateModel.TryUpdateModel<TModel>(TModel model, string prefix, string[] includeProperties, string[] excludeProperties) { bool IUpdateModel.TryUpdateModel<TModel>(TModel model, string prefix, string[] includeProperties, string[] excludeProperties) {
return TryUpdateModel(model, prefix, includeProperties, excludeProperties); return TryUpdateModel(model, prefix, includeProperties, excludeProperties);
} }

View File

@@ -1,8 +1,6 @@
using System.Web.Mvc; using System.Web.Mvc;
using Orchard.ContentManagement; using Orchard.ContentManagement;
using Orchard.Core.Contents.ViewModels;
using Orchard.DisplayManagement; using Orchard.DisplayManagement;
using Orchard.Mvc.ViewModels;
namespace Orchard.Core.Contents.Controllers { namespace Orchard.Core.Contents.Controllers {
public class ItemController : Controller { public class ItemController : Controller {
@@ -18,12 +16,8 @@ namespace Orchard.Core.Contents.Controllers {
// /Contents/Item/Display/72 // /Contents/Item/Display/72
public ActionResult Display(int id) { public ActionResult Display(int id) {
var contentItem = _contentManager.Get(id, VersionOptions.Published); var contentItem = _contentManager.Get(id, VersionOptions.Published);
var model = _contentManager.BuildDisplayModel(contentItem, "Detail");
var model = Shape.Content( return View(Shape.Model(model));
_contentManager.BuildDisplayShape(contentItem, "Detail")
);
//PrepareDisplayViewModel(model.Content);
return View(model);
} }
// /Contents/Item/Preview/72 // /Contents/Item/Preview/72
@@ -35,18 +29,8 @@ namespace Orchard.Core.Contents.Controllers {
} }
var contentItem = _contentManager.Get(id, versionOptions); var contentItem = _contentManager.Get(id, versionOptions);
var model = _contentManager.BuildDisplayModel(contentItem, "Detail");
var model = new DisplayItemViewModel { return View(Shape.Model(model));
Content = _contentManager.BuildDisplayShape(contentItem, "Detail")
};
PrepareDisplayViewModel(model.Content);
return View("Preview", model);
}
private static void PrepareDisplayViewModel(ContentItemViewModel itemViewModel) {
if (string.IsNullOrEmpty(itemViewModel.TemplateName)) {
itemViewModel.TemplateName = "Items/Contents.Item";
}
} }
} }
} }

View File

@@ -1,8 +1,8 @@
using Orchard.Mvc.ViewModels; namespace Orchard.Core.Contents.ViewModels {
#if REFACTORING
namespace Orchard.Core.Contents.ViewModels {
public class CreateItemViewModel { public class CreateItemViewModel {
public string Id { get; set; } public string Id { get; set; }
public ContentItemViewModel Content { get; set; } public ContentItemViewModel Content { get; set; }
} }
#endif
} }

View File

@@ -1,6 +1,5 @@
using Orchard.Mvc.ViewModels; namespace Orchard.Core.Contents.ViewModels {
#if REFACTORING
namespace Orchard.Core.Contents.ViewModels {
public class EditItemViewModel { public class EditItemViewModel {
public int Id { get; set; } public int Id { get; set; }
public ContentItemViewModel Content { get; set; } public ContentItemViewModel Content { get; set; }
@@ -8,4 +7,5 @@ namespace Orchard.Core.Contents.ViewModels {
public class DisplayItemViewModel { public class DisplayItemViewModel {
public ContentItemViewModel Content { get; set; } public ContentItemViewModel Content { get; set; }
} }
#endif
} }

View File

@@ -1,6 +1,5 @@
using System.Collections.Generic; using System.Collections.Generic;
using Orchard.ContentManagement; using Orchard.ContentManagement;
using Orchard.Mvc.ViewModels;
namespace Orchard.Core.Contents.ViewModels { namespace Orchard.Core.Contents.ViewModels {
public class ListContentsViewModel { public class ListContentsViewModel {
@@ -25,7 +24,6 @@ namespace Orchard.Core.Contents.ViewModels {
public class Entry { public class Entry {
public ContentItem ContentItem { get; set; } public ContentItem ContentItem { get; set; }
public ContentItemMetadata ContentItemMetadata { get; set; } public ContentItemMetadata ContentItemMetadata { get; set; }
public ContentItemViewModel ViewModel { get; set; }
} }
#endregion #endregion

View File

@@ -0,0 +1,11 @@
@model dynamic
<section style="background:#AAA;color:#000;padding:10px;">
<h1>HomePage shape template</h1>
<h2>I am the home page</h2>
<dl>
<dt>content item id</dt>
<dd>@Display(Model.Id)</dd>
<dt>the hard way to get at the raw body text</dt>
<dd>@Display(Model.Parts[3].Text)</dd>
</dl>
</section>

View File

@@ -7,10 +7,10 @@ using Orchard.Core.Localization.Models;
using Orchard.Core.Localization.Services; using Orchard.Core.Localization.Services;
using Orchard.Core.Localization.ViewModels; using Orchard.Core.Localization.ViewModels;
using Orchard.Core.Routable.Models; using Orchard.Core.Routable.Models;
using Orchard.DisplayManagement;
using Orchard.Localization; using Orchard.Localization;
using Orchard.Localization.Services; using Orchard.Localization.Services;
using Orchard.Mvc.Results; using Orchard.Mvc.Results;
using Orchard.Mvc.ViewModels;
using Orchard.UI.Notify; using Orchard.UI.Notify;
namespace Orchard.Core.Localization.Controllers { namespace Orchard.Core.Localization.Controllers {
@@ -20,14 +20,21 @@ namespace Orchard.Core.Localization.Controllers {
private readonly ICultureManager _cultureManager; private readonly ICultureManager _cultureManager;
private readonly ILocalizationService _localizationService; private readonly ILocalizationService _localizationService;
public AdminController(IOrchardServices orchardServices, IContentManager contentManager, ICultureManager cultureManager, ILocalizationService localizationService) { public AdminController(
IOrchardServices orchardServices,
IContentManager contentManager,
ICultureManager cultureManager,
ILocalizationService localizationService,
IShapeHelperFactory shapeHelperFactory) {
_contentManager = contentManager; _contentManager = contentManager;
_cultureManager = cultureManager; _cultureManager = cultureManager;
_localizationService = localizationService; _localizationService = localizationService;
T = NullLocalizer.Instance; T = NullLocalizer.Instance;
Services = orchardServices; Services = orchardServices;
Shape = shapeHelperFactory.CreateHelper();
} }
dynamic Shape { get; set; }
public Localizer T { get; set; } public Localizer T { get; set; }
public IOrchardServices Services { get; set; } public IOrchardServices Services { get; set; }
@@ -60,12 +67,11 @@ namespace Orchard.Core.Localization.Controllers {
Id = id, Id = id,
SelectedCulture = selectedCulture, SelectedCulture = selectedCulture,
SiteCultures = siteCultures, SiteCultures = siteCultures,
Content = _contentManager.BuildEditorShape(contentItem) Content = _contentManager.BuildEditorModel(contentItem)
}; };
Services.TransactionManager.Cancel(); Services.TransactionManager.Cancel();
PrepareEditorViewModel(model.Content); return View(Shape.Model(model));
return View(model);
} }
[HttpPost, ActionName("Translate")] [HttpPost, ActionName("Translate")]
@@ -75,11 +81,11 @@ namespace Orchard.Core.Localization.Controllers {
if (contentItem == null) if (contentItem == null)
return new NotFoundResult(); return new NotFoundResult();
var viewModel = new AddLocalizationViewModel(); var model = new AddLocalizationViewModel();
TryUpdateModel(viewModel); TryUpdateModel(model);
ContentItem contentItemTranslation = null; ContentItem contentItemTranslation = null;
var existingTranslation = _localizationService.GetLocalizedContentItem(contentItem, viewModel.SelectedCulture); var existingTranslation = _localizationService.GetLocalizedContentItem(contentItem, model.SelectedCulture);
if (existingTranslation != null) { if (existingTranslation != null) {
// edit existing // edit existing
contentItemTranslation = _contentManager.Get(existingTranslation.ContentItem.Id, VersionOptions.DraftRequired); contentItemTranslation = _contentManager.Get(existingTranslation.ContentItem.Id, VersionOptions.DraftRequired);
@@ -89,8 +95,8 @@ namespace Orchard.Core.Localization.Controllers {
contentItemTranslation = _contentManager.New(contentItem.ContentType); contentItemTranslation = _contentManager.New(contentItem.ContentType);
var localized = contentItemTranslation.As<LocalizationPart>(); var localized = contentItemTranslation.As<LocalizationPart>();
localized.MasterContentItem = contentItem; localized.MasterContentItem = contentItem;
if (!string.IsNullOrWhiteSpace(viewModel.SelectedCulture)) if (!string.IsNullOrWhiteSpace(model.SelectedCulture))
localized.Culture = _cultureManager.GetCultureByName(viewModel.SelectedCulture); localized.Culture = _cultureManager.GetCultureByName(model.SelectedCulture);
_contentManager.Create(contentItemTranslation, VersionOptions.Draft); _contentManager.Create(contentItemTranslation, VersionOptions.Draft);
if (!contentItem.Has<IPublishingControlAspect>() && contentItem.VersionRecord != null && contentItem.VersionRecord.Published) { if (!contentItem.Has<IPublishingControlAspect>() && contentItem.VersionRecord != null && contentItem.VersionRecord.Published) {
@@ -98,32 +104,25 @@ namespace Orchard.Core.Localization.Controllers {
} }
} }
viewModel.Content = _contentManager.UpdateEditorShape(contentItemTranslation, this); model.Content = _contentManager.UpdateEditorModel(contentItemTranslation, this);
if (!ModelState.IsValid) { if (!ModelState.IsValid) {
Services.TransactionManager.Cancel(); Services.TransactionManager.Cancel();
viewModel.SiteCultures = _cultureManager.ListCultures().Where(s => s != _localizationService.GetContentCulture(contentItem) && s != _cultureManager.GetSiteCulture()); model.SiteCultures = _cultureManager.ListCultures().Where(s => s != _localizationService.GetContentCulture(contentItem) && s != _cultureManager.GetSiteCulture());
contentItem.As<LocalizationPart>().Culture.Culture = null; contentItem.As<LocalizationPart>().Culture.Culture = null;
viewModel.Content = _contentManager.BuildEditorShape(contentItem); model.Content = _contentManager.BuildEditorModel(contentItem);
PrepareEditorViewModel(viewModel.Content); return View(Shape.Model(model));
return View(viewModel);
} }
Services.Notifier.Information(T("Created content item translation.")); Services.Notifier.Information(T("Created content item translation."));
var metadata = _contentManager.GetItemMetadata(viewModel.Content.Item); var metadata = _contentManager.GetItemMetadata(model.Content);
if (metadata.EditorRouteValues == null) if (metadata.EditorRouteValues == null)
return null; //todo: (heskew) redirect to somewhere better than nowhere return null; //todo: (heskew) redirect to somewhere better than nowhere
return RedirectToRoute(metadata.EditorRouteValues); return RedirectToRoute(metadata.EditorRouteValues);
} }
private static void PrepareEditorViewModel(ContentItemViewModel itemViewModel) {
if (string.IsNullOrEmpty(itemViewModel.TemplateName)) {
itemViewModel.TemplateName = "Items/Contents.Item";
}
}
bool IUpdateModel.TryUpdateModel<TModel>(TModel model, string prefix, string[] includeProperties, string[] excludeProperties) { bool IUpdateModel.TryUpdateModel<TModel>(TModel model, string prefix, string[] includeProperties, string[] excludeProperties) {
return TryUpdateModel(model, prefix, includeProperties, excludeProperties); return TryUpdateModel(model, prefix, includeProperties, excludeProperties);
} }

View File

@@ -1,6 +1,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using Orchard.Mvc.ViewModels; using Orchard.ContentManagement;
namespace Orchard.Core.Localization.ViewModels { namespace Orchard.Core.Localization.ViewModels {
public class AddLocalizationViewModel { public class AddLocalizationViewModel {
@@ -8,6 +8,6 @@ namespace Orchard.Core.Localization.ViewModels {
[Required] [Required]
public string SelectedCulture { get; set; } public string SelectedCulture { get; set; }
public IEnumerable<string> SiteCultures { get; set; } public IEnumerable<string> SiteCultures { get; set; }
public ContentItemViewModel Content { get; set; } public IContent Content { get; set; }
} }
} }

View File

@@ -6,6 +6,7 @@ using Orchard.Core.Navigation.Drivers;
using Orchard.Core.Navigation.Models; using Orchard.Core.Navigation.Models;
using Orchard.Core.Navigation.Services; using Orchard.Core.Navigation.Services;
using Orchard.Core.Navigation.ViewModels; using Orchard.Core.Navigation.ViewModels;
using Orchard.DisplayManagement;
using Orchard.Localization; using Orchard.Localization;
using Orchard.Mvc.AntiForgery; using Orchard.Mvc.AntiForgery;
using Orchard.UI.Navigation; using Orchard.UI.Navigation;
@@ -18,13 +19,19 @@ namespace Orchard.Core.Navigation.Controllers {
private readonly IOrchardServices _services; private readonly IOrchardServices _services;
private readonly INavigationManager _navigationManager; private readonly INavigationManager _navigationManager;
public AdminController(IMenuService menuService, IOrchardServices services, INavigationManager navigationManager) { public AdminController(
IMenuService menuService,
IOrchardServices services,
INavigationManager navigationManager,
IShapeHelperFactory shapeHelperFactory) {
_menuService = menuService; _menuService = menuService;
_services = services; _services = services;
_navigationManager = navigationManager; _navigationManager = navigationManager;
T = NullLocalizer.Instance; T = NullLocalizer.Instance;
Shape = shapeHelperFactory.CreateHelper();
} }
dynamic Shape { get; set; }
public Localizer T { get; set; } public Localizer T { get; set; }
public ActionResult Index(NavigationManagementViewModel model) { public ActionResult Index(NavigationManagementViewModel model) {
@@ -37,7 +44,7 @@ namespace Orchard.Core.Navigation.Controllers {
if (model.MenuItemEntries == null || model.MenuItemEntries.Count() < 1) if (model.MenuItemEntries == null || model.MenuItemEntries.Count() < 1)
model.MenuItemEntries = _menuService.Get().Select(menuPart => CreateMenuItemEntries(menuPart)).OrderBy(menuPartEntry => menuPartEntry.MenuItem.Position, new PositionComparer()).ToList(); model.MenuItemEntries = _menuService.Get().Select(menuPart => CreateMenuItemEntries(menuPart)).OrderBy(menuPartEntry => menuPartEntry.MenuItem.Position, new PositionComparer()).ToList();
return View("Index", model); return View(Shape.Model(model));
} }
[HttpPost, ActionName("Index")] [HttpPost, ActionName("Index")]
@@ -81,7 +88,7 @@ namespace Orchard.Core.Navigation.Controllers {
return new HttpUnauthorizedResult(); return new HttpUnauthorizedResult();
var menuPart = _services.ContentManager.New<MenuPart>("MenuItem"); var menuPart = _services.ContentManager.New<MenuPart>("MenuItem");
model.MenuItem = _services.ContentManager.UpdateEditorShape(menuPart, this); model.MenuItem = _services.ContentManager.UpdateEditorModel(menuPart, this);
if (!ModelState.IsValid) { if (!ModelState.IsValid) {
_services.TransactionManager.Cancel(); _services.TransactionManager.Cancel();
@@ -92,7 +99,7 @@ namespace Orchard.Core.Navigation.Controllers {
menuPart.MenuPosition = Position.GetNext(_navigationManager.BuildMenu("main")); menuPart.MenuPosition = Position.GetNext(_navigationManager.BuildMenu("main"));
menuPart.OnMainMenu = true; menuPart.OnMainMenu = true;
_services.ContentManager.Create(model.MenuItem.Item.ContentItem); _services.ContentManager.Create(model.MenuItem);
return RedirectToAction("Index"); return RedirectToAction("Index");
} }

View File

@@ -1,8 +1,7 @@
using Orchard.Core.Navigation.Models; using Orchard.ContentManagement;
using Orchard.Mvc.ViewModels;
namespace Orchard.Core.Navigation.ViewModels { namespace Orchard.Core.Navigation.ViewModels {
public class CreateMenuItemViewModel { public class CreateMenuItemViewModel {
public ContentItemViewModel<MenuPart> MenuItem { get; set; } public IContent MenuItem { get; set; }
} }
} }

View File

@@ -376,6 +376,7 @@
<Content Include="Messaging\Views\Web.config" /> <Content Include="Messaging\Views\Web.config" />
<None Include="Contents\Views\Content.cshtml" /> <None Include="Contents\Views\Content.cshtml" />
<None Include="Contents\Views\Item\Display.cshtml" /> <None Include="Contents\Views\Item\Display.cshtml" />
<None Include="HomePage\Views\HomePage.cshtml" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" /> <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />

View File

@@ -1,27 +1,29 @@
using System.Linq; using System.Linq;
using System.Web.Mvc; using System.Web.Mvc;
using Orchard.Core.Reports.ViewModels; using Orchard.Core.Reports.ViewModels;
using Orchard.Mvc.ViewModels; using Orchard.DisplayManagement;
using Orchard.Reports.Services; using Orchard.Reports.Services;
namespace Orchard.Core.Reports.Controllers { namespace Orchard.Core.Reports.Controllers {
public class AdminController : Controller { public class AdminController : Controller {
private readonly IReportsManager _reportsManager; private readonly IReportsManager _reportsManager;
public AdminController(IReportsManager reportsManager) { public AdminController(IReportsManager reportsManager, IShapeHelperFactory shapeHelperFactory) {
_reportsManager = reportsManager; _reportsManager = reportsManager;
} }
dynamic Shape { get; set; }
public ActionResult Index() { public ActionResult Index() {
var model = new ReportsAdminIndexViewModel { Reports = _reportsManager.GetReports().ToList() }; var model = new ReportsAdminIndexViewModel { Reports = _reportsManager.GetReports().ToList() };
return View(model); return View(Shape.Model(model));
} }
public ActionResult Display(int id) { public ActionResult Display(int id) {
var model = new DisplayReportViewModel { Report = _reportsManager.Get(id) }; var model = new DisplayReportViewModel { Report = _reportsManager.Get(id) };
return View(model); return View(Shape.Model(model));
} }
} }

View File

@@ -3,12 +3,10 @@ using System.Linq;
using System.Web.Mvc; using System.Web.Mvc;
using Orchard.ContentManagement; using Orchard.ContentManagement;
using Orchard.ContentManagement.Aspects; using Orchard.ContentManagement.Aspects;
using Orchard.Core.Common.Models;
using Orchard.Core.Routable.Models; using Orchard.Core.Routable.Models;
using Orchard.Core.Routable.ViewModels;
using Orchard.Data; using Orchard.Data;
using Orchard.DisplayManagement;
using Orchard.Localization; using Orchard.Localization;
using Orchard.Mvc.ViewModels;
namespace Orchard.Core.Routable.Controllers { namespace Orchard.Core.Routable.Controllers {
[ValidateInput(false)] [ValidateInput(false)]
@@ -17,12 +15,15 @@ namespace Orchard.Core.Routable.Controllers {
private readonly ITransactionManager _transactionManager; private readonly ITransactionManager _transactionManager;
private readonly IRoutablePathConstraint _routablePathConstraint; private readonly IRoutablePathConstraint _routablePathConstraint;
public ItemController(IContentManager contentManager, ITransactionManager transactionManager, IRoutablePathConstraint routablePathConstraint) { public ItemController(IContentManager contentManager, ITransactionManager transactionManager, IRoutablePathConstraint routablePathConstraint, IShapeHelperFactory shapeHelperFactory) {
_contentManager = contentManager; _contentManager = contentManager;
_transactionManager = transactionManager; _transactionManager = transactionManager;
_routablePathConstraint = routablePathConstraint; _routablePathConstraint = routablePathConstraint;
Shape = shapeHelperFactory.CreateHelper();
} }
dynamic Shape { get; set; }
public ActionResult Display(string path) { public ActionResult Display(string path) {
var matchedPath = _routablePathConstraint.FindPath(path); var matchedPath = _routablePathConstraint.FindPath(path);
if (string.IsNullOrEmpty(matchedPath)) { if (string.IsNullOrEmpty(matchedPath)) {
@@ -39,17 +40,9 @@ namespace Orchard.Core.Routable.Controllers {
if (hits.Count() != 1) { if (hits.Count() != 1) {
throw new ApplicationException("Ambiguous content"); throw new ApplicationException("Ambiguous content");
} }
var model = new RoutableDisplayViewModel {
Routable = _contentManager.BuildDisplayShape<IRoutableAspect>(hits.Single(), "Detail")
};
PrepareDisplayViewModel(model.Routable);
return View("Display", model);
}
private void PrepareDisplayViewModel(ContentItemViewModel<IRoutableAspect> itemViewModel) { var model = _contentManager.BuildDisplayModel<IRoutableAspect>(hits.Single(), "Detail");
if (string.IsNullOrEmpty(itemViewModel.TemplateName)) { return View(Shape.Model(model));
itemViewModel.TemplateName = "Items/Contents.Item";
}
} }
public ActionResult Slugify(string contentType, int? id, int? containerId) { public ActionResult Slugify(string contentType, int? id, int? containerId) {
@@ -71,7 +64,7 @@ namespace Orchard.Core.Routable.Controllers {
} }
} }
_contentManager.UpdateEditorShape(contentItem, this); _contentManager.UpdateEditorModel(contentItem, this);
_transactionManager.Cancel(); _transactionManager.Cancel();
return Json(contentItem.As<IRoutableAspect>().Slug ?? slug); return Json(contentItem.As<IRoutableAspect>().Slug ?? slug);

View File

@@ -2,7 +2,7 @@
using JetBrains.Annotations; using JetBrains.Annotations;
using Orchard.ContentManagement.Aspects; using Orchard.ContentManagement.Aspects;
using Orchard.Core.Routable.Models; using Orchard.Core.Routable.Models;
using Orchard.Core.Routable.ViewModels; using Orchard.DisplayManagement;
using Orchard.Localization; using Orchard.Localization;
using Orchard.Mvc.Results; using Orchard.Mvc.Results;
using Orchard.Services; using Orchard.Services;
@@ -14,12 +14,14 @@ namespace Orchard.Core.Routable.Services {
private readonly IContentManager _contentManager; private readonly IContentManager _contentManager;
public const string Name = "RoutableHomePageProvider"; public const string Name = "RoutableHomePageProvider";
public RoutableHomePageProvider(IOrchardServices services, IContentManager contentManager) { public RoutableHomePageProvider(IOrchardServices services, IContentManager contentManager, IShapeHelperFactory shapeHelperFactory) {
_contentManager = contentManager; _contentManager = contentManager;
Services = services; Services = services;
T = NullLocalizer.Instance; T = NullLocalizer.Instance;
Shape = shapeHelperFactory.CreateHelper();
} }
dynamic Shape { get; set; }
public IOrchardServices Services { get; private set; } public IOrchardServices Services { get; private set; }
public Localizer T { get; set; } public Localizer T { get; set; }
@@ -36,13 +38,11 @@ namespace Orchard.Core.Routable.Services {
if (contentItem == null || !contentItem.Is<RoutePart>()) if (contentItem == null || !contentItem.Is<RoutePart>())
return new NotFoundResult(); return new NotFoundResult();
var model = new RoutableDisplayViewModel { var model = _contentManager.BuildDisplayModel(contentItem, "Detail");
Routable = _contentManager.BuildDisplayShape<IRoutableAspect>(contentItem.As<RoutePart>(), "Detail")
};
return new ViewResult { return new ViewResult {
ViewName = "~/Core/Routable/Views/Item/Display.ascx", //ViewName = "~/Core/Routable/Views/Item/Display.ascx",
ViewData = new ViewDataDictionary<RoutableDisplayViewModel>(model) ViewData = new ViewDataDictionary<dynamic>(Shape.HomePage(model))
}; };
} }
} }

View File

@@ -1,8 +1,9 @@
using Orchard.ContentManagement.Aspects; using Orchard.ContentManagement.Aspects;
using Orchard.Mvc.ViewModels;
namespace Orchard.Core.Routable.ViewModels { namespace Orchard.Core.Routable.ViewModels {
#if REFACTORING
public class RoutableDisplayViewModel { public class RoutableDisplayViewModel {
public ContentItemViewModel<IRoutableAspect> Routable {get;set;} public ContentItemViewModel<IRoutableAspect> Routable {get;set;}
} }
#endif
} }

View File

@@ -3,6 +3,7 @@ using System.Linq;
using System.Web.Mvc; using System.Web.Mvc;
using Orchard.Core.Settings.Models; using Orchard.Core.Settings.Models;
using Orchard.Core.Settings.ViewModels; using Orchard.Core.Settings.ViewModels;
using Orchard.DisplayManagement;
using Orchard.Localization; using Orchard.Localization;
using Orchard.ContentManagement; using Orchard.ContentManagement;
using Orchard.Localization.Services; using Orchard.Localization.Services;
@@ -16,25 +17,30 @@ namespace Orchard.Core.Settings.Controllers {
private readonly ICultureManager _cultureManager; private readonly ICultureManager _cultureManager;
public IOrchardServices Services { get; private set; } public IOrchardServices Services { get; private set; }
public AdminController(ISiteService siteService, IOrchardServices services, ICultureManager cultureManager) { public AdminController(
ISiteService siteService,
IOrchardServices services,
ICultureManager cultureManager,
IShapeHelperFactory shapeHelperFactory) {
_siteService = siteService; _siteService = siteService;
_cultureManager = cultureManager; _cultureManager = cultureManager;
Services = services; Services = services;
T = NullLocalizer.Instance; T = NullLocalizer.Instance;
} }
dynamic Shape { get; set; }
public Localizer T { get; set; } public Localizer T { get; set; }
public ActionResult Index(string tabName) { public ActionResult Index(string tabName) {
if (!Services.Authorizer.Authorize(Permissions.ManageSettings, T("Not authorized to manage settings"))) if (!Services.Authorizer.Authorize(Permissions.ManageSettings, T("Not authorized to manage settings")))
return new HttpUnauthorizedResult(); return new HttpUnauthorizedResult();
var site = _siteService.GetSiteSettings().As<SiteSettingsPart>();
var model = new SettingsIndexViewModel { var model = new SettingsIndexViewModel {
Site = _siteService.GetSiteSettings().As<SiteSettingsPart>(), Site = Services.ContentManager.BuildEditorModel(site),
SiteCultures = _cultureManager.ListCultures() SiteCultures = _cultureManager.ListCultures()
}; };
model.ViewModel = Services.ContentManager.BuildEditorShape(model.Site); return View(Shape.Model(model));
return View(model);
} }
[HttpPost, ActionName("Index")] [HttpPost, ActionName("Index")]
@@ -42,11 +48,12 @@ namespace Orchard.Core.Settings.Controllers {
if (!Services.Authorizer.Authorize(Permissions.ManageSettings, T("Not authorized to manage settings"))) if (!Services.Authorizer.Authorize(Permissions.ManageSettings, T("Not authorized to manage settings")))
return new HttpUnauthorizedResult(); return new HttpUnauthorizedResult();
var viewModel = new SettingsIndexViewModel { Site = _siteService.GetSiteSettings().As<SiteSettingsPart>() }; var site = _siteService.GetSiteSettings().As<SiteSettingsPart>();
viewModel.ViewModel = Services.ContentManager.UpdateEditorShape(viewModel.Site.ContentItem, this); var model = new SettingsIndexViewModel { Site = Services.ContentManager.UpdateEditorModel(site, this) };
if (!TryUpdateModel(viewModel)) { if (!ModelState.IsValid) {
return View(viewModel); Services.TransactionManager.Cancel();
return View(Shape.Model(model));
} }
Services.Notifier.Information(T("Settings updated")); Services.Notifier.Information(T("Settings updated"));
@@ -58,15 +65,15 @@ namespace Orchard.Core.Settings.Controllers {
if (!Services.Authorizer.Authorize(Permissions.ManageSettings, T("Not authorized to manage settings"))) if (!Services.Authorizer.Authorize(Permissions.ManageSettings, T("Not authorized to manage settings")))
return new HttpUnauthorizedResult(); return new HttpUnauthorizedResult();
var viewModel = new SiteCulturesViewModel { var model = new SiteCulturesViewModel {
CurrentCulture = _cultureManager.GetCurrentCulture(HttpContext), CurrentCulture = _cultureManager.GetCurrentCulture(HttpContext),
SiteCultures = _cultureManager.ListCultures(), SiteCultures = _cultureManager.ListCultures(),
}; };
viewModel.AvailableSystemCultures = CultureInfo.GetCultures(CultureTypes.SpecificCultures) model.AvailableSystemCultures = CultureInfo.GetCultures(CultureTypes.SpecificCultures)
.Select(ci => ci.Name) .Select(ci => ci.Name)
.Where(s => !viewModel.SiteCultures.Contains(s)); .Where(s => !model.SiteCultures.Contains(s));
return View(viewModel); return View(Shape.Model(model));
} }
[HttpPost] [HttpPost]

View File

@@ -1,14 +1,12 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Web.Mvc; using System.Web.Mvc;
using Orchard.ContentManagement; using Orchard.ContentManagement;
using Orchard.Mvc.ViewModels;
using Orchard.Core.Settings.Models; using Orchard.Core.Settings.Models;
namespace Orchard.Core.Settings.ViewModels { namespace Orchard.Core.Settings.ViewModels {
public class SettingsIndexViewModel { public class SettingsIndexViewModel {
public SiteSettingsPart Site { get; set; } public SiteSettingsPart Site { get; set; }
public IEnumerable<string> SiteCultures { get; set; } public IEnumerable<string> SiteCultures { get; set; }
public ContentItemViewModel ViewModel { get; set; }
[HiddenInput(DisplayValue = false)] [HiddenInput(DisplayValue = false)]

View File

@@ -0,0 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Orchard.ContentTypes", "Orchard.ContentTypes.csproj", "{0E7646E8-FE8F-43C1-8799-D97860925EC4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{0E7646E8-FE8F-43C1-8799-D97860925EC4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0E7646E8-FE8F-43C1-8799-D97860925EC4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0E7646E8-FE8F-43C1-8799-D97860925EC4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0E7646E8-FE8F-43C1-8799-D97860925EC4}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View File

@@ -6,6 +6,7 @@ using Orchard.Data;
using Orchard.DevTools.ViewModels; using Orchard.DevTools.ViewModels;
using Orchard.ContentManagement; using Orchard.ContentManagement;
using Orchard.ContentManagement.Records; using Orchard.ContentManagement.Records;
using Orchard.DisplayManagement;
namespace Orchard.DevTools.Controllers { namespace Orchard.DevTools.Controllers {
public class ContentController : Controller { public class ContentController : Controller {
@@ -14,11 +15,14 @@ namespace Orchard.DevTools.Controllers {
public ContentController( public ContentController(
IRepository<ContentTypeRecord> contentTypeRepository, IRepository<ContentTypeRecord> contentTypeRepository,
IContentManager contentManager) { IContentManager contentManager,
IShapeHelperFactory shapeHelperFactory) {
_contentTypeRepository = contentTypeRepository; _contentTypeRepository = contentTypeRepository;
_contentManager = contentManager; _contentManager = contentManager;
} }
dynamic Shape { get; set; }
public ActionResult Index() { public ActionResult Index() {
return View(new ContentIndexViewModel { return View(new ContentIndexViewModel {
Items = _contentManager.Query().List(), Items = _contentManager.Query().List(),
@@ -34,10 +38,10 @@ namespace Orchard.DevTools.Controllers {
.Select(x => x.GetType()) .Select(x => x.GetType())
.SelectMany(x => AllTypes(x)) .SelectMany(x => AllTypes(x))
.Distinct(); .Distinct();
model.DisplayModel = _contentManager.BuildDisplayShape(model.Item, "Detail"); model.DisplayShape = _contentManager.BuildDisplayModel(model.Item, "Detail");
model.EditorModel = _contentManager.BuildEditorShape(model.Item); model.EditorShape = _contentManager.BuildEditorModel(model.Item);
return View(model); return View(Shape.Model(model));
} }
static IEnumerable<Type> AllTypes(Type type) { static IEnumerable<Type> AllTypes(Type type) {

View File

@@ -1,6 +1,5 @@
using JetBrains.Annotations; using JetBrains.Annotations;
using Orchard.ContentManagement.Handlers; using Orchard.ContentManagement.Handlers;
using Orchard.ContentManagement.ViewModels;
using Orchard.DevTools.Models; using Orchard.DevTools.Models;
namespace Orchard.DevTools.Handlers { namespace Orchard.DevTools.Handlers {
@@ -9,12 +8,12 @@ namespace Orchard.DevTools.Handlers {
protected override void BuildDisplayShape(BuildDisplayModelContext context) { protected override void BuildDisplayShape(BuildDisplayModelContext context) {
var devToolsSettings = context.ContentItem.TypeDefinition.Settings.GetModel<Settings.DevToolsSettings>(); var devToolsSettings = context.ContentItem.TypeDefinition.Settings.GetModel<Settings.DevToolsSettings>();
if (devToolsSettings.ShowDebugLinks) if (devToolsSettings.ShowDebugLinks)
context.AddDisplay(new TemplateViewModel(new ShowDebugLink { ContentItem = context.ContentItem }) { TemplateName = "Parts/DevTools.ShowDebugLink", ZoneName = "recap", Position = "9999" }); context.ContentItem.Zones["Recap"].Add(new ShowDebugLink { ContentItem = context.ContentItem }, "9999");
} }
protected override void BuildEditorShape(BuildEditorModelContext context) { protected override void BuildEditorShape(BuildEditorModelContext context) {
var devToolsSettings = context.ContentItem.TypeDefinition.Settings.GetModel<Settings.DevToolsSettings>(); var devToolsSettings = context.ContentItem.TypeDefinition.Settings.GetModel<Settings.DevToolsSettings>();
if (devToolsSettings.ShowDebugLinks) if (devToolsSettings.ShowDebugLinks)
context.AddEditor(new TemplateViewModel(new ShowDebugLink { ContentItem = context.ContentItem }) { TemplateName = "Parts/DevTools.ShowDebugLink", ZoneName = "recap", Position = "9999" }); context.ContentItem.Zones["Recap"].Add(new ShowDebugLink { ContentItem = context.ContentItem }, "9999");
} }
} }
} }

View File

@@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using Orchard.ContentManagement; using Orchard.ContentManagement;
using Orchard.ContentManagement.ViewModels; using Orchard.ContentManagement.ViewModels;
using Orchard.Mvc.ViewModels;
using Orchard.UI.Zones; using Orchard.UI.Zones;
namespace Orchard.DevTools.ViewModels { namespace Orchard.DevTools.ViewModels {
@@ -12,27 +11,13 @@ namespace Orchard.DevTools.ViewModels {
public IEnumerable<Type> PartTypes { get; set; } public IEnumerable<Type> PartTypes { get; set; }
public ContentItemViewModel DisplayModel { get; set; } public IContent DisplayShape { get; set; }
public ContentItemViewModel EditorModel { get; set; } public IContent EditorShape { get; set; }
public IEnumerable<TemplateViewModel> Displays {
get {
return DisplayModel.Zones
.SelectMany(z => z.Value.Items
.OfType<ContentPartDisplayZoneItem>()
.Select(x=>new{ZoneName=z.Key,Item=x}))
.Select(x => new TemplateViewModel(x.Item.Model,x.Item.Prefix) {
Model = x.Item.Model,
TemplateName=x.Item.TemplateName,
WasUsed=x.Item.WasExecuted,
ZoneName=x.ZoneName,
});
}
}
public IEnumerable<TemplateViewModel> Editors { public IEnumerable<TemplateViewModel> Editors {
get { get {
#if REFACTORING
return EditorModel.Zones return EditorModel.Zones
.SelectMany(z => z.Value.Items .SelectMany(z => z.Value.Items
.OfType<ContentPartEditorZoneItem>() .OfType<ContentPartEditorZoneItem>()
@@ -43,6 +28,9 @@ namespace Orchard.DevTools.ViewModels {
WasUsed = x.Item.WasExecuted, WasUsed = x.Item.WasExecuted,
ZoneName = x.ZoneName, ZoneName = x.ZoneName,
}); });
#else
return null;
#endif
} }
} }

View File

@@ -26,12 +26,10 @@ using Orchard.Mvc.ViewEngines;
using Orchard.Mvc.ViewEngines.Razor; using Orchard.Mvc.ViewEngines.Razor;
using Orchard.Mvc.ViewEngines.WebForms; using Orchard.Mvc.ViewEngines.WebForms;
using Orchard.Settings; using Orchard.Settings;
using Orchard.Setup.Commands;
using Orchard.Themes; using Orchard.Themes;
using Orchard.UI.Notify; using Orchard.UI.Notify;
using Orchard.UI.PageClass; using Orchard.UI.PageClass;
using Orchard.UI.PageTitle; using Orchard.UI.PageTitle;
using Orchard.UI.Zones;
namespace Orchard.Setup { namespace Orchard.Setup {
public class SetupMode : Module { public class SetupMode : Module {
@@ -47,7 +45,6 @@ namespace Orchard.Setup {
builder.RegisterType<ViewEngineFilter>().As<IFilterProvider>().InstancePerLifetimeScope(); builder.RegisterType<ViewEngineFilter>().As<IFilterProvider>().InstancePerLifetimeScope();
builder.RegisterType<ThemeFilter>().As<IFilterProvider>().InstancePerLifetimeScope(); builder.RegisterType<ThemeFilter>().As<IFilterProvider>().InstancePerLifetimeScope();
builder.RegisterType<PageTitleBuilder>().As<IPageTitleBuilder>().InstancePerLifetimeScope(); builder.RegisterType<PageTitleBuilder>().As<IPageTitleBuilder>().InstancePerLifetimeScope();
builder.RegisterType<ZoneManager>().As<IZoneManager>().InstancePerLifetimeScope();
builder.RegisterType<PageClassBuilder>().As<IPageClassBuilder>().InstancePerLifetimeScope(); builder.RegisterType<PageClassBuilder>().As<IPageClassBuilder>().InstancePerLifetimeScope();
builder.RegisterType<Notifier>().As<INotifier>().InstancePerLifetimeScope(); builder.RegisterType<Notifier>().As<INotifier>().InstancePerLifetimeScope();
builder.RegisterType<NotifyFilter>().As<IFilterProvider>().InstancePerLifetimeScope(); builder.RegisterType<NotifyFilter>().As<IFilterProvider>().InstancePerLifetimeScope();

View File

@@ -2,8 +2,8 @@
using System.Reflection; using System.Reflection;
using System.Web; using System.Web;
using System.Web.Mvc; using System.Web.Mvc;
using Orchard.DisplayManagement;
using Orchard.Localization; using Orchard.Localization;
using Orchard.Mvc.ViewModels;
using Orchard.Security; using Orchard.Security;
using Orchard.Themes.Preview; using Orchard.Themes.Preview;
using Orchard.Themes.ViewModels; using Orchard.Themes.ViewModels;
@@ -15,13 +15,20 @@ namespace Orchard.Themes.Controllers {
private readonly IThemeService _themeService; private readonly IThemeService _themeService;
private readonly IPreviewTheme _previewTheme; private readonly IPreviewTheme _previewTheme;
public AdminController(IOrchardServices services, IThemeService themeService, IPreviewTheme previewTheme, IAuthorizer authorizer, INotifier notifier) { public AdminController(
IOrchardServices services,
IThemeService themeService,
PreviewTheme previewTheme,
IAuthorizer authorizer,
INotifier notifier,
IShapeHelperFactory shapeHelperFactory) {
Services = services; Services = services;
_themeService = themeService; _themeService = themeService;
_previewTheme = previewTheme; _previewTheme = previewTheme;
T = NullLocalizer.Instance; T = NullLocalizer.Instance;
} }
dynamic Shape { get; set; }
public IOrchardServices Services{ get; set; } public IOrchardServices Services{ get; set; }
public Localizer T { get; set; } public Localizer T { get; set; }
@@ -30,11 +37,11 @@ namespace Orchard.Themes.Controllers {
var themes = _themeService.GetInstalledThemes(); var themes = _themeService.GetInstalledThemes();
var currentTheme = _themeService.GetSiteTheme(); var currentTheme = _themeService.GetSiteTheme();
var model = new ThemesIndexViewModel { CurrentTheme = currentTheme, Themes = themes }; var model = new ThemesIndexViewModel { CurrentTheme = currentTheme, Themes = themes };
return View(model); return View(Shape.Model(model));
} }
catch (Exception exception) { catch (Exception exception) {
Services.Notifier.Error(T("Listing themes failed: " + exception.Message)); Services.Notifier.Error(T("Listing themes failed: " + exception.Message));
return View(new ThemesIndexViewModel()); return View(Shape.Model(new ThemesIndexViewModel()));
} }
} }

View File

@@ -9,6 +9,7 @@ using Orchard.Services;
using Orchard.UI.Zones; using Orchard.UI.Zones;
namespace Orchard.Themes.DesignerNotes { namespace Orchard.Themes.DesignerNotes {
#if REFACTORING
public class ZoneManagerEvents : IZoneManagerEvents { public class ZoneManagerEvents : IZoneManagerEvents {
private readonly IThemeService _themeService; private readonly IThemeService _themeService;
private readonly IAuthorizationService _authorizationService; private readonly IAuthorizationService _authorizationService;
@@ -82,4 +83,5 @@ namespace Orchard.Themes.DesignerNotes {
public void ZoneRendered(ZoneRenderContext context) { public void ZoneRendered(ZoneRenderContext context) {
} }
} }
#endif
} }

View File

@@ -104,7 +104,7 @@
<Content Include="Views\Admin\Install.aspx" /> <Content Include="Views\Admin\Install.aspx" />
<Content Include="Views\Admin\ThemePreview.ascx" /> <Content Include="Views\Admin\ThemePreview.ascx" />
<Content Include="Views\DisplayTemplates\Items\ContentItem.ascx" /> <Content Include="Views\DisplayTemplates\Items\ContentItem.ascx" />
<Content Include="Views\Document.aspx" /> <Content Include="Views\_Document.aspx" />
<Content Include="Views\EditorTemplates\Items\ContentItem.ascx" /> <Content Include="Views\EditorTemplates\Items\ContentItem.ascx" />
<Content Include="Views\Header.ascx" /> <Content Include="Views\Header.ascx" />
<Content Include="Views\HeadPreload.ascx" /> <Content Include="Views\HeadPreload.ascx" />
@@ -128,6 +128,9 @@
<Name>Orchard.Framework</Name> <Name>Orchard.Framework</Name>
</ProjectReference> </ProjectReference>
</ItemGroup> </ItemGroup>
<ItemGroup>
<None Include="Views\Document.cshtml" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" /> <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.

View File

@@ -2,6 +2,7 @@
using Orchard.UI.Zones; using Orchard.UI.Zones;
namespace Orchard.Themes.Services { namespace Orchard.Themes.Services {
#if REFACTORING
public class ThemeZoneManagerEvents : IZoneManagerEvents { public class ThemeZoneManagerEvents : IZoneManagerEvents {
public ThemeZoneManagerEvents() { public ThemeZoneManagerEvents() {
T = NullLocalizer.Instance; T = NullLocalizer.Instance;
@@ -47,4 +48,5 @@ namespace Orchard.Themes.Services {
#endif #endif
} }
} }
#endif
} }

View File

@@ -0,0 +1,24 @@
@using Orchard.Mvc.Html
<!DOCTYPE html>
@//"en" needs to change to the current culture, btw
@//all inline styles for tmp reference only
<html lang="en" class="static" style="background:#000;color:#fff;padding:5px">
<head>
<title>Page Title@{/*View.Page.Title*/}</title>
@//could be a resource - at least need to get at the right location and this is something
<link rel="shortcut icon" type="image/x-icon" href="/modules/orchard.themes/Content/orchard.ico" />
@{
//todo: (heskew) have resource modules that can be leaned on (like a jQuery module that knows about various CDNs and jQuery's version and min naming schemes)
//todo: (heskew) this is an interim solution to inlude jQuery in every page and still allow that to be overriden in some theme by it containing a headScripts partial
}
@//Model.Zones.AddRenderPartial("head:before", "HeadPreload", Model);
@//Html.Zone("head", ":metas :styles :scripts"); %>
<script type="text/javascript">document.documentElement.className="dyn";</script>
</head>
<body class="@Html.ClassForPage()">
<section>
<h1>document template</h1>
@Html.RenderOrchardBody()
</section>
</body>
</html>

View File

@@ -2,6 +2,7 @@ using System.Linq;
using System.Web.Mvc; using System.Web.Mvc;
using JetBrains.Annotations; using JetBrains.Annotations;
using Orchard.ContentManagement; using Orchard.ContentManagement;
using Orchard.DisplayManagement;
using Orchard.Localization; using Orchard.Localization;
using Orchard.Security; using Orchard.Security;
using Orchard.Settings; using Orchard.Settings;
@@ -20,13 +21,16 @@ namespace Orchard.Users.Controllers {
public AdminController( public AdminController(
IOrchardServices services, IOrchardServices services,
IMembershipService membershipService, IMembershipService membershipService,
IUserService userService) { IUserService userService,
IShapeHelperFactory shapeHelperFactory) {
Services = services; Services = services;
_membershipService = membershipService; _membershipService = membershipService;
_userService = userService; _userService = userService;
T = NullLocalizer.Instance; T = NullLocalizer.Instance;
Shape = shapeHelperFactory.CreateHelper();
} }
dynamic Shape { get; set; }
public IOrchardServices Services { get; set; } public IOrchardServices Services { get; set; }
public Localizer T { get; set; } public Localizer T { get; set; }
protected virtual ISite CurrentSite { get; [UsedImplicitly] private set; } protected virtual ISite CurrentSite { get; [UsedImplicitly] private set; }
@@ -46,7 +50,7 @@ namespace Orchard.Users.Controllers {
.ToList() .ToList()
}; };
return View(model); return View(Shape.Model(model));
} }
public ActionResult Create() { public ActionResult Create() {
@@ -55,9 +59,9 @@ namespace Orchard.Users.Controllers {
var user = Services.ContentManager.New<IUser>("User"); var user = Services.ContentManager.New<IUser>("User");
var model = new UserCreateViewModel { var model = new UserCreateViewModel {
User = Services.ContentManager.BuildEditorShape(user) User = Services.ContentManager.BuildEditorModel(user)
}; };
return View(model); return View(Shape.Model(model));
} }
[HttpPost, ActionName("Create")] [HttpPost, ActionName("Create")]
@@ -66,10 +70,10 @@ namespace Orchard.Users.Controllers {
return new HttpUnauthorizedResult(); return new HttpUnauthorizedResult();
var user = Services.ContentManager.New<IUser>("User"); var user = Services.ContentManager.New<IUser>("User");
model.User = Services.ContentManager.UpdateEditorShape(user, this); model.User = Services.ContentManager.UpdateEditorModel(user, this);
if (!ModelState.IsValid) { if (!ModelState.IsValid) {
Services.TransactionManager.Cancel(); Services.TransactionManager.Cancel();
return View(model); return View(Shape.Model(model));
} }
string userExistsMessage = _userService.VerifyUserUnicity(model.UserName, model.Email); string userExistsMessage = _userService.VerifyUserUnicity(model.UserName, model.Email);
@@ -87,14 +91,14 @@ namespace Orchard.Users.Controllers {
model.Email, model.Email,
null, null, true)); null, null, true));
model.User = Services.ContentManager.UpdateEditorShape(user, this); model.User = Services.ContentManager.UpdateEditorModel(user, this);
if (ModelState.IsValid == false) { if (ModelState.IsValid == false) {
Services.TransactionManager.Cancel(); Services.TransactionManager.Cancel();
return View(model); return View(Shape.Model(model));
} }
return RedirectToAction("edit", new {user.Id}); return RedirectToAction("edit", new { user.Id });
} }
public ActionResult Edit(int id) { public ActionResult Edit(int id) {
@@ -122,7 +126,7 @@ namespace Orchard.Users.Controllers {
return View(model); return View(model);
} }
model.User.Item.NormalizedUserName = model.UserName.ToLower(); model.User.As<UserPart>().NormalizedUserName = model.UserName.ToLower();
string userExistsMessage = _userService.VerifyUserUnicity(id, model.UserName, model.Email); string userExistsMessage = _userService.VerifyUserUnicity(id, model.UserName, model.Email);
if (userExistsMessage != null) { if (userExistsMessage != null) {

View File

@@ -9,7 +9,7 @@ namespace Orchard.Users.Handlers {
public RegistrationSettingsPartHandler(IRepository<RegistrationSettingsPartRecord> repository) { public RegistrationSettingsPartHandler(IRepository<RegistrationSettingsPartRecord> repository) {
Filters.Add(new ActivatingFilter<RegistrationSettingsPart>("Site")); Filters.Add(new ActivatingFilter<RegistrationSettingsPart>("Site"));
Filters.Add(StorageFilter.For(repository)); Filters.Add(StorageFilter.For(repository));
Filters.Add(new TemplateFilterForRecord<RegistrationSettingsPartRecord>("RegistrationSettings", "Parts/Users.RegistrationSettings")); Filters.Add(new TemplateFilterForRecord<RegistrationSettingsPartRecord>("RegistrationSettings"));
} }
} }
} }

View File

@@ -39,6 +39,7 @@
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="Microsoft.CSharp" />
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Data" /> <Reference Include="System.Data" />
<Reference Include="System.ComponentModel.DataAnnotations"> <Reference Include="System.ComponentModel.DataAnnotations">

View File

@@ -1,6 +1,5 @@
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using Orchard.Mvc.ViewModels; using Orchard.ContentManagement;
using Orchard.Security;
namespace Orchard.Users.ViewModels { namespace Orchard.Users.ViewModels {
public class UserCreateViewModel { public class UserCreateViewModel {
@@ -16,6 +15,6 @@ namespace Orchard.Users.ViewModels {
[Required, DataType(DataType.Password)] [Required, DataType(DataType.Password)]
public string ConfirmPassword { get; set; } public string ConfirmPassword { get; set; }
public ContentItemViewModel<IUser> User { get; set; } public IContent User { get; set; }
} }
} }

View File

@@ -1,27 +1,27 @@
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.Web.Mvc; using System.Web.Mvc;
using Orchard.Mvc.ViewModels; using Orchard.ContentManagement;
using Orchard.Users.Models; using Orchard.Users.Models;
namespace Orchard.Users.ViewModels { namespace Orchard.Users.ViewModels {
public class UserEditViewModel { public class UserEditViewModel {
[HiddenInput(DisplayValue = false)] [HiddenInput(DisplayValue = false)]
public int Id { public int Id {
get { return User.Item.Id; } get { return User.ContentItem.Id; }
} }
[Required] [Required]
public string UserName { public string UserName {
get { return User.Item.Record.UserName; } get { return User.As<UserPart>().Record.UserName; }
set { User.Item.Record.UserName = value; } set { User.As<UserPart>().Record.UserName = value; }
} }
[Required] [Required]
public string Email { public string Email {
get { return User.Item.Record.Email; } get { return User.As<UserPart>().Record.Email; }
set { User.Item.Record.Email = value; } set { User.As<UserPart>().Record.Email = value; }
} }
public ContentItemViewModel<UserPart> User { get; set; } public IContent User { get; set; }
} }
} }

View File

@@ -141,6 +141,8 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Content Include="Config\Sample.Host.config" /> <Content Include="Config\Sample.Host.config" />
<None Include="Themes\Contoso\Views\HomePage\Home\Index.cshtml" />
<None Include="Themes\Contoso\Views\Layout.HomePage.cshtml" />
<None Include="Themes\TheAdmin\Styles\images\icons.psd" /> <None Include="Themes\TheAdmin\Styles\images\icons.psd" />
<Content Include="Themes\ClassicDark\Content\Images\bodyBackgroundgrey.gif" /> <Content Include="Themes\ClassicDark\Content\Images\bodyBackgroundgrey.gif" />
<Content Include="Themes\ClassicDark\Content\Images\sidebarBackground.gif" /> <Content Include="Themes\ClassicDark\Content\Images\sidebarBackground.gif" />
@@ -212,7 +214,7 @@
<Content Include="Themes\Contoso\Theme.txt" /> <Content Include="Themes\Contoso\Theme.txt" />
<Content Include="Themes\Contoso\Views\Footer.ascx" /> <Content Include="Themes\Contoso\Views\Footer.ascx" />
<Content Include="Themes\Contoso\Views\Layout.ascx" /> <Content Include="Themes\Contoso\Views\Layout.ascx" />
<Content Include="Themes\Contoso\Views\Layout.HomePage.ascx" /> <Content Include="Themes\Contoso\Views\_Layout.HomePage.ascx" />
<Content Include="Themes\Contoso\Views\ListOfComments.ascx" /> <Content Include="Themes\Contoso\Views\ListOfComments.ascx" />
<Content Include="Themes\Contoso\Views\LogOn.ascx" /> <Content Include="Themes\Contoso\Views\LogOn.ascx" />
<Content Include="Themes\Contoso\Views\User.ascx" /> <Content Include="Themes\Contoso\Views\User.ascx" />

View File

@@ -0,0 +1,5 @@
@model dynamic
<section style="background:#666;color:#fff;padding:10px;">
<h1>HomePage action template</h1>
@Display(Model)
</section>

View File

@@ -0,0 +1,5 @@
@using Orchard.Mvc.Html
<section style="background:#333;color:#fff;padding:10px;">
<h1>Contoso Layout.HomePage template</h1>
@Html.RenderOrchardBody()
</section>

View File

@@ -165,26 +165,26 @@ namespace Orchard.ContentManagement {
/* Display and editor convenience extension methods */ /* Display and editor convenience extension methods */
public static ContentItemViewModel<T> BuildDisplayShape<T>(this IContentManager manager, int id, string displayType) where T : class, IContent { public static TContent BuildDisplayShape<TContent>(this IContentManager manager, int id, string displayType) where TContent : class, IContent {
var content = manager.Get<T>(id); var content = manager.Get<TContent>(id);
if (content == null) if (content == null)
return null; return null;
return manager.BuildDisplayShape(content, displayType); return manager.BuildDisplayModel(content, displayType);
} }
public static ContentItemViewModel<T> BuildEditorShape<T>(this IContentManager manager, int id) where T : class, IContent { public static TContent BuildEditorShape<TContent>(this IContentManager manager, int id) where TContent : class, IContent {
var content = manager.Get<T>(id); var content = manager.Get<TContent>(id);
if (content == null) if (content == null)
return null; return null;
return manager.BuildEditorShape(content); return manager.BuildEditorModel(content);
} }
public static ContentItemViewModel<T> UpdateEditorShape<T>(this IContentManager manager, int id, IUpdateModel updater) where T : class, IContent { public static TContent UpdateEditorShape<TContent>(this IContentManager manager, int id, IUpdateModel updater) where TContent : class, IContent {
var content = manager.Get<T>(id); var content = manager.Get<TContent>(id);
if (content == null) if (content == null)
return null; return null;
return manager.UpdateEditorShape(content, updater); return manager.UpdateEditorModel(content, updater);
} }

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using Orchard.ContentManagement.MetaData.Models; using Orchard.ContentManagement.MetaData.Models;
using Orchard.ContentManagement.Records; using Orchard.ContentManagement.Records;
using Orchard.UI;
namespace Orchard.ContentManagement { namespace Orchard.ContentManagement {
public class ContentItem : IContent { public class ContentItem : IContent {
@@ -14,6 +15,13 @@ namespace Orchard.ContentManagement {
private readonly IList<ContentPart> _parts; private readonly IList<ContentPart> _parts;
ContentItem IContent.ContentItem { get { return this; } } ContentItem IContent.ContentItem { get { return this; } }
private readonly IZoneCollection _zones = new ZoneCollection();
public virtual IZoneCollection Zones {
get {
return _zones;
}
}
public int Id { get { return Record == null ? 0 : Record.Id; } } public int Id { get { return Record == null ? 0 : Record.Id; } }
public int Version { get { return VersionRecord == null ? 0 : VersionRecord.Number; } } public int Version { get { return VersionRecord == null ? 0 : VersionRecord.Number; } }

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using Orchard.ContentManagement.MetaData.Models; using Orchard.ContentManagement.MetaData.Models;
using Orchard.ContentManagement.Utilities; using Orchard.ContentManagement.Utilities;
using Orchard.UI;
namespace Orchard.ContentManagement { namespace Orchard.ContentManagement {
public class ContentPart : IContent { public class ContentPart : IContent {
@@ -13,6 +14,15 @@ namespace Orchard.ContentManagement {
} }
public virtual ContentItem ContentItem { get; set; } public virtual ContentItem ContentItem { get; set; }
//interesting thought, should/could parts also have zones (would then have zones on the page, content item and parts...)?
private readonly IZoneCollection _zones = new ZoneCollection();
public virtual IZoneCollection Zones {
get {
return _zones;
}
}
public ContentTypeDefinition TypeDefinition { get { return ContentItem.TypeDefinition; } } public ContentTypeDefinition TypeDefinition { get { return ContentItem.TypeDefinition; } }
public ContentTypePartDefinition TypePartDefinition { get; set; } public ContentTypePartDefinition TypePartDefinition { get; set; }
public ContentPartDefinition PartDefinition { get { return TypePartDefinition.PartDefinition; } } public ContentPartDefinition PartDefinition { get { return TypePartDefinition.PartDefinition; } }

View File

@@ -393,35 +393,28 @@ namespace Orchard.ContentManagement {
return context.Metadata; return context.Metadata;
} }
public ContentItemViewModel<TContentPart> BuildDisplayShape<TContentPart>(TContentPart content, string displayType) where TContentPart : IContent { public TContent BuildDisplayModel<TContent>(TContent content, string displayType) where TContent : IContent {
if (content == null) var context = new BuildDisplayModelContext(content, displayType);
return null;
var displayModel = new ContentItemViewModel<TContentPart>(content);
var context = new BuildDisplayModelContext(displayModel, displayType);
foreach (var handler in Handlers) { foreach (var handler in Handlers) {
handler.BuildDisplayShape(context); handler.BuildDisplayShape(context);
} }
return displayModel; return content;
} }
public ContentItemViewModel<TContentPart> BuildEditorShape<TContentPart>(TContentPart content) where TContentPart : IContent { public TContent BuildEditorModel<TContent>(TContent content) where TContent : IContent {
var editorModel = new ContentItemViewModel<TContentPart>(content); var context = new BuildEditorModelContext(content);
var context = new BuildEditorModelContext(editorModel);
foreach (var handler in Handlers) { foreach (var handler in Handlers) {
handler.BuildEditorShape(context); handler.BuildEditorShape(context);
} }
return editorModel; return content;
} }
public ContentItemViewModel<TContentPart> UpdateEditorShape<TContentPart>(TContentPart content, IUpdateModel updater) where TContentPart : IContent { public TContent UpdateEditorModel<TContent>(TContent content, IUpdateModel updater) where TContent : IContent {
var editorModel = new ContentItemViewModel<TContentPart>(content); var context = new UpdateEditorModelContext(content, updater);
var context = new UpdateEditorModelContext(editorModel, updater);
foreach (var handler in Handlers) { foreach (var handler in Handlers) {
handler.UpdateEditorShape(context); handler.UpdateEditorShape(context);
} }
return editorModel; return content;
} }
public IContentQuery<ContentItem> Query() { public IContentQuery<ContentItem> Query() {

View File

@@ -12,6 +12,7 @@ namespace Orchard.ContentManagement.Drivers {
public string TemplateName { get; set; } public string TemplateName { get; set; }
public override void Apply(BuildDisplayModelContext context) { public override void Apply(BuildDisplayModelContext context) {
#if REFACTORING
//todo: (heskew)evaluate - for lack of having access to the full context in a driver to conditionally return results (e.g. BlogDriver item display is otherwise being overriden by the ContentPartDriver) //todo: (heskew)evaluate - for lack of having access to the full context in a driver to conditionally return results (e.g. BlogDriver item display is otherwise being overriden by the ContentPartDriver)
if (!string.IsNullOrWhiteSpace(context.ViewModel.TemplateName) if (!string.IsNullOrWhiteSpace(context.ViewModel.TemplateName)
&& context.ViewModel.GetType() != typeof(ContentItemViewModel<TContent>)) && context.ViewModel.GetType() != typeof(ContentItemViewModel<TContent>))
@@ -26,9 +27,11 @@ namespace Orchard.ContentManagement.Drivers {
html.RouteCollection); html.RouteCollection);
}; };
} }
#endif
} }
public override void Apply(BuildEditorModelContext context) { public override void Apply(BuildEditorModelContext context) {
#if REFACTORING
context.ViewModel.TemplateName = TemplateName; context.ViewModel.TemplateName = TemplateName;
if (context.ViewModel.GetType() != typeof(ContentItemViewModel<TContent>)) { if (context.ViewModel.GetType() != typeof(ContentItemViewModel<TContent>)) {
context.ViewModel.Adaptor = (html, viewModel) => { context.ViewModel.Adaptor = (html, viewModel) => {
@@ -38,6 +41,7 @@ namespace Orchard.ContentManagement.Drivers {
html.RouteCollection); html.RouteCollection);
}; };
} }
#endif
} }
class ViewDataContainer : IViewDataContainer { class ViewDataContainer : IViewDataContainer {

View File

@@ -1,5 +1,4 @@
using System; using System.Linq;
using System.Linq;
using Orchard.ContentManagement.Handlers; using Orchard.ContentManagement.Handlers;
namespace Orchard.ContentManagement.Drivers { namespace Orchard.ContentManagement.Drivers {
@@ -17,13 +16,14 @@ namespace Orchard.ContentManagement.Drivers {
} }
public override void Apply(BuildDisplayModelContext context) { public override void Apply(BuildDisplayModelContext context) {
context.ViewModel.Zones.AddDisplayPart( context.ContentItem.Zones[Zone].Add(Model, Position);
Zone + ":" + Position, Model, TemplateName, Prefix); //Zone + ":" + Position, Model, TemplateName, Prefix);
} }
public override void Apply(BuildEditorModelContext context) { public override void Apply(BuildEditorModelContext context) {
context.ViewModel.Zones.AddEditorPart( context.ContentItem.Zones[Zone].Add(Model, Position);
Zone + ":" + Position, Model, TemplateName, Prefix); //context.ViewModel.Zones.AddEditorPart(
// Zone + ":" + Position, Model, TemplateName, Prefix);
} }
public ContentTemplateResult Location(string zone) { public ContentTemplateResult Location(string zone) {

View File

@@ -1,25 +1,11 @@
using Orchard.ContentManagement.ViewModels;
using Orchard.Mvc.ViewModels;
namespace Orchard.ContentManagement.Handlers { namespace Orchard.ContentManagement.Handlers {
public class BuildDisplayModelContext { public class BuildDisplayModelContext {
public BuildDisplayModelContext(ContentItemViewModel viewModel, string displayType) { public BuildDisplayModelContext(IContent content, string displayType) {
ContentItem = viewModel.Item; ContentItem = content.ContentItem;
DisplayType = displayType; DisplayType = displayType;
ViewModel = viewModel;
} }
public ContentItem ContentItem { get; private set; } public ContentItem ContentItem { get; private set; }
public string DisplayType { get; private set; } public string DisplayType { get; private set; }
public ContentItemViewModel ViewModel { get; private set; }
public void AddDisplay(TemplateViewModel display) {
//TEMP: (loudej) transition code - from TemplateViewMode to ZoneItem
ViewModel.Zones.AddDisplayPart(
display.ZoneName+":"+display.Position,
display.Model,
display.TemplateName,
display.Prefix);
}
} }
} }

View File

@@ -1,24 +1,9 @@
using Orchard.ContentManagement.ViewModels;
using Orchard.Mvc.ViewModels;
namespace Orchard.ContentManagement.Handlers { namespace Orchard.ContentManagement.Handlers {
public class BuildEditorModelContext { public class BuildEditorModelContext {
public BuildEditorModelContext(ContentItemViewModel viewModel) { public BuildEditorModelContext(IContent content) {
ContentItem = viewModel.Item; ContentItem = content.ContentItem;
ViewModel = viewModel;
} }
public ContentItem ContentItem { get; set; } public ContentItem ContentItem { get; set; }
public ContentItemViewModel ViewModel { get; set; }
public void AddEditor(TemplateViewModel display) {
//TEMP: (loudej) transition code - from TemplateViewMode to ZoneItem
ViewModel.Zones.AddEditorPart(
display.ZoneName + ":" + display.Position,
display.Model,
display.TemplateName,
display.Prefix);
}
} }
} }

View File

@@ -9,7 +9,7 @@ namespace Orchard.ContentManagement.Handlers {
// todo: (heskew) use _prefix? // todo: (heskew) use _prefix?
private readonly string _prefix; private readonly string _prefix;
private readonly string[] _displayTypes; private readonly string[] _displayTypes;
private Action<UpdateEditorModelContext, ContentItemViewModel<TContent>> _updater; private Action<UpdateEditorModelContext, IContent> _updater;
public ContentItemTemplates(string templateName) public ContentItemTemplates(string templateName)
: this(templateName, "") { : this(templateName, "") {
@@ -23,6 +23,7 @@ namespace Orchard.ContentManagement.Handlers {
} }
protected override void BuildDisplayShape(BuildDisplayModelContext context, TContent instance) { protected override void BuildDisplayShape(BuildDisplayModelContext context, TContent instance) {
#if REFACTORING
context.ViewModel.TemplateName = _templateName; context.ViewModel.TemplateName = _templateName;
var longestMatch = LongestMatch(context.DisplayType); var longestMatch = LongestMatch(context.DisplayType);
if (!string.IsNullOrEmpty(longestMatch)) if (!string.IsNullOrEmpty(longestMatch))
@@ -38,6 +39,7 @@ namespace Orchard.ContentManagement.Handlers {
html.RouteCollection); html.RouteCollection);
}; };
} }
#endif
} }
class ViewDataContainer : IViewDataContainer { class ViewDataContainer : IViewDataContainer {
@@ -55,6 +57,7 @@ namespace Orchard.ContentManagement.Handlers {
} }
protected override void BuildEditorShape(BuildEditorModelContext context, TContent instance) { protected override void BuildEditorShape(BuildEditorModelContext context, TContent instance) {
#if REFACTORING
context.ViewModel.TemplateName = _templateName; context.ViewModel.TemplateName = _templateName;
context.ViewModel.Prefix = _prefix; context.ViewModel.Prefix = _prefix;
if (context.ViewModel.GetType() != typeof(ContentItemViewModel<TContent>)) { if (context.ViewModel.GetType() != typeof(ContentItemViewModel<TContent>)) {
@@ -65,18 +68,21 @@ namespace Orchard.ContentManagement.Handlers {
html.RouteCollection); html.RouteCollection);
}; };
} }
#endif
} }
protected override void UpdateEditorShape(UpdateEditorModelContext context, TContent instance) { protected override void UpdateEditorShape(UpdateEditorModelContext context, TContent instance) {
#if REFACTORING
if (context.ViewModel is ContentItemViewModel<TContent>) if (context.ViewModel is ContentItemViewModel<TContent>)
_updater(context, (ContentItemViewModel<TContent>)context.ViewModel); _updater(context, (ContentItemViewModel<TContent>)context.ViewModel);
else else
_updater(context, new ContentItemViewModel<TContent>(context.ViewModel)); _updater(context, new ContentItemViewModel<TContent>(context.ViewModel));
context.ViewModel.TemplateName = _templateName; context.ViewModel.TemplateName = _templateName;
context.ViewModel.Prefix = _prefix; context.ViewModel.Prefix = _prefix;
#endif
} }
public void Updater(Action<UpdateEditorModelContext, ContentItemViewModel<TContent>> updater) { public void Updater(Action<UpdateEditorModelContext, IContent> updater) {
_updater = updater; _updater = updater;
} }
} }

View File

@@ -3,13 +3,13 @@
namespace Orchard.ContentManagement.Handlers { namespace Orchard.ContentManagement.Handlers {
public class TemplateFilterForRecord<TRecord> : TemplateFilterBase<ContentPart<TRecord>> where TRecord : ContentPartRecord, new() { public class TemplateFilterForRecord<TRecord> : TemplateFilterBase<ContentPart<TRecord>> where TRecord : ContentPartRecord, new() {
private readonly string _prefix; private readonly string _prefix;
private readonly string _templateName;
private string _location; private string _location;
private string _position;
public TemplateFilterForRecord(string prefix, string templateName) { public TemplateFilterForRecord(string prefix) {
_prefix = prefix; _prefix = prefix;
_templateName = templateName;
_location = "primary"; _location = "primary";
_position = "5";
} }
public TemplateFilterForRecord<TRecord> Location(string location) { public TemplateFilterForRecord<TRecord> Location(string location) {
@@ -17,13 +17,18 @@ namespace Orchard.ContentManagement.Handlers {
return this; return this;
} }
public TemplateFilterForRecord<TRecord> Position(string position) {
_position = position;
return this;
}
protected override void BuildEditorShape(BuildEditorModelContext context, ContentPart<TRecord> part) { protected override void BuildEditorShape(BuildEditorModelContext context, ContentPart<TRecord> part) {
context.ViewModel.Zones.AddEditorPart(_location, part.Record, _templateName, _prefix); context.ContentItem.Zones[_location].Add(part.Record, _position);
} }
protected override void UpdateEditorShape(UpdateEditorModelContext context, ContentPart<TRecord> part) { protected override void UpdateEditorShape(UpdateEditorModelContext context, ContentPart<TRecord> part) {
context.Updater.TryUpdateModel(part.Record, _prefix, null, null); context.Updater.TryUpdateModel(part.Record, _prefix, null, null);
context.ViewModel.Zones.AddEditorPart(_location, part.Record, _templateName, _prefix); BuildEditorShape(context, part);
} }
} }
} }

View File

@@ -1,9 +1,7 @@
using Orchard.Mvc.ViewModels;
namespace Orchard.ContentManagement.Handlers { namespace Orchard.ContentManagement.Handlers {
public class UpdateEditorModelContext : BuildEditorModelContext { public class UpdateEditorModelContext : BuildEditorModelContext {
public UpdateEditorModelContext(ContentItemViewModel viewModel, IUpdateModel updater) public UpdateEditorModelContext(IContent content, IUpdateModel updater)
: base(viewModel) { : base(content) {
Updater = updater; Updater = updater;
} }

View File

@@ -1,5 +1,8 @@
namespace Orchard.ContentManagement { using Orchard.UI;
namespace Orchard.ContentManagement {
public interface IContent { public interface IContent {
ContentItem ContentItem { get; } ContentItem ContentItem { get; }
IZoneCollection Zones { get; }
} }
} }

View File

@@ -27,9 +27,9 @@ namespace Orchard.ContentManagement {
ContentItemMetadata GetItemMetadata(IContent contentItem); ContentItemMetadata GetItemMetadata(IContent contentItem);
ContentItemViewModel<TContent> BuildDisplayShape<TContent>(TContent content, string displayType) where TContent : IContent; TContent BuildDisplayModel<TContent>(TContent content, string displayType) where TContent : IContent;
ContentItemViewModel<TContent> BuildEditorShape<TContent>(TContent content) where TContent : IContent; TContent BuildEditorModel<TContent>(TContent content) where TContent : IContent;
ContentItemViewModel<TContent> UpdateEditorShape<TContent>(TContent content, IUpdateModel updater) where TContent : IContent; TContent UpdateEditorModel<TContent>(TContent content, IUpdateModel updater) where TContent : IContent;
} }
public class VersionOptions { public class VersionOptions {

View File

@@ -5,7 +5,8 @@ using System.Web.Mvc.Html;
using Orchard.Mvc.ViewModels; using Orchard.Mvc.ViewModels;
namespace Orchard.Mvc.Html { namespace Orchard.Mvc.Html {
public static class ContentItemDisplayExtensions { #if REFACTORING
public static class ContentItemDisplayExtensions {
public static MvcHtmlString DisplayForItem<TModel, TItemModel>(this HtmlHelper<TModel> html, TItemModel item) where TItemModel : ContentItemViewModel { public static MvcHtmlString DisplayForItem<TModel, TItemModel>(this HtmlHelper<TModel> html, TItemModel item) where TItemModel : ContentItemViewModel {
return html.DisplayForItem(x => item); return html.DisplayForItem(x => item);
} }
@@ -21,4 +22,5 @@ namespace Orchard.Mvc.Html {
return html.DisplayFor(expression, model.TemplateName, model.Prefix ?? ""); return html.DisplayFor(expression, model.TemplateName, model.Prefix ?? "");
} }
} }
#endif
} }

View File

@@ -5,6 +5,7 @@ using System.Web.Mvc.Html;
using Orchard.Mvc.ViewModels; using Orchard.Mvc.ViewModels;
namespace Orchard.Mvc.Html { namespace Orchard.Mvc.Html {
#if REFACTORING
public static class ContentItemEditorExtensions { public static class ContentItemEditorExtensions {
public static MvcHtmlString EditorForItem<TModel, TItemModel>(this HtmlHelper<TModel> html, TItemModel item) where TItemModel : ContentItemViewModel { public static MvcHtmlString EditorForItem<TModel, TItemModel>(this HtmlHelper<TModel> html, TItemModel item) where TItemModel : ContentItemViewModel {
return html.EditorForItem(x => item); return html.EditorForItem(x => item);
@@ -21,4 +22,5 @@ namespace Orchard.Mvc.Html {
return html.EditorFor(expression, model.TemplateName, model.Prefix ?? ""); return html.EditorFor(expression, model.TemplateName, model.Prefix ?? "");
} }
} }
#endif
} }

View File

@@ -2,18 +2,18 @@
using System.IO; using System.IO;
using System.Web.Mvc; using System.Web.Mvc;
using System.Web.UI; using System.Web.UI;
using Microsoft.WebPages;
using Orchard.Mvc.ViewEngines; using Orchard.Mvc.ViewEngines;
using Orchard.Mvc.ViewModels;
using Orchard.UI.PageClass; using Orchard.UI.PageClass;
using Orchard.UI.PageTitle; using Orchard.UI.PageTitle;
using Orchard.UI.Resources; using Orchard.UI.Resources;
using Orchard.UI.Zones; using HtmlHelper = System.Web.Mvc.HtmlHelper;
namespace Orchard.Mvc.Html { namespace Orchard.Mvc.Html {
public static class LayoutExtensions { public static class LayoutExtensions {
public static void RenderBody(this HtmlHelper html) { public static HelperResult RenderOrchardBody(this HtmlHelper html) {
LayoutViewContext layoutViewContext = LayoutViewContext.From(html.ViewContext); LayoutViewContext layoutViewContext = LayoutViewContext.From(html.ViewContext);
html.ViewContext.Writer.Write(layoutViewContext.BodyContent); return new HelperResult(writer => writer.Write(layoutViewContext.BodyContent));
} }
public static MvcHtmlString Body(this HtmlHelper html) { public static MvcHtmlString Body(this HtmlHelper html) {
@@ -61,35 +61,6 @@ namespace Orchard.Mvc.Html {
return MvcHtmlString.Create(html.Encode(pageClassBuilder.ToString())); return MvcHtmlString.Create(html.Encode(pageClassBuilder.ToString()));
} }
public static void Zone<TModel>(this HtmlHelper<TModel> html, string zoneName, string partitions) where TModel : IZoneContainer {
var manager = html.Resolve<IZoneManager>();
manager.Render(html, html.ViewData.Model.Zones, zoneName, partitions, null);
}
public static void Zone<TModel>(this HtmlHelper<TModel> html, string zoneName) where TModel : IZoneContainer {
html.Zone(zoneName, string.Empty);
}
public static void Zone<TModel>(this HtmlHelper<TModel> html, string zoneName, Action action) where TModel : IZoneContainer {
//TODO: again, IoC could move this AddAction (or similar) method out of the data-bearing object
html.ViewData.Model.Zones.AddAction(zoneName, x => action());
html.Zone(zoneName, string.Empty);
}
public static void ZonesAny<TModel>(this HtmlHelper<TModel> html) where TModel : IZoneContainer {
html.ZonesExcept();
}
public static void ZonesExcept<TModel>(this HtmlHelper<TModel> html, params string[] except) where TModel : IZoneContainer {
var manager = html.Resolve<IZoneManager>();
manager.Render(html, html.ViewData.Model.Zones, null, null, except);
}
//public static void ZoneBody<TModel>(this HtmlHelper<TModel> html, string zoneName) where TModel {
// html.Zone(zoneName, () => html.RenderBody());
//}
public static void RegisterMeta(this HtmlHelper html, string name, string content) { public static void RegisterMeta(this HtmlHelper html, string name, string content) {
html.Resolve<IResourceManager>().RegisterMeta(name, content); html.Resolve<IResourceManager>().RegisterMeta(name, content);
} }

View File

@@ -46,7 +46,7 @@ namespace Orchard.Mvc.ViewEngines {
return new ViewDataDictionary<BaseViewModel>(BaseViewModel.From(dictionary)); return new ViewDataDictionary<BaseViewModel>(BaseViewModel.From(dictionary));
#else #else
return null; return dictionary;
#endif #endif
} }

View File

@@ -4,6 +4,7 @@ using Orchard.ContentManagement;
using Orchard.UI.Zones; using Orchard.UI.Zones;
namespace Orchard.Mvc.ViewModels { namespace Orchard.Mvc.ViewModels {
#if REFACTORING
public class ContentItemViewModel : IZoneContainer { public class ContentItemViewModel : IZoneContainer {
private ContentItem _item; private ContentItem _item;
@@ -70,4 +71,5 @@ namespace Orchard.Mvc.ViewModels {
base.SetItem(value); base.SetItem(value);
} }
} }
#endif
} }

View File

@@ -168,9 +168,6 @@
<Compile Include="ContentManagement\ContentPart.cs"> <Compile Include="ContentManagement\ContentPart.cs">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Compile Include="ContentManagement\ContentType.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="ContentManagement\DefaultContentManager.cs"> <Compile Include="ContentManagement\DefaultContentManager.cs">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>

View File

@@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.Web.Mvc; using System.Web.Mvc;
namespace Orchard.UI { namespace Orchard.UI {
@@ -10,10 +11,42 @@ namespace Orchard.UI {
IZone this[string key] { get; } IZone this[string key] { get; }
} }
class ZoneCollection : IZoneCollection {
readonly IDictionary<string, IZone> _zones = new Dictionary<string, IZone>();
public IZone this[string key] {
get {
//a nice race condition
if (!_zones.ContainsKey(key))
_zones[key] = new Zone();
return _zones[key];
}
}
}
public interface IZone { public interface IZone {
void Add(object item); void Add(object item);
void Add(object item, string position); void Add(object item, string position);
void Add(Action<HtmlHelper> action); void Add(Action<HtmlHelper> action);
void Add(Action<HtmlHelper> action, string position); void Add(Action<HtmlHelper> action, string position);
} }
class Zone : IZone {
private readonly IList<object> _items = new List<object>();
public void Add(object item) {
_items.Add(item);
}
public void Add(object item, string position) {
_items.Add(item); // not messing with position at the moment
}
public void Add(Action<HtmlHelper> action) {
//throw new NotImplementedException();
}
public void Add(Action<HtmlHelper> action, string position) {
//throw new NotImplementedException();
}
}
} }

View File

@@ -16,6 +16,7 @@ namespace Orchard.UI.Navigation {
} }
public void OnResultExecuting(ResultExecutingContext filterContext) { public void OnResultExecuting(ResultExecutingContext filterContext) {
#if REFACTORING
var menuName = "main"; var menuName = "main";
if (AdminFilter.IsApplied(filterContext.RequestContext)) if (AdminFilter.IsApplied(filterContext.RequestContext))
menuName = "admin"; menuName = "admin";
@@ -23,6 +24,7 @@ namespace Orchard.UI.Navigation {
//todo: (heskew) does the menu need to be on Page? //todo: (heskew) does the menu need to be on Page?
var shape = _shapeHelperFactory.CreateHelper(); var shape = _shapeHelperFactory.CreateHelper();
_workContextAccessor.GetContext(filterContext).CurrentPage.Zones["Navigation"].Add(shape.Menu(_navigationManager.BuildMenu(menuName))); _workContextAccessor.GetContext(filterContext).CurrentPage.Zones["Navigation"].Add(shape.Menu(_navigationManager.BuildMenu(menuName)));
#endif
} }
public void OnResultExecuted(ResultExecutedContext filterContext) {} public void OnResultExecuted(ResultExecutedContext filterContext) {}

View File

@@ -14,6 +14,7 @@ namespace Orchard.UI.Resources {
} }
public void OnResultExecuting(ResultExecutingContext filterContext) { public void OnResultExecuting(ResultExecutingContext filterContext) {
#if REFACTORING
var headZone = _workContextAccessor.GetContext().CurrentPage.Zones["Head"]; var headZone = _workContextAccessor.GetContext().CurrentPage.Zones["Head"];
headZone.Add(html => html.ViewContext.Writer.Write(_resourceManager.GetMetas()), ":metas"); headZone.Add(html => html.ViewContext.Writer.Write(_resourceManager.GetMetas()), ":metas");
headZone.Add(html => html.ViewContext.Writer.Write(_resourceManager.GetStyles()), ":styles"); headZone.Add(html => html.ViewContext.Writer.Write(_resourceManager.GetStyles()), ":styles");
@@ -28,6 +29,7 @@ namespace Orchard.UI.Resources {
html.ViewContext.Writer.Write(captured); html.ViewContext.Writer.Write(captured);
}, },
":after"); ":after");
#endif
} }
public void OnResultExecuted(ResultExecutedContext filterContext) {} public void OnResultExecuted(ResultExecutedContext filterContext) {}

View File

@@ -3,6 +3,7 @@ using Orchard.Mvc.Html;
using Orchard.Mvc.ViewModels; using Orchard.Mvc.ViewModels;
namespace Orchard.UI.Zones { namespace Orchard.UI.Zones {
#if REFACTORING
public class ContentItemDisplayZoneItem : ZoneItem { public class ContentItemDisplayZoneItem : ZoneItem {
public ContentItemViewModel ViewModel { get; set; } public ContentItemViewModel ViewModel { get; set; }
@@ -11,4 +12,5 @@ namespace Orchard.UI.Zones {
html.ViewContext.Writer.Write(htmlString); html.ViewContext.Writer.Write(htmlString);
} }
} }
#endif
} }

View File

@@ -2,6 +2,7 @@ using System.Web.Mvc;
using System.Web.Mvc.Html; using System.Web.Mvc.Html;
namespace Orchard.UI.Zones { namespace Orchard.UI.Zones {
#if REFACTORING
public class ContentPartDisplayZoneItem : ZoneItem { public class ContentPartDisplayZoneItem : ZoneItem {
public object Model { get; set; } public object Model { get; set; }
public string TemplateName { get; set; } public string TemplateName { get; set; }
@@ -12,4 +13,5 @@ namespace Orchard.UI.Zones {
html.ViewContext.Writer.Write(htmlString); html.ViewContext.Writer.Write(htmlString);
} }
} }
#endif
} }

View File

@@ -2,6 +2,7 @@ using System.Web.Mvc;
using System.Web.Mvc.Html; using System.Web.Mvc.Html;
namespace Orchard.UI.Zones { namespace Orchard.UI.Zones {
#if REFACTORING
public class ContentPartEditorZoneItem : ZoneItem { public class ContentPartEditorZoneItem : ZoneItem {
public object Model { get; set; } public object Model { get; set; }
public string TemplateName { get; set; } public string TemplateName { get; set; }
@@ -12,4 +13,5 @@ namespace Orchard.UI.Zones {
html.EditorFor(m => Model, TemplateName, Prefix)); html.EditorFor(m => Model, TemplateName, Prefix));
} }
} }
#endif
} }

View File

@@ -2,6 +2,7 @@ using System;
using System.Web.Mvc; using System.Web.Mvc;
namespace Orchard.UI.Zones { namespace Orchard.UI.Zones {
#if REFACTORING
public class DelegateZoneItem : ZoneItem { public class DelegateZoneItem : ZoneItem {
public Action<HtmlHelper> Action { get; set; } public Action<HtmlHelper> Action { get; set; }
@@ -9,4 +10,5 @@ namespace Orchard.UI.Zones {
Action(html); Action(html);
} }
} }
#endif
} }

View File

@@ -1,7 +1,9 @@
using System.Web.Mvc; using System.Web.Mvc;
namespace Orchard.UI.Zones { namespace Orchard.UI.Zones {
#if REFACTORING
public interface IZoneManager : IDependency { public interface IZoneManager : IDependency {
void Render<TModel>(HtmlHelper<TModel> html, ZoneCollection zones, string zoneName, string partitions, string[] except); void Render<TModel>(HtmlHelper<TModel> html, ZoneCollection zones, string zoneName, string partitions, string[] except);
} }
#endif
} }

View File

@@ -3,6 +3,7 @@ using System.Web.Mvc;
using Orchard.Events; using Orchard.Events;
namespace Orchard.UI.Zones { namespace Orchard.UI.Zones {
#if REFACTORING
public interface IZoneManagerEvents : IEventHandler { public interface IZoneManagerEvents : IEventHandler {
void ZoneRendering(ZoneRenderContext context); void ZoneRendering(ZoneRenderContext context);
void ZoneItemRendering(ZoneRenderContext context, ZoneItem item); void ZoneItemRendering(ZoneRenderContext context, ZoneItem item);
@@ -15,5 +16,5 @@ namespace Orchard.UI.Zones {
public string ZoneName { get; set; } public string ZoneName { get; set; }
public IEnumerable<ZoneItem> RenderingItems { get; set; } public IEnumerable<ZoneItem> RenderingItems { get; set; }
} }
#endif
} }

View File

@@ -5,6 +5,7 @@ using System.Web.Routing;
using Orchard.Mvc.ViewModels; using Orchard.Mvc.ViewModels;
namespace Orchard.UI.Zones { namespace Orchard.UI.Zones {
#if REFACTORING
public interface IZoneContainer { public interface IZoneContainer {
ZoneCollection Zones { get; } ZoneCollection Zones { get; }
} }
@@ -76,4 +77,5 @@ namespace Orchard.UI.Zones {
} }
} }
#endif
} }

View File

@@ -6,7 +6,7 @@ using Orchard.Logging;
using Orchard.UI.Navigation; using Orchard.UI.Navigation;
namespace Orchard.UI.Zones { namespace Orchard.UI.Zones {
#if REFACTORING
public class ZoneManager : IZoneManager { public class ZoneManager : IZoneManager {
private readonly IEnumerable<IZoneManagerEvents> _zoneManagerEventHandler; private readonly IEnumerable<IZoneManagerEvents> _zoneManagerEventHandler;
@@ -95,4 +95,5 @@ namespace Orchard.UI.Zones {
public IEnumerable<ZoneItem> Items { get; set; } public IEnumerable<ZoneItem> Items { get; set; }
} }
} }
#endif
} }