mirror of
https://github.com/TracksApp/tracks.git
synced 2026-03-06 12:50:19 +01:00
Merge pull request #193 from mattdbridges/extract-rich-message
Extract behavior from Todo.from_rich_message
This commit is contained in:
commit
c28ffd6763
7 changed files with 155 additions and 54 deletions
|
|
@ -23,7 +23,8 @@ class MessageGateway < ActionMailer::Base
|
|||
end
|
||||
end
|
||||
|
||||
todo = Todo.from_rich_message(user, context.id, description, notes)
|
||||
todo_builder = TodoFromRichMessage.new(user, context.id, description, notes)
|
||||
todo = todo_builder.construct
|
||||
todo.save!
|
||||
Rails.logger.info "Saved email as todo for user #{user.login} in context #{context.name}"
|
||||
end
|
||||
|
|
|
|||
|
|
@ -381,48 +381,6 @@ class Todo < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
# Rich Todo API
|
||||
def self.from_rich_message(user, default_context_id, description, notes)
|
||||
fields = description.match(/([^>@]*)@?([^>]*)>?(.*)/)
|
||||
description = fields[1].strip
|
||||
context = fields[2].strip
|
||||
project = fields[3].strip
|
||||
|
||||
context = nil if context == ""
|
||||
project = nil if project == ""
|
||||
|
||||
context_id = default_context_id
|
||||
unless(context.nil?)
|
||||
found_context = user.contexts.active.where("name like ?", "%#{context}%").first
|
||||
found_context = user.contexts.where("name like ?", "%#{context}%").first if !found_context
|
||||
context_id = found_context.id if found_context
|
||||
end
|
||||
|
||||
unless user.contexts.exists? context_id
|
||||
raise(CannotAccessContext, "Cannot access a context that does not belong to this user.")
|
||||
end
|
||||
|
||||
project_id = nil
|
||||
unless(project.blank?)
|
||||
if(project[0..3].downcase == "new:")
|
||||
found_project = user.projects.build
|
||||
found_project.name = project[4..255+4].strip
|
||||
found_project.save!
|
||||
else
|
||||
found_project = user.projects.active.find_by_namepart(project)
|
||||
found_project = user.projects.find_by_namepart(project) if found_project.nil?
|
||||
end
|
||||
project_id = found_project.id unless found_project.nil?
|
||||
end
|
||||
|
||||
todo = user.todos.build
|
||||
todo.description = description
|
||||
todo.raw_notes = notes
|
||||
todo.context_id = context_id
|
||||
todo.project_id = project_id unless project_id.nil?
|
||||
return todo
|
||||
end
|
||||
|
||||
def render_note
|
||||
unless self.notes.nil?
|
||||
self.rendered_notes = Tracks::Utils.render_text(self.notes)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue