diff --git a/app/controllers/challenges_controller.rb b/app/controllers/challenges_controller.rb index 58b43a737..953a3575f 100644 --- a/app/controllers/challenges_controller.rb +++ b/app/controllers/challenges_controller.rb @@ -2,12 +2,12 @@ class ChallengesController < ApplicationController layout "base_shixun" before_filter :check_authentication - 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 :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 @@ -26,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! @@ -53,6 +60,7 @@ class ChallengesController < ApplicationController raise ActiveRecord::Rollback end end +=end end # 处理新建challenge返回的pipeline片段 @@ -84,6 +92,8 @@ class ChallengesController < ApplicationController end def edit + @tab = params[:tab].blank? ? 1 : params[:tab].to_i + @editor = params[:editor] # 编辑模式 end def destroy @@ -94,6 +104,9 @@ 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| ActiveRecord::Base.transaction do @challenge.update_attributes(params[:challenge]) @@ -123,6 +136,40 @@ class ChallengesController < ApplicationController 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 + # 向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 diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index a974abce7..84f445f53 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -44,22 +44,29 @@ class CoursesController < ApplicationController @user = User.current @search = params[:search].nil? ? '' : params[:search] @select = params[:select].nil? ? '' : params[:select] - # 全部课堂 + @is_end = params[:is_end].nil? ? 0 : params[:is_end].to_i #是否归档 + @syllabuses_num = Course.where("is_end = 0 and is_delete = 0").count - all_syllabuses = Course.where("is_end = 0 and is_delete = 0 and name like '%#{@search}%'").order("created_at desc") - # 我参与的课堂 - join_syllabuses = @user.courses.where("is_end = 0 and is_delete = 0 and tea_id != #{@user.id} and name like '%#{@search}%'").order("created_at desc") + #@syllabus_count = all_syllabuses.count # 我创建的课堂 - create_syllabuses = Course.where(:tea_id => @user.id).where("is_end = 0 and is_delete = 0 and name like '%#{@search}%'").order("created_at desc") - @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 @select == "create" @syllabuses = create_syllabuses 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 diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 5157197e4..13aa8349e 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -200,8 +200,15 @@ class ShixunsController < ApplicationController shixun_ids = Myshixun.where(:user_id => User.current, :status => 1).map(&:shixun_id) @shixuns = @shixuns.where(:id => shixun_ids) end - @shixuns = @shixuns.reorder(order_str) - + 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 @@ -577,6 +584,7 @@ class ShixunsController < ApplicationController @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 diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 10064d77b..da7c72a84 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -45,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, - :shixuns, :user_show_course_list] + :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 @@ -2030,6 +2030,7 @@ class UsersController < ApplicationController @user_fanlist_count = fan_query.count(); @user_fanlist = fan_query.order("#{Watcher.table_name}.id desc").limit(12); +=begin # 合作者及创建者 ids = Shixun.find_by_sql("select shixun_id from shixun_members where user_id=#{@user.id}") # 已挑战过 @@ -2038,12 +2039,13 @@ class UsersController < ApplicationController ids2 = ids2.map{|shixun| shixun.id} unless ids2.blank? id = ids + ids2 id = id.uniq +=end if @user == User.current - @shixuns = Shixun.where(:id => id).order("created_at desc") + @shixuns = Shixun.where(:user_id => @user).order("created_at desc") else - @shixuns = Shixun.where(:status => [2, 3], :id => id).order("created_at desc") + @shixuns = Shixun.where(:status => [2, 3], :id => @user).order("created_at desc") end - @limit = 8 + @limit = 5 @is_remote = true @shixuns_count = @shixuns.count @shixuns_pages = Paginator.new @shixuns_count, @limit, params['page'] || 1 @@ -2193,11 +2195,67 @@ 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], :id => @user).order("created_at desc") + end + elsif params[:filter] == "cooperative" + # 合作者及创建者 + ids = Shixun.find_by_sql("select shixun_id from shixun_members where user_id=#{@user.id}") + ids = ids.map{|shixun| shixun.shixun_id} unless ids.blank? + # 我创建的id + create_id = Shixun.where(:user_id => @user).pluck(:id) + id = ids - create_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 + 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") + 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 + @courses = @user.courses.not_deleted_not_end.where(:tea_id => @user.id).order("updated_at desc") @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 + @limit = 5 @is_remote = true @courses_pages = Paginator.new @courses_count, @limit, params['page'] || 1 @offset ||= @courses_pages.offset diff --git a/app/models/challenge.rb b/app/models/challenge.rb index e37a91360..82b776c86 100644 --- a/app/models/challenge.rb +++ b/app/models/challenge.rb @@ -9,7 +9,7 @@ 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 diff --git a/app/models/myshixun.rb b/app/models/myshixun.rb index e6692381a..5e57b85e9 100644 --- a/app/models/myshixun.rb +++ b/app/models/myshixun.rb @@ -58,9 +58,9 @@ 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} + passed_games = games.select{|game| game.status == 2} current_game = passed_games.first end return current_game diff --git a/app/views/challenges/_answer_form.html.erb b/app/views/challenges/_answer_form.html.erb new file mode 100644 index 000000000..9e7ed5cde --- /dev/null +++ b/app/views/challenges/_answer_form.html.erb @@ -0,0 +1,77 @@ +<%= stylesheet_link_tag '/editormd/css/editormd','/editormd/css/editormd.min.css' %> +<%= javascript_include_tag '/editormd/editormd.min.js','/editormd/examples/js/jquery.min.js' %> + +
+ \ No newline at end of file diff --git a/app/views/challenges/_edit_answer.html.erb b/app/views/challenges/_edit_answer.html.erb new file mode 100644 index 000000000..1d4df206e --- /dev/null +++ b/app/views/challenges/_edit_answer.html.erb @@ -0,0 +1,41 @@ ++ <% if @shixun.status == 0 && User.current.manager_of_shixun?(@shixun) %> + 编辑 + <% end %> +
++ <% if @shixun.status == 0 && User.current.manager_of_shixun?(@shixun) %> + 编辑 + <% end %> +
++ 测试集<%= index + 1 %> + <% if test.is_public? %> + + <% else %> + + <% end %> +
+<%= test.input.gsub("\r\n", "
").html_safe unless test.input.blank? %>
<%= test.output.gsub("\r\n", "
").html_safe unless test.output.blank? %>
+ <% if @shixun.status == 0 && User.current.manager_of_shixun?(@shixun) %> + 编辑 + <% end %> +
++ <% if @shixun.status == 0 && User.current.manager_of_shixun?(@shixun) %> + 编辑 + <% end %> +
++ <% if @shixun.status == 0 && User.current.manager_of_shixun?(@shixun) %> + 编辑 + <% end %> +
++