Switch to Ember Data

This commit is contained in:
Piotr Sarnacki 2015-01-27 20:33:16 +01:00
parent 81f950e4f6
commit ec24b21e81
42 changed files with 395 additions and 523 deletions

View File

@ -0,0 +1,13 @@
Travis.ApplicationAdapter = DS.ActiveModelAdapter.extend
host: Travis.config.api_endpoint
ajaxOptions: (url, type, options) ->
hash = @_super(url, type, options)
hash.headers ||= {}
hash.headers['accept'] = 'application/json; version=2'
token = Travis.sessionStorage.getItem('travis.token')
hash.headers['Authorization'] ||= "token #{token}"
hash

View File

@ -0,0 +1,23 @@
get = Ember.get
Travis.EnvVarAdapter = Travis.ApplicationAdapter.extend
namespace: 'settings'
buildURL: (type, id, record) ->
url = @_super.apply this, arguments
if record && (repoId = get(record, 'repo.id'))
delimiter = if url.indexOf('?') != -1 then '&' else '?'
url = "#{url}#{delimiter}repository_id=#{repo_id}"
url
updateRecord: (store, type, record) ->
data = {};
serializer = store.serializerFor(type.typeKey);
serializer.serializeIntoHash(data, type, record);
id = Ember.get(record, 'id');
this.ajax(this.buildURL(type.typeKey, id, record), "PATCH", { data: data })

View File

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

View File

