From 326cf2a887dd5583e97283c08b4102d4f562fde3 Mon Sep 17 00:00:00 2001 From: Stas Vilchik Date: Fri, 20 Feb 2015 11:04:02 +0100 Subject: [PATCH] fix quality flaws --- server/sonar-web/Gruntfile.coffee | 2 - .../js/coding-rules/bulk-change-popup-view.js | 6 +- .../src/main/js/graphics/barchart.js | 14 +- .../src/main/js/source-viewer/viewer.js | 3 +- server/sonar-web/src/main/js/top-search.js | 172 ------------------ 5 files changed, 11 insertions(+), 186 deletions(-) delete mode 100644 server/sonar-web/src/main/js/top-search.js diff --git a/server/sonar-web/Gruntfile.coffee b/server/sonar-web/Gruntfile.coffee index fbb1f883bc3..840d2784188 100644 --- a/server/sonar-web/Gruntfile.coffee +++ b/server/sonar-web/Gruntfile.coffee @@ -102,7 +102,6 @@ module.exports = (grunt) -> '<%= grunt.option("assetsDir") || pkg.assets %>js/graphics/pie-chart.js' '<%= grunt.option("assetsDir") || pkg.assets %>js/graphics/timeline.js' '<%= grunt.option("assetsDir") || pkg.assets %>js/graphics/barchart.js' - '<%= grunt.option("assetsDir") || pkg.assets %>js/top-search.js' '<%= grunt.option("assetsDir") || pkg.assets %>js/sortable.js' '<%= grunt.option("assetsDir") || pkg.assets %>js/common/inputs.js' '<%= grunt.option("assetsDir") || pkg.assets %>js/common/dialogs.js' @@ -148,7 +147,6 @@ module.exports = (grunt) -> '<%= grunt.option("assetsDir") || pkg.assets %>js/graphics/pie-chart.js' '<%= grunt.option("assetsDir") || pkg.assets %>js/graphics/timeline.js' '<%= grunt.option("assetsDir") || pkg.assets %>js/graphics/barchart.js' - '<%= grunt.option("assetsDir") || pkg.assets %>js/top-search.js' '<%= grunt.option("assetsDir") || pkg.assets %>js/sortable.js' '<%= grunt.option("assetsDir") || pkg.assets %>js/common/inputs.js' '<%= grunt.option("assetsDir") || pkg.assets %>js/common/dialogs.js' diff --git a/server/sonar-web/src/main/js/coding-rules/bulk-change-popup-view.js b/server/sonar-web/src/main/js/coding-rules/bulk-change-popup-view.js index a8eb0b8fb96..b54ba6a457e 100644 --- a/server/sonar-web/src/main/js/coding-rules/bulk-change-popup-view.js +++ b/server/sonar-web/src/main/js/coding-rules/bulk-change-popup-view.js @@ -27,13 +27,13 @@ define([ var query = this.options.app.state.get('query'), profileKey = query.qprofile, profile = _.findWhere(this.options.app.qualityProfiles, { key: profileKey }), - activation = query.activation; + activation = '' + query.activation; return { qualityProfile: profileKey, qualityProfileName: profile != null ? profile.name : null, - allowActivateOnProfile: profileKey != null && (activation === 'false' || activation === false), - allowDeactivateOnProfile: profileKey != null && (activation === 'true' || activation === true) + allowActivateOnProfile: profileKey != null && activation === 'false', + allowDeactivateOnProfile: profileKey != null && activation === 'true' }; } }); diff --git a/server/sonar-web/src/main/js/graphics/barchart.js b/server/sonar-web/src/main/js/graphics/barchart.js index 8520bbf5d80..c45b331b2d1 100644 --- a/server/sonar-web/src/main/js/graphics/barchart.js +++ b/server/sonar-web/src/main/js/graphics/barchart.js @@ -9,7 +9,12 @@ height: 140, color: '#1f77b4', interpolate: 'basis', - endDate: moment().format('YYYY-MM-DD') + endDate: moment().format('YYYY-MM-DD'), + + marginLeft: 1, + marginRight: 1, + marginTop: 18, + marginBottom: 1 }; }; @@ -48,13 +53,6 @@ yScale = d3.scale.linear() .domain([0, yScaleMax]); - _.extend(options, { - marginLeft: 1, - marginRight: 1, - marginTop: 18, - marginBottom: 1 - }); - _.extend(options, { availableWidth: options.width - options.marginLeft - options.marginRight, availableHeight: options.height - options.marginTop - options.marginBottom diff --git a/server/sonar-web/src/main/js/source-viewer/viewer.js b/server/sonar-web/src/main/js/source-viewer/viewer.js index cb3f65bfc5a..6d8d9636eaa 100644 --- a/server/sonar-web/src/main/js/source-viewer/viewer.js +++ b/server/sonar-web/src/main/js/source-viewer/viewer.js @@ -392,7 +392,8 @@ define([ line = $(e.currentTarget).data('line-number'), blocks = this.model.get('duplications')[index - 1].blocks; blocks = _.filter(blocks, function (b) { - return (b._ref !== '1') || (b._ref === '1' && b.from > line) || (b._ref === '1' && b.from + b.size < line); + var outOfBounds = b.from > line || b.from + b.size < line; + return (b._ref !== '1') || (b._ref === '1' && outOfBounds); }); var popup = new DuplicationPopupView({ triggerEl: $(e.currentTarget), diff --git a/server/sonar-web/src/main/js/top-search.js b/server/sonar-web/src/main/js/top-search.js deleted file mode 100644 index 31fad10cc27..00000000000 --- a/server/sonar-web/src/main/js/top-search.js +++ /dev/null @@ -1,172 +0,0 @@ -(function($) { - - $.fn.topSearch = function(options) { - - var el = $(this), - resultsEl = $(options.results), - spinnerEl = $(options.spinner); - - var index, total, selected, items, term, symbol = false; - - - var select = function() { - if (selected) { - selected.removeClass('selected'); - } - - selected = items.eq(index); - selected.addClass('selected'); - }, - - selectPrev = function() { - if (index > 0) { - index--; - } - select(); - }, - - selectNext = function() { - if (index < total - 1) { - index++; - } - select(); - }, - - choose = function() { - if (selected) { - var key = selected.data('key'); - window.location = baseUrl + '/dashboard/index/' + key + dashboardParameters(); - } - }, - - show = function(r) { - resultsEl.empty(); - - var ul = $('').appendTo(resultsEl); - - r.results.forEach(function(qualifier) { - qualifier.items.forEach(function(item, idx) { - var itemEl = $('
  • ') - .data('key', item.id), - - q = $('
    ') - .addClass('q') - .appendTo(itemEl), - - highlightRegexp = new RegExp(term, 'gi'), - highlightedName = item.name.replace(highlightRegexp, '$&'), - - label = $('') - .html(' ' + highlightedName) - .appendTo(itemEl); - - $('') - .addClass('icon-qualifier-' + qualifier.q.toLowerCase()) - .prependTo(label); - - if (idx === 0) { - q.text(qualifier.name); - } - - itemEl.appendTo(ul); - }); - }); - - resultsEl.append('
    ' + r.total + ' ' + resultsEl.data('results') + '
    '); - - resultsEl.show(); - - if (r.total === 0) { - ul.append('
  • ' + resultsEl.data('no-results') + '
  • '); - } else { - items = resultsEl.find('li'); - index = -1; - total = items.length; - selectNext(); - - items - .on('mouseover', function() { - index = items.index($(this)); - select(); - }) - .on('click', function() { - index = items.index($(this)); - select(); - choose(); - }); - } - }, - - hide = function() { - resultsEl.fadeOut(); - }, - - onKeyup = function() { - if (symbol) { - if (el.val().length >= options.minLength) { - term = el.val(); - - spinnerEl.show(); - $.ajax({ - url: baseUrl + '/api/components/suggestions', - data: { s: term } - }) - .done(function(r) { - show(r); - }) - .fail(hide) - .always(function() { - spinnerEl.hide(); - }); - } else { - hide(); - } - } - }, - - debouncedKeyup = _.debounce(onKeyup, 250), - - onKeyDown = function(e) { - if ([13, 38, 40, 37, 39, 16, 17, 18, 91, 20, 21].indexOf(e.keyCode) !== -1) { - symbol = false; - } - - switch (e.keyCode) { - case 13: // return - e.preventDefault(); - choose(); - return; - case 38: // up - e.preventDefault(); - selectPrev(); - return; - case 40: // down - e.preventDefault(); - selectNext(); - return; - default: - symbol = true; - } - }; - - - el - .on('keydown', onKeyDown) - .on('keyup', debouncedKeyup) - .on('focus', function() { - el.data('placeholder', el.val()); - el.val(''); - }) - .on('focusout', function() { - if (el.val().length === 0) { - el.val(el.data('placeholder') || ''); - } - hide(); - }); - - $('body').on('mousedown', function() { - hide(); - }); - }; - -})(jQuery); -- 2.39.5