diff options
author | Stas Vilchik <vilchiks@gmail.com> | 2015-01-21 17:45:22 +0100 |
---|---|---|
committer | Stas Vilchik <vilchiks@gmail.com> | 2015-01-21 17:49:57 +0100 |
commit | 9fb7e333d10e6c834994e27de86b31e7ee06ac70 (patch) | |
tree | 37c4de43b11435ecd226ccabcff195d2c05771f5 /server/sonar-web/src/main/js | |
parent | 9f73addd1004325b911a58327a391058e3b4c69b (diff) | |
download | sonarqube-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')
6 files changed, 258 insertions, 55 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; diff --git a/server/sonar-web/src/main/js/tests/e2e/tests/coding-rules/app.json b/server/sonar-web/src/main/js/tests/e2e/tests/coding-rules/app.json index 4f3319c8707..0eb43bc39f7 100644 --- a/server/sonar-web/src/main/js/tests/e2e/tests/coding-rules/app.json +++ b/server/sonar-web/src/main/js/tests/e2e/tests/coding-rules/app.json @@ -124,45 +124,193 @@ "DEPRECATED": "Deprecated", "READY": "Ready" }, - "characteristics": { - "UNDERSTANDABILITY": "Maintainability: Understandability", - "MAINTAINABILITY": "Maintainability", - "TIME_ZONE_RELATED_PORTABILITY": "Portability: Time zone related portability", - "READABILITY": "Maintainability: Readability", - "SECURITY_FEATURES": "Security: Security features", - "ARCHITECTURE_RELIABILITY": "Reliability: Architecture related reliability", - "OS_RELATED_PORTABILITY": "Portability: OS related portability", - "EXCEPTION_HANDLING": "Reliability: Exception handling", - "LOGIC_CHANGEABILITY": "Changeability: Logic related changeability", - "SOFTWARE_RELATED_PORTABILITY": "Portability: Software related portability", - "INPUT_VALIDATION_AND_REPRESENTATION": "Security: Input validation and representation", - "LANGUAGE_RELATED_PORTABILITY": "Portability: Language related portability", - "ERRORS": "Security: Errors", - "SECURITY": "Security", - "RELIABILITY": "Reliability", - "PORTABILITY": "Portability", - "HARDWARE_RELATED_PORTABILITY": "Portability: Hardware related portability", - "SYNCHRONIZATION_RELIABILITY": "Reliability: Synchronization related reliability", - "TRANSPORTABILITY": "Reusability: Transportability", - "COMPILER_RELATED_PORTABILITY": "Portability: Compiler related portability", - "RESOURCE_RELIABILITY": "Reliability: Resource", - "CPU_EFFICIENCY": "Efficiency: Processor use", - "EFFICIENCY": "Efficiency", - "CHANGEABILITY": "Changeability", - "DATA_CHANGEABILITY": "Changeability: Data related changeability", - "API_ABUSE": "Security: API abuse", - "ARCHITECTURE_CHANGEABILITY": "Changeability: Architecture related changeability", - "UNIT_TESTS": "Reliability: Unit tests", - "INSTRUCTION_RELIABILITY": "Reliability: Instruction related reliability", - "REUSABILITY": "Reusability", - "MODULARITY": "Reusability: Modularity", - "UNIT_TESTABILITY": "Testability: Unit level testability", - "TESTABILITY": "Testability", - "INTEGRATION_TESTABILITY": "Testability: Integration level testability", - "NETWORK_USE": "Efficiency: Network use", - "MEMORY_EFFICIENCY": "Efficiency: Memory use", - "DATA_RELIABILITY": "Reliability: Data related reliability", - "FAULT_TOLERANCE": "Reliability: Fault tolerance", - "LOGIC_RELIABILITY": "Reliability: Logic related reliability" - } + "characteristics": [ + { + "key": "UNDERSTANDABILITY", + "name": "Understandability", + "parent": "MAINTAINABILITY" + }, + { + "key": "MAINTAINABILITY", + "name": "Maintainability" + }, + { + "key": "TIME_ZONE_RELATED_PORTABILITY", + "name": "Time zone related portability", + "parent": "PORTABILITY" + }, + { + "key": "READABILITY", + "name": "Readability", + "parent": "MAINTAINABILITY" + }, + { + "key": "SECURITY_FEATURES", + "name": "Security features", + "parent": "SECURITY" + }, + { + "key": "ARCHITECTURE_RELIABILITY", + "name": "Architecture related reliability", + "parent": "RELIABILITY" + }, + { + "key": "OS_RELATED_PORTABILITY", + "name": "OS related portability", + "parent": "PORTABILITY" + }, + { + "key": "EXCEPTION_HANDLING", + "name": "Exception handling", + "parent": "RELIABILITY" + }, + { + "key": "LOGIC_CHANGEABILITY", + "name": "Logic related changeability", + "parent": "CHANGEABILITY" + }, + { + "key": "SOFTWARE_RELATED_PORTABILITY", + "name": "Software related portability", + "parent": "PORTABILITY" + }, + { + "key": "INPUT_VALIDATION_AND_REPRESENTATION", + "name": "Input validation and representation", + "parent": "SECURITY" + }, + { + "key": "LANGUAGE_RELATED_PORTABILITY", + "name": "Language related portability", + "parent": "PORTABILITY" + }, + { + "key": "ERRORS", + "name": "Errors", + "parent": "SECURITY" + }, + { + "key": "SECURITY", + "name": "Security" + }, + { + "key": "RELIABILITY", + "name": "Reliability" + }, + { + "key": "PORTABILITY", + "name": "Portability" + }, + { + "key": "HARDWARE_RELATED_PORTABILITY", + "name": "Hardware related portability", + "parent": "PORTABILITY" + }, + { + "key": "SYNCHRONIZATION_RELIABILITY", + "name": "Synchronization related reliability", + "parent": "RELIABILITY" + }, + { + "key": "TRANSPORTABILITY", + "name": "Transportability", + "parent": "REUSABILITY" + }, + { + "key": "COMPILER_RELATED_PORTABILITY", + "name": "Compiler related portability", + "parent": "PORTABILITY" + }, + { + "key": "RESOURCE_RELIABILITY", + "name": "Resource", + "parent": "RELIABILITY" + }, + { + "key": "CPU_EFFICIENCY", + "name": "Processor use", + "parent": "EFFICIENCY" + }, + { + "key": "EFFICIENCY", + "name": "Efficiency" + }, + { + "key": "CHANGEABILITY", + "name": "Changeability" + }, + { + "key": "DATA_CHANGEABILITY", + "name": "Data related changeability", + "parent": "CHANGEABILITY" + }, + { + "key": "API_ABUSE", + "name": "API abuse", + "parent": "SECURITY" + }, + { + "key": "ARCHITECTURE_CHANGEABILITY", + "name": "Architecture related changeability", + "parent": "CHANGEABILITY" + }, + { + "key": "UNIT_TESTS", + "name": "Unit tests", + "parent": "RELIABILITY" + }, + { + "key": "INSTRUCTION_RELIABILITY", + "name": "Instruction related reliability", + "parent": "RELIABILITY" + }, + { + "key": "REUSABILITY", + "name": "Reusability" + }, + { + "key": "MODULARITY", + "name": "Modularity", + "parent": "REUSABILITY" + }, + { + "key": "UNIT_TESTABILITY", + "name": "Unit level testability", + "parent": "TESTABILITY" + }, + { + "key": "TESTABILITY", + "name": "Testability" + }, + { + "key": "INTEGRATION_TESTABILITY", + "name": "Integration level testability", + "parent": "TESTABILITY" + }, + { + "key": "NETWORK_USE", + "name": "Network use", + "parent": "EFFICIENCY" + }, + { + "key": "MEMORY_EFFICIENCY", + "name": "Memory use", + "parent": "EFFICIENCY" + }, + { + "key": "DATA_RELIABILITY", + "name": "Data related reliability", + "parent": "RELIABILITY" + }, + { + "key": "FAULT_TOLERANCE", + "name": "Fault tolerance", + "parent": "RELIABILITY" + }, + { + "key": "LOGIC_RELIABILITY", + "name": "Logic related reliability", + "parent": "RELIABILITY" + } + ] } |