]> source.dussan.org Git - sonarqube.git/commitdiff
stop using jquery for ajax calls
authorStas Vilchik <stas.vilchik@sonarsource.com>
Thu, 19 Oct 2017 14:32:33 +0000 (16:32 +0200)
committerStas Vilchik <stas.vilchik@sonarsource.com>
Fri, 20 Oct 2017 12:52:01 +0000 (14:52 +0200)
17 files changed:
server/sonar-web/src/main/js/api/metrics.ts
server/sonar-web/src/main/js/api/rules.ts
server/sonar-web/src/main/js/api/tests.ts [new file with mode: 0644]
server/sonar-web/src/main/js/apps/coding-rules/bulk-change-modal-view.js
server/sonar-web/src/main/js/apps/coding-rules/controller.js
server/sonar-web/src/main/js/apps/coding-rules/rule-details-view.js
server/sonar-web/src/main/js/apps/coding-rules/rule/delete-rule-view.js
server/sonar-web/src/main/js/apps/coding-rules/rule/rule-meta-view.js
server/sonar-web/src/main/js/apps/metrics/init.js
server/sonar-web/src/main/js/apps/overview/meta/MetaQualityProfiles.js
server/sonar-web/src/main/js/apps/quality-profiles/details/ProfileRules.tsx
server/sonar-web/src/main/js/apps/quality-profiles/home/EvolutionRules.tsx
server/sonar-web/src/main/js/components/SourceViewer/views/measures-overlay.js
server/sonar-web/src/main/js/components/controls/SearchSelect.js
server/sonar-web/src/main/js/components/navigator/controller.js
server/sonar-web/src/main/js/components/navigator/workspace-list-view.js
server/sonar-web/src/main/js/components/workspace/main.js

index 985a82064035a975db4982573eeba763ec39bc67..0cdc333aef0dfdc99076adae0b9cda0dccbd71da 100644 (file)
  */
 import { getJSON } from '../helpers/request';
 import { Metric } from '../app/types';
+import throwGlobalError from '../app/utils/throwGlobalError';
 
 export function getMetrics(): Promise<Metric[]> {
   return getJSON('/api/metrics/search', { ps: 9999 }).then(r => r.metrics);
 }
