summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
Diffstat (limited to 'app/models')
-rw-r--r--app/models/concerns/sortable.rb4
-rw-r--r--app/models/issue.rb12
2 files changed, 12 insertions, 4 deletions
diff --git a/app/models/concerns/sortable.rb b/app/models/concerns/sortable.rb
index 42617ecbb96..8b47b9e0abd 100644
--- a/app/models/concerns/sortable.rb
+++ b/app/models/concerns/sortable.rb
@@ -18,8 +18,6 @@ module Sortable
scope :order_updated_asc, -> { reorder(updated_at: :asc) }
scope :order_name_asc, -> { reorder(name: :asc) }
scope :order_name_desc, -> { reorder(name: :desc) }
- scope :order_due_date_asc, -> { reorder("issues.due_date IS NULL, issues.due_date ASC") }
- scope :order_due_date_desc, -> { reorder("issues.due_date IS NULL, issues.due_date DESC") }
end
module ClassMethods
@@ -33,8 +31,6 @@ module Sortable
when 'created_desc' then order_created_desc
when 'id_desc' then order_id_desc
when 'id_asc' then order_id_asc
- when 'due_date_asc', 'due_date_desc'
- column_names.include?('due_date') ? send("order_#{method}") : all
else
all
end
diff --git a/app/models/issue.rb b/app/models/issue.rb
index d72233006ee..9a382fcda8d 100644
--- a/app/models/issue.rb
+++ b/app/models/issue.rb
@@ -46,6 +46,9 @@ class Issue < ActiveRecord::Base
scope :open_for, ->(user) { opened.assigned_to(user) }
scope :in_projects, ->(project_ids) { where(project_id: project_ids) }
+ scope :order_due_date_asc, -> { reorder('issues.due_date IS NULL, issues.due_date ASC') }
+ scope :order_due_date_desc, -> { reorder('issues.due_date IS NULL, issues.due_date DESC') }
+
state_machine :state, initial: :opened do
event :close do
transition [:reopened, :opened] => :closed
@@ -89,6 +92,15 @@ class Issue < ActiveRecord::Base
@link_reference_pattern ||= super("issues", /(?<issue>\d+)/)
end
+ def self.sort(method)
+ case method.to_s
+ when 'due_date_asc' then order_due_date_asc
+ when 'due_date_desc' then order_due_date_desc
+ else
+ super
+ end
+ end
+
def to_reference(from_project = nil)
reference = "#{self.class.reference_prefix}#{iid}"