Hi there,
I’m currently working with a setup where:
- Each customer has 1+ “sites” (i.e. locations, facilities, etc.)
- Each site has 1+ devices
The sites are implemented as user groups that are nested underneath the the customer. I’d like to be able to display the number of devices per site for a given customer. I’ve thought of a few ways of doing this and would like to know which is the idiomatic way using Losant.
1) AJAX calls with JS
For this one I had loaded a customer and then used the ID to fetch all of the devices. I could then loop over them and build up an object that mapped a location to the number of devices (which could be determined by tags). While this is straight forward, I don’t like having to use JS to then manipulate the DOM
2) Manually associate devices with sites
What I like about this solution is that it’s pretty simple. The devices are loaded when I fetch a user, so I can then template them in use Handlebars. What I don’t like is that I have to manually associate devices with subgroups – this won’t scale, and doesn’t make use of tags (which is the recommended way in Losant)
3) Build an Object in a Workflow
The idea here is:
- Create an object
- Given a particular user:
- Find all subgroups
- For each subgroup:
- Create a key with the subgroup name, and then a value which is the number of devices for said subgroup (i.e. site)
I found this to be really hard to do using the Workflow system, and gave up part way through. That may be me not knowing which nodes to reach for, though. If this is feasible, then it seems it’d be the right option as I could just use it as an Experience Page’s workflow.
Thanks in advance! I’m sure there are other possible solutions that I’ve missed.