From: Bill Erickson Date: Wed, 29 Oct 2014 21:06:58 +0000 (-0400) Subject: kmain227_Authority_browse_interface X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=f04e6cae490d541e1bf0ca9f9c1893cde24d2e08;p=working%2FEvergreen.git kmain227_Authority_browse_interface Cross-port: 590666f --- diff --git a/KCLS/openils/var/templates_kcls/cat/authority/list.tt2 b/KCLS/openils/var/templates_kcls/cat/authority/list.tt2 index 754a8473cf..b38f10aaa3 100644 --- a/KCLS/openils/var/templates_kcls/cat/authority/list.tt2 +++ b/KCLS/openils/var/templates_kcls/cat/authority/list.tt2 @@ -2,11 +2,13 @@ [% WRAPPER base.tt2 %] + diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Cat/Authority.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Cat/Authority.pm index 717bcb4f44..5252ed95b1 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Cat/Authority.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Cat/Authority.pm @@ -8,6 +8,9 @@ use OpenILS::Application::AppUtils; use OpenILS::Utils::Fieldmapper; use OpenILS::Const qw/:const/; use OpenILS::Event; +use Try::Tiny; +use MARC::Record; +use MARC::File::XML ( BinaryEncoding => 'UTF-8' ); my $U = 'OpenILS::Application::AppUtils'; my $MARC_NAMESPACE = 'http://www.loc.gov/MARC21/slim'; @@ -227,6 +230,49 @@ sub count_linked_bibs { } __PACKAGE__->register_method( + method => 'titled_linked_bibs', + api_name => 'open-ils.cat.authority.records.titled_linked_bibs', + signature => q/ + Returns titles of all bib records linked to each authority record in the input list + @param records Array of authority records to return counts + @return A list of hashes containing the authority record ID ("id") and linked bib count ("bibs") + / +); + +sub titled_linked_bibs { + my( $self, $conn, $records ) = @_; + + # Returns array_ref auth_id, bib_id, display_text_for_bib + my $response = $U->storagereq( + 'open-ils.storage.authority.get_linked_bibs', $records); + + # This is a hash of hashes {auth_id => {bib_id => display_text_for_bib}} + my %linked_bibs; + + foreach my $bib (@{$response}){ + + # add to auth's array if it's already there + if ($linked_bibs{${$bib}[0]}){ + + my %oldAuth = $linked_bibs{${$bib}[0]}; + + $oldAuth{${$bib}[1]} = ${$bib}[2]; + } + + # otherwise, make a new auth object + else{ + + my %newAuth = (${$bib}[1] => ${$bib}[2]); + $linked_bibs{${$bib}[0]} = \%newAuth; + } + } + + return \%linked_bibs; +} + + + +__PACKAGE__->register_method( "method" => "retrieve_acs", "api_name" => "open-ils.cat.authority.control_set.retrieve", "api_level" => 1, diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/authority.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/authority.pm index 5e4b9c917f..893fa2d8f9 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/authority.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/authority.pm @@ -343,4 +343,163 @@ sub authority_id_find { return $list; } +## Grabs all bibs (title by author in a string) with ids of bibs and +# authorities using a list of authority ID's + +__PACKAGE__->register_method( + api_name => 'open-ils.storage.authority.get_linked_bibs', + method => 'get_linked_bibs', + api_level => 1, + stream => 1, +); + +sub get_linked_bibs { + + my $self = shift; + my $client = shift; + my $auth_ids_ref = shift; + + my @holder_array = (); + my $id_string = ''; + my $length = scalar @{ $auth_ids_ref }; + + if ($length > 0){ + + foreach my $id (@{ $auth_ids_ref }){ + + $id_string .= $id . ','; + } + + # Remove last comma + chop($id_string); + + # Build SQL statement + my $select = <<" SQL"; + SELECT abl.authority AS auth_id, bre.id AS bre_id, bre.marc AS marc FROM biblio.record_entry bre + JOIN authority.bib_linking abl ON (bre.id = abl.bib) + WHERE abl.authority in ($id_string); + SQL + + @holder_array = @{ authority::full_rec->db_Main->selectall_arrayref( $select ) }; + + foreach my $row (@holder_array){ + + ${$row}[2] = get_display_string(${$row}[2]); + } + } + + return \@holder_array; +} + +sub get_display_string { + + my $marc_xml = shift; + + # Grab and cleanup title + my $title = get_marc_value($marc_xml, 245, 'a'); + + my @split_array = split(/\//, $title); + $title = $split_array[0]; + $title =~ s/\[(.*?)]//g; + $title =~ s/ ://g; + + # Grab and cleanup author + my $author = get_marc_value($marc_xml, 100, 'a'); + + # DVD's should grab editor + if ($author eq "Not Found" || $author eq ""){ + + $author = get_marc_value($marc_xml, 700, 'a'); + } + + my $return_string = $title . " by " . $author; + + if ($author eq "Not Found"){ + + $return_string = $title; + } + + return $return_string; +} + +sub get_marc_value { + + my $xml = shift; + my $value = shift; + my $code = shift; + my $return_value = "Not Found"; + + if($xml =~ m//) { + + my $datafield = $1; + + if ($code && $datafield =~ m/(.*?)(.*?)debug("get_marc_value timed out!"); + }; + } + + return $return_value; +} + +sub get_marc_value_use_marc { + + my $xml = shift; + my $value = shift; + my $code = shift; + my $return_value; + + if($xml =~ m/""/) { + + $xml = ""; + + my $r = MARC::Record->new_from_xml($xml); + + if ($value == 100){ + + $return_value = $r->author(); + } + + if ($value == 245){ + + $return_value = $r->title_proper(); + } + + else{ + + if ($code){ + + $return_value = $r->subfield("$value",$code); + } + else{ + + $return_value = $r->subfield("$value","a"); + } + } + } + + return $return_value; +} + 1; diff --git a/Open-ILS/web/js/ui/kcls/cat/authority/list.js b/Open-ILS/web/js/ui/kcls/cat/authority/list.js index f446dd9161..3037fb8943 100644 --- a/Open-ILS/web/js/ui/kcls/cat/authority/list.js +++ b/Open-ILS/web/js/ui/kcls/cat/authority/list.js @@ -16,6 +16,7 @@ dojo.require('openils.XUL'); dojo.require('openils.widget.OrgUnitFilteringSelect'); dojo.require("openils.widget.PCrudAutocompleteBox"); dojo.require("MARC.FixedFields"); + dojo.requireLocalization("openils.authority", "authority"); var auth_strings = dojo.i18n.getLocalization("openils.authority", "authority"); @@ -100,7 +101,8 @@ function displayAuthorities(data) { dojo.place( '
' + '
' + - '' + auth.text + '
ID: ' + + '' + auth.text + '
ID: ' + auth.id + '
' + '
Control Set: ' + fetch_control_set(auth.thesaurus).name() + @@ -194,8 +196,8 @@ function displayAuthorities(data) { auth_mb.placeAt(dojo.create("div", null, "auth" + auth.id, "first"), "first"); auth_menu.startup(); }); - - showBibCount(idArr); + + getAssociatedBibs(idArr); } function viewMARC(recId) { @@ -250,35 +252,87 @@ function confirmDelete(recId) { } } -function showBibCount(authIds) { - /* Decorate the list with # of bibs linked to each authority record */ - var ses = new OpenSRF.ClientSession('open-ils.cat'); - var req = ses.request('open-ils.cat.authority.records.count_linked_bibs', authIds); - var linkedIds = []; +function getAssociatedBibs(authIds) { + + var ses = new OpenSRF.ClientSession('open-ils.cat'); + var req = ses.request('open-ils.cat.authority.records.titled_linked_bibs', authIds); + req.oncomplete = function(r) { + var msg = r.recv().content(); - dojo.forEach(msg, function(auth) { - linkedIds.push(auth.authority); - dojo.place('' + auth.bibs + ' ', 'authLabel' + auth.authority, 'first'); - } - ); - - /* Assign counts of 0 for every non-linked authority */ - dojo.forEach(authIds, function (id) { - var found = false; - dojo.forEach(linkedIds, function (lid) { - if (id == lid) { - found = true; - } - }); - if (!found) { - dojo.place('0 ', 'authLabel' + id, 'first'); - } - }); + + for (var i in authIds){ + + if (authIds[i] in msg){ + + var count = 0; + + for (var bib in msg[authIds[i]]){ + + count ++; + + dojo.place(' ', + 'auth' + authIds[i], + 'last'); + } + + dojo.place('► ' + count + + '', + 'authLabel' + authIds[i], 'first'); + } + + else{ + + dojo.place('0 ', 'authLabel' + authIds[i], 'first'); + dojo.place('
-
', 'auth' + authIds[i], 'last'); + } + } } req.send(); } +function toggleBibsForAuthority(authId){ + + var bibs = document.getElementsByClassName("forAuth" + authId); + var show = true; + + for (var i in bibs){ + + if (bibs[i] != undefined && bibs[i].style != undefined){ + + if (bibs[i].style.visibility == "" || bibs[i].style.visibility == "hidden"){ + + bibs[i].style.visibility = "visible"; + show = true; + } + + else{ + + bibs[i].style.visibility = "hidden"; + show = false; + } + } + } + + var textToChange = document.getElementById("bibcount" + authId).innerHTML; + + if (show){ + + var changedText = textToChange.replace(textToChange.substring(0,1), String.fromCharCode(9660)); + } + + else{ + + var changedText = textToChange.replace(textToChange.substring(0,1), String.fromCharCode(9658)); + } + + document.getElementById("bibcount" + authId).innerHTML = changedText; +} + function loadMarcEditor(pcrud, rec) { /* Prevent the spawned MARC editor from making its title bar inaccessible */