summaryrefslogtreecommitdiff
path: root/templates/project/widgets/number/number.coffee
blob: aa7cf8b295cb7e15d7d7006e44e5175d34269cf2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
class AllTheThings.Number extends AllTheThings.Widget
  source: 'number'

  @accessor 'current', Batman.Property.EasingSetter

  ready: ->

  @accessor 'difference', ->
    if @get('last')
      last = parseInt(@get('last'))
      current = parseInt(@get('current'))
      if last != 0
        diff = Math.abs(Math.round((current - last) / last * 100))
        "#{diff}%"

  @accessor 'arrow', ->
    if @get('last')
      if parseInt(@get('current')) > parseInt(@get('last')) then 'icon-arrow-up' else 'icon-arrow-down'

  @accessor 'statusStyle', ->
    "status-#{@get('status')}"

  @accessor 'needsAttention', ->
    @get('status') == 'warning' || @get('status') == 'danger'

  onData: (data) ->
    super
    if data.status
      $(@get('node')).addClass("status-#{data.status}")