pageflow 14.5.2 → 15.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of pageflow might be problematic. Click here for more details.

Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +44 -39
  3. data/admins/pageflow/membership.rb +1 -5
  4. data/app/assets/javascripts/pageflow/dist/react-client.js +62 -179
  5. data/app/assets/javascripts/pageflow/dist/react-server.js +62 -179
  6. data/app/assets/javascripts/pageflow/editor/api/widget_type.js +1 -0
  7. data/app/assets/javascripts/pageflow/editor/base.js +2 -2
  8. data/app/assets/javascripts/pageflow/editor/collections/files_collection.js +4 -0
  9. data/app/assets/javascripts/pageflow/editor/collections/nested_files_collection.js +4 -0
  10. data/app/assets/javascripts/pageflow/editor/initializers/setup_audio.js +1 -1
  11. data/app/assets/javascripts/pageflow/editor/models/encoded_file.js +1 -1
  12. data/app/assets/javascripts/pageflow/editor/models/image_file.js +1 -1
  13. data/app/assets/javascripts/pageflow/editor/models/mixins/transient_references.js +7 -7
  14. data/app/assets/javascripts/pageflow/editor/models/preview_entry_data.js +2 -2
  15. data/app/assets/javascripts/pageflow/editor/models/{uploaded_file.js → reusable_file.js} +1 -1
  16. data/app/assets/javascripts/pageflow/editor/models/text_track_file.js +2 -2
  17. data/app/assets/javascripts/pageflow/editor/models/{hosted_file.js → uploadable_file.js} +1 -1
  18. data/app/assets/javascripts/pageflow/editor/views/widget_types/title_loading_spinner.js +0 -3
  19. data/app/assets/stylesheets/pageflow/mixins/pageflow.scss +1 -1
  20. data/app/assets/stylesheets/pageflow/themes/default/base.scss +1 -1
  21. data/app/assets/stylesheets/pageflow/themes/default/loading_spinner/title.scss +50 -10
  22. data/app/assets/stylesheets/pageflow/themes/default/loading_spinner.scss +0 -2
  23. data/app/assets/stylesheets/pageflow/themes/default/player_controls/classic/info_box.scss +0 -5
  24. data/app/assets/stylesheets/pageflow/themes/default/player_controls/slim/info_box.scss +0 -4
  25. data/app/controllers/pageflow/files_controller.rb +3 -3
  26. data/app/helpers/pageflow/audio_files_helper.rb +18 -16
  27. data/app/helpers/pageflow/background_image_helper.rb +22 -17
  28. data/app/helpers/pageflow/entry_json_seed_helper.rb +3 -3
  29. data/app/helpers/pageflow/file_thumbnails_helper.rb +1 -1
  30. data/app/helpers/pageflow/meta_tags_helper.rb +3 -3
  31. data/app/helpers/pageflow/pages_helper.rb +10 -1
  32. data/app/helpers/pageflow/revision_file_helper.rb +27 -0
  33. data/app/helpers/pageflow/social_share_helper.rb +5 -3
  34. data/app/helpers/pageflow/social_share_links_helper.rb +1 -1
  35. data/app/helpers/pageflow/video_files_helper.rb +18 -13
  36. data/app/jobs/pageflow/{process_file_job.rb → process_image_or_text_track_job.rb} +1 -1
  37. data/app/models/concerns/pageflow/{uploaded_file.rb → reusable_file.rb} +59 -5
  38. data/app/models/concerns/pageflow/{hosted_file.rb → uploadable_file.rb} +26 -15
  39. data/app/models/pageflow/audio_file.rb +2 -2
  40. data/app/models/pageflow/draft_entry.rb +1 -1
  41. data/app/models/pageflow/entry.rb +0 -8
  42. data/app/models/pageflow/file_usage.rb +3 -1
  43. data/app/models/pageflow/image_file.rb +31 -29
  44. data/app/models/pageflow/membership.rb +4 -3
  45. data/app/models/pageflow/page.rb +0 -8
  46. data/app/models/pageflow/positioned_file.rb +3 -2
  47. data/app/models/pageflow/published_entry.rb +9 -3
  48. data/app/models/pageflow/revision.rb +6 -12
  49. data/app/models/pageflow/text_track_file.rb +13 -12
  50. data/app/models/pageflow/thumbnail_file_resolver.rb +3 -3
  51. data/app/models/pageflow/used_file.rb +4 -0
  52. data/app/models/pageflow/video_file.rb +2 -2
  53. data/app/models/pageflow/widget.rb +6 -12
  54. data/app/state_machines/pageflow/{processed_file_state_machine.rb → image_and_text_track_processing_state_machine.rb} +3 -2
  55. data/app/state_machines/pageflow/{encoded_file_state_machine.rb → media_encoding_state_machine.rb} +27 -19
  56. data/app/views/pageflow/editor/files/_file.json.jbuilder +1 -1
  57. data/app/views/pageflow/entries/mobile_navigation/_page.html.erb +1 -1
  58. data/app/views/pageflow/entries/navigation/_page.html.erb +2 -2
  59. data/app/views/pageflow/entries/overview/_page.html.erb +1 -1
  60. data/app/views/pageflow/files/_file.json.jbuilder +1 -0
  61. data/app/views/pageflow/social_share/_page_meta_tags.html.erb +1 -1
  62. data/config/locales/de.yml +0 -24
  63. data/config/locales/en.yml +0 -24
  64. data/db/migrate/20190306161431_copy_file_attributes_of_failed_uploads.rb +4 -4
  65. data/db/migrate/20190523151140_add_perma_id_to_file_usages.rb +13 -0
  66. data/lib/pageflow/built_in_widget_type.rb +0 -7
  67. data/lib/pageflow/built_in_widget_types_plugin.rb +0 -6
  68. data/lib/pageflow/user_mixin.rb +0 -6
  69. data/lib/pageflow/version.rb +1 -1
  70. data/lib/pageflow/widget_types.rb +1 -9
  71. data/spec/factories/{hosted_files.rb → uploadable_files.rb} +3 -3
  72. metadata +16 -32
  73. data/app/assets/javascripts/pageflow/dist/editor.js +0 -11890
  74. data/app/assets/javascripts/pageflow/dist/frontend.js +0 -5800
  75. data/app/assets/javascripts/pageflow/dist/ui.js +0 -3114
  76. data/app/assets/javascripts/pageflow/editor/views/widget_types/media_loading_spinner.js +0 -18
  77. data/app/assets/stylesheets/pageflow/themes/default/loading_spinner/media.scss +0 -56
