From a03c0f68c2ad6f4ccb27049083e468528e474529 Mon Sep 17 00:00:00 2001 From: cxt Date: Fri, 23 Dec 2016 16:58:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BD=9C=E5=93=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../contestant_works_controller.rb | 208 +++++++++++- app/controllers/student_work_controller.rb | 16 - app/helpers/application_helper.rb | 31 ++ app/models/contestant_work.rb | 5 +- app/models/contestant_work_project.rb | 2 +- app/models/contestant_work_score.rb | 2 +- .../_choose_group_member.html.erb | 125 +++++++ .../_contestant_work_attachment.html.erb | 56 ++++ .../_contestant_work_list.html.erb | 0 .../_has_commit_work.html.erb | 24 ++ .../_work_information.html.erb | 44 +++ .../_work_post_brief.html.erb | 96 ++++++ app/views/contestant_works/create.js.erb | 24 ++ app/views/contestant_works/index.html.erb | 190 +++++++++++ app/views/contestant_works/new.html.erb | 310 ++++++++++++++++++ app/views/contestant_works/retry_work.js.erb | 3 + .../search_contest_students.js.erb | 42 +++ .../student_work_project.js.erb | 2 +- config/routes.rb | 4 +- 19 files changed, 1162 insertions(+), 22 deletions(-) create mode 100644 app/views/contestant_works/_choose_group_member.html.erb create mode 100644 app/views/contestant_works/_contestant_work_attachment.html.erb create mode 100644 app/views/contestant_works/_contestant_work_list.html.erb create mode 100644 app/views/contestant_works/_has_commit_work.html.erb create mode 100644 app/views/contestant_works/_work_information.html.erb create mode 100644 app/views/contestant_works/create.js.erb create mode 100644 app/views/contestant_works/index.html.erb create mode 100644 app/views/contestant_works/new.html.erb create mode 100644 app/views/contestant_works/retry_work.js.erb create mode 100644 app/views/contestant_works/search_contest_students.js.erb diff --git a/app/controllers/contestant_works_controller.rb b/app/controllers/contestant_works_controller.rb index 50adc24b1..95df7db36 100644 --- a/app/controllers/contestant_works_controller.rb +++ b/app/controllers/contestant_works_controller.rb @@ -5,7 +5,7 @@ class ContestantWorksController < ApplicationController require 'bigdecimal' require "base64" before_filter :find_contestwork, :only => [:new, :index, :create, :new_student_work_project,:student_work_project,:cancel_relate_project, - :search_course_students,:work_canrepeat,:add_group_member,:change_project] + :delete_work,:search_contest_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] before_filter :member_of_contest, :only => [:new, :create, :show] before_filter :author_of_work, :only => [:edit, :update, :destroy] @@ -13,11 +13,80 @@ class ContestantWorksController < ApplicationController before_filter :is_logged, :only => [:index] def new + #更新消息 + noEvaluation = @contestwork.contest_messages.where("user_id =? and viewed =?", User.current.id, 0) + noEvaluation.update_all(:viewed => true) + @user = User.current + @student_work = ContestantWork.new + respond_to do |format| + format.html{ render :layout => "base_contests"} + end end def index + # 作业消息状态更新? + work_messages = ContestMessage.where(:user_id => User.current.id, :viewed => 0, :contest_message_id => @contestwork.id, :contest_message_type => "Work") + work_messages.update_all(:viewed => true) + studentwork_messages = ContestMessage.where(:user_id => User.current.id, :viewed => 0, :contest_id => @contestwork.contest, :contest_message_type => "ContestantWork") + studentwork_messages.update_all(:viewed => true) + # 作品打分消息状态更新 + #studentworks_scores = ContestMessage.where("user_id =? and contest_id =? and contest_message_type =? and viewed =?", User.current.id, @contestwork.contest, "StudentWorksScore", 0) + #studentworks_scores.update_all(:viewed => true) + # 作品评论消息状态更新 + #journals_for_teacher = ContestMessage.where("user_id =? and contest_id =? and contest_message_type =? and viewed =?", User.current.id, @contestwork.contest, "JournalsForMessage", 0) + #journals_for_teacher.update_all(:viewed => true) + ################################################################################################################## + @order,@b_sort,@name,@group = params[:order] || "score",params[:sort] || "desc",params[:name].to_s.strip || "",params[:group] + @homework_commons = @contest.works.where("publish_time <= ?",Time.now.strftime("%Y-%m-%d")).order("created_at desc") + @all_homework_commons = @contest.works.order("created_at desc") + @is_teacher = User.current.admin_of_contest?(@contest) || User.current.admin? + @is_judge = User.current.judge_of_contest?(@contest) + + @show_all = false + + if @is_teacher || @is_judge + # 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 = @contestwork.contestant_works.no_copy.select("contestant_works.*,contestant_works.work_score as score").includes(:user => {:user_extensions => []}, :project => {}, :contestant_work_scores => {}).order("#{@order} #{@b_sort}") + #end + @show_all = true + elsif User.current.member_of_contest?(@contest) + if @contestwork.work_type == 3 + pro = @contestwork.contestant_work_projects.where(:user_id => User.current.id).first + if pro.nil? + @stundet_works = [] + else + @stundet_works = @contestwork.contestant_works.select("contestant_works.*,contestant_works.work_score as score").where(:id => pro.contestant_work_id) + end + else + @stundet_works = @contestwork.contestant_works.select("contestant_works.*,contestant_works.work_score as score").where(:user_id => User.current.id) + end + else + render_403 + return + end + @student_work_count = @contestwork.contestant_works.has_committed.select("contestant_works.*,contestant_works.work_score as score").order("#{@order} #{@b_sort}").count + + @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] + @left_nav_type = 3 + @tab = params[:tab].to_i + respond_to do |format| + format.js + format.html + # format.xls { + # filename = "#{@contest.user.lastname.to_s + @contest.user.firstname}_#{@contest.name}_#{@contestwork.name}#{l(:excel_homework_list)}.xls" + # send_data(homework_to_xls(@stundet_works), :type => "text/excel;charset=utf-8; header=present", + # :filename => filename_for_content_disposition(filename)) + # } + end end def show @@ -25,7 +94,72 @@ class ContestantWorksController < ApplicationController end def create + # 提交作品前先判断是否已经提交 + @has_commit = false; + if hsd_committed_work?(User.current.id, @contestwork.id) + @work = ContestantWork.where("user_id =? and work_id =?", User.current.id, @contestwork.id).first + @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 + student_work = ContestantWork.find(params[:student_work_id]) if params[:student_work_id] + student_work ||= ContestantWork.new + student_work.name = params[:student_work][:name] == "#{@contestwork.name}的作品提交(可修改)" ? "#{@contestwork.name}的作品提交" : params[:student_work][:name] + student_work.description = params[:student_work][:description] + student_work.work_id = @contestwork.id + student_work.user_id = User.current.id + student_work.commit_time = Time.now + student_work.save_attachments(params[:attachments]) + render_attachment_warning_if_needed(student_work) + if @contestwork.work_type == 3 && @contestwork.work_detail_group.base_on_project + @student_work_project = @contestwork.contestant_work_projects.where("user_id = #{User.current.id}").first + student_work.project_id = @student_work_project.project_id + end + #提交作品时,计算是否迟交 + student_work.work_status = Time.parse(@contestwork.end_time.to_s).strftime("%Y-%m-%d") < Time.parse(Time.now.to_s).strftime("%Y-%m-%d") ? 2 : 1 + if student_work.save + if @contestwork.work_type == 3 + if @contestwork.work_detail_group.base_on_project + @student_work_project.contestant_work_id = student_work.id + @student_work_project.save + else + stu_project = ContestantWorkProject.new(:work_id => @contestwork.id, :contestant_work_id => student_work.id, :project_id => student_work.project_id, :user_id => student_work.user_id, :is_leader => 1, :contest_id => @contestwork.contest_id) + stu_project.save + end + members = params[:group_member_ids].split(',') + for i in 1 .. members.count-1 + stu_work = ContestantWork.new(:name => student_work.name, :description => student_work.description,:user_id =>members[i].to_i, :work_id => @contestwork.id, :project_id => student_work.project_id, :work_status => 3, :commit_time => student_work.commit_time) + if stu_work.save + stu_project = ContestantWorkProject.new(:work_id => @contestwork.id, :contestant_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, :contest_id => @contestwork.contest_id) + stu_project.save + end + end + end + @contestwork.update_column(:updated_at, Time.now) + update_contest_activity(@contestwork.class,@contestwork.id) + update_user_activity(@contestwork.class,@contestwork.id) + + contest_message = ContestMessage.new(:user_id =>User.current.id,:content=>"new",:contest_message_id=>student_work.id,:contest_id => @contest.id,:contest_message_type=>"ContestantWork", :status => 9) #作品提交记录 + contest_message.save + + @student_work = ContestantWork.where(work_id: @contestwork.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 end def edit @@ -40,6 +174,72 @@ class ContestantWorksController < ApplicationController end + def delete_work + @work = ContestantWork.where("user_id =? and work_id =?", User.current.id, @contestwork.id).first + if @work + @work.destroy + if @contestwork.work_type == 3 && @contestwork.work_detail_group.base_on_project + pros = @work.contestant_work_projects.where("is_leader = 0") + pros.each do |pro| + pro.destroy + end + project = @work.contestant_work_projects.where("is_leader = 1").first + project.update_attributes(:contestant_work_id => nil) + elsif @contestwork.work_type == 3 && !@contestwork.work_detail_group.base_on_project + @work.contestant_work_projects.each do |pro2| + pro2.destroy + end + end + end + redirect_to works_path(:contest => @contestwork.contest_id) + end + + def retry_work + if @contestwork.work_type == 3 + pros = @work.contestant_work_projects.where("is_leader = 0") + user_ids = pros.empty? ? "(-1)" : "(" + pros.map{|stu|stu.user_id}.join(",") + ")" + student_works = @contestwork.contestant_works.where("user_id in #{user_ids}") + student_works.delete_all + pros.delete_all + + project = @work.contestant_work_projects.where("is_leader = 1").first + if @contestwork.work_detail_group.base_on_project + project.update_attributes(:contestant_work_id => nil) + else + project.destroy + end + end + @work.destroy + @work.attachments.destroy_all + @work.contest_messages.destroy_all + + @student_work = ContestantWork.new + respond_to do |format| + format.js + end + end + + #查找竞赛中的参赛者 + def search_contest_students + name = "" + unless params[:name].nil? + name = params[:name] + end + if !@contestwork.work_detail_group.base_on_project + all_student_ids = "(" + @contestwork.contest.contestants.map{|student| student.student_id}.join(",") + ")" + else + pro = Project.find @contestwork.contestant_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 = @contestwork.contestant_work_projects.where("user_id=? and contestant_work_id is not null",User.current.id).first.nil? ? -1 : @contestwork.contestant_work_projects.where("user_id=?",User.current.id).first.contestant_work_id + @commit_student_ids = @contestwork.contestant_works.where("id != #{student_work_id}").map{|student| student.user_id} + @users = searchstudent_by_name all_students,name + respond_to do |format| + format.js + end + end + def new_student_work_project @user_activity_id = params[:user_activity_id].to_i @hw_status = params[:hw_status].to_i @@ -80,6 +280,12 @@ class ContestantWorksController < ApplicationController end private + def hsd_committed_work?(user, homework) + sw = ContestantWork.where("user_id =? and work_id =?", user, homework).first + sw.nil? ? result = false : result = true + result + end + #获取题目 def find_contestwork @contestwork = Work.find params[:work] diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb index 806a2e13b..92858d45b 100644 --- a/app/controllers/student_work_controller.rb +++ b/app/controllers/student_work_controller.rb @@ -1344,22 +1344,6 @@ class StudentWorkController < ApplicationController end private - def searchstudent_by_name users, name - mems = [] - if 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)) - mems << m - end - end - else - mems = users - end - mems - end - def hsd_committed_work?(user, homework) sw = StudentWork.where("user_id =? and homework_common_id =? and work_status != 0", user, homework).first sw.nil? ? result = false : result = true diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 5bb5e14d6..fd0cd6a5f 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -37,6 +37,21 @@ module ApplicationHelper # super # end + # 获取竞赛的管理人员 + def contest_managers contest + contest.contest_members.select{|cm| cm.roles.to_s.include?("ContestManager")} + end + + # 获取竞赛的评委人员 + def contest_judges contest + contest.contest_members.select{|cm| cm.roles.to_s.include?("Judge")} + end + + # 获取竞赛的参赛人员 + def contest_contestants contest + contest.contest_members.select{|cm| cm.roles.to_s.include?("Contestant")} + end + # 获取多种类型的user用户名 def user_message_username user user.try(:show_name) @@ -4022,6 +4037,22 @@ def visable_contest_work contest work_num end +def searchstudent_by_name users, name + mems = [] + if 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)) + mems << m + end + end + else + mems = users + end + mems +end + def add_reply_adapter obj, options #modify by nwb #添加对课程留言的支持 diff --git a/app/models/contestant_work.rb b/app/models/contestant_work.rb index 1922391b9..3db9dd160 100644 --- a/app/models/contestant_work.rb +++ b/app/models/contestant_work.rb @@ -2,13 +2,16 @@ class ContestantWork < ActiveRecord::Base belongs_to :work belongs_to :user belongs_to :project - attr_accessible :commit_time, :description, :is_delete, :name, :work_score, :work_status + attr_accessible :commit_time, :description, :is_delete, :name, :work_score, :work_status, :work_id, :user_id, :project_id has_many :contestant_work_projects, :dependent => :destroy has_many :contestant_work_scores, :dependent => :destroy has_many :contest_messages, :class_name =>'ContestMessage', :as => :contest_message, :dependent => :destroy has_many :attachments, :dependent => :destroy + scope :has_committed, lambda{where("work_status != 0 and work_status != 3")} + scope :no_copy, lambda{where("work_status != 3")} + after_create :act_as_message acts_as_attachable diff --git a/app/models/contestant_work_project.rb b/app/models/contestant_work_project.rb index 5142ddaad..71d53c532 100644 --- a/app/models/contestant_work_project.rb +++ b/app/models/contestant_work_project.rb @@ -4,5 +4,5 @@ class ContestantWorkProject < ActiveRecord::Base belongs_to :contestant_work belongs_to :project belongs_to :user - attr_accessible :is_leader + attr_accessible :is_leader, :contest_id, :work_id, :contestant_work_id, :project_id, :user_id end diff --git a/app/models/contestant_work_score.rb b/app/models/contestant_work_score.rb index 8b1d2aefd..b051647a6 100644 --- a/app/models/contestant_work_score.rb +++ b/app/models/contestant_work_score.rb @@ -1,5 +1,5 @@ class ContestantWorkScore < ActiveRecord::Base belongs_to :contestant_work belongs_to :user - attr_accessible :comment, :reviewer_role, :score + attr_accessible :comment, :reviewer_role, :score, :contestant_work_id, :user_id end diff --git a/app/views/contestant_works/_choose_group_member.html.erb b/app/views/contestant_works/_choose_group_member.html.erb new file mode 100644 index 000000000..51ca02d7d --- /dev/null +++ b/app/views/contestant_works/_choose_group_member.html.erb @@ -0,0 +1,125 @@ +<% if @contestwork.work_detail_group %> +
+
+
请从<%= @contestwork.work_detail_group.base_on_project ? '项目成员':'竞赛成员' %>中添加小组成员
+
+
+
+
+
+ +
+
+ +
+ +
+ + +
+
+ +<% end %> \ No newline at end of file diff --git a/app/views/contestant_works/_contestant_work_attachment.html.erb b/app/views/contestant_works/_contestant_work_attachment.html.erb new file mode 100644 index 000000000..ae88d4565 --- /dev/null +++ b/app/views/contestant_works/_contestant_work_attachment.html.erb @@ -0,0 +1,56 @@ +
+ + <% if defined?(container) && container && container.saved_attachments %> + <% container.attachments.each_with_index do |attachment, i| %> + + <%= text_field_tag("attachments[p#{i}][filename]", attachment.filename, :class => 'filename link_file', :readonly=>'readonly')%> + <%= text_field_tag("attachments[p#{i}][description]", attachment.description, :maxlength => 254, :placeholder => l(:label_optional_description), :class => 'description', :style=>"display: inline-block;") %> + <%= l(:field_is_public)%>: + <%= check_box_tag("attachments[p#{i}][is_public_checkbox]", attachment.is_public,attachment.is_public == 1 ? true : false,:class => 'is_public')%> + <%= link_to(' '.html_safe, attachment_path(attachment, :attachment_id => "p#{i}", :format => 'js'), :method => 'delete', :remote => true, :class => 'remove-upload') unless attachment.id.nil? %> + <%= hidden_field_tag "attachments[p#{i}][token]", "#{attachment.token}" %> + +
+ <% end %> + <% container.saved_attachments.each_with_index do |attachment, i| %> + + <%= text_field_tag("attachments[p#{i}][filename]", attachment.filename, :class => 'filename readonly', :readonly=>'readonly')%> + <%= text_field_tag("attachments[p#{i}][description]", attachment.description, :maxlength => 254, :placeholder => l(:label_optional_description), :class => 'description', :style=>"display: inline-block;") %> + <%= l(:field_is_public)%>: + <%= check_box_tag("attachments[p#{i}][is_public_checkbox]", attachment.is_public,attachment.is_public == 1 ? true : false,:class => 'is_public')%> + <%= link_to(' '.html_safe, attachment_path(attachment, :attachment_id => "p#{i}", :format => 'js'), :method => 'delete', :remote => true, :class => 'remove-upload') unless attachment.id.nil? %> + <%= hidden_field_tag "attachments[p#{i}][token]", "#{attachment.token}" %> + +
+ <% end %> + <% end %> +
+ <%= file_field_tag 'attachments[dummy][file]', + :id => '_file', + :class => ie8? ? '' : 'file_selector', + :multiple => true, + :onchange => 'addInputFiles(this);', + :style => ie8? ? '' : 'display:none', + :data => { + :max_file_size => Setting.attachment_max_size.to_i.kilobytes, + :max_file_size_message => l(:error_attachment_too_big, :max_size => number_to_human_size(Setting.attachment_max_size.to_i.kilobytes)), + :max_concurrent_uploads => Redmine::Configuration['max_concurrent_ajax_uploads'].to_i, + :upload_path => uploads_path(:format => 'js',:project =>nil), + :description_placeholder => l(:label_optional_description), + :field_is_public => l(:field_is_public), + :are_you_sure => l(:text_are_you_sure), + :file_count => l(:label_file_count), + :lebel_file_uploding => l(:lebel_file_uploding), + :delete_all_files => l(:text_are_you_sure_all) + } %> +
+
+ +
+ + 上传附件 +
+ +<% content_for :header_tags do %> + <%= javascript_include_tag 'attachments' %> +<% end %> \ No newline at end of file diff --git a/app/views/contestant_works/_contestant_work_list.html.erb b/app/views/contestant_works/_contestant_work_list.html.erb new file mode 100644 index 000000000..e69de29bb diff --git a/app/views/contestant_works/_has_commit_work.html.erb b/app/views/contestant_works/_has_commit_work.html.erb new file mode 100644 index 000000000..bbfc6e042 --- /dev/null +++ b/app/views/contestant_works/_has_commit_work.html.erb @@ -0,0 +1,24 @@ +
+
+

您已提交过作品,请不要重复提交,如果想修改作品请点击编辑。

+
+ +
+
+ + \ No newline at end of file diff --git a/app/views/contestant_works/_work_information.html.erb b/app/views/contestant_works/_work_information.html.erb new file mode 100644 index 000000000..9ca8366bf --- /dev/null +++ b/app/views/contestant_works/_work_information.html.erb @@ -0,0 +1,44 @@ +
+
+ 请您确认刚刚上传的作品信息 +

+ 作品名称:<%=@student_work.name%> +

+
+
作品描述:
+
<%=@student_work.description.html_safe %>
+
+
+

+ 件: + <% if @student_work.attachments.empty? %> + <%= "无附件"%> + <% else %> +

+ <% @student_work.attachments.each_with_index do |attachment,i| %> +
+ <%= link_to_short_attachment attachment, :class => 'link_file_a fl', :download => true -%> + <%= link_to(' '.html_safe, attachment_path(attachment, :format => 'js'), :method => 'delete', :remote => true, :title => '删除', :class => 'remove-upload fl', :confirm => l(:text_are_you_sure)) %> + (<%= number_to_human_size attachment.filesize %>) +
+
+ <% end -%> + <%#= render :partial => 'work_attachments_status', :locals => {:attachments => @student_work.attachments, :status => 2} %> +
+ <% end %> +

