diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index c00f223c9..6d3574309 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -19,8 +19,8 @@ class WelcomeController < ApplicationController caches_action :robots def index - @news = News.latest User.current - @projects = Project.latest User.current + # @news = News.latest User.current + # @projects = Project.latest User.current #by young (redirect_to(home_url); return) unless Setting.self_registration? || session[:auth_source_registration] if request.get? @@ -60,10 +60,10 @@ class WelcomeController < ApplicationController end #add by huang - @memberships = @user.memberships.all(:conditions => Project.visible_condition(User.current)) + # @memberships = @user.memberships.all(:conditions => Project.visible_condition(User.current)) - events = Redmine::Activity::Fetcher.new(User.current, :author => @user).events(nil, nil, :limit => 20) - @events_by_day = events.group_by(&:event_date) + # events = Redmine::Activity::Fetcher.new(User.current, :author => @user).events(nil, nil, :limit => 20) + # @events_by_day = events.group_by(&:event_date) # end diff --git a/app/helpers/welcome_helper.rb b/app/helpers/welcome_helper.rb index 0856a26ac..ea34c8aad 100644 --- a/app/helpers/welcome_helper.rb +++ b/app/helpers/welcome_helper.rb @@ -19,18 +19,18 @@ module WelcomeHelper - def newbieTopiclist - find_all_topic_by_board_id - end + # def newbieTopiclist + # find_all_topic_by_board_id + # end - def newbieTopicStickyList - find_all_topic_by_board_id 1 - end + # def newbieTopicStickyList + # find_all_topic_by_board_id 1 + # end - def find_project_by_topic topic - board = find_board_by_topic(topic) - find_project_by_board board - end + # def find_project_by_topic topic + # board = find_board_by_topic(topic) + # find_project_by_board board + # end def find_all_hot_project sort_project_by_hot @@ -47,78 +47,95 @@ module WelcomeHelper def find_all_hot_contest sort_contest_by_hot end + + def find_all_event_type event + case event.event_type + when 'news' + '新闻' + when 'issue' + '缺陷' + when 'attachment' + '附件' + when 'message' + '主题' + when 'reply' + '回复' + when 'bid' + '众包' + else + event.event_type + end + end + + def time_tag_welcome(time) + text = distance_of_time_in_words(Time.now, time) + content_tag('span', text, :title => format_time(time)) + end private - def search_project - Project.find_by_identifier "newbie_faq" - end + # def search_project + # Project.find_by_identifier "newbie_faq" + # end - def find_all_topic_by_board_id sticky = 0, limit = 30 - project = search_project - return [] if(project.nil? or project.boards.nil?) - board_id = project.boards.first.id - logger.debug "[WelcomeHelper] ===> find_all_topic_by_board_id=> project.id:#{project.id}, board_id:#{board_id}, sticky:#{sticky}" - Message.where("board_id = :board_id and sticky=:sticky", :board_id => board_id, :sticky => sticky ).limit(limit) - end + # def find_all_topic_by_board_id sticky = 0, limit = 30 + # project = search_project + # return [] if(project.nil? or project.boards.nil?) + # board_id = project.boards.first.id + # logger.debug "[WelcomeHelper] ===> find_all_topic_by_board_id=> project.id:#{project.id}, board_id:#{board_id}, sticky:#{sticky}" + # Message.where("board_id = :board_id and sticky=:sticky", :board_id => board_id, :sticky => sticky ).limit(limit) + # end - def find_board_by_topic topic - Board.find_by_id(topic.board_id) - end - def find_project_by_board board - Project.find_by_id(board.project_id) - end + # def find_board_by_topic topic + # Board.find_by_id(topic.board_id) + # end + # def find_project_by_board board + # Project.find_by_id(board.project_id) + # end def sort_project_by_hot - return sort_project_by_hot_rails 0 + sort_project_by_hot_rails 0, 'grade DESC' end def sort_course_by_hot - return sort_project_by_hot_rails 1 + sort_project_by_hot_rails 1, 'course_ac_para DESC' end def sort_bid_by_hot - return sort_bid_by_hot_rails 1 + sort_bid_by_hot_rails 1 end def sort_contest_by_hot - return sort_bid_by_hot_rails 2 + sort_bid_by_hot_rails 2 end #取得所有活动 - def find_all_activities limit=10 - users = [] - activities = Activity.find_by_sql("select distinct user_id from activities order by id DESC limit #{limit}" ) - activities.each { |activity| - users << activity.user_id - } - user_objs = User.find_by_sql("SELECT * FROM users WHERE (users.id IN #{"(" << users.join(',') << ")"} )") - activity = Redmine::Activity::Fetcher.new(user_objs) + def find_all_activities limit=5 + # users = [] + # activities = Activity.find_by_sql("select distinct user_id from activities order by id DESC limit #{limit}" ) + # activities.each { |activity| + # users << activity.user_id + # } + # user_objs = User.find_by_sql("SELECT * FROM users WHERE (users.id IN #{"(" << users.join(',') << ")"} )") + activity = Redmine::Activity::Fetcher.new(nil) activity.events_welcome(nil, nil, {:limit => limit}) end #取得论坛数据 def find_hot_forum_topics limit=10 - Memo.order('replies_count DESC').where('replies_count <> 0').limit(limit) + Memo.order('replies_count DESC').where('replies_count <> 0').limit(limit) end - def sort_project_by_hot_rails project_type - limit = 10 - project_type == 0 ? Project.find_by_sql(" + def sort_project_by_hot_rails project_type=0, order_by='grade DESC', limit=15 + Project.find_by_sql(" SELECT p.id, p.name, p.description, p.identifier, t.project_id FROM projects AS p RIGHT OUTER JOIN ( SELECT project_id,grade FROM project_statuses - WHERE project_type = #{project_type} ORDER BY grade DESC LIMIT #{limit} ) AS t ON p.id = t.project_id ") - : Project.find_by_sql(" - SELECT p.id, p.name, p.description, p.identifier, t.project_id - FROM projects AS p RIGHT OUTER JOIN ( - SELECT project_id,grade FROM project_statuses - WHERE project_type = #{project_type} ORDER BY course_ac_para DESC LIMIT #{limit} ) AS t ON p.id = t.project_id ") + WHERE project_type = #{project_type} ORDER BY #{order_by} LIMIT #{limit} ) AS t ON p.id = t.project_id ") end - def sort_bid_by_hot_rails reward_type - limit = 10 - Bid.visible.where('reward_type = ?', reward_type).reorder('bids.commit desc').limit(limit).all + def sort_bid_by_hot_rails reward_type, limit = 10 + Bid.visible.where('reward_type = ?', reward_type).reorder('bids.commit desc').limit(limit) end end diff --git a/app/models/forum.rb b/app/models/forum.rb index 993c00b23..277b55dce 100644 --- a/app/models/forum.rb +++ b/app/models/forum.rb @@ -4,11 +4,11 @@ class Forum < ActiveRecord::Base has_many :memos, :dependent => :destroy belongs_to :creator, :class_name => "User", :foreign_key => 'creator_id' safe_attributes 'name', - 'description', - 'topic_count', - 'memo_count', - 'last_memo_id', - 'creator_id' + 'description', + 'topic_count', + 'memo_count', + 'last_memo_id', + 'creator_id' validates_presence_of :name, :creator_id validates_length_of :name, maximum: 50 validates_length_of :description, maximum: 255 @@ -16,5 +16,17 @@ class Forum < ActiveRecord::Base acts_as_taggable scope :by_join_date, order("created_at DESC") - + + def reset_counters! + self.class.reset_counters!(id) + end + + # Updates topic_count, memo_count and last_memo_id attributes for +board_id+ + def self.reset_counters!(forum_id) + forum_id = forum_id.to_i + update_all("topic_count = (SELECT COUNT(*) FROM #{Memo.table_name} WHERE forum_id=#{forum_id} AND parent_id IS NULL)," + + " memo_count = (SELECT COUNT(*) FROM #{Memo.table_name} WHERE forum_id=#{forum_id} AND parent_id IS NOT NULL)," + + " last_memo_id = (SELECT MAX(id) FROM #{Memo.table_name} WHERE forum_id=#{forum_id})", + ["id = ?", forum_id]) + end end diff --git a/app/models/memo.rb b/app/models/memo.rb index 9a87009ec..b494064be 100644 --- a/app/models/memo.rb +++ b/app/models/memo.rb @@ -1,6 +1,6 @@ class Memo < ActiveRecord::Base include Redmine::SafeAttributes - belongs_to :forums + belongs_to :forum belongs_to :author, :class_name => "User", :foreign_key => 'author_id' validates_presence_of :author_id, :forum_id, :subject @@ -13,10 +13,10 @@ class Memo < ActiveRecord::Base acts_as_attachable belongs_to :last_reply_id, :class_name => 'Memo', :foreign_key => 'last_reply_id' # acts_as_searchable :column => ['subject', 'content'], - # #:include => { :forums => :p} + # #:include => { :forum => :p} # #:project_key => "#{Forum.table_name}.project_id" # :date_column => "#{table_name}.created_at" - # acts_as_event :title => Proc.new {|o| "#{o.forums.name}: #{o.subject}"}, + # acts_as_event :title => Proc.new {|o| "#{o.forum.name}: #{o.subject}"}, # :description => :content, # :group => :parent, # :type => Proc.new {|o| o.parent_id.nil? ? 'message' : 'reply'}, @@ -29,7 +29,7 @@ class Memo < ActiveRecord::Base "subject", "content", "forum_id", - "last_reply_id", + "last_memo_id", "lock", "parent_id", "replies_count", @@ -39,8 +39,8 @@ class Memo < ActiveRecord::Base # after_update :update_memos_forum after_destroy :reset_counters! # after_create :send_notification - after_save :plusParentAndForum - after_destroy :minusParentAndForum + # after_save :plusParentAndForum + # after_destroy :minusParentAndForum # scope :visible, lambda { |*args| # includes(:forum => ).where() @@ -62,7 +62,7 @@ class Memo < ActiveRecord::Base if parent && parent.id Memo.update_all({:last_reply_id => parent.children.maximum(:id)}, {:id => parent.id}) end - # forums.reset_counters! + forum.reset_counters! end def sticky=(arg) diff --git a/app/views/forums/index.html.erb b/app/views/forums/index.html.erb index 80c379ed0..f79c44ae9 100644 --- a/app/views/forums/index.html.erb +++ b/app/views/forums/index.html.erb @@ -32,16 +32,16 @@ -<% @forums.each do |forum| %> +< % @forums.each do |forum| %> -<%= forum.name %> -<%= forum.description %> -<%= forum.creator.show_name %> -<%= link_to 'Show', forum %> -<%= link_to 'Edit', edit_forum_path(forum) %> -<%= link_to 'Destroy', forum, method: :delete, data: { confirm: 'Are you sure?' } %> +< %= forum.name %> +< %= forum.description %> +< %= forum.creator.show_name %> +< %= link_to 'Show', forum %> +< %= link_to 'Edit', edit_forum_path(forum) %> +< %= link_to 'Destroy', forum, method: :delete, data: { confirm: 'Are you sure?' } %> -<% end %> +< % end %>
--> diff --git a/app/views/welcome/index.html.erb b/app/views/welcome/index.html.erb index 95b0f92fa..2e645ddbf 100644 --- a/app/views/welcome/index.html.erb +++ b/app/views/welcome/index.html.erb @@ -97,227 +97,126 @@ <%= stylesheet_link_tag 'welcome' %>
- - - -
- +
-

