-
-
Notifications
You must be signed in to change notification settings - Fork 313
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved the link dialog partials into view components
Try to migrate the link dialog partials into view component to make it easier extendable and lesser repetitive. In a later commit it will be configurable to allow other plugins to add their own tabs.
- Loading branch information
1 parent
4eaeebf
commit 856b036
Showing
14 changed files
with
289 additions
and
156 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# frozen_string_literal: true | ||
|
||
module Alchemy | ||
module Admin | ||
module Pages | ||
class AnchorTab < BaseLinkTab | ||
def title | ||
Alchemy.t("link_overlay_tab_label.anchor") | ||
end | ||
|
||
def type | ||
:anchor | ||
end | ||
|
||
def fields | ||
[ | ||
anchor_select, | ||
title_input | ||
] | ||
end | ||
|
||
def message | ||
content_tag("h3", Alchemy.t(:anchor_link_headline)) | ||
end | ||
|
||
private | ||
|
||
def anchor_select | ||
label = label_tag("anchor_link", Alchemy.t(:anchor), class: "control-label") | ||
select = select_tag(:anchor_link, | ||
options_for_select([[Alchemy.t("Please choose"), ""]]), | ||
is: "alchemy-select") | ||
content_tag("div", label + select, class: "input select") | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# frozen_string_literal: true | ||
|
||
module Alchemy | ||
module Admin | ||
module Pages | ||
class BaseLinkTab < ViewComponent::Base | ||
delegate :render_message, to: :helpers | ||
|
||
def initialize(url) | ||
@url = url | ||
end | ||
|
||
def title | ||
raise ArgumentError, "The tab needs to have a title" | ||
end | ||
|
||
def type | ||
raise ArgumentError, "The tab needs to have a panel type" | ||
end | ||
|
||
def fields | ||
[] | ||
end | ||
|
||
def message | ||
nil | ||
end | ||
|
||
def call | ||
content = message ? render_message(:info, message) : "" | ||
content += content_tag("div", content_tag("ul"), id: "errors", class: "errors") | ||
content += fields.join("").html_safe + submit_button | ||
|
||
form = content_tag("form", content.html_safe, {"data-link-form-type": type}) | ||
|
||
panel_name = "overlay_tab_#{type}_link" | ||
content_tag("sl-tab", title, slot: "nav", panel: panel_name, active: type == @tab.to_sym) + | ||
content_tag("sl-tab-panel", form, name: panel_name) | ||
end | ||
|
||
private | ||
|
||
def title_input | ||
name = "#{type}_link_title" | ||
label = label_tag(name, Alchemy.t(:link_title), class: "control-label") | ||
input = text_field_tag name, "", class: "link_title" | ||
content_tag("div", label + input, class: "input text") | ||
end | ||
|
||
def target_select | ||
name = "#{type}_link_target" | ||
label = label_tag(name, Alchemy.t("Open Link in"), class: "control-label") | ||
select = select_tag(name, options_for_select(Alchemy::Page.link_target_options, @target), class: "link_target") | ||
content_tag("div", label + select, class: "input select") | ||
end | ||
|
||
def submit_button | ||
content_tag("div", button_tag(Alchemy.t(:apply)), {class: "submit"}) | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# frozen_string_literal: true | ||
|
||
module Alchemy | ||
module Admin | ||
module Pages | ||
class ExternalTab < BaseLinkTab | ||
def title | ||
Alchemy.t("link_overlay_tab_label.external") | ||
end | ||
|
||
def type | ||
:external | ||
end | ||
|
||
def fields | ||
[ | ||
url_input, | ||
title_input, | ||
target_select | ||
] | ||
end | ||
|
||
def message | ||
content_tag("h3", Alchemy.t(:enter_external_link)) + | ||
content_tag("p", Alchemy.t(:external_link_notice_1)) + | ||
content_tag("p", Alchemy.t(:external_link_notice_2)) | ||
end | ||
|
||
private | ||
|
||
def url_input | ||
label = label_tag("external_link", Alchemy.t(:url), class: "control-label") | ||
input = text_field_tag "external_link", "" | ||
content_tag("div", label + input, class: "input text") | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# frozen_string_literal: true | ||
|
||
module Alchemy | ||
module Admin | ||
module Pages | ||
class FileTab < BaseLinkTab | ||
delegate :alchemy, to: :helpers | ||
|
||
def title | ||
Alchemy.t("link_overlay_tab_label.file") | ||
end | ||
|
||
def type | ||
:file | ||
end | ||
|
||
def fields | ||
[ | ||
attachment_select, | ||
title_input, | ||
target_select | ||
] | ||
end | ||
|
||
def message | ||
content_tag("h3", Alchemy.t(:choose_file_to_link)) | ||
end | ||
|
||
private | ||
|
||
def attachments | ||
@_attachments ||= Attachment.all.collect { |f| | ||
[f.name, alchemy.download_attachment_path(id: f.id, name: f.slug)] | ||
} | ||
end | ||
|
||
def attachment_select | ||
label = label_tag("file_link", Alchemy.t(:file), class: "control-label") | ||
select = select_tag "file_link", | ||
options_for_select(attachments), | ||
prompt: Alchemy.t("Please choose"), | ||
is: "alchemy-select" | ||
content_tag("div", label + select, class: "input select") | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# frozen_string_literal: true | ||
|
||
module Alchemy | ||
module Admin | ||
module Pages | ||
class InternalTab < BaseLinkTab | ||
def title | ||
Alchemy.t("link_overlay_tab_label.internal") | ||
end | ||
|
||
def type | ||
:internal | ||
end | ||
|
||
def fields | ||
[ | ||
page_select, | ||
dom_id_select, | ||
title_input, | ||
target_select | ||
] | ||
end | ||
|
||
def message | ||
content_tag("h3", Alchemy.t(:internal_link_headline)) + | ||
content_tag("p", Alchemy.t(:internal_link_page_elements_explanation)) | ||
end | ||
|
||
private | ||
|
||
def page | ||
@_page ||= @url ? Alchemy::Page.find_by(urlname: URI(@url).path[1..]) : nil | ||
end | ||
|
||
def dom_id_select | ||
label = label_tag("element_anchor", Alchemy.t(:anchor), class: "control-label") | ||
input = text_field_tag("element_anchor", nil, {id: "element_anchor", class: "alchemy_selectbox full_width", disabled: true, placeholder: Alchemy.t("Select a page first")}) | ||
content_tag("div", label + input, class: "input select") | ||
end | ||
|
||
def page_select | ||
label = label_tag("internal_link", Alchemy.t(:page), class: "control-label") | ||
input = text_field_tag("internal_link", page ? @url : "", id: "internal_link") | ||
page_select = render Alchemy::Admin::PageSelect.new(page, allow_clear: true).with_content(input) | ||
content_tag("div", label + page_select, class: "input select") | ||
end | ||
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.