Skip to content

Instantly share code, notes, and snippets.

@jwalton
Last active October 13, 2022 07:03
Show Gist options
  • Save jwalton/6616670 to your computer and use it in GitHub Desktop.
Save jwalton/6616670 to your computer and use it in GitHub Desktop.
Remote-reload widget for Dashing

So, you made a change to your dashboard, and now you have to run all over the building, plugging in a keyboard, and reloading the dashboard on the various TVs in your office. What if you could reload all the dashboard from the comfort of your desk?

Add this widget to the very bottom of your dashboard, after the "gridster" div:

<div class="gridster">
  <ul>
    <li data-row="1" data-col="1" data-sizex="1" data-sizey="1">
      <div data-view="Image" data-image="/benbria/loop.png" style="background-color:#666766"></div>
    </li>

    <!-- Blah blah blah - widgets go here -->

  </ul>
</div>

<!-- Special reload widget, doesn't display on the page. -->
<div data-id="reload" data-view="RemoteReload" style="padding: 0px"></div>

Note the style="padding: 0px"; this is important to make the widget take up no space on the page. Now you can use curl to remotely force all dashboards to reload their page:

curl -d '{ "auth_token": "YOUR_AUTH_TOKEN" }' \http://mydashboard.server.com/widgets/reload

You can also install this across all your dashboards by modifying layout.erb:

<div id="container">
  <%= yield %>
  <div data-id="reload" data-view="RemoteReload" style="padding: 0px"></div>
</div>
class Dashing.RemoteReload extends Dashing.Widget
# Wait a short while between reloads. Sometimes dashing will send a `onData()` event
# right when we startup, so without this we can get into a reload-forever loop.
minTimesBetweenReload: 1000 * 5 # 5 seconds
ready: ->
@lastLoad = Date.now()
@initialized = true
# Handle new data from Dashing.
onData: (data) ->
if !@initialized or (Date.now() < (@lastLoad + @minTimesBetweenReload))
console.log "Too soon to reload. Wait #{(@lastLoad + @minTimesBetweenReload - Date.now()) / 1000} seconds."
else if data.url
location.replace(data.url)
else
location.reload()
<!-- This file intentionally left blank -->
@jorgemorgado
Copy link

Here is a tip that will make this widget much simpler. Create a new file in the widget's directory like:

.widget-remote-reload {
  display: none !important;
  padding: 0px;
}

Now, remove the style attribute from the div tag when calling the widget. Simple and effective.

Copy link

ghost commented Mar 31, 2016

How do i get this to work? I get the following when trying to use CURL from Windows...

c:\cURL\bin>curl -d '{ "auth_token": "MyTokenHere" }' \http://MyIPHere:3030/widgets/reload
curl: (6) Could not resolve host: auth_token
curl: (6) Could not resolve host: MyTokenHere
curl: (3) [globbing] unmatched close brace/bracket in column 1
curl: (1) Protocol "\http" not supported or disabled in libcurl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment