From e08b4b416858b3a1bedb6374eea9c93b28eb17a7 Mon Sep 17 00:00:00 2001 From: Baptiste Wojtkowski Date: Mon, 22 May 2017 08:40:25 +0000 Subject: [PATCH] Bug 17047: Minor changes - search on reports module is now also validated by pressing enter. - AutoShare now initialized with nothing autmaticaly shared. - To create a report you now have to click on New report => New report from Mana. - Error messages are displayed in case of fail - Correct the display of sql reports containing "'" - Importing a report from Mana now opens the edit page - You don't get message after a successful import from mana (you simply get redirected) - Fix an error when cretaing subscription - Fix mana search - Correct encoding issues Signed-off-by: Brendan A Gallagher Signed-off-by: Kyle M Hall Rebased-by: Alex Arnaud (2018-07-04) Signed-off-by: Michal Denar Signed-off-by: Michal Denar --- Koha/SharedContent.pm | 2 +- Koha/Subscription.pm | 1 + .../atomicupdate/mana_03-add_mana_autoshare.sql | 2 +- .../intranet-tmpl/prog/en/includes/calendar.inc | 2 +- .../en/includes/mana/mana-report-search-result.inc | 2 +- .../mana/mana-subscription-search-result.inc | 3 +- .../prog/en/includes/reports-toolbar.inc | 141 +++++++++++++++++++++ .../en/modules/reports/guided_reports_start.tt | 122 ++---------------- .../prog/en/modules/serials/serials-search.tt | 2 +- .../prog/en/modules/serials/subscription-add.tt | 1 - .../intranet-tmpl/prog/js/subscription-add.js | 17 ++- reports/guided_reports.pl | 1 + serials/serials-search.pl | 3 + serials/subscription-add.pl | 2 +- svc/mana/share | 19 +++ 15 files changed, 194 insertions(+), 126 deletions(-) diff --git a/Koha/SharedContent.pm b/Koha/SharedContent.pm index 9bd4d09..55d10c5 100644 --- a/Koha/SharedContent.pm +++ b/Koha/SharedContent.pm @@ -42,7 +42,7 @@ sub manaRequest { my $response = $userAgent->request($mana_request); - eval { $result = from_json( $response->decoded_content ); }; + eval { $result = from_json( $response->decoded_content, { utf8 => 1} ); }; $result->{code} = $response->code; if ( $@ ){ $result->{msg} = $response->{_msg}; diff --git a/Koha/Subscription.pm b/Koha/Subscription.pm index 197bfe3..2709468 100644 --- a/Koha/Subscription.pm +++ b/Koha/Subscription.pm @@ -119,6 +119,7 @@ sub get_search_info { my $self=shift; my $searched_sub_id = shift; my $biblio = Koha::Biblios->find( { 'biblionumber' => $searched_sub_id } ); + return unless $biblio; my $biblioitem = Koha::Biblioitems->find( { 'biblionumber' => $searched_sub_id } ); diff --git a/installer/data/mysql/atomicupdate/mana_03-add_mana_autoshare.sql b/installer/data/mysql/atomicupdate/mana_03-add_mana_autoshare.sql index 353ffc1..f5cc363 100644 --- a/installer/data/mysql/atomicupdate/mana_03-add_mana_autoshare.sql +++ b/installer/data/mysql/atomicupdate/mana_03-add_mana_autoshare.sql @@ -1,2 +1,2 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES -('AutoShareWithMana','subscription','','defines datas automatically shared with mana','multiple'); +('AutoShareWithMana','','','defines datas automatically shared with mana','multiple'); diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc index 653221e..0328b3d 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc @@ -118,7 +118,7 @@ jQuery(function($){ dayNamesMin: [_("Su"),_("Mo"),_("Tu"),_("We"),_("Th"),_("Fr"),_("Sa")], weekHeader: _("Wk"), dateFormat: "[% IF ( dateformat == "us" ) %]mm/dd/yy[% ELSIF ( dateformat == "metric" ) %]dd/mm/yy[% ELSIF ( dateformat == "dmydot" ) %]dd.mm.yy[% ELSE %]yy-mm-dd[% END %]", - firstDay: [% Koha.Preference('CalendarFirstDayOfWeek') | html %], + firstDay: '[% Koha.Preference('CalendarFirstDayOfWeek') | html %]', isRTL: [% IF ( bidi ) %]true[% ELSE %]false[% END %], showMonthAfterYear: false, yearSuffix: ''}; diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/mana/mana-report-search-result.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/mana/mana-report-search-result.inc index 455f453..2de9fea 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/mana/mana-report-search-result.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/mana/mana-report-search-result.inc @@ -30,7 +30,7 @@ [% END %] [% IF ( report.report_name ) %][% report.report_name %][% END %] -
+
[% IF report.notes.length > 200 %] [% report.notes.substr(0,200) %]Show More
+ +[% IF Koha.Preference('Mana')==1 %] + +[% END %] + + diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt index 76c3f0e..2f2c25f 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt @@ -149,6 +149,13 @@ canned reports and writing custom SQL reports.

