-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
444 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
admin/app/components/solidus_admin/stock_items/edit/component.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<div | ||
data-controller="<%= stimulus_id %>" | ||
data-<%= stimulus_id %>-initial-count-on-hand-value="<%= @stock_item.count_on_hand_was || @stock_item.count_on_hand %>" | ||
data-action="input-><%= stimulus_id %>#updateCountOnHand" | ||
> | ||
<%= render component("ui/modal").new(title: t(".title"), close_path: solidus_admin.stock_items_path(page: params[:page], q: params[:q])) do |modal| %> | ||
<%= form_for @stock_item, url: solidus_admin.stock_item_path(@stock_item), html: { id: form_id } do |f| %> | ||
<div class="flex flex-col gap-6 pb-4"> | ||
<div class="flex gap-4"> | ||
<%= link_to spree.edit_admin_product_variant_path( | ||
@stock_item.variant.product, | ||
@stock_item.variant, | ||
), class: 'hover:bg-gray-25 rounded p-1 w-1/2 border border-gray-100' do %> | ||
<%= render component("ui/resource_item").new( | ||
thumbnail: | ||
( | ||
@stock_item.variant.images.first || | ||
@stock_item.variant.product.gallery.images.first | ||
)&.url(:small), | ||
title: @stock_item.variant.name, | ||
subtitle: | ||
"#{@stock_item.variant.sku}#{@stock_item.variant.options_text.presence&.prepend(" - ")}", | ||
) %> | ||
<% end %> | ||
<%= link_to spree.edit_admin_stock_location_path(@stock_item.stock_location), class: 'hover:bg-gray-25 rounded p-1 w-1/2 border border-gray-100' do %> | ||
<%= render component("ui/resource_item").new( | ||
title: @stock_item.stock_location.name, | ||
subtitle: "#{Spree::StockLocation.model_name.human} #{@stock_item.stock_location.code}", | ||
) %> | ||
<% end %> | ||
</div> | ||
|
||
<%= render component("ui/forms/field").text_field( | ||
f, | ||
:count_on_hand, | ||
disabled: true, | ||
value: @stock_item.count_on_hand_was || @stock_item.count_on_hand, | ||
"data-#{stimulus_id}-target": 'countOnHand', | ||
) %> | ||
<%= render component("ui/forms/field").new( | ||
label: t(".quantity_adjustment"), | ||
hint: t(".quantity_adjustment_hint_html"), | ||
) do %> | ||
<%= render component("ui/forms/input").new( | ||
value: params[:quantity_adjustment] || 0, | ||
name: :quantity_adjustment, | ||
type: :number, | ||
step: 1, | ||
"data-#{stimulus_id}-target": 'quantityAdjustment', | ||
) %> | ||
<% end %> | ||
|
||
<%= render component("ui/forms/switch_field").new( | ||
name: "#{f.object_name}[backorderable]", | ||
label: Spree::StockItem.human_attribute_name(:backorderable), | ||
error: f.object.errors[:backorderable], | ||
hint: t(".backorderable_hint_html"), | ||
checked: f.object.backorderable?, | ||
include_hidden: true, | ||
) %> | ||
</div> | ||
<% end %> | ||
|
||
<% modal.with_actions do %> | ||
<%= render component("ui/button").new( | ||
tag: :a, | ||
scheme: :secondary, | ||
text: t(".cancel"), | ||
href: solidus_admin.stock_items_path(page: params[:page], q: params[:q]), | ||
) %> | ||
|
||
<%= render component("ui/button").new( | ||
tag: :button, | ||
text: t(".submit"), | ||
form: form_id, | ||
) %> | ||
<% end %> | ||
<% end %> | ||
|
||
<%= render component("stock_items/index").new(page: @page) %> | ||
</div> |
17 changes: 17 additions & 0 deletions
17
admin/app/components/solidus_admin/stock_items/edit/component.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Controller } from '@hotwired/stimulus' | ||
|
||
export default class extends Controller { | ||
static values = { | ||
initialCountOnHand: Number, | ||
} | ||
|
||
static targets = ['countOnHand', 'quantityAdjustment'] | ||
|
||
connect() { | ||
this.updateCountOnHand() | ||
} | ||
|
||
updateCountOnHand() { | ||
this.countOnHandTarget.value = parseInt(this.initialCountOnHandValue) + parseInt(this.quantityAdjustmentTarget.value) | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
admin/app/components/solidus_admin/stock_items/edit/component.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# frozen_string_literal: true | ||
|
||
class SolidusAdmin::StockItems::Edit::Component < SolidusAdmin::BaseComponent | ||
def initialize(stock_item:, page:) | ||
@stock_item = stock_item | ||
@page = page | ||
end | ||
|
||
def title | ||
[ | ||
"#{Spree::StockLocation.model_name.human}: #{@stock_item.stock_location.name}", | ||
].join(' / ') | ||
end | ||
|
||
def form_id | ||
"#{stimulus_id}-#{dom_id(@stock_item)}" | ||
end | ||
end |
10 changes: 10 additions & 0 deletions
10
admin/app/components/solidus_admin/stock_items/edit/component.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
en: | ||
submit: "Save" | ||
cancel: "Cancel" | ||
title: "Edit Stock Levels" | ||
quantity_adjustment: "Quantity Adjustment" | ||
quantity_adjustment_hint_html: | | ||
Enter a positive number to increase the stock level, or a negative number to decrease the stock level. | ||
backorderable_hint_html: | | ||
Enable to allow customers to place orders even when the product is out of stock.<br> | ||
When ordering the product customers will know that the product will be delivered at a later date, once it becomes available again. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
admin/app/components/solidus_admin/ui/forms/switch_field/component.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<label class="flex flex-wrap items-center gap-2 w-full border border-gray-100 rounded px-4 py-2"> | ||
<div class="flex gap-1 items-center grow py-2"> | ||
<span class="text-gray-700 body-tiny-bold body-text-bold"><%= @label %></span> | ||
|
||
<%= render component("ui/toggletip").new(text: @tip) if @tip.present? %> | ||
</div> | ||
|
||
<%= render component("ui/forms/switch").new(**@attributes) %> | ||
|
||
<% if @hint.present? || @error.present? %> | ||
<div | ||
class=" | ||
w-full body-small [:disabled~&]:text-gray-300 text-gray-500 flex gap-1 flex-col pt-2 pb-4 | ||
" | ||
> | ||
<%= tag.span @hint if @hint.present? %> | ||
<%= tag.span safe_join(@error, tag.br), class: "text-red-400" if @error.present? %> | ||
</div> | ||
<% end %> | ||
</label> |
10 changes: 10 additions & 0 deletions
10
admin/app/components/solidus_admin/ui/forms/switch_field/component.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# frozen_string_literal: true | ||
|
||
class SolidusAdmin::UI::Forms::SwitchField::Component < SolidusAdmin::BaseComponent | ||
def initialize(label:, error:, hint:, **attributes) | ||
@label = label | ||
@error = error | ||
@hint = hint | ||
@attributes = attributes | ||
end | ||
end |
10 changes: 10 additions & 0 deletions
10
admin/app/components/solidus_admin/ui/resource_item/component.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<div class="flex gap-2 grow"> | ||
<%= render component("ui/thumbnail").new( | ||
src: @thumbnail, | ||
alt: @title, | ||
) if @thumbnail %> | ||
<div class="flex-col"> | ||
<div class="leading-5 text-black body-small-bold"><%= @title %></div> | ||
<div class="leading-5 text-gray-500 body-small"><%= @subtitle %></div> | ||
</div> | ||
</div> |
9 changes: 9 additions & 0 deletions
9
admin/app/components/solidus_admin/ui/resource_item/component.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# frozen_string_literal: true | ||
|
||
class SolidusAdmin::UI::ResourceItem::Component < SolidusAdmin::BaseComponent | ||
def initialize(title:, subtitle:, thumbnail: nil) | ||
@thumbnail = thumbnail | ||
@title = title | ||
@subtitle = subtitle | ||
end | ||
end |
Oops, something went wrong.