diff --git a/server/AyaNova/DataList/DataListFetcher.cs b/server/AyaNova/DataList/DataListFetcher.cs index e34c04c3..d5d34454 100644 --- a/server/AyaNova/DataList/DataListFetcher.cs +++ b/server/AyaNova/DataList/DataListFetcher.cs @@ -55,7 +55,7 @@ namespace AyaNova.DataList //BUILD THE QUERY //SELECT CLAUSE - var qSelect = DataListSqlSelectBuilder.Build(DataList.FieldDefinitions, AllUniqueFieldKeysRequiredForQuery); + var qSelect = DataListSqlSelectBuilder.BuildForDataTableListResponse(DataList.FieldDefinitions, AllUniqueFieldKeysRequiredForQuery); //FROM CLAUSE var qFrom = DataList.SQLFrom; @@ -277,6 +277,10 @@ namespace AyaNova.DataList if (DataList is IDataListInternalCriteria) StaticServerFilterOptions = ((IDataListInternalCriteria)DataList).DataListInternalCriteria(userId, userRoles, dataListSelectionOptions); + //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) + dataListSelectionOptions.Filter.Add(dfo); // //Hard coded extra criteria from Client end // //parse and combine any additional listview hard coded from Client UI @@ -289,7 +293,7 @@ namespace AyaNova.DataList //BUILD THE QUERY //SELECT FRAGMENT COLUMNS FROM TEMPLATE - var SelectBuild = DataListSqlSelectBuilder.BuildForReportIdListOnly(DataList.FieldDefinitions); + var qSelect = DataListSqlSelectBuilder.BuildForIdListResponse(DataList.FieldDefinitions, dataListSelectionOptions); //FROM CLAUSE var qFrom = DataList.SQLFrom; @@ -306,7 +310,7 @@ namespace AyaNova.DataList //PUT IT ALL TOGETHER string qDataQuery = string.Empty; - qDataQuery = $"{SelectBuild.Select} {qFrom} {qWhere} {qOrderBy} ".Replace(" ", " "); + qDataQuery = $"{qSelect} {qFrom} {qWhere} {qOrderBy} ".Replace(" ", " "); //RETURN OBJECTS var retList = new List(); diff --git a/server/AyaNova/DataList/DataListSqlSelectBuilder.cs b/server/AyaNova/DataList/DataListSqlSelectBuilder.cs index 0bca16d5..57539ec4 100644 --- a/server/AyaNova/DataList/DataListSqlSelectBuilder.cs +++ b/server/AyaNova/DataList/DataListSqlSelectBuilder.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Text; using System.Linq; +using AyaNova.Models; namespace AyaNova.DataList { @@ -13,7 +14,7 @@ namespace AyaNova.DataList { //Build the SELECT portion of a list query based on the columns - internal static SqlSelectBuilderResult Build(List objectFieldsList, List columns) + internal static SqlSelectBuilderResult BuildForDataTableListResponse(List objectFieldsList, List columns) { StringBuilder sb = new StringBuilder(); sb.Append("SELECT "); @@ -33,7 +34,7 @@ namespace AyaNova.DataList //Developers little helper if (o == null) { - throw new System.ArgumentNullException($"## DEV ERROR in DataListSqlSelectBuilder.cs:Build() field {ColumnName} specified in columns was NOT found in the data list's ObjectFields list, a defined fieldkey name differs from the columns key name"); + throw new System.ArgumentNullException($"## DEV ERROR in DataListSqlSelectBuilder.cs:BuildForDataTableListResponse() field {ColumnName} specified in columns was NOT found in the data list's ObjectFields list, a defined fieldkey name differs from the columns key name"); } #endif if (o != null) @@ -112,29 +113,67 @@ namespace AyaNova.DataList //Build the SELECT portion of a list query but only to return rowid's - internal static SqlSelectBuilderResult BuildForReportIdListOnly(List objectFieldsList) + + internal static string BuildForIdListResponse(List fieldDefinitions, DataListSelectionOptions dataListSelectionOptions) { + //BugBug - is not including internalcriteria OR user filtered columns so they don't filter properly + //needs to be there and also return correct 0th column for id filtering or make sure it's always the zeroth I guess + StringBuilder sb = new StringBuilder(); sb.Append("SELECT "); //map sql column name to ordinal name - Dictionary map = new Dictionary(); + // Dictionary map = new Dictionary(); - //find the rowid in the objectfields list and insert it - var o = objectFieldsList.FirstOrDefault(z => z.IsRowId == true); - if (o != null) - { - var idColumnName = o.SqlIdColumnName; - if (!string.IsNullOrWhiteSpace(idColumnName)) - { - sb.Append(idColumnName); - map.Add(idColumnName, 0); + //FIRST: find the rowid in the objectfields list and insert it + //this is now the zeroth column + //Note: IsRowId field should *always* exist for any list that is intended to be used in an idlist response + var o = fieldDefinitions.FirstOrDefault(z => z.IsRowId == true); + sb.Append(o.SqlIdColumnName); + // map.Add(o.SqlIdColumnName, 0); + + //Now add any rows found in filter + foreach(var filter in dataListSelectionOptions.Filter){ + //add all columns being filtered but not rowId + var fld=fieldDefinitions.FirstOrDefault(z=>z.FieldKey==filter.Column); + if(!fld.IsRowId){ + sb.Append($",{fld.SqlIdColumnName}"); + //map.Add(fld.SqlIdColumnName); } + } - return new SqlSelectBuilderResult() { map = map, Select = sb.ToString() }; + + + return sb.ToString(); }//eom + // internal static SqlSelectBuilderResult BuildForReportIdListOnly(List objectFieldsList) + // { + // //BugBug - is not including internalcriteria columns so they don't filter properly + // //needs to be there and also return correct 0th column for id filtering or make sure it's always the zeroth I guess + + // StringBuilder sb = new StringBuilder(); + // sb.Append("SELECT "); + // //map sql column name to ordinal name + // Dictionary map = new Dictionary(); + + // //find the rowid in the objectfields list and insert it + // var o = objectFieldsList.FirstOrDefault(z => z.IsRowId == true); + // if (o != null) + // { + // var idColumnName = o.SqlIdColumnName; + // if (!string.IsNullOrWhiteSpace(idColumnName)) + // { + // sb.Append(idColumnName); + // map.Add(idColumnName, 0); + // } + // } + + // return new SqlSelectBuilderResult() { map = map, Select = sb.ToString() }; + // }//eom + + // //Build the SELECT portion of a list query but only to return rowid's // internal static SqlSelectBuilderResult BuildForReportIdListOnly(List objectFieldsList, List listViewFieldList) // {