Skip to content

Commit

Permalink
UI: edit node: fix a case when editing a custom node
Browse files Browse the repository at this point in the history
  • Loading branch information
stanislaw committed Aug 23, 2024
1 parent cf743d1 commit a1bb002
Show file tree
Hide file tree
Showing 21 changed files with 379 additions and 179 deletions.
21 changes: 10 additions & 11 deletions strictdoc/backend/excel/export/excel_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,10 @@ def _export_single_document(
if len(parent_refs) > 0:
# TODO Allow multiple parent refs
ref = parent_refs[0]
if (
len(ref.ref_uid)
> columns[field][MAX_WIDTH_KEY]
):
columns[field][MAX_WIDTH_KEY] = len(
ref.ref_uid
)
columns[field][MAX_WIDTH_KEY] = max(
len(ref.ref_uid),
columns[field][MAX_WIDTH_KEY],
)
if ref.ref_uid in req_uid_rows:
worksheet.write_url(
row,
Expand Down Expand Up @@ -171,15 +168,17 @@ def _export_single_document(
)
worksheet.write(row, idx, relations_row_value)
value_len = len(relations_row_value)
if value_len > columns[field][MAX_WIDTH_KEY]:
columns[field][MAX_WIDTH_KEY] = value_len
columns[field][MAX_WIDTH_KEY] = max(
value_len, columns[field][MAX_WIDTH_KEY]
)
elif field_uc in node.ordered_fields_lookup.keys():
req_field = node.ordered_fields_lookup[field_uc][0]
value: str = req_field.get_text_value()
worksheet.write(row, idx, value)
value_len = len(value)
if value_len > columns[field][MAX_WIDTH_KEY]:
columns[field][MAX_WIDTH_KEY] = value_len
columns[field][MAX_WIDTH_KEY] = max(
value_len, columns[field][MAX_WIDTH_KEY]
)
elif hasattr(node, "special_fields"):
if len(node.special_fields):
for special_field in node.special_fields:
Expand Down
25 changes: 9 additions & 16 deletions strictdoc/export/html/form_objects/requirement_form_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -776,30 +776,23 @@ def validate(
relation_target_uids_so_far.add(link_uid)

# Check if the target document supports a given relation.
target_requirement: SDocNode = (
traceability_index.get_node_by_uid(link_uid)
)
target_grammar_element: GrammarElement = (
target_requirement.document.grammar.elements_by_type[
self.element_type
]
node_grammar_element: GrammarElement = (
self.grammar.elements_by_type[self.element_type]
)
field_role_or_none = (
reference_field.field_role
if reference_field.field_role is not None
and len(reference_field.field_role) > 0
else None
)
if not target_grammar_element.has_relation_type_role(

# This is not a realistic case to happen when a node is
# edited in UI because the UI dropdown element whitelists
# the available relation types.
# Using an assert anyway just to make sure.
assert node_grammar_element.has_relation_type_role(
reference_field.field_type, field_role_or_none
):
reference_field.validation_messages.append(
f"Relation target requirement's document "
"does not have this relation registered: "
f'type: "{reference_field.field_type}" '
f'role: "{reference_field.field_role}".'
)
continue
)

# Check if the relation forms a cycle.
ref_uid = reference_field.field_value
Expand Down
2 changes: 1 addition & 1 deletion strictdoc/server/routers/main_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -1795,8 +1795,8 @@ def document__add_relation(
)
assert document.grammar is not None
grammar: DocumentGrammar = document.grammar
element: GrammarElement = grammar.elements_by_type["REQUIREMENT"]

element: GrammarElement = grammar.elements_by_type[element_type]
grammar_element_relations = element.get_relation_types()

# The data of the form object is ignored. What matters is the relation
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[DOCUMENT]
TITLE: Test document #1

[GRAMMAR]
ELEMENTS:
- TAG: TEXT
FIELDS:
- TITLE: UID
TYPE: String
REQUIRED: False
- TITLE: STATEMENT
TYPE: String
REQUIRED: True
- TAG: RULE
FIELDS:
- TITLE: UID
TYPE: String
REQUIRED: False
- TITLE: TITLE
TYPE: String
REQUIRED: False
- TITLE: STATEMENT
TYPE: String
REQUIRED: False
RELATIONS:
- TYPE: Parent
ROLE: to trace objective

[RULE]
UID: RUL-1
TITLE: Rule #1
STATEMENT: >>>
Rule #1 statement.
<<<
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[DOCUMENT]
TITLE: Test document #2

[GRAMMAR]
ELEMENTS:
- TAG: TEXT
FIELDS:
- TITLE: UID
TYPE: String
REQUIRED: False
- TITLE: STATEMENT
TYPE: String
REQUIRED: True
- TAG: OBJECTIVE
FIELDS:
- TITLE: UID
TYPE: String
REQUIRED: False
- TITLE: TITLE
TYPE: String
REQUIRED: False
- TITLE: STATEMENT
TYPE: String
REQUIRED: False

[OBJECTIVE]
UID: OBJ-1
TITLE: Objective #1
STATEMENT: Objective #1 statement.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[DOCUMENT]
TITLE: Test document #1

[GRAMMAR]
ELEMENTS:
- TAG: TEXT
FIELDS:
- TITLE: UID
TYPE: String
REQUIRED: False
- TITLE: STATEMENT
TYPE: String
REQUIRED: True
- TAG: RULE
FIELDS:
- TITLE: UID
TYPE: String
REQUIRED: False
- TITLE: TITLE
TYPE: String
REQUIRED: False
- TITLE: STATEMENT
TYPE: String
REQUIRED: False
RELATIONS:
- TYPE: Parent
ROLE: to trace objective

[RULE]
UID: RUL-1
TITLE: Rule #1
STATEMENT: >>>
Rule #1 statement.
<<<
RELATIONS:
- TYPE: Parent
VALUE: OBJ-1
ROLE: to trace objective
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[DOCUMENT]
TITLE: Test document #2

[GRAMMAR]
ELEMENTS:
- TAG: TEXT
FIELDS:
- TITLE: UID
TYPE: String
REQUIRED: False
- TITLE: STATEMENT
TYPE: String
REQUIRED: True
- TAG: OBJECTIVE
FIELDS:
- TITLE: UID
TYPE: String
REQUIRED: False
- TITLE: TITLE
TYPE: String
REQUIRED: False
- TITLE: STATEMENT
TYPE: String
REQUIRED: False

[OBJECTIVE]
UID: OBJ-1
TITLE: Objective #1
STATEMENT: Objective #1 statement.
Loading

0 comments on commit a1bb002

Please sign in to comment.