Commit bcb82c8022595f078df0de822a88b9e8910f46ae
1 parent
dd846d23
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
virtuoso: added pagination for triples templates
Showing
2 changed files
with
12 additions
and
4 deletions
Show diff stats
plugins/virtuoso/lib/virtuoso_plugin/triples_template.rb
| ... | ... | @@ -28,7 +28,7 @@ class VirtuosoPlugin::TriplesTemplate < Article |
| 28 | 28 | def to_html(options = {}) |
| 29 | 29 | article = self |
| 30 | 30 | proc do |
| 31 | - render :file => 'content_viewer/triples_template', :locals => {:article => article} | |
| 31 | + render :file => 'content_viewer/triples_template', :locals => {:article => article, :page => params[:npage]} | |
| 32 | 32 | end |
| 33 | 33 | end |
| 34 | 34 | |
| ... | ... | @@ -36,11 +36,17 @@ class VirtuosoPlugin::TriplesTemplate < Article |
| 36 | 36 | @plugin ||= VirtuosoPlugin.new(self) |
| 37 | 37 | end |
| 38 | 38 | |
| 39 | + attr_reader :results | |
| 40 | + | |
| 39 | 41 | def template_content(page=1) |
| 40 | 42 | begin |
| 41 | - results = plugin.virtuoso_readonly_client.query(query).paginate({:per_page => per_page, :page => page}) | |
| 43 | + @results ||= plugin.virtuoso_readonly_client.query(query).paginate({:per_page => per_page, :page => page}) | |
| 42 | 44 | liquid_template = Liquid::Template.parse(template) |
| 43 | - rendered_template = liquid_template.render('results' => results) | |
| 45 | + rendered_template = liquid_template.render('results' => results, | |
| 46 | + 'total_pages' => results.total_pages, | |
| 47 | + 'current_page' => results.current_page, | |
| 48 | + 'per_page' => results.per_page, | |
| 49 | + 'total_entries' => results.total_entries) | |
| 44 | 50 | transform_html(rendered_template) |
| 45 | 51 | rescue => ex |
| 46 | 52 | logger.info ex.to_s | ... | ... |
plugins/virtuoso/views/content_viewer/triples_template.html.erb