I am creating a time blocking app, and I want to only show sessions that start after the current time.
While I can get the page to do that on load, as the time changes, I would like the page to remove sessions whose start times become after the current time as the time passes their start time.
e.g. a session is due to start at 4.20. I load the page at 4.15 and the session is visible. When it gets to 4.21, the 4.20 session disappears.
which provides me with sessions up to 5 minutes late. This doesnât refresh with time, so when the time passes, if I donât reload the page, then sessions I want to have disappeared are still visible.
Sessions are stored with a start time, and that start time is displayed.
I have tried adding a condition on the group within the repeating group, but it doesnât seems to automatically cause the group to disappear when the start time (+5 minutes) has passed:
I have now tried the workflow âDo every 5 secondsâ - âRefresh pageâ
This is working, but every 5 seconds, the page disappears and reappears. Is there a way to refresh the page (or get the old data to disappear) in a way that doesnât make the page blink?
A very similar question to this came up here in the forum recently with a few valid suggestions for a solutionâŚ.
But basically, you need to update the time every second (or every 5 seconds, or whatever), but you donât want to be doing a new database search every time you do that or it will cost a lot of WUâŚ
So one solution was to load a large set of data to the page first, and the filter it client side based on the real-time time variable.
Obviously, whether that will work in your case will depend on many specifics of your app and data, but it might be one option (probably the one Iâd recommend).
I like the idea of filtering it client side, but how do I get the filtering to happen in real time?
I have tried putting in a condition that the information only shows when the start time (+5 minutes) is greater than the current time, but that only seems to update when the page refreshes, rather than automatically as the time changes.
You just need to update the current date/time in real time (i.e. every second) and use that value in your filter.
There must be a thousand forum posts on how to do that - but to summarise, you can use a group with a Date content-type, or a custom state of type Date, and run a do every x seconds workflow to update it.
Or you can use some custom JavaScript with setInterval to output the date value (or use one of the several plugins that do this for you).
In any case, the end result is the same - the current date/time kept up to date in real-time.
You can then use that value as a constraint in your client-side filtering of the data which youâll have already loaded to the page (just make sure you have already loaded it to the page - otherwise youâll be doing a fresh database search every second which will consume a lot of WUs).
Loading the data, I presume the following loads all the data?
I have a repeating group, type Period, data source Search for Periods (filtered for the current user, etc)
++++
For the constraint, I have used a conditional for visibility - does this reference that date/time though, or some other? Or am I supposed to reference the current date/time some other way?
That doesnât work⌠(although I can see why you might think it would)âŚ
you actually have to set the current date/time every seconds using a âDisplay Dataâ action, rather then âReset Dataâ (which just resets it to its original value, which was set when the group was first loaded).
Loading the data, I presume the following loads all the data?
If thatâs the data youâre intending to load, then yes - but just make sure you donât include any date/time constraints relating to the real-time date value in the search.
Then just refer to that RGâs list of things in the main RG you using (although it might be better to use a custom state rather than a RG to load the initial data).
For the constraint, I have used a conditional for visibility - does this reference that date/time though, or some other? Or am I supposed to reference the current date/time some other way?
A conditional wonât work here⌠you need to use a constraint on a filter of the initial data.
So, lets assume youâre loading the initial data into a custom state (presumably all those which start after the current date/time, or maybe just some of those, depending on the size of your database)âŚ
Then, in your RG, set the data source to that custom stateâs value: filtered - then set the start time constraint according to the real-time data value (not the current date/time).
Hmm, ok, so I have tried that, but I am getting the error that I must both display data, and that the data to display should be empty, which makes no sense to meâŚ
Have you defined the content-type of Date on the Group? (certainly, it looks like you havenât from the issue checker message).
What am I doing wrong? Why would adding a custom state stop the page from working, or am I setting the custom state wrong?
It shouldnât make any difference, so if thatâs the case it must be something else thatâs wrong (although in your screenshot youâre not setting any value to the custom state at all).
but if I am filtering my search of them to include only those that start after the current date/time, surely I would be doing just that?
NoâŚ
If you put the constraint on the search, then the search will be repeated every second.
Iâm saying DONâT do that.
Instead, apply a filter to the data thatâs already on the page (in the custom state), so you only do the search once, and then filter the results client-side.
Iâm not sure what you mean. Which group are you suggesting I set content type to date? Do you mean the custom state?
I thought I was setting the custom state to be my list of periods / sessions? Setting the custom state to be a list of dates gives me this error, presumably because I need the list of sessions to be somewhereâŚ
No I donât mean Custom State⌠I mean content-type. If youâre using a group for this then you need to set the content-type of that Group to Date before you can display Date data in it. (although you could use a Custom State instead for this, it really makes no difference).
I thought I was setting the custom state to be my list of periods / sessions?
Maybe you thought you were⌠but (at least in the screenshot you posted) you havenât set anything.
Obviously, if you RG is intended to show a list of Periods, the data source must be a list of PeriodsâŚ
So I canât really work out what youâre trying to do from that screenshot? (the Custom State youâre showing is a list of Dates? - what is that for? and how does it relate to anything here?)
I have set my countdown element to type date, which seems to have removed the error (although I havenât tested it yet because setting the state still breaks the page) .
I see - I had set its value, and that stopped the page from working; so I then took away its value (the screenshot shows that) and the page still doesnât work.
Either way, putting the set state instruction into the page stops the page from doing anything when I try to open the popup. Could it be interacting with something else? Certainly the page work until I try to set that state, it is only once I put that instruction in that the page ceases to functionâŚ
Ok, so I have got my list of sessions loaded into a custom state.
I have a countdown timer counting down to the start of the first session.
I cannot seem to get the page to update the information when the current time passes the session start time. When the countdown gets to zero (i.e. the 1st sessionâs start time is the current time), no matter what I do, the 1st session stays there rather than being replaced with the next session, and the countdown stubbornly refuses to restart.
the list of sessions, which is set by workflow every time the page reloads
the current date / time, which is set by workflow every 1 second
I needed a filter to make everything on the page show as it should. That filter is an advanced one, looking to the current date / time within the custom state.
E.g. start countdown with an end date of the the first sessionâs start time, and the filter to determine which is the first session is:
Advanced: current date / time custom state < this sessionâs start time.
My repeating groups used the same advanced filter.