add the project what one watch

This commit is contained in:
xianbo 2013-10-24 08:24:56 +08:00
parent 5d0b5812b3
commit 2589d429b0
32 changed files with 660 additions and 146 deletions

View File

@ -307,11 +307,14 @@ class BidsController < ApplicationController
# a = [1]
# @project = Project.where("id in []", a)
@user = @bid.author
@bidding_project = @bid.biding_projects
@bidding_project = @bid.biding_projects.all
@bidding_project = @bidding_project.sort {|a,b| b.project.project_status.grade <=> a.project.project_status.grade}
if @bid.homework_type == 1
@homework = HomeworkAttach.new
@homework_list = @bid.homeworks
end
respond_to do |format|
if @bid.reward_type == 3
format.html {

View File

@ -48,12 +48,14 @@ class MembersController < ApplicationController
def create
members = []
project_info = []
user_grade = []
if params[:membership]
if params[:membership][:user_ids]
attrs = params[:membership].dup
user_ids = attrs.delete(:user_ids)
user_ids.each do |user_id|
members << Member.new(:role_ids => params[:membership][:role_ids], :user_id => user_id)
user_grade << UserGrade.new(:user_id => user_id, :project_id => @project.id)
## added by nie
if(params[:membership][:role_ids] && params[:membership][:role_ids][0] == "3")
project_info << ProjectInfo.new(:user_id => user_id, :project_id => @project.id)
@ -65,13 +67,14 @@ class MembersController < ApplicationController
members << Member.new(:role_ids => params[:membership][:role_ids], :user_id => params[:membership][:user_id])
## added by nie
if(params[:membership][:role_ids] && params[:membership][:role_ids][0] == "3")
project_info << ProjectInfo.new(:role_ids => params[:membership][:role_ids], :user_id => params[:membership][:user_id])
project_info << ProjectInfo.new(:project_id => @project.id, :user_id => params[:membership][:user_id])
end
## end
end
@project.members << members
# added by nie
@project.project_infos << project_info
@project.user_grades << user_grade
# end
end
@ -124,13 +127,20 @@ class MembersController < ApplicationController
def destroy
if request.delete? && @member.deletable?
@member.destroy
end
# end
user_admin = ProjectInfo.where("user_id = ? and project_id = ?", @member.user_id, @project.id)
if user_admin.size > 0
user_admin.each do |user|
user.destroy
end
end
user_grade = UserGrade.where("user_id = ? and project_id = ?", @member.user_id, @project.id)
if user_grade.size > 0
user_grade.each do |grade|
grade.destroy
end
end
end
respond_to do |format|
format.html { redirect_to_settings_in_projects }
format.js

View File

@ -146,8 +146,20 @@ class ProjectsController < ApplicationController
#
# end
# end
# @projects = Project.where("project_type <> ? or project_type is null", 1)
# @projects.each do |project|
# ProjectStatus.create(:changesets_count => project.changesets.count, :project_id => project.id, :watchers_count => project.watcher_users.count)
# @id = project.id
# @users = Member.find_by_sql("SELECT
# members.user_id
# FROM members
# INNER JOIN users
# ON members.user_id = users.id
# WHERE members.project_id = #{@id}
# AND (users.type = 'User' AND users.status = 1);")
# @users.each do |user|
# UserGrade.create(:project_id => project.id, :user_id => user.user_id)
# end
# #ProjectStatus.create(:changesets_count => project.changesets.count, :project_id => project.id, :watchers_count => project.watcher_users.count)
# end
# @projects_status = Project.visible.like(params[:name]) if params[:name].present?
@project_count = @projects_status.count
@ -175,13 +187,13 @@ class ProjectsController < ApplicationController
when '1'
@offset ||= @project_pages.reverse_offset
unless @offset == 0
@projects_status = @projects_status.reorder('changesets_count').offset(@offset).limit(@limit).all.reverse
@projects_status = @projects_status.reorder('grade').offset(@offset).limit(@limit).all.reverse
else
limit = @project_count % @limit
if limit == 0
limit = @limit
end
@projects_status = @projects_status.reorder('changesets_count').offset(@offset).limit(limit).all.reverse
@projects_status = @projects_status.reorder('grade').offset(@offset).limit(limit).all.reverse
end
@s_type = 1
@ -202,13 +214,13 @@ class ProjectsController < ApplicationController
else
@offset ||= @project_pages.reverse_offset
unless @offset == 0
@projects_status = @projects_status.reorder('changesets_count').offset(@offset).limit(@limit).all.reverse
@projects_status = @projects_status.reorder('grade').offset(@offset).limit(@limit).all.reverse
else
limit = @project_count % @limit
if limit == 0
limit = @limit
end
@projects_status = @projects_status.reorder('changesets_count').offset(@offset).limit(limit).all.reverse
@projects_status = @projects_status.reorder('grade').offset(@offset).limit(limit).all.reverse
end
@s_type = 1
# @projects = @projects.sort {|x,y| y.created_on <=> x.created_on }
@ -524,8 +536,9 @@ class ProjectsController < ApplicationController
r = Role.givable.find_by_id(Setting.new_project_user_role_id.to_i) || Role.givable.first
m = Member.new(:user => User.current, :roles => [r])
project = ProjectInfo.new(:user_id => User.current.id, :project_id => @project.id)
if (params[:project][:is_public] == '1' && @course_tag != "1") || (@course_tag=="1" && params[:project][:is_public] == '1')
project_status = ProjectStatus.create(:project_id => @project.id, :watchers_count => 0, :changesets_count => 0, :project_type => @course_tag)
UserGrade.create(:user_id => User.current.id, :project_id => @project.id, :grade => 0)
if params[:project][:is_public] == '1'
project_status = ProjectStatus.create(:project_id => @project.id, :watchers_count => 0, :changesets_count => 0, :grade => 0, :project_type => @course_tag)
end
@project.members << m
@project.project_infos << project
@ -747,6 +760,20 @@ class ProjectsController < ApplicationController
if @project.project_type == 1
render :layout => 'base_courses'
end
# roles = Role.find_all_givable
# members = @project.member_principals.includes(:roles, :principal).all.sort
#
# users = UserGrade.find_by_sql("select * from user_grades where project_id = #{@project.id}").sort {|a,b| a[:grade] <=> b[:grade]}
#
# temp = []
# users.each do |user|
# members.each do |member|
# if member[:user_id] == user[:user_id]
# temp << member
# end
# end
# end
# temps = temp.reverse
end
# def news
@ -790,7 +817,7 @@ class ProjectsController < ApplicationController
project_status = ProjectStatus.find_by_project_id(@project.id)
project_status.destroy
elsif params[:project][:is_public] == '1'
project_status = ProjectStatus.create(:project_id => @project.id, :watchers_count => 0, :changesets_count => 0, :project_type => 1)
project_status = ProjectStatus.create(:project_id => @project.id, :watchers_count => 0, :changesets_count => 0,:grade => 0, :project_type => 1)
end
respond_to do |format|

View File

@ -1,6 +1,7 @@
# encoding: utf-8
class SharesController < ApplicationController
before_filter :require_login, :except => [:index]
before_filter :require_admin, :only => [:index]
# GET /shares
# GET /shares.json
def index

View File

@ -21,7 +21,7 @@ class UsersController < ApplicationController
menu_item :user_information, :only => :info
menu_item :user_course, :only => :user_courses
menu_item :user_homework, :only => :user_homeworks
menu_item :user_project, :only => :user_projects
menu_item :user_project, :only => [:user_projects, :watch_projects]
menu_item :requirement_focus, :only => :watch_bids
menu_item :user_newfeedback, :only => :user_newfeedback
@ -29,10 +29,12 @@ class UsersController < ApplicationController
#Ended by young
before_filter :require_admin, :except => [:show, :index, :search, :tag_save, :user_projects, :user_newfeedback, :user_comments, :watch_bids, :info, :user_watchlist, :user_fanslist,:update, :user_courses, :user_homeworks]
before_filter :require_admin, :except => [:show, :index, :search, :tag_save, :user_projects, :user_newfeedback, :user_comments, :watch_bids, :info,
:user_watchlist, :user_fanslist,:update, :user_courses, :user_homeworks, :watch_projects]
#edit has been deleted by huang, 2013-9-23
before_filter :find_user, :only => [:user_fanslist, :user_watchlist, :show, :edit, :update, :destroy, :edit_membership, :user_courses, :user_homeworks,
:destroy_membership, :user_activities, :user_projects, :user_newfeedback, :user_comments, :watch_bids, :info]
:destroy_membership, :user_activities, :user_projects, :user_newfeedback, :user_comments, :watch_bids, :info,
:watch_projects]
accept_api_auth :index, :show, :create, :update, :destroy,:tag_save
#william
@ -560,6 +562,22 @@ class UsersController < ApplicationController
@membership ||= Member.new
end
def watch_projects
@watch_type = Watcher.visible.where("watchable_type = ? and user_id = ?", 'Project', @user.id)
@watch_projects = []
unless @watch_type.nil?
@watch_type.each do |obj|
@watch_projects << Project.find(obj.watchable_id) if(Project.find(obj.watchable_id))
end
end
respond_to do |format|
format.html {
render :layout => 'base_users'
}
format.api
end
end
def update
@user.admin = params[:user][:admin] if params[:user][:admin]
@user.login = params[:user][:login] if params[:user][:login]

