添加写project_status和user_status两表的方法,

在关注中写这2个表,
重构了tag的过滤方法,
拿掉了user_extension.rb.
exceptionHandle
william 12 years ago
parent c7beefa556
commit 0c22d409fc

File diff suppressed because it is too large Load Diff

@ -14,10 +14,8 @@
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class WatchersController < ApplicationController
before_filter :require_login, :find_watchables, :only => [:watch, :unwatch]
def watch
set_watcher(@watchables, User.current, true)
end
@ -100,7 +98,27 @@ class WatchersController < ApplicationController
def set_watcher(watchables, user, watching)
watchables.each do |watchable|
watchable.set_watcher(user, watching)
@user = watchable # added by william
# @user = watchable # added by william
if watching
# 修改 user和project的状态
if watchable.instance_of?(User)
#写user_statuses表
watchable.user_status.update_watchers_count(1)
elsif watchable.instance_of?(Project)
#写project_statuese表
watchable.project_status.update_watchers_count(1)
end
else
# 修改 user和project的状态
if watchable.instance_of?(User)
#写user_statuses表
watchable.user_status.update_watchers_count(-1)
elsif watchable.instance_of?(Project)
#写project_statuese表 :project_status
watchable.project_status.update_watchers_count(-1)
end
end
end
respond_to do |format|
format.html { redirect_to_referer_or {render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true}}

@ -34,7 +34,7 @@ module BidsHelper
# this method is used to get all projects that tagged one tag
# added by william
def get_bids_by_tag(tag_name)
Bid.tagged_with(tag_name)
Bid.tagged_with(tag_name).order('updated_on desc')
end
end

@ -377,7 +377,7 @@ module IssuesHelper
# this method is used to get all projects that tagged one tag
# added by william
def get_issues_by_tag(tag_name)
Issue.tagged_with(tag_name)
Issue.tagged_with(tag_name).order('updated_on desc')
end
end

@ -85,7 +85,7 @@ module ProjectsHelper
# this method is used to get all projects that tagged one tag
# added by william
def get_projects_by_tag(tag_name)
Project.tagged_with(tag_name)
Project.tagged_with(tag_name).order('updated_on desc')
end
end

@ -58,7 +58,7 @@ module UsersHelper
# this method is used to get all projects that tagged one tag
# added by william
def get_users_by_tag(tag_name)
User.tagged_with(tag_name)
User.tagged_with(tag_name).order('updated_on desc')
end
# added by fq

@ -56,6 +56,8 @@ class Project < ActiveRecord::Base
# end
#ADDED BY NIE
has_many :project_infos, :dependent => :destroy
has_one :project_status, :class_name => "ProjectStatus", :dependent => :destroy
#end
has_one :wiki, :dependent => :destroy
# Custom field for the project issues
@ -82,7 +84,7 @@ class Project < ActiveRecord::Base
:author => nil
############################added by william
acts_as_taggable
scope :by_join_date, order("created_at DESC")
scope :by_join_date, order("created_on DESC")
###################added by liuping 关注
acts_as_watchable

@ -0,0 +1,21 @@
class ProjectStatus < ActiveRecord::Base
attr_accessible :changesets_count, :watchers_count, :project_id
belongs_to :projects
belongs_to :watchers
belongs_to :changesets
validates_presence_of :project_id
validates_uniqueness_of :project_id
# 更新字段 watchers_count 加1 这里没有做用户是否存在的匹配
# 负责这个表的聂同学 是在新建用户时就新建了该表的记录
# 但是 如果超级用户删除其他用户的话会造成读取错误 这里是遗漏点
# 删除用户时 此表创建人员未作相应删除动作
def update_watchers_count(num)
if self.watchers_count >= 0
self.update_attribute(:watchers_count, self.watchers_count.to_i + num)
end
end
end

@ -89,6 +89,7 @@ class User < Principal
######added by nie
has_many :project_infos, :dependent => :destroy
has_one :user_status, :dependent => :destroy
#####
scope :logged, lambda { where("#{User.table_name}.status <> #{STATUS_ANONYMOUS}") }
@ -99,10 +100,10 @@ class User < Principal
acts_as_customizable
############################added by william
acts_as_taggable
scope :by_join_date, order("created_at DESC")
scope :by_join_date, order("created_on DESC")
############################# added by liuping 关注
acts_as_watchable
has_one :user_extensions
has_one :user_extensions,:dependent => :destroy
## end
attr_accessor :password, :password_confirmation

@ -1,11 +0,0 @@
class UserExtension < ActiveRecord::Base
attr_accessible :birthday, :brief_introduction, :fans_num, :finish_project_num, :follow_num, :gender, :good_num, :location, :occupation, :publish_requirement_num, :user_id, :work_experience, :zip_code
belongs_to :user
validate :validate_user
def validate_user
errors.add :user_id, :invalid if user.nil? || !user.active? || User.current != user_id
end
end

@ -0,0 +1,20 @@
class UserStatus < ActiveRecord::Base
attr_accessible :changesets_count, :user_id, :watchers_count
belongs_to :users
belongs_to :watchers
belongs_to :changesets
validates_presence_of :user_id
validates_uniqueness_of :user_id
# 更新字段 watchers_count 加1 这里没有做用户是否存在的匹配
# 负责这个表的聂同学 是在新建用户时就新建了该表的记录
# 但是 如果超级用户删除其他用户的话会造成读取错误 这里是遗漏点
# 删除用户时 此表创建人员未作相应删除动作
def update_watchers_count(num)
if self.watchers_count >= 0
self.update_attribute(:watchers_count, self.watchers_count.to_i + num)
end
end
end

