Right in the middle of conversion, not compilable yet
This commit is contained in:
@@ -74,7 +74,7 @@ namespace AyaNova.Api.Controllers
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
ApiDataListResponse r = await DataListFetcher.GetResponseAsync(listOptions.DataListKey, ct, listOptions, UserRoles, log, UserId);
|
ApiDataListResponse r = await DataListFetcher.GetResponseAsync(ct, listOptions, UserRoles, log, UserId);
|
||||||
return Ok(r);
|
return Ok(r);
|
||||||
}
|
}
|
||||||
catch (System.UnauthorizedAccessException)
|
catch (System.UnauthorizedAccessException)
|
||||||
|
|||||||
@@ -93,5 +93,7 @@ namespace AyaNova.DataList
|
|||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}//eoc
|
}//eoc
|
||||||
}//eons
|
}//eons
|
||||||
@@ -25,9 +25,22 @@ namespace AyaNova.DataList
|
|||||||
public AuthorizationRoles AllowedRoles { get; set; }
|
public AuthorizationRoles AllowedRoles { get; set; }
|
||||||
public AyaType DefaultListObjectType { get; set; }
|
public AyaType DefaultListObjectType { get; set; }
|
||||||
|
|
||||||
public string DefaultListView { get; set; }
|
|
||||||
|
|
||||||
public long CurrentUserId { get; set; }
|
public long CurrentUserId { get; set; }
|
||||||
|
|
||||||
|
public List<string> DefaultColumns { get; set; }
|
||||||
|
public List<string> DefaultSortBy { get; set; }
|
||||||
|
|
||||||
|
//set defaults if not provided in listOptions
|
||||||
|
public void SetListOptionDefaultsIfNecessary(DataListOptions listOptions)
|
||||||
|
{
|
||||||
|
if (listOptions.Columns.Count == 0)
|
||||||
|
listOptions.Columns = DefaultColumns;
|
||||||
|
if (listOptions.SortBy.Count == 0)
|
||||||
|
listOptions.SortBy = DefaultSortBy;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//return array of field keys in list view
|
//return array of field keys in list view
|
||||||
public List<string> GetFieldListFromListView(JArray listViewArray)
|
public List<string> GetFieldListFromListView(JArray listViewArray)
|
||||||
@@ -215,7 +228,6 @@ namespace AyaNova.DataList
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}//eoc
|
}//eoc
|
||||||
|
|
||||||
}//eons
|
}//eons
|
||||||
@@ -12,6 +12,7 @@ namespace AyaNova.DataList
|
|||||||
var RoleSet = BizRoles.GetRoleSet(DefaultListObjectType);
|
var RoleSet = BizRoles.GetRoleSet(DefaultListObjectType);
|
||||||
AllowedRoles = RoleSet.ReadFullRecord | RoleSet.Change;
|
AllowedRoles = RoleSet.ReadFullRecord | RoleSet.Change;
|
||||||
|
|
||||||
|
|
||||||
//######## DEFAULT VIEW WHEN NO VIEW CHOSEN ############
|
//######## DEFAULT VIEW WHEN NO VIEW CHOSEN ############
|
||||||
//Default ListView
|
//Default ListView
|
||||||
dynamic dlistView = new JArray();
|
dynamic dlistView = new JArray();
|
||||||
@@ -308,5 +309,8 @@ namespace AyaNova.DataList
|
|||||||
FieldDefinitions.Add(new AyaDataListFieldDefinition { TKey = "CustomerCustom15", FieldKey = "customercustom15", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "acustomer.customfields" });
|
FieldDefinitions.Add(new AyaDataListFieldDefinition { TKey = "CustomerCustom15", FieldKey = "customercustom15", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "acustomer.customfields" });
|
||||||
FieldDefinitions.Add(new AyaDataListFieldDefinition { TKey = "CustomerCustom16", FieldKey = "customercustom16", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "acustomer.customfields" });
|
FieldDefinitions.Add(new AyaDataListFieldDefinition { TKey = "CustomerCustom16", FieldKey = "customercustom16", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "acustomer.customfields" });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}//eoc
|
}//eoc
|
||||||
}//eons
|
}//eons
|
||||||
@@ -1,9 +1,11 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using AyaNova.Biz;
|
using AyaNova.Biz;
|
||||||
|
using AyaNova.Models;
|
||||||
|
|
||||||
namespace AyaNova.DataList
|
namespace AyaNova.DataList
|
||||||
{
|
{
|
||||||
internal class CustomerNoteDataList : AyaDataList
|
internal class CustomerNoteDataList : AyaDataList, IAyaDataListServerCriteria
|
||||||
{
|
{
|
||||||
public CustomerNoteDataList()
|
public CustomerNoteDataList()
|
||||||
{
|
{
|
||||||
@@ -75,5 +77,11 @@ namespace AyaNova.DataList
|
|||||||
IsMeta = true
|
IsMeta = true
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string DataListServerCriteria(AyaNova.Models.AyContext ct, long currentUserId, DataListOptions dataListOptions)
|
||||||
|
{
|
||||||
|
throw new System.NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
}//eoc
|
}//eoc
|
||||||
}//eons
|
}//eons
|
||||||
@@ -170,5 +170,6 @@ namespace AyaNova.DataList
|
|||||||
FieldDefinitions.Add(new AyaDataListFieldDefinition { TKey = "CustomerServiceRequestCustom15", FieldKey = "customerservicerequestcustom15", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "acustomerservicerequest.customfields" });
|
FieldDefinitions.Add(new AyaDataListFieldDefinition { TKey = "CustomerServiceRequestCustom15", FieldKey = "customerservicerequestcustom15", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "acustomerservicerequest.customfields" });
|
||||||
FieldDefinitions.Add(new AyaDataListFieldDefinition { TKey = "CustomerServiceRequestCustom16", FieldKey = "customerservicerequestcustom16", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "acustomerservicerequest.customfields" });
|
FieldDefinitions.Add(new AyaDataListFieldDefinition { TKey = "CustomerServiceRequestCustom16", FieldKey = "customerservicerequestcustom16", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "acustomerservicerequest.customfields" });
|
||||||
}
|
}
|
||||||
|
|
||||||
}//eoc
|
}//eoc
|
||||||
}//eons
|
}//eons
|
||||||
@@ -18,57 +18,45 @@ namespace AyaNova.DataList
|
|||||||
// Get the data list data requested
|
// Get the data list data requested
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
internal static async Task<ApiDataListResponse> GetResponseAsync(string DataListKey, AyContext ct, DataListOptions listOptions, AuthorizationRoles UserRoles, ILogger log, long userId)
|
internal static async Task<ApiDataListResponse> GetResponseAsync(AyContext ct, DataListOptions listOptions, AuthorizationRoles userRoles, ILogger log, long userId)
|
||||||
{
|
{
|
||||||
|
|
||||||
var DataList = DataListFactory.GetAyaDataList(DataListKey);
|
var DataList = DataListFactory.GetAyaDataList(listOptions.DataListKey);
|
||||||
|
|
||||||
//was the name not found as a list?
|
//was the name not found as a list?
|
||||||
if (DataList == null)
|
if (DataList == null)
|
||||||
throw new System.ArgumentOutOfRangeException($"DataList \"{DataListKey}\" specified does not exist");
|
throw new System.ArgumentOutOfRangeException($"DataList \"{listOptions.DataListKey}\" specified does not exist");
|
||||||
|
|
||||||
|
|
||||||
//check rights
|
//check rights
|
||||||
if (!UserRoles.HasAnyFlags(DataList.AllowedRoles))
|
if (!userRoles.HasAnyFlags(DataList.AllowedRoles))
|
||||||
throw new System.UnauthorizedAccessException("User roles insufficient for this datalist");
|
throw new System.UnauthorizedAccessException("User roles insufficient for this datalist");
|
||||||
|
|
||||||
//do we need to default the listView?
|
DataList.SetListOptionDefaultsIfNecessary(listOptions);
|
||||||
if (string.IsNullOrWhiteSpace(listOptions.ListView))
|
|
||||||
listOptions.ListView = DataList.DefaultListView;
|
|
||||||
|
|
||||||
//parse the list view(s)
|
|
||||||
//This one is for the return list to the Client for grid column display
|
|
||||||
var PublicListViewArray = JArray.Parse(listOptions.ListView);
|
|
||||||
|
|
||||||
|
|
||||||
|
//STATIC filter options from server
|
||||||
//this one is for internal use here to build the filter and sort etc
|
List<DataListFilterOption> StaticServerFilterOptions = null;
|
||||||
var InternalListViewArray = JArray.Parse(listOptions.ListView);
|
if (DataList is IAyaDataListServerCriteria)
|
||||||
|
StaticServerFilterOptions = ((IAyaDataListServerCriteria)DataList).DataListServerCriteria(userId, userRoles, listOptions);
|
||||||
//Hard coded extra criteria from server end
|
|
||||||
if (DataList is IAyaDataListViewServerCriteria)
|
|
||||||
{
|
|
||||||
var ServerCriteriaListView = JArray.Parse(((IAyaDataListViewServerCriteria)DataList).ListViewServerCriteria(await ct.User.AsNoTracking().FirstOrDefaultAsync(z => z.Id == userId), ct));
|
|
||||||
foreach (JToken jt in ServerCriteriaListView)
|
|
||||||
InternalListViewArray.Add(jt);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Hard coded extra criteria from Client end
|
|
||||||
var MetaListViewArray = JArray.Parse(listOptions.MetaView ?? "[]");
|
|
||||||
foreach (JToken jt in MetaListViewArray)
|
|
||||||
InternalListViewArray.Add(jt);
|
|
||||||
|
|
||||||
|
|
||||||
//Get the public field key names in a list from the listview
|
//Get the public field key names in a list from the listview
|
||||||
List<string> PublicListViewFieldList = DataList.GetFieldListFromListView(PublicListViewArray);
|
List<string> PublicListViewFieldList = listOptions.Columns;
|
||||||
|
|
||||||
//Get the internal only field key names from the internal list view
|
//Get the combination of all unique fields from both StaticServerFilterOptions and listOptions
|
||||||
List<string> InternalListViewFieldList = DataList.GetFieldListFromListView(InternalListViewArray);
|
//NOTE: this assumes no list options filter colums that don't exist in listoptions.columns
|
||||||
|
var AllUniqueFieldKeysRequiredForQuery = PublicListViewFieldList.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)
|
||||||
|
listOptions.Filter.Add(dfo);
|
||||||
|
|
||||||
//BUILD THE QUERY
|
//BUILD THE QUERY
|
||||||
//SELECT FRAGMENT COLUMNS FROM TEMPLATE
|
|
||||||
var SelectBuild = DataListSqlSelectBuilder.Build(DataList.FieldDefinitions, InternalListViewFieldList);
|
//SELECT CLAUSE
|
||||||
|
var qSelect = DataListSqlSelectBuilder.Build(DataList.FieldDefinitions, AllUniqueFieldKeysRequiredForQuery);
|
||||||
|
|
||||||
//FROM CLAUSE
|
//FROM CLAUSE
|
||||||
var qFrom = DataList.SQLFrom;
|
var qFrom = DataList.SQLFrom;
|
||||||
@@ -77,11 +65,11 @@ namespace AyaNova.DataList
|
|||||||
var qOrderBy = string.Empty;
|
var qOrderBy = string.Empty;
|
||||||
|
|
||||||
//WHERE CLAUSE - FILTER
|
//WHERE CLAUSE - FILTER
|
||||||
qWhere = DataListSqlFilterCriteriaBuilder.DataFilterToSQLCriteria(DataList.FieldDefinitions, InternalListViewArray);
|
qWhere = DataListSqlFilterCriteriaBuilder.DataFilterToSQLCriteria(DataList.FieldDefinitions, listOptions);
|
||||||
|
|
||||||
//ORDER BY CLAUSE - SORT
|
//ORDER BY CLAUSE - SORT
|
||||||
//BUILD ORDER BY
|
//BUILD ORDER BY
|
||||||
qOrderBy = DataListSqlFilterOrderByBuilder.DataFilterToSQLOrderBy(DataList.FieldDefinitions, InternalListViewArray);
|
qOrderBy = DataListSqlFilterOrderByBuilder.DataFilterToSQLOrderBy(DataList.FieldDefinitions, listOptions);
|
||||||
|
|
||||||
//LIMIT AND OFFSET CLAUSE - PAGING
|
//LIMIT AND OFFSET CLAUSE - PAGING
|
||||||
listOptions.Offset = listOptions.Offset ?? DataListOptions.DefaultOffset;
|
listOptions.Offset = listOptions.Offset ?? DataListOptions.DefaultOffset;
|
||||||
@@ -92,7 +80,7 @@ namespace AyaNova.DataList
|
|||||||
string qDataQuery = string.Empty;
|
string qDataQuery = string.Empty;
|
||||||
string qTotalRecordsQuery = string.Empty;
|
string qTotalRecordsQuery = string.Empty;
|
||||||
|
|
||||||
qDataQuery = $"{SelectBuild.Select} {qFrom} {qWhere} {qOrderBy} {qLimitOffset}".Replace(" ", " ");
|
qDataQuery = $"{qSelect.Select} {qFrom} {qWhere} {qOrderBy} {qLimitOffset}".Replace(" ", " ");
|
||||||
qTotalRecordsQuery = $"SELECT COUNT(*) {qFrom} {qWhere}".Replace(" ", " ");
|
qTotalRecordsQuery = $"SELECT COUNT(*) {qFrom} {qWhere}".Replace(" ", " ");
|
||||||
|
|
||||||
//RETURN OBJECTS
|
//RETURN OBJECTS
|
||||||
@@ -126,7 +114,7 @@ namespace AyaNova.DataList
|
|||||||
{
|
{
|
||||||
|
|
||||||
AyaFieldData AyaField = new AyaFieldData();
|
AyaFieldData AyaField = new AyaFieldData();
|
||||||
var cust = dr.GetString(SelectBuild.map[f.GetSqlValueColumnName()]);
|
var cust = dr.GetString(qSelect.map[f.GetSqlValueColumnName()]);
|
||||||
if (!string.IsNullOrWhiteSpace(cust))
|
if (!string.IsNullOrWhiteSpace(cust))
|
||||||
{
|
{
|
||||||
JObject j = JObject.Parse(cust);
|
JObject j = JObject.Parse(cust);
|
||||||
@@ -165,7 +153,7 @@ namespace AyaNova.DataList
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
AyaFieldData AyaField = new AyaFieldData();
|
AyaFieldData AyaField = new AyaFieldData();
|
||||||
AyaField.v = dr.GetValue(SelectBuild.map[f.GetSqlValueColumnName()]);
|
AyaField.v = dr.GetValue(qSelect.map[f.GetSqlValueColumnName()]);
|
||||||
|
|
||||||
if (f.IsRowId)
|
if (f.IsRowId)
|
||||||
{
|
{
|
||||||
@@ -178,21 +166,21 @@ namespace AyaNova.DataList
|
|||||||
|
|
||||||
if (f.SqlIdColumnName != null)
|
if (f.SqlIdColumnName != null)
|
||||||
{
|
{
|
||||||
var ordinal = SelectBuild.map[f.SqlIdColumnName];
|
var ordinal = qSelect.map[f.SqlIdColumnName];
|
||||||
if (!await dr.IsDBNullAsync(ordinal))
|
if (!await dr.IsDBNullAsync(ordinal))
|
||||||
AyaField.i = dr.GetInt64(ordinal);
|
AyaField.i = dr.GetInt64(ordinal);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (f.SqlAyTypeColumnName != null)
|
if (f.SqlAyTypeColumnName != null)
|
||||||
{
|
{
|
||||||
var ordinal = SelectBuild.map[f.SqlAyTypeColumnName];
|
var ordinal = qSelect.map[f.SqlAyTypeColumnName];
|
||||||
if (!await dr.IsDBNullAsync(ordinal))
|
if (!await dr.IsDBNullAsync(ordinal))
|
||||||
AyaField.ot = dr.GetInt32(ordinal);
|
AyaField.ot = dr.GetInt32(ordinal);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (f.SqlColorColumnName != null)
|
if (f.SqlColorColumnName != null)
|
||||||
{
|
{
|
||||||
var ordinal = SelectBuild.map[f.SqlColorColumnName];
|
var ordinal = qSelect.map[f.SqlColorColumnName];
|
||||||
if (!await dr.IsDBNullAsync(ordinal))
|
if (!await dr.IsDBNullAsync(ordinal))
|
||||||
AyaField.clr = dr.GetString(ordinal);
|
AyaField.clr = dr.GetString(ordinal);
|
||||||
}
|
}
|
||||||
@@ -242,7 +230,7 @@ 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;
|
||||||
|
|
||||||
ColumnsJSON = DataList.GenerateListColumnsJSONFromListView(PublicListViewArray);
|
ColumnsJSON = DataList.GenerateListColumnsJSONFromListView(listOptions.Columns);
|
||||||
|
|
||||||
return new ApiDataListResponse(rows, totalRecordCount, ColumnsJSON);
|
return new ApiDataListResponse(rows, totalRecordCount, ColumnsJSON);
|
||||||
|
|
||||||
@@ -275,9 +263,9 @@ namespace AyaNova.DataList
|
|||||||
|
|
||||||
|
|
||||||
//Hard coded extra criteria from server end
|
//Hard coded extra criteria from server end
|
||||||
if (DataList is IAyaDataListViewServerCriteria)
|
if (DataList is IAyaDataListServerCriteria)
|
||||||
{
|
{
|
||||||
var ServerCriteriaListView = JArray.Parse(((IAyaDataListViewServerCriteria)DataList).ListViewServerCriteria(await ct.User.AsNoTracking().FirstOrDefaultAsync(z => z.Id == userId), ct));
|
var ServerCriteriaListView = JArray.Parse(((IAyaDataListServerCriteria)DataList).DataListServerCriteria(await ct.User.AsNoTracking().FirstOrDefaultAsync(z => z.Id == userId), ct));
|
||||||
foreach (JToken jt in ServerCriteriaListView)
|
foreach (JToken jt in ServerCriteriaListView)
|
||||||
ListViewArray.Add(jt);
|
ListViewArray.Add(jt);
|
||||||
}
|
}
|
||||||
|
|||||||
68
server/AyaNova/DataList/DataListOptions.cs
Normal file
68
server/AyaNova/DataList/DataListOptions.cs
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace AyaNova.DataList
|
||||||
|
{
|
||||||
|
|
||||||
|
public sealed class DataListOptions
|
||||||
|
{
|
||||||
|
public const int MaxPageSize = 1000;
|
||||||
|
public const int DefaultOffset = 0;
|
||||||
|
public const int DefaultLimit = 25;
|
||||||
|
|
||||||
|
[FromBody]
|
||||||
|
public int? Offset { get; set; }
|
||||||
|
|
||||||
|
[FromBody]
|
||||||
|
public int? Limit { get; set; }
|
||||||
|
|
||||||
|
[FromBody, Required]
|
||||||
|
public string DataListKey { get; set; }
|
||||||
|
|
||||||
|
/*
|
||||||
|
OLD EXAMPLE:
|
||||||
|
{"offset":0,"limit":10,"dataListKey":"CustomerDataList",
|
||||||
|
"listView":"[
|
||||||
|
{\"fld\":\"customername\",\"sort\":\"+\",\"filter\":{\"items\":[{\"op\":\"=\",\"value\":\"dfdfdf\"},{\"op\":\"=\",\"value\":\"3333\"}],\"any\":true}},
|
||||||
|
{\"fld\":\"customerphone1\",\"filter\":{\"items\":[{\"op\":\">\",\"value\":\"44444\"},
|
||||||
|
{\"op\":\"<\",\"value\":\"7777\"}]}},
|
||||||
|
{\"fld\":\"customeremail\"}
|
||||||
|
{\"fld\":\"customerheadoffice\"},
|
||||||
|
{\"fld\":\"customertags\",\"sort\":\"+\"}]"}
|
||||||
|
|
||||||
|
NEW:
|
||||||
|
columns:["PartInventoryTransactionEntryDate","PartPartNumber","PartWarehouseName","PartInventoryTransactionQuantity","PartInventoryTransactionDescription","PartInventoryTransactionSource","PartInventoryBalance"]
|
||||||
|
sortBy:[{"PartInventoryTransactionEntryDate":"-"}],//All sorted columns here as keyvalue pairs value is a string of "+" for ascending "-" for descending
|
||||||
|
filter:[{column:"PartPartNumber",any:true/false,items:[{op: "=",value: "400735"}]}],
|
||||||
|
clientCriteria:"2" //could be anything here that makes sense to the list, in this case an example customer id for customernotedatalist
|
||||||
|
*/
|
||||||
|
[FromBody]
|
||||||
|
public List<string> Columns { get; set; }
|
||||||
|
[FromBody]
|
||||||
|
public Dictionary<string, string> SortBy { get; set; }
|
||||||
|
[FromBody]
|
||||||
|
public List<DataListFilterOption> Filter { get; set; }
|
||||||
|
[FromBody]
|
||||||
|
public string ClientCriteria { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public class DataListFilterOption
|
||||||
|
{
|
||||||
|
public string Column { get; set; }
|
||||||
|
public List<DataListColumnFilter> items { get; set; }
|
||||||
|
public bool Any {get;set;}//means "or" the filter conditions
|
||||||
|
DataListFilterOption()
|
||||||
|
{
|
||||||
|
items = new List<DataListColumnFilter>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class DataListColumnFilter
|
||||||
|
{
|
||||||
|
public string op { get; set; }
|
||||||
|
public string value { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -10,10 +10,10 @@ namespace AyaNova.DataList
|
|||||||
{
|
{
|
||||||
public static class DataListSqlFilterCriteriaBuilder
|
public static class DataListSqlFilterCriteriaBuilder
|
||||||
{
|
{
|
||||||
public static string DataFilterToSQLCriteria(List<AyaDataListFieldDefinition> objectFieldsList, JArray listViewArray)
|
public static string DataFilterToSQLCriteria(List<AyaDataListFieldDefinition> objectFieldsList, DataListOptions listOptions)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (listViewArray == null || listViewArray.Count == 0)
|
if (listOptions.Filter == null || listOptions.Filter.Count == 0)
|
||||||
{
|
{
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
@@ -21,23 +21,25 @@ namespace AyaNova.DataList
|
|||||||
//List to compile each columns where clause fragment for later assembly into sql query
|
//List to compile each columns where clause fragment for later assembly into sql query
|
||||||
List<string> ColumnWhereClauses = new List<string>();
|
List<string> ColumnWhereClauses = new List<string>();
|
||||||
|
|
||||||
for (int i = 0; i < listViewArray.Count; i++)
|
// for (int i = 0; i < listViewArray.Count; i++)
|
||||||
|
|
||||||
|
foreach (DataListFilterOption f in listOptions.Filter)
|
||||||
{
|
{
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
var cm = listViewArray[i];
|
// var cm = listViewArray[i];
|
||||||
//skip it if FILTER is not defined
|
// //skip it if FILTER is not defined
|
||||||
if (cm["filter"] == null)
|
// if (cm["filter"] == null)
|
||||||
{
|
// {
|
||||||
continue;
|
// continue;
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Get some info about this column / field
|
//Get some info about this column / field
|
||||||
var fld = cm["fld"].Value<string>();
|
// var fld = cm["fld"].Value<string>();
|
||||||
|
|
||||||
//var dataType = objectFieldsList.Find(z => z.FieldKey.ToLowerInvariant() == fld.ToLowerInvariant()).UiFieldDataType;
|
//var dataType = objectFieldsList.Find(z => z.FieldKey.ToLowerInvariant() == fld.ToLowerInvariant()).UiFieldDataType;
|
||||||
AyaDataListFieldDefinition DataListField = objectFieldsList.FirstOrDefault(z => z.FieldKey == fld);
|
AyaDataListFieldDefinition DataListField = objectFieldsList.FirstOrDefault(z => z.FieldKey == f.Column);
|
||||||
var dataType = DataListField.UiFieldDataType;
|
var dataType = DataListField.UiFieldDataType;
|
||||||
|
|
||||||
|
|
||||||
@@ -50,26 +52,29 @@ namespace AyaNova.DataList
|
|||||||
//Developers little helper
|
//Developers little helper
|
||||||
if (DataListField == null)
|
if (DataListField == null)
|
||||||
{
|
{
|
||||||
throw new System.ArgumentNullException($"DEV ERROR in DataListSqlFilterCriteriaBuilder.cs: field {fld} specified in template was NOT found in ObjectFields list");
|
throw new System.ArgumentNullException($"DEV ERROR in DataListSqlFilterCriteriaBuilder.cs: field {f.Column} specified in template was NOT found in ObjectFields list");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//get filter items collection for this field view definition
|
//get filter items collection for this field view definition
|
||||||
var filterItems = (JArray)cm["filter"]["items"];
|
// var filterItems = (JArray)cm["filter"]["items"];
|
||||||
|
|
||||||
|
// var IsOrFilter = false;
|
||||||
|
// if (cm["filter"]["any"] != null)
|
||||||
|
// {
|
||||||
|
// IsOrFilter = cm["filter"]["any"].Value<bool>();
|
||||||
|
// }
|
||||||
|
|
||||||
var IsOrFilter = false;
|
|
||||||
if (cm["filter"]["any"] != null)
|
|
||||||
{
|
|
||||||
IsOrFilter = cm["filter"]["any"].Value<bool>();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Iterate filter items building this WHERE segment
|
//Iterate filter items building this WHERE segment
|
||||||
bool ThisIsTheFirstFilterItemForThisColumn = true;
|
bool ThisIsTheFirstFilterItemForThisColumn = true;
|
||||||
var ThereAreMultipleFilterItems = filterItems.Count > 1;
|
//var ThereAreMultipleFilterItems = filterItems.Count > 1;
|
||||||
|
var ThereAreMultipleFilterItems = f.items.Count > 1;
|
||||||
|
|
||||||
for (int y = 0; y < filterItems.Count; y++)
|
// for (int y = 0; y < filterItems.Count; y++)
|
||||||
|
foreach (DataListColumnFilter filterItem in f.items)
|
||||||
{
|
{
|
||||||
//close or open another parenthetic group
|
//close or open another parenthetic group
|
||||||
|
|
||||||
@@ -84,7 +89,8 @@ namespace AyaNova.DataList
|
|||||||
if (!ThisIsTheFirstFilterItemForThisColumn)
|
if (!ThisIsTheFirstFilterItemForThisColumn)
|
||||||
{
|
{
|
||||||
//Close last filter item and start new one
|
//Close last filter item and start new one
|
||||||
if (IsOrFilter)
|
// if (IsOrFilter)
|
||||||
|
if (f.Any)
|
||||||
sb.Append(") OR (");
|
sb.Append(") OR (");
|
||||||
else
|
else
|
||||||
sb.Append(") AND (");
|
sb.Append(") AND (");
|
||||||
@@ -93,39 +99,47 @@ namespace AyaNova.DataList
|
|||||||
|
|
||||||
|
|
||||||
//gather filter data
|
//gather filter data
|
||||||
var filterItem = (JObject)filterItems[y];
|
//var filterItem = (JObject)filterItems[y];
|
||||||
var opType = filterItem["op"].Value<string>();
|
// var opType = filterItem["op"].Value<string>();
|
||||||
List<string> tagList = new List<string>();
|
|
||||||
string val = string.Empty;
|
//#### Commented out this block as much of it is related to filter by ID as it says it's not used and I think that's true still when switched to new listOptions with split filter / view
|
||||||
bool IsPossibleIdValue = filterItem["value"].Type == JTokenType.Integer;
|
// List<string> tagList = new List<string>();
|
||||||
if (filterItem["value"].Type != JTokenType.Array)
|
// string val = string.Empty;
|
||||||
val = filterItem["value"].Value<string>();
|
// bool IsPossibleIdValue = filterItem["value"].Type == JTokenType.Integer;
|
||||||
else
|
// if (filterItem["value"].Type != JTokenType.Array)
|
||||||
{
|
// val = filterItem["value"].Value<string>();
|
||||||
tagList = filterItem["value"].ToObject<List<String>>();
|
// else
|
||||||
}
|
// {
|
||||||
//prep for possible ID field filter instead
|
// tagList = filterItem["value"].ToObject<List<String>>();
|
||||||
|
// }
|
||||||
|
// //prep for possible ID field filter instead
|
||||||
|
// string columnNameToFilter = string.Empty;
|
||||||
|
// UiFieldDataType DataTypeToFilter = UiFieldDataType.NoType;
|
||||||
|
// //Check if filtering by ID rather than by name
|
||||||
|
// //this is indicated by this column being an id type
|
||||||
|
// //and by the comparison operator being eq or neq
|
||||||
|
// //and the value being a number not a string
|
||||||
|
// //NOTE: This is not actually used anywhere at the client or on server, only defined here in this class
|
||||||
|
// //it was probabaly for supporting filtering by ID but I have found that unnecessary so far
|
||||||
|
// // if (DataListField.HasIdColumn() && IsPossibleIdValue && (opType == DataListFilterComparisonOperator.Equality || opType == DataListFilterComparisonOperator.NotEqual))
|
||||||
|
// if (DataListField.HasIdColumn() && IsPossibleIdValue && (filterItem.op == DataListFilterComparisonOperator.Equality || filterItem.op == DataListFilterComparisonOperator.NotEqual))
|
||||||
|
// {
|
||||||
|
// columnNameToFilter = DataListField.SqlIdColumnName;
|
||||||
|
// DataTypeToFilter = UiFieldDataType.InternalId;
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
// DataTypeToFilter = (UiFieldDataType)dataType;
|
||||||
|
// columnNameToFilter = DataListField.GetSqlValueColumnName();
|
||||||
|
// }
|
||||||
|
|
||||||
|
//replaced above with simplified block here
|
||||||
string columnNameToFilter = string.Empty;
|
string columnNameToFilter = string.Empty;
|
||||||
UiFieldDataType DataTypeToFilter = UiFieldDataType.NoType;
|
UiFieldDataType DataTypeToFilter = UiFieldDataType.NoType;
|
||||||
//Check if filtering by ID rather than by name
|
DataTypeToFilter = (UiFieldDataType)dataType;
|
||||||
//this is indicated by this column being an id type
|
columnNameToFilter = DataListField.GetSqlValueColumnName();
|
||||||
//and by the comparison operator being eq or neq
|
|
||||||
//and the value being a number not a string
|
|
||||||
//NOTE: This is not actually used anywhere at the client or on server, only defined here in this class
|
|
||||||
//it was probabaly for supporting filtering by ID but I have found that unnecessary so far
|
|
||||||
if (DataListField.HasIdColumn() && IsPossibleIdValue && (opType == DataListFilterComparisonOperator.Equality || opType == DataListFilterComparisonOperator.NotEqual))
|
|
||||||
{
|
|
||||||
columnNameToFilter = DataListField.SqlIdColumnName;
|
|
||||||
DataTypeToFilter = UiFieldDataType.InternalId;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
DataTypeToFilter = (UiFieldDataType)dataType;
|
|
||||||
columnNameToFilter = DataListField.GetSqlValueColumnName();
|
|
||||||
}
|
|
||||||
|
|
||||||
//Append this filter's criteria
|
//Append this filter's criteria
|
||||||
sb.Append(DataFilterToColumnCriteria(columnNameToFilter, DataTypeToFilter, opType, val, tagList));
|
sb.Append(DataFilterToColumnCriteria(columnNameToFilter, DataTypeToFilter, filterItem.op, filterItem.value));
|
||||||
|
|
||||||
|
|
||||||
ThisIsTheFirstFilterItemForThisColumn = false;
|
ThisIsTheFirstFilterItemForThisColumn = false;
|
||||||
@@ -160,12 +174,17 @@ namespace AyaNova.DataList
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//sTags is redundant now as the sValue can contain a array of strings and dataType already gives away if it's a tag filter or no
|
||||||
|
// private static string DataFilterToColumnCriteria(string SqlColumnNameToFilter, UiFieldDataType DataType, string sOperator, string sValue, List<string> sTags)//, bool IsCompound)
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Translate DataFilter to Postgres friendly SQL criteria
|
/// Translate DataFilter to Postgres friendly SQL criteria
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private static string DataFilterToColumnCriteria(string SqlColumnNameToFilter, UiFieldDataType DataType, string sOperator, string sValue, List<string> sTags)//, bool IsCompound)
|
private static string DataFilterToColumnCriteria(string SqlColumnNameToFilter, UiFieldDataType DataType, string sOperator, string sValue)
|
||||||
{
|
{
|
||||||
bool TagFilter = sTags.Count < 0;
|
|
||||||
|
// bool TagFilter = sTags.Count < 0; Nope, the datatype already states if it's tags or not no need for redundancy
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
//Column name
|
//Column name
|
||||||
//sb.Append(" ");
|
//sb.Append(" ");
|
||||||
@@ -173,7 +192,7 @@ namespace AyaNova.DataList
|
|||||||
sb.Append(" ");
|
sb.Append(" ");
|
||||||
|
|
||||||
//handle null values separately
|
//handle null values separately
|
||||||
if (!TagFilter && sValue == "*NULL*")
|
if (DataType != UiFieldDataType.Tags && sValue == "*NULL*")
|
||||||
{
|
{
|
||||||
switch (DataType)
|
switch (DataType)
|
||||||
{
|
{
|
||||||
@@ -212,7 +231,7 @@ namespace AyaNova.DataList
|
|||||||
//so....
|
//so....
|
||||||
//Special addition to handle nulls
|
//Special addition to handle nulls
|
||||||
|
|
||||||
if (!TagFilter)
|
if (DataType != UiFieldDataType.Tags)
|
||||||
{
|
{
|
||||||
switch (sOperator)
|
switch (sOperator)
|
||||||
{
|
{
|
||||||
@@ -562,7 +581,9 @@ namespace AyaNova.DataList
|
|||||||
//sounds like it might fuck up when using other languages so...
|
//sounds like it might fuck up when using other languages so...
|
||||||
StringBuilder sbTags = new StringBuilder();
|
StringBuilder sbTags = new StringBuilder();
|
||||||
sbTags.Append("@> array[");
|
sbTags.Append("@> array[");
|
||||||
List<string> normalizedTags = TagBiz.NormalizeTags(sTags);
|
//List<string> normalizedTags = TagBiz.NormalizeTags(sTags);
|
||||||
|
//Note: with listOptions change to split filter and view the tags are now in sValue as a string of comma delimited strings so split them out here
|
||||||
|
List<string> normalizedTags = TagBiz.NormalizeTags(sValue.Split(',').ToList<string>());
|
||||||
foreach (string s in normalizedTags)
|
foreach (string s in normalizedTags)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ namespace AyaNova.DataList
|
|||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
public static string DataFilterToSQLOrderBy(List<AyaDataListFieldDefinition> objectFieldsList, JArray listViewArray)
|
public static string DataFilterToSQLOrderBy(List<AyaDataListFieldDefinition> objectFieldsList, DataListOptions listOptions)
|
||||||
{
|
{
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|||||||
@@ -109,5 +109,6 @@ namespace AyaNova.DataList
|
|||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}//eoc
|
}//eoc
|
||||||
}//eons
|
}//eons
|
||||||
@@ -269,5 +269,7 @@ namespace AyaNova.DataList
|
|||||||
FieldDefinitions.Add(new AyaDataListFieldDefinition { TKey = "HeadOfficeCustom15", FieldKey = "headofficecustom15", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "aheadoffice.customfields" });
|
FieldDefinitions.Add(new AyaDataListFieldDefinition { TKey = "HeadOfficeCustom15", FieldKey = "headofficecustom15", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "aheadoffice.customfields" });
|
||||||
FieldDefinitions.Add(new AyaDataListFieldDefinition { TKey = "HeadOfficeCustom16", FieldKey = "headofficecustom16", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "aheadoffice.customfields" });
|
FieldDefinitions.Add(new AyaDataListFieldDefinition { TKey = "HeadOfficeCustom16", FieldKey = "headofficecustom16", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "aheadoffice.customfields" });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}//eoc
|
}//eoc
|
||||||
}//eons
|
}//eons
|
||||||
@@ -18,13 +18,18 @@ namespace AyaNova.DataList
|
|||||||
//Default object type to open for rows of this list (use no object if no)
|
//Default object type to open for rows of this list (use no object if no)
|
||||||
AyaType DefaultListObjectType { get; set; }
|
AyaType DefaultListObjectType { get; set; }
|
||||||
|
|
||||||
//Default / STOCK DataListView when none is specified
|
//Defaults when none is specified (see DataListOptions for formats and notes)
|
||||||
string DefaultListView { get; set; }
|
List<string> DefaultColumns { get; set; }
|
||||||
|
List<string> DefaultSortBy { get; set; }
|
||||||
|
|
||||||
|
void SetListOptionDefaultsIfNecessary(DataListOptions listOptions);
|
||||||
|
|
||||||
Newtonsoft.Json.Linq.JArray GenerateListColumnsJSONFromListView(JArray listViewArray);
|
Newtonsoft.Json.Linq.JArray GenerateListColumnsJSONFromListView(JArray listViewArray);
|
||||||
List<string> GetFieldListFromListView(JArray listViewArray);
|
List<string> GetFieldListFromListView(JArray listViewArray);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,11 @@
|
|||||||
namespace AyaNova.DataList
|
namespace AyaNova.DataList
|
||||||
{
|
{
|
||||||
internal interface IAyaDataListViewServerCriteria
|
internal interface IAyaDataListServerCriteria
|
||||||
{
|
{
|
||||||
//Additional criteria for security or other reasons
|
//Additional criteria for security or other reasons
|
||||||
//hard coded into some lists (e.g. MemoDataList so users can't get other people's memos)
|
//hard coded into some lists (e.g. MemoDataList so users can't get other people's memos)
|
||||||
string ListViewServerCriteria(AyaNova.Models.User user, AyaNova.Models.AyContext ct);
|
//User is just to look up for roles and stuff
|
||||||
|
//clientCriteria is additional criteria provided by client to list to process as it sees fit (e.g. CustomerNoteDataList requires customer id from client)
|
||||||
|
System.Collections.Generic.List<DataListFilterOption> DataListServerCriteria(long currentUserId, AyaNova.Biz.AuthorizationRoles userRoles, DataListOptions dataListOptions);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -124,5 +124,6 @@ namespace AyaNova.DataList
|
|||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}//eoc
|
}//eoc
|
||||||
}//eons
|
}//eons
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
|
|
||||||
namespace AyaNova.DataList
|
|
||||||
{
|
|
||||||
|
|
||||||
public sealed class DataListOptions
|
|
||||||
{
|
|
||||||
public const int MaxPageSize = 1000;
|
|
||||||
public const int DefaultOffset = 0;
|
|
||||||
public const int DefaultLimit = 25;
|
|
||||||
|
|
||||||
[FromBody]
|
|
||||||
public int? Offset { get; set; }
|
|
||||||
|
|
||||||
[FromBody]
|
|
||||||
public int? Limit { get; set; }
|
|
||||||
|
|
||||||
[FromBody, Required]
|
|
||||||
public string DataListKey { get; set; }
|
|
||||||
|
|
||||||
/*
|
|
||||||
columns:["PartInventoryTransactionEntryDate","PartPartNumber","PartWarehouseName","PartInventoryTransactionQuantity","PartInventoryTransactionDescription","PartInventoryTransactionSource","PartInventoryBalance"]
|
|
||||||
sortBy:["PartInventoryTransactionEntryDate"],//same as grid natively does all columns here
|
|
||||||
sortDesc:[true],//same as grid natively does, all columns here true or false each
|
|
||||||
filter:[{column:"PartPartNumber",items:[{op: "=",value: "400735"}]}],
|
|
||||||
variant:"string"
|
|
||||||
*/
|
|
||||||
[FromBody]
|
|
||||||
public string ListView { get; set; }//optional, if null or empty will use default list view built into DataList
|
|
||||||
|
|
||||||
[FromBody]
|
|
||||||
public string MetaView { get; set; }//optional meta list view to integrate into the standard list view. Used by client to add "meta" filter conditions above the user's choices e.g. customer notes customer id
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -181,5 +181,7 @@ namespace AyaNova.DataList
|
|||||||
FieldDefinitions.Add(new AyaDataListFieldDefinition { TKey = "LoanUnitCustom15", FieldKey = "loanunitcustom15", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "aloanunit.customfields" });
|
FieldDefinitions.Add(new AyaDataListFieldDefinition { TKey = "LoanUnitCustom15", FieldKey = "loanunitcustom15", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "aloanunit.customfields" });
|
||||||
FieldDefinitions.Add(new AyaDataListFieldDefinition { TKey = "LoanUnitCustom16", FieldKey = "loanunitcustom16", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "aloanunit.customfields" });
|
FieldDefinitions.Add(new AyaDataListFieldDefinition { TKey = "LoanUnitCustom16", FieldKey = "loanunitcustom16", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "aloanunit.customfields" });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}//eoc
|
}//eoc
|
||||||
}//eons
|
}//eons
|
||||||
@@ -4,7 +4,7 @@ using AyaNova.Models;
|
|||||||
using AyaNova.Biz;
|
using AyaNova.Biz;
|
||||||
namespace AyaNova.DataList
|
namespace AyaNova.DataList
|
||||||
{
|
{
|
||||||
internal class MemoDataList : AyaDataList, IAyaDataListViewServerCriteria
|
internal class MemoDataList : AyaDataList, IAyaDataListServerCriteria
|
||||||
{
|
{
|
||||||
public MemoDataList()
|
public MemoDataList()
|
||||||
{
|
{
|
||||||
@@ -135,12 +135,9 @@ namespace AyaNova.DataList
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
string IAyaDataListServerCriteria.DataListServerCriteria(AyaNova.Models.AyContext ct, long currentUserId, DataListOptions dataListOptions)
|
||||||
|
|
||||||
|
|
||||||
string IAyaDataListViewServerCriteria.ListViewServerCriteria(User user, AyaNova.Models.AyContext ct)
|
|
||||||
{
|
{
|
||||||
return "[{\"fld\":\"metamemoto\",\"filter\":{\"items\":[{\"op\":\"=\",\"value\":" + user.Id.ToString() + "}]}}]";
|
return "[{\"fld\":\"metamemoto\",\"filter\":{\"items\":[{\"op\":\"=\",\"value\":" + currentUserId.ToString() + "}]}}]";
|
||||||
}
|
}
|
||||||
|
|
||||||
}//eoc
|
}//eoc
|
||||||
|
|||||||
@@ -129,5 +129,6 @@ namespace AyaNova.DataList
|
|||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}//eoc
|
}//eoc
|
||||||
}//eons
|
}//eons
|
||||||
@@ -4,7 +4,7 @@ using AyaNova.Models;
|
|||||||
using AyaNova.Biz;
|
using AyaNova.Biz;
|
||||||
namespace AyaNova.DataList
|
namespace AyaNova.DataList
|
||||||
{
|
{
|
||||||
internal class ReminderDataList : AyaDataList, IAyaDataListViewServerCriteria
|
internal class ReminderDataList : AyaDataList, IAyaDataListServerCriteria
|
||||||
{
|
{
|
||||||
public ReminderDataList()
|
public ReminderDataList()
|
||||||
{
|
{
|
||||||
@@ -114,9 +114,9 @@ namespace AyaNova.DataList
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Ensure only current user can fetch their reminders
|
//Ensure only current user can fetch their reminders
|
||||||
string IAyaDataListViewServerCriteria.ListViewServerCriteria(User user, AyContext ct)
|
string IAyaDataListServerCriteria.DataListServerCriteria(AyaNova.Models.AyContext ct, long currentUserId, DataListOptions dataListOptions)
|
||||||
{
|
{
|
||||||
return "[{\"fld\":\"metareminderuser\",\"filter\":{\"items\":[{\"op\":\"=\",\"value\":" + user.Id.ToString() + "}]}}]";
|
return "[{\"fld\":\"metareminderuser\",\"filter\":{\"items\":[{\"op\":\"=\",\"value\":" + currentUserId.ToString() + "}]}}]";
|
||||||
}
|
}
|
||||||
|
|
||||||
}//eoc
|
}//eoc
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using AyaNova.Models;
|
using AyaNova.Models;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using System.Linq;
|
||||||
using AyaNova.Biz;
|
using AyaNova.Biz;
|
||||||
namespace AyaNova.DataList
|
namespace AyaNova.DataList
|
||||||
{
|
{
|
||||||
internal class ReviewDataList : AyaDataList, IAyaDataListViewServerCriteria
|
internal class ReviewDataList : AyaDataList, IAyaDataListServerCriteria
|
||||||
{
|
{
|
||||||
public ReviewDataList()
|
public ReviewDataList()
|
||||||
{
|
{
|
||||||
@@ -187,17 +189,17 @@ namespace AyaNova.DataList
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
string IAyaDataListViewServerCriteria.ListViewServerCriteria(User user, AyaNova.Models.AyContext ct)
|
string IAyaDataListServerCriteria.DataListServerCriteria(long currentUserId, AyaNova.Biz.AuthorizationRoles userRoles, DataListOptions dataListOptions)
|
||||||
{
|
{
|
||||||
var CurrentUserRoles = user.Roles;
|
|
||||||
bool HasSupervisorRole =
|
bool HasSupervisorRole =
|
||||||
CurrentUserRoles.HasFlag(AuthorizationRoles.BizAdminFull) ||
|
userRoles.HasFlag(AuthorizationRoles.BizAdminFull) ||
|
||||||
CurrentUserRoles.HasFlag(AuthorizationRoles.DispatchFull) ||
|
userRoles.HasFlag(AuthorizationRoles.DispatchFull) ||
|
||||||
CurrentUserRoles.HasFlag(AuthorizationRoles.InventoryFull) ||
|
userRoles.HasFlag(AuthorizationRoles.InventoryFull) ||
|
||||||
CurrentUserRoles.HasFlag(AuthorizationRoles.SalesFull) ||
|
userRoles.HasFlag(AuthorizationRoles.SalesFull) ||
|
||||||
CurrentUserRoles.HasFlag(AuthorizationRoles.AccountingFull);
|
userRoles.HasFlag(AuthorizationRoles.AccountingFull);
|
||||||
if (!HasSupervisorRole)
|
if (!HasSupervisorRole)
|
||||||
return "[{\"fld\":\"metareviewuser\",\"filter\":{\"items\":[{\"op\":\"=\",\"value\":" + user.Id.ToString() + "}]}}]";
|
return "[{\"fld\":\"metareviewuser\",\"filter\":{\"items\":[{\"op\":\"=\",\"value\":" + currentUserId.ToString() + "}]}}]";
|
||||||
return "[]";//this means effectively don't process this at all
|
return "[]";//this means effectively don't process this at all
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -45,6 +45,8 @@ namespace AyaNova.DataList
|
|||||||
|
|
||||||
DefaultListView = dlistView.ToString(Newtonsoft.Json.Formatting.None);
|
DefaultListView = dlistView.ToString(Newtonsoft.Json.Formatting.None);
|
||||||
|
|
||||||
|
DefaultColumns=""
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// DefaultDataListView = @"
|
// DefaultDataListView = @"
|
||||||
|
|||||||
Reference in New Issue
Block a user