diff --git a/app/assets/stylesheets/alchemy/forms.scss b/app/assets/stylesheets/alchemy/forms.scss index 219529a5f0..ae294f1661 100644 --- a/app/assets/stylesheets/alchemy/forms.scss +++ b/app/assets/stylesheets/alchemy/forms.scss @@ -169,7 +169,8 @@ form { } .inline-input { - @include clearfix; + align-items: center; + display: flex; margin: 0 -1 * $default-margin; .left-column, @@ -179,12 +180,10 @@ form { .left-column { width: $form-right-width; - float: left; } .right-column { width: $form-left-width; - float: right; } button, diff --git a/app/components/alchemy/admin/growl.rb b/app/components/alchemy/admin/growl.rb new file mode 100644 index 0000000000..a6556ea925 --- /dev/null +++ b/app/components/alchemy/admin/growl.rb @@ -0,0 +1,25 @@ +module Alchemy + module Admin + class Growl < ViewComponent::Base + delegate :flash, to: :helpers + + attr_reader :message, :type + + def before_render + @message = nil + if flash.any? + key = flash.keys.first + @message = flash[key] + @type = key + flash.delete(key) + end + end + + def call + return unless message + + content_tag("alchemy-growl", nil, {message: message, type: type}) + end + end + end +end diff --git a/app/controllers/alchemy/admin/base_controller.rb b/app/controllers/alchemy/admin/base_controller.rb index e36f133e67..d752cbddb1 100644 --- a/app/controllers/alchemy/admin/base_controller.rb +++ b/app/controllers/alchemy/admin/base_controller.rb @@ -33,7 +33,7 @@ def leave # Disable layout rendering for xhr requests. def set_layout - request.xhr? ? false : "alchemy/admin" + (request.xhr? || turbo_frame_request?) ? false : "alchemy/admin" end # Handles exceptions diff --git a/app/controllers/alchemy/admin/nodes_controller.rb b/app/controllers/alchemy/admin/nodes_controller.rb index 9695f26048..a7ac9dabd6 100644 --- a/app/controllers/alchemy/admin/nodes_controller.rb +++ b/app/controllers/alchemy/admin/nodes_controller.rb @@ -16,6 +16,34 @@ def new ) end + def create + if turbo_frame_request? + @node = Alchemy::Node.build(resource_params) + @page = @node.page + if @node.valid? + @node.save + flash_notice_for_resource_action(:create) + else + flash[:error] = @node.errors.full_messages.join(", ") + @page.reload # reload the page to update the nodes collection + end + else + super + end + end + + def destroy + if turbo_frame_request? + @node = Alchemy::Node.find(params[:id]) + @page = @node.page + @node.destroy + @page.reload # reload the page to update the nodes collection + flash_notice_for_resource_action(:destroy) + else + super + end + end + private def resource_params diff --git a/app/javascript/alchemy_admin.js b/app/javascript/alchemy_admin.js index 8c2b755834..268ca46c3b 100644 --- a/app/javascript/alchemy_admin.js +++ b/app/javascript/alchemy_admin.js @@ -25,6 +25,7 @@ import "alchemy_admin/components/clipboard_button" import "alchemy_admin/components/datepicker" import "alchemy_admin/components/dialog_link" import "alchemy_admin/components/element_editor" +import "alchemy_admin/components/growl" import "alchemy_admin/components/ingredient_group" import "alchemy_admin/components/link_buttons" import "alchemy_admin/components/node_select" diff --git a/app/javascript/alchemy_admin/components/growl.js b/app/javascript/alchemy_admin/components/growl.js new file mode 100644 index 0000000000..015d994098 --- /dev/null +++ b/app/javascript/alchemy_admin/components/growl.js @@ -0,0 +1,17 @@ +export class Growl extends HTMLElement { + connectedCallback() { + if (this.message) { + Alchemy.growl(this.message, this.type) + } + } + + get message() { + return this.getAttribute("message") + } + + get type() { + return this.getAttribute("type") || "notice" + } +} + +customElements.define("alchemy-growl", Growl) diff --git a/app/views/alchemy/admin/nodes/_page_nodes.erb b/app/views/alchemy/admin/nodes/_page_nodes.erb new file mode 100644 index 0000000000..e124456b37 --- /dev/null +++ b/app/views/alchemy/admin/nodes/_page_nodes.erb @@ -0,0 +1,50 @@ +<%= turbo_frame_tag("page_nodes") do %> +
+ <%= Alchemy::Node.model_name.human %> + | ++ |
---|---|
<%= "#{node.ancestors.map(&:name).join(" / ")} / #{node.name}" %> | +
+ |
+
<%= Alchemy.t('No menu node for this page found') %> | ++ |