diff options
author | Stas Vilchik <vilchiks@gmail.com> | 2015-04-09 17:19:55 +0200 |
---|---|---|
committer | Stas Vilchik <vilchiks@gmail.com> | 2015-04-10 14:45:20 +0200 |
commit | 52a0578e61c4e9d8496b2e77ea5cabb95c1d5a72 (patch) | |
tree | 7108e20840544ea813fc0eea0b767172fbc17255 /server/sonar-web | |
parent | f20953ac6c24877fb80f151369227dfad5890324 (diff) | |
download | sonarqube-52a0578e61c4e9d8496b2e77ea5cabb95c1d5a72.tar.gz sonarqube-52a0578e61c4e9d8496b2e77ea5cabb95c1d5a72.zip |
SONAR-5851 add profile details, implement profile actions
Diffstat (limited to 'server/sonar-web')
34 files changed, 1434 insertions, 70 deletions
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 @@ +<h1 class="page-title">{{t 'quality_profiles.page'}}</h1> + +<div class="page-actions"> + <div class="button-group dropdown"> + <button id="quality-profiles-create">{{t 'create'}}</button> + <a class="button dropdown-toggle" href="#" data-toggle="dropdown"><i class="icon-dropdown"></i></a> + <ul class="dropdown-menu dropdown-menu-right"> + <li> + <a href="#">{{t 'quality_profiles.compare_profiles'}}</a> + </li> + <li> + <a id="quality-profiles-restore" href="#">{{t 'quality_profiles.restore_profile'}}</a> + </li> + <li> + <a id="quality-profiles-restore-built-in" href="#">{{t 'quality_profiles.restore_built_in_profiles'}}</a> + </li> + </ul> + </div> +</div> 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 @@ +<form id="copy-profile-form"> + <div class="modal-head"> + <h2>{{tp 'quality_profiles.copy_x_title' name languageName}}</h2> + </div> + <div class="modal-body"> + <div class="js-modal-messages"></div> + <div class="modal-field"> + <label for="name">{{t 'quality_profiles.copy_new_name'}}<em class="mandatory">*</em></label> + <input id="copy-name" name="name" type="text" size="50" maxlength="100" autofocus="autofocus"> + </div> + </div> + <div class="modal-foot"> + <button id="copy-submit">{{t 'copy'}}</button> + <a href="#" class="js-modal-close" id="copy-cancel">{{t 'cancel'}}</a> + </div> +</form> 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 @@ +<form id="create-profile-form"> + <div class="modal-head"> + <h2>{{t 'quality_profiles.new_profile'}}</h2> + </div> + <div class="modal-body"> + <div class="js-modal-messages"></div> + <div class="modal-field"> + <label for="create-profile-name">{{t 'name'}}<em class="mandatory">*</em></label> + <input id="create-profile-name" name="name" type="text" size="50" maxlength="100" autofocus="autofocus"> + </div> + <div class="modal-field"> + <label for="create-profile-language">{{t 'language'}}<em class="mandatory">*</em></label> + <select id="create-profile-language" name="language"> + {{#each languages}} + <option value="{{key}}">{{name}}</option> + {{/each}} + </select> + </div> + </div> + <div class="modal-foot"> + <button id="create-profile-submit">{{t 'create'}}</button> + <a href="#" class="js-modal-close" id="create-profile-cancel">{{t 'cancel'}}</a> + </div> +</form> 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 @@ +<form id="delete-profile-form"> + <div class="modal-head"> + <h2>{{t 'quality_profiles.delete_confirm_title'}}</h2> + </div> + <div class="modal-body"> + <div class="js-modal-messages"></div> + <p>{{tp 'quality_profiles.are_you_sure_want_delete_profile_x_and_descendants' name languageName}}</p> + </div> + <div class="modal-foot"> + <button id="delete-submit">{{t 'delete'}}</button> + <a href="#" class="js-modal-close" id="delete-cancel">{{t 'cancel'}}</a> + </div> +</form> 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 @@ +<div class="search-navigator-side search-navigator-side-light"> + <div class="search-navigator-filters"></div> + <div class="quality-profiles-results panel"></div> + + <div class="panel"> + <div class="alert alert-danger">Work in progress... please no feedback yet</div> + </div> +</div> + +<div class="search-navigator-workspace"> + <div class="search-navigator-workspace-header"></div> + <div class="search-navigator-workspace-list"></div> +</div> 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 @@ +<h3>{{t 'coding_rules'}}</h3> +<p class="spacer-top">Total: <a href="{{link rulesSearchUrl}}">{{formatMeasure activeRuleCount 'INT'}}</a></p> +{{#notEmpty rulesSeverities}} + <ul class="spacer-top list-inline"> + {{#each rulesSeverities}} + <li> + {{severity val}} + <a href="{{link ../rulesSearchUrl '|severities=' val}}">{{formatMeasure count 'INT'}}</a> + </li> + {{/each}} + </ul> +{{/notEmpty}} + +<hr class="spacer-top spacer-bottom"> + +<h3>{{t 'projects'}}</h3> +{{#if isDefault}} + <p class="alert alert-info">{{t 'quality_profiles.projects_for_default.edit'}}</p> +{{else}} + <div id="quality-profile-projects"></div> +{{/if}} + +<hr class="spacer-top spacer-bottom"> + +<h3>{{t 'permalinks'}}</h3> +<p class="alert alert-warning">Coming soon...</p> + +<hr class="spacer-top spacer-bottom"> + +<h3>{{t 'quality_profiles.profile_inheritance'}}</h3> +<p class="alert alert-warning">Coming soon...</p> + +<hr class="spacer-top spacer-bottom"> + +<h3>{{t 'changelog'}}</h3> +<p class="alert alert-warning">Coming soon...</p> 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 @@ +<h2 class="search-navigator-header-component"> + {{name}} + <span class="note">{{languageName}}</span> +</h2> + +<div class="search-navigator-header-actions"> + <div class="button-group"> + <a class="button" href="{{link '/api/qualityprofiles/backup?profileKey=' encodedKey}}" target="_blank" + id="quality-profile-backup">{{t 'backup_verb'}}</a> + <button id="quality-profile-rename">{{t 'rename'}}</button> + <button id="quality-profile-copy">{{t 'copy'}}</button> + {{#unless isDefault}} + <button id="quality-profile-set-as-default">{{t 'set_as_default'}}</button> + <button id="quality-profile-delete" class="button-red">{{t 'delete'}}</button> + {{/unless}} + </div> +</div> 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}} + <span class="note pull-right">{{t 'default'}}</span> +{{/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 @@ +<h6 class="spacer-top js-list-language">{{languageName}}</h6> 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 @@ +<div class="js-list"></div> 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 @@ +<form id="copy-profile-form"> + <div class="modal-head"> + <h2>{{tp 'quality_profiles.rename_x_title' name languageName}}</h2> + </div> + <div class="modal-body"> + <div class="js-modal-messages"></div> + <div class="modal-field"> + <label for="new_name">{{t 'quality_profiles.new_name'}} <em class="mandatory">*</em></label> + <input id="new-name" name="new_name" type="text" size="50" maxlength="100" autofocus="autofocus" value="{{name}}"> + </div> + </div> + <div class="modal-foot"> + <button id="rename-submit">{{t 'rename'}}</button> + <a href="#" class="js-modal-close" id="rename-cancel">{{t 'cancel'}}</a> + </div> +</form> 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 @@ +<form id="restore-built-in-profiles-form"> + <div class="modal-head"> + <h2>{{t 'quality_profiles.new_profile'}}</h2> + </div> + <div class="modal-body"> + <div class="js-modal-messages"></div> + <div class="modal-field"> + <label for="restore-built-in-profiles-language">{{t 'language'}}<em class="mandatory">*</em></label> + <select id="restore-built-in-profiles-language" name="language"> + {{#each languages}} + <option value="{{key}}">{{name}}</option> + {{/each}} + </select> + </div> + </div> + <div class="modal-foot"> + <button id="restore-built-in-profiles-submit">{{t 'restore'}}</button> + <a href="#" class="js-modal-close" id="restore-built-in-profiles-cancel">{{t 'cancel'}}</a> + </div> +</form> 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 @@ +<div class="modal-head"> + <h2>{{t 'quality_profiles.restore_profile'}}</h2> +</div> +<form id="restore-profile-form" action="{{link '/api/qualityprofiles/restore'}}" enctype="multipart/form-data" + method="POST"> + <div class="modal-body"> + <div class="js-modal-messages"></div> + <div class="modal-field"> + <label for="restore-profile-backup">{{t 'backup'}}<em class="mandatory">*</em></label> + <input type="file" id="restore-profile-backup" name="backup"> + </div> + </div> + <div class="modal-foot"> + <button id="restore-profile-submit">{{t 'restore'}}</button> + <a href="#" class="js-modal-close" id="restore-profile-cancel">{{t 'cancel'}}</a> + </div> +</form> 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 $('<iframe></iframe>') + .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.$('<iframe src="javascript:0" tabindex="-1" />').hide().appendTo('body')[0].contentWindow; + var frame = Backbone.$('<iframe src="javascript:0" tabindex="-1">'); + this.iframe = frame.hide().appendTo('body')[0].contentWindow; this.navigate(fragment); } @@ -1413,7 +1439,6 @@ // opened by a non-pushState browser. this.fragment = fragment; var loc = this.location; - var atRoot = loc.pathname.replace(/[^\/]$/, '$&/') === this.root; // Transition from hashChange to pushState or vice versa if both are // requested. @@ -1421,17 +1446,17 @@ // If we've started off with a route from a `pushState`-enabled // browser, but we're currently in a browser that doesn't support it... - if (!this._hasPushState && !atRoot) { + if (!this._hasPushState && !this.atRoot()) { this.fragment = this.getFragment(null, true); - this.location.replace(this.root + this.location.search + '#' + this.fragment); + this.location.replace(this.root + '#' + this.fragment); // Return immediately as browser will do redirect to new url return true; // Or if we've started out with a hash-based route, but we're currently // in a browser where it could be `pushState`-based instead... - } else if (this._hasPushState && atRoot && loc.hash) { + } else if (this._hasPushState && this.atRoot() && loc.hash) { this.fragment = this.getHash().replace(routeStripper, ''); - this.history.replaceState({}, document.title, this.root + this.fragment + loc.search); + this.history.replaceState({}, document.title, this.root + this.fragment); } } @@ -1443,7 +1468,7 @@ // but possibly useful for unit testing Routers. stop: function() { Backbone.$(window).off('popstate', this.checkUrl).off('hashchange', this.checkUrl); - clearInterval(this._checkUrlInterval); + if (this._checkUrlInterval) clearInterval(this._checkUrlInterval); History.started = false; }, @@ -1491,7 +1516,7 @@ var url = this.root + (fragment = this.getFragment(fragment || '')); - // Strip the fragment of the query and hash for matching. + // Strip the hash for matching. fragment = fragment.replace(pathStripper, ''); if (this.fragment === fragment) return; @@ -1597,4 +1622,6 @@ }; }; -}).call(this); + return Backbone; + +})); diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/quality_profiles_controller.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/quality_profiles_controller.rb index 5884d08ab16..3c84dc757c5 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/quality_profiles_controller.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/quality_profiles_controller.rb @@ -26,4 +26,8 @@ class QualityProfilesController < ApplicationController end + def show + render :action => 'index' + end + end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/views/profiles/_restore_form.html.erb b/server/sonar-web/src/main/webapp/WEB-INF/app/views/profiles/_restore_form.html.erb index 42063d7f3c9..8fcae1336f2 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/app/views/profiles/_restore_form.html.erb +++ b/server/sonar-web/src/main/webapp/WEB-INF/app/views/profiles/_restore_form.html.erb @@ -2,7 +2,7 @@ <fieldset> <div class="modal-head"> - <h2><%= h message('quality_profiles.restore_profile') -%></h2> + <h2><%= h message('quality_profiles.restore_built_in_profiles') -%></h2> </div> <div class="modal-body"> |