add "i am the author of this" checkbox for stories
Highlights username in a different color and says "authored by" instead of just "by". Move html class printing into a method in Story to use in the future for friends, admin posts, etc. Closes #171
This commit is contained in:
parent
befee851c8
commit
0d61e0cf68
|
@ -585,6 +585,10 @@ li .byline a.inactive_user {
|
|||
color: gray;
|
||||
text-decoration: line-through;
|
||||
}
|
||||
span.user_is_author, a.user_is_author,
|
||||
li .byline a.user_is_author{
|
||||
color: blue;
|
||||
}
|
||||
|
||||
li.story.hidden {
|
||||
opacity: 0.25;
|
||||
|
|
|
@ -271,7 +271,7 @@ private
|
|||
def story_params
|
||||
p = params.require(:story).permit(
|
||||
:title, :url, :description, :moderation_reason, :seen_previous,
|
||||
:merge_story_short_id, :is_unavailable, :tags_a => [],
|
||||
:merge_story_short_id, :is_unavailable, :user_is_author, :tags_a => [],
|
||||
)
|
||||
|
||||
if @user.is_moderator?
|
||||
|
|
|
@ -63,6 +63,10 @@ class Story < ActiveRecord::Base
|
|||
errors.add(:description, "must contain text if no URL posted")
|
||||
end
|
||||
|
||||
if !errors.any? && self.url.blank?
|
||||
self.user_is_author = true
|
||||
end
|
||||
|
||||
check_tags
|
||||
end
|
||||
|
||||
|
@ -258,6 +262,19 @@ class Story < ActiveRecord::Base
|
|||
@hider_count ||= HiddenStory.where(:story_id => self.id).count
|
||||
end
|
||||
|
||||
def html_class_for_user(u = nil)
|
||||
c = []
|
||||
if !self.user.is_active?
|
||||
c.push "inactive_user"
|
||||
elsif self.user.is_new?
|
||||
c.push "new_user"
|
||||
elsif self.user_is_author?
|
||||
c.push "user_is_author"
|
||||
end
|
||||
|
||||
c.join("")
|
||||
end
|
||||
|
||||
def is_downvotable?
|
||||
return true
|
||||
if self.created_at
|
||||
|
|
|
@ -121,6 +121,16 @@
|
|||
</div>
|
||||
</div>
|
||||
</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" %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
|
|
|
@ -59,6 +59,9 @@ class="story <%= story.vote && story.vote[:vote] == 1 ? "upvoted" : "" %>
|
|||
break_long_words(ms.domain) %></a>
|
||||
<% end %>
|
||||
<span class="byline">
|
||||
<% if story.user_is_author? %>
|
||||
authored
|
||||
<% end %>
|
||||
by
|
||||
<a href="/u/<%= ms.user.username %>"
|
||||
<% if ms.user.is_new? %>
|
||||
|
@ -76,19 +79,21 @@ class="story <%= story.vote && story.vote[:vote] == 1 ? "upvoted" : "" %>
|
|||
<% end %>
|
||||
<% end %>
|
||||
<div class="byline">
|
||||
<% if story.user_is_author? %>
|
||||
authored
|
||||
<% end %>
|
||||
<% if story.previewing %>
|
||||
by
|
||||
<a><%= story.user.username %></a>
|
||||
<a class="<%= story.html_class_for_user(@user) %>"><%=
|
||||
story.user.username %></a>
|
||||
<% if @user && @user.show_avatars? %>
|
||||
<img src="<%= story.user.avatar_url(16) %>" class="avatar">
|
||||
<% end %>
|
||||
just now
|
||||
<% else %>
|
||||
by
|
||||
<a href="/u/<%= story.user.username %>"
|
||||
<% if story.user.is_new? %>
|
||||
class="new_user"
|
||||
<% end %>><%= story.user.username %></a>
|
||||
<a href="/u/<%= story.user.username %>" class="<%=
|
||||
story.html_class_for_user(@user) %>"><%= story.user.username %></a>
|
||||
|
||||
<% if @user && @user.show_avatars? %>
|
||||
<img src="<%= story.user.avatar_url(16) %>" class="avatar">
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
:f => f } %>
|
||||
|
||||
<% if @user.is_moderator? %>
|
||||
<br />
|
||||
<div class="box">
|
||||
<div class="boxline">
|
||||
<%= f.label :merge_story_short_id, "Merge Into:",
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
class AddSubmitterIsAuthor < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :stories, :user_is_author, :boolean, :default => false
|
||||
end
|
||||
end
|
19
db/schema.rb
19
db/schema.rb
|
@ -11,7 +11,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20150313040930) do
|
||||
ActiveRecord::Schema.define(version: 20150730215915) do
|
||||
|
||||
create_table "comments", force: true do |t|
|
||||
t.datetime "created_at", null: false
|
||||
|
@ -109,20 +109,21 @@ ActiveRecord::Schema.define(version: 20150313040930) do
|
|||
t.datetime "created_at"
|
||||
t.integer "user_id"
|
||||
t.string "url", limit: 250, default: ""
|
||||
t.string "title", limit: 150, default: "", null: false
|
||||
t.string "title", limit: 150, default: "", null: false
|
||||
t.text "description", limit: 16777215
|
||||
t.string "short_id", limit: 6, default: "", null: false
|
||||
t.integer "is_expired", limit: 1, default: 0, null: false
|
||||
t.integer "upvotes", default: 0, null: false
|
||||
t.integer "downvotes", default: 0, null: false
|
||||
t.integer "is_moderated", limit: 1, default: 0, null: false
|
||||
t.decimal "hotness", precision: 20, scale: 10, default: 0.0, null: false
|
||||
t.string "short_id", limit: 6, default: "", null: false
|
||||
t.integer "is_expired", limit: 1, default: 0, null: false
|
||||
t.integer "upvotes", default: 0, null: false
|
||||
t.integer "downvotes", default: 0, null: false
|
||||
t.integer "is_moderated", limit: 1, default: 0, null: false
|
||||
t.decimal "hotness", precision: 20, scale: 10, default: 0.0, null: false
|
||||
t.text "markeddown_description", limit: 16777215
|
||||
t.text "story_cache", limit: 16777215
|
||||
t.integer "comments_count", default: 0, null: false
|
||||
t.integer "comments_count", default: 0, null: false
|
||||
t.integer "merged_story_id"
|
||||
t.datetime "unavailable_at"
|
||||
t.string "twitter_id", limit: 20
|
||||
t.boolean "user_is_author", default: false
|
||||
end
|
||||
|
||||
add_index "stories", ["hotness"], name: "hotness_idx", using: :btree
|
||||
|
|
Loading…
Reference in New Issue