diff --git a/app/controllers/homework_common_controller.rb b/app/controllers/homework_common_controller.rb index e71fd5e29..333f86da1 100644 --- a/app/controllers/homework_common_controller.rb +++ b/app/controllers/homework_common_controller.rb @@ -18,28 +18,28 @@ class HomeworkCommonController < ApplicationController end def new - # @homework_type = "1" - # - # @homework = HomeworkCommon.new - # @homework.safe_attributes = params[:homework_common] - # @homework.late_penalty = 0 - # @homework.end_time = (Time.now + 3600 * 24).strftime('%Y-%m-%d') - # @homework.publish_time = Time.now.strftime('%Y-%m-%d') - # - # if @homework_type == "1" - # #匿评作业相关属性 - # @homework_detail_manual = HomeworkDetailManual.new - # @homework_detail_manual.ta_proportion = 0.6 - # @homework_detail_manual.absence_penalty = 0 - # @homework_detail_manual.evaluation_num = 3 - # @homework_detail_manual.evaluation_start = Time.now.strftime('%Y-%m-%d') - # @homework_detail_manual.evaluation_end = (Time.now + 3600 * 24).strftime('%Y-%m-%d') - # @homework.homework_detail_manual = @homework_detail_manual - # elsif @homework_type == "2" - # #编程作业相关属性 - # @homework_detail_programing = HomeworkDetailPrograming.new - # @homework.homework_detail_programing = @homework_detail_programing - # end + @homework_type = "1" + + @homework = HomeworkCommon.new + @homework.safe_attributes = params[:homework_common] + @homework.late_penalty = 0 + @homework.end_time = (Time.now + 3600 * 24).strftime('%Y-%m-%d') + @homework.publish_time = Time.now.strftime('%Y-%m-%d') + + if @homework_type == "1" + #匿评作业相关属性 + @homework_detail_manual = HomeworkDetailManual.new + @homework_detail_manual.ta_proportion = 0.6 + @homework_detail_manual.absence_penalty = 0 + @homework_detail_manual.evaluation_num = 3 + @homework_detail_manual.evaluation_start = Time.now.strftime('%Y-%m-%d') + @homework_detail_manual.evaluation_end = (Time.now + 3600 * 24).strftime('%Y-%m-%d') + @homework.homework_detail_manual = @homework_detail_manual + elsif @homework_type == "2" + #编程作业相关属性 + @homework_detail_programing = HomeworkDetailPrograming.new + @homework.homework_detail_programing = @homework_detail_programing + end respond_to do |format| format.html end @@ -209,7 +209,7 @@ class HomeworkCommonController < ApplicationController end if @homework.homework_type == 2 && @homework_detail_programing #编程作业 - @homework_detail_programing.language = "C++" + @homework_detail_programing.language = params[:language] @homework_detail_programing.standard_code = params[:standard_code] @homework_detail_programing.ta_proportion = params[:ta_proportion] || 0.6 homework_tests = @homework.homework_tests @@ -236,6 +236,25 @@ class HomeworkCommonController < ApplicationController end end end + + #发送修改作业的请求 + question = {title:@homework.name,content:@homework.description} + question[:input] = [] + question[:output] = [] + @homework.homework_tests.each do |test| + question[:input] << test.input + question[:output] << test.output + end + uri = URI("http://192.168.80.21:8080/api/questions/#{@homework_detail_programing.question_id}.json") + body = question.to_json + res = Net::HTTP.new(uri.host, uri.port).start do |client| + request = Net::HTTP::Put.new(uri.path) + request.body = body + request["Content-Type"] = "application/json" + client.request(request) + end + result = JSON.parse(res.body) + homework_detail_programing.question_id = result["id"] if result["status"] && result["status"] == 0 end @homework.save_attachments(params[:attachments]) diff --git a/app/controllers/news_controller.rb b/app/controllers/news_controller.rb index 56b4a30fc..9385c73ee 100644 --- a/app/controllers/news_controller.rb +++ b/app/controllers/news_controller.rb @@ -73,8 +73,14 @@ class NewsController < ApplicationController @news_count = scope.count #@news_pages = Paginator.new @news_count, @limit, params['page'] #@offset ||= scope_page.offset - scope_order = scope.all(:include => [:author, :course], - :order => "#{News.table_name}.created_on DESC") + if params[:subject].nil? + scope_order = scope.all(:include => [:author, :course], + :order => "#{News.table_name}.created_on DESC") + else + scope_order = scope.where("news.title like '#{'%' << params[:subject].to_s << '%'}'").all(:include => [:author, :course], + :order => "#{News.table_name}.created_on DESC") + end + # :offset => @offset, # :limit => @limit) @newss = paginateHelper scope_order,10 @@ -83,6 +89,7 @@ class NewsController < ApplicationController @news = News.new render :layout => 'base_courses' } + format.js format.api format.atom { render_feed(@newss, :title => (@course ? @course.name : Setting.app_title) + ": #{l(:label_news_plural)}") } end @@ -141,7 +148,7 @@ class NewsController < ApplicationController ids = params[:asset_id].split(',') update_kindeditor_assets_owner ids,@news.id,OwnerTypeHelper::NEWS end - # ض̬ļ¼add start + # ������ض�̬�ļ�¼add start teachers = searchTeacherAndAssistant(@course) for teacher in teachers if(teacher.user_id != User.current.id) @@ -155,7 +162,7 @@ class NewsController < ApplicationController notify.save() end end - # ض̬ļ¼add end + # ������ض�̬�ļ�¼add end render_attachment_warning_if_needed(@news) flash[:notice] = l(:notice_successful_create) redirect_to course_news_index_url(@course) diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index b335e1830..f5fa007a5 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -484,7 +484,18 @@ update if params[:repository_id].present? @repository = @project.repositories.find_by_identifier_param(params[:repository_id]) else - @repository = @project.repository + # 多版本库,如果一个版本库为空则去下一个 + rep_count = @project.repositories.count + if @project.repository.nil? + for i in 0..rep_count + unless @project.repositories[i].nil? + @repository = @project.repositories[i] + break + end + end + else + @repository = @project.repository + end end (render_404; return false) unless @repository @path = params[:path].is_a?(Array) ? params[:path].join('/') : params[:path].to_s diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb index 209fa7269..da2575456 100644 --- a/app/controllers/student_work_controller.rb +++ b/app/controllers/student_work_controller.rb @@ -157,7 +157,7 @@ class StudentWorkController < ApplicationController end def edit - if @homework.homework_type == 2 #编程作业不能修改作业 + if !User.current.admin? && @homework.homework_type == 2 #编程作业不能修改作业 render_403 else respond_to do |format| @@ -396,6 +396,7 @@ class StudentWorkController < ApplicationController if student_work_test.result == 0 student_score_count += 1 end + student_work_test.error_msg = params[:compile_error_msg] student_work_test.save! end end @@ -444,7 +445,7 @@ class StudentWorkController < ApplicationController #判断是不是当前作品的提交者 #提交者 && (非匿评作业 || 未开启匿评) 可以编辑作品 def author_of_work - render_403 unless (User.current.id == @work.user_id || User.current.admin?) && (@homework.homework_type != 1 || @homework.homework_detail_manual.comment_status == 1 ) + render_403 unless User.current.admin? || (User.current.id == @work.user_id && @homework.homework_type != 1 || @homework.homework_detail_manual.comment_status == 1 ) end def teacher_of_course diff --git a/app/models/homework_test.rb b/app/models/homework_test.rb index 7c477bfaf..4ed290ecd 100644 --- a/app/models/homework_test.rb +++ b/app/models/homework_test.rb @@ -2,5 +2,5 @@ class HomeworkTest < ActiveRecord::Base attr_accessible :input, :output, :homework_common_id belongs_to :homework_common - has_one :student_work_test + has_many :student_work_test end diff --git a/app/models/student_work_test.rb b/app/models/student_work_test.rb index 2e6efdf0a..413528b82 100644 --- a/app/models/student_work_test.rb +++ b/app/models/student_work_test.rb @@ -1,6 +1,6 @@ # encoding: utf-8 class StudentWorkTest < ActiveRecord::Base - attr_accessible :student_work_id, :homework_test_id, :result + attr_accessible :student_work_id, :homework_test_id, :result, :error_msg belongs_to :homework_test belongs_to :student_work diff --git a/app/views/homework_common/_homework_detail_programing_form.html.erb b/app/views/homework_common/_homework_detail_programing_form.html.erb index 5d1d5ce88..be08dd107 100644 --- a/app/views/homework_common/_homework_detail_programing_form.html.erb +++ b/app/views/homework_common/_homework_detail_programing_form.html.erb @@ -56,7 +56,7 @@
- <%= l(:label_total_news) %> - <%= @news_count %> - <%= l(:label_course_news_count) %> -
- <% if @course && User.current.allowed_to?(:manage_news, @course) %> - <%= link_to(btn_tips,new_course_news_path(@course),:class => 'problem_new_btn fl c_dorange')%> - ++ <%= l(:label_total_news) %> + <%= @news_count %> + <%= l(:label_course_news_count) %> +
+ <% if @course && User.current.allowed_to?(:manage_news, @course) %> + <%= link_to(btn_tips,new_course_news_path(@course),:class => 'problem_new_btn fl c_dorange')%> + - <% end %> + <% end %> +- <%= l(:label_no_data) %> -
- <% else %> - <% @newss.each do |news| %> -+ <%= l(:label_no_data) %> +
+<% else %> + <% newss.each do |news| %> +