More ember-cli compat changes

This commit is contained in:
Piotr Sarnacki 2015-01-29 12:02:44 +01:00
parent 8124bc3780
commit 47c87317d0
19 changed files with 186 additions and 144 deletions

View File

@ -1,4 +1,4 @@
Travis.ApplicationAdapter = DS.ActiveModelAdapter.extend
Adapter = DS.ActiveModelAdapter.extend
host: Travis.config.api_endpoint
ajaxOptions: (url, type, options) ->
hash = @_super(url, type, options)
@ -11,3 +11,6 @@ Travis.ApplicationAdapter = DS.ActiveModelAdapter.extend
hash.headers['Authorization'] ||= "token #{token}"
hash
Travis.ApplicationAdapter = Adapter

View File

@ -1,12 +1,12 @@
get = Ember.get
ApplicationAdapter = Travis.ApplicationAdapter
Travis.EnvVarAdapter = Travis.ApplicationAdapter.extend
Adapter = ApplicationAdapter.extend
namespace: 'settings'
buildURL: (type, id, record) ->
url = @_super.apply this, arguments
if record && (repoId = get(record, 'repo.id'))
if record && (repoId = Ember.get(record, 'repo.id'))
delimiter = if url.indexOf('?') != -1 then '&' else '?'
url = "#{url}#{delimiter}repository_id=#{repoId}"
@ -21,3 +21,5 @@ Travis.EnvVarAdapter = Travis.ApplicationAdapter.extend
id = Ember.get(record, 'id');
this.ajax(this.buildURL(type.typeKey, id, record), "PATCH", { data: data })
Travis.EnvVarAdapter = Adapter

View File

@ -1,6 +1,8 @@
get = Ember.get
Travis.SshKeyAdapter = Travis.ApplicationAdapter.extend
ApplicationAdapter = Travis.ApplicationAdapter
Adapter = ApplicationAdapter.extend
namespace: 'settings'
createRecord: (store, type, record) ->
@ -9,3 +11,5 @@ Travis.SshKeyAdapter = Travis.ApplicationAdapter.extend
serializer.serializeIntoHash(data, type, record, { includeId: true });
this.ajax(this.buildURL(type.typeKey, null, record), "POST", { data: data })
Travis.SshKeyAdapter = Adapter

View File

@ -1,4 +1,4 @@
window.Auth = Ember.Object.extend
Auth = Ember.Object.extend
state: "signed-out"
receivingEnd: "#{location.protocol}//#{location.host}"
@ -9,7 +9,7 @@ window.Auth = Ember.Object.extend
Travis.sessionStorage.getItem('travis.token')
endpoint: (->
@container.lookup('application:main').config.api_endpoint
@config.api_endpoint
).property(),
signOut: ->
@ -141,15 +141,4 @@ window.Auth = Ember.Object.extend
"#{location.protocol}//www.gravatar.com/avatar/#{@get('currentUser.gravatarId')}?s=48&d=mm"
).property('currentUser.gravatarId')
Ember.onLoad 'Ember.Application', (Application) ->
Application.initializer
name: "auth",
initialize: (container, application) ->
application.register 'auth:main', Auth
application.inject('route', 'auth', 'auth:main')
application.inject('controller', 'auth', 'auth:main')
application.inject('application', 'auth', 'auth:main')
application.inject('auth', 'store', 'store:main')
window.Auth = Auth

View File

@ -0,0 +1,17 @@
initialize = (container, app) ->
app.register 'auth:main', Auth
app.inject('route', 'auth', 'auth:main')
app.inject('controller', 'auth', 'auth:main')
app.inject('application', 'auth', 'auth:main')
Auth.store = container.lookup('store:main')
Auth.config = container.lookup('config:main')
AuthInitializer =
name: 'auth'
initialize: initialize
Ember.onLoad 'Ember.Application', (Application) ->
Application.initializer AuthInitializer

View File

@ -0,0 +1,13 @@
initialize = (container, application) ->
application.register 'config:main', application.config, { instantiate: false }
application.inject('controller', 'config', 'config:main')
application.inject('route', 'config', 'config:main')
application.inject('auth', 'config', 'config:main')
ConfigInitializer =
name: 'pusher'
initialize: initialize
Ember.onLoad 'Ember.Application', (Application) ->
Application.initializer ConfigInitializer

View File

