Skip to content

Commit

Permalink
Merge pull request #5536 from solidusio/elia/admin/shipping
Browse files Browse the repository at this point in the history
[admin] Add index pages for the settings / shipping area
  • Loading branch information
elia committed Dec 5, 2023
2 parents 946a49e + cab7ad2 commit b96773e
Show file tree
Hide file tree
Showing 23 changed files with 557 additions and 1 deletion.
30 changes: 30 additions & 0 deletions admin/app/components/solidus_admin/shipping/component.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<%= page do %>
<%= page_header do %>
<%= page_header_title safe_join([
tag.div(t(".title")),
tag.div(t(".subtitle"), class: "body-small text-gray-500"),
]) %>
<% end %>
<%= page_header do %>
<% title = capture do %>
<% tabs.each do |tab_class, href|%>
<%= render component('ui/button').new(
tag: :a,
scheme: :ghost,
href: href,
text: tab_class.model_name.human.pluralize,
"aria-current" => tab_class == @current_class,
) %>
<% end %>
<% end %>
<%= page_header_title title %>
<%= page_header_actions do %>
<%= actions %>
<% end %>
<% end %>
<%= content %>
<% end %>
18 changes: 18 additions & 0 deletions admin/app/components/solidus_admin/shipping/component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true

class SolidusAdmin::Shipping::Component < SolidusAdmin::BaseComponent
include SolidusAdmin::Layout::PageHelpers
renders_one :actions

def initialize(current_class:)
@current_class = current_class
end

def tabs
{
Spree::ShippingMethod => solidus_admin.shipping_methods_path,
Spree::ShippingCategory => solidus_admin.shipping_categories_path,
Spree::StockLocation => solidus_admin.stock_locations_path,
}
end
end
3 changes: 3 additions & 0 deletions admin/app/components/solidus_admin/shipping/component.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
en:
title: "Shipping"
subtitle: "Configure shipping methods, categories, and stock locations for customer orders."
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<%= render component('shipping').new(current_class: Spree::ShippingCategory) do |layout| %>
<% layout.with_actions do %>
<%= render component("ui/button").new(
tag: :a,
text: t('.add'),
href: spree.new_admin_shipping_category_path,
icon: "add-line",
class: "align-self-end w-full",
) %>
<% end %>
<%= render component('ui/table').new(
id: stimulus_id,
data: {
class: Spree::ShippingCategory,
rows: @page.records,
url: ->(shipping_category) { spree.edit_admin_shipping_category_path(shipping_category) },
prev: prev_page_path,
next: next_page_path,
columns: columns,
batch_actions: batch_actions,
},
search: {
name: :q,
value: params[:q],
url: solidus_admin.shipping_categories_path,
searchbar_key: :name_or_description_cont,
filters: filters,
scopes: scopes,
},
) %>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# frozen_string_literal: true

class SolidusAdmin::ShippingCategories::Index::Component < SolidusAdmin::BaseComponent
include SolidusAdmin::Layout::PageHelpers

def initialize(page:)
@page = page
end

def title
Spree::ShippingCategory.model_name.human.pluralize
end

def prev_page_path
solidus_admin.url_for(**request.params, page: @page.number - 1, only_path: true) unless @page.first?
end

def next_page_path
solidus_admin.url_for(**request.params, page: @page.next_param, only_path: true) unless @page.last?
end

def batch_actions
[
{
display_name: t('.batch_actions.delete'),
action: solidus_admin.shipping_categories_path,
method: :delete,
icon: 'delete-bin-7-line',
},
]
end

def filters
[]
end

def scopes
[]
end

def columns
[
:name
]
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
en:
add: 'Add new'
batch_actions:
delete: 'Delete'
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<%= render component('shipping').new(current_class: Spree::ShippingMethod) do |layout| %>
<% layout.with_actions do %>
<%= render component("ui/button").new(
tag: :a,
text: t('.add'),
href: spree.new_admin_shipping_method_path,
icon: "add-line",
class: "align-self-end w-full",
) %>
<% end %>
<%= render component('ui/table').new(
id: stimulus_id,
data: {
class: Spree::ShippingMethod,
rows: @page.records,
url: ->(shipping_method) { spree.edit_admin_shipping_method_path(shipping_method) },
prev: prev_page_path,
next: next_page_path,
columns: columns,
batch_actions: batch_actions,
},
search: {
name: :q,
value: params[:q],
url: solidus_admin.shipping_methods_path,
searchbar_key: :name_or_description_cont,
filters: filters,
scopes: scopes,
},
) %>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# frozen_string_literal: true

class SolidusAdmin::ShippingMethods::Index::Component < SolidusAdmin::BaseComponent
include SolidusAdmin::Layout::PageHelpers

def initialize(page:)
@page = page
end

def title
Spree::ShippingMethod.model_name.human.pluralize
end

def prev_page_path
solidus_admin.url_for(**request.params, page: @page.number - 1, only_path: true) unless @page.first?
end

def next_page_path
solidus_admin.url_for(**request.params, page: @page.next_param, only_path: true) unless @page.last?
end

def batch_actions
[
{
display_name: t('.batch_actions.delete'),
action: solidus_admin.shipping_methods_path,
method: :delete,
icon: 'delete-bin-7-line',
},
]
end

def filters
[]
end

def scopes
[]
end

def columns
[
{
header: :name,
data: -> { [_1.admin_name.presence, _1.name].compact.join(' / ') },
},
{
header: :zone,
data: -> { _1.zones.pluck(:name).to_sentence },
},
{
header: :calculator,
data: -> { _1.calculator&.description },
},
{
header: :available_to_users,
data: -> { _1.available_to_users? ? component('ui/badge').yes : component('ui/badge').no },
},
]
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
en:
add: 'Add new'
batch_actions:
delete: 'Delete'
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<%= render component('shipping').new(current_class: Spree::StockLocation) do |layout| %>
<% layout.with_actions do %>
<%= render component("ui/button").new(
tag: :a,
text: t('.add'),
href: spree.new_admin_stock_location_path,
icon: "add-line",
class: "align-self-end w-full",
) %>
<% end %>
<%= render component('ui/table').new(
id: stimulus_id,
data: {
class: Spree::StockLocation,
rows: @page.records,
url: ->(stock_location) { spree.edit_admin_stock_location_path(stock_location) },
prev: prev_page_path,
next: next_page_path,
columns: columns,
batch_actions: batch_actions,
},
search: {
name: :q,
value: params[:q],
url: solidus_admin.stock_locations_path,
searchbar_key: :name_or_description_cont,
filters: filters,
scopes: scopes,
},
) %>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# frozen_string_literal: true

class SolidusAdmin::StockLocations::Index::Component < SolidusAdmin::BaseComponent
include SolidusAdmin::Layout::PageHelpers

def initialize(page:)
@page = page
end

def title
Spree::StockLocation.model_name.human.pluralize
end

def prev_page_path
solidus_admin.url_for(**request.params, page: @page.number - 1, only_path: true) unless @page.first?
end

def next_page_path
solidus_admin.url_for(**request.params, page: @page.next_param, only_path: true) unless @page.last?
end

def batch_actions
[
{
display_name: t('.batch_actions.delete'),
action: solidus_admin.stock_locations_path,
method: :delete,
icon: 'delete-bin-7-line',
},
]
end

def filters
[]
end

def scopes
[]
end

def columns
[
:name,
:code,
:admin_name,
{
header: :state,
data: -> {
color = _1.active? ? :green : :graphite_light
text = _1.active? ? t('.active') : t('.inactive')

component('ui/badge').new(name: text, color: color)
},
},
{
header: :backorderable,
data: -> {
_1.backorderable_default ? component('ui/badge').yes : component('ui/badge').no
}
},
{
header: :default,
data: -> {
_1.default ? component('ui/badge').yes : component('ui/badge').no
}
},
{
header: :stock_movements,
data: -> {
count = _1.stock_movements.count

link_to(
"#{count} #{Spree::StockMovement.model_name.human(count: count).downcase}",
spree.admin_stock_location_stock_movements_path(_1),
class: 'body-link'
)
}
}
]
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
en:
active: 'Active'
inactive: 'Inactive'
add: 'Add new'
batch_actions:
delete: 'Delete'
Loading

0 comments on commit b96773e

Please sign in to comment.