mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Fix remaining issues with DateTimeRelative, etc. shapes
--HG-- branch : dev
This commit is contained in:
@@ -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"));
|
||||
}
|
||||
}
|
||||
}
|
31
src/Orchard.Web/Core/Common/Shapes.cs
Normal file
31
src/Orchard.Web/Core/Common/Shapes.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,2 +1 @@
|
||||
@using Orchard.Core.Common.Extensions;
|
||||
<div class="published">@Display.PublishedState(versionPublishedUtc: (DateTime?)Model.ContentPart.VersionPublishedUtc)</div>
|
||||
<div class="published">@Display.PublishedState(dateTimeUtc: Model.ContentPart.VersionPublishedUtc)</div>
|
@@ -9,7 +9,7 @@
|
||||
}
|
||||
<ul class="pageStatus">
|
||||
<li>@if (modifiedUtc.HasValue) {
|
||||
@T("Last modified: {0}", Display.DateTimeRelative(dateTime: modifiedUtc.Value))} |
|
||||
@T("Last modified: {0}", Display.DateTimeRelative(dateTimeUtc: modifiedUtc.Value))} |
|
||||
</li>
|
||||
<li>@T("By {0}", owner.UserName)</li>
|
||||
</ul>
|
@@ -1,2 +1 @@
|
||||
@using Orchard.Core.Common.Extensions;
|
||||
<div class="published">@Display.PublishedState(versionPublishedUtc: (DateTime?)Model.ContentPart.VersionPublishedUtc)</div>
|
||||
<div class="published">@Display.PublishedState(dateTimeUtc: Model.ContentPart.VersionPublishedUtc)</div>
|
@@ -70,7 +70,7 @@
|
||||
<Compile Include="Common\Drivers\BodyPartDriver.cs" />
|
||||
<Compile Include="Common\Drivers\CommonPartDriver.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="Contents\Security\AuthorizationEventHandler.cs" />
|
||||
<Compile Include="Common\Services\BbcodeFilter.cs" />
|
||||
@@ -231,6 +231,7 @@
|
||||
<Compile Include="Settings\ViewModels\SiteSettingsPartViewModel.cs" />
|
||||
<Compile Include="Shapes\ResourceManifest.cs" />
|
||||
<Compile Include="Shapes\CoreShapes.cs" />
|
||||
<Compile Include="Shapes\DateTimeShapes.cs" />
|
||||
<Compile Include="XmlRpc\Controllers\HomeController.cs" />
|
||||
<Compile Include="XmlRpc\Controllers\LiveWriterController.cs" />
|
||||
<Compile Include="XmlRpc\IXmlRpcHandler.cs" />
|
||||
|
@@ -6,5 +6,5 @@
|
||||
DateTime? versionPublishedUtc = publishLaterPart.As<CommonPart>() == null ? null : publishLaterPart.As<CommonPart>().VersionPublishedUtc;
|
||||
}
|
||||
@if (publishLaterPart.IsPublished() && versionPublishedUtc.HasValue) {
|
||||
@T("Published: {0}", Display.DateTimeRelative(versionPublishedUtc.Value)) @T(" | ")
|
||||
@T("Published: {0}", Display.DateTimeRelative(dateTimeUtc: versionPublishedUtc.Value)) @T(" | ")
|
||||
}
|
@@ -26,7 +26,7 @@
|
||||
@if ((((DateTime?)Model.ScheduledPublishUtc).HasValue && ((DateTime?)Model.ScheduledPublishUtc).Value > DateTime.UtcNow) || (publishLaterPart.IsPublished() && versionPublishedUtc.HasValue)) {
|
||||
<li>
|
||||
@if (publishLaterPart.IsPublished() && versionPublishedUtc.HasValue) {
|
||||
@T("Published: {0}", Display.DateTimeRelative(versionPublishedUtc.Value))
|
||||
@T("Published: {0}", Display.DateTimeRelative(dateTimeUtc: versionPublishedUtc.Value))
|
||||
}
|
||||
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>
|
||||
|
@@ -6,5 +6,5 @@
|
||||
DateTime? versionPublishedUtc = publishLaterPart.As<CommonPart>() == null ? null : publishLaterPart.As<CommonPart>().VersionPublishedUtc;
|
||||
}
|
||||
@if (publishLaterPart.IsPublished() && versionPublishedUtc.HasValue) {
|
||||
@T("Published: {0}", Display.DateTimeRelative(dateTime: versionPublishedUtc.Value))
|
||||
@T("Published: {0}", Display.DateTimeRelative(dateTimeUtc: versionPublishedUtc.Value))
|
||||
}
|
@@ -1,15 +1,16 @@
|
||||
using System;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Orchard.DisplayManagement;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Mvc.Html;
|
||||
using Orchard.Services;
|
||||
|
||||
namespace Orchard.Mvc {
|
||||
public class Shapes {
|
||||
namespace Orchard.Core.Shapes {
|
||||
public class DateTimeShapes : IDependency {
|
||||
private readonly IClock _clock;
|
||||
|
||||
public Shapes(IClock clock) {
|
||||
public DateTimeShapes(IClock clock) {
|
||||
_clock = clock;
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
@@ -17,16 +18,11 @@ namespace Orchard.Mvc {
|
||||
public Localizer T { get; set; }
|
||||
|
||||
[Shape]
|
||||
public LocalizedString DateTimeRelative(HtmlHelper Html, DateTime? dateTime, LocalizedString defaultIfNull) {
|
||||
return dateTime.HasValue ? DateTimeRelative(Html, dateTime.Value) : defaultIfNull;
|
||||
}
|
||||
|
||||
[Shape]
|
||||
public LocalizedString DateTimeRelative(HtmlHelper Html, DateTime dateTime) {
|
||||
var time = _clock.UtcNow - dateTime;
|
||||
public IHtmlString DateTimeRelative(HtmlHelper Html, DateTime dateTimeUtc) {
|
||||
var time = _clock.UtcNow - dateTimeUtc;
|
||||
|
||||
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)
|
||||
return T.Plural("1 day ago", "{0} days ago", time.Days);
|
||||
if (time.TotalMinutes > 60)
|
@@ -1,6 +1,5 @@
|
||||
@model Orchard.Comments.Models.CommentsPart
|
||||
@using Orchard.Comments.Models;
|
||||
@using Orchard.Comments.Extensions;
|
||||
@using Orchard.Localization;
|
||||
|
||||
<fieldset>
|
||||
|
@@ -9,7 +9,7 @@
|
||||
<h4>
|
||||
<span class="who">@Html.LinkOrDefault(comment.Record.UserName, comment.Record.SiteName, new { rel = "nofollow" })
|
||||
</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>
|
||||
</h4>
|
||||
</header>
|
||||
|
@@ -1,5 +1,4 @@
|
||||
@using Orchard.Comments.Models;
|
||||
@using Orchard.Comments.Extensions;
|
||||
@using Orchard.Comments.ViewModels;
|
||||
@using Orchard.ContentManagement;
|
||||
<span class="commentcount">@Display.CommentSummaryLinks(item: Model.ContentPart.ContentItem, count: Model.CommentCount, pendingCount: Model.PendingCount)</span>
|
@@ -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 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>
|
||||
@Html.AntiForgeryTokenOrchard()
|
||||
|
@@ -3,5 +3,5 @@
|
||||
<%@ Import Namespace="Orchard.Blogs.Models"%>
|
||||
<%
|
||||
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))%><%
|
||||
} %>
|
||||
|
@@ -7,7 +7,7 @@ foreach (var comment in Model) { %>
|
||||
<p><%: comment.Record.CommentText %></p>
|
||||
</div>
|
||||
<div class="commentauthor">
|
||||
<span class="who"><%: Html.LinkOrDefault(Html.Encode(comment.Record.UserName), Html.Encode(comment.Record.SiteName), new { rel = "nofollow" })%></span> <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> <span>said <%: Html.Link(Display.DateTimeRelative(dateTimeUtc: comment.Record.CommentDateUtc.GetValueOrDefault()).Text, "#")%></span>
|
||||
</div>
|
||||
</li><%
|
||||
} %>
|
||||
|
@@ -2,9 +2,8 @@
|
||||
<%@ Import Namespace="Orchard.Mvc.ViewModels"%>
|
||||
<%@ Import Namespace="Orchard.Blogs.Extensions"%>
|
||||
<%@ Import Namespace="Orchard.Blogs.Models"%>
|
||||
<%@ Import Namespace="Orchard.Core.Common.Extensions" %>
|
||||
<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">
|
||||
<% Html.Zone("primary"); %>
|
||||
</div>
|
@@ -1,7 +1,6 @@
|
||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<BlogPart>" %>
|
||||
<%@ Import Namespace="Orchard.Blogs.Extensions"%>
|
||||
<%@ Import Namespace="Orchard.Blogs.Models"%>
|
||||
<%@ Import Namespace="Orchard.Core.Common.Extensions" %><%
|
||||
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))%><%
|
||||
} %>
|
@@ -7,7 +7,7 @@ foreach (var comment in Model) { %>
|
||||
<p><%: comment.Record.CommentText %></p>
|
||||
</div>
|
||||
<div class="commentauthor">
|
||||
<span class="who"><%: Html.LinkOrDefault(comment.Record.UserName, comment.Record.SiteName, new { rel = "nofollow" })%></span> <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> <span>said <%: Html.Link(Display.DateTimeRelative(dateTimeUtc: comment.Record.CommentDateUtc.GetValueOrDefault()).Text, "#")%></span>
|
||||
</div>
|
||||
</li><%
|
||||
} %>
|
||||
|
@@ -1,6 +1,5 @@
|
||||
@using Orchard.Blogs.Extensions;
|
||||
@using Orchard.Blogs.Models;
|
||||
@using Orchard.Core.Common.Extensions;
|
||||
@using Orchard.Core.Common.Models;
|
||||
@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. -->
|
||||
<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)
|
||||
</div>
|
||||
|
||||
|
@@ -176,7 +176,6 @@
|
||||
<Compile Include="Environment\Extensions\Loaders\RawThemeExtensionLoader.cs" />
|
||||
<Compile Include="Localization\Services\DefaultLocalizedStringManager.cs" />
|
||||
<Compile Include="Localization\Services\ILocalizedStringManager.cs" />
|
||||
<Compile Include="Mvc\Shapes.cs" />
|
||||
<Compile Include="Mvc\IOrchardViewPage.cs" />
|
||||
<Compile Include="Mvc\Spooling\HtmlStringWriter.cs" />
|
||||
<Compile Include="Scripting\IScriptingManager.cs" />
|
||||
|
Reference in New Issue
Block a user