Fix remaining issues with DateTimeRelative, etc. shapes

--HG--
branch : dev
This commit is contained in:
Renaud Paquay
2010-10-18 20:03:33 -07:00
parent 42344af36e
commit 0601e2fb24
21 changed files with 54 additions and 60 deletions

View File

@@ -1,26 +0,0 @@
using System;
using System.Web;
using System.Web.Mvc;
using Orchard.DisplayManagement;
using Orchard.Localization;
using Orchard.Mvc.Html;
namespace Orchard.Core.Common.Extensions {
public class Shapes {
public Shapes() {
T = NullLocalizer.Instance;
}
public Localizer T { get; set; }
[Shape]
public IHtmlString PublishedState(HtmlHelper Html, DateTime? versionPublishedUtc) {
return Html.DateTime(versionPublishedUtc, T("Draft"));
}
[Shape]
public IHtmlString PublishedWhen(dynamic Display, HtmlHelper Html, DateTime? versionPublishedUtc) {
return Display.DateTimeRelative(dateTime: versionPublishedUtc, defaultIfNull: T("as a Draft"));
}
}
}

View File

@@ -0,0 +1,31 @@
using System;
using System.Web;
using System.Web.Mvc;
using Orchard.DisplayManagement;
using Orchard.Localization;
using Orchard.Mvc.Html;
namespace Orchard.Core.Common {
public class Shapes : IDependency {
public Shapes() {
T = NullLocalizer.Instance;
}
public Localizer T { get; set; }
[Shape]
public IHtmlString PublishedState(HtmlHelper Html, DateTime? dateTimeUtc) {
return Html.DateTime(dateTimeUtc, T("Draft"));
}
[Shape]
public IHtmlString PublishedWhen(dynamic Display, DateTime? dateTimeUtc) {
if (dateTimeUtc == null) {
return T("as a Draft");
}
else {
return Display.DateTimeRelative(dateTimeUtc: dateTimeUtc);
}
}
}
}

View File

@@ -1,2 +1 @@
@using Orchard.Core.Common.Extensions; <div class="published">@Display.PublishedState(dateTimeUtc: Model.ContentPart.VersionPublishedUtc)</div>
<div class="published">@Display.PublishedState(versionPublishedUtc: (DateTime?)Model.ContentPart.VersionPublishedUtc)</div>

View File

