feat(posts): extend preview and show
This commit is contained in:
1 parent
10d1cdaf1e
commit
4043926dea
3 files changed
+140
No files matched your search
@@ -0,0 +1,46 @@
|
||||
<h1><%= t('posts.preview_heading') %></h1>
|
||||
|
||||
<% unless errors.empty? %>
|
||||
<h2><%= t('posts.errors_heading') %></h2>
|
||||
<ul class="errors">
|
||||
<% errors.each do |message| %>
|
||||
<li><%= message %></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
<% end %>
|
||||
|
||||
<% if diff.empty? %>
|
||||
<p><%= t('posts.preview_noop') %></p>
|
||||
<% else %>
|
||||
<h2><%= t('posts.preview_diff_heading') %></h2>
|
||||
<table class="diff">
|
||||
<thead>
|
||||
<tr><th><%= t('posts.preview_field') %></th><th><%= t('posts.preview_current') %></th><th><%= t('posts.preview_proposed') %></th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% diff.each do |field, (old_value, new_value)| %>
|
||||
<tr>
|
||||
<td><%= field %></td>
|
||||
<td><%= old_value %></td>
|
||||
<td><%= new_value %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
<% end %>
|
||||
|
||||
<!-- post.title here is read straight off `post` AFTER Dirty#restore_attributes -
|
||||
it must be the row's actual saved title, proving the preview above never
|
||||
mutated the persisted record. -->
|
||||
<p><%= t('posts.preview_currently_saved', title: post.title) %></p>
|
||||
|
||||
<% if errors.empty? %>
|
||||
<% form_for(post, url: url_for(:post, slug: post.to_param), method: :patch) do |f| %>
|
||||
<%== f.hidden_field(:title, value: attempted['title']) %>
|
||||
<%== f.hidden_field(:body, value: attempted['body']) %>
|
||||
<%== f.hidden_field(:lock_version) %>
|
||||
<%== f.submit(t('posts.preview_confirm')) %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<p><%== link_to(t('posts.edit_link'), url_for(:edit_post, slug: post.to_param)) %></p>
|
||||
@@ -1,2 +1,75 @@
|
||||
<% if notice %>
|
||||
<p class="notice"><%= notice %></p>
|
||||
<% end %>
|
||||
|
||||
<h1><%= post.title %></h1>
|
||||
<p class="status"><%= t("posts.status_#{post.status}") %></p>
|
||||
<% if post.cover %>
|
||||
<p><img src="/uploads/<%= post.cover %>" alt="<%= post.title %>"></p>
|
||||
<% end %>
|
||||
<p><%= post.body %></p>
|
||||
<p class="last-activity"><%= t('posts.last_activity', when: l(post.updated_at)) %></p>
|
||||
<p>
|
||||
<%= t('likes.count', count: likes_count(post)) %>
|
||||
<% if user_signed_in? %>
|
||||
<% own_like = current_user_like(post) %>
|
||||
<% if own_like %>
|
||||
<%== button_to(t('likes.unlike'), "/likes/#{own_like.id}", method: :delete) %>
|
||||
<% else %>
|
||||
<%== button_to(t('likes.like'), "/likes?likeable_type=Post&likeable_id=#{post.id}") %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</p>
|
||||
<% if post.giveaway? %>
|
||||
<p class="giveaway">
|
||||
<% if post.giveaway_sold_out? %>
|
||||
<%= t('claims.sold_out_label') %>
|
||||
<% else %>
|
||||
<%= t('claims.remaining_label', count: post.giveaway_remaining) %>
|
||||
<% end %>
|
||||
<% if user_signed_in? %>
|
||||
<% if current_user_claim(post) %>
|
||||
<%= t('claims.already_claimed_label') %>
|
||||
<% elsif !post.giveaway_sold_out? %>
|
||||
<%== button_to(t('claims.claim_button'), "/posts/#{post.to_param}/claims") %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</p>
|
||||
<% end %>
|
||||
<p><%== link_to(t('posts.back_to_list'), url_for(:posts)) %></p>
|
||||
<% if current_user && current_user.id == post.user_id %>
|
||||
<p><%== link_to(t('posts.edit_link'), url_for(:edit_post, slug: post.to_param)) %></p>
|
||||
<% if post.published? %>
|
||||
<%== button_to(t('posts.unpublish'), url_for(:unpublish_post, slug: post.to_param), method: :patch) %>
|
||||
<% else %>
|
||||
<%== button_to(t('posts.publish'), url_for(:publish_post, slug: post.to_param), method: :patch) %>
|
||||
<% end %>
|
||||
<%== button_to(t('posts.delete'), url_for(:post, slug: post.to_param), method: :delete, data_confirm: t('posts.confirm_delete')) %>
|
||||
<%== link_to(t('posts.trash_heading'), url_for(:trash_posts)) %>
|
||||
<% end %>
|
||||
|
||||
<h2><%= t('comments.heading') %></h2>
|
||||
<p><%== link_to(t('comments.view_all_link'), url_for(:comments, post_id: post.to_param)) %></p>
|
||||
<% if comments.empty? %>
|
||||
<p><%= t('comments.empty') %></p>
|
||||
<% else %>
|
||||
<ul class="comments">
|
||||
<% comments.each do |comment| %>
|
||||
<%== partial('comment', locals: { comment: comment, post: post }) %>
|
||||
<% end %>
|
||||
</ul>
|
||||
<% end %>
|
||||
|
||||
<% if user_signed_in? %>
|
||||
<% form_for(new_comment, url: "/posts/#{post.to_param}/comments", method: :post) do |f| %>
|
||||
<p>
|
||||
<%== f.label(:author, t('comments.author_label')) %>
|
||||
<%== f.text_field(:author) %>
|
||||
</p>
|
||||
<p>
|
||||
<%== f.label(:body, t('comments.body_label')) %>
|
||||
<%== f.text_area(:body) %>
|
||||
</p>
|
||||
<%== f.submit(t('comments.submit')) %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
@@ -0,0 +1,21 @@
|
||||
<% if notice %>
|
||||
<p class="notice"><%= notice %></p>
|
||||
<% end %>
|
||||
|
||||
<h1><%= t('posts.trash_heading') %></h1>
|
||||
|
||||
<% if posts.empty? %>
|
||||
<p><%= t('posts.trash_empty') %></p>
|
||||
<% else %>
|
||||
<ul class="posts trash">
|
||||
<% posts.each do |post| %>
|
||||
<li class="post" id="post-<%= post.to_param %>">
|
||||
<h2><%= post.title %></h2>
|
||||
<p><%= post.body %></p>
|
||||
<%== button_to(t('posts.restore'), url_for(:restore_post, slug: post.to_param), method: :patch) %>
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
||||
<% end %>
|
||||
|
||||
<p><%== link_to(t('posts.back_to_list'), url_for(:posts)) %></p>
|
||||
Reference in new issue
Block a user