diff options
author | Stas Vilchik <vilchiks@gmail.com> | 2015-09-17 16:15:28 +0200 |
---|---|---|
committer | Stas Vilchik <vilchiks@gmail.com> | 2015-09-18 10:47:27 +0200 |
commit | 890ab0b59cdb3902f4869eabf8ca534814f1b3dd (patch) | |
tree | 0ed74726957e590f6506e378366ea15bf21bfcbd /server/sonar-web/src/main/js/apps/quality-profiles | |
parent | ce60ac8d2e137f33bb111668e54e78c195c73d79 (diff) | |
download | sonarqube-890ab0b59cdb3902f4869eabf8ca534814f1b3dd.tar.gz sonarqube-890ab0b59cdb3902f4869eabf8ca534814f1b3dd.zip |
migrate js apps to es2015 modules
Diffstat (limited to 'server/sonar-web/src/main/js/apps/quality-profiles')
23 files changed, 1160 insertions, 1190 deletions
diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/actions-view.js b/server/sonar-web/src/main/js/apps/quality-profiles/actions-view.js index efed98e7d35..a2fe43cbe18 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/actions-view.js +++ b/server/sonar-web/src/main/js/apps/quality-profiles/actions-view.js @@ -1,97 +1,96 @@ -define([ - './create-profile-view', - './restore-profile-view', - './restore-built-in-profiles-view', - './templates' -], function (CreateProfileView, RestoreProfileView, RestoreBuiltInProfilesView) { - - var $ = jQuery; - - return Marionette.ItemView.extend({ - template: Templates['quality-profiles-actions'], - - events: { - 'click #quality-profiles-create': 'onCreateClick', - 'click #quality-profiles-restore': 'onRestoreClick', - 'click #quality-profiles-restore-built-in': 'onRestoreBuiltInClick', - - 'click .js-filter-by-language': 'onLanguageClick' - }, - - onCreateClick: function (e) { - e.preventDefault(); - this.create(); - }, - - onRestoreClick: function (e) { - e.preventDefault(); - this.restore(); - }, - - onRestoreBuiltInClick: function (e) { - e.preventDefault(); - this.restoreBuiltIn(); - }, - - onLanguageClick: function (e) { - e.preventDefault(); - var language = $(e.currentTarget).data('language'); - this.filterByLanguage(language); - }, - - create: function () { - var that = this; - this.requestImporters().done(function () { - new CreateProfileView({ - collection: that.collection, - languages: that.languages, - importers: that.importers - }).render(); - }); - }, - - restore: function () { - new RestoreProfileView({ - collection: this.collection +import $ from 'jquery'; +import _ from 'underscore'; +import Marionette from 'backbone.marionette'; +import CreateProfileView from './create-profile-view'; +import RestoreProfileView from './restore-profile-view'; +import RestoreBuiltInProfilesView from './restore-built-in-profiles-view'; +import './templates'; + +export default Marionette.ItemView.extend({ + template: Templates['quality-profiles-actions'], + + events: { + 'click #quality-profiles-create': 'onCreateClick', + 'click #quality-profiles-restore': 'onRestoreClick', + 'click #quality-profiles-restore-built-in': 'onRestoreBuiltInClick', + + 'click .js-filter-by-language': 'onLanguageClick' + }, + + onCreateClick: function (e) { + e.preventDefault(); + this.create(); + }, + + onRestoreClick: function (e) { + e.preventDefault(); + this.restore(); + }, + + onRestoreBuiltInClick: function (e) { + e.preventDefault(); + this.restoreBuiltIn(); + }, + + onLanguageClick: function (e) { + e.preventDefault(); + var language = $(e.currentTarget).data('language'); + this.filterByLanguage(language); + }, + + create: function () { + var that = this; + this.requestImporters().done(function () { + new CreateProfileView({ + collection: that.collection, + languages: that.languages, + importers: that.importers }).render(); - }, + }); + }, + + restore: function () { + new RestoreProfileView({ + collection: this.collection + }).render(); + }, + + restoreBuiltIn: function () { + new RestoreBuiltInProfilesView({ + collection: this.collection, + languages: this.languages + }).render(); + }, + + requestLanguages: function () { + var that = this, + url = baseUrl + '/api/languages/list'; + return $.get(url).done(function (r) { + that.languages = r.languages; + }); + }, + + requestImporters: function () { + var that = this, + url = baseUrl + '/api/qualityprofiles/importers'; + return $.get(url).done(function (r) { + that.importers = r.importers; + }); + }, + + filterByLanguage: function (language) { + this.selectedLanguage = _.findWhere(this.languages, { key: language }); + this.render(); + this.collection.trigger('filter', language); + }, + + serializeData: function () { + return _.extend(Marionette.ItemView.prototype.serializeData.apply(this, arguments), { + canWrite: this.options.canWrite, + languages: this.languages, + selectedLanguage: this.selectedLanguage + }); + } +}); - restoreBuiltIn: function () { - new RestoreBuiltInProfilesView({ - collection: this.collection, - languages: this.languages - }).render(); - }, - - requestLanguages: function () { - var that = this, - url = baseUrl + '/api/languages/list'; - return $.get(url).done(function (r) { - that.languages = r.languages; - }); - }, - - requestImporters: function () { - var that = this, - url = baseUrl + '/api/qualityprofiles/importers'; - return $.get(url).done(function (r) { - that.importers = r.importers; - }); - }, - - filterByLanguage: function (language) { - this.selectedLanguage = _.findWhere(this.languages, { key: language }); - this.render(); - this.collection.trigger('filter', language); - }, - - serializeData: function () { - return _.extend(Marionette.ItemView.prototype.serializeData.apply(this, arguments), { - canWrite: this.options.canWrite, - languages: this.languages, - selectedLanguage: this.selectedLanguage - }); - } - }); -}); diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/app.js b/server/sonar-web/src/main/js/apps/quality-profiles/app.js index cd94804cb03..1a81ee6598b 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/app.js +++ b/server/sonar-web/src/main/js/apps/quality-profiles/app.js @@ -1,62 +1,62 @@ -define([ - './router', - './controller', - './layout', - './profiles', - './actions-view', - './profiles-view' -], function (Router, Controller, Layout, Profiles, ActionsView, ProfilesView) { - - var $ = jQuery, - App = new Marionette.Application(), - requestUser = $.get(baseUrl + '/api/users/current').done(function (r) { - App.canWrite = r.permissions.global.indexOf('profileadmin') !== -1; - }), - requestExporters = $.get(baseUrl + '/api/qualityprofiles/exporters').done(function (r) { - App.exporters = r.exporters; - }), - init = function (options) { - // Layout - this.layout = new Layout({ el: options.el }); - this.layout.render(); - $('#footer').addClass('search-navigator-footer'); - - // Profiles List - this.profiles = new Profiles(); - - // Controller - this.controller = new Controller({ app: this }); - - // Actions View - this.actionsView = new ActionsView({ - collection: this.profiles, - canWrite: this.canWrite - }); - this.actionsView.requestLanguages().done(function () { - App.layout.actionsRegion.show(App.actionsView); - }); - - // Profiles View - this.profilesView = new ProfilesView({ - collection: this.profiles, - canWrite: this.canWrite - }); - this.layout.resultsRegion.show(this.profilesView); - - // Router - this.router = new Router({ app: this }); - Backbone.history.start({ - pushState: true, - root: options.urlRoot - }); - }; - - App.on('start', function (options) { - $.when(window.requestMessages(), requestUser, requestExporters).done(function () { - init.call(App, options); - }); +import $ from 'jquery'; +import Backbone from 'backbone'; +import Marionette from 'backbone.marionette'; +import Router from './router'; +import Controller from './controller'; +import Layout from './layout'; +import Profiles from './profiles'; +import ActionsView from './actions-view'; +import ProfilesView from './profiles-view'; + +var App = new Marionette.Application(), + requestUser = $.get(baseUrl + '/api/users/current').done(function (r) { + App.canWrite = r.permissions.global.indexOf('profileadmin') !== -1; + }), + requestExporters = $.get(baseUrl + '/api/qualityprofiles/exporters').done(function (r) { + App.exporters = r.exporters; + }), + init = function (options) { + // Layout + this.layout = new Layout({ el: options.el }); + this.layout.render(); + $('#footer').addClass('search-navigator-footer'); + + // Profiles List + this.profiles = new Profiles(); + + // Controller + this.controller = new Controller({ app: this }); + + // Actions View + this.actionsView = new ActionsView({ + collection: this.profiles, + canWrite: this.canWrite + }); + this.actionsView.requestLanguages().done(function () { + App.layout.actionsRegion.show(App.actionsView); + }); + + // Profiles View + this.profilesView = new ProfilesView({ + collection: this.profiles, + canWrite: this.canWrite + }); + this.layout.resultsRegion.show(this.profilesView); + + // Router + this.router = new Router({ app: this }); + Backbone.history.start({ + pushState: true, + root: options.urlRoot + }); + }; + +App.on('start', function (options) { + $.when(window.requestMessages(), requestUser, requestExporters).done(function () { + init.call(App, options); }); +}); + +export default App; - return App; -}); diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/change-profile-parent-view.js b/server/sonar-web/src/main/js/apps/quality-profiles/change-profile-parent-view.js index a8acc0d5325..a3d5ec6b7ad 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/change-profile-parent-view.js +++ b/server/sonar-web/src/main/js/apps/quality-profiles/change-profile-parent-view.js @@ -1,63 +1,62 @@ -define([ - 'components/common/modal-form', - './templates' -], function (ModalFormView) { +import $ from 'jquery'; +import _ from 'underscore'; +import Marionette from 'backbone.marionette'; +import ModalFormView from 'components/common/modal-form'; +import './templates'; - var $ = jQuery; +export default ModalFormView.extend({ + template: Templates['quality-profiles-change-profile-parent'], - return ModalFormView.extend({ - template: Templates['quality-profiles-change-profile-parent'], + onRender: function () { + ModalFormView.prototype.onRender.apply(this, arguments); + this.$('select').select2({ + width: '250px', + minimumResultsForSearch: 50 + }); + }, - onRender: function () { - ModalFormView.prototype.onRender.apply(this, arguments); - this.$('select').select2({ - width: '250px', - minimumResultsForSearch: 50 - }); - }, + onFormSubmit: function () { + ModalFormView.prototype.onFormSubmit.apply(this, arguments); + this.disableForm(); + this.sendRequest(); + }, - onFormSubmit: function () { - ModalFormView.prototype.onFormSubmit.apply(this, arguments); - this.disableForm(); - this.sendRequest(); - }, + sendRequest: function () { + var that = this, + url = baseUrl + '/api/qualityprofiles/change_parent', + parent = this.$('#change-profile-parent').val(), + options = { + profileKey: this.model.get('key'), + parentKey: parent + }; + return $.ajax({ + type: 'POST', + url: url, + data: options, + statusCode: { + // do not show global error + 400: null + } + }).done(function () { + that.model.collection.fetch(); + that.model.trigger('select', that.model); + that.destroy(); + }).fail(function (jqXHR) { + that.showErrors(jqXHR.responseJSON.errors, jqXHR.responseJSON.warnings); + that.enableForm(); + }); + }, - sendRequest: function () { - var that = this, - url = baseUrl + '/api/qualityprofiles/change_parent', - parent = this.$('#change-profile-parent').val(), - options = { - profileKey: this.model.get('key'), - parentKey: parent - }; - return $.ajax({ - type: 'POST', - url: url, - data: options, - statusCode: { - // do not show global error - 400: null - } - }).done(function () { - that.model.collection.fetch(); - that.model.trigger('select', that.model); - that.destroy(); - }).fail(function (jqXHR) { - that.showErrors(jqXHR.responseJSON.errors, jqXHR.responseJSON.warnings); - that.enableForm(); - }); - }, + serializeData: function () { + var that = this, + profilesData = this.model.collection.toJSON(), + profiles = _.filter(profilesData, function (profile) { + return profile.language === that.model.get('language') && profile.key !== that.model.id; + }); + return _.extend(Marionette.ItemView.prototype.serializeData.apply(this, arguments), { + profiles: profiles + }); + } +}); - serializeData: function () { - var that = this, - profilesData = this.model.collection.toJSON(), - profiles = _.filter(profilesData, function (profile) { - return profile.language === that.model.get('language') && profile.key !== that.model.id; - }); - return _.extend(Marionette.ItemView.prototype.serializeData.apply(this, arguments), { - profiles: profiles - }); - } - }); -}); diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/controller.js b/server/sonar-web/src/main/js/apps/quality-profiles/controller.js index 09fed1ff580..489db7f8b53 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/controller.js +++ b/server/sonar-web/src/main/js/apps/quality-profiles/controller.js @@ -1,111 +1,110 @@ -define([ - './profile-header-view', - './profile-details-view' -], function (ProfileHeaderView, ProfileDetailsView) { - - var $ = jQuery; - - return Marionette.Controller.extend({ - - initialize: function () { - this.listenTo(this.options.app.profiles, 'select', this.onProfileSelect); - this.listenTo(this.options.app.profiles, 'setAsDefault', this.onProfileSetAsDefault); - this.listenTo(this.options.app.profiles, 'destroy', this.onProfileDestroy); - }, - - index: function () { - this.fetchProfiles(); - }, - - show: function (key) { - var that = this; - this.fetchProfiles().done(function () { - var profile = that.options.app.profiles.findWhere({ key: key }); - if (profile != null) { - profile.trigger('select', profile, { trigger: false }); - } - }); - }, - - changelog: function (key, since, to) { - var that = this; - this.anchor = 'changelog'; - this.fetchProfiles().done(function () { - var profile = that.options.app.profiles.findWhere({ key: key }); - if (profile != null) { - profile.trigger('select', profile, { trigger: false }); - profile.fetchChangelog({ since: since, to: to }); - } - }); - }, - - compare: function (key, withKey) { - var that = this; - this.anchor = 'comparison'; - this.fetchProfiles().done(function () { - var profile = that.options.app.profiles.findWhere({ key: key }); - if (profile != null) { - profile.trigger('select', profile, { trigger: false }); - profile.compareWith(withKey); - } - }); - }, - - onProfileSelect: function (profile, options) { - var that = this, - key = profile.get('key'), - route = 'show?key=' + encodeURIComponent(key), - opts = _.defaults(options || {}, { trigger: true }); - if (opts.trigger) { - this.options.app.router.navigate(route); +import $ from 'jquery'; +import _ from 'underscore'; +import Marionette from 'backbone.marionette'; +import ProfileHeaderView from './profile-header-view'; +import ProfileDetailsView from './profile-details-view'; + +export default Marionette.Controller.extend({ + + initialize: function () { + this.listenTo(this.options.app.profiles, 'select', this.onProfileSelect); + this.listenTo(this.options.app.profiles, 'setAsDefault', this.onProfileSetAsDefault); + this.listenTo(this.options.app.profiles, 'destroy', this.onProfileDestroy); + }, + + index: function () { + this.fetchProfiles(); + }, + + show: function (key) { + var that = this; + this.fetchProfiles().done(function () { + var profile = that.options.app.profiles.findWhere({ key: key }); + if (profile != null) { + profile.trigger('select', profile, { trigger: false }); } - this.options.app.profilesView.highlight(key); - this.fetchProfile(profile).done(function () { - var profileHeaderView = new ProfileHeaderView({ - model: profile, - canWrite: that.options.app.canWrite - }); - that.options.app.layout.headerRegion.show(profileHeaderView); - - var profileDetailsView = new ProfileDetailsView({ - model: profile, - canWrite: that.options.app.canWrite, - exporters: that.options.app.exporters, - anchor: that.anchor - }); - that.options.app.layout.detailsRegion.show(profileDetailsView); - - that.anchor = null; - }); - }, - - onProfileSetAsDefault: function (profile) { - var that = this, - url = baseUrl + '/api/qualityprofiles/set_default', - key = profile.get('key'), - options = { profileKey: key }; - return $.post(url, options).done(function () { - profile.set({ isDefault: true }); - that.fetchProfiles(); - }); - }, - - onProfileDestroy: function () { - this.options.app.router.navigate(''); - this.options.app.layout.headerRegion.reset(); - this.options.app.layout.detailsRegion.reset(); - this.options.app.layout.renderIntro(); - this.options.app.profilesView.highlight(null); - }, - - fetchProfiles: function () { - return this.options.app.profiles.fetch({ reset: true }); - }, - - fetchProfile: function (profile) { - return profile.fetch(); + }); + }, + + changelog: function (key, since, to) { + var that = this; + this.anchor = 'changelog'; + this.fetchProfiles().done(function () { + var profile = that.options.app.profiles.findWhere({ key: key }); + if (profile != null) { + profile.trigger('select', profile, { trigger: false }); + profile.fetchChangelog({ since: since, to: to }); + } + }); + }, + + compare: function (key, withKey) { + var that = this; + this.anchor = 'comparison'; + this.fetchProfiles().done(function () { + var profile = that.options.app.profiles.findWhere({ key: key }); + if (profile != null) { + profile.trigger('select', profile, { trigger: false }); + profile.compareWith(withKey); + } + }); + }, + + onProfileSelect: function (profile, options) { + var that = this, + key = profile.get('key'), + route = 'show?key=' + encodeURIComponent(key), + opts = _.defaults(options || {}, { trigger: true }); + if (opts.trigger) { + this.options.app.router.navigate(route); } + this.options.app.profilesView.highlight(key); + this.fetchProfile(profile).done(function () { + var profileHeaderView = new ProfileHeaderView({ + model: profile, + canWrite: that.options.app.canWrite + }); + that.options.app.layout.headerRegion.show(profileHeaderView); - }); + var profileDetailsView = new ProfileDetailsView({ + model: profile, + canWrite: that.options.app.canWrite, + exporters: that.options.app.exporters, + anchor: that.anchor + }); + that.options.app.layout.detailsRegion.show(profileDetailsView); + + that.anchor = null; + }); + }, + + onProfileSetAsDefault: function (profile) { + var that = this, + url = baseUrl + '/api/qualityprofiles/set_default', + key = profile.get('key'), + options = { profileKey: key }; + return $.post(url, options).done(function () { + profile.set({ isDefault: true }); + that.fetchProfiles(); + }); + }, + + onProfileDestroy: function () { + this.options.app.router.navigate(''); + this.options.app.layout.headerRegion.reset(); + this.options.app.layout.detailsRegion.reset(); + this.options.app.layout.renderIntro(); + this.options.app.profilesView.highlight(null); + }, + + fetchProfiles: function () { + return this.options.app.profiles.fetch({ reset: true }); + }, + + fetchProfile: function (profile) { + return profile.fetch(); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/copy-profile-view.js b/server/sonar-web/src/main/js/apps/quality-profiles/copy-profile-view.js index 246d2856bf3..9c7d29d0dbc 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/copy-profile-view.js +++ b/server/sonar-web/src/main/js/apps/quality-profiles/copy-profile-view.js @@ -1,50 +1,47 @@ -define([ - 'components/common/modal-form', - './profile', - './templates' -], function (ModalFormView, Profile) { +import $ from 'jquery'; +import ModalFormView from 'components/common/modal-form'; +import Profile from './profile'; +import './templates'; - var $ = jQuery; +export default ModalFormView.extend({ + template: Templates['quality-profiles-copy-profile'], - return ModalFormView.extend({ - template: Templates['quality-profiles-copy-profile'], + onFormSubmit: function () { + ModalFormView.prototype.onFormSubmit.apply(this, arguments); + this.disableForm(); + this.sendRequest(); + }, - onFormSubmit: function () { - ModalFormView.prototype.onFormSubmit.apply(this, arguments); - this.disableForm(); - this.sendRequest(); - }, + sendRequest: function () { + var that = this, + url = baseUrl + '/api/qualityprofiles/copy', + name = this.$('#copy-profile-name').val(), + options = { + fromKey: this.model.get('key'), + toName: name + }; + return $.ajax({ + type: 'POST', + url: url, + data: options, + statusCode: { + // do not show global error + 400: null + } + }).done(function (r) { + that.addProfile(r); + that.destroy(); + }).fail(function (jqXHR) { + that.enableForm(); + that.showErrors(jqXHR.responseJSON.errors, jqXHR.responseJSON.warnings); + }); + }, - sendRequest: function () { - var that = this, - url = baseUrl + '/api/qualityprofiles/copy', - name = this.$('#copy-profile-name').val(), - options = { - fromKey: this.model.get('key'), - toName: name - }; - return $.ajax({ - type: 'POST', - url: url, - data: options, - statusCode: { - // do not show global error - 400: null - } - }).done(function (r) { - that.addProfile(r); - that.destroy(); - }).fail(function (jqXHR) { - that.enableForm(); - that.showErrors(jqXHR.responseJSON.errors, jqXHR.responseJSON.warnings); - }); - }, + addProfile: function (profileData) { + var profile = new Profile(profileData); + this.model.collection.add([profile]); + profile.trigger('select', profile); + } +}); - addProfile: function (profileData) { - var profile = new Profile(profileData); - this.model.collection.add([profile]); - profile.trigger('select', profile); - } - }); -}); diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/create-profile-view.js b/server/sonar-web/src/main/js/apps/quality-profiles/create-profile-view.js index e120c36d705..a6258bff571 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/create-profile-view.js +++ b/server/sonar-web/src/main/js/apps/quality-profiles/create-profile-view.js @@ -1,87 +1,85 @@ -define([ - 'components/common/modal-form', - 'components/common/file-upload', - './profile', - './templates' -], function (ModalFormView, uploader, Profile) { +import $ from 'jquery'; +import _ from 'underscore'; +import ModalFormView from 'components/common/modal-form'; +import uploader from 'components/common/file-upload'; +import Profile from './profile'; +import './templates'; - var $ = jQuery; +export default ModalFormView.extend({ + template: Templates['quality-profiles-create-profile'], - return ModalFormView.extend({ - template: Templates['quality-profiles-create-profile'], + events: function () { + return _.extend(ModalFormView.prototype.events.apply(this, arguments), { + 'change #create-profile-language': 'onLanguageChange' + }); + }, - events: function () { - return _.extend(ModalFormView.prototype.events.apply(this, arguments), { - 'change #create-profile-language': 'onLanguageChange' - }); - }, - - onFormSubmit: function (e) { - ModalFormView.prototype.onFormSubmit.apply(this, arguments); - this.sendRequest(e); - }, + onFormSubmit: function (e) { + ModalFormView.prototype.onFormSubmit.apply(this, arguments); + this.sendRequest(e); + }, - onRender: function () { - ModalFormView.prototype.onRender.apply(this, arguments); - this.$('select').select2({ - width: '250px', - minimumResultsForSearch: 50 - }); - this.onLanguageChange(); - }, + onRender: function () { + ModalFormView.prototype.onRender.apply(this, arguments); + this.$('select').select2({ + width: '250px', + minimumResultsForSearch: 50 + }); + this.onLanguageChange(); + }, - onLanguageChange: function () { - var that = this; - var language = this.$('#create-profile-language').val(); - var importers = this.getImportersForLanguages(language); - this.$('.js-importer').each(function () { - that.emptyInput($(this)); - $(this).addClass('hidden'); - }); - importers.forEach(function (importer) { - that.$('.js-importer[data-key="' + importer.key + '"]').removeClass('hidden'); - }); - }, + onLanguageChange: function () { + var that = this; + var language = this.$('#create-profile-language').val(); + var importers = this.getImportersForLanguages(language); + this.$('.js-importer').each(function () { + that.emptyInput($(this)); + $(this).addClass('hidden'); + }); + importers.forEach(function (importer) { + that.$('.js-importer[data-key="' + importer.key + '"]').removeClass('hidden'); + }); + }, - emptyInput: function (e) { - e.wrap('<form>').closest('form').get(0).reset(); - e.unwrap(); - }, + emptyInput: function (e) { + e.wrap('<form>').closest('form').get(0).reset(); + e.unwrap(); + }, - sendRequest: function (e) { - var that = this; - uploader({ form: $(e.currentTarget) }).done(function (r) { - if (_.isArray(r.errors) || _.isArray(r.warnings)) { - that.showErrors(r.errors, r.warnings); - } else { - that.addProfile(r.profile); - that.destroy(); - } - }); - }, - - addProfile: function (profileData) { - var profile = new Profile(profileData); - this.collection.add([profile]); - profile.trigger('select', profile); - }, - - getImportersForLanguages: function (language) { - if (language != null) { - return this.options.importers.filter(function (importer) { - return importer.languages.indexOf(language) !== -1; - }); + sendRequest: function (e) { + var that = this; + uploader({ form: $(e.currentTarget) }).done(function (r) { + if (_.isArray(r.errors) || _.isArray(r.warnings)) { + that.showErrors(r.errors, r.warnings); } else { - return []; + that.addProfile(r.profile); + that.destroy(); } - }, + }); + }, + + addProfile: function (profileData) { + var profile = new Profile(profileData); + this.collection.add([profile]); + profile.trigger('select', profile); + }, - serializeData: function () { - return _.extend(ModalFormView.prototype.serializeData.apply(this, arguments), { - languages: this.options.languages, - importers: this.options.importers + getImportersForLanguages: function (language) { + if (language != null) { + return this.options.importers.filter(function (importer) { + return importer.languages.indexOf(language) !== -1; }); + } else { + return []; } - }); + }, + serializeData: function () { + return _.extend(ModalFormView.prototype.serializeData.apply(this, arguments), { + languages: this.options.languages, + importers: this.options.importers + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/delete-profile-view.js b/server/sonar-web/src/main/js/apps/quality-profiles/delete-profile-view.js index 7511506f4fd..ed2ee8ac7da 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/delete-profile-view.js +++ b/server/sonar-web/src/main/js/apps/quality-profiles/delete-profile-view.js @@ -1,43 +1,40 @@ -define([ - 'components/common/modal-form', - './templates' -], function (ModalFormView) { +import $ from 'jquery'; +import ModalFormView from 'components/common/modal-form'; +import './templates'; - var $ = jQuery; +export default ModalFormView.extend({ + template: Templates['quality-profiles-delete-profile'], - return ModalFormView.extend({ - template: Templates['quality-profiles-delete-profile'], + modelEvents: { + 'destroy': 'destroy' + }, - modelEvents: { - 'destroy': 'destroy' - }, + onFormSubmit: function () { + ModalFormView.prototype.onFormSubmit.apply(this, arguments); + this.disableForm(); + this.sendRequest(); + }, - onFormSubmit: function () { - ModalFormView.prototype.onFormSubmit.apply(this, arguments); - this.disableForm(); - this.sendRequest(); - }, + sendRequest: function () { + var that = this, + url = baseUrl + '/api/qualityprofiles/delete', + options = { profileKey: this.model.get('key') }; + return $.ajax({ + type: 'POST', + url: url, + data: options, + statusCode: { + // do not show global error + 400: null + } + }).done(function () { + that.model.collection.fetch(); + that.model.trigger('destroy', that.model, that.model.collection); + }).fail(function (jqXHR) { + that.showErrors(jqXHR.responseJSON.errors, jqXHR.responseJSON.warnings); + that.enableForm(); + }); + } +}); - sendRequest: function () { - var that = this, - url = baseUrl + '/api/qualityprofiles/delete', - options = { profileKey: this.model.get('key') }; - return $.ajax({ - type: 'POST', - url: url, - data: options, - statusCode: { - // do not show global error - 400: null - } - }).done(function () { - that.model.collection.fetch(); - that.model.trigger('destroy', that.model, that.model.collection); - }).fail(function (jqXHR) { - that.showErrors(jqXHR.responseJSON.errors, jqXHR.responseJSON.warnings); - that.enableForm(); - }); - } - }); -}); diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/helpers.js b/server/sonar-web/src/main/js/apps/quality-profiles/helpers.js index f511e5b6383..efb8e83253d 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/helpers.js +++ b/server/sonar-web/src/main/js/apps/quality-profiles/helpers.js @@ -1,31 +1,27 @@ -(function () { +Handlebars.registerHelper('profileUrl', function (key) { + return baseUrl + '/profiles/show?key=' + encodeURIComponent(key); +}); - Handlebars.registerHelper('profileUrl', function (key) { - return baseUrl + '/profiles/show?key=' + encodeURIComponent(key); - }); +Handlebars.registerHelper('exporterUrl', function (profile, exporterKey) { + var url = baseUrl + '/api/qualityprofiles/export'; + url += '?language=' + encodeURIComponent(profile.language); + url += '&name=' + encodeURIComponent(profile.name); + if (exporterKey != null) { + url += '&exporterKey=' + encodeURIComponent(exporterKey); + } + return url; +}); - Handlebars.registerHelper('exporterUrl', function (profile, exporterKey) { - var url = baseUrl + '/api/qualityprofiles/export'; - url += '?language=' + encodeURIComponent(profile.language); - url += '&name=' + encodeURIComponent(profile.name); - if (exporterKey != null) { - url += '&exporterKey=' + encodeURIComponent(exporterKey); - } - return url; - }); +Handlebars.registerHelper('severityChangelog', function (severity) { + var label = '<i class="icon-severity-' + severity.toLowerCase() + '"></i> ' + t('severity', severity), + message = tp('quality_profiles.severity_set_to_x', label); + return new Handlebars.SafeString(message); +}); - Handlebars.registerHelper('severityChangelog', function (severity) { - var label = '<i class="icon-severity-' + severity.toLowerCase() + '"></i> ' + t('severity', severity), - message = tp('quality_profiles.severity_set_to_x', label); - return new Handlebars.SafeString(message); - }); - - Handlebars.registerHelper('parameterChangelog', function (value, parameter) { - if (parameter) { - return new Handlebars.SafeString(tp('quality_profiles.parameter_set_to_x', value, parameter)); - } else { - return new Handlebars.SafeString(tp('quality_profiles.changelog.parameter_reset_to_default_value_x', parameter)); - } - }); - -})(); +Handlebars.registerHelper('parameterChangelog', function (value, parameter) { + if (parameter) { + return new Handlebars.SafeString(tp('quality_profiles.parameter_set_to_x', value, parameter)); + } else { + return new Handlebars.SafeString(tp('quality_profiles.changelog.parameter_reset_to_default_value_x', parameter)); + } +}); diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/intro-view.js b/server/sonar-web/src/main/js/apps/quality-profiles/intro-view.js index bb409c80cfe..c250e4c7569 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/intro-view.js +++ b/server/sonar-web/src/main/js/apps/quality-profiles/intro-view.js @@ -1,9 +1,8 @@ -define([ - './templates' -], function () { - - return Marionette.ItemView.extend({ - template: Templates['quality-profiles-intro'] - }); +import Marionette from 'backbone.marionette'; +import './templates'; +export default Marionette.ItemView.extend({ + template: Templates['quality-profiles-intro'] }); + + diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/layout.js b/server/sonar-web/src/main/js/apps/quality-profiles/layout.js index eebc8a27045..6f7a0af9057 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/layout.js +++ b/server/sonar-web/src/main/js/apps/quality-profiles/layout.js @@ -1,30 +1,29 @@ -define([ - './intro-view', - './templates' -], function (IntroView) { +import Marionette from 'backbone.marionette'; +import IntroView from './intro-view'; +import './templates'; - return Marionette.LayoutView.extend({ - template: Templates['quality-profiles-layout'], +export default Marionette.LayoutView.extend({ + template: Templates['quality-profiles-layout'], - regions: { - headerRegion: '.search-navigator-workspace-header', - actionsRegion: '.search-navigator-filters', - resultsRegion: '.quality-profiles-results', - detailsRegion: '.search-navigator-workspace-details' - }, + regions: { + headerRegion: '.search-navigator-workspace-header', + actionsRegion: '.search-navigator-filters', + resultsRegion: '.quality-profiles-results', + detailsRegion: '.search-navigator-workspace-details' + }, - onRender: function () { - var navigator = this.$('.search-navigator'); - navigator.addClass('sticky search-navigator-extended-view'); - var top = navigator.offset().top; - this.$('.search-navigator-workspace-header').css({ top: top }); - this.$('.search-navigator-side').css({ top: top }).isolatedScroll(); - this.renderIntro(); - }, - - renderIntro: function () { - this.detailsRegion.show(new IntroView()); - } - }); + onRender: function () { + var navigator = this.$('.search-navigator'); + navigator.addClass('sticky search-navigator-extended-view'); + var top = navigator.offset().top; + this.$('.search-navigator-workspace-header').css({ top: top }); + this.$('.search-navigator-side').css({ top: top }).isolatedScroll(); + this.renderIntro(); + }, + renderIntro: function () { + this.detailsRegion.show(new IntroView()); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/profile-changelog-view.js b/server/sonar-web/src/main/js/apps/quality-profiles/profile-changelog-view.js index ee2f4985dad..4d9e18ad660 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/profile-changelog-view.js +++ b/server/sonar-web/src/main/js/apps/quality-profiles/profile-changelog-view.js @@ -1,38 +1,37 @@ -define([ - './templates' -], function () { - - return Marionette.ItemView.extend({ - template: Templates['quality-profile-changelog'], - - events: { - 'submit #quality-profile-changelog-form': 'onFormSubmit', - 'click .js-show-more-changelog': 'onShowMoreChangelogClick', - 'click .js-hide-changelog': 'onHideChangelogClick' - }, - - onFormSubmit: function (e) { - e.preventDefault(); - this.model.fetchChangelog(this.getSearchParameters()); - }, - - onShowMoreChangelogClick: function (e) { - e.preventDefault(); - this.model.fetchMoreChangelog(); - }, - - onHideChangelogClick: function (e) { - e.preventDefault(); - this.model.resetChangelog(); - }, - - getSearchParameters: function () { - var form = this.$('#quality-profile-changelog-form'); - return { - since: form.find('[name="since"]').val(), - to: form.find('[name="to"]').val() - }; - } - }); +import Marionette from 'backbone.marionette'; +import './templates'; +export default Marionette.ItemView.extend({ + template: Templates['quality-profile-changelog'], + + events: { + 'submit #quality-profile-changelog-form': 'onFormSubmit', + 'click .js-show-more-changelog': 'onShowMoreChangelogClick', + 'click .js-hide-changelog': 'onHideChangelogClick' + }, + + onFormSubmit: function (e) { + e.preventDefault(); + this.model.fetchChangelog(this.getSearchParameters()); + }, + + onShowMoreChangelogClick: function (e) { + e.preventDefault(); + this.model.fetchMoreChangelog(); + }, + + onHideChangelogClick: function (e) { + e.preventDefault(); + this.model.resetChangelog(); + }, + + getSearchParameters: function () { + var form = this.$('#quality-profile-changelog-form'); + return { + since: form.find('[name="since"]').val(), + to: form.find('[name="to"]').val() + }; + } }); + + diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/profile-comparison-view.js b/server/sonar-web/src/main/js/apps/quality-profiles/profile-comparison-view.js index 522c75d16e0..aab7018aac6 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/profile-comparison-view.js +++ b/server/sonar-web/src/main/js/apps/quality-profiles/profile-comparison-view.js @@ -1,41 +1,41 @@ -define([ - './templates' -], function () { - - return Marionette.ItemView.extend({ - template: Templates['quality-profile-comparison'], - - events: { - 'submit #quality-profile-comparison-form': 'onFormSubmit' - }, - - onRender: function () { - this.$('select').select2({ - width: '250px', - minimumResultsForSearch: 50 - }); - }, - - onFormSubmit: function (e) { - e.preventDefault(); - var withKey = this.$('#quality-profile-comparison-with-key').val(); - this.model.compareWith(withKey); - }, - - getProfilesForComparison: function () { - var profiles = this.model.collection.toJSON(), - key = this.model.id, - language = this.model.get('language'); - return profiles.filter(function (profile) { - return profile.language === language && key !== profile.key; - }); - }, - - serializeData: function () { - return _.extend(Marionette.ItemView.prototype.serializeData.apply(this, arguments), { - profiles: this.getProfilesForComparison() - }); - } - }); +import _ from 'underscore'; +import Marionette from 'backbone.marionette'; +import './templates'; +export default Marionette.ItemView.extend({ + template: Templates['quality-profile-comparison'], + + events: { + 'submit #quality-profile-comparison-form': 'onFormSubmit' + }, + + onRender: function () { + this.$('select').select2({ + width: '250px', + minimumResultsForSearch: 50 + }); + }, + + onFormSubmit: function (e) { + e.preventDefault(); + var withKey = this.$('#quality-profile-comparison-with-key').val(); + this.model.compareWith(withKey); + }, + + getProfilesForComparison: function () { + var profiles = this.model.collection.toJSON(), + key = this.model.id, + language = this.model.get('language'); + return profiles.filter(function (profile) { + return profile.language === language && key !== profile.key; + }); + }, + + serializeData: function () { + return _.extend(Marionette.ItemView.prototype.serializeData.apply(this, arguments), { + profiles: this.getProfilesForComparison() + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/profile-details-view.js b/server/sonar-web/src/main/js/apps/quality-profiles/profile-details-view.js index 8f20d637e9c..03ea016e555 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/profile-details-view.js +++ b/server/sonar-web/src/main/js/apps/quality-profiles/profile-details-view.js @@ -1,156 +1,155 @@ -define([ - './change-profile-parent-view', - './profile-changelog-view', - './profile-comparison-view', - 'components/common/select-list', - './helpers', - './templates' -], function (ChangeProfileParentView, ProfileChangelogView, ProfileComparisonView) { - - var $ = jQuery; - - return Marionette.LayoutView.extend({ - template: Templates['quality-profiles-profile-details'], - - regions: { - changelogRegion: '#quality-profile-changelog', - comparisonRegion: '#quality-profile-comparison' - }, - - modelEvents: { - 'change': 'render', - 'flashChangelog': 'flashChangelog' - }, - - events: { - 'click .js-profile': 'onProfileClick', - 'click #quality-profile-change-parent': 'onChangeParentClick' - }, - - onRender: function () { - if (!this.model.get('isDefault')) { - this.initProjectsSelect(); - } - this.changelogRegion.show(new ProfileChangelogView({ model: this.model })); - this.comparisonRegion.show(new ProfileComparisonView({ model: this.model })); - if (this.options.anchor === 'changelog') { - this.scrollToChangelog(); - this.flashChangelog(); - } - if (this.options.anchor === 'comparison') { - this.scrollToComparison(); - } - this.$('#quality-profile-changelog-form input') - .datepicker({ - dateFormat: 'yy-mm-dd', - changeMonth: true, - changeYear: true - }); - }, - - initProjectsSelect: function () { - var key = this.model.get('key'); - this.projectsSelectList = new window.SelectList({ - el: this.$('#quality-profile-projects-list'), - width: '100%', - height: 200, - readOnly: !this.options.canWrite, - focusSearch: false, - format: function (item) { - return item.name; - }, - searchUrl: baseUrl + '/api/qualityprofiles/projects?key=' + encodeURIComponent(key), - selectUrl: baseUrl + '/api/qualityprofiles/add_project', - deselectUrl: baseUrl + '/api/qualityprofiles/remove_project', - extra: { - profileKey: key - }, - selectParameter: 'projectUuid', - selectParameterValue: 'uuid', - labels: { - selected: t('quality_gates.projects.with'), - deselected: t('quality_gates.projects.without'), - all: t('quality_gates.projects.all'), - noResults: t('quality_gates.projects.noResults') - }, - tooltips: { - select: t('quality_gates.projects.select_hint'), - deselect: t('quality_gates.projects.deselect_hint') - } - }); - this.listenTo(this.projectsSelectList.collection, 'change:selected', this.onProjectsChange); - }, - - onProfileClick: function (e) { - var key = $(e.currentTarget).data('key'), - profile = this.model.collection.get(key); - if (profile != null) { - e.preventDefault(); - this.model.collection.trigger('select', profile); +import $ from 'jquery'; +import _ from 'underscore'; +import Marionette from 'backbone.marionette'; +import ChangeProfileParentView from './change-profile-parent-view'; +import ProfileChangelogView from './profile-changelog-view'; +import ProfileComparisonView from './profile-comparison-view'; +import 'components/common/select-list'; +import './helpers'; +import './templates'; + +export default Marionette.LayoutView.extend({ + template: Templates['quality-profiles-profile-details'], + + regions: { + changelogRegion: '#quality-profile-changelog', + comparisonRegion: '#quality-profile-comparison' + }, + + modelEvents: { + 'change': 'render', + 'flashChangelog': 'flashChangelog' + }, + + events: { + 'click .js-profile': 'onProfileClick', + 'click #quality-profile-change-parent': 'onChangeParentClick' + }, + + onRender: function () { + if (!this.model.get('isDefault')) { + this.initProjectsSelect(); + } + this.changelogRegion.show(new ProfileChangelogView({ model: this.model })); + this.comparisonRegion.show(new ProfileComparisonView({ model: this.model })); + if (this.options.anchor === 'changelog') { + this.scrollToChangelog(); + this.flashChangelog(); + } + if (this.options.anchor === 'comparison') { + this.scrollToComparison(); + } + this.$('#quality-profile-changelog-form input') + .datepicker({ + dateFormat: 'yy-mm-dd', + changeMonth: true, + changeYear: true + }); + }, + + initProjectsSelect: function () { + var key = this.model.get('key'); + this.projectsSelectList = new window.SelectList({ + el: this.$('#quality-profile-projects-list'), + width: '100%', + height: 200, + readOnly: !this.options.canWrite, + focusSearch: false, + format: function (item) { + return item.name; + }, + searchUrl: baseUrl + '/api/qualityprofiles/projects?key=' + encodeURIComponent(key), + selectUrl: baseUrl + '/api/qualityprofiles/add_project', + deselectUrl: baseUrl + '/api/qualityprofiles/remove_project', + extra: { + profileKey: key + }, + selectParameter: 'projectUuid', + selectParameterValue: 'uuid', + labels: { + selected: t('quality_gates.projects.with'), + deselected: t('quality_gates.projects.without'), + all: t('quality_gates.projects.all'), + noResults: t('quality_gates.projects.noResults') + }, + tooltips: { + select: t('quality_gates.projects.select_hint'), + deselect: t('quality_gates.projects.deselect_hint') } - }, - - onChangeParentClick: function (e) { + }); + this.listenTo(this.projectsSelectList.collection, 'change:selected', this.onProjectsChange); + }, + + onProfileClick: function (e) { + var key = $(e.currentTarget).data('key'), + profile = this.model.collection.get(key); + if (profile != null) { e.preventDefault(); - this.changeParent(); - }, - - onProjectsChange: function () { - this.model.collection.updateForLanguage(this.model.get('language')); - }, - - changeParent: function () { - new ChangeProfileParentView({ - model: this.model - }).render(); - }, - - scrollTo: function (selector) { - var el = this.$(selector), - parent = el.scrollParent(); - var elOffset = el.offset(), - parentOffset = parent.offset(); - if (parent.is(document)) { - parentOffset = { top: 0 }; - } - if (elOffset != null && parentOffset != null) { - var scrollTop = elOffset.top - parentOffset.top - 53; - parent.scrollTop(scrollTop); - } - }, - - scrollToChangelog: function () { - this.scrollTo('#quality-profile-changelog'); - }, - - scrollToComparison: function () { - this.scrollTo('#quality-profile-comparison'); - }, - - getExporters: function () { - var language = this.model.get('language'); - return this.options.exporters.filter(function (exporter) { - return exporter.languages.indexOf(language) !== -1; - }); - }, - - flashChangelog: function () { - var changelogEl = this.$(this.changelogRegion.el); - changelogEl.addClass('flash in'); - setTimeout(function () { - changelogEl.removeClass('in'); - }, 2000); - }, - - serializeData: function () { - var key = this.model.get('key'), - rulesSearchUrl = '/coding_rules#qprofile=' + encodeURIComponent(key) + '|activation=true'; - return _.extend(Marionette.ItemView.prototype.serializeData.apply(this, arguments), { - rulesSearchUrl: rulesSearchUrl, - canWrite: this.options.canWrite, - exporters: this.getExporters() - }); + this.model.collection.trigger('select', profile); } - }); - + }, + + onChangeParentClick: function (e) { + e.preventDefault(); + this.changeParent(); + }, + + onProjectsChange: function () { + this.model.collection.updateForLanguage(this.model.get('language')); + }, + + changeParent: function () { + new ChangeProfileParentView({ + model: this.model + }).render(); + }, + + scrollTo: function (selector) { + var el = this.$(selector), + parent = el.scrollParent(); + var elOffset = el.offset(), + parentOffset = parent.offset(); + if (parent.is(document)) { + parentOffset = { top: 0 }; + } + if (elOffset != null && parentOffset != null) { + var scrollTop = elOffset.top - parentOffset.top - 53; + parent.scrollTop(scrollTop); + } + }, + + scrollToChangelog: function () { + this.scrollTo('#quality-profile-changelog'); + }, + + scrollToComparison: function () { + this.scrollTo('#quality-profile-comparison'); + }, + + getExporters: function () { + var language = this.model.get('language'); + return this.options.exporters.filter(function (exporter) { + return exporter.languages.indexOf(language) !== -1; + }); + }, + + flashChangelog: function () { + var changelogEl = this.$(this.changelogRegion.el); + changelogEl.addClass('flash in'); + setTimeout(function () { + changelogEl.removeClass('in'); + }, 2000); + }, + + serializeData: function () { + var key = this.model.get('key'), + rulesSearchUrl = '/coding_rules#qprofile=' + encodeURIComponent(key) + '|activation=true'; + return _.extend(Marionette.ItemView.prototype.serializeData.apply(this, arguments), { + rulesSearchUrl: rulesSearchUrl, + canWrite: this.options.canWrite, + exporters: this.getExporters() + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/profile-header-view.js b/server/sonar-web/src/main/js/apps/quality-profiles/profile-header-view.js index 99a9a1e022c..4c75884fff8 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/profile-header-view.js +++ b/server/sonar-web/src/main/js/apps/quality-profiles/profile-header-view.js @@ -1,74 +1,73 @@ -define([ - './copy-profile-view', - './rename-profile-view', - './delete-profile-view', - './templates' -], function (ProfileCopyView, ProfileRenameView, ProfileDeleteView) { +import $ from 'jquery'; +import _ from 'underscore'; +import Marionette from 'backbone.marionette'; +import ProfileCopyView from './copy-profile-view'; +import ProfileRenameView from './rename-profile-view'; +import ProfileDeleteView from './delete-profile-view'; +import './templates'; - var $ = jQuery; +export default Marionette.ItemView.extend({ + template: Templates['quality-profiles-profile-header'], - return Marionette.ItemView.extend({ - template: Templates['quality-profiles-profile-header'], + modelEvents: { + 'change': 'render' + }, - modelEvents: { - 'change': 'render' - }, + events: { + 'click #quality-profile-backup': 'onBackupClick', + 'click #quality-profile-copy': 'onCopyClick', + 'click #quality-profile-rename': 'onRenameClick', + 'click #quality-profile-set-as-default': 'onDefaultClick', + 'click #quality-profile-delete': 'onDeleteClick' + }, - events: { - 'click #quality-profile-backup': 'onBackupClick', - 'click #quality-profile-copy': 'onCopyClick', - 'click #quality-profile-rename': 'onRenameClick', - 'click #quality-profile-set-as-default': 'onDefaultClick', - 'click #quality-profile-delete': 'onDeleteClick' - }, + onBackupClick: function (e) { + $(e.currentTarget).blur(); + }, - onBackupClick: function (e) { - $(e.currentTarget).blur(); - }, + onCopyClick: function (e) { + e.preventDefault(); + this.copy(); + }, - onCopyClick: function (e) { - e.preventDefault(); - this.copy(); - }, + onRenameClick: function (e) { + e.preventDefault(); + this.rename(); + }, - onRenameClick: function (e) { - e.preventDefault(); - this.rename(); - }, + onDefaultClick: function (e) { + e.preventDefault(); + this.setAsDefault(); + }, - onDefaultClick: function (e) { - e.preventDefault(); - this.setAsDefault(); - }, + onDeleteClick: function (e) { + e.preventDefault(); + this.delete(); + }, - onDeleteClick: function (e) { - e.preventDefault(); - this.delete(); - }, + copy: function () { + new ProfileCopyView({ model: this.model }).render(); + }, - copy: function () { - new ProfileCopyView({ model: this.model }).render(); - }, + rename: function () { + new ProfileRenameView({ model: this.model }).render(); + }, - rename: function () { - new ProfileRenameView({ model: this.model }).render(); - }, + setAsDefault: function () { + this.model.trigger('setAsDefault', this.model); + }, - setAsDefault: function () { - this.model.trigger('setAsDefault', this.model); - }, + delete: function () { + new ProfileDeleteView({ model: this.model }).render(); + }, - delete: function () { - new ProfileDeleteView({ model: this.model }).render(); - }, + serializeData: function () { + var key = this.model.get('key'); + return _.extend(Marionette.ItemView.prototype.serializeData.apply(this, arguments), { + encodedKey: encodeURIComponent(key), + canWrite: this.options.canWrite + }); + } +}); - serializeData: function () { - var key = this.model.get('key'); - return _.extend(Marionette.ItemView.prototype.serializeData.apply(this, arguments), { - encodedKey: encodeURIComponent(key), - canWrite: this.options.canWrite - }); - } - }); -}); diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/profile-view.js b/server/sonar-web/src/main/js/apps/quality-profiles/profile-view.js index 19ddacf5e71..541482a5569 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/profile-view.js +++ b/server/sonar-web/src/main/js/apps/quality-profiles/profile-view.js @@ -1,41 +1,41 @@ -define([ - './templates' -], function () { - - return Marionette.ItemView.extend({ - tagName: 'a', - className: 'list-group-item', - template: Templates['quality-profiles-profile'], - - modelEvents: { - 'change': 'render' - }, - - events: { - 'click': 'onClick' - }, - - onRender: function () { - this.$el.toggleClass('active', this.options.highlighted); - this.$el.attr('data-key', this.model.id); - this.$el.attr('data-language', this.model.get('language')); - this.$('[data-toggle="tooltip"]').tooltip({ container: 'body' }); - }, - - onDestroy: function () { - this.$('[data-toggle="tooltip"]').tooltip('destroy'); - }, - - onClick: function (e) { - e.preventDefault(); - this.model.trigger('select', this.model); - }, - - serializeData: function () { - return _.extend(Marionette.ItemView.prototype.serializeData.apply(this, arguments), { - projectCountFormatted: window.formatMeasure(this.model.get('projectCount'), 'INT') - }); - } - }); - +import _ from 'underscore'; +import Marionette from 'backbone.marionette'; +import './templates'; + +export default Marionette.ItemView.extend({ + tagName: 'a', + className: 'list-group-item', + template: Templates['quality-profiles-profile'], + + modelEvents: { + 'change': 'render' + }, + + events: { + 'click': 'onClick' + }, + + onRender: function () { + this.$el.toggleClass('active', this.options.highlighted); + this.$el.attr('data-key', this.model.id); + this.$el.attr('data-language', this.model.get('language')); + this.$('[data-toggle="tooltip"]').tooltip({ container: 'body' }); + }, + + onDestroy: function () { + this.$('[data-toggle="tooltip"]').tooltip('destroy'); + }, + + onClick: function (e) { + e.preventDefault(); + this.model.trigger('select', this.model); + }, + + serializeData: function () { + return _.extend(Marionette.ItemView.prototype.serializeData.apply(this, arguments), { + projectCountFormatted: window.formatMeasure(this.model.get('projectCount'), 'INT') + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/profile.js b/server/sonar-web/src/main/js/apps/quality-profiles/profile.js index 3ae71d5c5b6..955cb2546a7 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/profile.js +++ b/server/sonar-web/src/main/js/apps/quality-profiles/profile.js @@ -1,114 +1,114 @@ -define(function () { +import $ from 'jquery'; +import _ from 'underscore'; +import Backbone from 'backbone'; - var $ = jQuery; +export default Backbone.Model.extend({ + idAttribute: 'key', - return Backbone.Model.extend({ - idAttribute: 'key', + defaults: { + activeRuleCount: 0, + projectCount: 0 + }, - defaults: { - activeRuleCount: 0, - projectCount: 0 - }, - - fetch: function () { - var that = this; - this.fetchChanged = {}; - return $.when( - this.fetchProfileRules(), - this.fetchInheritance() - ).done(function () { - that.set(that.fetchChanged); - }); - }, + 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: 'active_severities', - qprofile: key, - activation: 'true' - }; - return $.get(url, options).done(function (r) { - var severityFacet = _.findWhere(r.facets, { property: 'active_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 }); - } - }); - }, + fetchProfileRules: function () { + var that = this, + url = baseUrl + '/api/rules/search', + key = this.id, + options = { + ps: 1, + facets: 'active_severities', + qprofile: key, + activation: 'true' + }; + return $.get(url, options).done(function (r) { + var severityFacet = _.findWhere(r.facets, { property: 'active_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 - }); + 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 }); - }, + }); + }, - fetchChangelog: function (options) { - var that = this, - url = baseUrl + '/api/qualityprofiles/changelog', - opts = _.extend({}, options, { profileKey: this.id }); - return $.get(url, opts).done(function (r) { - that.set({ - events: r.events, - eventsPage: r.p, - totalEvents: r.total, - eventsParameters: _.clone(options) - }); + fetchChangelog: function (options) { + var that = this, + url = baseUrl + '/api/qualityprofiles/changelog', + opts = _.extend({}, options, { profileKey: this.id }); + return $.get(url, opts).done(function (r) { + that.set({ + events: r.events, + eventsPage: r.p, + totalEvents: r.total, + eventsParameters: _.clone(options) }); - }, + }); + }, - fetchMoreChangelog: function () { - var that = this, - url = baseUrl + '/api/qualityprofiles/changelog', - page = this.get('eventsPage') || 0, - parameters = this.get('eventsParameters') || {}, - opts = _.extend({}, parameters, { profileKey: this.id, p: page + 1 }); - return $.get(url, opts).done(function (r) { - var events = that.get('events') || []; - that.set({ - events: [].concat(events, r.events), - eventsPage: r.p, - totalEvents: r.total - }); + fetchMoreChangelog: function () { + var that = this, + url = baseUrl + '/api/qualityprofiles/changelog', + page = this.get('eventsPage') || 0, + parameters = this.get('eventsParameters') || {}, + opts = _.extend({}, parameters, { profileKey: this.id, p: page + 1 }); + return $.get(url, opts).done(function (r) { + var events = that.get('events') || []; + that.set({ + events: [].concat(events, r.events), + eventsPage: r.p, + totalEvents: r.total }); - }, + }); + }, - resetChangelog: function () { - this.unset('events', { silent: true }); - this.unset('eventsPage', { silent: true }); - this.unset('totalEvents'); - }, + resetChangelog: function () { + this.unset('events', { silent: true }); + this.unset('eventsPage', { silent: true }); + this.unset('totalEvents'); + }, - compareWith: function (withKey) { - var that = this, - url = baseUrl + '/api/qualityprofiles/compare', - options = { leftKey: this.id, rightKey: withKey }; - return $.get(url, options).done(function (r) { - var comparison = _.extend(r, { - inLeftSize: _.size(r.inLeft), - inRightSize: _.size(r.inRight), - modifiedSize: _.size(r.modified) - }); - that.set({ - comparison: comparison, - comparedWith: withKey - }); + compareWith: function (withKey) { + var that = this, + url = baseUrl + '/api/qualityprofiles/compare', + options = { leftKey: this.id, rightKey: withKey }; + return $.get(url, options).done(function (r) { + var comparison = _.extend(r, { + inLeftSize: _.size(r.inLeft), + inRightSize: _.size(r.inRight), + modifiedSize: _.size(r.modified) }); - } - }); - + that.set({ + comparison: comparison, + comparedWith: withKey + }); + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/profiles-empty-view.js b/server/sonar-web/src/main/js/apps/quality-profiles/profiles-empty-view.js index f4844bfc85f..49a0a803749 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/profiles-empty-view.js +++ b/server/sonar-web/src/main/js/apps/quality-profiles/profiles-empty-view.js @@ -1,10 +1,9 @@ -define([ - './templates' -], function () { - - return Marionette.ItemView.extend({ - className: 'list-group-item', - template: Templates['quality-profiles-empty'] - }); +import Marionette from 'backbone.marionette'; +import './templates'; +export default Marionette.ItemView.extend({ + className: 'list-group-item', + template: Templates['quality-profiles-empty'] }); + + diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/profiles-view.js b/server/sonar-web/src/main/js/apps/quality-profiles/profiles-view.js index 33d95a47b5f..82d8c26f297 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/profiles-view.js +++ b/server/sonar-web/src/main/js/apps/quality-profiles/profiles-view.js @@ -1,66 +1,65 @@ -define([ - './profile-view', - './profiles-empty-view', - './templates' -], function (ProfileView, ProfilesEmptyView) { +import Marionette from 'backbone.marionette'; +import ProfileView from './profile-view'; +import ProfilesEmptyView from './profiles-empty-view'; +import './templates'; - return Marionette.CompositeView.extend({ - className: 'list-group', - template: Templates['quality-profiles-profiles'], - languageTemplate: Templates['quality-profiles-profiles-language'], - childView: ProfileView, - childViewContainer: '.js-list', - emptyView: ProfilesEmptyView, +export default Marionette.CompositeView.extend({ + className: 'list-group', + template: Templates['quality-profiles-profiles'], + languageTemplate: Templates['quality-profiles-profiles-language'], + childView: ProfileView, + childViewContainer: '.js-list', + emptyView: ProfilesEmptyView, - collectionEvents: { - 'filter': 'filterByLanguage' - }, + collectionEvents: { + 'filter': 'filterByLanguage' + }, - childViewOptions: function (model) { - return { - collectionView: this, - highlighted: model.get('key') === this.highlighted - }; - }, + childViewOptions: function (model) { + return { + collectionView: this, + highlighted: model.get('key') === this.highlighted + }; + }, - highlight: function (key) { - this.highlighted = key; - this.render(); - }, + highlight: function (key) { + this.highlighted = key; + this.render(); + }, - attachHtml: function (compositeView, childView, index) { - var $container = this.getChildViewContainer(compositeView), - model = this.collection.at(index); - if (model != null) { - var prev = this.collection.at(index - 1), - putLanguage = prev == null; - if (prev != null) { - var lang = model.get('language'), - prevLang = prev.get('language'); - if (lang !== prevLang) { - putLanguage = true; - } - } - if (putLanguage) { - $container.append(this.languageTemplate(model.toJSON())); + attachHtml: function (compositeView, childView, index) { + var $container = this.getChildViewContainer(compositeView), + model = this.collection.at(index); + if (model != null) { + var prev = this.collection.at(index - 1), + putLanguage = prev == null; + if (prev != null) { + var lang = model.get('language'), + prevLang = prev.get('language'); + if (lang !== prevLang) { + putLanguage = true; } } - compositeView._insertAfter(childView); - }, - - destroyChildren: function () { - Marionette.CompositeView.prototype.destroyChildren.apply(this, arguments); - this.$('.js-list-language').remove(); - }, - - filterByLanguage: function (language) { - if (language) { - this.$('[data-language]').addClass('hidden'); - this.$('[data-language="' + language + '"]').removeClass('hidden'); - } else { - this.$('[data-language]').removeClass('hidden'); + if (putLanguage) { + $container.append(this.languageTemplate(model.toJSON())); } } - }); + compositeView._insertAfter(childView); + }, + + destroyChildren: function () { + Marionette.CompositeView.prototype.destroyChildren.apply(this, arguments); + this.$('.js-list-language').remove(); + }, + filterByLanguage: function (language) { + if (language) { + this.$('[data-language]').addClass('hidden'); + this.$('[data-language="' + language + '"]').removeClass('hidden'); + } else { + this.$('[data-language]').removeClass('hidden'); + } + } }); + + diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/profiles.js b/server/sonar-web/src/main/js/apps/quality-profiles/profiles.js index fde1a6e6397..194004e905e 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/profiles.js +++ b/server/sonar-web/src/main/js/apps/quality-profiles/profiles.js @@ -1,26 +1,25 @@ -define([ - './profile' -], function (Profile) { +import Backbone from 'backbone'; +import Profile from './profile'; - return Backbone.Collection.extend({ - model: Profile, - url: baseUrl + '/api/qualityprofiles/search', - comparator: 'key', +export default Backbone.Collection.extend({ + model: Profile, + url: baseUrl + '/api/qualityprofiles/search', + comparator: 'key', - parse: function (r) { - return r.profiles; - }, - - updateForLanguage: function (language) { - this.fetch({ - data: { - language: language - }, - merge: true, - reset: false, - remove: false - }); - } - }); + parse: function (r) { + return r.profiles; + }, + updateForLanguage: function (language) { + this.fetch({ + data: { + language: language + }, + merge: true, + reset: false, + remove: false + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/rename-profile-view.js b/server/sonar-web/src/main/js/apps/quality-profiles/rename-profile-view.js index e54377708ca..9e4aef76403 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/rename-profile-view.js +++ b/server/sonar-web/src/main/js/apps/quality-profiles/rename-profile-view.js @@ -1,41 +1,38 @@ -define([ - 'components/common/modal-form', - './templates' -], function (ModalFormView) { +import $ from 'jquery'; +import ModalFormView from 'components/common/modal-form'; +import './templates'; - var $ = jQuery; +export default ModalFormView.extend({ + template: Templates['quality-profiles-rename-profile'], - return ModalFormView.extend({ - template: Templates['quality-profiles-rename-profile'], + onFormSubmit: function () { + ModalFormView.prototype.onFormSubmit.apply(this, arguments); + this.sendRequest(); + }, - onFormSubmit: function () { - ModalFormView.prototype.onFormSubmit.apply(this, arguments); - this.sendRequest(); - }, + sendRequest: function () { + var that = this, + url = baseUrl + '/api/qualityprofiles/rename', + name = this.$('#rename-profile-name').val(), + options = { + key: this.model.get('key'), + name: name + }; + return $.ajax({ + type: 'POST', + url: url, + data: options, + statusCode: { + // do not show global error + 400: null + } + }).done(function () { + that.model.set({ name: name }); + that.destroy(); + }).fail(function (jqXHR) { + that.showErrors(jqXHR.responseJSON.errors, jqXHR.responseJSON.warnings); + }); + } +}); - sendRequest: function () { - var that = this, - url = baseUrl + '/api/qualityprofiles/rename', - name = this.$('#rename-profile-name').val(), - options = { - key: this.model.get('key'), - name: name - }; - return $.ajax({ - type: 'POST', - url: url, - data: options, - statusCode: { - // do not show global error - 400: null - } - }).done(function () { - that.model.set({ name: name }); - that.destroy(); - }).fail(function (jqXHR) { - that.showErrors(jqXHR.responseJSON.errors, jqXHR.responseJSON.warnings); - }); - } - }); -}); diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/restore-built-in-profiles-view.js b/server/sonar-web/src/main/js/apps/quality-profiles/restore-built-in-profiles-view.js index 2c84315281a..76ca3851738 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/restore-built-in-profiles-view.js +++ b/server/sonar-web/src/main/js/apps/quality-profiles/restore-built-in-profiles-view.js @@ -1,56 +1,54 @@ -define([ - 'components/common/modal-form', - './templates' -], function (ModalFormView) { +import $ from 'jquery'; +import _ from 'underscore'; +import ModalFormView from 'components/common/modal-form'; +import './templates'; - var $ = jQuery; +export default ModalFormView.extend({ + template: Templates['quality-profiles-restore-built-in-profiles'], - return ModalFormView.extend({ - template: Templates['quality-profiles-restore-built-in-profiles'], + onFormSubmit: function () { + ModalFormView.prototype.onFormSubmit.apply(this, arguments); + this.disableForm(); + this.sendRequest(); + }, - onFormSubmit: function () { - ModalFormView.prototype.onFormSubmit.apply(this, arguments); - this.disableForm(); - this.sendRequest(); - }, + onRender: function () { + ModalFormView.prototype.onRender.apply(this, arguments); + this.$('select').select2({ + width: '250px', + minimumResultsForSearch: 50 + }); + }, - onRender: function () { - ModalFormView.prototype.onRender.apply(this, arguments); - this.$('select').select2({ - width: '250px', - minimumResultsForSearch: 50 - }); - }, + sendRequest: function () { + var that = this, + url = baseUrl + '/api/qualityprofiles/restore_built_in', + options = { + language: this.$('#restore-built-in-profiles-language').val() + }; + return $.ajax({ + type: 'POST', + url: url, + data: options, + statusCode: { + // do not show global error + 400: null + } + }).done(function () { + that.collection.fetch({ reset: true }); + that.collection.trigger('destroy'); + that.destroy(); + }).fail(function (jqXHR) { + that.showErrors(jqXHR.responseJSON.errors, jqXHR.responseJSON.warnings); + that.enableForm(); + }); + }, - sendRequest: function () { - var that = this, - url = baseUrl + '/api/qualityprofiles/restore_built_in', - options = { - language: this.$('#restore-built-in-profiles-language').val() - }; - return $.ajax({ - type: 'POST', - url: url, - data: options, - statusCode: { - // do not show global error - 400: null - } - }).done(function () { - that.collection.fetch({ reset: true }); - that.collection.trigger('destroy'); - that.destroy(); - }).fail(function (jqXHR) { - that.showErrors(jqXHR.responseJSON.errors, jqXHR.responseJSON.warnings); - that.enableForm(); - }); - }, + serializeData: function () { + return _.extend(ModalFormView.prototype.serializeData.apply(this, arguments), { + languages: this.options.languages + }); + } +}); - serializeData: function () { - return _.extend(ModalFormView.prototype.serializeData.apply(this, arguments), { - languages: this.options.languages - }); - } - }); -}); diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/restore-profile-view.js b/server/sonar-web/src/main/js/apps/quality-profiles/restore-profile-view.js index ebc7812e12d..57540d9b4a4 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/restore-profile-view.js +++ b/server/sonar-web/src/main/js/apps/quality-profiles/restore-profile-view.js @@ -1,36 +1,34 @@ -define([ - 'components/common/modal-form', - 'components/common/file-upload', - './profile', - './templates' -], function (ModalFormView, uploader, Profile) { +import $ from 'jquery'; +import _ from 'underscore'; +import ModalFormView from 'components/common/modal-form'; +import uploader from 'components/common/file-upload'; +import Profile from './profile'; +import './templates'; - var $ = jQuery; +export default ModalFormView.extend({ + template: Templates['quality-profiles-restore-profile'], - return ModalFormView.extend({ - template: Templates['quality-profiles-restore-profile'], - - onFormSubmit: function (e) { - var that = this; - ModalFormView.prototype.onFormSubmit.apply(this, arguments); - uploader({ form: $(e.currentTarget) }).done(function (r) { - if (_.isArray(r.errors) || _.isArray(r.warnings)) { - that.showErrors(r.errors, r.warnings); - } else { - that.addProfile(r.profile); - that.destroy(); - } - }); - }, - - addProfile: function (profileData) { - var profile = new Profile(profileData); - this.collection.add([profile], { merge: true }); - var addedProfile = this.collection.get(profile.id); - if (addedProfile != null) { - addedProfile.trigger('select', addedProfile); + onFormSubmit: function (e) { + var that = this; + ModalFormView.prototype.onFormSubmit.apply(this, arguments); + uploader({ form: $(e.currentTarget) }).done(function (r) { + if (_.isArray(r.errors) || _.isArray(r.warnings)) { + that.showErrors(r.errors, r.warnings); + } else { + that.addProfile(r.profile); + that.destroy(); } - } - }); + }); + }, + addProfile: function (profileData) { + var profile = new Profile(profileData); + this.collection.add([profile], { merge: true }); + var addedProfile = this.collection.get(profile.id); + if (addedProfile != null) { + addedProfile.trigger('select', addedProfile); + } + } }); + + diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/router.js b/server/sonar-web/src/main/js/apps/quality-profiles/router.js index 1854fe66b22..c672f5b3418 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/router.js +++ b/server/sonar-web/src/main/js/apps/quality-profiles/router.js @@ -1,37 +1,37 @@ -define(function () { - - return Backbone.Router.extend({ - routes: { - '': 'index', - 'index': 'index', - 'show?key=:key': 'show', - 'changelog*': 'changelog', - 'compare*': 'compare' - }, - - initialize: function (options) { - this.app = options.app; - }, - - index: function () { - this.app.controller.index(); - }, - - show: function (key) { - this.app.controller.show(key); - }, - - changelog: function () { - var params = window.getQueryParams(); - this.app.controller.changelog(params.key, params.since, params.to); - }, - - compare: function () { - var params = window.getQueryParams(); - if (params.key && params.withKey) { - this.app.controller.compare(params.key, params.withKey); - } - } - }); +import Backbone from 'backbone'; + +export default Backbone.Router.extend({ + routes: { + '': 'index', + 'index': 'index', + 'show?key=:key': 'show', + 'changelog*': 'changelog', + 'compare*': 'compare' + }, + + initialize: function (options) { + this.app = options.app; + }, + + index: function () { + this.app.controller.index(); + }, + + show: function (key) { + this.app.controller.show(key); + }, + changelog: function () { + var params = window.getQueryParams(); + this.app.controller.changelog(params.key, params.since, params.to); + }, + + compare: function () { + var params = window.getQueryParams(); + if (params.key && params.withKey) { + this.app.controller.compare(params.key, params.withKey); + } + } }); + + |