diff options
-rw-r--r-- | Build.PL | 7 | ||||
-rw-r--r-- | lib/Bookmarks.pm | 2 | ||||
-rw-r--r-- | lib/Bookmarks/C/Main.pm | 26 | ||||
-rw-r--r-- | lib/Bookmarks/M/DB/Links.pm | 24 | ||||
-rw-r--r-- | root/links | 24 | ||||
-rw-r--r-- | root/results | 54 | ||||
-rw-r--r-- | root/search | 10 | ||||
-rw-r--r-- | root/style.css | 52 | ||||
-rw-r--r-- | root/tags | 1 | ||||
-rw-r--r-- | root/toggle_details | 17 |
10 files changed, 187 insertions, 30 deletions
@@ -8,13 +8,8 @@ my $build = Catalyst::Build->new( requires => { Catalyst => '5.10', YAML => 0, - Catalyst::Plugin::DefaultEnd => 0, - Class::DBI::AbstractSearch => 0, - Class::DBI::Plugin::DeepAbstractSearch => 0, - Class::DBI::Plugin::AbstractCount => 0, - Class::DBI::Plugin::Pager => 0, + 'Catalyst::Plugin::DefaultEnd' => 0, DateTime => '0.2901', - # altra roba }, create_makefile_pl => 'passthrough', script_files => [ glob('script/*') ], diff --git a/lib/Bookmarks.pm b/lib/Bookmarks.pm index 63d6578..89aa0c9 100644 --- a/lib/Bookmarks.pm +++ b/lib/Bookmarks.pm @@ -1,7 +1,7 @@ package Bookmarks; use strict; -use Catalyst qw/-Debug Prototype DefaultEnd Static::Simple/; +use Catalyst qw/Prototype DefaultEnd Static::Simple/; use HTML::Element; our $VERSION = '0.01'; diff --git a/lib/Bookmarks/C/Main.pm b/lib/Bookmarks/C/Main.pm index d957c5d..83edfa9 100644 --- a/lib/Bookmarks/C/Main.pm +++ b/lib/Bookmarks/C/Main.pm @@ -76,7 +76,7 @@ sub jump : Global { my ( $self, $c ) = @_; my $link=Bookmarks::M::DB::Links->retrieve($c->req->param('link')); - $link->access_count($link->access_count()+1); + $link->access_count(($link->access_count()||0)+1); $link->last_access_date(time()); $link->update(); @@ -177,8 +177,17 @@ sub complete_tag : Global { $c->res->body($c->prototype->auto_complete_result(\@tags)); } -=back +sub search : Global { + my ( $self, $c ) = @_; + + my $query=$c->req->param('q'); + my @tags=split /\s+/,$c->req->param('tags'); + + my @links=Bookmarks::M::DB::Links->search_complex($query,@tags); + $c->stash->{links}=[ @links ]; + $c->stash->{template}='results'; +} =head1 AUTHOR @@ -207,10 +216,17 @@ sub stylesheet { )->as_string(); } -sub tag_info { - my ($self, $tag)=@_; +sub tags { + my ($self)=@_; + return URI->new( + $self->{base} . 'tags' + )->as_string(); +} + +sub search { + my ($self)=@_; return URI->new( - $self->{base} . 'tag-info/' . $tag->name() + $self->{base} . 'search' )->as_string(); } diff --git a/lib/Bookmarks/M/DB/Links.pm b/lib/Bookmarks/M/DB/Links.pm index 5c0d37f..5103522 100644 --- a/lib/Bookmarks/M/DB/Links.pm +++ b/lib/Bookmarks/M/DB/Links.pm @@ -2,6 +2,7 @@ package Bookmarks::M::DB::Links; use strict; use MIME::Base64; use Bookmarks::M::DB::LinksTags; +use List::MoreUtils qw(uniq); for my $col_name (qw(add_date last_access_date)) { __PACKAGE__->has_a( $col_name => 'DateTime', @@ -19,6 +20,29 @@ sub get_icon { return decode_base64($self->icon()||''); } +sub search_complex { + my ($class, $query, @tags)=@_; + + $query =~ s{^ +| +$}{}g; + $query =~ s{ +}{%}g; + + my $iterator = $class->search_like(title => "%$query%", {order_by => 'access_count'}); + + my @result=(); + + while (my $link=$iterator->next()) { + my @link_tags = map {$_->pk} $link->tags(); + + # se @tags contiene roba non in @link_tags, i risultati sono diversi + # notare che @tags=() significa 'tutti' + if (scalar uniq(@link_tags,@tags) == scalar @link_tags) { + push @result,$link; + } + } + + return @result; +} + __PACKAGE__->has_many( tags => ['Bookmarks::M::DB::LinksTags' => 'tag'] ); =head1 NAME @@ -9,23 +9,7 @@ </title> <link rel="stylesheet" href="[% href.stylesheet() %]" type="text/css" /> [% href.js_library() %] - <script type="text/javascript"> - // <!-- - function toggle_details(linkid) { - var theDiv=$('link_details_' + linkid); - var theButton=$('link_toggle_' + linkid); - if (theDiv.style.display == 'none') { - Effect.SlideDown(theDiv); - theButton.textContent='^'; - } - else { - Effect.SlideUp(theDiv); - theButton.textContent='V'; - } - return false; - } - // --> - </script> + [% INCLUDE toggle_details %] </head> <body> <div id="tagset"> @@ -64,6 +48,7 @@ </ul> </div> </div> + [% INCLUDE search local=1 %] <div id="links"> <h2>Links:</h2> <div> @@ -93,6 +78,11 @@ </li> [% END %] </ul> + [%- IF link.descr %] + <div class="link descr"> + [%- link.descr -%] + </div> + [% END -%] </div> </div> </li> diff --git a/root/results b/root/results new file mode 100644 index 0000000..e3cc6d2 --- /dev/null +++ b/root/results @@ -0,0 +1,54 @@ +<html> + <head> + <title> + Search results + </title> + <link rel="stylesheet" href="[% href.stylesheet() %]" type="text/css" /> + [% href.js_library() %] + [% INCLUDE toggle_details %] + </head> + <body> + [% INCLUDE search %] + <div id="links" class="results"> + <h2>Links:</h2> + <div> + <ol> + [% FOR link IN links %] + <li> + <div class="link head"> + <span class="link icon"> + <img src="[% href.link_icon(link) %]" width="18" height="18" /> + </span> + <span class="link title"> + <a href="[% href.link(link) %]" title="[% link.url %]">[% link.title %]</a> + </span> + <span class="link appear" id="link_toggle_[% link.pk %]" onclick="toggle_details('[% link.pk %]')">V</span> + </div> + <div class="link details" style="display: none;" id="link_details_[% link.pk %]"> + <div> + <span class="link edit"> + <a href="[% href.edit_link(link) %]" target="_self">edit</a> + </span> + <ul> + [% FOR rtag IN link.tags %] + <li> + <span class="tag name"> + <a href="[% href.to_tag(rtag) %]" target="_self">[% rtag.name %]</a> + </span> + </li> + [% END %] + </ul> + [%- IF link.descr %] + <div class="link descr"> + [%- link.descr -%] + </div> + [% END -%] + </div> + </div> + </li> + [% END %] + </ol> + </div> + </div> + </body> +</html> diff --git a/root/search b/root/search new file mode 100644 index 0000000..198bc35 --- /dev/null +++ b/root/search @@ -0,0 +1,10 @@ +<div id="search[% IF local; '-local'; END %]"> + <form action="[% href.search() %]" method="get"> + <p> + <label for="term">Search:</label> + <input type="text" id="term" name="q" size="30" /> + <input type="hidden" name="tags" value="[% IF local; FOR tag IN tagset.tags; tag.pk _ ' '; END; END %]" /> + <input type="submit" name="go" value=">" /> + </p> + </form> +</div>
\ No newline at end of file diff --git a/root/style.css b/root/style.css index ff8aa36..6fbb706 100644 --- a/root/style.css +++ b/root/style.css @@ -20,6 +20,7 @@ div#all-tags ol { list-style: none; margin:0;padding:0;border:0; + margin-top: 30px; } div#all-tags li { @@ -112,7 +113,7 @@ div#related ul li span.tag.add a div#links { padding:0;border:0;margin:0; - margin-top: 85px; + margin-top: 115px; } div#links h2 { @@ -160,6 +161,11 @@ div#links ol > li div.link.details ul li padding:0;margin:0;border:0; padding-left: 5px; margin-left: 5px; border-left: solid thin black; } +div#links ol > li div.link.descr +{ + background-color: rgb(180,180,180); + border: solid thin black; +} /* add form */ label { @@ -176,4 +182,48 @@ input[type=submit] { border: none; background-color: red; +} + +/* search form */ +div#search, +div#search-local +{ + position: fixed; left:0; + width:100%;height:30px; + background-color: white; + z-index: 2; + margin:0;padding:0;border:0; + border: solid thin black; +} +div#search /* in tags list */ +{ + top:0; +} +div#search-local /* in links list */ +{ + top:80px; +} +div#search p, +div#search-local p +{ + margin:0;padding:0;border:0; +} +div#search input[type=text], +div#search-local input[type=text] +{ + border:none; + border-top: solid thin black; +} + +div#search input[type=submit], +div#search-local input[type=submit] +{ + position: absolute; + top:0;right:0; +} + +/* search results */ +div#links.results +{ + margin-top: 40px; }
\ No newline at end of file @@ -4,6 +4,7 @@ <link rel="stylesheet" href="[% href.stylesheet() %]" type="text/css" /> </head> <body> + [% INCLUDE search %] <div id="all-tags"> <ol> [% FOR tag IN tags %] diff --git a/root/toggle_details b/root/toggle_details new file mode 100644 index 0000000..f2095d2 --- /dev/null +++ b/root/toggle_details @@ -0,0 +1,17 @@ + <script type="text/javascript"> + // <!-- + function toggle_details(linkid) { + var theDiv=$('link_details_' + linkid); + var theButton=$('link_toggle_' + linkid); + if (theDiv.style.display == 'none') { + Effect.SlideDown(theDiv); + theButton.textContent='^'; + } + else { + Effect.SlideUp(theDiv); + theButton.textContent='V'; + } + return false; + } + // --> + </script> |