alchemy_cms 7.0.0.pre.a → 7.0.0.pre.c
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/brakeman-analysis.yml +2 -2
- data/.github/workflows/lint.yml +37 -0
- data/.github/workflows/{ci.yml → test.yml} +8 -8
- data/.gitignore +0 -5
- data/.hound.yml +2 -3
- data/.rubocop.yml +4 -350
- data/.standard.yml +3 -0
- data/CHANGELOG.md +33 -0
- data/Gemfile +3 -2
- data/README.md +10 -12
- data/Rakefile +0 -19
- data/alchemy_cms.gemspec +4 -2
- data/app/assets/config/alchemy_manifest.js +1 -0
- data/app/assets/javascripts/alchemy/admin.js +0 -2
- data/app/assets/javascripts/alchemy/alchemy.dirty.js.coffee +1 -1
- data/app/assets/javascripts/alchemy/alchemy.initializer.js.coffee +5 -12
- data/app/assets/javascripts/alchemy/alchemy.link_dialog.js.coffee +6 -1
- data/app/assets/stylesheets/alchemy/base.scss +2 -2
- data/app/components/alchemy/ingredients/audio_view.rb +37 -0
- data/app/components/alchemy/ingredients/base_view.rb +38 -0
- data/app/components/alchemy/ingredients/boolean_view.rb +13 -0
- data/app/components/alchemy/ingredients/datetime_view.rb +22 -0
- data/app/components/alchemy/ingredients/file_view.rb +40 -0
- data/app/components/alchemy/ingredients/headline_view.rb +20 -0
- data/app/components/alchemy/ingredients/html_view.rb +9 -0
- data/app/components/alchemy/ingredients/link_view.rb +25 -0
- data/app/components/alchemy/ingredients/node_view.rb +11 -0
- data/app/components/alchemy/ingredients/page_view.rb +15 -0
- data/app/components/alchemy/ingredients/picture_view.rb +108 -0
- data/app/components/alchemy/ingredients/richtext_view.rb +22 -0
- data/app/components/alchemy/ingredients/select_view.rb +6 -0
- data/app/components/alchemy/ingredients/text_view.rb +41 -0
- data/app/components/alchemy/ingredients/video_view.rb +39 -0
- data/app/controllers/alchemy/admin/attachments_controller.rb +3 -3
- data/app/controllers/alchemy/admin/base_controller.rb +7 -7
- data/app/controllers/alchemy/admin/clipboard_controller.rb +2 -2
- data/app/controllers/alchemy/admin/elements_controller.rb +26 -11
- data/app/controllers/alchemy/admin/languages_controller.rb +1 -1
- data/app/controllers/alchemy/admin/nodes_controller.rb +2 -2
- data/app/controllers/alchemy/admin/pages_controller.rb +10 -10
- data/app/controllers/alchemy/admin/pictures_controller.rb +14 -14
- data/app/controllers/alchemy/admin/resources_controller.rb +27 -28
- data/app/controllers/alchemy/admin/styleguide_controller.rb +1 -0
- data/app/controllers/alchemy/admin/tags_controller.rb +11 -11
- data/app/controllers/alchemy/api/base_controller.rb +2 -2
- data/app/controllers/alchemy/api/elements_controller.rb +11 -11
- data/app/controllers/alchemy/api/ingredients_controller.rb +1 -1
- data/app/controllers/alchemy/api/nodes_controller.rb +1 -1
- data/app/controllers/alchemy/api/pages_controller.rb +11 -11
- data/app/controllers/alchemy/attachments_controller.rb +3 -3
- data/app/controllers/alchemy/base_controller.rb +1 -8
- data/app/controllers/alchemy/messages_controller.rb +9 -9
- data/app/controllers/alchemy/pages_controller.rb +8 -19
- data/app/controllers/concerns/alchemy/admin/archive_overlay.rb +1 -0
- data/app/controllers/concerns/alchemy/admin/uploader_responses.rb +5 -7
- data/app/controllers/concerns/alchemy/legacy_page_redirects.rb +5 -5
- data/app/decorators/alchemy/element_editor.rb +4 -4
- data/app/decorators/alchemy/ingredient_editor.rb +6 -6
- data/app/helpers/alchemy/admin/attachments_helper.rb +1 -1
- data/app/helpers/alchemy/admin/base_helper.rb +21 -22
- data/app/helpers/alchemy/admin/elements_helper.rb +1 -1
- data/app/helpers/alchemy/admin/form_helper.rb +1 -1
- data/app/helpers/alchemy/admin/navigation_helper.rb +7 -7
- data/app/helpers/alchemy/admin/pages_helper.rb +2 -2
- data/app/helpers/alchemy/admin/tags_helper.rb +3 -3
- data/app/helpers/alchemy/base_helper.rb +2 -2
- data/app/helpers/alchemy/elements_block_helper.rb +9 -7
- data/app/helpers/alchemy/elements_helper.rb +12 -12
- data/app/helpers/alchemy/pages_helper.rb +11 -11
- data/app/helpers/alchemy/url_helper.rb +1 -1
- data/{package/src → app/javascript/alchemy_admin}/datepicker.js +1 -0
- data/{package/src → app/javascript/alchemy_admin}/node_tree.js +2 -2
- data/{package/src → app/javascript/alchemy_admin}/page_publication_fields.js +1 -1
- data/{package/src → app/javascript/alchemy_admin}/page_sorter.js +1 -1
- data/{package/src → app/javascript/alchemy_admin}/picture_editors.js +2 -2
- data/{package/src → app/javascript/alchemy_admin}/sitemap.js +4 -4
- data/app/javascript/alchemy_admin/tinymce.js +142 -0
- data/app/javascript/alchemy_admin.js +34 -0
- data/app/mailers/alchemy/messages_mailer.rb +1 -1
- data/app/models/alchemy/attachment.rb +6 -6
- data/app/models/alchemy/base_record.rb +1 -0
- data/app/models/alchemy/eager_loading.rb +6 -6
- data/app/models/alchemy/element/definitions.rb +1 -1
- data/app/models/alchemy/element/element_ingredients.rb +3 -3
- data/app/models/alchemy/element.rb +2 -2
- data/app/models/alchemy/elements_repository.rb +1 -1
- data/app/models/alchemy/image_cropper_settings.rb +2 -2
- data/app/models/alchemy/ingredient.rb +14 -12
- data/app/models/alchemy/ingredient_validator.rb +1 -1
- data/app/models/alchemy/ingredients/datetime.rb +1 -1
- data/app/models/alchemy/ingredients/file.rb +5 -5
- data/app/models/alchemy/ingredients/headline.rb +4 -4
- data/app/models/alchemy/ingredients/picture.rb +27 -9
- data/app/models/alchemy/ingredients/richtext.rb +15 -12
- data/app/models/alchemy/ingredients/text.rb +6 -6
- data/app/models/alchemy/language/code.rb +1 -1
- data/app/models/alchemy/language.rb +4 -4
- data/app/models/alchemy/legacy_page_url.rb +1 -1
- data/app/models/alchemy/node.rb +2 -2
- data/app/models/alchemy/page/page_elements.rb +14 -14
- data/app/models/alchemy/page/page_naming.rb +4 -4
- data/app/models/alchemy/page/page_natures.rb +1 -1
- data/app/models/alchemy/page/page_scopes.rb +5 -5
- data/app/models/alchemy/page.rb +11 -11
- data/app/models/alchemy/picture/calculations.rb +2 -2
- data/app/models/alchemy/picture/transformations.rb +2 -2
- data/app/models/alchemy/picture/url.rb +4 -4
- data/app/models/alchemy/picture.rb +11 -10
- data/app/models/alchemy/picture_thumb/create.rb +1 -1
- data/app/models/alchemy/picture_thumb.rb +1 -1
- data/app/models/alchemy/picture_variant.rb +2 -3
- data/app/models/alchemy/tag.rb +8 -0
- data/app/models/concerns/alchemy/picture_thumbnails.rb +6 -6
- data/app/serializers/alchemy/base_serializer.rb +1 -1
- data/app/serializers/alchemy/page_tree_serializer.rb +7 -7
- data/app/services/alchemy/duplicate_element.rb +3 -3
- data/app/services/alchemy/tag_validations.rb +1 -1
- data/app/views/alchemy/_menubar.html.erb +1 -1
- data/app/views/alchemy/admin/attachments/_replace_button.html.erb +1 -1
- data/app/views/alchemy/admin/attachments/destroy.js.erb +1 -1
- data/app/views/alchemy/admin/elements/_element.html.erb +3 -0
- data/app/views/alchemy/admin/nodes/index.html.erb +4 -2
- data/app/views/alchemy/admin/pages/_page_layout_filter.html.erb +1 -1
- data/app/views/alchemy/admin/pages/edit.html.erb +3 -7
- data/app/views/alchemy/admin/pages/index.html.erb +1 -1
- data/app/views/alchemy/admin/pages/update.js.erb +12 -6
- data/app/views/alchemy/admin/pictures/_infos.html.erb +1 -1
- data/app/views/alchemy/admin/resources/_filter_bar.html.erb +1 -1
- data/app/views/alchemy/admin/styleguide/index.html.erb +1 -1
- data/app/views/alchemy/admin/uploader/_button.html.erb +1 -1
- data/app/views/alchemy/base/permission_denied.js.erb +1 -1
- data/app/views/alchemy/base/redirect.js.erb +1 -1
- data/app/views/alchemy/ingredients/_audio_view.html.erb +1 -14
- data/app/views/alchemy/ingredients/_boolean_view.html.erb +1 -1
- data/app/views/alchemy/ingredients/_datetime_view.html.erb +3 -9
- data/app/views/alchemy/ingredients/_file_view.html.erb +3 -16
- data/app/views/alchemy/ingredients/_headline_view.html.erb +4 -10
- data/app/views/alchemy/ingredients/_html_view.html.erb +1 -1
- data/app/views/alchemy/ingredients/_link_view.html.erb +4 -9
- data/app/views/alchemy/ingredients/_node_view.html.erb +1 -1
- data/app/views/alchemy/ingredients/_page_view.html.erb +1 -4
- data/app/views/alchemy/ingredients/_picture_view.html.erb +4 -5
- data/app/views/alchemy/ingredients/_richtext_editor.html.erb +11 -2
- data/app/views/alchemy/ingredients/_richtext_view.html.erb +3 -3
- data/app/views/alchemy/ingredients/_select_view.html.erb +1 -1
- data/app/views/alchemy/ingredients/_text_view.html.erb +3 -19
- data/app/views/alchemy/ingredients/_video_view.html.erb +3 -18
- data/app/views/alchemy/ingredients/shared/_link_tools.html.erb +1 -0
- data/app/views/alchemy/ingredients/shared/_picture_tools.html.erb +1 -0
- data/app/views/layouts/alchemy/admin.html.erb +9 -15
- data/bin/importmap +4 -0
- data/bin/setup +28 -0
- data/bin/start +17 -0
- data/config/brakeman.ignore +0 -46
- data/config/importmap.rb +8 -0
- data/config/initializers/assets.rb +1 -0
- data/config/initializers/dragonfly.rb +1 -0
- data/config/initializers/mime_types.rb +1 -0
- data/config/initializers/mini_profiler.rb +1 -0
- data/config/initializers/simple_form.rb +3 -2
- data/config/locales/alchemy.en.yml +1 -1
- data/config/routes.rb +21 -20
- data/config/spring.rb +1 -0
- data/db/migrate/20230121212637_alchemy_six_point_one.rb +8 -8
- data/db/migrate/20230505132743_add_indexes_to_alchemy_pictures.rb +6 -0
- data/lib/alchemy/admin/locale.rb +3 -3
- data/lib/alchemy/admin/preview_url.rb +2 -2
- data/lib/alchemy/auth_accessors.rb +1 -1
- data/lib/alchemy/config.rb +1 -1
- data/lib/alchemy/controller_actions.rb +4 -4
- data/lib/alchemy/deprecation.rb +1 -0
- data/lib/alchemy/dragonfly/processors/thumbnail.rb +1 -1
- data/lib/alchemy/element_definition.rb +2 -2
- data/lib/alchemy/engine.rb +16 -1
- data/lib/alchemy/filetypes.rb +7 -7
- data/lib/alchemy/forms/builder.rb +4 -4
- data/lib/alchemy/i18n.rb +6 -4
- data/lib/alchemy/install/tasks.rb +2 -1
- data/lib/alchemy/name_conversions.rb +1 -1
- data/lib/alchemy/page_layout.rb +1 -1
- data/lib/alchemy/permissions.rb +5 -4
- data/lib/alchemy/resource.rb +10 -10
- data/lib/alchemy/resources_helper.rb +7 -7
- data/lib/alchemy/routing_constraints.rb +2 -2
- data/lib/alchemy/seeder.rb +12 -5
- data/lib/alchemy/shell.rb +2 -1
- data/lib/alchemy/taggable.rb +3 -2
- data/lib/alchemy/tasks/tidy.rb +1 -0
- data/lib/alchemy/test_support/capybara_helpers.rb +1 -1
- data/lib/alchemy/test_support/config_stubbing.rb +1 -0
- data/lib/alchemy/test_support/factories/element_factory.rb +4 -0
- data/lib/alchemy/test_support/factories/page_factory.rb +2 -2
- data/lib/alchemy/test_support/having_crop_action_examples.rb +9 -9
- data/lib/alchemy/test_support/having_picture_thumbnails_examples.rb +33 -33
- data/lib/alchemy/test_support/integration_helpers.rb +4 -3
- data/lib/alchemy/test_support/shared_contexts.rb +2 -1
- data/lib/alchemy/test_support/shared_dom_ids_examples.rb +9 -9
- data/lib/alchemy/test_support/shared_ingredient_examples.rb +12 -6
- data/lib/alchemy/test_support/shared_uploader_examples.rb +1 -0
- data/lib/alchemy/tinymce.rb +3 -26
- data/lib/alchemy/upgrader/seven_point_zero.rb +13 -23
- data/lib/alchemy/upgrader.rb +1 -11
- data/lib/alchemy/version.rb +1 -1
- data/lib/alchemy.rb +5 -0
- data/lib/alchemy_cms.rb +3 -1
- data/lib/generators/alchemy/base.rb +3 -2
- data/lib/generators/alchemy/elements/elements_generator.rb +2 -1
- data/lib/generators/alchemy/ingredient/ingredient_generator.rb +1 -0
- data/lib/generators/alchemy/install/files/application.html.erb +2 -2
- data/lib/generators/alchemy/install/install_generator.rb +2 -25
- data/lib/generators/alchemy/module/module_generator.rb +1 -0
- data/lib/generators/alchemy/page_layouts/page_layouts_generator.rb +1 -0
- data/lib/generators/alchemy/site_layouts/site_layouts_generator.rb +1 -0
- data/lib/generators/alchemy/views/views_generator.rb +2 -1
- data/lib/tasks/alchemy/thumbnails.rake +5 -5
- data/lib/tasks/alchemy/tidy.rake +1 -0
- data/lib/tasks/alchemy/upgrade.rake +10 -15
- data/package.json +6 -26
- metadata +80 -31
- data/app/assets/javascripts/alchemy/alchemy.tinymce.js.coffee +0 -93
- data/app/presenters/alchemy/picture_view.rb +0 -88
- data/app/views/alchemy/admin/pages/_tinymce_custom_config.html.erb +0 -10
- data/package/admin.js +0 -32
- data/package/dist/admin.js +0 -16
- data/package/dist/admin.js.map +0 -7
- data/package/src/__tests__/i18n.spec.js +0 -93
- data/package/src/utils/__tests__/ajax.spec.js +0 -168
- data/package/src/utils/__tests__/events.spec.js +0 -38
- /data/{package/src → app/javascript/alchemy_admin}/file_editors.js +0 -0
- /data/{package/src → app/javascript/alchemy_admin}/i18n.js +0 -0
- /data/{package/src → app/javascript/alchemy_admin}/image_cropper.js +0 -0
- /data/{package/src → app/javascript/alchemy_admin}/image_loader.js +0 -0
- /data/{package/src → app/javascript/alchemy_admin}/ingredient_anchor_link.js +0 -0
- /data/{package/src → app/javascript/alchemy_admin}/translations.js +0 -0
- /data/{package/src → app/javascript/alchemy_admin}/utils/ajax.js +0 -0
- /data/{package/src → app/javascript/alchemy_admin}/utils/events.js +0 -0
@@ -24,7 +24,7 @@ module Alchemy
|
|
24
24
|
linkname: "name",
|
25
25
|
show_title: true,
|
26
26
|
spacer: "",
|
27
|
-
reverse: false
|
27
|
+
reverse: false
|
28
28
|
}.merge(options)
|
29
29
|
languages = Language.on_current_site.published.with_root_page.order("name #{options[:reverse] ? "DESC" : "ASC"}")
|
30
30
|
return nil if languages.count < 2
|
@@ -33,7 +33,7 @@ module Alchemy
|
|
33
33
|
partial: "alchemy/language_links/language",
|
34
34
|
collection: languages,
|
35
35
|
spacer_template: "alchemy/language_links/spacer",
|
36
|
-
locals: {
|
36
|
+
locals: {languages: languages, options: options}
|
37
37
|
)
|
38
38
|
end
|
39
39
|
|
@@ -79,7 +79,7 @@ module Alchemy
|
|
79
79
|
def render_menu(menu_type, options = {})
|
80
80
|
root_node = Alchemy::Node.roots.find_by(
|
81
81
|
menu_type: menu_type,
|
82
|
-
language: Alchemy::Language.current
|
82
|
+
language: Alchemy::Language.current
|
83
83
|
)
|
84
84
|
if root_node.nil?
|
85
85
|
warning("Menu with type #{menu_type} not found!")
|
@@ -110,12 +110,12 @@ module Alchemy
|
|
110
110
|
page: @page,
|
111
111
|
restricted_only: false,
|
112
112
|
reverse: false,
|
113
|
-
link_active_page: false
|
113
|
+
link_active_page: false
|
114
114
|
}.merge(options)
|
115
115
|
|
116
|
-
pages = options[:page]
|
117
|
-
self_and_ancestors.contentpages
|
118
|
-
published
|
116
|
+
pages = options[:page]
|
117
|
+
.self_and_ancestors.contentpages
|
118
|
+
.published
|
119
119
|
|
120
120
|
if options.delete(:restricted_only)
|
121
121
|
pages = pages.restricted
|
@@ -146,13 +146,13 @@ module Alchemy
|
|
146
146
|
options = {
|
147
147
|
prefix: "",
|
148
148
|
suffix: "",
|
149
|
-
separator: ""
|
149
|
+
separator: ""
|
150
150
|
}.update(options)
|
151
151
|
title_parts = [options[:prefix]]
|
152
|
-
if response.status == 200
|
153
|
-
|
152
|
+
title_parts << if response.status == 200
|
153
|
+
@page.title
|
154
154
|
else
|
155
|
-
|
155
|
+
response.status
|
156
156
|
end
|
157
157
|
title_parts << options[:suffix]
|
158
158
|
title_parts.reject(&:blank?).join(options[:separator]).html_safe
|
@@ -20,7 +20,7 @@ module Alchemy
|
|
20
20
|
def show_page_path_params(page, optional_params = {})
|
21
21
|
raise ArgumentError, "Page is nil" if page.nil?
|
22
22
|
|
23
|
-
url_params = {
|
23
|
+
url_params = {urlname: page.urlname}.update(optional_params)
|
24
24
|
prefix_locale?(page.language_code) ? url_params.update(locale: page.language_code) : url_params
|
25
25
|
end
|
26
26
|
|
@@ -24,6 +24,7 @@ export default function Datepicker(scope = document) {
|
|
24
24
|
altInput: true,
|
25
25
|
altFormat: Alchemy.t(`formats.${type}`),
|
26
26
|
altInputClass: "flatpickr-input",
|
27
|
+
dateFormat: "Z",
|
27
28
|
enableTime: /time/.test(type),
|
28
29
|
noCalendar: type === "time",
|
29
30
|
time_24hr: Alchemy.t("formats.time_24hr"),
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import Sortable from "sortablejs"
|
2
|
-
import { patch } from "
|
3
|
-
import { on } from "
|
2
|
+
import { patch } from "alchemy_admin/utils/ajax"
|
3
|
+
import { on } from "alchemy_admin/utils/events"
|
4
4
|
|
5
5
|
function displayNodeFolders() {
|
6
6
|
document.querySelectorAll("li.menu-item").forEach((el) => {
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import debounce from "lodash-es/debounce"
|
2
2
|
import max from "lodash-es/max"
|
3
|
-
import { get } from "
|
4
|
-
import ImageLoader from "
|
3
|
+
import { get } from "alchemy_admin/utils/ajax"
|
4
|
+
import ImageLoader from "alchemy_admin/image_loader"
|
5
5
|
|
6
6
|
const UPDATE_DELAY = 125
|
7
7
|
const IMAGE_PLACEHOLDER = '<i class="icon far fa-image fa-fw"></i>'
|
@@ -1,8 +1,8 @@
|
|
1
1
|
// The admin sitemap Alchemy class
|
2
|
-
import PageSorter from "
|
3
|
-
import { on } from "
|
4
|
-
import { get, patch } from "
|
5
|
-
import { createSortables, displayPageFolders } from "
|
2
|
+
import PageSorter from "alchemy_admin/page_sorter"
|
3
|
+
import { on } from "alchemy_admin/utils/events"
|
4
|
+
import { get, patch } from "alchemy_admin/utils/ajax"
|
5
|
+
import { createSortables, displayPageFolders } from "alchemy_admin/page_sorter"
|
6
6
|
|
7
7
|
export default class Sitemap {
|
8
8
|
// Storing some objects.
|
@@ -0,0 +1,142 @@
|
|
1
|
+
// Alchemy Tinymce wrapper
|
2
|
+
//
|
3
|
+
|
4
|
+
let tinymceCustomConfigs = {}
|
5
|
+
let tinymceIntersectionObserver = null
|
6
|
+
|
7
|
+
// Returns default config for a tinymce editor.
|
8
|
+
function getDefaultConfig(editorId) {
|
9
|
+
const config = Alchemy.TinymceDefaults
|
10
|
+
config.language = Alchemy.locale
|
11
|
+
config.selector = `#${editorId}`
|
12
|
+
config.init_instance_callback = initInstanceCallback
|
13
|
+
return config
|
14
|
+
}
|
15
|
+
|
16
|
+
// Returns configuration for given custom tinymce editor selector.
|
17
|
+
//
|
18
|
+
// It uses the +.getDefaultConfig+ and merges the custom parts.
|
19
|
+
function getConfig(editorId) {
|
20
|
+
const editorConfig = tinymceCustomConfigs[editorId] || {}
|
21
|
+
return { ...getDefaultConfig(editorId), ...editorConfig }
|
22
|
+
}
|
23
|
+
|
24
|
+
// create intersection observer and register textareas to be initialized when
|
25
|
+
// they are visible
|
26
|
+
function initEditors(ids) {
|
27
|
+
initializeIntersectionObserver()
|
28
|
+
|
29
|
+
ids.forEach((id) => {
|
30
|
+
const editorId = `tinymce_${id}`
|
31
|
+
const textarea = document.getElementById(editorId)
|
32
|
+
|
33
|
+
if (textarea) {
|
34
|
+
tinymceIntersectionObserver.observe(textarea)
|
35
|
+
} else {
|
36
|
+
console.warn(`Could not initialize TinyMCE for textarea#${editorId}!`)
|
37
|
+
}
|
38
|
+
})
|
39
|
+
}
|
40
|
+
|
41
|
+
// initialize IntersectionObserver
|
42
|
+
// the observer will initialize Tinymce if the textarea becomes visible
|
43
|
+
function initializeIntersectionObserver() {
|
44
|
+
if (tinymceIntersectionObserver !== null) {
|
45
|
+
tinymceIntersectionObserver.disconnect()
|
46
|
+
}
|
47
|
+
|
48
|
+
const observerCallback = (entries, observer) => {
|
49
|
+
entries.forEach((entry) => {
|
50
|
+
if (entry.intersectionRatio > 0) {
|
51
|
+
initTinymceEditor(entry.target)
|
52
|
+
// disable observer after the Tinymce was initialized
|
53
|
+
observer.unobserve(entry.target)
|
54
|
+
}
|
55
|
+
})
|
56
|
+
}
|
57
|
+
const options = {
|
58
|
+
root: Alchemy.ElementEditors.element_area.get(0),
|
59
|
+
rootMargin: "0px",
|
60
|
+
threshold: [0.05]
|
61
|
+
}
|
62
|
+
|
63
|
+
tinymceIntersectionObserver = new IntersectionObserver(
|
64
|
+
observerCallback,
|
65
|
+
options
|
66
|
+
)
|
67
|
+
}
|
68
|
+
|
69
|
+
// Initializes one specific TinyMCE editor
|
70
|
+
function initTinymceEditor(textarea) {
|
71
|
+
const editorId = textarea.id
|
72
|
+
const config = getConfig(editorId)
|
73
|
+
|
74
|
+
// remove editor instance, if already initialized
|
75
|
+
removeEditor(editorId)
|
76
|
+
|
77
|
+
if (config) {
|
78
|
+
const spinner = new Alchemy.Spinner("small")
|
79
|
+
textarea.closest(".tinymce_container").prepend(spinner.spin().el.get(0))
|
80
|
+
tinymce.init(config)
|
81
|
+
} else {
|
82
|
+
console.warn("No tinymce configuration found for", id)
|
83
|
+
}
|
84
|
+
}
|
85
|
+
|
86
|
+
// Gets called after an editor instance gets initialized
|
87
|
+
function initInstanceCallback(editor) {
|
88
|
+
const element = document.getElementById(editor.id).closest(".element-editor")
|
89
|
+
element.getElementsByClassName("spinner").item(0).remove()
|
90
|
+
editor.on("dirty", function () {
|
91
|
+
Alchemy.setElementDirty(element)
|
92
|
+
})
|
93
|
+
editor.on("click", function (event) {
|
94
|
+
event.target = element
|
95
|
+
Alchemy.ElementEditors.onClickElement(event)
|
96
|
+
})
|
97
|
+
}
|
98
|
+
|
99
|
+
function removeEditor(editorId) {
|
100
|
+
const editorElement = document.getElementById(editorId)
|
101
|
+
if (tinymceIntersectionObserver && editorElement) {
|
102
|
+
tinymceIntersectionObserver.unobserve(editorElement)
|
103
|
+
}
|
104
|
+
|
105
|
+
const editor = tinymce.get(editorId)
|
106
|
+
if (editor) {
|
107
|
+
editor.remove()
|
108
|
+
}
|
109
|
+
}
|
110
|
+
|
111
|
+
export default {
|
112
|
+
// Initializes all TinyMCE editors with given ids
|
113
|
+
//
|
114
|
+
// @param ids [Array]
|
115
|
+
// - Editor ids that should be initialized.
|
116
|
+
init(ids) {
|
117
|
+
initEditors(ids)
|
118
|
+
},
|
119
|
+
|
120
|
+
// Initializes TinyMCE editor with given options
|
121
|
+
initWith(options) {
|
122
|
+
tinymce.init({ ...Alchemy.TinymceDefaults, ...options })
|
123
|
+
},
|
124
|
+
|
125
|
+
// Removes the TinyMCE editor from given dom ids.
|
126
|
+
remove(ids) {
|
127
|
+
ids.forEach((id) => removeEditor(`tinymce_${id}`))
|
128
|
+
},
|
129
|
+
|
130
|
+
// Remove all tinymce instances for given selector
|
131
|
+
removeFrom(selector) {
|
132
|
+
// the selector is a jQuery selector - it has to be refactor if we taking care of the calling methods
|
133
|
+
$(selector).each(function (element) {
|
134
|
+
removeEditor(element.id)
|
135
|
+
})
|
136
|
+
},
|
137
|
+
|
138
|
+
// set tinymce configuration for a given selector key
|
139
|
+
setCustomConfig(key, configuration) {
|
140
|
+
tinymceCustomConfigs[key] = configuration
|
141
|
+
}
|
142
|
+
}
|
@@ -0,0 +1,34 @@
|
|
1
|
+
import "@hotwired/turbo-rails"
|
2
|
+
|
3
|
+
import translate from "alchemy_admin/i18n"
|
4
|
+
import translationData from "alchemy_admin/translations"
|
5
|
+
import fileEditors from "alchemy_admin/file_editors"
|
6
|
+
import IngredientAnchorLink from "alchemy_admin/ingredient_anchor_link"
|
7
|
+
import pictureEditors from "alchemy_admin/picture_editors"
|
8
|
+
import ImageLoader from "alchemy_admin/image_loader"
|
9
|
+
import ImageCropper from "alchemy_admin/image_cropper"
|
10
|
+
import Datepicker from "alchemy_admin/datepicker"
|
11
|
+
import Sitemap from "alchemy_admin/sitemap"
|
12
|
+
import Tinymce from "alchemy_admin/tinymce"
|
13
|
+
import PagePublicationFields from "alchemy_admin/page_publication_fields"
|
14
|
+
|
15
|
+
// Global Alchemy object
|
16
|
+
if (typeof window.Alchemy === "undefined") {
|
17
|
+
window.Alchemy = {}
|
18
|
+
}
|
19
|
+
|
20
|
+
// Enhance the global Alchemy object with imported features
|
21
|
+
Object.assign(Alchemy, {
|
22
|
+
// Global utility method for translating a given string
|
23
|
+
t: translate,
|
24
|
+
translations: Object.assign(Alchemy.translations || {}, translationData),
|
25
|
+
fileEditors,
|
26
|
+
pictureEditors,
|
27
|
+
ImageLoader: ImageLoader.init,
|
28
|
+
ImageCropper,
|
29
|
+
IngredientAnchorLink,
|
30
|
+
Datepicker,
|
31
|
+
Sitemap,
|
32
|
+
Tinymce,
|
33
|
+
PagePublicationFields
|
34
|
+
})
|
@@ -40,7 +40,7 @@ module Alchemy
|
|
40
40
|
|
41
41
|
scope :by_file_type, ->(file_type) { where(file_mime_type: file_type) }
|
42
42
|
scope :recent, -> { where("#{table_name}.created_at > ?", Time.current - 24.hours).order(:created_at) }
|
43
|
-
scope :without_tag, -> { left_outer_joins(:taggings).where(gutentag_taggings: {
|
43
|
+
scope :without_tag, -> { left_outer_joins(:taggings).where(gutentag_taggings: {id: nil}) }
|
44
44
|
|
45
45
|
# We need to define this method here to have it available in the validations below.
|
46
46
|
class << self
|
@@ -62,12 +62,12 @@ module Alchemy
|
|
62
62
|
[
|
63
63
|
{
|
64
64
|
name: :by_file_type,
|
65
|
-
values: distinct.pluck(:file_mime_type).map { |type| [Alchemy.t(type, scope: "mime_types"), type] }.sort_by(&:first)
|
65
|
+
values: distinct.pluck(:file_mime_type).map { |type| [Alchemy.t(type, scope: "mime_types"), type] }.sort_by(&:first)
|
66
66
|
},
|
67
67
|
{
|
68
68
|
name: :misc,
|
69
|
-
values: %w
|
70
|
-
}
|
69
|
+
values: %w[recent last_upload without_tag]
|
70
|
+
}
|
71
71
|
]
|
72
72
|
end
|
73
73
|
|
@@ -79,7 +79,7 @@ module Alchemy
|
|
79
79
|
end
|
80
80
|
|
81
81
|
def searchable_alchemy_resource_attributes
|
82
|
-
%w
|
82
|
+
%w[name file_name]
|
83
83
|
end
|
84
84
|
|
85
85
|
def allowed_filetypes
|
@@ -106,7 +106,7 @@ module Alchemy
|
|
106
106
|
{
|
107
107
|
"name" => read_attribute(:file_name),
|
108
108
|
"size" => read_attribute(:file_size),
|
109
|
-
"error" => errors[:file].join
|
109
|
+
"error" => errors[:file].join
|
110
110
|
}
|
111
111
|
end
|
112
112
|
|
@@ -20,18 +20,18 @@ module Alchemy
|
|
20
20
|
[
|
21
21
|
:tags,
|
22
22
|
{
|
23
|
-
language
|
23
|
+
:language => :site,
|
24
24
|
version => {
|
25
25
|
elements: [
|
26
26
|
:page,
|
27
27
|
:touchable_pages,
|
28
28
|
:tags,
|
29
29
|
{
|
30
|
-
ingredients: :related_object
|
31
|
-
}
|
32
|
-
]
|
33
|
-
}
|
34
|
-
}
|
30
|
+
ingredients: :related_object
|
31
|
+
}
|
32
|
+
]
|
33
|
+
}
|
34
|
+
}
|
35
35
|
]
|
36
36
|
end
|
37
37
|
end
|
@@ -41,7 +41,7 @@ module Alchemy
|
|
41
41
|
# The definition of this element.
|
42
42
|
#
|
43
43
|
def definition
|
44
|
-
if definition = self.class.definition_by_name(name)
|
44
|
+
if (definition = self.class.definition_by_name(name))
|
45
45
|
definition
|
46
46
|
else
|
47
47
|
log_warning "Could not find element definition for #{name}. " \
|
@@ -159,9 +159,9 @@ module Alchemy
|
|
159
159
|
scope: "ingredient_validations",
|
160
160
|
default: [
|
161
161
|
"fields.#{role}.#{error}".to_sym,
|
162
|
-
"errors.#{error}".to_sym
|
162
|
+
"errors.#{error}".to_sym
|
163
163
|
],
|
164
|
-
field: Alchemy::Ingredient.translated_label_for(role, name)
|
164
|
+
field: Alchemy::Ingredient.translated_label_for(role, name)
|
165
165
|
)
|
166
166
|
end
|
167
167
|
end
|
@@ -175,7 +175,7 @@ module Alchemy
|
|
175
175
|
ingredient_definitions.each do |attributes|
|
176
176
|
ingredients.build(
|
177
177
|
role: attributes[:role],
|
178
|
-
type: Alchemy::Ingredient.normalize_type(attributes[:type])
|
178
|
+
type: Alchemy::Ingredient.normalize_type(attributes[:type])
|
179
179
|
)
|
180
180
|
end
|
181
181
|
end
|
@@ -41,7 +41,7 @@ module Alchemy
|
|
41
41
|
"taggable",
|
42
42
|
"compact",
|
43
43
|
"message",
|
44
|
-
"deprecated"
|
44
|
+
"deprecated"
|
45
45
|
].freeze
|
46
46
|
|
47
47
|
# All Elements that share the same page version and parent element and are fixed or not are considered a list.
|
@@ -100,7 +100,7 @@ module Alchemy
|
|
100
100
|
scope :excluded, ->(names) { where.not(name: names) }
|
101
101
|
scope :fixed, -> { where(fixed: true) }
|
102
102
|
scope :unfixed, -> { where(fixed: false) }
|
103
|
-
scope :from_current_site, -> { where(Language.table_name => {
|
103
|
+
scope :from_current_site, -> { where(Language.table_name => {site_id: Site.current || Site.default}).joins(page: "language") }
|
104
104
|
scope :folded, -> { where(folded: true) }
|
105
105
|
scope :expanded, -> { where(folded: false) }
|
106
106
|
scope :not_nested, -> { where(parent_element_id: nil) }
|
@@ -21,7 +21,7 @@ module Alchemy
|
|
21
21
|
min_size: large_enough? ? min_size : false,
|
22
22
|
ratio: ratio,
|
23
23
|
default_box: default_box,
|
24
|
-
image_size: [image_width, image_height]
|
24
|
+
image_size: [image_width, image_height]
|
25
25
|
}.freeze
|
26
26
|
end
|
27
27
|
|
@@ -80,7 +80,7 @@ module Alchemy
|
|
80
80
|
default_crop_from[0],
|
81
81
|
default_crop_from[1],
|
82
82
|
default_crop_from[0] + default_crop_size[0],
|
83
|
-
default_crop_from[1] + default_crop_size[1]
|
83
|
+
default_crop_from[1] + default_crop_size[1]
|
84
84
|
]
|
85
85
|
end
|
86
86
|
end
|
@@ -19,7 +19,7 @@ module Alchemy
|
|
19
19
|
if: -> { definition.key?(:default) && value.nil? }
|
20
20
|
|
21
21
|
validates :type, presence: true
|
22
|
-
validates :role, presence: true, uniqueness: {
|
22
|
+
validates :role, presence: true, uniqueness: {scope: :element_id, case_sensitive: false}
|
23
23
|
|
24
24
|
validates_with Alchemy::IngredientValidator, on: :update, if: :has_validations?
|
25
25
|
|
@@ -75,7 +75,7 @@ module Alchemy
|
|
75
75
|
Alchemy.t(
|
76
76
|
role,
|
77
77
|
scope: "ingredient_roles.#{element_name}",
|
78
|
-
default: Alchemy.t("ingredient_roles.#{role}", default: role.humanize)
|
78
|
+
default: Alchemy.t("ingredient_roles.#{role}", default: role.humanize)
|
79
79
|
)
|
80
80
|
end
|
81
81
|
|
@@ -100,16 +100,6 @@ module Alchemy
|
|
100
100
|
definition[:settings] || {}
|
101
101
|
end
|
102
102
|
|
103
|
-
# Fetches value from settings
|
104
|
-
#
|
105
|
-
# @param key [Symbol] - The hash key you want to fetch the value from
|
106
|
-
# @param options [Hash] - An optional Hash that can override the settings.
|
107
|
-
# Normally passed as options hash into the ingredient
|
108
|
-
# editor view.
|
109
|
-
def settings_value(key, options = {})
|
110
|
-
settings.merge(options || {})[key.to_sym]
|
111
|
-
end
|
112
|
-
|
113
103
|
# Definition hash for this ingredient from +elements.yml+ file.
|
114
104
|
#
|
115
105
|
def definition
|
@@ -165,8 +155,20 @@ module Alchemy
|
|
165
155
|
!!definition[:as_element_title]
|
166
156
|
end
|
167
157
|
|
158
|
+
# The view component of the ingredient with mapped options.
|
159
|
+
#
|
160
|
+
# @param options [Hash] - Passed to the view component as keyword arguments
|
161
|
+
# @param html_options [Hash] - Passed to the view component
|
162
|
+
def as_view_component(options: {}, html_options: {})
|
163
|
+
view_component_class.new(self, **options, html_options: html_options)
|
164
|
+
end
|
165
|
+
|
168
166
|
private
|
169
167
|
|
168
|
+
def view_component_class
|
169
|
+
@_view_component_class ||= "#{self.class.name}View".constantize
|
170
|
+
end
|
171
|
+
|
170
172
|
def hint_translation_attribute
|
171
173
|
role
|
172
174
|
end
|
@@ -89,7 +89,7 @@ module Alchemy
|
|
89
89
|
def duplicates
|
90
90
|
ingredient.class
|
91
91
|
.joins(:element).merge(Alchemy::Element.published)
|
92
|
-
.where(Alchemy::Element.table_name => {
|
92
|
+
.where(Alchemy::Element.table_name => {name: ingredient.element.name})
|
93
93
|
.where(value: ingredient.value)
|
94
94
|
.where.not(id: ingredient.id)
|
95
95
|
end
|
@@ -28,15 +28,15 @@ module Alchemy
|
|
28
28
|
related_object_alias :picture, class_name: "Alchemy::Picture"
|
29
29
|
|
30
30
|
allow_settings %i[
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
31
|
+
crop
|
32
|
+
css_classes
|
33
|
+
fixed_ratio
|
34
|
+
linkable
|
35
|
+
size
|
36
|
+
sizes
|
37
|
+
srcset
|
38
|
+
upsample
|
39
|
+
]
|
40
40
|
|
41
41
|
# The first 30 characters of the pictures name
|
42
42
|
#
|
@@ -47,6 +47,24 @@ module Alchemy
|
|
47
47
|
def preview_text(max_length = 30)
|
48
48
|
picture&.name.to_s[0..max_length - 1]
|
49
49
|
end
|
50
|
+
|
51
|
+
# The picture view component with mapped options.
|
52
|
+
#
|
53
|
+
# @param options [Hash] - Passed to the view component
|
54
|
+
# @param html_options [Hash] - Passed to the view component
|
55
|
+
#
|
56
|
+
# @return Alchemy::Ingredients::PictureView
|
57
|
+
def as_view_component(options: {}, html_options: {})
|
58
|
+
PictureView.new(
|
59
|
+
self,
|
60
|
+
show_caption: options.delete(:show_caption),
|
61
|
+
disable_link: options.delete(:disable_link),
|
62
|
+
srcset: options.delete(:srcset),
|
63
|
+
sizes: options.delete(:sizes),
|
64
|
+
picture_options: options,
|
65
|
+
html_options: html_options
|
66
|
+
)
|
67
|
+
end
|
50
68
|
end
|
51
69
|
end
|
52
70
|
end
|