Shopify / dashing

The exceptionally handsome dashboard framework in Ruby and Coffeescript.
http://shopify.github.com/dashing/
MIT License
10.97k stars 1.18k forks source link

Dashing.AnimatedValue not refreshing data on scheduled jobs #631

Open raphaelcazorla opened 9 years ago

raphaelcazorla commented 9 years ago

Hi,

I try the example here Works pretty well, values are being fetched from a google spreadsheet file on my gdrive.

But animated values (using widget Number, are not refresh on each tick of my job.

On the first load, it does animate the value to its actual value.

But when I change the value to display in my spreadsheet, the value is not refreshed (while the last modified message changes indeed in my number box...). When I debug via console, I actually see the value is well refreshed.

Another curious thing: If I disable the AnimatedValue in the number.coffee file, the value gets well refreshed on each tick of my job...

Help me understand what's going on...I suspect some kind of async/sync...but what I can't explain is why the value that actually changes is not reflected in the widget.

Many thanks.

scoreboard.erb in dashboards

<% content_for :title do %>Tableau de suivi des scores<% end %>
<div class="gridster">
  <ul>
    <li data-row="1" data-col="1" data-sizex="1" data-sizey="1">
      <div data-id="google_spreadsheetA" data-view="Number" data-title="Current Valuation" data-moreinfo="In billions" data-prefix="$"></div>
    </li>
  </ul>
</div>

extract of my scoreboard.rb in jobs

def authorize
  client = Google::APIClient.new(
    :application_name => 'Get Value from Google SpreadSheet for Dashing',
    :application_version => '1.0.0')

  file_storage = Google::APIClient::FileStorage.new('credential-oauth2.json')
  if file_storage.authorization.nil?
    flow = Google::APIClient::InstalledAppFlow.new(
      :client_id => ENV['GOOGLE_DRIVE_CLIENT_ID'],
      :client_secret => ENV['GOOGLE_DRIVE_CLIENT_SECRET'],
      :scope => %w(
        https://www.googleapis.com/auth/drive
        https://docs.google.com/feeds/
        https://docs.googleusercontent.com/
        https://spreadsheets.google.com/feeds/
      ),
    )
    client.authorization = flow.authorize(file_storage)
  else
    client.authorization = file_storage.authorization
  end

  client
end

SCHEDULER.every '10s', :first_in => 0 do |job|
  client = authorize
  session = GoogleDrive.login_with_oauth(client.authorization.access_token)
  ws = session.spreadsheet_by_key(ENV['DASHING_TARGET_SPREAD_SHEET_ID']).worksheets[WORKSHEET_NUMBER]

  lastA=currentA

  lastRankA=currentRankA

  currentA = ws[CELLS_ROW_NUMBER, CELLS_COLUMN_NUMBER]

  currentRankA = ws[CELLS_ROW_NUMBER, CELLS_COLUMN_NUMBER+1]

  ## output is correct ! as said previously
  puts "Tick A with #{currentA} - #{lastA} - #{currentRankA} - #{lastRankA}"

  # send_event('google_spreadsheet', { valueA: currentA, valueB: cell_valueB, valueC: cell_valueC, valueD: cell_valueD, valueE: cell_valueE, valueF: cell_valueF })
  send_event('google_spreadsheetA', { current: currentA, last: lastA, ranking: currentRankA, lastRanking: lastRankA })

end
surfi2000 commented 8 years ago

I'm having the same issue. I'm also using hotness with this. The background colour changes based on the new value but the number displayed remains the same

DeanCording commented 8 years ago

Dashing.AnimatedValue has a bug which causes it to lock up if the old and new values are the same. See #672