Permalink
Browse files

WIP2

  • Loading branch information...
drogus committed May 28, 2013
1 parent 0efbc1b commit 25d27552c75d87b0748bc99a0b7bfa2eb33e7f24
@@ -4,23 +4,80 @@ Adapter = Ember.RESTAdapter.extend
unless window.TravisApplication
window.TravisApplication = Em.Application.extend(Ember.Evented,
LOG_TRANSITIONS: true
authStateBinding: 'auth.state'
signedIn: (-> @get('authState') == 'signed-in' ).property('authState')
setup: ->
modelClasses = [Travis.User, Travis.Build, Travis.Job, Travis.Repo]
modelClasses = [Travis.User, Travis.Build, Travis.Job, Travis.Repo, Travis.Commit, Travis.Worker, Travis.Account, Travis.Broadcast]
modelClasses.forEach (klass) ->
klass.adapter = Adapter.create()
klass.adapter = Adapter.extend(
findMany: (klass, records, ids) ->
debugger
console.log 'findMany', klass+'', records+'', ids
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
buildURL: ->
@_super.apply(this, arguments).replace(/\.json$/, '')
didFind: (record, id, data) ->
@sideload(record.constructor, data)
@_super(record, id, data)
didFindAll: (klass, records, data) ->
@sideload(klass, data)
@_super(klass, records, data)
didFindQuery: (klass, records, params, data) ->
@sideload(klass, data)
@_super(klass, records, params, data)
didCreateRecord: (record, data) ->
@sideload(record.constructor, data)
@_super(record, data)
didSaveRecord: (record, data) ->
@sideload(record.constructor, data)
@_super(record, data)
didDeleteRecord: (record, data) ->
@sideload(record.constructor, data)
@_super(record, data)
sideload: (klass, data) ->
for name, records of data
records = [records] unless Ember.isArray(records)
# we need to skip records of type, which is loaded by adapter already
if (type = @mappings[name]) != klass
for record in records
type.findFromCacheOrLoad(record)
).create()
Travis.User.url = '/users'
Travis.Build.url = '/builds'
Travis.Job.url = '/jobs'
Travis.Repo.url = '/repos'
Travis.Build.url = '/builds'
# TODO: fix
#@store.loadMany(Travis.Sponsor, Travis.SPONSORS)
Travis.SPONSORS.forEach (sponsor) ->
Travis.Sponsor.findFromCacheOrLoad(sponsor)
@slider = new Travis.Slider()
@pusher = new Travis.Pusher(Travis.config.pusher_key) if Travis.config.pusher_key
@@ -9,7 +9,7 @@ Travis.RepoController = Travis.Controller.extend
init: ->
@_super.apply this, arguments
Ember.run.later(@updateTimes.bind(this), Travis.INTERVALS.updateTimes)
setInterval(@updateTimes.bind(this), Travis.INTERVALS.updateTimes)
updateTimes: ->
if builds = @get('builds')
@@ -21,13 +21,12 @@ Travis.RepoController = Travis.Controller.extend
if build && jobs = build.get('jobs')
jobs.forEach (j) -> j.updateTimes()
Ember.run.later(@updateTimes.bind(this), Travis.INTERVALS.updateTimes)
activate: (action) ->
@_unbind()
this["view#{$.camelize(action)}"]()
viewIndex: ->
console.log 'bind repo'
@_bind('repo', 'controllers.repos.firstObject')
@_bind('build', 'repo.lastBuild')
@connectTab('current')
@@ -27,7 +27,7 @@ Travis.ReposController = Ember.ArrayController.extend
init: ->
@_super.apply this, arguments
Ember.run.later(@updateTimes.bind(this), Travis.INTERVALS.updateTimes)
setInterval @updateTimes.bind(this), Travis.INTERVALS.updateTimes
Travis.Repo.withLastBuild()
recentRepos: (->
@@ -45,8 +45,6 @@ Travis.ReposController = Ember.ArrayController.extend
if content = @get('content')
content.forEach (r) -> r.updateTimes()
Ember.run.later(@updateTimes.bind(this), Travis.INTERVALS.updateTimes)
activate: (tab, params) ->
@set('sortProperties', null)
tab ||= @get('defaultTab')
@@ -5,11 +5,11 @@ Travis.reopen
init: ->
@_super.apply this, arguments
@tickables = []
Travis.Ticker.create(target: this, interval: Travis.INTERVALS.sponsors)
# @tickables = []
#Travis.Ticker.create(target: this, interval: Travis.INTERVALS.sponsors)
tick: ->
tickable.tick() for tickable in @tickables
#tick: ->
# tickable.tick() for tickable in @tickables
QueuesController: Em.ArrayController.extend
init: ->
@@ -80,7 +80,7 @@ Travis.DecksController = Travis.SponsorsController.extend
init: ->
@_super.apply this, arguments
@get('controllers.sidebar').tickables.push(this)
#@get('controllers.sidebar').tickables.push(this)
@set 'content', Travis.Sponsor.decks()
Travis.LinksController = Travis.SponsorsController.extend
@@ -90,5 +90,5 @@ Travis.LinksController = Travis.SponsorsController.extend
init: ->
@_super.apply this, arguments
@get('controllers.sidebar').tickables.push(this)
#@get('controllers.sidebar').tickables.push(this)
@set 'content', Travis.Sponsor.links()
@@ -12,7 +12,7 @@ require 'travis/model'
startedAt: Ember.attr('string')
finishedAt: Ember.attr('string')
# commit: DS.belongsTo('Travis.Commit')
commit: Ember.belongsTo('Travis.Commit')
repo: (->
Travis.Repo.find @get('repoId') if @get('repoId')
@@ -17,9 +17,9 @@ require 'travis/model'
pullRequestTitle: Ember.attr('string')
pullRequestNumber: Ember.attr('number')
# repo: DS.belongsTo('Travis.Repo')
# commit: DS.belongsTo('Travis.Commit')
# jobs: DS.hasMany('Travis.Job')
repo: Ember.belongsTo('Travis.Repo', key: 'repositoryId')
commit: Ember.belongsTo('Travis.Commit')
jobs: Ember.hasMany('Travis.Job')
config: (->
Travis.Helpers.compact(@get('_config'))
@@ -12,4 +12,4 @@ require 'travis/model'
committerEmail: Ember.attr('string')
pullRequestNumber: Ember.attr('number')
# build: DS.belongsTo('Travis.Build')
build: Ember.belongsTo('Travis.Build')
@@ -14,24 +14,19 @@ require 'travis/model'
allowFailure: Ember.attr('boolean')
repositorySlug: Ember.attr('string')
# repo: DS.belongsTo('Travis.Repo')
# build: DS.belongsTo('Travis.Build')
# commit: DS.belongsTo('Travis.Commit')
# this is a fake relationship just to get rid
# of ember data's bug: https://github.com/emberjs/data/issues/758
# TODO: remove when this issue is fixed
# fakeBuild: DS.belongsTo('Travis.Build')
repo: Ember.belongsTo('Travis.Repo', key: 'repositoryId')
build: Ember.belongsTo('Travis.Build')
commit: Ember.belongsTo('Travis.Commit')
_config: Ember.attr('object')
repoSlugDidChange: (->
if slug = @get('repoSlug')
@get('store').loadIncomplete(Travis.Repo, {
id: @get('repoId'),
slug: slug
}, { skipIfExists: true })
).observes('repoSlug')
#repoSlugDidChange: (->
# if slug = @get('repoSlug')
# @get('store').loadIncomplete(Travis.Repo, {
# id: @get('repoId'),
# slug: slug
# }, { skipIfExists: true })
#).observes('repoSlug')
log: ( ->
@set('isLogAccessed', true)
@@ -118,16 +113,23 @@ require 'travis/model'
@Travis.Job.reopenClass
queued: (queue) ->
@find()
Travis.store.filter this, (job) ->
queued = ['created', 'queued'].indexOf(job.get('state')) != -1
# TODO: why queue is sometimes just common instead of build.common?
queued && (!queue || job.get('queue') == "builds.#{queue}" || job.get('queue') == queue)
Ember.FilteredRecordArray.create(
modelClass: Travis.Job
filterFunction: (job) ->
queued = ['created', 'queued'].indexOf(job.get('state')) != -1
# TODO: why queue is sometimes just common instead of build.common?
queued && (!queue || job.get('queue') == "builds.#{queue}" || job.get('queue') == queue)
filterProperties: ['state', 'queue']
)
running: ->
@find(state: 'started')
Travis.store.filter this, (job) ->
job.get('state') == 'started'
Ember.FilteredRecordArray.create(
modelClass: Travis.Job
filterFunction: (job) ->
job.get('state') == 'started'
filterProperties: ['state']
)
findMany: (ids) ->
Travis.store.findMany this, ids
@@ -2,6 +2,7 @@ require 'travis/expandable_record_array'
require 'travis/model'
@Travis.Repo = Travis.Model.extend
id: Ember.attr('string')
slug: Ember.attr('string')
description: Ember.attr('string')
lastBuildId: Ember.attr('number')
@@ -11,7 +12,7 @@ require 'travis/model'
lastBuildFinishedAt: Ember.attr('string')
_lastBuildDuration: Ember.attr('number')
# lastBuild: DS.belongsTo('Travis.Build')
lastBuild: Ember.belongsTo('Travis.Build', key: 'lastBuildId')
lastBuildHash: (->
{
@@ -25,6 +26,7 @@ require 'travis/model'
Travis.Build.find()
).property()
# TODO: this should not belong in the model
builds: (->
id = @get('id')
builds = Travis.Build.byRepoId id, event_type: 'push'
@@ -33,7 +35,6 @@ require 'travis/model'
array = Travis.ExpandableRecordArray.create
type: Travis.Build
content: Ember.A([])
store: @get('store')
array.load(builds)
@@ -49,7 +50,6 @@ require 'travis/model'
array = Travis.ExpandableRecordArray.create
type: Travis.Build
content: Ember.A([])
store: @get('store')
array.load(builds)
@@ -117,18 +117,20 @@ require 'travis/model'
@find(search: query, orderBy: 'name')
withLastBuild: ->
Ember.FilteredRecordArray.create(
filtered = Ember.FilteredRecordArray.create(
modelClass: Travis.Repo
filterFunction: (repo) -> console.log(repo+'', repo.get('lastBuildId')); repo.get('lastBuildId')
# (!repo.get('incomplete') || repo.isAttributeLoaded('lastBuildId'))
filterFunction: (repo) -> repo.get('lastBuildId')
filterProperties: ['lastBuildId']
)
Travis.Repo.findAll().then (array) ->
filtered.updateFilter()
filtered
bySlug: (slug) ->
repo = $.select(@find().toArray(), (repo) -> repo.get('slug') == slug)
if repo.length > 0 then repo else @find(slug: slug)
# buildURL: (slug) ->
# if slug then slug else 'repos'
@@ -4,11 +4,7 @@ require 'travis/model'
type: Ember.attr('string')
url: Ember.attr('string')
link: Ember.attr('string')
_image: Ember.attr('string')
image: (->
"/images/sponsors/#{@get('_image')}"
).property('_image')
image: Ember.attr('string', transform: (image) -> "/images/sponsors/#{image}")
Travis.Sponsor.reopenClass
decks: ->
@@ -27,5 +23,9 @@ Travis.Sponsor.reopenClass
byType: ->
types = Array.prototype.slice.apply(arguments)
Travis.Sponsor.filter (sponsor) -> types.indexOf(sponsor.get('type')) != -1
Ember.FilteredRecordArray.create(
modelClass: Travis.Sponsor
filterFunction: (sponsor) -> types.indexOf(sponsor.get('type')) != -1
filterProperties: ['type']
)
Oops, something went wrong.

0 comments on commit 25d2755

Please sign in to comment.