PREAMBLE: I have read this post which was very helpful, but my problem is slightly more advanced
Using that post I’ve managed to get dynamic query-params working that I can use in the link-to helper. I created a helper mostly as suggested (called dynamic-query-params
), and it works well. Nice!
My additional need is to send more complex POJO’s via the link-to query-params. From the /show
route I am using link-to to open a new tab target="_blank"
that points to the /print route, so that I can generate a print view of the /show but with changes for optimised print. I need the /print route to fetch the same model (except not paginated data), and apply the same config that was on the /show route. Passing this config is the issue.
It comes down to needing to do this;
{{#link-to 'reports.print' report.id (dynamic-query-params filter=filterObject sort=sortObject)}}
Print
{{/link-to}}
filterObject
and sortObject
change as the user interacts with the /show page. Examples of these two objects are;
filterObject: {
alarm_state: [1,2,3]
position: 50
}
sortObject: [{id:'asc'},{position:'desc'}]
When I perform a GET/POST query to the backend, I have extended the JSONAPI adapter to form the URL like so;
/report_data?filter[alarm_state][]=1&filter[alarm_state][]=2&filter[alarm_state][]=3&filter[position]=50&sort=id,-position&page[number]=1&page[size]=5
I want the same to occur for link-to’s query-params - what’s the best way to serialize this, and then deserialize those query-params at the /print route? Is there some kind of adapter I can modify to do the same for query-params? Should I override the link-to helper?
I can probably hack together a solution, I am just not sure of the ember-y way to do this.