From 7605ec404f2036e8cb5f79e089ac3769a13fe7d8 Mon Sep 17 00:00:00 2001 From: Reinier Balt Date: Mon, 29 Jul 2013 12:25:13 +0200 Subject: [PATCH] move will_paginate on all_todos pages to will_paginate-bootstrap gem to get the bootstrap styling for free. Adds caching to todos/done page too --- Gemfile | 2 +- Gemfile.lock | 4 +++- app/controllers/todos_controller.rb | 8 ++++++- app/helpers/todos_helper.rb | 6 ++--- app/views/todos/all_done.html.erb | 36 +++++++++++++++-------------- app/views/todos/done.html.erb | 21 ++++++++++------- 6 files changed, 46 insertions(+), 31 deletions(-) diff --git a/Gemfile b/Gemfile index 8afded69..8d2545a8 100644 --- a/Gemfile +++ b/Gemfile @@ -35,7 +35,7 @@ gem 'mousetrap-rails' gem "RedCloth" gem "sanitize" -gem "will_paginate" +gem "will_paginate-bootstrap" gem "acts_as_list" gem "aasm" gem "htmlentities" diff --git a/Gemfile.lock b/Gemfile.lock index a083aa28..25b0e5d4 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -206,6 +206,8 @@ GEM uniform_notifier (1.2.0) websocket (1.0.7) will_paginate (3.0.4) + will_paginate-bootstrap (0.2.3) + will_paginate (>= 3.0.3) xpath (2.0.0) nokogiri (~> 1.3) yard (0.8.7) @@ -250,5 +252,5 @@ DEPENDENCIES turbolinks twitter-bootstrap-rails! uglifier (>= 1.3.0) - will_paginate + will_paginate-bootstrap yard diff --git a/app/controllers/todos_controller.rb b/app/controllers/todos_controller.rb index 551ed1be..ea823b25 100644 --- a/app/controllers/todos_controller.rb +++ b/app/controllers/todos_controller.rb @@ -32,6 +32,8 @@ class TodosController < ApplicationController # Set count badge to number of not-done, not hidden context items @count = current_user.todos.active.not_hidden.count(:all) @todos_without_project = @not_done_todos.select{|t|t.project.nil?} + @last_updated_todo_without_project = @todos_without_project + .inject(@todos_without_project.first){ |last, todo| todo.updated_at > last.updated_at ? todo : last } end format.m do @page_title = t('todos.mobile_todos_page_title') @@ -536,7 +538,11 @@ class TodosController < ApplicationController @source_view = 'done' @page_title = t('todos.completed_tasks_title') - @done = current_user.todos.completed.includes(Todo::DEFAULT_INCLUDES).reorder('completed_at DESC').paginate :page => params[:page], :per_page => 20 + @done = current_user.todos.completed + .includes(Todo::DEFAULT_INCLUDES) + .reorder('completed_at DESC') + .page(params[:page]).per_page(20) + @count = @done.size end diff --git a/app/helpers/todos_helper.rb b/app/helpers/todos_helper.rb index 65a200d1..91e702c7 100644 --- a/app/helpers/todos_helper.rb +++ b/app/helpers/todos_helper.rb @@ -87,11 +87,11 @@ module TodosHelper end def todos_container_header(settings={}) - header = settings[:link_in_header].nil? ? "" : content_tag(:div, :class=>"add_note_link"){settings[:link_in_header]} - header += content_tag(:h4) do + link = settings[:link_in_header].nil? ? "" : content_tag(:span, :class=>"add-note-link"){"(#{settings[:link_in_header]})".html_safe} + header = content_tag(:h4) do toggle = "" # TODO: toggle = settings[:collapsible] ? container_toggle("toggle_#{settings[:id]}") : "" - "#{toggle} #{settings[:title]} #{settings[:append_descriptor]}".html_safe + "#{toggle} #{settings[:title]} #{settings[:append_descriptor]} #{link}".html_safe end header.html_safe end diff --git a/app/views/todos/all_done.html.erb b/app/views/todos/all_done.html.erb index d55c05c1..4b238d2b 100644 --- a/app/views/todos/all_done.html.erb +++ b/app/views/todos/all_done.html.erb @@ -1,22 +1,24 @@ <% paginate_options = { - :class => :add_note_link, - :previous_label => '« '+ t('common.previous'), - :next_label => t('common.next')+' »', - :inner_window => 2 + class: 'pagination pagination-small', + previous_label: '« '+ t('common.previous'), + next_label: t('common.next')+' »', + inner_window: 2, + renderer: BootstrapPagination::Rails } %> -
-
-
<%= will_paginate @done, paginate_options %>
-

<%= t('todos.all_completed') %>

- <% if @done.empty? -%> -

<%= t('todos.no_completed_actions') %>

- <% else -%> - <%= render :partial => "todos/todo", :collection => @done, :locals => { :parent_container_type => "completed", :suppress_context => false, :suppress_project => false } %> - <% end -%> -
- - - +
+ <%= will_paginate @done, paginate_options %>
+ +

<%= t('todos.all_completed') %>

+ +<% if @done.empty? -%> +
+

<%= t('todos.no_completed_actions') %>

+
+<% else -%> + <%= render :partial => "todos/todo", :collection => @done, :locals => { :parent_container_type => "completed", :suppress_context => false, :suppress_project => false } %> +<% end -%> + + \ No newline at end of file diff --git a/app/views/todos/done.html.erb b/app/views/todos/done.html.erb index c5b5b0d9..58330131 100644 --- a/app/views/todos/done.html.erb +++ b/app/views/todos/done.html.erb @@ -1,13 +1,18 @@ -
- +<%# Template Dependency: todos/collection -%> +<% cache [@done_today.first, "done_today"] do -%> <%= show_completed_todos_for("today", @done_today) %> - <%= show_completed_todos_for("rest_of_week", @done_rest_of_week) %> - <%= show_completed_todos_for("rest_of_month", @done_rest_of_month) %> +<% end -%> -

+<% cache [@done_rest_of_week.first, "done_rest_of_week"] do -%> + <%= show_completed_todos_for("rest_of_week", @done_rest_of_week) %> +<% end -%> + +<% cache [@done_rest_of_month.first, "done_rest_of_month"] do -%> + <%= show_completed_todos_for("rest_of_month", @done_rest_of_month) %> +<% end -%> + +

<%= raw t('todos.see_all_completed', :link => link_to(t("todos.all_completed_here"), determine_all_done_path)) %> -

- -
+

\ No newline at end of file