| 
									
										
										
										
											2017-10-23 16:50:48 -07:00
										 |  |  | import Component from '@ember/component'; | 
					
						
							|  |  |  | import ComputedProperty from '@ember/object/computed'; | 
					
						
							| 
									
										
										
										
											2017-09-10 19:31:54 -07:00
										 |  |  | import { avatar } from 'wherehows-web/constants'; | 
					
						
							| 
									
										
										
										
											2017-10-23 16:50:48 -07:00
										 |  |  | import { computed, get } from '@ember/object'; | 
					
						
							| 
									
										
										
										
											2017-09-10 19:31:54 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | const { fallbackUrl, url }: { fallbackUrl: string; url: string } = avatar; | 
					
						
							|  |  |  | const headlessUserName: string = 'wherehows'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-23 16:50:48 -07:00
										 |  |  | export default class UserAvatar extends Component { | 
					
						
							|  |  |  |   tagName = 'span'; | 
					
						
							| 
									
										
										
										
											2017-09-10 19:31:54 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /** | 
					
						
							| 
									
										
										
										
											2017-10-23 16:50:48 -07:00
										 |  |  |    * username for the user, e.g. ldap userName that can be used to construct the url | 
					
						
							|  |  |  |    * @type {string}  | 
					
						
							| 
									
										
										
										
											2017-09-10 19:31:54 -07:00
										 |  |  |    */ | 
					
						
							| 
									
										
										
										
											2017-10-25 03:04:36 -07:00
										 |  |  |   userName: string; | 
					
						
							| 
									
										
										
										
											2017-09-10 19:31:54 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /** | 
					
						
							| 
									
										
										
										
											2017-10-23 16:50:48 -07:00
										 |  |  |    * Ember.ComputedProperty that resolves with the image url for the avatar | 
					
						
							| 
									
										
										
										
											2017-10-25 03:04:36 -07:00
										 |  |  |    * @type {ComputedProperty<string>} | 
					
						
							|  |  |  |    * @memberof UserAvatar | 
					
						
							| 
									
										
										
										
											2017-09-10 19:31:54 -07:00
										 |  |  |    */ | 
					
						
							| 
									
										
										
										
											2017-10-23 16:50:48 -07:00
										 |  |  |   imageUrl: ComputedProperty<string> = computed('userName', function(this: UserAvatar) { | 
					
						
							| 
									
										
										
										
											2017-09-10 19:31:54 -07:00
										 |  |  |     const userName = get(this, 'userName'); | 
					
						
							|  |  |  |     if (userName && userName !== headlessUserName) { | 
					
						
							|  |  |  |       return url.replace('[username]', userName); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return fallbackUrl; | 
					
						
							| 
									
										
										
										
											2017-10-23 16:50:48 -07:00
										 |  |  |   }); | 
					
						
							|  |  |  | } |