This commit is contained in:
@@ -13,7 +13,7 @@ namespace AyaNova.DataList
|
||||
{
|
||||
internal static class DataListFetcher
|
||||
{
|
||||
internal static async Task<ApiPagedResponse> GetResponseAsync(string DataListKey, AyContext ct, IUrlHelper Url,
|
||||
internal static async Task<ApiDataListResponse> GetResponseAsync(string DataListKey, AyContext ct, IUrlHelper Url,
|
||||
string routeName, ListOptions listOptions, long UserId, AuthorizationRoles UserRoles)
|
||||
{
|
||||
|
||||
@@ -78,15 +78,19 @@ namespace AyaNova.DataList
|
||||
DataListFilter TheFilter = null;
|
||||
var qWhere = string.Empty;
|
||||
var qOrderBy = string.Empty;
|
||||
if (listOptions.DataFilterId > 0)
|
||||
if (!string.IsNullOrWhiteSpace(listOptions.FilterJson))
|
||||
{
|
||||
TheFilter = await ct.DataListFilter.FirstOrDefaultAsync(x => x.Id == listOptions.DataFilterId);
|
||||
//WHERE CLAUSE - FILTER
|
||||
qWhere = DataListSqlFilterCriteriaBuilder.DataFilterToSQLCriteria(DataList.FieldDefinitions, TheFilter, DataList.FieldDefinitions, UserId);
|
||||
qWhere = DataListSqlFilterCriteriaBuilder.DataFilterToSQLCriteria(DataList.FieldDefinitions, listOptions.FilterJson, DataList.FieldDefinitions, UserId);
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(listOptions.SortJson))
|
||||
{
|
||||
//ORDER BY CLAUSE - SORT
|
||||
//BUILD ORDER BY
|
||||
qOrderBy = DataListSqlFilterOrderByBuilder.DataFilterToSQLOrderBy(DataList.FieldDefinitions, TheFilter);
|
||||
}else{
|
||||
qOrderBy = DataListSqlFilterOrderByBuilder.DataFilterToSQLOrderBy(DataList.FieldDefinitions, listOptions.SortJson);
|
||||
}
|
||||
else
|
||||
{
|
||||
//BUILD DEFAULT ORDER BY IF POSSIBLE
|
||||
qOrderBy = DataListSqlFilterOrderByBuilder.DataFilterToSQLOrderBy(DataList.FieldDefinitions, null);
|
||||
}
|
||||
@@ -180,38 +184,41 @@ namespace AyaNova.DataList
|
||||
}
|
||||
}
|
||||
|
||||
//RES.PAGING.COUNT is all I need so the rest is moot, particularly since it's a post method now to get a datalist not a GET with query parameters
|
||||
//below commented stuff can go once it tests
|
||||
|
||||
//BUILD THE PAGING LINKS PORTION
|
||||
//var pageLinks = new PaginationLinkBuilder(Url, routeName, null, listOptions, totalRecordCount).PagingLinksObject();
|
||||
//http://localhost:7575/api/v8/DataList/List?Offset=2&Limit=3&DataFilterId=2&Mini=true&DataListKey=TestWidgetDataList
|
||||
|
||||
object routeValues = null;
|
||||
//no data filter?
|
||||
if (listOptions.DataFilterId == 0)
|
||||
{
|
||||
if (listOptions.Mini)
|
||||
{
|
||||
routeValues = new { DataListKey = DataListKey, Mini = listOptions.Mini };
|
||||
}
|
||||
else
|
||||
{
|
||||
routeValues = new { DataListKey = DataListKey };
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (listOptions.Mini)
|
||||
{
|
||||
routeValues = new { DataListKey = DataListKey, DataFilterId = listOptions.DataFilterId, Mini = listOptions.Mini };
|
||||
}
|
||||
else
|
||||
{
|
||||
routeValues = new { DataListKey = DataListKey, DataFilterId = listOptions.DataFilterId };
|
||||
}
|
||||
}
|
||||
// object routeValues = null;
|
||||
// //no data filter?
|
||||
// if (listOptions.DataFilterId == 0)
|
||||
// {
|
||||
// if (listOptions.Mini)
|
||||
// {
|
||||
// routeValues = new { DataListKey = DataListKey, Mini = listOptions.Mini };
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// routeValues = new { DataListKey = DataListKey };
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// if (listOptions.Mini)
|
||||
// {
|
||||
// routeValues = new { DataListKey = DataListKey, DataFilterId = listOptions.DataFilterId, Mini = listOptions.Mini };
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// routeValues = new { DataListKey = DataListKey, DataFilterId = listOptions.DataFilterId };
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
|
||||
var pageLinks = new PaginationLinkBuilder(Url, routeName, routeValues, listOptions, totalRecordCount).PagingLinksObject();
|
||||
// var pageLinks = new PaginationLinkBuilder(Url, routeName, routeValues, listOptions, totalRecordCount).PagingLinksObject();
|
||||
|
||||
//BUILD THE COLUMNS RETURN PROPERTY JSON FRAGMENT
|
||||
Newtonsoft.Json.Linq.JArray ColumnsJSON = null;
|
||||
@@ -225,8 +232,8 @@ namespace AyaNova.DataList
|
||||
}
|
||||
|
||||
|
||||
ApiPagedResponse pr = new ApiPagedResponse(rows, pageLinks, ColumnsJSON);
|
||||
return pr;
|
||||
return new ApiDataListResponse(rows, totalRecordCount, ColumnsJSON);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -11,10 +11,10 @@ namespace AyaNova.DataList
|
||||
{
|
||||
public static class DataListSqlFilterCriteriaBuilder
|
||||
{
|
||||
public static string DataFilterToSQLCriteria(List<AyaDataListFieldDefinition> objectFieldsList, AyaNova.Models.DataListFilter dataFilter, List<AyaDataListFieldDefinition> objectFields, long userId)
|
||||
public static string DataFilterToSQLCriteria(List<AyaDataListFieldDefinition> objectFieldsList, string filterJson, List<AyaDataListFieldDefinition> objectFields, long userId)
|
||||
{
|
||||
|
||||
if (string.IsNullOrWhiteSpace(dataFilter.Filter))
|
||||
if (string.IsNullOrWhiteSpace(filterJson))
|
||||
{
|
||||
return "";
|
||||
}
|
||||
@@ -22,7 +22,7 @@ namespace AyaNova.DataList
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
//iterate the datafilter and concatenate a sql query from it
|
||||
var FilterArray = JArray.Parse(dataFilter.Filter);
|
||||
var FilterArray = JArray.Parse(filterJson);
|
||||
for (int i = 0; i < FilterArray.Count; i++)
|
||||
{
|
||||
|
||||
|
||||
@@ -12,10 +12,10 @@ namespace AyaNova.DataList
|
||||
|
||||
// public static string DefaultPickListOrderBy => "ORDER BY NAME ASC";
|
||||
|
||||
public static string DataFilterToSQLOrderBy(List<AyaDataListFieldDefinition> objectFieldsList, AyaNova.Models.DataListFilter dataFilter)
|
||||
public static string DataFilterToSQLOrderBy(List<AyaDataListFieldDefinition> objectFieldsList, string SortJson)
|
||||
{
|
||||
|
||||
if (dataFilter == null || string.IsNullOrWhiteSpace(dataFilter.Sort))
|
||||
if ( string.IsNullOrWhiteSpace(SortJson))
|
||||
{
|
||||
//sort by default field descending which should in theory always be the id column of the main object in the list
|
||||
//which should return the results to user with most recent records at the top if no sort order was specified
|
||||
@@ -33,7 +33,7 @@ namespace AyaNova.DataList
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
//iterate the datafilter and concatenate a sql query from it
|
||||
var SortArray = JArray.Parse(dataFilter.Sort);
|
||||
var SortArray = JArray.Parse(SortJson);
|
||||
for (int i = 0; i < SortArray.Count; i++)
|
||||
{
|
||||
|
||||
|
||||
Reference in New Issue
Block a user