mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
#21294: Added optional date parameter to TimerActivity. Also added description hints and updated class name.
Work Item: 21294
This commit is contained in:
@@ -6,6 +6,7 @@ using Orchard.Data;
|
||||
using Orchard.Environment.Extensions;
|
||||
using Orchard.Forms.Services;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Localization.Services;
|
||||
using Orchard.Services;
|
||||
using Orchard.Tasks;
|
||||
using Orchard.Workflows.Models;
|
||||
@@ -15,9 +16,11 @@ namespace Orchard.Workflows.Activities {
|
||||
[OrchardFeature("Orchard.Workflows.Timer")]
|
||||
public class TimerActivity : Event {
|
||||
private readonly IClock _clock;
|
||||
private readonly IDateLocalizationServices _dateServices;
|
||||
|
||||
public TimerActivity(IClock clock) {
|
||||
public TimerActivity(IClock clock, IDateLocalizationServices dateServices) {
|
||||
_clock = clock;
|
||||
_dateServices = dateServices;
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
|
||||
@@ -57,7 +60,11 @@ namespace Orchard.Workflows.Activities {
|
||||
DateTime started;
|
||||
|
||||
if (!workflowContext.HasStateFor(activityContext.Record, "StartedUtc")) {
|
||||
workflowContext.SetStateFor(activityContext.Record, "StartedUtc", started = _clock.UtcNow);
|
||||
var dateString = activityContext.GetState<string>("Date");
|
||||
var date = _dateServices.ConvertFromLocalizedString(dateString);
|
||||
started = date ?? _clock.UtcNow;
|
||||
|
||||
workflowContext.SetStateFor(activityContext.Record, "StartedUtc", started);
|
||||
}
|
||||
else {
|
||||
started = workflowContext.GetStateFor<DateTime>(activityContext.Record, "StartedUtc");
|
||||
@@ -71,7 +78,6 @@ namespace Orchard.Workflows.Activities {
|
||||
|
||||
public static DateTime When(DateTime started, int amount, string type) {
|
||||
try {
|
||||
|
||||
var when = started;
|
||||
|
||||
switch (type) {
|
||||
|
@@ -7,11 +7,11 @@ using Orchard.Localization;
|
||||
|
||||
namespace Orchard.Workflows.Forms {
|
||||
[OrchardFeature("Orchard.Workflows.Timer")]
|
||||
public class ScheduleForms : IFormProvider {
|
||||
public class TimerForms : IFormProvider {
|
||||
protected dynamic Shape { get; set; }
|
||||
public Localizer T { get; set; }
|
||||
|
||||
public ScheduleForms(IShapeFactory shapeFactory) {
|
||||
public TimerForms(IShapeFactory shapeFactory) {
|
||||
Shape = shapeFactory;
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
@@ -24,7 +24,8 @@ namespace Orchard.Workflows.Forms {
|
||||
_Amount: Shape.Textbox(
|
||||
Id: "Amount", Name: "Amount",
|
||||
Title: T("Amount"),
|
||||
Classes: new[] { "text small" }),
|
||||
Description: T("Amount of time units to add."),
|
||||
Classes: new[] { "text small tokenized" }),
|
||||
_Type: Shape.SelectList(
|
||||
Id: "Unity", Name: "Unity",
|
||||
Title: T("Amount type"))
|
||||
@@ -32,8 +33,12 @@ namespace Orchard.Workflows.Forms {
|
||||
.Add(new SelectListItem { Value = "Hour", Text = T("Hours").Text })
|
||||
.Add(new SelectListItem { Value = "Day", Text = T("Days").Text })
|
||||
.Add(new SelectListItem { Value = "Week", Text = T("Weeks").Text })
|
||||
.Add(new SelectListItem { Value = "Month", Text = T("Months").Text })
|
||||
);
|
||||
.Add(new SelectListItem { Value = "Month", Text = T("Months").Text }),
|
||||
_Date: Shape.Textbox(
|
||||
Id: "Date", Name: "Date",
|
||||
Title: T("Date"),
|
||||
Description: T("Optional. Starting date/time to calculate difference from. Leave blank to use current date/time."),
|
||||
Classes: new[] {"text medium tokenized"}));
|
||||
|
||||
return form;
|
||||
}
|
||||
|
Reference in New Issue
Block a user