Merge pull request #399 from travis-ci/lp-query-more-branches

Fix owner/branches/dashbaord after api cleanup
This commit is contained in:
Lisa P 2015-10-14 15:37:36 +02:00
commit a048e1fca1
15 changed files with 93 additions and 67 deletions

View File

@ -2,9 +2,12 @@
Component = Ember.Component.extend
actions: {
actions:
toggleOrgFilter: () ->
@toggleProperty('showFilter')
false
select: (org) ->
@toggleProperty('showFilter')
@sendAction('action', org)
}
`export default Component`

View File

@ -7,15 +7,16 @@ BranchesController = Ember.Controller.extend
defaultBranch: (->
repos = @get('model')
output = repos.filter (item, index) ->
item if item.repository.default_branch['@href'] == item['@href']
output[0]
item if item.default_branch == true
if output.length
output[0]
).property('model')
activeBranches: (->
repos = @get('model')
repos = repos.filter (item, index) ->
item if item.exists_on_github == true && item.repository.default_branch['@href'] != item['@href']
.sortBy('last_build.finished_at')
item if item.exists_on_github == true && item.default_branch == false
.sortBy('default_branch.last_build.finished_at')
.reverse()
).property('model')

View File

@ -12,7 +12,8 @@ Controller = Ember.Controller.extend
org = @get('org')
repos = repos.filter (item, index) ->
item.get('default_branch.last_build') != null
if item.get('default_branch')
item.get('default_branch.last_build') != null
.sortBy('default_branch.last_build.finished_at')
.reverse()

View File

@ -8,7 +8,8 @@ Controller = Ember.Controller.extend
data = @get('model')
repos = data.repositories.filter (item, index) ->
if item.default_branch.last_build
if item.active
console.log(item)
item
repos.sortBy('default_branch.last_build.finished_at').reverse()

View File

@ -8,12 +8,15 @@ Route = TravisRoute.extend
apiEndpoint = config.apiEndpoint
repoId = @modelFor('repo').get('id')
allTheBranches = Ember.ArrayProxy.create()
options = {}
if @get('auth.signedIn')
options.headers = { Authorization: "token #{@auth.token()}" }
$.ajax("#{apiEndpoint}/v3/repo/#{repoId}/branches?include=build.commit&limit=100", options).then (response) ->
response.branches
allTheBranches = response.branches
allTheBranches
activate: () ->
$('.tab.tabs--main li').removeClass('active')

View File

@ -2,12 +2,5 @@
Route = TravisRoute.extend
needsAuth: true
# activate: ->
# @get('stylesheetsManager').disable('main')
# @get('stylesheetsManager').enable('dashboard')
# deactivate: ->
# @get('stylesheetsManager').enable('main')
# @get('stylesheetsManager').disable('dashboard')
`export default Route`

View File

