diff --git a/app/controllers/bids_controller.rb b/app/controllers/bids_controller.rb index 9e51a8598..f2e197cd8 100644 --- a/app/controllers/bids_controller.rb +++ b/app/controllers/bids_controller.rb @@ -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 { diff --git a/app/controllers/members_controller.rb b/app/controllers/members_controller.rb index fadeec3e0..940172e9c 100644 --- a/app/controllers/members_controller.rb +++ b/app/controllers/members_controller.rb @@ -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 diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 783e8222a..b7427b1e9 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -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| diff --git a/app/controllers/shares_controller.rb b/app/controllers/shares_controller.rb index e019af505..953274b39 100644 --- a/app/controllers/shares_controller.rb +++ b/app/controllers/shares_controller.rb @@ -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 diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index f9d4a30ea..2998eb2a1 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -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 @@ -559,6 +561,22 @@ class UsersController < ApplicationController @auth_sources = AuthSource.all @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] diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 571eb0b81..0db12e244 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -254,11 +254,13 @@ module ApplicationHelper s << "" end if @project.project_type == 1 - unless Course.find_by_extra(@project.identifier).tea_id == User.current.id + unless Course.find_by_extra(@project.identifier).nil? + unless Course.find_by_extra(@project.identifier).tea_id == User.current.id s << "" s << join_in_course(@project, User.current)#, ['whiteButton']) s << "" end + end end s << (render :partial => 'projects/project', :locals => {:project => project}).to_s s << "\n" diff --git a/app/models/project.rb b/app/models/project.rb index e45c8dc29..9e5c2f663 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -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) } diff --git a/app/models/user.rb b/app/models/user.rb index 2d6b59082..36bcd0d06 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 @@ -774,4 +777,4 @@ class AnonymousUser < User def destroy false end -end +end \ No newline at end of file diff --git a/app/models/user_grade.rb b/app/models/user_grade.rb new file mode 100644 index 000000000..f79fcd2c6 --- /dev/null +++ b/app/models/user_grade.rb @@ -0,0 +1,4 @@ +class UserGrade < ActiveRecord::Base + # attr_accessible :title, :body + belongs_to :project +end diff --git a/app/models/watcher.rb b/app/models/watcher.rb index 853e0cf6b..f700e62ac 100644 --- a/app/models/watcher.rb +++ b/app/models/watcher.rb @@ -26,7 +26,10 @@ 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={}) if options.has_key?(:user) diff --git a/app/views/bids/_list_projects.html.erb b/app/views/bids/_list_projects.html.erb index 42812a5fa..06a7a85f3 100644 --- a/app/views/bids/_list_projects.html.erb +++ b/app/views/bids/_list_projects.html.erb @@ -8,12 +8,14 @@
<%= link_to image_tag(url_to_avatar(b_project.project), :class => 'avatar3'), :class => "avatar" %> +
@@ -21,7 +23,7 @@
<%= link_to(b_project.project.name, project_path(b_project.project)) %> + <%= l(:label_join_bidding)%> - + <%= 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)%> diff --git a/app/views/bids/_project_list.html.erb b/app/views/bids/_project_list.html.erb index 5c99fdce1..25f0ef452 100644 --- a/app/views/bids/_project_list.html.erb +++ b/app/views/bids/_project_list.html.erb @@ -1,11 +1,13 @@ <%= render_flash_messages %> -<% if @bid.reward_type == 3 %> +<% if @bid.reward_type == 3 %> + <% unless User.current.nil?%> <% if User.current.user_extensions.identity == 1 %>

<%= l(:label_homework_prompt) %>

<%= l(:label_homework_prompt_content) %>

+ <% end %> <% end %> diff --git a/app/views/projects/_project.html.erb b/app/views/projects/_project.html.erb index ad750fe94..0a4f0b0e7 100644 --- a/app/views/projects/_project.html.erb +++ b/app/views/projects/_project.html.erb @@ -87,19 +87,12 @@
<%= content_tag('span', "#{l(:label_create_time)}: ") %><%= content_tag('span', format_time(@project.created_on)) %>
+
+ <%= content_tag('span', "#{l(:label_project_grade)}: ")%><%= @project.project_status.grade%> +
- - diff --git a/app/views/projects/member.html.erb b/app/views/projects/member.html.erb index f0b94c6eb..a3cd24cee 100644 --- a/app/views/projects/member.html.erb +++ b/app/views/projects/member.html.erb @@ -4,16 +4,29 @@ <%= 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| %>
- <% next if member.new_record? %> - <% unless member.created_on.nil? %> + <% next if member.new_record? %> + <% unless member.created_on.nil? %> <%= content_tag "p", "#{format_date(member.created_on)}#{l(:label_member_since)}", :class => "float_right member_since" %> <% 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" %> + <% if @project.project_type == 1 %>

