diff --git a/app/api/mobile/apis/courses.rb b/app/api/mobile/apis/courses.rb index c325639f9..0d34cecaf 100644 --- a/app/api/mobile/apis/courses.rb +++ b/app/api/mobile/apis/courses.rb @@ -311,6 +311,31 @@ module Mobile present :data,news,with:Mobile::Entities::News present :status,0 end + + desc '课程历次作业总成绩列表' + params do + requires :token,type:String + requires :course_id,type:Integer,desc:'课程id' + optional :page,type:Integer,desc:'页码' + end + get ':course_id/students_score_list' do + cs = CoursesService.new + news = cs.students_score_list params,current_user + present :data,news,with:Mobile::Entities::User + end + + desc '课程某次作业提交列表 并显示成绩' + params do + requires :token,type:String + requires :course_id,type:Integer,desc:'课程id' + requires :homework_id,type:Integer,desc:'作业id' + optional :page,type:Integer,desc:'页码' + end + get ':course_id/student_works_list' do + cs = CoursesService.new + student_works = cs.student_work_list params,current_user + present :data,student_works.all,with:Mobile::Entities::StudentWork + end end end end diff --git a/app/api/mobile/entities/course_dynamic.rb b/app/api/mobile/entities/course_dynamic.rb index f086f1dd1..46ab5b272 100644 --- a/app/api/mobile/entities/course_dynamic.rb +++ b/app/api/mobile/entities/course_dynamic.rb @@ -38,30 +38,6 @@ module Mobile end end obj - elsif field == :homework_submit_num - obj = nil - c[:dynamics].each do |d| - if d[:type] == 4 - obj = d[:submit_count] - end - end - obj - elsif field == :homework_submit_students - obj = nil - c[:dynamics].each do |d| - if d[:type] == 4 - obj = d[:studentlist] - end - end - obj - elsif field == :homework_status - obj = nil - c[:dynamics].each do |d| - if d[:type] == 4 - obj = d[:homework_status] - end - end - obj else c[field] if (c.is_a?(Hash) && c.key?(field)) end @@ -82,11 +58,8 @@ module Mobile course_dynamic_expose :document_count course_dynamic_expose :topic_count course_dynamic_expose :homework_count - course_dynamic_expose :homework_submit_students - course_dynamic_expose :homework_submit_num - course_dynamic_expose :homework_status #在dynamics里解析出四种动态 - expose :document,using:Mobile::Entities::Attachment do |f,opt| + expose :documents,using:Mobile::Entities::Attachment do |f,opt| obj = nil f[:dynamics].each do |d| if d[:type] == 3 @@ -95,20 +68,20 @@ module Mobile end obj end - expose :topic,using:Mobile::Entities::Message do |f,opt| + expose :topics,using:Mobile::Entities::Message do |f,opt| obj = nil f[:dynamics].each do |d| if d[:type] == 2 - obj = d[:topic] + obj = d[:topics] end end obj end - expose :homework,using:Mobile::Entities::Homework do |f,opt| + expose :homeworks,using:Mobile::Entities::Homework do |f,opt| obj = nil f[:dynamics].each do |d| if d[:type] == 4 - obj = d[:homework] + obj = d[:homeworks] end end obj @@ -118,7 +91,17 @@ module Mobile obj = nil f[:dynamics].each do |d| if d[:type] == 1 - obj = d + obj = d[:news] + end + end + obj + end + + expose :better_students,using:Mobile::Entities::User do |f,opt| + obj = nil + f[:dynamics].each do |d| + if d[:type] == 6 + obj = d[:better_students] end end obj diff --git a/app/api/mobile/entities/homework.rb b/app/api/mobile/entities/homework.rb index e2c181048..2ea9404b8 100644 --- a/app/api/mobile/entities/homework.rb +++ b/app/api/mobile/entities/homework.rb @@ -3,6 +3,8 @@ module Mobile module Entities class Homework < Grape::Entity include Redmine::I18n + include ApplicationHelper + include ApiHelper def self.homework_expose(field) expose field do |f,opt| if f.is_a?(Hash) && f.key?(field) @@ -20,6 +22,12 @@ module Mobile f.send(:name) when :homework_notsubmit_num f.course.members.count - f.student_works.count + when :homework_submit_num + f.student_works.count + when :homework_status + get_homework_status f + when :homework_times + f.course.homework_commons.index(f) + 1 end end end @@ -66,11 +74,13 @@ module Mobile f[:homework_for_anonymous_comments] if f.is_a?(Hash) && f.key?(:homework_for_anonymous_comments) end + homework_expose :homework_submit_num homework_expose :homework_notsubmit_num - expose :submit_student_list ,using:Mobile::Entities::User do |f,opt| - f[:studentlist] + expose :submit_student_list ,using: Mobile::Entities::User do |f,opt| + get_submit_sutdent_list f end + homework_expose :homework_status end end diff --git a/app/api/mobile/entities/news.rb b/app/api/mobile/entities/news.rb index f189771e3..5ed3958ba 100644 --- a/app/api/mobile/entities/news.rb +++ b/app/api/mobile/entities/news.rb @@ -6,6 +6,12 @@ module Mobile expose field do |f,opt| if f.is_a?(Hash) && f.key?(field) f[field] + elsif f.is_a?(::News) + if field == :created_on + format_time(f.send(field)) if f.respond_to?(field) + else + f.send(field) if f.respond_to?(field) + end elsif f.is_a?(Hash) && !f.key?(field) n = f[:news] comments = f[:comments] @@ -26,13 +32,20 @@ module Mobile news_expose :title expose :author,using: Mobile::Entities::User do |f, opt| - n = f[:news] - n.author if n.respond_to?(:author) + obj = nil + if f.is_a?(::News) && f.respond_to?(:author) + obj = f.send(:author) + elsif f.is_a?(Hash) && f.key?(:author) + obj = f[:author] + end + obj end #作者id news_expose :author_id #作者名 news_expose :author_name + #作者头像url + news_expose :author_img_url #新闻内容 news_expose :description #发布时间 diff --git a/app/api/mobile/entities/student_work.rb b/app/api/mobile/entities/student_work.rb new file mode 100644 index 000000000..6cf68c875 --- /dev/null +++ b/app/api/mobile/entities/student_work.rb @@ -0,0 +1,45 @@ +module Mobile + module Entities + class StudentWork < Grape::Entity + include ApplicationHelper + include ApiHelper + def self.student_work_expose(f) + expose f do |u,opt| + if u.is_a?(Hash) && u.key?(f) + u[f] + elsif u.is_a?(::StudentWork) + if u.respond_to?(f) + if f == :created_at + format_time(u.send(:created_at)) + else + u.send(f) + end + + else + case f + when :student_id + u.user.user_extensions.student_id + end + end + end + + end + end + + expose :user, using: Mobile::Entities::User do |c, opt| + if c.is_a?(::StudentWork) + c.user + end + end + student_work_expose :student_id + student_work_expose :id + student_work_expose :name + student_work_expose :description + student_work_expose :final_score + student_work_expose :teacher_score + student_work_expose :student_score + student_work_expose :teacher_asistant_score + student_work_expose :created_at + end + end +end \ No newline at end of file diff --git a/app/api/mobile/entities/user.rb b/app/api/mobile/entities/user.rb index aee687dc9..2b3483625 100644 --- a/app/api/mobile/entities/user.rb +++ b/app/api/mobile/entities/user.rb @@ -22,6 +22,8 @@ module Mobile get_user_location u unless u.user_extensions.nil? when :brief_introduction u.nil? || u.user_extensions.nil? ? "" : u.user_extensions.brief_introduction + when :student_num + u.nil? || u.user_extensions.nil? ? "" : u.user_extensions.student_id end end end @@ -47,6 +49,10 @@ module Mobile user_expose :location #签名 user_expose :brief_introduction + #总成绩 + user_expose :score + #学号 + user_expose :student_num end end diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index 8e23041c6..086ecfb7f 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -34,13 +34,21 @@ class AdminController < ApplicationController def projects @status = params[:status] || 1 - scope = Project.status(@status).order('lft') + scope = Project.status(@status).order('id asc') scope = scope.like(params[:name]) if params[:name].present? @projects = scope.where(project_type: Project::ProjectType_project).all render :action => "projects", :layout => false if request.xhr? end + def courses + @name = params[:name] + @courses = Course.like(@name) + respond_to do |format| + format.html + end + end + def users sort_init 'login', 'asc' sort_update %w(login firstname lastname mail admin created_on last_login_on) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 3b25438df..00d740ee7 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -443,26 +443,19 @@ class CoursesController < ApplicationController def create cs = CoursesService.new @course = cs.create_course(params,User.current)[:course] - if @course.new_record? + if @course respond_to do |format| - format.html { render :action => 'new', :layout => 'new_base' } #Added by young - format.api { render_validation_errors(@course) } + flash[:notice] = l(:notice_successful_create) + format.html {redirect_to settings_course_url(@course, :course_type => 1)} + format.api { render :action => 'show', :status => :created, :location => url_for(:controller => 'courses', :action => 'show', :id => @course.id) } end else respond_to do |format| - format.html { - # render :layout => 'base_courses' - flash[:notice] = l(:notice_successful_create) - if params[:continue] - redirect_to new_course_url(attrs, :course => '0') - elsif params[:course_continue] - redirect_to new_course_url(:course => '1') - else - redirect_to settings_course_url(@course, :course_type => 1) - end - } - format.api { render :action => 'show', :status => :created, :location => url_for(:controller => 'courses', :action => 'show', :id => @course.id) } - end + flash[:notice] = l(:notice_create_failed) + # @course = Course.new + format.html { redirect_to new_course_path } #Added by young + format.api { render_validation_errors(@course) } + end end end @@ -532,7 +525,7 @@ class CoursesController < ApplicationController @trackers = Tracker.sorted.all @course = Course.new @course.safe_attributes = params[:course] - month = Time.now.month + # month = Time.now.month render :layout => 'new_base' end diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index 0003f7586..19c1214e2 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -37,7 +37,7 @@ class FilesController < ApplicationController obj.each do |container| @attachments += container.attachments end - @all_attachments = visable_attachemnts(@attachments) + @all_attachments = User.current.admin? ? @attachments : visable_attachemnts(@attachments) @limit = 10 @feedback_count = @all_attachments.count @feedback_pages = Paginator.new @feedback_count, @limit, params['page'] diff --git a/app/controllers/git_usage_controller.rb b/app/controllers/git_usage_controller.rb index 0b97fd523..56aaa56f1 100644 --- a/app/controllers/git_usage_controller.rb +++ b/app/controllers/git_usage_controller.rb @@ -1,6 +1,6 @@ #added by baiyu class GitUsageController < ApplicationController - layout "base_projects" + layout "new_base" def ch_usage end diff --git a/app/controllers/homework_common_controller.rb b/app/controllers/homework_common_controller.rb index 5cd55e23b..6b2cd21ed 100644 --- a/app/controllers/homework_common_controller.rb +++ b/app/controllers/homework_common_controller.rb @@ -92,7 +92,6 @@ class HomeworkCommonController < ApplicationController @homework.publish_time = params[:homework_common][:publish_time] @homework.homework_type = params[:homework_common][:homework_type] @homework.late_penalty = params[:late_penalty] - @homework.user_id = User.current.id @homework.course_id = @course.id #匿评作业相关属性 @@ -135,6 +134,7 @@ class HomeworkCommonController < ApplicationController #statue 1:启动成功,2:启动失败,作业总数大于等于2份时才能启动匿评,3:已开启匿评,请务重复开启,4:没有开启匿评的权限 def start_anonymous_comment @statue =4 and return unless User.current.admin? || User.current.allowed_to?(:as_teacher,@course) + @statue = 5 and return if Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") >= Time.now.strftime("%Y-%m-%d") if @homework_detail_manual.comment_status == 1 student_works = @homework.student_works if student_works && student_works.size >=2 diff --git a/app/controllers/journals_controller.rb b/app/controllers/journals_controller.rb index aa3a7e0ea..d8cd8eeec 100644 --- a/app/controllers/journals_controller.rb +++ b/app/controllers/journals_controller.rb @@ -74,6 +74,7 @@ class JournalsController < ApplicationController text = text.to_s.strip.gsub(%r{
((.|\s)*?)
}m, '[...]') @content = "> #{ll(Setting.default_language, :text_user_wrote, user)}\n> " @content << text.gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n" + @content = "
" << @content @id = user.id rescue ActiveRecord::RecordNotFound render_404 diff --git a/app/controllers/stores_controller.rb b/app/controllers/stores_controller.rb index b1705c826..85ea85241 100644 --- a/app/controllers/stores_controller.rb +++ b/app/controllers/stores_controller.rb @@ -72,6 +72,22 @@ class StoresController < ApplicationController l(:label_borad_project), #l(:label_contest_innovate), l(:label_forum) ] end + + #缺失文件列表 + def lost_file + attachments = [] + Attachment.where("container_id is not null and container_type is not null and container_type <> 'Bid' and container_type <> 'HomeworkAttach'").each do |attachment| + unless File.exist?(attachment.diskfile) + attachments << attachment + end + end + respond_to do |format| + format.xls { + send_data(homework_to_xls(attachments), :type => "text/excel;charset=utf-8; header=present", + :filename => "#{l(:label_file_lost_list)}.xls") + } + end + end private @@ -117,4 +133,27 @@ class StoresController < ApplicationController else end end + + #作品列表转换为excel + def homework_to_xls attachments + xls_report = StringIO.new + book = Spreadsheet::Workbook.new + sheet1 = book.create_worksheet :name => "homework" + blue = Spreadsheet::Format.new :color => :blue, :weight => :bold, :size => 10 + sheet1.row(0).default_format = blue + sheet1.row(0).concat(["文件ID","文件名","硬盘路径","上传时间","是否公开","所属对象","所属对象Id"]) + count_row = 1 + attachments.each do |attachment| + sheet1[count_row,0] = attachment.id + sheet1[count_row,1] = attachment.filename + sheet1[count_row,2] = attachment.diskfile + sheet1[count_row,3] = format_time(attachment.created_on) + sheet1[count_row,4] = (attachment.is_public == 1 || attachment.is_public) ? "是" :"否" + sheet1[count_row,5] = attachment.container_type + sheet1[count_row,6] = attachment.container_id + count_row += 1 + end + book.write xls_report + xls_report.string + end end diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb index e695a6fb0..deeefcd75 100644 --- a/app/controllers/student_work_controller.rb +++ b/app/controllers/student_work_controller.rb @@ -2,10 +2,11 @@ class StudentWorkController < ApplicationController layout "base_courses" include StudentWorkHelper require 'bigdecimal' - before_filter :find_homework, :only => [:new, :index, :create, :student_work_absence_penalty] + before_filter :find_homework, :only => [:new, :index, :create, :student_work_absence_penalty, :absence_penalty_list, :evaluation_list] before_filter :find_work, :only => [:edit, :update, :show, :destroy, :add_score, :praise_student_work] before_filter :member_of_course, :only => [:index, :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] def index @order,@b_sort,@name = params[:order] || "final_score",params[:sort] || "desc",params[:name] || "" @@ -241,9 +242,8 @@ class StudentWorkController < ApplicationController end end - #评价列表显示 + #缺评列表显示 def student_work_absence_penalty - render_403 unless User.current.allowed_to?(:as_teacher,@course) order = params[:order] || "desc" if @homework.student_works.empty? @stundet_works = [] @@ -251,7 +251,7 @@ class StudentWorkController < ApplicationController work_ids = "(" + @homework.student_works.map(&:id).join(",") + ")" @stundet_works = StudentWork.find_by_sql("SELECT *,(all_count - has_count) AS absence FROM( SELECT * , - (SELECT COUNT(*) FROM `student_works_evaluation_distributions` WHERE user_id = student_works.user_id AND student_work_id IN #{work_ids}) AS all_count, + (SELECT evaluation_num FROM homework_detail_manuals WHERE homework_detail_manuals.homework_common_id = #{@homework.id}) AS all_count, (SELECT COUNT(*) FROM `student_works_scores` WHERE user_id = student_works.user_id AND student_work_id IN #{work_ids}) AS has_count FROM `student_works` WHERE homework_common_id = #{@homework.id} @@ -264,6 +264,39 @@ class StudentWorkController < ApplicationController end end + #导出缺评列表 + def absence_penalty_list + if @homework.student_works.empty? + @stundet_works = [] + else + work_ids = "(" + @homework.student_works.map(&:id).join(",") + ")" + @stundet_works = StudentWork.find_by_sql("SELECT * FROM (SELECT *,(all_count - has_count) AS absence FROM( + SELECT * , + (SELECT evaluation_num FROM homework_detail_manuals WHERE homework_detail_manuals.homework_common_id = #{@homework.id}) AS all_count, + (SELECT COUNT(*) FROM `student_works_scores` WHERE user_id = student_works.user_id AND student_work_id IN #{work_ids}) AS has_count + FROM `student_works` + WHERE homework_common_id = #{@homework.id} + ) AS table_1) AS table_2 + where absence > 0 order by absence") + end + respond_to do |format| + format.xls { + send_data(absence_penalty_list_xls(@stundet_works), :type => "text/excel;charset=utf-8; header=present", + :filename => "#{@course.teacher.lastname.to_s + @course.teacher.firstname}_#{@course.name}_#{@course.time.to_s + @course.term}_#{@homework.name}#{l(:excel_absence_list)}.xls") + } + end + end + + #导出匿评列表 + def evaluation_list + respond_to do |format| + format.xls { + send_data(evaluation_list_xls(@homework.student_works), :type => "text/excel;charset=utf-8; header=present", + :filename => "#{@course.teacher.lastname.to_s + @course.teacher.firstname}_#{@course.name}_#{@course.time.to_s + @course.term}_#{@homework.name}#{l(:excel_evaluation_list)}.xls") + } + end + end + private #获取作业 def find_homework @@ -293,6 +326,10 @@ class StudentWorkController < ApplicationController render_403 unless (User.current.id == @work.user_id || User.current.admin?) && (@homework.homework_type != 1 || @homework.homework_detail_manual.comment_status == 1 ) end + def teacher_of_course + render_403 unless User.current.allowed_to?(:as_teacher,@course) + end + #根据条件过滤作业结果 def search_homework_member homeworks,name name = name.downcase @@ -302,6 +339,7 @@ class StudentWorkController < ApplicationController select_homework end + #作品列表转换为excel def homework_to_xls items xls_report = StringIO.new book = Spreadsheet::Workbook.new @@ -328,4 +366,55 @@ class StudentWorkController < ApplicationController book.write xls_report xls_report.string end + + #缺评列表转换为excel + def absence_penalty_list_xls items + xls_report = StringIO.new + book = Spreadsheet::Workbook.new + sheet1 = book.create_worksheet :name => "homework" + blue = Spreadsheet::Format.new :color => :blue, :weight => :bold, :size => 10 + sheet1.row(0).default_format = blue + + sheet1.row(0).concat([l(:excel_student_id),l(:excel_nickname),l(:excel_user_name),l(:lable_all_penalty),l(:lable_has_penalty),l(:lable_absence_penalty)]) + count_row = 1 + items.each do |homework| + sheet1[count_row,0] = homework.user.user_extensions.student_id + sheet1[count_row,1] = homework.user.login + sheet1[count_row,2] = homework.user.lastname.to_s + homework.user.firstname.to_s + sheet1[count_row,3] = homework.all_count + sheet1[count_row,4] = homework.has_count + sheet1[count_row,5] = homework.absence + count_row += 1 + end + book.write xls_report + xls_report.string + end + + #匿评列表转换为excel + def evaluation_list_xls items + xls_report = StringIO.new + book = Spreadsheet::Workbook.new + sheet1 = book.create_worksheet :name => "homework" + blue = Spreadsheet::Format.new :color => :blue, :weight => :bold, :size => 10 + sheet1.row(0).default_format = blue + + sheet1.row(0).concat([l(:label_work_name),l(:label_work_id),l(:label_work_autor),l(:label_evaluation_id),l(:label_evaluation_name), + l(:label_evaluation_score),l(:label_evaluation_common),l(:label_evaluation_time)]) + count_row = 1 + items.each do |homework| + homework.student_works_scores.where(:reviewer_role => 3).each do |score| + sheet1[count_row,0] = homework.name + sheet1[count_row,1] = homework.user.user_extensions.student_id + sheet1[count_row,2] = homework.user.show_name + sheet1[count_row,3] = score.user.user_extensions.student_id + sheet1[count_row,4] = score.user.show_name + sheet1[count_row,5] = score.score + sheet1[count_row,6] = score.comment + sheet1[count_row,7] = format_time(score.created_at) + count_row += 1 + end + end + book.write xls_report + xls_report.string + end end \ No newline at end of file diff --git a/app/helpers/api_helper.rb b/app/helpers/api_helper.rb index afdc306a4..916383b05 100644 --- a/app/helpers/api_helper.rb +++ b/app/helpers/api_helper.rb @@ -1,3 +1,4 @@ +# encoding: utf-8 module ApiHelper #获取用户的工作单位 def get_user_work_unit user @@ -64,4 +65,45 @@ module ApiHelper def get_user_language user (user.language.nil? || user.language == "") ? 'zh':user.language end + + # 获取课程作业的状态 + def get_homework_status homework + homework_status = "" + if !homework.nil? + if homework.homework_type == 1 && homework.homework_detail_manual + case homework.homework_detail_manual.comment_status + when 1 + homework_status = show_homework_deadline homework + when 2 + homework_status = "正在匿评中" + when 3 + homework_status = "匿评已结束" + end + elsif homework.homework_type == 0 + homework_status = "未启用匿评" + elsif homework.homework_type == 2 + homework_status = "编程作业" + else + end + end + homework_status + end + + #获取 + def get_submit_sutdent_list homework + studentlist = [] + if homework.is_a?(Hash) && homework.key?(:studentlist) + studentlist = homework[:studentlist] + else + homework.student_works.order("created_at desc").page(1).per(6).each do |work| + studentlist << work.user + end + end + studentlist + end + + #计算作业的截止日期,剩余日期 + def show_homework_deadline homework + "距作业截止还有" << (Date.parse(Time.now.to_s) - Date.parse(homework.end_time.to_s)).to_i.to_s << "天" + end end \ No newline at end of file diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 5af4e2038..a31bd6189 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -2278,7 +2278,9 @@ module ApplicationHelper #获取匿评相关连接代码 def homework_anonymous_comment homework if homework.homework_type == 1 && homework.homework_detail_manual #匿评作业 - if homework.student_works.count >= 2 #作业份数大于2 + if Time.parse(homework.end_time.to_s).strftime("%Y-%m-%d") >= Time.now.strftime("%Y-%m-%d") + link = "启动匿评".html_safe + elsif homework.student_works.count >= 2 #作业份数大于2 case homework.homework_detail_manual.comment_status when 1 link = link_to '启动匿评', alert_anonymous_comment_homework_common_path(homework), id: "#{homework.id}_start_anonymous_comment", remote: true, disable_with: '加载中...',:class => 'fr mr10 work_edit' diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index 13012a70c..a0bd18582 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -35,7 +35,7 @@ module CoursesHelper #生成课程老师成员链接 def course_teacher_link teacher_num - if User.current.member_of_course?(@course) + if User.current.member_of_course?(@course) || User.current.admin? link_to "#{teacher_num}", course_member_path(@course, :role => 1), :class => 'info_foot_num c_blue' else content_tag 'span',teacher_num, :class => 'info_foot_num c_blue' @@ -44,7 +44,7 @@ module CoursesHelper #生成课程学生列表连接 def course_student_link student_num - if (User.current.logged? && @course.open_student == 1) || (User.current.member_of_course?(@course)) + if (User.current.logged? && @course.open_student == 1) || (User.current.member_of_course?(@course)) || User.current.admin? link_to "#{student_num}", course_member_path(@course, :role => 2), :class => 'info_foot_num c_blue' else content_tag 'span',student_num, :class => 'info_foot_num c_blue' diff --git a/app/models/project.rb b/app/models/project.rb index 49ed2d0ee..f201e6e3c 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -839,7 +839,7 @@ class Project < ActiveRecord::Base # Yields the given block for each project with its level in the tree def self.project_tree(projects, &block) ancestors = [] - projects.sort_by(&:lft).each do |project| + projects.sort_by(&:id).each do |project| while (ancestors.any? && !project.is_descendant_of?(ancestors.last)) ancestors.pop end diff --git a/app/services/courses_service.rb b/app/services/courses_service.rb index 29c4fb1b0..b77703a37 100644 --- a/app/services/courses_service.rb +++ b/app/services/courses_service.rb @@ -120,10 +120,10 @@ class CoursesService if current_user.nil? || !(current_user.admin? || @course.is_public == 1 || (@course.is_public == 0 && current_user.member_of_course?(@course))) raise '403' end - scope = @course ? @course.news.course_visible(current_user) : News.course_visible(current_user) + scope = @course ? @course.news.order("news.created_on desc").course_visible(current_user) : News.order("news.created_on desc").course_visible(current_user) news = [] scope.each do |n| - news << {:id => n.id,:title => n.title,:author_name => n.author.name,:author_id => n.author.id, :description => n.description,:created_on => format_time(n.created_on),:comments_count => n.comments_count} + news << {:id => n.id,:title => n.title,:author_name => n.author.name,:author_id => n.author.id, :author=>n.author, :description => n.description,:created_on => format_time(n.created_on),:comments_count => n.comments_count} end news end @@ -201,12 +201,14 @@ class CoursesService @course.class_period = params[:class_period].to_i params[:course][:is_public] ? @course.is_public = 1 : @course.is_public = 0 params[:course][:open_student] ? @course.open_student = 1 : @course.open_student = 0 + else + end @issue_custom_fields = IssueCustomField.sorted.all @trackers = Tracker.sorted.all - if @course.save + if @course && @course.save #unless User.current.admin? r = Role.givable.find_by_id(Setting.new_project_user_role_id.to_i) || Role.givable.first m = Member.new(:user => current_user, :roles => [r]) @@ -330,7 +332,7 @@ class CoursesService def homework_list params,current_user course = Course.find(params[:id]) if course.is_public != 0 || current_user.member_of_course?(course) - bids = course.homework_commons.page(1).per(3).order('created_at DESC') + bids = course.homework_commons.page(1).per(20).order('created_at DESC') bids = bids.like(params[:name]) if params[:name].present? homeworks = [] bids.each do |bid| @@ -665,58 +667,41 @@ class CoursesService course = mp.course latest_course_dynamics = [] dynamics_count = 0 + # 课程学霸 学生总分数排名靠前的5个人 + homework_count = course.homework_commons.count + unless homework_count == 0 + sql = "select users.*,sum(IFNULL(0,student_works.final_score))/#{homework_count} score from student_works left outer join users on student_works.user_id = users.id" << + " where homework_common_id in ( select id from homework_commons where homework_commons.course_id = #{course.id}) GROUP BY student_works.user_id ORDER BY score limit 0,6" + latest_course_dynamics <<{:type=> 6,:time=>Time.now.to_s,:count=> 6,:better_students=> User.find_by_sql(sql)} + dynamics_count += 1 + end # 课程通知 - latest_news = course.news.order("created_on desc").first - unless latest_news.nil? - latest_course_dynamics << {:type => 1, :time => latest_news.created_on,:count=>course.news.count, - :news => latest_news} + latest_news = course.news.page(1).per(2).order("created_on desc") + unless latest_news.first.nil? + latest_course_dynamics << {:type => 1, :time => latest_news.first.created_on,:count=>course.news.count, + :news => latest_news.all} dynamics_count += 1 end # 课程讨论区 - latest_message = course.boards.first.topics[0] - unless latest_message.nil? - latest_course_dynamics << {:type => 2, :time => latest_message.created_on, :count =>course.boards.nil? ? 0 : course.boards.first.topics.count, - :topic => latest_message} - dynamics_count += 1 - end + # latest_message = course.boards.first.topics.page(1).per(2) + # unless latest_message.first.nil? + # latest_course_dynamics << {:type => 2, :time => latest_message.first.created_on, :count =>course.boards.nil? ? 0 : course.boards.first.topics.count, + # :topics => latest_message.all} + # dynamics_count += 1 + # end # 课程资源 - latest_attachment = course.attachments.order("created_on desc").first - unless latest_attachment.nil? - latest_course_dynamics << {:type => 3, :time => latest_attachment.created_on,:count =>course.attachments.count , :documents=>latest_attachment} - dynamics_count += 1 - end + # latest_attachment = course.attachments.order("created_on desc").page(1).per(2) + # unless latest_attachment.first.nil? + # latest_course_dynamics << {:type => 3, :time => latest_attachment.first.created_on,:count =>course.attachments.count , :documents=>latest_attachment} + # dynamics_count += 1 + # end #课程作业 已经交的学生列表(暂定显示6人),未交的学生列表,作业的状态 - homework = course.homework_commons.order('created_at desc').first - homework_status = ""; - # 判断作业所处的状态,如果是刚发布,就获取剩余时间 - #如果是匿评状态,显示正在匿评 - #如果是匿评结束,显示匿评结束 - #获取作业提交的前6个人,不足6个显示所有 - studentlist = [] - if !homework.nil? - if homework.homework_type == 1 && homework.homework_detail_manual - case homework.homework_detail_manual.comment_status - when 1 - homework_status = show_homework_deadline homework - when 2 - homework_status = "正在匿评中" - when 3 - homework_status = "匿评已结束" - end - elsif homework.homework_type == 0 - homework_status = "未启用匿评" - elsif homework.homework_type == 2 - homework_status = "编程作业" - else - end - # 获取提交作业的前六个学生的名字 和 头像路径 - homework.student_works.order("created_at desc").page(1).per(6).each do |work| - studentlist << {:image_url=> url_to_avatar(work.user),:user_name=>work.user.realname} - end - latest_course_dynamics << {:type => 4, :time => homework.updated_at, :count=>course.homework_commons.count,:submit_count => homework.student_works.count , :homework => homework, :homework_status => homework_status, :studentlist => studentlist} + homeworks = course.homework_commons.page(1).per(2).order('created_at desc') + unless homeworks.first.nil? + latest_course_dynamics << {:type => 4, :time => homeworks.first.updated_at, :count=>course.homework_commons.count , :homeworks => homeworks} dynamics_count += 1 end latest_course_dynamics.sort! { |order, newer| newer[:time] <=> order[:time] } @@ -730,9 +715,44 @@ class CoursesService result end - #计算作业的截止日期,剩余日期 - def show_homework_deadline homework - "距作业截止还有" << (Date.parse(Time.now.to_s) - Date.parse(homework.end_time.to_s)).to_i.to_s << "天" + # 获取课程历次作业的学生总成绩 + def students_score_list params,current_user + homework_count = Course.find(params[:course_id]).homework_commons.count + page = (params[:page] || 1) - 1 + sql = "select users.*,sum(IFNULL(0,student_works.final_score))/#{homework_count} score from student_works left outer join users on student_works.user_id = users.id" << + " where homework_common_id in ( select id from homework_commons where homework_commons.course_id = #{params[:course_id]}) GROUP BY student_works.user_id ORDER BY score limit #{page*10},10" + User.find_by_sql(sql) + end + + # 获取某次作业的所有作业列表 + def student_work_list params,current_user + is_teacher = User.current.allowed_to?(:as_teacher,Course.find(params[:course_id])) + homework = HomeworkCommon.find(params[:homework_id]) + student_works = [] + #老师 || 非匿评作业 || 匿评结束 显示所有的作品 + show_all = is_teacher || homework.homework_type != 1 || homework.homework_detail_manual.comment_status == 3 + if show_all + if homework.homework_type == 1 || is_teacher || current_user.admin? + student_works = homework.student_works.page(params[:page] || 1).per(10).order("final_score desc ") + else + my_work = homework.student_works.where(:user_id => current_user.id) + if my_work.empty? + student_works = [] + else + student_works = homework.student_works.page(params[:page] || 1).per(10).order("final_score desc") + end + end + else #学生 + if homework.homework_detail_manual.comment_status == 1 #未开启匿评,只显示我的作品 + student_works = homework.student_works.where(:user_id => current_user.id).page(params[:page] || 1).per(10) + elsif homework.homework_detail_manual.comment_status == 2 #匿评列表,显示匿评作品和我的作品 + #is_evaluation = true + my_work = homework.student_works.where(:user_id => current_user.id).page(params[:page] || 1).per(10) + student_works = my_work + current_user.student_works_evaluation_distributions.map(&:student_work).select { |work| work.homework_common_id == homework.id} + end end + student_works end +end + diff --git a/app/views/admin/courses.html.erb b/app/views/admin/courses.html.erb new file mode 100644 index 000000000..1615bccbc --- /dev/null +++ b/app/views/admin/courses.html.erb @@ -0,0 +1,76 @@ +
+ <%= link_to l(:label_course_new), {:controller => 'courses', :action => 'new'}, :class => 'icon icon-add' %> +
+ +

