Skip to content

Commit f910e0a

Browse files
stanislawthseiler
authored andcommitted
UI: generalize autocompletion to work for MultipleChoice fields (code review)
1 parent aaece00 commit f910e0a

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

strictdoc/backend/sdoc/models/document.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
)
2626
from strictdoc.core.document_meta import DocumentMeta
2727
from strictdoc.helpers.auto_described import auto_described
28+
from strictdoc.helpers.cast import assert_cast
2829
from strictdoc.helpers.mid import MID
2930

3031

@@ -217,8 +218,7 @@ def get_grammar_element_field_for(
217218
"""
218219
Returns the GrammarElementField for a field of a [element_type] in this document.
219220
"""
220-
assert self.grammar is not None
221-
grammar: DocumentGrammar = self.grammar
221+
grammar: DocumentGrammar = assert_cast(self.grammar, DocumentGrammar)
222222
element: GrammarElement = grammar.elements_by_type[element_type]
223223
field: GrammarElementField = element.fields_map[field_name]
224224
return field

strictdoc/export/html/_static/controllers/autocompletable_field_controller.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@
185185
const text = this.autocompletable.innerText || "";
186186
const parts = text.split(",");
187187

188-
// Replace the last incomplete token with the suggestion
188+
// Replace the last incomplete token with the suggestion.
189189
parts[parts.length - 1] = " " + suggestion;
190190
suggestion = parts.map(p => p.trim()).join(", ")
191191
}

strictdoc/server/routers/main_router.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2793,14 +2793,14 @@ def get_autocomplete_field_results(
27932793
)
27942794

27952795
if field.gef_type == RequirementFieldType.MULTIPLE_CHOICE:
2796-
# MultipleChoice: Split the query into parts
2796+
# MultipleChoice: Split the query into parts.
27972797
parts = q.lower().split(",")
27982798

27992799
# only use the last_part for lookup
28002800
last_part = parts[-1].strip()
28012801
query_words = last_part.split()
28022802

2803-
# and pre-filter: don't suggest choices that were already selected / present in the query
2803+
# Pre-filter: don't suggest choices that were already selected / present in the query.
28042804
already_selected = [
28052805
p.strip() for p in parts[:-1] if p.strip()
28062806
]
@@ -2810,13 +2810,13 @@ def get_autocomplete_field_results(
28102810
if choice.lower() not in already_selected
28112811
]
28122812
else:
2813-
# SingleChoice: use all available options
2813+
# SingleChoice: use all available options.
28142814
query_words = q.lower().split()
28152815
filtered_options = all_options
28162816

28172817
resulting_values = []
28182818

2819-
# now filter the remainig options for those that macht all words in query_words
2819+
# Now filter the remaining options for those that match all words in query_words.
28202820
for option_ in filtered_options:
28212821
words_ = option_.strip().lower()
28222822

0 commit comments

Comments
 (0)