Skip to content

Commit

Permalink
Prelim push
Browse files Browse the repository at this point in the history
  • Loading branch information
laurensWe committed Oct 15, 2024
1 parent 8364ee0 commit 9749d90
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 40 deletions.
62 changes: 54 additions & 8 deletions amt/api/routes/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from amt.enums.status import Status
from amt.models import Project
from amt.schema.measure import MeasureTask , ExtendedMeasureTask
from amt.schema.requirement import RequirementTask
from amt.schema.system_card import SystemCard
from amt.schema.task import MovedTask
from amt.services import task_registry
Expand Down Expand Up @@ -280,19 +281,24 @@ async def get_system_card_requirements(
# Get measures that correspond to the requirements and merge them with the measuretasks
requirements_and_measures = []
for requirement in requirements:
completed_measures_count = 0
linked_measures = fetch_measures(requirement.links)
extended_linked_measures: list[ExtendedMeasureTask] = []
for measure in linked_measures:
measure_task = find_measure_task(system_card , measure.urn)
if measure_task:
ext_measure_task = ExtendedMeasureTask(name=measure.name ,
description=measure.description ,
urn=measure.urn ,
state=measure_task.state ,
value=measure_task.value ,
ext_measure_task = ExtendedMeasureTask(name=measure.name,
description=measure.description,
urn=measure.urn,
state=measure_task.state,
value=measure_task.value,
version=measure_task.version)
if ext_measure_task.state == "done":
completed_measures_count += 1
extended_linked_measures.append(ext_measure_task)
requirements_and_measures.append((requirement , extended_linked_measures))
requirements_and_measures.append((requirement, completed_measures_count, extended_linked_measures))



context = {
"instrument_state": instrument_state ,
Expand All @@ -314,6 +320,28 @@ def find_measure_task(system_card: SystemCard , urn: str) -> MeasureTask | None:
return None


def find_requirement_task(system_card: SystemCard , requirement_urn: str) -> RequirementTask | None:
for requirement in system_card.requirements:
if requirement.urn == requirement_urn:
return requirement
return None


def find_requirement_tasks_by_measure_urn(system_card: SystemCard , measure_urn: str) -> list[RequirementTask]:
requirement_mapper = {}
for requirement_task in system_card.requirements:
requirement_mapper[requirement_task.urn] = requirement_task

requirement_tasks = []
measure = fetch_measures([measure_urn])
for requirement_urn in measure[0].links:
# TODO: This is because measure are linked to too many requirement not applicable in our use case
if len(fetch_requirements([requirement_urn])) > 0:
requirement_tasks.append(requirement_mapper[requirement_urn])

return requirement_tasks


@router.get("/{project_id}/measure/{measure_urn}")
async def get_measure(request: Request , project_id: int , measure_urn: str ,
projects_service: Annotated[ProjectsService , Depends(ProjectsService)]) -> HTMLResponse:
Expand Down Expand Up @@ -341,15 +369,33 @@ async def update_measure_value(request: Request ,
project_id: int ,
measure_urn: str ,
measure_update: MeasureUpdate ,
projects_service: Annotated[ProjectsService , Depends(ProjectsService)]) -> None:
projects_service: Annotated[ProjectsService , Depends(ProjectsService)]) -> HTMLResponse:
project = get_project_or_error(project_id , projects_service , request)

measure_task = find_measure_task(project.system_card , measure_urn) #TODO: Pyright ignore
measure_task.state = measure_update.measure_state
measure_task.value = measure_update.measure_value

projects_service.update(project)
# update for the linked requirements the state based on all it's measures
requirement_tasks = find_requirement_tasks_by_measure_urn(project.system_card, measure_urn)
requirement_urns = [requirement_task.urn for requirement_task in requirement_tasks]
requirements = fetch_requirements(requirement_urns)

for requirement in requirements:
count_completed = 0
for link_measure_urn in requirement.links:
link_measure_task = find_measure_task(project.system_card, link_measure_urn)
if link_measure_task.state == "done":
count_completed += 1
requirement_task = find_requirement_task(project.system_card, requirement.urn)
if count_completed == len(requirement.links):
requirement_task.state = "done"
else:
requirement_task.state = "in progress"

projects_service.update(project)
# TODO: FIX THIS!! The page now reloads at the top, which is annoying
return templates.Redirect(request, f"/project/{project_id}/details/system_card/requirements")

# !!!
# Implementation of this endpoint is for now independent of the project ID, meaning
Expand Down
4 changes: 2 additions & 2 deletions amt/schema/measure.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pydantic import BaseModel
from pydantic import BaseModel, Field


class MeasureBase(BaseModel):
Expand All @@ -14,7 +14,7 @@ class MeasureTask(MeasureBase):
class Measure(MeasureBase):
name: str
description: str

links: list[str] = Field(default=[])

class ExtendedMeasureTask(MeasureTask):
name: str
Expand Down
33 changes: 22 additions & 11 deletions amt/site/templates/projects/details_measure_modal.html.j2
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@
{{ measure.description }}
</div>
</div>
<div class="rvo-layout-row">
<span
class="utrecht-icon rvo-icon rvo-icon-info rvo-icon--xl rvo-status-icon-info"
role="img"
aria-label="Info"
></span>
<a href="https://minbzk.github.io/Algoritmekader/" class="rvo-link utrecht-link">
{% trans %}Read more on the algoritmekader{% endtrans %}
</a>
</div>
</div>
{# Status#}
<div role="group" aria-labelledby="fieldId-label"
Expand All @@ -34,14 +44,17 @@
</label>
</div>
<div class="rvo-select-wrapper utrecht-textbox--small">
<select id="field" name="measure_state" class="utrecht-select utrecht-select--html-select">
<select id="field" name="measure_state"
class="utrecht-select utrecht-select--html-select">
{% if measure_state == "to do" %}
<option value="to do" selected="selected">{% trans %}to do{% endtrans %}</option>
<option value="to do" selected="selected">{% trans %}to
do{% endtrans %}</option>
{% else %}
<option value="to do">{% trans %}to do{% endtrans %}</option>
{% endif %}
{% if measure_state == "in progress" %}
<option value="in progress" selected="selected">{% trans %}in progress{% endtrans %}</option>
<option value="in progress" selected="selected">{% trans %}in
progress{% endtrans %}</option>
{% else %}
<option value="in progress">{% trans %}in progress{% endtrans %}</option>
{% endif %}
Expand All @@ -62,21 +75,19 @@
{% trans %}Implementation{% endtrans %}
</label>
</div>
<input id="field"
placeholder="{% trans %}Describe how the measure has been implemented, including challenges and solutions.{% endtrans %}"
type="text"
class="utrecht-textbox utrecht-textbox--html-input utrecht-textbox--large"
dir="auto"
name="measure_value"
value="{{ measure_value }}" />
<textarea id="field"
placeholder="{% trans %}Describe how the measure has been implemented, including challenges and solutions.{% endtrans %}"
class="utrecht-textarea utrecht-textarea--html-textarea utrecht-textarea--large"
dir="auto"
name="measure_value">{{ measure_value }}</textarea>
</div>
</fieldset>
</div>
<p class="utrecht-button-group">
<button id="save-measure-edit"
type="submit"
class="flex utrecht-button utrecht-button--primary-action rvo-layout-row rvo-layout-gap--md utrecht-button--rvo-md rvo-link--no-underline utrecht-button-group__align-left"
>
onclick="amt.closeModal('measure-modal')">
{% trans %}Save{% endtrans %}
</button>
<button id="close-measure-edit"
Expand Down
40 changes: 21 additions & 19 deletions amt/site/templates/projects/details_requirements.html.j2
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{% endblock %}
{% block detail_content %}
<div class="rvo-accordion">
{% for (requirement, measures) in requirements_and_measures %}
{% for (requirement, completed_measures_count, measures) in requirements_and_measures %}
<details class="rvo-accordion__item">
<summary class="rvo-accordion__item-summary margin-bottom-large">
<h3 class="utrecht-heading-3 rvo-accordion__item-title rvo-heading--no-margins rvo-heading--mixed">
Expand All @@ -20,8 +20,12 @@
</h3>
<span class="rvo-accordion-teaser">
<div class="rvo-layout-row rvo-layout-gap--sm">
<div class="rvo-status-indicator rvo-status-indicator--oranje"></div>
0 / {{ measures | length }} {% trans %}measures executed{% endtrans %}
{% if completed_measures_count == measures | length %}
<div class="rvo-status-indicator rvo-status-indicator--groen"></div>
{% else %}
<div class="rvo-status-indicator rvo-status-indicator--oranje"></div>
{% endif %}
{{ completed_measures_count }} / {{ measures | length }} {% trans %}measures executed{% endtrans %}
</div>
</span>
</summary>
Expand All @@ -40,24 +44,22 @@
<div class="rvo-status-indicator rvo-status-indicator--rood"></div>
{% endif %}
<div class="rvo-layout-column">
<h4 class="utrecht-heading-4 rvo-heading--no-margins">{{ measure.name }}</h4>
<h4 class="utrecht-heading-4 rvo-heading--no-margins">{{ loop.index }}. {{ measure.name }}</h4>
<p class="rvo-text">{{ measure.value }}</p>
<a class="rvo-link rvo-link--normal rvo-link--with-icon"
href="/project/{{ project_id }}/measure/{{ measure.urn }}"
hx-target="#dynamic-modal-content"
hx-trigger="click"
hx-swap="innerHTML"
onclick="amt.openModal('measure-modal')">
<span
class="utrecht-icon rvo-icon rvo-icon-pijl-naar-rechts rvo-icon--md rvo-icon--hemelblauw rvo-link__icon--before"
role="img"
aria-label="Home"></span>
{% trans %}Edit measure{% endtrans %}
</a>
</div>

<a class="rvo-link rvo-link--normal rvo-link--with-icon"
hx-trigger="click"
hx-target="#dynamic-modal-content"
hx-get="/project/{{ project_id }}/measure/{{ measure.urn }}"
hx-swap="innerHTML"
onclick="amt.openModal('measure-modal')">
<span
class="utrecht-icon rvo-icon rvo-icon-pijl-naar-rechts rvo-icon--md rvo-icon--hemelblauw rvo-link__icon--before"
role="img"
aria-label="Home"></span>
{% trans %}Edit measure{% endtrans %}
</a>
</div>
</div>

</div>
{% endfor %}
</details>
Expand Down

0 comments on commit 9749d90

Please sign in to comment.