@ -0,0 +1,18 @@
initialize = (container) ->
if Travis.config.ga_code
window._gaq = []
_gaq.push(['_setAccount', Travis.config.ga_code])
ga = document.createElement('script')
ga.type = 'text/javascript'
ga.async = true
ga.src = 'https://ssl.google-analytics.com/ga.js'
s = document.getElementsByTagName('script')[0]
s.parentNode.insertBefore(ga, s)
GAInitializer =
name: 'google-analytics'
initialize: initialize
Ember.onLoad 'Ember.Application', (Application) ->
Application.initializer GAInitializer

View File

@ -0,0 +1,14 @@
initialize = (container, application) ->
application.register 'pusher:main', application.pusher, { instantiate: false }
application.inject('route', 'pusher', 'pusher:main')
application.pusher.store = container.lookup('store:main')
PusherInitializer =
name: 'pusher'
initialize: initialize
Ember.onLoad 'Ember.Application', (Application) ->
Application.initializer PusherInitializer

View File

@ -0,0 +1,55 @@
Storage = Em.Object.extend
init: ->
@set('storage', {})
key: (key) ->
"__#{key.replace('.', '__')}"
getItem: (k) ->
return @get("storage.#{@key(k)}")
setItem: (k,v) ->
@set("storage.#{@key(k)}", v)
removeItem: (k) ->
@setItem(k, null)
clear: ->
@set('storage', {})
sessionStorage = (->
storage = null
try
# firefox will not throw error on access for sessionStorage var,
# you need to actually get something from session
sessionStorage.getItem('foo')
storage = sessionStorage
catch err
storage = Storage.create()
storage
)()
storage = (->
storage = null
try
storage = window.localStorage || throw('no storage')
catch err
storage = Storage.create()
storage
)()
initialize = (container, application) ->
application.register 'storage:main', storage, { instantiate: false }
application.register 'sessionStorage:main', sessionStorage, { instantiate: false }
application.inject('auth', 'storage', 'storage:main')
application.inject('auth', 'sessionStorage', 'sessionStorage:main')
# I still use Travis.storage in some places which are not that easy to
# refactor
application.storage = storage
application.sessionStorage = sessionStorage
StorageInitializer =
name: 'storage'
initialize: initialize
Ember.onLoad 'Ember.Application', (Application) ->
Application.initializer StorageInitializer

View File

@ -0,0 +1,15 @@
stylesheetsManager = Ember.Object.create
enable: (id) ->
$("##{id}").removeAttr('disabled')
disable: (id) ->
$("##{id}").attr('disabled', 'disabled')
initialize = (container, application) ->
application.register 'stylesheetsManager:main', stylesheetsManager, { instantiate: false }
application.inject('route', 'stylesheetsManager', 'stylesheetsManager:main')
StylesheetsManagerInitializer =
name: 'inject-stylesheets-manager'
initialize: initialize

View File

@ -8,6 +8,11 @@ Ember.Router.reopen
Travis.Router.reopen
location: 'history'
didTransition: ->
@_super.apply @, arguments
if Travis.config.ga_code
_gaq.push ['_trackPageview', location.pathname]
Travis.Router.map ->
@resource 'dashboard', ->

View File

@ -1,2 +1,6 @@
Travis.AccountSerializer = Travis.ApplicationSerializer.extend
ApplicationSerializer = Travis.ApplicationSerializer
Serializer = ApplicationSerializer.extend
primaryKey: 'login'
Travis.AccountSerializer = Serializer

View File

@ -1,13 +1,5 @@
Travis.ApplicationSerializer = DS.ActiveModelSerializer.extend
Serializer = DS.ActiveModelSerializer.extend
defaultSerializer: 'application'
serializer: 'application'
extractSingle: (store, primaryType, rawPayload, recordId) ->
#newPayload = {}
#if payload.build
@_super.apply(this, arguments)
extractArray: (store, type, payload) ->
@_super.apply(this, arguments)
Travis.ApplicationSerializer = Serializer

View File

