Skip to content
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 @@ -27,7 +27,12 @@ public async Task ExplicitSetAsync(Guid valueId, string value)
[RemoteService(false)]
public async Task ExplicitAddAsync(CustomFieldValueDto value)
{
await customFieldValueRepository.InsertAsync(ObjectMapper.Map<CustomFieldValueDto, CustomFieldValue>(value));
var entity = new CustomFieldValue(
value.Id,
value.WorksheetInstanceId,
value.CustomFieldId,
value.CurrentValue ?? "{}");
await customFieldValueRepository.InsertAsync(entity);
}

[RemoteService(false)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ public async Task OnGetAsync(Guid valueId,
Guid worksheetInstanceId,
Guid formVersionId,
Guid applicationId,
string uiAnchor)
string uiAnchor,
string columnOrder = "")
{
Row = row;
ValueId = valueId;
Expand Down Expand Up @@ -114,7 +115,7 @@ public async Task OnGetAsync(Guid valueId,

DynamicKeyMap = JsonSerializer.Serialize(keyMap);

AllFields = MergeAndSortFields(DynamicFields ?? [], Properties ?? []);
AllFields = MergeAndSortFields(DynamicFields ?? [], Properties ?? [], columnOrder);
}

private static DynamicFieldMap[] PrefixDynamicFields(DynamicFieldMap[] dynamicFieldMaps)
Expand Down Expand Up @@ -246,15 +247,26 @@ private static void ApplyDynamicFieldPresentationFormat(

private sealed record DynamicKeyMapEntry(string Name, string Type, bool IsDynamic = true);

private static List<EditRowField> MergeAndSortFields(DynamicFieldMap[] dynamicFields, List<WorksheetFieldViewModel> customFields)
private static List<EditRowField> MergeAndSortFields(DynamicFieldMap[] dynamicFields, List<WorksheetFieldViewModel> customFields, string columnOrder)
{
var columnKeys = columnOrder.Split(',', StringSplitOptions.RemoveEmptyEntries);
var orderMap = columnKeys
.Select((key, idx) => (key, idx))
.ToDictionary(t => t.key, t => t.idx, StringComparer.OrdinalIgnoreCase);

int GetOrder(string key) => orderMap.TryGetValue(key, out var idx) ? idx : int.MaxValue;

var fields = new List<EditRowField>();

foreach (var df in dynamicFields)
{
var rawKey = df.Key.StartsWith(DynamicFieldPrefix, StringComparison.Ordinal)
? df.Key[DynamicFieldPrefix.Length..]
: df.Key;
fields.Add(new EditRowField
{
SortKey = df.Name,
SortOrder = GetOrder(rawKey),
DynamicField = df
});
}
Expand All @@ -264,16 +276,18 @@ private static List<EditRowField> MergeAndSortFields(DynamicFieldMap[] dynamicFi
fields.Add(new EditRowField
{
SortKey = cf.Label,
SortOrder = GetOrder(cf.Name),
CustomField = cf
});
}

return [.. fields.OrderBy(f => f.SortKey, StringComparer.OrdinalIgnoreCase)];
return [.. fields.OrderBy(f => f.SortOrder).ThenBy(f => f.SortKey, StringComparer.OrdinalIgnoreCase)];
}

public class EditRowField
{
public string SortKey { get; set; } = string.Empty;
public int SortOrder { get; set; } = int.MaxValue;
public WorksheetFieldViewModel? CustomField { get; set; }
public DynamicFieldMap? DynamicField { get; set; }
public bool IsDynamic => DynamicField != null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,31 +162,32 @@ $(function () {
} return -1; // Return -1 if the column is not found
}

function openEditDatagridRowModal(valueId,
fieldId,
worksheetId,
worksheetInstanceId,
row,
isNew,
uiAnchor) {

function openEditDatagridRowModal(options) {
let formVersionId = $('#ApplicationFormVersionId').val();
let applicationId = $('#DetailsViewApplicationId').val();

editDatagridRowModal.open({
valueId: valueId,
fieldId: fieldId,
row: row,
isNew: isNew,
worksheetId: worksheetId,
worksheetInstanceId: worksheetInstanceId,
valueId: options.valueId,
fieldId: options.fieldId,
row: options.row,
isNew: options.isNew,
worksheetId: options.worksheetId,
worksheetInstanceId: options.worksheetInstanceId,
// There is dependency here on the core module and details page !
formVersionId: formVersionId,
applicationId: applicationId,
uiAnchor: uiAnchor
uiAnchor: options.uiAnchor,
columnOrder: options.columnOrder || ''
});
}

function getColumnOrder(dt) {
return dt.columns().header().toArray()
.map(th => $(th).data('key'))
.filter(key => key !== undefined && key !== null)
.join(',');
}

let actionButtons = [
{
id: 'AddRecord',
Expand All @@ -201,13 +202,16 @@ $(function () {
let tableElement = $('#' + tableId);
let tableDataSet = tableElement[0].dataset;

openEditDatagridRowModal(tableDataSet.valueId,
tableDataSet.fieldId,
tableDataSet.wsId,
tableDataSet.wsiId,
0,
true,
tableDataSet.wsAnchor);
openEditDatagridRowModal({
valueId: tableDataSet.valueId,
fieldId: tableDataSet.fieldId,
worksheetId: tableDataSet.wsId,
worksheetInstanceId: tableDataSet.wsiId,
row: 0,
isNew: true,
uiAnchor: tableDataSet.wsAnchor,
columnOrder: getColumnOrder(dt)
});
}
},
{
Expand Down Expand Up @@ -320,13 +324,16 @@ $(function () {
let table = $(button).closest('table');
let tableDataSet = table[0].dataset;

openEditDatagridRowModal(tableDataSet.valueId,
tableDataSet.fieldId,
tableDataSet.wsId,
tableDataSet.wsiId,
rowDataSet.rowNo,
false,
tableDataSet.uiAnchor);
openEditDatagridRowModal({
valueId: tableDataSet.valueId,
fieldId: tableDataSet.fieldId,
worksheetId: tableDataSet.wsId,
worksheetInstanceId: tableDataSet.wsiId,
row: rowDataSet.rowNo,
isNew: false,
uiAnchor: tableDataSet.uiAnchor,
columnOrder: getColumnOrder(table.DataTable())
});
}

PubSub.subscribe(
Expand Down
Loading