diff --git a/app/controllers/forums_controller.rb b/app/controllers/forums_controller.rb index 8bcc9f38..80726f22 100644 --- a/app/controllers/forums_controller.rb +++ b/app/controllers/forums_controller.rb @@ -4,6 +4,8 @@ class ForumsController < ApplicationController # GET /forums.json before_filter :authenticate_user_edit, :only => [:edit, :update] before_filter :authenticate_user_destroy, :only => [:destroy] + + PageLimit = 20 def index @offset, @limit = api_offset_and_limit({:limit => 10}) @@ -101,7 +103,43 @@ class ForumsController < ApplicationController format.json { head :no_content } end end -end + + def search_forum + # @forums = paginateHelper Forum.where("name LIKE '%#{params[:name]}%'") + @offset, @limit = api_offset_and_limit({:limit => 10}) + @forums_all = Forum.where("name LIKE '%#{params[:name]}%'") + @forums_count = @forums_all.count + @forums_pages = Paginator.new @forums_count, @limit, params['page'] + + + @offset ||= @forums_pages.offset + @forums = @forums_all.offset(@offset).limit(@limit).all + respond_to do |format| + format.html { + render 'index' + } + format.json { render json: @forums } + end + end + + def search_memo + limit = PageLimit + @memo = Memo.new + @offset, @limit = api_offset_and_limit({:limit => limit}) + @forum = Forum.find(params[:id]) + @memos_all = @forum.topics.where("subject LIKE '%#{params[:name]}%'") + @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 + respond_to do |format| + format.html { + render 'show', :layout => 'base_forums' + } + format.json { render json: @forum } + end + end private @@ -121,4 +159,5 @@ end def authenticate_user_destroy find_forum render_403 unless @forum.destroyable_by? User.current - end \ No newline at end of file + end +end \ No newline at end of file diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 24fb6ee8..42440c0c 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1331,6 +1331,8 @@ module ApplicationHelper # Add by Tao def url_to_avatar(source) + source = nil if source.kind_of?(String) + logger.error "======================================#{source.class}" get_avatar(source) end # Endof Tao's code diff --git a/app/helpers/welcome_helper.rb b/app/helpers/welcome_helper.rb index 3cd12ee6..35bc65c5 100644 --- a/app/helpers/welcome_helper.rb +++ b/app/helpers/welcome_helper.rb @@ -51,6 +51,11 @@ module WelcomeHelper nil end + def topic_last_time topic + return topic.event_datetime unless topic.methods.to_s =~ %r[last_reply] + topic.last_reply.event_datetime + end + def time_tag_welcome time text = distance_of_time_in_words(Time.now, time) @@ -99,7 +104,7 @@ module WelcomeHelper # or searchStudent(project).count end - + private def sort_project_by_hot diff --git a/app/models/memo.rb b/app/models/memo.rb index b6871c99..55282557 100644 --- a/app/models/memo.rb +++ b/app/models/memo.rb @@ -11,7 +11,7 @@ class Memo < ActiveRecord::Base acts_as_tree :counter_cache => :replies_count, :order => "#{Memo.table_name}.created_at ASC" acts_as_attachable - belongs_to :last_reply_id, :class_name => 'Memo', :foreign_key => 'last_reply_id' + belongs_to :last_reply, :class_name => 'Memo', :foreign_key => 'last_reply_id' # acts_as_searchable :column => ['subject', 'content'], # #:include => { :forum => :p} # #:project_key => "#{Forum.table_name}.project_id" diff --git a/app/views/forums/index.html.erb b/app/views/forums/index.html.erb index 97e8cc8a..f6546778 100644 --- a/app/views/forums/index.html.erb +++ b/app/views/forums/index.html.erb @@ -9,7 +9,14 @@ <%= link_to( l(:label_forum_new), new_forum_path, :class => 'icon icon-add') %> <% end %> -