From: Stas Vilchik Date: Tue, 3 Oct 2017 14:13:14 +0000 (+0200) Subject: SONAR-9665 Bring back the issues link from the Most Violated Projects section X-Git-Tag: 6.6-RC1~66 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=dcea9d6a8eb3084cc06d31f88d2dc2a099180898;p=sonarqube.git SONAR-9665 Bring back the issues link from the Most Violated Projects section --- diff --git a/server/sonar-web/src/main/js/apps/coding-rules/rule/rule-issues-view.js b/server/sonar-web/src/main/js/apps/coding-rules/rule/rule-issues-view.js index e9cdac4acf7..74406c29807 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/rule/rule-issues-view.js +++ b/server/sonar-web/src/main/js/apps/coding-rules/rule/rule-issues-view.js @@ -17,26 +17,38 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -import $ from 'jquery'; import Marionette from 'backbone.marionette'; import Template from '../templates/rule/coding-rules-rule-issues.hbs'; -import { getComponentIssuesUrlAsString } from '../../../helpers/urls'; +import { searchIssues } from '../../../api/issues'; +import { getComponentIssuesUrlAsString, getBaseUrl } from '../../../helpers/urls'; export default Marionette.ItemView.extend({ template: Template, initialize() { - const that = this; this.total = null; this.projects = []; - this.requestIssues().done(() => { - that.render(); - }); + this.loading = true; + this.mounted = true; + this.requestIssues().then( + () => { + if (this.mounted) { + this.loading = false; + this.render(); + } + }, + () => { + this.loading = false; + } + ); + }, + + onDestroy() { + this.mounted = false; }, requestIssues() { - const url = window.baseUrl + '/api/issues/search'; - const options = { + const parameters = { rules: this.model.id, resolved: false, ps: 1, @@ -44,9 +56,9 @@ export default Marionette.ItemView.extend({ }; const { organization } = this.options.app; if (organization) { - Object.assign(options, { organization }); + Object.assign(parameters, { organization }); } - return $.get(url, options).done(r => { + return searchIssues(parameters).then(r => { const projectsFacet = r.facets.find(facet => facet.property === 'projectUuids'); let projects = projectsFacet != null ? projectsFacet.values : []; projects = projects.map(project => { @@ -68,9 +80,15 @@ export default Marionette.ItemView.extend({ }, serializeData() { + const { organization } = this.options.app; + const pathname = organization ? `/organizations/${organization}/issues` : '/issues'; + const query = `?resolved=false&rules=${encodeURIComponent(this.model.id)}`; + const totalIssuesUrl = getBaseUrl() + pathname + query; return { ...Marionette.ItemView.prototype.serializeData.apply(this, arguments), + loading: this.loading, total: this.total, + totalIssuesUrl, projects: this.projects }; } diff --git a/server/sonar-web/src/main/js/apps/coding-rules/templates/rule/coding-rules-rule-issues.hbs b/server/sonar-web/src/main/js/apps/coding-rules/templates/rule/coding-rules-rule-issues.hbs index 8aee69dafff..32f822b85ff 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/templates/rule/coding-rules-rule-issues.hbs +++ b/server/sonar-web/src/main/js/apps/coding-rules/templates/rule/coding-rules-rule-issues.hbs @@ -1,21 +1,27 @@
-

- {{t 'coding_rules.issues'}} ({{total}}) -

+{{#if loading}} +

+ {{t 'coding_rules.issues'}} +

+{{else}} +

+ {{t 'coding_rules.issues'}} ({{total}}) +

-{{#notEmpty projects}} - - - - - {{#each projects}} + {{#notEmpty projects}} +
{{t 'coding_rules.most_violating_projects'}}
- - + - {{/each}} -
{{name}} - {{count}} - {{t 'coding_rules.most_violating_projects'}}
-{{/notEmpty}} + {{#each projects}} + + {{name}} + + {{count}} + + + {{/each}} + + {{/notEmpty}} +{{/if}}