Fix builds lists for Ember Data
This commit is contained in:
parent
ec24b21e81
commit
ac25220ef2
|
@ -14,8 +14,15 @@ Travis.BuildsController = Em.ArrayController.extend
|
||||||
showMore: ->
|
showMore: ->
|
||||||
id = @get('repo.id')
|
id = @get('repo.id')
|
||||||
number = @get('lastObject.number')
|
number = @get('lastObject.number')
|
||||||
@get('content').load Travis.Build.olderThanNumber(id, number, @get('tab'))
|
@get('content').load @olderThanNumber(id, number, @get('tab'))
|
||||||
|
|
||||||
displayShowMoreButton: (->
|
displayShowMoreButton: (->
|
||||||
@get('tab') != 'branches' and parseInt(@get('lastObject.number')) > 1
|
@get('tab') != 'branches' and parseInt(@get('lastObject.number')) > 1
|
||||||
).property('tab', 'lastObject.number')
|
).property('tab', 'lastObject.number')
|
||||||
|
|
||||||
|
olderThanNumber: (id, number, type) ->
|
||||||
|
options = { repository_id: id, after_number: number }
|
||||||
|
if type?
|
||||||
|
options.event_type = type.replace(/s$/, '') # poor man's singularize
|
||||||
|
|
||||||
|
@store.find('build', options)
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
|
colorForState = Travis.Helpers.colorForState
|
||||||
|
|
||||||
Controller = Em.ObjectController.extend(Travis.GithubUrlProperties,
|
Controller = Em.ObjectController.extend(Travis.GithubUrlProperties,
|
||||||
needs: ['builds']
|
needs: ['builds']
|
||||||
isPullRequestsListBinding: 'controllers.builds.isPullRequestsList'
|
isPullRequestsListBinding: 'controllers.builds.isPullRequestsList'
|
||||||
buildBinding: 'content'
|
buildBinding: 'content'
|
||||||
|
|
||||||
color: (->
|
color: (->
|
||||||
Travis.Helpers.colorForState(@get('build.state'))
|
colorForState(@get('build.state'))
|
||||||
).property('build.state')
|
).property('build.state')
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -106,19 +106,3 @@ Travis.Build = Travis.Model.extend DurationCalculations,
|
||||||
if finishedAt = @get('finishedAt')
|
if finishedAt = @get('finishedAt')
|
||||||
moment(finishedAt).format('lll')
|
moment(finishedAt).format('lll')
|
||||||
).property('finishedAt')
|
).property('finishedAt')
|
||||||
|
|
||||||
@Travis.Build.reopenClass
|
|
||||||
byRepoId: (id, parameters) ->
|
|
||||||
@find($.extend(parameters || {}, repository_id: id))
|
|
||||||
|
|
||||||
branches: (options) ->
|
|
||||||
@find repository_id: options.repoId, branches: true
|
|
||||||
|
|
||||||
olderThanNumber: (id, build_number, type) ->
|
|
||||||
console.log type
|
|
||||||
# TODO fix this api and use some kind of pagination scheme
|
|
||||||
options = { repository_id: id, after_number: build_number }
|
|
||||||
if type?
|
|
||||||
options.event_type = type.replace(/s$/, '') # poor man's singularize
|
|
||||||
|
|
||||||
@find(options)
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ require 'travis/expandable_record_array'
|
||||||
require 'travis/model'
|
require 'travis/model'
|
||||||
require 'helpers/helpers'
|
require 'helpers/helpers'
|
||||||
|
|
||||||
|
ExpandableRecordArray = Travis.ExpandableRecordArray
|
||||||
EnvVar = Travis.EnvVar
|
EnvVar = Travis.EnvVar
|
||||||
Build = Travis.Build
|
Build = Travis.Build
|
||||||
SshKey = Travis.SshKey
|
SshKey = Travis.SshKey
|
||||||
|
@ -64,50 +65,47 @@ Travis.Repo = Travis.Model.extend
|
||||||
array
|
array
|
||||||
).property()
|
).property()
|
||||||
|
|
||||||
allBuilds: (->
|
|
||||||
recordArray = Ember.RecordArray.create({ modelClass: Build, content: Ember.A([]) })
|
|
||||||
Build.registerRecordArray(recordArray)
|
|
||||||
recordArray
|
|
||||||
).property()
|
|
||||||
|
|
||||||
builds: (->
|
builds: (->
|
||||||
id = @get('id')
|
id = @get('id')
|
||||||
builds = Build.byRepoId id, event_type: 'push'
|
builds = @store.find('build', event_type: 'push', repository_id: id)
|
||||||
|
|
||||||
# TODO: move to controller
|
# TODO: move to controller
|
||||||
array = ExpandableRecordArray.create
|
array = ExpandableRecordArray.create
|
||||||
type: Build
|
type: 'build'
|
||||||
content: Ember.A([])
|
content: Ember.A([])
|
||||||
|
|
||||||
array.load(builds)
|
array.load(builds)
|
||||||
|
|
||||||
id = @get('id')
|
id = @get('id')
|
||||||
array.observe(@get('allBuilds'), (build) -> build.get('isLoaded') && build.get('repo.id') == id && !build.get('isPullRequest') )
|
array.observe(@store.all('build'), (build) -> build.get('isLoaded') && build.get('repo.id') == id && !build.get('isPullRequest') )
|
||||||
|
|
||||||
array
|
array
|
||||||
).property()
|
).property()
|
||||||
|
|
||||||
pullRequests: (->
|
pullRequests: (->
|
||||||
id = @get('id')
|
id = @get('id')
|
||||||
builds = Build.byRepoId id, event_type: 'pull_request'
|
builds = @store.find('build', event_type: 'pull_request', repository_id: id)
|
||||||
|
|
||||||
|
# TODO: move to controller
|
||||||
array = ExpandableRecordArray.create
|
array = ExpandableRecordArray.create
|
||||||
type: Build
|
type: 'build'
|
||||||
content: Ember.A([])
|
content: Ember.A([])
|
||||||
|
|
||||||
array.load(builds)
|
array.load(builds)
|
||||||
|
|
||||||
id = @get('id')
|
id = @get('id')
|
||||||
array.observe(@get('allBuilds'), (build) -> build.get('isLoaded') && build.get('repo.id') == id && build.get('isPullRequest') )
|
array.observe(@store.all('build'), (build) -> build.get('isLoaded') && build.get('repo.id') == id && build.get('isPullRequest') )
|
||||||
|
|
||||||
array
|
array
|
||||||
).property()
|
).property()
|
||||||
|
|
||||||
branches: (->
|
branches: (->
|
||||||
Build.branches repoId: @get('id')
|
builds = @store.find 'build', repository_id: @get('id'), branches: true
|
||||||
).property()
|
|
||||||
|
|
||||||
events: (->
|
builds.then ->
|
||||||
Event.byRepoId @get('id')
|
builds.set 'isLoaded', true
|
||||||
|
|
||||||
|
builds
|
||||||
).property()
|
).property()
|
||||||
|
|
||||||
owner: (->
|
owner: (->
|
||||||
|
|
|
@ -1,60 +1,48 @@
|
||||||
#Travis.ExpandableRecordArray = Ember.RecordArray.extend
|
Travis.ExpandableRecordArray = DS.RecordArray.extend
|
||||||
# isLoaded: false
|
isLoaded: false
|
||||||
# isLoading: false
|
isLoading: false
|
||||||
#
|
|
||||||
# promise: (->
|
promise: (->
|
||||||
# console.log 'promise'
|
self = this
|
||||||
# self = this
|
new Ember.RSVP.Promise (resolve, reject) ->
|
||||||
# new Ember.RSVP.Promise (resolve, reject) ->
|
observer = ->
|
||||||
# console.log 'inside promise'
|
if self.get('isLoaded')
|
||||||
# observer = ->
|
resolve(self)
|
||||||
# console.log 'observer', self.get('isLoaded')
|
self.removeObserver('isLoaded', observer)
|
||||||
# if self.get('isLoaded')
|
true
|
||||||
# console.log 'resolve'
|
|
||||||
# resolve(self)
|
unless observer()
|
||||||
# self.removeObserver('isLoaded', observer)
|
self.addObserver 'isLoaded', observer
|
||||||
# true
|
).property()
|
||||||
#
|
|
||||||
# unless observer()
|
load: (array) ->
|
||||||
# self.addObserver 'isLoaded', observer
|
@set 'isLoading', true
|
||||||
# ).property()
|
array.then =>
|
||||||
#
|
array.forEach (record) =>
|
||||||
# load: (array) ->
|
@pushObject(record) unless @contains(record)
|
||||||
# @set 'isLoading', true
|
|
||||||
# self = this
|
@set 'isLoading', false
|
||||||
#
|
@set 'isLoaded', true
|
||||||
# observer = ->
|
|
||||||
# if @get 'isLoaded'
|
observe: (collection, filterWith) ->
|
||||||
# content = self.get 'content'
|
@set 'filterWith', filterWith
|
||||||
#
|
collection.addArrayObserver this,
|
||||||
# array.removeObserver 'isLoaded', observer
|
willChange: 'observedArrayWillChange'
|
||||||
# array.forEach (record) ->
|
didChange: 'observedArraydidChange'
|
||||||
# self.pushObject(record) unless self.contains(record)
|
|
||||||
#
|
observedArrayWillChange: (array, index, removedCount, addedCount) ->
|
||||||
# self.set 'isLoading', false
|
removedObjects = array.slice index, index + removedCount
|
||||||
# self.set 'isLoaded', true
|
for object in removedObjects
|
||||||
#
|
@removeObject(object)
|
||||||
# array.addObserver 'isLoaded', observer
|
|
||||||
#
|
observedArraydidChange: (array, index, removedCount, addedCount) ->
|
||||||
# observe: (collection, filterWith) ->
|
addedObjects = array.slice index, index + addedCount
|
||||||
# @set 'filterWith', filterWith
|
for object in addedObjects
|
||||||
# collection.addArrayObserver this,
|
# TODO: I'm not sure why deleted objects get here, but I'll just filter them
|
||||||
# willChange: 'observedArrayWillChange'
|
# for now
|
||||||
# didChange: 'observedArraydidChange'
|
if !object.get('isDeleted') && @get('filterWith').call(this, object)
|
||||||
#
|
@pushObject(object) unless @contains(object)
|
||||||
# observedArrayWillChange: (array, index, removedCount, addedCount) ->
|
|
||||||
# removedObjects = array.slice index, index + removedCount
|
pushObject: (record) ->
|
||||||
# for object in removedObjects
|
if content = @get('content')
|
||||||
# @removeObject(object)
|
content.pushObject(record) unless content.contains(record)
|
||||||
#
|
|
||||||
# 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)
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user