From 869f9a15137d1dfc69cb64efed78abc1e11b93f1 Mon Sep 17 00:00:00 2001 From: Ahmad-Wahid Date: Fri, 11 Sep 2026 01:45:33 +0200 Subject: [PATCH 1/4] api/v3_0: let num-records respect the root/depth subtree filter Context: - Issue #2518 wants the asset listings to show only top-level assets per default, which the UI does by passing depth=0. - num-records was counted from the account/type filter alone, so a listing scoped to a subtree reported every other asset as filtered out by the search. Change: - Apply filter_assets_under_root to the num-records count as well, whenever root or depth is given. Co-Authored-By: Claude Opus 5 Signed-off-by: Ahmad-Wahid --- flexmeasures/api/v3_0/assets.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/flexmeasures/api/v3_0/assets.py b/flexmeasures/api/v3_0/assets.py index 7fab5ec99e..a88e5ce490 100644 --- a/flexmeasures/api/v3_0/assets.py +++ b/flexmeasures/api/v3_0/assets.py @@ -631,9 +631,16 @@ def index( select_pagination: SelectPagination = db.paginate( query, per_page=per_page, page=page ) - num_records = db.session.scalar( - select(func.count(GenericAsset.id)).filter(filter_statement) + # `num-records` reports the size of the scope the search filter was applied to, + # so it must respect the same subtree constraint as the paginated query itself. + num_records_query = select(func.count(GenericAsset.id)).filter( + filter_statement ) + if root_asset is not None or max_depth is not None: + num_records_query = filter_assets_under_root( + query=num_records_query, root_asset=root_asset, max_depth=max_depth + ) + num_records = db.session.scalar(num_records_query) response = { "data": response_schema.dump(select_pagination.items, many=True), "num-records": num_records, From 9352df7924e258e45d1d15a772d642c71b9bee43 Mon Sep 17 00:00:00 2001 From: Ahmad-Wahid Date: Fri, 11 Sep 2026 01:47:18 +0200 Subject: [PATCH 2/4] ui/templates: list only top-level assets per default Context: - Issue #2518: an organisation's asset list is hard to scan when every sub-asset is listed alongside the sites they belong to, and you cannot narrow it down without knowing what to search for. Change: - Add a "Top-level only" checkbox, checked per default, to the asset listing on the account page and on /assets. - When checked, the listing requests depth=0, so the API returns only assets without a parent asset. - On the account page, the checkbox sits left of the one for public assets, as the issue asks. Co-Authored-By: Claude Opus 5 Signed-off-by: Ahmad-Wahid --- .../ui/templates/accounts/account.html | 23 ++++++++++++++++ flexmeasures/ui/templates/assets/assets.html | 27 +++++++++++++++++-- 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/flexmeasures/ui/templates/accounts/account.html b/flexmeasures/ui/templates/accounts/account.html index 4abf7e79ba..3842c12abd 100644 --- a/flexmeasures/ui/templates/accounts/account.html +++ b/flexmeasures/ui/templates/accounts/account.html @@ -412,6 +412,17 @@

Assets {% endif %}

+
+ +