diff --git a/lib/AmuseWikiFarm/Controller/BookBuilder.pm b/lib/AmuseWikiFarm/Controller/BookBuilder.pm index 3a8c693a..07c44c2a 100644 --- a/lib/AmuseWikiFarm/Controller/BookBuilder.pm +++ b/lib/AmuseWikiFarm/Controller/BookBuilder.pm @@ -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}; diff --git a/lib/AmuseWikiFarm/Schema/Result/Aggregation.pm b/lib/AmuseWikiFarm/Schema/Result/Aggregation.pm index 8bd8e0eb..37dcd084 100644 --- a/lib/AmuseWikiFarm/Schema/Result/Aggregation.pm +++ b/lib/AmuseWikiFarm/Schema/Result/Aggregation.pm @@ -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; } diff --git a/lib/AmuseWikiFarm/Schema/Result/Node.pm b/lib/AmuseWikiFarm/Schema/Result/Node.pm index 3df2330e..09d24fda 100644 --- a/lib/AmuseWikiFarm/Schema/Result/Node.pm +++ b/lib/AmuseWikiFarm/Schema/Result/Node.pm @@ -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)) { diff --git a/root/src/aggregation/aggregation.tt b/root/src/aggregation/aggregation.tt index 1d1371bd..f03b69a0 100644 --- a/root/src/aggregation/aggregation.tt +++ b/root/src/aggregation/aggregation.tt @@ -17,6 +17,12 @@ [% loc('Create a new text for this aggregation') %] [% END %] + + + [% loc('Add to the Bookbuilder') %] +