From 36fcfe5c59f8dbf2665eed2679bdad60e9a37999 Mon Sep 17 00:00:00 2001 From: bsag Date: Sun, 14 Jan 2007 19:29:01 +0000 Subject: [PATCH] Support for tagging of actions! Made a start on tagging support. You can add tags via the action forms (just single word tags, separated by a space so far), update tags via the edit form (same limitations), and also search for all actions with a particular tag: /todo/tag/[tag_name] Tests for tagging are a bit rudimentary at the moment, and you can't as yet use tags consisting of multiple words, or search for conjunctions of tags (e.g. foo+bar), but I'm hoping to add these. Also no validation, so don't try anything funny! I'm also planning on letting the user create custom links to /todo/tag pages, so that you can use a tag for inbox, someday/maybe, today, a meta-project, priority, or whatever you like. git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@400 a4c988fc-2ded-0310-b66e-134b36920a42 --- tracks/app/controllers/todo_controller.rb | 18 ++++++ tracks/app/models/todo.rb | 1 + tracks/app/models/user.rb | 2 + .../app/views/shared/_add_new_item_form.rhtml | 9 ++- tracks/app/views/todo/_edit_form.rhtml | 4 ++ tracks/app/views/todo/_item.rhtml | 15 +++++ tracks/app/views/todo/tag.rhtml | 22 +++++++ tracks/db/migrate/024_add_tag_support.rb | 23 ++++++++ tracks/db/schema.rb | 45 +++++++++----- tracks/public/stylesheets/standard.css | 24 +++++++- tracks/test/fixtures/taggings.yml | 22 +++++++ tracks/test/fixtures/tags.yml | 17 ++++++ .../test/functional/todo_controller_test.rb | 13 +++- .../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 + 19 files changed, 317 insertions(+), 20 deletions(-) create mode 100644 tracks/app/views/todo/tag.rhtml create mode 100644 tracks/db/migrate/024_add_tag_support.rb create mode 100644 tracks/test/fixtures/taggings.yml create mode 100644 tracks/test/fixtures/tags.yml create mode 100644 tracks/vendor/plugins/acts_as_taggable/init.rb create mode 100644 tracks/vendor/plugins/acts_as_taggable/lib/README create mode 100644 tracks/vendor/plugins/acts_as_taggable/lib/acts_as_taggable.rb create mode 100644 tracks/vendor/plugins/acts_as_taggable/lib/tag.rb create mode 100644 tracks/vendor/plugins/acts_as_taggable/lib/tagging.rb create mode 100644 tracks/vendor/plugins/acts_as_taggable/test/acts_as_taggable_test.rb diff --git a/tracks/app/controllers/todo_controller.rb b/tracks/app/controllers/todo_controller.rb index af6eecd1..d87db7d6 100644 --- a/tracks/app/controllers/todo_controller.rb +++ b/tracks/app/controllers/todo_controller.rb @@ -33,6 +33,7 @@ class TodoController < 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' @@ -69,6 +70,7 @@ class TodoController < ApplicationController @item.show_from = parse_date_per_user_prefs(p['todo']['show_from']) end + @item.tag_with(params[:tag_list], @user) @saved = @item.save respond_to do |wants| @@ -124,6 +126,7 @@ class TodoController < ApplicationController def update @item = check_user_return_item + @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? @@ -159,6 +162,8 @@ class TodoController < ApplicationController params['item']['show_from'] = parse_date_per_user_prefs(params['item']['show_from']) end + + @saved = @item.update_attributes params["item"] @context_changed = @original_item_context_id != @item.context_id @item_was_activated_from_deferred_state = @original_item_was_deferred && @item.active? @@ -234,6 +239,19 @@ class TodoController < ApplicationController end end + # /todo/tag/[tag_name] shows all the actions tagged with tag_name + # + def tag + @tag = tag_name = params[:id] + if Tag.find_by_name(tag_name) + @todos = Todo.find_tagged_with(tag_name, @user) + else + @todos = [] + end + + @count = @todos.size unless @todos.empty? + end + private def check_user_return_item diff --git a/tracks/app/models/todo.rb b/tracks/app/models/todo.rb index e11c3807..9e525edb 100644 --- a/tracks/app/models/todo.rb +++ b/tracks/app/models/todo.rb @@ -5,6 +5,7 @@ class Todo < ActiveRecord::Base 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 } diff --git a/tracks/app/models/user.rb b/tracks/app/models/user.rb index 98717aa4..8a0f5d93 100644 --- a/tracks/app/models/user.rb +++ b/tracks/app/models/user.rb @@ -33,6 +33,8 @@ class User < ActiveRecord::Base end has_many :notes, :order => "created_at DESC", :dependent => :delete_all has_one :preference, :dependent => :destroy + has_many :taggings + has_many :tags, :through => :taggings, :select => "DISTINCT tags.*" attr_protected :is_admin diff --git a/tracks/app/views/shared/_add_new_item_form.rhtml b/tracks/app/views/shared/_add_new_item_form.rhtml index a1da6b83..30c58da4 100644 --- a/tracks/app/views/shared/_add_new_item_form.rhtml +++ b/tracks/app/views/shared/_add_new_item_form.rhtml @@ -43,14 +43,17 @@ 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("todo", "due", "size" => 10, "class" => "Date", "onfocus" => "Calendar.setup", "tabindex" => 5, "autocomplete" => "off") %> +<%= text_field("todo", "due", "size" => 10, "class" => "Date", "onfocus" => "Calendar.setup", "tabindex" => 6, "autocomplete" => "off") %> - <%= text_field("todo", "show_from", "size" => 10, "class" => "Date", "onfocus" => "Calendar.setup", "tabindex" => 6, "autocomplete" => "off") %> + <%= text_field("todo", "show_from", "size" => 10, "class" => "Date", "onfocus" => "Calendar.setup", "tabindex" => 7, "autocomplete" => "off") %> <%= source_view_tag( @source_view ) %> -
+
<% end -%> diff --git a/tracks/app/views/todo/_edit_form.rhtml b/tracks/app/views/todo/_edit_form.rhtml index 632ab413..90bb49e6 100644 --- a/tracks/app/views/todo/_edit_form.rhtml +++ b/tracks/app/views/todo/_edit_form.rhtml @@ -34,6 +34,10 @@ Event.observe($('<%= dom_id(@item, 'project_name') %>'), "click", editFormProjectAutoCompleter.activate.bind(editFormProjectAutoCompleter)); + + + <%= text_field_tag "tag_list", @item.tags.collect{|t| t.name}.join(" "), :size => 40 %> +