diff --git a/app/controllers/open_source_projects_controller.rb b/app/controllers/open_source_projects_controller.rb index 4feca7b2..52b81610 100644 --- a/app/controllers/open_source_projects_controller.rb +++ b/app/controllers/open_source_projects_controller.rb @@ -57,7 +57,7 @@ class OpenSourceProjectsController < ApplicationController @memo = RelativeMemo.new(:open_source_project => @open_source_project) @topic_count = @open_source_project.topics.count - @topic_pages = Paginator.new @topic_count, per_page_option, params['page'] + @topic_pages = Paginator.new @topic_count, 10, params['page'] @memos = @open_source_project.topics. reorder("#{RelativeMemo.table_name}.sticky DESC"). includes(:last_reply). @@ -73,11 +73,40 @@ class OpenSourceProjectsController < ApplicationController format.json { render json: @open_source_project } end end - - def search + + +def search end + +# added by yiang 暴力添加,请绕道 +def showmemo + @open_source_project = OpenSourceProject.find(params[:id]) + + sort_init 'updated_at', 'desc' + sort_update 'created_at' => "#{RelativeMemo.table_name}.created_at", + 'replies' => "#{RelativeMemo.table_name}.replies_count", + 'updated_at' => "COALESCE (last_replies_relative_memos.created_at, #{RelativeMemo.table_name}.created_at)" + + @memo = RelativeMemo.new(:open_source_project => @open_source_project) + @topic_count = @open_source_project.topics.count + @topic_pages = Paginator.new @topic_count, per_page_option, params['page'] + @memos = @open_source_project.topics. + reorder("#{RelativeMemo.table_name}.sticky DESC"). + includes(:last_reply). + limit(@topic_pages.per_page). + offset(@topic_pages.offset). + order(sort_clause). + all + + respond_to do |format| + format.html { + render :layout => "base_opensource_p" + } + format.json { render json: @open_source_project } + end +end # GET /open_source_projects/new # GET /open_source_projects/new.json def new diff --git a/app/controllers/relative_memos_controller.rb b/app/controllers/relative_memos_controller.rb index f8741365..924efe9e 100644 --- a/app/controllers/relative_memos_controller.rb +++ b/app/controllers/relative_memos_controller.rb @@ -37,7 +37,7 @@ class RelativeMemosController < ApplicationController def show pre_count = REPLIES_PER_PAGE - @memo = @memo.root # 取出楼主,防止输入帖子id让回复作为主贴显示 + # @memo = @memo.root # 取出楼主,防止输入帖子id让回复作为主贴显示 @memo.update_column(:viewed_count_local, (@memo.viewed_count_local.to_i + 1)) page = params[:page] @@ -92,13 +92,14 @@ class RelativeMemosController < ApplicationController def create @memo = RelativeMemo.new(params[:relative_memo]) # @memo.url = "http://forge.trustie.net/open_source_projects" - @memo.osp_id = params[:open_source_project_id] + # @memo.osp_id = params[:open_source_project_id] @memo.author_id = User.current.id @memo.save_attachments(params[:attachments] || (params[:relative_memo] && params[:relative_memo][:uploads])) respond_to do |format| if @memo.save + RelativeMemoToOpenSourceProject.create(:osp_id => params[:open_source_project_id], :relative_memo_id => @memo.id) format.html { redirect_to back_memo_url, notice: "#{l :label_memo_create_succ}" } format.json { render json: @memo, status: :created, location: @memo } else @@ -142,7 +143,7 @@ class RelativeMemosController < ApplicationController def find_memo return unless find_osp - @memo = @open_source_project.relative_memos.find(params[:id]) + @memo = @open_source_project.topics.find(RelativeMemo.find(params[:id]).root.id) rescue ActiveRecord::RecordNotFound render_404 nil diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 0c451476..f6966e14 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -472,6 +472,14 @@ module ApplicationHelper def added_time(created) l(:label_added_time, :age => time_tag(created)).html_safe end + + def user_url_and_time(user_name, user_url, created) + unless user_name.nil? + l(:label_added_time_by, :author => link_to(user_name, user_url), :age => time_tag(created)).html_safe + else + l(:label_added_time, :age => time_tag(created)).html_safe + end + end #huang def betweentime(enddate) diff --git a/app/models/open_source_project.rb b/app/models/open_source_project.rb index e526dc92..6413a0d9 100644 --- a/app/models/open_source_project.rb +++ b/app/models/open_source_project.rb @@ -3,8 +3,10 @@ class OpenSourceProject < ActiveRecord::Base include Redmine::SafeAttributes has_many :applies, :class_name => "ApplyProjectMaster", :as => :apply, :dependent => :delete_all - has_many :topics, :class_name => 'RelativeMemo', :foreign_key => 'osp_id', :conditions => "#{RelativeMemo.table_name}.parent_id IS NULL", :order => "#{RelativeMemo.table_name}.created_at DESC", :dependent => :destroy - has_many :relative_memos, :class_name => 'RelativeMemo', :foreign_key => 'osp_id', :dependent => :destroy + has_many :relation_topics, :class_name => 'RelativeMemoToOpenSourceProject', :foreign_key => 'osp_id', :order => "#{RelativeMemo.table_name}.created_at DESC", :dependent => :destroy + # has_many :topics, :class_name => 'RelativeMemo', :foreign_key => 'osp_id', :conditions => "#{RelativeMemo.table_name}.parent_id IS NULL", :order => "#{RelativeMemo.table_name}.created_at DESC", :dependent => :destroy + has_many :topics, :through => :relation_topics, :class_name => 'RelativeMemo' + # has_many :relative_memos, :class_name => 'RelativeMemo', :foreign_key => 'osp_id', :dependent => :destroy has_many :tags, :through => :project_tags, :class_name => 'Tag' has_many :project_tags, :class_name => 'ProjectTags' has_many :masters, :class_name => 'ApplyProjectMaster', :as => :apply, :dependent => :delete_all, :conditions => "#{ApplyProjectMaster.table_name}.status = 2" @@ -126,9 +128,14 @@ class OpenSourceProject < ActiveRecord::Base def self.reset_counters!(id) osp_id = id.to_i - update_all("topic_count = (SELECT COUNT(*) FROM #{RelativeMemo.table_name} WHERE osp_id=#{osp_id} AND parent_id IS NULL)," + - " memo_count = (SELECT COUNT(*) FROM #{RelativeMemo.table_name} WHERE osp_id=#{osp_id} AND parent_id IS NOT NULL)," + - " last_memo_id = (SELECT MAX(id) FROM #{RelativeMemo.table_name} WHERE osp_id=#{osp_id})", + # update_all("topic_count = (SELECT COUNT(*) FROM #{RelativeMemo.table_name} WHERE osp_id=#{osp_id} AND parent_id IS NULL)," + + # " memo_count = (SELECT COUNT(*) FROM #{RelativeMemo.table_name} WHERE osp_id=#{osp_id} AND parent_id IS NOT NULL)," + + # " last_memo_id = (SELECT MAX(id) FROM #{RelativeMemo.table_name} WHERE osp_id=#{osp_id})", + # ["id = ?", osp_id]) + update_all("topic_count = (SELECT COUNT(*) FROM #{RelativeMemoToOpenSourceProject.table_name} WHERE osp_id=#{osp_id})", + # + + # " memo_count = (SELECT COUNT(*) FROM #{RelativeMemo.table_name} WHERE osp_id=#{osp_id} AND parent_id IS NOT NULL)," + + # " last_memo_id = (SELECT MAX(id) FROM #{RelativeMemo.table_name} WHERE osp_id=#{osp_id})", ["id = ?", osp_id]) end end diff --git a/app/models/relative_memo.rb b/app/models/relative_memo.rb index 24504241..11766bb0 100644 --- a/app/models/relative_memo.rb +++ b/app/models/relative_memo.rb @@ -7,12 +7,13 @@ class RelativeMemo < ActiveRecord::Base has_many :tags, :through => :project_tags, :class_name => 'Tag' has_many :project_tags, :class_name => 'ProjectTags' + has_many :relation_topics, :class_name => 'RelativeMemoToOpenSourceProject' + has_many :no_uses, :as => :no_use, :dependent => :delete_all acts_as_taggable - acts_as_attachable - validates_presence_of :osp_id, :subject + validates_presence_of :subject #validates :content, presence: true # validates_length_of :subject, maximum: 50 #validates_length_of :content, maximum: 3072 @@ -80,6 +81,11 @@ class RelativeMemo < ActiveRecord::Base { :include => :no_uses, :conditions => ["#{NoUse.table_name}.user_id = ?", user_id] } } + + # 获取帖子的回复 + def replies + memos = RelativeMemo.where("parent_id = ?", id) + end def no_use_for?(user) self.no_uses.each do |no_use| diff --git a/app/models/relative_memo_to_open_source_project.rb b/app/models/relative_memo_to_open_source_project.rb new file mode 100644 index 00000000..cb33de2d --- /dev/null +++ b/app/models/relative_memo_to_open_source_project.rb @@ -0,0 +1,14 @@ +class RelativeMemoToOpenSourceProject < ActiveRecord::Base + # attr_accessible :title, :body + belongs_to :open_source_project, :foreign_key => "osp_id" + belongs_to :topic, :class_name => 'RelativeMemo', :foreign_key => 'relative_memo_id' + + has_many :no_uses, :as => :no_use, :dependent => :delete_all + + validates_presence_of :osp_id, :relative_memo_id + + scope :no_use_for, lambda { |user_id| + {:include => :no_uses, + :conditions => ["#{NoUse.table_name}.user_id = ?", user_id] } + } +end diff --git a/app/views/open_source_projects/_show_memo.html.erb b/app/views/open_source_projects/_show_memo.html.erb new file mode 100644 index 00000000..8c1cbc81 --- /dev/null +++ b/app/views/open_source_projects/_show_memo.html.erb @@ -0,0 +1,77 @@ + + + +
<%= link_to image_tag(url_to_avatar(topic.author), :class => "avatar"), user_path(topic.author) if topic.author%> + <%= image_tag('../images/avatars/User/0', :class => "avatar") unless topic.author%> | +
+
|
+
+ <%= l(:label_no_data) %> +
+ <% end %> +<%= link_to h(topic.subject), open_source_project_relative_memo_path(topic.open_source_project, topic) %> | +<%= link_to h(topic.subject), open_source_project_relative_memo_path(open_source_project, topic) %> |
|
+
|
+
+
+
|