View File

@ -254,12 +254,14 @@ module ApplicationHelper
s << "</span>"
end
if @project.project_type == 1
unless Course.find_by_extra(@project.identifier).nil?
unless Course.find_by_extra(@project.identifier).tea_id == User.current.id
s << "<span style = 'float: right;'>"
s << join_in_course(@project, User.current)#, ['whiteButton'])
s << "</span>"
end
end
end
s << (render :partial => 'projects/project', :locals => {:project => project}).to_s
s << "</div>\n"
ancestors << project

View File

@ -70,6 +70,7 @@ class Project < ActiveRecord::Base
has_one :project_status, :class_name => "ProjectStatus", :dependent => :destroy
has_one :project_status, :class_name => "ProjectStatus", :dependent => :destroy
has_one :project_status, :class_name => "ProjectStatus", :dependent => :destroy
has_many :user_grades, :class_name => "UserGrade", :dependent => :destroy
#end
has_one :wiki, :dependent => :destroy
@ -88,7 +89,7 @@ class Project < ActiveRecord::Base
has_many :tags, :through => :project_tags, :class_name => 'Tag'
has_many :project_tags, :class_name => 'ProjectTags'
has_many :project_tags, :class_name => 'ProjectTags', :dependent => :destroy
acts_as_nested_set :order => 'name', :dependent => :destroy
acts_as_attachable :view_permission => :view_files,
@ -122,7 +123,10 @@ class Project < ActiveRecord::Base
after_save :update_position_under_parent, :if => Proc.new {|project| project.name_changed?}
after_save :update_inherited_members, :if => Proc.new {|project| project.inherit_members_changed?}
before_destroy :delete_all_members
def remove_references_before_destroy
return if self.id.nil?
Watcher.delete_all ['watchable_id = ?', id]
end
scope :has_module, lambda {|mod|
where("#{Project.table_name}.id IN (SELECT em.project_id FROM #{EnabledModule.table_name} em WHERE em.name=?)", mod.to_s)
}

