Skip to content

Commit

Permalink
Merge pull request #92 from emeraudeframework/dev
Browse files Browse the repository at this point in the history
Apply parent reference to forms views
  • Loading branch information
gsk567 committed Jan 12, 2022
2 parents 6b5e7c3 + ecfa730 commit 0ae83a8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Emeraude.Application.Admin.EmPages.Shared;
using Emeraude.Application.Admin.EmPages.Utilities;
using Emeraude.Application.Exceptions;
using Emeraude.Essentials.Extensions;
using Emeraude.Essentials.Helpers;
using Microsoft.Extensions.Primitives;

Expand Down Expand Up @@ -99,11 +100,14 @@ public async Task<EmPageFormViewModel> RetrieveFormViewModelAsync(EmPageFormType
model.Identifier = rawModel?.Id;
this.SetDataRelatedPlaceholders(model.Context.Breadcrumbs, rawModel, schemaDescription);
this.SetDataRelatedPlaceholders(model.Context.NavbarActions, rawModel, schemaDescription);

break;
default:
throw new ArgumentOutOfRangeException(nameof(type), type, null);
}

await this.AssignParentModelAsync(model, schemaDescription, query);

foreach (var formViewItem in formViewItems)
{
model.Inputs.Add(this.BuildFormInput(formViewItem, schemaDescription, rawModel, model));
Expand Down Expand Up @@ -187,6 +191,21 @@ public async Task<EmPageFormSubmissionResponse> SubmitFormViewModelAsync(string
Parameters = viewModel.PropertyParametersMap.FirstOrDefault(x => x.Property == formViewItem.SourceName)?.Value,
};

private async Task AssignParentModelAsync(EmPageViewModel model, EmPageSchemaDescription schemaDescription, IDictionary<string, StringValues> query)
{
var parentId = query.GetValueOrDefault(EmPagesConstants.ParentQueryParam).FirstOrDefault();
if (schemaDescription.ParentSchema != null && !string.IsNullOrWhiteSpace(parentId))
{
var parentDataManager = this.GetDataManagerInstance(schemaDescription.ParentSchema);
var parentRawModel = await parentDataManager.GetRawModelAsync(parentId);
if (parentRawModel != null)
{
this.SetDataRelatedPlaceholders(model.Context.Breadcrumbs, parentRawModel, schemaDescription.ParentSchema);
this.SetDataRelatedPlaceholders(model.Context.NavbarActions, parentRawModel, schemaDescription.ParentSchema);
}
}
}

private IEmPageModel GetModelFromPayload(JsonElement payload, EmPageSchemaDescription schemaDescription)
{
return payload.Deserialize(schemaDescription.ModelType, this.jsonOptions.JsonSerializerOptions) as IEmPageModel;
Expand Down
12 changes: 12 additions & 0 deletions src/Emeraude.Application.Admin.EmPages/Shared/EmPagesConstants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace Emeraude.Application.Admin.EmPages.Shared;

/// <summary>
/// EmPages constants used in the workflow.
/// </summary>
public static class EmPagesConstants
{
/// <summary>
/// Query param key used for identification of the parent.
/// </summary>
public const string ParentQueryParam = "em_parent_id";
}

0 comments on commit 0ae83a8

Please sign in to comment.