@@ -9,7 +9,7 @@
} }
<ul class="pageStatus"> <ul class="pageStatus">
<li>@if (modifiedUtc.HasValue) { <li>@if (modifiedUtc.HasValue) {
@T("Last modified: {0}", Display.DateTimeRelative(dateTime: modifiedUtc.Value))}&nbsp;&#124;&nbsp; @T("Last modified: {0}", Display.DateTimeRelative(dateTimeUtc: modifiedUtc.Value))}&nbsp;&#124;&nbsp;
</li> </li>
<li>@T("By {0}", owner.UserName)</li> <li>@T("By {0}", owner.UserName)</li>
</ul> </ul>

View File

@@ -1,2 +1 @@
@using Orchard.Core.Common.Extensions; <div class="published">@Display.PublishedState(dateTimeUtc: Model.ContentPart.VersionPublishedUtc)</div>
<div class="published">@Display.PublishedState(versionPublishedUtc: (DateTime?)Model.ContentPart.VersionPublishedUtc)</div>

View File

@@ -70,7 +70,7 @@
<Compile Include="Common\Drivers\BodyPartDriver.cs" /> <Compile Include="Common\Drivers\BodyPartDriver.cs" />
<Compile Include="Common\Drivers\CommonPartDriver.cs" /> <Compile Include="Common\Drivers\CommonPartDriver.cs" />
<Compile Include="Common\Drivers\TextFieldDriver.cs" /> <Compile Include="Common\Drivers\TextFieldDriver.cs" />
<Compile Include="Common\Extensions\HtmlHelperExtensions.cs" /> <Compile Include="Common\Shapes.cs" />
<Compile Include="Common\Fields\TextField.cs" /> <Compile Include="Common\Fields\TextField.cs" />
<Compile Include="Contents\Security\AuthorizationEventHandler.cs" /> <Compile Include="Contents\Security\AuthorizationEventHandler.cs" />
<Compile Include="Common\Services\BbcodeFilter.cs" /> <Compile Include="Common\Services\BbcodeFilter.cs" />
@@ -231,6 +231,7 @@
<Compile Include="Settings\ViewModels\SiteSettingsPartViewModel.cs" /> <Compile Include="Settings\ViewModels\SiteSettingsPartViewModel.cs" />
<Compile Include="Shapes\ResourceManifest.cs" /> <Compile Include="Shapes\ResourceManifest.cs" />
<Compile Include="Shapes\CoreShapes.cs" /> <Compile Include="Shapes\CoreShapes.cs" />
<Compile Include="Shapes\DateTimeShapes.cs" />
<Compile Include="XmlRpc\Controllers\HomeController.cs" /> <Compile Include="XmlRpc\Controllers\HomeController.cs" />
<Compile Include="XmlRpc\Controllers\LiveWriterController.cs" /> <Compile Include="XmlRpc\Controllers\LiveWriterController.cs" />
<Compile Include="XmlRpc\IXmlRpcHandler.cs" /> <Compile Include="XmlRpc\IXmlRpcHandler.cs" />

View File

@@ -6,5 +6,5 @@
DateTime? versionPublishedUtc = publishLaterPart.As<CommonPart>() == null ? null : publishLaterPart.As<CommonPart>().VersionPublishedUtc; DateTime? versionPublishedUtc = publishLaterPart.As<CommonPart>() == null ? null : publishLaterPart.As<CommonPart>().VersionPublishedUtc;
} }
@if (publishLaterPart.IsPublished() && versionPublishedUtc.HasValue) { @if (publishLaterPart.IsPublished() && versionPublishedUtc.HasValue) {
@T("Published: {0}", Display.DateTimeRelative(versionPublishedUtc.Value)) @T(" | ") @T("Published: {0}", Display.DateTimeRelative(dateTimeUtc: versionPublishedUtc.Value)) @T(" | ")
} }

View File

