Adding scope ctor parameter to localization component.

--HG--
extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4041484
This commit is contained in:
loudej
2009-11-20 02:49:20 +00:00
parent b759bba2ec
commit 35b1b5a1d4
18 changed files with 207 additions and 83 deletions

View File

@@ -1,9 +1,51 @@
using Orchard.Core.Common.Records;
using System;
using Orchard.Core.Common.Records;
using Orchard.Models;
using Orchard.Security;
namespace Orchard.Core.Common.Models {
public class CommonPart : ContentPartForRecord<CommonRecord> {
public IUser Owner { get; set; }
private readonly Lazy<IUser> _owner = new Lazy<IUser>();
private readonly Lazy<ContentItem> _container = new Lazy<ContentItem>();
public IUser Owner {
get { return _owner.Value; }
set { _owner.Value = value; }
}
public ContentItem Container {
get { return _container.Value; }
set { _container.Value = value; }
}
public void LoadOwner(Func<IUser> loader) {
_owner.Loader(loader);
}
public void LoadContainer(Func<ContentItem> loader) {
_container.Loader(loader);
}
}
public class Lazy<T> {
private Func<T> _loader;
private T _value;
public void Loader(Func<T> loader) {
_loader = loader;
}
public T Value {
get {
if (_loader != null) {
_value = _loader();
_loader = null;
}
return _value;
}
set {
_value = value;
_loader = null;
}
}
}
}

View File

@@ -40,10 +40,17 @@ namespace Orchard.Core.Common.Models {
}
}
void LoadOwnerModel(LoadContentContext context, CommonPart instance) {
if (instance.Record.OwnerId != 0) {
instance.Owner = _contentManager.Get(instance.Record.OwnerId).As<IUser>();
}
protected override void UpdateEditors(UpdateContentContext context) {
var part = context.ContentItem.As<CommonPart>();
if (part==null)
return;
part.Record.ModifiedUtc = _clock.UtcNow;
}
void LoadOwnerModel(LoadContentContext context, CommonPart part) {
part.LoadOwner(() => _contentManager.Get<IUser>(part.Record.OwnerId));
part.LoadContainer(() => part.Record.Container == null ? null : _contentManager.Get(part.Record.Container.Id));
}
}
}

View File

