alchemy_cms 5.1.4 → 6.0.0.b1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +7 -14
- data/.gitignore +0 -1
- data/.hound.yml +1 -1
- data/.rubocop.yml +46 -4
- data/CHANGELOG.md +112 -5
- data/Gemfile +5 -2
- data/README.md +5 -2
- data/alchemy_cms.gemspec +78 -65
- data/app/assets/javascripts/alchemy/admin.js +0 -2
- data/app/assets/javascripts/alchemy/alchemy.base.js.coffee +0 -27
- data/app/assets/javascripts/alchemy/alchemy.confirm_dialog.js.coffee +2 -1
- data/app/assets/javascripts/alchemy/alchemy.dialog.js.coffee +1 -1
- data/app/assets/javascripts/alchemy/alchemy.dragndrop.js.coffee +0 -25
- data/app/assets/javascripts/alchemy/alchemy.element_editors.js.coffee +1 -1
- data/app/assets/javascripts/alchemy/alchemy.elements_window.js.coffee +2 -0
- data/app/assets/javascripts/alchemy/alchemy.fixed_elements.js +1 -1
- data/app/assets/javascripts/alchemy/alchemy.gui.js.coffee +3 -1
- data/app/assets/javascripts/alchemy/alchemy.image_overlay.coffee +1 -1
- data/app/assets/javascripts/alchemy/alchemy.link_dialog.js.coffee +40 -27
- data/app/assets/javascripts/alchemy/templates/node_folder.hbs +1 -1
- data/app/assets/stylesheets/alchemy/_variables.scss +2 -0
- data/app/assets/stylesheets/alchemy/admin.scss +1 -1
- data/app/assets/stylesheets/alchemy/archive.scss +4 -4
- data/app/assets/stylesheets/alchemy/buttons.scss +0 -4
- data/app/assets/stylesheets/alchemy/elements.scss +111 -66
- data/app/assets/stylesheets/alchemy/images.scss +8 -0
- data/app/assets/stylesheets/alchemy/node-select.scss +4 -3
- data/app/assets/stylesheets/alchemy/page-select.scss +1 -0
- data/app/controllers/alchemy/admin/attachments_controller.rb +6 -2
- data/app/controllers/alchemy/admin/base_controller.rb +5 -6
- data/app/controllers/alchemy/admin/elements_controller.rb +58 -34
- data/app/controllers/alchemy/admin/essence_audios_controller.rb +30 -0
- data/app/controllers/alchemy/admin/essence_files_controller.rb +0 -14
- data/app/controllers/alchemy/admin/essence_pictures_controller.rb +8 -79
- data/app/controllers/alchemy/admin/essence_videos_controller.rb +33 -0
- data/app/controllers/alchemy/admin/ingredients_controller.rb +30 -0
- data/app/controllers/alchemy/admin/layoutpages_controller.rb +0 -1
- data/app/controllers/alchemy/admin/pages_controller.rb +6 -13
- data/app/controllers/alchemy/admin/pictures_controller.rb +35 -9
- data/app/controllers/alchemy/api/elements_controller.rb +10 -5
- data/app/controllers/alchemy/api/pages_controller.rb +3 -4
- data/app/controllers/concerns/alchemy/admin/archive_overlay.rb +13 -3
- data/app/controllers/concerns/alchemy/admin/crop_action.rb +26 -0
- data/app/decorators/alchemy/content_editor.rb +64 -0
- data/app/decorators/alchemy/element_editor.rb +24 -1
- data/app/decorators/alchemy/ingredient_editor.rb +154 -0
- data/app/helpers/alchemy/admin/contents_helper.rb +3 -8
- data/app/helpers/alchemy/admin/elements_helper.rb +1 -0
- data/app/helpers/alchemy/admin/essences_helper.rb +1 -1
- data/app/helpers/alchemy/admin/ingredients_helper.rb +42 -0
- data/app/helpers/alchemy/elements_block_helper.rb +22 -7
- data/app/helpers/alchemy/elements_helper.rb +12 -23
- data/app/helpers/alchemy/pages_helper.rb +3 -9
- data/app/jobs/alchemy/base_job.rb +11 -0
- data/app/jobs/alchemy/publish_page_job.rb +11 -0
- data/app/models/alchemy/attachment.rb +4 -0
- data/app/models/alchemy/content.rb +5 -3
- data/app/models/alchemy/content/factory.rb +23 -27
- data/app/models/alchemy/element.rb +72 -67
- data/app/models/alchemy/element/definitions.rb +26 -41
- data/app/models/alchemy/element/element_contents.rb +131 -122
- data/app/models/alchemy/element/element_essences.rb +100 -98
- data/app/models/alchemy/element/element_ingredients.rb +176 -0
- data/app/models/alchemy/element/presenters.rb +89 -87
- data/app/models/alchemy/elements_repository.rb +126 -0
- data/app/models/alchemy/essence_audio.rb +12 -0
- data/app/models/alchemy/essence_headline.rb +40 -0
- data/app/models/alchemy/essence_picture.rb +4 -116
- data/app/models/alchemy/essence_richtext.rb +12 -0
- data/app/models/alchemy/essence_video.rb +12 -0
- data/app/models/alchemy/image_cropper_settings.rb +87 -0
- data/app/models/alchemy/ingredient.rb +219 -0
- data/app/models/alchemy/ingredient_validator.rb +97 -0
- data/app/models/alchemy/ingredients/audio.rb +29 -0
- data/app/models/alchemy/ingredients/boolean.rb +21 -0
- data/app/models/alchemy/ingredients/datetime.rb +20 -0
- data/app/models/alchemy/ingredients/file.rb +30 -0
- data/app/models/alchemy/ingredients/headline.rb +42 -0
- data/app/models/alchemy/ingredients/html.rb +19 -0
- data/app/models/alchemy/ingredients/link.rb +16 -0
- data/app/models/alchemy/ingredients/node.rb +23 -0
- data/app/models/alchemy/ingredients/page.rb +23 -0
- data/app/models/alchemy/ingredients/picture.rb +41 -0
- data/app/models/alchemy/ingredients/richtext.rb +57 -0
- data/app/models/alchemy/ingredients/select.rb +10 -0
- data/app/models/alchemy/ingredients/text.rb +17 -0
- data/app/models/alchemy/ingredients/video.rb +33 -0
- data/app/models/alchemy/language.rb +0 -11
- data/app/models/alchemy/page.rb +66 -32
- data/app/models/alchemy/page/fixed_attributes.rb +53 -51
- data/app/models/alchemy/page/page_elements.rb +187 -199
- data/app/models/alchemy/page/page_naming.rb +66 -64
- data/app/models/alchemy/page/page_natures.rb +139 -142
- data/app/models/alchemy/page/page_scopes.rb +113 -102
- data/app/models/alchemy/page/publisher.rb +50 -0
- data/app/models/alchemy/page/url_path.rb +1 -1
- data/app/models/alchemy/page_version.rb +58 -0
- data/app/models/alchemy/picture.rb +3 -1
- data/app/models/alchemy/picture/calculations.rb +2 -8
- data/app/models/alchemy/picture/preprocessor.rb +2 -0
- data/app/models/alchemy/picture/transformations.rb +24 -96
- data/app/models/alchemy/picture_variant.rb +1 -1
- data/app/models/concerns/alchemy/picture_thumbnails.rb +181 -0
- data/app/models/concerns/alchemy/touch_elements.rb +2 -2
- data/app/presenters/alchemy/picture_view.rb +88 -0
- data/app/serializers/alchemy/element_serializer.rb +5 -0
- data/app/serializers/alchemy/page_tree_serializer.rb +3 -2
- data/app/services/alchemy/delete_elements.rb +44 -0
- data/app/services/alchemy/duplicate_element.rb +56 -0
- data/app/views/alchemy/admin/attachments/_archive_overlay.html.erb +1 -2
- data/app/views/alchemy/admin/attachments/_file_to_assign.html.erb +3 -3
- data/app/views/alchemy/admin/attachments/assign.js.erb +11 -0
- data/app/views/alchemy/admin/crop.html.erb +36 -0
- data/app/views/alchemy/admin/elements/_element.html.erb +14 -10
- data/app/views/alchemy/admin/elements/{_element_footer.html.erb → _footer.html.erb} +0 -0
- data/app/views/alchemy/admin/elements/{_new_element_form.html.erb → _form.html.erb} +1 -1
- data/app/views/alchemy/admin/elements/{_element_header.html.erb → _header.html.erb} +3 -1
- data/app/views/alchemy/admin/elements/{_element_toolbar.html.erb → _toolbar.html.erb} +5 -6
- data/app/views/alchemy/admin/elements/{trash.js.erb → destroy.js.erb} +1 -3
- data/app/views/alchemy/admin/elements/new.html.erb +3 -3
- data/app/views/alchemy/admin/elements/order.js.erb +0 -17
- data/app/views/alchemy/admin/elements/update.js.erb +3 -2
- data/app/views/alchemy/admin/essence_audios/edit.html.erb +7 -0
- data/app/views/alchemy/admin/essence_pictures/update.js.erb +0 -1
- data/app/views/alchemy/admin/essence_videos/edit.html.erb +11 -0
- data/app/views/alchemy/admin/ingredients/_audio_fields.html.erb +4 -0
- data/app/views/alchemy/admin/ingredients/_file_fields.html.erb +18 -0
- data/app/views/alchemy/admin/ingredients/_picture_fields.html.erb +25 -0
- data/app/views/alchemy/admin/ingredients/_video_fields.html.erb +8 -0
- data/app/views/alchemy/admin/ingredients/edit.html.erb +4 -0
- data/app/views/alchemy/admin/layoutpages/edit.html.erb +0 -5
- data/app/views/alchemy/admin/nodes/_node.html.erb +2 -2
- data/app/views/alchemy/admin/pages/_anchor_link.html.erb +1 -1
- data/app/views/alchemy/admin/pages/_external_link.html.erb +1 -1
- data/app/views/alchemy/admin/pages/_file_link.html.erb +1 -1
- data/app/views/alchemy/admin/pages/_form.html.erb +0 -6
- data/app/views/alchemy/admin/pages/_internal_link.html.erb +1 -1
- data/app/views/alchemy/admin/pages/_tinymce_custom_config.html.erb +5 -2
- data/app/views/alchemy/admin/pages/edit.html.erb +36 -24
- data/app/views/alchemy/admin/partials/_remote_search_form.html.erb +2 -4
- data/app/views/alchemy/admin/partials/_routes.html.erb +7 -11
- data/app/views/alchemy/admin/pictures/_filter_and_size_bar.html.erb +4 -8
- data/app/views/alchemy/admin/pictures/_infos.html.erb +0 -1
- data/app/views/alchemy/admin/pictures/_picture_to_assign.html.erb +4 -4
- data/app/views/alchemy/admin/pictures/assign.js.erb +10 -0
- data/app/views/alchemy/admin/resources/_form.html.erb +1 -0
- data/app/views/alchemy/essences/_essence_audio_editor.html.erb +4 -0
- data/app/views/alchemy/essences/_essence_audio_view.html.erb +15 -0
- data/app/views/alchemy/essences/_essence_file_editor.html.erb +15 -6
- data/app/views/alchemy/essences/_essence_headline_editor.html.erb +36 -0
- data/app/views/alchemy/essences/_essence_headline_view.html.erb +10 -0
- data/app/views/alchemy/essences/_essence_link_editor.html.erb +8 -4
- data/app/views/alchemy/essences/_essence_picture_editor.html.erb +27 -12
- data/app/views/alchemy/essences/_essence_picture_view.html.erb +3 -3
- data/app/views/alchemy/essences/_essence_text_editor.html.erb +12 -4
- data/app/views/alchemy/essences/_essence_video_editor.html.erb +4 -0
- data/app/views/alchemy/essences/_essence_video_view.html.erb +18 -0
- data/app/views/alchemy/essences/shared/_essence_picture_tools.html.erb +21 -16
- data/app/views/alchemy/essences/shared/_linkable_essence_tools.html.erb +2 -2
- data/app/views/alchemy/ingredients/_audio_editor.html.erb +5 -0
- data/app/views/alchemy/ingredients/_audio_view.html.erb +14 -0
- data/app/views/alchemy/ingredients/_boolean_editor.html.erb +11 -0
- data/app/views/alchemy/ingredients/_boolean_view.html.erb +1 -0
- data/app/views/alchemy/ingredients/_datetime_editor.html.erb +17 -0
- data/app/views/alchemy/ingredients/_datetime_view.html.erb +9 -0
- data/app/views/alchemy/ingredients/_file_editor.html.erb +50 -0
- data/app/views/alchemy/ingredients/_file_view.html.erb +17 -0
- data/app/views/alchemy/ingredients/_headline_editor.html.erb +30 -0
- data/app/views/alchemy/ingredients/_headline_view.html.erb +9 -0
- data/app/views/alchemy/ingredients/_html_editor.html.erb +8 -0
- data/app/views/alchemy/ingredients/_html_view.html.erb +1 -0
- data/app/views/alchemy/ingredients/_link_editor.html.erb +24 -0
- data/app/views/alchemy/ingredients/_link_view.html.erb +9 -0
- data/app/views/alchemy/ingredients/_node_editor.html.erb +25 -0
- data/app/views/alchemy/ingredients/_node_view.html.erb +1 -0
- data/app/views/alchemy/ingredients/_page_editor.html.erb +24 -0
- data/app/views/alchemy/ingredients/_page_view.html.erb +4 -0
- data/app/views/alchemy/ingredients/_picture_editor.html.erb +59 -0
- data/app/views/alchemy/ingredients/_picture_view.html.erb +5 -0
- data/app/views/alchemy/ingredients/_richtext_editor.html.erb +12 -0
- data/app/views/alchemy/ingredients/_richtext_view.html.erb +3 -0
- data/app/views/alchemy/ingredients/_select_editor.html.erb +29 -0
- data/app/views/alchemy/ingredients/_select_view.html.erb +1 -0
- data/app/views/alchemy/ingredients/_text_editor.html.erb +19 -0
- data/app/views/alchemy/ingredients/_text_view.html.erb +16 -0
- data/app/views/alchemy/ingredients/_video_editor.html.erb +5 -0
- data/app/views/alchemy/ingredients/_video_view.html.erb +17 -0
- data/app/views/alchemy/ingredients/shared/_link_tools.html.erb +20 -0
- data/app/views/alchemy/ingredients/shared/_picture_tools.html.erb +57 -0
- data/config/brakeman.ignore +212 -17
- data/config/initializers/dragonfly.rb +10 -0
- data/config/locales/alchemy.en.yml +63 -39
- data/config/routes.rb +17 -22
- data/db/migrate/20201207131309_create_page_versions.rb +19 -0
- data/db/migrate/20201207135820_add_page_version_id_to_alchemy_elements.rb +76 -0
- data/db/migrate/20210205143548_rename_public_on_and_public_until_on_alchemy_pages.rb +10 -0
- data/db/migrate/20210326105046_add_sanitized_body_to_alchemy_essence_richtexts.rb +7 -0
- data/db/migrate/20210406093436_add_alchemy_essence_headlines.rb +12 -0
- data/db/migrate/20210506135919_create_essence_audios.rb +19 -0
- data/db/migrate/20210506140258_create_essence_videos.rb +23 -0
- data/db/migrate/20210508091432_create_alchemy_ingredients.rb +22 -0
- data/lib/alchemy/admin/preview_url.rb +2 -0
- data/lib/alchemy/deprecation.rb +1 -1
- data/lib/alchemy/dragonfly/processors/auto_orient.rb +18 -0
- data/lib/alchemy/dragonfly/processors/crop_resize.rb +35 -0
- data/lib/alchemy/element_definition.rb +70 -0
- data/lib/alchemy/elements_finder.rb +14 -56
- data/lib/alchemy/essence.rb +5 -6
- data/lib/alchemy/filetypes.rb +13 -0
- data/lib/alchemy/forms/builder.rb +1 -1
- data/lib/alchemy/hints.rb +8 -4
- data/lib/alchemy/i18n.rb +4 -5
- data/lib/alchemy/page_layout.rb +0 -12
- data/lib/alchemy/permissions.rb +30 -29
- data/lib/alchemy/resource.rb +13 -3
- data/lib/alchemy/tasks/tidy.rb +29 -0
- data/lib/alchemy/test_support.rb +9 -0
- data/lib/alchemy/test_support/essence_shared_examples.rb +0 -4
- data/lib/alchemy/test_support/factories/attachment_factory.rb +0 -2
- data/lib/alchemy/test_support/factories/content_factory.rb +0 -6
- data/lib/alchemy/test_support/factories/dummy_user_factory.rb +0 -2
- data/lib/alchemy/test_support/factories/element_factory.rb +8 -11
- data/lib/alchemy/test_support/factories/essence_audio_factory.rb +7 -0
- data/lib/alchemy/test_support/factories/essence_file_factory.rb +0 -3
- data/lib/alchemy/test_support/factories/essence_page_factory.rb +0 -3
- data/lib/alchemy/test_support/factories/essence_picture_factory.rb +0 -4
- data/lib/alchemy/test_support/factories/essence_text_factory.rb +0 -2
- data/lib/alchemy/test_support/factories/essence_video_factory.rb +7 -0
- data/lib/alchemy/test_support/factories/ingredient_factory.rb +25 -0
- data/lib/alchemy/test_support/factories/language_factory.rb +0 -3
- data/lib/alchemy/test_support/factories/node_factory.rb +0 -4
- data/lib/alchemy/test_support/factories/page_factory.rb +20 -4
- data/lib/alchemy/test_support/factories/page_version_factory.rb +23 -0
- data/lib/alchemy/test_support/factories/picture_factory.rb +0 -2
- data/lib/alchemy/test_support/factories/picture_thumb_factory.rb +0 -3
- data/lib/alchemy/test_support/factories/site_factory.rb +0 -2
- data/lib/alchemy/test_support/having_crop_action_examples.rb +170 -0
- data/lib/alchemy/test_support/having_picture_thumbnails_examples.rb +646 -0
- data/lib/alchemy/test_support/integration_helpers.rb +5 -5
- data/lib/alchemy/test_support/shared_ingredient_editor_examples.rb +21 -0
- data/lib/alchemy/test_support/shared_ingredient_examples.rb +57 -0
- data/lib/alchemy/tinymce.rb +17 -0
- data/lib/alchemy/upgrader/six_point_zero.rb +21 -0
- data/lib/alchemy/upgrader/tasks/add_page_versions.rb +33 -0
- data/lib/alchemy/upgrader/tasks/ingredients_migrator.rb +51 -0
- data/lib/alchemy/version.rb +1 -1
- data/lib/alchemy_cms.rb +1 -0
- data/lib/generators/alchemy/elements/elements_generator.rb +1 -0
- data/lib/generators/alchemy/elements/templates/view.html.erb +9 -0
- data/lib/generators/alchemy/elements/templates/view.html.haml +9 -0
- data/lib/generators/alchemy/elements/templates/view.html.slim +9 -0
- data/lib/generators/alchemy/ingredient/ingredient_generator.rb +38 -0
- data/lib/generators/alchemy/ingredient/templates/editor.html.erb +14 -0
- data/lib/generators/alchemy/ingredient/templates/model.rb.tt +13 -0
- data/lib/generators/alchemy/ingredient/templates/view.html.erb +1 -0
- data/lib/generators/alchemy/install/templates/dragonfly.rb.tt +1 -1
- data/lib/tasks/alchemy/thumbnails.rake +2 -0
- data/lib/tasks/alchemy/tidy.rake +12 -0
- data/lib/tasks/alchemy/upgrade.rake +26 -0
- data/package.json +2 -1
- data/package/admin.js +11 -1
- data/package/src/__tests__/i18n.spec.js +23 -0
- data/package/src/file_editors.js +28 -0
- data/package/src/i18n.js +1 -3
- data/package/src/image_cropper.js +103 -0
- data/package/src/image_loader.js +58 -0
- data/package/src/node_tree.js +5 -5
- data/package/src/picture_editors.js +169 -0
- data/package/src/utils/__tests__/ajax.spec.js +20 -12
- data/package/src/utils/ajax.js +8 -3
- data/vendor/assets/javascripts/jquery_plugins/jquery.Jcrop.min.js +3 -18
- data/vendor/assets/stylesheets/jquery.Jcrop.min.scss +2 -28
- metadata +290 -52
- data/app/assets/javascripts/alchemy/alchemy.image_cropper.js.coffee +0 -44
- data/app/assets/javascripts/alchemy/alchemy.trash_window.js.coffee +0 -30
- data/app/assets/stylesheets/alchemy/trash.scss +0 -8
- data/app/controllers/alchemy/admin/trash_controller.rb +0 -42
- data/app/views/alchemy/admin/essence_files/assign.js.erb +0 -3
- data/app/views/alchemy/admin/essence_pictures/assign.js.erb +0 -4
- data/app/views/alchemy/admin/essence_pictures/crop.html.erb +0 -48
- data/app/views/alchemy/admin/trash/clear.js.erb +0 -4
- data/app/views/alchemy/admin/trash/index.html.erb +0 -31
- data/lib/alchemy/test_support/factories.rb +0 -5
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Alchemy
|
4
|
+
module Admin
|
5
|
+
class IngredientsController < Alchemy::Admin::BaseController
|
6
|
+
load_and_authorize_resource class: Alchemy::Ingredient
|
7
|
+
|
8
|
+
include CropAction
|
9
|
+
|
10
|
+
helper "Alchemy::Admin::Ingredients"
|
11
|
+
|
12
|
+
def edit
|
13
|
+
end
|
14
|
+
|
15
|
+
def update
|
16
|
+
@ingredient.update(ingredient_params)
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def ingredient_params
|
22
|
+
params.require(:ingredient).permit(@ingredient.class.stored_attributes[:data])
|
23
|
+
end
|
24
|
+
|
25
|
+
def load_croppable_resource
|
26
|
+
@croppable_resource = @ingredient
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -33,6 +33,8 @@ module Alchemy
|
|
33
33
|
|
34
34
|
before_action :set_view, only: [:index]
|
35
35
|
|
36
|
+
before_action :set_page_version, only: [:show, :edit]
|
37
|
+
|
36
38
|
def index
|
37
39
|
@query = @current_language.pages.contentpages.ransack(search_filter_params[:q])
|
38
40
|
|
@@ -118,7 +120,6 @@ module Alchemy
|
|
118
120
|
|
119
121
|
# Set page configuration like page names, meta tags and states.
|
120
122
|
def configure
|
121
|
-
@page_layouts = PageLayout.layouts_with_own_for_select(@page.page_layout, @current_language.id, @page.layoutpage?)
|
122
123
|
end
|
123
124
|
|
124
125
|
# Updates page
|
@@ -191,24 +192,12 @@ module Alchemy
|
|
191
192
|
end
|
192
193
|
end
|
193
194
|
|
194
|
-
def visit
|
195
|
-
@page.unlock!
|
196
|
-
redirect_to show_page_url(
|
197
|
-
urlname: @page.urlname,
|
198
|
-
locale: prefix_locale? ? @page.language_code : nil,
|
199
|
-
host: @page.site.host == "*" ? request.host : @page.site.host,
|
200
|
-
)
|
201
|
-
end
|
202
|
-
|
203
195
|
# Sets the page public and updates the published_at attribute that is used as cache_key
|
204
196
|
#
|
205
197
|
def publish
|
206
198
|
# fetching page via before filter
|
207
199
|
@page.publish!
|
208
200
|
|
209
|
-
# Send publish notification to all registered publish targets
|
210
|
-
Alchemy.publish_targets.each { |p| p.perform_later(@page) }
|
211
|
-
|
212
201
|
flash[:notice] = Alchemy.t(:page_published, name: @page.name)
|
213
202
|
redirect_back(fallback_location: admin_pages_path)
|
214
203
|
end
|
@@ -403,6 +392,10 @@ module Alchemy
|
|
403
392
|
@page_root = @current_language.root_page
|
404
393
|
end
|
405
394
|
|
395
|
+
def set_page_version
|
396
|
+
@page_version = @page.draft_version
|
397
|
+
end
|
398
|
+
|
406
399
|
def serialized_page_tree
|
407
400
|
PageTreeSerializer.new(@page, ability: current_ability,
|
408
401
|
user: current_alchemy_user,
|
@@ -9,12 +9,16 @@ module Alchemy
|
|
9
9
|
helper "alchemy/admin/tags"
|
10
10
|
|
11
11
|
before_action :load_resource,
|
12
|
-
only: [:show, :edit, :update, :destroy, :info]
|
12
|
+
only: [:show, :edit, :update, :url, :destroy, :info]
|
13
13
|
|
14
14
|
before_action :set_size, only: [:index, :show, :edit_multiple]
|
15
15
|
|
16
16
|
authorize_resource class: Alchemy::Picture
|
17
17
|
|
18
|
+
before_action(only: :assign) do
|
19
|
+
@picture = Picture.find(params[:id])
|
20
|
+
end
|
21
|
+
|
18
22
|
def index
|
19
23
|
@query = Picture.ransack(search_filter_params[:q])
|
20
24
|
@pictures = Picture.search_by(
|
@@ -32,10 +36,21 @@ module Alchemy
|
|
32
36
|
def show
|
33
37
|
@previous = @picture.previous(params)
|
34
38
|
@next = @picture.next(params)
|
35
|
-
@assignments = @picture.essence_pictures.joins(content: {element: :page})
|
39
|
+
@assignments = @picture.essence_pictures.joins(content: { element: :page })
|
36
40
|
render action: "show"
|
37
41
|
end
|
38
42
|
|
43
|
+
def url
|
44
|
+
options = picture_url_params.to_h.symbolize_keys.transform_values! do |value|
|
45
|
+
value.in?(%w[true false]) ? value == "true" : value
|
46
|
+
end
|
47
|
+
render json: {
|
48
|
+
url: @picture.url(options),
|
49
|
+
alt: @picture.name,
|
50
|
+
title: Alchemy.t(:image_name, name: @picture.name),
|
51
|
+
}
|
52
|
+
end
|
53
|
+
|
39
54
|
def create
|
40
55
|
@picture = Picture.new(picture_params)
|
41
56
|
@picture.name = @picture.humanized_name
|
@@ -125,8 +140,8 @@ module Alchemy
|
|
125
140
|
end
|
126
141
|
else
|
127
142
|
cookies[:alchemy_pictures_per_page] = params[:per_page] ||
|
128
|
-
|
129
|
-
|
143
|
+
cookies[:alchemy_pictures_per_page] ||
|
144
|
+
pictures_per_page_for_size
|
130
145
|
end
|
131
146
|
end
|
132
147
|
|
@@ -158,17 +173,28 @@ module Alchemy
|
|
158
173
|
def search_filter_params
|
159
174
|
@_search_filter_params ||= params.except(*COMMON_SEARCH_FILTER_EXCLUDES + [:picture_ids]).permit(
|
160
175
|
*common_search_filter_includes + [
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
:content_id,
|
165
|
-
],
|
176
|
+
:size,
|
177
|
+
:form_field_id,
|
178
|
+
],
|
166
179
|
)
|
167
180
|
end
|
168
181
|
|
169
182
|
def picture_params
|
170
183
|
params.require(:picture).permit(:image_file, :upload_hash, :name, :tag_list)
|
171
184
|
end
|
185
|
+
|
186
|
+
def picture_url_params
|
187
|
+
params.permit(
|
188
|
+
:crop_from,
|
189
|
+
:crop_size,
|
190
|
+
:crop,
|
191
|
+
:flatten,
|
192
|
+
:format,
|
193
|
+
:quality,
|
194
|
+
:size,
|
195
|
+
:upsample
|
196
|
+
)
|
197
|
+
end
|
172
198
|
end
|
173
199
|
end
|
174
200
|
end
|
@@ -9,18 +9,21 @@ module Alchemy
|
|
9
9
|
# If you want to only load a specific type of element pass ?named=an_element_name
|
10
10
|
#
|
11
11
|
def index
|
12
|
-
|
12
|
+
if params[:page_id].present?
|
13
|
+
@page = Page.find(params[:page_id])
|
14
|
+
@elements = @page.elements.not_nested
|
15
|
+
else
|
16
|
+
@elements = Element.not_nested.joins(:page_version).merge(PageVersion.published)
|
17
|
+
end
|
18
|
+
|
13
19
|
# Fix for cancancan not able to merge multiple AR scopes for logged in users
|
14
20
|
if cannot? :manage, Alchemy::Element
|
15
21
|
@elements = @elements.accessible_by(current_ability, :index)
|
16
22
|
end
|
17
|
-
if params[:page_id].present?
|
18
|
-
@elements = @elements.where(page_id: params[:page_id])
|
19
|
-
end
|
20
23
|
if params[:named].present?
|
21
24
|
@elements = @elements.named(params[:named])
|
22
25
|
end
|
23
|
-
@elements = @elements.includes(*element_includes)
|
26
|
+
@elements = @elements.includes(*element_includes).order(:position)
|
24
27
|
|
25
28
|
render json: @elements, adapter: :json, root: "elements"
|
26
29
|
end
|
@@ -43,6 +46,7 @@ module Alchemy
|
|
43
46
|
contents: {
|
44
47
|
essence: :ingredient_association,
|
45
48
|
},
|
49
|
+
ingredients: :related_object,
|
46
50
|
},
|
47
51
|
:tags,
|
48
52
|
],
|
@@ -51,6 +55,7 @@ module Alchemy
|
|
51
55
|
contents: {
|
52
56
|
essence: :ingredient_association,
|
53
57
|
},
|
58
|
+
ingredients: :related_object,
|
54
59
|
},
|
55
60
|
:tags,
|
56
61
|
]
|
@@ -7,11 +7,10 @@ module Alchemy
|
|
7
7
|
# Returns all pages as json object
|
8
8
|
#
|
9
9
|
def index
|
10
|
+
@pages = Language.current&.pages.presence || Alchemy::Page.none
|
10
11
|
# Fix for cancancan not able to merge multiple AR scopes for logged in users
|
11
|
-
if
|
12
|
-
@pages =
|
13
|
-
else
|
14
|
-
@pages = Page.accessible_by(current_ability, :index)
|
12
|
+
if cannot? :edit_content, Alchemy::Page
|
13
|
+
@pages = @pages.accessible_by(current_ability, :index)
|
15
14
|
end
|
16
15
|
@pages = @pages.includes(*page_includes)
|
17
16
|
@pages = @pages.ransack(params[:q]).result
|
@@ -2,18 +2,28 @@
|
|
2
2
|
module Alchemy
|
3
3
|
module Admin
|
4
4
|
module ArchiveOverlay
|
5
|
+
# Sets assignable id on given form field via JS.
|
6
|
+
#
|
7
|
+
# When the user saves the model the assignable
|
8
|
+
# gets persisted with the model as well.
|
9
|
+
#
|
10
|
+
def assign
|
11
|
+
@assignable_id = params[:id]
|
12
|
+
@form_field_id = params[:form_field_id]
|
13
|
+
end
|
14
|
+
|
5
15
|
private
|
6
16
|
|
7
17
|
def in_overlay?
|
8
|
-
params[:
|
18
|
+
params[:form_field_id].present?
|
9
19
|
end
|
10
20
|
|
11
21
|
def archive_overlay
|
12
|
-
@
|
22
|
+
@form_field_id = params[:form_field_id]
|
13
23
|
|
14
24
|
respond_to do |format|
|
15
25
|
format.html { render partial: "archive_overlay" }
|
16
|
-
format.js
|
26
|
+
format.js { render action: "archive_overlay" }
|
17
27
|
end
|
18
28
|
end
|
19
29
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Alchemy
|
4
|
+
module Admin
|
5
|
+
module CropAction
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
included do
|
9
|
+
before_action :load_croppable_resource, only: [:crop]
|
10
|
+
end
|
11
|
+
|
12
|
+
def crop
|
13
|
+
@picture = Alchemy::Picture.find_by(id: params[:picture_id])
|
14
|
+
if @picture
|
15
|
+
@croppable_resource.picture = @picture
|
16
|
+
@settings = @croppable_resource.image_cropper_settings
|
17
|
+
@element = @croppable_resource.element
|
18
|
+
else
|
19
|
+
@no_image_notice = Alchemy.t(:no_image_for_cropper_found)
|
20
|
+
end
|
21
|
+
|
22
|
+
render template: "alchemy/admin/crop"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -12,6 +12,7 @@ module Alchemy
|
|
12
12
|
[
|
13
13
|
"content_editor",
|
14
14
|
essence_partial_name,
|
15
|
+
deprecated? ? "deprecated" : nil,
|
15
16
|
].compact
|
16
17
|
end
|
17
18
|
|
@@ -51,5 +52,68 @@ module Alchemy
|
|
51
52
|
|
52
53
|
super
|
53
54
|
end
|
55
|
+
|
56
|
+
def has_warnings?
|
57
|
+
definition.blank? || deprecated?
|
58
|
+
end
|
59
|
+
|
60
|
+
def warnings
|
61
|
+
return unless has_warnings?
|
62
|
+
|
63
|
+
if definition.blank?
|
64
|
+
Logger.warn("Content #{name} is missing its definition", caller(1..1))
|
65
|
+
Alchemy.t(:content_definition_missing)
|
66
|
+
else
|
67
|
+
deprecation_notice
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
# Returns a deprecation notice for contents marked deprecated
|
72
|
+
#
|
73
|
+
# You can either use localizations or pass a String as notice
|
74
|
+
# in the content definition.
|
75
|
+
#
|
76
|
+
# == Custom deprecation notices
|
77
|
+
#
|
78
|
+
# Use general content deprecation notice
|
79
|
+
#
|
80
|
+
# - name: element_name
|
81
|
+
# contents:
|
82
|
+
# - name: old_content
|
83
|
+
# type: EssenceText
|
84
|
+
# deprecated: true
|
85
|
+
#
|
86
|
+
# Add a translation to your locale file for a per content notice.
|
87
|
+
#
|
88
|
+
# en:
|
89
|
+
# alchemy:
|
90
|
+
# content_deprecation_notices:
|
91
|
+
# element_name:
|
92
|
+
# old_content: Foo baz widget is deprecated
|
93
|
+
#
|
94
|
+
# or use the global translation that apply to all deprecated contents.
|
95
|
+
#
|
96
|
+
# en:
|
97
|
+
# alchemy:
|
98
|
+
# content_deprecation_notice: Foo baz widget is deprecated
|
99
|
+
#
|
100
|
+
# or pass string as deprecation notice.
|
101
|
+
#
|
102
|
+
# - name: element_name
|
103
|
+
# contents:
|
104
|
+
# - name: old_content
|
105
|
+
# type: EssenceText
|
106
|
+
# deprecated: This content will be removed soon.
|
107
|
+
#
|
108
|
+
def deprecation_notice
|
109
|
+
case definition["deprecated"]
|
110
|
+
when String
|
111
|
+
definition["deprecated"]
|
112
|
+
when TrueClass
|
113
|
+
Alchemy.t(name,
|
114
|
+
scope: [:content_deprecation_notices, element.name],
|
115
|
+
default: Alchemy.t(:content_deprecated))
|
116
|
+
end
|
117
|
+
end
|
54
118
|
end
|
55
119
|
end
|
@@ -19,6 +19,23 @@ module Alchemy
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
+
# Returns ingredient editor instances for defined ingredients
|
23
|
+
#
|
24
|
+
# Creates ingredient on demand if the ingredient is not yet present on the element
|
25
|
+
#
|
26
|
+
# @return Array<Alchemy::IngredientEditor>
|
27
|
+
def ingredients
|
28
|
+
element.definition.fetch(:ingredients, []).map do |ingredient|
|
29
|
+
Alchemy::IngredientEditor.new(find_or_create_ingredient(ingredient[:role]))
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# Are any ingredients defined?
|
34
|
+
# @return [Boolean]
|
35
|
+
def has_ingredients_defined?
|
36
|
+
element.definition.fetch(:ingredients, []).any?
|
37
|
+
end
|
38
|
+
|
22
39
|
# CSS classes for the element editor partial.
|
23
40
|
def css_classes
|
24
41
|
[
|
@@ -28,6 +45,7 @@ module Alchemy
|
|
28
45
|
taggable? ? "taggable" : "not-taggable",
|
29
46
|
folded ? "folded" : "expanded",
|
30
47
|
compact? ? "compact" : nil,
|
48
|
+
deprecated? ? "deprecated" : nil,
|
31
49
|
fixed? ? "is-fixed" : "not-fixed",
|
32
50
|
public? ? "visible" : "hidden",
|
33
51
|
].join(" ")
|
@@ -37,7 +55,7 @@ module Alchemy
|
|
37
55
|
def editable?
|
38
56
|
return false if folded?
|
39
57
|
|
40
|
-
content_definitions.present? || taggable?
|
58
|
+
content_definitions.present? || ingredient_definitions.any? || taggable?
|
41
59
|
end
|
42
60
|
|
43
61
|
# Fixes Rails partial renderer calling to_model on the object
|
@@ -102,5 +120,10 @@ module Alchemy
|
|
102
120
|
def create_content(name)
|
103
121
|
Alchemy::Content.create(element: element, name: name)
|
104
122
|
end
|
123
|
+
|
124
|
+
def find_or_create_ingredient(role)
|
125
|
+
element.ingredients.find { |i| i.role == role } ||
|
126
|
+
Ingredient.create(element: element, role: role)
|
127
|
+
end
|
105
128
|
end
|
106
129
|
end
|
@@ -0,0 +1,154 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Alchemy
|
4
|
+
class IngredientEditor < SimpleDelegator
|
5
|
+
alias_method :ingredient, :__getobj__
|
6
|
+
|
7
|
+
def to_partial_path
|
8
|
+
"alchemy/ingredients/#{partial_name}_editor"
|
9
|
+
end
|
10
|
+
|
11
|
+
# Returns the translated role for displaying in labels
|
12
|
+
#
|
13
|
+
# Translate it in your locale yml file:
|
14
|
+
#
|
15
|
+
# alchemy:
|
16
|
+
# ingredient_roles:
|
17
|
+
# foo: Bar
|
18
|
+
#
|
19
|
+
# Optionally you can scope your ingredient role to an element:
|
20
|
+
#
|
21
|
+
# alchemy:
|
22
|
+
# ingredient_roles:
|
23
|
+
# article:
|
24
|
+
# foo: Baz
|
25
|
+
#
|
26
|
+
def translated_role
|
27
|
+
Alchemy.t(
|
28
|
+
role,
|
29
|
+
scope: "ingredient_roles.#{element.name}",
|
30
|
+
default: Alchemy.t("ingredient_roles.#{role}", default: role.humanize),
|
31
|
+
)
|
32
|
+
end
|
33
|
+
|
34
|
+
def css_classes
|
35
|
+
[
|
36
|
+
"ingredient-editor",
|
37
|
+
partial_name,
|
38
|
+
deprecated? ? "deprecated" : nil,
|
39
|
+
].compact
|
40
|
+
end
|
41
|
+
|
42
|
+
def data_attributes
|
43
|
+
{
|
44
|
+
ingredient_id: id,
|
45
|
+
ingredient_role: role,
|
46
|
+
}
|
47
|
+
end
|
48
|
+
|
49
|
+
# Returns a string to be passed to Rails form field tags to ensure it can be used with Rails' nested attributes.
|
50
|
+
#
|
51
|
+
# === Example:
|
52
|
+
#
|
53
|
+
# <%= text_field_tag text_editor.form_field_name, text_editor.value %>
|
54
|
+
#
|
55
|
+
# === Options:
|
56
|
+
#
|
57
|
+
# You can pass an Ingredient column_name. Default is 'value'
|
58
|
+
#
|
59
|
+
# ==== Example:
|
60
|
+
#
|
61
|
+
# <%= text_field_tag text_editor.form_field_name(:link), text_editor.value %>
|
62
|
+
#
|
63
|
+
def form_field_name(column = "value")
|
64
|
+
"element[ingredients_attributes][#{form_field_counter}][#{column}]"
|
65
|
+
end
|
66
|
+
|
67
|
+
def form_field_id(column = "value")
|
68
|
+
"element_ingredients_attributes_#{form_field_counter}_#{column}"
|
69
|
+
end
|
70
|
+
|
71
|
+
# Fixes Rails partial renderer calling to_model on the object
|
72
|
+
# which reveals the delegated ingredient instead of this decorator.
|
73
|
+
def respond_to?(method_name)
|
74
|
+
return false if method_name == :to_model
|
75
|
+
|
76
|
+
super
|
77
|
+
end
|
78
|
+
|
79
|
+
def has_warnings?
|
80
|
+
definition.blank? || deprecated?
|
81
|
+
end
|
82
|
+
|
83
|
+
def linked?
|
84
|
+
link.try(:present?)
|
85
|
+
end
|
86
|
+
|
87
|
+
def warnings
|
88
|
+
return unless has_warnings?
|
89
|
+
|
90
|
+
if definition.blank?
|
91
|
+
Logger.warn("ingredient #{role} is missing its definition", caller(1..1))
|
92
|
+
Alchemy.t(:ingredient_definition_missing)
|
93
|
+
else
|
94
|
+
deprecation_notice
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
# Returns a deprecation notice for ingredients marked deprecated
|
99
|
+
#
|
100
|
+
# You can either use localizations or pass a String as notice
|
101
|
+
# in the ingredient definition.
|
102
|
+
#
|
103
|
+
# == Custom deprecation notices
|
104
|
+
#
|
105
|
+
# Use general ingredient deprecation notice
|
106
|
+
#
|
107
|
+
# - name: element_name
|
108
|
+
# ingredients:
|
109
|
+
# - role: old_ingredient
|
110
|
+
# type: Text
|
111
|
+
# deprecated: true
|
112
|
+
#
|
113
|
+
# Add a translation to your locale file for a per ingredient notice.
|
114
|
+
#
|
115
|
+
# en:
|
116
|
+
# alchemy:
|
117
|
+
# ingredient_deprecation_notices:
|
118
|
+
# element_name:
|
119
|
+
# old_ingredient: Foo baz widget is deprecated
|
120
|
+
#
|
121
|
+
# or use the global translation that apply to all deprecated ingredients.
|
122
|
+
#
|
123
|
+
# en:
|
124
|
+
# alchemy:
|
125
|
+
# ingredient_deprecation_notice: Foo baz widget is deprecated
|
126
|
+
#
|
127
|
+
# or pass string as deprecation notice.
|
128
|
+
#
|
129
|
+
# - name: element_name
|
130
|
+
# ingredients:
|
131
|
+
# - role: old_ingredient
|
132
|
+
# type: Text
|
133
|
+
# deprecated: This ingredient will be removed soon.
|
134
|
+
#
|
135
|
+
def deprecation_notice
|
136
|
+
case definition[:deprecated]
|
137
|
+
when String
|
138
|
+
definition[:deprecated]
|
139
|
+
when TrueClass
|
140
|
+
Alchemy.t(
|
141
|
+
role,
|
142
|
+
scope: [:ingredient_deprecation_notices, element.name],
|
143
|
+
default: Alchemy.t(:ingredient_deprecated),
|
144
|
+
)
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
private
|
149
|
+
|
150
|
+
def form_field_counter
|
151
|
+
element.definition.fetch(:ingredients, []).index { |i| i[:role] == role }
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|