diff --git a/tracks/app/controllers/application.rb b/tracks/app/controllers/application.rb index a6635bdb..10715bcd 100644 --- a/tracks/app/controllers/application.rb +++ b/tracks/app/controllers/application.rb @@ -7,6 +7,7 @@ require "redcloth" require 'date' require 'time' +Tag # We need this in development mode, or you get 'method missing' errors class ApplicationController < ActionController::Base diff --git a/tracks/app/controllers/todos_controller.rb b/tracks/app/controllers/todos_controller.rb index c18cd994..d230f26d 100644 --- a/tracks/app/controllers/todos_controller.rb +++ b/tracks/app/controllers/todos_controller.rb @@ -33,7 +33,6 @@ class TodosController < ApplicationController def create @item = @user.todos.build p = params['request'] || params - # @item.tag_with(params[:tag_list]) @item.attributes = p['todo'] if p['todo']['project_id'].blank? && !p['project_name'].blank? && p['project_name'] != 'None' @@ -70,9 +69,11 @@ class TodosController < ApplicationController @item.show_from = parse_date_per_user_prefs(p['todo']['show_from']) end - @item.tag_with(params[:tag_list], @user) + @item.save + @item.tag_with(params[:tag_list],@user) @saved = @item.save + respond_to do |wants| wants.html { redirect_to :action => "index" } wants.js do @@ -126,7 +127,7 @@ class TodosController < ApplicationController def update @item = check_user_return_item - @item.tag_with(params[:tag_list], @user) + @item.tag_with(params[:tag_list],@user) @original_item_context_id = @item.context_id @original_item_project_id = @item.project_id @original_item_was_deferred = @item.deferred? @@ -245,10 +246,11 @@ class TodosController < ApplicationController # def tag @tag = tag_name = params[:name] - if Tag.find_by_name(tag_name) - @todos = Todo.find_tagged_with(tag_name, @user) - else + tag_collection = Tag.find_by_name(tag_name).todos + if tag_collection.empty? @todos = [] + else + @todos = tag_collection.find(:all, :conditions => ['taggings.user_id = ?', @user.id]) end @count = @todos.size unless @todos.empty? diff --git a/tracks/app/models/tag.rb b/tracks/app/models/tag.rb new file mode 100644 index 00000000..009c8f0b --- /dev/null +++ b/tracks/app/models/tag.rb @@ -0,0 +1,11 @@ +class Tag < ActiveRecord::Base + has_many_polymorphs :taggables, + :from => [:todos], + :through => :taggings, + :dependent => :destroy + + def on(taggable, user) + tagging = taggings.create :taggable => taggable, :user => user + end + +end \ No newline at end of file diff --git a/tracks/app/models/tagging.rb b/tracks/app/models/tagging.rb new file mode 100644 index 00000000..16c1d5da --- /dev/null +++ b/tracks/app/models/tagging.rb @@ -0,0 +1,11 @@ +class Tagging < ActiveRecord::Base + belongs_to :tag + belongs_to :taggable, :polymorphic => true + belongs_to :user + + # def before_destroy + # # disallow orphaned tags + # # TODO: this doesn't seem to be working + # tag.destroy if tag.taggings.count < 2 + # end +end diff --git a/tracks/app/models/todo.rb b/tracks/app/models/todo.rb index 9e525edb..204857a7 100644 --- a/tracks/app/models/todo.rb +++ b/tracks/app/models/todo.rb @@ -1,11 +1,10 @@ class Todo < ActiveRecord::Base - require 'validations' + require 'validations' belongs_to :context, :order => 'name' belongs_to :project belongs_to :user - acts_as_taggable acts_as_state_machine :initial => :active, :column => 'state' state :active, :enter => Proc.new { |t| t[:show_from] = nil } @@ -85,5 +84,5 @@ class Todo < ActiveRecord::Base original_set_initial_state end end - + end \ No newline at end of file diff --git a/tracks/app/views/shared/_add_new_item_form.rhtml b/tracks/app/views/shared/_add_new_item_form.rhtml index 0669dc85..e2380e85 100644 --- a/tracks/app/views/shared/_add_new_item_form.rhtml +++ b/tracks/app/views/shared/_add_new_item_form.rhtml @@ -43,8 +43,8 @@ Event.observe($('todo_project_name'), "focus", projectAutoCompleter.activate.bin Event.observe($('todo_project_name'), "click", projectAutoCompleter.activate.bind(projectAutoCompleter)); - -<%= text_field_tag "tag_list", nil, :size => 40, :tabindex => 5 %> + +<%= text_field_tag "tag_list", nil, :size => 40, :tabindex => 5 %> <%= text_field("todo", "due", "size" => 10, "class" => "Date", "onfocus" => "Calendar.setup", "tabindex" => 6, "autocomplete" => "off") %> diff --git a/tracks/app/views/todos/_edit_form.rhtml b/tracks/app/views/todos/_edit_form.rhtml index 90bb49e6..6d493a9a 100644 --- a/tracks/app/views/todos/_edit_form.rhtml +++ b/tracks/app/views/todos/_edit_form.rhtml @@ -35,8 +35,8 @@ - - <%= text_field_tag "tag_list", @item.tags.collect{|t| t.name}.join(" "), :size => 40 %> + + <%= text_field_tag "tag_list", @item.tags.collect{|t| t.name}.join(", "), :size => 40 %>