From 5e547e5a383075a0a04c849d559cec4d726e02d6 Mon Sep 17 00:00:00 2001 From: MayamaTakeshi Date: Sat, 29 Apr 2023 15:49:12 +0900 Subject: [PATCH 1/5] 1) Correted issue with url with querystring params or hash mark, added protection against failure to get journal related to dynamic change --- assets/javascripts/issue_dynamic_edit.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/assets/javascripts/issue_dynamic_edit.js b/assets/javascripts/issue_dynamic_edit.js index 21bf318..a72817a 100644 --- a/assets/javascripts/issue_dynamic_edit.js +++ b/assets/javascripts/issue_dynamic_edit.js @@ -24,7 +24,13 @@ const SVG_CANCEL = ' { + let nu = new URL(url); + return `${nu.protocol}//${nu.host}${nu.pathname}`; +} + +let LOCATION_HREF = typeof custom_location_href !== 'undefined' ? custom_location_href : clean_url(window.location.href); if (_CONF_FORCE_HTTPS) { LOCATION_HREF = LOCATION_HREF.replace(/^http:\/\//i, 'https://'); @@ -409,7 +415,15 @@ let sendData = function(serialized_data){ document.querySelector('form#issue-form').innerHTML = doc.querySelector('form#issue-form').innerHTML; document.querySelector('#all_attributes').innerHTML = doc.querySelector('#all_attributes').innerHTML; document.querySelector('div.issue.details').innerHTML = doc.querySelector('div.issue.details').innerHTML; - document.querySelector('#tab-content-history').appendChild(doc.querySelector('#history .journal.has-details:last-child')); + + let journal = doc.querySelector('#history .journal.has-details:last-child'); + if(!journal) { + journal = doc.querySelector('#history .journal.has-details'); + } + if(journal) { + document.querySelector('#tab-content-history').appendChild(journal); + } + document.querySelector('#issue_lock_version').value = doc.querySelector("#issue_lock_version").value; cloneEditForm(); From 39371e8e34fba5236bdec8c7fbf9bd05968d3e68 Mon Sep 17 00:00:00 2001 From: MayamaTakeshi Date: Sat, 29 Apr 2023 17:36:09 +0900 Subject: [PATCH 2/5] Protection against absent history --- assets/javascripts/issue_dynamic_edit.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/assets/javascripts/issue_dynamic_edit.js b/assets/javascripts/issue_dynamic_edit.js index a72817a..8c6dd32 100644 --- a/assets/javascripts/issue_dynamic_edit.js +++ b/assets/javascripts/issue_dynamic_edit.js @@ -417,11 +417,12 @@ let sendData = function(serialized_data){ document.querySelector('div.issue.details').innerHTML = doc.querySelector('div.issue.details').innerHTML; let journal = doc.querySelector('#history .journal.has-details:last-child'); - if(!journal) { - journal = doc.querySelector('#history .journal.has-details'); - } if(journal) { - document.querySelector('#tab-content-history').appendChild(journal); + let tch = document.querySelector('#tab-content-history'); + // sometimes, there will be no history yet. + if(tch) { + tch.appendChild(journal); + } } document.querySelector('#issue_lock_version').value = doc.querySelector("#issue_lock_version").value; From 89df6f5a81a864b3dcccacbff3c45423ad587042 Mon Sep 17 00:00:00 2001 From: MayamaTakeshi Date: Wed, 3 May 2023 07:34:29 +0900 Subject: [PATCH 3/5] Added support for comments in reverse order --- assets/javascripts/issue_dynamic_edit.js | 23 +++++++++++++++++------ lib/details_issue_hooks.rb | 1 + 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/assets/javascripts/issue_dynamic_edit.js b/assets/javascripts/issue_dynamic_edit.js index 8c6dd32..f8f29c4 100644 --- a/assets/javascripts/issue_dynamic_edit.js +++ b/assets/javascripts/issue_dynamic_edit.js @@ -416,12 +416,23 @@ let sendData = function(serialized_data){ document.querySelector('#all_attributes').innerHTML = doc.querySelector('#all_attributes').innerHTML; document.querySelector('div.issue.details').innerHTML = doc.querySelector('div.issue.details').innerHTML; - let journal = doc.querySelector('#history .journal.has-details:last-child'); - if(journal) { - let tch = document.querySelector('#tab-content-history'); - // sometimes, there will be no history yet. - if(tch) { - tch.appendChild(journal); + let tch = document.querySelector('#tab-content-history'); + // sometimes, there will be no history yet (like when the issue was just created). + if(tch) { + let query + if(_COMMENTS_IN_REVERSE_ORDER_) { + query = '#history .journal.has-details:first-child'; + } else { + query = '#history .journal.has-details:last-child'; + } + + let journal = doc.querySelector(query); + if(journal) { + if(_COMMENTS_IN_REVERSE_ORDER_) { + tch.insertBefore(journal, tch.firstChild); + } else { + tch.appendChild(journal); + } } } diff --git a/lib/details_issue_hooks.rb b/lib/details_issue_hooks.rb index bcab8bf..2eb3d36 100644 --- a/lib/details_issue_hooks.rb +++ b/lib/details_issue_hooks.rb @@ -31,6 +31,7 @@ def view_issues_show_details_bottom(context) content << " const _TXT_CONFLICT_TITLE = \"" + l(:ide_txt_notice_conflict_title) + "\";\n" content << " const _TXT_CONFLICT_TXT = \"" + l(:ide_txt_notice_conflict_text) + "\";\n" content << " const _TXT_CONFLICT_LINK = \"" + l(:ide_txt_notice_conflict_link) + "\";\n" + content << " const _COMMENTS_IN_REVERSE_ORDER_ = #{User.current.wants_comments_in_reverse_order? ? 'true' : 'false'};\n" content << "\n" content << "
+
+ + +
+
+
` + + /* * Allow inclusion from other page * See https://github.com/Ilogeek/redmine_issue_dynamic_edit/commit/26684a2dd9b12dcc7377afd79e9fe5c142d26ebd for more info @@ -437,27 +458,34 @@ let sendData = function(serialized_data){ document.querySelector('div.issue.details').innerHTML = doc.querySelector('div.issue.details').innerHTML; let tch = document.querySelector('#tab-content-history'); - // sometimes, there will be no history yet (like when the issue was just created). - if(tch) { - let query - if(_COMMENTS_IN_REVERSE_ORDER_) { - query = '#history .journal.has-details:first-child'; - } else { - query = '#history .journal.has-details:last-child'; + // sometimes, there will be no tab-content-history yet (like when the issue was just created). + if(!tch) { + let parser = new DOMParser(); + let dom = parser.parseFromString(HISTORY_DIV, 'text/html'); + let newHistory = dom.querySelector('div'); + let oldHistory = document.querySelector('div#history'); + oldHistory.parentNode.replaceChild(newHistory, oldHistory); + tch = document.querySelector('#tab-content-history'); + } + + let query + if(_COMMENTS_IN_REVERSE_ORDER_) { + query = '#history .journal.has-details:first-child'; + } else { + query = '#history .journal.has-details:last-child'; + } + + let journal = doc.querySelector(query); + if(journal) { + let selectedTabId = $("#history .tabs ul li a.selected").attr("id"); + if(!item_is_visible(selectedTabId, journal)) { + $(journal).css('display', 'none'); } - let journal = doc.querySelector(query); - if(journal) { - let selectedTabId = $("#history .tabs ul li a.selected").attr("id"); - if(!item_is_visible(selectedTabId, journal)) { - $(journal).css('display', 'none'); - } - - if(_COMMENTS_IN_REVERSE_ORDER_) { - tch.insertBefore(journal, tch.firstChild); - } else { - tch.appendChild(journal); - } + if(_COMMENTS_IN_REVERSE_ORDER_) { + tch.insertBefore(journal, tch.firstChild); + } else { + tch.appendChild(journal); } }