travis-web/assets/scripts/app/app.coffee
Piotr Sarnacki b0b1ef305b Change the way config is stored
On ember-cli config is stored in config/environment.js file and it can be
accessed at any time of app being booted. Till now we were using Travis.config
which was making things hard, because we needed an application instance to get
any config value. This commit moves config to config/environment.js and allows
to access it at any point of loading the app.
2015-01-30 15:29:46 +01:00

128 lines
3.6 KiB
CoffeeScript

App = Ember.Application.extend(Ember.Evented,
LOG_TRANSITIONS: true
LOG_TRANSITIONS_INTERNAL: true
LOG_ACTIVE_GENERATION: true
LOG_MODULE_RESOLVER: true
LOG_VIEW_LOOKUPS: true
#LOG_RESOLVER: true
setup: ->
if @config.pusher.key
@pusher = new Travis.Pusher(@config.pusher)
@tailing = new Travis.Tailing($(window), '#tail', '#log')
@toTop = new Travis.ToTop($(window), '.to-top', '#log-container')
@on 'user:signed_in', (user) ->
Travis.onUserUpdate(user)
@on 'user:synced', (user) ->
Travis.onUserUpdate(user)
lookup: ->
@__container__.lookup.apply @__container__, arguments
flash: (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(commit: [commit])
if event == 'job:log'
console.log 'store: received job:log event', data if Log.DEBUG
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: ->
$('body').toggleClass('maximized')
# TODO gotta force redraws here :/
element = $('<span></span>')
$('#top .profile').append(element)
Em.run.later (-> element.remove()), 10
element = $('<span></span>')
$('#repo').append(element)
Em.run.later (-> element.remove()), 10
ready: ->
@slider = new Travis.Slider(@storage)
location.href = location.href.replace('#!/', '') if location.hash.slice(0, 2) == '#!'
currentDate: ->
new Date()
onUserUpdate: (user) ->
if Travis.config.pro
@identifyCustomer(user)
@subscribePusher(user)
@setupCharm(user)
subscribePusher: (user) ->
channels = user.channels
channels = channels.map (channel) ->
if channel.match /^private-/
channel
else
"private-#{channel}"
Travis.pusher.subscribeAll(channels)
setupCharm: (user) ->
$.extend window.__CHARM,
customer: user.login,
customer_id: user.id,
email: user.email
displayCharm: ->
__CHARM.show()
identifyCustomer: (user) ->
if _cio && _cio.identify
_cio.identify
id: user.id
email: user.email
name: user.name
created_at: (Date.parse(user.created_at) / 1000) || null
login: user.login
)
window.App = App unless window.App