Skip to content

Commit 16af9f0

Browse files
committed
add signout component
1 parent 7ae9e3c commit 16af9f0

7 files changed

Lines changed: 50 additions & 13 deletions

File tree

app/components/signout-link.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import Ember from 'ember';
2+
3+
export default Ember.Component.extend({
4+
currentUserObserver: function() {
5+
if(this.get('currentUser')){
6+
var currentUser = this.get('currentUser');
7+
if(this.get('avatarAttribute')){
8+
this.setProperties({
9+
isAvatarPresent: !Ember.isEmpty(currentUser.get(this.get('avatarAttribute'))),
10+
avatarUrl: currentUser.get(this.get('avatarAttribute')).get('thumb_url')
11+
});
12+
}
13+
this.set('username', currentUser.get(this.get('nameAttribute')));
14+
}
15+
}.observes('currentUser'),
16+
actions:{
17+
signout: function(){
18+
this.sendAction('signoutAction');
19+
}
20+
}
21+
});

app/styles/app.css

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{{#if currentUser}}
2+
{{#if isAvatarPresent}}
3+
<ul class="nav navbar-nav navbar-right">
4+
<li class="dropdown">
5+
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
6+
<img {{bind-attr src=avatarUrl}} class="profile-image img-circle avatar"> {{username}} <b class="caret"></b></a>
7+
<ul class="dropdown-menu">
8+
<li>{{#link-to 'users.edit' currentUser}}<i class="glyphicon glyphicon-cog"></i> Account{{/link-to}}</li>
9+
<li class="divider"></li>
10+
<li><a {{ action 'signout' }} href="#"><i class="glyphicon glyphicon-log-out"></i> Sign-out</a></li>
11+
</ul>
12+
</li>
13+
</ul>
14+
{{else}}
15+
<p class="navbar-text navbar-right">
16+
<a {{ action 'signout' }} href="#">
17+
Signout
18+
<i class="glyphicon glyphicon-log-out"></i>
19+
</a>
20+
</p>
21+
<p class="navbar-text navbar-right">
22+
Signed in as&nbsp;
23+
<span class='username'>{{username}}</span>
24+
</p>
25+
{{/if}}
26+
{{/if}}

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ module.exports = {
33

44
included: function(app) {
55
this.app = app;
6+
app.import('vendor/signout-link.css');
67
}
78
};

server/mocks/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ module.exports = function(app) {
4343

4444
appRouter.get('/users/:id', function(req, res) {
4545
if(req.params.id === 'admin'){
46-
return res.send({user: {id: 1, name: 'testuser', lat: 50, long: 40, zoom: 3}});
46+
return res.send({user: {id: 1, name: 'Admin', lat: 50, long: 40, zoom: 3, avatar_id: 1}, avatars: [{id: 1, thumb_url: 'http://placehold.it/50x50', url: 'http://placehold.it/350x350'}]});
4747
}
4848
res.send({user: {id: req.params.id, name: 'testuser', lat: 50, long: 40, zoom: 3}});
4949
});

tests/dummy/app/styles/app.scss

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/dummy/app/templates/admin/navigation.hbs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,7 @@
88
{{/each}}
99
</ul>
1010
{{#if session.isAuthenticated}}
11-
<p class="navbar-text navbar-right">
12-
<a {{ action 'invalidateSession' }} href="#">
13-
Signout
14-
<i class="glyphicon glyphicon-log-out"></i>
15-
</a>
16-
</p>
17-
<p class="navbar-text navbar-right">Signed in as <span class='username'>{{shared.currentUser.name}}</span></p>
11+
{{signout-link signoutAction='invalidateSession' currentUser=shared.currentUser nameAttribute='name' avatarAttribute='avatar'}}
1812
{{/if}}
1913
</div>
2014
</div>

0 commit comments

Comments
 (0)