From 890ab0b59cdb3902f4869eabf8ca534814f1b3dd Mon Sep 17 00:00:00 2001 From: Stas Vilchik Date: Thu, 17 Sep 2015 16:15:28 +0200 Subject: [PATCH] migrate js apps to es2015 modules --- server/sonar-web/.eslintrc | 5 - server/sonar-web/Gruntfile.coffee | 12 +- .../sonar-web/src/main/js/apps/account/app.js | 54 +- .../js/apps/account/change-password-view.js | 89 ++-- .../js/apps/api-documentation/action-view.js | 104 ++-- .../js/apps/api-documentation/actions-view.js | 78 ++- .../src/main/js/apps/api-documentation/app.js | 118 +++-- .../js/apps/api-documentation/controller.js | 125 +++-- .../js/apps/api-documentation/filters-view.js | 42 +- .../js/apps/api-documentation/header-view.js | 19 +- .../js/apps/api-documentation/item-view.js | 102 ++-- .../main/js/apps/api-documentation/layout.js | 41 +- .../js/apps/api-documentation/list-view.js | 37 +- .../main/js/apps/api-documentation/list.js | 39 +- .../main/js/apps/api-documentation/router.js | 25 +- .../js/apps/api-documentation/search-view.js | 66 +-- .../src/main/js/apps/coding-rules/app.js | 202 ++++---- .../coding-rules/bulk-change-modal-view.js | 164 +++---- .../coding-rules/bulk-change-popup-view.js | 66 ++- .../main/js/apps/coding-rules/controller.js | 294 +++++------ .../main/js/apps/coding-rules/facets-view.js | 91 ++-- .../facets/active-severity-facet.js | 87 ++-- .../facets/available-since-facet.js | 75 ++- .../js/apps/coding-rules/facets/base-facet.js | 16 +- .../facets/characteristic-facet.js | 112 +++-- .../facets/custom-labels-facet.js | 43 +- .../facets/custom-values-facet.js | 121 +++-- .../coding-rules/facets/inheritance-facet.js | 114 +++-- .../js/apps/coding-rules/facets/key-facet.js | 37 +- .../coding-rules/facets/language-facet.js | 93 ++-- .../facets/quality-profile-facet.js | 136 +++-- .../apps/coding-rules/facets/query-facet.js | 61 ++- .../coding-rules/facets/repository-facet.js | 105 ++-- .../coding-rules/facets/severity-facet.js | 29 +- .../apps/coding-rules/facets/status-facet.js | 49 +- .../js/apps/coding-rules/facets/tag-facet.js | 50 +- .../coding-rules/facets/template-facet.js | 51 +- .../main/js/apps/coding-rules/filters-view.js | 38 +- .../src/main/js/apps/coding-rules/layout.js | 72 ++- .../main/js/apps/coding-rules/models/rule.js | 51 +- .../main/js/apps/coding-rules/models/rules.js | 68 +-- .../main/js/apps/coding-rules/models/state.js | 38 +- .../js/apps/coding-rules/rule-details-view.js | 351 +++++++------ .../js/apps/coding-rules/rule-filter-view.js | 37 +- .../rule/custom-rule-creation-view.js | 362 +++++++------- .../coding-rules/rule/custom-rule-view.js | 73 ++- .../coding-rules/rule/custom-rules-view.js | 88 ++-- .../rule/manual-rule-creation-view.js | 206 ++++---- .../rule/profile-activation-view.js | 273 +++++------ .../rule/rule-description-view.js | 143 +++--- .../coding-rules/rule/rule-filter-mixin.js | 47 +- .../coding-rules/rule/rule-issues-view.js | 87 ++-- .../apps/coding-rules/rule/rule-meta-view.js | 165 +++---- .../coding-rules/rule/rule-parameters-view.js | 40 +- .../coding-rules/rule/rule-profile-view.js | 250 +++++----- .../coding-rules/rule/rule-profiles-view.js | 14 +- .../coding-rules/workspace-header-view.js | 96 ++-- .../coding-rules/workspace-list-empty-view.js | 16 +- .../coding-rules/workspace-list-item-view.js | 161 +++--- .../apps/coding-rules/workspace-list-view.js | 56 +-- .../src/main/js/apps/computation/app.js | 108 ++-- .../main/js/apps/computation/header-view.js | 13 +- .../src/main/js/apps/computation/layout.js | 25 +- .../js/apps/computation/list-footer-view.js | 64 +-- .../js/apps/computation/list-item-view.js | 44 +- .../src/main/js/apps/computation/list-view.js | 17 +- .../src/main/js/apps/computation/report.js | 44 +- .../src/main/js/apps/computation/reports.js | 64 +-- .../src/main/js/apps/computation/router.js | 46 +- .../main/js/apps/computation/search-view.js | 64 +-- .../apps/custom-measures/{app.jsx => app.js} | 1 + .../js/apps/custom-measures/create-view.js | 56 +-- .../js/apps/custom-measures/custom-measure.js | 65 +-- .../apps/custom-measures/custom-measures.js | 100 ++-- .../js/apps/custom-measures/delete-view.js | 54 +- .../main/js/apps/custom-measures/form-view.js | 101 ++-- .../js/apps/custom-measures/header-view.js | 41 +- .../main/js/apps/custom-measures/layout.js | 23 +- .../apps/custom-measures/list-footer-view.js | 64 +-- .../js/apps/custom-measures/list-item-view.js | 91 ++-- .../main/js/apps/custom-measures/list-view.js | 19 +- .../js/apps/custom-measures/update-view.js | 50 +- .../src/main/js/apps/drilldown/app.js | 54 +- .../main/js/apps/global-permissions/app.jsx | 2 - .../js/apps/global-permissions/groups-view.js | 94 ++-- .../main/js/apps/global-permissions/main.jsx | 3 +- .../permission-users-groups-mixin.jsx | 2 - .../global-permissions/permission-users.jsx | 1 - .../js/apps/global-permissions/permission.jsx | 3 +- .../js/apps/global-permissions/users-view.js | 94 ++-- .../sonar-web/src/main/js/apps/groups/app.js | 87 ++-- .../src/main/js/apps/groups/create-view.js | 52 +- .../src/main/js/apps/groups/delete-view.js | 64 ++- .../src/main/js/apps/groups/form-view.js | 38 +- .../src/main/js/apps/groups/group.js | 65 +-- .../src/main/js/apps/groups/groups.js | 73 ++- .../src/main/js/apps/groups/header-view.js | 39 +- .../src/main/js/apps/groups/layout.js | 25 +- .../main/js/apps/groups/list-footer-view.js | 64 +-- .../src/main/js/apps/groups/list-item-view.js | 120 +++-- .../src/main/js/apps/groups/list-view.js | 17 +- .../src/main/js/apps/groups/search-view.js | 92 ++-- .../src/main/js/apps/groups/update-view.js | 50 +- .../src/main/js/apps/groups/users-view.js | 74 ++- .../src/main/js/apps/issues/app-context.js | 164 +++---- .../sonar-web/src/main/js/apps/issues/app.js | 117 +++-- .../issues/component-viewer/issue-view.js | 29 +- .../js/apps/issues/component-viewer/main.js | 399 ++++++++------- .../src/main/js/apps/issues/controller.js | 464 +++++++++--------- .../src/main/js/apps/issues/facets-view.js | 94 ++-- .../apps/issues/facets/action-plan-facet.js | 114 +++-- .../js/apps/issues/facets/assignee-facet.js | 182 ++++--- .../js/apps/issues/facets/author-facet.js | 76 ++- .../main/js/apps/issues/facets/base-facet.js | 39 +- .../js/apps/issues/facets/context-facet.js | 25 +- .../apps/issues/facets/creation-date-facet.js | 260 +++++----- .../apps/issues/facets/custom-values-facet.js | 119 +++-- .../main/js/apps/issues/facets/file-facet.js | 72 ++- .../js/apps/issues/facets/issue-key-facet.js | 37 +- .../js/apps/issues/facets/language-facet.js | 117 +++-- .../main/js/apps/issues/facets/mode-facet.js | 35 +- .../js/apps/issues/facets/module-facet.js | 51 +- .../js/apps/issues/facets/project-facet.js | 145 +++--- .../js/apps/issues/facets/reporter-facet.js | 79 ++- .../js/apps/issues/facets/resolution-facet.js | 82 ++-- .../main/js/apps/issues/facets/rule-facet.js | 139 +++--- .../js/apps/issues/facets/severity-facet.js | 27 +- .../js/apps/issues/facets/status-facet.js | 27 +- .../main/js/apps/issues/facets/tag-facet.js | 97 ++-- .../src/main/js/apps/issues/filters-view.js | 155 +++--- .../apps/issues/helpers/format-facet-value.js | 10 +- .../main/js/apps/issues/issue-filter-view.js | 38 +- .../src/main/js/apps/issues/layout.js | 104 ++-- .../src/main/js/apps/issues/models/filter.js | 26 +- .../src/main/js/apps/issues/models/filters.js | 25 +- .../src/main/js/apps/issues/models/issue.js | 24 +- .../src/main/js/apps/issues/models/issues.js | 144 +++--- .../src/main/js/apps/issues/models/state.js | 127 +++-- .../src/main/js/apps/issues/router.js | 76 ++- .../js/apps/issues/workspace-header-view.js | 224 +++++---- .../js/apps/issues/workspace-home-view.js | 19 +- .../apps/issues/workspace-list-empty-view.js | 16 +- .../apps/issues/workspace-list-item-view.js | 253 +++++----- .../js/apps/issues/workspace-list-view.js | 196 ++++---- .../src/main/js/apps/maintenance/app.js | 25 +- .../src/main/js/apps/maintenance/main-view.js | 122 ++--- .../src/main/js/apps/markdown/app.js | 15 +- .../js/apps/markdown/markdown-help-view.js | 11 +- .../src/main/js/apps/measures/app.js | 326 ++++++------ .../js/apps/measures/measures-filter-bar.js | 15 +- .../sonar-web/src/main/js/apps/metrics/app.js | 119 +++-- .../src/main/js/apps/metrics/create-view.js | 64 ++- .../src/main/js/apps/metrics/delete-view.js | 54 +- .../src/main/js/apps/metrics/form-view.js | 108 ++-- .../src/main/js/apps/metrics/header-view.js | 45 +- .../src/main/js/apps/metrics/layout.js | 23 +- .../main/js/apps/metrics/list-footer-view.js | 64 +-- .../main/js/apps/metrics/list-item-view.js | 101 ++-- .../src/main/js/apps/metrics/list-view.js | 29 +- .../src/main/js/apps/metrics/metric.js | 65 +-- .../src/main/js/apps/metrics/metrics.js | 78 +-- .../src/main/js/apps/metrics/update-view.js | 56 +-- .../apps/nav/component/component-nav-menu.jsx | 1 + .../js/apps/nav/component/component-nav.jsx | 3 +- .../js/apps/nav/global/global-nav-search.jsx | 3 +- .../main/js/apps/nav/global/global-nav.jsx | 3 +- .../main/js/apps/nav/global/search-view.js | 440 ++++++++--------- .../js/apps/nav/global/shortcuts-help-view.js | 16 +- .../src/main/js/apps/nav/links-mixin.jsx | 1 + .../js/apps/nav/settings/settings-nav.jsx | 3 +- .../apply-template-view.jsx | 1 + .../apps/project-permissions/groups-view.js | 93 ++-- .../project-permissions/main-component.jsx | 3 +- .../js/apps/project-permissions/search.jsx | 1 + .../js/apps/project-permissions/users-view.js | 91 ++-- .../src/main/js/apps/provisioning/app.js | 87 ++-- .../js/apps/provisioning/bulk-delete-view.js | 53 +- .../main/js/apps/provisioning/create-view.js | 54 +- .../main/js/apps/provisioning/delete-view.js | 54 +- .../main/js/apps/provisioning/form-view.js | 38 +- .../main/js/apps/provisioning/header-view.js | 95 ++-- .../src/main/js/apps/provisioning/layout.js | 25 +- .../js/apps/provisioning/list-footer-view.js | 64 +-- .../js/apps/provisioning/list-item-view.js | 101 ++-- .../main/js/apps/provisioning/list-view.js | 17 +- .../src/main/js/apps/provisioning/project.js | 63 +-- .../src/main/js/apps/provisioning/projects.js | 94 ++-- .../main/js/apps/provisioning/search-view.js | 198 ++++---- .../js/apps/quality-gates/actions-view.js | 44 +- .../src/main/js/apps/quality-gates/app.js | 112 ++--- .../main/js/apps/quality-gates/condition.js | 90 ++-- .../main/js/apps/quality-gates/conditions.js | 15 +- .../main/js/apps/quality-gates/controller.js | 107 ++-- .../main/js/apps/quality-gates/copy-view.js | 40 +- .../main/js/apps/quality-gates/create-view.js | 40 +- .../main/js/apps/quality-gates/delete-view.js | 56 +-- .../js/apps/quality-gates/details-view.js | 87 ++-- .../main/js/apps/quality-gates/form-view.js | 82 ++-- .../apps/quality-gates/gate-condition-view.js | 196 ++++---- .../gate-conditions-delete-view.js | 68 +-- .../gate-conditions-empty-view.js | 26 +- .../quality-gates/gate-conditions-view.js | 130 ++--- .../apps/quality-gates/gate-projects-view.js | 84 ++-- .../main/js/apps/quality-gates/gate-view.js | 45 +- .../src/main/js/apps/quality-gates/gate.js | 102 ++-- .../main/js/apps/quality-gates/gates-view.js | 41 +- .../src/main/js/apps/quality-gates/gates.js | 48 +- .../main/js/apps/quality-gates/header-view.js | 102 ++-- .../main/js/apps/quality-gates/intro-view.js | 13 +- .../src/main/js/apps/quality-gates/layout.js | 45 +- .../main/js/apps/quality-gates/rename-view.js | 38 +- .../src/main/js/apps/quality-gates/router.js | 34 +- .../js/apps/quality-profiles/actions-view.js | 187 ++++--- .../src/main/js/apps/quality-profiles/app.js | 118 ++--- .../change-profile-parent-view.js | 111 +++-- .../js/apps/quality-profiles/controller.js | 211 ++++---- .../quality-profiles/copy-profile-view.js | 85 ++-- .../quality-profiles/create-profile-view.js | 144 +++--- .../quality-profiles/delete-profile-view.js | 71 ++- .../main/js/apps/quality-profiles/helpers.js | 52 +- .../js/apps/quality-profiles/intro-view.js | 13 +- .../main/js/apps/quality-profiles/layout.js | 49 +- .../profile-changelog-view.js | 71 ++- .../profile-comparison-view.js | 78 +-- .../quality-profiles/profile-details-view.js | 303 ++++++------ .../quality-profiles/profile-header-view.js | 117 +++-- .../js/apps/quality-profiles/profile-view.js | 80 +-- .../main/js/apps/quality-profiles/profile.js | 198 ++++---- .../quality-profiles/profiles-empty-view.js | 15 +- .../js/apps/quality-profiles/profiles-view.js | 109 ++-- .../main/js/apps/quality-profiles/profiles.js | 43 +- .../quality-profiles/rename-profile-view.js | 69 ++- .../restore-built-in-profiles-view.js | 96 ++-- .../quality-profiles/restore-profile-view.js | 60 ++- .../main/js/apps/quality-profiles/router.js | 70 +-- .../src/main/js/apps/source-viewer/app.js | 45 +- .../src/main/js/apps/update-center/app.js | 100 ++-- .../main/js/apps/update-center/controller.js | 48 +- .../main/js/apps/update-center/footer-view.js | 30 +- .../main/js/apps/update-center/header-view.js | 44 +- .../src/main/js/apps/update-center/layout.js | 25 +- .../js/apps/update-center/list-item-view.js | 189 ++++--- .../main/js/apps/update-center/list-view.js | 15 +- .../update-center/plugin-changelog-view.js | 47 +- .../src/main/js/apps/update-center/plugin.js | 123 ++--- .../src/main/js/apps/update-center/plugins.js | 389 ++++++++------- .../src/main/js/apps/update-center/router.js | 72 +-- .../main/js/apps/update-center/search-view.js | 164 +++---- .../sonar-web/src/main/js/apps/users/app.js | 87 ++-- .../js/apps/users/change-password-view.js | 62 ++- .../src/main/js/apps/users/create-view.js | 60 ++- .../src/main/js/apps/users/deactivate-view.js | 54 +- .../src/main/js/apps/users/form-view.js | 100 ++-- .../src/main/js/apps/users/groups-view.js | 76 ++- .../src/main/js/apps/users/header-view.js | 39 +- .../src/main/js/apps/users/layout.js | 25 +- .../main/js/apps/users/list-footer-view.js | 64 +-- .../src/main/js/apps/users/list-item-view.js | 224 ++++----- .../src/main/js/apps/users/list-view.js | 17 +- .../src/main/js/apps/users/search-view.js | 92 ++-- .../src/main/js/apps/users/update-view.js | 52 +- .../sonar-web/src/main/js/apps/users/user.js | 121 ++--- .../sonar-web/src/main/js/apps/users/users.js | 73 ++- 263 files changed, 10718 insertions(+), 11014 deletions(-) rename server/sonar-web/src/main/js/apps/custom-measures/{app.jsx => app.js} (96%) diff --git a/server/sonar-web/.eslintrc b/server/sonar-web/.eslintrc index 95ac0b44959..5f72d666f6c 100644 --- a/server/sonar-web/.eslintrc +++ b/server/sonar-web/.eslintrc @@ -187,13 +187,8 @@ "globals": { "define": true, "require": true, - "jQuery": true, - "$": true, - "_": true, "Templates": true, "Handlebars": true, - "Backbone": true, - "Marionette": true, "moment": true, "numeral": true, "key": true, diff --git a/server/sonar-web/Gruntfile.coffee b/server/sonar-web/Gruntfile.coffee index 2a35ef057db..939625d8ab0 100644 --- a/server/sonar-web/Gruntfile.coffee +++ b/server/sonar-web/Gruntfile.coffee @@ -43,7 +43,11 @@ module.exports = (grunt) -> files: [ expand: true cwd: '<%= SOURCE_PATH %>/js' - src: ['**/*.jsx'] + src: [ + '**/*.jsx' + '**/api/**/*.js' + '**/apps/**/*.js' + ] dest: '<%= BUILD_PATH %>/js' ext: '.js' ] @@ -310,11 +314,7 @@ module.exports = (grunt) -> js: files: '<%= SOURCE_PATH %>/js/**/*.js' - tasks: ['copy:js', 'concat:build', 'copy:assets-all-js'] - - jsx: - files: '<%= SOURCE_PATH %>/js/**/*.jsx' - tasks: ['babel:build', 'concat:build', 'copy:assets-all-js'] + tasks: ['copy:js', 'babel:build', 'concat:build', 'copy:assets-all-js'] handlebars: files: '<%= SOURCE_PATH %>/**/*.hbs' diff --git a/server/sonar-web/src/main/js/apps/account/app.js b/server/sonar-web/src/main/js/apps/account/app.js index 7559a916e48..0f441abacca 100644 --- a/server/sonar-web/src/main/js/apps/account/app.js +++ b/server/sonar-web/src/main/js/apps/account/app.js @@ -1,35 +1,31 @@ -define([ - './change-password-view' -], function (ChangePasswordView) { +import $ from 'jquery'; +import ChangePasswordView from './change-password-view'; - var $ = jQuery; - var shouldShowAvatars = window.SS && window.SS.lf && window.SS.lf.enableGravatar; - var favorites = $('.js-account-favorites tr'); +var shouldShowAvatars = window.SS && window.SS.lf && window.SS.lf.enableGravatar; +var favorites = $('.js-account-favorites tr'); - function showExtraFavorites () { - favorites.removeClass('hidden'); - } - - return { - start: function () { - $('html').addClass('dashboard-page'); - - if (shouldShowAvatars) { - var avatarHtml = Handlebars.helpers.avatarHelper(window.SS.userEmail, 100).string; - $('.js-avatar').html(avatarHtml); - } +function showExtraFavorites () { + favorites.removeClass('hidden'); +} - $('.js-show-all-favorites').on('click', function (e) { - e.preventDefault(); - $(e.currentTarget).hide(); - showExtraFavorites(); - }); +export default { + start: function () { + $('html').addClass('dashboard-page'); - $('#account-change-password-trigger').on('click', function (e) { - e.preventDefault(); - new ChangePasswordView().render(); - }); + if (shouldShowAvatars) { + var avatarHtml = Handlebars.helpers.avatarHelper(window.SS.userEmail, 100).string; + $('.js-avatar').html(avatarHtml); } - }; -}); + $('.js-show-all-favorites').on('click', function (e) { + e.preventDefault(); + $(e.currentTarget).hide(); + showExtraFavorites(); + }); + + $('#account-change-password-trigger').on('click', function (e) { + e.preventDefault(); + new ChangePasswordView().render(); + }); + } +}; diff --git a/server/sonar-web/src/main/js/apps/account/change-password-view.js b/server/sonar-web/src/main/js/apps/account/change-password-view.js index 86522a8dc40..e8f825f57b4 100644 --- a/server/sonar-web/src/main/js/apps/account/change-password-view.js +++ b/server/sonar-web/src/main/js/apps/account/change-password-view.js @@ -1,52 +1,47 @@ -define([ - 'components/common/modal-form', - './templates' -], function (ModalForm) { +import $ from 'jquery'; +import ModalForm from '../../components/common/modal-form'; +import './templates'; - var $ = jQuery; +export default ModalForm.extend({ + template: Templates['account-change-password'], - return ModalForm.extend({ - template: Templates['account-change-password'], - - onFormSubmit: function (e) { - this._super(e); - if (this.checkPasswords()) { - this.sendRequest(); - } else { - this.showErrors([{ msg: t('user.password_doesnt_match_confirmation') }]); - } - }, - - checkPasswords: function () { - var p1 = this.$('#password').val(), - p2 = this.$('#password_confirmation').val(); - return p1 === p2; - }, - - sendRequest: function () { - var that = this; - var data = { - login: window.SS.user, - password: this.$('#password').val(), - previousPassword: this.$('#old_password').val() - }; - var opts = { - type: 'POST', - url: baseUrl + '/api/users/change_password', - data: data, - statusCode: { - // do not show global error - 400: null - } - }; - this.disableForm(); - $.ajax(opts).done(function () { - that.destroy(); - }).fail(function (jqXHR) { - that.enableForm(); - that.showErrors(jqXHR.responseJSON.errors, jqXHR.responseJSON.warnings); - }); + onFormSubmit: function (e) { + this._super(e); + if (this.checkPasswords()) { + this.sendRequest(); + } else { + this.showErrors([{ msg: t('user.password_doesnt_match_confirmation') }]); } - }); + }, + + checkPasswords: function () { + var p1 = this.$('#password').val(), + p2 = this.$('#password_confirmation').val(); + return p1 === p2; + }, + sendRequest: function () { + var that = this; + var data = { + login: window.SS.user, + password: this.$('#password').val(), + previousPassword: this.$('#old_password').val() + }; + var opts = { + type: 'POST', + url: baseUrl + '/api/users/change_password', + data: data, + statusCode: { + // do not show global error + 400: null + } + }; + this.disableForm(); + $.ajax(opts).done(function () { + that.destroy(); + }).fail(function (jqXHR) { + that.enableForm(); + that.showErrors(jqXHR.responseJSON.errors, jqXHR.responseJSON.warnings); + }); + } }); diff --git a/server/sonar-web/src/main/js/apps/api-documentation/action-view.js b/server/sonar-web/src/main/js/apps/api-documentation/action-view.js index 8def59981b1..5ccac8c097b 100644 --- a/server/sonar-web/src/main/js/apps/api-documentation/action-view.js +++ b/server/sonar-web/src/main/js/apps/api-documentation/action-view.js @@ -1,55 +1,51 @@ -define([ - './templates' -], function () { - - var $ = jQuery; - - return Marionette.ItemView.extend({ - className: 'panel panel-vertical', - template: Templates['api-documentation-action'], - - modelEvents: { - 'change': 'render' - }, - - events: { - 'click .js-show-response-example': 'onShowResponseExampleClick', - 'click .js-hide-response-example': 'onHideResponseExampleClick' - }, - - initialize: function () { - this.listenTo(this.options.state, 'change:query', this.toggleHidden); - }, - - onRender: function () { - this.$el.attr('data-web-service', this.model.get('path')); - this.$el.attr('data-action', this.model.get('key')); - this.toggleHidden(); - }, - - onShowResponseExampleClick: function (e) { - e.preventDefault(); - this.fetchResponse(); - }, - - onHideResponseExampleClick: function (e) { - e.preventDefault(); - this.model.unset('responseExample'); - }, - - fetchResponse: function () { - var that = this, - url = baseUrl + '/api/webservices/response_example', - options = { controller: this.model.get('path'), action: this.model.get('key') }; - return $.get(url, options).done(function (r) { - that.model.set({ responseExample: r.example }); - }); - }, - - toggleHidden: function () { - var test = this.model.get('path') + '/' + this.model.get('key'); - this.$el.toggleClass('hidden', !this.options.state.match(test)); - } - }); - +import $ from 'jquery'; +import Marionette from 'backbone.marionette'; +import './templates'; + +export default Marionette.ItemView.extend({ + className: 'panel panel-vertical', + template: Templates['api-documentation-action'], + + modelEvents: { + 'change': 'render' + }, + + events: { + 'click .js-show-response-example': 'onShowResponseExampleClick', + 'click .js-hide-response-example': 'onHideResponseExampleClick' + }, + + initialize: function () { + this.listenTo(this.options.state, 'change:query', this.toggleHidden); + }, + + onRender: function () { + this.$el.attr('data-web-service', this.model.get('path')); + this.$el.attr('data-action', this.model.get('key')); + this.toggleHidden(); + }, + + onShowResponseExampleClick: function (e) { + e.preventDefault(); + this.fetchResponse(); + }, + + onHideResponseExampleClick: function (e) { + e.preventDefault(); + this.model.unset('responseExample'); + }, + + fetchResponse: function () { + var that = this, + url = baseUrl + '/api/webservices/response_example', + options = { controller: this.model.get('path'), action: this.model.get('key') }; + return $.get(url, options).done(function (r) { + that.model.set({ responseExample: r.example }); + }); + }, + + toggleHidden: function () { + var test = this.model.get('path') + '/' + this.model.get('key'); + this.$el.toggleClass('hidden', !this.options.state.match(test)); + } }); diff --git a/server/sonar-web/src/main/js/apps/api-documentation/actions-view.js b/server/sonar-web/src/main/js/apps/api-documentation/actions-view.js index 1553c648400..d316434fe61 100644 --- a/server/sonar-web/src/main/js/apps/api-documentation/actions-view.js +++ b/server/sonar-web/src/main/js/apps/api-documentation/actions-view.js @@ -1,49 +1,45 @@ -define([ - './action-view' -], function (ActionView) { +import $ from 'jquery'; +import Marionette from 'backbone.marionette'; +import ActionView from './action-view'; - var $ = jQuery; +export default Marionette.CollectionView.extend({ + childView: ActionView, - return Marionette.CollectionView.extend({ - childView: ActionView, + childViewOptions: function () { + return { + state: this.options.state + }; + }, - childViewOptions: function () { - return { - state: this.options.state - }; - }, - - scrollToTop: function () { - var parent = this.$el.scrollParent(); - if (parent.is(document)) { - parent = $(window); - } - parent.scrollTop(0); - }, - - scrollToAction: function (action) { - var model = this.collection.findWhere({ key: action }); - if (model != null) { - var view = this.children.findByModel(model); - if (view != null) { - this.scrollToView(view); - } - } - }, + scrollToTop: function () { + var parent = this.$el.scrollParent(); + if (parent.is(document)) { + parent = $(window); + } + parent.scrollTop(0); + }, - scrollToView: function (view) { - var el = view.$el, - 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 - 70; - parent.scrollTop(scrollTop); + scrollToAction: function (action) { + var model = this.collection.findWhere({ key: action }); + if (model != null) { + var view = this.children.findByModel(model); + if (view != null) { + this.scrollToView(view); } } - }); + }, + scrollToView: function (view) { + var el = view.$el, + 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 - 70; + parent.scrollTop(scrollTop); + } + } }); diff --git a/server/sonar-web/src/main/js/apps/api-documentation/app.js b/server/sonar-web/src/main/js/apps/api-documentation/app.js index 640cb0ede39..5451cde9da7 100644 --- a/server/sonar-web/src/main/js/apps/api-documentation/app.js +++ b/server/sonar-web/src/main/js/apps/api-documentation/app.js @@ -1,71 +1,69 @@ -define([ - './router', - './controller', - './layout', - './list', - './list-view', - './filters-view', - './search-view' -], function (Router, Controller, Layout, List, ListView, FiltersView, SearchView) { +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 List from './list'; +import ListView from './list-view'; +import FiltersView from './filters-view'; +import SearchView from './search-view'; - var $ = jQuery, - App = new Marionette.Application(), - init = function (options) { - // State - this.state = new Backbone.Model({ internal: false }); - this.state.match = function (test) { - var pattern = new RegExp(this.get('query'), 'i'); - return test.search(pattern) !== -1; - }; +var App = new Marionette.Application(), + init = function (options) { + // State + this.state = new Backbone.Model({ internal: false }); + this.state.match = function (test) { + var pattern = new RegExp(this.get('query'), 'i'); + return test.search(pattern) !== -1; + }; - // Layout - this.layout = new Layout({ el: options.el }); - this.layout.render(); - $('#footer').addClass('search-navigator-footer'); + // Layout + this.layout = new Layout({ el: options.el }); + this.layout.render(); + $('#footer').addClass('search-navigator-footer'); - // Web Services List - this.list = new List(); + // Web Services List + this.list = new List(); - // Controller - this.controller = new Controller({ - app: this, - state: this.state - }); + // Controller + this.controller = new Controller({ + app: this, + state: this.state + }); - // List View - this.listView = new ListView({ - collection: this.list, - state: this.state - }); - this.layout.resultsRegion.show(this.listView); + // List View + this.listView = new ListView({ + collection: this.list, + state: this.state + }); + this.layout.resultsRegion.show(this.listView); - // Filters View - this.filtersView = new FiltersView({ - collection: this.list, - state: this.state - }); - this.layout.actionsRegion.show(this.filtersView); + // Filters View + this.filtersView = new FiltersView({ + collection: this.list, + state: this.state + }); + this.layout.actionsRegion.show(this.filtersView); - // Search View - this.searchView = new SearchView({ - state: this.state - }); - this.layout.searchRegion.show(this.searchView); + // Search View + this.searchView = new SearchView({ + state: this.state + }); + this.layout.searchRegion.show(this.searchView); - // Router - this.router = new Router({ app: this }); - Backbone.history.start({ - pushState: true, - root: options.urlRoot - }); - }; + // Router + this.router = new Router({ app: this }); + Backbone.history.start({ + pushState: true, + root: options.urlRoot + }); + }; - App.on('start', function (options) { - window.requestMessages().done(function () { - init.call(App, options); - }); +App.on('start', function (options) { + window.requestMessages().done(function () { + init.call(App, options); }); - - return App; - }); + +export default App; diff --git a/server/sonar-web/src/main/js/apps/api-documentation/controller.js b/server/sonar-web/src/main/js/apps/api-documentation/controller.js index 9e0738b9de8..1d668e2d46f 100644 --- a/server/sonar-web/src/main/js/apps/api-documentation/controller.js +++ b/server/sonar-web/src/main/js/apps/api-documentation/controller.js @@ -1,77 +1,74 @@ -define([ - './actions-view', - './header-view' -], function (ActionsView, HeaderView) { +import _ from 'underscore'; +import Backbone from 'backbone'; +import Marionette from 'backbone.marionette'; +import ActionsView from './actions-view'; +import HeaderView from './header-view'; - return Marionette.Controller.extend({ +export default Marionette.Controller.extend({ + initialize: function (options) { + this.list = options.app.list; + this.listenTo(this.list, 'select', this.onItemSelect); + }, - initialize: function (options) { - this.list = options.app.list; - this.listenTo(this.list, 'select', this.onItemSelect); - }, - - show: function (path) { - var that = this; - this.fetchList().done(function () { - if (path) { - var item = that.list.findWhere({ path: path }); - if (item != null) { - that.showWebService(path); - } else { - that.showAction(path); - } + show: function (path) { + var that = this; + this.fetchList().done(function () { + if (path) { + var item = that.list.findWhere({ path: path }); + if (item != null) { + that.showWebService(path); + } else { + that.showAction(path); } - }); - }, - - showWebService: function (path) { - var item = this.list.findWhere({ path: path }); - if (item != null) { - item.trigger('select', item); } - }, + }); + }, - showAction: function (path) { - var webService = this.list.find(function (item) { - return path.indexOf(item.get('path')) === 0; - }); - if (webService != null) { - var action = path.substr(webService.get('path').length + 1); - webService.trigger('select', webService, { trigger: false, action: action }); - } - }, + showWebService: function (path) { + var item = this.list.findWhere({ path: path }); + if (item != null) { + item.trigger('select', item); + } + }, - onItemSelect: function (item, options) { - var path = item.get('path'), - opts = _.defaults(options || {}, { trigger: true }); - if (opts.trigger) { - this.options.app.router.navigate(path); - } - this.options.app.listView.highlight(path); + showAction: function (path) { + var webService = this.list.find(function (item) { + return path.indexOf(item.get('path')) === 0; + }); + if (webService != null) { + var action = path.substr(webService.get('path').length + 1); + webService.trigger('select', webService, { trigger: false, action: action }); + } + }, - if (item.get('internal')) { - this.options.state.set({ internal: true }); - } + onItemSelect: function (item, options) { + var path = item.get('path'), + opts = _.defaults(options || {}, { trigger: true }); + if (opts.trigger) { + this.options.app.router.navigate(path); + } + this.options.app.listView.highlight(path); - var actions = new Backbone.Collection(item.get('actions')), - actionsView = new ActionsView({ - collection: actions, - state: this.options.state - }); - this.options.app.layout.detailsRegion.show(actionsView); - this.options.app.layout.headerRegion.show(new HeaderView({ model: item })); + if (item.get('internal')) { + this.options.state.set({ internal: true }); + } - if (opts.action != null) { - actionsView.scrollToAction(opts.action); - } else { - actionsView.scrollToTop(); - } - }, + var actions = new Backbone.Collection(item.get('actions')), + actionsView = new ActionsView({ + collection: actions, + state: this.options.state + }); + this.options.app.layout.detailsRegion.show(actionsView); + this.options.app.layout.headerRegion.show(new HeaderView({ model: item })); - fetchList: function () { - return this.list.fetch({ data: { 'include_internals': true } }); + if (opts.action != null) { + actionsView.scrollToAction(opts.action); + } else { + actionsView.scrollToTop(); } + }, - }); - + fetchList: function () { + return this.list.fetch({ data: { 'include_internals': true } }); + } }); diff --git a/server/sonar-web/src/main/js/apps/api-documentation/filters-view.js b/server/sonar-web/src/main/js/apps/api-documentation/filters-view.js index 3511e704b94..aa54b532f2b 100644 --- a/server/sonar-web/src/main/js/apps/api-documentation/filters-view.js +++ b/server/sonar-web/src/main/js/apps/api-documentation/filters-view.js @@ -1,27 +1,27 @@ -define([ - './templates' -], function () { +import _ from 'underscore'; +import Marionette from 'backbone.marionette'; +import './templates'; - return Marionette.ItemView.extend({ - template: Templates['api-documentation-filters'], +export default Marionette.ItemView.extend({ + template: Templates['api-documentation-filters'], - events: { - 'change .js-toggle-internal': 'toggleInternal' - }, + events: { + 'change .js-toggle-internal': 'toggleInternal' + }, - initialize: function () { - this.listenTo(this.options.state, 'change:internal', this.render); - }, + initialize: function () { + this.listenTo(this.options.state, 'change:internal', this.render); + }, - toggleInternal: function () { - this.options.state.set({ internal: !this.options.state.get('internal')}); - }, - - serializeData: function () { - return _.extend(Marionette.ItemView.prototype.serializeData.apply(this, arguments), { - state: this.options.state.toJSON() - }); - } - }); + toggleInternal: function () { + this.options.state.set({ internal: !this.options.state.get('internal') }); + }, + serializeData: function () { + return _.extend(Marionette.ItemView.prototype.serializeData.apply(this, arguments), { + state: this.options.state.toJSON() + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/api-documentation/header-view.js b/server/sonar-web/src/main/js/apps/api-documentation/header-view.js index a880fa4f2dc..818ccfdde47 100644 --- a/server/sonar-web/src/main/js/apps/api-documentation/header-view.js +++ b/server/sonar-web/src/main/js/apps/api-documentation/header-view.js @@ -1,13 +1,12 @@ -define([ - './templates' -], function () { +import Marionette from 'backbone.marionette'; +import './templates'; - return Marionette.ItemView.extend({ - template: Templates['api-documentation-header'], - - modelEvents: { - 'change': 'render' - } - }); +export default Marionette.ItemView.extend({ + template: Templates['api-documentation-header'], + modelEvents: { + 'change': 'render' + } }); + + diff --git a/server/sonar-web/src/main/js/apps/api-documentation/item-view.js b/server/sonar-web/src/main/js/apps/api-documentation/item-view.js index 9649989d915..b23ffff12ff 100644 --- a/server/sonar-web/src/main/js/apps/api-documentation/item-view.js +++ b/server/sonar-web/src/main/js/apps/api-documentation/item-view.js @@ -1,52 +1,52 @@ -define([ - './templates' -], function () { - - return Marionette.ItemView.extend({ - tagName: 'a', - className: 'list-group-item', - template: Templates['api-documentation-web-service'], - - modelEvents: { - 'change': 'render' - }, - - events: { - 'click': 'onClick' - }, - - initialize: function () { - this.listenTo(this.options.state, 'change:query', this.toggleHidden); - this.listenTo(this.options.state, 'change:internal', this.toggleHidden); - }, - - shouldBeHidden: function () { - var that = this; - var match = this.options.state.match(this.model.get('path')) || - _.some(this.model.get('actions'), function (action) { - var test = action.path + '/' + action.key; - return that.options.state.match(test); - }); - - var showInternal = this.options.state.get('internal'), - hideMe = this.model.get('internal') && !showInternal; - return !match || hideMe; - }, - - onRender: function () { - this.$el.attr('data-path', this.model.get('path')); - this.$el.toggleClass('active', this.options.highlighted); - this.toggleHidden(); - }, - - onClick: function (e) { - e.preventDefault(); - this.model.trigger('select', this.model); - }, - - toggleHidden: function () { - this.$el.toggleClass('hidden', this.shouldBeHidden()); - } - }); - +import _ from 'underscore'; +import Marionette from 'backbone.marionette'; +import './templates'; + +export default Marionette.ItemView.extend({ + tagName: 'a', + className: 'list-group-item', + template: Templates['api-documentation-web-service'], + + modelEvents: { + 'change': 'render' + }, + + events: { + 'click': 'onClick' + }, + + initialize: function () { + this.listenTo(this.options.state, 'change:query', this.toggleHidden); + this.listenTo(this.options.state, 'change:internal', this.toggleHidden); + }, + + shouldBeHidden: function () { + var that = this; + var match = this.options.state.match(this.model.get('path')) || + _.some(this.model.get('actions'), function (action) { + var test = action.path + '/' + action.key; + return that.options.state.match(test); + }); + + var showInternal = this.options.state.get('internal'), + hideMe = this.model.get('internal') && !showInternal; + return !match || hideMe; + }, + + onRender: function () { + this.$el.attr('data-path', this.model.get('path')); + this.$el.toggleClass('active', this.options.highlighted); + this.toggleHidden(); + }, + + onClick: function (e) { + e.preventDefault(); + this.model.trigger('select', this.model); + }, + + toggleHidden: function () { + this.$el.toggleClass('hidden', this.shouldBeHidden()); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/api-documentation/layout.js b/server/sonar-web/src/main/js/apps/api-documentation/layout.js index ac46b9c1bc6..229b48ec560 100644 --- a/server/sonar-web/src/main/js/apps/api-documentation/layout.js +++ b/server/sonar-web/src/main/js/apps/api-documentation/layout.js @@ -1,25 +1,24 @@ -define([ - './templates' -], function () { +import Marionette from 'backbone.marionette'; +import './templates'; - return Marionette.LayoutView.extend({ - template: Templates['api-documentation-layout'], +export default Marionette.LayoutView.extend({ + template: Templates['api-documentation-layout'], - regions: { - headerRegion: '.search-navigator-workspace-header', - actionsRegion: '.search-navigator-filters', - searchRegion: '.api-documentation-search', - resultsRegion: '.api-documentation-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(); - } - }); + regions: { + headerRegion: '.search-navigator-workspace-header', + actionsRegion: '.search-navigator-filters', + searchRegion: '.api-documentation-search', + resultsRegion: '.api-documentation-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(); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/api-documentation/list-view.js b/server/sonar-web/src/main/js/apps/api-documentation/list-view.js index c953c4fcab1..2360ebf707a 100644 --- a/server/sonar-web/src/main/js/apps/api-documentation/list-view.js +++ b/server/sonar-web/src/main/js/apps/api-documentation/list-view.js @@ -1,23 +1,22 @@ -define([ - './item-view' -], function (ItemView) { +import Marionette from 'backbone.marionette'; +import ItemView from './item-view'; - return Marionette.CollectionView.extend({ - className: 'list-group', - childView: ItemView, +export default Marionette.CollectionView.extend({ + className: 'list-group', + childView: ItemView, - childViewOptions: function (model) { - return { - collectionView: this, - highlighted: model.get('path') === this.highlighted, - state: this.options.state - }; - }, - - highlight: function (path) { - this.highlighted = path; - this.render(); - } - }); + childViewOptions: function (model) { + return { + collectionView: this, + highlighted: model.get('path') === this.highlighted, + state: this.options.state + }; + }, + highlight: function (path) { + this.highlighted = path; + this.render(); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/api-documentation/list.js b/server/sonar-web/src/main/js/apps/api-documentation/list.js index 1ac6c325d08..dcb5823f809 100644 --- a/server/sonar-web/src/main/js/apps/api-documentation/list.js +++ b/server/sonar-web/src/main/js/apps/api-documentation/list.js @@ -1,23 +1,24 @@ -define(function () { +import _ from 'underscore'; +import Backbone from 'backbone'; - return Backbone.Collection.extend({ - url: baseUrl + '/api/webservices/list', - comparator: 'path', +export default Backbone.Collection.extend({ + url: baseUrl + '/api/webservices/list', + comparator: 'path', - parse: function (r) { - return r.webServices.map(function (webService) { - var internal = _.every(webService.actions, function (action) { - return action.internal; - }), - actions = webService.actions.map(function (action) { - return _.extend(action, { path: webService.path }); - }); - return _.extend(webService, { - internal: internal, - actions: actions - }); + parse: function (r) { + return r.webServices.map(function (webService) { + var internal = _.every(webService.actions, function (action) { + return action.internal; + }), + actions = webService.actions.map(function (action) { + return _.extend(action, { path: webService.path }); + }); + return _.extend(webService, { + internal: internal, + actions: actions }); - } - }); - + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/api-documentation/router.js b/server/sonar-web/src/main/js/apps/api-documentation/router.js index b187022a6bb..f84f4394d8c 100644 --- a/server/sonar-web/src/main/js/apps/api-documentation/router.js +++ b/server/sonar-web/src/main/js/apps/api-documentation/router.js @@ -1,18 +1,17 @@ -define(function () { +import Backbone from 'backbone'; - return Backbone.Router.extend({ +export default Backbone.Router.extend({ + routes: { + '*path': 'show' + }, - routes: { - '*path': 'show' - }, + initialize: function (options) { + this.app = options.app; + }, - initialize: function (options) { - this.app = options.app; - }, + show: function (path) { + this.app.controller.show(path); + } +}); - show: function (path) { - this.app.controller.show(path); - } - }); -}); diff --git a/server/sonar-web/src/main/js/apps/api-documentation/search-view.js b/server/sonar-web/src/main/js/apps/api-documentation/search-view.js index a24d9390bb2..1635d8a2abf 100644 --- a/server/sonar-web/src/main/js/apps/api-documentation/search-view.js +++ b/server/sonar-web/src/main/js/apps/api-documentation/search-view.js @@ -1,36 +1,36 @@ -define([ - './templates' -], function () { - - return Marionette.ItemView.extend({ - template: Templates['api-documentation-search'], - - ui: { - input: '.search-box-input' - }, - - events: { - 'keyup @ui.input': 'onChange', - 'search @ui.input': 'onChange' - }, - - initialize: function () { - this.query = ''; - this.debouncedFilter = _.debounce(this.filter, 250); - }, - - onChange: function () { - var query = this.ui.input.val(); - if (query === this.query) { - return; - } - this.query = this.ui.input.val(); - this.debouncedFilter(query); - }, - - filter: function (query) { - this.options.state.set({ query: query }); +import _ from 'underscore'; +import Marionette from 'backbone.marionette'; +import './templates'; + +export default Marionette.ItemView.extend({ + template: Templates['api-documentation-search'], + + ui: { + input: '.search-box-input' + }, + + events: { + 'keyup @ui.input': 'onChange', + 'search @ui.input': 'onChange' + }, + + initialize: function () { + this.query = ''; + this.debouncedFilter = _.debounce(this.filter, 250); + }, + + onChange: function () { + var query = this.ui.input.val(); + if (query === this.query) { + return; } - }); + this.query = this.ui.input.val(); + this.debouncedFilter(query); + }, + filter: function (query) { + this.options.state.set({ query: query }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/coding-rules/app.js b/server/sonar-web/src/main/js/apps/coding-rules/app.js index 61f5e97ddd2..e1e53516f05 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/app.js +++ b/server/sonar-web/src/main/js/apps/coding-rules/app.js @@ -1,114 +1,100 @@ -define([ - './models/state', - './layout', - './models/rules', - 'components/navigator/models/facets', - - './controller', - 'components/navigator/router', - - './workspace-list-view', - './workspace-header-view', - - './facets-view', - './filters-view' - ], - function (State, - Layout, - Rules, - Facets, - Controller, - Router, - WorkspaceListView, - WorkspaceHeaderView, - FacetsView, - FiltersView) { - - var $ = jQuery, - App = new Marionette.Application(), - init = function (options) { - this.layout = new Layout({ el: options.el }); - this.layout.render(); - $('#footer').addClass('search-navigator-footer'); - - this.state = new State(); - this.list = new Rules(); - this.facets = new Facets(); - - this.controller = new Controller({ app: this }); - - this.workspaceListView = new WorkspaceListView({ - app: this, - collection: this.list - }); - this.layout.workspaceListRegion.show(this.workspaceListView); - this.workspaceListView.bindScrollEvents(); - - this.workspaceHeaderView = new WorkspaceHeaderView({ - app: this, - collection: this.list - }); - this.layout.workspaceHeaderRegion.show(this.workspaceHeaderView); - - this.facetsView = new FacetsView({ - app: this, - collection: this.facets - }); - this.layout.facetsRegion.show(this.facetsView); - - this.filtersView = new FiltersView({ - app: this - }); - this.layout.filtersRegion.show(this.filtersView); - - key.setScope('list'); - this.router = new Router({ - app: this - }); - Backbone.history.start(); - }; - - App.manualRepository = function () { - return { - key: 'manual', - name: t('coding_rules.manual_rule'), - language: 'none' - }; - }; - - App.getSubCharacteristicName = function (key) { - if (key != null) { - var ch = _.findWhere(App.characteristics, { key: key }), - parent = _.findWhere(App.characteristics, { key: ch.parent }); - return [parent.name, ch.name].join(' > '); - } else { - return null; - } - }; +import $ from 'jquery'; +import _ from 'underscore'; +import Backbone from 'backbone'; +import Marionette from 'backbone.marionette'; +import State from './models/state'; +import Layout from './layout'; +import Rules from './models/rules'; +import Facets from 'components/navigator/models/facets'; +import Controller from './controller'; +import Router from 'components/navigator/router'; +import WorkspaceListView from './workspace-list-view'; +import WorkspaceHeaderView from './workspace-header-view'; +import FacetsView from './facets-view'; +import FiltersView from './filters-view'; + +var App = new Marionette.Application(), + init = function (options) { + this.layout = new Layout({ el: options.el }); + this.layout.render(); + $('#footer').addClass('search-navigator-footer'); + + this.state = new State(); + this.list = new Rules(); + this.facets = new Facets(); + + this.controller = new Controller({ app: this }); + + this.workspaceListView = new WorkspaceListView({ + app: this, + collection: this.list + }); + this.layout.workspaceListRegion.show(this.workspaceListView); + this.workspaceListView.bindScrollEvents(); - var appXHR = $.get(baseUrl + '/api/rules/app').done(function (r) { - App.canWrite = r.canWrite; - App.qualityProfiles = _.sortBy(r.qualityprofiles, ['name', 'lang']); - App.languages = _.extend(r.languages, { - none: 'None' - }); - _.map(App.qualityProfiles, function (profile) { - profile.language = App.languages[profile.lang]; - }); - App.repositories = r.repositories; - App.repositories.push(App.manualRepository()); - App.statuses = r.statuses; - App.characteristics = r.characteristics.map(function (item, index) { - return _.extend(item, { index: index }); - }); + this.workspaceHeaderView = new WorkspaceHeaderView({ + app: this, + collection: this.list }); + this.layout.workspaceHeaderRegion.show(this.workspaceHeaderView); - App.on('start', function (options) { - $.when(window.requestMessages(), appXHR).done(function () { - init.call(App, options); - }); + this.facetsView = new FacetsView({ + app: this, + collection: this.facets }); + this.layout.facetsRegion.show(this.facetsView); - return App; + this.filtersView = new FiltersView({ + app: this + }); + this.layout.filtersRegion.show(this.filtersView); - }); + key.setScope('list'); + this.router = new Router({ + app: this + }); + Backbone.history.start(); + }; + +App.manualRepository = function () { + return { + key: 'manual', + name: t('coding_rules.manual_rule'), + language: 'none' + }; +}; + +App.getSubCharacteristicName = function (key) { + if (key != null) { + var ch = _.findWhere(App.characteristics, { key: key }), + parent = _.findWhere(App.characteristics, { key: ch.parent }); + return [parent.name, ch.name].join(' > '); + } else { + return null; + } +}; + +var appXHR = $.get(baseUrl + '/api/rules/app').done(function (r) { + App.canWrite = r.canWrite; + App.qualityProfiles = _.sortBy(r.qualityprofiles, ['name', 'lang']); + App.languages = _.extend(r.languages, { + none: 'None' + }); + _.map(App.qualityProfiles, function (profile) { + profile.language = App.languages[profile.lang]; + }); + App.repositories = r.repositories; + App.repositories.push(App.manualRepository()); + App.statuses = r.statuses; + App.characteristics = r.characteristics.map(function (item, index) { + return _.extend(item, { index: index }); + }); +}); + +App.on('start', function (options) { + $.when(window.requestMessages(), appXHR).done(function () { + init.call(App, options); + }); +}); + +export default App; 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 4bd38a5425c..76e193d8f33 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 @@ -1,97 +1,95 @@ -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['coding-rules-bulk-change-modal'], - return ModalFormView.extend({ - template: Templates['coding-rules-bulk-change-modal'], + ui: function () { + return _.extend(ModalFormView.prototype.ui.apply(this, arguments), { + codingRulesSubmitBulkChange: '#coding-rules-submit-bulk-change' + }); + }, - ui: function () { - return _.extend(ModalFormView.prototype.ui.apply(this, arguments), { - codingRulesSubmitBulkChange: '#coding-rules-submit-bulk-change' - }); - }, - - showSuccessMessage: function (profile, succeeded) { - var profileBase = _.findWhere(this.options.app.qualityProfiles, { key: profile }), - profileName = profileBase != null ? profileBase.name : profile, - message = tp('coding_rules.bulk_change.success', profileName, profileBase.language, succeeded); - this.ui.messagesContainer.append('
' + message + '
'); - }, + showSuccessMessage: function (profile, succeeded) { + var profileBase = _.findWhere(this.options.app.qualityProfiles, { key: profile }), + profileName = profileBase != null ? profileBase.name : profile, + message = tp('coding_rules.bulk_change.success', profileName, profileBase.language, succeeded); + this.ui.messagesContainer.append('
' + message + '
'); + }, - showWarnMessage: function (profile, succeeded, failed) { - var profileBase = _.findWhere(this.options.app.qualityProfiles, { key: profile }), - profileName = profileBase != null ? profileBase.name : profile, - message = tp('coding_rules.bulk_change.warning', profileName, profileBase.language, succeeded, failed); - this.ui.messagesContainer.append('
' + message + '
'); - }, + showWarnMessage: function (profile, succeeded, failed) { + var profileBase = _.findWhere(this.options.app.qualityProfiles, { key: profile }), + profileName = profileBase != null ? profileBase.name : profile, + message = tp('coding_rules.bulk_change.warning', profileName, profileBase.language, succeeded, failed); + this.ui.messagesContainer.append('
' + message + '
'); + }, - onRender: function () { - ModalFormView.prototype.onRender.apply(this, arguments); - this.$('#coding-rules-bulk-change-profile').select2({ - width: '250px', - minimumResultsForSearch: 1, - openOnEnter: false - }); - }, + onRender: function () { + ModalFormView.prototype.onRender.apply(this, arguments); + this.$('#coding-rules-bulk-change-profile').select2({ + width: '250px', + minimumResultsForSearch: 1, + openOnEnter: false + }); + }, - onFormSubmit: function () { - ModalFormView.prototype.onFormSubmit.apply(this, arguments); - var url = baseUrl + '/api/qualityprofiles/' + this.options.action + '_rules', - options = _.extend({}, this.options.app.state.get('query'), { wsAction: this.options.action }), - profiles = this.$('#coding-rules-bulk-change-profile').val() || [this.options.param]; - this.ui.messagesContainer.empty(); - this.sendRequests(url, options, profiles); - }, + onFormSubmit: function () { + ModalFormView.prototype.onFormSubmit.apply(this, arguments); + var url = baseUrl + '/api/qualityprofiles/' + this.options.action + '_rules', + options = _.extend({}, this.options.app.state.get('query'), { wsAction: this.options.action }), + profiles = this.$('#coding-rules-bulk-change-profile').val() || [this.options.param]; + this.ui.messagesContainer.empty(); + this.sendRequests(url, options, profiles); + }, - sendRequests: function (url, options, profiles) { - var that = this, - looper = $.Deferred().resolve(); - profiles.forEach(function (profile) { - var opts = _.extend({}, options, { profile_key: profile }); - looper = looper.then(function () { - return $.post(url, opts).done(function (r) { - if (r.failed) { - that.showWarnMessage(profile, r.succeeded, r.failed); - } else { - that.showSuccessMessage(profile, r.succeeded); - } - }); + sendRequests: function (url, options, profiles) { + var that = this, + looper = $.Deferred().resolve(); + profiles.forEach(function (profile) { + var opts = _.extend({}, options, { profile_key: profile }); + looper = looper.then(function () { + return $.post(url, opts).done(function (r) { + if (r.failed) { + that.showWarnMessage(profile, r.succeeded, r.failed); + } else { + that.showSuccessMessage(profile, r.succeeded); + } }); }); - looper.done(function () { - that.options.app.controller.fetchList(); - that.$(that.ui.codingRulesSubmitBulkChange.selector).hide(); - that.$('.modal-field').hide(); - that.$('.js-modal-close').focus(); - }); - }, + }); + looper.done(function () { + that.options.app.controller.fetchList(); + that.$(that.ui.codingRulesSubmitBulkChange.selector).hide(); + that.$('.modal-field').hide(); + that.$('.js-modal-close').focus(); + }); + }, - getAvailableQualityProfiles: function () { - var queryLanguages = this.options.app.state.get('query').languages, - languages = queryLanguages && queryLanguages.length > 0 ? queryLanguages.split(',') : [], - profiles = this.options.app.qualityProfiles; - if (languages.length > 0) { - profiles = _.filter(profiles, function (profile) { - return languages.indexOf(profile.lang) !== -1; - }); - } - return profiles; - }, - - serializeData: function () { - var profile = _.findWhere(this.options.app.qualityProfiles, { key: this.options.param }); - return _.extend(ModalFormView.prototype.serializeData.apply(this, arguments), { - action: this.options.action, - state: this.options.app.state.toJSON(), - qualityProfile: this.options.param, - qualityProfileName: profile != null ? profile.name : null, - qualityProfiles: this.options.app.qualityProfiles, - availableQualityProfiles: this.getAvailableQualityProfiles() + getAvailableQualityProfiles: function () { + var queryLanguages = this.options.app.state.get('query').languages, + languages = queryLanguages && queryLanguages.length > 0 ? queryLanguages.split(',') : [], + profiles = this.options.app.qualityProfiles; + if (languages.length > 0) { + profiles = _.filter(profiles, function (profile) { + return languages.indexOf(profile.lang) !== -1; }); } - }); + return profiles; + }, + serializeData: function () { + var profile = _.findWhere(this.options.app.qualityProfiles, { key: this.options.param }); + return _.extend(ModalFormView.prototype.serializeData.apply(this, arguments), { + action: this.options.action, + state: this.options.app.state.toJSON(), + qualityProfile: this.options.param, + qualityProfileName: profile != null ? profile.name : null, + qualityProfiles: this.options.app.qualityProfiles, + availableQualityProfiles: this.getAvailableQualityProfiles() + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/coding-rules/bulk-change-popup-view.js b/server/sonar-web/src/main/js/apps/coding-rules/bulk-change-popup-view.js index 9dab485f22e..6d6268f3ef6 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/bulk-change-popup-view.js +++ b/server/sonar-web/src/main/js/apps/coding-rules/bulk-change-popup-view.js @@ -1,41 +1,39 @@ -define([ - 'components/common/popup', - './bulk-change-modal-view', - './templates' -], function (PopupView, BulkChangeModalView) { +import $ from 'jquery'; +import _ from 'underscore'; +import PopupView from 'components/common/popup'; +import BulkChangeModalView from './bulk-change-modal-view'; +import './templates'; - var $ = jQuery; +export default PopupView.extend({ + template: Templates['coding-rules-bulk-change-popup'], - return PopupView.extend({ - template: Templates['coding-rules-bulk-change-popup'], + events: { + 'click .js-bulk-change': 'doAction' + }, - events: { - 'click .js-bulk-change': 'doAction' - }, + doAction: function (e) { + var action = $(e.currentTarget).data('action'), + param = $(e.currentTarget).data('param'); + new BulkChangeModalView({ + app: this.options.app, + action: action, + param: param + }).render(); + }, - doAction: function (e) { - var action = $(e.currentTarget).data('action'), - param = $(e.currentTarget).data('param'); - new BulkChangeModalView({ - app: this.options.app, - action: action, - param: param - }).render(); - }, + serializeData: function () { + var query = this.options.app.state.get('query'), + profileKey = query.qprofile, + profile = _.findWhere(this.options.app.qualityProfiles, { key: profileKey }), + activation = '' + query.activation; - serializeData: function () { - var query = this.options.app.state.get('query'), - profileKey = query.qprofile, - profile = _.findWhere(this.options.app.qualityProfiles, { key: profileKey }), - activation = '' + query.activation; + return { + qualityProfile: profileKey, + qualityProfileName: profile != null ? profile.name : null, + allowActivateOnProfile: profileKey != null && activation === 'false', + allowDeactivateOnProfile: profileKey != null && activation === 'true' + }; + } +}); - return { - qualityProfile: profileKey, - qualityProfileName: profile != null ? profile.name : null, - allowActivateOnProfile: profileKey != null && activation === 'false', - allowDeactivateOnProfile: profileKey != null && activation === 'true' - }; - } - }); -}); 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 dabd4a0b166..dad6224391a 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 @@ -1,156 +1,156 @@ -define([ - 'components/navigator/controller', - './models/rule', - './rule-details-view' -], function (Controller, Rule, RuleDetailsView) { - - var $ = jQuery; - - return Controller.extend({ - pageSize: 200, - ruleFields: ['name', 'lang', 'langName', 'sysTags', 'tags', 'status', 'severity', - 'debtChar', 'debtCharName', 'debtSubChar', 'debtSubCharName'], - - - _searchParameters: function () { - var fields = this.ruleFields.slice(), - profile = this.app.state.get('query').qprofile; - if (profile != null) { - fields.push('actives'); - fields.push('params'); - fields.push('isTemplate'); - fields.push('severity'); - } - var params = { - p: this.app.state.get('page'), - ps: this.pageSize, - facets: this._facetsFromServer().join(), - f: fields.join() - }; - if (this.app.state.get('query').q == null) { - _.extend(params, { s: 'name', asc: true }); - } - return params; - }, +import $ from 'jquery'; +import _ from 'underscore'; +import Controller from 'components/navigator/controller'; +import Rule from './models/rule'; +import RuleDetailsView from './rule-details-view'; + +export default Controller.extend({ + pageSize: 200, + ruleFields: [ + 'name', 'lang', 'langName', 'sysTags', 'tags', 'status', 'severity', + 'debtChar', 'debtCharName', 'debtSubChar', 'debtSubCharName' + ], + + + _searchParameters: function () { + var fields = this.ruleFields.slice(), + profile = this.app.state.get('query').qprofile; + if (profile != null) { + fields.push('actives'); + fields.push('params'); + fields.push('isTemplate'); + fields.push('severity'); + } + var params = { + p: this.app.state.get('page'), + ps: this.pageSize, + facets: this._facetsFromServer().join(), + f: fields.join() + }; + if (this.app.state.get('query').q == null) { + _.extend(params, { s: 'name', asc: true }); + } + return params; + }, - fetchList: function (firstPage) { - firstPage = firstPage == null ? true : firstPage; + fetchList: function (firstPage) { + firstPage = firstPage == null ? true : firstPage; + if (firstPage) { + this.app.state.set({ selectedIndex: 0, page: 1 }, { silent: true }); + } + + this.hideDetails(firstPage); + + var that = this, + url = baseUrl + '/api/rules/search', + options = _.extend(this._searchParameters(), this.app.state.get('query')); + return $.get(url, options).done(function (r) { + var rules = that.app.list.parseRules(r); if (firstPage) { - this.app.state.set({ selectedIndex: 0, page: 1 }, { silent: true }); + that.app.list.reset(rules); + } else { + that.app.list.add(rules); } - - this.hideDetails(firstPage); - - var that = this, - url = baseUrl + '/api/rules/search', - options = _.extend(this._searchParameters(), this.app.state.get('query')); - return $.get(url, options).done(function (r) { - var rules = that.app.list.parseRules(r); - if (firstPage) { - that.app.list.reset(rules); - } else { - that.app.list.add(rules); - } - that.app.list.setIndex(); - that.app.list.addExtraAttributes(that.app.languages, 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({ - 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()); - } - }); - }, - - isRulePermalink: function () { - var query = this.app.state.get('query'); - return query.rule_key != null && this.app.list.length === 1; - }, - - requestFacet: function (id) { - var url = baseUrl + '/api/rules/search', - facet = this.app.facets.get(id), - options = _.extend({ facets: id, ps: 1 }, this.app.state.get('query')); - return $.get(url, options).done(function (r) { - var facetData = _.findWhere(r.facets, { property: id }); - if (facetData) { - facet.set(facetData); - } + that.app.list.setIndex(); + that.app.list.addExtraAttributes(that.app.languages, 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({ + page: r.p, + pageSize: r.ps, + total: r.total, + maxResultsReached: r.p * r.ps >= r.total }); - }, - - parseQuery: function () { - var q = Controller.prototype.parseQuery.apply(this, arguments); - delete q.asc; - delete q.s; - return q; - }, - - getRuleDetails: function (rule) { - var that = this, - url = baseUrl + '/api/rules/show', - options = { - key: rule.id, - actives: true - }; - return $.get(url, options).done(function (data) { - rule.set(data.rule); - rule.addExtraAttributes(that.app.repositories); - }); - }, - - showDetails: function (rule) { - var that = this, - ruleModel = typeof rule === 'string' ? new Rule({ key: rule }) : rule; - this.app.layout.workspaceDetailsRegion.reset(); - this.getRuleDetails(ruleModel).done(function (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); - }); - }, - - showDetailsForSelected: function () { - var rule = this.app.list.at(this.app.state.get('selectedIndex')); - this.showDetails(rule); - }, - - hideDetails: function (firstPage) { - key.setScope('list'); - this.app.state.unset('rule'); - this.app.layout.workspaceDetailsRegion.reset(); - this.app.layout.hideDetails(); - this.app.workspaceListView.bindScrollEvents(); - if (firstPage) { - this.app.workspaceListView.scrollTo(); + if (firstPage && that.isRulePermalink()) { + that.showDetails(that.app.list.first()); + } + }); + }, + + isRulePermalink: function () { + var query = this.app.state.get('query'); + return query.rule_key != null && this.app.list.length === 1; + }, + + requestFacet: function (id) { + var url = baseUrl + '/api/rules/search', + facet = this.app.facets.get(id), + options = _.extend({ facets: id, ps: 1 }, this.app.state.get('query')); + return $.get(url, options).done(function (r) { + var facetData = _.findWhere(r.facets, { property: id }); + if (facetData) { + facet.set(facetData); } - }, - - activateCurrent: function () { - var rule = this.app.list.at(this.app.state.get('selectedIndex')); - var ruleView = this.app.workspaceListView.children.findByModel(rule); - ruleView.$('.coding-rules-detail-quality-profile-activate').click(); - }, - - deactivateCurrent: function () { - var rule = this.app.list.at(this.app.state.get('selectedIndex')); - var ruleView = this.app.workspaceListView.children.findByModel(rule); - ruleView.$('.coding-rules-detail-quality-profile-deactivate').click(); + }); + }, + + parseQuery: function () { + var q = Controller.prototype.parseQuery.apply(this, arguments); + delete q.asc; + delete q.s; + return q; + }, + + getRuleDetails: function (rule) { + var that = this, + url = baseUrl + '/api/rules/show', + options = { + key: rule.id, + actives: true + }; + return $.get(url, options).done(function (data) { + rule.set(data.rule); + rule.addExtraAttributes(that.app.repositories); + }); + }, + + showDetails: function (rule) { + var that = this, + ruleModel = typeof rule === 'string' ? new Rule({ key: rule }) : rule; + this.app.layout.workspaceDetailsRegion.reset(); + this.getRuleDetails(ruleModel).done(function (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); + }); + }, + + showDetailsForSelected: function () { + var rule = this.app.list.at(this.app.state.get('selectedIndex')); + this.showDetails(rule); + }, + + hideDetails: function (firstPage) { + key.setScope('list'); + this.app.state.unset('rule'); + this.app.layout.workspaceDetailsRegion.reset(); + this.app.layout.hideDetails(); + this.app.workspaceListView.bindScrollEvents(); + if (firstPage) { + this.app.workspaceListView.scrollTo(); } + }, + + activateCurrent: function () { + var rule = this.app.list.at(this.app.state.get('selectedIndex')); + var ruleView = this.app.workspaceListView.children.findByModel(rule); + ruleView.$('.coding-rules-detail-quality-profile-activate').click(); + }, - }); + deactivateCurrent: function () { + var rule = this.app.list.at(this.app.state.get('selectedIndex')); + var ruleView = this.app.workspaceListView.children.findByModel(rule); + ruleView.$('.coding-rules-detail-quality-profile-deactivate').click(); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/coding-rules/facets-view.js b/server/sonar-web/src/main/js/apps/coding-rules/facets-view.js index 47f9e2edae5..c3da8bbe54b 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/facets-view.js +++ b/server/sonar-web/src/main/js/apps/coding-rules/facets-view.js @@ -1,59 +1,40 @@ -define([ - 'components/navigator/facets-view', - './facets/base-facet', - './facets/query-facet', - './facets/key-facet', - './facets/language-facet', - './facets/repository-facet', - './facets/tag-facet', - './facets/quality-profile-facet', - './facets/characteristic-facet', - './facets/severity-facet', - './facets/status-facet', - './facets/available-since-facet', - './facets/inheritance-facet', - './facets/active-severity-facet', - './facets/template-facet' - ], - function (FacetsView, - BaseFacet, - QueryFacet, - KeyFacet, - LanguageFacet, - RepositoryFacet, - TagFacet, - QualityProfileFacet, - CharacteristicFacet, - SeverityFacet, - StatusFacet, - AvailableSinceFacet, - InheritanceFacet, - ActiveSeverityFacet, - TemplateFacet) { +import FacetsView from 'components/navigator/facets-view'; +import BaseFacet from './facets/base-facet'; +import QueryFacet from './facets/query-facet'; +import KeyFacet from './facets/key-facet'; +import LanguageFacet from './facets/language-facet'; +import RepositoryFacet from './facets/repository-facet'; +import TagFacet from './facets/tag-facet'; +import QualityProfileFacet from './facets/quality-profile-facet'; +import CharacteristicFacet from './facets/characteristic-facet'; +import SeverityFacet from './facets/severity-facet'; +import StatusFacet from './facets/status-facet'; +import AvailableSinceFacet from './facets/available-since-facet'; +import InheritanceFacet from './facets/inheritance-facet'; +import ActiveSeverityFacet from './facets/active-severity-facet'; +import TemplateFacet from './facets/template-facet'; - var viewsMapping = { - q: QueryFacet, - rule_key: KeyFacet, - languages: LanguageFacet, - repositories: RepositoryFacet, - tags: TagFacet, - qprofile: QualityProfileFacet, - debt_characteristics: CharacteristicFacet, - severities: SeverityFacet, - statuses: StatusFacet, - available_since: AvailableSinceFacet, - inheritance: InheritanceFacet, - active_severities: ActiveSeverityFacet, - is_template: TemplateFacet - }; +var viewsMapping = { + q: QueryFacet, + rule_key: KeyFacet, + languages: LanguageFacet, + repositories: RepositoryFacet, + tags: TagFacet, + qprofile: QualityProfileFacet, + debt_characteristics: CharacteristicFacet, + severities: SeverityFacet, + statuses: StatusFacet, + available_since: AvailableSinceFacet, + inheritance: InheritanceFacet, + active_severities: ActiveSeverityFacet, + is_template: TemplateFacet +}; - return FacetsView.extend({ +export default FacetsView.extend({ - getChildView: function (model) { - var view = viewsMapping[model.get('property')]; - return view ? view : BaseFacet; - } + getChildView: function (model) { + var view = viewsMapping[model.get('property')]; + return view ? view : BaseFacet; + } - }); - - }); +}); diff --git a/server/sonar-web/src/main/js/apps/coding-rules/facets/active-severity-facet.js b/server/sonar-web/src/main/js/apps/coding-rules/facets/active-severity-facet.js index f41233b9a7a..0f0de13b0de 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/facets/active-severity-facet.js +++ b/server/sonar-web/src/main/js/apps/coding-rules/facets/active-severity-facet.js @@ -1,46 +1,45 @@ -define([ - './base-facet', - '../templates' -], function (BaseFacet) { - - return BaseFacet.extend({ - template: Templates['coding-rules-severity-facet'], - severities: ['BLOCKER', 'MINOR', 'CRITICAL', 'INFO', 'MAJOR'], - - initialize: function (options) { - this.listenTo(options.app.state, 'change:query', this.onQueryChange); - }, - - onQueryChange: function () { - var query = this.options.app.state.get('query'), - isProfileSelected = query.qprofile != null, - isActiveShown = '' + query.activation === 'true'; - if (!isProfileSelected || !isActiveShown) { - this.forbid(); - } - }, - - onRender: function () { - BaseFacet.prototype.onRender.apply(this, arguments); - this.onQueryChange(); - }, - - forbid: function () { - BaseFacet.prototype.forbid.apply(this, arguments); - this.$el.prop('title', t('coding_rules.filters.active_severity.inactive')); - }, - - allow: function () { - BaseFacet.prototype.allow.apply(this, arguments); - this.$el.prop('title', null); - }, - - sortValues: function (values) { - var order = this.severities; - return _.sortBy(values, function (v) { - return order.indexOf(v.val); - }); +import _ from 'underscore'; +import BaseFacet from './base-facet'; +import '../templates'; + +export default BaseFacet.extend({ + template: Templates['coding-rules-severity-facet'], + severities: ['BLOCKER', 'MINOR', 'CRITICAL', 'INFO', 'MAJOR'], + + initialize: function (options) { + this.listenTo(options.app.state, 'change:query', this.onQueryChange); + }, + + onQueryChange: function () { + var query = this.options.app.state.get('query'), + isProfileSelected = query.qprofile != null, + isActiveShown = '' + query.activation === 'true'; + if (!isProfileSelected || !isActiveShown) { + this.forbid(); } - }); - + }, + + onRender: function () { + BaseFacet.prototype.onRender.apply(this, arguments); + this.onQueryChange(); + }, + + forbid: function () { + BaseFacet.prototype.forbid.apply(this, arguments); + this.$el.prop('title', t('coding_rules.filters.active_severity.inactive')); + }, + + allow: function () { + BaseFacet.prototype.allow.apply(this, arguments); + this.$el.prop('title', null); + }, + + sortValues: function (values) { + var order = this.severities; + return _.sortBy(values, function (v) { + return order.indexOf(v.val); + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/coding-rules/facets/available-since-facet.js b/server/sonar-web/src/main/js/apps/coding-rules/facets/available-since-facet.js index 830fbe1bef0..3f2f6a2839f 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/facets/available-since-facet.js +++ b/server/sonar-web/src/main/js/apps/coding-rules/facets/available-since-facet.js @@ -1,42 +1,41 @@ -define([ - './base-facet', - '../templates' -], function (BaseFacet) { - - return BaseFacet.extend({ - template: Templates['coding-rules-available-since-facet'], - - events: function () { - return _.extend(BaseFacet.prototype.events.apply(this, arguments), { - 'change input': 'applyFacet' - }); - }, - - onRender: function () { - this.$el.toggleClass('search-navigator-facet-box-collapsed', !this.model.get('enabled')); - this.$el.attr('data-property', this.model.get('property')); - this.$('input').datepicker({ - dateFormat: 'yy-mm-dd', - changeMonth: true, - changeYear: true - }); - var value = this.options.app.state.get('query').available_since; - if (value) { - this.$('input').val(value); - } - }, - - applyFacet: function() { - var obj = {}, - property = this.model.get('property'); - obj[property] = this.$('input').val(); - this.options.app.state.updateFilter(obj); - }, - - getLabelsSource: function () { - return this.options.app.languages; +import _ from 'underscore'; +import BaseFacet from './base-facet'; +import '../templates'; + +export default BaseFacet.extend({ + template: Templates['coding-rules-available-since-facet'], + + events: function () { + return _.extend(BaseFacet.prototype.events.apply(this, arguments), { + 'change input': 'applyFacet' + }); + }, + + onRender: function () { + this.$el.toggleClass('search-navigator-facet-box-collapsed', !this.model.get('enabled')); + this.$el.attr('data-property', this.model.get('property')); + this.$('input').datepicker({ + dateFormat: 'yy-mm-dd', + changeMonth: true, + changeYear: true + }); + var value = this.options.app.state.get('query').available_since; + if (value) { + this.$('input').val(value); } + }, - }); + applyFacet: function () { + var obj = {}, + property = this.model.get('property'); + obj[property] = this.$('input').val(); + this.options.app.state.updateFilter(obj); + }, + + getLabelsSource: function () { + return this.options.app.languages; + } }); + + diff --git a/server/sonar-web/src/main/js/apps/coding-rules/facets/base-facet.js b/server/sonar-web/src/main/js/apps/coding-rules/facets/base-facet.js index 18dc6f2c040..f02260069cb 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/facets/base-facet.js +++ b/server/sonar-web/src/main/js/apps/coding-rules/facets/base-facet.js @@ -1,11 +1,9 @@ -define([ - 'components/navigator/facets/base-facet', - '../templates' -], function (BaseFacet) { - - return BaseFacet.extend({ - className: 'search-navigator-facet-box', - template: Templates['coding-rules-base-facet'] - }); +import BaseFacet from 'components/navigator/facets/base-facet'; +import '../templates'; +export default BaseFacet.extend({ + className: 'search-navigator-facet-box', + template: Templates['coding-rules-base-facet'] }); + + diff --git a/server/sonar-web/src/main/js/apps/coding-rules/facets/characteristic-facet.js b/server/sonar-web/src/main/js/apps/coding-rules/facets/characteristic-facet.js index c4a5e814bc2..5463b4e13bc 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/facets/characteristic-facet.js +++ b/server/sonar-web/src/main/js/apps/coding-rules/facets/characteristic-facet.js @@ -1,66 +1,64 @@ -define([ - './base-facet', - '../templates' -], function (BaseFacet) { +import $ from 'jquery'; +import _ from 'underscore'; +import BaseFacet from './base-facet'; +import '../templates'; - var $ = jQuery; +export default BaseFacet.extend({ + template: Templates['coding-rules-characteristic-facet'], - return BaseFacet.extend({ - template: Templates['coding-rules-characteristic-facet'], - - onRender: function () { - BaseFacet.prototype.onRender.apply(this, arguments); - var value = this.options.app.state.get('query').has_debt_characteristic; - if (value != null && ('' + value === 'false')) { - this.$('.js-facet').filter('[data-empty-characteristic]').addClass('active'); - } - }, - - toggleFacet: function (e) { - var noneCharacteristic = $(e.currentTarget).is('[data-empty-characteristic]'), - property = this.model.get('property'), - obj = {}; - $(e.currentTarget).toggleClass('active'); - if (noneCharacteristic) { - var checked = $(e.currentTarget).is('.active'); - obj.has_debt_characteristic = checked ? 'false' : null; - obj[property] = null; - } else { - obj.has_debt_characteristic = null; - obj[property] = this.getValue(); - } - this.options.app.state.updateFilter(obj); - }, + onRender: function () { + BaseFacet.prototype.onRender.apply(this, arguments); + var value = this.options.app.state.get('query').has_debt_characteristic; + if (value != null && ('' + value === 'false')) { + this.$('.js-facet').filter('[data-empty-characteristic]').addClass('active'); + } + }, - disable: function () { - var property = this.model.get('property'), - obj = {}; - obj.has_debt_characteristic = null; + toggleFacet: function (e) { + var noneCharacteristic = $(e.currentTarget).is('[data-empty-characteristic]'), + property = this.model.get('property'), + obj = {}; + $(e.currentTarget).toggleClass('active'); + if (noneCharacteristic) { + var checked = $(e.currentTarget).is('.active'); + obj.has_debt_characteristic = checked ? 'false' : null; obj[property] = null; - this.options.app.state.updateFilter(obj); - }, + } else { + obj.has_debt_characteristic = null; + obj[property] = this.getValue(); + } + this.options.app.state.updateFilter(obj); + }, - getValues: function () { - var values = this.model.getValues(), - characteristics = this.options.app.characteristics; - return values.map(function (value) { - var ch = _.findWhere(characteristics, { key: value.val }); - if (ch != null) { - _.extend(value, ch, { label: ch.name }); - } - return value; - }); - }, + disable: function () { + var property = this.model.get('property'), + obj = {}; + obj.has_debt_characteristic = null; + obj[property] = null; + this.options.app.state.updateFilter(obj); + }, - sortValues: function (values) { - return _.sortBy(values, 'index'); - }, + getValues: function () { + var values = this.model.getValues(), + characteristics = this.options.app.characteristics; + return values.map(function (value) { + var ch = _.findWhere(characteristics, { key: value.val }); + if (ch != null) { + _.extend(value, ch, { label: ch.name }); + } + return value; + }); + }, - serializeData: function () { - return _.extend(BaseFacet.prototype.serializeData.apply(this, arguments), { - values: this.sortValues(this.getValues()) - }); - } - }); + sortValues: function (values) { + return _.sortBy(values, 'index'); + }, + serializeData: function () { + return _.extend(BaseFacet.prototype.serializeData.apply(this, arguments), { + values: this.sortValues(this.getValues()) + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/coding-rules/facets/custom-labels-facet.js b/server/sonar-web/src/main/js/apps/coding-rules/facets/custom-labels-facet.js index cda2d4bd4f6..7396208123f 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/facets/custom-labels-facet.js +++ b/server/sonar-web/src/main/js/apps/coding-rules/facets/custom-labels-facet.js @@ -1,28 +1,27 @@ -define([ - './base-facet' -], function (BaseFacet) { +import _ from 'underscore'; +import BaseFacet from './base-facet'; - return BaseFacet.extend({ +export default BaseFacet.extend({ - getLabelsSource: function () { - return []; - }, + getLabelsSource: function () { + return []; + }, - getValues: function () { - var that = this, - labels = that.getLabelsSource(); - return this.model.getValues().map(function (item) { - return _.extend(item, { - label: labels[item.val] - }); + getValues: function () { + var that = this, + labels = that.getLabelsSource(); + return this.model.getValues().map(function (item) { + return _.extend(item, { + label: labels[item.val] }); - }, - - serializeData: function () { - return _.extend(BaseFacet.prototype.serializeData.apply(this, arguments), { - values: this.getValues() - }); - } - }); + }); + }, + serializeData: function () { + return _.extend(BaseFacet.prototype.serializeData.apply(this, arguments), { + values: this.getValues() + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/coding-rules/facets/custom-values-facet.js b/server/sonar-web/src/main/js/apps/coding-rules/facets/custom-values-facet.js index d42604e6fee..c2499876610 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/facets/custom-values-facet.js +++ b/server/sonar-web/src/main/js/apps/coding-rules/facets/custom-values-facet.js @@ -1,70 +1,69 @@ -define([ - './base-facet', - '../templates' -], function (BaseFacet) { +import _ from 'underscore'; +import BaseFacet from './base-facet'; +import '../templates'; - return BaseFacet.extend({ - template: Templates['coding-rules-custom-values-facet'], +export default BaseFacet.extend({ + template: Templates['coding-rules-custom-values-facet'], - events: function () { - return _.extend(BaseFacet.prototype.events.apply(this, arguments), { - 'change .js-custom-value': 'addCustomValue' - }); - }, + events: function () { + return _.extend(BaseFacet.prototype.events.apply(this, arguments), { + 'change .js-custom-value': 'addCustomValue' + }); + }, - getUrl: function () { - return baseUrl; - }, + getUrl: function () { + return baseUrl; + }, - onRender: function () { - BaseFacet.prototype.onRender.apply(this, arguments); - this.prepareSearch(); - }, + onRender: function () { + BaseFacet.prototype.onRender.apply(this, arguments); + this.prepareSearch(); + }, - prepareSearch: function () { - this.$('.js-custom-value').select2({ - placeholder: t('search_verb'), - minimumInputLength: 1, - allowClear: false, - formatNoMatches: function () { - return t('select2.noMatches'); - }, - formatSearching: function () { - return t('select2.searching'); - }, - formatInputTooShort: function () { - return tp('select2.tooShort', 1); - }, - width: '100%', - ajax: this.prepareAjaxSearch() - }); - }, + prepareSearch: function () { + this.$('.js-custom-value').select2({ + placeholder: t('search_verb'), + minimumInputLength: 1, + allowClear: false, + formatNoMatches: function () { + return t('select2.noMatches'); + }, + formatSearching: function () { + return t('select2.searching'); + }, + formatInputTooShort: function () { + return tp('select2.tooShort', 1); + }, + width: '100%', + ajax: this.prepareAjaxSearch() + }); + }, - prepareAjaxSearch: function () { - return { - quietMillis: 300, - url: this.getUrl(), - data: function (term, page) { - return { s: term, p: page }; - }, - results: function (data) { - return { more: data.more, results: data.results }; - } - }; - }, - - addCustomValue: function () { - var property = this.model.get('property'), - customValue = this.$('.js-custom-value').select2('val'), - value = this.getValue(); - if (value.length > 0) { - value += ','; + prepareAjaxSearch: function () { + return { + quietMillis: 300, + url: this.getUrl(), + data: function (term, page) { + return { s: term, p: page }; + }, + results: function (data) { + return { more: data.more, results: data.results }; } - value += customValue; - var obj = {}; - obj[property] = value; - this.options.app.state.updateFilter(obj); - } - }); + }; + }, + addCustomValue: function () { + var property = this.model.get('property'), + customValue = this.$('.js-custom-value').select2('val'), + value = this.getValue(); + if (value.length > 0) { + value += ','; + } + value += customValue; + var obj = {}; + obj[property] = value; + this.options.app.state.updateFilter(obj); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/coding-rules/facets/inheritance-facet.js b/server/sonar-web/src/main/js/apps/coding-rules/facets/inheritance-facet.js index 08339bebe14..e3dc2c2cafc 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/facets/inheritance-facet.js +++ b/server/sonar-web/src/main/js/apps/coding-rules/facets/inheritance-facet.js @@ -1,71 +1,69 @@ -define([ - './base-facet', - '../templates' -], function (BaseFacet) { +import $ from 'jquery'; +import _ from 'underscore'; +import BaseFacet from './base-facet'; +import '../templates'; - var $ = jQuery; +export default BaseFacet.extend({ + template: Templates['coding-rules-inheritance-facet'], - return BaseFacet.extend({ - template: Templates['coding-rules-inheritance-facet'], + initialize: function (options) { + this.listenTo(options.app.state, 'change:query', this.onQueryChange); + }, - initialize: function (options) { - this.listenTo(options.app.state, 'change:query', this.onQueryChange); - }, - - onQueryChange: function () { - var query = this.options.app.state.get('query'), - isProfileSelected = query.qprofile != null; - if (isProfileSelected) { - var profile = _.findWhere(this.options.app.qualityProfiles, { key: query.qprofile }); - if (profile != null && profile.parentKey == null) { - this.forbid(); - } - } else { + onQueryChange: function () { + var query = this.options.app.state.get('query'), + isProfileSelected = query.qprofile != null; + if (isProfileSelected) { + var profile = _.findWhere(this.options.app.qualityProfiles, { key: query.qprofile }); + if (profile != null && profile.parentKey == null) { this.forbid(); } - }, - - onRender: function () { - BaseFacet.prototype.onRender.apply(this, arguments); - this.onQueryChange(); - }, + } else { + this.forbid(); + } + }, - forbid: function () { - BaseFacet.prototype.forbid.apply(this, arguments); - this.$el.prop('title', t('coding_rules.filters.inheritance.inactive')); - }, + onRender: function () { + BaseFacet.prototype.onRender.apply(this, arguments); + this.onQueryChange(); + }, - allow: function () { - BaseFacet.prototype.allow.apply(this, arguments); - this.$el.prop('title', null); - }, + forbid: function () { + BaseFacet.prototype.forbid.apply(this, arguments); + this.$el.prop('title', t('coding_rules.filters.inheritance.inactive')); + }, - getValues: function () { - var values = ['NONE', 'INHERITED', 'OVERRIDES']; - return values.map(function (key) { - return { - label: t('coding_rules.filters.inheritance', key.toLowerCase()), - val: key - }; - }); - }, + allow: function () { + BaseFacet.prototype.allow.apply(this, arguments); + this.$el.prop('title', null); + }, - toggleFacet: function (e) { - var obj = {}, - property = this.model.get('property'); - if ($(e.currentTarget).is('.active')) { - obj[property] = null; - } else { - obj[property] = $(e.currentTarget).data('value'); - } - this.options.app.state.updateFilter(obj); - }, + getValues: function () { + var values = ['NONE', 'INHERITED', 'OVERRIDES']; + return values.map(function (key) { + return { + label: t('coding_rules.filters.inheritance', key.toLowerCase()), + val: key + }; + }); + }, - serializeData: function () { - return _.extend(BaseFacet.prototype.serializeData.apply(this, arguments), { - values: this.getValues() - }); + toggleFacet: function (e) { + var obj = {}, + property = this.model.get('property'); + if ($(e.currentTarget).is('.active')) { + obj[property] = null; + } else { + obj[property] = $(e.currentTarget).data('value'); } - }); + this.options.app.state.updateFilter(obj); + }, + serializeData: function () { + return _.extend(BaseFacet.prototype.serializeData.apply(this, arguments), { + values: this.getValues() + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/coding-rules/facets/key-facet.js b/server/sonar-web/src/main/js/apps/coding-rules/facets/key-facet.js index 7c26655108c..4117345bd4b 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/facets/key-facet.js +++ b/server/sonar-web/src/main/js/apps/coding-rules/facets/key-facet.js @@ -1,24 +1,23 @@ -define([ - './base-facet', - '../templates' -], function (BaseFacet) { +import BaseFacet from './base-facet'; +import _ from 'underscore'; +import '../templates'; - return BaseFacet.extend({ - template: Templates['coding-rules-key-facet'], +export default BaseFacet.extend({ + template: Templates['coding-rules-key-facet'], - onRender: function () { - this.$el.toggleClass('hidden', !this.options.app.state.get('query').rule_key); - }, + onRender: function () { + this.$el.toggleClass('hidden', !this.options.app.state.get('query').rule_key); + }, - disable: function () { - this.options.app.state.updateFilter({ rule_key: null }); - }, - - serializeData: function () { - return _.extend(BaseFacet.prototype.serializeData.apply(this, arguments), { - key: this.options.app.state.get('query').rule_key - }); - } - }); + disable: function () { + this.options.app.state.updateFilter({ rule_key: null }); + }, + serializeData: function () { + return _.extend(BaseFacet.prototype.serializeData.apply(this, arguments), { + key: this.options.app.state.get('query').rule_key + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/coding-rules/facets/language-facet.js b/server/sonar-web/src/main/js/apps/coding-rules/facets/language-facet.js index 7033080676f..258640cbd89 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/facets/language-facet.js +++ b/server/sonar-web/src/main/js/apps/coding-rules/facets/language-facet.js @@ -1,51 +1,50 @@ -define([ - './custom-values-facet' -], function (CustomValuesFacet) { - - return CustomValuesFacet.extend({ - - getUrl: function () { - return baseUrl + '/api/languages/list'; - }, - - prepareAjaxSearch: function () { - return { - quietMillis: 300, - url: this.getUrl(), - data: function (term) { - return { q: term, ps: 10000 }; - }, - results: function (data) { - return { - more: false, - results: data.languages.map(function (lang) { - return { id: lang.key, text: lang.name }; - }) - }; - } - }; - }, - - getLabelsSource: function () { - return this.options.app.languages; - }, - - getValues: function () { - var that = this, - labels = that.getLabelsSource(); - return this.model.getValues().map(function (item) { - return _.extend(item, { - label: labels[item.val] - }); +import _ from 'underscore'; +import CustomValuesFacet from './custom-values-facet'; + +export default CustomValuesFacet.extend({ + + getUrl: function () { + return baseUrl + '/api/languages/list'; + }, + + prepareAjaxSearch: function () { + return { + quietMillis: 300, + url: this.getUrl(), + data: function (term) { + return { q: term, ps: 10000 }; + }, + results: function (data) { + return { + more: false, + results: data.languages.map(function (lang) { + return { id: lang.key, text: lang.name }; + }) + }; + } + }; + }, + + getLabelsSource: function () { + return this.options.app.languages; + }, + + getValues: function () { + var that = this, + labels = that.getLabelsSource(); + return this.model.getValues().map(function (item) { + return _.extend(item, { + label: labels[item.val] }); - }, + }); + }, - serializeData: function () { - return _.extend(CustomValuesFacet.prototype.serializeData.apply(this, arguments), { - values: this.getValues() - }); - } - - }); + serializeData: function () { + return _.extend(CustomValuesFacet.prototype.serializeData.apply(this, arguments), { + values: this.getValues() + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/coding-rules/facets/quality-profile-facet.js b/server/sonar-web/src/main/js/apps/coding-rules/facets/quality-profile-facet.js index 21a7ed30d75..5686d6b2cea 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/facets/quality-profile-facet.js +++ b/server/sonar-web/src/main/js/apps/coding-rules/facets/quality-profile-facet.js @@ -1,80 +1,78 @@ -define([ - './base-facet', - '../templates' -], function (BaseFacet) { +import $ from 'jquery'; +import _ from 'underscore'; +import BaseFacet from './base-facet'; +import '../templates'; - var $ = jQuery; +export default BaseFacet.extend({ + template: Templates['coding-rules-quality-profile-facet'], - return BaseFacet.extend({ - template: Templates['coding-rules-quality-profile-facet'], + events: function () { + return _.extend(BaseFacet.prototype.events.apply(this, arguments), { + 'click .js-active': 'setActivation', + 'click .js-inactive': 'unsetActivation' + }); + }, - events: function () { - return _.extend(BaseFacet.prototype.events.apply(this, arguments), { - 'click .js-active': 'setActivation', - 'click .js-inactive': 'unsetActivation' - }); - }, + getValues: function () { + var that = this, + languagesQuery = this.options.app.state.get('query').languages, + languages = languagesQuery != null ? languagesQuery.split(',') : [], + lang = languages.length === 1 ? languages[0] : null, + values = this.options.app.qualityProfiles + .filter(function (profile) { + return lang != null ? profile.lang === lang : true; + }) + .map(function (profile) { + return { + label: profile.name, + extra: that.options.app.languages[profile.lang], + val: profile.key + }; + }); + return _.sortBy(values, 'label'); + }, - getValues: function () { - var that = this, - languagesQuery = this.options.app.state.get('query').languages, - languages = languagesQuery != null ? languagesQuery.split(',') : [], - lang = languages.length === 1 ? languages[0] : null, - values = this.options.app.qualityProfiles - .filter(function (profile) { - return lang != null ? profile.lang === lang : true; - }) - .map(function (profile) { - return { - label: profile.name, - extra: that.options.app.languages[profile.lang], - val: profile.key - }; - }); - return _.sortBy(values, 'label'); - }, + toggleFacet: function (e) { + var obj = {}, + property = this.model.get('property'); + if ($(e.currentTarget).is('.active')) { + obj.activation = null; + obj[property] = null; + } else { + obj.activation = true; + obj[property] = $(e.currentTarget).data('value'); + } + this.options.app.state.updateFilter(obj); + }, - toggleFacet: function (e) { - var obj = {}, - property = this.model.get('property'); - if ($(e.currentTarget).is('.active')) { - obj.activation = null; - obj[property] = null; - } else { - obj.activation = true; - obj[property] = $(e.currentTarget).data('value'); - } - this.options.app.state.updateFilter(obj); - }, + setActivation: function (e) { + e.stopPropagation(); + this.options.app.state.updateFilter({ activation: 'true' }); + }, - setActivation: function (e) { - e.stopPropagation(); - this.options.app.state.updateFilter({ activation: 'true' }); - }, + unsetActivation: function (e) { + e.stopPropagation(); + this.options.app.state.updateFilter({ activation: 'false', active_severities: null }); + }, - unsetActivation: function (e) { - e.stopPropagation(); - this.options.app.state.updateFilter({ activation: 'false', active_severities: null }); - }, + getToggled: function () { + var activation = this.options.app.state.get('query').activation; + return activation === 'true' || activation === true; + }, - getToggled: function () { - var activation = this.options.app.state.get('query').activation; - return activation === 'true' || activation === true; - }, + disable: function () { + var obj = { activation: null }, + property = this.model.get('property'); + obj[property] = null; + this.options.app.state.updateFilter(obj); + }, - disable: function () { - var obj = { activation: null }, - property = this.model.get('property'); - obj[property] = null; - this.options.app.state.updateFilter(obj); - }, + serializeData: function () { + return _.extend(BaseFacet.prototype.serializeData.apply(this, arguments), { + values: this.getValues(), + toggled: this.getToggled() + }); + } +}); - serializeData: function () { - return _.extend(BaseFacet.prototype.serializeData.apply(this, arguments), { - values: this.getValues(), - toggled: this.getToggled() - }); - } - }); -}); diff --git a/server/sonar-web/src/main/js/apps/coding-rules/facets/query-facet.js b/server/sonar-web/src/main/js/apps/coding-rules/facets/query-facet.js index f4770ff165f..fe380885438 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/facets/query-facet.js +++ b/server/sonar-web/src/main/js/apps/coding-rules/facets/query-facet.js @@ -1,37 +1,36 @@ -define([ - './base-facet', - '../templates' -], function (BaseFacet) { +import _ from 'underscore'; +import BaseFacet from './base-facet'; +import '../templates'; - return BaseFacet.extend({ - template: Templates['coding-rules-query-facet'], +export default BaseFacet.extend({ + template: Templates['coding-rules-query-facet'], - events: function () { - return _.extend(BaseFacet.prototype.events.apply(this, arguments), { - 'submit form': 'onFormSubmit' - }); - }, + events: function () { + return _.extend(BaseFacet.prototype.events.apply(this, arguments), { + 'submit form': 'onFormSubmit' + }); + }, - onRender: function () { - this.$el.attr('data-property', this.model.get('property')); - var query = this.options.app.state.get('query'), - value = query.q; - if (value != null) { - this.$('input').val(value); - } - }, - - onFormSubmit: function (e) { - e.preventDefault(); - this.applyFacet(); - }, - - applyFacet: function() { - var obj = {}, - property = this.model.get('property'); - obj[property] = this.$('input').val(); - this.options.app.state.updateFilter(obj, { force: true }); + onRender: function () { + this.$el.attr('data-property', this.model.get('property')); + var query = this.options.app.state.get('query'), + value = query.q; + if (value != null) { + this.$('input').val(value); } - }); + }, + + onFormSubmit: function (e) { + e.preventDefault(); + this.applyFacet(); + }, + applyFacet: function () { + var obj = {}, + property = this.model.get('property'); + obj[property] = this.$('input').val(); + this.options.app.state.updateFilter(obj, { force: true }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/coding-rules/facets/repository-facet.js b/server/sonar-web/src/main/js/apps/coding-rules/facets/repository-facet.js index 163bd5d23e8..8efc8b46869 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/facets/repository-facet.js +++ b/server/sonar-web/src/main/js/apps/coding-rules/facets/repository-facet.js @@ -1,55 +1,54 @@ -define([ - './custom-values-facet' -], function (CustomValuesFacet) { - - return CustomValuesFacet.extend({ - - getUrl: function () { - return baseUrl + '/api/rules/repositories'; - }, - - prepareAjaxSearch: function () { - return { - quietMillis: 300, - url: this.getUrl(), - data: function (term) { - return { q: term, ps: 10000 }; - }, - results: function (data) { - return { - more: false, - results: data.repositories.map(function (repo) { - return { id: repo.key, text: repo.name + ' (' + repo.language + ')' }; - }) - }; - } - }; - }, - - getLabelsSource: function () { - var repos = this.options.app.repositories; - return _.object(_.pluck(repos, 'key'), _.pluck(repos, 'name')); - }, - - getValues: function () { - var that = this, - labels = that.getLabelsSource(); - return this.model.getValues().map(function (value) { - var repo = _.findWhere(that.options.app.repositories, { key: value.val }); - if (repo != null) { - var langName = that.options.app.languages[repo.language]; - _.extend(value, { extra: langName }); - } - return _.extend(value, { label: labels[value.val] }); - }); - }, - - serializeData: function () { - return _.extend(CustomValuesFacet.prototype.serializeData.apply(this, arguments), { - values: this.getValues() - }); - } - - }); +import _ from 'underscore'; +import CustomValuesFacet from './custom-values-facet'; + +export default CustomValuesFacet.extend({ + + getUrl: function () { + return baseUrl + '/api/rules/repositories'; + }, + + prepareAjaxSearch: function () { + return { + quietMillis: 300, + url: this.getUrl(), + data: function (term) { + return { q: term, ps: 10000 }; + }, + results: function (data) { + return { + more: false, + results: data.repositories.map(function (repo) { + return { id: repo.key, text: repo.name + ' (' + repo.language + ')' }; + }) + }; + } + }; + }, + + getLabelsSource: function () { + var repos = this.options.app.repositories; + return _.object(_.pluck(repos, 'key'), _.pluck(repos, 'name')); + }, + + getValues: function () { + var that = this, + labels = that.getLabelsSource(); + return this.model.getValues().map(function (value) { + var repo = _.findWhere(that.options.app.repositories, { key: value.val }); + if (repo != null) { + var langName = that.options.app.languages[repo.language]; + _.extend(value, { extra: langName }); + } + return _.extend(value, { label: labels[value.val] }); + }); + }, + + serializeData: function () { + return _.extend(CustomValuesFacet.prototype.serializeData.apply(this, arguments), { + values: this.getValues() + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/coding-rules/facets/severity-facet.js b/server/sonar-web/src/main/js/apps/coding-rules/facets/severity-facet.js index 2b8a8af7974..6ab2c4f8a4d 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/facets/severity-facet.js +++ b/server/sonar-web/src/main/js/apps/coding-rules/facets/severity-facet.js @@ -1,18 +1,17 @@ -define([ - './base-facet', - '../templates' -], function (BaseFacet) { +import _ from 'underscore'; +import BaseFacet from './base-facet'; +import '../templates'; - return BaseFacet.extend({ - template: Templates['coding-rules-severity-facet'], - severities: ['BLOCKER', 'MINOR', 'CRITICAL', 'INFO', 'MAJOR'], - - sortValues: function (values) { - var order = this.severities; - return _.sortBy(values, function (v) { - return order.indexOf(v.val); - }); - } - }); +export default BaseFacet.extend({ + template: Templates['coding-rules-severity-facet'], + severities: ['BLOCKER', 'MINOR', 'CRITICAL', 'INFO', 'MAJOR'], + sortValues: function (values) { + var order = this.severities; + return _.sortBy(values, function (v) { + return order.indexOf(v.val); + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/coding-rules/facets/status-facet.js b/server/sonar-web/src/main/js/apps/coding-rules/facets/status-facet.js index 51a0c2c4451..7d2e627f243 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/facets/status-facet.js +++ b/server/sonar-web/src/main/js/apps/coding-rules/facets/status-facet.js @@ -1,30 +1,29 @@ -define([ - './base-facet' -], function (BaseFacet) { +import _ from 'underscore'; +import BaseFacet from './base-facet'; - return BaseFacet.extend({ - statuses: ['READY', 'DEPRECATED', 'BETA'], +export default BaseFacet.extend({ + statuses: ['READY', 'DEPRECATED', 'BETA'], - getValues: function () { - var values = this.model.getValues(); - var x = values.map(function (value) { - return _.extend(value, { label: t('rules.status', value.val.toLowerCase()) }); - }); - return x; - }, + getValues: function () { + var values = this.model.getValues(); + var x = values.map(function (value) { + return _.extend(value, { label: t('rules.status', value.val.toLowerCase()) }); + }); + return x; + }, - sortValues: function (values) { - var order = this.statuses; - return _.sortBy(values, function (v) { - return order.indexOf(v.val); - }); - }, - - serializeData: function () { - return _.extend(BaseFacet.prototype.serializeData.apply(this, arguments), { - values: this.sortValues(this.getValues()) - }); - } - }); + sortValues: function (values) { + var order = this.statuses; + return _.sortBy(values, function (v) { + return order.indexOf(v.val); + }); + }, + serializeData: function () { + return _.extend(BaseFacet.prototype.serializeData.apply(this, arguments), { + values: this.sortValues(this.getValues()) + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/coding-rules/facets/tag-facet.js b/server/sonar-web/src/main/js/apps/coding-rules/facets/tag-facet.js index cf4ba7e135e..b54b63ddb1a 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/facets/tag-facet.js +++ b/server/sonar-web/src/main/js/apps/coding-rules/facets/tag-facet.js @@ -1,31 +1,29 @@ -define([ - './custom-values-facet' -], function (CustomValuesFacet) { +import CustomValuesFacet from './custom-values-facet'; - return CustomValuesFacet.extend({ +export default CustomValuesFacet.extend({ - getUrl: function () { - return baseUrl + '/api/rules/tags'; - }, + getUrl: function () { + return baseUrl + '/api/rules/tags'; + }, - prepareAjaxSearch: function () { - return { - quietMillis: 300, - url: this.getUrl(), - data: function (term) { - return { q: term, ps: 10000 }; - }, - results: function (data) { - return { - more: false, - results: data.tags.map(function (tag) { - return { id: tag, text: tag }; - }) - }; - } - }; - } - - }); + prepareAjaxSearch: function () { + return { + quietMillis: 300, + url: this.getUrl(), + data: function (term) { + return { q: term, ps: 10000 }; + }, + results: function (data) { + return { + more: false, + results: data.tags.map(function (tag) { + return { id: tag, text: tag }; + }) + }; + } + }; + } }); + + diff --git a/server/sonar-web/src/main/js/apps/coding-rules/facets/template-facet.js b/server/sonar-web/src/main/js/apps/coding-rules/facets/template-facet.js index 8e35756ab4a..bf819b33b5f 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/facets/template-facet.js +++ b/server/sonar-web/src/main/js/apps/coding-rules/facets/template-facet.js @@ -1,33 +1,30 @@ -define([ - './base-facet', - '../templates' -], function (BaseFacet) { +import $ from 'jquery'; +import BaseFacet from './base-facet'; +import '../templates'; - var $ = jQuery; +export default BaseFacet.extend({ + template: Templates['coding-rules-template-facet'], - return BaseFacet.extend({ - template: Templates['coding-rules-template-facet'], - - onRender: function () { - BaseFacet.prototype.onRender.apply(this, arguments); - var value = this.options.app.state.get('query').is_template; - if (value != null) { - this.$('.js-facet').filter('[data-value="' + value + '"]').addClass('active'); - } - }, - - toggleFacet: function (e) { - $(e.currentTarget).toggleClass('active'); - var property = this.model.get('property'), - obj = {}; - if ($(e.currentTarget).hasClass('active')) { - obj[property] = '' + $(e.currentTarget).data('value'); - } else { - obj[property] = null; - } - this.options.app.state.updateFilter(obj); + onRender: function () { + BaseFacet.prototype.onRender.apply(this, arguments); + var value = this.options.app.state.get('query').is_template; + if (value != null) { + this.$('.js-facet').filter('[data-value="' + value + '"]').addClass('active'); } + }, - }); + toggleFacet: function (e) { + $(e.currentTarget).toggleClass('active'); + var property = this.model.get('property'), + obj = {}; + if ($(e.currentTarget).hasClass('active')) { + obj[property] = '' + $(e.currentTarget).data('value'); + } else { + obj[property] = null; + } + this.options.app.state.updateFilter(obj); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/coding-rules/filters-view.js b/server/sonar-web/src/main/js/apps/coding-rules/filters-view.js index 8cb424a488f..37644b06ee9 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/filters-view.js +++ b/server/sonar-web/src/main/js/apps/coding-rules/filters-view.js @@ -1,24 +1,24 @@ -define([ - './rule/manual-rule-creation-view', - './templates' -], function (ManualRuleCreationView) { +import _ from 'underscore'; +import Marionette from 'backbone.marionette'; +import ManualRuleCreationView from './rule/manual-rule-creation-view'; +import './templates'; - return Marionette.ItemView.extend({ - template: Templates['coding-rules-filters'], +export default Marionette.ItemView.extend({ + template: Templates['coding-rules-filters'], - events: { - 'click .js-create-manual-rule': 'createManualRule' - }, + events: { + 'click .js-create-manual-rule': 'createManualRule' + }, - createManualRule: function () { - new ManualRuleCreationView({ - app: this.options.app - }).render(); - }, - - serializeData: function () { - return _.extend(this._super(), { canWrite: this.options.app.canWrite }); - } - }); + createManualRule: function () { + new ManualRuleCreationView({ + app: this.options.app + }).render(); + }, + serializeData: function () { + return _.extend(this._super(), { canWrite: this.options.app.canWrite }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/coding-rules/layout.js b/server/sonar-web/src/main/js/apps/coding-rules/layout.js index b17061792d1..ac5e1b7e421 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/layout.js +++ b/server/sonar-web/src/main/js/apps/coding-rules/layout.js @@ -1,40 +1,38 @@ -define([ - './templates' -], function () { - - var $ = jQuery; - - return Marionette.LayoutView.extend({ - template: Templates['coding-rules-layout'], - - regions: { - filtersRegion: '.search-navigator-filters', - facetsRegion: '.search-navigator-facets', - workspaceHeaderRegion: '.search-navigator-workspace-header', - workspaceListRegion: '.search-navigator-workspace-list', - workspaceDetailsRegion: '.search-navigator-workspace-details' - }, - - onRender: function () { - var navigator = this.$('.search-navigator'); - var top = navigator.offset().top; - this.$('.search-navigator-workspace-header').css({ top: top }); - this.$('.search-navigator-side').css({ top: top }).isolatedScroll(); - }, - - showDetails: function () { - this.scroll = $(window).scrollTop(); - this.$('.search-navigator').addClass('search-navigator-extended-view'); - }, - - - hideDetails: function () { - this.$('.search-navigator').removeClass('search-navigator-extended-view'); - if (this.scroll != null) { - $(window).scrollTop(this.scroll); - } +import $ from 'jquery'; +import Marionette from 'backbone.marionette'; +import './templates'; + +export default Marionette.LayoutView.extend({ + template: Templates['coding-rules-layout'], + + regions: { + filtersRegion: '.search-navigator-filters', + facetsRegion: '.search-navigator-facets', + workspaceHeaderRegion: '.search-navigator-workspace-header', + workspaceListRegion: '.search-navigator-workspace-list', + workspaceDetailsRegion: '.search-navigator-workspace-details' + }, + + onRender: function () { + var navigator = this.$('.search-navigator'); + var top = navigator.offset().top; + this.$('.search-navigator-workspace-header').css({ top: top }); + this.$('.search-navigator-side').css({ top: top }).isolatedScroll(); + }, + + showDetails: function () { + this.scroll = $(window).scrollTop(); + this.$('.search-navigator').addClass('search-navigator-extended-view'); + }, + + + hideDetails: function () { + this.$('.search-navigator').removeClass('search-navigator-extended-view'); + if (this.scroll != null) { + $(window).scrollTop(this.scroll); } - - }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/coding-rules/models/rule.js b/server/sonar-web/src/main/js/apps/coding-rules/models/rule.js index 8b9fb465022..6cc502192d5 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/models/rule.js +++ b/server/sonar-web/src/main/js/apps/coding-rules/models/rule.js @@ -1,29 +1,30 @@ -define(function () { +import _ from 'underscore'; +import Backbone from 'backbone'; - return Backbone.Model.extend({ - idAttribute: 'key', +export default Backbone.Model.extend({ + idAttribute: 'key', - addExtraAttributes: function (repositories) { - var repo = _.findWhere(repositories, { key: this.get('repo') }) || this.get('repo'), - repoName = repo != null ? repo.name : repo, - isManual = this.get('repo') === 'manual', - isCustom = this.has('templateKey'); - this.set({ - repoName: repoName, - isManual: isManual, - isCustom: isCustom - }, { silent: true }); - }, - - getInactiveProfiles: function (actives, profiles) { - return actives.map(function (profile) { - var profileBase = _.findWhere(profiles, { key: profile.qProfile }); - if (profileBase != null) { - _.extend(profile, profileBase); - } - return profile; - }); - } - }); + addExtraAttributes: function (repositories) { + var repo = _.findWhere(repositories, { key: this.get('repo') }) || this.get('repo'), + repoName = repo != null ? repo.name : repo, + isManual = this.get('repo') === 'manual', + isCustom = this.has('templateKey'); + this.set({ + repoName: repoName, + isManual: isManual, + isCustom: isCustom + }, { silent: true }); + }, + getInactiveProfiles: function (actives, profiles) { + return actives.map(function (profile) { + var profileBase = _.findWhere(profiles, { key: profile.qProfile }); + if (profileBase != null) { + _.extend(profile, profileBase); + } + return profile; + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/coding-rules/models/rules.js b/server/sonar-web/src/main/js/apps/coding-rules/models/rules.js index 3cc31fcd149..8e293c6ad6e 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/models/rules.js +++ b/server/sonar-web/src/main/js/apps/coding-rules/models/rules.js @@ -1,43 +1,43 @@ -define([ - './rule' -], function (Rule) { +import _ from 'underscore'; +import Backbone from 'backbone'; +import Rule from './rule'; - return Backbone.Collection.extend({ - model: Rule, +export default Backbone.Collection.extend({ + model: Rule, - parseRules: function (r) { - var rules = r.rules, - profiles = r.qProfiles || []; + parseRules: function (r) { + var rules = r.rules, + profiles = r.qProfiles || []; - if (r.actives != null) { - rules = rules.map(function (rule) { - var activations = (r.actives[rule.key] || []).map(function (activation) { - var profile = profiles[activation.qProfile]; - if (profile != null) { - _.extend(activation, { profile: profile }); - if (profile.parent != null) { - _.extend(activation, { parentProfile: profiles[profile.parent] }); - } + if (r.actives != null) { + rules = rules.map(function (rule) { + var activations = (r.actives[rule.key] || []).map(function (activation) { + var profile = profiles[activation.qProfile]; + if (profile != null) { + _.extend(activation, { profile: profile }); + if (profile.parent != null) { + _.extend(activation, { parentProfile: profiles[profile.parent] }); } - return activation; - }); - return _.extend(rule, { activation: activations.length > 0 ? activations[0] : null }); + } + return activation; }); - } - return rules; - }, - - setIndex: function () { - this.forEach(function (rule, index) { - rule.set({ index: index }); - }); - }, - - addExtraAttributes: function (repositories) { - this.models.forEach(function (model) { - model.addExtraAttributes(repositories); + return _.extend(rule, { activation: activations.length > 0 ? activations[0] : null }); }); } - }); + return rules; + }, + setIndex: function () { + this.forEach(function (rule, index) { + rule.set({ index: index }); + }); + }, + + addExtraAttributes: function (repositories) { + this.models.forEach(function (model) { + model.addExtraAttributes(repositories); + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/coding-rules/models/state.js b/server/sonar-web/src/main/js/apps/coding-rules/models/state.js index 9d29484502f..da1dcad586c 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/models/state.js +++ b/server/sonar-web/src/main/js/apps/coding-rules/models/state.js @@ -1,22 +1,24 @@ -define([ - 'components/navigator/models/state' -], function (State) { +import State from 'components/navigator/models/state'; - return State.extend({ - defaults: { - page: 1, - maxResultsReached: false, - query: {}, - facets: ['languages', 'tags'], - allFacets: ['q', 'rule_key', 'languages', 'tags', 'repositories', 'debt_characteristics', 'severities', - 'statuses', 'available_since', 'is_template', 'qprofile', 'inheritance', 'active_severities'], - facetsFromServer: ['languages', 'repositories', 'tags', 'severities', 'statuses', 'debt_characteristics', - 'active_severities'], - transform: { - 'has_debt_characteristic': 'debt_characteristics' - } +export default State.extend({ + defaults: { + page: 1, + maxResultsReached: false, + query: {}, + facets: ['languages', 'tags'], + allFacets: [ + 'q', 'rule_key', 'languages', 'tags', 'repositories', 'debt_characteristics', 'severities', + 'statuses', 'available_since', 'is_template', 'qprofile', 'inheritance', 'active_severities' + ], + facetsFromServer: [ + 'languages', 'repositories', 'tags', 'severities', 'statuses', 'debt_characteristics', + 'active_severities' + ], + transform: { + 'has_debt_characteristic': 'debt_characteristics' } - }); - + } }); + + 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 f1a57c3a0ec..c33ea38e401 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 @@ -1,183 +1,172 @@ -define([ - './models/rules', - './rule/rule-meta-view', - './rule/rule-description-view', - './rule/rule-parameters-view', - './rule/rule-profiles-view', - './rule/custom-rules-view', - './rule/manual-rule-creation-view', - './rule/custom-rule-creation-view', - './rule/rule-issues-view', - './templates' - ], - function (Rules, - MetaView, - DescView, - ParamView, - ProfilesView, - CustomRulesView, - ManualRuleCreationView, - CustomRuleCreationView, - IssuesView) { - - var $ = jQuery; - - return Marionette.LayoutView.extend({ - className: 'coding-rule-details', - template: Templates['coding-rules-rule-details'], - - regions: { - metaRegion: '.js-rule-meta', - descRegion: '.js-rule-description', - paramRegion: '.js-rule-parameters', - profilesRegion: '.js-rule-profiles', - customRulesRegion: '.js-rule-custom-rules', - issuesRegion: '.js-rule-issues' - }, - - events: { - 'click .js-edit-manual': 'editManualRule', - 'click .js-edit-custom': 'editCustomRule', - 'click .js-delete': 'deleteRule' - }, - - initialize: function () { - this.bindShortcuts(); - this.customRules = new Rules(); - if (this.model.get('isTemplate')) { - this.fetchCustomRules(); - } - this.listenTo(this.options.app.state, 'change:selectedIndex', this.select); - }, - - onRender: function () { - this.metaRegion.show(new MetaView({ - app: this.options.app, - model: this.model - })); - this.descRegion.show(new DescView({ - app: this.options.app, - model: this.model - })); - this.paramRegion.show(new ParamView({ - app: this.options.app, - model: this.model - })); - this.profilesRegion.show(new ProfilesView({ - app: this.options.app, - model: this.model, - collection: new Backbone.Collection(this.getQualityProfiles()) - })); - this.customRulesRegion.show(new CustomRulesView({ - app: this.options.app, - model: this.model, - collection: this.customRules - })); - this.issuesRegion.show(new IssuesView({ - app: this.options.app, - model: this.model - })); - this.$el.scrollParent().scrollTop(0); - }, - - onDestroy: function () { - this.unbindShortcuts(); - }, - - fetchCustomRules: function () { - var that = this, - url = baseUrl + '/api/rules/search', - options = { - template_key: this.model.get('key'), - f: 'name,severity,params' - }; - return $.get(url, options).done(function (data) { - that.customRules.reset(data.rules); - }); - }, - - getQualityProfiles: function () { - return this.model.getInactiveProfiles(this.options.actives, this.options.app.qualityProfiles); - }, - - bindShortcuts: function () { - var that = this; - key('up', 'details', function () { - that.options.app.controller.selectPrev(); - return false; - }); - key('down', 'details', function () { - that.options.app.controller.selectNext(); - return false; - }); - key('left, backspace', 'details', function () { - that.options.app.controller.hideDetails(); - return false; - }); - }, - - unbindShortcuts: function () { - key.deleteScope('details'); - }, - - editManualRule: function () { - new ManualRuleCreationView({ - app: this.options.app, - model: this.model - }).render(); - }, - - editCustomRule: function () { - new CustomRuleCreationView({ - app: this.options.app, - model: this.model - }).render(); - }, - - deleteRule: function () { - var that = this, - ruleType = this.model.has('templateKey') ? 'custom' : 'manual'; - window.confirmDialog({ - title: t('delete'), - html: tp('coding_rules.delete.' + ruleType + '.confirm', this.model.get('name')), - yesHandler: function () { - var url = baseUrl + '/api/rules/delete', - options = { key: that.model.id }; - $.post(url, options).done(function () { - that.options.app.controller.fetchList(); - }); - } - }); - }, - - select: function () { - var selected = this.options.app.state.get('selectedIndex'), - selectedRule = this.options.app.list.at(selected); - this.options.app.controller.showDetails(selectedRule); - }, - - serializeData: function () { - var isManual = this.model.get('isManual'), - isCustom = this.model.has('templateKey'), - isEditable = this.options.app.canWrite && (isManual || isCustom), - qualityProfilesVisible = !isManual; - - if (qualityProfilesVisible) { - if (this.model.get('isTemplate')) { - qualityProfilesVisible = !_.isEmpty(this.options.actives); - } - else { - qualityProfilesVisible = (this.options.app.canWrite || !_.isEmpty(this.options.actives)); - } - } - - return _.extend(Marionette.ItemView.prototype.serializeData.apply(this, arguments), { - isEditable: isEditable, - canWrite: this.options.app.canWrite, - qualityProfilesVisible: qualityProfilesVisible, - allTags: _.union(this.model.get('sysTags'), this.model.get('tags')) - }); - } - }); +import $ from 'jquery'; +import _ from 'underscore'; +import Backbone from 'backbone'; +import Marionette from 'backbone.marionette'; +import Rules from './models/rules'; +import MetaView from './rule/rule-meta-view'; +import DescView from './rule/rule-description-view'; +import ParamView from './rule/rule-parameters-view'; +import ProfilesView from './rule/rule-profiles-view'; +import CustomRulesView from './rule/custom-rules-view'; +import ManualRuleCreationView from './rule/manual-rule-creation-view'; +import CustomRuleCreationView from './rule/custom-rule-creation-view'; +import IssuesView from './rule/rule-issues-view'; +import './templates'; + +export default Marionette.LayoutView.extend({ + className: 'coding-rule-details', + template: Templates['coding-rules-rule-details'], + + regions: { + metaRegion: '.js-rule-meta', + descRegion: '.js-rule-description', + paramRegion: '.js-rule-parameters', + profilesRegion: '.js-rule-profiles', + customRulesRegion: '.js-rule-custom-rules', + issuesRegion: '.js-rule-issues' + }, + + events: { + 'click .js-edit-manual': 'editManualRule', + 'click .js-edit-custom': 'editCustomRule', + 'click .js-delete': 'deleteRule' + }, + + initialize: function () { + this.bindShortcuts(); + this.customRules = new Rules(); + if (this.model.get('isTemplate')) { + this.fetchCustomRules(); + } + this.listenTo(this.options.app.state, 'change:selectedIndex', this.select); + }, + + onRender: function () { + this.metaRegion.show(new MetaView({ + app: this.options.app, + model: this.model + })); + this.descRegion.show(new DescView({ + app: this.options.app, + model: this.model + })); + this.paramRegion.show(new ParamView({ + app: this.options.app, + model: this.model + })); + this.profilesRegion.show(new ProfilesView({ + app: this.options.app, + model: this.model, + collection: new Backbone.Collection(this.getQualityProfiles()) + })); + this.customRulesRegion.show(new CustomRulesView({ + app: this.options.app, + model: this.model, + collection: this.customRules + })); + this.issuesRegion.show(new IssuesView({ + app: this.options.app, + model: this.model + })); + this.$el.scrollParent().scrollTop(0); + }, + + onDestroy: function () { + this.unbindShortcuts(); + }, + + fetchCustomRules: function () { + var that = this, + url = baseUrl + '/api/rules/search', + options = { + template_key: this.model.get('key'), + f: 'name,severity,params' + }; + return $.get(url, options).done(function (data) { + that.customRules.reset(data.rules); + }); + }, + + getQualityProfiles: function () { + return this.model.getInactiveProfiles(this.options.actives, this.options.app.qualityProfiles); + }, + bindShortcuts: function () { + var that = this; + key('up', 'details', function () { + that.options.app.controller.selectPrev(); + return false; + }); + key('down', 'details', function () { + that.options.app.controller.selectNext(); + return false; + }); + key('left, backspace', 'details', function () { + that.options.app.controller.hideDetails(); + return false; + }); + }, + + unbindShortcuts: function () { + key.deleteScope('details'); + }, + + editManualRule: function () { + new ManualRuleCreationView({ + app: this.options.app, + model: this.model + }).render(); + }, + + editCustomRule: function () { + new CustomRuleCreationView({ + app: this.options.app, + model: this.model + }).render(); + }, + + deleteRule: function () { + var that = this, + ruleType = this.model.has('templateKey') ? 'custom' : 'manual'; + window.confirmDialog({ + title: t('delete'), + html: tp('coding_rules.delete.' + ruleType + '.confirm', this.model.get('name')), + yesHandler: function () { + var url = baseUrl + '/api/rules/delete', + options = { key: that.model.id }; + $.post(url, options).done(function () { + that.options.app.controller.fetchList(); + }); + } + }); + }, + + select: function () { + var selected = this.options.app.state.get('selectedIndex'), + selectedRule = this.options.app.list.at(selected); + this.options.app.controller.showDetails(selectedRule); + }, + + serializeData: function () { + var isManual = this.model.get('isManual'), + isCustom = this.model.has('templateKey'), + isEditable = this.options.app.canWrite && (isManual || isCustom), + qualityProfilesVisible = !isManual; + + if (qualityProfilesVisible) { + if (this.model.get('isTemplate')) { + qualityProfilesVisible = !_.isEmpty(this.options.actives); + } + else { + qualityProfilesVisible = (this.options.app.canWrite || !_.isEmpty(this.options.actives)); + } + } + + return _.extend(Marionette.ItemView.prototype.serializeData.apply(this, arguments), { + isEditable: isEditable, + canWrite: this.options.app.canWrite, + qualityProfilesVisible: qualityProfilesVisible, + allTags: _.union(this.model.get('sysTags'), this.model.get('tags')) }); + } +}); diff --git a/server/sonar-web/src/main/js/apps/coding-rules/rule-filter-view.js b/server/sonar-web/src/main/js/apps/coding-rules/rule-filter-view.js index 3d1428c62f1..bb9acd5ccef 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/rule-filter-view.js +++ b/server/sonar-web/src/main/js/apps/coding-rules/rule-filter-view.js @@ -1,24 +1,23 @@ -define([ - 'components/common/action-options-view', - './templates' -], function (ActionOptionsView) { - var $ = jQuery; +import $ from 'jquery'; +import _ from 'underscore'; +import ActionOptionsView from 'components/common/action-options-view'; +import './templates'; - return ActionOptionsView.extend({ - template: Templates['coding-rules-rule-filter-form'], +export default ActionOptionsView.extend({ + template: Templates['coding-rules-rule-filter-form'], - selectOption: function (e) { - var property = $(e.currentTarget).data('property'), - value = $(e.currentTarget).data('value'); - this.trigger('select', property, value); - return ActionOptionsView.prototype.selectOption.apply(this, arguments); - }, + selectOption: function (e) { + var property = $(e.currentTarget).data('property'), + value = $(e.currentTarget).data('value'); + this.trigger('select', property, value); + return ActionOptionsView.prototype.selectOption.apply(this, arguments); + }, - serializeData: function () { - return _.extend(ActionOptionsView.prototype.serializeData.apply(this, arguments), { - tags: _.union(this.model.get('sysTags'), this.model.get('tags')) - }); - } + serializeData: function () { + return _.extend(ActionOptionsView.prototype.serializeData.apply(this, arguments), { + tags: _.union(this.model.get('sysTags'), this.model.get('tags')) + }); + } - }); }); + diff --git a/server/sonar-web/src/main/js/apps/coding-rules/rule/custom-rule-creation-view.js b/server/sonar-web/src/main/js/apps/coding-rules/rule/custom-rule-creation-view.js index 76e5f10fea1..dbaf9af0d64 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/rule/custom-rule-creation-view.js +++ b/server/sonar-web/src/main/js/apps/coding-rules/rule/custom-rule-creation-view.js @@ -1,191 +1,189 @@ -define([ - 'components/common/modal-form', - '../templates' -], function (ModalFormView) { - - var $ = jQuery; - - return ModalFormView.extend({ - template: Templates['coding-rules-custom-rule-creation'], - - ui: function () { - return _.extend(ModalFormView.prototype.ui.apply(this, arguments), { - customRuleCreationKey: '#coding-rules-custom-rule-creation-key', - customRuleCreationName: '#coding-rules-custom-rule-creation-name', - customRuleCreationHtmlDescription: '#coding-rules-custom-rule-creation-html-description', - customRuleCreationSeverity: '#coding-rules-custom-rule-creation-severity', - customRuleCreationStatus: '#coding-rules-custom-rule-creation-status', - customRuleCreationParameters: '[name]', - customRuleCreationCreate: '#coding-rules-custom-rule-creation-create', - customRuleCreationReactivate: '#coding-rules-custom-rule-creation-reactivate', - modalFoot: '.modal-foot' - }); - }, - - events: function () { - return _.extend(ModalFormView.prototype.events.apply(this, arguments), { - 'input @ui.customRuleCreationName': 'generateKey', - 'keydown @ui.customRuleCreationName': 'generateKey', - 'keyup @ui.customRuleCreationName': 'generateKey', - - 'input @ui.customRuleCreationKey': 'flagKey', - 'keydown @ui.customRuleCreationKey': 'flagKey', - 'keyup @ui.customRuleCreationKey': 'flagKey', - - 'click #coding-rules-custom-rule-creation-cancel': 'destroy', - 'click @ui.customRuleCreationCreate': 'create', - 'click @ui.customRuleCreationReactivate': 'reactivate' +import $ from 'jquery'; +import _ from 'underscore'; +import ModalFormView from 'components/common/modal-form'; +import '../templates'; + +export default ModalFormView.extend({ + template: Templates['coding-rules-custom-rule-creation'], + + ui: function () { + return _.extend(ModalFormView.prototype.ui.apply(this, arguments), { + customRuleCreationKey: '#coding-rules-custom-rule-creation-key', + customRuleCreationName: '#coding-rules-custom-rule-creation-name', + customRuleCreationHtmlDescription: '#coding-rules-custom-rule-creation-html-description', + customRuleCreationSeverity: '#coding-rules-custom-rule-creation-severity', + customRuleCreationStatus: '#coding-rules-custom-rule-creation-status', + customRuleCreationParameters: '[name]', + customRuleCreationCreate: '#coding-rules-custom-rule-creation-create', + customRuleCreationReactivate: '#coding-rules-custom-rule-creation-reactivate', + modalFoot: '.modal-foot' + }); + }, + + events: function () { + return _.extend(ModalFormView.prototype.events.apply(this, arguments), { + 'input @ui.customRuleCreationName': 'generateKey', + 'keydown @ui.customRuleCreationName': 'generateKey', + 'keyup @ui.customRuleCreationName': 'generateKey', + + 'input @ui.customRuleCreationKey': 'flagKey', + 'keydown @ui.customRuleCreationKey': 'flagKey', + 'keyup @ui.customRuleCreationKey': 'flagKey', + + 'click #coding-rules-custom-rule-creation-cancel': 'destroy', + 'click @ui.customRuleCreationCreate': 'create', + 'click @ui.customRuleCreationReactivate': 'reactivate' + }); + }, + + generateKey: function () { + if (!this.keyModifiedByUser && this.ui.customRuleCreationKey) { + var generatedKey = this.ui.customRuleCreationName.val().latinize().replace(/[^A-Za-z0-9]/g, '_'); + this.ui.customRuleCreationKey.val(generatedKey); + } + }, + + flagKey: function () { + this.keyModifiedByUser = true; + }, + + onRender: function () { + ModalFormView.prototype.onRender.apply(this, arguments); + + this.keyModifiedByUser = false; + + var format = function (state) { + if (!state.id) { + return state.text; + } else { + return ' ' + state.text; + } + }, + severity = (this.model && this.model.get('severity')) || this.options.templateRule.get('severity'), + status = (this.model && this.model.get('status')) || this.options.templateRule.get('status'); + + this.ui.customRuleCreationSeverity.val(severity); + this.ui.customRuleCreationSeverity.select2({ + width: '250px', + minimumResultsForSearch: 999, + formatResult: format, + formatSelection: format + }); + + this.ui.customRuleCreationStatus.val(status); + this.ui.customRuleCreationStatus.select2({ + width: '250px', + minimumResultsForSearch: 999 + }); + }, + + create: function (e) { + e.preventDefault(); + var action = (this.model && this.model.has('key')) ? 'update' : 'create', + options = { + name: this.ui.customRuleCreationName.val(), + markdown_description: this.ui.customRuleCreationHtmlDescription.val(), + severity: this.ui.customRuleCreationSeverity.val(), + status: this.ui.customRuleCreationStatus.val() + }; + if (this.model && this.model.has('key')) { + options.key = this.model.get('key'); + } else { + _.extend(options, { + template_key: this.options.templateRule.get('key'), + custom_key: this.ui.customRuleCreationKey.val(), + prevent_reactivation: true }); - }, - - generateKey: function () { - if (!this.keyModifiedByUser && this.ui.customRuleCreationKey) { - var generatedKey = this.ui.customRuleCreationName.val().latinize().replace(/[^A-Za-z0-9]/g, '_'); - this.ui.customRuleCreationKey.val(generatedKey); + } + var params = this.ui.customRuleCreationParameters.map(function () { + var node = $(this), + value = node.val(); + if (!value && action === 'create') { + value = node.prop('placeholder') || ''; } - }, - - flagKey: function () { - this.keyModifiedByUser = true; - }, - - onRender: function () { - ModalFormView.prototype.onRender.apply(this, arguments); - - this.keyModifiedByUser = false; - - var format = function (state) { - if (!state.id) { - return state.text; - } else { - return ' ' + state.text; - } - }, - severity = (this.model && this.model.get('severity')) || this.options.templateRule.get('severity'), - status = (this.model && this.model.get('status')) || this.options.templateRule.get('status'); - - this.ui.customRuleCreationSeverity.val(severity); - this.ui.customRuleCreationSeverity.select2({ - width: '250px', - minimumResultsForSearch: 999, - formatResult: format, - formatSelection: format - }); - - this.ui.customRuleCreationStatus.val(status); - this.ui.customRuleCreationStatus.select2({ - width: '250px', - minimumResultsForSearch: 999 - }); - }, - - create: function (e) { - e.preventDefault(); - var action = (this.model && this.model.has('key')) ? 'update' : 'create', - options = { - name: this.ui.customRuleCreationName.val(), - markdown_description: this.ui.customRuleCreationHtmlDescription.val(), - severity: this.ui.customRuleCreationSeverity.val(), - status: this.ui.customRuleCreationStatus.val() - }; - if (this.model && this.model.has('key')) { - options.key = this.model.get('key'); - } else { - _.extend(options, { - template_key: this.options.templateRule.get('key'), + return { + key: node.prop('name'), + value: value + }; + }).get(); + options.params = params.map(function (param) { + return param.key + '=' + window.csvEscape(param.value); + }).join(';'); + this.sendRequest(action, options); + }, + + reactivate: function () { + var options = { + name: this.existingRule.name, + markdown_description: this.existingRule.mdDesc, + severity: this.existingRule.severity, + status: this.existingRule.status, + template_key: this.existingRule.templateKey, custom_key: this.ui.customRuleCreationKey.val(), - prevent_reactivation: true - }); + prevent_reactivation: false + }, + params = this.existingRule.params; + options.params = params.map(function (param) { + return param.key + '=' + param.defaultValue; + }).join(';'); + this.sendRequest('create', options); + }, + + sendRequest: function (action, options) { + this.$('.alert').addClass('hidden'); + var that = this, + url = baseUrl + '/api/rules/' + action; + return $.ajax({ + url: url, + type: 'POST', + data: options, + statusCode: { + // do not show global error + 400: null } - var params = this.ui.customRuleCreationParameters.map(function () { - var node = $(this), - value = node.val(); - if (!value && action === 'create') { - value = node.prop('placeholder') || ''; - } - return { - key: node.prop('name'), - value: value - }; - }).get(); - options.params = params.map(function (param) { - return param.key + '=' + window.csvEscape(param.value); - }).join(';'); - this.sendRequest(action, options); - }, - - reactivate: function () { - var options = { - name: this.existingRule.name, - markdown_description: this.existingRule.mdDesc, - severity: this.existingRule.severity, - status: this.existingRule.status, - template_key: this.existingRule.templateKey, - custom_key: this.ui.customRuleCreationKey.val(), - prevent_reactivation: false - }, - params = this.existingRule.params; - options.params = params.map(function (param) { - return param.key + '=' + param.defaultValue; - }).join(';'); - this.sendRequest('create', options); - }, - - sendRequest: function (action, options) { - this.$('.alert').addClass('hidden'); - var that = this, - url = baseUrl + '/api/rules/' + action; - return $.ajax({ - url: url, - type: 'POST', - data: options, - statusCode: { - // do not show global error - 400: null - } - }).done(function () { - if (that.options.templateRule) { - that.options.app.controller.showDetails(that.options.templateRule); - } else { - that.options.app.controller.showDetails(that.model); - } - that.destroy(); - }).fail(function (jqXHR) { - if (jqXHR.status === 409) { - that.existingRule = jqXHR.responseJSON.rule; - that.showErrors([], [{ msg: t('coding_rules.reactivate.help') }]); - that.ui.customRuleCreationCreate.addClass('hidden'); - that.ui.customRuleCreationReactivate.removeClass('hidden'); - } else { - that.showErrors(jqXHR.responseJSON.errors, jqXHR.responseJSON.warnings); - } - }); - }, - - serializeData: function () { - var params = {}; - if (this.options.templateRule) { - params = this.options.templateRule.get('params'); - } else if (this.model && this.model.has('params')) { - params = this.model.get('params').map(function (p) { - return _.extend(p, { value: p.defaultValue }); - }); + }).done(function () { + if (that.options.templateRule) { + that.options.app.controller.showDetails(that.options.templateRule); + } else { + that.options.app.controller.showDetails(that.model); } - - var statuses = ['READY', 'BETA', 'DEPRECATED'].map(function (status) { - return { - id: status, - text: t('rules.status', status.toLowerCase()) - }; - }); - - return _.extend(ModalFormView.prototype.serializeData.apply(this, arguments), { - change: this.model && this.model.has('key'), - params: params, - severities: ['BLOCKER', 'CRITICAL', 'MAJOR', 'MINOR', 'INFO'], - statuses: statuses + that.destroy(); + }).fail(function (jqXHR) { + if (jqXHR.status === 409) { + that.existingRule = jqXHR.responseJSON.rule; + that.showErrors([], [{ msg: t('coding_rules.reactivate.help') }]); + that.ui.customRuleCreationCreate.addClass('hidden'); + that.ui.customRuleCreationReactivate.removeClass('hidden'); + } else { + that.showErrors(jqXHR.responseJSON.errors, jqXHR.responseJSON.warnings); + } + }); + }, + + serializeData: function () { + var params = {}; + if (this.options.templateRule) { + params = this.options.templateRule.get('params'); + } else if (this.model && this.model.has('params')) { + params = this.model.get('params').map(function (p) { + return _.extend(p, { value: p.defaultValue }); }); } - }); + var statuses = ['READY', 'BETA', 'DEPRECATED'].map(function (status) { + return { + id: status, + text: t('rules.status', status.toLowerCase()) + }; + }); + + return _.extend(ModalFormView.prototype.serializeData.apply(this, arguments), { + change: this.model && this.model.has('key'), + params: params, + severities: ['BLOCKER', 'CRITICAL', 'MAJOR', 'MINOR', 'INFO'], + statuses: statuses + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/coding-rules/rule/custom-rule-view.js b/server/sonar-web/src/main/js/apps/coding-rules/rule/custom-rule-view.js index f13f23bd9b4..a47aef607b8 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/rule/custom-rule-view.js +++ b/server/sonar-web/src/main/js/apps/coding-rules/rule/custom-rule-view.js @@ -1,44 +1,43 @@ -define([ - '../templates' -], function () { +import $ from 'jquery'; +import _ from 'underscore'; +import Marionette from 'backbone.marionette'; +import '../templates'; - var $ = jQuery; +export default Marionette.ItemView.extend({ + tagName: 'tr', + template: Templates['coding-rules-custom-rule'], - return Marionette.ItemView.extend({ - tagName: 'tr', - template: Templates['coding-rules-custom-rule'], + modelEvents: { + 'change': 'render' + }, - modelEvents: { - 'change': 'render' - }, + events: { + 'click .js-delete-custom-rule': 'deleteRule' + }, - events: { - 'click .js-delete-custom-rule': 'deleteRule' - }, + deleteRule: function () { + var that = this; + window.confirmDialog({ + title: t('delete'), + html: t('are_you_sure'), + yesHandler: function () { + var url = baseUrl + '/api/rules/delete', + options = { key: that.model.id }; + $.post(url, options).done(function () { + that.model.collection.remove(that.model); + that.destroy(); + }); + } + }); + }, - deleteRule: function () { - var that = this; - window.confirmDialog({ - title: t('delete'), - html: t('are_you_sure'), - yesHandler: function () { - var url = baseUrl + '/api/rules/delete', - options = { key: that.model.id }; - $.post(url, options).done(function () { - that.model.collection.remove(that.model); - that.destroy(); - }); - } - }); - }, + serializeData: function () { + return _.extend(Marionette.ItemView.prototype.serializeData.apply(this, arguments), { + canWrite: this.options.app.canWrite, + templateRule: this.options.templateRule, + permalink: baseUrl + '/coding_rules/#rule_key=' + encodeURIComponent(this.model.id) + }); + } +}); - serializeData: function () { - return _.extend(Marionette.ItemView.prototype.serializeData.apply(this, arguments), { - canWrite: this.options.app.canWrite, - templateRule: this.options.templateRule, - permalink: baseUrl + '/coding_rules/#rule_key=' + encodeURIComponent(this.model.id) - }); - } - }); -}); diff --git a/server/sonar-web/src/main/js/apps/coding-rules/rule/custom-rules-view.js b/server/sonar-web/src/main/js/apps/coding-rules/rule/custom-rules-view.js index 937dde94267..7486abbb573 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/rule/custom-rules-view.js +++ b/server/sonar-web/src/main/js/apps/coding-rules/rule/custom-rules-view.js @@ -1,45 +1,45 @@ -define([ - './custom-rule-view', - './custom-rule-creation-view', - '../templates' -], function (CustomRuleView, CustomRuleCreationView) { - - return Marionette.CompositeView.extend({ - template: Templates['coding-rules-custom-rules'], - childView: CustomRuleView, - childViewContainer: '#coding-rules-detail-custom-rules', - - childViewOptions: function () { - return { - app: this.options.app, - templateRule: this.model - }; - }, - - modelEvents: { - 'change': 'render' - }, - - events: { - 'click .js-create-custom-rule': 'createCustomRule' - }, - - onRender: function () { - this.$el.toggleClass('hidden', !this.model.get('isTemplate')); - }, - - createCustomRule: function () { - new CustomRuleCreationView({ - app: this.options.app, - templateRule: this.model - }).render(); - }, - - serializeData: function () { - return _.extend(Marionette.ItemView.prototype.serializeData.apply(this, arguments), { - canWrite: this.options.app.canWrite - }); - } - }); - +import _ from 'underscore'; +import Marionette from 'backbone.marionette'; +import CustomRuleView from './custom-rule-view'; +import CustomRuleCreationView from './custom-rule-creation-view'; +import '../templates'; + +export default Marionette.CompositeView.extend({ + template: Templates['coding-rules-custom-rules'], + childView: CustomRuleView, + childViewContainer: '#coding-rules-detail-custom-rules', + + childViewOptions: function () { + return { + app: this.options.app, + templateRule: this.model + }; + }, + + modelEvents: { + 'change': 'render' + }, + + events: { + 'click .js-create-custom-rule': 'createCustomRule' + }, + + onRender: function () { + this.$el.toggleClass('hidden', !this.model.get('isTemplate')); + }, + + createCustomRule: function () { + new CustomRuleCreationView({ + app: this.options.app, + templateRule: this.model + }).render(); + }, + + serializeData: function () { + return _.extend(Marionette.ItemView.prototype.serializeData.apply(this, arguments), { + canWrite: this.options.app.canWrite + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/coding-rules/rule/manual-rule-creation-view.js b/server/sonar-web/src/main/js/apps/coding-rules/rule/manual-rule-creation-view.js index 2118434b304..f0890a06e08 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/rule/manual-rule-creation-view.js +++ b/server/sonar-web/src/main/js/apps/coding-rules/rule/manual-rule-creation-view.js @@ -1,119 +1,117 @@ -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['coding-rules-manual-rule-creation'], - return ModalFormView.extend({ - template: Templates['coding-rules-manual-rule-creation'], + ui: function () { + return _.extend(ModalFormView.prototype.ui.apply(this.arguments), { + manualRuleCreationKey: '#coding-rules-manual-rule-creation-key', + manualRuleCreationName: '#coding-rules-manual-rule-creation-name', + manualRuleCreationHtmlDescription: '#coding-rules-manual-rule-creation-html-description', + manualRuleCreationSeverity: '#coding-rules-manual-rule-creation-severity', + manualRuleCreationStatus: '#coding-rules-manual-rule-creation-status', + manualRuleCreationParameters: '[name]', + manualRuleCreationCreate: '#coding-rules-manual-rule-creation-create', + manualRuleCreationReactivate: '#coding-rules-manual-rule-creation-reactivate', + modalFoot: '.modal-foot' + }); + }, - ui: function () { - return _.extend(ModalFormView.prototype.ui.apply(this.arguments), { - manualRuleCreationKey: '#coding-rules-manual-rule-creation-key', - manualRuleCreationName: '#coding-rules-manual-rule-creation-name', - manualRuleCreationHtmlDescription: '#coding-rules-manual-rule-creation-html-description', - manualRuleCreationSeverity: '#coding-rules-manual-rule-creation-severity', - manualRuleCreationStatus: '#coding-rules-manual-rule-creation-status', - manualRuleCreationParameters: '[name]', - manualRuleCreationCreate: '#coding-rules-manual-rule-creation-create', - manualRuleCreationReactivate: '#coding-rules-manual-rule-creation-reactivate', - modalFoot: '.modal-foot' - }); - }, + events: function () { + return _.extend(ModalFormView.prototype.events.apply(this.arguments), { + 'input @ui.manualRuleCreationName': 'generateKey', + 'keydown @ui.manualRuleCreationName': 'generateKey', + 'keyup @ui.manualRuleCreationName': 'generateKey', - events: function () { - return _.extend(ModalFormView.prototype.events.apply(this.arguments), { - 'input @ui.manualRuleCreationName': 'generateKey', - 'keydown @ui.manualRuleCreationName': 'generateKey', - 'keyup @ui.manualRuleCreationName': 'generateKey', + 'input @ui.manualRuleCreationKey': 'flagKey', + 'keydown @ui.manualRuleCreationKey': 'flagKey', + 'keyup @ui.manualRuleCreationKey': 'flagKey', - 'input @ui.manualRuleCreationKey': 'flagKey', - 'keydown @ui.manualRuleCreationKey': 'flagKey', - 'keyup @ui.manualRuleCreationKey': 'flagKey', + 'click #coding-rules-manual-rule-creation-cancel': 'hide', + 'click @ui.manualRuleCreationCreate': 'create', + 'click @ui.manualRuleCreationReactivate': 'reactivate' + }); + }, - 'click #coding-rules-manual-rule-creation-cancel': 'hide', - 'click @ui.manualRuleCreationCreate': 'create', - 'click @ui.manualRuleCreationReactivate': 'reactivate' - }); - }, + onRender: function () { + ModalFormView.prototype.onRender.apply(this, arguments); + this.keyModifiedByUser = false; + this.ui.manualRuleCreationReactivate.addClass('hidden'); + }, - onRender: function () { - ModalFormView.prototype.onRender.apply(this, arguments); - this.keyModifiedByUser = false; - this.ui.manualRuleCreationReactivate.addClass('hidden'); - }, + generateKey: function () { + if (!this.keyModifiedByUser && this.ui.manualRuleCreationKey) { + var generatedKey = this.ui.manualRuleCreationName.val().latinize().replace(/[^A-Za-z0-9]/g, '_'); + this.ui.manualRuleCreationKey.val(generatedKey); + } + }, - generateKey: function () { - if (!this.keyModifiedByUser && this.ui.manualRuleCreationKey) { - var generatedKey = this.ui.manualRuleCreationName.val().latinize().replace(/[^A-Za-z0-9]/g, '_'); - this.ui.manualRuleCreationKey.val(generatedKey); - } - }, + flagKey: function () { + this.keyModifiedByUser = true; + }, - flagKey: function () { - this.keyModifiedByUser = true; - }, + create: function () { + var action = (this.model && this.model.has('key')) ? 'update' : 'create', + options = { + name: this.ui.manualRuleCreationName.val(), + markdown_description: this.ui.manualRuleCreationHtmlDescription.val() + }; + if (action === 'update') { + options.key = this.model.get('key'); + } else { + options.manual_key = this.ui.manualRuleCreationKey.val(); + options.prevent_reactivation = true; + } + this.sendRequest(action, options); + }, - create: function () { - var action = (this.model && this.model.has('key')) ? 'update' : 'create', - options = { - name: this.ui.manualRuleCreationName.val(), - markdown_description: this.ui.manualRuleCreationHtmlDescription.val() - }; - if (action === 'update') { - options.key = this.model.get('key'); + reactivate: function () { + var options = { + name: this.existingRule.name, + markdown_description: this.existingRule.mdDesc, + manual_key: this.ui.manualRuleCreationKey.val(), + prevent_reactivation: false + }; + this.sendRequest('create', options); + }, + + sendRequest: function (action, options) { + var that = this, + url = baseUrl + '/api/rules/' + action; + return $.ajax({ + url: url, + type: 'POST', + data: options, + statusCode: { + // do not show global error + 400: null + } + }).done(function (r) { + if (typeof r === 'string') { + r = JSON.parse(r); + } + that.options.app.controller.showDetails(r.rule.key); + that.destroy(); + }).fail(function (jqXHR) { + if (jqXHR.status === 409) { + that.existingRule = jqXHR.responseJSON.rule; + that.showErrors([], [{ msg: t('coding_rules.reactivate.help') }]); + that.ui.manualRuleCreationCreate.addClass('hidden'); + that.ui.manualRuleCreationReactivate.removeClass('hidden'); } else { - options.manual_key = this.ui.manualRuleCreationKey.val(); - options.prevent_reactivation = true; + that.showErrors(jqXHR.responseJSON.errors, jqXHR.responseJSON.warnings); } - this.sendRequest(action, options); - }, + }); + }, - reactivate: function () { - var options = { - name: this.existingRule.name, - markdown_description: this.existingRule.mdDesc, - manual_key: this.ui.manualRuleCreationKey.val(), - prevent_reactivation: false - }; - this.sendRequest('create', options); - }, + serializeData: function () { + return _.extend(ModalFormView.prototype.serializeData.apply(this, arguments), { + change: this.model && this.model.has('key') + }); + } +}); - sendRequest: function (action, options) { - var that = this, - url = baseUrl + '/api/rules/' + action; - return $.ajax({ - url: url, - type: 'POST', - data: options, - statusCode: { - // do not show global error - 400: null - } - }).done(function (r) { - if (typeof r === 'string') { - r = JSON.parse(r); - } - that.options.app.controller.showDetails(r.rule.key); - that.destroy(); - }).fail(function (jqXHR) { - if (jqXHR.status === 409) { - that.existingRule = jqXHR.responseJSON.rule; - that.showErrors([], [{ msg: t('coding_rules.reactivate.help') }]); - that.ui.manualRuleCreationCreate.addClass('hidden'); - that.ui.manualRuleCreationReactivate.removeClass('hidden'); - } else { - that.showErrors(jqXHR.responseJSON.errors, jqXHR.responseJSON.warnings); - } - }); - }, - serializeData: function () { - return _.extend(ModalFormView.prototype.serializeData.apply(this, arguments), { - change: this.model && this.model.has('key') - }); - } - }); - -}); diff --git a/server/sonar-web/src/main/js/apps/coding-rules/rule/profile-activation-view.js b/server/sonar-web/src/main/js/apps/coding-rules/rule/profile-activation-view.js index 8354a882453..8ea8ce0496d 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/rule/profile-activation-view.js +++ b/server/sonar-web/src/main/js/apps/coding-rules/rule/profile-activation-view.js @@ -1,143 +1,142 @@ -define([ - 'components/common/modal-form', - '../templates' -], function (ModalForm) { - - var $ = jQuery; - - return ModalForm.extend({ - template: Templates['coding-rules-profile-activation'], - - ui: function () { - return _.extend(this._super(), { - qualityProfileSelect: '#coding-rules-quality-profile-activation-select', - qualityProfileSeverity: '#coding-rules-quality-profile-activation-severity', - qualityProfileActivate: '#coding-rules-quality-profile-activation-activate', - qualityProfileParameters: '[name]' - }); - }, - - events: function () { - return _.extend(this._super(), { - 'click @ui.qualityProfileActivate': 'activate' - }); - }, - - onRender: function () { - this._super(); - - this.ui.qualityProfileSelect.select2({ - width: '250px', - minimumResultsForSearch: 5 - }); - - var that = this, - format = function (state) { - if (!state.id) { - return state.text; - } else { - return ' ' + state.text; - } - }, - severity = (this.model && this.model.get('severity')) || this.options.rule.get('severity'); - this.ui.qualityProfileSeverity.val(severity); - this.ui.qualityProfileSeverity.select2({ - width: '250px', - minimumResultsForSearch: 999, - formatResult: format, - formatSelection: format - }); - setTimeout(function () { - that.$('a').first().focus(); - }, 0); - }, - - activate: function (e) { - e.preventDefault(); - var that = this, - profileKey = this.ui.qualityProfileSelect.val(), - params = this.ui.qualityProfileParameters.map(function () { - return { - key: $(this).prop('name'), - value: $(this).val() || $(this).prop('placeholder') || '' - }; - }).get(), - paramsHash = (params.map(function (param) { - return param.key + '=' + window.csvEscape(param.value); - })).join(';'); - - if (this.model) { - profileKey = this.model.get('qProfile'); - if (!profileKey) { - profileKey = this.model.get('key'); - } - } - - var severity = this.ui.qualityProfileSeverity.val(), - ruleKey = this.options.rule.get('key'); - - this.disableForm(); - - return jQuery.ajax({ - type: 'POST', - url: baseUrl + '/api/qualityprofiles/activate_rule', - data: { - profile_key: profileKey, - rule_key: ruleKey, - severity: severity, - params: paramsHash +import $ from 'jquery'; +import _ from 'underscore'; +import Backbone from 'backbone'; +import ModalForm from 'components/common/modal-form'; +import '../templates'; + +export default ModalForm.extend({ + template: Templates['coding-rules-profile-activation'], + + ui: function () { + return _.extend(this._super(), { + qualityProfileSelect: '#coding-rules-quality-profile-activation-select', + qualityProfileSeverity: '#coding-rules-quality-profile-activation-severity', + qualityProfileActivate: '#coding-rules-quality-profile-activation-activate', + qualityProfileParameters: '[name]' + }); + }, + + events: function () { + return _.extend(this._super(), { + 'click @ui.qualityProfileActivate': 'activate' + }); + }, + + onRender: function () { + this._super(); + + this.ui.qualityProfileSelect.select2({ + width: '250px', + minimumResultsForSearch: 5 + }); + + var that = this, + format = function (state) { + if (!state.id) { + return state.text; + } else { + return ' ' + state.text; + } }, - statusCode: { - // do not show global error - 400: null - } - }).done(function () { - that.destroy(); - that.trigger('profileActivated', severity, params, profileKey); - }).fail(function (jqXHR) { - that.enableForm(); - that.showErrors(jqXHR.responseJSON.errors, jqXHR.responseJSON.warnings); - }); - }, - - getAvailableQualityProfiles: function (lang) { - var activeQualityProfiles = this.collection || new Backbone.Collection(), - inactiveProfiles = _.reject(this.options.app.qualityProfiles, function (profile) { - return activeQualityProfiles.findWhere({ key: profile.key }); - }); - return _.filter(inactiveProfiles, function (profile) { - return profile.lang === lang; - }); - }, - - serializeData: function () { - var params = this.options.rule.get('params'); - if (this.model != null) { - var modelParams = this.model.get('params'); - if (_.isArray(modelParams)) { - params = params.map(function (p) { - var parentParam = _.findWhere(modelParams, { key: p.key }); - if (parentParam != null) { - _.extend(p, { value: parentParam.value }); - } - return p; - }); - } + severity = (this.model && this.model.get('severity')) || this.options.rule.get('severity'); + this.ui.qualityProfileSeverity.val(severity); + this.ui.qualityProfileSeverity.select2({ + width: '250px', + minimumResultsForSearch: 999, + formatResult: format, + formatSelection: format + }); + setTimeout(function () { + that.$('a').first().focus(); + }, 0); + }, + + activate: function (e) { + e.preventDefault(); + var that = this, + profileKey = this.ui.qualityProfileSelect.val(), + params = this.ui.qualityProfileParameters.map(function () { + return { + key: $(this).prop('name'), + value: $(this).val() || $(this).prop('placeholder') || '' + }; + }).get(), + paramsHash = (params.map(function (param) { + return param.key + '=' + window.csvEscape(param.value); + })).join(';'); + + if (this.model) { + profileKey = this.model.get('qProfile'); + if (!profileKey) { + profileKey = this.model.get('key'); } + } - var availableProfiles = this.getAvailableQualityProfiles(this.options.rule.get('lang')), - contextProfile = this.options.app.state.get('query').qprofile; - - return _.extend(this._super(), { - change: this.model && this.model.has('severity'), - params: params, - qualityProfiles: availableProfiles, - contextProfile: contextProfile, - severities: ['BLOCKER', 'CRITICAL', 'MAJOR', 'MINOR', 'INFO'], - saveEnabled: !_.isEmpty(availableProfiles) || (this.model && this.model.get('qProfile')), - isCustomRule: (this.model && this.model.has('templateKey')) || this.options.rule.has('templateKey') - }); + var severity = this.ui.qualityProfileSeverity.val(), + ruleKey = this.options.rule.get('key'); + + this.disableForm(); + + return $.ajax({ + type: 'POST', + url: baseUrl + '/api/qualityprofiles/activate_rule', + data: { + profile_key: profileKey, + rule_key: ruleKey, + severity: severity, + params: paramsHash + }, + statusCode: { + // do not show global error + 400: null + } + }).done(function () { + that.destroy(); + that.trigger('profileActivated', severity, params, profileKey); + }).fail(function (jqXHR) { + that.enableForm(); + that.showErrors(jqXHR.responseJSON.errors, jqXHR.responseJSON.warnings); + }); + }, + + getAvailableQualityProfiles: function (lang) { + var activeQualityProfiles = this.collection || new Backbone.Collection(), + inactiveProfiles = _.reject(this.options.app.qualityProfiles, function (profile) { + return activeQualityProfiles.findWhere({ key: profile.key }); + }); + return _.filter(inactiveProfiles, function (profile) { + return profile.lang === lang; + }); + }, + + serializeData: function () { + var params = this.options.rule.get('params'); + if (this.model != null) { + var modelParams = this.model.get('params'); + if (_.isArray(modelParams)) { + params = params.map(function (p) { + var parentParam = _.findWhere(modelParams, { key: p.key }); + if (parentParam != null) { + _.extend(p, { value: parentParam.value }); + } + return p; + }); + } } - }); + var availableProfiles = this.getAvailableQualityProfiles(this.options.rule.get('lang')), + contextProfile = this.options.app.state.get('query').qprofile; + + return _.extend(this._super(), { + change: this.model && this.model.has('severity'), + params: params, + qualityProfiles: availableProfiles, + contextProfile: contextProfile, + severities: ['BLOCKER', 'CRITICAL', 'MAJOR', 'MINOR', 'INFO'], + saveEnabled: !_.isEmpty(availableProfiles) || (this.model && this.model.get('qProfile')), + isCustomRule: (this.model && this.model.has('templateKey')) || this.options.rule.has('templateKey') + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/coding-rules/rule/rule-description-view.js b/server/sonar-web/src/main/js/apps/coding-rules/rule/rule-description-view.js index 3bb81840549..e49e2bb2a75 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/rule/rule-description-view.js +++ b/server/sonar-web/src/main/js/apps/coding-rules/rule/rule-description-view.js @@ -1,83 +1,84 @@ -define([ - '../templates' -], function () { +import $ from 'jquery'; +import _ from 'underscore'; +import Marionette from 'backbone.marionette'; +import '../templates'; - return Marionette.ItemView.extend({ - template: Templates['coding-rules-rule-description'], +export default Marionette.ItemView.extend({ + template: Templates['coding-rules-rule-description'], - modelEvents: { - 'change': 'render' - }, + modelEvents: { + 'change': 'render' + }, - ui: { - descriptionExtra: '#coding-rules-detail-description-extra', - extendDescriptionLink: '#coding-rules-detail-extend-description', - extendDescriptionForm: '.coding-rules-detail-extend-description-form', - extendDescriptionSubmit: '#coding-rules-detail-extend-description-submit', - extendDescriptionRemove: '#coding-rules-detail-extend-description-remove', - extendDescriptionText: '#coding-rules-detail-extend-description-text', - cancelExtendDescription: '#coding-rules-detail-extend-description-cancel' - }, + ui: { + descriptionExtra: '#coding-rules-detail-description-extra', + extendDescriptionLink: '#coding-rules-detail-extend-description', + extendDescriptionForm: '.coding-rules-detail-extend-description-form', + extendDescriptionSubmit: '#coding-rules-detail-extend-description-submit', + extendDescriptionRemove: '#coding-rules-detail-extend-description-remove', + extendDescriptionText: '#coding-rules-detail-extend-description-text', + cancelExtendDescription: '#coding-rules-detail-extend-description-cancel' + }, - events: { - 'click @ui.extendDescriptionLink': 'showExtendDescriptionForm', - 'click @ui.cancelExtendDescription': 'hideExtendDescriptionForm', - 'click @ui.extendDescriptionSubmit': 'submitExtendDescription', - 'click @ui.extendDescriptionRemove': 'removeExtendedDescription' - }, + events: { + 'click @ui.extendDescriptionLink': 'showExtendDescriptionForm', + 'click @ui.cancelExtendDescription': 'hideExtendDescriptionForm', + 'click @ui.extendDescriptionSubmit': 'submitExtendDescription', + 'click @ui.extendDescriptionRemove': 'removeExtendedDescription' + }, - showExtendDescriptionForm: function () { - this.ui.descriptionExtra.addClass('hidden'); - this.ui.extendDescriptionForm.removeClass('hidden'); - this.ui.extendDescriptionText.focus(); - }, + showExtendDescriptionForm: function () { + this.ui.descriptionExtra.addClass('hidden'); + this.ui.extendDescriptionForm.removeClass('hidden'); + this.ui.extendDescriptionText.focus(); + }, - hideExtendDescriptionForm: function () { - this.ui.descriptionExtra.removeClass('hidden'); - this.ui.extendDescriptionForm.addClass('hidden'); - }, + hideExtendDescriptionForm: function () { + this.ui.descriptionExtra.removeClass('hidden'); + this.ui.extendDescriptionForm.addClass('hidden'); + }, - submitExtendDescription: function () { - var that = this; - this.ui.extendDescriptionForm.addClass('hidden'); - return jQuery.ajax({ - type: 'POST', - url: baseUrl + '/api/rules/update', - dataType: 'json', - data: { - key: this.model.get('key'), - markdown_note: this.ui.extendDescriptionText.val() - } - }).done(function (r) { - that.model.set({ - htmlNote: r.rule.htmlNote, - mdNote: r.rule.mdNote - }); - that.render(); - }).fail(function () { - that.render(); + submitExtendDescription: function () { + var that = this; + this.ui.extendDescriptionForm.addClass('hidden'); + return $.ajax({ + type: 'POST', + url: baseUrl + '/api/rules/update', + dataType: 'json', + data: { + key: this.model.get('key'), + markdown_note: this.ui.extendDescriptionText.val() + } + }).done(function (r) { + that.model.set({ + htmlNote: r.rule.htmlNote, + mdNote: r.rule.mdNote }); - }, + that.render(); + }).fail(function () { + that.render(); + }); + }, - removeExtendedDescription: function () { - var that = this; - window.confirmDialog({ - html: t('coding_rules.remove_extended_description.confirm'), - yesHandler: function () { - that.ui.extendDescriptionText.val(''); - that.submitExtendDescription(); - } - }); - }, - - serializeData: function () { - var isEditable = this.options.app.canWrite && (this.model.get('isManual') || this.model.get('isCustom')); + removeExtendedDescription: function () { + var that = this; + window.confirmDialog({ + html: t('coding_rules.remove_extended_description.confirm'), + yesHandler: function () { + that.ui.extendDescriptionText.val(''); + that.submitExtendDescription(); + } + }); + }, - return _.extend(Marionette.ItemView.prototype.serializeData.apply(this, arguments), { - isEditable: isEditable, - canWrite: this.options.app.canWrite - }); - } - }); + serializeData: function () { + var isEditable = this.options.app.canWrite && (this.model.get('isManual') || this.model.get('isCustom')); + return _.extend(Marionette.ItemView.prototype.serializeData.apply(this, arguments), { + isEditable: isEditable, + canWrite: this.options.app.canWrite + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/coding-rules/rule/rule-filter-mixin.js b/server/sonar-web/src/main/js/apps/coding-rules/rule/rule-filter-mixin.js index 75e072f979b..f71af9a5826 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/rule/rule-filter-mixin.js +++ b/server/sonar-web/src/main/js/apps/coding-rules/rule/rule-filter-mixin.js @@ -1,28 +1,25 @@ -define([ - '../rule-filter-view' -], function (RuleFilterView) { +import $ from 'jquery'; +import RuleFilterView from '../rule-filter-view'; - var $ = jQuery; +export default { + onRuleFilterClick: function (e) { + e.preventDefault(); + e.stopPropagation(); + $('body').click(); + var that = this, + popup = new RuleFilterView({ + triggerEl: $(e.currentTarget), + bottomRight: true, + model: this.model + }); + popup.on('select', function (property, value) { + var obj = {}; + obj[property] = '' + value; + that.options.app.state.updateFilter(obj); + popup.destroy(); + }); + popup.render(); + } +}; - return { - onRuleFilterClick: function (e) { - e.preventDefault(); - e.stopPropagation(); - $('body').click(); - var that = this, - popup = new RuleFilterView({ - triggerEl: $(e.currentTarget), - bottomRight: true, - model: this.model - }); - popup.on('select', function (property, value) { - var obj = {}; - obj[property] = '' + value; - that.options.app.state.updateFilter(obj); - popup.destroy(); - }); - popup.render(); - } - }; -}); diff --git a/server/sonar-web/src/main/js/apps/coding-rules/rule/rule-issues-view.js b/server/sonar-web/src/main/js/apps/coding-rules/rule/rule-issues-view.js index 429be6fb6ee..0bd9da9bdac 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/rule/rule-issues-view.js +++ b/server/sonar-web/src/main/js/apps/coding-rules/rule/rule-issues-view.js @@ -1,51 +1,50 @@ -define([ - '../templates' -], function () { +import $ from 'jquery'; +import _ from 'underscore'; +import Marionette from 'backbone.marionette'; +import '../templates'; - var $ = jQuery; +export default Marionette.ItemView.extend({ + template: Templates['coding-rules-rule-issues'], - return Marionette.ItemView.extend({ - template: Templates['coding-rules-rule-issues'], + initialize: function () { + var that = this; + this.total = null; + this.projects = []; + this.requestIssues().done(function () { + that.render(); + }); + }, - initialize: function () { - var that = this; - this.total = null; - this.projects = []; - this.requestIssues().done(function () { - that.render(); - }); - }, - - requestIssues: function () { - var that = this, - url = baseUrl + '/api/issues/search', - options = { - rules: this.model.id, - resolved: false, - ps: 1, - facets: 'projectUuids' - }; - return $.get(url, options).done(function (r) { - var projectsFacet = _.findWhere(r.facets, { property: 'projectUuids' }), - projects = projectsFacet != null ? projectsFacet.values : []; - projects = projects.map(function (project) { - var projectBase = _.findWhere(r.components, { uuid: project.val }); - return _.extend(project, { - name: projectBase != null ? projectBase.longName : '' - }); + requestIssues: function () { + var that = this, + url = baseUrl + '/api/issues/search', + options = { + rules: this.model.id, + resolved: false, + ps: 1, + facets: 'projectUuids' + }; + return $.get(url, options).done(function (r) { + var projectsFacet = _.findWhere(r.facets, { property: 'projectUuids' }), + projects = projectsFacet != null ? projectsFacet.values : []; + projects = projects.map(function (project) { + var projectBase = _.findWhere(r.components, { uuid: project.val }); + return _.extend(project, { + name: projectBase != null ? projectBase.longName : '' }); - that.projects = projects; - that.total = r.total; - }); - }, - - serializeData: function () { - return _.extend(Marionette.ItemView.prototype.serializeData.apply(this, arguments), { - total: this.total, - projects: this.projects, - baseSearchUrl: baseUrl + '/issues/search#resolved=false|rules=' + encodeURIComponent(this.model.id) }); - } - }); + that.projects = projects; + that.total = r.total; + }); + }, + serializeData: function () { + return _.extend(Marionette.ItemView.prototype.serializeData.apply(this, arguments), { + total: this.total, + projects: this.projects, + baseSearchUrl: baseUrl + '/issues/search#resolved=false|rules=' + encodeURIComponent(this.model.id) + }); + } }); + + 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 ea48038362f..f2b947343dd 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 @@ -1,96 +1,97 @@ -define([ - './rule-filter-mixin', - '../templates' -], function (RuleFilterMixin) { +import $ from 'jquery'; +import _ from 'underscore'; +import Marionette from 'backbone.marionette'; +import RuleFilterMixin from './rule-filter-mixin'; +import '../templates'; - return Marionette.ItemView.extend(RuleFilterMixin).extend({ - template: Templates['coding-rules-rule-meta'], +export default Marionette.ItemView.extend(RuleFilterMixin).extend({ + template: Templates['coding-rules-rule-meta'], - modelEvents: { - 'change': 'render' - }, + modelEvents: { + 'change': 'render' + }, - ui: { - tagsChange: '.coding-rules-detail-tags-change', - tagInput: '.coding-rules-detail-tag-input', - tagsEdit: '.coding-rules-detail-tag-edit', - tagsEditDone: '.coding-rules-detail-tag-edit-done', - tagsEditCancel: '.coding-rules-details-tag-edit-cancel', - tagsList: '.coding-rules-detail-tag-list' - }, + ui: { + tagsChange: '.coding-rules-detail-tags-change', + tagInput: '.coding-rules-detail-tag-input', + tagsEdit: '.coding-rules-detail-tag-edit', + tagsEditDone: '.coding-rules-detail-tag-edit-done', + tagsEditCancel: '.coding-rules-details-tag-edit-cancel', + tagsList: '.coding-rules-detail-tag-list' + }, - events: { - 'click @ui.tagsChange': 'changeTags', - 'click @ui.tagsEditDone': 'editDone', - 'click @ui.tagsEditCancel': 'cancelEdit', - 'click .js-rule-filter': 'onRuleFilterClick' - }, + events: { + 'click @ui.tagsChange': 'changeTags', + 'click @ui.tagsEditDone': 'editDone', + 'click @ui.tagsEditCancel': 'cancelEdit', + 'click .js-rule-filter': 'onRuleFilterClick' + }, - onRender: function () { - this.$('[data-toggle="tooltip"]').tooltip({ - container: 'body' - }); - }, - - onDestroy: function () { - this.$('[data-toggle="tooltip"]').tooltip('destroy'); - }, + onRender: function () { + this.$('[data-toggle="tooltip"]').tooltip({ + container: 'body' + }); + }, - requestTags: function () { - var url = baseUrl + '/api/rules/tags'; - return jQuery.get(url); - }, + onDestroy: function () { + this.$('[data-toggle="tooltip"]').tooltip('destroy'); + }, - changeTags: function () { - var that = this; - this.requestTags().done(function (r) { - that.ui.tagInput.select2({ - tags: _.difference(_.difference(r.tags, that.model.get('tags')), that.model.get('sysTags')), - width: '300px' - }); + requestTags: function () { + var url = baseUrl + '/api/rules/tags'; + return $.get(url); + }, - that.ui.tagsEdit.removeClass('hidden'); - that.ui.tagsList.addClass('hidden'); - that.tagsBuffer = that.ui.tagInput.select2('val'); - that.ui.tagInput.select2('open'); + changeTags: function () { + var that = this; + this.requestTags().done(function (r) { + that.ui.tagInput.select2({ + tags: _.difference(_.difference(r.tags, that.model.get('tags')), that.model.get('sysTags')), + width: '300px' }); - }, - cancelEdit: function () { - this.ui.tagsList.removeClass('hidden'); - this.ui.tagsEdit.addClass('hidden'); - if (this.ui.tagInput.select2) { - this.ui.tagInput.select2('val', this.tagsBuffer); - this.ui.tagInput.select2('close'); - } - }, - - editDone: function () { - var that = this, - tags = this.ui.tagInput.val(); - return jQuery.ajax({ - type: 'POST', - url: baseUrl + '/api/rules/update', - data: { - key: this.model.get('key'), - tags: tags - } - }).done(function (r) { - that.model.set('tags', r.rule.tags); - that.cancelEdit(); - }).always(function () { - that.cancelEdit(); - }); - }, + that.ui.tagsEdit.removeClass('hidden'); + that.ui.tagsList.addClass('hidden'); + that.tagsBuffer = that.ui.tagInput.select2('val'); + that.ui.tagInput.select2('open'); + }); + }, - serializeData: function () { - return _.extend(Marionette.ItemView.prototype.serializeData.apply(this, arguments), { - canWrite: this.options.app.canWrite, - subCharacteristic: this.options.app.getSubCharacteristicName(this.model.get('debtSubChar')), - allTags: _.union(this.model.get('sysTags'), this.model.get('tags')), - permalink: baseUrl + '/coding_rules#rule_key=' + encodeURIComponent(this.model.id) - }); + cancelEdit: function () { + this.ui.tagsList.removeClass('hidden'); + this.ui.tagsEdit.addClass('hidden'); + if (this.ui.tagInput.select2) { + this.ui.tagInput.select2('val', this.tagsBuffer); + this.ui.tagInput.select2('close'); } - }); + }, + + editDone: function () { + var that = this, + tags = this.ui.tagInput.val(); + return $.ajax({ + type: 'POST', + url: baseUrl + '/api/rules/update', + data: { + key: this.model.get('key'), + tags: tags + } + }).done(function (r) { + that.model.set('tags', r.rule.tags); + that.cancelEdit(); + }).always(function () { + that.cancelEdit(); + }); + }, + serializeData: function () { + return _.extend(Marionette.ItemView.prototype.serializeData.apply(this, arguments), { + canWrite: this.options.app.canWrite, + subCharacteristic: this.options.app.getSubCharacteristicName(this.model.get('debtSubChar')), + allTags: _.union(this.model.get('sysTags'), this.model.get('tags')), + permalink: baseUrl + '/coding_rules#rule_key=' + encodeURIComponent(this.model.id) + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/coding-rules/rule/rule-parameters-view.js b/server/sonar-web/src/main/js/apps/coding-rules/rule/rule-parameters-view.js index 3dd13c51534..fc34437c23c 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/rule/rule-parameters-view.js +++ b/server/sonar-web/src/main/js/apps/coding-rules/rule/rule-parameters-view.js @@ -1,26 +1,26 @@ -define([ - '../templates' -], function () { +import _ from 'underscore'; +import Marionette from 'backbone.marionette'; +import '../templates'; - return Marionette.ItemView.extend({ - template: Templates['coding-rules-rule-parameters'], +export default Marionette.ItemView.extend({ + template: Templates['coding-rules-rule-parameters'], - modelEvents: { - 'change': 'render' - }, + modelEvents: { + 'change': 'render' + }, - onRender: function () { - this.$el.toggleClass('hidden', _.isEmpty(this.model.get('params'))); - }, + onRender: function () { + this.$el.toggleClass('hidden', _.isEmpty(this.model.get('params'))); + }, - serializeData: function () { - var isEditable = this.options.app.canWrite && (this.model.get('isManual') || this.model.get('isCustom')); - - return _.extend(Marionette.ItemView.prototype.serializeData.apply(this, arguments), { - isEditable: isEditable, - canWrite: this.options.app.canWrite - }); - } - }); + serializeData: function () { + var isEditable = this.options.app.canWrite && (this.model.get('isManual') || this.model.get('isCustom')); + return _.extend(Marionette.ItemView.prototype.serializeData.apply(this, arguments), { + isEditable: isEditable, + canWrite: this.options.app.canWrite + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/coding-rules/rule/rule-profile-view.js b/server/sonar-web/src/main/js/apps/coding-rules/rule/rule-profile-view.js index 7e025519094..40e09aed4a4 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/rule/rule-profile-view.js +++ b/server/sonar-web/src/main/js/apps/coding-rules/rule/rule-profile-view.js @@ -1,138 +1,140 @@ -define([ - './profile-activation-view', - '../templates' -], function (ProfileActivationView) { +import $ from 'jquery'; +import _ from 'underscore'; +import Backbone from 'backbone'; +import Marionette from 'backbone.marionette'; +import ProfileActivationView from './profile-activation-view'; +import '../templates'; - return Marionette.ItemView.extend({ - tagName: 'tr', - template: Templates['coding-rules-rule-profile'], +export default Marionette.ItemView.extend({ + tagName: 'tr', + template: Templates['coding-rules-rule-profile'], - modelEvents: { - 'change': 'render' - }, + modelEvents: { + 'change': 'render' + }, - ui: { - change: '.coding-rules-detail-quality-profile-change', - revert: '.coding-rules-detail-quality-profile-revert', - deactivate: '.coding-rules-detail-quality-profile-deactivate' - }, + ui: { + change: '.coding-rules-detail-quality-profile-change', + revert: '.coding-rules-detail-quality-profile-revert', + deactivate: '.coding-rules-detail-quality-profile-deactivate' + }, - events: { - 'click @ui.change': 'change', - 'click @ui.revert': 'revert', - 'click @ui.deactivate': 'deactivate' - }, + events: { + 'click @ui.change': 'change', + 'click @ui.revert': 'revert', + 'click @ui.deactivate': 'deactivate' + }, - onRender: function () { - this.$('[data-toggle="tooltip"]').tooltip({ - container: 'body' - }); - }, + onRender: function () { + this.$('[data-toggle="tooltip"]').tooltip({ + container: 'body' + }); + }, - change: function () { - var that = this, - activationView = new ProfileActivationView({ - model: this.model, - collection: this.model.collection, - rule: this.options.rule, - app: this.options.app - }); - activationView.on('profileActivated', function () { - that.options.refreshActives(); - }); - activationView.render(); - }, + change: function () { + var that = this, + activationView = new ProfileActivationView({ + model: this.model, + collection: this.model.collection, + rule: this.options.rule, + app: this.options.app + }); + activationView.on('profileActivated', function () { + that.options.refreshActives(); + }); + activationView.render(); + }, - revert: function () { - var that = this, - ruleKey = this.options.rule.get('key'); - window.confirmDialog({ - title: t('coding_rules.revert_to_parent_definition'), - html: tp('coding_rules.revert_to_parent_definition.confirm', this.getParent().name), - yesHandler: function () { - return jQuery.ajax({ - type: 'POST', - url: baseUrl + '/api/qualityprofiles/activate_rule', - data: { - profile_key: that.model.get('qProfile'), - rule_key: ruleKey, - reset: true - } - }).done(function () { - that.options.refreshActives(); - }); - } - }); - }, - - deactivate: function () { - var that = this, - ruleKey = this.options.rule.get('key'); - window.confirmDialog({ - title: t('coding_rules.deactivate'), - html: tp('coding_rules.deactivate.confirm'), - yesHandler: function () { - return jQuery.ajax({ - type: 'POST', - url: baseUrl + '/api/qualityprofiles/deactivate_rule', - data: { - profile_key: that.model.get('qProfile'), - rule_key: ruleKey - } - }).done(function () { - that.options.refreshActives(); - }); - } - }); - }, - - enableUpdate: function () { - return this.ui.update.prop('disabled', false); - }, - - getParent: function () { - if (!(this.model.get('inherit') && this.model.get('inherit') !== 'NONE')) { - return null; + revert: function () { + var that = this, + ruleKey = this.options.rule.get('key'); + window.confirmDialog({ + title: t('coding_rules.revert_to_parent_definition'), + html: tp('coding_rules.revert_to_parent_definition.confirm', this.getParent().name), + yesHandler: function () { + return $.ajax({ + type: 'POST', + url: baseUrl + '/api/qualityprofiles/activate_rule', + data: { + profile_key: that.model.get('qProfile'), + rule_key: ruleKey, + reset: true + } + }).done(function () { + that.options.refreshActives(); + }); } - var myProfile = _.findWhere(this.options.app.qualityProfiles, { - key: this.model.get('qProfile') - }), - parentKey = myProfile.parentKey, - parent = _.extend({}, _.findWhere(this.options.app.qualityProfiles, { - key: parentKey - })), - parentActiveInfo = this.model.collection.findWhere({ qProfile: parentKey }) || new Backbone.Model(); - _.extend(parent, parentActiveInfo.toJSON()); - return parent; - }, + }); + }, - enhanceParameters: function () { - var parent = this.getParent(), - params = _.sortBy(this.model.get('params'), 'key'); - if (!parent) { - return params; + deactivate: function () { + var that = this, + ruleKey = this.options.rule.get('key'); + window.confirmDialog({ + title: t('coding_rules.deactivate'), + html: tp('coding_rules.deactivate.confirm'), + yesHandler: function () { + return $.ajax({ + type: 'POST', + url: baseUrl + '/api/qualityprofiles/deactivate_rule', + data: { + profile_key: that.model.get('qProfile'), + rule_key: ruleKey + } + }).done(function () { + that.options.refreshActives(); + }); } - return params.map(function (p) { - var parentParam = _.findWhere(parent.params, { key: p.key }); - if (parentParam != null) { - return _.extend(p, { - original: _.findWhere(parent.params, { key: p.key }).value - }); - } else { - return p; - } - }); - }, + }); + }, - serializeData: function () { - return _.extend(Marionette.ItemView.prototype.serializeData.apply(this, arguments), { - canWrite: this.options.app.canWrite, - parent: this.getParent(), - parameters: this.enhanceParameters(), - templateKey: this.options.rule.get('templateKey'), - isTemplate: this.options.rule.get('isTemplate') - }); + enableUpdate: function () { + return this.ui.update.prop('disabled', false); + }, + + getParent: function () { + if (!(this.model.get('inherit') && this.model.get('inherit') !== 'NONE')) { + return null; } - }); + var myProfile = _.findWhere(this.options.app.qualityProfiles, { + key: this.model.get('qProfile') + }), + parentKey = myProfile.parentKey, + parent = _.extend({}, _.findWhere(this.options.app.qualityProfiles, { + key: parentKey + })), + parentActiveInfo = this.model.collection.findWhere({ qProfile: parentKey }) || new Backbone.Model(); + _.extend(parent, parentActiveInfo.toJSON()); + return parent; + }, + enhanceParameters: function () { + var parent = this.getParent(), + params = _.sortBy(this.model.get('params'), 'key'); + if (!parent) { + return params; + } + return params.map(function (p) { + var parentParam = _.findWhere(parent.params, { key: p.key }); + if (parentParam != null) { + return _.extend(p, { + original: _.findWhere(parent.params, { key: p.key }).value + }); + } else { + return p; + } + }); + }, + + serializeData: function () { + return _.extend(Marionette.ItemView.prototype.serializeData.apply(this, arguments), { + canWrite: this.options.app.canWrite, + parent: this.getParent(), + parameters: this.enhanceParameters(), + templateKey: this.options.rule.get('templateKey'), + isTemplate: this.options.rule.get('isTemplate') + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/coding-rules/rule/rule-profiles-view.js b/server/sonar-web/src/main/js/apps/coding-rules/rule/rule-profiles-view.js index c9abf542541..f449d944473 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/rule/rule-profiles-view.js +++ b/server/sonar-web/src/main/js/apps/coding-rules/rule/rule-profiles-view.js @@ -1,10 +1,10 @@ -define([ - './rule-profile-view', - './profile-activation-view', - '../templates' -], function (ProfileView, ProfileActivationView) { +import _ from 'underscore'; +import Marionette from 'backbone.marionette'; +import ProfileView from './rule-profile-view'; +import ProfileActivationView from './profile-activation-view'; +import '../templates'; - return Marionette.CompositeView.extend({ + export default Marionette.CompositeView.extend({ template: Templates['coding-rules-rule-profiles'], childView: ProfileView, childViewContainer: '#coding-rules-detail-quality-profiles', @@ -77,4 +77,4 @@ define([ } }); -}); + diff --git a/server/sonar-web/src/main/js/apps/coding-rules/workspace-header-view.js b/server/sonar-web/src/main/js/apps/coding-rules/workspace-header-view.js index b4ef460bacf..74b1a14dc50 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/workspace-header-view.js +++ b/server/sonar-web/src/main/js/apps/coding-rules/workspace-header-view.js @@ -1,50 +1,48 @@ -define([ - 'components/navigator/workspace-header-view', - './bulk-change-popup-view', - './templates' -], function (WorkspaceHeaderView, BulkChangePopup) { - - var $ = jQuery; - - return WorkspaceHeaderView.extend({ - template: Templates['coding-rules-workspace-header'], - - events: function () { - return _.extend(WorkspaceHeaderView.prototype.events.apply(this, arguments), { - 'click .js-back': 'onBackClick', - 'click .js-bulk-change': 'onBulkChangeClick', - 'click .js-reload': 'reload', - 'click .js-new-search': 'newSearch' - }); - }, - - onBackClick: function () { - this.options.app.controller.hideDetails(); - }, - - onBulkChangeClick: function (e) { - e.stopPropagation(); - $('body').click(); - new BulkChangePopup({ - app: this.options.app, - triggerEl: $(e.currentTarget), - bottomRight: true - }).render(); - }, - - reload: function () { - this.options.app.controller.fetchList(true); - }, - - newSearch: function () { - this.options.app.controller.newSearch(); - }, - - serializeData: function () { - return _.extend(WorkspaceHeaderView.prototype.serializeData.apply(this, arguments), { - canWrite: this.options.app.canWrite - }); - } - }); - +import $ from 'jquery'; +import _ from 'underscore'; +import WorkspaceHeaderView from 'components/navigator/workspace-header-view'; +import BulkChangePopup from './bulk-change-popup-view'; +import './templates'; + +export default WorkspaceHeaderView.extend({ + template: Templates['coding-rules-workspace-header'], + + events: function () { + return _.extend(WorkspaceHeaderView.prototype.events.apply(this, arguments), { + 'click .js-back': 'onBackClick', + 'click .js-bulk-change': 'onBulkChangeClick', + 'click .js-reload': 'reload', + 'click .js-new-search': 'newSearch' + }); + }, + + onBackClick: function () { + this.options.app.controller.hideDetails(); + }, + + onBulkChangeClick: function (e) { + e.stopPropagation(); + $('body').click(); + new BulkChangePopup({ + app: this.options.app, + triggerEl: $(e.currentTarget), + bottomRight: true + }).render(); + }, + + reload: function () { + this.options.app.controller.fetchList(true); + }, + + newSearch: function () { + this.options.app.controller.newSearch(); + }, + + serializeData: function () { + return _.extend(WorkspaceHeaderView.prototype.serializeData.apply(this, arguments), { + canWrite: this.options.app.canWrite + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/coding-rules/workspace-list-empty-view.js b/server/sonar-web/src/main/js/apps/coding-rules/workspace-list-empty-view.js index da182d39095..6563efc2e3a 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/workspace-list-empty-view.js +++ b/server/sonar-web/src/main/js/apps/coding-rules/workspace-list-empty-view.js @@ -1,11 +1,11 @@ -define(function () { +import Marionette from 'backbone.marionette'; - return Marionette.ItemView.extend({ - className: 'search-navigator-no-results', - - template: function () { - return t('coding_rules.no_results'); - } - }); +export default Marionette.ItemView.extend({ + className: 'search-navigator-no-results', + template: function () { + return t('coding_rules.no_results'); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/coding-rules/workspace-list-item-view.js b/server/sonar-web/src/main/js/apps/coding-rules/workspace-list-item-view.js index 01b4efb553e..4fda1255c8c 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/workspace-list-item-view.js +++ b/server/sonar-web/src/main/js/apps/coding-rules/workspace-list-item-view.js @@ -1,89 +1,90 @@ -define([ - 'components/navigator/workspace-list-item-view', - './rule/profile-activation-view', - './rule/rule-filter-mixin', - './templates' -], function (WorkspaceListItemView, ProfileActivationView, RuleFilterMixin) { +import $ from 'jquery'; +import _ from 'underscore'; +import Backbone from 'backbone'; +import WorkspaceListItemView from 'components/navigator/workspace-list-item-view'; +import ProfileActivationView from './rule/profile-activation-view'; +import RuleFilterMixin from './rule/rule-filter-mixin'; +import './templates'; - return WorkspaceListItemView.extend(RuleFilterMixin).extend({ - className: 'coding-rule', - template: Templates['coding-rules-workspace-list-item'], +export default WorkspaceListItemView.extend(RuleFilterMixin).extend({ + className: 'coding-rule', + template: Templates['coding-rules-workspace-list-item'], - modelEvents: { - 'change': 'render' - }, + modelEvents: { + 'change': 'render' + }, - events: { - 'click': 'selectCurrent', - 'dblclick': 'openRule', - 'click .js-rule': 'openRule', - 'click .js-rule-filter': 'onRuleFilterClick', - 'click .coding-rules-detail-quality-profile-activate': 'activate', - 'click .coding-rules-detail-quality-profile-change': 'change', - 'click .coding-rules-detail-quality-profile-revert': 'revert', - 'click .coding-rules-detail-quality-profile-deactivate': 'deactivate' - }, + events: { + 'click': 'selectCurrent', + 'dblclick': 'openRule', + 'click .js-rule': 'openRule', + 'click .js-rule-filter': 'onRuleFilterClick', + 'click .coding-rules-detail-quality-profile-activate': 'activate', + 'click .coding-rules-detail-quality-profile-change': 'change', + 'click .coding-rules-detail-quality-profile-revert': 'revert', + 'click .coding-rules-detail-quality-profile-deactivate': 'deactivate' + }, - selectCurrent: function () { - this.options.app.state.set({ selectedIndex: this.model.get('index') }); - }, + selectCurrent: function () { + this.options.app.state.set({ selectedIndex: this.model.get('index') }); + }, - openRule: function () { - this.options.app.controller.showDetails(this.model); - }, + openRule: function () { + this.options.app.controller.showDetails(this.model); + }, - activate: function () { - var that = this, - selectedProfile = this.options.app.state.get('query').qprofile, - othersQualityProfiles = _.reject(this.options.app.qualityProfiles, function (profile) { - return profile.key === selectedProfile; - }), - activationView = new ProfileActivationView({ - rule: this.model, - collection: new Backbone.Collection(othersQualityProfiles), - app: this.options.app - }); - activationView.on('profileActivated', function (severity, params, profile) { - var activation = { - severity: severity, - inherit: 'NONE', - params: params, - qProfile: profile - }; - that.model.set({ activation: activation }); - }); - activationView.render(); - }, + activate: function () { + var that = this, + selectedProfile = this.options.app.state.get('query').qprofile, + othersQualityProfiles = _.reject(this.options.app.qualityProfiles, function (profile) { + return profile.key === selectedProfile; + }), + activationView = new ProfileActivationView({ + rule: this.model, + collection: new Backbone.Collection(othersQualityProfiles), + app: this.options.app + }); + activationView.on('profileActivated', function (severity, params, profile) { + var activation = { + severity: severity, + inherit: 'NONE', + params: params, + qProfile: profile + }; + that.model.set({ activation: activation }); + }); + activationView.render(); + }, - deactivate: function () { - var that = this, - ruleKey = this.model.get('key'), - activation = this.model.get('activation'); - window.confirmDialog({ - title: t('coding_rules.deactivate'), - html: tp('coding_rules.deactivate.confirm'), - yesHandler: function () { - return jQuery.ajax({ - type: 'POST', - url: baseUrl + '/api/qualityprofiles/deactivate_rule', - data: { - profile_key: activation.qProfile, - rule_key: ruleKey - } - }).done(function () { - that.model.unset('activation'); - }); - } - }); - }, - - serializeData: function () { - return _.extend(WorkspaceListItemView.prototype.serializeData.apply(this, arguments), { - tags: _.union(this.model.get('sysTags'), this.model.get('tags')), - canWrite: this.options.app.canWrite, - selectedProfile: this.options.app.state.get('query').qprofile - }); - } - }); + deactivate: function () { + var that = this, + ruleKey = this.model.get('key'), + activation = this.model.get('activation'); + window.confirmDialog({ + title: t('coding_rules.deactivate'), + html: tp('coding_rules.deactivate.confirm'), + yesHandler: function () { + return $.ajax({ + type: 'POST', + url: baseUrl + '/api/qualityprofiles/deactivate_rule', + data: { + profile_key: activation.qProfile, + rule_key: ruleKey + } + }).done(function () { + that.model.unset('activation'); + }); + } + }); + }, + serializeData: function () { + return _.extend(WorkspaceListItemView.prototype.serializeData.apply(this, arguments), { + tags: _.union(this.model.get('sysTags'), this.model.get('tags')), + canWrite: this.options.app.canWrite, + selectedProfile: this.options.app.state.get('query').qprofile + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/coding-rules/workspace-list-view.js b/server/sonar-web/src/main/js/apps/coding-rules/workspace-list-view.js index d8ed84d5c81..252d5a093ce 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/workspace-list-view.js +++ b/server/sonar-web/src/main/js/apps/coding-rules/workspace-list-view.js @@ -1,32 +1,30 @@ -define([ - 'components/navigator/workspace-list-view', - './workspace-list-item-view', - './workspace-list-empty-view', - './templates' -], function (WorkspaceListView, WorkspaceListItemView, WorkspaceListEmptyView) { +import WorkspaceListView from 'components/navigator/workspace-list-view'; +import WorkspaceListItemView from './workspace-list-item-view'; +import WorkspaceListEmptyView from './workspace-list-empty-view'; +import './templates'; - return WorkspaceListView.extend({ - template: Templates['coding-rules-workspace-list'], - childView: WorkspaceListItemView, - childViewContainer: '.js-list', - emptyView: WorkspaceListEmptyView, - - bindShortcuts: function () { - WorkspaceListView.prototype.bindShortcuts.apply(this, arguments); - var that = this; - key('right', 'list', function () { - that.options.app.controller.showDetailsForSelected(); - return false; - }); - key('a', function () { - that.options.app.controller.activateCurrent(); - return false; - }); - key('d', function () { - that.options.app.controller.deactivateCurrent(); - return false; - }); - } - }); +export default WorkspaceListView.extend({ + template: Templates['coding-rules-workspace-list'], + childView: WorkspaceListItemView, + childViewContainer: '.js-list', + emptyView: WorkspaceListEmptyView, + bindShortcuts: function () { + WorkspaceListView.prototype.bindShortcuts.apply(this, arguments); + var that = this; + key('right', 'list', function () { + that.options.app.controller.showDetailsForSelected(); + return false; + }); + key('a', function () { + that.options.app.controller.activateCurrent(); + return false; + }); + key('d', function () { + that.options.app.controller.deactivateCurrent(); + return false; + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/computation/app.js b/server/sonar-web/src/main/js/apps/computation/app.js index 43e64d86b5d..ed7d8ede521 100644 --- a/server/sonar-web/src/main/js/apps/computation/app.js +++ b/server/sonar-web/src/main/js/apps/computation/app.js @@ -1,57 +1,57 @@ -define([ - './router', - './layout', - './reports', - './header-view', - './search-view', - './list-view', - './list-footer-view' -], function (Router, Layout, Reports, HeaderView, SearchView, ListView, ListFooterView) { - - var App = new Marionette.Application(), - init = function (options) { - // Collection - this.reports = new Reports(); - - // Router - this.router = new Router({ reports: this.reports }); - - // Layout - this.layout = new Layout({ el: options.el }); - this.layout.render(); - - // Header View - this.headerView = new HeaderView({ collection: this.reports }); - this.layout.headerRegion.show(this.headerView); - - // Search View - this.searchView = new SearchView({ - collection: this.reports, - router: this.router - }); - this.layout.searchRegion.show(this.searchView); - - // List View - this.listView = new ListView({ collection: this.reports }); - this.layout.listRegion.show(this.listView); - - // List Footer View - this.listFooterView = new ListFooterView({ collection: this.reports }); - this.layout.listFooterRegion.show(this.listFooterView); - - // Go! - Backbone.history.start({ - pushState: true, - root: options.urlRoot - }); - }; - - App.on('start', function (options) { - window.requestMessages().done(function () { - init.call(App, options); - }); +import Backbone from 'backbone'; +import Marionette from 'backbone.marionette'; +import Router from './router'; +import Layout from './layout'; +import Reports from './reports'; +import HeaderView from './header-view'; +import SearchView from './search-view'; +import ListView from './list-view'; +import ListFooterView from './list-footer-view'; + +var App = new Marionette.Application(), + init = function (options) { + // Collection + this.reports = new Reports(); + + // Router + this.router = new Router({ reports: this.reports }); + + // Layout + this.layout = new Layout({ el: options.el }); + this.layout.render(); + + // Header View + this.headerView = new HeaderView({ collection: this.reports }); + this.layout.headerRegion.show(this.headerView); + + // Search View + this.searchView = new SearchView({ + collection: this.reports, + router: this.router + }); + this.layout.searchRegion.show(this.searchView); + + // List View + this.listView = new ListView({ collection: this.reports }); + this.layout.listRegion.show(this.listView); + + // List Footer View + this.listFooterView = new ListFooterView({ collection: this.reports }); + this.layout.listFooterRegion.show(this.listFooterView); + + // Go! + Backbone.history.start({ + pushState: true, + root: options.urlRoot + }); + }; + +App.on('start', function (options) { + window.requestMessages().done(function () { + init.call(App, options); }); +}); + +export default App; - return App; -}); diff --git a/server/sonar-web/src/main/js/apps/computation/header-view.js b/server/sonar-web/src/main/js/apps/computation/header-view.js index 8e010c0eded..570ea82cde2 100644 --- a/server/sonar-web/src/main/js/apps/computation/header-view.js +++ b/server/sonar-web/src/main/js/apps/computation/header-view.js @@ -1,9 +1,8 @@ -define([ - './templates' -], function () { - - return Marionette.ItemView.extend({ - template: Templates['computation-header'] - }); +import Marionette from 'backbone.marionette'; +import './templates'; +export default Marionette.ItemView.extend({ + template: Templates['computation-header'] }); + + diff --git a/server/sonar-web/src/main/js/apps/computation/layout.js b/server/sonar-web/src/main/js/apps/computation/layout.js index 2e7edcd22bf..7ac5b7007bd 100644 --- a/server/sonar-web/src/main/js/apps/computation/layout.js +++ b/server/sonar-web/src/main/js/apps/computation/layout.js @@ -1,16 +1,15 @@ -define([ - './templates' -], function () { +import Marionette from 'backbone.marionette'; +import './templates'; - return Marionette.LayoutView.extend({ - template: Templates['computation-layout'], - - regions: { - headerRegion: '#computation-header', - searchRegion: '#computation-search', - listRegion: '#computation-list', - listFooterRegion: '#computation-list-footer' - } - }); +export default Marionette.LayoutView.extend({ + template: Templates['computation-layout'], + regions: { + headerRegion: '#computation-header', + searchRegion: '#computation-search', + listRegion: '#computation-list', + listFooterRegion: '#computation-list-footer' + } }); + + diff --git a/server/sonar-web/src/main/js/apps/computation/list-footer-view.js b/server/sonar-web/src/main/js/apps/computation/list-footer-view.js index 5034f25a3e8..89ee3120934 100644 --- a/server/sonar-web/src/main/js/apps/computation/list-footer-view.js +++ b/server/sonar-web/src/main/js/apps/computation/list-footer-view.js @@ -1,34 +1,34 @@ -define([ - './templates' -], function () { - - return Marionette.ItemView.extend({ - template: Templates['computation-list-footer'], - - collectionEvents: { - 'all': 'render' - }, - - events: { - 'click #computation-fetch-more': 'onMoreClick' - }, - - onMoreClick: function (e) { - e.preventDefault(); - this.fetchMore(); - }, - - fetchMore: function () { - this.collection.fetchMore(); - }, - - serializeData: function () { - return _.extend(Marionette.ItemView.prototype.serializeData.apply(this, arguments), { - total: this.collection.total, - count: this.collection.length, - more: this.collection.hasMore() - }); - } - }); +import _ from 'underscore'; +import Marionette from 'backbone.marionette'; +import './templates'; +export default Marionette.ItemView.extend({ + template: Templates['computation-list-footer'], + + collectionEvents: { + 'all': 'render' + }, + + events: { + 'click #computation-fetch-more': 'onMoreClick' + }, + + onMoreClick: function (e) { + e.preventDefault(); + this.fetchMore(); + }, + + fetchMore: function () { + this.collection.fetchMore(); + }, + + serializeData: function () { + return _.extend(Marionette.ItemView.prototype.serializeData.apply(this, arguments), { + total: this.collection.total, + count: this.collection.length, + more: this.collection.hasMore() + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/computation/list-item-view.js b/server/sonar-web/src/main/js/apps/computation/list-item-view.js index afcf2f15d3f..e891effd244 100644 --- a/server/sonar-web/src/main/js/apps/computation/list-item-view.js +++ b/server/sonar-web/src/main/js/apps/computation/list-item-view.js @@ -1,27 +1,27 @@ -define([ - './templates' -], function () { +import _ from 'underscore'; +import Marionette from 'backbone.marionette'; +import './templates'; - return Marionette.ItemView.extend({ - tagName: 'li', - className: 'panel', - template: Templates['computation-list-item'], +export default Marionette.ItemView.extend({ + tagName: 'li', + className: 'panel', + template: Templates['computation-list-item'], - onRender: function () { - this.$el.attr('data-id', this.model.id); - this.$el.toggleClass('panel-danger', this.model.isDanger()); - this.$('[data-toggle="tooltip"]').tooltip({ container: 'body', placement: 'bottom' }); - }, + onRender: function () { + this.$el.attr('data-id', this.model.id); + this.$el.toggleClass('panel-danger', this.model.isDanger()); + this.$('[data-toggle="tooltip"]').tooltip({ container: 'body', placement: 'bottom' }); + }, - onDestroy: function () { - this.$('[data-toggle="tooltip"]').tooltip('destroy'); - }, - - serializeData: function () { - return _.extend(Marionette.ItemView.prototype.serializeData.apply(this, arguments), { - duration: this.model.getDuration() - }); - } - }); + onDestroy: function () { + this.$('[data-toggle="tooltip"]').tooltip('destroy'); + }, + serializeData: function () { + return _.extend(Marionette.ItemView.prototype.serializeData.apply(this, arguments), { + duration: this.model.getDuration() + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/computation/list-view.js b/server/sonar-web/src/main/js/apps/computation/list-view.js index 24878864d30..695bf2ac034 100644 --- a/server/sonar-web/src/main/js/apps/computation/list-view.js +++ b/server/sonar-web/src/main/js/apps/computation/list-view.js @@ -1,11 +1,10 @@ -define([ - './list-item-view', - './templates' -], function (ListItemView) { - - return Marionette.CollectionView.extend({ - tagName: 'ul', - childView: ListItemView - }); +import Marionette from 'backbone.marionette'; +import ListItemView from './list-item-view'; +import './templates'; +export default Marionette.CollectionView.extend({ + tagName: 'ul', + childView: ListItemView }); + + diff --git a/server/sonar-web/src/main/js/apps/computation/report.js b/server/sonar-web/src/main/js/apps/computation/report.js index 2eac3f23e84..9c1ca5258d0 100644 --- a/server/sonar-web/src/main/js/apps/computation/report.js +++ b/server/sonar-web/src/main/js/apps/computation/report.js @@ -1,27 +1,27 @@ -define(function () { +import Backbone from 'backbone'; - return Backbone.Model.extend({ - idAttribute: 'key', +export default Backbone.Model.extend({ + idAttribute: 'key', - getDuration: function () { - var duration = null; - if (this.has('startedAt')) { - var startedAtMoment = moment(this.get('startedAt')), - finishedAtMoment = moment(this.get('finishedAt') || new Date()), - diff = finishedAtMoment.diff(startedAtMoment); - duration = { - seconds: Math.floor(diff / 1000) % 60, - minutes: Math.floor(diff / (1000 * 60)) % 60, - hours: Math.floor(diff / (1000 * 60 * 60)) % 24 - }; - } - return duration; - }, - - isDanger: function () { - var dangerStatuses = ['CANCELLED', 'FAILED']; - return dangerStatuses.indexOf(this.get('status')) !== -1; + getDuration: function () { + var duration = null; + if (this.has('startedAt')) { + var startedAtMoment = moment(this.get('startedAt')), + finishedAtMoment = moment(this.get('finishedAt') || new Date()), + diff = finishedAtMoment.diff(startedAtMoment); + duration = { + seconds: Math.floor(diff / 1000) % 60, + minutes: Math.floor(diff / (1000 * 60)) % 60, + hours: Math.floor(diff / (1000 * 60 * 60)) % 24 + }; } - }); + return duration; + }, + isDanger: function () { + var dangerStatuses = ['CANCELLED', 'FAILED']; + return dangerStatuses.indexOf(this.get('status')) !== -1; + } }); + + diff --git a/server/sonar-web/src/main/js/apps/computation/reports.js b/server/sonar-web/src/main/js/apps/computation/reports.js index 68b40269018..b355aedf50c 100644 --- a/server/sonar-web/src/main/js/apps/computation/reports.js +++ b/server/sonar-web/src/main/js/apps/computation/reports.js @@ -1,34 +1,34 @@ -define([ - './report' -], function (Report) { - - return Backbone.Collection.extend({ - model: Report, - url: '', - - parse: function (r) { - this.total = r.total || r.reports.length; - this.p = r.p || 1; - this.ps = r.ps; - return r.reports; - }, - - fetch: function (options) { - var opts = _.defaults(options || {}, { q: this.q }, { q: 'history', data: { ps: 250 } }); - opts.url = baseUrl + '/api/computation/' + opts.q; - this.q = opts.q; - return Backbone.Collection.prototype.fetch.call(this, opts); - }, - - fetchMore: function () { - var p = this.p + 1; - return this.fetch({ add: true, remove: false, data: { p: p, ps: this.ps } }); - }, - - hasMore: function () { - return this.total > this.p * this.ps; - } - - }); +import _ from 'underscore'; +import Backbone from 'backbone'; +import Report from './report'; + +export default Backbone.Collection.extend({ + model: Report, + url: '', + + parse: function (r) { + this.total = r.total || r.reports.length; + this.p = r.p || 1; + this.ps = r.ps; + return r.reports; + }, + + fetch: function (options) { + var opts = _.defaults(options || {}, { q: this.q }, { q: 'history', data: { ps: 250 } }); + opts.url = baseUrl + '/api/computation/' + opts.q; + this.q = opts.q; + return Backbone.Collection.prototype.fetch.call(this, opts); + }, + + fetchMore: function () { + var p = this.p + 1; + return this.fetch({ add: true, remove: false, data: { p: p, ps: this.ps } }); + }, + + hasMore: function () { + return this.total > this.p * this.ps; + } }); + + diff --git a/server/sonar-web/src/main/js/apps/computation/router.js b/server/sonar-web/src/main/js/apps/computation/router.js index 6d874801cd3..8ac31c7be90 100644 --- a/server/sonar-web/src/main/js/apps/computation/router.js +++ b/server/sonar-web/src/main/js/apps/computation/router.js @@ -1,29 +1,29 @@ -define(function () { +import Backbone from 'backbone'; - return Backbone.Router.extend({ - routes: { - '': 'index', - 'index': 'index', - 'current': 'current', - 'past': 'past' - }, +export default Backbone.Router.extend({ + routes: { + '': 'index', + 'index': 'index', + 'current': 'current', + 'past': 'past' + }, - initialize: function (options) { - this.options = options; - }, + initialize: function (options) { + this.options = options; + }, - index: function () { - this.navigate('current'); - this.current(); - }, + index: function () { + this.navigate('current'); + this.current(); + }, - current: function () { - this.options.reports.fetch({ q: 'queue' }); - }, - - past: function () { - this.options.reports.fetch({ q: 'history' }); - } - }); + current: function () { + this.options.reports.fetch({ q: 'queue' }); + }, + past: function () { + this.options.reports.fetch({ q: 'history' }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/computation/search-view.js b/server/sonar-web/src/main/js/apps/computation/search-view.js index 75ab65c4dad..1e896df0c16 100644 --- a/server/sonar-web/src/main/js/apps/computation/search-view.js +++ b/server/sonar-web/src/main/js/apps/computation/search-view.js @@ -1,34 +1,34 @@ -define([ - './templates' -], function () { - - return Marionette.ItemView.extend({ - template: Templates['computation-search'], - - collectionEvents: { - 'all': 'render' - }, - - events: { - 'click .js-queue': 'queue', - 'click .js-history': 'history' - }, - - queue: function (e) { - e.preventDefault(); - this.options.router.navigate('current', { trigger: true }); - }, - - history: function (e) { - e.preventDefault(); - this.options.router.navigate('past', { trigger: true }); - }, - - serializeData: function () { - return _.extend(Marionette.ItemView.prototype.serializeData.apply(this, arguments), { - tab: this.collection.q - }); - } - }); +import _ from 'underscore'; +import Marionette from 'backbone.marionette'; +import './templates'; +export default Marionette.ItemView.extend({ + template: Templates['computation-search'], + + collectionEvents: { + 'all': 'render' + }, + + events: { + 'click .js-queue': 'queue', + 'click .js-history': 'history' + }, + + queue: function (e) { + e.preventDefault(); + this.options.router.navigate('current', { trigger: true }); + }, + + history: function (e) { + e.preventDefault(); + this.options.router.navigate('past', { trigger: true }); + }, + + serializeData: function () { + return _.extend(Marionette.ItemView.prototype.serializeData.apply(this, arguments), { + tab: this.collection.q + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/custom-measures/app.jsx b/server/sonar-web/src/main/js/apps/custom-measures/app.js similarity index 96% rename from server/sonar-web/src/main/js/apps/custom-measures/app.jsx rename to server/sonar-web/src/main/js/apps/custom-measures/app.js index 1a0d965348e..5d6c1c2b16c 100644 --- a/server/sonar-web/src/main/js/apps/custom-measures/app.jsx +++ b/server/sonar-web/src/main/js/apps/custom-measures/app.js @@ -1,3 +1,4 @@ +import Marionette from 'backbone.marionette'; import Layout from './layout'; import CustomMeasures from './custom-measures'; import HeaderView from './header-view'; diff --git a/server/sonar-web/src/main/js/apps/custom-measures/create-view.js b/server/sonar-web/src/main/js/apps/custom-measures/create-view.js index d7461fe7158..6e113b4911f 100644 --- a/server/sonar-web/src/main/js/apps/custom-measures/create-view.js +++ b/server/sonar-web/src/main/js/apps/custom-measures/create-view.js @@ -1,32 +1,30 @@ -define([ - './custom-measure', - './form-view' -], function (CustomMeasure, FormView) { +import CustomMeasure from './custom-measure'; +import FormView from './form-view'; - return FormView.extend({ - - sendRequest: function () { - var that = this, - customMeasure = new CustomMeasure({ - metricId: this.$('#create-custom-measure-metric').val(), - value: this.$('#create-custom-measure-value').val(), - description: this.$('#create-custom-measure-description').val(), - projectId: this.options.projectId - }); - this.disableForm(); - return customMeasure.save(null, { - statusCode: { - // do not show global error - 400: null - } - }).done(function () { - that.collection.refresh(); - that.destroy(); - }).fail(function (jqXHR) { - that.enableForm(); - that.showErrors(jqXHR.responseJSON.errors, jqXHR.responseJSON.warnings); - }); - } - }); +export default FormView.extend({ + sendRequest: function () { + var that = this, + customMeasure = new CustomMeasure({ + metricId: this.$('#create-custom-measure-metric').val(), + value: this.$('#create-custom-measure-value').val(), + description: this.$('#create-custom-measure-description').val(), + projectId: this.options.projectId + }); + this.disableForm(); + return customMeasure.save(null, { + statusCode: { + // do not show global error + 400: null + } + }).done(function () { + that.collection.refresh(); + that.destroy(); + }).fail(function (jqXHR) { + that.enableForm(); + that.showErrors(jqXHR.responseJSON.errors, jqXHR.responseJSON.warnings); + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/custom-measures/custom-measure.js b/server/sonar-web/src/main/js/apps/custom-measures/custom-measure.js index fce8bf4fbdf..17565de6cfe 100644 --- a/server/sonar-web/src/main/js/apps/custom-measures/custom-measure.js +++ b/server/sonar-web/src/main/js/apps/custom-measures/custom-measure.js @@ -1,37 +1,38 @@ -define(function () { +import _ from 'underscore'; +import Backbone from 'backbone'; - return Backbone.Model.extend({ - idAttribute: 'id', +export default Backbone.Model.extend({ + idAttribute: 'id', - urlRoot: function () { - return baseUrl + '/api/custom_measures'; - }, + urlRoot: function () { + return baseUrl + '/api/custom_measures'; + }, - sync: function (method, model, options) { - var opts = options || {}; - if (method === 'create') { - _.defaults(opts, { - url: this.urlRoot() + '/create', - type: 'POST', - data: _.pick(model.toJSON(), 'metricId', 'value', 'description', 'projectId') - }); - } - if (method === 'update') { - _.defaults(opts, { - url: this.urlRoot() + '/update', - type: 'POST', - data: _.pick(model.toJSON(), 'id', 'value', 'description') - }); - } - if (method === 'delete') { - _.defaults(opts, { - url: this.urlRoot() + '/delete', - type: 'POST', - data: { id: this.id } - }); - } - return Backbone.ajax(opts); + sync: function (method, model, options) { + var opts = options || {}; + if (method === 'create') { + _.defaults(opts, { + url: this.urlRoot() + '/create', + type: 'POST', + data: _.pick(model.toJSON(), 'metricId', 'value', 'description', 'projectId') + }); } - }); - + if (method === 'update') { + _.defaults(opts, { + url: this.urlRoot() + '/update', + type: 'POST', + data: _.pick(model.toJSON(), 'id', 'value', 'description') + }); + } + if (method === 'delete') { + _.defaults(opts, { + url: this.urlRoot() + '/delete', + type: 'POST', + data: { id: this.id } + }); + } + return Backbone.ajax(opts); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/custom-measures/custom-measures.js b/server/sonar-web/src/main/js/apps/custom-measures/custom-measures.js index 2febc1ea652..14d51c6cf33 100644 --- a/server/sonar-web/src/main/js/apps/custom-measures/custom-measures.js +++ b/server/sonar-web/src/main/js/apps/custom-measures/custom-measures.js @@ -1,52 +1,52 @@ -define([ - './custom-measure' -], function (CustomMeasure) { - - return Backbone.Collection.extend({ - model: CustomMeasure, - - initialize: function (options) { - this.projectId = options.projectId; - }, - - url: function () { - return baseUrl + '/api/custom_measures/search'; - }, - - parse: function (r) { - this.total = r.total; - this.p = r.p; - this.ps = r.ps; - return r.customMeasures; - }, - - fetch: function (options) { - var opts = _.defaults(options || {}, { data: {} }); - this.q = opts.data.q; - opts.data.projectId = this.projectId; - return this._super(opts); - }, - - fetchMore: function () { - var p = this.p + 1; - return this.fetch({ add: true, remove: false, data: { p: p, ps: this.ps, q: this.q } }); - }, - - refresh: function () { - return this.fetch({ reset: true, data: { q: this.q } }); - }, - - hasMore: function () { - return this.total > this.p * this.ps; - }, - - getTakenMetrics: function () { - var metrics = this.map(function (model) { - return model.get('metric').id; - }); - return _.uniq(metrics); - } - - }); +import _ from 'underscore'; +import Backbone from 'backbone'; +import CustomMeasure from './custom-measure'; + +export default Backbone.Collection.extend({ + model: CustomMeasure, + + initialize: function (options) { + this.projectId = options.projectId; + }, + + url: function () { + return baseUrl + '/api/custom_measures/search'; + }, + + parse: function (r) { + this.total = r.total; + this.p = r.p; + this.ps = r.ps; + return r.customMeasures; + }, + + fetch: function (options) { + var opts = _.defaults(options || {}, { data: {} }); + this.q = opts.data.q; + opts.data.projectId = this.projectId; + return this._super(opts); + }, + + fetchMore: function () { + var p = this.p + 1; + return this.fetch({ add: true, remove: false, data: { p: p, ps: this.ps, q: this.q } }); + }, + + refresh: function () { + return this.fetch({ reset: true, data: { q: this.q } }); + }, + + hasMore: function () { + return this.total > this.p * this.ps; + }, + + getTakenMetrics: function () { + var metrics = this.map(function (model) { + return model.get('metric').id; + }); + return _.uniq(metrics); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/custom-measures/delete-view.js b/server/sonar-web/src/main/js/apps/custom-measures/delete-view.js index 1838b83e044..6798c1259a3 100644 --- a/server/sonar-web/src/main/js/apps/custom-measures/delete-view.js +++ b/server/sonar-web/src/main/js/apps/custom-measures/delete-view.js @@ -1,32 +1,30 @@ -define([ - 'components/common/modal-form', - './templates' -], function (ModalForm) { +import ModalForm from 'components/common/modal-form'; +import './templates'; - return ModalForm.extend({ - template: Templates['custom-measures-delete'], +export default ModalForm.extend({ + template: Templates['custom-measures-delete'], - onFormSubmit: function (e) { - this._super(e); - this.sendRequest(); - }, - - sendRequest: function () { - var that = this, - collection = this.model.collection; - return this.model.destroy({ - wait: true, - statusCode: { - // do not show global error - 400: null - } - }).done(function () { - collection.refresh(); - that.destroy(); - }).fail(function (jqXHR) { - that.showErrors(jqXHR.responseJSON.errors, jqXHR.responseJSON.warnings); - }); - } - }); + onFormSubmit: function (e) { + this._super(e); + this.sendRequest(); + }, + sendRequest: function () { + var that = this, + collection = this.model.collection; + return this.model.destroy({ + wait: true, + statusCode: { + // do not show global error + 400: null + } + }).done(function () { + collection.refresh(); + that.destroy(); + }).fail(function (jqXHR) { + that.showErrors(jqXHR.responseJSON.errors, jqXHR.responseJSON.warnings); + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/custom-measures/form-view.js b/server/sonar-web/src/main/js/apps/custom-measures/form-view.js index 30ed30082b9..d86e0176b30 100644 --- a/server/sonar-web/src/main/js/apps/custom-measures/form-view.js +++ b/server/sonar-web/src/main/js/apps/custom-measures/form-view.js @@ -1,52 +1,51 @@ -define([ - 'components/common/modal-form', - 'apps/metrics/metrics', - './templates' -], function (ModalForm, Metrics) { - - return ModalForm.extend({ - template: Templates['custom-measures-form'], - - initialize: function () { - this.metrics = new Metrics(); - this.listenTo(this.metrics, 'reset', this.render); - this.metrics.fetch({ reset: true }); - }, - - onRender: function () { - this._super(); - this.$('[data-toggle="tooltip"]').tooltip({ container: 'body', placement: 'bottom' }); - this.$('#create-custom-measure-metric').select2({ - width: '250px', - minimumResultsForSearch: 20 - }); - }, - - onDestroy: function () { - this._super(); - this.$('[data-toggle="tooltip"]').tooltip('destroy'); - }, - - onFormSubmit: function (e) { - this._super(e); - this.sendRequest(); - }, - - getAvailableMetrics: function () { - var takenMetrics = this.collection.getTakenMetrics(); - return this.metrics.toJSON().filter(function (metric) { - return takenMetrics.indexOf(metric.id) === -1; - }); - }, - - serializeData: function () { - var metrics = this.getAvailableMetrics(), - isNew = !this.model; - return _.extend(this._super(), { - metrics: metrics, - canCreateMetric: !isNew || (isNew && metrics.length > 0) - }); - } - }); - +import _ from 'underscore'; +import ModalForm from 'components/common/modal-form'; +import Metrics from 'apps/metrics/metrics'; +import './templates'; + +export default ModalForm.extend({ + template: Templates['custom-measures-form'], + + initialize: function () { + this.metrics = new Metrics(); + this.listenTo(this.metrics, 'reset', this.render); + this.metrics.fetch({ reset: true }); + }, + + onRender: function () { + this._super(); + this.$('[data-toggle="tooltip"]').tooltip({ container: 'body', placement: 'bottom' }); + this.$('#create-custom-measure-metric').select2({ + width: '250px', + minimumResultsForSearch: 20 + }); + }, + + onDestroy: function () { + this._super(); + this.$('[data-toggle="tooltip"]').tooltip('destroy'); + }, + + onFormSubmit: function (e) { + this._super(e); + this.sendRequest(); + }, + + getAvailableMetrics: function () { + var takenMetrics = this.collection.getTakenMetrics(); + return this.metrics.toJSON().filter(function (metric) { + return takenMetrics.indexOf(metric.id) === -1; + }); + }, + + serializeData: function () { + var metrics = this.getAvailableMetrics(), + isNew = !this.model; + return _.extend(this._super(), { + metrics: metrics, + canCreateMetric: !isNew || (isNew && metrics.length > 0) + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/custom-measures/header-view.js b/server/sonar-web/src/main/js/apps/custom-measures/header-view.js index 8b22efcec5a..02ee2a795c3 100644 --- a/server/sonar-web/src/main/js/apps/custom-measures/header-view.js +++ b/server/sonar-web/src/main/js/apps/custom-measures/header-view.js @@ -1,26 +1,25 @@ -define([ - './create-view', - './templates' -], function (CreateView) { +import Marionette from 'backbone.marionette'; +import CreateView from './create-view'; +import './templates'; - return Marionette.ItemView.extend({ - template: Templates['custom-measures-header'], +export default Marionette.ItemView.extend({ + template: Templates['custom-measures-header'], - events: { - 'click #custom-measures-create': 'onCreateClick' - }, + events: { + 'click #custom-measures-create': 'onCreateClick' + }, - onCreateClick: function (e) { - e.preventDefault(); - this.createCustomMeasure(); - }, - - createCustomMeasure: function () { - new CreateView({ - collection: this.collection, - projectId: this.options.projectId - }).render(); - } - }); + onCreateClick: function (e) { + e.preventDefault(); + this.createCustomMeasure(); + }, + createCustomMeasure: function () { + new CreateView({ + collection: this.collection, + projectId: this.options.projectId + }).render(); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/custom-measures/layout.js b/server/sonar-web/src/main/js/apps/custom-measures/layout.js index b4aa4ece791..92ac6de28b1 100644 --- a/server/sonar-web/src/main/js/apps/custom-measures/layout.js +++ b/server/sonar-web/src/main/js/apps/custom-measures/layout.js @@ -1,15 +1,14 @@ -define([ - './templates' -], function () { +import Marionette from 'backbone.marionette'; +import './templates'; - return Marionette.LayoutView.extend({ - template: Templates['custom-measures-layout'], - - regions: { - headerRegion: '#custom-measures-header', - listRegion: '#custom-measures-list', - listFooterRegion: '#custom-measures-list-footer' - } - }); +export default Marionette.LayoutView.extend({ + template: Templates['custom-measures-layout'], + regions: { + headerRegion: '#custom-measures-header', + listRegion: '#custom-measures-list', + listFooterRegion: '#custom-measures-list-footer' + } }); + + diff --git a/server/sonar-web/src/main/js/apps/custom-measures/list-footer-view.js b/server/sonar-web/src/main/js/apps/custom-measures/list-footer-view.js index d66c27ad335..e917ddb294a 100644 --- a/server/sonar-web/src/main/js/apps/custom-measures/list-footer-view.js +++ b/server/sonar-web/src/main/js/apps/custom-measures/list-footer-view.js @@ -1,34 +1,34 @@ -define([ - './templates' -], function () { - - return Marionette.ItemView.extend({ - template: Templates['custom-measures-list-footer'], - - collectionEvents: { - 'all': 'render' - }, - - events: { - 'click #custom-measures-fetch-more': 'onMoreClick' - }, - - onMoreClick: function (e) { - e.preventDefault(); - this.fetchMore(); - }, - - fetchMore: function () { - this.collection.fetchMore(); - }, - - serializeData: function () { - return _.extend(this._super(), { - total: this.collection.total, - count: this.collection.length, - more: this.collection.hasMore() - }); - } - }); +import _ from 'underscore'; +import Marionette from 'backbone.marionette'; +import './templates'; +export default Marionette.ItemView.extend({ + template: Templates['custom-measures-list-footer'], + + collectionEvents: { + 'all': 'render' + }, + + events: { + 'click #custom-measures-fetch-more': 'onMoreClick' + }, + + onMoreClick: function (e) { + e.preventDefault(); + this.fetchMore(); + }, + + fetchMore: function () { + this.collection.fetchMore(); + }, + + serializeData: function () { + return _.extend(this._super(), { + total: this.collection.total, + count: this.collection.length, + more: this.collection.hasMore() + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/custom-measures/list-item-view.js b/server/sonar-web/src/main/js/apps/custom-measures/list-item-view.js index 32ba7e691d8..7b7cb5aa6e1 100644 --- a/server/sonar-web/src/main/js/apps/custom-measures/list-item-view.js +++ b/server/sonar-web/src/main/js/apps/custom-measures/list-item-view.js @@ -1,47 +1,46 @@ -define([ - './update-view', - './delete-view', - './templates' -], function (UpdateView, DeleteView) { - - return Marionette.ItemView.extend({ - tagName: 'tr', - template: Templates['custom-measures-list-item'], - - events: { - 'click .js-custom-measure-update': 'onUpdateClick', - 'click .js-custom-measure-delete': 'onDeleteClick' - }, - - onRender: function () { - this.$el.attr('data-id', this.model.id); - this.$('[data-toggle="tooltip"]').tooltip({ container: 'body', placement: 'bottom' }); - }, - - onDestroy: function () { - this.$('[data-toggle="tooltip"]').tooltip('destroy'); - }, - - onUpdateClick: function (e) { - e.preventDefault(); - this.updateCustomMeasure(); - }, - - onDeleteClick: function (e) { - e.preventDefault(); - this.deleteCustomMeasure(); - }, - - updateCustomMeasure: function () { - new UpdateView({ - model: this.model, - collection: this.model.collection - }).render(); - }, - - deleteCustomMeasure: function () { - new DeleteView({ model: this.model }).render(); - } - }); - +import Marionette from 'backbone.marionette'; +import UpdateView from './update-view'; +import DeleteView from './delete-view'; +import './templates'; + +export default Marionette.ItemView.extend({ + tagName: 'tr', + template: Templates['custom-measures-list-item'], + + events: { + 'click .js-custom-measure-update': 'onUpdateClick', + 'click .js-custom-measure-delete': 'onDeleteClick' + }, + + onRender: function () { + this.$el.attr('data-id', this.model.id); + this.$('[data-toggle="tooltip"]').tooltip({ container: 'body', placement: 'bottom' }); + }, + + onDestroy: function () { + this.$('[data-toggle="tooltip"]').tooltip('destroy'); + }, + + onUpdateClick: function (e) { + e.preventDefault(); + this.updateCustomMeasure(); + }, + + onDeleteClick: function (e) { + e.preventDefault(); + this.deleteCustomMeasure(); + }, + + updateCustomMeasure: function () { + new UpdateView({ + model: this.model, + collection: this.model.collection + }).render(); + }, + + deleteCustomMeasure: function () { + new DeleteView({ model: this.model }).render(); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/custom-measures/list-view.js b/server/sonar-web/src/main/js/apps/custom-measures/list-view.js index 986ad559e98..2d38eae4d1d 100644 --- a/server/sonar-web/src/main/js/apps/custom-measures/list-view.js +++ b/server/sonar-web/src/main/js/apps/custom-measures/list-view.js @@ -1,12 +1,11 @@ -define([ - './list-item-view', - './templates' -], function (ListItemView) { - - return Marionette.CompositeView.extend({ - template: Templates['custom-measures-list'], - childView: ListItemView, - childViewContainer: 'tbody' - }); +import Marionette from 'backbone.marionette'; +import ListItemView from './list-item-view'; +import './templates'; +export default Marionette.CompositeView.extend({ + template: Templates['custom-measures-list'], + childView: ListItemView, + childViewContainer: 'tbody' }); + + diff --git a/server/sonar-web/src/main/js/apps/custom-measures/update-view.js b/server/sonar-web/src/main/js/apps/custom-measures/update-view.js index 301c083e5e6..4b3fae8384b 100644 --- a/server/sonar-web/src/main/js/apps/custom-measures/update-view.js +++ b/server/sonar-web/src/main/js/apps/custom-measures/update-view.js @@ -1,29 +1,27 @@ -define([ - './form-view' -], function (FormView) { +import FormView from './form-view'; - return FormView.extend({ - - sendRequest: function () { - var that = this; - this.model.set({ - value: this.$('#create-custom-measure-value').val(), - description: this.$('#create-custom-measure-description').val() - }); - this.disableForm(); - return this.model.save(null, { - statusCode: { - // do not show global error - 400: null - } - }).done(function () { - that.collection.refresh(); - that.destroy(); - }).fail(function (jqXHR) { - that.enableForm(); - that.showErrors(jqXHR.responseJSON.errors, jqXHR.responseJSON.warnings); - }); - } - }); +export default FormView.extend({ + sendRequest: function () { + var that = this; + this.model.set({ + value: this.$('#create-custom-measure-value').val(), + description: this.$('#create-custom-measure-description').val() + }); + this.disableForm(); + return this.model.save(null, { + statusCode: { + // do not show global error + 400: null + } + }).done(function () { + that.collection.refresh(); + that.destroy(); + }).fail(function (jqXHR) { + that.enableForm(); + that.showErrors(jqXHR.responseJSON.errors, jqXHR.responseJSON.warnings); + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/drilldown/app.js b/server/sonar-web/src/main/js/apps/drilldown/app.js index 6c7bb383a60..f860933924f 100644 --- a/server/sonar-web/src/main/js/apps/drilldown/app.js +++ b/server/sonar-web/src/main/js/apps/drilldown/app.js @@ -1,32 +1,30 @@ -define([ - 'components/source-viewer/main' -], function (SourceViewer) { +import $ from 'jquery'; +import Marionette from 'backbone.marionette'; +import SourceViewer from '../../components/source-viewer/main'; - var $ = jQuery, - App = new Marionette.Application(), - init = function (options) { - App.addRegions({ viewerRegion: options.el }); - $('.js-drilldown-link').on('click', function (e) { - e.preventDefault(); - $(e.currentTarget).closest('table').find('.selected').removeClass('selected'); - $(e.currentTarget).closest('tr').addClass('selected'); - var uuid = $(e.currentTarget).data('uuid'), - viewer = new SourceViewer(); - App.viewerRegion.show(viewer); - viewer.open(uuid); - if (window.drilldown.period != null) { - viewer.on('loaded', function () { - viewer.filterLinesByDate(window.drilldown.period, window.drilldown.periodName); - }); - } - }); - }; +var App = new Marionette.Application(), + init = function (options) { + App.addRegions({ viewerRegion: options.el }); + $('.js-drilldown-link').on('click', function (e) { + e.preventDefault(); + $(e.currentTarget).closest('table').find('.selected').removeClass('selected'); + $(e.currentTarget).closest('tr').addClass('selected'); + var uuid = $(e.currentTarget).data('uuid'), + viewer = new SourceViewer(); + App.viewerRegion.show(viewer); + viewer.open(uuid); + if (window.drilldown.period != null) { + viewer.on('loaded', function () { + viewer.filterLinesByDate(window.drilldown.period, window.drilldown.periodName); + }); + } + }); + }; - App.on('start', function (options) { - window.requestMessages().done(function () { - init.call(App, options); - }); +App.on('start', function (options) { + window.requestMessages().done(function () { + init.call(App, options); }); - - return App; }); + +export default App; diff --git a/server/sonar-web/src/main/js/apps/global-permissions/app.jsx b/server/sonar-web/src/main/js/apps/global-permissions/app.jsx index 28dc73b7f42..f35eeceda98 100644 --- a/server/sonar-web/src/main/js/apps/global-permissions/app.jsx +++ b/server/sonar-web/src/main/js/apps/global-permissions/app.jsx @@ -1,8 +1,6 @@ import React from 'react'; import Main from './main'; -const $ = jQuery; - export default { start(options) { window.requestMessages().done(() => { diff --git a/server/sonar-web/src/main/js/apps/global-permissions/groups-view.js b/server/sonar-web/src/main/js/apps/global-permissions/groups-view.js index ef87bb94186..f6369ea191a 100644 --- a/server/sonar-web/src/main/js/apps/global-permissions/groups-view.js +++ b/server/sonar-web/src/main/js/apps/global-permissions/groups-view.js @@ -1,56 +1,54 @@ -define([ - 'components/common/modals', - 'components/common/select-list', - './templates' -], function (Modal) { +import Modal from 'components/common/modals'; +import 'components/common/select-list'; +import './templates'; - function getSearchUrl(permission, project) { - var url = baseUrl + '/api/permissions/groups?ps=100&permission=' + permission; - if (project) { - url = url + '&projectId=' + project; - } - return url; +function getSearchUrl (permission, project) { + var url = baseUrl + '/api/permissions/groups?ps=100&permission=' + permission; + if (project) { + url = url + '&projectId=' + project; } + return url; +} - function getExtra (permission, project) { - var extra = { permission: permission }; - if (project) { - extra.projectId = project; - } - return extra; +function getExtra (permission, project) { + var extra = { permission: permission }; + if (project) { + extra.projectId = project; } + return extra; +} - return Modal.extend({ - template: Templates['global-permissions-groups'], +export default Modal.extend({ + template: Templates['global-permissions-groups'], - onRender: function () { - this._super(); - new window.SelectList({ - el: this.$('#global-permissions-groups'), - width: '100%', - readOnly: false, - focusSearch: false, - format: function (item) { - return item.name; - }, - queryParam: 'q', - searchUrl: getSearchUrl(this.options.permission, this.options.project), - selectUrl: baseUrl + '/api/permissions/add_group', - deselectUrl: baseUrl + '/api/permissions/remove_group', - extra: getExtra(this.options.permission, this.options.project), - selectParameter: 'groupName', - selectParameterValue: 'name', - parse: function (r) { - this.more = false; - return r.groups; - } - }); - }, - - onDestroy: function () { - this.options.refresh(); - this._super(); - } - }); + onRender: function () { + this._super(); + new window.SelectList({ + el: this.$('#global-permissions-groups'), + width: '100%', + readOnly: false, + focusSearch: false, + format: function (item) { + return item.name; + }, + queryParam: 'q', + searchUrl: getSearchUrl(this.options.permission, this.options.project), + selectUrl: baseUrl + '/api/permissions/add_group', + deselectUrl: baseUrl + '/api/permissions/remove_group', + extra: getExtra(this.options.permission, this.options.project), + selectParameter: 'groupName', + selectParameterValue: 'name', + parse: function (r) { + this.more = false; + return r.groups; + } + }); + }, + onDestroy: function () { + this.options.refresh(); + this._super(); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/global-permissions/main.jsx b/server/sonar-web/src/main/js/apps/global-permissions/main.jsx index 8712c979465..11f6b032ebf 100644 --- a/server/sonar-web/src/main/js/apps/global-permissions/main.jsx +++ b/server/sonar-web/src/main/js/apps/global-permissions/main.jsx @@ -1,8 +1,7 @@ +import $ from 'jquery'; import React from 'react'; import PermissionsList from './permissions-list'; -let $ = jQuery; - export default React.createClass({ getInitialState() { return { permissions: [] }; diff --git a/server/sonar-web/src/main/js/apps/global-permissions/permission-users-groups-mixin.jsx b/server/sonar-web/src/main/js/apps/global-permissions/permission-users-groups-mixin.jsx index ec7f415d83a..91da5b747bb 100644 --- a/server/sonar-web/src/main/js/apps/global-permissions/permission-users-groups-mixin.jsx +++ b/server/sonar-web/src/main/js/apps/global-permissions/permission-users-groups-mixin.jsx @@ -1,7 +1,5 @@ import React from 'react'; -let $ = jQuery; - export default { propTypes: { permission: React.PropTypes.object.isRequired, diff --git a/server/sonar-web/src/main/js/apps/global-permissions/permission-users.jsx b/server/sonar-web/src/main/js/apps/global-permissions/permission-users.jsx index 56f52feed0d..aaed2ab0014 100644 --- a/server/sonar-web/src/main/js/apps/global-permissions/permission-users.jsx +++ b/server/sonar-web/src/main/js/apps/global-permissions/permission-users.jsx @@ -1,6 +1,5 @@ import React from 'react'; import PermissionsUsersGroupsMixin from './permission-users-groups-mixin'; -import Avatar from 'components/shared/avatar'; import UsersView from './users-view'; export default React.createClass({ diff --git a/server/sonar-web/src/main/js/apps/global-permissions/permission.jsx b/server/sonar-web/src/main/js/apps/global-permissions/permission.jsx index ac259f521de..1a5f993a90e 100644 --- a/server/sonar-web/src/main/js/apps/global-permissions/permission.jsx +++ b/server/sonar-web/src/main/js/apps/global-permissions/permission.jsx @@ -1,9 +1,8 @@ +import $ from 'jquery'; import React from 'react'; import PermissionUsers from './permission-users'; import PermissionGroups from './permission-groups'; -let $ = jQuery; - // Maximum number of displayed groups const MAX_ITEMS = 3; diff --git a/server/sonar-web/src/main/js/apps/global-permissions/users-view.js b/server/sonar-web/src/main/js/apps/global-permissions/users-view.js index 4e85024f480..61ad9371166 100644 --- a/server/sonar-web/src/main/js/apps/global-permissions/users-view.js +++ b/server/sonar-web/src/main/js/apps/global-permissions/users-view.js @@ -1,56 +1,54 @@ -define([ - 'components/common/modals', - 'components/common/select-list', - './templates' -], function (Modal) { +import Modal from 'components/common/modals'; +import 'components/common/select-list'; +import './templates'; - function getSearchUrl (permission, project) { - var url = baseUrl + '/api/permissions/users?ps=100&permission=' + permission; - if (project) { - url = url + '&projectId=' + project; - } - return url; +function getSearchUrl (permission, project) { + var url = baseUrl + '/api/permissions/users?ps=100&permission=' + permission; + if (project) { + url = url + '&projectId=' + project; } + return url; +} - function getExtra (permission, project) { - var extra = { permission: permission }; - if (project) { - extra.projectId = project; - } - return extra; +function getExtra (permission, project) { + var extra = { permission: permission }; + if (project) { + extra.projectId = project; } + return extra; +} - return Modal.extend({ - template: Templates['global-permissions-users'], +export default Modal.extend({ + template: Templates['global-permissions-users'], - onRender: function () { - this._super(); - new window.SelectList({ - el: this.$('#global-permissions-users'), - width: '100%', - readOnly: false, - focusSearch: false, - format: function (item) { - return item.name + '
' + item.login + ''; - }, - queryParam: 'q', - searchUrl: getSearchUrl(this.options.permission, this.options.project), - selectUrl: baseUrl + '/api/permissions/add_user', - deselectUrl: baseUrl + '/api/permissions/remove_user', - extra: getExtra(this.options.permission, this.options.project), - selectParameter: 'login', - selectParameterValue: 'login', - parse: function (r) { - this.more = false; - return r.users; - } - }); - }, - - onDestroy: function () { - this.options.refresh(); - this._super(); - } - }); + onRender: function () { + this._super(); + new window.SelectList({ + el: this.$('#global-permissions-users'), + width: '100%', + readOnly: false, + focusSearch: false, + format: function (item) { + return item.name + '
' + item.login + ''; + }, + queryParam: 'q', + searchUrl: getSearchUrl(this.options.permission, this.options.project), + selectUrl: baseUrl + '/api/permissions/add_user', + deselectUrl: baseUrl + '/api/permissions/remove_user', + extra: getExtra(this.options.permission, this.options.project), + selectParameter: 'login', + selectParameterValue: 'login', + parse: function (r) { + this.more = false; + return r.users; + } + }); + }, + onDestroy: function () { + this.options.refresh(); + this._super(); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/groups/app.js b/server/sonar-web/src/main/js/apps/groups/app.js index 55c6dfef534..8965f3ecea7 100644 --- a/server/sonar-web/src/main/js/apps/groups/app.js +++ b/server/sonar-web/src/main/js/apps/groups/app.js @@ -1,47 +1,46 @@ -define([ - './layout', - './groups', - './header-view', - './search-view', - './list-view', - './list-footer-view' -], function (Layout, Groups, HeaderView, SearchView, ListView, ListFooterView) { - - var App = new Marionette.Application(), - init = function (options) { - // Layout - this.layout = new Layout({ el: options.el }); - this.layout.render(); - - // Collection - this.groups = new Groups(); - - // Header View - this.headerView = new HeaderView({ collection: this.groups }); - this.layout.headerRegion.show(this.headerView); - - // Search View - this.searchView = new SearchView({ collection: this.groups }); - this.layout.searchRegion.show(this.searchView); - - // List View - this.listView = new ListView({ collection: this.groups }); - this.layout.listRegion.show(this.listView); - - // List Footer View - this.listFooterView = new ListFooterView({ collection: this.groups }); - this.layout.listFooterRegion.show(this.listFooterView); - - // Go! - this.groups.fetch(); - }; - - App.on('start', function (options) { - window.requestMessages().done(function () { - init.call(App, options); - }); +import Marionette from 'backbone.marionette'; +import Layout from './layout'; +import Groups from './groups'; +import HeaderView from './header-view'; +import SearchView from './search-view'; +import ListView from './list-view'; +import ListFooterView from './list-footer-view'; + +var App = new Marionette.Application(), + init = function (options) { + // Layout + this.layout = new Layout({ el: options.el }); + this.layout.render(); + + // Collection + this.groups = new Groups(); + + // Header View + this.headerView = new HeaderView({ collection: this.groups }); + this.layout.headerRegion.show(this.headerView); + + // Search View + this.searchView = new SearchView({ collection: this.groups }); + this.layout.searchRegion.show(this.searchView); + + // List View + this.listView = new ListView({ collection: this.groups }); + this.layout.listRegion.show(this.listView); + + // List Footer View + this.listFooterView = new ListFooterView({ collection: this.groups }); + this.layout.listFooterRegion.show(this.listFooterView); + + // Go! + this.groups.fetch(); + }; + +App.on('start', function (options) { + window.requestMessages().done(function () { + init.call(App, options); }); +}); + +export default App; - return App; -}); diff --git a/server/sonar-web/src/main/js/apps/groups/create-view.js b/server/sonar-web/src/main/js/apps/groups/create-view.js index cddde867a99..2f3edf11fa0 100644 --- a/server/sonar-web/src/main/js/apps/groups/create-view.js +++ b/server/sonar-web/src/main/js/apps/groups/create-view.js @@ -1,30 +1,28 @@ -define([ - './group', - './form-view' -], function (Group, FormView) { +import Group from './group'; +import FormView from './form-view'; - return FormView.extend({ - - sendRequest: function () { - var that = this, - group = new Group({ - name: this.$('#create-group-name').val(), - description: this.$('#create-group-description').val() - }); - this.disableForm(); - return group.save(null, { - statusCode: { - // do not show global error - 400: null - } - }).done(function () { - that.collection.refresh(); - that.destroy(); - }).fail(function (jqXHR) { - that.enableForm(); - that.showErrors(jqXHR.responseJSON.errors, jqXHR.responseJSON.warnings); - }); - } - }); +export default FormView.extend({ + sendRequest: function () { + var that = this, + group = new Group({ + name: this.$('#create-group-name').val(), + description: this.$('#create-group-description').val() + }); + this.disableForm(); + return group.save(null, { + statusCode: { + // do not show global error + 400: null + } + }).done(function () { + that.collection.refresh(); + that.destroy(); + }).fail(function (jqXHR) { + that.enableForm(); + that.showErrors(jqXHR.responseJSON.errors, jqXHR.responseJSON.warnings); + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/groups/delete-view.js b/server/sonar-web/src/main/js/apps/groups/delete-view.js index 85b33a632b5..272a0a85bbc 100644 --- a/server/sonar-web/src/main/js/apps/groups/delete-view.js +++ b/server/sonar-web/src/main/js/apps/groups/delete-view.js @@ -1,38 +1,36 @@ -define([ - 'components/common/modal-form', - './templates' -], function (ModalForm) { +import ModalForm from 'components/common/modal-form'; +import './templates'; - return ModalForm.extend({ - template: Templates['groups-delete'], +export default ModalForm.extend({ + template: Templates['groups-delete'], - onFormSubmit: function (e) { - this._super(e); - this.sendRequest(); - }, + onFormSubmit: function (e) { + this._super(e); + this.sendRequest(); + }, - sendRequest: function () { - var that = this, - collection = this.model.collection; - return this.model.destroy({ - wait: true, - statusCode: { - // do not show global error - 400: null - } - }).done(function () { - collection.total--; - that.destroy(); - }).fail(function (jqXHR) { - that.showErrors(jqXHR.responseJSON.errors, jqXHR.responseJSON.warnings); - }); - }, - - showErrors: function (errors, warnings) { - this.$('.js-modal-text').addClass('hidden'); - this.disableForm(); - this._super(errors, warnings); - } - }); + sendRequest: function () { + var that = this, + collection = this.model.collection; + return this.model.destroy({ + wait: true, + statusCode: { + // do not show global error + 400: null + } + }).done(function () { + collection.total--; + that.destroy(); + }).fail(function (jqXHR) { + that.showErrors(jqXHR.responseJSON.errors, jqXHR.responseJSON.warnings); + }); + }, + showErrors: function (errors, warnings) { + this.$('.js-modal-text').addClass('hidden'); + this.disableForm(); + this._super(errors, warnings); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/groups/form-view.js b/server/sonar-web/src/main/js/apps/groups/form-view.js index 7e3c26b98ee..5b541f1ae12 100644 --- a/server/sonar-web/src/main/js/apps/groups/form-view.js +++ b/server/sonar-web/src/main/js/apps/groups/form-view.js @@ -1,25 +1,23 @@ -define([ - 'components/common/modal-form', - './templates' -], function (ModalForm) { +import ModalForm from 'components/common/modal-form'; +import './templates'; - return ModalForm.extend({ - template: Templates['groups-form'], +export default ModalForm.extend({ + template: Templates['groups-form'], - onRender: function () { - this._super(); - this.$('[data-toggle="tooltip"]').tooltip({ container: 'body', placement: 'bottom' }); - }, + onRender: function () { + this._super(); + this.$('[data-toggle="tooltip"]').tooltip({ container: 'body', placement: 'bottom' }); + }, - onDestroy: function () { - this._super(); - this.$('[data-toggle="tooltip"]').tooltip('destroy'); - }, - - onFormSubmit: function (e) { - this._super(e); - this.sendRequest(); - } - }); + onDestroy: function () { + this._super(); + this.$('[data-toggle="tooltip"]').tooltip('destroy'); + }, + onFormSubmit: function (e) { + this._super(e); + this.sendRequest(); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/groups/group.js b/server/sonar-web/src/main/js/apps/groups/group.js index aced6727b91..89018901895 100644 --- a/server/sonar-web/src/main/js/apps/groups/group.js +++ b/server/sonar-web/src/main/js/apps/groups/group.js @@ -1,36 +1,37 @@ -define(function () { +import _ from 'underscore'; +import Backbone from 'backbone'; - return Backbone.Model.extend({ - urlRoot: function () { - return baseUrl + '/api/usergroups'; - }, +export default Backbone.Model.extend({ + urlRoot: function () { + return baseUrl + '/api/usergroups'; + }, - sync: function (method, model, options) { - var opts = options || {}; - if (method === 'create') { - _.defaults(opts, { - url: this.urlRoot() + '/create', - type: 'POST', - data: _.pick(model.toJSON(), 'name', 'description') - }); - } - if (method === 'update') { - var attrs = _.extend(_.pick(model.changed, 'name', 'description'), { id: model.id }); - _.defaults(opts, { - url: this.urlRoot() + '/update', - type: 'POST', - data: attrs - }); - } - if (method === 'delete') { - _.defaults(opts, { - url: this.urlRoot() + '/delete', - type: 'POST', - data: { id: this.id } - }); - } - return Backbone.ajax(opts); + sync: function (method, model, options) { + var opts = options || {}; + if (method === 'create') { + _.defaults(opts, { + url: this.urlRoot() + '/create', + type: 'POST', + data: _.pick(model.toJSON(), 'name', 'description') + }); } - }); - + if (method === 'update') { + var attrs = _.extend(_.pick(model.changed, 'name', 'description'), { id: model.id }); + _.defaults(opts, { + url: this.urlRoot() + '/update', + type: 'POST', + data: attrs + }); + } + if (method === 'delete') { + _.defaults(opts, { + url: this.urlRoot() + '/delete', + type: 'POST', + data: { id: this.id } + }); + } + return Backbone.ajax(opts); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/groups/groups.js b/server/sonar-web/src/main/js/apps/groups/groups.js index dcfbb8c731b..d22d3373d9a 100644 --- a/server/sonar-web/src/main/js/apps/groups/groups.js +++ b/server/sonar-web/src/main/js/apps/groups/groups.js @@ -1,40 +1,39 @@ -define([ - './group' -], function (Group) { +import Backbone from 'backbone'; +import Group from './group'; + +export default Backbone.Collection.extend({ + model: Group, + + url: function () { + return baseUrl + '/api/usergroups/search'; + }, + + parse: function (r) { + this.total = +r.total; + this.p = +r.p; + this.ps = +r.ps; + return r.groups; + }, + + fetch: function (options) { + var d = (options && options.data) || {}; + this.q = d.q; + return this._super(options); + }, + + fetchMore: function () { + var p = this.p + 1; + return this.fetch({ add: true, remove: false, data: { p: p, ps: this.ps, q: this.q } }); + }, + + refresh: function () { + return this.fetch({ reset: true, data: { q: this.q } }); + }, + + hasMore: function () { + return this.total > this.p * this.ps; + } - return Backbone.Collection.extend({ - model: Group, - - url: function () { - return baseUrl + '/api/usergroups/search'; - }, - - parse: function (r) { - this.total = +r.total; - this.p = +r.p; - this.ps = +r.ps; - return r.groups; - }, - - fetch: function (options) { - var d = (options && options.data) || {}; - this.q = d.q; - return this._super(options); - }, - - fetchMore: function () { - var p = this.p + 1; - return this.fetch({ add: true, remove: false, data: { p: p, ps: this.ps, q: this.q } }); - }, - - refresh: function () { - return this.fetch({ reset: true, data: { q: this.q } }); - }, - - hasMore: function () { - return this.total > this.p * this.ps; - } +}); - }); -}); diff --git a/server/sonar-web/src/main/js/apps/groups/header-view.js b/server/sonar-web/src/main/js/apps/groups/header-view.js index da6f7f60919..bd7226176b2 100644 --- a/server/sonar-web/src/main/js/apps/groups/header-view.js +++ b/server/sonar-web/src/main/js/apps/groups/header-view.js @@ -1,25 +1,24 @@ -define([ - './create-view', - './templates' -], function (CreateView) { +import Marionette from 'backbone.marionette'; +import CreateView from './create-view'; +import './templates'; - return Marionette.ItemView.extend({ - template: Templates['groups-header'], +export default Marionette.ItemView.extend({ + template: Templates['groups-header'], - events: { - 'click #groups-create': 'onCreateClick' - }, + events: { + 'click #groups-create': 'onCreateClick' + }, - onCreateClick: function (e) { - e.preventDefault(); - this.createGroup(); - }, - - createGroup: function () { - new CreateView({ - collection: this.collection - }).render(); - } - }); + onCreateClick: function (e) { + e.preventDefault(); + this.createGroup(); + }, + createGroup: function () { + new CreateView({ + collection: this.collection + }).render(); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/groups/layout.js b/server/sonar-web/src/main/js/apps/groups/layout.js index 18f6c7738d1..ba1f58e81fc 100644 --- a/server/sonar-web/src/main/js/apps/groups/layout.js +++ b/server/sonar-web/src/main/js/apps/groups/layout.js @@ -1,16 +1,15 @@ -define([ - './templates' -], function () { +import Marionette from 'backbone.marionette'; +import './templates'; - return Marionette.LayoutView.extend({ - template: Templates['groups-layout'], - - regions: { - headerRegion: '#groups-header', - searchRegion: '#groups-search', - listRegion: '#groups-list', - listFooterRegion: '#groups-list-footer' - } - }); +export default Marionette.LayoutView.extend({ + template: Templates['groups-layout'], + regions: { + headerRegion: '#groups-header', + searchRegion: '#groups-search', + listRegion: '#groups-list', + listFooterRegion: '#groups-list-footer' + } }); + + diff --git a/server/sonar-web/src/main/js/apps/groups/list-footer-view.js b/server/sonar-web/src/main/js/apps/groups/list-footer-view.js index 3c0fbe198c5..53dc3e7acaa 100644 --- a/server/sonar-web/src/main/js/apps/groups/list-footer-view.js +++ b/server/sonar-web/src/main/js/apps/groups/list-footer-view.js @@ -1,34 +1,34 @@ -define([ - './templates' -], function () { - - return Marionette.ItemView.extend({ - template: Templates['groups-list-footer'], - - collectionEvents: { - 'all': 'render' - }, - - events: { - 'click #groups-fetch-more': 'onMoreClick' - }, - - onMoreClick: function (e) { - e.preventDefault(); - this.fetchMore(); - }, - - fetchMore: function () { - this.collection.fetchMore(); - }, - - serializeData: function () { - return _.extend(this._super(), { - total: this.collection.total, - count: this.collection.length, - more: this.collection.hasMore() - }); - } - }); +import _ from 'underscore'; +import Marionette from 'backbone.marionette'; +import './templates'; +export default Marionette.ItemView.extend({ + template: Templates['groups-list-footer'], + + collectionEvents: { + 'all': 'render' + }, + + events: { + 'click #groups-fetch-more': 'onMoreClick' + }, + + onMoreClick: function (e) { + e.preventDefault(); + this.fetchMore(); + }, + + fetchMore: function () { + this.collection.fetchMore(); + }, + + serializeData: function () { + return _.extend(this._super(), { + total: this.collection.total, + count: this.collection.length, + more: this.collection.hasMore() + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/groups/list-item-view.js b/server/sonar-web/src/main/js/apps/groups/list-item-view.js index 45ce8b9688a..43278c2ac6e 100644 --- a/server/sonar-web/src/main/js/apps/groups/list-item-view.js +++ b/server/sonar-web/src/main/js/apps/groups/list-item-view.js @@ -1,62 +1,60 @@ -define([ - './update-view', - './delete-view', - './users-view', - './templates' -], function (UpdateView, DeleteView, UsersView) { - - var $ = jQuery; - - return Marionette.ItemView.extend({ - tagName: 'li', - className: 'panel panel-vertical', - template: Templates['groups-list-item'], - - events: { - 'click .js-group-update': 'onUpdateClick', - 'click .js-group-delete': 'onDeleteClick', - 'click .js-group-users': 'onUsersClick' - }, - - onRender: function () { - this.$el.attr('data-id', this.model.id); - this.$('[data-toggle="tooltip"]').tooltip({ container: 'body', placement: 'bottom' }); - }, - - onDestroy: function () { - this.$('[data-toggle="tooltip"]').tooltip('destroy'); - }, - - onUpdateClick: function (e) { - e.preventDefault(); - this.updateGroup(); - }, - - onDeleteClick: function (e) { - e.preventDefault(); - this.deleteGroup(); - }, - - onUsersClick: function (e) { - e.preventDefault(); - $('.tooltip').remove(); - this.showUsers(); - }, - - updateGroup: function () { - new UpdateView({ - model: this.model, - collection: this.model.collection - }).render(); - }, - - deleteGroup: function () { - new DeleteView({ model: this.model }).render(); - }, - - showUsers: function () { - new UsersView({ model: this.model }).render(); - } - }); - +import $ from 'jquery'; +import Marionette from 'backbone.marionette'; +import UpdateView from './update-view'; +import DeleteView from './delete-view'; +import UsersView from './users-view'; +import './templates'; + +export default Marionette.ItemView.extend({ + tagName: 'li', + className: 'panel panel-vertical', + template: Templates['groups-list-item'], + + events: { + 'click .js-group-update': 'onUpdateClick', + 'click .js-group-delete': 'onDeleteClick', + 'click .js-group-users': 'onUsersClick' + }, + + onRender: function () { + this.$el.attr('data-id', this.model.id); + this.$('[data-toggle="tooltip"]').tooltip({ container: 'body', placement: 'bottom' }); + }, + + onDestroy: function () { + this.$('[data-toggle="tooltip"]').tooltip('destroy'); + }, + + onUpdateClick: function (e) { + e.preventDefault(); + this.updateGroup(); + }, + + onDeleteClick: function (e) { + e.preventDefault(); + this.deleteGroup(); + }, + + onUsersClick: function (e) { + e.preventDefault(); + $('.tooltip').remove(); + this.showUsers(); + }, + + updateGroup: function () { + new UpdateView({ + model: this.model, + collection: this.model.collection + }).render(); + }, + + deleteGroup: function () { + new DeleteView({ model: this.model }).render(); + }, + + showUsers: function () { + new UsersView({ model: this.model }).render(); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/groups/list-view.js b/server/sonar-web/src/main/js/apps/groups/list-view.js index 24878864d30..695bf2ac034 100644 --- a/server/sonar-web/src/main/js/apps/groups/list-view.js +++ b/server/sonar-web/src/main/js/apps/groups/list-view.js @@ -1,11 +1,10 @@ -define([ - './list-item-view', - './templates' -], function (ListItemView) { - - return Marionette.CollectionView.extend({ - tagName: 'ul', - childView: ListItemView - }); +import Marionette from 'backbone.marionette'; +import ListItemView from './list-item-view'; +import './templates'; +export default Marionette.CollectionView.extend({ + tagName: 'ul', + childView: ListItemView }); + + diff --git a/server/sonar-web/src/main/js/apps/groups/search-view.js b/server/sonar-web/src/main/js/apps/groups/search-view.js index 1540d7eb36e..db3d4d8bb18 100644 --- a/server/sonar-web/src/main/js/apps/groups/search-view.js +++ b/server/sonar-web/src/main/js/apps/groups/search-view.js @@ -1,49 +1,49 @@ -define([ - './templates' -], function () { - - return Marionette.ItemView.extend({ - template: Templates['groups-search'], - - events: { - 'submit #groups-search-form': 'onFormSubmit', - 'search #groups-search-query': 'debouncedOnKeyUp', - 'keyup #groups-search-query': 'debouncedOnKeyUp' - }, - - initialize: function () { - this._bufferedValue = null; - this.debouncedOnKeyUp = _.debounce(this.onKeyUp, 400); - }, - - onRender: function () { - this.delegateEvents(); - }, - - onFormSubmit: function (e) { - e.preventDefault(); - this.debouncedOnKeyUp(); - }, - - onKeyUp: function () { - var q = this.getQuery(); - if (q === this._bufferedValue) { - return; - } - this._bufferedValue = this.getQuery(); - if (this.searchRequest != null) { - this.searchRequest.abort(); - } - this.searchRequest = this.search(q); - }, - - getQuery: function () { - return this.$('#groups-search-query').val(); - }, - - search: function (q) { - return this.collection.fetch({ reset: true, data: { q: q } }); +import _ from 'underscore'; +import Marionette from 'backbone.marionette'; +import './templates'; + +export default Marionette.ItemView.extend({ + template: Templates['groups-search'], + + events: { + 'submit #groups-search-form': 'onFormSubmit', + 'search #groups-search-query': 'debouncedOnKeyUp', + 'keyup #groups-search-query': 'debouncedOnKeyUp' + }, + + initialize: function () { + this._bufferedValue = null; + this.debouncedOnKeyUp = _.debounce(this.onKeyUp, 400); + }, + + onRender: function () { + this.delegateEvents(); + }, + + onFormSubmit: function (e) { + e.preventDefault(); + this.debouncedOnKeyUp(); + }, + + onKeyUp: function () { + var q = this.getQuery(); + if (q === this._bufferedValue) { + return; } - }); + this._bufferedValue = this.getQuery(); + if (this.searchRequest != null) { + this.searchRequest.abort(); + } + this.searchRequest = this.search(q); + }, + + getQuery: function () { + return this.$('#groups-search-query').val(); + }, + search: function (q) { + return this.collection.fetch({ reset: true, data: { q: q } }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/groups/update-view.js b/server/sonar-web/src/main/js/apps/groups/update-view.js index 850ddb7510f..c93608b197b 100644 --- a/server/sonar-web/src/main/js/apps/groups/update-view.js +++ b/server/sonar-web/src/main/js/apps/groups/update-view.js @@ -1,29 +1,27 @@ -define([ - './form-view' -], function (FormView) { +import FormView from './form-view'; - return FormView.extend({ - - sendRequest: function () { - var that = this; - this.model.set({ - name: this.$('#create-group-name').val(), - description: this.$('#create-group-description').val() - }); - this.disableForm(); - return this.model.save(null, { - statusCode: { - // do not show global error - 400: null - } - }).done(function () { - that.collection.refresh(); - that.destroy(); - }).fail(function (jqXHR) { - that.enableForm(); - that.showErrors(jqXHR.responseJSON.errors, jqXHR.responseJSON.warnings); - }); - } - }); +export default FormView.extend({ + sendRequest: function () { + var that = this; + this.model.set({ + name: this.$('#create-group-name').val(), + description: this.$('#create-group-description').val() + }); + this.disableForm(); + return this.model.save(null, { + statusCode: { + // do not show global error + 400: null + } + }).done(function () { + that.collection.refresh(); + that.destroy(); + }).fail(function (jqXHR) { + that.enableForm(); + that.showErrors(jqXHR.responseJSON.errors, jqXHR.responseJSON.warnings); + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/groups/users-view.js b/server/sonar-web/src/main/js/apps/groups/users-view.js index de5901fc5f1..8c815ff2e4d 100644 --- a/server/sonar-web/src/main/js/apps/groups/users-view.js +++ b/server/sonar-web/src/main/js/apps/groups/users-view.js @@ -1,42 +1,40 @@ -define([ - 'components/common/modals', - 'components/common/select-list', - './templates' -], function (Modal) { +import Modal from 'components/common/modals'; +import 'components/common/select-list'; +import './templates'; - return Modal.extend({ - template: Templates['groups-users'], +export default Modal.extend({ + template: Templates['groups-users'], - onRender: function () { - this._super(); - new window.SelectList({ - el: this.$('#groups-users'), - width: '100%', - readOnly: false, - focusSearch: false, - format: function (item) { - return item.name + '
' + item.login + ''; - }, - queryParam: 'q', - searchUrl: baseUrl + '/api/usergroups/users?ps=100&id=' + this.model.id, - selectUrl: baseUrl + '/api/usergroups/add_user', - deselectUrl: baseUrl + '/api/usergroups/remove_user', - extra: { - id: this.model.id - }, - selectParameter: 'login', - selectParameterValue: 'login', - parse: function (r) { - this.more = false; - return r.users; - } - }); - }, - - onDestroy: function () { - this.model.collection.refresh(); - this._super(); - } - }); + onRender: function () { + this._super(); + new window.SelectList({ + el: this.$('#groups-users'), + width: '100%', + readOnly: false, + focusSearch: false, + format: function (item) { + return item.name + '
' + item.login + ''; + }, + queryParam: 'q', + searchUrl: baseUrl + '/api/usergroups/users?ps=100&id=' + this.model.id, + selectUrl: baseUrl + '/api/usergroups/add_user', + deselectUrl: baseUrl + '/api/usergroups/remove_user', + extra: { + id: this.model.id + }, + selectParameter: 'login', + selectParameterValue: 'login', + parse: function (r) { + this.more = false; + return r.users; + } + }); + }, + onDestroy: function () { + this.model.collection.refresh(); + this._super(); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/issues/app-context.js b/server/sonar-web/src/main/js/apps/issues/app-context.js index 3d7db3aa2ef..8d28597d056 100644 --- a/server/sonar-web/src/main/js/apps/issues/app-context.js +++ b/server/sonar-web/src/main/js/apps/issues/app-context.js @@ -1,97 +1,97 @@ -define([ - './models/state', - './layout', - './models/issues', - 'components/navigator/models/facets', - './models/filters', - './controller', - './router', - './workspace-list-view', - './workspace-header-view', - './facets-view', - './helpers/format-facet-value' -], function (State, Layout, Issues, Facets, Filters, Controller, Router, WorkspaceListView, WorkspaceHeaderView, - FacetsView) { +import $ from 'jquery'; +import _ from 'underscore'; +import Backbone from 'backbone'; +import Marionette from 'backbone.marionette'; +import State from './models/state'; +import Layout from './layout'; +import Issues from './models/issues'; +import Facets from 'components/navigator/models/facets'; +import Filters from './models/filters'; +import Controller from './controller'; +import Router from './router'; +import WorkspaceListView from './workspace-list-view'; +import WorkspaceHeaderView from './workspace-header-view'; +import FacetsView from './facets-view'; +import './helpers/format-facet-value'; - var $ = jQuery, - App = new Marionette.Application(), - init = function (options) { - this.config = options.config; - this.state = new State({ - isContext: true, - contextQuery: { componentUuids: options.config.resource }, - contextComponentUuid: options.config.resource, - contextComponentName: options.config.resourceName, - contextComponentQualifier: options.config.resourceQualifier - }); - this.updateContextFacets(); - this.list = new Issues(); - this.facets = new Facets(); - this.filters = new Filters(); +var App = new Marionette.Application(), + init = function (options) { + this.config = options.config; + this.state = new State({ + isContext: true, + contextQuery: { componentUuids: options.config.resource }, + contextComponentUuid: options.config.resource, + contextComponentName: options.config.resourceName, + contextComponentQualifier: options.config.resourceQualifier + }); + this.updateContextFacets(); + this.list = new Issues(); + this.facets = new Facets(); + this.filters = new Filters(); - this.layout = new Layout({ app: this, el: options.el }); - this.layout.render(); - $('#footer').addClass('search-navigator-footer'); + this.layout = new Layout({ app: this, el: options.el }); + this.layout.render(); + $('#footer').addClass('search-navigator-footer'); - this.controller = new Controller({ app: this }); + this.controller = new Controller({ app: this }); - this.issuesView = new WorkspaceListView({ - app: this, - collection: this.list - }); - this.layout.workspaceListRegion.show(this.issuesView); - this.issuesView.bindScrollEvents(); + this.issuesView = new WorkspaceListView({ + app: this, + collection: this.list + }); + this.layout.workspaceListRegion.show(this.issuesView); + this.issuesView.bindScrollEvents(); - this.workspaceHeaderView = new WorkspaceHeaderView({ - app: this, - collection: this.list - }); - this.layout.workspaceHeaderRegion.show(this.workspaceHeaderView); + this.workspaceHeaderView = new WorkspaceHeaderView({ + app: this, + collection: this.list + }); + this.layout.workspaceHeaderRegion.show(this.workspaceHeaderView); - this.facetsView = new FacetsView({ - app: this, - collection: this.facets - }); - this.layout.facetsRegion.show(this.facetsView); + this.facetsView = new FacetsView({ + app: this, + collection: this.facets + }); + this.layout.facetsRegion.show(this.facetsView); - this.controller.fetchFilters().done(function () { - key.setScope('list'); - App.router = new Router({ app: App }); - Backbone.history.start(); - }); - }; + this.controller.fetchFilters().done(function () { + key.setScope('list'); + App.router = new Router({ app: App }); + Backbone.history.start(); + }); + }; - App.getContextQuery = function () { - return { componentUuids: this.config.resource }; - }; +App.getContextQuery = function () { + return { componentUuids: this.config.resource }; +}; - App.getRestrictedFacets = function () { - return { - 'TRK': ['projectUuids'], - 'BRC': ['projectUuids'], - 'DIR': ['projectUuids', 'moduleUuids', 'directories'], - 'DEV': ['authors'], - 'DEV_PRJ': ['projectUuids', 'authors'] - }; +App.getRestrictedFacets = function () { + return { + 'TRK': ['projectUuids'], + 'BRC': ['projectUuids'], + 'DIR': ['projectUuids', 'moduleUuids', 'directories'], + 'DEV': ['authors'], + 'DEV_PRJ': ['projectUuids', 'authors'] }; +}; - App.updateContextFacets = function () { - var facets = this.state.get('facets'), - allFacets = this.state.get('allFacets'), - facetsFromServer = this.state.get('facetsFromServer'); - return this.state.set({ - facets: facets, - allFacets: _.difference(allFacets, this.getRestrictedFacets()[this.config.resourceQualifier]), - facetsFromServer: _.difference(facetsFromServer, this.getRestrictedFacets()[this.config.resourceQualifier]) - }); - }; +App.updateContextFacets = function () { + var facets = this.state.get('facets'), + allFacets = this.state.get('allFacets'), + facetsFromServer = this.state.get('facetsFromServer'); + return this.state.set({ + facets: facets, + allFacets: _.difference(allFacets, this.getRestrictedFacets()[this.config.resourceQualifier]), + facetsFromServer: _.difference(facetsFromServer, this.getRestrictedFacets()[this.config.resourceQualifier]) + }); +}; - App.on('start', function (options) { - $.when(window.requestMessages()).done(function () { - init.call(App, options); - }); +App.on('start', function (options) { + $.when(window.requestMessages()).done(function () { + init.call(App, options); }); +}); + +export default App; - return App; -}); diff --git a/server/sonar-web/src/main/js/apps/issues/app.js b/server/sonar-web/src/main/js/apps/issues/app.js index 12e5671c5c3..fe9188b27f8 100644 --- a/server/sonar-web/src/main/js/apps/issues/app.js +++ b/server/sonar-web/src/main/js/apps/issues/app.js @@ -1,71 +1,70 @@ -define([ - './models/state', - './layout', - './models/issues', - 'components/navigator/models/facets', - './models/filters', - './controller', - './router', - './workspace-list-view', - './workspace-header-view', - './facets-view', - './filters-view', - './helpers/format-facet-value' -], function (State, Layout, Issues, Facets, Filters, Controller, Router, WorkspaceListView, WorkspaceHeaderView, - FacetsView, FiltersView) { +import $ from 'jquery'; +import Backbone from 'backbone'; +import Marionette from 'backbone.marionette'; +import State from './models/state'; +import Layout from './layout'; +import Issues from './models/issues'; +import Facets from 'components/navigator/models/facets'; +import Filters from './models/filters'; +import Controller from './controller'; +import Router from './router'; +import WorkspaceListView from './workspace-list-view'; +import WorkspaceHeaderView from './workspace-header-view'; +import FacetsView from './facets-view'; +import FiltersView from './filters-view'; +import './helpers/format-facet-value'; - var $ = jQuery, - App = new Marionette.Application(), - init = function (options) { - this.state = new State(); - this.list = new Issues(); - this.facets = new Facets(); - this.filters = new Filters(); +var App = new Marionette.Application(), + init = function (options) { + this.state = new State(); + this.list = new Issues(); + this.facets = new Facets(); + this.filters = new Filters(); - this.layout = new Layout({ app: this, el: options.el }); - this.layout.render(); - $('#footer').addClass('search-navigator-footer'); + this.layout = new Layout({ app: this, el: options.el }); + this.layout.render(); + $('#footer').addClass('search-navigator-footer'); - this.controller = new Controller({ app: this }); + this.controller = new Controller({ app: this }); - this.issuesView = new WorkspaceListView({ - app: this, - collection: this.list - }); - this.layout.workspaceListRegion.show(this.issuesView); - this.issuesView.bindScrollEvents(); + this.issuesView = new WorkspaceListView({ + app: this, + collection: this.list + }); + this.layout.workspaceListRegion.show(this.issuesView); + this.issuesView.bindScrollEvents(); - this.workspaceHeaderView = new WorkspaceHeaderView({ - app: this, - collection: this.list - }); - this.layout.workspaceHeaderRegion.show(this.workspaceHeaderView); + this.workspaceHeaderView = new WorkspaceHeaderView({ + app: this, + collection: this.list + }); + this.layout.workspaceHeaderRegion.show(this.workspaceHeaderView); - this.facetsView = new FacetsView({ - app: this, - collection: this.facets - }); - this.layout.facetsRegion.show(this.facetsView); + this.facetsView = new FacetsView({ + app: this, + collection: this.facets + }); + this.layout.facetsRegion.show(this.facetsView); - this.filtersView = new FiltersView({ - app: this, - collection: this.filters - }); - this.layout.filtersRegion.show(this.filtersView); + this.filtersView = new FiltersView({ + app: this, + collection: this.filters + }); + this.layout.filtersRegion.show(this.filtersView); - this.controller.fetchFilters().done(function () { - key.setScope('list'); - App.router = new Router({ app: App }); - Backbone.history.start(); - }); - }; + this.controller.fetchFilters().done(function () { + key.setScope('list'); + App.router = new Router({ app: App }); + Backbone.history.start(); + }); + }; - App.on('start', function (options) { - $.when(window.requestMessages()).done(function () { - init.call(App, options); - }); +App.on('start', function (options) { + $.when(window.requestMessages()).done(function () { + init.call(App, options); }); +}); + +export default App; - return App; -}); diff --git a/server/sonar-web/src/main/js/apps/issues/component-viewer/issue-view.js b/server/sonar-web/src/main/js/apps/issues/component-viewer/issue-view.js index 97d3e2b40e9..41e8087fd25 100644 --- a/server/sonar-web/src/main/js/apps/issues/component-viewer/issue-view.js +++ b/server/sonar-web/src/main/js/apps/issues/component-viewer/issue-view.js @@ -1,18 +1,17 @@ -define([ - '../workspace-list-item-view' -], function (IssueView) { +import _ from 'underscore'; +import IssueView from '../workspace-list-item-view'; - return IssueView.extend({ - onRender: function () { - IssueView.prototype.onRender.apply(this, arguments); - this.$el.removeClass('issue-navigate-right issue-with-checkbox'); - }, - - serializeData: function () { - return _.extend(IssueView.prototype.serializeData.apply(this, arguments), { - showComponent: false - }); - } - }); +export default IssueView.extend({ + onRender: function () { + IssueView.prototype.onRender.apply(this, arguments); + this.$el.removeClass('issue-navigate-right issue-with-checkbox'); + }, + serializeData: function () { + return _.extend(IssueView.prototype.serializeData.apply(this, arguments), { + showComponent: false + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/issues/component-viewer/main.js b/server/sonar-web/src/main/js/apps/issues/component-viewer/main.js index 8792113e213..2397bf06cb0 100644 --- a/server/sonar-web/src/main/js/apps/issues/component-viewer/main.js +++ b/server/sonar-web/src/main/js/apps/issues/component-viewer/main.js @@ -1,206 +1,203 @@ -define([ - 'components/source-viewer/main', - '../models/issues', - './issue-view', - '../templates' -], function (SourceViewer, Issues, IssueView) { - - var $ = jQuery; - - return SourceViewer.extend({ - events: function () { - return _.extend(SourceViewer.prototype.events.apply(this, arguments), { - 'click .js-close-component-viewer': 'closeComponentViewer', - 'click .code-issue': 'selectIssue' - }); - }, - - initialize: function (options) { - SourceViewer.prototype.initialize.apply(this, arguments); - return this.listenTo(options.app.state, 'change:selectedIndex', this.select); - }, - - onLoaded: function () { - SourceViewer.prototype.onLoaded.apply(this, arguments); - this.bindShortcuts(); - if (this.baseIssue != null) { - this.baseIssue.trigger('locations', this.baseIssue); - return this.scrollToLine(this.baseIssue.get('line')); +import $ from 'jquery'; +import _ from 'underscore'; +import SourceViewer from 'components/source-viewer/main'; +import IssueView from './issue-view'; +import '../templates'; + +export default SourceViewer.extend({ + events: function () { + return _.extend(SourceViewer.prototype.events.apply(this, arguments), { + 'click .js-close-component-viewer': 'closeComponentViewer', + 'click .code-issue': 'selectIssue' + }); + }, + + initialize: function (options) { + SourceViewer.prototype.initialize.apply(this, arguments); + return this.listenTo(options.app.state, 'change:selectedIndex', this.select); + }, + + onLoaded: function () { + SourceViewer.prototype.onLoaded.apply(this, arguments); + this.bindShortcuts(); + if (this.baseIssue != null) { + this.baseIssue.trigger('locations', this.baseIssue); + return this.scrollToLine(this.baseIssue.get('line')); + } + }, + + bindShortcuts: function () { + var that = this; + var doAction = function (action) { + var selectedIssueView = that.getSelectedIssueEl(); + if (!selectedIssueView) { + return; } - }, - - bindShortcuts: function () { - var that = this; - var doAction = function (action) { - var selectedIssueView = that.getSelectedIssueEl(); - if (!selectedIssueView) { - return; - } - return selectedIssueView.find('.js-issue-' + action).click(); - }; - key('up', 'componentViewer', function () { - that.options.app.controller.selectPrev(); - return false; - }); - key('down', 'componentViewer', function () { - that.options.app.controller.selectNext(); - return false; - }); - key('left,backspace', 'componentViewer', function () { - that.options.app.controller.closeComponentViewer(); - return false; - }); - key('f', 'componentViewer', function () { - return doAction('transition'); - }); - key('a', 'componentViewer', function () { - return doAction('assign'); - }); - key('m', 'componentViewer', function () { - return doAction('assign-to-me'); - }); - key('p', 'componentViewer', function () { - return doAction('plan'); - }); - key('i', 'componentViewer', function () { - return doAction('set-severity'); - }); - return key('c', 'componentViewer', function () { - return doAction('comment'); - }); - }, - - unbindShortcuts: function () { - return key.deleteScope('componentViewer'); - }, - - onDestroy: function () { - SourceViewer.prototype.onDestroy.apply(this, arguments); - this.unbindScrollEvents(); - return this.unbindShortcuts(); - }, - - select: function () { + return selectedIssueView.find('.js-issue-' + action).click(); + }; + key('up', 'componentViewer', function () { + that.options.app.controller.selectPrev(); + return false; + }); + key('down', 'componentViewer', function () { + that.options.app.controller.selectNext(); + return false; + }); + key('left,backspace', 'componentViewer', function () { + that.options.app.controller.closeComponentViewer(); + return false; + }); + key('f', 'componentViewer', function () { + return doAction('transition'); + }); + key('a', 'componentViewer', function () { + return doAction('assign'); + }); + key('m', 'componentViewer', function () { + return doAction('assign-to-me'); + }); + key('p', 'componentViewer', function () { + return doAction('plan'); + }); + key('i', 'componentViewer', function () { + return doAction('set-severity'); + }); + return key('c', 'componentViewer', function () { + return doAction('comment'); + }); + }, + + unbindShortcuts: function () { + return key.deleteScope('componentViewer'); + }, + + onDestroy: function () { + SourceViewer.prototype.onDestroy.apply(this, arguments); + this.unbindScrollEvents(); + return this.unbindShortcuts(); + }, + + select: function () { + var selected = this.options.app.state.get('selectedIndex'), + selectedIssue = this.options.app.list.at(selected); + if (selectedIssue.get('component') === this.model.get('key')) { + selectedIssue.trigger('locations', selectedIssue); + return this.scrollToIssue(selectedIssue.get('key')); + } else { + this.unbindShortcuts(); + return this.options.app.controller.showComponentViewer(selectedIssue); + } + }, + + getSelectedIssueEl: function () { + var selected = this.options.app.state.get('selectedIndex'); + if (selected == null) { + return null; + } + var selectedIssue = this.options.app.list.at(selected); + if (selectedIssue == null) { + return null; + } + var selectedIssueView = this.$('#issue-' + (selectedIssue.get('key'))); + if (selectedIssueView.length > 0) { + return selectedIssueView; + } else { + return null; + } + }, + + selectIssue: function (e) { + var key = $(e.currentTarget).data('issue-key'), + issue = this.issues.find(function (model) { + return model.get('key') === key; + }), + index = this.options.app.list.indexOf(issue); + return this.options.app.state.set({ selectedIndex: index }); + }, + + scrollToIssue: function (key) { + var el = this.$('#issue-' + key); + if (el.length > 0) { + var line = el.closest('[data-line-number]').data('line-number'); + return this.scrollToLine(line); + } else { + this.unbindShortcuts(); var selected = this.options.app.state.get('selectedIndex'), selectedIssue = this.options.app.list.at(selected); - if (selectedIssue.get('component') === this.model.get('key')) { - selectedIssue.trigger('locations', selectedIssue); - return this.scrollToIssue(selectedIssue.get('key')); - } else { - this.unbindShortcuts(); - return this.options.app.controller.showComponentViewer(selectedIssue); - } - }, - - getSelectedIssueEl: function () { - var selected = this.options.app.state.get('selectedIndex'); - if (selected == null) { - return null; - } - var selectedIssue = this.options.app.list.at(selected); - if (selectedIssue == null) { - return null; - } - var selectedIssueView = this.$('#issue-' + (selectedIssue.get('key'))); - if (selectedIssueView.length > 0) { - return selectedIssueView; - } else { - return null; - } - }, - - selectIssue: function (e) { - var key = $(e.currentTarget).data('issue-key'), - issue = this.issues.find(function (model) { - return model.get('key') === key; - }), - index = this.options.app.list.indexOf(issue); - return this.options.app.state.set({ selectedIndex: index }); - }, - - scrollToIssue: function (key) { - var el = this.$('#issue-' + key); - if (el.length > 0) { - var line = el.closest('[data-line-number]').data('line-number'); - return this.scrollToLine(line); - } else { - this.unbindShortcuts(); - var selected = this.options.app.state.get('selectedIndex'), - selectedIssue = this.options.app.list.at(selected); - return this.options.app.controller.showComponentViewer(selectedIssue); - } - }, - - openFileByIssue: function (issue) { - this.baseIssue = issue; - var componentKey = issue.get('component'), - componentUuid = issue.get('componentUuid'); - return this.open(componentUuid, componentKey); - }, - - linesLimit: function () { - var line = this.LINES_LIMIT / 2; - if ((this.baseIssue != null) && this.baseIssue.has('line')) { - line = Math.max(line, this.baseIssue.get('line')); - } - return { - from: line - this.LINES_LIMIT / 2 + 1, - to: line + this.LINES_LIMIT / 2 - }; - }, - - limitIssues: function (issues) { - var that = this; - var index = this.ISSUES_LIMIT / 2; - if ((this.baseIssue != null) && this.baseIssue.has('index')) { - index = Math.max(index, this.baseIssue.get('index')); - } - return issues.filter(function (issue) { - return Math.abs(issue.get('index') - index) <= that.ISSUES_LIMIT / 2; - }); - }, - - requestIssues: function () { - var that = this; - var r; - if (this.options.app.list.last().get('component') === this.model.get('key')) { - r = this.options.app.controller.fetchNextPage(); - } else { - r = $.Deferred().resolve().promise(); - } - return r.done(function () { - that.issues.reset(that.options.app.list.filter(function (issue) { - return issue.get('component') === that.model.key(); - })); - that.issues.reset(that.limitIssues(that.issues)); - return that.addIssuesPerLineMeta(that.issues); - }); - }, - - renderIssues: function () { - this.issues.forEach(this.renderIssue, this); - return this.$('.source-line-issues').addClass('hidden'); - }, - - renderIssue: function (issue) { - var issueView = new IssueView({ - el: '#issue-' + issue.get('key'), - model: issue, - app: this.options.app - }); - this.issueViews.push(issueView); - return issueView.render(); - }, - - scrollToLine: function (line) { - var row = this.$('[data-line-number=' + line + ']'), - goal = row.length > 0 ? row.offset().top - 200 : 0; - return $(window).scrollTop(goal); - }, - - closeComponentViewer: function () { - return this.options.app.controller.closeComponentViewer(); + return this.options.app.controller.showComponentViewer(selectedIssue); } - }); - + }, + + openFileByIssue: function (issue) { + this.baseIssue = issue; + var componentKey = issue.get('component'), + componentUuid = issue.get('componentUuid'); + return this.open(componentUuid, componentKey); + }, + + linesLimit: function () { + var line = this.LINES_LIMIT / 2; + if ((this.baseIssue != null) && this.baseIssue.has('line')) { + line = Math.max(line, this.baseIssue.get('line')); + } + return { + from: line - this.LINES_LIMIT / 2 + 1, + to: line + this.LINES_LIMIT / 2 + }; + }, + + limitIssues: function (issues) { + var that = this; + var index = this.ISSUES_LIMIT / 2; + if ((this.baseIssue != null) && this.baseIssue.has('index')) { + index = Math.max(index, this.baseIssue.get('index')); + } + return issues.filter(function (issue) { + return Math.abs(issue.get('index') - index) <= that.ISSUES_LIMIT / 2; + }); + }, + + requestIssues: function () { + var that = this; + var r; + if (this.options.app.list.last().get('component') === this.model.get('key')) { + r = this.options.app.controller.fetchNextPage(); + } else { + r = $.Deferred().resolve().promise(); + } + return r.done(function () { + that.issues.reset(that.options.app.list.filter(function (issue) { + return issue.get('component') === that.model.key(); + })); + that.issues.reset(that.limitIssues(that.issues)); + return that.addIssuesPerLineMeta(that.issues); + }); + }, + + renderIssues: function () { + this.issues.forEach(this.renderIssue, this); + return this.$('.source-line-issues').addClass('hidden'); + }, + + renderIssue: function (issue) { + var issueView = new IssueView({ + el: '#issue-' + issue.get('key'), + model: issue, + app: this.options.app + }); + this.issueViews.push(issueView); + return issueView.render(); + }, + + scrollToLine: function (line) { + var row = this.$('[data-line-number=' + line + ']'), + goal = row.length > 0 ? row.offset().top - 200 : 0; + return $(window).scrollTop(goal); + }, + + closeComponentViewer: function () { + return this.options.app.controller.closeComponentViewer(); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/issues/controller.js b/server/sonar-web/src/main/js/apps/issues/controller.js index bf54a35c2bc..b7843450ada 100644 --- a/server/sonar-web/src/main/js/apps/issues/controller.js +++ b/server/sonar-web/src/main/js/apps/issues/controller.js @@ -1,259 +1,259 @@ -define([ - 'components/navigator/controller', - './component-viewer/main', - './workspace-home-view' -], function (Controller, ComponentViewer, HomeView) { +import $ from 'jquery'; +import _ from 'underscore'; +import Backbone from 'backbone'; +import Controller from 'components/navigator/controller'; +import ComponentViewer from './component-viewer/main'; +import HomeView from './workspace-home-view'; - var $ = jQuery, - FIELDS = 'component,componentId,project,subProject,rule,status,resolution,author,reporter,assignee,debt,line,' + - 'message,severity,actionPlan,creationDate,updateDate,closeDate,tags,comments,attr,actions,transitions,' + - 'actionPlanName', - FACET_DATA_FIELDS = ['components', 'users', 'rules', 'actionPlans', 'languages']; +var FIELDS = 'component,componentId,project,subProject,rule,status,resolution,author,reporter,assignee,debt,line,' + + 'message,severity,actionPlan,creationDate,updateDate,closeDate,tags,comments,attr,actions,transitions,' + + 'actionPlanName', + FACET_DATA_FIELDS = ['components', 'users', 'rules', 'actionPlans', 'languages']; - return Controller.extend({ - _facetsFromServer: function () { - var facets = Controller.prototype._facetsFromServer.apply(this, arguments) || []; - facets.push('assigned_to_me'); - return facets; - }, +export default Controller.extend({ + _facetsFromServer: function () { + var facets = Controller.prototype._facetsFromServer.apply(this, arguments) || []; + facets.push('assigned_to_me'); + return facets; + }, - _issuesParameters: function () { - return { - p: this.options.app.state.get('page'), - ps: this.pageSize, - s: 'FILE_LINE', - asc: true, - f: FIELDS, - additionalFields: '_all', - facets: this._facetsFromServer().join() - }; - }, + _issuesParameters: function () { + return { + p: this.options.app.state.get('page'), + ps: this.pageSize, + s: 'FILE_LINE', + asc: true, + f: FIELDS, + additionalFields: '_all', + facets: this._facetsFromServer().join() + }; + }, - _myIssuesFromResponse: function (r) { - var myIssuesData = _.findWhere(r.facets, { property: 'assigned_to_me' }); - if ((myIssuesData != null) && _.isArray(myIssuesData.values) && myIssuesData.values.length > 0) { - return this.options.app.state.set({ myIssues: myIssuesData.values[0].count }, { silent: true }); - } else { - return this.options.app.state.unset('myIssues', { silent: true }); - } - }, + _myIssuesFromResponse: function (r) { + var myIssuesData = _.findWhere(r.facets, { property: 'assigned_to_me' }); + if ((myIssuesData != null) && _.isArray(myIssuesData.values) && myIssuesData.values.length > 0) { + return this.options.app.state.set({ myIssues: myIssuesData.values[0].count }, { silent: true }); + } else { + return this.options.app.state.unset('myIssues', { silent: true }); + } + }, - fetchList: function (firstPage) { - var that = this; - if (firstPage == null) { - firstPage = true; - } + fetchList: function (firstPage) { + var that = this; + if (firstPage == null) { + firstPage = true; + } + if (firstPage) { + this.options.app.state.set({ selectedIndex: 0, page: 1 }, { silent: true }); + this.hideHomePage(); + this.closeComponentViewer(); + } + var data = this._issuesParameters(); + _.extend(data, this.options.app.state.get('query')); + if (this.options.app.state.get('isContext')) { + _.extend(data, this.options.app.state.get('contextQuery')); + } + return $.get(baseUrl + '/api/issues/search', data).done(function (r) { + var issues = that.options.app.list.parseIssues(r); if (firstPage) { - this.options.app.state.set({ selectedIndex: 0, page: 1 }, { silent: true }); - this.hideHomePage(); - this.closeComponentViewer(); - } - var data = this._issuesParameters(); - _.extend(data, this.options.app.state.get('query')); - if (this.options.app.state.get('isContext')) { - _.extend(data, this.options.app.state.get('contextQuery')); + that.options.app.list.reset(issues); + } else { + that.options.app.list.add(issues); } - return $.get(baseUrl + '/api/issues/search', data).done(function (r) { - var issues = that.options.app.list.parseIssues(r); - if (firstPage) { - that.options.app.list.reset(issues); - } else { - that.options.app.list.add(issues); - } - that.options.app.list.setIndex(); - FACET_DATA_FIELDS.forEach(function (field) { - that.options.app.facets[field] = r[field]; - }); - that.options.app.facets.reset(that._allFacets()); - that.options.app.facets.add(_.reject(r.facets, function (f) { - return f.property === 'assigned_to_me'; - }), { merge: true }); - that._myIssuesFromResponse(r); - that.enableFacets(that._enabledFacets()); - that.options.app.state.set({ - page: r.p, - pageSize: r.ps, - total: r.total, - maxResultsReached: r.p * r.ps >= r.total - }); - if (firstPage && that.isIssuePermalink()) { - return that.showComponentViewer(that.options.app.list.first()); - } + that.options.app.list.setIndex(); + FACET_DATA_FIELDS.forEach(function (field) { + that.options.app.facets[field] = r[field]; + }); + that.options.app.facets.reset(that._allFacets()); + that.options.app.facets.add(_.reject(r.facets, function (f) { + return f.property === 'assigned_to_me'; + }), { merge: true }); + that._myIssuesFromResponse(r); + that.enableFacets(that._enabledFacets()); + that.options.app.state.set({ + page: r.p, + pageSize: r.ps, + total: r.total, + maxResultsReached: r.p * r.ps >= r.total }); - }, + if (firstPage && that.isIssuePermalink()) { + return that.showComponentViewer(that.options.app.list.first()); + } + }); + }, - isIssuePermalink: function () { - var query = this.options.app.state.get('query'); - return (query.issues != null) && this.options.app.list.length === 1; - }, + isIssuePermalink: function () { + var query = this.options.app.state.get('query'); + return (query.issues != null) && this.options.app.list.length === 1; + }, - fetchFilters: function () { - var that = this; - return $.when( - that.options.app.filters.fetch({ reset: true }), - $.get(baseUrl + '/api/issue_filters/app', function (r) { - that.options.app.state.set({ - canBulkChange: r.canBulkChange, - canManageFilters: r.canManageFilters - }); - })); - }, + fetchFilters: function () { + var that = this; + return $.when( + that.options.app.filters.fetch({ reset: true }), + $.get(baseUrl + '/api/issue_filters/app', function (r) { + that.options.app.state.set({ + canBulkChange: r.canBulkChange, + canManageFilters: r.canManageFilters + }); + })); + }, - _mergeCollections: function (a, b) { - var collection = new Backbone.Collection(a); - collection.add(b, { merge: true }); - return collection.toJSON(); - }, + _mergeCollections: function (a, b) { + var collection = new Backbone.Collection(a); + collection.add(b, { merge: true }); + return collection.toJSON(); + }, - requestFacet: function (id) { - var that = this; - if (id === 'assignees') { - return this.requestAssigneeFacet(); - } - var facet = this.options.app.facets.get(id), - data = _.extend({ facets: id, ps: 1, additionalFields: '_all' }, this.options.app.state.get('query')); - if (this.options.app.state.get('isContext')) { - _.extend(data, this.options.app.state.get('contextQuery')); - } - return $.get(baseUrl + '/api/issues/search', data, function (r) { - FACET_DATA_FIELDS.forEach(function (field) { - that.options.app.facets[field] = that._mergeCollections(that.options.app.facets[field], r[field]); - }); - var facetData = _.findWhere(r.facets, { property: id }); - if (facetData != null) { - return facet.set(facetData); - } + requestFacet: function (id) { + var that = this; + if (id === 'assignees') { + return this.requestAssigneeFacet(); + } + var facet = this.options.app.facets.get(id), + data = _.extend({ facets: id, ps: 1, additionalFields: '_all' }, this.options.app.state.get('query')); + if (this.options.app.state.get('isContext')) { + _.extend(data, this.options.app.state.get('contextQuery')); + } + return $.get(baseUrl + '/api/issues/search', data, function (r) { + FACET_DATA_FIELDS.forEach(function (field) { + that.options.app.facets[field] = that._mergeCollections(that.options.app.facets[field], r[field]); }); - }, - - requestAssigneeFacet: function () { - var that = this; - var facet = this.options.app.facets.get('assignees'), - data = _.extend({ facets: 'assignees,assigned_to_me', ps: 1, additionalFields: '_all' }, - this.options.app.state.get('query')); - if (this.options.app.state.get('isContext')) { - _.extend(data, this.options.app.state.get('contextQuery')); + var facetData = _.findWhere(r.facets, { property: id }); + if (facetData != null) { + return facet.set(facetData); } - return $.get(baseUrl + '/api/issues/search', data, function (r) { - FACET_DATA_FIELDS.forEach(function (field) { - that.options.app.facets[field] = that._mergeCollections(that.options.app.facets[field], r[field]); - }); - var facetData = _.findWhere(r.facets, { property: 'assignees' }); - that._myIssuesFromResponse(r); - if (facetData != null) { - return facet.set(facetData); - } + }); + }, + + requestAssigneeFacet: function () { + var that = this; + var facet = this.options.app.facets.get('assignees'), + data = _.extend({ facets: 'assignees,assigned_to_me', ps: 1, additionalFields: '_all' }, + this.options.app.state.get('query')); + if (this.options.app.state.get('isContext')) { + _.extend(data, this.options.app.state.get('contextQuery')); + } + return $.get(baseUrl + '/api/issues/search', data, function (r) { + FACET_DATA_FIELDS.forEach(function (field) { + that.options.app.facets[field] = that._mergeCollections(that.options.app.facets[field], r[field]); }); - }, + var facetData = _.findWhere(r.facets, { property: 'assignees' }); + that._myIssuesFromResponse(r); + if (facetData != null) { + return facet.set(facetData); + } + }); + }, - newSearch: function () { - this.options.app.state.unset('filter'); - return this.options.app.state.setQuery({ resolved: 'false' }); - }, + newSearch: function () { + this.options.app.state.unset('filter'); + return this.options.app.state.setQuery({ resolved: 'false' }); + }, - applyFilter: function (filter, ignoreQuery) { - if (ignoreQuery == null) { - ignoreQuery = false; - } - if (!ignoreQuery) { - var filterQuery = this.parseQuery(filter.get('query')); - this.options.app.state.setQuery(filterQuery); - } - return this.options.app.state.set({ filter: filter, changed: false }); - }, + applyFilter: function (filter, ignoreQuery) { + if (ignoreQuery == null) { + ignoreQuery = false; + } + if (!ignoreQuery) { + var filterQuery = this.parseQuery(filter.get('query')); + this.options.app.state.setQuery(filterQuery); + } + return this.options.app.state.set({ filter: filter, changed: false }); + }, - parseQuery: function () { - var q = Controller.prototype.parseQuery.apply(this, arguments); - delete q.asc; - delete q.s; - return q; - }, + parseQuery: function () { + var q = Controller.prototype.parseQuery.apply(this, arguments); + delete q.asc; + delete q.s; + return q; + }, - getQuery: function (separator, addContext) { - if (separator == null) { - separator = '|'; - } - if (addContext == null) { - addContext = false; - } - var filter = this.options.app.state.get('query'); - if (addContext && this.options.app.state.get('isContext')) { - _.extend(filter, this.options.app.state.get('contextQuery')); - } - var route = []; - _.map(filter, function (value, property) { - return route.push('' + property + '=' + encodeURIComponent(value)); - }); - return route.join(separator); - }, + getQuery: function (separator, addContext) { + if (separator == null) { + separator = '|'; + } + if (addContext == null) { + addContext = false; + } + var filter = this.options.app.state.get('query'); + if (addContext && this.options.app.state.get('isContext')) { + _.extend(filter, this.options.app.state.get('contextQuery')); + } + var route = []; + _.map(filter, function (value, property) { + return route.push('' + property + '=' + encodeURIComponent(value)); + }); + return route.join(separator); + }, - getRoute: function () { - var filter = this.options.app.state.get('filter'), - query = Controller.prototype.getRoute.apply(this, arguments); - if (filter != null) { - if (this.options.app.state.get('changed') && query.length > 0) { - query = 'id=' + filter.id + '|' + query; - } else { - query = 'id=' + filter.id; - } + getRoute: function () { + var filter = this.options.app.state.get('filter'), + query = Controller.prototype.getRoute.apply(this, arguments); + if (filter != null) { + if (this.options.app.state.get('changed') && query.length > 0) { + query = 'id=' + filter.id + '|' + query; + } else { + query = 'id=' + filter.id; } - return query; - }, + } + return query; + }, - _prepareComponent: function (issue) { - return { - key: issue.get('component'), - name: issue.get('componentLongName'), - qualifier: issue.get('componentQualifier'), - subProject: issue.get('subProject'), - subProjectName: issue.get('subProjectLongName'), - project: issue.get('project'), - projectName: issue.get('projectLongName') - }; - }, + _prepareComponent: function (issue) { + return { + key: issue.get('component'), + name: issue.get('componentLongName'), + qualifier: issue.get('componentQualifier'), + subProject: issue.get('subProject'), + subProjectName: issue.get('subProjectLongName'), + project: issue.get('project'), + projectName: issue.get('projectLongName') + }; + }, - showComponentViewer: function (issue) { - this.options.app.layout.workspaceComponentViewerRegion.reset(); - key.setScope('componentViewer'); - this.options.app.issuesView.unbindScrollEvents(); - this.options.app.state.set('component', this._prepareComponent(issue)); - this.options.app.componentViewer = new ComponentViewer({ app: this.options.app }); - this.options.app.layout.workspaceComponentViewerRegion.show(this.options.app.componentViewer); - this.options.app.layout.showComponentViewer(); - return this.options.app.componentViewer.openFileByIssue(issue); - }, + showComponentViewer: function (issue) { + this.options.app.layout.workspaceComponentViewerRegion.reset(); + key.setScope('componentViewer'); + this.options.app.issuesView.unbindScrollEvents(); + this.options.app.state.set('component', this._prepareComponent(issue)); + this.options.app.componentViewer = new ComponentViewer({ app: this.options.app }); + this.options.app.layout.workspaceComponentViewerRegion.show(this.options.app.componentViewer); + this.options.app.layout.showComponentViewer(); + return this.options.app.componentViewer.openFileByIssue(issue); + }, - closeComponentViewer: function () { - key.setScope('list'); - $('body').click(); - this.options.app.state.unset('component'); - this.options.app.layout.workspaceComponentViewerRegion.reset(); - this.options.app.layout.hideComponentViewer(); - this.options.app.issuesView.bindScrollEvents(); - return this.options.app.issuesView.scrollTo(); - }, + closeComponentViewer: function () { + key.setScope('list'); + $('body').click(); + this.options.app.state.unset('component'); + this.options.app.layout.workspaceComponentViewerRegion.reset(); + this.options.app.layout.hideComponentViewer(); + this.options.app.issuesView.bindScrollEvents(); + return this.options.app.issuesView.scrollTo(); + }, - showHomePage: function () { - this.fetchList(); - this.options.app.layout.workspaceComponentViewerRegion.reset(); - key.setScope('home'); - this.options.app.issuesView.unbindScrollEvents(); - this.options.app.homeView = new HomeView({ - app: this.options.app, - collection: this.options.app.filters - }); - this.options.app.layout.workspaceHomeRegion.show(this.options.app.homeView); - return this.options.app.layout.showHomePage(); - }, - - hideHomePage: function () { - this.options.app.layout.workspaceComponentViewerRegion.reset(); - this.options.app.layout.workspaceHomeRegion.reset(); - key.setScope('list'); - this.options.app.layout.hideHomePage(); - this.options.app.issuesView.bindScrollEvents(); - return this.options.app.issuesView.scrollTo(); - } - }); + showHomePage: function () { + this.fetchList(); + this.options.app.layout.workspaceComponentViewerRegion.reset(); + key.setScope('home'); + this.options.app.issuesView.unbindScrollEvents(); + this.options.app.homeView = new HomeView({ + app: this.options.app, + collection: this.options.app.filters + }); + this.options.app.layout.workspaceHomeRegion.show(this.options.app.homeView); + return this.options.app.layout.showHomePage(); + }, + hideHomePage: function () { + this.options.app.layout.workspaceComponentViewerRegion.reset(); + this.options.app.layout.workspaceHomeRegion.reset(); + key.setScope('list'); + this.options.app.layout.hideHomePage(); + this.options.app.issuesView.bindScrollEvents(); + return this.options.app.issuesView.scrollTo(); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/issues/facets-view.js b/server/sonar-web/src/main/js/apps/issues/facets-view.js index fa715f902f7..82fd76fe714 100644 --- a/server/sonar-web/src/main/js/apps/issues/facets-view.js +++ b/server/sonar-web/src/main/js/apps/issues/facets-view.js @@ -1,52 +1,48 @@ -define([ - 'components/navigator/facets-view', - './facets/base-facet', - './facets/severity-facet', - './facets/status-facet', - './facets/project-facet', - './facets/module-facet', - './facets/assignee-facet', - './facets/rule-facet', - './facets/tag-facet', - './facets/resolution-facet', - './facets/creation-date-facet', - './facets/action-plan-facet', - './facets/file-facet', - './facets/reporter-facet', - './facets/language-facet', - './facets/author-facet', - './facets/issue-key-facet', - './facets/context-facet', - './facets/mode-facet' -], function (FacetsView, BaseFacet, SeverityFacet, StatusFacet, ProjectFacet, ModuleFacet, AssigneeFacet, RuleFacet, - TagFacet, ResolutionFacet, CreationDateFacet, ActionPlanFacet, FileFacet, ReporterFacet, LanguageFacet, - AuthorFacet, IssueKeyFacet, ContextFacet, ModeFacet) { +import FacetsView from 'components/navigator/facets-view'; +import BaseFacet from './facets/base-facet'; +import SeverityFacet from './facets/severity-facet'; +import StatusFacet from './facets/status-facet'; +import ProjectFacet from './facets/project-facet'; +import ModuleFacet from './facets/module-facet'; +import AssigneeFacet from './facets/assignee-facet'; +import RuleFacet from './facets/rule-facet'; +import TagFacet from './facets/tag-facet'; +import ResolutionFacet from './facets/resolution-facet'; +import CreationDateFacet from './facets/creation-date-facet'; +import ActionPlanFacet from './facets/action-plan-facet'; +import FileFacet from './facets/file-facet'; +import ReporterFacet from './facets/reporter-facet'; +import LanguageFacet from './facets/language-facet'; +import AuthorFacet from './facets/author-facet'; +import IssueKeyFacet from './facets/issue-key-facet'; +import ContextFacet from './facets/context-facet'; +import ModeFacet from './facets/mode-facet'; - var viewsMapping = { - severities: SeverityFacet, - statuses: StatusFacet, - assignees: AssigneeFacet, - resolutions: ResolutionFacet, - createdAt: CreationDateFacet, - projectUuids: ProjectFacet, - moduleUuids: ModuleFacet, - rules: RuleFacet, - tags: TagFacet, - actionPlans: ActionPlanFacet, - fileUuids: FileFacet, - reporters: ReporterFacet, - languages: LanguageFacet, - authors: AuthorFacet, - issues: IssueKeyFacet, - context: ContextFacet, - facetMode: ModeFacet - }; - - return FacetsView.extend({ - getChildView: function (model) { - var view = viewsMapping[model.get('property')]; - return view ? view : BaseFacet; - } - }); +var viewsMapping = { + severities: SeverityFacet, + statuses: StatusFacet, + assignees: AssigneeFacet, + resolutions: ResolutionFacet, + createdAt: CreationDateFacet, + projectUuids: ProjectFacet, + moduleUuids: ModuleFacet, + rules: RuleFacet, + tags: TagFacet, + actionPlans: ActionPlanFacet, + fileUuids: FileFacet, + reporters: ReporterFacet, + languages: LanguageFacet, + authors: AuthorFacet, + issues: IssueKeyFacet, + context: ContextFacet, + facetMode: ModeFacet +}; +export default FacetsView.extend({ + getChildView: function (model) { + var view = viewsMapping[model.get('property')]; + return view ? view : BaseFacet; + } }); + + diff --git a/server/sonar-web/src/main/js/apps/issues/facets/action-plan-facet.js b/server/sonar-web/src/main/js/apps/issues/facets/action-plan-facet.js index d85fa9e5dfd..fa415f981ff 100644 --- a/server/sonar-web/src/main/js/apps/issues/facets/action-plan-facet.js +++ b/server/sonar-web/src/main/js/apps/issues/facets/action-plan-facet.js @@ -1,68 +1,66 @@ -define([ - './base-facet', - '../templates' -], function (BaseFacet) { +import $ from 'jquery'; +import _ from 'underscore'; +import BaseFacet from './base-facet'; +import '../templates'; - var $ = jQuery; +export default BaseFacet.extend({ + template: Templates['issues-action-plan-facet'], - return BaseFacet.extend({ - template: Templates['issues-action-plan-facet'], - - onRender: function () { - BaseFacet.prototype.onRender.apply(this, arguments); - var value = this.options.app.state.get('query').planned; - if ((value != null) && (!value || value === 'false')) { - return this.$('.js-facet').filter('[data-unplanned]').addClass('active'); - } - }, - - toggleFacet: function (e) { - var unplanned = $(e.currentTarget).is('[data-unplanned]'); - $(e.currentTarget).toggleClass('active'); - if (unplanned) { - var checked = $(e.currentTarget).is('.active'), - value = checked ? 'false' : null; - return this.options.app.state.updateFilter({ - planned: value, - actionPlans: null - }); - } else { - return this.options.app.state.updateFilter({ - planned: null, - actionPlans: this.getValue() - }); - } - }, - - getValuesWithLabels: function () { - var values = this.model.getValues(), - actionPlans = this.options.app.facets.actionPlans; - values.forEach(function (v) { - var key = v.val, - label = null; - if (key) { - var actionPlan = _.findWhere(actionPlans, { key: key }); - if (actionPlan != null) { - label = actionPlan.name; - } - } - v.label = label; - }); - return values; - }, + onRender: function () { + BaseFacet.prototype.onRender.apply(this, arguments); + var value = this.options.app.state.get('query').planned; + if ((value != null) && (!value || value === 'false')) { + return this.$('.js-facet').filter('[data-unplanned]').addClass('active'); + } + }, - disable: function () { + toggleFacet: function (e) { + var unplanned = $(e.currentTarget).is('[data-unplanned]'); + $(e.currentTarget).toggleClass('active'); + if (unplanned) { + var checked = $(e.currentTarget).is('.active'), + value = checked ? 'false' : null; return this.options.app.state.updateFilter({ - planned: null, + planned: value, actionPlans: null }); - }, - - serializeData: function () { - return _.extend(BaseFacet.prototype.serializeData.apply(this, arguments), { - values: this.getValuesWithLabels() + } else { + return this.options.app.state.updateFilter({ + planned: null, + actionPlans: this.getValue() }); } - }); + }, + getValuesWithLabels: function () { + var values = this.model.getValues(), + actionPlans = this.options.app.facets.actionPlans; + values.forEach(function (v) { + var key = v.val, + label = null; + if (key) { + var actionPlan = _.findWhere(actionPlans, { key: key }); + if (actionPlan != null) { + label = actionPlan.name; + } + } + v.label = label; + }); + return values; + }, + + disable: function () { + return this.options.app.state.updateFilter({ + planned: null, + actionPlans: null + }); + }, + + serializeData: function () { + return _.extend(BaseFacet.prototype.serializeData.apply(this, arguments), { + values: this.getValuesWithLabels() + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/issues/facets/assignee-facet.js b/server/sonar-web/src/main/js/apps/issues/facets/assignee-facet.js index 3645b7215d6..edebc4adf52 100644 --- a/server/sonar-web/src/main/js/apps/issues/facets/assignee-facet.js +++ b/server/sonar-web/src/main/js/apps/issues/facets/assignee-facet.js @@ -1,108 +1,106 @@ -define([ - './custom-values-facet', - '../templates' -], function (CustomValuesFacet) { +import $ from 'jquery'; +import _ from 'underscore'; +import CustomValuesFacet from './custom-values-facet'; +import '../templates'; - var $ = jQuery; +export default CustomValuesFacet.extend({ + template: Templates['issues-assignee-facet'], - return CustomValuesFacet.extend({ - template: Templates['issues-assignee-facet'], + getUrl: function () { + return baseUrl + '/api/users/search'; + }, - getUrl: function () { - return baseUrl + '/api/users/search'; - }, + prepareAjaxSearch: function () { + return { + quietMillis: 300, + url: this.getUrl(), + data: function (term, page) { + return { q: term, p: page }; + }, + results: window.usersToSelect2 + }; + }, - prepareAjaxSearch: function () { - return { - quietMillis: 300, - url: this.getUrl(), - data: function (term, page) { - return { q: term, p: page }; - }, - results: window.usersToSelect2 - }; - }, - - onRender: function () { - CustomValuesFacet.prototype.onRender.apply(this, arguments); - var value = this.options.app.state.get('query').assigned; - if ((value != null) && (!value || value === 'false')) { - return this.$('.js-facet').filter('[data-unassigned]').addClass('active'); - } - }, - - toggleFacet: function (e) { - var unassigned = $(e.currentTarget).is('[data-unassigned]'); - $(e.currentTarget).toggleClass('active'); - if (unassigned) { - var checked = $(e.currentTarget).is('.active'), - value = checked ? 'false' : null; - return this.options.app.state.updateFilter({ - assigned: value, - assignees: null - }); - } else { - return this.options.app.state.updateFilter({ - assigned: null, - assignees: this.getValue() - }); - } - }, + onRender: function () { + CustomValuesFacet.prototype.onRender.apply(this, arguments); + var value = this.options.app.state.get('query').assigned; + if ((value != null) && (!value || value === 'false')) { + return this.$('.js-facet').filter('[data-unassigned]').addClass('active'); + } + }, - getValuesWithLabels: function () { - var values = this.model.getValues(), - users = this.options.app.facets.users; - values.forEach(function (v) { - var login = v.val, - name = ''; - if (login) { - var user = _.findWhere(users, { login: login }); - if (user != null) { - name = user.name; - } - } - v.label = name; + toggleFacet: function (e) { + var unassigned = $(e.currentTarget).is('[data-unassigned]'); + $(e.currentTarget).toggleClass('active'); + if (unassigned) { + var checked = $(e.currentTarget).is('.active'), + value = checked ? 'false' : null; + return this.options.app.state.updateFilter({ + assigned: value, + assignees: null }); - return values; - }, - - disable: function () { + } else { return this.options.app.state.updateFilter({ assigned: null, - assignees: null + assignees: this.getValue() }); - }, + } + }, - addCustomValue: function () { - var property = this.model.get('property'), - customValue = this.$('.js-custom-value').select2('val'), - value = this.getValue(); - if (value.length > 0) { - value += ','; + getValuesWithLabels: function () { + var values = this.model.getValues(), + users = this.options.app.facets.users; + values.forEach(function (v) { + var login = v.val, + name = ''; + if (login) { + var user = _.findWhere(users, { login: login }); + if (user != null) { + name = user.name; + } } - value += customValue; - var obj = {}; - obj[property] = value; - obj.assigned = null; - return this.options.app.state.updateFilter(obj); - }, + v.label = name; + }); + return values; + }, - sortValues: function (values) { - return _.sortBy(values, function (v) { - return v.val === '' ? -999999 : -v.count; - }); - }, + disable: function () { + return this.options.app.state.updateFilter({ + assigned: null, + assignees: null + }); + }, - getNumberOfMyIssues: function () { - return this.options.app.state.get('myIssues'); - }, - - serializeData: function () { - return _.extend(CustomValuesFacet.prototype.serializeData.apply(this, arguments), { - myIssues: this.getNumberOfMyIssues(), - values: this.sortValues(this.getValuesWithLabels()) - }); + addCustomValue: function () { + var property = this.model.get('property'), + customValue = this.$('.js-custom-value').select2('val'), + value = this.getValue(); + if (value.length > 0) { + value += ','; } - }); + value += customValue; + var obj = {}; + obj[property] = value; + obj.assigned = null; + return this.options.app.state.updateFilter(obj); + }, + sortValues: function (values) { + return _.sortBy(values, function (v) { + return v.val === '' ? -999999 : -v.count; + }); + }, + + getNumberOfMyIssues: function () { + return this.options.app.state.get('myIssues'); + }, + + serializeData: function () { + return _.extend(CustomValuesFacet.prototype.serializeData.apply(this, arguments), { + myIssues: this.getNumberOfMyIssues(), + values: this.sortValues(this.getValuesWithLabels()) + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/issues/facets/author-facet.js b/server/sonar-web/src/main/js/apps/issues/facets/author-facet.js index ee987a3d067..6567912ab1e 100644 --- a/server/sonar-web/src/main/js/apps/issues/facets/author-facet.js +++ b/server/sonar-web/src/main/js/apps/issues/facets/author-facet.js @@ -1,44 +1,42 @@ -define([ - './custom-values-facet' -], function (CustomValuesFacet) { +import CustomValuesFacet from './custom-values-facet'; - return CustomValuesFacet.extend({ - getUrl: function () { - return baseUrl + '/api/issues/authors'; - }, +export default CustomValuesFacet.extend({ + getUrl: function () { + return baseUrl + '/api/issues/authors'; + }, - prepareSearch: function () { - return this.$('.js-custom-value').select2({ - placeholder: 'Search...', - minimumInputLength: 2, - allowClear: false, - formatNoMatches: function () { - return t('select2.noMatches'); + prepareSearch: function () { + return this.$('.js-custom-value').select2({ + placeholder: 'Search...', + minimumInputLength: 2, + allowClear: false, + formatNoMatches: function () { + return t('select2.noMatches'); + }, + formatSearching: function () { + return t('select2.searching'); + }, + formatInputTooShort: function () { + return tp('select2.tooShort', 2); + }, + width: '100%', + ajax: { + quietMillis: 300, + url: this.getUrl(), + data: function (term) { + return { q: term, ps: 25 }; }, - formatSearching: function () { - return t('select2.searching'); - }, - formatInputTooShort: function () { - return tp('select2.tooShort', 2); - }, - width: '100%', - ajax: { - quietMillis: 300, - url: this.getUrl(), - data: function (term) { - return { q: term, ps: 25 }; - }, - results: function (data) { - return { - more: false, - results: data.authors.map(function (author) { - return { id: author, text: author }; - }) - }; - } + results: function (data) { + return { + more: false, + results: data.authors.map(function (author) { + return { id: author, text: author }; + }) + }; } - }); - } - }); - + } + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/issues/facets/base-facet.js b/server/sonar-web/src/main/js/apps/issues/facets/base-facet.js index 923e1d4e6d1..d781c602fbd 100644 --- a/server/sonar-web/src/main/js/apps/issues/facets/base-facet.js +++ b/server/sonar-web/src/main/js/apps/issues/facets/base-facet.js @@ -1,25 +1,24 @@ -define([ - 'components/navigator/facets/base-facet', - '../templates' -], function (BaseFacet) { +import _ from 'underscore'; +import BaseFacet from 'components/navigator/facets/base-facet'; +import '../templates'; - return BaseFacet.extend({ - template: Templates['issues-base-facet'], +export default BaseFacet.extend({ + template: Templates['issues-base-facet'], - onRender: function () { - BaseFacet.prototype.onRender.apply(this, arguments); - return this.$('[data-toggle="tooltip"]').tooltip({ container: 'body' }); - }, + onRender: function () { + BaseFacet.prototype.onRender.apply(this, arguments); + return this.$('[data-toggle="tooltip"]').tooltip({ container: 'body' }); + }, - onDestroy: function () { - return this.$('[data-toggle="tooltip"]').tooltip('destroy'); - }, - - serializeData: function () { - return _.extend(this._super(), { - state: this.options.app.state.toJSON() - }); - } - }); + onDestroy: function () { + return this.$('[data-toggle="tooltip"]').tooltip('destroy'); + }, + serializeData: function () { + return _.extend(this._super(), { + state: this.options.app.state.toJSON() + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/issues/facets/context-facet.js b/server/sonar-web/src/main/js/apps/issues/facets/context-facet.js index 48c88c8f1c0..4f49aebc6ea 100644 --- a/server/sonar-web/src/main/js/apps/issues/facets/context-facet.js +++ b/server/sonar-web/src/main/js/apps/issues/facets/context-facet.js @@ -1,16 +1,15 @@ -define([ - './base-facet', - '../templates' -], function (BaseFacet) { +import _ from 'underscore'; +import BaseFacet from './base-facet'; +import '../templates'; - return BaseFacet.extend({ - template: Templates['issues-context-facet'], - - serializeData: function () { - return _.extend(BaseFacet.prototype.serializeData.apply(this, arguments), { - state: this.options.app.state.toJSON() - }); - } - }); +export default BaseFacet.extend({ + template: Templates['issues-context-facet'], + serializeData: function () { + return _.extend(BaseFacet.prototype.serializeData.apply(this, arguments), { + state: this.options.app.state.toJSON() + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/issues/facets/creation-date-facet.js b/server/sonar-web/src/main/js/apps/issues/facets/creation-date-facet.js index fbf81e94fbb..34edcbf706d 100644 --- a/server/sonar-web/src/main/js/apps/issues/facets/creation-date-facet.js +++ b/server/sonar-web/src/main/js/apps/issues/facets/creation-date-facet.js @@ -1,135 +1,133 @@ -define([ - './base-facet', - '../templates' -], function (BaseFacet) { - - var $ = jQuery; - - return BaseFacet.extend({ - template: Templates['issues-creation-date-facet'], - - events: function () { - return _.extend(BaseFacet.prototype.events.apply(this, arguments), { - 'change input': 'applyFacet', - 'click .js-select-period-start': 'selectPeriodStart', - 'click .js-select-period-end': 'selectPeriodEnd', - 'click .sonar-d3 rect': 'selectBar', - 'click .js-all': 'onAllClick', - 'click .js-last-week': 'onLastWeekClick', - 'click .js-last-month': 'onLastMonthClick', - 'click .js-last-year': 'onLastYearClick' - }); - }, - - onRender: function () { - var that = this; - this.$el.toggleClass('search-navigator-facet-box-collapsed', !this.model.get('enabled')); - this.$('input').datepicker({ - dateFormat: 'yy-mm-dd', - changeMonth: true, - changeYear: true - }); - var props = ['createdAfter', 'createdBefore', 'createdAt'], - query = this.options.app.state.get('query'); - props.forEach(function (prop) { - var value = query[prop]; - if (value != null) { - return that.$('input[name=' + prop + ']').val(value); - } - }); - var values = this.model.getValues(); - if (!(_.isArray(values) && values.length > 0)) { - var date = moment(); - values = []; - _.times(10, function () { - values.push({ count: 0, val: date.toDate().toString() }); - date = date.subtract(1, 'days'); - }); - values.reverse(); +import $ from 'jquery'; +import _ from 'underscore'; +import BaseFacet from './base-facet'; +import '../templates'; + +export default BaseFacet.extend({ + template: Templates['issues-creation-date-facet'], + + events: function () { + return _.extend(BaseFacet.prototype.events.apply(this, arguments), { + 'change input': 'applyFacet', + 'click .js-select-period-start': 'selectPeriodStart', + 'click .js-select-period-end': 'selectPeriodEnd', + 'click .sonar-d3 rect': 'selectBar', + 'click .js-all': 'onAllClick', + 'click .js-last-week': 'onLastWeekClick', + 'click .js-last-month': 'onLastMonthClick', + 'click .js-last-year': 'onLastYearClick' + }); + }, + + onRender: function () { + var that = this; + this.$el.toggleClass('search-navigator-facet-box-collapsed', !this.model.get('enabled')); + this.$('input').datepicker({ + dateFormat: 'yy-mm-dd', + changeMonth: true, + changeYear: true + }); + var props = ['createdAfter', 'createdBefore', 'createdAt'], + query = this.options.app.state.get('query'); + props.forEach(function (prop) { + var value = query[prop]; + if (value != null) { + return that.$('input[name=' + prop + ']').val(value); } - values = values.map(function (v) { - var format = that.options.app.state.getFacetMode() === 'count' ? 'SHORT_INT' : 'SHORT_WORK_DUR'; - var text = window.formatMeasure(v.count, format); - return _.extend(v, { text: text }); - }); - return this.$('.js-barchart').barchart(values); - }, - - selectPeriodStart: function () { - return this.$('.js-period-start').datepicker('show'); - }, - - selectPeriodEnd: function () { - return this.$('.js-period-end').datepicker('show'); - }, - - applyFacet: function () { - var obj = { createdAt: null, createdInLast: null }; - this.$('input').each(function () { - var property, value; - property = $(this).prop('name'); - value = $(this).val(); - obj[property] = value; - }); - return this.options.app.state.updateFilter(obj); - }, - - disable: function () { - return this.options.app.state.updateFilter({ - createdAfter: null, - createdBefore: null, - createdAt: null, - createdInLast: null - }); - }, - - selectBar: function (e) { - var periodStart = $(e.currentTarget).data('period-start'), - periodEnd = $(e.currentTarget).data('period-end'); - return this.options.app.state.updateFilter({ - createdAfter: periodStart, - createdBefore: periodEnd, - createdAt: null, - createdInLast: null - }); - }, - - selectPeriod: function (period) { - return this.options.app.state.updateFilter({ - createdAfter: null, - createdBefore: null, - createdAt: null, - createdInLast: period - }); - }, - - onAllClick: function () { - return this.disable(); - }, - - onLastWeekClick: function (e) { - e.preventDefault(); - return this.selectPeriod('1w'); - }, - - onLastMonthClick: function (e) { - e.preventDefault(); - return this.selectPeriod('1m'); - }, - - onLastYearClick: function (e) { - e.preventDefault(); - return this.selectPeriod('1y'); - }, - - serializeData: function () { - return _.extend(BaseFacet.prototype.serializeData.apply(this, arguments), { - periodStart: this.options.app.state.get('query').createdAfter, - periodEnd: this.options.app.state.get('query').createdBefore, - createdAt: this.options.app.state.get('query').createdAt, - createdInLast: this.options.app.state.get('query').createdInLast + }); + var values = this.model.getValues(); + if (!(_.isArray(values) && values.length > 0)) { + var date = moment(); + values = []; + _.times(10, function () { + values.push({ count: 0, val: date.toDate().toString() }); + date = date.subtract(1, 'days'); }); + values.reverse(); } - }); - + values = values.map(function (v) { + var format = that.options.app.state.getFacetMode() === 'count' ? 'SHORT_INT' : 'SHORT_WORK_DUR'; + var text = window.formatMeasure(v.count, format); + return _.extend(v, { text: text }); + }); + return this.$('.js-barchart').barchart(values); + }, + + selectPeriodStart: function () { + return this.$('.js-period-start').datepicker('show'); + }, + + selectPeriodEnd: function () { + return this.$('.js-period-end').datepicker('show'); + }, + + applyFacet: function () { + var obj = { createdAt: null, createdInLast: null }; + this.$('input').each(function () { + var property, value; + property = $(this).prop('name'); + value = $(this).val(); + obj[property] = value; + }); + return this.options.app.state.updateFilter(obj); + }, + + disable: function () { + return this.options.app.state.updateFilter({ + createdAfter: null, + createdBefore: null, + createdAt: null, + createdInLast: null + }); + }, + + selectBar: function (e) { + var periodStart = $(e.currentTarget).data('period-start'), + periodEnd = $(e.currentTarget).data('period-end'); + return this.options.app.state.updateFilter({ + createdAfter: periodStart, + createdBefore: periodEnd, + createdAt: null, + createdInLast: null + }); + }, + + selectPeriod: function (period) { + return this.options.app.state.updateFilter({ + createdAfter: null, + createdBefore: null, + createdAt: null, + createdInLast: period + }); + }, + + onAllClick: function () { + return this.disable(); + }, + + onLastWeekClick: function (e) { + e.preventDefault(); + return this.selectPeriod('1w'); + }, + + onLastMonthClick: function (e) { + e.preventDefault(); + return this.selectPeriod('1m'); + }, + + onLastYearClick: function (e) { + e.preventDefault(); + return this.selectPeriod('1y'); + }, + + serializeData: function () { + return _.extend(BaseFacet.prototype.serializeData.apply(this, arguments), { + periodStart: this.options.app.state.get('query').createdAfter, + periodEnd: this.options.app.state.get('query').createdBefore, + createdAt: this.options.app.state.get('query').createdAt, + createdInLast: this.options.app.state.get('query').createdInLast + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/issues/facets/custom-values-facet.js b/server/sonar-web/src/main/js/apps/issues/facets/custom-values-facet.js index 11b3aebdd74..04faae8470b 100644 --- a/server/sonar-web/src/main/js/apps/issues/facets/custom-values-facet.js +++ b/server/sonar-web/src/main/js/apps/issues/facets/custom-values-facet.js @@ -1,70 +1,69 @@ -define([ - './base-facet', - '../templates' -], function (BaseFacet) { +import _ from 'underscore'; +import BaseFacet from './base-facet'; +import '../templates'; - return BaseFacet.extend({ - template: Templates['issues-custom-values-facet'], +export default BaseFacet.extend({ + template: Templates['issues-custom-values-facet'], - events: function () { - return _.extend(BaseFacet.prototype.events.apply(this, arguments), { - 'change .js-custom-value': 'addCustomValue' - }); - }, + events: function () { + return _.extend(BaseFacet.prototype.events.apply(this, arguments), { + 'change .js-custom-value': 'addCustomValue' + }); + }, - getUrl: function () { + getUrl: function () { - }, + }, - onRender: function () { - BaseFacet.prototype.onRender.apply(this, arguments); - return this.prepareSearch(); - }, + onRender: function () { + BaseFacet.prototype.onRender.apply(this, arguments); + return this.prepareSearch(); + }, - prepareSearch: function () { - return this.$('.js-custom-value').select2({ - placeholder: 'Search...', - minimumInputLength: 2, - allowClear: false, - formatNoMatches: function () { - return t('select2.noMatches'); - }, - formatSearching: function () { - return t('select2.searching'); - }, - formatInputTooShort: function () { - return tp('select2.tooShort', 2); - }, - width: '100%', - ajax: this.prepareAjaxSearch() - }); - }, + prepareSearch: function () { + return this.$('.js-custom-value').select2({ + placeholder: 'Search...', + minimumInputLength: 2, + allowClear: false, + formatNoMatches: function () { + return t('select2.noMatches'); + }, + formatSearching: function () { + return t('select2.searching'); + }, + formatInputTooShort: function () { + return tp('select2.tooShort', 2); + }, + width: '100%', + ajax: this.prepareAjaxSearch() + }); + }, - prepareAjaxSearch: function () { - return { - quietMillis: 300, - url: this.getUrl(), - data: function (term, page) { - return { s: term, p: page }; - }, - results: function (data) { - return { more: data.more, results: data.results }; - } - }; - }, - - addCustomValue: function () { - var property = this.model.get('property'), - customValue = this.$('.js-custom-value').select2('val'), - value = this.getValue(); - if (value.length > 0) { - value += ','; + prepareAjaxSearch: function () { + return { + quietMillis: 300, + url: this.getUrl(), + data: function (term, page) { + return { s: term, p: page }; + }, + results: function (data) { + return { more: data.more, results: data.results }; } - value += customValue; - var obj = {}; - obj[property] = value; - return this.options.app.state.updateFilter(obj); - } - }); + }; + }, + addCustomValue: function () { + var property = this.model.get('property'), + customValue = this.$('.js-custom-value').select2('val'), + value = this.getValue(); + if (value.length > 0) { + value += ','; + } + value += customValue; + var obj = {}; + obj[property] = value; + return this.options.app.state.updateFilter(obj); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/issues/facets/file-facet.js b/server/sonar-web/src/main/js/apps/issues/facets/file-facet.js index d01340e6d3c..0c904feeec5 100644 --- a/server/sonar-web/src/main/js/apps/issues/facets/file-facet.js +++ b/server/sonar-web/src/main/js/apps/issues/facets/file-facet.js @@ -1,43 +1,41 @@ -define([ - './base-facet', - '../templates' -], function (BaseFacet) { +import $ from 'jquery'; +import _ from 'underscore'; +import BaseFacet from './base-facet'; +import '../templates'; - var $ = jQuery; +export default BaseFacet.extend({ + template: Templates['issues-file-facet'], - return BaseFacet.extend({ - template: Templates['issues-file-facet'], + onRender: function () { + BaseFacet.prototype.onRender.apply(this, arguments); + var maxValueWidth = _.max(this.$('.facet-stat').map(function () { + return $(this).outerWidth(); + }).get()); + return this.$('.facet-name').css('padding-right', maxValueWidth); + }, - onRender: function () { - BaseFacet.prototype.onRender.apply(this, arguments); - var maxValueWidth = _.max(this.$('.facet-stat').map(function () { - return $(this).outerWidth(); - }).get()); - return this.$('.facet-name').css('padding-right', maxValueWidth); - }, - - getValuesWithLabels: function () { - var values = this.model.getValues(), - source = this.options.app.facets.components; - values.forEach(function (v) { - var key = v.val, - label = null; - if (key) { - var item = _.findWhere(source, { uuid: key }); - if (item != null) { - label = item.longName; - } + getValuesWithLabels: function () { + var values = this.model.getValues(), + source = this.options.app.facets.components; + values.forEach(function (v) { + var key = v.val, + label = null; + if (key) { + var item = _.findWhere(source, { uuid: key }); + if (item != null) { + label = item.longName; } - v.label = label; - }); - return values; - }, - - serializeData: function () { - return _.extend(BaseFacet.prototype.serializeData.apply(this, arguments), { - values: this.sortValues(this.getValuesWithLabels()) - }); - } - }); + } + v.label = label; + }); + return values; + }, + serializeData: function () { + return _.extend(BaseFacet.prototype.serializeData.apply(this, arguments), { + values: this.sortValues(this.getValuesWithLabels()) + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/issues/facets/issue-key-facet.js b/server/sonar-web/src/main/js/apps/issues/facets/issue-key-facet.js index 2d309b85a3e..b7e8cfd136a 100644 --- a/server/sonar-web/src/main/js/apps/issues/facets/issue-key-facet.js +++ b/server/sonar-web/src/main/js/apps/issues/facets/issue-key-facet.js @@ -1,24 +1,23 @@ -define([ - './base-facet', - '../templates' -], function (BaseFacet) { +import _ from 'underscore'; +import BaseFacet from './base-facet'; +import '../templates'; - return BaseFacet.extend({ - template: Templates['issues-issue-key-facet'], +export default BaseFacet.extend({ + template: Templates['issues-issue-key-facet'], - onRender: function () { - return this.$el.toggleClass('hidden', !this.options.app.state.get('query').issues); - }, + onRender: function () { + return this.$el.toggleClass('hidden', !this.options.app.state.get('query').issues); + }, - disable: function () { - return this.options.app.state.updateFilter({ issues: null }); - }, - - serializeData: function () { - return _.extend(BaseFacet.prototype.serializeData.apply(this, arguments), { - issues: this.options.app.state.get('query').issues - }); - } - }); + disable: function () { + return this.options.app.state.updateFilter({ issues: null }); + }, + serializeData: function () { + return _.extend(BaseFacet.prototype.serializeData.apply(this, arguments), { + issues: this.options.app.state.get('query').issues + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/issues/facets/language-facet.js b/server/sonar-web/src/main/js/apps/issues/facets/language-facet.js index 3418158fba4..c3d6f274420 100644 --- a/server/sonar-web/src/main/js/apps/issues/facets/language-facet.js +++ b/server/sonar-web/src/main/js/apps/issues/facets/language-facet.js @@ -1,67 +1,66 @@ -define([ - './custom-values-facet' -], function (CustomValuesFacet) { +import _ from 'underscore'; +import CustomValuesFacet from './custom-values-facet'; - return CustomValuesFacet.extend({ - getUrl: function () { - return baseUrl + '/api/languages/list'; - }, +export default CustomValuesFacet.extend({ + getUrl: function () { + return baseUrl + '/api/languages/list'; + }, - prepareSearch: function () { - return this.$('.js-custom-value').select2({ - placeholder: 'Search...', - minimumInputLength: 2, - allowClear: false, - formatNoMatches: function () { - return t('select2.noMatches'); + prepareSearch: function () { + return this.$('.js-custom-value').select2({ + placeholder: 'Search...', + minimumInputLength: 2, + allowClear: false, + formatNoMatches: function () { + return t('select2.noMatches'); + }, + formatSearching: function () { + return t('select2.searching'); + }, + formatInputTooShort: function () { + return tp('select2.tooShort', 2); + }, + width: '100%', + ajax: { + quietMillis: 300, + url: this.getUrl(), + data: function (term) { + return { q: term, ps: 0 }; }, - formatSearching: function () { - return t('select2.searching'); - }, - formatInputTooShort: function () { - return tp('select2.tooShort', 2); - }, - width: '100%', - ajax: { - quietMillis: 300, - url: this.getUrl(), - data: function (term) { - return { q: term, ps: 0 }; - }, - results: function (data) { - return { - more: false, - results: data.languages.map(function (lang) { - return { id: lang.key, text: lang.name }; - }) - }; - } + results: function (data) { + return { + more: false, + results: data.languages.map(function (lang) { + return { id: lang.key, text: lang.name }; + }) + }; } - }); - }, + } + }); + }, - getValuesWithLabels: function () { - var values = this.model.getValues(), - source = this.options.app.facets.languages; - values.forEach(function (v) { - var key = v.val, - label = null; - if (key) { - var item = _.findWhere(source, { key: key }); - if (item != null) { - label = item.name; - } + getValuesWithLabels: function () { + var values = this.model.getValues(), + source = this.options.app.facets.languages; + values.forEach(function (v) { + var key = v.val, + label = null; + if (key) { + var item = _.findWhere(source, { key: key }); + if (item != null) { + label = item.name; } - v.label = label; - }); - return values; - }, - - serializeData: function () { - return _.extend(CustomValuesFacet.prototype.serializeData.apply(this, arguments), { - values: this.sortValues(this.getValuesWithLabels()) - }); - } - }); + } + v.label = label; + }); + return values; + }, + serializeData: function () { + return _.extend(CustomValuesFacet.prototype.serializeData.apply(this, arguments), { + values: this.sortValues(this.getValuesWithLabels()) + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/issues/facets/mode-facet.js b/server/sonar-web/src/main/js/apps/issues/facets/mode-facet.js index 454b4e96803..d826c379940 100644 --- a/server/sonar-web/src/main/js/apps/issues/facets/mode-facet.js +++ b/server/sonar-web/src/main/js/apps/issues/facets/mode-facet.js @@ -1,23 +1,22 @@ -define([ - './base-facet', - '../templates' -], function (BaseFacet) { +import _ from 'underscore'; +import BaseFacet from './base-facet'; +import '../templates'; - return BaseFacet.extend({ - template: Templates['issues-mode-facet'], +export default BaseFacet.extend({ + template: Templates['issues-mode-facet'], - events: { - 'change [name="issues-page-mode"]': 'onModeChange' - }, + events: { + 'change [name="issues-page-mode"]': 'onModeChange' + }, - onModeChange: function () { - var mode = this.$('[name="issues-page-mode"]:checked').val(); - this.options.app.state.updateFilter({ facetMode: mode }); - }, - - serializeData: function () { - return _.extend(this._super(), { mode: this.options.app.state.getFacetMode() }); - } - }); + onModeChange: function () { + var mode = this.$('[name="issues-page-mode"]:checked').val(); + this.options.app.state.updateFilter({ facetMode: mode }); + }, + serializeData: function () { + return _.extend(this._super(), { mode: this.options.app.state.getFacetMode() }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/issues/facets/module-facet.js b/server/sonar-web/src/main/js/apps/issues/facets/module-facet.js index 96c4a1de07f..ef950762081 100644 --- a/server/sonar-web/src/main/js/apps/issues/facets/module-facet.js +++ b/server/sonar-web/src/main/js/apps/issues/facets/module-facet.js @@ -1,30 +1,29 @@ -define([ - './base-facet' -], function (BaseFacet) { +import _ from 'underscore'; +import BaseFacet from './base-facet'; - return BaseFacet.extend({ - getValuesWithLabels: function () { - var values = this.model.getValues(), - components = this.options.app.facets.components; - values.forEach(function (v) { - var uuid = v.val, - label = uuid; - if (uuid) { - var component = _.findWhere(components, { uuid: uuid }); - if (component != null) { - label = component.longName; - } +export default BaseFacet.extend({ + getValuesWithLabels: function () { + var values = this.model.getValues(), + components = this.options.app.facets.components; + values.forEach(function (v) { + var uuid = v.val, + label = uuid; + if (uuid) { + var component = _.findWhere(components, { uuid: uuid }); + if (component != null) { + label = component.longName; } - v.label = label; - }); - return values; - }, - - serializeData: function () { - return _.extend(BaseFacet.prototype.serializeData.apply(this, arguments), { - values: this.sortValues(this.getValuesWithLabels()) - }); - } - }); + } + v.label = label; + }); + return values; + }, + serializeData: function () { + return _.extend(BaseFacet.prototype.serializeData.apply(this, arguments), { + values: this.sortValues(this.getValuesWithLabels()) + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/issues/facets/project-facet.js b/server/sonar-web/src/main/js/apps/issues/facets/project-facet.js index 429d9e876c2..ba84cb017a2 100644 --- a/server/sonar-web/src/main/js/apps/issues/facets/project-facet.js +++ b/server/sonar-web/src/main/js/apps/issues/facets/project-facet.js @@ -1,83 +1,82 @@ -define([ - './custom-values-facet' -], function (CustomValuesFacet) { +import _ from 'underscore'; +import CustomValuesFacet from './custom-values-facet'; - return CustomValuesFacet.extend({ +export default CustomValuesFacet.extend({ - getUrl: function () { - var q = this.options.app.state.get('contextComponentQualifier'); - if (q === 'VW' || q === 'SVW') { - return baseUrl + '/api/components/search'; - } else { - return baseUrl + '/api/resources/search?f=s2&q=TRK&display_uuid=true'; - } - }, + getUrl: function () { + var q = this.options.app.state.get('contextComponentQualifier'); + if (q === 'VW' || q === 'SVW') { + return baseUrl + '/api/components/search'; + } else { + return baseUrl + '/api/resources/search?f=s2&q=TRK&display_uuid=true'; + } + }, - prepareSearch: function () { - var q = this.options.app.state.get('contextComponentQualifier'); - if (q === 'VW' || q === 'SVW') { - return this.prepareSearchForViews(); - } else { - return CustomValuesFacet.prototype.prepareSearch.apply(this, arguments); - } - }, + prepareSearch: function () { + var q = this.options.app.state.get('contextComponentQualifier'); + if (q === 'VW' || q === 'SVW') { + return this.prepareSearchForViews(); + } else { + return CustomValuesFacet.prototype.prepareSearch.apply(this, arguments); + } + }, - prepareSearchForViews: function () { - var componentUuid = this.options.app.state.get('contextComponentUuid'); - return this.$('.js-custom-value').select2({ - placeholder: 'Search...', - minimumInputLength: 2, - allowClear: false, - formatNoMatches: function () { - return t('select2.noMatches'); - }, - formatSearching: function () { - return t('select2.searching'); - }, - formatInputTooShort: function () { - return tp('select2.tooShort', 2); + prepareSearchForViews: function () { + var componentUuid = this.options.app.state.get('contextComponentUuid'); + return this.$('.js-custom-value').select2({ + placeholder: 'Search...', + minimumInputLength: 2, + allowClear: false, + formatNoMatches: function () { + return t('select2.noMatches'); + }, + formatSearching: function () { + return t('select2.searching'); + }, + formatInputTooShort: function () { + return tp('select2.tooShort', 2); + }, + width: '100%', + ajax: { + quietMillis: 300, + url: this.getUrl(), + data: function (term, page) { + return { q: term, componentUuid: componentUuid, p: page, ps: 25 }; }, - width: '100%', - ajax: { - quietMillis: 300, - url: this.getUrl(), - data: function (term, page) { - return { q: term, componentUuid: componentUuid, p: page, ps: 25 }; - }, - results: function (data) { - return { - more: data.p * data.ps < data.total, - results: data.components.map(function (c) { - return { id: c.uuid, text: c.name }; - }) - }; - } + results: function (data) { + return { + more: data.p * data.ps < data.total, + results: data.components.map(function (c) { + return { id: c.uuid, text: c.name }; + }) + }; } - }); - }, + } + }); + }, - getValuesWithLabels: function () { - var values = this.model.getValues(), - projects = this.options.app.facets.components; - values.forEach(function (v) { - var uuid = v.val, - label = ''; - if (uuid) { - var project = _.findWhere(projects, { uuid: uuid }); - if (project != null) { - label = project.longName; - } + getValuesWithLabels: function () { + var values = this.model.getValues(), + projects = this.options.app.facets.components; + values.forEach(function (v) { + var uuid = v.val, + label = ''; + if (uuid) { + var project = _.findWhere(projects, { uuid: uuid }); + if (project != null) { + label = project.longName; } - v.label = label; - }); - return values; - }, - - serializeData: function () { - return _.extend(CustomValuesFacet.prototype.serializeData.apply(this, arguments), { - values: this.sortValues(this.getValuesWithLabels()) - }); - } - }); + } + v.label = label; + }); + return values; + }, + serializeData: function () { + return _.extend(CustomValuesFacet.prototype.serializeData.apply(this, arguments), { + values: this.sortValues(this.getValuesWithLabels()) + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/issues/facets/reporter-facet.js b/server/sonar-web/src/main/js/apps/issues/facets/reporter-facet.js index 6340aefe04f..240297a469e 100644 --- a/server/sonar-web/src/main/js/apps/issues/facets/reporter-facet.js +++ b/server/sonar-web/src/main/js/apps/issues/facets/reporter-facet.js @@ -1,46 +1,45 @@ -define([ - './custom-values-facet' -], function (CustomValuesFacet) { +import _ from 'underscore'; +import CustomValuesFacet from './custom-values-facet'; - return CustomValuesFacet.extend({ - getUrl: function () { - return baseUrl + '/api/users/search'; - }, +export default CustomValuesFacet.extend({ + getUrl: function () { + return baseUrl + '/api/users/search'; + }, - prepareAjaxSearch: function () { - return { - quietMillis: 300, - url: this.getUrl(), - data: function (term, page) { - return { q: term, p: page }; - }, - results: window.usersToSelect2 - }; - }, + prepareAjaxSearch: function () { + return { + quietMillis: 300, + url: this.getUrl(), + data: function (term, page) { + return { q: term, p: page }; + }, + results: window.usersToSelect2 + }; + }, - getValuesWithLabels: function () { - var values = this.model.getValues(), - source = this.options.app.facets.users; - values.forEach(function (v) { - var item, key, label; - key = v.val; - label = null; - if (key) { - item = _.findWhere(source, { login: key }); - if (item != null) { - label = item.name; - } + getValuesWithLabels: function () { + var values = this.model.getValues(), + source = this.options.app.facets.users; + values.forEach(function (v) { + var item, key, label; + key = v.val; + label = null; + if (key) { + item = _.findWhere(source, { login: key }); + if (item != null) { + label = item.name; } - v.label = label; - }); - return values; - }, - - serializeData: function () { - return _.extend(CustomValuesFacet.prototype.serializeData.apply(this, arguments), { - values: this.sortValues(this.getValuesWithLabels()) - }); - } - }); + } + v.label = label; + }); + return values; + }, + serializeData: function () { + return _.extend(CustomValuesFacet.prototype.serializeData.apply(this, arguments), { + values: this.sortValues(this.getValuesWithLabels()) + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/issues/facets/resolution-facet.js b/server/sonar-web/src/main/js/apps/issues/facets/resolution-facet.js index 75dd3e78289..a15cf51aed7 100644 --- a/server/sonar-web/src/main/js/apps/issues/facets/resolution-facet.js +++ b/server/sonar-web/src/main/js/apps/issues/facets/resolution-facet.js @@ -1,52 +1,50 @@ -define([ - './base-facet', - '../templates' -], function (BaseFacet) { +import $ from 'jquery'; +import _ from 'underscore'; +import BaseFacet from './base-facet'; +import '../templates'; - var $ = jQuery; +export default BaseFacet.extend({ + template: Templates['issues-resolution-facet'], - return BaseFacet.extend({ - template: Templates['issues-resolution-facet'], - - onRender: function () { - BaseFacet.prototype.onRender.apply(this, arguments); - var value = this.options.app.state.get('query').resolved; - if ((value != null) && (!value || value === 'false')) { - return this.$('.js-facet').filter('[data-unresolved]').addClass('active'); - } - }, - - toggleFacet: function (e) { - var unresolved = $(e.currentTarget).is('[data-unresolved]'); - $(e.currentTarget).toggleClass('active'); - if (unresolved) { - var checked = $(e.currentTarget).is('.active'), - value = checked ? 'false' : null; - return this.options.app.state.updateFilter({ - resolved: value, - resolutions: null - }); - } else { - return this.options.app.state.updateFilter({ - resolved: null, - resolutions: this.getValue() - }); - } - }, + onRender: function () { + BaseFacet.prototype.onRender.apply(this, arguments); + var value = this.options.app.state.get('query').resolved; + if ((value != null) && (!value || value === 'false')) { + return this.$('.js-facet').filter('[data-unresolved]').addClass('active'); + } + }, - disable: function () { + toggleFacet: function (e) { + var unresolved = $(e.currentTarget).is('[data-unresolved]'); + $(e.currentTarget).toggleClass('active'); + if (unresolved) { + var checked = $(e.currentTarget).is('.active'), + value = checked ? 'false' : null; return this.options.app.state.updateFilter({ - resolved: null, + resolved: value, resolutions: null }); - }, - - sortValues: function (values) { - var order = ['', 'FIXED', 'FALSE-POSITIVE', 'WONTFIX', 'REMOVED']; - return _.sortBy(values, function (v) { - return order.indexOf(v.val); + } else { + return this.options.app.state.updateFilter({ + resolved: null, + resolutions: this.getValue() }); } - }); + }, + + disable: function () { + return this.options.app.state.updateFilter({ + resolved: null, + resolutions: null + }); + }, + sortValues: function (values) { + var order = ['', 'FIXED', 'FALSE-POSITIVE', 'WONTFIX', 'REMOVED']; + return _.sortBy(values, function (v) { + return order.indexOf(v.val); + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/issues/facets/rule-facet.js b/server/sonar-web/src/main/js/apps/issues/facets/rule-facet.js index 32e06658d3c..8d50f462c0e 100644 --- a/server/sonar-web/src/main/js/apps/issues/facets/rule-facet.js +++ b/server/sonar-web/src/main/js/apps/issues/facets/rule-facet.js @@ -1,79 +1,78 @@ -define([ - './custom-values-facet' -], function (CustomValuesFacet) { +import _ from 'underscore'; +import CustomValuesFacet from './custom-values-facet'; - return CustomValuesFacet.extend({ - prepareSearch: function () { - var url = baseUrl + '/api/rules/search?f=name,langName', - languages = this.options.app.state.get('query').languages; - if (languages != null) { - url += '&languages=' + languages; - } - return this.$('.js-custom-value').select2({ - placeholder: 'Search...', - minimumInputLength: 2, - allowClear: false, - formatNoMatches: function () { - return t('select2.noMatches'); - }, - formatSearching: function () { - return t('select2.searching'); - }, - formatInputTooShort: function () { - return tp('select2.tooShort', 2); +export default CustomValuesFacet.extend({ + prepareSearch: function () { + var url = baseUrl + '/api/rules/search?f=name,langName', + languages = this.options.app.state.get('query').languages; + if (languages != null) { + url += '&languages=' + languages; + } + return this.$('.js-custom-value').select2({ + placeholder: 'Search...', + minimumInputLength: 2, + allowClear: false, + formatNoMatches: function () { + return t('select2.noMatches'); + }, + formatSearching: function () { + return t('select2.searching'); + }, + formatInputTooShort: function () { + return tp('select2.tooShort', 2); + }, + width: '100%', + ajax: { + quietMillis: 300, + url: url, + data: function (term, page) { + return { q: term, p: page }; }, - width: '100%', - ajax: { - quietMillis: 300, - url: url, - data: function (term, page) { - return { q: term, p: page }; - }, - results: function (data) { - var results; - results = data.rules.map(function (rule) { - var lang = rule.langName || window.t('manual'); - return { - id: rule.key, - text: '(' + lang + ') ' + rule.name - }; - }); + results: function (data) { + var results; + results = data.rules.map(function (rule) { + var lang = rule.langName || window.t('manual'); return { - more: data.p * data.ps < data.total, - results: results + id: rule.key, + text: '(' + lang + ') ' + rule.name }; - } + }); + return { + more: data.p * data.ps < data.total, + results: results + }; } - }); - }, + } + }); + }, - getValuesWithLabels: function () { - var values = this.model.getValues(), - rules = this.options.app.facets.rules; - values.forEach(function (v) { - var key = v.val, - label = '', - extra = ''; - if (key) { - var rule = _.findWhere(rules, { key: key }); - if (rule != null) { - label = rule.name; - } - if (rule != null) { - extra = rule.langName; - } + getValuesWithLabels: function () { + var values = this.model.getValues(), + rules = this.options.app.facets.rules; + values.forEach(function (v) { + var key = v.val, + label = '', + extra = ''; + if (key) { + var rule = _.findWhere(rules, { key: key }); + if (rule != null) { + label = rule.name; } - v.label = label; - v.extra = extra; - }); - return values; - }, - - serializeData: function () { - return _.extend(CustomValuesFacet.prototype.serializeData.apply(this, arguments), { - values: this.sortValues(this.getValuesWithLabels()) - }); - } - }); + if (rule != null) { + extra = rule.langName; + } + } + v.label = label; + v.extra = extra; + }); + return values; + }, + serializeData: function () { + return _.extend(CustomValuesFacet.prototype.serializeData.apply(this, arguments), { + values: this.sortValues(this.getValuesWithLabels()) + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/issues/facets/severity-facet.js b/server/sonar-web/src/main/js/apps/issues/facets/severity-facet.js index eccaf546684..e1dc9abe396 100644 --- a/server/sonar-web/src/main/js/apps/issues/facets/severity-facet.js +++ b/server/sonar-web/src/main/js/apps/issues/facets/severity-facet.js @@ -1,17 +1,16 @@ -define([ - './base-facet', - '../templates' -], function (BaseFacet) { +import _ from 'underscore'; +import BaseFacet from './base-facet'; +import '../templates'; - return BaseFacet.extend({ - template: Templates['issues-severity-facet'], - - sortValues: function (values) { - var order = ['BLOCKER', 'MINOR', 'CRITICAL', 'INFO', 'MAJOR']; - return _.sortBy(values, function (v) { - return order.indexOf(v.val); - }); - } - }); +export default BaseFacet.extend({ + template: Templates['issues-severity-facet'], + sortValues: function (values) { + var order = ['BLOCKER', 'MINOR', 'CRITICAL', 'INFO', 'MAJOR']; + return _.sortBy(values, function (v) { + return order.indexOf(v.val); + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/issues/facets/status-facet.js b/server/sonar-web/src/main/js/apps/issues/facets/status-facet.js index 08db6d508f8..9293d393cf7 100644 --- a/server/sonar-web/src/main/js/apps/issues/facets/status-facet.js +++ b/server/sonar-web/src/main/js/apps/issues/facets/status-facet.js @@ -1,17 +1,16 @@ -define([ - './base-facet', - '../templates' -], function (BaseFacet) { +import _ from 'underscore'; +import BaseFacet from './base-facet'; +import '../templates'; - return BaseFacet.extend({ - template: Templates['issues-status-facet'], - - sortValues: function (values) { - var order = ['OPEN', 'RESOLVED', 'REOPENED', 'CLOSED', 'CONFIRMED']; - return _.sortBy(values, function (v) { - return order.indexOf(v.val); - }); - } - }); +export default BaseFacet.extend({ + template: Templates['issues-status-facet'], + sortValues: function (values) { + var order = ['OPEN', 'RESOLVED', 'REOPENED', 'CLOSED', 'CONFIRMED']; + return _.sortBy(values, function (v) { + return order.indexOf(v.val); + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/issues/facets/tag-facet.js b/server/sonar-web/src/main/js/apps/issues/facets/tag-facet.js index 96a0d85729e..291bcf6f393 100644 --- a/server/sonar-web/src/main/js/apps/issues/facets/tag-facet.js +++ b/server/sonar-web/src/main/js/apps/issues/facets/tag-facet.js @@ -1,55 +1,54 @@ -define([ - './custom-values-facet' -], function (CustomValuesFacet) { +import _ from 'underscore'; +import CustomValuesFacet from './custom-values-facet'; - return CustomValuesFacet.extend({ - prepareSearch: function () { - var url = baseUrl + '/api/issues/tags?ps=10', - tags = this.options.app.state.get('query').tags; - if (tags != null) { - url += '&tags=' + tags; - } - return this.$('.js-custom-value').select2({ - placeholder: 'Search...', - minimumInputLength: 0, - allowClear: false, - formatNoMatches: function () { - return t('select2.noMatches'); - }, - formatSearching: function () { - return t('select2.searching'); +export default CustomValuesFacet.extend({ + prepareSearch: function () { + var url = baseUrl + '/api/issues/tags?ps=10', + tags = this.options.app.state.get('query').tags; + if (tags != null) { + url += '&tags=' + tags; + } + return this.$('.js-custom-value').select2({ + placeholder: 'Search...', + minimumInputLength: 0, + allowClear: false, + formatNoMatches: function () { + return t('select2.noMatches'); + }, + formatSearching: function () { + return t('select2.searching'); + }, + width: '100%', + ajax: { + quietMillis: 300, + url: url, + data: function (term) { + return { q: term, ps: 10 }; }, - width: '100%', - ajax: { - quietMillis: 300, - url: url, - data: function (term) { - return { q: term, ps: 10 }; - }, - results: function (data) { - var results = data.tags.map(function (tag) { - return { id: tag, text: tag }; - }); - return { more: false, results: results }; - } + results: function (data) { + var results = data.tags.map(function (tag) { + return { id: tag, text: tag }; + }); + return { more: false, results: results }; } - }); - }, - - getValuesWithLabels: function () { - var values = this.model.getValues(); - values.forEach(function (v) { - v.label = v.val; - v.extra = ''; - }); - return values; - }, + } + }); + }, - serializeData: function () { - return _.extend(CustomValuesFacet.prototype.serializeData.apply(this, arguments), { - values: this.sortValues(this.getValuesWithLabels()) - }); - } - }); + getValuesWithLabels: function () { + var values = this.model.getValues(); + values.forEach(function (v) { + v.label = v.val; + v.extra = ''; + }); + return values; + }, + serializeData: function () { + return _.extend(CustomValuesFacet.prototype.serializeData.apply(this, arguments), { + values: this.sortValues(this.getValuesWithLabels()) + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/issues/filters-view.js b/server/sonar-web/src/main/js/apps/issues/filters-view.js index c3ea67bd434..18a46bfd096 100644 --- a/server/sonar-web/src/main/js/apps/issues/filters-view.js +++ b/server/sonar-web/src/main/js/apps/issues/filters-view.js @@ -1,92 +1,91 @@ -define([ - './templates' -], function () { +import $ from 'jquery'; +import _ from 'underscore'; +import Marionette from 'backbone.marionette'; +import './templates'; - var $ = jQuery; +export default Marionette.ItemView.extend({ + template: Templates['issues-filters'], - return Marionette.ItemView.extend({ - template: Templates['issues-filters'], + events: { + 'click .js-toggle-filters': 'toggleFilters', + 'click .js-filter': 'applyFilter', + 'click .js-filter-save-as': 'saveAs', + 'click .js-filter-save': 'save', + 'click .js-filter-copy': 'copy', + 'click .js-filter-edit': 'edit' + }, - events: { - 'click .js-toggle-filters': 'toggleFilters', - 'click .js-filter': 'applyFilter', - 'click .js-filter-save-as': 'saveAs', - 'click .js-filter-save': 'save', - 'click .js-filter-copy': 'copy', - 'click .js-filter-edit': 'edit' - }, - - initialize: function (options) { - var that = this; - this.listenTo(options.app.state, 'change:filter', this.render); - this.listenTo(options.app.state, 'change:changed', this.render); - this.listenTo(options.app.filters, 'reset', this.render); - window.onSaveAs = window.onCopy = window.onEdit = function (id) { - $('#modal').dialog('close'); - return that.options.app.controller.fetchFilters().done(function () { - var filter = that.collection.get(id); - return filter.fetch().done(function () { - return that.options.app.controller.applyFilter(filter); - }); + initialize: function (options) { + var that = this; + this.listenTo(options.app.state, 'change:filter', this.render); + this.listenTo(options.app.state, 'change:changed', this.render); + this.listenTo(options.app.filters, 'reset', this.render); + window.onSaveAs = window.onCopy = window.onEdit = function (id) { + $('#modal').dialog('close'); + return that.options.app.controller.fetchFilters().done(function () { + var filter = that.collection.get(id); + return filter.fetch().done(function () { + return that.options.app.controller.applyFilter(filter); }); - }; - }, - - onRender: function () { - this.$el.toggleClass('search-navigator-filters-selected', this.options.app.state.has('filter')); - }, - - toggleFilters: function (e) { - var that = this; - e.stopPropagation(); - this.$('.search-navigator-filters-list').toggle(); - return $('body').on('click.issues-filters', function () { - $('body').off('click.issues-filters'); - return that.$('.search-navigator-filters-list').hide(); }); - }, + }; + }, - applyFilter: function (e) { - var that = this; - var id = $(e.currentTarget).data('id'), - filter = this.collection.get(id); - return that.options.app.controller.applyFilter(filter); + onRender: function () { + this.$el.toggleClass('search-navigator-filters-selected', this.options.app.state.has('filter')); + }, - }, + toggleFilters: function (e) { + var that = this; + e.stopPropagation(); + this.$('.search-navigator-filters-list').toggle(); + return $('body').on('click.issues-filters', function () { + $('body').off('click.issues-filters'); + return that.$('.search-navigator-filters-list').hide(); + }); + }, - saveAs: function () { - var query = this.options.app.controller.getQuery('&'), - url = baseUrl + '/issues/save_as_form?' + query; - window.openModalWindow(url, {}); - }, + applyFilter: function (e) { + var that = this; + var id = $(e.currentTarget).data('id'), + filter = this.collection.get(id); + return that.options.app.controller.applyFilter(filter); - save: function () { - var that = this; - var query = this.options.app.controller.getQuery('&'), - url = baseUrl + '/issues/save/' + (this.options.app.state.get('filter').id) + '?' + query; - return $.post(url).done(function () { - return that.options.app.state.set({ changed: false }); - }); - }, + }, - copy: function () { - var url = baseUrl + '/issues/copy_form/' + (this.options.app.state.get('filter').id); - window.openModalWindow(url, {}); - }, + saveAs: function () { + var query = this.options.app.controller.getQuery('&'), + url = baseUrl + '/issues/save_as_form?' + query; + window.openModalWindow(url, {}); + }, - edit: function () { - var url = baseUrl + '/issues/edit_form/' + (this.options.app.state.get('filter').id); - window.openModalWindow(url, {}); - }, + save: function () { + var that = this; + var query = this.options.app.controller.getQuery('&'), + url = baseUrl + '/issues/save/' + (this.options.app.state.get('filter').id) + '?' + query; + return $.post(url).done(function () { + return that.options.app.state.set({ changed: false }); + }); + }, - serializeData: function () { - var filter = this.options.app.state.get('filter'); - return _.extend(Marionette.ItemView.prototype.serializeData.apply(this, arguments), { - state: this.options.app.state.toJSON(), - filter: filter != null ? filter.toJSON() : null, - currentUser: window.SS.user - }); - } - }); + copy: function () { + var url = baseUrl + '/issues/copy_form/' + (this.options.app.state.get('filter').id); + window.openModalWindow(url, {}); + }, + + edit: function () { + var url = baseUrl + '/issues/edit_form/' + (this.options.app.state.get('filter').id); + window.openModalWindow(url, {}); + }, + serializeData: function () { + var filter = this.options.app.state.get('filter'); + return _.extend(Marionette.ItemView.prototype.serializeData.apply(this, arguments), { + state: this.options.app.state.toJSON(), + filter: filter != null ? filter.toJSON() : null, + currentUser: window.SS.user + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/issues/helpers/format-facet-value.js b/server/sonar-web/src/main/js/apps/issues/helpers/format-facet-value.js index b89d39ccef2..5cef0500ded 100644 --- a/server/sonar-web/src/main/js/apps/issues/helpers/format-facet-value.js +++ b/server/sonar-web/src/main/js/apps/issues/helpers/format-facet-value.js @@ -1,8 +1,6 @@ -define(function () { +Handlebars.registerHelper('formatFacetValue', function (value, facetMode) { + var formatter = facetMode === 'debt' ? 'SHORT_WORK_DUR' : 'SHORT_INT'; + return window.formatMeasure(value, formatter); +}); - Handlebars.registerHelper('formatFacetValue', function (value, facetMode) { - var formatter = facetMode === 'debt' ? 'SHORT_WORK_DUR' : 'SHORT_INT'; - return window.formatMeasure(value, formatter); - }); -}); diff --git a/server/sonar-web/src/main/js/apps/issues/issue-filter-view.js b/server/sonar-web/src/main/js/apps/issues/issue-filter-view.js index 28a6a86e212..980a0eceded 100644 --- a/server/sonar-web/src/main/js/apps/issues/issue-filter-view.js +++ b/server/sonar-web/src/main/js/apps/issues/issue-filter-view.js @@ -1,25 +1,23 @@ -define([ - 'components/common/action-options-view', - './templates' -], function (ActionOptionsView) { +import $ from 'jquery'; +import _ from 'underscore'; +import ActionOptionsView from 'components/common/action-options-view'; +import './templates'; - var $ = jQuery; +export default ActionOptionsView.extend({ + template: Templates['issues-issue-filter-form'], - return ActionOptionsView.extend({ - template: Templates['issues-issue-filter-form'], + selectOption: function (e) { + var property = $(e.currentTarget).data('property'), + value = $(e.currentTarget).data('value'); + this.trigger('select', property, value); + this._super(e); + }, - selectOption: function (e) { - var property = $(e.currentTarget).data('property'), - value = $(e.currentTarget).data('value'); - this.trigger('select', property, value); - this._super(e); - }, + serializeData: function () { + return _.extend(this._super(), { + s: this.model.get('severity') + }); + } +}); - serializeData: function () { - return _.extend(this._super(), { - s: this.model.get('severity') - }); - } - }); -}); diff --git a/server/sonar-web/src/main/js/apps/issues/layout.js b/server/sonar-web/src/main/js/apps/issues/layout.js index 5dbbcaf1139..7b6c7b8366e 100644 --- a/server/sonar-web/src/main/js/apps/issues/layout.js +++ b/server/sonar-web/src/main/js/apps/issues/layout.js @@ -1,55 +1,55 @@ -define([ - './templates' -], function () { - - var $ = jQuery; - return Marionette.LayoutView.extend({ - template: Templates['issues-layout'], - - regions: { - filtersRegion: '.search-navigator-filters', - facetsRegion: '.search-navigator-facets', - workspaceHeaderRegion: '.search-navigator-workspace-header', - workspaceListRegion: '.search-navigator-workspace-list', - workspaceComponentViewerRegion: '.issues-workspace-component-viewer', - workspaceHomeRegion: '.issues-workspace-home' - }, - - onRender: function () { - if (this.options.app.state.get('isContext')) { - this.$(this.filtersRegion.el).addClass('hidden'); - } - this.$('.search-navigator').addClass('sticky'); - var top = this.$('.search-navigator').offset().top; - this.$('.search-navigator-workspace-header').css({ top: top }); - this.$('.search-navigator-side').css({ top: top }).isolatedScroll(); - }, - - showSpinner: function (region) { - return this[region].show(new Marionette.ItemView({ - template: _.template('') - })); - }, - - showComponentViewer: function () { - this.scroll = $(window).scrollTop(); - this.$('.issues').addClass('issues-extended-view'); - }, - - hideComponentViewer: function () { - this.$('.issues').removeClass('issues-extended-view'); - if (this.scroll != null) { - $(window).scrollTop(this.scroll); - } - }, - - showHomePage: function () { - this.$('.issues').addClass('issues-home-view'); - }, - - hideHomePage: function () { - this.$('.issues').removeClass('issues-home-view'); +import $ from 'jquery'; +import _ from 'underscore'; +import Marionette from 'backbone.marionette'; +import './templates'; + +export default Marionette.LayoutView.extend({ + template: Templates['issues-layout'], + + regions: { + filtersRegion: '.search-navigator-filters', + facetsRegion: '.search-navigator-facets', + workspaceHeaderRegion: '.search-navigator-workspace-header', + workspaceListRegion: '.search-navigator-workspace-list', + workspaceComponentViewerRegion: '.issues-workspace-component-viewer', + workspaceHomeRegion: '.issues-workspace-home' + }, + + onRender: function () { + if (this.options.app.state.get('isContext')) { + this.$(this.filtersRegion.el).addClass('hidden'); } - }); + this.$('.search-navigator').addClass('sticky'); + var top = this.$('.search-navigator').offset().top; + this.$('.search-navigator-workspace-header').css({ top: top }); + this.$('.search-navigator-side').css({ top: top }).isolatedScroll(); + }, + + showSpinner: function (region) { + return this[region].show(new Marionette.ItemView({ + template: _.template('') + })); + }, + + showComponentViewer: function () { + this.scroll = $(window).scrollTop(); + this.$('.issues').addClass('issues-extended-view'); + }, + + hideComponentViewer: function () { + this.$('.issues').removeClass('issues-extended-view'); + if (this.scroll != null) { + $(window).scrollTop(this.scroll); + } + }, + + showHomePage: function () { + this.$('.issues').addClass('issues-home-view'); + }, + hideHomePage: function () { + this.$('.issues').removeClass('issues-home-view'); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/issues/models/filter.js b/server/sonar-web/src/main/js/apps/issues/models/filter.js index aa31f8ab267..14f9746938d 100644 --- a/server/sonar-web/src/main/js/apps/issues/models/filter.js +++ b/server/sonar-web/src/main/js/apps/issues/models/filter.js @@ -1,17 +1,17 @@ -define(function () { +import Backbone from 'backbone'; - return Backbone.Model.extend({ - url: function () { - return baseUrl + '/api/issue_filters/show/' + this.id; - }, +export default Backbone.Model.extend({ + url: function () { + return baseUrl + '/api/issue_filters/show/' + this.id; + }, - parse: function (r) { - if (r.filter != null) { - return r.filter; - } else { - return r; - } + parse: function (r) { + if (r.filter != null) { + return r.filter; + } else { + return r; } - }); - + } }); + + diff --git a/server/sonar-web/src/main/js/apps/issues/models/filters.js b/server/sonar-web/src/main/js/apps/issues/models/filters.js index 34a46690bfe..e24ef5c146e 100644 --- a/server/sonar-web/src/main/js/apps/issues/models/filters.js +++ b/server/sonar-web/src/main/js/apps/issues/models/filters.js @@ -1,17 +1,16 @@ -define([ - './filter' -], function (Filter) { +import Backbone from 'backbone'; +import Filter from './filter'; - return Backbone.Collection.extend({ - model: Filter, +export default Backbone.Collection.extend({ + model: Filter, - url: function () { - return window.baseUrl + '/api/issue_filters/search'; - }, - - parse: function (r) { - return r.issueFilters; - } - }); + url: function () { + return window.baseUrl + '/api/issue_filters/search'; + }, + parse: function (r) { + return r.issueFilters; + } }); + + diff --git a/server/sonar-web/src/main/js/apps/issues/models/issue.js b/server/sonar-web/src/main/js/apps/issues/models/issue.js index 6266434fa23..f466243ad63 100644 --- a/server/sonar-web/src/main/js/apps/issues/models/issue.js +++ b/server/sonar-web/src/main/js/apps/issues/models/issue.js @@ -1,15 +1,13 @@ -define([ - 'components/issue/models/issue' -], function (Issue) { - - return Issue.extend({ - reset: function (attrs, options) { - var keepFields = ['index', 'selected', 'comments']; - keepFields.forEach(function (field) { - attrs[field] = this.get(field); - }.bind(this)); - return this._super(attrs, options); - } - }); +import Issue from 'components/issue/models/issue'; +export default Issue.extend({ + reset: function (attrs, options) { + var keepFields = ['index', 'selected', 'comments']; + keepFields.forEach(function (field) { + attrs[field] = this.get(field); + }.bind(this)); + return this._super(attrs, options); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/issues/models/issues.js b/server/sonar-web/src/main/js/apps/issues/models/issues.js index 2b57399a5b5..0ec79f448dc 100644 --- a/server/sonar-web/src/main/js/apps/issues/models/issues.js +++ b/server/sonar-web/src/main/js/apps/issues/models/issues.js @@ -1,84 +1,84 @@ -define([ - './issue' -], function (Issue) { +import _ from 'underscore'; +import Backbone from 'backbone'; +import Issue from './issue'; - return Backbone.Collection.extend({ - model: Issue, +export default Backbone.Collection.extend({ + model: Issue, - url: function () { - return baseUrl + '/api/issues/search'; - }, + url: function () { + return baseUrl + '/api/issues/search'; + }, - _injectRelational: function (issue, source, baseField, lookupField) { - var baseValue = issue[baseField]; - if (baseValue != null && _.size(source)) { - var lookupValue = _.find(source, function (candidate) { - return candidate[lookupField] === baseValue; - }); - if (lookupValue != null) { - Object.keys(lookupValue).forEach(function (key) { - var newKey = baseField + key.charAt(0).toUpperCase() + key.slice(1); - issue[newKey] = lookupValue[key]; - }); - } - } - return issue; - }, - - _injectCommentsRelational: function (issue, users) { - if (issue.comments) { - var that = this; - var newComments = issue.comments.map(function (comment) { - var newComment = _.extend({}, comment, { author: comment.login }); - delete newComment.login; - newComment = that._injectRelational(newComment, users, 'author', 'login'); - return newComment; + _injectRelational: function (issue, source, baseField, lookupField) { + var baseValue = issue[baseField]; + if (baseValue != null && _.size(source)) { + var lookupValue = _.find(source, function (candidate) { + return candidate[lookupField] === baseValue; + }); + if (lookupValue != null) { + Object.keys(lookupValue).forEach(function (key) { + var newKey = baseField + key.charAt(0).toUpperCase() + key.slice(1); + issue[newKey] = lookupValue[key]; }); - issue = _.extend({}, issue, { comments: newComments }); } - return issue; - }, - - _prepareClosed: function (issue) { - if (issue.status === 'CLOSED') { - issue.flows = []; - delete issue.textRange; - } - return issue; - }, + } + return issue; + }, - parseIssues: function (r) { + _injectCommentsRelational: function (issue, users) { + if (issue.comments) { var that = this; - return r.issues.map(function (issue, index) { - _.extend(issue, { index: index }); - issue = that._injectRelational(issue, r.components, 'component', 'key'); - issue = that._injectRelational(issue, r.components, 'project', 'key'); - issue = that._injectRelational(issue, r.components, 'subProject', 'key'); - issue = that._injectRelational(issue, r.rules, 'rule', 'key'); - issue = that._injectRelational(issue, r.users, 'assignee', 'login'); - issue = that._injectRelational(issue, r.users, 'reporter', 'login'); - issue = that._injectRelational(issue, r.actionPlans, 'actionPlan', 'key'); - issue = that._injectCommentsRelational(issue, r.users); - issue = that._prepareClosed(issue); - return issue; + var newComments = issue.comments.map(function (comment) { + var newComment = _.extend({}, comment, { author: comment.login }); + delete newComment.login; + newComment = that._injectRelational(newComment, users, 'author', 'login'); + return newComment; }); - }, - - setIndex: function () { - return this.forEach(function (issue, index) { - return issue.set({ index: index }); - }); - }, + issue = _.extend({}, issue, { comments: newComments }); + } + return issue; + }, - selectByKeys: function (keys) { - var that = this; - keys.forEach(function (key) { - var issue = that.get(key); - if (issue) { - issue.set({ selected: true }); - } - }); + _prepareClosed: function (issue) { + if (issue.status === 'CLOSED') { + issue.flows = []; + delete issue.textRange; } - }); + return issue; + }, + + parseIssues: function (r) { + var that = this; + return r.issues.map(function (issue, index) { + _.extend(issue, { index: index }); + issue = that._injectRelational(issue, r.components, 'component', 'key'); + issue = that._injectRelational(issue, r.components, 'project', 'key'); + issue = that._injectRelational(issue, r.components, 'subProject', 'key'); + issue = that._injectRelational(issue, r.rules, 'rule', 'key'); + issue = that._injectRelational(issue, r.users, 'assignee', 'login'); + issue = that._injectRelational(issue, r.users, 'reporter', 'login'); + issue = that._injectRelational(issue, r.actionPlans, 'actionPlan', 'key'); + issue = that._injectCommentsRelational(issue, r.users); + issue = that._prepareClosed(issue); + return issue; + }); + }, + + setIndex: function () { + return this.forEach(function (issue, index) { + return issue.set({ index: index }); + }); + }, + selectByKeys: function (keys) { + var that = this; + keys.forEach(function (key) { + var issue = that.get(key); + if (issue) { + issue.set({ selected: true }); + } + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/issues/models/state.js b/server/sonar-web/src/main/js/apps/issues/models/state.js index 246d27c24ca..f49d2566dfc 100644 --- a/server/sonar-web/src/main/js/apps/issues/models/state.js +++ b/server/sonar-web/src/main/js/apps/issues/models/state.js @@ -1,68 +1,67 @@ -define([ - 'components/navigator/models/state' -], function (State) { +import _ from 'underscore'; +import State from 'components/navigator/models/state'; - return State.extend({ - defaults: { - page: 1, - maxResultsReached: false, - query: {}, - facets: ['facetMode', 'severities', 'resolutions'], - isContext: false, - allFacets: [ - 'facetMode', - 'issues', - 'severities', - 'resolutions', - 'statuses', - 'createdAt', - 'rules', - 'tags', - 'projectUuids', - 'moduleUuids', - 'directories', - 'fileUuids', - 'assignees', - 'reporters', - 'authors', - 'languages', - 'actionPlans' - ], - facetsFromServer: [ - 'severities', - 'statuses', - 'resolutions', - 'actionPlans', - 'projectUuids', - 'directories', - 'rules', - 'moduleUuids', - 'tags', - 'assignees', - 'reporters', - 'authors', - 'fileUuids', - 'languages', - 'createdAt' - ], - transform: { - 'resolved': 'resolutions', - 'assigned': 'assignees', - 'planned': 'actionPlans', - 'createdBefore': 'createdAt', - 'createdAfter': 'createdAt', - 'createdInLast': 'createdAt' - } - }, - - getFacetMode: function () { - var query = this.get('query'); - return query.facetMode || 'count'; - }, - - toJSON: function () { - return _.extend({ facetMode: this.getFacetMode() }, this.attributes); +export default State.extend({ + defaults: { + page: 1, + maxResultsReached: false, + query: {}, + facets: ['facetMode', 'severities', 'resolutions'], + isContext: false, + allFacets: [ + 'facetMode', + 'issues', + 'severities', + 'resolutions', + 'statuses', + 'createdAt', + 'rules', + 'tags', + 'projectUuids', + 'moduleUuids', + 'directories', + 'fileUuids', + 'assignees', + 'reporters', + 'authors', + 'languages', + 'actionPlans' + ], + facetsFromServer: [ + 'severities', + 'statuses', + 'resolutions', + 'actionPlans', + 'projectUuids', + 'directories', + 'rules', + 'moduleUuids', + 'tags', + 'assignees', + 'reporters', + 'authors', + 'fileUuids', + 'languages', + 'createdAt' + ], + transform: { + 'resolved': 'resolutions', + 'assigned': 'assignees', + 'planned': 'actionPlans', + 'createdBefore': 'createdAt', + 'createdAfter': 'createdAt', + 'createdInLast': 'createdAt' } - }); + }, + + getFacetMode: function () { + var query = this.get('query'); + return query.facetMode || 'count'; + }, + toJSON: function () { + return _.extend({ facetMode: this.getFacetMode() }, this.attributes); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/issues/router.js b/server/sonar-web/src/main/js/apps/issues/router.js index 519689e8f40..6cb6622da6e 100644 --- a/server/sonar-web/src/main/js/apps/issues/router.js +++ b/server/sonar-web/src/main/js/apps/issues/router.js @@ -1,45 +1,43 @@ -define([ - 'components/navigator/router' -], function (Router) { +import Router from 'components/navigator/router'; - return Router.extend({ - routes: { - '': 'home', - ':query': 'index' - }, +export default Router.extend({ + routes: { + '': 'home', + ':query': 'index' + }, - initialize: function (options) { - Router.prototype.initialize.apply(this, arguments); - this.listenTo(options.app.state, 'change:filter', this.updateRoute); - }, + initialize: function (options) { + Router.prototype.initialize.apply(this, arguments); + this.listenTo(options.app.state, 'change:filter', this.updateRoute); + }, - home: function () { - if (this.options.app.state.get('isContext')) { - return this.navigate('resolved=false', { trigger: true, replace: true }); - } else { - return this.options.app.controller.showHomePage(); - } - }, - - index: function (query) { - var that = this; - query = this.options.app.controller.parseQuery(query); - if (query.id != null) { - var filter = this.options.app.filters.get(query.id); - delete query.id; - return filter.fetch().done(function () { - if (Object.keys(query).length > 0) { - that.options.app.controller.applyFilter(filter, true); - that.options.app.state.setQuery(query); - that.options.app.state.set({ changed: true }); - } else { - that.options.app.controller.applyFilter(filter); - } - }); - } else { - return this.options.app.state.setQuery(query); - } + home: function () { + if (this.options.app.state.get('isContext')) { + return this.navigate('resolved=false', { trigger: true, replace: true }); + } else { + return this.options.app.controller.showHomePage(); } - }); + }, + index: function (query) { + var that = this; + query = this.options.app.controller.parseQuery(query); + if (query.id != null) { + var filter = this.options.app.filters.get(query.id); + delete query.id; + return filter.fetch().done(function () { + if (Object.keys(query).length > 0) { + that.options.app.controller.applyFilter(filter, true); + that.options.app.state.setQuery(query); + that.options.app.state.set({ changed: true }); + } else { + that.options.app.controller.applyFilter(filter); + } + }); + } else { + return this.options.app.state.setQuery(query); + } + } }); + + diff --git a/server/sonar-web/src/main/js/apps/issues/workspace-header-view.js b/server/sonar-web/src/main/js/apps/issues/workspace-header-view.js index 928b4b42c5f..dba0e384c5a 100644 --- a/server/sonar-web/src/main/js/apps/issues/workspace-header-view.js +++ b/server/sonar-web/src/main/js/apps/issues/workspace-header-view.js @@ -1,116 +1,114 @@ -define([ - 'components/navigator/workspace-header-view', - './templates' -], function (WorkspaceHeaderView) { - - var $ = jQuery; - - return WorkspaceHeaderView.extend({ - template: Templates['issues-workspace-header'], - - events: function () { - return _.extend(WorkspaceHeaderView.prototype.events.apply(this, arguments), { - 'click .js-selection': 'onSelectionClick', - 'click .js-back': 'returnToList', - 'click .js-new-search': 'newSearch', - 'click .js-bulk-change-selected': 'onBulkChangeSelectedClick' - }); - }, - - initialize: function () { - WorkspaceHeaderView.prototype.initialize.apply(this, arguments); - this._onBulkIssues = window.onBulkIssues; - window.onBulkIssues = _.bind(this.afterBulkChange, this); - }, - - onDestroy: function () { +import $ from 'jquery'; +import _ from 'underscore'; +import WorkspaceHeaderView from 'components/navigator/workspace-header-view'; +import './templates'; + +export default WorkspaceHeaderView.extend({ + template: Templates['issues-workspace-header'], + + events: function () { + return _.extend(WorkspaceHeaderView.prototype.events.apply(this, arguments), { + 'click .js-selection': 'onSelectionClick', + 'click .js-back': 'returnToList', + 'click .js-new-search': 'newSearch', + 'click .js-bulk-change-selected': 'onBulkChangeSelectedClick' + }); + }, + + initialize: function () { + WorkspaceHeaderView.prototype.initialize.apply(this, arguments); + this._onBulkIssues = window.onBulkIssues; + window.onBulkIssues = _.bind(this.afterBulkChange, this); + }, + + onDestroy: function () { + this._super(); + window.onBulkIssues = this._onBulkIssues; + }, + + onSelectionClick: function (e) { + e.preventDefault(); + this.toggleSelection(); + }, + + onBulkChangeSelectedClick: function (e) { + e.preventDefault(); + this.bulkChangeSelected(); + }, + + afterBulkChange: function () { + var that = this; + $('#modal').dialog('close'); + var selectedIndex = this.options.app.state.get('selectedIndex'); + var selectedKeys = _.pluck(this.options.app.list.where({ selected: true }), 'id'); + this.options.app.controller.fetchList().done(function () { + that.options.app.state.set({ selectedIndex: selectedIndex }); + that.options.app.list.selectByKeys(selectedKeys); + }); + }, + + render: function () { + if (!this._suppressUpdate) { this._super(); - window.onBulkIssues = this._onBulkIssues; - }, - - onSelectionClick: function (e) { - e.preventDefault(); - this.toggleSelection(); - }, - - onBulkChangeSelectedClick: function (e) { - e.preventDefault(); - this.bulkChangeSelected(); - }, - - afterBulkChange: function () { - var that = this; - $('#modal').dialog('close'); - var selectedIndex = this.options.app.state.get('selectedIndex'); - var selectedKeys = _.pluck(this.options.app.list.where({ selected: true }), 'id'); - this.options.app.controller.fetchList().done(function () { - that.options.app.state.set({ selectedIndex: selectedIndex }); - that.options.app.list.selectByKeys(selectedKeys); - }); - }, - - render: function () { - if (!this._suppressUpdate) { - this._super(); - } - }, - - toggleSelection: function () { - this._suppressUpdate = true; - var selectedCount = this.options.app.list.where({ selected: true }).length, - someSelected = selectedCount > 0; - return someSelected ? this.selectNone() : this.selectAll(); - }, - - selectNone: function () { - this.options.app.list.where({ selected: true }).forEach(function (issue) { - issue.set({ selected: false }); - }); - this._suppressUpdate = false; - this.render(); - }, - - selectAll: function () { - this.options.app.list.forEach(function (issue) { - issue.set({ selected: true }); - }); - this._suppressUpdate = false; - this.render(); - }, - - returnToList: function () { - this.options.app.controller.closeComponentViewer(); - }, - - newSearch: function () { - this.options.app.controller.newSearch(); - }, - - bulkChange: function () { - var query = this.options.app.controller.getQuery('&', true), - url = baseUrl + '/issues/bulk_change_form?' + query; - window.openModalWindow(url, {}); - }, - - bulkChangeSelected: function () { - var selected = this.options.app.list.where({ selected: true }), - selectedKeys = _.first(_.pluck(selected, 'id'), 200), - query = 'issues=' + selectedKeys.join(), - url = baseUrl + '/issues/bulk_change_form?' + query; - window.openModalWindow(url, {}); - }, - - serializeData: function () { - var issuesCount = this.options.app.list.length, - selectedCount = this.options.app.list.where({ selected: true }).length, - allSelected = issuesCount > 0 && issuesCount === selectedCount, - someSelected = !allSelected && selectedCount > 0; - return _.extend(this._super(), { - selectedCount: selectedCount, - allSelected: allSelected, - someSelected: someSelected - }); } - }); - + }, + + toggleSelection: function () { + this._suppressUpdate = true; + var selectedCount = this.options.app.list.where({ selected: true }).length, + someSelected = selectedCount > 0; + return someSelected ? this.selectNone() : this.selectAll(); + }, + + selectNone: function () { + this.options.app.list.where({ selected: true }).forEach(function (issue) { + issue.set({ selected: false }); + }); + this._suppressUpdate = false; + this.render(); + }, + + selectAll: function () { + this.options.app.list.forEach(function (issue) { + issue.set({ selected: true }); + }); + this._suppressUpdate = false; + this.render(); + }, + + returnToList: function () { + this.options.app.controller.closeComponentViewer(); + }, + + newSearch: function () { + this.options.app.controller.newSearch(); + }, + + bulkChange: function () { + var query = this.options.app.controller.getQuery('&', true), + url = baseUrl + '/issues/bulk_change_form?' + query; + window.openModalWindow(url, {}); + }, + + bulkChangeSelected: function () { + var selected = this.options.app.list.where({ selected: true }), + selectedKeys = _.first(_.pluck(selected, 'id'), 200), + query = 'issues=' + selectedKeys.join(), + url = baseUrl + '/issues/bulk_change_form?' + query; + window.openModalWindow(url, {}); + }, + + serializeData: function () { + var issuesCount = this.options.app.list.length, + selectedCount = this.options.app.list.where({ selected: true }).length, + allSelected = issuesCount > 0 && issuesCount === selectedCount, + someSelected = !allSelected && selectedCount > 0; + return _.extend(this._super(), { + selectedCount: selectedCount, + allSelected: allSelected, + someSelected: someSelected + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/issues/workspace-home-view.js b/server/sonar-web/src/main/js/apps/issues/workspace-home-view.js index aff1c52366f..44efc574890 100644 --- a/server/sonar-web/src/main/js/apps/issues/workspace-home-view.js +++ b/server/sonar-web/src/main/js/apps/issues/workspace-home-view.js @@ -1,13 +1,12 @@ -define([ - './templates' -], function () { +import Marionette from 'backbone.marionette'; +import './templates'; - Handlebars.registerHelper('issueFilterHomeLink', function (id) { - return baseUrl + '/issues/search#id=' + id; - }); - - return Marionette.ItemView.extend({ - template: Templates['issues-workspace-home'] - }); +Handlebars.registerHelper('issueFilterHomeLink', function (id) { + return baseUrl + '/issues/search#id=' + id; +}); +export default Marionette.ItemView.extend({ + template: Templates['issues-workspace-home'] }); + + diff --git a/server/sonar-web/src/main/js/apps/issues/workspace-list-empty-view.js b/server/sonar-web/src/main/js/apps/issues/workspace-list-empty-view.js index ada57f15a2d..b40c68d0ab6 100644 --- a/server/sonar-web/src/main/js/apps/issues/workspace-list-empty-view.js +++ b/server/sonar-web/src/main/js/apps/issues/workspace-list-empty-view.js @@ -1,11 +1,11 @@ -define(function () { +import Marionette from 'backbone.marionette'; - return Marionette.ItemView.extend({ - className: 'search-navigator-no-results', - - template: function () { - return t('issue_filter.no_issues'); - } - }); +export default Marionette.ItemView.extend({ + className: 'search-navigator-no-results', + template: function () { + return t('issue_filter.no_issues'); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/issues/workspace-list-item-view.js b/server/sonar-web/src/main/js/apps/issues/workspace-list-item-view.js index 28a6eb7e433..585beb1afce 100644 --- a/server/sonar-web/src/main/js/apps/issues/workspace-list-item-view.js +++ b/server/sonar-web/src/main/js/apps/issues/workspace-list-item-view.js @@ -1,135 +1,134 @@ -define([ - 'components/issue/issue-view', - './issue-filter-view', - './templates' -], function (IssueView, IssueFilterView) { - - var $ = jQuery, - SHOULD_NULL = { - any: ['issues'], - resolutions: ['resolved'], - resolved: ['resolutions'], - assignees: ['assigned'], - assigned: ['assignees'], - actionPlans: ['planned'], - planned: ['actionPlans'] - }; - - return IssueView.extend({ - checkboxTemplate: Templates['issues-issue-checkbox'], - filterTemplate: Templates['issues-issue-filter'], - - events: function () { - return _.extend(IssueView.prototype.events.apply(this, arguments), { - 'click': 'selectCurrent', - 'dblclick': 'openComponentViewer', - 'click .js-issue-navigate': 'openComponentViewer', - 'click .js-issue-filter': 'onIssueFilterClick', - 'click .js-toggle': 'onIssueToggle' - }); - }, - - initialize: function (options) { - IssueView.prototype.initialize.apply(this, arguments); - this.listenTo(options.app.state, 'change:selectedIndex', this.select); - }, - - onRender: function () { - IssueView.prototype.onRender.apply(this, arguments); - this.select(); - this.addFilterSelect(); - this.addCheckbox(); - this.$el.addClass('issue-navigate-right'); - if (this.options.app.state.get('canBulkChange')) { - this.$el.addClass('issue-with-checkbox'); - } - }, - - onIssueFilterClick: function (e) { - var that = this; - e.preventDefault(); - e.stopPropagation(); - $('body').click(); - this.popup = new IssueFilterView({ - triggerEl: $(e.currentTarget), - bottomRight: true, - model: this.model +import $ from 'jquery'; +import _ from 'underscore'; +import IssueView from 'components/issue/issue-view'; +import IssueFilterView from './issue-filter-view'; +import './templates'; + +var SHOULD_NULL = { + any: ['issues'], + resolutions: ['resolved'], + resolved: ['resolutions'], + assignees: ['assigned'], + assigned: ['assignees'], + actionPlans: ['planned'], + planned: ['actionPlans'] + }; + +export default IssueView.extend({ + checkboxTemplate: Templates['issues-issue-checkbox'], + filterTemplate: Templates['issues-issue-filter'], + + events: function () { + return _.extend(IssueView.prototype.events.apply(this, arguments), { + 'click': 'selectCurrent', + 'dblclick': 'openComponentViewer', + 'click .js-issue-navigate': 'openComponentViewer', + 'click .js-issue-filter': 'onIssueFilterClick', + 'click .js-toggle': 'onIssueToggle' + }); + }, + + initialize: function (options) { + IssueView.prototype.initialize.apply(this, arguments); + this.listenTo(options.app.state, 'change:selectedIndex', this.select); + }, + + onRender: function () { + IssueView.prototype.onRender.apply(this, arguments); + this.select(); + this.addFilterSelect(); + this.addCheckbox(); + this.$el.addClass('issue-navigate-right'); + if (this.options.app.state.get('canBulkChange')) { + this.$el.addClass('issue-with-checkbox'); + } + }, + + onIssueFilterClick: function (e) { + var that = this; + e.preventDefault(); + e.stopPropagation(); + $('body').click(); + this.popup = new IssueFilterView({ + triggerEl: $(e.currentTarget), + bottomRight: true, + model: this.model + }); + this.popup.on('select', function (property, value) { + var obj; + obj = {}; + obj[property] = '' + value; + SHOULD_NULL.any.forEach(function (p) { + obj[p] = null; }); - this.popup.on('select', function (property, value) { - var obj; - obj = {}; - obj[property] = '' + value; - SHOULD_NULL.any.forEach(function (p) { + if (SHOULD_NULL[property] != null) { + SHOULD_NULL[property].forEach(function (p) { obj[p] = null; }); - if (SHOULD_NULL[property] != null) { - SHOULD_NULL[property].forEach(function (p) { - obj[p] = null; - }); - } - that.options.app.state.updateFilter(obj); - that.popup.destroy(); - }); - this.popup.render(); - }, - - onIssueToggle: function (e) { - e.preventDefault(); - this.model.set({ selected: !this.model.get('selected') }); - var selected = this.model.collection.where({ selected: true }).length; - this.options.app.state.set({ selected: selected }); - }, - - addFilterSelect: function () { - this.$('.issue-table-meta-cell-first') - .find('.issue-meta-list') - .append(this.filterTemplate(this.model.toJSON())); - }, - - addCheckbox: function () { - this.$el.append(this.checkboxTemplate(this.model.toJSON())); - }, - - select: function () { - var selected = this.model.get('index') === this.options.app.state.get('selectedIndex'); - this.$el.toggleClass('selected', selected); - }, - - selectCurrent: function () { - this.options.app.state.set({ selectedIndex: this.model.get('index') }); - }, - - resetIssue: function (options) { - var that = this; - var key = this.model.get('key'), - componentUuid = this.model.get('componentUuid'), - index = this.model.get('index'), - selected = this.model.get('selected'); - this.model.reset({ - key: key, - componentUuid: componentUuid, - index: index, - selected: selected - }, { silent: true }); - return this.model.fetch(options).done(function () { - return that.trigger('reset'); - }); - }, - - openComponentViewer: function () { - this.options.app.state.set({ selectedIndex: this.model.get('index') }); - if (this.options.app.state.has('component')) { - return this.options.app.controller.closeComponentViewer(); - } else { - return this.options.app.controller.showComponentViewer(this.model); } - }, + that.options.app.state.updateFilter(obj); + that.popup.destroy(); + }); + this.popup.render(); + }, - serializeData: function () { - return _.extend(IssueView.prototype.serializeData.apply(this, arguments), { - showComponent: true - }); + onIssueToggle: function (e) { + e.preventDefault(); + this.model.set({ selected: !this.model.get('selected') }); + var selected = this.model.collection.where({ selected: true }).length; + this.options.app.state.set({ selected: selected }); + }, + + addFilterSelect: function () { + this.$('.issue-table-meta-cell-first') + .find('.issue-meta-list') + .append(this.filterTemplate(this.model.toJSON())); + }, + + addCheckbox: function () { + this.$el.append(this.checkboxTemplate(this.model.toJSON())); + }, + + select: function () { + var selected = this.model.get('index') === this.options.app.state.get('selectedIndex'); + this.$el.toggleClass('selected', selected); + }, + + selectCurrent: function () { + this.options.app.state.set({ selectedIndex: this.model.get('index') }); + }, + + resetIssue: function (options) { + var that = this; + var key = this.model.get('key'), + componentUuid = this.model.get('componentUuid'), + index = this.model.get('index'), + selected = this.model.get('selected'); + this.model.reset({ + key: key, + componentUuid: componentUuid, + index: index, + selected: selected + }, { silent: true }); + return this.model.fetch(options).done(function () { + return that.trigger('reset'); + }); + }, + + openComponentViewer: function () { + this.options.app.state.set({ selectedIndex: this.model.get('index') }); + if (this.options.app.state.has('component')) { + return this.options.app.controller.closeComponentViewer(); + } else { + return this.options.app.controller.showComponentViewer(this.model); } - }); + }, + serializeData: function () { + return _.extend(IssueView.prototype.serializeData.apply(this, arguments), { + showComponent: true + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/issues/workspace-list-view.js b/server/sonar-web/src/main/js/apps/issues/workspace-list-view.js index 30a192d0b01..3a4d2be2599 100644 --- a/server/sonar-web/src/main/js/apps/issues/workspace-list-view.js +++ b/server/sonar-web/src/main/js/apps/issues/workspace-list-view.js @@ -1,111 +1,109 @@ -define([ - 'components/navigator/workspace-list-view', - './workspace-list-item-view', - './workspace-list-empty-view', - './templates' -], function (WorkspaceListView, IssueView, EmptyView) { +import $ from 'jquery'; +import WorkspaceListView from 'components/navigator/workspace-list-view'; +import IssueView from './workspace-list-item-view'; +import EmptyView from './workspace-list-empty-view'; +import './templates'; - var $ = jQuery, - COMPONENT_HEIGHT = 29, - BOTTOM_OFFSET = 10; +var COMPONENT_HEIGHT = 29, + BOTTOM_OFFSET = 10; - return WorkspaceListView.extend({ - template: Templates['issues-workspace-list'], - componentTemplate: Templates['issues-workspace-list-component'], - childView: IssueView, - childViewContainer: '.js-list', - emptyView: EmptyView, +export default WorkspaceListView.extend({ + template: Templates['issues-workspace-list'], + componentTemplate: Templates['issues-workspace-list-component'], + childView: IssueView, + childViewContainer: '.js-list', + emptyView: EmptyView, - bindShortcuts: function () { - var that = this; - var doAction = function (action) { - var selectedIssue = that.collection.at(that.options.app.state.get('selectedIndex')); - if (selectedIssue == null) { - return; - } - var selectedIssueView = that.children.findByModel(selectedIssue); - selectedIssueView.$('.js-issue-' + action).click(); - }; - WorkspaceListView.prototype.bindShortcuts.apply(this, arguments); - key('right', 'list', function () { - var selectedIssue = that.collection.at(that.options.app.state.get('selectedIndex')); - that.options.app.controller.showComponentViewer(selectedIssue); - return false; - }); - key('space', 'list', function () { - var selectedIssue = that.collection.at(that.options.app.state.get('selectedIndex')); - selectedIssue.set({ selected: !selectedIssue.get('selected') }); - return false; - }); - key('f', 'list', function () { - return doAction('transition'); - }); - key('a', 'list', function () { - return doAction('assign'); - }); - key('m', 'list', function () { - return doAction('assign-to-me'); - }); - key('p', 'list', function () { - return doAction('plan'); - }); - key('i', 'list', function () { - return doAction('set-severity'); - }); - key('c', 'list', function () { - return doAction('comment'); - }); - return key('t', 'list', function () { - return doAction('edit-tags'); - }); - }, - - scrollTo: function () { - var selectedIssue = this.collection.at(this.options.app.state.get('selectedIndex')); + bindShortcuts: function () { + var that = this; + var doAction = function (action) { + var selectedIssue = that.collection.at(that.options.app.state.get('selectedIndex')); if (selectedIssue == null) { return; } - var selectedIssueView = this.children.findByModel(selectedIssue), - parentTopOffset = this.$el.offset().top, - viewTop = selectedIssueView.$el.offset().top - parentTopOffset; - if (selectedIssueView.$el.prev().is('.issues-workspace-list-component')) { - viewTop -= COMPONENT_HEIGHT; - } - var viewBottom = selectedIssueView.$el.offset().top + selectedIssueView.$el.outerHeight() + BOTTOM_OFFSET, - windowTop = $(window).scrollTop(), - windowBottom = windowTop + $(window).height(); - if (viewTop < windowTop) { - $(window).scrollTop(viewTop); - } - if (viewBottom > windowBottom) { - $(window).scrollTop($(window).scrollTop() - windowBottom + viewBottom); - } - }, + var selectedIssueView = that.children.findByModel(selectedIssue); + selectedIssueView.$('.js-issue-' + action).click(); + }; + WorkspaceListView.prototype.bindShortcuts.apply(this, arguments); + key('right', 'list', function () { + var selectedIssue = that.collection.at(that.options.app.state.get('selectedIndex')); + that.options.app.controller.showComponentViewer(selectedIssue); + return false; + }); + key('space', 'list', function () { + var selectedIssue = that.collection.at(that.options.app.state.get('selectedIndex')); + selectedIssue.set({ selected: !selectedIssue.get('selected') }); + return false; + }); + key('f', 'list', function () { + return doAction('transition'); + }); + key('a', 'list', function () { + return doAction('assign'); + }); + key('m', 'list', function () { + return doAction('assign-to-me'); + }); + key('p', 'list', function () { + return doAction('plan'); + }); + key('i', 'list', function () { + return doAction('set-severity'); + }); + key('c', 'list', function () { + return doAction('comment'); + }); + return key('t', 'list', function () { + return doAction('edit-tags'); + }); + }, - 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), - putComponent = prev == null; - if (prev != null) { - var fullComponent = [model.get('project'), model.get('component')].join(' '), - fullPrevComponent = [prev.get('project'), prev.get('component')].join(' '); - if (fullComponent !== fullPrevComponent) { - putComponent = true; - } - } - if (putComponent) { - $container.append(this.componentTemplate(model.toJSON())); + scrollTo: function () { + var selectedIssue = this.collection.at(this.options.app.state.get('selectedIndex')); + if (selectedIssue == null) { + return; + } + var selectedIssueView = this.children.findByModel(selectedIssue), + parentTopOffset = this.$el.offset().top, + viewTop = selectedIssueView.$el.offset().top - parentTopOffset; + if (selectedIssueView.$el.prev().is('.issues-workspace-list-component')) { + viewTop -= COMPONENT_HEIGHT; + } + var viewBottom = selectedIssueView.$el.offset().top + selectedIssueView.$el.outerHeight() + BOTTOM_OFFSET, + windowTop = $(window).scrollTop(), + windowBottom = windowTop + $(window).height(); + if (viewTop < windowTop) { + $(window).scrollTop(viewTop); + } + if (viewBottom > windowBottom) { + $(window).scrollTop($(window).scrollTop() - windowBottom + viewBottom); + } + }, + + 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), + putComponent = prev == null; + if (prev != null) { + var fullComponent = [model.get('project'), model.get('component')].join(' '), + fullPrevComponent = [prev.get('project'), prev.get('component')].join(' '); + if (fullComponent !== fullPrevComponent) { + putComponent = true; } } - $container.append(childView.el); - }, - - destroyChildren: function () { - WorkspaceListView.prototype.destroyChildren.apply(this, arguments); - this.$('.issues-workspace-list-component').remove(); + if (putComponent) { + $container.append(this.componentTemplate(model.toJSON())); + } } - }); + $container.append(childView.el); + }, + destroyChildren: function () { + WorkspaceListView.prototype.destroyChildren.apply(this, arguments); + this.$('.issues-workspace-list-component').remove(); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/maintenance/app.js b/server/sonar-web/src/main/js/apps/maintenance/app.js index cc7b016bef0..b089a9cb574 100644 --- a/server/sonar-web/src/main/js/apps/maintenance/app.js +++ b/server/sonar-web/src/main/js/apps/maintenance/app.js @@ -1,17 +1,18 @@ -define([ - './main-view' -], function (MainView) { +import _ from 'underscore'; +import Backbone from 'backbone'; +import Marionette from 'backbone.marionette'; +import MainView from './main-view'; - var App = new Marionette.Application(); +var App = new Marionette.Application(); - App.on('start', function (options) { - var viewOptions = _.extend(options, { - model: new Backbone.Model() - }); - var mainView = new MainView(viewOptions); - mainView.render().refresh(); +App.on('start', function (options) { + var viewOptions = _.extend(options, { + model: new Backbone.Model() }); + var mainView = new MainView(viewOptions); + mainView.render().refresh(); +}); + +export default App; - return App; -}); diff --git a/server/sonar-web/src/main/js/apps/maintenance/main-view.js b/server/sonar-web/src/main/js/apps/maintenance/main-view.js index 47b380973da..3e9825adfa0 100644 --- a/server/sonar-web/src/main/js/apps/maintenance/main-view.js +++ b/server/sonar-web/src/main/js/apps/maintenance/main-view.js @@ -1,62 +1,62 @@ -define([ - './templates' -], function () { - - var $ = jQuery; - - return Marionette.ItemView.extend({ - template: Templates['maintenance-main'], - - events: { - 'click #start-migration': 'startMigration' - }, - - initialize: function () { - var that = this; - this.requestOptions = { - type: 'GET', - url: baseUrl + '/api/system/' + (this.options.setup ? 'db_migration_status' : 'status') - }; - setInterval(function () { - that.refresh(); - }, 5000); - }, - - refresh: function () { - var that = this; - return Backbone.ajax(this.requestOptions).done(function (r) { - that.model.set(r); - that.render(); - if (that.model.get('state') === 'MIGRATION_SUCCEEDED') { - that.goHome(); - } - }); - }, - - startMigration: function () { - var that = this; - Backbone.ajax({ - url: baseUrl + '/api/system/migrate_db', - type: 'POST' - }).done(function (r) { - that.model.set(r); - that.render(); - }); - }, - - onRender: function () { - $('.page-simple').toggleClass('panel-warning', this.model.get('state') === 'MIGRATION_REQUIRED'); - }, - - goHome: function () { - setInterval(function () { - window.location = baseUrl + '/'; - }, 2500); - }, - - serializeData: function () { - return _.extend(this._super(), { setup: this.options.setup }); - } - }); - +import $ from 'jquery'; +import _ from 'underscore'; +import Backbone from 'backbone'; +import Marionette from 'backbone.marionette'; +import './templates'; + +export default Marionette.ItemView.extend({ + template: Templates['maintenance-main'], + + events: { + 'click #start-migration': 'startMigration' + }, + + initialize: function () { + var that = this; + this.requestOptions = { + type: 'GET', + url: baseUrl + '/api/system/' + (this.options.setup ? 'db_migration_status' : 'status') + }; + setInterval(function () { + that.refresh(); + }, 5000); + }, + + refresh: function () { + var that = this; + return Backbone.ajax(this.requestOptions).done(function (r) { + that.model.set(r); + that.render(); + if (that.model.get('state') === 'MIGRATION_SUCCEEDED') { + that.goHome(); + } + }); + }, + + startMigration: function () { + var that = this; + Backbone.ajax({ + url: baseUrl + '/api/system/migrate_db', + type: 'POST' + }).done(function (r) { + that.model.set(r); + that.render(); + }); + }, + + onRender: function () { + $('.page-simple').toggleClass('panel-warning', this.model.get('state') === 'MIGRATION_REQUIRED'); + }, + + goHome: function () { + setInterval(function () { + window.location = baseUrl + '/'; + }, 2500); + }, + + serializeData: function () { + return _.extend(this._super(), { setup: this.options.setup }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/markdown/app.js b/server/sonar-web/src/main/js/apps/markdown/app.js index 46cf48a8fc5..86ed29e5207 100644 --- a/server/sonar-web/src/main/js/apps/markdown/app.js +++ b/server/sonar-web/src/main/js/apps/markdown/app.js @@ -1,11 +1,12 @@ -define(['./markdown-help-view'], function (MarkdownView) { +import Marionette from 'backbone.marionette'; +import MarkdownView from './markdown-help-view'; - var App = new Marionette.Application(); +var App = new Marionette.Application(); - App.on('start', function (options) { - new MarkdownView({ el: options.el }).render(); - }); +App.on('start', function (options) { + new MarkdownView({ el: options.el }).render(); +}); + +export default App; - return App; -}); diff --git a/server/sonar-web/src/main/js/apps/markdown/markdown-help-view.js b/server/sonar-web/src/main/js/apps/markdown/markdown-help-view.js index 321dd2c40b0..c7db13a5b09 100644 --- a/server/sonar-web/src/main/js/apps/markdown/markdown-help-view.js +++ b/server/sonar-web/src/main/js/apps/markdown/markdown-help-view.js @@ -1,7 +1,8 @@ -define(['./templates'], function () { - - return Marionette.ItemView.extend({ - template: Templates['markdown-help'] - }); +import Marionette from 'backbone.marionette'; +import './templates'; +export default Marionette.ItemView.extend({ + template: Templates['markdown-help'] }); + + diff --git a/server/sonar-web/src/main/js/apps/measures/app.js b/server/sonar-web/src/main/js/apps/measures/app.js index f382eae9773..a3b533d0958 100644 --- a/server/sonar-web/src/main/js/apps/measures/app.js +++ b/server/sonar-web/src/main/js/apps/measures/app.js @@ -1,168 +1,164 @@ -define([ - './measures-filter-bar', - 'components/navigator/filters/base-filters', - 'components/navigator/filters/checkbox-filters', - 'components/navigator/filters/choice-filters', - 'components/navigator/filters/ajax-select-filters', - 'components/navigator/filters/favorite-filters', - 'components/navigator/filters/range-filters', - 'components/navigator/filters/string-filters', - 'components/navigator/filters/metric-filters' - ], - function (FilterBar, BaseFilters, CheckboxFilterView, ChoiceFilters, AjaxSelectFilters, FavoriteFilters, - RangeFilters, StringFilterView, MetricFilterView) { - - var NavigatorApp = new Marionette.Application(), - init = function () { - NavigatorApp.addRegions({ filtersRegion: '.navigator-filters' }); - - this.filters = new BaseFilters.Filters(); - - if (_.isObject(window.SS.favorites)) { - this.filters.add([ - new BaseFilters.Filter({ - type: FavoriteFilters.FavoriteFilterView, - enabled: true, - optional: false, - choices: window.SS.favorites, - favoriteUrl: '/measures/filter', - manageUrl: '/measures/manage' - }) - ]); - } - - this.filters.add([ - new BaseFilters.Filter({ - name: window.SS.phrases.components, - property: 'qualifiers[]', - type: ChoiceFilters.ChoiceFilterView, - enabled: true, - optional: false, - choices: window.SS.qualifiers, - defaultValue: window.SS.phrases.any - }), - - new BaseFilters.Filter({ - name: window.SS.phrases.componentsOf, - property: 'base', - type: AjaxSelectFilters.ComponentFilterView, - multiple: false, - enabled: false, - optional: true - }), - - new BaseFilters.Filter({ - name: window.SS.phrases.favoritesOnly, - property: 'onFavourites', - type: CheckboxFilterView, - enabled: false, - optional: true - }), - - new BaseFilters.Filter({ - name: window.SS.phrases.date, - propertyFrom: 'fromDate', - propertyTo: 'toDate', - type: RangeFilters.DateRangeFilterView, - enabled: false, - optional: true - }), - - new BaseFilters.Filter({ - name: window.SS.phrases.keyContains, - property: 'keySearch', - type: StringFilterView, - enabled: false, - optional: true - }) - ]); - - this.filters.add([ - new BaseFilters.Filter({ - name: window.SS.phrases.lastAnalysis, - propertyFrom: 'ageMinDays', - propertyTo: 'ageMaxDays', - type: RangeFilters.RangeFilterView, - placeholder: window.SS.phrases.days, - enabled: false, - optional: true - }), - - new BaseFilters.Filter({ - name: window.SS.phrases.metric, - property: 'c3', - type: MetricFilterView, - metrics: window.SS.metrics, - periods: window.SS.metricPeriods, - operations: { 'eq': '=', 'lt': '<', 'lte': '≤', 'gt': '>', 'gte': '≥' }, - enabled: false, - optional: true - }), - - new BaseFilters.Filter({ - name: window.SS.phrases.metric, - property: 'c2', - type: MetricFilterView, - metrics: window.SS.metrics, - periods: window.SS.metricPeriods, - operations: { 'eq': '=', 'lt': '<', 'lte': '≤', 'gt': '>', 'gte': '≥' }, - enabled: false, - optional: true - }), - - new BaseFilters.Filter({ - name: window.SS.phrases.metric, - property: 'c1', - type: MetricFilterView, - metrics: window.SS.metrics, - periods: window.SS.metricPeriods, - operations: { 'eq': '=', 'lt': '<', 'lte': '≤', 'gt': '>', 'gte': '≥' }, - enabled: false, - optional: true - }), - - new BaseFilters.Filter({ - name: window.SS.phrases.nameContains, - property: 'nameSearch', - type: StringFilterView, - enabled: false, - optional: true - }), - - new BaseFilters.Filter({ - name: window.SS.phrases.alert, - property: 'alertLevels[]', - type: ChoiceFilters.ChoiceFilterView, - enabled: false, - optional: true, - choices: { - 'error': window.SS.phrases.error, - 'warn': window.SS.phrases.warning, - 'ok': window.SS.phrases.ok - } - }) - ]); - - this.filterBarView = new FilterBar({ - collection: this.filters, - extra: { - sort: '', - asc: false - } - }); - - this.filtersRegion.show(this.filterBarView); - - if (window.queryParams) { - NavigatorApp.filterBarView.restoreFromQuery(window.queryParams); - } - key.setScope('list'); - }; - - NavigatorApp.on('start', function () { - init.call(NavigatorApp); +import _ from 'underscore'; +import Marionette from 'backbone.marionette'; +import FilterBar from './measures-filter-bar'; +import BaseFilters from 'components/navigator/filters/base-filters'; +import CheckboxFilterView from 'components/navigator/filters/checkbox-filters'; +import ChoiceFilters from 'components/navigator/filters/choice-filters'; +import AjaxSelectFilters from 'components/navigator/filters/ajax-select-filters'; +import FavoriteFilters from 'components/navigator/filters/favorite-filters'; +import RangeFilters from 'components/navigator/filters/range-filters'; +import StringFilterView from 'components/navigator/filters/string-filters'; +import MetricFilterView from 'components/navigator/filters/metric-filters'; + +var NavigatorApp = new Marionette.Application(), + init = function () { + NavigatorApp.addRegions({ filtersRegion: '.navigator-filters' }); + + this.filters = new BaseFilters.Filters(); + + if (_.isObject(window.SS.favorites)) { + this.filters.add([ + new BaseFilters.Filter({ + type: FavoriteFilters.FavoriteFilterView, + enabled: true, + optional: false, + choices: window.SS.favorites, + favoriteUrl: '/measures/filter', + manageUrl: '/measures/manage' + }) + ]); + } + + this.filters.add([ + new BaseFilters.Filter({ + name: window.SS.phrases.components, + property: 'qualifiers[]', + type: ChoiceFilters.ChoiceFilterView, + enabled: true, + optional: false, + choices: window.SS.qualifiers, + defaultValue: window.SS.phrases.any + }), + + new BaseFilters.Filter({ + name: window.SS.phrases.componentsOf, + property: 'base', + type: AjaxSelectFilters.ComponentFilterView, + multiple: false, + enabled: false, + optional: true + }), + + new BaseFilters.Filter({ + name: window.SS.phrases.favoritesOnly, + property: 'onFavourites', + type: CheckboxFilterView, + enabled: false, + optional: true + }), + + new BaseFilters.Filter({ + name: window.SS.phrases.date, + propertyFrom: 'fromDate', + propertyTo: 'toDate', + type: RangeFilters.DateRangeFilterView, + enabled: false, + optional: true + }), + + new BaseFilters.Filter({ + name: window.SS.phrases.keyContains, + property: 'keySearch', + type: StringFilterView, + enabled: false, + optional: true + }) + ]); + + this.filters.add([ + new BaseFilters.Filter({ + name: window.SS.phrases.lastAnalysis, + propertyFrom: 'ageMinDays', + propertyTo: 'ageMaxDays', + type: RangeFilters.RangeFilterView, + placeholder: window.SS.phrases.days, + enabled: false, + optional: true + }), + + new BaseFilters.Filter({ + name: window.SS.phrases.metric, + property: 'c3', + type: MetricFilterView, + metrics: window.SS.metrics, + periods: window.SS.metricPeriods, + operations: { 'eq': '=', 'lt': '<', 'lte': '≤', 'gt': '>', 'gte': '≥' }, + enabled: false, + optional: true + }), + + new BaseFilters.Filter({ + name: window.SS.phrases.metric, + property: 'c2', + type: MetricFilterView, + metrics: window.SS.metrics, + periods: window.SS.metricPeriods, + operations: { 'eq': '=', 'lt': '<', 'lte': '≤', 'gt': '>', 'gte': '≥' }, + enabled: false, + optional: true + }), + + new BaseFilters.Filter({ + name: window.SS.phrases.metric, + property: 'c1', + type: MetricFilterView, + metrics: window.SS.metrics, + periods: window.SS.metricPeriods, + operations: { 'eq': '=', 'lt': '<', 'lte': '≤', 'gt': '>', 'gte': '≥' }, + enabled: false, + optional: true + }), + + new BaseFilters.Filter({ + name: window.SS.phrases.nameContains, + property: 'nameSearch', + type: StringFilterView, + enabled: false, + optional: true + }), + + new BaseFilters.Filter({ + name: window.SS.phrases.alert, + property: 'alertLevels[]', + type: ChoiceFilters.ChoiceFilterView, + enabled: false, + optional: true, + choices: { + 'error': window.SS.phrases.error, + 'warn': window.SS.phrases.warning, + 'ok': window.SS.phrases.ok + } + }) + ]); + + this.filterBarView = new FilterBar({ + collection: this.filters, + extra: { + sort: '', + asc: false + } }); - return NavigatorApp; + this.filtersRegion.show(this.filterBarView); - }); + if (window.queryParams) { + NavigatorApp.filterBarView.restoreFromQuery(window.queryParams); + } + key.setScope('list'); + }; + +NavigatorApp.on('start', function () { + init.call(NavigatorApp); +}); + +export default NavigatorApp; diff --git a/server/sonar-web/src/main/js/apps/measures/measures-filter-bar.js b/server/sonar-web/src/main/js/apps/measures/measures-filter-bar.js index a14400664f3..acd0c0dea3a 100644 --- a/server/sonar-web/src/main/js/apps/measures/measures-filter-bar.js +++ b/server/sonar-web/src/main/js/apps/measures/measures-filter-bar.js @@ -1,9 +1,10 @@ -define(['components/navigator/filters/filter-bar'], function (FilterBarView) { - - return FilterBarView.extend({ - template: function () { - return jQuery('#filter-bar-template').html(); - } - }); +import $ from 'jquery'; +import FilterBarView from 'components/navigator/filters/filter-bar'; +export default FilterBarView.extend({ + template: function () { + return $('#filter-bar-template').html(); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/metrics/app.js b/server/sonar-web/src/main/js/apps/metrics/app.js index 4e42d95a09d..42eecceff9a 100644 --- a/server/sonar-web/src/main/js/apps/metrics/app.js +++ b/server/sonar-web/src/main/js/apps/metrics/app.js @@ -1,64 +1,63 @@ -define([ - './layout', - './metrics', - './header-view', - './list-view', - './list-footer-view' -], function (Layout, Metrics, HeaderView, ListView, ListFooterView) { - - var $ = jQuery, - App = new Marionette.Application(), - init = function (options) { - // Layout - this.layout = new Layout({ el: options.el }); - this.layout.render(); - - // Collection - this.metrics = new Metrics(); - - // Header View - this.headerView = new HeaderView({ - collection: this.metrics, - domains: this.domains, - types: this.types, - app: App - }); - this.layout.headerRegion.show(this.headerView); - - // List View - this.listView = new ListView({ - collection: this.metrics, - domains: this.domains, - types: this.types - }); - this.layout.listRegion.show(this.listView); - - // List Footer View - this.listFooterView = new ListFooterView({ collection: this.metrics }); - this.layout.listFooterRegion.show(this.listFooterView); - - // Go! - this.metrics.fetch(); - }; - - - App.requestDomains = function () { - return $.get(baseUrl + '/api/metrics/domains').done(function (r) { - App.domains = r.domains; - }); - }; - App.requestTypes = function () { - return $.get(baseUrl + '/api/metrics/types').done(function (r) { - App.types = r.types; - }); - }; +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'; + +var App = new Marionette.Application(), + init = function (options) { + // Layout + this.layout = new Layout({ el: options.el }); + this.layout.render(); + + // Collection + this.metrics = new Metrics(); + + // Header View + this.headerView = new HeaderView({ + collection: this.metrics, + domains: this.domains, + types: this.types, + app: App + }); + this.layout.headerRegion.show(this.headerView); + + // List View + this.listView = new ListView({ + collection: this.metrics, + domains: this.domains, + types: this.types + }); + this.layout.listRegion.show(this.listView); + + // List Footer View + this.listFooterView = new ListFooterView({ collection: this.metrics }); + this.layout.listFooterRegion.show(this.listFooterView); + + // Go! + this.metrics.fetch(); + }; + + +App.requestDomains = function () { + return $.get(baseUrl + '/api/metrics/domains').done(function (r) { + App.domains = r.domains; + }); +}; +App.requestTypes = function () { + return $.get(baseUrl + '/api/metrics/types').done(function (r) { + App.types = r.types; + }); +}; - App.on('start', function (options) { - $.when(window.requestMessages(), App.requestDomains(), App.requestTypes()).done(function () { - init.call(App, options); - }); +App.on('start', function (options) { + $.when(window.requestMessages(), App.requestDomains(), App.requestTypes()).done(function () { + init.call(App, options); }); +}); + +export default App; - return App; -}); diff --git a/server/sonar-web/src/main/js/apps/metrics/create-view.js b/server/sonar-web/src/main/js/apps/metrics/create-view.js index 9e2145fbee7..68681d93822 100644 --- a/server/sonar-web/src/main/js/apps/metrics/create-view.js +++ b/server/sonar-web/src/main/js/apps/metrics/create-view.js @@ -1,36 +1,34 @@ -define([ - './metric', - './form-view' -], function (Metric, FormView) { +import Metric from './metric'; +import FormView from './form-view'; - return FormView.extend({ - - sendRequest: function () { - var that = this, - metric = new Metric({ - key: this.$('#create-metric-key').val(), - name: this.$('#create-metric-name').val(), - description: this.$('#create-metric-description').val(), - domain: this.$('#create-metric-domain').val(), - type: this.$('#create-metric-type').val() - }); - this.disableForm(); - return metric.save(null, { - statusCode: { - // do not show global error - 400: null - } - }).done(function () { - that.collection.refresh(); - if (that.options.domains.indexOf(metric.get('domain')) === -1) { - that.options.domains.push(metric.get('domain')); - } - that.destroy(); - }).fail(function (jqXHR) { - that.showErrors(jqXHR.responseJSON.errors, jqXHR.responseJSON.warnings); - that.enableForm(); - }); - } - }); +export default FormView.extend({ + sendRequest: function () { + var that = this, + metric = new Metric({ + key: this.$('#create-metric-key').val(), + name: this.$('#create-metric-name').val(), + description: this.$('#create-metric-description').val(), + domain: this.$('#create-metric-domain').val(), + type: this.$('#create-metric-type').val() + }); + this.disableForm(); + return metric.save(null, { + statusCode: { + // do not show global error + 400: null + } + }).done(function () { + that.collection.refresh(); + if (that.options.domains.indexOf(metric.get('domain')) === -1) { + that.options.domains.push(metric.get('domain')); + } + that.destroy(); + }).fail(function (jqXHR) { + that.showErrors(jqXHR.responseJSON.errors, jqXHR.responseJSON.warnings); + that.enableForm(); + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/metrics/delete-view.js b/server/sonar-web/src/main/js/apps/metrics/delete-view.js index 8719b9fdb3a..cef043b54b8 100644 --- a/server/sonar-web/src/main/js/apps/metrics/delete-view.js +++ b/server/sonar-web/src/main/js/apps/metrics/delete-view.js @@ -1,32 +1,30 @@ -define([ - 'components/common/modal-form', - './templates' -], function (ModalForm) { +import ModalForm from 'components/common/modal-form'; +import './templates'; - return ModalForm.extend({ - template: Templates['metrics-delete'], +export default ModalForm.extend({ + template: Templates['metrics-delete'], - onFormSubmit: function (e) { - this._super(e); - this.sendRequest(); - }, - - sendRequest: function () { - var that = this, - collection = this.model.collection; - return this.model.destroy({ - wait: true, - statusCode: { - // do not show global error - 400: null - } - }).done(function () { - collection.refresh(); - that.destroy(); - }).fail(function (jqXHR) { - that.showErrors(jqXHR.responseJSON.errors, jqXHR.responseJSON.warnings); - }); - } - }); + onFormSubmit: function (e) { + this._super(e); + this.sendRequest(); + }, + sendRequest: function () { + var that = this, + collection = this.model.collection; + return this.model.destroy({ + wait: true, + statusCode: { + // do not show global error + 400: null + } + }).done(function () { + collection.refresh(); + that.destroy(); + }).fail(function (jqXHR) { + that.showErrors(jqXHR.responseJSON.errors, jqXHR.responseJSON.warnings); + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/metrics/form-view.js b/server/sonar-web/src/main/js/apps/metrics/form-view.js index 03e66f715b6..7396e4da8ff 100644 --- a/server/sonar-web/src/main/js/apps/metrics/form-view.js +++ b/server/sonar-web/src/main/js/apps/metrics/form-view.js @@ -1,57 +1,55 @@ -define([ - 'components/common/modal-form', - './templates' -], function (ModalForm) { - - var $ = jQuery; - - return ModalForm.extend({ - template: Templates['metrics-form'], - - onRender: function () { - var that = this; - this._super(); - this.$('[data-toggle="tooltip"]').tooltip({ container: 'body', placement: 'bottom' }); - this.$('#create-metric-domain').select2({ - width: '250px', - createSearchChoice: function (term) { - return { id: term, text: '+' + term }; - }, - createSearchChoicePosition: 'top', - initSelection: function (element, callback) { - var value = $(element).val(); - callback({ id: value, text: value }); - }, - query: function (options) { - var items = that.options.domains.filter(function (d) { - return d.toLowerCase().indexOf(options.term.toLowerCase()) !== -1; - }), - results = items.map(function (item) { - return { id: item, text: item }; - }); - options.callback({ results: results, more: false }); - } - }).select2('val', this.model && this.model.get('domain')); - this.$('#create-metric-type').select2({ width: '250px' }); - }, - - onDestroy: function () { - this._super(); - this.$('[data-toggle="tooltip"]').tooltip('destroy'); - }, - - onFormSubmit: function (e) { - this._super(e); - this.sendRequest(); - }, - - serializeData: function () { - return _.extend(this._super(), { - domains: this.options.domains, - types: this.options.types - }); - } - - }); +import $ from 'jquery'; +import _ from 'underscore'; +import ModalForm from 'components/common/modal-form'; +import './templates'; + +export default ModalForm.extend({ + template: Templates['metrics-form'], + + onRender: function () { + var that = this; + this._super(); + this.$('[data-toggle="tooltip"]').tooltip({ container: 'body', placement: 'bottom' }); + this.$('#create-metric-domain').select2({ + width: '250px', + createSearchChoice: function (term) { + return { id: term, text: '+' + term }; + }, + createSearchChoicePosition: 'top', + initSelection: function (element, callback) { + var value = $(element).val(); + callback({ id: value, text: value }); + }, + query: function (options) { + var items = that.options.domains.filter(function (d) { + return d.toLowerCase().indexOf(options.term.toLowerCase()) !== -1; + }), + results = items.map(function (item) { + return { id: item, text: item }; + }); + options.callback({ results: results, more: false }); + } + }).select2('val', this.model && this.model.get('domain')); + this.$('#create-metric-type').select2({ width: '250px' }); + }, + + onDestroy: function () { + this._super(); + this.$('[data-toggle="tooltip"]').tooltip('destroy'); + }, + + onFormSubmit: function (e) { + this._super(e); + this.sendRequest(); + }, + + serializeData: function () { + return _.extend(this._super(), { + domains: this.options.domains, + types: this.options.types + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/metrics/header-view.js b/server/sonar-web/src/main/js/apps/metrics/header-view.js index 78a9b0da0d0..37cdc7dc8b4 100644 --- a/server/sonar-web/src/main/js/apps/metrics/header-view.js +++ b/server/sonar-web/src/main/js/apps/metrics/header-view.js @@ -1,28 +1,27 @@ -define([ - './create-view', - './templates' -], function (CreateView) { +import Marionette from 'backbone.marionette'; +import CreateView from './create-view'; +import './templates'; - return Marionette.ItemView.extend({ - template: Templates['metrics-header'], +export default Marionette.ItemView.extend({ + template: Templates['metrics-header'], - events: { - 'click #metrics-create': 'onCreateClick' - }, + events: { + 'click #metrics-create': 'onCreateClick' + }, - onCreateClick: function (e) { - e.preventDefault(); - this.createMetric(); - }, - - createMetric: function () { - new CreateView({ - collection: this.collection, - domains: this.options.domains, - types: this.options.types, - app: this.options.app - }).render(); - } - }); + onCreateClick: function (e) { + e.preventDefault(); + this.createMetric(); + }, + createMetric: function () { + new CreateView({ + collection: this.collection, + domains: this.options.domains, + types: this.options.types, + app: this.options.app + }).render(); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/metrics/layout.js b/server/sonar-web/src/main/js/apps/metrics/layout.js index 9575307d96f..6d1a560cf89 100644 --- a/server/sonar-web/src/main/js/apps/metrics/layout.js +++ b/server/sonar-web/src/main/js/apps/metrics/layout.js @@ -1,15 +1,14 @@ -define([ - './templates' -], function () { +import Marionette from 'backbone.marionette'; +import './templates'; - return Marionette.LayoutView.extend({ - template: Templates['metrics-layout'], - - regions: { - headerRegion: '#metrics-header', - listRegion: '#metrics-list', - listFooterRegion: '#metrics-list-footer' - } - }); +export default Marionette.LayoutView.extend({ + template: Templates['metrics-layout'], + regions: { + headerRegion: '#metrics-header', + listRegion: '#metrics-list', + listFooterRegion: '#metrics-list-footer' + } }); + + diff --git a/server/sonar-web/src/main/js/apps/metrics/list-footer-view.js b/server/sonar-web/src/main/js/apps/metrics/list-footer-view.js index 932dfd6d35f..a48c0a11e7a 100644 --- a/server/sonar-web/src/main/js/apps/metrics/list-footer-view.js +++ b/server/sonar-web/src/main/js/apps/metrics/list-footer-view.js @@ -1,34 +1,34 @@ -define([ - './templates' -], function () { - - return Marionette.ItemView.extend({ - template: Templates['metrics-list-footer'], - - collectionEvents: { - 'all': 'render' - }, - - events: { - 'click #metrics-fetch-more': 'onMoreClick' - }, - - onMoreClick: function (e) { - e.preventDefault(); - this.fetchMore(); - }, - - fetchMore: function () { - this.collection.fetchMore(); - }, - - serializeData: function () { - return _.extend(this._super(), { - total: this.collection.total, - count: this.collection.length, - more: this.collection.hasMore() - }); - } - }); +import _ from 'underscore'; +import Marionette from 'backbone.marionette'; +import './templates'; +export default Marionette.ItemView.extend({ + template: Templates['metrics-list-footer'], + + collectionEvents: { + 'all': 'render' + }, + + events: { + 'click #metrics-fetch-more': 'onMoreClick' + }, + + onMoreClick: function (e) { + e.preventDefault(); + this.fetchMore(); + }, + + fetchMore: function () { + this.collection.fetchMore(); + }, + + serializeData: function () { + return _.extend(this._super(), { + total: this.collection.total, + count: this.collection.length, + more: this.collection.hasMore() + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/metrics/list-item-view.js b/server/sonar-web/src/main/js/apps/metrics/list-item-view.js index c6989e3b7b3..3a56e9c9650 100644 --- a/server/sonar-web/src/main/js/apps/metrics/list-item-view.js +++ b/server/sonar-web/src/main/js/apps/metrics/list-item-view.js @@ -1,52 +1,51 @@ -define([ - './update-view', - './delete-view', - './templates' -], function (UpdateView, DeleteView) { - - return Marionette.ItemView.extend({ - tagName: 'li', - className: 'panel panel-vertical', - template: Templates['metrics-list-item'], - - events: { - 'click .js-metric-update': 'onUpdateClick', - 'click .js-metric-delete': 'onDeleteClick' - }, - - onRender: function () { - this.$el - .attr('data-id', this.model.id) - .attr('data-key', this.model.get('key')); - this.$('[data-toggle="tooltip"]').tooltip({ container: 'body', placement: 'bottom' }); - }, - - onDestroy: function () { - this.$('[data-toggle="tooltip"]').tooltip('destroy'); - }, - - onUpdateClick: function (e) { - e.preventDefault(); - this.updateMetric(); - }, - - onDeleteClick: function (e) { - e.preventDefault(); - this.deleteMetric(); - }, - - updateMetric: function () { - new UpdateView({ - model: this.model, - collection: this.model.collection, - types: this.options.types, - domains: this.options.domains - }).render(); - }, - - deleteMetric: function () { - new DeleteView({ model: this.model }).render(); - } - }); - +import Marionette from 'backbone.marionette'; +import UpdateView from './update-view'; +import DeleteView from './delete-view'; +import './templates'; + +export default Marionette.ItemView.extend({ + tagName: 'li', + className: 'panel panel-vertical', + template: Templates['metrics-list-item'], + + events: { + 'click .js-metric-update': 'onUpdateClick', + 'click .js-metric-delete': 'onDeleteClick' + }, + + onRender: function () { + this.$el + .attr('data-id', this.model.id) + .attr('data-key', this.model.get('key')); + this.$('[data-toggle="tooltip"]').tooltip({ container: 'body', placement: 'bottom' }); + }, + + onDestroy: function () { + this.$('[data-toggle="tooltip"]').tooltip('destroy'); + }, + + onUpdateClick: function (e) { + e.preventDefault(); + this.updateMetric(); + }, + + onDeleteClick: function (e) { + e.preventDefault(); + this.deleteMetric(); + }, + + updateMetric: function () { + new UpdateView({ + model: this.model, + collection: this.model.collection, + types: this.options.types, + domains: this.options.domains + }).render(); + }, + + deleteMetric: function () { + new DeleteView({ model: this.model }).render(); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/metrics/list-view.js b/server/sonar-web/src/main/js/apps/metrics/list-view.js index b015c65d966..e5a0f9f1e96 100644 --- a/server/sonar-web/src/main/js/apps/metrics/list-view.js +++ b/server/sonar-web/src/main/js/apps/metrics/list-view.js @@ -1,18 +1,17 @@ -define([ - './list-item-view', - './templates' -], function (ListItemView) { +import Marionette from 'backbone.marionette'; +import ListItemView from './list-item-view'; +import './templates'; - return Marionette.CollectionView.extend({ - tagName: 'ul', - childView: ListItemView, - - childViewOptions: function () { - return { - types: this.options.types, - domains: this.options.domains - }; - } - }); +export default Marionette.CollectionView.extend({ + tagName: 'ul', + childView: ListItemView, + childViewOptions: function () { + return { + types: this.options.types, + domains: this.options.domains + }; + } }); + + diff --git a/server/sonar-web/src/main/js/apps/metrics/metric.js b/server/sonar-web/src/main/js/apps/metrics/metric.js index cb160c882d0..82bb67c20fe 100644 --- a/server/sonar-web/src/main/js/apps/metrics/metric.js +++ b/server/sonar-web/src/main/js/apps/metrics/metric.js @@ -1,37 +1,38 @@ -define(function () { +import _ from 'underscore'; +import Backbone from 'backbone'; - return Backbone.Model.extend({ - idAttribute: 'id', +export default Backbone.Model.extend({ + idAttribute: 'id', - urlRoot: function () { - return baseUrl + '/api/metrics'; - }, + urlRoot: function () { + return baseUrl + '/api/metrics'; + }, - sync: function (method, model, options) { - var opts = options || {}; - if (method === 'create') { - _.defaults(opts, { - url: this.urlRoot() + '/create', - type: 'POST', - data: _.pick(model.toJSON(), 'key', 'name', 'description', 'domain', 'type') - }); - } - if (method === 'update') { - _.defaults(opts, { - url: this.urlRoot() + '/update', - type: 'POST', - data: _.pick(model.toJSON(), 'id', 'key', 'name', 'description', 'domain', 'type') - }); - } - if (method === 'delete') { - _.defaults(opts, { - url: this.urlRoot() + '/delete', - type: 'POST', - data: { ids: this.id } - }); - } - return Backbone.ajax(opts); + sync: function (method, model, options) { + var opts = options || {}; + if (method === 'create') { + _.defaults(opts, { + url: this.urlRoot() + '/create', + type: 'POST', + data: _.pick(model.toJSON(), 'key', 'name', 'description', 'domain', 'type') + }); } - }); - + if (method === 'update') { + _.defaults(opts, { + url: this.urlRoot() + '/update', + type: 'POST', + data: _.pick(model.toJSON(), 'id', 'key', 'name', 'description', 'domain', 'type') + }); + } + if (method === 'delete') { + _.defaults(opts, { + url: this.urlRoot() + '/delete', + type: 'POST', + data: { ids: this.id } + }); + } + return Backbone.ajax(opts); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/metrics/metrics.js b/server/sonar-web/src/main/js/apps/metrics/metrics.js index 393ebe3c2b1..44fa17c8227 100644 --- a/server/sonar-web/src/main/js/apps/metrics/metrics.js +++ b/server/sonar-web/src/main/js/apps/metrics/metrics.js @@ -1,41 +1,41 @@ -define([ - './metric' -], function (Metric) { - - return Backbone.Collection.extend({ - model: Metric, - - url: function () { - return baseUrl + '/api/metrics/search'; - }, - - parse: function (r) { - this.total = r.total; - this.p = r.p; - this.ps = r.ps; - return r.metrics; - }, - - fetch: function (options) { - var opts = _.defaults(options || {}, { data: {} }); - this.q = opts.data.q; - opts.data.isCustom = true; - return this._super(opts); - }, - - fetchMore: function () { - var p = this.p + 1; - return this.fetch({ add: true, remove: false, data: { p: p, ps: this.ps, q: this.q } }); - }, - - refresh: function () { - return this.fetch({ reset: true, data: { q: this.q } }); - }, - - hasMore: function () { - return this.total > this.p * this.ps; - } - - }); +import _ from 'underscore'; +import Backbone from 'backbone'; +import Metric from './metric'; + +export default Backbone.Collection.extend({ + model: Metric, + + url: function () { + return baseUrl + '/api/metrics/search'; + }, + + parse: function (r) { + this.total = r.total; + this.p = r.p; + this.ps = r.ps; + return r.metrics; + }, + + fetch: function (options) { + var opts = _.defaults(options || {}, { data: {} }); + this.q = opts.data.q; + opts.data.isCustom = true; + return this._super(opts); + }, + + fetchMore: function () { + var p = this.p + 1; + return this.fetch({ add: true, remove: false, data: { p: p, ps: this.ps, q: this.q } }); + }, + + refresh: function () { + return this.fetch({ reset: true, data: { q: this.q } }); + }, + + hasMore: function () { + return this.total > this.p * this.ps; + } }); + + diff --git a/server/sonar-web/src/main/js/apps/metrics/update-view.js b/server/sonar-web/src/main/js/apps/metrics/update-view.js index 3dfea4a584e..8ccce5ce7d0 100644 --- a/server/sonar-web/src/main/js/apps/metrics/update-view.js +++ b/server/sonar-web/src/main/js/apps/metrics/update-view.js @@ -1,32 +1,30 @@ -define([ - './form-view' -], function (FormView) { +import FormView from './form-view'; - return FormView.extend({ - - sendRequest: function () { - var that = this; - this.model.set({ - key: this.$('#create-metric-key').val(), - name: this.$('#create-metric-name').val(), - description: this.$('#create-metric-description').val(), - domain: this.$('#create-metric-domain').val(), - type: this.$('#create-metric-type').val() - }); - this.disableForm(); - return this.model.save(null, { - statusCode: { - // do not show global error - 400: null - } - }).done(function () { - that.collection.refresh(); - that.destroy(); - }).fail(function (jqXHR) { - that.enableForm(); - that.showErrors(jqXHR.responseJSON.errors, jqXHR.responseJSON.warnings); - }); - } - }); +export default FormView.extend({ + sendRequest: function () { + var that = this; + this.model.set({ + key: this.$('#create-metric-key').val(), + name: this.$('#create-metric-name').val(), + description: this.$('#create-metric-description').val(), + domain: this.$('#create-metric-domain').val(), + type: this.$('#create-metric-type').val() + }); + this.disableForm(); + return this.model.save(null, { + statusCode: { + // do not show global error + 400: null + } + }).done(function () { + that.collection.refresh(); + that.destroy(); + }).fail(function (jqXHR) { + that.enableForm(); + that.showErrors(jqXHR.responseJSON.errors, jqXHR.responseJSON.warnings); + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/nav/component/component-nav-menu.jsx b/server/sonar-web/src/main/js/apps/nav/component/component-nav-menu.jsx index ae156463086..fd55fa80097 100644 --- a/server/sonar-web/src/main/js/apps/nav/component/component-nav-menu.jsx +++ b/server/sonar-web/src/main/js/apps/nav/component/component-nav-menu.jsx @@ -1,3 +1,4 @@ +import _ from 'underscore'; import React from 'react'; import DashboardNameMixin from '../dashboard-name-mixin'; import LinksMixin from '../links-mixin'; diff --git a/server/sonar-web/src/main/js/apps/nav/component/component-nav.jsx b/server/sonar-web/src/main/js/apps/nav/component/component-nav.jsx index 855482981d9..29d93a87b64 100644 --- a/server/sonar-web/src/main/js/apps/nav/component/component-nav.jsx +++ b/server/sonar-web/src/main/js/apps/nav/component/component-nav.jsx @@ -1,11 +1,10 @@ +import $ from 'jquery'; import React from 'react'; import ComponentNavFavorite from './component-nav-favorite'; import ComponentNavBreadcrumbs from './component-nav-breadcrumbs'; import ComponentNavMeta from './component-nav-meta'; import ComponentNavMenu from './component-nav-menu'; -let $ = jQuery; - export default React.createClass({ getInitialState() { return { component: {}, conf: {} }; diff --git a/server/sonar-web/src/main/js/apps/nav/global/global-nav-search.jsx b/server/sonar-web/src/main/js/apps/nav/global/global-nav-search.jsx index 157ba7b25f7..48fadbfe6eb 100644 --- a/server/sonar-web/src/main/js/apps/nav/global/global-nav-search.jsx +++ b/server/sonar-web/src/main/js/apps/nav/global/global-nav-search.jsx @@ -1,8 +1,7 @@ +import Backbone from 'backbone'; import React from 'react'; import SearchView from './search-view'; -let $ = jQuery; - function contains (root, node) { while (node) { if (node === root) { diff --git a/server/sonar-web/src/main/js/apps/nav/global/global-nav.jsx b/server/sonar-web/src/main/js/apps/nav/global/global-nav.jsx index 908033c73bf..ebbdc07db5c 100644 --- a/server/sonar-web/src/main/js/apps/nav/global/global-nav.jsx +++ b/server/sonar-web/src/main/js/apps/nav/global/global-nav.jsx @@ -1,3 +1,4 @@ +import $ from 'jquery'; import React from 'react'; import GlobalNavBranding from './global-nav-branding'; import GlobalNavMenu from './global-nav-menu'; @@ -5,8 +6,6 @@ import GlobalNavUser from './global-nav-user'; import GlobalNavSearch from './global-nav-search'; import ShortcutsHelpView from './shortcuts-help-view'; -let $ = jQuery; - export default React.createClass({ getInitialState() { return this.props; diff --git a/server/sonar-web/src/main/js/apps/nav/global/search-view.js b/server/sonar-web/src/main/js/apps/nav/global/search-view.js index e38787aba66..12e170da60b 100644 --- a/server/sonar-web/src/main/js/apps/nav/global/search-view.js +++ b/server/sonar-web/src/main/js/apps/nav/global/search-view.js @@ -1,232 +1,232 @@ -define([ - 'components/common/selectable-collection-view', - '../templates' -], function (SelectableCollectionView) { - - var $ = jQuery, - - SearchItemView = Marionette.ItemView.extend({ - tagName: 'li', - template: Templates['nav-search-item'], - - select: function () { - this.$el.addClass('active'); - }, - - deselect: function () { - this.$el.removeClass('active'); - }, - - submit: function () { - this.$('a')[0].click(); - }, - - serializeData: function () { - return _.extend(Marionette.ItemView.prototype.serializeData.apply(this, arguments), { - index: this.options.index - }); - } - }), - - SearchEmptyView = Marionette.ItemView.extend({ - tagName: 'li', - template: Templates['nav-search-empty'] - }), - - SearchResultsView = SelectableCollectionView.extend({ - className: 'menu', - tagName: 'ul', - childView: SearchItemView, - emptyView: SearchEmptyView - }); - - return Marionette.LayoutView.extend({ - className: 'navbar-search', - tagName: 'form', - template: Templates['nav-search'], - - regions: { - resultsRegion: '.js-search-results' - }, - - events: { - 'submit': 'onSubmit', - 'keydown .js-search-input': 'onKeyDown', - 'keyup .js-search-input': 'debouncedOnKeyUp' - }, - - initialize: function () { - var that = this; - this.results = new Backbone.Collection(); - this.favorite = []; - if (window.SS.user) { - this.fetchFavorite().always(function () { - that.resetResultsToDefault(); +import $ from 'jquery'; +import _ from 'underscore'; +import Backbone from 'backbone'; +import Marionette from 'backbone.marionette'; +import SelectableCollectionView from 'components/common/selectable-collection-view'; +import '../templates'; + +var SearchItemView = Marionette.ItemView.extend({ + tagName: 'li', + template: Templates['nav-search-item'], + + select: function () { + this.$el.addClass('active'); + }, + + deselect: function () { + this.$el.removeClass('active'); + }, + + submit: function () { + this.$('a')[0].click(); + }, + + serializeData: function () { + return _.extend(Marionette.ItemView.prototype.serializeData.apply(this, arguments), { + index: this.options.index }); - } else { - this.resetResultsToDefault(); - } - this.resultsView = new SearchResultsView({ collection: this.results }); - this.debouncedOnKeyUp = _.debounce(this.onKeyUp, 400); - this._bufferedValue = ''; - }, - - onRender: function () { - var that = this; - this.resultsRegion.show(this.resultsView); - setTimeout(function () { - that.$('.js-search-input').focus(); - }, 0); - }, - - onKeyDown: function (e) { - if (e.keyCode === 38) { - this.resultsView.selectPrev(); - return false; - } - if (e.keyCode === 40) { - this.resultsView.selectNext(); - return false; - } - if (e.keyCode === 13) { - this.resultsView.submitCurrent(); - return false; - } - if (e.keyCode === 27) { - this.options.hide(); - return false; } - }, - - onKeyUp: function () { - var value = this.$('.js-search-input').val(); - if (value === this._bufferedValue) { - return; - } - this._bufferedValue = this.$('.js-search-input').val(); - if (this.searchRequest != null && this.searchRequest.abort != null) { - this.searchRequest.abort(); - } - this.searchRequest = this.search(value); - }, - - onSubmit: function () { + }), + + SearchEmptyView = Marionette.ItemView.extend({ + tagName: 'li', + template: Templates['nav-search-empty'] + }), + + SearchResultsView = SelectableCollectionView.extend({ + className: 'menu', + tagName: 'ul', + childView: SearchItemView, + emptyView: SearchEmptyView + }); + +export default Marionette.LayoutView.extend({ + className: 'navbar-search', + tagName: 'form', + template: Templates['nav-search'], + + regions: { + resultsRegion: '.js-search-results' + }, + + events: { + 'submit': 'onSubmit', + 'keydown .js-search-input': 'onKeyDown', + 'keyup .js-search-input': 'debouncedOnKeyUp' + }, + + initialize: function () { + var that = this; + this.results = new Backbone.Collection(); + this.favorite = []; + if (window.SS.user) { + this.fetchFavorite().always(function () { + that.resetResultsToDefault(); + }); + } else { + this.resetResultsToDefault(); + } + this.resultsView = new SearchResultsView({ collection: this.results }); + this.debouncedOnKeyUp = _.debounce(this.onKeyUp, 400); + this._bufferedValue = ''; + }, + + onRender: function () { + var that = this; + this.resultsRegion.show(this.resultsView); + setTimeout(function () { + that.$('.js-search-input').focus(); + }, 0); + }, + + onKeyDown: function (e) { + if (e.keyCode === 38) { + this.resultsView.selectPrev(); + return false; + } + if (e.keyCode === 40) { + this.resultsView.selectNext(); + return false; + } + if (e.keyCode === 13) { + this.resultsView.submitCurrent(); return false; - }, + } + if (e.keyCode === 27) { + this.options.hide(); + return false; + } + }, - fetchFavorite: function () { - var that = this; - return $.get(baseUrl + '/api/favourites').done(function (r) { - that.favorite = r.map(function (f) { - var isFile = ['FIL', 'UTS'].indexOf(f.qualifier) !== -1; + onKeyUp: function () { + var value = this.$('.js-search-input').val(); + if (value === this._bufferedValue) { + return; + } + this._bufferedValue = this.$('.js-search-input').val(); + if (this.searchRequest != null && this.searchRequest.abort != null) { + this.searchRequest.abort(); + } + this.searchRequest = this.search(value); + }, + + onSubmit: function () { + return false; + }, + + fetchFavorite: function () { + var that = this; + return $.get(baseUrl + '/api/favourites').done(function (r) { + that.favorite = r.map(function (f) { + var isFile = ['FIL', 'UTS'].indexOf(f.qualifier) !== -1; + return { + url: baseUrl + '/dashboard/index?id=' + encodeURIComponent(f.key) + window.dashboardParameters(true), + name: isFile ? window.collapsedDirFromPath(f.lname) + window.fileFromPath(f.lname) : f.name, + icon: 'favorite' + }; + }); + that.favorite = _.sortBy(that.favorite, 'name'); + }); + }, + + resetResultsToDefault: function () { + var recentHistory = JSON.parse(localStorage.getItem('sonar_recent_history')), + history = (recentHistory || []).map(function (historyItem, index) { + var url = baseUrl + '/dashboard/index?id=' + encodeURIComponent(historyItem.key) + + window.dashboardParameters(true); return { - url: baseUrl + '/dashboard/index?id=' + encodeURIComponent(f.key) + window.dashboardParameters(true), - name: isFile ? window.collapsedDirFromPath(f.lname) + window.fileFromPath(f.lname) : f.name, - icon: 'favorite' + url: url, + name: historyItem.name, + q: historyItem.icon, + extra: index === 0 ? t('browsed_recently') : null + }; + }), + favorite = _.first(this.favorite, 6).map(function (f, index) { + return _.extend(f, { extra: index === 0 ? t('favorite') : null }); + }), + qualifiers = this.model.get('qualifiers').map(function (q, index) { + return { + url: baseUrl + '/all_projects?qualifier=' + encodeURIComponent(q), + name: t('qualifiers.all', q), + extra: index === 0 ? '' : null }; }); - that.favorite = _.sortBy(that.favorite, 'name'); - }); - }, - - resetResultsToDefault: function () { - var recentHistory = JSON.parse(localStorage.getItem('sonar_recent_history')), - history = (recentHistory || []).map(function (historyItem, index) { - var url = baseUrl + '/dashboard/index?id=' + encodeURIComponent(historyItem.key) + - window.dashboardParameters(true); - return { - url: url, - name: historyItem.name, - q: historyItem.icon, - extra: index === 0 ? t('browsed_recently') : null - }; - }), - favorite = _.first(this.favorite, 6).map(function (f, index) { - return _.extend(f, { extra: index === 0 ? t('favorite') : null }); - }), - qualifiers = this.model.get('qualifiers').map(function (q, index) { - return { - url: baseUrl + '/all_projects?qualifier=' + encodeURIComponent(q), - name: t('qualifiers.all', q), - extra: index === 0 ? '' : null - }; - }); - this.results.reset([].concat(history, favorite, qualifiers)); - }, - - search: function (q) { - if (q.length < 2) { - this.resetResultsToDefault(); - return; - } - var that = this, - url = baseUrl + '/api/components/suggestions', - options = { s: q }; - return $.get(url, options).done(function (r) { - var collection = []; - r.results.forEach(function (domain) { - domain.items.forEach(function (item, index) { - collection.push(_.extend(item, { - q: domain.q, - extra: index === 0 ? domain.name : null, - url: baseUrl + '/dashboard/index?id=' + encodeURIComponent(item.key) + window.dashboardParameters(true) - })); - }); - }); - that.results.reset([].concat( - that.getNavigationFindings(q), - that.getGlobalDashboardFindings(q), - that.getFavoriteFindings(q), - collection - )); - }); - }, - - getNavigationFindings: function (q) { - var DEFAULT_ITEMS = [ - { name: t('issues.page'), url: baseUrl + '/issues/search' }, - { name: t('layout.measures'), url: baseUrl + '/measures/search?qualifiers[]=TRK' }, - { name: t('coding_rules.page'), url: baseUrl + '/coding_rules' }, - { name: t('quality_profiles.page'), url: baseUrl + '/profiles' }, - { name: t('quality_gates.page'), url: baseUrl + '/quality_gates' }, - { name: t('comparison_global.page'), url: baseUrl + '/comparison' } - ], - customItems = []; - if (window.SS.isUserAdmin) { - customItems.push({ name: t('layout.settings'), url: baseUrl + '/settings' }); - } - var findings = [].concat(DEFAULT_ITEMS, customItems).filter(function (f) { - return f.name.match(new RegExp(q, 'i')); - }); - if (findings.length > 0) { - findings[0].extra = t('navigation'); - } - return _.first(findings, 6); - }, - - getGlobalDashboardFindings: function (q) { - var dashboards = this.model.get('globalDashboards') || [], - items = dashboards.map(function (d) { - return { name: d.name, url: baseUrl + '/dashboard/index?did=' + encodeURIComponent(d.key) }; - }); - var findings = items.filter(function (f) { - return f.name.match(new RegExp(q, 'i')); - }); - if (findings.length > 0) { - findings[0].extra = t('dashboard.global_dashboards'); - } - return _.first(findings, 6); - }, + this.results.reset([].concat(history, favorite, qualifiers)); + }, - getFavoriteFindings: function (q) { - var findings = this.favorite.filter(function (f) { - return f.name.match(new RegExp(q, 'i')); + search: function (q) { + if (q.length < 2) { + this.resetResultsToDefault(); + return; + } + var that = this, + url = baseUrl + '/api/components/suggestions', + options = { s: q }; + return $.get(url, options).done(function (r) { + var collection = []; + r.results.forEach(function (domain) { + domain.items.forEach(function (item, index) { + collection.push(_.extend(item, { + q: domain.q, + extra: index === 0 ? domain.name : null, + url: baseUrl + '/dashboard/index?id=' + encodeURIComponent(item.key) + window.dashboardParameters(true) + })); + }); }); - if (findings.length > 0) { - findings[0].extra = t('favorite'); - } - return _.first(findings, 6); + that.results.reset([].concat( + that.getNavigationFindings(q), + that.getGlobalDashboardFindings(q), + that.getFavoriteFindings(q), + collection + )); + }); + }, + + getNavigationFindings: function (q) { + var DEFAULT_ITEMS = [ + { name: t('issues.page'), url: baseUrl + '/issues/search' }, + { name: t('layout.measures'), url: baseUrl + '/measures/search?qualifiers[]=TRK' }, + { name: t('coding_rules.page'), url: baseUrl + '/coding_rules' }, + { name: t('quality_profiles.page'), url: baseUrl + '/profiles' }, + { name: t('quality_gates.page'), url: baseUrl + '/quality_gates' }, + { name: t('comparison_global.page'), url: baseUrl + '/comparison' } + ], + customItems = []; + if (window.SS.isUserAdmin) { + customItems.push({ name: t('layout.settings'), url: baseUrl + '/settings' }); + } + var findings = [].concat(DEFAULT_ITEMS, customItems).filter(function (f) { + return f.name.match(new RegExp(q, 'i')); + }); + if (findings.length > 0) { + findings[0].extra = t('navigation'); } - }); + return _.first(findings, 6); + }, + getGlobalDashboardFindings: function (q) { + var dashboards = this.model.get('globalDashboards') || [], + items = dashboards.map(function (d) { + return { name: d.name, url: baseUrl + '/dashboard/index?did=' + encodeURIComponent(d.key) }; + }); + var findings = items.filter(function (f) { + return f.name.match(new RegExp(q, 'i')); + }); + if (findings.length > 0) { + findings[0].extra = t('dashboard.global_dashboards'); + } + return _.first(findings, 6); + }, + + getFavoriteFindings: function (q) { + var findings = this.favorite.filter(function (f) { + return f.name.match(new RegExp(q, 'i')); + }); + if (findings.length > 0) { + findings[0].extra = t('favorite'); + } + return _.first(findings, 6); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/nav/global/shortcuts-help-view.js b/server/sonar-web/src/main/js/apps/nav/global/shortcuts-help-view.js index b016a734d8c..02807d5951f 100644 --- a/server/sonar-web/src/main/js/apps/nav/global/shortcuts-help-view.js +++ b/server/sonar-web/src/main/js/apps/nav/global/shortcuts-help-view.js @@ -1,11 +1,9 @@ -define([ - 'components/common/modals', - '../templates' -], function (ModalView) { - - return ModalView.extend({ - className: 'modal modal-large', - template: Templates['nav-shortcuts-help'] - }); +import ModalView from 'components/common/modals'; +import '../templates'; +export default ModalView.extend({ + className: 'modal modal-large', + template: Templates['nav-shortcuts-help'] }); + + diff --git a/server/sonar-web/src/main/js/apps/nav/links-mixin.jsx b/server/sonar-web/src/main/js/apps/nav/links-mixin.jsx index 7e9d76121aa..eb01839a8df 100644 --- a/server/sonar-web/src/main/js/apps/nav/links-mixin.jsx +++ b/server/sonar-web/src/main/js/apps/nav/links-mixin.jsx @@ -1,3 +1,4 @@ +import _ from 'underscore'; import React from 'react'; export default { diff --git a/server/sonar-web/src/main/js/apps/nav/settings/settings-nav.jsx b/server/sonar-web/src/main/js/apps/nav/settings/settings-nav.jsx index 760034e7384..d856844e271 100644 --- a/server/sonar-web/src/main/js/apps/nav/settings/settings-nav.jsx +++ b/server/sonar-web/src/main/js/apps/nav/settings/settings-nav.jsx @@ -1,8 +1,7 @@ +import $ from 'jquery'; import React from 'react'; import LinksMixin from '../links-mixin'; -let $ = jQuery; - export default React.createClass({ mixins: [LinksMixin], diff --git a/server/sonar-web/src/main/js/apps/project-permissions/apply-template-view.jsx b/server/sonar-web/src/main/js/apps/project-permissions/apply-template-view.jsx index 9bcd05d8e13..dbf1c26520f 100644 --- a/server/sonar-web/src/main/js/apps/project-permissions/apply-template-view.jsx +++ b/server/sonar-web/src/main/js/apps/project-permissions/apply-template-view.jsx @@ -1,4 +1,5 @@ import $ from 'jquery'; +import _ from 'underscore'; import ModalForm from '../../components/common/modal-form'; import {applyTemplateToProject} from '../../api/permissions'; import './templates'; diff --git a/server/sonar-web/src/main/js/apps/project-permissions/groups-view.js b/server/sonar-web/src/main/js/apps/project-permissions/groups-view.js index e5315e5dd14..ed88709054a 100644 --- a/server/sonar-web/src/main/js/apps/project-permissions/groups-view.js +++ b/server/sonar-web/src/main/js/apps/project-permissions/groups-view.js @@ -1,55 +1,54 @@ -define([ - 'components/common/modals', - 'components/common/select-list', - './templates' -], function (Modal) { +import _ from 'underscore'; +import Modal from 'components/common/modals'; +import 'components/common/select-list'; +import './templates'; - function getSearchUrl(permission, project) { - return baseUrl + '/api/permissions/groups?ps=100&permission=' + permission + '&projectId=' + project; - } - - return Modal.extend({ - template: Templates['project-permissions-groups'], +function getSearchUrl (permission, project) { + return baseUrl + '/api/permissions/groups?ps=100&permission=' + permission + '&projectId=' + project; +} - onRender: function () { - this._super(); - new window.SelectList({ - el: this.$('#project-permissions-groups'), - width: '100%', - readOnly: false, - focusSearch: false, - format: function (item) { - return item.name; - }, - queryParam: 'q', - searchUrl: getSearchUrl(this.options.permission, this.options.project), - selectUrl: baseUrl + '/api/permissions/add_group', - deselectUrl: baseUrl + '/api/permissions/remove_group', - extra: { - permission: this.options.permission, - projectId: this.options.project - }, - selectParameter: 'groupName', - selectParameterValue: 'name', - parse: function (r) { - this.more = false; - return r.groups; - } - }); - }, +export default Modal.extend({ + template: Templates['project-permissions-groups'], - onDestroy: function () { - if (this.options.refresh) { - this.options.refresh(); + onRender: function () { + this._super(); + new window.SelectList({ + el: this.$('#project-permissions-groups'), + width: '100%', + readOnly: false, + focusSearch: false, + format: function (item) { + return item.name; + }, + queryParam: 'q', + searchUrl: getSearchUrl(this.options.permission, this.options.project), + selectUrl: baseUrl + '/api/permissions/add_group', + deselectUrl: baseUrl + '/api/permissions/remove_group', + extra: { + permission: this.options.permission, + projectId: this.options.project + }, + selectParameter: 'groupName', + selectParameterValue: 'name', + parse: function (r) { + this.more = false; + return r.groups; } - this._super(); - }, + }); + }, - serializeData: function () { - return _.extend(Modal.prototype.serializeData.apply(this, arguments), { - projectName: this.options.projectName - }); + onDestroy: function () { + if (this.options.refresh) { + this.options.refresh(); } - }); + this._super(); + }, + serializeData: function () { + return _.extend(Modal.prototype.serializeData.apply(this, arguments), { + projectName: this.options.projectName + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/project-permissions/main-component.jsx b/server/sonar-web/src/main/js/apps/project-permissions/main-component.jsx index 2df3f3694a9..253952fbe26 100644 --- a/server/sonar-web/src/main/js/apps/project-permissions/main-component.jsx +++ b/server/sonar-web/src/main/js/apps/project-permissions/main-component.jsx @@ -1,9 +1,8 @@ +import $ from 'jquery'; import _ from 'underscore'; import React from 'react'; import PermissionsList from '../global-permissions/permissions-list'; -let $ = jQuery; - const PERMISSIONS_ORDER = ['user', 'codeviewer', 'issueadmin', 'admin']; export default React.createClass({ diff --git a/server/sonar-web/src/main/js/apps/project-permissions/search.jsx b/server/sonar-web/src/main/js/apps/project-permissions/search.jsx index 3506d78834b..6b90a16b7f5 100644 --- a/server/sonar-web/src/main/js/apps/project-permissions/search.jsx +++ b/server/sonar-web/src/main/js/apps/project-permissions/search.jsx @@ -1,3 +1,4 @@ +import _ from 'underscore'; import React from 'react'; export default React.createClass({ diff --git a/server/sonar-web/src/main/js/apps/project-permissions/users-view.js b/server/sonar-web/src/main/js/apps/project-permissions/users-view.js index 370db728ba1..31cbc91c653 100644 --- a/server/sonar-web/src/main/js/apps/project-permissions/users-view.js +++ b/server/sonar-web/src/main/js/apps/project-permissions/users-view.js @@ -1,53 +1,52 @@ -define([ - 'components/common/modals', - 'components/common/select-list', - './templates' -], function (Modal) { +import _ from 'underscore'; +import Modal from 'components/common/modals'; +import 'components/common/select-list'; +import './templates'; - return Modal.extend({ - template: Templates['project-permissions-users'], +export default Modal.extend({ + template: Templates['project-permissions-users'], - onRender: function () { - this._super(); - var searchUrl = baseUrl + '/api/permissions/users?ps=100&permission=' + this.options.permission + - '&projectId=' + this.options.project; - new window.SelectList({ - el: this.$('#project-permissions-users'), - width: '100%', - readOnly: false, - focusSearch: false, - format: function (item) { - return item.name + '
' + item.login + ''; - }, - queryParam: 'q', - searchUrl: searchUrl, - selectUrl: baseUrl + '/api/permissions/add_user', - deselectUrl: baseUrl + '/api/permissions/remove_user', - extra: { - permission: this.options.permission, - projectId: this.options.project - }, - selectParameter: 'login', - selectParameterValue: 'login', - parse: function (r) { - this.more = false; - return r.users; - } - }); - }, - - onDestroy: function () { - if (this.options.refresh) { - this.options.refresh(); + onRender: function () { + this._super(); + var searchUrl = baseUrl + '/api/permissions/users?ps=100&permission=' + this.options.permission + + '&projectId=' + this.options.project; + new window.SelectList({ + el: this.$('#project-permissions-users'), + width: '100%', + readOnly: false, + focusSearch: false, + format: function (item) { + return item.name + '
' + item.login + ''; + }, + queryParam: 'q', + searchUrl: searchUrl, + selectUrl: baseUrl + '/api/permissions/add_user', + deselectUrl: baseUrl + '/api/permissions/remove_user', + extra: { + permission: this.options.permission, + projectId: this.options.project + }, + selectParameter: 'login', + selectParameterValue: 'login', + parse: function (r) { + this.more = false; + return r.users; } - this._super(); - }, + }); + }, - serializeData: function () { - return _.extend(Modal.prototype.serializeData.apply(this, arguments), { - projectName: this.options.projectName - }); + onDestroy: function () { + if (this.options.refresh) { + this.options.refresh(); } - }); + this._super(); + }, + serializeData: function () { + return _.extend(Modal.prototype.serializeData.apply(this, arguments), { + projectName: this.options.projectName + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/provisioning/app.js b/server/sonar-web/src/main/js/apps/provisioning/app.js index aa754e5ba77..427179d6fec 100644 --- a/server/sonar-web/src/main/js/apps/provisioning/app.js +++ b/server/sonar-web/src/main/js/apps/provisioning/app.js @@ -1,47 +1,46 @@ -define([ - './layout', - './projects', - './header-view', - './search-view', - './list-view', - './list-footer-view' -], function (Layout, Projects, HeaderView, SearchView, ListView, ListFooterView) { - - var App = new Marionette.Application(), - init = function (options) { - // Layout - this.layout = new Layout({ el: options.el }); - this.layout.render(); - - // Collection - this.projects = new Projects(); - - // Header View - this.headerView = new HeaderView({ collection: this.projects }); - this.layout.headerRegion.show(this.headerView); - - // Search View - this.searchView = new SearchView({ collection: this.projects }); - this.layout.searchRegion.show(this.searchView); - - // List View - this.listView = new ListView({ collection: this.projects }); - this.layout.listRegion.show(this.listView); - - // List Footer View - this.listFooterView = new ListFooterView({ collection: this.projects }); - this.layout.listFooterRegion.show(this.listFooterView); - - // Go! - this.projects.fetch(); - }; - - App.on('start', function (options) { - window.requestMessages().done(function () { - init.call(App, options); - }); +import Marionette from 'backbone.marionette'; +import Layout from './layout'; +import Projects from './projects'; +import HeaderView from './header-view'; +import SearchView from './search-view'; +import ListView from './list-view'; +import ListFooterView from './list-footer-view'; + +var App = new Marionette.Application(), + init = function (options) { + // Layout + this.layout = new Layout({ el: options.el }); + this.layout.render(); + + // Collection + this.projects = new Projects(); + + // Header View + this.headerView = new HeaderView({ collection: this.projects }); + this.layout.headerRegion.show(this.headerView); + + // Search View + this.searchView = new SearchView({ collection: this.projects }); + this.layout.searchRegion.show(this.searchView); + + // List View + this.listView = new ListView({ collection: this.projects }); + this.layout.listRegion.show(this.listView); + + // List Footer View + this.listFooterView = new ListFooterView({ collection: this.projects }); + this.layout.listFooterRegion.show(this.listFooterView); + + // Go! + this.projects.fetch(); + }; + +App.on('start', function (options) { + window.requestMessages().done(function () { + init.call(App, options); }); +}); + +export default App; - return App; -}); diff --git a/server/sonar-web/src/main/js/apps/provisioning/bulk-delete-view.js b/server/sonar-web/src/main/js/apps/provisioning/bulk-delete-view.js index 731e3e163d2..6e6abfd127e 100644 --- a/server/sonar-web/src/main/js/apps/provisioning/bulk-delete-view.js +++ b/server/sonar-web/src/main/js/apps/provisioning/bulk-delete-view.js @@ -1,31 +1,30 @@ -define([ - 'components/common/modal-form', - './templates' -], function (ModalForm) { +import _ from 'underscore'; +import ModalForm from 'components/common/modal-form'; +import './templates'; - return ModalForm.extend({ - template: Templates['provisioning-bulk-delete'], +export default ModalForm.extend({ + template: Templates['provisioning-bulk-delete'], - onFormSubmit: function (e) { - this._super(e); - this.sendRequest(); - }, - - sendRequest: function () { - var that = this, - selected = _.pluck(this.collection.where({ selected: true }), 'id'); - return this.collection.bulkDelete(selected, { - statusCode: { - // do not show global error - 400: null - } - }).done(function () { - that.collection.refresh(); - that.destroy(); - }).fail(function (jqXHR) { - that.showErrors(jqXHR.responseJSON.errors, jqXHR.responseJSON.warnings); - }); - } - }); + onFormSubmit: function (e) { + this._super(e); + this.sendRequest(); + }, + sendRequest: function () { + var that = this, + selected = _.pluck(this.collection.where({ selected: true }), 'id'); + return this.collection.bulkDelete(selected, { + statusCode: { + // do not show global error + 400: null + } + }).done(function () { + that.collection.refresh(); + that.destroy(); + }).fail(function (jqXHR) { + that.showErrors(jqXHR.responseJSON.errors, jqXHR.responseJSON.warnings); + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/provisioning/create-view.js b/server/sonar-web/src/main/js/apps/provisioning/create-view.js index 2aba2786c3c..6c02f5a2281 100644 --- a/server/sonar-web/src/main/js/apps/provisioning/create-view.js +++ b/server/sonar-web/src/main/js/apps/provisioning/create-view.js @@ -1,31 +1,29 @@ -define([ - './project', - './form-view' -], function (Project, FormView) { +import Project from './project'; +import FormView from './form-view'; - return FormView.extend({ - - sendRequest: function () { - var that = this, - project = new Project({ - name: this.$('#create-project-name').val(), - branch: this.$('#create-project-branch').val(), - key: this.$('#create-project-key').val() - }); - this.disableForm(); - return project.save(null, { - statusCode: { - // do not show global error - 400: null - } - }).done(function () { - that.collection.refresh(); - that.destroy(); - }).fail(function (jqXHR) { - that.enableForm(); - that.showErrors([{ msg: jqXHR.responseJSON.err_msg }]); - }); - } - }); +export default FormView.extend({ + sendRequest: function () { + var that = this, + project = new Project({ + name: this.$('#create-project-name').val(), + branch: this.$('#create-project-branch').val(), + key: this.$('#create-project-key').val() + }); + this.disableForm(); + return project.save(null, { + statusCode: { + // do not show global error + 400: null + } + }).done(function () { + that.collection.refresh(); + that.destroy(); + }).fail(function (jqXHR) { + that.enableForm(); + that.showErrors([{ msg: jqXHR.responseJSON.err_msg }]); + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/provisioning/delete-view.js b/server/sonar-web/src/main/js/apps/provisioning/delete-view.js index dd503c4b1a4..d4176097d27 100644 --- a/server/sonar-web/src/main/js/apps/provisioning/delete-view.js +++ b/server/sonar-web/src/main/js/apps/provisioning/delete-view.js @@ -1,32 +1,30 @@ -define([ - 'components/common/modal-form', - './templates' -], function (ModalForm) { +import ModalForm from 'components/common/modal-form'; +import './templates'; - return ModalForm.extend({ - template: Templates['provisioning-delete'], +export default ModalForm.extend({ + template: Templates['provisioning-delete'], - onFormSubmit: function (e) { - this._super(e); - this.sendRequest(); - }, - - sendRequest: function () { - var that = this, - collection = this.model.collection; - return this.model.destroy({ - wait: true, - statusCode: { - // do not show global error - 400: null - } - }).done(function () { - collection.refresh(); - that.destroy(); - }).fail(function (jqXHR) { - that.showErrors(jqXHR.responseJSON.errors, jqXHR.responseJSON.warnings); - }); - } - }); + onFormSubmit: function (e) { + this._super(e); + this.sendRequest(); + }, + sendRequest: function () { + var that = this, + collection = this.model.collection; + return this.model.destroy({ + wait: true, + statusCode: { + // do not show global error + 400: null + } + }).done(function () { + collection.refresh(); + that.destroy(); + }).fail(function (jqXHR) { + that.showErrors(jqXHR.responseJSON.errors, jqXHR.responseJSON.warnings); + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/provisioning/form-view.js b/server/sonar-web/src/main/js/apps/provisioning/form-view.js index bb0fc0bcef5..525be213f49 100644 --- a/server/sonar-web/src/main/js/apps/provisioning/form-view.js +++ b/server/sonar-web/src/main/js/apps/provisioning/form-view.js @@ -1,26 +1,24 @@ -define([ - 'components/common/modal-form', - './templates' -], function (ModalForm) { +import ModalForm from 'components/common/modal-form'; +import './templates'; - return ModalForm.extend({ - template: Templates['provisioning-form'], +export default ModalForm.extend({ + template: Templates['provisioning-form'], - onRender: function () { - this._super(); - this.$('[data-toggle="tooltip"]').tooltip({ container: 'body', placement: 'bottom' }); - }, + onRender: function () { + this._super(); + this.$('[data-toggle="tooltip"]').tooltip({ container: 'body', placement: 'bottom' }); + }, - onDestroy: function () { - this._super(); - this.$('[data-toggle="tooltip"]').tooltip('destroy'); - }, + onDestroy: function () { + this._super(); + this.$('[data-toggle="tooltip"]').tooltip('destroy'); + }, - onFormSubmit: function (e) { - this._super(e); - this.sendRequest(); - } - - }); + onFormSubmit: function (e) { + this._super(e); + this.sendRequest(); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/provisioning/header-view.js b/server/sonar-web/src/main/js/apps/provisioning/header-view.js index 37165494eac..8fd88483e9b 100644 --- a/server/sonar-web/src/main/js/apps/provisioning/header-view.js +++ b/server/sonar-web/src/main/js/apps/provisioning/header-view.js @@ -1,49 +1,48 @@ -define([ - './create-view', - './bulk-delete-view', - './templates' -], function (CreateView, BulkDeleteView) { - - return Marionette.ItemView.extend({ - template: Templates['provisioning-header'], - - collectionEvents: { - 'change:selected': 'toggleDeleteButton', - 'reset': 'toggleDeleteButton' - }, - - events: { - 'click #provisioning-create': 'onCreateClick', - 'click #provisioning-bulk-delete': 'onBulkDeleteClick' - }, - - onCreateClick: function (e) { - e.preventDefault(); - this.createProject(); - }, - - onBulkDeleteClick: function (e) { - e.preventDefault(); - this.bulkDelete(); - }, - - createProject: function () { - new CreateView({ - collection: this.collection - }).render(); - }, - - bulkDelete: function () { - new BulkDeleteView({ - collection: this.collection - }).render(); - }, - - toggleDeleteButton: function () { - var selectedCount = this.collection.where({ selected: true }).length, - someSelected = selectedCount > 0; - this.$('#provisioning-bulk-delete').prop('disabled', !someSelected); - } - }); - +import Marionette from 'backbone.marionette'; +import CreateView from './create-view'; +import BulkDeleteView from './bulk-delete-view'; +import './templates'; + +export default Marionette.ItemView.extend({ + template: Templates['provisioning-header'], + + collectionEvents: { + 'change:selected': 'toggleDeleteButton', + 'reset': 'toggleDeleteButton' + }, + + events: { + 'click #provisioning-create': 'onCreateClick', + 'click #provisioning-bulk-delete': 'onBulkDeleteClick' + }, + + onCreateClick: function (e) { + e.preventDefault(); + this.createProject(); + }, + + onBulkDeleteClick: function (e) { + e.preventDefault(); + this.bulkDelete(); + }, + + createProject: function () { + new CreateView({ + collection: this.collection + }).render(); + }, + + bulkDelete: function () { + new BulkDeleteView({ + collection: this.collection + }).render(); + }, + + toggleDeleteButton: function () { + var selectedCount = this.collection.where({ selected: true }).length, + someSelected = selectedCount > 0; + this.$('#provisioning-bulk-delete').prop('disabled', !someSelected); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/provisioning/layout.js b/server/sonar-web/src/main/js/apps/provisioning/layout.js index 31b67e8b774..60bf7f209ca 100644 --- a/server/sonar-web/src/main/js/apps/provisioning/layout.js +++ b/server/sonar-web/src/main/js/apps/provisioning/layout.js @@ -1,16 +1,15 @@ -define([ - './templates' -], function () { +import Marionette from 'backbone.marionette'; +import './templates'; - return Marionette.LayoutView.extend({ - template: Templates['provisioning-layout'], - - regions: { - headerRegion: '#provisioning-header', - searchRegion: '#provisioning-search', - listRegion: '#provisioning-list', - listFooterRegion: '#provisioning-list-footer' - } - }); +export default Marionette.LayoutView.extend({ + template: Templates['provisioning-layout'], + regions: { + headerRegion: '#provisioning-header', + searchRegion: '#provisioning-search', + listRegion: '#provisioning-list', + listFooterRegion: '#provisioning-list-footer' + } }); + + diff --git a/server/sonar-web/src/main/js/apps/provisioning/list-footer-view.js b/server/sonar-web/src/main/js/apps/provisioning/list-footer-view.js index 902b9322372..87fdbd793c9 100644 --- a/server/sonar-web/src/main/js/apps/provisioning/list-footer-view.js +++ b/server/sonar-web/src/main/js/apps/provisioning/list-footer-view.js @@ -1,34 +1,34 @@ -define([ - './templates' -], function () { - - return Marionette.ItemView.extend({ - template: Templates['provisioning-list-footer'], - - collectionEvents: { - 'all': 'render' - }, - - events: { - 'click #provisioning-fetch-more': 'onMoreClick' - }, - - onMoreClick: function (e) { - e.preventDefault(); - this.fetchMore(); - }, - - fetchMore: function () { - this.collection.fetchMore(); - }, - - serializeData: function () { - return _.extend(this._super(), { - total: this.collection.total, - count: this.collection.length, - more: this.collection.hasMore() - }); - } - }); +import _ from 'underscore'; +import Marionette from 'backbone.marionette'; +import './templates'; +export default Marionette.ItemView.extend({ + template: Templates['provisioning-list-footer'], + + collectionEvents: { + 'all': 'render' + }, + + events: { + 'click #provisioning-fetch-more': 'onMoreClick' + }, + + onMoreClick: function (e) { + e.preventDefault(); + this.fetchMore(); + }, + + fetchMore: function () { + this.collection.fetchMore(); + }, + + serializeData: function () { + return _.extend(this._super(), { + total: this.collection.total, + count: this.collection.length, + more: this.collection.hasMore() + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/provisioning/list-item-view.js b/server/sonar-web/src/main/js/apps/provisioning/list-item-view.js index ead9b009ca3..41959c7439d 100644 --- a/server/sonar-web/src/main/js/apps/provisioning/list-item-view.js +++ b/server/sonar-web/src/main/js/apps/provisioning/list-item-view.js @@ -1,52 +1,51 @@ -define([ - './delete-view', - './templates' -], function (DeleteView) { - - return Marionette.ItemView.extend({ - tagName: 'li', - className: 'panel panel-vertical', - template: Templates['provisioning-list-item'], - - modelEvents: { - 'change:selected': 'onSelectedChange' - }, - - events: { - 'click .js-toggle': 'onToggleClick', - 'click .js-project-delete': 'onDeleteClick' - }, - - onRender: function () { - this.$el.attr('data-id', this.model.id); - this.$('[data-toggle="tooltip"]').tooltip({ container: 'body', placement: 'bottom' }); - }, - - onDestroy: function () { - this.$('[data-toggle="tooltip"]').tooltip('destroy'); - }, - - onToggleClick: function (e) { - e.preventDefault(); - this.toggle(); - }, - - onDeleteClick: function (e) { - e.preventDefault(); - this.deleteProject(); - }, - - onSelectedChange: function () { - this.$('.js-toggle').toggleClass('icon-checkbox-checked', this.model.get('selected')); - }, - - toggle: function () { - this.model.toggle(); - }, - - deleteProject: function () { - new DeleteView({ model: this.model }).render(); - } - }); - +import Marionette from 'backbone.marionette'; +import DeleteView from './delete-view'; +import './templates'; + +export default Marionette.ItemView.extend({ + tagName: 'li', + className: 'panel panel-vertical', + template: Templates['provisioning-list-item'], + + modelEvents: { + 'change:selected': 'onSelectedChange' + }, + + events: { + 'click .js-toggle': 'onToggleClick', + 'click .js-project-delete': 'onDeleteClick' + }, + + onRender: function () { + this.$el.attr('data-id', this.model.id); + this.$('[data-toggle="tooltip"]').tooltip({ container: 'body', placement: 'bottom' }); + }, + + onDestroy: function () { + this.$('[data-toggle="tooltip"]').tooltip('destroy'); + }, + + onToggleClick: function (e) { + e.preventDefault(); + this.toggle(); + }, + + onDeleteClick: function (e) { + e.preventDefault(); + this.deleteProject(); + }, + + onSelectedChange: function () { + this.$('.js-toggle').toggleClass('icon-checkbox-checked', this.model.get('selected')); + }, + + toggle: function () { + this.model.toggle(); + }, + + deleteProject: function () { + new DeleteView({ model: this.model }).render(); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/provisioning/list-view.js b/server/sonar-web/src/main/js/apps/provisioning/list-view.js index 24878864d30..695bf2ac034 100644 --- a/server/sonar-web/src/main/js/apps/provisioning/list-view.js +++ b/server/sonar-web/src/main/js/apps/provisioning/list-view.js @@ -1,11 +1,10 @@ -define([ - './list-item-view', - './templates' -], function (ListItemView) { - - return Marionette.CollectionView.extend({ - tagName: 'ul', - childView: ListItemView - }); +import Marionette from 'backbone.marionette'; +import ListItemView from './list-item-view'; +import './templates'; +export default Marionette.CollectionView.extend({ + tagName: 'ul', + childView: ListItemView }); + + diff --git a/server/sonar-web/src/main/js/apps/provisioning/project.js b/server/sonar-web/src/main/js/apps/provisioning/project.js index fa34df605f2..b709f02695b 100644 --- a/server/sonar-web/src/main/js/apps/provisioning/project.js +++ b/server/sonar-web/src/main/js/apps/provisioning/project.js @@ -1,38 +1,39 @@ -define(function () { +import _ from 'underscore'; +import Backbone from 'backbone'; - return Backbone.Model.extend({ - idAttribute: 'uuid', +export default Backbone.Model.extend({ + idAttribute: 'uuid', - defaults: { - selected: false - }, + defaults: { + selected: false + }, - urlRoot: function () { - return baseUrl + '/api/projects'; - }, + urlRoot: function () { + return baseUrl + '/api/projects'; + }, - sync: function (method, model, options) { - var opts = options || {}; - if (method === 'create') { - _.defaults(opts, { - url: this.urlRoot() + '/create', - type: 'POST', - data: _.pick(model.toJSON(), 'key', 'name', 'branch') - }); - } - if (method === 'delete') { - _.defaults(opts, { - url: this.urlRoot() + '/bulk_delete', - type: 'POST', - data: { ids: this.id } - }); - } - return Backbone.ajax(opts); - }, - - toggle: function () { - this.set({ selected: !this.get('selected') }); + sync: function (method, model, options) { + var opts = options || {}; + if (method === 'create') { + _.defaults(opts, { + url: this.urlRoot() + '/create', + type: 'POST', + data: _.pick(model.toJSON(), 'key', 'name', 'branch') + }); + } + if (method === 'delete') { + _.defaults(opts, { + url: this.urlRoot() + '/bulk_delete', + type: 'POST', + data: { ids: this.id } + }); } - }); + return Backbone.ajax(opts); + }, + toggle: function () { + this.set({ selected: !this.get('selected') }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/provisioning/projects.js b/server/sonar-web/src/main/js/apps/provisioning/projects.js index 05a59f822af..8e31d6a2a04 100644 --- a/server/sonar-web/src/main/js/apps/provisioning/projects.js +++ b/server/sonar-web/src/main/js/apps/provisioning/projects.js @@ -1,49 +1,49 @@ -define([ - './project' -], function (Project) { - - return Backbone.Collection.extend({ - model: Project, - - url: function () { - return baseUrl + '/api/projects/provisioned'; - }, - - parse: function (r) { - this.total = r.total; - this.p = r.p; - this.ps = r.ps; - return r.projects; - }, - - fetch: function (options) { - var d = (options && options.data) || {}; - this.q = d.q; - return this._super(options); - }, - - fetchMore: function () { - var p = this.p + 1; - return this.fetch({ add: true, remove: false, data: { p: p, ps: this.ps, q: this.q } }); - }, - - refresh: function () { - return this.fetch({ reset: true, data: { q: this.q } }); - }, - - hasMore: function () { - return this.total > this.p * this.ps; - }, - - bulkDelete: function (ids, options) { - var opts = _.extend({}, options, { - type: 'POST', - url: baseUrl + '/api/projects/bulk_delete', - data: { ids: ids.join() } - }); - return Backbone.ajax(opts); - } - - }); +import _ from 'underscore'; +import Backbone from 'backbone'; +import Project from './project'; + +export default Backbone.Collection.extend({ + model: Project, + + url: function () { + return baseUrl + '/api/projects/provisioned'; + }, + + parse: function (r) { + this.total = r.total; + this.p = r.p; + this.ps = r.ps; + return r.projects; + }, + + fetch: function (options) { + var d = (options && options.data) || {}; + this.q = d.q; + return this._super(options); + }, + + fetchMore: function () { + var p = this.p + 1; + return this.fetch({ add: true, remove: false, data: { p: p, ps: this.ps, q: this.q } }); + }, + + refresh: function () { + return this.fetch({ reset: true, data: { q: this.q } }); + }, + + hasMore: function () { + return this.total > this.p * this.ps; + }, + + bulkDelete: function (ids, options) { + var opts = _.extend({}, options, { + type: 'POST', + url: baseUrl + '/api/projects/bulk_delete', + data: { ids: ids.join() } + }); + return Backbone.ajax(opts); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/provisioning/search-view.js b/server/sonar-web/src/main/js/apps/provisioning/search-view.js index 55c0fafc4fb..2b926a05dbf 100644 --- a/server/sonar-web/src/main/js/apps/provisioning/search-view.js +++ b/server/sonar-web/src/main/js/apps/provisioning/search-view.js @@ -1,101 +1,101 @@ -define([ - './templates' -], function () { - - return Marionette.ItemView.extend({ - template: Templates['provisioning-search'], - - collectionEvents: { - 'change:selected': 'onSelectedChange', - 'reset': 'onSelectedChange' - }, - - events: { - 'click .js-toggle-selection': 'onToggleSelectionClick', - 'submit #provisioning-search-form': 'onFormSubmit', - 'search #provisioning-search-query': 'debouncedOnKeyUp', - 'keyup #provisioning-search-query': 'debouncedOnKeyUp' - }, - - initialize: function () { - this._bufferedValue = null; - this.debouncedOnKeyUp = _.debounce(this.onKeyUp, 400); - }, - - onRender: function () { - this.delegateEvents(); - }, - - onFormSubmit: function (e) { - e.preventDefault(); - this.debouncedOnKeyUp(); - }, - - onKeyUp: function () { - var q = this.getQuery(); - if (q === this._bufferedValue) { - return; - } - this._bufferedValue = this.getQuery(); - if (this.searchRequest != null) { - this.searchRequest.abort(); - } - this.searchRequest = this.search(q); - }, - - onSelectedChange: function () { - var projectsCount = this.collection.length, - selectedCount = this.collection.where({ selected: true }).length, - allSelected = projectsCount > 0 && projectsCount === selectedCount, - someSelected = !allSelected && selectedCount > 0; - this.$('.js-toggle-selection') - .toggleClass('icon-checkbox-checked', allSelected || someSelected) - .toggleClass('icon-checkbox-single', someSelected); - }, - - onToggleSelectionClick: function (e) { - e.preventDefault(); - this.toggleSelection(); - }, - - toggleSelection: function () { - var selectedCount = this.collection.where({ selected: true }).length, - someSelected = selectedCount > 0; - return someSelected ? this.selectNone() : this.selectAll(); - }, - - selectNone: function () { - this.collection.where({ selected: true }).forEach(function (project) { - project.set({ selected: false }); - }); - }, - - selectAll: function () { - this.collection.forEach(function (project) { - project.set({ selected: true }); - }); - }, - - getQuery: function () { - return this.$('#provisioning-search-query').val(); - }, - - search: function (q) { - this.selectNone(); - return this.collection.fetch({ reset: true, data: { q: q } }); - }, - - serializeData: function () { - var projectsCount = this.collection.length, - selectedCount = this.collection.where({ selected: true }).length, - allSelected = projectsCount > 0 && projectsCount === selectedCount, - someSelected = !allSelected && selectedCount > 0; - return _.extend(this._super(), { - selectedCount: selectedCount, - allSelected: allSelected, - someSelected: someSelected - }); +import _ from 'underscore'; +import Marionette from 'backbone.marionette'; +import './templates'; + +export default Marionette.ItemView.extend({ + template: Templates['provisioning-search'], + + collectionEvents: { + 'change:selected': 'onSelectedChange', + 'reset': 'onSelectedChange' + }, + + events: { + 'click .js-toggle-selection': 'onToggleSelectionClick', + 'submit #provisioning-search-form': 'onFormSubmit', + 'search #provisioning-search-query': 'debouncedOnKeyUp', + 'keyup #provisioning-search-query': 'debouncedOnKeyUp' + }, + + initialize: function () { + this._bufferedValue = null; + this.debouncedOnKeyUp = _.debounce(this.onKeyUp, 400); + }, + + onRender: function () { + this.delegateEvents(); + }, + + onFormSubmit: function (e) { + e.preventDefault(); + this.debouncedOnKeyUp(); + }, + + onKeyUp: function () { + var q = this.getQuery(); + if (q === this._bufferedValue) { + return; } - }); - + this._bufferedValue = this.getQuery(); + if (this.searchRequest != null) { + this.searchRequest.abort(); + } + this.searchRequest = this.search(q); + }, + + onSelectedChange: function () { + var projectsCount = this.collection.length, + selectedCount = this.collection.where({ selected: true }).length, + allSelected = projectsCount > 0 && projectsCount === selectedCount, + someSelected = !allSelected && selectedCount > 0; + this.$('.js-toggle-selection') + .toggleClass('icon-checkbox-checked', allSelected || someSelected) + .toggleClass('icon-checkbox-single', someSelected); + }, + + onToggleSelectionClick: function (e) { + e.preventDefault(); + this.toggleSelection(); + }, + + toggleSelection: function () { + var selectedCount = this.collection.where({ selected: true }).length, + someSelected = selectedCount > 0; + return someSelected ? this.selectNone() : this.selectAll(); + }, + + selectNone: function () { + this.collection.where({ selected: true }).forEach(function (project) { + project.set({ selected: false }); + }); + }, + + selectAll: function () { + this.collection.forEach(function (project) { + project.set({ selected: true }); + }); + }, + + getQuery: function () { + return this.$('#provisioning-search-query').val(); + }, + + search: function (q) { + this.selectNone(); + return this.collection.fetch({ reset: true, data: { q: q } }); + }, + + serializeData: function () { + var projectsCount = this.collection.length, + selectedCount = this.collection.where({ selected: true }).length, + allSelected = projectsCount > 0 && projectsCount === selectedCount, + someSelected = !allSelected && selectedCount > 0; + return _.extend(this._super(), { + selectedCount: selectedCount, + allSelected: allSelected, + someSelected: someSelected + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/quality-gates/actions-view.js b/server/sonar-web/src/main/js/apps/quality-gates/actions-view.js index 156c7d88104..62d27477f50 100644 --- a/server/sonar-web/src/main/js/apps/quality-gates/actions-view.js +++ b/server/sonar-web/src/main/js/apps/quality-gates/actions-view.js @@ -1,27 +1,27 @@ -define([ - './create-view', - './templates' -], function (CreateView) { +import _ from 'underscore'; +import Marionette from 'backbone.marionette'; +import CreateView from './create-view'; +import './templates'; - return Marionette.ItemView.extend({ - template: Templates['quality-gate-actions'], +export default Marionette.ItemView.extend({ + template: Templates['quality-gate-actions'], - events: { - 'click #quality-gate-add': 'add' - }, + events: { + 'click #quality-gate-add': 'add' + }, - add: function (e) { - e.preventDefault(); - new CreateView({ - collection: this.collection - }).render(); - }, - - serializeData: function () { - return _.extend(Marionette.ItemView.prototype.serializeData.apply(this, arguments), { - canEdit: this.options.canEdit - }); - } - }); + add: function (e) { + e.preventDefault(); + new CreateView({ + collection: this.collection + }).render(); + }, + serializeData: function () { + return _.extend(Marionette.ItemView.prototype.serializeData.apply(this, arguments), { + canEdit: this.options.canEdit + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/quality-gates/app.js b/server/sonar-web/src/main/js/apps/quality-gates/app.js index 6f939c9aa24..3dc3eece7f6 100644 --- a/server/sonar-web/src/main/js/apps/quality-gates/app.js +++ b/server/sonar-web/src/main/js/apps/quality-gates/app.js @@ -1,62 +1,62 @@ -define([ - './gates', - './gates-view', - './actions-view', - './router', - './layout', - './controller' -], function (Gates, GatesView, ActionsView, Router, Layout, Controller) { - - var $ = jQuery, - App = new Marionette.Application(); - - var init = function (options) { - // Layout - this.layout = new Layout({ el: options.el }); - this.layout.render(); - $('#footer').addClass('search-navigator-footer'); - - // Gates List - this.gates = new Gates(); - - // Controller - this.controller = new Controller({ app: this }); - - // Header - this.actionsView = new ActionsView({ - canEdit: this.canEdit, - collection: this.gates - }); - this.layout.actionsRegion.show(this.actionsView); +import $ from 'jquery'; +import Backbone from 'backbone'; +import Marionette from 'backbone.marionette'; +import Gates from './gates'; +import GatesView from './gates-view'; +import ActionsView from './actions-view'; +import Router from './router'; +import Layout from './layout'; +import Controller from './controller'; + +var App = new Marionette.Application(); + +var init = function (options) { + // Layout + this.layout = new Layout({ el: options.el }); + this.layout.render(); + $('#footer').addClass('search-navigator-footer'); + + // Gates List + this.gates = new Gates(); + + // Controller + this.controller = new Controller({ app: this }); + + // Header + this.actionsView = new ActionsView({ + canEdit: this.canEdit, + collection: this.gates + }); + this.layout.actionsRegion.show(this.actionsView); - // List - this.gatesView = new GatesView({ - canEdit: this.canEdit, - collection: this.gates - }); - this.layout.resultsRegion.show(this.gatesView); + // List + this.gatesView = new GatesView({ + canEdit: this.canEdit, + collection: this.gates + }); + this.layout.resultsRegion.show(this.gatesView); - // Router - this.router = new Router({ app: this }); - Backbone.history.start({ - pushState: true, - root: options.urlRoot - }); - }; - - var appXHR = $.get(baseUrl + '/api/qualitygates/app') - .done(function (r) { - App.canEdit = r.edit; - App.periods = r.periods; - App.metrics = r.metrics; - }); - - App.on('start', function (options) { - $.when(window.requestMessages(), appXHR).done(function () { - init.call(App, options); - }); + // Router + this.router = new Router({ app: this }); + Backbone.history.start({ + pushState: true, + root: options.urlRoot }); +}; - return App; +var appXHR = $.get(baseUrl + '/api/qualitygates/app') + .done(function (r) { + App.canEdit = r.edit; + App.periods = r.periods; + App.metrics = r.metrics; + }); +App.on('start', function (options) { + $.when(window.requestMessages(), appXHR).done(function () { + init.call(App, options); + }); }); + +export default App; + + diff --git a/server/sonar-web/src/main/js/apps/quality-gates/condition.js b/server/sonar-web/src/main/js/apps/quality-gates/condition.js index 9ca451ee5a0..0a7787d40ec 100644 --- a/server/sonar-web/src/main/js/apps/quality-gates/condition.js +++ b/server/sonar-web/src/main/js/apps/quality-gates/condition.js @@ -1,47 +1,47 @@ -define(function () { - - return Backbone.Model.extend({ - - defaults: { - period: 0 - }, - - url: function () { - return baseUrl + '/api/qualitygates'; - }, - - createUrl: function () { - return this.url() + '/create_condition'; - }, - - updateUrl: function () { - return this.url() + '/update_condition'; - }, - - deleteUrl: function () { - return this.url() + '/delete_condition'; - }, - - sync: function (method, model, options) { - var opts = options || {}; - opts.type = 'POST'; - if (method === 'create') { - opts.url = this.createUrl(); - opts.data = model.toJSON(); - } - if (method === 'update') { - opts.url = this.updateUrl(); - opts.data = model.toJSON(); - } - if (method === 'delete') { - opts.url = this.deleteUrl(); - opts.data = { id: model.id }; - } - if (opts.data.period === '0') { - delete opts.data.period; - } - return Backbone.ajax(opts); - } - }); +import Backbone from 'backbone'; + +export default Backbone.Model.extend({ + + defaults: { + period: 0 + }, + + url: function () { + return baseUrl + '/api/qualitygates'; + }, + + createUrl: function () { + return this.url() + '/create_condition'; + }, + + updateUrl: function () { + return this.url() + '/update_condition'; + }, + + deleteUrl: function () { + return this.url() + '/delete_condition'; + }, + sync: function (method, model, options) { + var opts = options || {}; + opts.type = 'POST'; + if (method === 'create') { + opts.url = this.createUrl(); + opts.data = model.toJSON(); + } + if (method === 'update') { + opts.url = this.updateUrl(); + opts.data = model.toJSON(); + } + if (method === 'delete') { + opts.url = this.deleteUrl(); + opts.data = { id: model.id }; + } + if (opts.data.period === '0') { + delete opts.data.period; + } + return Backbone.ajax(opts); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/quality-gates/conditions.js b/server/sonar-web/src/main/js/apps/quality-gates/conditions.js index 49cbb23f069..0307ebf0cb7 100644 --- a/server/sonar-web/src/main/js/apps/quality-gates/conditions.js +++ b/server/sonar-web/src/main/js/apps/quality-gates/conditions.js @@ -1,10 +1,9 @@ -define([ - './condition' -], function (Condition) { - - return Backbone.Collection.extend({ - model: Condition, - comparator: 'metric' - }); +import Backbone from 'backbone'; +import Condition from './condition'; +export default Backbone.Collection.extend({ + model: Condition, + comparator: 'metric' }); + + diff --git a/server/sonar-web/src/main/js/apps/quality-gates/controller.js b/server/sonar-web/src/main/js/apps/quality-gates/controller.js index 890adc1ad8b..a1589af3b5a 100644 --- a/server/sonar-web/src/main/js/apps/quality-gates/controller.js +++ b/server/sonar-web/src/main/js/apps/quality-gates/controller.js @@ -1,65 +1,64 @@ -define([ - './gate', - './details-view', - './header-view' -], function (Gate, DetailsView, HeaderView) { +import _ from 'underscore'; +import Marionette from 'backbone.marionette'; +import DetailsView from './details-view'; +import HeaderView from './header-view'; - return Marionette.Controller.extend({ +export default Marionette.Controller.extend({ - initialize: function (options) { - this.app = options.app; - this.canEdit = this.app.canEdit; - this.listenTo(this.app.gates, 'select', this.onSelect); - this.listenTo(this.app.gates, 'destroy', this.onDestroy); - }, + initialize: function (options) { + this.app = options.app; + this.canEdit = this.app.canEdit; + this.listenTo(this.app.gates, 'select', this.onSelect); + this.listenTo(this.app.gates, 'destroy', this.onDestroy); + }, - index: function () { - this.app.gates.fetch(); - }, + index: function () { + this.app.gates.fetch(); + }, - show: function (id) { - var that = this; - this.app.gates.fetch().done(function () { - var gate = that.app.gates.get(id); - if (gate != null) { - gate.trigger('select', gate, { trigger: false }); - } - }); - }, - - onSelect: function (gate, options) { - var that = this, - route = 'show/' + gate.id, - opts = _.defaults(options || {}, { trigger: true }); - if (opts.trigger) { - this.app.router.navigate(route); + show: function (id) { + var that = this; + this.app.gates.fetch().done(function () { + var gate = that.app.gates.get(id); + if (gate != null) { + gate.trigger('select', gate, { trigger: false }); } - this.app.gatesView.highlight(gate.id); - gate.fetch().done(function () { - var headerView = new HeaderView({ - model: gate, - canEdit: that.canEdit - }); - that.app.layout.headerRegion.show(headerView); + }); + }, - var detailsView = new DetailsView({ - model: gate, - canEdit: that.canEdit, - metrics: that.app.metrics, - periods: that.app.periods - }); - that.app.layout.detailsRegion.show(detailsView); + onSelect: function (gate, options) { + var that = this, + route = 'show/' + gate.id, + opts = _.defaults(options || {}, { trigger: true }); + if (opts.trigger) { + this.app.router.navigate(route); + } + this.app.gatesView.highlight(gate.id); + gate.fetch().done(function () { + var headerView = new HeaderView({ + model: gate, + canEdit: that.canEdit }); - }, + that.app.layout.headerRegion.show(headerView); - onDestroy: function () { - this.app.router.navigate(''); - this.app.layout.headerRegion.reset(); - this.app.layout.detailsRegion.reset(); - this.app.layout.renderIntro(); - this.app.gatesView.highlight(null); - } + var detailsView = new DetailsView({ + model: gate, + canEdit: that.canEdit, + metrics: that.app.metrics, + periods: that.app.periods + }); + that.app.layout.detailsRegion.show(detailsView); + }); + }, - }); + onDestroy: function () { + this.app.router.navigate(''); + this.app.layout.headerRegion.reset(); + this.app.layout.detailsRegion.reset(); + this.app.layout.renderIntro(); + this.app.gatesView.highlight(null); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/quality-gates/copy-view.js b/server/sonar-web/src/main/js/apps/quality-gates/copy-view.js index fdd6c974cf8..8c4d1f04bc3 100644 --- a/server/sonar-web/src/main/js/apps/quality-gates/copy-view.js +++ b/server/sonar-web/src/main/js/apps/quality-gates/copy-view.js @@ -1,24 +1,22 @@ -define([ - './form-view' -], function (FormView) { +import FormView from './form-view'; - return FormView.extend({ - method: 'copy', - - prepareRequest: function () { - var that = this; - var url = baseUrl + '/api/qualitygates/copy', - name = this.$('#quality-gate-form-name').val(), - options = { - url: url, - data: { id: this.model.id, name: name } - }; - return this.sendRequest(options) - .done(function (r) { - var gate = that.addGate(r); - gate.trigger('select', gate); - }); - } - }); +export default FormView.extend({ + method: 'copy', + prepareRequest: function () { + var that = this; + var url = baseUrl + '/api/qualitygates/copy', + name = this.$('#quality-gate-form-name').val(), + options = { + url: url, + data: { id: this.model.id, name: name } + }; + return this.sendRequest(options) + .done(function (r) { + var gate = that.addGate(r); + gate.trigger('select', gate); + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/quality-gates/create-view.js b/server/sonar-web/src/main/js/apps/quality-gates/create-view.js index f58863ba315..4adbd45552b 100644 --- a/server/sonar-web/src/main/js/apps/quality-gates/create-view.js +++ b/server/sonar-web/src/main/js/apps/quality-gates/create-view.js @@ -1,24 +1,22 @@ -define([ - './form-view' -], function (FormView) { +import FormView from './form-view'; - return FormView.extend({ - method: 'create', - - prepareRequest: function () { - var that = this; - var url = baseUrl + '/api/qualitygates/create', - name = this.$('#quality-gate-form-name').val(), - options = { - url: url, - data: { name: name } - }; - return this.sendRequest(options) - .done(function (r) { - var gate = that.addGate(r); - gate.trigger('select', gate); - }); - } - }); +export default FormView.extend({ + method: 'create', + prepareRequest: function () { + var that = this; + var url = baseUrl + '/api/qualitygates/create', + name = this.$('#quality-gate-form-name').val(), + options = { + url: url, + data: { name: name } + }; + return this.sendRequest(options) + .done(function (r) { + var gate = that.addGate(r); + gate.trigger('select', gate); + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/quality-gates/delete-view.js b/server/sonar-web/src/main/js/apps/quality-gates/delete-view.js index d142b883c84..ca25708f342 100644 --- a/server/sonar-web/src/main/js/apps/quality-gates/delete-view.js +++ b/server/sonar-web/src/main/js/apps/quality-gates/delete-view.js @@ -1,33 +1,31 @@ -define([ - 'components/common/modal-form', - './templates' -], function (ModalForm) { +import ModalForm from 'components/common/modal-form'; +import './templates'; - return ModalForm.extend({ - template: Templates['quality-gates-delete'], +export default ModalForm.extend({ + template: Templates['quality-gates-delete'], - onFormSubmit: function () { - ModalForm.prototype.onFormSubmit.apply(this, arguments); - this.disableForm(); - this.sendRequest(); - }, - - sendRequest: function () { - var that = this, - options = { - statusCode: { - // do not show global error - 400: null - } - }; - return this.model.destroy(options) - .done(function () { - that.destroy(); - }).fail(function (jqXHR) { - that.enableForm(); - that.showErrors(jqXHR.responseJSON.errors, jqXHR.responseJSON.warnings); - }); - } - }); + onFormSubmit: function () { + ModalForm.prototype.onFormSubmit.apply(this, arguments); + this.disableForm(); + this.sendRequest(); + }, + sendRequest: function () { + var that = this, + options = { + statusCode: { + // do not show global error + 400: null + } + }; + return this.model.destroy(options) + .done(function () { + that.destroy(); + }).fail(function (jqXHR) { + that.enableForm(); + that.showErrors(jqXHR.responseJSON.errors, jqXHR.responseJSON.warnings); + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/quality-gates/details-view.js b/server/sonar-web/src/main/js/apps/quality-gates/details-view.js index 9af1b38e65e..0c97cb26c01 100644 --- a/server/sonar-web/src/main/js/apps/quality-gates/details-view.js +++ b/server/sonar-web/src/main/js/apps/quality-gates/details-view.js @@ -1,46 +1,45 @@ -define([ - './conditions', - './gate-conditions-view', - './gate-projects-view', - './templates' -], function (Conditions, DetailConditionsView, ProjectsView) { - - return Marionette.LayoutView.extend({ - template: Templates['quality-gate-detail'], - - regions: { - conditionsRegion: '#quality-gate-conditions', - projectsRegion: '#quality-gate-projects' - }, - - modelEvents: { - 'change': 'render' - }, - - onRender: function () { - this.showConditions(); - this.showProjects(); - }, - - showConditions: function () { - var conditions = new Conditions(this.model.get('conditions')), - view = new DetailConditionsView({ - canEdit: this.options.canEdit, - collection: conditions, - model: this.model, - metrics: this.options.metrics, - periods: this.options.periods - }); - this.conditionsRegion.show(view); - }, - - showProjects: function () { - var view = new ProjectsView({ - canEdit: this.options.canEdit, - model: this.model - }); - this.projectsRegion.show(view); - } - }); +import Marionette from 'backbone.marionette'; +import Conditions from './conditions'; +import DetailConditionsView from './gate-conditions-view'; +import ProjectsView from './gate-projects-view'; +import './templates'; +export default Marionette.LayoutView.extend({ + template: Templates['quality-gate-detail'], + + regions: { + conditionsRegion: '#quality-gate-conditions', + projectsRegion: '#quality-gate-projects' + }, + + modelEvents: { + 'change': 'render' + }, + + onRender: function () { + this.showConditions(); + this.showProjects(); + }, + + showConditions: function () { + var conditions = new Conditions(this.model.get('conditions')), + view = new DetailConditionsView({ + canEdit: this.options.canEdit, + collection: conditions, + model: this.model, + metrics: this.options.metrics, + periods: this.options.periods + }); + this.conditionsRegion.show(view); + }, + + showProjects: function () { + var view = new ProjectsView({ + canEdit: this.options.canEdit, + model: this.model + }); + this.projectsRegion.show(view); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/quality-gates/form-view.js b/server/sonar-web/src/main/js/apps/quality-gates/form-view.js index 9b61f400bf3..f3f4d55d869 100644 --- a/server/sonar-web/src/main/js/apps/quality-gates/form-view.js +++ b/server/sonar-web/src/main/js/apps/quality-gates/form-view.js @@ -1,47 +1,47 @@ -define([ - 'components/common/modal-form', - './gate', - './templates' -], function (ModalForm, Gate) { +import _ from 'underscore'; +import Backbone from 'backbone'; +import ModalForm from 'components/common/modal-form'; +import Gate from './gate'; +import './templates'; - return ModalForm.extend({ - template: Templates['quality-gate-form'], +export default ModalForm.extend({ + template: Templates['quality-gate-form'], - onFormSubmit: function () { - ModalForm.prototype.onFormSubmit.apply(this, arguments); - this.disableForm(); - this.prepareRequest(); - }, + onFormSubmit: function () { + ModalForm.prototype.onFormSubmit.apply(this, arguments); + this.disableForm(); + this.prepareRequest(); + }, - sendRequest: function (options) { - var that = this, - opts = _.defaults(options || {}, { - type: 'POST', - statusCode: { - // do not show global error - 400: null - } - }); - return Backbone.ajax(opts) - .done(function () { - that.destroy(); - }).fail(function (jqXHR) { - that.enableForm(); - that.showErrors(jqXHR.responseJSON.errors, jqXHR.responseJSON.warnings); - }); - }, + sendRequest: function (options) { + var that = this, + opts = _.defaults(options || {}, { + type: 'POST', + statusCode: { + // do not show global error + 400: null + } + }); + return Backbone.ajax(opts) + .done(function () { + that.destroy(); + }).fail(function (jqXHR) { + that.enableForm(); + that.showErrors(jqXHR.responseJSON.errors, jqXHR.responseJSON.warnings); + }); + }, - addGate: function (attrs) { - var gate = new Gate(attrs); - this.collection.add(gate, { merge: true }); - return gate; - }, - - serializeData: function () { - return _.extend(ModalForm.prototype.serializeData.apply(this, arguments), { - method: this.method - }); - } - }); + addGate: function (attrs) { + var gate = new Gate(attrs); + this.collection.add(gate, { merge: true }); + return gate; + }, + serializeData: function () { + return _.extend(ModalForm.prototype.serializeData.apply(this, arguments), { + method: this.method + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/quality-gates/gate-condition-view.js b/server/sonar-web/src/main/js/apps/quality-gates/gate-condition-view.js index 0dfbea0ab17..7678405c622 100644 --- a/server/sonar-web/src/main/js/apps/quality-gates/gate-condition-view.js +++ b/server/sonar-web/src/main/js/apps/quality-gates/gate-condition-view.js @@ -1,100 +1,100 @@ -define([ - './gate-conditions-delete-view', - './templates' -], function (DeleteConditionView) { - - return Marionette.ItemView.extend({ - tagName: 'tr', - template: Templates['quality-gate-detail-condition'], - - modelEvents: { - 'change': 'render' - }, - - ui: { - periodSelect: '[name=period]', - operatorSelect: '[name=operator]', - warningInput: '[name=warning]', - errorInput: '[name=error]', - actionsBox: '.quality-gate-condition-actions', - updateButton: '.update-condition', - deleteButton: '.delete-condition' - }, - - events: { - 'click @ui.updateButton': 'saveCondition', - 'click @ui.deleteButton': 'deleteCondition', - 'click .add-condition': 'saveCondition', - 'click .cancel-add-condition': 'cancelAddCondition', - 'keyup :input': 'enableUpdate', - 'change :input': 'enableUpdate' - }, - - onRender: function () { - this.ui.warningInput.val(this.model.get('warning')); - this.ui.errorInput.val(this.model.get('error')); - - this.ui.periodSelect.select2({ - allowClear: false, - minimumResultsForSearch: 999 - }); - - this.ui.operatorSelect.select2({ - allowClear: false, - minimumResultsForSearch: 999 - }); - - if (this.model.isNew()) { - this.ui.periodSelect.select2('open'); - } - }, - - saveCondition: function () { - var attrs = { - gateId: this.model.isNew() ? this.options.gate.id : void 0, - period: this.ui.periodSelect.val(), - op: this.ui.operatorSelect.val(), - warning: this.ui.warningInput.val(), - error: this.ui.errorInput.val() - }; - this.model.save(attrs, { wait: true }); - }, - - deleteCondition: function () { - new DeleteConditionView({ - model: this.model, - metric: this.getMetric() - }).render(); - }, - - cancelAddCondition: function () { - this.destroy(); - }, - - enableUpdate: function () { - this.ui.updateButton.prop('disabled', false); - }, - - getMetric: function () { - var key = this.model.get('metric'); - return _.findWhere(this.options.metrics, { key: key }); - }, - - isDiffMetric: function () { - var key = this.model.get('metric'); - return key.indexOf('new_') === 0; - }, - - serializeData: function () { - var period = _.findWhere(this.options.periods, { key: this.model.get('period') }); - return _.extend(Marionette.ItemView.prototype.serializeData.apply(this, arguments), { - canEdit: this.options.canEdit, - periods: this.options.periods, - periodText: period ? period.text : t('value'), - metric: this.getMetric(), - isDiffMetric: this.isDiffMetric() - }); +import _ from 'underscore'; +import Marionette from 'backbone.marionette'; +import DeleteConditionView from './gate-conditions-delete-view'; +import './templates'; + +export default Marionette.ItemView.extend({ + tagName: 'tr', + template: Templates['quality-gate-detail-condition'], + + modelEvents: { + 'change': 'render' + }, + + ui: { + periodSelect: '[name=period]', + operatorSelect: '[name=operator]', + warningInput: '[name=warning]', + errorInput: '[name=error]', + actionsBox: '.quality-gate-condition-actions', + updateButton: '.update-condition', + deleteButton: '.delete-condition' + }, + + events: { + 'click @ui.updateButton': 'saveCondition', + 'click @ui.deleteButton': 'deleteCondition', + 'click .add-condition': 'saveCondition', + 'click .cancel-add-condition': 'cancelAddCondition', + 'keyup :input': 'enableUpdate', + 'change :input': 'enableUpdate' + }, + + onRender: function () { + this.ui.warningInput.val(this.model.get('warning')); + this.ui.errorInput.val(this.model.get('error')); + + this.ui.periodSelect.select2({ + allowClear: false, + minimumResultsForSearch: 999 + }); + + this.ui.operatorSelect.select2({ + allowClear: false, + minimumResultsForSearch: 999 + }); + + if (this.model.isNew()) { + this.ui.periodSelect.select2('open'); } - }); - + }, + + saveCondition: function () { + var attrs = { + gateId: this.model.isNew() ? this.options.gate.id : void 0, + period: this.ui.periodSelect.val(), + op: this.ui.operatorSelect.val(), + warning: this.ui.warningInput.val(), + error: this.ui.errorInput.val() + }; + this.model.save(attrs, { wait: true }); + }, + + deleteCondition: function () { + new DeleteConditionView({ + model: this.model, + metric: this.getMetric() + }).render(); + }, + + cancelAddCondition: function () { + this.destroy(); + }, + + enableUpdate: function () { + this.ui.updateButton.prop('disabled', false); + }, + + getMetric: function () { + var key = this.model.get('metric'); + return _.findWhere(this.options.metrics, { key: key }); + }, + + isDiffMetric: function () { + var key = this.model.get('metric'); + return key.indexOf('new_') === 0; + }, + + serializeData: function () { + var period = _.findWhere(this.options.periods, { key: this.model.get('period') }); + return _.extend(Marionette.ItemView.prototype.serializeData.apply(this, arguments), { + canEdit: this.options.canEdit, + periods: this.options.periods, + periodText: period ? period.text : t('value'), + metric: this.getMetric(), + isDiffMetric: this.isDiffMetric() + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/quality-gates/gate-conditions-delete-view.js b/server/sonar-web/src/main/js/apps/quality-gates/gate-conditions-delete-view.js index c8ed23a2883..9922a0bc5b1 100644 --- a/server/sonar-web/src/main/js/apps/quality-gates/gate-conditions-delete-view.js +++ b/server/sonar-web/src/main/js/apps/quality-gates/gate-conditions-delete-view.js @@ -1,39 +1,39 @@ -define([ - 'components/common/modal-form', - './templates' -], function (ModalForm) { +import _ from 'underscore'; +import Marionette from 'backbone.marionette'; +import ModalForm from 'components/common/modal-form'; +import './templates'; - return ModalForm.extend({ - template: Templates['quality-gates-condition-delete'], +export default ModalForm.extend({ + template: Templates['quality-gates-condition-delete'], - onFormSubmit: function () { - ModalForm.prototype.onFormSubmit.apply(this, arguments); - this.disableForm(); - this.sendRequest(); - }, + onFormSubmit: function () { + ModalForm.prototype.onFormSubmit.apply(this, arguments); + this.disableForm(); + this.sendRequest(); + }, - sendRequest: function () { - var that = this, - options = { - statusCode: { - // do not show global error - 400: null - } - }; - return this.model.destroy(options) - .done(function () { - that.destroy(); - }).fail(function (jqXHR) { - that.enableForm(); - that.showErrors(jqXHR.responseJSON.errors, jqXHR.responseJSON.warnings); - }); - }, - - serializeData: function () { - return _.extend(Marionette.ItemView.prototype.serializeData.apply(this, arguments), { - metric: this.options.metric - }); - } - }); + sendRequest: function () { + var that = this, + options = { + statusCode: { + // do not show global error + 400: null + } + }; + return this.model.destroy(options) + .done(function () { + that.destroy(); + }).fail(function (jqXHR) { + that.enableForm(); + that.showErrors(jqXHR.responseJSON.errors, jqXHR.responseJSON.warnings); + }); + }, + serializeData: function () { + return _.extend(Marionette.ItemView.prototype.serializeData.apply(this, arguments), { + metric: this.options.metric + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/quality-gates/gate-conditions-empty-view.js b/server/sonar-web/src/main/js/apps/quality-gates/gate-conditions-empty-view.js index 03390ac7a89..5be03d5a0c6 100644 --- a/server/sonar-web/src/main/js/apps/quality-gates/gate-conditions-empty-view.js +++ b/server/sonar-web/src/main/js/apps/quality-gates/gate-conditions-empty-view.js @@ -1,16 +1,16 @@ -define([ - './templates' -], function () { +import _ from 'underscore'; +import Marionette from 'backbone.marionette'; +import './templates'; - return Marionette.ItemView.extend({ - tagName: 'tr', - template: Templates['quality-gate-detail-conditions-empty'], - - serializeData: function () { - return _.extend(Marionette.ItemView.prototype.serializeData.apply(this, arguments), { - canEdit: this.options.canEdit - }); - } - }); +export default Marionette.ItemView.extend({ + tagName: 'tr', + template: Templates['quality-gate-detail-conditions-empty'], + serializeData: function () { + return _.extend(Marionette.ItemView.prototype.serializeData.apply(this, arguments), { + canEdit: this.options.canEdit + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/quality-gates/gate-conditions-view.js b/server/sonar-web/src/main/js/apps/quality-gates/gate-conditions-view.js index b0c0857cc95..d02f8f93603 100644 --- a/server/sonar-web/src/main/js/apps/quality-gates/gate-conditions-view.js +++ b/server/sonar-web/src/main/js/apps/quality-gates/gate-conditions-view.js @@ -1,75 +1,75 @@ -define([ - './condition', - './gate-condition-view', - './gate-conditions-empty-view', - './templates' -], function (Condition, ConditionView, ConditionsEmptyView) { +import _ from 'underscore'; +import Marionette from 'backbone.marionette'; +import Condition from './condition'; +import ConditionView from './gate-condition-view'; +import ConditionsEmptyView from './gate-conditions-empty-view'; +import './templates'; - return Marionette.CompositeView.extend({ - template: Templates['quality-gate-detail-conditions'], - childView: ConditionView, - emptyView: ConditionsEmptyView, - childViewContainer: '.js-conditions', +export default Marionette.CompositeView.extend({ + template: Templates['quality-gate-detail-conditions'], + childView: ConditionView, + emptyView: ConditionsEmptyView, + childViewContainer: '.js-conditions', - ui: { - metricSelect: '#quality-gate-new-condition-metric' - }, + ui: { + metricSelect: '#quality-gate-new-condition-metric' + }, - events: { - 'click .js-show-more': 'showMoreIntroduction', - 'change @ui.metricSelect': 'addCondition' - }, + events: { + 'click .js-show-more': 'showMoreIntroduction', + 'change @ui.metricSelect': 'addCondition' + }, - childViewOptions: function () { - return { - canEdit: this.options.canEdit, - gate: this.model, - collectionView: this, - metrics: this.options.metrics, - periods: this.options.periods - }; - }, + childViewOptions: function () { + return { + canEdit: this.options.canEdit, + gate: this.model, + collectionView: this, + metrics: this.options.metrics, + periods: this.options.periods + }; + }, - onRender: function () { - this.ui.metricSelect.select2({ - allowClear: false, - width: '250px', - placeholder: t('alerts.select_metric') - }); - }, + onRender: function () { + this.ui.metricSelect.select2({ + allowClear: false, + width: '250px', + placeholder: t('alerts.select_metric') + }); + }, - showMoreIntroduction: function () { - this.$('.js-show-more').addClass('hidden'); - this.$('.js-more').removeClass('hidden'); - }, + showMoreIntroduction: function () { + this.$('.js-show-more').addClass('hidden'); + this.$('.js-more').removeClass('hidden'); + }, - addCondition: function () { - var metric = this.ui.metricSelect.val(); - this.ui.metricSelect.select2('val', ''); - var condition = new Condition({ metric: metric }); - this.collection.add(condition); - }, + addCondition: function () { + var metric = this.ui.metricSelect.val(); + this.ui.metricSelect.select2('val', ''); + var condition = new Condition({ metric: metric }); + this.collection.add(condition); + }, - groupedMetrics: function () { - var metrics = this.options.metrics.filter(function (metric) { - return !metric.hidden; - }); - metrics = _.groupBy(metrics, 'domain'); - metrics = _.map(metrics, function (list, domain) { - return { - domain: domain, - metrics: _.sortBy(list, 'short_name') - }; - }); - return _.sortBy(metrics, 'domain'); - }, - - serializeData: function () { - return _.extend(Marionette.CompositeView.prototype.serializeData.apply(this, arguments), { - canEdit: this.options.canEdit, - metricGroups: this.groupedMetrics() - }); - } - }); + groupedMetrics: function () { + var metrics = this.options.metrics.filter(function (metric) { + return !metric.hidden; + }); + metrics = _.groupBy(metrics, 'domain'); + metrics = _.map(metrics, function (list, domain) { + return { + domain: domain, + metrics: _.sortBy(list, 'short_name') + }; + }); + return _.sortBy(metrics, 'domain'); + }, + serializeData: function () { + return _.extend(Marionette.CompositeView.prototype.serializeData.apply(this, arguments), { + canEdit: this.options.canEdit, + metricGroups: this.groupedMetrics() + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/quality-gates/gate-projects-view.js b/server/sonar-web/src/main/js/apps/quality-gates/gate-projects-view.js index c188c473be5..732074be79d 100644 --- a/server/sonar-web/src/main/js/apps/quality-gates/gate-projects-view.js +++ b/server/sonar-web/src/main/js/apps/quality-gates/gate-projects-view.js @@ -1,48 +1,48 @@ -define([ - 'components/common/select-list', - './templates' -], function () { +import _ from 'underscore'; +import Marionette from 'backbone.marionette'; +import 'components/common/select-list'; +import './templates'; - return Marionette.ItemView.extend({ - template: Templates['quality-gate-detail-projects'], +export default Marionette.ItemView.extend({ + template: Templates['quality-gate-detail-projects'], - onRender: function () { - if (!this.model.isDefault()) { - new window.SelectList({ - el: this.$('#select-list-projects'), - width: '100%', - readOnly: !this.options.canEdit, - focusSearch: false, - format: function (item) { - return item.name; - }, - searchUrl: baseUrl + '/api/qualitygates/search?gateId=' + this.model.id, - selectUrl: baseUrl + '/api/qualitygates/select', - deselectUrl: baseUrl + '/api/qualitygates/deselect', - extra: { - gateId: this.model.id - }, - selectParameter: 'projectId', - selectParameterValue: 'id', - 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') - } - }); - } - }, - - serializeData: function () { - return _.extend(Marionette.ItemView.prototype.serializeData.apply(this, arguments), { - canEdit: this.options.canEdit + onRender: function () { + if (!this.model.isDefault()) { + new window.SelectList({ + el: this.$('#select-list-projects'), + width: '100%', + readOnly: !this.options.canEdit, + focusSearch: false, + format: function (item) { + return item.name; + }, + searchUrl: baseUrl + '/api/qualitygates/search?gateId=' + this.model.id, + selectUrl: baseUrl + '/api/qualitygates/select', + deselectUrl: baseUrl + '/api/qualitygates/deselect', + extra: { + gateId: this.model.id + }, + selectParameter: 'projectId', + selectParameterValue: 'id', + 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') + } }); } - }); + }, + serializeData: function () { + return _.extend(Marionette.ItemView.prototype.serializeData.apply(this, arguments), { + canEdit: this.options.canEdit + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/quality-gates/gate-view.js b/server/sonar-web/src/main/js/apps/quality-gates/gate-view.js index 30036a3c313..13b3e582b96 100644 --- a/server/sonar-web/src/main/js/apps/quality-gates/gate-view.js +++ b/server/sonar-web/src/main/js/apps/quality-gates/gate-view.js @@ -1,29 +1,28 @@ -define([ - './templates' -], function () { +import Marionette from 'backbone.marionette'; +import './templates'; - return Marionette.ItemView.extend({ - tagName: 'a', - className: 'list-group-item', - template: Templates['quality-gates-gate'], +export default Marionette.ItemView.extend({ + tagName: 'a', + className: 'list-group-item', + template: Templates['quality-gates-gate'], - modelEvents: { - 'change': 'render' - }, + modelEvents: { + 'change': 'render' + }, - events: { - 'click': 'onClick' - }, + events: { + 'click': 'onClick' + }, - onRender: function () { - this.$el.toggleClass('active', this.options.highlighted); - this.$el.attr('data-id', this.model.id); - }, - - onClick: function (e) { - e.preventDefault(); - this.model.trigger('select', this.model); - } - }); + onRender: function () { + this.$el.toggleClass('active', this.options.highlighted); + this.$el.attr('data-id', this.model.id); + }, + onClick: function (e) { + e.preventDefault(); + this.model.trigger('select', this.model); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/quality-gates/gate.js b/server/sonar-web/src/main/js/apps/quality-gates/gate.js index 54b4e6ce13c..f118bc9295d 100644 --- a/server/sonar-web/src/main/js/apps/quality-gates/gate.js +++ b/server/sonar-web/src/main/js/apps/quality-gates/gate.js @@ -1,54 +1,54 @@ -define(function () { - - return Backbone.Model.extend({ - - isDefault: function () { - return this.get('isDefault'); - }, - - url: function () { - return baseUrl + '/api/qualitygates'; - }, - - showUrl: function () { - return this.url() + '/show'; - }, - - deleteUrl: function () { - return this.url() + '/destroy'; - }, - - toggleDefaultUrl: function () { - var method = this.isDefault() ? 'unset_default' : 'set_as_default'; - return this.url() + '/' + method; - }, - - sync: function (method, model, options) { - var opts = options || {}; - opts.data = opts.data || {}; - opts.data.id = model.id; - if (method === 'read') { - opts.url = this.showUrl(); - } - if (method === 'delete') { - opts.url = this.deleteUrl(); - opts.type = 'POST'; - } - return Backbone.ajax(opts); - }, - - toggleDefault: function () { - var that = this; - var opts = { - type: 'POST', - url: this.toggleDefaultUrl(), - data: { id: this.id } - }; - return Backbone.ajax(opts).done(function () { - that.collection.toggleDefault(that); - }); - } +import Backbone from 'backbone'; + +export default Backbone.Model.extend({ + + isDefault: function () { + return this.get('isDefault'); + }, + + url: function () { + return baseUrl + '/api/qualitygates'; + }, + + showUrl: function () { + return this.url() + '/show'; + }, + + deleteUrl: function () { + return this.url() + '/destroy'; + }, - }); + toggleDefaultUrl: function () { + var method = this.isDefault() ? 'unset_default' : 'set_as_default'; + return this.url() + '/' + method; + }, + + sync: function (method, model, options) { + var opts = options || {}; + opts.data = opts.data || {}; + opts.data.id = model.id; + if (method === 'read') { + opts.url = this.showUrl(); + } + if (method === 'delete') { + opts.url = this.deleteUrl(); + opts.type = 'POST'; + } + return Backbone.ajax(opts); + }, + + toggleDefault: function () { + var that = this; + var opts = { + type: 'POST', + url: this.toggleDefaultUrl(), + data: { id: this.id } + }; + return Backbone.ajax(opts).done(function () { + that.collection.toggleDefault(that); + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/quality-gates/gates-view.js b/server/sonar-web/src/main/js/apps/quality-gates/gates-view.js index cd36c381a39..956cc21826a 100644 --- a/server/sonar-web/src/main/js/apps/quality-gates/gates-view.js +++ b/server/sonar-web/src/main/js/apps/quality-gates/gates-view.js @@ -1,25 +1,24 @@ -define([ - './gate-view', - './templates' -], function (ItemView) { +import Marionette from 'backbone.marionette'; +import ItemView from './gate-view'; +import './templates'; - return Marionette.CompositeView.extend({ - className: 'list-group', - template: Templates['quality-gates-gates'], - childView: ItemView, - childViewContainer: '.js-list', +export default Marionette.CompositeView.extend({ + className: 'list-group', + template: Templates['quality-gates-gates'], + childView: ItemView, + childViewContainer: '.js-list', - childViewOptions: function (model) { - return { - collectionView: this, - highlighted: model.id === this.highlighted - }; - }, - - highlight: function (id) { - this.highlighted = id; - this.render(); - } - }); + childViewOptions: function (model) { + return { + collectionView: this, + highlighted: model.id === this.highlighted + }; + }, + highlight: function (id) { + this.highlighted = id; + this.render(); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/quality-gates/gates.js b/server/sonar-web/src/main/js/apps/quality-gates/gates.js index d33b35bcfe5..f7664745e19 100644 --- a/server/sonar-web/src/main/js/apps/quality-gates/gates.js +++ b/server/sonar-web/src/main/js/apps/quality-gates/gates.js @@ -1,30 +1,30 @@ -define([ - './gate' -], function (Gate) { +import _ from 'underscore'; +import Backbone from 'backbone'; +import Gate from './gate'; - return Backbone.Collection.extend({ - model: Gate, +export default Backbone.Collection.extend({ + model: Gate, - url: function () { - return baseUrl + '/api/qualitygates/list'; - }, + url: function () { + return baseUrl + '/api/qualitygates/list'; + }, - parse: function (r) { - return r.qualitygates.map(function (gate) { - return _.extend(gate, { isDefault: gate.id === r.default }); - }); - }, + parse: function (r) { + return r.qualitygates.map(function (gate) { + return _.extend(gate, { isDefault: gate.id === r.default }); + }); + }, - comparator: function (item) { - return item.get('name').toLowerCase(); - }, - - toggleDefault: function (gate) { - var isDefault = gate.isDefault(); - this.forEach(function (model) { - model.set({ isDefault: gate.id === model.id ? !isDefault : false }); - }); - } - }); + comparator: function (item) { + return item.get('name').toLowerCase(); + }, + toggleDefault: function (gate) { + var isDefault = gate.isDefault(); + this.forEach(function (model) { + model.set({ isDefault: gate.id === model.id ? !isDefault : false }); + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/quality-gates/header-view.js b/server/sonar-web/src/main/js/apps/quality-gates/header-view.js index b86b2c9ba62..7a002258513 100644 --- a/server/sonar-web/src/main/js/apps/quality-gates/header-view.js +++ b/server/sonar-web/src/main/js/apps/quality-gates/header-view.js @@ -1,52 +1,52 @@ -define([ - './rename-view', - './copy-view', - './delete-view', - './templates' -], function (RenameView, CopyView, DeleteView) { - - return Marionette.ItemView.extend({ - template: Templates['quality-gate-detail-header'], - - modelEvents: { - 'change': 'render' - }, - - events: { - 'click #quality-gate-rename': 'renameQualityGate', - 'click #quality-gate-copy': 'copyQualityGate', - 'click #quality-gate-delete': 'deleteQualityGate', - 'click #quality-gate-toggle-default': 'toggleDefault' - }, - - renameQualityGate: function () { - new RenameView({ - model: this.model - }).render(); - }, - - copyQualityGate: function () { - new CopyView({ - model: this.model, - collection: this.model.collection - }).render(); - }, - - deleteQualityGate: function () { - new DeleteView({ - model: this.model - }).render(); - }, - - toggleDefault: function () { - this.model.toggleDefault(); - }, - - serializeData: function () { - return _.extend(Marionette.ItemView.prototype.serializeData.apply(this, arguments), { - canEdit: this.options.canEdit - }); - } - }); - +import _ from 'underscore'; +import Marionette from 'backbone.marionette'; +import RenameView from './rename-view'; +import CopyView from './copy-view'; +import DeleteView from './delete-view'; +import './templates'; + +export default Marionette.ItemView.extend({ + template: Templates['quality-gate-detail-header'], + + modelEvents: { + 'change': 'render' + }, + + events: { + 'click #quality-gate-rename': 'renameQualityGate', + 'click #quality-gate-copy': 'copyQualityGate', + 'click #quality-gate-delete': 'deleteQualityGate', + 'click #quality-gate-toggle-default': 'toggleDefault' + }, + + renameQualityGate: function () { + new RenameView({ + model: this.model + }).render(); + }, + + copyQualityGate: function () { + new CopyView({ + model: this.model, + collection: this.model.collection + }).render(); + }, + + deleteQualityGate: function () { + new DeleteView({ + model: this.model + }).render(); + }, + + toggleDefault: function () { + this.model.toggleDefault(); + }, + + serializeData: function () { + return _.extend(Marionette.ItemView.prototype.serializeData.apply(this, arguments), { + canEdit: this.options.canEdit + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/quality-gates/intro-view.js b/server/sonar-web/src/main/js/apps/quality-gates/intro-view.js index c9588a3d48f..6128211275c 100644 --- a/server/sonar-web/src/main/js/apps/quality-gates/intro-view.js +++ b/server/sonar-web/src/main/js/apps/quality-gates/intro-view.js @@ -1,9 +1,8 @@ -define([ - './templates' -], function () { - - return Marionette.ItemView.extend({ - template: Templates['quality-gates-intro'] - }); +import Marionette from 'backbone.marionette'; +import './templates'; +export default Marionette.ItemView.extend({ + template: Templates['quality-gates-intro'] }); + + diff --git a/server/sonar-web/src/main/js/apps/quality-gates/layout.js b/server/sonar-web/src/main/js/apps/quality-gates/layout.js index db02143caa6..5d0a65ae47b 100644 --- a/server/sonar-web/src/main/js/apps/quality-gates/layout.js +++ b/server/sonar-web/src/main/js/apps/quality-gates/layout.js @@ -1,28 +1,27 @@ -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-gates-layout'], +export default Marionette.LayoutView.extend({ + template: Templates['quality-gates-layout'], - regions: { - headerRegion: '.search-navigator-workspace-header', - actionsRegion: '.search-navigator-filters', - resultsRegion: '.quality-gates-results', - detailsRegion: '.search-navigator-workspace-details' - }, + regions: { + headerRegion: '.search-navigator-workspace-header', + actionsRegion: '.search-navigator-filters', + resultsRegion: '.quality-gates-results', + detailsRegion: '.search-navigator-workspace-details' + }, - onRender: function () { - var top = this.$('.search-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 top = this.$('.search-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-gates/rename-view.js b/server/sonar-web/src/main/js/apps/quality-gates/rename-view.js index d9b5946653a..1cc4ddeed5a 100644 --- a/server/sonar-web/src/main/js/apps/quality-gates/rename-view.js +++ b/server/sonar-web/src/main/js/apps/quality-gates/rename-view.js @@ -1,23 +1,21 @@ -define([ - './form-view' -], function (FormView) { +import FormView from './form-view'; - return FormView.extend({ - method: 'rename', - - prepareRequest: function () { - var that = this; - var url = baseUrl + '/api/qualitygates/rename', - name = this.$('#quality-gate-form-name').val(), - options = { - url: url, - data: { id: this.model.id, name: name } - }; - return this.sendRequest(options) - .done(function (r) { - that.model.set(r); - }); - } - }); +export default FormView.extend({ + method: 'rename', + prepareRequest: function () { + var that = this; + var url = baseUrl + '/api/qualitygates/rename', + name = this.$('#quality-gate-form-name').val(), + options = { + url: url, + data: { id: this.model.id, name: name } + }; + return this.sendRequest(options) + .done(function (r) { + that.model.set(r); + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/quality-gates/router.js b/server/sonar-web/src/main/js/apps/quality-gates/router.js index 582c47361d5..52d28d4787c 100644 --- a/server/sonar-web/src/main/js/apps/quality-gates/router.js +++ b/server/sonar-web/src/main/js/apps/quality-gates/router.js @@ -1,22 +1,22 @@ -define(function () { +import Backbone from 'backbone'; - return Backbone.Router.extend({ - routes: { - '': 'index', - 'show/:id': 'show' - }, +export default Backbone.Router.extend({ + routes: { + '': 'index', + 'show/:id': 'show' + }, - initialize: function (options) { - this.app = options.app; - }, + initialize: function (options) { + this.app = options.app; + }, - index: function () { - this.app.controller.index(); - }, - - show: function (id) { - this.app.controller.show(id); - } - }); + index: function () { + this.app.controller.index(); + }, + show: function (id) { + this.app.controller.show(id); + } }); + + 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('
').closest('form').get(0).reset(); - e.unwrap(); - }, + emptyInput: function (e) { + e.wrap('').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 = ' ' + t('severity', severity), + message = tp('quality_profiles.severity_set_to_x', label); + return new Handlebars.SafeString(message); +}); - Handlebars.registerHelper('severityChangelog', function (severity) { - var label = ' ' + 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); + } + } }); + + diff --git a/server/sonar-web/src/main/js/apps/source-viewer/app.js b/server/sonar-web/src/main/js/apps/source-viewer/app.js index 1c6947db3ee..3c013e406de 100644 --- a/server/sonar-web/src/main/js/apps/source-viewer/app.js +++ b/server/sonar-web/src/main/js/apps/source-viewer/app.js @@ -1,29 +1,28 @@ -define([ - 'components/source-viewer/main' -], function (SourceViewer) { +import Marionette from 'backbone.marionette'; +import SourceViewer from 'components/source-viewer/main'; - var App = new Marionette.Application(), - init = function (options) { - this.addRegions({ mainRegion: options.el }); +var App = new Marionette.Application(), + init = function (options) { + this.addRegions({ mainRegion: options.el }); - var viewer = new SourceViewer(); - this.mainRegion.show(viewer); - viewer.open(options.file.uuid); - if (typeof options.file.line === 'number') { - viewer.on('loaded', function () { - viewer - .highlightLine(options.file.line) - .scrollToLine(options.file.line); - }); - } - }; + var viewer = new SourceViewer(); + this.mainRegion.show(viewer); + viewer.open(options.file.uuid); + if (typeof options.file.line === 'number') { + viewer.on('loaded', function () { + viewer + .highlightLine(options.file.line) + .scrollToLine(options.file.line); + }); + } + }; - App.on('start', function (options) { - window.requestMessages().done(function () { - init.call(App, options); - }); +App.on('start', function (options) { + window.requestMessages().done(function () { + init.call(App, options); }); +}); + +export default App; - return App; -}); diff --git a/server/sonar-web/src/main/js/apps/update-center/app.js b/server/sonar-web/src/main/js/apps/update-center/app.js index a866a0c2879..b667f6736b8 100644 --- a/server/sonar-web/src/main/js/apps/update-center/app.js +++ b/server/sonar-web/src/main/js/apps/update-center/app.js @@ -1,64 +1,64 @@ -define([ - './layout', - './header-view', - './search-view', - './list-view', - './footer-view', - './controller', - './router', - './plugins' -], function (Layout, HeaderView, SearchView, ListView, FooterView, Controller, Router, Plugins) { +import Backbone from 'backbone'; +import Marionette from 'backbone.marionette'; +import Layout from './layout'; +import HeaderView from './header-view'; +import SearchView from './search-view'; +import ListView from './list-view'; +import FooterView from './footer-view'; +import Controller from './controller'; +import Router from './router'; +import Plugins from './plugins'; - var App = new Marionette.Application(), - init = function (options) { - // State - this.state = new Backbone.Model({ - updateCenterActive: window.SS.updateCenterActive - }); +var App = new Marionette.Application(), + init = function (options) { + // State + this.state = new Backbone.Model({ + updateCenterActive: window.SS.updateCenterActive + }); - // Layout - this.layout = new Layout({ el: options.el }); - this.layout.render(); + // Layout + this.layout = new Layout({ el: options.el }); + this.layout.render(); - // Plugins - this.plugins = new Plugins(); + // Plugins + this.plugins = new Plugins(); - // Controller - this.controller = new Controller({ collection: this.plugins, state: this.state }); + // Controller + this.controller = new Controller({ collection: this.plugins, state: this.state }); - // Router - this.router = new Router({ controller: this.controller}); + // Router + this.router = new Router({ controller: this.controller }); - // Header - this.headerView = new HeaderView({ collection: this.plugins }); - this.layout.headerRegion.show(this.headerView); + // Header + this.headerView = new HeaderView({ collection: this.plugins }); + this.layout.headerRegion.show(this.headerView); - // Search - this.searchView = new SearchView({ collection: this.plugins, router: this.router, state: this.state }); - this.layout.searchRegion.show(this.searchView); - this.searchView.focusSearch(); + // Search + this.searchView = new SearchView({ collection: this.plugins, router: this.router, state: this.state }); + this.layout.searchRegion.show(this.searchView); + this.searchView.focusSearch(); - // List - this.listView = new ListView({ collection: this.plugins }); - this.layout.listRegion.show(this.listView); + // List + this.listView = new ListView({ collection: this.plugins }); + this.layout.listRegion.show(this.listView); - // Footer - this.footerView = new FooterView({ collection: this.plugins }); - this.layout.footerRegion.show(this.footerView); + // Footer + this.footerView = new FooterView({ collection: this.plugins }); + this.layout.footerRegion.show(this.footerView); - // Go - Backbone.history.start({ - pushState: true, - root: options.urlRoot - }); - }; + // Go + Backbone.history.start({ + pushState: true, + root: options.urlRoot + }); + }; - App.on('start', function (options) { - window.requestMessages().done(function () { - init.call(App, options); - }); +App.on('start', function (options) { + window.requestMessages().done(function () { + init.call(App, options); }); +}); + +export default App; - return App; -}); diff --git a/server/sonar-web/src/main/js/apps/update-center/controller.js b/server/sonar-web/src/main/js/apps/update-center/controller.js index a8f069c9dc0..4f80e0615a7 100644 --- a/server/sonar-web/src/main/js/apps/update-center/controller.js +++ b/server/sonar-web/src/main/js/apps/update-center/controller.js @@ -1,30 +1,30 @@ -define(function () { +import Marionette from 'backbone.marionette'; - return Marionette.Controller.extend({ - initialize: function (options) { - this.collection = options.collection; - this.state = options.state; - }, +export default Marionette.Controller.extend({ + initialize: function (options) { + this.collection = options.collection; + this.state = options.state; + }, - showInstalled: function () { - this.state.set({ section: 'installed' }); - this.collection.fetchInstalled(); - }, + showInstalled: function () { + this.state.set({ section: 'installed' }); + this.collection.fetchInstalled(); + }, - showUpdates: function () { - this.state.set({ section: 'updates' }); - this.collection.fetchUpdates(); - }, + showUpdates: function () { + this.state.set({ section: 'updates' }); + this.collection.fetchUpdates(); + }, - showAvailable: function () { - this.state.set({ section: 'available' }); - this.collection.fetchAvailable(); - }, - - showSystemUpgrades: function () { - this.state.set({ section: 'system' }); - this.collection.fetchSystemUpgrades(); - } - }); + showAvailable: function () { + this.state.set({ section: 'available' }); + this.collection.fetchAvailable(); + }, + showSystemUpgrades: function () { + this.state.set({ section: 'system' }); + this.collection.fetchSystemUpgrades(); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/update-center/footer-view.js b/server/sonar-web/src/main/js/apps/update-center/footer-view.js index 2f83d509dc7..085dacf43c2 100644 --- a/server/sonar-web/src/main/js/apps/update-center/footer-view.js +++ b/server/sonar-web/src/main/js/apps/update-center/footer-view.js @@ -1,19 +1,19 @@ -define([ - './templates' -], function () { +import _ from 'underscore'; +import Marionette from 'backbone.marionette'; +import './templates'; - return Marionette.ItemView.extend({ - template: Templates['update-center-footer'], +export default Marionette.ItemView.extend({ + template: Templates['update-center-footer'], - collectionEvents: { - 'all': 'render' - }, - - serializeData: function () { - return _.extend(this._super(), { - total: this.collection.where({ _hidden: false }).length - }); - } - }); + collectionEvents: { + 'all': 'render' + }, + serializeData: function () { + return _.extend(this._super(), { + total: this.collection.where({ _hidden: false }).length + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/update-center/header-view.js b/server/sonar-web/src/main/js/apps/update-center/header-view.js index 99e1095ad7f..1a78ad8533b 100644 --- a/server/sonar-web/src/main/js/apps/update-center/header-view.js +++ b/server/sonar-web/src/main/js/apps/update-center/header-view.js @@ -1,28 +1,28 @@ -define([ - './templates' -], function () { +import _ from 'underscore'; +import Marionette from 'backbone.marionette'; +import './templates'; - return Marionette.ItemView.extend({ - template: Templates['update-center-header'], +export default Marionette.ItemView.extend({ + template: Templates['update-center-header'], - collectionEvents: { - all: 'render' - }, + collectionEvents: { + all: 'render' + }, - events: { - 'click .js-cancel-all': 'cancelAll' - }, + events: { + 'click .js-cancel-all': 'cancelAll' + }, - cancelAll: function () { - this.collection.cancelAll(); - }, - - serializeData: function () { - return _.extend(this._super(), { - installing: this.collection._installedCount, - uninstalling: this.collection._uninstalledCount - }); - } - }); + cancelAll: function () { + this.collection.cancelAll(); + }, + serializeData: function () { + return _.extend(this._super(), { + installing: this.collection._installedCount, + uninstalling: this.collection._uninstalledCount + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/update-center/layout.js b/server/sonar-web/src/main/js/apps/update-center/layout.js index 58e480d16de..2a8c5d7b4e8 100644 --- a/server/sonar-web/src/main/js/apps/update-center/layout.js +++ b/server/sonar-web/src/main/js/apps/update-center/layout.js @@ -1,16 +1,15 @@ -define([ - './templates' -], function () { +import Marionette from 'backbone.marionette'; +import './templates'; - return Marionette.LayoutView.extend({ - template: Templates['update-center-layout'], - - regions: { - headerRegion: '#update-center-header', - searchRegion: '#update-center-search', - listRegion: '#update-center-plugins', - footerRegion: '#update-center-footer' - } - }); +export default Marionette.LayoutView.extend({ + template: Templates['update-center-layout'], + regions: { + headerRegion: '#update-center-header', + searchRegion: '#update-center-search', + listRegion: '#update-center-plugins', + footerRegion: '#update-center-footer' + } }); + + diff --git a/server/sonar-web/src/main/js/apps/update-center/list-item-view.js b/server/sonar-web/src/main/js/apps/update-center/list-item-view.js index 67750c343ec..163d3c61fa0 100644 --- a/server/sonar-web/src/main/js/apps/update-center/list-item-view.js +++ b/server/sonar-web/src/main/js/apps/update-center/list-item-view.js @@ -1,98 +1,97 @@ -define([ - './plugin-changelog-view', - './templates' -], function (PluginChangelogView) { - - var $ = jQuery; - - return Marionette.ItemView.extend({ - tagName: 'li', - className: 'panel panel-vertical', - template: Templates['update-center-plugin'], - systemTemplate: Templates['update-center-system-update'], - - modelEvents: { - 'change:_hidden': 'toggleDisplay', - 'change': 'onModelChange', - 'request': 'onRequest' - }, - - events: { - 'click .js-changelog': 'onChangelogClick', - 'click .js-install': 'install', - 'click .js-update': 'update', - 'click .js-uninstall': 'uninstall', - 'change .js-terms': 'onTermsChange', - 'click .js-plugin-category': 'onCategoryClick' - }, - - getTemplate: function () { - return this.model.get('_system') ? this.systemTemplate : this.template; - }, - - onRender: function () { - this.$el.attr('data-id', this.model.id); - if (this.model.get('_system')) { - this.$el.attr('data-system', ''); - } - this.$('[data-toggle="tooltip"]').tooltip({ container: 'body', placement: 'bottom' }); - }, - - onDestroy: function () { - this.$('[data-toggle="tooltip"]').tooltip('destroy'); - }, - - onModelChange: function () { - if (!this.model.hasChanged('_hidden')) { - this.render(); - } - }, - - onChangelogClick: function (e) { - e.preventDefault(); - e.stopPropagation(); - $('body').click(); - var index = $(e.currentTarget).data('idx'), - // if show changelog of update, show details of this update - // otherwise show changelog of the available release - update = this.model.has('release') ? this.model.toJSON() : this.model.get('updates')[index], - popup = new PluginChangelogView({ - triggerEl: $(e.currentTarget), - model: new Backbone.Model(update) - }); - popup.render(); - }, - - onRequest: function () { - this.$('.js-actions').addClass('hidden'); - this.$('.js-spinner').removeClass('hidden'); - }, - - toggleDisplay: function () { - this.$el.toggleClass('hidden', this.model.get('_hidden')); - }, - - install: function () { - this.model.install(); - }, - - update: function () { - this.model.update(); - }, - - uninstall: function () { - this.model.uninstall(); - }, - - onTermsChange: function () { - var isAccepted = this.$('.js-terms').is(':checked'); - this.$('.js-install').prop('disabled', !isAccepted); - }, - - onCategoryClick: function (e) { - e.preventDefault(); - this.model.trigger('filter', this.model); +import $ from 'jquery'; +import Backbone from 'backbone'; +import Marionette from 'backbone.marionette'; +import PluginChangelogView from './plugin-changelog-view'; +import './templates'; + +export default Marionette.ItemView.extend({ + tagName: 'li', + className: 'panel panel-vertical', + template: Templates['update-center-plugin'], + systemTemplate: Templates['update-center-system-update'], + + modelEvents: { + 'change:_hidden': 'toggleDisplay', + 'change': 'onModelChange', + 'request': 'onRequest' + }, + + events: { + 'click .js-changelog': 'onChangelogClick', + 'click .js-install': 'install', + 'click .js-update': 'update', + 'click .js-uninstall': 'uninstall', + 'change .js-terms': 'onTermsChange', + 'click .js-plugin-category': 'onCategoryClick' + }, + + getTemplate: function () { + return this.model.get('_system') ? this.systemTemplate : this.template; + }, + + onRender: function () { + this.$el.attr('data-id', this.model.id); + if (this.model.get('_system')) { + this.$el.attr('data-system', ''); } - }); + this.$('[data-toggle="tooltip"]').tooltip({ container: 'body', placement: 'bottom' }); + }, + onDestroy: function () { + this.$('[data-toggle="tooltip"]').tooltip('destroy'); + }, + + onModelChange: function () { + if (!this.model.hasChanged('_hidden')) { + this.render(); + } + }, + + onChangelogClick: function (e) { + e.preventDefault(); + e.stopPropagation(); + $('body').click(); + var index = $(e.currentTarget).data('idx'), + // if show changelog of update, show details of this update + // otherwise show changelog of the available release + update = this.model.has('release') ? this.model.toJSON() : this.model.get('updates')[index], + popup = new PluginChangelogView({ + triggerEl: $(e.currentTarget), + model: new Backbone.Model(update) + }); + popup.render(); + }, + + onRequest: function () { + this.$('.js-actions').addClass('hidden'); + this.$('.js-spinner').removeClass('hidden'); + }, + + toggleDisplay: function () { + this.$el.toggleClass('hidden', this.model.get('_hidden')); + }, + + install: function () { + this.model.install(); + }, + + update: function () { + this.model.update(); + }, + + uninstall: function () { + this.model.uninstall(); + }, + + onTermsChange: function () { + var isAccepted = this.$('.js-terms').is(':checked'); + this.$('.js-install').prop('disabled', !isAccepted); + }, + + onCategoryClick: function (e) { + e.preventDefault(); + this.model.trigger('filter', this.model); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/update-center/list-view.js b/server/sonar-web/src/main/js/apps/update-center/list-view.js index e188597e511..699e9c76a85 100644 --- a/server/sonar-web/src/main/js/apps/update-center/list-view.js +++ b/server/sonar-web/src/main/js/apps/update-center/list-view.js @@ -1,10 +1,9 @@ -define([ - './list-item-view' -], function (ListItemView) { - - return Marionette.CollectionView.extend({ - tagName: 'ul', - childView: ListItemView - }); +import Marionette from 'backbone.marionette'; +import ListItemView from './list-item-view'; +export default Marionette.CollectionView.extend({ + tagName: 'ul', + childView: ListItemView }); + + diff --git a/server/sonar-web/src/main/js/apps/update-center/plugin-changelog-view.js b/server/sonar-web/src/main/js/apps/update-center/plugin-changelog-view.js index 9ece2454bb7..56ce094b922 100644 --- a/server/sonar-web/src/main/js/apps/update-center/plugin-changelog-view.js +++ b/server/sonar-web/src/main/js/apps/update-center/plugin-changelog-view.js @@ -1,29 +1,28 @@ -define([ - 'components/common/popup', - './templates' -], function (Popup) { +import _ from 'underscore'; +import Popup from 'components/common/popup'; +import './templates'; - return Popup.extend({ - template: Templates['update-center-plugin-changelog'], +export default Popup.extend({ + template: Templates['update-center-plugin-changelog'], - onRender: function () { - this._super(); - this.$('.bubble-popup-container').isolatedScroll(); - this.$('[data-toggle="tooltip"]').tooltip({ container: 'body', placement: 'bottom' }); - }, + onRender: function () { + this._super(); + this.$('.bubble-popup-container').isolatedScroll(); + this.$('[data-toggle="tooltip"]').tooltip({ container: 'body', placement: 'bottom' }); + }, - onClose: function () { - this._super(); - this.$('[data-toggle="tooltip"]').tooltip('destroy'); - }, - - serializeData: function () { - return _.extend(this._super(), { - // if there is no status, this is a new plugin - // => force COMPATIBLE status - status: this.model.get('status') || 'COMPATIBLE' - }); - } - }); + onClose: function () { + this._super(); + this.$('[data-toggle="tooltip"]').tooltip('destroy'); + }, + serializeData: function () { + return _.extend(this._super(), { + // if there is no status, this is a new plugin + // => force COMPATIBLE status + status: this.model.get('status') || 'COMPATIBLE' + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/update-center/plugin.js b/server/sonar-web/src/main/js/apps/update-center/plugin.js index 697979e4ed0..5730d0e4525 100644 --- a/server/sonar-web/src/main/js/apps/update-center/plugin.js +++ b/server/sonar-web/src/main/js/apps/update-center/plugin.js @@ -1,70 +1,71 @@ -define(function () { +import _ from 'underscore'; +import Backbone from 'backbone'; - return Backbone.Model.extend({ - idAttribute: 'key', +export default Backbone.Model.extend({ + idAttribute: 'key', - defaults: { - _hidden: false, - _system: false - }, + defaults: { + _hidden: false, + _system: false + }, - _matchAttribute: function (attr, query) { - var value = this.get(attr) || ''; - return value.search(new RegExp(query, 'i')) !== -1; - }, + _matchAttribute: function (attr, query) { + var value = this.get(attr) || ''; + return value.search(new RegExp(query, 'i')) !== -1; + }, - match: function (query) { - return this._matchAttribute('name', query) || - this._matchAttribute('category', query) || - this._matchAttribute('description', query); - }, + match: function (query) { + return this._matchAttribute('name', query) || + this._matchAttribute('category', query) || + this._matchAttribute('description', query); + }, - _action: function (options) { - var that = this; - var opts = _.extend({}, options, { - type: 'POST', - data: { key: this.id }, - beforeSend: function () { - // disable global ajax notifications - }, - success: function () { - options.success(that); - }, - error: function (jqXHR) { - that.set({ _status: 'failed', _errors: jqXHR.responseJSON.errors }); - } - }); - var xhr = Backbone.ajax(opts); - this.trigger('request', this, xhr); - return xhr; - }, + _action: function (options) { + var that = this; + var opts = _.extend({}, options, { + type: 'POST', + data: { key: this.id }, + beforeSend: function () { + // disable global ajax notifications + }, + success: function () { + options.success(that); + }, + error: function (jqXHR) { + that.set({ _status: 'failed', _errors: jqXHR.responseJSON.errors }); + } + }); + var xhr = Backbone.ajax(opts); + this.trigger('request', this, xhr); + return xhr; + }, - install: function () { - return this._action({ - url: baseUrl + '/api/plugins/install', - success: function (model) { - model.set({ _status: 'installing' }); - } - }); - }, + install: function () { + return this._action({ + url: baseUrl + '/api/plugins/install', + success: function (model) { + model.set({ _status: 'installing' }); + } + }); + }, - update: function () { - return this._action({ - url: baseUrl + '/api/plugins/update', - success: function (model) { - model.set({ _status: 'installing' }); - } - }); - }, - - uninstall: function () { - return this._action({ - url: baseUrl + '/api/plugins/uninstall', - success: function (model) { - model.set({ _status: 'uninstalling' }); - } - }); - } - }); + update: function () { + return this._action({ + url: baseUrl + '/api/plugins/update', + success: function (model) { + model.set({ _status: 'installing' }); + } + }); + }, + uninstall: function () { + return this._action({ + url: baseUrl + '/api/plugins/uninstall', + success: function (model) { + model.set({ _status: 'uninstalling' }); + } + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/update-center/plugins.js b/server/sonar-web/src/main/js/apps/update-center/plugins.js index 021e124511c..5ae26d5f1d7 100644 --- a/server/sonar-web/src/main/js/apps/update-center/plugins.js +++ b/server/sonar-web/src/main/js/apps/update-center/plugins.js @@ -1,206 +1,205 @@ -define([ - './plugin' -], function (Plugin) { - - var $ = jQuery; - - var Plugins = Backbone.Collection.extend({ - model: Plugin, - - comparator: function (model) { - return model.get('name') || ''; - }, - - initialize: function () { - this._installedCount = 0; - this._uninstalledCount = 0; - this.listenTo(this, 'change:_status', this.onStatusChange); - }, - - parse: function (r) { - var that = this; - return r.plugins.map(function (plugin) { - var updates = [ - that._getLastWithStatus(plugin.updates, 'COMPATIBLE'), - that._getLastWithStatus(plugin.updates, 'REQUIRES_SYSTEM_UPGRADE'), - that._getLastWithStatus(plugin.updates, 'DEPS_REQUIRE_SYSTEM_UPGRADE') - ].filter(_.identity); - updates = updates.map(function (update) { - return that._extendChangelog(plugin.updates, update); - }); - return _.extend(plugin, { updates: updates }); - }); - }, - - _getLastWithStatus: function (updates, status) { - var index = _.findLastIndex(updates, function (update) { - return update.status === status; +import $ from 'jquery'; +import _ from 'underscore'; +import Backbone from 'backbone'; +import Plugin from './plugin'; + +var Plugins = Backbone.Collection.extend({ + model: Plugin, + + comparator: function (model) { + return model.get('name') || ''; + }, + + initialize: function () { + this._installedCount = 0; + this._uninstalledCount = 0; + this.listenTo(this, 'change:_status', this.onStatusChange); + }, + + parse: function (r) { + var that = this; + return r.plugins.map(function (plugin) { + var updates = [ + that._getLastWithStatus(plugin.updates, 'COMPATIBLE'), + that._getLastWithStatus(plugin.updates, 'REQUIRES_SYSTEM_UPGRADE'), + that._getLastWithStatus(plugin.updates, 'DEPS_REQUIRE_SYSTEM_UPGRADE') + ].filter(_.identity); + updates = updates.map(function (update) { + return that._extendChangelog(plugin.updates, update); }); - return index !== -1 ? updates[index] : null; - }, - - _extendChangelog: function (updates, update) { - var index = updates.indexOf(update); - var previousUpdates = index > 0 ? updates.slice(0, index) : []; - return _.extend(update, { previousUpdates: previousUpdates }); - }, - - _fetchInstalled: function () { - if (this._installed) { - return $.Deferred().resolve().promise(); + return _.extend(plugin, { updates: updates }); + }); + }, + + _getLastWithStatus: function (updates, status) { + var index = _.findLastIndex(updates, function (update) { + return update.status === status; + }); + return index !== -1 ? updates[index] : null; + }, + + _extendChangelog: function (updates, update) { + var index = updates.indexOf(update); + var previousUpdates = index > 0 ? updates.slice(0, index) : []; + return _.extend(update, { previousUpdates: previousUpdates }); + }, + + _fetchInstalled: function () { + if (this._installed) { + return $.Deferred().resolve().promise(); + } + var that = this; + var opts = { + type: 'GET', + url: baseUrl + '/api/plugins/installed', + success: function (r) { + that._installed = that.parse(r); } - var that = this; - var opts = { - type: 'GET', - url: baseUrl + '/api/plugins/installed', - success: function (r) { - that._installed = that.parse(r); - } - }; - return Backbone.ajax(opts); - }, - - _fetchUpdates: function () { - if (this._updates) { - return $.Deferred().resolve().promise(); + }; + return Backbone.ajax(opts); + }, + + _fetchUpdates: function () { + if (this._updates) { + return $.Deferred().resolve().promise(); + } + var that = this; + var opts = { + type: 'GET', + url: baseUrl + '/api/plugins/updates', + success: function (r) { + that._updates = that.parse(r); } - var that = this; - var opts = { - type: 'GET', - url: baseUrl + '/api/plugins/updates', - success: function (r) { - that._updates = that.parse(r); - } - }; - return Backbone.ajax(opts); - }, - - _fetchAvailable: function () { - if (this._available) { - return $.Deferred().resolve().promise(); + }; + return Backbone.ajax(opts); + }, + + _fetchAvailable: function () { + if (this._available) { + return $.Deferred().resolve().promise(); + } + var that = this; + var opts = { + type: 'GET', + url: baseUrl + '/api/plugins/available', + success: function (r) { + that._available = that.parse(r); } - var that = this; - var opts = { - type: 'GET', - url: baseUrl + '/api/plugins/available', - success: function (r) { - that._available = that.parse(r); - } - }; - return Backbone.ajax(opts); - }, - - _fetchPending: function () { - var that = this; - var opts = { - type: 'GET', - url: baseUrl + '/api/plugins/pending', - success: function (r) { - var installing = r.installing.map(function (plugin) { - return { key: plugin.key, _status: 'installing' }; - }), - uninstalling = r.removing.map(function (plugin) { - return { key: plugin.key, _status: 'uninstalling' }; - }); - that._installedCount = installing.length; - that._uninstalledCount = uninstalling.length; - that._pending = new Plugins([].concat(installing, uninstalling)).models; - } - }; - return Backbone.ajax(opts); - }, - - _fetchSystemUpgrades: function () { - if (this._systemUpdates) { - return $.Deferred().resolve().promise(); + }; + return Backbone.ajax(opts); + }, + + _fetchPending: function () { + var that = this; + var opts = { + type: 'GET', + url: baseUrl + '/api/plugins/pending', + success: function (r) { + var installing = r.installing.map(function (plugin) { + return { key: plugin.key, _status: 'installing' }; + }), + uninstalling = r.removing.map(function (plugin) { + return { key: plugin.key, _status: 'uninstalling' }; + }); + that._installedCount = installing.length; + that._uninstalledCount = uninstalling.length; + that._pending = new Plugins([].concat(installing, uninstalling)).models; } - var that = this; - var opts = { - type: 'GET', - url: baseUrl + '/api/system/upgrades', - success: function (r) { - that._systemUpdates = r.upgrades.map(function (update) { - return _.extend(update, { _system: true }); - }); - } - }; - return Backbone.ajax(opts); - }, - - fetchInstalled: function () { - var that = this; - return $.when(this._fetchInstalled(), this._fetchUpdates(), this._fetchPending()).done(function () { - var plugins = new Plugins(); - plugins.set(that._installed); - plugins.set(that._updates, { remove: false }); - plugins.set(that._pending, { add: false, remove: false }); - that.reset(plugins.models); - }); - }, - - fetchUpdates: function () { - var that = this; - return $.when(this._fetchInstalled(), this._fetchUpdates(), this._fetchPending()) - .done(function () { - var plugins = new Plugins(); - plugins.set(that._installed); - plugins.set(that._updates, { remove: true }); - plugins.set(that._pending, { add: false, remove: false }); - that.reset(plugins.models); - }); - }, - - fetchAvailable: function () { - var that = this; - return $.when(this._fetchAvailable(), this._fetchPending()).done(function () { - var plugins = new Plugins(); - plugins.set(that._available); - plugins.set(that._pending, { add: false, remove: false }); - that.reset(plugins.models); - }); - }, - - fetchSystemUpgrades: function () { - var that = this; - return $.when(this._fetchSystemUpgrades()).done(function () { - that.reset(that._systemUpdates); - }); - }, + }; + return Backbone.ajax(opts); + }, - search: function (query) { - this.filter(function (model) { - model.set({ _hidden: !model.match(query) }); - }); - }, - - cancelAll: function () { - var that = this; - var opts = { - type: 'POST', - url: baseUrl + '/api/plugins/cancel_all', - success: function () { - that._installedCount = 0; - that._uninstalledCount = 0; - that.forEach(function (model) { - model.unset('_status'); - }); - that.trigger('change'); - } - }; - return Backbone.ajax(opts); - }, - - onStatusChange: function (model, status) { - if (status === 'installing') { - this._installedCount++; + _fetchSystemUpgrades: function () { + if (this._systemUpdates) { + return $.Deferred().resolve().promise(); + } + var that = this; + var opts = { + type: 'GET', + url: baseUrl + '/api/system/upgrades', + success: function (r) { + that._systemUpdates = r.upgrades.map(function (update) { + return _.extend(update, { _system: true }); + }); } - if (status === 'uninstalling') { - this._uninstalledCount++; + }; + return Backbone.ajax(opts); + }, + + fetchInstalled: function () { + var that = this; + return $.when(this._fetchInstalled(), this._fetchUpdates(), this._fetchPending()).done(function () { + var plugins = new Plugins(); + plugins.set(that._installed); + plugins.set(that._updates, { remove: false }); + plugins.set(that._pending, { add: false, remove: false }); + that.reset(plugins.models); + }); + }, + + fetchUpdates: function () { + var that = this; + return $.when(this._fetchInstalled(), this._fetchUpdates(), this._fetchPending()) + .done(function () { + var plugins = new Plugins(); + plugins.set(that._installed); + plugins.set(that._updates, { remove: true }); + plugins.set(that._pending, { add: false, remove: false }); + that.reset(plugins.models); + }); + }, + + fetchAvailable: function () { + var that = this; + return $.when(this._fetchAvailable(), this._fetchPending()).done(function () { + var plugins = new Plugins(); + plugins.set(that._available); + plugins.set(that._pending, { add: false, remove: false }); + that.reset(plugins.models); + }); + }, + + fetchSystemUpgrades: function () { + var that = this; + return $.when(this._fetchSystemUpgrades()).done(function () { + that.reset(that._systemUpdates); + }); + }, + + search: function (query) { + this.filter(function (model) { + model.set({ _hidden: !model.match(query) }); + }); + }, + + cancelAll: function () { + var that = this; + var opts = { + type: 'POST', + url: baseUrl + '/api/plugins/cancel_all', + success: function () { + that._installedCount = 0; + that._uninstalledCount = 0; + that.forEach(function (model) { + model.unset('_status'); + }); + that.trigger('change'); } - this.trigger('change'); + }; + return Backbone.ajax(opts); + }, + + onStatusChange: function (model, status) { + if (status === 'installing') { + this._installedCount++; + } + if (status === 'uninstalling') { + this._uninstalledCount++; } - }); + this.trigger('change'); + } +}); + +export default Plugins; - return Plugins; -}); diff --git a/server/sonar-web/src/main/js/apps/update-center/router.js b/server/sonar-web/src/main/js/apps/update-center/router.js index 0a9af1440cc..25b2b7a3b95 100644 --- a/server/sonar-web/src/main/js/apps/update-center/router.js +++ b/server/sonar-web/src/main/js/apps/update-center/router.js @@ -1,37 +1,37 @@ -define(function () { - - return Backbone.Router.extend({ - routes: { - '': 'index', - 'installed': 'showInstalled', - 'updates': 'showUpdates', - 'available': 'showAvailable', - 'system': 'showSystemUpgrades' - }, - - initialize: function (options) { - this.controller = options.controller; - }, - - index: function () { - this.navigate('installed', { trigger: true, replace: true }); - }, - - showInstalled: function () { - this.controller.showInstalled(); - }, - - showUpdates: function () { - this.controller.showUpdates(); - }, - - showAvailable: function () { - this.controller.showAvailable(); - }, - - showSystemUpgrades: function () { - this.controller.showSystemUpgrades(); - } - }); - +import Backbone from 'backbone'; + +export default Backbone.Router.extend({ + routes: { + '': 'index', + 'installed': 'showInstalled', + 'updates': 'showUpdates', + 'available': 'showAvailable', + 'system': 'showSystemUpgrades' + }, + + initialize: function (options) { + this.controller = options.controller; + }, + + index: function () { + this.navigate('installed', { trigger: true, replace: true }); + }, + + showInstalled: function () { + this.controller.showInstalled(); + }, + + showUpdates: function () { + this.controller.showUpdates(); + }, + + showAvailable: function () { + this.controller.showAvailable(); + }, + + showSystemUpgrades: function () { + this.controller.showSystemUpgrades(); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/update-center/search-view.js b/server/sonar-web/src/main/js/apps/update-center/search-view.js index b46cf5ce293..739f11a2c96 100644 --- a/server/sonar-web/src/main/js/apps/update-center/search-view.js +++ b/server/sonar-web/src/main/js/apps/update-center/search-view.js @@ -1,84 +1,84 @@ -define([ - './templates' -], function () { - - return Marionette.ItemView.extend({ - template: Templates['update-center-search'], - - events: { - 'change [name="update-center-filter"]': 'onFilterChange', - - 'submit #update-center-search-form': 'onFormSubmit', - 'search #update-center-search-query': 'debouncedOnKeyUp', - 'keyup #update-center-search-query': 'debouncedOnKeyUp', - 'change #update-center-search-query': 'debouncedOnKeyUp' - }, - - collectionEvents: { - 'filter': 'onFilter' - }, - - initialize: function () { - this._bufferedValue = null; - this.debouncedOnKeyUp = _.debounce(this.onKeyUp, 50); - this.listenTo(this.options.state, 'change', this.render); - }, - - onRender: function () { - this.$('[data-toggle="tooltip"]').tooltip({ container: 'body', placement: 'bottom' }); - }, - - onDestroy: function () { - this.$('[data-toggle="tooltip"]').tooltip('destroy'); - }, - - onFilterChange: function () { - var value = this.$('[name="update-center-filter"]:checked').val(); - this.filter(value); - }, - - filter: function (value) { - this.options.router.navigate(value, { trigger: true }); - }, - - onFormSubmit: function (e) { - e.preventDefault(); - this.debouncedOnKeyUp(); - }, - - onKeyUp: function () { - var q = this.getQuery(); - if (q === this._bufferedValue) { - return; - } - this._bufferedValue = this.getQuery(); - this.search(q); - }, - - getQuery: function () { - return this.$('#update-center-search-query').val(); - }, - - search: function (q) { - this.collection.search(q); - }, - - focusSearch: function () { - var that = this; - setTimeout(function () { - that.$('#update-center-search-query').focus(); - }, 0); - }, - - onFilter: function (model) { - var q = model.get('category'); - this.$('#update-center-search-query').val(q); - this.search(q); - }, - - serializeData: function () { - return _.extend(this._super(), { state: this.options.state.toJSON() }); +import _ from 'underscore'; +import Marionette from 'backbone.marionette'; +import './templates'; + +export default Marionette.ItemView.extend({ + template: Templates['update-center-search'], + + events: { + 'change [name="update-center-filter"]': 'onFilterChange', + + 'submit #update-center-search-form': 'onFormSubmit', + 'search #update-center-search-query': 'debouncedOnKeyUp', + 'keyup #update-center-search-query': 'debouncedOnKeyUp', + 'change #update-center-search-query': 'debouncedOnKeyUp' + }, + + collectionEvents: { + 'filter': 'onFilter' + }, + + initialize: function () { + this._bufferedValue = null; + this.debouncedOnKeyUp = _.debounce(this.onKeyUp, 50); + this.listenTo(this.options.state, 'change', this.render); + }, + + onRender: function () { + this.$('[data-toggle="tooltip"]').tooltip({ container: 'body', placement: 'bottom' }); + }, + + onDestroy: function () { + this.$('[data-toggle="tooltip"]').tooltip('destroy'); + }, + + onFilterChange: function () { + var value = this.$('[name="update-center-filter"]:checked').val(); + this.filter(value); + }, + + filter: function (value) { + this.options.router.navigate(value, { trigger: true }); + }, + + onFormSubmit: function (e) { + e.preventDefault(); + this.debouncedOnKeyUp(); + }, + + onKeyUp: function () { + var q = this.getQuery(); + if (q === this._bufferedValue) { + return; } - }); - + this._bufferedValue = this.getQuery(); + this.search(q); + }, + + getQuery: function () { + return this.$('#update-center-search-query').val(); + }, + + search: function (q) { + this.collection.search(q); + }, + + focusSearch: function () { + var that = this; + setTimeout(function () { + that.$('#update-center-search-query').focus(); + }, 0); + }, + + onFilter: function (model) { + var q = model.get('category'); + this.$('#update-center-search-query').val(q); + this.search(q); + }, + + serializeData: function () { + return _.extend(this._super(), { state: this.options.state.toJSON() }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/users/app.js b/server/sonar-web/src/main/js/apps/users/app.js index 9fa9df3759a..cf64028a2e7 100644 --- a/server/sonar-web/src/main/js/apps/users/app.js +++ b/server/sonar-web/src/main/js/apps/users/app.js @@ -1,47 +1,46 @@ -define([ - './layout', - './users', - './header-view', - './search-view', - './list-view', - './list-footer-view' -], function (Layout, Users, HeaderView, SearchView, ListView, ListFooterView) { - - var App = new Marionette.Application(), - init = function (options) { - // Layout - this.layout = new Layout({ el: options.el }); - this.layout.render(); - - // Collection - this.users = new Users(); - - // Header View - this.headerView = new HeaderView({ collection: this.users }); - this.layout.headerRegion.show(this.headerView); - - // Search View - this.searchView = new SearchView({ collection: this.users }); - this.layout.searchRegion.show(this.searchView); - - // List View - this.listView = new ListView({ collection: this.users }); - this.layout.listRegion.show(this.listView); - - // List Footer View - this.listFooterView = new ListFooterView({ collection: this.users }); - this.layout.listFooterRegion.show(this.listFooterView); - - // Go! - this.users.fetch(); - }; - - App.on('start', function (options) { - window.requestMessages().done(function () { - init.call(App, options); - }); +import Marionette from 'backbone.marionette'; +import Layout from './layout'; +import Users from './users'; +import HeaderView from './header-view'; +import SearchView from './search-view'; +import ListView from './list-view'; +import ListFooterView from './list-footer-view'; + +var App = new Marionette.Application(), + init = function (options) { + // Layout + this.layout = new Layout({ el: options.el }); + this.layout.render(); + + // Collection + this.users = new Users(); + + // Header View + this.headerView = new HeaderView({ collection: this.users }); + this.layout.headerRegion.show(this.headerView); + + // Search View + this.searchView = new SearchView({ collection: this.users }); + this.layout.searchRegion.show(this.searchView); + + // List View + this.listView = new ListView({ collection: this.users }); + this.layout.listRegion.show(this.listView); + + // List Footer View + this.listFooterView = new ListFooterView({ collection: this.users }); + this.layout.listFooterRegion.show(this.listFooterView); + + // Go! + this.users.fetch(); + }; + +App.on('start', function (options) { + window.requestMessages().done(function () { + init.call(App, options); }); +}); + +export default App; - return App; -}); diff --git a/server/sonar-web/src/main/js/apps/users/change-password-view.js b/server/sonar-web/src/main/js/apps/users/change-password-view.js index 659d3012a79..f8b9f95eb60 100644 --- a/server/sonar-web/src/main/js/apps/users/change-password-view.js +++ b/server/sonar-web/src/main/js/apps/users/change-password-view.js @@ -1,37 +1,35 @@ -define([ - 'components/common/modal-form', - './templates' -], function (ModalForm) { +import ModalForm from 'components/common/modal-form'; +import './templates'; - return ModalForm.extend({ - template: Templates['users-change-password'], +export default ModalForm.extend({ + template: Templates['users-change-password'], - onFormSubmit: function (e) { - this._super(e); - this.sendRequest(); - }, + onFormSubmit: function (e) { + this._super(e); + this.sendRequest(); + }, - sendRequest: function () { - var that = this, - password = this.$('#change-user-password-password').val(), - confirmation = this.$('#change-user-password-password-confirmation').val(); - if (password !== confirmation) { - that.showErrors([{ msg: 'New password and its confirmation do not match' }]); - return; - } - this.disableForm(); - return this.model.changePassword(password, { - statusCode: { - // do not show global error - 400: null - } - }).done(function () { - that.destroy(); - }).fail(function (jqXHR) { - that.enableForm(); - that.showErrors(jqXHR.responseJSON.errors, jqXHR.responseJSON.warnings); - }); + sendRequest: function () { + var that = this, + password = this.$('#change-user-password-password').val(), + confirmation = this.$('#change-user-password-password-confirmation').val(); + if (password !== confirmation) { + that.showErrors([{ msg: 'New password and its confirmation do not match' }]); + return; } - }); - + this.disableForm(); + return this.model.changePassword(password, { + statusCode: { + // do not show global error + 400: null + } + }).done(function () { + that.destroy(); + }).fail(function (jqXHR) { + that.enableForm(); + that.showErrors(jqXHR.responseJSON.errors, jqXHR.responseJSON.warnings); + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/users/create-view.js b/server/sonar-web/src/main/js/apps/users/create-view.js index 743035362ad..84e2bbdade1 100644 --- a/server/sonar-web/src/main/js/apps/users/create-view.js +++ b/server/sonar-web/src/main/js/apps/users/create-view.js @@ -1,34 +1,32 @@ -define([ - './user', - './form-view' -], function (User, FormView) { +import User from './user'; +import FormView from './form-view'; - return FormView.extend({ - - sendRequest: function () { - var that = this, - user = new User({ - login: this.$('#create-user-login').val(), - name: this.$('#create-user-name').val(), - email: this.$('#create-user-email').val(), - password: this.$('#create-user-password').val(), - scmAccounts: this.getScmAccounts() - }); - this.disableForm(); - return user.save(null, { - statusCode: { - // do not show global error - 400: null, - 500: null - } - }).done(function () { - that.collection.refresh(); - that.destroy(); - }).fail(function (jqXHR) { - that.enableForm(); - that.showErrors(jqXHR.responseJSON.errors, jqXHR.responseJSON.warnings); - }); - } - }); +export default FormView.extend({ + sendRequest: function () { + var that = this, + user = new User({ + login: this.$('#create-user-login').val(), + name: this.$('#create-user-name').val(), + email: this.$('#create-user-email').val(), + password: this.$('#create-user-password').val(), + scmAccounts: this.getScmAccounts() + }); + this.disableForm(); + return user.save(null, { + statusCode: { + // do not show global error + 400: null, + 500: null + } + }).done(function () { + that.collection.refresh(); + that.destroy(); + }).fail(function (jqXHR) { + that.enableForm(); + that.showErrors(jqXHR.responseJSON.errors, jqXHR.responseJSON.warnings); + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/users/deactivate-view.js b/server/sonar-web/src/main/js/apps/users/deactivate-view.js index 000a350ea57..bf7cbe80489 100644 --- a/server/sonar-web/src/main/js/apps/users/deactivate-view.js +++ b/server/sonar-web/src/main/js/apps/users/deactivate-view.js @@ -1,32 +1,30 @@ -define([ - 'components/common/modal-form', - './templates' -], function (ModalForm) { +import ModalForm from 'components/common/modal-form'; +import './templates'; - return ModalForm.extend({ - template: Templates['users-deactivate'], +export default ModalForm.extend({ + template: Templates['users-deactivate'], - onFormSubmit: function (e) { - this._super(e); - this.sendRequest(); - }, - - sendRequest: function () { - var that = this, - collection = this.model.collection; - return this.model.destroy({ - wait: true, - statusCode: { - // do not show global error - 400: null - } - }).done(function () { - collection.total--; - that.destroy(); - }).fail(function (jqXHR) { - that.showErrors(jqXHR.responseJSON.errors, jqXHR.responseJSON.warnings); - }); - } - }); + onFormSubmit: function (e) { + this._super(e); + this.sendRequest(); + }, + sendRequest: function () { + var that = this, + collection = this.model.collection; + return this.model.destroy({ + wait: true, + statusCode: { + // do not show global error + 400: null + } + }).done(function () { + collection.total--; + that.destroy(); + }).fail(function (jqXHR) { + that.showErrors(jqXHR.responseJSON.errors, jqXHR.responseJSON.warnings); + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/users/form-view.js b/server/sonar-web/src/main/js/apps/users/form-view.js index 50b18c1d237..71bd7716038 100644 --- a/server/sonar-web/src/main/js/apps/users/form-view.js +++ b/server/sonar-web/src/main/js/apps/users/form-view.js @@ -1,52 +1,50 @@ -define([ - 'components/common/modal-form', - './templates' -], function (ModalForm) { - - var $ = jQuery; - - return ModalForm.extend({ - template: Templates['users-form'], - - events: function () { - return _.extend(this._super(), { - 'click #create-user-add-scm-account': 'onAddScmAccountClick' - }); - }, - - onRender: function () { - this._super(); - this.$('[data-toggle="tooltip"]').tooltip({ container: 'body', placement: 'bottom' }); - }, - - onDestroy: function () { - this._super(); - this.$('[data-toggle="tooltip"]').tooltip('destroy'); - }, - - onFormSubmit: function (e) { - this._super(e); - this.sendRequest(); - }, - - onAddScmAccountClick: function (e) { - e.preventDefault(); - this.addScmAccount(); - }, - - getScmAccounts: function () { - var scmAccounts = this.$('[name="scmAccounts"]').map(function () { - return $(this).val(); - }).toArray(); - return scmAccounts.filter(function (value) { - return !!value; - }); - }, - - addScmAccount: function () { - var fields = this.$('[name="scmAccounts"]'); - fields.first().clone().val('').insertAfter(fields.last()); - } - }); - +import $ from 'jquery'; +import _ from 'underscore'; +import ModalForm from 'components/common/modal-form'; +import './templates'; + +export default ModalForm.extend({ + template: Templates['users-form'], + + events: function () { + return _.extend(this._super(), { + 'click #create-user-add-scm-account': 'onAddScmAccountClick' + }); + }, + + onRender: function () { + this._super(); + this.$('[data-toggle="tooltip"]').tooltip({ container: 'body', placement: 'bottom' }); + }, + + onDestroy: function () { + this._super(); + this.$('[data-toggle="tooltip"]').tooltip('destroy'); + }, + + onFormSubmit: function (e) { + this._super(e); + this.sendRequest(); + }, + + onAddScmAccountClick: function (e) { + e.preventDefault(); + this.addScmAccount(); + }, + + getScmAccounts: function () { + var scmAccounts = this.$('[name="scmAccounts"]').map(function () { + return $(this).val(); + }).toArray(); + return scmAccounts.filter(function (value) { + return !!value; + }); + }, + + addScmAccount: function () { + var fields = this.$('[name="scmAccounts"]'); + fields.first().clone().val('').insertAfter(fields.last()); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/users/groups-view.js b/server/sonar-web/src/main/js/apps/users/groups-view.js index 09a127fc6fd..f402b931cb8 100644 --- a/server/sonar-web/src/main/js/apps/users/groups-view.js +++ b/server/sonar-web/src/main/js/apps/users/groups-view.js @@ -1,43 +1,41 @@ -define([ - 'components/common/modals', - 'components/common/select-list', - './templates' -], function (Modal) { +import Modal from 'components/common/modals'; +import 'components/common/select-list'; +import './templates'; - return Modal.extend({ - template: Templates['users-groups'], - itemTemplate: Templates['users-group'], +export default Modal.extend({ + template: Templates['users-groups'], + itemTemplate: Templates['users-group'], - onRender: function () { - this._super(); - new window.SelectList({ - el: this.$('#users-groups'), - width: '100%', - readOnly: false, - focusSearch: false, - format: function (item) { - return item.name + '
' + item.description + ''; - }, - queryParam: 'q', - searchUrl: baseUrl + '/api/users/groups?ps=100&login=' + this.model.id, - selectUrl: baseUrl + '/api/usergroups/add_user', - deselectUrl: baseUrl + '/api/usergroups/remove_user', - extra: { - login: this.model.id - }, - selectParameter: 'id', - selectParameterValue: 'id', - parse: function (r) { - this.more = false; - return r.groups; - } - }); - }, - - onDestroy: function () { - this.model.collection.refresh(); - Modal.prototype.onDestroy.apply(this, arguments); - } - }); + onRender: function () { + this._super(); + new window.SelectList({ + el: this.$('#users-groups'), + width: '100%', + readOnly: false, + focusSearch: false, + format: function (item) { + return item.name + '
' + item.description + ''; + }, + queryParam: 'q', + searchUrl: baseUrl + '/api/users/groups?ps=100&login=' + this.model.id, + selectUrl: baseUrl + '/api/usergroups/add_user', + deselectUrl: baseUrl + '/api/usergroups/remove_user', + extra: { + login: this.model.id + }, + selectParameter: 'id', + selectParameterValue: 'id', + parse: function (r) { + this.more = false; + return r.groups; + } + }); + }, + onDestroy: function () { + this.model.collection.refresh(); + Modal.prototype.onDestroy.apply(this, arguments); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/users/header-view.js b/server/sonar-web/src/main/js/apps/users/header-view.js index c8b76193b4c..ae9bae8e422 100644 --- a/server/sonar-web/src/main/js/apps/users/header-view.js +++ b/server/sonar-web/src/main/js/apps/users/header-view.js @@ -1,25 +1,24 @@ -define([ - './create-view', - './templates' -], function (CreateView) { +import Marionette from 'backbone.marionette'; +import CreateView from './create-view'; +import './templates'; - return Marionette.ItemView.extend({ - template: Templates['users-header'], +export default Marionette.ItemView.extend({ + template: Templates['users-header'], - events: { - 'click #users-create': 'onCreateClick' - }, + events: { + 'click #users-create': 'onCreateClick' + }, - onCreateClick: function (e) { - e.preventDefault(); - this.createUser(); - }, - - createUser: function () { - new CreateView({ - collection: this.collection - }).render(); - } - }); + onCreateClick: function (e) { + e.preventDefault(); + this.createUser(); + }, + createUser: function () { + new CreateView({ + collection: this.collection + }).render(); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/users/layout.js b/server/sonar-web/src/main/js/apps/users/layout.js index 9acb054bdad..90866f6f6e1 100644 --- a/server/sonar-web/src/main/js/apps/users/layout.js +++ b/server/sonar-web/src/main/js/apps/users/layout.js @@ -1,16 +1,15 @@ -define([ - './templates' -], function () { +import Marionette from 'backbone.marionette'; +import './templates'; - return Marionette.LayoutView.extend({ - template: Templates['users-layout'], - - regions: { - headerRegion: '#users-header', - searchRegion: '#users-search', - listRegion: '#users-list', - listFooterRegion: '#users-list-footer' - } - }); +export default Marionette.LayoutView.extend({ + template: Templates['users-layout'], + regions: { + headerRegion: '#users-header', + searchRegion: '#users-search', + listRegion: '#users-list', + listFooterRegion: '#users-list-footer' + } }); + + diff --git a/server/sonar-web/src/main/js/apps/users/list-footer-view.js b/server/sonar-web/src/main/js/apps/users/list-footer-view.js index cf802586354..7c4d2482efa 100644 --- a/server/sonar-web/src/main/js/apps/users/list-footer-view.js +++ b/server/sonar-web/src/main/js/apps/users/list-footer-view.js @@ -1,34 +1,34 @@ -define([ - './templates' -], function () { - - return Marionette.ItemView.extend({ - template: Templates['users-list-footer'], - - collectionEvents: { - 'all': 'render' - }, - - events: { - 'click #users-fetch-more': 'onMoreClick' - }, - - onMoreClick: function (e) { - e.preventDefault(); - this.fetchMore(); - }, - - fetchMore: function () { - this.collection.fetchMore(); - }, - - serializeData: function () { - return _.extend(this._super(), { - total: this.collection.total, - count: this.collection.length, - more: this.collection.hasMore() - }); - } - }); +import _ from 'underscore'; +import Marionette from 'backbone.marionette'; +import './templates'; +export default Marionette.ItemView.extend({ + template: Templates['users-list-footer'], + + collectionEvents: { + 'all': 'render' + }, + + events: { + 'click #users-fetch-more': 'onMoreClick' + }, + + onMoreClick: function (e) { + e.preventDefault(); + this.fetchMore(); + }, + + fetchMore: function () { + this.collection.fetchMore(); + }, + + serializeData: function () { + return _.extend(this._super(), { + total: this.collection.total, + count: this.collection.length, + more: this.collection.hasMore() + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/users/list-item-view.js b/server/sonar-web/src/main/js/apps/users/list-item-view.js index b11e39e2766..50e864992fa 100644 --- a/server/sonar-web/src/main/js/apps/users/list-item-view.js +++ b/server/sonar-web/src/main/js/apps/users/list-item-view.js @@ -1,113 +1,113 @@ -define([ - './update-view', - './change-password-view', - './deactivate-view', - './groups-view', - './templates' -], function (UpdateView, ChangePasswordView, DeactivateView, GroupsView) { - - return Marionette.ItemView.extend({ - tagName: 'li', - className: 'panel panel-vertical', - template: Templates['users-list-item'], - - events: { - 'click .js-user-more-scm': 'onMoreScmClick', - 'click .js-user-more-groups': 'onMoreGroupsClick', - 'click .js-user-update': 'onUpdateClick', - 'click .js-user-change-password': 'onChangePasswordClick', - 'click .js-user-deactivate': 'onDeactivateClick', - 'click .js-user-groups': 'onGroupsClick' - }, - - initialize: function () { - this.scmLimit = 3; - this.groupsLimit = 3; - }, - - onRender: function () { - this.$el.attr('data-login', this.model.id); - this.$('[data-toggle="tooltip"]').tooltip({ container: 'body', placement: 'bottom' }); - }, - - onDestroy: function () { - this.$('[data-toggle="tooltip"]').tooltip('destroy'); - }, - - onMoreScmClick: function (e) { - e.preventDefault(); - this.showMoreScm(); - }, - - onMoreGroupsClick: function (e) { - e.preventDefault(); - this.showMoreGroups(); - }, - - onUpdateClick: function (e) { - e.preventDefault(); - this.updateUser(); - }, - - onChangePasswordClick: function (e) { - e.preventDefault(); - this.changePassword(); - }, - - onDeactivateClick: function (e) { - e.preventDefault(); - this.deactivateUser(); - }, - - onGroupsClick: function (e) { - e.preventDefault(); - this.showGroups(); - }, - - showMoreScm: function () { - this.scmLimit = 10000; - this.render(); - }, - - showMoreGroups: function () { - this.groupsLimit = 10000; - this.render(); - }, - - updateUser: function () { - new UpdateView({ - model: this.model, - collection: this.model.collection - }).render(); - }, - - changePassword: function () { - new ChangePasswordView({ - model: this.model, - collection: this.model.collection - }).render(); - }, - - deactivateUser: function () { - new DeactivateView({ model: this.model }).render(); - }, - - showGroups: function () { - new GroupsView({ model: this.model }).render(); - }, - - serializeData: function () { - var scmAccounts = this.model.get('scmAccounts'), - scmAccountsLimit = scmAccounts.length > this.scmLimit ? this.scmLimit - 1 : this.scmLimit, - groups = this.model.get('groups'), - groupsLimit = groups.length > this.groupsLimit ? this.groupsLimit - 1 : this.groupsLimit; - return _.extend(this._super(), { - firstScmAccounts: _.first(scmAccounts, scmAccountsLimit), - moreScmAccountsCount: scmAccounts.length - scmAccountsLimit, - firstGroups: _.first(groups, groupsLimit), - moreGroupsCount: groups.length - groupsLimit - }); - } - }); - +import _ from 'underscore'; +import Marionette from 'backbone.marionette'; +import UpdateView from './update-view'; +import ChangePasswordView from './change-password-view'; +import DeactivateView from './deactivate-view'; +import GroupsView from './groups-view'; +import './templates'; + +export default Marionette.ItemView.extend({ + tagName: 'li', + className: 'panel panel-vertical', + template: Templates['users-list-item'], + + events: { + 'click .js-user-more-scm': 'onMoreScmClick', + 'click .js-user-more-groups': 'onMoreGroupsClick', + 'click .js-user-update': 'onUpdateClick', + 'click .js-user-change-password': 'onChangePasswordClick', + 'click .js-user-deactivate': 'onDeactivateClick', + 'click .js-user-groups': 'onGroupsClick' + }, + + initialize: function () { + this.scmLimit = 3; + this.groupsLimit = 3; + }, + + onRender: function () { + this.$el.attr('data-login', this.model.id); + this.$('[data-toggle="tooltip"]').tooltip({ container: 'body', placement: 'bottom' }); + }, + + onDestroy: function () { + this.$('[data-toggle="tooltip"]').tooltip('destroy'); + }, + + onMoreScmClick: function (e) { + e.preventDefault(); + this.showMoreScm(); + }, + + onMoreGroupsClick: function (e) { + e.preventDefault(); + this.showMoreGroups(); + }, + + onUpdateClick: function (e) { + e.preventDefault(); + this.updateUser(); + }, + + onChangePasswordClick: function (e) { + e.preventDefault(); + this.changePassword(); + }, + + onDeactivateClick: function (e) { + e.preventDefault(); + this.deactivateUser(); + }, + + onGroupsClick: function (e) { + e.preventDefault(); + this.showGroups(); + }, + + showMoreScm: function () { + this.scmLimit = 10000; + this.render(); + }, + + showMoreGroups: function () { + this.groupsLimit = 10000; + this.render(); + }, + + updateUser: function () { + new UpdateView({ + model: this.model, + collection: this.model.collection + }).render(); + }, + + changePassword: function () { + new ChangePasswordView({ + model: this.model, + collection: this.model.collection + }).render(); + }, + + deactivateUser: function () { + new DeactivateView({ model: this.model }).render(); + }, + + showGroups: function () { + new GroupsView({ model: this.model }).render(); + }, + + serializeData: function () { + var scmAccounts = this.model.get('scmAccounts'), + scmAccountsLimit = scmAccounts.length > this.scmLimit ? this.scmLimit - 1 : this.scmLimit, + groups = this.model.get('groups'), + groupsLimit = groups.length > this.groupsLimit ? this.groupsLimit - 1 : this.groupsLimit; + return _.extend(this._super(), { + firstScmAccounts: _.first(scmAccounts, scmAccountsLimit), + moreScmAccountsCount: scmAccounts.length - scmAccountsLimit, + firstGroups: _.first(groups, groupsLimit), + moreGroupsCount: groups.length - groupsLimit + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/users/list-view.js b/server/sonar-web/src/main/js/apps/users/list-view.js index 24878864d30..695bf2ac034 100644 --- a/server/sonar-web/src/main/js/apps/users/list-view.js +++ b/server/sonar-web/src/main/js/apps/users/list-view.js @@ -1,11 +1,10 @@ -define([ - './list-item-view', - './templates' -], function (ListItemView) { - - return Marionette.CollectionView.extend({ - tagName: 'ul', - childView: ListItemView - }); +import Marionette from 'backbone.marionette'; +import ListItemView from './list-item-view'; +import './templates'; +export default Marionette.CollectionView.extend({ + tagName: 'ul', + childView: ListItemView }); + + diff --git a/server/sonar-web/src/main/js/apps/users/search-view.js b/server/sonar-web/src/main/js/apps/users/search-view.js index 5129bf5a253..114f0971e71 100644 --- a/server/sonar-web/src/main/js/apps/users/search-view.js +++ b/server/sonar-web/src/main/js/apps/users/search-view.js @@ -1,49 +1,49 @@ -define([ - './templates' -], function () { - - return Marionette.ItemView.extend({ - template: Templates['users-search'], - - events: { - 'submit #users-search-form': 'onFormSubmit', - 'search #users-search-query': 'debouncedOnKeyUp', - 'keyup #users-search-query': 'debouncedOnKeyUp' - }, - - initialize: function () { - this._bufferedValue = null; - this.debouncedOnKeyUp = _.debounce(this.onKeyUp, 400); - }, - - onRender: function () { - this.delegateEvents(); - }, - - onFormSubmit: function (e) { - e.preventDefault(); - this.debouncedOnKeyUp(); - }, - - onKeyUp: function () { - var q = this.getQuery(); - if (q === this._bufferedValue) { - return; - } - this._bufferedValue = this.getQuery(); - if (this.searchRequest != null) { - this.searchRequest.abort(); - } - this.searchRequest = this.search(q); - }, - - getQuery: function () { - return this.$('#users-search-query').val(); - }, - - search: function (q) { - return this.collection.fetch({ reset: true, data: { q: q } }); +import _ from 'underscore'; +import Marionette from 'backbone.marionette'; +import './templates'; + +export default Marionette.ItemView.extend({ + template: Templates['users-search'], + + events: { + 'submit #users-search-form': 'onFormSubmit', + 'search #users-search-query': 'debouncedOnKeyUp', + 'keyup #users-search-query': 'debouncedOnKeyUp' + }, + + initialize: function () { + this._bufferedValue = null; + this.debouncedOnKeyUp = _.debounce(this.onKeyUp, 400); + }, + + onRender: function () { + this.delegateEvents(); + }, + + onFormSubmit: function (e) { + e.preventDefault(); + this.debouncedOnKeyUp(); + }, + + onKeyUp: function () { + var q = this.getQuery(); + if (q === this._bufferedValue) { + return; } - }); + this._bufferedValue = this.getQuery(); + if (this.searchRequest != null) { + this.searchRequest.abort(); + } + this.searchRequest = this.search(q); + }, + + getQuery: function () { + return this.$('#users-search-query').val(); + }, + search: function (q) { + return this.collection.fetch({ reset: true, data: { q: q } }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/users/update-view.js b/server/sonar-web/src/main/js/apps/users/update-view.js index b276b79ba42..42a83c9fdd6 100644 --- a/server/sonar-web/src/main/js/apps/users/update-view.js +++ b/server/sonar-web/src/main/js/apps/users/update-view.js @@ -1,30 +1,28 @@ -define([ - './form-view' -], function (FormView) { +import FormView from './form-view'; - return FormView.extend({ - - sendRequest: function () { - var that = this; - this.model.set({ - name: this.$('#create-user-name').val(), - email: this.$('#create-user-email').val(), - scmAccounts: this.getScmAccounts() - }); - this.disableForm(); - return this.model.save(null, { - statusCode: { - // do not show global error - 400: null - } - }).done(function () { - that.collection.refresh(); - that.destroy(); - }).fail(function (jqXHR) { - that.enableForm(); - that.showErrors(jqXHR.responseJSON.errors, jqXHR.responseJSON.warnings); - }); - } - }); +export default FormView.extend({ + sendRequest: function () { + var that = this; + this.model.set({ + name: this.$('#create-user-name').val(), + email: this.$('#create-user-email').val(), + scmAccounts: this.getScmAccounts() + }); + this.disableForm(); + return this.model.save(null, { + statusCode: { + // do not show global error + 400: null + } + }).done(function () { + that.collection.refresh(); + that.destroy(); + }).fail(function (jqXHR) { + that.enableForm(); + that.showErrors(jqXHR.responseJSON.errors, jqXHR.responseJSON.warnings); + }); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/users/user.js b/server/sonar-web/src/main/js/apps/users/user.js index 746ffe8bdd7..3c041571ddb 100644 --- a/server/sonar-web/src/main/js/apps/users/user.js +++ b/server/sonar-web/src/main/js/apps/users/user.js @@ -1,71 +1,72 @@ -define(function () { +import _ from 'underscore'; +import Backbone from 'backbone'; - return Backbone.Model.extend({ - idAttribute: 'login', +export default Backbone.Model.extend({ + idAttribute: 'login', - urlRoot: function () { - return baseUrl + '/api/users'; - }, + urlRoot: function () { + return baseUrl + '/api/users'; + }, - defaults: function () { - return { - groups: [], - scmAccounts: [] - }; - }, + defaults: function () { + return { + groups: [], + scmAccounts: [] + }; + }, - toQuery: function () { - var q = this.toJSON(); - _.each(q, function (value, key) { - if (_.isArray(value)) { - q[key] = value.join(','); - } - }); - return q; - }, - - isNew: function() { - // server never sends a password - return this.has('password'); - }, - - sync: function (method, model, options) { - var opts = options || {}; - if (method === 'create') { - _.defaults(opts, { - url: this.urlRoot() + '/create', - type: 'POST', - data: _.pick(model.toQuery(), 'login', 'name', 'email', 'password', 'scmAccounts') - }); - } - if (method === 'update') { - _.defaults(opts, { - url: this.urlRoot() + '/update', - type: 'POST', - data: _.pick(model.toQuery(), 'login', 'name', 'email', 'scmAccounts') - }); + toQuery: function () { + var q = this.toJSON(); + _.each(q, function (value, key) { + if (_.isArray(value)) { + q[key] = value.join(','); } - if (method === 'delete') { - _.defaults(opts, { - url: this.urlRoot() + '/deactivate', - type: 'POST', - data: { login: this.id } - }); - } - return Backbone.ajax(opts); - }, + }); + return q; + }, + + isNew: function () { + // server never sends a password + return this.has('password'); + }, - changePassword: function (password, options) { - var opts = _.defaults(options || {}, { - url: this.urlRoot() + '/change_password', + sync: function (method, model, options) { + var opts = options || {}; + if (method === 'create') { + _.defaults(opts, { + url: this.urlRoot() + '/create', type: 'POST', - data: { - login: this.id, - password: password - } + data: _.pick(model.toQuery(), 'login', 'name', 'email', 'password', 'scmAccounts') }); - return Backbone.ajax(opts); } - }); + if (method === 'update') { + _.defaults(opts, { + url: this.urlRoot() + '/update', + type: 'POST', + data: _.pick(model.toQuery(), 'login', 'name', 'email', 'scmAccounts') + }); + } + if (method === 'delete') { + _.defaults(opts, { + url: this.urlRoot() + '/deactivate', + type: 'POST', + data: { login: this.id } + }); + } + return Backbone.ajax(opts); + }, + changePassword: function (password, options) { + var opts = _.defaults(options || {}, { + url: this.urlRoot() + '/change_password', + type: 'POST', + data: { + login: this.id, + password: password + } + }); + return Backbone.ajax(opts); + } }); + + diff --git a/server/sonar-web/src/main/js/apps/users/users.js b/server/sonar-web/src/main/js/apps/users/users.js index 9c45979a9fe..a123212ace9 100644 --- a/server/sonar-web/src/main/js/apps/users/users.js +++ b/server/sonar-web/src/main/js/apps/users/users.js @@ -1,40 +1,39 @@ -define([ - './user' -], function (User) { +import Backbone from 'backbone'; +import User from './user'; + +export default Backbone.Collection.extend({ + model: User, + + url: function () { + return baseUrl + '/api/users/search'; + }, + + parse: function (r) { + this.total = +r.total; + this.p = +r.p; + this.ps = +r.ps; + return r.users; + }, + + fetch: function (options) { + var d = (options && options.data) || {}; + this.q = d.q; + return this._super(options); + }, + + fetchMore: function () { + var p = this.p + 1; + return this.fetch({ add: true, remove: false, data: { p: p, ps: this.ps, q: this.q } }); + }, + + refresh: function () { + return this.fetch({ reset: true, data: { q: this.q } }); + }, + + hasMore: function () { + return this.total > this.p * this.ps; + } - return Backbone.Collection.extend({ - model: User, - - url: function () { - return baseUrl + '/api/users/search'; - }, - - parse: function (r) { - this.total = +r.total; - this.p = +r.p; - this.ps = +r.ps; - return r.users; - }, - - fetch: function (options) { - var d = (options && options.data) || {}; - this.q = d.q; - return this._super(options); - }, - - fetchMore: function () { - var p = this.p + 1; - return this.fetch({ add: true, remove: false, data: { p: p, ps: this.ps, q: this.q } }); - }, - - refresh: function () { - return this.fetch({ reset: true, data: { q: this.q } }); - }, - - hasMore: function () { - return this.total > this.p * this.ps; - } +}); - }); -}); -- 2.39.5