Closed mstenta closed 4 years ago
@paul121 Awesome! Good idea to use hook_view_query_alter()
.
But now that I'm starting on adding this info to the map, I'm realizing I will need a separate helper function to make essentially the same query that Views is making.
Curious how you're thinking of approaching the map (#2) - and also curious if we could leverage Views for that as well.
It may require taking the hook_view_query_alter()
to the next level (converting it into an actual Views filter plugin). We already use Views to generate the GeoJSON layer data for other map layers - so perhaps the "restricted areas" geometry could be done in the same way - by joining in the geometries of areas referenced by the input logs. Want to discuss those ideas over in #2 and/or in chat later today?
One thought I had was showing a "Restricted until" column, but it seems too complex to calculate a timestamp AND format it as a date string in the view itself. But maybe it would be simple enough for the view to render the "restricted until" timestamp, and then alter the view to format a date string before displaying on screen?
These could be Views field plugins provided by the module - which would make them selectable options when you are building the View in the UI.
After chatting with @mstenta we decided to go forward with a custom views handler filter. I implemented this with options to filter Logs with an REI status of any
, active
, past
, or planned
. We're only using the active
status right now, but exposing this filter to the UI would allow users to view past or planned REIs which could be a nice feature down the road.
@mstenta I've taken a first pass at this by creating a View block of Input logs with active REIs. Any quick thoughts re: displayed fields, field order, etc?
A
hook_view_query_alter()
was required to limit the logs to ones with an "active" REI, taking into accounting for the REI value. The alter is a one-liner, roughly:WHERE log.timestamp >= REQUEST_TIME - rei.value * 86400
.Implementing this with a view was really quite easy - especially considering the table renders with links to the log, areas and materials "for free". But now that I'm starting on adding this info to the map, I'm realizing I will need a separate helper function to make essentially the same query that Views is making.
I think it's worth keeping the View since it does add a lot "for free" (rendering the table, links to logs, areas, materials, etc), but before we commit to this, I want to make sure using a View won't be limiting in any way. If it is, then it would make sense to design the helper function so it can serve multiple purposes.
One thought I had was showing a "Restricted until" column, but it seems too complex to calculate a timestamp AND format it as a date string in the view itself. But maybe it would be simple enough for the view to render the "restricted until" timestamp, and then alter the view to format a date string before displaying on screen?