From e6c4292fd5a3182f01f16dfd445359f5dcb87e0c Mon Sep 17 00:00:00 2001 From: Helena Rasche Date: Tue, 4 Dec 2018 17:50:50 +0100 Subject: [PATCH] Move to correct location --- .../scripts/mvc/history/history-item-li.js | 33 ++--------------- .../scripts/mvc/ui/ui-select-default.js | 2 +- client/galaxy/scripts/utils/utils.js | 37 ++++++++++++++++++- 3 files changed, 40 insertions(+), 32 deletions(-) diff --git a/client/galaxy/scripts/mvc/history/history-item-li.js b/client/galaxy/scripts/mvc/history/history-item-li.js index 316da595826..b57ef7135c3 100644 --- a/client/galaxy/scripts/mvc/history/history-item-li.js +++ b/client/galaxy/scripts/mvc/history/history-item-li.js @@ -1,14 +1,7 @@ +import Utils from "utils/utils"; + function _templateNametag(tag) { - return `${_.escape(tag.slice(5))}`; -} - -function generateTagColor(tagValue) { - var hash = hashFnv32a(tagValue); - var r = ((hash & 0xf) % 10), - g = (((hash & 0xf0) >> 4) % 10), - b = (((hash & 0xf00) >> 8) % 10); - - return `#${r}${g}${b}`; + return `${_.escape(tag.slice(5))}`; } function nametagTemplate(historyItem) { @@ -23,23 +16,3 @@ function nametagTemplate(historyItem) { export default { nametagTemplate: nametagTemplate }; - -/** - * Calculate a 32 bit FNV-1a hash - * Found here: https://gist.github.com/vaiorabbit/5657561 - * Ref.: http://isthe.com/chongo/tech/comp/fnv/ - * - * @param {string} str the input value - * @returns {integer} - */ -function hashFnv32a(str) { - /*jshint bitwise:false */ - var i, l, - hval = 0x811c9dc5; - - for (i = 0, l = str.length; i < l; i++) { - hval ^= str.charCodeAt(i); - hval += (hval << 1) + (hval << 4) + (hval << 7) + (hval << 8) + (hval << 24); - } - return hval >>> 0; -} diff --git a/client/galaxy/scripts/mvc/ui/ui-select-default.js b/client/galaxy/scripts/mvc/ui/ui-select-default.js index 67e3370b415..95f867d97fc 100644 --- a/client/galaxy/scripts/mvc/ui/ui-select-default.js +++ b/client/galaxy/scripts/mvc/ui/ui-select-default.js @@ -208,7 +208,7 @@ var View = Backbone.View.extend({ ${_.reduce( filteredTags.slice(0, 5), (memo, tag) => { - return `${memo} 
${_.escape( + return `${memo} 
${_.escape( tag )}
`; }, diff --git a/client/galaxy/scripts/utils/utils.js b/client/galaxy/scripts/utils/utils.js index e9c45c4e952..6b98e520aec 100644 --- a/client/galaxy/scripts/utils/utils.js +++ b/client/galaxy/scripts/utils/utils.js @@ -349,6 +349,40 @@ export function setWindowTitle(title) { } } +/** + * Calculate a 32 bit FNV-1a hash + * Found here: https://gist.github.com/vaiorabbit/5657561 + * Ref.: http://isthe.com/chongo/tech/comp/fnv/ + * + * @param {string} str the input value + * @returns {integer} + */ +function hashFnv32a(str) { + /*jshint bitwise:false */ + var i, l, + hval = 0x811c9dc5; + + for (i = 0, l = str.length; i < l; i++) { + hval ^= str.charCodeAt(i); + hval += (hval << 1) + (hval << 4) + (hval << 7) + (hval << 8) + (hval << 24); + } + return hval >>> 0; +} + +export function generateTagColor(tagValue) { + //var r = (15 - ((hash & 0xf) % 6)).toString(16), + //g = (15 - (((hash & 0xf0) >> 4) % 6)).toString(16), + //b = (15 - (((hash & 0xf00) >> 8) % 6)).toString(16); + + var hash = hashFnv32a(tagValue); + var r = (((hash & 0x00f) >> 0) % 10), + g = (((hash & 0x0f0) >> 4) % 10), + b = (((hash & 0xf00) >> 8) % 10); + + return `#${r}${g}${b}`; +} + + export default { cssLoadFile: cssLoadFile, cssGetAttribute: cssGetAttribute, @@ -368,5 +402,6 @@ export default { linkify: linkify, appendScriptStyle: appendScriptStyle, getQueryString: getQueryString, - setWindowTitle: setWindowTitle + setWindowTitle: setWindowTitle, + generateTagColor: generateTagColor };