3

Working with dashing.io to make some awesome dashboards. I understand that dashing was build with ruby and sinatra and uses .erb files in a specific directory to make dashboards.

I have no issues setting up dashing or getting info into my dashboards with the .erb jobs.

What I'm trying to do is use a variable passed from the uri string in one of my dashboard .erb files. The dashboard directory also has a layout.erb file that looks like the template and this is what I'm trying to put:

<% group = params["apps"] %>

However this gives me an error in sinatra. Ideally I'd like to add a uri parameter to change the dashboard. So I'd like to hit my instance of dashing running at sample.com:3030/mydashboard add a uri parameter sample.com:3030/mydashboard?apps=group1

<li data-row="1" data-col="1" data-sizex="1" data-sizey="1">
    <div data-id="<% group %>" data-view="List" </div>
</li>

and use that to dynamically create my erb file as such:

<li data-row="1" data-col="1" data-sizex="1" data-sizey="1">
    <div data-id="group1" data-view="List" </div>
</li>

I started looking at erb layouts on sinatras docs but with so many different technologies meshed together here, I'm not sure the order of how the page is built and at what point or file I would need to make these changes.

UPDATE:

I thought I was making some progress, I forked the gem and altered this line in the app.rb file:

get '/:dashboard/' do

to

get '/:dashboard/group/' do

which allows me to use this in my dashboards to get the url parameter <%= params[:group] %> but this seems to break the dashboards. Gridster still shows the widget boxes but no data. This seems to be breaking the view/[widget].html from being resolvable, as I'm getting a resource not found.

Community
  • 1
  • 1
Ryan Litwiller
  • 445
  • 5
  • 23

2 Answers2

2

This has been addressed in an issue in dashing repo itself.

As you've used in your code, erb files get access to params from sinatra. So it's simple as

<li data-row="1" data-col="1" data-sizex="1" data-sizey="1">
    <div data-id="<%= params[:app] %>" data-view="List" </div>
</li>

And if you hit it with

sample.com:3030/mydashboard?apps=group1

data-id will be taken as group1.

If you're feeling adventures, You can configure custom routes like those in the UPDATE part.

The following links will give you enough information to do that

How dashboards are accessed with routes
How routing works in sinatra

Even if so many technologies are meshed up in dashing, you just need to look in to routing in sinatra and how it is used in dashing

sudo bangbang
  • 19,198
  • 7
  • 64
  • 71
1

The answer to this was much simpler then trying to meddle with the dashing gem, and was very close to my original attempts. Thanks to nauoa65 at fiverr!

This is what I needed in my dashboard's erb, this answer is on the sample.erb dashboard.

<!-- The parameter should come from http://sample.com:3030/sample?apps=mytestparam -->
<% group = params[:apps] || "A default value if parameter is not set" %>

<!-- The equal sign outputs the content of variable to html -->
<%= group %>
Ryan Litwiller
  • 445
  • 5
  • 23