From c6c7bf08a06b6884785cc12e5d39e20ed9b3a36b Mon Sep 17 00:00:00 2001 From: Stas Vilchik Date: Fri, 10 Jun 2016 17:37:21 +0200 Subject: refactor react components (#1033) --- .../sonar-web/src/main/js/components/ui/Avatar.js | 48 ++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 server/sonar-web/src/main/js/components/ui/Avatar.js (limited to 'server/sonar-web/src/main/js/components/ui/Avatar.js') diff --git a/server/sonar-web/src/main/js/components/ui/Avatar.js b/server/sonar-web/src/main/js/components/ui/Avatar.js new file mode 100644 index 00000000000..f7b78320c85 --- /dev/null +++ b/server/sonar-web/src/main/js/components/ui/Avatar.js @@ -0,0 +1,48 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +import React from 'react'; +import md5 from 'blueimp-md5'; + +export default class Avatar extends React.Component { + static propTypes = { + email: React.PropTypes.string, + size: React.PropTypes.number.isRequired + }; + + render () { + const shouldShowAvatar = window.SS && window.SS.lf && window.SS.lf.enableGravatar; + if (!shouldShowAvatar) { + return null; + } + + const emailHash = md5.md5(this.props.email || '').trim(); + const url = ('' + window.SS.lf.gravatarServerUrl) + .replace('{EMAIL_MD5}', emailHash) + .replace('{SIZE}', this.props.size * 2); + + return ( + {this.props.email}/ + ); + } +} -- cgit v1.2.3