@@ -78,11 +78,6 @@ $classic-player-controls-info-box-border-radius: 4px !default;
78
78
 
79
79
  .js &-info_box {
80
80
  pointer-events: none;
81
-
82
- a {
83
- pointer-events: all;
84
- }
85
-
86
81
  margin: 0;
87
82
  margin-bottom: 60px + $classic-player-controls-border-width * 4;
88
83
  width: 434px;
@@ -73,10 +73,6 @@ $slim-player-controls-info-box-header-typography: () !default;
73
73
  @include transition(opacity 0.2s linear, visibility 0.2s linear, transform 0.2s ease);
74
74
  pointer-events: none;
75
75
 
76
- a {
77
- pointer-events: all;
78
- }
79
-
80
76
  position: absolute;
81
77
  left: 50%;
82
78
  @include transform(translate3d(-50%, 0, 0));
@@ -8,10 +8,10 @@ module Pageflow
8
8
  def show
9
9
  respond_to do |format|
10
10
  format.html do
11
- entry = PublishedEntry.find(params[:entry_id], entry_request_scope)
12
- @file = entry.find_file(file_type.model, params[:id])
11
+ @entry = PublishedEntry.find(params[:entry_id], entry_request_scope)
12
+ @file = @entry.find_file(file_type.model, params[:id])
13
13
 
14
- check_entry_password_protection(entry)
14
+ check_entry_password_protection(@entry)
15
15
  end
16
16
  end
17
17
  end
@@ -1,32 +1,34 @@
1
1
  module Pageflow
2
2
  module AudioFilesHelper
3
- def audio_file_audio_tag(audio_file_id, options = {})
3
+ include RevisionFileHelper
4
+
5
+ def audio_file_audio_tag(audio_file_perma_id, options = {})
4
6
  options.merge!(class: ['audio-js', options.delete(:class)].compact * ' ',
5
7
  controls: true,
6
8
  preload: 'none')
7
9
  url_options = {unique_id: options.delete(:unique_id)}
8
10
 
9
- if (audio_file = AudioFile.find_by_id(audio_file_id))
10
- content_tag(:audio, options) do
11
- audio_file_sources(audio_file, url_options).each do |source|
12
- concat(tag(:source, source.slice(:src, :type)))
13
- end
11
+ audio_file = find_file_in_entry(AudioFile, audio_file_perma_id)
12
+ return unless audio_file
13
+ content_tag(:audio, options) do
14
+ audio_file_sources(audio_file, url_options).each do |source|
15
+ concat(tag(:source, source.slice(:src, :type)))
14
16
  end
15
17
  end
16
18
  end
17
19
 
18
- def audio_file_script_tag(audio_file_id, options = {})
19
- if (audio_file = AudioFile.find_by_id(audio_file_id))
20
- render('pageflow/audio_files/script_tag',
21
- audio_file: audio_file,
22
- audio_file_sources: audio_file_sources(audio_file, options))
23
- end
20
+ def audio_file_script_tag(audio_file_perma_id, options = {})
21
+ audio_file = find_file_in_entry(AudioFile, audio_file_perma_id)
22
+ return unless audio_file
23
+ render('pageflow/audio_files/script_tag',
24
+ audio_file: audio_file,
25
+ audio_file_sources: audio_file_sources(audio_file, options))
24
26
  end
25
27
 
26
- def audio_file_non_js_link(entry, audio_file_id)
27
- if (audio_file = AudioFile.find_by_id(audio_file_id))
28
- link_to(t('pageflow.audio.open'), short_audio_file_path(entry, audio_file))
29
- end
28
+ def audio_file_non_js_link(entry, audio_file_perma_id)
29
+ audio_file = find_file_in_entry(AudioFile, audio_file_perma_id)
30
+ return unless audio_file
31
+ link_to(t('pageflow.audio.open'), short_audio_file_path(entry, audio_file))
30
32
  end
31
33
 
32
34
  def audio_file_sources(audio_file, options = {})
@@ -1,33 +1,36 @@
1
1
  module Pageflow
2
2
  module BackgroundImageHelper
3
+ include RevisionFileHelper
4
+
3
5
  def background_image_div(configuration, property_base_name, options = {})
4
- Div.new(self, configuration, property_base_name, options).render
6
+ Div.new(@entry, self, configuration, property_base_name, options).render
5
7
  end
6
8
 
7
9
  def background_image_div_with_size(configuration, property_base_name, options = {})
8
- DivWithSizeAttributes.new(self, configuration, property_base_name, options).render
10
+ DivWithSizeAttributes.new(@entry, self, configuration, property_base_name, options).render
9
11
  end
10
12
 
11
- def background_image_tag(image_id, options = {})
12
- image = ImageFile.find_by_id(image_id)
13
- if image&.ready?
14
- options = options.merge(:'data-src' => image.attachment.url(:medium))
15
- options = options.merge(:'data-printsrc' => image.attachment.url(:print))
16
- image_tag('', options)
17
- end
13
+ def background_image_tag(image_perma_id, options = {})
14
+ image = find_file_in_entry(ImageFile, image_perma_id)
15
+ return unless image&.ready?
16
+
17
+ options = options.merge('data-src': image.attachment.url(:medium))
18
+ options = options.merge('data-printsrc': image.attachment.url(:print))
19
+ image_tag('', options)
18
20
  end
19
21
 
20
22
  def background_image_lazy_loading_css_class(prefix, model)
21
- css_class = [prefix, model.id].join('_')
23
+ css_class = [prefix, model.perma_id].join('_')
22
24
  ".load_all_images .#{css_class}, .load_image.#{css_class}"
23
25
  end
24
26
 
25
27
  class Div
26
28
  attr_reader :configuration, :property_base_name, :options
27
29
 
28
- delegate :content_tag, :to => :@template
30
+ delegate :content_tag, to: :@template
29
31
 
30
- def initialize(template, configuration, property_base_name, options)
32
+ def initialize(entry, template, configuration, property_base_name, options)
33
+ @entry = entry
31
34
  @template = template
32
35
  @configuration = configuration
33
36
  @property_base_name = property_base_name
@@ -35,7 +38,7 @@ module Pageflow
35
38
  end
36
39
 
37
40
  def render
38
- content_tag(:div, '', :class => css_class, :style => inline_style, :data => data_attributes)
41
+ content_tag(:div, '', class: css_class, style: inline_style, data: data_attributes)
39
42
  end
40
43
 
41
44
  protected
@@ -44,7 +47,7 @@ module Pageflow
44
47
  options.slice(:style_group)
45
48
  end
46
49
 
47
- def file_id
50
+ def file_perma_id
48
51
  configuration["#{property_base_name}_id"]
49
52
  end
50
53
 
@@ -59,7 +62,7 @@ module Pageflow
59
62
  end
60
63
 
61
64
  def image_css_class
62
- [image_css_class_prefix, options[:style_group], file_id || 'none'].compact.join('_')
65
+ [image_css_class_prefix, options[:style_group], file_perma_id || 'none'].compact.join('_')
63
66
  end
64
67
 
65
68
  def image_css_class_prefix
@@ -78,9 +81,11 @@ module Pageflow
78
81
  end
79
82
 
80
83
  class DivWithSizeAttributes < Div
84
+ include RevisionFileHelper
85
+
81
86
  def data_attributes
82
87
  if file
83
- super.merge(:width => file.width, :height => file.height)
88
+ super.merge(width: file.width, height: file.height)
84
89
  else
85
90
  super
86
91
  end
@@ -110,7 +115,7 @@ module Pageflow
110
115
  end
111
116
 
112
117
  def find_file
113
- file_type.model.find_by_id(file_id)
118
+ find_file_in_entry(file_type.model, file_perma_id)
114
119
  end
115
120
  end
116
121
  end
@@ -50,13 +50,13 @@ module Pageflow
50
50
 
51
51
  def entry_file_ids_seed(entry)
52
52
  Pageflow.config.file_types.with_thumbnail_support.each_with_object({}) do |file_type, result|
53
- result[file_type.collection_name] = entry.find_files(file_type.model).map(&:id)
53
+ result[file_type.collection_name] = entry.find_files(file_type.model).map(&:perma_id)
54
54
  end
55
55
  end
56
56
 
57
57
  def entry_audio_files_json_seed(entry)
58
- seed = entry.audio_files.each_with_object({}) do |audio_file, result|
59
- result[audio_file.id] = audio_file_sources(audio_file)
58
+ seed = entry.find_files(AudioFile).each_with_object({}) do |audio_file, result|
59
+ result[audio_file.perma_id] = audio_file_sources(audio_file)
60
60
  end
61
61
 
62
62
  sanitize_json(seed.to_json).html_safe
@@ -12,7 +12,7 @@ module Pageflow
12
12
 
13
13
  def file_thumbnail_css_class(file, style)
14
14
  return if file.blank?
15
- [file.to_model.class.model_name.singular, style, file.to_model.id] * '_'
15
+ [file.to_model.class.model_name.singular, style, file.perma_id] * '_'
16
16
  end
17
17
  end
18
18
  end
@@ -7,9 +7,9 @@ module Pageflow
7
7
 
8
8
  def meta_tags_data_for_entry(entry)
9
9
  {
10
- keywords: entry.keywords.presence,
11
- author: entry.author.presence,
12
- publisher: entry.publisher.presence
10
+ keywords: entry.keywords.presence || Pageflow.config.default_keywords_meta_tag,
11
+ author: entry.author.presence || Pageflow.config.default_author_meta_tag,
12
+ publisher: entry.publisher.presence || Pageflow.config.default_publisher_meta_tag
13
13
  }
14
14
  end
15
15
  end
@@ -88,7 +88,16 @@ module Pageflow
88
88
  end
89
89
 
90
90
  def page_thumbnail_image_class(page, hero)
91
- file_thumbnail_css_class(page.thumbnail_file, hero ? :link_thumbnail_large : :link_thumbnail)
91
+ file_thumbnail_css_class(page_thumbnail_file(page), hero ? :link_thumbnail_large : :link_thumbnail)
92
+ end
93
+
94
+ def page_thumbnail_url(page, *args)
95
+ page_thumbnail_file(page).thumbnail_url(*args)
96
+ end
97
+
98
+ def page_thumbnail_file(page)
99
+ ThumbnailFileResolver.new(@entry, page.page_type.thumbnail_candidates, page.configuration)
100
+ .find_thumbnail
92
101
  end
93
102
  end
94
103
  end
@@ -0,0 +1,27 @@
1
+ module Pageflow
2
+ module RevisionFileHelper
3
+ # Instead of finding a file directly by its ID (stored in configuration hashes for example),
4
+ # finds the file by its usages perma_id within the scope of the revisions usages.
5
+ # The @entry instance variable (of type DraftEntry or PublishedEntry)
6
+ # must always be available in views using this helper, otherwise an exception is raised.
7
+ #
8
+ # When testing helpers which use the RevisionFileHelper to find their respective files,
9
+ # you can use the UsedfileTestHelper to create the file. This will set the @entry-variable
10
+ # and create a file usage for the file:
11
+ #
12
+ # image_file = create_used_file(:image_file)
13
+ #
14
+ # This simplifies spec setup by eliminating the need to set up the entry and usages first.
15
+ # If you need to setup the entry explicitely, you can optionally pass it to the helper like so:
16
+ #
17
+ # entry = PublishedEntry.new(create(:entry, :published))
18
+ # image_file = create_used_file(:image_file, entry: entry)
19
+ #
20
+ # @since 15.0
21
+ # @returns UsedFile
22
+ def find_file_in_entry(file_type, file_perma_id)
23
+ raise 'No entry of type PublishedEntry or DraftEntry set.' unless @entry.present?
24
+ @entry.find_file_by_perma_id(file_type, file_perma_id)
25
+ end
26
+ end
27
+ end
@@ -1,6 +1,8 @@
1
1
  module Pageflow
2
2
  module SocialShareHelper
3
3
  include EntriesHelper
4
+ include PagesHelper
5
+ include RevisionFileHelper
4
6
 
5
7
  def social_share_meta_tags_for(target)
6
8
  if target.is_a?(Page)
@@ -53,7 +55,7 @@ module Pageflow
53
55
 
54
56
  def social_share_entry_image_tags(entry)
55
57
  image_urls = []
56
- image_file = ImageFile.find_by_id(entry.share_image_id)
58
+ image_file = find_file_in_entry(ImageFile, entry.share_image_id)
57
59
 
58
60
  if image_file
59
61
  image_urls << image_file.thumbnail_url(:medium)
@@ -62,13 +64,13 @@ module Pageflow
62
64
  if image_urls.size >= 4
63
65
  break
64
66
  else
65
- image_urls << page.thumbnail_url(:medium)
67
+ image_urls << page_thumbnail_url(page, :medium)
66
68
  image_urls.uniq!
67
69
  end
68
70
  end
69
71
  end
70
72
 
71
- render 'pageflow/social_share/image_tags', :image_urls => image_urls
73
+ render 'pageflow/social_share/image_tags', image_urls: image_urls
72
74
  end
73
75
 
74
76
  def social_share_normalize_protocol(url)
@@ -8,7 +8,7 @@ module Pageflow
8
8
  google: 'https://plus.google.com/share?url=%{url}',
9
9
  linked_in: 'https://www.linkedin.com/shareArticle?mini=true&url=%{url}',
10
10
  telegram: 'tg://msg?text=%{url}',
11
- twitter: 'https://twitter.com/intent/tweet?url=%{url}',
11
+ twitter: 'http://twitter.com/home?status=%{url}',
12
12
  whats_app: 'WhatsApp://send?text=%{url}'
13
13
  }.freeze