View File

@ -95,10 +95,13 @@ class User < Principal
has_many :project_infos, :dependent => :destroy
has_one :user_status, :dependent => :destroy
#####
has_many :shares ,:dependent => :destroy
scope :logged, lambda { where("#{User.table_name}.status <> #{STATUS_ANONYMOUS}") }
scope :status, lambda {|arg| where(arg.blank? ? nil : {:status => arg.to_i}) }
scope :visible, lambda {|*args|
nil
}
acts_as_customizable

4
app/models/user_grade.rb Normal file
View File

@ -0,0 +1,4 @@
class UserGrade < ActiveRecord::Base
# attr_accessible :title, :body
belongs_to :project
end

View File

@ -26,6 +26,9 @@ class Watcher < ActiveRecord::Base
validates_presence_of :user
validates_uniqueness_of :user_id, :scope => [:watchable_type, :watchable_id]
validate :validate_user
scope :visible, lambda {|*args|
nil
}
# Unwatch things that users are no longer allowed to view
def self.prune(options={})

View File

@ -8,12 +8,14 @@
<td width="50px" valign="top" colspan="2" align="middle">
<div style="width: 50px; height: 50px;">
<%= link_to image_tag(url_to_avatar(b_project.project), :class => 'avatar3'), :class => "avatar" %>
</div></td>
<td width="65%" valign="top">
<table width="100%" valign="top">
<tr>
<td colspan="2" valign="top" width="50%"><strong>
<%= link_to(b_project.project.name, project_path(b_project.project)) %>
</strong><a class="font_lighter"><%= l(:label_join_bidding)%></a>
</td>
@ -21,7 +23,7 @@
<td style="color: red;" align="right" valign="0.1em" width="15%">
<strong><span id="reward_result_<%=b_project.id%>">
<%= l(:label_system_grade) %>:<%= (b_project.project.project_status.grade.nil? ? 0 : b_project.project.project_status.grade) unless (b_project.project.project_status.nil? && b_project.project.nil?) %>
<% if get_prize(b_project).nil? or get_prize(b_project) == "" %>
<% if @bid.deadline < Date.today %>
<%= l(:label_noawards)%>

View File

@ -1,12 +1,14 @@
<!-- fq -->
<%= render_flash_messages %>
<% if @bid.reward_type == 3 %>
<% unless User.current.nil?%>
<% if User.current.user_extensions.identity == 1 %>
<div class="font_lighter">
<p><%= l(:label_homework_prompt) %></p>
<P><%= l(:label_homework_prompt_content) %></P>
</div>
<% end %>
<% end %>
<table width="1000px" border="0" style="padding-left: 15px">
<td class="font_lighter" style="font-size: 15px;"><%= l(:label_homework_project) %>(<%= bidding_project.count%>)</td>
<td>

View File

@ -87,18 +87,11 @@
<div class="licences">
<%= content_tag('span', "#{l(:label_create_time)}: ") %><%= content_tag('span', format_time(@project.created_on)) %>
</div>
<div class="grade">
<%= content_tag('span', "#{l(:label_project_grade)}: ")%><span style='color:red'><%= @project.project_status.grade%></span>
</div>
<!-- added by liuping -->
<!-- <% unless User.current.member_of?(@project) %>
<%= watcher_link(@project, User.current) %>
<% end %>
<span style="float: right; margin-right: 100px">
<% if @project.project_type == 1 %>
<% unless Course.find_by_extra(@project.identifier).tea_id == User.current.id %>
<%= join_in_course(@project, User.current)%>
<% end %>
<% end %> -->
</span>

View File

@ -4,8 +4,20 @@
<%= error_messages_for 'member' %>
<% roles = Role.find_all_givable
members = @project.member_principals.includes(:roles, :principal).all.sort %>
<% if members.any? %>
<% members.each do |member| %>
<%
users = UserGrade.find_by_sql("select * from user_grades where project_id = #{@project.id}").sort {|a,b| a[:grade] <=> b[:grade]}
%>
<% temp = [] %>
<% users.each do |user|%>
<% members.each do |member|%>
<% if member[:user_id] == user[:user_id] %>
<% temp << member%>
<% end %>
<% end %>
<% end %>
<% temps = temp.reverse %>
<% if temps.any? %>
<% temps.each do |member| %>
<div class="well">
<!--Modified by nie-->
<% next if member.new_record? %>
@ -14,6 +26,7 @@
<% end %>
<%= member.user.nil? ? '' : (link_to image_tag(url_to_avatar(member.user), :class => 'avatar'), :class => "avatar") %>
<%= content_tag "div", link_to_user(member.principal), :class => "nomargin avatar_name" %>
<!-- added by huang modified by bai-->
<% if @project.project_type == 1 %>
<div class ="clear avatar_name"> <p>
@ -26,9 +39,17 @@
<% else %>
<% end %>
</p></div>
</p>
</div>
<% else%>
<%= content_tag "div", content_tag("p", member.roles.sort.collect(&:to_s).join(', ')), :class => "clear avatar_name" %>
<% users.each do |user|%>
<% if user[:user_id] == member[:user_id]%>
<div class="clear avatar_user">
<p><%= l(:label_user_for_project_grade) %>: <span style="color:red"><%= user[:grade] %></span></p>
</div>
<% end %>
<% end %>
<% end %>
<!-- end -->
<%= call_hook(:view_projects_settings_members_table_row, { :project => @project, :member => member}) %>
@ -41,3 +62,5 @@
</p>
<% end %>
</div>

