Skip to content

Commit

Permalink
Update save and read workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
dogzz9445 committed Jun 24, 2024
1 parent 75d9c21 commit d439df5
Show file tree
Hide file tree
Showing 19 changed files with 388 additions and 117 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"Preferences": {
"UseSystemTheme": false,
"Theme": "Light",
"Language": "en_US"
},
"Packages": {},
"Dashboards": {
"Id": "ba5b6e0a-51fa-4dc4-992e-3123cc287cb7",
"SelectedProjectId": null,
"Projects": [
{
"Id": "926c252b-a158-4e05-8593-7cb55c10bf24",
"SelectedWorkflowId": null,
"Settings": {
"Name": "ABCasdasdasd"
},
"WorkflowIds": []
},
{
"Id": "22778c82-674a-41a7-9fe9-c61d76329690",
"SelectedWorkflowId": null,
"Settings": {
"Name": "\uC548\uB155\uD558\uC138\uC694!"
},
"WorkflowIds": []
},
{
"Id": "0c7f047c-e153-4496-9bc0-1d79d8e2c91b",
"SelectedWorkflowId": null,
"Settings": {
"Name": "My Project"
},
"WorkflowIds": []
}
],
"Workflows": [],
"Widgets": []
}
}
7 changes: 5 additions & 2 deletions src/Apps/Corathing.Organizer/Corathing.Organizer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@

<ItemGroup>
<PackageReference Include="MahApps.Metro" Version="2.4.10" />
<PackageReference Include="MaterialDesignThemes" Version="5.0.0" />
<PackageReference Include="MaterialDesignThemes.MahApps" Version="1.0.0" />
<PackageReference Include="MaterialDesignThemes" Version="5.1.0" />
<PackageReference Include="MaterialDesignThemes.MahApps" Version="3.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.6" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
Expand Down Expand Up @@ -68,6 +68,9 @@
</ItemGroup>

<ItemGroup>
<None Update="AppData\Current\cora-organizer-settings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="appsettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down
34 changes: 28 additions & 6 deletions src/Apps/Corathing.Organizer/Models/ProjectContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
using CommunityToolkit.Mvvm.Input;

using Corathing.Contracts.Bases;
using Corathing.Contracts.Bases.Interfaces;
using Corathing.Contracts.Services;
using Corathing.Organizer.Services;

using Microsoft.Extensions.DependencyInjection;

Expand All @@ -24,7 +26,6 @@ public partial class ProjectContext : ObservableObject
#endregion
#region Public Properties
public Guid ProjectId { get; set; }
public ProjectState ProjectState;

