Browse Source

Wording improvements.

pull/747/head
Sebastian 4 years ago
parent
commit
c7cadbb069
  1. 14
      backend/extensions/Squidex.Extensions/Actions/SignalR/SignalRAction.cs
  2. 33
      backend/extensions/Squidex.Extensions/Actions/SignalR/SignalRActionHandler.cs
  3. 2
      frontend/app/features/rules/shared/actions/generic-action.component.html

14
backend/extensions/Squidex.Extensions/Actions/SignalR/SignalRAction.cs

@ -19,12 +19,12 @@ namespace Squidex.Extensions.Actions.SignalR
IconImage = "<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'><path d='M.011 16L0 6.248l12-1.63V16zM14 4.328L29.996 2v14H14zM30 18l-.004 14L14 29.75V18zM12 29.495L.01 27.851.009 18H12z'/></svg>",
IconColor = "#1566BF",
Display = "Send to Azure SignalR",
Description = "Send an message to azure SignalR.",
Description = "Send a message to Azure SignalR.",
ReadMore = "https://azure.microsoft.com/fr-fr/services/signalr-service/")]
public sealed record SignalRAction : RuleAction
{
[LocalizedRequired]
[Display(Name = "Connection", Description = "The connection string to the Signal R Azure.")]
[Display(Name = "Connection", Description = "The connection string to the Azure SignalR.")]
[Editor(RuleFieldEditor.Text)]
[Formattable]
public string ConnectionString { get; set; }
@ -36,14 +36,14 @@ namespace Squidex.Extensions.Actions.SignalR
public string HubName { get; set; }
[LocalizedRequired]
[Display(Name = "Action", Description = "Broadcast = send to all User, User = send to specific user(s) specified in the 'Target' field, Group = send to specific group(s) specified in the 'Target' field")]
[Display(Name = "Action", Description = "* Broadcast = send to all users.\n * User = send to all target users(s).\n * Group = send to all target group(s).")]
public ActionTypeEnum Action { get; set; }
[Display(Name = "Methode Name", Description = "Set the Name of the hub method received by the customer, default value 'push.")]
[Display(Name = "Methode Name", Description = "Set the Name of the hub method received by the customer.")]
[Editor(RuleFieldEditor.Text)]
public string MethodName { get; set; }
[Display(Name = "Target (Optional)", Description = "Defines a user, group or target list by an id or name. For a list, define one value per line. Not necessary with the 'Broadcast' action")]
[Display(Name = "Target (Optional)", Description = "Define target users or groups by id or name. One item per line. Not needed for Broadcast action.")]
[Editor(RuleFieldEditor.TextArea)]
[Formattable]
public string Target { get; set; }
@ -55,12 +55,12 @@ namespace Squidex.Extensions.Actions.SignalR
protected override IEnumerable<ValidationError> CustomValidate()
{
if (!string.IsNullOrWhiteSpace(HubName) && !Regex.IsMatch(HubName, "^[a-z][a-z0-9]{2,}(\\-[a-z0-9]+)*$"))
if (HubName != null && !Regex.IsMatch(HubName, "^[a-z][a-z0-9]{2,}(\\-[a-z0-9]+)*$"))
{
yield return new ValidationError("Hub must be valid azure hub name.", nameof(HubName));
}
if ((Action == ActionTypeEnum.User || Action == ActionTypeEnum.Group) && string.IsNullOrWhiteSpace(Target))
if (Action != ActionTypeEnum.Broadcast && string.IsNullOrWhiteSpace(Target))
{
yield return new ValidationError("Target must be specified with 'User' or 'Group' Action.", nameof(HubName));
}

33
backend/extensions/Squidex.Extensions/Actions/SignalR/SignalRActionHandler.cs

@ -30,6 +30,7 @@ namespace Squidex.Extensions.Actions.SignalR
option.ServiceTransportType = ServiceTransportType.Transient;
})
.Build();
return serviceManager;
});
}
@ -49,26 +50,20 @@ namespace Squidex.Extensions.Actions.SignalR
requestBody = ToEnvelopeJson(@event);
}
string[] targetArray = new string[0];
string target = string.Empty;
target = await FormatAsync(action.Target, @event);
if (!string.IsNullOrEmpty(target))
{
targetArray = target.Split('\n');
}
var target = (await FormatAsync(action.Target, @event)) ?? string.Empty;
var ruleDescription = $"Send SignalRJob to signalR hub '{hubName}'";
var ruleJob = new SignalRJob
{
Action = action.Action,
ConnectionString = action.ConnectionString,
HubName = hubName,
Action = action.Action,
MethodName = action.MethodName,
Target = target,
TargetArray = targetArray,
Payload = requestBody
MethodPayload = requestBody,
Targets = target.Split("\n"),
};
return (ruleDescription, ruleJob);
}
@ -76,22 +71,20 @@ namespace Squidex.Extensions.Actions.SignalR
{
var signalR = await clients.GetClientAsync((job.ConnectionString, job.HubName));
await using (var signalRContext = await signalR.CreateHubContextAsync(job.HubName))
await using (var signalRContext = await signalR.CreateHubContextAsync(job.HubName, cancellationToken: ct))
{
var methodeName = !string.IsNullOrWhiteSpace(job.MethodName) ? job.MethodName : "push";
switch (job.Action)
{
case ActionTypeEnum.Broadcast:
await signalRContext.Clients.All.SendAsync(methodeName, job.Payload);
await signalRContext.Clients.All.SendAsync(methodeName, job.MethodPayload, ct);
break;
case ActionTypeEnum.User:
await signalRContext.Clients.Users(job.TargetArray).SendAsync(methodeName, job.Payload);
await signalRContext.Clients.Users(job.Targets).SendAsync(methodeName, job.MethodPayload, ct);
break;
case ActionTypeEnum.Group:
await signalRContext.Clients.Groups(job.TargetArray).SendAsync(methodeName, job.Payload);
await signalRContext.Clients.Groups(job.Targets).SendAsync(methodeName, job.MethodPayload, ct);
break;
}
}
@ -110,10 +103,8 @@ namespace Squidex.Extensions.Actions.SignalR
public string MethodName { get; set; }
public string Target { get; set; }
public string[] TargetArray { get; set; }
public string MethodPayload { get; set; }
public string Payload { get; set; }
public string[] Targets { get; set; }
}
}

2
frontend/app/features/rules/shared/actions/generic-action.component.html

@ -37,7 +37,7 @@
</ng-container>
<sqx-form-hint>
{{property.description}}
<span [innerHTML]="property.description | sqxMarkdownInline"></span>
<div *ngIf="property.isFormattable">
You can use advanced formatting: <a href="https://docs.squidex.io/concepts/rules#3-formatting" sqxExternalLink>Documentation</a>

Loading…
Cancel
Save