@@ -26,7 +26,7 @@
@if ((((DateTime?)Model.ScheduledPublishUtc).HasValue && ((DateTime?)Model.ScheduledPublishUtc).Value > DateTime.UtcNow) || (publishLaterPart.IsPublished() && versionPublishedUtc.HasValue)) { @if ((((DateTime?)Model.ScheduledPublishUtc).HasValue && ((DateTime?)Model.ScheduledPublishUtc).Value > DateTime.UtcNow) || (publishLaterPart.IsPublished() && versionPublishedUtc.HasValue)) {
<li> <li>
@if (publishLaterPart.IsPublished() && versionPublishedUtc.HasValue) { @if (publishLaterPart.IsPublished() && versionPublishedUtc.HasValue) {
@T("Published: {0}", Display.DateTimeRelative(versionPublishedUtc.Value)) @T("Published: {0}", Display.DateTimeRelative(dateTimeUtc: versionPublishedUtc.Value))
} }
else { else {
<img class="icon" src="@Href("~/Core/PublishLater/Content/Admin/images/scheduled.gif")" alt="@T("Scheduled")" title="@T("The page is scheduled for publishing")" /><text> @T("Scheduled") </text> <img class="icon" src="@Href("~/Core/PublishLater/Content/Admin/images/scheduled.gif")" alt="@T("Scheduled")" title="@T("The page is scheduled for publishing")" /><text> @T("Scheduled") </text>

View File

@@ -6,5 +6,5 @@
DateTime? versionPublishedUtc = publishLaterPart.As<CommonPart>() == null ? null : publishLaterPart.As<CommonPart>().VersionPublishedUtc; DateTime? versionPublishedUtc = publishLaterPart.As<CommonPart>() == null ? null : publishLaterPart.As<CommonPart>().VersionPublishedUtc;
} }
@if (publishLaterPart.IsPublished() && versionPublishedUtc.HasValue) { @if (publishLaterPart.IsPublished() && versionPublishedUtc.HasValue) {
@T("Published: {0}", Display.DateTimeRelative(dateTime: versionPublishedUtc.Value)) @T("Published: {0}", Display.DateTimeRelative(dateTimeUtc: versionPublishedUtc.Value))
} }

View File

@@ -1,15 +1,16 @@
using System; using System;
using System.Web;
using System.Web.Mvc; using System.Web.Mvc;
using Orchard.DisplayManagement; using Orchard.DisplayManagement;
using Orchard.Localization; using Orchard.Localization;
using Orchard.Mvc.Html; using Orchard.Mvc.Html;
using Orchard.Services; using Orchard.Services;
namespace Orchard.Mvc { namespace Orchard.Core.Shapes {
public class Shapes { public class DateTimeShapes : IDependency {
private readonly IClock _clock; private readonly IClock _clock;
public Shapes(IClock clock) { public DateTimeShapes(IClock clock) {
_clock = clock; _clock = clock;
T = NullLocalizer.Instance; T = NullLocalizer.Instance;
} }
@@ -17,16 +18,11 @@ namespace Orchard.Mvc {
public Localizer T { get; set; } public Localizer T { get; set; }
[Shape] [Shape]
public LocalizedString DateTimeRelative(HtmlHelper Html, DateTime? dateTime, LocalizedString defaultIfNull) { public IHtmlString DateTimeRelative(HtmlHelper Html, DateTime dateTimeUtc) {
return dateTime.HasValue ? DateTimeRelative(Html, dateTime.Value) : defaultIfNull; var time = _clock.UtcNow - dateTimeUtc;
}
[Shape]
public LocalizedString DateTimeRelative(HtmlHelper Html, DateTime dateTime) {
var time = _clock.UtcNow - dateTime;
if (time.TotalDays > 7) if (time.TotalDays > 7)
return Html.DateTime(dateTime, T("'on' MMM d yyyy 'at' h:mm tt")); return Html.DateTime(dateTimeUtc, T("'on' MMM d yyyy 'at' h:mm tt"));
if (time.TotalHours > 24) if (time.TotalHours > 24)
return T.Plural("1 day ago", "{0} days ago", time.Days); return T.Plural("1 day ago", "{0} days ago", time.Days);
if (time.TotalMinutes > 60) if (time.TotalMinutes > 60)

View File

@@ -1,6 +1,5 @@
@model Orchard.Comments.Models.CommentsPart @model Orchard.Comments.Models.CommentsPart
@using Orchard.Comments.Models; @using Orchard.Comments.Models;
@using Orchard.Comments.Extensions;
@using Orchard.Localization; @using Orchard.Localization;
<fieldset> <fieldset>

View File

@@ -9,7 +9,7 @@
<h4> <h4>
<span class="who">@Html.LinkOrDefault(comment.Record.UserName, comment.Record.SiteName, new { rel = "nofollow" }) <span class="who">@Html.LinkOrDefault(comment.Record.UserName, comment.Record.SiteName, new { rel = "nofollow" })
</span> </span>
<span class="when">said <time datetime="@comment.Record.CommentDateUtc.GetValueOrDefault()">@Html.Link(Display.DateTimeRelative(dateTime: comment.Record.CommentDateUtc.GetValueOrDefault()).ToString(), "#")</time> <span class="when">said <time datetime="@comment.Record.CommentDateUtc.GetValueOrDefault()">@Html.Link((string)Display.DateTimeRelative(dateTimeUtc: comment.Record.CommentDateUtc.GetValueOrDefault()).ToString(), "#")</time>
</span> </span>
</h4> </h4>
</header> </header>

View File

@@ -1,5 +1,4 @@
@using Orchard.Comments.Models; @using Orchard.Comments.Models;
@using Orchard.Comments.Extensions;
@using Orchard.Comments.ViewModels; @using Orchard.Comments.ViewModels;
@using Orchard.ContentManagement; @using Orchard.ContentManagement;
<span class="commentcount">@Display.CommentSummaryLinks(item: Model.ContentPart.ContentItem, count: Model.CommentCount, pendingCount: Model.PendingCount)</span> <span class="commentcount">@Display.CommentSummaryLinks(item: Model.ContentPart.ContentItem, count: Model.CommentCount, pendingCount: Model.PendingCount)</span>

View File

@@ -20,7 +20,7 @@
<p>@T("The search index contains the following fields: {0}.", string.Join(T(", ").Text, Model.IndexEntry.Fields))</p> <p>@T("The search index contains the following fields: {0}.", string.Join(T(", ").Text, Model.IndexEntry.Fields))</p>
} }
<p>@T("The search index was last updated {0}.", Display.DateTimeRelative(dateTime: Model.IndexEntry.LastUpdateUtc.Value))</p> <p>@T("The search index was last updated {0}.", Display.DateTimeRelative(dateTimeUtc: Model.IndexEntry.LastUpdateUtc.Value))</p>
} }
<p>@T("Update the search index now: ")<button type="submit" title="@T("Update the search index.")" class="primaryAction">@T("Update")</button></p> <p>@T("Update the search index now: ")<button type="submit" title="@T("Update the search index.")" class="primaryAction">@T("Update")</button></p>
@Html.AntiForgeryTokenOrchard() @Html.AntiForgeryTokenOrchard()

View File

@@ -3,5 +3,5 @@
<%@ Import Namespace="Orchard.Blogs.Models"%> <%@ Import Namespace="Orchard.Blogs.Models"%>
<% <%
if (Model.Creator != null) { if (Model.Creator != null) {
%><%=_Encoded(" | Posted by {0} {1}", Model.Creator.UserName, Display.PublishedWhen(versionPublishedUtc: Model))%><% %><%=_Encoded(" | Posted by {0} {1}", Model.Creator.UserName, Display.PublishedWhen(dateTimeUtc: Model))%><%
} %> } %>

View File

@@ -7,7 +7,7 @@ foreach (var comment in Model) { %>
<p><%: comment.Record.CommentText %></p> <p><%: comment.Record.CommentText %></p>
</div> </div>
<div class="commentauthor"> <div class="commentauthor">
<span class="who"><%: Html.LinkOrDefault(Html.Encode(comment.Record.UserName), Html.Encode(comment.Record.SiteName), new { rel = "nofollow" })%></span>&nbsp;<span>said <%: Html.Link(Display.DateTimeRelative(dateTime: comment.Record.CommentDateUtc.GetValueOrDefault()).Text, "#")%></span> <span class="who"><%: Html.LinkOrDefault(Html.Encode(comment.Record.UserName), Html.Encode(comment.Record.SiteName), new { rel = "nofollow" })%></span>&nbsp;<span>said <%: Html.Link(Display.DateTimeRelative(dateTimeUtc: comment.Record.CommentDateUtc.GetValueOrDefault()).Text, "#")%></span>
</div> </div>
</li><% </li><%
} %> } %>

View File

@@ -2,9 +2,8 @@
<%@ Import Namespace="Orchard.Mvc.ViewModels"%> <%@ Import Namespace="Orchard.Mvc.ViewModels"%>
<%@ Import Namespace="Orchard.Blogs.Extensions"%> <%@ Import Namespace="Orchard.Blogs.Extensions"%>
<%@ Import Namespace="Orchard.Blogs.Models"%> <%@ Import Namespace="Orchard.Blogs.Models"%>
<%@ Import Namespace="Orchard.Core.Common.Extensions" %>
<h3><%: Html.Link(Model.Item.Title, Url.BlogPost(Model.Item)) %></h3> <h3><%: Html.Link(Model.Item.Title, Url.BlogPost(Model.Item)) %></h3>
<div class="meta"><%: Display.PublishedState(versionPublishedUtc: Model.Item)%> | <%Html.Zone("meta");%></div> <div class="meta"><%: Display.PublishedState(dateTimeUtc: Model.Item)%> | <%Html.Zone("meta");%></div>
<div class="postsummary"> <div class="postsummary">
<% Html.Zone("primary"); %> <% Html.Zone("primary"); %>
</div> </div>

View File

@@ -1,7 +1,6 @@
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<BlogPart>" %> <%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<BlogPart>" %>
<%@ Import Namespace="Orchard.Blogs.Extensions"%> <%@ Import Namespace="Orchard.Blogs.Extensions"%>
<%@ Import Namespace="Orchard.Blogs.Models"%> <%@ Import Namespace="Orchard.Blogs.Models"%>
<%@ Import Namespace="Orchard.Core.Common.Extensions" %><%
if (Model.Creator != null) { if (Model.Creator != null) {
%><%: T("Posted by {0} {1}", Model.Creator.UserName, Display.PublishedWhen(versionPublishedUtc: Model))%><% %><%: T("Posted by {0} {1}", Model.Creator.UserName, Display.PublishedWhen(dateTimeUtc: Model))%><%
} %> } %>

View File

@@ -7,7 +7,7 @@ foreach (var comment in Model) { %>
<p><%: comment.Record.CommentText %></p> <p><%: comment.Record.CommentText %></p>
</div> </div>
<div class="commentauthor"> <div class="commentauthor">
<span class="who"><%: Html.LinkOrDefault(comment.Record.UserName, comment.Record.SiteName, new { rel = "nofollow" })%></span>&nbsp;<span>said <%: Html.Link(Display.DateTimeRelative(dateTime: comment.Record.CommentDateUtc.GetValueOrDefault()).Text, "#")%></span> <span class="who"><%: Html.LinkOrDefault(comment.Record.UserName, comment.Record.SiteName, new { rel = "nofollow" })%></span>&nbsp;<span>said <%: Html.Link(Display.DateTimeRelative(dateTimeUtc: comment.Record.CommentDateUtc.GetValueOrDefault()).Text, "#")%></span>
</div> </div>
</li><% </li><%
} %> } %>

View File

@@ -1,6 +1,5 @@
@using Orchard.Blogs.Extensions; @using Orchard.Blogs.Extensions;
@using Orchard.Blogs.Models; @using Orchard.Blogs.Models;
@using Orchard.Core.Common.Extensions;
@using Orchard.Core.Common.Models; @using Orchard.Core.Common.Models;
@using Orchard.Core.Common.ViewModels; @using Orchard.Core.Common.ViewModels;
@@ -8,7 +7,7 @@
<!-- TODO: Meta should be it's own shape and not part of the blog summary view. Theme authors will need access to it. --> <!-- TODO: Meta should be it's own shape and not part of the blog summary view. Theme authors will need access to it. -->
<div class="meta"> <div class="meta">
@Display.PublishedState(versionPublishedUtc: new CommonMetadataViewModel((CommonPart)Model.ContentItem.Get(typeof(CommonPart)))) @Display.PublishedState(dateTimeUtc: new CommonMetadataViewModel((CommonPart)Model.ContentItem.Get(typeof(CommonPart))))
@Display(Model.meta) @Display(Model.meta)
</div> </div>

View File

@@ -176,7 +176,6 @@
<Compile Include="Environment\Extensions\Loaders\RawThemeExtensionLoader.cs" /> <Compile Include="Environment\Extensions\Loaders\RawThemeExtensionLoader.cs" />
<Compile Include="Localization\Services\DefaultLocalizedStringManager.cs" /> <Compile Include="Localization\Services\DefaultLocalizedStringManager.cs" />
<Compile Include="Localization\Services\ILocalizedStringManager.cs" /> <Compile Include="Localization\Services\ILocalizedStringManager.cs" />
<Compile Include="Mvc\Shapes.cs" />
<Compile Include="Mvc\IOrchardViewPage.cs" /> <Compile Include="Mvc\IOrchardViewPage.cs" />
<Compile Include="Mvc\Spooling\HtmlStringWriter.cs" /> <Compile Include="Mvc\Spooling\HtmlStringWriter.cs" />
<Compile Include="Scripting\IScriptingManager.cs" /> <Compile Include="Scripting\IScriptingManager.cs" />