Skip to content

Commit

Permalink
Incremental work on saving and loading workflow definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
sfmskywalker committed Nov 17, 2020
1 parent acf884c commit c193b28
Show file tree
Hide file tree
Showing 37 changed files with 472 additions and 247 deletions.
2 changes: 2 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ indent_size=4
# ReSharper properties
resharper_csharp_max_line_length=240
resharper_keep_user_linebreaks=true
resharper_place_field_attribute_on_same_line=if_owner_is_single_line
resharper_space_within_single_line_array_initializer_braces=true
resharper_wrap_before_linq_expression=true

# Microsoft .NET properties
csharp_new_line_before_members_in_object_initializers=false
Expand Down
10 changes: 3 additions & 7 deletions src/clients/Elsa.Client/Models/ConnectionDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,15 @@ namespace Elsa.Client.Models
[DataContract]
public class ConnectionDefinition
{
public ConnectionDefinition()
{
}

public ConnectionDefinition(string sourceActivityId, string targetActivityId, string outcome)
{
SourceActivityId = sourceActivityId;
TargetActivityId = targetActivityId;
Outcome = outcome;
}

[DataMember(Order = 1)] public string? SourceActivityId { get; set; }
[DataMember(Order = 2)] public string? TargetActivityId { get; set; }
[DataMember(Order = 3)] public string? Outcome { get; set; }
[DataMember(Order = 1)] public string SourceActivityId { get; set; }
[DataMember(Order = 2)] public string TargetActivityId { get; set; }
[DataMember(Order = 3)] public string Outcome { get; set; }
}
}
4 changes: 3 additions & 1 deletion src/clients/Elsa.Client/Models/List.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System.Collections.Generic;
using System.Runtime.Serialization;

namespace Elsa.Client.Models
{
[DataContract]
public class List<T>
{
public ICollection<T> Items { get; set; } = new System.Collections.Generic.List<T>();
[DataMember(Order = 1)] public ICollection<T> Items { get; set; } = new System.Collections.Generic.List<T>();
}
}
11 changes: 7 additions & 4 deletions src/clients/Elsa.Client/Models/PagedList.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
namespace Elsa.Client.Models
using System.Runtime.Serialization;

