From abfbe7f2c7cd3d8193581984d9fff27c60a1a0d4 Mon Sep 17 00:00:00 2001 From: Maryna Balioura Date: Mon, 23 Oct 2023 00:23:45 +0200 Subject: [PATCH 1/3] export/html: adding the ability to clone a requirement --- .../form_objects/requirement_form_object.py | 14 ++++ .../components/node/node_controls/index.jinja | 12 +++ strictdoc/server/routers/main_router.py | 73 +++++++++++++++++++ 3 files changed, 99 insertions(+) diff --git a/strictdoc/export/html/form_objects/requirement_form_object.py b/strictdoc/export/html/form_objects/requirement_form_object.py index d76e8d672..af5ca25ee 100644 --- a/strictdoc/export/html/form_objects/requirement_form_object.py +++ b/strictdoc/export/html/form_objects/requirement_form_object.py @@ -438,6 +438,20 @@ def create_from_requirement( relation_types=grammar_element_relations, ) + @staticmethod + def clone_from_requirement( + *, requirement: Requirement, clone_uid: str + ) -> "RequirementFormObject": + form_object: RequirementFormObject = RequirementFormObject.create_from_requirement(requirement=requirement) + for field_name, fields_ in form_object.fields.items(): + if field_name == "UID": + field: RequirementFormField = fields_[0] + field.field_unescaped_value = clone_uid + field.field_escaped_value = clone_uid + form_object.requirement_mid = MID.create().get_string_value() + + return form_object + def any_errors(self): if super().any_errors(): return True diff --git a/strictdoc/export/html/templates/components/node/node_controls/index.jinja b/strictdoc/export/html/templates/components/node/node_controls/index.jinja index 32c3d630d..e1ed2cb6e 100644 --- a/strictdoc/export/html/templates/components/node/node_controls/index.jinja +++ b/strictdoc/export/html/templates/components/node/node_controls/index.jinja @@ -220,4 +220,16 @@ {%- endif -%} + + {%- if sdoc_entity.get_type_string() == 'requirement' -%} + {% include "_res/svg_ico16_add.jinja.html" %} + {%- endif -%} diff --git a/strictdoc/server/routers/main_router.py b/strictdoc/server/routers/main_router.py index c495a318d..bd3c03fa1 100644 --- a/strictdoc/server/routers/main_router.py +++ b/strictdoc/server/routers/main_router.py @@ -702,6 +702,79 @@ def get_new_requirement(reference_mid: str, whereto: str): }, ) + @router.get("/actions/document/clone_requirement", response_class=Response) + def get_clone_requirement(reference_mid: str): + assert isinstance(reference_mid, str), reference_mid + + reference_node = export_action.traceability_index.get_node_by_mid( + MID(reference_mid) + ) + reference_requirement: Requirement = assert_cast(reference_node, Requirement) + document = ( + reference_node + if isinstance(reference_node, Document) + else reference_node.document + ) + document_tree_stats: DocumentTreeStats = ( + DocumentUIDAnalyzer.analyze_document_tree( + export_action.traceability_index + ) + ) + next_uid: str = document_tree_stats.get_next_requirement_uid( + reference_node.get_requirement_prefix() + ) + # form_object = RequirementFormObject.create_new( + # document=document, next_uid=next_uid + # ) + form_object: RequirementFormObject = ( + RequirementFormObject.clone_from_requirement( + requirement=reference_requirement, + clone_uid=next_uid + ) + ) + + target_node_mid = reference_mid + + whereto = NodeCreationOrder.AFTER + replace_action = "after" + + template = env().get_template( + "actions/" + "document/" + "create_requirement/" + "stream_new_requirement.jinja.html" + ) + link_renderer = LinkRenderer( + root_path=document.meta.get_root_path_prefix(), + static_path=project_config.dir_for_sdoc_assets, + ) + markup_renderer = MarkupRenderer.create( + markup="RST", + traceability_index=export_action.traceability_index, + link_renderer=link_renderer, + html_templates=html_generator.html_templates, + config=project_config, + context_document=document, + ) + output = template.render( + is_new_requirement=True, + renderer=markup_renderer, + form_object=form_object, + reference_mid=reference_mid, + target_node_mid=target_node_mid, + document_type=DocumentType.document(), + whereto=whereto, + replace_action=replace_action, + ) + + return HTMLResponse( + content=output, + status_code=200, + headers={ + "Content-Type": "text/vnd.turbo-stream.html", + }, + ) + @router.post( "/actions/document/create_requirement", response_class=Response ) From e39ca28187f794055b3a7d5c3474a6a583c258fa Mon Sep 17 00:00:00 2001 From: Maryna Balioura Date: Mon, 23 Oct 2023 20:33:12 +0200 Subject: [PATCH 2/3] export/html: add copy icon; put clone button in front of the add button --- .../html/templates/_res/svg_ico16_copy.jinja | 4 ++ .../components/node/node_controls/index.jinja | 38 +++++++++++-------- 2 files changed, 26 insertions(+), 16 deletions(-) create mode 100644 strictdoc/export/html/templates/_res/svg_ico16_copy.jinja diff --git a/strictdoc/export/html/templates/_res/svg_ico16_copy.jinja b/strictdoc/export/html/templates/_res/svg_ico16_copy.jinja new file mode 100644 index 000000000..2e8d16e1c --- /dev/null +++ b/strictdoc/export/html/templates/_res/svg_ico16_copy.jinja @@ -0,0 +1,4 @@ + + + + diff --git a/strictdoc/export/html/templates/components/node/node_controls/index.jinja b/strictdoc/export/html/templates/components/node/node_controls/index.jinja index e1ed2cb6e..472ba2355 100644 --- a/strictdoc/export/html/templates/components/node/node_controls/index.jinja +++ b/strictdoc/export/html/templates/components/node/node_controls/index.jinja @@ -27,12 +27,12 @@ >{% include "_res/svg_ico16_edit.jinja.html" %} {%- endif -%} -{%- if sdoc_entity.get_type_string() != 'document' -%} - {# EDIT & DELETE: + {# EDIT & DELETE: + section - + equirement + + requirement - NOT document #} +{%- if sdoc_entity.get_type_string() != 'document' -%} {% include "_res/svg_ico16_delete.jinja.html" %} - {%- endif -%} +{%- endif -%} + + {# CLONE: + - NOT section + + requirement + - NOT document + #} +{%- if sdoc_entity.get_type_string() == 'requirement' -%} + {% include "_res/svg_ico16_copy.jinja" %} +{%- endif -%} {# ADD NODES menu: + section - + equirement + + requirement + document ONLY 'not document.section_contents' #} {%- if sdoc_entity.get_type_string() != 'document' or not document.section_contents -%} @@ -221,15 +238,4 @@ {%- endif -%} - {%- if sdoc_entity.get_type_string() == 'requirement' -%} - {% include "_res/svg_ico16_add.jinja.html" %} - {%- endif -%} From 8d0c6c9e01495d92486ff2d5fe226dbeef797b94 Mon Sep 17 00:00:00 2001 From: Maryna Balioura Date: Mon, 23 Oct 2023 20:42:39 +0200 Subject: [PATCH 3/3] Fix linting issues --- .../html/form_objects/requirement_form_object.py | 6 +++++- strictdoc/server/routers/main_router.py | 10 ++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/strictdoc/export/html/form_objects/requirement_form_object.py b/strictdoc/export/html/form_objects/requirement_form_object.py index af5ca25ee..d7dbf6f32 100644 --- a/strictdoc/export/html/form_objects/requirement_form_object.py +++ b/strictdoc/export/html/form_objects/requirement_form_object.py @@ -442,7 +442,11 @@ def create_from_requirement( def clone_from_requirement( *, requirement: Requirement, clone_uid: str ) -> "RequirementFormObject": - form_object: RequirementFormObject = RequirementFormObject.create_from_requirement(requirement=requirement) + form_object: RequirementFormObject = ( + RequirementFormObject.create_from_requirement( + requirement=requirement + ) + ) for field_name, fields_ in form_object.fields.items(): if field_name == "UID": field: RequirementFormField = fields_[0] diff --git a/strictdoc/server/routers/main_router.py b/strictdoc/server/routers/main_router.py index bd3c03fa1..34d07a688 100644 --- a/strictdoc/server/routers/main_router.py +++ b/strictdoc/server/routers/main_router.py @@ -709,7 +709,9 @@ def get_clone_requirement(reference_mid: str): reference_node = export_action.traceability_index.get_node_by_mid( MID(reference_mid) ) - reference_requirement: Requirement = assert_cast(reference_node, Requirement) + reference_requirement: Requirement = assert_cast( + reference_node, Requirement + ) document = ( reference_node if isinstance(reference_node, Document) @@ -723,13 +725,9 @@ def get_clone_requirement(reference_mid: str): next_uid: str = document_tree_stats.get_next_requirement_uid( reference_node.get_requirement_prefix() ) - # form_object = RequirementFormObject.create_new( - # document=document, next_uid=next_uid - # ) form_object: RequirementFormObject = ( RequirementFormObject.clone_from_requirement( - requirement=reference_requirement, - clone_uid=next_uid + requirement=reference_requirement, clone_uid=next_uid ) )