Skip to content

Commit

Permalink
Implement support for activity property ordering
Browse files Browse the repository at this point in the history
Closes #884
  • Loading branch information
sfmskywalker committed May 30, 2021
1 parent 16c93e1 commit 0f8a0e9
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,20 @@ public SendEmail(ISmtpService smtpService, IOptions<SmtpOptions> options)
[ActivityInput(Hint = "The recipients email addresses.", UIHint = ActivityInputUIHints.MultiText, DefaultSyntax = SyntaxNames.Json, SupportedSyntaxes = new[] { SyntaxNames.Json, SyntaxNames.JavaScript })]
public ICollection<string> To { get; set; } = new List<string>();

[ActivityInput(Hint = "The cc recipients email addresses. (Optional)", UIHint = ActivityInputUIHints.MultiText, DefaultSyntax = SyntaxNames.Json, SupportedSyntaxes = new[] { SyntaxNames.Json, SyntaxNames.JavaScript })]
[ActivityInput(
Hint = "The cc recipients email addresses.",
UIHint = ActivityInputUIHints.MultiText,
DefaultSyntax = SyntaxNames.Json,
SupportedSyntaxes = new[] { SyntaxNames.Json, SyntaxNames.JavaScript },
Category = "More")]
public ICollection<string> Cc { get; set; } = new List<string>();

[ActivityInput(Hint = "The Bcc recipients email addresses. (Optional)", UIHint = ActivityInputUIHints.MultiText, DefaultSyntax = SyntaxNames.Json, SupportedSyntaxes = new[] { SyntaxNames.Json, SyntaxNames.JavaScript })]
[ActivityInput(
Hint = "The Bcc recipients email addresses.",
UIHint = ActivityInputUIHints.MultiText,
DefaultSyntax = SyntaxNames.Json,
SupportedSyntaxes = new[] { SyntaxNames.Json, SyntaxNames.JavaScript },
Category = "More")]
public ICollection<string> Bcc { get; set; } = new List<string>();

[ActivityInput(Hint = "The subject of the email message.", SupportedSyntaxes = new[] { SyntaxNames.JavaScript, SyntaxNames.Liquid })]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public WriteHttpResponse(IHttpContextAccessor httpContextAccessor, IStringLocali
Hint = "The HTTP status code to write.",
Options = new[] { HttpStatusCode.OK, HttpStatusCode.Created, HttpStatusCode.Accepted, HttpStatusCode.NoContent, HttpStatusCode.Redirect, HttpStatusCode.BadRequest, HttpStatusCode.NotFound, HttpStatusCode.Conflict },
SupportedSyntaxes = new[] { SyntaxNames.Literal, SyntaxNames.JavaScript, SyntaxNames.Liquid },
DefaultValue = HttpStatusCode.OK
DefaultValue = HttpStatusCode.OK,
Category = PropertyCategories.Advanced
)]
public HttpStatusCode StatusCode { get; set; } = HttpStatusCode.OK;

Expand All @@ -60,17 +61,18 @@ public WriteHttpResponse(IHttpContextAccessor httpContextAccessor, IStringLocali
SupportedSyntaxes = new[] { SyntaxNames.Literal, SyntaxNames.JavaScript, SyntaxNames.Liquid }
)]
public string? ContentType { get; set; } = "text/plain";

/// <summary>
/// The character set to use when writing the response.
/// </summary>
[ActivityInput(
Hint = "The character set to use when writing the response.",
Hint = "The character set to use when writing the response.",
UIHint = ActivityInputUIHints.Dropdown,
Options = new[] { "utf-8", "ASCII", "ANSI", "ISO-8859-1" },
DefaultValue = "utf-8",
SupportedSyntaxes = new[] { SyntaxNames.Literal, SyntaxNames.JavaScript, SyntaxNames.Liquid })]
public string CharSet { get; set; }
SupportedSyntaxes = new[] { SyntaxNames.Literal, SyntaxNames.JavaScript, SyntaxNames.Liquid },
Category = PropertyCategories.Advanced)]
public string CharSet { get; set; } = "utf-8";

