From c020c6baecfb3549de4b1afa2a0f72a0357f0b9e Mon Sep 17 00:00:00 2001 From: Stas Vilchik Date: Mon, 13 Apr 2015 17:25:28 +0200 Subject: [PATCH] SONAR-5851 refactor profile fetch --- .../main/js/quality-profiles/controller.js | 5 +- .../src/main/js/quality-profiles/profile.js | 48 +++++++++++++++++++ 2 files changed, 49 insertions(+), 4 deletions(-) diff --git a/server/sonar-web/src/main/js/quality-profiles/controller.js b/server/sonar-web/src/main/js/quality-profiles/controller.js index 7a71e1e71e6..a7071cde771 100644 --- a/server/sonar-web/src/main/js/quality-profiles/controller.js +++ b/server/sonar-web/src/main/js/quality-profiles/controller.js @@ -83,10 +83,7 @@ define([ }, fetchProfile: function (profile) { - return $.when( - this.fetchProfileRules(profile), - this.fetchInheritance(profile) - ); + return profile.fetch(); }, fetchProfileRules: function (profile) { 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 6c1d9684946..c88f747cf97 100644 --- a/server/sonar-web/src/main/js/quality-profiles/profile.js +++ b/server/sonar-web/src/main/js/quality-profiles/profile.js @@ -19,11 +19,59 @@ */ define(function () { + var $ = jQuery; + return Backbone.Model.extend({ idAttribute: 'key', defaults: { activeRuleCount: 0 + }, + + fetch: function () { + var that = this; + this.fetchChanged = {}; + return $.when( + this.fetchProfileRules(), + this.fetchInheritance() + ).done(function () { + that.set(that.fetchChanged); + }); + }, + + fetchProfileRules: function () { + var that = this, + url = baseUrl + '/api/rules/search', + key = this.id, + options = { + ps: 1, + facets: 'severities,tags', + qprofile: key, + activation: 'true' + }; + return $.get(url, options).done(function (r) { + var severityFacet = _.findWhere(r.facets, { property: 'severities' }); + if (severityFacet != null) { + var severities = severityFacet.values, + severityComparator = function (s) { + return window.severityColumnsComparator(s.val); + }, + sortedSeverities = _.sortBy(severities, severityComparator); + _.extend(that.fetchChanged, { rulesSeverities: sortedSeverities }); + } + }); + }, + + fetchInheritance: function () { + var that = this, + url = baseUrl + '/api/qualityprofiles/inheritance', + options = { profileKey: this.id }; + return $.get(url, options).done(function (r) { + _.extend(that.fetchChanged, r.profile, { + ancestors: r.ancestors, + children: r.children + }); + }); } }); -- 2.39.5