Refactor sign in related templates, fix indicator in auth template

This commit is contained in:
Piotr Sarnacki 2013-08-05 03:20:28 +02:00
parent 218a078164
commit c79725d0e9
6 changed files with 51 additions and 24 deletions

View File

@ -1,7 +1,7 @@
unless window.TravisApplication unless window.TravisApplication
window.TravisApplication = Em.Application.extend(Ember.Evented, window.TravisApplication = Em.Application.extend(Ember.Evented,
LOG_TRANSITIONS: true, LOG_TRANSITIONS: true,
authStateBinding: 'auth.state' authState: Ember.computed.alias('auth.state')
signedIn: (-> @get('authState') == 'signed-in' ).property('authState') signedIn: (-> @get('authState') == 'signed-in' ).property('authState')
mappings: (-> mappings: (->
@ -58,6 +58,10 @@ unless window.TravisApplication
signOut: -> signOut: ->
@get('auth').signOut() @get('auth').signOut()
signingIn: (->
Travis.get('authState') == 'signing-in'
).property('authState')
receive: (event, data) -> receive: (event, data) ->
[name, type] = event.split(':') [name, type] = event.split(':')

View File

@ -5,6 +5,26 @@ Travis.TopController = Em.Controller.extend
needs: ['currentUser'] needs: ['currentUser']
userBinding: 'controllers.currentUser' userBinding: 'controllers.currentUser'
userName: (->
@get('user.name') || @get('user.login')
).property('user.login', 'user.name')
gravatarUrl: (->
"#{location.protocol}//www.gravatar.com/avatar/#{@get('user.gravatarId')}?s=48&d=mm"
).property('user.gravatarId')
signedIn: (->
Travis.get('authState') == 'signed-in'
).property('Travis.authState')
signedOut: (->
Travis.get('authState') == 'signed-out'
).property('Travis.authState')
signingIn: (->
Travis.get('authState') == 'signing-in'
).property('Travis.authState')
Travis.ApplicationController = Em.Controller.extend Travis.ApplicationController = Em.Controller.extend
templateName: 'layouts/home' templateName: 'layouts/home'

View File

@ -26,6 +26,8 @@ Ember.Route.reopen
error: (error) -> error: (error) ->
if error == 'needs-auth' if error == 'needs-auth'
authController = @container.lookup('controller:auth') || @generateController('auth')
authController.set('redirected', true)
@transitionTo('auth') @transitionTo('auth')
else else
throw(error) throw(error)
@ -384,3 +386,6 @@ Travis.AuthRoute = Ember.Route.extend
setupController: -> setupController: ->
@container.lookup('controller:application').connectLayout('simple') @container.lookup('controller:application').connectLayout('simple')
deactivate: ->
@controllerFor('auth').set('redirected', false)

View File

@ -1,11 +1,12 @@
{{#if view.signingIn}} {{#if redirected}}
<h1>Signing in ...</h1> <p>You need to sign in to see this page.</p>
<p>
Trying to authenticate with GitHub.
</p>
{{else}}
<h1>Sign in</h1>
<p>
<a href="#" {{action "signIn" target="Travis"}}>Please sign in with GitHub.</a>
</p>
{{/if}} {{/if}}
<p>
<a href="#" {{action "signIn" target="Travis"}}>
{{#if Travis.signingIn}}
Signing in...
{{else}}
Sign in with GitHub.
{{/if}}
</a>
</p>

View File

@ -31,9 +31,15 @@
</li> </li>
<li {{bindAttr class="view.classProfile"}}> <li {{bindAttr class="view.classProfile"}}>
<p class="handle"> <p class="handle">
<a class="signed-out" href="#" {{action "signIn" target="Travis"}}>{{t layouts.top.github_login}}</a> {{#if signedOut}}
{{#linkTo "profile.index" class="signed-in"}}<img {{bindAttr src="view.gravatarUrl"}}>{{view.userName}}{{/linkTo}} <a class="signed-out" href="#" {{action "signIn" target="Travis"}}>{{t layouts.top.github_login}}</a>
<span class="signing-in">{{t layouts.top.signing_in}}</span> {{/if}}
{{#if signedIn}}
{{#linkTo "profile.index" class="signed-in"}}<img {{bindAttr src="gravatarUrl"}}/>{{userName}}{{/linkTo}}
{{/if}}
{{#if signingIn}}
<span class="signing-in">{{t layouts.top.signing_in}}</span>
{{/if}}
</p> </p>
<ul> <ul>
<li> <li>

View File

@ -3,15 +3,6 @@
templateName: 'layouts/top' templateName: 'layouts/top'
tabBinding: 'controller.tab' tabBinding: 'controller.tab'
userBinding: 'controller.user'
userName: (->
@get('user.name') || @get('user.login')
).property('user.login', 'user.name')
gravatarUrl: (->
"#{location.protocol}//www.gravatar.com/avatar/#{@get('user.gravatarId')}?s=48&d=mm"
).property('user.gravatarId')
# hrm. how to parametrize bindAttr? # hrm. how to parametrize bindAttr?
classHome: (-> classHome: (->
@ -25,7 +16,7 @@
classProfile: (-> classProfile: (->
classes = ['profile menu'] classes = ['profile menu']
classes.push('active') if @get('tab') == 'profile' classes.push('active') if @get('tab') == 'profile'
classes.push(Travis.get('authState')) classes.push(Travis.get('authState') || 'signed-out')
classes.join(' ') classes.join(' ')
).property('tab', 'Travis.authState') ).property('tab', 'Travis.authState')