diff --git a/server/AyaNova/DataList/AyaDataList.cs b/server/AyaNova/DataList/AyaDataList.cs index d82b59f6..c32c81ba 100644 --- a/server/AyaNova/DataList/AyaDataList.cs +++ b/server/AyaNova/DataList/AyaDataList.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using AyaNova.Models; using AyaNova.Biz; using Newtonsoft.Json.Linq; using Microsoft.EntityFrameworkCore; @@ -33,10 +34,13 @@ namespace AyaNova.DataList public Dictionary DefaultSortBy { get; set; } //set defaults if not provided in listOptions - public void SetListOptionDefaultsIfNecessary(DataListOptions listOptions) + public void SetListOptionDefaultsIfNecessary(DataListBase listOptions) { - if (listOptions.Columns.Count == 0) - listOptions.Columns = DefaultColumns; + if(listOptions is DataListTableOptions){//if this doesn't work then just ditch this method in favor of local code, it's not really saving much + if (((DataListTableOptions)listOptions).Columns.Count == 0) + ((DataListTableOptions)listOptions).Columns = DefaultColumns; + } + if (listOptions.SortBy.Count == 0) listOptions.SortBy = DefaultSortBy; } diff --git a/server/AyaNova/DataList/DataListFetcher.cs b/server/AyaNova/DataList/DataListFetcher.cs index 538c1861..88f28c4f 100644 --- a/server/AyaNova/DataList/DataListFetcher.cs +++ b/server/AyaNova/DataList/DataListFetcher.cs @@ -18,27 +18,27 @@ namespace AyaNova.DataList // Get the data list data requested // // - internal static async Task GetResponseAsync(AyContext ct, DataListOptions listOptions, AuthorizationRoles userRoles, ILogger log, long userId) + internal static async Task GetResponseAsync(AyContext ct, DataListTableOptions dataListTableOptions, AuthorizationRoles userRoles, ILogger log, long userId) { - var DataList = DataListFactory.GetAyaDataList(listOptions.DataListKey); + var DataList = DataListFactory.GetAyaDataList(dataListTableOptions.DataListKey); //was the name not found as a list? if (DataList == null) - throw new System.ArgumentOutOfRangeException($"DataList \"{listOptions.DataListKey}\" specified does not exist"); + throw new System.ArgumentOutOfRangeException($"DataList \"{dataListTableOptions.DataListKey}\" specified does not exist"); //check rights if (!userRoles.HasAnyFlags(DataList.AllowedRoles)) throw new System.UnauthorizedAccessException("User roles insufficient for this datalist"); - DataList.SetListOptionDefaultsIfNecessary(listOptions); + DataList.SetListOptionDefaultsIfNecessary(dataListTableOptions); //STATIC filter options from server List StaticServerFilterOptions = null; if (DataList is IAyaDataListServerCriteria) - StaticServerFilterOptions = ((IAyaDataListServerCriteria)DataList).DataListServerCriteria(userId, userRoles, listOptions); + StaticServerFilterOptions = ((IAyaDataListServerCriteria)DataList).DataListServerCriteria(userId, userRoles, dataListTableOptions); // //Get the public field key names in a list from the listview @@ -46,12 +46,12 @@ namespace AyaNova.DataList //Get the combination of all unique fields from both StaticServerFilterOptions and listOptions //NOTE: this assumes no list options filter colums that don't exist in listoptions.columns - var AllUniqueFieldKeysRequiredForQuery = listOptions.Columns.Union(StaticServerFilterOptions.Select(z => z.Column).ToList()).ToList(); + var AllUniqueFieldKeysRequiredForQuery = dataListTableOptions.Columns.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); + dataListTableOptions.Filter.Add(dfo); //BUILD THE QUERY @@ -65,16 +65,16 @@ namespace AyaNova.DataList var qOrderBy = string.Empty; //WHERE CLAUSE - FILTER - qWhere = DataListSqlFilterCriteriaBuilder.DataFilterToSQLCriteria(DataList.FieldDefinitions, listOptions); + qWhere = DataListSqlFilterCriteriaBuilder.DataFilterToSQLCriteria(DataList.FieldDefinitions, dataListTableOptions); //ORDER BY CLAUSE - SORT //BUILD ORDER BY - qOrderBy = DataListSqlFilterOrderByBuilder.DataFilterToSQLOrderBy(DataList.FieldDefinitions, listOptions); + qOrderBy = DataListSqlFilterOrderByBuilder.DataFilterToSQLOrderBy(DataList.FieldDefinitions, dataListTableOptions); //LIMIT AND OFFSET CLAUSE - PAGING - listOptions.Offset = listOptions.Offset ?? DataListOptions.DefaultOffset; - listOptions.Limit = listOptions.Limit ?? DataListOptions.DefaultLimit; - var qLimitOffset = $"LIMIT {listOptions.Limit} OFFSET {listOptions.Offset}"; + dataListTableOptions.Offset = dataListTableOptions.Offset ?? DataListTableOptions.DefaultOffset; + dataListTableOptions.Limit = dataListTableOptions.Limit ?? DataListTableOptions.DefaultLimit; + var qLimitOffset = $"LIMIT {dataListTableOptions.Limit} OFFSET {dataListTableOptions.Offset}"; //PUT IT ALL TOGETHER string qDataQuery = string.Empty; @@ -84,7 +84,7 @@ namespace AyaNova.DataList qTotalRecordsQuery = $"SELECT COUNT(*) {qFrom} {qWhere}".Replace(" ", " "); //RETURN OBJECTS - int returnRowColumnCount = listOptions.Columns.Count(); + int returnRowColumnCount = dataListTableOptions.Columns.Count(); List> rows = new List>(); long totalRecordCount = 0; @@ -105,7 +105,7 @@ namespace AyaNova.DataList //INSERT REMAINING FIELDS FROM TEMPLATE INTO THE RETURN ROWS LIST - foreach (string TemplateField in listOptions.Columns) + foreach (string TemplateField in dataListTableOptions.Columns) { //get the AyaObjectFieldDefinition @@ -230,7 +230,7 @@ namespace AyaNova.DataList //BUILD THE COLUMNS RETURN PROPERTY JSON FRAGMENT Newtonsoft.Json.Linq.JArray ColumnsJSON = null; - ColumnsJSON = DataList.GenerateReturnListColumns(listOptions.Columns);//<<<-----this next + ColumnsJSON = DataList.GenerateReturnListColumns(dataListTableOptions.Columns);//<<<-----this next return new ApiDataListResponse(rows, totalRecordCount, ColumnsJSON); diff --git a/server/AyaNova/DataList/DataListOptions.cs b/server/AyaNova/DataList/DataListOptions.cs index 0c18a2dc..b63707f3 100644 --- a/server/AyaNova/DataList/DataListOptions.cs +++ b/server/AyaNova/DataList/DataListOptions.cs @@ -1,86 +1,89 @@ -using System.ComponentModel.DataAnnotations; -using Microsoft.AspNetCore.Mvc; -using System.Collections.Generic; -using -namespace AyaNova.DataList -{ +//MOVED TO MODELS AS DataListTableOptions AND BROKEN APART - public sealed class DataListOptions : DataListBase - { - public const int MaxPageSize = 1000; - public const int DefaultOffset = 0; - public const int DefaultLimit = 25; +// using System.ComponentModel.DataAnnotations; +// using Microsoft.AspNetCore.Mvc; +// using System.Collections.Generic; +// using - [FromBody] - public int? Offset { get; set; } +// namespace AyaNova.DataList +// { - [FromBody] - public int? Limit { get; set; } +// public sealed class DataListOptions : DataListBase +// { +// public const int MaxPageSize = 1000; +// public const int DefaultOffset = 0; +// public const int DefaultLimit = 25; - [FromBody, Required] - public string DataListKey { get; set; } +// [FromBody] +// public int? Offset { get; set; } - [FromBody] - public DataListView View { get; set; } +// [FromBody] +// public int? Limit { get; set; } + +// [FromBody, Required] +// public string DataListKey { get; set; } + +// [FromBody] +// public DataListView View { get; set; } - // [FromBody] - // public List Columns { get; set; } - // [FromBody] - // public Dictionary SortBy { get; set; } - // [FromBody] - // public List Filter { get; set; } - // [FromBody] - // public string ClientCriteria { get; set; } - } +// // [FromBody] +// // public List Columns { get; set; } +// // [FromBody] +// // public Dictionary SortBy { get; set; } +// // [FromBody] +// // public List Filter { get; set; } +// // [FromBody] +// // public string ClientCriteria { get; set; } +// } - public class DataListView - { - /* - 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\":\"+\"}]"} +// public class DataListView +// { +// /* +// 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 and are IN ORDER of how to be sorted - 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 Columns { get; set; } - [FromBody] - public Dictionary SortBy { get; set; } - [FromBody] - public List Filter { get; set; } - [FromBody] - public string ClientCriteria { get; set; } - } +// 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 and are IN ORDER of how to be sorted +// 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 Columns { get; set; } +// [FromBody] +// public Dictionary SortBy { get; set; } +// [FromBody] +// public List Filter { get; set; } +// [FromBody] +// public string ClientCriteria { get; set; } +// } - public class DataListFilterOption - { - public string Column { get; set; } - public List items { get; set; } - public bool Any { get; set; }//means "or" the filter conditions - DataListFilterOption() - { - items = new List(); - } - } +// public class DataListFilterOption +// { +// public string Column { get; set; } +// public List items { get; set; } +// public bool Any { get; set; }//means "or" the filter conditions +// DataListFilterOption() +// { +// items = new List(); +// } +// } - public class DataListColumnFilter - { - public string op { get; set; } - public string value { get; set; } - } +// public class DataListColumnFilter +// { +// public string op { get; set; } +// public string value { get; set; } +// } -} \ No newline at end of file +// } \ No newline at end of file diff --git a/server/AyaNova/DataList/DataListSqlFilterCriteriaBuilder.cs b/server/AyaNova/DataList/DataListSqlFilterCriteriaBuilder.cs index 68fc7047..5861a14c 100644 --- a/server/AyaNova/DataList/DataListSqlFilterCriteriaBuilder.cs +++ b/server/AyaNova/DataList/DataListSqlFilterCriteriaBuilder.cs @@ -4,13 +4,14 @@ using System.Globalization; using System.Text; using Newtonsoft.Json.Linq; using System.Linq; +using AyaNova.Models; using AyaNova.Biz; namespace AyaNova.DataList { public static class DataListSqlFilterCriteriaBuilder { - public static string DataFilterToSQLCriteria(List objectFieldsList, DataListOptions listOptions) + public static string DataFilterToSQLCriteria(List objectFieldsList, DataListTableOptions listOptions) { if (listOptions.Filter == null || listOptions.Filter.Count == 0) diff --git a/server/AyaNova/DataList/DataListSqlFilterOrderByBuilder.cs b/server/AyaNova/DataList/DataListSqlFilterOrderByBuilder.cs index e62307e8..7f8f9f30 100644 --- a/server/AyaNova/DataList/DataListSqlFilterOrderByBuilder.cs +++ b/server/AyaNova/DataList/DataListSqlFilterOrderByBuilder.cs @@ -2,6 +2,7 @@ using System.Text; using System.Linq; using Newtonsoft.Json.Linq; using System.Collections.Generic; +using AyaNova.Models; namespace AyaNova.DataList { @@ -9,7 +10,7 @@ namespace AyaNova.DataList { - public static string DataFilterToSQLOrderBy(List objectFieldsList, DataListOptions listOptions) + public static string DataFilterToSQLOrderBy(List objectFieldsList, DataListTableOptions listOptions) { StringBuilder sb = new StringBuilder(); diff --git a/server/AyaNova/DataList/IAyaDataList.cs b/server/AyaNova/DataList/IAyaDataList.cs index bd333650..9b4327b4 100644 --- a/server/AyaNova/DataList/IAyaDataList.cs +++ b/server/AyaNova/DataList/IAyaDataList.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using Newtonsoft.Json.Linq; using AyaNova.Biz; +using AyaNova.Models; namespace AyaNova.DataList { internal interface IAyaDataList @@ -22,7 +23,7 @@ namespace AyaNova.DataList List DefaultColumns { get; set; } Dictionary DefaultSortBy { get; set; } - void SetListOptionDefaultsIfNecessary(DataListOptions listOptions); + void SetListOptionDefaultsIfNecessary(DataListBase listOptions); Newtonsoft.Json.Linq.JArray GenerateReturnListColumns(List columns); // List GetFieldListFromListView(JArray listViewArray); diff --git a/server/AyaNova/DataList/IAyaDataListExtraCriteria.cs b/server/AyaNova/DataList/IAyaDataListExtraCriteria.cs index d91c4d0a..2801f044 100644 --- a/server/AyaNova/DataList/IAyaDataListExtraCriteria.cs +++ b/server/AyaNova/DataList/IAyaDataListExtraCriteria.cs @@ -1,11 +1,11 @@ +using AyaNova.Models; namespace AyaNova.DataList { internal interface IAyaDataListServerCriteria { //Additional criteria for security or other reasons //hard coded into some lists (e.g. MemoDataList so users can't get other people's memos) - //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 DataListServerCriteria(long currentUserId, AyaNova.Biz.AuthorizationRoles userRoles, DataListOptions dataListOptions); + System.Collections.Generic.List DataListServerCriteria(long currentUserId, AyaNova.Biz.AuthorizationRoles userRoles, DataListBase dataListBase); } } \ No newline at end of file diff --git a/server/AyaNova/DataList/MemoDataList.cs b/server/AyaNova/DataList/MemoDataList.cs index 0eff8630..3cf02374 100644 --- a/server/AyaNova/DataList/MemoDataList.cs +++ b/server/AyaNova/DataList/MemoDataList.cs @@ -135,9 +135,10 @@ namespace AyaNova.DataList - string IAyaDataListServerCriteria.DataListServerCriteria(AyaNova.Models.AyContext ct, long currentUserId, DataListOptions dataListOptions) + DataListFilterOption DataListServerCriteria(long currentUserId, AyaNova.Biz.AuthorizationRoles userRoles, DataListBase dataListBase) { - return "[{\"fld\":\"metamemoto\",\"filter\":{\"items\":[{\"op\":\"=\",\"value\":" + currentUserId.ToString() + "}]}}]"; + //return "[{\"fld\":\"metamemoto\",\"filter\":{\"items\":[{\"op\":\"=\",\"value\":" + currentUserId.ToString() + "}]}}]"; + return null; } }//eoc diff --git a/server/AyaNova/biz/ReportBiz.cs b/server/AyaNova/biz/ReportBiz.cs index e1f57800..c2f0c61f 100644 --- a/server/AyaNova/biz/ReportBiz.cs +++ b/server/AyaNova/biz/ReportBiz.cs @@ -555,7 +555,9 @@ namespace AyaNova.Biz } //Report meta data - var reportMeta = $"{{Id:{report.Id},Name:`{report.Name}`,Notes:`{report.Notes}`,ObjectType:`{report.ObjectType}`,CustomFieldsDefinition:{CustomFieldsTemplate},DataListKey:`{reportParam.DataListKey}`,ListView:`{reportParam.ListView}`,SelectedRowIds: `{string.Join(",", reportParam.SelectedRowIds)}`}}"; + // var reportMeta = $"{{Id:{report.Id},Name:`{report.Name}`,Notes:`{report.Notes}`,ObjectType:`{report.ObjectType}`,CustomFieldsDefinition:{CustomFieldsTemplate},DataListKey:`{reportParam.DataListKey}`,ListView:`{reportParam.ListView}`,SelectedRowIds: `{string.Join(",", reportParam.SelectedRowIds)}`}}"; + //removed listview as it no longer exists and I don't think there's any useful purpose to it in the report javascript at this time + var reportMeta = $"{{Id:{report.Id},Name:`{report.Name}`,Notes:`{report.Notes}`,ObjectType:`{report.ObjectType}`,CustomFieldsDefinition:{CustomFieldsTemplate},DataListKey:`{reportParam.DataListKey}`,SelectedRowIds: `{string.Join(",", reportParam.SelectedRowIds)}`}}"; //duplicate meta data in report page wide variable for use by our internal functions