aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStas Vilchik <vilchiks@gmail.com>2015-06-02 18:32:00 +0200
committerStas Vilchik <vilchiks@gmail.com>2015-06-02 18:32:10 +0200
commit3203cdf1597fe567a56942f5e1dd45170496199a (patch)
tree5fa5fa4f677c4d5a84650c0d68ba83d7bcc45496
parent5381835db07e40e02cd4e9d214988ab6418dffd6 (diff)
downloadsonarqube-3203cdf1597fe567a56942f5e1dd45170496199a.tar.gz
sonarqube-3203cdf1597fe567a56942f5e1dd45170496199a.zip
refactor creation of manual issues
-rw-r--r--server/sonar-web/src/main/js/components/issue/manual-issue-view.js66
-rw-r--r--server/sonar-web/src/main/js/components/issue/models/issue.js34
-rw-r--r--server/sonar-web/src/main/js/components/issue/templates/manual-issue.hbs42
-rw-r--r--server/sonar-web/src/main/js/components/source-viewer/main.js4
4 files changed, 60 insertions, 86 deletions
diff --git a/server/sonar-web/src/main/js/components/issue/manual-issue-view.js b/server/sonar-web/src/main/js/components/issue/manual-issue-view.js
index c1f60b486e6..1b043544a44 100644
--- a/server/sonar-web/src/main/js/components/issue/manual-issue-view.js
+++ b/server/sonar-web/src/main/js/components/issue/manual-issue-view.js
@@ -1,10 +1,9 @@
define([
+ './models/issue',
'./templates'
-], function () {
+], function (Issue) {
- var $ = jQuery,
- API_ISSUE = baseUrl + '/api/issues/show',
- API_ADD_MANUAL_ISSUE = baseUrl + '/api/issues/create';
+ var $ = jQuery;
return Marionette.ItemView.extend({
template: Templates['manual-issue'],
@@ -44,68 +43,35 @@ define([
}
},
- showSpinner: function () {
- this.$('.js-submit').hide();
- this.$('.js-spinner').show();
- },
-
- hideSpinner: function () {
- this.$('.js-submit').show();
- this.$('.js-spinner').hide();
- },
-
- validateFields: function () {
- var message = this.$('[name=message]');
- if (!message.val()) {
- message.addClass('invalid').focus();
- return false;
- }
- return true;
- },
-
formSubmit: function (e) {
var that = this;
e.preventDefault();
- if (!this.validateFields()) {
- return;
- }
- this.showSpinner();
- var data = $(e.currentTarget).serialize();
- $.post(API_ADD_MANUAL_ISSUE, data)
- .done(function (r) {
- if (typeof r === 'string') {
- r = JSON.parse(r);
- }
- that.addIssue(r.issue.key);
- }).fail(function (r) {
- that.hideSpinner();
- if (r.responseJSON && r.responseJSON.errors) {
- that.showError(_.pluck(r.responseJSON.errors, 'msg').join('. '));
- }
- });
+ var issue = new Issue({
+ component: this.options.component,
+ line: this.options.line,
+ message: this.$('[name="message"]').val(),
+ rule: this.$('[name="rule"]').val()
+ });
+ issue.save().done(function () {
+ that.addIssue(issue);
+ });
},
- addIssue: function (key) {
+ addIssue: function (issue) {
var that = this;
- return $.get(API_ISSUE, { key: key }).done(function (r) {
- that.trigger('add', r.issue);
+ return issue.fetch().done(function () {
+ that.trigger('add', issue);
that.close();
});
},
- showError: function (msg) {
- this.$('.code-issue-errors').removeClass('hidden').text(msg);
- },
-
cancel: function (e) {
e.preventDefault();
this.close();
},
serializeData: function () {
- return _.extend(Marionette.ItemView.prototype.serializeData.apply(this, arguments), {
- line: this.options.line,
- component: this.options.component,
+ return _.extend(this._super(), {
rules: _.sortBy(this.rules, 'name')
});
}
diff --git a/server/sonar-web/src/main/js/components/issue/models/issue.js b/server/sonar-web/src/main/js/components/issue/models/issue.js
index 1c5e928818e..af5dd980c27 100644
--- a/server/sonar-web/src/main/js/components/issue/models/issue.js
+++ b/server/sonar-web/src/main/js/components/issue/models/issue.js
@@ -1,4 +1,4 @@
-define([], function () {
+define(function () {
return Backbone.Model.extend({
idAttribute: 'key',
@@ -7,8 +7,40 @@ define([], function () {
return baseUrl + '/api/issues/show?key=' + this.get('key');
},
+ urlRoot: function () {
+ return baseUrl + '/api/issues';
+ },
+
parse: function (r) {
return r.issue ? r.issue : r;
+ },
+
+ sync: function (method, model, options) {
+ var opts = options || {};
+ opts.contentType = 'application/x-www-form-urlencoded';
+ if (method === 'read') {
+ _.extend(opts, {
+ type: 'GET',
+ url: this.urlRoot() + '/show',
+ data: { key: model.id }
+ });
+ }
+ if (method === 'create') {
+ _.extend(opts, {
+ type: 'POST',
+ url: this.urlRoot() + '/create',
+ data: {
+ component: model.get('component'),
+ line: model.get('line'),
+ message: model.get('message'),
+ rule: model.get('rule'),
+ severity: model.get('severity')
+ }
+ });
+ }
+ var xhr = options.xhr = Backbone.ajax(opts);
+ model.trigger('request', model, xhr, options);
+ return xhr;
}
});
diff --git a/server/sonar-web/src/main/js/components/issue/templates/manual-issue.hbs b/server/sonar-web/src/main/js/components/issue/templates/manual-issue.hbs
index bbcf333395b..0a38fa2136f 100644
--- a/server/sonar-web/src/main/js/components/issue/templates/manual-issue.hbs
+++ b/server/sonar-web/src/main/js/components/issue/templates/manual-issue.hbs
@@ -1,19 +1,6 @@
-<form action="" class="js-manual-issue-form code-issue-create-form">
- {{! no manual rules }}
- {{! <div class="warning" style="margin: 10px"> }}
- {{! <% if is_admin %> }}
- {{! <%= message('issue.manual.no_rules.admin') -%> }}
- {{! &nbsp;<a href="<%= ApplicationController.root_context -%>/manual_rules/index"><%= message('manage') -%></a> }}
- {{! <% else %> }}
- {{! <%= message('issue.manual.no_rules.non_admin') -%> }}
- {{! <% end %> }}
- {{! &nbsp;<%= link_to_function message('cancel'), 'closeCreateIssueForm(this)' -%> }}
- {{! </div> }}
+<form class="js-manual-issue-form spacer-top spacer-bottom">
- <input type="hidden" name="line" value="{{line}}">
- <input type="hidden" name="component" value="{{component}}">
-
- <div class="code-issue-name">
+ <div class="spacer-bottom">
<select name="rule">
{{#each rules}}
<option value="{{key}}">{{name}}</option>
@@ -21,24 +8,13 @@
</select>
</div>
- <div class="code-issue-msg">
- <table class="width100">
- <tr>
- <td>
- <textarea rows="4" name="message" class="width100 marginbottom5"></textarea>
- </td>
- </tr>
- <tr>
- <td class="js-submit">
- <input type="submit" value="{{t 'create'}}">
- <a class="js-cancel" href="#">{{t 'cancel'}}</a>
- </td>
- <td class="js-spinner" style="display: none;">
- <i class="spinner"></i>
- </td>
- </tr>
- </table>
- <div class="code-issue-errors alert alert-danger hidden"></div>
+ <div class="spacer-top">
+ <textarea rows="4" name="message" class="width-100" required></textarea>
+ </div>
+
+ <div class="spacer-top">
+ <input type="submit" value="{{t 'create'}}">
+ <a class="js-cancel" href="#">{{t 'cancel'}}</a>
</div>
</form>
diff --git a/server/sonar-web/src/main/js/components/source-viewer/main.js b/server/sonar-web/src/main/js/components/source-viewer/main.js
index 07dfc55580d..a007145f354 100644
--- a/server/sonar-web/src/main/js/components/source-viewer/main.js
+++ b/server/sonar-web/src/main/js/components/source-viewer/main.js
@@ -479,8 +479,8 @@ define([
line: line,
row: $(e.currentTarget).closest('.source-line')
});
- popup.on('onManualIssueAdded', function (data) {
- that.addIssue(new Issue(data));
+ popup.on('onManualIssueAdded', function (issue) {
+ that.addIssue(issue);
});
popup.render();
},