From 978d8a5ba9bdfff3c2cfb875e43f8f30d361a8d2 Mon Sep 17 00:00:00 2001 From: Stas Vilchik Date: Mon, 20 Apr 2015 12:48:42 +0200 Subject: [PATCH] SONAR-5851 show number of associated projects --- .../quality-profiles/quality-profiles-profile.hbs | 12 +++++++----- .../main/js/quality-profiles/profile-details-view.js | 7 ++++++- .../src/main/js/quality-profiles/profile-view.js | 6 ++++++ .../src/main/js/quality-profiles/profile.js | 3 ++- .../src/main/js/quality-profiles/profiles.js | 11 +++++++++++ server/sonar-web/src/test/js/quality-profiles.js | 10 +++++----- .../main/resources/org/sonar/l10n/core.properties | 1 + 7 files changed, 38 insertions(+), 12 deletions(-) diff --git a/server/sonar-web/src/main/hbs/quality-profiles/quality-profiles-profile.hbs b/server/sonar-web/src/main/hbs/quality-profiles/quality-profiles-profile.hbs index 3a9d461703e..030140c27b1 100644 --- a/server/sonar-web/src/main/hbs/quality-profiles/quality-profiles-profile.hbs +++ b/server/sonar-web/src/main/hbs/quality-profiles/quality-profiles-profile.hbs @@ -7,11 +7,13 @@ {{/if}} {{name}} - {{#if isDefault}} - - {{t 'default'}} - - {{/if}} + + {{#if isDefault}} + {{t 'default'}} + {{else}} + {{tp 'quality_profiles.x_projects' projectCountFormatted}} + {{/if}} + diff --git a/server/sonar-web/src/main/js/quality-profiles/profile-details-view.js b/server/sonar-web/src/main/js/quality-profiles/profile-details-view.js index 96146f29159..51aa787cb3f 100644 --- a/server/sonar-web/src/main/js/quality-profiles/profile-details-view.js +++ b/server/sonar-web/src/main/js/quality-profiles/profile-details-view.js @@ -61,7 +61,7 @@ define([ initProjectsSelect: function () { var key = this.model.get('key'); - new window.SelectList({ + this.projectsSelectList = new window.SelectList({ el: this.$('#quality-profile-projects-list'), width: '100%', readOnly: !this.options.canWrite, @@ -88,6 +88,7 @@ define([ deselect: t('quality_gates.projects.deselect_hint') } }); + this.listenTo(this.projectsSelectList.collection, 'change:selected', this.onProjectsChange); }, onProfileClick: function (e) { @@ -104,6 +105,10 @@ define([ this.changeParent(); }, + onProjectsChange: function () { + this.model.collection.updateForLanguage(this.model.get('language')); + }, + changeParent: function () { new ChangeProfileParentView({ model: this.model diff --git a/server/sonar-web/src/main/js/quality-profiles/profile-view.js b/server/sonar-web/src/main/js/quality-profiles/profile-view.js index d2d42aee324..b8c69aba0fb 100644 --- a/server/sonar-web/src/main/js/quality-profiles/profile-view.js +++ b/server/sonar-web/src/main/js/quality-profiles/profile-view.js @@ -48,6 +48,12 @@ define([ onClick: function (e) { e.preventDefault(); this.model.trigger('select', this.model); + }, + + serializeData: function () { + return _.extend(Marionette.ItemView.prototype.serializeData.apply(this, arguments), { + projectCountFormatted: window.formatMeasure(this.model.get('projectCount'), 'INT') + }); } }); diff --git a/server/sonar-web/src/main/js/quality-profiles/profile.js b/server/sonar-web/src/main/js/quality-profiles/profile.js index 3f061e4a9a9..4f4bd39133a 100644 --- a/server/sonar-web/src/main/js/quality-profiles/profile.js +++ b/server/sonar-web/src/main/js/quality-profiles/profile.js @@ -25,7 +25,8 @@ define(function () { idAttribute: 'key', defaults: { - activeRuleCount: 0 + activeRuleCount: 0, + projectCount: 0 }, fetch: function () { diff --git a/server/sonar-web/src/main/js/quality-profiles/profiles.js b/server/sonar-web/src/main/js/quality-profiles/profiles.js index c7d5c45f397..38c0477ca29 100644 --- a/server/sonar-web/src/main/js/quality-profiles/profiles.js +++ b/server/sonar-web/src/main/js/quality-profiles/profiles.js @@ -28,6 +28,17 @@ define([ parse: function (r) { return r.profiles; + }, + + updateForLanguage: function (language) { + this.fetch({ + data: { + language: language + }, + merge: true, + reset: false, + remove: false + }); } }); diff --git a/server/sonar-web/src/test/js/quality-profiles.js b/server/sonar-web/src/test/js/quality-profiles.js index 63e7a65ea55..04ca1ff46f6 100644 --- a/server/sonar-web/src/test/js/quality-profiles.js +++ b/server/sonar-web/src/test/js/quality-profiles.js @@ -59,7 +59,7 @@ casper.test.begin(testName('Should Show List'), 9, function (test) { test.assertSelectorContains('.js-list-language', 'PHP'); test.assertSelectorContains('.js-list-language', 'Python'); - test.assertElementCount('.js-list .note', 4); + test.assertElementCount('.js-list .badge', 4); }) .then(function () { @@ -557,8 +557,8 @@ casper.test.begin(testName('Make Profile Default'), 4, function (test) { }) .then(function () { - test.assertDoesntExist('.js-list .list-group-item[data-key="php-psr-2-46772"] .note'); - test.assertExists('.js-list .list-group-item[data-key="php-sonar-way-10778"] .note'); + test.assertDoesntExist('.js-list .list-group-item[data-key="php-psr-2-46772"] .badge'); + test.assertExists('.js-list .list-group-item[data-key="php-sonar-way-10778"] .badge'); casper.click('.js-list .list-group-item[data-key="php-psr-2-46772"]'); casper.waitForSelector('#quality-profile-set-as-default'); }) @@ -568,12 +568,12 @@ casper.test.begin(testName('Make Profile Default'), 4, function (test) { lib.mockRequestFromFile('/api/qualityprofiles/search', 'search-another-default.json'); casper.click('#quality-profile-set-as-default'); - casper.waitWhileSelector('.js-list .list-group-item[data-key="php-sonar-way-10778"] .note'); + casper.waitWhileSelector('.js-list .list-group-item[data-key="php-sonar-way-10778"] .badge'); }) .then(function () { test.assertDoesntExist('#quality-profile-set-as-default'); - test.assertExists('.js-list .list-group-item[data-key="php-psr-2-46772"] .note'); + test.assertExists('.js-list .list-group-item[data-key="php-psr-2-46772"] .badge'); }) .then(function () { 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 3b08fd16d2c..2d0fa3b2f14 100644 --- a/sonar-core/src/main/resources/org/sonar/l10n/core.properties +++ b/sonar-core/src/main/resources/org/sonar/l10n/core.properties @@ -1794,6 +1794,7 @@ quality_profiles.x_overridden_rules={0} overridden rules quality_profiles.change_parent=Change Parent quality_profiles.all_profiles=All Profiles quality_profiles.x_profiles={0} Profiles +quality_profiles.x_projects={0} projects -- 2.39.5