@@ -4,6 +4,7 @@ using Orchard.Models.Records;
namespace Orchard.Core.Common.Records {
public class CommonRecord : ContentPartRecord {
public virtual int OwnerId { get; set; }
public virtual ContentItemRecord Container { get; set; }
public virtual DateTime? CreatedUtc { get; set; }
public virtual DateTime? ModifiedUtc { get; set; }
}

View File

@@ -1,4 +1,5 @@
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<Orchard.DevTools.ViewModels.ContentDetailsViewModel>" %>
<%@ Import Namespace="Orchard.Models"%>
<%@ Import Namespace="System.Reflection" %>
<%@ Import Namespace="Orchard.Mvc.Html" %>
@@ -36,13 +37,23 @@
<%=Html.Encode(" (" + partType.GetGenericArguments().First().Namespace + ")")%><%}
else {%><%=Html.Encode(partType.Name)%></span>
<%=Html.Encode( " (" + partType.Namespace + ")")%><%
}%>
}
%>
<ul style="margin-left: 20px">
<%foreach (var prop in partType.GetProperties().Where(x => x.DeclaringType == partType)) {
var value = prop.GetValue(Model.Locate(partType), null);%>
<li style="font-weight: normal;">
<%=Html.Encode(prop.Name) %>:
<%=Html.Encode(value) %>
<%var valueItem = value as ContentItem;
if (valueItem == null && value is IContentItemPart) {
valueItem = (value as IContentItemPart).ContentItem;
}
if (valueItem != null) {
%><%=Html.ActionLink(valueItem.ContentType + " #" + valueItem.Id, "details", new { valueItem.Id }, new { })%><%
}
%>
<ul style="margin-left: 20px">
<%if (value == null || prop.PropertyType.IsPrimitive || prop.PropertyType == typeof(string)) { }
else if (typeof(IEnumerable).IsAssignableFrom(prop.PropertyType)) {

View File

@@ -1,14 +1,14 @@
using Orchard.UI.Navigation;
namespace Orchard.Wikis {
public class AdminMenu : INavigationProvider {
public string MenuName { get { return "admin"; } }
//public class AdminMenu : INavigationProvider {
// public string MenuName { get { return "admin"; } }
public void GetNavigation(NavigationBuilder builder) {
builder.Add("Wiki", "9",
menu => menu
.Add("Wiki Pages", "1.0", item => item.Action("Index", "Admin", new { area = "Orchard.Wikis" }))
);
}
}
// public void GetNavigation(NavigationBuilder builder) {
// builder.Add("Wiki", "9",
// menu => menu
// .Add("Wiki Pages", "1.0", item => item.Action("Index", "Admin", new { area = "Orchard.Wikis" }))
// );
// }
//}
}

View File

@@ -6,28 +6,28 @@ using Orchard.Security;
namespace Orchard.Wikis.Controllers {
public class AdminController : Controller {
private readonly IContentManager _contentManager;
//private readonly IContentManager _contentManager;
public AdminController(IContentManager contentManager) {
_contentManager = contentManager;
}
//public AdminController(IContentManager contentManager) {
// _contentManager = contentManager;
//}
public ActionResult Index() {
return View(new AdminViewModel());
}
//public ActionResult Index() {
// return View(new AdminViewModel());
//}
public IUser CurrentUser { get; set; }
//public IUser CurrentUser { get; set; }
public ActionResult Create() {
var page = _contentManager.New("wikipage");
_contentManager.Create(page);
//public ActionResult Create() {
// var page = _contentManager.New("wikipage");
// _contentManager.Create(page);
return RedirectToAction("View", new{page.Id});
}
// return RedirectToAction("View", new{page.Id});
//}
public ActionResult View(int id) {
var page = _contentManager.Get(id).As<CommonPart>();
return View(page);
}
//public ActionResult View(int id) {
// var page = _contentManager.Get(id).As<CommonPart>();
// return View(page);
//}
}
}

View File

@@ -1,9 +1,11 @@
using System;
using System.Linq;
using System.Web.Mvc;
using Orchard.Core.Common.Models;
using Orchard.Data;
using Orchard.Models;
using Orchard.Models.Driver;
using Orchard.Settings;
using Orchard.Wikis.Models;
using Orchard.Wikis.ViewModels;
@@ -39,10 +41,13 @@ namespace Orchard.Wikis.Controllers
return View(new PageCreateViewModel());
}
public ISite CurrentSite { get; set; }
[HttpPost]
public ActionResult Create(PageCreateViewModel model) {
var page = _contentManager.New<WikiPage>("wikipage");
page.Record.Name = model.Name;
page.As<CommonPart>().Container = CurrentSite.ContentItem;
_contentManager.Create(page);
return RedirectToAction("show", new {page.ContentItem.Id});
}

View File

@@ -20,14 +20,10 @@ todo: (heskew) rework how/what pages are assembled when we get into theming --%>
</head>
<body>
<div id="banner" role="banner">
<h1><%=Html.ActionLink(_("Project Orchard"), "Index", new { Area = "", Controller = "Home" })%></h1>
<div><%=Html.ActionLink(_("Your Site"), "Index", new { Area = "", Controller = "Home" })%></div>
<h1><%=Html.ActionLink(T("Project Orchard").ToString(), "Index", new { Area = "", Controller = "Home" })%></h1>
<div><%=Html.ActionLink(T("Your Site").ToString(), "Index", new { Area = "", Controller = "Home" })%></div>
<% if (Model.CurrentUser != null) {
%><div id="login"><%=_(
"User: {0} | {1}",
Model.CurrentUser.UserName, /* todo: (heskew) need some encode extension methods */
Html.ActionLink("Logout", "LogOff", new { Area = "", Controller = "Account" }).ToString()
)%></div><%
%><div id="login"><%=T("User")%><%=H(Model.CurrentUser.UserName)%> | <%=Html.ActionLink(T("Logout").ToString(), "LogOff", new { Area = "", Controller = "Account" }) %></div><%
} %>
</div>
<div id="main" role="main">