From 0bc2b8f2b3e30c4f9af36ff2d223a290a555be21 Mon Sep 17 00:00:00 2001 From: yanxd Date: Wed, 11 Dec 2013 08:52:55 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E8=AE=BA=E5=9D=9B=E4=B8=A2?= =?UTF-8?q?=E5=A4=B1=E4=BA=86=E7=9A=84=E7=BC=96=E8=BE=91=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=20=E8=B4=B4=E5=90=A7=E7=9A=84=E7=BD=AE=E9=A1=B6=E9=94=81?= =?UTF-8?q?=E5=AE=9A=E5=8A=9F=E8=83=BD=EF=BC=8C=E7=9B=AE=E5=89=8D=E5=8F=AA?= =?UTF-8?q?=E9=92=88=E5=AF=B9=E7=AE=A1=E7=90=86=E5=91=98=E5=BC=80=E6=94=BE?= =?UTF-8?q?=20=E8=B4=B4=E5=90=A7=E5=88=97=E8=A1=A8=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E9=87=8D=E6=9E=84=20=E5=A2=9E=E5=8A=A01/2?= =?UTF-8?q?=E5=B8=96=E5=AD=90=E6=98=BE=E7=A4=BA=E6=95=B0=E7=9B=AE=20?= =?UTF-8?q?=E5=8F=96=E5=87=BA=E6=A5=BC=E4=B8=BB=EF=BC=8C=E9=98=B2=E6=AD=A2?= =?UTF-8?q?=E8=BE=93=E5=85=A5=E5=B8=96=E5=AD=90id=E8=AE=A9=E5=9B=9E?= =?UTF-8?q?=E5=A4=8D=E4=BD=9C=E4=B8=BA=E4=B8=BB=E8=B4=B4=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=20=E9=A6=96=E9=A1=B5=E5=8F=96=E6=96=B0=E5=B8=96=E5=AD=90=20?= =?UTF-8?q?=E5=B8=96=E5=AD=90=E4=B8=8B=E8=BD=BD=E5=86=85=E5=AE=B9=E9=9A=8F?= =?UTF-8?q?=E6=84=8F=E5=88=A0=E9=99=A4=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/forums_controller.rb | 46 +++++--- app/controllers/memos_controller.rb | 30 ++++-- app/models/memo.rb | 6 +- app/views/forums/_show_topics.html.erb | 2 +- app/views/memos/edit.html.erb | 13 ++- app/views/memos/show.html.erb | 72 +------------ app/views/messages/show.html.erb | 22 ++++ app/views/projects/_tools_expand.html.erb | 49 --------- config/locales/en.yml | 4 + config/locales/zh.yml | 4 + config/routes.rb | 6 +- public/images/zding.gif | Bin 0 -> 1273 bytes public/stylesheets/nyan.css | 124 ++++++++++++++++++++++ 13 files changed, 228 insertions(+), 150 deletions(-) create mode 100644 public/images/zding.gif diff --git a/app/controllers/forums_controller.rb b/app/controllers/forums_controller.rb index 80726f222..a47bbdafc 100644 --- a/app/controllers/forums_controller.rb +++ b/app/controllers/forums_controller.rb @@ -2,9 +2,13 @@ class ForumsController < ApplicationController # GET /forums # GET /forums.json + before_filter :find_forum_if_available before_filter :authenticate_user_edit, :only => [:edit, :update] before_filter :authenticate_user_destroy, :only => [:destroy] + helper :sort + include SortHelper + PageLimit = 20 def index @@ -26,15 +30,33 @@ class ForumsController < ApplicationController # GET /forums/1 # GET /forums/1.json def show - @memo = Memo.new - @offset, @limit = api_offset_and_limit({:limit => 10}) - @forum = Forum.find(params[:id]) - @memos_all = @forum.topics - @topic_count = @memos_all.count - @topic_pages = Paginator.new @topic_count, @limit, params['page'] + sort_init 'updated_at', 'desc' + sort_update 'created_at' => "#{Memo.table_name}.created_at", + 'replies' => "#{Memo.table_name}.replies_count", + 'updated_at' => "COALESCE (last_replies_memos.created_at, #{Memo.table_name}.created_at)" + + @memo = Memo.new(:forum => @forum) + @topic_count = @forum.topics.count + @topic_pages = Paginator.new @topic_count, per_page_option, params['page'] + @memos = @forum.topics. + reorder("#{Memo.table_name}.sticky DESC"). + includes(:last_reply). + limit(@topic_pages.per_page). + offset(@topic_pages.offset). + order(sort_clause). + preload(:author, {:last_reply => :author}). + all + + + + # @offset, @limit = api_offset_and_limit({:limit => 10}) + # @forum = Forum.find(params[:id]) + # @memos_all = @forum.topics + # @topic_count = @memos_all.count + # @topic_pages = Paginator.new @topic_count, @limit, params['page'] - @offset ||= @topic_pages.offset - @memos = @memos_all.offset(@offset).limit(@limit).all + # @offset ||= @topic_pages.offset + # @memos = @memos_all.offset(@offset).limit(@limit).all respond_to do |format| format.html { render :layout => 'base_forums' @@ -144,20 +166,20 @@ class ForumsController < ApplicationController private - def find_forum - @forum = Forum.find(params[:id]) + def find_forum_if_available + @forum = Forum.find(params[:id]) if params[:id] rescue ActiveRecord::RecordNotFound render_404 nil end def authenticate_user_edit - find_forum + find_forum_if_available render_403 unless @forum.editable_by? User.current end def authenticate_user_destroy - find_forum + find_forum_if_available render_403 unless @forum.destroyable_by? User.current end end \ No newline at end of file diff --git a/app/controllers/memos_controller.rb b/app/controllers/memos_controller.rb index f872582b3..bcf2a519b 100644 --- a/app/controllers/memos_controller.rb +++ b/app/controllers/memos_controller.rb @@ -52,15 +52,22 @@ class MemosController < ApplicationController end end + REPLIES_PER_PAGE = 20 unless const_defined?(:REPLIES_PER_PAGE) def show - pre_count = 20 - @current_count = pre_count * (params['page'].to_i - 1) if params['page'].to_i > 0 - @offset, @limit = api_offset_and_limit({:limit => pre_count}) - @replies_all = @memo.replies - @reply_count = @replies_all.count - @reply_pages = Paginator.new @reply_count, @limit, params['page'] - @offset ||= @reply_pages.offset - @replies = @replies_all.offset(@offset).limit(@limit).all + pre_count = REPLIES_PER_PAGE + + @memo = @memo.root # 取出楼主,防止输入帖子id让回复作为主贴显示 + + page = params[:page] + @reply_count = @memo.children.count + @reply_pages = Paginator.new @reply_count, pre_count, page + @replies = @memo.children. + includes(:author, :attachments). + reorder("#{Memo.table_name}.created_at ASC"). + limit(@reply_pages.per_page). + offset(@reply_pages.offset). + all + @mome_new = Memo.new @@ -76,12 +83,15 @@ class MemosController < ApplicationController end def edit + @replying = true end def update respond_to do |format| - if(@memo.update_attribute(:subject, params[:memo][:subject]) && - @memo.update_attribute(:content, params[:memo][:content])) + if( @memo.update_attribute(:subject, params[:memo][:subject]) && + @memo.update_attribute(:content, params[:memo][:content]) && + @memo.update_attribute(:sticky, params[:memo][:sticky]) && + @memo.update_attribute(:lock, params[:memo][:lock])) @memo.save_attachments(params[:attachments] || (params[:memo] && params[:memo][:uploads])) format.html {redirect_to back_memo_url, notice: "#{l :label_memo_create_succ}"} else diff --git a/app/models/memo.rb b/app/models/memo.rb index 55282557e..4ca5f888c 100644 --- a/app/models/memo.rb +++ b/app/models/memo.rb @@ -6,7 +6,7 @@ class Memo < ActiveRecord::Base validates_presence_of :author_id, :forum_id, :subject validates :content, presence: true validates_length_of :subject, maximum: 50 - validates_length_of :content, maximum: 2048 + validates_length_of :content, maximum: 3072 validate :cannot_reply_to_locked_topic, :on => :create acts_as_tree :counter_cache => :replies_count, :order => "#{Memo.table_name}.created_at ASC" @@ -50,7 +50,7 @@ class Memo < ActiveRecord::Base # } def cannot_reply_to_locked_topic - errors.add :base, 'Topic is locked' if root.locked? && self != root + errors.add :base, l(:label_memo_locked) if root.locked? && self != root end # def update_memos_forum @@ -69,7 +69,7 @@ class Memo < ActiveRecord::Base end def sticky=(arg) - write_attribute :sticky, (arg == true || arg.to_s == '1' ? 1 : 0) + write_attribute :sticky, (arg == true || arg.to_s == 'true' ? true : false) end def sticky? diff --git a/app/views/forums/_show_topics.html.erb b/app/views/forums/_show_topics.html.erb index cf90ca621..1aab4af80 100644 --- a/app/views/forums/_show_topics.html.erb +++ b/app/views/forums/_show_topics.html.erb @@ -9,7 +9,7 @@ - +
<%= link_to h(topic.subject), forum_memo_path(@forum, topic) %><%= link_to h(topic.subject), forum_memo_path(@forum, topic) %> diff --git a/app/views/memos/edit.html.erb b/app/views/memos/edit.html.erb index 14c29b636..cf8770c8c 100644 --- a/app/views/memos/edit.html.erb +++ b/app/views/memos/edit.html.erb @@ -1,4 +1,5 @@ +<% @replying ||= false %>

