From e6560274979630cbda734b53b7b320d96dc3a6a2 Mon Sep 17 00:00:00 2001 From: jesusbagpuss Date: Fri, 24 Jan 2025 12:28:39 +0000 Subject: [PATCH 1/2] Add StaticContent view --- cfg.d/z_irstats2.pl | 1 + .../Plugin/Stats/View/StaticContent.pm | 97 +++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 plugins/EPrints/Plugin/Stats/View/StaticContent.pm diff --git a/cfg.d/z_irstats2.pl b/cfg.d/z_irstats2.pl index 4a530aa..7ae61a7 100644 --- a/cfg.d/z_irstats2.pl +++ b/cfg.d/z_irstats2.pl @@ -528,6 +528,7 @@ $c->{plugins}{"Stats::View::Grid"}{params}{disable} = 0; $c->{plugins}{"Stats::View::KeyFigures"}{params}{disable} = 0; $c->{plugins}{"Stats::View::ReportHeader"}{params}{disable} = 0; +$c->{plugins}{"Stats::View::StaticContent"}{params}{disable} = 0; $c->{plugins}{"Stats::View::Table"}{params}{disable} = 0; $c->{plugins}{"Stats::View::D3::Graph"}{params}{disable} = 0; diff --git a/plugins/EPrints/Plugin/Stats/View/StaticContent.pm b/plugins/EPrints/Plugin/Stats/View/StaticContent.pm new file mode 100644 index 0000000..baa7dff --- /dev/null +++ b/plugins/EPrints/Plugin/Stats/View/StaticContent.pm @@ -0,0 +1,97 @@ +package EPrints::Plugin::Stats::View::StaticContent; + +use EPrints::Plugin::Stats::View; +@ISA = ('EPrints::Plugin::Stats::View'); + +use strict; + +# Stats::View::StaticContent +# +# Allows phrases to be embeded in the Stats grid layout. +# Phrases can contain script references/blocks, so this View can be used to do a lot - if you +# make your phrases complicated enough! +# +# Options: +# - title_phrase +# - view +# - page_phrase +# - container_class (can be used to remove box outlines) +# - title_class +# - content_class + +sub can_export { return 0; } + +sub has_title +{ + my( $self ) = @_; + + return defined $self->options->{title_phrase}; +} + +# Mostly the same as Stats::View, but with the ability to not have a border around everything +sub render +{ + my( $self ) = @_; + + my $session = $self->{session}; + my $frag = $session->make_doc_fragment; + my $options = $self->options; + + # just re-use $self->options->{view} + my $class_id = $self->get_id; + $class_id =~ s/^Stats::View:://g; + $class_id =~ s/::/_/g; + + my $classes = "irstats2_view irstats2_view_$class_id"; + $classes .= " $options->{container_class}" if defined $options->{container_class}; + + if( $self->{hide_from_print} ) + { + $classes .= " ep_noprint"; + } + + my $container = $session->make_element( 'div', class => "$classes" ); + $frag->appendChild( $container ); + + if( $self->has_title() ) + { + my $title_class = 'irstats2_view_title'; + $title_class .= " $options->{title_class}" if defined $options->{title_class}; + my $title = $session->make_element( "div", class => $title_class ); + + $title->appendChild( $self->html_phrase( $options->{title_phrase} ) ); + + $container->appendChild( $title ); + } + + my $content_class = "irstats2_view_content"; + $content_class .= " $options->{content_class}" if defined $options->{content_class}; + + my $content = $session->make_element( "div", class => $content_class ); + $container->appendChild( $content ); + + $content->appendChild( $self->render_content() ); + + return $frag; +} + +sub render_content +{ + my( $self ) = @_; + + my $session = $self->{session}; + + my $frag = $session->make_doc_fragment; + my $view = $self->options->{view}; + my $page = $self->options->{page_phrase}; + + $frag->appendChild( $self->html_phrase( $page ) ); + + return $frag; +} + +# Renders the title of the View, if any. +sub render_title { shift->html_phrase( 'title' ) } + +1; + From e168f3d45169cd199ae2474caba8c2422ca61dd6 Mon Sep 17 00:00:00 2001 From: John Salter Date: Mon, 3 Feb 2025 17:44:41 +0000 Subject: [PATCH 2/2] Add support for more parameters. Fixes #22 --- plugins/EPrints/Plugin/Stats/Utils.pm | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/plugins/EPrints/Plugin/Stats/Utils.pm b/plugins/EPrints/Plugin/Stats/Utils.pm index d11812c..f90541b 100644 --- a/plugins/EPrints/Plugin/Stats/Utils.pm +++ b/plugins/EPrints/Plugin/Stats/Utils.pm @@ -55,6 +55,10 @@ sub validate_non_context_param { return $v =~ /^\d+|all$/; } + elsif( $k eq 'fields' ) + { + return $v =~ /^value|datestamp|eprintid|set_value$/; + } elsif( $k eq 'date_resolution' ) { return $v =~ /^day|month|year$/; @@ -77,6 +81,10 @@ sub validate_non_context_param # https://perldoc.perl.org/perlrecharclass#Bracketed-Character-Classes return $v =~ /^[[:print:]]+$/; } + elsif( $k =~ /^do_render|human_display|show_count|show_more|show_order$/ ) + { + return $v =~ /^0|1$/; + } elsif( $k =~ /^export|top|view|container_id$/ ) { return $v =~ /^[\w\.\-\:]+$/; #NB \w includes underscore, digit