aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/main/js/apps/quality-profiles/views
diff options
context:
space:
mode:
authorStas Vilchik <vilchiks@gmail.com>2016-06-27 16:08:44 +0200
committerGitHub <noreply@github.com>2016-06-27 16:08:44 +0200
commit4ecb6fc3ec08ee37a1bb5c19d8ca44e2b832b5a7 (patch)
tree763ce4b5a9d7b37982ab54fc64a0597167c2bc3d /server/sonar-web/src/main/js/apps/quality-profiles/views
parentc467e84eed1a60bbe8c0fe800e2cada2bb26bb4c (diff)
downloadsonarqube-4ecb6fc3ec08ee37a1bb5c19d8ca44e2b832b5a7.tar.gz
sonarqube-4ecb6fc3ec08ee37a1bb5c19d8ca44e2b832b5a7.zip
refactor quality profiles page (#1056)
Diffstat (limited to 'server/sonar-web/src/main/js/apps/quality-profiles/views')
-rw-r--r--server/sonar-web/src/main/js/apps/quality-profiles/views/ChangeParentView.js63
-rw-r--r--server/sonar-web/src/main/js/apps/quality-profiles/views/ChangeProjectsView.js70
-rw-r--r--server/sonar-web/src/main/js/apps/quality-profiles/views/CopyProfileView.js52
-rw-r--r--server/sonar-web/src/main/js/apps/quality-profiles/views/CreateProfileView.js95
-rw-r--r--server/sonar-web/src/main/js/apps/quality-profiles/views/DeleteProfileView.js55
-rw-r--r--server/sonar-web/src/main/js/apps/quality-profiles/views/RenameProfileView.js51
-rw-r--r--server/sonar-web/src/main/js/apps/quality-profiles/views/RestoreBuiltInProfilesView.js56
-rw-r--r--server/sonar-web/src/main/js/apps/quality-profiles/views/RestoreProfileView.js55
8 files changed, 497 insertions, 0 deletions
diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/views/ChangeParentView.js b/server/sonar-web/src/main/js/apps/quality-profiles/views/ChangeParentView.js
new file mode 100644
index 00000000000..6b405179e44
--- /dev/null
+++ b/server/sonar-web/src/main/js/apps/quality-profiles/views/ChangeParentView.js
@@ -0,0 +1,63 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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.
+ */
+import ModalFormView from '../../../components/common/modal-form';
+import Template from '../templates/quality-profiles-change-profile-parent.hbs';
+import { changeProfileParent } from '../../../api/quality-profiles';
+
+export default ModalFormView.extend({
+ template: Template,
+
+ onRender () {
+ ModalFormView.prototype.onRender.apply(this, arguments);
+ this.$('select').select2({
+ width: '250px',
+ minimumResultsForSearch: 50
+ });
+ },
+
+ onFormSubmit () {
+ ModalFormView.prototype.onFormSubmit.apply(this, arguments);
+ this.disableForm();
+ this.sendRequest();
+ },
+
+ sendRequest () {
+ const parent = this.$('#change-profile-parent').val();
+ changeProfileParent(this.options.profile.key, parent)
+ .then(() => {
+ this.destroy();
+ this.trigger('done');
+ })
+ .catch(e => {
+ if (e.response.status === 400) {
+ this.enableForm();
+ e.response.json().then(r => this.showErrors(r.errors, r.warnings));
+ }
+ });
+ },
+
+ serializeData () {
+ const { profile } = this.options;
+ const profiles = this.options.profiles
+ .filter(p => p !== profile && p.language === profile.language);
+ return { ...profile, profiles };
+ }
+});
+
diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/views/ChangeProjectsView.js b/server/sonar-web/src/main/js/apps/quality-profiles/views/ChangeProjectsView.js
new file mode 100644
index 00000000000..5292bfa183e
--- /dev/null
+++ b/server/sonar-web/src/main/js/apps/quality-profiles/views/ChangeProjectsView.js
@@ -0,0 +1,70 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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.
+ */
+import ModalFormView from '../../../components/common/modal-form';
+import Template from '../templates/quality-profiles-change-projects.hbs';
+import { translate } from '../../../helpers/l10n';
+import '../../../components/SelectList';
+
+export default ModalFormView.extend({
+ template: Template,
+
+ onRender () {
+ ModalFormView.prototype.onRender.apply(this, arguments);
+
+ const { key } = this.options.profile;
+
+ const searchUrl = window.baseUrl + '/api/qualityprofiles/projects?key=' +
+ encodeURIComponent(key);
+
+ new window.SelectList({
+ searchUrl,
+ el: this.$('#profile-projects'),
+ width: '100%',
+ readOnly: false,
+ focusSearch: false,
+ format (item) {
+ return item.name;
+ },
+ selectUrl: window.baseUrl + '/api/qualityprofiles/add_project',
+ deselectUrl: window.baseUrl + '/api/qualityprofiles/remove_project',
+ extra: {
+ profileKey: key
+ },
+ selectParameter: 'projectUuid',
+ selectParameterValue: 'uuid',
+ labels: {
+ selected: translate('quality_gates.projects.with'),
+ deselected: translate('quality_gates.projects.without'),
+ all: translate('quality_gates.projects.all'),
+ noResults: translate('quality_gates.projects.noResults')
+ },
+ tooltips: {
+ select: translate('quality_profiles.projects.select_hint'),
+ deselect: translate('quality_profiles.projects.deselect_hint')
+ }
+ });
+ },
+
+ onDestroy() {
+ this.options.loadProjects();
+ ModalFormView.prototype.onDestroy.apply(this, arguments);
+ }
+});
+
diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/views/CopyProfileView.js b/server/sonar-web/src/main/js/apps/quality-profiles/views/CopyProfileView.js
new file mode 100644
index 00000000000..5809894287e
--- /dev/null
+++ b/server/sonar-web/src/main/js/apps/quality-profiles/views/CopyProfileView.js
@@ -0,0 +1,52 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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.
+ */
+import ModalFormView from '../../../components/common/modal-form';
+import Template from '../templates/quality-profiles-copy-profile.hbs';
+import { copyProfile } from '../../../api/quality-profiles';
+
+export default ModalFormView.extend({
+ template: Template,
+
+ onFormSubmit () {
+ ModalFormView.prototype.onFormSubmit.apply(this, arguments);
+ this.disableForm();
+ this.sendRequest();
+ },
+
+ sendRequest () {
+ const name = this.$('#copy-profile-name').val();
+ copyProfile(this.options.profile.key, name)
+ .then(profile => {
+ this.destroy();
+ this.trigger('done', profile);
+ })
+ .catch(e => {
+ if (e.response.status === 400) {
+ this.enableForm();
+ e.response.json().then(r => this.showErrors(r.errors, r.warnings));
+ }
+ });
+ },
+
+ serializeData () {
+ return this.options.profile;
+ }
+});
+
diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/views/CreateProfileView.js b/server/sonar-web/src/main/js/apps/quality-profiles/views/CreateProfileView.js
new file mode 100644
index 00000000000..60d800bc9fa
--- /dev/null
+++ b/server/sonar-web/src/main/js/apps/quality-profiles/views/CreateProfileView.js
@@ -0,0 +1,95 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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.
+ */
+import $ from 'jquery';
+import _ from 'underscore';
+import ModalFormView from '../../../components/common/modal-form';
+import Template from '../templates/quality-profiles-create-profile.hbs';
+import { createQualityProfile } from '../../../api/quality-profiles';
+
+export default ModalFormView.extend({
+ template: Template,
+
+ events () {
+ return _.extend(ModalFormView.prototype.events.apply(this, arguments), {
+ 'change #create-profile-language': 'onLanguageChange'
+ });
+ },
+
+ onFormSubmit () {
+ ModalFormView.prototype.onFormSubmit.apply(this, arguments);
+
+ const form = this.$('form')[0];
+ const data = new FormData(form);
+
+ createQualityProfile(data)
+ .then(r => {
+ this.trigger('done', r.profile);
+ this.destroy();
+ })
+ .catch(e => {
+ e.response.json().then(r => this.showErrors(r.errors, r.warnings));
+ });
+ },
+
+ onRender () {
+ ModalFormView.prototype.onRender.apply(this, arguments);
+ this.$('select').select2({
+ width: '250px',
+ minimumResultsForSearch: 50
+ });
+ this.onLanguageChange();
+ },
+
+ onLanguageChange () {
+ const that = this;
+ const language = this.$('#create-profile-language').val();
+ const importers = this.getImportersForLanguages(language);
+ this.$('.js-importer').each(function () {
+ that.emptyInput($(this));
+ $(this).addClass('hidden');
+ });
+ importers.forEach(function (importer) {
+ that.$(`.js-importer[data-key="${importer.key}"]`).removeClass('hidden');
+ });
+ },
+
+ emptyInput (e) {
+ e.wrap('<form>').closest('form').get(0).reset();
+ e.unwrap();
+ },
+
+ getImportersForLanguages (language) {
+ if (language != null) {
+ return this.options.importers.filter(function (importer) {
+ return importer.languages.indexOf(language) !== -1;
+ });
+ } else {
+ return [];
+ }
+ },
+
+ serializeData () {
+ return _.extend(ModalFormView.prototype.serializeData.apply(this, arguments), {
+ languages: this.options.languages,
+ importers: this.options.importers
+ });
+ }
+});
+
diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/views/DeleteProfileView.js b/server/sonar-web/src/main/js/apps/quality-profiles/views/DeleteProfileView.js
new file mode 100644
index 00000000000..b9bb6023c71
--- /dev/null
+++ b/server/sonar-web/src/main/js/apps/quality-profiles/views/DeleteProfileView.js
@@ -0,0 +1,55 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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.
+ */
+import ModalFormView from '../../../components/common/modal-form';
+import Template from '../templates/quality-profiles-delete-profile.hbs';
+import { deleteProfile } from '../../../api/quality-profiles';
+
+export default ModalFormView.extend({
+ template: Template,
+
+ modelEvents: {
+ 'destroy': 'destroy'
+ },
+
+ onFormSubmit () {
+ ModalFormView.prototype.onFormSubmit.apply(this, arguments);
+ this.disableForm();
+ this.sendRequest();
+ },
+
+ sendRequest () {
+ deleteProfile(this.options.profile.key)
+ .then(() => {
+ this.destroy();
+ this.trigger('done');
+ })
+ .catch(e => {
+ if (e.response.status === 400) {
+ this.enableForm();
+ e.response.json().then(r => this.showErrors(r.errors, r.warnings));
+ }
+ });
+ },
+
+ serializeData () {
+ return this.options.profile;
+ }
+});
+
diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/views/RenameProfileView.js b/server/sonar-web/src/main/js/apps/quality-profiles/views/RenameProfileView.js
new file mode 100644
index 00000000000..964a4b58115
--- /dev/null
+++ b/server/sonar-web/src/main/js/apps/quality-profiles/views/RenameProfileView.js
@@ -0,0 +1,51 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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.
+ */
+import ModalFormView from '../../../components/common/modal-form';
+import Template from '../templates/quality-profiles-rename-profile.hbs';
+import { renameProfile } from '../../../api/quality-profiles';
+
+export default ModalFormView.extend({
+ template: Template,
+
+ onFormSubmit () {
+ ModalFormView.prototype.onFormSubmit.apply(this, arguments);
+ this.sendRequest();
+ },
+
+ sendRequest () {
+ const name = this.$('#rename-profile-name').val();
+ renameProfile(this.options.profile.key, name)
+ .then(profile => {
+ this.destroy();
+ this.trigger('done', profile);
+ })
+ .catch(e => {
+ if (e.response.status === 400) {
+ this.enableForm();
+ e.response.json().then(r => this.showErrors(r.errors, r.warnings));
+ }
+ });
+ },
+
+ serializeData () {
+ return this.options.profile;
+ }
+});
+
diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/views/RestoreBuiltInProfilesView.js b/server/sonar-web/src/main/js/apps/quality-profiles/views/RestoreBuiltInProfilesView.js
new file mode 100644
index 00000000000..f71f85c06af
--- /dev/null
+++ b/server/sonar-web/src/main/js/apps/quality-profiles/views/RestoreBuiltInProfilesView.js
@@ -0,0 +1,56 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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.
+ */
+import ModalFormView from '../../../components/common/modal-form';
+import Template from '../templates/quality-profiles-restore-built-in-profiles.hbs';
+import TemplateSuccess from '../templates/quality-profiles-restore-built-in-profiles-success.hbs';
+import { restoreBuiltInProfiles } from '../../../api/quality-profiles';
+
+export default ModalFormView.extend({
+ template: Template,
+ successTemplate: TemplateSuccess,
+
+ getTemplate () {
+ return this.done ? this.successTemplate : this.template;
+ },
+
+ onFormSubmit () {
+ ModalFormView.prototype.onFormSubmit.apply(this, arguments);
+ this.disableForm();
+ this.sendRequest();
+ },
+
+ sendRequest () {
+ restoreBuiltInProfiles(this.options.language.key)
+ .then(() => {
+ this.done = true;
+ this.render();
+ this.trigger('done');
+ })
+ .catch(e => {
+ this.enableForm();
+ e.response.json().then(r => this.showErrors(r.errors, r.warnings));
+ });
+ },
+
+ serializeData () {
+ return { language: this.options.language };
+ }
+});
+
diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/views/RestoreProfileView.js b/server/sonar-web/src/main/js/apps/quality-profiles/views/RestoreProfileView.js
new file mode 100644
index 00000000000..4fceffda657
--- /dev/null
+++ b/server/sonar-web/src/main/js/apps/quality-profiles/views/RestoreProfileView.js
@@ -0,0 +1,55 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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.
+ */
+import ModalFormView from '../../../components/common/modal-form';
+import Template from '../templates/quality-profiles-restore-profile.hbs';
+import { restoreQualityProfile } from '../../../api/quality-profiles';
+
+export default ModalFormView.extend({
+ template: Template,
+
+ onFormSubmit (e) {
+ ModalFormView.prototype.onFormSubmit.apply(this, arguments);
+ const data = new FormData(e.currentTarget);
+
+ this.disableForm();
+
+ restoreQualityProfile(data)
+ .then(r => {
+ this.profile = r.profile;
+ this.ruleSuccesses = r.ruleSuccesses;
+ this.ruleFailures = r.ruleFailures;
+ this.render();
+ this.trigger('done');
+ })
+ .catch(e => {
+ this.enableForm();
+ e.response.json().then(r => this.showErrors(r.errors, r.warnings));
+ });
+ },
+
+ serializeData() {
+ return {
+ ...ModalFormView.prototype.serializeData.apply(this, arguments),
+ profile: this.profile,
+ ruleSuccesses: this.ruleSuccesses,
+ ruleFailures: this.ruleFailures
+ };
+ }
+});