-
Notifications
You must be signed in to change notification settings - Fork 9
Complete default report setup (D 800) #580
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
Open
droberts-ctrlo
wants to merge
1
commit into
ctrlo:dev
Choose a base branch
from
droberts-ctrlo:default-reports
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,178 @@ | ||
| package GADS::PDFGenerator; | ||
|
|
||
| use strict; | ||
| use warnings; | ||
|
|
||
| use Moo; | ||
|
|
||
| use GADS::Config; | ||
|
|
||
| use CtrlO::PDF; | ||
|
|
||
| has site => ( | ||
| is => 'ro', | ||
| required => 1, | ||
| ); | ||
|
|
||
| has layouts => ( | ||
| is => 'ro', | ||
| required => 1, | ||
| ); | ||
|
|
||
| has record => ( | ||
| is => 'ro', | ||
| required => 1 | ||
| ); | ||
|
|
||
| has user => ( | ||
| is => 'ro', | ||
| required => 1, | ||
| ); | ||
|
|
||
| has security_marking => ( | ||
| is => 'ro', | ||
| ); | ||
|
|
||
| has _default_marking => ( | ||
| is => 'lazy', | ||
| ); | ||
|
|
||
| sub _build__default_marking { | ||
| return shift->site->read_security_marking; | ||
| } | ||
|
|
||
| has _logo => ( | ||
| is => 'lazy', | ||
| ); | ||
|
|
||
| sub _build__logo { | ||
| return shift->site->create_temp_logo; | ||
| } | ||
|
|
||
| sub build { | ||
| my ($self, %options) = @_; | ||
|
|
||
| my $marking = $self->security_marking || $self->_default_marking; | ||
| my $logo = $self->_logo; | ||
|
|
||
| my $pdf; | ||
| my $topmargin = 0; | ||
|
|
||
| if ($logo) | ||
| { | ||
| $pdf = CtrlO::PDF->new( | ||
| header => $marking, | ||
| footer => $marking, | ||
| logo => $logo, | ||
| ); | ||
|
|
||
| # Adjust the top margin to allow for the logo - 30px allows the table (below the logo) to not encroach on the logo when rendered | ||
| # This is used rather than overcomplicating and using image size to centre the header, and then having to "drop" the table down to avoid the logo | ||
| $topmargin = -30; | ||
| } | ||
| else | ||
| { | ||
| $pdf = CtrlO::PDF->new( | ||
| header => $marking, | ||
| footer => $marking, | ||
| ); | ||
| } | ||
|
|
||
| $pdf->add_page; | ||
|
|
||
| $pdf->heading($options{title}, topmargin => $topmargin); | ||
| $pdf->text($options{subtitle}, size => 14) if $options{subtitle}; | ||
|
|
||
| my $hdr_props = { | ||
| repeat => 0, | ||
| justify => 'center', | ||
| font_size => 12, | ||
| bg_color => '#007c88', | ||
| fg_color => '#ffffff', | ||
| }; | ||
|
|
||
| my $result = $self->layouts; | ||
|
|
||
| my @cols = $self->record->presentation_map_columns(columns => $result); | ||
| my @topics = $self->record->get_topics(\@cols); | ||
|
|
||
| my $i = 0; | ||
| foreach my $topic (@topics) | ||
| { | ||
| my $topic_name = $topic->{topic} ? $topic->{topic}->name : 'Other'; | ||
| my $fields = [ [$topic_name] ]; | ||
|
|
||
| my $width = 0; | ||
| foreach my $col (@{ $topic->{columns} }) | ||
| { | ||
| if ($col->{data}->{selected_values}) | ||
| { | ||
| my $first = 1; | ||
| foreach my $c (@{ $col->{data}->{selected_values} }) | ||
| { | ||
| my $values = $c->{values}; | ||
| $width = | ||
| $width < (scalar(@$values) + 1) | ||
| ? scalar(@$values) + 1 | ||
| : $width; | ||
| push @$fields, [ $first ? $col->{name} : '', @$values ]; | ||
| $first = 0; | ||
| } | ||
| } | ||
| else | ||
| { | ||
| if ($col->{data}->{value}) | ||
| { | ||
| push @$fields, | ||
| [ $col->{name}, $col->{data}->{value} || "" ]; | ||
| } | ||
| else | ||
| { | ||
| push @$fields, [ $col->{name}, $col->{data}->{grade} ]; | ||
| } | ||
| $width = 2 if $width < 2; | ||
| } | ||
| } | ||
|
|
||
| my $cell_props = []; | ||
| foreach my $d (@$fields) | ||
| { | ||
| my $has = @$d; | ||
|
|
||
| # $max_fields does not include field name | ||
| my $gap = $width - $has + 1; | ||
| push @$d, undef for (1 .. $gap); | ||
| push @$cell_props, | ||
| [ (undef) x ($has - 1), { colspan => $gap + 1 }, ]; | ||
| } | ||
|
|
||
| $pdf->table( | ||
| data => $fields, | ||
| header_props => $hdr_props, | ||
| border_c => '#007C88', | ||
| h_border_w => 1, | ||
| cell_props => $cell_props, | ||
| size => '4cm *', | ||
| ); | ||
| } | ||
|
|
||
| my $now = DateTime->now; | ||
| my $format = GADS::Config->instance->dateformat; | ||
| $pdf->text( | ||
| 'Last edited by ' | ||
| . $self->record->edited_user->as_string . ' on ' | ||
| . $self->record->edited_time->as_string, | ||
| size => 10 | ||
| ); | ||
| $pdf->text( | ||
| 'Report generated by ' | ||
| . $self->user->value . ' on ' | ||
| . $now->format_cldr($format) . ' at ' | ||
| . $now->hms, | ||
| size => 10 | ||
| ); | ||
|
|
||
| return $pdf; | ||
| } | ||
|
|
||
| 1; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.