mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-22 20:13:50 +08:00
Updating displays/editors api to include a content item view model.
--HG-- extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4043002
This commit is contained in:
@@ -40,7 +40,7 @@ namespace Orchard.Sandbox.Controllers {
|
||||
var page = _contentManager.Get<SandboxPage>(id);
|
||||
var model = new PageShowViewModel {
|
||||
Page = page,
|
||||
ItemView = _contentManager.GetDisplays(page, null, null)
|
||||
ItemView = _contentManager.GetDisplays(page, null, "Detail")
|
||||
};
|
||||
return View(model);
|
||||
}
|
||||
|
@@ -4,6 +4,7 @@ using Orchard.Core.Common.Models;
|
||||
using Orchard.Data;
|
||||
using Orchard.Models;
|
||||
using Orchard.Models.Driver;
|
||||
using Orchard.Models.ViewModels;
|
||||
|
||||
namespace Orchard.Sandbox.Models {
|
||||
public class SandboxContentProvider : ContentProvider {
|
||||
@@ -43,6 +44,15 @@ namespace Orchard.Sandbox.Models {
|
||||
});
|
||||
});
|
||||
|
||||
//TODO: helper that glues this for free - include list of known-displaytype prefixes
|
||||
|
||||
OnGetDisplays<SandboxPage>((context, page) => context.ItemView.TemplateName = "SandboxPage" + context.DisplayType);
|
||||
OnGetEditors<SandboxPage>((context, page) => context.ItemView.TemplateName = "SandboxPage");
|
||||
OnUpdateEditors<SandboxPage>((context, page) => {
|
||||
context.Updater.TryUpdateModel((ItemEditorViewModel<SandboxPage>)context.ItemView, "", null, null);
|
||||
context.ItemView.TemplateName = "SandboxPage";
|
||||
});
|
||||
|
||||
// add settings to site, and simple record-template gui
|
||||
Filters.Add(new ActivatingFilter<ContentPart<SandboxSettingsRecord>>("site"));
|
||||
Filters.Add(new StorageFilter<SandboxSettingsRecord>(settingsRepository) { AutomaticallyCreateMissingRecord = true });
|
||||
|
@@ -75,6 +75,9 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Package.txt" />
|
||||
<Content Include="Views\Models\DisplayTemplates\SandboxPageList.ascx" />
|
||||
<Content Include="Views\Models\DisplayTemplates\SandboxPageDetail.ascx" />
|
||||
<Content Include="Views\Models\EditorTemplates\SandboxPage.ascx" />
|
||||
<Content Include="Views\Models\EditorTemplates\SandboxSettingsRecord.ascx" />
|
||||
<Content Include="Views\Page\Edit.aspx" />
|
||||
<Content Include="Views\Page\Create.aspx" />
|
||||
|
@@ -0,0 +1,14 @@
|
||||
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<ItemDisplayViewModel<SandboxPage>>" %>
|
||||
<%@ Import Namespace="Orchard.Mvc.Html"%>
|
||||
<%@ Import Namespace="Orchard.Sandbox.Models" %>
|
||||
<%@ Import Namespace="Orchard.Models.ViewModels" %>
|
||||
<%@ Import Namespace="Orchard.Models" %>
|
||||
|
||||
<h1><%=Html.Encode(Model.Item.Record.Name) %></h1>
|
||||
|
||||
<%foreach (var display in Model.Displays) { %>
|
||||
<%=Html.DisplayFor(m=>display.Model, display.TemplateName, display.Prefix) %>
|
||||
<%} %>
|
||||
|
||||
<p>
|
||||
<%=Html.ItemEditLink("Edit this page", Model.Item) %>, <%=Html.ActionLink("Return to list", "index") %></p>
|
@@ -0,0 +1,8 @@
|
||||
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<ItemDisplayViewModel<SandboxPage>>" %>
|
||||
<%@ Import Namespace="Orchard.Sandbox.Models" %>
|
||||
<%@ Import Namespace="Orchard.Models.ViewModels" %>
|
||||
<%@ Import Namespace="Orchard.Models" %>
|
||||
<h1><%=Html.Encode(Model.Item.Record.Name) %></h1>
|
||||
<%foreach (var display in Model.Displays) { %>
|
||||
<%=Html.DisplayFor(m=>display.Model, display.TemplateName, display.Prefix??"") %>
|
||||
<%} %>
|
@@ -0,0 +1,14 @@
|
||||
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<ItemEditorViewModel<SandboxPage>>" %>
|
||||
<%@ Import Namespace="Orchard.Sandbox.Models" %>
|
||||
<%@ Import Namespace="Orchard.Models.ViewModels" %>
|
||||
<%@ Import Namespace="Orchard.Models" %>
|
||||
|
||||
|
||||
<li>
|
||||
<%=Html.LabelFor(m => m.Item.Record.Name)%>
|
||||
<%=Html.EditorFor(m => m.Item.Record.Name)%>
|
||||
</li>
|
||||
|
||||
<%foreach (var e in Model.Editors) { %>
|
||||
<%=Html.EditorFor(m=>e.Model, e.TemplateName, e.Prefix??"") %>
|
||||
<%} %>
|
@@ -1,14 +1,12 @@
|
||||
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Orchard.Sandbox.Models.SandboxSettingsRecord>" %>
|
||||
<h3>Sandbox</h3>
|
||||
<ol>
|
||||
<li>
|
||||
<%= Html.LabelFor(x=>x.AllowAnonymousEdits) %>
|
||||
<%= Html.EditorFor(x=>x.AllowAnonymousEdits) %>
|
||||
<%= Html.ValidationMessage("AllowAnonymousEdits", "*")%>
|
||||
</li>
|
||||
<li>
|
||||
<%= Html.LabelFor(x => x.NameOfThemeWhenEditingPage)%>
|
||||
<%= Html.EditorFor(x=>x.NameOfThemeWhenEditingPage) %>
|
||||
<%= Html.ValidationMessage("NameOfThemeWhenEditingPage", "*")%>
|
||||
</li>
|
||||
</ol>
|
||||
<fieldset>
|
||||
<legend>Sandbox</legend>
|
||||
<%= Html.LabelFor(x=>x.AllowAnonymousEdits) %>
|
||||
<%= Html.EditorFor(x=>x.AllowAnonymousEdits) %>
|
||||
<%= Html.ValidationMessage("AllowAnonymousEdits", "*")%>
|
||||
<br />
|
||||
<%= Html.LabelFor(x => x.NameOfThemeWhenEditingPage)%>
|
||||
<%= Html.EditorFor(x=>x.NameOfThemeWhenEditingPage) %>
|
||||
<%= Html.ValidationMessage("NameOfThemeWhenEditingPage", "*")%>
|
||||
<br />
|
||||
</fieldset>
|
||||
|
@@ -24,13 +24,17 @@
|
||||
Edit Page</h3>
|
||||
<%using (Html.BeginForm()) { %>
|
||||
<ul>
|
||||
<li>
|
||||
<%=Html.EditorFor(m => m.ItemView, Model.ItemView.TemplateName, Model.ItemView.Prefix ?? "")%>
|
||||
|
||||
<li><input type="submit" name="submit" value="Save" /></li>
|
||||
|
||||
<%-- <li>
|
||||
<%=Html.LabelFor(x => x.Page.Record.Name)%><%=Html.EditorFor(x => x.Page.Record.Name)%></li>
|
||||
<%foreach (var x in Model.ItemView.Editors) { %>
|
||||
<%=Html.EditorFor(m=>x.Model, x.TemplateName, x.Prefix) %>
|
||||
<%} %>
|
||||
<li>
|
||||
<input type="submit" name="submit" value="Save" /></li>
|
||||
<input type="submit" name="submit" value="Save" /></li>--%>
|
||||
</ul>
|
||||
<%} %>
|
||||
</div>
|
||||
|
@@ -20,13 +20,14 @@
|
||||
</div>
|
||||
<div id="main">
|
||||
<% Html.RenderPartial("Messages", Model.Messages); %>
|
||||
<h1><%=Html.Encode(Model.Page.Record.Name) %></h1>
|
||||
<%=Html.DisplayFor(m => m.ItemView, Model.ItemView.TemplateName, "")%>
|
||||
<%-- <h1><%=Html.Encode(Model.Page.Record.Name) %></h1>
|
||||
<%foreach (var display in Model.ItemView.Displays) { %>
|
||||
<%=Html.DisplayFor(m=>display.Model, display.TemplateName, display.Prefix) %>
|
||||
<%} %>
|
||||
<p>
|
||||
<%=Html.ActionLink("Edit this page", "edit", new{Model.Page.ContentItem.Id}, new{}) %>, <%=Html.ActionLink("Return to list", "index") %></p>
|
||||
</div>
|
||||
--%> </div>
|
||||
<div id="footer">
|
||||
<% Html.Include("footer"); %>
|
||||
</div>
|
||||
|
@@ -7,7 +7,7 @@ namespace Orchard.Models {
|
||||
public RouteValueDictionary DisplayRouteValues { get; set; }
|
||||
public RouteValueDictionary EditorRouteValues { get; set; }
|
||||
|
||||
public IEnumerable<string> DisplayTabs { get; set; }
|
||||
public IEnumerable<string> EditorTabs { get; set; }
|
||||
public IEnumerable<string> DisplayGroups { get; set; }
|
||||
public IEnumerable<string> EditorGroups { get; set; }
|
||||
}
|
||||
}
|
@@ -136,32 +136,35 @@ namespace Orchard.Models {
|
||||
return context.Metadata;
|
||||
}
|
||||
|
||||
public ItemDisplayViewModel GetDisplays(IContent content, string tabName, string displayType) {
|
||||
var context = new GetDisplaysContext(content);
|
||||
public ItemDisplayViewModel<TContentPart> GetDisplays<TContentPart>(TContentPart content, string groupName, string displayType) where TContentPart : IContent {
|
||||
var itemView = new ItemDisplayViewModel<TContentPart> {Item = content, Displays = Enumerable.Empty<TemplateViewModel>()};
|
||||
var context = new GetDisplaysContext(itemView, groupName, displayType);
|
||||
foreach (var driver in Drivers) {
|
||||
driver.GetDisplays(context);
|
||||
}
|
||||
context.ItemView.Displays = OrderTemplates(context.ItemView.Displays);
|
||||
return context.ItemView;
|
||||
return itemView;
|
||||
}
|
||||
|
||||
public ItemEditorViewModel GetEditors(IContent content, string tabName) {
|
||||
var context = new GetEditorsContext(content);
|
||||
public ItemEditorViewModel<TContentPart> GetEditors<TContentPart>(TContentPart content, string groupName) where TContentPart : IContent {
|
||||
var itemView = new ItemEditorViewModel<TContentPart> { Item = content, Editors = Enumerable.Empty<TemplateViewModel>() };
|
||||
var context = new GetEditorsContext(itemView, groupName);
|
||||
foreach (var driver in Drivers) {
|
||||
driver.GetEditors(context);
|
||||
}
|
||||
context.ItemView.Editors = OrderTemplates(context.ItemView.Editors);
|
||||
return context.ItemView;
|
||||
return itemView;
|
||||
}
|
||||
|
||||
public ItemEditorViewModel UpdateEditors(IContent content, string tabName, IUpdateModel updater) {
|
||||
public ItemEditorViewModel<TContentPart> UpdateEditors<TContentPart>(TContentPart content, string groupName, IUpdateModel updater) where TContentPart : IContent {
|
||||
var itemView = new ItemEditorViewModel<TContentPart> { Item = content, Editors = Enumerable.Empty<TemplateViewModel>() };
|
||||
|
||||
var context = new UpdateContentContext(content, updater);
|
||||
var context = new UpdateContentContext(itemView, groupName, updater);
|
||||
foreach (var driver in Drivers) {
|
||||
driver.UpdateEditors(context);
|
||||
}
|
||||
context.ItemView.Editors = OrderTemplates(context.ItemView.Editors);
|
||||
return context.ItemView;
|
||||
return itemView;
|
||||
}
|
||||
|
||||
private static IEnumerable<TemplateViewModel> OrderTemplates(IEnumerable<TemplateViewModel> templates) {
|
||||
|
@@ -1,20 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Orchard.Models.ViewModels;
|
||||
|
||||
namespace Orchard.Models.Driver {
|
||||
public class GetDisplaysContext {
|
||||
public GetDisplaysContext(IContent content) {
|
||||
ContentItem = content.ContentItem;
|
||||
ItemView = new ItemDisplayViewModel {
|
||||
ContentItem = ContentItem,
|
||||
Displays = Enumerable.Empty<TemplateViewModel>(),
|
||||
};
|
||||
public GetDisplaysContext(ItemDisplayViewModel itemView, string groupName, string displayType) {
|
||||
ContentItem = itemView.Item;
|
||||
GroupName = groupName;
|
||||
DisplayType = displayType;
|
||||
ItemView = itemView;
|
||||
}
|
||||
|
||||
|
||||
public ContentItem ContentItem { get; set; }
|
||||
public string GroupName { get; set; }
|
||||
public string DisplayType { get; set; }
|
||||
public ItemDisplayViewModel ItemView { get; set; }
|
||||
|
||||
|
||||
|
||||
public void AddDisplay(TemplateViewModel display) {
|
||||
ItemView.Displays = ItemView.Displays.Concat(new[] { display });
|
||||
}
|
||||
|
@@ -5,15 +5,14 @@ using Orchard.Models.ViewModels;
|
||||
|
||||
namespace Orchard.Models.Driver {
|
||||
public class GetEditorsContext {
|
||||
public GetEditorsContext(IContent content) {
|
||||
ContentItem = content.ContentItem;
|
||||
ItemView = new ItemEditorViewModel {
|
||||
ContentItem = ContentItem,
|
||||
Editors = Enumerable.Empty<TemplateViewModel>(),
|
||||
};
|
||||
public GetEditorsContext(ItemEditorViewModel itemView, string groupName) {
|
||||
ContentItem = itemView.Item;
|
||||
GroupName = groupName;
|
||||
ItemView = itemView;
|
||||
}
|
||||
|
||||
public ContentItem ContentItem { get; set; }
|
||||
public string GroupName { get; set; }
|
||||
public ItemEditorViewModel ItemView { get; set; }
|
||||
|
||||
public void AddEditor(TemplateViewModel editor) {
|
||||
|
@@ -1,6 +1,9 @@
|
||||
using Orchard.Models.ViewModels;
|
||||
|
||||
namespace Orchard.Models.Driver {
|
||||
public class UpdateContentContext : GetEditorsContext {
|
||||
public UpdateContentContext(IContent content, IUpdateModel updater) : base(content) {
|
||||
public UpdateContentContext(ItemEditorViewModel itemView, string groupName, IUpdateModel updater)
|
||||
: base(itemView, groupName) {
|
||||
Updater = updater;
|
||||
}
|
||||
|
||||
|
@@ -15,8 +15,8 @@ namespace Orchard.Models {
|
||||
IContentQuery<ContentItem> Query();
|
||||
|
||||
ContentItemMetadata GetItemMetadata(IContent contentItem);
|
||||
ItemDisplayViewModel GetDisplays(IContent contentItem, string tabName, string displayType);
|
||||
ItemEditorViewModel GetEditors(IContent contentItem, string tabName);
|
||||
ItemEditorViewModel UpdateEditors(IContent contentItem, string tabName, IUpdateModel updater);
|
||||
ItemDisplayViewModel<TContentPart> GetDisplays<TContentPart>(TContentPart contentItem, string groupName, string displayType) where TContentPart : IContent;
|
||||
ItemEditorViewModel<TContentPart> GetEditors<TContentPart>(TContentPart contentItem, string groupName) where TContentPart : IContent;
|
||||
ItemEditorViewModel<TContentPart> UpdateEditors<TContentPart>(TContentPart contentItem, string groupName, IUpdateModel updater) where TContentPart : IContent;
|
||||
}
|
||||
}
|
||||
|
@@ -1,9 +1,33 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Orchard.Models.ViewModels {
|
||||
public class ItemDisplayViewModel {
|
||||
public ContentItem ContentItem { get; set; }
|
||||
public class ItemDisplayViewModel {
|
||||
private ContentItem _item;
|
||||
public ContentItem Item {
|
||||
get { return _item; }
|
||||
set { SetItem(value); }
|
||||
}
|
||||
|
||||
protected virtual void SetItem(ContentItem value) {
|
||||
_item = value;
|
||||
}
|
||||
|
||||
public string TemplateName { get; set; }
|
||||
public string Prefix { get; set; }
|
||||
public IEnumerable<TemplateViewModel> Displays { get; set; }
|
||||
}
|
||||
|
||||
public class ItemDisplayViewModel<TPart> : ItemDisplayViewModel where TPart : IContent {
|
||||
private TPart _item;
|
||||
public new TPart Item {
|
||||
get { return _item; }
|
||||
set { SetItem(value.ContentItem); }
|
||||
}
|
||||
|
||||
protected override void SetItem(ContentItem value) {
|
||||
_item = value.As<TPart>();
|
||||
base.SetItem(value);
|
||||
}
|
||||
}
|
||||
}
|
@@ -2,8 +2,32 @@ using System.Collections.Generic;
|
||||
|
||||
namespace Orchard.Models.ViewModels {
|
||||
public class ItemEditorViewModel {
|
||||
public ContentItem ContentItem { get; set; }
|
||||
private ContentItem _item;
|
||||
public ContentItem Item {
|
||||
get { return _item; }
|
||||
set { SetItem(value); }
|
||||
}
|
||||
|
||||
protected virtual void SetItem(ContentItem value) {
|
||||
_item = value;
|
||||
}
|
||||
|
||||
public string TemplateName { get; set; }
|
||||
public string Prefix { get; set; }
|
||||
|
||||
public IEnumerable<TemplateViewModel> Editors { get; set; }
|
||||
}
|
||||
|
||||
public class ItemEditorViewModel<TPart> : ItemEditorViewModel where TPart : IContent {
|
||||
private TPart _item;
|
||||
public new TPart Item {
|
||||
get { return _item; }
|
||||
set { SetItem(value.ContentItem); }
|
||||
}
|
||||
|
||||
protected override void SetItem(ContentItem value) {
|
||||
_item = value.As<TPart>();
|
||||
base.SetItem(value);
|
||||
}
|
||||
}
|
||||
}
|
@@ -15,13 +15,14 @@ namespace Orchard.Tasks {
|
||||
_timer = new Timer();
|
||||
_timer.Elapsed += Elapsed;
|
||||
Logger = NullLogger.Instance;
|
||||
Interval = TimeSpan.FromMinutes(5);
|
||||
}
|
||||
|
||||
public ILogger Logger { get; set; }
|
||||
|
||||
public TimeSpan Interval {
|
||||
get { return TimeSpan.FromMilliseconds(_timer.Interval); }
|
||||
set { _timer.Interval = value.Milliseconds; }
|
||||
set { _timer.Interval = value.TotalMilliseconds; }
|
||||
}
|
||||
|
||||
public void Activated() {
|
||||
|
Reference in New Issue
Block a user