Mojito/Model/Link.pm

filter: Statementstmt 17.6% 32 / 181 Branchbran 3.3% 1 / 30 Conditioncond 0.0% 0 / 39 MC/DCmcdc 0.0% 0 / 20 Subroutinesub 33.3% 9 / 27 Podpod 89.4% 17 / 19 totaltotal 18.6% 59 / 316 CC 37 SCAR 35.5
CC
37
Cov
13%
get_link_data
110.0
create_list_of_links
72.0
create_generic_list_of_links
42.0
CRAP 34.7
« Mojito/Collection/CRUD/Mongo.pm ↑ Summary Mojito/Collection/CRUD/Elasticsearch.pm »
1 4 ▶use strictures 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 package Mojito::Model::Link;
3 4 $Mojito::Model::Link::VERSION = '0.25';
4 4 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use Mojito::Model::Doc;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use Mojito::Collection::Present;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use DateTime;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use XML::Atom::SimpleFeed;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use Data::Dumper::Concise;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 4 with('Mojito::Role::Config');
12  
13 4 has base_url => ( is => 'rw', );
14  
15 4 has name_of_page_collection => (
16 is => 'rw',
17 );
18  
19 4 has db => (is => 'ro', lazy => 1);
20  
21 has doc => (
22 is => 'ro',
23 3 ▶ isa => sub { die "Need a Doc Model object. Have ref($_[0]) instead." unless $_[0]->isa('Mojito::Model::Doc') },
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0]->isa("Mojito::Model::Doc") 0 3 3
24 4 lazy => 1,
25 handles => [
26 qw(
27 get_most_recent_docs
28 get_feed_docs
29 get_collections
30 get_collection_pages
31 get_docs_for_month
32 )
33 ],
34 writer => '_build_doc',
35 );
36  
37 =head1 Methods
38  
39 =head2 get_most_recent_link_data
40  
41 Get the recent links data structure - ArrayRef[HashRef]
42  
43 TODO: There's HTML in here, omg.
44  
45 =cut
46  
47 0 ▶sub get_most_recent_link_data {
Subroutine get_most_recent_link_data: not called CC=1 SCAR=6.9
Pod documented
48 0 my ($self) = @_;
49 0 my $cursor = $self->get_most_recent_docs;
50 0 return $self->get_link_data($cursor);
51 }
52  
53 =head2 get_feed_link_data
54  
55 Get the data to create links for a particular feed.
56  
57 =cut
58  
59 0 ▶sub get_feed_link_data {
Subroutine get_feed_link_data: not called CC=1 SCAR=6.9
Pod documented
60 0 my ($self, $feed) = @_;
61 0 my $cursor = $self->get_feed_docs($feed);
62 0 return $self->get_link_data($cursor);
63 }
64  
65 =head2 get_atom_feed
66  
67 Get the data to create links for a particular feed.
68  
69 =cut
70  
71 0 ▶sub get_atom_feed {
Subroutine get_atom_feed: not called CC=4 SCAR=30.0
Pod documented
72 0 my ($self, $feed) = @_;
73 0 my $cursor = $self->get_feed_docs($feed);
74 0 my @feed_title = split /_/, $feed;
75 0 my $feed_title = join ' ', map { ucfirst($_) } @feed_title;
76 0 my $atom = XML::Atom::SimpleFeed->new(title => $feed_title, id => $feed);
77 0 ▶ while (my $doc = $cursor->next) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $doc = $cursor->next) 0 0 0
78 0 my $link = $self->base_url . 'public/page/' . $doc->{'_id'}->value;
79 0 ▶ my $author = $doc->{author} || $self->config->{default_author} || 'Anonymous';
Condition0%0/5
$doc->{'author'} || $self->config->{'default_author'} || 'Anonymous'
l!l
00
$doc->{"author"} or $self->config->{"default_author"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$doc->{'author'} || $self->config->{'default_author'} || 'Anonymous'
$doc->{"author"} $self->config->{"default_author"}
Truth table0%0/3
A or B
A= $doc->{"author"}B= $self->config->{"default_author"}
ABresult
1X1
011
000
80 0 my $dt = DateTime->from_epoch( epoch => $doc->{last_modified} );
81 0 $dt->set_time_zone($self->config->{local_timezone});
82 0 my $updated = $dt->mdy('/') . ' ' . $dt->hms;
83 $atom->add_entry(
84 title => $doc->{title},
85 'link', => $link,
86 author => $author,
87 0 id => $doc->{'_id'}->value,
88 updated => $updated,
89 );
90 }
91 0 return $atom->as_string;
92 }
93  
94 =head2 get_collections_index_link_data
95  
96 Get the data to create links to all the available collections.
97  
98 =cut
99  
100 0 ▶sub get_collections_index_link_data {
Subroutine get_collections_index_link_data: not called CC=1 SCAR=6.9
Pod documented
101 0 my ($self) = @_;
102 0 my $cursor = $self->get_collections;
103 0 return $self->get_link_data($cursor);
104 }
105  
106 =head2 get_collection_link_data
107  
108 Get the data to create links to all the documents in a collection.
109  
110 =cut
111  
112 0 ▶sub get_collection_link_data {
Subroutine get_collection_link_data: not called CC=1 SCAR=6.9
Pod documented
113 0 my ($self, $collection_id) = @_;
114 0 my ($name_of_page_collection, $pages) = $self->get_collection_pages($collection_id);
115 # Store this for use later
116 0 $self->name_of_page_collection($name_of_page_collection);
117 0 return $self->get_link_data($pages);
118 }
119  
120 =head2 get_link_data
121  
122 Given a MongoDB cursor OR ArrayRef of documents then create the link data.
123  
124 =cut
125  
126 0 ▶sub get_link_data {
Subroutine get_link_data: not called CC=10 SCAR=47.0
Pod documented
127 0 my ($self, $cursor) = @_;
128 0 my $link_data;
129 0 ▶ if ( ref($cursor) eq 'MongoDB::Cursor' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $cursor eq 'MongoDB::Cursor') { } 0 0 0
elsif (ref $cursor eq 'ARRAY') { } 0 0 0
130 0 ▶ while ( my $doc = $cursor->next ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $doc = $cursor->next) 0 0 0
131 0 ▶ my $title = $doc->{title}||$doc->{collection_name}||'no title';
Condition0%0/5
$doc->{'title'} || $doc->{'collection_name'} || 'no title'
l!l
00
$doc->{"title"} or $doc->{"collection_name"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$doc->{'title'} || $doc->{'collection_name'} || 'no title'
$doc->{"title"} $doc->{"collection_name"}
Truth table0%0/3
A or B
A= $doc->{"title"}B= $doc->{"collection_name"}
ABresult
1X1
011
000
132 0 push @{$link_data}, { id => $doc->{'_id'}->value, title => $title };
133 }
134 }
135 elsif ( ref($cursor) eq 'ARRAY' ) {
136 0 foreach my $doc (@{$cursor}) {
137 0 ▶ my $title = $doc->{title}||$doc->{collection_name}||'no title';
Condition0%0/5
$doc->{'title'} || $doc->{'collection_name'} || 'no title'
l!l
00
$doc->{"title"} or $doc->{"collection_name"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$doc->{'title'} || $doc->{'collection_name'} || 'no title'
$doc->{"title"} $doc->{"collection_name"}
Truth table0%0/3
A or B
A= $doc->{"title"}B= $doc->{"collection_name"}
ABresult
1X1
011
000
138 0 ▶ push @{$link_data}, { id => $doc->{'_id'}||$doc->{id}, title => $title };
Condition0%0/3
$doc->{'_id'} || $doc->{'id'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$doc->{'_id'} || $doc->{'id'}
$doc->{'_id'} $doc->{'id'}
Truth table0%0/3
A || B
A= $doc->{'_id'}B= $doc->{'id'}
ABresult
1X1
011
000
139 }
140 }
141 else {
142 0 die "I don't know how to get link data for ", Dumper $cursor;
143 }
144  
145 0 return $link_data;
146 }
147  
148 =head2 get_recent_links
149  
150 Turn the data into HTML
151 $args should be a HashRef of options
152  
153 =cut
154  
155 0 ▶sub get_recent_links {
Subroutine get_recent_links: not called CC=2 SCAR=17.9
Pod documented
156 0 my ($self, $args) = @_;
157  
158 # Let's limit the amount of recent links we show
159 # if we've set a limit in our config.
160 0 $args->{last_link_number} = $self->config->{last_link_number};
161 0 my $base_url = $self->base_url;
162 0 my $link_data = $self->get_most_recent_link_data;
163 0 my $link_title = '<span id="recent_articles_label" style="font-weight: bold;">Recent Articles</span><br />' . "\n";
164 0 ▶ my $links = $self->create_list_of_links($link_data, $args) || "No Documents yet. Get to <a href='${base_url}page'>writing!</a>";
Condition0%0/2
$self->create_list_of_links($link_data, $args) || "No Documents yet. Get to <a href='${base_url}page'>writing!</a>"
l!l
00
MC/DC0%0/1
$self->create_list_of_links($link_data, $args) || "No Documents yet. Get to <a href='${base_url}page'>writing!</a>"
$self->create_list_of_links($link_data, $args)
Truth table0%0/2
A
A= $self->create_list_of_links($link_data, $args)
Aresult
11
00
165  
166 0 return $link_title . $links;
167 }
168  
169 =head2 get_feed_links
170  
171 Get the links for the documents belonging to a particular feed.
172  
173 =cut
174  
175 0 ▶sub get_feed_links {
Subroutine get_feed_links: not called CC=2 SCAR=17.9
Pod documented
176 0 my ($self, $feed) = @_;
177  
178 0 my $link_data = $self->get_feed_link_data($feed);
179 0 my @feed_title = split /_/, $feed;
180 0 my $feed_title = join ' ', map { ucfirst($_) } @feed_title;
181 0 my $title = $feed_title . ' Feed';
182 0 my $link_title = "<span class='feeds' style='font-weight: bold;'>$title</span><br />";
183 0 my $links = $self->create_list_of_links($link_data, {want_public_link => 1});
184 0 ▶ if ($links) {
Branch: 1 branch
BranchTrueFalseTotal
if ($links) { } 0 0 0
185 0 return $link_title . $links;
186 }
187 else {
188 0 "The <em>$feed</em> feed is <b>empty</b>";
189 }
190 }
191  
192 =head2 view_selectable_page_list
193  
194 Get the links for the documents belonging to a particular feed.
195  
196 =cut
197  
198 0 ▶sub view_selectable_page_list {
Subroutine view_selectable_page_list: not called CC=2 SCAR=17.9
Pod documented
199 0 my ($self, $args) = @_;
200  
201 0 my $base_url = $self->base_url;
202 0 my $link_data = $self->get_most_recent_link_data;
203 0 my $list_title = '<span id="selectable_page_list_label" style="font-weight: bold;">Select articles to be part of a collection</span><br />' . "\n";
204 0 ▶ my $list = $self->create_selectable_page_list($link_data, $args) || "No Documents yet. Get to <a href='${base_url}page'>writing!</a>";
Condition0%0/2
$self->create_selectable_page_list($link_data, $args) || "No Documents yet. Get to <a href='${base_url}page'>writing!</a>"
l!l
00
MC/DC0%0/1
$self->create_selectable_page_list($link_data, $args) || "No Documents yet. Get to <a href='${base_url}page'>writing!</a>"
$self->create_selectable_page_list($link_data, $args)
Truth table0%0/2
A
A= $self->create_selectable_page_list($link_data, $args)
Aresult
11
00
205  
206 0 return $list_title . $list;
207 }
208  
209 =head2 view_sortable_page_list
210  
211 View the pages in a collection, ready to be sorted.
212  
213 =cut
214  
215 0 ▶sub view_sortable_page_list {
Subroutine view_sortable_page_list: not called CC=2 SCAR=17.9
Pod documented
216 0 my ($self, $args) = (shift, shift);
217  
218 0 my $base_url = $self->base_url;
219 0 my $link_data = $self->get_collection_link_data($args->{collection_id});
220 0 my $name_of_page_collection = $self->name_of_page_collection;
221 0 my $list_title =<<"EOH";
222 <header id='collections_index' style='font-weight: bold;'>
223 ORDER (drag-n-drop) pages in the collection:
224 <span style='color: darkblue; font-size: 1.33em;'>$name_of_page_collection</i></span>
225 </header>
226 EOH
227 0 ▶ my $list = $self->create_sortable_page_list($link_data, $name_of_page_collection) || "No Documents yet. Get to <a href='${base_url}page'>writing!</a>";
Condition0%0/2
$self->create_sortable_page_list($link_data, $name_of_page_collection) || "No Documents yet. Get to <a href='${base_url}page'>writing!</a>"
l!l
00
MC/DC0%0/1
$self->create_sortable_page_list($link_data, $name_of_page_collection) || "No Documents yet. Get to <a href='${base_url}page'>writing!</a>"
$self->create_sortable_page_list($link_data, $name_of_page_collection)
Truth table0%0/2
A
A= $self->create_sortable_page_list($link_data, $name_of_page_collection)
Aresult
11
00
228  
229 0 return $list_title . $list;
230 }
231  
232 =head2 create_selectable_page_list
233  
234 Given link data (doc id and title) and possibly some $args then create hyperlinks
235  
236 =cut
237  
238 0 ▶sub create_selectable_page_list {
Subroutine create_selectable_page_list: not called CC=3 SCAR=24.8
Pod documented
239 0 my ($self, $link_data) = (shift, shift);
240  
241 0 ▶ return if !$link_data;
Branch: 1 branch
BranchTrueFalseTotal
unless $link_data 0 0 0
242 0 my $base_url = $self->base_url;
243 0 my $list;
244 0 foreach my $datum (@{$link_data}) {
245 0 $list .= "<li id='$datum->{id}'>$datum->{title}</li>\n";
246 }
247 0 $list =<<"EOH";
248 <section id='selectable_page_list'>
249 <form action=${base_url}collect method=POST>
250 <label for="collection_name">Collection name: </label>
251 <input type="text" name="collection_name" id="collection_name" required="required" value="" />
252 <ul>
253 ${list}
254 </ul>
255 <div id="hidden_params"><input type="hidden" name="collected_page_ids" id="collected_page_ids" value="" /></div>
256 <input type=submit name=collect value="Create Collection"/>
257 </form>
258 </section>
259  
260 EOH
261
262 0 return $list;
263 }
264  
265 =head2 create_sortable_page_list
266  
267 Create a sortable list of the pages in a collection.
268 This is how we impose order to collection of pages.
269  
270 =cut
271  
272 0 ▶sub create_sortable_page_list {
Subroutine create_sortable_page_list: not called CC=2 SCAR=17.9
Pod documented
273 0 my ($self, $link_data, $collection_name) = (shift, shift, shift);
274  
275 0 my $list;
276 0 foreach my $datum (@{$link_data}) {
277 0 $list .= "<li id='$datum->{id}'>$datum->{title}</li>\n";
278 }
279 0 $list =<<"EOH";
280 <section id='sortable'>
281 <form action='' method=POST>
282 <input type="hidden" name="collection_name" id="collection_name" value="${collection_name}" />
283 <ol>
284 ${list}
285 </ol>
286 <div id="hidden_params"><input type="hidden" name="collected_page_ids" id="collected_page_ids" value="" /></div>
287 <input type=submit name=collect value="Order Collection"/>
288 </form>
289 </section>
290  
291 EOH
292
293 0 return $list;
294 }
295  
296 =head2 view_collections_index
297  
298 List the existing collections
299  
300 =cut
301  
302 0 ▶sub view_collections_index {
Subroutine view_collections_index: not called CC=2 SCAR=17.9
Pod documented
303 0 my ($self, $args) = @_;
304  
305 0 $args->{route} = '/collection/';
306 0 my $base_url = $self->base_url;
307 0 my $link_data = $self->get_collections_index_link_data;
308 0 my $list_title = "<span id='collections_index' style='font-weight: bold;'>Page Collections:</span> <a href='${base_url}collect'>create one</a><br />\n";
309 0 ▶ my $list = $self->create_generic_list_of_links($link_data, $args) || "No Collections yet. Get to <a href='${base_url}collect'>creating them!</a>";
Condition0%0/2
$self->create_generic_list_of_links($link_data, $args) || "No Collections yet. Get to <a href='${base_url}collect'>creating them!</a>"
l!l
00
MC/DC0%0/1
$self->create_generic_list_of_links($link_data, $args) || "No Collections yet. Get to <a href='${base_url}collect'>creating them!</a>"
$self->create_generic_list_of_links($link_data, $args)
Truth table0%0/2
A
A= $self->create_generic_list_of_links($link_data, $args)
Aresult
11
00
310  
311 0 return $list_title . $list;
312 }
313  
314 =head2 view_collection_page
315  
316 View a list of links to the pages that make up a collection.
317  
318 =cut
319  
320 0 ▶sub view_collection_page {
Subroutine view_collection_page: not called CC=3 SCAR=24.8
Pod documented
321 0 my ($self, $args) = @_;
322  
323 0 my $base_url = $self->base_url;
324 0 my $link_data = $self->get_collection_link_data($args->{collection_id});
325 0 my $name_of_page_collection = $self->name_of_page_collection;
326 0 my $list_title =<<"EOH";
327 <header id='collections_index' style='font-weight: bold;'>
328 <span style='color: darkblue; font-size: 1.33em;'>$name_of_page_collection</i></span>
329 </header>
330 EOH
331  
332 0 $args->{route} = '/collection/' . $args->{collection_id} . '/page/';
333 0 ▶ $args->{route} = '/public' . $args->{route} if $args->{is_public};
Branch: 1 branch
BranchTrueFalseTotal
if $args->{"is_public"} 0 0 0
334 0 $args->{list_style} = 'ordered';
335 0 ▶ my $list = $self->create_generic_list_of_links($link_data, $args) || "No Collections yet. Get to <a href='${base_url}/collect'>creating them!</a>";
Condition0%0/2
$self->create_generic_list_of_links($link_data, $args) || "No Collections yet. Get to <a href='$base_url/collect'>creating them!</a>"
l!l
00
MC/DC0%0/1
$self->create_generic_list_of_links($link_data, $args) || "No Collections yet. Get to <a href='$base_url/collect'>creating them!</a>"
$self->create_generic_list_of_links($link_data, $args)
Truth table0%0/2
A
A= $self->create_generic_list_of_links($link_data, $args)
Aresult
11
00
336  
337 0 return $list_title . $list;
338 }
339  
340 =head2 create_list_of_links
341  
342 Given link data (doc id and title) and possibly some $args then create hyperlinks
343  
344 =cut
345  
346 0 ▶sub create_list_of_links {
Subroutine create_list_of_links: not called CC=8 SCAR=42.8
Pod documented
347 0 my ($self, $link_data, $args) = @_;
348  
349 0 my $base_url = $self->base_url;
350 0 ▶ $base_url .= 'public/' if $args->{want_public_link};
Branch: 1 branch
BranchTrueFalseTotal
if $args->{"want_public_link"} 0 0 0
351 0 my $links;
352 0 my $i = 1; my $limit = $args->{last_link_number};
353 0 foreach my $datum (@{$link_data}) {
354 0 $links .= "<div class='list_of_links'>&middot; <a href=\"${base_url}page/" . $datum->{id} . '">' . $datum->{title} . "</a>";
355 0 ▶ if ($args && $args->{want_delete_link}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args and $args->{"want_delete_link"}) 0 0 0
Condition0%0/3
$args and $args->{"want_delete_link"}
!ll&&!rl&&r
000
MC/DC0%0/2
$args and $args->{"want_delete_link"}
$args $args->{"want_delete_link"}
Truth table0%0/3
A and B
A= $argsB= $args->{"want_delete_link"}
ABresult
0X0
100
111
356 0 $links .= " | <span style='font-size: 0.88em;'><a href=\"${base_url}page/" . $datum->{id} . '/delete"> delete</a></span>';
357 }
358 0 $links .= "</div>\n";
359 0 ▶ last if ($limit && ($i == $limit)); $i++;
Branch: 1 branch
BranchTrueFalseTotal
if $limit and $i == $limit 0 0 0
Condition0%0/3
$limit and $i == $limit
!ll&&!rl&&r
000
MC/DC0%0/2
$limit and $i == $limit
$limit $i == $limit
Truth table0%0/3
A and B
A= $limitB= $i == $limit
ABresult
0X0
100
111
360 }
361 0 ▶ $links = "<section id='list_of_links'>\n${links}\n</section>" if defined $links;
Branch: 1 branch
BranchTrueFalseTotal
if defined $links 0 0 0
362 0 return $links;
363 }
364  
365 =head2 create_generic_list_of_links
366  
367 Given link data (doc id and title) and possibly some $args then create hyperlinks,
368 but in a more general manner than create_list_of_links().
369  
370 Returns array of <a hrefs
371  
372 =cut
373  
374 0 ▶sub create_generic_list_of_links {
Subroutine create_generic_list_of_links: not called CC=6 SCAR=37.4
Pod documented
375 0 my ($self, $link_data, $args) = @_;
376
377 0 my $base_url = $self->base_url;
378 0 ▶ my $route = $args->{route}||die 'Need a route to create a generic list of links';
Condition0%0/2
$args->{'route'} || die('Need a route to create a generic list of links')
l!l
00
MC/DC0%0/1
$args->{'route'} || die('Need a route to create a generic list of links')
$args->{'route'}
Truth table0%0/2
A
A= $args->{'route'}
Aresult
11
00
379 # make sure $route doesn't start with a '/'
380 0 $route =~ s/^\///;
381 # NOTE: We're assuming a route like /page/$id or /collection/$id etc.
382 0 my $base_href = $base_url . $route;
383 0 my @links;
384 0 my $item_number = 1;
385 0 foreach my $datum (@{$link_data}) {
386 0 ▶ next if not $datum->{id};
Branch: 1 branch
BranchTrueFalseTotal
unless $datum->{"id"} 0 0 0
387 0 ▶ my $moniker = ($args->{list_style} && $args->{list_style} eq 'ordered') ? "$item_number. " : '&middot; ';
Branch: 1 branch
BranchTrueFalseTotal
$args->{'list_style'} && $args->{'list_style'} eq 'ordered' ? : 0 0 0
Condition0%0/3
$args->{"list_style"} and $args->{"list_style"} eq "ordered"
!ll&&!rl&&r
000
MC/DC0%0/2
$args->{"list_style"} and $args->{"list_style"} eq "ordered"
$args->{"list_style"} $args->{"list_style"} eq "ordered"
Truth table0%0/3
A and B
A= $args->{"list_style"}B= $args->{"list_style"} eq "ordered"
ABresult
0X0
100
111
388 0 push @links, $moniker . "<a href=\"${base_href}" . $datum->{id} . '">' . $datum->{title} . "</a>";
389 0 $item_number++;
390 }
391 0 my $links = join "<br />\n", @links;
392 0 my $return = '<section id="list_of_links">' . $links . '</section>';
393 }
394  
395 0 ▶sub view_collection_nav {
Subroutine view_collection_nav: not called CC=2 SCAR=17.9
Pod undocumented
396 0 my ($self, $params) = @_;
397
398 # Obtain focus point.
399 my $presenter = Mojito::Collection::Present->new(
400 config => $self->config,
401 db => $self->db,
402 collection_id => $params->{collection_id},
403 focus_page_id => $params->{page_id},
404 0 );
405
406 # Handle public collections
407 0 my $base_url = $self->base_url;
408 0 ▶ $base_url .= 'public/' if $params->{public};
Branch: 1 branch
BranchTrueFalseTotal
if $params->{"public"} 0 0 0
409  
410 0 my $next_page_URL = $base_url . $presenter->next_page_route;
411 0 my $previous_page_URL = $base_url . $presenter->previous_page_route;
412 0 my $index_page_URL = $base_url . $presenter->index_page_route;
413 0 my $js = $self->collection_nav_js( $next_page_URL, $previous_page_URL, $index_page_URL);
414 0 my $nav_fragment =<<"EOH";
415 $js
416 <div style="float:right;">
417 <a accesskey='p' href="${previous_page_URL}" title='[p]'>&lt; &lt; Previous</a> |
418 <a accesskey='i' href="${index_page_URL}" title='[i]'>Index</a> |
419 <a accesskey='n' href="${next_page_URL}" title='[n]'>Next &gt;&gt;</a>
420 </div>
421 EOH
422  
423 0 return $nav_fragment;
424 }
425  
426 0 ▶sub collection_nav_js {
Subroutine collection_nav_js: not called CC=1 SCAR=6.9
Pod undocumented
427 0 my ($self, $next_page, $previous_page, $index_page) = @_;
428  
429 0 my $js =<<"EOJ";
430 <script>
431 function nextSlide() {
432 window.location = '$next_page';
433 }
434
435 function prevSlide() {
436 window.location = '$previous_page';
437 }
438
439 function indexSlide() {
440 window.location = '$index_page';
441 }
442
443 function handleKey(e) {
444 var key;
445 if (e == null) {
446 // IE
447 key = event.keyCode
448 }
449 else {
450 // Mozilla
451 if (e.altKey || e.ctrlKey) {
452 return true
453 }
454 key = e.which
455 }
456 switch(key) {
457 case 8: prevSlide(); break
458 case 13: nextSlide(); break
459 case 32: nextSlide(); break
460 case 105: indexSlide(); break
461 case 110: nextSlide(); break
462 case 112: prevSlide(); break
463 default: //xxx(e.which)
464 }
465 }
466  
467 document.onkeypress = handleKey
468 </script>
469  
470 EOJ
471 0 return $js
472 }
473  
474 =head2 BUILD
475  
476 Create the handler objects
477  
478 =cut
479  
480 3 ▶sub BUILD {
Subroutine BUILD: called CC=1 SCAR=0.0
Pod documented
481 3 my $self = shift;
482 3 my $constructor_args_href = shift;
483  
484 # pass the options into the subclasses
485 3 $self->_build_doc(Mojito::Model::Doc->new($constructor_args_href));
486 }
487  
488 4 1
« Mojito/Collection/CRUD/Mongo.pm ↑ Summary Mojito/Collection/CRUD/Elasticsearch.pm »