+ <%=l(:label_course_all)%> +

+ +<%= form_tag({}, :method => :get) do %> +
+ + <%= text_field_tag 'name', params[:name], :size => 30, :placeholder => '课程名称' %> + <%= submit_tag l(:button_apply), :class => "small", :name => nil %> + + <%= l(:button_clear)%> + +
+<% end %> +  + +
+ + + + + + + + + + + + + <% @courses.each do |course| %> + "> + + + + + + + + <% end %> + +
+ 序号 + + 课程 + + 主讲老师 + + 学时 + + <%=l(:field_is_public)%> + + <%=l(:field_created_on)%> +
+ <%= course.id %> + + + <%= link_to(course.name, course_path(course.id)) %> + + + <%= link_to(course.try(:teacher).try(:realname).truncate(6, omission: '...'), user_path(course.teacher)) %> + + <%= course.class_period %> + + <%= checked_image course.is_public? %> + + <%= format_date(course.created_at) %> +
+
+ +<% html_title(l(:label_course_all)) -%> diff --git a/app/views/admin/projects.html.erb b/app/views/admin/projects.html.erb index 4c9479a6d..f5b7955bf 100644 --- a/app/views/admin/projects.html.erb +++ b/app/views/admin/projects.html.erb @@ -1,5 +1,5 @@
-<%= link_to l(:label_project_new), {:controller => 'projects', :action => 'new'}, :class => 'icon icon-add' %> + <%= link_to l(:label_project_new), {:controller => 'projects', :action => 'new'}, :class => 'icon icon-add' %>

