0

I've been beating my head against this issue for a bit and am looking for some help. I have a Dashing Wallboard that has been working great. I am trying to add a widget that shows a list of data, but no data ever shows up in the widget nor the history.yml file.

The rest of my widgets are pulling data from the same SQL server, that's why the connection information is omitted below:

I have the following code in my .rb job file:

results = client.execute("
  SELECT [data] as name, [data2] as value
  FROM [DB]
  Where [Conditions]
  GROUP BY [Tier];
")

   datalist = results.map do |row|
      row = {
        :label => row['name'],
        :value => row['value']
      }
    end     
send_event('listofdata', { items: datalist } )  

My dashboard widget looks like this:

<li data-row="2" data-col="3" data-sizex="1" data-sizey="2">
  <div data-id="listofdata" data-view="List" data-title="This is a list of data" data-unordered="true"></div>
</li>   

The output from my SQL query looks like this:

Tier 1  10
Tier2   6
Tier 3  31

The data types are varchar and int. I did include spaces and no spaces in the name column to show that the results of the query do contains spaces.

I have also tried doing the ruby side like this but it still didn't work.

results.each do |row|
    send_event('listofdata', { label: row['name'], value: row['value'] })  
end 

No matter what I seem to do, I can't get any data to show in the widget. Am I missing something incredibly obvious here?

Update 1: Tried also with this, didn't work:

datalist = results.each(:symbolize_keys => true, :as => :array, :cache_rows => true, :empty_sets => true) do |rowset| end

data_count = Array.new

for j in (0...results.affected_rows)
    data_count << {"label" => datalist[j].at(0), "value" => datalist[j].at(1).to_i}
end
mikeyeg
  • 28
  • 5
  • this looks a bit weird to me: `datalist = results.map do |row| row = { ... }` i believe you are trying to make a hash from the results but the contents of your datalist after that block is probably not what you expect. – Kimmo Lehto Feb 09 '16 at 19:27
  • also you could try to create a `send_event('listofdata', ...)` command with handcrafted data not from the database, such as `send_event('listofdata', { items: [ { label: 'test label', value: 'test value' }, { label: 'test label 2', 'test value 2' }] })` – Kimmo Lehto Feb 09 '16 at 19:53
  • Thanks for the comments kimmmo. I tried with your code and it still did not show data in the list widget. I believe the issue might relate to the way the hash is getting created and what the List widget is expecting. I created a standalone ruby script that queries the data and puts the hash to the screen. It appears to be in a different format than what dashing is looking for. – mikeyeg Feb 09 '16 at 20:47

1 Answers1

0

It appeared to be a conflict with the column names and the hash keys. This is confirmed working:

results = client.execute("
  SELECT CAST([data] as varchar) as name, CAST([data2] as int) as count
  FROM [DB]
  Where [Conditions]
  GROUP BY [Tier];
")

   datalist = results.map do |row|
      row = {
        :label => row['name'],
        :value => row['count']
      }
    end     
send_event('listofdata', { items: datalist } )  
mikeyeg
  • 28
  • 5