LISTS WORKING cleanup afterwords

This commit is contained in:
2021-02-08 20:10:28 +00:00
parent 4a7f9f06ca
commit 658b345378
48 changed files with 50 additions and 2586 deletions

View File

@@ -6,7 +6,6 @@ using Microsoft.Extensions.Logging;
using AyaNova.Models;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using EnumsNET;
namespace AyaNova.DataList
{
@@ -19,39 +18,7 @@ namespace AyaNova.DataList
//
internal static async Task<DataListReturnData> GetResponseAsync(AyContext ct, DataListTableProcessingOptions dataListTableProcessingOptions, IDataListProcessing DataList, AuthorizationRoles userRoles, ILogger log, long userId)
{
// var DataList = DataListFactory.GetAyaDataList(dataListTableRequest.DataListKey);
//was the name not found as a list?
// if (DataList == null)
// throw new System.ArgumentOutOfRangeException($"DataList \"{dataListTableRequest.DataListKey}\" specified does not exist");
//turn the DataListTableRequest into a DataListTableProcesingOptions object here
//hydrates filter and column selections etc
// = new DataListTableProcessingOptions(dataListTableRequest, DataList, ct);
//#### TODO: below block into above method to clean it up and centralize it
// //STATIC filter options from server
// List<DataListFilterOption> StaticServerFilterOptions = new List<DataListFilterOption>();
// if (DataList is IDataListInternalCriteria)
// StaticServerFilterOptions = ((IDataListInternalCriteria)DataList).DataListInternalCriteria(userId, userRoles, dataListTableOptions);
// //Get the public field key names in a list from the listview
// List<string> PublicListViewFieldList = listOptions.Columns;
//Get the combination of all unique fields from both StaticServerFilterOptions and listOptions
//NOTE: this assumes no list options filter colums that don't exist in listoptions.columns
// var AllUniqueFieldKeysRequiredForQuery = dataListTableOptions.Columns.Union(StaticServerFilterOptions.Select(z => z.Column).ToList()).ToList();
// //Add the internal filters into the listoptions existing filters
// //NOTE: There is currently no overlap between internal filtered columns and filters coming from the client
// foreach (DataListFilterOption dfo in StaticServerFilterOptions)
// dataListTableOptions.Filter.Add(dfo);
//BUILD THE QUERY
//#BUILD THE QUERY
//SELECT CLAUSE
var qSelect = DataListSqlSelectBuilder.BuildForDataTableListResponse(DataList.FieldDefinitions, dataListTableProcessingOptions.AllUniqueColumnKeysReferenced);
@@ -100,17 +67,13 @@ namespace AyaNova.DataList
while (dr.Read())
{
List<DataListField> row = new List<DataListField>(returnRowColumnCount);
//INSERT REMAINING FIELDS FROM TEMPLATE INTO THE RETURN ROWS LIST
foreach (string TemplateField in dataListTableProcessingOptions.Columns)
{
//get the AyaObjectFieldDefinition
DataListFieldDefinition f = DataList.FieldDefinitions.FirstOrDefault(z => z.FieldKey == TemplateField);
if (f.IsCustomField)
{
DataListField AyaField = new DataListField();
//could be null
var rawValue = dr.GetValue(qSelect.map[f.GetSqlValueColumnName()]);
@@ -123,7 +86,6 @@ namespace AyaNova.DataList
//convert field name to cust name then get value
var InternalCustomFieldName = FormFieldReference.TranslateLTCustomFieldToInternalCustomFieldName(TemplateField);
//Sometimes a custom field is specified but doesn't exist in the collection so don't assume it's there
// AyaField.v = j[InternalCustomFieldName].Value<object>();
JToken o = j[InternalCustomFieldName];
if (o != null)
AyaField.v = o.Value<object>();
@@ -131,29 +93,12 @@ namespace AyaNova.DataList
AyaField.v = null;
row.Add(AyaField);
}else{
AyaField.v=null;
}
else
{
AyaField.v = null;
}
}
/*
TODO: Custom field handling
GetName works just not with multipart identifiers
I could force naming by making all fields and AS, or
I could map the ordinal when generating the Select fields so that I have a map to refer to here
mapping in advance actually makes a lot of sense, then no more of this fragility of going by pointer index and hoping for the best
it would just be premapped out.
dr.GetOrdinal(f.SqlValueColumnName)
'dr.GetOrdinal(f.SqlValueColumnName)' threw an exception of type 'System.IndexOutOfRangeException'
f.SqlValueColumnName
"awidget.customfields"
dr.GetName(nCurrentColumnPointer)
"customfields"
dr.GetOrdinal("customfields");
5
*/
}
else
{
@@ -230,72 +175,22 @@ namespace AyaNova.DataList
}
}
//BUILD THE COLUMNS RETURN PROPERTY JSON FRAGMENT
Newtonsoft.Json.Linq.JArray ColumnsJSON = null;
ColumnsJSON = DataList.GenerateReturnListColumns(dataListTableProcessingOptions.Columns);
return new DataListReturnData(rows, totalRecordCount, ColumnsJSON, dataListTableProcessingOptions.SortBy, dataListTableProcessingOptions.Filter.Where(z => z.Column.StartsWith("meta") == false).ToList());
}
/////////////////////////////////////////////////////////////////
// Get a list of id's of the datalist results for reporting
//
//
internal static async Task<long[]> GetIdListResponseAsync(AyContext ct, DataListSelectedProcessingOptions dataListSelectionOptions, IDataListProcessing DataList, AuthorizationRoles userRoles, ILogger log, long userId)
{
// // var DataList = DataListFactory.GetAyaDataList(dataListSelectionOptions.DataListKey);
// // //was the name not found as a list?
// // if (DataList == null)
// // throw new System.ArgumentOutOfRangeException($"DataList \"{dataListSelectionOptions.DataListKey}\" specified does not exist");
//#BUILD THE QUERY
// //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;
// DataList.SetListOptionDefaultsIfNecessary(dataListSelectionOptions);
// // //parse the list view
// // var ListViewArray = JArray.Parse(listView);
// // //Hard coded extra criteria from server end
// // if (DataList is IAyaDataListServerCriteria)
// // {
// // var ServerCriteriaListView = JArray.Parse(((IAyaDataListServerCriteria)DataList).DataListServerCriteria(await ct.User.AsNoTracking().FirstOrDefaultAsync(z => z.Id == userId), ct));
// // foreach (JToken jt in ServerCriteriaListView)
// // ListViewArray.Add(jt);
// // }
// //STATIC filter options from server
// List<DataListFilterOption> StaticServerFilterOptions = null;
// if (DataList is IDataListInternalCriteria)
// StaticServerFilterOptions = ((IDataListInternalCriteria)DataList).DataListInternalCriteria(userId, userRoles, dataListSelectionOptions);
// //Add the internal filters into the listoptions existing filters
// //NOTE: There is currently no overlap between internal filtered columns and filters coming from the client
// foreach (DataListFilterOption dfo in StaticServerFilterOptions)
// dataListSelectionOptions.Filter.Add(dfo);
// // //Hard coded extra criteria from Client end
// // //parse and combine any additional listview hard coded from Client UI
// // 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 qSelect = DataListSqlSelectBuilder.BuildForIdListResponse(DataList.FieldDefinitions, dataListSelectionOptions);
@@ -319,22 +214,6 @@ namespace AyaNova.DataList
//RETURN OBJECTS
var retList = new List<long>();
//GET ID COLUMN ORDINAL
int IDColumnOrdinal = 0;
//NOTE: assuming change of code means id column is *always* the zeroth column
// foreach (string TemplateField in ListViewFieldList)
// {
// //get the AyaObjectFieldDefinition
// AyaDataListFieldDefinition f = DataList.FieldDefinitions.FirstOrDefault(z => z.FieldKey == TemplateField);
// if (f.IsRowId)
// {
// IDColumnOrdinal = SelectBuild.map[f.SqlIdColumnName];
// break;
// }
// }
using (var command = ct.Database.GetDbConnection().CreateCommand())
{
await ct.Database.OpenConnectionAsync();
@@ -345,8 +224,9 @@ namespace AyaNova.DataList
{
while (dr.Read())
{
if (!dr.IsDBNull(IDColumnOrdinal))
retList.Add(dr.GetInt64(IDColumnOrdinal));
//only one column and it's the zeroth id column
if (!dr.IsDBNull(0))
retList.Add(dr.GetInt64(0));
}
}
}