* Refactored post history. Each post now has a single history record. This history record has multiple revisions, serialized as JSON in a text field.
This commit is contained in:
19
app/presenters/post_history_presenter.rb
Normal file
19
app/presenters/post_history_presenter.rb
Normal file
@@ -0,0 +1,19 @@
|
||||
class PostHistoryPresenter < Presenter
|
||||
attr_reader :revision
|
||||
|
||||
def initialize(revision)
|
||||
@revision = revision
|
||||
end
|
||||
|
||||
def changes
|
||||
|
||||
end
|
||||
|
||||
def updated_at
|
||||
revision["updated_at"]
|
||||
end
|
||||
|
||||
def updater_name
|
||||
User.id_to_name(revision["user_id"].to_i)
|
||||
end
|
||||
end
|
||||
@@ -1,7 +1,24 @@
|
||||
class PostPresenter < Presenter
|
||||
def self.preview(post)
|
||||
flags = []
|
||||
flags << "pending" if post.is_pending?
|
||||
flags << "flagged" if post.is_flagged?
|
||||
flags << "removed" if post.is_removed?
|
||||
|
||||
html = %{<article id="post_#{post.id}" data-id="#{post.id}" data-tags="#{h(post.tag_string)}" data-uploader="#{h(post.uploader_name)}" data-rating="#{post.rating}" data-width="#{post.image_width}" data-height="#{post.image_height}" data-flags="#{flags.join(' ')}">}
|
||||
html << %{<a href="/posts/#{post.id}">}
|
||||
html << %{<img src="#{post.preview_file_url}">}
|
||||
html << %{</a>}
|
||||
html << %{</article>}
|
||||
end
|
||||
|
||||
def initialize(post)
|
||||
@post = post
|
||||
end
|
||||
|
||||
def preview_html
|
||||
PostPresenter.preview(@post)
|
||||
end
|
||||
|
||||
def image_html(template)
|
||||
return template.content_tag("p", "This image was deleted.") if @post.is_removed? && !CurrentUser.user.is_janitor?
|
||||
|
||||
@@ -50,16 +50,7 @@ class PostSetPresenter < Presenter
|
||||
html = ""
|
||||
|
||||
posts.each do |post|
|
||||
flags = []
|
||||
flags << "pending" if post.is_pending?
|
||||
flags << "flagged" if post.is_flagged?
|
||||
flags << "removed" if post.is_removed?
|
||||
|
||||
html << %{<article id="post_#{post.id}" data-id="#{post.id}" data-tags="#{h(post.tag_string)}" data-uploader="#{h(post.uploader_name)}" data-rating="#{post.rating}" data-width="#{post.image_width}" data-height="#{post.image_height}" data-flags="#{flags.join(' ')}">}
|
||||
html << %{<a href="/posts/#{post.id}">}
|
||||
html << %{<img src="#{post.preview_file_url}">}
|
||||
html << %{</a>}
|
||||
html << %{</article>}
|
||||
html << PostPresenter.preview(post)
|
||||
end
|
||||
|
||||
html.html_safe
|
||||
|
||||
Reference in New Issue
Block a user