diff --git a/building_dialouge_webapp/heat/flows.py b/building_dialouge_webapp/heat/flows.py index f9948d4..26f0b0a 100644 --- a/building_dialouge_webapp/heat/flows.py +++ b/building_dialouge_webapp/heat/flows.py @@ -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" diff --git a/building_dialouge_webapp/heat/navigation.py b/building_dialouge_webapp/heat/navigation.py index 6b5daaf..23f05ca 100644 --- a/building_dialouge_webapp/heat/navigation.py +++ b/building_dialouge_webapp/heat/navigation.py @@ -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 @@ -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"}, + ], + }, ] diff --git a/building_dialouge_webapp/templates/base.html b/building_dialouge_webapp/templates/base.html index f75f0f4..b28932b 100644 --- a/building_dialouge_webapp/templates/base.html +++ b/building_dialouge_webapp/templates/base.html @@ -99,16 +99,15 @@