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 %> + + + + + + <% if @page.nodes.length > 0 %> + <% @page.nodes.each do |node| %> + + + + + <% end %> + <% else %> + + + + + <% end %> +
+ <%= Alchemy::Node.model_name.human %> +
<%= "#{node.ancestors.map(&:name).join(" / ")} / #{node.name}" %> + "> + <%= link_to render_icon(:minus), + admin_node_path(node), + class: "icon_button", + data: { turbo_method: :delete, turbo_confirm: Alchemy.t('confirm_to_delete_node') } %> + +
<%= Alchemy.t('No menu node for this page found') %>
+ +
+ <%= Alchemy.t('Create node on parent:') %> + + <%= alchemy_form_for([:admin, @page.nodes.build], id: "new_node_form") do |f| %> + <%= f.hidden_field :page_id, value: @page.id %> + <%= f.hidden_field :language_id, value: @page.language_id %> + + <%= render Alchemy::Admin::NodeSelect.new(nil, url: alchemy.api_nodes_path(language_id: @page.language_id, include: :ancestors)) do %> + <%= f.text_field :parent_id, class: 'alchemy_selectbox full_width' %> + <% end %> + +
+ +
+ <% end %> +
+ <%= render Alchemy::Admin::Growl.new %> +<% end %> + + diff --git a/app/views/alchemy/admin/nodes/create.html.erb b/app/views/alchemy/admin/nodes/create.html.erb new file mode 100644 index 0000000000..8861fc5769 --- /dev/null +++ b/app/views/alchemy/admin/nodes/create.html.erb @@ -0,0 +1 @@ +<%= render "page_nodes" %> diff --git a/app/views/alchemy/admin/nodes/destroy.html.erb b/app/views/alchemy/admin/nodes/destroy.html.erb new file mode 100644 index 0000000000..8861fc5769 --- /dev/null +++ b/app/views/alchemy/admin/nodes/destroy.html.erb @@ -0,0 +1 @@ +<%= render "page_nodes" %> diff --git a/app/views/alchemy/admin/pages/configure.html.erb b/app/views/alchemy/admin/pages/configure.html.erb index e051a06769..b04b15319d 100644 --- a/app/views/alchemy/admin/pages/configure.html.erb +++ b/app/views/alchemy/admin/pages/configure.html.erb @@ -2,12 +2,18 @@ <%= Alchemy.t('Properties') %> + + (<%= @page.nodes.size %>) <%= Alchemy::Node.model_name.human(count: @page.nodes.size) %> + <%= render 'alchemy/admin/legacy_page_urls/label', count: @page.legacy_urls.size %> <%= render 'form' %> + + <%= render 'alchemy/admin/nodes/page_nodes' %> + <%= render 'legacy_urls' %> diff --git a/config/locales/alchemy.en.yml b/config/locales/alchemy.en.yml index a5a51f2f11..4b2fcebf18 100644 --- a/config/locales/alchemy.en.yml +++ b/config/locales/alchemy.en.yml @@ -250,6 +250,7 @@ en: "Confirm new password": "Confirm new password" "Copy": "Copy" "Could not load Adobe Flash® Plugin!": "Could not load Adobe Flash® Plugin!" + "Create node on parent:": "Create node on parent:" "Currently locked pages": "Currently locked pages" "Default language has to be public": "Default language has to be public" "Delete image": "Delete image" @@ -286,6 +287,7 @@ en: "New": "New" "New Element": "New element" "New page": "New page" + "No menu node for this page found": "No menu node for this page found" "No page links for this page found": "No page links for this page found" "New password": "New password" "New Tag": "New tag"