aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/main
diff options
context:
space:
mode:
authorStas Vilchik <vilchiks@gmail.com>2015-04-15 11:14:43 +0200
committerStas Vilchik <vilchiks@gmail.com>2015-04-15 15:00:53 +0200
commit19094a0c94d551e59466274ce5115e192dfd264a (patch)
treeb4e163e61bf2613fe7332e40da4904baf645902d /server/sonar-web/src/main
parentcd5957698e0110754c73fd8118de3909d3e96c00 (diff)
downloadsonarqube-19094a0c94d551e59466274ce5115e192dfd264a.tar.gz
sonarqube-19094a0c94d551e59466274ce5115e192dfd264a.zip
SONAR-5851 use importers when create a profile
Diffstat (limited to 'server/sonar-web/src/main')
-rw-r--r--server/sonar-web/src/main/hbs/quality-profiles/quality-profiles-create-profile.hbs16
-rw-r--r--server/sonar-web/src/main/js/quality-profiles/actions-view.js20
-rw-r--r--server/sonar-web/src/main/js/quality-profiles/create-profile-view.js70
3 files changed, 76 insertions, 30 deletions
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
index e44f29d4de5..50fbc195fff 100644
--- 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
@@ -1,4 +1,5 @@
-<form id="create-profile-form">
+<form id="create-profile-form" action="{{link '/api/qualityprofiles/create'}}" enctype="multipart/form-data"
+ method="POST">
<div class="modal-head">
<h2>{{t 'quality_profiles.new_profile'}}</h2>
</div>
@@ -6,16 +7,23 @@
<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">
+ <input id="create-profile-name" name="name" type="text" size="50" maxlength="100" required>
</div>
- <div class="modal-field">
+ <div class="modal-field spacer-bottom">
<label for="create-profile-language">{{t 'language'}}<em class="mandatory">*</em></label>
- <select id="create-profile-language" name="language">
+ <select id="create-profile-language" name="language" required>
{{#each languages}}
<option value="{{key}}">{{name}}</option>
{{/each}}
</select>
</div>
+ {{#each importers}}
+ <div class="modal-field spacer-bottom js-importer" data-key="{{key}}">
+ <label for="create-profile-form-backup-{{key}}">{{name}}</label>
+ <input id="create-profile-form-backup-{{key}}" name="backup_{{key}}" type="file">
+ <p class="note">{{t 'quality_profiles.optional_configuration_file'}}</p>
+ </div>
+ {{/each}}
</div>
<div class="modal-foot">
<button id="create-profile-submit">{{t 'create'}}</button>
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
index 4d0653c3f57..9cb0e2d3f98 100644
--- a/server/sonar-web/src/main/js/quality-profiles/actions-view.js
+++ b/server/sonar-web/src/main/js/quality-profiles/actions-view.js
@@ -52,10 +52,11 @@ define([
create: function () {
var that = this;
- this.requestLanguages().done(function (r) {
+ $.when(this.requestLanguages(), this.requestImporters()).done(function () {
new CreateProfileView({
collection: that.collection,
- languages: r.languages
+ languages: that.languages,
+ importers: that.importers
}).render();
});
},
@@ -77,8 +78,19 @@ define([
},
requestLanguages: function () {
- var url = baseUrl + '/api/languages/list';
- return $.get(url);
+ var that = this,
+ url = baseUrl + '/api/languages/list';
+ return $.get(url).done(function (r) {
+ that.languages = r.languages;
+ });
+ },
+
+ requestImporters: function () {
+ var that = this,
+ url = baseUrl + '/api/qualityprofiles/importers';
+ return $.get(url).done(function (r) {
+ that.importers = r.importers;
+ });
},
serializeData: function () {
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
index 89d25107816..e6045f31716 100644
--- 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
@@ -19,18 +19,25 @@
*/
define([
'common/modal-form',
+ 'common/file-upload',
'quality-profiles/profile',
'templates/quality-profiles'
-], function (ModalFormView, Profile) {
+], function (ModalFormView, uploader, Profile) {
var $ = jQuery;
return ModalFormView.extend({
template: Templates['quality-profiles-create-profile'],
+ events: function () {
+ return _.extend(ModalFormView.prototype.events.apply(this, arguments), {
+ 'change #create-profile-language': 'onLanguageChange'
+ });
+ },
+
onFormSubmit: function (e) {
ModalFormView.prototype.onFormSubmit.apply(this, arguments);
- this.sendRequest();
+ this.sendRequest(e);
},
onRender: function () {
@@ -39,28 +46,36 @@ define([
width: '250px',
minimumResultsForSearch: 50
});
+ this.onLanguageChange();
},
- sendRequest: function () {
- var that = this,
- url = baseUrl + '/api/qualityprofiles/create',
- options = {
- language: this.$('#create-profile-language').val(),
- name: this.$('#create-profile-name').val()
- };
- return $.ajax({
- type: 'POST',
- url: url,
- data: options,
- statusCode: {
- // do not show global error
- 400: null
+ onLanguageChange: function () {
+ var that = this;
+ var language = this.$('#create-profile-language').val();
+ var importers = this.getImportersForLanguages(language);
+ this.$('.js-importer').each(function () {
+ that.emptyInput($(this));
+ $(this).addClass('hidden');
+ });
+ importers.forEach(function (importer) {
+ that.$('.js-importer[data-key="' + importer.key + '"]').removeClass('hidden');
+ });
+ },
+
+ emptyInput: function (e) {
+ e.wrap('<form>').closest('form').get(0).reset();
+ e.unwrap();
+ },
+
+ sendRequest: function (e) {
+ var that = this;
+ uploader({ form: $(e.currentTarget) }).done(function (r) {
+ if (_.isArray(r.errors) || _.isArray(r.warnings)) {
+ that.showErrors(r.errors, r.warnings);
+ } else {
+ that.addProfile(r.profile);
+ that.close();
}
- }).done(function (r) {
- that.addProfile(r.profile);
- that.close();
- }).fail(function (jqXHR) {
- that.showErrors(jqXHR.responseJSON.errors, jqXHR.responseJSON.warnings);
});
},
@@ -70,9 +85,20 @@ define([
profile.trigger('select', profile);
},
+ getImportersForLanguages: function (language) {
+ if (language != null) {
+ return this.options.importers.filter(function (importer) {
+ return importer.languages.indexOf(language) !== -1;
+ });
+ } else {
+ return [];
+ }
+ },
+
serializeData: function () {
return _.extend(ModalFormView.prototype.serializeData.apply(this, arguments), {
- languages: this.options.languages
+ languages: this.options.languages,
+ importers: this.options.importers
});
}
});