Skip to content

Commit e1fd6c3

Browse files
authored
Merge branch 'main' into 4990-highlight-items-below-min-quantity
2 parents ba458c4 + d1c52ea commit e1fd6c3

77 files changed

Lines changed: 98 additions & 111 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,4 @@ package-lock.json
8888
out/
8989

9090
.vscode/
91+
.aider*

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -831,4 +831,4 @@ DEPENDENCIES
831831
webmock (~> 3.24)
832832

833833
BUNDLED WITH
834-
2.6.5
834+
2.6.6

app/controllers/partners/requests_controller.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,11 @@ def fetch_items
8181
@requestable_items = PartnerFetchRequestableItemsService.new(partner_id: partner.id).call
8282
if Flipper.enabled?(:enable_packs)
8383
# hash of (item ID => hash of (request unit name => request unit plural name))
84-
@item_units = Item.where(id: @requestable_items.to_h.values).to_h do |i|
85-
[i.id, i.request_units.to_h { |u| [u.name, u.name.pluralize] }]
84+
item_ids = @requestable_items.to_h.values
85+
if item_ids.present?
86+
@item_units = Item.where(id: item_ids).to_h do |i|
87+
[i.id, i.request_units.to_h { |u| [u.name, u.name.pluralize] }]
88+
end
8689
end
8790
end
8891
end

app/javascript/controllers/item_units_controller.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export default class extends Controller {
4343
this.requestSelectTarget.style.display = 'inline';
4444
this.clearOptions()
4545
this.addOption('-1', 'Please select a unit')
46-
this.addOption('', 'Units')
46+
this.addOption('', 'units')
4747
for (const [index, [name, displayName]] of Object.entries(Object.entries(units))) {
4848
this.addOption(name, displayName)
4949
}

app/javascript/controllers/select2_controller.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,19 @@ export default class extends Controller {
2929
}
3030
}
3131
});
32+
33+
/**
34+
* This is a workaround to prevent select2 from filling in an existing
35+
* value even when you try to remove everything. This solution was found at
36+
* https://github.com/select2/select2/issues/3320#issuecomment-1440268574
37+
*/
38+
if ($(this.element).prop('multiple')) {
39+
select2.on("select2:unselecting", function (e) {
40+
$(this).on("select2:opening", function (ev) {
41+
ev.preventDefault();
42+
$(this).off("select2:opening");
43+
});
44+
});
45+
}
3246
}
3347
}

app/models/partners/item_request.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ def request_unit_is_supported
3838

3939
def name_with_unit(quantity_override = nil)
4040
if Flipper.enabled?(:enable_packs) && request_unit.present?
41-
"#{item.name} - #{request_unit.pluralize(quantity_override || quantity.to_i)}"
41+
"#{item&.name || name} - #{request_unit.pluralize(quantity_override || quantity.to_i)}"
4242
else
43-
item.name
43+
item&.name || name
4444
end
4545
end
4646
end

app/models/unit.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,7 @@
1010
#
1111
class Unit < ApplicationRecord
1212
belongs_to :organization
13-
validates :name, uniqueness: {scope: :organization}
13+
validates :name,
14+
uniqueness: {scope: :organization},
15+
format: {without: /\Aunits?\z/i, message: "'unit' is reserved."}
1416
end

app/pdfs/picklists_pdf.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def data_with_units(line_items)
145145
data + line_items.map do |line_item|
146146
[line_item.name,
147147
line_item.quantity,
148-
line_item.request_unit&.capitalize&.pluralize(line_item.quantity),
148+
line_item.request_unit&.pluralize(line_item.quantity),
149149
"[ ]",
150150
""]
151151
end

app/services/organization_update_service.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ def update(organization, params)
1818
org_params["partner_form_fields"] = org_params["partner_form_fields"].compact_blank
1919
end
2020

21-
if Flipper.enabled?(:enable_packs) && org_params[:request_unit_names]
21+
if Flipper.enabled?(:enable_packs)
22+
request_unit_names = org_params[:request_unit_names] || []
2223
# Find or create units for the organization
23-
request_unit_ids = org_params[:request_unit_names].compact_blank.map do |request_unit_name|
24+
request_unit_ids = request_unit_names.compact_blank.map do |request_unit_name|
2425
Unit.find_or_create_by(organization: organization, name: request_unit_name).id
2526
end
2627
org_params.delete(:request_unit_names)

app/views/layouts/_lte_navbar.html.erb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,12 @@
5050
<i class="fa fa-repeat text-aqua"></i><%= "Switch to: #{role.resource&.name || "Super Admin"}" %>
5151
<% end %>
5252
<% end %>
53-
<% if current_user.has_cached_role?(Role::ORG_ADMIN, current_organization) %>
53+
<% if current_user.has_cached_role?(Role::ORG_ADMIN, current_organization) %>
5454
<div class="dropdown-divider"></div>
55-
<%= link_to users_path, class:"dropdown-item" do %>
56-
<i class="fas fa-users mr-2"></i> My Co-Workers
55+
<% if current_user.has_cached_role?(:partner) %>
56+
<%= link_to users_path, class:"dropdown-item" do %>
57+
<i class="fas fa-users mr-2"></i> My Co-Workers
58+
<% end %>
5759
<% end %>
5860
<%= link_to organization_path, class:"dropdown-item" do %>
5961
<i class="fas fa-sitemap mr-2"></i> My Organization

0 commit comments

Comments
 (0)