mirror of
https://github.com/TracksApp/tracks.git
synced 2026-01-06 17:28:50 +01:00
* Some refactoring that makes todo_controller a little skinnier by making the user model a little fatter: Introduce new has_many relationships for completed_todos and deferred_todos and include Association Extensions to support their use. Update TodoController to use these new relationships.
* Remove the the app/views/feed/index.rhtml which has been previously moved to app/views/feedlist/index.rhtml git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@377 a4c988fc-2ded-0310-b66e-134b36920a42
This commit is contained in:
parent
1d22f08670
commit
0e6c6f9f77
4 changed files with 47 additions and 133 deletions
|
|
@ -16,15 +16,8 @@ class TodoController < ApplicationController
|
|||
|
||||
# If you've set no_completed to zero, the completed items box
|
||||
# isn't shown on the home page
|
||||
max_completed = @user.preference.show_number_completed - 1
|
||||
@done = nil
|
||||
if max_completed > 0
|
||||
@done = Todo.find(:all,
|
||||
:conditions => ['todos.user_id = ? and todos.state = ?', @user.id, 'completed'],
|
||||
:order => 'todos.completed_at DESC',
|
||||
:limit => max_completed,
|
||||
:include => [ :project, :context ])
|
||||
end
|
||||
max_completed = @user.preference.show_number_completed
|
||||
@done = @user.completed_todos.find(:all, :limit => max_completed) unless max_completed == 0
|
||||
|
||||
@contexts_to_show = @contexts.reject {|x| x.hide? }
|
||||
|
||||
|
|
@ -221,7 +214,7 @@ class TodoController < ApplicationController
|
|||
|
||||
def completed
|
||||
@page_title = "TRACKS::Completed tasks"
|
||||
@done = Todo.find_completed(@user.id)
|
||||
@done = @user.completed_todos
|
||||
@done_today = @done.completed_within 1.day.ago
|
||||
@done_this_week = @done.completed_within 1.week.ago
|
||||
@done_this_month = @done.completed_within 4.week.ago
|
||||
|
|
@ -229,34 +222,27 @@ class TodoController < ApplicationController
|
|||
|
||||
def completed_archive
|
||||
@page_title = "TRACKS::Archived completed tasks"
|
||||
@done = Todo.find_completed(@user.id)
|
||||
@done = @user.completed_todos
|
||||
@done_archive = @done.completed_more_than 28.day.ago
|
||||
end
|
||||
|
||||
def tickler
|
||||
@source_view = 'deferred'
|
||||
@page_title = "TRACKS::Tickler"
|
||||
@tickles = @user.todos.find_in_state(:all, :deferred, :order => "show_from ASC")
|
||||
@tickles = @user.deferred_todos
|
||||
@count = @tickles.size
|
||||
end
|
||||
|
||||
# Check for any due tickler items, activate them
|
||||
# Called by periodically_call_remote
|
||||
def check_tickler
|
||||
now = Date.today()
|
||||
@due_tickles = @user.todos.find_in_state(:all, :deferred, :conditions => ['show_from < ? OR show_from = ?', now, now ], :order => "show_from ASC")
|
||||
# Change the due tickles to active
|
||||
@due_tickles.each do |t|
|
||||
t.activate!
|
||||
t.save
|
||||
end
|
||||
respond_to do |wants|
|
||||
wants.html { redirect_to :controller => 'todo', :action => 'index' }
|
||||
wants.js
|
||||
@due_tickles = @user.deferred_todos.find_and_activate_ready
|
||||
respond_to do |format|
|
||||
format.html { redirect_to :controller => 'todo', :action => 'index' }
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
def check_user_return_item
|
||||
|
|
|
|||
|
|
@ -57,6 +57,11 @@ class Todo < ActiveRecord::Base
|
|||
complete!
|
||||
end
|
||||
end
|
||||
|
||||
def activate_and_save!
|
||||
activate!
|
||||
save!
|
||||
end
|
||||
|
||||
def show_from=(date)
|
||||
activate! if deferred? && date.blank?
|
||||
|
|
@ -73,33 +78,11 @@ class Todo < ActiveRecord::Base
|
|||
alias_method :original_set_initial_state, :set_initial_state
|
||||
|
||||
def set_initial_state
|
||||
if show_from && (show_from > Date.today())
|
||||
if show_from && (show_from > Date.today)
|
||||
write_attribute self.class.state_column, 'deferred'
|
||||
else
|
||||
original_set_initial_state
|
||||
end
|
||||
end
|
||||
|
||||
def self.not_done( id=id )
|
||||
self.find(:all, :conditions =>[ "done = ? AND context_id = ?", false, id], :order =>"due IS NULL, due ASC, created_at ASC")
|
||||
end
|
||||
|
||||
def self.find_completed(user_id)
|
||||
done = self.find(:all,
|
||||
:conditions => ['todos.user_id = ? and todos.state = ? and todos.completed_at is not null', user_id, 'completed'],
|
||||
:order => 'todos.completed_at DESC',
|
||||
:include => [ :project, :context ])
|
||||
|
||||
def done.completed_within( date )
|
||||
reject { |x| x.completed_at < date }
|
||||
end
|
||||
|
||||
def done.completed_more_than( date )
|
||||
reject { |x| x.completed_at > date }
|
||||
end
|
||||
|
||||
done
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
@ -1,9 +1,36 @@
|
|||
require 'digest/sha1'
|
||||
|
||||
class User < ActiveRecord::Base
|
||||
has_many :contexts, :order => "position ASC", :dependent => :delete_all
|
||||
has_many :projects, :order => "position ASC", :dependent => :delete_all
|
||||
has_many :todos, :order => "completed_at DESC, created_at DESC", :dependent => :delete_all
|
||||
has_many :contexts,
|
||||
:order => 'position ASC',
|
||||
:dependent => :delete_all
|
||||
has_many :projects,
|
||||
:order => 'position ASC',
|
||||
:dependent => :delete_all
|
||||
has_many :todos,
|
||||
:order => 'completed_at DESC, created_at DESC',
|
||||
:dependent => :delete_all
|
||||
has_many :deferred_todos,
|
||||
:class_name => 'Todo',
|
||||
:conditions => [ 'state = ?', 'deferred' ],
|
||||
:order => 'show_from ASC, created_at DESC' do
|
||||
def find_and_activate_ready
|
||||
find(:all, :conditions => ['show_from <= ?', Date.today ]).collect { |t| t.activate_and_save! }
|
||||
end
|
||||
end
|
||||
has_many :completed_todos,
|
||||
:class_name => 'Todo',
|
||||
:conditions => ['todos.state = ? and todos.completed_at is not null', 'completed'],
|
||||
:order => 'todos.completed_at DESC',
|
||||
:include => [ :project, :context ] do
|
||||
def completed_within( date )
|
||||
reject { |x| x.completed_at < date }
|
||||
end
|
||||
|
||||
def completed_more_than( date )
|
||||
reject { |x| x.completed_at > date }
|
||||
end
|
||||
end
|
||||
has_many :notes, :order => "created_at DESC", :dependent => :delete_all
|
||||
has_one :preference
|
||||
|
||||
|
|
|
|||
|
|
@ -1,82 +0,0 @@
|
|||
<div id="display_box">
|
||||
<div id="feeds">
|
||||
<div id="feedlegend">
|
||||
<h3>Legend:</h3>
|
||||
<dl>
|
||||
<dt><%= image_tag("feed-icon.png", :size => "16X16", :border => 0)%></dt><dd>RSS Feed</dd>
|
||||
<dt><span class="feed">TXT</span></dt><dd>Plain Text Feed</dd>
|
||||
<dt><span class="feed">iCal</span></dt><dd>iCal feed</dd>
|
||||
</dl>
|
||||
<p>Note: All feeds show only actions that have not been marked as done.</p>
|
||||
</div>
|
||||
<ul>
|
||||
<li>
|
||||
<%= rss_feed_link({ :limit => 15 }) %>
|
||||
<%= text_feed_link({ :limit => 15 }) %>
|
||||
<%= ical_feed_link({ :limit => 15 }) %>
|
||||
Last 15 actions
|
||||
</li>
|
||||
<li>
|
||||
<%= rss_feed_link %>
|
||||
<%= text_feed_link %>
|
||||
<%= ical_feed_link %>
|
||||
All actions
|
||||
</li>
|
||||
<li>
|
||||
<%= rss_feed_link({ :due => 0 }) %>
|
||||
<%= text_feed_link({ :due => 0 }) %>
|
||||
<%= ical_feed_link({ :due => 0 }) %>
|
||||
Actions due today or earlier
|
||||
</li>
|
||||
<li>
|
||||
<%= rss_feed_link({ :due => 6 }) %>
|
||||
<%= text_feed_link({ :due => 6 }) %>
|
||||
<%= ical_feed_link({ :due => 6 }) %>
|
||||
Actions due in 7 days or earlier
|
||||
</li>
|
||||
<li>
|
||||
<%= rss_feed_link({ :done => 7 }) %>
|
||||
<%= text_feed_link({ :done => 7 }) %>
|
||||
Actions completed in the last 7 days
|
||||
</li>
|
||||
<li>
|
||||
<%= rss_feed_link({ :action => 'list_contexts_only', :feedtype => 'rss' }) %>
|
||||
<%= text_feed_link({ :action => 'list_contexts_only', :feedtype => 'text' }) %>
|
||||
All Contexts
|
||||
</li>
|
||||
<li>
|
||||
<%= rss_feed_link({ :action => 'list_projects_only', :feedtype => 'rss' }) %>
|
||||
<%= text_feed_link({ :action => 'list_projects_only', :feedtype => 'text' }) %>
|
||||
All Projects
|
||||
</li>
|
||||
<li><h4>Feeds for uncompleted actions in a specific context:</h4>
|
||||
<ul>
|
||||
<% for context in @contexts %>
|
||||
<li>
|
||||
<%= rss_feed_link({ :context => context }) %>
|
||||
<%= text_feed_link({ :context => context }) %>
|
||||
<%= ical_feed_link({ :context => context }) %>
|
||||
Next actions in <strong><%=h context.name %></strong>
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</li>
|
||||
<li><h4>Feeds for uncompleted actions in a specific project:</h4>
|
||||
<ul>
|
||||
<% for project in @projects %>
|
||||
<li>
|
||||
<%= rss_feed_link({ :project => project }) %>
|
||||
<%= text_feed_link({ :project => project }) %>
|
||||
<%= ical_feed_link({ :project => project }) %>
|
||||
Next actions for <strong><%=h project.name %></strong>
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div><!-- End of display_box -->
|
||||
|
||||
<div id="input_box">
|
||||
<%= render "sidebar/sidebar" %>
|
||||
</div><!-- End of input box -->
|
||||
Loading…
Add table
Add a link
Reference in a new issue