From ef5f199a04ed1062cfa2e655844e1c88db927d00 Mon Sep 17 00:00:00 2001 From: Owen Leonard Date: Fri, 14 Aug 2020 12:08:10 +0000 Subject: [PATCH] Bug 26207: Compare values of system preference log entries This patch adds the ability to compare the values of system preferences in the system log. The user can select two entries in the log search results and view a diff of the two versions. The feature is designed specifically for CSS and JS preferences like OpacUserCSS or OpacUserJS where code changes are difficult to track. To test, apply the patch and go to Tools -> Log viewer. You may need to add values and make changes to preferences like OpacUserCSS if you don't already have a history in your logs. - Perform a search for log entries in the "System prefs" module. - In the results, each entry for a system preference should have a "Compare" checkbox." - Check one of the checkboxes. - The table should now be filtered by the system preference name. This facilitates meaningful selections for comparison. - You should see a message displayed onscreen, "Showing results for...[ preference name]" - The "Check none" link in the toolbar above the table should now be enabled. - If youy click the "Compare selected" link in the toolbar at this stage you should get a message, "You must select two entries to compare." - If you uncheck the checkbox the table should return to an unfiltered state. - Check two checkboxes. - The "Compare selected" link in the toolbar should now be enabled. - Next to each of the checkboxes you checked should be a "View comparison" link. - Clicking either of the "View comparison" links or the "Compare selected" link should trigger a modal with the diff view of the two preferences. - Try to select a third checkbox. You should get a message, "You can select a maximum of two checkboxes." The box should remain unchecked. - Test that unchecking both checkboxes manually clears the table filter. - Test that the "Check none" link works to uncheck checked boxes and clear the table filter. Signed-off-by: Brandon J --- .../prog/en/modules/tools/viewlog.tt | 105 +++++++++++++++--- koha-tmpl/intranet-tmpl/prog/js/viewlog.js | 70 ++++++++++++ 2 files changed, 158 insertions(+), 17 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/viewlog.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/viewlog.tt index 58e8b54914..aa314e3bec 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/viewlog.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/viewlog.tt @@ -16,22 +16,49 @@ [% END %] [% INCLUDE 'doc-head-close.inc' %] - +[% Asset.css("css/humanmsg.css") | $raw %] +[% FILTER collapse %] + +[% END %] @@ -225,6 +252,10 @@ fieldset.rows label.viewlog { [% IF ( do_it ) %] [% IF ( total ) %]

Log entries

+
+ Check none + +
@@ -284,7 +315,18 @@ fieldset.rows label.viewlog { [% IF ( loopro.module == 'CIRCULATION' ) %] Item [% loopro.barcode | html %] [% ELSE %] - [% loopro.info | html %] + [% IF loopro.module == "SYSTEMPREFERENCE" %] +
+ [% loopro.info | html %] +
+
+ +
+ [% ELSE %] +
+ [% loopro.info | html %] +
+ [% END %] [% END %] @@ -325,15 +367,44 @@ fieldset.rows label.viewlog { + + [% MACRO jsinclude BLOCK %] [% INCLUDE 'calendar.inc' %] [% INCLUDE 'datatables.inc' %] [% INCLUDE 'columns_settings.inc' %] + [% Asset.js("lib/jquery/plugins/humanmsg.js") | $raw %] [% Asset.js("js/tools-menu.js") | $raw %] + [% Asset.js("lib/hc-sticky.js") | $raw %] [% IF ( circulation ) %] [% INCLUDE 'str/members-menu.inc' %] [% Asset.js("js/members-menu.js") | $raw %] [% END %] + [% Asset.js("lib/jsdiff/jsdiff.min.js") | $raw %] diff --git a/koha-tmpl/intranet-tmpl/prog/js/viewlog.js b/koha-tmpl/intranet-tmpl/prog/js/viewlog.js index 1354c95e0a..04eb6c7b2f 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/viewlog.js +++ b/koha-tmpl/intranet-tmpl/prog/js/viewlog.js @@ -1,3 +1,5 @@ +var Sticky; + function tickAll(section){ $("input[type='checkbox'][name='" + section + "']").prop("checked", true); $("#" + section.slice(0,-1) + "ALL").prop("checked", true); @@ -10,7 +12,52 @@ function untickAll(section){ $("input[type='checkbox'][name='" + section + "']").prop("disabled", false); } +function limitCheckboxes() { + var checkboxes = $(".compare"); + var limit = 2; + var compare_link = ' ' + __("View comparison") + ''; + checkboxes.each(function(){ + $(this).on("change", function(){ + var checked = []; + checkboxes.each(function () { + if( $(this).prop("checked") ){ + checked.push( $(this).data("actionid") ); + } + }); + if (checked.length > 0) { + $("#select_none").removeClass("disabled"); + } else { + $("#select_none").addClass("disabled"); + $("#logst").DataTable().search("").draw(); + } + if( checked.length == 1 ){ + $("#logst").DataTable().search($(this).data("filter")).draw(); + humanMsg.displayAlert( __("Showing results for %s").format( $(this).data("filter") ) ); + } + if( checked.length == 2 ){ + $("#compare_info" + checked[0]).prepend( compare_link ); + $("#compare_info" + checked[1]).prepend( compare_link ); + $("button.compare_link").removeClass("disabled"); + } else if (checked.length > limit) { + humanMsg.displayAlert( __("You can select maximum of two checkboxes") ); + $(this).prop("checked", false ); + } else if (checked.length < limit) { + $("a.compare_link").remove(); + $("button.compare_link").addClass("disabled"); + } + }); + }); +} + $(document).ready(function(){ + limitCheckboxes(); + if ($('#toolbar').length) { + Sticky = $("#toolbar"); + Sticky.hcSticky({ + stickTo: "main", + stickyClass: "floating" + }); + } if ( $('input[type="checkbox"][name="modules"]:checked').length == 0 ) { tickAll('modules'); @@ -67,4 +114,27 @@ $(document).ready(function(){ "order": [[0, "desc"]], "pagingType" : "full" }, columns_settings); + + $("body").on("click", ".compare_link", function(e){ + e.preventDefault(); + if( $(this).hasClass('disabled') ){ + humanMsg.displayAlert( __("You must select two entries to compare") ); + } else { + var firstid = $(".compare:checked").eq(0).data("actionid"); + var secondid = $(".compare:checked").eq(1).data("actionid"); + var firstvalue = $("#loginfo" + firstid).text(); + var secondvalue = $("#loginfo" + secondid).text(); + var diffs = diffString(secondvalue, firstvalue); + $("#col1 pre,#col2 pre").html(diffs); + $("#compareInfo").modal("show"); + } + }); + $("#compareInfo").on("hidden.bs.modal", function(){ + $("#col1 pre,#col2 pre").html(""); + }); + + $("#select_none").on("click", function(e){ + e.preventDefault(); + $(".compare:checked").prop("checked", false).change(); + }); }); -- 2.17.1
[% PROCESS translate_log_interface log_interface=loopro.interface %]