Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@KingScooty
Forked from chelsea/README.md
Last active January 31, 2018 17:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KingScooty/bc9cd8a1d1a368d2323687713a271806 to your computer and use it in GitHub Desktop.
Save KingScooty/bc9cd8a1d1a368d2323687713a271806 to your computer and use it in GitHub Desktop.
Random Aww

Description

Dashing widget to display a random cute picture from http://reddit.com/r/aww

The display of the widget is heavily based on the Image widget, however it does not prepend the src with 'assets' which allows for external images.

Settings

You can set a placeholder image in the event that reddit is down, or otherwise unresponse. This is set at the top of random_aww.rb as follows:

placeholder = '/assets/nyantocat.gif'

This can be an image in /assets/images, or a full path to a remotely hosted image.

Usage

To use this widget, copy random_aww.html, random_aww.coffee, and random_aww.scss into the /widgets/random_aww directory. Put the random_aww.rb file in your /jobs folder.

To include the widget in a dashboard, add the following snippet to the dashboard layout file:

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

Preview

Preview

class Dashing.RandomAww extends Dashing.Widget
ready: ->
# This is fired when the widget is done being rendered
onData: (data) ->
# Handle incoming data
# You can access the html node of this widget with `@node`
# Example: $(@node).fadeOut().fadeIn() will make the node flash each time data comes in.
<h1 data-id="status" data-bind-style="statusText"></h1>
require 'net/http'
require 'json'
placeholder = '/assets/nyantocat.gif'
SCHEDULER.every '60s', first_in: 0 do |job|
http = Net::HTTP.new('nginx-proxy1.dev.web.eu-west-1.traveljigsaw.net')
response = http.request(Net::HTTP::Get.new("/health/aggregator"))
json = JSON.parse(response)
if json.count <= 0
send_event('aww', image: placeholder)
else
send_event('status', statusText: "#{json.status}")
end
end
// ----------------------------------------------------------------------------
// Sass declarations
// ----------------------------------------------------------------------------
$background-color: #2d2e29;
// ----------------------------------------------------------------------------
// Widget-image styles
// ----------------------------------------------------------------------------
.widget-random-aww {
background-color: $background-color;
.image_container {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
background-size: cover;
background-position: center;
background-repeat: no-repeat;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment