Permalink
Browse files

start on automated story title and tagging suggestions

Rather than keep "poorly titled" and "poorly tagged" as reasons for
flagging, make the user do the work of suggesting new ones.

At some point, suggested taggings will flip to real taggings once
they reach a certain count (to be determined later).  This also has
to take into account tagging sets that don't contain current tags,
for when they need to be removed.

For titles, I'm not yet sure how to handle this in an automated
fashion except for the (probably rare) case of multiple users
submitting the same exact thing, but at least collect them for now.

Issue #207
  • Loading branch information...
jcs committed Oct 15, 2015
1 parent 700c63b commit e940601a2f8bb21c6450130a2f09a22bd665475e
@@ -823,7 +823,7 @@ div#story_box #story_tags_a {
div#story_box textarea {
width: 600px;
}
div#story_box div.markdown_help_toggler {
div#story_box div.actions {
margin-left: 7em;
width: 610px;
}
@@ -222,7 +222,7 @@
div#story_box button,
div#story_box textarea,
div#story_box #story_tags_a,
div.markdown_help_toggler {
div.actions {
margin: 0 !important;
width: 100% !important;
}
@@ -1,12 +1,11 @@
class StoriesController < ApplicationController
before_filter :require_logged_in_user_or_400,
:only => [ :upvote, :downvote, :unvote, :hide, :unhide, :preview ]
before_filter :require_logged_in_user, :only => [ :destroy, :create, :edit,
:fetch_url_title, :new ]
:fetch_url_title, :new, :suggest ]
before_filter :find_user_story, :only => [ :destroy, :edit, :undelete,
:update ]
before_filter :find_story!, :only => [ :suggest, :submit_suggestions ]
def create
@title = "Submit Story"
@@ -169,6 +168,33 @@ def show
end
end
def suggest
if (st = @story.suggested_taggings.where(:user_id => @user.id)).any?
@story.tags_a = st.map{|st| st.tag.tag }
end
if tt = @story.suggested_titles.where(:user_id => @user.id).first
@story.title = tt.title
end
end
def submit_suggestions
ostory = @story.dup
@story.title = params[:story][:title]
if @story.valid?
if @story.title != ostory.title
@story.save_suggested_title_for_user!(@story.title, @user)
end
if @story.tags_a.sort != params[:story][:tags_a].sort
@story.save_suggested_tags_a_for_user!(params[:story][:tags_a], @user)
end
flash[:success] = "Your suggested changes have been noted."
redirect_to ostory.comments_path
else
render :action => "suggest"
end
end
def undelete
if !(@story.is_editable_by_user?(@user) &&
@story.is_undeletable_by_user?(@user))
@@ -291,6 +317,13 @@ def find_story
story
end
def find_story!
@story = find_story
if !@story
raise ActiveRecord::RecordNotFound
end
end
def find_user_story
if @user.is_moderator?
@story = Story.where(:short_id => params[:story_id] || params[:id]).first
View
@@ -8,6 +8,8 @@ class Story < ActiveRecord::Base
:foreign_key => "merged_story_id"
has_many :taggings,
:autosave => true
has_many :suggested_taggings
has_many :suggested_titles
has_many :comments,
:inverse_of => :story
has_many :tags, :through => :taggings
@@ -478,7 +480,8 @@ def tagging_changes
@_tags_a = []
def tags_a
@_tags_a ||= self.taggings.map{|t| t.tag.tag }
@_tags_a ||= self.taggings.reject{|t| t.marked_for_destruction?
}.map{|t| t.tag.tag }
end
def tags_a=(new_tag_names_a)
@@ -501,6 +504,47 @@ def tags_a=(new_tag_names_a)
end
end
def save_suggested_tags_a_for_user!(new_tag_names_a, user)
st = self.suggested_taggings.where(:user_id => user.id)
st.each do |tagging|
if !new_tag_names_a.include?(tagging.tag.tag)
tagging.destroy
end
end
st.reload
new_tag_names_a.each do |tag_name|
# XXX: AR bug? st.exists?(:tag => tag_name) does not work
if tag_name.to_s != "" && !st.map{|x| x.tag.tag }.include?(tag_name)
if (t = Tag.active.where(:tag => tag_name).first) &&
t.valid_for?(user)
tg = self.suggested_taggings.build
tg.user_id = user.id
tg.tag_id = t.id
tg.save!
st.reload
else
next
end
end
end
# TODO: promote suggested tags to real one when count reaches something
end
def save_suggested_title_for_user!(title, user)
st = self.suggested_titles.where(:user_id => user.id).first
if !st
st = self.suggested_titles.build
st.user_id = user.id
end
st.title = title
st.save!
end
def title=(t)
# change unicode whitespace characters into real spaces
self[:title] = t.strip
@@ -0,0 +1,5 @@
class SuggestedTagging < ActiveRecord::Base
belongs_to :tag
belongs_to :story
belongs_to :user
end
@@ -0,0 +1,4 @@
class SuggestedTitle < ActiveRecord::Base
belongs_to :story
belongs_to :user
end
View
@@ -15,8 +15,6 @@ class Vote < ActiveRecord::Base
STORY_REASONS = {
"O" => "Off-topic",
"A" => "Already Posted",
"T" => "Poorly Tagged",
"L" => "Poorly Titled",
"S" => "Spam",
"" => "Cancel",
}
@@ -25,19 +25,21 @@
<% end %>
<div class="box">
<div class="boxline">
<% if f.object.url_is_editable_by_user?(@user) %>
<%= f.label :url, "URL:", :class => "required" %>
<%= f.text_field :url, :autocomplete => "off" %>
<%= button_tag "Fetch Title", :id => "story_fetch_title",
:type => "button" %>
<% elsif !f.object.new_record? && !f.object.url.blank? %>
<%= f.label :url, "URL:", :class => "required" %>
<div class="d">
<a href="<%= f.object.url %>"><%= f.object.url %></a>
<% unless defined?(suggesting) %>
<div class="boxline">
<% if f.object.url_is_editable_by_user?(@user) %>
<%= f.label :url, "URL:", :class => "required" %>
<%= f.text_field :url, :autocomplete => "off" %>
<%= button_tag "Fetch Title", :id => "story_fetch_title",
:type => "button" %>
<% elsif !f.object.new_record? && !f.object.url.blank? %>
<%= f.label :url, "URL:", :class => "required" %>
<div class="d">
<a href="<%= f.object.url %>"><%= f.object.url %></a>
</div>
<% end %>
</div>
<% end %>
</div>
<div class="boxline">
<%= f.label :title, "Title:", :class => "required" %>
@@ -63,80 +65,84 @@
f.object.tags_a), {}, { :multiple => true } %>
</div>
<div class="boxline">
<%= f.label :description, "Text:", :class => "required" %>
<%= f.text_area :description, :rows => 15,
:placeholder => "Optional when submitting a URL; please see guidelines",
:autocomplete => "off" %>
</div>
<% unless defined?(suggesting) %>
<div class="boxline">
<%= f.label :description, "Text:", :class => "required" %>
<%= f.text_area :description, :rows => 15,
:placeholder => "Optional when submitting a URL; please see guidelines",
:autocomplete => "off" %>
</div>
<div class="boxline markdown_help_toggler">
<a href="#" id="story_guidelines_toggler">
Story submission guidelines
</a>
<div id="story_guidelines" style="<%= show_guidelines?? "" :
"display: none;" %>">
<div style="float: right;">
<a href="javascript:window.location=%22<%= Rails.application.root_url %>stories/new?url=%22+encodeURIComponent(document.location)+%22&title=%22+encodeURIComponent(document.title)"
style="border: 1px solid #ddd; padding: 0.5em; background-color:
#f8f8f8; line-height: 1.5em; margin-left: 1em;">Submit to
<%= Rails.application.name %></a>
</div>
<ul>
<div class="boxline actions markdown_help_toggler">
<a href="#" id="story_guidelines_toggler">
Story submission guidelines
</a>
<div id="story_guidelines" style="<%= show_guidelines?? "" :
"display: none;" %>">
<div style="float: right;">
<a href="javascript:window.location=%22<%= Rails.application.root_url %>stories/new?url=%22+encodeURIComponent(document.location)+%22&title=%22+encodeURIComponent(document.title)"
style="border: 1px solid #ddd; padding: 0.5em; background-color:
#f8f8f8; line-height: 1.5em; margin-left: 1em;">Submit to
<%= Rails.application.name %></a>
</div>
<ul>
<li><p>
To be able to easily submit a page you're viewing in your browser
to <%= Rails.application.name %>, drag the bookmarklet to the right
to your bookmark bar. You'll be taken to this page with the viewed
page's URL and title.
</p></li>
<li><p>
To be able to easily submit a page you're viewing in your browser
to <%= Rails.application.name %>, drag the bookmarklet to the right
to your bookmark bar. You'll be taken to this page with the viewed
page's URL and title.
</p></li>
<li><p>
When submitting a URL, the text field is optional and should only
be used when additional context or explanation of the URL is
needed. Commentary or opinion should be reserved for a comment,
so that it can be voted on separately from the story.
</p></li>
<li><p>
When submitting a URL, the text field is optional and should only
be used when additional context or explanation of the URL is
needed. Commentary or opinion should be reserved for a comment,
so that it can be voted on separately from the story.
</p></li>
<li><p>
Do not editorialize story titles, but when the original story's
title has no context or is unclear, please change it. <strong>Please
remove extraneous components from titles such as the name of the
site or section.</strong>
</p></li>
<li><p>
Do not editorialize story titles, but when the original story's
title has no context or is unclear, please change it. <strong>Please
remove extraneous components from titles such as the name of the
site or section.</strong>
</p></li>
<li><p>
If no tags clearly apply to the story you are submitting, chances
are it does not belong here. Do not overreach with tags if they
are not the primary focus of the story.
</p></li>
<li><p>
If no tags clearly apply to the story you are submitting, chances
are it does not belong here. Do not overreach with tags if they
are not the primary focus of the story.
</p></li>
<li><p>
When the story being submitted is more than a year or so old,
please add the year the story was written to the post title in
parentheses.
</p></li>
<li><p>
When the story being submitted is more than a year or so old,
please add the year the story was written to the post title in
parentheses.
</p></li>
</ul>
</ul>
</div>
</div>
</div>
<% end %>
</div>
<div class="box">
<div class="boxline">
<%= f.label :user_is_author, "Author:", :class => "required" %>
<%= f.check_box :user_is_author %>
<%= f.label :user_is_author,
(f.object.id && f.object.user_id != @user.id ? "Submitter is" : "I am") +
" the author of the story at this URL (or this text)",
:class => "normal" %>
<% unless defined?(suggesting) %>
<div class="box">
<div class="boxline">
<%= f.label :user_is_author, "Author:", :class => "required" %>
<%= f.check_box :user_is_author %>
<%= f.label :user_is_author,
(f.object.id && f.object.user_id != @user.id ? "Submitter is" : "I am") +
" the author of the story at this URL (or this text)",
:class => "normal" %>
</div>
</div>
</div>
<script>
$(document).ready(function() {
$("#story_fetch_title").click(function() {
Lobsters.fetchURLTitle($(this), $("#story_url"), $("#story_title"));
return false;
<script>
$(document).ready(function() {
$("#story_fetch_title").click(function() {
Lobsters.fetchURLTitle($(this), $("#story_url"), $("#story_title"));
return false;
});
});
});
</script>
</script>
<% end %>
@@ -127,6 +127,9 @@ class="story <%= story.vote && story.vote[:vote] == 1 ? "upvoted" : "" %>
:confirm => "Are you sure you want to delete this story?" } %>
<% end %>
<% end %>
<% elsif @user %>
| <%= link_to "suggest", story_suggest_path(story.short_id),
:class => "suggester" %>
<% end %>
<% if !story.is_gone? && @user %>
<% if @user && story.vote && story.vote[:vote] == -1 %>
@@ -38,7 +38,7 @@
<p></p>
<div class="box">
<div class="boxline markdown_help_toggler">
<div class="boxline actions markdown_help_toggler">
<div class="markdown_help_label">
Markdown formatting available
</div>
@@ -11,7 +11,7 @@
<p></p>
<div class="box">
<div class="boxline markdown_help_toggler">
<div class="boxline actions markdown_help_toggler">
<div class="markdown_help_label">
Markdown formatting available
</div>
Oops, something went wrong.

0 comments on commit e940601

Please sign in to comment.