热门竞赛

- -
- -
+

热门竞赛

+
+ +
-
-

最新众包

- -
- -
+
+

热门众包

+ +
+
    + <% find_all_hot_bid.map do |bid| break if(bid == find_all_hot_bid[5]) %> +
  • +

    + <%= link_to( bid.name, respond_path(bid.id), :class => "d-g-blue d-p-project-name", :target => "_blank", :title => "#{bid.name}")%> +

    +

    + <%= bid.description.truncate(50, omission: '...') %> +

    +
  • + <% end %> +
+
-

热门课程

- -
-
    - <% find_all_hot_course.map do |project| break if(project == find_all_hot_course[5]) %> -
  • -

    - <%= link_to( project.name, project_path(project.project_id), :class => "d-g-blue d-p-project-name", :target => "_blank", :title => "#{project.name}")%> -

    -

    - <%= project.description %> -

    -
  • - <% end %> -
-
+

热门课程

+
+
    + <% find_all_hot_course.map do |project| break if(project == find_all_hot_course[5]) %> +
  • +

    + <%= link_to( project.name, project_path(project.project_id), :class => "d-g-blue d-p-project-name", :target => "_blank", :title => "#{project.name}")%> +

    +

    + <%= project.description.truncate(50, omission: '...') %> +

    +
  • + <% end %> +
