Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/dalyons/redmine-todos-scrum…
Browse files Browse the repository at this point in the history
…-plugin into dalyons/master

Conflicts:
	app/views/todos/_new_todo.html.erb
  • Loading branch information
iteman committed Oct 3, 2009
2 parents 684fe87 + 2d69150 commit 0e159d7
Show file tree
Hide file tree
Showing 30 changed files with 491 additions and 363 deletions.
9 changes: 8 additions & 1 deletion README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@
A nested, easy to use project based todos plugin for Redmine. Allows easy creation and management of infinitely nestable todo lists on a per project basis, that can be organised into sprints(or releases).
Also provides global 'My Todos' for all projects. Todos can be allocated to uses, and tied to Redmine Issues.

Currently has translations for Chinese, Spanish, Italian, French, German, Korean, Japanese and English, thanks to contributions from others.
Currently has translations for Russian, Chinese, Spanish, Italian, French, German, Korean, Japanese and English, thanks to contributions from others.

Please check the issues page(thanks Mischa!) for current known bugs.

== Release 0.0.3.9
* Merging in of nowhereman's changes(thanks for all the features!)
* Re-implementation of todo editing functionality - now you can edit everything, not just text.
* Massive refactoring of the todo associations to make them simpler and more generic, and to prepare for templates.
* Russian translations added
* IMPORTANT NOTE: you will have to 'rake db:migrate_plugins' after updating to this version(there are db changes)!!!

== Release 0.0.3.8
* Issue page integration (Adding todos directly in the Issue page)
* You can edit the text of a todo
Expand Down
140 changes: 24 additions & 116 deletions app/controllers/mytodos_controller.rb
Original file line number Diff line number Diff line change
@@ -1,147 +1,55 @@
#require 'ruby-debug'

class MytodosController < ApplicationController
#Inherits from the Todos controller to save repition of all the todo methods.
#Since todos attach through the Todoable interface, all you have to do is override
#the parent_object method, which finds/loads the object that the todos belong to (User/Project/etc).
#TODO: This could be done as a mixin module, something like 'acts_as_todoable'.
class MytodosController < TodosController

#put in a filthy hack to reload the patches to core redmine models.
#If cache_classes is off, the patches are dropped when the classes reload on every request.
#So, we reapply the patches here - for some reason it doesnt work in the Todo model.
#TODO: you are very welcome to find a better way to do this!
#unless Rails.configuration.cache_classes
# unloadable
# User.send(:include, TodosUserPatch)
#end


before_filter :authorize
helper :todos
before_filter :set_user

def index
#@user = User.current

#get all the root level todos belonging to current user
#@todos = User.current.todos.select{|t| t.parent_id == nil }
@personal_todos = Todo.personal_todos.for_user(User.current.id).roots
@personal_todos = @user.todos.roots

#find the roots of any project todo that belongs to or was authored by the user
#(The root itself may not belong to the user, but we still want to display it!)
@project_todos = Todo.project_todos.for_user(User.current.id).collect{|t| t.root}.uniq
@project_todos = Todo.project_todos.for_user(@user.id).collect{|t| t.root}.uniq

#group the results by project, into a hash keyed on project.
#this line is so beautiful it nearly made me cry!
@grouped_project_todos = Set.new(@project_todos).classify{|t| t.project }


@new_todo = Todo.new(:author_id => User.current.id)
end

def new
@todo = Todo.new
@todo.parent_id = Todo.find(params[:parent_id]).id
@todo.assigned_to = User.current
render :partial => 'new_todo',
:locals => { :todo => @todo}
end

def create
@todo = Todo.new(params[:todo])
@todo.author = User.current
@grouped_project_todos = Set.new(@project_todos).classify{|t| t.todoable }

#debugger
if @todo.save

if (request.xhr?)
@element_html = render_to_string :partial => 'todos/todo_li',
:locals => { :todo => @todo, :editable => true }
render :template => 'todos/create.rjs' #using rjs
else
flash[:notice] = @todo.errors.collect{|k,m| m}.join
redirect_to :action => "index"
end
else
flash.now[:error] = @todo.errors.collect{|k,m| m}.join
respond_to do |format|
format.html { redirect_to :action => "index" }
format.js { render :template => 'todos/create.rjs' }
end
end
@new_todo = @user.todos.new(:author_id => @user.id)
end

def destroy
@todo = Todo.find_by_user(params[:id], User.current.id)

if @todo.destroy
render :text => ""
else
render :text => @todo.errors.collect{|k,m| m}.join
end
end

def show
begin
@todo = Todo.for_user(User.current.id).find(params[:id])
rescue ActiveRecord::RecordNotFound => ex
raise ex, l(:todo_not_found_error)
end

if @todo
respond_to do |format|
format.html { render :template => 'todos/show'}
#format.js { render :template => 'todos/show' }
end
else
flash.now[:error] = @todo.errors.collect{|k,m| m}.join
respond_to do |format|
format.html { redirect_to :action => 'index' }
#format.js { render :action => 'edit' }
end
end
end

def toggle_complete
@todo = Todo.for_user(User.current.id).find(params[:id])
@todo.set_done !@todo.done
if (request.xhr?)
@element_html = render_to_string :partial => 'todos/todo',
:locals => {:todo => @todo, :editable => true}
render :template => 'todos/todo.rjs'
else
redirect_to :action => "index", :project_id => params[:project_id]
end
end

def sort

@todos = Todo.for_user(User.current)
protected
def parent_object
todoable = User.current #you can only ever view your own mytodos.
raise ActiveRecord::RecordNotFound, "TODO association not FOUND! " if !todoable

params.keys.select{|k| k.include? TodosController::UL_ID }.each do |key|
Todo.sort_todos(@todos,params[key])
end

render :nothing => true
#render :template => 'todos/sort.rjs'
return todoable
end

def edit
if request.post?
@todo = Todo.for_user(User.current).find(params[:id])
if @todo.update_attributes(:text => params[:text])
respond_to do |format|
format.html { redirect_to :controller => 'mytodos', :action => 'index' }
format.js { render :action => 'update' }
end
else
flash.now[:error] = @todo.errors.collect{|k,m| m}.join
respond_to do |format|
format.html { redirect_to :action => 'index' }
format.js { render :action => 'edit' }
end
end
end
end

private
#override the usual authenitcation to something more appropriate for global, personal todos.
def authorize
action = {:controller => params[:controller], :action => params[:action]}
allowed = User.current.allowed_to?(action, project = nil, options={:global => true})
allowed ? true : deny_access
end

def set_user
@user = parent_object
end


end
Loading

0 comments on commit 0e159d7

Please sign in to comment.