14
14
 
@@ -1,5 +1,7 @@
1
1
  module Pageflow
2
2
  module VideoFilesHelper
3
+ include RevisionFileHelper
4
+
3
5
  def mobile_poster_image_div(config = {})
4
6
  classes = ['background', 'background_image']
5
7
  position = {x: 50, y: 50}
@@ -25,9 +27,9 @@ module Pageflow
25
27
  style: "background-position: #{position[:x]}% #{position[:y]}%;")
26
28
  end
27
29
 
28
- def poster_image_tag(video_id, poster_image_id, options = {})
29
- video_file = VideoFile.find_by_id(video_id)
30
- poster = ImageFile.find_by_id(poster_image_id)
30
+ def poster_image_tag(video_file_perma_id, poster_image_perma_id = nil, options = {})
31
+ video_file = find_file_in_entry(VideoFile, video_file_perma_id)
32
+ poster = poster_image_perma_id.present? ? find_file_in_entry(ImageFile, poster_image_perma_id) : nil
31
33
 
32
34
  if poster&.ready?
33
35
  options = options.merge('data-src' => poster.attachment.url(:medium))
@@ -53,8 +55,10 @@ module Pageflow
53
55
  options.reverse_merge! defaults
54
56
  url_options = {unique_id: options.delete(:unique_id)}
