From 52a0578e61c4e9d8496b2e77ea5cabb95c1d5a72 Mon Sep 17 00:00:00 2001 From: Stas Vilchik Date: Thu, 9 Apr 2015 17:19:55 +0200 Subject: [PATCH] SONAR-5851 add profile details, implement profile actions --- .../quality-profiles-actions.hbs | 19 ++ .../quality-profiles-copy-profile.hbs | 16 ++ .../quality-profiles-create-profile.hbs | 24 +++ .../quality-profiles-delete-profile.hbs | 13 ++ .../quality-profiles-layout.hbs | 13 ++ .../quality-profiles-profile-details.hbs | 36 ++++ .../quality-profiles-profile-header.hbs | 17 ++ .../quality-profiles-profile.hbs | 4 + .../quality-profiles-profiles-language.hbs | 1 + .../quality-profiles-profiles.hbs | 1 + .../quality-profiles-rename-profile.hbs | 16 ++ ...ity-profiles-restore-built-in-profiles.hbs | 20 +++ .../quality-profiles-restore-profile.hbs | 17 ++ .../src/main/js/common/file-upload.js | 65 +++++++ .../main/js/quality-profiles/actions-view.js | 83 +++++++++ .../src/main/js/quality-profiles/app.js | 61 ++++++- .../main/js/quality-profiles/controller.js | 120 +++++++++++++ .../js/quality-profiles/copy-profile-view.js | 61 +++++++ .../quality-profiles/create-profile-view.js | 77 +++++++++ .../quality-profiles/delete-profile-view.js | 59 +++++++ .../src/main/js/quality-profiles/layout.js | 45 +++++ .../quality-profiles/profile-details-view.js | 74 ++++++++ .../quality-profiles/profile-header-view.js | 92 ++++++++++ .../main/js/quality-profiles/profile-view.js | 47 +++++ .../src/main/js/quality-profiles/profile.js | 30 ++++ .../main/js/quality-profiles/profiles-view.js | 70 ++++++++ .../src/main/js/quality-profiles/profiles.js | 34 ++++ .../quality-profiles/rename-profile-view.js | 61 +++++++ .../restore-built-in-profiles-view.js | 70 ++++++++ .../quality-profiles/restore-profile-view.js | 47 +++++ .../src/main/js/quality-profiles/router.js | 42 +++++ .../src/main/js/third-party/backbone.js | 163 ++++++++++-------- .../quality_profiles_controller.rb | 4 + .../app/views/profiles/_restore_form.html.erb | 2 +- .../resources/org/sonar/l10n/core.properties | 6 +- 35 files changed, 1439 insertions(+), 71 deletions(-) create mode 100644 server/sonar-web/src/main/hbs/quality-profiles/quality-profiles-actions.hbs create mode 100644 server/sonar-web/src/main/hbs/quality-profiles/quality-profiles-copy-profile.hbs create mode 100644 server/sonar-web/src/main/hbs/quality-profiles/quality-profiles-create-profile.hbs create mode 100644 server/sonar-web/src/main/hbs/quality-profiles/quality-profiles-delete-profile.hbs create mode 100644 server/sonar-web/src/main/hbs/quality-profiles/quality-profiles-layout.hbs create mode 100644 server/sonar-web/src/main/hbs/quality-profiles/quality-profiles-profile-details.hbs create mode 100644 server/sonar-web/src/main/hbs/quality-profiles/quality-profiles-profile-header.hbs create mode 100644 server/sonar-web/src/main/hbs/quality-profiles/quality-profiles-profile.hbs create mode 100644 server/sonar-web/src/main/hbs/quality-profiles/quality-profiles-profiles-language.hbs create mode 100644 server/sonar-web/src/main/hbs/quality-profiles/quality-profiles-profiles.hbs create mode 100644 server/sonar-web/src/main/hbs/quality-profiles/quality-profiles-rename-profile.hbs create mode 100644 server/sonar-web/src/main/hbs/quality-profiles/quality-profiles-restore-built-in-profiles.hbs create mode 100644 server/sonar-web/src/main/hbs/quality-profiles/quality-profiles-restore-profile.hbs create mode 100644 server/sonar-web/src/main/js/common/file-upload.js create mode 100644 server/sonar-web/src/main/js/quality-profiles/actions-view.js create mode 100644 server/sonar-web/src/main/js/quality-profiles/controller.js create mode 100644 server/sonar-web/src/main/js/quality-profiles/copy-profile-view.js create mode 100644 server/sonar-web/src/main/js/quality-profiles/create-profile-view.js create mode 100644 server/sonar-web/src/main/js/quality-profiles/delete-profile-view.js create mode 100644 server/sonar-web/src/main/js/quality-profiles/layout.js create mode 100644 server/sonar-web/src/main/js/quality-profiles/profile-details-view.js create mode 100644 server/sonar-web/src/main/js/quality-profiles/profile-header-view.js create mode 100644 server/sonar-web/src/main/js/quality-profiles/profile-view.js create mode 100644 server/sonar-web/src/main/js/quality-profiles/profile.js create mode 100644 server/sonar-web/src/main/js/quality-profiles/profiles-view.js create mode 100644 server/sonar-web/src/main/js/quality-profiles/profiles.js create mode 100644 server/sonar-web/src/main/js/quality-profiles/rename-profile-view.js create mode 100644 server/sonar-web/src/main/js/quality-profiles/restore-built-in-profiles-view.js create mode 100644 server/sonar-web/src/main/js/quality-profiles/restore-profile-view.js create mode 100644 server/sonar-web/src/main/js/quality-profiles/router.js diff --git a/server/sonar-web/src/main/hbs/quality-profiles/quality-profiles-actions.hbs b/server/sonar-web/src/main/hbs/quality-profiles/quality-profiles-actions.hbs new file mode 100644 index 00000000000..d78c76b513a --- /dev/null +++ b/server/sonar-web/src/main/hbs/quality-profiles/quality-profiles-actions.hbs @@ -0,0 +1,19 @@ +

