]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9665 Bring back the issues link from the Most Violated Projects section
authorStas Vilchik <stas.vilchik@sonarsource.com>
Tue, 3 Oct 2017 14:13:14 +0000 (16:13 +0200)
committerStas Vilchik <stas.vilchik@sonarsource.com>
Wed, 4 Oct 2017 08:35:13 +0000 (10:35 +0200)
server/sonar-web/src/main/js/apps/coding-rules/rule/rule-issues-view.js
server/sonar-web/src/main/js/apps/coding-rules/templates/rule/coding-rules-rule-issues.hbs

index e9cdac4acf7bf0cd4cea99eb5a2e61c5a615b013..74406c29807d8e2292970d97c7901d62e16c34d4 100644 (file)
  * 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
     };
   }
index 8aee69daffffca9cdbc9c604783374d19532118a..32f822b85ff7407d8dadd8f4ebd741fa91405335 100644 (file)
@@ -1,21 +1,27 @@
 <div class="coding-rule-section-separator"></div>
 
-<h3 class="coding-rules-detail-title">
-  {{t 'coding_rules.issues'}} ({{total}})
-</h3>
+{{#if loading}}
+  <h3 class="coding-rules-detail-title">
+    {{t 'coding_rules.issues'}} <i class="spinner spacer-left"/>
+  </h3>
+{{else}}
+  <h3 class="coding-rules-detail-title">
+    {{t 'coding_rules.issues'}} (<a href="{{totalIssuesUrl}}">{{total}}</a>)
+  </h3>
 
-{{#notEmpty projects}}
-  <table class="coding-rules-detail-list coding-rules-most-violated-projects">
-    <tr>
-      <td class="coding-rules-detail-list-name" colspan="2">{{t 'coding_rules.most_violating_projects'}}</td>
-    </tr>
-    {{#each projects}}
+  {{#notEmpty projects}}
+    <table class="coding-rules-detail-list coding-rules-most-violated-projects">
       <tr>
-        <td class="coding-rules-detail-list-name">{{name}}</td>
-        <td class="coding-rules-detail-list-parameters">
-          <a href="{{issuesUrl}}" target="_blank">{{count}}</a>
-        </td>
+        <td class="coding-rules-detail-list-name" colspan="2">{{t 'coding_rules.most_violating_projects'}}</td>
       </tr>
-    {{/each}}
-  </table>
-{{/notEmpty}}
+      {{#each projects}}
+        <tr>
+          <td class="coding-rules-detail-list-name">{{name}}</td>
+          <td class="coding-rules-detail-list-parameters">
+            <a href="{{issuesUrl}}" target="_blank">{{count}}</a>
+          </td>
+        </tr>
+      {{/each}}
+    </table>
+  {{/notEmpty}}
+{{/if}}