Move receiving pusher events to store
This commit is contained in:
parent
fdda7b482f
commit
ba9b6d844a
|
@ -23,54 +23,6 @@ App = Ember.Application.extend(Ember.Evented,
|
||||||
flash: (options) ->
|
flash: (options) ->
|
||||||
Travis.lookup('controller:flash').loadFlashes([options])
|
Travis.lookup('controller:flash').loadFlashes([options])
|
||||||
|
|
||||||
receive: (event, data) ->
|
|
||||||
[name, type] = event.split(':')
|
|
||||||
|
|
||||||
store = @__container__.lookup('store:main')
|
|
||||||
|
|
||||||
if name == 'job' && data.job?.commit
|
|
||||||
store.pushPayload(commits: [data.job.commit])
|
|
||||||
|
|
||||||
if name == 'build' && data.build?.commit
|
|
||||||
# TODO: commit should be a sideload record on build, not mixed with it
|
|
||||||
build = data.build
|
|
||||||
commit = {
|
|
||||||
id: build.commit_id
|
|
||||||
author_email: build.author_email
|
|
||||||
author_name: build.author_name
|
|
||||||
branch: build.branch
|
|
||||||
committed_at: build.committed_at
|
|
||||||
committer_email: build.committer_email
|
|
||||||
committer_name: build.committer_name
|
|
||||||
compare_url: build.compare_url
|
|
||||||
message: build.message
|
|
||||||
sha: build.commit
|
|
||||||
}
|
|
||||||
delete(data.build.commit)
|
|
||||||
|
|
||||||
store.pushPayload(commits: [commit])
|
|
||||||
|
|
||||||
if event == 'job:log'
|
|
||||||
data = data.job
|
|
||||||
job = store.recordForId('job', data.id)
|
|
||||||
job.appendLog(number: parseInt(data.number), content: data._log, final: data.final)
|
|
||||||
else if data[name]
|
|
||||||
@_loadOne(store, name, data)
|
|
||||||
else
|
|
||||||
throw "can't load data for #{name}" unless type
|
|
||||||
|
|
||||||
_loadOne: (store, type, json) ->
|
|
||||||
payload = {}
|
|
||||||
payload[type.pluralize()] = [json[type]]
|
|
||||||
store.pushPayload(payload)
|
|
||||||
|
|
||||||
# we get other types of records only in a few situations and
|
|
||||||
# it's not always needed to update data, so I'm specyfing which
|
|
||||||
# things I want to update here:
|
|
||||||
if type == 'build' && (json.repository || json.repo)
|
|
||||||
data = json.repository || json.repo
|
|
||||||
store.pushPayload(repos: [data])
|
|
||||||
|
|
||||||
toggleSidebar: ->
|
toggleSidebar: ->
|
||||||
$('body').toggleClass('maximized')
|
$('body').toggleClass('maximized')
|
||||||
# TODO gotta force redraws here :/
|
# TODO gotta force redraws here :/
|
||||||
|
|
|
@ -4,4 +4,52 @@ Store = DS.Store.extend
|
||||||
defaultAdapter: 'application'
|
defaultAdapter: 'application'
|
||||||
adapter: 'application'
|
adapter: 'application'
|
||||||
|
|
||||||
|
receivePusherEvent: (event, data) ->
|
||||||
|
[name, type] = event.split(':')
|
||||||
|
|
||||||
|
if name == 'job' && data.job?.commit
|
||||||
|
@pushPayload(commits: [data.job.commit])
|
||||||
|
|
||||||
|
if name == 'build' && data.build?.commit
|
||||||
|
# TODO: commit should be a sideload record on build, not mixed with it
|
||||||
|
build = data.build
|
||||||
|
commit = {
|
||||||
|
id: build.commit_id
|
||||||
|
author_email: build.author_email
|
||||||
|
author_name: build.author_name
|
||||||
|
branch: build.branch
|
||||||
|
committed_at: build.committed_at
|
||||||
|
committer_email: build.committer_email
|
||||||
|
committer_name: build.committer_name
|
||||||
|
compare_url: build.compare_url
|
||||||
|
message: build.message
|
||||||
|
sha: build.commit
|
||||||
|
}
|
||||||
|
delete(data.build.commit)
|
||||||
|
|
||||||
|
@pushPayload(commits: [commit])
|
||||||
|
|
||||||
|
if event == 'job:log'
|
||||||
|
data = data.job
|
||||||
|
job = @recordForId('job', data.id)
|
||||||
|
job.appendLog(number: parseInt(data.number), content: data._log, final: data.final)
|
||||||
|
else if data[name]
|
||||||
|
@_loadOne(name, data)
|
||||||
|
else
|
||||||
|
throw "can't load data for #{name}" unless type
|
||||||
|
|
||||||
|
_loadOne: (type, json) ->
|
||||||
|
payload = {}
|
||||||
|
payload[type.pluralize()] = [json[type]]
|
||||||
|
@pushPayload(payload)
|
||||||
|
|
||||||
|
# we get other types of records only in a few situations and
|
||||||
|
# it's not always needed to update data, so I'm specyfing which
|
||||||
|
# things I want to update here:
|
||||||
|
if type == 'build' && (json.repository || json.repo)
|
||||||
|
data = json.repository || json.repo
|
||||||
|
@pushPayload(repos: [data])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
`export default Store`
|
`export default Store`
|
||||||
|
|
|
@ -58,8 +58,8 @@ TravisPusher.prototype.receive = (event, data) ->
|
||||||
if job = Travis.__container__.lookup('store:main').getById('job', data.job.id)
|
if job = Travis.__container__.lookup('store:main').getById('job', data.job.id)
|
||||||
job.clearLog()
|
job.clearLog()
|
||||||
|
|
||||||
Ember.run.next ->
|
Ember.run.next =>
|
||||||
Travis.receive(event, data)
|
@store.receivePusherEvent(event, data)
|
||||||
|
|
||||||
TravisPusher.prototype.processSavedCallbacks = ->
|
TravisPusher.prototype.processSavedCallbacks = ->
|
||||||
while callback = @callbacksToProcess.shiftObject()
|
while callback = @callbacksToProcess.shiftObject()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user