55
57
 
56
- poster = ImageFile.find_by_id(options.delete(:poster_image_id))
57
- mobile_poster = ImageFile.find_by_id(options.delete(:mobile_poster_image_id))
58
+ poster_image_id = options.delete(:poster_image_id)
59
+ poster = poster_image_id.present? ? find_file_in_entry(ImageFile, poster_image_id) : nil
60
+ mobile_poster_image_id = options.delete(:mobile_poster_image_id)
61
+ mobile_poster = mobile_poster_image_id.present? ? find_file_in_entry(ImageFile, mobile_poster_image_id) : nil
58
62
 
59
63
  options[:data] = {}
60
64
 
@@ -87,8 +91,8 @@ module Pageflow
87
91
  video_file_script_tag(video_id, options.merge(poster_image_id: poster_image_id))
88
92
  end
89
93
 
90
- def video_file_script_tag(video_id, options = {})
91
- video_file = VideoFile.find_by_id(video_id)
94
+ def video_file_script_tag(video_file_perma_id, options = {})
95
+ video_file = find_file_in_entry(VideoFile, video_file_perma_id)
92
96
 
93
97
  script_tag_data = {template: 'video'}
94
98
 
@@ -103,12 +107,13 @@ module Pageflow
103
107
  options: options)
104
108
  end
