This commit is contained in:
2020-02-13 22:18:25 +00:00
parent 684f7be73d
commit e855a7cf88
6 changed files with 73 additions and 74 deletions

View File

@@ -26,6 +26,11 @@ 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)
{ {

View File

@@ -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.GenerateMINIListColumnsJSON();
}
else
{
ColumnsJSON = DataList.GenerateListColumnsJSONFromListView(JSONDataListTemplate); ColumnsJSON = DataList.GenerateListColumnsJSONFromListView(JSONDataListTemplate);
}
return new ApiDataListResponse(rows, totalRecordCount, ColumnsJSON); return new ApiDataListResponse(rows, totalRecordCount, ColumnsJSON);

View File

@@ -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))

View File

@@ -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))

View File

@@ -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

View File

@@ -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);