Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Event send request #28

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<Authors>EasyMicroservices</Authors>
<IsPackable>true</IsPackable>
<Version>0.0.0.23</Version>
<Version>0.0.0.24</Version>
<Description>TemplateGenerator UI compoents.</Description>
<Copyright>[email protected]</Copyright>
<PackageTags>component,microcomponent,ui,core,templategenerator,generator,template,form,formgenerator</PackageTags>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@
}
}

[Parameter]
[Category("Behavior")]
public ObservableCollection<FormItemEventContract> FormItemEvents
{
get
Expand All @@ -72,11 +74,18 @@
}
set
{
if (ViewModel.FormItemEvents == value)
return;
ViewModel.FormItemEvents = value;
StateHasChanged();
FormItemEventsChanged.InvokeAsync(value);
}
}


[Parameter]
public EventCallback<ObservableCollection<FormItemEventContract>> FormItemEventsChanged { get; set; }

AddOrUpdateFormItemEvent AddOrUpdateFormItemEventView;
SaveChangeBaseDialog<FormItemEventContract> addOrUpdateDialog;
DeleteBaseDialog<FormItemEventContract> deleteDialog;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
</MudDataGrid>
</MudTabPanel>
<MudTabPanel Text="@viewModel.GetInnerTranslatedByKey("Events")">
<FormItemEventsList @ref="formItemEventsList" />
<FormItemEventsList @ref="formItemEventsList" @bind-FormItemEvents="@viewModel.FormItemEvents" />
</MudTabPanel>
</MudTabs>
<MudButton Variant="Variant.Filled" StartIcon="@Icons.Material.Filled.Save" Color="Color.Info" Disabled="viewModel.IsBusy" OnClick="(arg) => viewModel.SaveCommand.Execute(null)">
Expand Down Expand Up @@ -156,7 +156,6 @@
addDialog.ShowDialog(() =>
{
AddOrUpdateFormItemView.ViewModel.Clear();
viewModel.FormItemEvents = formItemEventsList.FormItemEvents;
AddOrUpdateFormItemView.ViewModel.OnSuccess = (contract) =>
{
viewModel.FormItems.Add(contract);
Expand All @@ -174,8 +173,8 @@
{
AddOrUpdateFormItemView.ViewModel.Clear();
AddOrUpdateFormItemView.ViewModel.UpdateFormItemContract = formItemContract;
if (formItemContract.Events != null)
viewModel.FormItemEvents = formItemEventsList.FormItemEvents = new System.Collections.ObjectModel.ObservableCollection<FormItemEventContract>(formItemContract.Events);
//if (formItemContract.Events != null)
// viewModel.FormItemEvents = formItemEventsList.FormItemEvents = new System.Collections.ObjectModel.ObservableCollection<FormItemEventContract>(formItemContract.Events);
AddOrUpdateFormItemView.ViewModel.OnSuccess = (item) =>
{
var index = viewModel.FormItems.IndexOf(formItemContract);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<Authors>EasyMicroservices</Authors>
<IsPackable>true</IsPackable>
<Version>0.0.0.23</Version>
<Version>0.0.0.24</Version>
<Description>TemplateGenerator view model.</Description>
<Copyright>[email protected]</Copyright>
<PackageTags>component,microcomponent,ui,core,templategenerator,generator,template,form,formgenerator</PackageTags>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@
Title = Title,
Items = FormItems,
PrimaryFormItemId = SelectedNoParentFormItem?.Id,
Events = FormItemEvents
Events = CleanCollection(Clone(FormItemEvents.ToList()))
};
}

Expand All @@ -162,7 +162,7 @@
Title = Title,
Items = JsonSerializer.Deserialize<List<CreateFormItemContract>>(JsonSerializer.Serialize(FormItems)),
PrimaryFormItemId = SelectedNoParentFormItem?.Id,
Events = FormItemEvents
Events = CleanCollection(Clone(FormItemEvents.ToList()))
};
}

Expand All @@ -176,11 +176,11 @@
Title = Title,
Items = FormItems,
PrimaryFormItemId = SelectedNoParentFormItem?.Id,
Events = FormItemEvents
Events = CleanCollection(Clone(FormItemEvents.ToList()))
};
}

public async Task Save()

Check warning on line 183 in src/CSharp/Cores/EasyMicroservices.UI.TemplateGenerator.ViewModels/ViewModels/FormItems/AddOrUpdateFormItemViewModel.cs

View workflow job for this annotation

GitHub Actions / os-tests

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 183 in src/CSharp/Cores/EasyMicroservices.UI.TemplateGenerator.ViewModels/ViewModels/FormItems/AddOrUpdateFormItemViewModel.cs

View workflow job for this annotation

GitHub Actions / os-tests

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 183 in src/CSharp/Cores/EasyMicroservices.UI.TemplateGenerator.ViewModels/ViewModels/FormItems/AddOrUpdateFormItemViewModel.cs

View workflow job for this annotation

GitHub Actions / os-tests

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
{
OnSuccess?.Invoke(GetContract());
}
Expand Down Expand Up @@ -216,6 +216,37 @@
}
}

T Clone<T>(T data)
{
return JsonSerializer.Deserialize<T>(JsonSerializer.Serialize(data));
}

ICollection<FormItemEventContract> CleanCollection(ICollection<FormItemEventContract> formItemEvents)
{
if (formItemEvents == null)
return formItemEvents;
foreach (var item in formItemEvents)
{
if (item.EventId > 0)
item.Event = null;
CleanCollection(item.FormItemEventActions);
}
return formItemEvents;
}

ICollection<FormItemEventActionContract> CleanCollection(ICollection<FormItemEventActionContract> formItemEventActions)
{
if (formItemEventActions == null)
return formItemEventActions;
foreach (var item in formItemEventActions)
{
if (item.ActionId > 0)
item.Action = null;
CleanCollection(item.Children);
}
return formItemEventActions;
}

public void Clear()
{
Title = "";
Expand Down
Loading