Skip to content

Commit

Permalink
Merge pull request strictdoc-project#1364 from strictdoc-project/_UI_…
Browse files Browse the repository at this point in the history
…clone_req

export/html: adding the ability to clone a requirement
  • Loading branch information
stanislaw authored Oct 23, 2023
2 parents 686b080 + 8d0c6c9 commit 0404262
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 5 deletions.
18 changes: 18 additions & 0 deletions strictdoc/export/html/form_objects/requirement_form_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,24 @@ 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
Expand Down
4 changes: 4 additions & 0 deletions strictdoc/export/html/templates/_res/svg_ico16_copy.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<svg class="svg_icon" width="16px" height="16px" viewBox="0 0 16 16">
<path d="M8,2 L12,2 C13,2 14,3 14,4 L14,8 C14,9 13,10 12,10 L8,10 C7,10 6,9 6,8 L6,4 C6,3 7,2 8,2 Z"/>
<path d="M10,12 C10,13 9,14 8,14 L4,14 C3,14 2,13 2,12 L2,8 C2,7 3,6 4,6"/>
</svg>
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@
>{% include "_res/svg_ico16_edit.jinja.html" %}</a>
{%- endif -%}

{%- if sdoc_entity.get_type_string() != 'document' -%}
{# EDIT & DELETE:
{# EDIT & DELETE:
+ section
+ equirement
+ requirement
- NOT document
#}
{%- if sdoc_entity.get_type_string() != 'document' -%}
<a
href="/actions/document/edit_{{ sdoc_entity.get_type_string() }}/{{ sdoc_entity.mid.get_string_value() }}"
class="action_button"
Expand All @@ -49,11 +49,28 @@
title="Delete"
data-testid="node-delete-action"
>{% include "_res/svg_ico16_delete.jinja.html" %}</a>
{%- endif -%}
{%- endif -%}

{# CLONE:
- NOT section
+ requirement
- NOT document
#}
{%- if sdoc_entity.get_type_string() == 'requirement' -%}
<a
href="/actions/document/clone_requirement?reference_mid={{ sdoc_entity.mid.get_string_value() }}"
class="action_button"
{# data-turbo-action="replace" #}
{# data-turbo-method="delete" #}
data-turbo="true"
title="Clone"
data-testid="node-clone-action"
>{% include "_res/svg_ico16_copy.jinja" %}</a>
{%- 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 -%}
Expand Down Expand Up @@ -220,4 +237,5 @@
</sdoc-menu-list>
</sdoc-menu>
{%- endif -%}

</sdoc-node-controls>
71 changes: 71 additions & 0 deletions strictdoc/server/routers/main_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,77 @@ 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 = (
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
)
Expand Down

0 comments on commit 0404262

Please sign in to comment.