+
+export function getMetricDomains(): Promise<string[]> {
+  return getJSON('/api/metrics/domains').then(r => r.domains, throwGlobalError);
+}
+
+export function getMetricTypes(): Promise<string[]> {
+  return getJSON('/api/metrics/types').then(r => r.types, throwGlobalError);
+}
index ded000324d1f7bcf7e760c2fc9ae42b7004a2386..f7b1c0bdab0713d364991ae70c1a595ca363f5bd 100644 (file)
@@ -17,7 +17,7 @@
  * along with this program; if not, write to the Free Software Foundation,
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
-import { getJSON, RequestData } from '../helpers/request';
+import { post, getJSON, RequestData } from '../helpers/request';
 import throwGlobalError from '../app/utils/throwGlobalError';
 
 export interface GetRulesAppResponse {
@@ -29,10 +29,28 @@ export function getRulesApp(): Promise<GetRulesAppResponse> {
 }
 
 export function searchRules(data: RequestData) {
-  return getJSON('/api/rules/search', data);
+  return getJSON('/api/rules/search', data).catch(throwGlobalError);
 }
 
 export function takeFacet(response: any, property: string) {
   const facet = response.facets.find((facet: any) => facet.property === property);
   return facet ? facet.values : [];
 }
+
+export interface GetRuleDetailsParameters {
+  actives?: boolean;
+  key: string;
+  organization?: string;
+}
+
+export function getRuleDetails({ key }: GetRuleDetailsParameters): Promise<any> {
+  return getJSON('/api/rules/show', { key }).catch(throwGlobalError);
+}
+
+export function getRuleTags(parameters: { organization?: string }): Promise<string[]> {
+  return getJSON('/api/rules/tags', parameters).then(r => r.tags, throwGlobalError);
+}
+
+export function deleteRule({ key }: { key: string }) {
+  return post('/api/rules/delete', { key }).catch(throwGlobalError);
+}
diff --git a/server/sonar-web/src/main/js/api/tests.ts b/server/sonar-web/src/main/js/api/tests.ts
new file mode 100644 (file)
index 0000000..132f4d4
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+* SonarQube
+* Copyright (C) 2009-2016 SonarSource SA
+* mailto:contact AT sonarsource DOT com
+*
+* This program is free software; you can redistribute it and/or
+* modify it under the terms of the GNU Lesser General Public
+* License as published by the Free Software Foundation; either
+* version 3 of the License, or (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public License
+* along with this program; if not, write to the Free Software Foundation,
+* Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+*/
+import throwGlobalError from '../app/utils/throwGlobalError';
+import { getJSON } from '../helpers/request';
+
+export interface GetTestsParameters {
+  branch?: string;
+  testFileKey: string;
+}
+
+export function getTests(parameters: GetTestsParameters) {
+  return getJSON('/api/tests/list', parameters).catch(throwGlobalError);
+}
+
+export interface GetCoveredFilesParameters {
+  testId: string;
+}
+
+export function getCoveredFiles(parameters: GetCoveredFilesParameters) {
+  return getJSON('/api/tests/covered_files', parameters).catch(throwGlobalError);
+}
index 953c9c7900e0ec56e1d781a00eee4fdc01abc337..31de119d09f586b30b6c1a9bc190c0e4f2c2463b 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 ModalFormView from '../../components/common/modal-form';
 import Template from './templates/coding-rules-bulk-change-modal.hbs';
 import { translateWithParameters } from '../../helpers/l10n';
+import { postJSON } from '../../helpers/request';
 
 export default ModalFormView.extend({
   template: Template,
@@ -75,12 +75,12 @@ export default ModalFormView.extend({
 
   sendRequests(url, options, profiles) {
     const that = this;
-    let looper = $.Deferred().resolve();
+    let looper = Promise.resolve();
     this.disableForm();
     profiles.forEach(profile => {
       const opts = { ...options, profile_key: profile };
-      looper = looper.then(() => {
-        return $.post(url, opts).done(r => {
+      looper = looper.then(() =>
+        postJSON(url, opts).then(r => {
           if (!that.isDestroyed) {
             if (r.failed) {
               that.showWarnMessage(profile, r.succeeded, r.failed);
@@ -88,18 +88,21 @@ export default ModalFormView.extend({
               that.showSuccessMessage(profile, r.succeeded);
             }
           }
-        });
-      });
-    });
-    looper.done(() => {
-      that.options.app.controller.fetchList();
-      if (!that.isDestroyed) {
-        that.$(that.ui.codingRulesSubmitBulkChange.selector).hide();
-        that.enableForm();
-        that.$('.modal-field').hide();
-        that.$('.js-modal-close').focus();
-      }
+        })
+      );
     });
+    looper.then(
+      () => {
+        that.options.app.controller.fetchList();
+        if (!that.isDestroyed) {
+          that.$(that.ui.codingRulesSubmitBulkChange.selector).hide();
+          that.enableForm();
+          that.$('.modal-field').hide();
+          that.$('.js-modal-close').focus();
+        }
+      },
+      () => {}
+    );
   },
 
   getAvailableQualityProfiles() {
index a291f9530df236ceeea7d44884f72ff1d910d510..ec53f42cadfc7950f486bdb6f6a497b4d317bd4e 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 key from 'keymaster';
 import Controller from '../../components/navigator/controller';
 import Rule from './models/rule';
 import RuleDetailsView from './rule-details-view';
-import throwGlobalError from '../../app/utils/throwGlobalError';
+import { searchRules, getRuleDetails } from '../../api/rules';
 
 export default Controller.extend({
   pageSize: 200,
@@ -67,36 +66,34 @@ export default Controller.extend({
 
     this.hideDetails(firstPage);
 
-    const that = this;
-    const url = window.baseUrl + '/api/rules/search';
     const options = { ...this._searchParameters(), ...this.app.state.get('query') };
-    return $.get(url, options)
-      .done(r => {
-        const rules = that.app.list.parseRules(r);
+    return searchRules(options).then(
+      r => {
+        const rules = this.app.list.parseRules(r);
         if (firstPage) {
-          that.app.list.reset(rules);
+          this.app.list.reset(rules);
         } else {
-          that.app.list.add(rules);
+          this.app.list.add(rules);
         }
-        that.app.list.setIndex();
-        that.app.list.addExtraAttributes(that.app.repositories);
-        that.app.facets.reset(that._allFacets());
-        that.app.facets.add(r.facets, { merge: true });
-        that.enableFacets(that._enabledFacets());
-        that.app.state.set({
+        this.app.list.setIndex();
+        this.app.list.addExtraAttributes(this.app.repositories);
+        this.app.facets.reset(this._allFacets());
+        this.app.facets.add(r.facets, { merge: true });
+        this.enableFacets(this._enabledFacets());
+        this.app.state.set({
           page: r.p,
           pageSize: r.ps,
           total: r.total,
           maxResultsReached: r.p * r.ps >= r.total
         });
-        if (firstPage && that.isRulePermalink()) {
-          that.showDetails(that.app.list.first());
+        if (firstPage && this.isRulePermalink()) {
+          this.showDetails(this.app.list.first());
         }
-      })
-      .fail(error => {
+      },
+      () => {
         this.app.state.set({ maxResultsReached: true });
-        throwGlobalError(error);
-      });
+      }
+    );
   },
 
   isRulePermalink() {
@@ -105,10 +102,9 @@ export default Controller.extend({
   },
 
   requestFacet(id) {
-    const url = window.baseUrl + '/api/rules/search';
     const facet = this.app.facets.get(id);
     const options = { facets: id, ps: 1, ...this.app.state.get('query') };
-    return $.get(url, options).done(r => {
+    return searchRules(options).then(r => {
       const facetData = r.facets.find(facet => facet.property === id);
       if (facetData) {
         facet.set(facetData);
@@ -124,18 +120,11 @@ export default Controller.extend({
   },
 
   getRuleDetails(rule) {
-    const that = this;
-    const url = window.baseUrl + '/api/rules/show';
-    const options = {
-      key: rule.id,
-      actives: true
-    };
-    if (this.app.organization) {
-      options.organization = this.app.organization;
-    }
-    return $.get(url, options).done(data => {
-      rule.set(data.rule);
-      rule.addExtraAttributes(that.app.repositories);
+    const parameters = { key: rule.id, actives: true, organization: this.app.organization };
+    return getRuleDetails(parameters).then(r => {
+      rule.set(r.rule);
+      rule.addExtraAttributes(this.app.repositories);
+      return r;
     });
   },
 
@@ -143,18 +132,21 @@ export default Controller.extend({
     const that = this;
     const ruleModel = typeof rule === 'string' ? new Rule({ key: rule }) : rule;
     this.app.layout.workspaceDetailsRegion.reset();
-    this.getRuleDetails(ruleModel).done(data => {
-      key.setScope('details');
-      that.app.workspaceListView.unbindScrollEvents();
-      that.app.state.set({ rule: ruleModel });
-      that.app.workspaceDetailsView = new RuleDetailsView({
-        app: that.app,
-        model: ruleModel,
-        actives: data.actives
-      });
-      that.app.layout.showDetails();
-      that.app.layout.workspaceDetailsRegion.show(that.app.workspaceDetailsView);
-    });
+    this.getRuleDetails(ruleModel).then(
+      r => {
+        key.setScope('details');
+        that.app.workspaceListView.unbindScrollEvents();
+        that.app.state.set({ rule: ruleModel });
+        that.app.workspaceDetailsView = new RuleDetailsView({
+          app: that.app,
+          model: ruleModel,
+          actives: r.actives
+        });
+        that.app.layout.showDetails();
+        that.app.layout.workspaceDetailsRegion.show(that.app.workspaceDetailsView);
+      },
+      () => {}
+    );
   },
 
   showDetailsForSelected() {
index 722e3f22d3ec31f35e3627e77ca2bcf8b67adc6f..4053b2dd0a2b34583cb714ef09e631def25019b4 100644 (file)
@@ -17,7 +17,6 @@
  * 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 { union } from 'lodash';
 import Backbone from 'backbone';
 import Marionette from 'backbone.marionette';
@@ -32,6 +31,7 @@ import CustomRuleCreationView from './rule/custom-rule-creation-view';
 import DeleteRuleView from './rule/delete-rule-view';
 import IssuesView from './rule/rule-issues-view';
 import Template from './templates/coding-rules-rule-details.hbs';
+import { searchRules } from '../../api/rules';
 
 export default Marionette.LayoutView.extend({
   className: 'coding-rule-details',
@@ -107,15 +107,11 @@ export default Marionette.LayoutView.extend({
   },
 
   fetchCustomRules() {
-    const that = this;
-    const url = window.baseUrl + '/api/rules/search';
     const options = {
       template_key: this.model.get('key'),
       f: 'name,severity,params'
     };
-    return $.get(url, options).done(data => {
-      that.customRules.reset(data.rules);
-    });
+    searchRules(options).then(r => this.customRules.reset(r.rules), () => {});
   },
 
   getQualityProfiles() {
index ba33cd5a0a5e938dc38bddbf39d802db24876a72..1d5af98fb885fb68b5c1245d3e52a8f9d58c9a9f 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 ModalFormView from '../../../components/common/modal-form';
 import Template from '../templates/rule/coding-rules-delete-rule.hbs';
+import { deleteRule } from '../../../api/rules';
 
 export default ModalFormView.extend({
   template: Template,
 
   onFormSubmit() {
     ModalFormView.prototype.onFormSubmit.apply(this, arguments);
-
-    const url = window.baseUrl + '/api/rules/delete';
-    const options = { key: this.model.id };
-    $.post(url, options).done(() => {
-      this.destroy();
-      this.trigger('delete');
-    });
+    deleteRule({ key: this.model.id }).then(
+      () => {
+        this.destroy();
+        this.trigger('delete');
+      },
+      () => {}
+    );
   }
 });
index 68c9748e386f9744864419503f8fdcbdac2c95e6..15d18464f5c777ba57ebc739d8e6e3c130d2cc39 100644 (file)
@@ -22,6 +22,7 @@ import { difference, union } from 'lodash';
 import Marionette from 'backbone.marionette';
 import RuleFilterMixin from './rule-filter-mixin';
 import Template from '../templates/rule/coding-rules-rule-meta.hbs';
+import { getRuleTags } from '../../../api/rules';
 
 export default Marionette.ItemView.extend(RuleFilterMixin).extend({
   template: Template,
@@ -56,27 +57,21 @@ export default Marionette.ItemView.extend(RuleFilterMixin).extend({
     this.$('[data-toggle="tooltip"]').tooltip('destroy');
   },
 
-  requestTags() {
-    const url = window.baseUrl + '/api/rules/tags';
-    const data = this.options.app.organization
-      ? { organization: this.options.app.organization }
-      : undefined;
-    return $.get(url, data);
-  },
-
   changeTags() {
-    const that = this;
-    this.requestTags().done(r => {
-      that.ui.tagInput.select2({
-        tags: difference(difference(r.tags, that.model.get('tags')), that.model.get('sysTags')),
-        width: '300px'
-      });
+    getRuleTags({ organization: this.options.app.organization }).then(
+      tags => {
+        this.ui.tagInput.select2({
+          tags: difference(difference(tags, this.model.get('tags')), this.model.get('sysTags')),
+          width: '300px'
+        });
 
-      that.ui.tagsEdit.removeClass('hidden');
-      that.ui.tagsList.addClass('hidden');
-      that.tagsBuffer = that.ui.tagInput.select2('val');
-      that.ui.tagInput.select2('open');
-    });
+        this.ui.tagsEdit.removeClass('hidden');
+        this.ui.tagsList.addClass('hidden');
+        this.tagsBuffer = this.ui.tagInput.select2('val');
+        this.ui.tagInput.select2('open');
+      },
+      () => {}
+    );
   },
 
   cancelEdit() {
index 5f4560cef9f7c290a8fe615fe90ec6470f3df81f..34711becb8dbc9ffef7e47605a1c59118617d25d 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 Layout from './layout';
 import Metrics from './metrics';
 import HeaderView from './header-view';
 import ListView from './list-view';
 import ListFooterView from './list-footer-view';
+import { getMetricDomains, getMetricTypes } from '../../api/metrics';
 
 const App = new Marionette.Application();
 const init = function(el) {
@@ -59,21 +59,15 @@ const init = function(el) {
   this.metrics.fetch();
 };
 
-App.requestDomains = function() {
-  return $.get(window.baseUrl + '/api/metrics/domains').done(r => {
-    App.domains = r.domains;
-  });
-};
-App.requestTypes = function() {
-  return $.get(window.baseUrl + '/api/metrics/types').done(r => {
-    App.types = r.types;
-  });
-};
-
 App.on('start', el => {
-  $.when(App.requestDomains(), App.requestTypes()).done(() => {
-    init.call(App, el);
-  });
+  Promise.all([getMetricDomains(), getMetricTypes()]).then(
+    ([domains, types]) => {
+      App.domains = domains;
+      App.types = types;
+      init.call(App, el);
+    },
+    () => {}
+  );
 });
 
 export default function(el) {
index 99554d9e207d2e9d176f0b078fce9b65115195cf..123e04229656ad5561e8cbd21187d4c1974af2de 100644 (file)
@@ -55,16 +55,19 @@ class MetaQualityProfiles extends React.PureComponent {
     const requests = this.props.profiles.map(profile =>
       this.loadDeprecatedRulesForProfile(profile.key)
     );
-    Promise.all(requests).then(responses => {
-      if (this.mounted) {
-        const deprecatedByKey = {};
-        responses.forEach((count, i) => {
-          const profileKey = this.props.profiles[i].key;
-          deprecatedByKey[profileKey] = count;
-        });
-        this.setState({ deprecatedByKey });
-      }
-    });
+    Promise.all(requests).then(
+      responses => {
+        if (this.mounted) {
+          const deprecatedByKey = {};
+          responses.forEach((count, i) => {
+            const profileKey = this.props.profiles[i].key;
+            deprecatedByKey[profileKey] = count;
+          });
+          this.setState({ deprecatedByKey });
+        }
+      },
+      () => {}
+    );
   }
 
   loadDeprecatedRulesForProfile(profileKey) {
index a036a636f62d6fb8257e7315d6e396acc6d261a8..b2ab673292117a8ce3663c55702ad1f202cf022b 100644 (file)
@@ -107,23 +107,26 @@ export default class ProfileRules extends React.PureComponent<Props, State> {
 
   loadRules() {
     this.setState({ loading: true });
-    Promise.all([
-      this.loadAllRules(),
-      this.loadActivatedRules(),
-      this.loadProfile()
-    ]).then(responses => {
-      if (this.mounted) {
-        const [allRules, activatedRules, showProfile] = responses;
-        this.setState({
-          activatedTotal: activatedRules.total,
-          allByType: keyBy<ByType>(takeFacet(allRules, 'types'), 'val'),
-          activatedByType: keyBy<ByType>(takeFacet(activatedRules, 'types'), 'val'),
-          compareToSonarWay: showProfile && showProfile.compareToSonarWay,
-          loading: false,
-          total: allRules.total
-        });
+    Promise.all([this.loadAllRules(), this.loadActivatedRules(), this.loadProfile()]).then(
+      responses => {
+        if (this.mounted) {
+          const [allRules, activatedRules, showProfile] = responses;
+          this.setState({
+            activatedTotal: activatedRules.total,
+            allByType: keyBy<ByType>(takeFacet(allRules, 'types'), 'val'),
+            activatedByType: keyBy<ByType>(takeFacet(activatedRules, 'types'), 'val'),
+            compareToSonarWay: showProfile && showProfile.compareToSonarWay,
+            loading: false,
+            total: allRules.total
+          });
+        }
+      },
+      () => {
+        if (this.mounted) {
+          this.setState({ loading: false });
+        }
       }
-    });
+    );
   }
 
   getRulesCountForType(type: string) {
index 03a9aed243ecc7059ba5fb17cfc844dfde482b9e..9ff9410a37c024e77e53f4f9534b92fd40bef899 100644 (file)
@@ -82,14 +82,17 @@ export default class EvolutionRules extends React.PureComponent<Props, State> {
       f: 'name,langName,actives'
     };
 
-    searchRules(data).then((r: any) => {
-      if (this.mounted) {
-        this.setState({
-          latestRules: sortBy<Rule>(parseRules(r), 'langName'),
-          latestRulesTotal: r.total
-        });
-      }
-    });
+    searchRules(data).then(
+      (r: any) => {
+        if (this.mounted) {
+          this.setState({
+            latestRules: sortBy<Rule>(parseRules(r), 'langName'),
+            latestRulesTotal: r.total
+          });
+        }
+      },
+      () => {}
+    );
   }
 
   render() {
index e30f3d8fcd1057de96e5656a61ae32163553e6ef..2acefd6cce61c5b86e472610278383357e2275a3 100644 (file)
@@ -23,8 +23,10 @@ import { arc as d3Arc, pie as d3Pie } from 'd3-shape';
 import { groupBy, sortBy, toPairs } from 'lodash';
 import ModalView from '../../common/modals';
 import Template from './templates/source-viewer-measures.hbs';
+import { searchIssues } from '../../../api/issues';
 import { getMeasures } from '../../../api/measures';
 import { getMetrics } from '../../../api/metrics';
+import { getTests, getCoveredFiles } from '../../../api/tests';
 import { getLocalizedMetricName, getLocalizedMetricDomain } from '../../../helpers/l10n';
 import { formatMeasure } from '../../../helpers/measures';
 
@@ -174,17 +176,16 @@ export default ModalView.extend({
   },
 
   requestIssues() {
-    return new Promise(resolve => {
-      const url = window.baseUrl + '/api/issues/search';
-      const options = {
-        branch: this.options.branch,
-        componentKeys: this.options.component.key,
-        resolved: false,
-        ps: 1,
-        facets: 'types,severities,tags'
-      };
+    const options = {
+      branch: this.options.branch,
+      componentKeys: this.options.component.key,
+      resolved: false,
+      ps: 1,
+      facets: 'types,severities,tags'
+    };
 
-      $.get(url, options).done(data => {
+    return searchIssues(options).then(
+      data => {
         const typesFacet = data.facets.find(facet => facet.property === 'types').values;
         const typesOrder = ['BUG', 'VULNERABILITY', 'CODE_SMELL'];
         const sortedTypesFacet = sortBy(typesFacet, v => typesOrder.indexOf(v.val));
@@ -200,25 +201,21 @@ export default ModalView.extend({
         this.typesFacet = sortedTypesFacet;
         this.severitiesFacet = sortedSeveritiesFacet;
         this.issuesCount = data.total;
-
-        resolve();
-      });
-    });
+      },
+      () => {}
+    );
   },
 
   requestTests() {
-    return new Promise(resolve => {
-      const url = window.baseUrl + '/api/tests/list';
-      const options = { branch: this.options.branch, testFileKey: this.options.component.key };
-
-      $.get(url, options).done(data => {
+    return getTests({ branch: this.options.branch, testFileKey: this.options.component.key }).then(
+      data => {
         this.tests = data.tests;
         this.testSorting = 'status';
         this.testAsc = true;
         this.sortTests(test => `${this.testsOrder.indexOf(test.status)}_______${test.name}`);
-        resolve();
-      });
-    });
+      },
+      () => {}
+    );
   },
 
   sortTests(condition) {
@@ -261,16 +258,17 @@ export default ModalView.extend({
 
   showTest(e) {
     const testId = $(e.currentTarget).data('id');
-    const url = window.baseUrl + '/api/tests/covered_files';
-    const options = { testId };
     this.testsScroll = $(e.currentTarget)
       .scrollParent()
       .scrollTop();
-    return $.get(url, options).done(data => {
-      this.coveredFiles = data.files;
-      this.selectedTest = this.tests.find(test => test.id === testId);
-      this.render();
-    });
+    getCoveredFiles({ testId }).then(
+      data => {
+        this.coveredFiles = data.files;
+        this.selectedTest = this.tests.find(test => test.id === testId);
+        this.render();
+      },
+      () => {}
+    );
   },
 
   showAllMeasures() {
index 84eb5253b9b8a8daa78d0df5413f26544b9b7ded..39ca6539c59159f9de7331bd09fcba62e99aeac9 100644 (file)
@@ -73,11 +73,18 @@ export default class SearchSelect extends React.PureComponent {
   }
 
   search = (query /*: string */) => {
-    this.props.onSearch(query).then(options => {
-      if (this.mounted) {
-        this.setState({ loading: false, options });
+    this.props.onSearch(query).then(
+      options => {
+        if (this.mounted) {
+          this.setState({ loading: false, options });
+        }
+      },
+      () => {
+        if (this.mounted) {
+          this.setState({ loading: false });
+        }
       }
-    });
+    );
   };
 
   handleBlur = () => {
index 9f60ff97d9b05c0130d111278f63b83f54c465c9..65dd3e77ab0edf4ae50e1819381ee172d0046d28 100644 (file)
@@ -68,7 +68,7 @@ export default Marionette.Controller.extend({
     if (facet.has('values') || this.options.app.state.get('facetsFromServer').indexOf(id) === -1) {
       facet.set({ enabled: true });
     } else {
-      this.requestFacet(id).done(() => {
+      this.requestFacet(id).then(() => {
         facet.set({ enabled: true });
       });
     }
@@ -130,7 +130,7 @@ export default Marionette.Controller.extend({
       this.options.app.state.set({ selectedIndex: index });
     } else if (!this.options.app.state.get('maxResultsReached')) {
       const that = this;
-      this.fetchNextPage().done(() => {
+      this.fetchNextPage().then(() => {
         that.options.app.state.set({ selectedIndex: index });
       });
     } else {
index 12a087bba97eeb65d3727bff2de4ae7759e2fe79..32520cee27a41d8d855dde4f8355bfb2c628c914 100644 (file)
@@ -95,7 +95,7 @@ export default Marionette.CompositeView.extend({
     if (!this.options.app.state.get('maxResultsReached')) {
       const that = this;
       this.unbindScrollEvents();
-      this.options.app.controller.fetchNextPage().done(() => {
+      this.options.app.controller.fetchNextPage().then(() => {
         that.bindScrollEvents();
       });
     }
index cfc93f499b5d5fc9937bfa4e5ec65d3d7cbbaac2..b9b589c478f5e1056b302e3363c6fc32cc9ee7e5 100644 (file)
@@ -24,6 +24,7 @@ import Items from './models/items';
 import ItemsView from './views/items-view';
 import ViewerView from './views/viewer-view';
 import RuleView from './views/rule-view';
+import { getRuleDetails } from '../../api/rules';
 
 let instance = null;
 const Workspace = function() {
@@ -117,23 +118,16 @@ Workspace.prototype = {
 
   showRule(model) {
     const that = this;
-    this.fetchRule(model)
-      .done(() => {
-        model.set({ exist: true });
+    getRuleDetails({ key: model.get('key') }).then(
+      r => {
+        model.set({ ...r.rule, exist: true });
         that.showViewer(RuleView, model);
-      })
-      .fail(() => {
+      },
+      () => {
         model.set({ exist: false });
         that.showViewer(RuleView, model);
-      });
-  },
-
-  fetchRule(model) {
-    const url = window.baseUrl + '/api/rules/show';
-    const options = { key: model.get('key') };
-    return $.get(url, options).done(r => {
-      model.set(r.rule);
-    });
+      }
+    );
   }
 };