my_dashboard 0.5.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5b4a3de86bf9412c0193837c1013ae644d810ffd
4
- data.tar.gz: e1031e3260691eeecd9388df0d3e3489dc774c1e
3
+ metadata.gz: c38526e7f894d0e46e9d11c665e8b1bdbaef1719
4
+ data.tar.gz: 39d40a9513598287e1eb8075123646057790c051
5
5
  SHA512:
6
- metadata.gz: 4d0fe4aed124531c1f18d61f5caa65b74d2fdbf8d81b121fa89782ac09c2ca00584f0774793e3206cc615c53ae8a057dd63a9c671febbc39cb64bd6fdc5ed0b5
7
- data.tar.gz: 802f6e13dcaf60a7d08b392e61bdb01cf0200439ed497b1d62d740e621358d7a822aa65ab86cb4e7bee8e6abd8ad7070ad06a1c1463513826b611e590c8d76f3
6
+ metadata.gz: d7a048cbf4d36cae5a064cd84138a6478f4aabfe342fcf6ed8923e9202c1eb1c930f9ee9451b6e0c4f1ebae218e07569225c4b24b30a303161768269d639a648
7
+ data.tar.gz: 50d183b1b22149eadf7bb55966b23033b99ca5c4689b3a687b65fd7c94058fb936cc1b9e0dd50e9a2d89cabaffbee80a6545da2ed206c215811fee27539db749
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.5.1 (05/17/2016)
2
+
3
+ * Fix problem with my_dashboard generator batmanjs integration
4
+
1
5
  ## 0.5.0 (05/17/2016)
2
6
 
3
7
  * Add Batman.js for generate templates
@@ -1,3 +1,3 @@
1
1
  module MyDashboard
2
- VERSION = '0.5.0'
2
+ VERSION = '0.5.1'
3
3
  end
@@ -0,0 +1,127 @@
1
+ Batman.config.pathPrefix = '/'
2
+ Batman.config.viewPrefix = '/my_dashboard/widgets/'
3
+
4
+ Batman.Filters.prettyNumber = (num) ->
5
+ num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",") unless isNaN(num)
6
+
7
+ Batman.Filters.dashize = (str) ->
8
+ dashes_rx1 = /([A-Z]+)([A-Z][a-z])/g;
9
+ dashes_rx2 = /([a-z\d])([A-Z])/g;
10
+
11
+ return str.replace(dashes_rx1, '$1_$2').replace(dashes_rx2, '$1_$2').replace(/_/g, '-').toLowerCase()
12
+
13
+ Batman.Filters.shortenedNumber = (num) ->
14
+ return num if isNaN(num)
15
+ if num >= 1000000000
16
+ (num / 1000000000).toFixed(1) + 'B'
17
+ else if num >= 1000000
18
+ (num / 1000000).toFixed(1) + 'M'
19
+ else if num >= 1000
20
+ (num / 1000).toFixed(1) + 'K'
21
+ else
22
+ num
23
+
24
+ class window.MyDashboard extends Batman.App
25
+ @on 'reload', (data) ->
26
+ window.location.reload(true)
27
+
28
+ @root ->
29
+ MyDashboard.params = Batman.URI.paramsFromQuery(window.location.search.slice(1));
30
+
31
+ class MyDashboard.Widget extends Batman.View
32
+ constructor: ->
33
+ # Set the view path
34
+ @constructor::source = Batman.Filters.underscore(@constructor.name)
35
+ super
36
+
37
+ @mixin($(@node).data())
38
+ MyDashboard.widgets[@id] ||= []
39
+ MyDashboard.widgets[@id].push(@)
40
+
41
+ type = Batman.Filters.dashize(@view)
42
+ $(@node).addClass("widget widget-#{type} #{@id}")
43
+
44
+ @accessor 'updatedAtMessage', ->
45
+ if updatedAt = @get('updatedAt')
46
+ timestamp = new Date(updatedAt * 1000)
47
+ hours = timestamp.getHours()
48
+ minutes = ("0" + timestamp.getMinutes()).slice(-2)
49
+ "Last updated at #{hours}:#{minutes}"
50
+
51
+ @::on 'ready', ->
52
+ MyDashboard.Widget.fire 'ready'
53
+
54
+ # In case the events from the server came before the widget was rendered
55
+ lastData = MyDashboard.lastEvents[@id]
56
+ if lastData
57
+ @mixin(lastData)
58
+ @onData(lastData)
59
+
60
+ receiveData: (data) =>
61
+ @mixin(data)
62
+ @onData(data)
63
+
64
+ onData: (data) =>
65
+ # Widgets override this to handle incoming data
66
+
67
+ MyDashboard.AnimatedValue =
68
+ get: Batman.Property.defaultAccessor.get
69
+ set: (k, to) ->
70
+ if !to? || isNaN(to)
71
+ @[k] = to
72
+ else
73
+ timer = "interval_#{k}"
74
+ num = if (!isNaN(@[k]) && @[k]?) then @[k] else 0
75
+ unless @[timer] || num == to
76
+ to = parseFloat(to)
77
+ num = parseFloat(num)
78
+ up = to > num
79
+ num_interval = Math.abs(num - to) / 90
80
+ @[timer] =
81
+ setInterval =>
82
+ num = if up then Math.ceil(num+num_interval) else Math.floor(num-num_interval)
83
+ if (up && num > to) || (!up && num < to)
84
+ num = to
85
+ clearInterval(@[timer])
86
+ @[timer] = null
87
+ delete @[timer]
88
+ @[k] = num
89
+ @set k, to
90
+ , 10
91
+ @[k] = num
92
+
93
+ MyDashboard.widgets = widgets = {}
94
+ MyDashboard.lastEvents = lastEvents = {}
95
+ MyDashboard.debugMode = false
96
+
97
+ source = new EventSource('/my_dashboard/events')
98
+ source.addEventListener 'open', (e) ->
99
+ console.log("Connection opened", e)
100
+
101
+ source.addEventListener 'error', (e)->
102
+ console.log("Connection error", e)
103
+ if (e.currentTarget.readyState == EventSource.CLOSED)
104
+ console.log("Connection closed")
105
+ setTimeout (->
106
+ window.location.reload()
107
+ ), 5*60*1000
108
+
109
+ source.addEventListener 'message', (e) ->
110
+ data = JSON.parse(e.data)
111
+ if lastEvents[data.id]?.updatedAt != data.updatedAt
112
+ if MyDashboard.debugMode
113
+ console.log("Received data for #{data.id}", data)
114
+ lastEvents[data.id] = data
115
+ if widgets[data.id]?.length > 0
116
+ for widget in widgets[data.id]
117
+ widget.receiveData(data)
118
+
119
+ source.addEventListener 'dashboards', (e) ->
120
+ data = JSON.parse(e.data)
121
+ if MyDashboard.debugMode
122
+ console.log("Received data for dashboards", data)
123
+ if data.dashboard is '*' or window.location.pathname is "/#{data.dashboard}"
124
+ MyDashboard.fire data.event, data
125
+
126
+ $(document).ready ->
127
+ MyDashboard.run()
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: my_dashboard
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danilo Vaz