-
-
Notifications
You must be signed in to change notification settings - Fork 315
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a new menu tab to page configuration dialog. This is a shortcut to create a menu entry for the current page. It is also the first try to provide Turbo Frames inside of Alchemy, which is coming with a few challenges (flash messages, and updated tab headline).
- Loading branch information
1 parent
b7f1b0d
commit 7e4a48e
Showing
11 changed files
with
171 additions
and
6 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
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
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 @@ | ||
(<%= count %>) <%= Alchemy::Node.model_name.human(count: count) %> |
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,59 @@ | ||
<%= turbo_frame_tag("page_nodes") do %> | ||
<table class="list" id="connected_nodes"> | ||
<tr> | ||
<th class="name"> | ||
<%= Alchemy::Node.model_name.human %> | ||
</th> | ||
<th class="tools"></th> | ||
</tr> | ||
<% nodes = @page.nodes.select(&:persisted?) %> | ||
<% if nodes.length > 0 %> | ||
<% nodes.each do |node| %> | ||
<tr class="even"> | ||
<td><%= "#{node.ancestors.map(&:name).join(" / ")} / #{node.name}" %></td> | ||
<td class="tools"> | ||
<sl-tooltip content="<%= Alchemy.t("delete_node") %>"> | ||
<%= link_to render_icon(:minus), | ||
admin_node_path(node), | ||
class: "icon_button", | ||
data: { turbo_method: :delete, turbo_confirm: Alchemy.t('confirm_to_delete_node') } %> | ||
</sl-tooltip> | ||
</td> | ||
</tr> | ||
<% end %> | ||
<% else %> | ||
<tr class="even"> | ||
<td><%= Alchemy.t('No menu node for this page found') %></td> | ||
<td class="tools"></td> | ||
</tr> | ||
<% end %> | ||
</table> | ||
|
||
<fieldset> | ||
<legend><%= Alchemy.t('Create node on parent:') %></legend> | ||
|
||
<%= 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 %> | ||
|
||
<div class="submit"> | ||
<button is="alchemy-button"><%= Alchemy.t(:create_node) %></button> | ||
</div> | ||
<% end %> | ||
</fieldset> | ||
|
||
<script type="module"> | ||
<% if flash.any? %> | ||
<% key = flash.keys.first %> | ||
Alchemy.growl("<%= flash[key] %>", "<%= key %>"); | ||
<% flash.delete(key) %> | ||
<% end %> | ||
document.querySelector('[panel="nodes"]').innerHTML = "<%= j render('alchemy/admin/nodes/label', count: nodes.length) %>" | ||
</script> | ||
<% 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 @@ | ||
<%= render "page_nodes" %> |
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 @@ | ||
<%= render "page_nodes" %> |
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
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,70 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rails_helper" | ||
|
||
RSpec.describe "Nodes management", type: :system, js: true do | ||
before do | ||
authorize_user(:as_admin) | ||
end | ||
|
||
let!(:a_page) { create(:alchemy_page) } | ||
let!(:a_menu) { create(:alchemy_node, name: "Menu") } | ||
|
||
def open_page_properties | ||
visit admin_pages_path | ||
expect(page.find("alchemy-overlay").style("display")["display"]).to have_content("none") | ||
page.find("a[href='#{configure_admin_page_path(a_page)}']", wait: 10).click | ||
find("[panel='nodes']").click | ||
end | ||
|
||
def add_menu_item | ||
find("#new_node_form .select2-choice").click | ||
find(".select2-result:first-child").click | ||
|
||
click_button "Add a menu node" | ||
end | ||
|
||
it "lets a user add a menu node" do | ||
open_page_properties | ||
add_menu_item | ||
|
||
within "#connected_nodes" do | ||
expect(page).to have_content("Menu node Menu / A Page 1") | ||
end | ||
within "[panel='nodes']" do | ||
expect(page).to have_content("(1) Menu node") | ||
end | ||
end | ||
|
||
context "without parent id" do | ||
it "displays error message" do | ||
open_page_properties | ||
|
||
click_button "Add a menu node" | ||
within ".flash.error" do | ||
expect(page).to have_content("Menu Type can't be blank") | ||
end | ||
end | ||
end | ||
|
||
context "with menu node present" do | ||
before do | ||
open_page_properties | ||
add_menu_item | ||
end | ||
|
||
it "lets a user remove a menu node" do | ||
page.accept_alert "Do you really want to delete this menu node?" do | ||
click_link_with_tooltip("Delete this menu node") | ||
end | ||
|
||
within "#connected_nodes" do | ||
expect(page).to_not have_content("Menu node Menu / A Page 1") | ||
expect(page).to have_content(Alchemy.t("No menu node for this page found")) | ||
end | ||
within "[panel='nodes']" do | ||
expect(page).to have_content("(0) Menu nodes") | ||
end | ||
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