+
@@ -328,43 +227,4 @@ - - - - diff --git a/lib/plugins/acts_as_activity_provider/lib/acts_as_activity_provider.rb b/lib/plugins/acts_as_activity_provider/lib/acts_as_activity_provider.rb index 4c0a1c8a5..6e48ff4b7 100644 --- a/lib/plugins/acts_as_activity_provider/lib/acts_as_activity_provider.rb +++ b/lib/plugins/acts_as_activity_provider/lib/acts_as_activity_provider.rb @@ -103,7 +103,7 @@ module Redmine end if provider_options.has_key?(:permission) - user1 = User.find_by_login('user') + user1 = User.find_by_admin(true) scope = scope.scoped(:conditions => Project.allowed_to_condition(user1, provider_options[:permission] || :view_project, options)) elsif respond_to?(:visible) scope = scope.visible(user1, options) diff --git a/lib/redmine.rb b/lib/redmine.rb index ee3967aae..6f0a36757 100644 --- a/lib/redmine.rb +++ b/lib/redmine.rb @@ -203,7 +203,7 @@ Redmine::MenuManager.map :top_menu do |menu| menu.push :software_user, {:controller => 'users', :action => 'index'} menu.push :contest_innovate, {:controller => 'bids', :action => 'contest', :project_type => 1} menu.push :requirement_enterprise, {:controller => 'bids', :action => 'index'} - menu.push :project_module_forums, {:controller => 'forums', :action => 'index'} + menu.push :project_module_forums, :forums_path # menu.push :investor, :home_path diff --git a/public/images/list-icon.png b/public/images/list-icon.png new file mode 100644 index 000000000..930d6aae0 Binary files /dev/null and b/public/images/list-icon.png differ diff --git a/public/stylesheets/welcome.css b/public/stylesheets/welcome.css index e22f53fc3..bd8ec1d92 100644 --- a/public/stylesheets/welcome.css +++ b/public/stylesheets/welcome.css @@ -155,7 +155,7 @@ li { color: #999999; background: center -1px no-repeat; line-height: 20px; - padding: 0px 9px; + padding: 5px 5px 0px 9px; width: 440px; cursor: pointer; font: 12px/1.5 tahoma,arial,\5b8b\4f53; @@ -191,6 +191,19 @@ p.layout { margin-bottom: 6px; } +.avatar-3 { + width: 40px; + height: 40px; + margin-top: 5px; +} +.message-brief-intro .gray{ + color: gray; +} + +.avatar-4 { + width: 45px; + height: 45px; +} /*p.clr, .clr { clear:both; padding:0; margin:0; background:none;}*/