-
-
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
7 changed files
with
165 additions
and
0 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
admin/app/components/solidus_admin/zones/index/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,35 @@ | ||
<%= page do %> | ||
<%= page_header do %> | ||
<%= page_header_title title %> | ||
<%= page_header_actions do %> | ||
<%= render component("ui/button").new( | ||
tag: :a, | ||
text: t('.add'), | ||
href: spree.new_admin_zone_path, | ||
icon: "add-line", | ||
class: "align-self-end w-full", | ||
) %> | ||
<% end %> | ||
<% end %> | ||
|
||
<%= render component('ui/table').new( | ||
id: stimulus_id, | ||
data: { | ||
class: Spree::Zone, | ||
rows: @page.records, | ||
url: ->(zone) { spree.edit_admin_zone_path(zone) }, | ||
prev: prev_page_path, | ||
next: next_page_path, | ||
columns: columns, | ||
batch_actions: batch_actions, | ||
}, | ||
search: { | ||
name: :q, | ||
value: params[:q], | ||
url: solidus_admin.zones_path, | ||
searchbar_key: :name_or_description_cont, | ||
filters: filters, | ||
scopes: scopes, | ||
}, | ||
) %> | ||
<% end %> |
55 changes: 55 additions & 0 deletions
55
admin/app/components/solidus_admin/zones/index/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,55 @@ | ||
# frozen_string_literal: true | ||
|
||
class SolidusAdmin::Zones::Index::Component < SolidusAdmin::BaseComponent | ||
include SolidusAdmin::Layout::PageHelpers | ||
|
||
def initialize(page:) | ||
@page = page | ||
end | ||
|
||
def title | ||
Spree::Zone.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.zones_path, | ||
method: :delete, | ||
icon: 'delete-bin-7-line', | ||
}, | ||
] | ||
end | ||
|
||
def filters | ||
[] | ||
end | ||
|
||
def scopes | ||
[] | ||
end | ||
|
||
def columns | ||
[ | ||
:name, | ||
:description, | ||
{ | ||
header: :kind, | ||
data: -> { component('ui/badge').new(name: _1.kind, color: _1.kind == 'country' ? :green : :blue) }, | ||
}, | ||
{ | ||
header: :zone_members, | ||
data: -> { _1.zone_members.map(&:zoneable).map(&:name).to_sentence }, | ||
}, | ||
] | ||
end | ||
end |
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,4 @@ | ||
en: | ||
add: 'Add new' | ||
batch_actions: | ||
delete: 'Delete' |
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,40 @@ | ||
# frozen_string_literal: true | ||
|
||
module SolidusAdmin | ||
class ZonesController < SolidusAdmin::BaseController | ||
include SolidusAdmin::ControllerHelpers::Search | ||
|
||
def index | ||
zones = apply_search_to( | ||
Spree::Zone.order(id: :desc), | ||
param: :q | ||
) | ||
|
||
set_page_and_extract_portion_from(zones) | ||
|
||
respond_to do |format| | ||
format.html { render component('zones/index').new(page: @page) } | ||
end | ||
end | ||
|
||
def destroy | ||
@zones = Spree::Zone.where(id: params[:id]) | ||
|
||
Spree::Zone.transaction { @zones.destroy_all } | ||
|
||
flash[:notice] = t('.success') | ||
redirect_back_or_to zones_path, status: :see_other | ||
end | ||
|
||
private | ||
|
||
def load_zone | ||
@zone = Spree::Zone.find_by!(number: params[:id]) | ||
authorize! action_name, @zone | ||
end | ||
|
||
def zone_params | ||
params.require(:zone).permit(:zone_id, permitted_zone_attributes) | ||
end | ||
end | ||
end |
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,6 @@ | ||
en: | ||
solidus_admin: | ||
zones: | ||
title: "Zones" | ||
destroy: | ||
success: "Zones were successfully removed." |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
describe "Zones", :js, type: :feature do | ||
before { sign_in create(:admin_user, email: '[email protected]') } | ||
|
||
it "lists zones and allows deleting them" do | ||
create(:zone, name: "Europe") | ||
create(:zone, name: "North America") | ||
|
||
visit "/admin/zones" | ||
expect(page).to have_content("Europe") | ||
expect(page).to have_content("North America") | ||
expect(page).to be_axe_clean | ||
|
||
select_row("Europe") | ||
click_on "Delete" | ||
expect(page).to have_content("Zones were successfully removed.") | ||
expect(page).not_to have_content("Europe") | ||
expect(Spree::Zone.count).to eq(1) | ||
expect(page).to be_axe_clean | ||
end | ||
end |