mirror of
https://github.com/TracksApp/tracks.git
synced 2026-03-13 07:56:17 +01:00
small refactorings
fix passing params in use of _collection
This commit is contained in:
parent
f891ee86fe
commit
5cfa115cdc
8 changed files with 54 additions and 30 deletions
|
|
@ -23,7 +23,11 @@ module TodosHelper
|
||||||
|
|
||||||
def show_grouped_todos
|
def show_grouped_todos
|
||||||
collection = (@group_view_by == 'context') ? @contexts_to_show : @projects_to_show
|
collection = (@group_view_by == 'context') ? @contexts_to_show : @projects_to_show
|
||||||
render(:partial => collection, :locals => { :settings => {:collapsible => true, :show_empty_containers => @show_empty_containers }})
|
render(:partial => collection, :locals => { :settings => {
|
||||||
|
:collapsible => true,
|
||||||
|
:show_empty_containers => @show_empty_containers,
|
||||||
|
:parent_container_type => @group_view_by
|
||||||
|
}})
|
||||||
end
|
end
|
||||||
|
|
||||||
def default_collection_settings
|
def default_collection_settings
|
||||||
|
|
@ -295,22 +299,34 @@ module TodosHelper
|
||||||
def project_and_context_links(todo, parent_container_type, opts = {})
|
def project_and_context_links(todo, parent_container_type, opts = {})
|
||||||
str = ''
|
str = ''
|
||||||
if todo.completed?
|
if todo.completed?
|
||||||
str += todo.context.name unless opts[:suppress_context]
|
links = []
|
||||||
should_suppress_project = opts[:suppress_project] || todo.project.nil?
|
links << todo.context.name unless opts[:suppress_context]
|
||||||
str += ", " unless str.blank? || should_suppress_project
|
links << todo.project.name unless opts[:suppress_project] || todo.project.nil?
|
||||||
str += todo.project.name unless should_suppress_project
|
str = "(#{links.join(", ")})" unless links.empty?
|
||||||
str = "(#{str})" unless str.blank?
|
|
||||||
else
|
else
|
||||||
if (['project', 'tag', 'stats', 'search'].include?(parent_container_type))
|
str << item_link_to_context( todo ) if include_context_link(todo, parent_container_type)
|
||||||
str << item_link_to_context( todo )
|
str << item_link_to_project( todo ) if include_project_link(todo, parent_container_type)
|
||||||
end
|
|
||||||
if (['context', 'tickler', 'tag', 'stats', 'search'].include?(parent_container_type)) && !todo.project_id.nil? && !todo.project.is_a?(NullProject)
|
|
||||||
str << item_link_to_project( todo )
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
return str.html_safe
|
return str.html_safe
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def include_context_link(todo, parent_container_type)
|
||||||
|
return true if (['stats', 'search'].include?(parent_container_type))
|
||||||
|
# TODO: remove next line if 'project' supports group_view_by
|
||||||
|
return true if parent_container_type == 'project'
|
||||||
|
return true if @group_view_by == 'project'
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
def include_project_link(todo, parent_container_type)
|
||||||
|
return false unless todo.has_project?
|
||||||
|
return true if (['stats', 'search'].include?(parent_container_type))
|
||||||
|
# TODO: remove next line if 'context' supports group_view_by
|
||||||
|
return true if parent_container_type == 'context'
|
||||||
|
return true if @group_view_by == 'context'
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
# Uses the 'staleness_starts' value from settings.yml (in days) to colour the
|
# Uses the 'staleness_starts' value from settings.yml (in days) to colour the
|
||||||
# background of the action appropriately according to the age of the creation
|
# background of the action appropriately according to the age of the creation
|
||||||
# date:
|
# date:
|
||||||
|
|
|
||||||
|
|
@ -527,19 +527,15 @@ class RecurringTodo < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# check if there are any days left this week for the next todo
|
day = find_first_day_in_this_week(start)
|
||||||
start.wday().upto 6 do |i|
|
return day unless day == -1
|
||||||
return start + (i-start.wday()).days unless self.every_day[i,1] == ' '
|
|
||||||
end
|
|
||||||
|
|
||||||
# we did not find anything this week, so check the nth next, starting from
|
# we did not find anything this week, so check the nth next, starting from
|
||||||
# sunday
|
# sunday
|
||||||
start = start + self.every_other1.week - (start.wday()).days
|
start = start + self.every_other1.week - (start.wday()).days
|
||||||
|
|
||||||
# check if there are any days left this week for the next todo
|
start = find_first_day_in_this_week(start)
|
||||||
start.wday().upto 6 do |i|
|
return start unless start == -1
|
||||||
return start + (i-start.wday()).days unless self.every_day[i,1] == ' '
|
|
||||||
end
|
|
||||||
|
|
||||||
raise Exception.new, "unable to find next weekly date (#{self.every_day})"
|
raise Exception.new, "unable to find next weekly date (#{self.every_day})"
|
||||||
end
|
end
|
||||||
|
|
@ -729,4 +725,12 @@ class RecurringTodo < ActiveRecord::Base
|
||||||
return start
|
return start
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def find_first_day_in_this_week(start)
|
||||||
|
# check if there are any days left this week for the next todo
|
||||||
|
start.wday().upto 6 do |i|
|
||||||
|
return start + (i-start.wday()).days unless self.every_day[i,1] == ' '
|
||||||
|
end
|
||||||
|
return -1
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -367,6 +367,10 @@ class Todo < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def has_project?
|
||||||
|
return ! (project_id.nil? || project.is_a?(NullProject))
|
||||||
|
end
|
||||||
|
|
||||||
# used by the REST API. <tags> will also work, this is renamed to add_tags in TodosController::TodoCreateParamsHelper::initialize
|
# used by the REST API. <tags> will also work, this is renamed to add_tags in TodosController::TodoCreateParamsHelper::initialize
|
||||||
def add_tags=(params)
|
def add_tags=(params)
|
||||||
unless params[:tag].nil?
|
unless params[:tag].nil?
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@
|
||||||
# rendering of "due in x days" that change without touching updated at of the todo
|
# 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
|
cache [context, @source_view, current_user.date.strftime("%Y%m%d"), @tag_name] do
|
||||||
%>
|
%>
|
||||||
|
|
||||||
<%=
|
<%=
|
||||||
render :partial => 'todos/collection',
|
render :partial => 'todos/collection',
|
||||||
:object => @not_done,
|
:object => @not_done,
|
||||||
|
|
@ -13,8 +12,8 @@ cache [context, @source_view, current_user.date.strftime("%Y%m%d"), @tag_name] d
|
||||||
:collapsible => settings[:collapsible],
|
:collapsible => settings[:collapsible],
|
||||||
:container_name => 'context',
|
:container_name => 'context',
|
||||||
:title => show_context_name(context),
|
:title => show_context_name(context),
|
||||||
:show_empty_containers => settings[:show_empty_containers]
|
:show_empty_containers => settings[:show_empty_containers],
|
||||||
|
:parent_container_type => settings[:parent_container_type]
|
||||||
}}
|
}}
|
||||||
%>
|
%>
|
||||||
|
<% end %>
|
||||||
<% end %>
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
done_todo_options = {:append_descriptor => suffix_completed, :suppress_context => true, :parent_container_type => 'context'}
|
done_todo_options = {:append_descriptor => suffix_completed, :suppress_context => true, :parent_container_type => 'context'}
|
||||||
-%>
|
-%>
|
||||||
<div id="display_box">
|
<div id="display_box">
|
||||||
<%= render :partial => @context, :locals => { :settings => {:collapsible => false, :show_empty_containers => true }} %>
|
<%= render :partial => @context, :locals => { :settings => {:collapsible => false, :show_empty_containers => true, :parent_container_type => 'context' }} %>
|
||||||
|
|
||||||
<%= show_deferred_pending_todos(@deferred_todos, @pending_todos, deferred_pending_options) %>
|
<%= show_deferred_pending_todos(@deferred_todos, @pending_todos, deferred_pending_options) %>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,14 +10,15 @@ cache [project, @source_view, current_user.date.strftime("%Y%m%d")] do
|
||||||
<%=
|
<%=
|
||||||
title = source_view_is(:project) ? t('projects.actions_in_project_title') : show_project_name(project)
|
title = source_view_is(:project) ? t('projects.actions_in_project_title') : show_project_name(project)
|
||||||
|
|
||||||
render :partial => 'todos/collection',
|
render(:partial => 'todos/collection',
|
||||||
:object => @not_done,
|
:object => @not_done,
|
||||||
:locals => { :settings => {
|
:locals => { :settings => {
|
||||||
:id => "p#{project.id}",
|
:id => "p#{project.id}",
|
||||||
:collapsible => settings[:collapsible],
|
:collapsible => settings[:collapsible],
|
||||||
:title => title,
|
:title => title,
|
||||||
:container_name => 'project',
|
:container_name => 'project',
|
||||||
:show_empty_containers => settings[:show_empty_containers]
|
:show_empty_containers => settings[:show_empty_containers],
|
||||||
}}
|
:parent_container_type => settings[:parent_container_type]
|
||||||
|
}})
|
||||||
%>
|
%>
|
||||||
<% end -%>
|
<% end -%>
|
||||||
|
|
@ -9,7 +9,7 @@
|
||||||
<div id="display_box">
|
<div id="display_box">
|
||||||
<%= project_next_prev %>
|
<%= project_next_prev %>
|
||||||
|
|
||||||
<%= render :partial => @project, :locals => {:settings => {:collapsible => false, :show_empty_containers => true }} %>
|
<%= render :partial => @project, :locals => {:settings => {:collapsible => false, :show_empty_containers => true, :parent_container_type => 'project' }} %>
|
||||||
|
|
||||||
<%= show_deferred_pending_todos(@deferred_todos, @pending_todos, deferred_pending_options) %>
|
<%= show_deferred_pending_todos(@deferred_todos, @pending_todos, deferred_pending_options) %>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
<%= show_todos_without_project(@todos_without_project) -%>
|
<%= show_todos_without_project(@todos_without_project) -%>
|
||||||
<% end -%>
|
<% end -%>
|
||||||
|
|
||||||
<%= show_done_todos(@done, {:parent_container_type => 'home', :collapsible => true}) unless @done.nil? %>
|
<%= show_done_todos(@done, {:parent_container_type => @group_view_by, :collapsible => true}) unless @done.nil? %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="input_box">
|
<div id="input_box">
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue