summaryrefslogtreecommitdiff
path: root/app/models/todo.rb
diff options
context:
space:
mode:
authorDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-02-20 11:59:59 -0200
committerDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-02-20 12:39:27 -0200
commit3d52e139b13ad077286f2f9f46b7e98f43ad9564 (patch)
tree22c70561b0f64851d938e44661aafeed3a2c80b2 /app/models/todo.rb
parent408e010d65e7e2e2b64a694e12d44636d7d81dec (diff)
downloadgitlab-ce-3d52e139b13ad077286f2f9f46b7e98f43ad9564.tar.gz
Rename Tasks to Todos
Diffstat (limited to 'app/models/todo.rb')
-rw-r--r--app/models/todo.rb64
1 files changed, 64 insertions, 0 deletions
diff --git a/app/models/todo.rb b/app/models/todo.rb
new file mode 100644
index 00000000000..7a9b0212f9f
--- /dev/null
+++ b/app/models/todo.rb
@@ -0,0 +1,64 @@
+# == Schema Information
+#
+# Table name: todos
+#
+# id :integer not null, primary key
+# user_id :integer not null
+# project_id :integer not null
+# target_id :integer not null
+# target_type :string not null
+# author_id :integer
+# note_id :integer
+# action :integer not null
+# state :string not null
+# created_at :datetime
+# updated_at :datetime
+#
+
+class Todo < ActiveRecord::Base
+ ASSIGNED = 1
+ MENTIONED = 2
+
+ belongs_to :author, class_name: "User"
+ belongs_to :note
+ belongs_to :project
+ belongs_to :target, polymorphic: true, touch: true
+ belongs_to :user
+
+ delegate :name, :email, to: :author, prefix: true, allow_nil: true
+
+ validates :action, :project, :target, :user, presence: true
+
+ default_scope { reorder(id: :desc) }
+
+ scope :pending, -> { with_state(:pending) }
+ scope :done, -> { with_state(:done) }
+
+ state_machine :state, initial: :pending do
+ event :done do
+ transition pending: :done
+ end
+
+ state :pending
+ state :done
+ end
+
+ def action_name
+ case action
+ when ASSIGNED then 'assigned'
+ when MENTIONED then 'mentioned you on'
+ end
+ end
+
+ def body
+ if note.present?
+ note.note
+ else
+ target.title
+ end
+ end
+
+ def target_iid
+ target.respond_to?(:iid) ? target.iid : target_id
+ end
+end