From d0666038f2d2b91e8f88eabeac3bd0aab010d628 Mon Sep 17 00:00:00 2001 From: bsag Date: Sun, 4 Feb 2007 15:33:24 +0000 Subject: [PATCH] Removed acts_as_taggable because it is deprecated and replaced with has_many_polymorphs: Also removed chronic because it is not currently used. * Tags are entered separated by commas, so tags with spaces are allowed * When you edit an action, whatever is submitted in the tags text field replaces existing tags: if you submit an empty field, tags are removed from the action * Clicking on a tag shows a page listing all the actions with that tag (/todo/tag/tag+name) Todo: * Tests * RESTful routes for Tags (if it makes sense for tags - I haven't decided) * If you remove tags for an action, it removes the entries from the Taggings table, but it can leave an orphan Tag if there are no more Taggings for that Tag. One problem is that another user might have an identically-named Tag, so we don't want to remove their Tag, just because we have finished with it. I'm not sure how to arrange this yet. Don't forget to rake db:migrate. There is also a change in config/environment.rb.tmpl, so remember to copy the changes to your copy. git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@425 a4c988fc-2ded-0310-b66e-134b36920a42 --- tracks/app/controllers/application.rb | 1 + tracks/app/controllers/todos_controller.rb | 14 +- tracks/app/models/tag.rb | 11 + tracks/app/models/tagging.rb | 11 + tracks/app/models/todo.rb | 5 +- .../app/views/shared/_add_new_item_form.rhtml | 4 +- tracks/app/views/todos/_edit_form.rhtml | 4 +- tracks/app/views/todos/_item.rhtml | 3 +- tracks/config/environment.rb.tmpl | 1 + tracks/db/schema.rb | 28 +- .../lib/activerecord_base_tag_extensions.rb | 26 + tracks/test/unit/tag_test.rb | 10 + tracks/test/unit/tagging_test.rb | 10 + .../vendor/plugins/acts_as_taggable/init.rb | 5 - .../plugins/acts_as_taggable/lib/README | 4 - .../acts_as_taggable/lib/acts_as_taggable.rb | 59 -- .../plugins/acts_as_taggable/lib/tag.rb | 40 -- .../plugins/acts_as_taggable/lib/tagging.rb | 13 - .../test/acts_as_taggable_test.rb | 1 - tracks/vendor/plugins/chronic/README | 119 ---- tracks/vendor/plugins/chronic/init.rb | 5 - tracks/vendor/plugins/chronic/lib/chronic.rb | 41 -- .../plugins/chronic/lib/chronic/chronic.rb | 242 -------- .../plugins/chronic/lib/chronic/grabber.rb | 26 - .../plugins/chronic/lib/chronic/handlers.rb | 403 ------------ .../plugins/chronic/lib/chronic/ordinal.rb | 40 -- .../plugins/chronic/lib/chronic/pointer.rb | 27 - .../plugins/chronic/lib/chronic/repeater.rb | 114 ---- .../lib/chronic/repeaters/repeater_day.rb | 44 -- .../chronic/repeaters/repeater_day_name.rb | 45 -- .../chronic/repeaters/repeater_day_portion.rb | 93 --- .../chronic/repeaters/repeater_fortnight.rb | 64 -- .../lib/chronic/repeaters/repeater_hour.rb | 52 -- .../lib/chronic/repeaters/repeater_minute.rb | 21 - .../lib/chronic/repeaters/repeater_month.rb | 54 -- .../chronic/repeaters/repeater_month_name.rb | 82 --- .../lib/chronic/repeaters/repeater_season.rb | 23 - .../chronic/repeaters/repeater_season_name.rb | 24 - .../lib/chronic/repeaters/repeater_second.rb | 34 - .../lib/chronic/repeaters/repeater_time.rb | 106 ---- .../lib/chronic/repeaters/repeater_week.rb | 62 -- .../lib/chronic/repeaters/repeater_weekend.rb | 11 - .../lib/chronic/repeaters/repeater_year.rb | 55 -- .../plugins/chronic/lib/chronic/scalar.rb | 74 --- .../plugins/chronic/lib/chronic/separator.rb | 76 --- .../plugins/chronic/test/parse_numbers.rb | 50 -- tracks/vendor/plugins/chronic/test/suite.rb | 9 - .../plugins/chronic/test/test_Chronic.rb | 50 -- .../plugins/chronic/test/test_Handler.rb | 110 ---- .../chronic/test/test_RepeaterDayName.rb | 52 -- .../chronic/test/test_RepeaterFortnight.rb | 63 -- .../plugins/chronic/test/test_RepeaterHour.rb | 65 -- .../chronic/test/test_RepeaterMonth.rb | 47 -- .../chronic/test/test_RepeaterMonthName.rb | 57 -- .../plugins/chronic/test/test_RepeaterTime.rb | 72 --- .../plugins/chronic/test/test_RepeaterWeek.rb | 63 -- .../plugins/chronic/test/test_RepeaterYear.rb | 63 -- .../vendor/plugins/chronic/test/test_Span.rb | 24 - .../vendor/plugins/chronic/test/test_Token.rb | 26 - .../plugins/chronic/test/test_parsing.rb | 478 -------------- .../plugins/has_many_polymorphs/LICENSE | 184 ++++++ .../vendor/plugins/has_many_polymorphs/README | 46 ++ .../plugins/has_many_polymorphs/init.rb | 1 + .../lib/has_many_polymorphs.rb | 581 ++++++++++++++++++ .../test/fixtures/aquatic/fish.yml | 8 + .../fixtures/aquatic/little_whale_pupils.yml | 0 .../test/fixtures/aquatic/whales.yml | 3 + .../test/fixtures/bow_wows.yml | 6 + .../test/fixtures/cats.yml | 8 + .../test/fixtures/eaters_foodstuffs.yml | 0 .../test/fixtures/frogs.yml | 3 + .../test/fixtures/keep_your_enemies_close.yml | 0 .../test/fixtures/petfoods.yml | 6 + .../test/fixtures/wild_boars.yml | 6 + .../test/models/aquatic/fish.rb | 4 + .../test/models/aquatic/pupils_whale.rb | 7 + .../test/models/aquatic/whale.rb | 11 + .../models/beautiful_fight_relationship.rb | 13 + .../has_many_polymorphs/test/models/cat.rb | 5 + .../has_many_polymorphs/test/models/dog.rb | 16 + .../test/models/eaters_foodstuff.rb | 10 + .../has_many_polymorphs/test/models/frog.rb | 4 + .../has_many_polymorphs/test/models/kitten.rb | 3 + .../test/models/petfood.rb | 21 + .../has_many_polymorphs/test/models/tabby.rb | 2 + .../test/models/wild_boar.rb | 3 + .../has_many_polymorphs/test/schema.rb | 52 ++ .../has_many_polymorphs/test/test_helper.rb | 23 + .../test/unit/polymorph_test.rb | 487 +++++++++++++++ 89 files changed, 1612 insertions(+), 3317 deletions(-) create mode 100644 tracks/app/models/tag.rb create mode 100644 tracks/app/models/tagging.rb create mode 100644 tracks/lib/activerecord_base_tag_extensions.rb create mode 100644 tracks/test/unit/tag_test.rb create mode 100644 tracks/test/unit/tagging_test.rb delete mode 100644 tracks/vendor/plugins/acts_as_taggable/init.rb delete mode 100644 tracks/vendor/plugins/acts_as_taggable/lib/README delete mode 100644 tracks/vendor/plugins/acts_as_taggable/lib/acts_as_taggable.rb delete mode 100644 tracks/vendor/plugins/acts_as_taggable/lib/tag.rb delete mode 100644 tracks/vendor/plugins/acts_as_taggable/lib/tagging.rb delete mode 100644 tracks/vendor/plugins/acts_as_taggable/test/acts_as_taggable_test.rb delete mode 100644 tracks/vendor/plugins/chronic/README delete mode 100644 tracks/vendor/plugins/chronic/init.rb delete mode 100644 tracks/vendor/plugins/chronic/lib/chronic.rb delete mode 100644 tracks/vendor/plugins/chronic/lib/chronic/chronic.rb delete mode 100644 tracks/vendor/plugins/chronic/lib/chronic/grabber.rb delete mode 100644 tracks/vendor/plugins/chronic/lib/chronic/handlers.rb delete mode 100644 tracks/vendor/plugins/chronic/lib/chronic/ordinal.rb delete mode 100644 tracks/vendor/plugins/chronic/lib/chronic/pointer.rb delete mode 100644 tracks/vendor/plugins/chronic/lib/chronic/repeater.rb delete mode 100644 tracks/vendor/plugins/chronic/lib/chronic/repeaters/repeater_day.rb delete mode 100644 tracks/vendor/plugins/chronic/lib/chronic/repeaters/repeater_day_name.rb delete mode 100644 tracks/vendor/plugins/chronic/lib/chronic/repeaters/repeater_day_portion.rb delete mode 100644 tracks/vendor/plugins/chronic/lib/chronic/repeaters/repeater_fortnight.rb delete mode 100644 tracks/vendor/plugins/chronic/lib/chronic/repeaters/repeater_hour.rb delete mode 100644 tracks/vendor/plugins/chronic/lib/chronic/repeaters/repeater_minute.rb delete mode 100644 tracks/vendor/plugins/chronic/lib/chronic/repeaters/repeater_month.rb delete mode 100644 tracks/vendor/plugins/chronic/lib/chronic/repeaters/repeater_month_name.rb delete mode 100644 tracks/vendor/plugins/chronic/lib/chronic/repeaters/repeater_season.rb delete mode 100644 tracks/vendor/plugins/chronic/lib/chronic/repeaters/repeater_season_name.rb delete mode 100644 tracks/vendor/plugins/chronic/lib/chronic/repeaters/repeater_second.rb delete mode 100644 tracks/vendor/plugins/chronic/lib/chronic/repeaters/repeater_time.rb delete mode 100644 tracks/vendor/plugins/chronic/lib/chronic/repeaters/repeater_week.rb delete mode 100644 tracks/vendor/plugins/chronic/lib/chronic/repeaters/repeater_weekend.rb delete mode 100644 tracks/vendor/plugins/chronic/lib/chronic/repeaters/repeater_year.rb delete mode 100644 tracks/vendor/plugins/chronic/lib/chronic/scalar.rb delete mode 100644 tracks/vendor/plugins/chronic/lib/chronic/separator.rb delete mode 100644 tracks/vendor/plugins/chronic/test/parse_numbers.rb delete mode 100644 tracks/vendor/plugins/chronic/test/suite.rb delete mode 100644 tracks/vendor/plugins/chronic/test/test_Chronic.rb delete mode 100644 tracks/vendor/plugins/chronic/test/test_Handler.rb delete mode 100644 tracks/vendor/plugins/chronic/test/test_RepeaterDayName.rb delete mode 100644 tracks/vendor/plugins/chronic/test/test_RepeaterFortnight.rb delete mode 100644 tracks/vendor/plugins/chronic/test/test_RepeaterHour.rb delete mode 100644 tracks/vendor/plugins/chronic/test/test_RepeaterMonth.rb delete mode 100644 tracks/vendor/plugins/chronic/test/test_RepeaterMonthName.rb delete mode 100644 tracks/vendor/plugins/chronic/test/test_RepeaterTime.rb delete mode 100644 tracks/vendor/plugins/chronic/test/test_RepeaterWeek.rb delete mode 100644 tracks/vendor/plugins/chronic/test/test_RepeaterYear.rb delete mode 100644 tracks/vendor/plugins/chronic/test/test_Span.rb delete mode 100644 tracks/vendor/plugins/chronic/test/test_Token.rb delete mode 100644 tracks/vendor/plugins/chronic/test/test_parsing.rb create mode 100644 tracks/vendor/plugins/has_many_polymorphs/LICENSE create mode 100644 tracks/vendor/plugins/has_many_polymorphs/README create mode 100644 tracks/vendor/plugins/has_many_polymorphs/init.rb create mode 100644 tracks/vendor/plugins/has_many_polymorphs/lib/has_many_polymorphs.rb create mode 100644 tracks/vendor/plugins/has_many_polymorphs/test/fixtures/aquatic/fish.yml create mode 100644 tracks/vendor/plugins/has_many_polymorphs/test/fixtures/aquatic/little_whale_pupils.yml create mode 100644 tracks/vendor/plugins/has_many_polymorphs/test/fixtures/aquatic/whales.yml create mode 100644 tracks/vendor/plugins/has_many_polymorphs/test/fixtures/bow_wows.yml create mode 100644 tracks/vendor/plugins/has_many_polymorphs/test/fixtures/cats.yml create mode 100644 tracks/vendor/plugins/has_many_polymorphs/test/fixtures/eaters_foodstuffs.yml create mode 100644 tracks/vendor/plugins/has_many_polymorphs/test/fixtures/frogs.yml create mode 100644 tracks/vendor/plugins/has_many_polymorphs/test/fixtures/keep_your_enemies_close.yml create mode 100644 tracks/vendor/plugins/has_many_polymorphs/test/fixtures/petfoods.yml create mode 100644 tracks/vendor/plugins/has_many_polymorphs/test/fixtures/wild_boars.yml create mode 100644 tracks/vendor/plugins/has_many_polymorphs/test/models/aquatic/fish.rb create mode 100644 tracks/vendor/plugins/has_many_polymorphs/test/models/aquatic/pupils_whale.rb create mode 100644 tracks/vendor/plugins/has_many_polymorphs/test/models/aquatic/whale.rb create mode 100644 tracks/vendor/plugins/has_many_polymorphs/test/models/beautiful_fight_relationship.rb create mode 100644 tracks/vendor/plugins/has_many_polymorphs/test/models/cat.rb create mode 100644 tracks/vendor/plugins/has_many_polymorphs/test/models/dog.rb create mode 100644 tracks/vendor/plugins/has_many_polymorphs/test/models/eaters_foodstuff.rb create mode 100644 tracks/vendor/plugins/has_many_polymorphs/test/models/frog.rb create mode 100644 tracks/vendor/plugins/has_many_polymorphs/test/models/kitten.rb create mode 100644 tracks/vendor/plugins/has_many_polymorphs/test/models/petfood.rb create mode 100644 tracks/vendor/plugins/has_many_polymorphs/test/models/tabby.rb create mode 100644 tracks/vendor/plugins/has_many_polymorphs/test/models/wild_boar.rb create mode 100644 tracks/vendor/plugins/has_many_polymorphs/test/schema.rb create mode 100644 tracks/vendor/plugins/has_many_polymorphs/test/test_helper.rb create mode 100644 tracks/vendor/plugins/has_many_polymorphs/test/unit/polymorph_test.rb 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 %>