diff options
author | Stas Vilchik <vilchiks@gmail.com> | 2015-12-17 15:14:08 +0100 |
---|---|---|
committer | Stas Vilchik <vilchiks@gmail.com> | 2015-12-18 11:02:51 +0100 |
commit | 3f38540619ece91a5f77cdd202ba339d3eb41462 (patch) | |
tree | 17386de2fc2b0972bb5f42453af3fcf4ffcb416f /server/sonar-web/src/main/js/helpers | |
parent | a76c4cc7cee9d6974324d93d936b904eab4960dc (diff) | |
download | sonarqube-3f38540619ece91a5f77cdd202ba339d3eb41462.tar.gz sonarqube-3f38540619ece91a5f77cdd202ba339d3eb41462.zip |
install webpack
Diffstat (limited to 'server/sonar-web/src/main/js/helpers')
93 files changed, 670 insertions, 598 deletions
diff --git a/server/sonar-web/src/main/js/helpers/handlebars-helpers.js b/server/sonar-web/src/main/js/helpers/handlebars-helpers.js deleted file mode 100644 index b9c54ea4562..00000000000 --- a/server/sonar-web/src/main/js/helpers/handlebars-helpers.js +++ /dev/null @@ -1,598 +0,0 @@ -import _ from 'underscore'; -import moment from 'moment'; -import numeral from 'numeral'; -import Handlebars from 'hbsfy/runtime'; -import md5 from 'blueimp-md5'; -import { formatMeasure, formatMeasureVariation } from './measures'; - - -var defaultActions = ['comment', 'assign', 'assign_to_me', 'plan', 'set_severity', 'set_tags']; - - -Handlebars.registerHelper('log', function () { - /* eslint no-console: 0 */ - var args = Array.prototype.slice.call(arguments, 0, -1); - console.log.apply(console, args); -}); - -Handlebars.registerHelper('link', function () { - var url = Array.prototype.slice.call(arguments, 0, -1).join(''); - return baseUrl + url; -}); - -Handlebars.registerHelper('componentPermalink', function (componentKey) { - return baseUrl + '/dashboard/index?id=' + encodeURIComponent(componentKey); -}); - -Handlebars.registerHelper('componentDashboardPermalink', function (componentKey, dashboardKey) { - var params = [ - { key: 'id', value: componentKey }, - { key: 'did', value: dashboardKey } - ]; - - var matchPeriod = window.location.search.match(/period=(\d+)/); - if (matchPeriod) { - // If we have a match for period, check that it is not project-specific - var period = parseInt(matchPeriod[1], 10); - if (period <= 3) { - params.push({ key: 'period', value: period }); - } - } - - var query = params.map(function (p) { - return p.key + '=' + encodeURIComponent(p.value); - }).join('&'); - return baseUrl + '/dashboard/index?' + query; -}); - -Handlebars.registerHelper('componentBrowsePermalink', function (componentKey) { - return baseUrl + '/components/index?id=' + encodeURIComponent(componentKey); -}); - -Handlebars.registerHelper('componentIssuesPermalink', function (componentKey) { - return baseUrl + '/component_issues/index?id=' + encodeURIComponent(componentKey); -}); - -Handlebars.registerHelper('rulePermalink', function (ruleKey) { - return baseUrl + '/coding_rules#rule_key=' + encodeURIComponent(ruleKey); -}); - -Handlebars.registerHelper('isActiveLink', function () { - var args = Array.prototype.slice.call(arguments, 0, -1), - options = arguments[arguments.length - 1], - prefix = args.join(''), - path = window.location.pathname, - match = path.indexOf(baseUrl + prefix) === 0; - return match ? options.fn(this) : options.inverse(this); -}); - -Handlebars.registerHelper('capitalize', function (string) { - return string.charAt(0).toUpperCase() + string.slice(1).toLowerCase(); -}); - -Handlebars.registerHelper('severityIcon', function (severity) { - return new Handlebars.SafeString( - '<i class="icon-severity-' + severity.toLowerCase() + '"></i>' - ); -}); - -Handlebars.registerHelper('severityHelper', function (severity) { - return new Handlebars.SafeString( - '<i class="icon-severity-' + severity.toLowerCase() + '"></i> ' + window.t('severity', severity) - ); -}); - -Handlebars.registerHelper('statusIcon', function (status) { - return new Handlebars.SafeString( - '<i class="icon-status-' + status.toLowerCase() + '"></i>' - ); -}); - -Handlebars.registerHelper('statusHelper', function (status, resolution) { - var s = '<i class="icon-status-' + status.toLowerCase() + '"></i> ' + window.t('issue.status', status); - if (resolution != null) { - s = s + ' (' + window.t('issue.resolution', resolution) + ')'; - } - return new Handlebars.SafeString(s); -}); - -Handlebars.registerHelper('testStatusIcon', function (status) { - return new Handlebars.SafeString( - '<i class="icon-test-status-' + status.toLowerCase() + '"></i>' - ); -}); - -Handlebars.registerHelper('testStatusIconClass', function (status) { - return new Handlebars.SafeString('' + - 'icon-test-status-' + status.toLowerCase() - ); -}); - -Handlebars.registerHelper('alertIconClass', function (alert) { - return new Handlebars.SafeString( - 'icon-alert-' + alert.toLowerCase() - ); -}); - -Handlebars.registerHelper('qualifierIcon', function (qualifier) { - return new Handlebars.SafeString( - qualifier ? '<i class="icon-qualifier-' + qualifier.toLowerCase() + '"></i>' : '' - ); -}); - -Handlebars.registerHelper('default', function () { - var args = Array.prototype.slice.call(arguments, 0, -1); - return args.reduce(function (prev, current) { - return prev != null ? prev : current; - }, null); -}); - -Handlebars.registerHelper('show', function () { - var args = Array.prototype.slice.call(arguments), - ret = null; - args.forEach(function (arg) { - if (typeof arg === 'string' && ret == null) { - ret = arg; - } - }); - return ret || ''; -}); - -Handlebars.registerHelper('percent', function (value, total) { - if (total > 0) { - return '' + ((value || 0) / total * 100) + '%'; - } else { - return '0%'; - } -}); - -Handlebars.registerHelper('eachIndex', function (context, options) { - var ret = ''; - context.forEach(function (d, i) { - var c = _.extend({ index: i }, d); - ret += options.fn(c); - }); - return ret; -}); - -Handlebars.registerHelper('eachChanged', function (context, property, options) { - var ret = ''; - context.forEach(function (d, i) { - var changed = i > 0 ? d[property] !== context[i - 1][property] : true, - c = _.extend({ changed: changed }, d); - ret += options.fn(c); - }); - return ret; -}); - -Handlebars.registerHelper('eachEven', function (context, options) { - var ret = ''; - context.forEach(function (d, i) { - if (i % 2 === 0) { - ret += options.fn(d); - } - }); - return ret; -}); - -Handlebars.registerHelper('eachOdd', function (context, options) { - var ret = ''; - context.forEach(function (d, i) { - if (i % 2 === 1) { - ret += options.fn(d); - } - }); - return ret; -}); - -Handlebars.registerHelper('eq', function (v1, v2, options) { - /* eslint eqeqeq: 0 */ - return v1 == v2 ? options.fn(this) : options.inverse(this); -}); - -Handlebars.registerHelper('notEq', function (v1, v2, options) { - /* eslint eqeqeq: 0 */ - return v1 != v2 ? options.fn(this) : options.inverse(this); -}); - -Handlebars.registerHelper('gt', function (v1, v2, options) { - return v1 > v2 ? options.fn(this) : options.inverse(this); -}); - -Handlebars.registerHelper('lt', function (v1, v2, options) { - return v1 < v2 ? options.fn(this) : options.inverse(this); -}); - -Handlebars.registerHelper('notNull', function (value, options) { - return value != null ? options.fn(this) : options.inverse(this); -}); - -Handlebars.registerHelper('isNull', function (value, options) { - return value == null ? options.fn(this) : options.inverse(this); -}); - -Handlebars.registerHelper('notEmpty', function (array, options) { - var cond = _.isArray(array) && array.length > 0; - return cond ? options.fn(this) : options.inverse(this); -}); - -Handlebars.registerHelper('empty', function (array, options) { - var cond = _.isArray(array) && array.length > 0; - return cond ? options.inverse(this) : options.fn(this); -}); - -Handlebars.registerHelper('all', function () { - var args = Array.prototype.slice.call(arguments, 0, -1), - options = arguments[arguments.length - 1], - all = args.reduce(function (prev, current) { - return prev && current; - }, true); - return all ? options.fn(this) : options.inverse(this); -}); - -Handlebars.registerHelper('any', function () { - var args = Array.prototype.slice.call(arguments, 0, -1), - options = arguments[arguments.length - 1], - any = args.reduce(function (prev, current) { - return prev || current; - }, false); - return any ? options.fn(this) : options.inverse(this); -}); - -Handlebars.registerHelper('inArray', function (array, element, options) { - if (_.isArray(array)) { - if (array.indexOf(element) !== -1) { - return options.fn(this); - } else { - return options.inverse(this); - } - } -}); - -Handlebars.registerHelper('ifNotEmpty', function () { - var args = Array.prototype.slice.call(arguments, 0, -1), - options = arguments[arguments.length - 1], - notEmpty = args.reduce(function (prev, current) { - return prev || (current && current.length > 0); - }, false); - return notEmpty ? options.fn(this) : options.inverse(this); -}); - -Handlebars.registerHelper('join', function (array, separator) { - return array.join(separator); -}); - -Handlebars.registerHelper('ifLength', function (array, len, options) { - var cond = _.isArray(array) && array.length === +len; - return cond ? options.fn(this) : options.inverse(this); -}); - -Handlebars.registerHelper('unlessLength', function (array, len, options) { - var cond = _.isArray(array) && array.length === +len; - return cond ? options.inverse(this) : options.fn(this); -}); - -Handlebars.registerHelper('eachReverse', function (array, options) { - var ret = ''; - - if (array && array.length > 0) { - for (var i = array.length - 1; i >= 0; i--) { - ret += options.fn(array[i]); - } - } else { - ret = options.inverse(this); - } - - return ret; -}); - -Handlebars.registerHelper('joinEach', function (array, separator, options) { - var ret = ''; - - if (array && array.length > 0) { - for (var i = 0, n = array.length; i < n; i++) { - ret += options.fn(array[i]); - if (i < n - 1) { - ret += separator; - } - } - } else { - ret = options.inverse(this); - } - - return ret; -}); - -Handlebars.registerHelper('sum', function () { - var args = Array.prototype.slice.call(arguments, 0, -1); - return args.reduce(function (p, c) { - return p + +c; - }, 0); -}); - -Handlebars.registerHelper('dashboardUrl', function (componentKey, componentQualifier) { - var url = baseUrl + '/dashboard/index?id=' + encodeURIComponent(componentKey); - if (componentQualifier === 'FIL' || componentQualifier === 'CLA') { - url += '&metric=sqale_index'; - } - return url; -}); - -Handlebars.registerHelper('translate', function () { - var args = Array.prototype.slice.call(arguments, 0, -1); - return window.translate.apply(this, args); -}); - -Handlebars.registerHelper('t', function () { - var args = Array.prototype.slice.call(arguments, 0, -1); - return window.t.apply(this, args); -}); - -Handlebars.registerHelper('tp', function () { - var args = Array.prototype.slice.call(arguments, 0, -1); - return window.tp.apply(this, args); -}); - -Handlebars.registerHelper('d', function (date) { - return moment(date).format('LL'); -}); - -Handlebars.registerHelper('dt', function (date) { - return moment(date).format('LLL'); -}); - -Handlebars.registerHelper('ds', function (date) { - return moment(date).format('YYYY-MM-DD'); -}); - -Handlebars.registerHelper('fromNow', function (date) { - return moment(date).fromNow(); -}); - -Handlebars.registerHelper('durationFromNow', function (date, units) { - return moment(new Date()).diff(date, units); -}); - -Handlebars.registerHelper('numberShort', function (number) { - var format = '0,0'; - if (number >= 10000) { - format = '0.[0]a'; - } - if (number >= 100000) { - format = '0a'; - } - return numeral(number).format(format); -}); - -Handlebars.registerHelper('pluginActions', function (actions, options) { - var pluginActions = _.difference(actions, defaultActions); - return pluginActions.reduce(function (prev, current) { - return prev + options.fn(current); - }, ''); -}); - -Handlebars.registerHelper('ifHasExtraActions', function (actions, options) { - var actionsLeft = _.difference(actions, defaultActions); - if (actionsLeft.length > 0) { - return options.fn(this); - } else { - return options.inverse(this); - } -}); - -Handlebars.registerHelper('withFirst', function (list, options) { - if (list && list.length > 0) { - return options.fn(list[0]); - } else { - return ''; - } -}); - -Handlebars.registerHelper('withLast', function (list, options) { - if (list && list.length > 0) { - return options.fn(list[list.length - 1]); - } else { - return ''; - } -}); - -Handlebars.registerHelper('withoutFirst', function (list, options) { - if (list && list.length > 1) { - return list.slice(1).reduce(function (prev, current) { - return prev + options.fn(current); - }, ''); - } else { - return ''; - } -}); - -var audaciousFn; -Handlebars.registerHelper('recursive', function (children, options) { - var out = ''; - - if (options.fn !== undefined) { - audaciousFn = options.fn; - } - - children.forEach(function (child) { - out = out + audaciousFn(child); - }); - - return out; -}); - -Handlebars.registerHelper('sources', function (source, scm, options) { - if (options == null) { - options = scm; - scm = null; - } - - var sources = _.map(source, function (code, line) { - return { - lineNumber: line, - code: code, - scm: (scm && scm[line]) ? { author: scm[line][0], date: scm[line][1] } : undefined - }; - }); - - return sources.reduce(function (prev, current, index) { - return prev + options.fn(_.extend({ first: index === 0 }, current)); - }, ''); -}); - -Handlebars.registerHelper('operators', function (options) { - var ops = ['LT', 'GT', 'EQ', 'NE']; - - return ops.reduce(function (prev, current) { - return prev + options.fn(current); - }, ''); -}); - -Handlebars.registerHelper('changelog', function (diff) { - var message = ''; - if (diff.newValue != null) { - message = window.tp('issue.changelog.changed_to', window.t('issue.changelog.field', diff.key), diff.newValue); - } else { - message = window.tp('issue.changelog.removed', window.t('issue.changelog.field', diff.key)); - } - if (diff.oldValue != null) { - message += ' ('; - message += window.tp('issue.changelog.was', diff.oldValue); - message += ')'; - } - return message; -}); - -Handlebars.registerHelper('ifMeasureShouldBeShown', function (measure, period, options) { - if (measure != null || period != null) { - return options.fn(this); - } else { - return options.inverse(this); - } -}); - -Handlebars.registerHelper('ifSCMChanged', function (source, line, options) { - var currentLine = _.findWhere(source, { lineNumber: line }), - prevLine = _.findWhere(source, { lineNumber: line - 1 }), - changed = true; - if (currentLine && prevLine && currentLine.scm && prevLine.scm) { - changed = (currentLine.scm.author !== prevLine.scm.author) || - (currentLine.scm.date !== prevLine.scm.date) || (!prevLine.show); - } - return changed ? options.fn(this) : options.inverse(this); -}); - -Handlebars.registerHelper('ifSCMChanged2', function (source, line, options) { - var currentLine = _.findWhere(source, { line: line }), - prevLine = _.findWhere(source, { line: line - 1 }), - changed = true; - if (currentLine && prevLine && currentLine.scmAuthor && prevLine.scmAuthor) { - changed = (currentLine.scmAuthor !== prevLine.scmAuthor) || (currentLine.scmDate !== prevLine.scmDate); - } - return changed ? options.fn(this) : options.inverse(this); -}); - -Handlebars.registerHelper('ifTestData', function (test, options) { - if ((test.status !== 'OK') || ((test.status === 'OK') && test.coveredLines)) { - return options.fn(this); - } else { - return options.inverse(this); - } -}); - -Handlebars.registerHelper('eqComponents', function (a, b, options) { - var notEq = a && b && ((a.project !== b.project) || (a.subProject !== b.subProject)); - return notEq ? options.inverse(this) : options.fn(this); -}); - -Handlebars.registerHelper('notEqComponents', function (a, b, options) { - var notEq = a && b && ((a.project !== b.project) || (a.subProject !== b.subProject)); - return notEq ? options.fn(this) : options.inverse(this); -}); - -Handlebars.registerHelper('projectFullName', function (component) { - return component.projectName + (component.subProjectName ? (' / ' + component.subProjectName) : ''); -}); - -Handlebars.registerHelper('dirFromPath', function (path) { - if (typeof path === 'string') { - var tokens = path.split('/'); - return tokens.length > 1 ? _.initial(tokens).join('/') + '/' : ''; - } else { - return null; - } -}); - -Handlebars.registerHelper('collapsedDirFromPath', function (path) { - return window.collapsedDirFromPath(path); -}); - -Handlebars.registerHelper('fileFromPath', function (path) { - return window.fileFromPath(path); -}); - -Handlebars.registerHelper('repeat', function (number, options) { - var ret = ''; - for (var i = 0; i < number; i++) { - ret += options.fn(this); - } - return ret; -}); - -Handlebars.registerHelper('limitString', function (str) { - if (typeof str === 'string') { - var LIMIT = 30; - return str.length > LIMIT ? str.substr(0, LIMIT) + '...' : str; - } -}); - -Handlebars.registerHelper('withSign', function (number) { - return number >= 0 ? '+' + number : '' + number; -}); - -Handlebars.registerHelper('formatMeasure', function (measure, type) { - return formatMeasure(measure, type); -}); - -Handlebars.registerHelper('formatMeasureVariation', function (measure, type) { - return formatMeasureVariation(measure, type); -}); - -Handlebars.registerHelper('dashboardL10n', function (dashboardName) { - var l10nKey = 'dashboard.' + dashboardName + '.name'; - var l10nLabel = window.t(l10nKey); - if (l10nLabel !== l10nKey) { - return l10nLabel; - } else { - return dashboardName; - } -}); - -Handlebars.registerHelper('ifShowAvatars', function (options) { - var cond = window.SS && window.SS.lf && window.SS.lf.enableGravatar; - return cond ? options.fn(this) : options.inverse(this); -}); - -Handlebars.registerHelper('avatarHelper', function (email, size) { - // double the size for high pixel density screens - var emailHash = md5.md5((email || '').trim()), - url = ('' + window.SS.lf.gravatarServerUrl) - .replace('{EMAIL_MD5}', emailHash) - .replace('{SIZE}', size * 2); - return new Handlebars.SafeString( - '<img class="rounded" src="' + url + '" width="' + size + '" height="' + size + '" alt="' + email + '">' - ); -}); - -Handlebars.registerHelper('ifCanUseFilter', function (query, options) { - var cond = window.SS.user || query.indexOf('__me__') === -1; - return cond ? options.fn(this) : options.inverse(this); -}); - -Handlebars.registerHelper('length', function (array) { - return _.size(array); -}); - -Handlebars.registerHelper('ifLengthGT', function (array, len, options) { - return _.size(array) > len ? options.fn(this) : options.inverse(this); -}); diff --git a/server/sonar-web/src/main/js/helpers/handlebars/alertIconClass.js b/server/sonar-web/src/main/js/helpers/handlebars/alertIconClass.js new file mode 100644 index 00000000000..6a7f68414bd --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/alertIconClass.js @@ -0,0 +1,7 @@ +import Handlebars from 'handlebars/runtime'; + +module.exports = function (alert) { + return new Handlebars.default.SafeString( + 'icon-alert-' + alert.toLowerCase() + ); +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/all.js b/server/sonar-web/src/main/js/helpers/handlebars/all.js new file mode 100644 index 00000000000..c5b99b69f7b --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/all.js @@ -0,0 +1,8 @@ +module.exports = function () { + var args = Array.prototype.slice.call(arguments, 0, -1), + options = arguments[arguments.length - 1], + all = args.reduce(function (prev, current) { + return prev && current; + }, true); + return all ? options.fn(this) : options.inverse(this); +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/any.js b/server/sonar-web/src/main/js/helpers/handlebars/any.js new file mode 100644 index 00000000000..a3609cf7649 --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/any.js @@ -0,0 +1,8 @@ +module.exports = function () { + var args = Array.prototype.slice.call(arguments, 0, -1), + options = arguments[arguments.length - 1], + any = args.reduce(function (prev, current) { + return prev || current; + }, false); + return any ? options.fn(this) : options.inverse(this); +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/avatarHelper.js b/server/sonar-web/src/main/js/helpers/handlebars/avatarHelper.js new file mode 100644 index 00000000000..dc793122988 --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/avatarHelper.js @@ -0,0 +1,13 @@ +import md5 from 'blueimp-md5'; +import Handlebars from 'handlebars/runtime'; + +module.exports = function (email, size) { + // double the size for high pixel density screens + var emailHash = md5.md5((email || '').trim()), + url = ('' + window.SS.lf.gravatarServerUrl) + .replace('{EMAIL_MD5}', emailHash) + .replace('{SIZE}', size * 2); + return new Handlebars.default.SafeString( + '<img class="rounded" src="' + url + '" width="' + size + '" height="' + size + '" alt="' + email + '">' + ); +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/capitalize.js b/server/sonar-web/src/main/js/helpers/handlebars/capitalize.js new file mode 100644 index 00000000000..f2d29b8fd74 --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/capitalize.js @@ -0,0 +1,3 @@ +module.exports = function (string) { + return string.charAt(0).toUpperCase() + string.slice(1).toLowerCase(); +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/changelog.js b/server/sonar-web/src/main/js/helpers/handlebars/changelog.js new file mode 100644 index 00000000000..ca4ce7b147f --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/changelog.js @@ -0,0 +1,14 @@ +module.exports = function (diff) { + var message = ''; + if (diff.newValue != null) { + message = window.tp('issue.changelog.changed_to', window.t('issue.changelog.field', diff.key), diff.newValue); + } else { + message = window.tp('issue.changelog.removed', window.t('issue.changelog.field', diff.key)); + } + if (diff.oldValue != null) { + message += ' ('; + message += window.tp('issue.changelog.was', diff.oldValue); + message += ')'; + } + return message; +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/codeWithIssueLocations.js b/server/sonar-web/src/main/js/helpers/handlebars/codeWithIssueLocations.js new file mode 100644 index 00000000000..9e047d110e1 --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/codeWithIssueLocations.js @@ -0,0 +1,5 @@ +import doTheStuff from '../../components/source-viewer/helpers/code-with-issue-locations-helper'; + +module.exports = function (code, issueLocations) { + return doTheStuff(code, issueLocations); +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/collapsedDirFromPath.js b/server/sonar-web/src/main/js/helpers/handlebars/collapsedDirFromPath.js new file mode 100644 index 00000000000..a0fe0da46e2 --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/collapsedDirFromPath.js @@ -0,0 +1,3 @@ +module.exports = function (path) { + return window.collapsedDirFromPath(path); +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/componentBrowsePermalink.js b/server/sonar-web/src/main/js/helpers/handlebars/componentBrowsePermalink.js new file mode 100644 index 00000000000..70688372f21 --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/componentBrowsePermalink.js @@ -0,0 +1,3 @@ +module.exports = function (componentKey) { + return baseUrl + '/components/index?id=' + encodeURIComponent(componentKey); +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/componentDashboardPermalink.js b/server/sonar-web/src/main/js/helpers/handlebars/componentDashboardPermalink.js new file mode 100644 index 00000000000..e627e25bc27 --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/componentDashboardPermalink.js @@ -0,0 +1,20 @@ +module.exports = function (componentKey, dashboardKey) { + var params = [ + { key: 'id', value: componentKey }, + { key: 'did', value: dashboardKey } + ]; + + var matchPeriod = window.location.search.match(/period=(\d+)/); + if (matchPeriod) { + // If we have a match for period, check that it is not project-specific + var period = parseInt(matchPeriod[1], 10); + if (period <= 3) { + params.push({ key: 'period', value: period }); + } + } + + var query = params.map(function (p) { + return p.key + '=' + encodeURIComponent(p.value); + }).join('&'); + return baseUrl + '/dashboard/index?' + query; +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/componentIssuesPermalink.js b/server/sonar-web/src/main/js/helpers/handlebars/componentIssuesPermalink.js new file mode 100644 index 00000000000..6463a2c888f --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/componentIssuesPermalink.js @@ -0,0 +1,3 @@ +module.exports = function (componentKey) { + return baseUrl + '/component_issues/index?id=' + encodeURIComponent(componentKey); +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/componentPermalink.js b/server/sonar-web/src/main/js/helpers/handlebars/componentPermalink.js new file mode 100644 index 00000000000..59bc52fb75d --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/componentPermalink.js @@ -0,0 +1,3 @@ +module.exports = function (componentKey) { + return window.baseUrl + '/dashboard/index?id=' + encodeURIComponent(componentKey); +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/d.js b/server/sonar-web/src/main/js/helpers/handlebars/d.js new file mode 100644 index 00000000000..65effa50969 --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/d.js @@ -0,0 +1,5 @@ +import moment from 'moment'; + +module.exports = function (date) { + return moment(date).format('LL'); +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/dashboardL10n.js b/server/sonar-web/src/main/js/helpers/handlebars/dashboardL10n.js new file mode 100644 index 00000000000..33c3d58ddf5 --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/dashboardL10n.js @@ -0,0 +1,9 @@ +module.exports = function (dashboardName) { + var l10nKey = 'dashboard.' + dashboardName + '.name'; + var l10nLabel = window.t(l10nKey); + if (l10nLabel !== l10nKey) { + return l10nLabel; + } else { + return dashboardName; + } +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/dashboardUrl.js b/server/sonar-web/src/main/js/helpers/handlebars/dashboardUrl.js new file mode 100644 index 00000000000..36c466d2bb6 --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/dashboardUrl.js @@ -0,0 +1,7 @@ +module.exports = function (componentKey, componentQualifier) { + var url = baseUrl + '/dashboard/index?id=' + encodeURIComponent(componentKey); + if (componentQualifier === 'FIL' || componentQualifier === 'CLA') { + url += '&metric=sqale_index'; + } + return url; +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/default.js b/server/sonar-web/src/main/js/helpers/handlebars/default.js new file mode 100644 index 00000000000..56ea431ae77 --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/default.js @@ -0,0 +1,6 @@ +module.exports = function () { + var args = Array.prototype.slice.call(arguments, 0, -1); + return args.reduce(function (prev, current) { + return prev != null ? prev : current; + }, null); +} diff --git a/server/sonar-web/src/main/js/helpers/handlebars/dirFromPath.js b/server/sonar-web/src/main/js/helpers/handlebars/dirFromPath.js new file mode 100644 index 00000000000..13954e18228 --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/dirFromPath.js @@ -0,0 +1,10 @@ +import _ from 'underscore'; + +module.exports = function (path) { + if (typeof path === 'string') { + var tokens = path.split('/'); + return tokens.length > 1 ? _.initial(tokens).join('/') + '/' : ''; + } else { + return null; + } +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/ds.js b/server/sonar-web/src/main/js/helpers/handlebars/ds.js new file mode 100644 index 00000000000..9e6f38d4c08 --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/ds.js @@ -0,0 +1,5 @@ +import moment from 'moment'; + +module.exports = function (date) { + return moment(date).format('YYYY-MM-DD'); +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/dt.js b/server/sonar-web/src/main/js/helpers/handlebars/dt.js new file mode 100644 index 00000000000..4236708eb93 --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/dt.js @@ -0,0 +1,5 @@ +import moment from 'moment'; + +module.exports = function (date) { + return moment(date).format('LLL'); +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/durationFromNow.js b/server/sonar-web/src/main/js/helpers/handlebars/durationFromNow.js new file mode 100644 index 00000000000..a80c24967ec --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/durationFromNow.js @@ -0,0 +1,5 @@ +import moment from 'moment'; + +module.exports = function (date, units) { + return moment(new Date()).diff(date, units); +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/eachChanged.js b/server/sonar-web/src/main/js/helpers/handlebars/eachChanged.js new file mode 100644 index 00000000000..e64695a5aaa --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/eachChanged.js @@ -0,0 +1,9 @@ +module.exports = function (context, property, options) { + var ret = ''; + context.forEach(function (d, i) { + var changed = i > 0 ? d[property] !== context[i - 1][property] : true, + c = _.extend({ changed: changed }, d); + ret += options.fn(c); + }); + return ret; +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/eachEven.js b/server/sonar-web/src/main/js/helpers/handlebars/eachEven.js new file mode 100644 index 00000000000..33443e8ebf6 --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/eachEven.js @@ -0,0 +1,9 @@ +module.exports = function (context, options) { + var ret = ''; + context.forEach(function (d, i) { + if (i % 2 === 0) { + ret += options.fn(d); + } + }); + return ret; +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/eachIndex.js b/server/sonar-web/src/main/js/helpers/handlebars/eachIndex.js new file mode 100644 index 00000000000..209d8d78b06 --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/eachIndex.js @@ -0,0 +1,10 @@ +import _ from 'underscore'; + +module.exports = function (context, options) { + var ret = ''; + context.forEach(function (d, i) { + var c = _.extend({ index: i }, d); + ret += options.fn(c); + }); + return ret; +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/eachOdd.js b/server/sonar-web/src/main/js/helpers/handlebars/eachOdd.js new file mode 100644 index 00000000000..431fe625945 --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/eachOdd.js @@ -0,0 +1,9 @@ +module.exports = function (context, options) { + var ret = ''; + context.forEach(function (d, i) { + if (i % 2 === 1) { + ret += options.fn(d); + } + }); + return ret; +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/eachReverse.js b/server/sonar-web/src/main/js/helpers/handlebars/eachReverse.js new file mode 100644 index 00000000000..7b3e3e2a5df --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/eachReverse.js @@ -0,0 +1,13 @@ +module.exports = function (array, options) { + var ret = ''; + + if (array && array.length > 0) { + for (var i = array.length - 1; i >= 0; i--) { + ret += options.fn(array[i]); + } + } else { + ret = options.inverse(this); + } + + return ret; +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/empty.js b/server/sonar-web/src/main/js/helpers/handlebars/empty.js new file mode 100644 index 00000000000..72df1f9ad72 --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/empty.js @@ -0,0 +1,6 @@ +import _ from 'underscore'; + +module.exports = function (array, options) { + var cond = _.isArray(array) && array.length > 0; + return cond ? options.inverse(this) : options.fn(this); +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/eq.js b/server/sonar-web/src/main/js/helpers/handlebars/eq.js new file mode 100644 index 00000000000..1f90a2780f0 --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/eq.js @@ -0,0 +1,4 @@ +module.exports = function (v1, v2, options) { + /* eslint eqeqeq: 0 */ + return v1 == v2 ? options.fn(this) : options.inverse(this); +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/eqComponents.js b/server/sonar-web/src/main/js/helpers/handlebars/eqComponents.js new file mode 100644 index 00000000000..ed5ac68bf35 --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/eqComponents.js @@ -0,0 +1,4 @@ +module.exports = function (a, b, options) { + var notEq = a && b && ((a.project !== b.project) || (a.subProject !== b.subProject)); + return notEq ? options.inverse(this) : options.fn(this); +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/exporterUrl.js b/server/sonar-web/src/main/js/helpers/handlebars/exporterUrl.js new file mode 100644 index 00000000000..2be8f948aec --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/exporterUrl.js @@ -0,0 +1,9 @@ +module.exports = function (profile, exporterKey) { + var url = baseUrl + '/api/qualityprofiles/export'; + url += '?language=' + encodeURIComponent(profile.language); + url += '&name=' + encodeURIComponent(profile.name); + if (exporterKey != null) { + url += '&exporterKey=' + encodeURIComponent(exporterKey); + } + return url; +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/fileFromPath.js b/server/sonar-web/src/main/js/helpers/handlebars/fileFromPath.js new file mode 100644 index 00000000000..a4ef264cc11 --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/fileFromPath.js @@ -0,0 +1,3 @@ +module.exports = function (path) { + return window.fileFromPath(path); +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/formatFacetValue.js b/server/sonar-web/src/main/js/helpers/handlebars/formatFacetValue.js new file mode 100644 index 00000000000..2d8c778fca8 --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/formatFacetValue.js @@ -0,0 +1,8 @@ +import { formatMeasure } from '../measures'; + +module.exports = function (value, facetMode) { + var formatter = facetMode === 'debt' ? 'SHORT_WORK_DUR' : 'SHORT_INT'; + return formatMeasure(value, formatter); +}; + + diff --git a/server/sonar-web/src/main/js/helpers/handlebars/formatMeasure.js b/server/sonar-web/src/main/js/helpers/handlebars/formatMeasure.js new file mode 100644 index 00000000000..71f1c60cd7d --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/formatMeasure.js @@ -0,0 +1,5 @@ +import { formatMeasure } from '../measures'; + +module.exports = function (measure, type) { + return formatMeasure(measure, type); +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/formatMeasureVariation.js b/server/sonar-web/src/main/js/helpers/handlebars/formatMeasureVariation.js new file mode 100644 index 00000000000..94260bcf954 --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/formatMeasureVariation.js @@ -0,0 +1,5 @@ +import { formatMeasureVariation } from '../measures'; + +module.exports = function (measure, type) { + return formatMeasureVariation(measure, type); +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/fromNow.js b/server/sonar-web/src/main/js/helpers/handlebars/fromNow.js new file mode 100644 index 00000000000..17f31d5a796 --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/fromNow.js @@ -0,0 +1,5 @@ +import moment from 'moment'; + +module.exports = function (date) { + return moment(date).fromNow(); +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/gt.js b/server/sonar-web/src/main/js/helpers/handlebars/gt.js new file mode 100644 index 00000000000..a2ab7cf8ad5 --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/gt.js @@ -0,0 +1,3 @@ +module.exports = function (v1, v2, options) { + return v1 > v2 ? options.fn(this) : options.inverse(this); +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/ifCanUseFilter.js b/server/sonar-web/src/main/js/helpers/handlebars/ifCanUseFilter.js new file mode 100644 index 00000000000..e98fcd66cb9 --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/ifCanUseFilter.js @@ -0,0 +1,4 @@ +module.exports = function (query, options) { + var cond = window.SS.user || query.indexOf('__me__') === -1; + return cond ? options.fn(this) : options.inverse(this); +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/ifHasExtraActions.js b/server/sonar-web/src/main/js/helpers/handlebars/ifHasExtraActions.js new file mode 100644 index 00000000000..0affd4646e8 --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/ifHasExtraActions.js @@ -0,0 +1,10 @@ +const DEFAULT_ACTIONS = ['comment', 'assign', 'assign_to_me', 'plan', 'set_severity', 'set_tags']; + +module.exports = function (actions, options) { + var actionsLeft = _.difference(actions, DEFAULT_ACTIONS); + if (actionsLeft.length > 0) { + return options.fn(this); + } else { + return options.inverse(this); + } +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/ifLength.js b/server/sonar-web/src/main/js/helpers/handlebars/ifLength.js new file mode 100644 index 00000000000..ee39effa9f8 --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/ifLength.js @@ -0,0 +1,6 @@ +import _ from 'underscore'; + +module.exports = function (array, len, options) { + var cond = _.isArray(array) && array.length === +len; + return cond ? options.fn(this) : options.inverse(this); +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/ifLengthGT.js b/server/sonar-web/src/main/js/helpers/handlebars/ifLengthGT.js new file mode 100644 index 00000000000..c2c2d7fb025 --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/ifLengthGT.js @@ -0,0 +1,5 @@ +import _ from 'underscore'; + +module.exports = function (array, len, options) { + return _.size(array) > len ? options.fn(this) : options.inverse(this); +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/ifMeasureShouldBeShown.js b/server/sonar-web/src/main/js/helpers/handlebars/ifMeasureShouldBeShown.js new file mode 100644 index 00000000000..3a340385107 --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/ifMeasureShouldBeShown.js @@ -0,0 +1,7 @@ +module.exports = function (measure, period, options) { + if (measure != null || period != null) { + return options.fn(this); + } else { + return options.inverse(this); + } +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/ifNotEmpty.js b/server/sonar-web/src/main/js/helpers/handlebars/ifNotEmpty.js new file mode 100644 index 00000000000..ecc80908163 --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/ifNotEmpty.js @@ -0,0 +1,8 @@ +module.exports = function () { + var args = Array.prototype.slice.call(arguments, 0, -1), + options = arguments[arguments.length - 1], + notEmpty = args.reduce(function (prev, current) { + return prev || (current && current.length > 0); + }, false); + return notEmpty ? options.fn(this) : options.inverse(this); +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/ifSCMChanged.js b/server/sonar-web/src/main/js/helpers/handlebars/ifSCMChanged.js new file mode 100644 index 00000000000..c68db21618b --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/ifSCMChanged.js @@ -0,0 +1,12 @@ +import _ from 'underscore'; + +module.exports = function (source, line, options) { + var currentLine = _.findWhere(source, { lineNumber: line }), + prevLine = _.findWhere(source, { lineNumber: line - 1 }), + changed = true; + if (currentLine && prevLine && currentLine.scm && prevLine.scm) { + changed = (currentLine.scm.author !== prevLine.scm.author) || + (currentLine.scm.date !== prevLine.scm.date) || (!prevLine.show); + } + return changed ? options.fn(this) : options.inverse(this); +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/ifSCMChanged2.js b/server/sonar-web/src/main/js/helpers/handlebars/ifSCMChanged2.js new file mode 100644 index 00000000000..e13fb095c96 --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/ifSCMChanged2.js @@ -0,0 +1,11 @@ +import _ from 'underscore'; + +module.exports = function (source, line, options) { + var currentLine = _.findWhere(source, { line: line }), + prevLine = _.findWhere(source, { line: line - 1 }), + changed = true; + if (currentLine && prevLine && currentLine.scmAuthor && prevLine.scmAuthor) { + changed = (currentLine.scmAuthor !== prevLine.scmAuthor) || (currentLine.scmDate !== prevLine.scmDate); + } + return changed ? options.fn(this) : options.inverse(this); +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/ifShowAvatars.js b/server/sonar-web/src/main/js/helpers/handlebars/ifShowAvatars.js new file mode 100644 index 00000000000..7cfd27d2c5c --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/ifShowAvatars.js @@ -0,0 +1,4 @@ +module.exports = function (options) { + var cond = window.SS && window.SS.lf && window.SS.lf.enableGravatar; + return cond ? options.fn(this) : options.inverse(this); +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/ifTestData.js b/server/sonar-web/src/main/js/helpers/handlebars/ifTestData.js new file mode 100644 index 00000000000..ac00900c087 --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/ifTestData.js @@ -0,0 +1,7 @@ +module.exports = function (test, options) { + if ((test.status !== 'OK') || ((test.status === 'OK') && test.coveredLines)) { + return options.fn(this); + } else { + return options.inverse(this); + } +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/inArray.js b/server/sonar-web/src/main/js/helpers/handlebars/inArray.js new file mode 100644 index 00000000000..0a4c3ff5bdb --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/inArray.js @@ -0,0 +1,11 @@ +import _ from 'underscore'; + +module.exports = function (array, element, options) { + if (_.isArray(array)) { + if (array.indexOf(element) !== -1) { + return options.fn(this); + } else { + return options.inverse(this); + } + } +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/isActiveLink.js b/server/sonar-web/src/main/js/helpers/handlebars/isActiveLink.js new file mode 100644 index 00000000000..5eca1464585 --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/isActiveLink.js @@ -0,0 +1,8 @@ +module.exports = function () { + var args = Array.prototype.slice.call(arguments, 0, -1), + options = arguments[arguments.length - 1], + prefix = args.join(''), + path = window.location.pathname, + match = path.indexOf(baseUrl + prefix) === 0; + return match ? options.fn(this) : options.inverse(this); +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/isNull.js b/server/sonar-web/src/main/js/helpers/handlebars/isNull.js new file mode 100644 index 00000000000..0a9882468a0 --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/isNull.js @@ -0,0 +1,3 @@ +module.exports = function (value, options) { + return value == null ? options.fn(this) : options.inverse(this); +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/issueFilterHomeLink.js b/server/sonar-web/src/main/js/helpers/handlebars/issueFilterHomeLink.js new file mode 100644 index 00000000000..b87fc3f7ed5 --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/issueFilterHomeLink.js @@ -0,0 +1,3 @@ +module.exports = function (id) { + return baseUrl + '/issues/search#id=' + id; +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/issueFilterItemLink.js b/server/sonar-web/src/main/js/helpers/handlebars/issueFilterItemLink.js new file mode 100644 index 00000000000..98f4108f5ee --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/issueFilterItemLink.js @@ -0,0 +1,25 @@ +import _ from 'underscore'; + +function getQuery (query, separator) { + separator = separator || '|'; + var route = []; + _.forEach(query, function (value, property) { + route.push('' + property + '=' + encodeURIComponent(value)); + }); + return route.join(separator); +} + +module.exports = function (query, property, value, mode) { + var criterion = {}; + criterion[property] = value; + var r = _.extend({}, query, criterion); + if (mode === 'debt') { + r.facetMode = 'debt'; + } + if (r.componentKey != null) { + return baseUrl + '/component_issues/index?id=' + encodeURIComponent(r.componentKey) + + '#' + getQuery(_.omit(r, 'componentKey')); + } else { + return baseUrl + '/issues/search#' + getQuery(r); + } +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/issueFilterTotalLink.js b/server/sonar-web/src/main/js/helpers/handlebars/issueFilterTotalLink.js new file mode 100644 index 00000000000..07e346b92b1 --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/issueFilterTotalLink.js @@ -0,0 +1,23 @@ +import _ from 'underscore'; + +function getQuery (query, separator) { + separator = separator || '|'; + var route = []; + _.forEach(query, function (value, property) { + route.push('' + property + '=' + encodeURIComponent(value)); + }); + return route.join(separator); +} + +module.exports = function (query, mode) { + var r = _.extend({}, query); + if (mode === 'debt') { + r.facetMode = 'debt'; + } + if (r.componentKey != null) { + return baseUrl + '/component_issues/index?id=' + encodeURIComponent(r.componentKey) + + '#' + getQuery(_.omit(r, 'componentKey')); + } else { + return baseUrl + '/issues/search#' + getQuery(r); + } +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/issueFilterValue.js b/server/sonar-web/src/main/js/helpers/handlebars/issueFilterValue.js new file mode 100644 index 00000000000..7eba2d25cdf --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/issueFilterValue.js @@ -0,0 +1,6 @@ +import { formatMeasure } from '../measures'; + +module.exports = function (value, mode) { + var formatter = mode === 'debt' ? 'SHORT_WORK_DUR' : 'SHORT_INT'; + return formatMeasure(value, formatter); +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/join.js b/server/sonar-web/src/main/js/helpers/handlebars/join.js new file mode 100644 index 00000000000..20a24939eb3 --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/join.js @@ -0,0 +1,3 @@ +module.exports = function (array, separator) { + return array.join(separator); +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/joinEach.js b/server/sonar-web/src/main/js/helpers/handlebars/joinEach.js new file mode 100644 index 00000000000..3971af32d7e --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/joinEach.js @@ -0,0 +1,16 @@ +module.exports = function (array, separator, options) { + var ret = ''; + + if (array && array.length > 0) { + for (var i = 0, n = array.length; i < n; i++) { + ret += options.fn(array[i]); + if (i < n - 1) { + ret += separator; + } + } + } else { + ret = options.inverse(this); + } + + return ret; +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/length.js b/server/sonar-web/src/main/js/helpers/handlebars/length.js new file mode 100644 index 00000000000..c7d1747fe64 --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/length.js @@ -0,0 +1,5 @@ +import _ from 'underscore'; + +module.exports = function (array) { + return _.size(array); +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/limitString.js b/server/sonar-web/src/main/js/helpers/handlebars/limitString.js new file mode 100644 index 00000000000..6621f2957b3 --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/limitString.js @@ -0,0 +1,6 @@ +module.exports = function (str) { + if (typeof str === 'string') { + var LIMIT = 30; + return str.length > LIMIT ? str.substr(0, LIMIT) + '...' : str; + } +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/link.js b/server/sonar-web/src/main/js/helpers/handlebars/link.js new file mode 100644 index 00000000000..db23f132418 --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/link.js @@ -0,0 +1,4 @@ +module.exports = function () { + var url = Array.prototype.slice.call(arguments, 0, -1).join(''); + return window.baseUrl + url; +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/log.js b/server/sonar-web/src/main/js/helpers/handlebars/log.js new file mode 100644 index 00000000000..ad7d814f6e8 --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/log.js @@ -0,0 +1,5 @@ +module.exports = function () { + /* eslint no-console: 0 */ + var args = Array.prototype.slice.call(arguments, 0, -1); + console.log.apply(console, args); +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/lt.js b/server/sonar-web/src/main/js/helpers/handlebars/lt.js new file mode 100644 index 00000000000..11929ec762a --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/lt.js @@ -0,0 +1,3 @@ +module.exports = function (v1, v2, options) { + return v1 < v2 ? options.fn(this) : options.inverse(this); +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/notEmpty.js b/server/sonar-web/src/main/js/helpers/handlebars/notEmpty.js new file mode 100644 index 00000000000..109d4e3d0f5 --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/notEmpty.js @@ -0,0 +1,6 @@ +import _ from 'underscore'; + +module.exports = function (array, options) { + var cond = _.isArray(array) && array.length > 0; + return cond ? options.fn(this) : options.inverse(this); +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/notEq.js b/server/sonar-web/src/main/js/helpers/handlebars/notEq.js new file mode 100644 index 00000000000..aff01a58ba6 --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/notEq.js @@ -0,0 +1,4 @@ +module.exports = function (v1, v2, options) { + /* eslint eqeqeq: 0 */ + return v1 != v2 ? options.fn(this) : options.inverse(this); +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/notEqComponents.js b/server/sonar-web/src/main/js/helpers/handlebars/notEqComponents.js new file mode 100644 index 00000000000..57905a6ee0f --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/notEqComponents.js @@ -0,0 +1,4 @@ +module.exports = function (a, b, options) { + var notEq = a && b && ((a.project !== b.project) || (a.subProject !== b.subProject)); + return notEq ? options.fn(this) : options.inverse(this); +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/notNull.js b/server/sonar-web/src/main/js/helpers/handlebars/notNull.js new file mode 100644 index 00000000000..672b702236b --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/notNull.js @@ -0,0 +1,3 @@ +module.exports = function (value, options) { + return value != null ? options.fn(this) : options.inverse(this); +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/numberShort.js b/server/sonar-web/src/main/js/helpers/handlebars/numberShort.js new file mode 100644 index 00000000000..bba8f44a82f --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/numberShort.js @@ -0,0 +1,12 @@ +import numeral from 'numeral'; + +module.exports = function (number) { + var format = '0,0'; + if (number >= 10000) { + format = '0.[0]a'; + } + if (number >= 100000) { + format = '0a'; + } + return numeral(number).format(format); +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/operators.js b/server/sonar-web/src/main/js/helpers/handlebars/operators.js new file mode 100644 index 00000000000..d042e9db3d3 --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/operators.js @@ -0,0 +1,7 @@ +module.exports = function (options) { + var ops = ['LT', 'GT', 'EQ', 'NE']; + + return ops.reduce(function (prev, current) { + return prev + options.fn(current); + }, ''); +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/parameterChangelog.js b/server/sonar-web/src/main/js/helpers/handlebars/parameterChangelog.js new file mode 100644 index 00000000000..c12a4ecd894 --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/parameterChangelog.js @@ -0,0 +1,13 @@ +import Handlebars from 'handlebars/runtime'; + +module.exports = function (value, parameter) { + if (parameter) { + return new Handlebars.default.SafeString( + window.tp('quality_profiles.parameter_set_to_x', value, parameter) + ); + } else { + return new Handlebars.default.SafeString( + window.tp('quality_profiles.changelog.parameter_reset_to_default_value_x', parameter) + ); + } +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/percent.js b/server/sonar-web/src/main/js/helpers/handlebars/percent.js new file mode 100644 index 00000000000..24c871add4e --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/percent.js @@ -0,0 +1,7 @@ +module.exports = function (value, total) { + if (total > 0) { + return '' + ((value || 0) / total * 100) + '%'; + } else { + return '0%'; + } +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/pluginActions.js b/server/sonar-web/src/main/js/helpers/handlebars/pluginActions.js new file mode 100644 index 00000000000..c69680da952 --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/pluginActions.js @@ -0,0 +1,8 @@ +const DEFAULT_ACTIONS = ['comment', 'assign', 'assign_to_me', 'plan', 'set_severity', 'set_tags']; + +module.exports = function (actions, options) { + var pluginActions = _.difference(actions, DEFAULT_ACTIONS); + return pluginActions.reduce(function (prev, current) { + return prev + options.fn(current); + }, ''); +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/profileUrl.js b/server/sonar-web/src/main/js/helpers/handlebars/profileUrl.js new file mode 100644 index 00000000000..e8184594727 --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/profileUrl.js @@ -0,0 +1,3 @@ +module.exports = function (key) { + return baseUrl + '/profiles/show?key=' + encodeURIComponent(key); +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/projectFullName.js b/server/sonar-web/src/main/js/helpers/handlebars/projectFullName.js new file mode 100644 index 00000000000..ef3d4582610 --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/projectFullName.js @@ -0,0 +1,3 @@ +module.exports = function (component) { + return component.projectName + (component.subProjectName ? (' / ' + component.subProjectName) : ''); +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/qualifierIcon.js b/server/sonar-web/src/main/js/helpers/handlebars/qualifierIcon.js new file mode 100644 index 00000000000..ff61c1bf790 --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/qualifierIcon.js @@ -0,0 +1,7 @@ +import Handlebars from 'handlebars/runtime'; + +module.exports = function (qualifier) { + return new Handlebars.default.SafeString( + qualifier ? '<i class="icon-qualifier-' + qualifier.toLowerCase() + '"></i>' : '' + ); +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/recursive.js b/server/sonar-web/src/main/js/helpers/handlebars/recursive.js new file mode 100644 index 00000000000..c123d31416a --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/recursive.js @@ -0,0 +1,15 @@ +let audaciousFn; + +module.exports = function (children, options) { + var out = ''; + + if (options.fn !== undefined) { + audaciousFn = options.fn; + } + + children.forEach(function (child) { + out = out + audaciousFn(child); + }); + + return out; +} diff --git a/server/sonar-web/src/main/js/helpers/handlebars/repeat.js b/server/sonar-web/src/main/js/helpers/handlebars/repeat.js new file mode 100644 index 00000000000..1a29f2b4d39 --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/repeat.js @@ -0,0 +1,7 @@ +module.exports = function (number, options) { + var ret = ''; + for (var i = 0; i < number; i++) { + ret += options.fn(this); + } + return ret; +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/rulePermalink.js b/server/sonar-web/src/main/js/helpers/handlebars/rulePermalink.js new file mode 100644 index 00000000000..e0187519286 --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/rulePermalink.js @@ -0,0 +1,3 @@ +module.exports = function (ruleKey) { + return baseUrl + '/coding_rules#rule_key=' + encodeURIComponent(ruleKey); +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/severityChangelog.js b/server/sonar-web/src/main/js/helpers/handlebars/severityChangelog.js new file mode 100644 index 00000000000..135f557584c --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/severityChangelog.js @@ -0,0 +1,7 @@ +import Handlebars from 'handlebars/runtime'; + +module.exports = function (severity) { + var label = '<i class="icon-severity-' + severity.toLowerCase() + '"></i> ' + window.t('severity', severity), + message = window.tp('quality_profiles.severity_set_to_x', label); + return new Handlebars.default.SafeString(message); +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/severityHelper.js b/server/sonar-web/src/main/js/helpers/handlebars/severityHelper.js new file mode 100644 index 00000000000..815ca6800ac --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/severityHelper.js @@ -0,0 +1,7 @@ +import Handlebars from 'handlebars/runtime'; + +module.exports = function (severity) { + return new Handlebars.default.SafeString( + '<i class="icon-severity-' + severity.toLowerCase() + '"></i> ' + window.t('severity', severity) + ); +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/severityIcon.js b/server/sonar-web/src/main/js/helpers/handlebars/severityIcon.js new file mode 100644 index 00000000000..e3aa78e48cb --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/severityIcon.js @@ -0,0 +1,7 @@ +import Handlebars from 'handlebars/runtime'; + +module.exports = function (severity) { + return new Handlebars.default.SafeString( + '<i class="icon-severity-' + severity.toLowerCase() + '"></i>' + ); +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/show.js b/server/sonar-web/src/main/js/helpers/handlebars/show.js new file mode 100644 index 00000000000..54a7ef545c6 --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/show.js @@ -0,0 +1,10 @@ +module.exports = function () { + var args = Array.prototype.slice.call(arguments), + ret = null; + args.forEach(function (arg) { + if (typeof arg === 'string' && ret == null) { + ret = arg; + } + }); + return ret || ''; +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/sources.js b/server/sonar-web/src/main/js/helpers/handlebars/sources.js new file mode 100644 index 00000000000..2c3a25e8e2b --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/sources.js @@ -0,0 +1,18 @@ +module.exports = function (source, scm, options) { + if (options == null) { + options = scm; + scm = null; + } + + var sources = _.map(source, function (code, line) { + return { + lineNumber: line, + code: code, + scm: (scm && scm[line]) ? { author: scm[line][0], date: scm[line][1] } : undefined + }; + }); + + return sources.reduce(function (prev, current, index) { + return prev + options.fn(_.extend({ first: index === 0 }, current)); + }, ''); +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/statusHelper.js b/server/sonar-web/src/main/js/helpers/handlebars/statusHelper.js new file mode 100644 index 00000000000..1a2099cbee6 --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/statusHelper.js @@ -0,0 +1,9 @@ +import Handlebars from 'handlebars/runtime'; + +module.exports = function (status, resolution) { + var s = '<i class="icon-status-' + status.toLowerCase() + '"></i> ' + window.t('issue.status', status); + if (resolution != null) { + s = s + ' (' + window.t('issue.resolution', resolution) + ')'; + } + return new Handlebars.default.SafeString(s); +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/statusIcon.js b/server/sonar-web/src/main/js/helpers/handlebars/statusIcon.js new file mode 100644 index 00000000000..76d9b4869d2 --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/statusIcon.js @@ -0,0 +1,7 @@ +import Handlebars from 'handlebars/runtime'; + +module.exports = function (status) { + return new Handlebars.default.SafeString( + '<i class="icon-status-' + status.toLowerCase() + '"></i>' + ); +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/sum.js b/server/sonar-web/src/main/js/helpers/handlebars/sum.js new file mode 100644 index 00000000000..dc82107b74f --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/sum.js @@ -0,0 +1,6 @@ +module.exports = function () { + var args = Array.prototype.slice.call(arguments, 0, -1); + return args.reduce(function (p, c) { + return p + +c; + }, 0); +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/t.js b/server/sonar-web/src/main/js/helpers/handlebars/t.js new file mode 100644 index 00000000000..3fd74714904 --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/t.js @@ -0,0 +1,4 @@ +module.exports = function () { + var args = Array.prototype.slice.call(arguments, 0, -1); + return window.t.apply(this, args); +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/testStatusIcon.js b/server/sonar-web/src/main/js/helpers/handlebars/testStatusIcon.js new file mode 100644 index 00000000000..5f52f1a78de --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/testStatusIcon.js @@ -0,0 +1,7 @@ +import Handlebars from 'handlebars/runtime'; + +module.exports = function (status) { + return new Handlebars.default.SafeString( + '<i class="icon-test-status-' + status.toLowerCase() + '"></i>' + ); +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/testStatusIconClass.js b/server/sonar-web/src/main/js/helpers/handlebars/testStatusIconClass.js new file mode 100644 index 00000000000..17e36c6f624 --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/testStatusIconClass.js @@ -0,0 +1,7 @@ +import Handlebars from 'handlebars/runtime'; + +module.exports = function (status) { + return new Handlebars.default.SafeString('' + + 'icon-test-status-' + status.toLowerCase() + ); +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/tp.js b/server/sonar-web/src/main/js/helpers/handlebars/tp.js new file mode 100644 index 00000000000..d7b8f69a0b5 --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/tp.js @@ -0,0 +1,4 @@ +module.exports = function () { + var args = Array.prototype.slice.call(arguments, 0, -1); + return window.tp.apply(this, args); +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/translate.js b/server/sonar-web/src/main/js/helpers/handlebars/translate.js new file mode 100644 index 00000000000..b4fd0b23178 --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/translate.js @@ -0,0 +1,4 @@ +module.exports = function () { + var args = Array.prototype.slice.call(arguments, 0, -1); + return window.translate.apply(this, args); +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/unlessLength.js b/server/sonar-web/src/main/js/helpers/handlebars/unlessLength.js new file mode 100644 index 00000000000..2c55bdbd49c --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/unlessLength.js @@ -0,0 +1,6 @@ +import _ from 'underscore'; + +module.exports = function (array, len, options) { + var cond = _.isArray(array) && array.length === +len; + return cond ? options.inverse(this) : options.fn(this); +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/withFirst.js b/server/sonar-web/src/main/js/helpers/handlebars/withFirst.js new file mode 100644 index 00000000000..fd0d97a81c0 --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/withFirst.js @@ -0,0 +1,7 @@ +module.exports = function (list, options) { + if (list && list.length > 0) { + return options.fn(list[0]); + } else { + return ''; + } +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/withLast.js b/server/sonar-web/src/main/js/helpers/handlebars/withLast.js new file mode 100644 index 00000000000..61c402cdaf6 --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/withLast.js @@ -0,0 +1,7 @@ +module.exports = function (list, options) { + if (list && list.length > 0) { + return options.fn(list[list.length - 1]); + } else { + return ''; + } +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/withSign.js b/server/sonar-web/src/main/js/helpers/handlebars/withSign.js new file mode 100644 index 00000000000..372d0c7053b --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/withSign.js @@ -0,0 +1,3 @@ +module.exports = function (number) { + return number >= 0 ? '+' + number : '' + number; +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/withoutFirst.js b/server/sonar-web/src/main/js/helpers/handlebars/withoutFirst.js new file mode 100644 index 00000000000..da5f1c528e0 --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/withoutFirst.js @@ -0,0 +1,9 @@ +module.exports = function (list, options) { + if (list && list.length > 1) { + return list.slice(1).reduce(function (prev, current) { + return prev + options.fn(current); + }, ''); + } else { + return ''; + } +}; |