forked from solidusio/solidus
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Admin product properties: Load modal with turbo frame
- Loading branch information
Showing
7 changed files
with
26 additions
and
145 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
10 changes: 1 addition & 9 deletions
10
admin/app/components/solidus_admin/properties/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 |
---|---|---|
@@ -1,12 +1,4 @@ | ||
# frozen_string_literal: true | ||
|
||
class SolidusAdmin::Properties::Edit::Component < SolidusAdmin::BaseComponent | ||
def initialize(page:, property:) | ||
@page = page | ||
@property = property | ||
end | ||
|
||
def form_id | ||
dom_id(@property, "#{stimulus_id}_edit_property_form") | ||
end | ||
class SolidusAdmin::Properties::Edit::Component < SolidusAdmin::Resources::Edit::Component | ||
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
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
10 changes: 1 addition & 9 deletions
10
admin/app/components/solidus_admin/properties/new/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 |
---|---|---|
@@ -1,12 +1,4 @@ | ||
# frozen_string_literal: true | ||
|
||
class SolidusAdmin::Properties::New::Component < SolidusAdmin::BaseComponent | ||
def initialize(page:, property:) | ||
@page = page | ||
@property = property | ||
end | ||
|
||
def form_id | ||
dom_id(@property, "#{stimulus_id}_new_property_form") | ||
end | ||
class SolidusAdmin::Properties::New::Component < SolidusAdmin::Resources::New::Component | ||
end |
110 changes: 4 additions & 106 deletions
110
admin/app/controllers/solidus_admin/properties_controller.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 |
---|---|---|
@@ -1,117 +1,15 @@ | ||
# frozen_string_literal: true | ||
|
||
module SolidusAdmin | ||
class PropertiesController < SolidusAdmin::BaseController | ||
include SolidusAdmin::ControllerHelpers::Search | ||
|
||
before_action :set_property, only: %i[edit update] | ||
|
||
def index | ||
set_index_page | ||
|
||
respond_to do |format| | ||
format.html { render component('properties/index').new(page: @page) } | ||
end | ||
end | ||
|
||
def new | ||
@property = Spree::Property.new | ||
|
||
set_index_page | ||
|
||
respond_to do |format| | ||
format.html { render component('properties/new').new(page: @page, property: @property) } | ||
end | ||
end | ||
|
||
def create | ||
@property = Spree::Property.new(property_params) | ||
|
||
if @property.save | ||
respond_to do |format| | ||
flash[:notice] = t('.success') | ||
|
||
format.html do | ||
redirect_to solidus_admin.properties_path, status: :see_other | ||
end | ||
|
||
format.turbo_stream do | ||
render turbo_stream: '<turbo-stream action="refresh" />' | ||
end | ||
end | ||
else | ||
set_index_page | ||
|
||
respond_to do |format| | ||
format.html do | ||
page_component = component('properties/new').new(page: @page, property: @property) | ||
render page_component, status: :unprocessable_entity | ||
end | ||
end | ||
end | ||
end | ||
|
||
def edit | ||
set_index_page | ||
|
||
respond_to do |format| | ||
format.html { render component('properties/edit').new(page: @page, property: @property) } | ||
end | ||
end | ||
|
||
def update | ||
if @property.update(property_params) | ||
respond_to do |format| | ||
flash[:notice] = t('.success') | ||
|
||
format.html do | ||
redirect_to solidus_admin.properties_path, status: :see_other | ||
end | ||
|
||
format.turbo_stream do | ||
render turbo_stream: '<turbo-stream action="refresh" />' | ||
end | ||
end | ||
else | ||
set_index_page | ||
|
||
respond_to do |format| | ||
format.html do | ||
page_component = component('properties/edit').new(page: @page, property: @property) | ||
render page_component, status: :unprocessable_entity | ||
end | ||
end | ||
end | ||
end | ||
|
||
def destroy | ||
@properties = Spree::Property.where(id: params[:id]) | ||
|
||
Spree::Property.transaction do | ||
@properties.destroy_all | ||
end | ||
|
||
flash[:notice] = t('.success') | ||
redirect_to properties_path, status: :see_other | ||
end | ||
|
||
class PropertiesController < SolidusAdmin::ResourcesController | ||
private | ||
|
||
def set_property | ||
@property = Spree::Property.find(params[:id]) | ||
end | ||
def resource_class = Spree::Property | ||
|
||
def property_params | ||
def permitted_resource_params | ||
params.require(:property).permit(:name, :presentation) | ||
end | ||
|
||
def set_index_page | ||
properties = apply_search_to( | ||
Spree::Property.unscoped.order(id: :desc), | ||
param: :q, | ||
) | ||
|
||
set_page_and_extract_portion_from(properties) | ||
end | ||
def resources_collection = Spree::Property.unscoped | ||
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