View File

@ -28,25 +28,13 @@
</div>
<%end%>
<!-- <div class="pagination_list">
<ul>
<li>
<%= link_to l(:label_sort_by_time), projects_path(:project_sort_type => '0'),:class=>"test_new" %>
</li>
<li>
<%= link_to l(:label_sort_by_active), projects_path(:project_sort_type => '1'),:class=>"test_new" %>
</li>
<li>
<%= link_to l(:label_sort_by_influence), projects_path(:project_sort_type => '2'),:class=>"test_new" %>
</li>
</ul>
</div> -->
<div id="projects-index">
<%= render_project_hierarchy(@projects)%>
</div>
<!-- <p class="pagination"><%= pagination_links_full @project_pages%></p> -->
<div class="pagination">
<ul>
<%= pagination_links_full @project_pages %>

View File

@ -117,10 +117,16 @@
<div>
<%= link_to image_tag(url_to_avatar(user), :class => 'avatar'), user_path(user) %>
<%= content_tag "span", link_to_user(user), :class => "nomargin avatar_name" %>
<!-- <%= content_tag "div", "#{l(:label_user_grade)}:" %><%= user.user_status.grade %> -->
</div>
<div style="margin-top: 20px;margin-left:66px">
<%= l(:label_x_has_fans,:count=>user.watcher_users.count)%>
<%= l(:label_has_watchers,:count=>User.watched_by(user.id).count) %>
</div>
<div style="position:relative;float:left;margin-top:-20px;margin-left: 724px">
<%= l(:label_user_grade) %>: <span style="color:red"><%= user.user_status.grade %></span>
</div>
<div class="user-bottom">
@ -139,7 +145,7 @@
<div class="pagination">
<ul>
<%= pagination_links_full @user_pages, @user_count %>
<ul>
</ul>
</div>
<% html_title(l(:label_user_plural)) -%>
<% end -%>

View File

@ -1,8 +1,11 @@
<!--add by huang-->
<div class="content_frame">
<p><%= link_to "关注的项目" , {:controller => 'users', :action => 'watch_projects', :id => @user.id}%>
<% unless @memberships.empty? %>
<% if @user == User.current %>
<p><%= link_to(l(:label_project_new), {:controller => 'projects', :action => 'new', :course => 0, :project_type => @project_type}, :class => 'icon icon-add') if User.current.allowed_to?(:add_project, nil, :global => true) %></p>
<%= link_to(l(:label_project_new), {:controller => 'projects', :action => 'new', :course => 0, :project_type => @project_type}, :class => 'icon icon-add') if User.current.allowed_to?(:add_project, nil, :global => true) %></p>
<% end %>
<ul class="user_project_sort">
<% for membership in @memberships %>
@ -14,7 +17,7 @@
<table width="580" border="0">
<tr>
<td colspan="2" valign="top"><strong> <%= link_to_user(membership.user) if membership.respond_to?(:user) %></strong>
<span class="font_lighter"> <%= l(:label_create_project) %></span> <%= link_to_project(membership.project) %></td>
<span class="font_lighter"> <%= l(:label_watch_project) %></span> <%= link_to_project(membership.project) %></td>
</tr>
<tr>
<td colspan="2" width="580" >

View File

@ -0,0 +1,34 @@
<p><%= link_to "关注的项目" , {:controller => 'users', :action => 'watch_projects', :id => @user.id}%>
<% if @user == User.current %>
<%= link_to(l(:label_project_new), {:controller => 'projects', :action => 'new', :course => 0, :project_type => @project_type}, :class => 'icon icon-add') if User.current.allowed_to?(:add_project, nil, :global => true) %></p>
<% end %>
<% unless @watch_projects.nil?&&watch_projects.project.nil? %>
<% for watch_project in @watch_projects %>
<table width="660" border="0" align="center" style="border-bottom: 1px dashed rgb(204, 204, 204); margin-bottom: 10px;font-size:14px;">
<tr>
<td colspan="2" valign="top" width="50" ><%= link_to image_tag(url_to_avatar(watch_project.project), :class => 'avatar'), project_path(watch_project.project) %></td>
<td>
<table width="580" border="0">
<tr>
<td colspan="2" valign="top"><strong> <%= link_to_user(@user) if watch_project.respond_to?(:user) %></strong>
<span class="font_lighter"> <%= @user.name%><%= l(:label_watch_project) %></span> <%= link_to_project(watch_project.project) %></td>
</tr>
<tr>
<td colspan="2" width="580" >
<p class="font_description">
<%= watch_project.project.description%>
</p></td>
</tr>
<tr>
<td align="left"><span class="font_lighter"> <%= format_time(watch_project.created_on) %></span></td><!-- modified by ming -->
</tr>
</table></td>
</tr>
</table>
</li>
<% end %>
<% else %>
还米有关注任何项目
<% end %>

View File

@ -1631,9 +1631,19 @@ zh:
role_of_course: 课程角色
label_student: 学生
label_project_grade: 项目得分
label_user_grade: 个人得分
label_user_for_project_grade: 个人得分
label_system_grade: 系统评分
label_teacher: 老师
label_ta: 助教
label_in_course: 在课程中
label_assign_homework: 中布置了作业
label_noawards: 未评奖
label_course_modify_settings: 配置课程
label_module_share: dts测试工具
label_homework_prompt: 贴心小提示:
label_homework_prompt_content: 亲,在这里我们的作业将以项目的形式提交,如果小伙伴们还没有创建项目,请先创建一个项目。项目创建成功后,就可以
label_create_homework: 布置了作业:
label_watch_project: 关注了

View File

@ -16,7 +16,7 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
RedmineApp::Application.routes.draw do
resources :shares, only: [:new, :create, :destroy]
resources :shares
#added by william
get "tags/index"
@ -94,10 +94,13 @@ RedmineApp::Application.routes.draw do
match 'user_fanslist', :to => 'users#user_fanslist', :via => :get, :as => "user_fanslist" #add by huang
match 'user_courses', :to => 'users#user_courses', :via => :get
match 'user_homeworks', :to => 'users#user_homeworks', :via => :get
match 'watch_projects', :to => 'users#watch_projects', :via => :get
end
end
match 'users/:id/user_newfeedback', :to => 'users#user_newfeedback', :via => :get, :as => "feedback"
match 'users/:id/user_projects', :controller => 'users', :action => 'user_projects', :via => :get
#end
match 'my/account', :controller => 'my', :action => 'account', :via => [:get, :post]
match 'my/account/destroy', :controller => 'my', :action => 'destroy', :via => [:get, :post]
@ -129,6 +132,7 @@ RedmineApp::Application.routes.draw do
post 'issues/:object_id/watchers', :to => 'watchers#create', :object_type => 'issue'
delete 'issues/:object_id/watchers/:user_id' => 'watchers#destroy', :object_type => 'issue'
resources :projects do
member do
get 'settings(/:tab)', :action => 'settings', :as => 'settings'

View File

