This commit is contained in:
2021-09-02 19:26:01 +00:00
parent 7767c7d67c
commit 7eaa9e5907

View File

@@ -948,10 +948,37 @@ namespace AyaNova.DataList
This method and choices ensures users don't need to make a separate row for each one they can just treat the entire tag collection like they treat a single word match in a text field This method and choices ensures users don't need to make a separate row for each one they can just treat the entire tag collection like they treat a single word match in a text field
*/ */
//HAS VALUE / NO VALUE
if (sValue == "*NULL*")
{
if (sOperator == DataListFilterComparisonOperator.Equality)
return $"{SqlColumnNameToFilter} = '{{}}'";
else
return $"{SqlColumnNameToFilter} <> '{{}}'";
}
else
{
string PostgresTagArrayFragment = string.Empty;
//Filter ui builder allows multiple tag selection just like any other tag selection and sends the filter to the server like this:
//filter "[{\"column\":\"customertags\",\"any\":false,\"items\":[{\"op\":\"=\",\"value\":\"completed.reminder,burnaby.dispatchzone,cabling-fibre.user-skill\"}]}]"
//needs to be "ARRAY['red','green'::varchar(255)]"
StringBuilder sbTemp = new StringBuilder();
sbTemp = sbTemp.Append("ARRAY[");
List<string> normalizedTags = TagBiz.NormalizeTags(sValue.Split(',').ToList<string>());
if (normalizedTags.Count == 0)
throw new System.ArgumentNullException("DataListSqlFilterCriteriaBuilder::TagDataFilterToColumnCriteria - NO tags were provided for filtering");
foreach (string s in normalizedTags)
sbTemp.Append($"'{s}',");
PostgresTagArrayFragment = sbTemp.ToString().TrimEnd(',');
PostgresTagArrayFragment += "::VARCHAR(255)]";
switch (sOperator) switch (sOperator)
{ {
case DataListFilterComparisonOperator.Equality: case DataListFilterComparisonOperator.Equality:
{ {
//WHERE ARRAY['green'::varchar(255)] <@ tags and array_length(tags,1) = 1
StringBuilder sbTags = new StringBuilder(); StringBuilder sbTags = new StringBuilder();
sbTags.Append("@> array["); sbTags.Append("@> array[");
//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 //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
@@ -990,21 +1017,10 @@ namespace AyaNova.DataList
} }
//NOTE: tag filter OPERATOR is ignored, query matches if all tags are found in a tag collection that could have other tags as well
//for initial release a tag filter is inclusive of all tags only
//in other words all tags presented must be in record to match (simple AND)
//select * from awidget where awidget.tags @> array['blah','blah3'::varchar(255)]
//NOTE: After coding this discovered *can* do a LIKE query with tags like this:
//(array_to_string(awidget.tags,',') like '%zo%')
//implemented that way in picklistquery builder
//also ilike is a postgres case insensitive like but works on current locale of server which
//sounds like it might fuck up when using other languages so...
}
return sb.ToString(); return sb.ToString();