fixed conflict when trying to add a note after update from dropdown. New method used, REST API is not required anymore

This commit is contained in:
Hugo Zilliox 2017-08-11 13:42:43 +02:00
parent 9a7a860ea5
commit 8c4e908c58
5 changed files with 32 additions and 27 deletions

View File

@ -1,7 +1,6 @@
# redmine_issue_dynamic_edit # redmine_issue_dynamic_edit
Add new dropdowns elements on detailed issue page to dynamically update issue's status, assignee and priority directly in the details block of the issue Add new dropdown elements on detailed issue page to dynamically update issue's status, assignee and priority fields, directly in the details block of the issue.
**You have to enable Redmine REST API** (`Administration` > `Settings` > `API` > check **Enable REST web service**)
### Example ### Example
@ -9,11 +8,15 @@ Add new dropdowns elements on detailed issue page to dynamically update issue's
### Installation ### Installation
* Enable REST API
* Clone repo into plugins directory : `git clone https://github.com/Ilogeek/redmine_issue_dynamic_edit.git` * Clone repo into plugins directory : `git clone https://github.com/Ilogeek/redmine_issue_dynamic_edit.git`
* Restart your Redmine instance * Restart your Redmine instance
### Customization ### Customization
Feel free to edit `assets/stylesheets/issue_dynamic_edit.css` to update the look of your fields depending on your current Redmine Theme Feel free to edit `assets/stylesheets/issue_dynamic_edit.css` to update the look of your fields depending on your current Redmine Theme.
This plugin uses [FontAwesome icons](http://fontawesome.io/) This plugin uses [FontAwesome icons](http://fontawesome.io/)
### Changelog
* **v 0.2.0** : fixed "conflict" when trying to add a note after an update from dropdowns. New method used, REST API is not required anymore
* **v 0.1.0** : initial commit

View File

@ -1,4 +1,3 @@
= redmine_issue_dynamic_edit = redmine_issue_dynamic_edit
Add new dropdowns elements on detailed issue page to dynamically update issue's status, assignee and priority directly in the details block of the issue Add new dropdowns elements on detailed issue page to dynamically update issue's status, assignee and priority directly in the details block of the issue
You have to enable Redmine REST API

View File

@ -1,3 +1,4 @@
/* FontAwesome inclusion */
var cssId = 'fontAwesome'; var cssId = 'fontAwesome';
if (!document.getElementById(cssId)) if (!document.getElementById(cssId))
{ {
@ -10,7 +11,8 @@ var cssId = 'fontAwesome';
link.media = 'all'; link.media = 'all';
head.appendChild(link); head.appendChild(link);
} }
/* Put new dropdown lists in the detailed info block */
if($('#statusListDropdown').length > 0) { if($('#statusListDropdown').length > 0) {
var htmlCopy = $('#statusListDropdown').get(0).outerHTML; var htmlCopy = $('#statusListDropdown').get(0).outerHTML;
$('#statusListDropdown').remove(); $('#statusListDropdown').remove();
@ -28,23 +30,18 @@ if($('#prioritiesListDropdown').length > 0) {
$('#prioritiesListDropdown').remove(); $('#prioritiesListDropdown').remove();
$('.details .attributes .priority.attribute .value').html(htmlCopy); $('.details .attributes .priority.attribute .value').html(htmlCopy);
} }
function updateDataIssue(field_name, field_value, cssClass) { function issueDynamicUpdate(field_name, field_value, cssClass){
$('.details .attributes .' + cssClass + '.attribute .value').append(' <i class="fa fa-refresh fa-spin fa-fw"></i>'); $('.details .attributes .' + cssClass + '.attribute .value').append(' <i class="fa fa-refresh fa-spin fa-fw"></i>');
ticketData = '<?xml version="1.0" encoding="UTF-8"?>'; var token = $("meta[name=csrf-token]").attr('content');
ticketData += '<issue>';
ticketData += '<id>' + _ISSUE_ID + '</id>';
ticketData += '<' + field_name + '>'+ field_value +'</' + field_name + '>';
ticketData += '</issue>';
jQuery.ajax({ jQuery.ajax({
type: 'PUT', type: 'POST',
url: '/issues/' + _ISSUE_ID + '.xml', url: '/issues/bulk_update?back_url=%2Fissues&amp;ids%5B%5D=' + _ISSUE_ID + '&amp;issue%5B' + field_name + '%5D=' + field_value,
crossDomain: true, data: { "authenticity_token" : token },
crossDomain: true,
async: false, async: false,
contentType: "application/xml",
data: ticketData,
beforeSend: function(xhr) { beforeSend: function(xhr) {
xhr.setRequestHeader("X-Redmine-API-Key", _USER_API_KEY); xhr.setRequestHeader("authenticity_token", token);
}, },
success: function(msg) { success: function(msg) {
setTimeout(function(){ setTimeout(function(){
@ -57,22 +54,28 @@ function updateDataIssue(field_name, field_value, cssClass) {
$('.details .attributes .' + cssClass + '.attribute .value i.fa-check').remove(); $('.details .attributes .' + cssClass + '.attribute .value i.fa-check').remove();
}, 2000); }, 2000);
}, 500); }, 500);
// update other fields to avoid conflict
$('#issue_lock_version').val(parseInt($('#issue_lock_version').val()) + 1 );
$('#last_journal_id').val(parseInt($('#last_journal_id').val()) + 1 );
$('#issue_' + field_name + ' option').removeAttr('selected').filter('[value=' + field_value + ']').prop('selected', true);
}, },
error: function(xhr, msg, error) {} error: function(xhr, msg, error) {}
}); });
} /* end function updateDataIssue */ };
/* Listeners foreach dropdown */
var domSelectStatus = $('body').find('#statusListDropdown select'); var domSelectStatus = $('body').find('#statusListDropdown select');
domSelectStatus.on('change', function(e){ domSelectStatus.on('change', function(e){
updateDataIssue('status_id', domSelectStatus.val(), 'status'); issueDynamicUpdate('status_id', domSelectStatus.val(), 'status');
}); /* end on change domSelectStatus */ }); /* end on change domSelectStatus */
var domSelectPriorities = $('body').find('#prioritiesListDropdown select'); var domSelectPriorities = $('body').find('#prioritiesListDropdown select');
domSelectPriorities.on('change', function(e){ domSelectPriorities.on('change', function(e){
updateDataIssue('priority_id', domSelectPriorities.val(), 'priority'); issueDynamicUpdate('priority_id', domSelectPriorities.val(), 'priority');
}); /* end on change domSelectPriorities */ }); /* end on change domSelectPriorities */
var domSelectUsers = $('body').find('#usersListDropdown select'); var domSelectUsers = $('body').find('#usersListDropdown select');
domSelectUsers.on('change', function(e){ domSelectUsers.on('change', function(e){
updateDataIssue('assigned_to_id', domSelectUsers.val(), 'assigned-to'); issueDynamicUpdate('assigned_to_id', domSelectUsers.val(), 'assigned-to');
}); /* end on change domSelectUsers */ }); /* end on change domSelectUsers */

