From 62de68b68b015fad9c6cfbef9fe867ca35083bde Mon Sep 17 00:00:00 2001 From: Olli-Antti Kivilahti Date: Wed, 11 Nov 2015 15:10:49 +0200 Subject: [PATCH] Bug 9525 - group floating rules, floating rule tester :) Implemented a tester to floating-matrix.pl to more easily test the changes in the floating rules matrix "FloMax". --- admin/floating-matrix-api.pl | 10 ++++ .../prog/en/css/admin/floating-matrix.css | 8 +++ .../prog/en/js/admin/floating-matrix.js | 64 ++++++++++++++++++++++ .../prog/en/modules/admin/floating-matrix.tt | 27 +++++++++ 4 files changed, 109 insertions(+) diff --git a/admin/floating-matrix-api.pl b/admin/floating-matrix-api.pl index 47cfe8d..27a69be 100755 --- a/admin/floating-matrix-api.pl +++ b/admin/floating-matrix-api.pl @@ -25,6 +25,7 @@ use JSON::XS; use C4::Context; use C4::Output; use C4::Auth qw(check_cookie_auth); +use C4::Items; use Koha::FloatingMatrix; @@ -52,6 +53,15 @@ if ($data) { $fm->deleteBranchRule($data->{fromBranch}, $data->{toBranch}); $fm->store(); } + elsif ($data->{test}) { + my $item = C4::Items::GetItem(undef, $data->{barcode}); + if ($data->{barcode} && $item) { + $data->{testResult} = $fm->checkFloating($item, $data->{fromBranch}, $data->{toBranch}); + } + else { + Koha::Exception::BadParameter->throw(error => "No Item found using barcode '".$data->{barcode}."'"); + } + } ##If we are getting a POST-request, we UPSERT else { $fm->upsertBranchRule($data); diff --git a/koha-tmpl/intranet-tmpl/prog/en/css/admin/floating-matrix.css b/koha-tmpl/intranet-tmpl/prog/en/css/admin/floating-matrix.css index de8df9a..14da50b 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/css/admin/floating-matrix.css +++ b/koha-tmpl/intranet-tmpl/prog/en/css/admin/floating-matrix.css @@ -1,6 +1,14 @@ .disabled-transfer { background-color: #FF8888; } + +#testResulDisplay { width: 20px; + height: 22px; + background-color: #B9D8D9; + vertical-align: middle; + display: inline-block; +} + .branchRule select { width: 100%; } .branchRule select {padding: 0px; margin: 5px 0px;} diff --git a/koha-tmpl/intranet-tmpl/prog/en/js/admin/floating-matrix.js b/koha-tmpl/intranet-tmpl/prog/en/js/admin/floating-matrix.js index 1547f9e..09b669d 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/js/admin/floating-matrix.js +++ b/koha-tmpl/intranet-tmpl/prog/en/js/admin/floating-matrix.js @@ -1,5 +1,6 @@ ////Create javascript namespace var FloMax = FloMax || {}; +FloMax.Tester = FloMax.Tester || {}; //// DOCUMENT READY INIT SCRIPTS @@ -15,6 +16,13 @@ $(document).ready(function() { FloMax.changeBranchRuleColor(this); }); + //Bind actions to the FloMax Tester + $("#floatingRuleTester input[type='submit']").bind({ + click: function() { + FloMax.Tester.testFloating(); + } + }); + //Bind action listeners to the floating matrix $(".branchRule").bind({ click: function() { @@ -183,4 +191,60 @@ FloMax.persistBranchRule = function (brJSON, branchRule) { alert("Saving floating rule "+brJSON.fromBranch+"-"+brJSON.toBranch+" failed, because of the following error:\n"+data.status+" "+data.statusText+"\n"+"More specific error: "+error.error); }); } +} + +FloMax.Tester.defaultTestResultColor = "#B9D8D9"; + +FloMax.Tester.testFloating = function() { + var testCase = FloMax.Tester.buildTestCaseFromHTML(); + $(".cssload-loader").css('visibility', 'visible'); + + $.ajax('floating-matrix-api.pl', + {method : 'POST', + data : testCase, + dataType : 'json', + }).done(function(data, textStatus, jqXHR){ + + FloMax.Tester.displayTestResult(data.testResult); + + }).fail(function (data, textStatus, jqXHR) { + var error = $.parseJSON(data.responseText); //Pass the error as JSON so we don't trigger the default Koha error pages. + alert("Testing floating rule "+testCase.fromBranch+"-"+testCase.toBranch+" failed, because of the following error:\n"+data.status+" "+data.statusText+"\n"+"More specific error: "+error.error); + FloMax.Tester.displayTestResult("error"); + }); +} +FloMax.Tester.buildTestCaseFromHTML = function () { + var fromBranch = $("#floatingRuleTester #testerFromBranch").val(); + var toBranch = $("#floatingRuleTester #testerToBranch").val(); + var barcode = $("#floatingRuleTester #testerBarcode").val(); + + var testCase = { + 'fromBranch' : fromBranch, + 'toBranch' : toBranch, + 'barcode' : barcode, + 'test': true, + }; + return testCase; +} +FloMax.Tester.displayTestResult = function (testResult) { + $(".cssload-loader").css('visibility', 'hidden'); + var color; + if (testResult == null) { + color = FloMax.branchRuleDisabledColor; + } + else if (testResult == 'ALWAYS') { + color = FloMax.branchRuleAlwaysColor; + } + else if (testResult == 'POSSIBLE') { + color = FloMax.branchRulePossibleColor; + } + else if (testResult == "error") { + color = FloMax.Tester.defaultTestResultColor; + } + else { + color = FloMax.Tester.defaultTestResultColor; + alert("Couldn't display test result '"+testResult+"'. Value is unknown."); + } + + $("#testResulDisplay").css('background-color', color); } \ No newline at end of file diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/floating-matrix.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/floating-matrix.tt index 1d113a3..27d6a16 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/floating-matrix.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/floating-matrix.tt @@ -1,6 +1,7 @@ [% INCLUDE 'doc-head-open.inc' %] Koha › Administration › Floating matrix + [% INCLUDE 'doc-head-close.inc' %] @@ -38,6 +39,32 @@ +
+ Floating rule tester +
+ + + + + + + +
+
+
+
+
+
+
+ -- 1.9.1
From \ To