@ -7,22 +7,16 @@ Route = TravisRoute.extend
filter: { replace: true }
model: ->
apiEndpoint = config.apiEndpoint
$.ajax(apiEndpoint + '/v3/repos?repository.active=true&include=build.commit', {
$.ajax(apiEndpoint + '/v3/repos?repository.active=true&include=repository.default_branch,build.commit', {
headers: {
Authorization: 'token ' + @auth.token()
}
}).then (response) ->
response.repositories.sortBy('last_build.finished_at').filter( (repo) ->
repo.last_build
).sort( (a, b) ->
if !a.last_build.finished_at || a.last_build.finished_at > b.last_build.finished_at
return -1
else if !b.last_build.finished_at || b.last_build.finished_at > a.last_build.finished_at
return 1
else
return 0
response.repositories.filter( (repo) ->
if repo.default_branch
repo.default_branch.last_build
).map( (repo) ->
Ember.Object.create(repo)
)
).sortBy('default_branch.last_build.finished_at')
`export default Route`

View File

@ -11,7 +11,7 @@ Route = TravisRoute.extend
options = {}
if @get('auth.signedIn')
options.headers = { Authorization: "token #{@auth.token()}" }
$.ajax(config.apiEndpoint + "/v3/owner/#{params.owner}", options)
$.ajax(config.apiEndpoint + "/v3/owner/#{params.owner}?include=organization.repositories,repository.default_branch,build.commit", options)
beforeModel: ->
@controllerFor('loading').set('layoutName', 'simple')

View File

@ -13,6 +13,7 @@ Route = TravisRoute.extend
options = {}
if @get('auth.signedIn')
options.headers = { Authorization: "token #{@auth.token()}" }
$.ajax(config.apiEndpoint + "/v3/owner/#{transition.params.owner.owner}?include=user.repositories,organization.repositories,build.commit,repository.active", options)
$.ajax(config.apiEndpoint + "/v3/owner/#{transition.params.owner.owner}?include=organization.repositories,repository.default_branch,build.commit", options).then (response) ->
response
`export default Route`

View File

@ -83,9 +83,8 @@ $dropdown-border: #C3D9DB
a
font-weight: 600
.filter-current:hover ~ .filter-dropdown,
.filter-dropdown:hover
display: block
&.is-open
display: block

View File

@ -9,7 +9,7 @@
<div class="one-line fade-out">
<div class="row-request">
<div class="row-item">
{{#link-to "build" repo.owner.login repo.name repo.last_build.id}}
{{#link-to "build" repo.owner.login repo.name repo.default_branch.last_build.id}}
{{request-icon build=repo.default_branch.last_build}}
<span class="label-align">#{{repo.default_branch.last_build.number}} {{repo.default_branch.last_build.state}} on {{repo.default_branch.name}}</span>
{{/link-to}}

View File

@ -3,7 +3,7 @@
{{#if orgs.isLoading}}
{{loading-indicator}}
{{else}}
<a href="" title="">
<a {{action 'toggleOrgFilter'}} title="">
{{#if selected }}
<img src="{{selected.avatar_url}}" alt="{{org.login}}">
{{#if selected.name}}
@ -17,7 +17,7 @@
</a><span class="icon-arrow-down"></span>
{{/if}}
</div>
<ul class="filter-dropdown">
<ul class="filter-dropdown {{if showFilter 'is-open'}}">
{{#if selected }}
<li><a title="" {{action 'select'}}>All organizations</a></li>
{{/if}}

View File

@ -96,5 +96,5 @@
</div>
</div>
{{else}}
<p>there is no build</p>
<p class="row-item">There is no build on the default branch yet.</p>
{{/if}}

View File

@ -19,6 +19,8 @@
<ul class="dashboard-active">
{{#each repo in filteredRepositories}}
{{dashboard-row repo=repo}}
{{else}}
{{no-repos}}
{{/each}}
</ul>
{{!-- <hr> --}}

View File

@ -13,44 +13,72 @@ module 'Acceptance: Dashboard',
server = new Pretender ->
@get('/v3/repos', (request) ->
data = {
"@type": "repositories",
"repositories": [{
"repositories": [
"@type": "repository",
"active": true,
"id": 1,
"name": "travis-web",
"slug": "travis-ci/travis-web",
"description": "The Ember web client for Travis CI",
"github_language": "CoffeeScript",
"private": false,
"owner": {
"@type": "organization",
"id": 1,
"login": "travis-ci"
"@href": "/v3/repo/4289199",
"@representation": "standard",
"@permissions": {
"read": true,
"enable": true,
"disable": true,
"create_request": true
},
"last_build": {
"@type": "build",
"id": 1,
"number": "1",
"state": "passed",
"duration": 20,
"started_at": "2015-02-05T09:58:31Z",
"finished_at": "2015-02-05T10:09:10Z"
}
}, {
"@type": "repository",
"id": 4289199,
"name": "jupiter-brain",
"slug": "travis-ci/jupiter-brain",
"description": "Jupiter Brain manages servers",
"github_language": "Go",
"active": true,
"id": 2,
"name": "travis-test",
"slug": "travis-ci/travis-test",
"private": false,
"owner": {
"@type": "organization",
"id": 87,
"login": "travis-ci"
"login": "travis-ci",
"@href": "/v3/org/87"
},
"last_build": null
}]
"default_branch": {
"@type": "branch",
"@href": "/v3/repo/4289199/branch/master",
"@representation": "standard",
"name": "master",
"repository": {
"@href": "/v3/repo/4289199"
},
"default_branch": true,
"exists_on_github": true,
"last_build": {
"@type": "build",
"@href": "/v3/build/81667484",
"@representation": "minimal",
"id": 81667484,
"number": "77",
"state": "passed",
"duration": 107,
"event_type": "push",
"previous_state": "passed",
"started_at": "2015-09-22T20:56:03Z",
"finished_at": "2015-09-22T20:57:50Z",
"commit": {
"@type": "commit",
"@representation": "standard",
"id": 23259185,
"sha": "39f658654f2d458af074b600d11e47547988ee56",
"ref": "refs/heads/master",
"message": "Merge pull request #6 from travis-ci/hh-circuit-breaker\n\nvsphere: add circuit breaker between Jupiter Brain and vSphere",
"compare_url": "https://github.com/travis-ci/jupiter-brain/compare/923f220a494f...39f658654f2d",
"committed_at": "2015-09-22T20:55:43Z",
"committer": {
"name": "emma trimble",
"avatar_url": "https://0.gravatar.com/avatar/e3058e8bba1f2b87defccd5695070782"
},
"author": {
"name": "emma trimble",
"avatar_url": "https://0.gravatar.com/avatar/e3058e8bba1f2b87defccd5695070782"
}
}
}
}
]
}
return [200, { "Content-Type": "application/json" }, JSON.stringify(data)]
)
@ -64,4 +92,4 @@ test 'visiting /dashboard', ->
andThen ->
equal find('.dashboard-active .dashboard-row').length, 1, 'there should be one repo displayed on dashboard'
equal find('.dashboard-active .dashboard-row h2').text(), 'travis-web', 'travis-web repository should be displayed'
equal find('.dashboard-active .dashboard-row h2').text(), 'jupiter-brain', 'jupiter-brain repository should be displayed'