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.
Files changed (167) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -2
  3. data/Rakefile +37 -0
  4. data/app/assets/builds/pages_core/admin-dist.js +55 -0
  5. data/app/assets/stylesheets/pages/admin/components/image_editor.scss +1 -0
  6. data/app/assets/stylesheets/pages/admin/components/image_grid.scss +33 -5
  7. data/app/assets/stylesheets/pages/admin/components/layout.scss +2 -1
  8. data/app/assets/stylesheets/pages/admin/components/login.scss +6 -0
  9. data/app/assets/stylesheets/pages/admin/components/tabs.scss +5 -0
  10. data/app/assets/stylesheets/pages/admin/components/tag_editor.scss +13 -7
  11. data/app/assets/stylesheets/pages/admin/controllers/pages.scss +13 -5
  12. data/app/assets/stylesheets/pages/admin.scss +0 -1
  13. data/app/controller_dummies/admin/admin_controller.rb +1 -1
  14. data/app/controller_dummies/application_controller.rb +1 -1
  15. data/app/controller_dummies/attachments_controller.rb +1 -1
  16. data/app/controller_dummies/frontend_controller.rb +1 -1
  17. data/app/controller_dummies/images_controller.rb +1 -1
  18. data/app/controller_dummies/page_files_controller.rb +1 -1
  19. data/app/controller_dummies/pages_controller.rb +1 -1
  20. data/app/controller_dummies/sitemaps_controller.rb +1 -1
  21. data/app/controllers/admin/attachments_controller.rb +1 -1
  22. data/app/controllers/admin/images_controller.rb +11 -8
  23. data/app/controllers/concerns/pages_core/authentication.rb +9 -4
  24. data/app/controllers/concerns/pages_core/preview_pages_controller.rb +5 -0
  25. data/app/controllers/pages_core/frontend/pages_controller.rb +5 -2
  26. data/app/controllers/sessions_controller.rb +1 -1
  27. data/app/formatters/pages_core/link_renderer.rb +2 -2
  28. data/app/helpers/application_helper.rb +1 -1
  29. data/app/helpers/frontend_helper.rb +1 -1
  30. data/app/helpers/pages_core/admin/content_tabs_helper.rb +5 -2
  31. data/app/helpers/pages_core/admin/image_uploads_helper.rb +2 -3
  32. data/app/helpers/pages_core/admin/tag_editor_helper.rb +9 -39
  33. data/app/helpers/pages_core/head_tags_helper.rb +11 -20
  34. data/app/helpers/pages_core/open_graph_tags_helper.rb +1 -1
  35. data/app/javascript/admin-dist.js +2 -0
  36. data/app/javascript/components/Attachments/Attachment.jsx +121 -0
  37. data/app/javascript/components/Attachments/AttachmentEditor.jsx +116 -0
  38. data/app/javascript/components/Attachments/Placeholder.jsx +10 -0
  39. data/app/javascript/components/Attachments.jsx +165 -0
  40. data/app/{assets/javascripts/pages/admin/components/date_range_select.jsx → javascript/components/DateRangeSelect.jsx} +16 -5
  41. data/app/javascript/components/EditableImage.jsx +61 -0
  42. data/app/javascript/components/FileUploadButton.jsx +47 -0
  43. data/app/{assets/javascripts/pages/admin/components/focal_point.jsx → javascript/components/ImageCropper/FocalPoint.jsx} +12 -1
  44. data/app/javascript/components/ImageCropper/Image.jsx +65 -0
  45. data/app/javascript/components/ImageCropper/Toolbar.jsx +73 -0
  46. data/app/javascript/components/ImageCropper/useCrop.js +199 -0
  47. data/app/javascript/components/ImageCropper.jsx +90 -0
  48. data/app/javascript/components/ImageEditor/Form.jsx +98 -0
  49. data/app/javascript/components/ImageEditor.jsx +62 -0
  50. data/app/javascript/components/ImageGrid/DragElement.jsx +30 -0
  51. data/app/javascript/components/ImageGrid/FilePlaceholder.jsx +9 -0
  52. data/app/javascript/components/ImageGrid/GridImage.jsx +103 -0
  53. data/app/javascript/components/ImageGrid/Placeholder.jsx +23 -0
  54. data/app/javascript/components/ImageGrid.jsx +257 -0
  55. data/app/javascript/components/ImageUploader.jsx +171 -0
  56. data/app/{assets/javascripts/pages/admin/components/modal.jsx → javascript/components/Modal.jsx} +13 -2
  57. data/app/{assets/javascripts/pages/admin/components/page_dates.jsx → javascript/components/PageDates.jsx} +11 -1
  58. data/app/{assets/javascripts/pages/admin/components/page_files.jsx → javascript/components/PageFiles.jsx} +11 -2
  59. data/app/{assets/javascripts/pages/admin/components/page_images.jsx → javascript/components/PageImages.jsx} +11 -2
  60. data/app/{assets/javascripts/pages/admin/components/page_tree_store.jsx → javascript/components/PageTree.jsx} +127 -137
  61. data/app/{assets/javascripts/pages/admin/components/page_tree.jsx → javascript/components/PageTreeDraggable.jsx} +35 -29
  62. data/app/{assets/javascripts/pages/admin/components/page_tree_node.jsx → javascript/components/PageTreeNode.jsx} +35 -20
  63. data/app/javascript/components/RichTextArea.jsx +213 -0
  64. data/app/javascript/components/RichTextToolbarButton.jsx +20 -0
  65. data/app/javascript/components/TagEditor/AddTagForm.jsx +42 -0
  66. data/app/javascript/components/TagEditor/Tag.jsx +32 -0
  67. data/app/javascript/components/TagEditor.jsx +61 -0
  68. data/app/javascript/components/Toast.jsx +72 -0
  69. data/app/javascript/components/drag/draggedOrder.js +51 -0
  70. data/app/javascript/components/drag/useDragCollection.js +84 -0
  71. data/app/javascript/components/drag/useDragUploader.js +112 -0
  72. data/app/javascript/components/drag/useDraggable.js +17 -0
  73. data/app/javascript/components/drag.js +6 -0
  74. data/app/javascript/components.js +15 -0
  75. data/app/javascript/controllers/EditPageController.js +20 -0
  76. data/app/javascript/controllers/LoginController.js +29 -0
  77. data/app/javascript/controllers/MainController.js +65 -0
  78. data/app/javascript/controllers/PageOptionsController.js +62 -0
  79. data/app/javascript/features/RichText.jsx +34 -0
  80. data/app/javascript/hooks.js +2 -0
  81. data/app/javascript/index.js +38 -0
  82. data/app/{assets/javascripts/pages/admin/lib/tree.jsx → javascript/lib/Tree.js} +55 -54
  83. data/app/javascript/lib/copyToClipboard.js +13 -0
  84. data/app/javascript/lib/readyHandler.js +22 -0
  85. data/app/javascript/lib/request.js +36 -0
  86. data/app/javascript/stores/ModalStore.jsx +12 -0
  87. data/app/javascript/stores/ToastStore.jsx +14 -0
  88. data/app/javascript/stores.js +2 -0
  89. data/app/models/concerns/pages_core/page_model/images.rb +3 -1
  90. data/app/models/concerns/pages_core/page_model/searchable.rb +19 -0
  91. data/app/models/concerns/pages_core/searchable_document.rb +71 -0
  92. data/app/models/concerns/pages_core/taggable.rb +27 -12
  93. data/app/models/page.rb +2 -0
  94. data/app/models/page_exporter.rb +2 -2
  95. data/app/models/page_image.rb +0 -2
  96. data/app/models/role.rb +1 -1
  97. data/app/models/search_document.rb +72 -0
  98. data/app/models/tag.rb +1 -0
  99. data/app/models/user.rb +1 -1
  100. data/app/{serializers/admin/attachment_serializer.rb → resources/admin/attachment_resource.rb} +6 -5
  101. data/app/{serializers/admin/image_serializer.rb → resources/admin/image_resource.rb} +9 -9
  102. data/app/resources/admin/page_file_resource.rb +10 -0
  103. data/app/{serializers/admin/page_image_serializer.rb → resources/admin/page_image_resource.rb} +4 -2
  104. data/app/resources/export/attachment_resource.rb +10 -0
  105. data/app/resources/export/page_image_resource.rb +45 -0
  106. data/app/resources/export/page_resource.rb +42 -0
  107. data/app/{serializers/page_image_serializer.rb → resources/page_image_resource.rb} +8 -16
  108. data/app/resources/page_resource.rb +33 -0
  109. data/app/services/pages_core/destroy_invite_service.rb +2 -2
  110. data/app/services/pages_core/invite_service.rb +2 -2
  111. data/app/views/admin/pages/_edit_content.html.erb +1 -1
  112. data/app/views/admin/pages/_edit_files.html.erb +1 -5
  113. data/app/views/admin/pages/_edit_images.html.erb +1 -5
  114. data/app/views/admin/pages/_edit_options.html.erb +74 -55
  115. data/app/views/admin/pages/_form.html.erb +19 -0
  116. data/app/views/admin/pages/edit.html.erb +35 -61
  117. data/app/views/admin/pages/index.html.erb +0 -1
  118. data/app/views/admin/pages/new.html.erb +32 -32
  119. data/app/views/admin/users/_access_control.html.erb +5 -1
  120. data/app/views/admin/users/login.html.erb +12 -4
  121. data/app/views/feeds/pages.rss.builder +1 -2
  122. data/app/views/layouts/admin/_header.html.erb +1 -1
  123. data/app/views/layouts/admin/_page_header.html.erb +33 -0
  124. data/app/views/layouts/admin.html.erb +23 -42
  125. data/app/views/pages_core/_google_analytics.html.erb +8 -0
  126. data/db/migrate/20180625154059_enable_search_extensions.rb +10 -0
  127. data/db/migrate/20210209151400_create_search_configurations.rb +35 -0
  128. data/db/migrate/20210210235200_create_search_documents.rb +74 -0
  129. data/lib/pages_core/engine.rb +1 -5
  130. data/lib/pages_core/templates/block_configuration.rb +1 -1
  131. data/lib/pages_core/templates/configuration_handler.rb +1 -1
  132. data/lib/pages_core/version.rb +3 -1
  133. data/lib/pages_core.rb +3 -5
  134. data/lib/rails/generators/pages_core/frontend/frontend_generator.rb +0 -7
  135. data/lib/rails/generators/pages_core/install/templates/page_templates_initializer.rb +2 -2
  136. metadata +116 -115
  137. data/app/assets/javascripts/pages/admin/components/attachment.jsx +0 -130
  138. data/app/assets/javascripts/pages/admin/components/attachment_editor.jsx +0 -131
  139. data/app/assets/javascripts/pages/admin/components/attachments.jsx +0 -211
  140. data/app/assets/javascripts/pages/admin/components/drag_uploader.jsx +0 -174
  141. data/app/assets/javascripts/pages/admin/components/editable_image.jsx +0 -57
  142. data/app/assets/javascripts/pages/admin/components/file_upload_button.jsx +0 -44
  143. data/app/assets/javascripts/pages/admin/components/grid_image.jsx +0 -124
  144. data/app/assets/javascripts/pages/admin/components/image_editor.jsx +0 -496
  145. data/app/assets/javascripts/pages/admin/components/image_grid.jsx +0 -306
  146. data/app/assets/javascripts/pages/admin/components/image_uploader.jsx +0 -176
  147. data/app/assets/javascripts/pages/admin/components/modal_store.jsx +0 -20
  148. data/app/assets/javascripts/pages/admin/components/rich_text_area.jsx +0 -64
  149. data/app/assets/javascripts/pages/admin/components/rich_text_toolbar.jsx +0 -91
  150. data/app/assets/javascripts/pages/admin/components/toast.jsx +0 -34
  151. data/app/assets/javascripts/pages/admin/components/toast_store.jsx +0 -52
  152. data/app/assets/javascripts/pages/admin/components.jsx +0 -2
  153. data/app/assets/javascripts/pages/admin/features/content_tabs.jsx +0 -72
  154. data/app/assets/javascripts/pages/admin/features/edit_page.jsx +0 -97
  155. data/app/assets/javascripts/pages/admin/features/rich_text.jsx +0 -14
  156. data/app/assets/javascripts/pages/admin/features/tag_editor.jsx +0 -160
  157. data/app/assets/javascripts/pages/admin.jsx +0 -17
  158. data/app/assets/javascripts/pages/login_form.jsx +0 -21
  159. data/app/serializers/admin/page_file_serializer.rb +0 -8
  160. data/app/serializers/page_export_serializer.rb +0 -32
  161. data/app/serializers/page_file_export_serializer.rb +0 -6
  162. data/app/serializers/page_image_export_serializer.rb +0 -42
  163. data/app/serializers/page_serializer.rb +0 -23
  164. data/app/views/layouts/admin/_analytics.html.erb +0 -16
  165. data/lib/rails/generators/pages_core/frontend/templates/application.js.erb +0 -15
  166. data/vendor/assets/javascripts/ReactCrop.min.js +0 -1
  167. 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
- .includes(:tags)
19
- .where(tags: { name: Tag.parse(tags) })
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
- tags.order("name ASC").map(&:name).to_json
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.transaction do
34
- taggings.destroy_all
35
- Tag.parse(list).each do |name|
36
- Tag.find_or_create_by(name: name).on(self)
37
- end
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).sort
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
@@ -29,7 +29,7 @@ class PageExporter
29
29
  end
30
30
 
31
31
  def export_files(page)
32
- path = page_path(page).join("files")
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 = PageExportSerializer.new(page).to_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
@@ -6,8 +6,6 @@ class PageImage < ApplicationRecord
6
6
  belongs_to :page
7
7
  belongs_to_image :image
8
8
 
9
- validates :page_id, presence: true
10
-
11
9
  accepts_nested_attributes_for :image
12
10
  validates_associated :image
13
11
 
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
- "but a role by that name already exists"
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
@@ -4,6 +4,7 @@ class Tag < ApplicationRecord
4
4
  include PagesCore::HumanizableParam
5
5
  has_many :taggings, dependent: :destroy
6
6
 
7
+ scope :by_name, -> { order("name ASC") }
7
8
  scope :pinned, -> { where(pinned: true) }
8
9
  scope :sorted, -> { order("pinned DESC, name ASC") }