<%=l(:label_memo_edit)%>

<%= labelled_form_for(@memo, :url => forum_memo_path(@memo.forum_id, @memo)) do |f| %> <% if @memo.errors.any? %> @@ -12,7 +13,17 @@ <% end %>
-

<%= f.text_field :subject, :required => true %>

+

<%= f.text_field :subject, :required => true, :size => 96 %>

+

+ <% unless @replying %> + <% if @memo.safe_attribute? 'sticky' %> + <%= f.check_box :sticky %> <%= label_tag 'memo_sticky', l(:label_board_sticky) %> + <% end %> + <% if @memo.safe_attribute? 'lock' %> + <%= f.check_box :lock %> <%= label_tag 'memo_locked', l(:label_board_locked) %> + <% end %> + <% end %> +

<%= f.text_area :content, :required => true, :size => 80, id: 'editor01' %>


diff --git a/app/views/memos/show.html.erb b/app/views/memos/show.html.erb index 0f865b8f9..5bdde8b9c 100644 --- a/app/views/memos/show.html.erb +++ b/app/views/memos/show.html.erb @@ -1,71 +1,3 @@ - -
<%= link_to image_tag(url_to_avatar(@memo.author), :class => "avatar"), user_path(@memo.author) %>
@@ -95,7 +27,7 @@ ) if @memo.destroyable_by?(User.current) %>
-
<%= label_tag l(:field_subject) %>: <%=h @memo.subject %>
+
<%= label_tag l(:field_subject) %>: <%=h @memo.subject %>
<%= raw @memo.content %> @@ -149,7 +81,7 @@

