Check version improved (avoiding update conflicts) (#97)
using Redmine REST API : https://www.redmine.org/projects/redmine/wiki/rest_issues and disabling check when tab is not focused
This commit is contained in:
parent
9eeea54521
commit
127af3ae25
@ -37,6 +37,8 @@ Feel free to edit `assets/stylesheets/issue_dynamic_edit.css` to update the look
|
|||||||
|
|
||||||
### 🆕 Changelog
|
### 🆕 Changelog
|
||||||
|
|
||||||
|
* **v 0.9.1** : Check version improved (avoiding update conflicts) : using [Redmine REST API](https://www.redmine.org/projects/redmine/wiki/rest_issues) and disabling check when tab is not focused (#97)
|
||||||
|
* **v 0.9.0** : JS rewritten to remove jQuery code
|
||||||
* **v 0.8.1** : fixed Github issue #89 : Issue version check (AJAX call) may give glitch while editing text + disable global event listener on ajaxSend
|
* **v 0.8.1** : fixed Github issue #89 : Issue version check (AJAX call) may give glitch while editing text + disable global event listener on ajaxSend
|
||||||
* **v 0.8.0** : Complete rework. Compatible with last Redmine version. New settings added : `_CONF_CHECK_ISSUE_UPDATE_CONFLICT` (#70 #88). Removed external lib (FontAwesome) (#74). Mobile style added (#87). Print style added (#84). Bug fix (#79, #85)
|
* **v 0.8.0** : Complete rework. Compatible with last Redmine version. New settings added : `_CONF_CHECK_ISSUE_UPDATE_CONFLICT` (#70 #88). Removed external lib (FontAwesome) (#74). Mobile style added (#87). Print style added (#84). Bug fix (#79, #85)
|
||||||
* **v 0.7.2** : New settings added into config file (`_CONF_DISPLAY_EDIT_ICON` and `_CONF_LISTENER_TYPE_ICON`) see Configuration part for more info ; new event `none` for `_CONF_LISTENER_TYPE_VALUE` disabling listener on value ; css fix
|
* **v 0.7.2** : New settings added into config file (`_CONF_DISPLAY_EDIT_ICON` and `_CONF_LISTENER_TYPE_ICON`) see Configuration part for more info ; new event `none` for `_CONF_LISTENER_TYPE_VALUE` disabling listener on value ; css fix
|
||||||
|
|||||||
@ -278,7 +278,7 @@ document.onkeydown = function(evt) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const checkVersion = function(callback){
|
const getVersion = function(callback){
|
||||||
fetch(LOCATION_HREF, {
|
fetch(LOCATION_HREF, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
crossDomain: true,
|
crossDomain: true,
|
||||||
@ -286,9 +286,28 @@ const checkVersion = function(callback){
|
|||||||
const parser = new DOMParser();
|
const parser = new DOMParser();
|
||||||
const doc = parser.parseFromString(data, 'text/html');
|
const doc = parser.parseFromString(data, 'text/html');
|
||||||
const distant_version = doc.querySelector('#issue_lock_version').value;
|
const distant_version = doc.querySelector('#issue_lock_version').value;
|
||||||
if(distant_version !== document.querySelector('#issue_lock_version').value){
|
if(callback) callback(distant_version);
|
||||||
if(!document.querySelector('#content . conflict')){
|
return distant_version;
|
||||||
const msg = document.createElement('div');
|
}).catch(err => {
|
||||||
|
console.warn('Issue while trying to get version (avoiding conflict)');
|
||||||
|
console.log(err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
let loadedDate = new Date();
|
||||||
|
const checkVersion = function(callback){
|
||||||
|
|
||||||
|
fetch(LOCATION_HREF + ".json", {
|
||||||
|
method: 'GET',
|
||||||
|
crossDomain: true,
|
||||||
|
}).then(res => res.text()).then(data => {
|
||||||
|
try {
|
||||||
|
const parsedData = JSON.parse(data);
|
||||||
|
const lastUpdate = new Date(parsedData.issue.updated_on);
|
||||||
|
if(lastUpdate > loadedDate){
|
||||||
|
loadedDate = lastUpdate;
|
||||||
|
if(!document.querySelectorAll('#content .conflict').length){
|
||||||
|
let msg = document.createElement('div');
|
||||||
msg.classList.add('conflict');
|
msg.classList.add('conflict');
|
||||||
msg.innerHTML = `${_TXT_CONFLICT_TITLE}
|
msg.innerHTML = `${_TXT_CONFLICT_TITLE}
|
||||||
<div class="conflict-details">
|
<div class="conflict-details">
|
||||||
@ -298,10 +317,15 @@ const checkVersion = function(callback){
|
|||||||
</div>`
|
</div>`
|
||||||
document.querySelector('#content').insertBefore(msg, document.querySelector('#content').firstChild);
|
document.querySelector('#content').insertBefore(msg, document.querySelector('#content').firstChild);
|
||||||
}
|
}
|
||||||
|
if(callback) getVersion(callback);
|
||||||
} else {
|
} else {
|
||||||
if(document.querySelector('#content .conflict')) document.querySelector('#content .conflict').remove();
|
if(document.querySelector('#content .conflict')) document.querySelector('#content .conflict').remove();
|
||||||
|
if(callback) callback(parseInt(document.querySelector('#issue_lock_version').value));
|
||||||
}
|
}
|
||||||
if(callback) callback(distant_version);
|
} catch (e) {
|
||||||
|
throw new Error('Error occured: ', e);
|
||||||
|
}
|
||||||
|
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
console.warn('Issue while trying to get version (avoiding conflict)');
|
console.warn('Issue while trying to get version (avoiding conflict)');
|
||||||
console.log(err);
|
console.log(err);
|
||||||
@ -313,7 +337,7 @@ let setCheckVersionInterval = function(activate){
|
|||||||
if(!_CONF_CHECK_ISSUE_UPDATE_CONFLICT) return false;
|
if(!_CONF_CHECK_ISSUE_UPDATE_CONFLICT) return false;
|
||||||
if(activate && !checkVersionInterval){
|
if(activate && !checkVersionInterval){
|
||||||
checkVersionInterval = window.setInterval(function(){
|
checkVersionInterval = window.setInterval(function(){
|
||||||
if(Document.visibilityState === "visible") checkVersion();
|
if(document.visibilityState === "visible") checkVersion();
|
||||||
}, 5000);
|
}, 5000);
|
||||||
} else {
|
} else {
|
||||||
clearInterval(checkVersionInterval);
|
clearInterval(checkVersionInterval);
|
||||||
|
|||||||
2
init.rb
2
init.rb
@ -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 attributes in detailed view without refreshing the page (JIRA style)'
|
description 'Allows users to dynamically update issue attributes in detailed view without refreshing the page (JIRA style)'
|
||||||
version '0.8.1'
|
version '0.9.1'
|
||||||
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
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user