diff --git a/app/assets/javascripts/tracks.js b/app/assets/javascripts/tracks.js index 87361fb8..5d867ff0 100644 --- a/app/assets/javascripts/tracks.js +++ b/app/assets/javascripts/tracks.js @@ -329,6 +329,12 @@ var TracksPages = { refresh_page(); }); + $("a#show_empty_containers").click(function () { + var show = ($(this).attr("x_show_empty_containers") == "true"); + $.cookie('show_empty_containers', !show); + refresh_page(); + }); + /* fade flashes and alerts in automatically */ $(".alert").fadeOut(8000); } diff --git a/app/controllers/contexts_controller.rb b/app/controllers/contexts_controller.rb index 7a312abd..9bc7ea29 100644 --- a/app/controllers/contexts_controller.rb +++ b/app/controllers/contexts_controller.rb @@ -43,13 +43,13 @@ class ContextsController < ApplicationController @done = @context.todos.completed.limit(@max_completed).reorder("todos.completed_at DESC, todos.created_at DESC").includes(Todo::DEFAULT_INCLUDES) @not_done_todos = @context.todos.active.reorder("todos.due IS NULL, todos.due ASC, todos.created_at ASC").includes(Todo::DEFAULT_INCLUDES) - @deferred = @context.todos.deferred.includes(Todo::DEFAULT_INCLUDES) - @pending = @context.todos.pending.includes(Todo::DEFAULT_INCLUDES) + @deferred_todos = @context.todos.deferred.includes(Todo::DEFAULT_INCLUDES) + @pending_todos = @context.todos.pending.includes(Todo::DEFAULT_INCLUDES) @projects = current_user.projects @contexts = current_user.contexts - @count = @not_done_todos.count + @deferred.count + @pending.count + @count = @not_done_todos.count + @deferred_todos.count + @pending_todos.count @page_title = "TRACKS::Context: #{@context.name}" respond_to do |format| format.html diff --git a/app/controllers/todos_controller.rb b/app/controllers/todos_controller.rb index fb285bf7..24ec64f2 100644 --- a/app/controllers/todos_controller.rb +++ b/app/controllers/todos_controller.rb @@ -9,6 +9,8 @@ class TodosController < ApplicationController def index @source_view = params['_source_view'] || 'todo' @group_view_by = cookies['group_view_by'] || 'context' + @show_empty_containers = (cookies['show_empty_containers']=="true") || false + init_data_for_sidebar unless mobile? @todos = current_user.todos.includes(Todo::DEFAULT_INCLUDES) @@ -31,6 +33,7 @@ class TodosController < ApplicationController @page_title = t('todos.task_list_title') # 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?} end format.m do @page_title = t('todos.mobile_todos_page_title') @@ -931,6 +934,7 @@ class TodosController < ApplicationController @tag_title = @single_tag ? @tag_name : tag_title(@tag_expr) @group_view_by = cookies['group_view_by'] || 'context' + @show_empty_containers = (cookies['show_empty_containers']=="true") || false end def get_ids_from_tag_expr(tag_expr) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 1b63eeb0..e4397553 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -17,6 +17,17 @@ module ApplicationHelper end end + def show_empty_containers_menu_entry + @show_empty_containers ||= false + @group_view_by ||= 'context' + content_tag(:li) do + link_to( + t("layouts.navigation.show_empty_containers_#{@group_view_by}"), + '#', + {:id => "show_empty_containers", :accesskey => "s", :title => t('layouts.navigation.show_empty_containers_title'), :x_show_empty_containers => @show_empty_containers} ) + end + end + def container_toggle(id) link_to( image_tag("blank.png", :alt => t('common.collapse_expand')), diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index 2899eb02..c4a85993 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -15,11 +15,13 @@ module ProjectsHelper end def project_next_prev - html = "" - html << link_to_project(@previous_project, "« #{@previous_project.shortened_name}".html_safe) if @previous_project - html << " | " if @previous_project && @next_project - html << link_to_project(@next_project, "#{@next_project.shortened_name} »".html_safe) if @next_project - return html.html_safe + content_tag(:div, :id=>"project-next-prev") do + html = "" + html << link_to_project(@previous_project, "« #{@previous_project.shortened_name}".html_safe) if @previous_project + html << " | " if @previous_project && @next_project + html << link_to_project(@next_project, "#{@next_project.shortened_name} »".html_safe) if @next_project + html.html_safe + end end def project_next_prev_mobile diff --git a/app/helpers/todos_helper.rb b/app/helpers/todos_helper.rb index 464867f6..87926aba 100644 --- a/app/helpers/todos_helper.rb +++ b/app/helpers/todos_helper.rb @@ -1,17 +1,112 @@ module TodosHelper - def empty_message_holder(show) - content_tag(:div, :id => "no_todos_in_view", :class => "container context", :style => "display:" + (show ? "block" : "none") ) do - content_tag(:h2) { t('todos.no_actions_found_title') } + def empty_message_holder(container_name, show, title_param=nil) + content_tag(:div, :id => "no_todos_in_view", :class => "container #{container_name}", :style => "display:" + (show ? "block" : "none") ) do + content_tag(:h2) { t("todos.no_actions.title", :param=>title_param) } + content_tag(:div, :class => "message") do - content_tag(:p) { t('todos.no_actions_found') } + content_tag(:p) { t("todos.no_actions.#{container_name}", :param=>title_param) } + end + end + end + + def todos_container_empty_message(container_name, container_id, show_message) + content_tag(:div, :id=>"#{container_id}-empty-d", :style=>"display:#{show_message ? 'block' : 'none'}") do + content_tag(:div, :class=>"message") do + content_tag(:p) do + t("todos.no_actions.#{container_name}") + end end end end def show_grouped_todos collection = (@group_view_by == 'context') ? @contexts_to_show : @projects_to_show - render(:partial => collection, :locals => { :collapsible => true }) + render(:partial => collection, :locals => { :settings => {:collapsible => true, :show_empty_containers => @show_empty_containers }}) + end + + def default_collection_settings + { + :suppress_context => false, + :suppress_project => false, + :collapsible => false, + :append_descriptor => nil, + :parent_container_type => nil, + :show_empty_containers => true + } + end + + def show_done_todos(done_todos, settings={}) + settings[:container_name] = "completed" + settings[:link_in_header] = link_to(t('common.show_all'), determine_done_path) + + render :partial => 'todos/collection', + :object => done_todos, + :locals => {:settings => settings.reverse_merge!(default_collection_settings)} + end + + def show_hidden_todos(hidden_todos, settings={}) + settings[:container_name] = "hidden" + + render :partial => 'todos/collection', + :object => hidden_todos, + :locals => {:settings => settings.reverse_merge!(default_collection_settings)} + end + + def show_deferred_pending_todos(deferred_todos, pending_todos, settings={}) + settings[:pending] = pending_todos + settings[:container_name]="deferred_pending" + + render :partial => "todos/collection", + :object => deferred_todos+pending_todos, + :locals => {:settings => settings.reverse_merge!(default_collection_settings)} + end + + def show_todos_without_project(todos_without_project) + render :partial => 'todos/collection', + :object => todos_without_project, + :locals => {:settings => { + :collapsible => true, + :container_name => "without_project" + } + } + end + + def todos_container(settings={}) + container_name = settings[:container_name] + settings.reverse_merge!({ + :id => "#{container_name}_container", + :class => "container #{container_name}", + }) + + content_tag(:div, + :class=>settings[:class], + :id=>settings[:id], + :style => "display:" + (settings[:show_container] ? "block" : "none")) do + yield + end + end + + def todos_container_header(settings={}) + settings.reverse_merge!({ + :title => t("todos.actions.#{settings[:parent_container_type]}_#{settings[:container_name]}", :param => settings[:title_param]) + }) + header = settings[:link_in_header].nil? ? "" : content_tag(:div, :class=>"add_note_link"){settings[:link_in_header]} + header += content_tag(:h2) do + toggle = settings[:collapsible] ? container_toggle("toggle_#{settings[:container_name]}") : "" + "#{toggle} #{settings[:title]} #{settings[:append_descriptor]}".html_safe + end + header.html_safe + end + + def todos_container_items(collection, settings={}) + settings.reverse_merge!({:id => "#{settings[:container_name]}"}) + # do not pass :class to partial locals + settings.delete(:class) + + content_tag(:div, :id =>settings[:id]+"_items", :class=>"items toggle_target") do + todos_container_empty_message(settings[:container_name], settings[:id], collection.empty?) + + render(:partial => "todos/todo", :collection => collection, :locals => settings) + end end def remote_star_icon(todo=@todo) diff --git a/app/models/project.rb b/app/models/project.rb index 85005f9e..1cc84500 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -167,4 +167,8 @@ class NullProject nil end + def name + "" + end + end diff --git a/app/views/contexts/_context.html.erb b/app/views/contexts/_context.html.erb index 950f0402..096625a7 100644 --- a/app/views/contexts/_context.html.erb +++ b/app/views/contexts/_context.html.erb @@ -4,17 +4,17 @@ # rendering of "due in x days" that change without touching updated at of the todo cache [context, @source_view, current_user.date.strftime("%Y%m%d"), @tag_name] do %> -