Skip to content

Commit

Permalink
Add aggregations and collections to the BB
Browse files Browse the repository at this point in the history
  • Loading branch information
melmothx committed Jan 22, 2024
1 parent 9b50a51 commit f50416b
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 1 deletion.
41 changes: 41 additions & 0 deletions lib/AmuseWikiFarm/Controller/BookBuilder.pm
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,47 @@ sub clear :Chained('root') :PathPart('clear') :Args(0) {
$c->response->redirect($c->uri_for_action('/bookbuilder/index'));
}

sub bulk :Chained('root') :PathPart('bulk') :Args(2) {
my ($self, $c, $type, $id) = @_;
my $bb = $c->stash->{bb};
my $site = $c->stash->{site};
if ($id =~ m/\A[0-9]+\z/) {
my @list;
my ($found, $bulk_name);
if ($type eq 'aggregation') {
if (my $agg = $site->aggregations->find($id)) {
$found = $c->uri_for_action('/aggregation/aggregation', $agg->uri);
$bulk_name = $agg->final_name;
foreach my $title ($agg->titles({ public_only => 1 })) {
push @list, $title->uri;
}
}
}
elsif ($type eq 'node') {
if (my $node = $site->nodes->find($id)) {
$found = $c->uri_for_action('/nodes/display', $node->uri);
$bulk_name = $node->muse_name($c->stash->{current_locale_code});
foreach my $title ($node->titles->sorted->published_all) {
push @list, $title->uri;
}
}
}
if ($found) {
if (@list) {
$bb->add_text($_) for @list;
if ($bulk_name and !$bb->title) {
$bb->title($bulk_name);
}
$self->save_session($c);
log_debug { "All ok" };
$c->flash(status_msg => 'BOOKBUILDER_ADDED_BULK');
}
return $c->response->redirect($found);
}
}
$c->detach('/not_found');
}

sub add :Chained('root') :PathPart('add') :Args(1) {
my ( $self, $c, $text ) = @_;
my $bb = $c->stash->{bb};
Expand Down
2 changes: 1 addition & 1 deletion lib/AmuseWikiFarm/Schema/Result/Aggregation.pm
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ sub titles {
my ($self, $opts) = @_;
my $rsd = $self->_rs_titles;
my $rs = $rsd->{rs};
if ($opts->{view}) {
if ($opts->{view} or $opts->{public_only}) {
if ($opts->{public_only}) {
$rs = $rs->status_is_published;
}
Expand Down
7 changes: 7 additions & 0 deletions lib/AmuseWikiFarm/Schema/Result/Node.pm
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,13 @@ sub as_html {
return $html;
}

sub muse_name {
my ($self, $lang) = @_;
my $desc = $self->description($lang);
my $name = $desc ? $desc->title_muse : $self->canonical_title || $self->uri;
return $name;
}

sub name {
my ($self, $lang) = @_;
if (my $desc = $self->description($lang)) {
Expand Down
6 changes: 6 additions & 0 deletions root/src/aggregation/aggregation.tt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
<span class="sr-only">[% loc('Create a new text for this aggregation') %]</span>
</a>
[% END %]
<a href="[% c.uri_for_action('/bookbuilder/bulk', 'aggregation', aggregation.aggregation_id) | html %]"
title="[% loc('Add to the Bookbuilder') %]"
class="btn btn-default pull-right" role="button">
<span class="fa fa-book"></span>
<span class="sr-only">[% loc('Add to the Bookbuilder') %]</span>
</a>
</h1>
</div>
<div class="well">
Expand Down
4 changes: 4 additions & 0 deletions root/src/layout.tt
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,10 @@
<a href="[% c.uri_for_action('/bookbuilder/index') %]" class="text-success">
<strong>[% loc('The text was added to the bookbuilder') %]</strong>
</a>
[% ELSIF c.flash.status_msg == 'BOOKBUILDER_ADDED_BULK' %]
<a href="[% c.uri_for_action('/bookbuilder/index') %]" class="text-success">
<strong>[% loc('The texts were added to the bookbuilder') %]</strong>
</a>
[% ELSE %]
[% c.flash.status_msg | html %]
[% END %]
Expand Down
8 changes: 8 additions & 0 deletions root/src/nodes/display.tt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@
<span class="sr-only">[% loc('Create a new child collection') %]</span>
</a>
[% END %]
[% IF node_linked_pages %]
<a href="[% c.uri_for_action('/bookbuilder/bulk', 'node', node.node_id) | html %]"
title="[% loc('Add to the Bookbuilder') %]"
class="btn btn-default pull-right" role="button" style="margin: 0 10px">
<span class="fa fa-book"></span>
<span class="sr-only">[% loc('Add to the Bookbuilder') %]</span>
</a>
[% END %]
</h1>
</div>
</div>
Expand Down

0 comments on commit f50416b

Please sign in to comment.