9
10
 
data/app/models/user.rb CHANGED
@@ -83,7 +83,7 @@ class User < ApplicationRecord
83
83
  end
84
84
 
85
85
  def online?
86
- last_login_at && last_login_at > 15.minutes.ago ? true : false
86
+ last_login_at && last_login_at > 15.minutes.ago
87
87
  end
88
88
 
89
89
  def realname
@@ -1,22 +1,23 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Admin
4
- class AttachmentSerializer < ActiveModel::Serializer
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
- :name, :description, :created_at, :updated_at, :url
10
+ :created_at, :updated_at
10
11
 
11
- def name
12
+ attribute :name do
12
13
  localized_attribute(:name)
13
14
  end
14
15
 
15
- def description
16
+ attribute :description do
16
17
  localized_attribute(:description)
17
18
  end
18
19
 
19
- def url
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 ImageSerializer < ActiveModel::Serializer
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, :alternative, :caption, :created_at, :updated_at
12
- attributes :cropped_url, :uncropped_url, :original_url, :thumbnail_url
12
+ :crop_gravity_y, :created_at, :updated_at
13
13
 
14
- def alternative
14
+ attribute :alternative do
15
15
  localized_attribute(:alternative)
16
16
  end
17
17
 
18
- def caption
18
+ attribute :caption do
19
19
  localized_attribute(:caption)
