Skip to content

Instantly share code, notes, and snippets.

@tonyklawrence
Created November 22, 2013 09:02
Show Gist options
  • Save tonyklawrence/7596983 to your computer and use it in GitHub Desktop.
Save tonyklawrence/7596983 to your computer and use it in GitHub Desktop.
Workitems
class Dashing.Workitems extends Dashing.Widget
@accessor 'current', Dashing.AnimatedValue
onData: (data) ->
if data.status
$(@get('node')).attr 'class', (i,c) -> c.replace /\bstatus-\S+/g, ''
$(@get('node')).addClass "status-#{data.status}"
// ----------------------------------------------------------------------------
// Sass declarations
// ----------------------------------------------------------------------------
$background-color: #00bb00;
$value-color: #fff;
$title-color: rgba(255, 255, 255, 0.7);
$moreinfo-color: rgba(255, 255, 255, 0.7);
// ----------------------------------------------------------------------------
// Widget-number styles
// ----------------------------------------------------------------------------
.widget-workitems {
background-color: $background-color;
.title {
color: $title-color;
}
.value {
color: $value-color;
}
.more-info {
color: $moreinfo-color;
}
.updated-at {
color: rgba(0, 0, 0, 0.3);
}
}
require 'net/http'
require 'json'
app1 = 'http://host1/api/open/openSupportWorkItems.json'
app2 = 'http://host2/openapi/dashboard/workitems/open'
SCHEDULER.every '30s' do
send_event('workitems-app1', workitems(app1))
send_event('workitems-app2', workitems(app2))
end
def workitems(url)
begin
response = Net::HTTP.get(URI(url))
count = JSON.parse(response)['open']
status = case count
when 0 then { count: count, status: 'ok' }
else { count: count, status: 'warning' }
end
rescue Exception
{ count: -1, status: 'danger' }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment