Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make dropdown lists alphabetical order ( Part 1) #4663

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -801,4 +801,4 @@ DEPENDENCIES
webmock (~> 3.23)

BUNDLED WITH
2.5.16
2.5.19
2 changes: 1 addition & 1 deletion app/controllers/adjustments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def index
@paginated_adjustments = @adjustments.page(params[:page])

@storage_locations = Adjustment.storage_locations_adjusted_for(current_organization).uniq
@users = current_organization.users
@users = current_organization.users.sort_by { |user| user.name.to_s.downcase }

respond_to do |format|
format.html
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/audits_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class AuditsController < ApplicationController
def index
@selected_location = filter_params[:at_location]
@audits = current_organization.audits.class_filter(filter_params)
@storage_locations = Audit.storage_locations_audited_for(current_organization).uniq
@storage_locations = Audit.storage_locations_audited_for(current_organization).uniq.sort_by{ |sl| sl.name.to_s.downcase }
end

def show
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/barcode_items_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# anomaly here is the :find action, which has some special logic built-in to it, see the comments below.
class BarcodeItemsController < ApplicationController
def index
@items = Item.gather_items(current_organization, @global)
@items = Item.gather_items(current_organization, @global).alphabetized
@base_items = BaseItem.alphabetized
@selected_barcodeable_id = filter_params[:barcodeable_id]
@selected_partner_key = filter_params[:by_item_partner_key]
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/distributions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ def index
.apply_filters(filter_params, helpers.selected_range)
@paginated_distributions = @distributions.page(params[:page])
@items = current_organization.items.alphabetized
@item_categories = current_organization.item_categories
@item_categories = current_organization.item_categories.alphabetized
@storage_locations = current_organization.storage_locations.active_locations.alphabetized
@partners = @distributions.collect(&:partner).uniq.sort_by(&:name)
@partners = @distributions.collect(&:partner).uniq
@selected_item = filter_params[:by_item_id].presence
@total_value_all_distributions = total_value(@distributions)
@total_items_all_distributions = total_items(@distributions, @selected_item)
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/donations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ def index
@paginated_donations_quantity = @paginated_donations.collect(&:total_quantity).sum
@total_value_all_donations = total_value(@donations)
@total_money_raised = total_money_raised(@donations)
@storage_locations = @donations.filter_map { |donation| donation.storage_location if !donation.storage_location.discarded_at }.compact.uniq.sort
@storage_locations = @donations.filter_map { |donation| donation.storage_location if !donation.storage_location.discarded_at }.compact.uniq.sort_by { |sl| sl.name.to_s.downcase }
@selected_storage_location = filter_params[:at_storage_location]
@sources = @donations.collect(&:source).uniq.sort
@sources = @donations.collect(&:source).uniq.sort_by { |source| source.to_s.downcase }
@selected_source = filter_params[:by_source]
@donation_sites = @donations.collect(&:donation_site).compact.uniq.sort_by { |site| site.name.downcase }
@donation_sites = @donations.collect(&:donation_site).compact.uniq.sort_by { |site| site.name.to_s.downcase }
@selected_donation_site = filter_params[:from_donation_site]
@selected_product_drive = filter_params[:by_product_drive]
@selected_product_drive_participant = filter_params[:by_product_drive_participant]
@manufacturers = @donations.collect(&:manufacturer).compact.uniq.sort
@manufacturers = @donations.collect(&:manufacturer).compact.uniq.sort_by { |manufacturer| manufacturer.name.to_s.downcase }
@selected_manufacturer = filter_params[:from_manufacturer]

respond_to do |format|
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ def index
if params.dig(:filters, :date_range).present?
@events = @events.during(helpers.selected_range)
end
@items = current_organization.items.sort_by(&:name)
@locations = current_organization.storage_locations
@items = current_organization.items.alphabetized
@locations = current_organization.storage_locations.alphabetized

respond_to do |format|
format.html do
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/items_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ def index
.alphabetized
.class_filter(filter_params)
.group('items.id')
@items = @items.active unless params[:include_inactive_items]
@items = @items.active.alphabetized unless params[:include_inactive_items]

@item_categories = current_organization.item_categories.includes(:items).order('name ASC')
@item_categories = current_organization.item_categories.includes(:items).alphabetized
@kits = current_organization.kits.includes(line_items: :item, inventory_items: :storage_location)
@storages = current_organization.storage_locations.active_locations.order(id: :asc)

Expand Down Expand Up @@ -59,13 +59,13 @@ def create

def new
@base_items = BaseItem.without_kit.alphabetized
@item_categories = current_organization.item_categories
@item_categories = current_organization.item_categories.alphabetized
@item = current_organization.items.new
end

def edit
@base_items = BaseItem.without_kit.alphabetized
@item_categories = current_organization.item_categories
@item_categories = current_organization.item_categories.alphabetized
@item = current_organization.items.find(params[:id])
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/base_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class BaseItem < ApplicationRecord

scope :by_partner_key, ->(partner_key) { where(partner_key: partner_key) }
scope :without_kit, -> { where.not(name: 'Kit') }
scope :alphabetized, -> { order(:name) }
scope :alphabetized, -> { order('LOWER(name)') }

def to_h
{ partner_key: partner_key, name: name }
Expand Down
2 changes: 1 addition & 1 deletion app/models/item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class Item < ApplicationRecord
scope :loose, -> { where(kit_id: nil) }

scope :visible, -> { where(visible_to_partners: true) }
scope :alphabetized, -> { order(:name) }
scope :alphabetized, -> { order('LOWER(name)') }
scope :by_base_item, ->(base_item) { where(base_item: base_item) }
scope :by_partner_key, ->(partner_key) { where(partner_key: partner_key) }

Expand Down
2 changes: 2 additions & 0 deletions app/models/item_category.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ class ItemCategory < ApplicationRecord
belongs_to :organization
has_many :items, -> { order(name: :asc) }, inverse_of: :item_category, dependent: :nullify
has_many :partner_groups, dependent: :nullify

scope :alphabetized, -> { order('LOWER(name)') }
end
2 changes: 1 addition & 1 deletion app/models/partner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class Partner < ApplicationRecord
.order(:name)
}

scope :alphabetized, -> { order(:name) }
scope :alphabetized, -> { order('LOWER(name)') }
scope :active, -> { where.not(status: :deactivated) }

include Filterable
Expand Down
2 changes: 2 additions & 0 deletions app/models/unit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@
class Unit < ApplicationRecord
belongs_to :organization
validates :name, uniqueness: {scope: :organization}

scope :alphabetized, -> { order('LOWER(name)') }
end
1 change: 0 additions & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ class User < ApplicationRecord
validate :password_complexity

default_scope -> { kept }
scope :alphabetized, -> { order(discarded_at: :desc, name: :asc) }
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This wasn't being used anywhere, so I opted to remove it and look to order user select fields on the instance vars defined in relevant controller files.

scope :partner_users, -> { with_role(Role::PARTNER, :any) }
scope :org_users, -> { with_role(Role::ORG_USER, :any) }
scope :search_name, ->(query) { where("name ilike ?", "%#{query}%") }
Expand Down
4 changes: 2 additions & 2 deletions app/views/barcode_items/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
<%= form_with(url: barcode_items_path, method: :get) do |f| %>
<div class="row">
<div class="form-group col-lg-4 col-md-4 col-sm-6 col-xs-12">
<%= filter_select(label: "Filter by Item Category", scope: :barcodeable_id, collection: @items.alphabetized, key: :id, value: :name, selected: @selected_barcodeable_id) %>
<%= filter_select(label: "Filter by Item Category", scope: :barcodeable_id, collection: @items, key: :id, value: :name, selected: @selected_barcodeable_id) %>
</div>
<div class="form-group col-lg-4 col-md-4 col-sm-6 col-xs-12">
<%= filter_select(label: "Filter by Base Item", scope: :by_item_partner_key, collection: @base_items.order('name'), key: :partner_key, value: :name, selected: @selected_partner_key) %>
<%= filter_select(label: "Filter by Base Item", scope: :by_item_partner_key, collection: @base_items, key: :partner_key, value: :name, selected: @selected_partner_key) %>
</div>
<div class="form-group col-lg-4 col-md-4 col-sm-6 col-xs-12">
<%= filter_text(label: "Filter By Barcode (Boop it!)", scope: :by_value, selected: @selected_barcode_id) %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/events/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
selected: params.dig(:filters, :by_type)) %>
</div>
<div class="form-group col-lg-3 col-md-3 col-sm-6 col-xs-12">
<%= filter_select(scope: :by_storage_location, collection: current_organization.storage_locations,
<%= filter_select(scope: :by_storage_location, collection: @locations,
selected:params.dig(:filters, :by_storage_location)) %>
</div>
<div class="form-group col-lg-3 col-md-3 col-sm-6 col-xs-12">
Expand Down
2 changes: 1 addition & 1 deletion app/views/items/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

<% if Flipper.enabled?(:enable_packs) %>
<%= f.input :request_units, label: "Additional Custom Request Units" do %>
<%= f.association :request_units, as: :check_boxes, collection: current_organization.request_units, checked: selected_item_request_units(@item), label_method: :name, value_method: :id, class: "form-check-input" %>
<%= f.association :request_units, as: :check_boxes, collection: current_organization.request_units.alphabetized, checked: selected_item_request_units(@item), label_method: :name, value_method: :id, class: "form-check-input" %>
<% end %>
<% end %>

Expand Down
4 changes: 2 additions & 2 deletions app/views/line_items/_line_item_fields.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
<span class="li-name w-100">
<%= field.input :item_id,
disabled: requested.present?,
collection: @items, prompt: "Choose an item",
include_blank: "",
collection: @items,
include_blank: false,
label: false,
input_html: { class: "my-0 line_item_name", "data-controller": "select2" } %>
<% if requested.present? %>
Expand Down
3 changes: 2 additions & 1 deletion app/views/storage_locations/_source.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
label: label,
error: error,
selected: storage_location_for_source(source.object),
include_blank: true,
include_blank: false,
prompt: "Choose a storage location",
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Felt like this just looked better.

Before:
image

After:
image

input_html: {
data: {
storage_location_inventory_path: inventory_storage_location_path(
Expand Down