@ -69,7 +69,7 @@
<%= render :partial => 'users/preferences' %></div>
</fieldset>
<!-- added by william -->
<fieldset class="collapsible collapsed" style="width:800px;margin-left: 10px;display: none;">
<fieldset class="collapsible collapsed" style="width:800px;margin-left: 10px;display: none">
<legend onclick="toggleFieldset(this);">
<%= l(:label_user_extensions)%>
</legend>

@ -6,10 +6,7 @@
<span id="tag">
<%= rt %>
</span>
<% @issue_size = Issue.tagged_with("#{rt}").size %>
<% @project_size = Project.tagged_with(rt).size %>
<% @user_size = User.tagged_with("#{rt}").size %>
(<%= @user_size + @project_size + @issue_size %>)
<%= render :partial => 'sidebar_tags',:locals => {:show_flag => show_flag,:sg => rt }%>
</li>
<% end %>
</ul>

@ -2,12 +2,10 @@
<ul style="list-style-type: none">
<% for sg in selected_tags %>
<li>
<%= link_to image_tag("/images/sidebar/minus.png"),:action => "delete_tag",:remote=>true,:tag => sg,:show_flag => show_flag %>
<%= link_to image_tag("/images/sidebar/minus.png"),:action => "delete_tag",
:remote=>true,:tag => sg,:show_flag => show_flag %>
<span id="tag"><%= sg %> </span>
<% @issue_size = Issue.tagged_with("#{sg}").size %>
<% @project_size = Project.tagged_with(sg).size %>
<% @user_size = User.tagged_with("#{sg}").size %>
(<%= @user_size + @project_size + @issue_size %>)
<%= render :partial => 'sidebar_tags',:locals => {:show_flag => show_flag,:sg => sg }%>
</li>
<% end %>
</ul>

@ -6,6 +6,7 @@
<strong><%= l(:label_tags_bid) %>:<%= link_to "#{bid.name}",:controller => "bids",:action => "show",:id => bid.id %></strong>
<br />
<strong><%= l(:label_tags_bid_description) %>:</strong><%= bid.description %>
<%= bid.updated_on %>
</p>
<div class="line_under"></div>
<% end %>

@ -40,6 +40,4 @@
<div><%= l(:label_tags_no) %></div>
<% end %>
<% end %>

@ -15,16 +15,14 @@
<%= render :partial => "show_bids",:locals => {:bids_results => bids_results}%>
<% else %>
<strong><%= l(:label_tags_all_objects)%></strong>
<!-- 这里为显示搜有过滤结果预留了默认设置 -->
<%= render :partial => "show_issues",:locals => {:issues_results => issues_results }%>
<%= render :partial => "show_users",:locals => {:users_results => users_results }%>
<%= render :partial => "show_projects",:locals => {:projects_results => projects_results }%>
<%= render :partial => "show_bids",:locals => {:bids_results => bids_results}%>
<% end %>
<% else %>
<span>no data.</span>
<% end %>
</ul>
<div class="pagination" style="float:right;">
<ul>
<%= pagination_links_full @obj_pages %>
<ul>
</div>

@ -4,6 +4,7 @@ $('#related_tags').html('<%= j(render :partial => "related_tags",
:locals => {:related_tags => $related_tags ,:show_flag => @show_flag })%>')
$('#show_results').html('<%= j(render :partial => "tag_search_results",:locals => {:issues_results => @issues_results,
:projects_results => @projects_results,:users_results => @users_results,:bids_results => @bids_results ,:show_flag => @show_flag })%>')
:projects_results => @projects_results,:users_results => @users_results,
:bids_results => @bids_results ,:show_flag => @show_flag,:obj_pages => @obj_pages })%>')

@ -4,5 +4,7 @@ $('#related_tags').html('<%= j(render :partial => "related_tags",
:locals => {:related_tags => $related_tags,:show_flag => @show_flag })%>')
$('#show_results').html('<%= j(render :partial => "tag_search_results",:locals => {:issues_results => @issues_results,
:projects_results => @projects_results,:users_results => @users_results,:bids_results => @bids_results ,:show_flag => @show_flag })%>')
:projects_results => @projects_results,:users_results => @users_results,
:bids_results => @bids_results ,:show_flag => @show_flag ,:obj_pages => @obj_pages })%>')

@ -23,8 +23,11 @@
</div>
<div id="show_results">
<%= render :partial => "tag_search_results",:locals => {:issues_results => @issues_results,
:projects_results => @projects_results,:users_results => @users_results ,:bids_results=>@bids_results,:show_flag => @obj_flag}%>
:projects_results => @projects_results,:users_results => @users_results ,
:bids_results=>@bids_results,:show_flag => @obj_flag}%>
</div>
</div>
<%= render :partial => "pagination",:locals => {:obj_pages => @obj_pages}%>
<% end %>

@ -5,7 +5,7 @@
<div id="show_all_tags">
<% for tag in @tags %>
<span id="tag" class="tag<%= tag.id %>">
<%= link_to tag.name,:remote=>true,:action=>"delete",:q => tag.id%>
<%= link_to tag.name,:remote=>true,:action=>"delete",:q => tag.id,:confirm => "Are you Sure?"%>
</span>
<% end %>
<% end %>

@ -1,5 +1,2 @@
<% selector = ".#{watcher_css(watched)}" %>
$("<%= selector %>").each(function(){$(this).replaceWith("<%= escape_javascript watcher_link(watched, user) %>")});
$('#fans_num').html('<%= j(render :partial => "/watchers/fans_num",:locals => {:fans_num => get_fans_num(@user) }
) %>');

Loading…
Cancel
Save