Add pusher receive related stuff to App (previously it was in store)
This commit is contained in:
parent
8082d3a6d3
commit
f92c592f2d
|
@ -1,13 +1,35 @@
|
|||
unless window.TravisApplication
|
||||
window.TravisApplication = Em.Application.extend(Ember.Evented,
|
||||
LOG_TRANSITIONS: true
|
||||
LOG_TRANSITIONS: true,
|
||||
authStateBinding: 'auth.state'
|
||||
signedIn: (-> @get('authState') == 'signed-in' ).property('authState')
|
||||
|
||||
mappings: (->
|
||||
broadcasts: Travis.Broadcast
|
||||
repositories: Travis.Repo
|
||||
repository: Travis.Repo
|
||||
repos: Travis.Repo
|
||||
repo: Travis.Repo
|
||||
builds: Travis.Build
|
||||
build: Travis.Build
|
||||
commits: Travis.Commit
|
||||
commit: Travis.Commit
|
||||
jobs: Travis.Job
|
||||
job: Travis.Job
|
||||
account: Travis.Account
|
||||
accounts: Travis.Account
|
||||
worker: Travis.Worker
|
||||
workers: Travis.Worker
|
||||
).property()
|
||||
|
||||
modelClasses: (->
|
||||
[Travis.User, Travis.Build, Travis.Job, Travis.Repo, Travis.Commit, Travis.Worker, Travis.Account, Travis.Broadcast, Travis.Hook]
|
||||
).property()
|
||||
|
||||
setup: ->
|
||||
@store = Travis.Store.create(
|
||||
adapter: Travis.RestAdapter.create()
|
||||
)
|
||||
@get('modelClasses').forEach (klass) ->
|
||||
klass.adapter = Travis.Adapter.create()
|
||||
klass.url = "/#{klass.pluralName()}"
|
||||
|
||||
@slider = new Travis.Slider()
|
||||
@pusher = new Travis.Pusher(Travis.config.pusher_key) if Travis.config.pusher_key
|
||||
|
@ -16,7 +38,9 @@ unless window.TravisApplication
|
|||
@set('auth', Travis.Auth.create(app: this, endpoint: Travis.config.api_endpoint))
|
||||
|
||||
reset: ->
|
||||
@_super.apply(this, arguments);
|
||||
@_super.apply(this, arguments)
|
||||
@get('modelClasses').forEach (klass) ->
|
||||
klass.resetData()
|
||||
@setup()
|
||||
|
||||
lookup: ->
|
||||
|
@ -34,8 +58,78 @@ unless window.TravisApplication
|
|||
signOut: ->
|
||||
@get('auth').signOut()
|
||||
|
||||
receive: ->
|
||||
@store.receive.apply(@store, arguments)
|
||||
receive: (event, data) ->
|
||||
[name, type] = event.split(':')
|
||||
|
||||
type = Ember.get(Travis, 'mappings')[name]
|
||||
|
||||
if event == 'build:started' && 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)
|
||||
@loadOrMerge(Travis.Commit, commit)
|
||||
|
||||
|
||||
if event == 'job:log'
|
||||
console.log 'store: received job:log event', data if Log.DEBUG
|
||||
data = data.job
|
||||
job = Travis.Job.find(data.id)
|
||||
job.appendLog(number: parseInt(data.number), content: data._log, final: data.final)
|
||||
else if data[type.singularName()]
|
||||
@_loadOne(this, type, data)
|
||||
else if data[type.pluralName()]
|
||||
@_loadMany(this, type, data)
|
||||
else
|
||||
throw "can't load data for #{name}" unless type
|
||||
|
||||
_loadOne: (store, type, json) ->
|
||||
root = type.singularName()
|
||||
result = @loadOrMerge(type, json[root])
|
||||
if result && result.id
|
||||
record = type.find(result.id)
|
||||
type.addToRecordArrays(record)
|
||||
|
||||
# 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 == Travis.Build && (json.repository || json.repo)
|
||||
result = @loadOrMerge(Travis.Repo, json.repository || json.repo)
|
||||
if result && result.id
|
||||
record = Travis.Repo.find(result.id)
|
||||
Travis.Repo.addToRecordArrays(record)
|
||||
|
||||
loadOrMerge: (type, hash, options) ->
|
||||
options ||= {}
|
||||
|
||||
if !type._idToReference
|
||||
type._idToReference = {}
|
||||
reference = type._idToReference[hash.id]
|
||||
|
||||
if reference && options.skipIfExists
|
||||
return
|
||||
|
||||
reference = type._referenceForId(hash.id)
|
||||
if reference.record
|
||||
reference.record.merge(hash)
|
||||
else
|
||||
if type.sideloadedData && type.sideloadedData[hash.id]
|
||||
Ember.merge(type.sideloadedData[hash.id], hash)
|
||||
else
|
||||
type.load([hash])
|
||||
|
||||
reference
|
||||
|
||||
toggleSidebar: ->
|
||||
$('body').toggleClass('maximized')
|
||||
|
|
|
@ -132,6 +132,4 @@ require 'travis/model'
|
|||
filterProperties: ['state']
|
||||
)
|
||||
|
||||
findMany: (ids) ->
|
||||
Travis.store.findMany this, ids
|
||||
|
||||
|
|
|
@ -55,11 +55,11 @@ $.extend Travis.Pusher.prototype,
|
|||
# TODO remove job:requeued, once sf-restart-event has been merged
|
||||
# TODO this also needs to clear logs on build:created if matrix jobs are already loaded
|
||||
if event == 'job:created' || event == 'job:requeued'
|
||||
if Travis.store.isInStore(Travis.Job, data.job.id)
|
||||
if Travis.Job.isRecordLoaded(data.job.id)
|
||||
Travis.Job.find(data.job.id).clearLog()
|
||||
|
||||
Ember.run.next ->
|
||||
Travis.store.receive(event, data)
|
||||
Travis.receive(event, data)
|
||||
|
||||
processSavedCallbacks: ->
|
||||
while callback = @callbacksToProcess.shiftObject()
|
||||
|
|
Loading…
Reference in New Issue
Block a user