aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/main/js/components/ui/Avatar.js
diff options
context:
space:
mode:
authorStas Vilchik <vilchiks@gmail.com>2016-06-10 17:37:21 +0200
committerGitHub <noreply@github.com>2016-06-10 17:37:21 +0200
commitc6c7bf08a06b6884785cc12e5d39e20ed9b3a36b (patch)
tree856f132b1fff3687ef27d1fbca4f708884661521 /server/sonar-web/src/main/js/components/ui/Avatar.js
parentc321ee96905615ae8608e3047c5a5f0695e65bf2 (diff)
downloadsonarqube-c6c7bf08a06b6884785cc12e5d39e20ed9b3a36b.tar.gz
sonarqube-c6c7bf08a06b6884785cc12e5d39e20ed9b3a36b.zip
refactor react components (#1033)
Diffstat (limited to 'server/sonar-web/src/main/js/components/ui/Avatar.js')
-rw-r--r--server/sonar-web/src/main/js/components/ui/Avatar.js48
1 files changed, 48 insertions, 0 deletions
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 (
+ <img className="rounded"
+ src={url}
+ width={this.props.size}
+ height={this.props.size}
+ alt={this.props.email}/>
+ );
+ }
+}