+
+
+ + 确 定 + + <%= link_to("重 试", retry_work_contestant_work_path(@student_work.id),:class => "tijiao",:style =>"margin-bottom: 15px;margin-top:15px;",:remote => true)%> +
+
+
+ + \ No newline at end of file diff --git a/app/views/contestant_works/_work_post_brief.html.erb b/app/views/contestant_works/_work_post_brief.html.erb index e69de29bb..c3ed1452a 100644 --- a/app/views/contestant_works/_work_post_brief.html.erb +++ b/app/views/contestant_works/_work_post_brief.html.erb @@ -0,0 +1,96 @@ +
+ <%=link_to image_tag(url_to_avatar(homework.user),width:"50px", height: "50px"), user_activities_path(homework.user_id)%> +
+
+
+ <%= link_to homework.user.show_name, user_activities_path(homework.user_id), :class => "newsBlue mr15"%> +
+ + <%=get_cw_status(homework).html_safe %> +
+ <% if homework.work_type == 3 && work.work_detail_group.base_on_project %> + 系统提示:该作业要求各组长<%=link_to "创建项目", new_project_path(:host=>Setting.host_name),:class=>"linkBlue",:title=>"新建项目",:style=>"text-decoration:underline;"%>,组成员加入项目,然后由组长关联项目。谢谢配合! + <% elsif homework.work_type == 3 && !homework.work_detail_group.base_on_project%> + 系统提示:该作业要求各组长提交作品,提交作品时请添加组成员。谢谢配合! + <% end %> + + <% is_pro = homework.homework_type == 2 && is_teacher %> + <% is_base_group = homework.homework_type == 3 && (homework.homework_detail_group.base_on_project == 1 || !(cur_user_works_for_homework(homework).nil?)) && !is_teacher %> +
+ <%= render :partial => 'users/homework_opr', :locals => {:activity => homework, :is_teacher => is_teacher, :hw_status => 5, :user_activity_id => homework.id} %> + <% if is_pro || is_base_group %> +
+ <% end %> + <% if !homework.publish_time.nil? %> +
+ <%= l(:label_publish_time)%>:<%= homework.publish_time%> 00:00 +
+ <% end %> + <% if !homework.end_time.nil? %> +
提交截止时间:<%= homework.end_time.to_s %> 23:59
+ <% end %> +
+
+
+
+
+
+ <%= homework.description.html_safe %> +
+
+ <% if is_pro %> +
测试集:<%=homework.homework_tests.count %>组 + + + + + + + <% homework.homework_tests.each_with_index do |test, i| %> + + + + + + <% end %> +
 测试集输入测试集输出
