This commit is contained in:
@@ -13,6 +13,11 @@ namespace AyaNova.DataList
|
||||
{
|
||||
internal static class DataListFetcher
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Get the data list data requested
|
||||
//
|
||||
//
|
||||
internal static async Task<ApiDataListResponse> GetResponseAsync(string DataListKey, AyContext ct, ListOptions listOptions, AuthorizationRoles UserRoles, ILogger log)
|
||||
{
|
||||
|
||||
@@ -20,20 +25,15 @@ namespace AyaNova.DataList
|
||||
|
||||
//was the name not found as a list?
|
||||
if (DataList == null)
|
||||
{
|
||||
throw new System.ArgumentOutOfRangeException($"DataList \"{DataListKey}\" specified does not exist");
|
||||
}
|
||||
|
||||
//check rights
|
||||
|
||||
if (!UserRoles.HasAnyFlags(DataList.AllowedRoles))
|
||||
throw new System.UnauthorizedAccessException("User roles insufficient for this datalist");
|
||||
|
||||
//do we need to default the listView?
|
||||
if (string.IsNullOrWhiteSpace(listOptions.ListView))
|
||||
{
|
||||
listOptions.ListView = DataList.DefaultListView;
|
||||
}
|
||||
|
||||
//parse the list view(s)
|
||||
//This one is for the return list to the Client for grid column display
|
||||
@@ -212,37 +212,35 @@ namespace AyaNova.DataList
|
||||
}
|
||||
|
||||
|
||||
//Get a list of id's for reporting
|
||||
internal static async Task<long[]> GetIdListResponseAsync(string dataListKey, string listView, AyContext ct, AuthorizationRoles userRoles, ILogger log)
|
||||
/////////////////////////////////////////////////////////////////
|
||||
// Get a list of id's of the datalist results for reporting
|
||||
//
|
||||
//
|
||||
internal static async Task<long[]> GetIdListResponseAsync(string dataListKey, string listView, string metaListView, AyContext ct, AuthorizationRoles userRoles, ILogger log)
|
||||
{
|
||||
|
||||
var DataList = DataListFactory.GetAyaDataList(dataListKey);
|
||||
|
||||
//was the name not found as a list?
|
||||
if (DataList == null)
|
||||
{
|
||||
throw new System.ArgumentOutOfRangeException($"DataList \"{dataListKey}\" specified does not exist");
|
||||
}
|
||||
|
||||
//check rights
|
||||
|
||||
if (!userRoles.HasAnyFlags(DataList.AllowedRoles))
|
||||
throw new System.UnauthorizedAccessException("User roles insufficient for this datalist");
|
||||
|
||||
//do we need to default the listView?
|
||||
if (string.IsNullOrWhiteSpace(listView))
|
||||
{
|
||||
listView = DataList.DefaultListView;
|
||||
}
|
||||
|
||||
//parse the list view
|
||||
var ListViewArray = JArray.Parse(listView);
|
||||
|
||||
var MetaListViewArray = JArray.Parse(metaListView ?? "[]");
|
||||
foreach (JToken jt in MetaListViewArray)
|
||||
ListViewArray.Add(jt);
|
||||
|
||||
//Get the field key names in a list from the listview
|
||||
List<string> ListViewFieldList = DataList.GetFieldListFromListView(ListViewArray);
|
||||
|
||||
|
||||
//BUILD THE QUERY
|
||||
//SELECT FRAGMENT COLUMNS FROM TEMPLATE
|
||||
var SelectBuild = DataListSqlSelectBuilder.BuildForReportIdListOnly(DataList.FieldDefinitions, ListViewFieldList);
|
||||
@@ -259,7 +257,6 @@ namespace AyaNova.DataList
|
||||
//ORDER BY CLAUSE - SORT
|
||||
qOrderBy = DataListSqlFilterOrderByBuilder.DataFilterToSQLOrderBy(DataList.FieldDefinitions, ListViewArray);
|
||||
|
||||
|
||||
//PUT IT ALL TOGETHER
|
||||
string qDataQuery = string.Empty;
|
||||
|
||||
@@ -281,12 +278,9 @@ namespace AyaNova.DataList
|
||||
}
|
||||
}
|
||||
|
||||
//QUERY THE DB
|
||||
using (var command = ct.Database.GetDbConnection().CreateCommand())
|
||||
{
|
||||
await ct.Database.OpenConnectionAsync();
|
||||
|
||||
//GET DATA RETURN ROWS
|
||||
command.CommandText = qDataQuery;
|
||||
try
|
||||
{
|
||||
@@ -294,21 +288,8 @@ namespace AyaNova.DataList
|
||||
{
|
||||
while (dr.Read())
|
||||
{
|
||||
//todo: test this with a full on widget report
|
||||
if (!dr.IsDBNull(IDColumnOrdinal))
|
||||
retList.Add(dr.GetInt64(IDColumnOrdinal));
|
||||
// foreach (string TemplateField in ListViewFieldList)
|
||||
// {
|
||||
// //get the AyaObjectFieldDefinition
|
||||
// AyaDataListFieldDefinition f = DataList.FieldDefinitions.FirstOrDefault(z => z.FieldKey == TemplateField);
|
||||
// if (f.IsRowId)
|
||||
// {
|
||||
// var ordinal = SelectBuild.map[f.SqlIdColumnName];
|
||||
// if (!await dr.IsDBNullAsync(ordinal))
|
||||
// retList.Add(dr.GetInt64(ordinal));
|
||||
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -320,13 +301,9 @@ namespace AyaNova.DataList
|
||||
|
||||
log.LogInformation(e, "DB Exception");
|
||||
throw new System.Exception("DataListFetcher:GetIdListResponseAsync - Query failed see log");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//retList.Reverse();
|
||||
return retList.ToArray();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -328,7 +328,7 @@ namespace AyaNova.Biz
|
||||
|
||||
//Do we need to rehydrate the ID List from a DataList?
|
||||
if (reportDataParam.SelectedRowIds.Length == 0)
|
||||
reportDataParam.SelectedRowIds = await AyaNova.DataList.DataListFetcher.GetIdListResponseAsync(reportDataParam.DataListKey, reportDataParam.ListView, ct, effectiveRoles, log);
|
||||
reportDataParam.SelectedRowIds = await AyaNova.DataList.DataListFetcher.GetIdListResponseAsync(reportDataParam.DataListKey, reportDataParam.ListView, reportDataParam.MetaView, ct, effectiveRoles, log);
|
||||
|
||||
log.LogDebug($"Instantiating biz object handler for {reportDataParam.ObjectType}");
|
||||
var biz = BizObjectFactory.GetBizObject(reportDataParam.ObjectType, ct);
|
||||
|
||||
@@ -10,7 +10,9 @@ namespace AyaNova.Models
|
||||
public AyaType ObjectType { get; set; }
|
||||
public long[] SelectedRowIds { get; set; }
|
||||
public string DataListKey { get; set; }
|
||||
public string ListView { get; set; }//optional, if null or empty will use default list view built into DataList
|
||||
public string ListView { get; set; }//optional, if null or empty will use default list view built into DataList
|
||||
public string MetaView { get; set; }//optional meta list view to integrate into the standard list view. Used by client to add "meta" filter conditions above the user's choices e.g. customer notes customer id
|
||||
|
||||
|
||||
public bool IsEmpty
|
||||
{
|
||||
@@ -23,7 +25,7 @@ namespace AyaNova.Models
|
||||
public async Task RehydrateIdList(AyContext ct, AuthorizationRoles userRoles, Microsoft.Extensions.Logging.ILogger log)
|
||||
{
|
||||
if (SelectedRowIds.Length == 0)
|
||||
SelectedRowIds = await AyaNova.DataList.DataListFetcher.GetIdListResponseAsync(DataListKey, ListView, ct, userRoles, log);
|
||||
SelectedRowIds = await AyaNova.DataList.DataListFetcher.GetIdListResponseAsync(DataListKey, ListView, MetaView, ct, userRoles, log);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user