summaryrefslogtreecommitdiff
path: root/app/models/todo.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/todo.rb')
-rw-r--r--app/models/todo.rb54
1 files changed, 50 insertions, 4 deletions
diff --git a/app/models/todo.rb b/app/models/todo.rb
index 2792fa9b9a8..11c072dd000 100644
--- a/app/models/todo.rb
+++ b/app/models/todo.rb
@@ -1,8 +1,19 @@
class Todo < ActiveRecord::Base
- ASSIGNED = 1
- MENTIONED = 2
- BUILD_FAILED = 3
- MARKED = 4
+ include Sortable
+
+ ASSIGNED = 1
+ MENTIONED = 2
+ BUILD_FAILED = 3
+ MARKED = 4
+ APPROVAL_REQUIRED = 5 # This is an EE-only feature
+
+ ACTION_NAMES = {
+ ASSIGNED => :assigned,
+ MENTIONED => :mentioned,
+ BUILD_FAILED => :build_failed,
+ MARKED => :marked,
+ APPROVAL_REQUIRED => :approval_required
+ }
belongs_to :author, class_name: "User"
belongs_to :note
@@ -30,10 +41,39 @@ class Todo < ActiveRecord::Base
state :done
end
+ after_save :keep_around_commit
+
+ class << self
+ def sort(method)
+ method == "priority" ? order_by_labels_priority : order_by(method)
+ end
+
+ # Order by priority depending on which issue/merge request the Todo belongs to
+ # Todos with highest priority first then oldest todos
+ # Need to order by created_at last because of differences on Mysql and Postgres when joining by type "Merge_request/Issue"
+ def order_by_labels_priority
+ params = {
+ target_type: ['Issue', 'MergeRequest'],
+ target_column: "todos.target_id",
+ project_column: "todos.project_id"
+ }
+
+ highest_priority = highest_label_priority(params).to_sql
+
+ select("#{table_name}.*, (#{highest_priority}) AS highest_priority").
+ order(Gitlab::Database.nulls_last_order('highest_priority', 'ASC')).
+ order('todos.created_at')
+ end
+ end
+
def build_failed?
action == BUILD_FAILED
end
+ def action_name
+ ACTION_NAMES[action]
+ end
+
def body
if note.present?
note.note
@@ -62,4 +102,10 @@ class Todo < ActiveRecord::Base
target.to_reference
end
end
+
+ private
+
+ def keep_around_commit
+ project.repository.keep_around(self.commit_id)
+ end
end