diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index e12d4886a..7d26b2eca 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -615,6 +615,10 @@ class CoursesController < ApplicationController end def show + #更新创建课程消息状态 + create_course_messages = @course.course_messages.where("user_id =? and course_message_type =? and course_id =? and viewed =?", User.current.id, 'Course', @course.id, 0) + create_course_messages.update_all(:viewed => true) + course_activities = @course.course_activities @canShowRealName = User.current.member_of_course? @course @page = params[:page] ? params[:page].to_i + 1 : 0 diff --git a/app/controllers/members_controller.rb b/app/controllers/members_controller.rb index 6271a6832..6bb61e6a1 100644 --- a/app/controllers/members_controller.rb +++ b/app/controllers/members_controller.rb @@ -81,8 +81,12 @@ class MembersController < ApplicationController user_ids.each do |user_id| members << Member.new(:role_ids => params[:membership][:role_ids], :user_id => user_id) user_grades << UserGrade.new(:user_id => user_id, :project_id => @project.id) - ## added by nie + #给新成员发送加入项目的消息,发送者id放在ForgeMessage的forge_message_id字段中, + #forge_message_type设置为JoinProject + forge_join = ForgeMessage.new(:user_id =>user_id, :forge_message_id=>User.current.id,:project_id => @project.id,:forge_message_type=>"JoinProject", :viewed => false) + forge_join.save + ## added by nie if (params[:membership][:role_ids]) role = Role.find(params[:membership][:role_ids][0]) project_info << ProjectInfo.new(:user_id => user_id, :project_id => @project.id) if role.allowed_to?(:is_manager) @@ -301,6 +305,7 @@ class MembersController < ApplicationController grade.destroy end end + ForgeMessage.create(:user_id => @member.user_id, :project_id => @project.id, :forge_message_type => "RemoveFromProject", :viewed => false, :forge_message_id => User.current.id) end respond_to do |format| format.html { redirect_to_settings_in_projects } diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 90974b376..d26e465ba 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -534,6 +534,14 @@ class ProjectsController < ApplicationController project_invite_messages.each do |project_invite_message| project_invite_message.update_attribute(:viewed, true) end + #更新被加入项目消息的viewed字段 + join_project_messages = ForgeMessage.where("user_id =? and project_id =? and forge_message_type=?", user, project, "JoinProject") + join_project_messages.each do |join_project| + join_project.update_attribute(:viewed, true) + end + #更新被移出项目消息的viewed字段 + remove_project_messages = ForgeMessage.where("user_id =? and project_id =? and forge_message_type=?", user, project, "RemoveFromProject") + remove_project_messages.update_all(:viewed => true) end def message_invite(message_id, key) diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 9d1284fde..24bd10186 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -29,7 +29,7 @@ class RepositoriesController < ApplicationController menu_item :repository menu_item :settings, :only => [:new, :create, :edit, :update, :destroy, :committers] default_search_scope :changesets - + before_filter :find_project_by_project_id, :only => [:new, :create, :newrepo] before_filter :find_repository, :only => [:edit, :update, :destroy, :committers] before_filter :find_project_repository, :except => [:new, :create, :newcreate, :edit, :update, :destroy, :committers, :newrepo,:to_gitlab] @@ -42,7 +42,7 @@ class RepositoriesController < ApplicationController include RepositoriesHelper helper :project_score #@root_path = RepositoriesHelper::ROOT_PATH - + rescue_from Redmine::Scm::Adapters::CommandFailed, :with => :show_error_command_failed def new @@ -62,8 +62,8 @@ class RepositoriesController < ApplicationController end end - - + + def newrepo scm = params[:repository_scm] || (Redmine::Scm::Base.all & Setting.enabled_scm).first @repository = Repository.factory(scm) @@ -76,23 +76,23 @@ class RepositoriesController < ApplicationController render :layout => 'base_projects' end end - + def fork @repository_url = params[:repository_url] - + # @repository.url # system "htpasswd -mb "+@root_path+"user.passwd "+params[:repository][:identifier]+" "+@upasswd # system "echo -e '"+params[:project_id]+"-"+params[:repository][:identifier]+"-write:"+ - # " "+params[:repository][:identifier]+"' >> "+@root_path+"group.passwd" - system "git clone --bare "+@repository_url + # " "+params[:repository][:identifier]+"' >> "+@root_path+"group.passwd" + system "git clone --bare "+@repository_url # system "mv "+@project_path+"/hooks/post-update{.sample,}" # system "chmod a+x "+@project_path+"/hooks/post-update" # system "."+@project_path+"/hooks/post-update" # system "echo -e 'Allow from all \n Order Deny,Allow \n "+ - # " \n"+ - # "Require group "+params[:project_id]+"-"+params[:repository][:identifier]+"-write \n "+ - # " \n ' >>"+ - # @project_path+"/.htaccess" + # " \n"+ + # "Require group "+params[:project_id]+"-"+params[:repository][:identifier]+"-write \n "+ + # " \n ' >>"+ + # @project_path+"/.htaccess" flash[:notice] = l(:label_notice_fork_successed) @repositories = @project.repositories render :action => 'show', :layout => 'base_projects' @@ -139,13 +139,12 @@ update ) @project.gpid = gproject.id @project.save! - redirect_to settings_project_url(@project, :tab => 'repositories') else redirect_to settings_project_url(@project, :tab => 'repositories',:repository_error_message=>@repository.errors.full_messages) end end - + def edit end @@ -190,11 +189,11 @@ update flash[:notice] = l(:notice_successful_update) redirect_to settings_project_url(@project, :tab => 'repositories') elsif request.get? - respond_to do |format| - format.html{ - render :layout => "base_projects" - } - end + respond_to do |format| + format.html{ + render :layout => "base_projects" + } + end end @@ -251,7 +250,7 @@ update @entries ? render(:partial => 'dir_list_content') : render(:nothing => true) else #Modified by young - # (show_error_not_found; return) unless @entries + # (show_error_not_found; return) unless @entries @changesets = @repository.latest_changesets(@path, @rev) @properties = @repository.properties(@path, @rev) @repositories = @project.repositories @@ -259,7 +258,7 @@ update project_path_cut = RepositoriesHelper::PROJECT_PATH_CUT ip = RepositoriesHelper::REPO_IP_ADDRESS @repos_url = "http://"+@repository.login.to_s+"_"+@repository.identifier.to_s+"@"+ip.to_s+ - @repository.url.slice(project_path_cut, @repository.url.length).to_s + @repository.url.slice(project_path_cut, @repository.url.length).to_s if @course_tag == 1 render :action => 'show', :layout => 'base_courses' else @@ -285,10 +284,10 @@ update per_page_option, params['page'] @changesets = @repository.changesets. - limit(@changeset_pages.per_page). - offset(@changeset_pages.offset). - includes(:user, :repository, :parents). - all + limit(@changeset_pages.per_page). + offset(@changeset_pages.offset). + includes(:user, :repository, :parents). + all respond_to do |format| format.html { render :layout => 'base_projects' } @@ -314,8 +313,8 @@ update @content = @repository.cat(@path, @rev) (show_error_not_found; return) unless @content if is_raw || - (@content.size && @content.size > Setting.file_max_size_displayed.to_i.kilobyte) || - ! is_entry_text_data?(@content, @path) + (@content.size && @content.size > Setting.file_max_size_displayed.to_i.kilobyte) || + ! is_entry_text_data?(@content, @path) # Force the download send_opt = { :filename => filename_for_content_disposition(@path.split('/').last) } send_type = Redmine::MimeType.of(@path) @@ -398,8 +397,8 @@ update filename = "changeset_r#{@rev}" filename << "_r#{@rev_to}" if @rev_to send_data @diff.join, :filename => "#{filename}.diff", - :type => 'text/x-patch', - :disposition => 'attachment' + :type => 'text/x-patch', + :disposition => 'attachment' else @diff_type = params[:type] || User.current.pref[:diff_type] || 'inline' @diff_type = 'inline' unless %w(inline sbs).include?(@diff_type) @@ -410,7 +409,7 @@ update User.current.preference.save end @cache_key = "repositories/diff/#{@repository.id}/" + - Digest::MD5.hexdigest("#{@path}-#{@rev}-#{@rev_to}-#{@diff_type}-#{current_language}") + Digest::MD5.hexdigest("#{@path}-#{@rev}-#{@rev_to}-#{@diff_type}-#{current_language}") unless read_fragment(@cache_key) @diff = @repository.diff(@path, @rev, @rev_to) unless @diff @@ -437,16 +436,16 @@ update def graph data = nil case params[:graph] - when "commits_per_month" - data = graph_commits_per_month(@repository) - when "commits_per_author" - data = graph_commits_per_author(@repository) - when "author_commits_per_month" - data = graph_author_commits_per_month(@repository) - when "author_commits_six_month" - data = author_commits_six_month(@repository) - when "author_code_six_months" - data = author_code_six_month(@repository) + when "commits_per_month" + data = graph_commits_per_month(@repository) + when "commits_per_author" + data = graph_commits_per_author(@repository) + when "author_commits_per_month" + data = graph_author_commits_per_month(@repository) + when "author_commits_six_month" + data = author_commits_six_month(@repository) + when "author_code_six_months" + data = author_code_six_month(@repository) end if data headers["Content-Type"] = "image/svg+xml" @@ -526,14 +525,14 @@ update @date_from = @date_to << 11 @date_from = Date.civil(@date_from.year, @date_from.month, 1) commits_by_day = Changeset.count( - :all, :group => :commit_date, - :conditions => ["repository_id = ? AND commit_date BETWEEN ? AND ?", repository.id, @date_from, @date_to]) + :all, :group => :commit_date, + :conditions => ["repository_id = ? AND commit_date BETWEEN ? AND ?", repository.id, @date_from, @date_to]) commits_by_month = [0] * 12 commits_by_day.each {|c| commits_by_month[(@date_to.month - c.first.to_date.month) % 12] += c.last } changes_by_day = Change.count( - :all, :group => :commit_date, :include => :changeset, - :conditions => ["#{Changeset.table_name}.repository_id = ? AND #{Changeset.table_name}.commit_date BETWEEN ? AND ?", repository.id, @date_from, @date_to]) + :all, :group => :commit_date, :include => :changeset, + :conditions => ["#{Changeset.table_name}.repository_id = ? AND #{Changeset.table_name}.commit_date BETWEEN ? AND ?", repository.id, @date_from, @date_to]) changes_by_month = [0] * 12 changes_by_day.each {|c| changes_by_month[(@date_to.month - c.first.to_date.month) % 12] += c.last } @@ -541,26 +540,26 @@ update 12.times {|m| fields << month_name(((Date.today.month - 1 - m) % 12) + 1)} graph = SVG::Graph::Bar.new( - :height => 300, - :width => 600, - :fields => fields.reverse, - :stack => :side, - :scale_integers => true, - :step_x_labels => 2, - :show_data_values => true, - :graph_title => l(:label_commits_per_month), - :show_graph_title => true + :height => 300, + :width => 600, + :fields => fields.reverse, + :stack => :side, + :scale_integers => true, + :step_x_labels => 2, + :show_data_values => true, + :graph_title => l(:label_commits_per_month), + :show_graph_title => true ) # 具状图 graph.add_data( - :data => commits_by_month[0..11].reverse, - :title => l(:label_revision_plural) + :data => commits_by_month[0..11].reverse, + :title => l(:label_revision_plural) ) graph.add_data( - :data => changes_by_month[0..11].reverse, - :title => l(:label_change_plural) + :data => changes_by_month[0..11].reverse, + :title => l(:label_change_plural) ) graph.burn @@ -585,23 +584,23 @@ update fields = fields.collect {|c| c.gsub(%r{<.+@.+>}, '') } graph = SVG::Graph::BarHorizontal.new( - :height => 400, - :width => 600, - :fields => fields, - :stack => :side, - :scale_integers => true, - :show_data_values => true, - :rotate_y_labels => false, - :graph_title => l(:label_commits_per_author), - :show_graph_title => true + :height => 400, + :width => 600, + :fields => fields, + :stack => :side, + :scale_integers => true, + :show_data_values => true, + :rotate_y_labels => false, + :graph_title => l(:label_commits_per_author), + :show_graph_title => true ) graph.add_data( - :data => commits_data, - :title => l(:label_revision_plural) + :data => commits_data, + :title => l(:label_revision_plural) ) graph.add_data( - :data => changes_data, - :title => l(:label_change_plural) + :data => changes_data, + :title => l(:label_change_plural) ) graph.burn end @@ -612,7 +611,7 @@ update @date_from = @date_to << 12 @date_from = Date.civil(@date_from.year, @date_from.month, @date_from.day) commits_by_author = Changeset.count(:all, :group => :committer, - :conditions => ["#{Changeset.table_name}.repository_id = ? AND #{Changeset.table_name}.commit_date BETWEEN ? AND ?", repository.id, @date_from, @date_to]) + :conditions => ["#{Changeset.table_name}.repository_id = ? AND #{Changeset.table_name}.commit_date BETWEEN ? AND ?", repository.id, @date_from, @date_to]) commits_by_author = commits_by_author.to_a.sort! {|x, y| x.last <=> y.last}.last(25) fields = commits_by_author.collect {|r| r.first} diff --git a/app/controllers/school_controller.rb b/app/controllers/school_controller.rb index 062b0fa34..d20a58b75 100644 --- a/app/controllers/school_controller.rb +++ b/app/controllers/school_controller.rb @@ -5,14 +5,18 @@ class SchoolController < ApplicationController def upload uploaded_io = params[:logo] school_id ||= params[:id] + s1 = School.find(school_id) unless uploaded_io.nil? File.open(Rails.root.join('public', 'images', 'school', school_id.to_s+'.png'), 'wb') do |file| file.write(uploaded_io.read) end - s1 = School.find(school_id) + s1.logo_link = '/images/school/'+school_id.to_s+'.png' - s1.save + end + s1.name = params[:name] unless params[:name].blank? + s1.province = params[:province] unless params[:province].blank? + s1.save redirect_to admin_schools_url(:school_name => params[:school_name]) end @@ -121,16 +125,18 @@ class SchoolController < ApplicationController end end if(condition == '') - @school = School.all + @school = School.page((params[:page].to_i || 1) - 1).per(100) + @school_count = School.count else - @school = School.where("name like '%#{chinese.join("")}%' and pinyin like '%#{pinyin.join("")}%'").all + @school = School.where("name like '%#{chinese.join("")}%' and pinyin like '%#{pinyin.join("")}%'").page((params[:page].to_i || 1) - 1).per(100) + @school_count = School.where("name like '%#{chinese.join("")}%' and pinyin like '%#{pinyin.join("")}%'").count end result = [] # @school.each do |sc| # result << {:value=>sc.name,:data=>sc.id} # end - render :json => @school.to_json + render :json =>{ :schools => @school,:count=>@school_count}.to_json end #添加学校 diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb index 85c01bcbd..9393339a8 100644 --- a/app/controllers/student_work_controller.rb +++ b/app/controllers/student_work_controller.rb @@ -62,6 +62,9 @@ class StudentWorkController < ApplicationController journals_for_teacher.each do |journal_for_teacher| journal_for_teacher.update_attributes(:viewed => true) end + #不能参与作业匿评消息状态更新 + no_evaluation = CourseMessage.where("user_id =? and course_id =? and course_message_type =? and viewed =?", User.current.id, @homework.course, "NoEvaluation", 0) + no_evaluation.update_all(:viewed => true) # 作品留言 # 消息end #设置作业对应的forge_messages表的viewed字段 diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 90fdbe837..ef3210719 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -128,12 +128,12 @@ class UsersController < ApplicationController #课程相关消息 when 'homework' - @message_alls = CourseMessage.where("course_message_type in ('HomeworkCommon','StudentWorksScore','JournalsForMessage') and user_id =?", @user).order("created_at desc") + @message_alls = CourseMessage.where("course_message_type in ('HomeworkCommon','StudentWorksScore','JournalsForMessage','NoEvaluation') and user_id =?", @user).order("created_at desc") when 'course_message' @message_alls = CourseMessage.where("course_message_type =? and user_id =?", "Message", @user).order("created_at desc") when 'course_news' # 课程通知包含发布的通知和回复的通知 - @message_alls = CourseMessage.where("course_message_type =? or course_message_type =?", "News", "Comment").where("user_id =?", @user).order("created_at desc") + @message_alls = CourseMessage.where("course_message_type in (?, ? ,?)", "News", "Comment", "Course").where("user_id =?", @user).order("created_at desc") when 'poll' @message_alls = CourseMessage.where("course_message_type =? and user_id =?", "Poll", @user).order("created_at desc") @@ -145,7 +145,7 @@ class UsersController < ApplicationController when 'forge_news' @message_alls = ForgeMessage.where("forge_message_type in (?,?) and user_id =?", "News", "Comment", @user).order("created_at desc") when 'apply' - @message_alls = ForgeMessage.where("forge_message_type in ('ProjectInvite', 'AppliedProject') and user_id =?", @user).order("created_at desc") + @message_alls = ForgeMessage.where("forge_message_type in ('ProjectInvite', 'AppliedProject', 'JoinProject', 'RemoveFromProject') and user_id =?", @user).order("created_at desc") #贴吧消息 when 'forum' @@ -881,8 +881,8 @@ class UsersController < ApplicationController @page = params[:page] ? params[:page].to_i + 1 : 0 user_project_ids = @user.projects.visible.empty? ? "(-1)" : "(" + @user.projects.visible.map{|project| project.id}.join(",") + ")" user_course_ids = @user.courses.visible.empty? ? "(-1)" : "(" + @user.courses.visible.map{|course| course.id}.join(",") + ")" - course_types = "('Message','News','HomeworkCommon','Poll')" - project_types = "('Message','Issue')" + course_types = "('Message','News','HomeworkCommon','Poll','Course')" + project_types = "('Message','Issue','ProjectCreateInfo')" principal_types = "JournalsForMessage" if params[:type].present? case params[:type] diff --git a/app/models/course.rb b/app/models/course.rb index 501d958e4..7288c3b3b 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -50,7 +50,9 @@ class Course < ActiveRecord::Base validates_format_of :name,:with =>/^[^ ]+[a-zA-Z0-9_\u4e00-\u9fa5\s\S]+$/ validates_length_of :description, :maximum => 10000 before_save :self_validate - after_create :create_board_sync, :act_as_course_activity + # 公开课程变成私有课程,所有资源都变成私有 + after_update :update_files_public + after_create :create_board_sync, :act_as_course_activity, :act_as_course_message before_destroy :delete_all_members safe_attributes 'extra', @@ -212,6 +214,14 @@ class Course < ActiveRecord::Base def self_validate end + + def update_files_public + unless self.is_public? + self.attachments.each do |a| + a.update_attributes(:is_public => false) + end + end + end # 创建课程讨论区 def create_board_sync @@ -321,6 +331,10 @@ class Course < ActiveRecord::Base self.course_acts << CourseActivity.new(:user_id => self.tea_id,:course_id => self.id) end + #创建课程后,给该用户发送消息 + def act_as_course_message + self.course_messages << CourseMessage.new(:user_id => self.tea_id, :course_id => self.id, :viewed => false) + end #项目与课程分离后,很多课程的名称等信息为空,这些数据信息存储在项目表中!!就是数据兼容的问题 #def name # read_attribute('name') || Project.find_by_identifier(self.extra).try(:name) diff --git a/app/models/student_work.rb b/app/models/student_work.rb index cd4d81a32..700613792 100644 --- a/app/models/student_work.rb +++ b/app/models/student_work.rb @@ -12,6 +12,7 @@ class StudentWork < ActiveRecord::Base before_destroy :delete_praise before_save :set_program_score, :set_src + after_create :act_as_message acts_as_attachable def delete_praise @@ -136,4 +137,11 @@ class StudentWork < ActiveRecord::Base end end end + + def act_as_message + if self.created_at > self.homework_common.end_time + 1 + CourseMessage.create(:user_id => self.user_id, :course_id => self.homework_common.course_id, + :course_message_id => self.id, :course_message_type => 'NoEvaluation',:viewed => false) + end + end end diff --git a/app/views/boards/_course_new.html.erb b/app/views/boards/_course_new.html.erb index a5cbc1c1e..61bbb85d2 100644 --- a/app/views/boards/_course_new.html.erb +++ b/app/views/boards/_course_new.html.erb @@ -4,17 +4,19 @@
- +