From 9cb4388a37d6eeb3003bce8e151ff4fb866d1e49 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-loader.css | 78 ++++++++++++++++++++++ .../prog/en/css/admin/floating-matrix.css | 8 +++ .../prog/en/js/admin/floating-matrix.js | 64 ++++++++++++++++++ .../prog/en/modules/admin/floating-matrix.tt | 27 ++++++++ 5 files changed, 187 insertions(+) create mode 100644 koha-tmpl/intranet-tmpl/prog/en/css/admin/floating-matrix-loader.css 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-loader.css b/koha-tmpl/intranet-tmpl/prog/en/css/admin/floating-matrix-loader.css new file mode 100644 index 0000000..70e69a0 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/css/admin/floating-matrix-loader.css @@ -0,0 +1,78 @@ +.cssload-loader { + position: relative; + left: calc(50% - 8px); + width: 16px; + height: 16px; + border-radius: 50%; + -moz-border-radius: 50%; + perspective: 200px; + margin-top: 3px; + visibility: hidden; +} + +.cssload-inner { + position: absolute; + width: 100%; + height: 100%; + box-sizing: border-box; + -moz-box-sizing: border-box; + border-radius: 50%; + -moz-border-radius: 50%; +} + +.cssload-inner.cssload-one { + left: 0%; + top: 0%; + animation: cssload-rotate-one 1.3s linear infinite; + -moz-animation: cssload-rotate-one 1.3s linear infinite; + border-bottom: 2px solid rgb(0,0,0); +} + +.cssload-inner.cssload-two { + right: 0%; + top: 0%; + animation: cssload-rotate-two 1.3s linear infinite; + -moz-animation: cssload-rotate-two 1.3s linear infinite; + border-right: 2px solid rgb(0,0,0); +} + +.cssload-inner.cssload-three { + right: 0%; + bottom: 0%; + animation: cssload-rotate-three 1.3s linear infinite; + -moz-animation: cssload-rotate-three 1.3s linear infinite; + border-top: 2px solid rgba(0,0,0,0.99); +} + + + + + + + +@keyframes cssload-rotate-one { + 0% { + transform: rotateX(35deg) rotateY(-45deg) rotateZ(0deg); + } + 100% { + transform: rotateX(35deg) rotateY(-45deg) rotateZ(360deg); + } +} + +@keyframes cssload-rotate-two { + 0% { + transform: rotateX(50deg) rotateY(10deg) rotateZ(0deg); + } + 100% { + transform: rotateX(50deg) rotateY(10deg) rotateZ(360deg); + } +} + +@keyframes cssload-rotate-three { + 0% { + transform: rotateX(35deg) rotateY(55deg) rotateZ(0deg); + } + 100% { + transform: rotateX(35deg) rotateY(55deg) rotateZ(360deg); + } +} 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