修改了用户活动,可以查看关注好友的活动,并且将需求加入到活动中

修复了一些需求中的BUG
This commit is contained in:
fanqiang 2013-08-05 22:47:01 +08:00
parent c3f81ba00e
commit bb5052cf30
17 changed files with 920 additions and 842 deletions

View File

@ -1,5 +1,4 @@
# fq # fq
class BidsController < ApplicationController class BidsController < ApplicationController
before_filter :find_bid, :only => [:show, :show_project, :create, :destroy, :more, :back, :add] before_filter :find_bid, :only => [:show, :show_project, :create, :destroy, :more, :back, :add]
@ -11,8 +10,13 @@ class BidsController < ApplicationController
@limit = 5 @limit = 5
@bid_count = Bid.count @bid_count = Bid.count
@bid_pages = Paginator.new @bid_count, @limit, params['page'] @bid_pages = Paginator.new @bid_count, @limit, params['page']
@offset ||= @bid_pages.offset @offset ||= @bid_pages.reverse_offset
@bids = Bid.offset(@offset).limit(@limit).all unless @offset == 0
@bids = Bid.offset(@offset).limit(@limit).all.reverse
else
limit = @bid_count%@limit
@bids = Bid.offset(@offset).limit(limit).all.reverse
end
end end
@ -98,7 +102,7 @@ class BidsController < ApplicationController
# @message_count = a_message.count # @message_count = a_message.count
respond_to do |format| respond_to do |format|
# format.html # format.html
format.js format.js
#format.api { render_api_ok } #format.api { render_api_ok }
end end
@ -132,7 +136,7 @@ class BidsController < ApplicationController
@bids = Bid.offset(@offset).limit(@limit).all @bids = Bid.offset(@offset).limit(@limit).all
respond_to do |format| respond_to do |format|
# format.html # format.html
format.html { redirect_to :back } format.html { redirect_to :back }
format.js format.js
# format.api { render_api_ok } # format.api { render_api_ok }
end end
@ -165,8 +169,8 @@ class BidsController < ApplicationController
private private
def find_bid def find_bid
if params[:bid_id] if params[:id]
@bid = Bid.find(params[:bid_id]) @bid = Bid.find(params[:id])
end end
rescue rescue
render_404 render_404

View File

@ -27,7 +27,7 @@ class UsersController < ApplicationController
include CustomFieldsHelper include CustomFieldsHelper
include AvatarHelper include AvatarHelper
# added by liuping 关注 # added by liuping 关注
helper :watchers helper :watchers
helper :activities helper :activities
@ -35,7 +35,6 @@ class UsersController < ApplicationController
### added by william ### added by william
include ActsAsTaggableOn::TagsHelper include ActsAsTaggableOn::TagsHelper
helper :watchers helper :watchers
helper :activities helper :activities
@ -74,14 +73,19 @@ class UsersController < ApplicationController
end end
end end
# added by fq
def user_activities def user_activities
#####fq #####fq
# @message = MessagesForUser.find_message(@user.id) # @message = MessagesForUser.find_message(@user.id)
# show projects based on current user visibility # show projects based on current user visibility
# @memberships = @user.memberships.all(:conditions => Project.visible_condition(User.current)) # @memberships = @user.memberships.all(:conditions => Project.visible_condition(User.current))
@watcher = User.watched_by_id(@user)
events = []
for user in @watcher
events << Redmine::Activity::Fetcher.new(User.current, :author => @user).events(nil, nil, :limit => 30)
end
events = Redmine::Activity::Fetcher.new(User.current, :author => @user).events(nil, nil, :limit => 30)
@events_by_day = events.group_by(&:event_date) @events_by_day = events.group_by(&:event_date)
unless User.current.admin? unless User.current.admin?
@ -96,9 +100,10 @@ class UsersController < ApplicationController
format.api format.api
end end
end end
# end
def user_newfeedback def user_newfeedback
@jour = @user.journals_for_messages @jour = @user.journals_for_messages
@jour.each_with_index {|j,i| j.indice = i+1} @jour.each_with_index {|j,i| j.indice = i+1}
@state = false @state = false
@ -107,6 +112,7 @@ class UsersController < ApplicationController
def user_comments def user_comments
end end
#end #end
def index def index
sort_init 'login', 'asc' sort_init 'login', 'asc'
@ -125,7 +131,6 @@ class UsersController < ApplicationController
} }
# @count = Redmine::Activity::Fetcher.new(User.current, :author => @user).scope_select {|t| !has["show_#{t}"].nil?}.events(nil, nil).count # @count = Redmine::Activity::Fetcher.new(User.current, :author => @user).scope_select {|t| !has["show_#{t}"].nil?}.events(nil, nil).count
scope = User.logged.status(@status) scope = User.logged.status(@status)
scope = scope.like(params[:name]) if params[:name].present? scope = scope.like(params[:name]) if params[:name].present?
scope = scope.in_group(params[:group_id]) if params[:group_id].present? scope = scope.in_group(params[:group_id]) if params[:group_id].present?
@ -144,13 +149,23 @@ class UsersController < ApplicationController
end end
end end
### modified by fq
def show def show
#####fq #####fq
@message = MessagesForUser.find_message(@user.id) @message = MessagesForUser.find_message(@user.id)
# show projects based on current user visibility # show projects based on current user visibility
@memberships = @user.memberships.all(:conditions => Project.visible_condition(User.current)) @memberships = @user.memberships.all(:conditions => Project.visible_condition(User.current))
if @user == User.current
events = []
events += Redmine::Activity::Fetcher.new(User.current, :author => User.current).events(nil, nil, :limit => 10)
@watcher = User.watched_by(@user)
for user in @watcher
events += Redmine::Activity::Fetcher.new(User.current, :author => user).events(nil, nil, :limit => 10)
end
else
events = Redmine::Activity::Fetcher.new(User.current, :author => @user).events(nil, nil, :limit => 10)
end
events = Redmine::Activity::Fetcher.new(User.current, :author => @user).events(nil, nil, :limit => 10)
@events_by_day = events.group_by(&:event_date) @events_by_day = events.group_by(&:event_date)
unless User.current.admin? unless User.current.admin?
@ -166,6 +181,8 @@ class UsersController < ApplicationController
end end
end end
##end fq
def new def new
@user = User.new(:language => Setting.default_language, :mail_notification => Setting.default_notification_option) @user = User.new(:language => Setting.default_language, :mail_notification => Setting.default_notification_option)
@auth_sources = AuthSource.all @auth_sources = AuthSource.all

View File

@ -16,9 +16,29 @@ class Bid < ActiveRecord::Base
# validates_format_of :deadline, :with => # validates_format_of :deadline, :with =>
validate :validate_user validate :validate_user
scope :visible, lambda {|*args|
nil
}
scope :like, lambda {|arg|
if arg.blank?
where(nil)
else
pattern = "%#{arg.to_s.strip.downcase}%"
where("LOWER(identifier) LIKE :p OR LOWER(name) LIKE :p OR LOWER(description) LIKE :p", :p => pattern)
end
}
acts_as_watchable acts_as_watchable
acts_as_taggable acts_as_taggable
acts_as_event :title => Proc.new {|o| "#{l(:label_requirement)} ##{o.id}: #{o.name}" },
:description => :description,
:author => :author,
:url => Proc.new {|o| {:controller => 'bids', :action => 'show', :id => o.id}}
acts_as_activity_provider :find_options => {:include => [:author]},
:author_key => :author_id
def add_jour(user, notes) def add_jour(user, notes)
self.journals_for_messages << JournalsForMessage.new(:user_id => user.id, :notes => notes) self.journals_for_messages << JournalsForMessage.new(:user_id => user.id, :notes => notes)
@ -26,23 +46,23 @@ class Bid < ActiveRecord::Base
def self.creat_bids(budget, deadline, name, description=nil) def self.creat_bids(budget, deadline, name, description=nil)
self.create(:author_id => User.current.id, :budget => budget, self.create(:author_id => User.current.id, :budget => budget,
:deadline => deadline, :name => name, :description => description, :commit => 0) :deadline => deadline, :name => name, :description => description, :commit => 0)
end end
def update_bids(budget, deadline, name, description=nil) def update_bids(budget, deadline, name, description=nil)
if(User.current.id == self.author_id) if(User.current.id == self.author_id)
self.name = name self.name = name
self.budget = budget self.budget = budget
self.deadline = deadline self.deadline = deadline
self.description = description self.description = description
self.save self.save
end end
end end
def delete_bids def delete_bids
unless self.nil? unless self.nil?
if User.current.id == self.author_id if User.current.id == self.author_id
self.destroy self.destroy
end end
end end
end end

