Changeset 112 in bookmarks
- Timestamp:
- 02/17/16 22:05:50 (9 years ago)
- Location:
- trunk/lib
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/Bookmarks/Controller.pm
r108 r112 71 71 } 72 72 73 sub _get_search_from_request { 74 my $self = shift; 75 76 my @tags = grep { $_ ne '' } $self->request->param('tag'); 77 my $query = $self->request->param('q'); 78 my $limit = $self->request->param('limit'); 79 my $offset = $self->request->param('offset'); 80 my $page = $self->request->param('page'); 81 82 return $self->bookmarks->search({ 83 query => $query, 84 tags => \@tags, 85 limit => $limit, 86 offset => $offset, 87 page => $page, 88 }); 89 } 90 73 91 sub list { 74 92 my $self = shift; … … 79 97 my $format = $self->request->param('format') || 'html'; 80 98 81 my @tags = grep { $_ ne '' } $self->request->param('tag');82 my $query = $self->request->param('q');83 my $limit = $self->request->param('limit');84 my $offset = $self->request->param('offset');85 my $page = $self->request->param('page');86 87 99 my $list = Bookmarks::List->new({ 88 100 bookmarks => $self->bookmarks, 89 search => $self->bookmarks->search({ 90 query => $query, 91 tags => \@tags, 92 limit => $limit, 93 offset => $offset, 94 page => $page, 95 }), 101 search => $self->_get_search_from_request, 96 102 }); 97 103 … … 101 107 } 102 108 return $list->$as_format; 109 } 110 111 sub sidebar { 112 my $self = shift; 113 114 my $list = Bookmarks::List->new({ 115 bookmarks => $self->bookmarks, 116 search => $self->_get_search_from_request, 117 }); 118 119 require Template; 120 require File::Basename; 121 my $template = Template->new({ INCLUDE_PATH => File::Basename::dirname($INC{'Bookmarks/List.pm'}) }); 122 123 my @all_tags = $list->bookmarks->get_tags({ selected => @{ $list->tags }[0] }); 124 my @cotags = $list->bookmarks->get_cotags({ search => $list->search }); 125 126 $template->process( 127 'list.tt', 128 { 129 base_url => $list->bookmarks->base_uri, 130 title => $list->title, 131 query => $list->query, 132 selected_tag => @{ $list->tags }[0], 133 search_tags => $list->tags, 134 links => [ $list->_get_list_links('text/html', { q => $list->query, tag => $list->tags }) ], 135 all_tags => \@all_tags, 136 cotags => \@cotags, 137 resources => $list->results, 138 pages => $list->search->pages, 139 }, 140 \my $output, 141 ); 142 return [200, ['Content-Type' => 'text/html; charset=UTF-8'], [$output]]; 103 143 } 104 144 -
trunk/lib/Bookmarks/List.pm
r106 r112 32 32 text => 'JSON', 33 33 type => 'application/json', 34 path => 'list', 34 35 query => { 35 36 %$query, … … 40 41 text => 'XBEL', 41 42 type => 'application/xml', 43 path => 'list', 42 44 query => { 43 45 %$query, … … 56 58 text => 'CSV', 57 59 type => 'text/csv', 60 path => 'list', 58 61 query => { 59 62 %$query, … … 64 67 text => 'URI List', 65 68 type => 'text/uri-list', 69 path => 'list', 66 70 query => { 67 71 %$query, … … 72 76 text => 'HTML', 73 77 type => 'text/html', 78 path => 'list', 74 79 query => { 75 80 %$query, … … 105 110 sub as_xbel { 106 111 my $self = shift; 107 require XML::XBEL; 108 #TODO: conditional support; if XML::XBEL is not present, return a 5xx response 112 113 eval { require XML::XBEL; } or 114 return [406, ['Content-Type' => 'text/plain'], ['This server does not support XBEL lists']]; 109 115 110 116 my $xbel = XML::XBEL->new; … … 147 153 sub as_csv { 148 154 my $self = shift; 149 require Text::CSV::Encoded; 155 156 eval { require Text::CSV::Encoded } or 157 return [406, ['Content-Type' => 'text/plain'], ['This server does not support CSV lists']]; 158 150 159 my $csv = Text::CSV::Encoded->new({ encoding_out => 'utf8' }); 151 160 my $text = qq{id,uri,title,tags,ctime,mtime\n}; … … 182 191 my $template = Template->new({ INCLUDE_PATH => File::Basename::dirname($INC{'Bookmarks/List.pm'}) }); 183 192 184 my @all_tags = $self->bookmarks->get_tags({ selected => @{ $self->tags }[0] });185 my @cotags = $self->bookmarks->get_cotags({ search => $self->search });186 187 193 $template->process( 188 ' list.tt',194 'html_list.tt', 189 195 { 190 196 base_url => $self->bookmarks->base_uri, 191 197 title => $self->title, 192 198 query => $self->query, 193 selected_tag => @{ $self->tags }[0],194 search_tags => $self->tags,195 199 links => [ $self->_get_list_links('text/html', { q => $self->query, tag => $self->tags }) ], 196 all_tags => \@all_tags,197 cotags => \@cotags,198 200 resources => $self->results, 199 201 pages => $self->search->pages, … … 207 209 my $self = shift; 208 210 209 require XML::Atom; 211 eval { require XML::Atom } or 212 return [406, ['Content-Type' => 'text/plain'], ['This server does not support Atom lists']]; 213 210 214 $XML::Atom::DefaultVersion = "1.0"; 211 215 -
trunk/lib/BookmarksApp.pm
r107 r112 61 61 } 62 62 63 # otherwise return a list64 return $self->_controller-> list;63 # otherwise return the sidebar 64 return $self->_controller->sidebar; 65 65 }; 66 66 POST {
Note: See TracChangeset
for help on using the changeset viewer.