From 098cbcdc21effeebe7e57fbd912a785e85cbfc5d Mon Sep 17 00:00:00 2001 From: hmhealey Date: Mon, 13 Jul 2015 17:47:57 -0400 Subject: Unify all locations where we determine a user's display named based off of their nickname/username into a helper function --- web/react/utils/utils.jsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'web/react/utils') diff --git a/web/react/utils/utils.jsx b/web/react/utils/utils.jsx index 7186251e7..5a1a7ee73 100644 --- a/web/react/utils/utils.jsx +++ b/web/react/utils/utils.jsx @@ -796,7 +796,6 @@ module.exports.getHomeLink = function() { return window.location.protocol + "//" + parts.join("."); } - module.exports.changeColor =function(col, amt) { var usePound = false; @@ -824,5 +823,12 @@ module.exports.changeColor =function(col, amt) { else if (g < 0) g = 0; return (usePound?"#":"") + String("000000" + (g | (b << 8) | (r << 16)).toString(16)).slice(-6); +}; +module.exports.getDisplayName = function(user) { + if (user.nickname && user.nickname.trim().length > 0) { + return user.nickname; + } else { + return user.username; + } }; -- cgit v1.2.3-1-g7c22 From 1dba330146a10718a2fc9eac0ae7d6e1d6bc0d79 Mon Sep 17 00:00:00 2001 From: hmhealey Date: Tue, 14 Jul 2015 17:07:19 -0400 Subject: Use a user's full name as their display name if a nickname hasn't been specified --- web/react/utils/utils.jsx | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'web/react/utils') diff --git a/web/react/utils/utils.jsx b/web/react/utils/utils.jsx index 5a1a7ee73..416ea5ae4 100644 --- a/web/react/utils/utils.jsx +++ b/web/react/utils/utils.jsx @@ -825,10 +825,28 @@ module.exports.changeColor =function(col, amt) { return (usePound?"#":"") + String("000000" + (g | (b << 8) | (r << 16)).toString(16)).slice(-6); }; +module.exports.getFullName = function(user) { + if (user.first_name && user.last_name) { + return user.first_name + " " + user.last_name; + } else if (user.first_name) { + return user.first_name; + } else if (user.last_name) { + return user.last_name; + } else { + return ""; + } +}; + module.exports.getDisplayName = function(user) { if (user.nickname && user.nickname.trim().length > 0) { return user.nickname; } else { - return user.username; + var fullName = module.exports.getFullName(user); + + if (fullName) { + return fullName; + } else { + return user.username; + } } }; -- cgit v1.2.3-1-g7c22