Fix show more button and make it disabled when loading
This commit is contained in:
parent
2e16337e68
commit
202f158d55
|
@ -1,3 +1,4 @@
|
||||||
|
require 'travis/expandable_record_array'
|
||||||
require 'travis/model'
|
require 'travis/model'
|
||||||
|
|
||||||
@Travis.Repository = Travis.Model.extend
|
@Travis.Repository = Travis.Model.extend
|
||||||
|
@ -13,14 +14,28 @@ require 'travis/model'
|
||||||
|
|
||||||
builds: (->
|
builds: (->
|
||||||
id = @get('id')
|
id = @get('id')
|
||||||
Travis.Build.byRepositoryId id, event_type: 'push'
|
builds = Travis.Build.byRepositoryId id, event_type: 'push'
|
||||||
Travis.Build.filter (data) -> parseInt(data.get('repository_id')) == id && !data.get('pull_request')
|
array = Travis.ExpandableRecordArray.create
|
||||||
|
type: Travis.Build
|
||||||
|
content: Ember.A([])
|
||||||
|
store: @get('store')
|
||||||
|
|
||||||
|
array.load(builds)
|
||||||
|
|
||||||
|
array
|
||||||
).property()
|
).property()
|
||||||
|
|
||||||
pullRequests: (->
|
pullRequests: (->
|
||||||
id = @get('id')
|
id = @get('id')
|
||||||
Travis.Build.byRepositoryId id, event_type: 'pull_request'
|
builds = Travis.Build.byRepositoryId id, event_type: 'pull_request'
|
||||||
Travis.Build.filter (data) -> parseInt(data.get('repository_id')) == id && data.get('pull_request')
|
array = Travis.ExpandableRecordArray.create
|
||||||
|
type: Travis.Build
|
||||||
|
content: Ember.A([])
|
||||||
|
store: @get('store')
|
||||||
|
|
||||||
|
array.load(builds)
|
||||||
|
|
||||||
|
array
|
||||||
).property()
|
).property()
|
||||||
|
|
||||||
branches: (->
|
branches: (->
|
||||||
|
|
|
@ -40,9 +40,7 @@
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
<p>
|
<p>
|
||||||
<button {{action showMore on="click" target="this" isVisibleBinding="hasMore"}}>
|
{{view view.ShowMoreButton}}
|
||||||
{{t builds.show_more}}
|
|
||||||
</button>
|
|
||||||
</p>
|
</p>
|
||||||
{{else}}
|
{{else}}
|
||||||
<div class="loading"><span>Loading</span></div>
|
<div class="loading"><span>Loading</span></div>
|
||||||
|
|
|
@ -1,12 +1,28 @@
|
||||||
@Travis.reopen
|
@Travis.reopen
|
||||||
BuildsView: Travis.View.extend
|
BuildsView: Travis.View.extend
|
||||||
templateName: 'builds/list'
|
templateName: 'builds/list'
|
||||||
buildsBinding: 'controller'
|
buildsBinding: 'controller.builds'
|
||||||
|
|
||||||
showMore: ->
|
showMore: ->
|
||||||
id = @get('controller.repository.id')
|
id = @get('controller.repository.id')
|
||||||
number = @get('controller.builds.lastObject.number')
|
number = @get('builds.lastObject.number')
|
||||||
Travis.Build.olderThanNumber(id, number)
|
@get('builds').load Travis.Build.olderThanNumber(id, number)
|
||||||
|
|
||||||
|
ShowMoreButton: Em.View.extend
|
||||||
|
tagName: 'button'
|
||||||
|
classNameBindings: ['isLoading']
|
||||||
|
attributeBindings: ['disabled']
|
||||||
|
isLoadingBinding: 'controller.builds.isLoading'
|
||||||
|
template: Em.Handlebars.compile('{{view.label}}')
|
||||||
|
|
||||||
|
disabledBinding: 'isLoading'
|
||||||
|
|
||||||
|
label: (->
|
||||||
|
if @get('isLoading') then 'Loading' else 'Show more'
|
||||||
|
).property('isLoading')
|
||||||
|
|
||||||
|
click: ->
|
||||||
|
@get('parentView').showMore()
|
||||||
|
|
||||||
BuildsItemView: Travis.View.extend
|
BuildsItemView: Travis.View.extend
|
||||||
tagName: 'tr'
|
tagName: 'tr'
|
||||||
|
|
29
assets/javascripts/lib/travis/expandable_record_array.coffee
Normal file
29
assets/javascripts/lib/travis/expandable_record_array.coffee
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
Travis.ExpandableRecordArray = DS.RecordArray.extend
|
||||||
|
isLoaded: false
|
||||||
|
isLoading: false
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
self.set 'isLoading', false
|
||||||
|
self.set 'isLoaded', true
|
||||||
|
|
||||||
|
array.addObserver 'isLoaded', observer
|
||||||
|
|
||||||
|
pushObject: (record) ->
|
||||||
|
ids = @get 'content'
|
||||||
|
id = record.get 'id'
|
||||||
|
clientId = record.get 'clientId'
|
||||||
|
|
||||||
|
return if ids.contains clientId
|
||||||
|
|
||||||
|
ids.pushObject clientId
|
File diff suppressed because one or more lines are too long
8
public/javascripts/application.min.js
vendored
8
public/javascripts/application.min.js
vendored
File diff suppressed because one or more lines are too long
|
@ -1 +1 @@
|
||||||
9937c24d
|
73435ff6
|
Loading…
Reference in New Issue
Block a user