Browse Source

Order schemes alphabeticlly only

CLDC-2640-location-guidance
Kat 1 year ago
parent
commit
2a8c379743
  1. 2
      app/controllers/organisations_controller.rb
  2. 2
      app/controllers/schemes_controller.rb
  3. 15
      app/models/scheme.rb

2
app/controllers/organisations_controller.rb

@ -23,7 +23,7 @@ class OrganisationsController < ApplicationController
def schemes
all_schemes = Scheme.where(owning_organisation: [@organisation] + @organisation.parent_organisations)
@pagy, @schemes = pagy(filter_manager.filtered_schemes(all_schemes, search_term, session_filters).order_by_completion.order_by_service_name)
@pagy, @schemes = pagy(filter_manager.filtered_schemes(all_schemes, search_term, session_filters).order_by_service_name)
@searched = search_term.presence
@total_count = all_schemes.size
@filter_type = "schemes"

2
app/controllers/schemes_controller.rb

@ -15,7 +15,7 @@ class SchemesController < ApplicationController
redirect_to schemes_organisation_path(current_user.organisation) unless current_user.support?
all_schemes = Scheme.all
@pagy, @schemes = pagy(filter_manager.filtered_schemes(all_schemes, search_term, session_filters).order_by_completion.order_by_service_name)
@pagy, @schemes = pagy(filter_manager.filtered_schemes(all_schemes, search_term, session_filters).order_by_service_name)
@searched = search_term.presence
@total_count = all_schemes.size
@filter_type = "schemes"

15
app/models/scheme.rb

@ -11,14 +11,17 @@ class Scheme < ApplicationRecord
scope :search_by_postcode, ->(postcode) { left_joins(:locations).where("REPLACE(locations.postcode, ' ', '') ILIKE ?", "%#{postcode.delete(' ')}%") }
scope :search_by_location_name, ->(name) { left_joins(:locations).where("locations.name ILIKE ?", "%#{name}%") }
scope :search_by, lambda { |param|
search_by_postcode(param)
.or(search_by_service_name(param))
.or(search_by_location_name(param))
.or(filter_by_id(param)).distinct
select("schemes.*, lower(service_name) as lowercase_service_name")
.search_by_postcode(param)
.or(search_by_service_name(param))
.or(search_by_location_name(param))
.or(filter_by_id(param)).distinct
}
scope :order_by_completion, -> { order("schemes.confirmed ASC NULLS FIRST") }
scope :order_by_service_name, -> { order(service_name: :asc) }
scope :order_by_service_name, lambda {
select("schemes.*, lower(service_name) as lowercase_service_name")
.order("lowercase_service_name ASC")
}
scope :filter_by_owning_organisation, ->(owning_organisation, _user = nil) { where(owning_organisation:) }
scope :filter_by_status, lambda { |statuses, _user = nil|
filtered_records = all

Loading…
Cancel
Save