From cac81c5c401813e609a9b3345eec91a570071fab Mon Sep 17 00:00:00 2001 From: dakkar Date: Thu, 10 Nov 2005 20:19:29 +0000 Subject: =?UTF-8?q?aggiunta=20la=20funzionalit=C3=A0=20di=20ricerca,=20e?= =?UTF-8?q?=20"finiti"=20gli=20stili?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Build.PL | 7 +----- lib/Bookmarks.pm | 2 +- lib/Bookmarks/C/Main.pm | 26 +++++++++++++++++----- lib/Bookmarks/M/DB/Links.pm | 24 ++++++++++++++++++++ root/links | 24 ++++++-------------- root/results | 54 +++++++++++++++++++++++++++++++++++++++++++++ root/search | 10 +++++++++ root/style.css | 52 ++++++++++++++++++++++++++++++++++++++++++- root/tags | 1 + root/toggle_details | 17 ++++++++++++++ 10 files changed, 187 insertions(+), 30 deletions(-) create mode 100644 root/results create mode 100644 root/search create mode 100644 root/toggle_details diff --git a/Build.PL b/Build.PL index 110246b..c0c6e61 100644 --- a/Build.PL +++ b/Build.PL @@ -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 diff --git a/root/links b/root/links index ee07953..58a5b83 100644 --- a/root/links +++ b/root/links @@ -9,23 +9,7 @@ [% href.js_library() %] - + [% INCLUDE toggle_details %]
@@ -64,6 +48,7 @@
+ [% INCLUDE search local=1 %] diff --git a/root/results b/root/results new file mode 100644 index 0000000..e3cc6d2 --- /dev/null +++ b/root/results @@ -0,0 +1,54 @@ + + + + Search results + + + [% href.js_library() %] + [% INCLUDE toggle_details %] + + + [% INCLUDE search %] + + + diff --git a/root/search b/root/search new file mode 100644 index 0000000..198bc35 --- /dev/null +++ b/root/search @@ -0,0 +1,10 @@ +
+
+

+ + + + +

+
+
\ 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 diff --git a/root/tags b/root/tags index 244ae32..f742ef8 100644 --- a/root/tags +++ b/root/tags @@ -4,6 +4,7 @@ + [% INCLUDE search %]
    [% 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 @@ + -- cgit v1.2.3