{{t 'quality_profiles.page'}}

+ +
+ +
diff --git a/server/sonar-web/src/main/hbs/quality-profiles/quality-profiles-copy-profile.hbs b/server/sonar-web/src/main/hbs/quality-profiles/quality-profiles-copy-profile.hbs new file mode 100644 index 00000000000..5d352d68412 --- /dev/null +++ b/server/sonar-web/src/main/hbs/quality-profiles/quality-profiles-copy-profile.hbs @@ -0,0 +1,16 @@ +
+ + + +
diff --git a/server/sonar-web/src/main/hbs/quality-profiles/quality-profiles-create-profile.hbs b/server/sonar-web/src/main/hbs/quality-profiles/quality-profiles-create-profile.hbs new file mode 100644 index 00000000000..1a16c954460 --- /dev/null +++ b/server/sonar-web/src/main/hbs/quality-profiles/quality-profiles-create-profile.hbs @@ -0,0 +1,24 @@ +
+ + + +
diff --git a/server/sonar-web/src/main/hbs/quality-profiles/quality-profiles-delete-profile.hbs b/server/sonar-web/src/main/hbs/quality-profiles/quality-profiles-delete-profile.hbs new file mode 100644 index 00000000000..960f447e4f8 --- /dev/null +++ b/server/sonar-web/src/main/hbs/quality-profiles/quality-profiles-delete-profile.hbs @@ -0,0 +1,13 @@ +
+ + + +
diff --git a/server/sonar-web/src/main/hbs/quality-profiles/quality-profiles-layout.hbs b/server/sonar-web/src/main/hbs/quality-profiles/quality-profiles-layout.hbs new file mode 100644 index 00000000000..e171121f21a --- /dev/null +++ b/server/sonar-web/src/main/hbs/quality-profiles/quality-profiles-layout.hbs @@ -0,0 +1,13 @@ +
+
+
+ +
+
Work in progress... please no feedback yet
+
+
+ +
+
+
+
diff --git a/server/sonar-web/src/main/hbs/quality-profiles/quality-profiles-profile-details.hbs b/server/sonar-web/src/main/hbs/quality-profiles/quality-profiles-profile-details.hbs new file mode 100644 index 00000000000..4409201bcd2 --- /dev/null +++ b/server/sonar-web/src/main/hbs/quality-profiles/quality-profiles-profile-details.hbs @@ -0,0 +1,36 @@ +

{{t 'coding_rules'}}

+

Total: {{formatMeasure activeRuleCount 'INT'}}