View File

@ -6,7 +6,7 @@ Redmine::Plugin.register :redmine_issue_dynamic_edit do
name 'Redmine Dynamic edit Issue plugin' name 'Redmine Dynamic edit Issue plugin'
author 'Hugo Zilliox' author 'Hugo Zilliox'
description 'Allows users to dynamically update issue\'s status, assignee and priority in detailed view using REST API' description 'Allows users to dynamically update issue\'s status, assignee and priority in detailed view using REST API'
version '0.1.0' version '0.2.0'
url 'https://github.com/ilogeek/redmine_issue_dynamic_edit' url 'https://github.com/ilogeek/redmine_issue_dynamic_edit'
author_url 'https://hzilliox.fr' author_url 'https://hzilliox.fr'
end end

View File

@ -23,7 +23,7 @@ class DetailsIssueHooks < Redmine::Hook::ViewListener
if (issue) if (issue)
if (User.current.allowed_to?(:edit_issues, project)) if (User.current.allowed_to?(:edit_issues, project))
o = '' o = ''
statuses = issue.new_statuses_allowed_to(User.current) statuses = issue.new_statuses_allowed_to(User.current)
if (!statuses.empty?) if (!statuses.empty?)
o << "<span class='dynamicEditSelect' id='statusListDropdown'>" o << "<span class='dynamicEditSelect' id='statusListDropdown'>"
o << "<div class='selectedValue'><span>#{issue.status}</span> <i class=\"fa fa-pencil fa-fw\" aria-hidden=\"true\"></i></div> " o << "<div class='selectedValue'><span>#{issue.status}</span> <i class=\"fa fa-pencil fa-fw\" aria-hidden=\"true\"></i></div> "