+[% IF report_converted %] +
+ The report "[% report_converted %]" has been converted. +
+[% END %] + + [% IF ( saved1 ) %] [% IF ( savedreports ) %]

Saved reports

@@ -190,14 +197,8 @@ canned reports and writing custom SQL reports.

[% END %] - [% IF (Koha.Preference('Mana') == 1) %] - - [% END %] - -

[% savedreport.sql %]

+
@@ -237,7 +238,7 @@ canned reports and writing custom SQL reports.

[% IF ( CAN_user_reports_delete_reports ) %] [% END %] - +
@@ -1273,10 +1274,6 @@ $(document).ready(function() { window.history.back(); }); - $(".mana_search_button").on("click",function(){ - mana_search($(this).prev().val()); - }); - $(".ShareButton").on("click", function(){ if($(this).closest("tr").find(".report_notes").text().length < 20 || $(this).closest("tr").find(".report_name").text().length < 20){ $("#shared_infos").hide(); @@ -1293,10 +1290,6 @@ $(document).ready(function() { } }); - $('#search_form').submit(function () { - return false; - }); - $("#addColumn").on("click",function(){ addColumn(); }); @@ -1488,103 +1481,6 @@ $(document).ready(function() { return confirmDelete(MSG_CONFIRM_DELETE); }); }); - function mana_increment(mana_id, resourcename, fieldvalue, stepvalue = 1){ - $.ajax( { - type: "POST", - url: "/cgi-bin/koha/svc/mana/addvaluetofield", - data: {id: mana_id, field: fieldvalue, resource: resourcename, step: stepvalue}, - datatype: "json", - }).done( function() { - }).fail( function(){ }); - } - - function mana_use( mana_id ){ - $.ajax( { - type:"POST", - url: "/cgi-bin/koha/svc/mana/use", - data: {id:mana_id, resource: 'report', saveinbase: 1}, - dataType: "json", - }) - .done( function (result){ - window.location = ("/cgi-bin/koha/reports/guided_reports.pl?reports=").concat(result.id).concat("&phase=Show%20SQL"); - }) - .fail( function ( foo, msg, longmsg){ - }); - } - - function mana_search( textquery ){ - $.ajax({ - type: "POST", - url: "/cgi-bin/koha/svc/mana/search", - data: {biblionumber: $("#biblionumber").val(), resource: 'report', id: textquery, usecomments: 1}, - dataType: "html", - }) - .done( function( result ) { - $("#mana_search_result .modal-body").html(result); - $("#mana_search_result_label").text("Results from Mana Knowledge Base"); - $("#mana_results_datatable").dataTable($.extend(true, {}, dataTablesDefaults,{ - "sPaginationType":"four_button", - "autoWidth": false, - "columnDefs": [ - { "width": "35%", "targets": 1 } - ], - "aoColumnDefs": [ - { 'bSortable': false, "bSearchable": false, 'aTargets': [ 'NoSort' ] }, - { "sType": "title-string", "aTargets" : [ "title-string" ] }, - { 'sType': "anti-the", 'aTargets' : [ 'anti-the'] } - ] - })); - if($("td.dataTables_empty").length == 0){ - $("#mana_search").show(); - } - - $( "select[class='actionreport1']" ).show(); - $( "button[class='actionreport2']" ).hide(); - $("#CommentButton").on("click", function(){ - var resource_type = "report"; - var target_id = $("#selected_id").val(); - var manamsg = $("#manamsg").val(); - mana_comment(target_id, manamsg, resource_type); - $("#comment_box").modal("hide"); - }); - - $(".showbutton").on("click", function(){ - $(this).parent().hide(); - $(this).parent().next().show(); - }); - - $("a[class='hidebutton']").on("click", function(){ - $(this).parent().hide(); - $(this).parent().prev().show(); - }); - - $("#commentCloseButton").on("click", function(){ - $("#comment_box").modal("hide"); - }); - - $(".actionreport1").on("click", function(){ - $("#selectedcomment").val($(this).val()); - $(this).parent("select").hide(); - $(this).parent("select").next().show(); - }); - - $(".actionreport2").on("click", function(){ - $(this).hide(); - $(this).prev().show(); - mana_increment($("#selectedcomment").val(), 'resource_comment', 'nb', -1); - }); - }).fail( function( result ){ - }); - } - - function mana_comment( target_id, manamsg, resource_type ){ - $.ajax( { - type: "POST", - url: "/cgi-bin/koha/svc/mana/share", - data: {message: manamsg, resource: resource_type , resource_id: target_id}, - datatype: "json", - }) - } function addColumn() { $("#availableColumns option:selected").clone().appendTo("#selectedColumns").attr("selected", "selected"); diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-search.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-search.tt index 3e1d3dc..7e88b10 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-search.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-search.tt @@ -296,7 +296,7 @@ [% IF mana %]
- [% INCLUDE 'mana-subscription-search-result.inc' %] + [% INCLUDE 'mana/mana-subscription-search-result.inc' %]
[% ELSE %]
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tt index 5be4cdd..af8b019 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tt @@ -216,7 +216,6 @@ width: 300px; /* not enough for IE7 apparently */ [% END %]
diff --git a/koha-tmpl/intranet-tmpl/prog/js/subscription-add.js b/koha-tmpl/intranet-tmpl/prog/js/subscription-add.js index 4a091f2..3e75ffe 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/subscription-add.js +++ b/koha-tmpl/intranet-tmpl/prog/js/subscription-add.js @@ -393,6 +393,9 @@ function show_page_2() { } function mana_search() { + $("#mana_search").html("

Mana kb is being asked for your subscription..

"); + $("#mana_search").show(); + $.ajax({ type: "POST", url: "/cgi-bin/koha/svc/mana/search", @@ -416,8 +419,15 @@ function mana_search() { ] })); if( $("#mana_results_datatable").length && $("td.dataTables_empty").length == 0){ - $("#mana_search").show(); + $("#mana_search").html("

Subscription found on Mana Knowledge Base:

Quick fill

"); + } + else if ( $("#mana_results_datatable").length ){ + $("#mana_search").html("

No subscription found on Mana Knowledge Base :(

Please feel free to share you pattern with all others librarians once you are done

"); } + else{ + $("#mana_search").html( result ); + } + $("#mana_search").show(); $( "select[class='actionreport1']" ).show(); $( "button[class='actionreport2']" ).hide(); @@ -446,6 +456,8 @@ function mana_search() { }); }).fail(function(result){ + console.log( msg ); + console.log( longmsg ); }); } @@ -548,9 +560,6 @@ function removeDisabledAttr() { $(document).ready(function() { mana_search(); - $("#myid").on("click", function(){ - debugger; - }) $("#displayexample").hide(); $("#mana_search_result").modal("hide"); $("#aqbooksellerid").on('keypress', function(e) { diff --git a/reports/guided_reports.pl b/reports/guided_reports.pl index bba37de..94e6683 100755 --- a/reports/guided_reports.pl +++ b/reports/guided_reports.pl @@ -182,6 +182,7 @@ elsif ( $phase eq 'Show SQL'){ 'notes' => $report->notes, 'sql' => $report->savedsql, 'showsql' => 1, + 'mana_success' => $input->param('mana_success'), ); } diff --git a/serials/serials-search.pl b/serials/serials-search.pl index d6cb85c..d213c92 100755 --- a/serials/serials-search.pl +++ b/serials/serials-search.pl @@ -96,6 +96,7 @@ for my $field ( @$additional_fields ) { my $expiration_date_dt = $expiration_date ? dt_from_string( $expiration_date ) : undef; my @subscriptions; +my $mana_statuscode; if ($searched){ if ($mana) { my $result = Koha::SharedContent::manaGetRequest("subscription",{ @@ -104,6 +105,7 @@ if ($searched){ ean => $EAN, publisher => $publisher }); + $mana_statuscode = $result->{code}; @subscriptions = @{ $result->{data} }; } else { @@ -127,6 +129,7 @@ if ($searched){ if ($mana) { $template->param( subscriptions => \@subscriptions, + statuscode => $mana_statuscode, total => scalar @subscriptions, title_filter => $title, ISSN_filter => $ISSN, diff --git a/serials/subscription-add.pl b/serials/subscription-add.pl index e0ee70e..170993e 100755 --- a/serials/subscription-add.pl +++ b/serials/subscription-add.pl @@ -304,7 +304,7 @@ sub manage_subscription_numbering_pattern_id { return $existing->id; } - $params->{label} = Koha::Subscription::Numberpattern->uniqueLabel($query->param('patternname')); + $params->{label} = Koha::Subscription::Numberpatterns->uniqueLabel($query->param('patternname')); $params->{description} = $query->param('sndescription'); diff --git a/svc/mana/share b/svc/mana/share index a294bd0..47db3e1 100755 --- a/svc/mana/share +++ b/svc/mana/share @@ -45,3 +45,22 @@ $content->{resource_id} = $input->param("resource_id"); $content->{resource_type} = $input->param("resource"); $content->{message} = $input->param("message"); Koha::SharedContent::manaPostRequest('resource_comment', $content); + my $package = "Koha::".ucfirst($input->param('resource')); + my $resource; + my $result; +eval{ + $result = Koha::SharedContent::manaGetRequestWithId($input->param('resource'), $input->param('id') ); +}; +if ( $@ or $result->{code} == 500 ){ + $resource->{errmsg} = "Error: mana access got broken, please try again later\n\n ( error: $@ )"; +} +else{ + if ( $input->param( 'saveinbase' )) { + $resource = { id => $package->new_from_mana($result->{data})->id }; + } + else{ + $resource = $result->{data}; + } +} + +print(to_json($resource)); -- 2.1.4