+{{#notEmpty rulesSeverities}} + +{{/notEmpty}} + +
+ +

{{t 'projects'}}

+{{#if isDefault}} +

{{t 'quality_profiles.projects_for_default.edit'}}

+{{else}} +
+{{/if}} + +
+ +

{{t 'permalinks'}}

+

Coming soon...

+ +
+ +

{{t 'quality_profiles.profile_inheritance'}}

+

Coming soon...

+ +
+ +

{{t 'changelog'}}

+

Coming soon...

diff --git a/server/sonar-web/src/main/hbs/quality-profiles/quality-profiles-profile-header.hbs b/server/sonar-web/src/main/hbs/quality-profiles/quality-profiles-profile-header.hbs new file mode 100644 index 00000000000..00ba0b100de --- /dev/null +++ b/server/sonar-web/src/main/hbs/quality-profiles/quality-profiles-profile-header.hbs @@ -0,0 +1,17 @@ +

+ {{name}} + {{languageName}} +

+ +
+
+ {{t 'backup_verb'}} + + + {{#unless isDefault}} + + + {{/unless}} +
+
diff --git a/server/sonar-web/src/main/hbs/quality-profiles/quality-profiles-profile.hbs b/server/sonar-web/src/main/hbs/quality-profiles/quality-profiles-profile.hbs new file mode 100644 index 00000000000..0eb92a7ff7c --- /dev/null +++ b/server/sonar-web/src/main/hbs/quality-profiles/quality-profiles-profile.hbs @@ -0,0 +1,4 @@ +{{name}} +{{#if isDefault}} + {{t 'default'}} +{{/if}} diff --git a/server/sonar-web/src/main/hbs/quality-profiles/quality-profiles-profiles-language.hbs b/server/sonar-web/src/main/hbs/quality-profiles/quality-profiles-profiles-language.hbs new file mode 100644 index 00000000000..e7288e85f87 --- /dev/null +++ b/server/sonar-web/src/main/hbs/quality-profiles/quality-profiles-profiles-language.hbs @@ -0,0 +1 @@ +
{{languageName}}
diff --git a/server/sonar-web/src/main/hbs/quality-profiles/quality-profiles-profiles.hbs b/server/sonar-web/src/main/hbs/quality-profiles/quality-profiles-profiles.hbs new file mode 100644 index 00000000000..8022059ffad --- /dev/null +++ b/server/sonar-web/src/main/hbs/quality-profiles/quality-profiles-profiles.hbs @@ -0,0 +1 @@ +
diff --git a/server/sonar-web/src/main/hbs/quality-profiles/quality-profiles-rename-profile.hbs b/server/sonar-web/src/main/hbs/quality-profiles/quality-profiles-rename-profile.hbs new file mode 100644 index 00000000000..a7250b2f43c --- /dev/null +++ b/server/sonar-web/src/main/hbs/quality-profiles/quality-profiles-rename-profile.hbs @@ -0,0 +1,16 @@ +
+ + + +
diff --git a/server/sonar-web/src/main/hbs/quality-profiles/quality-profiles-restore-built-in-profiles.hbs b/server/sonar-web/src/main/hbs/quality-profiles/quality-profiles-restore-built-in-profiles.hbs new file mode 100644 index 00000000000..44c02a80497 --- /dev/null +++ b/server/sonar-web/src/main/hbs/quality-profiles/quality-profiles-restore-built-in-profiles.hbs @@ -0,0 +1,20 @@ +
+ + + +
diff --git a/server/sonar-web/src/main/hbs/quality-profiles/quality-profiles-restore-profile.hbs b/server/sonar-web/src/main/hbs/quality-profiles/quality-profiles-restore-profile.hbs new file mode 100644 index 00000000000..30edf580e71 --- /dev/null +++ b/server/sonar-web/src/main/hbs/quality-profiles/quality-profiles-restore-profile.hbs @@ -0,0 +1,17 @@ + +
+ + +
diff --git a/server/sonar-web/src/main/js/common/file-upload.js b/server/sonar-web/src/main/js/common/file-upload.js new file mode 100644 index 00000000000..266d2b12903 --- /dev/null +++ b/server/sonar-web/src/main/js/common/file-upload.js @@ -0,0 +1,65 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +define(function () { + + var $ = jQuery; + + function createFrame () { + var uuid = _.uniqueId('upload-form-'); + return $('') + .prop('frameborder', 0) + .prop('width', 0) + .prop('height', 0) + .prop('id', uuid) + .prop('name', uuid) + .css('display', 'none'); + } + + return function (options) { + var deferred = new $.Deferred(), + body = $('body'), + frame = createFrame(), + parent = options.form.parent(), + clonedForm = options.form.detach(); + + clonedForm + .prop('target', frame.prop('id')) + .appendTo(frame); + + frame.appendTo(body); + + frame.on('load', function () { + var result = this.contentWindow.document.body.textContent; + try { + var js = JSON.parse(result); + deferred.resolve(js); + } catch (e) { + deferred.resolve(result); + } + clonedForm.detach().appendTo(parent); + frame.off('load').remove(); + }); + + clonedForm.submit(); + + return deferred.promise(); + }; + +}); diff --git a/server/sonar-web/src/main/js/quality-profiles/actions-view.js b/server/sonar-web/src/main/js/quality-profiles/actions-view.js new file mode 100644 index 00000000000..d06e62675af --- /dev/null +++ b/server/sonar-web/src/main/js/quality-profiles/actions-view.js @@ -0,0 +1,83 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +define([ + 'quality-profiles/create-profile-view', + 'quality-profiles/restore-profile-view', + 'quality-profiles/restore-built-in-profiles-view', + 'templates/quality-profiles' +], 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' + }, + + onCreateClick: function (e) { + e.preventDefault(); + this.create(); + }, + + onRestoreClick: function (e) { + e.preventDefault(); + this.restore(); + }, + + onRestoreBuiltInClick: function (e) { + e.preventDefault(); + this.restoreBuiltIn(); + }, + + create: function () { + var that = this; + this.requestLanguages().done(function (r) { + new CreateProfileView({ + collection: that.collection, + languages: r.languages + }).render(); + }); + }, + + restore: function () { + new RestoreProfileView().render(); + }, + + restoreBuiltIn: function () { + var that = this; + this.requestLanguages().done(function (r) { + new RestoreBuiltInProfilesView({ + collection: that.collection, + languages: r.languages + }).render(); + }); + }, + + requestLanguages: function () { + var url = baseUrl + '/api/languages/list'; + return $.get(url); + } + }); + +}); diff --git a/server/sonar-web/src/main/js/quality-profiles/app.js b/server/sonar-web/src/main/js/quality-profiles/app.js index 5fb1b6cc539..9fe2f97ac10 100644 --- a/server/sonar-web/src/main/js/quality-profiles/app.js +++ b/server/sonar-web/src/main/js/quality-profiles/app.js @@ -1,8 +1,67 @@ -require([], function () { +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +require([ + 'quality-profiles/router', + 'quality-profiles/controller', + 'quality-profiles/layout', + 'quality-profiles/profiles', + 'quality-profiles/actions-view', + 'quality-profiles/profiles-view' +], function (Router, Controller, Layout, Profiles, ActionsView, ProfilesView) { var $ = jQuery, App = new Marionette.Application(); + App.on('start', function () { + // Layout + this.layout = new Layout({ el: '#quality-profiles' }); + 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 + }); + this.layout.actionsRegion.show(this.actionsView); + + // Profiles View + this.profilesView = new ProfilesView({ + collection: this.profiles + }); + this.layout.resultsRegion.show(this.profilesView); + + // Router + this.router = new Router({ app: this }); + Backbone.history.start({ + pushState: true, + root: baseUrl + '/quality_profiles' + }); + + }); + window.requestMessages().done(function () { App.start(); }); diff --git a/server/sonar-web/src/main/js/quality-profiles/controller.js b/server/sonar-web/src/main/js/quality-profiles/controller.js new file mode 100644 index 00000000000..041ad870960 --- /dev/null +++ b/server/sonar-web/src/main/js/quality-profiles/controller.js @@ -0,0 +1,120 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +define([ + 'quality-profiles/profile-header-view', + 'quality-profiles/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, 'copy', this.onProfileCopy); + 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); + } + }); + }, + + onProfileSelect: function (profile) { + var that = this, + key = profile.get('key'), + route = 'show?key=' + encodeURIComponent(key); + this.options.app.router.navigate(route); + this.options.app.profilesView.highlight(key); + this.fetchProfile(profile).done(function () { + var profileHeaderView = new ProfileHeaderView({ model: profile }); + that.options.app.layout.headerRegion.show(profileHeaderView); + + var profileDetailsView = new ProfileDetailsView({ model: profile }); + that.options.app.layout.detailsRegion.show(profileDetailsView); + }); + }, + + onProfileCopy: function (name, profile) { + var that = this, + lang = profile.get('language'); + this.fetchProfiles().done(function () { + var newProfile = that.options.app.profiles.findWhere({ language: lang, name: name }); + if (newProfile != null) { + newProfile.trigger('select', newProfile); + } + }); + }, + + 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(); + }, + + fetchProfiles: function () { + return this.options.app.profiles.fetch({ reset: true }); + }, + + fetchProfile: function (profile) { + return $.when(this.fetchProfileRules(profile)); + }, + + fetchProfileRules: function (profile) { + var url = baseUrl + '/api/rules/search', + key = profile.get('key'), + options = { + ps: 1, + facets: 'severities', + qprofile: key, + activation: 'true' + }; + return $.get(url, options).done(function (r) { + var severityFacet = _.findWhere(r.facets, { property: 'severities' }); + if (severityFacet != null) { + profile.set({ rulesSeverities: severityFacet.values }); + } + }); + } + + }); + +}); diff --git a/server/sonar-web/src/main/js/quality-profiles/copy-profile-view.js b/server/sonar-web/src/main/js/quality-profiles/copy-profile-view.js new file mode 100644 index 00000000000..b46b3639eb2 --- /dev/null +++ b/server/sonar-web/src/main/js/quality-profiles/copy-profile-view.js @@ -0,0 +1,61 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +define([ + 'common/modal-form', + 'templates/quality-profiles' +], function (ModalFormView) { + + var $ = jQuery; + + return ModalFormView.extend({ + template: Templates['quality-profiles-copy-profile'], + + onFormSubmit: function () { + ModalFormView.prototype.onFormSubmit.apply(this, arguments); + this.sendRequest(); + }, + + sendRequest: function () { + var that = this, + url = baseUrl + '/api/qualityprofiles/copy', + name = this.$('#copy-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 () { + // TODO open new profile using key from response + that.model.trigger('copy', name, that.model); + that.close(); + }).fail(function (jqXHR) { + that.showErrors(jqXHR.responseJSON.errors, jqXHR.responseJSON.warnings); + }); + } + }); + +}); diff --git a/server/sonar-web/src/main/js/quality-profiles/create-profile-view.js b/server/sonar-web/src/main/js/quality-profiles/create-profile-view.js new file mode 100644 index 00000000000..9724dc03821 --- /dev/null +++ b/server/sonar-web/src/main/js/quality-profiles/create-profile-view.js @@ -0,0 +1,77 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +define([ + 'common/modal-form', + 'quality-profiles/profile', + 'templates/quality-profiles' +], function (ModalFormView, Profile) { + + var $ = jQuery; + + return ModalFormView.extend({ + template: Templates['quality-profiles-create-profile'], + + onFormSubmit: function (e) { + ModalFormView.prototype.onFormSubmit.apply(this, arguments); + this.sendRequest($(e.currentTarget)); + }, + + onRender: function () { + ModalFormView.prototype.onRender.apply(this, arguments); + this.$('select').select2({ + width: '250px', + minimumResultsForSearch: 50 + }); + }, + + sendRequest: function (form) { + var that = this, + url = baseUrl + '/api/qualityprofiles/create', + options = form.serialize(); + return $.ajax({ + type: 'POST', + url: url, + data: options, + statusCode: { + // do not show global error + 400: null + } + }).done(function (r) { + that.addProfile(r.profile); + that.close(); + }).fail(function (jqXHR) { + that.showErrors(jqXHR.responseJSON.errors, jqXHR.responseJSON.warnings); + }); + }, + + 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 + }); + } + }); + +}); diff --git a/server/sonar-web/src/main/js/quality-profiles/delete-profile-view.js b/server/sonar-web/src/main/js/quality-profiles/delete-profile-view.js new file mode 100644 index 00000000000..2c23638432d --- /dev/null +++ b/server/sonar-web/src/main/js/quality-profiles/delete-profile-view.js @@ -0,0 +1,59 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +define([ + 'common/modal-form', + 'templates/quality-profiles' +], function (ModalFormView) { + + var $ = jQuery; + + return ModalFormView.extend({ + template: Templates['quality-profiles-delete-profile'], + + modelEvents: { + 'destroy': 'close' + }, + + onFormSubmit: function () { + ModalFormView.prototype.onFormSubmit.apply(this, arguments); + 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.trigger('destroy', that.model, that.model.collection); + }).fail(function (jqXHR) { + that.showErrors(jqXHR.responseJSON.errors, jqXHR.responseJSON.warnings); + }); + } + }); + +}); diff --git a/server/sonar-web/src/main/js/quality-profiles/layout.js b/server/sonar-web/src/main/js/quality-profiles/layout.js new file mode 100644 index 00000000000..5a0b5686d77 --- /dev/null +++ b/server/sonar-web/src/main/js/quality-profiles/layout.js @@ -0,0 +1,45 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +define([ + 'templates/quality-profiles' +], function () { + + var $ = jQuery; + + return Marionette.Layout.extend({ + template: Templates['quality-profiles-layout'], + + regions: { + headerRegion: '.search-navigator-workspace-header', + actionsRegion: '.search-navigator-filters', + resultsRegion: '.quality-profiles-results', + detailsRegion: '.search-navigator-workspace-list' + }, + + onRender: function () { + var navigator = $('.search-navigator'); + navigator.addClass('sticky'); + 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/quality-profiles/profile-details-view.js b/server/sonar-web/src/main/js/quality-profiles/profile-details-view.js new file mode 100644 index 00000000000..a4af7dbff0d --- /dev/null +++ b/server/sonar-web/src/main/js/quality-profiles/profile-details-view.js @@ -0,0 +1,74 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +define([ + 'common/select-list', + 'templates/quality-profiles' +], function () { + + return Marionette.ItemView.extend({ + template: Templates['quality-profiles-profile-details'], + + modelEvents: { + 'change': 'render' + }, + + onRender: function () { + var key = this.model.get('key'); + if (!this.model.get('isDefault')) { + new SelectList({ + el: this.$('#quality-profile-projects'), + width: '100%', + readOnly: false, + 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: 'key', + 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 () { + 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 + }); + } + }); + +}); diff --git a/server/sonar-web/src/main/js/quality-profiles/profile-header-view.js b/server/sonar-web/src/main/js/quality-profiles/profile-header-view.js new file mode 100644 index 00000000000..0ea480936b8 --- /dev/null +++ b/server/sonar-web/src/main/js/quality-profiles/profile-header-view.js @@ -0,0 +1,92 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +define([ + 'quality-profiles/copy-profile-view', + 'quality-profiles/rename-profile-view', + 'quality-profiles/delete-profile-view', + 'templates/quality-profiles' +], function (ProfileCopyView, ProfileRenameView, ProfileDeleteView) { + + var $ = jQuery; + + return Marionette.ItemView.extend({ + template: Templates['quality-profiles-profile-header'], + + 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' + }, + + onBackupClick: function (e) { + $(e.currentTarget).blur(); + }, + + onCopyClick: function (e) { + e.preventDefault(); + this.copy(); + }, + + onRenameClick: function (e) { + e.preventDefault(); + this.rename(); + }, + + onDefaultClick: function (e) { + e.preventDefault(); + this.setAsDefault(); + }, + + onDeleteClick: function (e) { + e.preventDefault(); + this.delete(); + }, + + copy: function () { + new ProfileCopyView({ model: this.model }).render(); + }, + + rename: function () { + new ProfileRenameView({ model: this.model }).render(); + }, + + setAsDefault: function () { + this.model.trigger('setAsDefault', this.model); + }, + + 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) + }); + } + }); + +}); diff --git a/server/sonar-web/src/main/js/quality-profiles/profile-view.js b/server/sonar-web/src/main/js/quality-profiles/profile-view.js new file mode 100644 index 00000000000..8739aec7faf --- /dev/null +++ b/server/sonar-web/src/main/js/quality-profiles/profile-view.js @@ -0,0 +1,47 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +define([ + 'templates/quality-profiles' +], 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); + }, + + onClick: function (e) { + e.preventDefault(); + this.model.trigger('select', this.model); + } + }); + +}); diff --git a/server/sonar-web/src/main/js/quality-profiles/profile.js b/server/sonar-web/src/main/js/quality-profiles/profile.js new file mode 100644 index 00000000000..6c1d9684946 --- /dev/null +++ b/server/sonar-web/src/main/js/quality-profiles/profile.js @@ -0,0 +1,30 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +define(function () { + + return Backbone.Model.extend({ + idAttribute: 'key', + + defaults: { + activeRuleCount: 0 + } + }); + +}); diff --git a/server/sonar-web/src/main/js/quality-profiles/profiles-view.js b/server/sonar-web/src/main/js/quality-profiles/profiles-view.js new file mode 100644 index 00000000000..fe2e1a97dd8 --- /dev/null +++ b/server/sonar-web/src/main/js/quality-profiles/profiles-view.js @@ -0,0 +1,70 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +define([ + 'quality-profiles/profile-view', + 'templates/quality-profiles' +], function (ProfileView) { + + return Marionette.CompositeView.extend({ + className: 'list-group', + template: Templates['quality-profiles-profiles'], + languageTemplate: Templates['quality-profiles-profiles-language'], + itemView: ProfileView, + itemViewContainer: '.js-list', + + itemViewOptions: function (model) { + return { + collectionView: this, + highlighted: model.get('key') === this.highlighted + }; + }, + + highlight: function (key) { + this.highlighted = key; + this.render(); + }, + + appendHtml: function (compositeView, itemView, index) { + var $container = this.getItemViewContainer(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())); + } + } + return $container.append(itemView.el); + }, + + closeChildren: function () { + Marionette.CompositeView.prototype.closeChildren.apply(this, arguments); + this.$('.js-list-language').remove(); + } + }); + +}); diff --git a/server/sonar-web/src/main/js/quality-profiles/profiles.js b/server/sonar-web/src/main/js/quality-profiles/profiles.js new file mode 100644 index 00000000000..c7d5c45f397 --- /dev/null +++ b/server/sonar-web/src/main/js/quality-profiles/profiles.js @@ -0,0 +1,34 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +define([ + 'quality-profiles/profile' +], function (Profile) { + + return Backbone.Collection.extend({ + model: Profile, + url: baseUrl + '/api/qualityprofiles/search', + comparator: 'key', + + parse: function (r) { + return r.profiles; + } + }); + +}); diff --git a/server/sonar-web/src/main/js/quality-profiles/rename-profile-view.js b/server/sonar-web/src/main/js/quality-profiles/rename-profile-view.js new file mode 100644 index 00000000000..be565a4cbab --- /dev/null +++ b/server/sonar-web/src/main/js/quality-profiles/rename-profile-view.js @@ -0,0 +1,61 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +define([ + 'common/modal-form', + 'templates/quality-profiles' +], function (ModalFormView) { + + var $ = jQuery; + + return ModalFormView.extend({ + template: Templates['quality-profiles-rename-profile'], + + onFormSubmit: function () { + ModalFormView.prototype.onFormSubmit.apply(this, arguments); + this.sendRequest(); + }, + + sendRequest: function () { + // TODO change name input id + var that = this, + url = baseUrl + '/api/qualityprofiles/rename', + name = this.$('#new-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.close(); + }).fail(function (jqXHR) { + that.showErrors(jqXHR.responseJSON.errors, jqXHR.responseJSON.warnings); + }); + } + }); + +}); diff --git a/server/sonar-web/src/main/js/quality-profiles/restore-built-in-profiles-view.js b/server/sonar-web/src/main/js/quality-profiles/restore-built-in-profiles-view.js new file mode 100644 index 00000000000..6fb509d56e1 --- /dev/null +++ b/server/sonar-web/src/main/js/quality-profiles/restore-built-in-profiles-view.js @@ -0,0 +1,70 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +define([ + 'common/modal-form', + 'templates/quality-profiles' +], function (ModalFormView) { + + var $ = jQuery; + + return ModalFormView.extend({ + template: Templates['quality-profiles-restore-built-in-profiles'], + + onFormSubmit: function (e) { + ModalFormView.prototype.onFormSubmit.apply(this, arguments); + this.sendRequest($(e.currentTarget)); + }, + + onRender: function () { + ModalFormView.prototype.onRender.apply(this, arguments); + this.$('select').select2({ + width: '250px', + minimumResultsForSearch: 50 + }); + }, + + sendRequest: function (form) { + var that = this, + url = baseUrl + '/api/qualityprofiles/restore_built_in', + options = form.serialize(); + return $.ajax({ + type: 'POST', + url: url, + data: options, + statusCode: { + // do not show global error + 400: null + } + }).done(function () { + that.collection.fetch({ reset: true }); + that.close(); + }).fail(function (jqXHR) { + that.showErrors(jqXHR.responseJSON.errors, jqXHR.responseJSON.warnings); + }); + }, + + serializeData: function () { + return _.extend(ModalFormView.prototype.serializeData.apply(this, arguments), { + languages: this.options.languages + }); + } + }); + +}); diff --git a/server/sonar-web/src/main/js/quality-profiles/restore-profile-view.js b/server/sonar-web/src/main/js/quality-profiles/restore-profile-view.js new file mode 100644 index 00000000000..6cd06e01c4b --- /dev/null +++ b/server/sonar-web/src/main/js/quality-profiles/restore-profile-view.js @@ -0,0 +1,47 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +define([ + 'common/modal-form', + 'common/file-upload', + 'templates/quality-profiles' +], function (ModalFormView, uploader) { + + var $ = jQuery; + + 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 (typeof r === 'object') { + if (_.isArray(r.errors) || _.isArray(r.warning)) { + that.showErrors(r.errors, r.warnings); + return; + } + } + that.collection.fetch(); + that.close(); + }); + } + }); + +}); diff --git a/server/sonar-web/src/main/js/quality-profiles/router.js b/server/sonar-web/src/main/js/quality-profiles/router.js new file mode 100644 index 00000000000..521dea6a04a --- /dev/null +++ b/server/sonar-web/src/main/js/quality-profiles/router.js @@ -0,0 +1,42 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +define(function () { + + return Backbone.Router.extend({ + routes: { + '': 'index', + 'index': 'index', + 'show?key=:key': 'show' + }, + + initialize: function (options) { + this.app = options.app; + }, + + index: function () { + this.app.controller.index(); + }, + + show: function (key) { + this.app.controller.show(key); + } + }); + +}); diff --git a/server/sonar-web/src/main/js/third-party/backbone.js b/server/sonar-web/src/main/js/third-party/backbone.js index ff3784a1489..b1508ff0e46 100644 --- a/server/sonar-web/src/main/js/third-party/backbone.js +++ b/server/sonar-web/src/main/js/third-party/backbone.js @@ -17,23 +17,38 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -// Backbone.js 1.1.0 +// Backbone.js 1.1.2 -// (c) 2010-2011 Jeremy Ashkenas, DocumentCloud Inc. -// (c) 2011-2013 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors +// (c) 2010-2014 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors // Backbone may be freely distributed under the MIT license. // For all details and documentation: // http://backbonejs.org -(function(){ +(function(root, factory) { + + // Set up Backbone appropriately for the environment. Start with AMD. + if (typeof define === 'function' && define.amd) { + define(['underscore', 'jquery', 'exports'], function(_, $, exports) { + // Export global even in AMD case in case this script is loaded with + // others that may still expect a global Backbone. + root.Backbone = factory(root, exports, _, $); + }); + + // Next for Node.js or CommonJS. jQuery may not be needed as a module. + } else if (typeof exports !== 'undefined') { + var _ = require('underscore'); + factory(root, exports, _); + + // Finally, as a browser global. + } else { + root.Backbone = factory(root, {}, root._, (root.jQuery || root.Zepto || root.ender || root.$)); + } + +}(this, function(root, Backbone, _, $) { // Initial Setup // ------------- - // Save a reference to the global object (`window` in the browser, `exports` - // on the server). - var root = this; - // Save the previous value of the `Backbone` variable, so that it can be // restored later on, if `noConflict` is used. var previousBackbone = root.Backbone; @@ -44,25 +59,12 @@ var slice = array.slice; var splice = array.splice; - // The top-level namespace. All public Backbone classes and modules will - // be attached to this. Exported for both the browser and the server. - var Backbone; - if (typeof exports !== 'undefined') { - Backbone = exports; - } else { - Backbone = root.Backbone = {}; - } - // Current version of the library. Keep in sync with `package.json`. - Backbone.VERSION = '1.1.0'; - - // Require Underscore, if we're on the server, and it's not already present. - var _ = root._; - if (!_ && (typeof require !== 'undefined')) _ = require('underscore'); + Backbone.VERSION = '1.1.2'; // For Backbone's purposes, jQuery, Zepto, Ender, or My Library (kidding) owns // the `$` variable. - Backbone.$ = root.jQuery || root.Zepto || root.ender || root.$; + Backbone.$ = $; // Runs Backbone.js in *noConflict* mode, returning the `Backbone` variable // to its previous owner. Returns a reference to this Backbone object. @@ -128,7 +130,7 @@ var retain, ev, events, names, i, l, j, k; if (!this._events || !eventsApi(this, 'off', name, [callback, context])) return this; if (!name && !callback && !context) { - this._events = {}; + this._events = void 0; return this; } names = name ? [name] : _.keys(this._events); @@ -224,7 +226,7 @@ case 1: while (++i < l) (ev = events[i]).callback.call(ev.ctx, a1); return; case 2: while (++i < l) (ev = events[i]).callback.call(ev.ctx, a1, a2); return; case 3: while (++i < l) (ev = events[i]).callback.call(ev.ctx, a1, a2, a3); return; - default: while (++i < l) (ev = events[i]).callback.apply(ev.ctx, args); + default: while (++i < l) (ev = events[i]).callback.apply(ev.ctx, args); return; } }; @@ -369,7 +371,7 @@ // Trigger all relevant attribute changes. if (!silent) { - if (changes.length) this._pending = true; + if (changes.length) this._pending = options; for (var i = 0, l = changes.length; i < l; i++) { this.trigger('change:' + changes[i], this, current[changes[i]], options); } @@ -380,6 +382,7 @@ if (changing) return this; if (!silent) { while (this._pending) { + options = this._pending; this._pending = false; this.trigger('change', this, options); } @@ -547,9 +550,12 @@ // using Backbone's restful methods, override this to change the endpoint // that will be called. url: function() { - var base = _.result(this, 'urlRoot') || _.result(this.collection, 'url') || urlError(); + var base = + _.result(this, 'urlRoot') || + _.result(this.collection, 'url') || + urlError(); if (this.isNew()) return base; - return base + (base.charAt(base.length - 1) === '/' ? '' : '/') + encodeURIComponent(this.id); + return base.replace(/([^\/])$/, '$1/') + encodeURIComponent(this.id); }, // **parse** converts a response into the hash of attributes to be `set` on @@ -565,7 +571,7 @@ // A model is new if it has never been saved to the server, and lacks an id. isNew: function() { - return this.id == null; + return !this.has(this.idAttribute); }, // Check if the model is currently in a valid state. @@ -669,7 +675,7 @@ options.index = index; model.trigger('remove', model, this, options); } - this._removeReference(model); + this._removeReference(model, options); } return singular ? models[0] : models; }, @@ -695,11 +701,11 @@ // Turn bare objects into model references, and prevent invalid models // from being added. for (i = 0, l = models.length; i < l; i++) { - attrs = models[i]; + attrs = models[i] || {}; if (attrs instanceof Model) { id = model = attrs; } else { - id = attrs[targetModel.prototype.idAttribute]; + id = attrs[targetModel.prototype.idAttribute || 'id']; } // If a duplicate is found, prevent it from being added and @@ -719,14 +725,13 @@ model = models[i] = this._prepareModel(attrs, options); if (!model) continue; toAdd.push(model); - - // Listen to added models' events, and index models for lookup by - // `id` and by `cid`. - model.on('all', this._onModelEvent, this); - this._byId[model.cid] = model; - if (model.id != null) this._byId[model.id] = model; + this._addReference(model, options); } - if (order) order.push(existing || model); + + // Do not add multiple models with the same `id`. + model = existing || model; + if (order && (model.isNew() || !modelMap[model.id])) order.push(model); + modelMap[model.id] = true; } // Remove nonexistent models if appropriate. @@ -764,7 +769,7 @@ } if (sort || (order && order.length)) this.trigger('sort', this, options); } - + // Return the added (or merged) model (or models). return singular ? models[0] : models; }, @@ -776,7 +781,7 @@ reset: function(models, options) { options || (options = {}); for (var i = 0, l = this.models.length; i < l; i++) { - this._removeReference(this.models[i]); + this._removeReference(this.models[i], options); } options.previousModels = this.models; this._reset(); @@ -817,7 +822,7 @@ // Get a model from the set by id. get: function(obj) { if (obj == null) return void 0; - return this._byId[obj.id] || this._byId[obj.cid] || this._byId[obj]; + return this._byId[obj] || this._byId[obj.id] || this._byId[obj.cid]; }, // Get the model at the given index. @@ -893,7 +898,7 @@ if (!options.wait) this.add(model, options); var collection = this; var success = options.success; - options.success = function(model, resp, options) { + options.success = function(model, resp) { if (options.wait) collection.add(model, options); if (success) success(model, resp, options); }; @@ -923,10 +928,7 @@ // Prepare a hash of attributes (or other model) to be added to this // collection. _prepareModel: function(attrs, options) { - if (attrs instanceof Model) { - if (!attrs.collection) attrs.collection = this; - return attrs; - } + if (attrs instanceof Model) return attrs; options = options ? _.clone(options) : {}; options.collection = this; var model = new this.model(attrs, options); @@ -935,8 +937,16 @@ return false; }, + // Internal method to create a model's ties to a collection. + _addReference: function(model, options) { + this._byId[model.cid] = model; + if (model.id != null) this._byId[model.id] = model; + if (!model.collection) model.collection = this; + model.on('all', this._onModelEvent, this); + }, + // Internal method to sever a model's ties to a collection. - _removeReference: function(model) { + _removeReference: function(model, options) { if (this === model.collection) delete model.collection; model.off('all', this._onModelEvent, this); }, @@ -965,7 +975,7 @@ 'reject', 'every', 'all', 'some', 'any', 'include', 'contains', 'invoke', 'max', 'min', 'toArray', 'size', 'first', 'head', 'take', 'initial', 'rest', 'tail', 'drop', 'last', 'without', 'difference', 'indexOf', 'shuffle', - 'lastIndexOf', 'isEmpty', 'chain']; + 'lastIndexOf', 'isEmpty', 'chain', 'sample']; // Mix in each Underscore method as a proxy to `Collection#models`. _.each(methods, function(method) { @@ -977,7 +987,7 @@ }); // Underscore methods that take a property name as an argument. - var attributeMethods = ['groupBy', 'countBy', 'sortBy']; + var attributeMethods = ['groupBy', 'countBy', 'sortBy', 'indexBy']; // Use attributes instead of properties. _.each(attributeMethods, function(method) { @@ -1199,7 +1209,9 @@ return xhr; }; - var noXhrPatch = typeof window !== 'undefined' && !!window.ActiveXObject && !(window.XMLHttpRequest && (new XMLHttpRequest).dispatchEvent); + var noXhrPatch = + typeof window !== 'undefined' && !!window.ActiveXObject && + !(window.XMLHttpRequest && (new XMLHttpRequest).dispatchEvent); // Map from CRUD to HTTP for our default `Backbone.sync` implementation. var methodMap = { @@ -1258,7 +1270,7 @@ var router = this; Backbone.history.route(route, function(fragment) { var args = router._extractParameters(route, fragment); - callback && callback.apply(router, args); + router.execute(callback, args); router.trigger.apply(router, ['route:' + name].concat(args)); router.trigger('route', name, args); Backbone.history.trigger('route', router, name, args); @@ -1266,6 +1278,12 @@ return this; }, + // Execute a route handler with the provided parameters. This is an + // excellent place to do pre-route setup or post-route cleanup. + execute: function(callback, args) { + if (callback) callback.apply(this, args); + }, + // Simple proxy to `Backbone.history` to save a fragment into the history. navigate: function(fragment, options) { Backbone.history.navigate(fragment, options); @@ -1290,10 +1308,10 @@ route = route.replace(escapeRegExp, '\\$&') .replace(optionalParam, '(?:$1)?') .replace(namedParam, function(match, optional) { - return optional ? match : '([^\/]+)'; + return optional ? match : '([^/?]+)'; }) - .replace(splatParam, '(.*?)'); - return new RegExp('^' + route + '$'); + .replace(splatParam, '([^?]*?)'); + return new RegExp('^' + route + '(?:\\?([\\s\\S]*))?$'); }, // Given a route, and a URL fragment that it matches, return the array of @@ -1301,7 +1319,9 @@ // treated as `null` to normalize cross-browser behavior. _extractParameters: function(route, fragment) { var params = route.exec(fragment).slice(1); - return _.map(params, function(param) { + return _.map(params, function(param, i) { + // Don't decode the search params. + if (i === params.length - 1) return param || null; return param ? decodeURIComponent(param) : null; }); } @@ -1339,8 +1359,8 @@ // Cached regex for removing a trailing slash. var trailingSlash = /\/$/; - // Cached regex for stripping urls of hash and query. - var pathStripper = /[?#].*$/; + // Cached regex for stripping urls of hash. + var pathStripper = /#.*$/; // Has the history handling already been started? History.started = false; @@ -1352,6 +1372,11 @@ // twenty times a second. interval: 50, + // Are we at the app root? + atRoot: function() { + return this.location.pathname.replace(/[^\/]$/, '$&/') === this.root; + }, + // Gets the true hash value. Cannot use location.hash directly due to bug // in Firefox where location.hash will always be decoded. getHash: function(window) { @@ -1364,7 +1389,7 @@ getFragment: function(fragment, forcePushState) { if (fragment == null) { if (this._hasPushState || !this._wantsHashChange || forcePushState) { - fragment = this.location.pathname; + fragment = decodeURI(this.location.pathname + this.location.search); var root = this.root.replace(trailingSlash, ''); if (!fragment.indexOf(root)) fragment = fragment.slice(root.length); } else { @@ -1395,7 +1420,8 @@ this.root = ('/' + this.root + '/').replace(rootStripper, '/'); if (oldIE && this._wantsHashChange) { - this.iframe = Backbone.$('