Class: Pageflow::Revision

Inherits:
ApplicationRecord show all
Includes:
SerializedConfiguration, ThemeReferencer
Defined in:
app/models/pageflow/revision.rb

Constant Summary collapse

PAGE_ORDER =
[
  'pageflow_storylines.position ASC',
  'pageflow_chapters.position ASC',
  'pageflow_pages.position ASC'
].join(',')
CHAPTER_ORDER =
[
  'pageflow_storylines.position ASC',
  'pageflow_chapters.position ASC'
].join(',')

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ThemeReferencer

#theme

Class Method Details

.depublish_allObject



193
194
195
# File 'app/models/pageflow/revision.rb', line 193

def self.depublish_all
  published.update_all(:published_until => Time.now)
end

.ransackable_attributes(_auth_object = nil) ⇒ Object



209
210
211
# File 'app/models/pageflow/revision.rb', line 209

def self.ransackable_attributes(_auth_object = nil)
  %w[published_at]
end

Instance Method Details

#active_share_providersObject



122
123
124
# File 'app/models/pageflow/revision.rb', line 122

def active_share_providers
  share_providers.select { |_k, v| v }.keys
end

#authorObject



110
111
112
# File 'app/models/pageflow/revision.rb', line 110

def author
  read_attribute(:author) || Pageflow.config.default_author_meta_tag
end

#chaptersObject



138
139
140
# File 'app/models/pageflow/revision.rb', line 138

def chapters
  super.tap { |c| c.first.is_first = true if c.present? }
end

#configurationObject



197
198
199
200
201
202
203
204
205
206
207
# File 'app/models/pageflow/revision.rb', line 197

def configuration
  {
    'emphasize_chapter_beginning' => emphasize_chapter_beginning,
    'emphasize_new_pages' => emphasize_new_pages,
    'home_url' => home_url,
    'home_button_enabled' => home_button_enabled,
    'manual_start' => manual_start,
    'overview_button_enabled' => overview_button_enabled
  }.delete_if { |_k, v| v.nil? }
    .merge(read_attribute(:configuration) || {})
end

#copy {|revision| ... } ⇒ Object

Public interface for copying a revision

Yields:

  • (revision)

Since:

  • 15.1



166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'app/models/pageflow/revision.rb', line 166

def copy(&block)
  revision = dup

  yield(revision) if block_given?

  widgets.each do |widget|
    widget.copy_to(revision)
  end

  file_usages.each do |file_usage|
    file_usage.copy_to(revision)
  end

  find_revision_components.each do |revision_component|
    revision_component.copy_to(revision)
  end

  revision.save!
  revision
end

#created_withObject



151
152
153
154
155
156
157
158
159
160
161
# File 'app/models/pageflow/revision.rb', line 151

def created_with
  if published_at
    :publish
  elsif snapshot_type == 'auto'
    :auto
  elsif snapshot_type == 'user'
    :user
  else
    :restore
  end
end

#creatorObject



126
127
128
# File 'app/models/pageflow/revision.rb', line 126

def creator
  super || NullUser.new
end

#find_file(model, id) ⇒ Object



95
96
97
98
# File 'app/models/pageflow/revision.rb', line 95

def find_file(model, id)
  file = files(model).find(id)
  UsedFile.new(file)
end

#find_file_by_perma_id(model, perma_id) ⇒ Object



100
101
102
103
104
# File 'app/models/pageflow/revision.rb', line 100

def find_file_by_perma_id(model, perma_id)
  file = files(model).find_by(pageflow_file_usages: {file_perma_id: perma_id})
  return unless file
  UsedFile.new(file)
end

#find_files(model) ⇒ Object



89
90
91
92
93
# File 'app/models/pageflow/revision.rb', line 89

def find_files(model)
  files(model).map do |file|
    UsedFile.new(file)
  end
end

#find_revision_componentsObject



187
188
189
190
191
# File 'app/models/pageflow/revision.rb', line 187

def find_revision_components
  Pageflow.config.revision_components.flat_map do |model|
    model.all_for_revision(self).to_a
  end
end

#frozen?Boolean

Returns:

  • (Boolean)


147
148
149
# File 'app/models/pageflow/revision.rb', line 147

def frozen?
  frozen_at.present?
end

#keywordsObject



118
119
120
# File 'app/models/pageflow/revision.rb', line 118

def keywords
  read_attribute(:keywords) || Pageflow.config.default_keywords_meta_tag
end

#localeObject



130
131
132
# File 'app/models/pageflow/revision.rb', line 130

def locale
  super.presence || I18n.default_locale.to_s
end

#main_storyline_chaptersObject



84
85
86
87
# File 'app/models/pageflow/revision.rb', line 84

def main_storyline_chapters
  main_storyline = storylines.first
  main_storyline ? main_storyline.chapters : Chapter.none
end

#pagesObject



134
135
136
# File 'app/models/pageflow/revision.rb', line 134

def pages
  super.tap { |p| p.first.is_first = true if p.present? }
end

#published?Boolean

Returns:

  • (Boolean)


142
143
144
145
# File 'app/models/pageflow/revision.rb', line 142

def published?
  (published_at.present? && Time.now >= published_at) &&
    (published_until.blank? || Time.now < published_until)
end

#publisherObject



114
115
116
# File 'app/models/pageflow/revision.rb', line 114

def publisher
  read_attribute(:publisher) || Pageflow.config.default_publisher_meta_tag
end

#share_providersObject



106
107
108
# File 'app/models/pageflow/revision.rb', line 106

def share_providers
  self[:share_providers] || entry.entry_template.default_share_providers
end