<%=i+1 %>
<%=test.input %>
<%=test.output %>
+
+ <% end %> +
+
+ <% if homework.homework_detail_manual%> + <% if homework.homework_detail_manual.comment_status == 1%> + <% end_time = homework.end_time.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 %> + <% elsif homework.homework_detail_manual.comment_status == 2%> + <% 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%> +
+
+
+
+
+
+ <%= render :partial=>"attachments/activity_attach", :locals=>{:activity => homework} %> +
+ + <%= render :partial => "users/homework_base_info", :locals =>{:activity => homework, :user_activity_id =>homework.id, :is_teacher => is_teacher, :hw_status => 5} %> +
+
\ No newline at end of file diff --git a/app/views/contestant_works/create.js.erb b/app/views/contestant_works/create.js.erb new file mode 100644 index 000000000..d636e788e --- /dev/null +++ b/app/views/contestant_works/create.js.erb @@ -0,0 +1,24 @@ +<% if @has_commit %> +$('#ajax-modal').html('<%= escape_javascript(render :partial => 'has_commit_work') %>'); +showModal('ajax-modal', '500px'); +$('#ajax-modal').siblings().remove(); +$('#ajax-modal').before("" + + ""); +$('#ajax-modal').parent().css("top","").css("left","").css("border","3px solid #269ac9"); +$('#ajax-modal').parent().addClass("anonymos"); +<% elsif @submit_result%> +$('#ajax-modal').html('<%= escape_javascript(render :partial => 'work_information') %>'); +showModal('ajax-modal', '500px'); +$('#ajax-modal').siblings().remove(); +$('#ajax-modal').before("" + + ""); +$('#ajax-modal').parent().css("top","").css("left","").css("border","3px solid #269ac9"); +$('#ajax-modal').parent().addClass("anonymos"); +<% else %> +window.location.href = '<%= new_contestant_work_path(:work => @contestwork.id)%>'; +<% end %> + +function clickCanel() { + hideModal('#popbox02'); + window.location.href = '<%= contestant_works_path(:work => @contestwork.id)%>'; +} \ No newline at end of file diff --git a/app/views/contestant_works/index.html.erb b/app/views/contestant_works/index.html.erb new file mode 100644 index 000000000..299739e9a --- /dev/null +++ b/app/views/contestant_works/index.html.erb @@ -0,0 +1,190 @@ +<% content_for :header_tags do %> + <%= 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 = @contestwork.work_type == 3 && @contestwork.work_detail_group.base_on_project %> + + + +
+
+
+ + + <% if @is_teacher%> +
+
    +
  • + 导出 +
      + + + +
    • + <% if @contestwork.contestant_works.empty?%> + <%= link_to "导出作业附件", "javascript:void(0)", class: "hworkExport resourcesGrey", :onclick => "alert('没有学生提交作业,无法下载附件')" %> + <% else%> + <%= link_to "导出作业附件", zipdown_assort_path(obj_class: @contestwork.class, obj_id: @contestwork, format: :json), + remote: true, class: "hworkExport resourcesGrey", :id => "download_homework_attachments" %> + <% end%> +
    • +
    +
  • +
