Skip to content

Commit

Permalink
added finished method to flow and modified navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
josihoppe committed Nov 27, 2024
1 parent 9205f07 commit 90f90ac
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 42 deletions.
5 changes: 5 additions & 0 deletions building_dialouge_webapp/heat/flows.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,11 @@ def dispatch(self, request, *args, **kwargs) -> HttpResponse:
# Fill template with state partials by adding them with their target_id
return self.render_to_response(context)

def finished(self):
"""Check if the given flow is finished."""
state_responses = self.start.set()
return any(isinstance(response, EndState) for response in state_responses.values())


class BuildingTypeFlow(SidebarNavigationMixin, Flow):
template_name = "pages/building_type.html"
Expand Down
113 changes: 80 additions & 33 deletions building_dialouge_webapp/heat/navigation.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
class SidebarNavigationMixin:
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)

index = self.get_flows()
state_found = False
current_url = self.request.path

for category in index:
for step in category["steps"]:
flow_object = step["object"]

for step in index:
index_state = ""
if step["object"] == type(self):
index_state = "active"
state_found = True
elif not state_found:
index_state = "visited"
if step["url"] == current_url:
step["index_state"] = "active"
elif flow_object.finished(self):
step["index_state"] = "visited"
else:
step["index_state"] = ""

step["index_state"] = index_state
step["is_category"] = step["name"][0].isdigit()
# Set category state based on step states
if any(step["index_state"] == "active" for step in category["steps"]):
category["index_state"] = "active"
elif all(step["index_state"] == "visited" for step in category["steps"]):
category["index_state"] = "visited"
else:
category["index_state"] = ""

context["index"] = index
return context
Expand All @@ -24,27 +31,67 @@ def get_flows(self):
from . import views

return [
{"name": "1. Verbrauchsanalyse", "object": views.IntroConsumption, "url": "heat:intro_consumption"},
{"name": "Gebäudeart", "object": flows.BuildingTypeFlow, "url": "heat:building_type"},
{"name": "Angaben zu Gebäude", "object": flows.BuildingDataFlow, "url": "heat:building_data"},
{"name": "Keller", "object": flows.CellarFlow, "url": "heat:cellar"},
{"name": "Heizung & Warmwasser", "object": flows.HotwaterHeatingFlow, "url": "heat:hotwater_heating"},
{"name": "Verbrauchseingabe", "object": flows.ConsumptionInputFlow, "url": "heat:consumption_input"},
{"name": "Verbrauchsergebnis", "object": views.ConsumptionResult, "url": "heat:consumption_result"},
{"name": "2. Bestandsanalyse", "object": views.IntroInventory, "url": "heat:intro_inventory"},
{"name": "Dach", "object": flows.RoofFlow, "url": "heat:roof"},
{"name": "Fenster", "object": flows.WindowFlow, "url": "heat:window"},
{"name": "Fassade", "object": flows.FacadeFlow, "url": "heat:facade"},
{"name": "Heizung", "object": flows.HeatingFlow, "url": "heat:heating"},
{"name": "PV-Anlage", "object": flows.PVSystemFlow, "url": "heat:pv_system"},
{"name": "Lüftungsanlage", "object": flows.VentilationSystemFlow, "url": "heat:ventilation_system"},
{"name": "3. Sanierung", "object": views.IntroRenovation, "url": "heat:intro_renovation"},
{
"name": "Sanierungswunsch",
"object": flows.FinancialSupporFlow,
"url": "heat:financial_support",
}, # renovation
{"name": "Förderung", "object": flows.FinancialSupporFlow, "url": "heat:financial_support"},
{"name": "4. Ergebnisse", "object": views.Results, "url": "heat:results"},
{"name": "Nächste Schritte", "object": views.NextSteps, "url": "heat:next_steps"},
"category": "1. Verbrauchsanalyse",
"object": views.IntroConsumption,
"url": "heat:intro_consumption",
"steps": [
{"name": "Gebäudeart", "object": flows.BuildingTypeFlow, "url": "heat:building_type"},
{"name": "Angaben zu Gebäude", "object": flows.BuildingDataFlow, "url": "heat:building_data"},
{"name": "Keller", "object": flows.CellarFlow, "url": "heat:cellar"},
{
"name": "Heizung & Warmwasser",
"object": flows.HotwaterHeatingFlow,
"url": "heat:hotwater_heating",
},
{
"name": "Verbrauchseingabe",
"object": flows.ConsumptionInputFlow,
"url": "heat:consumption_input",
},
{
"name": "Verbrauchsergebnis",
"object": views.ConsumptionResult,
"url": "heat:consumption_result",
},
],
},
{
"category": "2. Bestandsanalyse",
"object": views.IntroInventory,
"url": "heat:intro_inventory",
"steps": [
{"name": "Dach", "object": flows.RoofFlow, "url": "heat:roof"},
{"name": "Fenster", "object": flows.WindowFlow, "url": "heat:window"},
{"name": "Fassade", "object": flows.FacadeFlow, "url": "heat:facade"},
{"name": "Heizung", "object": flows.HeatingFlow, "url": "heat:heating"},
{"name": "PV-Anlage", "object": flows.PVSystemFlow, "url": "heat:pv_system"},
{
"name": "Lüftungsanlage",
"object": flows.VentilationSystemFlow,
"url": "heat:ventilation_system",
},
],
},
{
"category": "3. Sanierung",
"object": views.IntroRenovation,
"url": "heat:intro_renovation",
"steps": [
{
"name": "Sanierungswunsch",
"object": flows.FinancialSupporFlow,
"url": "heat:financial_support",
}, # renovation
{"name": "Förderung", "object": flows.FinancialSupporFlow, "url": "heat:financial_support"},
],
},
{
"category": "4. Ergebnisse",
"object": views.Results,
"url": "heat:results",
"steps": [
{"name": "Nächste Schritte", "object": views.NextSteps, "url": "heat:next_steps"},
],
},
]
17 changes: 8 additions & 9 deletions building_dialouge_webapp/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,15 @@
</div>
<div class="sidebar-nav pt-4">
<ul class="ps-0">
{% for item in index %}
{% if item.is_category %}
<li class="sidebar-nav__category {{ item.index_state }}">
<a href="{% url item.url %}">{{ item.name }}</a>
{% for category in index %}
<li class="sidebar-nav__category {{ category.index_state }}">
<a href="{% url category.url %}">{{ category.category }}</a>
</li>
{% for step in category.steps %}
<li class="sidebar-nav__step {{ step.index_state }}">
<a href="{% url step.url %}">{{ step.name }}</a>
</li>
{% else %}
<li class="sidebar-nav__step {{ item.index_state }}">
<a href="{% url item.url %}">{{ item.name }}</a>
</li>
{% endif %}
{% endfor %}
{% endfor %}
</ul>
</div>
Expand Down

0 comments on commit 90f90ac

Please sign in to comment.