diff options
author | Stas Vilchik <stas.vilchik@sonarsource.com> | 2017-10-19 16:32:33 +0200 |
---|---|---|
committer | Stas Vilchik <stas.vilchik@sonarsource.com> | 2017-10-20 14:52:01 +0200 |
commit | 97df5136aa8b05ed3e56c47e457a5e53288697e9 (patch) | |
tree | 89243890bbe3cfd5394585b63ca4aa8d62e0e1aa /server/sonar-web/src/main/js/apps/coding-rules | |
parent | 2c1b9cae54f36b9d62a65de6ef631f091bea99b6 (diff) | |
download | sonarqube-97df5136aa8b05ed3e56c47e457a5e53288697e9.tar.gz sonarqube-97df5136aa8b05ed3e56c47e457a5e53288697e9.zip |
stop using jquery for ajax calls
Diffstat (limited to 'server/sonar-web/src/main/js/apps/coding-rules')
5 files changed, 81 insertions, 95 deletions
diff --git a/server/sonar-web/src/main/js/apps/coding-rules/bulk-change-modal-view.js b/server/sonar-web/src/main/js/apps/coding-rules/bulk-change-modal-view.js index 953c9c7900e..31de119d09f 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/bulk-change-modal-view.js +++ b/server/sonar-web/src/main/js/apps/coding-rules/bulk-change-modal-view.js @@ -17,10 +17,10 @@ * 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() { diff --git a/server/sonar-web/src/main/js/apps/coding-rules/controller.js b/server/sonar-web/src/main/js/apps/coding-rules/controller.js index a291f9530df..ec53f42cadf 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/controller.js +++ b/server/sonar-web/src/main/js/apps/coding-rules/controller.js @@ -17,12 +17,11 @@ * 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() { diff --git a/server/sonar-web/src/main/js/apps/coding-rules/rule-details-view.js b/server/sonar-web/src/main/js/apps/coding-rules/rule-details-view.js index 722e3f22d3e..4053b2dd0a2 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/rule-details-view.js +++ b/server/sonar-web/src/main/js/apps/coding-rules/rule-details-view.js @@ -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() { diff --git a/server/sonar-web/src/main/js/apps/coding-rules/rule/delete-rule-view.js b/server/sonar-web/src/main/js/apps/coding-rules/rule/delete-rule-view.js index ba33cd5a0a5..1d5af98fb88 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/rule/delete-rule-view.js +++ b/server/sonar-web/src/main/js/apps/coding-rules/rule/delete-rule-view.js @@ -17,21 +17,21 @@ * 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'); + }, + () => {} + ); } }); diff --git a/server/sonar-web/src/main/js/apps/coding-rules/rule/rule-meta-view.js b/server/sonar-web/src/main/js/apps/coding-rules/rule/rule-meta-view.js index 68c9748e386..15d18464f5c 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/rule/rule-meta-view.js +++ b/server/sonar-web/src/main/js/apps/coding-rules/rule/rule-meta-view.js @@ -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() { |