namespace Elsa.Client.Models
{
[DataContract]
public class PagedList<T> : List<T>
{
public int? Page { get; set; }
public int? PageSize { get; set; }
public int TotalCount { get; set; }
[DataMember(Order = 1)] public int? Page { get; set; }
[DataMember(Order = 2)] public int? PageSize { get; set; }
[DataMember(Order = 3)] public int TotalCount { get; set; }
}
}
17 changes: 10 additions & 7 deletions src/clients/Elsa.Client/Services/IWorkflowDefinitionsApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,19 @@ namespace Elsa.Client.Services
{
public interface IWorkflowDefinitionsApi
{
[Get("/v1/workflow-definitions/{workflowDefinitionId}")]
Task<WorkflowDefinition> GetAsync(string workflowDefinitionId, VersionOptions? versionOptions = default, CancellationToken cancellationToken = default);
[Get("/v1/workflow-definitions/{workflowDefinitionId}/{versionOptions}")]
Task<WorkflowDefinition> GetByDefinitionAndVersionAsync(string workflowDefinitionId, VersionOptions versionOptions, CancellationToken cancellationToken = default);

[Get("/v1/workflow-definitions/{workflowDefinitionVersionId}")]
Task<WorkflowDefinition> GetByVersionIdAsync(string workflowDefinitionVersionId, CancellationToken cancellationToken = default);

[Get("/v1/workflow-definitions")]
Task<WorkflowDefinition> ListAsync(string workflowDefinitionId, VersionOptions? versionOptions = default, CancellationToken cancellationToken = default);
Task<PagedList<WorkflowDefinition>> ListAsync(int? page = default, int? pageSize = default, VersionOptions? versionOptions = default, CancellationToken cancellationToken = default);

[Post("/v1/workflow-definitions")]
Task<WorkflowDefinition> PostAsync([Body(BodySerializationMethod.Serialized)]PostWorkflowDefinitionRequest request, CancellationToken cancellationToken = default);
Task<WorkflowDefinition> PostAsync([Body(BodySerializationMethod.Serialized)] PostWorkflowDefinitionRequest request, CancellationToken cancellationToken = default);

[Post("/v1/workflow-definitions/{workflowDefinitionId}")]
Task<WorkflowDefinition> PostAsync(string workflowDefinitionId, [Body(BodySerializationMethod.Serialized)]PostWorkflowDefinitionRequest request, CancellationToken cancellationToken = default);
Task<WorkflowDefinition> PostAsync(string workflowDefinitionId, [Body(BodySerializationMethod.Serialized)] PostWorkflowDefinitionRequest request, CancellationToken cancellationToken = default);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace ElsaDashboard.Application.Server
{
public enum BlazorRuntimeModel
{
Server,
Browser
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<a class="dismiss">🗙</a>
</div>

@if (Program.UseBlazorServer)
@if (Program.RuntimeModel == BlazorRuntimeModel.Server)
{
<script src="_framework/blazor.server.js"></script>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ namespace ElsaDashboard.Application.Server
{
public class Program
{
public static bool UseBlazorServer = true;
public static bool UseBlazorWebAssembly => !UseBlazorServer;
public static RenderMode RenderMode => UseBlazorServer ? RenderMode.ServerPrerendered: RenderMode.WebAssemblyPrerendered;
public static BlazorRuntimeModel RuntimeModel => BlazorRuntimeModel.Browser;
public static RenderMode RenderMode => RuntimeModel == BlazorRuntimeModel.Server ? RenderMode.ServerPrerendered : RenderMode.WebAssemblyPrerendered;

public static void Main(string[] args)
{
Expand All @@ -17,9 +16,6 @@ public static void Main(string[] args)

public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
.ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup<Startup>(); });
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void ConfigureServices(IServiceCollection services)
services.AddElsaDashboardUI();
services.AddElsaDashboardBackend(options => options.ServerUrl = new Uri("https://localhost:11000"));

if (Program.UseBlazorServer)
if (Program.RuntimeModel == BlazorRuntimeModel.Server)
services.AddServerSideBlazor(options =>
{
options.DetailedErrors = !Environment.IsProduction();
Expand All @@ -40,7 +40,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseDeveloperExceptionPage();

if(Program.UseBlazorWebAssembly)
if (Program.RuntimeModel == BlazorRuntimeModel.Browser)
app.UseWebAssemblyDebugging();
}
else
Expand All @@ -50,15 +50,15 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
app.UseHsts();
}

if(Program.UseBlazorWebAssembly)
if (Program.RuntimeModel == BlazorRuntimeModel.Browser)
app.UseBlazorFrameworkFiles();

app.UseStaticFiles();
app.UseRouting();
app.UseElsaGrpcServices();
app.UseEndpoints(endpoints =>
{
if(Program.UseBlazorServer)
if (Program.RuntimeModel == BlazorRuntimeModel.Server)
endpoints.MapBlazorHub();

endpoints.MapFallbackToPage("/_Host");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,14 @@ <h3 class="px-3 text-xs leading-4 font-semibold text-gray-500 uppercase tracking
</div>
<main class="flex-1 relative z-0 overflow-y-auto focus:outline-none" tabindex="0" x-data="" x-init="$el.focus()">


<!-- Page title & actions -->
<div class="border-b border-gray-200 px-4 py-4 sm:flex sm:items-center sm:justify-between sm:px-6 lg:px-8">
<div class="flex-1 min-w-0">
<h1 class="text-lg font-medium leading-6 text-gray-900 sm:truncate">
Home
</h1>
</div>
</div>

</main>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
<module href="./src/partials/layout.html">

<!-- Page title & actions -->
<div class="border-b border-gray-200 px-4 py-4 sm:flex sm:items-center sm:justify-between sm:px-6 lg:px-8">
<div class="flex-1 min-w-0">
<h1 class="text-lg font-medium leading-6 text-gray-900 sm:truncate">
Home
</h1>
</div>
</div>
</module>
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
namespace ElsaDashboard.Application.Models
using Microsoft.AspNetCore.Components.Routing;

namespace ElsaDashboard.Application.Models
{
public class MenuItem
{
public MenuItem(string text, string url, string icon)
public MenuItem(string text, string url, string icon, NavLinkMatch match = NavLinkMatch.Prefix)
{
Text = text;
Url = url;
Icon = icon;
}

public string Text { get; set; }
public string Icon { get; set; }
public string Url { get; set; }
public string Text { get; init; }
public string Icon { get; init; }
public string Url { get; init; }
public NavLinkMatch Match { get; init; } = NavLinkMatch.Prefix;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@page "/designer"
@page "/workflows/designer"
@page "/workflows/{workflowDefinitionVersionId}/designer"
<div class="flex-0 border-b border-gray-200 px-4 py-4 sm:flex sm:items-center sm:justify-between sm:px-6 lg:px-8">
<div class="flex-1 min-w-0">
<h1 class="text-lg font-medium leading-6 text-gray-900 sm:truncate">
Expand All @@ -13,4 +14,4 @@
</span>
</div>
</div>
<WorkflowDesigner />
<WorkflowDesigner Model="WorkflowModel" />
Original file line number Diff line number Diff line change
@@ -1,6 +1,56 @@
namespace ElsaDashboard.Application.Pages
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Threading.Tasks;
using Elsa.Client.Models;
using ElsaDashboard.Application.Models;
using ElsaDashboard.Shared.Rpc;
using Microsoft.AspNetCore.Components;

namespace ElsaDashboard.Application.Pages
{
partial class Designer
{
[Parameter]public string? WorkflowDefinitionVersionId { get; set; }
[Inject] private IWorkflowDefinitionService WorkflowDefinitionService { get; set; } = default!;
[Inject] private IActivityService ActivityService { get; set; } = default!;
private IDictionary<string, ActivityDescriptor> ActivityDescriptors { get; set; } = default!;
private WorkflowModel WorkflowModel { get; set; } = WorkflowModel.Blank();

protected override async Task OnInitializedAsync()
{
ActivityDescriptors = (await ActivityService.GetActivitiesAsync()).ToDictionary(x => x.Type);

if (WorkflowDefinitionVersionId != null)
{
var workflowDefinition = await WorkflowDefinitionService.GetByVersionIdAsync(WorkflowDefinitionVersionId);
WorkflowModel = CreateWorkflowModel(workflowDefinition);
}
else
{
WorkflowModel = WorkflowModel.Blank();
}
}

private WorkflowModel CreateWorkflowModel(WorkflowDefinition workflowDefinition)
{
return new WorkflowModel
{
Name = workflowDefinition.Name,
Activities = workflowDefinition.Activities.Select(CreateActivityModel).ToImmutableList(),
Connections = workflowDefinition.Connections.Select(CreateConnectionModel).ToImmutableList()
};
}

private ConnectionModel CreateConnectionModel(ConnectionDefinition connectionDefinition)
{
return new(connectionDefinition.SourceActivityId, connectionDefinition.TargetActivityId, connectionDefinition.Outcome);
}

private ActivityModel CreateActivityModel(ActivityDefinition activityDefinition)
{
var descriptor = ActivityDescriptors[activityDefinition.Type];
return new ActivityModel(activityDefinition.ActivityId, activityDefinition.Type, descriptor.Outcomes);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
@page "/"

<h1>Hello, world!</h1>

Welcome to your new app.
<!-- Page title & actions -->
<div class="border-b border-gray-200 px-4 py-4 sm:flex sm:items-center sm:justify-between sm:px-6 lg:px-8">
<div class="flex-1 min-w-0">
<h1 class="text-lg font-medium leading-6 text-gray-900 sm:truncate">
Home
</h1>
</div>
</div>
Loading

0 comments on commit c193b28

Please sign in to comment.