@@ -7,62 +7,70 @@

<%= form_tag({}, :method => :get) do %> -
- +
+ <%= l(:label_filter_plural) %> - - - <%= select_tag 'status', project_status_options_for_select(@status), :class => "small", :onchange => "this.form.submit(); return false;" %> - - <%= text_field_tag 'name', params[:name], :size => 30 %> - <%= submit_tag l(:button_apply), :class => "small", :name => nil %> - <%= link_to l(:button_clear), {:controller => 'admin', :action => 'projects'}, :class => 'icon icon-reload' %> -
+
+ + <%= select_tag 'status', project_status_options_for_select(@status), :class => "small", :onchange => "this.form.submit(); return false;" %> + + <%= text_field_tag 'name', params[:name], :size => 30 %> + <%= submit_tag l(:button_apply), :class => "small", :name => nil %> + <%= link_to l(:button_clear), {:controller => 'admin', :action => 'projects'}, :class => 'icon icon-reload' %> +
<% end %>  
- - - - - - - - -<% project_tree(@projects) do |project, level| %> - <%= project.css_classes %> <%= level > 0 ? "idnt idnt-#{level}" : nil %>"> - - - - - -<% end %> - -
- <%=l(:label_project)%> - - <%=l(:field_is_public)%> - - <%=l(:field_created_on)%> -
- - <%= link_to_project_settings(project, {}) %> - - - <%= checked_image project.is_public? %> - - <%= format_date(project.created_on) %> - - <%= link_to(l(:button_archive), { :controller => 'projects', :action => 'archive', :id => project, :status => params[:status] }, :data => {:confirm => l(:text_are_you_sure)}, :method => :post, :class => 'icon icon-lock') unless project.archived? %> - <%= link_to(l(:button_unarchive), { :controller => 'projects', :action => 'unarchive', :id => project, :status => params[:status] }, :method => :post, :class => 'icon icon-unlock') if project.archived? && (project.parent.nil? || !project.parent.archived?) %> - <%= link_to(l(:button_copy), { :controller => 'projects', :action => 'copy', :id => project }, :class => 'icon icon-copy') %> - <%= link_to(l(:button_delete), project_path(project), :method => :delete, :class => 'icon icon-del') %> -
+ + + + + + + + + + + + <% project_tree(@projects) do |project, level| %> + <%= project.css_classes %> <%= level > 0 ? "idnt idnt-#{level}" : nil %>"> + + + + + + + <% end %> + +
+ 序号 + + <%=l(:label_project)%> + + <%=l(:field_is_public)%> + + <%=l(:field_created_on)%> +
+ <%= project.id %> + + + <%= link_to_project_settings(project, {}) %> + + + <%= checked_image project.is_public? %> + + <%= format_date(project.created_on) %> + + <%= link_to(l(:button_archive), { :controller => 'projects', :action => 'archive', :id => project, :status => params[:status] }, :data => {:confirm => l(:text_are_you_sure)}, :method => :post, :class => 'icon icon-lock') unless project.archived? %> + <%= link_to(l(:button_unarchive), { :controller => 'projects', :action => 'unarchive', :id => project, :status => params[:status] }, :method => :post, :class => 'icon icon-unlock') if project.archived? && (project.parent.nil? || !project.parent.archived?) %> + <%= link_to(l(:button_copy), { :controller => 'projects', :action => 'copy', :id => project }, :class => 'icon icon-copy') %> + <%= link_to(l(:button_delete), project_path(project), :method => :delete, :class => 'icon icon-del') %> +
<% html_title(l(:label_project_plural)) -%> diff --git a/app/views/courses/_history.html.erb b/app/views/courses/_history.html.erb index e5f5fc0ec..e9639f4f0 100644 --- a/app/views/courses/_history.html.erb +++ b/app/views/courses/_history.html.erb @@ -9,7 +9,7 @@
- <%= link_to journal.user, user_path(journal.user),:class => 'c_blue fb fl mb10', :target => "_blank"%> + <%= link_to journal.user.show_name, user_path(journal.user),:class => 'c_blue fb fl mb10', :target => "_blank"%> <%= format_time(journal.created_on) %> @@ -18,6 +18,7 @@

