Skip to content

Commit

Permalink
10529 adv search list operators (#10610)
Browse files Browse the repository at this point in the history
* creates helper method for concept datatype append_search_filter for lists, re #10529

* calls helper method for concept datatype for cases any, all, and not in list, re #10529

* commits translations for in_list adv search ops, re #10529

* adds translation in_list options to select2config in concept datatype view, re #10529

* creates alternate select2 that can be multi for in_list ops in concept adv search re #10529

* creates alternate select2 to handle multi select for in_list ops re #10529

* Revert "creates alternate select2 to handle multi select for in_list ops re #10529"

This reverts commit 5a067f5.

reverts commit

* Revert "creates alternate select2 that can be multi for in_list ops in concept adv search re #10529"

This reverts commit 8b826aa.

reverts commit

* swaps array type checking to before check for self.multi in concept-select re #10529

* on select2-config init, falls back on array type check of valueList if self.multi was init false before param.val was inherited re #10529

* clones select2config in concept-select vm to support simultaneous select2config for multiselect re #10529

* init select2multi in concept select template if adv search op support multiselect re #10529

* updates str formatting for search filter nodeid str re #10529

* replaces if/elif/else blocks with match/case for in_list search filter method re #10529

* rm unused arg request from in_list search filter method re #10529

* corrects translation declarations for in_list text values re #10529

* moves 2nd if block into else if in concept-select vm for casting valueList as arr re #10529

* conforms translation vars to single names re #10529

* refs corrected translation vars in concept-select template re #10529
  • Loading branch information
whatisgalen authored Apr 8, 2024
1 parent ed2a79d commit 74b5121
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 4 deletions.
28 changes: 28 additions & 0 deletions arches/app/datatypes/concept_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ def append_search_filters(self, value, node, query, request):
try:
if value["op"] == "null" or value["op"] == "not_null":
self.append_null_search_filters(value, node, query, request)
elif value["op"] == "in_list_any":
self.append_in_list_search_filters(value, node, query, match_any=True)
elif value["op"] == "in_list_all":
self.append_in_list_search_filters(value, node, query, match_any=False)
elif value["op"] == "in_list_not":
self.append_in_list_search_filters(value, node, query, match_any=None)
elif value["val"] != "":
match_query = Match(field="tiles.data.%s" % (str(node.pk)), type="phrase", query=value["val"])
if "!" in value["op"]:
Expand All @@ -139,6 +145,28 @@ def append_search_filters(self, value, node, query, request):
except KeyError as e:
pass

def append_in_list_search_filters(self, value, node, query, match_any=True):
try:
# Extract the list of values from the filter
values_list = value.get("val", [])

if values_list:
field_name = f"tiles.data.{str(node.pk)}"
for val in values_list:
match_q = Match(field=field_name, type="phrase", query=val)

match match_any:
case True:
query.should(match_q)
case False:
query.must(match_q)
case None:
query.must_not(match_q)
query.filter(Exists(field=field_name))

except KeyError as e:
pass


class ConceptDataType(BaseConceptDataType):
def validate(self, value, row_number=None, source="", node=None, nodeid=None, strict=False, **kwargs):
Expand Down
9 changes: 5 additions & 4 deletions arches/app/media/js/viewmodels/concept-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ define([
var valueList = self.value() || self.defaultValue();
self.displayName();

if (!self.multiple && valueList) {
valueList = [valueList];
}
if (Array.isArray(valueList)) {
return valueList;
} else if (!self.multiple && valueList) {
return [valueList];
}
return [];
});
Expand Down Expand Up @@ -130,7 +129,7 @@ define([
var setSelectionData = function(data) {
var valueData = [];

if (self.multiple) {
if (self.multiple || Array.isArray(valueList)) {
if (!(data instanceof Array)) { data = [data]; }

valueData = data.map(function(valueId) {
Expand Down Expand Up @@ -192,6 +191,8 @@ define([

}
};
this.select2ConfigMulti = { ...this.select2Config };
this.select2ConfigMulti.multiple = true;
};

return ConceptSelectViewModel;
Expand Down
4 changes: 4 additions & 0 deletions arches/app/templates/javascript.htm
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,10 @@
date-format='{% trans "Date Format" as dateFormat %} "{{ dateFormat|escapejs }}"'
has-no-value='{% trans "Has no value" as hasNoValue %} "{{ hasNoValue|escapejs }}"'
has-any-value='{% trans "Has any value" as hasAnyValue %} "{{ hasAnyValue|escapejs }}"'
has-any-list-value='{% trans "Has any value in list" as hasAnyListValue %} "{{ hasAnyListValue|escapejs }}"'
has-all-list-values='{% trans "Has all values in list" as hasAllListValues %} "{{ hasAllListValues|escapejs }}"'
has-no-list-values='{% trans "Has no values in list" as hasNoListValues %} "{{ hasNoListValues|escapejs }}"'
default-value='{% trans "Default Value" as defaultValue %} "{{ defaultValue|escapejs }}"'
format='{% trans "Format" as format %} "{{ format|escapejs }}"'
view-valid-formats='{% trans "view valid formats" as viewValidFormats %} "{{ viewValidFormats|escapejs }}"'
max='{% trans "Max" as max %} "{{ max|escapejs }}"'
Expand Down
15 changes: 15 additions & 0 deletions arches/app/templates/views/components/datatypes/concept.htm
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,17 @@
{ text: $root.translations.not, id: '!eq' },
{ text: $root.translations.hasNoValue, id: 'null' },
{ text: $root.translations.hasAnyValue, id: 'not_null' },
{ text: $root.translations.hasAnyListValue, id: 'in_list_any' },
{ text: $root.translations.hasAllListValues, id: 'in_list_all' },
{ text: $root.translations.hasNoListValues, id: 'in_list_not' }
],
value: op
}}">
</select>
</div>

<div class="col-md-8 col-lg-9" data-bind="visible: op() !== 'null' && op() !== 'not_null'">
<!-- ko if: !ko.unwrap(op).includes('in_list') -->
<select style="display:inline-block;"
data-bind="
attr: {'data-label': node.label},
Expand All @@ -52,5 +56,16 @@
}
">
</select>
<!-- /ko -->
<!-- ko if: ko.unwrap(op).includes('in_list') -->
<select style="display:inline-block;"
data-bind="
attr: {'data-label': node.label},
select2Query: {
select2Config: select2ConfigMulti
}
">
</select>
<!-- /ko -->
</div>
<!-- /ko -->

0 comments on commit 74b5121

Please sign in to comment.