Rerender dashboard stats if new is available.

This commit is contained in:
Martin Edenhofer 2015-09-08 13:42:03 +02:00
parent cc50022773
commit f67b7d2f73
3 changed files with 28 additions and 15 deletions

View file

@ -1,16 +1,16 @@
class App.DashboardStats extends App.Controller class App.DashboardStats extends App.Controller
constructor: -> constructor: ->
super super
@load()
@bind('dashboard_stats_rebuild', @load)
load: =>
stats_store = App.StatsStore.first() stats_store = App.StatsStore.first()
if stats_store if stats_store
@render(stats_store.data) @render(stats_store.data)
else else
@render() @render()
# bind to rebuild view event
@bind('dashboard_stats_rebuild', @render)
render: (data = {}) -> render: (data = {}) ->
if !data.TicketResponseTime if !data.TicketResponseTime
data.TicketResponseTime = data.TicketResponseTime =
@ -63,7 +63,7 @@ class App.DashboardStats extends App.Controller
if data.TicketResponseTime if data.TicketResponseTime
@renderWidgetClockFace data.TicketResponseTime.handling_time @renderWidgetClockFace data.TicketResponseTime.handling_time
renderWidgetClockFace: (time) => renderWidgetClockFace: (time, max_time = 60) =>
canvas = @el.find 'canvas' canvas = @el.find 'canvas'
ctx = canvas.get(0).getContext '2d' ctx = canvas.get(0).getContext '2d'
radius = 26 radius = 26
@ -73,14 +73,14 @@ class App.DashboardStats extends App.Controller
canvas.attr 'width', 2 * radius canvas.attr 'width', 2 * radius
canvas.attr 'height', 2 * radius canvas.attr 'height', 2 * radius
time = 60 if time > 60 time = max_time if time > max_time
handlingTimeColors = handlingTimeColors = {}
5: '#38AE6A' # supergood handlingTimeColors[max_time/12] = '#38AE6A' # supergood
10: '#A9AC41' # good handlingTimeColors[max_time/6] = '#A9AC41' # good
15: '#FAAB00' # ok handlingTimeColors[max_time/4] = '#FAAB00' # ok
20: '#F6820B' # bad handlingTimeColors[max_time/3] = '#F6820B' # bad
25: '#F35910' # superbad handlingTimeColors[max_time/2] = '#F35910' # superbad
for handlingTime, timeColor of handlingTimeColors for handlingTime, timeColor of handlingTimeColors
if time <= handlingTime if time <= handlingTime
@ -88,6 +88,7 @@ class App.DashboardStats extends App.Controller
break break
# 30% background # 30% background
if time isnt 0
ctx.globalAlpha = 0.3 ctx.globalAlpha = 0.3
ctx.fillStyle = backgroundColor ctx.fillStyle = backgroundColor
ctx.beginPath() ctx.beginPath()
@ -100,7 +101,7 @@ class App.DashboardStats extends App.Controller
ctx.beginPath() ctx.beginPath()
ctx.moveTo radius, radius ctx.moveTo radius, radius
arcsector = Math.PI * 2 * time/60 arcsector = Math.PI * 2 * time/max_time
ctx.arc radius, radius, radius, -Math.PI/2, arcsector - Math.PI/2, false ctx.arc radius, radius, radius, -Math.PI/2, arcsector - Math.PI/2, false
ctx.lineTo radius, radius ctx.lineTo radius, radius
ctx.closePath() ctx.closePath()

View file

@ -68,7 +68,7 @@ class StatsStore < ApplicationModel
if item if item
item.data = data item.data = data
item.save item.save
return true return item
end end
# lookups # lookups

View file

@ -71,12 +71,24 @@ returns
data.each {|backend, result| data.each {|backend, result|
data_for_user[backend.to_app_model] = result data_for_user[backend.to_app_model] = result
} }
StatsStore.sync( state_store = StatsStore.sync(
object: 'User', object: 'User',
o_id: user_id, o_id: user_id,
key: 'dashboard', key: 'dashboard',
data: data_for_user, data: data_for_user,
) )
message = {
event: 'resetCollection',
data: {
state_store.class.to_app_model => [state_store],
},
}
Sessions.send_to(user_id, message)
event = {
event: 'dashboard_stats_rebuild',
}
Sessions.send_to(user_id, event)
} }
true true