<%= journal.notes.html_safe %>

+
<% ids = 'project_respond_form_'+ journal.id.to_s%> diff --git a/app/views/courses/join_private_courses.js.erb b/app/views/courses/join_private_courses.js.erb index 23dc551f7..fecfb13cd 100644 --- a/app/views/courses/join_private_courses.js.erb +++ b/app/views/courses/join_private_courses.js.erb @@ -1,5 +1,5 @@ $('#ajax-modal').html('<%= escape_javascript(render :partial => 'join_private_course') %>'); -showModal('ajax-modal', '510px'); +showModal('ajax-modal', '540px'); $('#ajax-modal').css('height','330px'); $('#ajax-modal').siblings().remove(); $('#ajax-modal').before("" + diff --git a/app/views/files/_course_list.html.erb b/app/views/files/_course_list.html.erb index 8536a3ef5..353d19dab 100644 --- a/app/views/files/_course_list.html.erb +++ b/app/views/files/_course_list.html.erb @@ -22,7 +22,7 @@
<% curse_attachments.each do |file| %> - <% if file.is_public? || User.current.member_of_course?(course) %> + <% if file.is_public? || User.current.member_of_course?(course) || User.current.admin? %>
<%= link_to truncate(file.filename,length: 35, omission: '...'), diff --git a/app/views/forums/_show_topics.html.erb b/app/views/forums/_show_topics.html.erb index 9af8538ed..f46600a6c 100644 --- a/app/views/forums/_show_topics.html.erb +++ b/app/views/forums/_show_topics.html.erb @@ -4,36 +4,40 @@ <% if memos.any? %> <% memos.each do |topic| %> - - + + +
<%= link_to image_tag(url_to_avatar(topic.author), :class => "avatar"), user_path(topic.author) if topic.author%> - - - - - - - - - - - -
<%= link_to h(topic.subject), forum_memo_path(topic.forum, topic) %> - - - - - - - -
<%= link_to (topic.replies_count), forum_memo_path(topic.forum, topic) %>
回答
<%= authoring topic.created_at, topic.author %> - - <% author = topic.last_reply.try(:author)%> - <% if author%> - 最后回复:<%=link_to_user author %> - <% end%> - -
-
+ <%= link_to image_tag(url_to_avatar(topic.author), :class => "avatar"), user_path(topic.author) if topic.author%> + + + + + + + + + + + + +
<%= link_to h(topic.subject), forum_memo_path(topic.forum, topic) %> + + + + + + + +
<%= link_to (topic.replies_count), forum_memo_path(topic.forum, topic) %>
回答
<%= authoring topic.created_at, topic.author %> + + <% author = topic.last_reply.try(:author)%> + <% if author%> + 最后回复:<%=link_to_user author %> + <% end%> + +
+
+
<% end %> diff --git a/app/views/homework_common/index.html.erb b/app/views/homework_common/index.html.erb index 3208bb969..a1aa49c8c 100644 --- a/app/views/homework_common/index.html.erb +++ b/app/views/homework_common/index.html.erb @@ -41,12 +41,13 @@ <%= homework.description.html_safe %>
+
-

+ + + <%= l(:button_submit) %> diff --git a/app/views/journals/new.js.erb b/app/views/journals/new.js.erb index ae2574595..d02568426 100644 --- a/app/views/journals/new.js.erb +++ b/app/views/journals/new.js.erb @@ -1,11 +1,11 @@ -$('#issue_notes').val("<%= raw escape_javascript(@content) %>"); +$('#journal_issue_note').html("<%= raw escape_javascript(@content.html_safe) %>"); +$("input[name='issue_quote_new']").val("<%= raw escape_javascript(@content.html_safe) %>"); <% # when quoting a private journal, check the private checkbox - if @journal && @journal.private_notes? + if @journal && @journal.private_notes? %> $('#issue_private_notes').attr('checked', true); <% end %> - showAndScrollTo("update", "notes"); $('#notes').scrollTop = $('#notes').scrollHeight - $('#notes').clientHeight; diff --git a/app/views/layouts/_base_header.html.erb b/app/views/layouts/_base_header.html.erb index fa8787122..b800a1722 100644 --- a/app/views/layouts/_base_header.html.erb +++ b/app/views/layouts/_base_header.html.erb @@ -17,15 +17,14 @@ visiable = hidden_non_project && hidden_non_project.value == "0"%>
-