Reputation: 1
I'm new to using ruby and Coffee script but I have managed to get as far as displaying data within a single widget.
I am trying to think logically how would one go about creating a widget for each entry from a collection.
Does anyone know how to go about creating widgets after calling a service and getting a collection of data.
For example:
entries: [
{
name: "bob",
age: 21
},
{
name: "alex",
age: 42
},
{
name: "fred",
age: 35
}
]
I want to be able go through each of these and create a widget for each of these entries. Is this possible?
Upvotes: 0
Views: 654
Reputation: 66
Here's a more full example from our zendesk widget set.
def update_dashing(view, value)
puts 'sending ' + view + ' : ' + value.to_s
send_event('zendesk-' + view, current: value, status: 'normal',
service: 'Zendesk')
end
def update_zendesk(views)
counts = zendesk_client.view_counts(ids: views, path: 'views/count_many')
counts.all do |ct|
next unless ct.fresh
update_dashing(ct.view_id.to_s, ct.value.to_i)
end
end
The zendesk_client.view_counts() function returns a list of <view_id>:<count>
pairs that we then loop through.
Upvotes: 1
Reputation: 66
This is easy enough. From any of the Ruby scripts you have in your jobs folder, you'll typically update a widget with a send_event call, like so:
send_event(widget.to_s, bus_info)
This will update the appropriate widget. A job, however, can make this call as much as is useful, so could update dozens of widgets in its run. You could just loop through your list and run send_event() for each item in your list. Play with it and if you get stuck, let me know and I can put together a bigger example, but hopefully you can use the above to get you going.
Upvotes: 1