pages_core 3.7.0 → 3.8.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -2
- data/Rakefile +37 -0
- data/app/assets/builds/pages_core/admin-dist.js +55 -0
- data/app/assets/stylesheets/pages/admin/components/image_editor.scss +1 -0
- data/app/assets/stylesheets/pages/admin/components/image_grid.scss +33 -5
- data/app/assets/stylesheets/pages/admin/components/layout.scss +2 -1
- data/app/assets/stylesheets/pages/admin/components/login.scss +6 -0
- data/app/assets/stylesheets/pages/admin/components/tabs.scss +5 -0
- data/app/assets/stylesheets/pages/admin/components/tag_editor.scss +13 -7
- data/app/assets/stylesheets/pages/admin/controllers/pages.scss +13 -5
- data/app/assets/stylesheets/pages/admin.scss +0 -1
- data/app/controller_dummies/admin/admin_controller.rb +1 -1
- data/app/controller_dummies/application_controller.rb +1 -1
- data/app/controller_dummies/attachments_controller.rb +1 -1
- data/app/controller_dummies/frontend_controller.rb +1 -1
- data/app/controller_dummies/images_controller.rb +1 -1
- data/app/controller_dummies/page_files_controller.rb +1 -1
- data/app/controller_dummies/pages_controller.rb +1 -1
- data/app/controller_dummies/sitemaps_controller.rb +1 -1
- data/app/controllers/admin/attachments_controller.rb +1 -1
- data/app/controllers/admin/images_controller.rb +11 -8
- data/app/controllers/concerns/pages_core/authentication.rb +9 -4
- data/app/controllers/concerns/pages_core/preview_pages_controller.rb +5 -0
- data/app/controllers/pages_core/frontend/pages_controller.rb +5 -2
- data/app/controllers/sessions_controller.rb +1 -1
- data/app/formatters/pages_core/link_renderer.rb +2 -2
- data/app/helpers/application_helper.rb +1 -1
- data/app/helpers/frontend_helper.rb +1 -1
- data/app/helpers/pages_core/admin/content_tabs_helper.rb +5 -2
- data/app/helpers/pages_core/admin/image_uploads_helper.rb +2 -3
- data/app/helpers/pages_core/admin/tag_editor_helper.rb +9 -39
- data/app/helpers/pages_core/head_tags_helper.rb +11 -20
- data/app/helpers/pages_core/open_graph_tags_helper.rb +1 -1
- data/app/javascript/admin-dist.js +2 -0
- data/app/javascript/components/Attachments/Attachment.jsx +121 -0
- data/app/javascript/components/Attachments/AttachmentEditor.jsx +116 -0
- data/app/javascript/components/Attachments/Placeholder.jsx +10 -0
- data/app/javascript/components/Attachments.jsx +165 -0
- data/app/{assets/javascripts/pages/admin/components/date_range_select.jsx → javascript/components/DateRangeSelect.jsx} +16 -5
- data/app/javascript/components/EditableImage.jsx +61 -0
- data/app/javascript/components/FileUploadButton.jsx +47 -0
- data/app/{assets/javascripts/pages/admin/components/focal_point.jsx → javascript/components/ImageCropper/FocalPoint.jsx} +12 -1
- data/app/javascript/components/ImageCropper/Image.jsx +65 -0
- data/app/javascript/components/ImageCropper/Toolbar.jsx +73 -0
- data/app/javascript/components/ImageCropper/useCrop.js +199 -0
- data/app/javascript/components/ImageCropper.jsx +90 -0
- data/app/javascript/components/ImageEditor/Form.jsx +98 -0
- data/app/javascript/components/ImageEditor.jsx +62 -0
- data/app/javascript/components/ImageGrid/DragElement.jsx +30 -0
- data/app/javascript/components/ImageGrid/FilePlaceholder.jsx +9 -0
- data/app/javascript/components/ImageGrid/GridImage.jsx +103 -0
- data/app/javascript/components/ImageGrid/Placeholder.jsx +23 -0
- data/app/javascript/components/ImageGrid.jsx +257 -0
- data/app/javascript/components/ImageUploader.jsx +171 -0
- data/app/{assets/javascripts/pages/admin/components/modal.jsx → javascript/components/Modal.jsx} +13 -2
- data/app/{assets/javascripts/pages/admin/components/page_dates.jsx → javascript/components/PageDates.jsx} +11 -1
- data/app/{assets/javascripts/pages/admin/components/page_files.jsx → javascript/components/PageFiles.jsx} +11 -2
- data/app/{assets/javascripts/pages/admin/components/page_images.jsx → javascript/components/PageImages.jsx} +11 -2
- data/app/{assets/javascripts/pages/admin/components/page_tree_store.jsx → javascript/components/PageTree.jsx} +127 -137
- data/app/{assets/javascripts/pages/admin/components/page_tree.jsx → javascript/components/PageTreeDraggable.jsx} +35 -29
- data/app/{assets/javascripts/pages/admin/components/page_tree_node.jsx → javascript/components/PageTreeNode.jsx} +35 -20
- data/app/javascript/components/RichTextArea.jsx +213 -0
- data/app/javascript/components/RichTextToolbarButton.jsx +20 -0
- data/app/javascript/components/TagEditor/AddTagForm.jsx +42 -0
- data/app/javascript/components/TagEditor/Tag.jsx +32 -0
- data/app/javascript/components/TagEditor.jsx +61 -0
- data/app/javascript/components/Toast.jsx +72 -0
- data/app/javascript/components/drag/draggedOrder.js +51 -0
- data/app/javascript/components/drag/useDragCollection.js +84 -0
- data/app/javascript/components/drag/useDragUploader.js +112 -0
- data/app/javascript/components/drag/useDraggable.js +17 -0
- data/app/javascript/components/drag.js +6 -0
- data/app/javascript/components.js +15 -0
- data/app/javascript/controllers/EditPageController.js +20 -0
- data/app/javascript/controllers/LoginController.js +29 -0
- data/app/javascript/controllers/MainController.js +65 -0
- data/app/javascript/controllers/PageOptionsController.js +62 -0
- data/app/javascript/features/RichText.jsx +34 -0
- data/app/javascript/hooks.js +2 -0
- data/app/javascript/index.js +38 -0
- data/app/{assets/javascripts/pages/admin/lib/tree.jsx → javascript/lib/Tree.js} +55 -54
- data/app/javascript/lib/copyToClipboard.js +13 -0
- data/app/javascript/lib/readyHandler.js +22 -0
- data/app/javascript/lib/request.js +36 -0
- data/app/javascript/stores/ModalStore.jsx +12 -0
- data/app/javascript/stores/ToastStore.jsx +14 -0
- data/app/javascript/stores.js +2 -0
- data/app/models/concerns/pages_core/page_model/images.rb +3 -1
- data/app/models/concerns/pages_core/page_model/searchable.rb +19 -0
- data/app/models/concerns/pages_core/searchable_document.rb +71 -0
- data/app/models/concerns/pages_core/taggable.rb +27 -12
- data/app/models/page.rb +2 -0
- data/app/models/page_exporter.rb +2 -2
- data/app/models/page_image.rb +0 -2
- data/app/models/role.rb +1 -1
- data/app/models/search_document.rb +72 -0
- data/app/models/tag.rb +1 -0
- data/app/models/user.rb +1 -1
- data/app/{serializers/admin/attachment_serializer.rb → resources/admin/attachment_resource.rb} +6 -5
- data/app/{serializers/admin/image_serializer.rb → resources/admin/image_resource.rb} +9 -9
- data/app/resources/admin/page_file_resource.rb +10 -0
- data/app/{serializers/admin/page_image_serializer.rb → resources/admin/page_image_resource.rb} +4 -2
- data/app/resources/export/attachment_resource.rb +10 -0
- data/app/resources/export/page_image_resource.rb +45 -0
- data/app/resources/export/page_resource.rb +42 -0
- data/app/{serializers/page_image_serializer.rb → resources/page_image_resource.rb} +8 -16
- data/app/resources/page_resource.rb +33 -0
- data/app/services/pages_core/destroy_invite_service.rb +2 -2
- data/app/services/pages_core/invite_service.rb +2 -2
- data/app/views/admin/pages/_edit_content.html.erb +1 -1
- data/app/views/admin/pages/_edit_files.html.erb +1 -5
- data/app/views/admin/pages/_edit_images.html.erb +1 -5
- data/app/views/admin/pages/_edit_options.html.erb +74 -55
- data/app/views/admin/pages/_form.html.erb +19 -0
- data/app/views/admin/pages/edit.html.erb +35 -61
- data/app/views/admin/pages/index.html.erb +0 -1
- data/app/views/admin/pages/new.html.erb +32 -32
- data/app/views/admin/users/_access_control.html.erb +5 -1
- data/app/views/admin/users/login.html.erb +12 -4
- data/app/views/feeds/pages.rss.builder +1 -2
- data/app/views/layouts/admin/_header.html.erb +1 -1
- data/app/views/layouts/admin/_page_header.html.erb +33 -0
- data/app/views/layouts/admin.html.erb +23 -42
- data/app/views/pages_core/_google_analytics.html.erb +8 -0
- data/db/migrate/20180625154059_enable_search_extensions.rb +10 -0
- data/db/migrate/20210209151400_create_search_configurations.rb +35 -0
- data/db/migrate/20210210235200_create_search_documents.rb +74 -0
- data/lib/pages_core/engine.rb +1 -5
- data/lib/pages_core/templates/block_configuration.rb +1 -1
- data/lib/pages_core/templates/configuration_handler.rb +1 -1
- data/lib/pages_core/version.rb +3 -1
- data/lib/pages_core.rb +3 -5
- data/lib/rails/generators/pages_core/frontend/frontend_generator.rb +0 -7
- data/lib/rails/generators/pages_core/install/templates/page_templates_initializer.rb +2 -2
- metadata +116 -115
- data/app/assets/javascripts/pages/admin/components/attachment.jsx +0 -130
- data/app/assets/javascripts/pages/admin/components/attachment_editor.jsx +0 -131
- data/app/assets/javascripts/pages/admin/components/attachments.jsx +0 -211
- data/app/assets/javascripts/pages/admin/components/drag_uploader.jsx +0 -174
- data/app/assets/javascripts/pages/admin/components/editable_image.jsx +0 -57
- data/app/assets/javascripts/pages/admin/components/file_upload_button.jsx +0 -44
- data/app/assets/javascripts/pages/admin/components/grid_image.jsx +0 -124
- data/app/assets/javascripts/pages/admin/components/image_editor.jsx +0 -496
- data/app/assets/javascripts/pages/admin/components/image_grid.jsx +0 -306
- data/app/assets/javascripts/pages/admin/components/image_uploader.jsx +0 -176
- data/app/assets/javascripts/pages/admin/components/modal_store.jsx +0 -20
- data/app/assets/javascripts/pages/admin/components/rich_text_area.jsx +0 -64
- data/app/assets/javascripts/pages/admin/components/rich_text_toolbar.jsx +0 -91
- data/app/assets/javascripts/pages/admin/components/toast.jsx +0 -34
- data/app/assets/javascripts/pages/admin/components/toast_store.jsx +0 -52
- data/app/assets/javascripts/pages/admin/components.jsx +0 -2
- data/app/assets/javascripts/pages/admin/features/content_tabs.jsx +0 -72
- data/app/assets/javascripts/pages/admin/features/edit_page.jsx +0 -97
- data/app/assets/javascripts/pages/admin/features/rich_text.jsx +0 -14
- data/app/assets/javascripts/pages/admin/features/tag_editor.jsx +0 -160
- data/app/assets/javascripts/pages/admin.jsx +0 -17
- data/app/assets/javascripts/pages/login_form.jsx +0 -21
- data/app/serializers/admin/page_file_serializer.rb +0 -8
- data/app/serializers/page_export_serializer.rb +0 -32
- data/app/serializers/page_file_export_serializer.rb +0 -6
- data/app/serializers/page_image_export_serializer.rb +0 -42
- data/app/serializers/page_serializer.rb +0 -23
- data/app/views/layouts/admin/_analytics.html.erb +0 -16
- data/lib/rails/generators/pages_core/frontend/templates/application.js.erb +0 -15
- data/vendor/assets/javascripts/ReactCrop.min.js +0 -1
- data/vendor/assets/javascripts/reflux.min.js +0 -1
@@ -4,25 +4,27 @@ module PagesCore
|
|
4
4
|
module Taggable
|
5
5
|
extend ActiveSupport::Concern
|
6
6
|
|
7
|
+
attr_accessor :new_tags
|
8
|
+
|
7
9
|
included do
|
8
10
|
has_many :taggings,
|
9
11
|
as: :taggable,
|
10
12
|
dependent: :destroy,
|
11
13
|
inverse_of: :taggable
|
12
14
|
has_many :tags, through: :taggings
|
15
|
+
after_save :update_taggings
|
13
16
|
end
|
14
17
|
|
15
18
|
module ClassMethods
|
16
19
|
def tagged_with(*tags)
|
17
|
-
all
|
18
|
-
|
19
|
-
|
20
|
-
.references(:tags)
|
20
|
+
all.includes(:tags)
|
21
|
+
.where(tags: { name: Tag.parse(tags) })
|
22
|
+
.references(:tags)
|
21
23
|
end
|
22
24
|
end
|
23
25
|
|
24
26
|
def serialized_tags
|
25
|
-
|
27
|
+
tag_names.to_json
|
26
28
|
end
|
27
29
|
|
28
30
|
def serialized_tags=(json)
|
@@ -30,12 +32,11 @@ module PagesCore
|
|
30
32
|
end
|
31
33
|
|
32
34
|
def tag_with(*list)
|
33
|
-
Tag.
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
end
|
35
|
+
@new_tags = Tag.parse(list)
|
36
|
+
end
|
37
|
+
|
38
|
+
def tag_with!(*list)
|
39
|
+
update(tag_list: list)
|
39
40
|
end
|
40
41
|
|
41
42
|
def tag_list=(tag_list)
|
@@ -47,7 +48,21 @@ module PagesCore
|
|
47
48
|
end
|
48
49
|
|
49
50
|
def tag_names
|
50
|
-
tags.map(&:name)
|
51
|
+
@new_tags || tags.by_name.map(&:name)
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def update_taggings
|
57
|
+
return unless new_tags
|
58
|
+
|
59
|
+
Tag.transaction do
|
60
|
+
taggings.includes(:tag).where.not(tag: { name: new_tags }).destroy_all
|
61
|
+
new_tags.map { |n| Tag.find_or_create_by(name: n) }
|
62
|
+
.each { |t| taggings.create(tag: t) }
|
63
|
+
end
|
64
|
+
|
65
|
+
@new_tags = nil
|
51
66
|
end
|
52
67
|
end
|
53
68
|
end
|
data/app/models/page.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
class Page < ApplicationRecord
|
4
4
|
include PagesCore::HumanizableParam
|
5
|
+
include PagesCore::SearchableDocument
|
5
6
|
include PagesCore::Sweepable
|
6
7
|
include PagesCore::Taggable
|
7
8
|
|
@@ -12,6 +13,7 @@ class Page < ApplicationRecord
|
|
12
13
|
include PagesCore::PageModel::Localizable
|
13
14
|
include PagesCore::PageModel::Pathable
|
14
15
|
include PagesCore::PageModel::Redirectable
|
16
|
+
include PagesCore::PageModel::Searchable
|
15
17
|
include PagesCore::PageModel::Sortable
|
16
18
|
include PagesCore::PageModel::Status
|
17
19
|
include PagesCore::PageModel::Tree
|
data/app/models/page_exporter.rb
CHANGED
@@ -29,7 +29,7 @@ class PageExporter
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def export_files(page)
|
32
|
-
path = page_path(page).join("
|
32
|
+
path = page_path(page).join("attachments")
|
33
33
|
page.attachments.each do |file|
|
34
34
|
write_file(
|
35
35
|
path.join([file.content_hash, file.filename].join("-")),
|
@@ -57,7 +57,7 @@ class PageExporter
|
|
57
57
|
end
|
58
58
|
|
59
59
|
def export_page_json(path, page)
|
60
|
-
json =
|
60
|
+
json = Export::PageResource.new(page).serialize
|
61
61
|
write_file(path.join("page.#{page.locale}.json"), json)
|
62
62
|
write_file(path.join("page.#{page.locale}.yml"), JSON.parse(json).to_yaml)
|
63
63
|
end
|
data/app/models/page_image.rb
CHANGED
data/app/models/role.rb
CHANGED
@@ -11,7 +11,7 @@ class Role < ApplicationRecord
|
|
11
11
|
def define(name, description, default: false)
|
12
12
|
if roles.map(&:name).include?(name.to_s)
|
13
13
|
raise ArgumentError, "Tried to define role :#{role}, " \
|
14
|
-
|
14
|
+
"but a role by that name already exists"
|
15
15
|
else
|
16
16
|
roles << OpenStruct.new(
|
17
17
|
name: name.to_s,
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class SearchDocument < ApplicationRecord
|
4
|
+
include PgSearch::Model
|
5
|
+
|
6
|
+
belongs_to :searchable, polymorphic: true
|
7
|
+
|
8
|
+
validates :locale, presence: true
|
9
|
+
|
10
|
+
before_validation :configure_dictionary,
|
11
|
+
:inherit_updated_at
|
12
|
+
|
13
|
+
scope :published, -> { where(published: true) }
|
14
|
+
|
15
|
+
pg_search_scope :full_text_search_scope, lambda { |query, dictionary|
|
16
|
+
{ against: %i[name description content tags],
|
17
|
+
using: { tsearch: { prefix: true,
|
18
|
+
dictionary: dictionary,
|
19
|
+
tsvector_column: "tsv" },
|
20
|
+
trigram: { only: %i[name] } },
|
21
|
+
ignoring: :accents,
|
22
|
+
order_within_rank: "search_documents.record_updated_at DESC",
|
23
|
+
query: query }
|
24
|
+
}
|
25
|
+
|
26
|
+
class << self
|
27
|
+
def results
|
28
|
+
select(:searchable_id, :searchable_type, :locale)
|
29
|
+
.map(&:localized_searchable)
|
30
|
+
end
|
31
|
+
|
32
|
+
def search(query, locale: nil)
|
33
|
+
locale ||= I18n.locale
|
34
|
+
where(locale: locale)
|
35
|
+
.includes(:searchable)
|
36
|
+
.full_text_search_scope(query, search_configuration(locale))
|
37
|
+
end
|
38
|
+
|
39
|
+
def search_configuration(locale)
|
40
|
+
search_configurations[locale&.to_sym] || "simple_unaccent"
|
41
|
+
end
|
42
|
+
|
43
|
+
def search_configurations
|
44
|
+
# These are the dictionaries PostgreSQL 12 ships with.
|
45
|
+
# Also available in PostgreSQL 13: el: "greek_unaccent",
|
46
|
+
{ ar: "arabic_unaccent", da: "danish_unaccent", nl: "dutch_unaccent",
|
47
|
+
en: "english_unaccent", fi: "finnish_unaccent", fr: "french_unaccent",
|
48
|
+
de: "german_unaccent", hu: "hungarian_unaccent",
|
49
|
+
id: "indonesian_unaccent", ga: "irish_unaccent", it: "italian_unaccent",
|
50
|
+
lt: "lithuanian_unaccent", ne: "nepali_unaccent",
|
51
|
+
nb: "norwegian_unaccent", pt: "portuguese_unaccent",
|
52
|
+
rm: "romanian_unaccent", ru: "russian_unaccent", es: "spanish_unaccent",
|
53
|
+
sv: "swedish_unaccent", ta: "tamil_unaccent", tr: "turkish_unaccent" }
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def localized_searchable
|
58
|
+
return searchable unless searchable.respond_to?(:localize)
|
59
|
+
|
60
|
+
searchable.localize(locale)
|
61
|
+
end
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
def configure_dictionary
|
66
|
+
self.tsv_config = self.class.search_configuration(locale)
|
67
|
+
end
|
68
|
+
|
69
|
+
def inherit_updated_at
|
70
|
+
self.record_updated_at = searchable.updated_at
|
71
|
+
end
|
72
|
+
end
|
data/app/models/tag.rb
CHANGED
data/app/models/user.rb
CHANGED
data/app/{serializers/admin/attachment_serializer.rb → resources/admin/attachment_resource.rb}
RENAMED
@@ -1,22 +1,23 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Admin
|
4
|
-
class
|
4
|
+
class AttachmentResource
|
5
|
+
include Alba::Resource
|
5
6
|
include Rails.application.routes.url_helpers
|
6
7
|
include PagesCore::AttachmentsHelper
|
7
8
|
|
8
9
|
attributes :id, :filename, :content_type, :content_hash, :content_length,
|
9
|
-
:
|
10
|
+
:created_at, :updated_at
|
10
11
|
|
11
|
-
|
12
|
+
attribute :name do
|
12
13
|
localized_attribute(:name)
|
13
14
|
end
|
14
15
|
|
15
|
-
|
16
|
+
attribute :description do
|
16
17
|
localized_attribute(:description)
|
17
18
|
end
|
18
19
|
|
19
|
-
|
20
|
+
attribute :url do
|
20
21
|
attachment_path(object)
|
21
22
|
end
|
22
23
|
|
@@ -1,29 +1,29 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Admin
|
4
|
-
class
|
4
|
+
class ImageResource
|
5
|
+
include Alba::Resource
|
5
6
|
include Rails.application.routes.url_helpers
|
6
7
|
include DynamicImage::Helper
|
7
8
|
|
8
9
|
attributes :id, :filename, :content_type, :content_hash, :content_length,
|
9
10
|
:colorspace, :real_width, :real_height, :crop_width,
|
10
11
|
:crop_height, :crop_start_x, :crop_start_y, :crop_gravity_x,
|
11
|
-
:crop_gravity_y, :
|
12
|
-
attributes :cropped_url, :uncropped_url, :original_url, :thumbnail_url
|
12
|
+
:crop_gravity_y, :created_at, :updated_at
|
13
13
|
|
14
|
-
|
14
|
+
attribute :alternative do
|
15
15
|
localized_attribute(:alternative)
|
16
16
|
end
|
17
17
|
|
18
|
-
|
18
|
+
attribute :caption do
|
19
19
|
localized_attribute(:caption)
|
20
20
|
end
|
21
21
|
|
22
|
-
|
22
|
+
attribute :original_url do
|
23
23
|
original_dynamic_image_path(object)
|
24
24
|
end
|
25
25
|
|
26
|
-
|
26
|
+
attribute :thumbnail_url do
|
27
27
|
dynamic_image_path(
|
28
28
|
object,
|
29
29
|
size: "500x",
|
@@ -31,7 +31,7 @@ module Admin
|
|
31
31
|
)
|
32
32
|
end
|
33
33
|
|
34
|
-
|
34
|
+
attribute :cropped_url do
|
35
35
|
dynamic_image_path(
|
36
36
|
object,
|
37
37
|
size: "1200x1200",
|
@@ -40,7 +40,7 @@ module Admin
|
|
40
40
|
)
|
41
41
|
end
|
42
42
|
|
43
|
-
|
43
|
+
attribute :uncropped_url do
|
44
44
|
uncropped_dynamic_image_path(
|
45
45
|
object,
|
46
46
|
size: "2000x2000",
|
data/app/{serializers/admin/page_image_serializer.rb → resources/admin/page_image_resource.rb}
RENAMED
@@ -1,8 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Admin
|
4
|
-
class
|
4
|
+
class PageImageResource
|
5
|
+
include Alba::Resource
|
6
|
+
|
5
7
|
attributes :id, :page_id, :image_id, :position, :primary
|
6
|
-
|
8
|
+
one :image, resource: Admin::ImageResource
|
7
9
|
end
|
8
10
|
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Export
|
4
|
+
class PageImageResource
|
5
|
+
include Alba::Resource
|
6
|
+
|
7
|
+
attributes :primary
|
8
|
+
|
9
|
+
attribute :id do
|
10
|
+
object.image.id
|
11
|
+
end
|
12
|
+
|
13
|
+
attribute :name do
|
14
|
+
object.image.name
|
15
|
+
end
|
16
|
+
|
17
|
+
attribute :alternative do
|
18
|
+
object.image.alternative
|
19
|
+
end
|
20
|
+
|
21
|
+
attribute :caption do
|
22
|
+
object.image.caption
|
23
|
+
end
|
24
|
+
|
25
|
+
attribute :content_hash do
|
26
|
+
object.image.content_hash
|
27
|
+
end
|
28
|
+
|
29
|
+
attribute :content_type do
|
30
|
+
object.image.content_type
|
31
|
+
end
|
32
|
+
|
33
|
+
attribute :filename do
|
34
|
+
object.image.filename
|
35
|
+
end
|
36
|
+
|
37
|
+
attribute :size do
|
38
|
+
object.image.crop_size
|
39
|
+
end
|
40
|
+
|
41
|
+
attribute :created_at do
|
42
|
+
object.image.created_at
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Export
|
4
|
+
class PageResource
|
5
|
+
include Alba::Resource
|
6
|
+
|
7
|
+
attributes :id, :locale
|
8
|
+
attributes(*PagesCore::Templates::TemplateConfiguration.all_blocks)
|
9
|
+
attributes :created_at, :published_at, :pinned, :template, :redirect_to,
|
10
|
+
:starts_at, :ends_at, :all_day
|
11
|
+
|
12
|
+
has_many :attachments, resource: Export::AttachmentResource
|
13
|
+
|
14
|
+
attribute :author_name do
|
15
|
+
object&.author&.name
|
16
|
+
end
|
17
|
+
|
18
|
+
attribute :path do
|
19
|
+
object.full_path || object.to_param
|
20
|
+
end
|
21
|
+
|
22
|
+
attribute :image do
|
23
|
+
image_resource(object.page_images.where(primary: true).try(:first))
|
24
|
+
end
|
25
|
+
|
26
|
+
attribute :images do
|
27
|
+
object.page_images.map { |image| image_resource(image) }
|
28
|
+
end
|
29
|
+
|
30
|
+
attribute :status do
|
31
|
+
object.status_label
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def image_resource(image)
|
37
|
+
return nil unless image
|
38
|
+
|
39
|
+
Export::PageImageResource.new(image)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -1,37 +1,29 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
class
|
3
|
+
class PageImageResource
|
4
|
+
include Alba::Resource
|
4
5
|
include Rails.application.routes.url_helpers
|
5
6
|
include DynamicImage::Helper
|
6
7
|
|
7
|
-
attributes :id, :image_id, :primary
|
8
|
-
attributes :alternative, :caption, :created_at, :url
|
8
|
+
attributes :id, :image_id, :primary
|
9
9
|
|
10
|
-
|
11
|
-
object.image.name
|
12
|
-
end
|
13
|
-
|
14
|
-
def alternative
|
10
|
+
attribute :alternative do
|
15
11
|
object.image.alternative
|
16
12
|
end
|
17
13
|
|
18
|
-
|
14
|
+
attribute :caption do
|
19
15
|
object.image.caption
|
20
16
|
end
|
21
17
|
|
22
|
-
|
18
|
+
attribute :filename do
|
23
19
|
object.image.filename
|
24
20
|
end
|
25
21
|
|
26
|
-
|
27
|
-
object.image.crop_size
|
28
|
-
end
|
29
|
-
|
30
|
-
def created_at
|
22
|
+
attribute :created_at do
|
31
23
|
object.image.created_at
|
32
24
|
end
|
33
25
|
|
34
|
-
|
26
|
+
attribute :url do
|
35
27
|
dynamic_image_path(
|
36
28
|
object.image,
|
37
29
|
size: "2000x2000",
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class PageResource
|
4
|
+
include Alba::Resource
|
5
|
+
|
6
|
+
attributes :id, :parent_page_id, :locale
|
7
|
+
attributes(*PagesCore::Templates::TemplateConfiguration.all_blocks)
|
8
|
+
attributes :published_at, :pinned
|
9
|
+
|
10
|
+
attribute :param do
|
11
|
+
object.to_param
|
12
|
+
end
|
13
|
+
|
14
|
+
attribute :image do
|
15
|
+
image_resource(object.page_images.where(primary: true).try(:first))
|
16
|
+
end
|
17
|
+
|
18
|
+
attribute :images do
|
19
|
+
object.page_images.map { |image| image_resource(image) }
|
20
|
+
end
|
21
|
+
|
22
|
+
attribute :pages do
|
23
|
+
object.pages.map { |p| PageResource.new(p) }
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def image_resource(image)
|
29
|
+
return nil unless image
|
30
|
+
|
31
|
+
PageImageResource.new(image)
|
32
|
+
end
|
33
|
+
end
|
@@ -1,8 +1,4 @@
|
|
1
1
|
<%= react_component("PageFiles",
|
2
2
|
locale: @locale,
|
3
3
|
locales: PagesCore.config.locales,
|
4
|
-
|
5
|
-
records: ActiveModel::Serializer::CollectionSerializer.new(
|
6
|
-
@page.files,
|
7
|
-
serializer: Admin::PageFileSerializer
|
8
|
-
)) %>
|
4
|
+
records: @page.files.map { |pf| Admin::PageFileResource.new(pf).to_hash }) %>
|
@@ -1,8 +1,4 @@
|
|
1
1
|
<%= react_component("PageImages",
|
2
2
|
locale: @locale,
|
3
3
|
locales: PagesCore.config.locales,
|
4
|
-
|
5
|
-
records: ActiveModel::Serializer::CollectionSerializer.new(
|
6
|
-
@page.page_images,
|
7
|
-
serializer: Admin::PageImageSerializer
|
8
|
-
)) %>
|
4
|
+
records: @page.page_images.map { |pi| Admin::PageImageResource.new(pi).to_hash }) %>
|