/// <summary>
/// The headers to send along with the response.
Expand All @@ -79,7 +81,8 @@ public WriteHttpResponse(IHttpContextAccessor httpContextAccessor, IStringLocali
Hint = "Additional headers to write.",
UIHint = ActivityInputUIHints.MultiLine,
DefaultSyntax = SyntaxNames.Json,
SupportedSyntaxes = new[]{ SyntaxNames.JavaScript, SyntaxNames.Liquid, SyntaxNames.Json }
SupportedSyntaxes = new[]{ SyntaxNames.JavaScript, SyntaxNames.Liquid, SyntaxNames.Json },
Category = PropertyCategories.Advanced
)]
public HttpResponseHeaders? ResponseHeaders { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ private ActivityType CreateWebhookActivityType(WebhookDefinition webhook)
"Specify what request method this webhook should handle. Leave empty to handle both GET and POST requests",
new[] { "", "GET", "POST" },
"Webhooks",
0,
"POST",
SyntaxNames.Literal,
new[] { SyntaxNames.JavaScript, SyntaxNames.Liquid })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ public class ActivityInputAttribute : Attribute
/// </summary>
public string? Category { get; set; }

/// <summary>
/// A value to order this property by. Properties are displayed in ascending order (lower appears before higher).
/// </summary>
public float Order { get; set; }

/// <summary>
/// The default value to set.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public ActivityInputDescriptor()
string? hint = default,
object? options = default,
string? category = default,
float order = 0,
object? defaultValue = default,
string? defaultSyntax = "Literal",
IEnumerable<string>? supportedSyntaxes = default)
Expand All @@ -29,6 +30,7 @@ public ActivityInputDescriptor()
Hint = hint;
Options = options;
Category = category;
Order = order;
DefaultValue = defaultValue;
DefaultSyntax = defaultSyntax;
SupportedSyntaxes = supportedSyntaxes?.ToList() ?? new List<string>();
Expand All @@ -41,6 +43,7 @@ public ActivityInputDescriptor()
public string? Hint { get; set; }
public object? Options { get; set; }
public string? Category { get; set; }
public float Order { get; set; }
public object? DefaultValue { get; set; }
public string? DefaultSyntax { get; set; }
public IList<string> SupportedSyntaxes { get; set; } = new List<string>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Elsa.Activities.Signaling.Models;
using Elsa.ActivityResults;
using Elsa.Attributes;
using Elsa.Design;
using Elsa.Expressions;
using Elsa.Services;
using Elsa.Services.Models;
Expand All @@ -22,9 +23,12 @@ public class SignalReceived : Activity
[ActivityInput(Hint = "The name of the signal to wait for.", SupportedSyntaxes = new[] { SyntaxNames.JavaScript, SyntaxNames.Liquid })]
public string Signal { get; set; } = default!;

[ActivityInput(Hint = "The scope of the signal to wait for.", SupportedSyntaxes = new[] { SyntaxNames.JavaScript, SyntaxNames.Liquid }, DefaultValue = SignalScope.Instance)]
[ActivityInput(Hint = "The scope of the signal to wait for.", SupportedSyntaxes = new[] { SyntaxNames.JavaScript, SyntaxNames.Liquid }, DefaultValue = SignalScope.Instance, Category = PropertyCategories.Advanced)]
public SignalScope Scope { get; set; } = SignalScope.Instance;

[ActivityOutput(Hint = "The input that was received with the signal.")]
public object? SignalInput { get; set; }

protected override bool OnCanExecute(ActivityExecutionContext context)
{
if (context.Input is Signal triggeredSignal)
Expand All @@ -38,6 +42,7 @@ protected override bool OnCanExecute(ActivityExecutionContext context)
protected override IActivityExecutionResult OnResume(ActivityExecutionContext context)
{
var triggeredSignal = context.GetInput<Signal>()!;
SignalInput = triggeredSignal.Input;
return Done(triggeredSignal.Input);
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/core/Elsa.Core/Metadata/TypedActivityTypeDescriber.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public TypedActivityTypeDescriber(IActivityPropertyOptionsResolver optionsResolv
var traits = activityAttribute?.Traits ?? ActivityTraits.Action;
var outcomes = await GetOutcomesAsync(activityAttribute, cancellationToken);
var properties = activityType.GetProperties();
var inputProperties = DescribeInputProperties(properties);
var inputProperties = DescribeInputProperties(properties).OrderBy(x => x.Order);
var outputProperties = DescribeOutputProperties(properties);

return new ActivityDescriptor
Expand Down Expand Up @@ -93,6 +93,7 @@ private IEnumerable<ActivityInputDescriptor> DescribeInputProperties(IEnumerable
activityPropertyAttribute.Hint,
_optionsResolver.GetOptions(propertyInfo),
activityPropertyAttribute.Category,
activityPropertyAttribute.Order,
_defaultValueResolver.GetDefaultValue(propertyInfo),
activityPropertyAttribute.DefaultSyntax,
activityPropertyAttribute.SupportedSyntaxes
Expand Down

0 comments on commit 0f8a0e9

Please sign in to comment.