@ -1,4 +1,6 @@
Travis.BuildSerializer = Travis.ApplicationSerializer.extend
ApplicationSerializer = Travis.ApplicationSerializer
Serializer = ApplicationSerializer.extend
attrs: {
repo: { key: 'repository_id' }
_config: { key: 'config' }
@ -11,3 +13,5 @@ Travis.BuildSerializer = Travis.ApplicationSerializer.extend
rawPayload.commits = [commit]
@_super(store, primaryType, rawPayload, recordId)
Travis.BuildSerializer = Serializer

View File

@ -1,4 +1,8 @@
Travis.EnvVarSerializer = Travis.ApplicationSerializer.extend
ApplicationSerializer = Travis.ApplicationSerializer
Serializer = ApplicationSerializer.extend
attrs: {
repo: { key: 'repository_id' }
}
Travis.EnvVarSerializer = Serializer

View File

@ -1,4 +1,6 @@
Travis.JobSerializer = Travis.ApplicationSerializer.extend
ApplicationSerializer = Travis.ApplicationSerializer
Serializer = ApplicationSerializer.extend
attrs: {
repo: { key: 'repository_id' }
_config: { key: 'config' }
@ -11,3 +13,5 @@ Travis.JobSerializer = Travis.ApplicationSerializer.extend
rawPayload.commits = [commit]
@_super(store, primaryType, rawPayload, recordId)
Travis.JobSerializer = Serializer

View File

@ -1,4 +1,8 @@
Travis.RepoSerializer = Travis.ApplicationSerializer.extend
ApplicationSerializer = Travis.ApplicationSerializer
Serializer = ApplicationSerializer.extend
attrs: {
_lastBuildDuration: { key: 'last_build_duration' }
}
Travis.RepoSerializer = Serializer

View File

@ -1,6 +1,10 @@
Travis.RequestSerializer = Travis.ApplicationSerializer.extend
ApplicationSerializer = Travis.ApplicationSerializer
Serializer = ApplicationSerializer.extend
attrs: {
branchName: { key: 'branch' }
tagName: { key: 'tag' }
repo: { key: 'repository_id' }
}
Travis.RequestSerializer = Serializer

View File

@ -6,20 +6,6 @@ require 'app'
window.ENV ||= {}
window.ENV.RAISE_ON_DEPRECATION = true
Storage = Em.Object.extend
init: ->
@set('storage', {})
key: (key) ->
"__#{key.replace('.', '__')}"
getItem: (k) ->
return @get("storage.#{@key(k)}")
setItem: (k,v) ->
@set("storage.#{@key(k)}", v)
removeItem: (k) ->
@setItem(k, null)
clear: ->
@set('storage', {})
window.Travis = TravisApplication.create(
LOG_ACTIVE_GENERATION: true,
LOG_MODULE_RESOLVER: true,
@ -103,101 +89,6 @@ $.extend Travis,
INTERVALS: { times: -1, updateTimes: 1000 }
sessionStorage = (->
storage = null
try
# firefox will not throw error on access for sessionStorage var,
# you need to actually get something from session
sessionStorage.getItem('foo')
storage = sessionStorage
catch err
storage = Storage.create()
storage
)()
storage = (->
storage = null
try
storage = window.localStorage || throw('no storage')
catch err
storage = Storage.create()
storage
)()
Travis.initializer
name: 'storage'
initialize: (container, application) ->
application.register 'storage:main', storage, { instantiate: false }
application.register 'sessionStorage:main', sessionStorage, { instantiate: false }
application.inject('auth', 'storage', 'storage:main')
application.inject('auth', 'sessionStorage', 'sessionStorage:main')
# I still use Travis.storage in some places which are not that easy to
# refactor
application.storage = storage
application.sessionStorage = sessionStorage
Travis.initializer
name: 'googleAnalytics'
initialize: (container) ->
if Travis.config.ga_code
window._gaq = []
_gaq.push(['_setAccount', Travis.config.ga_code])
ga = document.createElement('script')
ga.type = 'text/javascript'
ga.async = true
ga.src = 'https://ssl.google-analytics.com/ga.js'
s = document.getElementsByTagName('script')[0]
s.parentNode.insertBefore(ga, s)
Travis.initializer
name: 'inject-config'
initialize: (container, application) ->
application.register 'config:main', Travis.config, { instantiate: false }
application.inject('controller', 'config', 'config:main')
application.inject('route', 'config', 'config:main')
application.inject('auth', '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.pusher.store = container.lookup('store:main')
stylesheetsManager = Ember.Object.create
enable: (id) ->
$("##{id}").removeAttr('disabled')
disable: (id) ->
$("##{id}").attr('disabled', 'disabled')
Travis.initializer
name: 'inject-stylesheets-manager'
initialize: (container, application) ->
application.register 'stylesheetsManager:main', stylesheetsManager, { instantiate: false }
application.inject('route', 'stylesheetsManager', 'stylesheetsManager:main')
Travis.Router.reopen
didTransition: ->
@_super.apply @, arguments
if Travis.config.ga_code
_gaq.push ['_trackPageview', location.pathname]
Ember.LinkView.reopen
loadingClass: 'loading_link'