@ -4,19 +4,45 @@ class StoredStatusProcedure < ActiveRecord::Migration
execute "
create procedure `sp_user_status_cursor`()
begin
declare v_uid bigint(22);
declare v int(10);
declare _done TINYINT(1) default 0;
declare user_uid bigint(22);
declare user_changesets_count int(10);
declare _done tinyint(1) default 0;
declare cur_user cursor for select user_id, count(*) from changesets where user_id != '' group by user_id;
declare continue handler for not found set _done = 1;
open cur_user;
loop_xxx:loop
fetch cur_user into v_uid,v;
fetch cur_user into user_uid,user_changesets_count;
if _done=1 then
leave loop_xxx;
end if;
begin
update user_statuses set changesets_count = v where user_id = v_uid;
declare journals_for_messages_count int(10);
declare journals_count int(10);
declare comments_count int(10);
declare messages_count int(10);
declare news_count int(10);
declare wiki_contents_count int(10);
declare activities_count int(10);
declare total_count numeric(8,2);
select count(*) into journals_for_messages_count from journals_for_messages where user_id = user_uid;
select count(*) into journals_count from journals where user_id = user_uid;
select count(*) into comments_count from comments where author_id = user_uid;
select count(*) into messages_count from messages where author_id = user_uid;
select count(*) into news_count from news where author_id = user_uid;
select count(*) into wiki_contents_count from wiki_contents where author_id = user_uid;
select count(*) into activities_count from activities where user_id = user_uid;
set total_count = journals_for_messages_count*0.05 +
journals_count*0.1 +
comments_count*0.1 +
messages_count*0.05 +
news_count*0.1 +
wiki_contents_count*0.1 +
activities_count*0.2 +
user_changesets_count*0.3;
update user_statuses set changesets_count = user_changesets_count, grade = total_count where user_id = user_uid;
commit;
end;
end loop;
@ -24,34 +50,281 @@ end;
"
execute "
create event if not exists e_test
on schedule every 1 day starts'2013_08_27 01:50:00'
on schedule every 1 day starts'2013-08-27 01:50:00'
on completion preserve
do call `sp_user_status_cursor`();
"
execute "
create procedure `sp_project_status_cursor`()
begin
declare v_uid bigint(22);
declare v int(10);
declare _done TINYINT(1) default 0;
declare cur_user cursor for select project_id,count(*) from (select project_id,repositories.id from repositories inner join changesets where repositories.id = changesets.repository_id and project_id in (SELECT `projects`.id FROM `projects` WHERE (((projects.status <> 9) AND (projects.is_public = 1)))))t group by project_id;
declare continue handler for not found set _done = 1;
open cur_user;
loop_xxx:loop
fetch cur_user into v_uid,v;
if _done=1 then
leave loop_xxx;
end if;
begin
update project_statuses set changesets_count = v where project_id = v_uid;
commit;
end;
end loop;
end;
CREATE PROCEDURE `sp_project_status_cursor` ()
BEGIN
DECLARE project_uid bigint(22);
DECLARE project_changesets_count int(10);
DECLARE _done tinyint(1) DEFAULT 0;
DECLARE cur_project CURSOR FOR
SELECT
project_id,
COUNT(*)
FROM (SELECT
project_id,
repositories.id
FROM repositories
INNER JOIN changesets
WHERE repositories.id = changesets.repository_id
AND project_id IN (SELECT
projects.id
FROM projects
WHERE (((projects.status <> 9)
AND (projects.is_public = 1))))) t
GROUP BY project_id;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET _done = 1;
OPEN cur_project;
loop_xxx:
LOOP
FETCH cur_project INTO project_uid, project_changesets_count;
IF _done = 1 THEN
LEAVE loop_xxx;
END IF;
BEGIN
DECLARE total_count numeric(8, 2);
DECLARE news_id int(10);
DECLARE issues_id int(10);
DECLARE issues_count int(10);
DECLARE news_count int(10);
DECLARE time_entries_count int(10);
DECLARE documents_count int(10);
DECLARE issues_jour_count_total int(10) DEFAULT 0;
DECLARE issues_jour_count int(10);
DECLARE news_jour_count_total int(10) DEFAULT 0;
DECLARE news_jour_count int(10);
DECLARE boards_messages_count int(10);
DECLARE cur_user_id int(10);
DECLARE cur_user_issues_journals_count int(10);
DECLARE cur_user_news_journals_count int(10);
DECLARE cur_user_issues_count int(10);
DECLARE cur_user_news_count int(10);
DECLARE cur_user_issues_id int(10);
DECLARE cur_user_news_id int(10);
DECLARE _inner_done_one tinyint(1) DEFAULT 0;
DECLARE cur_issues CURSOR FOR
SELECT
issues.id
FROM issues
WHERE project_id = project_uid;
DECLARE cur_news CURSOR FOR
SELECT
news.id
FROM news
WHERE project_id = project_uid;
DECLARE cur_user CURSOR FOR
SELECT
members.user_id
FROM members
INNER JOIN users
ON members.user_id = users.id
WHERE members.project_id = project_uid
AND (users.type = 'User' AND users.status = 1);
DECLARE CONTINUE HANDLER FOR NOT FOUND SET _inner_done_one = 1;
OPEN cur_issues;
loop_issues:
LOOP
FETCH cur_issues INTO issues_id;
IF _inner_done_one = 1 THEN
LEAVE loop_issues;
END IF;
BEGIN
SELECT
COUNT(*) INTO issues_jour_count
FROM `journals`
WHERE `journals`.`journalized_id` = issues_id AND `journals`.`journalized_type` = 'Issue';
SET issues_jour_count_total = issues_jour_count_total + issues_jour_count;
END;
END LOOP;
-- CLOSE cur_issues;
SET _inner_done_one = 0;
OPEN cur_news;
loop_news:
LOOP
FETCH cur_news INTO news_id;
IF _inner_done_one = 1 THEN
LEAVE loop_news;
END IF;
BEGIN
SELECT
COUNT(*) INTO news_jour_count
FROM `journals`
WHERE `journals`.`journalized_id` = news_id AND `journals`.`journalized_type` = 'News';
SET news_jour_count_total = news_jour_count_total + news_jour_count;
END;
END LOOP;
-- CLOSE cur_news;
SET _inner_done_one = 0;
OPEN cur_user;
loop_user:
LOOP
FETCH cur_user INTO cur_user_id;
IF _inner_done_one = 1 THEN
LEAVE loop_user;
END IF;
BEGIN
DECLARE total_cur_user_issues_journals_count int(10) DEFAULT 0;
DECLARE total_cur_user_news_journals_count int(10) DEFAULT 0;
DECLARE cur_user_changesets_count INT(10);
DECLARE user_total_count numeric(8, 2);
DECLARE _inner_inner_done tinyint(1) DEFAULT 0;
DECLARE cur_user_issues CURSOR FOR
SELECT
issues.id
FROM issues
WHERE project_id = project_uid AND author_id = cur_user_id;
DECLARE cur_user_news CURSOR FOR
SELECT
news.id
FROM news
WHERE project_id = project_uid AND author_id = cur_user_id;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET _inner_inner_done = 1;
OPEN cur_user_issues;
loop_user_issues:
LOOP
FETCH cur_issues INTO cur_user_issues_id;
IF _inner_inner_done = 1 THEN
LEAVE loop_user_issues;
END IF;
BEGIN
SELECT
COUNT(*) INTO cur_user_issues_journals_count
FROM journals
WHERE journalized_id = cur_user_issues_id AND user_id = cur_user_id
AND journalized_type = 'Issues';
SET total_cur_user_issues_journals_count = total_cur_user_issues_journals_count +
cur_user_issues_journals_count;
END;
END LOOP;
-- CLOSE cur_user_issues;
SET _inner_inner_done = 0;
OPEN cur_user_news;
loop_user_news:
LOOP
FETCH cur_user_news INTO cur_user_news_id;
IF _inner_inner_done = 1 THEN
LEAVE loop_user_news;
END IF;
BEGIN
SELECT
COUNT(*) INTO cur_user_news_journals_count
FROM journals
WHERE journalized_id = cur_user_news_id AND user_id = cur_user_id AND journalized_type = 'News';
SET total_cur_user_news_journals_count = total_cur_user_news_journals_count +
cur_user_news_journals_count;
END;
END LOOP;
SELECT
COUNT(*) INTO cur_user_issues_count
FROM issues
WHERE project_id = project_uid AND author_id = cur_user_id;
SELECT
COUNT(*) INTO cur_user_news_count
FROM news
WHERE project_id = project_uid AND author_id = cur_user_id;
SELECT
COUNT(*) INTO cur_user_changesets_count
FROM changesets
WHERE user_id = cur_user_id AND
repository_id IN (SELECT
id
FROM repositories
WHERE project_id = project_uid);
SET user_total_count = cur_user_issues_count*0.2 +
cur_user_news_count*0.2 +
total_cur_user_issues_journals_count*0.1 +
total_cur_user_news_journals_count*0.1 +
cur_user_changesets_count*0.4;
UPDATE user_grades
SET grade = user_total_count
WHERE user_id = cur_user_id AND project_id = project_uid;
COMMIT;
END;
END LOOP;
SELECT
COUNT(*) INTO issues_count
FROM issues
WHERE project_id = project_uid;
SELECT
COUNT(*) INTO news_count
FROM news
WHERE project_id = project_uid;
SELECT
COUNT(*) INTO documents_count
FROM documents
WHERE project_id = project_uid;
SELECT
SUM(boards.messages_count) INTO boards_messages_count
FROM boards
WHERE project_id = project_uid;
IF boards_messages_count IS NULL THEN
SET boards_messages_count = 0;
SET total_count = issues_count * 0.2 +
issues_jour_count_total * 0.1 +
news_count * 0.1 +
news_jour_count_total * 0.1 +
documents_count * 0.1 +
project_changesets_count * 0.3 +
boards_messages_count * 0.1;
ELSE
SET total_count = issues_count * 0.2 +
issues_jour_count_total * 0.1 +
news_count * 0.1 +
news_jour_count_total * 0.1 +
documents_count * 0.1 +
project_changesets_count * 0.3 +
boards_messages_count * 0.1;
END IF;
IF total_count IS NOT NULL THEN
UPDATE project_statuses
SET changesets_count = project_changesets_count,
grade = total_count
WHERE project_id = project_uid;
ELSE
UPDATE project_statuses
SET changesets_count = project_changesets_count,
grade = 0
WHERE project_id = project_uid;
END IF;
COMMIT;
END;
END LOOP;
END;
"
execute "
create event if not exists e_project_status_test
on schedule every 1 day starts'2013_08_27 01:50:00'
on schedule every 1 day starts'2013-08-27 01:50:00'
on completion preserve
do call `sp_project_status_cursor`();
"