105
109
 
106
- def video_file_non_js_link(entry, video_file_id)
107
- if (video_file = VideoFile.find_by_id(video_file_id))
108
- link_to(t('pageflow.public.play_video'),
109
- short_video_file_path(entry, video_file),
110
- class: 'hint')
111
- end
110
+ def video_file_non_js_link(entry, video_file_perma_id)
111
+ video_file = find_file_in_entry(VideoFile, video_file_perma_id)
112
+ return unless video_file
113
+
114
+ link_to(t('pageflow.public.play_video'),
115
+ short_video_file_path(entry, video_file.id),
116
+ class: 'hint')
112
117
  end
113
118
 
114
119
  def video_file_sources(video_file, options = {})
@@ -1,5 +1,5 @@
1
1
  module Pageflow
2
- class ProcessFileJob < ApplicationJob
2
+ class ProcessImageOrTextTrackJob < ApplicationJob
3
3
  queue_as :resizing
4
4
 
5
5
  include StateMachineJob
@@ -1,5 +1,5 @@
1
1
  module Pageflow
2
- module UploadedFile
2
+ module ReusableFile
3
3
  extend ActiveSupport::Concern
4
4
 
5
5
  included do
@@ -56,14 +56,68 @@ module Pageflow
56
56
  "#{super}-#{state}"