@ -2,46 +2,7 @@ unless window.TravisApplication
window.TravisApplication = Em.Application.extend(Ember.Evented,
LOG_TRANSITIONS: true,
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
annotation: Travis.Annotation
annotations: Travis.Annotation
request: Travis.Request
requests: Travis.Request
env_var: Travis.EnvVar
env_vars: Travis.EnvVar
ssh_key: Travis.SshKey
).property()
modelClasses: (->
[Travis.User, Travis.Build, Travis.Job, Travis.Repo, Travis.Commit, Travis.Worker, Travis.Account, Travis.Broadcast, Travis.Hook, Travis.Annotation, Travis.Request, Travis.EnvVar, Travis.SshKey]
).property()
setup: ->
@get('modelClasses').forEach (klass) ->
klass.adapter = Travis.Adapter.create()
klass.url = "/#{klass.pluralName()}"
Travis.EnvVar.url = "/settings/env_vars"
Travis.EnvVar.adapter = Travis.EnvVarsAdapter.create()
Travis.SshKey.url = "/settings/ssh_key"
Travis.SshKey.adapter = Travis.SshKeyAdapter.create()
@pusher = new Travis.Pusher(key: Travis.config.pusher_key, host: Travis.config.pusher_host) if Travis.config.pusher_key
@tailing = new Travis.Tailing($(window), '#tail', '#log')
@toTop = new Travis.ToTop($(window), '.to-top', '#log-container')
@ -65,12 +26,15 @@ unless window.TravisApplication
Travis.lookup('controller:flash').loadFlashes([options])
receive: (event, data) ->
return
[name, type] = event.split(':')
type = Ember.get(Travis, 'mappings')[name]
store = @__container__.lookup('store:main')
type = store.modelFor(name)
if name == 'job' && data.job?.commit
@loadOrMerge(Travis.Commit, 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
@ -88,13 +52,13 @@ unless window.TravisApplication
sha: build.commit
}
delete(data.build.commit)
@loadOrMerge(Travis.Commit, commit)
store.pushPayload(commits: [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 = store.find('job', data.id)
job.appendLog(number: parseInt(data.number), content: data._log, final: data.final)
else if data[type.singularName()]
@_loadOne(this, type, data)

View File

@ -75,7 +75,7 @@ window.Auth = Ember.Object.extend
refreshUserData: (user) ->
Travis.ajax.get "/users/#{user.id}", (data) =>
Travis.loadOrMerge(Travis.User, data.user)
@store.push('user', data.user)
# if user is still signed in, update saved data
if @get('signedIn')
data.user.token = user.token
@ -101,8 +101,8 @@ window.Auth = Ember.Object.extend
storage.setItem('travis.user', JSON.stringify(data.user))
loadUser: (user) ->
Travis.loadOrMerge(Travis.User, user)
user = Travis.User.find(user.id)
@store.push('user', user)
user = @store.find('user', user.id)
user.get('permissions')
user
@ -151,3 +151,5 @@ Ember.onLoad 'Ember.Application', (Application) ->
application.inject('route', 'auth', 'auth:main')
application.inject('controller', 'auth', 'auth:main')
application.inject('application', 'auth', 'auth:main')
application.inject('auth', 'store', 'store:main')

View File

@ -20,7 +20,12 @@ Travis.AccountController = Ember.ObjectController.extend
reloadHooks: ->
if login = @get('login')
@set('allHooks', Travis.Hook.find(all: true, owner_name: login))
hooks = @store.find('hook', all: true, owner_name: login)
hooks.then () ->
hooks.set('isLoaded', true)
@set('allHooks', hooks)
hooks: (->
@reloadHooks() unless hooks = @get('allHooks')

View File

@ -20,7 +20,7 @@ Travis.FlashController = Ember.ArrayController.extend
).property('broadcasts.isLoaded', 'broadcasts.length')
broadcasts: (->
if @get('currentUser.id') then Travis.Broadcast.find() else Ember.A()
if @get('currentUser.id') then @store.find('broadcast') else Ember.A()
).property('currentUser.id')
loadFlashes: (msgs) ->

View File

@ -13,8 +13,8 @@ Controller = Ember.Controller.extend
init: ->
@_super.apply this, arguments
if !Ember.testing
Visibility.every Travis.INTERVALS.updateTimes, @updateTimes.bind(this)
#if !Ember.testing
# Visibility.every Travis.INTERVALS.updateTimes, @updateTimes.bind(this)
updateTimes: ->
Ember.run this, ->
@ -70,7 +70,7 @@ Controller = Ember.Controller.extend
@connectTab('settings')
lastBuildDidChange: ->
Ember.run.scheduleOnce('data', this, @_lastBuildDidChange);
Ember.run.scheduleOnce('actions', this, @_lastBuildDidChange);
_lastBuildDidChange: ->
build = @get('repo.lastBuild')

View File

@ -28,13 +28,13 @@ Travis.ReposController = Ember.ArrayController.extend
init: ->
@_super.apply this, arguments
if !Ember.testing
Visibility.every Travis.INTERVALS.updateTimes, @updateTimes.bind(this)
#if !Ember.testing
# Visibility.every Travis.INTERVALS.updateTimes, @updateTimes.bind(this)
recentRepos: (->
Ember.ArrayProxy.extend(
isLoadedBinding: 'repos.isLoaded'
repos: Repo.withLastBuild()
repos: Repo.withLastBuild(@store)
sorted: Ember.computed.sort('repos', 'sortedReposKeys')
content: Ember.computed.limit('sorted', 'limit')
sortedReposKeys: ['sortOrder:asc']
@ -49,7 +49,7 @@ Travis.ReposController = Ember.ArrayController.extend
activate: (tab, params) ->
@set('sortProperties', ['sortOrder'])
@set('tab', tab)
this["view_#{tab}".camelize()]()
this["view_#{tab}".camelize()](params)
viewRecent: ->
@set('content', @get('recentRepos'))
@ -59,14 +59,14 @@ Travis.ReposController = Ember.ArrayController.extend
userRepos: (->
if login = @get('currentUser.login')
Travis.Repo.accessibleBy(login)
Travis.Repo.accessibleBy(@store, login)
else
[]
).property('currentUser.login')
viewSearch: (phrase) ->
@set('search', phrase)
@set('content', Travis.Repo.search(phrase))
@set('content', Travis.Repo.search(@store, phrase))
searchObserver: (->
search = @get('search')

View File

@ -12,6 +12,5 @@ require 'models/annotation'
require 'models/repo'
require 'models/request'
require 'models/user'
require 'models/worker'
require 'models/env_var'
require 'models/ssh_key'

View File

@ -1,16 +1,9 @@
require 'travis/model'
Travis.Account = Travis.Model.extend
login: Ember.attr('string')
name: Ember.attr('string')
type: Ember.attr('string')
_reposCount: Ember.attr(Number, key: 'repos_count')
subscribed: Ember.attr(Boolean)
education: Ember.attr(Boolean)
# TODO: maybe it would be good to add a "default" value for Ember.attr
reposCount: (->
@get('_reposCount') || 0
).property('_reposCount')
Travis.Account.primaryKey = 'login'
name: DS.attr()
type: DS.attr()
reposCount: DS.attr('number')
subscribed: DS.attr('boolean')
education: DS.attr('boolean')
loginBinding: 'id'

View File

@ -1,10 +1,10 @@
require 'travis/model'
@Travis.Annotation = Travis.Model.extend
jobId: Ember.attr('number')
description: Ember.attr('string')
url: Ember.attr('string')
status: Ember.attr('string')
providerName: Ember.attr('string')
Travis.Annotation = Travis.Model.extend
jobId: DS.attr('number')
description: DS.attr()
url: DS.attr()
status: DS.attr()
providerName: DS.attr()
job: Ember.belongsTo('Travis.Job')
job: DS.belongsTo('job')

View File

@ -1,29 +1,27 @@
require 'travis/model'
Repo = Travis.Repo
Travis.Branch = Travis.Model.extend
repositoryId: DS.attr('number')
commitId: DS.attr('number')
state: DS.attr()
number: DS.attr('number')
branch: DS.attr()
message: DS.attr()
result: DS.attr('number')
duration: DS.attr('number')
startedAt: DS.attr()
finishedAt: DS.attr()
@Travis.Branch = Travis.Model.extend
repoId: Ember.attr('number', key: 'repository_id')
commitId: Ember.attr('number')
state: Ember.attr('string')
number: Ember.attr('number')
branch: Ember.attr('string')
message: Ember.attr('string')
result: Ember.attr('number')
duration: Ember.attr('number')
startedAt: Ember.attr('string')
finishedAt: Ember.attr('string')
commit: Ember.belongsTo('Travis.Commit')
commit: DS.belongsTo('commit')
repo: (->
Repo.find @get('repoId') if @get('repoId')
).property('repoId')
@store.find('repo', @get('repositoryId')) if @get('repositoryId')
).property('repositoryId')
updateTimes: ->
@notifyPropertyChange 'started_at'
@notifyPropertyChange 'finished_at'
@Travis.Branch.reopenClass
Travis.Branch.reopenClass
byRepoId: (id) ->
@find repository_id: id

View File

@ -1,21 +1,21 @@
require 'travis/model'
@Travis.Broadcast = Travis.Model.extend
message: Ember.attr('string')
Broadcast = Travis.Model.extend
message: DS.attr()
toObject: ->
{ type: 'broadcast', id: @get('id'), message: @get('message') }
isSeen: (->
@get('id') in Travis.Broadcast.get('seen')
@get('id') in Broadcast.get('seen')
).property()
setSeen: ->
Travis.Broadcast.get('seen').pushObject(@get('id'))
Travis.storage.setItem('travis.seen_broadcasts', JSON.stringify(Travis.Broadcast.get('seen')))
Broadcast.get('seen').pushObject(@get('id'))
Travis.storage.setItem('travis.seen_broadcasts', JSON.stringify(Broadcast.get('seen')))
@notifyPropertyChange('isSeen')
@Travis.Broadcast.reopenClass
Broadcast.reopenClass
seen: (->
seenBroadcasts = Travis.storage.getItem('travis.seen_broadcasts')
seenBroadcasts = JSON.parse(seenBroadcasts) if seenBroadcasts?
@ -25,3 +25,4 @@ require 'travis/model'
# TODO fix or monkey-patch the adapter's url and key lookup/generation crap
# url: 'users/broadcasts'
Travis.Broadcast = Broadcast

View File

@ -8,27 +8,22 @@ Ajax = Travis.ajax
config_keys_map = Travis.CONFIG_KEYS_MAP
DurationCalculations = Travis.DurationCalculations
@Travis.Build = Travis.Model.extend DurationCalculations,
repositoryId: Ember.attr('number')
commitId: Ember.attr('number')
Travis.Build = Travis.Model.extend DurationCalculations,
state: DS.attr()
number: DS.attr('number')
branch: DS.attr('string')
message: DS.attr('string')
_duration: DS.attr('number')
_config: DS.attr('object')
_startedAt: DS.attr()
_finishedAt: DS.attr()
pullRequest: DS.attr('boolean')
pullRequestTitle: DS.attr()
pullRequestNumber: DS.attr('number')
state: Ember.attr('string')
number: Ember.attr(Number)
branch: Ember.attr('string')
message: Ember.attr('string')
_duration: Ember.attr(Number, key: 'duration')
_config: Ember.attr('object', key: 'config')
_startedAt: Ember.attr('string', key: 'started_at')
_finishedAt: Ember.attr('string', key: 'finished_at')
pullRequest: Ember.attr('boolean')
pullRequestTitle: Ember.attr('string')
pullRequestNumber: Ember.attr(Number)
# TODO add eventType to the api for api build requests
# eventType: Ember.attr('string')
repo: Ember.belongsTo('Travis.Repo', key: 'repository_id')
commit: Ember.belongsTo('Travis.Commit')
jobs: Ember.hasMany('Travis.Job')
repo: DS.belongsTo('repo', async: true)
commit: DS.belongsTo('commit', async: true)
jobs: DS.hasMany('job', async: true)
config: (->
console.log('config')

View File

@ -1,19 +1,19 @@
require 'travis/model'
@Travis.Commit = Travis.Model.extend
buildId: Ember.attr('number')
sha: Ember.attr('string')
branch: Ember.attr('string')
message: Ember.attr('string')
compareUrl: Ember.attr('string')
authorName: Ember.attr('string')
authorEmail: Ember.attr('string')
committerName: Ember.attr('string')
committerEmail: Ember.attr('string')
subject: Ember.attr('string')
body: Ember.attr('string')
sha: DS.attr()
branch: DS.attr()
message: DS.attr()
compareUrl: DS.attr()
authorName: DS.attr()
authorEmail: DS.attr()
committerName: DS.attr()
committerEmail: DS.attr()
subject: DS.attr()
body: DS.attr()
commitedAt: DS.attr()
build: Ember.belongsTo('Travis.Build')
build: DS.belongsTo('build')
subject: ( ->
@get('message').split("\n", 1)[0]

View File

@ -1,8 +1,8 @@
require 'travis/model'
Travis.EnvVar = Travis.Model.extend
name: Ember.attr('string')
value: Ember.attr('string')
public: Ember.attr('boolean')
name: DS.attr()
value: DS.attr()
public: DS.attr('boolean')
repo: Ember.belongsTo('Travis.Repo', key: 'repository_id')
repo: DS.belongsTo('repo', async: true)

View File

@ -1,11 +1,11 @@
require 'travis/model'
@Travis.Event = Travis.Model.extend
event: Ember.attr('string')
repoId: Ember.attr('number', key: 'repository_id')
sourceId: Ember.attr('number', key: 'source_id')
sourceType: Ember.attr('string', key: 'source_type')
createdAt: Ember.attr('string', key: 'created_at')
event: DS.attr()
repositoryId: DS.attr('number')
sourceId: DS.attr('number')
sourceType: DS.attr()
createdAt: DS.attr()
event_: (->
@get('event')

View File

@ -4,11 +4,12 @@ loadOrMerge = Travis.loadOrMerge
Repo = Travis.Repo
@Travis.Hook = Travis.Model.extend
name: Ember.attr('string')
ownerName: Ember.attr('string')
description: Ember.attr('string')
active: Ember.attr('boolean')
admin: Ember.attr('boolean')
name: DS.attr()
ownerName: DS.attr()
description: DS.attr()
active: DS.attr('boolean')
admin: DS.attr('boolean')
private: DS.attr('boolean')
account: (->
@get('slug').split('/')[0]
@ -37,6 +38,6 @@ Repo = Travis.Repo
# I add an info which we have here to the store - this will allow to display
# a link to the repo and if more info is needed, it will be requested when the
# link is used
loadOrMerge(Repo, @getProperties('id', 'slug', 'name', 'ownerName'), skipIfExists: true)
Repo.find(@get('id'))
@store.push('repo', @getProperties('id', 'slug'))
@store.getById('repo', @get('id'))
).property('id')

View File

@ -7,26 +7,23 @@ Log = Travis.Log
compact = Travis.Helpers.compact
@Travis.Job = Travis.Model.extend DurationCalculations,
repoId: Ember.attr('string', key: 'repository_id')
buildId: Ember.attr('string')
commitId: Ember.attr('string')
logId: Ember.attr('string')
logId: DS.attr()
queue: Ember.attr('string')
state: Ember.attr('string')
number: Ember.attr('string')
_startedAt: Ember.attr('string', key: 'started_at')
_finishedAt: Ember.attr('string', key: 'finished_at')
allowFailure: Ember.attr('boolean')
queue: DS.attr()
state: DS.attr()
number: DS.attr()
_startedAt: DS.attr()
_finishedAt: DS.attr()
allowFailure: DS.attr('boolean')
repositorySlug: Ember.attr('string')
repo: Ember.belongsTo('Travis.Repo', key: 'repository_id')
build: Ember.belongsTo('Travis.Build')
commit: Ember.belongsTo('Travis.Commit')
repositorySlug: DS.attr()
repo: DS.belongsTo('repo', async: true)
build: DS.belongsTo('build', async: true)
commit: DS.belongsTo('commit', async: true)
annotations: Ember.hasMany('Travis.Annotation')
annotations: DS.hasMany('annotation')
_config: Ember.attr('object', key: 'config')
_config: DS.attr('object')
log: ( ->
@set('isLogAccessed', true)

View File

@ -5,26 +5,23 @@ require 'helpers/helpers'
EnvVar = Travis.EnvVar
Build = Travis.Build
SshKey = Travis.SshKey
ExpandableRecordArray = Travis.ExpandableRecordArray
Event = Travis.Event
durationFrom = Travis.Helpers.durationFrom
Ajax = Travis.ajax
@Travis.Repo = Travis.Model.extend
id: Ember.attr('string')
slug: Ember.attr('string')
description: Ember.attr('string')
private: Ember.attr('boolean')
lastBuildId: Ember.attr('string')
lastBuildNumber: Ember.attr(Number)
lastBuildState: Ember.attr('string')
lastBuildStartedAt: Ember.attr('string')
lastBuildFinishedAt: Ember.attr('string')
githubLanguage: Ember.attr('string')
_lastBuildDuration: Ember.attr(Number, key: 'last_build_duration')
lastBuild: Ember.belongsTo('Travis.Build', key: 'last_build_id')
Travis.Repo = Travis.Model.extend
slug: DS.attr()
description: DS.attr()
private: DS.attr('boolean')
lastBuildNumber: DS.attr('number')
lastBuildState: DS.attr()
lastBuildStartedAt: DS.attr()
lastBuildFinishedAt: DS.attr()
githubLanguage: DS.attr()
_lastBuildDuration: DS.attr('number')
lastBuildLanguage: DS.attr()
active: DS.attr()
lastBuildId: DS.attr('number')
lastBuildHash: (->
{
id: @get('lastBuildId')
@ -33,6 +30,10 @@ Ajax = Travis.ajax
}
).property('lastBuildId', 'lastBuildNumber')
lastBuild: (->
@store.find('build', @get('lastBuildId'))
).property('lastBuildId')
withLastBuild: ->
@filter( (repo) -> repo.get('lastBuildId') )
@ -42,7 +43,11 @@ Ajax = Travis.ajax
envVars: (->
id = @get('id')
envVars = EnvVar.find repository_id: id
envVars = @store.filter('env_var', { repository_id: id }, (envVar) ->
# envVar.get('
)
EnvVar.find repository_id: id
# TODO: move to controller
array = ExpandableRecordArray.create
@ -152,38 +157,41 @@ Travis.Repo.reopenClass
recent: ->
@find()
ownedBy: (login) ->
@find(owner_name: login, orderBy: 'name')
accessibleBy: (store, login) ->
repos = store.find('repo', { member: login, orderBy: 'name' })
accessibleBy: (login) ->
@find(member: login, orderBy: 'name')
repos.then () ->
repos.set('isLoaded', true)
search: (query) ->
@find(search: query, orderBy: 'name')
repos
withLastBuild: ->
filtered = Ember.FilteredRecordArray.create(
modelClass: this
filterFunction: (repo) -> repo.get('lastBuildId')
filterProperties: ['lastBuildId']
search: (store, query) ->
store.find('repo', search: query, orderBy: 'name')
withLastBuild: (store) ->
repos = store.filter('repo', {}, (build) ->
build.get('lastBuildId')
)
@fetch().then (array) ->
filtered.updateFilter()
filtered.set('isLoaded', true)
repos.then () ->
repos.set('isLoaded', true)
filtered
repos
bySlug: (slug) ->
repo = $.select(@find().toArray(), (repo) -> repo.get('slug') == slug)
if repo.length > 0 then repo else @find(slug: slug)
fetchBySlug: (slug) ->
repos = $.select(@find().toArray(), (repo) -> repo.get('slug') == slug)
if repos.length > 0
repos[0]
bySlug: (store, slug) ->
# first check if there is a repo with a given slug already ordered
repos = store.all('repo').filterBy('slug', slug)
if repos.get('length') > 0
repos
else
@fetch(slug: slug).then (repos) ->
store.find('repo', { slug: slug })
fetchBySlug: (store, slug) ->
repos = @bySlug(store, slug)
if repos.get('length') > 0
repos.get('firstObject')
else
repos.then (repos) ->
error = new Error('repo not found')
error.slug = slug
Ember.get(repos, 'firstObject') || throw(error)

View File

@ -1,22 +1,21 @@
require 'travis/model'
@Travis.Request = Travis.Model.extend
id: Ember.attr('string')
created_at: Ember.attr('string')
event_type: Ember.attr('string')
result: Ember.attr('string')
message: Ember.attr('string')
headCommit: Ember.attr('string')
baseCommit: Ember.attr('string')
branchName: Ember.attr('string', key: 'branch')
tagName: Ember.attr('string', key: 'tag')
pullRequest: Ember.attr('boolean')
pullRequestTitle: Ember.attr('string')
pullRequestNumber: Ember.attr(Number)
created_at: DS.attr()
event_type: DS.attr()
result: DS.attr()
message: DS.attr()
headCommit: DS.attr()
baseCommit: DS.attr()
branchName: DS.attr()
tagName: DS.attr()
pullRequest: DS.attr('boolean')
pullRequestTitle: DS.attr()
pullRequestNumber: DS.attr('number')
repo: Ember.belongsTo('Travis.Repo', key: 'repository_id')
commit: Ember.belongsTo('Travis.Commit', key: 'commit_id')
build: Ember.belongsTo('Travis.Build', key: 'build_id')
repo: DS.belongsTo('repo')
commit: DS.belongsTo('commit')
build: DS.belongsTo('build')
isAccepted: (->
# For some reason some of the requests have a null result beside the fact that

View File

@ -1,5 +1,4 @@
Travis.SshKey = Travis.Model.extend
id: Ember.attr('string')
value: Ember.attr('string')
description: Ember.attr('string')
fingerprint: Ember.attr('string')
value: DS.attr()
description: DS.attr()
fingerprint: DS.attr()

View File

@ -6,23 +6,18 @@ trigger = Travis.trigger
Account = Travis.Account
@Travis.User = Travis.Model.extend
_name: Ember.attr('string', key: 'name')
email: Ember.attr('string')
login: Ember.attr('string')
token: Ember.attr('string')
gravatarId: Ember.attr('string')
isSyncing: Ember.attr('boolean')
syncedAt: Ember.attr('string')
repoCount: Ember.attr('number')
name: DS.attr()
email: DS.attr()
login: DS.attr()
token: DS.attr()
gravatarId: DS.attr()
isSyncing: DS.attr('boolean')
syncedAt: DS.attr()
repoCount: DS.attr('number')
# This is the only way I found to override the attribue created with Ember.attr
name: Ember.computed( (key, value) ->
if arguments.length == 1
@get('_name') || @get('login')
else
@set('_name', value)
value
).property('login', '_name')
fullName: (->
@get('name') || @get('login')
).property('name', 'login')
isSyncingDidChange: (->
Ember.run.next this, ->

View File

@ -1,61 +0,0 @@
require 'travis/model'
@Travis.Worker = Travis.Model.extend
state: Ember.attr('string')
name: Ember.attr('string')
host: Ember.attr('string')
payload: Ember.attr('object')
number: (->
@get('name').match(/\d+$/)[0]
).property('name')
isWorking: (->
@get('state') == 'working'
).property('state')
jobId: (->
@get('payload.build.id') || @get('payload.job.id')
).property('payload.job.id', 'payload.build.id')
job: (->
Travis.Job.find @get('job_id')
).property('jobId')
jobNumber: (->
@get('payload.job.number')
).property('jobNumber')
repo: (->
id = @get('payload.repository.id') || @get('payload.repo.id')
slug = @get('repoSlug')
@get('store').loadIncomplete(Travis.Repo, {
id: id,
slug: slug
}, { skipIfExists: true })
Travis.Repo.find(@get('payload.repository.id') || @get('payload.repo.id'))
).property('payload.repository.id', 'payload.repo.id')
repoSlug: (->
@get('payload.repo.slug') || @get('payload.repository.slug')
).property('payload.repo.slug', 'payload.repository.slug')
repoId: (->
@get('payload.repo.id') || @get('payload.repository.id')
).property('payload.repo.id', 'payload.repository.id')
nameForSort: (->
if name = @get('name')
match = name.match /(.*?)-(\d+)/
if match
name = match[1]
id = match[2].toString()
if id.length < 2
id = "00#{id}"
else if id.length < 3
id = "0#{id}"
"#{name}-#{id}"
).property('name')

View File

@ -61,12 +61,12 @@ $.extend Travis.Pusher.prototype,
return if event.substr(0, 6) == 'pusher'
data = @normalize(event, data) if data.id
@processWhenVisible ->
@processWhenVisible =>
# 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.Job.isRecordLoaded(data.job.id)
Travis.Job.find(data.job.id).clearLog()
if job = Travis.__container__.lookup('store:main').getById('job', data.job.id)
job.clearLog()
Ember.run.next ->
Travis.receive(event, data)

View File

@ -6,7 +6,7 @@ TravisRoute = Travis.Route
Route = TravisRoute.extend
model: ->
Account.fetch(all: true)
@store.find('account', { all: true })
renderTemplate: ->
@_super.apply(this, arguments)

View File

@ -11,7 +11,7 @@ Route = TravisRoute.extend
{ job_id: id }
setupController: (controller, model) ->
model = Job.find(model) if model && !model.get
model = @store.find('job', model) if model && !model.get
repo = @controllerFor('repo')
@controllerFor('job').set('job', model)
@ -21,7 +21,7 @@ Route = TravisRoute.extend
@controllerFor('build').set('build', build)
model: (params) ->
Job.fetch(params.job_id)
@store.find('job', params.job_id)
deactivate: ->
@controllerFor('build').set('build', null)

View File

@ -11,7 +11,7 @@ Route = TravisRoute.extend
setupController: (controller, model) ->
# TODO: if repo is just a data hash with id and slug load it
# as incomplete record
model = Repo.find(model.id) if model && !model.get
model = @store.find('repo', model.id) if model && !model.get
controller.set('repo', model)
serialize: (repo) ->
@ -21,7 +21,7 @@ Route = TravisRoute.extend
model: (params) ->
slug = "#{params.owner}/#{params.name}"
Repo.fetchBySlug(slug)
Repo.fetchBySlug(@store, slug)
resetController: ->
@controllerFor('repo').deactivate()

View File

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

View File

@ -0,0 +1,13 @@
Travis.ApplicationSerializer = 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)

View File

@ -0,0 +1,13 @@
Travis.BuildSerializer = Travis.ApplicationSerializer.extend
attrs: {
repo: { key: 'repository_id' }
_config: { key: 'config' }
_finishedAt: { key: 'finished_at' }
_startedAt: { key: 'started_at' }
}
extractSingle: (store, primaryType, rawPayload, recordId) ->
if commit = rawPayload.commit
rawPayload.commits = [commit]
@_super(store, primaryType, rawPayload, recordId)

View File

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

View File

@ -0,0 +1,13 @@
Travis.JobSerializer = Travis.ApplicationSerializer.extend
attrs: {
repo: { key: 'repository_id' }
_config: { key: 'config' }
_finishedAt: { key: 'finished_at' }
_startedAt: { key: 'started_at' }
}
extractSingle: (store, primaryType, rawPayload, recordId) ->
if commit = rawPayload.commit
rawPayload.commits = [commit]
@_super(store, primaryType, rawPayload, recordId)

View File

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

View File

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

View File

@ -0,0 +1,3 @@
Travis.Store = DS.Store.extend
defaultAdapter: 'application'
adapter: 'application'

View File

@ -0,0 +1,6 @@
Travis.ObjectTransform = DS.Transform.extend
deserialize: (serialized) ->
serialized
serialize: (deserialized) ->
deserialized

View File

@ -100,7 +100,7 @@ View = Travis.View.extend
_job: (->
if id = @get('jobIdForLog')
Travis.Job.find(id)
Travis.__container__.lookup('store:main').find('job', id)
).property('jobIdForLog')
jobIdForLog: (->

View File

@ -1,60 +1,60 @@
Travis.ExpandableRecordArray = Ember.RecordArray.extend
isLoaded: false
isLoading: false
promise: (->
console.log 'promise'
self = this
new Ember.RSVP.Promise (resolve, reject) ->
console.log 'inside promise'
observer = ->
console.log 'observer', self.get('isLoaded')
if self.get('isLoaded')
console.log 'resolve'
resolve(self)
self.removeObserver('isLoaded', observer)
true
unless observer()
self.addObserver 'isLoaded', observer
).property()
load: (array) ->
@set 'isLoading', true
self = this
observer = ->
if @get 'isLoaded'
content = self.get 'content'
array.removeObserver 'isLoaded', observer
array.forEach (record) ->
self.pushObject(record) unless self.contains(record)
self.set 'isLoading', false
self.set 'isLoaded', true
array.addObserver 'isLoaded', observer
observe: (collection, filterWith) ->
@set 'filterWith', filterWith
collection.addArrayObserver this,
willChange: 'observedArrayWillChange'
didChange: 'observedArraydidChange'
observedArrayWillChange: (array, index, removedCount, addedCount) ->
removedObjects = array.slice index, index + removedCount
for object in removedObjects
@removeObject(object)
observedArraydidChange: (array, index, removedCount, addedCount) ->
addedObjects = array.slice index, index + addedCount
for object in addedObjects
# TODO: I'm not sure why deleted objects get here, but I'll just filter them
# for now
if !object.get('isDeleted') && @get('filterWith').call(this, object)
@pushObject(object) unless @contains(object)
pushObject: (record) ->
if content = @get('content')
content.pushObject(record) unless content.contains(record)
#Travis.ExpandableRecordArray = Ember.RecordArray.extend
# isLoaded: false
# isLoading: false
#
# promise: (->
# console.log 'promise'
# self = this
# new Ember.RSVP.Promise (resolve, reject) ->
# console.log 'inside promise'
# observer = ->
# console.log 'observer', self.get('isLoaded')
# if self.get('isLoaded')
# console.log 'resolve'
# resolve(self)
# self.removeObserver('isLoaded', observer)
# true
#
# unless observer()
# self.addObserver 'isLoaded', observer
# ).property()
#
# load: (array) ->
# @set 'isLoading', true
# self = this
#
# observer = ->
# if @get 'isLoaded'
# content = self.get 'content'
#
# array.removeObserver 'isLoaded', observer
# array.forEach (record) ->
# self.pushObject(record) unless self.contains(record)
#
# self.set 'isLoading', false
# self.set 'isLoaded', true
#
# array.addObserver 'isLoaded', observer
#
# observe: (collection, filterWith) ->
# @set 'filterWith', filterWith
# collection.addArrayObserver this,
# willChange: 'observedArrayWillChange'
# didChange: 'observedArraydidChange'
#
# observedArrayWillChange: (array, index, removedCount, addedCount) ->
# removedObjects = array.slice index, index + removedCount
# for object in removedObjects
# @removeObject(object)
#
# observedArraydidChange: (array, index, removedCount, addedCount) ->
# addedObjects = array.slice index, index + addedCount
# for object in addedObjects
# # TODO: I'm not sure why deleted objects get here, but I'll just filter them
# # for now
# if !object.get('isDeleted') && @get('filterWith').call(this, object)
# @pushObject(object) unless @contains(object)
#
# pushObject: (record) ->
# if content = @get('content')
# content.pushObject(record) unless content.contains(record)

View File

@ -5,124 +5,4 @@ Array.prototype.diff = (a) ->
this.filter (i) -> !(a.indexOf(i) > -1)
@Travis.Model = Ember.Model.extend
id: Ember.attr('number')
init: ->
@_super.apply this, arguments
this
merge: (hash) ->
data = @get('_data')
Ember.merge(data, hash)
@notifyPropertyChange('_data')
unload: ->
@constructor.unload(this)
dataKey: (key) ->
meta = @constructor.metaForProperty(key)
if meta.isRelationship && !meta.options?.key?
type = meta.type
if typeof type == "string"
type = Ember.get(Ember.lookup, type)
if meta.kind == 'belongsTo'
return type.singularName() + '_id'
else
return type.singularName() + '_ids'
@_super(key)
getBelongsTo: (key, type, meta) ->
unless key
key = type.singularName() + '_id'
@_super(key, type, meta)
getHasMany: (key, type, meta) ->
unless key
key = type.singularName() + '_ids'
@_super(key, type, meta)
select: ->
@constructor.select(@get('id'))
@Travis.Model.reopenClass
select: (id) ->
@find().forEach (record) ->
record.set('selected', record.get('id') == id)
buildURL: (suffix) ->
base = @url || @pluralName()
Ember.assert('Base URL (' + base + ') must not start with slash', !base || base.toString().charAt(0) != '/')
Ember.assert('URL suffix (' + suffix + ') must not start with slash', !suffix || suffix.toString().charAt(0) != '/')
url = [base]
url.push(suffix) if (suffix != undefined)
url.join('/')
singularName: ->
parts = @toString().split('.')
name = parts[parts.length - 1]
name.replace(/([A-Z])/g, '_$1').toLowerCase().slice(1)
pluralName: ->
@singularName() + 's'
collectionKey: (->
@pluralName()
).property()
rootKey: (->
@singularName()
).property()
isModel: (->
true
).property()
isRecordLoaded: (id) ->
reference = @_getReferenceById(id)
reference && reference.record
camelizeKeys: true
# TODO: the functions below will be added to Ember Model, remove them when that
# happens
resetData: ->
@_referenceCache = {}
@sideloadedData = {}
@recordArrays = []
@_currentBatchIds = []
@_hasManyArrays = []
@_findAllRecordArray = null
unload: (record) ->
@removeFromRecordArrays(record)
primaryKey = record.get(get(this, 'primaryKey'))
@removeFromCache(primaryKey)
removeFromCache: (key) ->
if @sideloadedData && @sideloadedData[key]
delete this.sideloadedData[key]
if @recordCache && @recordCache[key]
delete this.recordCache[key]
loadRecordForReference: (reference) ->
record = @create({ _reference: reference, id: reference.id })
@sideloadedData = {} unless @sideloadedData
reference.record = record
record.load(reference.id, @sideloadedData[reference.id])
# TODO: find a nicer way to not add record to record arrays twice
if @currentRecordsToAdd
@currentRecordsToAdd.pushObject(record) unless @currentRecordsToAdd.contains(record)
else
@currentRecordsToAdd = [record]
Ember.run.scheduleOnce('data', this, @_batchAddToRecordArrays);
_batchAddToRecordArrays: ->
for record in @currentRecordsToAdd
if !@_findAllRecordArray || !@_findAllRecordArray.contains(record)
@addToRecordArrays(record)
@currentRecordsToAdd = null
@Travis.Model = DS.Model.extend()

View File

@ -20,34 +20,6 @@ Storage = Em.Object.extend
clear: ->
@set('storage', {})
Ember.RecordArray.reopen
# TODO: ember.js changed a way ArrayProxies behave, so that check for content is done
# in _replace method. I should not be overriding it, because it's private, but
# there is no easy other way to do it at this point
_replace: (index, removedCount, records) ->
# in Travis it's sometimes the case that we add new records to RecordArrays
# from pusher before its content has loaded from an ajax query. In order to handle
# this case nicer I'm extending record array to buffer those records and push them
# to content when it's available
@bufferedRecords = [] unless @bufferedRecords
if !@get('content')
for record in records
@bufferedRecords.pushObject(record) unless @bufferedRecords.contains(record)
records = []
# call super only if there's anything more to add
if removedCount || records.length
@_super(index, removedCount, records)
contentDidChange: (->
if (content = @get('content')) && @bufferedRecords && @bufferedRecords.length
for record in @bufferedRecords
content.pushObject(record) unless content.contains(record)
@bufferedRecords = []
).observes('content')
window.Travis = TravisApplication.create(
LOG_ACTIVE_GENERATION: true,
LOG_MODULE_RESOLVER: true,
@ -202,6 +174,8 @@ Travis.initializer
application.inject('route', 'pusher', 'pusher:main')
Travis.pusher.store = container.lookup('store:main')
stylesheetsManager = Ember.Object.create
enable: (id) ->
$("##{id}").removeAttr('disabled')
@ -238,9 +212,21 @@ require 'travis/ajax'
Travis.ajax.pro = Travis.config.pro
require 'travis/adapter'
require 'travis/adapters/env_vars'
require 'travis/adapters/ssh_key'
require 'adapters/application'
require 'serializers/application'
require 'serializers/repo'
require 'serializers/job'
require 'serializers/build'
require 'serializers/account'
require 'serializers/request'
require 'serializers/env_var'
require 'adapters/env_var'
require 'adapters/ssh_key'
require 'transforms/object'
require 'store'
#require 'travis/adapter'
#require 'travis/adapters/env_vars'
#require 'travis/adapters/ssh_key'
require 'routes'
require 'auth'
require 'controllers'