@@ -26,9 +39,17 @@ <% else %> <% end %> -

+

+
<% 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]%> +
+

<%= l(:label_user_for_project_grade) %>: <%= user[:grade] %>

+
+ <% end %> + <% end %> <% end %> <%= call_hook(:view_projects_settings_members_table_row, { :project => @project, :member => member}) %> @@ -40,4 +61,6 @@ <%= l(:label_no_data) %>

<% end %> - \ No newline at end of file + + + diff --git a/app/views/projects/search.html.erb b/app/views/projects/search.html.erb index 8671d5add..195e49618 100644 --- a/app/views/projects/search.html.erb +++ b/app/views/projects/search.html.erb @@ -28,25 +28,13 @@ <%end%> - +
<%= render_project_hierarchy(@projects)%>
- +
<%= l(:label_homework_project) %>(<%= bidding_project.count%>)
+ <%= l(:label_watch_project) %> <%= link_to_project(membership.project) %>
<%= link_to_user(membership.user) if membership.respond_to?(:user) %> - <%= l(:label_create_project) %> <%= link_to_project(membership.project) %>
diff --git a/app/views/users/watch_projects.html.erb b/app/views/users/watch_projects.html.erb new file mode 100644 index 000000000..de8f19c20 --- /dev/null +++ b/app/views/users/watch_projects.html.erb @@ -0,0 +1,34 @@ +

<%= 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) %>

+<% end %> +<% unless @watch_projects.nil?&&watch_projects.project.nil? %> +<% for watch_project in @watch_projects %> + + + + + + +
<%= link_to image_tag(url_to_avatar(watch_project.project), :class => 'avatar'), project_path(watch_project.project) %> + + + + + + + + + + +
<%= link_to_user(@user) if watch_project.respond_to?(:user) %> + <%= @user.name%><%= l(:label_watch_project) %> <%= link_to_project(watch_project.project) %>
+

+ <%= watch_project.project.description%> +

