--HG--
branch : theming
This commit is contained in:
Louis DeJardin
2010-09-03 17:42:36 -07:00
86 changed files with 437 additions and 424 deletions

View File

@@ -41,7 +41,7 @@ namespace Orchard.Core.Tests.Body {
public void BodyCanHandleLongText() {
var contentManager = _container.Resolve<IContentManager>();
contentManager.Create<Thing>(ThingDriver.ContentType.Name, t => {
contentManager.Create<Thing>(ThingDriver.ContentTypeName, t => {
t.As<BodyPart>().Record = new BodyPartRecord();
t.Text = new String('x', 10000);
});
@@ -69,10 +69,10 @@ namespace Orchard.Core.Tests.Body {
[UsedImplicitly]
public class ThingHandler : ContentHandler {
public ThingHandler() {
Filters.Add(new ActivatingFilter<Thing>(ThingDriver.ContentType.Name));
Filters.Add(new ActivatingFilter<ContentPart<CommonPartVersionRecord>>(ThingDriver.ContentType.Name));
Filters.Add(new ActivatingFilter<CommonPart>(ThingDriver.ContentType.Name));
Filters.Add(new ActivatingFilter<BodyPart>(ThingDriver.ContentType.Name));
Filters.Add(new ActivatingFilter<Thing>(ThingDriver.ContentTypeName));
Filters.Add(new ActivatingFilter<ContentPart<CommonPartVersionRecord>>(ThingDriver.ContentTypeName));
Filters.Add(new ActivatingFilter<CommonPart>(ThingDriver.ContentTypeName));
Filters.Add(new ActivatingFilter<BodyPart>(ThingDriver.ContentTypeName));
}
}
@@ -87,10 +87,7 @@ namespace Orchard.Core.Tests.Body {
}
public class ThingDriver : ContentPartDriver<Thing> {
public readonly static ContentType ContentType = new ContentType {
Name = "thing",
DisplayName = "Thing"
};
public static readonly string ContentTypeName = "thing";
}
}

View File

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

View File

@@ -165,7 +165,7 @@ namespace Orchard.Tests.ContentManagement {
[Test]
public void GetContentTypesShouldReturnAllTypes() {
var types = _manager.GetContentTypes();
var types = _manager.GetContentTypeDefinitions();
Assert.That(types.Count(), Is.EqualTo(4));
Assert.That(types, Has.Some.With.Property("Name").EqualTo("alpha"));
Assert.That(types, Has.Some.With.Property("Name").EqualTo("beta"));

View File

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

View File

@@ -1,16 +1,11 @@
using System.Collections.Generic;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Handlers;
using Orchard.ContentManagement.ViewModels;
using Orchard.ContentManagement.Handlers;
namespace Orchard.Tests.ContentManagement.Models {
public class AlphaHandler : ContentHandler {
public AlphaHandler() {
OnGetDisplayShape<Alpha>((ctx, part) => ctx.AddDisplay(new TemplateViewModel(part) { Position = "3" }));
}
public override IEnumerable<ContentType> GetContentTypes() {
return new[] { new ContentType { Name = "alpha" } };
OnGetDisplayShape<Alpha>((ctx, part) => ctx.ContentItem.Zones["Main"].Add(part, "3"));
}
protected override void Activating(ActivatingContentContext context) {
if (context.ContentType == "alpha") {
context.Builder.Weld<Alpha>();

View File

@@ -1,16 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Handlers;
using Orchard.ContentManagement.Handlers;
namespace Orchard.Tests.ContentManagement.Models {
public class BetaHandler : ContentHandler {
public override System.Collections.Generic.IEnumerable<Orchard.ContentManagement.ContentType> GetContentTypes() {
return new[] { new ContentType { Name = "beta" } };
}
protected override void Activating(ActivatingContentContext context) {
if (context.ContentType == "beta") {
context.Builder.Weld<Beta>();

View File

@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Orchard.Data;
using Orchard.Data;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Handlers;
using Orchard.Tests.ContentManagement.Records;
@@ -13,9 +9,6 @@ namespace Orchard.Tests.ContentManagement.Models {
public class DeltaHandler : ContentHandler {
public override System.Collections.Generic.IEnumerable<Orchard.ContentManagement.ContentType> GetContentTypes() {
return new[] { new ContentType { Name = "delta" } };
}
public DeltaHandler(IRepository<DeltaRecord> repository) {
Filters.Add(new ActivatingFilter<Delta>(x => x == "delta"));

View File

@@ -1,10 +1,9 @@
using Orchard.ContentManagement.Handlers;
using Orchard.ContentManagement.ViewModels;
namespace Orchard.Tests.ContentManagement.Models {
public class FlavoredHandler : ContentHandler {
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) {
if (context.ContentType == "beta" || context.ContentType == "alpha") {

View File

@@ -9,10 +9,6 @@ namespace Orchard.Tests.ContentManagement.Models {
public class GammaHandler : ContentHandler {
public override System.Collections.Generic.IEnumerable<ContentType> GetContentTypes() {
return new[] { new ContentType { Name = "gamma" } };
}
public GammaHandler(IRepository<GammaRecord> repository) {
Filters.Add(new ActivatingFilter<Gamma>(x => x == "gamma"));
Filters.Add(StorageFilter.For(repository));

View File

@@ -1,10 +1,9 @@
using Orchard.ContentManagement.Handlers;
using Orchard.ContentManagement.ViewModels;
namespace Orchard.Tests.ContentManagement.Models {
public class StyledHandler : ContentHandler {
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) {

View File

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

View File

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

View File

@@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Web;
using JetBrains.Annotations;
using Orchard.ContentManagement;
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 \/\/
protected override DriverResult Display(BodyPart part, string displayType) {
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);
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 {
public class BodyDisplayViewModel {
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.ViewModels;
using Orchard.Data;
using Orchard.DisplayManagement;
using Orchard.Localization;
using Orchard.Logging;
using Orchard.Mvc.Results;
using Orchard.Mvc.ViewModels;
using Orchard.UI.Notify;
namespace Orchard.Core.Contents.Controllers {
@@ -29,15 +29,18 @@ namespace Orchard.Core.Contents.Controllers {
IOrchardServices orchardServices,
IContentManager contentManager,
IContentDefinitionManager contentDefinitionManager,
ITransactionManager transactionManager) {
ITransactionManager transactionManager,
IShapeHelperFactory shapeHelperFactory) {
Services = orchardServices;
_contentManager = contentManager;
_contentDefinitionManager = contentDefinitionManager;
_transactionManager = transactionManager;
T = NullLocalizer.Instance;
Logger = NullLogger.Instance;
Shape = shapeHelperFactory.CreateHelper();
}
dynamic Shape { get; set; }
public IOrchardServices Services { get; private set; }
public Localizer T { 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))
.ToList().OrderBy(kvp => kvp.Key);
return View("List", model);
return View(Shape.Model(model));
}
private IEnumerable<ContentTypeDefinition> GetCreatableTypes() {
@@ -188,9 +191,8 @@ namespace Orchard.Core.Contents.Controllers {
private ListContentsViewModel.Entry BuildEntry(ContentItem contentItem) {
var entry = new ListContentsViewModel.Entry {
ContentItem = contentItem,
ContentItem = _contentManager.BuildDisplayModel(contentItem, "SummaryAdmin"),
ContentItemMetadata = _contentManager.GetItemMetadata(contentItem),
ViewModel = _contentManager.BuildDisplayShape(contentItem, "SummaryAdmin"),
};
if (string.IsNullOrEmpty(entry.ContentItemMetadata.DisplayText)) {
entry.ContentItemMetadata.DisplayText = string.Format("[{0}#{1}]", contentItem.ContentType, contentItem.Id);
@@ -207,11 +209,7 @@ namespace Orchard.Core.Contents.Controllers {
}
ActionResult CreatableTypeList() {
var model = new ListContentTypesViewModel {
Types = GetCreatableTypes()
};
return View("CreatableTypeList", model);
return View(Shape.Model(Types: GetCreatableTypes()));
}
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")))
return new HttpUnauthorizedResult();
var model = new CreateItemViewModel {
Id = id,
Content = _contentManager.BuildEditorShape(contentItem)
};
PrepareEditorViewModel(model.Content);
return View("Create", model);
var model = _contentManager.BuildEditorModel(contentItem);
return View(Shape.Model(Content: model));
}
[HttpPost]
public ActionResult Create(CreateItemViewModel model) {
var contentItem = _contentManager.New(model.Id);
[HttpPost, ActionName("Create")]
public ActionResult CreatePOST(string id) {
var contentItem = _contentManager.New(id);
if (!Services.Authorizer.Authorize(Permissions.PublishContent, contentItem, T("Couldn't create content")))
return new HttpUnauthorizedResult();
_contentManager.Create(contentItem, VersionOptions.Draft);
model.Content = _contentManager.UpdateEditorShape(contentItem, this);
var model = _contentManager.UpdateEditorModel(contentItem, this);
if (!ModelState.IsValid) {
_transactionManager.Cancel();
PrepareEditorViewModel(model.Content);
return View("Create", model);
return View(Shape.Model(Content: model));
}
if (!contentItem.Has<IPublishingControlAspect>())
_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 } });
}
@@ -264,19 +259,14 @@ namespace Orchard.Core.Contents.Controllers {
if (!Services.Authorizer.Authorize(Permissions.EditOthersContent, contentItem, T("Cannot edit content")))
return new HttpUnauthorizedResult();
var model = new EditItemViewModel {
Id = id,
Content = _contentManager.BuildEditorShape(contentItem)
};
var model = _contentManager.BuildEditorModel(contentItem);
PrepareEditorViewModel(model.Content);
return View("Edit", model);
return View(Shape.Model(Content: model));
}
[HttpPost]
public ActionResult Edit(EditItemViewModel model) {
var contentItem = _contentManager.Get(model.Id, VersionOptions.DraftRequired);
[HttpPost, ActionName("Edit")]
public ActionResult EditPOST(int id) {
var contentItem = _contentManager.Get(id, VersionOptions.DraftRequired);
if (contentItem == null)
return new NotFoundResult();
@@ -284,18 +274,19 @@ namespace Orchard.Core.Contents.Controllers {
if (!Services.Authorizer.Authorize(Permissions.EditOthersContent, contentItem, T("Couldn't edit content")))
return new HttpUnauthorizedResult();
model.Content = _contentManager.UpdateEditorShape(contentItem, this);
var model = _contentManager.UpdateEditorModel(contentItem, this);
if (!ModelState.IsValid) {
_transactionManager.Cancel();
PrepareEditorViewModel(model.Content);
return View("Edit", model);
return View("Edit", Shape.Model(Content: model));
}
//need to go about this differently - to know when to publish (IPlublishableAspect ?)
if (!contentItem.Has<IPublishingControlAspect>())
_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 } });
}
@@ -308,7 +299,9 @@ namespace Orchard.Core.Contents.Controllers {
if (contentItem != null) {
_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))
@@ -355,12 +348,6 @@ namespace Orchard.Core.Contents.Controllers {
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) {
return TryUpdateModel(model, prefix, includeProperties, excludeProperties);
}

View File

@@ -1,8 +1,6 @@
using System.Web.Mvc;
using Orchard.ContentManagement;
using Orchard.Core.Contents.ViewModels;
using Orchard.DisplayManagement;
using Orchard.Mvc.ViewModels;
namespace Orchard.Core.Contents.Controllers {
public class ItemController : Controller {
@@ -18,12 +16,8 @@ namespace Orchard.Core.Contents.Controllers {
// /Contents/Item/Display/72
public ActionResult Display(int id) {
var contentItem = _contentManager.Get(id, VersionOptions.Published);
var model = Shape.Content(
_contentManager.BuildDisplayShape(contentItem, "Detail")
);
//PrepareDisplayViewModel(model.Content);
return View(model);
var model = _contentManager.BuildDisplayModel(contentItem, "Detail");
return View(Shape.Model(model));
}
// /Contents/Item/Preview/72
@@ -35,18 +29,8 @@ namespace Orchard.Core.Contents.Controllers {
}
var contentItem = _contentManager.Get(id, versionOptions);
var model = new DisplayItemViewModel {
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";
}
var model = _contentManager.BuildDisplayModel(contentItem, "Detail");
return View(Shape.Model(model));
}
}
}

View File

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

View File

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

View File

@@ -1,6 +1,5 @@
using System.Collections.Generic;
using Orchard.ContentManagement;
using Orchard.Mvc.ViewModels;
namespace Orchard.Core.Contents.ViewModels {
public class ListContentsViewModel {
@@ -25,7 +24,6 @@ namespace Orchard.Core.Contents.ViewModels {
public class Entry {
public ContentItem ContentItem { get; set; }
public ContentItemMetadata ContentItemMetadata { get; set; }
public ContentItemViewModel ViewModel { get; set; }
}
#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.ViewModels;
using Orchard.Core.Routable.Models;
using Orchard.DisplayManagement;
using Orchard.Localization;
using Orchard.Localization.Services;
using Orchard.Mvc.Results;
using Orchard.Mvc.ViewModels;
using Orchard.UI.Notify;
namespace Orchard.Core.Localization.Controllers {
@@ -20,14 +20,21 @@ namespace Orchard.Core.Localization.Controllers {
private readonly ICultureManager _cultureManager;
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;
_cultureManager = cultureManager;
_localizationService = localizationService;
T = NullLocalizer.Instance;
Services = orchardServices;
Shape = shapeHelperFactory.CreateHelper();
}
dynamic Shape { get; set; }
public Localizer T { get; set; }
public IOrchardServices Services { get; set; }
@@ -60,12 +67,11 @@ namespace Orchard.Core.Localization.Controllers {
Id = id,
SelectedCulture = selectedCulture,
SiteCultures = siteCultures,
Content = _contentManager.BuildEditorShape(contentItem)
Content = _contentManager.BuildEditorModel(contentItem)
};
Services.TransactionManager.Cancel();
PrepareEditorViewModel(model.Content);
return View(model);
return View(Shape.Model(model));
}
[HttpPost, ActionName("Translate")]
@@ -75,11 +81,11 @@ namespace Orchard.Core.Localization.Controllers {
if (contentItem == null)
return new NotFoundResult();
var viewModel = new AddLocalizationViewModel();
TryUpdateModel(viewModel);
var model = new AddLocalizationViewModel();
TryUpdateModel(model);
ContentItem contentItemTranslation = null;
var existingTranslation = _localizationService.GetLocalizedContentItem(contentItem, viewModel.SelectedCulture);
var existingTranslation = _localizationService.GetLocalizedContentItem(contentItem, model.SelectedCulture);
if (existingTranslation != null) {
// edit existing
contentItemTranslation = _contentManager.Get(existingTranslation.ContentItem.Id, VersionOptions.DraftRequired);
@@ -89,8 +95,8 @@ namespace Orchard.Core.Localization.Controllers {
contentItemTranslation = _contentManager.New(contentItem.ContentType);
var localized = contentItemTranslation.As<LocalizationPart>();
localized.MasterContentItem = contentItem;
if (!string.IsNullOrWhiteSpace(viewModel.SelectedCulture))
localized.Culture = _cultureManager.GetCultureByName(viewModel.SelectedCulture);
if (!string.IsNullOrWhiteSpace(model.SelectedCulture))
localized.Culture = _cultureManager.GetCultureByName(model.SelectedCulture);
_contentManager.Create(contentItemTranslation, VersionOptions.Draft);
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) {
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;
viewModel.Content = _contentManager.BuildEditorShape(contentItem);
PrepareEditorViewModel(viewModel.Content);
return View(viewModel);
model.Content = _contentManager.BuildEditorModel(contentItem);
return View(Shape.Model(model));
}
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)
return null; //todo: (heskew) redirect to somewhere better than nowhere
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) {
return TryUpdateModel(model, prefix, includeProperties, excludeProperties);
}

View File

@@ -1,6 +1,6 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using Orchard.Mvc.ViewModels;
using Orchard.ContentManagement;
namespace Orchard.Core.Localization.ViewModels {
public class AddLocalizationViewModel {
@@ -8,6 +8,6 @@ namespace Orchard.Core.Localization.ViewModels {
[Required]
public string SelectedCulture { 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.Services;
using Orchard.Core.Navigation.ViewModels;
using Orchard.DisplayManagement;
using Orchard.Localization;
using Orchard.Mvc.AntiForgery;
using Orchard.UI.Navigation;
@@ -18,13 +19,19 @@ namespace Orchard.Core.Navigation.Controllers {
private readonly IOrchardServices _services;
private readonly INavigationManager _navigationManager;
public AdminController(IMenuService menuService, IOrchardServices services, INavigationManager navigationManager) {
public AdminController(
IMenuService menuService,
IOrchardServices services,
INavigationManager navigationManager,
IShapeHelperFactory shapeHelperFactory) {
_menuService = menuService;
_services = services;
_navigationManager = navigationManager;
T = NullLocalizer.Instance;
Shape = shapeHelperFactory.CreateHelper();
}
dynamic Shape { get; set; }
public Localizer T { get; set; }
public ActionResult Index(NavigationManagementViewModel model) {
@@ -37,7 +44,7 @@ namespace Orchard.Core.Navigation.Controllers {
if (model.MenuItemEntries == null || model.MenuItemEntries.Count() < 1)
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")]
@@ -81,7 +88,7 @@ namespace Orchard.Core.Navigation.Controllers {
return new HttpUnauthorizedResult();
var menuPart = _services.ContentManager.New<MenuPart>("MenuItem");
model.MenuItem = _services.ContentManager.UpdateEditorShape(menuPart, this);
model.MenuItem = _services.ContentManager.UpdateEditorModel(menuPart, this);
if (!ModelState.IsValid) {
_services.TransactionManager.Cancel();
@@ -92,7 +99,7 @@ namespace Orchard.Core.Navigation.Controllers {
menuPart.MenuPosition = Position.GetNext(_navigationManager.BuildMenu("main"));
menuPart.OnMainMenu = true;
_services.ContentManager.Create(model.MenuItem.Item.ContentItem);
_services.ContentManager.Create(model.MenuItem);
return RedirectToAction("Index");
}

View File

@@ -1,8 +1,7 @@
using Orchard.Core.Navigation.Models;
using Orchard.Mvc.ViewModels;
using Orchard.ContentManagement;
namespace Orchard.Core.Navigation.ViewModels {
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" />
<None Include="Contents\Views\Content.cshtml" />
<None Include="Contents\Views\Item\Display.cshtml" />
<None Include="HomePage\Views\HomePage.cshtml" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />

View File

@@ -1,27 +1,29 @@
using System.Linq;
using System.Web.Mvc;
using Orchard.Core.Reports.ViewModels;
using Orchard.Mvc.ViewModels;
using Orchard.DisplayManagement;
using Orchard.Reports.Services;
namespace Orchard.Core.Reports.Controllers {
public class AdminController : Controller {
private readonly IReportsManager _reportsManager;
public AdminController(IReportsManager reportsManager) {
public AdminController(IReportsManager reportsManager, IShapeHelperFactory shapeHelperFactory) {
_reportsManager = reportsManager;
}
dynamic Shape { get; set; }
public ActionResult Index() {
var model = new ReportsAdminIndexViewModel { Reports = _reportsManager.GetReports().ToList() };
return View(model);
return View(Shape.Model(model));
}
public ActionResult Display(int 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 Orchard.ContentManagement;
using Orchard.ContentManagement.Aspects;
using Orchard.Core.Common.Models;
using Orchard.Core.Routable.Models;
using Orchard.Core.Routable.ViewModels;
using Orchard.Data;
using Orchard.DisplayManagement;
using Orchard.Localization;
using Orchard.Mvc.ViewModels;
namespace Orchard.Core.Routable.Controllers {
[ValidateInput(false)]
@@ -17,12 +15,15 @@ namespace Orchard.Core.Routable.Controllers {
private readonly ITransactionManager _transactionManager;
private readonly IRoutablePathConstraint _routablePathConstraint;
public ItemController(IContentManager contentManager, ITransactionManager transactionManager, IRoutablePathConstraint routablePathConstraint) {
public ItemController(IContentManager contentManager, ITransactionManager transactionManager, IRoutablePathConstraint routablePathConstraint, IShapeHelperFactory shapeHelperFactory) {
_contentManager = contentManager;
_transactionManager = transactionManager;
_routablePathConstraint = routablePathConstraint;
Shape = shapeHelperFactory.CreateHelper();
}
dynamic Shape { get; set; }
public ActionResult Display(string path) {
var matchedPath = _routablePathConstraint.FindPath(path);
if (string.IsNullOrEmpty(matchedPath)) {
@@ -39,17 +40,9 @@ namespace Orchard.Core.Routable.Controllers {
if (hits.Count() != 1) {
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) {
if (string.IsNullOrEmpty(itemViewModel.TemplateName)) {
itemViewModel.TemplateName = "Items/Contents.Item";
}
var model = _contentManager.BuildDisplayModel<IRoutableAspect>(hits.Single(), "Detail");
return View(Shape.Model(model));
}
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();
return Json(contentItem.As<IRoutableAspect>().Slug ?? slug);

View File

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

View File

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

View File

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

View File

@@ -3,7 +3,6 @@ using Orchard.Settings;
namespace Orchard.Core.Settings.Models {
public sealed class SiteSettingsPart : ContentPart<SiteSettingsPartRecord>, ISite {
public static readonly ContentType ContentType = new ContentType { Name = "Site", DisplayName = "Site Settings" };
public string PageTitleSeparator {
get { return Record.PageTitleSeparator; }

View File

@@ -1,14 +1,12 @@
using System.Collections.Generic;
using System.Web.Mvc;
using Orchard.ContentManagement;
using Orchard.Mvc.ViewModels;
using Orchard.Core.Settings.Models;
namespace Orchard.Core.Settings.ViewModels {
public class SettingsIndexViewModel {
public SiteSettingsPart Site { get; set; }
public IEnumerable<string> SiteCultures { get; set; }
public ContentItemViewModel ViewModel { get; set; }
[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.ContentManagement;
using Orchard.ContentManagement.Records;
using Orchard.DisplayManagement;
namespace Orchard.DevTools.Controllers {
public class ContentController : Controller {
@@ -14,11 +15,14 @@ namespace Orchard.DevTools.Controllers {
public ContentController(
IRepository<ContentTypeRecord> contentTypeRepository,
IContentManager contentManager) {
IContentManager contentManager,
IShapeHelperFactory shapeHelperFactory) {
_contentTypeRepository = contentTypeRepository;
_contentManager = contentManager;
}
dynamic Shape { get; set; }
public ActionResult Index() {
return View(new ContentIndexViewModel {
Items = _contentManager.Query().List(),
@@ -34,10 +38,10 @@ namespace Orchard.DevTools.Controllers {
.Select(x => x.GetType())
.SelectMany(x => AllTypes(x))
.Distinct();
model.DisplayModel = _contentManager.BuildDisplayShape(model.Item, "Detail");
model.EditorModel = _contentManager.BuildEditorShape(model.Item);
model.DisplayShape = _contentManager.BuildDisplayModel(model.Item, "Detail");
model.EditorShape = _contentManager.BuildEditorModel(model.Item);
return View(model);
return View(Shape.Model(model));
}
static IEnumerable<Type> AllTypes(Type type) {

View File

@@ -1,6 +1,5 @@
using JetBrains.Annotations;
using Orchard.ContentManagement.Handlers;
using Orchard.ContentManagement.ViewModels;
using Orchard.DevTools.Models;
namespace Orchard.DevTools.Handlers {
@@ -9,12 +8,12 @@ namespace Orchard.DevTools.Handlers {
protected override void BuildDisplayShape(BuildDisplayModelContext context) {
var devToolsSettings = context.ContentItem.TypeDefinition.Settings.GetModel<Settings.DevToolsSettings>();
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) {
var devToolsSettings = context.ContentItem.TypeDefinition.Settings.GetModel<Settings.DevToolsSettings>();
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 Orchard.ContentManagement;
using Orchard.ContentManagement.ViewModels;
using Orchard.Mvc.ViewModels;
using Orchard.UI.Zones;
namespace Orchard.DevTools.ViewModels {
@@ -12,27 +11,13 @@ namespace Orchard.DevTools.ViewModels {
public IEnumerable<Type> PartTypes { get; set; }
public ContentItemViewModel DisplayModel { get; set; }
public IContent DisplayShape { get; set; }
public ContentItemViewModel EditorModel { 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 IContent EditorShape { get; set; }
public IEnumerable<TemplateViewModel> Editors {
get {
#if REFACTORING
return EditorModel.Zones
.SelectMany(z => z.Value.Items
.OfType<ContentPartEditorZoneItem>()
@@ -43,6 +28,9 @@ namespace Orchard.DevTools.ViewModels {
WasUsed = x.Item.WasExecuted,
ZoneName = x.ZoneName,
});
#else
return null;
#endif
}
}

View File

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

View File

@@ -2,8 +2,8 @@
using System.Reflection;
using System.Web;
using System.Web.Mvc;
using Orchard.DisplayManagement;
using Orchard.Localization;
using Orchard.Mvc.ViewModels;
using Orchard.Security;
using Orchard.Themes.Preview;
using Orchard.Themes.ViewModels;
@@ -15,13 +15,20 @@ namespace Orchard.Themes.Controllers {
private readonly IThemeService _themeService;
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;
_themeService = themeService;
_previewTheme = previewTheme;
T = NullLocalizer.Instance;
}
dynamic Shape { get; set; }
public IOrchardServices Services{ get; set; }
public Localizer T { get; set; }
@@ -30,11 +37,11 @@ namespace Orchard.Themes.Controllers {
var themes = _themeService.GetInstalledThemes();
var currentTheme = _themeService.GetSiteTheme();
var model = new ThemesIndexViewModel { CurrentTheme = currentTheme, Themes = themes };
return View(model);
return View(Shape.Model(model));
}
catch (Exception exception) {
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;
namespace Orchard.Themes.DesignerNotes {
#if REFACTORING
public class ZoneManagerEvents : IZoneManagerEvents {
private readonly IThemeService _themeService;
private readonly IAuthorizationService _authorizationService;
@@ -82,4 +83,5 @@ namespace Orchard.Themes.DesignerNotes {
public void ZoneRendered(ZoneRenderContext context) {
}
}
#endif
}

View File

@@ -104,7 +104,7 @@
<Content Include="Views\Admin\Install.aspx" />
<Content Include="Views\Admin\ThemePreview.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\Header.ascx" />
<Content Include="Views\HeadPreload.ascx" />
@@ -128,6 +128,9 @@
<Name>Orchard.Framework</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="Views\Document.cshtml" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.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.

View File

@@ -2,6 +2,7 @@
using Orchard.UI.Zones;
namespace Orchard.Themes.Services {
#if REFACTORING
public class ThemeZoneManagerEvents : IZoneManagerEvents {
public ThemeZoneManagerEvents() {
T = NullLocalizer.Instance;
@@ -47,4 +48,5 @@ namespace Orchard.Themes.Services {
#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 JetBrains.Annotations;
using Orchard.ContentManagement;
using Orchard.DisplayManagement;
using Orchard.Localization;
using Orchard.Security;
using Orchard.Settings;
@@ -20,13 +21,16 @@ namespace Orchard.Users.Controllers {
public AdminController(
IOrchardServices services,
IMembershipService membershipService,
IUserService userService) {
IUserService userService,
IShapeHelperFactory shapeHelperFactory) {
Services = services;
_membershipService = membershipService;
_userService = userService;
T = NullLocalizer.Instance;
Shape = shapeHelperFactory.CreateHelper();
}
dynamic Shape { get; set; }
public IOrchardServices Services { get; set; }
public Localizer T { get; set; }
protected virtual ISite CurrentSite { get; [UsedImplicitly] private set; }
@@ -46,7 +50,7 @@ namespace Orchard.Users.Controllers {
.ToList()
};
return View(model);
return View(Shape.Model(model));
}
public ActionResult Create() {
@@ -55,9 +59,9 @@ namespace Orchard.Users.Controllers {
var user = Services.ContentManager.New<IUser>("User");
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")]
@@ -66,10 +70,10 @@ namespace Orchard.Users.Controllers {
return new HttpUnauthorizedResult();
var user = Services.ContentManager.New<IUser>("User");
model.User = Services.ContentManager.UpdateEditorShape(user, this);
model.User = Services.ContentManager.UpdateEditorModel(user, this);
if (!ModelState.IsValid) {
Services.TransactionManager.Cancel();
return View(model);
return View(Shape.Model(model));
}
string userExistsMessage = _userService.VerifyUserUnicity(model.UserName, model.Email);
@@ -87,14 +91,14 @@ namespace Orchard.Users.Controllers {
model.Email,
null, null, true));
model.User = Services.ContentManager.UpdateEditorShape(user, this);
model.User = Services.ContentManager.UpdateEditorModel(user, this);
if (ModelState.IsValid == false) {
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) {
@@ -122,7 +126,7 @@ namespace Orchard.Users.Controllers {
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);
if (userExistsMessage != null) {

View File

@@ -9,7 +9,7 @@ namespace Orchard.Users.Handlers {
public RegistrationSettingsPartHandler(IRepository<RegistrationSettingsPartRecord> repository) {
Filters.Add(new ActivatingFilter<RegistrationSettingsPart>("Site"));
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>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.CSharp" />
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.ComponentModel.DataAnnotations">

View File

@@ -1,6 +1,5 @@
using System.ComponentModel.DataAnnotations;
using Orchard.Mvc.ViewModels;
using Orchard.Security;
using Orchard.ContentManagement;
namespace Orchard.Users.ViewModels {
public class UserCreateViewModel {
@@ -16,6 +15,6 @@ namespace Orchard.Users.ViewModels {
[Required, DataType(DataType.Password)]
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.Web.Mvc;
using Orchard.Mvc.ViewModels;
using Orchard.ContentManagement;
using Orchard.Users.Models;
namespace Orchard.Users.ViewModels {
public class UserEditViewModel {
[HiddenInput(DisplayValue = false)]
public int Id {
get { return User.Item.Id; }
get { return User.ContentItem.Id; }
}
[Required]
public string UserName {
get { return User.Item.Record.UserName; }
set { User.Item.Record.UserName = value; }
get { return User.As<UserPart>().Record.UserName; }
set { User.As<UserPart>().Record.UserName = value; }
}
[Required]
public string Email {
get { return User.Item.Record.Email; }
set { User.Item.Record.Email = value; }
get { return User.As<UserPart>().Record.Email; }
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>
<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" />
<Content Include="Themes\ClassicDark\Content\Images\bodyBackgroundgrey.gif" />
<Content Include="Themes\ClassicDark\Content\Images\sidebarBackground.gif" />
@@ -212,7 +214,7 @@
<Content Include="Themes\Contoso\Theme.txt" />
<Content Include="Themes\Contoso\Views\Footer.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\LogOn.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 */
public static ContentItemViewModel<T> BuildDisplayShape<T>(this IContentManager manager, int id, string displayType) where T : class, IContent {
var content = manager.Get<T>(id);
public static TContent BuildDisplayShape<TContent>(this IContentManager manager, int id, string displayType) where TContent : class, IContent {
var content = manager.Get<TContent>(id);
if (content == 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 {
var content = manager.Get<T>(id);
public static TContent BuildEditorShape<TContent>(this IContentManager manager, int id) where TContent : class, IContent {
var content = manager.Get<TContent>(id);
if (content == 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 {
var content = manager.Get<T>(id);
public static TContent UpdateEditorShape<TContent>(this IContentManager manager, int id, IUpdateModel updater) where TContent : class, IContent {
var content = manager.Get<TContent>(id);
if (content == 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 Orchard.ContentManagement.MetaData.Models;
using Orchard.ContentManagement.Records;
using Orchard.UI;
namespace Orchard.ContentManagement {
public class ContentItem : IContent {
@@ -14,6 +15,13 @@ namespace Orchard.ContentManagement {
private readonly IList<ContentPart> _parts;
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 Version { get { return VersionRecord == null ? 0 : VersionRecord.Number; } }

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using Orchard.ContentManagement.MetaData.Models;
using Orchard.ContentManagement.Utilities;
using Orchard.UI;
namespace Orchard.ContentManagement {
public class ContentPart : IContent {
@@ -13,6 +14,15 @@ namespace Orchard.ContentManagement {
}
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 ContentTypePartDefinition TypePartDefinition { get; set; }
public ContentPartDefinition PartDefinition { get { return TypePartDefinition.PartDefinition; } }

View File

@@ -1,6 +0,0 @@
namespace Orchard.ContentManagement {
public class ContentType {
public string Name { get; set; }
public string DisplayName { get; set; }
}
}

View File

@@ -5,6 +5,7 @@ using Autofac;
using Orchard.ContentManagement.Handlers;
using Orchard.ContentManagement.MetaData;
using Orchard.ContentManagement.MetaData.Builders;
using Orchard.ContentManagement.MetaData.Models;
using Orchard.ContentManagement.Records;
using Orchard.Data;
using Orchard.Indexing;
@@ -43,10 +44,8 @@ namespace Orchard.ContentManagement {
}
}
public IEnumerable<ContentType> GetContentTypes() {
return Handlers.Aggregate(
Enumerable.Empty<ContentType>(),
(types, handler) => types.Concat(handler.GetContentTypes()));
public IEnumerable<ContentTypeDefinition> GetContentTypeDefinitions() {
return _contentDefinitionManager.ListTypeDefinitions();
}
public virtual ContentItem New(string contentType) {
@@ -394,35 +393,28 @@ namespace Orchard.ContentManagement {
return context.Metadata;
}
public ContentItemViewModel<TContentPart> BuildDisplayShape<TContentPart>(TContentPart content, string displayType) where TContentPart : IContent {
if (content == null)
return null;
var displayModel = new ContentItemViewModel<TContentPart>(content);
var context = new BuildDisplayModelContext(displayModel, displayType);
public TContent BuildDisplayModel<TContent>(TContent content, string displayType) where TContent : IContent {
var context = new BuildDisplayModelContext(content, displayType);
foreach (var handler in Handlers) {
handler.BuildDisplayShape(context);
}
return displayModel;
return content;
}
public ContentItemViewModel<TContentPart> BuildEditorShape<TContentPart>(TContentPart content) where TContentPart : IContent {
var editorModel = new ContentItemViewModel<TContentPart>(content);
var context = new BuildEditorModelContext(editorModel);
public TContent BuildEditorModel<TContent>(TContent content) where TContent : IContent {
var context = new BuildEditorModelContext(content);
foreach (var handler in Handlers) {
handler.BuildEditorShape(context);
}
return editorModel;
return content;
}
public ContentItemViewModel<TContentPart> UpdateEditorShape<TContentPart>(TContentPart content, IUpdateModel updater) where TContentPart : IContent {
var editorModel = new ContentItemViewModel<TContentPart>(content);
var context = new UpdateEditorModelContext(editorModel, updater);
public TContent UpdateEditorModel<TContent>(TContent content, IUpdateModel updater) where TContent : IContent {
var context = new UpdateEditorModelContext(content, updater);
foreach (var handler in Handlers) {
handler.UpdateEditorShape(context);
}
return editorModel;
return content;
}
public IContentQuery<ContentItem> Query() {

View File

@@ -12,6 +12,7 @@ namespace Orchard.ContentManagement.Drivers {
public string TemplateName { get; set; }
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)
if (!string.IsNullOrWhiteSpace(context.ViewModel.TemplateName)
&& context.ViewModel.GetType() != typeof(ContentItemViewModel<TContent>))
@@ -26,9 +27,11 @@ namespace Orchard.ContentManagement.Drivers {
html.RouteCollection);
};
}
#endif
}
public override void Apply(BuildEditorModelContext context) {
#if REFACTORING
context.ViewModel.TemplateName = TemplateName;
if (context.ViewModel.GetType() != typeof(ContentItemViewModel<TContent>)) {
context.ViewModel.Adaptor = (html, viewModel) => {
@@ -38,6 +41,7 @@ namespace Orchard.ContentManagement.Drivers {
html.RouteCollection);
};
}
#endif
}
class ViewDataContainer : IViewDataContainer {

View File

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

View File

@@ -1,25 +1,11 @@
using Orchard.ContentManagement.ViewModels;
using Orchard.Mvc.ViewModels;
namespace Orchard.ContentManagement.Handlers {
public class BuildDisplayModelContext {
public BuildDisplayModelContext(ContentItemViewModel viewModel, string displayType) {
ContentItem = viewModel.Item;
public BuildDisplayModelContext(IContent content, string displayType) {
ContentItem = content.ContentItem;
DisplayType = displayType;
ViewModel = viewModel;
}
public ContentItem ContentItem { 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 {
public class BuildEditorModelContext {
public BuildEditorModelContext(ContentItemViewModel viewModel) {
ContentItem = viewModel.Item;
ViewModel = viewModel;
public BuildEditorModelContext(IContent content) {
ContentItem = content.ContentItem;
}
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

@@ -181,10 +181,6 @@ namespace Orchard.ContentManagement.Handlers {
}
}
public virtual IEnumerable<ContentType> GetContentTypes() {
return Enumerable.Empty<ContentType>();
}
void IContentHandler.Activating(ActivatingContentContext context) {
foreach (var filter in Filters.OfType<IContentActivatingFilter>())
filter.Activating(context);

View File

@@ -1,12 +1,5 @@
using System.Collections.Generic;
using System.Linq;
namespace Orchard.ContentManagement.Handlers {
namespace Orchard.ContentManagement.Handlers {
public class ContentHandlerBase : IContentHandler {
public virtual IEnumerable<ContentType> GetContentTypes() {
return Enumerable.Empty<ContentType>();
}
public virtual void Activating(ActivatingContentContext context) {}
public virtual void Activated(ActivatedContentContext context) {}
public virtual void Initializing(InitializingContentContext context) {}

View File

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

View File

@@ -1,9 +1,5 @@
using System.Collections.Generic;
namespace Orchard.ContentManagement.Handlers {
namespace Orchard.ContentManagement.Handlers {
public interface IContentHandler : IEvents {
IEnumerable<ContentType> GetContentTypes();
void Activating(ActivatingContentContext context);
void Activated(ActivatedContentContext context);
void Initializing(InitializingContentContext context);

View File

@@ -3,13 +3,13 @@
namespace Orchard.ContentManagement.Handlers {
public class TemplateFilterForRecord<TRecord> : TemplateFilterBase<ContentPart<TRecord>> where TRecord : ContentPartRecord, new() {
private readonly string _prefix;
private readonly string _templateName;
private string _location;
private string _position;
public TemplateFilterForRecord(string prefix, string templateName) {
public TemplateFilterForRecord(string prefix) {
_prefix = prefix;
_templateName = templateName;
_location = "primary";
_position = "5";
}
public TemplateFilterForRecord<TRecord> Location(string location) {
@@ -17,13 +17,18 @@ namespace Orchard.ContentManagement.Handlers {
return this;
}
public TemplateFilterForRecord<TRecord> Position(string position) {
_position = position;
return this;
}
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) {
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 {
public class UpdateEditorModelContext : BuildEditorModelContext {
public UpdateEditorModelContext(ContentItemViewModel viewModel, IUpdateModel updater)
: base(viewModel) {
public UpdateEditorModelContext(IContent content, IUpdateModel updater)
: base(content) {
Updater = updater;
}

View File

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

View File

@@ -1,10 +1,11 @@
using System.Collections.Generic;
using Orchard.ContentManagement.MetaData.Models;
using Orchard.Indexing;
using Orchard.Mvc.ViewModels;
namespace Orchard.ContentManagement {
public interface IContentManager : IDependency {
IEnumerable<ContentType> GetContentTypes();
IEnumerable<ContentTypeDefinition> GetContentTypeDefinitions();
ContentItem New(string contentType);
@@ -26,9 +27,9 @@ namespace Orchard.ContentManagement {
ContentItemMetadata GetItemMetadata(IContent contentItem);
ContentItemViewModel<TContent> BuildDisplayShape<TContent>(TContent content, string displayType) where TContent : IContent;
ContentItemViewModel<TContent> BuildEditorShape<TContent>(TContent content) where TContent : IContent;
ContentItemViewModel<TContent> UpdateEditorShape<TContent>(TContent content, IUpdateModel updater) where TContent : IContent;
TContent BuildDisplayModel<TContent>(TContent content, string displayType) where TContent : IContent;
TContent BuildEditorModel<TContent>(TContent content) where TContent : IContent;
TContent UpdateEditorModel<TContent>(TContent content, IUpdateModel updater) where TContent : IContent;
}
public class VersionOptions {

View File

@@ -5,7 +5,8 @@ using System.Web.Mvc.Html;
using Orchard.Mvc.ViewModels;
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 {
return html.DisplayForItem(x => item);
}
@@ -21,4 +22,5 @@ namespace Orchard.Mvc.Html {
return html.DisplayFor(expression, model.TemplateName, model.Prefix ?? "");
}
}
#endif
}

View File

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

View File

@@ -2,18 +2,18 @@
using System.IO;
using System.Web.Mvc;
using System.Web.UI;
using Microsoft.WebPages;
using Orchard.Mvc.ViewEngines;
using Orchard.Mvc.ViewModels;
using Orchard.UI.PageClass;
using Orchard.UI.PageTitle;
using Orchard.UI.Resources;
using Orchard.UI.Zones;
using HtmlHelper = System.Web.Mvc.HtmlHelper;
namespace Orchard.Mvc.Html {
public static class LayoutExtensions {
public static void RenderBody(this HtmlHelper html) {
public static HelperResult RenderOrchardBody(this HtmlHelper html) {
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) {
@@ -61,35 +61,6 @@ namespace Orchard.Mvc.Html {
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) {
html.Resolve<IResourceManager>().RegisterMeta(name, content);
}

View File

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

View File

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

View File

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

View File

@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Web.Mvc;
namespace Orchard.UI {
@@ -10,10 +11,42 @@ namespace Orchard.UI {
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 {
void Add(object item);
void Add(object item, string position);
void Add(Action<HtmlHelper> action);
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) {
#if REFACTORING
var menuName = "main";
if (AdminFilter.IsApplied(filterContext.RequestContext))
menuName = "admin";
@@ -23,6 +24,7 @@ namespace Orchard.UI.Navigation {
//todo: (heskew) does the menu need to be on Page?
var shape = _shapeHelperFactory.CreateHelper();
_workContextAccessor.GetContext(filterContext).CurrentPage.Zones["Navigation"].Add(shape.Menu(_navigationManager.BuildMenu(menuName)));
#endif
}
public void OnResultExecuted(ResultExecutedContext filterContext) {}

View File

@@ -14,6 +14,7 @@ namespace Orchard.UI.Resources {
}
public void OnResultExecuting(ResultExecutingContext filterContext) {
#if REFACTORING
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.GetStyles()), ":styles");
@@ -28,6 +29,7 @@ namespace Orchard.UI.Resources {
html.ViewContext.Writer.Write(captured);
},
":after");
#endif
}
public void OnResultExecuted(ResultExecutedContext filterContext) {}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -5,6 +5,7 @@ using System.Web.Routing;
using Orchard.Mvc.ViewModels;
namespace Orchard.UI.Zones {
#if REFACTORING
public interface IZoneContainer {
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;
namespace Orchard.UI.Zones {
#if REFACTORING
public class ZoneManager : IZoneManager {
private readonly IEnumerable<IZoneManagerEvents> _zoneManagerEventHandler;
@@ -95,4 +95,5 @@ namespace Orchard.UI.Zones {
public IEnumerable<ZoneItem> Items { get; set; }
}
}
#endif
}