From e4de94839d306b5f3da15d8d06f7d00ae2e91a7a Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Tue, 24 Jan 2012 12:12:44 -0500 Subject: [PATCH] kpac : infrastructure Signed-off-by: Bill Erickson --- Open-ILS/examples/apache/eg_vhost.conf | 14 ++++ Open-ILS/examples/kpac.xml | 6 +- .../src/perlmods/lib/OpenILS/WWW/EGKPacLoader.pm | 91 ++++++++++++++++++++++ Open-ILS/src/templates/kpac/home.tt2 | 10 +++ Open-ILS/src/templates/kpac/parts/base.tt2 | 14 ++++ Open-ILS/src/templates/kpac/parts/page.tt2 | 36 +++++++++ 6 files changed, 168 insertions(+), 3 deletions(-) create mode 100644 Open-ILS/src/perlmods/lib/OpenILS/WWW/EGKPacLoader.pm create mode 100644 Open-ILS/src/templates/kpac/home.tt2 create mode 100644 Open-ILS/src/templates/kpac/parts/base.tt2 create mode 100644 Open-ILS/src/templates/kpac/parts/page.tt2 diff --git a/Open-ILS/examples/apache/eg_vhost.conf b/Open-ILS/examples/apache/eg_vhost.conf index 9fd59b2604..5d5551be8e 100644 --- a/Open-ILS/examples/apache/eg_vhost.conf +++ b/Open-ILS/examples/apache/eg_vhost.conf @@ -611,6 +611,20 @@ RewriteRule ^/openurl$ ${openurl:%1} [NE,PT] # (e.g. NOVELIST) into here or to an outer container shared by # both /opac and /eg/opac since some are used in both places + + PerlSetVar OILSWebContextLoader "OpenILS::WWW::EGKPacLoader" + # Expire the HTML quickly since we're loading dynamic data for each page + ExpiresActive On + ExpiresByType text/html "access plus 5 seconds" + + # For use with embedded Content Cafe content + #SetEnv OILS_CONTENT_CAFE_USER 123 + #SetEnv OILS_CONTENT_CAFE_PASS 456 + # Consider copying/moving other added content configs + # (e.g. NOVELIST) into here or to an outer container shared by + # both /opac and /eg/opac since some are used in both places + + # Note: the template processor will decline handling anything it does not diff --git a/Open-ILS/examples/kpac.xml b/Open-ILS/examples/kpac.xml index b370e51ba4..22868a7ccf 100644 --- a/Open-ILS/examples/kpac.xml +++ b/Open-ILS/examples/kpac.xml @@ -11,7 +11,7 @@ 10 12 - + su:mammal audience(j) su:reptile audience(j) su:fish audience(j) @@ -21,11 +21,11 @@ su:aliens audience(j) http://wikipedia.org/animals - + 92 onions and such audience(j) - + su:igneous rock audience(j) su:sedimentary rock audience(j) su:metamorphic rock audience(j) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGKPacLoader.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGKPacLoader.pm new file mode 100644 index 0000000000..1a200a4343 --- /dev/null +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGKPacLoader.pm @@ -0,0 +1,91 @@ +package OpenILS::WWW::EGKPacLoader; +use base 'OpenILS::WWW::EGCatLoader'; +use strict; use warnings; +use XML::Simple; +use Apache2::Const -compile => qw(OK DECLINED FORBIDDEN HTTP_INTERNAL_SERVER_ERROR REDIRECT HTTP_BAD_REQUEST); +use OpenSRF::Utils::Logger qw/$logger/; +use OpenILS::Application::AppUtils; +use OpenILS::Utils::CStoreEditor qw/:funcs/; +my $U = 'OpenILS::Application::AppUtils'; +my $kpac_config; + +# ----------------------------------------------------------------------------- +# Override our parent's load() sub so we can do kpac-specific path routing. +# ----------------------------------------------------------------------------- +sub load { + my $self = shift; + + $self->init_ro_object_cache; + + my $stat = $self->load_common; + return $stat unless $stat == Apache2::Const::OK; + + $self->load_kpac_config; + + my $path = $self->apache->path_info; + + return $self->load_simple("home") if $path =~ m|kpac/home|; + + # ---------------------------------------------------------------- + # Everything below here requires SSL + # ---------------------------------------------------------------- + return $self->redirect_ssl unless $self->cgi->https; + return $self->load_logout if $path =~ m|kpac/logout|; + + if($path =~ m|kpac/login|) { + return $self->load_login unless $self->editor->requestor; # already logged in? + + # This will be less confusing to users than to be shown a login form + # when they're already logged in. + return $self->generic_redirect( + sprintf( + "https://%s%s/kpac/home", + $self->apache->hostname, $self->ctx->{base_path} + ) + ); + } + + + # ---------------------------------------------------------------- + # Everything below here requires authentication + # ---------------------------------------------------------------- + return $self->redirect_auth unless $self->editor->requestor; + + # AUTH pages + + return Apache2::Const::OK; +} + + +sub load_kpac_config { + my $self = shift; + my $path = '/home/berick/code/Evergreen/Open-ILS/examples/kpac.xml'; # TODO: apache config + + unless ($kpac_config) { + $kpac_config = XMLin( + $path, + KeyAttr => ['id'], + ForceArray => ['layout', 'page', 'cell'], + NormaliseSpace => 2 + ); + } + + # TODO: make generic "whoami" sub for EGCatLoader. + my $ou = $self->ctx->{physical_loc} || $self->cgi->param('loc') || $self->ctx->{aou_tree}->()->id; + my $layout; + + # Search up the org tree to find the nearest config for the context org unit + while (my $org = $self->ctx->{get_aou}->($ou)) { + ($layout) = grep {$_->{owner} eq $org->id} @{$kpac_config->{layout}}; + last if $layout; + $ou = $org->parent_ou; + } + + $self->ctx->{kpac_layout} = $kpac_config->{pages}->{page}->{$layout->{page}}; + $self->ctx->{kpac_config} = $kpac_config; +} + + + +1; + diff --git a/Open-ILS/src/templates/kpac/home.tt2 b/Open-ILS/src/templates/kpac/home.tt2 new file mode 100644 index 0000000000..abd1faa7c5 --- /dev/null +++ b/Open-ILS/src/templates/kpac/home.tt2 @@ -0,0 +1,10 @@ +[% + PROCESS "opac/parts/header.tt2"; + PROCESS "kpac/parts/page.tt2"; + WRAPPER "kpac/parts/base.tt2"; + ctx.page_title = l("Home") +%] + + [% render_kpac_page(ctx.kpac_layout); %] + +[% END %] diff --git a/Open-ILS/src/templates/kpac/parts/base.tt2 b/Open-ILS/src/templates/kpac/parts/base.tt2 new file mode 100644 index 0000000000..674f38a306 --- /dev/null +++ b/Open-ILS/src/templates/kpac/parts/base.tt2 @@ -0,0 +1,14 @@ + + + + + [% IF ctx.authtime %] + + [% END %] + [% l("Kid's Catalog - [_1]", ctx.page_title) %] + + + [% content %] + [%# INCLUDE 'opac/parts/js.tt2' %] + + diff --git a/Open-ILS/src/templates/kpac/parts/page.tt2 b/Open-ILS/src/templates/kpac/parts/page.tt2 new file mode 100644 index 0000000000..d5dd6a0777 --- /dev/null +++ b/Open-ILS/src/templates/kpac/parts/page.tt2 @@ -0,0 +1,36 @@ +[% + MACRO render_kpac_page(page) BLOCK; + ncols = page.columns; + name = page.name; + idx = 0 %] + + + [% FOR cell IN page.cell; + IF idx == ncols; + %][% + idx = 0; + END; + idx = idx + 1; + + IF cell.type == 'topic'; + page_id = cell.content; + topic_page = ctx.kpac_config.pages.page.$page_id %] + + + + + +
[% topic_page.name %] + + [% ELSIF cell.type == 'search'; %] + + [% cell.name _ ' : ' _ cell.content %] + + [% ELSIF cell.type == 'link'; %] + + [% cell.name _ ' : ' _ cell.content %] + + [% END %] + [% END %] +
+[% END %] -- 2.11.0