diff --git a/.idea/bigdate.iml b/.idea/bigdate.iml new file mode 100644 index 000000000..c92bd62e0 --- /dev/null +++ b/.idea/bigdate.iml @@ -0,0 +1,288 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml new file mode 100644 index 000000000..eed3339c2 --- /dev/null +++ b/.idea/dataSources.xml @@ -0,0 +1,30 @@ + + + + + mysql + com.mysql.jdbc.Driver + jdbc:mysql://127.0.0.1/test + root + dfcbdfc6dfcbdfc4dfc6dfc5dfc4dfcd + + + + mysql + com.mysql.jdbc.Driver + jdbc:mysql://127.0.0.1/test + root + dfcbdfc6dfcbdfc4dfc6dfc5dfc4dfcd + + + + mysql + com.mysql.jdbc.Driver + jdbc:mysql://127.0.0.1/test + root + dfcbdfc6dfcbdfc4dfc6dfc5dfc4dfcd + + + + + diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 000000000..e206d70d8 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 000000000..d95b1f48d --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 000000000..3b312839b --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 000000000..af7fb8d35 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + + Data flow issuesJavaScript + + + Error handlingJavaScript + + + JavaScript + + + JavaScript validity issuesJavaScript + + + Ruby + + + + + DebuggerStatementJS + + + + + + + + + + + + + + + + + + + diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 000000000..e2f26c5c4 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/.idea/scopes/scope_settings.xml b/.idea/scopes/scope_settings.xml new file mode 100644 index 000000000..922003b84 --- /dev/null +++ b/.idea/scopes/scope_settings.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 000000000..c80f2198b --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/app/assets/javascripts/department.js.coffee b/app/assets/javascripts/department.js.coffee new file mode 100644 index 000000000..761567942 --- /dev/null +++ b/app/assets/javascripts/department.js.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ diff --git a/app/assets/stylesheets/department.css.scss b/app/assets/stylesheets/department.css.scss new file mode 100644 index 000000000..b31882b3b --- /dev/null +++ b/app/assets/stylesheets/department.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Department controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/account_controller.rb b/app/controllers/account_controller.rb index d7db4c1bb..65bbd4b7c 100644 --- a/app/controllers/account_controller.rb +++ b/app/controllers/account_controller.rb @@ -22,6 +22,10 @@ class AccountController < ApplicationController # prevents login action to be filtered by check_if_login_required application scope filter skip_before_filter :check_if_login_required + before_filter :auth_login1, :only => [:avatar, :authentication, :security_settings, :change_psd] + + before_filter :require_login, only: [:avatar, :authentication, :security_settings, :change_psd] + # Login request and validation def login if params[:type] == "activated" @@ -317,24 +321,25 @@ class AccountController < ApplicationController req = Hash.new(false) req[:valid] = false type = params[:type].to_i - if type == 1 || type == 2 || params[:phone] =~ /^1\d{10}$/ - code = VerificationCode.where(:phone => params[:phone], :code => params[:code], :code_type => (params[:type].to_i != 1 && params[:type].to_i != 2) ? 2 : params[:type].to_i ).last + if type == 1 || type == 2 || type == 4 || params[:phone] =~ /^1\d{10}$/ + code = VerificationCode.where(:phone => params[:phone], :code => params[:code], :code_type => (params[:type].to_i != 1 && params[:type].to_i != 2 && params[:type].to_i != 4) ? 2 : params[:type].to_i ).last else - code = VerificationCode.where(:email => params[:phone], :code => params[:code], :code_type => 3).last + code = VerificationCode.where(:email => params[:phone], :code => params[:code], :code_type => params[:type].to_i).last end req[:valid] = !code.nil? && (Time.now.to_i - code.created_at.to_i) <= 10*60 render :json => req end - # 发送验证码:type 1:注册手机验证码 2:找回密码手机验证码 3:找回密码邮箱验证码 + # 发送验证码:type 1:注册手机验证码 2:找回密码手机验证码 3:找回密码邮箱验证码 4:绑定手机 5:绑定邮箱 def get_verification_code code = %W(0 1 2 3 4 5 6 7 8 9) type = params[:type].to_i req = Hash.new(false) req[:status] = 0 + req[:msg] = '' if type == 1 if User.where(:phone => params[:value]).count > 0 - req[:status] = 2 + req[:status] = 2 #已注册 else begin verification_code = code.sample(6).join @@ -347,10 +352,10 @@ class AccountController < ApplicationController end req[:status] = 1 end - else + elsif type == 2 || type == 3 if params[:value] =~ /^[a-zA-Z0-9]+([._\\]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/ if User.where(:mail => params[:value]).count == 0 - req[:status] = 2 + req[:status] = 2 #未注册 else begin verification_code = code.sample(6).join @@ -384,11 +389,90 @@ class AccountController < ApplicationController else req[:status] = 2 end + else + if params[:value] =~ /^[a-zA-Z0-9]+([._\\]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/ + if User.where(:mail => params[:value]).count > 0 + req[:status] = 2 #已绑定 + req[:msg] = '该邮箱已被绑定' + else + begin + verification_code = code.sample(6).join + user = User.current + token = Token.new(:user => user, :action => "bind") + if token.save + Mailer.run.bind_email(token, verification_code) + VerificationCode.create(:email => params[:value], :status => 1, :code_type => 5, :code => verification_code) + end + rescue => e + Rails.logger.error "发送验证码出错: #{e}" + end + req[:status] = 3 + req[:link] = params[:value].split("@")[1] + end + elsif params[:value] =~ /^1\d{10}$/ + if User.where(:phone => params[:value]).count > 0 + req[:status] = 2 + req[:msg] = '该手机号已被绑定' + else + begin + verification_code = code.sample(6).join + status = Trustie::Sms.send(mobile: params[:value], code: verification_code) + if status + VerificationCode.create(:phone => params[:value], :status => 1, :code_type => 4, :code => verification_code) + end + rescue => e + Rails.logger.error "发送验证码出错: #{e}" + end + req[:status] = 1 + end + else + req[:status] = 2 + end end render :json => req end + def avatar + @user = User.current + @setting_type = 2 + render :layout => 'base_edu_account' + end + + def authentication + @setting_type = 3 + render :layout => 'base_edu_account' + end + + def security_settings + @user = User.current + @setting_type = 4 + render :layout => 'base_edu_account' + end + + def change_psd + @user = User.current + @setting_type = 5 + render :layout => 'base_edu_account' + end + + def change_or_bind + @user = User.current + @type = params[:type] + @setting_type = 4 + render :layout => 'base_edu_account' + end + + def bind_email_or_phone + @user = User.current + if params[:type] == "phone" + @user.update_attributes(:phone => params[:value]) + else + @user.update_attributes(:mail => params[:value]) + end + redirect_to security_settings_path + end + def wechat_bind respond_to do |format| format.html { render :layout => "login_bigdata"} diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index 001195bba..ec96fcf76 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -718,7 +718,7 @@ class AdminController < ApplicationController def applied_schools # 更新消息状态 if params[:flag] - applied_message = AppliedMessage.where(:id => params[:applied_message_id]).first + applied_message = AppliedMessage.where(:id => params[:applied_message_id], :applied_type => 'ApplyAddSchools').first applied_message.update_attribute(:viewed, true) end @@ -790,6 +790,8 @@ class AdminController < ApplicationController if aas.school_id != school[0].id.to_i aas.school.destroy end + ApplyAddDepartment.where(:school_id => aas.school_id).update_all(:school_id => school[0].id) + Department.where(:school_id => aas.school_id).update_all(:school_id => school[0].id) aas.update_attribute(:school_id, school[0].id) rescue Exception => e puts e @@ -825,13 +827,18 @@ class AdminController < ApplicationController applied_message = AppliedMessage.where(:applied_id => applied_message_id, :applied_type => "ApplyAddSchools") applied_message.update_all(:status => 3) applied_school.update_attribute(:status, 3) + # 单位对应的部门审核也应做删除处理 + applied_departments = ApplyAddDepartment.where(:school_id => applied_school.school_id) + applied_departments.update_all(:status => 3) + AppliedMessage.where(:applied_id => applied_departments.map(&:id), :applied_type => "ApplyAddDepartment").update_all(:status => 3) # 未审批删除 if params[:tip] == "unapplied" AppliedMessage.create(:user_id => applied_school.user_id, :status => 3, :viewed => 0, :applied_id => applied_school.id, :applied_type => "ApplyAddSchools", :name => applied_school.name ) # 删除学校的用户 users = UserExtensions.where("school_id = #{applied_school.school_id}") - users.update_all(:school_id => nil) + users.update_all(:school_id => nil, :department_id => nil) applied_school.school.destroy + applied_school.school.departments.destroy_all redirect_to unapplied_schools_url # 已审批删除 elsif params[:tip] == "applied" @@ -840,6 +847,75 @@ class AdminController < ApplicationController end end + # 部门审核 + # 未审批tab页 + # status: 0 未审批; 1 已批阅; 2已更改; 3拒绝; + def applied_departments + # 更新消息状态 + if params[:flag] + applied_message = AppliedMessage.where(:id => params[:applied_message_id], :applied_type => 'ApplyAddDepartment').first + applied_message.update_attribute(:viewed, true) + end + + @name = params[:name] || "" + condition = "#{@name.strip}".gsub(" ","") + @apply_status = ApplyAddDepartment.where("status = 0 and name like '%#{condition}%'").order('created_at desc') + @apply_count = @apply_status.count + @apply_pages = Paginator.new @apply_count, 30, params['page'] || 1 + @apply_status = paginateHelper @apply_status, 30 + @page = (params['page'] || 1).to_i - 1 + + respond_to do |format| + format.html + end + end + + def has_applied_departments + @name = params[:name] || "" + condition = "#{@name.strip}".gsub(" ","") + + @has_apply_status = ApplyAddDepartment.where("(status = 1 or status = 2) and name like '%#{condition}%'").order('created_at desc') + @has_apply_count = @has_apply_status.count + @has_apply_pages = Paginator.new @has_apply_count, 30, params['page'] || 1 + @has_apply_status = paginateHelper @has_apply_status, 30 + @page = (params['page'] || 1).to_i - 1 + + respond_to do |format| + format.html + end + end + + def approve_applied_departments + applied_department = ApplyAddDepartment.find params[:id] + applied_message = AppliedMessage.where(:applied_id => applied_department.id, :applied_type => "ApplyAddDepartment") + applied_message.update_all(:status => 1) + applied_department.update_column('status', 1) unless applied_department.nil? + AppliedMessage.create(:user_id => applied_department.user_id, :status => 1, :viewed => 0, :applied_id => applied_department.id, :applied_type => "ApplyAddDepartment", :name => applied_department.name ) + respond_to do |format| + format.html{ redirect_to unapplied_departments_path } + end + end + + def delete_applied_departments + applied_department = ApplyAddDepartment.find params[:id] + applied_message = AppliedMessage.where(:applied_id => applied_department.id, :applied_type => "ApplyAddDepartment") + applied_message.update_all(:status => 3) + applied_department.update_attribute(:status, 3) + # 未审批删除 + if params[:tip] == "unapplied" + AppliedMessage.create(:user_id => applied_department.user_id, :status => 3, :viewed => 0, :applied_id => applied_department.id, :applied_type => "ApplyAddDepartment", :name => applied_department.name ) + # 删除学校的用户 + users = UserExtensions.where("department_id = #{applied_department.department_id}") + users.update_all(:department_id => nil) + applied_department.department.destroy + redirect_to unapplied_departments_path + # 已审批删除 + elsif params[:tip] == "applied" + applied_department.destroy + redirect_to applied_departments_path + end + end + #移动端版本管理 def mobile_version @versions = PhoneAppVersion.reorder('created_at desc') diff --git a/app/controllers/avatar_controller.rb b/app/controllers/avatar_controller.rb index 22f0ad84d..bd2dd3699 100644 --- a/app/controllers/avatar_controller.rb +++ b/app/controllers/avatar_controller.rb @@ -10,7 +10,7 @@ class AvatarController < ApplicationController unless request.content_type == 'application/octet-stream' @source_type = params[:source_type] @source_id = params[:source_id] - @temp_file = params[:avatar][:image] + @temp_file = params[:img] || params[:avatar][:image] @image_file = @temp_file.original_filename @is_direct = params[:is_direct] else @@ -32,7 +32,7 @@ class AvatarController < ApplicationController end size = @temp_file.size - if @temp_file && (@temp_file.size > 0) + if @temp_file && (@temp_file.size > 0) if @temp_file.size > Setting.upload_avatar_max_size.to_i @status = 1 @msg = l(:error_upload_avatar_to_large, :max_size => number_to_human_size(Setting.upload_avatar_max_size.to_i)) @@ -80,15 +80,6 @@ class AvatarController < ApplicationController end @temp_file = nil - sleep(3) - - unless File.size(diskfile) < size - logger.info("###############################################################sleep") - sleep(0.5) - end - - #@src_file = diskfile - respond_to do |format| format.json{ render :inline => {status: @status, message:@msg, url:"#{@urlfile.to_s}?#{Time.now.to_i}"}.to_json,:content_type => 'text/html' diff --git a/app/controllers/blog_comments_controller.rb b/app/controllers/blog_comments_controller.rb index 88d4c4d53..6605170f1 100644 --- a/app/controllers/blog_comments_controller.rb +++ b/app/controllers/blog_comments_controller.rb @@ -43,6 +43,7 @@ class BlogCommentsController < ApplicationController update_messsages_to_viewed("BlogMessage", params[:blog_id]) @article = BlogComment.find(params[:id]) + update_visiti_count @article @replies = BlogComment.where("root_id = #{@article.id}").reorder("created_on desc") @reply_count = @replies.count @replies = get_no_children_comments_all @replies diff --git a/app/controllers/challenges_controller.rb b/app/controllers/challenges_controller.rb index 9095dea3d..a1d69ebd7 100644 --- a/app/controllers/challenges_controller.rb +++ b/app/controllers/challenges_controller.rb @@ -115,6 +115,17 @@ class ChallengesController < ApplicationController ChallengeTag.create(:name => input, :challenge_id => @challenge.id) end end + # 向jenkins端发送请求,构建pipeline片段,实时返回结果 + jenkins_shixuns = Redmine::Configuration['jenkins_shixuns'] + params = {:challengeStage => "#{@challenge.position}", :challengeType => "#{@challenge.evaluation_way.to_i}", :challengeProgramName => "#{@challenge.path}", :trainingID => "#{@shixun.id}"} + uri = URI("#{jenkins_shixuns}/jenkins-exec/game/generatePipelineScriptForChallenge") + res = uri_exec uri, {challengeInfo: params.to_json} + if res['code'] == 0 + @challenge.update_attribute(:pipeline_script, res['msg']) + else + logger.error("res['code'] is #{res['code']}, res['msg'] is #{res['code']}") + raise("脚本构建失败") + end end format.html {redirect_to shixun_challenge_path(@challenge, :shixun_id => @shixun), notice: '更新成功!'} format.json { head :no_content } diff --git a/app/controllers/department_controller.rb b/app/controllers/department_controller.rb new file mode 100644 index 000000000..f790cc77c --- /dev/null +++ b/app/controllers/department_controller.rb @@ -0,0 +1,88 @@ +class DepartmentController < ApplicationController + + #根据部门名字或者拼音来查询 + def on_search + condition = "#{params[:name].strip}".gsub(" ","") + #获取拼音的第一次出现的位置 + + if(condition == '') + @departments = Department.order("CONVERT(name USING gbk) COLLATE gbk_chinese_ci asc").page((params[:page].to_i || 1) - 1).per(100) + @department_count = Department.count + else + @departments = Department.where("name like '%#{condition}%'").order("CONVERT(name USING gbk) COLLATE gbk_chinese_ci asc").page((params[:page].to_i || 1) - 1).per(100) + @department_count = School.where("name like '%#{condition}%'").count + end + + render :json =>{ :departments => @departments,:count=>@department_count}.to_json + end + + #申请学院或部门(单位) name:名称 remarks:备注 + def apply_add_department + school = School.find params[:school_id] + + data = {result:0,name:params[:name],department_id:0} + #0 成功 1参数错误 2名称已存在 3.失败 + data[:result] = 0 + + if school + #检验参数 + if params[:name] == "" + data[:result] = 1 + else + department = Department.where(:school_id => school.id, :name => params[:name]).first + if department + data[:result] = 2 + else + department = Department.new + department.name = params[:name].strip + department.school = school + + #status 0未处理 1通过 2拒绝 + apply_department = ApplyAddDepartment.new + + #用belongs_to 可以一起存数据库 + apply_department.department = department + apply_department.school = department.school + apply_department.name = department.name + apply_department.remarks = params[:remarks] + apply_department.user_id = User.current.id + if apply_department.save + data[:department_id] = department.id + user_extention = User.current.extensions + user_extention.department_id = department.id + user_extention.save! + + # 向管理员发送信息 + users = User.where(:admin => 1) + users.each do |user| + AppliedMessage.create(:user_id => user.id, :status => 0, :applied_user_id => User.current.id, :viewed => 0, :applied_id => apply_department.id, :applied_type => "ApplyAddDepartment", :name => department.name ) + end + + else + data[:result] = 3 + end + end + end + end + + render :json =>data + end + + def search_repeat_departmentname + status = 0 #没有重复的 + name = params[:name] + school = School.where(:id => params[:school_id].to_i).first + if school + if name + department = school.departments.where(:name => name).first + if department + status = 1 #有重复的 + end + end + else + status = 2 + end + + render :json =>status + end +end diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index bd35b5a4d..c03f48a8d 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -62,6 +62,7 @@ class GamesController < ApplicationController @test_sets = test_set_static_data(test_sets) end + @consume_time = (@game.status == 2 ? game_spend_time(@game.open_time, @game.updated_at) : game_spend_time(@game.open_time, Time.now)) logger.info("#################################{@public_test_sets}") @test_sets_count = test_sets.count @test_sets_hidden_count = test_sets.where(:is_public => false).count @@ -173,11 +174,12 @@ class GamesController < ApplicationController # 出错的测试用例序号 error_position = Output.where(:game_id => @game.id, :result => false).last static_error_position = error_position.blank? ? 0 : error_position.try(:test_set_position).to_i + consume_time = @game.status == 2 ? game_spend_time(@game.open_time, @game.updated_at) : game_spend_time(@game.open_time, Time.now) # 异常结果 latest_output = error_position.try(:out_put) render :json => {test_sets: total_test_sets, status: @game.status, had_done: had_done, latest_output: latest_output, error_position: static_error_position, had_passed_testsests:had_passed_testsests, test_sets_count:test_sets_count, test_sets_hidden_count:test_sets_hidden_count, - final_score:final_score, had_tested:had_tested} + final_score:final_score, had_tested:had_tested, consume_time: consume_time} end def change_status @@ -197,7 +199,7 @@ class GamesController < ApplicationController next_game = @game.next_game next_game.update_attributes(:status => 0, :open_time => Time.now) if next_game.status == 3 - redirect_to myshixun_game_path(next_game, :myshixun_id => @myshixun.id) + redirect_to myshixun_game_path(next_game, :myshixun_id => @myshixun.id) end diff --git a/app/controllers/my_controller.rb b/app/controllers/my_controller.rb index ce5a575c0..532f54eed 100644 --- a/app/controllers/my_controller.rb +++ b/app/controllers/my_controller.rb @@ -145,15 +145,21 @@ class MyController < ApplicationController applied_message = AppliedMessage.where(:id => params[:applied_message_id]).first applied_message.update_attribute(:viewed, true) end + @user = User.current # 基本资料不完善 @force为false, 完善 @force为true @force = false if params[:tip] @force = true + else + user = UserExtensions.where(:user_id => User.current.id).first + if user.gender.nil? || user.school_id.nil? || User.current.lastname.nil? + @force = true + elsif user.identity == 3 && user.school_id.nil? + @force = true + end end - @user = User.current - lg = @user.login @pref = @user.pref diskfile = disk_filename('User', @user.id) @@ -225,7 +231,8 @@ class MyController < ApplicationController File.delete(diskfile1) if File.exist?(diskfile1) end - render :layout => 'new_base_user' + @setting_type = 1 + render :layout => 'base_edu_account' end # Destroys user's account @@ -278,7 +285,8 @@ class MyController < ApplicationController end flash.now[:error] = l(:notice_account_old_wrong_password) end - render :template => 'my/account',:layout=>'new_base_user' + @setting_type = 5 + render :template => 'account/change_psd',:layout=>'base_edu_account' end # Create a new feeds key diff --git a/app/controllers/syllabus_member_controller.rb b/app/controllers/syllabus_member_controller.rb index b6da3290e..f2a0c02fa 100644 --- a/app/controllers/syllabus_member_controller.rb +++ b/app/controllers/syllabus_member_controller.rb @@ -29,6 +29,19 @@ class SyllabusMemberController < ApplicationController end end + def change_manager + @syllabus = Syllabus.find(params[:syllabus]) + if params[:chooseteacher] + man_member = SyllabusMember.where(:syllabus_id => @syllabus.id, :user_id => @syllabus.user_id).first + cha_member = @syllabus.syllabus_members.where(:id => params[:chooseteacher].to_i).first + if man_member && cha_member + man_member.update_attributes(:rank => cha_member.rank) + cha_member.update_attributes(:rank => 1) + @syllabus.update_attributes(:user_id => cha_member.user_id) + end + end + end + def destroy member = SyllabusMember.find(params[:id]) @syllabus = member.syllabus diff --git a/app/controllers/syllabuses_controller.rb b/app/controllers/syllabuses_controller.rb index 2be73ff27..35db25b68 100644 --- a/app/controllers/syllabuses_controller.rb +++ b/app/controllers/syllabuses_controller.rb @@ -28,9 +28,13 @@ class SyllabusesController < ApplicationController def create if User.current.user_extensions.identity @syllabus = Syllabus.new - @syllabus.title = params[:title] + @syllabus.title = params[:title].to_s.strip @syllabus.eng_name = params[:eng_name] @syllabus.user_id = User.current.id + @syllabus.major_level = params[:major_level].to_i + @syllabus.discipline_category_id = params[:discipline_category_id].to_i + @syllabus.first_level_discipline_id = params[:first_level_discipline_id].to_i + @syllabus.syllabus_type = params[:syllabus_type].to_i @syllabus.description = Message.where("id = 19412").first.nil? ? '' : Message.where("id = 19412").first.content if @syllabus && @syllabus.save member = SyllabusMember.create(:user_id => @syllabus.user_id, :rank => 1) @@ -50,19 +54,46 @@ class SyllabusesController < ApplicationController end end + def regex_syllabus_name + data = {result:1} + if Syllabus.where(:user_id => User.current.id, :name => params[:name]).count > 0 + data[:result] = 0 + end + render :json => data + end + def edit respond_to do |format| format.html{render :layout => 'base_syllabus'} end end - def delete_syllabus + def update + title = @syllabus.title + @syllabus.title = params[:title].to_s.strip + @syllabus.eng_name = params[:eng_name] + @syllabus.major_level = params[:major_level].to_i + @syllabus.discipline_category_id = params[:discipline_category_id].to_i + @syllabus.first_level_discipline_id = params[:first_level_discipline_id].to_i + @syllabus.syllabus_type = params[:syllabus_type].to_i + if @syllabus.save + if title != params[:title].to_s.strip + @syllabus.courses.each do |course| + course.name.gsub!(/^#{title}/, params[:title].to_s.strip) + course.save + end + end + end + redirect_to syllabus_path(@syllabus) + end + + def edit_des respond_to do |format| - format.js + format.html{render :layout => 'base_syllabus'} end end - def update + def update_des @syllabus.description = params[:syllabus][:description] @syllabus.des_status = 1 @syllabus.save_attachments(params[:attachments]) @@ -77,6 +108,12 @@ class SyllabusesController < ApplicationController end end + def delete_syllabus + respond_to do |format| + format.js + end + end + #删除课程大纲的描述 def delete_des if @syllabus @@ -183,6 +220,40 @@ class SyllabusesController < ApplicationController end end + def get_discipline_categories + data = {result:0,options:[]} + if params[:major_level] + if DisciplineCategory.where(:major_level => params[:major_level].to_i).count > 0 + data[:result] = 1 + DisciplineCategory.where(:major_level => params[:major_level].to_i).each do |dis| + option = [] + option << dis.name.to_s + option << dis.id + data[:options] << option + end + end + end + + render :json =>data + end + + def get_first_level_disciplines + data = {result:0,options:[]} + if params[:discipline_category_id] + if FirstLevelDiscipline.where(:discipline_category_id => params[:discipline_category_id].to_i).count > 0 + data[:result] = 1 + FirstLevelDiscipline.where(:discipline_category_id => params[:discipline_category_id].to_i).each do |dis| + option = [] + option << dis.name.to_s + option << dis.id + data[:options] << option + end + end + end + + render :json =>data + end + private def find_syllabus @syllabus = Syllabus.find params[:id] diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 79f4d83ee..7de524f11 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -2097,147 +2097,161 @@ class UsersController < ApplicationController end def show - if User.current == @user - # 点击小铃铛,更新点击时间 - update_onclick_time if params[:click_user_message] == 'true' - # 全部设为已读 - # 自己的主页显示消息 - messages_all = MessageAll.where(:user_id => @user.id) - @message_count = messages_all.count - # REDO:已删除的内容应该在页面中显示不点击 - @message_all_pages = Paginator.new @message_count, per_page_option, params['page'] - @message_alls = messages_all.includes(:message). - limit(@message_all_pages.per_page). - offset(@message_all_pages.offset). - reorder("#{MessageAll.table_name}.created_at desc") - - @unsolved_issues_count = Issue.where(:assigned_to_id => @user.id, :status_id => [1, 2, 4, 6]).includes(:author, :project).count - - my_course_ids = StudentsForCourse.includes(:course).where("student_id = #{@user.id} and courses.is_delete = 0").blank? ? "(-1)" : "(" + StudentsForCourse.includes(:course). - where("student_id = #{@user.id} and courses.is_delete = 0").map{|sc| sc.course_id}.join(",") + ")" - # 用户待完成的作业 - homeworks = HomeworkCommon.where("course_id in #{my_course_ids} and publish_time <= '#{Time.now}'") - homework_ids = homeworks.blank? ? "(-1)" : "(" + homeworks.map{|homework| homework.id}.join(",") + ")" - student_works = StudentWork.where("user_id = #{@user.id} and homework_common_id in #{homework_ids} and work_status != 0") - @unfinished_homework_count = homeworks.count - student_works.count - # 用户待完成的测验 - exercises = Exercise.where("course_id in #{my_course_ids} and exercise_status = 2") - exercise_users = ExerciseUser.where(:user_id => @user.id, :exercise_id => exercises.map{|ex| ex.id}) - @unfinished_test_count = exercises.count - exercise_users.count - # 用户待完成的问卷 - polls = Poll.where("polls_type = 'Course' and polls_group_id in #{my_course_ids} and polls_status = 2") - poll_users = PollUser.where(:user_id => @user.id, :poll_id => polls.map{|poll| poll.id}) - @unfinished_poll_count = polls.count - poll_users.count - # 用户待匿评的作品 - homeworks = HomeworkCommon.includes(:homework_detail_manual).where("homework_commons.course_id in #{my_course_ids} and homework_detail_manuals.comment_status = 2") - student_work_scores = @user.student_works_scores.where("reviewer_role = 3") - anonymous_evaluation_ids = student_work_scores.blank? ? "(-1)" : "(" + student_work_scores.map{|st| st.student_work_id}.join(",") + ")" - unfinished_evaluations = @user.student_works_evaluation_distributions.where("student_work_id not in #{anonymous_evaluation_ids}") - @anonymous_evaluation_count = StudentWork.where(:id => unfinished_evaluations.map{|ev| ev.student_work_id}, :homework_common_id => homeworks.map{|hw| hw.id}).count - # 待评阅的作业 暂不做 - # @unreview_homework = 1 - - # 待审批的申请 - #applied_message_count = AppliedMessage.where(:applied_type => ["Organization", "AppliedContest", "StudentWorksScoresAppeal", "AppliedProject", "ApplyAddSchools"], :user_id => User.current.id, :status => 0).count - #applied_course_message_count = CourseMessage.where(:user_id => User.current.id, :course_message_type => "JoinCourseRequest", :status => 0).count - # applied_pull_request_message_count = ForgeMessage.where(:user_id => User.current.id, :forge_message_type => "PullRequest", :status => [1,3]).count - # @applied_message_alls_count = applied_message_count + applied_course_message_count + applied_pull_request_message_count - user_id = User.current.id - sql = "SELECT * FROM `message_alls` ma left join `forge_messages` fm on ma.message_id=fm.id - left join `course_messages` cm on ma.message_id=cm.id left join `applied_messages` apm on ma.message_id=apm.id - where (ma.user_id =#{user_id} and ma.message_type = 'ForgeMessage' and fm.forge_message_type='PullRequest' and fm.status=0 and fm.user_id=#{user_id} ) or - (ma.user_id=#{user_id} and ma.message_type='AppliedMessage' and apm.applied_type in ('Organization', 'AppliedContest', 'StudentWorksScoresAppeal', 'AppliedProject', 'ApplyAddSchools') and apm.user_id =#{user_id} and apm.status =0 ) or - (ma.user_id=#{user_id} and ma.message_type='CourseMessage' and cm.course_message_type='JoinCourseRequest' and cm.status=0 and cm.user_id=#{user_id} );" - message_alls = MessageAll.find_by_sql(sql) - @applied_message_alls_count = message_alls.count - else - # 看别人的主页显示动态 - #更新用户申请成为课程老师或教辅消息的状态 - if params[:course_id] != nil - join_course_messages = CourseMessage.where("course_id =? and course_message_type =? and user_id =? and course_message_id =? and viewed =?", - params[:course_id], 'JoinCourseRequest', User.current.id, @user.id, false) - join_course_messages.update_all(:viewed => true) - end - shield_project_ids = ShieldActivity.select("shield_id").where("container_type='User' and container_id=#{@user.id} and shield_type='Project'").map(&:shield_id) - shield_course_ids = ShieldActivity.select("shield_id").where("container_type='User' and container_id=#{@user.id} and shield_type='Course'").map(&:shield_id) - @page = params[:page] ? params[:page].to_i + 1 : 0 - user_project_ids = (@user.favorite_projects.visible.map{|project| project.id}-shield_project_ids).empty? ? "(-1)" : "(" + (@user.favorite_projects.visible.map{|project| project.id}-shield_project_ids).join(",") + ")" - user_course_ids = (@user.favorite_courses.visible.where("is_delete = 0").map{|course| course.id}-shield_course_ids).empty? ? "(-1)" : "(" + (@user.favorite_courses.visible.where("is_delete = 0").map{|course| course.id}-shield_course_ids).join(",") + ")" - course_types = "('Message','News','HomeworkCommon','Poll','Course','JournalsForMessage')" - project_types = "('Message','Issue','Project')" - principal_types = "JournalsForMessage" - container_type = '' - act_type = '' - # 他的动态 - sql = "user_id = #{@user.id} and ((container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types}) or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}))" - if params[:type].present? - case params[:type] - when "course_homework" - container_type = 'Course' - act_type = 'HomeworkCommon' - when "course_news" - container_type = 'Course' - act_type = 'News' - when "course_message" - container_type = 'Course' - act_type = 'Message' - when "course_poll" - container_type = 'Course' - act_type = 'Poll' - when "course_journals" - container_type = 'Course' - act_type = 'JournalsForMessage' - when "project_issue" - container_type = 'Project' - act_type = 'Issue' - when "project_message" - container_type = 'Project' - act_type = 'Message' - when "user_journals" - container_type = 'Principal' - act_type = 'JournalsForMessage' - when "current_user" - container_type = 'Principal' - act_type = 'Principal' - when "all" - container_type = 'all' - act_type = 'all' - end - end - if container_type != '' && container_type != 'all' - if container_type == 'Course' - sql = "container_type = '#{container_type}' and container_id in #{user_course_ids} and act_type = '#{act_type}'" - elsif container_type == 'Project' - sql = "container_type = '#{container_type}' and container_id in #{user_project_ids} and act_type = '#{act_type}'" - elsif container_type == 'Principal' && act_type == 'JournalsForMessage' - sql = "container_type = '#{container_type}' and act_type= '#{act_type}' and container_id = #{@user.id}" - elsif container_type == 'Principal' && act_type == 'Principal' - sql = "user_id = #{@user.id} and ((container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types}) or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}))" - end - if User.current != @user - sql += " and user_id = #{@user.id}" - end - else - if User.current != @user - blog_ids = "("+@user.blog.id.to_s+")" - else - blog_ids = "("+@user.blog.id.to_s+","+((User.watched_by(@user.id).count == 0 )? '0' :User.watched_by(@user.id).map{|u| u.blog.id}.join(','))+")" - end - sql = "(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types})" + - "or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}) "+ - "or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{@user.id}) " + - "or (container_type = 'Blog' and act_type= 'BlogComment' and container_id in #{blog_ids})" - if container_type != 'all' && User.current != @user - sql = "user_id = #{@user.id} and(" + sql + ")" - end - end - @user_activities_count = UserActivity.where("#{sql}").order('updated_at desc').count - @user_activities = UserActivity.where("#{sql}").order('updated_at desc').limit(10).offset(@page * 10) - @type = params[:type] - end + @blog_list = @user.blog.articles.reorder("#{BlogComment.table_name}.sticky desc,#{BlogComment.table_name}.created_at desc") + @blog_count = @blog_list.count + @blog_list = @blog_list.limit(3) + watch_query = User.watched_by(@user.id); + @user_watchlist_count = watch_query.count(); + @user_watchlist = watch_query.order("#{Watcher.table_name}.id desc").limit(12); + fan_query = @user.watcher_users; + @user_fanlist_count = fan_query.count(); + @user_fanlist = fan_query.order("#{Watcher.table_name}.id desc").limit(12); + @courses = @user.courses.visible.not_deleted + @courses_count = @courses.count + @courses = @courses.select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS updatetime").order("updatetime desc").limit(8) + @shixuns = [] + @shixuns_count = 0 + # if User.current == @user + # # 点击小铃铛,更新点击时间 + # update_onclick_time if params[:click_user_message] == 'true' + # # 全部设为已读 + # # 自己的主页显示消息 + # messages_all = MessageAll.where(:user_id => @user.id) + # @message_count = messages_all.count + # # REDO:已删除的内容应该在页面中显示不点击 + # @message_all_pages = Paginator.new @message_count, per_page_option, params['page'] + # @message_alls = messages_all.includes(:message). + # limit(@message_all_pages.per_page). + # offset(@message_all_pages.offset). + # reorder("#{MessageAll.table_name}.created_at desc") + # + # @unsolved_issues_count = Issue.where(:assigned_to_id => @user.id, :status_id => [1, 2, 4, 6]).includes(:author, :project).count + # + # my_course_ids = StudentsForCourse.includes(:course).where("student_id = #{@user.id} and courses.is_delete = 0").blank? ? "(-1)" : "(" + StudentsForCourse.includes(:course). + # where("student_id = #{@user.id} and courses.is_delete = 0").map{|sc| sc.course_id}.join(",") + ")" + # # 用户待完成的作业 + # homeworks = HomeworkCommon.where("course_id in #{my_course_ids} and publish_time <= '#{Time.now}'") + # homework_ids = homeworks.blank? ? "(-1)" : "(" + homeworks.map{|homework| homework.id}.join(",") + ")" + # student_works = StudentWork.where("user_id = #{@user.id} and homework_common_id in #{homework_ids} and work_status != 0") + # @unfinished_homework_count = homeworks.count - student_works.count + # # 用户待完成的测验 + # exercises = Exercise.where("course_id in #{my_course_ids} and exercise_status = 2") + # exercise_users = ExerciseUser.where(:user_id => @user.id, :exercise_id => exercises.map{|ex| ex.id}) + # @unfinished_test_count = exercises.count - exercise_users.count + # # 用户待完成的问卷 + # polls = Poll.where("polls_type = 'Course' and polls_group_id in #{my_course_ids} and polls_status = 2") + # poll_users = PollUser.where(:user_id => @user.id, :poll_id => polls.map{|poll| poll.id}) + # @unfinished_poll_count = polls.count - poll_users.count + # # 用户待匿评的作品 + # homeworks = HomeworkCommon.includes(:homework_detail_manual).where("homework_commons.course_id in #{my_course_ids} and homework_detail_manuals.comment_status = 2") + # student_work_scores = @user.student_works_scores.where("reviewer_role = 3") + # anonymous_evaluation_ids = student_work_scores.blank? ? "(-1)" : "(" + student_work_scores.map{|st| st.student_work_id}.join(",") + ")" + # unfinished_evaluations = @user.student_works_evaluation_distributions.where("student_work_id not in #{anonymous_evaluation_ids}") + # @anonymous_evaluation_count = StudentWork.where(:id => unfinished_evaluations.map{|ev| ev.student_work_id}, :homework_common_id => homeworks.map{|hw| hw.id}).count + # # 待评阅的作业 暂不做 + # # @unreview_homework = 1 + # + # # 待审批的申请 + # #applied_message_count = AppliedMessage.where(:applied_type => ["Organization", "AppliedContest", "StudentWorksScoresAppeal", "AppliedProject", "ApplyAddSchools"], :user_id => User.current.id, :status => 0).count + # #applied_course_message_count = CourseMessage.where(:user_id => User.current.id, :course_message_type => "JoinCourseRequest", :status => 0).count + # # applied_pull_request_message_count = ForgeMessage.where(:user_id => User.current.id, :forge_message_type => "PullRequest", :status => [1,3]).count + # # @applied_message_alls_count = applied_message_count + applied_course_message_count + applied_pull_request_message_count + # user_id = User.current.id + # sql = "SELECT * FROM `message_alls` ma left join `forge_messages` fm on ma.message_id=fm.id + # left join `course_messages` cm on ma.message_id=cm.id left join `applied_messages` apm on ma.message_id=apm.id + # where (ma.user_id =#{user_id} and ma.message_type = 'ForgeMessage' and fm.forge_message_type='PullRequest' and fm.status=0 and fm.user_id=#{user_id} ) or + # (ma.user_id=#{user_id} and ma.message_type='AppliedMessage' and apm.applied_type in ('Organization', 'AppliedContest', 'StudentWorksScoresAppeal', 'AppliedProject', 'ApplyAddSchools') and apm.user_id =#{user_id} and apm.status =0 ) or + # (ma.user_id=#{user_id} and ma.message_type='CourseMessage' and cm.course_message_type='JoinCourseRequest' and cm.status=0 and cm.user_id=#{user_id} );" + # message_alls = MessageAll.find_by_sql(sql) + # @applied_message_alls_count = message_alls.count + # else + # # 看别人的主页显示动态 + # #更新用户申请成为课程老师或教辅消息的状态 + # if params[:course_id] != nil + # join_course_messages = CourseMessage.where("course_id =? and course_message_type =? and user_id =? and course_message_id =? and viewed =?", + # params[:course_id], 'JoinCourseRequest', User.current.id, @user.id, false) + # join_course_messages.update_all(:viewed => true) + # end + # shield_project_ids = ShieldActivity.select("shield_id").where("container_type='User' and container_id=#{@user.id} and shield_type='Project'").map(&:shield_id) + # shield_course_ids = ShieldActivity.select("shield_id").where("container_type='User' and container_id=#{@user.id} and shield_type='Course'").map(&:shield_id) + # @page = params[:page] ? params[:page].to_i + 1 : 0 + # user_project_ids = (@user.favorite_projects.visible.map{|project| project.id}-shield_project_ids).empty? ? "(-1)" : "(" + (@user.favorite_projects.visible.map{|project| project.id}-shield_project_ids).join(",") + ")" + # user_course_ids = (@user.favorite_courses.visible.where("is_delete = 0").map{|course| course.id}-shield_course_ids).empty? ? "(-1)" : "(" + (@user.favorite_courses.visible.where("is_delete = 0").map{|course| course.id}-shield_course_ids).join(",") + ")" + # course_types = "('Message','News','HomeworkCommon','Poll','Course','JournalsForMessage')" + # project_types = "('Message','Issue','Project')" + # principal_types = "JournalsForMessage" + # container_type = '' + # act_type = '' + # # 他的动态 + # sql = "user_id = #{@user.id} and ((container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types}) or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}))" + # if params[:type].present? + # case params[:type] + # when "course_homework" + # container_type = 'Course' + # act_type = 'HomeworkCommon' + # when "course_news" + # container_type = 'Course' + # act_type = 'News' + # when "course_message" + # container_type = 'Course' + # act_type = 'Message' + # when "course_poll" + # container_type = 'Course' + # act_type = 'Poll' + # when "course_journals" + # container_type = 'Course' + # act_type = 'JournalsForMessage' + # when "project_issue" + # container_type = 'Project' + # act_type = 'Issue' + # when "project_message" + # container_type = 'Project' + # act_type = 'Message' + # when "user_journals" + # container_type = 'Principal' + # act_type = 'JournalsForMessage' + # when "current_user" + # container_type = 'Principal' + # act_type = 'Principal' + # when "all" + # container_type = 'all' + # act_type = 'all' + # end + # end + # if container_type != '' && container_type != 'all' + # if container_type == 'Course' + # sql = "container_type = '#{container_type}' and container_id in #{user_course_ids} and act_type = '#{act_type}'" + # elsif container_type == 'Project' + # sql = "container_type = '#{container_type}' and container_id in #{user_project_ids} and act_type = '#{act_type}'" + # elsif container_type == 'Principal' && act_type == 'JournalsForMessage' + # sql = "container_type = '#{container_type}' and act_type= '#{act_type}' and container_id = #{@user.id}" + # elsif container_type == 'Principal' && act_type == 'Principal' + # sql = "user_id = #{@user.id} and ((container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types}) or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}))" + # end + # if User.current != @user + # sql += " and user_id = #{@user.id}" + # end + # else + # if User.current != @user + # blog_ids = "("+@user.blog.id.to_s+")" + # else + # blog_ids = "("+@user.blog.id.to_s+","+((User.watched_by(@user.id).count == 0 )? '0' :User.watched_by(@user.id).map{|u| u.blog.id}.join(','))+")" + # end + # sql = "(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types})" + + # "or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}) "+ + # "or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{@user.id}) " + + # "or (container_type = 'Blog' and act_type= 'BlogComment' and container_id in #{blog_ids})" + # if container_type != 'all' && User.current != @user + # sql = "user_id = #{@user.id} and(" + sql + ")" + # end + # end + # @user_activities_count = UserActivity.where("#{sql}").order('updated_at desc').count + # @user_activities = UserActivity.where("#{sql}").order('updated_at desc').limit(10).offset(@page * 10) + # @type = params[:type] + # end respond_to do |format| format.js - format.html {render :layout => 'new_base_user'} + format.html {render :layout => 'base_edu_user'} end end diff --git a/app/controllers/watchers_controller.rb b/app/controllers/watchers_controller.rb index 6f0d96dfa..292a64f28 100644 --- a/app/controllers/watchers_controller.rb +++ b/app/controllers/watchers_controller.rb @@ -39,6 +39,12 @@ class WatchersController < ApplicationController else if params[:target_id] @user = User.find(params[:target_id]) + watch_query = User.watched_by(@user.id); + @user_watchlist_count = watch_query.count(); + @user_watchlist = watch_query.order("#{Watcher.table_name}.id desc").limit(12); + fan_query = @user.watcher_users; + @user_fanlist_count = fan_query.count(); + @user_fanlist = fan_query.order("#{Watcher.table_name}.id desc").limit(12); end end @@ -82,6 +88,12 @@ class WatchersController < ApplicationController else if params[:target_id] @user = User.find(params[:target_id]) + watch_query = User.watched_by(@user.id); + @user_watchlist_count = watch_query.count(); + @user_watchlist = watch_query.order("#{Watcher.table_name}.id desc").limit(12); + fan_query = @user.watcher_users; + @user_fanlist_count = fan_query.count(); + @user_fanlist = fan_query.order("#{Watcher.table_name}.id desc").limit(12); end end if params[:object_type] == 'project' diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index e46485ade..24842f414 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1118,7 +1118,7 @@ module ApplicationHelper def render_flash_messages s = '' flash.each do |k,v| - s << content_tag('div', v.html_safe, :class => "flash #{k}", :id => "flash_#{k}") + s << content_tag('div', v.html_safe, :class => "alert alert-orange mb15 mt15", :id => "flash_#{k}") end s.html_safe end @@ -4280,6 +4280,57 @@ def get_contest_group_member_names work result end +def major_level_option + content = [] + option0 = [] + option0 << "选择课程所属专业层级" + option0 << 0 + option1 = [] + option1 << "专科" + option1 << 3 + option2 = [] + option2 << "本科" + option2 << 2 + option3 = [] + option3 << "研究生" + option3 << 1 + content << option0 + content << option1 + content << option2 + content << option3 + content +end + +def discipline_category_option major_level = 3 + content = [] + option0 = [] + option0 << "选择课程所属学科门类" + option0 << 0 + content << option0 + DisciplineCategory.where(:major_level => major_level).each do |dis| + option = [] + option << dis.name.to_s + option << dis.id + content << option + end + content +end + +def first_level_discipline_option disc_ca = 27 + content = [] + option0 = [] + option0 << "选择课程所属一级学科" + option0 << 0 + content << option0 + FirstLevelDiscipline.where(:discipline_category_id => disc_ca).each do |fir_dis| + option = [] + option << fir_dis.name.to_s + option << fir_dis.id + content << option + end + content +end + def course_syllabus_option user = User.current syllabus_members = SyllabusMember.where("user_id = #{user.id}") syllabus_ids = syllabus_members.empty? ? "(-1)" : "(" + syllabus_members.map{|mem| mem.syllabus_id}.join(',') + ")" diff --git a/app/helpers/department_helper.rb b/app/helpers/department_helper.rb new file mode 100644 index 000000000..fdd36b814 --- /dev/null +++ b/app/helpers/department_helper.rb @@ -0,0 +1,2 @@ +module DepartmentHelper +end diff --git a/app/helpers/watchers_helper.rb b/app/helpers/watchers_helper.rb index 8f6d6a8e5..ff25f6bab 100644 --- a/app/helpers/watchers_helper.rb +++ b/app/helpers/watchers_helper.rb @@ -262,11 +262,25 @@ module WatchersHelper content.present? ? content_tag('ul', content, :class => 'watchers') : content end - - - - - +#用户关注、取消关注 + def watcher_link_for_user(target, user) + return '' unless user && user.logged? + watched = target.watched_by?(user) + text = watched ? '已关注' : '添加关注' + url = watch_path(:object_type => 'user', + :object_id => target.id, + :target_id => target.id) + method = watched ? 'delete' : 'post' + id = watched ? 'cancel_watch' : '' + title = watched ? '取消关注' : '添加关注' + if target != user + link_to text, url, :remote => true, :method => method, :remote => true, + :class => "fl font-14 user_watch",:id => id, :title => title + else + link_to "关注", "javascript:void(0)", :remote => true, :method => method, + :class => "fl font-14 user_watch", :id => id, :title => title + end + end # 缺陷跟踪者列表复选框生成 def watchers_checkboxes(object, users, checked=nil) diff --git a/app/models/applied_message.rb b/app/models/applied_message.rb index c5228ce83..93b1d2047 100644 --- a/app/models/applied_message.rb +++ b/app/models/applied_message.rb @@ -4,6 +4,7 @@ class AppliedMessage < ActiveRecord::Base attr_accessible :applied_id, :applied_type, :status, :user_id, :viewed, :applied_user_id, :role, :project_id, :name belongs_to :applied ,:polymorphic => true belongs_to :apply_add_schools + belongs_to :apply_add_department belongs_to :user has_many :message_alls, :class_name => 'MessageAll', :as =>:message, :dependent => :destroy diff --git a/app/models/apply_add_department.rb b/app/models/apply_add_department.rb new file mode 100644 index 000000000..4b6a984d0 --- /dev/null +++ b/app/models/apply_add_department.rb @@ -0,0 +1,7 @@ +class ApplyAddDepartment < ActiveRecord::Base + belongs_to :school + belongs_to :user + attr_accessible :name, :remarks, :status, :school_id, :user_id + has_many :applied_messages, :class_name =>'AppliedMessage', :as => :applied + belongs_to :department +end diff --git a/app/models/attachment.rb b/app/models/attachment.rb index 593a1090e..a27a36ac8 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -29,6 +29,7 @@ class Attachment < ActiveRecord::Base belongs_to :softapplication, foreign_key: 'container_id', conditions: "attachments.container_type = 'Softapplication'" belongs_to :author, :class_name => "User", :foreign_key => "author_id" belongs_to :attachmentstype, :foreign_key => "attachtype",:primary_key => "id" + belongs_to :resource_bank # 被ForgeActivity虚拟关联 has_many :forge_acts, :class_name => 'ForgeActivity',:as =>:forge_act ,:dependent => :destroy has_many :forwards, :as => :from, :dependent => :destroy diff --git a/app/models/blog.rb b/app/models/blog.rb index bd338cdad..7c54b2be7 100644 --- a/app/models/blog.rb +++ b/app/models/blog.rb @@ -2,8 +2,8 @@ class Blog < ActiveRecord::Base # attr_accessible :title, :body include Redmine::SafeAttributes belongs_to :user - has_many :articles, :class_name => 'BlogComment', :conditions => "#{BlogComment.table_name}.parent_id IS NULL ", :order => "#{BlogComment.table_name}.created_on DESC" - has_many :blog_comments, :dependent => :destroy, :order => "#{BlogComment.table_name}.created_on DESC" + has_many :articles, :class_name => 'BlogComment', :conditions => "#{BlogComment.table_name}.parent_id IS NULL ", :order => "#{BlogComment.table_name}.created_at DESC" + has_many :blog_comments, :dependent => :destroy, :order => "#{BlogComment.table_name}.created_at DESC" belongs_to :last_comment, :class_name => 'BlogComment', :foreign_key => :last_comment_id acts_as_tree :dependent => :nullify #acts_as_list :scope => '(user_id = #{user_id} AND parent_id #{user_id ? = "#{parent_id}" : "IS NULL"})' diff --git a/app/models/blog_comment.rb b/app/models/blog_comment.rb index cf241ce3b..a04c7d208 100644 --- a/app/models/blog_comment.rb +++ b/app/models/blog_comment.rb @@ -20,7 +20,7 @@ class BlogComment < ActiveRecord::Base validates_presence_of :title, :content validates_length_of :title, :maximum => 255 #validate :cannot_reply_to_locked_comment, :on => :create - safe_attributes 'title', 'content',"sticky", "locked", "root_id" + safe_attributes 'title', 'content',"sticky", "locked", "root_id", 'visits' after_save :add_user_activity after_update :update_activity diff --git a/app/models/department.rb b/app/models/department.rb new file mode 100644 index 000000000..4163f6bd3 --- /dev/null +++ b/app/models/department.rb @@ -0,0 +1,4 @@ +class Department < ActiveRecord::Base + belongs_to :school + attr_accessible :name, :school_id +end diff --git a/app/models/discipline_category.rb b/app/models/discipline_category.rb new file mode 100644 index 000000000..2e8ded1bb --- /dev/null +++ b/app/models/discipline_category.rb @@ -0,0 +1,5 @@ +class DisciplineCategory < ActiveRecord::Base + attr_accessible :major_level, :name + + has_many :first_level_disciplines +end diff --git a/app/models/first_level_discipline.rb b/app/models/first_level_discipline.rb new file mode 100644 index 000000000..ce610cc31 --- /dev/null +++ b/app/models/first_level_discipline.rb @@ -0,0 +1,5 @@ +class FirstLevelDiscipline < ActiveRecord::Base + belongs_to :discipline_category + attr_accessible :name + has_many :syllabuses +end diff --git a/app/models/mailer.rb b/app/models/mailer.rb index 49b58c3db..7fe18d91d 100644 --- a/app/models/mailer.rb +++ b/app/models/mailer.rb @@ -837,6 +837,15 @@ class Mailer < ActionMailer::Base :subject => l(:mail_subject_register, Setting.app_title) end + def bind_email(token, code="111111") + set_language_if_valid(token.user.language) + @login = token.user.try(:login) + @token = token + @code = code + mail :to => token.user.mail, + :subject => l(:mail_subject_bind_mail, Setting.app_title+"("+Setting.host_name+")") + end + def lost_password(token, code="111111") set_language_if_valid(token.user.language) @login = token.user.try(:login) diff --git a/app/models/reference_material.rb b/app/models/reference_material.rb new file mode 100644 index 000000000..627f6eeb3 --- /dev/null +++ b/app/models/reference_material.rb @@ -0,0 +1,4 @@ +class ReferenceMaterial < ActiveRecord::Base + belongs_to :syllabus + attr_accessible :book, :editor, :press, :syllabus_id +end diff --git a/app/models/resource_bank.rb b/app/models/resource_bank.rb new file mode 100644 index 000000000..b2d9b29c6 --- /dev/null +++ b/app/models/resource_bank.rb @@ -0,0 +1,5 @@ +class ResourceBank < ActiveRecord::Base + belongs_to :course + belongs_to :user + attr_accessible :course_id, :user_id, :applicable_syllabus, :copy_from, :description, :digest, :discipline_category_id, :disk_directory, :disk_filename, :downloads, :filename, :filesize, :first_level_discipline_id, :is_public, :major_level, :quotes, :attachment_id +end diff --git a/app/models/school.rb b/app/models/school.rb index b9a1d88cb..81e1743b2 100644 --- a/app/models/school.rb +++ b/app/models/school.rb @@ -1,6 +1,7 @@ class School < ActiveRecord::Base attr_accessible :name, :province,:pinyin has_many :courses + has_many :departments, :dependent => :destroy def to_s self.name.to_s diff --git a/app/models/syllabus.rb b/app/models/syllabus.rb index ea5d44dfd..ecb496753 100644 --- a/app/models/syllabus.rb +++ b/app/models/syllabus.rb @@ -20,12 +20,15 @@ class Syllabus < ActiveRecord::Base belongs_to :user has_many :courses + has_many :reference_materials, :dependent => :destroy + has_many :syllabus_update_records, :dependent => :destroy has_many :journals_for_messages, :as => :jour, :dependent => :destroy has_many :syllabus_members, :dependent => :destroy has_many :praise_tread, as: :praise_tread_object, dependent: :destroy has_one :praise_tread_cache, as: :object, dependent: :destroy - attr_accessible :description, :user_id, :title, :eng_name, :syllabus_type, :credit, :hours, :theory_hours, :practice_hours, :applicable_major, :pre_course - safe_attributes 'title','user', 'description', 'eng_name', 'syllabus_type', 'credit', 'hours', 'theory_hours', 'practice_hours', 'credit', 'applicable_major', 'pre_course' + belongs_to :first_level_discipline + attr_accessible :description, :user_id, :title, :eng_name, :syllabus_type, :credit, :hours, :theory_hours, :practice_hours, :applicable_major, :pre_course, :major_level, :discipline_category_id, :first_level_discipline_id + safe_attributes 'title','user', 'description', 'eng_name', 'syllabus_type', 'credit', 'hours', 'theory_hours', 'practice_hours', 'credit', 'applicable_major', 'pre_course', 'major_level', 'discipline_category_id', "first_level_discipline_id" validates :title, :user_id, presence: true @@ -48,7 +51,21 @@ class Syllabus < ActiveRecord::Base delete_kindeditor_assets_from_disk self.id,OwnerTypeHelper::SYLLABUS end + def syllabus_major_level + type = "" + case self.major_level + when 1 + type = "研究生/博士" + when 2 + type = "本科" + when 3 + type = "专科" + end + type + end + def syllabus_type_str + type = "" case self.syllabus_type when 1 type = "公共必修课" diff --git a/app/models/syllabus_update_record.rb b/app/models/syllabus_update_record.rb new file mode 100644 index 000000000..f5d2481e4 --- /dev/null +++ b/app/models/syllabus_update_record.rb @@ -0,0 +1,6 @@ +class SyllabusUpdateRecord < ActiveRecord::Base + belongs_to :user + belongs_to :syllabus + #property 1:描述 2:参考资料 + attr_accessible :property, :syllabus_id, :user_id +end diff --git a/app/models/user.rb b/app/models/user.rb index f023fde4b..3b6c0441c 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -605,6 +605,16 @@ class User < Principal name_formatter[:order].map {|field| "#{table}.#{field}"} end + # 186***2342 + def user_phone + phone.nil? || (phone && phone.empty?) ? "" : phone.gsub(/(\d{3})\d{4}(\d{4})/, '\1****\2') + end + + # 8***2@qq.com + def user_mail + mail.nil? || (mail && mail.empty?) ? "" : mail.gsub(/(.{1}).+(.{1}@.+)/, '\1****\2') + end + # Return user's full name for display def realname(formatter = nil) f = self.class.name_formatter(formatter) @@ -1198,7 +1208,9 @@ class User < Principal 'language', 'custom_field_values', 'custom_fields', - 'identity_url' + 'identity_url', + 'phone', + 'authentication' safe_attributes 'status', 'auth_source_id', diff --git a/app/models/user_extensions.rb b/app/models/user_extensions.rb index a02b1ac6a..10904d106 100644 --- a/app/models/user_extensions.rb +++ b/app/models/user_extensions.rb @@ -11,6 +11,7 @@ class UserExtensions < ActiveRecord::Base belongs_to :user belongs_to :school, :class_name => 'School', :foreign_key => :school_id + belongs_to :department attr_accessible :user_id,:birthday,:brief_introduction,:gender,:location,:occupation,:work_experience,:zip_code,:identity, :technical_title,:student_id validates_length_of :description, :maximum => 255 validates_length_of :brief_introduction, :maximum => 255 diff --git a/app/views/account/avatar.html.erb b/app/views/account/avatar.html.erb new file mode 100644 index 000000000..deca3169a --- /dev/null +++ b/app/views/account/avatar.html.erb @@ -0,0 +1,136 @@ + + + + + + + + +
+ +
+ + \ No newline at end of file diff --git a/app/views/account/change_or_bind.html.erb b/app/views/account/change_or_bind.html.erb new file mode 100644 index 000000000..d9a5b266b --- /dev/null +++ b/app/views/account/change_or_bind.html.erb @@ -0,0 +1,85 @@ +
+
+ <%= form_tag(bind_email_or_phone_path, :id => 'bind_email_or_phone_form') do %> + + <% if @type == 'phone' %> +