57
57
  end
58
58
 
59
+
60
+ # The following are method defaults for file types that do not require processing/encoding.
61
+ # They are overwritten with default values in UploadableFile for files that are uploaded
62
+ # through the editor.
63
+
64
+ # Overwritten if a file type provides a default url for its file.
65
+ def url
66
+ ''
67
+ end
68
+
69
+ # Overwritten in case of a file type providing its original (unprocessed) file
70
+ # for download in the editor.
71
+ # Defaults to the default url of the file (see above)
72
+ def original_url
73
+ url
74
+ end
75
+
76
+ # Overwritten with the basename of the file.
77
+ def basename
78
+ 'unused'
79
+ end
80
+
81
+ # Overwritten in UploadableFile with attachment filename.
82
+ def file_name
83
+ 'unused'
84
+ end
85
+
86
+ # Overwritten in UploadableFile based on initial state_machine-state.
87
+ # Defaults to false for files that only use the ReusableFile module
59
88
  def can_upload?
60
- # Overwritten in HostedFile based on initial state_machine-state.
61
- # Only true directly after creation.
62
89
  false
63
90
  end
64
91
 
65
- def direct_upload_config
66
- Pageflow.config.paperclip_direct_upload_options.call(attachment)
92
+ # Overwritten with the conditions that need to be fulfilled in order to `retry`
93
+ # whatever the file does (i.e. processing/transcoding).
94
+ def retryable?
95
+ raise 'Not implemented!'
96
+ end
97
+
98
+ # Overwritten with the conditions that need to be fulfilled in order to (re)use the file.
99
+ def ready?
100
+ raise 'Not implemented!'
101
+ end
102
+
103
+ # Overwritten with the conditions that indicate failure during processing.
104
+ def failed?
105
+ raise 'Not implemented!'
106
+ end
107
+
108
+ # If the conditions in retryable? are met then this method specifies what should happen when
109
+ # a retry is requested, depending on the including class' processing state machine.
110
+ def retry!
111
+ raise 'Not implemented!'
112
+ end
113
+
114
+ # Gets called to trigger the `file_uploaded` event in the upload state machine of UploadableFile.
115
+ # Files that are not uploaded through the editor (and therefore not using the
116
+ # upload state machine of UploadableFile) can overwrite this method to trigger whatever
117
+ # the file does (i.e. processing/transcoding), depending on the including class'
118
+ # processing state machine.
119
+ def publish!
120
+ raise 'Not implemented!'
67
121
  end
