This commit is contained in:
@@ -26,58 +26,63 @@ namespace AyaNova.DataList
|
|||||||
public string DefaultListView { get; set; }
|
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)
|
public Newtonsoft.Json.Linq.JArray GenerateListColumnsJSONFromListView(string listView)
|
||||||
{
|
{
|
||||||
throw new System.NotImplementedException("AyaDataList:GenerateListColumnsJSONFromListView not coded yet ");
|
throw new System.NotImplementedException("AyaDataList:GenerateListColumnsJSONFromListView not coded yet ");
|
||||||
// //parse the template
|
// //parse the template
|
||||||
// var jtemplate = JObject.Parse(listView);
|
// var jtemplate = JObject.Parse(listView);
|
||||||
|
|
||||||
|
|
||||||
// //convert to strings (https://stackoverflow.com/a/33836599/8939)
|
// //convert to strings (https://stackoverflow.com/a/33836599/8939)
|
||||||
// var fullFields = ((JArray)jtemplate["full"]).ToObject<string[]>();
|
// var fullFields = ((JArray)jtemplate["full"]).ToObject<string[]>();
|
||||||
|
|
||||||
// //Generate JSON fragment to return with column definitions
|
// //Generate JSON fragment to return with column definitions
|
||||||
// StringBuilder sb = new StringBuilder();
|
// StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
// sb.Append("[");
|
// sb.Append("[");
|
||||||
// //df First column is always the df column
|
// //df First column is always the df column
|
||||||
// sb.Append($"{{\"cm\":\"df\",\"dt\":0,\"ay\":{(int)DefaultListObjectType}}}");
|
// sb.Append($"{{\"cm\":\"df\",\"dt\":0,\"ay\":{(int)DefaultListObjectType}}}");
|
||||||
|
|
||||||
// foreach (string s in fullFields)
|
// foreach (string s in fullFields)
|
||||||
// {
|
// {
|
||||||
// AyaDataListFieldDefinition o = FieldDefinitions.FirstOrDefault(x => x.FieldKey == s);
|
// AyaDataListFieldDefinition o = FieldDefinitions.FirstOrDefault(x => x.FieldKey == s);
|
||||||
// #if (DEBUG)
|
// #if (DEBUG)
|
||||||
// //Developers little helper
|
// //Developers little helper
|
||||||
// if (o == null)
|
// if (o == null)
|
||||||
// {
|
// {
|
||||||
// throw new System.ArgumentNullException($"DEV ERROR in AyaDataList::GenerateListColumnsJSONFromTemplate - field {s} specified in template was NOT found in ObjectFields list");
|
// throw new System.ArgumentNullException($"DEV ERROR in AyaDataList::GenerateListColumnsJSONFromTemplate - field {s} specified in template was NOT found in ObjectFields list");
|
||||||
// }
|
// }
|
||||||
// #endif
|
// #endif
|
||||||
|
|
||||||
// if (o != null)
|
// 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
|
// {//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(",");
|
||||||
// sb.Append("{");
|
// sb.Append("{");
|
||||||
// //Build required part of column definition
|
// //Build required part of column definition
|
||||||
// sb.Append($"\"cm\":\"{o.LtKey}\",\"dt\":{(int)o.UiFieldDataType}");
|
// sb.Append($"\"cm\":\"{o.LtKey}\",\"dt\":{(int)o.UiFieldDataType}");
|
||||||
|
|
||||||
// //Has a AyObjectType? (linkable / openable)
|
// //Has a AyObjectType? (linkable / openable)
|
||||||
// if (o.AyaObjectType != 0)
|
// if (o.AyaObjectType != 0)
|
||||||
// sb.Append($",\"ay\":{(int)o.AyaObjectType}");
|
// sb.Append($",\"ay\":{(int)o.AyaObjectType}");
|
||||||
|
|
||||||
// //Has a Enumtype?
|
// //Has a Enumtype?
|
||||||
// if (!string.IsNullOrEmpty(o.EnumType))
|
// if (!string.IsNullOrEmpty(o.EnumType))
|
||||||
// sb.Append($",\"et\":\"{AyaNova.Util.StringUtil.TrimTypeName(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)
|
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);
|
var DataList = DataListFactory.GetAyaDataList(DataListKey);
|
||||||
//was the name not found as a list?
|
//was the name not found as a list?
|
||||||
if (DataList == null)
|
if (DataList == null)
|
||||||
@@ -25,42 +25,39 @@ namespace AyaNova.DataList
|
|||||||
}
|
}
|
||||||
|
|
||||||
//check rights
|
//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
|
if (!UserRoles.HasAnyFlags(DataList.AllowedRoles))
|
||||||
//start with default
|
throw new System.UnauthorizedAccessException("User roles insufficient for this datalist");
|
||||||
string JSONDataListTemplate = DataList.DefaultDataListDisplayTemplate;
|
|
||||||
|
//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
|
//PARSE THE TEMPLATE INTO A STRING ARRAY
|
||||||
//SO WE KNOW WHICH FIELDS TO RETURN FROM QUERY
|
//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)
|
// //convert to strings array (https://stackoverflow.com/a/33836599/8939)
|
||||||
string[] templateFieldList;
|
// string[] templateFieldList;
|
||||||
if (listOptions.Mini != null && listOptions.Mini == true)
|
// if (listOptions.Mini != null && listOptions.Mini == true)
|
||||||
{
|
// {
|
||||||
templateFieldList = ((JArray)jtemplate["mini"]).ToObject<string[]>();
|
// templateFieldList = ((JArray)jtemplate["mini"]).ToObject<string[]>();
|
||||||
}
|
// }
|
||||||
else
|
// else
|
||||||
{
|
// {
|
||||||
templateFieldList = ((JArray)jtemplate["full"]).ToObject<string[]>();
|
// templateFieldList = ((JArray)jtemplate["full"]).ToObject<string[]>();
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
string[] templateFieldList = DataList.GetFieldListFromListView(listOptions.ListView);
|
||||||
|
|
||||||
//BUILD THE QUERY
|
//BUILD THE QUERY
|
||||||
//SELECT FRAGMENT COLUMNS FROM TEMPLATE
|
//SELECT FRAGMENT COLUMNS FROM TEMPLATE
|
||||||
var qSelectColumns = DataListSqlSelectBuilder.Build(DataList.FieldDefinitions, JSONDataListTemplate, listOptions.Mini);
|
var qSelectColumns = DataListSqlSelectBuilder.Build(DataList.FieldDefinitions, listOptions.ListView);
|
||||||
|
|
||||||
//FROM CLAUSE
|
//FROM CLAUSE
|
||||||
var qFrom = DataList.SQLFrom;
|
var qFrom = DataList.SQLFrom;
|
||||||
@@ -179,14 +176,9 @@ namespace AyaNova.DataList
|
|||||||
|
|
||||||
//BUILD THE COLUMNS RETURN PROPERTY JSON FRAGMENT
|
//BUILD THE COLUMNS RETURN PROPERTY JSON FRAGMENT
|
||||||
Newtonsoft.Json.Linq.JArray ColumnsJSON = null;
|
Newtonsoft.Json.Linq.JArray ColumnsJSON = null;
|
||||||
if (listOptions.Mini != null && listOptions.Mini == true)
|
|
||||||
{
|
ColumnsJSON = DataList.GenerateListColumnsJSONFromListView(JSONDataListTemplate);
|
||||||
ColumnsJSON = DataList.GenerateMINIListColumnsJSON();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ColumnsJSON = DataList.GenerateListColumnsJSONFromListView(JSONDataListTemplate);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return new ApiDataListResponse(rows, totalRecordCount, ColumnsJSON);
|
return new ApiDataListResponse(rows, totalRecordCount, ColumnsJSON);
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ namespace AyaNova.DataList
|
|||||||
{
|
{
|
||||||
public static class DataListSqlFilterCriteriaBuilder
|
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))
|
if (string.IsNullOrWhiteSpace(filterJson))
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ namespace AyaNova.DataList
|
|||||||
|
|
||||||
// public static string DefaultPickListOrderBy => "ORDER BY NAME ASC";
|
// 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))
|
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
|
//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
|
//parse the template
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
using AyaNova.Biz;
|
using AyaNova.Biz;
|
||||||
namespace AyaNova.DataList
|
namespace AyaNova.DataList
|
||||||
{
|
{
|
||||||
@@ -20,7 +21,8 @@ namespace AyaNova.DataList
|
|||||||
//Default / STOCK DataListView when none is specified
|
//Default / STOCK DataListView when none is specified
|
||||||
string DefaultListView { get; set; }
|
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);
|
// bool ValidateTemplate(string template);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user