add org filter to dashboard, prepare sync button

This commit is contained in:
Lisa Passing 2015-02-26 17:49:27 +01:00
parent 35851ef34b
commit faca83ba5f
7 changed files with 94 additions and 15 deletions

View File

@ -0,0 +1,10 @@
`import Ember from 'ember'`
Component = Ember.Component.extend
actions: {
select: (org) ->
@sendAction('action', org)
}
`export default Component`

View File

@ -0,0 +1,10 @@
`import Ember from 'ember'`
Component = Ember.Component.extend
actions: {
sync: ->
console.log(@get('user'));
}
`export default Component`

View File

@ -1,12 +1,19 @@
`import Ember from 'ember'`
`import config from 'travis/config/environment'`
Controller = Ember.Controller.extend
#queryParams: ['filter']
queryParams: ['org']
filter: null
org: null
filteredRepositories: (->
filter = @get('filter')
repos = @get('model')
org = @get('org')
if org
repos = repos.filter (item, index) ->
item.get('owner.login') == org
if Ember.isBlank(filter)
repos
@ -14,16 +21,45 @@ Controller = Ember.Controller.extend
repos.filter (item, index) ->
item.slug.match(new RegExp(filter))
).property('filter', 'model')
).property('filter', 'model', 'org')
updateFilter: () ->
value = @get('_lastFilterValue')
@transitionToRoute queryParams: { filter: value }
@set('filter', value)
selectedOrg: (->
@get('orgs').findBy('login', @get('org'))
).property('org', 'orgs.[]')
orgs: (->
orgs = Ember.ArrayProxy.create(
content: []
isLoading: true
)
apiEndpoint = config.apiEndpoint
$.ajax(apiEndpoint + '/v3/orgs', {
headers: {
Authorization: 'token ' + @auth.token()
}
}).then (response) ->
array = response.organizations.map( (org) ->
Ember.Object.create(org)
)
orgs.set('content', array)
orgs.set('isLoading', false)
orgs
).property()
actions:
updateFilter: (value) ->
@set('_lastFilterValue', value)
Ember.run.throttle this, @updateFilter, [], 200, false
selectOrg: (org) ->
login = if org then org.get('login') else null
@set('org', login)
`export default Controller`

View File

@ -0,0 +1,28 @@
<div class="filter filter--org">
<div class="filter-current">
{{#if orgs.isLoading}}
<span class="loading"></span>
{{else}}
<a href="" title="">
{{#if selected }}<img src="https://placehold.it/30x30" alt="">{{selected.name}} {{else}} All organizations {{/if}}
</a><span class="icon-arrow-down"></span>
{{/if}}
</div>
<ul class="filter-dropdown">
{{#if selected }}
<li><a href="#" title="" {{action 'select'}}>All organizations</a></li>
{{/if}}
{{#each org in orgs}}
<li>
<a href="#" title="" {{action 'select' org}}><img src="https://placehold.it/30x30" alt="">
{{#if org.name }}
{{org.name}}
{{else}}
{{org.login}}
{{/if}}
</a>
</li>
{{/each}}
</ul>
</div>

View File

@ -0,0 +1,2 @@
<button {{action sync}}>HERE</button>
{{user.syncedAt}}

View File

@ -1,20 +1,13 @@
<div id="filters" class="section section--white section--maxheight">
<div class="row">
<div class="filter filter--org">
<div class="filter-current">
<img src="https://placehold.it/30x30" alt="">something else</a><span class="icon-arrow-down"></span>
</div>
<ul class="filter-dropdown">
<li><a href="#" title="">All organizations</a></li>
<li class="is-selected"><a href="#" title=""><img src="https://placehold.it/30x30" alt="">something else</a></li>
<li><a href="#" title=""><img src="https://placehold.it/30x30" alt="">something</a></li>
<li><a href="#" title=""><img src="https://placehold.it/30x30" alt="">eurucamp</a></li>
</ul>
{{orgs-filter orgs=orgs selected=selectedOrg action="selectOrg"}}
<div class="">
{{sync-button user=auth.currentUser}}
</div>
<div class="search">
{{!-- <div class="search">
{{filter-input placeholder="Search all repositories" class="search-field"
action="updateFilter" on="key-up"}}
</div>
</div> --}}
</div>
</div>

View File

@ -3,6 +3,6 @@
Location = Ember.HistoryLocation.extend
getURL: ->
location = @get('location')
location.pathname + location.hash
location.pathname + location.search + location.hash
`export default Location`