68
122
  end
69
123
  end
@@ -1,7 +1,7 @@
1
1
  module Pageflow
2
- module HostedFile
2
+ module UploadableFile
3
3
  extend ActiveSupport::Concern
4
- include UploadedFile
4
+ include ReusableFile
5
5
 
6
6
  included do
7
7
  alias_attribute :file_name, :attachment_on_s3_file_name
@@ -30,7 +30,7 @@ module Pageflow
30
30
  state 'uploaded'
31
31
  state 'uploading_failed'
32
32
 
33
- event :publish do
33
+ event :file_uploaded do
34
34
  transition 'uploading' => 'uploaded'
35
35
  end
36
36
 
@@ -46,14 +46,35 @@ module Pageflow
46
46
  self.attachment_on_s3 = value
47
47
  end
48
48
 
49
+ def direct_upload_config
50
+ Pageflow.config.paperclip_direct_upload_options.call(attachment)
51
+ end
52
+
53
+ # Overwritten if a file type wants to merge its attachments default_url into
54
+ # Pageflow.config.paperclip_s3_default_options.
55
+ # (See Pageflow::ImageFile for example)
49
56
  def attachment_default_url
50
57
  ''
51
58
  end
52
59
 
60
+ # Overwritten if a file type wants to add additional styles to
61
+ # Pageflow.config.paperclip_s3_default_options.
62
+ # (See Pageflow::ImageFile for example)
53
63
  def attachment_styles(_attachment)
