What is the best approach to take user input before entering a route?


#1

I’m trying to do a screen with charts formed by data coming from InfluxDB (using ember 2.1.0) InfluxDB allows to tag measurements, and allows to query for those tags values. I need to fetch these tags and present them to the user prior to the actual query

For example I have:

Measurement: “Operation”. Tags: “username”. Tag values for “username”: [‘Carl’, ‘Jane’]

In order to form a query I need some input from the user:

  1. Pick start and end date
  2. Select usernames

So, in order to present option one I need to prefetch the tags from InfluxDB (ajax request), then ask the user input for option 1 and 2 and finally construct a query based on that to send again to InfluxDB. The response of this query will be passed down to a component that builds the graph.

Flow is: Navigate to route --> fetch tags from InfluxDB --> ask user for input --> send query to InfluxDB --> show chart

So, my problem is that I’m not sure how to approach this in an Ember way. I considered making a route to get the tags, and show them in a form along with date pickers for option 1. On submit, I’d pass the user input somehow (queryparams?) to a nested route where I’d form the final query for Influxdb and bring that final data. None of this seems a good solution to me. What options do I have?


#2

I would probably redirect to a subRoute that would then reach for the parentModel and other params needed for querying the rest of the data.


#3

That would be using modelFor, right?

How would this work with a user navigating directly to the child route (without previously making any selection)? Redirect to parent if no selection?


#4

As far as I know, if you directly visit the subRoute calling modelFor should not be a problem is the parent model is executed first. But yeah not having the params could cause some trouble. Doing a check in beforeModel() and redirecting could be a good solution. Alternative would be serving empty model at first and then reload() it after the params are ready or refresh() the whole route.