diff --git a/.idea/bigdate.iml b/.idea/bigdate.iml index 75895d98a..62e3c0921 100644 --- a/.idea/bigdate.iml +++ b/.idea/bigdate.iml @@ -77,6 +77,8 @@ + + @@ -100,7 +102,9 @@ + + @@ -196,6 +200,7 @@ + @@ -256,6 +261,11 @@ + + + + + diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml index e9ec192f0..934f79cf7 100644 --- a/.idea/dataSources.xml +++ b/.idea/dataSources.xml @@ -28,25 +28,25 @@ mysql com.mysql.jdbc.Driver - jdbc:mysql://127.0.0.1/trustie2 + jdbc:mysql://127.0.0.1/0604new root - df9bdf98df99df9edf9fdf9c + df9bdf98df99df9e mysql com.mysql.jdbc.Driver - jdbc:mysql://127.0.0.1/trustie2 + jdbc:mysql://127.0.0.1/20161227data root - df9bdf98df99df9edf9fdf9c + df9bdf98df99df9e mysql com.mysql.jdbc.Driver - jdbc:mysql://127.0.0.1/trustie2 + jdbc:mysql://127.0.0.1/0623newblank root - df9bdf98df99df9edf9fdf9c + df9bdf98df99df9e diff --git a/Gemfile b/Gemfile index 57e9d17f7..8033bf210 100644 --- a/Gemfile +++ b/Gemfile @@ -75,7 +75,7 @@ group :development, :test do gem 'pry-byebug' gem "test-unit", "~>3.0" end - # gem 'rspec-rails', '~> 3.0' + gem 'rspec-rails', '~> 3.0' gem 'factory_girl_rails' end diff --git a/app/assets/javascripts/discusses.js.coffee b/app/assets/javascripts/discusses.js.coffee new file mode 100644 index 000000000..761567942 --- /dev/null +++ b/app/assets/javascripts/discusses.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/javascripts/homework_bank.js.coffee b/app/assets/javascripts/homework_bank.js.coffee new file mode 100644 index 000000000..761567942 --- /dev/null +++ b/app/assets/javascripts/homework_bank.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/javascripts/management.js.coffee b/app/assets/javascripts/management.js.coffee new file mode 100644 index 000000000..761567942 --- /dev/null +++ b/app/assets/javascripts/management.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/javascripts/managements.js.coffee b/app/assets/javascripts/managements.js.coffee new file mode 100644 index 000000000..761567942 --- /dev/null +++ b/app/assets/javascripts/managements.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/javascripts/stages.js.coffee b/app/assets/javascripts/stages.js.coffee new file mode 100644 index 000000000..761567942 --- /dev/null +++ b/app/assets/javascripts/stages.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/javascripts/subjects.js.coffee b/app/assets/javascripts/subjects.js.coffee new file mode 100644 index 000000000..761567942 --- /dev/null +++ b/app/assets/javascripts/subjects.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/discusses.css.scss b/app/assets/stylesheets/discusses.css.scss new file mode 100644 index 000000000..3b4264c09 --- /dev/null +++ b/app/assets/stylesheets/discusses.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the discusses controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/homework_bank.css.scss b/app/assets/stylesheets/homework_bank.css.scss new file mode 100644 index 000000000..d8be9e5ef --- /dev/null +++ b/app/assets/stylesheets/homework_bank.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the HomeworkBank controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/management.css.scss b/app/assets/stylesheets/management.css.scss new file mode 100644 index 000000000..6d4f81abc --- /dev/null +++ b/app/assets/stylesheets/management.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the management controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/managements.css.scss b/app/assets/stylesheets/managements.css.scss new file mode 100644 index 000000000..00a467eed --- /dev/null +++ b/app/assets/stylesheets/managements.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the managements controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/stages.css.scss b/app/assets/stylesheets/stages.css.scss new file mode 100644 index 000000000..3784335fe --- /dev/null +++ b/app/assets/stylesheets/stages.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the stages controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/subjects.css.scss b/app/assets/stylesheets/subjects.css.scss new file mode 100644 index 000000000..454072191 --- /dev/null +++ b/app/assets/stylesheets/subjects.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the subjects 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 128d625b5..83a6d1ab1 100644 --- a/app/controllers/account_controller.rb +++ b/app/controllers/account_controller.rb @@ -22,6 +22,7 @@ class AccountController < ApplicationController # prevents login action to be filtered by check_if_login_required application scope filter skip_before_filter :check_if_login_required + skip_before_filter :check_authentication, :only => [:login, :logout, :user_join, :avatar, :authentication, :security_settings, :change_psd] before_filter :auth_login1, :only => [:avatar, :authentication, :security_settings, :change_psd] before_filter :require_login, only: [:avatar, :authentication, :security_settings, :change_psd, :user_auth] @@ -47,7 +48,7 @@ class AccountController < ApplicationController redirect_to user_path(User.current) end else - render :layout => 'login_bigdata' + render :layout => 'login_bigdata' end else authenticate_user @@ -83,7 +84,7 @@ class AccountController < ApplicationController # 服务协议 def agreement - render :layout => 'static_base' + render :layout => 'base_edu' end def about_us @@ -405,7 +406,7 @@ class AccountController < ApplicationController user = User.current token = Token.new(:user => user, :action => "bind") if token.save - Mailer.run.bind_email(token, verification_code) + Mailer.run.bind_email(token, verification_code, params[:value]) VerificationCode.create(:email => params[:value], :status => 1, :code_type => 5, :code => verification_code) end rescue => e @@ -451,6 +452,16 @@ class AccountController < ApplicationController render :layout => 'base_edu_account' end + def apply_trail + apply_action = ApplyAction.where(:user_id => User.current.id, :container_type => "TrialAuthorization", :status => 0).first + if apply_action.blank? + ApplyAction.create(:user_id => User.current.id, :status => 0, :container_type => "TrialAuthorization") + end + respond_to do |format| + format.js + end + end + def user_auth @user = User.current diskfile1 = disk_auth_filename('UserAuthentication', @user.id, 'ID') @@ -483,6 +494,15 @@ class AccountController < ApplicationController render :layout => 'base_edu_account' end + # 修改密码时判断密码是否输入正确 + def valid_psd + @user = User.current + req = Hash.new(false) + req[:valid] = false + req[:valid] = @user.check_password?(params[:value]) + render :json => req + end + def change_or_bind @user = User.current @type = params[:type] diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index 9bb0dc75c..c6298555e 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -939,6 +939,39 @@ class AdminController < ApplicationController end + # 身份认证 + def identity_authentication + type = params[:type] || 0 # 存在type 就用type 没有就为 0 + + user_id = User.find_by_sql("select id from users where concat(lastname,firstname) like '%#{params[:name]}%'") + @unapproved_user = ApplyUserAuthentication.where(:status => type, :user_id => user_id).order("updated_at desc") + + + respond_to do |format| + format.html{ render :layout => 'base_edu' } + format.js + end + end + + # 拒绝身份认证 + def reject_authentication + apply_user = ApplyUserAuthentication.find(params[:apply_id]) + reason = apply_user.update_attributes(:status => 2, :remarks => params[:reject_reason]) + render :json => {success: reason} + end + + # 统一身份认证 + def agree_authentication + apply_user = ApplyUserAuthentication.find(params[:apply_id]) + user = User.find(apply_user.user_id) + apply_user.update_attribute(:status, 1) + user.update_attribute(:authentication, true) + @unapproved_user = ApplyUserAuthentication.where(:status => 0).order("updated_at desc") + respond_to do |format| + format.js + end + end + def create_version @versions = PhoneAppVersion.reorder('created_at desc') @new_version = PhoneAppVersion.new diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 8fdc0801a..1e8ae7f1e 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -60,6 +60,20 @@ class ApplicationController < ActionController::Base logger.info "HTTP_USER_AGENT #{request.env["HTTP_USER_AGENT"]}" end + # 判断用户是否认证 + # def check_authentication + # # return true + # if params[:action] == "on_search" || params[:action] == "apply_trail" # 之所以这样处理是为了避开account页面ajax加载 + # return true + # end + # authentication = ApplyAction.where(:user_id => User.current.id, :status => 1).first + # user_identity = User.current.try(:user_extensions).try(:identity) + # if user_identity.blank? || authentication.blank? + # redirect_to my_account_path + # return + # end + # end + def session_expiration if session[:user_id] if session_expired? && !try_to_autologin @@ -106,6 +120,7 @@ class ApplicationController < ActionController::Base def current_user find_current_user end + def find_current_user user = nil unless api_request? @@ -948,6 +963,20 @@ class ApplicationController < ActionController::Base end end + # gitlab分页定制 + def paginateHelperForGitlab obj, pre_size=15 + @obj_count = obj.count + @obj_pages = Paginator.new @obj_count, pre_size, params['page'] + if obj.kind_of? ActiveRecord::Base or obj.kind_of? ActiveRecord::Relation + obj.limit(@obj_pages.per_page).offset(@obj_pages.offset) + elsif obj.kind_of? Array + obj[0, @obj_pages.per_page] + else + logger.error "[ApplicationController] Error : application_controller#paginateHelper ===> unknow category: #{obj.class}" + raise RuntimeError, 'unknow type, Please input you type into this helper.' + end + end + #查找首页相关信息 def find_first_page @first_page = FirstPage.find_by_page_type('project') diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index bee294f5c..ddce8496d 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -371,7 +371,7 @@ class AttachmentsController < ApplicationController @attachment = Attachment.find(params[:attachments ].first[1][:attachment_id]) #将需要修改的记录保存到历史记录 @history = AttachmentHistory.new - @history.attributes = @old_attachment.attributes.dup.except("id") + @history.attributes = @old_attachment.attributes.dup.except("id", "resource_bank_id") @history.attachment_id = params[:old_attachment_id] #需要更新版本号,需要拿到原来该文件最大的历史版本号 @old_history = @old_attachment.attachment_histories.reorder('version desc').first diff --git a/app/controllers/avatar_controller.rb b/app/controllers/avatar_controller.rb index b9a166a6e..409fdc43f 100644 --- a/app/controllers/avatar_controller.rb +++ b/app/controllers/avatar_controller.rb @@ -1,3 +1,4 @@ +#encoding: utf-8 class AvatarController < ApplicationController include ActionView::Helpers::NumberHelper @@ -92,7 +93,9 @@ class AvatarController < ApplicationController end end - if @source_type == 'Contest' + if @source_type == 'UserAuthentication' + + elsif @source_type == 'Contest' Trustie::Utils::Image.new(diskfile,true).compress(900) else Trustie::Utils::Image.new(diskfile,true).compress(300) diff --git a/app/controllers/boards_controller.rb b/app/controllers/boards_controller.rb index ca6f6912f..1c0fa35a4 100644 --- a/app/controllers/boards_controller.rb +++ b/app/controllers/boards_controller.rb @@ -19,7 +19,7 @@ class BoardsController < ApplicationController layout 'base_projects'#by young default_search_scope :messages before_filter :find_project_by_project_id, :find_board_if_available, :except => [:join_to_org_subfields] - before_filter :authorize, :except => [:new, :show, :create, :index, :join_to_org_subfields, :update_position, :update_name] + before_filter :authorize, :except => [:new, :show, :create, :index, :join_to_org_subfields, :update_position, :update_name, :update_boards_position, :update_boards_name] accept_rss_auth :index, :show @@ -183,7 +183,7 @@ class BoardsController < ApplicationController end #分页 - @limit = 15 + @limit = 1 @is_remote = true @atta_count = @topics.count @atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1 @@ -260,6 +260,10 @@ class BoardsController < ApplicationController board.project_id = -1 board.position = parent.children.count + 1 parent.children << board + + @course_board = @course.boards.where("parent_id is NULL").first + @board = @course_board.children.order("position asc") + @board_count = @board.count respond_to do |format| format.js end @@ -298,6 +302,11 @@ class BoardsController < ApplicationController after_boards = @board.parent.children.where("position > #{@board.position}") after_boards.update_all("position = position - 1") @board.destroy + + @course_board = @course.boards.where("parent_id is NULL").first + @board = @course_board.children.order("position asc") + @board_count = @board.count + if @course || @contest respond_to do |format| format.js @@ -327,6 +336,29 @@ class BoardsController < ApplicationController end end + def update_boards_position + boards = @board.parent.children + if params[:opr] == 'up' && @board.position > 1 + before_board = boards.where("position = #{@board.position - 1}").first + if before_board && @board.update_attribute('position', @board.position - 1) + before_board.update_attribute('position', before_board.position + 1) + end + elsif params[:opr] == 'down' && @board.position < boards.count + after_board = boards.where("position = #{@board.position + 1}").first + if after_board && @board.update_attribute('position', @board.position + 1) + after_board.update_attribute('position', after_board.position - 1) + end + end + + @course_board = @course.boards.where("parent_id is NULL").first + @board = @course_board.children.order("position asc") + @board_count = @board.count + + respond_to do |format| + format.js + end + end + def update_name if @course || @contest @board.update_attribute("name", params[:name]) @@ -337,6 +369,19 @@ class BoardsController < ApplicationController end end + def update_boards_name + @board.update_attribute("name", params[:name]) + @board.update_attribute("description", params[:name]) + + @course_board = @course.boards.where("parent_id is NULL").first + @board = @course_board.children.order("position asc") + @board_count = @board.count + + respond_to do |format| + format.js + end + end + def join_to_org_subfields if params[:id] @board = Board.find(params[:id]) diff --git a/app/controllers/challenges_controller.rb b/app/controllers/challenges_controller.rb index 050a45882..89e298286 100644 --- a/app/controllers/challenges_controller.rb +++ b/app/controllers/challenges_controller.rb @@ -1,12 +1,13 @@ # encoding: utf-8 class ChallengesController < ApplicationController layout "base_shixun" - before_filter :find_shixun, :only => [:index, :new, :create, :destroy, :challenge_build] - before_filter :find_challenge, :only => [:show, :edit, :update, :challenge_build, :index_up, :index_down, :destroy] + before_filter :check_authentication + before_filter :find_shixun, :only => [:index, :new, :create, :destroy, :challenge_build, :update_evaluation] + before_filter :find_challenge, :only => [:show, :edit, :update, :challenge_build, :index_up, :index_down, :destroy, :update_evaluation] before_filter :build_challege_from_params, :only => [:new, :create] before_filter :tpi_manager_allowed, :only => [:challenge_build, :destroy, :edit, :new, :create] before_filter :allowed_view, :only => [:show] - before_filter :query_challeges, :only => [:show, :edit, :update] + before_filter :query_challeges, :only => [:show, :edit, :update, :update_evaluation] before_filter :find_shixun_language, :only => [:show, :new, :edit] include ApplicationHelper @@ -25,6 +26,13 @@ class ChallengesController < ApplicationController @challenge.position = challenge_count + 1 @challenge.shixun = @shixun @challenge.user = User.current + @challenge.save! + + respond_to do |format| + format.html {redirect_to edit_shixun_challenge_path(@challenge, :shixun_id => @shixun)} + end + +=begin ActiveRecord::Base.transaction do begin @challenge.save! @@ -41,23 +49,10 @@ 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.exec_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']) - respond_to do |format| - format.html {redirect_to shixun_challenge_path(@challenge, :shixun_id => @shixun)} - end - else - logger.error("res['code'] is #{res['code']}, res['msg'] is #{res['msg']}") - # unless res['msg'].blank? - # test_msg = Base64.decode64(res['msg']) - # end - # logger.info("###############{test_msg}") - raise("脚本构建失败:本关执行文件名格式错误") + # 更新shixun公共测试用例 + add_shixun_modify_status(@shixun, 1) + respond_to do |format| + format.html {redirect_to shixun_challenge_path(@challenge, :shixun_id => @shixun)} end rescue Exception => e flash[:error] = "#{e.message}" @@ -65,6 +60,7 @@ class ChallengesController < ApplicationController raise ActiveRecord::Rollback end end +=end end # 处理新建challenge返回的pipeline片段 @@ -84,6 +80,11 @@ class ChallengesController < ApplicationController end def show + challenge_num = Challenge.where(:shixun_id => @shixun).count + challenge_pos = @challenge.position + if challenge_pos < challenge_num + @next_challenge = Challenge.where(:shixun_id => @shixun, :position => challenge_pos+1).first + end respond_to do |format| format.html format.js @@ -91,6 +92,13 @@ class ChallengesController < ApplicationController end def edit + challenge_num = Challenge.where(:shixun_id => @shixun).count + challenge_pos = @challenge.position + if challenge_pos < challenge_num + @next_challenge = Challenge.where(:shixun_id => @shixun, :position => challenge_pos+1).first + end + @tab = params[:tab].blank? ? 1 : params[:tab].to_i + @editor = params[:editor] # 编辑模式 end def destroy @@ -101,9 +109,13 @@ class ChallengesController < ApplicationController end def update + @challenge.update_attributes(params[:challenge]) + redirect_to edit_shixun_challenge_path(@challenge, :shixun_id => @shixun, :tab => params[:tab]) +=begin respond_to do |format| - if @challenge.update_attributes(params[:challenge]) - ActiveRecord::Base.transaction do + ActiveRecord::Base.transaction do + @challenge.update_attributes(params[:challenge]) + begin @test_sets.delete_all unless @test_sets.blank? @challenge_tags.delete_all unless @challenge_tags.blank? if params[:test_set][:hidden].length > 0 @@ -119,34 +131,60 @@ 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.exec_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("脚本构建失败") + # 向jenkins端发送请求,构建公共测试用例 + add_shixun_modify_status(@shixun, 1) + format.html {redirect_to shixun_challenge_path(@challenge, :shixun_id => @shixun), notice: '更新成功!'} + rescue Exception => e + flash[:error] = "#{e.message}" + format.html{redirect_to edit_shixun_challenge_path(@challenge, :shixun_id => @shixun)} + raise ActiveRecord::Rollback + end + end + end +=end + end + + def update_evaluation + ActiveRecord::Base.transaction do + @challenge.update_attributes(params[:challenge]) + begin + if params[:tab].to_i == 2 + @test_sets.delete_all unless @test_sets.blank? + if params[:test_set][:hidden].length > 0 + params[:test_set][:input].each_with_index do |input, index| + unless (input[index] == params[:test_set][:output][index] && input[index].nil?) + params[:test_set][:hidden][index].to_i == 0 ? open = 1 : open = 0 + TestSet.create(:challenge_id => @challenge.id, :input => input, :output => params[:test_set][:output][index], :is_public => open, :position => (index + 1)) + end + end + end + elsif params[:tab].to_i == 5 + @challenge_tags.delete_all unless @challenge_tags.blank? + unless params[:knowledge].blank? + params[:knowledge][:input].each do |input| + ChallengeTag.create(:name => input, :challenge_id => @challenge.id) + end end end - format.html {redirect_to shixun_challenge_path(@challenge, :shixun_id => @shixun), notice: '更新成功!'} - format.json { head :no_content } - else - format.html { render action: "edit" } - format.json { render json: @challenge.errors } + # 向jenkins端发送请求,构建公共测试用例 + add_shixun_modify_status(@shixun, 1) + redirect_to edit_shixun_challenge_path(@challenge, :shixun_id => @shixun, :tab => params[:tab]) + rescue Exception => e + flash[:error] = "#{e.message}" + redirect_to edit_shixun_challenge_path(@challenge, :shixun_id => @shixun, :tab => params[:tab]) + raise ActiveRecord::Rollback end end end - def index_down next_challenge = @challenge.next_challenge position = @challenge.position @challenge.update_attribute(:position, (position + 1)) next_challenge.update_attribute(:position, next_challenge.position - 1) @challenges = @shixun.challenges + # 向jenkins端发送请求,构建公共测试用例 + add_shixun_modify_status(@shixun, 1) end def index_up @@ -155,6 +193,8 @@ class ChallengesController < ApplicationController @challenge.update_attribute(:position, (position - 1)) last_challenge.update_attribute(:position, last_challenge.position + 1) @challenges = @shixun.challenges + # 向jenkins端发送请求,构建公共测试用例 + add_shixun_modify_status(@shixun, 1) end # build job 只负责发送请求 @@ -194,7 +234,7 @@ class ChallengesController < ApplicationController end def allowed_view - unless allow_to_view_challenge(@challenge, @shixun) + unless (allow_to_view_challenge(@challenge, @shixun) || User.current.manager_of_shixun?(@shixun)) render_403 end end @@ -230,6 +270,11 @@ class ChallengesController < ApplicationController if @shixun.nil? render_404 return + else + if (@shixun.status == 0 && !(User.current.manager_of_shixun?(@shixun) || User.current.admin?)) + render_403 + return + end end rescue ActiveRecord::RecordNotFound render_404 diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 414f98bfb..32fa30536 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -13,6 +13,8 @@ class CoursesController < ApplicationController helper SyllabusesHelper before_filter :auth_login1, :only => [:show, :course_activity, :feedback] + skip_before_filter :verify_authenticity_token, :only => [:update_position] + before_filter :check_authentication, :except => [:update_position] menu_item :overview menu_item :feedback, :only => :feedback menu_item :homework, :only => :homework @@ -40,28 +42,49 @@ class CoursesController < ApplicationController # def index @user = User.current - sy_courses = @user.courses.visible.not_deleted - syllabus_ids = sy_courses.empty? ? '(-1)' : "(" + sy_courses.map{|course| !course.syllabus_id.nil? && course.syllabus_id}.join(",") + ")" - syllabus_members = SyllabusMember.where("user_id = #{@user.id}") - syllabus_member_ids = syllabus_members.empty? ? "(-1)" : "(" + syllabus_members.map{|syl_mem| syl_mem.syllabus_id}.join(',') + ")" + @search = params[:search].nil? ? '' : params[:search] + @select = params[:select].nil? ? '' : params[:select] + @is_end = params[:is_end].nil? ? 0 : params[:is_end].to_i #是否归档 - search = params[:search].nil? ? '' : params[:search] - # 我发布的课程 - create_syllabuses = Syllabus.where("user_id = #{@user.id} and title like '%#{search}%'").order("created_at desc") - # 我参与的课程 - join_syllabuses = Syllabus.where("(id in #{syllabus_ids} or id in #{syllabus_member_ids}) and user_id != #{@user.id} and title like '%#{search}%'").order("created_at desc") - # 我的所有课程 - all_syllabuses = Syllabus.where("(id in #{syllabus_ids} or id in #{syllabus_member_ids}) and title like '%#{search}%'").order("created_at desc") + @syllabuses_num = Course.where("is_end = #{@is_end} and is_delete = 0").count + #@syllabus_count = all_syllabuses.count + # 我创建的课堂 + create_syllabuses = Course.where(:tea_id => @user.id).where("is_end = #{@is_end} and is_delete = 0 and name like '%#{@search}%'") + # 我参与的课堂 + join_syllabuses = @user.courses.where("is_end = #{@is_end} and is_delete = 0 and tea_id != #{@user.id} and name like '%#{@search}%'") + @join_syllabuses_count = join_syllabuses.count + @create_syllabuses_count = create_syllabuses.count # 页面筛选的课程 - if params[:select] == "create" + if @select == "create" @syllabuses = create_syllabuses - elsif params[:select] == "join" + elsif @select == "join" @syllabuses = join_syllabuses + elsif @select == "end" + # 归档的课堂 + end_syllabuses = Course.where("is_end = #{@is_end} and name like '%#{@search}%'") + @syllabuses = end_syllabuses else + # 全部课堂 + all_syllabuses = Course.where("is_end = #{@is_end} and is_delete = 0 and name like '%#{@search}%'") @syllabuses = all_syllabuses end + @syllabuses.each do |course| + course[:infocount] = course.members.count + #course[:infocount] = (User.current.admin? || User.current.allowed_to?(:as_teacher,course)) ? (course.homework_commons.count + visable_attachemnts_incourse(course).count + course.members.count) : (course.homework_commons.where("publish_time <= '#{Time.now}'").count + visable_attachemnts_incourse(course).count + course.members.count) + if course[:infocount] < 0 + course[:infocount] = 0 + end + end + @syllabuses = @syllabuses.sort{|x,y| y[:infocount] <=> x[:infocount] } + + @syllabuses_count = @syllabuses.count + @limit = 16 + @is_remote = true + @syllabuses_pages = Paginator.new @syllabuses_count, @limit, params['page'] || 1 + @offset ||= @syllabuses_pages.offset + @syllabuses = paginateHelper @syllabuses, @limit respond_to do |format| format.js format.html { render :layout => "base_edu" } @@ -162,18 +185,18 @@ class CoursesController < ApplicationController @course = c[:course] if @course.errors.full_messages.count <= 0 respond_to do |format| - format.html { + format.js { # render :layout => 'base_courses' #flash[:notice] = l(:notice_successful_update) - redirect_to settings_course_url(@course) + #redirect_to settings_course_url(@course) } format.api { render_api_ok } end else respond_to do |format| - format.html { - settings - redirect_to settings_course_url(@course) + format.js { + # settings + # redirect_to settings_course_url(@course) } format.api { render_validation_errors(@course) } end @@ -340,7 +363,9 @@ class CoursesController < ApplicationController member.update_attributes(:course_group_id => params[:course_group_id].to_i) if member end end - @no_group_student = @course.student.count - @course.members.where("course_group_id != 0").count + @teacher_count = searchTeacherAndAssistant(@course).count + @student_count = @course.student.count + @no_group_count = @course.members.where("course_group_id = 0").select{|m| m.roles.to_s.include?("Student")}.count respond_to do |format| format.js end @@ -388,9 +413,9 @@ class CoursesController < ApplicationController @search = params[:search] q = params[:search] ? "#{params[:search].strip}" : "" if @order == "student_id" - @members = @course.members.joins("join user_extensions on members.user_id = user_extensions.user_id").order("student_id #{@sort}").select{|m| m.roles.to_s.include?("Student")} + @members = @course.members.joins("join user_extensions on members.user_id = user_extensions.user_id").order("student_id #{@r_sort}").select{|m| m.roles.to_s.include?("Student")} else - @members = @course.members.joins("join users on members.user_id = users.id").order("CONVERT(lastname USING gbk) COLLATE gbk_chinese_ci #{@sort}, login #{@b_sort}").select{|m| m.roles.to_s.include?("Student")} + @members = @course.members.joins("join users on members.user_id = users.id").order("CONVERT(lastname USING gbk) COLLATE gbk_chinese_ci #{@r_sort}, login #{@r_sort}").select{|m| m.roles.to_s.include?("Student")} end if q.nil? || q == "" else @@ -414,7 +439,7 @@ class CoursesController < ApplicationController @teacher_count = TeacherAndAssistantCount @course @student_count = studentCount(@course) - @no_group_count = @student_count - @course.members.where("course_group_id != 0").count + @no_group_count = @course.members.where(:course_group_id => 0).select{|m| m.roles.to_s.include?("Student")}.count respond_to do |format| format.js end @@ -453,7 +478,7 @@ class CoursesController < ApplicationController @teacher_count = TeacherAndAssistantCount @course @student_count = studentCount(@course) - @no_group_count = @student_count - @course.members.where("course_group_id != 0").count + @no_group_count = @course.members.where(:course_group_id => 0).select{|m| m.roles.to_s.include?("Student")}.count respond_to do |format| format.js end @@ -493,7 +518,7 @@ class CoursesController < ApplicationController @teacher_count = TeacherAndAssistantCount @course @student_count = studentCount(@course) - @no_group_count = @student_count - @course.members.where("course_group_id != 0").count + @no_group_count = @course.members.where(:course_group_id => 0).select{|m| m.roles.to_s.include?("Student")}.count respond_to do |format| format.js end @@ -568,6 +593,10 @@ class CoursesController < ApplicationController member.course_group_id = 0 member.save @group = group + @course = @group.course + @teacher_count = searchTeacherAndAssistant(@course).count + @student_count = @course.student.count + @no_group_count = @course.members.where("course_group_id = 0").select{|m| m.roles.to_s.include?("Student")}.count end def searchgroupmembers @@ -589,7 +618,7 @@ class CoursesController < ApplicationController page_from = params[:page].nil? ? 0 : (params[:page].to_i - 1) @results = student_homework_score(0,page_from, 10,"desc") end - @no_group_count = @course.student.count - @course.members.where("course_group_id != 0").count + @no_group_count = @course.members.where(:course_group_id => 0).select{|m| m.roles.to_s.include?("Student")}.count @course_groups = @course.course_groups @limit = 50 @page = params[:page].nil? ? 1 : params['page'].to_i @@ -675,7 +704,7 @@ class CoursesController < ApplicationController @teacher_count = TeacherAndAssistantCount @course @student_count = studentCount(@course) - @no_group_count = @student_count - @course.members.where("course_group_id != 0").count + @no_group_count = @course.members.where(:course_group_id => 0).select{|m| m.roles.to_s.include?("Student")}.count respond_to do |format| if @search @@ -704,7 +733,7 @@ class CoursesController < ApplicationController end @homeworks = @course.homework_commons.where("publish_time <= '#{Time.now}'").order("created_at asc") - filename="#{@course.teacher.lastname.to_s + @course.teacher.firstname.to_s }_#{@course.name}_#{@course.time.to_s + @course.term}#{l(:excel_member_list)}"; + filename="#{@course.teacher.lastname.to_s + @course.teacher.firstname.to_s }_#{@course.name}_#{l(:excel_member_list)}"; respond_to do |format| format.xls { @@ -751,7 +780,7 @@ class CoursesController < ApplicationController @limit = 50 @page = params[:page].nil? ? 1 : params['page'].to_i @members_count = @results.count - @no_group_count = @members_count - @course.members.where("course_group_id != 0").count + @no_group_count = @course.members.where(:course_group_id => 0).select{|m| m.roles.to_s.include?("Student")}.count @mem_pages = Paginator.new @members_count, @limit, @page @results = paginateHelper @results, @limit end @@ -797,7 +826,7 @@ class CoursesController < ApplicationController CourseMessage.create(:user_id => member.user_id, :course_id => @course.id, :course_message_type => "RemoveFromCourse", :viewed => false, :course_message_id => User.current.id) @course_groups = @course.course_groups - @no_group_count = @course.student.count - @course.members.where("course_group_id != 0").count + @no_group_count = @course.members.where(:course_group_id => 0).select{|m| m.roles.to_s.include?("Student")}.count @canShowCode = isCourseTeacher(User.current.id,@course) respond_to do |format| format.js @@ -824,6 +853,7 @@ class CoursesController < ApplicationController if User.current.allowed_to?(:as_teacher,@course) @select_tab = params[:tab] + @role = params[:role] if params[:role] @issue_custom_fields = IssueCustomField.sorted.all @issue_category ||= IssueCategory.new @member ||= @course.members.new @@ -832,19 +862,26 @@ class CoursesController < ApplicationController @teachers = searchTeacherAndAssistant(@course) @teacher_count = @teachers.count @student_count = studentCount(@course) - @no_group_count = @student_count - @course.members.where("course_group_id != 0").count + @no_group_count = @course.members.where(:course_group_id => 0).select{|m| m.roles.to_s.include?("Student")}.count + @apply_users = CourseMessage.where(:course_id => @course.id,:course_message_type => 'JoinCourseRequest', :status => 0) - @roles = Role.givable.all[3..5] - @members = @course.member_principals.includes(:roles, :principal).all.sort - - course_org_ids = OrgCourse.find_by_sql("select distinct organization_id from org_courses where course_id = #{@course.id}").map(&:organization_id) - if course_org_ids.empty? - @orgs_not_in_course = User.current.organizations - else - course_org_ids = "(" + course_org_ids.join(',') + ")" - @orgs_not_in_course = User.current.organizations.where("organizations.id not in #{course_org_ids}") + course_module = @course.course_modules + if course_module.blank? + type = ["news", "boards", "homework", "exercises", "poll", "statistics", "attachment"] + for i in 0..6 + CourseModule.create(:course_id => @course.id, :type => type[i], :position => i + 1, :hidden => 0 ) + end + course_module = @course.course_modules end + + @modules = course_module.order("position asc") + + @course_board = @course.boards.where("parent_id is NULL").first + @board = @course_board.children.order("position asc") + @board_count = @board.count + + @curr_page = '设置' respond_to do |format| format.html { render :layout => 'base_edu_course' } @@ -856,6 +893,47 @@ class CoursesController < ApplicationController end + def update_position + + course_module = @course.course_modules + + for i in 0..6 + case params[:position][i] + when "boards" + course_module.where(:module_type => 'boards').first.update_attribute('position', i+1) + when "news" + course_module.where(:module_type => 'news').first.update_attribute('position', i+1) + when "homework" + course_module.where(:module_type => 'homework').first.update_attribute('position', i+1) + when "exercises" + course_module.where(:module_type => 'exercises').first.update_attribute('position', i+1) + when "poll" + course_module.where(:module_type => 'poll').first.update_attribute('position', i+1) + when "statistics" + course_module.where(:module_type => 'statistics').first.update_attribute('position', i+1) + when "attachment" + course_module.where(:module_type => 'attachment').first.update_attribute('position', i+1) + end + end + + # params[:message] 有值 就更行字段: 0为不隐藏,1为隐藏 + type = ["news", "boards", "attachment", "homework", "poll", "exercises", "statistics"] + + hidden = type - params[:message] + course_module.where(:module_type => params[:message]).update_all(:hidden => 0) + course_module.where(:module_type => hidden).update_all(:hidden => 1) + + + @modules = @course.course_modules.order("position asc") + @course_board = @course.boards.where("parent_id is NULL").first + @board = @course_board.children.order("position asc") + @board_count = @board.count + + respond_to do |format| + format.js + end + end + def private_or_public if @course.is_public == 0 @course.update_attributes(:is_public => 1) @@ -1250,7 +1328,7 @@ class CoursesController < ApplicationController # course_request_messages = CourseMessage.where("user_id =? and course_id =? and course_message_type =? and viewed =?", User.current.id, @course.id, 'CourseRequestDealResult', false) # course_request_messages.update_all(:viewed => true) - course_activities = @course.course_activities + course_activities = @course.course_activities.where("course_act_type in ('HomeworkCommon', 'Attachment', 'Course')") @canShowRealName = User.current.member_of_course? @course @page = params[:page] ? params[:page].to_i + 1 : 0 if params[:type].present? @@ -1336,6 +1414,7 @@ class CoursesController < ApplicationController # 作业查重 def code_repeat #代码查重新加的 + @index = params[:index] @order,@b_sort,@name,@group = params[:order] || "score",params[:sort] || "desc",params[:name] || "",params[:group] @is_teacher = User.current.allowed_to?(:as_teacher,@course) || User.current.admin? @@ -1356,13 +1435,13 @@ class CoursesController < ApplicationController puts tmpwork.id end - #respond_to do |format| - #format.html {render :layout => 'base_courses'} - #end + respond_to do |format| + format.html {render :layout => 'base_edu'} + end end def show_comparecode - + @index = params[:index] src_id = params[:src_id] dst_id = params[:dst_id] @@ -1393,7 +1472,7 @@ class CoursesController < ApplicationController @dst_username = dst_user.try(:realname) != " " ? dst_user.lastname + dst_user.firstname : dst_user.try(:login) respond_to do |format| - format.js + format.html{render :layout => 'base_edu'} end end @@ -1586,7 +1665,7 @@ class CoursesController < ApplicationController def search_not_students if !params[:search].nil? members = @course.members.select{|m| m.roles.to_s.include?("Student")} - member_ids = "(" + members.map(&:user_id).join(',') + ")" + member_ids = members.empty? ? "(-1)" : "(" + members.map(&:user_id).join(',') + ")" condition = "%#{params[:search].strip}%".gsub(" ","") @users = User.joins(:user_extensions).where("users.id not in #{member_ids} and status = 1 and (LOWER(concat(lastname, firstname)) LIKE '#{condition}' or user_extensions.student_id LIKE '#{condition}')") end @@ -1762,27 +1841,25 @@ class CoursesController < ApplicationController sheet1[1,1] = course.syllabus.title sheet1[2,0] = "班级编号" sheet1[2,1] = course.id - sheet1[3,0] = "班级学期" - sheet1[3,1] = course.time.to_s+"年"+course.term - sheet1[4,0] = "班级名称" - sheet1[4,1] = course.name - sheet1[5,0] = "教师团队" - sheet1[5,1] = (searchTeacherAndAssistant course).map{|member| member.user.show_name}.join('、') - sheet1[6,0] = "主讲教师" - sheet1[6,1] = course.teacher.show_name - sheet1[7,0] = "排名" - sheet1[7,1] = "学生姓名" - sheet1[7,2] = "昵称" - sheet1[7,3] = "学号" + sheet1[3,0] = "班级名称" + sheet1[3,1] = course.name + sheet1[4,0] = "教师团队" + sheet1[4,1] = (searchTeacherAndAssistant course).map{|member| member.user.show_name}.join('、') + sheet1[5,0] = "主讲教师" + sheet1[5,1] = course.teacher.show_name + sheet1[6,0] = "排名" + sheet1[6,1] = "学生姓名" + sheet1[6,2] = "昵称" + sheet1[6,3] = "学号" for i in 0 ... homeworks.count - sheet1[7,i+4] = "第"+(i+1).to_s+"次" + sheet1[6,i+4] = "第"+(i+1).to_s+"次" end - sheet1[7,homeworks.count+4] = "作业得分" - sheet1[7,homeworks.count+5] = "测评得分" - sheet1[7,homeworks.count+6] = "社区得分" - sheet1[7,homeworks.count+7] = "总得分" - sheet1[7,homeworks.count+8] = "分班" - count_row = 8 + sheet1[6,homeworks.count+4] = "作业得分" + sheet1[6,homeworks.count+5] = "测评得分" + sheet1[6,homeworks.count+6] = "社区得分" + sheet1[6,homeworks.count+7] = "总得分" + sheet1[6,homeworks.count+8] = "分班" + count_row = 7 members.each_with_index do |member, i| sheet1[count_row,0]= i+1 sheet1[count_row,1] = member.user.lastname.to_s + member.user.firstname.to_s @@ -1817,27 +1894,25 @@ class CoursesController < ApplicationController sheet[1,1] = course.syllabus.title sheet[2,0] = "班级编号" sheet[2,1] = course.id - sheet[3,0] = "班级学期" - sheet[3,1] = course.time.to_s+"年"+course.term - sheet[4,0] = "班级名称" - sheet[4,1] = course.name - sheet[5,0] = "教师团队" - sheet[5,1] = (searchTeacherAndAssistant course).map{|member| member.user.show_name}.join('、') - sheet[6,0] = "主讲教师" - sheet[6,1] = course.teacher.show_name - sheet[6,0] = "作业批次" - sheet[6,1] = "第#{i+1}次作业" - sheet[6,0] = "作业名称" - sheet[6,1] = home.name + sheet[3,0] = "班级名称" + sheet[3,1] = course.name + sheet[4,0] = "教师团队" + sheet[4,1] = (searchTeacherAndAssistant course).map{|member| member.user.show_name}.join('、') + sheet[5,0] = "主讲教师" + sheet[5,1] = course.teacher.show_name + sheet[5,0] = "作业批次" + sheet[5,1] = "第#{i+1}次作业" + sheet[5,0] = "作业名称" + sheet[5,1] = home.name if home.homework_type == 1 #普通作业 if home.anonymous_comment ==0 - sheet.row(7).concat([l(:excel_rank),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_homework_name),l(:excel_homework_des), + sheet.row(6).concat([l(:excel_rank),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_homework_name),l(:excel_homework_des), l(:excel_t_score),l(:excel_ta_score), l(:excel_n_score),l(:excel_a_penalty),l(:excel_l_penalty),l(:excel_f_score),l(:excel_commit_time)]) else - sheet.row(7).concat([l(:excel_rank),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_homework_name),l(:excel_homework_des), + sheet.row(6).concat([l(:excel_rank),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_homework_name),l(:excel_homework_des), l(:excel_t_score),l(:excel_ta_score),l(:excel_l_penalty),l(:excel_f_score),l(:excel_commit_time)]) end - count_row = 8 + count_row = 7 items = home.student_works.order("work_score desc") items.each_with_index do |stu, j| sheet[count_row,0]= j + 1 @@ -1863,13 +1938,13 @@ class CoursesController < ApplicationController end elsif home.homework_type == 2 #编程作业 if home.anonymous_comment ==0 - sheet.row(7).concat([l(:excel_rank),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_homework_name),l(:excel_homework_des), + sheet.row(6).concat([l(:excel_rank),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_homework_name),l(:excel_homework_des), l(:excel_t_score),l(:excel_ta_score), l(:excel_s_score),l(:excel_n_score),l(:excel_a_penalty),l(:excel_l_penalty),l(:excel_f_score),l(:excel_commit_time)]) else - sheet.row(7).concat([l(:excel_rank),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_homework_name),l(:excel_homework_des), + sheet.row(6).concat([l(:excel_rank),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_homework_name),l(:excel_homework_des), l(:excel_t_score),l(:excel_ta_score), l(:excel_s_score),l(:excel_l_penalty),l(:excel_f_score),l(:excel_commit_time)]) end - count_row = 8 + count_row = 7 items = home.student_works.order("work_score desc") items.each_with_index do |stu, j| sheet[count_row,0]= j + 1 @@ -1896,13 +1971,13 @@ class CoursesController < ApplicationController end elsif home.homework_type == 3 #分组作业 if home.anonymous_comment ==0 - sheet.row(7).concat([l(:excel_rank),l(:excel_group_member),l(:excel_homework_name),l(:excel_homework_project),l(:excel_homework_des), + sheet.row(6).concat([l(:excel_rank),l(:excel_group_member),l(:excel_homework_name),l(:excel_homework_project),l(:excel_homework_des), l(:excel_t_score),l(:excel_ta_score),l(:excel_n_score),l(:excel_a_penalty),l(:excel_l_penalty),l(:excel_f_score),l(:excel_commit_time)]) else - sheet.row(7).concat([l(:excel_rank),l(:excel_group_member),l(:excel_homework_name),l(:excel_homework_project),l(:excel_homework_des), + sheet.row(6).concat([l(:excel_rank),l(:excel_group_member),l(:excel_homework_name),l(:excel_homework_project),l(:excel_homework_des), l(:excel_t_score),l(:excel_ta_score),l(:excel_l_penalty),l(:excel_f_score),l(:excel_commit_time)]) end - count_row = 8 + count_row = 7 items = home.student_works.order("work_score desc") items.each_with_index do |stu, j| sheet[count_row,0] = j + 1 diff --git a/app/controllers/discusses_controller.rb b/app/controllers/discusses_controller.rb new file mode 100644 index 000000000..ba3c12665 --- /dev/null +++ b/app/controllers/discusses_controller.rb @@ -0,0 +1,48 @@ +class DiscussesController < ApplicationController + include ApplicationHelper + before_filter :find_dis_object, :except => [:destroy] + before_filter :find_discuss, :only => [:destroy] + + def create + if @model + if params[:reply_id].blank? + @model.discusses << Discuss.new(:content => params[:content], :user_id => User.current.id, :praise_count => 0) + else + @model.discusses << Discuss.new(:content => params[:content], :user_id => User.current.id, :parent_id => params[:reply_id], :root_id => params[:reply_id], :praise_count => 0) + end + if params[:dis_type] == "Shixun" + redirect_to shixun_discuss_shixun_path(@model) + end + end + end + + def destroy + if @discuss + if @discuss.dis_type == "Shixun" + @shixun = @discuss.dis + end + @discuss.destroy + end + end + + private + + def find_discuss + @discuss = Discuss.find params[:id] + rescue ActiveRecord::RecordNotFound + render_404 + end + + def find_dis_object + unless params[:dis_id] && params[:dis_type] + render_404 + else + case params[:dis_type] + when 'Shixun' + @model = Shixun.find params[:dis_id] + end + end + rescue ActiveRecord::RecordNotFound + render_404 + end +end diff --git a/app/controllers/forums_controller.rb b/app/controllers/forums_controller.rb index 24223c25d..ed646354c 100644 --- a/app/controllers/forums_controller.rb +++ b/app/controllers/forums_controller.rb @@ -8,6 +8,7 @@ class ForumsController < ApplicationController before_filter :authenticate_user_edit, :only => [:edit, :update] before_filter :authenticate_user_destroy, :only => [:destroy] before_filter :require_login, :only => [:new, :create,:destroy,:update,:edit] + before_filter :check_authentication helper :sort include SortHelper diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 2b0ebae3a..b53d6979e 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -3,8 +3,9 @@ class GamesController < ApplicationController layout "base_myshixun" skip_before_filter :verify_authenticity_token, :only => [:file_update] before_filter :find_myshixun, :only => [:index] - before_filter :find_game, :only => [:show, :game_build, :entry,:next_step, :outputs_show, :file_edit, :file_update, :game_status, :change_status, :answer, :minus_score] - before_filter :find_repository, :only => [:show, :entry, :file_edit, :file_update] + before_filter :find_game, :only => [:show, :game_build, :entry,:next_step, :outputs_show, :file_edit, :file_update, + :game_status, :change_status, :answer, :minus_score, :refresh_game_list, :reset_original_code, :reset_new_code] + before_filter :find_repository, :only => [:show, :entry, :file_edit, :file_update, :reset_original_code, :reset_new_code] before_filter :allowd_manager before_filter :allowd_view, :only => [:show] before_filter :find__shixun_language, :only => [:show, :entry] @@ -23,15 +24,19 @@ class GamesController < ApplicationController # 首次进入版本库自动打开文件 # path:"" && path: @game.path # @praise 判断是否点赞 - # @praise 判断是否踩 + # @tread 判断是否踩 + # git_repository_url @myshixun, "Myshixun" def show # 展示全部实训 if @game.status == 1 # 放置页面ajax数据还没获取就关闭 @game.update_attribute(:status, 0) end - @games = @myshixun.games.includes(:challenge) - @games_count = @games.count + # logger.info("#################%%%%%%#{@game.outputs.first.out_put}") + # @games = @myshixun.games.includes(:challenge) + @challenges = Challenge.where(:shixun_id => @myshixun.shixun_id) + @shixun = @myshixun.shixun + # @games_count = @games.count @game_challenge = @game.challenge @had_done = @game.had_done @praise = PraiseTread.where("praise_tread_object_id=? and praise_tread_object_type=? and user_id=?", @game_challenge.id, @game_challenge.class.to_s, User.current.id).first @@ -57,7 +62,7 @@ class GamesController < ApplicationController end end end - @content = Base64.urlsafe_decode64(file_content) unless file_content.blank? + @content = Base64.decode64(file_content) unless file_content.blank? end if @content.nil? @entries = @repository.entries(@path, @rev) @@ -77,11 +82,13 @@ class GamesController < ApplicationController @had_passed_testsests_error_count = had_test.blank? ? 0 : had_test.select{|had_test| had_test.result == false}.count @had_passed_testsests_hidden_count = had_test.blank? ? 0 : had_test.select{|had_test| had_test.result == true && had_test.is_public == false}.count @had_passed_testsests_public_count = had_test.blank? ? 0 : had_test.select{|had_test| had_test.result == true && had_test.is_public == true}.count - @final_score = @game.final_score.to_i + @final_score = ((@game.answer_open? || @shixun.status <= 1) ? 0 : @game.final_score.to_i) @had_done = ((@myshixun.games.where(:status => 2).count == @myshixun.games.count && @game_challenge.position == @myshixun.games.count) ? 1 : 0) error_position = had_test.blank? ? nil : had_test.select{|had_test| had_test.result == false}.last logger.info("latest output id is #{error_position.id unless error_position.blank?}") - @latest_output = error_position.try(:out_put).gsub("\r\n", "
").gsub("\n", "
").html_safe unless error_position.try(:out_put).blank? + @latest_output = error_position.try(:out_put).gsub(/\n/, '
').gsub(/\t/, '        ').to_json unless error_position.try(:out_put).blank? + logger.info(@latest_output) + respond_to do |format| format.html format.js @@ -109,7 +116,7 @@ class GamesController < ApplicationController def file_update @g = Gitlab.client - content = params[:content].strip + content = params[:content].try(:strip) code_file = @g.edit_file(@myshixun.gpid, :content => params[:content], :file_path => @path, :branch_name => @rev, :commit_message => "shixun exec") unless code_file.blank? render :json => {:success => "success"} @@ -134,29 +141,50 @@ class GamesController < ApplicationController end # status 0: 未提交测评或者提交测评失败后报错;1:中间状态还没返回值;2:返回值并成功 + # resubmit 唯一随机码,为了区分每一次重新评测结果 + CODES = %W(1 2 3 4 5 6 7 8 9 A B C D E F G H J K L N M O P Q R S T U V W X Y Z) def game_build game_challenge = @game.challenge - gitUrl = git_repository_url(@myshixun, "Myshixun") + shixun = @myshixun.shixun + gitUrl = git_myshixun_url_ip(@myshixun, @myshixun.try(:user_id)) gitUrl = Base64.encode64(gitUrl) taskId = @game.id jobName = "myshixun_#{@myshixun.id}" - resubmit = (@game.status == 2 ? "1" : "0") - # 过关后重评不更新状态 - unless resubmit == "1" + code = CODES.sample(8).join + # status为2说明是重新评测 + if @game.status == 2 + resubmit = "#{code}_#{@myshixun.id}" + else @game.update_attributes!(:status => 1) end + + # 过关后重评不更新状态 + # if resubmit.nil? + # @game.update_attributes!(:status => 1) + # end + + # 如果shixun有改动,增需要进行后台的一些更新 + shixun_mod = ShixunModify.where(:myshixun_id => @myshixun.id, :status => 1).first + modifyStatus = 0 + unless shixun_mod.nil? + modifyStatus = 1 + gameInfo = shixun.gameInfo + end jenkins_shixuns = Redmine::Configuration['jenkins_shixuns'] step = game_challenge.try(:position) - params = {:jobNameForInstance => "#{jobName}", :buildID => "#{taskId}", :step => "#{step}", :instanceGitURL => "#{gitUrl}", :instanceChallenge => "#{step}", :resubmit => resubmit} + # 注意:这个地方的参数写的时候不能换行 + params = {:jobNameForInstance => "#{jobName}", :buildID => "#{taskId}", :instanceGitURL => "#{gitUrl}", :instanceChallenge => "#{step}", :resubmit => resubmit, :modifyStatus => "#{modifyStatus}", :gameInfo => "#{gameInfo}"} uri = URI("#{jenkins_shixuns}/jenkins-exec/api/buildJobForInstance") res = uri_exec uri, params logger.info("#####################buildJobForInstance result is #{res}") + logger.info("#####################buildJobForInstance params is #{params}") if (res && res['code'] != 0) - raise("Build job failed") + @message = "实训云平台繁忙(繁忙等级:86)" + raise("实训云平台繁忙(繁忙等级:86)") end - render :json => {:result => "success"} + render :json => {:result => "success", :resubmit => resubmit} rescue - unless resubmit == "1" + if resubmit.nil? @game.update_attributes!(:status => 0) end #REDO Jenkins服务异常弹框抛出 @@ -165,27 +193,43 @@ class GamesController < ApplicationController # @myshixun -status 1:完成实训 # 全部通关奖励1000分 - # retry_status不等于0则说明是重新评测,重新评测对以前已产生的结果不造成影响 + # retry_status 评测的唯一标识,重新评测对以前已产生的结果不造成影响 + # params[:resubmit] 不为空表示已通过该关后重新评测, 重新评测必须是通过该关后才能执行 # @had_done 1 通关所有关 def game_status game_challenge = @game.challenge had_done = @game.had_done - # 重新评测不需要全部通关效果 - if @game.retry_status != 0 - game_status = (@game.retry_status == 2 ? 2 : 0) - had_done = 0 - else - if had_done == 1 - reward_grade(@game.user, @game.id, @game.class, 1000) + resubmit_identifier = @game.resubmit_identifier + shixun = @myshixun.shixun + logger.info("##### resubmit_identifier is #{resubmit_identifier}") + if params[:resubmit].blank? # 非重新评测 + if had_done == 1 # 通过最后一关,即所有关卡 @myshixun.update_attribute(:status, 1) - else - # 通过当前一关 - if @game.status == 2 - @game.next_game.update_attribute(:status, 0) + end + # 通过当前一关 + if @game.status == 2 + @game.update_attribute(:end_time, Time.now) + game_passed_code(@game.id, game_challenge.try(:path), @myshixun.try(:gpid), 1) + if !@game.answer_open && shixun.status > 1 reward_grade(@game.user, @game.id, @game.class, game_challenge.score) + reward_experience(@game.user, @game.id, @game.class, game_challenge.score) end end game_status = @game.status + else # 重新评测 + if params[:resubmit] == resubmit_identifier # 本次重新评测结果已经返回并存入数据库 + game_status = (@game.retry_status == 2 ? 2 : 0) # retry_status 2:成功 1: 失败 + if game_status == 2 && had_done == 1 # 重新评测如果评测成功 + had_done =1 + game_passed_code(@game.id, game_challenge.try(:path), @myshixun.try(:gpid), 1) + else + had_done = 0 + end + else + # game_status 在前端有行为判断,2表示通关;0表示失败;1表示评测中的中间状态 + game_status = 1 + had_done = 0 + end end test_sets = game_challenge.test_sets unless test_sets.blank? @@ -201,9 +245,9 @@ class GamesController < ApplicationController @had_passed_testsests_error_count = had_test.blank? ? 0 : had_test.select{|had_test| had_test.result == false}.count @had_passed_testsests_hidden_count = had_test.blank? ? 0 : had_test.select{|had_test| had_test.result == true && had_test.is_public == false}.count @had_passed_testsests_public_count = had_test.blank? ? 0 : had_test.select{|had_test| had_test.result == true && had_test.is_public == true}.count - @final_score = @game.final_score.to_i + @final_score = ((@game.answer_open? || shixun.status <= 1) ? 0 : @game.final_score.to_i) error_position = had_test.blank? ? nil : had_test.select{|had_test| had_test.result == false}.last - @latest_output = error_position.try(:out_put).gsub("\r\n", "
").gsub("\n", "
") unless error_position.try(:out_put).blank? + @latest_output = error_position.try(:out_put).gsub(/\n/, '
').gsub(/\t/, '        ') unless error_position.try(:out_put).blank? render :json => {test_sets: total_test_sets, test_sets_count: @test_sets_count, test_sets_hidden_count: @test_sets_hidden_count, @@ -229,6 +273,27 @@ class GamesController < ApplicationController render :json => {status: @game.status, output: "服务器网络异常", results: outputs, had_done: 0} end + # 获取等待的任务数 + # 如果没有等待任务页面上将不显示 + # msg: -1 不存在等待的任务 + # 如果该方法异常则直接返回0,跳过等待 + def waiting_info + begin + jenkins_shixuns = Redmine::Configuration['jenkins_shixuns'] + params = {:buildID => "#{@game.id}"} + uri = URI("#{jenkins_shixuns}/jenkins-exec/api/getWaitingTime") + res = uri_exec uri, params + if (res && res['code'] != 0) + raise("获取等待任务数异常") + end + task_count = res['msg'].to_i + task_count > 0 ? task_count : 0 + render :json => {task_count: task_count} + rescue + render :json => {task_count: 0} + end + end + # 自动推送下一个任务 def next_step render_403 if @game.status != 2 @@ -244,52 +309,115 @@ class GamesController < ApplicationController # viewed 1: 直接查看 2:弹框提示将要扣除积分,确定后显示内容 3:弹框提示分数不够 def answer challenge = @game.challenge - user = User.current @challenge_score = challenge.score.to_i - user_score = user.grade.to_i - @score = user_score - @challenge_score # 已经开启过 + @score = User.current.grade.to_i - @challenge_score @answer = challenge.answer - if @game.answer_open + if challenge.shixun.status < 2 || @game.answer_open @viewed = 1 - logger.info("1 is #{@viewed}") else if @score >= 0 @viewed = 2 - logger.info("2 is #{@viewed}") else @viewed = 3 - logger.info("3 is #{@viewed}") end end respond_to do |format| format.js + format.html end end def minus_score - challenge = @game.challenge + @game_challenge = @game.challenge user = User.current - challenge_score = challenge.score.to_i - user_score = user.grade.to_i - @score = user_score - challenge_score - @answer = challenge.answer - - user.update_column(:grade, @score) + challenge_score = @game_challenge.score.to_i + reward_grade(user, @game.id, 'Answer', -challenge_score) + @answer = @game_challenge.answer @game.update_column(:answer_open, true) + respond_to do |format| + format.js + end + end + + def refresh_game_list + myshixun_id = params[:myshixun_id] + @myshixun = Myshixun.find_by_identifier(myshixun_id) + @challenges = Challenge.where(:shixun_id => @myshixun.shixun_id) respond_to do |format| format.js end end + def reset_original_code + begin + @shixun = @myshixun.shixun + @g = Gitlab.client + game_code = GameCode.where(:game_id => @game.id).first + content = game_code.try(:original_code) + if content.nil? + raise("初始代码为空,代码重置失败") + end + @path = params[:path] + @rev = @rev.nil? ? "master" : @rev + message = "file reset" + update_gitlab_file(content, @path, @rev, message) + file_content = @g.files(@myshixun.gpid, @path, @rev).content + @content = Base64.decode64(file_content) unless file_content.blank? + if @content.nil? + raise("初始代码为空,代码重置失败") + # @entries = @repository.entries(@path, @rev) + end + respond_to do |format| + format.js + end + rescue Exception => e + @error_messages = e.message + end + end + + def reset_new_code + begin + @shixun = @myshixun.shixun + @g = Gitlab.client + game_code = GameCode.where(:game_id => @game.id).first + content = game_code.try(:new_code) + if content.nil? + raise("示例代码为空,代码重置失败") + end + @path = params[:path] + @rev = @rev.nil? ? "master" : @rev + message = "file reset" + update_gitlab_file(content, @path, @rev, message) + file_content = @g.files(@myshixun.gpid, @path, @rev).content + @content = Base64.decode64(file_content) unless file_content.blank? + if @content.nil? + raise("示例代码为空,代码重置失败") + # @entries = @repository.entries(@path, @rev) + end + respond_to do |format| + format.js + end + rescue Exception => e + @error_messages = e.message + end + end + private + def update_gitlab_file content, path, rev, message + code_file = @g.edit_file(@myshixun.gpid, :content => content, :file_path => path, :branch_name => rev, :commit_message => "#{message}") + if code_file.nil? + raise("网络异常,文件更新失败") + end + end + def test_set_static_data test_sets test_result = [] unless test_sets.blank? test_sets.each do |test_set| output = Output.where(:game_id => @game.id, :test_set_position => test_set.position).first - actual_output = output.try(:actual_output) + actual_output = (output.try(:actual_output).gsub(/\n/, '
').gsub(/\t/, '        ') unless output.try(:actual_output).blank?) result = output.try(:result) public_result = {:is_public => (test_set.is_public ? 1 : 0), :result => result, :input => test_set.input, :actual_output => actual_output, :output => test_set.output} diff --git a/app/controllers/homework_bank_controller.rb b/app/controllers/homework_bank_controller.rb new file mode 100644 index 000000000..2f62ffdc3 --- /dev/null +++ b/app/controllers/homework_bank_controller.rb @@ -0,0 +1,236 @@ +class HomeworkBankController < ApplicationController + before_filter :require_login, :only => [:index, :show, :new, :create, :edit, :update, :destroy, :destroy_all, :choose_user_course, :send_h_bank_to_course] + before_filter :find_homework_bank, :only => [:show, :edit, :update, :destroy, :set_public] + + def index + @order,@b_sort = params[:order] || "updated_at",params[:sort] || "desc" + @user = User.current + @r_sort = @b_sort == "desc" ? "asc" : "desc" + @search = params[:search] + if(params[:type].blank? || params[:type] == "1") #我的题库 + @homeworks = @user.homework_banks.where("name like ?", "%#{@search}%") + elsif params[:type] == "2" #公共题库 + @homeworks = HomeworkBank.where(:is_public => true).where("name like ?", "%#{@search}%") + end + if params[:property] + @property = params[:property].to_i + @homeworks = @homeworks.where(:homework_type => params[:property].to_i) + end + @homeworks = @homeworks.reorder("#{@order} #{@b_sort}") + @type = params[:type] ? params[:type] : '1' + @limit = 15 + @is_remote = true + @hw_count = @homeworks.count + @hw_pages = Paginator.new @hw_count, @limit, params['page'] || 1 + @offset ||= @hw_pages.offset + @homeworks = paginateHelper @homeworks,15 + respond_to do |format| + format.js + format.html {render :layout => 'base_edu'} + end + end + + def show + @is_admin = User.current == @homework.user || User.current.admin? + respond_to do |format| + format.html {render :layout => 'base_edu'} + end + end + + def new + @homework_type = params[:homework_type].to_i + @homework = HomeworkBank.new + respond_to do |format| + format.html{render :layout => 'base_edu'} + end + end + + # 新建实训作业 + def shixuns + search = params[:search] + @homework = HomeworkBank.new + @shixuns = Shixun.where(:status => 2).where("name like ?", "%#{search}%") + @shixuns_count = @shixuns.count + @limit = 10 + @is_remote = true + @shixun_pages = Paginator.new @shixuns_count, @limit, params['page'] || 1 + @offset ||= @shixun_pages.offset + @shixuns = paginateHelper @shixuns, @limit + respond_to do |format| + format.js + end + end + + def create + if params[:homework_bank] || params[:shixun_homework] + homework = HomeworkBank.new + if params[:shixun_homework] + shixun = Shixun.find(params[:shixun_homework]) + homework.name = shixun.name + homework.description = shixun.description + else + homework.name = params[:homework_bank][:name] + homework.description = params[:homework_bank][:description] + homework.reference_answer = params[:homework_bank][:reference_answer] + homework.save_attachments(params[:attachments]) + render_attachment_warning_if_needed(homework) + end + homework.is_public = 0 + homework.quotes = 0 + homework.homework_type = params[:shixun_homework] ? 4 : (params[:homework_type].to_i || 1) + homework.user_id = User.current.id + homework.syllabus_id = params[:syllabus_id] if params[:syllabus_id] && params[:syllabus_id] != '0' + + #编程作业相关属性 + if homework.homework_type == 2 + homework.language = params[:language_type].to_i + + sample_inputs = params[:sample][:input] + if Array === sample_inputs + sample_inputs.each_with_index do |val, i| + homework.homework_bank_samples << HomeworkBankSample.new( + input: val, + output: params[:sample][:output][i] + ) + end + end + + inputs = params[:program][:input] + if Array === inputs + inputs.each_with_index do |val, i| + homework.homework_bank_tests << HomeworkBankTest.new( + input: val, + output: params[:program][:output][i] + ) + end + end + end + + #分组作业 + if homework.homework_type == 3 + homework.min_num = params[:min_num].to_i + homework.max_num = params[:max_num].to_i + end + + if homework.save + if homework.homework_type == 4 + HomeworkBankShixun.create(:homework_bank_id => homework.id, :shixun_id => shixun.id) + end + redirect_to homework_bank_path(homework) + end + end + end + + def edit + @homework_type = @homework.homework_type + respond_to do |format| + format.html{render :layout => 'base_edu'} + end + end + + def update + if params[:homework_bank] + @homework.name = params[:homework_bank][:name] + @homework.description = params[:homework_bank][:description] + @homework.reference_answer = params[:homework_bank][:reference_answer] + @homework.syllabus_id = params[:syllabus_id] ? (params[:syllabus_id] == '0' ? nil : params[:syllabus_id].to_i) : nil + @homework.save_attachments(params[:attachments]) + render_attachment_warning_if_needed(@homework) + + #编程作业相关属性 + if @homework.homework_type == 2 + @homework.language = params[:language_type].to_i if params[:language_type] + + @homework.homework_bank_samples.delete_all if params[:sample] + sample_inputs = params[:sample][:input] if params[:sample] + if Array === sample_inputs + sample_inputs.each_with_index do |val, i| + @homework.homework_bank_samples << HomeworkBankSample.new( + input: val, + output: params[:sample][:output][i] + ) + end + end + + @homework.homework_bank_tests.delete_all if params[:program] + inputs = params[:program][:input] if params[:program] + if Array === inputs + inputs.each_with_index do |val, i| + @homework.homework_bank_tests << HomeworkBankTest.new( + input: val, + output: params[:program][:output][i] + ) + end + end + end + + #分组作业 + if @homework.homework_type == 3 + @homework.min_num = params[:min_num].to_i if params[:min_num] + @homework.max_num = params[:max_num].to_i if params[:max_num] + end + + if @homework.save + redirect_to homework_bank_path(@homework) + end + end + end + + def destroy + @homework.homework_commons.update_all(:homework_bank_id => nil) + @homework.destroy + redirect_to homework_bank_index_path() + end + + def destroy_all + if params[:check_homework_bank] && !params[:check_homework_bank].blank? + params[:check_homework_bank].each do |hb_id| + homework = HomeworkBank.find hb_id + if homework && homework.user == User.current + HomeworkCommon.where(:homework_bank_id => homework.id).update_all(:homework_bank_id => nil) + homework.destroy + end + end + end + redirect_to homework_bank_index_path + end + + def choose_user_course + if !params[:search].nil? + search = "%#{params[:search].to_s.strip.downcase}%" + @courses = User.current.courses.where("is_delete = 0 and is_end = 0 and (#{Course.table_name}.id = #{params[:search].to_i } or #{Course.table_name}.name like :p)",:p=>search).select{ |course| User.current.has_teacher_role(course)} + else + @courses = User.current.courses.where("is_delete = 0 and is_end = 0").select{ |course| User.current.has_teacher_role(course)} + end + @homework_ids = params[:check_homework_bank] if params[:check_homework_bank] + @search = params[:search] + respond_to do |format| + format.js + end + end + + def send_h_bank_to_course + course = Course.find params[:course_id] + if course + params[:homework_id].each do |homework_id| + homework = HomeworkBank.find homework_id + quote_homework_bank homework, course + end + end + end + + def set_public + @homework.update_attributes(:is_public => true) + respond_to do |format| + format.html{ redirect_to homework_bank_path(@homework) } + format.js + end + end + + private + def find_homework_bank + @homework = HomeworkBank.find params[:id] + rescue ActiveRecord::RecordNotFound + render_404 + end +end diff --git a/app/controllers/homework_common_controller.rb b/app/controllers/homework_common_controller.rb index 1812e7cff..a4f092d31 100644 --- a/app/controllers/homework_common_controller.rb +++ b/app/controllers/homework_common_controller.rb @@ -8,34 +8,50 @@ class HomeworkCommonController < ApplicationController before_filter :find_course, :only => [:index,:new,:create] before_filter :find_homework, :only => [:edit,:update,:alert_anonymous_comment,:start_anonymous_comment,:stop_anonymous_comment,:destroy,:start_evaluation_set, :set_evaluation_attr,:score_rule_set,:alert_forbidden_anonymous_comment,:alert_open_student_works,:open_student_works, - :set_score_open,:alert_score_open_modal,:add_to_homework_bank,:publish_homework] + :set_score_open,:alert_score_open_modal,:add_to_homework_bank,:publish_homework,:setting,:set_public,:homework_setting] before_filter :teacher_of_course, :only => [:new, :create, :edit, :update, :destroy, :start_anonymous_comment, :stop_anonymous_comment, :alert_anonymous_comment, :start_evaluation_set,:set_evaluation_attr,:score_rule_set,:alert_forbidden_anonymous_comment,:alert_open_student_works, :open_student_works,:add_to_homework_bank,:publish_homework] - before_filter :member_of_course, :only => [:index] + before_filter :member_of_course, :only => [:index,:setting] def index #unless params[:page] # update_homework_time(@course.homework_commons) #end - search = "%#{params[:search].to_s.strip.downcase}%" - @new_homework = HomeworkCommon.new - @new_homework.homework_detail_manual = HomeworkDetailManual.new - @new_homework.course = @course + @search = "#{params[:search].to_s.strip.downcase}" if params[:search] + @order = params[:order] @page = params[:page] ? params[:page].to_i + 1 : 0 + @homework_type = params[:homework_type].to_i @is_teacher = User.current.logged? && (User.current.admin? || User.current.allowed_to?(:as_teacher,@course)) - if @is_teacher - #@homeworks = @course.homework_commons.order("created_at desc").limit(10).offset(@page * 10) - @homework_commons = @course.homework_commons.where("name like '%#{search}%'").order("created_at desc") + if @search + @homework_commons = @course.homework_commons.where(:homework_type => @homework_type).where("name like '%#{@search}%'") else - #@homeworks = @course.homework_commons.where("publish_time <= '#{Date.today}'").order("created_at desc").limit(10).offset(@page * 10) - @homework_commons = @course.homework_commons.where("name like '%#{search}%' and publish_time <= '#{Time.now}'").order("created_at desc") + @homework_commons = @course.homework_commons.where(:homework_type => @homework_type) + end + if @order.blank? + if @is_teacher + @homework_commons = @homework_commons.order("created_at desc") + else + @homework_commons = @homework_commons.where("publish_time <= '#{Time.now}'").order("created_at desc") + end + else + case @order + when '1' + @homework_commons = @homework_commons.includes(:homework_detail_manual).where("homework_detail_manuals.comment_status = #{@order} and end_time > '#{Time.now}'").order("homework_commons.created_at desc") + when '3' + @homework_commons = @homework_commons.includes(:homework_detail_manual).where("homework_detail_manuals.comment_status = #{@order} and homework_detail_manuals.evaluation_end > '#{Time.now}'").order("homework_commons.created_at desc") + when '4' + @homework_commons = @homework_commons.includes(:homework_detail_manual).where("(homework_detail_manuals.comment_status = #{@order} and homework_detail_manuals.appeal_time > '#{Time.now}')").order("homework_commons.created_at desc") + when '5' + @homework_commons = @homework_commons.includes(:homework_detail_manual).where("(homework_detail_manuals.comment_status = #{@order} and archive_time > '#{Time.now}')").order("homework_commons.created_at desc") + else + @homework_commons = @homework_commons.includes(:homework_detail_manual).where("homework_detail_manuals.comment_status = #{@order}").order("homework_commons.created_at desc") + end end - #update_homework_time @homework_commons @is_student = User.current.logged? && (User.current.admin? || (User.current.member_of_course?(@course) && !@is_teacher)) @is_new = params[:is_new] - @homeworks = paginateHelper @homework_commons,10 + @homeworks = paginateHelper @homework_commons,15 #设置at已读 ids = @homeworks.inject([]) do |ids, homework| jids = homework.journals_for_messages.map(&:id) @@ -58,33 +74,286 @@ class HomeworkCommonController < ApplicationController #新建作业,在个人作业列表创建作业 def new - render_404 + @homework_type = params[:homework_type].to_i + @homework = HomeworkCommon.new + @ref_answer = HomeworkReferenceAnswer.new + respond_to do |format| + format.html{render :layout => 'base_edu'} + end + end + + # 新建实训作业 + def shixuns + search = params[:search] + @course = Course.find(params[:course]) + @homework = HomeworkCommon.new + @shixuns = Shixun.where(:status => 2).where("name like ?", "%#{search}%") + @shixuns_count = @shixuns.count + @limit = 8 + @is_remote = true + @shixun_pages = Paginator.new @shixuns_count, @limit, params['page'] || 1 + @offset ||= @shixun_pages.offset + @shixuns = paginateHelper @shixuns, @limit + respond_to do |format| + format.js + end end #新建作业,在个人作业列表创建作业 def create - redirect_to user_homeworks_user_path(User.current.id) + if params[:homework_common] || params[:shixun_homework] + homework = HomeworkCommon.new + if params[:shixun_homework] + shixun = Shixun.find(params[:shixun_homework]) + homework.name = shixun.name + homework.description = shixun.description + else + homework.name = params[:homework_common][:name] + homework.description = params[:homework_common][:description] + homework.reference_answer = params[:homework_common][:reference_answer] + homework.save_attachments(params[:attachments]) + render_attachment_warning_if_needed(homework) + end + homework.anonymous_comment = 1 + homework.homework_type = params[:shixun_homework] ? 4 : (params[:homework_type].to_i || 1) + homework.late_penalty = 0 + homework.teacher_priority = 1 + homework.user_id = User.current.id + homework.course_id = params[:course] + + + homework_detail_manual = HomeworkDetailManual.new + homework_detail_manual.te_proportion = 1.0 + homework_detail_manual.ta_proportion = 0 + homework_detail_manual.comment_status = 0 + + homework_detail_manual.evaluation_num = 0 + homework_detail_manual.absence_penalty = 0 + homework.homework_detail_manual = homework_detail_manual + + #编程作业相关属性 + if homework.homework_type == 2 + homework_detail_programing = HomeworkDetailPrograming.new + homework.homework_detail_programing = homework_detail_programing + homework_detail_programing.ta_proportion = 0 + homework_detail_programing.language = params[:language_type].to_i + + sample_inputs = params[:sample][:input] + if Array === sample_inputs + sample_inputs.each_with_index do |val, i| + homework.homework_samples << HomeworkSample.new( + input: val, + output: params[:sample][:output][i] + ) + end + end + + inputs = params[:program][:input] + if Array === inputs + inputs.each_with_index do |val, i| + homework.homework_tests << HomeworkTest.new( + input: val, + output: params[:program][:output][i] + ) + end + end + end + + #分组作业 + if homework.homework_type == 3 + homework_detail_group = HomeworkDetailGroup.new + homework.homework_detail_group = homework_detail_group + homework_detail_group.min_num = params[:min_num].to_i + homework_detail_group.max_num = params[:max_num].to_i + homework_detail_group.base_on_project = 0 + end + + if homework.save + homework_detail_manual.save if homework_detail_manual + homework_detail_programing.save if homework_detail_programing + homework_detail_group.save if homework_detail_group + + if homework.homework_type != 4 && homework_detail_manual.comment_status == 1 + create_works_list homework + elsif homework.homework_type == 4 + HomeworkCommonsShixuns.create(:homework_common_id => homework.id, :shixun_id => shixun.id) + end + + if params[:quotes] && !params[:quotes].blank? + quotes_homework = HomeworkBank.find params[:quotes].to_i + quotes_homework.update_column(:quotes, quotes_homework.quotes+1) + homework.update_attributes(:homework_bank_id => quotes_homework.id) + end + + # if params[:add_to_bank] + # homework_bank = add_to_homework_bank_f homework + # homework_bank.save + # homework.update_attributes(:homework_bank_id => homework_bank.id) + # end + redirect_to setting_homework_common_path(homework, :is_new => 1) + end + end + end + + def setting + @is_new = params[:is_new].to_i if params[:is_new] + @is_empty = @homework.publish_time.nil? + @is_teacher = User.current.logged? && (User.current.admin? || User.current.allowed_to?(:as_teacher,@course)) + respond_to do |format| + format.html{render :layout => 'base_edu'} + end + end + + def homework_setting + @homework.publish_time = params[:homework_publish_time] if params[:homework_publish_time] + @homework.end_time = params[:homework_end_time] if params[:homework_end_time] + @homework.archive_time = params[:homework_archive_time] if params[:homework_archive_time] + if @homework.archive_time < Time.now && @homework_detail_manual.comment_status < 6 + @homework_detail_manual.comment_status = 6 + elsif @homework.archive_time > Time.now && @homework_detail_manual.comment_status == 6 + @homework_detail_manual.comment_status = 5 + end + + if params[:homework_allow_late] == '1' + @homework.allow_late = true + @homework.late_penalty = params[:homework_late_penalty].to_i + else + @homework.allow_late = false + @homework.late_penalty = 0 + end + + anonymous_comment = @homework.anonymous_comment + absence_penalty = @homework_detail_manual.absence_penalty + appeal_penalty = @homework_detail_manual.appeal_penalty + if @homework_detail_manual.comment_status < 3 + if params[:homework_anonymous_comment] + @homework.anonymous_comment = 0 + @homework_detail_manual.evaluation_start = params[:homework_evaluation_start] if params[:homework_evaluation_start] + @homework_detail_manual.evaluation_end = params[:homework_evaluation_end] if params[:homework_evaluation_end] + @homework_detail_manual.evaluation_num = params[:homework_evaluation_num] if params[:homework_evaluation_num] + @homework_detail_manual.absence_penalty = params[:homework_absence_penalty] if params[:homework_absence_penalty] + else + @homework.anonymous_comment = 1 + @homework_detail_manual.evaluation_start = nil + @homework_detail_manual.evaluation_end = nil + @homework_detail_manual.evaluation_num = 0 + @homework_detail_manual.absence_penalty = 0 + end + else + @homework_detail_manual.evaluation_end = params[:homework_evaluation_end] if params[:homework_evaluation_end] + @homework_detail_manual.evaluation_num = params[:homework_evaluation_num] if params[:homework_evaluation_num] + @homework_detail_manual.absence_penalty = params[:homework_absence_penalty] if params[:homework_absence_penalty] + end + if anonymous_comment != @homework.anonymous_comment + @homework_detail_manual.te_proportion = 1 + @homework_detail_manual.ta_proportion = 0 + @homework_detail_programing.ta_proportion = 0 if @homework_detail_programing + end + if @homework_detail_manual.comment_status < 4 + if params[:homework_anonymous_appeal] + @homework.anonymous_appeal = 1 + @homework_detail_manual.appeal_time = params[:homework_appeal_time] if params[:homework_appeal_time] + @homework_detail_manual.appeal_penalty = params[:homework_appeal_penalty] if params[:homework_appeal_penalty] + else + @homework.anonymous_appeal = 0 + @homework_detail_manual.appeal_time = nil + @homework_detail_manual.appeal_penalty = 0 + end + else + @homework_detail_manual.appeal_time = params[:homework_appeal_time] if params[:homework_appeal_time] + @homework_detail_manual.appeal_penalty = params[:homework_appeal_penalty] if params[:homework_appeal_penalty] + end + if absence_penalty != @homework_detail_manual.absence_penalty && @homework_detail_manual.comment_status >= 4 + all_dis_eva = StudentWorksEvaluationDistribution.where(:student_work_id => @homework.student_works.map(&:id)) + has_sw_count = all_dis_eva.select("distinct user_id").count + anon_count = all_dis_eva.count / has_sw_count + @homework.student_works.where("work_status != 0").each do |student_work| + absence_penalty_count = student_work.user.student_works_evaluation_distributions.where(:student_work_id => @homework.student_works.map(&:id)).count - student_work.user.student_works_scores.where(:student_work_id => @homework.student_works.map(&:id), :reviewer_role => 3).count + student_work.absence_penalty = absence_penalty_count > 0 ? absence_penalty_count * @homework_detail_manual.absence_penalty : 0 + student_work.save + end + end + if appeal_penalty != @homework_detail_manual.appeal_penalty && @homework_detail_manual.comment_status >= 4 + @homework.student_works.each do |student_work| + appeal_penalty_count = student_work.user.student_works_scores.where(:student_work_id => @homework.student_works.map(&:id), :appeal_status => 3).count + student_work.appeal_penalty = appeal_penalty_count > 0 ? appeal_penalty_count * @homework_detail_manual.absence_penalty : 0 + student_work.save + end + end + + if params[:homework_ta_mode] && @homework_detail_manual.ta_mode.to_i != params[:homework_ta_mode].to_i + @homework_detail_manual.ta_mode = params[:ta_mode].to_i + @homework_detail_manual.save + if @homework_detail_manual.ta_mode == 1 + @homework.student_works.where("work_status != 0").each do |student_work| + ts_score = StudentWorksScore.find_by_sql("SELECT AVG(score) AS score FROM (SELECT * FROM (SELECT * FROM student_works_scores WHERE student_work_id = #{student_work.id} AND reviewer_role = 2 AND score IS NOT NULL ORDER BY created_at DESC) AS t GROUP BY user_id) AS a") + student_work.teaching_asistant_score = ts_score.first.score.nil? ? nil : ts_score.first.score.try(:round, 2).to_f + student_work.save + end + else + @homework.student_works.where("work_status != 0").each do |student_work| + ts_score = StudentWorksScore.where("student_work_id = #{student_work.id} AND reviewer_role = 2 AND score IS NOT NULL").order("created_at DESC") + student_work.teaching_asistant_score = ts_score.first.nil? ? nil : ts_score.first.score + student_work.save + end + end + end + + if params[:homework_final_mode] && params[:homework_final_mode].to_i != @homework_detail_manual.final_mode + @homework_detail_manual.final_mode = params[:homework_final_mode].to_i + if params[:homework_final_mode].to_i == 0 + @homework_detail_manual.te_proportion = params[:te_proportion] + @homework_detail_manual.ta_proportion = params[:ta_proportion] + @homework_detail_programing.ta_proportion = params[:sy_proportion] if @homework_detail_programing + @homework_detail_programing.save if @homework_detail_programing + end + @homework_detail_manual.save if @homework_detail_manual + @homework.save + @homework = HomeworkCommon.find @homework.id + @homework.student_works.each do |student_work| + set_final_score @homework,student_work + student_work.save + end + elsif params[:homework_final_mode] && @homework_detail_manual.final_mode == 0 + if (params[:te_proportion] && params[:te_proportion].to_s != @homework_detail_manual.te_proportion.to_s) || (params[:ta_proportion] && params[:ta_proportion].to_s != @homework_detail_manual.ta_proportion.to_s) || (@homework_detail_programing && @homework_detail_programing.ta_proportion.to_s != params[:sy_proportion].to_s) + @homework_detail_manual.te_proportion = params[:te_proportion] + @homework_detail_manual.ta_proportion = params[:ta_proportion] + @homework_detail_programing.ta_proportion = params[:sy_proportion] if @homework_detail_programing + + @homework_detail_manual.save if @homework_detail_manual + @homework_detail_programing.save if @homework_detail_programing + @homework.save + @homework = HomeworkCommon.find @homework.id + @homework.student_works.each do |student_work| + set_final_score @homework,student_work + student_work.save + end + end + end + + if @homework.homework_type == 4 + @homework.score_open = params[:homework_score_open] ? 1 : 0 + else + @homework.work_public = params[:homework_work_public] ? 1 : 0 + @homework.score_open = params[:homework_score_open] ? 1 : 0 + @homework.answer_public = params[:homework_answer_public] ? 1 : 0 + end + @homework.save + @homework_detail_manual.save + redirect_to setting_homework_common_path(@homework) end def edit @user = User.current - @hw_status = params[:hw_status].to_i - @is_manage = params[:is_manage] - if @hw_status != 1 - @left_nav_type = 3 - respond_to do |format| - format.html{render :layout => 'base_courses'} - end - else - respond_to do |format| - format.html{render :layout => 'base_course_community'} - end + @homework_type = @homework.homework_type + respond_to do |format| + format.html{render :layout => 'base_edu'} end end def update if params[:homework_common] - is_update = @homework.name != params[:homework_common][:name] || @homework.description != params[:homework_common][:description] || params[:homework_type].to_i != @homework.homework_type + is_update = @homework.name != params[:homework_common][:name] || @homework.description != params[:homework_common][:description] || @homework.reference_answer != params[:homework_common][:reference_answer] if params[:homework_type].to_i == 2 is_update = is_update || params[:language_type] != @homework.homework_detail_programing.language if !is_update && params[:sample] && params[:program] @@ -98,92 +367,8 @@ class HomeworkCommonController < ApplicationController @homework.name = params[:homework_common][:name] @homework.description = params[:homework_common][:description] - homework_detail_manual = @homework.homework_detail_manual || HomeworkDetailManual.new - if params[:homework_common][:end_time] != "" - if params[:homework_common][:publish_time] == "" - @homework.publish_time = Time.now - else - @homework.publish_time = params[:homework_common][:publish_time] - end - param_end_time = Time.parse(params[:homework_common][:end_time]).to_s - homework_end_time = @homework.end_time ? @homework.end_time.to_s : '' - if homework_end_time != param_end_time - if homework_end_time > param_end_time - @homework.student_works.where("work_status = 1").each do |st| - if param_end_time < st.commit_time - st.late_penalty = @homework.late_penalty - st.work_status = 2 - st.save - #更新CourseHomeworkStatistics中学生的迟交作品数 - course_statistics = CourseHomeworkStatistics.find_by_course_id_and_user_id(@homework.course_id, st.user_id) - course_statistics.update_attribute('late_commit_work_num', course_statistics.late_commit_work_num + 1) if course_statistics - end - end - else - @homework.student_works.where("work_status = 2").each do |st| - if param_end_time >= Time.parse(st.commit_time.to_s).strftime("%Y-%m-%d") - st.late_penalty = 0 - st.work_status = 1 - st.save - #更新CourseHomeworkStatistics中学生的迟交作品数 - course_statistics = CourseHomeworkStatistics.find_by_course_id_and_user_id(@homework.course_id, st.user_id) - course_statistics.update_attribute('late_commit_work_num', (course_statistics.late_commit_work_num - 1) < 0 ? 0 : (course_statistics.late_commit_work_num - 1)) if course_statistics - end - end - end - end - @homework.end_time = params[:homework_common][:end_time] || Time.now - - status = false - if @homework.publish_time > Time.now && homework_detail_manual.comment_status == 1 - homework_detail_manual.comment_status = 0 - @homework.student_works.destroy_all - #更新CourseHomeworkStatistics中每个学生的未交作品数 - @homework.course.student.each do |student| - course_statistics = CourseHomeworkStatistics.find_by_course_id_and_user_id(@homework.course_id, student.student_id) - course_statistics.update_attribute('un_commit_work_num', (course_statistics.un_commit_work_num - 1) < 0 ? 0 : (course_statistics.un_commit_work_num - 1)) if course_statistics - end - elsif @homework.publish_time <= Time.now && homework_detail_manual.comment_status == 0 - homework_detail_manual.comment_status = 1 - create_works_list @homework if params[:homework_type].to_i != 3 - status = true - #更新CourseHomeworkStatistics中每个学生的未交作品数 - @homework.course.student.each do |student| - course_statistics = CourseHomeworkStatistics.find_by_course_id_and_user_id(@homework.course_id, student.student_id) - course_statistics.update_attribute('un_commit_work_num', course_statistics.un_commit_work_num + 1) if course_statistics - end - end - - eval_start = homework_detail_manual.evaluation_start - if eval_start.nil? || (Time.parse(eval_start.to_s) <= @homework.end_time && homework_detail_manual.comment_status <= 1) - homework_detail_manual.evaluation_start = (@homework.end_time + 7*24*60*60).strftime("%Y-%m-%d") - homework_detail_manual.evaluation_end = homework_detail_manual.evaluation_start + 7 - end - end - - if params[:homework_type] && params[:homework_type].to_i != @homework.homework_type - if @homework.homework_type == 2 - @homework.homework_detail_programing.destroy if @homework.homework_detail_programing - @homework.homework_tests.destroy_all - elsif @homework.homework_type == 3 - @homework.homework_detail_group.destroy if @homework.homework_detail_group - create_works_list @homework if homework_detail_manual.comment_status > 0 && @homework.student_works.empty? - end - if params[:homework_type].to_i == 3 - @homework.student_works.destroy_all - end - @homework.homework_type = params[:homework_type].to_i - end - anonymous = params[:homework_common][:anonymous_comment] ? params[:homework_common][:anonymous_comment].to_i : 1 - if anonymous != @homework.anonymous_comment - if anonymous == 1 - homework_detail_manual.ta_proportion = @homework.homework_type == 2 ? 0.4 : 1.0 - else - homework_detail_manual.ta_proportion = @homework.homework_type == 2 ? 0.3 : 0.6 - end - end - @homework.save_attachments(params[:attachments]) + @homework.reference_answer = params[:homework_common][:reference_answer] render_attachment_warning_if_needed(@homework) #编程作业相关属性 @@ -191,13 +376,6 @@ class HomeworkCommonController < ApplicationController @homework.homework_detail_programing ||= HomeworkDetailPrograming.new @homework_detail_programing = @homework.homework_detail_programing @homework_detail_programing.language = params[:language_type].to_i if params[:language_type] - if anonymous != @homework.anonymous_comment - if anonymous == 1 - @homework_detail_programing.ta_proportion = 0.6 - else - @homework_detail_programing.ta_proportion = 0.5 - end - end @homework.homework_samples.delete_all if params[:sample] sample_inputs = params[:sample][:input] if params[:sample] @@ -231,15 +409,7 @@ class HomeworkCommonController < ApplicationController @homework_detail_group.base_on_project = params[:base_on_project] ? 1 : 0 end - if anonymous != @homework.anonymous_comment - @homework.student_works.where("work_status != 0").each do |student_work| - student_work.save - end - end - - @homework.anonymous_comment = params[:homework_common][:anonymous_comment] ? params[:homework_common][:anonymous_comment].to_i : 1 if @homework.save - homework_detail_manual.save if homework_detail_manual @homework_detail_programing.save if @homework_detail_programing @homework_detail_group.save if @homework_detail_group @@ -247,20 +417,7 @@ class HomeworkCommonController < ApplicationController # create_works_list @homework # end - @hw_status = params[:hw_status].to_i - if params[:is_manage] == "1" - redirect_to user_manage_homeworks_user_path(User.current.id) - elsif params[:is_manage] == "2" - redirect_to user_receive_homeworks_user_path(User.current.id) - elsif @hw_status == 1 - redirect_to user_course_community_path(User.current.id) - elsif @hw_status == 2 - redirect_to course_path(@course.id) - elsif @hw_status == 5 - redirect_to student_work_index_url(:homework => @homework.id) - else - redirect_to homework_common_index_path(:course => @course.id) - end + redirect_to student_work_index_url(:homework => @homework.id) end end end @@ -299,14 +456,7 @@ class HomeworkCommonController < ApplicationController respond_to do |format| format.html { - @hw_status = params[:hw_status].to_i - if @hw_status == 1 - redirect_to user_path(User.current.id) - elsif @hw_status == 2 - redirect_to course_path(@course.id) - else - redirect_to homework_common_index_path(:course => @course.id) - end + redirect_to homework_common_index_path(:course => @course.id, :homework_type => @homework.homework_type) } end end @@ -325,24 +475,25 @@ class HomeworkCommonController < ApplicationController end homework_bank = add_to_homework_bank_f @homework homework_bank.save + if @homework.homework_type == 4 + HomeworkBankShixun.create(:homework_bank_id => homework_bank.id, :shixun_id => @homework.homework_commons_shixuns.shixun_id) + end @homework.update_attributes(:homework_bank_id => homework_bank.id) elsif params[:type].to_i == 2 homework_bank = HomeworkBank.where(:id => @homework.homework_bank_id).first if homework_bank - homework_bank.update_attributes(:name => @homework.name, :description => @homework.description, :homework_type => @homework.homework_type) + homework_bank.update_attributes(:name => @homework.name, :description => @homework.description, :homework_type => @homework.homework_type, :reference_answer => @homework.reference_answer) if @homework.homework_type == 2 && @homework.homework_detail_programing homework_bank.update_attributes(:language => @homework.homework_detail_programing.language) homework_bank.homework_bank_tests.destroy_all @homework.homework_tests.each_with_index do |homework_test| homework_bank.homework_bank_tests << HomeworkBankTest.new( - test_type: 1, input: homework_test.input, output: homework_test.output ) end @homework.homework_samples.each_with_index do |homework_test| - homework_bank.homework_bank_tests << HomeworkBankTest.new( - test_type: 0, + homework_bank.homework_bank_samples << HomeworkBankSample.new( input: homework_test.input, output: homework_test.output ) @@ -355,9 +506,14 @@ class HomeworkCommonController < ApplicationController if @homework.is_update @homework.update_attributes(:is_update => 0) end - @user_activity_id = params[:user_activity_id].to_i - @hw_status = params[:hw_status].to_i - @is_teacher = User.current.admin? || User.current.allowed_to?(:as_teacher, @course) + end + + def set_public + @homework.update_attributes(:is_public => true) + respond_to do |format| + format.html{ redirect_to student_work_index_path(:homework => @homework.id) } + format.js + end end def publish_homework diff --git a/app/controllers/managements_controller.rb b/app/controllers/managements_controller.rb new file mode 100644 index 000000000..400fad766 --- /dev/null +++ b/app/controllers/managements_controller.rb @@ -0,0 +1,393 @@ +# encoding: utf-8 +class ManagementsController < ApplicationController + before_filter :require_admin + layout 'base_management' + include ManagementsHelper + include SortHelper + include UsersHelper + include ApplicationHelper + + # 0 全部;1 活动的; 2 已注册; 3 锁定 + def users + status = params[:user_status].nil? ? 0 : params[:user_status].to_i + @us_order = params[:us_order].blank? ? "desc" : params[:us_order] # 排序 + @order_key = params[:order_key].blank? ? "created_on" : params[:order_key] # 排序关键字 + condition = (params[:research_condition].nil? || params[:research_condition] == "name") ? "concat(lastname, firstname)" : params[:research_condition] + if 0 == status + if params[:research_condition] == "phone" && params[:research_contents].blank? + @users = User.order("#{@order_key} #{@us_order}").all + else + @users = User.where("#{condition} like '%#{params[:research_contents]}%'").order("#{@order_key} #{@us_order}").all + end + else + if params[:research_condition] == "phone" && params[:research_contents].blank? + @users = User.where(:status => status).order("#{@order_key} #{@us_order}").all + else + @users = User.where("status = #{status} and #{condition} like '%#{params[:research_contents]}%'").order("#{@order_key} #{@us_order}").all + end + end + + @users_count = @users.count + @limit = 20 + @is_remote = true + @users_pages = Paginator.new @users_count, @limit, params['page'] || 1 + @offset ||= @users_pages.offset + @users = paginateHelper @users, @limit + + respond_to do |format| + format.js + format.html + end + end + + def shixuns + @menu_type = 3 + sx_status = params[:status].blank? ? [0, 1, 2, 3] : params[:status].to_i # 搜索实训的状态 + keyword = params[:keyword].blank? ? "u_name" : params[:keyword] # 根据姓名/实训名搜索 + search = params[:search] # 搜索的字 + @sx_order = params[:sx_order].blank? ? "desc" : params[:sx_order] # 排序 + if "u_name" == keyword + # 如果用户搜索为空,不用遍历user表,直接查找所有实训, 有搜索时才查找user + if search.blank? + @shixuns = Shixun.where(:status => sx_status).order("created_at #{@sx_order}") + else + user_id = User.where("concat(lastname, firstname) like '%#{search}%'") + @shixuns = Shixun.where(:user_id => user_id, :status => sx_status).order("created_at #{@sx_order}") + end + else + @shixuns = Shixun.where("name like '%#{search}%'").where(:status => sx_status).order("created_at #{@sx_order}") + end + @edit_sx_num = Shixun.where(:status => 0).count + @audit_sx_num = Shixun.where(:status => 1).count + @publish_sx_num =Shixun.where(:status => 2).count + @close_sx_num = Shixun.where(:status => 3).count + + @shixuns_count = @shixuns.count + limit = 20 + @shixuns_pages = Paginator.new @shixuns_count, limit, params['page'] || 1 + @offset ||= @shixuns_pages.offset + @shixuns = paginateHelper @shixuns, limit + respond_to do |format| + format.js + format.html + end + end + + # 已发布的实训 + def publish_shixuns + @menu_type = 3 + @sx_order = params[:sx_order].blank? ? "desc" : params[:sx_order] # 排序 + search = params[:search] # 搜索字 + keyword = params[:keyword].blank? ? "u_name" : params[:keyword] # 根据姓名/实训名搜索 + close = params[:close] # 关闭实训,参数是实训的Id + unless close.blank? + Shixun.find(close).update_attribute(:status, 3) + end + if "u_name" == keyword + # 如果用户搜索为空,不用遍历user表,直接查找所有实训, 有搜索时才查找user + if search.blank? + @shixuns = Shixun.where(:status => 2).order("created_at #{@sx_order}") + else + user_id = User.where("concat(lastname, firstname) like '%#{search}%'") + @shixuns = Shixun.where(:user_id => user_id, :status => 2).order("created_at #{@sx_order}") + end + else + @shixuns = Shixun.where("name like '%#{search}%'").where(:status => 2).order("created_at #{@sx_order}") + end + @shixuns_count = @shixuns.count + limit = 20 + @shixuns_pages = Paginator.new @shixuns_count, limit, params['page'] || 1 + @offset ||= @shixuns_pages.offset + @shixuns = paginateHelper @shixuns, limit + + respond_to do |format| + format.js + format.html + end + end + + # 已关闭的实训 + def close_shixuns + @menu_type = 3 + @sx_order = params[:sx_order].blank? ? "desc" : params[:sx_order] # 排序 + search = params[:search] # 搜索字 + keyword = params[:keyword].blank? ? "u_name" : params[:keyword] # 根据姓名/实训名搜索 + reopen = params[:reopen] # 从新开启实训,参数是实训的Id + + unless reopen.blank? + Shixun.find(reopen).update_attribute(:status, 2) + end + if "u_name" == keyword + # 如果用户搜索为空,不用遍历user表,直接查找所有实训, 有搜索时才查找user + if search.blank? + @shixuns = Shixun.where(:status => 3).order("updated_at #{@sx_order}") + else + user_id = User.where("concat(lastname, firstname) like '%#{search}%'") + @shixuns = Shixun.where(:user_id => user_id, :status => 3).order("updated_at #{@sx_order}") + end + else + @shixuns = Shixun.where("name like '%#{search}%'").where(:status => 3).order("updated_at #{@sx_order}") + end + @shixuns_count = @shixuns.count + limit = 20 + @shixuns_pages = Paginator.new @shixuns_count, limit, params['page'] || 1 + @offset ||= @shixuns_pages.offset + @shixuns = paginateHelper @shixuns, limit + + respond_to do |format| + format.js + format.html + end + end + + def users_trial + @menu_type = 6 + @users = User.where(:status => 1).order("created_on desc").all + @users_count = @users.count + @limit = 20 + @is_remote = true + @users_pages = Paginator.new @users_count, @limit, params['page'] || 1 + @offset ||= @users_pages.offset + @users = paginateHelper @users, @limit + + end + + def search_user + +=begin + auth = ApplyUserAuthentication.where(:status => params[:authentication]) + auth_id = auth.blank? ? User.where(:status => 1).id : "(" + auth.map{|a| a.user_id }.join(",") + ")" +=end + + if params[:member_ids] && params[:trial_whether] == "trial_agree" + params[:member_ids].each do |member| + aUser = ApplyAction.where(:user_id => member, :container_type => "TrialAuthorization") + if aUser.blank? + ApplyAction.create(:user_id => member, :container_type => "TrialAuthorization", :status => 1) + else + aUser.update_all(:status => 1) + end + end + elsif params[:member_ids] && params[:trial_whether] == "trial_cancel" + ApplyAction.where(:user_id => params[:member_ids], :container_type => "TrialAuthorization").update_all(:status => 2) + end + + if params[:member_ids] && (params[:occupation] == "occupation_agree" || params[:realname] == "realname_agree") + User.where(:id => params[:member_ids]).update_all(:authentication => true) + elsif params[:member_ids] && (params[:occupation] == "occupation_agree" || params[:realname] == "realname_cancel") + User.where(:id => params[:member_ids]).update_all(:authentication => false) + end + + if params[:trial] == "-1" + apply = ApplyAction.where(:container_type => "TrialAuthorization") + apply_id = apply.blank? ? -1 : "(" + apply.map{|a| a.user_id}.join(",") + ")" + apply_user_id = User.where("id not in #{apply_id} and status = 1").all + apply_user_id = apply_user_id.blank? ? [-1] : apply_user_id.map{|a| a.id}.split(",")[0] + elsif params[:trial] == "-2" + apply_user_id = User.where(:status => 1).all + apply_user_id = apply_user_id.blank? ? [-1] : apply_user_id.map{|a| a.id}.split(",")[0] + else + apply = ApplyAction.where(:status => params[:trial]) + apply_user_id = apply.blank? ? [-1] : apply.map{|a| a.user_id}.split(",")[0] + end + + if params[:school] == "" + s_user_id = User.where(:status => 1).all + s_user_id = s_user_id.blank? ? [-1] : s_user_id.map{|s| s.id}.split(",")[0] + else + school = School.where("name like '%#{params[:school]}%'") + school_id = school.blank? ? -1 : school.map{|s| s.id }.split(",")[0] + usr = UserExtensions.where(:school_id => school_id) + s_user_id = usr.blank? ? [-1] : usr.map{|u| u.user_id}.split(",")[0] + end + + if params[:department] == "" + d_user_id = User.where(:status => 1).all + d_user_id = d_user_id.blank? ? [-1] : d_user_id.map{|d| d.id}.split(",")[0] + else + department = Department.where("name like '%#{params[:department]}%'").all + dep_id = department.blank? ? -1 : department.map{|d| d.id}.split(",") + usr = UserExtensions.where(:department_id => dep_id) + d_user_id = usr.blank? ? [-1] : usr.map{|u| u.user_id}.split(",")[0] + end + + user_id = s_user_id & d_user_id & apply_user_id + + if params[:research_condition] == "name" + @users = User.where(:id => user_id).where("concat(lastname, firstname) like '%#{params[:research_contents]}%'").order("created_on desc") + elsif params[:research_condition] == "email" + @users = User.where(:id => user_id).where("mail like '%#{params[:research_contents]}%'").order("created_on desc") + elsif params[:research_condition] == "phone" + if params[:research_contents].blank? + @users = User.where(:id => user_id).order("created_on desc") + else + @users = User.where(:id => user_id).where("phone like '%#{params[:research_contents]}%'").order("created_on desc") + end + + end + + @users_count = @users.count + @limit = 20 + @is_remote = true + @users_pages = Paginator.new @users_count, @limit, params['page'] || 1 + @offset ||= @users_pages.offset + @users = paginateHelper @users, @limit + + respond_to do |format| + format.js + end + end + + def update_webssh + webssh = params[:status] == "true" ? true : false + @shixuns = Shixun.find(params[:shixun_id]) + @shixuns.update_column(:webssh, webssh) + respond_to do |format| + format.js + end + end + + def affirm_cancel_auth + user_id = params[:users] + end + + + def trial_authorization + @menu_type = 9 + search = params[:search] + @status = trial_authorization_status(params[:status]) + # @status = (params[:status].blank? || params[:status] == "0") ? 0 : [1,2] + if search.blank? + @authorizations = ApplyAction.where(:container_type => "TrialAuthorization", :status => @status).includes(:user) + else + user_id = User.find_by_sql("select id from users where concat(lastname,firstname) like '%#{search}%'") + @authorizations = ApplyAction.where(:container_type => "TrialAuthorization", :status => @status, :user_id => user_id).includes(:user) + end + + @autu_count = @authorizations.count + @limit = 15 + @is_remote = true + @autu_pages = Paginator.new @autu_count, @limit, params['page'] || 1 + @offset ||= @autu_pages.offset + @authorizations = paginateHelper @authorizations, @limit + + end + + # 批量授权 + def batch_authorization + + end + + # params[:type] 1:拒绝 0:同意 + # authentication 会有一个初始值,不同的值代表不同的权限 + # REDO: 后面权限改了后,一并要改 + def trial_authorization_operation + apply_action = ApplyAction.find(params[:apply_id]) + type = params[:type] + search = params[:search] + if type == "0" + authentication_user = AuthenticationsUsers.where(:user_id => apply_action.user_id).first + if authentication_user.blank? + AuthenticationsUsers.create(:user_id => apply_action.user_id, :authentication_id => 1) + end + end + apply_action.update_attributes(:status => (params[:type] == "1" ? 2 : 1), :reason => params[:reject_reason], :dealer_id => User.current.id) + user_id = User.find_by_sql("select id from users where concat(lastname,firstname) like '%#{search}%'") + @authorizations = ApplyAction.where(:container_type => "TrialAuthorization", :status => 0, :user_id => user_id).includes(:user) + @autu_count = @authorizations.count + @limit = 15 + @is_remote = true + @autu_pages = Paginator.new @autu_count, @limit, params['page'] || 1 + @offset ||= @autu_pages.offset + @authorizations = paginateHelper @authorizations, @limit + respond_to do |format| + format.js + end + end + + def index + + end + + # copy from admin + def identity_authentication + @menu_type = 9 + @type = trial_authorization_status(params[:type]) + type = params[:type] || 0 # 存在type 就用type 没有就为 0 + user_id = User.find_by_sql("select id from users where concat(lastname,firstname) like '%#{params[:name]}%'") + @unapproved_user = ApplyUserAuthentication.where(:status => @type, :user_id => user_id).order("updated_at desc") + respond_to do |format| + format.html + format.js + end + end + + # 拒绝身份认证 + # copy from admin + def reject_authentication + apply_user = ApplyUserAuthentication.find(params[:apply_id]) + reason = apply_user.update_attributes(:status => 2, :remarks => params[:reject_reason]) + render :json => {success: reason} + end + + # 统一身份认证 + # copy from admin + def agree_authentication + apply_user = ApplyUserAuthentication.find(params[:apply_id]) + user = User.find(apply_user.user_id) + apply_user.update_attribute(:status, 1) + user.update_attribute(:authentication, true) + @unapproved_user = ApplyUserAuthentication.where(:status => 0).order("updated_at desc") + respond_to do |format| + format.js + end + end + + def shixun_authorization + @type = trial_authorization_status params[:type] + @authorizations = ApplyAction.where(:container_type => "ApplyShixun", :status => @type).order("created_at desc") + search = params[:search] + unless search.blank? + @authorizations = @authorizations.where(:container_id => Shixun.where(:id => @authorizations.map(&:container_id)).where("name like '%#{search}%'").map(&:id)).order("created_at desc") + end + + @authorizations_count = @authorizations.count + @limit = 15 + @is_remote = true + @authorizations_pages = Paginator.new @authorizations_count, @limit, params['page'] || 1 + @offset ||= @authorizations_pages.offset + @authorizations = paginateHelper @authorizations, @limit + respond_to do |format| + format.js + format.html + end + end + + def deal_shixun_authorization + apply_action = ApplyAction.find(params[:apply_id]) + type = params[:type].to_i + shixun = Shixun.find apply_action.container_id + if type == 0 + shixun.update_column('status', 0) + apply_action.update_attributes(:status => 2, :reason => params[:reject_reason], :dealer_id => User.current.id) + notes = "您所在团队提交的项目实训发布申请:#{shixun.name},审核未通过。
原因:#{params[:reject_reason]}" + shixun.shixun_members.each do |member| + JournalsForMessage.create(:jour_id => member.user_id, :jour_type => 'Principal', :user_id => User.current.id, :notes => notes, :private => 1, :reply_id => 0) + end + else + shixun.update_column('status', 2) + apply_action.update_attributes(:status => 1, :dealer_id => User.current.id) + shixun_modify_status_without_publish shixun, 1 + end + @authorizations = ApplyAction.where(:container_type => "ApplyShixun", :status => 0) + @authorizations_count = @authorizations.count + @limit = 15 + @is_remote = true + @authorizations_pages = Paginator.new @authorizations_count, @limit, params['page'] || 1 + @offset ||= @authorizations_pages.offset + @authorizations = paginateHelper @authorizations, @limit + respond_to do |format| + format.js + end + end +end diff --git a/app/controllers/members_controller.rb b/app/controllers/members_controller.rb index dbd53cd63..156a6653b 100644 --- a/app/controllers/members_controller.rb +++ b/app/controllers/members_controller.rb @@ -251,7 +251,6 @@ class MembersController < ApplicationController member = @course.members.where(:user_id => user_id).first member_role = MemberRole.new(:role_id => params[:membership][:role_ids][0], :is_current => 0) member.member_roles << member_role - member_role.save end role_ids = params[:membership][:role_ids] #role = Role.find(params[:membership][:role_ids]) @@ -286,9 +285,11 @@ class MembersController < ApplicationController end @course.members << members @course.course_infos << course_info - - @roles = Role.givable.all[3..5] - members = @course.member_principals.includes(:roles, :principal).all.sort + #@teacher_count = searchTeacherAndAssistant(@course).count + #@student_count = @course.student.count + #@no_group_count = @course.members.where("course_group_id = 0").select{|m| m.roles.to_s.include?("Student")}.count + #@roles = Role.givable.all[3..5] + #members = @course.member_principals.includes(:roles, :principal).all.sort else @create_member_error_messages = l(:label_user_role_null) end @@ -461,6 +462,7 @@ class MembersController < ApplicationController else @member.member_roles.where("role_id = 10").destroy_all joined = StudentsForCourse.where('student_id = ? and course_id = ?', @member.user_id,@course.id).destroy_all + @member.update_attributes(:course_group_id => 0) if params[:group_id] == '0' @members = @course.members.select{|m| m.roles.to_s.include?("Student")} else @@ -469,8 +471,8 @@ class MembersController < ApplicationController @member.member_roles.where("role_id = 7 or role_id = 9").first.update_attributes(:is_current => 1) end end - @teachers = searchTeacherAndAssistant(@course) - @all_student_count = @course.student.count + @teacher_count = searchTeacherAndAssistant(@course).count + @student_count = @course.student.count @no_group_count = @course.members.where("course_group_id = 0").select{|m| m.roles.to_s.include?("Student")}.count # user_admin = CourseInfos.where("user_id = ? and course_id = ?", @member.user_id, @course.id) # if user_admin.size > 0 diff --git a/app/controllers/my_controller.rb b/app/controllers/my_controller.rb index 08006001e..12c53f2f9 100644 --- a/app/controllers/my_controller.rb +++ b/app/controllers/my_controller.rb @@ -18,9 +18,8 @@ class MyController < ApplicationController include ApplicationHelper layout "users_base" - # edit + skip_before_filter :check_authentication, :only => [:account] before_filter :auth_login1, :only => [:account] - # before_filter :require_login, except: [:change_mail_notification] helper :issues @@ -148,18 +147,35 @@ class MyController < ApplicationController end @user = User.current - # 基本资料不完善 @force为false, 完善 @force为true - @force = false - if params[:tip] - @force = true + # 认证 + ue = @user.user_extensions + @trail_authentication = ApplyAction.where(:user_id => User.current.id).order("created_at desc").first + @authentication = @user.authentication + if ue.identity.nil? + @require_auth = 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 + if @trail_authentication.blank? || (@trail_authentication.status == 2 && (@trail_authentication.updated_at.to_i + 24*60*60) < Time.now.to_i) + @require_trail_auth = true end end + # @require_auth = true + # + # # 基本资料不完善 @force为false, 完善 @force为true + # @force = false + # # @authentication = @user.authentication + # @trail_authentication = AuthenticationsUsers.where(:user_id => User.current.id).first + # if params[:tip] + # @force = true + # else + # user = UserExtensions.where(:user_id => User.current.id).first + # if user.identity.nil? || user.school_id.nil? || User.current.lastname.nil? + # @force = false + # else + # @force = @trail_authentication.blank? ? false : true + # end + # end + # # 用户认证 + # @auth = @user.authentication ? false : true @s_message = AppliedMessage.where(:status => 3, :user_id => User.current.id, :viewed => 0, :applied_type => 'ApplyAddSchools').first @d_message = AppliedMessage.where(:status => 3, :user_id => User.current.id, :viewed => 0, :applied_type => 'ApplyAddDepartment').first @@ -176,8 +192,10 @@ class MyController < ApplicationController #changed_login = (@user.login != params[:login]) #changed_mail = (@user.mail != params[:user][:mail]) #@user.safe_attributes = params[:user] + @user.nickname = params[:nickname] @user.lastname = params[:lastname] @user.firstname = "" + @user.show_realname = params[:show_realname] ? 0 : 1 @user.pref.attributes = params[:pref] @user.pref[:no_self_notified] = (params[:no_self_notified] == '1') #@user.login = params[:login].strip @@ -196,6 +214,7 @@ class MyController < ApplicationController # @se.occupation = params[:occupation] # end @se.school_id = params[:occupation] + @se.department_id = params[:department_id] @se.gender = params[:sex] @se.location = params[:province] if params[:province] @se.location_city = params[:city] if params[:city] @@ -214,6 +233,7 @@ class MyController < ApplicationController @se.brief_introduction = params[:brief_introduction] if @user.save && @se.save + reward_grade(@user, @user.id, 'Account', 500) # 修改邮箱的时候同步修改到gitlab # if changed_mail || changed_login diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index 98fa5f812..f4b8c6c91 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -1,39 +1,101 @@ # encoding: utf-8 class MyshixunsController < ApplicationController layout 'base_myshixun' - skip_before_filter :verify_authenticity_token, :only => [:training_task_status] - before_filter :require_login, :except => [:training_task_status] - before_filter :find_myshixun, :only => [:show, :myshixun_reset] + skip_before_filter :verify_authenticity_token, :only => [:training_task_status, :close_webssh] + before_filter :require_login, :except => [:training_task_status, :close_webssh] + before_filter :check_authentication, :except => [:training_task_status, :close_webssh] + before_filter :find_myshixun, :only => [:show, :myshixun_reset, :open_webssh] + include ApplicationHelper + # 将代码重置到开启状态 + # 方法:使用文件更新,非Git重置 + def code_reset + + end + + def code_reset_success + + end + + # 连接webssh + def open_webssh + username = Redmine::Configuration['webssh_username'] + password = Redmine::Configuration['webssh_password'] + begin + jenkins_shixuns = Redmine::Configuration['jenkins_shixuns'] + uri = URI("#{jenkins_shixuns}/jenkins-exec/webssh/getConnectInfo") + user_id = User.current.id + params = {gameID:@myshixun.id} + res = uri_exec uri, params + if res && res['code'].to_i != 0 + raise("实训云平台繁忙(繁忙等级:92)") + end + render :json => {:host => res['address'], :port => res['port'], :username => username, :password => password, :game_id => @myshixun.id} + rescue Exception => e + logger.error(e) + render :json => {:error => e.try(:message)} + # @message = e.try(:message) + end + end + + # 断开webssh连接 + def close_webssh + username = Redmine::Configuration['webssh_username'] + password = Redmine::Configuration['webssh_password'] + begin + jenkins_shixuns = Redmine::Configuration['jenkins_shixuns'] + uri = URI("#{jenkins_shixuns}/jenkins-exec/webssh/deleteSSH") + user_id = User.current.id + params = {gameID:@_params[:id]} # @_params[:id] 是webssh传过来的gameId + res = uri_exec uri, params + if res && res['code'].to_i != 0 + raise("实训云平台繁忙(繁忙等级:93)") + end + render :jsonp => {:host => res['address'], :port => res['port'], :username => username, :password => password} + rescue Exception => e + logger.error(e) + @message = e.try(:message) + end + end + + # 实训重置只更新脚本 def myshixun_reset ActiveRecord::Base.transaction do begin + g = Gitlab.client jenkins_shixuns = Redmine::Configuration['jenkins_shixuns'] shixun = @myshixun.shixun myshixun_job = Base64.encode64("myshixun_#{@myshixun.id}") + StudentWork.where(:myshixun_id => @myshixun.id).update_all(:myshixun_id => nil, :work_status => 0) @myshixun.destroy myshixun_member = @myshixun repository = @myshixun.repository repository.destroy - g = Gitlab.client g_project = g.project(@myshixun.gpid) unless g_project.id.nil? git_rep = g.delete_project(@myshixun.gpid) logger.info("### delete repository result is #{git_rep}") - params = {:jobName => "#{myshixun_job}"} if git_rep != true - raise("版本库删除异常") + raise("实训云平台繁忙(繁忙等级:87)") end end - uri = URI("#{jenkins_shixuns}/jenkins-exec/game/deleteJob") - res = uri_exec uri, params + # job的删除放异步里面处理 + # params = {:jobName => "#{myshixun_job}"} + # uri = URI("#{jenkins_shixuns}/jenkins-exec/game/deleteJob") + # res = uri_exec uri, params + # if res && res['code'].to_i != 0 && res['code'].to_i != 1 + # raise("实训云平台繁忙(繁忙等级:89)") + # end + redirect_to shixun_exec_shixun_path(shixun, :type => 1) rescue Exception => e + flash[:error] = "实训云平台繁忙(繁忙等级:89)" + g.delete_project(@myshixun.gpid) if !g_project.try(:id).nil? + redirect_to myshixun_path(@myshixun) logger.error("myshixun reset failed #{e}") raise ActiveRecord::Rollback end - redirect_to shixun_exec_shixun_path(shixun) end end @@ -68,28 +130,18 @@ class MyshixunsController < ApplicationController end end end - # if status == "0" - # if game.status == 2 - # game.update_attributes!(:retry_status => 2) - # else - # game.update_attributes!(:status => 2, :final_score => challenge.score, :end_time => Time.now) - # end - # else - # if game.status == 2 - # game.update_attribute(:retry_status, 1) - # else - # game.update_attribute(:status, 0) - # end - # end if status == "0" - if resubmit == "1" - game.update_attributes!(:retry_status => 2) + if !resubmit.blank? + game.update_attributes(:retry_status => 2, :resubmit_identifier => resubmit) else - game.update_attributes!(:status => 2, :final_score => challenge.score, :end_time => Time.now) + game.update_attributes(:status => 2, :end_time => Time.now) + unless game.answer_open? # 如果没有查看答案,则获得该关卡得分 + game.update_attribute(:final_score, challenge.score) + end end - else - if resubmit == "1" - game.update_attribute(:retry_status, 1) + else # status == "-1" 表示返回结果错误 + if !resubmit.blank? + game.update_attributes(:retry_status => 1, :resubmit_identifier => resubmit) else game.update_attribute(:status, 0) end diff --git a/app/controllers/praise_tread_controller.rb b/app/controllers/praise_tread_controller.rb index a661892f8..680352e0a 100644 --- a/app/controllers/praise_tread_controller.rb +++ b/app/controllers/praise_tread_controller.rb @@ -149,6 +149,8 @@ class PraiseTreadController < ApplicationController @obj = Work.find_by_id(id) when 'Challenge' || 'ChallengeTread' @obj = Challenge.find_by_id(id) + when 'Discuss' + @obj = Discuss.find_by_id(id) else @obj = nil end diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index ff3f1c7d1..ea64d0397 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -929,10 +929,10 @@ class ProjectsController < ApplicationController end end - def uri_exec uri, params - res = Net::HTTP.post_form(uri, params).body - res = JSON.parse(res) - end + # def uri_exec uri, params + # # res = Net::HTTP.post_form(uri, params).body + # # res = JSON.parse(res) + # end # 开启实训项目,学生会fork一个项目并自动发送任务 def training_project_extend diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index b081230d1..0a139e648 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -36,17 +36,17 @@ class RepositoriesController < ApplicationController before_filter :find_repository, :only => [:edit, :update, :destroy, :committers] before_filter :find_project_repository, :except => [:commits, :shixun_show, :new, :create, :newcreate, :edit, :update, :destroy, :committers, - :newrepo, :to_gitlab, :forked, :export_rep_static, :training_project_extend, :shixun_entry] + :newrepo, :to_gitlab, :forked, :export_rep_static, :training_project_extend, :shixun_entry, :shixun_commit_diff] # 实训项目新增 - before_filter :find_project_and_repository, :only => [:commits, :shixun_show, :shixun_entry] + before_filter :find_project_and_repository, :only => [:commits, :shixun_show, :shixun_entry, :shixun_commit_diff] # 连接gitlab # before_filter :connect_gitlab, :only => [:quality_analysis, :commit_diff] before_filter :find_changeset, :only => [:revision, :add_related_issue, :remove_related_issue] # before_filter :authorize , :except => [:newrepo,:newcreate,:fork, :to_gitlab, :forked, :project_archive, :quality_analysis, :commit_diff] - before_filter :authorize_visible , :except => [:shixun_show, :newrepo,:newcreate,:fork, :to_gitlab, :forked, :project_archive, :quality_analysis, :commit_diff] + before_filter :authorize_visible , :except => [:shixun_show, :newrepo,:newcreate,:fork, :to_gitlab, :forked, :project_archive, :quality_analysis, :commit_diff, :shixun_commit_diff] # 版本库新增权限 # before_filter :show_rep, :only => [:show, :stats, :revisions, :revision, :diff, :commit_diff ] accept_rss_auth :revisions @@ -620,11 +620,15 @@ update @project_menu_type = 5 @entry = @repository.entry(@path, @rev) (show_error_not_found; return) unless @entry - limit = 10 + limit = 15 # 每次页面的换回值从1开始,但是gitlab的页面查询是从0开始,所以先改变page的类型减一在改回来 @commits = @g.commits(@shixun.gpid, page:(params[:page].to_i - 1).to_s, ref_name:@rev) @commits_count = params[:commit_count].nil? ? @g.user_static(@shixun.gpid, :rev => @rev).count : params[:commit_count].to_i - @commits_pages = Paginator.new @commits_count, limit, params[:page] + # @commits_pages = Paginator.new @commits_count, limit, params[:page] + + @commits_pages = Paginator.new @commits_count, limit, params['page'] || 1 + @offset ||= @commits_pages.offset + @commits = paginateHelperForGitlab @commits, limit render :layout => 'base_shixun' end @@ -798,6 +802,17 @@ update render :layout => 'base_projects' end + def shixun_commit_diff + @commit_diff = @g.commit_diff(@shixun.gpid, params[:changeset_id]) + diff = ActiveSupport::JSON.decode(@commit_diff.to_json).first + diff = OpenStruct.new(diff) + @diff_file = Trustie::Gitlab::Diff::File.new(diff) + + + # @commit_details = @g.commit(@project.gpid, params[:changeset]) + render :layout => 'base_shixun' + end + # 实训项目 # 每次提交对应的文件差异 def commit diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 40dbaa7b4..1c9ae8fb9 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -3,12 +3,58 @@ class ShixunsController < ApplicationController layout 'base_shixun' before_filter :require_login - before_filter :find_shixun, :except => [ :index, :new, :create, :index, :search] + before_filter :check_authentication + before_filter :find_shixun, :except => [ :index, :new, :create, :index, :search, :shixun_courses, :new_disscuss] before_filter :shixun_view_allow, :only => [:show] - before_filter :require_manager, :only => [ :settings, :add_script, :publish] + before_filter :require_manager, :only => [ :settings, :add_script, :publish, :collaborators_delete, :shixun_members_added, :add_collaborators] + #skip_before_filter :verify_authenticity_token, :only => :update_propaedeutics include ApplicationHelper + def shixun_test + jenkins_shixuns = Redmine::Configuration['jenkins_shixuns'] + uri = URI("#{jenkins_shixuns}/jenkins-exec/webssh/getConnectInfo") + user_id = User.current.id + params = {userID:user_id} + res = uri_exec uri, params + render :json => {data:"succesed"} + end + + def delete_shixun_test + jenkins_shixuns = Redmine::Configuration['jenkins_shixuns'] + uri = URI("#{jenkins_shixuns}/jenkins-exec/webssh/deleteSSH") + user_id = User.current.id + params = {userID:user_id} + res = uri_exec uri, params + render :json => {data:"succesed"} + end + + def game_webssh + + end + + def entry_edit + g = Gitlab.client + @path = params[:path] + @rev = params[:rev] + file_content = g.files(@shixun.gpid, @path, @rev).content + @content = Base64.decode64(file_content) unless file_content.blank? + respond_to do |format| + format.js + end + end + + def entry_update + g = Gitlab.client + @path = params[:path] + @rev = params[:rev] + @content = params[:content] + code_file = g.edit_file(@shixun.gpid, :content => params[:content], :file_path => @path, :branch_name => @rev, :commit_message => "shixun entry") + respond_to do |format| + format.js + end + end + def shixun_monitor # monitor_filter # if @had_exec @@ -22,29 +68,169 @@ class ShixunsController < ApplicationController def statistics @challenges = @shixun.challenges - @top_students = @shixun + @top_students = @shixun.myshixuns.where(:status => 1) myshixuns = @shixun.myshixuns.includes(:games) @latest_myshixuns = myshixuns.order("created_at desc").limit(4) end + def autocompletion + + end + def index - @shixuns = Shixun.where(:authentication => 1).order('updated_at desc') - @shixun_my_score = Game.where(:user_id => User.current).sum(:final_score) - @current_user_had_passed = Myshixun.where(:status => 1).count + @order = "created_at" + @sort = "desc" + search = params[:search] + @shixun_all_count = Shixun.all.count + @shixuns = Shixun.find_by_sql("select * from shixuns where id in (SELECT distinct(shixun_id) FROM `challenges`) and name like '%#{search}%' order by created_at desc") + #@shixuns = Shixun.where("name like ?", "%#{search}%").reorder("created_at desc") + # @shixun_my_score = Game.find_by_sql("select sum(final_score) as score from games where myshixun_id in (select id from myshixuns where status =1 + # and user_id=#{User.current.id} and shixun_id in (SELECT id FROM `shixuns` where status > 1))").first.try(:score).to_i + @shixun_my_score = Experience.find_by_sql("SELECT sum(score) as score FROM `experiences` where user_id=#{User.current.id}").first.try(:score).to_i + @current_user_had_passed = Myshixun.find_by_sql("select count(*) as had_passed from myshixuns where status =1 and user_id=#{User.current.id} + and shixun_id in (SELECT id FROM `shixuns` where status > 1)").first.try(:had_passed).to_i + @majors = Major.where(:id => [635, 636, 637, 638, 639, 622, 619]) + @courses = CourseList.where(:id => MajorCourse.where(:major_id => @majors.map(&:id)).map(&:course_list_id)) @shixuns_count = @shixuns.count + @limit = 16 + @is_remote = true + @shixun_pages = Paginator.new @shixuns_count, @limit, params['page'] || 1 + @offset ||= @shixun_pages.offset + @shixuns = paginateHelper @shixuns, @limit render :layout => "base_edu" end + def propaedeutics + respond_to do |format| + format.html + end + end + + def update_propaedeutics + @shixun = Shixun.where(:identifier => params[:id]).first + @shixun.update_attribute("propaedeutics", params[:shixun][:propaedeutics]) + redirect_to propaedeutics_shixun_path(@shixun) + end + + def collaborators + @collaborators = @shixun.collaborators + end + + def new_disscuss + render :layout => 'base_edu' + end + + def collaborators_delete + user_id = params[:c_id] + shixun_member = ShixunMember.where(:user_id => user_id, :shixun_id => @shixun.id, :role => 2).first + shixun_member.delete + @collaborators = @shixun.collaborators + respond_to do |format| + format.js + end + end + + # 已存在的成员不添加 + def add_collaborators + if !params[:search].nil? + # members = searchTeacherAndAssistant @course + member_ids = "(" + @shixun.shixun_members.map(&:user_id).join(',') + ")" + condition = "%#{params[:search].strip}%".gsub(" ","") + @users = User.where("id not in #{member_ids} and status = 1 and LOWER(concat(lastname, firstname)) LIKE '#{condition}'").includes(:user_extensions) + end + respond_to do |format| + format.js + end + end + + def shixun_members_added + unless params[:membership][:user_ids].blank? + memberships = params[:membership][:user_ids] + memberships.each do |member| + ShixunMember.create(:user_id => member, :shixun_id => @shixun.id, :role => 2) + end + @collaborators = @shixun.collaborators + end + respond_to do |format| + format.js + end + end + def search # 确定 sort 1升序 2 降序 - if params[:time_reorder] - order = "#{Shixun.table_name}.created_at #{params[:time_reorder]}" - elsif params[:hot_reorder] - order = "myshixun_count #{params[:hot_reorder]}, #{Shixun.table_name}.updated_at #{params[:hot_reorder]}" + @order = params[:order] || "created_at" + bsort = params[:sort] || "desc" + @sort = bsort == "desc" ? "asc" : "desc" + if @order == "created_at" + order_str = "#{Shixun.table_name}.created_at #{bsort}" else - order = "#{Shixun.table_name}.created_at desc" + order_str = "myshixun_count #{bsort}, #{Shixun.table_name}.updated_at #{bsort}" end - @shixuns = Shixun.where(:authentication => 1).reorder(order) + @language = params[:language] + @status = params[:status].to_i + @shixun_status = params[:shixun_status] # 2是已发布 3是未发布 + @search = params[:search] + @major = params[:major] + @course = params[:course] + @trainee = params[:trainee] + ids = Shixun.find_by_sql("select group_concat(id) as allId from shixuns where id in (SELECT distinct(shixun_id) FROM `challenges`)") + @shixuns = Shixun.where(:id => ids[0].allId.split(",")) + @shixuns = @shixuns.where(:language => @language) unless @language.blank? + @shixuns = @shixuns.where("name like ?", "%#{@search}%") unless @search.blank? + if !@major.blank? + @shixuns = @shixuns.where(:major_id => @major.to_i) + @courses = CourseList.where(:id => MajorCourse.where(:major_id => @major).map(&:course_list_id)) + else + @courses = CourseList.where(:id => MajorCourse.where(:major_id => [635, 636, 637, 638, 639, 622, 619]).map(&:course_list_id)) + end + if !@course.blank? && (@major.blank? || MajorCourse.where(:major_id => @major, :course_list_id => @course).count == 1) + @shixuns = @shixuns.where(:id => ShixunMajorCourse.where(:course_list_id => @course).map(&:shixun_id)) + end + if !@major.blank? && MajorCourse.where(:major_id => @major, :course_list_id => @course).count == 0 + @course = nil + end + @shixuns = @shixuns.where(:trainee => @trainee) unless @trainee.blank? + case @status + when 1, 0 + @shixuns = @shixuns + when 2 + @shixuns = @shixuns.where(:user_id => User.current) + when 3 + shixun_ids = Myshixun.where(:user_id => User.current).blank? ? "(-1)" : "(" + Myshixun.where(:user_id => User.current).map(&:shixun_id).join(',') +")" + @shixuns = @shixuns.where("id not in #{shixun_ids}") + when 4 + shixun_ids = Myshixun.where(:user_id => User.current, :status => 0).map(&:shixun_id) + @shixuns = @shixuns.where(:id => shixun_ids) + when 5 + shixun_ids = Myshixun.where(:user_id => User.current, :status => 1).map(&:shixun_id) + @shixuns = @shixuns.where(:id => shixun_ids) + end + case @shixun_status + when "1" + @shixuns = @shixuns.where(:status => [0, 1]) + when "2" + @shixuns = @shixuns.where(:status => 2) + when "3" + @shixuns = @shixuns.where(:status => 3) + when nil, "0" + @shixuns = @shixuns + end + if @order == "created_at" + @shixuns =@shixuns.reorder(order_str) + else + # 最热排序 + @shixuns.each do |shixun| + shixun[:myshixunCount] = shixun.myshixuns.count + end + @shixuns = @shixuns.sort{|x, y| y[:myshixunCount] <=> x[:myshixunCount]} + end + # @shixuns = Shixun.where(:authentication => 1).reorder(order) + @shixuns_count = @shixuns.count + @limit = 16 + @is_remote = true + @shixun_pages = Paginator.new @shixuns_count, @limit, params['page'] || 1 + @offset ||= @shixun_pages.offset + @shixuns = paginateHelper @shixuns, @limit respond_to do |format| format.js end @@ -54,50 +240,74 @@ class ShixunsController < ApplicationController # gameID 及实训ID def publish jenkins_shixuns = Redmine::Configuration['jenkins_shixuns'] - fragments = [] - testSet = [] - testCases = [] begin - challenges = @shixun.challenges.includes(:test_sets) - challenges.each do |challenge| - pipeline_script = challenge.try(:pipeline_script) - challenge_script = {:challengeStage => "#{challenge.position}", :challengePipeline => "#{pipeline_script}"} - fragments << challenge_script - # 每一关所有的测试集 - challenge.test_sets.each do |test_set| - test_cases = {:caseId => test_set.id.to_s, :input => test_set.input, :output => test_set.output, :isPublic => (test_set.is_public ? "1" : "0")} - testSet << test_cases - end - test_sets_list = {:challengeStage => challenge.position.to_s, :challengeTestCases => testSet} - testCases << test_sets_list - testSet = [] - end - gameInfo = {:trainingID => @shixun.id.to_s, :operationEnvironment => @shixun.language, :challengePipelines => fragments, :testCases => testCases} - fragments = fragments.to_json + gameInfo = @shixun.gameInfo uri = URI("#{jenkins_shixuns}/jenkins-exec/game/publishGame") - params = {gameInfo:gameInfo.to_json} + logger.info(gameInfo) + params = {gameInfo:gameInfo} + logger.info(params) res = uri_exec uri, params - if res['code'] == 0 - @shixun.update_attribute(:status, 1) - @shixun.update_attribute(:script, res["msg"]) + logger.info("###################{res['code']}") + if res && res['code'].to_i == 0 + logger.info("1111###################{res['code']}") + @shixun.update_attributes(:status => 1) + apply = ApplyAction.where(:container_type => "ApplyShixun", :container_id => @shixun.id).order("created_at desc").first + if apply && apply.status == 0 + @status = 0 + else + ApplyAction.create(:container_type => "ApplyShixun", :container_id => @shixun.id, :user_id => User.current.id, :status => 0) + notes = User.current.show_name.to_s + " 申请发布实训:#{@shixun.name}" + JournalsForMessage.create(:jour_id => 1, :jour_type => 'Principal', :user_id => User.current.id, :notes => notes, :private => 1, :reply_id => 0) + @status = 1 + end + shixun_modify_status_without_publish(@shixun, 1) else logger.error("res['code'] is #{res['code']}, res['msg'] is #{res['code']}") @jenkin_error = true - raise("当前系统繁忙,请稍后再试") end - rescue + rescue Exception => e + @jenkin_error = true + logger.error("pushlish game #{e}") respond_to do |format| format.js end end end + def apply_publish + apply = ApplyAction.where(:container_type => "ApplyShixun", :container_id => @shixun.id).last + if apply && apply.status == 0 + @status = 0 + else + ApplyAction.create(:container_type => "ApplyShixun", :container_id => @shixun.id, :user_id => User.current.id, :status => 0) + notes = User.current.show_name.to_s + " 申请发布实训:#{@shixun.name}" + JournalsForMessage.create(:jour_id => 1, :jour_type => 'Principal', :user_id => User.current.id, :notes => notes, :private => 1, :reply_id => 0) + @shixun.update_column('status', 1) + @status = 1 + end + end + + def cancel_publish + apply = ApplyAction.where(:container_type => "ApplyShixun", :container_id => @shixun.id).order("created_at desc").first + if apply && apply.status == 0 + apply.update_attributes(:status => 3) + @shixun.update_column('status', 0) + end + redirect_to shixun_path(@shixun) + end + + def close + @shixun.update_column('status', 3) + redirect_to shixun_path(@shixun) + end + # copy_shixun:复制一个新的实训模块包括版本库 # copy_myshixun自动创建系列game,game中只包含状态等信息,公共信息从Challeges中读取 # 开启过实训的则直接跳入my实训页面 def shixun_exec - unless allow_shixun_exec(@shixun) + unless allow_shixun_exec(@shixun) && (User.current.manager_of_shixun?(@shixun) || @shixun.status > 0) render_403 + return end myshixun = Myshixun.where(:user_id => User.current.id, :shixun_id => @shixun.id).first unless myshixun.blank? @@ -117,17 +327,48 @@ class ShixunsController < ApplicationController logger.info("#############gshixun is #{gshixun}") if !gshixun.id.nil? myshixun = copy_myshixun(@shixun, gshixun) - @shixun.update_attribute(:myshixun_count, (@shixun.myshixun_count + 1)) + # @shixun.update_attribute(:myshixun_count, (@shixun.myshixun_count + 1)) challenges = @shixun.challenges # 之所以增加user_id是为了方便统计查询性能 challenges.each_with_index do |challenge, index| status = (index == 0 ? 0 : 3) code = CODES.sample(12).join code = CODES.sample(12).join if Game.where(identifier: code).present? - Game.create!(:challenge_id => challenge.id, :myshixun_id => myshixun.id, :status => status, :user_id => myshixun.user_id, :open_time => Time.now, :identifier => code) + game =Game.create!(:challenge_id => challenge.id, :myshixun_id => myshixun.id, :status => status, :user_id => myshixun.user_id, :open_time => Time.now, :identifier => code) + # 记录刚开始时默认代开文件原始代码 + # 刚开始fork的一段时间是获取不了content内容的 + game_passed_code(game.try(:id), challenge.try(:path), myshixun.try(:gpid), 0) end + if params[:type] == "1" # 重置过来的请求 + shixun_mod = ShixunModify.where(:shixun_id => myshixun.try(:shixun_id), :myshixun_id => myshixun.try(:id)).first + if shixun_mod.nil? + ShixunModify.create(:shixun_id => myshixun.shixun_id, :myshixun_id => myshixun.id, :status => 0) + else + shixun_mod.update_attributes(:status => 0) + end + end + # webssh类型开始实训的时候建立webssh连接 + # if @shixun.webssh + # # username = Redmine::Configuration['webssh_username'] + # # password = Redmine::Configuration['webssh_password'] + # jenkins_shixuns = Redmine::Configuration['jenkins_shixuns'] + # uri = URI("#{jenkins_shixuns}/jenkins-exec/webssh/getConnectInfo") + # user_id = User.current.id + # params = {userID:user_id} + # res = uri_exec uri, params + # if res && res['code'].to_i == 0 + # myshixun_webssh = Webssh.where(:myshixun_id => myshixun.id).first + # if myshixun_webssh.nil? + # Webssh.create(:myshixun_id => myshixun.id, :host => @temp, :port => @temp) + # else + # myshixun_webssh.update_attributes(:host => @temp, :port => @temp) + # end + # else + # raise("实训云平台繁忙(繁忙等级:92)") + # end + # end else - raise("网络异常,请稍后重试") + raise("实训云平台繁忙(繁忙等级:81)") end logger.info("myshixun id si #{myshixun.id} and current_task id is#{myshixun.current_task.id}") redirect_to myshixun_game_path(myshixun.current_task, :myshixun_id => myshixun) @@ -141,11 +382,33 @@ class ShixunsController < ApplicationController end end + def shixun_courses + data = {result:0,options:[]} + if params[:major_id] != 0 + major = Major.find params[:major_id] + if major + data[:result] = 1 + major_courses = major.major_courses + CourseList.where(:id => major_courses.map(&:course_list_id)).each do |course| + option = [] + option << course.name.to_s + option << course.id + data[:options] << option + end + else + data[:result] = 0 + end + else + data[:result] = 0 + end + render :json =>data + end + def new @shixun = Shixun.new respond_to do |format| - format.html{render :layout => 'new_base'} + format.html{render :layout => 'base_edu'} format.json end end @@ -156,7 +419,14 @@ class ShixunsController < ApplicationController @shixun = Shixun.new(params[:shixun]) @shixun.user_id = User.current.id @shixun.language = params[:language] + @shixun.major_id = params[:major_id] + @shixun.trainee = params[:trainee] @shixun.identifier = identifier + if params[:course_id] + params[:course_id].each do |course_id| + @shixun.shixun_major_courses << ShixunMajorCourse.new(:major_id => params[:major_id], :course_list_id => course_id) + end + end (params[:shixun][:is_public] == "1" ? @shixun.is_public = true : @shixun.is_public = false) respond_to do |format| if @shixun.save @@ -176,7 +446,7 @@ class ShixunsController < ApplicationController raise "sync failed" if @shixun.gpid.blank? rescue Exception => e @shixun.update_attribute(:gpid, nil) - if @repository.id + if @repository && @repository.id @repository.destroy end end @@ -208,17 +478,55 @@ class ShixunsController < ApplicationController end def update - @shixun.attributes = params[:shixun] - @shixun.language = params[:language] - params[:shixun][:is_public] == "on" ? @shixun.is_public = 1 : @shixun.is_public = 0 - @shixun.save + if @shixun.status == 0 + language = @shixun.language + @shixun.attributes = params[:shixun] + @shixun.language = params[:language] + @shixun.trainee = params[:trainee] + if params[:course_id] + @shixun.shixun_major_courses.destroy_all + params[:course_id].each do |course_id| + @shixun.shixun_major_courses << ShixunMajorCourse.new(:major_id => params[:major_id], :course_list_id => course_id) + end + end + @shixun.major_id = params[:major_id] + params[:shixun][:is_public] == "on" ? @shixun.is_public = 1 : @shixun.is_public = 0 + if @shixun.save + # 实训语言更改了会影响后续的评测,所以需要更新is_updated + if language != params[:language] + add_shixun_modify_status(@shixun, 1) + end + end + else + @error = "该实训已申请发布了,暂不能编辑" + end respond_to do |format| format.html{redirect_to settings_shixun_url(@shixun)} + format.js end end - def destroy + def shixun_discuss + @discusses = @shixun.discusses.where(:parent_id => nil).reorder("created_at desc") + @discusses_count = @discusses.count + @limit = 15 + @is_remote = true + @discusses_pages = Paginator.new @discusses_count, @limit, params['page'] || 1 + @offset ||= @discusses_pages.offset + @discusses = paginateHelper @discusses, @limit + end + def destroy + unless User.current.admin? + render_403 + return + end + Subject.where(:id => @shixun.stage_shixuns.map(&:subject_id)).destroy_all + @shixun.destroy + respond_to do |format| + format.html{ redirect_to shixuns_managements_path } + format.js + end end def settings @@ -286,6 +594,14 @@ class ShixunsController < ApplicationController end end + # 实训行为操作 + def operation + @myshixun = Myshixun.where(:id => params[:myshixun_id]).first + @is_modify = ShixunModify.where(:myshixun_id => params[:myshixun_id], :shixun_id => @shixun.try(:id), :status => 1).first + @mail = User.current.mail.blank? + + end + private # REDO: 新增类型copy的时候 # 复制项目 @@ -293,7 +609,7 @@ class ShixunsController < ApplicationController CODES = %W(2 3 4 5 6 7 8 9 a b c f e f g h i j k l m n o p q r s t u v w x y z) def copy_myshixun shixun, gshixun myshixun = Myshixun.new - myshixun.attributes = shixun.attributes.dup.except("id","user_id","visits","gpid","status", "identifier") + myshixun.attributes = shixun.attributes.dup.except("id","user_id","visits","gpid","status", "identifier","propaedeutics") myshixun.shixun_id = shixun.id myshixun.user_id = User.current.id myshixun.gpid = gshixun.id @@ -307,13 +623,14 @@ class ShixunsController < ApplicationController rep.type = "Repository::Gitlab" rep.save! login = User.find_by_mail("educoder@163.com").try(:login) - rep_url = Base64.encode64(git_shixun_url shixun, login) + rep_url = Base64.encode64(git_shixun_url_ip shixun, login) uri = URI("#{jenkins_shixuns}/jenkins-exec/game/openGameInstance") pipeLine = "#{shixun.script}" - params = {jobNameForInstance: "myshixun_#{myshixun.id}", gamePipelineScript: pipeLine, instanceGitURL:rep_url} + params = {jobNameForInstance: "myshixun_#{myshixun.id}", gameInfo: shixun.gameInfo, instanceGitURL:rep_url} + logger.info("openGameInstance params is #{params}") res = uri_exec uri, params - if (res && res['code'] != 0) - raise("Job 创建失败") + if (res && res['code'].to_i != 0) + raise("实训云平台繁忙(繁忙等级:83)") end return myshixun end @@ -329,11 +646,7 @@ class ShixunsController < ApplicationController # 权限控制 def shixun_view_allow - if @shixun.is_public? - true - else - User.current.member_of?(@shixun) ? true : false - end + render_403 if (@shixun.status == 0 && !(User.current.manager_of_shixun?(@shixun) || User.current.admin?)) end # 实训管理员或者超级管理员 diff --git a/app/controllers/stages_controller.rb b/app/controllers/stages_controller.rb new file mode 100644 index 000000000..cdb8712df --- /dev/null +++ b/app/controllers/stages_controller.rb @@ -0,0 +1,83 @@ +class StagesController < ApplicationController + before_filter :check_authentication + before_filter :find_subject, :only => [ :create] + before_filter :find_stage, :only => [:edit, :update, :destroy] + include ApplicationHelper + + def create + if params[:stage_name] && params[:shixun_id] + stage = Stage.new + stage.name = params[:stage_name] + stage.subject_id = @subject.id + stage.user_id = User.current.id + stage.position = @subject.stages.count + 1 + ActiveRecord::Base.transaction do + if stage.save + begin + params[:shixun_id].each do |shixun_id| + shixun = Shixun.find shixun_id + stage.stage_shixuns << StageShixun.new(:subject_id => @subject.id, :shixun_id => shixun_id, :position => stage.stage_shixuns.count + 1) if shixun + end + rescue Exception => e + + end + end + end + redirect_to subject_path(@subject) + end + end + + def edit + respond_to do |format| + format.js + end + end + + def update + if params[:stage_name] && params[:shixun_id] + @stage.name = params[:stage_name] + ActiveRecord::Base.transaction do + if @stage.save + begin + @stage.stage_shixuns.destroy_all + params[:shixun_id].each do |shixun_id| + shixun = Shixun.find shixun_id + @stage.stage_shixuns << StageShixun.new(:subject_id => @subject.id, :shixun_id => shixun_id, :position => @stage.stage_shixuns.count + 1) if shixun + end + rescue Exception => e + + end + end + end + redirect_to subject_path(@subject) + end + end + + def destroy + if User.current.manager_of_subject?(@subject) + @subject.stages.where("position > #{@stage.position}").update_all("position = position - 1") + @stage.destroy + @status = 1 + else + @status = 0 + end + end + + private + def find_subject + @subject = Subject.find_by_id(params[:subject]) + if @subject.nil? + render_404 + return + end + rescue ActiveRecord::RecordNotFound + render_404 + end + + def find_stage + @stage = Stage.find(params[:id]) + @subject = @stage.subject + rescue ActiveRecord::RecordNotFound + render_404 + end +end diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb index 9ba631913..ba475aa80 100644 --- a/app/controllers/student_work_controller.rb +++ b/app/controllers/student_work_controller.rb @@ -7,8 +7,8 @@ class StudentWorkController < ApplicationController require "base64" before_filter :find_homework, :only => [:new, :index, :create, :student_work_absence_penalty, :absence_penalty_list, :evaluation_list, :program_test,:program_test_ex, :set_score_rule,:forbidden_anonymous_comment,:delete_work,:new_student_work_project,:student_work_project,:cancel_relate_project, - :search_course_students,:work_canrepeat,:add_group_member,:change_project] - before_filter :find_work, :only => [:edit, :update, :show, :destroy, :add_score, :praise_student_work, :retry_work, :revise_attachment, :hide_score_detail] + :search_course_students,:work_canrepeat,:add_group_member,:change_project,:relate_myshixun] + before_filter :find_work, :only => [:edit, :update, :show, :destroy, :add_score, :praise_student_work, :retry_work, :revise_attachment, :hide_score_detail, :destroy_score] before_filter :member_of_course, :only => [:new, :create, :show, :add_score, :praise_student_work] before_filter :author_of_work, :only => [:edit, :update, :destroy] before_filter :teacher_of_course, :only => [:student_work_absence_penalty, :absence_penalty_list, :evaluation_list, :set_score_rule, :forbidden_anonymous_comment] @@ -157,14 +157,9 @@ class StudentWorkController < ApplicationController unless student_work.save resultObj[:status] = 200 else - student_work.name = params[:title] + student_work.name = @homework.name.to_s + "的作品提交" student_work.description = params[:src] - if !is_test && @homework.end_time < Time.now.to_s - student_work.late_penalty = @homework.late_penalty - else - student_work.late_penalty = 0 - end #每次从数据库取出上次的结果加上本次的结果再存入数据库 if result["status"].to_i != -2 @@ -364,94 +359,44 @@ class StudentWorkController < ApplicationController end end ################################################################################################################## - @order,@b_sort,@name,@group = params[:order] || "score",params[:sort] || "desc",params[:name].to_s.strip || "",params[:group] + @order,@b_sort,@name,@group,@comment,@status = params[:order] || "updated_at",params[:sort] || "desc",params[:name].to_s.strip || "",params[:group], params[:comment], params[:status] @homework_commons = @course.homework_commons.where("publish_time <= ?",Time.now).order("created_at desc") @all_homework_commons = @course.homework_commons.order("created_at desc") @is_teacher = User.current.allowed_to?(:as_teacher,@course) || User.current.admin? - @is_evaluation = @homework.homework_detail_manual && @homework.homework_detail_manual.comment_status == 2 && !@is_teacher #是不是匿评 + @is_evaluation = @homework.homework_detail_manual && (@homework.homework_detail_manual.comment_status == 3 || @homework.homework_detail_manual.comment_status == 4) && !@is_teacher #是不是匿评 @show_all = false # 0表示没有分组的学生,-1表示所有分组的学生 if @group - if @group == "0" - none_group_students = @course.members.select{ |member| member.course_group_id == 0 } - if none_group_students.empty? - student_in_group = '(0)' - else - student_in_group = '(' + none_group_students.map{ |member| member.user_id }.join(',') + ')' - end - elsif @group == "-1" - all_group_students = @course.members.select{ |member| member.course_group_id } - if all_group_students.empty? - student_in_group = '(0)' - else - student_in_group = '(' + all_group_students.map{ |member| member.user_id }.join(',') + ')' - end + group_students = @course.members.where(:course_group_id => @group).joins("join users on members.user_id = users.id").select{|m| m.roles.to_s.include?("Student")} + + if group_students.empty? + student_in_group = '(-1)' else - course_group = CourseGroup.find_by_id(@group) - group_students = course_group.users - if group_students.empty? - student_in_group = '(0)' - else - student_in_group = '(' + group_students.map{ |user| user.id }.join(',') + ')' - end + student_in_group = '(' + group_students.map{ |member| member.user_id }.join(',') + ')' end #开放作品 || 老师 || 超级管理员 || 禁用匿评&&作业截止&&已提交作品 显示所有列表 - if (@homework.is_open == 1 && @course.is_public == 1) || (@homework.is_open == 1 && @course.is_public == 0 && User.current.member_of_course?(@course)) || @is_teacher || User.current.admin? || (User.current.member_of_course?(@course) && @homework.anonymous_comment == 1 && @homework.end_time < Time.now && !@homework.student_works.has_committed.where(:user_id => User.current.id).empty?) - if @order == 'lastname' - @stundet_works = search_homework_member @homework.student_works.no_copy.select("student_works.*,student_works.work_score as score").joins(:user).where("users.id in #{student_in_group}").order("CONVERT(lastname USING gbk) COLLATE gbk_chinese_ci #{@b_sort}, login #{@b_sort}"),@name - elsif @order == 'student_id' - @stundet_works = search_homework_member @homework.student_works.no_copy.select("student_works.*,student_works.work_score as score").joins(:user).where("users.id in #{student_in_group}").joins("join user_extensions on student_works.user_id = user_extensions.user_id").order("#{@order} #{@b_sort}"),@name - else - @stundet_works = search_homework_member @homework.student_works.no_copy.select("student_works.*,student_works.work_score as score").joins(:user).where("users.id in #{student_in_group}").order("#{@order} #{@b_sort}"),@name - end + if (@homework.is_open == 1 && @course.is_public == 1) || (@homework.is_open == 1 && @course.is_public == 0 && User.current.member_of_course?(@course)) || @is_teacher || User.current.admin? || (User.current.member_of_course?(@course) && @homework.homework_detail_manual.comment_status == 6) + @stundet_works = @homework.student_works.select("student_works.*,student_works.work_score as score").joins(:user).where("users.id in #{student_in_group}").order("#{@order} #{@b_sort}") @show_all = true elsif User.current.member_of_course?(@course) - if @homework.homework_detail_manual.comment_status == 1 #学生 && 未开启匿评 只看到自己的 + if @homework.homework_detail_manual.comment_status == 1 || @homework.homework_detail_manual.comment_status == 2 #学生 && 未开启匿评 只看到自己的 if @homework.homework_type == 3 - pro = @homework.student_work_projects.where(:user_id => User.current.id).first - if pro.nil? - @stundet_works = [] - else - @stundet_works = @homework.student_works.select("student_works.*,student_works.work_score as score").where(:id => pro.student_work_id) - end + my_work = @homework.student_works.where(:user_id => User.current.id).first + @stundet_works = my_work ? @homework.student_works.select("student_works.*,student_works.work_score as score").where(:group_id => my_work.group_id) : [] else - @stundet_works = @homework.student_works.has_committed.select("student_works.*,student_works.work_score as score").where(:user_id => User.current.id) - end - elsif @homework.homework_detail_manual.comment_status == 2 #学生 && 开启匿评 看到匿评列表 - if @homework.homework_type == 3 - pro = @homework.student_work_projects.where(:user_id => User.current.id).first - if pro.nil? - my_work = [] - else - my_work = @homework.student_works.where(:id => pro.student_work_id) - end - else - my_work = @homework.student_works.has_committed.where(:user_id => User.current.id) + @stundet_works = @homework.student_works.select("student_works.*,student_works.work_score as score").where(:user_id => User.current.id) end + elsif @homework.homework_detail_manual.comment_status == 3 || @homework.homework_detail_manual.comment_status == 4 #学生 && 开启匿评 看到匿评列表 + my_work = @homework.student_works.select("student_works.*,student_works.work_score as score").where(:user_id => User.current.id) @stundet_works = my_work + User.current.student_works_evaluation_distributions.map(&:student_work).select { |work| work.homework_common_id == @homework.id} - elsif @homework.homework_detail_manual.comment_status == 3 #学生 && 关闭匿评 未提交作品之前列表为空,提交了作品看到所有的 - if @homework.homework_type == 3 - pro = @homework.student_work_projects.where(:user_id => User.current.id).first - if pro.nil? - my_work = [] - else - my_work = @homework.student_works.select("student_works.*,student_works.work_score as score").where(:id => pro.student_work_id) - end - else - my_work = @homework.student_works.has_committed.select("student_works.*,student_works.work_score as score").where(:user_id => User.current.id) - end - if my_work.empty? + elsif @homework.homework_detail_manual.comment_status == 5 #学生 && 关闭匿评 未提交作品之前列表为空,提交了作品看到所有的 + my_work = @homework.student_works.select("student_works.*,student_works.work_score as score").where(:user_id => User.current.id) + if !my_work || my_work.status == 0 @stundet_works = [] else - if @order == 'lastname' - @stundet_works = search_homework_member @homework.student_works.has_committed.select("student_works.*,student_works.work_score as score").joins(:user).where("users.id in #{student_in_group}").order("CONVERT(lastname USING gbk) COLLATE gbk_chinese_ci #{@b_sort}, login #{@b_sort}"),@name - elsif @order == 'student_id' - @stundet_works = search_homework_member @homework.student_works.has_committed.select("student_works.*,student_works.work_score as score").joins(:user).where("users.id in #{student_in_group}").joins("join user_extensions on student_works.user_id = user_extensions.user_id").order("#{@order} #{@b_sort}"),@name - else - @stundet_works = search_homework_member @homework.student_works.has_committed.select("student_works.*,student_works.work_score as score").joins(:user).where("users.id in #{student_in_group}").order("#{@order} #{@b_sort}"),@name - end + @stundet_works = @homework.student_works.select("student_works.*,student_works.work_score as score").joins(:user).where("users.id in #{student_in_group}").order("#{@order} #{@b_sort}") @show_all = true end else @@ -462,62 +407,27 @@ class StudentWorkController < ApplicationController return end - @student_work_count = (search_homework_member @homework.student_works.has_committed.select("student_works.*,student_works.work_score as score").joins(:user).where("users.id in #{student_in_group}").order("#{@order} #{@b_sort}"),@name).count else - if (@homework.is_open == 1 &&@course.is_public == 1) || (@homework.is_open == 1 && @course.is_public == 0 && User.current.member_of_course?(@course)) || @is_teacher || User.current.admin? || (User.current.member_of_course?(@course) && @homework.anonymous_comment == 1 && @homework.end_time < Time.now && !@homework.student_works.has_committed.where(:user_id => User.current.id).empty?) - if @order == 'lastname' - @stundet_works = search_homework_member @homework.student_works.no_copy.select("student_works.*,student_works.work_score as score").joins(:user).order("CONVERT(lastname USING gbk) COLLATE gbk_chinese_ci #{@b_sort}, login #{@b_sort}"),@name - elsif @order == 'student_id' - @stundet_works = search_homework_member @homework.student_works.no_copy.select("student_works.*,student_works.work_score as score").joins("join user_extensions on student_works.user_id = user_extensions.user_id").order("#{@order} #{@b_sort}"),@name - else - @stundet_works = search_homework_member @homework.student_works.no_copy.select("student_works.*,student_works.work_score as score").includes(:user => {:user_extensions => []}, :project => {}, :student_works_scores => {}).order("#{@order} #{@b_sort}"),@name - end + if (@homework.is_open == 1 && @course.is_public == 1) || (@homework.is_open == 1 && @course.is_public == 0 && User.current.member_of_course?(@course)) || @is_teacher || User.current.admin? || (User.current.member_of_course?(@course) && @homework.homework_detail_manual.comment_status == 6) + @stundet_works = @homework.student_works.select("student_works.*,student_works.work_score as score").includes(:user => {:user_extensions => []}, :project => {}, :student_works_scores => {}).order("#{@order} #{@b_sort}") @show_all = true elsif User.current.member_of_course?(@course) - if @homework.homework_detail_manual.comment_status == 1 #学生 && 未开启匿评 只看到自己的 + if @homework.homework_detail_manual.comment_status == 1 || @homework.homework_detail_manual.comment_status == 2 #学生 && 未开启匿评 只看到自己的 if @homework.homework_type == 3 - pro = @homework.student_work_projects.where(:user_id => User.current.id).first - if pro.nil? - @stundet_works = [] - else - @stundet_works = @homework.student_works.select("student_works.*,student_works.work_score as score").where(:id => pro.student_work_id) - end + my_work = @homework.student_works.where(:user_id => User.current.id).first + @stundet_works = my_work ? @homework.student_works.select("student_works.*,student_works.work_score as score").where(:group_id => my_work.group_id) : [] else - @stundet_works = @homework.student_works.has_committed.select("student_works.*,student_works.work_score as score").where(:user_id => User.current.id) - end - elsif @homework.homework_detail_manual.comment_status == 2 #学生 && 开启匿评 看到匿评列表 - if @homework.homework_type == 3 - pro = @homework.student_work_projects.where(:user_id => User.current.id).first - if pro.nil? - my_work = [] - else - my_work = @homework.student_works.where(:id => pro.student_work_id) - end - else - my_work = @homework.student_works.has_committed.where(:user_id => User.current.id) + @stundet_works = @homework.student_works.select("student_works.*,student_works.work_score as score").where(:user_id => User.current.id) end + elsif @homework.homework_detail_manual.comment_status == 3 || @homework.homework_detail_manual.comment_status == 4 #学生 && 开启匿评 看到匿评列表 + my_work = @homework.student_works.select("student_works.*,student_works.work_score as score").where(:user_id => User.current.id) @stundet_works = my_work + User.current.student_works_evaluation_distributions.map(&:student_work).select { |work| work.homework_common_id == @homework.id} - elsif @homework.homework_detail_manual.comment_status == 3 #学生 && 关闭匿评 未提交作品之前列表为空,提交了作品看到所有的 - if @homework.homework_type == 3 - pro = @homework.student_work_projects.where(:user_id => User.current.id).first - if pro.nil? - my_work = [] - else - my_work = @homework.student_works.select("student_works.*,student_works.work_score as score").where(:id => pro.student_work_id) - end - else - my_work = @homework.student_works.has_committed.select("student_works.*,student_works.work_score as score").where(:user_id => User.current.id) - end - if my_work.empty? + elsif @homework.homework_detail_manual.comment_status == 5 #学生 && 关闭匿评 未提交作品之前列表为空,提交了作品看到所有的 + my_work = @homework.student_works.select("student_works.*,student_works.work_score as score").where(:user_id => User.current.id) + if !my_work || my_work.status == 0 @stundet_works = [] else - if @order == 'lastname' - @stundet_works = search_homework_member @homework.student_works.has_committed.select("student_works.*,student_works.work_score as score").joins(:user).order("CONVERT(lastname USING gbk) COLLATE gbk_chinese_ci #{@b_sort}, login #{@b_sort}"),@name - elsif @order == 'student_id' - @stundet_works = search_homework_member @homework.student_works.has_committed.select("student_works.*,student_works.work_score as score").joins("join user_extensions on student_works.user_id = user_extensions.user_id").order("#{@order} #{@b_sort}"),@name - else - @stundet_works = search_homework_member @homework.student_works.has_committed.select("student_works.*,student_works.work_score as score").order("#{@order} #{@b_sort}"),@name - end + @stundet_works = @homework.student_works.select("student_works.*,student_works.work_score as score").order("#{@order} #{@b_sort}") @show_all = true end else @@ -527,21 +437,46 @@ class StudentWorkController < ApplicationController render_403 return end - @student_work_count = (search_homework_member @homework.student_works.has_committed.select("student_works.*,student_works.work_score as score").order("#{@order} #{@b_sort}"),@name).count end + + unless @comment.blank? + has_comment_works = User.current.student_works_scores.where(:student_work_id => @homework.student_works.map(&:id), :reviewer_role => [1, 2]) + student_work_ids = has_comment_works.blank? ? '(-1)' : '(' + has_comment_works.map(&:student_work_id).join(',') + ')' + if @comment.include?('0') + @stundet_works = @stundet_works.where("student_works.id not in #{student_work_ids}") + else + @stundet_works = @stundet_works.where("work_status != 0 and student_works.id in #{student_work_ids}") + end + end + + unless @status.blank? + @stundet_works = @stundet_works.where(:work_status => @status) + end + + @stundet_works = search_homework_member @stundet_works, @name + @score = @b_sort == "desc" ? "asc" : "desc" @is_focus = params[:is_focus] ? params[:is_focus].to_i : 0 # 消息传过来的ID @message_student_work_id = params[:student_work_id] + @no_group_count = @course.members.where(:course_group_id => 0).select{|m| m.roles.to_s.include?("Student")}.count @left_nav_type = 3 @tab = params[:tab].to_i + @all_student_works = @stundet_works + @student_work_count = @stundet_works.count + @limit = 50 + @is_remote = true + @page = (params['page'] || 1).to_i + @student_work_pages = Paginator.new @student_work_count, @limit, @page + @offset ||= @student_work_pages.offset + @stundet_works = paginateHelper @stundet_works, @limit respond_to do |format| format.js - format.html + format.html { render :layout => 'base_edu'} format.xls { - filename = "#{@course.teacher.lastname.to_s + @course.teacher.firstname}_#{@course.name}_#{@course.time.to_s + @course.term}_#{@homework.name}#{l(:excel_homework_list)}.xls" - send_data(homework_to_xls(@stundet_works), :type => "text/excel;charset=utf-8; header=present", + filename = "#{@course.teacher.lastname.to_s + @course.teacher.firstname}_#{@course.name}_#{@homework.name}#{l(:excel_homework_list)}.xls" + send_data(homework_to_xls(@all_student_works), :type => "text/excel;charset=utf-8; header=present", :filename => filename_for_content_disposition(filename)) } end @@ -552,17 +487,21 @@ class StudentWorkController < ApplicationController noEvaluation = @homework.course_messages.where("user_id =? and viewed =?", User.current.id, 0) noEvaluation.update_all(:viewed => true) - if @homework.homework_type==2 - redirect_to new_user_commit_homework_users_path(homework_id: @homework.id) + # if @homework.homework_type==2 + # redirect_to new_user_commit_homework_users_path(homework_id: @homework.id) + # return + # end + @is_test = params[:is_test] == 'true' + @user = User.current + @student_work = @homework.student_works.where("user_id = ?",User.current.id).first + if @student_work.nil? + @student_work = StudentWork.new + elsif @student_work.work_status != 0 + render_403 return end - @user = User.current - #@student_work = @homework.student_works.where("user_id = ?",User.current.id).first - #if @student_work.nil? - @student_work = StudentWork.new - #end respond_to do |format| - format.html{ render :layout => "base_courses"} + format.html{ render :layout => "base_edu"} end end @@ -574,21 +513,21 @@ class StudentWorkController < ApplicationController @has_commit = true; #flash[:notice] = l(:notice_successful_create) #redirect_to edit_student_work_url(params[:student_work]) - respond_to do |format| - format.js - end - return - end - if params[:student_work] - @submit_result = true + # respond_to do |format| + # format.js + # end + # return + elsif params[:student_work] student_work = StudentWork.find(params[:student_work_id]) if params[:student_work_id] student_work = StudentWork.where("user_id =? and homework_common_id =? and work_status = 0", User.current.id, @homework.id).first student_work ||= StudentWork.new - student_work.name = params[:student_work][:name] == "#{@homework.name}的作品提交(可修改)" ? "#{@homework.name}的作品提交" : params[:student_work][:name] + student_work.name = @homework.name.to_s + "的作品提交" student_work.description = params[:student_work][:description] student_work.homework_common_id = @homework.id student_work.user_id = User.current.id student_work.commit_time = Time.now + #student_work.late_reason = params[:late_reason] if params[:late_reason] + student_work.group_id = @homework.homework_type == 3 ? @homework.student_works.all_commit.select("distinct group_id").count + 1 : 0 student_work.save_attachments(params[:attachments]) render_attachment_warning_if_needed(student_work) if @homework.homework_type == 3 && @homework.homework_detail_group.base_on_project == 1 @@ -600,7 +539,7 @@ class StudentWorkController < ApplicationController student_work.late_penalty = @homework.late_penalty student_work.work_status = 2 # 缺评扣分 - if @homework.homework_detail_manual.no_anon_penalty == 0 && @homework.homework_detail_manual.comment_status == 3 && @homework.anonymous_comment == 0 + if @homework.homework_detail_manual.no_anon_penalty == 0 && @homework.homework_detail_manual.comment_status == 5 && @homework.anonymous_comment == 0 work_ids = "(" + @homework.student_works.has_committed.map(&:id).join(",") + ")" all_dis_eva = StudentWorksEvaluationDistribution.where("student_work_id IN #{work_ids}") has_sw_count = all_dis_eva.select("distinct user_id").count @@ -626,14 +565,15 @@ class StudentWorkController < ApplicationController @student_work_project.student_work_id = student_work.id @student_work_project.save elsif @homework.homework_detail_group.base_on_project == 0 - stu_project = StudentWorkProject.new(:homework_common_id => @homework.id, :student_work_id => student_work.id, :project_id => student_work.project_id, :user_id => student_work.user_id, :is_leader => 1, :course_id => @homework.course_id) + stu_project = StudentWorkProject.new(:homework_common_id => @homework.id, :student_work_id => student_work.id, :project_id => 0, :user_id => student_work.user_id, :is_leader => 1, :course_id => @homework.course_id) stu_project.save end - members = params[:group_member_ids].split(',') + members = params[:user_id] for i in 1 .. members.count-1 - stu_work = StudentWork.new(:name => student_work.name, :description => student_work.description,:user_id =>members[i].to_i, :homework_common_id => @homework.id,:project_id => student_work.project_id, :late_penalty => student_work.late_penalty,:work_status => 3, :commit_time => student_work.commit_time) + stu_work = @homework.student_works.where(:user_id=> members[i].to_i).empty? ? StudentWork.new : @homework.student_works.where(:user_id=> members[i].to_i).first + stu_work.update_attributes(:name => student_work.name, :description => student_work.description, :homework_common_id => @homework.id,:project_id => student_work.project_id, :late_penalty => student_work.late_penalty,:work_status => student_work.work_status, :commit_time => Time.now, :group_id => student_work.group_id) if stu_work.save - stu_project = StudentWorkProject.new(:homework_common_id => @homework.id, :student_work_id => student_work.id, :project_id => stu_work.project_id == 0 ? -1 : stu_work.project_id, :user_id => members[i].to_i, :is_leader => 0, :course_id => @homework.course_id) + stu_project = StudentWorkProject.new(:homework_common_id => @homework.id, :student_work_id => student_work.id, :project_id => stu_work.project_id == 0 ? 0 : stu_work.project_id, :user_id => members[i].to_i, :is_leader => 0, :course_id => @homework.course_id) stu_project.save end @@ -655,33 +595,27 @@ class StudentWorkController < ApplicationController course_message.save @student_work = StudentWork.where(homework_common_id: @homework.id, user_id: User.current.id).first - respond_to do |format| - format.js - end - return end end - @submit_result = false - respond_to do |format| - format.js - end + redirect_to student_work_index_path(:homework => @homework.id) end def edit @user = User.current - if (!User.current.admin? && @homework.homework_type == 2) || @homework.end_time < Time.now #编程作业不能修改作业|| 截止日期已到不能修改作业 + if @homework.end_time < Time.now #截止日期已到不能修改作业 render_403 else + if @homework.homework_type == 3 + @commit_users = User.where(:id => @work.student_work_projects.map(&:user_id)) + end respond_to do |format| - format.html{ render :layout => "base_courses"} + format.html{ render :layout => "base_edu"} end end end def update if params[:student_work] - @submit_result = true - @work.name = params[:student_work][:name] @work.description = params[:student_work][:description] @work.save_attachments(params[:attachments]) render_attachment_warning_if_needed(@work) @@ -701,11 +635,12 @@ class StudentWorkController < ApplicationController course_statistics.update_attribute('committed_work_num', (course_statistics.committed_work_num - 1) < 0 ? 0 : (course_statistics.committed_work_num - 1)) if course_statistics course_statistics.update_attribute('un_commit_work_num', course_statistics.un_commit_work_num + 1) if course_statistics end - student_works.delete_all + student_works.update_all(:work_status => 0, :description => nil, :project_id => 0, :late_penalty => 0,:work_status => 0, :commit_time => nil) student_work_projects.delete_all - members = params[:group_member_ids].split(',') + members = params[:user_id] for i in 1 .. members.count-1 - stu_work = StudentWork.new(:name => @work.name, :description => @work.description,:user_id=> members[i].to_i, :homework_common_id => @homework.id, :project_id => @work.project_id, :late_penalty => @work.late_penalty,:work_status => 3, :commit_time => @work.commit_time) + stu_work = @homework.student_works.where(:user_id=> members[i].to_i).empty? ? StudentWork.new : @homework.student_works.where(:user_id=> members[i].to_i).first + stu_work.update_attributes(:name => @work.name, :description => @work.description, :homework_common_id => @homework.id,:project_id => @work.project_id, :late_penalty => @work.late_penalty,:work_status => @work.work_status, :commit_time => Time.now, :group_id => @work.group_id) if stu_work.save stu_project = StudentWorkProject.new(:homework_common_id => @homework.id, :student_work_id => @work.id, :project_id => stu_work.project_id == 0 ? -1 : stu_work.project_id, :user_id => members[i].to_i, :is_leader => 0, :course_id => @homework.course_id) stu_project.save @@ -724,25 +659,16 @@ class StudentWorkController < ApplicationController course_message = CourseMessage.new(:user_id =>User.current.id,:content=>"edit",:course_message_id=>@work.id,:course_id => @course.id,:course_message_type=>"StudentWork", :status => 9) #作品提交记录 course_message.save @student_work = @work - respond_to do |format| - format.js - end - return end end -=begin respond_to do |format| - format.html{redirect_to edit_student_work_url(@work)} - end -=end - @submit_result = false - respond_to do |format| - format.js + format.html{redirect_to student_work_index_path(:homework => @homework.id)} end end def show #匿评申诉消息状态更新 + @index = params[:index] if @work && !@work.student_works_scores.where("reviewer_role = 3 and appeal_status != 0").blank? score_ids = "(" + @work.student_works_scores.where("reviewer_role = 3 and appeal_status != 0").map{|score| score.id}.join(",") + ")" score_appeal_ids = StudentWorksScoresAppeal.where("student_works_score_id in #{score_ids}").blank? ? "(-1)" : "(" + StudentWorksScoresAppeal.where("student_works_score_id in #{score_ids}").map{|score_appeal| score_appeal.id}.join(",") + ")" @@ -752,15 +678,24 @@ class StudentWorkController < ApplicationController appeal_message.update_all(:viewed => true) end + @is_focus = params[:is_focus] if params[:is_focus] @score = student_work_score @work,User.current @is_teacher = User.current.allowed_to?(:as_teacher,@course) || User.current.admin? - if @homework.homework_detail_manual.comment_status == 2 && !@is_teacher && @work.user != User.current + if (@homework.homework_detail_manual.comment_status == 3 || @homework.homework_detail_manual.comment_status == 4) && !@is_teacher && @work.user != User.current @student_work_scores = @work.student_works_scores.where("user_id = #{User.current.id} and reviewer_role = 3").order("updated_at desc") else @student_work_scores = student_work_score_record(@work) end + if @homework.homework_type == 3 && @work.work_status != 0 + student_works = @homework.student_works.where("group_id = #{@work.group_id} and user_id != #{@work.user_id}") + @team_work = User.where(:id => student_works.map(&:user_id)) + elsif @homework.homework_type == 4 + @shixun = @homework.homework_commons_shixuns.shixun + @myshixun = Myshixun.find @work.myshixun_id + end respond_to do |format| format.js + format.html{render :layout => 'base_edu'} end end @@ -770,6 +705,7 @@ class StudentWorkController < ApplicationController user_ids = pros.empty? ? "(-1)" : "(" + pros.map{|stu|stu.user_id}.join(",") + ")" student_works = @homework.student_works.where("user_id in #{user_ids}") + #更新CourseHomeworkStatistics中每个学生的未交作品数、已交作品数、迟交作品数 student_works.each do |sw| course_statistics = CourseHomeworkStatistics.find_by_course_id_and_user_id(@homework.course_id, sw.user_id) @@ -779,7 +715,7 @@ class StudentWorkController < ApplicationController course_statistics.update_attribute('committed_work_num', (course_statistics.committed_work_num - 1) < 0 ? 0 : (course_statistics.committed_work_num - 1)) if course_statistics course_statistics.update_attribute('un_commit_work_num', course_statistics.un_commit_work_num + 1) if course_statistics end - student_works.delete_all + student_works.update_all(:work_status => 0, :description => nil, :project_id => 0, :late_penalty => 0,:work_status => 0, :commit_time => nil) pros.delete_all project = @work.student_work_projects.where("is_leader = 1").first @@ -788,7 +724,9 @@ class StudentWorkController < ApplicationController else project.destroy end - @work.destroy + + @homework.student_works.all_commit.where("group_id > #{@work.group_id}").update_all("group_id = group_id - 1") + @work.update_all(:work_status => 0, :description => nil, :project_id => 0, :late_penalty => 0,:work_status => 0, :commit_time => nil) else #更新CourseHomeworkStatistics中学生的已交作品数、迟交作品数 course_statistics = CourseHomeworkStatistics.find_by_course_id_and_user_id(@homework.course_id, @work.user_id) @@ -900,12 +838,57 @@ class StudentWorkController < ApplicationController end end + def relate_myshixun + myshixun = Myshixun.where(:shixun_id => @homework.homework_commons_shixuns.shixun_id, :user_id => User.current.id).first + if myshixun + work = @homework.student_works.where(:user_id => User.current.id).first + work = work || StudentWork.new(:homework_common_id => @homework.id, :user_id => User.current.id, :work_status => 0) + if work.work_status == 0 + work.myshixun_id = myshixun.id + work.commit_time = Time.now + if @homework.end_time < Time.now + work.late_penalty = @homework.late_penalty + work.work_status = 2 + + #更新CourseHomeworkStatistics中学生的迟交作品数 + course_statistics = CourseHomeworkStatistics.find_by_course_id_and_user_id(@homework.course_id, User.current.id) + course_statistics.update_attribute('late_commit_work_num', course_statistics.late_commit_work_num + 1) if course_statistics + else + work.late_penalty = 0 + work.work_status = 1 + end + if work.save + #更新CourseHomeworkStatistics中学生的未交作品数、已交作品数 + course_statistics = CourseHomeworkStatistics.find_by_course_id_and_user_id(@homework.course_id, User.current.id) + course_statistics.update_attribute('committed_work_num', course_statistics.committed_work_num + 1) if course_statistics + course_statistics.update_attribute('un_commit_work_num', (course_statistics.un_commit_work_num - 1) < 0 ? 0 : (course_statistics.un_commit_work_num - 1)) if course_statistics + + @homework.update_column(:updated_at, Time.now) + update_course_activity(@homework.class,@homework.id) + update_user_activity(@homework.class,@homework.id) + update_org_activity(@homework.class,@homework.id) + + course_message = CourseMessage.new(:user_id =>User.current.id,:content=>"new",:course_message_id=>work.id,:course_id => @course.id,:course_message_type=>"StudentWork", :status => 9) #作品提交记录 + course_message.save + @status = 1 + end + else + @status = 2 + end + else + @status = 0 + end + end + #添加评分,已评分则为修改评分 def add_score @is_last = params[:is_last] == "true" @is_teacher = User.current.allowed_to?(:as_teacher,@course) || User.current.admin? #老师、教辅可以随时评分,学生只能在匿评作业的匿评阶段进行评分 - render_403 and return unless @is_teacher || @homework.homework_detail_manual.comment_status == 2 + unless @is_teacher || @homework.homework_detail_manual.comment_status == 3 + render_403 + return + end @score = student_work_score @work,User.current #@score.comment = params[:new_form][:user_message] if params[:new_form] && params[:new_form][:user_message] && params[:new_form][:user_message] != "" #@score.score = params[:score] if params[:score] @@ -928,6 +911,11 @@ class StudentWorkController < ApplicationController @new_score.student_work_id = @work.id if @is_teacher && !@new_score.score.nil? && @work.work_status == 0 @work.update_attributes(:work_status => 1, :commit_time => Time.now) + if @homework.homework_type == 3 + @work.update_attributes(:group_id => @homework.student_works.all_commit.select("distinct group_id").count + 1) + stu_project = StudentWorkProject.new(:homework_common_id => @homework.id, :student_work_id => @work.id, :project_id => 0, :user_id => @work.user_id, :is_leader => 1, :course_id => @homework.course_id) + stu_project.save + end #更新CourseHomeworkStatistics中学生的已交作品数、未交作品数 course_statistics = CourseHomeworkStatistics.find_by_course_id_and_user_id(@homework.course_id, @work.user_id) course_statistics.update_attribute('committed_work_num', course_statistics.committed_work_num + 1) if course_statistics @@ -963,7 +951,7 @@ class StudentWorkController < ApplicationController case @new_score.reviewer_role when 1 #教师评分:最后一个教师评分为最终评分 @work.teacher_score = @new_score.score - if @is_group_leader && params[:same_score] + if params[:same_score] add_score_to_member @work, @homework, @new_score end when 2 #教辅评分 教辅评分显示平均分 @@ -974,7 +962,7 @@ class StudentWorkController < ApplicationController else @work.teaching_asistant_score = @new_score.score end - if @is_group_leader && params[:same_score] + if params[:same_score] add_score_to_member @work, @homework, @new_score end when 3 #学生评分 学生评分显示平均分 @@ -997,8 +985,13 @@ class StudentWorkController < ApplicationController update_org_activity(@homework.class,@homework.id) if @work.save @work = @homework.student_works.select("student_works.*,student_works.work_score as score").where(:id => @work.id).first - @count = @homework.student_works.has_committed.count - @student_work_scores = student_work_score_record @work + @score = @new_score + if @homework.homework_detail_manual.comment_status == 3 && !@is_teacher && @work.user != User.current + @student_work_scores = @work.student_works_scores.where("user_id = #{User.current.id} and reviewer_role = 3").order("updated_at desc") + else + @student_work_scores = student_work_score_record(@work) + end + @count = @student_work_scores.count respond_to do |format| format.js end @@ -1022,6 +1015,14 @@ class StudentWorkController < ApplicationController end end + # 删除教师/教辅的评分记录 + def destroy_score + @score = @work.student_works_scores.where(:id => params[:score_id]).first + if @score + @score.destroy + end + end + #删除评分的回复 def destroy_score_reply @jour = JournalsForMessage.find params[:jour_id] @@ -1275,6 +1276,27 @@ class StudentWorkController < ApplicationController @is_last = params[:is_last] end + # 删除评论记录,最新的一条不删除 + def delete_score_comment + begin + student_work_score = StudentWorksScore.where(:id => params[:score_id]).first + @work = student_work_score.student_work + @count = @work.student_works_scores.count + student_work_id = student_work_score.student_work_id + can_delete = User.current.allowed_to?(:as_teacher,@course) || User.current.admin? || User.current.id == student_work_score.user_id + unless can_delete + render_403 + return + end + student_work_score.destroy + respond_to do |format| + format.html{redirect_to student_work_path(student_work_id)} + end + rescue Exception => e + logger.error("###{e}") + end + end + def deal_appeal_score @student_work_score = StudentWorksScore.where("id = #{params[:score_id].to_i}").first @is_last = params[:is_last] == "true" ? true : false @@ -1369,10 +1391,7 @@ class StudentWorkController < ApplicationController CourseMessage.create(:user_id => student_work.homework_common.user_id, :course_id => student_work.homework_common.course_id, :viewed => false,:course_message_id=>attachment.container_id,:course_message_type=>'StudentWork',:status=>2) end @work.update_attributes(:re_commit => 1) - respond_to do |format| - format.js - end - @homework = @work.homework_common + redirect_to student_work_path(@work) end def new_student_work_project @@ -1445,16 +1464,19 @@ class StudentWorkController < ApplicationController unless params[:name].nil? name = params[:name] end - if @homework.homework_detail_group.base_on_project == 0 - all_student_ids = "(" + @homework.course.student.map{|student| student.student_id}.join(",") + ")" - else - pro = Project.find @homework.student_work_projects.where("user_id=?",User.current.id).first.project_id - all_student_ids = "(" + pro.members.map{|member| member.user_id}.join(",") + ")" - end - all_students = User.where("id in #{all_student_ids}") - student_work_id = @homework.student_work_projects.where("user_id=? and student_work_id is not null",User.current.id).first.nil? ? -1 : @homework.student_work_projects.where("user_id=?",User.current.id).first.student_work_id - @commit_student_ids = @homework.student_works.where("id != #{student_work_id}").map{|student| student.user_id} - @users = searchstudent_by_name all_students,name + + student_works = @homework.student_works.where("work_status != 0") + com_student_ids = student_works.blank? ? '(-1)' : '(' + student_works.map(&:user_id).join(",") + ')' + @users = User.includes(:user_extensions).where(:id => @course.student.where("student_id not in #{com_student_ids} and student_id != #{User.current.id}").map(&:student_id)) + @users = searchstudent_by_name @users,name + + @limit = 10 + @page = (params['page'] || 1).to_i + @user_count = @users.count + @user_pages = Paginator.new @user_count, @limit, params['page'] || 1 + @offset ||= @user_pages.offset + @users = paginateHelper @users,@limit + respond_to do |format| format.js end @@ -1590,8 +1612,7 @@ class StudentWorkController < ApplicationController select_homework = homeworks else name = name.downcase - select_homework = homeworks.select{ |homework| - homework.user[:login].to_s.downcase.include?(name) || homework.user.user_extensions[:student_id].to_s.downcase.include?(name) || (homework.user[:lastname].to_s.downcase + homework.user[:firstname].to_s.downcase).include?(name) + select_homework = homeworks.select{ |homework| homework.user.user_extensions[:student_id].to_s.downcase.include?(name) || (homework.user[:lastname].to_s.downcase + homework.user[:firstname].to_s.downcase).include?(name) } end select_homework @@ -1758,7 +1779,7 @@ class StudentWorkController < ApplicationController student_work = StudentWork.where(homework_common_id: @homework.id, user_id: User.current.id, is_test: is_test).first if student_work.nil? @homework.student_works.build( - name: params[:title], + name: @homework.name.to_s + "的作品提交", description: params[:src], user_id: User.current.id, is_test: is_test @@ -1816,129 +1837,4 @@ class StudentWorkController < ApplicationController end JSON.parse(res.body) end - - #成绩计算 - def set_final_score homework,student_work - if homework && homework.homework_detail_manual - if homework.homework_type != 2 #非编程作业 - if homework.teacher_priority == 1 #教师优先 - if student_work.teacher_score - student_work.final_score = student_work.teacher_score - student_work.work_score = student_work.teacher_score - student_work.absence_penalty - student_work.late_penalty - else - if student_work.teaching_asistant_score.nil? - student_work.final_score = student_work.student_score - elsif student_work.student_score.nil? - student_work.final_score = student_work.teaching_asistant_score - else - ta_proportion = homework.homework_detail_manual.ta_proportion - final_ta_score = BigDecimal.new("#{student_work.teaching_asistant_score}") * BigDecimal.new("#{ta_proportion}") - final_s_score = BigDecimal.new("#{student_work.student_score}") * (BigDecimal.new('1.0') - BigDecimal.new("#{ta_proportion}")) - final_score = final_ta_score + final_s_score - student_work.final_score = format("%.2f",final_score.to_f) - end - if student_work.final_score - score = student_work.final_score - student_work.absence_penalty - student_work.late_penalty - student_work.appeal_penalty - student_work.work_score = format("%.2f",(score < 0 ? 0 : score).to_f) if score - else - student_work.work_score = nil - end - end - else #不考虑教师评分 - if student_work.teaching_asistant_score.nil? - student_work.final_score = student_work.student_score - elsif student_work.student_score.nil? - student_work.final_score = student_work.teaching_asistant_score - else - ta_proportion = homework.homework_detail_manual.ta_proportion - final_ta_score = BigDecimal.new("#{student_work.teaching_asistant_score}") * BigDecimal.new("#{ta_proportion}") - final_s_score = BigDecimal.new("#{student_work.student_score}") * (BigDecimal.new('1.0') - BigDecimal.new("#{ta_proportion}")) - final_score = final_ta_score + final_s_score - student_work.final_score = format("%.2f",final_score.to_f) - end - if student_work.final_score - score = student_work.final_score - student_work.absence_penalty - student_work.late_penalty - student_work.appeal_penalty - student_work.work_score = format("%.2f",(score < 0 ? 0 : score).to_f) if score - else - student_work.work_score = nil - end - end - elsif homework.homework_type == 2 && homework.homework_detail_programing #编程作业-----设定:系统评分必定不为空 - if homework.teacher_priority == 1 #教师优先 - if student_work.teacher_score - student_work.final_score = student_work.teacher_score - student_work.work_score = student_work.teacher_score - student_work.absence_penalty - student_work.late_penalty - student_work.appeal_penalty - else - if student_work.teaching_asistant_score.nil? #教辅未评分 - if student_work.student_score.nil? - student_work.final_score = student_work.system_score - else - ta_proportion = homework.homework_detail_programing.ta_proportion + homework.homework_detail_manual.ta_proportion / 2 - final_sy_score = BigDecimal.new("#{student_work.system_score || 0}") * BigDecimal.new("#{ta_proportion}") - final_st_score = BigDecimal.new("#{student_work.student_score}") * (BigDecimal.new('1.0') - BigDecimal.new("#{ta_proportion}")) - final_score = final_sy_score + final_st_score - student_work.final_score = format("%.2f",final_score.to_f) - end - elsif student_work.student_score.nil? #学生未评分 - if student_work.teaching_asistant_score.nil? - student_work.final_score = student_work.system_score - else - ta_proportion = homework.homework_detail_programing.ta_proportion + (1.0 - homework.homework_detail_manual.ta_proportion - homework.homework_detail_programing.ta_proportion) / 2 - final_sy_score = BigDecimal.new("#{student_work.system_score || 0}") * BigDecimal.new("#{ta_proportion}") - final_ts_score = BigDecimal.new("#{student_work.teaching_asistant_score}") * (BigDecimal.new('1.0') - BigDecimal.new("#{ta_proportion}")) - final_score = final_sy_score + final_ts_score - student_work.final_score = format("%.2f",final_score.to_f) - end - else - final_sy_score = BigDecimal.new("#{student_work.system_score || 0}") * BigDecimal.new("#{homework.homework_detail_programing.ta_proportion}") - final_ts_score = BigDecimal.new("#{student_work.teaching_asistant_score}") * BigDecimal.new("#{homework.homework_detail_manual.ta_proportion}") - final_st_score = BigDecimal.new("#{student_work.student_score}") * (BigDecimal.new('1.0') - BigDecimal.new("#{homework.homework_detail_programing.ta_proportion}") - BigDecimal.new("#{homework.homework_detail_manual.ta_proportion}")) - final_score = final_sy_score + final_ts_score + final_st_score - student_work.final_score = format("%.2f",final_score.to_f) - end - if student_work.final_score - score = student_work.final_score - student_work.absence_penalty - student_work.late_penalty - student_work.appeal_penalty - student_work.work_score = format("%.2f",(score < 0 ? 0 : score).to_f) if score - else - student_work.work_score = nil - end - end - else #不考虑教师评分 - if student_work.teaching_asistant_score.nil? #教辅未评分 - if student_work.student_score.nil? - student_work.final_score = student_work.system_score - else - ta_proportion = homework.homework_detail_programing.ta_proportion + homework.homework_detail_manual.ta_proportion / 2 - final_sy_score = BigDecimal.new("#{student_work.system_score || 0}") * BigDecimal.new("#{ta_proportion}") - final_st_score = BigDecimal.new("#{student_work.student_score}") * (BigDecimal.new('1.0') - BigDecimal.new("#{ta_proportion}")) - final_score = final_sy_score + final_st_score - student_work.final_score = format("%.2f",final_score.to_f) - end - elsif student_work.student_score.nil? #学生未评分 - if student_work.teaching_asistant_score.nil? - student_work.final_score = student_work.system_score - else - ta_proportion = homework.homework_detail_programing.ta_proportion + (1.0 - homework.homework_detail_manual.ta_proportion - homework.homework_detail_programing.ta_proportion) / 2 - final_sy_score = BigDecimal.new("#{student_work.system_score || 0}") * BigDecimal.new("#{ta_proportion}") - final_ts_score = BigDecimal.new("#{student_work.teaching_asistant_score}") * (BigDecimal.new('1.0') - BigDecimal.new("#{ta_proportion}")) - final_score = final_sy_score + final_ts_score - student_work.final_score = format("%.2f",final_score.to_f) - end - else - final_sy_score = BigDecimal.new("#{student_work.system_score || 0}") * BigDecimal.new("#{homework.homework_detail_programing.ta_proportion}") - final_ts_score = BigDecimal.new("#{student_work.teaching_asistant_score}") * BigDecimal.new("#{homework.homework_detail_manual.ta_proportion}") - final_st_score = BigDecimal.new("#{student_work.student_score}") * (BigDecimal.new('1.0') - BigDecimal.new("#{homework.homework_detail_programing.ta_proportion}") - BigDecimal.new("#{homework.homework_detail_manual.ta_proportion}")) - final_score = final_sy_score + final_ts_score + final_st_score - student_work.final_score = format("%.2f",final_score.to_f) - end - if student_work.final_score - score = student_work.final_score - student_work.absence_penalty - student_work.late_penalty - student_work.appeal_penalty - student_work.work_score = format("%.2f",(score < 0 ? 0 : score).to_f) if score - else - student_work.work_score = nil - end - end - end - end - end end diff --git a/app/controllers/subjects_controller.rb b/app/controllers/subjects_controller.rb new file mode 100644 index 000000000..b73f6ab75 --- /dev/null +++ b/app/controllers/subjects_controller.rb @@ -0,0 +1,99 @@ +# encoding: utf-8 +class SubjectsController < ApplicationController + layout 'base_subject' + before_filter :require_login + before_filter :check_authentication + before_filter :find_subject, :except => [:index, :create_subject, :new_subject, :append_to_stage] + + include ApplicationHelper + + def index + @order = params[:order] || "created_at" + bsort = params[:sort] || "desc" + @sort = bsort == "desc" ? "asc" : "desc" + search = params[:search] + ids = Subject.find_by_sql("select group_concat(id) as allId from subjects where id in (SELECT distinct(subject_id) FROM `stages`)") + @subjects = Subject.where(:id => ids[0].allId.nil? ? "-1" : ids[0].allId.split(",")).reorder("#{@order} #{bsort}") + @subject_created_count = Subject.find_by_sql("select count(*) as count from subjects where id in (SELECT distinct(subject_id) FROM `stages`) and user_id=#{User.current.id};").first.try(:count) + @subjects_all_count = @subjects.count + #@subjects = Subject.where("name like ?", "%#{search}%").reorder("#{@order} #{@sort}") + @subjects_count = @subjects.count + @limit = 16 + @is_remote = true + @subject_pages = Paginator.new @subjects_count, @limit, params['page'] || 1 + @offset ||= @subject_pages.offset + @subjects = paginateHelper @subjects, @limit + render :layout => "base_edu" + end + + def show + @stages = @subject.stages + end + + def new_subject + if Course.where(:tea_id => User.current.id).count > 0 + @status = 1 + @course_lists = CourseList.where(:id => ShixunMajorCourse.where(:shixun_id => Shixun.where(:user_id => User.current.id).map(&:id)).map(&:course_list_id)) + else + @status = 0 + end + respond_to do |format| + format.js + end + end + + def create_subject + if params[:course_list_id] + course = CourseList.find params[:course_list_id] + if course + subject = Subject.create(:name => course.name, :user_id => User.current.id, :visits => 0, :status => 0, :course_list_id => course.id) + end + end + redirect_to subject_path(subject) + end + + def choose_subject_shixun + course_list = @subject.course_list + @shixuns = Shixun.where(:user_id => User.current.id, :status => [0, 1, 2], :id => course_list.shixun_major_courses.map(&:shixun_id)) + @shixuns_count = @shixuns.count + @limit = 8 + @shixuns_pages = Paginator.new @shixuns_count, @limit, params['page'] || 1 + @offset ||= @shixuns_pages.offset + @shixuns = paginateHelper @shixuns, @limit + end + + def append_to_stage + @shixuns = Shixun.where(:id => params[:shixun_id]) + end + + def publish + @subject.update_attributes(:status => 1) + apply = ApplyAction.where(:container_type => "ApplySubject", :container_id => @subject.id).order("created_at desc").first + if apply && apply.status == 0 + @status = 0 + else + ApplyAction.create(:container_type => "ApplySubject", :container_id => @subject.id, :user_id => User.current.id, :status => 0) + notes = User.current.show_name.to_s + " 申请发布课程实训:#{@subject.name}" + JournalsForMessage.create(:jour_id => 1, :jour_type => 'Principal', :user_id => User.current.id, :notes => notes, :private => 1, :reply_id => 0) + @status = 1 + end + end + + def cancel_publish + apply = ApplyAction.where(:container_type => "ApplySubject", :container_id => @subject.id).order("created_at desc").first + if apply && apply.status == 0 + apply.update_attributes(:status => 3) + @subject.update_column('status', 0) + end + redirect_to subject_path(@subject) + end + + private + # Find subject of id params[:id] + def find_subject + @subject = Subject.find_by_id(params[:id]) + render_404 if @subject.nil? + rescue ActiveRecord::RecordNotFound + render_404 + end +end diff --git a/app/controllers/syllabuses_controller.rb b/app/controllers/syllabuses_controller.rb index fc51536ea..fae83cdc1 100644 --- a/app/controllers/syllabuses_controller.rb +++ b/app/controllers/syllabuses_controller.rb @@ -5,18 +5,45 @@ class SyllabusesController < ApplicationController include AttachmentsHelper include CoursesHelper include SyllabusesHelper - + include UsersHelper before_filter :is_logged, :only => [:index, :show, :edit, :new, :update, :destroy, :delete_syllabus, :syllabus_resources, :syllabus_homeworks] + before_filter :check_authentication before_filter :find_syllabus, :only => [:show, :edit, :update, :destroy, :syllabus_courselist, :edit_syllabus_eng_name, :edit_syllabus_title, :update_base_info, :delete_syllabus, :delete_des, :members, :update_des, :edit_ref, :update_ref, :add_sy_member_alert, :search_not_sy_member, :syllabus_resources, :syllabus_homeworks, :send_homeworks_to_course, :choose_user_course, :send_resources_to_course, :send_r_and_h_to_course] + def index + @status = params[:type].nil? ? 1 : params[:type].to_i # 1表示正在进行,2表示已结束 + user = User.current - @syllabuses = user.syllabuses + @my_syllabuses = user.syllabuses + + archive_ids = Course.where("tea_id = #{user.id} and is_delete = 1 and syllabus_id is NOT NULL").blank? ? "(-1)" : "(" + Course.where("tea_id = #{user.id} and is_delete = 1 and syllabus_id is NOT NULL").map{|course| course.syllabus_id}.join(",") + ")" + @archive_syllabuses = Syllabus.where("id in #{archive_ids}") + + sy_courses = user.courses.visible.not_deleted + syllabus_ids = sy_courses.empty? ? '(-1)' : "(" + sy_courses.map{|course| !course.syllabus_id.nil? && course.syllabus_id}.join(",") + ")" + syllabus_members = SyllabusMember.where("user_id = #{user.id}") + syllabus_member_ids = syllabus_members.empty? ? "(-1)" : "(" + syllabus_members.map{|syl_mem| syl_mem.syllabus_id}.join(',') + ")" + @join_syllabuses = Syllabus.where("(id in #{syllabus_ids} or id in #{syllabus_member_ids}) and user_id != #{user.id}") + + @my_syllabuses = syllabus_course_list_sort @my_syllabuses + @join_syllabuses = syllabus_course_list_sort @join_syllabuses + @my_syllabuses = @my_syllabuses.sort{|x,y| y[:last_update] <=> x[:last_update]} + @join_syllabuses = @join_syllabuses.sort{|x,y| y[:last_update] <=> x[:last_update]} + @is_course = 1 + + respond_to do |format| + format.html{ render :layout => 'base_edu'} + format.js + end end def show - @is_syllabus_member = User.current.admin? || @syllabus.syllabus_members.map{|sm| sm.user_id}.include?(User.current.id) + @is_syllabus_teacher = User.current.admin? || @syllabus.syllabus_members.map{|sm| sm.user_id}.include?(User.current.id) || !@syllabus.courses.not_deleted_not_end.select { |course| User.current.has_teacher_role(course)}.blank? + @is_syllabus_member = !@syllabus.courses.not_deleted_not_end.select { |course| User.current.member_of_course?(course)}.blank? + @is_syllabus_admin = User.current.admin? || @syllabus.syllabus_members.map{|sm| sm.user_id}.include?(User.current.id) + @is_authen_teacher = User.current.authentication && User.current.user_extensions.try(:identity) != 1 @reference_materials = @syllabus.reference_materials @members = @syllabus.syllabus_members.includes(:user => {:user_extensions => []}).order("rank asc") @courses = @syllabus.courses.where("is_delete = 0 and is_end = 0").select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS ca_update").order("ca_update desc") @@ -42,6 +69,7 @@ class SyllabusesController < ApplicationController @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.major_id = params[:major_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 @@ -89,6 +117,7 @@ class SyllabusesController < ApplicationController @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.major_id = params[:major_id].to_i @syllabus.syllabus_type = params[:syllabus_type].to_i if @syllabus.save if title != params[:title].to_s.strip @@ -123,7 +152,7 @@ class SyllabusesController < ApplicationController sy_update_record = SyllabusUpdateRecord.new(:property => 2, :user_id => User.current.id) @syllabus.syllabus_update_records << sy_update_record @reference_materials = @syllabus.reference_materials - @is_syllabus_member = User.current.admin? || @syllabus.syllabus_members.map{|sm| sm.user_id}.include?(User.current.id) + @is_syllabus_admin = User.current.admin? || @syllabus.syllabus_members.map{|sm| sm.user_id}.include?(User.current.id) respond_to do |format| format.js end @@ -159,6 +188,10 @@ class SyllabusesController < ApplicationController end def syllabus_resources + @is_syllabus_teacher = User.current.admin? || @syllabus.syllabus_members.map{|sm| sm.user_id}.include?(User.current.id) || !@syllabus.courses.not_deleted_not_end.select { |course| User.current.has_teacher_role(course)}.blank? + @is_syllabus_member = !@syllabus.courses.not_deleted_not_end.select { |course| User.current.member_of_course?(course)}.blank? + @is_syllabus_admin = User.current.admin? || @syllabus.syllabus_members.map{|sm| sm.user_id}.include?(User.current.id) + @is_authen_teacher = User.current.authentication && User.current.user_extensions.try(:identity) != 1 @order, @r_sort = params[:order] || "created_at", params[:sort] || "asc" @sort = @r_sort == "desc" ? "asc" : "desc" @resources = sy_resources @syllabus @@ -170,10 +203,16 @@ class SyllabusesController < ApplicationController @resource_count = @resources.count @public_resource_count = @resources.where(:is_public => 1).count @private_resource_count = @resources.where(:is_public => 0).count + + if !(@is_syllabus_admin || @is_syllabus_member) + @resources = @resources.where(:is_public => 1) + end + #分页 + @page_resource_count = @resources.count @limit = 10 @is_remote = true - @resource_pages = Paginator.new @resource_count, @limit, params['page'] || 1 + @resource_pages = Paginator.new @page_resource_count, @limit, params['page'] || 1 @offset ||= @resource_pages.offset @resources = paginateHelper @resources,@limit respond_to do |format| @@ -182,16 +221,25 @@ class SyllabusesController < ApplicationController end def syllabus_homeworks + @is_syllabus_teacher = User.current.admin? || @syllabus.syllabus_members.map{|sm| sm.user_id}.include?(User.current.id) || !@syllabus.courses.not_deleted_not_end.select { |course| User.current.has_teacher_role(course)}.blank? + @is_syllabus_member = !@syllabus.courses.not_deleted_not_end.select { |course| User.current.member_of_course?(course)}.blank? + @is_syllabus_admin = User.current.admin? || @syllabus.syllabus_members.map{|sm| sm.user_id}.include?(User.current.id) + @is_authen_teacher = User.current.authentication && User.current.user_extensions.try(:identity) != 1 @order, @r_sort = params[:order] || "created_at", params[:sort] || "asc" @sort = @r_sort == "desc" ? "asc" : "desc" - @homeworks = (sy_homeworks @syllabus).order("#{@order} #{@sort}") + @homeworks = @syllabus.homework_banks.order("#{@order} #{@sort}") @homework_count = @homeworks.count @public_homework_count = @homeworks.where(:is_public => 1).count @private_homework_count = @homeworks.where(:is_public => 0).count + if !(@is_syllabus_admin || @is_syllabus_member) + @homeworks = @homeworks.where(:is_public => 1) + end + + @page_homework_count = @homeworks.count @limit = 10 @is_remote = true - @homework_pages = Paginator.new @homework_count, @limit, params['page'] || 1 + @homework_pages = Paginator.new @page_homework_count, @limit, params['page'] || 1 @offset ||= @homework_pages.offset @homeworks = paginateHelper @homeworks, @limit respond_to do |format| @@ -202,9 +250,9 @@ class SyllabusesController < ApplicationController def choose_user_course if !params[:search].nil? search = "%#{params[:search].to_s.strip.downcase}%" - @courses = User.current.courses.where("is_delete = 0 and is_end = 0 and (#{Course.table_name}.id = #{params[:search].to_i } or #{Course.table_name}.name like :p)",:p=>search).select { |course| User.current.allowed_to?(:as_teacher,course)} + @courses = User.current.courses.where("is_delete = 0 and is_end = 0 and (#{Course.table_name}.id = #{params[:search].to_i } or #{Course.table_name}.name like :p)",:p=>search).select { |course| User.current.has_teacher_role(course)} else - @courses = User.current.courses.where("is_delete = 0 and is_end = 0").select { |course| User.current.allowed_to?(:as_teacher,course)} + @courses = User.current.courses.where("is_delete = 0 and is_end = 0").select { |course| User.current.has_teacher_role(course)} end @resource_ids = params[:check_resource] if params[:check_resource] @homework_ids = params[:check_homework] if params[:check_homework] @@ -240,7 +288,7 @@ class SyllabusesController < ApplicationController course = Course.find params[:course_id] if course resources = sy_resources @syllabus - homeworks = (sy_homeworks @syllabus).order("#{@order} #{@sort}") + homeworks = @syllabus.homework_banks.order("#{@order} #{@sort}") ActiveRecord::Base.transaction do begin @@ -279,7 +327,7 @@ class SyllabusesController < ApplicationController def destroy if @syllabus && @syllabus.courses.not_deleted.empty? @syllabus.destroy - redirect_to user_courselist_user_path(User.current) + redirect_to syllabuses_path() end end @@ -404,6 +452,23 @@ class SyllabusesController < ApplicationController render :json =>data end + def get_major + data = {result:0,options:[]} + if params[:first_level_discipline_id] + if Major.where(:first_level_discipline_id => params[:first_level_discipline_id].to_i).count > 0 + data[:result] = 1 + Major.where(:first_level_discipline_id => params[:first_level_discipline_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 14af87c5c..795486167 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -35,6 +35,8 @@ class UsersController < ApplicationController # before_filter :can_show_course, :only => [:user_courses,:user_homeworks] + before_filter :check_authentication + before_filter :find_user, :only => [:user_fanslist, :user_watchlist, :show, :edit, :update, :destroy, :edit_membership, :user_courses, :unsolved_issues_list, :unfinished_homework_list, :user_manage_homeworks, :unfinished_poll_list, :user_homeworks,:student_homeworks, :destroy_membership, :user_activities, :user_projects, :user_newfeedback, :user_comments, :update_message_viewed, :anonymous_evaluation_list,:unfinished_test_list, :watch_contests, :info, :watch_projects, :show_score, :topic_score_index, :project_score_index, :user_receive_homeworks, @@ -43,7 +45,7 @@ class UsersController < ApplicationController :user_courses4show,:user_projects4show,:user_contests4show,:user_course_activities,:user_project_activities,:user_feedback4show,:user_visitorlist,:user_messages,:edit_brief_introduction, :user_import_homeworks,:user_search_homeworks,:user_import_resource, :user_system_messages,:choose_user_course,:user_courselist,:user_projectlist,:sort_syllabus_list, :sort_project_list,:my_homeworks,:manage_or_receive_homeworks,:search_m_r_homeworks, :cancel_or_collect,:expand_courses,:homepage, :user_issues, :course_community, :project_community, :contest_community, - :user_shixuns] + :shixuns, :user_show_course_list, :shixuns_or_courses_filter] before_filter :auth_user_extension, only: :show before_filter :show_system_message, :only => [:show] #before_filter :rest_user_score, only: :show @@ -354,6 +356,7 @@ class UsersController < ApplicationController case @type when 'HomeworkCommon' @root = HomeworkCommon.find reply.jour_id + @homework = @root options = {:notes => params[:reply_message], :reply_id => reply.user_id,:user_id => User.current.id,:m_parent_id => params[:reply_id].to_i,:m_reply_id => params[:reply_id].to_i, :root_id => reply.root_id} comment = HomeworkCommon.add_homework_jour(User.current, params[:reply_message], reply.jour_id, reply.root_id, options) @root.update_column('updated_at', Time.now) @@ -500,9 +503,9 @@ class UsersController < ApplicationController # 初始化/更新 点击按钮时间, 24小时内显示系统消息 update_onclick_time # 全部设为已读 - # if params[:viewed] == "all" + # if params[:viewed] == "all" # update_message_viewed(@user) - # end + # end # @new_message_count = forge_querys.count + forum_querys.count + course_querys.count + user_querys.count courses = @user.courses.where("is_delete = 1") course_ids = courses.empty? ? "(-1)" : "(" + courses.map{|course| course.id}.join(",") + ")" @@ -584,24 +587,24 @@ class UsersController < ApplicationController # 消息设置为已读 def update_message_viewed if User.current.id == @user.id - course_querys = CourseMessage.where("user_id =? and viewed =?", @user.id, 0) - forge_querys = ForgeMessage.where("user_id =? and viewed =?", @user.id, 0) - user_querys = UserFeedbackMessage.where("user_id =? and viewed =?", @user.id, 0) - forum_querys = MemoMessage.where("user_id =? and viewed =?", @user.id, 0) - org_querys = OrgMessage.where("user_id=? and viewed=0", @user.id) - at_querys = AtMessage.where("user_id=? and viewed=0", @user.id) - contest_querys = ContestMessage.where(:user_id => @user.id, :viewed => 0) - blog_querys = BlogMessage.where(:user_id => @user.id, :viewed => 0) - applied_querys = AppliedMessage.where("user_id=? and viewed =?", @user.id, 0) - course_querys.update_all(:viewed => true) unless course_querys.nil? - forge_querys.update_all(:viewed => true) unless forge_querys.nil? - user_querys.update_all(:viewed => true) unless user_querys.nil? - forum_querys.update_all(:viewed => true) unless forum_querys.nil? - org_querys.update_all(:viewed => true) unless org_querys.nil? - at_querys.update_all(:viewed => true) unless at_querys.nil? - contest_querys.update_all(:viewed => true) unless contest_querys.nil? - blog_querys.update_all(:viewed => true) unless blog_querys.nil? - applied_querys.update_all(:viewed => true) unless applied_querys.nil? + course_querys = CourseMessage.where("user_id =? and viewed =?", @user.id, 0) + forge_querys = ForgeMessage.where("user_id =? and viewed =?", @user.id, 0) + user_querys = UserFeedbackMessage.where("user_id =? and viewed =?", @user.id, 0) + forum_querys = MemoMessage.where("user_id =? and viewed =?", @user.id, 0) + org_querys = OrgMessage.where("user_id=? and viewed=0", @user.id) + at_querys = AtMessage.where("user_id=? and viewed=0", @user.id) + contest_querys = ContestMessage.where(:user_id => @user.id, :viewed => 0) + blog_querys = BlogMessage.where(:user_id => @user.id, :viewed => 0) + applied_querys = AppliedMessage.where("user_id=? and viewed =?", @user.id, 0) + course_querys.update_all(:viewed => true) unless course_querys.nil? + forge_querys.update_all(:viewed => true) unless forge_querys.nil? + user_querys.update_all(:viewed => true) unless user_querys.nil? + forum_querys.update_all(:viewed => true) unless forum_querys.nil? + org_querys.update_all(:viewed => true) unless org_querys.nil? + at_querys.update_all(:viewed => true) unless at_querys.nil? + contest_querys.update_all(:viewed => true) unless contest_querys.nil? + blog_querys.update_all(:viewed => true) unless blog_querys.nil? + applied_querys.update_all(:viewed => true) unless applied_querys.nil? end redirect_to user_path(@user) end @@ -652,11 +655,72 @@ class UsersController < ApplicationController end end - # 我发布的实训 - def shixuns_zone - @shixuns = Shixun.where(:user_id => User.current) + # params: index 1 课程 / 2 实训 + # search 搜索关键字 + def search_shixuns_or_courses + @index = params[:index].to_i + @search = params[:search] + @limit = 16 + if 1 == @index + @course_result = Course.where("is_end = 0 and is_delete = 0 and name like '%#{@search}%'").order("created_at desc") + @course_result_count = @course_result.count + @course_result_pages = Paginator.new @course_result_count, @limit, params['page'] || 1 + @offset ||= @course_result_pages.offset + @course_result = paginateHelper @course_result, @limit + else + @shixuns_result = Shixun.where(:status => [2,3]).where("name like ?", "%#{@search}%").reorder("created_at desc") + @shixuns_result_count = @shixuns_result.count + @shixun_pages = Paginator.new @shixuns_result_count, @limit, params['page'] || 1 + @offset ||= @shixun_pages.offset + @shixuns_result = paginateHelper @shixuns_result, @limit + end respond_to do |format| - format.html{render :layout=>'base_users_new'} + format.html{render :layout=>'base_edu'} + end + end + + # 我发布的实训 + def shixuns + @my_shixun = true + @type = params[:type] + if @type == "1" + ids = Shixun.find_by_sql("select shixun_id from shixun_members where role=2 and user_id=#{@user.id}") + ids2 = Shixun.find_by_sql("select id from shixuns where id in (select shixun_id from myshixuns where user_id = #{@user.id})") + ids = ids.map{|shixun| shixun.shixun_id} unless ids.blank? + ids2 = ids2.map{|shixun| shixun.id} unless ids2.blank? + id = ids + ids2 + id = id.uniq + @shixuns = Shixun.where(:id => id) + else + @shixuns = Shixun.where(:user_id => @user.id) + end + @shixuns_count = @shixuns.count + @limit = 10 + @shixun_pages = Paginator.new @shixuns_count, @limit, params['page'] || 1 + @offset ||= @shixun_pages.offset + @shixuns = paginateHelper @shixuns, @limit + respond_to do |format| + format.html{render :layout=> 'base_edu'} + format.js + end + end + + def my_join_shixuns + # 我参入的 + ids = Shixun.find_by_sql("select id from shixun_members where role=2 and user_id=#{@user.id}") + ids2 = Shixun.find_by_sql("select id from shixuns where id in (select shixun_id from myshixuns where user_id = #{@user.id})") + ids = ids.map{|shixun| shixun.id} unless ids.blank? + ids2 = ids2.map{|shixun| shixun.id} unless ids2.blank? + id = ids + ids2 + id = id.uniq + @shixuns = Shixun.where(:id => id) + @shixuns_count = @shixuns.count + @limit = 10 + @shixun_pages = Paginator.new @shixuns_count, @limit, params['page'] || 1 + @offset ||= @shixun_pages.offset + @shixuns = paginateHelper @shixuns, @limit + respond_to do |format| + format.html{render :layout=> 'base_edu'} end end @@ -720,11 +784,8 @@ class UsersController < ApplicationController c = Course.find(@msg.course_id) cs.send_wechat_join_class_notice apply_user,c,7,1 end - - end - respond_to do |format| - format.js end + redirect_to settings_course_path(@msg.course_id, :tab => 'member') end # 处理资源引用请求 @@ -1007,72 +1068,7 @@ class UsersController < ApplicationController course_ids = params[:course_ids] course_ids.each do |course_id| course = Course.find course_id.to_i - new_homework = HomeworkCommon.new - new_homework.name = homework.name - new_homework.user_id = User.current.id - new_homework.description = homework.description - new_homework.homework_type = homework.homework_type - new_homework.late_penalty = 0 - new_homework.course_id = course.id - new_homework.teacher_priority = 1 - new_homework.anonymous_comment = 1 - new_homework.quotes = 0 - new_homework.is_open = 0 - new_homework.homework_bank_id = homework.id - homework.attachments.each do |attachment| - att = attachment.copy - att.container_id = nil - att.container_type = nil - att.copy_from = attachment.id - att.save - new_homework.attachments << att - end - #homework_detail_manual = homework.homework_detail_manual - #homework_detail_programing = homework.homework_detail_programing - #homework_detail_group = homework.homework_detail_group - #if homework_detail_manual - new_homework.homework_detail_manual = HomeworkDetailManual.new - new_homework_detail_manual = new_homework.homework_detail_manual - new_homework_detail_manual.ta_proportion = new_homework.homework_type == 2 ? 0.4 : 1.0 - new_homework_detail_manual.comment_status = 0 - new_homework_detail_manual.evaluation_num = 3 - new_homework_detail_manual.absence_penalty = 0 - #end - #if homework_detail_programing - if new_homework.homework_type == 2 - new_homework.homework_detail_programing = HomeworkDetailPrograming.new - new_homework.homework_detail_programing.ta_proportion = 0.6 - new_homework.homework_detail_programing.language = homework.language - homework.homework_bank_tests.each_with_index do |homework_test| - if homework_test.test_type - new_homework.homework_tests << HomeworkTest.new( - input: homework_test.input, - output: homework_test.output - ) - else - new_homework.homework_samples << HomeworkSample.new( - input: homework_test.input, - output: homework_test.output - ) - end - end - end - #end - - #if homework_detail_group - if new_homework.homework_type == 3 - new_homework.homework_detail_group = HomeworkDetailGroup.new - new_homework.homework_detail_group.min_num = homework.min_num - new_homework.homework_detail_group.max_num = homework.max_num - new_homework.homework_detail_group.base_on_project = homework.base_on_project - end - #end - if new_homework.save - new_homework_detail_manual.save if new_homework_detail_manual - new_homework.homework_detail_programing.save if new_homework.homework_detail_programing - new_homework.homework_detail_group.save if new_homework.homework_detail_group - end - homework.update_column(:quotes, homework.quotes+1) + quote_homework_bank homework, course end @homework = homework respond_to do |format| @@ -1083,64 +1079,37 @@ class UsersController < ApplicationController #导入作业 def user_import_homeworks @user = User.current - @select_course = params[:select_course] ? 1 : 0 - #@user_homeworks = HomeworkCommon.where(:user_id => @user.id).order("created_at desc") - #courses = @user.courses.where("is_delete = 1") - #course_ids = courses.empty? ? "(-1)" : "(" + courses.map{|course| course.id}.join(",") + ")" - @homeworks = @user.homework_banks.order("#{@order} #{@b_sort}") - @type = params[:type] - @limit = 15 + @select_course = params[:select_course] + @homework_type = params[:homework_type].to_i + search = params[:search].to_s.strip.downcase + if(params[:type].blank? || params[:type] == "1") #我的题库 + @homeworks = @user.homework_banks.where(:homework_type => @homework_type) + elsif params[:type] == "2" #公共题库 + @homeworks = HomeworkBank.where(:is_public => true, :homework_type => @homework_type) + end + @type = params[:type] || "1" + @homeworks = @homeworks.where("name like '%#{search}%'").reorder("created_at desc") + @limit = 10 @is_remote = true @hw_count = @homeworks.count @hw_pages = Paginator.new @hw_count, @limit, params['page'] || 1 @offset ||= @hw_pages.offset - @homeworks = paginateHelper @homeworks,15 + @homeworks = paginateHelper @homeworks,@limit respond_to do |format| format.js end end def user_homework_type - @order,@b_sort = params[:order] || "created_at",params[:sort] || "desc" - @r_sort = @b_sort == "desc" ? "asc" : "desc" @user = User.current if(params[:type].blank? || params[:type] == "1") #我的题库 - #courses = @user.courses.where("is_delete = 1") - #course_ids = courses.empty? ? "(-1)" : "(" + courses.map{|course| course.id}.join(",") + ")" @homeworks = @user.homework_banks elsif params[:type] == "2" #公共题库 - #visible_course = Course.where("is_public = 1 && is_delete = 0") - #visible_course_ids = visible_course.empty? ? "(-1)" : "(" + visible_course.map{|course| course.id}.join(",") + ")" @homeworks = HomeworkBank.where(:is_public => true) - # elsif params[:type] == "3" #申请题库 - # none_visible_course = Course.where("is_delete = 1") - # none_visible_course_ids = none_visible_course.empty? ? "(-1)" : "(" + none_visible_course.map{|course| course.id}.join(",") + ")" - # #apply_homeworks = ApplyHomework.where("user_id = ?",@user.id).order('created_at desc') - # #homework_ids = apply_homeworks.empty? ? "(-1)" : "(" + apply_homeworks.map{|ah| ah.homework_common_id}.join(",") + ")" - # #@homeworks = HomeworkCommon.where("id in #{homework_ids} and course_id not in #{none_visible_course_ids}") - # - # sql = "SELECT homework_commons.* FROM homework_commons INNER JOIN apply_homeworks as ah ON homework_commons.id = ah.homework_common_id where ah.user_id = #{@user.id} and homework_commons.course_id not in #{none_visible_course_ids} order by ah.created_at desc" - # @homeworks = HomeworkCommon.find_by_sql(sql) end - if params[:property] - @homeworks = @homeworks.where(:homework_type => params[:property].to_i) - # all_homework_ids = @homeworks.empty? ? "(-1)" : "(" + @homeworks.map{|h| h.id}.join(",") + ")" - # if params[:property] == "1" - # @homeworks = HomeworkCommon.find_by_sql("select * from homework_commons where id in #{all_homework_ids} and homework_type = 1") - # #@homeworks = @homeworks.where("homework_type = 1").reorder("#{@order} #{@b_sort}") - # elsif params[:property] == "2" - # @homeworks = HomeworkCommon.find_by_sql("select * from homework_commons where id in #{all_homework_ids} and homework_type = 2") - # #@homeworks = @homeworks.where("homework_type = 2").reorder("#{@order} #{@b_sort}") - # elsif params[:property] == "3" - # @homeworks = HomeworkCommon.find_by_sql("select * from homework_commons where id in #{all_homework_ids} and homework_type = 3") - # #@homeworks = @homeworks.where("homework_type = 3").reorder("#{@order} #{@b_sort}") - # end - end - @homeworks = @homeworks.reorder("#{@order} #{@b_sort}") + @homeworks = @homeworks.reorder("created_at desc") @type = params[:type] ? params[:type] : '1' - @property = params[:property] - @is_import = params[:is_import] - @limit = params[:is_import].to_i == 1 ? 15 : 10 + @limit = 10 @is_remote = true @hw_count = @homeworks.count @hw_pages = Paginator.new @hw_count, @limit, params['page'] || 1 @@ -1266,58 +1235,12 @@ class UsersController < ApplicationController #导入作业,确定按钮 def user_select_homework - homework = HomeworkBank.find_by_id params[:checkMenu] - #homework_detail_programing = homework.homework_detail_programing - #homework_detail_group = homework.homework_detail_group - @homework = HomeworkCommon.new - @select_course = params[:select_course] || 0 - if homework - @ref_homework = homework - @homework.name = homework.name - @homework.description = homework.description - #@homework.end_time = homework.end_time - @homework.homework_type = homework.homework_type - #@homework.course_id = homework.course_id - homework.attachments.each do |attachment| - att = attachment.copy - att.container_id = nil - att.container_type = nil - att.copy_from = attachment.id - att.save - @homework.attachments << att + params[:checkMenu].each do |homework_bank| + homework = HomeworkBank.find_by_id homework_bank + @select_course = Course.find params[:select_course] + if homework && @select_course + quote_homework_bank homework, @select_course end - - #if homework_detail_programing - if homework.homework_type == 2 - @homework.homework_detail_programing = HomeworkDetailPrograming.new - @homework_detail_programing = @homework.homework_detail_programing - #@homework_detail_programing.ta_proportion = homework_detail_programing.ta_proportion - @homework_detail_programing.language = homework.language - homework.homework_bank_tests.each_with_index do |homework_test| - if homework_test.test_type - @homework.homework_tests << HomeworkTest.new( - input: homework_test.input, - output: homework_test.output - ) - else - @homework.homework_samples << HomeworkSample.new( - input: homework_test.input, - output: homework_test.output - ) - end - end - end - #end - - #if homework_detail_group - if homework.homework_type == 3 - @homework.homework_detail_group = HomeworkDetailGroup.new - @homework_detail_group = @homework.homework_detail_group - @homework_detail_group.min_num = homework.min_num - @homework_detail_group.max_num = homework.max_num - @homework_detail_group.base_on_project = homework.base_on_project - end - #end end respond_to do |format| format.js @@ -1682,6 +1605,7 @@ class UsersController < ApplicationController redirect_to signin_url return end + update_onclick_time # 自己访问自己的页面才更新消息状态 UserFeedbackMessage.where("user_id =? and viewed =? and journals_for_message_type =? ", User.current.id, 0, "JournalsForMessage").update_all(:viewed => true) # end @@ -1709,7 +1633,7 @@ class UsersController < ApplicationController # end # end @state = false - render :layout=>'new_base_user' + render :layout => 'edu_new_base_user' end #给某人留言 @@ -2102,15 +2026,45 @@ class UsersController < ApplicationController @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); + @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 + @user_fanlist = fan_query.order("#{Watcher.table_name}.id desc").limit(12) + + # 我创建的实训数 + @create_num = (@user == User.current ? Shixun.where(:user_id => @user).count : Shixun.where(:status => [2, 3], :user_id => @user).count) + # 我合作的实训数 + coop_id = Shixun.find_by_sql("select shixun_id from shixun_members where user_id=#{@user.id} and role = 2").map(&:shixun_id) # 合作者的实训id + @cooperative_num = (@user == User.current ? Shixun.where(:id => coop_id).count : Shixun.where(:status => [2, 3], :id => coop_id).count) + # 我挑战的实训数 + ch_id = Shixun.find_by_sql("select id from shixuns where id in (select shixun_id from myshixuns where user_id = #{@user.id})") + @challenge_num = (@user == User.current ? Shixun.where(:id => ch_id).count : Shixun.where(:status => [2, 3], :id => ch_id)) + # 我的所有课程数 + @all_courses_count = @user.courses.not_deleted_not_end.count + # 我创建的课程数 + @create_courses_count = @user.courses.not_deleted_not_end.where(:tea_id => @user.id).count + # 我参与的课程数 + @join_courses_count = @user.courses.not_deleted_not_end.where("tea_id != #{@user.id}").count + + # 合作者及创建者 + ids = Shixun.find_by_sql("select shixun_id from shixun_members where user_id=#{@user.id}") + # 已挑战过 + ids2 = Shixun.find_by_sql("select id from shixuns where id in (select shixun_id from myshixuns where user_id = #{@user.id})") + ids = ids.map{|shixun| shixun.shixun_id} unless ids.blank? + ids2 = ids2.map{|shixun| shixun.id} unless ids2.blank? + id = ids + ids2 + id = id.uniq + if @user == User.current + @shixuns = Shixun.where(:id => id).order("created_at desc") + else + @shixuns = Shixun.where(:status => [2, 3], :id => id).order("created_at desc") + end + @limit = 5 + @is_remote = true + @shixuns_count = @shixuns.count + @shixuns_pages = Paginator.new @shixuns_count, @limit, params['page'] || 1 + @offset ||= @shixuns_pages.offset + @shixuns = paginateHelper @shixuns, @limit # if User.current == @user # # 点击小铃铛,更新点击时间 # update_onclick_time if params[:click_user_message] == 'true' @@ -2255,6 +2209,88 @@ class UsersController < ApplicationController end end + # @params: index表示 "实训" 或 "课程" 那个的筛选 + # filter 表示筛选的条件[challenge => "我挑战的", create => "我创建的", cooperative => "合作者"] + def shixuns_or_courses_filter + if params[:index] == "shixun" + if params[:filter] == "challenge" + # 已挑战过 + id = Shixun.find_by_sql("select id from shixuns where id in (select shixun_id from myshixuns where user_id = #{@user.id})") + if @user == User.current + @shixuns = Shixun.where(:id => id).order("created_at desc") + else + @shixuns = Shixun.where(:status => [2, 3], :id => id).order("created_at desc") + end + elsif params[:filter] == "create" + if @user == User.current + @shixuns = Shixun.where(:user_id => @user).order("created_at desc") + else + @shixuns = Shixun.where(:status => [2, 3], :user_id => @user).order("created_at desc") + end + elsif params[:filter] == "cooperative" + # 合作者的实训id + id = Shixun.find_by_sql("select shixun_id from shixun_members where user_id=#{@user.id} and role = 2").map(&:shixun_id) + if @user == User.current + @shixuns = Shixun.where(:id => id).order("created_at desc") + else + @shixuns = Shixun.where(:status => [2, 3], :id => id).order("created_at desc") + end + elsif params[:filter] == "all" + # 合作者及创建者 + ids = Shixun.find_by_sql("select shixun_id from shixun_members where user_id=#{@user.id}") + # 已挑战过 + ids2 = Shixun.find_by_sql("select id from shixuns where id in (select shixun_id from myshixuns where user_id = #{@user.id})") + ids = ids.map{|shixun| shixun.shixun_id} unless ids.blank? + ids2 = ids2.map{|shixun| shixun.id} unless ids2.blank? + id = ids + ids2 + id = id.uniq + if @user == User.current + @shixuns = Shixun.where(:id => id).order("created_at desc") + else + @shixuns = Shixun.where(:status => [2, 3], :id => id).order("created_at desc") + end + end + @limit = 5 + @is_remote = true + @shixuns_count = @shixuns.count + @shixuns_pages = Paginator.new @shixuns_count, @limit, params['page'] || 1 + @offset ||= @shixuns_pages.offset + @shixuns = paginateHelper @shixuns, @limit + elsif params[:index] == "course" + if params[:filter] == "manage" + @courses = @user.courses.not_deleted_not_end.where(:tea_id => @user.id).order("updated_at desc") + elsif params[:filter] == "join" + @courses = @user.courses.not_deleted_not_end.where("tea_id != #{@user.id}").order("updated_at desc") + elsif params[:filter] == "all" + @courses = @user.courses.not_deleted_not_end.order("updated_at desc") + end + @limit = 5 + @is_remote = true + @courses_count = @courses.count + @courses_pages = Paginator.new @courses_count, @limit, params['page'] || 1 + @offset ||= @courses_pages.offset + @courses = paginateHelper @courses, @limit + end + + respond_to do |format| + format.js + end + end + + + def user_show_course_list + @courses = @user.courses.not_deleted_not_end.where(:tea_id => @user.id).order("updated_at desc") + @courses_count = @courses.count + @limit = 5 + @is_remote = true + @courses_pages = Paginator.new @courses_count, @limit, params['page'] || 1 + @offset ||= @courses_pages.offset + @courses = paginateHelper @courses, @limit + respond_to do |format| + format.js + end + end + # 待解决的Issue def unsolved_issues_list @unsolved_issues = Issue.where(:assigned_to_id => @user.id, :status_id => [1, 2, 4, 6]).includes(:author, :project).order("updated_on desc") @@ -2967,16 +3003,15 @@ class UsersController < ApplicationController @user = User.current if !params[:search].nil? search = "%#{params[:search].to_s.strip.downcase}%" - @course = @user.courses.not_deleted.where(" #{Course.table_name}.id = #{params[:search].to_i } or #{Course.table_name}.name like :p",:p=>search) + @course = @user.courses.not_deleted_not_end.where(" #{Course.table_name}.id = #{params[:search].to_i } or #{Course.table_name}.name like :p",:p=>search) else - @course = @user.courses.not_deleted + @course = @user.courses.not_deleted_not_end end @search = params[:search] @type = params[:type] #这里仅仅是传递需要发送的资源id @send_id = params[:send_id] @send_ids = params[:checkbox1] || params[:send_ids] - @hidden_unproject = hidden_unproject_infos respond_to do |format| format.js end @@ -3054,60 +3089,61 @@ class UsersController < ApplicationController else @flag = false end - @order, @b_sort = params[:order] || "created_on", params[:sort] || "asc" - @score = @b_sort == "desc" ? "asc" : "desc" - user_project_ids = User.current.projects.map {|p| p.id} - user_course_ids = User.current.courses.map { |c| c.id} #我的资源库的话,那么应该是我上传的所有资源 加上 我加入的课程的所有资源 - if(params[:type] == "1") # 我的资源 - # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源 - if params[:status] == "2" - @attachments = get_course_resources(User.current.id, user_course_ids, @order, @score) - elsif params[:status] == "3" - @attachments = get_project_resources(User.current.id, user_project_ids, @order, @score) - elsif params[:status] == "4" - @attachments = get_attch_resources(User.current.id, @order, @score) - elsif params[:status] == "5" - @attachments = get_principal_resources(User.current.id, @order, @score) - else - # 公共资源库:所有公开资源或者我上传的私有资源 - @attachments = get_my_resources(User.current.id, user_course_ids, user_project_ids, @order, @score) - end - elsif (params[:type].blank? || params[:type] == "6") # 公共资源 - if params[:status] == "2" - @attachments = get_course_resources_public( user_course_ids, @order, @score) - elsif params[:status] == "3" - @attachments = get_project_resources_public(user_project_ids, @order, @score) - elsif params[:status] == "4" - @attachments = get_attch_resources_public(@order, @score) - elsif params[:status] == "5" - @attachments = get_principal_resources_public(@order, @score) - else - # 公共资源库:所有公开资源或者我上传的私有资源 - @attachments = get_public_resources(user_course_ids, user_project_ids, params[:order], @score) - end - # elsif params[:type] == "2" - # apply_ids = ApplyResource.where("user_id =? and status =?", params[:id], 2).map { |ar| ar.attachment_id} - # if params[:status] == "2" - # resource_type = "'Course'" - # elsif params[:status] == "3" - # resource_type = "'Project'" - # elsif params[:status] == "5" - # resource_type = "'Principal'" - # else - # resource_type = "'Project','OrgSubfield','Principal','Course'" - # end - # @attachments = get_my_private_resources(apply_ids, resource_type, @order, @score) - end - @type = params[:type] - @limit = 25 - @path = user_resource_user_path(User.current, :type => @type) - @user = User.current - @is_remote = true - @atta_count = @attachments.count - @atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1 - @offset ||= @atta_pages.offset - #@curse_attachments_all = @all_attachments[@offset, @limit] - @attachments = paginateHelper @attachments,25 + # @order, @b_sort = params[:order] || "created_on", params[:sort] || "asc" + # @score = @b_sort == "desc" ? "asc" : "desc" + # user_project_ids = User.current.projects.map {|p| p.id} + # user_course_ids = User.current.courses.map { |c| c.id} #我的资源库的话,那么应该是我上传的所有资源 加上 我加入的课程的所有资源 + # if(params[:type] == "1") # 我的资源 + # # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源 + # if params[:status] == "2" + # @attachments = get_course_resources(User.current.id, user_course_ids, @order, @score) + # elsif params[:status] == "3" + # @attachments = get_project_resources(User.current.id, user_project_ids, @order, @score) + # elsif params[:status] == "4" + # @attachments = get_attch_resources(User.current.id, @order, @score) + # elsif params[:status] == "5" + # @attachments = get_principal_resources(User.current.id, @order, @score) + # else + # # 公共资源库:所有公开资源或者我上传的私有资源 + # @attachments = get_my_resources(User.current.id, user_course_ids, user_project_ids, @order, @score) + # end + # elsif (params[:type].blank? || params[:type] == "6") # 公共资源 + # if params[:status] == "2" + # @attachments = get_course_resources_public( user_course_ids, @order, @score) + # elsif params[:status] == "3" + # @attachments = get_project_resources_public(user_project_ids, @order, @score) + # elsif params[:status] == "4" + # @attachments = get_attch_resources_public(@order, @score) + # elsif params[:status] == "5" + # @attachments = get_principal_resources_public(@order, @score) + # else + # # 公共资源库:所有公开资源或者我上传的私有资源 + # @attachments = get_public_resources(user_course_ids, user_project_ids, params[:order], @score) + # end + # # elsif params[:type] == "2" + # # apply_ids = ApplyResource.where("user_id =? and status =?", params[:id], 2).map { |ar| ar.attachment_id} + # # if params[:status] == "2" + # # resource_type = "'Course'" + # # elsif params[:status] == "3" + # # resource_type = "'Project'" + # # elsif params[:status] == "5" + # # resource_type = "'Principal'" + # # else + # # resource_type = "'Project','OrgSubfield','Principal','Course'" + # # end + # # @attachments = get_my_private_resources(apply_ids, resource_type, @order, @score) + # end + # @type = params[:type] + # @limit = 25 + # @path = user_resource_user_path(User.current, :type => @type) + # @user = User.current + # @is_remote = true + # @atta_count = @attachments.count + # @atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1 + # @offset ||= @atta_pages.offset + # #@curse_attachments_all = @all_attachments[@offset, @limit] + # @attachments = paginateHelper @attachments,25 + @course = @ori.course respond_to do |format| format.js end @@ -3566,7 +3602,7 @@ class UsersController < ApplicationController def destroy @user.destroy respond_to do |format| - format.html { redirect_back_or_default(admin_users_path) } + format.html { redirect_back_or_default(params[:back_url]) } format.api { render_api_ok } end end @@ -4480,7 +4516,7 @@ class UsersController < ApplicationController private def show_system_message - # 系统消息总显示在最前面,显示周期30天 + # 系统消息总显示在最前面,显示周期30天 @system_messages = SystemMessage.where("created_at > ?", Time.now - 86400 * 30) end diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index 7632a58e6..439ecdd27 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -24,6 +24,7 @@ class WelcomeController < ApplicationController #before_filter :find_first_page, :only => [:index] # before_filter :fake, :only => [:index, :course] before_filter :entry_select, :only => [:index] + skip_before_filter :check_authentication, :only => [:index] def index # @welcome是因为有的页面不需要导航 diff --git a/app/controllers/words_controller.rb b/app/controllers/words_controller.rb index b3e8ec91c..49b006460 100644 --- a/app/controllers/words_controller.rb +++ b/app/controllers/words_controller.rb @@ -342,23 +342,23 @@ class WordsController < ApplicationController def leave_homework_message if User.current.logged? @user = User.current - @homework_common = HomeworkCommon.find(params[:id]); + @homework = HomeworkCommon.find(params[:id]); if params[:homework_message].size>0 && User.current.logged? && @user - feedback = HomeworkCommon.add_homework_jour(@user, params[:homework_message], params[:id], @homework_common.id) + feedback = HomeworkCommon.add_homework_jour(@user, params[:homework_message], params[:id], @homework.id) if (feedback.errors.empty?) if params[:asset_id] ids = params[:asset_id].split(',') update_kindeditor_assets_owner ids,feedback[:id],OwnerTypeHelper::JOURNALSFORMESSAGE end - @homework_common.update_column('updated_at', Time.now) - update_course_activity(@homework_common.class,@homework_common.id) - update_user_activity(@homework_common.class,@homework_common.id) - update_org_activity(@homework_common.class,@homework_common.id) + @homework.update_column('updated_at', Time.now) + update_course_activity(@homework.class,@homework.id) + update_user_activity(@homework.class,@homework.id) + update_org_activity(@homework.class,@homework.id) respond_to do |format| format.js{ @user_activity_id = params[:user_activity_id].to_i @hw_status = params[:hw_status].to_i if params[:hw_status] - @is_teacher = User.current.allowed_to?(:as_teacher, @homework_common.course) || User.current.admin? + @is_teacher = User.current.allowed_to?(:as_teacher, @homework.course) || User.current.admin? } end else @@ -375,7 +375,7 @@ class WordsController < ApplicationController if User.current.logged? @user = User.current reply = JournalsForMessage.find params[:id].to_i - @homework_common = HomeworkCommon.find reply.jour_id + @homework = HomeworkCommon.find reply.jour_id if params[:reply_message].size>0 && User.current.logged? && @user options = {:notes => params[:reply_message], :reply_id => reply.user_id,:user_id => @user.id,:m_parent_id => params[:id].to_i,:m_reply_id => params[:id].to_i, :root_id => reply.root_id} feedback = HomeworkCommon.add_homework_jour(@user, params[:reply_message], reply.jour_id, reply.root_id, options) @@ -384,15 +384,15 @@ class WordsController < ApplicationController ids = params[:asset_id].split(',') update_kindeditor_assets_owner ids,feedback[:id],OwnerTypeHelper::JOURNALSFORMESSAGE end - @homework_common.update_column('updated_at', Time.now) - update_course_activity(@homework_common.class,@homework_common.id) - update_user_activity(@homework_common.class,@homework_common.id) - update_org_activity(@homework_common.class,@homework_common.id) + @homework.update_column('updated_at', Time.now) + update_course_activity(@homework.class,@homework.id) + update_user_activity(@homework.class,@homework.id) + update_org_activity(@homework.class,@homework.id) respond_to do |format| format.js{ @user_activity_id = params[:user_activity_id].to_i @hw_status = params[:hw_status].to_i if params[:hw_status] - @is_teacher = User.current.allowed_to?(:as_teacher, @homework_common.course) || User.current.admin? + @is_teacher = User.current.allowed_to?(:as_teacher, @homework.course) || User.current.admin? } end else diff --git a/app/helpers/api_helper.rb b/app/helpers/api_helper.rb index f322fdb8c..119c3c920 100644 --- a/app/helpers/api_helper.rb +++ b/app/helpers/api_helper.rb @@ -205,6 +205,45 @@ module ApiHelper end + # 获取当前时间 + def time_from_future time + lastUpdateTime = time.to_i*1000 + + currentTime = Time.now.to_i*1000 + timePassed = lastUpdateTime - currentTime; + timeIntoFormat = 0 + updateAtValue = "" + if timePassed < 0 + updateAtValue = "马上" + elsif timePassed < ONE_MINUTE + updateAtValue = "1分钟" + elsif timePassed < ONE_HOUR + timeIntoFormat = timePassed / ONE_MINUTE + updateAtValue = timeIntoFormat.to_s + "分钟" + elsif (timePassed < ONE_DAY) + timeIntoFormat = timePassed / ONE_HOUR + updateAtValue = timeIntoFormat.to_s + "小时" + elsif (timePassed < ONE_MONTH) + timeIntoFormat = timePassed / ONE_DAY + updateAtValue = timeIntoFormat.to_s + "天" + elsif (timePassed < ONE_YEAR) + timeIntoFormat = timePassed / ONE_MONTH + updateAtValue = timeIntoFormat.to_s + "个月" + else + timeIntoFormat = timePassed / ONE_YEAR + updateAtValue = timeIntoFormat.to_s + "年" + end + updateAtValue + end + + # 计算到结束还有多长时间 **天**小时**分 + def how_much_time time + result = "" + result = ((time - Time.now.to_i).to_i / (24*60*60)).to_s + " 天 " + result += (((time - Time.now.to_i).to_i % (24*60*60)) / (60*60)).to_s + " 小时 " + result += ((((time - Time.now.to_i).to_i % (24*60*60)) % (60*60)) / 60).to_s + " 分 " + end + #日期转换为时间 def convert_to_time date, num if num == 0 diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 8dbdf34a1..99626c6cb 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -33,13 +33,117 @@ module ApplicationHelper extend Forwardable def_delegators :wiki_helper, :wikitoolbar_for, :heads_for_wiki_formatter + def open_webssh + # 如果我webssh类型, 开启webssh + jenkins_shixuns = Redmine::Configuration['jenkins_shixuns'] + uri = URI("#{jenkins_shixuns}/jenkins-exec/webssh/getConnectInfo") + user_id = User.current.id + params = {userID:user_id} + res = uri_exec uri, params + return [host, port, username, password] + end + + # 若实训有更改,则修改已发不实训的标记为已更改 + # shixun_modifies表中1表示已更改,进入myshixun需要强制重置,0表示没有修改 + # type 0:表示已经是最新的了;1:表示已经有修改 + # 功能:1、产生变更记录;2、生成pipeline脚本 + def add_shixun_modify_status shixun, type + jenkins_shixuns = Redmine::Configuration['jenkins_shixuns'] + gameInfo = shixun.gameInfo + uri = URI("#{jenkins_shixuns}/jenkins-exec/game/publishGame") + params = {gameInfo:gameInfo} + res = uri_exec uri, params + if res && res['code'].to_i != 0 + raise("实训云平台繁忙(繁忙等级:90)") + end + myshixuns = shixun.myshixuns + unless myshixuns.blank? + myshixuns.each do |myshixun| + shixun_modify = ShixunModify.where(:shixun_id => shixun.id, :myshixun_id => myshixun.id).first + if shixun_modify.nil? + ShixunModify.create(:shixun_id => shixun.id, :myshixun_id => myshixun.id, :status => type) + else + shixun_modify.update_attribute(:status, type) + end + end + end + end + + # 仅仅产生记录,用于已执行publish的方法 + def shixun_modify_status_without_publish shixun, type + myshixuns = shixun.myshixuns + unless myshixuns.blank? + myshixuns.each do |myshixun| + shixun_modify = ShixunModify.where(:shixun_id => shixun.id, :myshixun_id => myshixun.id).first + if shixun_modify.nil? + ShixunModify.create(:shixun_id => shixun.id, :myshixun_id => myshixun.id, :status => type) + else + shixun_modify.update_attribute(:status, type) + end + end + end + end + + # 通关后,把最后一次成功的代码存到数据库 + # type 0 创始内容, 1 最新内容 + def game_passed_code game_id, path, myshixun_gpid, type + g = Gitlab.client + rev = rev.nil? ? "master" : rev + file_content = g.files(myshixun_gpid, path, rev).content + if file_content.blank? + # gitlab缺陷:forked完成,短暂时间内取不了内容的,所以做一个小轮询,间隔0.1秒 + # 超过2秒则失败,需通过页面刷新 + for i in 0..30 do + sleep(0.1) + file_content = g.files(myshixun_gpid, path, rev).content + unless file_content.blank? + break + end + end + end + file_content = Base64.decode64(file_content) unless file_content.blank? + game_code = GameCode.where(:game_id => game_id).first + if game_code.nil? + if type == 0 + GameCode.create!(:game_id => game_id, :original_code => file_content, :path => path) + else + # 这种情况正常是不会出现的,因为没创建成功抛异常,之所以这样写为了防止异常没处理的问题 + GameCode.create!(:game_id => game_id, :original_code => file_content, :new_code => file_content, :path => path) + end + else + game_code.update_attribute(:new_code, file_content) + end + end + + # 判断用户是否认证 + def check_authentication + # return true + # if params[:action] == "on_search" || params[:action] == "apply_trail" # 之所以这样处理是为了避开account页面ajax加载 + # return true + # end + authentication = ApplyAction.where(:user_id => User.current.id, :status => 1).first + user_identity = User.current.try(:user_extensions).try(:identity) + if user_identity.blank? || authentication.blank? + redirect_to my_account_path + return + end + end + # 积分表中建立记录行为,有过奖励则不重复奖励 def reward_grade(user, container_id, container_type, score) grade = Grade.where(:user_id => user.id, :container_id => container_id, :container_type => container_type).first if grade.nil? - user.update_column(:grade, (score.to_i + user.grade.to_i)) Grade.create!(:user_id => user.id, :container_id => container_id, :container_type => container_type, :score => score) end + user.update_column(:grade, (score.to_i + user.grade.to_i)) + end + + def reward_experience(user, container_id, container_type, score) + experience = Experience.where(:user_id => user.id, :container_id => container_id, :container_type => container_type).first + if experience.nil? + Experience.create!(:user_id => user.id, :container_id => container_id, :container_type => container_type, :score => score) + end + user.update_column(:experience, (score.to_i + user.experience.to_i)) end # codeMirror语言转换 @@ -58,16 +162,74 @@ module ApplicationHelper end end + # 实训语言的种类 + def shixun_language + ["Java", "C", "C++", "Python", "MySQL/Java"] + end + + # 实训试用专业 + def shixun_major_option + content = [] + content << ["选择实训适用的专业", 0] + content << ["计算机科学与技术", 635] + content << ["软件工程", 636] + content << ["网络工程", 637] + content << ["信息安全", 638] + content << ["物联网工程", 639] + content << ["信息工程", 622] + content << ["通信工程", 619] + end + + # 实训面向学员 + def shixun_trainee + content = [] + content << ["初级学员", 1] + content << ["中级学员", 2] + content << ["高级学员", 3] + content << ["顶级学员", 4] + end + + # 班级设置排序中文 + def switch_to_chinese word + case word + when "boards" + result = "讨论区" + when "news" + result = "通知" + when "homework" + result = "作业" + when "exercises" + result = "试卷" + when "poll" + result = "问卷" + when "statistics" + result = "统计" + when "attachment" + result ="资源" + end + return result + end + def allow_to_view_challenge challenge, shixun # 判断对应关卡的game是否开启,如果开启则允许查看 game_count = Game.where(:challenge_id => challenge, :user_id => User.current, :status => [0,1,2]).count - if (User.current.manager_of_shixun?(shixun) || game_count > 0) + if game_count > 0 return true else return false end end + # 已通过的关卡数 + def had_passed_changllenge_count shixun, user + myshixun = Myshixun.where(:shixun_id => shixun.id, :user_id => user.id).first + if myshixun.nil? + 0 + else + myshixun.games.select{|game| game.status == 2}.count + end + end + # 定义实训相关方法 def sum_final_score Game.find_by_sql("SELECT sum(final_score) as total_score FROM `games` where user_id=#{User.current.id}").first.try(:total_score) @@ -210,6 +372,19 @@ module ApplicationHelper gitUrl = gitlab_address.to_s+"/"+login+"/"+ rep_identify + "."+"git" end + def git_shixun_url_ip shixun, login + rep_identify = Repository.where(:shixun_id => shixun.id, :type => "Repository::Gitlab").first.try(:identifier) + gitlab_address = Redmine::Configuration['gitlab_address_ip'] + gitUrl = gitlab_address.to_s+"/"+login+"/"+ rep_identify + "."+"git" + end + + def git_myshixun_url_ip myshixun, user_id + login = User.where(:id => user_id).first.try(:login) + rep_identify = Repository.where(:myshixun_id => myshixun.id, :type => "Repository::Gitlab").first.try(:identifier) + gitlab_address = Redmine::Configuration['gitlab_address_ip'] + gitUrl = gitlab_address.to_s+"/"+login+"/"+ rep_identify + "."+"git" + end + def uri_exec uri, params begin logger.error("@parmas is #{params}, url is #{uri}") @@ -217,7 +392,7 @@ module ApplicationHelper res = JSON.parse(res) rescue => e logger.error("failed to create challenge by 'generatePipelineScriptForChallenge'! #{e}") - raise("Jenkins服务器异常") + raise("实训云平台繁忙(繁忙等级:84)") end end @@ -231,6 +406,119 @@ module ApplicationHelper res = JSON.parse(res) end + def last_reply_time container_id + message = Message.where(:root_id => container_id).order("created_on desc").first + time = message.created_on + return time + end + + # homework_common状态 + # 0:挂起;1:提交中;2:匿评中;3:评阅中 + def new_homework_common_status status + case status + when 0 + "挂起" + when 1 + "提交中" + when 2 + "补交中" + when 3 + "匿评中" + when 4 + "申诉中" + when 5 + "评阅中" + when 6 + "已结束" + end + end + + # 作业不同状态的不同样式 + def homework_status_color status + style = "" + case status + when '挂起' + style = 'edu-filter-btn-yellow' + when '提交中' + style = 'edu-filter-btn-blue' + when '补交中' + style = 'edu-filter-btn-orange' + when '匿评中' + style = 'edu-filter-btn-green' + when '申诉中' + style = 'edu-filter-btn-red' + when '评阅中' + style = 'edu-filter-btn-green' + when '已结束' + style = 'edu-filter-btn' + when '已开启补交' + style = 'edu-filter-btn-late' + when '未开启补交' + style = 'edu-filter-btn-no-late' + end + end + + # 判断作业有多少人提交了 + # + def had_commit_studentwork_count homework_common + StudentWork.where("work_status !=? and homework_common_id=? and is_delete = 0",0, homework_common.id).count + end + + # 未提交作品数统计 + def had_uncommit_studentwork_count homework_common + homework_common.course.student.count - homework_common.student_works.where("work_status !=?", 0).count + end + + # 未评阅 + def had_unevaluate_count homework_common + count = StudentWorksScore.find_by_sql("SELECT count(distinct student_work_id) as count FROM student_works_scores sws, student_works sw, homework_commons hc where hc.id =#{homework_common.id} and sw.homework_common_id=hc.id and sw.is_delete = 0 and sws.student_work_id = sw.id and sws.user_id=#{User.current.id};").first.try(:count).to_i + student_count = homework_common.course.student.count + return student_count - count + end + + # 该阶段还有多长时间结束/距下一阶段还有多长时间 + def homework_curr_time homework_common + result = {} + status = "" + time = "" + ho_detail_manual = homework_common.homework_detail_manual + if ho_detail_manual + case ho_detail_manual.comment_status + when 0 + status = "挂起" + when 1 + if homework_common.end_time && homework_common.end_time >= Time.now + status = "提交中" + time = how_much_time(homework_common.end_time) + end + when 3 + if ho_detail_manual.evaluation_end && ho_detail_manual.evaluation_end > Time.now + status = "匿评中" + time = how_much_time(ho_detail_manual.evaluation_end) + end + when 4 + if ho_detail_manual.appeal_time && ho_detail_manual.appeal_time > Time.now + status = "申诉中" + time = how_much_time(ho_detail_manual.appeal_time) + end + when 5 + if homework_common.archive_time && homework_common.archive_time > Time.now + status = "评阅中" + time = how_much_time(homework_common.archive_time) + end + when 6 + status = "已结束" + time = format_time homework_common.archive_time + end + end + if status == "" && homework_common.allow_late && homework_common.archive_time > Time.now + time = how_much_time homework_common.archive_time + end + result[:status] = status + result[:time] = time + result + end + # 公共分页 def paginator_list objs, objs_count, limit, is_remote @is_remote = is_remote @@ -336,6 +624,20 @@ module ApplicationHelper (User.current.logged? && shixun.challenges.count > 0 && !shixun.repository.blank?) end + # 判断当前用户是否可以开始实战 + def link_to_shixun_exec myshixun, shixun, str + is_modify = ShixunModify.where(:myshixun_id => myshixun.try(:id), :shixun_id => shixun.try(:id), :status => 1).first.blank? + if User.current.mail.blank? + link_to str, "javascript:void(0);", :onclick => "notice_box_redirect('#{security_settings_path}', '开启实训,请先绑定邮箱')", :class => "fr shixun-task-btn task-btn-orange mr15", :target => "_blank" + else + if is_modify || myshixun.blank? + link_to str, shixun_exec_shixun_path(shixun), :class => "fr shixun-task-btn task-btn-orange mr15", :target => "_blank" + else + link_to str, "javascript:void(0);", :onclick => "sure_box_redirect('#{myshixun_reset_myshixun_path(myshixun)}', '实训已经更新啦,系统正在为您重置')", :class => "fr shixun-task-btn task-btn-orange mr15" + end + end + end + # 通过系统外部邮箱查找用户,如果用户不存在则用邮箱替换 def get_user_by_mail mail user = User.find_by_mail(mail) @@ -1612,22 +1914,38 @@ module ApplicationHelper if args.empty? title = @html_title || [] if @project - title << (@project.name.nil? ? "让创新更美好" : @project.name) + title << (@project.name.nil? ? "创新源于实践" : @project.name) elsif @welcome - title << "高校教育大数据服务平台" + title << "创新源于实践" elsif @course - title << (@course.name.nil? ? "智能课堂" : @course.name) + title << (@course.name.nil? ? "实训课堂" : @course.name) + elsif params[:controller] == "homework_bank" + title << ("题库") + elsif params[:controller] == "courses" && params[:action] == "index" + title << ("实训课堂") elsif @contest - title << (@contest.name.nil? ? "让创新更美好" : @contest.name) + title << (@contest.name.nil? ? "创新源于实践" : @contest.name) + elsif @shixun + title << (@shixun.name.nil? ? "实训分类" : @shixun.name) + elsif @my_shixun + title << ("我的实训") + elsif params[:controller] == "shixuns" && params[:action] == "index" + title << ("实训分类") + elsif @subject + title << (@subject.name.nil? ? "课程实训" : @subject.name) + elsif params[:controller] == "subjects" && params[:action] == "index" + title << ("课程实训") elsif @organization - title << (@organization.name.nil? ? "让创新更美好" : @organization.name) + title << (@organization.name.nil? ? "创新源于实践" : @organization.name) elsif @forum || params[:controller] == "forums" title << "问吧" + elsif @my_syllabuses + title << "我的课堂" elsif @user if !@project_community.blank? || !@user_projectlist.blank? title << "项目" elsif !@course_community.blank? || !@user_courselist.blank? - title << "智能课堂" + title << "实训课堂" elsif !@contest_community.blank? title << @contest_community elsif !@manage_issues.blank? @@ -1639,10 +1957,10 @@ module ApplicationHelper elsif !@receive_homeworks.blank? title << @receive_homeworks else - title << @user.try(:realname) + title << @user.show_name end elsif @syllabus - title << (@syllabus.title.nil? ? "智能课堂" : @syllabus.title) + title << (@syllabus.title.nil? ? "实训课堂" : @syllabus.title) else title << (User.current.id == 2 ? "未登录" : User.current.try(:realname)) end @@ -2285,6 +2603,19 @@ module ApplicationHelper link_to l(:button_delete), url, options end + def update_status_link(user) + url = {:controller => 'users', :action => 'update', :id => user, :page => params[:page], :status => params[:status], :tab => nil} + + if user.locked? + link_to "解锁", url.merge(:user => {:status => User::STATUS_ACTIVE}), :method => :put, :class => 'mr10 link-color-blue' + elsif user.registered? + link_to "激活", url.merge(:user => {:status => User::STATUS_ACTIVE}), :method => :put, :class => 'mr10 link-color-blue' + elsif user != User.current + link_to "加锁", url.merge(:user => {:status => User::STATUS_LOCKED}), :method => :put, :class => 'mr10 link-color-blue' + end + end + + def delete_version_link(url, options={}) options = { :method => :delete, @@ -2566,7 +2897,7 @@ module ApplicationHelper # Returns the javascript tags that are included in the html layout head def javascript_heads - tags = javascript_include_tag('jquery-1.8.3-ui-1.9.2-ujs-2.0.3', 'application', 'jquery.colorbox-min') + tags = javascript_include_tag('jquery-1.8.3-ui-1.9.2-ujs-2.0.3', 'application', 'jquery.colorbox-min', 'baiduTemplate') unless User.current.pref.warn_on_leaving_unsaved == '0' tags << "\n".html_safe + javascript_tag("$(window).load(function(){ warnLeavingUnsaved('#{escape_javascript l(:text_warn_on_leaving_unsaved)}'); });") end @@ -2638,7 +2969,34 @@ module ApplicationHelper if File.exist?(disk_auth_filename("UserAuthentication",user_id,type)) File.join(relative_path,avatar_directory("UserAuthentication"), auth_filename(user_id,type)) else - File.join(relative_path,avatar_directory("UserAuthentication"),'0') + File.join(relative_path,avatar_directory("UserAuthentication"),type) + end + end + + def identity_authentication_status user_id + apply = ApplyAction.where(:user_id => user_id).first + case apply.try(:status) + when nil + "未授权" + when 0 + "处理中" + when 1 + "已授权" + when 2 + "被拒绝" + end + end + + def shixun_authentication_status shixun + case shixun.try(:status) + when 0,nil + "编辑中" + when 1 + "待审核" + when 2 + "已发布" + when 3 + "已关闭" end end @@ -2729,13 +3087,30 @@ module ApplicationHelper def resource_bank_candown resource,type candown = false + if resource.is_public + candown = true + end if type == 'syllabus' - syllabus = resource.course.syllabus - candown = User.current.member_of_syl?(syllabus) || User.current.admin? + candown = syllabus_course_member(User.current, resource.course) || User.current.admin? end candown end + # 课程某个班级的成员 + def syllabus_course_member user, course + result = false + syllabus = course.syllabus + if syllabus + syllabus.courses.each do |course| + if user.member_of_course?(course) + result = true + return result + end + end + end + result + end + def attachment_candown attachment candown = false if attachment.container @@ -2797,6 +3172,10 @@ module ApplicationHelper else candown = (attachment.is_public == 1 || attachment.is_public == true) end + else + if attachment.container_type == "Shixun" + candown = true + end end candown end @@ -3378,50 +3757,57 @@ module ApplicationHelper if User.current.logged? if User.current.member_of_course?(homework.course) if is_teacher #老师显示作品数量 - link_to "作品(#{count})", student_work_index_url_in_org(homework.id, 2), :class => "c_blue" + link_to "作品(#{count})", student_work_index_url_in_org(homework.id, 2), :class => "c_blue homepagePostSubmit" else #学生显示提交作品、修改作品等按钮 work = cur_user_works_for_homework homework project = cur_user_projects_for_homework homework - if work.nil? && homework.end_time >= Time.now - if homework.homework_type ==3 && project.nil? && homework.homework_detail_group.base_on_project == 1 - link_to "提交作品(#{count})","javascript:void(0)", :class => 'c_grey',:style=>"cursor:not-allowed",:title => '请先关联项目再提交作品' + if homework.homework_type == 4 + if work.nil? + link_to "开始实战(#{count})", shixun_path(homework.homework_commons_shixuns.shixun),:class => 'c_blue homepagePostSubmit',:target => "_blank" else - link_to "提交作品(#{count})", new_student_work_url_without_domain(homework.id),:class => 'c_blue' + myshixun = Myshixun.find work.myshixun_id + link_to "继续实战(#{count})", myshixun_game_path(myshixun.current_task, :myshixun_id => myshixun), :class => "c_blue homepagePostSubmit",:target => "_blank" if myshixun + end + elsif work.nil? && homework.end_time >= Time.now + if homework.homework_type ==3 && project.nil? && homework.homework_detail_group.base_on_project == 1 + link_to "提交作品(#{count})","javascript:void(0)", :class => 'c_grey homepagePostSubmit',:style=>"cursor:not-allowed",:title => '请先关联项目再提交作品' + else + link_to "提交作品(#{count})", new_student_work_url_without_domain(homework.id),:class => 'c_blue homepagePostSubmit' end elsif work.nil? && homework.end_time < Time.now - if homework.homework_type ==3 && project.nil? && homework.homework_detail_group.base_on_project == 1 - link_to "补交作品(#{count})","javascript:void(0)", :class => 'c_grey',:style=>"cursor:not-allowed",:title => '请先关联项目再补交作品' - else - link_to "补交作品(#{count})", new_student_work_url_without_domain(homework.id),:class => 'c_red' + if homework.allow_late && homework.homework_detail_manual.comment_status < 6 + if homework.homework_type ==3 && project.nil? && homework.homework_detail_group.base_on_project == 1 + link_to "补交作品(#{count})","javascript:void(0)", :class => 'c_grey homepagePostSubmit',:style=>"cursor:not-allowed",:title => '请先关联项目再补交作品' + else + link_to "补交作品(#{count})", new_student_work_url_without_domain(homework.id),:class => 'c_red homepagePostSubmit' + end end - else - if homework.homework_detail_manual && homework.homework_detail_manual.comment_status == 2 && StudentWorksEvaluationDistribution.where("student_work_id = #{work.id}").count > 0 #匿评作业,且作业状态不是在开启匿评之前 + elsif work + if homework.homework_detail_manual && homework.homework_detail_manual.comment_status == 3 && StudentWorksEvaluationDistribution.where("student_work_id = #{work.id}").count > 0 #匿评作业,且作业状态不是在开启匿评之前 if homework.homework_type != 3 - link_to "作品匿评", student_work_index_url_in_org(homework.id, 2), :class => 'c_blue', :title => "开启匿评后不可修改作品" + link_to "作品匿评", student_work_index_url_in_org(homework.id, 2), :class => 'c_blue homepagePostSubmit', :title => "开启匿评后不可修改作品" else work_ids = "(" + homework.student_works.has_committed.map(&:id).join(",") + ")" if User.current.student_works_evaluation_distributions.where("student_work_id IN #{work_ids}").count > 0 - link_to "作品匿评", student_work_index_url_in_org(homework.id, 2), :class => 'c_blue', :title => "开启匿评后不可修改作品" + link_to "作品匿评", student_work_index_url_in_org(homework.id, 2), :class => 'c_blue homepagePostSubmit', :title => "开启匿评后不可修改作品" else - link_to "查看作品(#{count})",student_work_index_url_in_org(homework.id, 2), :class => 'c_blue', :title => "匿评开启后提交的作品不参与匿评" + link_to "查看作品(#{count})",student_work_index_url_in_org(homework.id, 2), :class => 'c_blue homepagePostSubmit', :title => "匿评开启后提交的作品不参与匿评" end end - elsif homework.homework_detail_manual && homework.homework_detail_manual.comment_status == 3 - link_to "查看作品(#{count})",student_work_index_url_in_org(homework.id, 2), :class => 'c_blue', :title => "匿评已结束" - elsif homework.homework_type == 2 && homework.end_time >= Time.now#编程作业不能修改作品 - link_to "修改作品(#{count})", new_student_work_url_without_domain(homework.id),:class => 'c_blue' + elsif homework.homework_detail_manual && homework.homework_detail_manual.comment_status > 3 + link_to "查看作品(#{count})",student_work_index_url_in_org(homework.id, 2), :class => 'c_blue homepagePostSubmit', :title => "匿评已结束" elsif homework.end_time >= Time.now && work.user_id == User.current.id - link_to "修改作品(#{count})", edit_student_work_url_without_domain(work.id),:class => 'c_blue' + link_to "修改作品(#{count})", edit_student_work_url_without_domain(work.id),:class => 'c_blue homepagePostSubmit' else - link_to "查看作品(#{count})", student_work_index_url_in_org(homework.id, 2), :class => 'c_blue', :title => "作业截止后不可修改作品" + link_to "查看作品(#{count})", student_work_index_url_in_org(homework.id, 2), :class => 'c_blue homepagePostSubmit', :title => "作业截止后不可修改作品" end end end else - link_to "作品(#{count})", "javascript:void(0)", :class => "c_blue", :onclick => "notice_sure_box('您不是班级成员,不能提交作品
请先从老师处获取邀请码后加入班级,再提交作品')" + link_to "作品(#{count})", "javascript:void(0)", :class => "c_blue homepagePostSubmit", :onclick => "notice_sure_box('您不是班级成员,不能提交作品
请先从老师处获取邀请码后加入班级,再提交作品')" end else - link_to "作品(#{count})", "javascript:void(0)", :class => "c_blue", :onclick => "login_notice_box('#{signin_url_without_domain}');" + link_to "作品(#{count})", "javascript:void(0)", :class => "c_blue homepagePostSubmit", :onclick => "login_notice_box('#{signin_url_without_domain}');" end end @@ -4237,11 +4623,20 @@ def get_work_index(hw,is_teacher) return index end -def get_hw_index(hw,is_teacher) +def get_hw_index(hw,is_teacher,type=0) + homework_commons = hw.course.homework_commons if is_teacher - homeworks = hw.course.homework_commons.order("created_at asc") + if type != 0 + homeworks = homework_commons.where("homework_commons.homework_type = #{type}").order("created_at asc") + else + homeworks = homework_commons.order("created_at asc") + end else - homeworks = hw.course.homework_commons.where("publish_time <= '#{Time.now}'").order("created_at asc") + if type != 0 + homeworks = homework_commons.where("homework_commons.homework_type = #{type} and publish_time <= '#{Time.now}'").order("created_at asc") + else + homeworks = homework_commons.where("publish_time <= '#{Time.now}'").order("created_at asc") + end end hw_ids = homeworks.map{|hw| hw.id} if !homeworks.empty? index = hw_ids.index(hw.id) @@ -4344,9 +4739,13 @@ def get_contest_group_member_names work result 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(',') + ")" +def course_syllabus_option syllabus_id = nil + syllabus_members = SyllabusMember.where("user_id = #{User.current.id}") + syllabus_ids = syllabus_members.map{|mem| mem.syllabus_id} + if syllabus_id && !syllabus_ids.include?(syllabus_id) + syllabus_ids << syllabus_id + end + syllabus_ids = syllabus_ids.empty? ? "(-1)" : "(" + syllabus_ids.join(',') + ")" syllabuses = Syllabus.where("id in #{syllabus_ids}") type = [] option1 = [] @@ -4384,20 +4783,19 @@ def create_works_list homework end def add_to_homework_bank_f homework - homework_bank = HomeworkBank.new(:name => homework.name, :description => homework.description, :user_id => homework.user_id, :homework_type => homework.homework_type, - :quotes => 1, :is_public => homework.course.is_public, :applicable_syllabus => homework.course.syllabus.title, :homework_common_id => homework.id) + homework_bank = HomeworkBank.new(:name => homework.name, :description => homework.description, :user_id => User.current.id, :homework_type => homework.homework_type, + :quotes => 1, :is_public => homework.course.is_public, :applicable_syllabus => homework.course.syllabus.title, :homework_common_id => homework.id, + :reference_answer => homework.reference_answer, :syllabus_id => homework.course.syllabus_id) if homework.homework_type == 2 && homework.homework_detail_programing homework_bank.language = homework.homework_detail_programing.language homework.homework_tests.each_with_index do |homework_test| homework_bank.homework_bank_tests << HomeworkBankTest.new( - test_type: 1, input: homework_test.input, output: homework_test.output ) end homework.homework_samples.each_with_index do |homework_test| - homework_bank.homework_bank_tests << HomeworkBankTest.new( - test_type: 0, + homework_bank.homework_bank_samples << HomeworkBankSample.new( input: homework_test.input, output: homework_test.output ) @@ -4485,7 +4883,7 @@ def searchstudent_by_name users, name name = name.to_s.downcase users.each do |m| username = m.lastname.to_s.downcase + m.firstname.to_s.downcase - if(m.login.to_s.downcase.include?(name) || m.user_extensions[:student_id].to_s.downcase.include?(name) || username.include?(name)) + if(m.login.to_s.downcase.include?(name) || m.user_extensions[:student_id].to_s.downcase.include?(name) || username.include?(name)) mems << m end end @@ -4541,3 +4939,243 @@ def add_reply_adapter obj, options # end end +def sy_resources syllabus + courses = syllabus.courses.not_deleted + attachments = Attachment.where(:container_type => 'Course', :container_id => courses.map(&:id)) + resources = ResourceBank.where(:id => attachments.map(&:resource_bank_id)) + resources +end + +def sy_homeworks syllabus + courses = syllabus.courses.not_deleted + homeworks = HomeworkCommon.where(:course_id => courses.map(&:id)) + homeworks = HomeworkBank.where(:id => homeworks.map(&:homework_bank_id)) + homeworks +end + +# 可以查看到资源库的资源 +def visable_attachemnts_incourse course + return[] unless course + result = [] + course.attachments.each do |attachment| + if attachment.is_public? && attachment.is_publish == 1 || User.current == attachment.author || User.current.allowed_to?(:as_teacher,course) || (User.current.member_of_course?(course) && attachment.is_publish == 1) || User.current.admin? + result << attachment + end + end + result +end + +def visable_course_homework course, type=0 + if User.current.admin? || User.current.allowed_to?(:as_teacher,course) + if type != 0 + homework_num = course.homework_commons.where(:homework_type => type).count + else + homework_num = course.homework_commons.count + end + else + if type != 0 + homework_num = course.homework_commons.where(:homework_type => type).where("publish_time <= '#{Time.now}'").count + else + homework_num = course.homework_commons.where("publish_time <= '#{Time.now}'").count + end + end + homework_num +end + +#成绩计算 +def set_final_score homework,student_work + if homework && homework.homework_detail_manual + if homework.homework_type != 2 #非编程作业 + if homework.teacher_priority == 1 #教师优先 + if student_work.teacher_score + student_work.final_score = student_work.teacher_score + student_work.work_score = student_work.teacher_score - student_work.absence_penalty - student_work.late_penalty + else + if student_work.teaching_asistant_score.nil? + student_work.final_score = student_work.student_score + elsif student_work.student_score.nil? + student_work.final_score = student_work.teaching_asistant_score + else + ta_proportion = homework.homework_detail_manual.ta_proportion + final_ta_score = BigDecimal.new("#{student_work.teaching_asistant_score}") * BigDecimal.new("#{ta_proportion}") + final_s_score = BigDecimal.new("#{student_work.student_score}") * (BigDecimal.new('1.0') - BigDecimal.new("#{ta_proportion}")) + final_score = final_ta_score + final_s_score + student_work.final_score = format("%.2f",final_score.to_f) + end + if student_work.final_score + score = student_work.final_score - student_work.absence_penalty - student_work.late_penalty - student_work.appeal_penalty + student_work.work_score = format("%.2f",(score < 0 ? 0 : score).to_f) if score + else + student_work.work_score = nil + end + end + else #不考虑教师评分 + if student_work.teaching_asistant_score.nil? + student_work.final_score = student_work.student_score + elsif student_work.student_score.nil? + student_work.final_score = student_work.teaching_asistant_score + else + ta_proportion = homework.homework_detail_manual.ta_proportion + final_ta_score = BigDecimal.new("#{student_work.teaching_asistant_score}") * BigDecimal.new("#{ta_proportion}") + final_s_score = BigDecimal.new("#{student_work.student_score}") * (BigDecimal.new('1.0') - BigDecimal.new("#{ta_proportion}")) + final_score = final_ta_score + final_s_score + student_work.final_score = format("%.2f",final_score.to_f) + end + if student_work.final_score + score = student_work.final_score - student_work.absence_penalty - student_work.late_penalty - student_work.appeal_penalty + student_work.work_score = format("%.2f",(score < 0 ? 0 : score).to_f) if score + else + student_work.work_score = nil + end + end + elsif homework.homework_type == 2 && homework.homework_detail_programing #编程作业-----设定:系统评分必定不为空 + if homework.teacher_priority == 1 #教师优先 + if student_work.teacher_score + student_work.final_score = student_work.teacher_score + student_work.work_score = student_work.teacher_score - student_work.absence_penalty - student_work.late_penalty - student_work.appeal_penalty + else + if student_work.teaching_asistant_score.nil? #教辅未评分 + if student_work.student_score.nil? + student_work.final_score = student_work.system_score + else + ta_proportion = homework.homework_detail_programing.ta_proportion + homework.homework_detail_manual.ta_proportion / 2 + final_sy_score = BigDecimal.new("#{student_work.system_score || 0}") * BigDecimal.new("#{ta_proportion}") + final_st_score = BigDecimal.new("#{student_work.student_score}") * (BigDecimal.new('1.0') - BigDecimal.new("#{ta_proportion}")) + final_score = final_sy_score + final_st_score + student_work.final_score = format("%.2f",final_score.to_f) + end + elsif student_work.student_score.nil? #学生未评分 + if student_work.teaching_asistant_score.nil? + student_work.final_score = student_work.system_score + else + ta_proportion = homework.homework_detail_programing.ta_proportion + (1.0 - homework.homework_detail_manual.ta_proportion - homework.homework_detail_programing.ta_proportion) / 2 + final_sy_score = BigDecimal.new("#{student_work.system_score || 0}") * BigDecimal.new("#{ta_proportion}") + final_ts_score = BigDecimal.new("#{student_work.teaching_asistant_score}") * (BigDecimal.new('1.0') - BigDecimal.new("#{ta_proportion}")) + final_score = final_sy_score + final_ts_score + student_work.final_score = format("%.2f",final_score.to_f) + end + else + final_sy_score = BigDecimal.new("#{student_work.system_score || 0}") * BigDecimal.new("#{homework.homework_detail_programing.ta_proportion}") + final_ts_score = BigDecimal.new("#{student_work.teaching_asistant_score}") * BigDecimal.new("#{homework.homework_detail_manual.ta_proportion}") + final_st_score = BigDecimal.new("#{student_work.student_score}") * (BigDecimal.new('1.0') - BigDecimal.new("#{homework.homework_detail_programing.ta_proportion}") - BigDecimal.new("#{homework.homework_detail_manual.ta_proportion}")) + final_score = final_sy_score + final_ts_score + final_st_score + student_work.final_score = format("%.2f",final_score.to_f) + end + if student_work.final_score + score = student_work.final_score - student_work.absence_penalty - student_work.late_penalty - student_work.appeal_penalty + student_work.work_score = format("%.2f",(score < 0 ? 0 : score).to_f) if score + else + student_work.work_score = nil + end + end + else #不考虑教师评分 + if student_work.teaching_asistant_score.nil? #教辅未评分 + if student_work.student_score.nil? + student_work.final_score = student_work.system_score + else + ta_proportion = homework.homework_detail_programing.ta_proportion + homework.homework_detail_manual.ta_proportion / 2 + final_sy_score = BigDecimal.new("#{student_work.system_score || 0}") * BigDecimal.new("#{ta_proportion}") + final_st_score = BigDecimal.new("#{student_work.student_score}") * (BigDecimal.new('1.0') - BigDecimal.new("#{ta_proportion}")) + final_score = final_sy_score + final_st_score + student_work.final_score = format("%.2f",final_score.to_f) + end + elsif student_work.student_score.nil? #学生未评分 + if student_work.teaching_asistant_score.nil? + student_work.final_score = student_work.system_score + else + ta_proportion = homework.homework_detail_programing.ta_proportion + (1.0 - homework.homework_detail_manual.ta_proportion - homework.homework_detail_programing.ta_proportion) / 2 + final_sy_score = BigDecimal.new("#{student_work.system_score || 0}") * BigDecimal.new("#{ta_proportion}") + final_ts_score = BigDecimal.new("#{student_work.teaching_asistant_score}") * (BigDecimal.new('1.0') - BigDecimal.new("#{ta_proportion}")) + final_score = final_sy_score + final_ts_score + student_work.final_score = format("%.2f",final_score.to_f) + end + else + final_sy_score = BigDecimal.new("#{student_work.system_score || 0}") * BigDecimal.new("#{homework.homework_detail_programing.ta_proportion}") + final_ts_score = BigDecimal.new("#{student_work.teaching_asistant_score}") * BigDecimal.new("#{homework.homework_detail_manual.ta_proportion}") + final_st_score = BigDecimal.new("#{student_work.student_score}") * (BigDecimal.new('1.0') - BigDecimal.new("#{homework.homework_detail_programing.ta_proportion}") - BigDecimal.new("#{homework.homework_detail_manual.ta_proportion}")) + final_score = final_sy_score + final_ts_score + final_st_score + student_work.final_score = format("%.2f",final_score.to_f) + end + if student_work.final_score + score = student_work.final_score - student_work.absence_penalty - student_work.late_penalty - student_work.appeal_penalty + student_work.work_score = format("%.2f",(score < 0 ? 0 : score).to_f) if score + else + student_work.work_score = nil + end + end + end + end +end + + +def quote_resource_bank resource, course + atta = Attachment.new(:filename => resource.filename, :disk_filename => resource.disk_filename, :filesize => resource.filesize, :digest => resource.digest, :downloads => 0, :is_publish => 0, + :author_id => User.current.id, :description => resource.description, :disk_directory => resource.disk_directory, :is_public => 0, :copy_from => resource.copy_from.nil? ? resource.id : resource.copy_from, + :quotes => 0, :resource_bank_id => resource.id, :created_on => Time.now, :content_type =>resource.content_type) + if course.attachments << atta + # 更新引用次数 + quotes = resource.quotes.to_i + 1 + resource.update_attribute(:quotes, quotes) + end +end + +def quote_homework_bank homework, course + new_homework = HomeworkCommon.new(:name => homework.name, :user_id => User.current.id, :description => homework.description, :homework_type => homework.homework_type, :late_penalty => 0, + :course_id => course.id, :teacher_priority => 1, :anonymous_comment => 1, :quotes => 0, :is_open => 0, :homework_bank_id => homework.id, :score_open => 1, + :anonymous_appeal => 0, :is_public => 0, :reference_answer => homework.reference_answer, :answer_public => 1, :allow_late => 1) + + new_homework.homework_detail_manual = HomeworkDetailManual.new + new_homework_detail_manual = new_homework.homework_detail_manual + new_homework_detail_manual.te_proportion = 1.0 + new_homework_detail_manual.ta_proportion = 0 + new_homework_detail_manual.comment_status = 0 + + new_homework_detail_manual.evaluation_num = 0 + new_homework_detail_manual.absence_penalty = 0 + + if new_homework.homework_type == 2 + new_homework.homework_detail_programing = HomeworkDetailPrograming.new + new_homework.homework_detail_programing.ta_proportion = 0 + new_homework.homework_detail_programing.language = homework.language + homework.homework_bank_tests.each_with_index do |homework_test| + new_homework.homework_tests << HomeworkTest.new( + input: homework_test.input, + output: homework_test.output + ) + end + homework.homework_bank_samples.each_with_index do |homework_test| + new_homework.homework_samples << HomeworkSample.new( + input: homework_test.input, + output: homework_test.output + ) + end + end + + if new_homework.homework_type == 3 + new_homework.homework_detail_group = HomeworkDetailGroup.new + new_homework.homework_detail_group.min_num = homework.min_num + new_homework.homework_detail_group.max_num = homework.max_num + new_homework.homework_detail_group.base_on_project = homework.base_on_project + end + + homework.attachments.each do |attachment| + att = attachment.copy + att.container_id = nil + att.container_type = nil + att.author_id = homework.user_id + att.copy_from = attachment.id + att.save + new_homework.attachments << att + end + + if new_homework.save + if new_homework.homework_type == 4 + HomeworkCommonsShixuns.create(:homework_common_id => new_homework.id, :shixun_id => homework.homework_bank_shixun.shixun_id) + end + new_homework_detail_manual.save if new_homework_detail_manual + new_homework.homework_detail_programing.save if new_homework.homework_detail_programing + new_homework.homework_detail_group.save if new_homework.homework_detail_group + homework.update_column(:quotes, homework.quotes+1) + end +end + diff --git a/app/helpers/challenges_helper.rb b/app/helpers/challenges_helper.rb index 06d71f9bb..dd63cc007 100644 --- a/app/helpers/challenges_helper.rb +++ b/app/helpers/challenges_helper.rb @@ -11,4 +11,18 @@ module ChallengesHelper "复杂" end end + + def find_game_status challenge_id + game = Game.where(:challenge_id => challenge_id, :user_id => User.current.id).first + case game.try(:status) + when 0 + "".html_safe + when 1 + "评测中" + when 2 + "".html_safe + when 3,nil + "".html_safe + end + end end diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index 7a03a58ef..ae3497878 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -78,7 +78,9 @@ module CoursesHelper #生成课程老师成员链接 def course_teacher_link teacher_num - if User.current.member_of_course?(@course) || User.current.admin? + if User.current.allowed_to?(:as_teacher, @course) + link_to "#{teacher_num}", settings_course_path(@course, :tab => 'member'), :class => 'mr5 link-color-blue', :id => 'teacher_number' + elsif User.current.member_of_course?(@course) link_to "#{teacher_num}", course_member_path(@course, :role => 't'), :class => 'mr5 link-color-blue', :id => 'teacher_number' else content_tag 'span',teacher_num, :class => 'mr5 color-blue' @@ -87,7 +89,9 @@ module CoursesHelper #生成课程学生列表连接 def course_student_link student_num - if (User.current.logged? && @course.open_student == 1) || (User.current.member_of_course?(@course)) || User.current.admin? + if User.current.allowed_to?(:as_teacher, @course) + link_to "#{student_num}", settings_course_path(@course, :tab => 'member', :role => 'as'), :class => 'mr5 link-color-blue', :id => 'student_number' + elsif (User.current.logged? && @course.open_student == 1) || (User.current.member_of_course?(@course)) link_to "#{student_num}", course_member_path(@course, :role => 'as'), :class => 'mr5 link-color-blue', :id => "student_number" else content_tag 'span',student_num, :class => 'mr5 color-blue' @@ -96,8 +100,10 @@ module CoursesHelper # 生成分班列表连接 def course_group_link group_num - if (User.current.logged? && @course.open_student == 1) || (User.current.member_of_course?(@course)) || User.current.admin? - link_to "#{group_num}", course_member_path(@course, :role => @course.course_groups.first.id), :class => 'sy_cblue', :id => "student_number" + if User.current.allowed_to?(:as_teacher, @course) + link_to "#{group_num}", settings_course_path(@course, :tab => 'member', :role => @course.course_groups.first.id), :class => 'mr5 link-color-blue', :id => 'group_number' + elsif (User.current.logged? && @course.open_student == 1) || (User.current.member_of_course?(@course)) + link_to "#{group_num}", course_member_path(@course, :role => @course.course_groups.first.id), :class => 'mr5 link-color-blue', :id => "group_number" else content_tag 'span',group_num, :class => 'sy_cblue' end @@ -827,26 +833,6 @@ module CoursesHelper link.html_safe end - # 可以查看到资源库的资源 - def visable_attachemnts_incourse course - return[] unless course - result = [] - course.attachments.each do |attachment| - if attachment.is_public? && attachment.is_publish == 1 || User.current == attachment.author || User.current.allowed_to?(:as_teacher,course) || (User.current.member_of_course?(course) && attachment.is_publish == 1) || User.current.admin? - result << attachment - end - end - result - end - - def visable_course_homework course - if User.current.admin? || User.current.allowed_to?(:as_teacher,course) - homework_num = course.homework_commons.count - else - homework_num = course.homework_commons.where("publish_time <= '#{Time.now}'").count - end - homework_num - end def zh_course_role role if role == "TeachingAsistant" diff --git a/app/helpers/discusses_helper.rb b/app/helpers/discusses_helper.rb new file mode 100644 index 000000000..544945763 --- /dev/null +++ b/app/helpers/discusses_helper.rb @@ -0,0 +1,2 @@ +module DiscussesHelper +end diff --git a/app/helpers/homework_bank_helper.rb b/app/helpers/homework_bank_helper.rb new file mode 100644 index 000000000..fbb669ff3 --- /dev/null +++ b/app/helpers/homework_bank_helper.rb @@ -0,0 +1,2 @@ +module HomeworkBankHelper +end diff --git a/app/helpers/management_helper.rb b/app/helpers/management_helper.rb new file mode 100644 index 000000000..c313ee671 --- /dev/null +++ b/app/helpers/management_helper.rb @@ -0,0 +1,5 @@ +module ManagementHelper + + + +end diff --git a/app/helpers/managements_helper.rb b/app/helpers/managements_helper.rb new file mode 100644 index 000000000..c1dac27f6 --- /dev/null +++ b/app/helpers/managements_helper.rb @@ -0,0 +1,20 @@ +module ManagementsHelper + + def trial_authorization_status status + case status + when "0", nil + 0 + when "1" + 1 + when "2" + 2 + else + [1,2] + end + end + + def query_user_status_num status + user = (status == 0) ? user = User.all : User.where(:status => status) + return user.count + end +end diff --git a/app/helpers/owner_type_helper.rb b/app/helpers/owner_type_helper.rb index 110bc3d58..9124a4f98 100644 --- a/app/helpers/owner_type_helper.rb +++ b/app/helpers/owner_type_helper.rb @@ -12,4 +12,7 @@ module OwnerTypeHelper ArticleHomepage = 11 PROJECT = 12 CONTEST = 13 + HOMEWORKREFERENCEANSWER = 14 + STUDENTWORK = 15 + HOMEWORKBANK = 16 end \ No newline at end of file diff --git a/app/helpers/shixuns_helper.rb b/app/helpers/shixuns_helper.rb index 635645587..6a9004aca 100644 --- a/app/helpers/shixuns_helper.rb +++ b/app/helpers/shixuns_helper.rb @@ -21,4 +21,5 @@ module ShixunsHelper def had_passed_challenge challenge Game.where(:challenge_id => challenge.id, :status => 2).limit(3).reorder("final_score desc") end + end diff --git a/app/helpers/stages_helper.rb b/app/helpers/stages_helper.rb new file mode 100644 index 000000000..93ca31e89 --- /dev/null +++ b/app/helpers/stages_helper.rb @@ -0,0 +1,2 @@ +module StagesHelper +end diff --git a/app/helpers/student_work_helper.rb b/app/helpers/student_work_helper.rb index 89a9455f5..65703baa7 100644 --- a/app/helpers/student_work_helper.rb +++ b/app/helpers/student_work_helper.rb @@ -73,6 +73,73 @@ module StudentWorkHelper str end + # 作品列表的提交状态 + def list_work_status status + case status + when 0 + str = "未提交" + when 1 + str = "按时提交" + when 2 + str = "延时提交" + end + end + + # 作品的助教评分模式 + def ta_score_mode homework + mode = homework.homework_detail_manual.ta_mode == 1 ? '平均' : '复审' + mode + end + + #根据传入作业确定显示为编辑作品还是新建作品,或者显示作品数量 + def user_work_status homework + if User.current.logged? + if User.current.member_of_course?(homework.course) + work = cur_user_works_for_homework homework + project = cur_user_projects_for_homework homework + if work.nil? && homework.end_time >= Time.now + if homework.homework_type == 4 + link_to "关联实战", relate_myshixun_student_work_index_path(:homework => homework.id),:class => 'task-btn task-btn-blue fr',:remote => true + else + link_to "提交作品", new_student_work_url_without_domain(homework.id),:class => 'task-btn task-btn-blue fr' + end + elsif work.nil? && homework.end_time < Time.now + if homework.allow_late && homework.homework_detail_manual.comment_status < 6 + if homework.homework_type == 4 + link_to "关联实战", relate_myshixun_student_work_index_path(:homework => homework.id),:class => 'task-btn task-btn-blue fr',:remote => true + else + link_to "补交作品", new_student_work_url_without_domain(homework.id),:class => 'task-btn task-btn-blue fr' + end + end + elsif work + if homework.homework_type == 4 + myshixun = Myshixun.find work.myshixun_id + link_to "继续实战", myshixun_game_path(myshixun.current_task, :myshixun_id => myshixun), :class => "task-btn task-btn-blue fr mr10",:target => "_blank" if myshixun + else + if homework.homework_detail_manual && homework.homework_detail_manual.comment_status == 3 && StudentWorksEvaluationDistribution.where("student_work_id = #{work.id}").count > 0 #匿评作业,且作业状态不是在开启匿评之前 + if homework.homework_type != 3 + link_to "匿评作品", student_work_index_url_in_org(homework.id, 2), :class => 'task-btn task-btn-blue fr', :title => "开启匿评后不可修改作品" + else + work_ids = "(" + homework.student_works.has_committed.map(&:id).join(",") + ")" + if User.current.student_works_evaluation_distributions.where("student_work_id IN #{work_ids}").count > 0 + link_to "匿评作品", student_work_index_url_in_org(homework.id, 2), :class => 'task-btn task-btn-blue fr', :title => "开启匿评后不可修改作品" + else + link_to "查看作品", student_work_path(work), :class => 'task-btn task-btn-blue fr', :title => "匿评开启后提交的作品不参与匿评" + end + end + elsif homework.homework_detail_manual && homework.homework_detail_manual.comment_status > 3 + link_to "查看作品", student_work_path(work), :class => 'task-btn task-btn-blue fr', :title => "匿评已结束" + elsif homework.end_time >= Time.now && work.user_id == User.current.id + link_to "修改作品", edit_student_work_url_without_domain(work.id),:class => 'task-btn task-btn-blue fr' + else + link_to "查看作品", student_work_path(work), :class => 'task-btn task-btn-blue fr', :title => "作业截止后不可修改作品" + end + end + end + end + end + end + #获取学生作品的评分记录:同一个教师或教辅只显示未隐藏的评分 def student_work_score_record work # sql = "SELECT MAX(id) id FROM student_works_scores WHERE (reviewer_role = 2 OR reviewer_role = 1) AND score IS NOT NULL AND is_hidden = 0 AND student_work_id = #{work.id} GROUP BY user_id" @@ -173,15 +240,29 @@ module StudentWorkHelper return status end - def group_student_works student_work, homework - pros = student_work.student_work_projects.where("is_leader = 0") + def group_member_work student_work + member_work = nil + if student_work.student_work_projects.count > 0 + member_work = student_work + else + student_work_pro = StudentWorkProject.where(:user_id => student_work.user_id, :homework_common_id => student_work.homework_common_id).first + if student_work_pro + member_work = StudentWork.find student_work_pro.student_work_id + end + end + member_work + end + + def group_student_works member_work, student_work, homework + pros = member_work.student_work_projects.where("user_id != #{student_work.user_id}") user_ids = pros.empty? ? "(-1)" : "(" + pros.map{|stu|stu.user_id}.join(",") + ")" student_works = homework.student_works.where("user_id in #{user_ids}") return student_works end def add_score_to_member student_work, homework, new_score - student_works = group_student_works student_work, homework + member_work = group_member_work student_work + student_works = group_student_works member_work, student_work, homework student_works.each do |st_work| st_work.student_works_scores << StudentWorksScore.create(:user_id => new_score.user_id, :score => new_score.score, :reviewer_role => new_score.reviewer_role, :comment => new_score.comment) if new_score.reviewer_role == 1 @@ -190,7 +271,7 @@ module StudentWorkHelper ts_score = StudentWorksScore.find_by_sql("SELECT AVG(score) AS score FROM (SELECT * FROM (SELECT * FROM student_works_scores WHERE student_work_id = #{st_work.id} AND reviewer_role = 2 AND score IS NOT NULL ORDER BY created_at DESC) AS t GROUP BY user_id) AS a") st_work.teaching_asistant_score = ts_score.first.score.nil? ? nil : ts_score.first.score.try(:round, 2).to_f else - st_work.student_score = student_work.student_score + st_work.student_score = member_work.student_score end st_work.save end diff --git a/app/helpers/subjects_helper.rb b/app/helpers/subjects_helper.rb new file mode 100644 index 000000000..2e47f7801 --- /dev/null +++ b/app/helpers/subjects_helper.rb @@ -0,0 +1,2 @@ +module SubjectsHelper +end diff --git a/app/helpers/syllabuses_helper.rb b/app/helpers/syllabuses_helper.rb index 674541d11..bfb5b199b 100644 --- a/app/helpers/syllabuses_helper.rb +++ b/app/helpers/syllabuses_helper.rb @@ -102,6 +102,21 @@ module SyllabusesHelper content end + def syllabus_major_option fir_dis = 213 + content = [] + option0 = [] + option0 << "选择课程所属专业" + option0 << 0 + content << option0 + Major.where(:first_level_discipline_id => fir_dis).each do |major| + option = [] + option << major.name.to_s + option << major.id + content << option + end + content + end + def syllabus_type_option content = [] option0 = [] @@ -131,74 +146,4 @@ module SyllabusesHelper content end - def sy_resources syllabus - courses = syllabus.courses.not_deleted - attachments = Attachment.where(:container_type => 'Course', :container_id => courses.map(&:id)) - resources = ResourceBank.where(:id => attachments.map(&:resource_bank_id)) - resources - end - - def sy_homeworks syllabus - courses = syllabus.courses.not_deleted - homeworks = HomeworkCommon.where(:course_id => courses.map(&:id)) - homeworks = HomeworkBank.where(:id => homeworks.map(&:homework_bank_id)) - homeworks - end - - def quote_resource_bank resource, course - atta = Attachment.new(:filename => resource.filename, :disk_filename => resource.disk_filename, :filesize => resource.filesize, :digest => resource.digest, :downloads => 0, :is_publish => 0, - :author_id => User.current.id, :description => resource.description, :disk_directory => resource.disk_directory, :is_public => 0, :copy_from => resource.copy_from.nil? ? resource.id : resource.copy_from, - :quotes => 0, :resource_bank_id => resource.id, :created_on => Time.now, :content_type =>resource.content_type) - if course.attachments << atta - # 更新引用次数 - quotes = resource.quotes.to_i + 1 - resource.update_attribute(:quotes, quotes) - end - end - - def quote_homework_bank homework, course - new_homework = HomeworkCommon.new(:name => homework.name, :user_id => User.current.id, :description => homework.description, :homework_type => homework.homework_type, :late_penalty => 0, - :course_id => course.id, :teacher_priority => 1, :anonymous_comment => 1, :quotes => 0, :is_open => 0, - :homework_bank_id => homework.id, :score_open => 1, :anonymous_appeal => 0) - - new_homework.homework_detail_manual = HomeworkDetailManual.new - new_homework_detail_manual = new_homework.homework_detail_manual - new_homework_detail_manual.ta_proportion = new_homework.homework_type == 2 ? 0.4 : 1.0 - new_homework_detail_manual.comment_status = 0 - new_homework_detail_manual.evaluation_num = 3 - new_homework_detail_manual.absence_penalty = 0 - - if new_homework.homework_type == 2 - new_homework.homework_detail_programing = HomeworkDetailPrograming.new - new_homework.homework_detail_programing.ta_proportion = 0.6 - new_homework.homework_detail_programing.language = homework.language - homework.homework_bank_tests.each_with_index do |homework_test| - if homework_test.test_type - new_homework.homework_tests << HomeworkTest.new( - input: homework_test.input, - output: homework_test.output - ) - else - new_homework.homework_samples << HomeworkSample.new( - input: homework_test.input, - output: homework_test.output - ) - end - end - end - - if new_homework.homework_type == 3 - new_homework.homework_detail_group = HomeworkDetailGroup.new - new_homework.homework_detail_group.min_num = homework.min_num - new_homework.homework_detail_group.max_num = homework.max_num - new_homework.homework_detail_group.base_on_project = homework.base_on_project - end - - if new_homework.save - new_homework_detail_manual.save if new_homework_detail_manual - new_homework.homework_detail_programing.save if new_homework.homework_detail_programing - new_homework.homework_detail_group.save if new_homework.homework_detail_group - homework.update_column(:quotes, homework.quotes+1) - end - end end diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index 5de7316a5..c4d46a09d 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -325,11 +325,11 @@ module UsersHelper url = {:controller => 'users', :action => 'update', :id => user, :page => params[:page], :status => params[:status], :tab => nil} if user.locked? - link_to l(:button_unlock), url.merge(:user => {:status => User::STATUS_ACTIVE}), :method => :put, :class => 'icon icon-unlock' + link_to "解锁", url.merge(:user => {:status => User::STATUS_ACTIVE}), :method => :put, :class => 'mr10 link-color-blue' elsif user.registered? link_to l(:button_activate), url.merge(:user => {:status => User::STATUS_ACTIVE}), :method => :put, :class => 'icon icon-unlock' elsif user != User.current - link_to l(:button_lock), url.merge(:user => {:status => User::STATUS_LOCKED}), :method => :put, :class => 'icon icon-lock' + link_to "加锁", url.merge(:user => {:status => User::STATUS_LOCKED}), :method => :put, :class => 'mr10 link-color-blue' end end diff --git a/app/models/apply_action.rb b/app/models/apply_action.rb new file mode 100644 index 000000000..2adb74869 --- /dev/null +++ b/app/models/apply_action.rb @@ -0,0 +1,7 @@ +# status:0 审核中 1 同意 2 拒绝 3 撤销 +class ApplyAction < ActiveRecord::Base + default_scope :order => 'updated_at desc' + attr_accessible :container_id, :container_type, :dealer_id, :reason, :user_id, :status + + belongs_to :user +end diff --git a/app/models/authentication.rb b/app/models/authentication.rb new file mode 100644 index 000000000..77cc49b8d --- /dev/null +++ b/app/models/authentication.rb @@ -0,0 +1,8 @@ +class Authentication < ActiveRecord::Base + attr_accessible :level, :permissions + serialize :permissions, Array + has_and_belongs_to_many :users + # has_many :users_authenticationses + # has_many :users, :through => :users_authenticationses + +end diff --git a/app/models/authentications_users.rb b/app/models/authentications_users.rb new file mode 100644 index 000000000..3805a6a8a --- /dev/null +++ b/app/models/authentications_users.rb @@ -0,0 +1,3 @@ +class AuthenticationsUsers < ActiveRecord::Base + attr_accessible :authentication_id, :user_id +end diff --git a/app/models/challenge.rb b/app/models/challenge.rb index e27d23d97..82b776c86 100644 --- a/app/models/challenge.rb +++ b/app/models/challenge.rb @@ -1,3 +1,4 @@ +#coding=utf-8 class Challenge < ActiveRecord::Base default_scope :order => 'position' belongs_to :shixun,:touch=> true @@ -8,10 +9,23 @@ class Challenge < ActiveRecord::Base has_many :games, :dependent => :destroy validates_presence_of :subject - validates_presence_of :score + # validates_presence_of :score validates_presence_of :task_pass validates_length_of :subject, :maximum => 255 + def game_difficulty + str = "简单" + case self.difficulty + when 1 + str = "简单" + when 2 + str = "中等" + when 3 + str = "困难" + end + str + end + def next_challenge challenge_count = Challenge.where(:shixun_id => self.shixun_id).count render_404 if self.position ==challenge_count diff --git a/app/models/course.rb b/app/models/course.rb index 20c558614..77bc0e757 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -24,7 +24,7 @@ class Course < ActiveRecord::Base end end - attr_accessible :code, :extra, :name, :state, :tea_id, :time , :location, :state, :term, :password,:is_public,:description,:class_period, :open_student, :enterprise_name, :is_delete, :syllabus_id, :end_time, :end_term, :choose_group_allow + attr_accessible :code, :extra, :name, :state, :tea_id, :time , :location, :state, :term, :password,:is_public,:description,:class_period, :open_student, :enterprise_name, :is_delete, :syllabus_id, :end_time, :end_term, :choose_group_allow, :is_end #belongs_to :project, :class_name => 'Course', :foreign_key => :extra, primary_key: :identifier belongs_to :teacher, :class_name => 'User', :foreign_key => :tea_id # 定义一个方法teacher,该方法通过tea_id来调用User表 belongs_to :school, :class_name => 'School', :foreign_key => :school_id #定义一个方法school,该方法通过school_id来调用School表 @@ -66,6 +66,8 @@ class Course < ActiveRecord::Base # 课程贡献榜 has_many :course_contributor_scores, :dependent => :destroy + #课程模块 + has_many :course_modules, :dependent => :destroy acts_as_taggable acts_as_nested_set :order => 'name', :dependent => :destroy acts_as_attachable :view_permission => :view_course_files, @@ -101,12 +103,15 @@ class Course < ActiveRecord::Base 'syllabus_id', 'end_time', 'end_term', - 'os_allow' - 'choose_group_allow' + 'os_allow', + 'choose_group_allow', + 'credit' acts_as_customizable scope :not_deleted, lambda{where(is_delete: 0)} + scope :not_deleted_not_end, lambda{where(is_delete: 0, is_end: 0)} + scope :not_deleted_but_is_end, lambda{where(is_end: 1, is_delete: 0)} scope :all_course scope :active, lambda { where(:status => STATUS_ACTIVE) } scope :status, lambda {|arg| where(arg.blank? ? nil : {:status => arg.to_i}) } @@ -354,6 +359,19 @@ class Course < ActiveRecord::Base end end + # 创建课程模块 + def create_course_modules + mod = self.course_modules + if mod.blank? + type = ["news", "boards", "attachment", "homework", "poll", "exercises", "statistics"] + for i in 0..6 + CourseModule.create(:course_id => self.id, :module_type => type[i], :position => i + 1, :hidden => 0 ) + end + mod = self.course_modules + end + return mod + end + def get_endup_time begin end_time = Time.parse(self.endup_time) diff --git a/app/models/course_list.rb b/app/models/course_list.rb new file mode 100644 index 000000000..8d6d482f5 --- /dev/null +++ b/app/models/course_list.rb @@ -0,0 +1,5 @@ +class CourseList < ActiveRecord::Base + has_many :major_courses + has_many :shixun_major_courses + attr_accessible :name +end diff --git a/app/models/course_module.rb b/app/models/course_module.rb new file mode 100644 index 000000000..c5b9c1fac --- /dev/null +++ b/app/models/course_module.rb @@ -0,0 +1,6 @@ +class CourseModule < ActiveRecord::Base + # attr_accessible :title, :body + belongs_to :course + attr_accessible :course_id, :module_type, :position, :hidden + +end diff --git a/app/models/discipline_category.rb b/app/models/discipline_category.rb index 2e8ded1bb..26ac6b3c0 100644 --- a/app/models/discipline_category.rb +++ b/app/models/discipline_category.rb @@ -2,4 +2,5 @@ class DisciplineCategory < ActiveRecord::Base attr_accessible :major_level, :name has_many :first_level_disciplines + has_many :majors end diff --git a/app/models/discuss.rb b/app/models/discuss.rb new file mode 100644 index 000000000..dbf0f99ec --- /dev/null +++ b/app/models/discuss.rb @@ -0,0 +1,10 @@ +class Discuss < ActiveRecord::Base + belongs_to :user + attr_accessible :user_id, :content, :dis_id, :dis_type, :parent_id, :praise_count, :root_id + + has_many :praise_tread, as: :praise_tread_object, dependent: :destroy + has_one :praise_tread_cache, as: :object, dependent: :destroy + acts_as_tree :foreign_key => 'parent_id' + belongs_to :dis, :polymorphic => true + validates_presence_of :dis, :user, :content +end diff --git a/app/models/experience.rb b/app/models/experience.rb new file mode 100644 index 000000000..c229f5f35 --- /dev/null +++ b/app/models/experience.rb @@ -0,0 +1,3 @@ +class Experience < ActiveRecord::Base + attr_accessible :container_id, :container_type, :score, :user_id +end diff --git a/app/models/first_level_discipline.rb b/app/models/first_level_discipline.rb index ce610cc31..4e792b2de 100644 --- a/app/models/first_level_discipline.rb +++ b/app/models/first_level_discipline.rb @@ -2,4 +2,5 @@ class FirstLevelDiscipline < ActiveRecord::Base belongs_to :discipline_category attr_accessible :name has_many :syllabuses + has_many :majors end diff --git a/app/models/game.rb b/app/models/game.rb index c033d64b7..44129ac33 100644 --- a/app/models/game.rb +++ b/app/models/game.rb @@ -1,13 +1,14 @@ class Game < ActiveRecord::Base # stauts 0: can exe 1:doing 2:successed 3:locked default_scope :order => 'created_at desc' - attr_accessible :myshixun_id, :user_id, :status, :final_score, :challenge_id, :open_time, :identifier, :answer_open, :end_time, :retry_status + attr_accessible :myshixun_id, :user_id, :status, :final_score, :challenge_id, :open_time, :identifier, :answer_open, :end_time, :retry_status, :resubmit_identifier belongs_to :myshixun,:touch=> true belongs_to :user belongs_to :challenge has_many :outputs, :dependent => :destroy - has_many :test_sets + has_many :test_sets, :dependent => :destroy has_many :challenge_samples + has_one :game_code, :dependent => :destroy def had_done myshixun = self.myshixun diff --git a/app/models/game_code.rb b/app/models/game_code.rb new file mode 100644 index 000000000..cb9eda249 --- /dev/null +++ b/app/models/game_code.rb @@ -0,0 +1,4 @@ +class GameCode < ActiveRecord::Base + attr_accessible :game_id, :new_code, :original_code, :path + belongs_to :game +end diff --git a/app/models/homework_bank.rb b/app/models/homework_bank.rb index 0f89c74d9..6cd699bbd 100644 --- a/app/models/homework_bank.rb +++ b/app/models/homework_bank.rb @@ -2,7 +2,11 @@ class HomeworkBank < ActiveRecord::Base # attr_accessible :title, :body belongs_to :user - has_many :homework_bank_tests + belongs_to :syllabus + has_many :homework_bank_tests, :dependent => :destroy + has_many :homework_bank_samples, :dependent => :destroy + has_many :homework_commons + has_one :homework_bank_shixun acts_as_attachable def language_name diff --git a/app/models/homework_bank_sample.rb b/app/models/homework_bank_sample.rb new file mode 100644 index 000000000..7b64f93a9 --- /dev/null +++ b/app/models/homework_bank_sample.rb @@ -0,0 +1,4 @@ +class HomeworkBankSample < ActiveRecord::Base + belongs_to :homework_bank + attr_accessible :input, :output, :homework_bank_id +end diff --git a/app/models/homework_bank_shixun.rb b/app/models/homework_bank_shixun.rb new file mode 100644 index 000000000..3bec23fcd --- /dev/null +++ b/app/models/homework_bank_shixun.rb @@ -0,0 +1,5 @@ +class HomeworkBankShixun < ActiveRecord::Base + belongs_to :homework_bank + belongs_to :shixun + attr_accessible :homework_bank_id, :shixun_id +end diff --git a/app/models/homework_common.rb b/app/models/homework_common.rb index 440eff661..961aabc9d 100644 --- a/app/models/homework_common.rb +++ b/app/models/homework_common.rb @@ -14,6 +14,7 @@ class HomeworkCommon < ActiveRecord::Base has_one :homework_detail_manual, :dependent => :destroy has_one :homework_detail_programing, :dependent => :destroy has_one :homework_detail_group, :dependent => :destroy + has_one :homework_commons_shixuns has_many :student_work_projects, :dependent => :destroy has_many :homework_tests, :dependent => :destroy has_many :homework_samples, :dependent => :destroy @@ -24,6 +25,7 @@ class HomeworkCommon < ActiveRecord::Base has_many :praise_tread, as: :praise_tread_object, dependent: :destroy has_one :praise_tread_cache, as: :object, dependent: :destroy has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy #用户活动 + has_and_belongs_to_many :shixuns # 课程动态 has_many :course_acts, :class_name => 'CourseActivity',:as =>:course_act ,:dependent => :destroy # 课程消息 @@ -59,6 +61,8 @@ class HomeworkCommon < ActiveRecord::Base type = "编程" when 3 type = "分组" + when 4 + type = "实训" end type end diff --git a/app/models/homework_commons_shixuns.rb b/app/models/homework_commons_shixuns.rb new file mode 100644 index 000000000..c55f101c2 --- /dev/null +++ b/app/models/homework_commons_shixuns.rb @@ -0,0 +1,5 @@ +class HomeworkCommonsShixuns < ActiveRecord::Base + attr_accessible :homework_common_id, :shixun_id + belongs_to :homework_common + belongs_to :shixun +end diff --git a/app/models/homework_detail_manual.rb b/app/models/homework_detail_manual.rb index 6faa84d40..de289b54f 100644 --- a/app/models/homework_detail_manual.rb +++ b/app/models/homework_detail_manual.rb @@ -1,5 +1,5 @@ #手动评分作业表 -#comment_status: 1:未开启匿评,2:开启匿评,3:匿评结束 +#comment_status: 0:挂起, 1:提交,2:补交(去掉),3:匿评中,4:申诉中,5:评阅中,6:已结束 class HomeworkDetailManual < ActiveRecord::Base attr_accessible :ta_proportion, :comment_status, :evaluation_start, :evaluation_end, :evaluation_num, :absence_penalty, :homework_common_id, :no_anon_penalty diff --git a/app/models/homework_reference_answer.rb b/app/models/homework_reference_answer.rb new file mode 100644 index 000000000..d3508f0bf --- /dev/null +++ b/app/models/homework_reference_answer.rb @@ -0,0 +1,6 @@ +class HomeworkReferenceAnswer < ActiveRecord::Base + belongs_to :homework_common + attr_accessible :answer, :homework_common_id + + acts_as_attachable +end diff --git a/app/models/mailer.rb b/app/models/mailer.rb index 7fe18d91d..facd8405b 100644 --- a/app/models/mailer.rb +++ b/app/models/mailer.rb @@ -837,12 +837,12 @@ class Mailer < ActionMailer::Base :subject => l(:mail_subject_register, Setting.app_title) end - def bind_email(token, code="111111") + def bind_email(token, code="111111", email) set_language_if_valid(token.user.language) @login = token.user.try(:login) @token = token @code = code - mail :to => token.user.mail, + mail :to => email, :subject => l(:mail_subject_bind_mail, Setting.app_title+"("+Setting.host_name+")") end diff --git a/app/models/major.rb b/app/models/major.rb new file mode 100644 index 000000000..5e521bb78 --- /dev/null +++ b/app/models/major.rb @@ -0,0 +1,8 @@ +class Major < ActiveRecord::Base + belongs_to :first_level_discipline + belongs_to :discipline_category + has_many :major_courses + has_many :shixun_major_courses + has_many :subjects + attr_accessible :major_code, :major_level, :name, :first_level_discipline_id, :discipline_category_id +end diff --git a/app/models/major_course.rb b/app/models/major_course.rb new file mode 100644 index 000000000..0e9732352 --- /dev/null +++ b/app/models/major_course.rb @@ -0,0 +1,5 @@ +class MajorCourse < ActiveRecord::Base + belongs_to :course_list + belongs_to :major + attr_accessible :course_list_id, :major_id +end diff --git a/app/models/myshixun.rb b/app/models/myshixun.rb index 1d062e607..5e57b85e9 100644 --- a/app/models/myshixun.rb +++ b/app/models/myshixun.rb @@ -3,9 +3,12 @@ class Myshixun < ActiveRecord::Base attr_accessible :description, :name, :parent_id, :user_id, :gpid, :forked_from, :visits, :is_public, :identifier # has_many :users, :through => :myshixun_members has_many :myshixun_members, :dependent => :destroy - has_one :repository + has_one :repository, :dependent => :destroy has_many :games, :dependent => :destroy, :order => "games.id ASC" belongs_to :shixun + has_one :shixun_modify, :dependent => :destroy + has_one :webssh, :dependent => :destroy + has_many :student_works def total_stage self.games.count @@ -17,6 +20,34 @@ class Myshixun < ActiveRecord::Base return position end + def done_time + time = "" + if self.status == 1 + time = self.games.order("end_time desc").first.try(:end_time) + end + time + end + + def total_spend_time + time = 0 + self.games.each do |game| + if game.status == 2 + time += (game.end_time -game.open_time).to_i > 0 ? (game.end_time -game.open_time).to_i : 0 + end + end + time + end + + def total_score + score = 0 + self.games.each do |game| + if game.status == 2 + score += game.final_score + end + end + score + end + # id 转换成 identifier def to_param identifier @@ -27,10 +58,10 @@ class Myshixun < ActiveRecord::Base # 如果都完成,则当前任务为最后一个任务 def current_task games = self.games - current_game = games.select{|game| game.status==1 || game.status==0}.first + current_game = games.select{|game| game.status == 1 || game.status == 0}.first if current_game.blank? - passed_games = games.select{|game| game.status==2} - current_game = passed_games.last + passed_games = games.select{|game| game.status == 2} + current_game = passed_games.first end return current_game end diff --git a/app/models/shixun.rb b/app/models/shixun.rb index 5f472ff49..28232c9e6 100644 --- a/app/models/shixun.rb +++ b/app/models/shixun.rb @@ -1,21 +1,104 @@ -# status 控制实训的状态,0:未开启;1: 已开启(TPM); 2:已认证 +# encoding: utf-8 +# status 控制实训的状态,0:编辑;1: 申请发布; 2:正式发布; 3:关闭 +# is_updated 字段为1表示实训的更改可能会影响到后续的评测,0表示更改不会影响后续的评测 +# 繁忙等级参数:80发布实训失败,返回code为-1;81:实训开启的时候fork失败;83:开启实训的时候,openGameInstance返回非0值;84:jenkins系统异常,post数据不成功 +# 85:challenge创建的时候Jenkins处理异常;86:实训评测失败,jenkins返回错误结果; 87:版本库删除异常;88:点击评测失败,没返回数据;89:重置链接jenkins返回失败 +# 90: 更新公共测试用例失败,返回code非0;91:实训有改动,评测的时候初始化数据,返回数据code非0;92:webssh开启失败,接口getConnectInfo返回code值非0 +# 93: 实训断开连接失败,接口deleteSSH返回code值非0 +# 116:challenge创建关卡的时候返回结果错误 +# class Shixun < ActiveRecord::Base - attr_accessible :description, :is_public, :name, :changeset_num, :status, :user_id, :gpid, :language, :identifier, :authentication, :myshixun_count + attr_accessible :description, :is_public, :name, :changeset_num, :status, :user_id, :gpid, :language, :identifier, :authentication, + :myshixun_count, :propaedeutics, :trainee, :major_id has_many :users, :through => :shixun_members - has_many :shixun_members - has_one :repository + has_many :shixun_members, :dependent => :destroy + has_one :repository, :dependent => :destroy + has_many :homework_commons_shixunses has_many :challenges, :dependent => :destroy, :order => "challenges.id ASC" - has_many :myshixuns + has_many :myshixuns, :dependent => :destroy + has_many :stage_shixuns, :dependent => :destroy + belongs_to :major + belongs_to :major_course + has_many :shixun_major_courses, :dependent => :destroy + has_and_belongs_to_many :homework_commons + has_many :discusses, :as => :dis, :dependent => :destroy + + # 获取特定格式的实训测试用例 + # params = {:challengeStage => "#{@challenge.position}", :challengeType => "#{@challenge.evaluation_way.to_i}", + # :challengeProgramName => "#{@challenge.exec_path}", + # :trainingID => "#{@shixun.id}", :operationEnvironment => @shixun.language} + def gameInfo + fragments = [] + testSet = [] + testCases = [] + challenges = self.challenges.includes(:test_sets) + challenges.each do |challenge| + pipeline_script = {:challengeStage => "#{challenge.position}", :challengeType => "#{challenge.evaluation_way.to_i}", :challengeProgramName => "#{challenge.exec_path}", :operationEnvironment => "#{self.language}", :trainingID => "#{self.id}"} + fragments << pipeline_script + # 每一关所有的测试集 + challenge.test_sets.each do |test_set| + test_cases = {:caseId => test_set.id.to_s, :input => test_set.input, :output => test_set.output, :isPublic => (test_set.is_public ? "1" : "0")} + testSet << test_cases + end + test_sets_list = {:challengeStage => challenge.position.to_s, :challengeTestCases => testSet} + testCases << test_sets_list + testSet = [] + end + gameInfo = {:trainingID => self.id.to_s, :operationEnvironment => self.language, :challengeInfo => fragments, :testCases => testCases} + gameInfo = Base64.strict_encode64(gameInfo.to_json) unless gameInfo.blank? + return gameInfo + end # id 转换成 identifier def to_param identifier end + def shixun_trainee + trainee = "" + case self.trainee + when 1 + trainee = "初级学员" + when 2 + trainee = "中级学员" + when 3 + trainee = "高级学员" + when 4 + trainee = "顶级学员" + end + trainee + end + def owner User.find(self.user_id) rescue ActiveRecord::RecordNotFound render_404 end + + def shixun_score + score = 0 + self.challenges.each do |challenge| + score += challenge.score.to_i + end + score + end + + def shixun_status + status = "" + case self.status + when 0 + status = "编辑中" + when 1 + status = "审核中" + when 2 + status = "已发布" + when 3 + status = "已关闭" + end + end + + def collaborators + self.shixun_members.select{|member| member.role == 2} unless self.shixun_members.blank? + end end diff --git a/app/models/shixun_major_course.rb b/app/models/shixun_major_course.rb new file mode 100644 index 000000000..7d288ecf0 --- /dev/null +++ b/app/models/shixun_major_course.rb @@ -0,0 +1,6 @@ +class ShixunMajorCourse < ActiveRecord::Base + belongs_to :shixun + belongs_to :major + belongs_to :course_list + #attr_accessible :course_list +end diff --git a/app/models/shixun_member.rb b/app/models/shixun_member.rb index c39c2521c..beab86fff 100644 --- a/app/models/shixun_member.rb +++ b/app/models/shixun_member.rb @@ -1,4 +1,5 @@ class ShixunMember < ActiveRecord::Base + # role 实训角色: 1 创建者 2 合作者 attr_accessible :shixun_id, :user_id, :role belongs_to :shixun belongs_to :user diff --git a/app/models/shixun_modify.rb b/app/models/shixun_modify.rb new file mode 100644 index 000000000..e92edbc1b --- /dev/null +++ b/app/models/shixun_modify.rb @@ -0,0 +1,4 @@ +class ShixunModify < ActiveRecord::Base + attr_accessible :myshixun_id, :shixun_id, :status + belongs_to :myshixun +end diff --git a/app/models/stage.rb b/app/models/stage.rb new file mode 100644 index 000000000..d284c62e9 --- /dev/null +++ b/app/models/stage.rb @@ -0,0 +1,7 @@ +class Stage < ActiveRecord::Base + belongs_to :subject + belongs_to :user + attr_accessible :description, :name, :position, :subject_id, :user_id + + has_many :stage_shixuns, :dependent => :destroy, :order => "stage_shixuns.position ASC" +end diff --git a/app/models/stage_shixun.rb b/app/models/stage_shixun.rb new file mode 100644 index 000000000..8ad272e08 --- /dev/null +++ b/app/models/stage_shixun.rb @@ -0,0 +1,6 @@ +class StageShixun < ActiveRecord::Base + belongs_to :subject + belongs_to :stage + belongs_to :shixun + attr_accessible :position, :subject_id, :stage_id, :shixun_id +end diff --git a/app/models/student_work.rb b/app/models/student_work.rb index 9ea0e75eb..cc800cbb6 100644 --- a/app/models/student_work.rb +++ b/app/models/student_work.rb @@ -1,6 +1,7 @@ #学生提交作品表 #work_status :0 未提交 1 已提交 2 迟交 3 分组作品复制的组员作品 class StudentWork < ActiveRecord::Base - attr_accessible :name, :description, :homework_common_id, :user_id, :final_score, :teacher_score, :student_score, :teaching_asistant_score, :system_score, :work_score, :project_id, :is_test, :simi_id, :simi_value, :work_status, :commit_time, :late_penalty, :absence_penalty, :re_commit + attr_accessible :name, :description, :homework_common_id, :user_id, :final_score, :teacher_score, :student_score, :teaching_asistant_score, :system_score, :work_score, :project_id, :is_test, :simi_id, + :simi_value, :work_status, :commit_time, :late_penalty, :absence_penalty, :re_commit, :late_reason, :group_id belongs_to :homework_common belongs_to :user @@ -12,9 +13,10 @@ class StudentWork < ActiveRecord::Base # course's message has_many :course_messages, :class_name =>'CourseMessage', :as => :course_message, :dependent => :destroy has_many :attachments, :dependent => :destroy + has_one :myshixun scope :has_committed, lambda{where("work_status != 0 and work_status != 3")} - scope :no_copy, lambda{where("work_status != 3")} + scope :all_commit, lambda{where("work_status != 0")} before_destroy :delete_praise before_save :set_program_score, :set_src diff --git a/app/models/students_for_course.rb b/app/models/students_for_course.rb index f3e0cb530..594793506 100644 --- a/app/models/students_for_course.rb +++ b/app/models/students_for_course.rb @@ -10,7 +10,7 @@ class StudentsForCourse < ActiveRecord::Base validates_uniqueness_of :student_id, :scope => :course_id after_destroy :delete_student_works, :delete_course_homework_statistic - after_create :recovery_student_works, :create_student_works, :create_course_homework_statistic, :create_course_contribute_score + after_create :recovery_student_works, :create_student_works #退出班级或删除学生时隐藏学生的作品 def delete_student_works @@ -23,50 +23,59 @@ class StudentsForCourse < ActiveRecord::Base #加入班级时还原作品 def recovery_student_works course = self.course - homework_ids = course.homework_commons.blank? ? "(-1)" : "(" + course.homework_commons.map{|hw| hw.id}.join(",") + ")" - student_works = StudentWork.where("user_id = #{self.student_id} && homework_common_id in #{homework_ids}") + homework_ids = course.homework_commons.map(&:id) + student_works = StudentWork.where(:user_id => self.student_id, :homework_common_id => homework_ids) student_works.update_all(:is_delete => 0) end #加入班级时创建已发布作业的作品 def create_student_works course = self.course - course.homework_commons.includes(:homework_detail_manual).where("homework_detail_manuals.comment_status > 0").each do |hw| - if hw.homework_type != 3 && hw.student_works.where("user_id = #{self.student_id}").count == 0 - hw.student_works << StudentWork.new(:user_id => self.student_id, :name => hw.name.to_s+"的作品提交", :work_status => 0) + str = "" + homeworks = course.homework_commons.includes(:homework_detail_manual).where("homework_detail_manuals.comment_status != 0") + if homeworks.count != 0 + homeworks.each do |hw| + if hw.student_works.where("user_id = #{self.student_id}").count == 0 + if str != "" + str += "," + end + str += "('#{hw.name}的作品提交',#{hw.id},#{self.student_id}, '#{format_time(Time.now)}', '#{format_time(Time.now)}')" + end end + sql = "insert into student_works (name, homework_common_id,user_id, created_at, updated_at) values" + str + ActiveRecord::Base.connection.execute sql end end #加入班级时创建一条记录 def create_course_homework_statistic - if CourseHomeworkStatistics.where(:user_id => self.student_id, :course_id => self.course_id).count == 0 - course = self.course - user = self.student - hw_count = course.homework_commons.includes(:homework_detail_manual).where("homework_detail_manuals.comment_status > 0").count - homework_ids = course.homework_commons.empty? ? "(-1)" : "(" + course.homework_commons.map{|hw| hw.id}.join(",") + ")" - student_works = StudentWork.where("homework_common_id in #{homework_ids} and work_status !=0") - is_eva_homeworks = course.homework_commons.includes(:homework_detail_manual).where("homework_commons.anonymous_comment = 0 and homework_detail_manuals.comment_status = 2") - is_eva_student_works = StudentWork.where(:homework_common_id => is_eva_homeworks.map{|hw| hw.id}) - has_eva_homeworks = course.homework_commons.includes(:homework_detail_manual).where("homework_commons.anonymous_comment = 0 and homework_detail_manuals.comment_status = 3") - has_eva_student_works = StudentWork.where(:homework_common_id => has_eva_homeworks.map{|hw| hw.id}) - - committed_work_num = user.student_works.where("homework_common_id in #{homework_ids} and work_status != 0").count - un_commit_work_num = (hw_count - committed_work_num) < 0 ? 0 : (hw_count - committed_work_num) - late_commit_work_num = user.student_works.where("homework_common_id in #{homework_ids} and work_status = 2").count - absence_evaluation_work_num = user.student_works_evaluation_distributions.where(:student_work_id => has_eva_student_works.map(&:id)).count - - user.student_works_scores.where(:reviewer_role => 3, :student_work_id => has_eva_student_works.map(&:id)).group_by(&:student_work_id).count - absence_evaluation_work_num = absence_evaluation_work_num < 0 ? 0 : absence_evaluation_work_num - un_evaluation_work_num = user.student_works_evaluation_distributions.where(:student_work_id => is_eva_student_works.map(&:id)).count - - user.student_works_scores.where(:reviewer_role => 3, :student_work_id => is_eva_student_works.map(&:id)).group_by(&:student_work_id).count - un_evaluation_work_num = un_evaluation_work_num < 0 ? 0 : un_evaluation_work_num - appeal_num = user.student_works_scores.where(:student_work_id => student_works.map(&:id), :appeal_status => 3).count - average_score = user.student_works.where(:id => student_works.map(&:id)).select("AVG(student_works.work_score) as score").first ? user.student_works.where(:id => student_works.map(&:id)).select("AVG(student_works.work_score) as score").first.score : 0 - total_score = user.student_works.where(:id => student_works.map(&:id)).select("SUM(student_works.work_score) as score").first ? user.student_works.where(:id => student_works.map(&:id)).select("SUM(student_works.work_score) as score").first.score : 0 - CourseHomeworkStatistics.create(:course_id => course.id, :user_id => user.id, :committed_work_num => committed_work_num, :un_commit_work_num => un_commit_work_num, - :late_commit_work_num => late_commit_work_num, :absence_evaluation_work_num => absence_evaluation_work_num, :un_evaluation_work_num => un_evaluation_work_num, - :appeal_num => appeal_num, :average_score => average_score, :total_score => total_score) - end + # if CourseHomeworkStatistics.where(:user_id => self.student_id, :course_id => self.course_id).count == 0 + # course = self.course + # user = self.student + # hw_count = course.homework_commons.includes(:homework_detail_manual).where("homework_detail_manuals.comment_status > 0").count + # homework_ids = course.homework_commons.empty? ? "(-1)" : "(" + course.homework_commons.map{|hw| hw.id}.join(",") + ")" + # student_works = StudentWork.where("homework_common_id in #{homework_ids} and work_status !=0") + # is_eva_homeworks = course.homework_commons.includes(:homework_detail_manual).where("homework_commons.anonymous_comment = 0 and homework_detail_manuals.comment_status = 2") + # is_eva_student_works = StudentWork.where(:homework_common_id => is_eva_homeworks.map{|hw| hw.id}) + # has_eva_homeworks = course.homework_commons.includes(:homework_detail_manual).where("homework_commons.anonymous_comment = 0 and homework_detail_manuals.comment_status = 3") + # has_eva_student_works = StudentWork.where(:homework_common_id => has_eva_homeworks.map{|hw| hw.id}) + # + # committed_work_num = user.student_works.where("homework_common_id in #{homework_ids} and work_status != 0").count + # un_commit_work_num = (hw_count - committed_work_num) < 0 ? 0 : (hw_count - committed_work_num) + # late_commit_work_num = user.student_works.where("homework_common_id in #{homework_ids} and work_status = 2").count + # absence_evaluation_work_num = user.student_works_evaluation_distributions.where(:student_work_id => has_eva_student_works.map(&:id)).count - + # user.student_works_scores.where(:reviewer_role => 3, :student_work_id => has_eva_student_works.map(&:id)).group_by(&:student_work_id).count + # absence_evaluation_work_num = absence_evaluation_work_num < 0 ? 0 : absence_evaluation_work_num + # un_evaluation_work_num = user.student_works_evaluation_distributions.where(:student_work_id => is_eva_student_works.map(&:id)).count - + # user.student_works_scores.where(:reviewer_role => 3, :student_work_id => is_eva_student_works.map(&:id)).group_by(&:student_work_id).count + # un_evaluation_work_num = un_evaluation_work_num < 0 ? 0 : un_evaluation_work_num + # appeal_num = user.student_works_scores.where(:student_work_id => student_works.map(&:id), :appeal_status => 3).count + # average_score = user.student_works.where(:id => student_works.map(&:id)).select("AVG(student_works.work_score) as score").first ? user.student_works.where(:id => student_works.map(&:id)).select("AVG(student_works.work_score) as score").first.score : 0 + # total_score = user.student_works.where(:id => student_works.map(&:id)).select("SUM(student_works.work_score) as score").first ? user.student_works.where(:id => student_works.map(&:id)).select("SUM(student_works.work_score) as score").first.score : 0 + # CourseHomeworkStatistics.create(:course_id => course.id, :user_id => user.id, :committed_work_num => committed_work_num, :un_commit_work_num => un_commit_work_num, + # :late_commit_work_num => late_commit_work_num, :absence_evaluation_work_num => absence_evaluation_work_num, :un_evaluation_work_num => un_evaluation_work_num, + # :appeal_num => appeal_num, :average_score => average_score, :total_score => total_score) + # end end def delete_course_homework_statistic @@ -74,23 +83,23 @@ class StudentsForCourse < ActiveRecord::Base end def create_course_contribute_score - ccs = CourseContributorScore.where("course_id =? and user_id =?", self.course_id, self.student_id).first - unless ccs - course = self.course - user_id = self.student_id - message_num = Message.find_by_sql("select DISTINCT me.* from messages me, boards b where b.id = me.board_id and b.course_id = #{course.id} and b.project_id = '-1' and me.author_id = #{user_id} and me.parent_id is null;").count - message_reply_num = Message.find_by_sql("select DISTINCT me.* from messages me, boards b where b.id = me.board_id and b.course_id = #{course.id} and b.project_id = '-1' and me.author_id = #{user_id} and me.parent_id is not null").count - news_reply_num = Comment.find_by_sql("select cm.* from comments cm, news n where cm.author_id = #{user_id} and n.course_id = #{course.id} and cm.commented_id = n.id and cm.commented_type ='News'").count - - resource_num = Attachment.find_by_sql("SELECT * FROM `attachments` where container_id = #{course.id} and author_id = #{user_id} and container_type ='Course'").count - journal_num = JournalsForMessage.where("user_id =? and jour_id =? and jour_type =?", user_id, course.id, "Course").count - journal_reply_num = JournalsForMessage.where("user_id =? and jour_id =? and jour_type =? and m_parent_id is not null", user_id, course.id, "Course").count - homework_ids = course.homework_commons.empty? ? "(-1)" : "(" + course.homework_commons.map(&:id).join(',') + ")" - homework_journal_num = JournalsForMessage.where("user_id =? and jour_id in #{homework_ids} and jour_type =?", user_id, "HomeworkCommon").count - news_num = News.where("author_id = #{user_id} and course_id =#{course.id}").count - total = message_num*2 + message_reply_num*1 + news_reply_num*1 + news_num*1 + resource_num*5 + journal_num*1 + homework_journal_num*1 - CourseContributorScore.create(:course_id => self.course_id, :user_id => self.student_id, :message_num => message_num, :message_reply_num => message_reply_num, :news_reply_num => news_reply_num, - :resource_num => resource_num, :journal_num => journal_num, :journal_reply_num => journal_reply_num, :total_score => total, :homework_journal_num => homework_journal_num, :news_num => news_num) - end + # ccs = CourseContributorScore.where("course_id =? and user_id =?", self.course_id, self.student_id).first + # unless ccs + # course = self.course + # user_id = self.student_id + # message_num = Message.find_by_sql("select DISTINCT me.* from messages me, boards b where b.id = me.board_id and b.course_id = #{course.id} and b.project_id = '-1' and me.author_id = #{user_id} and me.parent_id is null;").count + # message_reply_num = Message.find_by_sql("select DISTINCT me.* from messages me, boards b where b.id = me.board_id and b.course_id = #{course.id} and b.project_id = '-1' and me.author_id = #{user_id} and me.parent_id is not null").count + # news_reply_num = Comment.find_by_sql("select cm.* from comments cm, news n where cm.author_id = #{user_id} and n.course_id = #{course.id} and cm.commented_id = n.id and cm.commented_type ='News'").count + # + # resource_num = Attachment.find_by_sql("SELECT * FROM `attachments` where container_id = #{course.id} and author_id = #{user_id} and container_type ='Course'").count + # journal_num = JournalsForMessage.where("user_id =? and jour_id =? and jour_type =?", user_id, course.id, "Course").count + # journal_reply_num = JournalsForMessage.where("user_id =? and jour_id =? and jour_type =? and m_parent_id is not null", user_id, course.id, "Course").count + # homework_ids = course.homework_commons.empty? ? "(-1)" : "(" + course.homework_commons.map(&:id).join(',') + ")" + # homework_journal_num = JournalsForMessage.where("user_id =? and jour_id in #{homework_ids} and jour_type =?", user_id, "HomeworkCommon").count + # news_num = News.where("author_id = #{user_id} and course_id =#{course.id}").count + # total = message_num*2 + message_reply_num*1 + news_reply_num*1 + news_num*1 + resource_num*5 + journal_num*1 + homework_journal_num*1 + # CourseContributorScore.create(:course_id => self.course_id, :user_id => self.student_id, :message_num => message_num, :message_reply_num => message_reply_num, :news_reply_num => news_reply_num, + # :resource_num => resource_num, :journal_num => journal_num, :journal_reply_num => journal_reply_num, :total_score => total, :homework_journal_num => homework_journal_num, :news_num => news_num) + # end end end diff --git a/app/models/subject.rb b/app/models/subject.rb new file mode 100644 index 000000000..f5f46e7b1 --- /dev/null +++ b/app/models/subject.rb @@ -0,0 +1,28 @@ +class Subject < ActiveRecord::Base + #status :0 编辑中 1 审核中 2 发布 + belongs_to :user + belongs_to :course_list + belongs_to :major + attr_accessible :description, :name, :status, :visits, :user_id, :course_list_id, :major_id + + has_many :stages, :dependent => :destroy, :order => "stages.id ASC" + has_many :stage_shixuns, :dependent => :destroy + + def subject_challenges + count = 0 + self.stage_shixuns.each do |stage_shixun| + shixun = stage_shixun.shixun + count += shixun.challenges.count + end + count + end + + def subject_score + score = 0 + self.stage_shixuns.each do |stage_shixun| + shixun = stage_shixun.shixun + score += shixun.shixun_score + end + score + end +end diff --git a/app/models/syllabus.rb b/app/models/syllabus.rb index 80d24ba5a..f1d9cb34e 100644 --- a/app/models/syllabus.rb +++ b/app/models/syllabus.rb @@ -20,6 +20,7 @@ class Syllabus < ActiveRecord::Base belongs_to :user has_many :courses + has_many :homework_banks has_many :reference_materials, :dependent => :destroy has_many :syllabus_update_records, :dependent => :destroy has_many :journals_for_messages, :as => :jour, :dependent => :destroy @@ -28,7 +29,8 @@ class Syllabus < ActiveRecord::Base has_one :praise_tread_cache, as: :object, dependent: :destroy belongs_to :discipline_category 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 + belongs_to :major + 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, :major_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 @@ -90,6 +92,10 @@ class Syllabus < ActiveRecord::Base self.first_level_discipline ? self.first_level_discipline.name : '' end + def syllabus_major + self.major ? self.major.name : '' + end + ###添加回复 def self.add_syllabus_jour(user, notes, id, root_id, options = {}) syllabus = Syllabus.find(id) diff --git a/app/models/user.rb b/app/models/user.rb index 19e3d83b7..f04bb4b39 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,3 +1,4 @@ +# encoding: utf-8 # Redmine - project management software # Copyright (C) 2006-2013 Jean-Philippe Lang # @@ -86,7 +87,9 @@ class User < Principal # ['all', :label_user_mail_option_all], # ['none', :label_user_mail_option_none] # ] - + # has_many :users_authenticationses + # has_many :authentications, :through => :users_authenticationses + has_and_belongs_to_many :authentications, :order => "#{Authentication.table_name}.level" has_many :homework_users has_many :homework_attaches, :through => :homework_users has_many :homework_evaluations @@ -124,9 +127,12 @@ class User < Principal has_many :contestant_work_scores has_many :contestant_work_projects + has_many :shixuns, :through => :shixun_members has_many :shixun_members, :dependent => :destroy has_many :challenges, :dependent => :destroy + has_many :subjects + has_and_belongs_to_many :groups, :after_add => Proc.new {|user, group| group.user_added(user)}, :after_remove => Proc.new {|user, group| group.user_removed(user)} has_many :changesets, :dependent => :nullify @@ -196,9 +202,13 @@ class User < Principal ##### has_many :shares ,:dependent => :destroy + ### + has_many :apply_actions, :dependent => :destroy + has_one :user_wechat has_one :sso + has_many :apply_user_authentication # add by zjc has_one :level, :class_name => 'UserLevels', :dependent => :destroy @@ -251,6 +261,7 @@ class User < Principal validates_presence_of :login, :if => Proc.new { |user| !user.is_a?(AnonymousUser) } validates_uniqueness_of :login, :if => Proc.new { |user| user.login_changed? && user.login.present? }, :case_sensitive => false validates_uniqueness_of :mail, :if => Proc.new { |user| user.mail_changed? && user.mail.present? }, :case_sensitive => false + validates_uniqueness_of :phone, :if => Proc.new { |user| user.phone_changed? && user.phone.present? }, :case_sensitive => false # Login must contain letters, numbers, underscores only validates_format_of :login, :with => /\A[a-z0-9_\-\.]*\z/i validates_length_of :login, :maximum => LOGIN_LENGTH_LIMIT @@ -474,8 +485,17 @@ class User < Principal end def show_name + if self.show_realname + name = lastname + firstname + else + name = nickname + end + name.blank? ? login : name + end + + def show_real_name name = lastname + firstname - name.empty? || name.nil? ? login : name + name.blank? ? login : name end def show_occupation @@ -537,6 +557,18 @@ class User < Principal self.read_attribute(:identity_url) end + # 判断用户的身份 + def identity + ue = self.user_extensions + unless ue.blank? + if ue.technical_title.blank? + ue.identity == 0 ? "老师" : (ue.identity == 1 ? "学生" : "专业人士") + else + result = ue.technical_title + end + end + end + VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z]+)*\.[a-z]+\z/i VALID_PHONE_REGEX = /^1\d{10}$/ # VALID_EMAIL_REGEX = /^[0-9a-zA-Z_-]+@[0-9a-zA-Z_-]+(\.[0-9a-zA-Z_-]+)+$/ @@ -625,10 +657,6 @@ class User < Principal end end - def nickname(formatter = nil) - login.nil? || (login && login.empty?) ? "AnonymousUser" : login - end - def name(formatter = nil) login end @@ -845,6 +873,10 @@ class User < Principal !logged? end + def system_authentication? + self.authentication.blank? ? false : true + end + # Returns user's membership for the given project # or nil if the user is not a member of project def membership(project) @@ -912,9 +944,15 @@ class User < Principal projects.to_a.include?(project) end + # 超级管理员或者创建者 + def manager_of_subject?(subject) + (subject.user == User.current || User.current.admin?) ? true : false + end + + # 超级管理员或者role为1 def manager_of_shixun?(shixun) - member = ShixunMember.where(:user_id => self.id, :shixun_id => shixun, :role => 1) + member = ShixunMember.where(:user_id => self.id, :shixun_id => shixun, :role => [1,2]) (!member.blank? || User.current.admin?) ? true : false end @@ -1086,6 +1124,17 @@ class User < Principal end end + #是否是老师(不包括助教) + def teacher_of_course(course) + member = course.members.where("user_id = #{self.id}").first + if !member.nil? + role = MemberRole.where("member_id = #{member.id} and role_id in (3, 9)") + !role.blank? + else + return false + end + end + #是否具有老师角色 def has_teacher_role(course) member = course.members.where("user_id = #{self.id}").first @@ -1210,7 +1259,8 @@ class User < Principal 'custom_fields', 'identity_url', 'phone', - 'authentication' + 'authentication', + 'nickname' safe_attributes 'status', 'auth_source_id', diff --git a/app/models/webssh.rb b/app/models/webssh.rb new file mode 100644 index 000000000..5a3efd946 --- /dev/null +++ b/app/models/webssh.rb @@ -0,0 +1,4 @@ +class Webssh < ActiveRecord::Base + attr_accessible :host, :myshixun_id, :password, :port, :username + belongs_to :myshixun +end diff --git a/app/services/courses_service.rb b/app/services/courses_service.rb index a9b35e2f2..5faad5cd7 100644 --- a/app/services/courses_service.rb +++ b/app/services/courses_service.rb @@ -110,7 +110,7 @@ class CoursesService #双重身份 学生列表中不显示 # unless (params[:role] == '2' && role_ids.length >= 2) - users << {:id => m.user.id, :img_url => img_url, :nickname => m.user.login, :gender => gender, + users << {:id => m.user.id, :img_url => img_url, :nickname => m.user.nickname, :gender => gender, :work_unit => work_unit, :mail => m.user.mail, :location => location, role_name: m.roles.first.name, name: m.user.show_name, @@ -138,7 +138,7 @@ class CoursesService work_unit = get_user_work_unit user location = get_user_location user roles_ids = m.content.split(",") - reviewers << {:id => user.id, :img_url => img_url, :nickname => user.login, :gender => gender, + reviewers << {:id => user.id, :img_url => img_url, :nickname => user.nickname, :gender => gender, :work_unit => work_unit, :mail => user.mail, :location => location, role_name: "", name: user.show_name, @@ -168,7 +168,7 @@ class CoursesService work_unit = get_user_work_unit user location = get_user_location user roles_ids = messages.content.split(",") - info = {:id => user.id, :img_url => img_url, :nickname => user.login, :gender => gender, + info = {:id => user.id, :img_url => img_url, :nickname => user.nickname, :gender => gender, :work_unit => work_unit, :mail => user.mail, :location => location, role_name: "", name: user.show_name, @@ -370,7 +370,7 @@ class CoursesService #@course.setup_time = params[:setup_time] #@course.endup_time = params[:endup_time] @course.class_period = params[:period].to_i if params[:period] - @course.credit = params[:credit].to_i if params[:credit] + @course.credit = params[:credit] if params[:credit] @course.end_date = params[:end_date] if params[:end_date] params[:course][:is_public] ? @course.is_public = 1 : @course.is_public = 0 @course.open_student = 0 @@ -430,7 +430,7 @@ class CoursesService #course.end_time = params[:end_time] #course.end_term = params[:end_term] course.class_period = params[:period].to_i if params[:period] - course.credit = params[:credit].to_i if params[:credit] + course.credit = params[:credit] if params[:credit] course.end_date = params[:end_date] if params[:end_date] params[:course][:is_public] ? course.is_public = 1 : course.is_public = 0 if course.save diff --git a/app/services/projects_service.rb b/app/services/projects_service.rb index f3679aa22..97f67e114 100644 --- a/app/services/projects_service.rb +++ b/app/services/projects_service.rb @@ -215,7 +215,7 @@ class ProjectsService gender = user.user_extensions.gender.nil? ? 0 : user.user_extensions.gender work_unit = get_user_work_unit user location = get_user_location user - review_members << {:id => user.id, :img_url => img_url, :nickname => user.login, :gender => gender, + review_members << {:id => user.id, :img_url => img_url, :nickname => user.nickname, :gender => gender, :work_unit => work_unit, :mail => user.mail, :location => location, role_name: "", name: user.show_name, @@ -244,7 +244,7 @@ class ProjectsService gender = user.user_extensions.gender.nil? ? 0 : user.user_extensions.gender work_unit = get_user_work_unit user location = get_user_location user - info = {:id => user.id, :img_url => img_url, :nickname => user.login, :gender => gender, + info = {:id => user.id, :img_url => img_url, :nickname => user.nickname, :gender => gender, :work_unit => work_unit, :mail => user.mail, :location => location, role_name: "", name: user.show_name, diff --git a/app/services/users_service.rb b/app/services/users_service.rb index 1a7601ec9..85f026537 100644 --- a/app/services/users_service.rb +++ b/app/services/users_service.rb @@ -99,7 +99,7 @@ class UsersService gender = @user.user_extensions.gender.nil? ? 0 : @user.user_extensions.gender work_unit = get_user_work_unit @user location = get_user_location @user - {:id => @user.id, :img_url => img_url,:realname => @user.realname, :nickname => @user.login, :gender => gender, :work_unit => work_unit, :mail => @user.mail, :location => location, :brief_introduction => @user.user_extensions.brief_introduction} + {:id => @user.id, :img_url => img_url,:realname => @user.realname, :nickname => @user.nickname, :gender => gender, :work_unit => work_unit, :mail => @user.mail, :location => location, :brief_introduction => @user.user_extensions.brief_introduction} end #忘记密码 diff --git a/app/views/account/_change_user_email.html.erb b/app/views/account/_change_user_email.html.erb index 337516f61..e50ba6f16 100644 --- a/app/views/account/_change_user_email.html.erb +++ b/app/views/account/_change_user_email.html.erb @@ -55,18 +55,5 @@ } }); - function submit_user_emails(){ - if($mail_correct == false){ - return - }else{ - $.get('<%= account_change_email_path(:user_id => @user.id) %>', - { valid: "mail", - value: document.getElementById("user_mail").value }, - function (data){ - $("#user_email_show").html(data.email); - hideModal(); - return; - }); - } - } + \ No newline at end of file diff --git a/app/views/account/_has_authentication.html.erb b/app/views/account/_has_authentication.html.erb index c4058d112..f42f6ca6b 100644 --- a/app/views/account/_has_authentication.html.erb +++ b/app/views/account/_has_authentication.html.erb @@ -5,13 +5,28 @@ 已认证 <% end %> +<% if false %> + <%= render :partial => "welcome/one_btn_mask_pop", + :locals => { + :tip1 => "更多功能,需要经过管理员的授权审核", + :tip2 => "认证申请已提交,我们将在1个工作日内完成审核", + :btn => "试用申请", + :url => "javascript:void(0);" + } + %> +<% end %>
-
1.上传图片
-
-
2.审核并完成认证
-
+
1.上传图片
+ <% if !@user.authentication %> +
+
2.审核并完成认证
+ <% else %> +
+
2.审核并完成认证
+ <% end %>
+
职业证明:
@@ -61,4 +76,4 @@
提交认证申请
-
\ No newline at end of file +
diff --git a/app/views/account/agreement.html.erb b/app/views/account/agreement.html.erb index ac0b9906c..2bb958120 100644 --- a/app/views/account/agreement.html.erb +++ b/app/views/account/agreement.html.erb @@ -1,29 +1,29 @@ <%= stylesheet_link_tag 'css/public'%>
-

Trustie服务协议

+

服务协议

尊敬的用户,您好!
-欢迎使用Trustie平台,在您使用Trustie平台前,请您认真阅读并遵守《Trustie服务协议》(以下简称"本协议"),请您务必审慎阅读、充分理解协议的各条款内容。
-当您在注册过程中点击查看"看过并同意本服务协议",按照注册流程成功注册为Trustie平台的用户即表示您已充分阅读、理解并完全接受本协议中的全部条款。您承诺接受并遵守本协议的约定,届时您不应以未阅读本协议的内容等理由,主张本协议无效或本协议中的某些条款无效,或要求撤销本协议。

-

一、Trustie平台权利和义务

-

1、尊重用户隐私:尊重用户隐私,保障用户隐私安全是Trustie平台的一项基本政策;
-2、管理平台用户:Trustie平台依据国家法律、地方法律和国际法律等的标准以及本行业的规则来管理平台注册用户;
-3、处理用户反馈:Trustie平台的相关人员会及时处理用户反馈的问题并给予及时回复。

+欢迎使用本网站,在您使用本网站前,请您认真阅读并遵守《服务协议》(以下简称"本协议"),请您务必审慎阅读、充分理解协议的各条款内容。
+当您在注册过程中点击查看"看过并同意本服务协议",按照注册流程成功注册为网站的用户即表示您已充分阅读、理解并完全接受本协议中的全部条款。您承诺接受并遵守本协议的约定,届时您不应以未阅读本协议的内容等理由,主张本协议无效或本协议中的某些条款无效,或要求撤销本协议。

+

一、本网站权利和义务

+

1、尊重用户隐私:尊重用户隐私,保障用户隐私安全是网站的一项基本政策;
+2、管理网站用户:网站依据国家法律、地方法律和国际法律等的标准以及本行业的规则来管理网站注册用户;
+3、处理用户反馈:网站的相关人员会及时处理用户反馈的问题并给予及时回复。

二、用户权利和义务

-

用户在使用Trustie平台的过程中,必须遵守如下原则:
+

用户在使用网站的过程中,必须遵守如下原则:
1、遵守中国的有关法律和法规;
2、使用网络服务不作非法用途;
3、不干扰和混乱网络服务;
4、遵守所有使用网络服务的网络协议、规定、程序和惯例;
5、不传输任何非法的、骚扰性的、中伤他人的、辱骂性的、恐吓性的、伤害性的、庸俗的,淫秽等信息资料;
6、不传输任何教唆他人构成犯罪行为的资料;
-7、用户不得故意或者过失损害Trustie平台合法权利和利益。及时回复。

+7、用户不得故意或者过失损害网站合法权利和利益。及时回复。

三、关于责任

-

鉴于网络服务的特殊性,用户同意Trustie团队有权在事先通知的情况下,变更、中断、升级部分网络服务。Trustie团队不担保网络服务不会中断,但承诺在用户可承受的时间内快速恢复服务,同时确保用户数据的安全性和可靠性。

+

鉴于网络服务的特殊性,本网站有权在事先通知的情况下,变更、中断、升级部分网络服务。本网站不担保网络服务不会中断,但承诺在用户可承受的时间内快速恢复服务,同时确保用户数据的安全性和可靠性。

四、服务条款的修改

-

Trustie团队保留在必要时对本协议修改的权利,一旦发生变动,这些条款可由Trustie团队及时更新,且毋须另行通知,修改后的条款一旦在网页上公布即有效代替原来的服务条款。您可随时查阅最新版服务条款。

-

本协议最终解释权归Trustie团队所有。

+

本网站保留在必要时对本协议修改的权利,一旦发生变动,这些条款可由网站项目组及时更新,且毋须另行通知,修改后的条款一旦在网页上公布即有效代替原来的服务条款。您可随时查阅最新版服务条款。

+

本协议最终解释权归本网站所有。

diff --git a/app/views/account/apply_trail.js.erb b/app/views/account/apply_trail.js.erb new file mode 100644 index 000000000..c7b789ae5 --- /dev/null +++ b/app/views/account/apply_trail.js.erb @@ -0,0 +1 @@ +$("body").append('<%= j( render :partial => 'welcome/one_btn_mask_pop', :locals => {:btn => "确定", :tip1 => "申请成功,我们将在一个工作日内完成审核", :url => "#{my_account_path()}"}) %>'); \ No newline at end of file diff --git a/app/views/account/authentication.html.erb b/app/views/account/authentication.html.erb index e484ae85c..8428d1ae8 100644 --- a/app/views/account/authentication.html.erb +++ b/app/views/account/authentication.html.erb @@ -1,22 +1,24 @@
- <% if !@user.authentication && (@apply_user_auth.nil? || @apply_user_auth && @apply_user_auth.status == 2) %> -
- <% if !@user.authentication && @apply_user_auth.nil? %> - 未认证请及时提交认证申请,体验更全面、智能的资源和题库服务 - <% elsif !@user.authentication && @apply_user_auth.status == 2 %> - 未通过抱歉,您提交的认证资料里“职业证明”、“身份证明”于<%= format_time @apply_user_auth.deal_time %>未通过认证审核!请您重新申请认证。 - <% end %> -
+ <% if !@user.authentication && (@apply_user_auth.nil? || @apply_user_auth && (@apply_user_auth.status == 2 || @apply_user_auth.status == 1)) %> + <% unless @apply_user_auth && @apply_user_auth.status == 1 %> +
+ <% if !@user.authentication && @apply_user_auth.nil? %> + 未认证请及时提交认证申请,体验更全面、智能的资源和题库服务 + <% elsif !@user.authentication && @apply_user_auth.status == 2 %> + 未通过抱歉,您提交的认证资料里“职业证明”、“身份证明”于<%= format_time @apply_user_auth.deal_time %>未通过认证审核!请您重新申请认证。 + <% end %> +
+ <% end %>
1.上传图片
-
-
2.审核并完成认证
-
+
+
2.审核并完成认证
-
+ +
职业证明: -
+

如:教师证、学生证、工作证
请根据你基本资料中填写的职业、职称和单位名称,上传匹配的证件照片 @@ -46,7 +48,11 @@
点击上传图片

  • - <%= image_tag(url_to_auth_img(@user.id, 'PRO'), :width => 200, :height => 150, :class => 'user-renzheng-img', :id => 'nh_source_pro') %> + <% if @apply_user_auth && @apply_user_auth.status == 1 %> + <%= image_tag(url_to_auth_img(0, 'PRO'), :width => 200, :height => 150, :class => 'user-renzheng-img', :id => 'nh_source_pro') %> + <% else %> + <%= image_tag(url_to_auth_img(@user.id, 'PRO'), :width => 200, :height => 150, :class => 'user-renzheng-img', :id => 'nh_source_pro') %> + <% end %>
  • 1.请提交有效期内的资格证照片,需确保头像和文字清晰
    @@ -88,7 +94,11 @@
    点击上传图片

  • - <%= image_tag(url_to_auth_img(@user.id, 'ID'), :width => 200, :height => 150,:class => 'user-renzheng-img', :id => 'nh_source_id') %> + <% if @apply_user_auth && @apply_user_auth.status == 1 %> + <%= image_tag(url_to_auth_img(0, 'ID'), :width => 200, :height => 150, :class => 'user-renzheng-img', :id => 'nh_source_pro') %> + <% else %> + <%= image_tag(url_to_auth_img(@user.id, 'ID'), :width => 200, :height => 150,:class => 'user-renzheng-img', :id => 'nh_source_id') %> + <% end %>
  • 1.照片内所持身份证件必须在有效期内,没有作假痕迹。
    @@ -107,4 +117,85 @@ <% else %> <%= render :partial => 'has_authentication' %> <% end %> -

  • \ No newline at end of file +
    + + +<%if false%> +
    +

    实名认证

    +
    +
    +

    +

    当前用户尚未实名认证

    +

    请完成实名认证以更好的享受智能教学服务

    +

    立即认证

    +
    +
    + + +
    +
    +

    实名认证

    +

    + 1填写认证信息  > + 2人工审核  > + 3认证结果 +

    +
    +
    +

    以下信息通过审核后将不能再次修改,提交后请耐心等待核查

    +

    温馨提示:尊敬的用户,您提交的数据将会被加密,请放心填写。

    +
      +
    • + + +
    • +
    • + +

      所填姓名需与身份证上的姓名保持一致

      +
    • +
    • + + + + + + + + + +
    • +
    • + + +

      阶段名称不能为空

      +
    • +
    • + +

      请使用二代身份证,身份证号为18位
      统一身份证号只能认证一次

      +
    • +
    • + + +选择文件 +
    • +
    • + +

      请上传手持身份证正面的原件照片,确保身份证上的姓名、身份证号码和头像清晰可辨认。查看示例>>
      png/jpg/bmp格式,不超过2MB

      +
    • +
    • + +
      + +
      + 确认提交 +

      + + 示例 +

      +
      +
    • +
    +
    + +
    +<% end%> \ No newline at end of file diff --git a/app/views/account/avatar.html.erb b/app/views/account/avatar.html.erb index 911eef99d..266d6bbf1 100644 --- a/app/views/account/avatar.html.erb +++ b/app/views/account/avatar.html.erb @@ -24,21 +24,29 @@
    -
    +
    + 选择你要上传的图片
    +仅支持JPG、GIF、PNG,且文件小于2M
    +
    预览(请注意是否清晰)
    + <%= image_tag(url_to_avatar(@user), :width => 240, :height => 240, :alt => "头像") %>
    尺寸:240*240像素
    -
    +
    + <%= image_tag(url_to_avatar(@user), :width => 100, :height => 100, :alt => "头像") %> +
    尺寸:100*100像素 -
    +
    + <%= image_tag(url_to_avatar(@user), :width => 40, :height => 40, :alt => "头像") %> +
    尺寸:40*40像素
    @@ -136,13 +144,12 @@ if(re){ var o = JSON.parse(re); if (o.status !=0 ){ - alert(o.message); + console.log(o.message); } else { - alert('上传成功'); - window.location.reload(); + notice_box_redirect('<%= avatar_account_path() %>' ,"上传成功"); } } else { - alert("上传出错"); + notice_box("上传出错"); } }, diff --git a/app/views/account/change_or_bind.html.erb b/app/views/account/change_or_bind.html.erb index d9a5b266b..c102daf20 100644 --- a/app/views/account/change_or_bind.html.erb +++ b/app/views/account/change_or_bind.html.erb @@ -50,7 +50,7 @@
    • - + diff --git a/app/views/account/change_psd.html.erb b/app/views/account/change_psd.html.erb index 314daaef7..7b5348a5f 100644 --- a/app/views/account/change_psd.html.erb +++ b/app/views/account/change_psd.html.erb @@ -16,7 +16,7 @@
  • - + 只需要登录邮箱(<%= @user.mail %>),点击链接激活即可
    - +
    • 还没有收到激活账号邮件?
    • @@ -24,13 +24,13 @@
    • 2:再次发送验证邮件
    • 3:如果仍然没有收到注册验证邮件,请更换邮件地址
    • - <%= link_to '重新发送激活邮件'.html_safe, { :controller => 'account', :action => 'resendmail', :user => @user},:id => 'resend_email_a', :class => 'task-btn fl mr20', :remote => true, :method => 'get' %> - 更换邮件地址 + <%= link_to '重新发送激活邮件'.html_safe, { :controller => 'account', :action => 'resendmail', :user => @user},:id => 'resend_email_a', :class => 'task-btn-email fl mr20', :remote => true, :method => 'get' %> + 更换邮件地址
    • - 确定 + 确定
    • @@ -60,4 +60,10 @@ } } } + //跳转到指定的邮箱登录页面 + $(function(){ + var uurl = '<%= email %>'; + uurl = gotoEmail(uurl); + $("#user_email_link").attr("href", "http://"+uurl); + }); \ No newline at end of file diff --git a/app/views/account/email_valid.html.erb b/app/views/account/email_valid.html.erb index 77d7e8642..65892e8f3 100644 --- a/app/views/account/email_valid.html.erb +++ b/app/views/account/email_valid.html.erb @@ -5,8 +5,8 @@

      激活邮箱账号

      <%= link_to '首页', home_path %> - | - <%= link_to "帮助中心", "#{Setting.protocol}://#{Setting.host_name}/forums/1/memos/1168" %> + + <%#= link_to "帮助中心", "#{Setting.protocol}://#{Setting.host_name}/forums/1/memos/1168" %>

  • -

    +
    diff --git a/app/views/messages/_project_show_replies.html.erb b/app/views/messages/_project_show_replies.html.erb index 637fade8a..ebca39ace 100644 --- a/app/views/messages/_project_show_replies.html.erb +++ b/app/views/messages/_project_show_replies.html.erb @@ -44,7 +44,7 @@
    -

    +
    diff --git a/app/views/messages/quote.js.erb b/app/views/messages/quote.js.erb index aa429201d..47bd77351 100644 --- a/app/views/messages/quote.js.erb +++ b/app/views/messages/quote.js.erb @@ -1,8 +1,9 @@ -if($("#reply_message_<%= @message.id%>").length > 0) { +if($("#reply_message_<%= @message.id%>").html() == "") { + $(".reply_to_message").html(""); <% if params[:is_project] %> - $("#reply_message_<%= @message.id%>").replaceWith("<%= escape_javascript(render :partial => 'messages/project_rereply_message', :locals => {:reply => @message}) %>"); + $("#reply_message_<%= @message.id%>").html("<%= escape_javascript(render :partial => 'messages/project_rereply_message', :locals => {:reply => @message}) %>"); <% else %> - $("#reply_message_<%= @message.id%>").replaceWith("<%= escape_javascript(render :partial => 'reply_message', :locals => {:reply => @message}) %>"); + $("#reply_message_<%= @message.id%>").html("<%= escape_javascript(render :partial => 'reply_message', :locals => {:reply => @message}) %>"); <% end %> $(function(){ @@ -10,6 +11,6 @@ if($("#reply_message_<%= @message.id%>").length > 0) { $('#quote_quote').val("<%#= raw escape_javascript(@temp.content.html_safe) %>");*/ sd_create_editor_from_data(<%= @message.id%>,null,"100%", "<%=@message.class.to_s%>"); }); -}else if($("#reply_to_message_<%= @message.id%>").length >0) { - $("#reply_to_message_<%= @message.id%>").replaceWith("

    "); +}else { + $("#reply_message_<%= @message.id%>").html(""); } \ No newline at end of file diff --git a/app/views/my/account.html.erb b/app/views/my/account.html.erb index b67e846f2..4ca8bb68f 100644 --- a/app/views/my/account.html.erb +++ b/app/views/my/account.html.erb @@ -1,5 +1,19 @@ +<% if @require_auth %> + <%= render :partial => "welcome/guidance_mask" %> +<% else %> + <% if @require_trail_auth %> + <%= render :partial => 'welcome/two_btn_mask_pop', + :locals => {:btn1 => "试用申请", :btn2 => "身份认证", + :tip1 => "更多功能,需要经过管理员的授权审核", + :tip2 => "建议先提交身份认证,再进行试用申请", + :url1 => "#{apply_trail_account_path}", + :url2 => "#{authentication_account_path}" + } + %> + <% end %> +<% end %>
    -
    +
    × @@ -10,160 +24,366 @@

    您添加新的部门“<%= @d_message.name %>”的申请,经确认为无效的部门信息,已被删除,请重新编辑您的部门资料。谢谢!

    <% end %>
    + <% if @user.authentication %> +
    + + 已通过实名认证和职业认证,实名信息无法再修改,若您的职业信息需要变更,请重新申请<%= link_to "职业认证", authentication_account_path, :class => "link-color-blue" %> +
    + <% end %>
    <%= labelled_form_for :user, @user, :url => {:action => "account"}, :html => {:id => 'my_account_form', :method => :post} do |f| %> -
      -
    • - - + <% if @user.authentication %> +
        +
      • + + +
        + 请输入昵称,最多20个字符 +
      • +
      • + + + + > + +
        + 请填写您的真实姓名 +
      • +
      • + + + <% if User.current.user_extensions && User.current.user_extensions.gender && User.current.user_extensions.gender == 1 %> + + + + + + + + + <% else %> + + + + + + + + + <% end %> +
        +
      • +
      • + + + + + + + -
        - 请填写您的真实姓名 -
      • -
      • - - <% if User.current.user_extensions && User.current.user_extensions.gender && User.current.user_extensions.gender == 1 %> - - - - - - - - +
        + 请选择你的职业/职称 +
      • +
      • + + + + +
        + 请选择你的职业 +
      • +
      • + + + + +
        + 请选择你所在的省份/城市 +
      • +
      • + + + +

        你的单位不在列表中?请点击申请添加

        +
        + 请从下拉列表中选择你的单位 +
      • +
      • + + + +

        你的部门不在列表中?请点击申请添加

        +
        +
      • +
      • + + + +
        +
      • +
      • + 保存 + 取消 +
      • +
      <% else %> - - - - - - - - +
        +
      • + + +
        + 请输入昵称,最多20个字符 +
      • +
      • + + + > + +
        + 请填写您的真实姓名 +
      • +
      • + + <% if User.current.user_extensions && User.current.user_extensions.gender && User.current.user_extensions.gender == 1 %> + + + + + + + + + <% else %> + + + + + + + + + <% end %> +
        +
      • +
      • + + + + + +
        + 请选择你的职业/职称 +
      • +
      • + + + +
        + 请选择你的职业 +
      • +
      • + + + + +
        + 请选择你所在的省份/城市 +
      • +
      • + + + +

        你的单位不在列表中?请点击申请添加

        +
        + 请从下拉列表中选择你的单位 +
      • +
      • + + + +

        你的部门不在列表中?请点击申请添加

        +
        +
      • +
      • + + + +
        +
      • +
      • + 保存 + 取消 +
      • +
      <% end %> -
      -
    • -
    • - - - - - -
      - 请选择你的职业/职称 -
    • -
    • - - - -
      - 请选择你的职业 -
    • -
    • - - - - -
      - 请选择你所在的省份/城市 -
    • -
    • - - - -

      你的单位不在列表中?请点击申请添加

      -
      - 请从下拉列表中选择你的单位 -
    • -
    • - - - -

      你的部门不在列表中?请点击申请添加

      -
      -
    • -
    • - - - -
      -
    • -
    • - 保存 - 取消 -
    • -
    - <% end %> + <% end %>
    -
    +
      +
    • + + +

      <%= @user.try(:nickname) %>

      +
    • -

      <%= @user.try(:lastname) + @user.try(:firstname) %>

      +

      + <%= @user.try(:lastname) + @user.try(:firstname) %> + <% if @user.authentication %> + + + 已实名认证 + + <% else %> + <% apply_auth = ApplyUserAuthentication.where(:user_id => @user.id).last %> + <% if apply_auth && apply_auth.status == 0 %> + + + 实名认证中 + + <% elsif apply_auth && apply_auth.status == 2 %> + + + 实名认证未通过 + + <% else %> + + + 未实名认证 + + <% end %> + <% end %> +

    • @@ -174,17 +394,38 @@

      - <%= @user.user_extensions.show_identity %> + <%= @user.user_extensions.show_identity %> <% if @user.authentication %> - - - 已认证 - + + + 已职业认证 + <% else %> - - - 未认证 - + <% apply_auth = ApplyUserAuthentication.where(:user_id => @user.id).last %> + <% if apply_auth && apply_auth.status == 0 %> + + + 职业认证中 + + <% elsif apply_auth && apply_auth.status == 2 %> + + + 职业认证未通过 + + <% else %> + + + 未职业认证 + + <% end %> <% end %>

    • @@ -196,7 +437,7 @@ <% else %> -

      <%= @user.user_extensions.try(:technical_title) %>

      +

      <%= @user.user_extensions.try(:technical_title) %>

      <% end %>
    • diff --git a/app/views/myshixuns/_myshixun_top.html.erb b/app/views/myshixuns/_myshixun_top.html.erb index bb7c9733b..641a3d603 100644 --- a/app/views/myshixuns/_myshixun_top.html.erb +++ b/app/views/myshixuns/_myshixun_top.html.erb @@ -1,12 +1,12 @@
      -

      <%= @myshixun.name %>

      - - 第<%= @game_challenge.position %>关 +

      <%= @myshixun.shixun.try(:name) %>

      +      + 第<%= @game_challenge.position %>关:<%= @game_challenge.subject %>
      - <%= sum_final_score %> + <%= User.current.grade %>
      diff --git a/app/views/news/_course_news_new.html.erb b/app/views/news/_course_news_new.html.erb index 158f57459..38ac738eb 100644 --- a/app/views/news/_course_news_new.html.erb +++ b/app/views/news/_course_news_new.html.erb @@ -6,7 +6,7 @@
      - +

      @@ -226,7 +226,7 @@
      <% if i == 9 && projects.count > 10 %> - 更多>> + 更多>> <% end %> <% if i > 9 && i == (projects.count - 1) %> 收回<< diff --git a/app/views/poll/_poll_list.html.erb b/app/views/poll/_poll_list.html.erb index be2d6919d..353cfcd06 100644 --- a/app/views/poll/_poll_list.html.erb +++ b/app/views/poll/_poll_list.html.erb @@ -1,4 +1,4 @@ -
      +

      所有问卷 (<%= @obj_count%>)

      @@ -9,8 +9,6 @@
      - <%= render :partial => 'polls_list', :locals => {:polls => @polls,:obj_pages=>@obj_pages,:obj_count=>@obj_count} %> -
      \ No newline at end of file diff --git a/app/views/poll/_polls_list.html.erb b/app/views/poll/_polls_list.html.erb index e22e8fbdf..5433ebdb2 100644 --- a/app/views/poll/_polls_list.html.erb +++ b/app/views/poll/_polls_list.html.erb @@ -10,6 +10,5 @@ <%= pagination_links_full obj_pages, obj_count, :per_page_links => false, :remote => false, :flag => true%>
    <% else %> -
    -

    没有数据可以显示!

    + <%= render :partial => "welcome/no_data" %> <% end %> \ No newline at end of file diff --git a/app/views/praise_tread/_edu_praise.html.erb b/app/views/praise_tread/_edu_praise.html.erb new file mode 100644 index 000000000..9cc557e57 --- /dev/null +++ b/app/views/praise_tread/_edu_praise.html.erb @@ -0,0 +1,19 @@ +<% if PraiseTread.praised(activity) %> + + 赞 + <% num = activity.praise_tread_cache ? activity.praise_tread_cache.praise_num : 0 %> + <%= (num.nil? ? 0 : num) > 0 ? num : 0 %> + +<% else %> + + 赞 + <% num = activity.praise_tread_cache ? activity.praise_tread_cache.praise_num : 0 %> + <%= (num.nil? ? 0 : num) > 0 ? num : 0 %> + +<% end %> \ No newline at end of file diff --git a/app/views/praise_tread/praise_minus.js.erb b/app/views/praise_tread/praise_minus.js.erb index 057ecb8bd..5a8ebf2ca 100644 --- a/app/views/praise_tread/praise_minus.js.erb +++ b/app/views/praise_tread/praise_minus.js.erb @@ -1,9 +1,21 @@ <% if @activity %> <% if @type.to_s == 'activity' %> - $('#praise_count_<%=@user_activity_id %>').html('<%= j(render :partial=> "praise_tread/praise", :locals => {:activity=>@obj, :user_activity_id=>@user_activity_id,:type=>"activity"})%>'); + <% if @obj_type == 'HomeworkCommon' && @obj_id == @user_activity_id %> + $('#praise_count_<%=@user_activity_id %>').html('<%=j(render :partial=> "praise_tread/edu_praise", :locals => {:activity=>@obj, :user_activity_id=>@user_activity_id,:type=>"activity"})%>'); + <% else %> + $('#praise_count_<%=@user_activity_id %>').html('<%=j(render :partial=> "praise_tread/praise", :locals => {:activity=>@obj, :user_activity_id=>@user_activity_id,:type=>"activity"})%>'); + <% end %> <% else @type.to_s == 'reply' %> - $('.reply_praise_count_<%=@user_activity_id %>').html('<%=j(render :partial=> "praise_tread/praise", :locals => {:activity=>@obj, :user_activity_id=>@user_activity_id,:type=>"reply"})%>'); + <% if @obj_type == 'JournalsForMessage' && @obj_id == @user_activity_id && @obj.jour_type == 'HomeworkCommon' %> + $('.reply_praise_count_<%=@user_activity_id %>').html('<%=j(render :partial=> "praise_tread/edu_praise", :locals => {:activity=>@obj, :user_activity_id=>@user_activity_id,:type=>"activity"})%>'); + <% else %> + $('.reply_praise_count_<%=@user_activity_id %>').html('<%=j(render :partial=> "praise_tread/praise", :locals => {:activity=>@obj, :user_activity_id=>@user_activity_id,:type=>"reply"})%>'); + <% end %> <% end %> +<% elsif @obj_type == 'Discuss'%> + $('#dis_praise_<%= @obj.id %>').html('<%= j( + render :partial => "discusses/dis_praise",:locals => {:discuss => @obj} + )%>'); <% else %> $('#praise_tread').html('<%= j( render :partial => "/praise_tread/praise_tread",:locals => {:obj => @obj,:show_flag => false,:user_id => User.current.id,:horizontal=>@horizontal} diff --git a/app/views/praise_tread/praise_plus.js.erb b/app/views/praise_tread/praise_plus.js.erb index 5edc8c4cf..4e747a638 100644 --- a/app/views/praise_tread/praise_plus.js.erb +++ b/app/views/praise_tread/praise_plus.js.erb @@ -1,13 +1,25 @@ <% if @activity %> <% if @type.to_s == 'activity' %> - $('#praise_count_<%=@user_activity_id %>').html('<%=j(render :partial=> "praise_tread/praise", :locals => {:activity=>@obj, :user_activity_id=>@user_activity_id,:type=>"activity"})%>'); + <% if @obj_type == 'HomeworkCommon' && @obj_id == @user_activity_id %> + $('#praise_count_<%=@user_activity_id %>').html('<%=j(render :partial=> "praise_tread/edu_praise", :locals => {:activity=>@obj, :user_activity_id=>@user_activity_id,:type=>"activity"})%>'); + <% else %> + $('#praise_count_<%=@user_activity_id %>').html('<%=j(render :partial=> "praise_tread/praise", :locals => {:activity=>@obj, :user_activity_id=>@user_activity_id,:type=>"activity"})%>'); + <% end %> <% else @type.to_s == 'reply' %> - $('.reply_praise_count_<%=@user_activity_id %>').html('<%=j(render :partial=> "praise_tread/praise", :locals => {:activity=>@obj, :user_activity_id=>@user_activity_id,:type=>"reply"})%>'); + <% if @obj_type == 'JournalsForMessage' && @obj_id == @user_activity_id && @obj.jour_type == 'HomeworkCommon' %> + $('.reply_praise_count_<%=@user_activity_id %>').html('<%=j(render :partial=> "praise_tread/edu_praise", :locals => {:activity=>@obj, :user_activity_id=>@user_activity_id,:type=>"reply"})%>'); + <% else %> + $('.reply_praise_count_<%=@user_activity_id %>').html('<%=j(render :partial=> "praise_tread/praise", :locals => {:activity=>@obj, :user_activity_id=>@user_activity_id,:type=>"reply"})%>'); + <% end %> <% end %> <% elsif @obj_type == 'Memo'%> $('#praise_tread_<%= @obj.id %>').html('<%= j( render :partial => "/memos/praise_tread",:locals => {:obj => @obj,:user_id => User.current.id,:horizontal => @horizontal} )%>'); +<% elsif @obj_type == 'Discuss'%> + $('#dis_praise_<%= @obj.id %>').html('<%= j( + render :partial => "discusses/dis_praise",:locals => {:discuss => @obj} + )%>'); <% else %> $('#praise_tread_<%= @obj.id %>').html('<%= j( render :partial => "/praise_tread/praise_tread",:locals => {:obj => @obj,:user_id => User.current.id,:horizontal => @horizontal} diff --git a/app/views/repositories/_latest_commit.html.erb b/app/views/repositories/_latest_commit.html.erb index acce15cd8..b828aee73 100644 --- a/app/views/repositories/_latest_commit.html.erb +++ b/app/views/repositories/_latest_commit.html.erb @@ -1,11 +1,11 @@ <% if @changesets_latest_coimmit && @changesets_latest_coimmit.try(:time) %> -
    +
    <%= image_tag(url_to_avatar(user_commit_rep(@changesets_latest_coimmit.try(:author_email))), :width => "25", :height => "25", :class => "fl portraitRadius mt2 ml4 mr5") %> <%= link_to_user_mail(@changesets_latest_coimmit.try(:author_email), "fb fontGrey3 mr5 fl hidden maxwidth150 ml5") %>
    提交于 <%= time_tag(@changesets_latest_coimmit.try(:time)) %> 前:
    <%= @changesets_latest_coimmit.message %>
    - <% if @entry && @entry.kind == 'file' %> - <%= render :partial => 'link_to_functions' %> - <% end %> +
    +
    + <%= render :partial => 'link_to_functions' %>
    <% end %> \ No newline at end of file diff --git a/app/views/repositories/_link_to_functions.html.erb b/app/views/repositories/_link_to_functions.html.erb index e1fc50330..8e92cb14f 100644 --- a/app/views/repositories/_link_to_functions.html.erb +++ b/app/views/repositories/_link_to_functions.html.erb @@ -1,25 +1,35 @@ -<% if @entry && @entry.kind == 'file' %> - <% if action_name != 'entry' %> - <%= link_to l(:label_history), {:action => 'changes', :id => @project, :repository_id => @repository.identifier_param, :path => to_path_param(@path), :rev => @rev }, :class =>"fr mr5"%> - <% else %> - <%= l(:label_history) %> - <% end %> - - <% if @repository.supports_cat? %> +<% if @project %> + <% if @entry && @entry.kind == 'file' %> <% if action_name != 'entry' %> - <%= link_to l(:button_view), {:action => 'entry', :id => @project, :repository_id => @repository.identifier_param, :path => to_path_param(@path), :rev => @rev }, :class =>"fr mr5" %> + <%= link_to l(:label_history), {:action => 'changes', :id => @project, :repository_id => @repository.identifier_param, :path => to_path_param(@path), :rev => @rev }, :class =>"fr mr5"%> <% else %> - <%= l(:button_view) %> + <%= l(:label_history) %> <% end %> - <% end %> + <% if @repository.supports_cat? %> + <% if action_name != 'entry' %> + <%= link_to l(:button_view), {:action => 'entry', :id => @project, :repository_id => @repository.identifier_param, :path => to_path_param(@path), :rev => @rev }, :class =>"fr mr5" %> + <% else %> + <%= l(:button_view) %> + <% end %> + + <% end %> <%# if @repository.supports_annotate? %> - <%#= link_to_if action_name != 'annotate', l(:button_annotate), {:action => 'annotate', :id => @project, :repository_id => @repository.identifier_param, :path => to_path_param(@path), :rev => @rev } %> + <%#= link_to_if action_name != 'annotate', l(:button_annotate), {:action => 'annotate', :id => @project, :repository_id => @repository.identifier_param, :path => to_path_param(@path), :rev => @rev } %> <%# end %> - <%= link_to(l(:button_download), - {:action => 'raw', :id => @project, - :repository_id => @repository.identifier_param, - :path => to_path_param(@path), - :rev => @rev}, :class => "fr mr5") if @repository.supports_cat? %> - <%= "(#{number_to_human_size(@entry.size)})" if @entry.size %> + <%= link_to(l(:button_download), + {:action => 'raw', :id => @project, + :repository_id => @repository.identifier_param, + :path => to_path_param(@path), + :rev => @rev}, :class => "fr mr5") if @repository.supports_cat? %> + <%= "(#{number_to_human_size(@entry.size)})" if @entry.size %> + <% end %> +<% else %> + <% if params[:controller] == "shixuns" && params[:action] == "entry_edit" %> + 保存 + <% elsif params[:action] == "shixun_entry" || params[:action] == "entry_update" %> + <%= link_to "编辑", entry_edit_shixun_path(@shixun, :path => @path, :rev => @rev), :class => "fl mr5", :remote => true %> + <% end %> <% end %> + + diff --git a/app/views/repositories/_shixun_breadcrumbs.html.erb b/app/views/repositories/_shixun_breadcrumbs.html.erb index b3a5793f4..905e0cbdc 100644 --- a/app/views/repositories/_shixun_breadcrumbs.html.erb +++ b/app/views/repositories/_shixun_breadcrumbs.html.erb @@ -12,9 +12,7 @@ link_path << '/' unless link_path.empty? link_path << "#{dir}" %> - / <%= link_to h(dir), {:action => 'shixun_show', :id => @shixun, :repository_id => @repository.identifier_param, - :path => to_path_param(link_path), :rev => @rev}, :class => "f14 fb" %> - <% end %> +/<%= link_to h(dir), {:action => 'shixun_show', :id => @shixun, :repository_id => @repository.identifier_param, :path => to_path_param(link_path), :rev => @rev}, :class => "f14 fb" %><% end %> <% if filename %> / <%#= link_to h(filename), {:action => 'changes', :id => @shixun, :repository_id => @repository.identifier_param, diff --git a/app/views/repositories/_shixun_dir_list_content.html.erb b/app/views/repositories/_shixun_dir_list_content.html.erb index ab6493cfa..76986c8df 100644 --- a/app/views/repositories/_shixun_dir_list_content.html.erb +++ b/app/views/repositories/_shixun_dir_list_content.html.erb @@ -8,22 +8,33 @@ - <% if entry.is_dir? %> - <%# 展开文件目录 %> -   - <% end %> + <%= link_to h(ent_name), {:action => (entry.is_dir? ? 'shixun_show' : 'shixun_entry'), :id => @shixun, :repository_id => @repository.identifier_param, :path => to_path_param(ent_path), :rev => @rev}, :class => (entry.is_dir? ? 'old-icon old-icon-folder' : "old-icon old-icon-file #{Redmine::MimeType.css_class_of(ent_name)}")%> +
    + + + + + + + + + + +
    + <% end %> diff --git a/app/views/repositories/commits.html.erb b/app/views/repositories/commits.html.erb index ef58abfa6..0502b6235 100644 --- a/app/views/repositories/commits.html.erb +++ b/app/views/repositories/commits.html.erb @@ -16,12 +16,12 @@ <%= time_tag(commit.created_at) %>前 <%= link_to_user_mail(commit.author_email, "pullreques_pull_name fl ml10") %>

    <%= commit.title %>

    - <%= link_to truncate(commit.short_id, :length => 20), {:controller => 'repositories', :action => 'commits', :id => @shixun.id, :changeset_id => commit.id}, :target => "_blank", :class => "fr mr15 c_grey" %> + <%= link_to truncate(commit.short_id, :length => 20), {:controller => 'repositories', :action => 'shixun_commit_diff', :id => @shixun, :changeset_id => commit.id}, :target => "_blank", :class => "fr mr15 c_grey" %> <% unless get_commit_issues(commit.short_id, @shixun.id, 0).nil? %> <% get_commit_issues(commit.short_id, @shixun.id, 0).each do |issue_id| %>
    <% if issue_id == "more" %> - <%= link_to "更多", {:controller => 'repositories', :action => 'commit_diff', :id => @shixun.id, :changeset => commit.id}, :target => "_blank", :class => "commit_id_value mr5" %> + <%= link_to "更多", {:controller => 'repositories', :action => 'commit_diff', :id => @shixun, :changeset => commit.id}, :target => "_blank", :class => "commit_id_value mr5" %> <% else %> <%= link_to "##{issue_id}", issue_path(issue_id), :target => "_blank", :class => "commit_id_value mr5" %> <% end %> @@ -35,15 +35,15 @@
    <% end %> +
    -
    +
      <%= pagination_links_full @commits_pages, @commits_count, :per_page_links => false, :remote => false, :flag => true, :is_new => true %>
    -
    <%= call_hook(:view_repositories_show_contextual, { :repository => @repository, :project => @shixun }) %> <% html_title(l(:label_change_plural)) -%> diff --git a/app/views/repositories/shixun_commit_diff.html.erb b/app/views/repositories/shixun_commit_diff.html.erb new file mode 100644 index 000000000..1570978b9 --- /dev/null +++ b/app/views/repositories/shixun_commit_diff.html.erb @@ -0,0 +1,24 @@ +
    +
    +
    + <%=link_to "返回提交历史".html_safe, + {:action => 'commits', :path => to_path_param(@path), :id => @shixun, :repository_id => @repository.identifier_param, + :rev => @rev, :page => 1 ,:commit_count =>"#{@changesets_all_count}"}, :class => "fl linkBlue2 mt3" %> +
    +
    + <% unless @commit_diff.blank? %> + <% @commit_diff.each do |commit_diff| %> + +
    + <%= render :partial => 'repositories/change_diff', :locals => {:change => commit_diff} %> +
    + <% end %> + <% else %> + <%= render "welcome/no_data" %> + <% end %> + +
    diff --git a/app/views/repositories/shixun_entry.html.erb b/app/views/repositories/shixun_entry.html.erb index 75a7b2748..8ff133f49 100644 --- a/app/views/repositories/shixun_entry.html.erb +++ b/app/views/repositories/shixun_entry.html.erb @@ -1,3 +1,6 @@ +<%= javascript_include_tag "/codemirror/lib/codemirror", "/codemirror/mode/javascript/javascript", "/codemirror/addon/hint/show-hint", "/codemirror/addon/hint/javascript-hint", "/codemirror/addon/selection/active-line", "/codemirror/addon/lint/javascript-lint", "/codemirror/addon/lint/css-lint", "/codemirror/addon/lint/lint", "/codemirror/addon/lint/json-lint", "/editormd/lib/codemirror/addon/lint/css-lint" %> +<%= stylesheet_link_tag "/codemirror/lib/codemirror" %> +
    @@ -9,8 +12,9 @@
    <%= render :partial => 'latest_commit' %> - <%= render :partial => 'common/file', :locals => {:filename => @path, :content => @content} %> - +
    + <%= render :partial => 'common/file', :locals => {:filename => @path, :content => @content} %> +
    <% content_for :header_tags do %> <%= stylesheet_link_tag "scm" %> <% end %> diff --git a/app/views/repositories/shixun_show.html.erb b/app/views/repositories/shixun_show.html.erb index 1fa1b14f6..b76b07421 100644 --- a/app/views/repositories/shixun_show.html.erb +++ b/app/views/repositories/shixun_show.html.erb @@ -1,4 +1,4 @@ -
    +
    diff --git a/app/views/repositories/show.html.erb b/app/views/repositories/show.html.erb index c5fa4876c..319fc9a4d 100644 --- a/app/views/repositories/show.html.erb +++ b/app/views/repositories/show.html.erb @@ -2,7 +2,7 @@
    • - <%=link_to "#{choise_commit_count(@changesets_all_count, @g_project.commit_count.to_i)}", + <%=link_to "#{choise_commit_count(@changesets_all_count.to_i, @g_project.commit_count.to_i)}", {:action => 'changes', :path => to_path_param(@path), :id => @project, :repository_id => @repository.identifier_param, :rev => @rev, :page => 1 ,:commit_count =>"#{@changesets_all_count}"}, :class => "linkBlue fb" %> 提交
    • diff --git a/app/views/shixuns/_add_collaborators.html.erb b/app/views/shixuns/_add_collaborators.html.erb new file mode 100644 index 000000000..6ed910de9 --- /dev/null +++ b/app/views/shixuns/_add_collaborators.html.erb @@ -0,0 +1,29 @@ + +
      +
      +

      添加合作者

      + +
      +
      +
      + <%= form_tag url_for(shixun_members_added_shixun_path(@shixun)), :remote => true, :method => :post, :id => 'add_collaborators_form' do |f| %> +
      +
      + + + +
      +
      +
        + <%#= render :partial => 'courses/settings/search_not_teachers_list' %> +
      +
      +
      + 取消 + 确定 + <% end %> +
      + +
      +
      +
      \ No newline at end of file diff --git a/app/views/shixuns/_apply_publish_notice.html.erb b/app/views/shixuns/_apply_publish_notice.html.erb new file mode 100644 index 000000000..d0ed1dde3 --- /dev/null +++ b/app/views/shixuns/_apply_publish_notice.html.erb @@ -0,0 +1,19 @@ +
      +
      +

      提示

      + +
      +
      +

      + <% if @status == 0 %> + 已发布过申请,请等待管理员审核 + <% else %> + 发布申请已提交,请等待管理员的审核
      + • 我们将在1-2个工作日内完成审核 + <% end %> +

      +
      +
      + 知道啦 +
      +
      \ No newline at end of file diff --git a/app/views/shixuns/_authority_pop.html.erb b/app/views/shixuns/_authority_pop.html.erb index fe0164797..c9f00f6fe 100644 --- a/app/views/shixuns/_authority_pop.html.erb +++ b/app/views/shixuns/_authority_pop.html.erb @@ -1,4 +1,4 @@ -
      +

      提示

      diff --git a/app/views/shixuns/_collaborators_list.html.erb b/app/views/shixuns/_collaborators_list.html.erb new file mode 100644 index 000000000..114c5ce64 --- /dev/null +++ b/app/views/shixuns/_collaborators_list.html.erb @@ -0,0 +1,11 @@ +<% @collaborators.each do |collaborators| %> + +<% end %> \ No newline at end of file diff --git a/app/views/shixuns/_entry_content.html.erb b/app/views/shixuns/_entry_content.html.erb new file mode 100644 index 000000000..c71616f75 --- /dev/null +++ b/app/views/shixuns/_entry_content.html.erb @@ -0,0 +1,144 @@ +<%= javascript_include_tag "/codemirror/lib/codemirror", "/codemirror/mode/javascript/javascript", "/codemirror/addon/hint/show-hint", "/codemirror/addon/hint/javascript-hint", "/codemirror/addon/selection/active-line", "/codemirror/addon/lint/javascript-lint", "/codemirror/addon/lint/css-lint", "/codemirror/addon/lint/lint", "/codemirror/addon/lint/json-lint", "/editormd/lib/codemirror/addon/lint/css-lint" %> +<%= stylesheet_link_tag "/codemirror/lib/codemirror" %> + + +
      +
    • + +
    • +
      + + \ No newline at end of file diff --git a/app/views/shixuns/_form.html.erb b/app/views/shixuns/_form.html.erb index b8a2176d1..6607e749c 100644 --- a/app/views/shixuns/_form.html.erb +++ b/app/views/shixuns/_form.html.erb @@ -1,82 +1,275 @@ -
      -
        - <%= form_for(@shixun) do |f| %> - <% if @shixun.errors.any? %> -
        -

        <%= pluralize(@shixun.errors.count, "error") %> prohibited this product from being saved:

        -
          - <% @shixun.errors.full_messages.each do |msg| %> -
        • <%= msg %>
        • - <% end %> -
        -
        +<%= stylesheet_link_tag '/editormd/css/editormd','/editormd/css/editormd.min.css' %> +<%= javascript_include_tag '/editormd/editormd.min.js' %> +
        +
        +
        +
          + <%= form_for(@shixun) do |f| %> + <% if @shixun.errors.any? %> +
          +

          <%= pluralize(@shixun.errors.count, "error") %> prohibited this product from being saved:

          +
            + <% @shixun.errors.full_messages.each do |msg| %> +
          • <%= msg %>
          • + <% end %> +
          +
          + <% end %> +
        • + + <%= f.text_field :name, :class => "panel-form-width-690 panel-form-height-30 panel-box-sizing fl", :placeholder => "请输入实训名称,最多60个字符", :maxlength => 60, :onkeyup => "regex_project_name();" %> + +
        • +
        • + +
          + +
          +

          +

          +
        • +
        • + +
          + +
          +

          +

          +
          +
        • +
        • + + <%= select_tag :major_id, options_for_select(shixun_major_option, 0), :id => 'shixun_major', :class => "fl task-form-30 task-height-40"%> +
          + +
        • +
        • + +
          + + +
            +
          +
          +
          + +
        • +
        • + + <%= select_tag :trainee, options_for_select(shixun_trainee, 0), :id => 'shixun_trainee', :class => "fl task-form-10 task-height-40" %> +
        • +
        • + + <%= select_tag :language, options_for_select(shixun_language, "Java"), :id => 'shixun_language', :class => "fl task-form-10 task-height-40" %> +
        • +
        • + 提交 + <%= link_to "取消", shixuns_path, :class => "task-btn fr mr10" %> +
        • <% end %> -
        • - - <%= f.text_field :name, :class => "project_new_input project_new_input_project_new", :placeholder => "请输入实训名称", :onkeyup => "regex_project_name();" %> - -
        • -
        • - - <%= f.kindeditor :description, :editor_id => 'project_create_editor', - :owner_id => @project.nil? ? 0: @project.id, - :owner_type => OwnerTypeHelper::PROJECT, - :width => '86%', - :height => 300, - :minHeight=> 300, - :class => 'courses_text ml5 fl', - :input_html => { :id => 'description', - :class => 'courses_text fl', - :maxlength => 5000 } - %> -
          -
        • -
        • - - <%= select_tag :language, options_for_select(["Java","C","C++","Python","Ruby","Mysql-Java"], "Java"), :id => 'shixun[language]', :class => "ml5", :style => "height: 28px;" %> -
        • -
        • - - <%= f.text_field :is_public, :id => "project_is_public", :name => "shixun[is_public]", :type => "checkbox", :value => "1", :checked => "checked" %> - (选中为公开实训,不选中为私有实训;私有实训仅自己可见。) -
          -
        • -
        • - 提交 - <%= link_to "取消",user_activities_path(User.current.id),:class => "grey_btn fl c_white ml10"%> -
          -
        • - <% end %> -
        +
      +
      +
      -
      - \ No newline at end of file diff --git a/app/views/shixuns/_monitor_tip.html.erb b/app/views/shixuns/_monitor_tip.html.erb index 7a8c99547..bb427fb4e 100644 --- a/app/views/shixuns/_monitor_tip.html.erb +++ b/app/views/shixuns/_monitor_tip.html.erb @@ -1,18 +1,26 @@ -
      -
      +
      +

      提示

      - -
      +
      -
      -
        -
      • - <% if result %> - 发布成功 - <% else %> - 服务器异常,请联系系统管理员 - <% end %> -
      • -
      +
      +

      + <% if result %> + <% if @status == 0 %> + 已发布过申请,请等待管理员审核 + <% else %> + 发布申请已提交,请等待管理员的审核
      + • 我们将在1-2个工作日内完成审核 + <% end %> + <% else %> + 实训云平台繁忙(繁忙等级:80) + <% end %> +

      +
      + <% if result && @status == 1 %> + <%= link_to "知道啦", shixun_path(@shixun), :class => "task-btn task-btn-blue pop_close" %> + <% else %> + 知道啦 + <% end %>
      diff --git a/app/views/shixuns/_search.html.erb b/app/views/shixuns/_search.html.erb new file mode 100644 index 000000000..dc862256a --- /dev/null +++ b/app/views/shixuns/_search.html.erb @@ -0,0 +1,9 @@ +<%= form_tag url_for(search_shixuns_path(:status => @status, :type => @type, :order => @order)), :remote => true, :method => :post, :id => 'add_collaborators_form', :onsubmit => "submitFn(this, event);", :class => "fl ml15" do |f| %> +
      +
      + + +
      + +
      +<% end %> \ No newline at end of file diff --git a/app/views/shixuns/_settings_edit.html.erb b/app/views/shixuns/_settings_edit.html.erb index 3046d12cc..361e75edb 100644 --- a/app/views/shixuns/_settings_edit.html.erb +++ b/app/views/shixuns/_settings_edit.html.erb @@ -1,9 +1,6 @@ -<%= content_for(:header_tags) do %> - <%= import_ke(enable_at: false, prettify: false, init_activity: false) %> -<% end %>
        - <%= labelled_form_for @shixun do |f| %> + <%= labelled_form_for @shixun, :remote => true do |f| %>
      • @@ -11,52 +8,216 @@
      • - <%= f.kindeditor :description, :editor_id => 'shixun_setting_editor', - :owner_id => @shixun.nil? ? 0: @shixun.id, - :owner_type => OwnerTypeHelper::PROJECT, - :width => '89.7%', - :height => 300, - :minHeight=> 300, - :class => 'fl ml5 w690', - :input_html => { :id => 'project_description', - :class => 'courses_text fl', - :maxlength => 5000 } - %> +
        + +
        +

        +

        +
      • + +
      • + + <%= select_tag :major_id, options_for_select(shixun_major_option, @shixun.major_id ? @shixun.major_id : 0), :id => 'shixun_major', :class => "fl task-form-30 task-height-40"%> +
        + +
      • +
      • + +
        + + +
          +
        +
        +
        +
      • - - <%= select_tag :language, options_for_select(["Java","C","C++","Python","Ruby","Mysql-Java"], @shixun.language), :id => 'shixun[language]', :style => "height:40px;" %> + + <%= select_tag :trainee, options_for_select(shixun_trainee, @shixun.trainee), :id => 'shixun_trainee', :class => "fl task-form-10 task-height-40" %>
      • + + <%= select_tag :language, options_for_select(shixun_language, @shixun.language), :id => 'shixun[language]', :class => "fl task-form-10 task-height-40" %> +
      • +
      • - 保存 + 保存
      • <% end %>
      diff --git a/app/views/shixuns/_settings_show.html.erb b/app/views/shixuns/_settings_show.html.erb new file mode 100644 index 000000000..a0b235874 --- /dev/null +++ b/app/views/shixuns/_settings_show.html.erb @@ -0,0 +1,122 @@ +
      +
      +
      +
      +

      + <% if @shixun.status == 0 && User.current.manager_of_shixun?(@shixun) %> + 编辑 + <% end %> +

      +
      +
        +
      • + +
        + <%= @shixun.name %> +
        +
      • +
      • + +
        + +
        +
      • +
      • + +
        + <%= @shixun.major ? @shixun.major.try(:name) : "" %> +
        +
      • +
      • + +
        + <%= @shixun.shixun_major_courses.blank? ? "" : CourseList.where(:id => @shixun.shixun_major_courses.map(&:course_list_id)).map(&:name).join(",") %> +
        +
      • +
      • + +
        + <%= @shixun.shixun_trainee %> +
        +
      • +
      • + +
        + <%= @shixun.language %> +
        +
      • +
      +
      +
      +
      + \ No newline at end of file diff --git a/app/views/shixuns/_shixun_course_search.html.erb b/app/views/shixuns/_shixun_course_search.html.erb new file mode 100644 index 000000000..7078b2ca8 --- /dev/null +++ b/app/views/shixuns/_shixun_course_search.html.erb @@ -0,0 +1,30 @@ +
        +
      • + type="radio" value=""> + +
      • + <% @courses.each do |course| %> +
      • + class="undis" id="course_<%= course.id %>" type="radio" value="<%= course.id %>"> + +
      • + <% end %> +
      + \ No newline at end of file diff --git a/app/views/shixuns/_shixun_list.html.erb b/app/views/shixuns/_shixun_list.html.erb index 28475000e..1ef96c1d5 100644 --- a/app/views/shixuns/_shixun_list.html.erb +++ b/app/views/shixuns/_shixun_list.html.erb @@ -1,36 +1,66 @@ -<% @shixuns.each do |shixun| %> -
      -
      -
      -

      - <%= shixun.name %> -

      -
      - <%= link_to image_tag(url_to_avatar(shixun.owner), :width =>"60", :height => "60", :class => "panel-warp-img mr10 fl", :alt=>"头像"), user_path(shixun.owner), :target => "_blank" %> - <%= link_to shixun.owner.try(:show_name), user_path(shixun.owner), :class => "task-index-name task-hide fl", :target => "_blank" %> -
      - -
      + +
      +<% if @shixuns.blank? %> +
      + <%= render :partial => "welcome/no_data" %> +
      +<% else %> + <% @shixuns.each do |shixun| %> +
      + <% if shixun.status < 2 && !User.current.manager_of_shixun?(shixun) %> +
      +
      +
      尚未正式发布,请稍等
      -
      + <% end %> +
      +

      + <%= shixun.name %> +

      + +
      + <%= shixun.language %> +

      <%= shixun.shixun_trainee %>

      +
      +
        +
      • <%= shixun.challenges.count %>
      • +
      • <%= shixun.myshixuns.count %>
      • +
      • <%= shixun.shixun_score %>
      • +
      -
        -
      • <%= shixun.challenges.count %>
      • - -
      • <%= shixun.myshixuns.count %>
      • + <% end %> +
        +
        +
        +
          + <%= pagination_links_full @shixun_pages, @shixuns_count, :per_page_links => false, :remote => @is_remote, :flag => true, :is_new => true %>
        +
        -
        <% end %> -
        - - - - - - - - - \ No newline at end of file +
      + diff --git a/app/views/shixuns/_shixun_major_search.html.erb b/app/views/shixuns/_shixun_major_search.html.erb new file mode 100644 index 000000000..2f7948c60 --- /dev/null +++ b/app/views/shixuns/_shixun_major_search.html.erb @@ -0,0 +1,34 @@ +
        +
      • + + +
      • +
      • + + +
      • +
      • + + +
      • +
      • + + +
      • +
      • + + +
      • +
      • + + +
      • +
      • + + +
      • +
      • + + +
      • +
      \ No newline at end of file diff --git a/app/views/shixuns/_shixun_pob.html.erb b/app/views/shixuns/_shixun_pob.html.erb new file mode 100644 index 000000000..d59c058a2 --- /dev/null +++ b/app/views/shixuns/_shixun_pob.html.erb @@ -0,0 +1,14 @@ +
      +
      +

      提示

      + +
      +
      +

      + <%= message %> +

      +
      +
      + 知道啦 +
      +
      diff --git a/app/views/shixuns/_shixun_top.html.erb b/app/views/shixuns/_shixun_top.html.erb index cfc6fdff8..a6b2eb37c 100644 --- a/app/views/shixuns/_shixun_top.html.erb +++ b/app/views/shixuns/_shixun_top.html.erb @@ -5,20 +5,52 @@ <%= @shixun.owner.try(:show_name) %> /

      <%= @shixun.name %>

      + + <% myshixun = Myshixun.where(:user_id => User.current.id, :shixun_id => @shixun.id).first %> <% if allow_shixun_exec(@shixun) %> - <% if User.current.id == @shixun.user_id %> - <% if @shixun.status == 1 %> - <%= link_to "重新发布", publish_shixun_path(@shixun, :type => "retry"), :class => "fr shixun-task-btn task-btn-orange mr15", :id => "challenge_begin", :remote => true %> - <% else %> - <%= link_to "发布实训", publish_shixun_path(@shixun), :class => "fr shixun-task-btn task-btn-orange mr15", :id => "challenge_begin", :remote => true %> + <% if @shixun.status == 0 %> + <% if User.current.manager_of_shixun?(@shixun) %> + <%= link_to "模拟实战", operation_shixun_path(@shixun, :myshixun_id => myshixun.try(:id)), :class => "fr shixun-task-btn task-btn-orange mr15", :id => "shixun_operation",:remote => true %> + <%#= link_to_shixun_exec myshixun, @shixun, '模拟实战' %> + 申请发布 + <%#= link_to "申请发布", publish_shixun_path(@shixun), :class => "fr shixun-task-btn task-btn-green mr15", :id => "challenge_begin", :remote => true %> <% end %> - <% end %> - <% if @shixun.status == 1 %> -
      - <%= link_to "开始挑战", shixun_exec_shixun_path(@shixun), :class => "fr shixun-task-btn task-btn-orange mr15", :id => "challenge_begin", :target => "_blank"%> -
      + <% elsif @shixun.status == 1 %> + <%= link_to "模拟实战", operation_shixun_path(@shixun, :myshixun_id => myshixun.try(:id)), :class => "fr shixun-task-btn task-btn-orange mr15", :id => "shixun_operation", :remote => true %> + <%#= link_to_shixun_exec myshixun, @shixun, '模拟实战' %> + <% if User.current.manager_of_shixun?(@shixun) %> + <%= link_to "撤销发布", cancel_publish_shixun_path(@shixun), :class => "fr shixun-task-btn task-btn-grey-white mr15", :id => "challenge_begin" %> + <% end %> + <% elsif @shixun.status == 2 %> + <% if myshixun.blank? %> + <%= link_to "开始实战", operation_shixun_path(@shixun, :myshixun_id => myshixun.try(:id)), :class => "fr shixun-task-btn task-btn-orange mr15", :id => "shixun_operation", :remote => true %> + <%#= link_to_shixun_exec myshixun, @shixun, '开始实战' %> + <% else %> + <%= link_to "继续实战", operation_shixun_path(@shixun, :myshixun_id => myshixun.try(:id)), :class => "fr shixun-task-btn task-btn-orange mr15", :id => "shixun_operation", :remote => true %> + <% end %> + <% if User.current.manager_of_shixun?(@shixun) %> + 永久关闭 + <% end %> + <% elsif @shixun.status == 3 %> + <% unless myshixun.blank? %> + <%= link_to "继续实战", operation_shixun_path(@shixun, :myshixun_id => myshixun.try(:id)), :class => "fr shixun-task-btn task-btn-orange mr15", :id => "shixun_operation", :remote => true %> + <% end %> + 已关闭 <% end %> <% end %>
      + + diff --git a/app/views/shixuns/_shixun_yx.html b/app/views/shixuns/_shixun_yx.html new file mode 100644 index 000000000..88478f5e8 --- /dev/null +++ b/app/views/shixuns/_shixun_yx.html @@ -0,0 +1,397 @@ + + + + + + + + + + + + + + + + + +
      +
      +
      +
      + 适用专业 +
      +
        +
      • 不限
      • +
      • 计算机科学与技术
      • +
      • 软件工程
      • +
      • 网络工程
      • +
      • 信息安全
      • +
      • 通信工程
      • +
      • 信息工程
      • +
      • 物联网工程
      • +
      +
      +
      +
      + 适用课程 +
      +
        +
      • 不限
      • +
      • 数据结构
      • +
      • 离散数学
      • +
      • 计算机思维导论
      • +
      • 算法分析
      • +
      • C++程序设计
      • +
      • java程序设计
      • +
      • python程序设计
      • +
      • linux操作系统
      • +
      • 数据库系统
      • +
      • 计算机安全
      • +
      • 自然语言处理
      • +
      • 数字逻辑
      • +
      • 数据库系统
      • +
      • 计算机安全
      • +
      • 自然语言处理
      • +
      • 数字逻辑
      • +
      • 数据库系统
      • +
      • 计算机安全
      • +
      • 数据结构
      • +
      • 离散数学
      • +
      • 计算机思维导论
      • +
      • 算法分析
      • +
      • C++程序设计
      • +
      • java程序设计
      • +
      • python程序设计
      • +
      • linux操作系统
      • +
      • 数据库系统
      • +
      • 计算机安全
      • +
      • 自然语言处理
      • +
      • 数字逻辑
      • +
      • 数据库系统
      • +
      • 计算机安全
      • +
      • 自然语言处理
      • +
      • 数字逻辑
      • +
      • 数据库系统
      • +
      • 计算机安全
      • +
      • linux操作系统
      • +
      • 数据库系统
      • +
      • 计算机安全
      • +
      • 自然语言处理
      • +
      • 数字逻辑
      • +
      • 数据库系统
      • +
      • 计算机安全
      • +
      • 自然语言处理
      • +
      • 数字逻辑
      • +
      • 数据库系统
      • +
      • 计算机安全
      • +
      +
      + + 更多 + + + +
      +
      + 技术平台 +
      +
        +
      • 不限
      • +
      • java
      • +
      • C
      • +
      • C++
      • +
      • python
      • +
      • Ruby
      • +
      • JDBC
      • +
      +
      +
      +
      + 筛选条件 + +
      +
      + + +
      + +
      +
      +
      + +
      +
      +
      +

      + MySQL数据库编程开发实训(基础篇) +

      +
      + 头像 + 李乾坤 +
      +
      + MySQL/Java +

      初级学员

      +
      +
        +
      • 7
      • + +
      • 29
      • +
      • +500
      • +
      +
      +
      +
      +

      + MySQL数据库编程开发实训(基础篇) +

      +
      + 头像 + 李乾坤 +
      +
      + MySQL/Java +

      初级学员

      +
      +
        +
      • 7
      • + +
      • 29
      • +
      • +500
      • +
      +
      +
      +
      +

      + MySQL数据库编程开发实训(基础篇) +

      +
      + 头像 + 李乾坤 +
      +
      + MySQL/Java +

      初级学员

      +
      +
        +
      • 7
      • + +
      • 29
      • +
      • +500
      • +
      +
      +
      +
      +

      + MySQL数据库编程开发实训(基础篇) +

      +
      + 头像 + 李乾坤 +
      +
      + MySQL/Java +

      初级学员

      +
      +
        +
      • 7
      • + +
      • 29
      • +
      • +500
      • +
      +
      +
      +
      +

      + MySQL数据库编程开发实训(基础篇) +

      +
      + 头像 + 李乾坤 +
      +
      + MySQL/Java +

      初级学员

      +
      +
        +
      • 7
      • + +
      • 29
      • +
      • +500
      • +
      +
      +
      +
      +

      + MySQL数据库编程开发实训(基础篇) +

      +
      + 头像 + 李乾坤 +
      +
      + MySQL/Java +

      初级学员

      +
      +
        +
      • 7
      • + +
      • 29
      • +
      • +500
      • +
      +
      +
      +
      +

      + MySQL数据库编程开发实训(基础篇) +

      +
      + 头像 + 李乾坤 +
      +
      + MySQL/Java +

      初级学员

      +
      +
        +
      • 7
      • + +
      • 29
      • +
      • +500
      • +
      +
      +
      +
      +

      + MySQL数据库编程开发实训(基础篇) +

      +
      + 头像 + 李乾坤 +
      +
      + MySQL/Java +

      初级学员

      +
      +
        +
      • 7
      • + +
      • 29
      • +
      • +500
      • +
      +
      +
      +
      +
      + + + diff --git a/app/views/shixuns/add_collaborators.js.erb b/app/views/shixuns/add_collaborators.js.erb new file mode 100644 index 000000000..36fbc2af7 --- /dev/null +++ b/app/views/shixuns/add_collaborators.js.erb @@ -0,0 +1,6 @@ +<% if params[:is_observe] %> +$("#search_not_teachers_list").html("<%= j(render :partial => 'courses/settings/search_not_teachers_list') %>"); +<% else %> +var htmlvalue = "<%= j(render :partial => 'shixuns/add_collaborators') %>"; +pop_box_new(htmlvalue, 600, 420); +<% end %> \ No newline at end of file diff --git a/app/views/shixuns/apply_publish.js.erb b/app/views/shixuns/apply_publish.js.erb new file mode 100644 index 000000000..e4ece3d29 --- /dev/null +++ b/app/views/shixuns/apply_publish.js.erb @@ -0,0 +1,2 @@ +var htmlvalue = "<%= j(render :partial => "shixuns/apply_publish_notice") %>"; +pop_box_new(htmlvalue, 400, 300); \ No newline at end of file diff --git a/app/views/shixuns/autocompletion.html.erb b/app/views/shixuns/autocompletion.html.erb new file mode 100644 index 000000000..0e92bdde3 --- /dev/null +++ b/app/views/shixuns/autocompletion.html.erb @@ -0,0 +1,222 @@ +<%= javascript_include_tag "/codemirror/lib/codemirror", "/codemirror/mode/javascript/javascript", "/codemirror/addon/hint/show-hint", "/codemirror/addon/hint/anyword-hint", "/codemirror/addon/edit/matchbrackets", "/codemirror/addon/hint/javascript-hint" %> +<%= stylesheet_link_tag "/codemirror/lib/codemirror", "/codemirror/addon/hint/show-hint", "/codemirror/doc/docs", "/codemirror/addon/lint/lint" %> + + + +
      +

      Any Word Completion Demo

      +
      + +

      Press ctrl-space to activate autocompletion. The + completion uses + the anyword-hint.js + module, which simply looks at nearby words in the buffer and completes + to those.

      + + +
      diff --git a/app/views/shixuns/collaborators.html.erb b/app/views/shixuns/collaborators.html.erb new file mode 100644 index 000000000..35f5610e9 --- /dev/null +++ b/app/views/shixuns/collaborators.html.erb @@ -0,0 +1,15 @@ +
      +
      + <%= image_tag(url_to_avatar(@shixun.owner), :width => 60, :height => 60, :class => 'panel-list-img mr15 mt5') %> + + <% if User.current. manager_of_shixun?(@shixun) %> + 合作者 + <% end %> +
      +
      + <%= render :partial => "shixuns/collaborators_list" %> +
      +
      \ No newline at end of file diff --git a/app/views/shixuns/collaborators_delete.js.erb b/app/views/shixuns/collaborators_delete.js.erb new file mode 100644 index 000000000..f367b9c1a --- /dev/null +++ b/app/views/shixuns/collaborators_delete.js.erb @@ -0,0 +1 @@ +$("#collaborators_list").html("<%= j(render :partial => 'shixuns/collaborators_list') %>"); \ No newline at end of file diff --git a/app/views/shixuns/edit.html.erb b/app/views/shixuns/edit.html.erb new file mode 100644 index 000000000..e69de29bb diff --git a/app/views/shixuns/entry_edit.js.erb b/app/views/shixuns/entry_edit.js.erb new file mode 100644 index 000000000..18d037594 --- /dev/null +++ b/app/views/shixuns/entry_edit.js.erb @@ -0,0 +1,2 @@ +$("#common_file_content").html('<%= escape_javascript(render :partial => 'shixuns/entry_content') %>'); +$("#file_action").html('<%= escape_javascript(render :partial => 'repositories/link_to_functions') %>'); diff --git a/app/views/shixuns/entry_update.js.erb b/app/views/shixuns/entry_update.js.erb new file mode 100644 index 000000000..61a958697 --- /dev/null +++ b/app/views/shixuns/entry_update.js.erb @@ -0,0 +1,2 @@ +$("#common_file_content").html('<%= escape_javascript(render :partial => 'common/file', :locals => {:filename => @path, :content => @content}) %>') +$("#file_action").html('<%= escape_javascript(render :partial => 'repositories/link_to_functions') %>'); \ No newline at end of file diff --git a/app/views/shixuns/game_webssh.html.erb b/app/views/shixuns/game_webssh.html.erb new file mode 100644 index 000000000..57dbd0fb8 --- /dev/null +++ b/app/views/shixuns/game_webssh.html.erb @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/app/views/shixuns/index.html.erb b/app/views/shixuns/index.html.erb index 73006162b..5eae7fb6d 100644 --- a/app/views/shixuns/index.html.erb +++ b/app/views/shixuns/index.html.erb @@ -1,98 +1,354 @@ -
      -
      +
      +
      -

      游戏实训

      - <%= link_to "创建", new_shixun_path, :class => "task-btn task-btn-green fr" %> +

      实训分类

      + <%= link_to "+ 创建实训".html_safe, new_shixun_path, :class => "fr color_white font-20" %>
        -
      • <%= @shixuns_count %>
        全部实训
      • +
      • <%= @shixun_all_count %>
        全部实训
      • <%= @current_user_had_passed %>
        你已通过
      • -
      • <%= @shixun_my_score %>
        取得成绩
      • +
      • <%= @shixun_my_score %>
        累计经验值
      -
      -

      -

      - 热度排序 - -
      -
      - 时间排序 - -
      - 排序方式: - -

      -
      -
      +
      +
      +
      +
      + 适用专业 + +
      +
      + 适用课程 + + + 更多 + + + +
      +
      + 技术平台 +
      +
        +
      • + + +
      • +
      • + + +
      • +
      • + + +
      • +
      • + + +
      • +
      • + + +
      • +
      • + + +
      • +
      +
      +
      +
      + 筛选条件 +
      +
    • + 所有状态 + +
    • +
    • + 所有难度 + +
    • +
    • + 所有进展 + +
    • +
      +
      +
      + + +
      + +
      +
      +
      +
      + +
      <%= render "shixun_list" %>
      +
      + +<%= render :partial => 'layouts/public_left_info' %> + \ No newline at end of file diff --git a/app/views/shixuns/index.js.erb b/app/views/shixuns/index.js.erb new file mode 100644 index 000000000..e82692b2f --- /dev/null +++ b/app/views/shixuns/index.js.erb @@ -0,0 +1 @@ +$("#shixun_list_content").html('<%= escape_javascript( render :partial => 'shixuns/shixun_list') %>'); \ No newline at end of file diff --git a/app/views/shixuns/new.html.erb b/app/views/shixuns/new.html.erb index ed842d552..58acf4c74 100644 --- a/app/views/shixuns/new.html.erb +++ b/app/views/shixuns/new.html.erb @@ -1,12 +1,9 @@ -<%= content_for(:header_tags) do %> - <%= import_ke(enable_at: false, prettify: false, init_activity: false) %> -<% end %> -<%= error_messages_for 'project' %> -
      -

      新建实训

      -
      - -<%= render 'form' %> - - - +
      +

      + <%= User.current.show_name %> > 项目实训 > 新建实训 +

      +
      +

      新建实训

      +
      + <%= render :partial => 'form' %> +
      \ No newline at end of file diff --git a/app/views/shixuns/new_disscuss.html.erb b/app/views/shixuns/new_disscuss.html.erb new file mode 100644 index 000000000..48d6e4de5 --- /dev/null +++ b/app/views/shixuns/new_disscuss.html.erb @@ -0,0 +1,271 @@ + +
      +

      + + kosasa > + 实训课堂 > + 环境保护 >环境保护1班 +

      +
      +
      +

      新建帖子

      +
      + +
      +
      +
      +
      + +
      +
      +

      帖子详情

      + 返回帖子列表 +
      +
      +
      + 用户 +
      +
      开启实训就训”就是参加实训吗?实训就训”就是参加实训吗?实训就训”就是参加训就训”就是参加训训吗?置顶
      +

      +
      +

      + 尹刚尹刚尹刚尹刚刚尹刚刚尹刚 + 发表于10天前 + 更新于10分钟前 +

      +

      + 473 + 473 + 473 +

      + +
      +
      +

      实训开始后,点击“开启实训”进入实训,是不是就可以参加实训完成任务啦?实训开始后,点击“开启实训”进入实训,是不是就可以参加实 + 训完成任务啦?实训开始后,点击“开启实训”进入实训,是不是就可以参加实训完成任务啦?实训开始后,点击“开启实训”进入实训,是不 + 是就可以参加实训完成任务啦?实训开始后,点击“开启实训”进入实训,是不是就可以参加实训完成任务啦?实训开始后,点击“开启实训” + 进入实训,是不是就可以参加实训完成任务啦?

      + +
      + +
      +
      +
      +
      全部回复(41)
      +

      + 赞(5) + 回复(10) +

      +
      +
      +
      +
      头像
      +
      +
      +
      + Cillian风吹麦浪1分钟前 +
      +
      +
      +
      +
      +
      +
      +
      +
      +
      + 头像 +
      +
      + suntao30分钟前 +
      看看人家对待动物,再看看我们的活烤牛,这就是一个社会进步的表现,我们还很原始,不文明的社会看看人家对待动物,再看看我们的活烤牛,这就是一个社会进步的表现,我们还很原始,不文明的社会,看看人家对待动物,再看看我们的活烤牛,这就是一个社会进步的表现,我们还很原始,不文明的社会,,
      +
      +
      +

      + 删除 + 赞(5) + 回复 +

      +
      +
      +
      + 头像 +
      +
      + suntao30分钟前 +
      看看人家
      +
      +
      +

      + 赞(5) + 回复 +

      +
      +
      +
      + 头像 +
      +
      + suntao30分钟前 +
      看看人家对待动物,再看看我们的活烤牛,这就是一个社会进步的表现,我们
      +
      +
      +

      + 赞(5) + 回复 +

      +
      +
      +
      + 头像 +
      +
      + yixin5分钟前 +
      烤活牛你见过似的,美国那边吃人你怎么不信?
      +
      +
      +

      + 赞(5) + 回复 +

      +
      + + + +
      +
      点击展开隐藏楼层
      +
      + 头像 +
      +
      + yixin5分钟前 +
      烤活牛你见过似的,美国那边吃人你怎么不信?
      +
      +
      +

      + 赞(5) + 回复 +

      +
      +
      +
      +
      校园枪击案你知道吗校园枪击案你知道吗校园枪击案你知道吗校园枪击案你知道吗校园枪击案你知道吗校园枪击案你知道吗
      +
      +

      + 赞(5) + 回复 +

      +
      +
      + +
      +
      +
      +
      +
      + +
      +
      头像
      +
      +
      +
      + Cillian风吹麦浪1分钟前 +
      +
      +
      +
      +
      +
      校园枪击案你知道吗校园枪击案你知道吗校园枪击案你知道吗校园枪击案你知道吗校园枪击案你知道吗校园枪击案你知道吗
      +
      +
      +

      + 赞(5) + 回复 +

      +
      +
      +
      +
      + +
      +
      +
      +
      +
      + +
      +
      +
      + 头像 +
      + + 发布 +
      +
      +
      + +
      +
      +
      + +
      +
      +
      + + + diff --git a/app/views/shixuns/operation.js.erb b/app/views/shixuns/operation.js.erb new file mode 100644 index 000000000..5ce9959f3 --- /dev/null +++ b/app/views/shixuns/operation.js.erb @@ -0,0 +1,13 @@ +<% if @mail %> +notice_box_redirect('#{security_settings_path}', '开启实训,请先绑定邮箱') +<% else %> +<% if @is_modify.blank? %> +//为了防止浏览器阻挡 +window.location.href="<%= shixun_exec_shixun_path(@shixun) %>" +//var tempwindow = window.open(); +//tempwindow.location = '<%#= shixun_exec_shixun_path(@shixun) %>'; +//window.open("<%#= shixun_exec_shixun_path(@shixun) %>"); +<% else %> +sure_box_redirect('<%= myshixun_reset_myshixun_path(@myshixun) %>', '实训已经更新啦,系统正在为您重置') +<% end %> +<% end %> \ No newline at end of file diff --git a/app/views/shixuns/propaedeutics.html.erb b/app/views/shixuns/propaedeutics.html.erb new file mode 100644 index 000000000..b74beaee5 --- /dev/null +++ b/app/views/shixuns/propaedeutics.html.erb @@ -0,0 +1,121 @@ +<%= stylesheet_link_tag '/editormd/css/editormd','/editormd/css/editormd.min.css' %> +<%= javascript_include_tag '/editormd/lib/marked.min.js','/editormd/lib/prettify.min.js','/editormd/lib/raphael.min.js','/editormd/lib/underscore.min.js','/editormd/lib/sequence-diagram.min.js', + '/editormd/lib/flowchart.min.js','/editormd/lib/jquery.flowchart.min.js','/editormd/editormd.js'%> + +
      +
      +
      +

      预备知识

      + <% if @shixun.status == 0 && User.current.manager_of_shixun?(@shixun) %> + 编辑 + <% end %> +
      +
      +
        + <%= form_tag update_propaedeutics_shixun_path(@shixun), :method =>"post", :id => "update_propaedeutics" do |f| %> +
      • + +
        + +
        +

        +

        +
      • +
      • + 保存 + 取消 +
      • + <% end %> +
      +
      +
      + <% if @shixun.propaedeutics.nil? %> + <%= render :partial => "welcome/no_data" %> + <% else %> +
      + +
      + <% end %> +
      +
      + +
      + \ No newline at end of file diff --git a/app/views/shixuns/publish.js.erb b/app/views/shixuns/publish.js.erb index c32de7a77..b4099d3ae 100644 --- a/app/views/shixuns/publish.js.erb +++ b/app/views/shixuns/publish.js.erb @@ -1,8 +1,11 @@ +<% unless @status && @status = 1 %> + $("#apply_publish_shixun").attr("data-option", 1); + $("#apply_publish_shixun").removeClass("disabled-grey-bg"); +<% end %> <% if @jenkin_error %> var htmlvalue = "<%= escape_javascript(render :partial => 'shixuns/monitor_tip', :locals => {:result => false} )%>"; - pop_box_new(htmlvalue,460,406); + pop_box_new(htmlvalue,563,406); <% else %> var htmlvalue = "<%= escape_javascript(render :partial => 'shixuns/monitor_tip', :locals => {:result => true}) %>"; - pop_box_new(htmlvalue,460,406); - $("#shixun_top").html('<%= escape_javascript(render :partial => 'shixuns/shixun_top') %>'); + pop_box_new(htmlvalue,563,406); <% end %> diff --git a/app/views/shixuns/search.js.erb b/app/views/shixuns/search.js.erb index e82692b2f..9f7277e26 100644 --- a/app/views/shixuns/search.js.erb +++ b/app/views/shixuns/search.js.erb @@ -1 +1,2 @@ +$("#shixun_course_search").html("<%= escape_javascript( render :partial => 'shixuns/shixun_course_search') %>"); $("#shixun_list_content").html('<%= escape_javascript( render :partial => 'shixuns/shixun_list') %>'); \ No newline at end of file diff --git a/app/views/shixuns/settings.html.erb b/app/views/shixuns/settings.html.erb index 611d91334..93b973012 100644 --- a/app/views/shixuns/settings.html.erb +++ b/app/views/shixuns/settings.html.erb @@ -1,3 +1,7 @@ +<%= stylesheet_link_tag '/editormd/css/editormd','/editormd/css/editormd.min.css' %> +<%= javascript_include_tag '/editormd/lib/marked.min.js','/editormd/lib/prettify.min.js','/editormd/lib/raphael.min.js','/editormd/lib/underscore.min.js','/editormd/lib/sequence-diagram.min.js', + '/editormd/lib/flowchart.min.js','/editormd/lib/jquery.flowchart.min.js','/editormd/editormd.js'%> +
      @@ -14,7 +18,12 @@
    - <%= render :partial=> "shixuns/settings_edit" %> +
    + <%= render :partial=> "shixuns/settings_edit" %> +
    +
    + <%= render :partial => "shixuns/settings_show" %> +
    <%= render :partial=>"shixuns/settings_repository" %> @@ -25,32 +34,7 @@
    -<% if false %> -
    -
    -
      - <% show_memu = show_project_memu User.current %> -
    • 信息
    • - -
    • 版本库
    • - -
    -
    -
    -
    - <%= render :partial=> "shixuns/settings_edit" %> -
    -
    - <%= render :partial=>"shixuns/settings_repository" %> -
    - - - - -
    -
    -<% end %> \ No newline at end of file + + <% if @homework.anonymous_comment == 0 %> + + <% if student_work.student_score.nil? %> + <% if student_work.work_status != 0 %> + <% if @homework.homework_detail_manual.comment_status >= 3 && student_work.student_works_evaluation_distributions.count == 0 %> + 未参加 + + <% else %> + -- + <% end %> + <% else %> + -- + <% end %> + <% else %> + <% if !score_open %> + ** + <% else %> + <%=format("%.1f",student_work.student_score) %>(<%= student_work.student_works_scores.where(:reviewer_role => 3).group_by(&:user_id).count%>) + + <% end %> + <% end %> + + <% end %> + + <% score = student_work.work_score %> + + <%= score.nil? ? "--" : (!score_open ? "**" : format("%.1f",score<0 ? 0 : score))%> + <% unless !score_open || score.nil?%> + + <% end%> + + + <%= link_to "#{@is_teacher ? '评阅' : (student_work.work_status == 0 ? '--' : '查看')}", student_work_path(student_work) %> + + \ No newline at end of file diff --git a/app/views/student_work/_evaluation_un_pro_title.html.erb b/app/views/student_work/_evaluation_un_pro_title.html.erb index 86c102a4d..f23537351 100644 --- a/app/views/student_work/_evaluation_un_pro_title.html.erb +++ b/app/views/student_work/_evaluation_un_pro_title.html.erb @@ -1,55 +1,24 @@ - - 序号 -   - - <%= link_to "姓名", @show_all ? student_work_index_path(:homework => @homework.id, :order => "lastname", :sort => @score, :name => @name, :group => @group) : "javascript:void(0)", :class => "c_dark f14 fb", :remote => true %> - <% if @show_all && @order == "lastname" %> - <%= link_to "", student_work_index_path(:homework => @homework.id, :order => "lastname", :sort => @score, :name => @name, :group => @group), :class => "#{@score == 'desc' ? 'sort_up' : 'sort_down'} float-none", :style => "line-height:30px; vertical-align:middle;", :remote => true %> - <% end %> - - - <%= link_to "学号", @show_all ? student_work_index_path(:homework => @homework.id, :order => "student_id", :sort => @score, :name => @name, :group => @group) : "javascript:void(0)", :class => "c_dark f14 fb", :remote => true %> - <% if @show_all && @order == "student_id" %> - <%= link_to "", student_work_index_path(:homework => @homework.id, :order => "student_id", :sort => @score, :name => @name, :group => @group), :class => "#{@score == 'desc' ? 'sort_up' : 'sort_down'} float-none", :style => "line-height:30px; vertical-align:middle;", :remote => true %> - <% end %> - - - - <%= link_to "时间", @show_all ? student_work_index_path(:homework => @homework.id, :order => "created_at", :sort => @score, :name => @name, :group => @group) : "javascript:void(0)", :class => "c_dark f14 fb", :remote => true %> - <% if @show_all && @order == "created_at" %> - <%= link_to "", student_work_index_path(:homework => @homework.id, :order => "created_at", :sort => @score, :name => @name, :group => @group), :class => "#{@score == 'desc' ? 'sort_up' : 'sort_down'} float-none", :style => "line-height:30px; vertical-align:middle;", :remote => true %> - <% end %> - - - <%= link_to "教师", @show_all ? student_work_index_path(:homework => @homework.id, :order => "teacher_score", :sort => @score, :name => @name, :group => @group) : "javascript:void(0)", :class => "c_dark f14 fb", :remote => true %> - <% if @show_all && @order == "teacher_score" %> - <%= link_to "", student_work_index_path(:homework => @homework.id, :order => "teacher_score", :sort => @score, :name => @name, :group => @group), :class => "#{@score == 'desc' ? 'sort_up' : 'sort_down'} float-none", :style => "line-height:30px; vertical-align:middle;", :remote => true %> - <% end %> - - - <%= link_to "教辅", @show_all ? student_work_index_path(:homework => @homework.id, :order => "teaching_asistant_score", :sort => @score, :name => @name, :group => @group) : "javascript:void(0)", :class => "c_dark f14 fb", :remote => true %> - <% if @show_all && @order == "teaching_asistant_score" %> - <%= link_to "", student_work_index_path(:homework => @homework.id, :order => "teaching_asistant_score", :sort => @score, :name => @name, :group => @group), :class => "#{@score == 'desc' ? 'sort_up' : 'sort_down'} float-none", :style => "line-height:30px; vertical-align:middle;", :remote => true %> - <% end %> - - - <%= link_to "系统", @show_all ? student_work_index_path(:homework => @homework.id, :order => "system_score", :sort => @score, :name => @name, :group => @group) : "javascript:void(0)", :class => "c_dark f14 fb", :remote => true %> - <% if @show_all && @order == "system_score" %> - <%= link_to "", student_work_index_path(:homework => @homework.id, :order => "system_score", :sort => @score, :name => @name, :group => @group), :class => "#{@score == 'desc' ? 'sort_up' : 'sort_down'} float-none", :style => "line-height:30px; vertical-align:middle;", :remote => true %> - <% end %> - + + + 序号 + 姓名 + 学号 + 提交状态 + 更新时间 + 教师评分 + 助教评分 + 系统评分 <% if @homework.anonymous_comment == 0 %> - - <%= link_to "匿评", @show_all ? student_work_index_path(:homework => @homework.id, :order => "student_score", :sort => @score, :name => @name, :group => @group) : "javascript:void(0)", :class => "c_dark f14 fb", :remote => true %> - <% if @show_all && @order == "student_score" %> - <%= link_to "", student_work_index_path(:homework => @homework.id, :order => "student_score", :sort => @score, :name => @name, :group => @group), :class => "#{@score == 'desc' ? 'sort_up' : 'sort_down'} float-none", :style => "line-height:30px; vertical-align:middle;", :remote => true %> - <% end %> - + 匿评评分 <% end %> - - <%= link_to "成绩", @show_all ? student_work_index_path(:homework => @homework.id, :order => "score", :sort => @score, :name => @name, :group => @group) : "javascript:void(0)", :class => "c_dark f14 fb", :remote => true %> - <% if @show_all && @order == "score" %> - <%= link_to "", student_work_index_path(:homework => @homework.id, :order => "score", :sort => @score, :name => @name, :group => @group), :class => "#{@score == 'desc' ? 'sort_up' : 'sort_down'} float-none", :style => "line-height:30px; vertical-align:middle;", :remote => true %> - <% end %> - - \ No newline at end of file + 最终成绩 + 操作 + + + +<% @stundet_works.each_with_index do |student_work, i| %> + <% score_open = @is_teacher || @homework.score_open == 1 || student_work.user == User.current %> + + <%= render :partial => "evaluation_un_pro_work", :locals => {:student_work => student_work, :index => i, :score_open => score_open} %> +<% end %> + \ No newline at end of file diff --git a/app/views/student_work/_evaluation_un_pro_work.html.erb b/app/views/student_work/_evaluation_un_pro_work.html.erb index c23811304..d891e3da2 100644 --- a/app/views/student_work/_evaluation_un_pro_work.html.erb +++ b/app/views/student_work/_evaluation_un_pro_work.html.erb @@ -1,83 +1,92 @@ - - - <%= index + 1 %> - - <%= link_to(image_tag(url_to_avatar(student_work.user), :width => "40", :height => "40", :style => "display:block;"), user_activities_path(student_work.user)) %> + + <%= (@page - 1) * @limit + index + 1 %> + + <%= link_to student_work.user.show_real_name, user_path(student_work.user) %> - - <%= student_work.user.show_name %> - - " onclick="show_student_work('<%= student_work_path(student_work)%>');" style="cursor:pointer;"> + "> <%= student_work.user.user_extensions.nil? ? "--" : student_work.user.user_extensions.student_id %> - - <% if student_work.created_at && @homework.end_time %> - <%= Time.parse(format_time(student_work.created_at)).strftime("%m-%d %H:%M") %>  - <% if @homework.end_time < student_work.created_at %> - [迟交] - <% end %> + + <%= list_work_status student_work.work_status %> + + + <%= student_work.work_status == 0 ? '--' : format_time(student_work.updated_at) %> + + + <%= student_work.teacher_score.nil? ? "--" : (!score_open ? "**" : format("%.1f",student_work.teacher_score))%> + + + <%= student_work.teaching_asistant_score.nil? ? "--" : (!score_open ? "**" : format("%.1f",student_work.teaching_asistant_score))%> + <% if !student_work.teaching_asistant_score.nil? && score_open %> + <% end %> - - <%= student_work.teacher_score.nil? ? "--" : format("%.1f", student_work.teacher_score) %> - - - <%= student_work.teaching_asistant_score.nil? ? "--" : format("%.1f", student_work.teaching_asistant_score) %> - - - - <%= student_work.system_score.nil? ? "--" : format("%.1f", student_work.system_score) %> + + <%= student_work.system_score.nil? ? "--" : (!score_open ? "**" : format("%.1f",student_work.system_score))%> <% if @homework.anonymous_comment == 0 %> - + <% if student_work.student_score.nil? %> - 未参与 + <% if student_work.work_status != 0 %> + <% if @homework.homework_detail_manual.comment_status >= 3 && student_work.student_works_evaluation_distributions.count == 0 %> + 未参加 + + <% else %> + -- + <% end %> + <% else %> + -- + <% end %> <% else %> - <%= format("%.1f", student_work.student_score) %> - <% end %> - <% unless student_work.student_score.nil? %> - - (<%= student_work.student_works_scores.where(:reviewer_role => 3).group_by(&:user_id).count %>) - - -
    - 现共有 -  <%= student_work.student_works_scores.where(:reviewer_role => 3).group_by(&:user_id).count %>  - 名学生进行了匿评,平均分为 -  <%= format("%.1f", student_work.student_score) %> 分。 -
    + <% if !score_open %> + ** + <% else %> + <%=format("%.1f",student_work.student_score) %>(<%= student_work.student_works_scores.where(:reviewer_role => 3).group_by(&:user_id).count%>) + + <% end %> <% end %> <% end %> - <% if student_work.homework_common && student_work.homework_common.teacher_priority == 1 && student_work.teacher_score %> - <% score = student_work.respond_to?("score") ? student_work.score : student_work.teacher_score %> - <% else %> - <% score = student_work.respond_to?("score") ? student_work.score : (student_work.final_score || 0) - student_work.absence_penalty - student_work.late_penalty %> - <% end %> - - <%= score.nil? ? "--" : format("%.1f", score<0 ? 0 : score) %> - <% unless score.nil? %> -
    - 作品最终评分为 -  <%= student_work.final_score %> 分。 - 迟交扣分 -   - <%= student_work.homework_common && student_work.homework_common.teacher_priority == 1 && student_work.teacher_score ? 0 : student_work.late_penalty %> -  分, - 缺评扣分 -   - <%= student_work.homework_common && student_work.homework_common.teacher_priority == 1 && student_work.teacher_score ? 0 : student_work.absence_penalty %> -  分, - 最终成绩为 -  <%= format("%.1f", score<0 ? 0 : score) %> 分。 + <% score = student_work.work_score %> + + <%= score.nil? ? "--" : (!score_open ? "**" : format("%.1f",score<0 ? 0 : score))%> + <% unless !score_open || score.nil?%> + - <% end %> + <% end%> -
    - -
    + <%= link_to "#{@is_teacher ? '评阅' : (student_work.work_status == 0 ? '--' : '查看')}", student_work_path(student_work) %> \ No newline at end of file diff --git a/app/views/student_work/_evaluation_un_shixun_title.html.erb b/app/views/student_work/_evaluation_un_shixun_title.html.erb new file mode 100644 index 000000000..b4cf822c7 --- /dev/null +++ b/app/views/student_work/_evaluation_un_shixun_title.html.erb @@ -0,0 +1,20 @@ + + + 序号 + 姓名 + 学号 + 提交状态 + 更新时间 + 完成情况 + 最终成绩 + 操作 + + + +<% shixun = @homework.homework_commons_shixuns.shixun %> +<% @stundet_works.each_with_index do |student_work, i| %> + <% score_open = @is_teacher || @homework.score_open == 1 || student_work.user == User.current %> + + <%= render :partial => "evaluation_un_shixun_work", :locals => {:student_work => student_work, :index => i, :score_open => score_open, :shixun => shixun} %> +<% end %> + \ No newline at end of file diff --git a/app/views/student_work/_evaluation_un_shixun_work.html.erb b/app/views/student_work/_evaluation_un_shixun_work.html.erb new file mode 100644 index 000000000..9423f400c --- /dev/null +++ b/app/views/student_work/_evaluation_un_shixun_work.html.erb @@ -0,0 +1,38 @@ + + <%= (@page - 1) * @limit + index + 1 %> + + <%= link_to student_work.user.show_real_name, user_path(student_work.user) %> + + "> + <%= student_work.user.user_extensions.nil? ? "--" : student_work.user.user_extensions.student_id %> + + + <%= list_work_status student_work.work_status %> + + + <%= student_work.work_status == 0 ? '--' : format_time(student_work.updated_at) %> + + + <%= student_work.work_status == 0 ? '--' : had_passed_changllenge_count(shixun, student_work.user).to_s+"/"+shixun.challenges.count.to_s %> + <% if student_work.work_status != 0 %> + + <% end %> + + + <% score = student_work.work_score %> + + <%= score.nil? ? "--" : (!score_open ? "**" : format("%.1f",score<0 ? 0 : score))%> + + + <% if student_work.work_status != 0 %> + <%= link_to '查看', student_work_path(student_work), :remote => true %> + <% else %> + -- + <% end %> + + \ No newline at end of file diff --git a/app/views/student_work/_evaluation_un_title.html.erb b/app/views/student_work/_evaluation_un_title.html.erb index 71f604b25..6dfd1c150 100644 --- a/app/views/student_work/_evaluation_un_title.html.erb +++ b/app/views/student_work/_evaluation_un_title.html.erb @@ -1,90 +1,11 @@ - - <%# if @homework.homework_type == 1 %> - <%#= render :partial => 'evaluation_un_common_title' %> - <%# elsif @homework.homework_type == 2 %> - <%#= render :partial => 'evaluation_un_pro_title' %> - <%# elsif @homework.homework_type == 3 %> - <%#= render :partial => 'evaluation_un_group_title' %> - <%# else %> - - - - <% if @homework.homework_type != 3 %> - - - <% else %> - <% if @homework.homework_detail_group.base_on_project == 1 %> - - - <% elsif @homework.homework_detail_group.base_on_project == 0 %> - - <% end %> - <% end %> - - - - <% if @homework.homework_type == 2 %> - - <% end %> - <% if @homework.anonymous_comment == 0 %> - - <% end %> - - - - <%# end %> - <% @stundet_works.each_with_index do |student_work, i| %> - <% score_open = @is_teacher || @homework.score_open == 1 || student_work.user == User.current %> - - <%= render :partial => "evaluation_un_work", :locals => {:student_work => student_work, :index => i, :score_open => score_open} %> - - - +
    序号  - <%= link_to "姓名", @show_all ? student_work_index_path(:homework => @homework.id, :order => "lastname", :sort => @score, :name => @name, :group => @group) : "javascript:void(0)", :class => "c_dark f14 fb", :remote => true %> - <% if @show_all && @order == "lastname" %> - <%= link_to "", student_work_index_path(:homework => @homework.id, :order => "lastname", :sort => @score, :name => @name, :group => @group), :class => "#{@score == 'desc' ? 'sort_up' : 'sort_down'} float-none", :style => "line-height:30px; vertical-align:middle;", :remote => true %> - <% end %> - - <%= link_to "学号", @show_all ? student_work_index_path(:homework => @homework.id, :order => "student_id", :sort => @score, :name => @name, :group => @group) : "javascript:void(0)", :class => "c_dark f14 fb", :remote => true %> - <% if @show_all && @order == "student_id" %> - <%= link_to "", student_work_index_path(:homework => @homework.id, :order => "student_id", :sort => @score, :name => @name, :group => @group), :class => "#{@score == 'desc' ? 'sort_up' : 'sort_down'} float-none", :style => "line-height:30px; vertical-align:middle;", :remote => true %> - <% end %> - 组长 - 关联项目 - 组长 - <%= link_to "状态", @show_all ? student_work_index_path(:homework => @homework.id, :order => "work_status", :sort => @score, :name => @name, :group => @group) : "javascript:void(0)", :class => "c_dark f14 fb", :remote => true %> - <% if @show_all && @order == "work_status" %> - <%= link_to "", student_work_index_path(:homework => @homework.id, :order => "work_status", :sort => @score, :name => @name, :group => @group), :class => "#{@score == 'desc' ? 'sort_up' : 'sort_down'} float-none", :style => "line-height:30px; vertical-align:middle;", :remote => true %> - <% end %> - - <%= link_to "教师", @show_all ? student_work_index_path(:homework => @homework.id, :order => "teacher_score", :sort => @score, :name => @name, :group => @group) : "javascript:void(0)", :class => "c_dark f14 fb", :remote => true %> - <% if @show_all && @order == "teacher_score" %> - <%= link_to "", student_work_index_path(:homework => @homework.id, :order => "teacher_score", :sort => @score, :name => @name, :group => @group), :class => "#{@score == 'desc' ? 'sort_up' : 'sort_down'} float-none", :style => "line-height:30px; vertical-align:middle;", :remote => true %> - <% end %> - - <%= link_to "助教", @show_all ? student_work_index_path(:homework => @homework.id, :order => "teaching_asistant_score", :sort => @score, :name => @name, :group => @group) : "javascript:void(0)", :class => "c_dark f14 fb", :remote => true %> - <% if @show_all && @order == "teaching_asistant_score" %> - <%= link_to "", student_work_index_path(:homework => @homework.id, :order => "teaching_asistant_score", :sort => @score, :name => @name, :group => @group), :class => "#{@score == 'desc' ? 'sort_up' : 'sort_down'} float-none", :style => "line-height:30px; vertical-align:middle;", :remote => true %> - <% end %> - - <%= link_to "系统", @show_all ? student_work_index_path(:homework => @homework.id, :order => "system_score", :sort => @score, :name => @name, :group => @group) : "javascript:void(0)", :class => "c_dark f14 fb", :remote => true %> - <% if @show_all && @order == "system_score" %> - <%= link_to "", student_work_index_path(:homework => @homework.id, :order => "system_score", :sort => @score, :name => @name, :group => @group), :class => "#{@score == 'desc' ? 'sort_up' : 'sort_down'} float-none", :style => "line-height:30px; vertical-align:middle;", :remote => true %> - <% end %> - - <%= link_to "匿评", @show_all ? student_work_index_path(:homework => @homework.id, :order => "student_score", :sort => @score, :name => @name, :group => @group) : "javascript:void(0)", :class => "c_dark f14 fb", :remote => true %> - <% if @show_all && @order == "student_score" %> - <%= link_to "", student_work_index_path(:homework => @homework.id, :order => "student_score", :sort => @score, :name => @name, :group => @group), :class => "#{@score == 'desc' ? 'sort_up' : 'sort_down'} float-none", :style => "line-height:30px; vertical-align:middle;", :remote => true %> - <% end %> - - <%= link_to "成绩", @show_all ? student_work_index_path(:homework => @homework.id, :order => "score", :sort => @score, :name => @name, :group => @group) : "javascript:void(0)", :class => "c_dark f14 fb", :remote => true %> - <% if @show_all && @order == "score" %> - <%= link_to "", student_work_index_path(:homework => @homework.id, :order => "score", :sort => @score, :name => @name, :group => @group), :class => "#{@score == 'desc' ? 'sort_up' : 'sort_down'} float-none", :style => "line-height:30px; vertical-align:middle;", :remote => true %> - <% end %> - -
    -
    -
    -
    + <% if @homework.homework_type == 1 %> + <%= render :partial => 'evaluation_un_common_title' %> + <% elsif @homework.homework_type == 2 %> + <%= render :partial => 'evaluation_un_pro_title' %> + <% elsif @homework.homework_type == 3 %> + <%= render :partial => 'evaluation_un_group_title' %> + <% else %> + <%= render :partial => 'evaluation_un_shixun_title' %> <% end %>
    \ No newline at end of file diff --git a/app/views/student_work/_evaluation_un_work.html.erb b/app/views/student_work/_evaluation_un_work.html.erb index 56a5d2d99..f5b3f85df 100644 --- a/app/views/student_work/_evaluation_un_work.html.erb +++ b/app/views/student_work/_evaluation_un_work.html.erb @@ -12,8 +12,8 @@ <%= link_to(image_tag(url_to_avatar(student_work.user),:width =>"40",:height => "40",:style => "display:block;"),user_path(student_work.user), :target => '_blank') %> <% if @homework.homework_type != 3 %> - - <%= link_to student_work.user.show_name ,user_path(student_work.user), :target => '_blank' %> + + <%= link_to student_work.user.show_real_name ,user_path(student_work.user), :target => '_blank' %> " onclick="show_student_work('<%= student_work_path(student_work)%>');" style="cursor:pointer;"> <%= student_work.user.user_extensions.nil? ? "--" : student_work.user.user_extensions.student_id%> @@ -22,7 +22,7 @@ <% if @homework.homework_detail_group.base_on_project == 1 %>
    - <%= link_to student_work.user.show_name,"javascript:void(0)" ,:title => student_work.user.show_name, :class => "StudentName break_word"%> + <%= link_to student_work.user.show_real_name,"javascript:void(0)" ,:title => student_work.user.show_real_name, :class => "StudentName break_word"%>
    <% if student_work.project_id == 0 || student_work.project_id.nil?%> @@ -41,7 +41,7 @@ <% elsif @homework.homework_detail_group.base_on_project == 0 %>
    - <%= link_to student_work.user.show_name,"javascript:void(0)" ,:title => student_work.user.show_name, :class => "StudentName break_word #{@homework.homework_type == 2 ? '' : 'width165'}"%> + <%= link_to student_work.user.show_real_name,"javascript:void(0)" ,:title => student_work.user.show_real_name, :class => "StudentName break_word #{@homework.homework_type == 2 ? '' : 'width165'}"%>
    <% end %> diff --git a/app/views/student_work/_evaluation_un_work_archive.html.erb b/app/views/student_work/_evaluation_un_work_archive.html.erb index af4655356..1432c57b8 100644 --- a/app/views/student_work/_evaluation_un_work_archive.html.erb +++ b/app/views/student_work/_evaluation_un_work_archive.html.erb @@ -6,14 +6,14 @@
  • - <% student_work_name = student_work.name.nil? || student_work.name.empty? ? student_work.user.show_name + '的作品' : student_work.name%> + <% student_work_name = student_work.name.nil? || student_work.name.empty? ? student_work.user.show_real_name + '的作品' : student_work.name%>
    <%= link_to student_work_name,"javascript:void(0)" ,:title => student_work_name, :class => "linkGrey f14 StudentName break_word #{@homework.homework_type == 2 ? '' : 'width165'}"%>
  • <% if @homework.homework_type != 3 %> -
  • - <%= student_work.user.show_name%> +
  • + <%= student_work.user.show_real_name%>
  • " onclick="show_student_work('<%= student_work_path(student_work)%>');" style="cursor:pointer;"> <%= student_work.user.user_extensions.nil? ? "--" : student_work.user.user_extensions.student_id%> diff --git a/app/views/student_work/_evaluation_work.html.erb b/app/views/student_work/_evaluation_work.html.erb index ecd3f091c..39bc70a81 100644 --- a/app/views/student_work/_evaluation_work.html.erb +++ b/app/views/student_work/_evaluation_work.html.erb @@ -1,5 +1,5 @@ - + <% if @homework.homework_type != 3 %> <% is_my_work = student_work.user == User.current%> <% else %> @@ -8,96 +8,25 @@ <% end %> <% if is_my_work%> - <%=index + 1 %> - - <%= image_tag(url_to_avatar(student_work.user),width:"40", height: "40", style: "display:block;") %> + <%= index + 1 %> + <%= student_work.user.show_real_name%> + <%= format_time student_work.updated_at %> + + <%= student_work.student_score.nil? ? '--' : format("%.1f",student_work.student_score)+"(#{student_work.student_works_scores.where(:reviewer_role => 3).group_by(&:user_id).count})" %> + + + <%= link_to '查看', student_work_path(student_work), :class => 'link-color-blue' %> - <% if @homework.homework_type != 3 %> - - <%= student_work.user.show_name%> - - " onclick="show_student_work('<%= student_work_path(student_work)%>');" style="cursor: pointer;"> - - - <% elsif @homework.homework_type == 3 && @homework.homework_detail_group.base_on_project == 1 %> - -
    - <%= link_to student_work.user.show_name,"javascript:void(0)" ,:title => student_work.user.show_name, :class => "linkGrey f14 StudentName break_word"%> -
    - - <% if student_work.project_id == 0 || student_work.project_id.nil?%> - - -- - - <% elsif student_work.project.is_public || User.current.member_of?(student_work.project) || User.current.admin? %> - - <%= link_to( student_work.project.name, project_path(student_work.project.id))%> - - <% else %> - - <%= student_work.project.name %> - - <% end %> - <% elsif @homework.homework_type == 3 && @homework.homework_detail_group.base_on_project == 0 %> - -
    - <%= link_to student_work.user.show_name,"javascript:void(0)" ,:title => student_work.user.show_name, :class => "linkGrey f14 StudentName break_word"%> -
    - - <% end %> <% else%> - <%=index + 1 %> - - <%= image_tag(url_to_avatar(""),width:"40", height: "40", style: "display:block;") %> + <%= index + 1 %> + 匿名 + <%= format_time student_work.updated_at %> + <% my_score = student_work_score(student_work,User.current,3) %> + + <%= my_score.nil? ? "--" : format("%.1f",my_score.score)%> - <% if @homework.homework_type != 3 %> - - 匿名 - - - -- - - <% elsif @homework.homework_type == 3 && @homework.homework_detail_group.base_on_project == 1 %> - -
    匿名
    - - - 匿名 - - <% elsif @homework.homework_type == 3 && @homework.homework_detail_group.base_on_project == 0 %> - - 匿名 - - <% end %> - <% end%> - - <% if student_work.work_status%> - <%= get_status student_work.work_status, student_work.re_commit %> - <% end %> - - - - <% if @homework.homework_type == 2%> - - - <%= student_work.system_score.nil? ? "--" : (!score_open ? "**" : format("%.1f",student_work.system_score))%> + + <%= link_to @homework.homework_detail_manual.comment_status == 3 ? '评阅' : '查看', student_work_path(student_work), :class => 'link-color-blue' %> <% end%> - - <% my_score = student_work_score(student_work,User.current,3) %> - - <%= my_score.nil? ? "--" : format("%.1f",my_score.score)%> - - -
    评分
    - -
    - - diff --git a/app/views/student_work/_evaluation_work_archive.html.erb b/app/views/student_work/_evaluation_work_archive.html.erb index ee415f52c..6332194b6 100644 --- a/app/views/student_work/_evaluation_work_archive.html.erb +++ b/app/views/student_work/_evaluation_work_archive.html.erb @@ -13,14 +13,14 @@
  • - <% student_work_name = student_work.name.nil? || student_work.name.empty? ? student_work.user.show_name + '的作品' : student_work.name%> + <% student_work_name = student_work.name.nil? || student_work.name.empty? ? student_work.user.show_real_name + '的作品' : student_work.name%> <%= link_to student_work_name, student_work_path(student_work),:remote => true,:title => student_work_name, :class => "linkGrey f14 StudentName break_word w250"%>
  • <% if @homework.homework_type != 3 %> -
  • - <%= student_work.user.show_name%> +
  • + <%= student_work.user.show_real_name%>
  • " onclick="show_student_work('<%= student_work_path(student_work)%>');" style="cursor: pointer;"> <%= student_work.user.user_extensions.nil? ? "--" : student_work.user.user_extensions.student_id%> diff --git a/app/views/student_work/_group_member_search_list.html.erb b/app/views/student_work/_group_member_search_list.html.erb new file mode 100644 index 000000000..4a0affb61 --- /dev/null +++ b/app/views/student_work/_group_member_search_list.html.erb @@ -0,0 +1,21 @@ +<% unless @users.blank? %> + + + <% @users.each do |user| %> + + + + + + <% end %> + +
    <%= user.show_real_name %><%= user.user_extensions.try(:student_id) %><%= @course.members.where(:user_id => user.id).first.course_group.try(:name) %>
    +双击添加成员 +
    +
      + <%= pagination_links_full @user_pages, @user_count, :per_page_links => false, :remote => true, :flag => true, :is_new => true%> +
    +
    +
    +<% end %> +
    \ No newline at end of file diff --git a/app/views/student_work/_homework_post_brief.html.erb b/app/views/student_work/_homework_post_brief.html.erb index 27c5c8444..40e889831 100644 --- a/app/views/student_work/_homework_post_brief.html.erb +++ b/app/views/student_work/_homework_post_brief.html.erb @@ -3,7 +3,7 @@
  • - <%= link_to homework.user.show_name, user_activities_path(homework.user_id), :class => "newsBlue mr15"%> + <%= link_to homework.user.show_real_name, user_activities_path(homework.user_id), :class => "newsBlue mr15"%>
    <% index = get_hw_index(homework, is_teacher) %> diff --git a/app/views/student_work/_homework_reply.html.erb b/app/views/student_work/_homework_reply.html.erb new file mode 100644 index 000000000..184ccf447 --- /dev/null +++ b/app/views/student_work/_homework_reply.html.erb @@ -0,0 +1,8 @@ +
    + <% unless comment.parent.nil? %> +
    + <%= render :partial => 'student_work/homework_reply', :locals => {:comment => comment.parent, :parent_id => parent_id, :type => type, :user_activity_id => user_activity_id} %> +
    + <% end %> + <%= render :partial => 'student_work/homework_reply_detail', :locals => {:comment => comment, :parent_id => parent_id, :type => type, :user_activity_id => user_activity_id} %> +
    \ No newline at end of file diff --git a/app/views/student_work/_homework_reply_detail.html.erb b/app/views/student_work/_homework_reply_detail.html.erb new file mode 100644 index 000000000..5a6b8ece6 --- /dev/null +++ b/app/views/student_work/_homework_reply_detail.html.erb @@ -0,0 +1,42 @@ +
    + <%= link_to image_tag(url_to_avatar(comment.creator_user), :width => "32", :height => "32"), user_path(comment.creator_user), :target => "_blank", :alt => "用户头像" %> +
    + +
    +
    + <%= link_to comment.creator_user.show_real_name, user_path(comment.creator_user), :class => "content-username hide fl" %> + <%= time_from_now(comment.respond_to?(:created_on) ? comment.created_on : comment.created_at) %> +
    + <%= comment.content_detail.html_safe %> +
    +
    + +
    +
    +
    +
    + + <%=render :partial=> "praise_tread/edu_praise", :locals => {:activity=>comment, :user_activity_id=>comment.id,:type=>"reply"}%> + + <%= link_to('回复'.html_safe, + {:controller => 'users', + :action => 'reply_to_comment', + :reply_id => comment.id, + :type => type, + :user_activity_id => user_activity_id, + :parent_id => parent_id}, + :remote => true, + :method => 'get', + :title => l(:button_reply)) %> +
    +
    +
    +
    +
    +
    +
    \ No newline at end of file diff --git a/app/views/student_work/_jour_replay.html.erb b/app/views/student_work/_jour_replay.html.erb index 1887614fb..ec1a886c6 100644 --- a/app/views/student_work/_jour_replay.html.erb +++ b/app/views/student_work/_jour_replay.html.erb @@ -2,7 +2,7 @@ <%= link_to image_tag(url_to_avatar(show_real_name ? jour.user : ""), :width => "32", :height => "32"), show_real_name ? user_path(jour.user) : "javascript:void(0)",:class => "st_img fl" %>
    - <%= link_to show_real_name ? jour.user.show_name : "匿名", show_real_name ? user_path(jour.user) : "javascript:void(0)", :title => jour.user.show_name, :class => "c_blue fl" %> + <%= link_to show_real_name ? jour.user.show_real_name : "匿名", show_real_name ? user_path(jour.user) : "javascript:void(0)", :title => jour.user.show_real_name, :class => "c_blue fl" %> <% if jour.user==User.current || User.current.admin? %> <%= link_to(l(:label_bid_respond_delete), destroy_score_reply_student_work_index_path(:jour_id => jour.id), diff --git a/app/views/student_work/_new_pro_student_work.html.erb b/app/views/student_work/_new_pro_student_work.html.erb new file mode 100644 index 000000000..9c0d8c3ca --- /dev/null +++ b/app/views/student_work/_new_pro_student_work.html.erb @@ -0,0 +1,141 @@ +<% content_for :header_tags do %> + <%= javascript_include_tag "/assets/codemirror/codemirror_python_ruby_c", 'edu/homework' %> + <%= stylesheet_link_tag "/assets/codemirror/codemirror" %> +<% end %> + + + + +
    +
    +
    +
      +
    • +

      + + 请使用 <%= @homework.language_name %> 语言编写 + <% if @homework.language.to_i == 1 %> + 编译器信息:gcc version "4.4.7" 20120313 (Red Hat 4.4.7-11) (GCC) + <% elsif @homework.language.to_i == 2 %> + 编译器信息:gcc version "4.4.7" 20120313 (Red Hat 4.4.7-11) (GCC) + <% elsif @homework.language.to_i == 3 %> + 编译器信息:Python version "2.6.6" + <% elsif @homework.language.to_i == 4 %> + 编译器信息:java version "1.7.0_85" OpenJDK Runtime Environment + <% end %> + style="display-hidden" id="data-language"> +

      + + <%= f.text_area :description, id: 'program-src', class: "task-form-100 panel-form-height-150 fl panel-box-sizing task-textarea-pd", placeholder: "请贴入你的代码", rows: 10 %> + +
    • +
    • + 测试代码 + +
    • +
    +
    +
    +
    + +
    +
    +

    评测历史

    +
    +
    + <% student_work.student_work_tests.each_with_index do |test, index| %> +
    + 第<%= student_work.student_work_tests.count - index %>次 +
    + <% if test.status.to_i == -2 %> +
    <%= test.results.first %>
    + <% else %> + <% test.results.reverse.each_with_index do |x, i| %> +
    + + 测试集 <%= test.results.size - i %> + <% if x["status"].to_i == 0 %> + + <% else %> + + <% end %> +
    +
    + + + + + + + + + + + + + +
    期望输出实际输出
    +
    <%= x["output"].nil? ? "" : x["output"].force_encoding("UTF-8") %>
    +
    <%= x["result"].nil? ? "" : x["result"].force_encoding("UTF-8") %>
    +
    +
    + <% end %> + <% end %> +
    +
    + <% end %> +
    +
    + <% if !@is_test && @homework.end_time < Time.now %> +
    +
    +
  • + + +
  • +
    +
    + <% end %> + +<% unless @is_test %> +
  • + 提交 + <%= link_to '取消', student_work_index_path(:homework => @homework.id), :class => 'task-btn fr mr10' %> +
  • +<% end %> \ No newline at end of file diff --git a/app/views/student_work/_no_teacher_score_notice.html.erb b/app/views/student_work/_no_teacher_score_notice.html.erb index 0926e3c74..9230a0153 100644 --- a/app/views/student_work/_no_teacher_score_notice.html.erb +++ b/app/views/student_work/_no_teacher_score_notice.html.erb @@ -1,16 +1,24 @@ -
    -
    -

    - <%#A if work.teacher_score.nil? || work. %> - 您当次评阅未对作品进行评分,分数将取上次的评分结果,若没有评分记录则不评分,是否确定提交? -

    - +
    +
    +

    提示

    +
    -
    \ No newline at end of file +
    +

    您当次评阅未对作品进行评分,分数将取上次的评分结果,若没有评分记录则不评分
    + 是否确定提交?

    +
    + 取消 + 确定 +
    +
    + + \ No newline at end of file diff --git a/app/views/student_work/_programing_work_show.html.erb b/app/views/student_work/_programing_work_show.html.erb index 89087b351..880d6b842 100644 --- a/app/views/student_work/_programing_work_show.html.erb +++ b/app/views/student_work/_programing_work_show.html.erb @@ -111,8 +111,8 @@
  • <% if @is_teacher || (@homework.homework_detail_manual.comment_status == 2 && work.user != User.current )%> -
      - <%= render :partial => 'add_score',:locals => {:work => work,:score => score,:is_member_work => false}%> +
        + <%= render :partial => 'add_score',:locals => {:work => work, :score => score, :is_member_work => false}%>
      <% end%>
      @@ -124,7 +124,7 @@
  • -
    +
    <%= render :partial => 'student_work_score_records', :locals => {:student_work_scores => student_work_scores, :is_member_work => false} %>
    diff --git a/app/views/student_work/_relate_projects.html.erb b/app/views/student_work/_relate_projects.html.erb index 8a1382386..818f759cc 100644 --- a/app/views/student_work/_relate_projects.html.erb +++ b/app/views/student_work/_relate_projects.html.erb @@ -18,7 +18,7 @@ <% if is_change %> 更换项目 <% end %> - <%=link_to "".html_safe, user_path(projectUser), :title => "#{projectUser.show_name}" %> + <%=link_to "".html_safe, user_path(projectUser), :title => "#{projectUser.show_real_name}" %>
    diff --git a/app/views/student_work/_score_appeal_box.html.erb b/app/views/student_work/_score_appeal_box.html.erb index 52ef67e91..255c693e5 100644 --- a/app/views/student_work/_score_appeal_box.html.erb +++ b/app/views/student_work/_score_appeal_box.html.erb @@ -1,26 +1,27 @@ -
    -
    -

    匿评成绩申诉

    - -
    +
    +
    +

    匿评成绩申诉

    +
    <%= form_for('appeal',:url =>{:controller => 'student_work',:action => 'appeal_anonymous_score',:score_id => @student_work_score.id, :is_last => @is_last}, :method => "post", :remote => true) do |f|%> -
    -
    - *申诉理由: - <%= f.text_area 'comment', :id => 'appeal_comment', :style => 'height: 70px; width: 414px;', :placeholder => "请输入你的申诉理由,最多250个字符。",:maxlength => 250 %> -

    请输入申诉理由

    +
    +
    + *申诉理由: + <%= f.text_area 'comment', :id => 'appeal_comment', :style => 'height: 70px; width: 460px;', :placeholder => "请输入你的申诉理由,最多250个字符。",:maxlength => 250 %> +

    请输入申诉理由

    教师或者助教将收到您的申诉
    申诉被接受后,此匿评成绩将被废弃,且评阅人的作品将被违规扣分
    - 确定 - 取消
    +
    + 确定 + 取消 +
    <% end%>
    @@ -31,7 +32,7 @@ if ($.trim($("#appeal_comment").val()) != "") { first_click = false; $('#notice_notes').hide(); - $('#muban_popup_box').find('form').submit(); + $('#notice_notes').parent().parent().parent().submit(); } else { $('#notice_notes').show(); } diff --git a/app/views/student_work/_shixun_work_show.html.erb b/app/views/student_work/_shixun_work_show.html.erb new file mode 100644 index 000000000..961683f78 --- /dev/null +++ b/app/views/student_work/_shixun_work_show.html.erb @@ -0,0 +1,52 @@ +
    +
    +

    学员实训信息

    + +
    +
    +
    +

    + <%= link_to @shixun.owner.try(:show_real_name), user_path(@shixun.owner), :class => "link-name-dark fl", :target => "_blank" %> + / + <%= link_to @shixun.name, shixun_path(@shixun), :class => "edu-info-dark fl", :target => "_blank" %> +

    + 经验值:<%= @myshixun.total_score %> +
    +
    + <%= link_to image_tag(url_to_avatar(@work.user), :width =>"50", :height => "50", :alt=>"头像", :style => "width:50px; height:50px;"), user_path(@work.user), :class => "fl edu-work-user-img", :target => "_blank" %> +
      +
    • + <%= link_to @work.user.try(:show_real_name), user_path(@work.user), :class => "edu-txt-w140 task-hide fl", :target => "_blank" %> + +
    • +
    • 通关时间: <%= @myshixun.try(:status) == 1 ? (format_time @myshixun.done_time) : '- -' %>
    • +
    +
      +
    • 通关情况:<%= had_passed_changllenge_count(@shixun, @work.user).to_s+" / "+@shixun.challenges.count.to_s %>
    • +
    • 总耗时:<%=had_passed_changllenge_count(@shixun, @work.user) > 0 ? game_spend_time(total_spend_time @myshixun) : '- -' %>
    • +
    +
    +
    + + + + + + + + + + + <% @myshixun.games.each_with_index do |game, index| %> + + + + + + + <% end %> + +
    序号耗时经验值
    第<%= index + 1 %>关<%= game.status == 2 ? game_spend_time((game.end_time - game.open_time).to_i) : '- -' %><%= game.status == 2 ? game.final_score : '- -' %>
    +
    +
    +
    \ No newline at end of file diff --git a/app/views/student_work/_show.html.erb b/app/views/student_work/_show.html.erb index ede4f57f8..c17c8bf94 100644 --- a/app/views/student_work/_show.html.erb +++ b/app/views/student_work/_show.html.erb @@ -37,10 +37,10 @@
  • 参与人员: - <%= link_to(work.user.show_name+"(组长)", user_path(work.user.id), :class => "linkBlue" )%> + <%= link_to(work.user.show_real_name+"(组长)", user_path(work.user.id), :class => "linkBlue" )%> <% members = work.student_work_projects.where("is_leader = 0") %> <% members.each do |member| if !members.empty? %> - 、<%=link_to((User.find member.user_id).show_name, user_path(member.user.id), :class => "linkBlue" ) %> + 、<%=link_to((User.find member.user_id).show_real_name, user_path(member.user.id), :class => "linkBlue" ) %> <% end %> <% end %>
  • @@ -84,7 +84,7 @@ <% if @is_teacher || (@homework.homework_detail_manual.comment_status == 2 && !is_my_work)%>
    - <%= render :partial => 'add_score',:locals => {:work => work,:score => score,:is_member_work => is_member_work}%> + <%= render :partial => 'add_score', :locals => {:work => work, :score => score, :is_member_work => is_member_work}%>
    <% end%>
    diff --git a/app/views/student_work/_student_work.html.erb b/app/views/student_work/_student_work.html.erb index d2b9f00b9..f49c0a88c 100644 --- a/app/views/student_work/_student_work.html.erb +++ b/app/views/student_work/_student_work.html.erb @@ -6,10 +6,10 @@
  • - <%= link_to student_work.user.show_name,user_path(student_work.user),:title => student_work.user.show_name, :class => "c_blue02"%> + <%= link_to student_work.user.show_real_name,user_path(student_work.user),:title => student_work.user.show_real_name, :class => "c_blue02"%>
  • - <% student_work_name = student_work.name.nil? || student_work.name.empty? ? student_work.user.show_name + '的作品' : student_work.name%> + <% student_work_name = student_work.name.nil? || student_work.name.empty? ? student_work.user.show_real_name + '的作品' : student_work.name%> <%= link_to student_work_name, student_work_path(student_work),:remote => true,:title => student_work.name, :class => "c_blue02"%>
  • diff --git a/app/views/student_work/_student_work_list.html.erb b/app/views/student_work/_student_work_list.html.erb index c033b4647..1b0e7ed12 100644 --- a/app/views/student_work/_student_work_list.html.erb +++ b/app/views/student_work/_student_work_list.html.erb @@ -1,129 +1,35 @@ -
    - - 作品 - - <% if @homework.homework_type == 3 %> - <% member_count = @homework.student_works.where("work_status != 0").count %> - (<%= @student_work_count%>组<%=member_count %>人已交) - <% else %> - (<%= @student_work_count%>人已交) +
    + <%= link_to "更新时间排序", student_work_index_path(:homework => @homework.id, :order => "updated_at", :sort => @score, :name => @name, :group => @group, :comment => @comment, :status => @status), :class => "#{@order == 'updated_at' ? 'color-blue' : ''} fl ml15", :remote => true %> + | + <%= link_to "最终成绩排序", student_work_index_path(:homework => @homework.id, :order => "work_score", :sort => @score, :name => @name, :group => @group, :comment => @comment, :status => @status), :class => "#{@order == 'work_score' ? 'color-blue' : ''} fl", :remote => true %> +

    <%= @student_work_count %> 个检索结果(<%= @homework.course.student.count %> 学生)

    + <% if @is_teacher %> +
    + <%= link_to "导出成绩", student_work_index_path(:homework => @homework.id,:order => @order, :sort => @b_sort, :name => @name, :group => @group, :comment => @comment, :status => @status, :format => 'xls'),:class=>'fl mr5', :id => "export_student_work"%> + <% if @homework.homework_type == 1 || @homework.homework_type == 3 %> + <% if @stundet_works.empty?%> + <%= link_to "导出作品附件", "javascript:void(0)", class: "fl mr5", :onclick => "notice_box('该检索条件下没有作品,无法下载附件')" %> + <% else%> + <%= link_to "导出作品附件", zipdown_assort_path(obj_class: @homework.class, obj_id: @homework, format: :json), + remote: true, class: "fl mr5 download_homework_attachments" %> + <% end%> <% end %> - - <%# my_work = @homework.student_works.where("user_id = #{User.current.id}").first %> - <% my_work = cur_user_works_for_homework @homework %> - <% if !@is_teacher && my_work.nil? && User.current.member_of_course?(@course) %> - 您尚未提交作品 - <% unless @homework.homework_type == 3 && @homework.homework_detail_group.base_on_project == 1 %> - <%=link_to "提交作品", new_student_work_url_without_domain(@homework.id),:class => 'blueCir ml5 f12' %> - <% end %> - <% elsif !@is_teacher && my_work &&@homework.end_time < Time.now && !@stundet_works.empty?%> - 截止日期已过,已提交且不可修改 - <% elsif !@is_teacher && my_work &&@homework.end_time >= Time.now && !@stundet_works.empty?%> - <% if @homework.homework_type == 3 %> - 组长已提交,组长还可修改 - <% else %> - 您已提交,您还可以修改 - <% end %> - <% end %> - - <%if @is_teacher || @homework.homework_detail_manual.comment_status == 3 || @homework.is_open == 1%> -
    - -
    - <%= select_tag(:student_work_in_group,options_for_select(course_group_list(@course),@group), {:class => "classSplit fl mr10"}) unless course_group_list(@course).empty? %> - <%if @homework.homework_type == 2 && @is_teacher %> - <%= link_to "代码查重", work_canrepeat_student_work_index_path(homework:@homework.id, course_id:@course.id), class: 'BlueCirBtn fl',:remote => true %> - <% end %> + <% end %> +
    +
    + <% if @is_evaluation && !@stundet_works.empty? %> + <%= render :partial => "evaluation_title"%> + <% else%> + <%= render :partial => "evaluation_un_title"%> <% end%> - <% if !@is_teacher && @homework.homework_type == 3 && my_work && my_work.user == User.current && @homework.end_time < Time.now %> - - <% end %> - <% if @is_teacher && @homework.homework_type == 3 %> -
    - - -

    组长评分即小组作品评分
    - 组长评分时选择“组员同评”,本次评
    分结果将同时影响每个组员的评分。
    您可以继续对单个组员评分再调整或
    不调整 -

    -
    - <% end %>
    -
    -<% if @is_evaluation && !@stundet_works.empty? %> -
    - 不参与匿评将直接影响作业成绩,请按照事实进行评分
    -

    为了保障匿评的公平,允许学生对不合理的匿评成绩进行申诉

    -

    若您给出了不合理的匿评成绩,并被申诉成功,您自己的作品将被匿评违规扣分

    -
    -<% end %> - -
    - <% if @homework.homework_type != 3%> - <% if @is_evaluation && !@stundet_works.empty? %> - <%= render :partial => "evaluation_title"%> - <% else%> - <%= render :partial => "evaluation_un_title"%> - <% end%> - <% else %> - <% if @is_evaluation && !@stundet_works.empty? %> - <%= render :partial => "evaluation_title"%> - <% else %> - <%= render :partial => "evaluation_un_group"%> - <% end%> - <% end %> -
    -
    - - \ No newline at end of file +
    +
    +
      + <%= pagination_links_full @student_work_pages, @student_work_count, :per_page_links => false, :remote => @is_remote, :flag => true, :is_new => true %> +
    +
    +
    +
    \ No newline at end of file diff --git a/app/views/student_work/_student_work_replies.html.erb b/app/views/student_work/_student_work_replies.html.erb new file mode 100644 index 000000000..404150d0c --- /dev/null +++ b/app/views/student_work/_student_work_replies.html.erb @@ -0,0 +1,117 @@ +<% count=@homework.journals_for_messages.count %> +<% comments = @homework.journals_for_messages.reorder("created_on desc") %> +<% no_children_comments = get_no_children_comments_all comments %> +<% is_teacher = User.current.allowed_to?(:as_teacher, @homework.course) || User.current.admin? %> + +
    +

    全部回复<%= count %>

    +

    + + <%= render :partial => 'praise_tread/edu_praise', :locals => {:activity=>@homework, :user_activity_id=>@homework.id,:type=>"activity"} %> + + 回复<%= count %> +

    +
    +
    +<% no_children_comments.each do |comment| %> + <% unless comment.nil? %> + +
    +
    + <%= link_to image_tag(url_to_avatar(comment.creator_user), :width => 50, :height => 50, :alt => "用户头像"), user_url_in_org(comment.creator_user), :target => '_blank' %> +
    +
    +
    +
    + <%= link_to comment.creator_user.show_real_name, user_url_in_org(comment.creator_user), :class => "content-username hide fl" %> + <%= time_from_now(comment.respond_to?(:created_on) ? comment.created_on : comment.created_at) %> +
    +
    +
    +
    + <% if !comment.parent.nil? %> + <% parents_rely = [] %> + <% parents_rely = get_reply_parents parents_rely, comment %> + <% length = parents_rely.length %> +
    + <% if length <= 5 %> + <%=render :partial => 'student_work/homework_reply', :locals => {:comment => comment.parent, :parent_id => comment.id, :user_activity_id => @homework.id, :type => 'HomeworkCommon'} %> + <% else %> +
    +
    +
    +
    +
    + <%=render :partial => 'student_work/homework_reply_detail', :locals => {:comment => parents_rely[length - 1], :type => 'HomeworkCommon', :user_activity_id => @homework.id, :parent_id => comment.id} %> +
    +
    + + <%= link_to '点击展开隐藏楼层', show_all_replies_users_path(:comment => comment, :type => comment.class, :user_activity_id => @homework.id, :parent_id => comment.id),:remote=>true, :class => '' %> +
    + <%=render :partial => 'student_work/homework_reply_detail', :locals => {:comment => parents_rely[3], :type => 'HomeworkCommon', :user_activity_id => @homework.id, :parent_id => comment.id} %> +
    + <%=render :partial => 'student_work/homework_reply_detail', :locals => {:comment => parents_rely[2], :type => 'HomeworkCommon', :user_activity_id => @homework.id, :parent_id => comment.id} %> +
    + <%=render :partial => 'student_work/homework_reply_detail', :locals => {:comment => parents_rely[1], :type => 'HomeworkCommon', :user_activity_id => @homework.id, :parent_id => comment.id} %> +
    + <%=render :partial => 'student_work/homework_reply_detail', :locals => {:comment => parents_rely[0], :type => 'HomeworkCommon', :user_activity_id => @homework.id, :parent_id => comment.id} %> +
    + <% end %> +
    + <% end %> +
    +
    <%= comment.content_detail.html_safe %>
    +
    +

    + <% if is_teacher || comment.user == User.current%> + 删除 + <% end %> + + <%=render :partial=> "praise_tread/edu_praise", :locals => {:activity=>comment, :user_activity_id=>comment.id,:type=>"reply"}%> + + <%= link_to( + '回复'.html_safe, + {:controller => 'users' ,:action => 'reply_to', :reply_id => comment.id, :type => 'HomeworkCommon', :user_activity_id => @homework.id}, + :remote => true, + :method => 'get', + :title => l(:button_reply)) %> +

    +
    +
    +
    +
    + +
    +
    +
    +
    +
    + <% end %> +<% end %> + + +
    +
    +
    + <%= link_to image_tag(url_to_avatar(User.current), :width => "50", :height => "50"), :target => "_blank", :alt => "用户头像" %> +
    + +
    +
    +
    + +
    \ No newline at end of file diff --git a/app/views/student_work/_student_work_score.html.erb b/app/views/student_work/_student_work_score.html.erb index 1b36503e7..e5875c1be 100644 --- a/app/views/student_work/_student_work_score.html.erb +++ b/app/views/student_work/_student_work_score.html.erb @@ -1,82 +1,78 @@ -
      - <% show_real_name = @is_teacher || score.user == User.current || score.reviewer_role != 3 %> - <%= link_to image_tag(url_to_avatar(show_real_name ? score.user : ""), :width => "34", :height => "34"), show_real_name ? user_path(score.user) : "javascript:void(0)",:class => "ping_pic fl" %> - <% show_real_score = @homework.score_open == 1 || @is_teacher || score.student_work.user == User.current || score.user == User.current %> -
      - <%= link_to show_real_name ? score.user.show_name : "匿名", show_real_name ? user_path(score.user) : "javascript:void(0)", :title => show_real_name ? score.user.show_name : "匿评用户", :class => "linkBlue fl" %> - - (<%= student_work_score_role score%>) - - <% unless score.score.nil? %> - 评分: - - <%= show_real_score ? score.score : "**" %>分 - - <% end %> - <% if @is_teacher && score.user == User.current && score.reviewer_role != 3 %> - <% scores = User.current.student_works_scores.where("student_work_id = #{score.student_work_id} and reviewer_role != 3").order("created_at desc") %> - <% if scores.first != score %> - 隐藏 +<% show_real_name = @is_teacher || score.user == User.current || score.reviewer_role != 3 %> +<% show_real_score = @homework.score_open == 1 || @is_teacher || score.student_work.user == User.current || score.user == User.current %> +
      +
      + <%= link_to image_tag(url_to_avatar(show_real_name ? score.user : ""), :width => "50", :height => "50"), show_real_name ? user_path(score.user) : "javascript:void(0)", :target => "_blank" %> +
      +
      +
      +
      + <%= link_to show_real_name ? score.user.show_real_name : "匿名", show_real_name ? user_path(score.user) : "javascript:void(0)", :title => show_real_name ? score.user.show_real_name : "匿评用户", :class => "content-username hide fl" %> + (<%= student_work_score_role score%>) + <%= format_time score.updated_at %> + <% unless score.score.nil? %> + <%= show_real_score ? score.score : "**" %>分 <% end %> - <% end %> - 回复 - <% if @homework.anonymous_appeal == 1 %> - <% if score.student_work.user == User.current && score.reviewer_role == 3 && score.appeal_status == 0 %> - 申诉 - <% elsif score.reviewer_role == 3 && score.appeal_status == 1 %> - 申诉中 - <% elsif score.reviewer_role == 3 && score.appeal_status == 2 %> - 申诉已撤销 - <% elsif score.reviewer_role == 3 && score.appeal_status == 3 %> - 申诉成功 - <% elsif score.reviewer_role == 3 && score.appeal_status == 4 %> - 申诉失败 + <% if @is_teacher && score.user == User.current && score.reviewer_role != 3 %> + <% scores = User.current.student_works_scores.where("student_work_id = #{score.student_work_id} and reviewer_role != 3").order("created_at desc") %> + <% if scores.first != score %> + 删除 + <% end %> <% end %> - <% end %> - - <%=format_time score.updated_at %> - -
      - -

      - <%= score.comment%> -

      -
      - - <%= render :partial => 'work_attachments', :locals => {:attachments => score.attachments} %> -
      - -
      - <%= render :partial => 'add_score_reply',:locals => {:score => score,:is_last => is_last}%> + <% if @homework.anonymous_appeal == 1 %> + <% if @homework.homework_detail_manual.comment_status == 4 && score.student_work.user == User.current && score.reviewer_role == 3 && score.appeal_status == 0 %> + 申诉 + <% elsif score.reviewer_role == 3 && score.appeal_status == 1 %> + 申诉中 + <% elsif score.reviewer_role == 3 && score.appeal_status == 2 %> + 申诉已撤销 + <% elsif score.reviewer_role == 3 && score.appeal_status == 3 %> + 申诉成功 + <% elsif score.reviewer_role == 3 && score.appeal_status == 4 %> + 申诉失败 + <% end %> + <% end %> +
      -
      - <% unless score.student_works_scores_appeal.nil? %> -
      - 申诉 - <% if score.appeal_status == 1 && score.student_work.user == User.current %> - 撤销申诉 - <% elsif @is_teacher && score.appeal_status == 1 %> - 接受 - 拒绝 - <% end %> - - <%=format_time score.student_works_scores_appeal.updated_at %> - -
      -

      - 申诉理由:<%= score.student_works_scores_appeal.comment%> -

      -
      - <% end %> - -
      - <% score.journals_for_messages.order("created_on desc").each do |jour|%> - <% show_real_name = @is_teacher || score.reviewer_role != 3 || @homework.homework_detail_manual.comment_status != 2 %> - <%= render :partial => 'jour_replay',:locals => {:jour => jour, :show_real_name => show_real_name || jour.user == User.current}%> - <% end%> +
      +
      + <%= score.comment %> +
      + <% unless score.student_works_scores_appeal.nil? %> + <% show_real_name_for_appeal = @is_teacher || score.student_works_scores_appeal.try(:user_id) == User.current.id %> +
      +
      +
      +
      + <%= link_to image_tag(url_to_avatar(show_real_name_for_appeal ? score.student_works_scores_appeal.user : ""), :width => "32", :height => "32"), show_real_name_for_appeal ? user_path(score.student_works_scores_appeal.user) : "javascript:void(0)", :target => "_blank" %> +
      +
      + <%= link_to show_real_name_for_appeal ? score.student_works_scores_appeal.user.show_real_name : "匿名", show_real_name_for_appeal ? user_path(score.student_works_scores_appeal.user.show_real_name) : "javascript:void(0)", :title => show_real_name ? score.student_works_scores_appeal.user.show_real_name : "匿评用户", :class => "content-username" %> + <%=format_time score.student_works_scores_appeal.updated_at %> +
      <%= score.student_works_scores_appeal.comment%>
      +
      +
      +

      + <% if score.appeal_status == 1 && score.student_work.user == User.current %> + 撤销申诉 + <% elsif @is_teacher && score.appeal_status == 1 %> + 接受申诉 + 拒绝申诉 + <% end %> +

      +
      +
      +
      +
      + <% end %> + + +
      -
    + +
    + diff --git a/app/views/student_work/_student_work_score_div.html.erb b/app/views/student_work/_student_work_score_div.html.erb new file mode 100644 index 000000000..82b0cf2c0 --- /dev/null +++ b/app/views/student_work/_student_work_score_div.html.erb @@ -0,0 +1,101 @@ +
    + <% if @is_teacher || (@homework.homework_detail_manual.comment_status == 3 && @work.user != User.current ) %> + <%= form_for('new_form', :remote => true, :method => :post, :url => add_score_student_work_path(@work.id),:id=>'add_score_'+@work.id.to_s) do |f| %> +
    +
    全部评阅<%= @student_work_scores.count %>
    + + + +
    +
    + +
      +
    • + + <%= f.text_area 'user_message', :class => 'edu-reply-teat panel-box-sizing fl', :id => 'score_comment_'+@work.id.to_s, :placeholder => "录入你对本作品的评语,最多1000个字符", :maxlength => 1000 %> +
      + +
    • + <% if @is_teacher && @work.homework_common.homework_type == 3 %> +
    • + + + +
    • + <% end %> +
    • + + + + + + + +
    • + + + + + + + + + + +
    • + 确定 +
    • +
    +
    + <% end %> + <% end %> +
    + <%= render :partial => 'student_work_score_records', :locals => {:student_work_scores => @student_work_scores} %> +
    +
    + + \ No newline at end of file diff --git a/app/views/student_work/_student_work_score_records.html.erb b/app/views/student_work/_student_work_score_records.html.erb index b0215d127..997ae6025 100644 --- a/app/views/student_work/_student_work_score_records.html.erb +++ b/app/views/student_work/_student_work_score_records.html.erb @@ -1,8 +1,9 @@ -<%student_work_scores.each do |student_score|%> -
    - <%= render :partial => 'student_work_score',:locals => {:score => student_score,:is_last => student_score == student_work_scores.last}%> -
    +<% student_work_scores.each do |student_score| %> +
    + <%= render :partial => 'student_work_score', :locals => {:score => student_score, :is_last => student_score == student_work_scores.last} %> +
    <% end%> -<% if is_member_work && student_work_scores.empty? && !@is_teacher %> -

    暂无评分

    -<% end %> \ No newline at end of file + +<%# if is_member_work && student_work_scores.empty? && !@is_teacher %> + +<%# end %> \ No newline at end of file diff --git a/app/views/student_work/_upload_attachment.html.erb b/app/views/student_work/_upload_attachment.html.erb index 6f90a0705..5cedbbcd7 100644 --- a/app/views/student_work/_upload_attachment.html.erb +++ b/app/views/student_work/_upload_attachment.html.erb @@ -1,21 +1,23 @@ -
    -
    -

    - 上传附件 -

    - -
    +<% content_for :header_tags do %> + <%= javascript_include_tag 'attachments' %> +<% end %> + +
    +
    +

    补交附件

    +
    -
    - <%= form_tag(revise_attachment_student_work_path(work.id), :multipart => true,:remote => !ie8?,:name=>"upload_form",:id=>'upload_form') do %> + +
    + <%= form_tag(revise_attachment_student_work_path(work.id), :multipart => true,:name=>"upload_form",:id=>'upload_form') do %>
    - +
    -
    +
    - - 选择文件 + + 选择文件 <%= file_field_tag 'attachments[dummy][file]', :id => '_file', :class => ie8? ? '':'file_selector', @@ -35,27 +37,25 @@ :delete_all_files => l(:text_are_you_sure_all) } %>
    - -
    最多只能上传一个小于50MB的附件
    - +
    -

    -
    注意:暂不支持IE浏览器的上传,请更换浏览器
    -
    - 取消 - 确定 +
    +
    +

    + 确定 + 取消 +
    <% end %>
    -
    + +
    +

    + + <%= link_to @course.name, course_path(@course) %> > <%= link_to '作业列表', homework_common_index_path(:course => @course, :homework_type => @homework.homework_type) %> > #<%= link_to (get_hw_index(@homework, @is_teacher, @homework.homework_type) + 1), student_work_index_path(:homework => @homework.id) %>

    +
    +

    <%= @homework.name %>

    + <%= link_to '返回', homework_common_index_path(:course => @homework.course_id, :homework_type => @homework.homework_type), :class => 'fr font-12 mr15 mt3 link-color-grey' %> +
    + <%= form_for(@work, + :html => { :multipart => true, :id => "student_work_form"}, + :url => {:controller => 'student_work', + :action => 'update', + :id => @work.id + }) do |f| %> + <% if @homework.homework_type != 2 %> +
    +
    +
    +
      +
    • + + + <%= f.kindeditor :description, :editor_id => 'student_work_description_editor', + :owner_id => @work.nil? ? 0: @work.id, + :owner_type => OwnerTypeHelper::STUDENTWORK, + :width => '90%', + :height => 200, + :minHeight=>200, + :class => 'talk_text fl', + :input_html => { :id => 'student_work_content', + :class => 'talk_text fl', + :maxlength => 5000 } + %> +
    • + + + + +
    • + + 内容不能为空 +
    • +
    • + <%= render :partial => 'users/user_homework_attachment', :locals => {:container => @work} %> +
    • +
    +
    +
    +
    + + <% if @homework.homework_type == 3 %> +
    - <% str = User.current.id.to_s%> - <% @work.student_work_projects.where("is_leader = ?", 0).each do |pro| %> - <% str += ','+pro.user_id.to_s %> - <% end %> - <%=hidden_field_tag 'group_member_ids', params[:group_member_ids], :value=>str %> - <% end %> -
    - -
    -

    -
    -
    - - - -
    -

    -

    -

    -
    - -
    - <%= render :partial => 'users/user_homework_attachment', :locals => {:container => @work, :has_program=>false,:has_group=>false} %> -
    - - <% if @homework.homework_type == 3 %> -
    - 合作成员 +
    +
  • + +
    +
    + 成员要求:<%=@homework.homework_detail_group.min_num %>~<%=@homework.homework_detail_group.max_num %>人 + 成员人数不符合要求 +
    +
    + + + +
    +
    + <%= render :partial => 'group_member_search_list', :locals => {:users => nil} %> +
    +
    +
    + 已选成员 +
    + + + <% @commit_users.each do |user| %> + + + + + + + <% end %> + +
    <%= user.show_real_name %><%= user.user_extensions.try(:student_id) %><%= @course.members.where(:user_id => user.id).first.course_group.try(:name) %>
    +
    + 双击删除成员,但不能删除自己 +
    +
    +
    +
  • - <% end %> - -
    - 确定 - - <%= link_to "取消", student_work_index_path(:homework => @homework), :class => "fr mr10 mt3"%> -
    -
    - <% end%> -
    -
    -
    - \ No newline at end of file +
    + <% end %> +
  • + 提交 + <%=link_to '取消', student_work_index_path(:homework => @homework.id),:class=>'task-btn fr mr10' %> +
  • + <% else %> + <%= render :partial => 'new_pro_student_work', :locals => {:student_work => @work, :f => f} %> + <% end %> + <% end %> +
    \ No newline at end of file diff --git a/app/views/student_work/index.html.erb b/app/views/student_work/index.html.erb index 1837b66a9..0c125e6c7 100644 --- a/app/views/student_work/index.html.erb +++ b/app/views/student_work/index.html.erb @@ -1,212 +1,333 @@ <% content_for :header_tags do %> -<%= javascript_include_tag "/assets/codemirror/codemirror_python_ruby_c" %> -<%= javascript_include_tag "resizeable_table" %> +<%= javascript_include_tag "/assets/codemirror/codemirror_python_ruby_c" %> +<%= javascript_include_tag "resizeable_table" %> <%= stylesheet_link_tag "/assets/codemirror/codemirror" %> <%= import_ke(enable_at: true, prettify: false, init_activity: true) %> <% end %> <% is_group_project_homework = @homework.homework_type == 3 && @homework.homework_detail_group.base_on_project == 1 %> -
    -
    -
    - - - <% if @is_teacher%> -
    -
      -
    • - 导出 -
        -
      • - <%= link_to "导出作业成绩", student_work_index_path(:homework => @homework.id,:order => @order, :sort => @b_sort, :name => @name, :group => @group, :format => 'xls'),:class=>'hworkExport postTypeGrey', :id => "export_student_work"%> -
      • -
      • - <% if @homework.student_works.has_committed.empty?%> - <%= link_to "导出作业附件", "javascript:void(0)", class: "hworkExport resourcesGrey", :onclick => "alert('没有学生提交作业,无法下载附件')" %> - <% else%> - <%= link_to "导出作业附件", zipdown_assort_path(obj_class: @homework.class, obj_id: @homework, format: :json), - remote: true, class: "hworkExport resourcesGrey", :id => "download_homework_attachments" %> - <% end%> -
      • - <% if @homework.anonymous_comment == 0 %> -
      • - <%= link_to("导出缺评情况", absence_penalty_list_student_work_index_path(:homework => @homework.id, :format => 'xls'),:class=>'hworkExport resourcesGrey')%> -
      • -
      • - <%= link_to("导出匿评情况", evaluation_list_student_work_index_path(:homework => @homework.id, :format => 'xls'),:class=>'hworkExport resourcesGrey')%> -
      • - <% end %> -
      -
    • -
    -
    - <% end%> -
    -
    - -
      -
    • - 作业信息 -
    • -
    • - 作品列表 -
    • - <% if is_group_project_homework %> -
    • - 关联项目列表 -
    • - <% if !@homework.student_work_projects.empty? %> -
    •   - <%= link_to '项目活跃度', course_statistics_course_path(@homework.course, :tab => 3, :homework_id => @homework.id), - :id => 'project_activities', :class => 'fr fontBlue2 none', :style => 'font-weight: normal;', :target => '_blank' %> -
    • - <% else %> -
    •  
    • - <% end %> - <% else %> -
    •  
    • - <% end %> -
    -
    - -
    -
    - <%= render :partial => 'student_work/homework_post_brief', :locals => {:homework => @homework, :is_teacher => @is_teacher} %> -
    - <%= render :partial => 'users/homework_post_reply', :locals => {:activity => @homework, :user_activity_id => @homework.id, :hw_status => 3, :is_teacher => @is_teacher} %> -
    -
    - -
    -
    -
    -
    - <%= render :partial => "student_work/student_work_list"%> -
    -
    -
    -
    - - <% if is_group_project_homework %> -
    - <% student_work_ids = @homework.student_works.has_committed.blank? ? "(-1)" : "(" + @homework.student_works.has_committed.map{|st| st.id}.join(",") + ")" %> - <% student_work_projects = @homework.student_work_projects.where("student_work_id in #{student_work_ids} or student_work_id is null") %> - <% project_ids = student_work_projects.blank? ? "(-1)" : "(" + student_work_projects.map{|pro| pro.project_id}.join(",") + ")" %> - <% projects = Project.where("id in #{project_ids}").order("updated_on desc") %> - <%= render :partial => "student_work/relate_projects", :locals => {:projects => projects}%> -
    +
    +

    + + <%= link_to @homework.course.name, course_path(@homework.course) %> > <%= link_to '作业列表', homework_common_index_path(:course => @homework.course_id, :homework_type => @homework.homework_type) %> > #<%= get_hw_index(@homework, @is_teacher, @homework.homework_type) + 1 %>

    +
    +

    + <% unless @homework.is_public %> + <% end %> + <%= @homework.name %> +

    + <%= link_to '返回', homework_common_index_path(:course => @homework.course_id, :homework_type => @homework.homework_type), :class => 'fr font-12 mr15 mt3 link-color-grey' %> +
    +
    +
    +
    +
      +
    • + 作业详情 +
    • +
    • + 作品列表 +
    • + <% if @homework.homework_type!= 4 && @is_teacher || (@homework.answer_public && @homework.homework_detail_manual.comment_status > 2) %> +
    • + 参考答案 +
    • + <% end %> +
    +
    +
    +
    + <% if @is_teacher%> +
    + +
      + <% if @homework.homework_type != 4 %> +
    • + <%= link_to l(:button_edit), edit_homework_common_path(@homework) %> +
    • + <% end %> +
    • + <%= link_to "设置", setting_homework_common_path(@homework) %> +
    • + <% if @homework.homework_type == 4 %> +
    • + <%= link_to '进入实训', shixun_path(@homework.homework_commons_shixuns.shixun), :target => "_blank" %> +
    • + <% end %> + <% unless @homework.is_public %> +
    • + 设为公开 +
    • + <% end %> + <% if (User.current.teacher_of_course(@homework.course) || @homework.user == User.current) && User.current.homework_banks.where(:homework_common_id => @homework.id).empty? %> +
    • + <%= link_to "加入题库", add_to_homework_bank_homework_common_path(@homework, :type => 1), :remote => true %> +
    • + <% end %> + <% if @homework.user == User.current %> + <% if @homework.is_update && !User.current.homework_banks.where(:homework_common_id => @homework.id).blank? %> +
    • + <%= link_to "同步到题库", add_to_homework_bank_homework_common_path(@homework, :type => 2), :remote => true %> +
    • +
    • + <%= link_to "另存到题库", add_to_homework_bank_homework_common_path(@homework, :type => 3), :remote => true %> +
    • + <% end %> + <% end %> +
    • + 删除 +
    • +
    +
    + <% else %> + <%= user_work_status @homework %> + <% if @homework.homework_type == 4 && !@homework.student_works.where(:user_id => User.current.id, :work_status => 0).blank? %> + <%= link_to "开始实战", shixun_path(@homework.homework_commons_shixuns.shixun),:class => 'task-btn task-btn-blue fr mr10',:target => "_blank" %> + <% end %> + <%= link_to "查看设置", setting_homework_common_path(@homework), :class => 'edu-btn fr mr10' %> + <% end %> +
    +
    + <%= @homework.description.html_safe %>
    -
    \ No newline at end of file +
      + <%= render :partial=>"attachments/activity_attach", :locals=>{:activity => @homework} %> +
    +<% if @homework.homework_type == 3 %> +
    +
    +

    分组要求

    +
    +
    +

    分组人数: <%= @homework.homework_detail_group.min_num %> - <%= @homework.homework_detail_group.max_num %> 人

    + 注:任一成员都可以提交作品,提交作品时需要关联同组成员,组内成员作品共享。 +
    +
    +<% end %> + +<% if @homework.homework_type == 2 %> + <% samples = @homework.homework_samples %> + <% unless samples.empty? %> +
    +
    +

    输入输出样例:<%= samples.count %> 组

    +
    +
    + <% samples.each_with_index do |sample, index| %> +
    +
      +
    • + + 样例<%= index + 1 %> +
    • +
    • + +
      +
      <%=sample.input.blank? ? " " : sample.input %>
      +
      +
    • +
    • + +
      +
      <%=sample.output.blank? ? " " : sample.output %>
      +
      +
    • +
    +
    + <% end %> +
    +
    + <% end %> + + <% if @is_teacher %> +
    +
    +

    测试集:<%=@homework.homework_tests.count %> 组

    +
    +
    + + + + + + + + + + <% @homework.homework_tests.each_with_index do |test, i| %> + + + + + + <% end %> + +
    序号测试集输入测试集输出
    <%=i+1 %> +
    <%=test.input.blank? ? " " : test.input %>
    +
    +
    <%=test.output.blank? ? " " : test.output %>
    +
    +
    +
    + <% end %> +<% end %> +
    + <%= render :partial => 'student_work_replies' %> +
    +
    +
    +
    +
    + <% if @is_teacher %> + <% student_works = @homework.student_works.where("work_status != 0") %> +
    +
      + +
    • + 你的评阅: + + 不限 + + <% has_comment = User.current.student_works_scores.where(:student_work_id => @homework.student_works.map(&:id), :reviewer_role => [1, 2]).group_by(&:student_work_id).count %> + > + + > + +
    • +
    • + 作品状态: + + 不限 + + > + + > + + > + +
    • +
    • + 分班情况: + + 不限 + + <% @homework.course.course_groups.each do |group| %> + > + + <% end %> + + +
    • +
    • +   +
      + + +
      +
    • +
    +
    + <% else %> + <% my_work = cur_user_works_for_homework @homework %> + <% if @homework.homework_detail_manual.comment_status == 3 %> + <% unless my_work.nil?%> + <% if my_work.student_works_evaluation_distributions.count != 0 %> + 你在匿评开启之前提交了作品,你的作品正在匿评中 + <% else %> + 你在匿评开启之后才提交作品,你的作品没有参与匿评 + <% end %> + <% else %> + 你未提交作品,无法参与匿评 + <% end %> + <% else %> + <% if my_work %> + 你已提交 + <% else %> + 你未提交 + <% end %> + <% if @homework.homework_detail_manual.comment_status < 3 %> + <%= user_work_status @homework %> + <% end %> + <% if @homework.homework_type == 4 && !@homework.student_works.where(:user_id => User.current.id, :work_status => 0).blank? %> + <%= link_to "开始实战", shixun_path(@homework.homework_commons_shixuns.shixun),:class => 'task-btn task-btn-blue fr mr10',:target => "_blank" %> + <% end %> + <% end %> + +

    + <%= @homework.student_works.where("work_status != 0").count %> 已交 + <%= @homework.course.student.count - @homework.student_works.where("work_status != 0").count %> 未交 + <% if @homework.homework_detail_manual%> + <% if @homework.homework_detail_manual.comment_status == 1%> + <% end_time = @homework.end_time.to_i %> + <% if end_time >= Time.now.to_i %> + 提交剩余时间 <%= (end_time - Time.now.to_i) / (24*60*60) %> 天 <%= ((end_time - Time.now.to_i) % (24*60*60)) / (60*60)%> 小时 <%= (((end_time - Time.now.to_i) % (24*60*60)) % (60*60)) / 60%> 分 + <% else %> + 提交已截止 + <% end %> + <% elsif @homework.homework_detail_manual.comment_status == 3%> + <% end_time = @homework.homework_detail_manual.evaluation_end.to_time.to_i + 24*60*60 - 1 %> + <% if end_time >= Time.now.to_i %> + 匿评剩余时间 <%= (end_time - Time.now.to_i) / (24*60*60)%> 天 <%= ((end_time - Time.now.to_i) % (24*60*60)) / (60*60)%> 小时 <%= (((end_time - Time.now.to_i) % (24*60*60)) % (60*60)) / 60%> 分 + <% else %> + 匿评已截止 + <% end %> + <% end%> + <% end%> +

    + <% end %> +
    +
    + <%= render :partial => 'student_work_list' %> +
    +
    +
    +<% if @is_teacher || (@homework.answer_public && @homework.homework_detail_manual.comment_status > 2) %> +
    +
    +
    + <% unless @homework.reference_answer.blank? %> + <%= @homework.reference_answer.html_safe %> + <% else %> + +

    暂未设置参考答案 ~

    + <% end %> +
    +
    +
    +<% end %> +
    +
    +
    +
    +
    + + \ No newline at end of file diff --git a/app/views/student_work/index.js.erb b/app/views/student_work/index.js.erb index 6197c2259..9688c96b3 100644 --- a/app/views/student_work/index.js.erb +++ b/app/views/student_work/index.js.erb @@ -1,2 +1 @@ -$("#homework_student_work_list").html("<%= escape_javascript(render :partial => 'student_work/student_work_list') %>"); -$("#export_student_work").replaceWith("<%= escape_javascript( link_to "导出作业成绩", student_work_index_path(:homework => @homework.id,:order => @order, :sort => @b_sort, :group => @group, :name => @name, :format => 'xls'),:class=>'hworkExport postTypeGrey', :id => 'export_student_work') %>"); +$("#homework_student_work_list").html("<%= escape_javascript(render :partial => 'student_work_list') %>"); \ No newline at end of file diff --git a/app/views/student_work/new.html.erb b/app/views/student_work/new.html.erb index 306fb3749..36314f88b 100644 --- a/app/views/student_work/new.html.erb +++ b/app/views/student_work/new.html.erb @@ -1,11 +1,14 @@ <% content_for :header_tags do %> <%= import_ke(enable_at: true, prettify: false, init_activity: false) %> - <%= javascript_include_tag 'homework','baiduTemplate' %> <% end %> -
    -
    -
    提交作品
    -
    -
    +
    +

    + + <%= link_to @course.name, course_path(@course) %> > <%= link_to '作业列表', homework_common_index_path(:course => @course, :homework_type => @homework.homework_type) %> > #<%= link_to (get_hw_index(@homework, @is_teacher, @homework.homework_type) + 1), student_work_index_path(:homework => @homework.id) %>

    +
    +

    <%= @homework.name %>

    + <%= link_to '返回', homework_common_index_path(:course => @homework.course_id, :homework_type => @homework.homework_type), :class => 'fr font-12 mr15 mt3 link-color-grey' %> +
    -
    注意:暂不支持IE浏览器的上传,请更换浏览器
    + <%= form_for(@student_work, + :html => { :multipart => true, :id => "student_work_form"}, + :url => {:controller => 'student_work', + :action => 'create', + :homework => @homework.id + }, + :method => :post) do |f| %> + <% if @homework.homework_type == 2 %> + <%= render :partial => 'new_pro_student_work', :locals => {:student_work => @student_work, :f => f} %> + <% else %> +
    +
    +
    +
      +
    • + + + <%= f.kindeditor :description, :editor_id => 'student_work_description_editor', + :owner_id => @student_work.nil? ? 0: @student_work.id, + :owner_type => OwnerTypeHelper::STUDENTWORK, + :width => '90%', + :height => 200, + :minHeight=>200, + :class => 'talk_text fl', + :input_html => { :id => 'student_work_content', + :class => 'talk_text fl', + :maxlength => 5000 } + %> +
    • + + + + +
    • + + 内容不能为空 +
    • +
    • + <%= render :partial => 'users/user_homework_attachment', :locals => {:container => @student_work} %> +
    • +
    +
    +
    +
    -
    -
    -
    - - - 截止时间:<%= format_time @homework.end_time%> - -
    - - <%= link_to @homework.user.show_name, user_activities_path(@homework.user_id), :class => "c_blue"%> - -
    -
    - <%= @homework.description.html_safe %> -
    -
    - <%= render :partial => 'student_work/work_attachments', :locals => {:attachments => @homework.attachments} %> -
    -
    -
    -
    -
    - -
    - <%= form_for(@student_work, - :html => { :multipart => true }, - :url => {:controller => 'student_work', - :action => 'create', - :homework => @homework.id - },:remote=>true ) do |f| %> - <% if @homework.anonymous_comment == 0 %> -
    - 提示:作品名称和描述中不要出现真实的姓名信息 -
    - <% end %> -
    - <% if @homework.homework_type == 3 %> + <% if @homework.homework_type == 3 %> +
    - <%=hidden_field_tag 'group_member_ids', params[:group_member_ids], :value=>User.current.id %> - <% end %> -
    - <%= f.text_field "name", :required => true, :size => 60, :class => "InputBox W700", :maxlength => 200, :placeholder => "请输入作品名称",:value=>"#{@homework.name}的作品提交(可修改)", :onkeyup => "regexStudentWorkName();" %> -
    -

    -
    -
    - - <%#= f.text_area "description", :class => "InputBox W700 H150", :placeholder => "请输入作品描述", :onkeyup => "regexStudentWorkDescription();"%> - -
    -

    -

    -

    -
    - -
    - <%= render :partial => 'users/user_homework_attachment', :locals => {:container => @student_work, :has_program=>false,:has_group=>false} %> -
    -
    -
    -
    -
    - - <% if @homework.homework_type == 3 %> -
    - 合作成员 +
    +
  • + +
    +
    + 成员要求:<%=@homework.homework_detail_group.min_num %>~<%=@homework.homework_detail_group.max_num %>人 + 成员人数不符合要求 +
    +
    + + + +
    +
    + <%= render :partial => 'group_member_search_list', :locals => {:users => nil} %> +
    +
    +
    + 已选成员 +
    + + + + + + + + + +
    <%= @user.show_real_name %><%= @user.user_extensions.try(:student_id) %><%= @course.members.where(:user_id => @user.id).first.course_group.try(:name) %>
    +
    + 双击删除成员,但不能删除自己 +
    +
    +
    +
  • - <% end %> - - - - - -
    - 提交 - - <%= link_to "取消", delete_work_student_work_index_path(:homework =>@homework.id),:id => 'new_message_cancel_btn', :class => "fr mr10 mt3"%> -
    -
    - <% end%> -
    -
    +
    + <% end %> +
  • + 提交 + <%=link_to '取消', student_work_index_path(:homework => @homework.id),:class=>'task-btn fr mr10' %> +
  • + <% end %> + <% end %>
    diff --git a/app/views/student_work/relate_myshixun.js.erb b/app/views/student_work/relate_myshixun.js.erb new file mode 100644 index 000000000..88d859873 --- /dev/null +++ b/app/views/student_work/relate_myshixun.js.erb @@ -0,0 +1,7 @@ +<% if @status == 0 %> + notice_box("您还没有开启实训,无法关联"); +<% elsif @status == 1 %> + notice_box_redirect("<%= student_work_index_path(:homework => @homework.id) %>", "已关联成功"); +<% elsif @status == 2 %> + notice_box_redirect("<%= student_work_index_path(:homework => @homework.id) %>", "您已关联过实训,请不要重复关联"); +<% end %> \ No newline at end of file diff --git a/app/views/student_work/search_course_students.js.erb b/app/views/student_work/search_course_students.js.erb index d216633a6..b3c405d21 100644 --- a/app/views/student_work/search_course_students.js.erb +++ b/app/views/student_work/search_course_students.js.erb @@ -1,59 +1 @@ -$("#all_students_list").empty(); -<% @users.each do |user|%> - var link = "
  • <%=user.show_name %>"; - <% unless user.user_extensions.student_id == "" %> - link += "(<%=user.user_extensions.student_id %>)"; - <% end %> - link += "
  • "; - $("#all_students_list").append(link); - - var str = $("#group_member_ids").val(); - var choose_str = ""; - var lists = $("#choose_students_list li"); - if(lists.length > 0) { - for(var i=0; i - if (str.indexOf(<%=user.id.to_s %>) < 0 && choose_str.indexOf(<%=user.id.to_s %>) < 0) { - $("#student_<%=user.id %>").on("click",function choose_student() { - if($("#choose_student_<%=user.id %>").length > 0){ - $("#choose_member_notice").html("该成员已添加"); - $("#choose_member_notice").show(); - } else{ - $("#choose_member_notice").hide(); - var li = "
  • - li += " onclick='delete_student(<%=user.id %>);'"; - <% end %> - li += ">" + $("#student_<%=user.id %>").html()+"
  • "; - $("#choose_students_list").append(li); - } - }); - } - <% elsif !user.member_of_course?(@course) %> - if (str.indexOf(<%=user.id.to_s %>) < 0) { - $("#student_<%=user.id %>").on("click",function() { - $("#choose_member_notice").html("该项目成员不是本班级的学生"); - $("#choose_member_notice").show(); - }); - } - <% else %> - if (str.indexOf(<%=user.id.to_s %>) < 0) { - $("#student_<%=user.id %>").on("click",function() { - $("#choose_member_notice").html("该学生已加入其它分组"); - $("#choose_member_notice").show(); - }); - } else{ - $("#student_<%=user.id %>").on("click",function() { - $("#choose_member_notice").html("该成员已添加"); - $("#choose_member_notice").show(); - }); - } - <% end %> -<% end %> \ No newline at end of file +$("#group_member_search_list").html("<%= j(render :partial => 'group_member_search_list', :locals => {:users => @users}) %>"); diff --git a/app/views/student_work/show.html.erb b/app/views/student_work/show.html.erb new file mode 100644 index 000000000..e8eddf628 --- /dev/null +++ b/app/views/student_work/show.html.erb @@ -0,0 +1,212 @@ +<%= javascript_include_tag "/codemirror/lib/codemirror", "/codemirror/mode/javascript/javascript", "/codemirror/addon/edit/matchbrackets.js", "/codemirror/mode/clike/clike" %> +<%= stylesheet_link_tag "/codemirror/lib/codemirror" %> + +
    +

    <%= @course.name %> > 作业列表 > + #<%= link_to (get_hw_index(@homework, @is_teacher, @homework.homework_type) + 1), student_work_index_path(:homework => @homework.id) %> > + <% if @is_teacher || @work.user == User.current || (@homework.homework_detail_manual.comment_status != 3 && @homework.homework_detail_manual.comment_status != 4) %> + <%= link_to @work.user.try(:show_real_name), user_path(@work.user) %> + <% else %> + 匿名 + <% end %> +

    +
    +

    <%= @work.name %>

    + 返回 +
    +<%# work_status :0 未提交 1 已提交 2 迟交 3 分组作品复制的组员作品 %> +<%# homework_type: 0:普通作业;1:匿评作业;2:编程作业;3:分组作业; %> +<%# 补交:在作业截止日期之前提交了作品,作业截止之后补充了附件 %> +<%# 迟交:在作业截止日期之后提交了作品 %> +<% if @work.work_status != 0 %> +<% if @homework.homework_type == 1 || @homework.homework_type == 3 %> +
    +
    +

    <%= @work.work_status == 2 ? '补交内容' : "内容" %>

    + <% if @work.work_status != 0 && User.current == @work.user && @homework.allow_late && @homework.end_time < Time.now && @homework.homework_detail_manual.comment_status < 6 %> + 补交附件 + <% end %> +
    +
    +
    <%= @work.description ? @work.description.html_safe : "" %>
    +
      + <% com_attachments = @work.attachments.where("attachtype IS NULL OR attachtype <> 7") %> + <% if com_attachments.empty?%> + 尚未提交附件 + <% else%> + <%= render :partial => 'work_attachments_status', :locals => {:attachments => com_attachments, :status => @homework.homework_detail_manual.comment_status} %> + <% end%> +
    • <%= format_time(@work.commit_time) %> 提交<%= format_time(@work.updated_at) %> 更新
    • +
    +
    +
    + <% if !@work.attachments.where(:attachtype => 7).blank? %> + <% revise_attachment = @work.attachments.where("attachtype = 7").first %> +
    +
    +

    补交附件

    +
    +
    + 补交原因:<%= revise_attachment.description %> +
      + <%= render :partial => 'work_attachments_status', :locals => {:attachments => @work.attachments.where("attachtype = 7"), :status => @homework.homework_detail_manual.comment_status} %> +
    • <%= format_time(revise_attachment.created_on) %> 提交
    • +
    +
    +
    + <% end %> + + <% if @homework.homework_type == 3 %> + <% unless @team_work.count == 0 %> +
    +
    +

    其他组员

    +
    +
    +
    + <% @team_work.each do |team_work| %> + <%= team_work.try(:show_real_name) %> + <% end %> +
    +
    +
    + <% end %> + <% end %> +<% elsif @homework.homework_type == 2 %> + <% unless @work.description.blank? %> +
    +
    +

    内容

    +
    +
    + +
    +
    + + <% end %> + <% unless @work.student_work_tests.blank? %> +
    +
    +

    评测历史

    +
    +
    + <% @work.student_work_tests.each_with_index do |test, index| %> +
    + 第<%= @work.student_work_tests.count - index %>次 +
    + <% if test.status.to_i == -2 %> +
    <%= test.results.first %>
    + <% else %> + <% test.results.reverse.each_with_index do |x, i| %> +
    + + 测试集 <%= test.results.size - i %> + <% if x["status"].to_i == 0 %> + + <% else %> + + <% end %> +
    +
    + + + + + + + + + + + + + +
    期望输出实际输出
    +
    <%= x["output"].blank? ? "" : x["output"].force_encoding("UTF-8") %>
    +
    <%= x["result"].blank? ? "" : x["result"].force_encoding("UTF-8") %>
    +
    +
    + <% end %> + <% end %> +
    +
    + <% end %> +
    +
    + <% end %> +<% end %> +<% end %> + +
    + <%= render :partial => 'student_work_score_div' %> +
    +
    + + + \ No newline at end of file diff --git a/app/views/student_work/show.js.erb b/app/views/student_work/show.js.erb index d8f36d4ba..c9aecf6bc 100644 --- a/app/views/student_work/show.js.erb +++ b/app/views/student_work/show.js.erb @@ -1,37 +1,2 @@ -if($("#about_hwork_<%= @work.id%>").children().length > 0){ - $("#about_hwork_<%= @work.id%>").html(""); -} -else{ - $(".about_hwork").html(""); - <% if @homework.homework_type == 2%> - $("#about_hwork_<%= @work.id%>").html("<%= escape_javascript(render :partial => 'programing_work_show',:locals => {:work =>@work,:score =>@score,:student_work_scores => @student_work_scores}) %>"); - - var program_name = "text/x-csrc"; - var language = <%= @homework.language %>; - if (language == 1) { - program_name = 'text/x-csrc'; - } else if(language==2){ - program_name = 'text/x-c++src'; - }else if(language==3){ - program_name = 'text/x-cython'; - } else if(language==4){ - program_name = 'text/x-java'; - } - - var editor = CodeMirror(document.getElementById("work-code_<%= @work.id%>"), { - mode: {name: program_name, - version: 2, - singleLineStringErrors: false}, - lineNumbers: true, - indentUnit: 2, - matchBrackets: true, - readOnly: true, - value: $("#work-src_<%= @work.id%>").text() - } - ); - - <% else%> - $("#about_hwork_<%= @work.id%>").html("<%= escape_javascript(render :partial => 'show',:locals => {:work =>@work,:score =>@score,:student_work_scores => @student_work_scores}) %>"); - <% end%> - $('#score_<%= @work.id%>').peSlider({range: 'min'}); -} \ No newline at end of file +var htmlvalue = "<%= j(render :partial => 'student_work/shixun_work_show') %>"; +pop_box_new(htmlvalue, 600, 500) \ No newline at end of file diff --git a/app/views/student_work/student_work_absence_penalty.html.erb b/app/views/student_work/student_work_absence_penalty.html.erb index 967480552..01b693105 100644 --- a/app/views/student_work/student_work_absence_penalty.html.erb +++ b/app/views/student_work/student_work_absence_penalty.html.erb @@ -34,7 +34,7 @@
  • - <%= link_to student_work.user.show_name,user_path(student_work.user),:title => student_work.user.show_name, :class => "c_blue02"%> + <%= link_to student_work.user.show_real_name,user_path(student_work.user),:title => student_work.user.show_real_name, :class => "c_blue02"%>
  • <%= student_work.all_count%> diff --git a/app/views/student_work/work_canrepeat.js.erb b/app/views/student_work/work_canrepeat.js.erb index 4c7cb8489..2ddd52367 100644 --- a/app/views/student_work/work_canrepeat.js.erb +++ b/app/views/student_work/work_canrepeat.js.erb @@ -1,13 +1,7 @@ //代码查重 <% if @work_count <= 1 %> //弹框 - $("#ajax-modal").html('<%= escape_javascript( render :partial => 'courses/compare_code_tips_2',:locals => {:des=>"对不起该作业的作品过少不能查重!",:status=>0, :homework=> @homework,:courseid=> @course_id})%>'); - showModal('ajax-modal', '580px'); - $('#ajax-modal').siblings().remove(); - $('#ajax-modal').before(""); - $('#ajax-modal').parent().css("top", "30%").css("left", "50%").css("padding-top", "10px").css("position", "fixed"); - $('#ajax-modal').parent().addClass("resourceUploadPopup"); - $('#ajax-modal').css("padding-left", "16px").css("padding-bottom", "16px"); + notice_box("对不起该作业的作品过少不能查重!"); function closeModal() { hideModal($(".blue-border-box")); @@ -21,79 +15,29 @@ {homework: <%=@homework.id%>}, function (data, status) { if (data.status == 0) { - $("#ajax-modal").html('<%= escape_javascript( render :partial => 'courses/compare_code_tips_2',:locals => {:des=>"查重完成是否立即查看结果?",:status=>1, :homework=> @homework,:courseid=> @course_id})%>'); - showModal('ajax-modal', '580px'); - $('#ajax-modal').siblings().remove(); - $('#ajax-modal').before(""); - $('#ajax-modal').parent().css("top", "30%").css("left", "50%").css("padding-top", "10px").css("position", "fixed"); - $('#ajax-modal').parent().addClass("resourceUploadPopup"); - $('#ajax-modal').css("padding-left", "16px").css("padding-bottom", "16px"); - - function closeModal() { - hideModal($(".blue-border-box")); - } + var htmlvalue = "<%= escape_javascript( render :partial => 'courses/compare_code_tips_2', :locals => {:des=>"查重完成是否立即查看结果?",:status=>1, :homework=> @homework,:courseid=> @course_id})%>"; + pop_box_new(htmlvalue, 480, 140); } else if (data.status == -1) { + var htmlvalue = "<%= escape_javascript( render :partial => 'courses/compare_code_tips_2', :locals => {:des=>"对不起目前只支持java/c/c++的代码查重!",:status=>0, :homework=> @homework,:courseid=> @course_id})%>"; + pop_box_new(htmlvalue, 480, 140); // confirm("对不起只支持java/c/c++的代码查重!"); - $("#ajax-modal").html('<%= escape_javascript( render :partial => 'courses/compare_code_tips_2',:locals => {:des=>"对不起目前只支持java/c/c++的代码查重!",:status=>0, :homework=> @homework,:courseid=> @course_id})%>'); - showModal('ajax-modal', '580px'); - $('#ajax-modal').siblings().remove(); - $('#ajax-modal').before(""); - $('#ajax-modal').parent().css("top", "30%").css("left", "50%").css("padding-top", "10px").css("position", "fixed"); - $('#ajax-modal').parent().addClass("resourceUploadPopup"); - $('#ajax-modal').css("padding-left", "16px").css("padding-bottom", "16px"); - - function closeModal() { - hideModal($(".blue-border-box")); - } - } else if (data.status == -2) { // confirm("对不起该作业的作品过少不能查重!"); - $("#ajax-modal").html('<%= escape_javascript( render :partial => 'courses/compare_code_tips_2',:locals => {:des=>"对不起该作业的作品过少不能查重!",:status=>0, :homework=> @homework,:courseid=> @course_id})%>'); - showModal('ajax-modal', '580px'); - $('#ajax-modal').siblings().remove(); - $('#ajax-modal').before(""); - $('#ajax-modal').parent().css("top", "30%").css("left", "50%").css("padding-top", "10px").css("position", "fixed"); - $('#ajax-modal').parent().addClass("resourceUploadPopup"); - $('#ajax-modal').css("padding-left", "16px").css("padding-bottom", "16px"); - - function closeModal() { - hideModal($(".blue-border-box")); - } + var htmlvalue = "<%= escape_javascript( render :partial => 'courses/compare_code_tips_2', :locals => {:des=>"对不起该作业的作品过少不能查重!",:status=>0, :homework=> @homework,:courseid=> @course_id})%>"; + pop_box_new(htmlvalue, 480, 140); } } ).fail(function (xhr, status) { // confirm("对不起,服务器繁忙请稍后再试!"); - $("#ajax-modal").html('<%= escape_javascript( render :partial => 'courses/compare_code_tips_2',:locals => {:des=>"对不起,服务器繁忙请稍后再试!",:status=>0, :homework=> @homework,:courseid=> @course_id})%>'); - showModal('ajax-modal', '580px'); - $('#ajax-modal').siblings().remove(); - $('#ajax-modal').before(""); - $('#ajax-modal').parent().css("top", "30%").css("left", "50%").css("padding-top", "10px").css("position", "fixed"); - $('#ajax-modal').parent().addClass("resourceUploadPopup"); - $('#ajax-modal').css("padding-left", "16px").css("padding-bottom", "16px"); - - function closeModal() { - hideModal($(".blue-border-box")); - } + var htmlvalue = "<%= escape_javascript( render :partial => 'courses/compare_code_tips_2', :locals => {:des=>"对不起,服务器繁忙请稍后再试!",:status=>0, :homework=> @homework,:courseid=> @course_id})%>"; + pop_box_new(htmlvalue, 480, 140); }); }; test_repeat(); <% else%> - $("#ajax-modal").html('<%= escape_javascript( render :partial => 'courses/compare_code_tips_1',:locals => {:homework=> @homework,:courseid=>@course_id })%>'); - $('#compare-tips-1').html('您上次查重的时间为<%= Time.parse(@homework.simi_time.to_s).strftime("%Y-%m-%d %H:%M:%S")%>'); - showModal('ajax-modal', '580px'); - $('#ajax-modal').siblings().remove(); - $('#ajax-modal').before(""); - $('#ajax-modal').parent().css("top", "30%").css("left", "50%").css("padding-top", "10px").css("position", "fixed"); - $('#ajax-modal').parent().addClass("resourceUploadPopup"); - $('#ajax-modal').css("padding-left", "16px").css("padding-bottom", "16px"); - - function closeModal() { - hideModal($(".blue-border-box")); - } + var htmlvalue = "<%= escape_javascript( render :partial => 'courses/compare_code_tips_1', :locals => {:homework=> @homework,:courseid=>@course_id })%>"; + pop_box_new(htmlvalue, 480, 140); <% end %> -<% end %> - - - +<% end %> \ No newline at end of file diff --git a/app/views/subjects/_choose_shixun.html.erb b/app/views/subjects/_choose_shixun.html.erb new file mode 100644 index 000000000..cb314cf8f --- /dev/null +++ b/app/views/subjects/_choose_shixun.html.erb @@ -0,0 +1,41 @@ +
    +
    +

    选择课程

    + +
    +
    +
    +

    您可以组建的课程实训如下,请选择:

    +
      + <% @course_lists.each do |course| %> +
    • + + +
    • + <% end %> +
    +

    请至少选择一个课程

    +
  • + 确定 + 取消 +
  • +
    +
    +
    + + diff --git a/app/views/subjects/_course_shixun_list.html.erb b/app/views/subjects/_course_shixun_list.html.erb new file mode 100644 index 000000000..d0d6f3920 --- /dev/null +++ b/app/views/subjects/_course_shixun_list.html.erb @@ -0,0 +1,40 @@ +<% if @shixuns.count > 0 %> + + + + + + + + + + <% @shixuns.each do |shixun| %> + + + + + + <% end %> + +
    实训名称任务状态
    + + + + + <%= shixun.challenges.count %><%= shixun.shixun_status %>
    +<% else %> +

    没有实训可选择

    +<% end %> +

    请至少选择一个实训

    +
    +
    +
      + <%= pagination_links_full @shixuns_pages, @shixuns_count, :per_page_links => false, :flag => true, :is_remote => true, :is_new => true %> +
    +
    +
    +
    + 选择 + 取消 +
    +
    \ No newline at end of file diff --git a/app/views/subjects/_my_course_shixun_list.html.erb b/app/views/subjects/_my_course_shixun_list.html.erb new file mode 100644 index 000000000..2c2494f56 --- /dev/null +++ b/app/views/subjects/_my_course_shixun_list.html.erb @@ -0,0 +1,28 @@ +
    +
    +

    选择实训

    + +
    +
    +
    + <%= form_for('new_form', :url => append_to_stage_subjects_path(), :remote => true, :method => "post", :html => {:id => 'choose_course_shixun_form'}) do |f| %> +
    + <%= render :partial => "course_shixun_list" %> +
    + <% end %> +
    +
    +
    + + \ No newline at end of file diff --git a/app/views/subjects/_publish_notice.html.erb b/app/views/subjects/_publish_notice.html.erb new file mode 100644 index 000000000..b9c3f093d --- /dev/null +++ b/app/views/subjects/_publish_notice.html.erb @@ -0,0 +1,23 @@ +
    +
    +

    提示

    + +
    +
    +

    + <% if @status == 0 %> + 已发布过申请,请等待管理员审核 + <% else %> + 发布申请已提交,请等待管理员的审核
    + • 我们将在1-2个工作日内完成审核 + <% end %> +

    +
    +
    + <% if @status == 1 %> + <%= link_to "知道啦", subject_path(@subject), :class => "task-btn task-btn-blue pop_close" %> + <% else %> + 知道啦 + <% end %> +
    +
    diff --git a/app/views/subjects/_subject_list.html.erb b/app/views/subjects/_subject_list.html.erb new file mode 100644 index 000000000..60e1ba55a --- /dev/null +++ b/app/views/subjects/_subject_list.html.erb @@ -0,0 +1,79 @@ + +
    + <% if @subjects.blank? %> +
    + <%= render :partial => "welcome/no_data" %> +
    + <% else %> + <% @subjects.each do |subject| %> +
    + <% if subject.status < 2 && !User.current.manager_of_subject?(subject) %> +
    +
    +
    尚未正式发布,请稍等
    +
    + <% end %> +
    +

    + <%= subject.name %> +

    + +

    + <%# if !subject.user.user_extensions.school_id.blank? && subject.user.user_extensions.school %> + <%#= subject.user.user_extensions.school.name %> + <%# end %> +

    +

    + <%= subject.stage_shixuns.count %> + <%= subject.subject_challenges %> + <%= subject.subject_score %> +

    +
    +
    +
    +
      + <% if subject.stage_shixuns.count <= 6 %> + <% for i in 1 .. subject.stage_shixuns.count do %> +
    • <%= i %>
    • + <% end %> + <% else %> +
    • 1
    • +
    • 2
    • +
    • 3
    • +
    • 4
    • +
    • ...
    • +
    • <%= subject.stage_shixuns.count %>
    • + <% end %> +
    +
    +
    +
    + <% end %> + <% end %> +
    + + diff --git a/app/views/subjects/_subject_top.html.erb b/app/views/subjects/_subject_top.html.erb new file mode 100644 index 000000000..cdd006272 --- /dev/null +++ b/app/views/subjects/_subject_top.html.erb @@ -0,0 +1,24 @@ +
    +
    +

    + <% if !@subject.user.user_extensions.school_id.blank? && @subject.user.user_extensions.school %> + <%= @subject.user.user_extensions.school.name %>   + <% end %> + <%= @subject.user.show_name %> +

    +
    +

    <%= @subject.name %>

    + <% if @subject.status > 1 %> + + <% elsif @subject.status == 0 && @subject.stages.count > 0 && User.current.manager_of_subject?(@subject) %> + <%= link_to '申请发布', publish_subject_path(@subject), :class => "course-btn fr", :remote => true %> + <% elsif @subject.status == 1 && User.current.manager_of_subject?(@subject) %> + <%= link_to '撤销发布', cancel_publish_subject_path(@subject), :class => "task-btn color_white bc-grey fr" %> + <% end %> +
    +
    +
    \ No newline at end of file diff --git a/app/views/subjects/append_to_stage.js.erb b/app/views/subjects/append_to_stage.js.erb new file mode 100644 index 000000000..72b1dc147 --- /dev/null +++ b/app/views/subjects/append_to_stage.js.erb @@ -0,0 +1,26 @@ +<% @shixuns.each do |shixun| %> +var html= '
    ' + + '' + + '' + + '
    ' + + '

    ' + + '<%= shixun.name %>' + + '

    ' + + '' + + '
    ' + + '<%= shixun.language %>' + + '

    <%= shixun.shixun_trainee %>

    ' + + '
    ' + + '
      ' + + '
    • <%= shixun.challenges.count %>
    • ' + + '
    • <%= shixun.myshixuns.count %>
    • ' + + '
    • <%= shixun.shixun_score %>
    • ' + + '
    ' + +'
    '; +$("#sortable").append(html); +$("#sortable" ).sortable({containment:".stage-item"}); +$("#sortable" ).disableSelection(); +<% end %> \ No newline at end of file diff --git a/app/views/subjects/choose_subject_shixun.js.erb b/app/views/subjects/choose_subject_shixun.js.erb new file mode 100644 index 000000000..73e1b7f6a --- /dev/null +++ b/app/views/subjects/choose_subject_shixun.js.erb @@ -0,0 +1,6 @@ +<% if params[:page] %> +$("#course_shixun_list").html("<%= j(render :partial => "subjects/course_shixun_list") %>"); +<% else %> +var htmlvalue = "<%= j(render :partial => 'subjects/my_course_shixun_list') %>"; +pop_box_new(htmlvalue, 620, 300); +<% end %> \ No newline at end of file diff --git a/app/views/subjects/index.html.erb b/app/views/subjects/index.html.erb new file mode 100644 index 000000000..657aca869 --- /dev/null +++ b/app/views/subjects/index.html.erb @@ -0,0 +1,35 @@ +
    +
    +
    +
    +

    实训套件

    + <%= link_to "+ 创建套件".html_safe, new_subject_subjects_path, :remote => true, :class => "fr color_white font-20" %> +
    +
    +
      +
    • <%= @subjects_all_count %>
      全部实训套件
    • +
    • <%= @subject_created_count %>
      我已创建
    • +
    +
    + + + + + + + + + + + + + + + + +
    + <%= render "subject_list" %> +
    +
    +
    + \ No newline at end of file diff --git a/app/views/subjects/index.js.erb b/app/views/subjects/index.js.erb new file mode 100644 index 000000000..b0c5459d8 --- /dev/null +++ b/app/views/subjects/index.js.erb @@ -0,0 +1 @@ +$("#subjects_list_content").html('<%= escape_javascript( render :partial => 'subjects/subject_list') %>'); \ No newline at end of file diff --git a/app/views/subjects/new_subject.js.erb b/app/views/subjects/new_subject.js.erb new file mode 100644 index 000000000..40554624c --- /dev/null +++ b/app/views/subjects/new_subject.js.erb @@ -0,0 +1,6 @@ +<% if @status == 0 %> +notice_sure_box("您还没有创建课程,无法组建实训套件"); +<% else %> +var htmlvalue = "<%= j(render :partial => 'choose_shixun') %>"; +pop_box_new(htmlvalue, 500, 300); +<% end %> \ No newline at end of file diff --git a/app/views/subjects/publish.js.erb b/app/views/subjects/publish.js.erb new file mode 100644 index 000000000..04bdaeee6 --- /dev/null +++ b/app/views/subjects/publish.js.erb @@ -0,0 +1,2 @@ +var htmlvalue = "<%= escape_javascript(render :partial => 'subjects/publish_notice')%>"; +pop_box_new(htmlvalue,563,406); \ No newline at end of file diff --git a/app/views/subjects/show.html.erb b/app/views/subjects/show.html.erb new file mode 100644 index 000000000..577eba13c --- /dev/null +++ b/app/views/subjects/show.html.erb @@ -0,0 +1,185 @@ +
    + <% @stages.each do |stage| %> +
    +
    +
  • <%= stage.name %>
  • + <% if @subject.status == 0 && User.current.manager_of_subject?(@subject) %> +
  • + 删除 + 编辑 +
  • + <% end %> +
    +
    + <% stage.stage_shixuns.each_with_index do |stage_shixun, index| %> + <% shixun = stage_shixun.shixun %> +
    +
    <%= index + 1 %>
    +
    +

    + <%= shixun.name %> +

    + +
    + <%= shixun.language %> +

    <%= shixun.shixun_trainee %>

    +
    +
      +
    • <%= shixun.challenges.count %>
    • +
    • <%= shixun.myshixuns.count %>
    • +
    • <%= shixun.shixun_score %>
    • +
    +
    + <% end %> +
    +
    + <% end %> +
    +<% if @subject.status == 0 && User.current.manager_of_subject?(@subject) %> +
    + <% if @stages.count == 0 %> + <%= form_for('', :url => {:controller => 'stages', :action => 'create', :subject => @subject.id}, :method => "post", :html => {:id => 'new_stage_form'}) do |f| %> +
    +
    +
  • 阶段1
  • +
  • + 删除 + 保存 +
  • +
    +
    +
  • +
  • + +

    + <%= link_to '+选择实训', choose_subject_shixun_subject_path(@subject), :remote => true, :class => 'add-sx' %> +

    + 至少选择一个实训 + 选择实训后,在页面上通过拖拽进行排序调整 +

    +
  • +
    +
    + +
    +
    + <% end %> + <% end %> +
    +
    + +点击新建阶段(选择1至多个实训项目,组成一个阶段) +
    +<% end %> + + \ No newline at end of file diff --git a/app/views/syllabus_member/_sy_change_manager.html.erb b/app/views/syllabus_member/_sy_change_manager.html.erb index 46ea94ba7..17ae3157a 100644 --- a/app/views/syllabus_member/_sy_change_manager.html.erb +++ b/app/views/syllabus_member/_sy_change_manager.html.erb @@ -15,8 +15,8 @@ <% @members.each do |member| %> <% user = member.user %>
  • - -
    • -
    + <%= form_tag url_for(:controller => 'syllabus_member', :action => 'create', :syllabus => @syllabus),:id => 'syllabus_member_add_form', :remote => true do |f|%>
      -
    - <% end %> + 双击添加成员 + 双击删除成员 + <% end %>
    该用户已添加至右侧列表 确定 diff --git a/app/views/syllabuses/_courses_list.html.erb b/app/views/syllabuses/_courses_list.html.erb new file mode 100644 index 000000000..027a1a05a --- /dev/null +++ b/app/views/syllabuses/_courses_list.html.erb @@ -0,0 +1,14 @@ +<% if !courses.blank? %> + <% courses.each_with_index do |course, i| %> + <% allow_visit = course.is_delete == 0 && (User.current.member_of_course?(course) || User.current.admin? || course.is_public == 1) %> +
  • + +
  • + <% end %> +<% end %> \ No newline at end of file diff --git a/app/views/syllabuses/_delete_syllabus.html.erb b/app/views/syllabuses/_delete_syllabus.html.erb index cdcfbb1b6..632dcddc3 100644 --- a/app/views/syllabuses/_delete_syllabus.html.erb +++ b/app/views/syllabuses/_delete_syllabus.html.erb @@ -1,25 +1,29 @@ -
    -
    -

    删除课程

    - -
    +
    +
    +

    提示

    + + +
    -
    - <% if @syllabus.courses.not_deleted.empty? %> - 确认删除该课程吗? - <% else %> - 该课程下已经存在班级,不能删除。 - <% end %> +
    +

    + <% if @syllabus.courses.not_deleted.empty? %> + 确认删除该课程吗? + <% else %> + 该课程下已经存在班级,不能删除。 + <% end %> +

    -
    <% if @syllabus.courses.not_deleted.empty? %> - 取消 - <%=link_to '确认', syllabus_path(@syllabus), :class => 'sy_btn_blue fl', :method => 'delete'%> +
    + 取消 + <%=link_to '确认', syllabus_path(@syllabus), :class => 'task-btn task-btn-blue fr', :method => 'delete'%> +
    <% else %> - 确定 +
    + 确定 +
    <% end %> -
    -
    \ No newline at end of file diff --git a/app/views/syllabuses/_join_syllabuses.html.erb b/app/views/syllabuses/_join_syllabuses.html.erb new file mode 100644 index 000000000..99c74ac56 --- /dev/null +++ b/app/views/syllabuses/_join_syllabuses.html.erb @@ -0,0 +1,54 @@ +<% if @join_syllabuses.count > 0 %> + <% @join_syllabuses.each_with_index do |syllabus, index|%> + <% course_count = @status == 1 ? syllabus.courses.where("is_delete = 0 and is_end = 0").count : syllabus.courses.where("is_delete = 0 and is_end = 1").count %> + <% if !(@status == 2 && course_count == 0) %> +
    +
    + <%= syllabus.title.strip() %> + <%= format_time syllabus.updated_at %> 更新 +
    + +
    + +
      +
    • <%= link_to "新建班级", new_course_path(:syllabus_id => syllabus.id), :target => '_blank', :title => "新建班级"%>
    • +
    • <%= link_to '查看课程', syllabus_path(syllabus.id), :target =>'_blank', :title => '查看课程' %>
    • +
    • + <% if User.current == syllabus.user || User.current.admin? %> + <%= link_to '删除课程', delete_syllabus_syllabus_path(syllabus), :remote => 'true' %> + <% end %> +
    • +
    +
    +
    +
      + <% if @status == 1 %> + <% courses = syllabus.courses.where("is_delete = 0 and is_end = 0").select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS updatetime").order("updatetime desc") %> + <% else %> + <% courses = syllabus.courses.where("is_delete = 0 and is_end = 1").select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS updatetime").order("updatetime desc") %> + <% end %> + <%= render :partial => 'syllabuses/courses_list', :locals => { :courses => courses, :syllabus => syllabus} %> +
    + <% end %> + <% end %> +<% else %> + <%= render :partial => 'welcome/no_data' %> +<% end %> diff --git a/app/views/syllabuses/_my_syllabuses.html.erb b/app/views/syllabuses/_my_syllabuses.html.erb new file mode 100644 index 000000000..2ae67576a --- /dev/null +++ b/app/views/syllabuses/_my_syllabuses.html.erb @@ -0,0 +1,54 @@ +<% if @my_syllabuses.count > 0 %> + <% @my_syllabuses.each_with_index do |syllabus, index|%> + <% course_count = @status == 1 ? syllabus.courses.where("is_delete = 0 and is_end = 0").count : syllabus.courses.where("is_delete = 0 and is_end = 1").count %> + <% if !(@status == 2 && course_count == 0) %> +
    +
    + <%= syllabus.title.strip() %> + <%= format_time syllabus.updated_at %> 更新 +
    + +
    + +
      +
    • <%= link_to "新建班级", new_course_path(:syllabus_id => syllabus.id), :target => '_blank', :title => "新建班级"%>
    • +
    • <%= link_to '查看课程', syllabus_path(syllabus.id), :target =>'_blank', :title => '查看课程' %>
    • +
    • + <% if User.current == syllabus.user || User.current.admin? %> + <%= link_to '删除课程', delete_syllabus_syllabus_path(syllabus), :remote => 'true' %> + <% end %> +
    • +
    +
    +
    +
      + <% if @status == 1 %> + <% courses = syllabus.courses.where("is_delete = 0 and is_end = 0").select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS updatetime").order("updatetime desc") %> + <% else %> + <% courses = syllabus.courses.where("is_delete = 0 and is_end = 1").select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS updatetime").order("updatetime desc") %> + <% end %> + <%= render :partial => 'syllabuses/courses_list', :locals => { :courses => courses, :syllabus => syllabus} %> +
    + <% end %> + <% end %> +<% else %> + <%= render :partial => 'welcome/no_data' %> +<% end %> \ No newline at end of file diff --git a/app/views/syllabuses/_search_course_list.html.erb b/app/views/syllabuses/_search_course_list.html.erb index d8fbfbec3..8f03f9c05 100644 --- a/app/views/syllabuses/_search_course_list.html.erb +++ b/app/views/syllabuses/_search_course_list.html.erb @@ -2,8 +2,8 @@ <% @courses.each do |course| %>
  • <% end %> diff --git a/app/views/syllabuses/_show_ref.html.erb b/app/views/syllabuses/_show_ref.html.erb index d51ed74fb..5578dee12 100644 --- a/app/views/syllabuses/_show_ref.html.erb +++ b/app/views/syllabuses/_show_ref.html.erb @@ -1,6 +1,6 @@

    参考资料

    - <% if @is_syllabus_member %> + <% if @is_syllabus_admin %> <% end %>
    diff --git a/app/views/syllabuses/_syllabus_course_list.html.erb b/app/views/syllabuses/_syllabus_course_list.html.erb index 7ffb2b24f..e0d62ed6c 100644 --- a/app/views/syllabuses/_syllabus_course_list.html.erb +++ b/app/views/syllabuses/_syllabus_course_list.html.erb @@ -37,7 +37,7 @@
    - + <% if User.current.admin? || User.current.allowed_to?(:as_teacher,course) %> <% homework_num = course.homework_commons.count %> <% else %> @@ -47,7 +47,7 @@ <% if (course.is_public == 0 && !User.current.member_of_course?(course)) || @list_type == 1 %> <%=homework_num %> <% else %> - <%= link_to homework_num, homework_common_index_path(:course => course.id), :class => "sy_cblue",:target => '_blank'%> + <%= link_to homework_num, homework_common_index_path(:course => course.id, :homework_type => 1), :class => "sy_cblue",:target => '_blank'%> <% end %> 资源: diff --git a/app/views/syllabuses/_syllabus_des.html.erb b/app/views/syllabuses/_syllabus_des.html.erb index 61250b06f..43262147d 100644 --- a/app/views/syllabuses/_syllabus_des.html.erb +++ b/app/views/syllabuses/_syllabus_des.html.erb @@ -1,7 +1,7 @@ -
    +
    <% if @syllabus.des_status == 1 %> - <% if @is_syllabus_member %> - + <% if @is_syllabus_admin %> +
    <% end %>
    @@ -10,11 +10,11 @@ <% else %>

    - 还没有<% if @is_syllabus_member %>添加<% else %>添加<% end %>授课大纲 ~

    + 还没有<% if @is_syllabus_admin %>添加<% else %>添加<% end %>授课大纲 ~

    <% end %>
    -
    - +
    + <%= labelled_form_for @syllabus, :url =>update_des_syllabus_path(@syllabus), :html => {:nhname=>'form',:multipart => true, :method => 'post', :id => 'syllabus-des-form'} do |f| %> diff --git a/app/views/syllabuses/_syllabus_homeworks.html.erb b/app/views/syllabuses/_syllabus_homeworks.html.erb index 81128678f..aa177e9be 100644 --- a/app/views/syllabuses/_syllabus_homeworks.html.erb +++ b/app/views/syllabuses/_syllabus_homeworks.html.erb @@ -1,4 +1,4 @@ -
    +
    <% if @homework_count == 0 %>

    还没有添加课程题库 ~

    @@ -15,38 +15,63 @@ <%= form_tag(choose_user_course_syllabus_path(@syllabus), :id => 'sy_search_course_h_form', :remote => true, :method => 'post') do %> - <% @homeworks.each do |homework| %> -
      - - -
      -

      - <%= homework.name %> -

      - -
      -

      - <%= link_to homework.user.show_name, user_path(homework.user), :class => 'link-name-dark fl' %> - 创建于 - <%= format_time homework.created_at %> - 类别:<%= homework.homework_type_ch %> - 引用数:<%= homework.quotes %> -

      -
      -
      -
    + <% if @is_syllabus_teacher || @is_authen_teacher %> + <% @homeworks.each do |homework| %> +
      + + +
      +

      + <%= link_to homework.name, homework_bank_path(homework), :target => '_blank' %> +

      + +
      +

      + <%= link_to homework.user.show_real_name, user_path(homework.user), :class => 'link-name-dark fl' %> + 创建于 + <%= format_time homework.created_at %> + <%= homework.homework_type_ch %>作业 + <%= homework.quotes %>引用 +

      +
      +
      +
    + <% end %> + <% else %> + <% @homeworks.each do |homework| %> +
      +
      +

      + <%= link_to homework.name, homework_bank_path(homework), :target => '_blank' %> +

      + +
      +

      + <%= link_to homework.show_real_name_name, user_path(homework.user), :class => 'link-name-dark fl' %> + 创建于 + <%= format_time homework.created_at %> + <%= homework.homework_type_ch %>作业 + <%= homework.quotes %>引用 +

      +
      +
      +
    + <% end %> <% end %> <% end %> -
      +
        -
        - 发送 - -
        -
        + <% if @is_syllabus_teacher || @is_authen_teacher %> +
        + 发送 + +
        + <% end %> + +
          - <%= pagination_links_full @homework_pages, @homework_count, :per_page_links => false, :remote => @is_remote, :flag => true, :is_new => true%> + <%= pagination_links_full @homework_pages, @page_homework_count, :per_page_links => false, :remote => @is_remote, :flag => true, :is_new => true%>
        diff --git a/app/views/syllabuses/_syllabus_member_list.html.erb b/app/views/syllabuses/_syllabus_member_list.html.erb index 685342241..40e486ebc 100644 --- a/app/views/syllabuses/_syllabus_member_list.html.erb +++ b/app/views/syllabuses/_syllabus_member_list.html.erb @@ -21,14 +21,14 @@ <%= member.rank %> <% if user == @syllabus.user %> -
        <%= user.show_name %>创建者
        +
        <%= user.show_real_name %>创建者
        <% else %> - <%= user.show_name %> + <%= show_real_name_name %> <% end %> <% if user.user_extensions && user.user_extensions.identity %> - <%= get_user_roll user %> + <%= user.identity %> <% end%> <% courses = user.courses.not_deleted %> diff --git a/app/views/syllabuses/_syllabus_members.html.erb b/app/views/syllabuses/_syllabus_members.html.erb index 70dd146ed..afce4c833 100644 --- a/app/views/syllabuses/_syllabus_members.html.erb +++ b/app/views/syllabuses/_syllabus_members.html.erb @@ -1,23 +1,34 @@ -<% @members.each do |member| %> -
        +<% @members.each_with_index do |member, index| %> +
        <% user = member.user %> <%= link_to image_tag(url_to_avatar(user), :width => "100", :height => "100", :alt => "头像"), user_path(user), :target => '_blank', :class => "fl edu-class-user-img ml15 mr15" %>
          -
        • <%= link_to user.show_name, user_path(user), :class => "font-16 mt5 link-name-dark task-hide" %>
        • +
        • + <%= link_to user.show_real_name, user_path(user), :class => "font-16 link-name-dark task-hide fl" %> + <% if user == @syllabus.user %> + + <% end %> +
        • <%= user.user_extensions.user_technical_title %> +
        • +
        • <% if user == @syllabus.user && (User.current == @syllabus.user || User.current.admin?) %> <% if @members.count == 1 %> - 更换管理员 + 更换管理员 <% else %> - <%= link_to '更换管理员', change_manager_alert_syllabus_member_index_path(:syllabus => @syllabus), :class => 'font-12 ml15 link-color-grey', :remote => true %> + <%= link_to '更换管理员', change_manager_alert_syllabus_member_index_path(:syllabus => @syllabus), :class => 'font-12 link-color-grey', :remote => true %> <% end %> - <% elsif user == @syllabus.user %> - <% elsif user != @syllabus.user && @is_syllabus_member %> - 删除 + 删除 <% end %>
        + <% if index == 10 %> + + + 查看全部 + + <% end %> <% end %> \ No newline at end of file diff --git a/app/views/syllabuses/_syllabus_resources.html.erb b/app/views/syllabuses/_syllabus_resources.html.erb index 41d571a7e..d41450821 100644 --- a/app/views/syllabuses/_syllabus_resources.html.erb +++ b/app/views/syllabuses/_syllabus_resources.html.erb @@ -1,4 +1,4 @@ -
        +
        <% if @resource_count == 0 %>

        还没有添加课程资源库 ~

        @@ -15,41 +15,68 @@ <%= form_tag(choose_user_course_syllabus_path(@syllabus), :id => 'sy_search_course_form', :remote => true, :method => 'post') do %> - <% @resources.each do |resource| %> -
          - - -
          -

          - <%= link_to resource.filename, download_resource_attachment_path(resource.id, resource.filename, :type => 'syllabus'), :title => resource.filename %> -

          - <% unless resource.is_public %> - + <% if @is_syllabus_teacher || @is_authen_teacher %> + <% @resources.each do |resource| %> +
            + + +
            +

            + <%= link_to resource.filename, download_resource_attachment_path(resource.id, resource.filename, :type => 'syllabus'), :title => resource.filename %> +

            + <% unless resource.is_public %> + + <% end %> +
            +

            + <%= link_to resource.user.show_real_name, user_path(resource.user), :class => 'link-name-dark fl' %> + 上传于 + <%= format_time resource.created_at %> + 大小:<%= (number_to_human_size(resource.filesize)).gsub("ytes", "") %> + 下载数:<%= resource.downloads %> + 引用数:<%= resource.quotes %> +

            +
            +
            +
          <% end %> -
          -

          - <%= link_to resource.user.show_name, user_path(resource.user), :class => 'link-name-dark fl' %> - 上传于 - <%= format_time resource.created_at %> - 大小:<%= (number_to_human_size(resource.filesize)).gsub("ytes", "") %> - 下载数:<%= resource.downloads %> - 引用数:<%= resource.quotes %> -

          -
          -
          -
        + <% else %> + <% @resources.each do |resource| %> +
          +
          +

          + <%= link_to resource.filename, download_resource_attachment_path(resource.id, resource.filename, :type => 'syllabus'), :title => resource.filename %> +

          + <% unless resource.is_public %> + + <% end %> +
          +

          + <%= link_to resource.show_real_name_name, user_path(resource.user), :class => 'link-name-dark fl' %> + 上传于 + <%= format_time resource.created_at %> + 大小:<%= (number_to_human_size(resource.filesize)).gsub("ytes", "") %> + 下载数:<%= resource.downloads %> + 引用数:<%= resource.quotes %> +

          +
          +
          +
        + <% end %> + <% end %> <% end %> - <% end %> -
          +
            -
            - 发送 - -
            + <% if @is_syllabus_teacher || @is_authen_teacher %> +
            + 发送 + +
            + <% end %>
              - <%= pagination_links_full @resource_pages, @resource_count, :per_page_links => false, :remote => @is_remote, :flag => true, :is_new => true%> + <%= pagination_links_full @resource_pages, @page_resource_count, :per_page_links => false, :remote => @is_remote, :flag => true, :is_new => true%>
            diff --git a/app/views/syllabuses/edit.html.erb b/app/views/syllabuses/edit.html.erb index 245ebc850..6af31363b 100644 --- a/app/views/syllabuses/edit.html.erb +++ b/app/views/syllabuses/edit.html.erb @@ -1,7 +1,7 @@

            - <%= link_to User.current.show_name, user_path(User.current) %> > <%= link_to '智能课堂', user_course_community_path(User.current) %> + <%= link_to User.current.show_real_name, user_path(User.current) %> > <%= link_to '实训课堂', courses_path %>

            编辑课程

            @@ -33,16 +33,22 @@
            请选择课程所属一级学科 +
          • + + <%= select_tag :major_id,options_for_select(syllabus_major_option(@syllabus.first_level_discipline_id),@syllabus.major_id), {:id=>"major_id", :class=>"fl task-height-40 task-form-80"} %> +
            + 请选择课程所属专业 +
          • - +
            课程名称不能为空且至少有两个字符 同一个用户不能创建同名课程
          • - +
          • diff --git a/app/views/syllabuses/index.html.erb b/app/views/syllabuses/index.html.erb new file mode 100644 index 000000000..a51fdb527 --- /dev/null +++ b/app/views/syllabuses/index.html.erb @@ -0,0 +1,66 @@ +
            +

            + <%= link_to User.current.show_real_name, user_path(User.current) %> > <%= link_to '实训课堂', courses_path() %> > 我的课堂 +

            +
            +
            +
            + +
            + +
            +
            +

            + 正在进行 + 已结束 +

            +
            + <%= render :partial => "syllabuses/my_syllabuses" %> +
            +
            +
            + +
            +

            + 正在进行 + 已结束 +

            +
            +
            + <%= render :partial => "syllabuses/join_syllabuses" %> +
            +
            +
            +
            +
            +
            +
            +
            + diff --git a/app/views/syllabuses/index.js.erb b/app/views/syllabuses/index.js.erb new file mode 100644 index 000000000..0539df6fa --- /dev/null +++ b/app/views/syllabuses/index.js.erb @@ -0,0 +1,5 @@ +<% if params[:tab].to_i == 1 %> + $("#my_syllabuses").html("<%= j( render :partial => "syllabuses/my_syllabuses") %>"); +<% elsif params[:tab].to_i == 2 %> + $("#join_syllabuses").html("<%= j( render :partial => "syllabuses/join_syllabuses") %>"); +<% end %> diff --git a/app/views/syllabuses/new.html.erb b/app/views/syllabuses/new.html.erb index 18e13475d..eb1c6faff 100644 --- a/app/views/syllabuses/new.html.erb +++ b/app/views/syllabuses/new.html.erb @@ -1,7 +1,7 @@

            - <%= link_to User.current.show_name, user_path(User.current) %> > <%= link_to '智能课堂', user_course_community_path(User.current) %> + <%= link_to User.current.show_real_name, user_path(User.current) %> > <%= link_to '实训课堂', courses_path %>

            新建课程

            @@ -29,10 +29,16 @@
          • - <%= select_tag :first_level_discipline_id,options_for_select(first_level_discipline_option,@syllabus.first_level_discipline_id), {:id=>"first_level_discipline_id", :class=>"fl task-height-40 task-form-80"} %> + <%= select_tag :first_level_discipline_id,options_for_select(first_level_discipline_option,@syllabus.first_level_discipline_id), {:id=>"first_level_discipline_id", :class=>"fl task-height-40 task-form-80"} %>
            请选择课程所属一级学科
          • +
          • + + <%= select_tag :major_id,options_for_select(syllabus_major_option,@syllabus.major_id), {:id=>"major_id", :class=>"fl task-height-40 task-form-80"} %> +
            + 请选择课程所属专业 +
          • diff --git a/app/views/syllabuses/search_not_sy_member.js.erb b/app/views/syllabuses/search_not_sy_member.js.erb index 71d0d47d8..113513fc5 100644 --- a/app/views/syllabuses/search_not_sy_member.js.erb +++ b/app/views/syllabuses/search_not_sy_member.js.erb @@ -1,8 +1,8 @@ $("#add_member_search_ul").empty(); <% if @users.count > 0 %> <% @users.each do |user|%> - var link = "
          • " + - "<%=user.show_name %>(<%= user.login %>)
            " + + var link = "
          • " + + "<%=show_real_name_name %>(<%= user.login %>)
            " + "<%= user.user_extensions.user_technical_title %>" + "<%= user.user_extensions.school ? user.user_extensions.school.name : "" %>
          • "; $("#add_member_search_ul").append(link); @@ -12,9 +12,9 @@ $("#add_member_search_ul").empty(); $("#sy_add_member_notice").show(); } else{ $("#sy_add_member_notice").hide(); - var li = "
          • " + + var li = "
          • (<%= user.login %>)'>" + "" + - "<%=user.show_name %>(<%= user.login %>)
            " + + "(<%= user.login %>)
            " + "<%= user.user_extensions.user_technical_title %>" + "<%= user.user_extensions.school ? user.user_extensions.school.name : "" %>
          • "; $("#add_member_choose_ul").append(li); diff --git a/app/views/syllabuses/show.html.erb b/app/views/syllabuses/show.html.erb index 294064ba0..3a2135910 100644 --- a/app/views/syllabuses/show.html.erb +++ b/app/views/syllabuses/show.html.erb @@ -6,59 +6,68 @@

            - <%= link_to User.current.show_name, user_path(User.current) %> > <%= link_to '智能课堂', user_course_community_path(User.current) %> > <%= @syllabus.title %>

            -
            -
            + <%= link_to User.current.show_real_name, user_path(User.current) %> > <%= link_to '实训课堂', courses_path %> > <%= @syllabus.title %>

            +
            + <% if !(@is_syllabus_admin || @is_syllabus_member) %> +
            + + +

            + 私有资源和题库:
            仅对本课程的班级成员可见

            公共资源和题库:
            对所有用户可见 +

            +
            + <% end %> +
            - + + <% if @is_syllabus_teacher || @is_authen_teacher %> + <%= link_to '选用', choose_user_course_syllabus_path(@syllabus, :type => 'A'), :class => 'task-btn task-btn-blue fr ml20', :style => '', :remote => true %> <% end %>
            +
            -
            +
              -
            • +
            • 授课大纲 -
            • - <% if @is_syllabus_member %> -
            • - <%= link_to '课程资源库', syllabus_resources_syllabus_path(@syllabus), :remote => true, :class => 'tab_type' %> - -
            • -
            • - <%= link_to '课程题库', syllabus_homeworks_syllabus_path(@syllabus), :remote => true, :class => 'tab_type' %> - -
            • - <% end %> +
            • + <%= link_to '课程资源库', syllabus_resources_syllabus_path(@syllabus), :remote => true, :class => 'tab_type' %> +
            • +
            • + <%= link_to '课程题库', syllabus_homeworks_syllabus_path(@syllabus), :remote => true, :class => 'tab_type' %> +
            @@ -81,9 +90,15 @@
            -
            +

            教师团队

            + <% if @is_syllabus_admin %> + + + 添加教师 + + <% end %>
            分享
            @@ -94,20 +109,15 @@
            -
            +
            <%= render :partial => "syllabus_members" %>
            - <% if @is_syllabus_member %> - - - 添加 - - <% end %> +
            -
            +

            班级列表

            - 正在进行 + 正在进行
              <% if @courses.count == 0 %> @@ -121,14 +131,14 @@ <% end %> <% end %>
            - <% if @is_syllabus_member %> - + <% if @is_syllabus_admin %> + - 新建 + 新建班级 <% end %>
            -
            +

            班级列表

            已结束 @@ -186,5 +196,10 @@ }); autoUrl('syllabus_description_<%= @syllabus.id %>'); }); + + function show_all_members(ele){ + $(".sy_member_div").show(); + $(ele).hide(); + } diff --git a/app/views/syllabuses/syllabus_homeworks.js.erb b/app/views/syllabuses/syllabus_homeworks.js.erb index 8e5dfc8a1..7d7684ab6 100644 --- a/app/views/syllabuses/syllabus_homeworks.js.erb +++ b/app/views/syllabuses/syllabus_homeworks.js.erb @@ -3,5 +3,5 @@ document.getElementById('edu-tab-nav-1').className='edu-tab-nomal'; document.getElementById('edu-tab-nav-2').className='edu-tab-nomal'; document.getElementById('edu-tab-con-1').className='undis'; document.getElementById('edu-tab-con-2').className='undis'; -document.getElementById('edu-tab-nav-3').className='edu-tab-hover'; +document.getElementById('edu-tab-nav-3').className='edu-new-tab-hover'; document.getElementById('edu-tab-con-3').className='dis'; diff --git a/app/views/syllabuses/syllabus_resources.js.erb b/app/views/syllabuses/syllabus_resources.js.erb index 9cc6a616c..c5e76fc05 100644 --- a/app/views/syllabuses/syllabus_resources.js.erb +++ b/app/views/syllabuses/syllabus_resources.js.erb @@ -3,5 +3,5 @@ document.getElementById('edu-tab-nav-1').className='edu-tab-nomal'; document.getElementById('edu-tab-nav-3').className='edu-tab-nomal'; document.getElementById('edu-tab-con-1').className='undis'; document.getElementById('edu-tab-con-3').className='undis'; -document.getElementById('edu-tab-nav-2').className='edu-tab-hover'; +document.getElementById('edu-tab-nav-2').className='edu-new-tab-hover'; document.getElementById('edu-tab-con-2').className='dis'; diff --git a/app/views/users/_comment_reply_detail.html.erb b/app/views/users/_comment_reply_detail.html.erb index e7cd7e0b0..4461fc454 100644 --- a/app/views/users/_comment_reply_detail.html.erb +++ b/app/views/users/_comment_reply_detail.html.erb @@ -8,7 +8,7 @@ });
            - <%= link_to comment.creator_user.show_name, user_path(comment.creator_user), :class => "content-username" %> + <%= link_to comment.creator_user.show_real_name, user_path(comment.creator_user), :class => "content-username" %> <%= time_from_now(comment.respond_to?(:created_on) ? comment.created_on : comment.created_at) %>
            <% if comment.class == Journal %> @@ -64,6 +64,6 @@
            -

            +
            \ No newline at end of file diff --git a/app/views/users/_contest_newslist.html.erb b/app/views/users/_contest_newslist.html.erb index 4c9d7377c..354d5a996 100644 --- a/app/views/users/_contest_newslist.html.erb +++ b/app/views/users/_contest_newslist.html.erb @@ -1,6 +1,6 @@
            -
            +

            通知列表

            排序: diff --git a/app/views/users/_contest_work.html.erb b/app/views/users/_contest_work.html.erb index 95e1786bf..357f05cb8 100644 --- a/app/views/users/_contest_work.html.erb +++ b/app/views/users/_contest_work.html.erb @@ -17,10 +17,10 @@ <%= link_to activity.contest.name.to_s+" | 竞赛提交", works_path(:contest => activity.contest.id), :class => "newsBlue ml15"%> <% end %>
            -
        <% end %> \ No newline at end of file diff --git a/app/views/users/_course_homework.html.erb b/app/views/users/_course_homework.html.erb index b465e30b3..3548ff2aa 100644 --- a/app/views/users/_course_homework.html.erb +++ b/app/views/users/_course_homework.html.erb @@ -1,5 +1,5 @@ <% is_teacher = User.current.allowed_to?(:as_teacher,activity.course) %> -
        +
        <%= link_to image_tag(url_to_avatar(activity.user), :width => "50", :height => "50"), user_path(activity.user), :alt => "用户头像" %> @@ -7,23 +7,30 @@
        - <%= link_to activity.user.show_name, user_path(activity.user,:host=>Setting.host_user), :class => "newsBlue mr15" %> + <%= link_to activity.user.show_real_name, user_path(activity.user,:host=>Setting.host_user), :class => "newsBlue mr15" %> TO <% if hw_status == 3 || hw_status == 2 %> - <%= link_to "班级作业", homework_common_index_path(:course => activity.course.id, :host=> Setting.host_course), :class => "newsBlue ml15"%> + <%= link_to "#{activity.homework_type_ch}作业", homework_common_index_path(:course => activity.course.id, :host=> Setting.host_course, :homework_type => activity.homework_type), :class => "newsBlue ml15"%> <% else %> - <%= link_to activity.course.name.to_s+" | 班级作业", homework_common_index_path(:course => activity.course.id, :host=> Setting.host_course), :class => "newsBlue ml15"%> + <%= link_to activity.course.name.to_s+" | #{activity.homework_type_ch}作业", homework_common_index_path(:course => activity.course.id, :host=> Setting.host_course, :homework_type => activity.homework_type), :class => "newsBlue ml15"%> <% end %>
        -