mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-17 07:40:12 +01:00
first pass at restoring tag functionality
This commit is contained in:
parent
c0dbabf226
commit
c618d35d3a
8 changed files with 1943 additions and 1942 deletions
|
|
@ -175,7 +175,7 @@ class ApplicationController < ActionController::Base
|
|||
|
||||
saved = todo.save
|
||||
if saved
|
||||
todo.tag_with(rt.tag_list, current_user)
|
||||
todo.tag_with(rt.tag_list)
|
||||
todo.tags.reload
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ class RecurringTodosController < ApplicationController
|
|||
end
|
||||
|
||||
def update
|
||||
@recurring_todo.tag_with(params[:tag_list], current_user) if params[:tag_list]
|
||||
@recurring_todo.tag_with(params[:tag_list]) if params[:tag_list]
|
||||
@original_item_context_id = @recurring_todo.context_id
|
||||
@original_item_project_id = @recurring_todo.project_id
|
||||
|
||||
|
|
@ -106,7 +106,7 @@ class RecurringTodosController < ApplicationController
|
|||
|
||||
@recurring_saved = @recurring_todo.save
|
||||
unless (@recurring_saved == false) || p.tag_list.blank?
|
||||
@recurring_todo.tag_with(p.tag_list, current_user)
|
||||
@recurring_todo.tag_with(p.tag_list)
|
||||
@recurring_todo.tags.reload
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ class TodosController < ApplicationController
|
|||
|
||||
@saved = @todo.save
|
||||
unless (@saved == false) || p.tag_list.blank?
|
||||
@todo.tag_with(p.tag_list, current_user)
|
||||
@todo.tag_with(p.tag_list)
|
||||
@todo.tags.reload
|
||||
end
|
||||
|
||||
|
|
@ -175,7 +175,7 @@ class TodosController < ApplicationController
|
|||
def update
|
||||
@source_view = params['_source_view'] || 'todo'
|
||||
init_data_for_sidebar unless mobile?
|
||||
@todo.tag_with(params[:tag_list], current_user) if params[:tag_list]
|
||||
@todo.tag_with(params[:tag_list]) if params[:tag_list]
|
||||
@original_item_context_id = @todo.context_id
|
||||
@original_item_project_id = @todo.project_id
|
||||
@original_item_was_deferred = @todo.deferred?
|
||||
|
|
|
|||
|
|
@ -623,10 +623,10 @@ class RecurringTodo < ActiveRecord::Base
|
|||
|
||||
def toggle_star!
|
||||
if starred?
|
||||
delete_tags Todo::STARRED_TAG_NAME
|
||||
_remove_tags Todo::STARRED_TAG_NAME
|
||||
tags.reload
|
||||
else
|
||||
add_tag Todo::STARRED_TAG_NAME
|
||||
_add_tags(Todo::STARRED_TAG_NAME)
|
||||
tags.reload
|
||||
end
|
||||
starred?
|
||||
|
|
|
|||
|
|
@ -118,10 +118,10 @@ class Todo < ActiveRecord::Base
|
|||
|
||||
def toggle_star!
|
||||
if starred?
|
||||
delete_tags STARRED_TAG_NAME
|
||||
_remove_tags STARRED_TAG_NAME
|
||||
tags.reload
|
||||
else
|
||||
add_tag STARRED_TAG_NAME
|
||||
_add_tags(STARRED_TAG_NAME)
|
||||
tags.reload
|
||||
end
|
||||
starred?
|
||||
|
|
|
|||
|
|
@ -7,11 +7,11 @@ class ActiveRecord::Base #:nodoc:
|
|||
# Add tags to <tt>self</tt>. Accepts a string of tagnames, an array of tagnames, an array of ids, or an array of Tags.
|
||||
#
|
||||
# We need to avoid name conflicts with the built-in ActiveRecord association methods, thus the underscores.
|
||||
def _add_tags incoming, user
|
||||
def _add_tags incoming
|
||||
taggable?(true)
|
||||
tag_cast_to_string(incoming).each do |tag_name|
|
||||
begin
|
||||
tag = Tag.find_or_create_by_name(tag_name).on(self,user)
|
||||
tag = Tag.find_or_create_by_name(tag_name)
|
||||
raise Tag::Error, "tag could not be saved: #{tag_name}" if tag.new_record?
|
||||
tag.taggables << self
|
||||
rescue ActiveRecord::StatementInvalid => e
|
||||
|
|
@ -21,7 +21,7 @@ class ActiveRecord::Base #:nodoc:
|
|||
end
|
||||
|
||||
# Removes tags from <tt>self</tt>. Accepts a string of tagnames, an array of tagnames, an array of ids, or an array of Tags.
|
||||
def _remove_tags outgoing, user
|
||||
def _remove_tags outgoing
|
||||
taggable?(true)
|
||||
outgoing = tag_cast_to_string(outgoing)
|
||||
|
||||
|
|
@ -36,7 +36,7 @@ class ActiveRecord::Base #:nodoc:
|
|||
end
|
||||
|
||||
# Replace the existing tags on <tt>self</tt>. Accepts a string of tagnames, an array of tagnames, an array of ids, or an array of Tags.
|
||||
def tag_with list, user
|
||||
def tag_with list
|
||||
#:stopdoc:
|
||||
taggable?(true)
|
||||
list = tag_cast_to_string(list)
|
||||
|
|
@ -44,8 +44,8 @@ class ActiveRecord::Base #:nodoc:
|
|||
# Transactions may not be ideal for you here; be aware.
|
||||
Tag.transaction do
|
||||
current = tags.map(&:name)
|
||||
_add_tags(list - current, user)
|
||||
_remove_tags(current - list, user)
|
||||
_add_tags(list - current)
|
||||
_remove_tags(current - list)
|
||||
end
|
||||
|
||||
self
|
||||
|
|
@ -78,6 +78,7 @@ class ActiveRecord::Base #:nodoc:
|
|||
when String
|
||||
obj = obj.split(Tag::DELIMITER).map do |tag_name|
|
||||
tag_name.strip.squeeze(" ")
|
||||
puts "tn=#{tag_name.strip.squeeze(" ")}"
|
||||
end
|
||||
else
|
||||
raise "Invalid object of class #{obj.class} as tagging method parameter"
|
||||
|
|
|
|||
|
|
@ -251,7 +251,7 @@ class RecurringTodoTest < Test::Rails::TestCase
|
|||
end
|
||||
|
||||
def test_starred
|
||||
@yearly.tag_with("1, 2, starred", User.find(@yearly.user_id))
|
||||
@yearly.tag_with("1, 2, starred")
|
||||
@yearly.tags.reload
|
||||
|
||||
assert_equal true, @yearly.starred?
|
||||
|
|
|
|||
|
|
@ -163,7 +163,7 @@ class TodoTest < Test::Rails::TestCase
|
|||
end
|
||||
|
||||
def test_todo_is_starred_after_starred_tag_is_added
|
||||
@not_completed1.add_tag('starred')
|
||||
@not_completed1._add_tags('starred')
|
||||
assert @not_completed1.starred?
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue