-
-
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.
Merge pull request #2395 from tvdeyen/add-anchors
Allow to add anchors to ingredients
- Loading branch information
Showing
39 changed files
with
634 additions
and
44 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,22 @@ | ||
# frozen_string_literal: true | ||
|
||
module Alchemy | ||
class Api::IngredientsController < Api::BaseController | ||
# Returns all ingredients as json object | ||
# | ||
# You can either load all or only these for :element_id or :page_id param | ||
# | ||
def index | ||
@ingredients = Alchemy::Ingredient.accessible_by(current_ability, :index) | ||
|
||
if params[:page_id].present? | ||
@ingredients = @ingredients | ||
.where(alchemy_page_versions: { page_id: params[:page_id] }) | ||
.merge(Alchemy::PageVersion.drafts) | ||
.joins(element: :page_version) | ||
end | ||
|
||
render json: @ingredients, adapter: :json, root: "ingredients" | ||
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,32 @@ | ||
# frozen_string_literal: true | ||
|
||
module Alchemy | ||
module DomIds | ||
extend ActiveSupport::Concern | ||
|
||
RESERVED_ANCHOR_SETTING_VALUES = %w[false from_value true] | ||
|
||
included do | ||
before_validation :parameterize_dom_id, | ||
if: -> { settings[:anchor].to_s == "true" } | ||
before_validation :set_dom_id_from_value, | ||
if: -> { settings[:anchor].to_s == "from_value" } | ||
before_validation :set_dom_id_to_fixed_value, | ||
if: -> { !RESERVED_ANCHOR_SETTING_VALUES.include? settings[:anchor].to_s } | ||
end | ||
|
||
private | ||
|
||
def parameterize_dom_id | ||
self.dom_id = dom_id&.parameterize | ||
end | ||
|
||
def set_dom_id_from_value | ||
self.dom_id = value&.parameterize | ||
end | ||
|
||
def set_dom_id_to_fixed_value | ||
self.dom_id = settings[:anchor]&.parameterize | ||
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,11 @@ | ||
# frozen_string_literal: true | ||
|
||
module Alchemy | ||
class IngredientSerializer < ActiveModel::Serializer | ||
attributes :id, | ||
:role, | ||
:value, | ||
:element_id, | ||
:data | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<% disabled = ingredient.settings[:anchor].to_s != "true" %> | ||
<%= f.input :dom_id, | ||
disabled: disabled, | ||
hint: disabled && Alchemy.t(:automatic_anchor_notice) %> |
3 changes: 3 additions & 0 deletions
3
app/views/alchemy/admin/ingredients/_headline_fields.html.erb
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,3 @@ | ||
<% if ingredient.settings[:anchor] %> | ||
<%= render "dom_id_fields", f: f, ingredient: ingredient %> | ||
<% 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,3 @@ | ||
<% if ingredient.settings[:anchor] %> | ||
<%= render "dom_id_fields", f: f, ingredient: ingredient %> | ||
<% 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,7 @@ | ||
Alchemy.closeCurrentDialog( | ||
<% if @ingredient.settings[:anchor] %> | ||
function() { | ||
Alchemy.IngredientAnchorLink.updateIcon(<%= @ingredient.id %>, <%= @ingredient.dom_id.present? %>); | ||
} | ||
<% 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
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,9 @@ | ||
<span class="edit-ingredient-anchor-link"> | ||
<%= link_to_dialog render_icon(:bookmark, { style: ingredient_editor.dom_id.present? ? "solid" : "regular" }), | ||
alchemy.edit_admin_ingredient_path(id: ingredient_editor.id), | ||
{ | ||
title: Alchemy.t(:edit_anchor), | ||
size: "380x125" | ||
}, | ||
title: Alchemy.t(:edit_anchor) %> | ||
</span> |
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
Oops, something went wrong.