20
20
  end
21
21
 
22
- def original_url
22
+ attribute :original_url do
23
23
  original_dynamic_image_path(object)
24
24
  end
25
25
 
26
- def thumbnail_url
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
- def cropped_url
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
- def uncropped_url
43
+ attribute :uncropped_url do
44
44
  uncropped_dynamic_image_path(
45
45
  object,
46
46
  size: "2000x2000",
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Admin
4
+ class PageFileResource
5
+ include Alba::Resource
6
+
7
+ attributes :id, :page_id, :attachment_id, :position
8
+ one :attachment, resource: Admin::AttachmentResource
9
+ end
10
+ end
@@ -1,8 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Admin
4
- class PageImageSerializer < ActiveModel::Serializer
4
+ class PageImageResource
5
+ include Alba::Resource
6
+
5
7
  attributes :id, :page_id, :image_id, :position, :primary
6
- has_one :image, serializer: Admin::ImageSerializer
8
+ one :image, resource: Admin::ImageResource
7
9
  end
8
10
  end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Export
4
+ class AttachmentResource
5
+ include Alba::Resource
6
+
7
+ attributes :id, :filename, :content_type, :content_length, :content_hash,
8
+ :created_at, :updated_at
9
+ end
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 PageImageSerializer < ActiveModel::Serializer
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, :filename
8
- attributes :alternative, :caption, :created_at, :url
8
+ attributes :id, :image_id, :primary
9
9
 
10
- def name
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
- def caption
14
+ attribute :caption do
19
15
  object.image.caption
20
16
  end
21
17
 
22
- def filename
18
+ attribute :filename do
23
19
  object.image.filename
24
20
  end
25
21
 
26
- def size
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
- def url
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
@@ -9,8 +9,8 @@ module PagesCore
9
9
  end
10
10
 
11
11
  class << self
12
- def call(*attrs)
13
- new(*attrs).call
12
+ def call(invite:)
13
+ new(invite: invite).call
14
14
  end
15
15
  end
16
16
 
@@ -14,8 +14,8 @@ module PagesCore
14
14
  end
15
15
 
16
16
  class << self
17
- def call(*attrs)
18
- new(*attrs).call
17
+ def call(attrs, user:, host:, protocol: "http")
18
+ new(attrs, user: user, host: host, protocol: protocol).call
19
19
  end
20
20
  end
21
21
 
@@ -9,7 +9,7 @@
9
9
  all_day: @page.all_day }) %>
10
10
  <% end %>
11
11
 
12
- <% if !@page.new_record? && @page.template_config.value(:tags) %>
12
+ <% if @page.template_config.value(:tags) %>
13
13
  <div class="field">
14
14
  <label>
15
15
  Tags
@@ -1,8 +1,4 @@
1
1
  <%= react_component("PageFiles",
2
2
  locale: @locale,
3
3
  locales: PagesCore.config.locales,
4
- csrf_token: form_authenticity_token,
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
- csrf_token: form_authenticity_token,
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 }) %>