forked from tildeverse/tilde.news
show all suggested tags/titles, lift work from view to db
Also extracted tag_link helper to dedupe that snippet of repeated code.
This commit is contained in:
parent
0cea4d497c
commit
4e653a9896
|
@ -152,6 +152,10 @@ module ApplicationHelper
|
|||
pages
|
||||
end
|
||||
|
||||
def tag_link(tag)
|
||||
link_to tag.tag, tag_path(tag), class: tag.css_class, title: tag.description
|
||||
end
|
||||
|
||||
def time_ago_in_words_label(time, options = {})
|
||||
ago = ""
|
||||
secs = (Time.current - time).to_i
|
||||
|
|
|
@ -15,6 +15,14 @@ class Story < ApplicationRecord
|
|||
:dependent => :destroy
|
||||
has_many :suggested_taggings, :dependent => :destroy
|
||||
has_many :suggested_titles, :dependent => :destroy
|
||||
has_many :suggested_tagging_times,
|
||||
-> { group(:tag_id).select("count(*) as times, tag_id").order('times desc') },
|
||||
:class_name => 'SuggestedTagging',
|
||||
:inverse_of => :story
|
||||
has_many :suggested_title_times,
|
||||
-> { group(:title).select("count(*) as times, title").order('times desc') },
|
||||
:class_name => 'SuggestedTitle',
|
||||
:inverse_of => :story
|
||||
has_many :comments,
|
||||
:inverse_of => :story,
|
||||
:dependent => :destroy
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
<tr>
|
||||
<td><%= check_box_tag "tags[]", tag.tag,
|
||||
@filtered_tags.include?(tag) %></td>
|
||||
<td><%= link_to tag.tag, tag_path(tag), :class => tag.css_class %></td>
|
||||
<td><%= tag_link(tag) %></td>
|
||||
<td><%= tag.description %>
|
||||
<% if tag.hotness_mod != 0 %>
|
||||
|
||||
|
|
|
@ -6,9 +6,7 @@
|
|||
<% if @tag %>
|
||||
<div class="box" id="leader">
|
||||
Stories <a href="/tags">tagged</a> as
|
||||
<a href="<%= tag_path(@tag) %>"
|
||||
class="<%= @tag.css_class %>"
|
||||
title="<%= @tag.description %>"><%= @tag.tag %></a>
|
||||
<%= tag_link(@tag) %>
|
||||
–
|
||||
<%= @tag.description %>
|
||||
</div>
|
||||
|
|
|
@ -25,22 +25,14 @@
|
|||
</p>
|
||||
</div>
|
||||
|
||||
<% if f.object.id && !defined?(suggesting) %>
|
||||
<% title_votes = {} %>
|
||||
<% f.object.suggested_titles.each do |st| %>
|
||||
<% title_votes[st.title] ||= 0 %>
|
||||
<% title_votes[st.title] += 1 %>
|
||||
<% end %>
|
||||
<% title_votes.delete(f.object.title) %>
|
||||
<% if title_votes.any? %>
|
||||
<div class="boxline actions">
|
||||
Users have suggested changing this story's title to:
|
||||
<br>
|
||||
<% title_votes.each do |ti,c| %>
|
||||
<%= h(ti) %><%= c == 1 ? "" : " (#{c} votes)" %><br>
|
||||
<% end %>
|
||||
</div>
|
||||
<% end %>
|
||||
<% if f.object.id && !defined?(suggesting) && f.object.suggested_title_times.any? %>
|
||||
<div class="boxline actions">
|
||||
Users have suggested setting this story's title to:
|
||||
<br>
|
||||
<% f.object.suggested_title_times.each do |st| %>
|
||||
<%= st.times %>: <%= st.title %><br>
|
||||
<% end %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<div class="boxline" style="margin-bottom: 2px;">
|
||||
|
@ -62,23 +54,14 @@
|
|||
f.object.tags_a), {}, { :multiple => true } %>
|
||||
</div>
|
||||
|
||||
<% if f.object.id && !defined?(suggesting) %>
|
||||
<% tag_votes = {} %>
|
||||
<% f.object.suggested_taggings.group_by(&:user_id).each do |u,stg| %>
|
||||
<% tl = stg.map{|st| st.tag.tag }.sort.join(", ") %>
|
||||
<% tag_votes[tl] ||= 0 %>
|
||||
<% tag_votes[tl] += 1 %>
|
||||
<% end %>
|
||||
<% tag_votes.delete(f.object.tags_a.sort.join(", ")) %>
|
||||
<% if tag_votes.any? %>
|
||||
<div class="boxline actions">
|
||||
Users have suggested changing this story's tags to:
|
||||
<br>
|
||||
<% tag_votes.each do |ts,c| %>
|
||||
<%= ts %><%= c == 1 ? "" : " (#{c} votes)" %><br>
|
||||
<% end %>
|
||||
</div>
|
||||
<% end %>
|
||||
<% if f.object.id && !defined?(suggesting) && f.object.suggested_tagging_times.any? %>
|
||||
<div class="boxline actions">
|
||||
Users have suggested setting this story's tags to:
|
||||
<br>
|
||||
<% f.object.suggested_tagging_times.includes(:tag).each do |st| %>
|
||||
<%= st.times %>: <%= tag_link(st.tag) %><br>
|
||||
<% end %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<% unless defined?(suggesting) %>
|
||||
|
|
|
@ -38,9 +38,7 @@ class="story <%= story.vote && story.vote[:vote] == 1 ? "upvoted" : "" %>
|
|||
<% if story.can_be_seen_by_user?(@user) %>
|
||||
<span class="tags">
|
||||
<% story.tags.each do |tag| %>
|
||||
<a href="<%= tag_path(tag) %>"
|
||||
class="<%= tag.css_class %>"
|
||||
title="<%= tag.description %>"><%= tag.tag %></a>
|
||||
<%= tag_link(tag) %>
|
||||
<% end %>
|
||||
</span>
|
||||
<% if story.domain.present? %>
|
||||
|
|
Loading…
Reference in New Issue