2 use strict; use warnings;
4 # ------------------------------------------------------------
5 # turns the facet fields defined on config.metabib_field into JS
6 # ------------------------------------------------------------
9 use OpenILS::Utils::Fieldmapper;
10 use OpenSRF::Utils::SettingsClient;
11 use OpenSRF::Utils::Cache;
14 die "usage: $0 <bootstrap_config> <path> <filename>" unless $ARGV[2];
15 OpenSRF::System->bootstrap_client(config_file => $ARGV[0]);
18 my $filename = $ARGV[2];
20 Fieldmapper->import(IDL => OpenSRF::Utils::SettingsClient->new->config_value("IDL"));
22 # must be loaded after the IDL is parsed
23 require OpenILS::Utils::CStoreEditor;
25 # Get our list of locales
26 my $session = OpenSRF::AppSession->create("open-ils.cstore");
27 my $locales = $session->request("open-ils.cstore.direct.config.i18n_locale.search.atomic", {"code" => {"!=" => undef}}, {"order_by" => {"i18n_l" => "name"}})->gather();
28 $session->disconnect();
30 foreach my $locale (@$locales) {
31 warn "removing facet list from the cache for locale " . $locale->code . "...\n";
32 my $cache = OpenSRF::Utils::Cache->new;
33 $cache->delete_cache("facet_definition.".$locale->code);
35 # fetch the org_unit's and org_unit_type's
36 my $e = OpenILS::Utils::CStoreEditor->new;
37 $e->session->session_locale($locale->code) if ($locale->code);
39 my $types = $e->retrieve_all_actor_org_unit_type;
40 my $tree = $e->request(
41 'open-ils.cstore.direct.config.metabib_field.search.atomic',
42 { facet_field => 't' },
43 { no_i18n => $locale->code ? 0 : 1,
45 flesh_fields => { cmf => [ 'field_class' ] }
48 my $dir = File::Spec->catdir($path, $locale->code);
52 build_tree_js($tree, File::Spec->catfile($dir, $filename));
58 return 'null' unless defined $v;
60 # required for JS code this is checking truthness
61 # without using isTrue() (1/0 vs. t/f)
62 return 1 if $v eq 't';
63 return 0 if $v eq 'f';
65 $v =~ s/([\x{0080}-\x{fffd}])/sprintf('\u%04x',ord($1))/sgoe;
74 my $pile = "var globalFacets = {";
79 name => val($o->name),
80 label => val($o->label),
81 classname => val($o->field_class->name),
82 classlabel => val($o->field_class->label)
85 $pile .= $hash{id}.':{'.join(',', map { "$_:$hash{$_}" } keys %hash).'},';
88 $pile =~ s/,$//; # remove trailing comma
89 $pile .= "}; /* Facets */";
91 open(OUTFH, '>', $outfile) or die "Could not open $outfile : $!";
92 print OUTFH "$pile\n";