View File

@ -3,7 +3,7 @@
<td width="100px" class="font_lighter" style="font-size: 16px;">需求列表</td> <td width="100px" class="font_lighter" style="font-size: 16px;">需求列表</td>
<td> <td>
<div class='icon icon-add' > <div class='icon icon-add' >
<%= toggle_link l(:button_bidding), 'put-bid-form', {:focus => 'project_id'} %> <%= toggle_link l(:button_new_bid), 'put-bid-form', {:focus => 'project_id'} %>
</div></td> </div></td>
</table> </table>
@ -27,7 +27,7 @@
<td class="font_lighter">(<%= link_to bid.watcher_users.count, respond_path(bid)%>)关注</td> <td class="font_lighter">(<%= link_to bid.watcher_users.count, respond_path(bid)%>)关注</td>
</tr> </tr>
</table></td> </table></td>
<td width="200" align="right" class="a"><a class="font_lighter"> <%= format_time bid.created_at %></a></td> <td width="200" align="right" class="a"><a class="font_lighter"> <%= format_time bid.created_on %></a></td>
</tr> </tr>
<tr> <tr>
<td> <td>

View File

@ -20,6 +20,11 @@
<% end %> <% end %>
<% end %><td> <% end %><td>
</tr></table> </tr></table>
<div id='leave-message'>
<%= render :partial => 'new', :locals => {:bid => @bid, :sta => @state} %>
</div>
<% unless state%> <% unless state%>
<% if journals.size > 5 %> <% if journals.size > 5 %>
<% journals = journals[0, 5] %> <% journals = journals[0, 5] %>

View File

@ -11,6 +11,6 @@ border-top: 2px solid #acaeb1; border-bottom: 2px solid #acaeb1;">
</tr></table> </tr></table>
<table border="0" width="525px" align="center"> <table border="0" width="525px" align="center">
<tr><td align="right"><%= submit_tag l(:button_leave_meassge), :name => nil %> <tr><td align="right"><%= submit_tag l(:button_leave_meassge), :name => nil %>
<%= submit_tag l(:button_clear), :name => nil, :onclick => "clearMessage('user_message_message');", :type => 'button' %></td></tr> <%= submit_tag l(:button_clear), :name => nil, :onclick => "clearMessage('bid_message_message');", :type => 'button' %></td></tr>
</table> </table>
<% end %> <% end %>

View File

@ -1,4 +1,9 @@
<!-- fq --> <!-- fq -->
<table width="200px" border="0" style="padding-left: 15px">
<td class="font_lighter" style="font-size: 18px;">应标项目(<%= @bidding_project.count%>)</td>
</table>
<% @bidding_project.each do |b_project|%> <% @bidding_project.each do |b_project|%>
<table width="90%" border="0" align='center'> <table width="90%" border="0" align='center'>
<tr> <tr>

View File

@ -20,12 +20,12 @@
<tr><td style="font-size: 15px; color: rgb(0,0,0);"><%= @bid.description %></td></tr> <tr><td style="font-size: 15px; color: rgb(0,0,0);"><%= @bid.description %></td></tr>
</table> </table>
</div> </div>
<!-- added by fq -->
<div id="history"> <div id="history">
<%= render :partial => 'history', :locals => { :bid => @bid, :journals => @jour, :state => false} %> <%= render :partial => 'history', :locals => { :bid => @bid, :journals => @jour, :state => false} %>
</div> </div>
<div id='leave-message'>
<%= render :partial => 'new', :locals => {:bid => @bid, :sta => @state} %>
</div>
<!-- end --> <!-- end -->

