Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add StaticContent view #25

Open
wants to merge 4 commits into
base: 3_4
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cfg.d/z_irstats2.pl
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions plugins/EPrints/Plugin/Stats/Utils.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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$/;
Expand All @@ -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
Expand Down
97 changes: 97 additions & 0 deletions plugins/EPrints/Plugin/Stats/View/StaticContent.pm
Original file line number Diff line number Diff line change
@@ -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;