Skip to content

Commit

Permalink
Merge pull request strictdoc-project#1450 from strictdoc-project/stan…
Browse files Browse the repository at this point in the history
…islaw/search

 export/html: search: node.contains(...) expression
  • Loading branch information
mettta authored Nov 13, 2023
2 parents 06efcb2 + 9a6e15e commit 9895eee
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 7 deletions.
6 changes: 6 additions & 0 deletions strictdoc/core/query_engine/grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
|
NotInExpression
|
NodeContainsExpression
|
NodeIsRequirementExpression
|
NodeIsSectionExpression
Expand All @@ -60,6 +62,10 @@
'node["' field_name = /[A-Za-z0-9]+/ '"]'
;
NodeContainsExpression:
'node.contains("' string = /[A-Za-z0-9]+/ '")'
;
NodeHasParentRequirementsExpression:
_ = 'node.has_parent_requirements'
;
Expand Down
37 changes: 36 additions & 1 deletion strictdoc/core/query_engine/query_object.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from typing import List, Optional

from strictdoc.backend.sdoc.models.document_grammar import GrammarElement
from strictdoc.backend.sdoc.models.requirement import Requirement
from strictdoc.backend.sdoc.models.requirement import (
Requirement,
RequirementField,
)
from strictdoc.backend.sdoc.models.section import Section
from strictdoc.core.traceability_index import TraceabilityIndex
from strictdoc.helpers.cast import assert_cast
Expand All @@ -28,6 +31,12 @@ def __init__(self, parent, field_name: str):
self.field_name = field_name


class NodeContainsExpression:
def __init__(self, parent, string: str):
self.parent = parent
self.string: str = string


class NodeHasParentRequirementsExpression:
def __init__(self, parent, _):
self.parent = parent
Expand Down Expand Up @@ -117,6 +126,8 @@ def _evaluate(self, node, expression) -> bool:
return self._evaluate_equal(node, expression)
if isinstance(expression, NotEqualExpression):
return self._evaluate_not_equal(node, expression)
if isinstance(expression, NodeContainsExpression):
return self._evaluate_node_contains(node, expression)
if isinstance(expression, NodeHasParentRequirementsExpression):
return self._evaluate_node_has_parent_requirements(node)
if isinstance(expression, NodeHasChildRequirementsExpression):
Expand Down Expand Up @@ -217,3 +228,27 @@ def _evaluate_node_has_child_requirements(self, node):
f"the error, prepend your query with node.is_requirement."
)
return self.traceability_index.has_children_requirements(node)

def _evaluate_node_contains(
self, node, expression: NodeContainsExpression
) -> bool:
if isinstance(node, Requirement):
requirement = assert_cast(node, Requirement)
requirement_field_: RequirementField
for requirement_field_ in requirement.enumerate_fields():
if requirement_field_.field_value is not None:
if expression.string in requirement_field_.field_value:
return True
elif requirement_field_.field_value_multiline is not None:
if (
expression.string
in requirement_field_.field_value_multiline
):
return True
return False
if isinstance(node, Section):
section = assert_cast(node, Section)
if expression.string in section.title:
return True
return False
raise NotImplementedError
10 changes: 6 additions & 4 deletions strictdoc/core/query_engine/query_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,27 @@
AndExpression,
EqualExpression,
InExpression,
NodeContainsExpression,
NodeFieldExpression,
NodeHasChildRequirementsExpression,
NodeHasParentRequirementsExpression,
NodeIsRequirementExpression,
NodeIsRootExpression,
NodeIsSectionExpression,
NoneExpression,
NotEqualExpression,
NotExpression,
NotInExpression,
OrExpression,
Query,
StringExpression,
NodeIsRootExpression,
NotInExpression,
NoneExpression,
NodeHasChildRequirementsExpression,
)

QUERY_MODELS = [
AndExpression,
EqualExpression,
InExpression,
NodeContainsExpression,
NodeFieldExpression,
NodeHasChildRequirementsExpression,
NodeHasParentRequirementsExpression,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,31 @@
<td colspan="2"><b>TBD/TBC</b></td>
</tr>
<tr>
<td>Total TBD</td>
{% if project_config.is_activated_search() %}
<td>
<a
href="{{ link_renderer.render_url('search?q=node.contains("TBD")') }}"
>
Total TBD
</a>
</td>
{% else %}
<td>Total TBD</td>
{% endif %}
<td>{{ document_tree_stats.total_tbd }}</td>
</tr>
<tr>
<td>Total TBC</td>
{% if project_config.is_activated_search() %}
<td>
<a
href="{{ link_renderer.render_url('search?q=node.contains("TBC")') }}"
>
Total TBC
</a>
</td>
{% else %}
<td>Total TBC</td>
{% endif %}
<td>{{ document_tree_stats.total_tbc }}</td>
</tr>
</table>
Expand Down

0 comments on commit 9895eee

Please sign in to comment.