Use lastBuild from defaultBranch on repository

One thing that is not standard here is a serializer for branch, which
uses @href as id. At this point branches don't have ids and ember-data
needs one, so using @href is the easiest way.
This commit is contained in:
Piotr Sarnacki 2015-10-19 16:28:57 +02:00
parent d9cff6e8b4
commit 47439657a1
12 changed files with 49 additions and 58 deletions

View File

@ -14,9 +14,9 @@ export default V3Adapter.extend({
}
if(hash.data.include) {
hash.data.include += ',repository.last_build,build.commit';
hash.data.include += ',repository.default_branch,branch.last_build,build.commit';
} else {
hash.data.include = 'repository.last_build,build.commit';
hash.data.include = 'repository.default_branch,branch.last_build,build.commit';
}
return this._super(url, type, hash);

View File

@ -15,6 +15,10 @@ ReposListItemComponent = Ember.Component.extend Polling,
@get('repo') == @get('selectedRepo')
).property('selectedRepo')
color: (->
colorForState(@get('repo.defaultBranch.lastBuild.state'))
).property('repo.defaultBranch.lastBuild.state')
scrollTop: (->
if (window.scrollY > 0)
$('html, body').animate({scrollTop: 0}, 200)

View File

@ -77,15 +77,15 @@ Controller = Ember.Controller.extend
Ember.run.scheduleOnce('actions', this, @_lastBuildDidChange);
_lastBuildDidChange: ->
build = @get('repo.lastBuild')
build = @get('repo.defaultBranch.lastBuild')
@set('build', build)
stopObservingLastBuild: ->
@removeObserver('repo.lastBuild', this, 'lastBuildDidChange')
@removeObserver('repo.defaultBranch.lastBuild', this, 'lastBuildDidChange')
observeLastBuild: ->
@lastBuildDidChange()
@addObserver('repo.lastBuild', this, 'lastBuildDidChange')
@addObserver('repo.defaultBranch.lastBuild', this, 'lastBuildDidChange')
connectTab: (tab) ->
# TODO: such implementation seems weird now, because we render

View File

@ -2,25 +2,6 @@
`import Model from 'travis/models/model'`
Branch = 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()
commit: DS.belongsTo('commit')
repo: (->
@store.find('repo', @get('repositoryId')) if @get('repositoryId')
).property('repositoryId')
updateTimes: ->
@notifyPropertyChange 'started_at'
@notifyPropertyChange 'finished_at'
lastBuild: DS.belongsTo('build')
`export default Branch`

View File

@ -13,10 +13,12 @@ Repo = Model.extend
private: DS.attr('boolean')
githubLanguage: DS.attr()
active: DS.attr()
lastBuild: DS.belongsTo('build')
#lastBuild: DS.belongsTo('build')
defaultBranch: DS.belongsTo('branch')
withLastBuild: ->
@filter( (repo) -> repo.get('lastBuild') )
@filter( (repo) -> repo.get('defaultBranch.lastBuild') )
sshKey: (->
@store.find('ssh_key', @get('id'))
@ -83,27 +85,21 @@ Repo = Model.extend
(@get('slug') || '').split('/')[1]
).property('slug')
lastBuildDuration: (->
duration = @get('_lastBuildDuration')
duration = durationFromHelper(@get('lastBuildStartedAt'), @get('lastBuildFinishedAt')) unless duration
duration
).property('_lastBuildDuration', 'lastBuildStartedAt', 'lastBuildFinishedAt')
sortOrderForLandingPage: (->
state = @get('lastBuildState')
state = @get('defaultBranch.lastBuild.state')
if state != 'passed' && state != 'failed'
0
else
parseInt(@get('lastBuildId'))
).property('lastBuildId', 'lastBuildState')
parseInt(@get('defaultBranch.lastBuild.id'))
).property('defaultBranch.lastBuild.id', 'defaultBranch.lastBuild.state')
sortOrder: (->
# cuz sortAscending seems buggy when set to false
if lastBuildFinishedAt = @get('lastBuildFinishedAt')
if lastBuildFinishedAt = @get('defaultBranch.lastBuild.finishedAt')
- new Date(lastBuildFinishedAt).getTime()
else
- new Date('9999').getTime() - parseInt(@get('lastBuildId'))
).property('lastBuildFinishedAt', 'lastBuildId')
- new Date('9999').getTime() - parseInt(@get('defaultBranch.lastBuild.id'))
).property('defaultBranch.lastBuild.state', 'defaultBranch.lastBuild.finishedAt')
stats: (->
if @get('slug')
@ -114,7 +110,7 @@ Repo = Model.extend
).property('slug')
updateTimes: ->
@notifyPropertyChange 'lastBuildDuration'
@notifyPropertyChange 'defaultBranch.lastBuild.duration'
regenerateKey: (options) ->
@get('ajax').ajax '/repos/' + @get('id') + '/key', 'post', options
@ -153,7 +149,7 @@ Repo.reopenClass
withLastBuild: (store) ->
repos = store.filter('repo', {}, (build) ->
build.get('lastBuild')
build.get('defaultBranch.lastBuild')
)
repos.then () ->

