From: Stas Vilchik Date: Mon, 20 Apr 2015 12:00:27 +0000 (+0200) Subject: SONAR-6265 Allow modification of rule filter using rule properties X-Git-Tag: 5.2-RC1~2187 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=7d3b02bd2c5bd28999f623567722c132a42b571c;p=sonarqube.git SONAR-6265 Allow modification of rule filter using rule properties --- diff --git a/server/sonar-web/src/main/hbs/coding-rules/coding-rules-rule-filter-form.hbs b/server/sonar-web/src/main/hbs/coding-rules/coding-rules-rule-filter-form.hbs new file mode 100644 index 00000000000..1a414836868 --- /dev/null +++ b/server/sonar-web/src/main/hbs/coding-rules/coding-rules-rule-filter-form.hbs @@ -0,0 +1,18 @@ +
{{t 'coding_rules.filter_similar_rules'}}
+ +
+ + {{langName}} + + + {{#notEmpty tags}} +
+ {{#each tags}} + +  {{this}} + + {{/each}} + {{/notEmpty}} +
+ +
diff --git a/server/sonar-web/src/main/hbs/coding-rules/coding-rules-workspace-list-item.hbs b/server/sonar-web/src/main/hbs/coding-rules/coding-rules-workspace-list-item.hbs index b7202d164c7..92aef7fdc1c 100644 --- a/server/sonar-web/src/main/hbs/coding-rules/coding-rules-workspace-list-item.hbs +++ b/server/sonar-web/src/main/hbs/coding-rules/coding-rules-workspace-list-item.hbs @@ -32,6 +32,9 @@ {{join tags ', '}} {{/notEmpty}} + +   + diff --git a/server/sonar-web/src/main/js/coding-rules/rule-filter-view.js b/server/sonar-web/src/main/js/coding-rules/rule-filter-view.js new file mode 100644 index 00000000000..e1fed12ef5f --- /dev/null +++ b/server/sonar-web/src/main/js/coding-rules/rule-filter-view.js @@ -0,0 +1,43 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube 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. + * + * SonarQube 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. + */ +define([ + 'issue/views/action-options-view', + 'templates/coding-rules' +], function (ActionOptionsView) { + var $ = jQuery; + + return ActionOptionsView.extend({ + template: Templates['coding-rules-rule-filter-form'], + + selectOption: function (e) { + var property = $(e.currentTarget).data('property'), + value = $(e.currentTarget).data('value'); + this.trigger('select', property, value); + return ActionOptionsView.prototype.selectOption.apply(this, arguments); + }, + + serializeData: function () { + return _.extend(ActionOptionsView.prototype.serializeData.apply(this, arguments), { + tags: _.union(this.model.get('sysTags'), this.model.get('tags')) + }); + } + + }); +}); diff --git a/server/sonar-web/src/main/js/coding-rules/workspace-list-item-view.js b/server/sonar-web/src/main/js/coding-rules/workspace-list-item-view.js index 417b352eafa..0b3f942455d 100644 --- a/server/sonar-web/src/main/js/coding-rules/workspace-list-item-view.js +++ b/server/sonar-web/src/main/js/coding-rules/workspace-list-item-view.js @@ -20,8 +20,11 @@ define([ 'components/navigator/workspace-list-item-view', 'coding-rules/rule/profile-activation-view', + 'coding-rules/rule-filter-view', 'templates/coding-rules' -], function (WorkspaceListItemView, ProfileActivationView) { +], function (WorkspaceListItemView, ProfileActivationView, RuleFilterView) { + + var $ = jQuery; return WorkspaceListItemView.extend({ className: 'coding-rule', @@ -35,6 +38,7 @@ define([ 'click': 'selectCurrent', 'dblclick': 'openRule', 'click .js-rule': 'openRule', + 'click .js-rule-filter': 'onRuleFilterClick', 'click .coding-rules-detail-quality-profile-activate': 'activate', 'click .coding-rules-detail-quality-profile-change': 'change', 'click .coding-rules-detail-quality-profile-revert': 'revert', @@ -92,6 +96,25 @@ define([ }); }, + onRuleFilterClick: function (e) { + e.preventDefault(); + e.stopPropagation(); + $('body').click(); + var that = this, + popup = new RuleFilterView({ + triggerEl: $(e.currentTarget), + bottomRight: true, + model: this.model + }); + popup.on('select', function (property, value) { + var obj = {}; + obj[property] = '' + value; + that.options.app.state.updateFilter(obj); + popup.close(); + }); + popup.render(); + }, + serializeData: function () { return _.extend(WorkspaceListItemView.prototype.serializeData.apply(this, arguments), { tags: _.union(this.model.get('sysTags'), this.model.get('tags')), diff --git a/server/sonar-web/src/test/js/coding-rules-page-spec.js b/server/sonar-web/src/test/js/coding-rules-page-spec.js index 807218ddf22..aedc9368686 100644 --- a/server/sonar-web/src/test/js/coding-rules-page-spec.js +++ b/server/sonar-web/src/test/js/coding-rules-page-spec.js @@ -86,3 +86,53 @@ casper.test.begin(testName('Move Between Rules From Detailed View'), 3, function test.done(); }); }); + + +casper.test.begin(testName('Filter Similar Rules'), 3, function (test) { + casper + .start(lib.buildUrl('coding-rules'), function () { + lib.setDefaultViewport(); + + + lib.mockRequestFromFile('/api/rules/app', 'app.json'); + lib.mockRequestFromFile('/api/rules/search', 'search-sql-tag.json', { data: { tags: 'sql' } }); + lib.mockRequestFromFile('/api/rules/search', 'search.json'); + }) + + .then(function () { + casper.evaluate(function () { + require(['/js/coding-rules/app.js']); + }); + }) + + .then(function () { + casper.waitForSelector('.coding-rule.selected .js-rule-filter'); + }) + + .then(function () { + test.assertSelectorContains('#coding-rules-total', '609'); + + casper.click('.js-rule-filter'); + casper.waitForSelector('.bubble-popup'); + }) + + .then(function () { + test.assertExists('.bubble-popup [data-property="languages"][data-value="java"]'); + + casper.click('.bubble-popup [data-property="tags"][data-value="sql"]'); + casper.wait(1000, function () { lib.capture(); }); + casper.waitForSelectorTextChange('#coding-rules-total'); + }) + + .then(function () { + test.assertSelectorContains('#coding-rules-total', '2'); + }) + + .then(function () { + lib.sendCoverage(); + }) + + .run(function () { + test.done(); + }); +}); diff --git a/server/sonar-web/src/test/json/coding-rules/search-sql-tag.json b/server/sonar-web/src/test/json/coding-rules/search-sql-tag.json new file mode 100644 index 00000000000..d03932b85b6 --- /dev/null +++ b/server/sonar-web/src/test/json/coding-rules/search-sql-tag.json @@ -0,0 +1,30 @@ +{ + "total": 2, + "p": 1, + "ps": 200, + "rules": [ + { + "key": "php:S2014", + "tags": [], + "status": "READY", + "langName": "PHP", + "name": "\"$this\" should not be used in a static context", + "lang": "php", + "sysTags": [ + "sql" + ] + }, + { + "key": "squid:S2204", + "tags": [], + "status": "READY", + "langName": "Java", + "name": "\".equals()\" should not be used to test the values of \"Atomic\" classes", + "lang": "java", + "sysTags": [ + "sql" + ] + } + ], + "facets": [] +} diff --git a/sonar-core/src/main/resources/org/sonar/l10n/core.properties b/sonar-core/src/main/resources/org/sonar/l10n/core.properties index c370613d9eb..42fec916b8d 100644 --- a/sonar-core/src/main/resources/org/sonar/l10n/core.properties +++ b/sonar-core/src/main/resources/org/sonar/l10n/core.properties @@ -1928,6 +1928,7 @@ coding_rules.show_template=Show Template coding_rules.noncharacterized=Uncharacterized coding_rules.update_custom_rule=Update Custom Rule coding_rules.update_manual_rule=Update Manual Rule +coding_rules.filter_similar_rules=Filter Similar Rules coding_rules.validation.invalid_rule_key=The rule key "%s" is invalid, it should only contain: a-z, 0-9, "_" coding_rules.validation.missing_name=The name is missing