/// <summary>
/// Gets or sets the title.
Expand Down Expand Up @@ -64,11 +65,20 @@ public ObservableCollection<WorkflowContext> Workflows
public void AddWorkflow()
{
var appState = _services.GetService<IAppStateService>();
var workflow = appState.CreateAddWorkflow();
//appState.NewWorkflowState();

var workflowState = appState.CreateAddWorkflow();
var workflowContext = _services.GetService<WorkflowContext>();
workflowContext.WorkflowId = workflow.Id;
workflowContext.EditMode = EditMode;
workflowContext.UpdateWorkflow(workflowState);

if (!appState.TryGetProject(ProjectId, out var projectState))
{
// TODO:
// Change Exception Type
throw new Exception();
}
projectState.WorkflowIds.Add(workflowState.Id);
appState.UpdateProject(projectState);

Workflows.Add(workflowContext);
SelectedWorkflow = workflowContext;
Expand Down Expand Up @@ -97,11 +107,23 @@ public static ProjectContext Create(ProjectState? state = null)

public void UpdateProject(ProjectState projectState)
{
var packageService = _services.GetService<IPackageService>();
var appStateService = _services.GetService<IAppStateService>();
var dashboardState = appStateService.GetAppDashboardState();

ProjectId = projectState.Id;
Name = projectState.Settings.Name;

foreach (var workflowStateId in projectState.WorkflowIds)
{
if (!appStateService.TryGetWorkflow(workflowStateId, out var workflowState))
{
// TODO:
// Change Exception Type
throw new Exception();
}
var workflowContext = _services.GetService<WorkflowContext>();
workflowContext.EditMode = EditMode;
workflowContext.UpdateWorkflow(workflowState);
}
}

protected override void OnPropertyChanged(PropertyChangedEventArgs e)
Expand Down
46 changes: 30 additions & 16 deletions src/Apps/Corathing.Organizer/Models/WorkflowContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

using Corathing.Contracts.Bases;
using Corathing.Contracts.Entries;
using Corathing.Contracts.Factories;
using Corathing.Contracts.Services;
using Corathing.Dashboards.WPF.Controls;
using Corathing.Organizer.Controls;
Expand Down Expand Up @@ -54,7 +55,7 @@ public partial class WorkflowContext : ObservableObject

#endregion

public Guid? WorkflowId { get; set; }
public Guid WorkflowId { get; set; }
public WorkflowState WorkflowState { get; set; }

#region Public Properties
Expand All @@ -63,7 +64,7 @@ public partial class WorkflowContext : ObservableObject
/// </summary>
/// <value>The title.</value>
[ObservableProperty]
private string _title = "My Workflow";
private string _name = "My Workflow";

[DefaultValue(false)]
[ObservableProperty]
Expand All @@ -80,24 +81,33 @@ public partial class WorkflowContext : ObservableObject
[ObservableProperty]
private ObservableCollection<WidgetContext> _widgets;

public WorkflowContext(IServiceProvider services)
{
_services = services;
Widgets = new ObservableCollection<WidgetContext>();
}

public void UpdateWorkflow(WorkflowState workflowState)
{
var packageService = _services.GetService<IPackageService>();
var appStateService = _services.GetService<IAppStateService>();
var dashboardState = appStateService.GetAppDashboardState();

Title = workflowState.Settings.Name;
Name = workflowState.Settings.Name;
WorkflowId = workflowState.Id;
foreach (var widgetId in workflowState.WidgetIds)
foreach (var widgetStateId in workflowState.WidgetIds)
{
var widgetState = dashboardState.Widgets.FirstOrDefault(widget => widget.Id == widgetId);
if (widgetState == null)
continue;
if (!appStateService.TryGetWidget(widgetStateId, out var widgetState))
{
// TODO:
// Change Exception Type
throw new Exception();
}

if (!packageService.TryGetWidgetGenerator(widgetState.CoreSettings.TypeName, out var generator))
continue;

var widgetContext = generator.CreateWidget(widgetState);
widgetContext.EditMode = EditMode;
AddWidget(widgetContext);
}
}
Expand All @@ -111,8 +121,18 @@ public void AddWidget(CoraWidgetGenerator generator)

public void AddWidget(WidgetContext context)
{
var dialogService = _services.GetService<IDialogService>();
var appState = _services.GetService<IAppStateService>();

if (!appState.TryGetWorkflow(WorkflowId, out var workflowState))
{
// TODO:
// Change Exception Type
throw new Exception();
}

appState.UpdateWidget(context.State);
workflowState.WidgetIds.Add(context.WidgetId);
appState.UpdateWorkflow(workflowState);
Widgets.Add(context);
}

Expand Down Expand Up @@ -151,7 +171,7 @@ public void ConfigureWidget(WidgetHost widget)
public void LayoutChanged(DashboardHost host)
{
var appState = _services.GetService<IAppStateService>();
if (WorkflowId != null && appState.TryGetWorkflow(WorkflowId.Value, out var workflowState))
if (WorkflowId != null && appState.TryGetWorkflow(WorkflowId, out var workflowState))
{
appState.UpdateWorkflow(workflowState);
appState.UpdateForce();
Expand All @@ -167,12 +187,6 @@ protected override void OnPropertyChanging(PropertyChangingEventArgs e)
}


public WorkflowContext(IServiceProvider services)
{
_services = services;
Widgets = new ObservableCollection<WidgetContext>();
}

#endregion Public Properties
protected override void OnPropertyChanged(PropertyChangedEventArgs e)
{
Expand Down
Loading

0 comments on commit d439df5

Please sign in to comment.