View File

@ -27,9 +27,6 @@ border-top: 1px solid #acaeb1; border-bottom: 1px solid #acaeb1; margin-left: 45
<% end %> <% end %>
</div> </div>
<table width="200px" border="0" style="padding-left: 15px">
<td class="font_lighter" style="font-size: 18px;">应标项目(<%= @bidding_project.count%>)</td>
</table>
<div id='bidding_project_list'> <div id='bidding_project_list'>
<%= render :partial => 'project_list', :locals => {:bidding_project => @bidding_project} %> <%= render :partial => 'project_list', :locals => {:bidding_project => @bidding_project} %>
</div> </div>

View File

@ -1,26 +1,36 @@
<% unless @events_by_day.empty? %> <% unless @events_by_day.empty? %>
<div id="activity"> <div id="activity">
<% @events_by_day.keys.sort.reverse.each do |day| %> <% @events_by_day.keys.sort.reverse.each do |day| %>
<% @events_by_day[day].sort {|x,y| y.event_datetime <=> x.event_datetime }.each do |e| -%> <% @events_by_day[day].sort {|x,y| y.event_datetime <=> x.event_datetime }.each do |e| -%>
<table width="660" border="0" align="left"> <table width="660" border="0" align="left" style="border-bottom: 1px solid rgb(225, 225, 225); margin-bottom: 10px;">
<tr> <tr>
<td colspan="2" valign="top" width="50" ><img src="/images/new/news.png" width="40" height="40"/></td> <!-- fq -->
<td><table width="580" border="0"> <td colspan="2" valign="top" width="50" ><%= link_to image_tag(url_to_avatar(e.event_author), :class => "avatar"), user_path(e.event_author), :class => "avatar" %></td>
<tr> <td>
<td colspan="2" valign="top"><strong> <%= content_tag('span', h(e.project), :class => 'project') %></strong> <span class="font_lighter">有了最新动态</span> <%= link_to format_activity_title(e.event_title), e.event_url %></td> <table width="580" border="0">
</tr> <tr>
<tr> <% if e.event_author == User.current%>
<td colspan="2" width="580" ><p class="font_description"><%= textilizable e.event_description %></p></td> <td colspan="2" valign="top"><strong> <%= link_to("我", user_path(e.event_author)) %></strong><span class="font_lighter">有了最新动态</span> <%= link_to format_activity_title(e.event_title), e.event_url %></td>
</tr>
<tr> <% else %>
<td align="left"><a class="font_lighter"></a></td> <td colspan="2" valign="top"><strong> <%= link_to(h(e.event_author), user_path(e.event_author)) %></strong><span class="font_lighter">有了最新动态</span> <%= link_to format_activity_title(e.event_title), e.event_url %></td>
<td width="200" align="right" class="a"><span class="font_lighter"><%= format_activity_day(day) %></span></td> <% end %>
</tr> </tr>
<!-- <tr><div class="line_under"></div></tr> --> <tr>
</table></td> <td colspan="2" width="580" >
</tr> <p class="font_description">
<% end %> <%= textilizable e.event_description %>
</table><% end %> </p></td>
</tr>
<tr>
<td align="left"><a class="font_lighter"></a></td>
<td width="200" align="right" class="a"><span class="font_lighter"><%= format_activity_day(day) %></span></td>
</tr>
<!-- <tr><div class="line_under"></div></tr> -->
</table></td>
</tr>
<% end %>
</table>
<% end %>
</div> </div>
<% end %> <% end %>

View File