<% if reply.attachments.any?%> - <% options = {:author => true, :deletable => true} %> + <% options = {:author => true, :deletable => false} %> <%= render :partial => 'attachments/links', :locals => {:attachments => reply.attachments, :options => options} %> <% end %>

diff --git a/app/views/messages/show.html.erb b/app/views/messages/show.html.erb index dba9b52e7..50feacb7a 100644 --- a/app/views/messages/show.html.erb +++ b/app/views/messages/show.html.erb @@ -90,6 +90,28 @@
+
+ <%= watcher_link(@topic, User.current) %> + <%= link_to( + l(:button_quote), + {:action => 'quote', :id => @topic}, + :remote => true, + :method => 'get', + :class => 'icon icon-comment', + :remote => true) if !@topic.locked? && authorize_for('messages', 'reply') %> + <%= link_to( + l(:button_edit), + {:action => 'edit', :id => @topic}, + :class => 'icon icon-edit' + ) if @message.editable_by?(User.current) %> + <%= link_to( + l(:button_delete), + {:action => 'destroy', :id => @topic}, + :method => :post, + :data => {:confirm => l(:text_are_you_sure)}, + :class => 'icon icon-del' + ) if @message.destroyable_by?(User.current) %> +
<%= link_to image_tag(url_to_avatar(@topic.author), :class => "avatar"), user_path(@topic.author) %>

