0

how can i dynamically delete widgets from a job(rb) in Dashing?

I am building the dashboard dynamically by sending a data to the erb file:

<div class="gridster">
  <ul>
   <% settings.servers.each do |data| %>
       <li data-row="1" data-col="1" data-sizex="1" data-sizey="1">
         <div data-id="<%=data['webHost']%>"  data-title="<%=data['name']%>" data-version="<%=data['Version']%>"  >
      </li>
   <% end %>
</div>
lielran
  • 189
  • 1
  • 9
  • The ERB is only rendered once, on page load. You must update widgets via the EventSource connection that the Dashing JavaScript maintains. Also, you must send updates via send_event. – tylermauthe Sep 05 '15 at 23:04
  • i am sending updates via send_event for pushing data. but how can i send "delete" event to widget ? – lielran Sep 06 '15 at 05:39
  • What kind of widget is this? Are you able to add servers in this fashion without reloading the page? – tylermauthe Sep 06 '15 at 23:10
  • basic widget - title. and yes this will update the server list on run time without reloading the page – lielran Sep 19 '15 at 10:08

1 Answers1

0

Yes. I wrote a simple example job that can do just that here: http://www.mapledyne.com/ideas/2015/6/30/delete-a-dashing-dashboard-widget

You basically just want to manipulate the Sinatra::Application.settings.history variable, but the code in that link should get you most of the way to where you want to be.

Or skip the post and go right to the gist file: https://gist.github.com/mapledyne/6fb671c17c3f865309f3#file-delete-widget-rb

You can also generate parts of the erb dynamically if you don't know the widgets in the first place (more complicated), but it starts with the same - leveraging that same history variable.

  • 1
    before i submit this question i find your blog post and also tried it. it remove widgets just after a reload of the page(Ctrl+R). – lielran Sep 19 '15 at 10:09
  • lielran - Using the history variable, the widget data is removed immediately, but it may not be apparent if a dashboard is up, since there isn't a notification of this change sent to the dashboard. Refreshing the page would fix this (and, functionally, what we rely on since it works for how we use our dynamic dashboards). Someone else solved this and put it on gist: https://gist.github.com/jwalton/6616670 to send a reload from Dashing. I've not used or tested, though, but it looks promising. – Michael Knowles Sep 21 '15 at 18:17