View File

@ -0,0 +1,5 @@
class AddGradeToProjectStatuses < ActiveRecord::Migration
def change
add_column :project_statuses, :grade, :float, :default => 0
end
end

View File

@ -0,0 +1,5 @@
class AddGradeToUserStatuses < ActiveRecord::Migration
def change
add_column :user_statuses, :grade, :float, :default => 0
end
end

View File

@ -0,0 +1,10 @@
class CreateUserGrades < ActiveRecord::Migration
def change
create_table :user_grades do |t|
t.integer :user_id, :null => false
t.integer :project_id, :null => false
t.float :grade, :default => 0
t.timestamps
end
end
end

View File

@ -0,0 +1,7 @@
class AddIndexToUserGrades < ActiveRecord::Migration
def change
add_index :user_grades, :grade
add_index :user_grades, :project_id
add_index :user_grades, :user_id
end
end

View File

@ -0,0 +1,5 @@
class AddMissingIndexToUserStatuses < ActiveRecord::Migration
def change
add_index :user_statuses, :grade
end
end

View File

@ -0,0 +1,5 @@
class AddMissingIndexToProjectStatuses < ActiveRecord::Migration
def change
add_index :project_statuses, :grade
end
end

View File

@ -0,0 +1,5 @@
class AddDescriptionToShare < ActiveRecord::Migration
def change
add_column :shares, :description, :string
end
end

View File

@ -11,15 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20131009074454) do
create_table "a_user_watchers", :force => true do |t|
t.string "name"
t.text "description"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.integer "member_id"
end
ActiveRecord::Schema.define(:version => 20131021024144) do
create_table "activities", :force => true do |t|
t.integer "act_id", :null => false
@ -289,7 +281,7 @@ ActiveRecord::Schema.define(:version => 20131009074454) do
create_table "issue_relations", :force => true do |t|
t.integer "issue_from_id", :null => false
t.integer "issue_to_id", :null => false
t.string "relation_type", :null => false
t.string "relation_type", :default => "", :null => false
t.integer "delay"
end
@ -431,22 +423,6 @@ ActiveRecord::Schema.define(:version => 20131009074454) do
add_index "messages", ["last_reply_id"], :name => "index_messages_on_last_reply_id"
add_index "messages", ["parent_id"], :name => "messages_parent_id"
create_table "messages_for_bids", :force => true do |t|
t.string "message"
t.integer "user_id"
t.integer "bid_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "messages_for_users", :force => true do |t|
t.integer "messager_id"
t.integer "user_id"
t.string "message"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "news", :force => true do |t|
t.integer "project_id"
t.string "title", :limit => 60, :default => "", :null => false
@ -506,19 +482,10 @@ ActiveRecord::Schema.define(:version => 20131009074454) do
t.integer "watchers_count"
t.integer "project_id"
t.integer "project_type"
t.float "grade", :default => 0.0
end
add_index "project_statuses", ["changesets_count"], :name => "index_project_statuses_on_changesets_count"
add_index "project_statuses", ["watchers_count"], :name => "index_project_statuses_on_watchers_count"
create_table "project_tags", :force => true do |t|
t.integer "project_id"
t.integer "tag_id"
t.string "description"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.integer "user_id"
end
add_index "project_statuses", ["grade"], :name => "index_project_statuses_on_grade"
create_table "projects", :force => true do |t|
t.string "name", :default => "", :null => false
@ -587,6 +554,26 @@ ActiveRecord::Schema.define(:version => 20131009074454) do
t.string "issues_visibility", :limit => 30, :default => "default", :null => false
end
create_table "seems_rateable_cached_ratings", :force => true do |t|
t.integer "cacheable_id", :limit => 8
t.string "cacheable_type"
t.float "avg", :null => false
t.integer "cnt", :null => false
t.string "dimension"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "seems_rateable_rates", :force => true do |t|
t.integer "rater_id", :limit => 8
t.integer "rateable_id"
t.string "rateable_type"
t.float "stars", :null => false
t.string "dimension"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "settings", :force => true do |t|
t.string "name", :default => "", :null => false
t.text "value"
@ -597,9 +584,9 @@ ActiveRecord::Schema.define(:version => 20131009074454) do
create_table "shares", :force => true do |t|
t.date "created_on"
t.string "title"
t.string "share_type"
t.string "url"
t.string "title"
t.integer "share_type"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.integer "project_id"
@ -607,12 +594,6 @@ ActiveRecord::Schema.define(:version => 20131009074454) do
t.string "description"
end
create_table "students", :force => true do |t|
t.string "name"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "students_for_courses", :force => true do |t|
t.integer "student_id"
t.integer "course_id"
@ -671,7 +652,7 @@ ActiveRecord::Schema.define(:version => 20131009074454) do
create_table "tokens", :force => true do |t|
t.integer "user_id", :default => 0, :null => false
t.string "action", :limit => 30, :default => "", :null => false
t.string "value", :limit => 40
t.string "value", :limit => 40, :default => "", :null => false
t.datetime "created_on", :null => false
end
@ -697,14 +678,26 @@ ActiveRecord::Schema.define(:version => 20131009074454) do
t.integer "zip_code"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.integer "identity"
t.string "technical_title"
t.integer "identity"
t.string "student_id"
t.string "teacher_realname"
t.string "student_realname"
t.string "location_city"
end
create_table "user_grades", :force => true do |t|
t.integer "user_id", :null => false
t.integer "project_id", :null => false
t.float "grade", :default => 0.0
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
add_index "user_grades", ["grade"], :name => "index_user_grades_on_grade"
add_index "user_grades", ["project_id"], :name => "index_user_grades_on_project_id"
add_index "user_grades", ["user_id"], :name => "index_user_grades_on_user_id"
create_table "user_preferences", :force => true do |t|
t.integer "user_id", :default => 0, :null => false
t.text "others"
@ -720,19 +713,13 @@ ActiveRecord::Schema.define(:version => 20131009074454) do
t.integer "user_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.float "grade", :default => 0.0
end
add_index "user_statuses", ["changesets_count"], :name => "index_user_statuses_on_changesets_count"
add_index "user_statuses", ["grade"], :name => "index_user_statuses_on_grade"
add_index "user_statuses", ["watchers_count"], :name => "index_user_statuses_on_watchers_count"
create_table "user_tags", :force => true do |t|
t.integer "user_id"
t.integer "tag_id"
t.string "description"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "users", :force => true do |t|
t.string "login", :default => "", :null => false
t.string "hashed_password", :limit => 40, :default => "", :null => false

