diff options
author | Felipe Artur <felipefac@gmail.com> | 2016-07-26 18:21:20 -0300 |
---|---|---|
committer | Felipe Artur <felipefac@gmail.com> | 2016-08-19 16:14:20 -0300 |
commit | 37bf35f0bcba28e271789542fb8c81a6c77236b6 (patch) | |
tree | aa10aa7fbff70b17f9978cbe4aced667197062d9 /app/models/todo.rb | |
parent | 415159c28da1aec00bb383d46aad67a9de75faae (diff) | |
download | gitlab-ce-37bf35f0bcba28e271789542fb8c81a6c77236b6.tar.gz |
Todos sorting dropdownissue_18135
Diffstat (limited to 'app/models/todo.rb')
-rw-r--r-- | app/models/todo.rb | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/app/models/todo.rb b/app/models/todo.rb index 8d7a5965aa1..6ae9956ade5 100644 --- a/app/models/todo.rb +++ b/app/models/todo.rb @@ -1,4 +1,6 @@ class Todo < ActiveRecord::Base + include Sortable + ASSIGNED = 1 MENTIONED = 2 BUILD_FAILED = 3 @@ -41,6 +43,23 @@ class Todo < ActiveRecord::Base 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 + highest_priority = highest_label_priority(["Issue", "MergeRequest"], "todos.target_id").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 |