diff --git a/ReadMe.txt b/ReadMe.txt index 7e8af4e21..538457d3d 100644 --- a/ReadMe.txt +++ b/ReadMe.txt @@ -81,3 +81,10 @@ kw: 默认支持如下格式:"bmp,jpeg,jpg,png,gif" 可在configuration.yml中修改,格式:pic_types: "bmp,jpeg,jpg,png,gif"(注意:pic_types若前面有#号需去掉) 配置完成后重启服务 + +=================================[2014-08-16]==================================== +kw:数据迁移,project_scores表已存在 +bundle exec rake db:migrate:down VERSION=20140811022947 +bundle exec rake db:migrate:up VERSION=20140811022947 +bundle exec rake db:migrate +bundle exec rake project_score:calculate diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 178a82d17..4f731e580 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -279,7 +279,7 @@ class ApplicationController < ActionController::Base # Find project of id params[:id] def find_project - @project = Project.find(params[:id]) + @project = Project.find_by_id(params[:id]) rescue ActiveRecord::RecordNotFound render_404 end diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 44d68de26..c58cd3f82 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -79,7 +79,7 @@ class AttachmentsController < ApplicationController else candown = @attachment.is_public == 1 end - if candown || User.current.admin? + if candown || User.current.admin? || User.current.id == @attachment.author_id @attachment.increment_download if stale?(:etag => @attachment.digest) diff --git a/app/controllers/bids_controller.rb b/app/controllers/bids_controller.rb index be27a71ea..047f7103e 100644 --- a/app/controllers/bids_controller.rb +++ b/app/controllers/bids_controller.rb @@ -488,6 +488,11 @@ class BidsController < ApplicationController if @bid.homework_type @homework = HomeworkAttach.new + if @bid.proportion + teacher_proportion = @bid.proportion * 1.0 / 100 + else + teacher_proportion = 1.0 + end #@homework_list = @bid.homeworks #澧炲姞浣滀笟鎸夎瘎鍒嗘帓搴忥紝 #@homework_list = @bid.homeworks.eager_load(:rate_averages, :user, :attachments).order('seems_rateable_cached_ratings.avg DESC').order("#{HomeworkAttach.table_name}.created_at ASC") @@ -495,7 +500,7 @@ class BidsController < ApplicationController (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id = #{@bid.author_id}) AS t_score, (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id <> #{@bid.author_id}) AS s_score FROM homework_attaches WHERE bid_id = #{@bid.id} ORDER BY - (CASE WHEN t_score IS NULL THEN 0 ELSE t_score * #{@bid.proportion * 1.0 / 100} END + CASE WHEN s_score IS NULL THEN 0 ELSE s_score * #{1 - @bid.proportion * 1.0 / 100} END) DESC,created_at ASC") + (CASE WHEN t_score IS NULL THEN 0 ELSE t_score * #{teacher_proportion} END + CASE WHEN s_score IS NULL THEN 0 ELSE s_score * #{1 - teacher_proportion} END) DESC,created_at ASC") if params[:student_id].present? @temp = [] @homework_list.each do |pro| diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index c80ce6d69..666c39d30 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -38,6 +38,17 @@ class FilesController < ApplicationController @isproject = true @containers = [ Project.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").find(@project.id)] @containers += @project.versions.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").all.sort + + all_attachments = [] + @containers.each do |container| + all_attachments += container.attachments + end + @limit = 10 + @feedback_count = all_attachments.count + @feedback_pages = Paginator.new @feedback_count, @limit, params['page'] + @offset ||= @feedback_pages.offset + @curse_attachments = all_attachments[@offset, @limit] + render :layout => !request.xhr? elsif params[:course_id] @isproject = false @@ -67,6 +78,18 @@ class FilesController < ApplicationController else @containers = [ Course.includes(:attachments).reorder("#{Attachment.table_name}.created_on desc").find(@course.id)] end + + all_attachments = [] + @containers.each do |container| + all_attachments += container.attachments + end + + @limit = 10 + @feedback_count = all_attachments.count + @feedback_pages = Paginator.new @feedback_count, @limit, params['page'] + @offset ||= @feedback_pages.offset + @curse_attachments = all_attachments[@offset, @limit] + render :layout => 'base_courses' end end diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index e840664b4..cdeb17e54 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -103,7 +103,11 @@ class MessagesController < ApplicationController # Edit a message def edit - (render_403; return false) unless @message.editable_by?(User.current) + if @project + (render_403; return false) unless @message.editable_by?(User.current) + else + (render_403; return false) unless @message.course_editable_by?(User.current) + end @message.safe_attributes = params[:message] if request.post? && @message.save attachments = Attachment.attach_files(@message, params[:attachments]) @@ -124,7 +128,11 @@ class MessagesController < ApplicationController # Delete a messages def destroy - (render_403; return false) unless @message.destroyable_by?(User.current) + if @project + (render_403; return false) unless @message.destroyable_by?(User.current) + else + (render_403; return false) unless @message.course_destroyable_by?(User.current) + end r = @message.to_param @message.destroy # modify by nwb diff --git a/app/controllers/news_controller.rb b/app/controllers/news_controller.rb index 9437889b2..e564bc940 100644 --- a/app/controllers/news_controller.rb +++ b/app/controllers/news_controller.rb @@ -148,7 +148,8 @@ class NewsController < ApplicationController flash[:notice] = l(:notice_successful_update) redirect_to news_path(@news) else - render :action => 'edit' + #flash[:error] = l(:notice_successful_update) + redirect_to news_path(@news) end end diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index ccbff8e50..1893224f8 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -403,21 +403,35 @@ class ProjectsController < ApplicationController #Ended by young def feedback - page = params[:page] + @page = params[:page] + @page = @page.to_i # Find the page of the requested reply @jours = @project.journals_for_messages.where('m_parent_id IS NULL').order('created_on DESC') - @limit = 10 - if params[:r] && page.nil? - offset = @jours.count(:conditions => ["#{JournalsForMessage.table_name}.id > ?", params[:r].to_i]) - page = 1 + offset / @limit + @limit = 3 + + offset = @jours.count(:conditions => ["#{JournalsForMessage.table_name}.id > ?", params[:r].to_i]) + page = 1 + offset / @limit + if params[:r] && @page.nil? + @page = page end - + + puts @page + if @page < 0 + @page = 1 + end + if @page > page + @page = page + end + + @feedback_count = @jours.count - @feedback_pages = Paginator.new @feedback_count, @limit, page + @feedback_pages = Paginator.new @feedback_count, @limit, @page @offset ||= @feedback_pages.offset @jour = @jours[@offset, @limit] @state = false @base_courses_tag = @project.project_type + + respond_to do |format| format.html{render :layout => 'base_courses' if @base_courses_tag==1} format.api @@ -683,8 +697,8 @@ class ProjectsController < ApplicationController else # @project.project_type == Project::ProjectType_project roles = Role.find_all_givable @subPage_title = l :label_member_list - @members = @project.member_principals.includes(:roles, :principal).all - @members = sort_project_members(@project, @members) + @members = @project.member_principals.includes(:roles, :principal).joins("LEFT JOIN #{OptionNumber.table_name} ON #{OptionNumber.table_name}.user_id = #{Member.table_name}.user_id and #{OptionNumber.table_name}.score_type = 2 AND #{Member.table_name}.project_id = #{OptionNumber.table_name}.project_id").order("#{OptionNumber.table_name}.total_score DESC").all + #@members = sort_project_members(@project, @members) @applied_members = appied_project_members(@project, @members) end @members = paginateHelper @members diff --git a/app/controllers/words_controller.rb b/app/controllers/words_controller.rb index 110f81537..e31bb2738 100644 --- a/app/controllers/words_controller.rb +++ b/app/controllers/words_controller.rb @@ -88,7 +88,44 @@ class WordsController < ApplicationController #format.api { render_api_ok } end end - + + def destroyJournal + + @journalP=JournalsForMessage.find(params[:object_id]) + @journalP.destroy + + @page = params[:page] + @page = @page.to_i + @project = Project.find params[:project_id] + # Find the page of the requested reply + @jours = @project.journals_for_messages.where('m_parent_id IS NULL').order('created_on DESC') + @limit = 3 + + offset = @jours.count(:conditions => ["#{JournalsForMessage.table_name}.id > ?", params[:r].to_i]) + page = 1 + offset / @limit + if params[:r] && @page.nil? + @page = page + end + + if @page < 0 + @page = 1 + end + if @page > page + @page = page + end + + @feedback_count = @jours.count + @feedback_pages = Paginator.new @feedback_count, @limit, @page + @offset ||= @feedback_pages.offset + @jour = @jours[@offset, @limit] + @state = false + @base_courses_tag = @project.project_type + + respond_to do |format| + format.js + end + end + def new @jour = JournalsForMessage.find(params[:journal_id]) if params[:journal_id] if @jour diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 4d8b53e3c..7f38d8db9 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1442,6 +1442,8 @@ module ApplicationHelper email = $1 end return gravatar(email.to_s.downcase, options) unless email.blank? rescue nil + #options ={"class" => ["avatar2"],"width" =>["80px"],"height" =>["80px"]} + #return image_tag url_to_avatar(user), options else '' end diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index aad350d22..e08e50e80 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -441,7 +441,7 @@ module CoursesHelper def homework_user_of_homework homework,is_teacher homework_users = "" homework.users.each do |user| - homework_users = homework_users + (is_teacher ? user.realname : user.name) + homework_users = homework_users + (is_teacher ? (user.firstname + user.lastname) : user.login) if user != homework.users.last homework_users = homework_users + "銆" end diff --git a/app/helpers/project_score_helper.rb b/app/helpers/project_score_helper.rb index 07b0ee921..bdb070cc2 100644 --- a/app/helpers/project_score_helper.rb +++ b/app/helpers/project_score_helper.rb @@ -16,7 +16,7 @@ module ProjectScoreHelper end #鏂囨。鏁伴噺 - def document_num project + def documents_num project project.documents.count end @@ -48,8 +48,8 @@ module ProjectScoreHelper end #鏂囨。寰楀垎 - def document_score project - d_num = document_num project + def documents_score project + d_num = documents_num(project) d_num * 4 end @@ -67,7 +67,7 @@ module ProjectScoreHelper #璁$畻椤圭洰寰楀垎 def project_scores project - result = (issue_score project) + (news_score project) + (document_score project) + (changesets_score project) + (board_message_score project) + result = (issue_score project) + (news_score project) + (documents_score project) + (changesets_score project) + (board_message_score project) pss = ProjectScore.where("project_id = '#{project.id}'") if pss.nil? || pss.count == 0 ps = ProjectScore.new diff --git a/app/helpers/user_score_helper.rb b/app/helpers/user_score_helper.rb index 38f4f91f0..376f676b7 100644 --- a/app/helpers/user_score_helper.rb +++ b/app/helpers/user_score_helper.rb @@ -381,9 +381,52 @@ module UserScoreHelper result end + def get_option_num_by_id(user_id,type,project_id=nil) + if project_id.nil? + option_number = OptionNumber.where("user_id = '#{user_id}' and score_type = '#{type}'"); + else + option_number = OptionNumber.where("user_id = '#{user_id}' and score_type = '#{type}' and project_id = '#{project_id}'"); + end + + result = nil + if option_number.nil? || option_number.count == 0 + result = OptionNumber.new + result.user_id = user_id + result.memo = 0 + result.messages_for_issues = 0 + result.issues_status = 0 + result.replay_for_message = 0 + result.replay_for_memo = 0 + result.follow = 0 + result.tread = 0 + result.praise_by_one = 0 + result.praise_by_two = 0 + result.praise_by_three = 0 + result.tread_by_one = 0 + result.tread_by_two = 0 + result.tread_by_three = 0 + result.changeset = 0 + result.document = 0 + result.attachment = 0 + result.issue_done_ratio = 0 + result.post_issue = 0 + result.total_score = 0 + result.score_type =type + unless project_id.nil? + result.project_id = project_id + end + else + result = option_number.first + end + result + end + #鏇存柊鍒嗘暟 def update_score(option_number) option_number.total_score = collaboration(option_number) + influence(option_number) + skill(option_number) + active(option_number) + if option_number.total_score < 0 + option_number.total_score = 0 + end option_number.save option_number.total_score end @@ -415,11 +458,24 @@ module UserScoreHelper #鍙戝笘鏁 def memo_num(user,project=nil) if project.nil? - Message.includes(:author).joins(:board).where("#{Message.table_name}.parent_id IS NULL and #{Message.table_name}.author_id = '#{user.id}' and #{Board.table_name}.project_id != -1").all.count #+ Memo.includes(:author).where("parent_id IS NULL and author_id = '#{user.id}'").all.count - + #Message.includes(:author).joins(:board).where("#{Message.table_name}.parent_id IS NULL and #{Message.table_name}.author_id = '#{user.id}' and #{Board.table_name}.project_id != -1").all.count #+ Memo.includes(:author).where("parent_id IS NULL and author_id = '#{user.id}'").all.count + users = Message.find_by_sql("SELECT COUNT(*) as m_count FROM `messages` JOIN `boards` ON boards.project_id != -1 AND messages.board_id = boards.id +WHERE messages.parent_id IS NULL AND messages.author_id = #{user.id}") + result = 0 + users.each do |user| + result = user.m_count + end + result #user.messages.where("parent_id IS NULL").count else - Message.includes(:author).joins(:board).where("#{Message.table_name}.parent_id IS NULL and #{Message.table_name}.author_id = '#{user.id}' and #{Board.table_name}.project_id = #{project.id}").all.count + #Message.includes(:author).joins(:board).where("#{Message.table_name}.parent_id IS NULL and #{Message.table_name}.author_id = '#{user.id}' and #{Board.table_name}.project_id = #{project.id}").all.count + users = Message.find_by_sql("SELECT COUNT(*) as m_count FROM `messages` JOIN `boards` ON boards.project_id = '#{project.id}' AND messages.board_id = boards.id +WHERE messages.parent_id IS NULL AND messages.author_id = #{user.id}") + result = 0 + users.each do |user| + result = user.m_count + end + result end end @@ -438,16 +494,28 @@ FROM `users` where id = #{user.id}") #鏇存柊瀵圭己闄风暀瑷鏁 def update_messges_for_issue(user,type,project=nil) - option_number = get_option_number(user,type) + option_number = get_option_number(user,type,project) option_number.messages_for_issues = messges_for_issue_num(user,project)#Journal.includes(:user).where("user_id = '#{user.id}' and notes != '' and notes is not null").all.count update_score(option_number) end def messges_for_issue_num(user,project=nil) if project.nil? - Journal.includes(:user).where("user_id = '#{user.id}' and notes is not null and notes != ''").all.count + #Journal.includes(:user).where("user_id = '#{user.id}' and notes is not null and notes != ''").all.count + users = Journal.find_by_sql("SELECT COUNT(*) as m_count FROM journals WHERE journals.user_id = #{user.id} AND journals.notes IS NOT NULL AND journals.notes != ''") + result = 0 + if users.count > 0 + result = users.first.m_count + end + result else - Journal.includes(:user).joins(:issue).where("#{Journal.table_name}.user_id = '#{user.id}' and #{Issue.table_name}.project_id = '#{project.id}' and #{Journal.table_name}.notes != '' and #{Journal.table_name}.notes is not null").all.count + #Journal.includes(:user).joins(:issue).where("#{Journal.table_name}.user_id = '#{user.id}' and #{Issue.table_name}.project_id = '#{project.id}' and #{Journal.table_name}.notes != '' and #{Journal.table_name}.notes is not null").all.count + users = Journal.find_by_sql("SELECT COUNT(*) as m_count FROM journals join issues on #{Journal.table_name}.journalized_type = 'Issue' and #{Journal.table_name}.journalized_id = #{Issue.table_name}.id WHERE journals.user_id = #{user.id} AND journals.notes IS NOT NULL AND journals.notes != ''and #{Issue.table_name}.project_id = '#{project.id}'") + result = 0 + if users.count > 0 + result = users.first.m_count + end + result end end @@ -461,16 +529,28 @@ FROM `users` where id = #{user.id}") #鏇存柊鏇存敼缂洪櫡鐘舵佺姸鎬佹鏁 def update_issues_status(user,type,project=nil) - option_number = get_option_number(user,type) + option_number = get_option_number(user,type,project) option_number.issues_status = issues_status_num(user,project)#Journal.joins(:details, :user).where("#{JournalDetail.table_name}.prop_key = 'status_id' and #{User.table_name}.id = '#{user.id}'").count update_score(option_number) end def issues_status_num(user,project=nil) if project.nil? - Journal.joins(:details, :user).where("#{JournalDetail.table_name}.prop_key = 'status_id' and #{User.table_name}.id = '#{user.id}'").count + #Journal.joins(:details, :user).where("#{JournalDetail.table_name}.prop_key = 'status_id' and #{User.table_name}.id = '#{user.id}'").count + users = Journal.find_by_sql("SELECT COUNT(*) as m_count FROM journals JOIN journal_details on journals.id = journal_details.journal_id WHERE journal_details.prop_key = 'status_id' and journals.user_id = #{user.id}") + result = 0 + if users.count > 0 + result = users.first.m_count + end + result else - Journal.joins(:issue,:details,:user).where("#{Issue.table_name}.project_id = '#{project.id}' and #{JournalDetail.table_name}.prop_key = 'status_id' and #{User.table_name}.id = '#{user.id}'").count + #Journal.joins(:issue,:details,:user).where("#{Issue.table_name}.project_id = '#{project.id}' and #{JournalDetail.table_name}.prop_key = 'status_id' and #{User.table_name}.id = '#{user.id}'").count + users = Journal.find_by_sql("SELECT COUNT(*) as m_count FROM journals JOIN journal_details on journals.id = journal_details.journal_id JOIN issues ON issues.id = journals.journalized_id and journalized_type = 'Issue' WHERE journal_details.prop_key = 'status_id' and journals.user_id = #{user.id} and issues.project_id = '#{project.id}'") + result = 0 + if users.count > 0 + result = users.first.m_count + end + result end end @@ -478,25 +558,37 @@ FROM `users` where id = #{user.id}") def issues_status_score(user,project=nil) if project.nil? #Journal.joins(:details, :user).where("#{JournalDetail.table_name}.prop_key = 'status_id' and #{User.table_name}.id = '#{user.id}'").count - User.find_by_sql("SELECT users.id,(SELECT COUNT(*) FROM journals JOIN journal_details on journals.id = journal_details.journal_id WHERE journal_details.prop_key = 'status_id' and journals.user_id = users.id) AS m_score FROM users WHERE users.id = '#{user.id}'") + User.find_by_sql("SELECT users.id,(SELECT COUNT(*) FROM journals JOIN journal_details on journals.id = journal_details.journal_id WHERE journal_details.prop_key = 'status_id' and journals.user_id = users.id) AS m_count FROM users WHERE users.id = '#{user.id}'") else #Journal.joins(:issue,:details,:user).where("#{Issue.table_name}.project_id = '#{project.id}' and #{JournalDetail.table_name}.prop_key = 'status_id' and #{User.table_name}.id = '#{user.id}'").count - User.find_by_sql("SELECT users.id,(SELECT COUNT(*) FROM journals JOIN journal_details on journals.id = journal_details.journal_id JOIN issues ON issues.id = journals.journalized_id and journalized_type = 'Issue' WHERE journal_details.prop_key = 'status_id' and journals.user_id = users.id and issues.project_id = '#{project.id}') AS m_score FROM users WHERE users.id = '#{user.id}'") + User.find_by_sql("SELECT users.id,(SELECT COUNT(*) FROM journals JOIN journal_details on journals.id = journal_details.journal_id JOIN issues ON issues.id = journals.journalized_id and journalized_type = 'Issue' WHERE journal_details.prop_key = 'status_id' and journals.user_id = users.id and issues.project_id = '#{project.id}') AS m_count FROM users WHERE users.id = '#{user.id}'") end end #鏇存柊瀵圭暀瑷鐨勫洖澶嶆暟閲 def update_replay_for_message(user,type,project=nil) - option_number = get_option_number(user,type) + option_number = get_option_number(user,type,project) option_number.replay_for_message = replay_for_message_num(user,project)#JournalsForMessage.includes(:user).where("m_parent_id IS NOT NULL and user_id = #{user.id}").count update_score(option_number) end def replay_for_message_num(user,project=nil) if project.nil? - JournalsForMessage.includes(:user).where("m_parent_id IS NOT NULL and user_id = #{user.id} and jour_type = 'Project'").count + #JournalsForMessage.includes(:user).where("m_parent_id IS NOT NULL and user_id = #{user.id} and jour_type = 'Project'").count + users = JournalsForMessage.find_by_sql("SELECT COUNT(*) as m_count From #{JournalsForMessage.table_name} WHERE m_parent_id IS NOT NULL and user_id = #{user.id} and jour_type = 'Project'") + result = 0 + if users.count > 0 + result = users.first.m_count + end + result else - JournalsForMessage.includes(:user).where("m_parent_id IS NOT NULL and user_id = #{user.id} and jour_type = 'Project' and jour_id = '#{project.id}'").count + #JournalsForMessage.includes(:user).where("m_parent_id IS NOT NULL and user_id = #{user.id} and jour_type = 'Project' and jour_id = '#{project.id}'").count + users = JournalsForMessage.find_by_sql("SELECT COUNT(*) as m_count From #{JournalsForMessage.table_name} WHERE m_parent_id IS NOT NULL and user_id = #{user.id} and jour_type = 'Project' and jour_id = '#{project.id}'") + result = 0 + if users.count > 0 + result = users.first.m_count + end + result end end @@ -505,22 +597,34 @@ FROM `users` where id = #{user.id}") if project.nil? User.find_by_sql("SELECT users.id,(SELECT COUNT(*) From journals_for_messages WHERE m_parent_id IS NOT NULL and user_id = users.id and jour_type = 'Project') as m_score FROM users WHERE users.id = '#{user.id}'") else - User.find_by_sql("SELECT users.id,(SELECT COUNT(*) From journals_for_messages WHERE m_parent_id IS NOT NULL and user_id = users.id and jour_type = 'Project' and jour_id = '#{project.id}') as m_score FROM users WHERE users.id = '#{user.id}'") + User.find_by_sql("SELECT users.id,(SELECT COUNT(*) From journals_for_messages WHERE m_parent_id IS NOT NULL and user_id = users.id and jour_type = 'Project' and jour_id = '#{project.id}') as m_score FROM users WHERE users.id = '#{user.id}'") end end #鏇存柊瀵瑰笘瀛愮殑鍥炲鏁伴噺 def update_replay_for_memo(user,type,project=nil) - option_number = get_option_number(user,type) + option_number = get_option_number(user,type,project) option_number.replay_for_memo = replay_for_memo_num(user,project)#Message.includes(:author).where("parent_id IS NOT NULL and author_id = #{user.id}").all.count #+ Memo.includes(:author).where("parent_id IS NOT NULL and author_id = #{user.id}").all.count update_score(option_number) end def replay_for_memo_num(user,project=nil) if project.nil? - Message.includes(:author).joins(:board).where("#{Message.table_name}.parent_id IS NOT NULL and #{Message.table_name}.author_id = '#{user.id}' and #{Board.table_name}.project_id != -1").all.count + #Message.includes(:author).joins(:board).where("#{Message.table_name}.parent_id IS NOT NULL and #{Message.table_name}.author_id = '#{user.id}' and #{Board.table_name}.project_id != -1").all.count + users = Message.find_by_sql("SELECT COUNT(*) as m_count FROM messages JOIN boards on messages.board_id = boards.id WHERE messages.parent_id IS NOT NULL AND messages.author_id = #{user.id} AND boards.project_id != -1") + result = 0 + if users.count > 0 + result = users.first.m_count + end + result else - Message.includes(:author).joins(:board).where("#{Message.table_name}.parent_id IS NOT NULL and #{Message.table_name}.author_id = '#{user.id}' and #{Board.table_name}.project_id = #{project.id}").all.count + #Message.includes(:author).joins(:board).where("#{Message.table_name}.parent_id IS NOT NULL and #{Message.table_name}.author_id = '#{user.id}' and #{Board.table_name}.project_id = #{project.id}").all.count + users = Message.find_by_sql("SELECT COUNT(*) as m_count FROM messages JOIN boards on messages.board_id = boards.id WHERE messages.parent_id IS NOT NULL AND messages.author_id = #{user.id} AND boards.project_id = #{project.id}") + result = 0 + if users.count > 0 + result = users.first.m_count + end + result end end @@ -535,21 +639,27 @@ FROM `users` where id = #{user.id}") #鏇存柊琚叧娉ㄧ殑浜烘暟 def update_follow(user,type) option_number = get_option_number(user,type) - option_number.follow = Watcher.includes(:watchable).where("watchable_type = 'Principal' and watchable_id = '#{user.id}'").count + option_number.follow = follow_num(user)#Watcher.includes(:watchable).where("watchable_type = 'Principal' and watchable_id = '#{user.id}'").count update_score(option_number) end def follow_num(user) - Watcher.includes(:watchable).where("watchable_type = 'Principal' and watchable_id = '#{user.id}'").count + #Watcher.includes(:watchable).where("watchable_type = 'Principal' and watchable_id = '#{user.id}'").count + users = Watcher.find_by_sql("SELECT COUNT(*) as m_count FROM #{Watcher.table_name} WHERE watchable_type = 'Principal' and watchable_id = #{user.id}") + result = 0 + if users.count > 0 + result = users.first.m_count + end + result end def follow_score(user) - User.find_by_sql("SELECT users.id, (SELECT COUNT(*) * 2 FROM #{Watcher.table_name} WHERE watchable_type = 'Principal' and watchable_id = '#{user.id}') FROM users WHERE users.id = '#{user.id}'") + User.find_by_sql("SELECT users.id, (SELECT COUNT(*) * 2 FROM #{Watcher.table_name} WHERE watchable_type = 'Principal' and watchable_id = users.id) FROM users WHERE users.id = '#{user.id}'") end #鏇存柊甯栧瓙韪╁悇椤规暟閲 def update_tread(user,type,project=nil) - option_number = get_option_number(user,type) + option_number = get_option_number(user,type,project) tread_nums = tread_num(user,project) option_number.tread = tread_nums[:tread] option_number.tread_by_one = tread_nums[:tead_by_one] @@ -614,7 +724,7 @@ FROM `users` where id = #{user.id}") #鏇存柊甯栧瓙椤舵暟閲 def update_praise(user,type,project=nil) - option_number = get_option_number(user,type) + option_number = get_option_number(user,type,project) praise_nums = praise_num(user,project) option_number.praise_by_one = praise_nums[:praise_by_one] option_number.praise_by_two = praise_nums[:praise_by_two] @@ -679,82 +789,148 @@ FROM `users` where id = #{user.id}") #鏇存柊鎻愪氦浠g爜娆℃暟 def update_changeset(user,type,project=nil) - option_number = get_option_number(user,type) + option_number = get_option_number(user,type,project) option_number.changeset = changeset_num(user,project)#Changeset.includes(:user).where("user_id = '#{user.id}'").all.count update_score(option_number) end def changeset_num(user,project=nil) if project.nil? - Changeset.includes(:user).where("user_id = '#{user.id}'").all.count + #Changeset.includes(:user).where("user_id = '#{user.id}'").all.count + users = Changeset.find_by_sql("SELECT COUNT(*) as m_count FROM #{Changeset.table_name} WHERE user_id = #{user.id}") + result = 0 + if users.count > 0 + result = users.first.m_count + end + result else - Changeset.includes(:user).joins(:repository).where("#{Changeset.table_name}.user_id = '#{user.id}' and #{Repository.table_name}.project_id = #{project.id}").all.count + #Changeset.includes(:user).joins(:repository).where("#{Changeset.table_name}.user_id = '#{user.id}' and #{Repository.table_name}.project_id = #{project.id}").all.count + users = Changeset.find_by_sql("SELECT COUNT(*) as m_count FROM #{Changeset.table_name} JOIN #{Repository.table_name} ON #{Changeset.table_name}.repository_id = #{Repository.table_name}.id WHERE #{Changeset.table_name}.user_id = #{user.id} and #{Repository.table_name}.project_id = #{project.id}") + result = 0 + if users.count > 0 + result = users.first.m_count + end + result end end #鏇存柊鏂囨。鎻愪氦娆℃暟 def update_document(user,type,project=nil) - option_number = get_option_number(user,type) + option_number = get_option_number(user,type,project) option_number.document = document_num(user,project)#Document.includes(:user).where("user_id = '#{user.id}'").all.count update_score(option_number) end def document_num(user,project=nil) if project.nil? - Document.includes(:user).where("user_id = '#{user.id}'").all.count + #Document.includes(:user).where("user_id = '#{user.id}'").all.count + users = Document.find_by_sql("SELECT COUNT(*) as m_count FROM #{Document.table_name} WHERE #{Document.table_name}.user_id = #{user.id}") + result = 0 + if users.count > 0 + result = users.first.m_count + end + result else - Document.includes(:user,:project).where("user_id = '#{user.id}' and project_id = '#{project.id}'").all.count + #Document.includes(:user,:project).where("user_id = '#{user.id}' and project_id = '#{project.id}'").all.count + users = Document.find_by_sql("SELECT COUNT(*) as m_count FROM #{Document.table_name} WHERE #{Document.table_name}.user_id = #{user.id} and #{Document.table_name}.project_id = '#{project.id}'") + result = 0 + if users.count > 0 + result = users.first.m_count + end + result end end #鏇存柊闄勪欢鎻愪氦鏁伴噺 def update_attachment(user,type,project=nil) - option_number = get_option_number(user,type) + option_number = get_option_number(user,type,project) option_number.attachment = attachment_num(user,project)#Attachment.includes(:author).where("author_id = '#{user.id}'").all.count update_score(option_number) end def attachment_num(user,project=nil) if project.nil? - Attachment.includes(:author,:container).where("author_id = '#{user.id}' and container_type = 'Project'").all.count + #Attachment.includes(:author,:container).where("author_id = '#{user.id}' and container_type = 'Project'").all.count + users = Attachment.find_by_sql("SELECT COUNT(*) as m_count FROM #{Attachment.table_name} WHERE author_id = '#{user.id}' and container_type = 'Project'") + result = 0 + if users.count > 0 + result = users.first.m_count + end + result else - Attachment.includes(:author,:container).where("author_id = '#{user.id}' and container_type = 'Project' and container_id = #{project.id}").all.count + #Attachment.includes(:author,:container).where("author_id = '#{user.id}' and container_type = 'Project' and container_id = #{project.id}").all.count + users = Attachment.find_by_sql("SELECT COUNT(*) as m_count FROM #{Attachment.table_name} WHERE author_id = '#{user.id}' and container_type = 'Project' and container_id = #{project.id}") + result = 0 + if users.count > 0 + result = users.first.m_coumt + end + result end end #鏇存柊缂洪櫡瀹屾垚搴︽鏁 def update_issue_done_ratio(user,type,project=nil) - option_number = get_option_number(user,type) + option_number = get_option_number(user,type,project) option_number.issue_done_ratio = issue_done_ratio_num(user,project) #Journal.joins(:details, :user).where("#{JournalDetail.table_name}.prop_key = 'done_ratio' and #{User.table_name}.id = '#{user.id}'").count update_score(option_number) end def issue_done_ratio_num(user,project=nil) if project.nil? - Journal.joins(:details, :user).where("#{JournalDetail.table_name}.prop_key = 'done_ratio' and #{User.table_name}.id = '#{user.id}'").count + #Journal.joins(:details, :user).where("#{JournalDetail.table_name}.prop_key = 'done_ratio' and #{User.table_name}.id = '#{user.id}'").count + users = Journal.find_by_sql("SELECT COUNT(*) as m_count FROM #{Journal.table_name} JOIN #{JournalDetail.table_name} ON #{JournalDetail.table_name}.journal_id = #{Journal.table_name}.id WHERE #{JournalDetail.table_name}.prop_key = 'done_ratio' and #{Journal.table_name}.user_id = #{user.id}") + result = 0 + if users.count > 0 + result = users.first.m_count + end + result else - Journal.joins(:issue,:details,:user).where("#{Issue.table_name}.project_id = '#{project.id}' and #{JournalDetail.table_name}.prop_key = 'done_ratio' and #{User.table_name}.id = '#{user.id}'").count + #Journal.joins(:issue,:details,:user).where("#{Issue.table_name}.project_id = '#{project.id}' and #{JournalDetail.table_name}.prop_key = 'done_ratio' and #{User.table_name}.id = '#{user.id}'").count + users = Journal.find_by_sql("SELECT COUNT(*) as m_count FROM #{Journal.table_name} JOIN #{JournalDetail.table_name} ON #{JournalDetail.table_name}.journal_id = #{Journal.table_name}.id JOIN issues ON issues.id = journals.journalized_id and journalized_type = 'Issue' WHERE #{JournalDetail.table_name}.prop_key = 'done_ratio' and #{Journal.table_name}.user_id = #{user.id} and #{Issue.table_name}.project_id = '#{project.id}'") + result = 0 + if users.count > 0 + result = users.first.m_count + end + result end end #鏇存柊鍙戝竷缂洪櫡娆℃暟 def update_post_issue(user,type,project=nil) - option_number = get_option_number(user,type) + option_number = get_option_number(user,type,project) option_number.post_issue = post_issue_num(user,project) #Issue.includes(:author).where("author_id = '#{user.id}'").all.count update_score(option_number) end def post_issue_num(user,project=nil) if project.nil? - Issue.includes(:author).where("author_id = '#{user.id}'").all.count + #Issue.includes(:author).where("author_id = '#{user.id}'").all.count + users = Issue.find_by_sql("SELECT COUNT(*) as m_count FROM #{Issue.table_name} WHERE author_id = #{user.id}") + result = 0 + if users.count > 0 + result = users.first.m_count + end + result else - Issue.includes(:author).where("author_id = '#{user.id}' and project_id = '#{project.id}'").all.count + #Issue.includes(:author).where("author_id = '#{user.id}' and project_id = '#{project.id}'").all.count + users = Issue.find_by_sql("SELECT COUNT(*) as m_count FROM #{Issue.table_name} WHERE author_id = #{user.id} and project_id = '#{project.id}'") + result = 0 + if users.count > 0 + result = users.first.m_count + end + result end end + #璇诲彇椤圭洰鎴愬憳寰楀垎 + def read_user_project_scores(user,project) + option_num = get_option_number(user,2,project) + option_num.total_score + end + def user_scores(user,type,project=nil) ooption_num = get_option_number(user,type,project) update_memo_number(user,type,project) @@ -769,6 +945,9 @@ FROM `users` where id = #{user.id}") update_attachment(user,type,project) update_issue_done_ratio(user,type,project) update_post_issue(user,type,project) + if project.nil? + update_follow(user,type) + end update_score(ooption_num) ooption_num end diff --git a/app/models/attachment.rb b/app/models/attachment.rb index bcd8852f5..e25434e6e 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -29,9 +29,9 @@ class Attachment < ActiveRecord::Base include UserScoreHelper validates_presence_of :filename, :author - validates_length_of :filename, :maximum => 255 - validates_length_of :disk_filename, :maximum => 255 - validates_length_of :description, :maximum => 255 + validates_length_of :filename, :maximum => 254 + validates_length_of :disk_filename, :maximum => 254 + validates_length_of :description, :maximum => 254 validate :validate_max_file_size @@ -512,11 +512,18 @@ class Attachment < ActiveRecord::Base end end update_attachment(self.author,1) + if self.container_type == 'Project' + update_attachment(self.author,2,self.container) + end + end #鍒犻櫎闄勪欢鏃堕噸鏂扮粺璁$敤鎴风殑闄勪欢鏁伴噺寰楀垎 def down_user_score update_attachment(self.author,1) + if self.container_type == 'Project' + update_attachment(self.author,2,self.container) + end end end diff --git a/app/models/changeset.rb b/app/models/changeset.rb index 38bdd0cc8..f2228e699 100644 --- a/app/models/changeset.rb +++ b/app/models/changeset.rb @@ -308,12 +308,14 @@ class Changeset < ActiveRecord::Base #鏇存柊鐢ㄦ埛绛夌骇 UserLevels.update_user_level(self.user) update_changeset(self.user,1) + update_changeset(self.user,2,self.repository.project) end #绉垎鍒锋柊 def down_user_score UserLevels.update_user_level(self.user) update_changeset(self.user,1) + update_changeset(self.user,2,self.repository.project) end end diff --git a/app/models/document.rb b/app/models/document.rb index 42692bc22..7c2fa5a6d 100644 --- a/app/models/document.rb +++ b/app/models/document.rb @@ -69,9 +69,11 @@ class Document < ActiveRecord::Base def be_user_score UserScore.project(:push_document, self.user,self,{ document_id: self.id }) update_document(self.user,1) + update_document(self.user,2,self.project) end def down_user_score update_document(self.user,1) + update_document(self.user,2,self.project) end end diff --git a/app/models/issue.rb b/app/models/issue.rb index 68afe21a2..3a14d288d 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -138,10 +138,10 @@ class Issue < ActiveRecord::Base nil when 'default' user_ids = [user.id] + user.groups.map(&:id) - "(#{table_name}.is_private = #{connection.quoted_false}) OR (#{table_name}.author_id = #{user.id} OR #{table_name}.tracker_id IN (#{user_ids.join(',')}) OR #{table_name}.assigned_to_id IN (#{user_ids.join(',')}))" + "(#{table_name}.is_private = #{connection.quoted_false}) OR (#{table_name}.author_id = #{user.id} OR #{table_name}.assigned_to_id IN (#{user_ids.join(',')}))" when 'own' user_ids = [user.id] + user.groups.map(&:id) - "(#{table_name}.author_id = #{user.id} OR #{table_name}.tracker_id IN (#{user_ids.join(',')}) OR #{table_name}.assigned_to_id IN (#{user_ids.join(',')}))" + "(#{table_name}.author_id = #{user.id} OR #{table_name}.assigned_to_id IN (#{user_ids.join(',')}))" else '1=0' end @@ -159,9 +159,9 @@ class Issue < ActiveRecord::Base when 'all' true when 'default' - (!self.is_private? ||self.tracker == user) || (self.author == user || user.is_or_belongs_to?(assigned_to)) + !self.is_private? || (self.author == user || user.is_or_belongs_to?(assigned_to)) when 'own' - self.tracker == user || self.author == user || user.is_or_belongs_to?(assigned_to) + self.author == user || user.is_or_belongs_to?(assigned_to) else false end @@ -1524,6 +1524,7 @@ class Issue < ActiveRecord::Base def be_user_score_new_issue UserScore.project(:post_issue, self.author,self, { issue_id: self.id }) update_post_issue(self.author,1) + update_post_issue(self.author,2,self.project) end def down_user_score @@ -1539,8 +1540,13 @@ class Issue < ActiveRecord::Base # update_issues_status(self.author , 1) #end update_post_issue(self.author,1) - update_issue_done_ratio(User.current,1) - update_issues_status(self.author , 1) + #update_issue_done_ratio(self.author,1) + #update_issues_status(self.author , 1) + + update_post_issue(self.author,2,self.project) + #update_issue_done_ratio(self.author,2,self.project) + #update_issues_status(self.author , 2) + end diff --git a/app/models/journal.rb b/app/models/journal.rb index 0fe2b804b..a386c2b80 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -163,6 +163,7 @@ class Journal < ActiveRecord::Base #鍗忓悓寰楀垎鍔犲垎 UserScore.joint(:post_issue_message, self.user,self.issue.author,self, { message_id: self.id }) update_messges_for_issue(self.user,1) + update_messges_for_issue(self.user,2,self.issue.project) end end @@ -173,6 +174,7 @@ class Journal < ActiveRecord::Base #鍗忓悓寰楀垎鍑忓垎 UserScore.joint(:delete_issue_message, self.user,self.issue.author,self, { message_id: self.id }) update_messges_for_issue(self.user,1) + update_messges_for_issue(self.user,2,self.issue.project) end end diff --git a/app/models/journal_detail.rb b/app/models/journal_detail.rb index 82a63b028..57541fe85 100644 --- a/app/models/journal_detail.rb +++ b/app/models/journal_detail.rb @@ -46,9 +46,15 @@ class JournalDetail < ActiveRecord::Base #鏇存柊缂洪櫡瀹屾垚搴 if self.prop_key == 'done_ratio' update_issue_done_ratio(self.journal.user,1) + unless self.journal.project.nil? + update_issue_done_ratio(self.journal.user,2,self.journal.project) + end #鏇存柊缂洪櫡鐘舵 elsif self.prop_key == 'status_id' update_issues_status(self.journal.user , 1) + unless self.journal.project.nil? + update_issues_status(self.journal.user,2,self.journal.project) + end end end @@ -57,9 +63,16 @@ class JournalDetail < ActiveRecord::Base if self.prop_key == 'done_ratio' update_issue_done_ratio(self.journal.user,1) + unless self.journal.project.nil? + update_issue_done_ratio(self.journal.user,2,self.journal.project) + end + #鏇存柊缂洪櫡鐘舵 elsif self.prop_key == 'status_id' update_issues_status(self.journal.user, 1) + unless self.journal.project.nil? + update_issues_status(self.journal.user,2,self.journal.project) + end end end diff --git a/app/models/journals_for_message.rb b/app/models/journals_for_message.rb index dd687f263..20e0c15f4 100644 --- a/app/models/journals_for_message.rb +++ b/app/models/journals_for_message.rb @@ -144,6 +144,9 @@ class JournalsForMessage < ActiveRecord::Base #鍗忓悓寰楀垎鍔犲垎 UserScore.joint(:reply_message, self.user,User.find(self.reply_id),self, { journals_for_messages_id: self.id }) update_replay_for_message(self.user,1) + if self.jour_type == "Project" + update_replay_for_message(self.user,2,self.jour) + end end end # 鏇存柊鐢ㄦ埛鍒嗘暟 -by zjc @@ -153,6 +156,9 @@ class JournalsForMessage < ActiveRecord::Base #鍗忓悓寰楀垎鍑忓垎 UserScore.joint(:reply_message_delete, self.user,User.find(self.reply_id), { journals_for_messages_id: self.id }) update_replay_for_message(self.user,1) + if self.jour_type == "Project" + update_replay_for_message(self.user,2,self.jour) + end end end end diff --git a/app/models/memo.rb b/app/models/memo.rb index 2c0d3571f..b02564834 100644 --- a/app/models/memo.rb +++ b/app/models/memo.rb @@ -146,11 +146,12 @@ class Memo < ActiveRecord::Base end #鏇存柊鐢ㄦ埛鍒嗘暟 -by zjc - def be_user_score + def be_user_score #鏂板缓memo涓旀棤parent鐨勪负鍙戝笘 if self.parent_id.nil? UserScore.joint(:post_message, User.current,nil,self ,{ memo_id: self.id }) update_memo_number(User.current,1) + #鏂板缓memo涓旀湁parent鐨勪负鍥炲笘 elsif !self.parent_id.nil? UserScore.joint(:reply_posting, User.current,self.parent.author,self, { memo_id: self.id }) diff --git a/app/models/message.rb b/app/models/message.rb index 647a665dc..0fdfc5b15 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -127,6 +127,14 @@ class Message < ActiveRecord::Base board.course end + def course_editable_by?(usr) + usr && usr.logged? && (usr.allowed_to?(:edit_messages, course) || (self.author == usr && usr.allowed_to?(:edit_own_messages, course))) + end + + def course_destroyable_by?(usr) + usr && usr.logged? && (usr.allowed_to?(:delete_messages, course) || (self.author == usr && usr.allowed_to?(:delete_own_messages, course))) + end + def editable_by?(usr) usr && usr.logged? && (usr.allowed_to?(:edit_messages, project) || (self.author == usr && usr.allowed_to?(:edit_own_messages, project))) end @@ -152,11 +160,17 @@ class Message < ActiveRecord::Base #鏂板缓message涓旀棤parent鐨勪负鍙戝笘 if self.parent_id.nil? && !self.board.project.nil? UserScore.joint(:post_message, self.author,nil,self, { message_id: self.id }) - update_memo_number(User.current,1) + update_memo_number(self.author,1) + if self.board.project_id != -1 + update_memo_number(self.author,2,self.board.project) + end #鏂板缓message涓旀湁parent鐨勪负鍥炲笘 elsif !self.parent_id.nil? && !self.board.project.nil? UserScore.joint(:reply_posting, self.author,self.parent.author,self, { message_id: self.id }) - update_replay_for_memo(User.current,1) + update_replay_for_memo(self.author,1) + if self.board.project_id != -1 + update_replay_for_memo(self.author,2,self.board.project) + end end end @@ -165,9 +179,15 @@ class Message < ActiveRecord::Base if self.parent_id.nil? && !self.board.project.nil? UserScore.joint(:delete_message, self.author,nil,self, { message_id: self.id }) update_memo_number(User.current,1) + if self.board.project_id != -1 + update_memo_number(self.author,2,self.board.project) + end elsif !self.parent_id.nil? && !self.board.project.nil? UserScore.joint(:reply_deleting, self.author,self.parent.author,self, { message_id: self.id }) update_replay_for_memo(User.current,1) + if self.board.project_id != -1 + update_replay_for_memo(self.author,2,self.board.project) + end end end end diff --git a/app/models/praise_tread.rb b/app/models/praise_tread.rb index 0a7282d26..3df5c72d9 100644 --- a/app/models/praise_tread.rb +++ b/app/models/praise_tread.rb @@ -43,14 +43,21 @@ class PraiseTread < ActiveRecord::Base obj = PraiseTread.find_object_by_type_and_id(self.praise_tread_object_type,praise_tread_object_id) target_user = obj.author UserScore.skill(:treaded_by_user, User.current,target_user,self, { praise_tread_id: self.id }) - update_tread(User.current,1) + update_tread(self.user,1) update_tread(target_user,1) + unless self.project.nil? + update_tread(self.user,2,self.project) + update_tread(target_user,2,self.project) + end #椤惰创鍚ф垨璁ㄨ鍖哄笘瀛 elsif self.praise_or_tread == 1 && (self.praise_tread_object_type == 'Issue' || self.praise_tread_object_type == 'Message') obj = PraiseTread.find_object_by_type_and_id(self.praise_tread_object_type,praise_tread_object_id) target_user = obj.author UserScore.skill(:praised_by_user, User.current,target_user,self,{ praise_tread_id: self.id }) update_praise(target_user,1) + unless self.project.nil? + update_praise(target_user,2,self.project) + end #鏇存柊鐢ㄦ埛绛夌骇 UserLevels.update_user_level(target_user) end @@ -62,14 +69,21 @@ class PraiseTread < ActiveRecord::Base obj = PraiseTread.find_object_by_type_and_id(self.praise_tread_object_type,praise_tread_object_id) target_user = obj.author #UserScore.skill(:treaded_by_user, User.current,target_user,self, { praise_tread_id: self.id }) - update_tread(User.current,1) + update_tread(self.user,1) update_tread(target_user,1) + unless self.project.nil? + update_tread(self.user,2,self.project) + update_tread(target_user,2,self.project) + end #椤惰创鍚ф垨璁ㄨ鍖哄笘瀛 elsif self.praise_or_tread == 1 && (self.praise_tread_object_type == 'Issue' || self.praise_tread_object_type == 'Message') obj = PraiseTread.find_object_by_type_and_id(self.praise_tread_object_type,praise_tread_object_id) target_user = obj.author #UserScore.skill(:praised_by_user, User.current,target_user,self,{ praise_tread_id: self.id }) update_praise(target_user,1) + unless self.project.nil? + update_praise(target_user,2,self.project) + end #鏇存柊鐢ㄦ埛绛夌骇 UserLevels.update_user_level(target_user) end diff --git a/app/views/bids/_homework_list.html.erb b/app/views/bids/_homework_list.html.erb index 6797bc9eb..6d3a2adcc 100644 --- a/app/views/bids/_homework_list.html.erb +++ b/app/views/bids/_homework_list.html.erb @@ -28,13 +28,15 @@ + <% user_name = is_teacher ? (homework.user.firstname + homework.user.lastname) : homework.user.login %> - + - diff --git a/app/views/contestnotifications/_news.html.erb b/app/views/contestnotifications/_news.html.erb index 301a193d8..fbac2557f 100644 --- a/app/views/contestnotifications/_news.html.erb +++ b/app/views/contestnotifications/_news.html.erb @@ -1,9 +1,9 @@ - + <%# unless news.summary.blank? %> +
<%= image_tag(url_to_avatar(homework.user), :class => "avatar")%><%= image_tag(url_to_avatar(homework.user), :class => "avatar")%>
+ +

- <%= link_to (is_teacher ? homework.user.realname : homework.user ), user_path(homework.user),{:style => "color:#727272"} %> + <%= link_to user_name, user_path(homework.user),{:style => "color:#727272"} %>

<%#=h news.summary %><% end %><%#= authoring news.created_on, news.author %>

--> diff --git a/app/views/courses/_course_resources_html.erb b/app/views/courses/_course_resources_html.erb new file mode 100644 index 000000000..8f706725d --- /dev/null +++ b/app/views/courses/_course_resources_html.erb @@ -0,0 +1,32 @@ +<% id = "course_resources_ul_" + obj.id.to_s%> + \ No newline at end of file diff --git a/app/views/courses/show.html.erb b/app/views/courses/show.html.erb index d7d579dd1..366ec0c39 100644 --- a/app/views/courses/show.html.erb +++ b/app/views/courses/show.html.erb @@ -1,8 +1,8 @@ <% if @events_by_day != nil && @events_by_day.size >0 %>
- +

- <%= l(:label_date_from_to, :start => format_date(@date_from), :end => format_date(@date_to - 1)) %> + <%#= l(:label_date_from_to, :start => format_date(@date_from), :end => format_date(@date_to - 1)) %>

<% @events_by_day.keys.sort.reverse.each do |day| %> @@ -29,7 +29,7 @@ <%= l(:label_new_activity) %> - <%= link_to "#{eventToLanguageCourse(e.event_type, @course)}: "<< format_activity_title(e.event_title), (e.event_type.eql?("attachment")&&e.container.kind_of?(Course)) ? course_files_path(e.container) : e.event_url %> + <%= link_to "#{eventToLanguageCourse(e.event_type, @course)}: "<< format_activity_title(e.event_title), (e.event_type.eql?("attachment")&&e.container.kind_of?(Course)) ? course_files_path(e.container) : e.event_url,:style => "word-break:break-all;" %>
diff --git a/app/views/files/_course_show_all_attachment.html.erb b/app/views/files/_course_show_all_attachment.html.erb index 76112bc78..f70142a05 100644 --- a/app/views/files/_course_show_all_attachment.html.erb +++ b/app/views/files/_course_show_all_attachment.html.erb @@ -25,60 +25,70 @@ - <% @containers.each do |container| %> - <% next if container.attachments.empty? -%> - <% if container.is_a?(Version) -%> - + <%# @containers.each do |container| %> + <%# next if container.attachments.empty? -%> + <%# if container.is_a?(Version) -%> + - - --> + <%# end -%> + <% if @curse_attachments != nil %> + <% @curse_attachments.each do |file| %> + <%if file.is_public == 0 && !User.current.member_of_course?(@course)%> + <%next%> + <%end%> + "> + + + + - - + + - - - - - - - - <% end -%> - <% reset_cycle %> + + + + + + + + <% end -%> + <% end %> + <%# reset_cycle %> + <%# end -%> + +
<%= number_to_human_size(file.filesize) %> - <%= file.attachmentstype.typeName unless file.attachmentstype.nil? %> +
<%= link_to_attachment file, :download => true, :title => file.filename+"\n"+file.description.to_s, :style => "width: 230px; overflow: hidden; white-space: nowrap;text-overflow: ellipsis;" %><%= number_to_human_size(file.filesize) %> + <%= file.attachmentstype.typeName unless file.attachmentstype.nil? %> <%= render :partial => 'attachments/course_type_edit', :locals => {:attachmenttypes => attachmenttypes, :attachment => file, :contentype => selContentType} %> - <%= file.show_suffix_type %> - <%= file.file_dense_str %> -   + <%= file.show_suffix_type %> + <%= file.file_dense_str %> +   <%= render :partial => 'course_file_dense_edit', :locals => {:file_dense_list => file.file_dense_list, :attachment => file} %> - <%= file.downloads %> - <%= link_to(image_tag('delete.png'), attachment_path(file), - :data => {:confirm => l(:text_are_you_sure)}, :method => :delete) if delete_allowed %> -
-
- <%# @preTags = %w|棰勮A 棰勮B 棰勮C 棰勮D 棰勮E 棰勮Z | %> - <%= render :partial => 'tags/tag', :locals => {:obj => file, :object_flag => "6"} %> -
-
- -
<%= file.downloads %> + <%= link_to(image_tag('delete.png'), attachment_path(file), + :data => {:confirm => l(:text_are_you_sure)}, :method => :delete) if delete_allowed %> +
+
+ <%# @preTags = %w|棰勮A 棰勮B 棰勮C 棰勮D 棰勮E 棰勮Z | %> + <%= render :partial => 'tags/tag', :locals => {:obj => file, :object_flag => "6"} %> +
+
+ +
+ + diff --git a/app/views/files/_show_all_attachment.html.erb b/app/views/files/_show_all_attachment.html.erb index 838153c78..043fe1183 100644 --- a/app/views/files/_show_all_attachment.html.erb +++ b/app/views/files/_show_all_attachment.html.erb @@ -25,16 +25,17 @@ - <% @containers.each do |container| %> - <% next if container.attachments.empty? -%> - <% if container.is_a?(Version) -%> - + <%# @containers.each do |container| %> + <%# next if container.attachments.empty? -%> + <%# if container.is_a?(Version) -%> + + <%# end -%> + <% if @curse_attachments != nil %> + <% @curse_attachments.each do |file| %> <%if file.is_public == 0 && !User.current.member_of?(@project)%> <%next%> <%end%> @@ -75,10 +76,17 @@ <% end -%> - <% reset_cycle %> + <%# reset_cycle %> <% end -%> + + + diff --git a/app/views/issues/index.html.erb b/app/views/issues/index.html.erb index 804b52d68..f5018fc94 100644 --- a/app/views/issues/index.html.erb +++ b/app/views/issues/index.html.erb @@ -37,26 +37,26 @@ + -->
<%= link_to_function l(:label_issue_query), 'submit_query_form("query_form")', :class => 'icon icon-checked' %> <%= link_to l(:label_issue_cancel_query), {:set_filter => 1, :project_id => @project}, :class => 'icon icon-reload' %> diff --git a/app/views/layouts/_base_enterprise_header.html.erb b/app/views/layouts/_base_enterprise_header.html.erb index 7fd21afe1..d98b94839 100644 --- a/app/views/layouts/_base_enterprise_header.html.erb +++ b/app/views/layouts/_base_enterprise_header.html.erb @@ -1,13 +1,13 @@ @@ -31,14 +31,14 @@ - + - + diff --git a/app/views/layouts/_base_footer.html.erb b/app/views/layouts/_base_footer.html.erb index 990a6d3c8..46fc0debd 100644 --- a/app/views/layouts/_base_footer.html.erb +++ b/app/views/layouts/_base_footer.html.erb @@ -10,7 +10,7 @@ <%=l(:label_organizers)%> <%= link_to l(:label_organizers_information),"http://www.nudt.edu.cn/ArticleShow.asp?ID=47",:target=>"_blank"%> <%= link_to l(:label_organizers_information_institute), "http://www.nudt.edu.cn/ArticleShow.asp?ID=41", :target => "_blank" %> - <%=l(:label_copyright)%>@2007~2014 + <%=l(:label_copyright)%>漏2007~2014 <%= link_to l(:label_contact_us),"http://" + Setting.host_name + "/projects/2/member", :target=>"_blank" %> <%= link_to l(:label_record),"http://www.miibeian.gov.cn/", :target => "_blank" %> diff --git a/app/views/layouts/_base_header.html.erb b/app/views/layouts/_base_header.html.erb index 3116a9a68..b943cf565 100644 --- a/app/views/layouts/_base_header.html.erb +++ b/app/views/layouts/_base_header.html.erb @@ -44,6 +44,13 @@ <% if User.current.user_extensions && [UserExtensions::TEACHER, UserExtensions::STUDENT].include?(User.current.user_extensions.identity) -%> <% hasCourse=true%> + <% _bool=false %> + <% User.current.courses.each do |course| %> + <% if !course_endTime_timeout?(course) %> + <% _bool=true %> + <% end %> + <% end %> + <% if _bool %>
  • <%=link_to l(:label_my_course), {:controller => 'users', :action => 'user_courses', id: User.current.id} %>
  • + <% end %> <% end -%> <% end %> -
  • <%= link_to l(:label_my_projects), {:controller => 'users', :action => 'user_projects', id: User.current.id, host: Setting.project_domain} %> + <% if User.current.projects.count>0 %> +
  • + <%= link_to l(:label_my_projects), {:controller => 'users', :action => 'user_projects', id: User.current.id, host: Setting.project_domain} %> <% if hasCourse %>
  • + <% end %>
  • <%=link_to l(:label_user_edit), {:controller => 'my', :action=> 'account', host: Setting.user_domain}%>
  • diff --git a/app/views/layouts/_base_home_menu.html.erb b/app/views/layouts/_base_home_menu.html.erb index ca3e5c847..9327cae49 100644 --- a/app/views/layouts/_base_home_menu.html.erb +++ b/app/views/layouts/_base_home_menu.html.erb @@ -9,14 +9,14 @@ <%= content_tag('div', "#{l(:label_logged_as)} #{link_to_user(User.current, :format => :username)}".html_safe, :id => 'loggedas') if User.current.logged? %> - + - + <%= render_menu :top_home_menu if User.current.logged? || !Setting.login_required? -%>
    diff --git a/app/views/layouts/base_courses.html.erb b/app/views/layouts/base_courses.html.erb index 725e7fba9..01510865b 100644 --- a/app/views/layouts/base_courses.html.erb +++ b/app/views/layouts/base_courses.html.erb @@ -82,7 +82,7 @@ <%= join_in_course(@course, User.current) %> <% end %> <% unless User.current.member_of_course?(@course) %> - + <% end %> <% end %> diff --git a/app/views/layouts/base_projects.html.erb b/app/views/layouts/base_projects.html.erb index d8eb17acd..c3ad0fe08 100644 --- a/app/views/layouts/base_projects.html.erb +++ b/app/views/layouts/base_projects.html.erb @@ -50,11 +50,11 @@ - + <% elsif object_flag == '6' %> - <%#= image_tag("/images/sidebar/tags.png") %> + <%#= image_tag("/images/sidebar/tags.png") %> <%= link_to (image_tag "/images/sidebar/add.png"), 'javascript:void(0);', :class => "tags_icona", :onclick=>"$('#put-tag-form-#{obj.class}-#{obj.id}').toggle(); readmore(this);" if User.current.logged? %> - <%#= toggle_link (image_tag "/images/sidebar/add.png"), "put-tag-form-#{obj.class}-#{obj.id}", {:focus => "put-tag-form-#{obj.class}-#{obj.id} #name"} if User.current.logged? %> + <%#= toggle_link (image_tag "/images/sidebar/add.png"), "put-tag-form-#{obj.class}-#{obj.id}", {:focus => "put-tag-form-#{obj.class}-#{obj.id} #name"} if User.current.logged? %> -    -
    - <%= render :partial => "tags/tag_name",:locals => {:obj => obj,:non_list_all => false ,:object_flag => object_flag} %> -
    - +    +
    + <%= render :partial => "tags/tag_name",:locals => {:obj => obj,:non_list_all => false ,:object_flag => object_flag} %> +
    + <% else %> <%= image_tag("/images/sidebar/tags.png") %> diff --git a/app/views/tags/_tag_name.html.erb b/app/views/tags/_tag_name.html.erb index adee55564..38b8ac85c 100644 --- a/app/views/tags/_tag_name.html.erb +++ b/app/views/tags/_tag_name.html.erb @@ -70,14 +70,13 @@ :taggable_id => obj.id, :taggable_type => object_flag %> <% end %> - <% when '5' %> - <% if Forum.find(params[:id]) %> - <% if Forum.find(params[:id]).creator_id == User.current.id %> + <% when '5' %> + <% test = Forum.find(obj.id) %> + <% if test && test.creator_id == User.current.id %> <%= link_to 'x', :controller => "tags", :action => "remove_tag", :remote => true, :tag_name => tag, :taggable_id => obj.id, :taggable_type => object_flag %> - <% end %> - <% end %> + <% end %> <% when '6' %> <%# if (User.current.logged? && User.current.admin? diff --git a/app/views/users/_course_form.html.erb b/app/views/users/_course_form.html.erb index 71a44f3c9..055dd7d6b 100644 --- a/app/views/users/_course_form.html.erb +++ b/app/views/users/_course_form.html.erb @@ -32,8 +32,9 @@

    - <%= membership.course.short_description %> -

    + <%= textilizable membership.course.short_description %> +

    + diff --git a/app/views/welcome/_course_list.html.erb b/app/views/welcome/_course_list.html.erb index f590cf868..8d31f7c4c 100644 --- a/app/views/welcome/_course_list.html.erb +++ b/app/views/welcome/_course_list.html.erb @@ -6,11 +6,8 @@
    - <% if (course.school == nil) %> -               - <% else %> - <%= link_to course.school.name.try(:gsub, /(.+)$/, '\1:'), options={:action => 'course', :school_id => course.school.id}, html_options={:method => 'get'} %> - <% end %> + <%= link_to(course.name.truncate(30, omission: '...')+":", course_path(course.id), :class => "d-g-blue d-p-project-name", :title => "#{course.name}") %> + <%= link_to(course.try(:teacher).try(:realname), user_path(course.teacher)) %> @@ -19,7 +16,11 @@
    [<%= get_course_term course %>] - <%= link_to(course.name.truncate(30, omission: '...'), course_path(course.id), :class => "d-g-blue d-p-project-name", :title => "#{course.name}") %> + <% if (course.school == nil) %> +               + <% else %> + <%= link_to course.school.name.try(:gsub, /(.+)$/, '\1'), options={:action => 'course', :school_id => course.school.id}, html_options={:method => 'get'} %> + <% end %> (<%= course.members.count %>浜) <%# files_count = course.attachments.count.to_s %> (<%= link_to "#{course.attachments.count.to_s}浠", course_files_path(course) %>璧勬枡) diff --git a/app/views/words/_feedback.html.erb b/app/views/words/_feedback.html.erb new file mode 100644 index 000000000..774ee3b64 --- /dev/null +++ b/app/views/words/_feedback.html.erb @@ -0,0 +1,50 @@ +<% reply_allow = JournalsForMessage.create_by_user? User.current %> +<% if @jour.size >0 %> + +<% end %> + + \ No newline at end of file diff --git a/app/views/words/destroyJournal.js.erb b/app/views/words/destroyJournal.js.erb new file mode 100644 index 000000000..3600c3fd6 --- /dev/null +++ b/app/views/words/destroyJournal.js.erb @@ -0,0 +1,5 @@ + +<% if @journalP!=nil %> + //$(".message-for-user").children("#word_li_<%#=@journalP.id%>").remove(); + $("#project_feedback").html("<%= escape_javascript(render :partial => 'words/feedback') %>"); +<% end %> \ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index 367624f89..602e7a659 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1782,6 +1782,7 @@ en: label_no_file_uploaded: No file uploaded label_forum_new: New forum label_memo_new_from_forum: Release memo + bale_edit_notice: Edit label_user_grade: Individual score label_active_homework: homework @@ -1797,6 +1798,8 @@ en: label_record: 婀業CP澶09019772 label_check_comment: Check comment label_notification: Notification + + #end # ajax寮傛楠岃瘉 diff --git a/config/locales/zh.yml b/config/locales/zh.yml index 4c71e8990..a73f9db56 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -707,6 +707,7 @@ zh: label_news: 鏂伴椈 label_news_new: 娣诲姞鏂伴椈 bale_news_notice: 娣诲姞閫氱煡 #huang + bale_edit_notice: 淇敼閫氱煡 label_news_notice: 鍙戝竷璇剧▼閫氱煡 label_news_plural: 鏂伴椈 label_news_latest: 鏈杩戠殑鏂伴椈 @@ -1331,7 +1332,7 @@ zh: permission_add_documents: 鏂板缓鏂囨。 permission_edit_documents: 缂栬緫鏂囨。 permission_delete_documents: 鍒犻櫎鏂囨。 - label_gantt_progress_line: Progress line + label_gantt_progress_line: 杩涘害绾 setting_jsonp_enabled: Enable JSONP support field_inherit_members: Inherit members field_closed_on: 宸插叧闂 diff --git a/config/routes.rb b/config/routes.rb index 9d9b9d13b..f93318c7d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -652,6 +652,7 @@ RedmineApp::Application.routes.draw do delete 'words/destroy', :to => 'words#destroy' get 'words/more', :to => 'words#more' get 'words/back', :to=> 'words#back' + get 'words/destroyJournal', :to => 'words#destroyJournal' ############## fq post 'calls/create', :to => 'bids#create' delete 'calls/destroy', :to => 'bids#destroy' @@ -746,6 +747,7 @@ RedmineApp::Application.routes.draw do match 'words/add_brief_introdution', :controller => 'words', :action => 'add_brief_introdution' + Dir.glob File.expand_path("plugins/*", Rails.root) do |plugin_dir| file = File.join(plugin_dir, "config/routes.rb") if File.exists?(file) diff --git a/db/schema.rb b/db/schema.rb index e39644b3b..cdedc6a2c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20140814062455) do +ActiveRecord::Schema.define(:version => 20140812065417) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -177,6 +177,58 @@ ActiveRecord::Schema.define(:version => 20140814062455) do add_index "changesets_issues", ["changeset_id", "issue_id"], :name => "changesets_issues_ids", :unique => true + create_table "code_review_assignments", :force => true do |t| + t.integer "issue_id" + t.integer "change_id" + t.integer "attachment_id" + t.string "file_path" + t.string "rev" + t.string "rev_to" + t.string "action_type" + t.integer "changeset_id" + end + + create_table "code_review_project_settings", :force => true do |t| + t.integer "project_id" + t.integer "tracker_id" + t.datetime "created_at" + t.datetime "updated_at" + t.integer "updated_by" + t.boolean "hide_code_review_tab", :default => false + t.integer "auto_relation", :default => 1 + t.integer "assignment_tracker_id" + t.text "auto_assign" + t.integer "lock_version", :default => 0, :null => false + t.boolean "tracker_in_review_dialog", :default => false + end + + create_table "code_review_user_settings", :force => true do |t| + t.integer "user_id", :default => 0, :null => false + t.integer "mail_notification", :default => 0, :null => false + t.datetime "created_at" + t.datetime "updated_at" + end + + create_table "code_reviews", :force => true do |t| + t.integer "project_id" + t.integer "change_id" + t.datetime "created_at" + t.datetime "updated_at" + t.integer "line" + t.integer "updated_by_id" + t.integer "lock_version", :default => 0, :null => false + t.integer "status_changed_from" + t.integer "status_changed_to" + t.integer "issue_id" + t.string "action_type" + t.string "file_path" + t.string "rev" + t.string "rev_to" + t.integer "attachment_id" + t.integer "file_count", :default => 0, :null => false + t.boolean "diff_all" + end + create_table "comments", :force => true do |t| t.string "commented_type", :limit => 30, :default => "", :null => false t.integer "commented_id", :default => 0, :null => false @@ -396,14 +448,14 @@ ActiveRecord::Schema.define(:version => 20140814062455) do end create_table "forums", :force => true do |t| - t.string "name", :null => false - t.text "description" + t.string "name", :null => false + t.string "description", :default => "" t.integer "topic_count", :default => 0 t.integer "memo_count", :default => 0 t.integer "last_memo_id", :default => 0 - t.integer "creator_id", :null => false - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.integer "creator_id", :null => false + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false end create_table "groups_users", :id => false, :force => true do |t| @@ -820,18 +872,18 @@ ActiveRecord::Schema.define(:version => 20140814062455) do create_table "relative_memos", :force => true do |t| t.integer "osp_id" t.integer "parent_id" - t.string "subject", :null => false - t.text "content", :null => false + t.string "subject", :null => false + t.text "content", :limit => 16777215, :null => false t.integer "author_id" - t.integer "replies_count", :default => 0 + t.integer "replies_count", :default => 0 t.integer "last_reply_id" - t.boolean "lock", :default => false - t.boolean "sticky", :default => false - t.boolean "is_quote", :default => false - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false - t.integer "viewed_count_crawl", :default => 0 - t.integer "viewed_count_local", :default => 0 + t.boolean "lock", :default => false + t.boolean "sticky", :default => false + t.boolean "is_quote", :default => false + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + t.integer "viewed_count_crawl", :default => 0 + t.integer "viewed_count_local", :default => 0 t.string "url" t.string "username" t.string "userhomeurl" @@ -855,6 +907,19 @@ ActiveRecord::Schema.define(:version => 20140814062455) do add_index "repositories", ["project_id"], :name => "index_repositories_on_project_id" + create_table "rich_rich_files", :force => true do |t| + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + t.string "rich_file_file_name" + t.string "rich_file_content_type" + t.integer "rich_file_file_size" + t.datetime "rich_file_updated_at" + t.string "owner_type" + t.integer "owner_id" + t.text "uri_cache" + t.string "simplified_type", :default => "file" + end + create_table "roles", :force => true do |t| t.string "name", :limit => 30, :default => "", :null => false t.integer "position", :default => 1 @@ -905,10 +970,11 @@ ActiveRecord::Schema.define(:version => 20140814062455) do t.string "url" t.string "title" t.integer "share_type" - 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.integer "project_id" t.integer "user_id" + t.string "description" end create_table "softapplications", :force => true do |t| @@ -1014,8 +1080,8 @@ ActiveRecord::Schema.define(:version => 20140814062455) 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" @@ -1073,9 +1139,6 @@ ActiveRecord::Schema.define(:version => 20140814062455) do t.integer "active" t.datetime "created_at", :null => false t.datetime "updated_at", :null => false - t.integer "level" - t.integer "file" - t.integer "issue" end create_table "user_statuses", :force => true do |t| diff --git a/lib/plugins/acts_as_attachable/lib/acts_as_attachable.rb b/lib/plugins/acts_as_attachable/lib/acts_as_attachable.rb index 9f85dc49f..3059c23c9 100644 --- a/lib/plugins/acts_as_attachable/lib/acts_as_attachable.rb +++ b/lib/plugins/acts_as_attachable/lib/acts_as_attachable.rb @@ -43,8 +43,13 @@ module Redmine end def attachments_visible?(user=User.current) - (respond_to?(:visible?) ? visible?(user) : true) && - user.allowed_to?(self.class.attachable_options[:view_permission], self.project) + if self.respond_to?(:project) + (respond_to?(:visible?) ? visible?(user) : true) && + user.allowed_to?(self.class.attachable_options[:view_permission], self.project) + else + return true + end + end def attachments_deletable?(user=User.current) diff --git a/lib/tasks/user_new_score.rake b/lib/tasks/user_new_score.rake new file mode 100644 index 000000000..19f003f4d --- /dev/null +++ b/lib/tasks/user_new_score.rake @@ -0,0 +1,23 @@ +desc "User New Score description" +task :user_new_score do + puts "user_score sync." +end + +namespace :user_new_score do + desc "calculating user score" + task :calculating => :environment do + include UserScoreHelper + User.all.each do |user| + result = user_scores(user,1).total_score + puts "score of #{user.login} is #{result}" + end + + Project.where("project_type != 1").all.each do |project| + project.member_principals.includes(:roles, :principal).all.each do |member| + result = user_scores(member.user,2,project).total_score + puts "#{user.login}/'s score in #{project.name} is #{result}" + end + end + puts "calculate completed" + end +end \ No newline at end of file diff --git a/lib/tasks/user_score_new.rake b/lib/tasks/user_score_new.rake new file mode 100644 index 000000000..cb0e7ef52 --- /dev/null +++ b/lib/tasks/user_score_new.rake @@ -0,0 +1,453 @@ +desc "User Score description" +task :user_score_new do + puts "user_score sync." +end + +namespace :user_score_new do + desc "calculating user score" + task :calculated => :environment do + include UserScoreHelper + puts "truncating table...#{Rails.env}" + puts "loading..." + # collaboration 鍗忓悓寰楀垎 + users = {} + grades = {} + # 鍙戝笘 + Message.find_by_sql("SELECT `messages`.author_id AS u_id,`boards`.project_id AS p_id, COUNT(*) AS memo_number FROM `messages` JOIN `boards` ON `messages`.board_id = `boards`.id WHERE `messages`.parent_id IS NULL AND `boards`.project_id != -1 GROUP BY `messages`.author_id,`boards`.project_id ").each do|message| + option_num = get_option_num_by_id(message.u_id,2,message.p_id) + option_num.memo = message.memo_number + option_num.save + update_score(option_num) + puts "#{message.u_id}'s memo number in project #{message.p_id}: #{message.memo_number}" + end + + Message.find_by_sql("SELECT `messages`.author_id AS u_id, COUNT(*) AS memo_number FROM `messages` JOIN `boards` ON `messages`.board_id = `boards`.id WHERE `messages`.parent_id IS NULL AND `boards`.project_id != -1 GROUP BY `messages`.author_id").each do|message| + option_num = get_option_num_by_id(message.u_id,1) + option_num.memo = message.memo_number + option_num.save + update_score(option_num) + puts "#{message.u_id}'s memo number: #{message.memo_number}" + end + + + puts "post_message calculate Completed." + # + ## 瀵圭己闄风殑鐣欒█ + Journal.find_by_sql("SELECT user_id AS u_id,COUNT(*) AS m_count FROM journals WHERE journals.notes IS NOT NULL AND journals.notes != '' GROUP BY u_id").each do |journal| + option_num = get_option_num_by_id(journal.u_id,1) + option_num.messages_for_issues = journal.m_count + option_num.save + update_score(option_num) + puts "#{journal.u_id}'s messages_for_issues number: #{journal.m_count}" + end + + Journal.find_by_sql("SELECT #{Journal.table_name}.user_id AS u_id, #{Issue.table_name}.project_id AS p_id ,COUNT(*) as m_count FROM journals join #{Issue.table_name} on #{Journal.table_name}.journalized_type = 'Issue' and #{Journal.table_name}.journalized_id = #{Issue.table_name}.id WHERE journals.notes IS NOT NULL AND journals.notes != '' GROUP BY u_id,p_id").each do |journal| + option_num = get_option_num_by_id(journal.u_id,2,journal.p_id) + option_num.messages_for_issues = journal.m_count + option_num.save + update_score(option_num) + puts "#{journal.u_id}'s messages_for_issues number in project #{journal.p_id}: #{journal.m_count}" + end + + puts ":post_issue_message calculate Completed" + # + ## 鏇存敼涓娆$己闄风姸鎬 + Journal.find_by_sql("SELECT journals.user_id AS u_id, COUNT(*) as m_count FROM journals JOIN journal_details on journals.id = journal_details.journal_id WHERE journal_details.prop_key = 'status_id' GROUP BY u_id").each do |journal| + option_num = get_option_num_by_id(journal.u_id,1) + option_num.issues_status = journal.m_count + option_num.save + update_score(option_num) + puts "#{journal.u_id}'s issues_status number: #{journal.m_count}" + end + + Journal.find_by_sql("SELECT journals.user_id AS u_id,issues.project_id AS p_id,COUNT(*) as m_count FROM journals JOIN journal_details on journals.id = journal_details.journal_id JOIN issues ON issues.id = journals.journalized_id and journalized_type = 'Issue' WHERE journal_details.prop_key = 'status_id' GROUP BY u_id,p_id").each do |journal| + option_num = get_option_num_by_id(journal.u_id,2,journal.p_id) + option_num.issues_status = journal.m_count + option_num.save + update_score(option_num) + puts "#{journal.u_id}'s issues_status number in project #{journal.p_id}: #{journal.m_count}" + end + + puts ":change_issue_status calculate Completed" + # + ## 瀵圭暀瑷鐨勫洖澶 + JournalsForMessage.find_by_sql("SELECT user_id AS u_id,COUNT(*) as m_count From #{JournalsForMessage.table_name} WHERE m_parent_id IS NOT NULL and jour_type = 'Project' GROUP BY u_id").each do |jfm| + option_num = get_option_num_by_id(jfm.u_id,1) + option_num.replay_for_message = jfm.m_count + option_num.save + update_score(option_num) + puts "#{jfm.u_id}'s replay_for_message number: #{jfm.m_count}" + end + + JournalsForMessage.find_by_sql("SELECT user_id AS u_id,jour_id AS p_id,COUNT(*) as m_count From #{JournalsForMessage.table_name} WHERE m_parent_id IS NOT NULL and jour_type = 'Project' GROUP BY u_id,p_id").each do |jfm| + option_num = get_option_num_by_id(jfm.u_id,2,jfm.p_id) + option_num.replay_for_message = jfm.m_count + option_num.save + update_score(option_num) + puts "#{jfm.u_id}'s replay_for_message number in project #{jfm.p_id}: #{jfm.m_count}" + end + + puts ":reply_message calculate Completed" + # + ## 瀵瑰笘瀛愮殑鍥炲 + Message.find_by_sql("SELECT messages.author_id AS u_id, COUNT(*) as m_count FROM messages JOIN boards on messages.board_id = boards.id WHERE messages.parent_id IS NOT NULL AND boards.project_id != -1 GROUP BY u_id").each do |message| + option_num = get_option_num_by_id(message.u_id,1) + option_num.replay_for_memo = message.m_count + option_num.save + update_score(option_num) + puts "#{message.u_id}'s replay_for_memo number: #{message.m_count}" + end + + Message.find_by_sql("SELECT messages.author_id AS u_id,boards.project_id AS p_id,COUNT(*) as m_count FROM messages JOIN boards on messages.board_id = boards.id WHERE messages.parent_id IS NOT NULL AND boards.project_id != -1 GROUP BY u_id,p_id").each do |message| + option_num = get_option_num_by_id(message.u_id,2,message.p_id) + option_num.replay_for_memo = message.m_count + option_num.save + update_score(option_num) + puts "#{message.u_id}'s replay_for_memo number in project #{message.p_id}: #{message.m_count}" + end + + puts ":reply_posting calculate Completed." + # + #UserScore.transaction do + # users.each do |user_id, score| + # UserScore.find_or_create_by_user_id(user_id).update_attribute(:collaboration, score) + # end + #end + #puts "=== UserScore#collaboration calculate Completed. collaboration users count: #{users.count}" + #puts "" + # + #users.clear + # + ## influence 褰卞搷鍔涘緱鍒 + ##鍏虫敞 + Watcher.find_by_sql("SELECT watchable_id AS u_id ,COUNT(*) as m_count FROM #{Watcher.table_name} WHERE watchable_type = 'Principal' GROUP BY u_id").each do |watcher| + option_num = get_option_num_by_id(watcher.u_id,1) + option_num.follow = watcher.m_count + option_num.save + update_score(option_num) + puts "#{watcher.u_id}'s follow number: #{watcher.m_count}" + end + puts ":followed_by calculate Completed." + # + #UserScore.transaction do + # users_influence.each do |user_id, score| + # UserScore.find_or_create_by_user_id(user_id).update_attribute(:influence, score) + # end + #end + #puts "=== UserScore#influence calculate Completed. influence users count: #{users_influence.count}" + #puts "" + ## skill 鎶鏈緱鍒 + + #璁$畻鐩稿叧user鐨勭瓑绾 + PraiseTread.find_by_sql("SELECT user_id AS u_id,COUNT(*) AS m_count FROM `praise_treads` WHERE praise_tread_object_type IN ( 'Issue','Message') GROUP BY u_id").each do |pt| + user = User.find(pt.u_id) + level = UserLevels.get_level(user) + puts "user #{user.login}'s level is #{level}" + end + ## 韪╁笘 + PraiseTread.find_by_sql("SELECT user_id AS u_id,COUNT(*) AS m_count FROM `praise_treads` WHERE praise_tread_object_type IN ( 'Issue','Message') AND praise_or_tread = 0 GROUP BY u_id").each do |pt| + #韪╁埆浜烘墸鍒 + option_num = get_option_num_by_id(pt.u_id,1) + option_num.tread = pt.m_count + option_num.save + update_score(option_num) + puts "#{pt.u_id}'s tread number: #{pt.m_count}" + end + + + #SELECT AS u_id,COUNT(*) AS m_count FROM `praise_treads` JOIN issues ON `issues`.id = `praise_treads`.praise_tread_object_id AND `praise_treads`.praise_tread_object_type = 'Issue' WHERE praise_or_tread = 0 GROUP BY u_id + PraiseTread.find_by_sql("SELECT `issues`.author_id AS target_u_id,`user_levels`.level AS u_level,COUNT(*) AS m_count FROM `praise_treads` JOIN issues ON `issues`.id =`praise_treads`.praise_tread_object_id AND `praise_treads`.praise_tread_object_type = 'Issue' JOIN `user_levels` ON `praise_treads`.user_id = `user_levels`.user_id WHERE praise_or_tread = 0 GROUP BY target_u_id,u_level").each do |pt| + #缂洪櫡琚汉韪╃殑娆℃暟 + option_num = get_option_num_by_id(pt.target_u_id,1) + if pt.u_level == 1 + option_num.tread_by_one = pt.m_count + puts "user #{pt.target_u_id} tread by one-level member #{pt.m_count} times " + elsif pt.u_level == 2 + option_num.tread_by_two = pt.m_count + puts "user #{pt.target_u_id} tread by two-level member #{pt.m_count} times " + elsif pt.u_level == 3 + option_num.tread_by_three = pt.m_count + puts "user #{pt.target_u_id} tread by three-level member #{pt.m_count} times " + else + puts "level error!:#{pt.u_level}" + next + end + option_num.save + update_score(option_num) + end + + PraiseTread.find_by_sql("SELECT `praise_treads`.user_id AS u_id,`issues`.project_id AS p_id, COUNT(*) AS m_count FROM `praise_treads` JOIN issues ON `issues`.id =`praise_treads`.praise_tread_object_id AND `praise_treads`.praise_tread_object_type = 'Issue' WHERE praise_or_tread = 0 GROUP BY u_id,p_id").each do |pt| + #椤圭洰涓俯鍒汉缂洪櫡鐨勬鏁 + option_num = get_option_num_by_id(pt.u_id,2,pt.p_id) + option_num.tread = pt.m_count + option_num.save + update_score(option_num) + puts "#{pt.u_id}'s tread number: #{pt.m_count}" + end + + #椤圭洰涓浜鸿俯缂洪櫡鐨勬鏁 + PraiseTread.find_by_sql("SELECT `issues`.author_id AS target_u_id,`issues`.project_id AS p_id,`user_levels`.level AS u_level,COUNT(*) AS m_count FROM `praise_treads` JOIN issues ON `issues`.id =`praise_treads`.praise_tread_object_id AND `praise_treads`.praise_tread_object_type = 'Issue' JOIN `user_levels` ON `praise_treads`.user_id = `user_levels`.user_id WHERE praise_or_tread = 0 GROUP BY target_u_id,p_id,u_level").each do |pt| + option_num = get_option_num_by_id(pt.target_u_id,2,pt.p_id) + if pt.u_level == 1 + option_num.tread_by_one = pt.m_count + puts "user #{pt.target_u_id} tread by one-level member in project #{pt.p_id} #{pt.m_count} times " + elsif pt.u_level == 2 + option_num.tread_by_two = pt.m_count + puts "user #{pt.target_u_id} tread by two-level member in project #{pt.p_id} #{pt.m_count} times " + elsif pt.u_level == 3 + option_num.tread_by_three = pt.m_count + puts "user #{pt.target_u_id} tread by three-level member in project #{pt.p_id} #{pt.m_count} times " + else + puts "level error!:#{pt.u_level}" + next + end + option_num.save + update_score(option_num) + end + + PraiseTread.find_by_sql("SELECT `messages`.author_id AS target_u_id,`user_levels`.level AS u_level,COUNT(*) AS m_count FROM `praise_treads` JOIN messages ON `messages`.id =`praise_treads`.praise_tread_object_id AND `praise_treads`.praise_tread_object_type = 'Message' JOIN `user_levels` ON `praise_treads`.user_id = `user_levels`.user_id WHERE praise_or_tread = 0 GROUP BY target_u_id,u_level").each do |pt| + #璁ㄨ鍖鸿浜鸿俯鐨勬鏁 + option_num = get_option_num_by_id(pt.target_u_id,1) + if pt.u_level == 1 + option_num.tread_by_one += pt.m_count + puts "user #{pt.target_u_id} tread by one-level member #{pt.m_count} times " + elsif pt.u_level == 2 + option_num.tread_by_two += pt.m_count + puts "user #{pt.target_u_id} tread by two-level member #{pt.m_count} times " + elsif pt.u_level == 3 + option_num.tread_by_three += pt.m_count + puts "user #{pt.target_u_id} tread by three-level member #{pt.m_count} times " + else + puts "level error!:#{pt.u_level}" + next + end + option_num.save + update_score(option_num) + end + + PraiseTread.find_by_sql("SELECT `praise_treads`.user_id AS u_id,`boards`.project_id AS p_id, COUNT(*) AS m_count FROM `praise_treads` JOIN messages ON `messages`.id =`praise_treads`.praise_tread_object_id AND `praise_treads`.praise_tread_object_type = 'Message' JOIN `boards` ON `boards`.id = `messages`.board_id AND `boards`.project_id != '-1' WHERE praise_or_tread = 0 GROUP BY u_id , p_id").each do |pt| + #椤圭洰璁ㄨ鍖轰腑韪╁埆浜虹殑娆℃暟 + option_num = get_option_num_by_id(pt.u_id,2,pt.p_id) + option_num.tread += pt.m_count + option_num.save + update_score(option_num) + puts "#{pt.u_id}'s tread number: #{pt.m_count}" + end + + #椤圭洰涓浜鸿俯鐨勬鏁 + PraiseTread.find_by_sql("SELECT `messages`.author_id AS target_u_id,`boards`.project_id AS p_id,`user_levels`.level AS u_level,COUNT(*) AS m_count FROM `praise_treads` JOIN messages ON `messages`.id =`praise_treads`.praise_tread_object_id AND `praise_treads`.praise_tread_object_type = 'Message' JOIN `user_levels` ON `praise_treads`.user_id = `user_levels`.user_id JOIN `boards` ON `boards`.id = `messages`.board_id AND `boards`.project_id != '-1' WHERE praise_or_tread = 0 GROUP BY target_u_id,p_id,u_level").each do |pt| + option_num = get_option_num_by_id(pt.target_u_id,2,pt.p_id) + if pt.u_level == 1 + option_num.tread_by_one += pt.m_count + puts "user #{pt.target_u_id} tread by one-level member in project #{pt.p_id} #{pt.m_count} times " + elsif pt.u_level == 2 + option_num.tread_by_two += pt.m_count + puts "user #{pt.target_u_id} tread by two-level member in project #{pt.p_id} #{pt.m_count} times " + elsif pt.u_level == 3 + option_num.tread_by_three += pt.m_count + puts "user #{pt.target_u_id} tread by three-level member in project #{pt.p_id} #{pt.m_count} times " + else + puts "level error!:#{pt.u_level}" + next + end + option_num.save + update_score(option_num) + end + + #椤惰创 + #SELECT AS u_id,COUNT(*) AS m_count FROM `praise_treads` JOIN issues ON `issues`.id = `praise_treads`.praise_tread_object_id AND `praise_treads`.praise_tread_object_type = 'Issue' WHERE praise_or_tread = 0 GROUP BY u_id + PraiseTread.find_by_sql("SELECT `issues`.author_id AS target_u_id,`user_levels`.level AS u_level,COUNT(*) AS m_count FROM `praise_treads` JOIN issues ON `issues`.id =`praise_treads`.praise_tread_object_id AND `praise_treads`.praise_tread_object_type = 'Issue' JOIN `user_levels` ON `praise_treads`.user_id = `user_levels`.user_id WHERE praise_or_tread = 1 GROUP BY target_u_id,u_level").each do |pt| + #缂洪櫡琚汉椤剁殑娆℃暟 + option_num = get_option_num_by_id(pt.target_u_id,1) + if pt.u_level == 1 + option_num.praise_by_one = pt.m_count + puts "user #{pt.target_u_id} praise by one-level member #{pt.m_count} times " + elsif pt.u_level == 2 + option_num.praise_by_two = pt.m_count + puts "user #{pt.target_u_id} praise by two-level member #{pt.m_count} times " + elsif pt.u_level == 3 + option_num.praise_by_three = pt.m_count + puts "user #{pt.target_u_id} praise by three-level member #{pt.m_count} times " + else + puts "level error!:#{pt.u_level}" + next + end + option_num.save + update_score(option_num) + end + + #椤圭洰涓浜洪《缂洪櫡鐨勬鏁 + PraiseTread.find_by_sql("SELECT `issues`.author_id AS target_u_id,`issues`.project_id AS p_id,`user_levels`.level AS u_level,COUNT(*) AS m_count FROM `praise_treads` JOIN issues ON `issues`.id =`praise_treads`.praise_tread_object_id AND `praise_treads`.praise_tread_object_type = 'Issue' JOIN `user_levels` ON `praise_treads`.user_id = `user_levels`.user_id WHERE praise_or_tread = 1 GROUP BY target_u_id,p_id,u_level").each do |pt| + option_num = get_option_num_by_id(pt.target_u_id,2,pt.p_id) + if pt.u_level == 1 + option_num.praise_by_one = pt.m_count + puts "user #{pt.target_u_id} praise by one-level member in project #{pt.p_id} #{pt.m_count} times " + elsif pt.u_level == 2 + option_num.praise_by_two = pt.m_count + puts "user #{pt.target_u_id} praise by two-level member in project #{pt.p_id} #{pt.m_count} times " + elsif pt.u_level == 3 + option_num.praise_by_three = pt.m_count + puts "user #{pt.target_u_id} praise by three-level member in project #{pt.p_id} #{pt.m_count} times " + else + puts "level error!:#{pt.u_level}" + next + end + option_num.save + update_score(option_num) + end + + PraiseTread.find_by_sql("SELECT `messages`.author_id AS target_u_id,`user_levels`.level AS u_level,COUNT(*) AS m_count FROM `praise_treads` JOIN messages ON `messages`.id =`praise_treads`.praise_tread_object_id AND `praise_treads`.praise_tread_object_type = 'Message' JOIN `user_levels` ON `praise_treads`.user_id = `user_levels`.user_id WHERE praise_or_tread = 1 GROUP BY target_u_id,u_level").each do |pt| + #璁ㄨ鍖鸿浜洪《鐨勬鏁 + option_num = get_option_num_by_id(pt.target_u_id,1) + if pt.u_level == 1 + option_num.praise_by_one += pt.m_count + puts "user #{pt.target_u_id} praise by one-level member #{pt.m_count} times " + elsif pt.u_level == 2 + option_num.praise_by_two += pt.m_count + puts "user #{pt.target_u_id} praise by two-level member #{pt.m_count} times " + elsif pt.u_level == 3 + option_num.praise_by_three += pt.m_count + puts "user #{pt.target_u_id} praise by three-level member #{pt.m_count} times " + else + puts "level error!:#{pt.u_level}" + next + end + option_num.save + update_score(option_num) + end + + #椤圭洰涓浜鸿俯鐨勬鏁 + PraiseTread.find_by_sql("SELECT `messages`.author_id AS target_u_id,`boards`.project_id AS p_id,`user_levels`.level AS u_level,COUNT(*) AS m_count FROM `praise_treads` JOIN messages ON `messages`.id =`praise_treads`.praise_tread_object_id AND `praise_treads`.praise_tread_object_type = 'Message' JOIN `user_levels` ON `praise_treads`.user_id = `user_levels`.user_id JOIN `boards` ON `boards`.id = `messages`.board_id AND `boards`.project_id != '-1' WHERE praise_or_tread = 1 GROUP BY target_u_id,p_id,u_level").each do |pt| + option_num = get_option_num_by_id(pt.target_u_id,2,pt.p_id) + if pt.u_level == 1 + option_num.praise_by_one += pt.m_count + puts "user #{pt.target_u_id} praise by one-level member in project #{pt.p_id} #{pt.m_count} times " + elsif pt.u_level == 2 + option_num.praise_by_two += pt.m_count + puts "user #{pt.target_u_id} praise by two-level member in project #{pt.p_id} #{pt.m_count} times " + elsif pt.u_level == 3 + option_num.praise_by_three += pt.m_count + puts "user #{pt.target_u_id} praise by three-level member in project #{pt.p_id} #{pt.m_count} times " + else + puts "level error!:#{pt.u_level}" + next + end + option_num.save + update_score(option_num) + end + + puts "UserScore#skill calculate Completed." + #puts "" + # + ## active 椤圭洰璐$尞寰楀垎 + ## 鎻愪氦浠g爜 + Changeset.find_by_sql("SELECT user_id AS u_id, COUNT(*) AS m_count FROM `changesets` GROUP BY u_id").each do |changeset| + unless changeset.u_id.nil? + option_num = get_option_num_by_id(changeset.u_id,1) + option_num.changeset = changeset.m_count + option_num.save + update_score(option_num) + puts "#{changeset.u_id}'s changeset number: #{changeset.m_count}" + end + end + + Changeset.find_by_sql("SELECT `changesets`.user_id AS u_id, `repositories`.project_id AS p_id,COUNT(*) AS m_count FROM `changesets` JOIN `repositories` ON `repositories`.id = `changesets`.repository_id GROUP BY u_id,p_id ").each do |changeset| + unless changeset.nil? + option_num = get_option_num_by_id(changeset.u_id,2,changeset.p_id) + option_num.changeset = changeset.m_count + option_num.save + update_score(option_num) + puts "#{changeset.u_id}'s changeset number in project #{changeset.p_id}: #{changeset.m_count}" + end + end + + puts ":push_code calculate Completed." + ##鎻愪氦鏂囨。 + Document.find_by_sql("SELECT user_id AS u_id ,COUNT(*) AS m_count FROM `documents` GROUP BY user_id").each do |document| + option_num = get_option_num_by_id(document.u_id,1) + option_num.document = document.m_count + option_num.save + update_score(option_num) + puts "#{document.u_id}'s document number: #{document.m_count}" + end + + Document.find_by_sql("SELECT user_id AS u_id , project_id AS p_id, COUNT(*) AS m_count FROM `documents` GROUP BY u_id,p_id").each do |document| + option_num = get_option_num_by_id(document.u_id,2,document.p_id) + option_num.document = document.m_count + option_num.save + update_score(option_num) + puts "#{document.u_id}'s document number in project #{document.p_id}: #{document.m_count}" + end + + puts ":push_document calculate Completed." + ##鎻愪氦闄勪欢 + Attachment.find_by_sql("SELECT author_id AS u_id,COUNT(*) as m_count FROM #{Attachment.table_name} WHERE container_type = 'Project' GROUP By u_id").each do |attachment| + option_num = get_option_num_by_id(attachment.u_id,1) + option_num.attachment = attachment.m_count + option_num.save + update_score(option_num) + puts "#{attachment.u_id}'s attachment number: #{attachment.m_count}" + end + + Attachment.find_by_sql("SELECT author_id AS u_id,container_id AS p_id,COUNT(*) as m_count FROM #{Attachment.table_name} WHERE container_type = 'Project' GROUP By u_id,p_id").each do |attachment| + option_num = get_option_num_by_id(attachment.u_id,2,attachment.p_id) + option_num.attachment = attachment.m_count + option_num.save + update_score(option_num) + puts "#{attachment.u_id}'s attachment number in project #{attachment.p_id}: #{attachment.m_count}" + end + + puts ":push_file calculate Completed." + ##鏇存柊瀹屾垚搴 + Journal.find_by_sql("SELECT #{Journal.table_name}.user_id AS u_id, COUNT(*) as m_count FROM #{Journal.table_name} JOIN #{JournalDetail.table_name} ON #{JournalDetail.table_name}.journal_id = #{Journal.table_name}.id WHERE #{JournalDetail.table_name}.prop_key = 'done_ratio' GROUP BY u_id ").each do |j| + option_num = get_option_num_by_id(j.u_id,1) + option_num.issue_done_ratio = j.m_count + option_num.save + update_score(option_num) + puts "#{j.u_id}'s issue_done_ratio number: #{j.m_count}" + end + + Journal.find_by_sql("SELECT #{Journal.table_name}.user_id AS u_id, #{Issue.table_name}.project_id AS p_id,COUNT(*) as m_count FROM #{Journal.table_name} JOIN #{JournalDetail.table_name} ON #{JournalDetail.table_name}.journal_id = #{Journal.table_name}.id JOIN issues ON issues.id = journals.journalized_id and journalized_type = 'Issue' WHERE #{JournalDetail.table_name}.prop_key = 'done_ratio' GROUP BY u_id,p_id ").each do |j| + option_num = get_option_num_by_id(j.u_id,2,j.p_id) + option_num.issue_done_ratio = j.m_count + option_num.save + update_score(option_num) + puts "#{j.u_id}'s issue_done_ratio number in project #{j.p_id}: #{j.m_count}" + end + + puts ":update_issue_ratio calculate Completed." + ##鍙戝竷缂洪櫡 + Issue.find_by_sql("SELECT author_id AS u_id,COUNT(*) as m_count FROM #{Issue.table_name} GROUP BY u_id").each do |issues| + option_num = get_option_num_by_id(issues.u_id,1) + option_num.post_issue = issues.m_count + option_num.save + update_score(option_num) + puts "#{issues.u_id}'s issues number: #{issues.m_count}" + end + + Issue.find_by_sql("SELECT author_id AS u_id,project_id AS p_id,COUNT(*) as m_count FROM #{Issue.table_name} GROUP BY u_id,p_id").each do |issues| + option_num = get_option_num_by_id(issues.u_id,2,issues.p_id) + option_num.post_issue = issues.m_count + option_num.save + update_score(option_num) + puts "#{issues.u_id}'s issues number in project #{issues.p_id}: #{issues.m_count}" + end + puts ":post_issue calculate Completed." + # + # + #UserScore.transaction do + # users_active.each do |user_id, score| + # UserScore.find_or_create_by_user_id(user_id).update_attribute(:active, score) + # end + #end + #puts "=== UserScore#active calculate Completed. active users count: #{users_active.count}" + #UserGrade.transaction do + # grades.each do |grade_id,score| + # grade = UserGrade.find(grade_id) + # grade.grade = score + # grade.save + # end + #end + #puts "=== UserGrid calculate Completed. UserGrids count: #{grades.count}" + end +end \ No newline at end of file diff --git a/plugins/redmine_code_review/app/views/code_review/_issues_show_details_bottom.html.erb b/plugins/redmine_code_review/app/views/code_review/_issues_show_details_bottom.html.erb index e60198fff..480119ca7 100644 --- a/plugins/redmine_code_review/app/views/code_review/_issues_show_details_bottom.html.erb +++ b/plugins/redmine_code_review/app/views/code_review/_issues_show_details_bottom.html.erb @@ -46,8 +46,8 @@ review = issue.code_review %> <%= l(:label_revision) + " "%> <%= link_to_revision(assignment.revision, repo) %> - <% elsif assignment.attachment %> - <%= link_to(assignment.attachment.filename, :controller => 'attachments', :action => 'show', :id => attachment.id) %> + <% elsif assignment.respond_to?("attachment") && assignment.attachment %> + <%= link_to(assignment.attachment.filename.to_s, :controller => 'attachments', :action => 'show', :id => assignment.attachment.id) %> <% end %> diff --git a/plugins/redmine_code_review/app/views/code_review/_new_form.html.erb b/plugins/redmine_code_review/app/views/code_review/_new_form.html.erb index 81feda16e..79d0e6f9f 100644 --- a/plugins/redmine_code_review/app/views/code_review/_new_form.html.erb +++ b/plugins/redmine_code_review/app/views/code_review/_new_form.html.erb @@ -107,7 +107,7 @@ <% submit_url = url_for(:controller => 'code_review', :action => 'new', :id=>@project) %> - <%= button_to_function l(:button_apply), "$('#review-form').load('#{submit_url}', $('#review_form').serialize2json())" %> + <%= button_to_function l(:label_button_ok), "$('#review-form').load('#{submit_url}', $('#review_form').serialize2json())" %> <%= preview_link({ :controller => 'code_review', :action => 'preview', :id => @project}, 'review_form') %> diff --git a/plugins/redmine_code_review/app/views/code_review/_reply.html.erb b/plugins/redmine_code_review/app/views/code_review/_reply.html.erb index 7fccf0aa3..3fd5676c5 100644 --- a/plugins/redmine_code_review/app/views/code_review/_reply.html.erb +++ b/plugins/redmine_code_review/app/views/code_review/_reply.html.erb @@ -20,7 +20,8 @@ <%= authoring reply.created_on, reply.user %>.

    - <%= avatar(reply.user, :size => "32") %> + <%= image_tag(url_to_avatar(reply.user), :class => 'avatar2', :width=>32, :height=>32) %> + <%#= avatar(reply.user, :size => "32") %>