Skip to content

Commit

Permalink
Merge pull request #93 from emeraudeframework/dev
Browse files Browse the repository at this point in the history
Apply parent model placeholders to table rows
  • Loading branch information
gsk567 committed Jan 12, 2022
2 parents 0ae83a8 + a9e8c81 commit f269f92
Showing 1 changed file with 16 additions and 2 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.Admin.Models;
using Emeraude.Essentials.Extensions;
using Microsoft.Extensions.Primitives;

namespace Emeraude.Application.Admin.EmPages.Services;
Expand Down Expand Up @@ -151,9 +152,17 @@ private async Task<EmPageIndexViewModel> RetrieveTableViewModelAsync(
var requestResult = await dataManager.FetchAsync(fetchQuery);
if (requestResult != null)
{
IEmPageModel parentRawModel = null;
var parentId = query.GetValueOrDefault(EmPagesConstants.ParentQueryParam).FirstOrDefault();
if (schemaDescription.ParentSchema != null && !string.IsNullOrWhiteSpace(parentId))
{
var parentDataManager = this.GetDataManagerInstance(schemaDescription.ParentSchema);
parentRawModel = await parentDataManager.GetRawModelAsync(parentId);
}

foreach (var item in requestResult.Items)
{
var rowModel = this.BuildTableRow(item, model, schemaDescription);
var rowModel = await this.BuildTableRowAsync(item, model, schemaDescription, parentRawModel);
model.TableViewModel.Rows.Add(rowModel);
}

Expand Down Expand Up @@ -192,7 +201,7 @@ private ActionModel BuildRowAction(EmPageAction action, string route)
};
}

private EmPageTableRowModel BuildTableRow(EmPageModelResponse item, EmPageIndexViewModel model, EmPageSchemaDescription schemaDescription)
private async Task<EmPageTableRowModel> BuildTableRowAsync(EmPageModelResponse item, EmPageIndexViewModel model, EmPageSchemaDescription schemaDescription, IEmPageModel parentModel)
{
var rowModel = new EmPageTableRowModel
{
Expand All @@ -216,6 +225,11 @@ private EmPageTableRowModel BuildTableRow(EmPageModelResponse item, EmPageIndexV
rowModel.Actions.AddRange(model.TableViewModel.RowActions.Select(this.BuildRowAction));
this.SetDataRelatedPlaceholders(rowModel.Actions, item, schemaDescription);

if (schemaDescription.ParentSchema != null && parentModel != null)
{
this.SetDataRelatedPlaceholders(rowModel.Actions, parentModel, schemaDescription.ParentSchema);
}

return rowModel;
}

Expand Down

0 comments on commit f269f92

Please sign in to comment.