forked from enviPath/enviPy
The scenarios lists both in /scenarios and /package/<id>/scenario no longer show related scenarios (children).
All related scenarios are shown on the scenario page under Related Scenarios if there are any.
<img width="500" alt="{C2D38DED-A402-4A27-A241-BC2302C62A50}.png" src="attachments/1371c177-220c-42d5-94ff-56f9fbab761f">
Co-authored-by: Tim Lorsbach <tim@lorsba.ch>
Reviewed-on: enviPath/enviPy#323
Co-authored-by: Liam Brydon <lbry121@aucklanduni.ac.nz>
Co-committed-by: Liam Brydon <lbry121@aucklanduni.ac.nz>
This commit is contained in:
@ -12,7 +12,11 @@ from epdb.models import Scenario
|
||||
from epdb.logic import PackageManager
|
||||
from epdb.views import _anonymous_or_real
|
||||
from ..pagination import EnhancedPageNumberPagination
|
||||
from ..schemas import ReviewStatusFilter, ScenarioOutSchema, ScenarioCreateSchema
|
||||
from ..schemas import (
|
||||
ScenarioOutSchema,
|
||||
ScenarioCreateSchema,
|
||||
ScenarioReviewStatusAndRelatedFilter,
|
||||
)
|
||||
from ..dal import get_user_entities_for_read, get_package_entities_for_read
|
||||
from envipy_additional_information import registry
|
||||
|
||||
@ -25,11 +29,12 @@ router = Router()
|
||||
@paginate(
|
||||
EnhancedPageNumberPagination,
|
||||
page_size=s.API_PAGINATION_DEFAULT_PAGE_SIZE,
|
||||
filter_schema=ReviewStatusFilter,
|
||||
filter_schema=ScenarioReviewStatusAndRelatedFilter,
|
||||
)
|
||||
def list_all_scenarios(request):
|
||||
user = request.user
|
||||
return get_user_entities_for_read(Scenario, user).order_by("name").all()
|
||||
items = get_user_entities_for_read(Scenario, user)
|
||||
return items.order_by("name").all()
|
||||
|
||||
|
||||
@router.get(
|
||||
@ -39,11 +44,12 @@ def list_all_scenarios(request):
|
||||
@paginate(
|
||||
EnhancedPageNumberPagination,
|
||||
page_size=s.API_PAGINATION_DEFAULT_PAGE_SIZE,
|
||||
filter_schema=ReviewStatusFilter,
|
||||
filter_schema=ScenarioReviewStatusAndRelatedFilter,
|
||||
)
|
||||
def list_package_scenarios(request, package_uuid: UUID):
|
||||
user = request.user
|
||||
return get_package_entities_for_read(Scenario, package_uuid, user).order_by("name").all()
|
||||
items = get_package_entities_for_read(Scenario, package_uuid, user)
|
||||
return items.order_by("name").all()
|
||||
|
||||
|
||||
@router.post("/package/{uuid:package_uuid}/scenario/", response=ScenarioOutSchema)
|
||||
|
||||
@ -22,6 +22,12 @@ class StructureReviewStatusFilter(FilterSchema):
|
||||
review_status: Annotated[Optional[bool], FilterLookup("compound__package__reviewed")] = None
|
||||
|
||||
|
||||
class ScenarioReviewStatusAndRelatedFilter(ReviewStatusFilter):
|
||||
"""Filter schema for review_status and parent query parameter."""
|
||||
|
||||
exclude_related: Annotated[Optional[bool], FilterLookup("parent__isnull")] = None
|
||||
|
||||
|
||||
# Base schema for all package-scoped entities
|
||||
class PackageEntityOutSchema(Schema):
|
||||
"""Base schema for entities belonging to a package."""
|
||||
|
||||
@ -3962,8 +3962,12 @@ class Scenario(EnviPathModel):
|
||||
yield inst
|
||||
|
||||
def related_pathways(self):
|
||||
scens = [self]
|
||||
if self.parent is not None:
|
||||
scens.append(self.parent)
|
||||
|
||||
return Pathway.objects.filter(
|
||||
scenarios__in=[self], package__reviewed=True, package=self.package
|
||||
scenarios__in=scens, package__reviewed=True, package=self.package
|
||||
).distinct()
|
||||
|
||||
|
||||
|
||||
@ -2479,6 +2479,8 @@ def package_scenario(request, package_uuid, scenario_uuid):
|
||||
context["breadcrumbs"] = breadcrumbs(current_package, "scenario", current_scenario)
|
||||
|
||||
context["scenario"] = current_scenario
|
||||
# Get scenarios that have current_scenario as a parent
|
||||
context["children"] = current_scenario.scenario_set.order_by("name")
|
||||
|
||||
# Note: Modals now fetch schemas and data from API endpoints
|
||||
# Keeping these for backwards compatibility if needed elsewhere
|
||||
|
||||
@ -98,7 +98,7 @@
|
||||
class="mt-6"
|
||||
x-show="activeTab === 'reviewed' && !isEmpty"
|
||||
x-data="remotePaginatedList({
|
||||
endpoint: '{{ api_endpoint }}?review_status=true',
|
||||
endpoint: '{{ api_endpoint }}?review_status=true{% if entity_type == 'scenario' %}&exclude_related=true{% endif %}',
|
||||
instanceId: '{{ entity_type }}_reviewed',
|
||||
isReviewed: true,
|
||||
perPage: {{ per_page|default:50 }}
|
||||
@ -113,7 +113,7 @@
|
||||
class="mt-6"
|
||||
x-show="activeTab === 'unreviewed' && !isEmpty"
|
||||
x-data="remotePaginatedList({
|
||||
endpoint: '{{ api_endpoint }}?review_status=false',
|
||||
endpoint: '{{ api_endpoint }}?review_status=false{% if entity_type == 'scenario' %}&exclude_related=true{% endif %}',
|
||||
instanceId: '{{ entity_type }}_unreviewed',
|
||||
isReviewed: false,
|
||||
perPage: {{ per_page|default:50 }}
|
||||
|
||||
@ -171,6 +171,82 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% if scenario.parent %}
|
||||
<div class="card bg-base-100">
|
||||
<div class="card-body">
|
||||
<h3 class="card-title mb-4 text-lg">
|
||||
Parent Scenario Additional Information
|
||||
</h3>
|
||||
<div
|
||||
x-data="{
|
||||
items: [],
|
||||
schemas: {},
|
||||
loading: true,
|
||||
error: null,
|
||||
async init() {
|
||||
try {
|
||||
// Use the unified API client for loading data
|
||||
const { items, schemas } = await window.AdditionalInformationApi.loadSchemasAndItems('{{ scenario.parent.uuid }}');
|
||||
this.items = items;
|
||||
this.schemas = schemas;
|
||||
} catch (err) {
|
||||
this.error = err.message;
|
||||
console.error('Error loading additional information:', err);
|
||||
} finally {
|
||||
this.loading = false;
|
||||
}
|
||||
},
|
||||
}"
|
||||
>
|
||||
<!-- Loading state -->
|
||||
<template x-if="loading">
|
||||
<div class="flex items-center justify-center p-4">
|
||||
<span class="loading loading-spinner loading-md"></span>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- Error state -->
|
||||
<template x-if="error">
|
||||
<div class="alert alert-error mb-4">
|
||||
<span x-text="error"></span>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- Items list -->
|
||||
<template x-if="!loading && !error">
|
||||
<div class="space-y-4">
|
||||
<template x-if="items.length === 0">
|
||||
<p class="text-base-content/60">
|
||||
No additional information available.
|
||||
</p>
|
||||
</template>
|
||||
|
||||
<template x-for="item in items" :key="item.uuid">
|
||||
<div class="card bg-base-200 shadow-sm">
|
||||
<div class="card-body p-4">
|
||||
<div class="flex items-start justify-between">
|
||||
<div
|
||||
class="flex-1"
|
||||
x-data="schemaRenderer({
|
||||
rjsf: schemas[item.type.toLowerCase()],
|
||||
data: item.data,
|
||||
mode: 'view'
|
||||
})"
|
||||
x-init="init()"
|
||||
>
|
||||
{% include "components/schema_form.html" %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<!-- Pathways -->
|
||||
{% if scenario.related_pathways %}
|
||||
<div class="collapse-arrow bg-base-200 collapse">
|
||||
@ -189,6 +265,43 @@
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<!-- Related Scenarios -->
|
||||
{% if children.exists %}
|
||||
<div class="collapse-arrow bg-base-200 collapse">
|
||||
<input type="checkbox" />
|
||||
<div class="collapse-title text-xl font-medium">Related Scenarios</div>
|
||||
<div class="collapse-content">
|
||||
<ul class="menu bg-base-100 rounded-box">
|
||||
{% for s in children %}
|
||||
<li>
|
||||
<a href="{{ s.url }}" class="hover:bg-base-200"
|
||||
>{{ s.name }} <i>({{ s.package.name }})</i></a
|
||||
>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<!-- Parent Scenarios -->
|
||||
{% if scenario.parent %}
|
||||
<div class="collapse-arrow bg-base-200 collapse">
|
||||
<input type="checkbox" />
|
||||
<div class="collapse-title text-xl font-medium">Parent Scenario</div>
|
||||
<div class="collapse-content">
|
||||
<ul class="menu bg-base-100 rounded-box">
|
||||
<li>
|
||||
<a href="{{ scenario.parent.url }}" class="hover:bg-base-200"
|
||||
>{{ scenario.parent.name }}
|
||||
<i>({{ scenario.parent.package.name }})</i></a
|
||||
>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<script>
|
||||
|
||||
Reference in New Issue
Block a user