@@ -6,22 +6,45 @@ export default Ember.Mixin.create({
66 login : null ,
77 size : 40 ,
88
9- name : 'Loading...' ,
9+ name : null ,
10+ description : 'Loading...' ,
1011 _avatarUrl : null ,
1112
1213 loginOrTypeChanged : function ( ) {
1314 var self = this ;
15+ var session = this . get ( 'session' ) ;
1416
15- var cache = self . get ( 'session' ) . get ( 'avatarCache' ) || { } ;
16-
17+ var cache = session . get ( 'avatarCache' ) || { } ;
1718 var login = this . get ( 'login' ) ;
18- if ( ! login )
19+ var type = this . get ( 'type' ) ;
20+ var key = type + ':' + login ;
21+
22+ if ( ! type || ! login )
1923 {
2024 return ;
2125 }
2226
23- var type = this . get ( 'type' ) ;
24- var key = type + ':' + login ;
27+ // Teams can't be looked up without auth...
28+ if ( type === 'team' )
29+ {
30+ var entry = ( session . get ( 'teams' ) || [ ] ) . filterProperty ( 'name' , login ) [ 0 ] ;
31+ this . set ( '_avatarUrl' , null ) ;
32+ if ( entry )
33+ {
34+ this . set ( 'name' , entry . name ) ;
35+ this . set ( 'description' , entry . org + ' team' ) ;
36+ }
37+ else
38+ {
39+ this . set ( 'name' , '(' + login + ')' ) ;
40+ this . set ( 'description' , '(Unknown team id)' ) ;
41+ }
42+
43+ return ;
44+ }
45+
46+ this . set ( 'name' , login ) ;
47+
2548
2649 if ( cache [ key ] )
2750 {
@@ -30,21 +53,21 @@ export default Ember.Mixin.create({
3053 else
3154 {
3255 var url = C . GITHUB_API_URL + type + 's/' + login ;
33- Ember . $ . ajax ( { url : url , dataType : 'json' } ) . then ( function ( body ) {
56+ Ember . $ . ajax ( { url : url , dataType : 'json' } ) . then ( ( body ) => {
3457 cache [ key ] = body ;
3558
3659 // Sub-keys don't get automatically persisted to the session...
37- self . get ( ' session' ) . set ( 'avatarCache' , cache ) ;
60+ session . set ( 'avatarCache' , cache ) ;
3861
3962 gotInfo ( body ) ;
40- } , function ( ) {
41- self . sendAction ( 'notFound' , login ) ;
63+ } , ( ) => {
64+ this . sendAction ( 'notFound' , login ) ;
4265 } ) ;
4366 }
4467
4568 function gotInfo ( body )
4669 {
47- self . set ( 'name ' , body . name ) ;
70+ self . set ( 'description ' , body . name ) ;
4871 self . set ( '_avatarUrl' , body . avatar_url ) ;
4972 }
5073 } . observes ( 'login' , 'type' ) . on ( 'init' ) ,
0 commit comments