From 49f727b75d002cde98868fc5a1f3cb6beb09edb6 Mon Sep 17 00:00:00 2001 From: Anton Tranelis Date: Tue, 11 Nov 2025 20:16:10 +0100 Subject: [PATCH] show past items --- app/src/pages/MapContainer.tsx | 35 ++++++++------- .../snapshot/fields/layers/showPastItems.json | 45 +++++++++++++++++++ lib/src/types/LayerProps.d.ts | 1 + 3 files changed, 66 insertions(+), 15 deletions(-) create mode 100644 backend/directus-config/development/snapshot/fields/layers/showPastItems.json diff --git a/app/src/pages/MapContainer.tsx b/app/src/pages/MapContainer.tsx index d3317a0a..4bf983a4 100644 --- a/app/src/pages/MapContainer.tsx +++ b/app/src/pages/MapContainer.tsx @@ -39,28 +39,33 @@ function MapContainer({ layers, map }: { layers: LayerProps[]; map: any }) { // get timestamp for the end of the current day const now = new Date() const startOfDay = new Date(now.getFullYear(), now.getMonth(), now.getDate()) - const etartOfDayISO = startOfDay.toISOString() + const startOfDayISO = startOfDay.toISOString() layers.map((layer: LayerProps) => { + // Only apply date filter if showPastItems is not explicitly set to true + const dateFilter = layer.showPastItems + ? undefined + : { + _or: [ + { + end: { + _gt: startOfDayISO, + }, + }, + { + end: { + _null: true, + }, + }, + ], + } + apis && setApis((current) => [ ...current, { id: layer.id, - api: new itemsApi('items', layer.id, undefined, { - _or: [ - { - end: { - _gt: etartOfDayISO, - }, - }, - { - end: { - _null: true, - }, - }, - ], - }), + api: new itemsApi('items', layer.id, undefined, dateFilter), }, ]) }) diff --git a/backend/directus-config/development/snapshot/fields/layers/showPastItems.json b/backend/directus-config/development/snapshot/fields/layers/showPastItems.json new file mode 100644 index 00000000..0d8bfe7a --- /dev/null +++ b/backend/directus-config/development/snapshot/fields/layers/showPastItems.json @@ -0,0 +1,45 @@ +{ + "collection": "layers", + "field": "showPastItems", + "type": "boolean", + "meta": { + "collection": "layers", + "conditions": null, + "display": null, + "display_options": null, + "field": "showPastItems", + "group": null, + "hidden": false, + "interface": "boolean", + "note": null, + "options": null, + "readonly": false, + "required": false, + "sort": 19, + "special": [ + "cast-boolean" + ], + "translations": null, + "validation": null, + "validation_message": null, + "width": "full" + }, + "schema": { + "name": "showPastItems", + "table": "layers", + "data_type": "boolean", + "default_value": false, + "max_length": null, + "numeric_precision": null, + "numeric_scale": null, + "is_nullable": true, + "is_unique": false, + "is_indexed": false, + "is_primary_key": false, + "is_generated": false, + "generation_expression": null, + "has_auto_increment": false, + "foreign_key_table": null, + "foreign_key_column": null + } +} diff --git a/lib/src/types/LayerProps.d.ts b/lib/src/types/LayerProps.d.ts index d7fe65d3..1707ba6a 100644 --- a/lib/src/types/LayerProps.d.ts +++ b/lib/src/types/LayerProps.d.ts @@ -26,4 +26,5 @@ export interface LayerProps { listed?: boolean item_presets?: Record item_default_name?: string + showPastItems?: boolean }