Sort Legislation Processes by descending start date

This commit is contained in:
Julian Herrero
2019-01-17 18:05:29 +01:00
parent 858faa481c
commit 33d6f6c18d
5 changed files with 29 additions and 6 deletions

View File

@@ -6,7 +6,8 @@ class Admin::Legislation::ProcessesController < Admin::Legislation::BaseControll
load_and_authorize_resource :process, class: "Legislation::Process"
def index
@processes = ::Legislation::Process.send(@current_filter).order('id DESC').page(params[:page])
@processes = ::Legislation::Process.send(@current_filter).order(start_date: :desc)
.page(params[:page])
end
def create

View File

@@ -9,7 +9,7 @@ class Legislation::ProcessesController < Legislation::BaseController
def index
@current_filter ||= 'open'
@processes = ::Legislation::Process.send(@current_filter).published
.not_in_draft.page(params[:page])
.not_in_draft.order(start_date: :desc).page(params[:page])
end
def show

View File

@@ -44,10 +44,9 @@ class Legislation::Process < ActiveRecord::Base
validates :proposals_phase_end_date, presence: true, if: :proposals_phase_start_date?
validate :valid_date_ranges
scope :open, -> { where("start_date <= ? and end_date >= ?", Date.current, Date.current)
.order('id DESC') }
scope :next, -> { where("start_date > ?", Date.current).order('id DESC') }
scope :past, -> { where("end_date < ?", Date.current).order('id DESC') }
scope :open, -> { where("start_date <= ? and end_date >= ?", Date.current, Date.current) }
scope :next, -> { where("start_date > ?", Date.current) }
scope :past, -> { where("end_date < ?", Date.current) }
scope :published, -> { where(published: true) }
scope :not_in_draft, -> { where("draft_phase_enabled = false or (draft_start_date IS NOT NULL and