@ -1,3 +1,5 @@
<!-- fq -->
<table width="200px" border="0" style="padding-left: 10px; margin-bottom: 15px;"> <table width="200px" border="0" style="padding-left: 10px; margin-bottom: 15px;">
<td class="font_lighter" style="font-size: 18px;">需求列表</td> <td class="font_lighter" style="font-size: 18px;">需求列表</td>
</table> </table>
@ -22,7 +24,7 @@
<td class="font_lighter">(<%= bid.watcher_users.count%>)关注</td> <td class="font_lighter">(<%= bid.watcher_users.count%>)关注</td>
</tr> </tr>
</table></td> </table></td>
<td width="200" align="right" class="a"><a class="font_lighter"> <%= format_time bid.created_at %></a></td> <td width="200" align="right" class="a"><a class="font_lighter"> <%= format_time bid.created_on %></a></td>
</tr> </tr>
<tr> <tr>
<td> <td>

View File

@ -412,13 +412,13 @@ RedmineApp::Application.routes.draw do
delete 'bids/destroy', :to => 'bids#destroy' delete 'bids/destroy', :to => 'bids#destroy'
get 'bids/more', :to => 'bids#more' get 'bids/more', :to => 'bids#more'
get 'bids/back', :to=> 'bids#back' get 'bids/back', :to=> 'bids#back'
match 'bids/:bid_id/show_project', :controller => 'bids', :action => 'show_project', :as => 'project_for_bid' match 'bids/:id/show_project', :controller => 'bids', :action => 'show_project', :as => 'project_for_bid'
match 'bids/:bid_id/add', :controller => 'bids', :action => 'add' match 'bids/:id/add', :controller => 'bids', :action => 'add'
match 'bids/new_bid', :controller => 'bids', :action => 'new_bid' match 'bids/new_bid', :controller => 'bids', :action => 'new_bid'
# added by young # added by young
match 'bids', :controller => 'bids', :action => 'index' match 'bids', :controller => 'bids', :action => 'index'
match 'bids/:bid_id/show', :controller => 'bids', :action => 'show', :as => 'respond' match 'bids/:id', :controller => 'bids', :action => 'show', :as => 'respond'
match 'bids/new', :controller => 'bids', :action => 'new', :via => [:get , :post] match 'bids/new', :controller => 'bids', :action => 'new', :via => [:get , :post]

View File

@ -0,0 +1,4 @@
class ChangeTimetempInBidTable < ActiveRecord::Migration
rename_column :bids, :created_at, :created_on
rename_column :bids, :updated_at, :updated_on
end

View File

@ -11,7 +11,7 @@
# #
# It's strongly recommended to check this file into your version control system. # It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20130802011758) do ActiveRecord::Schema.define(:version => 20130805131602) do
create_table "a_user_watchers", :force => true do |t| create_table "a_user_watchers", :force => true do |t|
t.string "name" t.string "name"
@ -83,8 +83,8 @@ ActiveRecord::Schema.define(:version => 20130802011758) do
t.integer "author_id" t.integer "author_id"
t.date "deadline" t.date "deadline"
t.string "description" t.string "description"
t.datetime "created_at", :null => false t.datetime "created_on", :null => false
t.datetime "updated_at", :null => false t.datetime "updated_on", :null => false
t.integer "commit" t.integer "commit"
end end

View File

@ -282,6 +282,9 @@ Redmine::Activity.map do |activity|
activity.register :wiki_edits, :class_name => 'WikiContent::Version', :default => false activity.register :wiki_edits, :class_name => 'WikiContent::Version', :default => false
activity.register :messages, :default => false activity.register :messages, :default => false
activity.register :time_entries, :default => false activity.register :time_entries, :default => false
# added by fq
activity.register :bids, :class_name => 'Bid'
# end
end end
Redmine::Search.map do |search| Redmine::Search.map do |search|

View File

@ -42,6 +42,17 @@ module Redmine
(page - 1) * per_page (page - 1) * per_page
end end
## fq
def reverse_offset
offset = @item_count-@per_page*page
if offset < 0
offset = 0
end
offset
end
## end
def first_page def first_page
if item_count > 0 if item_count > 0
1 1