aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/main/js/coding-rules
diff options
context:
space:
mode:
authorStas Vilchik <vilchiks@gmail.com>2015-01-21 17:45:22 +0100
committerStas Vilchik <vilchiks@gmail.com>2015-01-21 17:49:57 +0100
commit9fb7e333d10e6c834994e27de86b31e7ee06ac70 (patch)
tree37c4de43b11435ecd226ccabcff195d2c05771f5 /server/sonar-web/src/main/js/coding-rules
parent9f73addd1004325b911a58327a391058e3b4c69b (diff)
downloadsonarqube-9fb7e333d10e6c834994e27de86b31e7ee06ac70.tar.gz
sonarqube-9fb7e333d10e6c834994e27de86b31e7ee06ac70.zip
SONAR-5820/SONAR-5987 Ability to filter rules that are active in a quality profile
Diffstat (limited to 'server/sonar-web/src/main/js/coding-rules')
-rw-r--r--server/sonar-web/src/main/js/coding-rules/controller.js1
-rw-r--r--server/sonar-web/src/main/js/coding-rules/models/rules.js14
-rw-r--r--server/sonar-web/src/main/js/coding-rules/rule/profile-activation-view.js8
-rw-r--r--server/sonar-web/src/main/js/coding-rules/rule/rule-profile-view.js7
-rw-r--r--server/sonar-web/src/main/js/coding-rules/workspace-list-item-view.js53
5 files changed, 69 insertions, 14 deletions
diff --git a/server/sonar-web/src/main/js/coding-rules/controller.js b/server/sonar-web/src/main/js/coding-rules/controller.js
index 6a502e4a0e8..f00691c679d 100644
--- a/server/sonar-web/src/main/js/coding-rules/controller.js
+++ b/server/sonar-web/src/main/js/coding-rules/controller.js
@@ -19,6 +19,7 @@ define([
profile = this.app.state.get('query').qprofile;
if (profile != null) {
fields.push('actives');
+ fields.push('params');
}
return {
p: this.app.state.get('page'),
diff --git a/server/sonar-web/src/main/js/coding-rules/models/rules.js b/server/sonar-web/src/main/js/coding-rules/models/rules.js
index e6d92e6135e..60bb4d7e48f 100644
--- a/server/sonar-web/src/main/js/coding-rules/models/rules.js
+++ b/server/sonar-web/src/main/js/coding-rules/models/rules.js
@@ -6,11 +6,19 @@ define([
model: Rule,
parseRules: function (r) {
- var rules = r.rules;
+ var rules = r.rules,
+ profileBases = r.qProfiles || [];
+
if (r.actives != null) {
rules = rules.map(function (rule) {
- var profiles = r.actives[rule.key];
- return _.extend(rule, { activeProfiles: profiles });
+ var profiles = (r.actives[rule.key] || []).map(function (profile) {
+ _.extend(profile, profileBases[profile.qProfile]);
+ if (profile.parent != null) {
+ _.extend(profile, { parentProfile: profileBases[profile.parent] });
+ }
+ return profile;
+ });
+ return _.extend(rule, { activeProfile: profiles.length > 0 ? profiles[0] : null });
});
}
return rules;
diff --git a/server/sonar-web/src/main/js/coding-rules/rule/profile-activation-view.js b/server/sonar-web/src/main/js/coding-rules/rule/profile-activation-view.js
index a9c0bee72d0..f83b0341a9a 100644
--- a/server/sonar-web/src/main/js/coding-rules/rule/profile-activation-view.js
+++ b/server/sonar-web/src/main/js/coding-rules/rule/profile-activation-view.js
@@ -83,7 +83,11 @@ define([
params: paramsHash
}
}).done(function () {
- that.options.app.controller.showDetails(that.options.rule);
+ if (that.options.fromList) {
+ that.options.rule.set({ activeProfile: { qProfile: profileKey, inherit: 'NONE', severity: severity } });
+ } else {
+ that.options.app.controller.showDetails(that.options.rule);
+ }
window.process.finishBackgroundProcess(p);
}).fail(function () {
that.options.app.controller.showDetails(that.options.rule);
@@ -92,7 +96,7 @@ define([
},
getAvailableQualityProfiles: function (lang) {
- var activeQualityProfiles = this.collection,
+ var activeQualityProfiles = this.collection || new Backbone.Collection(),
inactiveProfiles = _.reject(this.options.app.qualityProfiles, function (profile) {
return activeQualityProfiles.findWhere({ key: profile.key });
});
diff --git a/server/sonar-web/src/main/js/coding-rules/rule/rule-profile-view.js b/server/sonar-web/src/main/js/coding-rules/rule/rule-profile-view.js
index 5625796913d..37f1cbcdf53 100644
--- a/server/sonar-web/src/main/js/coding-rules/rule/rule-profile-view.js
+++ b/server/sonar-web/src/main/js/coding-rules/rule/rule-profile-view.js
@@ -64,13 +64,10 @@ define([
deactivate: function () {
var that = this,
- ruleKey = this.options.rule.get('key'),
- myProfile = _.findWhere(this.options.app.qualityProfiles, {
- key: this.model.get('qProfile')
- });
+ ruleKey = this.options.rule.get('key');
window.confirmDialog({
title: t('coding_rules.deactivate'),
- html: tp('coding_rules.deactivate.confirm', myProfile.name),
+ html: tp('coding_rules.deactivate.confirm'),
yesHandler: function () {
var p = window.process.addBackgroundProcess();
return jQuery.ajax({
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 02627c69f24..8a8dc8e2c57 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
@@ -1,7 +1,8 @@
define([
'components/navigator/workspace-list-item-view',
+ 'coding-rules/rule/profile-activation-view',
'templates/coding-rules'
-], function (WorkspaceListItemView) {
+], function (WorkspaceListItemView, ProfileActivationView) {
return WorkspaceListItemView.extend({
className: 'coding-rule',
@@ -13,7 +14,9 @@ define([
events: {
'click': 'selectCurrent',
- 'click .js-rule': 'openRule'
+ 'click .js-rule': 'openRule',
+ 'click .coding-rules-detail-quality-profile-activate': 'activate',
+ 'click .coding-rules-detail-quality-profile-deactivate': 'deactivate'
},
selectCurrent: function () {
@@ -24,9 +27,51 @@ define([
this.options.app.controller.showDetails(this.model);
},
+ getActiveProfile: function () {
+ return this.model.get('activeProfile');
+ },
+
+ activate: function () {
+ var activeProfile = this.options.app.state.get('query').qprofile,
+ othersQualityProfiles = _.reject(this.options.app.qualityProfiles, function (profile) {
+ return profile.key === activeProfile;
+ });
+
+ new ProfileActivationView({
+ rule: this.model,
+ collection: new Backbone.Collection(othersQualityProfiles),
+ app: this.options.app,
+ fromList: true
+ }).render();
+ },
+
+ deactivate: function () {
+ var that = this,
+ ruleKey = this.model.get('key'),
+ myProfile = this.model.get('activeProfile');
+ window.confirmDialog({
+ title: t('coding_rules.deactivate'),
+ html: tp('coding_rules.deactivate.confirm'),
+ yesHandler: function () {
+ var p = window.process.addBackgroundProcess();
+ return jQuery.ajax({
+ type: 'POST',
+ url: baseUrl + '/api/qualityprofiles/deactivate_rule',
+ data: {
+ profile_key: myProfile.qProfile,
+ rule_key: ruleKey
+ }
+ }).done(function () {
+ window.process.finishBackgroundProcess(p);
+ var newProfile = _.extend({}, myProfile, { severity: undefined });
+ that.model.set({ activeProfile: newProfile });
+ });
+ }
+ });
+ },
+
serializeData: function () {
- var activeProfiles = this.model.get('activeProfiles'),
- activeProfile = _.isArray(activeProfiles) && activeProfiles.length === 1 ? activeProfiles[0] : null,
+ var activeProfile = this.getActiveProfile(),
selectedProfile = this.options.app.state.get('query').qprofile;
if (selectedProfile != null && activeProfile == null) {
activeProfile = selectedProfile;