View File

@ -0,0 +1,68 @@
<div class="content_frame">
<% if @memberships.empty? %>
<% if @user != User.current %>
<p class="font_description">
<%= l(:label_project_course_un) %>
</p>
<% else %>
<p class="font_description">
<%= l(:label_project_course_unadd) %>
<% if User.current.user_extensions.identity == 0 %>
<%= link_to"#{l(:label_course_new)}",{:controller=>'projects',:action=>'new', :course => 1}, :class => 'icon icon-add' %>
<% end %>
</p>
<% end %>
<% else %>
<% if User.current.user_extensions.identity == 0 %>
<%= link_to"#{l(:label_course_new)}",{:controller=>'projects',:action=>'new', :course => 1}, :class => 'icon icon-add' %>
<% end %>
<ul class="user_project_sort">
<% for membership in @memberships %>
<li>
<table width="660" border="0" align="center" style="border-bottom: 1px dashed rgb(204, 204, 204); margin-bottom: 10px;font-size:14px;">
<tr>
<td colspan="2" valign="top" width="50" ><% if get_avatar?(membership.project)%>
<%= link_to image_tag(url_to_avatar(membership.project), :class => 'avatar'), project_path(membership.project) %>
<% else %>
<%= link_to image_tag('../images/avatars/Project/course.jpg', :class => "avatar"), project_path(membership.project)%>
<% end %></td>
<td>
<table width="580" border="0">
<tr>
<td colspan="2" valign="top"><span><%= link_to_project(membership.project) %></span>
<span style="float: right"><%= l(:label_homework) %> (<span class=""><%= link_to (membership.project.homeworks.count), {:controller => 'projects', :action => 'homework', :id => membership.project.identifier} %></span>)
&nbsp;&nbsp;&nbsp;
<%= l(:label_course_news)%> (<span style="color: #ed8924"><%= link_to (membership.project.news.count), {:controller => 'news', :action => 'index', :project_id => membership.project.identifier} %></span>)
<!-- <%= l(:label_member)%>(<span style="color: #ed8924"><%= link_to (membership.project.members.count), {:controller => 'news', :action => 'index', :project_id => membership.project.identifier} %></span>) </span> --></td>
</tr>
<tr>
<td colspan="2" width="580" >
<p class="font_description">
<%= membership.project.description%>
</p></td>
</tr>
<tr>
<td align="left"><span class="font_lighter"> <%= format_time(membership.created_on) %></span></td><!-- modified by ming -->
<td align="right" >
<% if membership.roles.sort.collect(&:to_s).join(', ') =='Manager' %>
Teacher
<% elsif membership.roles.sort.collect(&:to_s).join(', ') =='Reporter' %>
Student
<% elsif membership.roles.sort.collect(&:to_s).join(', ') =='TA' %>
TA
<% end %>
</td>
</tr>
</table></td>
</tr>
</table>
</li>
<% end %>
</ul>
<% end %>
<%= call_hook :view_account_left_bottom, :user => @user %>
</div>

View File

@ -1877,9 +1877,13 @@ a.font-user-after-color{
height:25px;
line-height:23px;
}
/*end*/
.create-share{
div.avatar_user{
position: relative;
float:left;
margin-top:-30px;
margin-left: 550px;
}.create-share{
border-radius: 5px;
padding-top: 3px;
margin-top: 5px;