54
64
  {}
55
65
  end
56
66
 
67
+ # ReusableFile-overrides:
68
+ def url
69
+ if attachment.present?
70
+ attachment.url
71
+ end
72
+ end
73
+
74
+ def basename
75
+ File.basename(attachment.original_filename, '.*')
76
+ end
77
+
57
78
  def can_upload?
58
79
  uploading?
59
80
  end
@@ -70,18 +91,8 @@ module Pageflow
70
91
  uploading_failed?
71
92
  end
72
93
 
73
- def basename
74
- File.basename(attachment.original_filename, '.*')
75
- end
76
-
77
- def url
78
- if attachment.present?
79
- attachment.url
80
- end
81
- end
82
-
83
- def original_url
84
- url
94
+ def publish!
95
+ file_uploaded!
85
96
  end
86
97
 
87
98
  module ClassMethods
@@ -1,7 +1,7 @@
1
1
  module Pageflow
2
2
  class AudioFile < ApplicationRecord
3
- include HostedFile
4
- include EncodedFileStateMachine
3
+ include UploadableFile
4
+ include MediaEncodingStateMachine
5
5
 
6
6
  belongs_to :confirmed_by, class_name: 'User', optional: true
7
7
 
@@ -20,7 +20,7 @@ module Pageflow
20
20
  :emphasize_new_pages,
21
21
  :share_url, :share_image_id, :share_image_x, :share_image_y,
22
22
  :share_providers, :active_share_providers,
23
- :find_files, :find_file,
23
+ :find_files, :find_file, :find_file_by_perma_id,
24
24
  :image_files, :video_files, :audio_files,
25
25
  :locale,
26
26
  :author, :publisher, :keywords,
@@ -112,14 +112,6 @@ module Pageflow
112
112
  [:title, [:title, :id]]
113
113
  end
114
114
 
115
- def self.ransackable_attributes(_auth_object)
116
- %w[title type_name created_at edited_at first_published_at]
117
- end
118
-
119
- def self.ransackable_associations(_auth_object)
120
- %w[account published_revision]
121
- end
122
-
123
115
  def self.ransackable_scopes(_)
124
116
  [:with_publication_state, :published]
125
117
  end
@@ -1,8 +1,10 @@
1
1
  module Pageflow
2
2
  class FileUsage < ApplicationRecord
3
3
  include SerializedConfiguration
4
+ include RevisionComponent
5
+
6
+ alias_attribute :perma_id, :file_perma_id
4
7
 
5
- belongs_to :revision
6
8
  belongs_to :file, polymorphic: true
7
9
 
8
10
  def copy_to(revision)