Change requests items to use components

This commit is contained in:
Piotr Sarnacki 2015-05-08 17:00:53 +02:00
parent d2dd744811
commit 81264689f8
6 changed files with 91 additions and 70 deletions

View File

@ -0,0 +1,41 @@
`import Ember from 'ember'`
`import config from 'travis/config/environment'`
RequestsItemComponent = Ember.Component.extend
classNames: ['tile', 'tile--jobs', 'row']
classNameBindings: ['requestClass']
tagName: 'li'
requestClass: (->
if @get('request.isAccepted')
'accepted'
else
'rejected'
).property('content.isAccepted')
type: (->
if @get('request.isPullRequest')
'pull_request'
else
'push'
).property('request.isPullRequest')
status: (->
if @get('request.isAccepted')
'Accepted'
else
'Rejected'
).property('request.isAccepted')
message: (->
message = @get('request.message')
if config.pro && message == "private repository"
''
else if !message
'Build created successfully '
else
message
).property('request.message')
`export default RequestsItemComponent`

View File

@ -2,12 +2,11 @@
`import { githubRepo } from 'travis/utils/urls'`
Controller = Ember.Controller.extend
needs: ['repos', 'currentUser', 'build', 'request', 'job']
needs: ['repos', 'currentUser', 'build', 'job']
currentUserBinding: 'controllers.currentUser.model'
build: Ember.computed.alias('controllers.build.build')
job: Ember.computed.alias('controllers.job.job')
request: Ember.computed.alias('controllers.request.model')
slug: (-> @get('repo.slug') ).property('repo.slug')
isLoading: (-> @get('repo.isLoading') ).property('repo.isLoading')

View File

@ -1,35 +0,0 @@
`import Ember from 'ember'`
Controller = Ember.ObjectController.extend
requestClass: (->
if @get('content.isAccepted')
'accepted'
else
'rejected'
).property('content.isAccepted')
type: (->
if @get('isPullRequest')
'pull_request'
else
'push'
).property('isPullRequest')
status: (->
if @get('isAccepted')
'Accepted'
else
'Rejected'
).property('isAccepted')
message: (->
message = @get('model.message')
if @config.pro && message == "private repository"
''
else if !message
'Build created successfully '
else
message
).property('model.message')
`export default Controller`

View File

@ -0,0 +1,30 @@
<div class="tile-status tile-status--job">
<span class="icon icon--job {{requestClass}}"></span>
</div>
<p class="jobs-item requests-time column">{{format-time request.created_at}}</p>
<p class="jobs-item requests-branch column">
<span class="icon icon--grey {{type}}"></span>
{{#if request.isPullRequest}}
<strong>#{{request.pullRequestNumber}}</strong>
{{else}}
<strong>{{request.branchName}}</strong>
{{/if}}
{{github-commit-link request.repo.slug request.commit.sha}}
</p>
<p class="jobs-item requests-commit column">
{{{format-message request.commit.message short="true" repoBinding=request.build.repo}}}
</p>
<p class="jobs-item requests-build column">
{{#if request.build}}
<span class="icon icon-hash"></span>
{{#link-to "build" request.build}}
{{request.build.number}}{{/link-to}}
{{else}}
-
{{/if}}
</p>
<p class="jobs-item requests-message column">{{message}}</p>

View File

@ -7,38 +7,7 @@
{{/if}}
<ul class="requests">
{{#each controller itemController="request"}}
<li {{bind-attr class=":tile :tile--jobs :row requestClass" }}>
<div class="tile-status tile-status--job">
<span {{bind-attr class=":icon :icon--job requestClass"}}></span>
</div>
<p class="jobs-item requests-time column">{{format-time created_at}}</p>
<p class="jobs-item requests-branch column">
<span {{bind-attr class=":icon :icon--grey type"}}></span>
{{#if isPullRequest}}
<strong>#{{pullRequestNumber}}</strong>
{{else}}
<strong>{{branchName}}</strong>
{{/if}}
{{github-commit-link repo.slug commit.sha}}
</p>
<p class="jobs-item requests-commit column">
{{{format-message commit.message short="true" repoBinding=build.repo}}}
</p>
<p class="jobs-item requests-build column">
{{#if build}}
<span class="icon icon-hash"></span>
{{#link-to "build" build}}
{{build.number}}{{/link-to}}
{{else}}
-
{{/if}}
</p>
<p class="jobs-item requests-message column">{{message}}</p>
</li>
{{#each model as |request| }}
{{requests-item request=request}}
{{/each}}
</ul>

View File

@ -0,0 +1,17 @@
`import { test, moduleForComponent } from 'ember-qunit'`
moduleForComponent 'requests-item', {
# specify the other units that are required for this test
# needs: ['component:foo', 'helper:bar']
}
test 'it renders', (assert) ->
assert.expect 2
# creates the component instance
component = @subject()
assert.equal component._state, 'preRender'
# renders the component to the page
@render()
assert.equal component._state, 'inDOM'