View File

@ -6,7 +6,7 @@ Route = TravisRoute.extend
@controllerFor('repo').activate('current')
renderTemplate: ->
if @modelFor('repo').get('lastBuild')
if @modelFor('repo').get('defaultBranch.lastBuild')
@render 'build'
else
@render 'builds/not_found'

12
app/serializers/branch.js Normal file
View File

@ -0,0 +1,12 @@
import Ember from 'ember';
import V3Serializer from 'travis/serializers/v3';
export default V3Serializer.extend({
extractAttributes(klass, payload) {
payload.id = payload['@href'];
return this._super(...arguments);
},
extractId(modelClass, resourceHash) {
return resourceHash.id || resourceHash['@href'];
}
});

View File

@ -3,8 +3,5 @@
Serializer = V2FallbackSerializer.extend
isNewSerializerAPI: true
attrs: {
_lastBuildDuration: { key: 'last_build_duration' }
}
`export default Serializer`

View File

@ -52,7 +52,7 @@ export default DS.JSONSerializer.extend({
if(type = payload['@type']) {
items = payload[type];
} else {
items = payload[primaryModelClass.modelName + 's'];
items = payload[primaryModelClass.modelName.underscore() + 's'];
}
documentHash.data = items.map((item) => {

View File

@ -20,6 +20,7 @@ Store = DS.Store.extend
canHandleEvent: (event, data) ->
[name, type] = event.split(':')
auth = @get('auth')
if event != 'job:log' && auth.get('signedIn') &&
!config.pro && !config.enterprise
# if recent repos hasn't been opened yet, we can safely

View File

@ -1,19 +1,19 @@
<div class="tile {{repo.lastBuild.state}}">
<h2 class="tile-title {{repo.lastBuild.state}}">
<div class="tile {{repo.defaultBranch.lastBuild.state}}">
<h2 class="tile-title {{repo.defaultBranch.lastBuild.state}}">
{{#if repo.slug}}
{{#link-to "repo" repo}}
{{status-icon status=repo.lastBuildState}}
{{status-icon status=repo.defaultBranch.lastBuild.state}}
<span class="label-align">{{repo.slug}}</span>
{{/link-to}}
{{/if}}
</h2>
{{#if repo.slug}}
{{#if repo.lastBuild.id}}
<p class="tile-title float-right {{repo.lastBuild.state}}">
{{#link-to "build" repo repo.lastBuild.id}}
{{#if repo.defaultBranch.lastBuild.id}}
<p class="tile-title float-right {{repo.defaultBranch.lastBuild.state}}">
{{#link-to "build" repo repo.defaultBranch.lastBuild.id}}
<span class="icon-hash"></span>
<span class="label-align">{{lastBuild.number}}</span>
<span class="label-align">{{repo.defaultBranch.lastBuild.number}}</span>
{{/link-to}}
</p>
{{/if}}
@ -22,16 +22,16 @@
<p>
<span class="icon-clock"></span>
<span class="label-align">Duration:
<abbr class="duration" title={{lastBuild.startedAt}}>
{{format-duration repo.lastBuild.duration}}
<abbr class="duration" title={{repo.defaultBranch.lastBuild.startedAt}}>
{{format-duration repo.defaultBranch.lastBuild.duration}}
</abbr></span>
</p>
<p>
<span class="icon-calendar"></span>
<span class="label-align">Finished:
<abbr class="finished_at timeago" title={{lastBuild.finishedAt}}>
{{format-time repo.lastBuild.finishedAt}}
<abbr class="finished_at timeago" title={{repo.defaultBranch.lastBuild.finishedAt}}>
{{format-time repo.defaultBranch.lastBuild.finishedAt}}
</abbr></span>
</p>
</div>

View File

@ -26,7 +26,7 @@
{{#if repo.active}}
{{outlet}}
{{else}}
{{#if repo.lastBuildId}}
{{#if repo.defaultBranch.lastBuild.id}}
{{outlet}}
{{else}}
{{not-active user=currentUser repo=repo}}