From 16f51fd9dc454b26d9866b080caa17ffe2f8ce27 Mon Sep 17 00:00:00 2001 From: Daniel Beauchamp Date: Mon, 13 Aug 2012 23:36:38 -0400 Subject: Updated to use sprockets! Ah, much cleaner. --- javascripts/dashing.coffee | 96 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 javascripts/dashing.coffee (limited to 'javascripts/dashing.coffee') diff --git a/javascripts/dashing.coffee b/javascripts/dashing.coffee new file mode 100644 index 0000000..2d9953d --- /dev/null +++ b/javascripts/dashing.coffee @@ -0,0 +1,96 @@ +#= require jquery +#= require es5-shim +#= require batman +#= require batman.jquery + + +Batman.Filters.prettyNumber = (num) -> + num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",") unless isNaN(num) + +Batman.Filters.dashize = (str) -> + dashes_rx1 = /([A-Z]+)([A-Z][a-z])/g; + dashes_rx2 = /([a-z\d])([A-Z])/g; + + return str.replace(dashes_rx1, '$1_$2').replace(dashes_rx2, '$1_$2').replace('_', '-').toLowerCase() + +Batman.Filters.shortenedNumber = (num) -> + return if isNaN(num) + if num >= 1000000000 + (num / 1000000000).toFixed(1) + 'B' + else if num >= 1000000 + (num / 1000000).toFixed(1) + 'M' + else if num >= 1000 + (num / 1000).toFixed(1) + 'K' + else + num + +class window.Dashing extends Batman.App + @root -> + +class Dashing.Widget extends Batman.View + constructor: -> + # Set the view path + @constructor::source = Batman.Filters.underscore(@constructor.name) + super + + @mixin($(@node).data()) + Dashing.widgets[@id] ||= [] + Dashing.widgets[@id].push(@) + @mixin(Dashing.lastEvents[@id]) # in case the events from the server came before the widget was rendered + + type = Batman.Filters.dashize(@view) + $(@node).addClass("widget widget-#{type} #{@id}") + + + @::on 'ready', -> + Dashing.Widget.fire 'ready' + + onData: (data) => + @mixin(data) + + +Dashing.AnimatedValue = + get: Batman.Property.defaultAccessor.get + set: (k, to) -> + if isNaN(to) + @[k] = to + else + timer = "interval_#{k}" + num = if !isNaN(@[k]) then @[k] else 0 + unless @[timer] || num == to + up = to > num + num_interval = Math.abs(num - to) / 90 + @[timer] = + setInterval => + num = if up then Math.ceil(num+num_interval) else Math.floor(num-num_interval) + if (up && num > to) || (!up && num < to) + num = to + clearInterval(@[timer]) + @[timer] = null + delete @[timer] + @[k] = num + @set k, to + @[k] = num + +Dashing.widgets = widgets = {} +Dashing.lastEvents = lastEvents = {} + +source = new EventSource('/events') +source.addEventListener 'open', (e) -> + console.log("Connection opened") + +source.addEventListener 'error', (e)-> + console.log("Connection error") + if (e.readyState == EventSource.CLOSED) + console.log("Connection closed") + +source.addEventListener 'message', (e) => + data = JSON.parse(e.data) + lastEvents[data.id] = data + if widgets[data.id]?.length > 0 + for widget in widgets[data.id] + widget.onData(data) + + +$(document).ready -> + Dashing.run() -- cgit v1.2.3 From c3ccc8f11619bc1d182d6c7e73ce160699ff27c7 Mon Sep 17 00:00:00 2001 From: Daniel Beauchamp Date: Fri, 24 Aug 2012 15:50:12 -0400 Subject: You no longer need to call 'super' inside your onData callbacks for widgets. Also, every widget now has a 'updatedAt' property that gets updated when data comes in. --- javascripts/dashing.coffee | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'javascripts/dashing.coffee') diff --git a/javascripts/dashing.coffee b/javascripts/dashing.coffee index 2d9953d..d3bf519 100644 --- a/javascripts/dashing.coffee +++ b/javascripts/dashing.coffee @@ -45,9 +45,13 @@ class Dashing.Widget extends Batman.View @::on 'ready', -> Dashing.Widget.fire 'ready' - onData: (data) => + receiveData: (data) => @mixin(data) + @set 'updatedAt', new Date() + @onData(data) + onData: (data) => + # Widgets override this to handle incoming data Dashing.AnimatedValue = get: Batman.Property.defaultAccessor.get @@ -89,7 +93,7 @@ source.addEventListener 'message', (e) => lastEvents[data.id] = data if widgets[data.id]?.length > 0 for widget in widgets[data.id] - widget.onData(data) + widget.receiveData(data) $(document).ready -> -- cgit v1.2.3 From 372ee8475ef9b685e8cd3b8dea2e0475d5a4bd6b Mon Sep 17 00:00:00 2001 From: Daniel Beauchamp Date: Fri, 24 Aug 2012 17:58:43 -0400 Subject: Keep track of updatedAt server side, instead of on widgets. --- javascripts/dashing.coffee | 1 - 1 file changed, 1 deletion(-) (limited to 'javascripts/dashing.coffee') diff --git a/javascripts/dashing.coffee b/javascripts/dashing.coffee index d3bf519..61c3fbe 100644 --- a/javascripts/dashing.coffee +++ b/javascripts/dashing.coffee @@ -47,7 +47,6 @@ class Dashing.Widget extends Batman.View receiveData: (data) => @mixin(data) - @set 'updatedAt', new Date() @onData(data) onData: (data) => -- cgit v1.2.3 From a4f10ed0084f2eb3801a64fc8ea8e8fea8e2540d Mon Sep 17 00:00:00 2001 From: Daniel Beauchamp Date: Fri, 24 Aug 2012 18:33:10 -0400 Subject: Widgets now have a formatted 'updatedAtMessage'. For stuff like 'Last updated at 18:00' --- javascripts/dashing.coffee | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'javascripts/dashing.coffee') diff --git a/javascripts/dashing.coffee b/javascripts/dashing.coffee index 61c3fbe..964cf2c 100644 --- a/javascripts/dashing.coffee +++ b/javascripts/dashing.coffee @@ -41,6 +41,10 @@ class Dashing.Widget extends Batman.View type = Batman.Filters.dashize(@view) $(@node).addClass("widget widget-#{type} #{@id}") + @accessor 'updatedAtMessage', -> + if updatedAt = @get('updatedAt') + timestamp = updatedAt.toString().match(/\d*:\d*/)[0] + "Last updated at #{timestamp}" @::on 'ready', -> Dashing.Widget.fire 'ready' -- cgit v1.2.3 From a3d84c8c0a30f5b761c37f6f2c805346d0009acd Mon Sep 17 00:00:00 2001 From: Daniel Beauchamp Date: Mon, 17 Sep 2012 11:16:31 -0400 Subject: Added a debug mode that lets you see all messages coming in. --- javascripts/dashing.coffee | 3 +++ 1 file changed, 3 insertions(+) (limited to 'javascripts/dashing.coffee') diff --git a/javascripts/dashing.coffee b/javascripts/dashing.coffee index 964cf2c..528ae2c 100644 --- a/javascripts/dashing.coffee +++ b/javascripts/dashing.coffee @@ -81,6 +81,7 @@ Dashing.AnimatedValue = Dashing.widgets = widgets = {} Dashing.lastEvents = lastEvents = {} +Dashing.debugMode = false source = new EventSource('/events') source.addEventListener 'open', (e) -> @@ -93,6 +94,8 @@ source.addEventListener 'error', (e)-> source.addEventListener 'message', (e) => data = JSON.parse(e.data) + if Dashing.debugMode + console.log("Received data for #{data.id}", data) lastEvents[data.id] = data if widgets[data.id]?.length > 0 for widget in widgets[data.id] -- cgit v1.2.3 From fe7880e018efe9b5db271c7b11f3469891d1b2b2 Mon Sep 17 00:00:00 2001 From: Daniel Beauchamp Date: Mon, 17 Sep 2012 13:55:18 -0400 Subject: Updated the animated setter to better work with null values. --- javascripts/dashing.coffee | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'javascripts/dashing.coffee') diff --git a/javascripts/dashing.coffee b/javascripts/dashing.coffee index 528ae2c..8852c1e 100644 --- a/javascripts/dashing.coffee +++ b/javascripts/dashing.coffee @@ -59,12 +59,14 @@ class Dashing.Widget extends Batman.View Dashing.AnimatedValue = get: Batman.Property.defaultAccessor.get set: (k, to) -> - if isNaN(to) + if !to? || isNaN(to) @[k] = to else timer = "interval_#{k}" - num = if !isNaN(@[k]) then @[k] else 0 + num = if (!isNaN(@[k]) && @[k]?) then @[k] else 0 unless @[timer] || num == to + to = parseFloat(to) + num = parseFloat(num) up = to > num num_interval = Math.abs(num - to) / 90 @[timer] = -- cgit v1.2.3 From 3a77d19282f2055559c63468c574b824138464ac Mon Sep 17 00:00:00 2001 From: Daniel Beauchamp Date: Thu, 11 Oct 2012 16:20:05 -0400 Subject: Provide a way to get the query params given to a dashboard. --- javascripts/dashing.coffee | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'javascripts/dashing.coffee') diff --git a/javascripts/dashing.coffee b/javascripts/dashing.coffee index 8852c1e..6d1b5cc 100644 --- a/javascripts/dashing.coffee +++ b/javascripts/dashing.coffee @@ -25,7 +25,8 @@ Batman.Filters.shortenedNumber = (num) -> num class window.Dashing extends Batman.App - @root -> + @root -> +Dashing.params = Batman.URI.paramsFromQuery(window.location.search.slice(1)); class Dashing.Widget extends Batman.View constructor: -> -- cgit v1.2.3 From a4a4564f760bb1bcd541366186cd46488d5a569b Mon Sep 17 00:00:00 2001 From: Daniel Beauchamp Date: Tue, 30 Oct 2012 05:16:35 -0400 Subject: Added new widgets, and made them more flexible. Ready for 0.1.3! --- javascripts/dashing.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'javascripts/dashing.coffee') diff --git a/javascripts/dashing.coffee b/javascripts/dashing.coffee index 6d1b5cc..d6d7e22 100644 --- a/javascripts/dashing.coffee +++ b/javascripts/dashing.coffee @@ -14,7 +14,7 @@ Batman.Filters.dashize = (str) -> return str.replace(dashes_rx1, '$1_$2').replace(dashes_rx2, '$1_$2').replace('_', '-').toLowerCase() Batman.Filters.shortenedNumber = (num) -> - return if isNaN(num) + return num if isNaN(num) if num >= 1000000000 (num / 1000000000).toFixed(1) + 'B' else if num >= 1000000 -- cgit v1.2.3 From 837cf50007ef8cbd7ec017d4e8cb67adc5725568 Mon Sep 17 00:00:00 2001 From: Daniel Beauchamp Date: Wed, 14 Nov 2012 12:18:25 -0500 Subject: Set explicit delay for AnimatedNumber filter. Firefox doesn't run SetInterval unless there is a delay specified. Closes #6 --- javascripts/dashing.coffee | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'javascripts/dashing.coffee') diff --git a/javascripts/dashing.coffee b/javascripts/dashing.coffee index d6d7e22..6662725 100644 --- a/javascripts/dashing.coffee +++ b/javascripts/dashing.coffee @@ -70,7 +70,7 @@ Dashing.AnimatedValue = num = parseFloat(num) up = to > num num_interval = Math.abs(num - to) / 90 - @[timer] = + @[timer] = setInterval => num = if up then Math.ceil(num+num_interval) else Math.floor(num-num_interval) if (up && num > to) || (!up && num < to) @@ -80,7 +80,8 @@ Dashing.AnimatedValue = delete @[timer] @[k] = num @set k, to - @[k] = num + , 10 + @[k] = num Dashing.widgets = widgets = {} Dashing.lastEvents = lastEvents = {} -- cgit v1.2.3 From c39be899b629378c0a4e1dd4beab528ebcbffa6e Mon Sep 17 00:00:00 2001 From: Scott Gerring Date: Sat, 3 Nov 2012 13:18:40 +0800 Subject: Display 'last updated' using user's locale. Closes #10 --- javascripts/dashing.coffee | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'javascripts/dashing.coffee') diff --git a/javascripts/dashing.coffee b/javascripts/dashing.coffee index 6662725..faf21a0 100644 --- a/javascripts/dashing.coffee +++ b/javascripts/dashing.coffee @@ -44,8 +44,10 @@ class Dashing.Widget extends Batman.View @accessor 'updatedAtMessage', -> if updatedAt = @get('updatedAt') - timestamp = updatedAt.toString().match(/\d*:\d*/)[0] - "Last updated at #{timestamp}" + timestamp = new Date(updatedAt * 1000) + hours = timestamp.getHours() + minutes = ("0" + timestamp.getMinutes()).slice(-2) + "Last updated at #{hours}:#{minutes}" @::on 'ready', -> Dashing.Widget.fire 'ready' -- cgit v1.2.3 From efc78f648a76ccc9421e3fc0a16e9f6c6448b346 Mon Sep 17 00:00:00 2001 From: Tim Santeford Date: Thu, 6 Dec 2012 01:10:48 -0800 Subject: Prevents duplicate widget event notifications --- javascripts/dashing.coffee | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'javascripts/dashing.coffee') diff --git a/javascripts/dashing.coffee b/javascripts/dashing.coffee index faf21a0..ebf5c0a 100644 --- a/javascripts/dashing.coffee +++ b/javascripts/dashing.coffee @@ -100,12 +100,13 @@ source.addEventListener 'error', (e)-> source.addEventListener 'message', (e) => data = JSON.parse(e.data) - if Dashing.debugMode - console.log("Received data for #{data.id}", data) - lastEvents[data.id] = data - if widgets[data.id]?.length > 0 - for widget in widgets[data.id] - widget.receiveData(data) + if lastEvents[data.id]?.updatedAt != data.updatedAt + if Dashing.debugMode + console.log("Received data for #{data.id}", data) + lastEvents[data.id] = data + if widgets[data.id]?.length > 0 + for widget in widgets[data.id] + widget.receiveData(data) $(document).ready -> -- cgit v1.2.3 From 3f58bbd626cd84d1cb24375b4d8fe6df75ce85ba Mon Sep 17 00:00:00 2001 From: Pieter van de Bruggen Date: Sun, 4 Nov 2012 17:10:36 -0800 Subject: Adding application messaging. While widgets are the most common target for events, there is good reason to sometimes target the application as a whole. This patch adds support for such events using the /-prefixed notation. (This convention is safe for use since it represents an extremely uncommon widget ID, and one which data could not be POSTed to.) Such events are NOT subject to replay, and are handled on the client-side by firing corresponding events on the Dashing application class. As a proof of concept (and to fufill a feature request), this patch also introduces a POST /reload endpoint, which when provided with a valid authkey (and optionally a dashboard name) fires the appropriate 'reload' event on all of the loaded dashboards. The 'reload' event handler then reloads the dashboard, unless a different dashboard was specified. --- javascripts/dashing.coffee | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'javascripts/dashing.coffee') diff --git a/javascripts/dashing.coffee b/javascripts/dashing.coffee index ebf5c0a..f90c14b 100644 --- a/javascripts/dashing.coffee +++ b/javascripts/dashing.coffee @@ -25,6 +25,12 @@ Batman.Filters.shortenedNumber = (num) -> num class window.Dashing extends Batman.App + @on 'reload', (data) -> + if data.dashboard? + location.reload() if window.location.pathname is "/#{data.dashboard}" + else + location.reload() + @root -> Dashing.params = Batman.URI.paramsFromQuery(window.location.search.slice(1)); @@ -83,7 +89,6 @@ Dashing.AnimatedValue = @[k] = num @set k, to , 10 - @[k] = num Dashing.widgets = widgets = {} Dashing.lastEvents = lastEvents = {} @@ -98,9 +103,13 @@ source.addEventListener 'error', (e)-> if (e.readyState == EventSource.CLOSED) console.log("Connection closed") -source.addEventListener 'message', (e) => +source.addEventListener 'message', (e) -> data = JSON.parse(e.data) if lastEvents[data.id]?.updatedAt != data.updatedAt + # /messages are internal messages, and cannot correspond to widgets. + # We will handle them as events on the Dashing application. + return Dashing.fire(data.id.slice(1), data) if data.id[0] is '/' + if Dashing.debugMode console.log("Received data for #{data.id}", data) lastEvents[data.id] = data -- cgit v1.2.3 From 5f8cbcb7debde027e79d87733b84cb852aa47dad Mon Sep 17 00:00:00 2001 From: Chad Jolly Date: Sun, 14 Jul 2013 18:36:19 -0600 Subject: dashboard events - use SSE event names --- javascripts/dashing.coffee | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'javascripts/dashing.coffee') diff --git a/javascripts/dashing.coffee b/javascripts/dashing.coffee index f90c14b..c4178f3 100644 --- a/javascripts/dashing.coffee +++ b/javascripts/dashing.coffee @@ -106,10 +106,6 @@ source.addEventListener 'error', (e)-> source.addEventListener 'message', (e) -> data = JSON.parse(e.data) if lastEvents[data.id]?.updatedAt != data.updatedAt - # /messages are internal messages, and cannot correspond to widgets. - # We will handle them as events on the Dashing application. - return Dashing.fire(data.id.slice(1), data) if data.id[0] is '/' - if Dashing.debugMode console.log("Received data for #{data.id}", data) lastEvents[data.id] = data @@ -117,6 +113,11 @@ source.addEventListener 'message', (e) -> for widget in widgets[data.id] widget.receiveData(data) +source.addEventListener 'dashboards', (e) -> + data = JSON.parse(e.data) + if Dashing.debugMode + console.log("Received data for dashboards", data) + Dashing.fire data.event, data $(document).ready -> Dashing.run() -- cgit v1.2.3 From 60dcd73bac913afe0a49b6c6c07b709aa288fd7d Mon Sep 17 00:00:00 2001 From: Chad Jolly Date: Sat, 20 Jul 2013 14:09:51 -0600 Subject: only fire dashboard events when target is current dashboard * send event to all dashboards by including {"dashboard": "*"} in payload * reload event forces reload from server, no caching --- javascripts/dashing.coffee | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'javascripts/dashing.coffee') diff --git a/javascripts/dashing.coffee b/javascripts/dashing.coffee index c4178f3..5712e98 100644 --- a/javascripts/dashing.coffee +++ b/javascripts/dashing.coffee @@ -26,10 +26,7 @@ Batman.Filters.shortenedNumber = (num) -> class window.Dashing extends Batman.App @on 'reload', (data) -> - if data.dashboard? - location.reload() if window.location.pathname is "/#{data.dashboard}" - else - location.reload() + window.location.reload(true) @root -> Dashing.params = Batman.URI.paramsFromQuery(window.location.search.slice(1)); @@ -89,6 +86,7 @@ Dashing.AnimatedValue = @[k] = num @set k, to , 10 + @[k] = num Dashing.widgets = widgets = {} Dashing.lastEvents = lastEvents = {} @@ -117,7 +115,8 @@ source.addEventListener 'dashboards', (e) -> data = JSON.parse(e.data) if Dashing.debugMode console.log("Received data for dashboards", data) - Dashing.fire data.event, data + if data.dashboard is '*' or window.location.pathname is "/#{data.dashboard}" + Dashing.fire data.event, data $(document).ready -> Dashing.run() -- cgit v1.2.3 From 8e14229951405d18d1e206c2dabaeeb7644a42e0 Mon Sep 17 00:00:00 2001 From: David Rubin Date: Thu, 8 Aug 2013 11:25:07 +0200 Subject: Handle widgets with multiple capital letters This change allows widgets to have names like AwesomeWidgetYes and it will be given awesome-widget-yes instead of awesome-widget_yes --- javascripts/dashing.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'javascripts/dashing.coffee') diff --git a/javascripts/dashing.coffee b/javascripts/dashing.coffee index 5712e98..d24bf54 100644 --- a/javascripts/dashing.coffee +++ b/javascripts/dashing.coffee @@ -11,7 +11,7 @@ Batman.Filters.dashize = (str) -> dashes_rx1 = /([A-Z]+)([A-Z][a-z])/g; dashes_rx2 = /([a-z\d])([A-Z])/g; - return str.replace(dashes_rx1, '$1_$2').replace(dashes_rx2, '$1_$2').replace('_', '-').toLowerCase() + return str.replace(dashes_rx1, '$1_$2').replace(dashes_rx2, '$1_$2').replace(/_/g, '-').toLowerCase() Batman.Filters.shortenedNumber = (num) -> return num if isNaN(num) -- cgit v1.2.3 From 99c64d55067fb301910a6626f3bbd2ce8ab30a6d Mon Sep 17 00:00:00 2001 From: micpango Date: Wed, 28 Aug 2013 15:23:58 +0200 Subject: Make relative to allow running on sub-path --- javascripts/dashing.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'javascripts/dashing.coffee') diff --git a/javascripts/dashing.coffee b/javascripts/dashing.coffee index d24bf54..ee4b6d4 100644 --- a/javascripts/dashing.coffee +++ b/javascripts/dashing.coffee @@ -92,7 +92,7 @@ Dashing.widgets = widgets = {} Dashing.lastEvents = lastEvents = {} Dashing.debugMode = false -source = new EventSource('/events') +source = new EventSource('events') source.addEventListener 'open', (e) -> console.log("Connection opened") -- cgit v1.2.3 From e11d3c270c297ba6de2fbc685c74bd67455c83fb Mon Sep 17 00:00:00 2001 From: John Tajima Date: Fri, 30 Aug 2013 16:53:59 +0000 Subject: Fixes event connection close error never re-establishes connection. Fix EventListener connection close check. console log the event on error and connection. Reload current page on connection close error event. --- javascripts/dashing.coffee | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'javascripts/dashing.coffee') diff --git a/javascripts/dashing.coffee b/javascripts/dashing.coffee index ee4b6d4..235a965 100644 --- a/javascripts/dashing.coffee +++ b/javascripts/dashing.coffee @@ -94,12 +94,15 @@ Dashing.debugMode = false source = new EventSource('events') source.addEventListener 'open', (e) -> - console.log("Connection opened") + console.log("Connection opened", e) source.addEventListener 'error', (e)-> - console.log("Connection error") - if (e.readyState == EventSource.CLOSED) + console.log("Connection error", e) + if (e.currentTarget.readyState == EventSource.CLOSED) console.log("Connection closed") + setTimeout (-> + window.location.reload() + ), 10000 source.addEventListener 'message', (e) -> data = JSON.parse(e.data) -- cgit v1.2.3 From 7b4cc3e123eefc82674ff7ea68d127dc5a84779e Mon Sep 17 00:00:00 2001 From: John Tajima Date: Tue, 3 Sep 2013 13:35:31 +0000 Subject: change reload to 5 minutes --- javascripts/dashing.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'javascripts/dashing.coffee') diff --git a/javascripts/dashing.coffee b/javascripts/dashing.coffee index 235a965..fa677e8 100644 --- a/javascripts/dashing.coffee +++ b/javascripts/dashing.coffee @@ -102,7 +102,7 @@ source.addEventListener 'error', (e)-> console.log("Connection closed") setTimeout (-> window.location.reload() - ), 10000 + ), 5*60*1000 source.addEventListener 'message', (e) -> data = JSON.parse(e.data) -- cgit v1.2.3 From 628242b7c8d749d01b40d5d0cc23bb5da5843029 Mon Sep 17 00:00:00 2001 From: BX017301 Date: Thu, 16 Jan 2014 12:21:11 -0600 Subject: Update lastEvents if a widget exists. --- javascripts/dashing.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'javascripts/dashing.coffee') diff --git a/javascripts/dashing.coffee b/javascripts/dashing.coffee index fa677e8..e5875d8 100644 --- a/javascripts/dashing.coffee +++ b/javascripts/dashing.coffee @@ -109,8 +109,8 @@ source.addEventListener 'message', (e) -> if lastEvents[data.id]?.updatedAt != data.updatedAt if Dashing.debugMode console.log("Received data for #{data.id}", data) - lastEvents[data.id] = data if widgets[data.id]?.length > 0 + lastEvents[data.id] = data for widget in widgets[data.id] widget.receiveData(data) -- cgit v1.2.3 From 6914d99bda53f7732988a61b639165b54d9b8cfd Mon Sep 17 00:00:00 2001 From: Adam Byrtek Date: Tue, 24 Feb 2015 20:18:14 +0000 Subject: Trigger onData on widget initialization --- javascripts/dashing.coffee | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'javascripts/dashing.coffee') diff --git a/javascripts/dashing.coffee b/javascripts/dashing.coffee index e5875d8..c66128d 100644 --- a/javascripts/dashing.coffee +++ b/javascripts/dashing.coffee @@ -40,7 +40,12 @@ class Dashing.Widget extends Batman.View @mixin($(@node).data()) Dashing.widgets[@id] ||= [] Dashing.widgets[@id].push(@) - @mixin(Dashing.lastEvents[@id]) # in case the events from the server came before the widget was rendered + + # In case the events from the server came before the widget was rendered + lastData = Dashing.lastEvents[@id] + if lastData + @mixin(lastData) + @onData(lastData) type = Batman.Filters.dashize(@view) $(@node).addClass("widget widget-#{type} #{@id}") -- cgit v1.2.3 From e18a162b663e5e0a924d3a884ad1c64f75e8cf8d Mon Sep 17 00:00:00 2001 From: Adam Byrtek Date: Tue, 24 Feb 2015 20:57:59 +0000 Subject: Store last events for all widgets Even the ones that haven't been initialized yet. --- javascripts/dashing.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'javascripts/dashing.coffee') diff --git a/javascripts/dashing.coffee b/javascripts/dashing.coffee index c66128d..f41a279 100644 --- a/javascripts/dashing.coffee +++ b/javascripts/dashing.coffee @@ -114,8 +114,8 @@ source.addEventListener 'message', (e) -> if lastEvents[data.id]?.updatedAt != data.updatedAt if Dashing.debugMode console.log("Received data for #{data.id}", data) + lastEvents[data.id] = data if widgets[data.id]?.length > 0 - lastEvents[data.id] = data for widget in widgets[data.id] widget.receiveData(data) -- cgit v1.2.3 From c49e181cdb13d3357d76759e5311746ffe00f281 Mon Sep 17 00:00:00 2001 From: Adam Byrtek Date: Tue, 24 Feb 2015 21:00:13 +0000 Subject: Send last event data when a widget is ready --- javascripts/dashing.coffee | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'javascripts/dashing.coffee') diff --git a/javascripts/dashing.coffee b/javascripts/dashing.coffee index f41a279..20a9987 100644 --- a/javascripts/dashing.coffee +++ b/javascripts/dashing.coffee @@ -41,12 +41,6 @@ class Dashing.Widget extends Batman.View Dashing.widgets[@id] ||= [] Dashing.widgets[@id].push(@) - # In case the events from the server came before the widget was rendered - lastData = Dashing.lastEvents[@id] - if lastData - @mixin(lastData) - @onData(lastData) - type = Batman.Filters.dashize(@view) $(@node).addClass("widget widget-#{type} #{@id}") @@ -60,6 +54,12 @@ class Dashing.Widget extends Batman.View @::on 'ready', -> Dashing.Widget.fire 'ready' + # In case the events from the server came before the widget was rendered + lastData = Dashing.lastEvents[@id] + if lastData + @mixin(lastData) + @onData(lastData) + receiveData: (data) => @mixin(data) @onData(data) -- cgit v1.2.3