Subscribe to pusher channels only when entering the MainRoute
We don't want to subscribe if we're at any other routes, because there is no data there. The main target is to avoid all of the notifications from a common channel if we're on the /dashboard route.
This commit is contained in:
parent
a891892bd8
commit
5065bb5739
|
@ -21,7 +21,6 @@ $.extend Travis.Pusher.prototype,
|
|||
Pusher.warn = @warn.bind(this)
|
||||
Pusher.host = config.host if config.host
|
||||
@pusher = new Pusher(config.key, encrypted: Travis.Pusher.ENCRYPTED, disableStats: true)
|
||||
@subscribeAll(Travis.Pusher.CHANNELS) if Travis.Pusher.CHANNELS
|
||||
|
||||
@callbacksToProcess = []
|
||||
|
||||
|
@ -33,6 +32,9 @@ $.extend Travis.Pusher.prototype,
|
|||
subscribeAll: (channels) ->
|
||||
@subscribe(channel) for channel in channels
|
||||
|
||||
unsubscribeAll: (channels) ->
|
||||
@unsubscribe(channel) for channel in channels
|
||||
|
||||
subscribe: (channel) ->
|
||||
return unless channel
|
||||
channel = @prefix(channel)
|
||||
|
|
|
@ -9,6 +9,7 @@ Ember.Router.reopen
|
|||
@_super(url)
|
||||
|
||||
Travis.Router.map ->
|
||||
@resource 'dashboard'
|
||||
@resource 'main', path: '/', ->
|
||||
@resource 'getting_started'
|
||||
@route 'recent'
|
||||
|
@ -80,3 +81,4 @@ require 'routes/settings'
|
|||
require 'routes/simple_layout'
|
||||
require 'routes/ssh_key'
|
||||
require 'routes/stats'
|
||||
require 'routes/dashboard'
|
||||
|
|
7
assets/scripts/app/routes/dashboard.coffee
Normal file
7
assets/scripts/app/routes/dashboard.coffee
Normal file
|
@ -0,0 +1,7 @@
|
|||
require 'routes/route'
|
||||
|
||||
TravisRoute = Travis.Route
|
||||
|
||||
Route = TravisRoute.extend()
|
||||
|
||||
Travis.DashboardRoute = Route
|
|
@ -1,6 +1,8 @@
|
|||
require 'routes/route'
|
||||
require 'pusher'
|
||||
|
||||
TravisRoute = Travis.Route
|
||||
channels = Travis.Pusher.CHANNELS
|
||||
|
||||
Route = TravisRoute.extend
|
||||
renderTemplate: ->
|
||||
|
@ -15,5 +17,9 @@ Route = TravisRoute.extend
|
|||
toActivate = if @signedIn() then 'owned' else 'recent'
|
||||
@container.lookup('controller:repos').activate(toActivate)
|
||||
|
||||
activate: ->
|
||||
# subscribe to pusher only if we're at a main route
|
||||
if channels
|
||||
@get('pusher').subscribeAll(channels)
|
||||
|
||||
Travis.MainRoute = Route
|
||||
|
|
1
assets/scripts/app/templates/dashboard.hbs
Normal file
1
assets/scripts/app/templates/dashboard.hbs
Normal file
|
@ -0,0 +1 @@
|
|||
DASHBOARD GOES HERE!
|
5
assets/scripts/app/templates/layouts/dashboard.hbs
Normal file
5
assets/scripts/app/templates/layouts/dashboard.hbs
Normal file
|
@ -0,0 +1,5 @@
|
|||
{{#link-to "main"}}Home{{/link-to}}
|
||||
|
||||
{{yield}}
|
||||
|
||||
END
|
|
@ -1,4 +1,5 @@
|
|||
require 'ext/ember/namespace'
|
||||
require 'views/view'
|
||||
|
||||
Em.View.reopen
|
||||
init: ->
|
||||
|
@ -9,25 +10,6 @@ Em.View.reopen
|
|||
Travis.NotFoundView = Ember.View.extend
|
||||
layoutName: 'layouts/simple'
|
||||
|
||||
@Travis.reopen
|
||||
View: Em.View.extend
|
||||
actions:
|
||||
popup: (name) -> @popup(name)
|
||||
popupClose: -> @popupClose()
|
||||
|
||||
popup: (name) ->
|
||||
@popupCloseAll()
|
||||
name = event?.target?.name || name
|
||||
$("##{name}").toggleClass('display')
|
||||
popupClose: ->
|
||||
$('.popup').removeClass('display')
|
||||
popupCloseAll: ->
|
||||
if view = Travis.View.currentPopupView
|
||||
view.destroy()
|
||||
Travis.View.currentPopupView = null
|
||||
|
||||
$('.popup').removeClass('display')
|
||||
|
||||
Travis.MainView = Travis.View.extend
|
||||
layoutName: 'layouts/home'
|
||||
classNames: ['application']
|
||||
|
@ -120,3 +102,4 @@ require 'views/signin'
|
|||
require 'views/top'
|
||||
require 'views/status_images'
|
||||
require 'views/status_image_input'
|
||||
require 'views/dashboard'
|
||||
|
|
8
assets/scripts/app/views/dashboard.coffee
Normal file
8
assets/scripts/app/views/dashboard.coffee
Normal file
|
@ -0,0 +1,8 @@
|
|||
require 'views/view'
|
||||
|
||||
TravisView = Travis.View
|
||||
|
||||
View = TravisView.extend
|
||||
layoutName: 'layouts/dashboard'
|
||||
|
||||
Travis.DashboardView = View
|
19
assets/scripts/app/views/view.coffee
Normal file
19
assets/scripts/app/views/view.coffee
Normal file
|
@ -0,0 +1,19 @@
|
|||
View = Ember.View.extend
|
||||
actions:
|
||||
popup: (name) -> @popup(name)
|
||||
popupClose: -> @popupClose()
|
||||
|
||||
popup: (name) ->
|
||||
@popupCloseAll()
|
||||
name = event?.target?.name || name
|
||||
$("##{name}").toggleClass('display')
|
||||
popupClose: ->
|
||||
$('.popup').removeClass('display')
|
||||
popupCloseAll: ->
|
||||
if view = Travis.View.currentPopupView
|
||||
view.destroy()
|
||||
Travis.View.currentPopupView = null
|
||||
|
||||
$('.popup').removeClass('display')
|
||||
|
||||
Travis.View = View
|
|
@ -182,6 +182,13 @@ Travis.initializer
|
|||
application.inject('controller', 'config', 'config:main')
|
||||
application.inject('route', 'config', 'config:main')
|
||||
|
||||
Travis.initializer
|
||||
name: 'inject-pusher'
|
||||
|
||||
initialize: (container, application) ->
|
||||
application.register 'pusher:main', Travis.pusher, { instantiate: false }
|
||||
|
||||
application.inject('route', 'pusher', 'pusher:main')
|
||||
|
||||
Travis.Router.reopen
|
||||
didTransition: ->
|
||||
|
|
Loading…
Reference in New Issue
Block a user