手机绑定

+ +
+ + 设置新手机号,并验证 +
+ + <% elsif @type == 'mail' %> +

邮箱绑定

+ +
+ + 设置新邮箱地址,并验证 +
+ + <% end %> + <% end %> +
+
+ + + \ No newline at end of file diff --git a/app/views/account/change_psd.html.erb b/app/views/account/change_psd.html.erb new file mode 100644 index 000000000..314daaef7 --- /dev/null +++ b/app/views/account/change_psd.html.erb @@ -0,0 +1,38 @@ +
+ + <% if( !@act.nil? && @act == 'password') %> + <%= render_flash_messages %> + <% end %> +
+ +
+
\ No newline at end of file diff --git a/app/views/account/security_settings.html.erb b/app/views/account/security_settings.html.erb new file mode 100644 index 000000000..d6b9f6438 --- /dev/null +++ b/app/views/account/security_settings.html.erb @@ -0,0 +1,40 @@ +
+ + + + + + + + + + + + + + + +
+
\ No newline at end of file diff --git a/app/views/account/user_join.html.erb b/app/views/account/user_join.html.erb index 66437dfa1..2daaf2606 100644 --- a/app/views/account/user_join.html.erb +++ b/app/views/account/user_join.html.erb @@ -9,7 +9,7 @@
-