+
+ <% end%> +
+
+ + + +
+
+ <%= render :partial => 'work_post_brief', :locals => {:homework => @contestwork, :is_teacher => @is_teacher} %> +
+ <%= render :partial => 'users/contest_work_post_reply', :locals => {:activity => @contestwork, :user_activity_id => @contestwork.id, :hw_status => 3, :is_teacher => @is_teacher} %> +
+
+ +
+
+
+
+ <%= render :partial => "student_work/student_work_list"%> +
+
+
+
+ + <% if @contestwork.work_type == 3 && @contestwork.work_detail_group.base_on_project %> +
+ <% student_work_ids = @contestwork.contestant_works.has_committed.blank? ? "(-1)" : "(" + @contestwork.contestant_works.has_committed.map{|st| st.id}.join(",") + ")" %> + <% student_work_projects = @contestwork.contestant_work_projects.where("contestant_work_id in #{student_work_ids} or contestant_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}%> +
+ <% end %> +
+
+
\ No newline at end of file diff --git a/app/views/contestant_works/new.html.erb b/app/views/contestant_works/new.html.erb new file mode 100644 index 000000000..a807d64f7 --- /dev/null +++ b/app/views/contestant_works/new.html.erb @@ -0,0 +1,310 @@ + +<% content_for :header_tags do %> + <%= import_ke(enable_at: true, prettify: false, init_activity: false) %> + <%= javascript_include_tag 'homework','baiduTemplate' %> +<% end %> + + + +
+
+
提交作品
+
+
+ +
注意:暂不支持IE浏览器的上传,请更换浏览器
+ +
+
+
+ + + 截止时间:<%= @contestwork.end_time%> + +
+ + <%= link_to @contestwork.user.show_name, user_activities_path(@contestwork.user_id), :class => "c_blue"%> + +
+
+ <%= @contestwork.description.html_safe %> +
+
+ <%= render :partial => 'student_work/work_attachments', :locals => {:attachments => @contestwork.attachments} %> +
+
+
+
+
+ +
+ <%= form_for(@student_work, + :html => { :multipart => true }, + :url => {:controller => 'contestant_works', + :action => 'create', + :work => @contestwork.id + },:remote=>true ) do |f| %> + +
+ <% if @contestwork.work_type == 3 %> + + + <%=hidden_field_tag 'group_member_ids', params[:group_member_ids], :value=>User.current.id %> + <% end %> +
+ +
+

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

+

+

+
+ +
+ +
+ +
+ <% if @contestwork && @contestwork.work_type == 3 %> + + 合作成员:<%= User.current.show_name %>(组长) + + + <% end %> +
+ + <% if @contestwork && @contestwork.work_type == 3 && @contestwork.work_detail_group.base_on_project %> + <% unless @contestwork.contestant_work_projects.where("user_id = #{User.current.id}").empty? %> + <% project = Project.find @contestwork.contestant_work_projects.where("user_id = #{User.current.id}").first.project_id %> + 关联项目:<%= project.name %> + <% end %> + <% end %> + +
+
+ +
+ <%= render :partial => 'contestant_work_attachment', :locals => {:container => @student_work} %> +
+
+
+
+
+ + <% if @contestwork.work_type == 3 %> + + <% end %> + +
+ 提交 + + <%= link_to "取消", delete_work_contestant_works_path(:work =>@contestwork.id),:id => 'new_message_cancel_btn', :class => "fr mr10 mt3"%> +
+
+ <% end%> +
+
+
diff --git a/app/views/contestant_works/retry_work.js.erb b/app/views/contestant_works/retry_work.js.erb new file mode 100644 index 000000000..7d1f2936f --- /dev/null +++ b/app/views/contestant_works/retry_work.js.erb @@ -0,0 +1,3 @@ +hideModal('#popbox02'); +$("#homework_attachments").html("<%= escape_javascript(render :partial => 'contestant_work_attachment', :locals => {:container => @work})%>"); +$("#group_member_ids").val("<%=User.current.id %>"); \ No newline at end of file diff --git a/app/views/contestant_works/search_contest_students.js.erb b/app/views/contestant_works/search_contest_students.js.erb new file mode 100644 index 000000000..a99f5887d --- /dev/null +++ b/app/views/contestant_works/search_contest_students.js.erb @@ -0,0 +1,42 @@ +$("#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 %>").one("click",function choose_student() { + var li = "
  • + li += " onclick='delete_student(<%=user.id %>);'"; + <% end %> + li += ">" + $("#student_<%=user.id %>").html()+"
  • "; + $("#choose_students_list").append(li); + }); +} +<% elsif !user.contestant_of_contest?(@contest) %> +if (str.indexOf(<%=user.id.to_s %>) < 0) { + $("#student_<%=user.id %>").attr("title","该项目成员不是本竞赛的参赛者"); +} +<% else %> +if (str.indexOf(<%=user.id.to_s %>) < 0) { + $("#student_<%=user.id %>").attr("title","该成员已加入其它分组"); +} +<% end %> +<% end %> \ No newline at end of file diff --git a/app/views/contestant_works/student_work_project.js.erb b/app/views/contestant_works/student_work_project.js.erb index 873febf2e..d107a764a 100644 --- a/app/views/contestant_works/student_work_project.js.erb +++ b/app/views/contestant_works/student_work_project.js.erb @@ -2,7 +2,7 @@ hideModal("#popbox02"); <% if @hw_status == 5 %> $("#homework_post_brief").html("<%= escape_javascript(render :partial => 'contestant_works/work_post_brief', :locals => {:homework => @contestwork, :is_teacher => @is_teacher}) %>"); <% else %> -$("#user_activity_<%= @user_activity_id%>").replaceWith("<%= escape_javascript(render :partial => 'users/contest_homework', :locals => {:activity => @contestwork,:user_activity_id =>@user_activity_id,:hw_status=>@hw_status}) %>"); +$("#user_activity_<%= @user_activity_id%>").replaceWith("<%= escape_javascript(render :partial => 'users/contest_work', :locals => {:activity => @contestwork,:user_activity_id =>@user_activity_id,:hw_status=>@hw_status}) %>"); <% end %> <% if @user_activity_id != @contestwork.id %> sd_create_editor_from_data(<%= @user_activity_id%>,"","100%", "UserActivity"); diff --git a/config/routes.rb b/config/routes.rb index 2882a50cd..b13d77658 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -590,10 +590,12 @@ RedmineApp::Application.routes.draw do post 'student_work_project' get 'new_student_work_project' get 'cancel_relate_project' + get 'delete_work' + get 'search_contest_students' end member do - + get 'retry_work' end end