<%=link_to @topic.author, user_path(@topic.author) %>

diff --git a/app/views/projects/_tools_expand.html.erb b/app/views/projects/_tools_expand.html.erb index b22c3ec23..e55452e74 100644 --- a/app/views/projects/_tools_expand.html.erb +++ b/app/views/projects/_tools_expand.html.erb @@ -1,52 +1,3 @@ -
<%= l(:label_project_tool)%>
diff --git a/config/locales/en.yml b/config/locales/en.yml index 119607aaa..2ec170f68 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -782,6 +782,9 @@ en: label_board_locked: Locked label_board_sticky: Sticky label_topic_plural: Topics + field_sticky: '' + field_locked: '' + field_lock: '' label_message_plural: Messages label_message_last: Last message label_message_new: New message @@ -1577,6 +1580,7 @@ en: label_forum: Forum label_tags_forum_description: Forum description label_tags_forum: Call forum + label_memo_locked: 'Topic is locked' diff --git a/config/locales/zh.yml b/config/locales/zh.yml index ee470d53f..36b69e6ea 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -792,6 +792,9 @@ zh: label_board_plural: 讨论区 label_board_locked: 锁定 label_board_sticky: 置顶 + field_sticky: '' + field_locked: '' + field_lock: '' label_topic_plural: 主题 label_message_plural: 帖子 label_message_last: 最新的帖子 @@ -1743,3 +1746,4 @@ zh: label_tags_forum_description: 贴吧描述 label_tags_forum: 贴吧名称 label_project_module_forums: 公共贴吧 + label_memo_locked: 帖子已被锁定 diff --git a/config/routes.rb b/config/routes.rb index 52ff0fc21..8d1156bff 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -18,12 +18,10 @@ RedmineApp::Application.routes.draw do resources :forums do collection do - get 'search_forum' - post 'search_forum' + match 'search_forum', :via => [:get, :post] end member do - get 'search_memo' - post 'search_memo' + match 'search_memo', :via => [:get, :post] end resources :memos do collection do diff --git a/public/images/zding.gif b/public/images/zding.gif new file mode 100644 index 0000000000000000000000000000000000000000..935adfc71766616697f1282fe27bc13d7a35b737 GIT binary patch literal 1273 zcmZ?wbhEHblxGlRSj57RFzZ9ipqNfZ~7d2;Tq&m&B4pAZ=q`QIMFN zom!%hl$xHIXRGvn_kJaX%oJOta8q9c-vZ~}1OnC3`ysn+mIn z+=ATHl0=1y+?>2(s|s7C#FYG`R4X7GB&@Hb09I0xZL8!6l28EI>6~Abs$i;Tpqp%9 zW}skZsAp(wVs37(qhMrUXrOOkq;F`XYiMp|Y-D9%pa2C*K--E^(yW49+@N*=dA3R! zB_#z``ugSN<$C4Ddih1^`i7R4mLM~XjC6r2bc-wVN)jt{^NN*WCb*;)Cl_TFlw{`T zDS%8&Ov*1Uu~h=P6yk;40$*Ra!Fk1cU=Qgf=jZBIBo^o!>KW+g=7RhMR$W{Yl!|Z$ zR@KEJl?AE#L8-<0rA5i9K;_CX&A_n3ZxKi#&^1>6MVY`zNz8G{PcF?(%`5SAu~h=f z=%r+)Sh<*(x)?h-8JRgdy0{t{8d|y-I$M}oT9{avTe_N>8NASOKF13B=l zlbQ$2FGawN!TA5*-#@>9{rvI$+t)9jKYjf0{@vR*uV1}<@%-7-CyyUJd~pBX-8;8$ z-Mn%A+SMzUFI~KF{@mF!r%#aDv3%LmC5sm=Trhv$+&Qyn&73iP+SDnNCrzBt-`CsI-PPIA-qzaE+|<}mUsqdG zT~%38URGLCTvS+)pO>4Hot2r9o|c-DoRpXl9~T=F9Tgc79u^uB926Mf@8|2|?d9p= z?&j*^?BwWRZ)a;`ZDna;Zf0s?Yy`}ddb&E=TACW_YN{&AN{R~da6|H%S!$V`Q!nu8-IY@^j% ovCWs|-~3WqrI(acxJ*TEqWYYjoU5wEM0Vd>(edLyHz$KN0A+#7ga7~l literal 0 HcmV?d00001 diff --git a/public/stylesheets/nyan.css b/public/stylesheets/nyan.css index 1297cfa5d..b6d655182 100644 --- a/public/stylesheets/nyan.css +++ b/public/stylesheets/nyan.css @@ -134,4 +134,128 @@ input[class='nyan-clean-gray']:active, .nyan-clean-gray:active { #share_label { line-height: 1.4em +} + + + .tools a:link{ + color: #116699; + text-decoration:none; + width:100px; + padding:3px 5px 0px 5px; +} +.tools a:visited{ + color: #116699; + text-decoration:none; + padding:3px 5px 0px 5px; + width:100px; +} +.tools a:hover{ + color:white; + padding:3px 3px 0px 20px; + width:88px; + text-decoration:none; + background-color:#539D26; +} +.tools a:active{ + color:white; + padding:3px 3px 0px 20px; + width:88px; + text-decoration:none; + background-color:#BD06B4; +} + +.tools ul{ + list-style-type: none; + margin: 0px 0px 0px 10% ; + padding: 0; +} +.tools li{ + background: url("/images/sidebar/tool_tag_alpha.png") 10px 30% no-repeat transparent; + color: #3e3e3e; + font-weight: 400; + line-height: 1.5em; + margin: 0px 0px 10px; + padding: 0px 0px 0px 30px; + font-size: 1.0em; + /*border-bottom: 1px solid #CCC;*/ +} +.tools li:last-child{ + border: none; +} + +/** { + -webkit-box-sizing: border-box; + -moz-box-sizing: border-box; + -box-sizing: border-box; +}*/ +.lz { + position:relative; + min-height: 200px; + margin: 10px 2px; + border-radius: 5px; + box-shadow: 1px 1px 6px #97EBF4; + border: 1px solid #F1F1F1; +} +.lz-left{ + float: left; + margin: 2%; + padding: 0; +} +.memo-section{ + width: auto; + margin-left: 15%; + padding-top: 1%; + border-left: 2px dotted #EEE; +} +.memo-title{ + margin: 1em 0; + padding-left: 1%; + padding-bottom: 1%; + font-weight: bold; + border-bottom: 1px dashed rgb(204, 204, 204); +} +.memo-content{ + padding: 1%; + margin: 1%; + margin-bottom: 40px; + background-color: #F8F8F8; + border-radius: 3px; +} +.memo-timestamp{ + position: absolute; + bottom: 0px; + right: 0; + margin: 20px; +} +.replies{ + overflow:hidden; + max-width: 100%; + float: right; + /*max-width: 90%;*/ +} +.reply-box{ + float: right; + width: 640px; + padding: 3%; + /*border: 2px solid #C6F3F9;*/ + border-top: 2px double #C6F3F9; + /*border-radius: 10px;*/ +} +.comments img { + overflow:hidden; + /*width: 100%;*/ + max-width: 500px; + height: auto !important; + width:expression(this.width > 500 ? "500px" : this.width+"px"); +} +table.content-text-list tbody tr td.sticky, div.memo-section .sticky{ + background: url(../images/zding.gif) no-repeat 0 1px; padding-left: 35px; + /*background: url(../images/2uparrow.png) no-repeat 0 1px; padding-left: 20px;*/ + font-weight: bold; + margin-left: 5px; +} +table.content-text-list tbody tr td.locked, div.memo-section .locked{ + background: url(../images/locked.png) no-repeat 0 1px; + padding-left: 20px; + margin-left: 5px; } \ No newline at end of file