work on forum
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
class ForumPostsController < ApplicationController
|
||||
respond_to :html, :xml, :json
|
||||
respond_to :html, :xml, :json, :js
|
||||
before_filter :member_only, :except => [:index, :show]
|
||||
rescue_from User::PrivilegeError, :with => "static/access_denied"
|
||||
|
||||
def new
|
||||
@forum_post = ForumPost.new(:topic_id => params[:topic_id])
|
||||
@forum_post = ForumPost.new_reply(params)
|
||||
respond_with(@forum_post)
|
||||
end
|
||||
|
||||
@@ -27,14 +27,14 @@ class ForumPostsController < ApplicationController
|
||||
|
||||
def create
|
||||
@forum_post = ForumPost.create(params[:forum_post])
|
||||
respond_with(@forum_post)
|
||||
respond_with(@forum_post, :location => forum_topic_path(@forum_post.topic, :page => @forum_post.topic.last_page))
|
||||
end
|
||||
|
||||
def update
|
||||
@forum_post = ForumPost.find(params[:id])
|
||||
check_privilege(@forum_post)
|
||||
@forum_post.update_attributes(params[:forum_post])
|
||||
respond_with(@forum_post)
|
||||
respond_with(@forum_post, :location => forum_topic_path(@forum_post.topic, :page => @forum_post.topic.last_page))
|
||||
end
|
||||
|
||||
def destroy
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
class ForumTopicsController < ApplicationController
|
||||
respond_to :html, :xml, :json
|
||||
before_filter :member_only, :except => [:index, :show]
|
||||
before_filter :normalize_search, :only => :index
|
||||
rescue_from User::PrivilegeError, :with => "static/access_denied"
|
||||
|
||||
def new
|
||||
@forum_topic = ForumTopic.new
|
||||
@forum_topic.original_post = ForumPost.new
|
||||
respond_with(@forum_topic)
|
||||
end
|
||||
|
||||
@@ -22,6 +24,7 @@ class ForumTopicsController < ApplicationController
|
||||
|
||||
def show
|
||||
@forum_topic = ForumTopic.find(params[:id])
|
||||
@forum_posts = ForumPost.search(:topic_id_eq => @forum_topic.id).paginate(:page => params[:page])
|
||||
respond_with(@forum_topic)
|
||||
end
|
||||
|
||||
@@ -33,6 +36,7 @@ class ForumTopicsController < ApplicationController
|
||||
def update
|
||||
@forum_topic = ForumTopic.find(params[:id])
|
||||
check_privilege(@forum_topic)
|
||||
assign_special_attributes(@forum_topic)
|
||||
@forum_topic.update_attributes(params[:forum_topic])
|
||||
respond_with(@forum_topic)
|
||||
end
|
||||
@@ -45,6 +49,25 @@ class ForumTopicsController < ApplicationController
|
||||
end
|
||||
|
||||
private
|
||||
def assign_special_attributes(forum_topic)
|
||||
return unless CurrentUser.is_moderator?
|
||||
|
||||
forum_topic.is_locked = params[:forum_topic][:is_locked]
|
||||
forum_topic.is_sticky = params[:forum_topic][:is_sticky]
|
||||
end
|
||||
|
||||
def normalize_search
|
||||
if params[:title_matches]
|
||||
params[:search] ||= {}
|
||||
params[:search][:title_matches] = params.delete(:title_matches)
|
||||
end
|
||||
|
||||
if params[:title]
|
||||
params[:search] ||= {}
|
||||
params[:search][:title_eq] = params.delete(:title)
|
||||
end
|
||||
end
|
||||
|
||||
def check_privilege(forum_topic)
|
||||
if !forum_topic.editable_by?(CurrentUser.user)
|
||||
raise User::PrivilegeError
|
||||
|
||||
@@ -8,6 +8,17 @@ class ForumPost < ActiveRecord::Base
|
||||
validates_presence_of :body, :creator_id
|
||||
scope :body_matches, lambda {|body| where(["text_index @@ plainto_tsquery(?)", body])}
|
||||
search_method :body_matches
|
||||
|
||||
def self.new_reply(params)
|
||||
if params[:topic_id]
|
||||
new(:topic_id => params[:topic_id])
|
||||
elsif params[:post_id]
|
||||
forum_post = ForumPost.find(params[:post_id])
|
||||
forum_post.build_response
|
||||
else
|
||||
new
|
||||
end
|
||||
end
|
||||
|
||||
def editable_by?(user)
|
||||
creator_id == user.id || user.is_moderator?
|
||||
@@ -25,4 +36,10 @@ class ForumPost < ActiveRecord::Base
|
||||
def initialize_updater
|
||||
self.updater_id = CurrentUser.id
|
||||
end
|
||||
|
||||
def build_response
|
||||
dup.tap do |x|
|
||||
x.body = "[quote]\n#{x.body}\n[/quote]\n\n"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -22,4 +22,12 @@ class ForumTopic < ActiveRecord::Base
|
||||
def initialize_updater
|
||||
self.updater_id = CurrentUser.id
|
||||
end
|
||||
|
||||
def last_page
|
||||
(posts.count / Danbooru.config.posts_per_page.to_f).ceil
|
||||
end
|
||||
|
||||
def presenter(forum_posts)
|
||||
@presenter ||= ForumTopicPresenter.new(self, forum_posts)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
class ForumTopicPresenter < Presenter
|
||||
attr_reader :forum_topic, :forum_posts
|
||||
|
||||
def initialize(forum_topic, forum_posts)
|
||||
@forum_posts = forum_posts
|
||||
@forum_topic = forum_topic
|
||||
end
|
||||
|
||||
def pagination_html(template)
|
||||
Paginators::ForumTopic.new(forum_topic, forum_posts).numbered_pagination_html(template)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,22 @@
|
||||
module Paginators
|
||||
class ForumPost < Base
|
||||
attr_accessor :forum_posts
|
||||
|
||||
def initialize(forum_posts)
|
||||
@forum_posts = forum_posts
|
||||
end
|
||||
|
||||
protected
|
||||
def total_pages
|
||||
forum_posts.total_entries
|
||||
end
|
||||
|
||||
def current_page
|
||||
forum_posts.current_page
|
||||
end
|
||||
|
||||
def paginated_link(template, page)
|
||||
template.link_to(page, template.forum_posts_path(:search => template.params[:search], :page => page))
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,23 @@
|
||||
module Paginators
|
||||
class ForumTopic < Base
|
||||
attr_accessor :forum_topic, :forum_posts
|
||||
|
||||
def initialize(forum_topic, forum_posts)
|
||||
@forum_topic = forum_topic
|
||||
@forum_posts = forum_posts
|
||||
end
|
||||
|
||||
protected
|
||||
def total_pages
|
||||
forum_posts.total_pages
|
||||
end
|
||||
|
||||
def current_page
|
||||
forum_posts.current_page
|
||||
end
|
||||
|
||||
def paginated_link(template, page)
|
||||
template.link_to(page, template.forum_topic_path(forum_topic, :page => page))
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1 @@
|
||||
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
|
||||
@@ -0,0 +1,23 @@
|
||||
<article data-forum-post-id="<%= forum_post.id %>">
|
||||
<div class="author">
|
||||
<h1><%= link_to forum_post.creator.name, user_path(forum_post.creator_id) %></h1>
|
||||
<p>
|
||||
<time datetime="<%= forum_post.created_at %>">
|
||||
<%= time_ago_in_words(forum_post.created_at) %> ago
|
||||
</time>
|
||||
</p>
|
||||
</div>
|
||||
<div class="content">
|
||||
<div>
|
||||
<%= format_text(forum_post.body) %>
|
||||
</div>
|
||||
<menu>
|
||||
<li><%= link_to "Reply", new_forum_post_path(:post_id => forum_post.id) %></li>
|
||||
<% if CurrentUser.user.is_janitor? || CurrentUser.user.id == forum_post.creator_id %>
|
||||
<li><%= link_to "Delete", forum_post_path(forum_post.id), :confirm => "Do you really want to delete this post?", :method => :delete, :remote => true %></li>
|
||||
<li><%= link_to "Edit", edit_forum_post_path(forum_post.id) %></li>
|
||||
<% end %>
|
||||
</menu>
|
||||
</div>
|
||||
<div class="clearfix"></div>
|
||||
</article>
|
||||
@@ -0,0 +1,6 @@
|
||||
<div class="list-of-forum-posts">
|
||||
<% forum_posts.each do |forum_post| %>
|
||||
<%= render :partial => "forum_posts/forum_post", :locals => {:forum_post => forum_post} %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
$("article[data-forum-post-id=<%= @forum_post.id %>]").remove();
|
||||
@@ -1,6 +1,10 @@
|
||||
<h1>Edit Post</h1>
|
||||
<div id="c-forum-topics">
|
||||
<div id="a-edit">
|
||||
<h1>Edit Forum Post</h1>
|
||||
|
||||
<%= simple_form_for(@forum_post) do |f| %>
|
||||
<%= f.input :body %>
|
||||
<%= f.button :submit %>
|
||||
<% end %>
|
||||
<%= simple_form_for(@forum_post) do |f| %>
|
||||
<%= f.input :body %>
|
||||
<%= f.button :submit, "Submit" %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
<h1>New Post</h1>
|
||||
<div id="c-forum-topics">
|
||||
<div id="a-new">
|
||||
<h1>New Forum Post</h1>
|
||||
|
||||
<%= simple_form_for(@forum_post) do |f| %>
|
||||
<%= f.input :topic_id, :as => :hidden %>
|
||||
<%= f.input :body %>
|
||||
<%= f.button :submit %>
|
||||
<% end %>
|
||||
<%= simple_form_for(@forum_post) do |f| %>
|
||||
<%= f.input :topic_id, :as => :hidden %>
|
||||
<%= f.input :body %>
|
||||
<%= f.button :submit, "Submit" %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
<div class="paginator">
|
||||
<%= @forum_topic.presenter(@forum_posts).pagination_html(self) %>
|
||||
</div>
|
||||
@@ -1,7 +1,6 @@
|
||||
<div>
|
||||
<%= simple_form_for @search do |f| %>
|
||||
<%= f.input :title_matches %>
|
||||
<%= f.input :creator_name_equals %>
|
||||
<%= f.button :submit %>
|
||||
<div id="search">
|
||||
<%= form_tag(forum_posts_path, :method => :get) do %>
|
||||
<%= text_field_tag "title_matches" %>
|
||||
<%= submit_tag "Search" %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
<% content_for(:secondary_links) do %>
|
||||
<menu>
|
||||
<li><%= link_to "Listing", forum_topics_path %></li>
|
||||
<li><%= link_to "New", new_forum_topic_path %></li>
|
||||
<li><%= link_to "Help", wiki_pages_path(:title => "help:forum") %></li>
|
||||
<% if @forum_topic %>
|
||||
<li>|</li>
|
||||
<li><%= link_to "Reply", new_forum_post_path(:topic_id => @forum_topic.id) %></li>
|
||||
<% unless @forum_topic.new_record? %>
|
||||
<li><%= link_to "Edit", edit_forum_topic_path(@forum_topic) %></li>
|
||||
<% if CurrentUser.is_moderator? %>
|
||||
<li><%= link_to "Delete", forum_topic_path(@forum_topic), :remote => true, :method => :delete, :confirm => "Do you want to delete this forum topic?" %></li>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</menu>
|
||||
<% end %>
|
||||
@@ -1,12 +1,19 @@
|
||||
<h1>Edit Topic</h1>
|
||||
<div id="c-forum-topics">
|
||||
<div id="a-edit">
|
||||
<h1>Edit Forum Topic</h1>
|
||||
|
||||
<%= simple_form_for(@forum_topic) do |f| %>
|
||||
<%= f.input :title %>
|
||||
<%= simple_form_for(@forum_topic) do |f| %>
|
||||
<%= f.input :title %>
|
||||
|
||||
<%= f.simple_fields_for :original_post do |pf| %>
|
||||
<%= text_field_tag "forum_topic[original_post_attributes][topic_id]", @forum_topic.id %>
|
||||
<%= pf.input :body %>
|
||||
<% end %>
|
||||
<%= f.simple_fields_for :original_post do |pf| %>
|
||||
<%= hidden_field_tag "forum_topic[original_post_attributes][topic_id]", @forum_topic.id %>
|
||||
<%= pf.input :body %>
|
||||
<% end %>
|
||||
|
||||
<%= f.button :submit %>
|
||||
<% end %>
|
||||
<%= f.input :is_sticky %>
|
||||
<%= f.input :is_locked %>
|
||||
|
||||
<%= f.button :submit, "Submit" %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
@@ -2,11 +2,11 @@
|
||||
|
||||
<%= render "search" %>
|
||||
|
||||
<table>
|
||||
<table width="100%">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Creator</th>
|
||||
<th>Title</th>
|
||||
<th>Creator</th>
|
||||
<th>Updated by</th>
|
||||
<th>Updated at</th>
|
||||
</tr>
|
||||
@@ -14,11 +14,13 @@
|
||||
<tbody>
|
||||
<% @forum_topics.each do |topic| %>
|
||||
<tr>
|
||||
<td><%= topic.creator.name %></td>
|
||||
<td><%= topic.title %></td>
|
||||
<td><%= topic.creator.name %></td>
|
||||
<td><%= topic.updater.name %></td>
|
||||
<td><%= compact_time topic.updated_at %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<%= render "secondary_links" %>
|
||||
@@ -1,11 +1,23 @@
|
||||
<h1>New Topic</h1>
|
||||
<div id="c-forum-topics">
|
||||
<div id="a-new">
|
||||
<h1>New Forum Topic</h1>
|
||||
|
||||
<%= simple_form_for(@forum_topic) do |f| %>
|
||||
<%= f.input :title %>
|
||||
|
||||
<%= f.simple_fields_for :original_post do |pf| %>
|
||||
<%= pf.input :body %>
|
||||
<% end %>
|
||||
|
||||
<%= f.button :submit %>
|
||||
<% end %>
|
||||
<div id="form-content">
|
||||
<%= simple_form_for(@forum_topic) do |f| %>
|
||||
<%= f.input :title %>
|
||||
|
||||
<%= f.simple_fields_for :original_post do |pf| %>
|
||||
<%= pf.input :body %>
|
||||
<% end %>
|
||||
|
||||
<%= f.button :submit, "Submit" %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<div id="dtext-help">
|
||||
<%= render "dtext/help" %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<%= render "secondary_links" %>
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
<div id="c-forum-topics">
|
||||
<div id="a-show">
|
||||
<h1 id="forum-topic-title">
|
||||
<%= @forum_topic.title %>
|
||||
<% if @forum_topic.is_locked? %>
|
||||
<span class="info">(locked)</span>
|
||||
<% end %>
|
||||
<% if @forum_topic.is_sticky? %>
|
||||
<span class="info">(sticky)</span>
|
||||
<% end %>
|
||||
</h1>
|
||||
|
||||
<%= render :partial => "forum_posts/listing", :locals => {:forum_posts => @forum_posts} %>
|
||||
<%= render "paginator" %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<%= render "secondary_links" %>
|
||||
@@ -2,7 +2,7 @@ module Danbooru
|
||||
class CustomConfiguration < Configuration
|
||||
# Define your custom overloads here
|
||||
def app_name
|
||||
"f"
|
||||
"Lorem"
|
||||
end
|
||||
|
||||
def posts_per_page
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -134,6 +134,9 @@ table.striped tbody tr:hover {
|
||||
table.striped tr.even {
|
||||
background-color: #EEE; }
|
||||
|
||||
div#search {
|
||||
margin-bottom: 1em; }
|
||||
|
||||
div#notice {
|
||||
margin: 1em;
|
||||
padding: 1em;
|
||||
@@ -259,11 +262,11 @@ div#c-pools div#a-edit ul.ui-sortable {
|
||||
/*** Comments ***/
|
||||
div.comments-for-post div.list-of-comments article {
|
||||
margin-bottom: 2em; }
|
||||
div.comments-for-post div.list-of-comments article span.comment-score {
|
||||
color: #CCC; }
|
||||
div.comments-for-post div.list-of-comments article div.author {
|
||||
width: 20%;
|
||||
float: left; }
|
||||
div.comments-for-post div.list-of-comments article div.author h1 {
|
||||
font-size: 1.5em; }
|
||||
div.comments-for-post div.list-of-comments article div.content {
|
||||
margin-left: 2em;
|
||||
width: 40em;
|
||||
@@ -436,3 +439,32 @@ div#c-uploads div#a-new div#upload-guide-notice {
|
||||
margin-bottom: 2em; }
|
||||
div#c-uploads div#a-new fieldset.ratings label {
|
||||
display: inline; }
|
||||
|
||||
/*** Forum ***/
|
||||
div.list-of-forum-posts article {
|
||||
margin-bottom: 3em; }
|
||||
div.list-of-forum-posts article div.author {
|
||||
width: 20%;
|
||||
float: left; }
|
||||
div.list-of-forum-posts article div.author h1 {
|
||||
font-size: 1.5em; }
|
||||
div.list-of-forum-posts article div.content {
|
||||
margin-left: 2em;
|
||||
width: 40em;
|
||||
float: left; }
|
||||
div.list-of-forum-posts article div.content menu {
|
||||
margin-top: 0.5em; }
|
||||
|
||||
div#c-forum-topics div#a-show h1#forum-topic-title {
|
||||
font-size: 2em; }
|
||||
div#c-forum-topics span.info {
|
||||
color: #AAA; }
|
||||
div#c-forum-topics textarea {
|
||||
width: 400px;
|
||||
height: 40em; }
|
||||
div#c-forum-topics div#form-content {
|
||||
float: left;
|
||||
width: 500px; }
|
||||
div#c-forum-topics div#dtext-help {
|
||||
float: left;
|
||||
width: 400px; }
|
||||
|
||||
@@ -179,6 +179,10 @@ table.striped {
|
||||
}
|
||||
}
|
||||
|
||||
div#search {
|
||||
margin-bottom: 1em;
|
||||
}
|
||||
|
||||
div#notice {
|
||||
margin: 1em;
|
||||
padding: 1em;
|
||||
@@ -394,13 +398,13 @@ div.comments-for-post {
|
||||
article {
|
||||
margin-bottom: 2em;
|
||||
|
||||
span.comment-score {
|
||||
color: #CCC;
|
||||
}
|
||||
|
||||
div.author {
|
||||
width: 20%;
|
||||
float: left;
|
||||
|
||||
h1 {
|
||||
font-size: 1.5em;
|
||||
}
|
||||
}
|
||||
|
||||
div.content {
|
||||
@@ -747,3 +751,58 @@ div#c-uploads {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*** Forum ***/
|
||||
div.list-of-forum-posts {
|
||||
article {
|
||||
margin-bottom: 3em;
|
||||
|
||||
div.author {
|
||||
width: 20%;
|
||||
float: left;
|
||||
|
||||
h1 {
|
||||
font-size: 1.5em;
|
||||
}
|
||||
}
|
||||
|
||||
div.content {
|
||||
margin-left: 2em;
|
||||
width: 40em;
|
||||
float: left;
|
||||
|
||||
menu {
|
||||
margin-top: 0.5em;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
div#c-forum-topics {
|
||||
div#a-show {
|
||||
h1#forum-topic-title {
|
||||
font-size: 2em;
|
||||
}
|
||||
}
|
||||
|
||||
span.info {
|
||||
color: #AAA;
|
||||
}
|
||||
|
||||
textarea {
|
||||
width: 400px;
|
||||
height: 40em;
|
||||
}
|
||||
|
||||
div#form-content {
|
||||
float: left;
|
||||
width: 500px;
|
||||
}
|
||||
|
||||
div#dtext-help {
|
||||
float: left;
|
||||
width: 400px;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user