This commit is contained in:
@@ -26,58 +26,63 @@ namespace AyaNova.DataList
|
||||
public string DefaultListView { get; set; }
|
||||
|
||||
|
||||
public string[] GetFieldListFromListView(string listView)
|
||||
{
|
||||
throw new System.NotImplementedException("AyaDataList:GetFieldListFromListView not coded yet ");
|
||||
|
||||
}
|
||||
|
||||
public Newtonsoft.Json.Linq.JArray GenerateListColumnsJSONFromListView(string listView)
|
||||
{
|
||||
throw new System.NotImplementedException("AyaDataList:GenerateListColumnsJSONFromListView not coded yet ");
|
||||
// //parse the template
|
||||
// var jtemplate = JObject.Parse(listView);
|
||||
// //parse the template
|
||||
// var jtemplate = JObject.Parse(listView);
|
||||
|
||||
|
||||
// //convert to strings (https://stackoverflow.com/a/33836599/8939)
|
||||
// var fullFields = ((JArray)jtemplate["full"]).ToObject<string[]>();
|
||||
// //convert to strings (https://stackoverflow.com/a/33836599/8939)
|
||||
// var fullFields = ((JArray)jtemplate["full"]).ToObject<string[]>();
|
||||
|
||||
// //Generate JSON fragment to return with column definitions
|
||||
// StringBuilder sb = new StringBuilder();
|
||||
// //Generate JSON fragment to return with column definitions
|
||||
// StringBuilder sb = new StringBuilder();
|
||||
|
||||
// sb.Append("[");
|
||||
// //df First column is always the df column
|
||||
// sb.Append($"{{\"cm\":\"df\",\"dt\":0,\"ay\":{(int)DefaultListObjectType}}}");
|
||||
// sb.Append("[");
|
||||
// //df First column is always the df column
|
||||
// sb.Append($"{{\"cm\":\"df\",\"dt\":0,\"ay\":{(int)DefaultListObjectType}}}");
|
||||
|
||||
// foreach (string s in fullFields)
|
||||
// {
|
||||
// AyaDataListFieldDefinition o = FieldDefinitions.FirstOrDefault(x => x.FieldKey == s);
|
||||
// #if (DEBUG)
|
||||
// //Developers little helper
|
||||
// if (o == null)
|
||||
// {
|
||||
// throw new System.ArgumentNullException($"DEV ERROR in AyaDataList::GenerateListColumnsJSONFromTemplate - field {s} specified in template was NOT found in ObjectFields list");
|
||||
// }
|
||||
// #endif
|
||||
// foreach (string s in fullFields)
|
||||
// {
|
||||
// AyaDataListFieldDefinition o = FieldDefinitions.FirstOrDefault(x => x.FieldKey == s);
|
||||
// #if (DEBUG)
|
||||
// //Developers little helper
|
||||
// if (o == null)
|
||||
// {
|
||||
// throw new System.ArgumentNullException($"DEV ERROR in AyaDataList::GenerateListColumnsJSONFromTemplate - field {s} specified in template was NOT found in ObjectFields list");
|
||||
// }
|
||||
// #endif
|
||||
|
||||
// if (o != null)
|
||||
// {//Here is where we can vet the field name, if it doesn't exist. For production we'll just ignore those ones
|
||||
// if (o != null)
|
||||
// {//Here is where we can vet the field name, if it doesn't exist. For production we'll just ignore those ones
|
||||
|
||||
// sb.Append(",");
|
||||
// sb.Append("{");
|
||||
// //Build required part of column definition
|
||||
// sb.Append($"\"cm\":\"{o.LtKey}\",\"dt\":{(int)o.UiFieldDataType}");
|
||||
// sb.Append(",");
|
||||
// sb.Append("{");
|
||||
// //Build required part of column definition
|
||||
// sb.Append($"\"cm\":\"{o.LtKey}\",\"dt\":{(int)o.UiFieldDataType}");
|
||||
|
||||
// //Has a AyObjectType? (linkable / openable)
|
||||
// if (o.AyaObjectType != 0)
|
||||
// sb.Append($",\"ay\":{(int)o.AyaObjectType}");
|
||||
// //Has a AyObjectType? (linkable / openable)
|
||||
// if (o.AyaObjectType != 0)
|
||||
// sb.Append($",\"ay\":{(int)o.AyaObjectType}");
|
||||
|
||||
// //Has a Enumtype?
|
||||
// if (!string.IsNullOrEmpty(o.EnumType))
|
||||
// sb.Append($",\"et\":\"{AyaNova.Util.StringUtil.TrimTypeName(o.EnumType)}\"");
|
||||
// //Has a Enumtype?
|
||||
// if (!string.IsNullOrEmpty(o.EnumType))
|
||||
// sb.Append($",\"et\":\"{AyaNova.Util.StringUtil.TrimTypeName(o.EnumType)}\"");
|
||||
|
||||
// sb.Append("}");
|
||||
// sb.Append("}");
|
||||
|
||||
// }
|
||||
// }
|
||||
// sb.Append("]");
|
||||
// }
|
||||
// }
|
||||
// sb.Append("]");
|
||||
|
||||
// return JArray.Parse(sb.ToString());
|
||||
// return JArray.Parse(sb.ToString());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace AyaNova.DataList
|
||||
internal static async Task<ApiDataListResponse> GetResponseAsync(string DataListKey, AyContext ct, ListOptions listOptions, long UserId, AuthorizationRoles UserRoles)
|
||||
{
|
||||
|
||||
// var AyaObjectFields = AyaObjectFieldDefinitions.AyaObjectFields(AyaObjectFieldDefinitions.TEST_WIDGET_USER_EMAIL_ADDRESS_LIST_KEY);
|
||||
|
||||
var DataList = DataListFactory.GetAyaDataList(DataListKey);
|
||||
//was the name not found as a list?
|
||||
if (DataList == null)
|
||||
@@ -25,42 +25,39 @@ namespace AyaNova.DataList
|
||||
}
|
||||
|
||||
//check rights
|
||||
if (listOptions.Mini != null && listOptions.Mini == true)
|
||||
{
|
||||
if (!UserRoles.HasAnyFlags(DataList.MiniListAllowedRoles))
|
||||
throw new System.UnauthorizedAccessException("User roles insufficient for this mini format datalist");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!UserRoles.HasAnyFlags(DataList.FullListAllowedRoles))
|
||||
throw new System.UnauthorizedAccessException("User roles insufficient for this full format datalist");
|
||||
}
|
||||
|
||||
//FETCH DATALISTTEMPLATE HERE OR USE DEFAULT IF FAULTY OR NOT FOUND
|
||||
//start with default
|
||||
string JSONDataListTemplate = DataList.DefaultDataListDisplayTemplate;
|
||||
if (!UserRoles.HasAnyFlags(DataList.AllowedRoles))
|
||||
throw new System.UnauthorizedAccessException("User roles insufficient for this datalist");
|
||||
|
||||
//parse the list view
|
||||
//TODO: do I need to try /catch here? Or will an exception properly bubble back to the controller
|
||||
var ListViewArray = JArray.Parse(listOptions.ListView);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//PARSE THE TEMPLATE INTO A STRING ARRAY
|
||||
//SO WE KNOW WHICH FIELDS TO RETURN FROM QUERY
|
||||
var jtemplate = JObject.Parse(JSONDataListTemplate);
|
||||
// var jtemplate = JObject.Parse(JSONDataListTemplate);
|
||||
|
||||
//convert to strings array (https://stackoverflow.com/a/33836599/8939)
|
||||
string[] templateFieldList;
|
||||
if (listOptions.Mini != null && listOptions.Mini == true)
|
||||
{
|
||||
templateFieldList = ((JArray)jtemplate["mini"]).ToObject<string[]>();
|
||||
}
|
||||
else
|
||||
{
|
||||
templateFieldList = ((JArray)jtemplate["full"]).ToObject<string[]>();
|
||||
}
|
||||
// //convert to strings array (https://stackoverflow.com/a/33836599/8939)
|
||||
// string[] templateFieldList;
|
||||
// if (listOptions.Mini != null && listOptions.Mini == true)
|
||||
// {
|
||||
// templateFieldList = ((JArray)jtemplate["mini"]).ToObject<string[]>();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// templateFieldList = ((JArray)jtemplate["full"]).ToObject<string[]>();
|
||||
// }
|
||||
|
||||
string[] templateFieldList = DataList.GetFieldListFromListView(listOptions.ListView);
|
||||
|
||||
//BUILD THE QUERY
|
||||
//SELECT FRAGMENT COLUMNS FROM TEMPLATE
|
||||
var qSelectColumns = DataListSqlSelectBuilder.Build(DataList.FieldDefinitions, JSONDataListTemplate, listOptions.Mini);
|
||||
var qSelectColumns = DataListSqlSelectBuilder.Build(DataList.FieldDefinitions, listOptions.ListView);
|
||||
|
||||
//FROM CLAUSE
|
||||
var qFrom = DataList.SQLFrom;
|
||||
@@ -179,14 +176,9 @@ namespace AyaNova.DataList
|
||||
|
||||
//BUILD THE COLUMNS RETURN PROPERTY JSON FRAGMENT
|
||||
Newtonsoft.Json.Linq.JArray ColumnsJSON = null;
|
||||
if (listOptions.Mini != null && listOptions.Mini == true)
|
||||
{
|
||||
ColumnsJSON = DataList.GenerateMINIListColumnsJSON();
|
||||
}
|
||||
else
|
||||
{
|
||||
ColumnsJSON = DataList.GenerateListColumnsJSONFromListView(JSONDataListTemplate);
|
||||
}
|
||||
|
||||
ColumnsJSON = DataList.GenerateListColumnsJSONFromListView(JSONDataListTemplate);
|
||||
|
||||
|
||||
|
||||
return new ApiDataListResponse(rows, totalRecordCount, ColumnsJSON);
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace AyaNova.DataList
|
||||
{
|
||||
public static class DataListSqlFilterCriteriaBuilder
|
||||
{
|
||||
public static string DataFilterToSQLCriteria(List<AyaDataListFieldDefinition> objectFieldsList, string filterJson, long userId)
|
||||
public static string DataFilterToSQLCriteria(List<AyaDataListFieldDefinition> objectFieldsList, JArray listViewArray, long userId)
|
||||
{
|
||||
|
||||
if (string.IsNullOrWhiteSpace(filterJson))
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace AyaNova.DataList
|
||||
|
||||
// public static string DefaultPickListOrderBy => "ORDER BY NAME ASC";
|
||||
|
||||
public static string DataFilterToSQLOrderBy(List<AyaDataListFieldDefinition> objectFieldsList, string SortJson)
|
||||
public static string DataFilterToSQLOrderBy(List<AyaDataListFieldDefinition> objectFieldsList, JArray listViewArray)
|
||||
{
|
||||
|
||||
if ( string.IsNullOrWhiteSpace(SortJson))
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace AyaNova.DataList
|
||||
{
|
||||
|
||||
//Build the SELECT portion of a list query based on the template, mini or full and the object key in question
|
||||
internal static string Build(List<AyaDataListFieldDefinition> objectFieldsList, string template, bool? mini)
|
||||
internal static string Build(List<AyaDataListFieldDefinition> objectFieldsList, JArray listViewArray)
|
||||
{
|
||||
|
||||
//parse the template
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using AyaNova.Biz;
|
||||
namespace AyaNova.DataList
|
||||
{
|
||||
@@ -20,7 +21,8 @@ namespace AyaNova.DataList
|
||||
//Default / STOCK DataListView when none is specified
|
||||
string DefaultListView { get; set; }
|
||||
|
||||
Newtonsoft.Json.Linq.JArray GenerateListColumnsJSONFromListView(string template);
|
||||
Newtonsoft.Json.Linq.JArray GenerateListColumnsJSONFromListView(JArray listViewArray);
|
||||
string[] GetFieldListFromListView(JArray listViewArray);
|
||||
|
||||
// bool ValidateTemplate(string template);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user