<%= format_time(watch_project.created_on) %>
+ + + <% end %> + <% else %> + 还米有关注任何项目 + <% end %> diff --git a/config/locales/zh.yml b/config/locales/zh.yml index 36cfc40c3..e592e170f 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -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: 关注了 \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index e95564712..6b2bee154 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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] @@ -128,6 +131,7 @@ RedmineApp::Application.routes.draw do # Specific routes for issue watchers API 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 diff --git a/db/migrate/20130828004955_stored_status_procedure.rb b/db/migrate/20130828004955_stored_status_procedure.rb index 29a752765..a27a6b97d 100644 --- a/db/migrate/20130828004955_stored_status_procedure.rb +++ b/db/migrate/20130828004955_stored_status_procedure.rb @@ -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`(); " diff --git a/db/migrate/20131017080750_add_grade_to_project_statuses.rb b/db/migrate/20131017080750_add_grade_to_project_statuses.rb new file mode 100644 index 000000000..10758617c --- /dev/null +++ b/db/migrate/20131017080750_add_grade_to_project_statuses.rb @@ -0,0 +1,5 @@ +class AddGradeToProjectStatuses < ActiveRecord::Migration + def change + add_column :project_statuses, :grade, :float, :default => 0 + end +end diff --git a/db/migrate/20131017120541_add_grade_to_user_statuses.rb b/db/migrate/20131017120541_add_grade_to_user_statuses.rb new file mode 100644 index 000000000..150a9607f --- /dev/null +++ b/db/migrate/20131017120541_add_grade_to_user_statuses.rb @@ -0,0 +1,5 @@ +class AddGradeToUserStatuses < ActiveRecord::Migration + def change + add_column :user_statuses, :grade, :float, :default => 0 + end +end diff --git a/db/migrate/20131017131615_create_user_grades.rb b/db/migrate/20131017131615_create_user_grades.rb new file mode 100644 index 000000000..e207b3eec --- /dev/null +++ b/db/migrate/20131017131615_create_user_grades.rb @@ -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 diff --git a/db/migrate/20131017135933_add_index_to_user_grades.rb b/db/migrate/20131017135933_add_index_to_user_grades.rb new file mode 100644 index 000000000..02cb9b3f2 --- /dev/null +++ b/db/migrate/20131017135933_add_index_to_user_grades.rb @@ -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 diff --git a/db/migrate/20131017140104_add_missing_index_to_user_statuses.rb b/db/migrate/20131017140104_add_missing_index_to_user_statuses.rb new file mode 100644 index 000000000..ccbb54de8 --- /dev/null +++ b/db/migrate/20131017140104_add_missing_index_to_user_statuses.rb @@ -0,0 +1,5 @@ +class AddMissingIndexToUserStatuses < ActiveRecord::Migration + def change + add_index :user_statuses, :grade + end +end diff --git a/db/migrate/20131017140123_add_missing_index_to_project_statuses.rb b/db/migrate/20131017140123_add_missing_index_to_project_statuses.rb new file mode 100644 index 000000000..61b184480 --- /dev/null +++ b/db/migrate/20131017140123_add_missing_index_to_project_statuses.rb @@ -0,0 +1,5 @@ +class AddMissingIndexToProjectStatuses < ActiveRecord::Migration + def change + add_index :project_statuses, :grade + end +end diff --git a/db/migrate/20131021024144_add_description_to_share.rb b/db/migrate/20131021024144_add_description_to_share.rb new file mode 100644 index 000000000..1ac25a9b4 --- /dev/null +++ b/db/migrate/20131021024144_add_description_to_share.rb @@ -0,0 +1,5 @@ +class AddDescriptionToShare < ActiveRecord::Migration + def change + add_column :shares, :description, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index fcd95793e..7b97e6911 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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 @@ -287,9 +279,9 @@ ActiveRecord::Schema.define(:version => 20131009074454) do add_index "issue_categories", ["project_id"], :name => "issue_categories_project_id" 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.integer "issue_from_id", :null => false + t.integer "issue_to_id", :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" @@ -718,21 +711,15 @@ ActiveRecord::Schema.define(:version => 20131009074454) do t.integer "changesets_count" t.integer "watchers_count" t.integer "user_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + 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 diff --git a/files/2013/10/131007102834__my_course.html.erb b/files/2013/10/131007102834__my_course.html.erb new file mode 100644 index 000000000..19acd49ac --- /dev/null +++ b/files/2013/10/131007102834__my_course.html.erb @@ -0,0 +1,68 @@ +
+ <% if @memberships.empty? %> + <% if @user != User.current %> +

+ <%= l(:label_project_course_un) %> +

+ <% else %> +

+ <%= 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 %> +

+ <% 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 %> +
    + <% for membership in @memberships %> +
  • + + + + + + +
    <% 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 %> + + + + + + + + + + + +
    <%= link_to_project(membership.project) %> + <%= l(:label_homework) %> (<%= link_to (membership.project.homeworks.count), {:controller => 'projects', :action => 'homework', :id => membership.project.identifier} %>) +     + <%= l(:label_course_news)%> (<%= link_to (membership.project.news.count), {:controller => 'news', :action => 'index', :project_id => membership.project.identifier} %>) +
    +

    + <%= membership.project.description%> +

    <%= format_time(membership.created_on) %> + + <% 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 %> +
    + +
  • + <% end %> +
+ + <% end %> + <%= call_hook :view_account_left_bottom, :user => @user %> +
diff --git a/lib/redmine/activity/fetcher.rb b/lib/redmine/activity/fetcher.rb index 58424bb66..c2e174ef2 100644 --- a/lib/redmine/activity/fetcher.rb +++ b/lib/redmine/activity/fetcher.rb @@ -56,7 +56,7 @@ module Redmine when :default default_scope! else - @scope = s & event_types + @scope = s & event_types end end @@ -70,7 +70,7 @@ module Redmine def events(from = nil, to = nil, options={}) e = [] @options[:limit] = options[:limit] - + @scope.each do |event_type| constantized_providers(event_type).each do |provider| e += provider.find_events(event_type, @user, from, to, @options) diff --git a/public/themes/redpenny-master/stylesheets/application.css b/public/themes/redpenny-master/stylesheets/application.css index ebd19e8bb..0f1e8781e 100644 --- a/public/themes/redpenny-master/stylesheets/application.css +++ b/public/themes/redpenny-master/stylesheets/application.css @@ -1877,11 +1877,15 @@ 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; margin-bottom: 5px; -} +} \ No newline at end of file