we have a few inhouse systems which track our processes and we would like to export it as json or csv on demand to give it to controlling. we use rummage for the search / sort / pagination and it works great, but i have to write to
write an export for every custom listview. i wondered if there is a general approach / lib for that?
ideally its a button on the bottom of every template “get this list as json/csv” with minimal extra code. i would write it but i dont know how to put it in a seperate reusable module yet.
for example i feel dirty to have to call view functions from the controller then, and to have to write similar code 2 times, so i thought maybe there is code for that
Why would you write similar code twice? The way I see it, you would have a controller whose only job is to export files, something like Web.ExportController with a single action, export/2. It would receive the resource for which to export files as a param and
Collect your data, render as json/csv with some lib, and send_resp/3 with appropriate headers set.
As for
call view functions from the controller
you already do it with render/3.
Could you provide some code that achieves what you want and maybe someone around here would then help you make it more idiomatic? It’s a bit difficult for me to understand what you mean exactly … I’m afraid we are just speaking past each other right now.
because the export controller would need to call the view functions as well, for example a date_format. i will post the code but will take 1-2 weeks before i can continue with this projects. thanks!