-
-
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
b3569db
commit f3e39a0
Showing
14 changed files
with
169 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
module Alchemy | ||
module Admin | ||
class Growl < ViewComponent::Base | ||
delegate :flash, to: :helpers | ||
attr_reader :message, :type | ||
|
||
def before_render | ||
if flash.any? | ||
key = flash.keys.first | ||
@message = flash[key] | ||
@type = key | ||
|
||
# delete the flash entry if the component is used in a Turbo Frame which can otherwise lead to multiple flash messages after a page reload | ||
flash.delete(key) | ||
end | ||
end | ||
|
||
def call | ||
return unless message | ||
|
||
content_tag("alchemy-growl", nil, {message: message, type: type}) | ||
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
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,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) |
26 changes: 26 additions & 0 deletions
26
app/javascript/alchemy_admin/components/replace_template.js
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,26 @@ | ||
export class ReplaceTemplate extends HTMLElement { | ||
connectedCallback() { | ||
const elementsToReplace = document.querySelectorAll( | ||
`[data-replace-with="${this.for}"]` | ||
) | ||
if (elementsToReplace.length > 0) { | ||
elementsToReplace.forEach((elementToReplace) => { | ||
elementToReplace.innerHTML = this.template.innerHTML | ||
}) | ||
} else { | ||
console.log( | ||
`Couldn't find element to replace for "${this.for}" - identifier!` | ||
) | ||
} | ||
} | ||
|
||
get template() { | ||
return this.querySelector("template") | ||
} | ||
|
||
get for() { | ||
return this.getAttribute("for") | ||
} | ||
} | ||
|
||
customElements.define("alchemy-replace-template", ReplaceTemplate) |
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 @@ | ||
(<%= @page.nodes.size %>) <%= Alchemy::Node.model_name.human(count: @page.nodes.size) %> |
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 @@ | ||
<%= 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> | ||
<% if @page.nodes.length > 0 %> | ||
<% @page.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> | ||
<%= render Alchemy::Admin::Growl.new %> | ||
<alchemy-replace-template for="nodes_label"> | ||
<template> | ||
<%= render 'alchemy/admin/nodes/label', count: @page.reload.nodes.size %> | ||
</template> | ||
</alchemy-replace-template> | ||
<% 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