diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index 477a8e2b9..9e935ae40 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -354,7 +354,7 @@ class AdminController < ApplicationController @schools = School.where('1=1') end @school_count = @schools.count - @school_pages = Paginator.new @school_count, per_page_option, params['page'] || 1 + @school_pages = Paginator.new @school_count, 100, params['page'] || 1 @schools = paginateHelper @schools,100 respond_to do |format| format.html diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index fe9318006..56252253a 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -31,17 +31,17 @@ class CoursesController < ApplicationController def join if User.current.logged? - if params[:role] == 10 + # if params[:role] == 10 cs = CoursesService.new @user = User.current - join = cs.join_course params,user + join = cs.join_course params,@user @state = join[:state] @course = join[:course] - else - @course = Course.find_by_id params[:object_id] - CourseMessage.create(:user_id => @course.tea_id, :course_id => @course.id, :viewed => false,:content=> params[:role],:course_message_id=>User.current.id,:course_message_type=>'JoinCourseRequest') - @state = 6 - end + # else + # @course = Course.find_by_id params[:object_id] + # CourseMessage.create(:user_id => @course.tea_id, :course_id => @course.id, :viewed => false,:content=> params[:role],:course_message_id=>User.current.id,:course_message_type=>'JoinCourseRequest') + # @state = 6 + # end else @state = 5 #未登录 end diff --git a/app/services/courses_service.rb b/app/services/courses_service.rb index 4639f1c2b..fb01e0398 100644 --- a/app/services/courses_service.rb +++ b/app/services/courses_service.rb @@ -15,11 +15,11 @@ class CoursesService page_no = params[:page] || 1 if @school_id == "0" || @school_id.nil? @courses_all = Course.active.visible. - joins("LEFT JOIN #{CourseStatus.table_name} ON #{Course.table_name}.id = #{CourseStatus.table_name}.course_id") + joins("LEFT JOIN #{CourseStatus.table_name} ON #{Course.table_name}.id = #{CourseStatus.table_name}.course_id") else @courses_all = Course.active.visible. - joins("LEFT JOIN #{CourseStatus.table_name} ON #{Course.table_name}.id = #{CourseStatus.table_name}.course_id"). - where("#{Course.table_name}.school_id = ?", @school_id) + joins("LEFT JOIN #{CourseStatus.table_name} ON #{Course.table_name}.id = #{CourseStatus.table_name}.course_id"). + where("#{Course.table_name}.school_id = ?", @school_id) end @course_count = @courses_all.count @course_pages = Redmine::Pagination::Paginator.new @course_count, per_page_option,page_no @@ -300,6 +300,7 @@ class CoursesService #@state == 4 您加入的课程不存在 #@state == 5 您还未登录 #@state == 6 申请成功,请等待审核完毕 + #@state == 7 您已经发送过申请了,请耐心等待 #@state 其他 未知错误,请稍后再试 def join_course params,current_user course = Course.find_by_id params[:object_id] @@ -308,15 +309,38 @@ class CoursesService if course_endTime_timeout? course @state = 2 else - if current_user.member_of_course?(course) - @state = 3 + if current_user.member_of_course?(course) #如果已经是成员 + if params[:course_password] == course.password + #如果加入角色为学生 + if params[:role] == "10" + @state = 3 + elsif current_user.allowed_to?(:as_teacher,course) + @state = 3 + else + #如果加入角色为教师或者教辅 + CourseMessage.create(:user_id => course.tea_id, :course_id => course.id, :viewed => false,:content=> params[:role],:course_message_id=>User.current.id,:course_message_type=>'JoinCourseRequest',:status=>0) + @state = 6 + end + else + @state = 1 + end else if params[:course_password] == course.password - members = [] - members << Member.new(:role_ids => [10], :user_id => current_user.id) - course.members << members - StudentsForCourse.create(:student_id => current_user.id, :course_id => params[:object_id]) - @state = 0 + if params[:role] == "10" + members = [] + members << Member.new(:role_ids => [10], :user_id => current_user.id) + course.members << members + StudentsForCourse.create(:student_id => current_user.id, :course_id => params[:object_id]) + @state = 0 + else + #如果已经发送过消息了,那么就要给个提示 + if CourseMessage.where("course_message_type = 'JoinCourseRequest' and user_id = #{course.tea_id} and content = #{params[:role]} and course_message_id = #{User.current.id} and course_id = #{course.id} and status = 0").count != 0 + @state = 7 + else + CourseMessage.create(:user_id => course.tea_id, :course_id => course.id, :viewed => false,:content=> params[:role],:course_message_id=>User.current.id,:course_message_type=>'JoinCourseRequest',:status=>0) + @state = 6 + end + end else @state = 1 end @@ -336,11 +360,11 @@ class CoursesService if course.is_public != 0 || current_user.member_of_course?(course) bids = course.homework_commons.page(params[:page] || 1).per(20).order('created_at DESC') bids = bids.like(params[:name]) if params[:name].present? - homeworks = [] - bids.each do |bid| - homeworks << show_homework_info(course,bid,current_user,is_course_teacher(current_user,course)) - end - homeworks + homeworks = [] + bids.each do |bid| + homeworks << show_homework_info(course,bid,current_user,is_course_teacher(current_user,course)) + end + homeworks else raise '403' end @@ -411,10 +435,10 @@ class CoursesService #每个作业中学生最后提交的作业 homeworks = [] course.homework_commons.each do |bid| - homework_attach = bid.student_works.order('updated_at DESC').first - unless homework_attach.nil? - homeworks << homework_attach - end + homework_attach = bid.student_works.order('updated_at DESC').first + unless homework_attach.nil? + homeworks << homework_attach + end end unless homeworks.count == 0 homeworks.sort!{|order,newer| newer.updated_at <=> order.updated_at} @@ -433,21 +457,21 @@ class CoursesService result end - # 课程课件 - def course_attachments params - result = [] - course = Course.find(params[:course_id]) - attachments = course.attachments.order("created_on ") - if !params[:name].nil? && params[:name] != "" - attachments.each do |atta| - result << atta if atta.filename.include?(params[:name]) + # 课程课件 + def course_attachments params + result = [] + course = Course.find(params[:course_id]) + attachments = course.attachments.order("created_on ") + if !params[:name].nil? && params[:name] != "" + attachments.each do |atta| + result << atta if atta.filename.include?(params[:name]) - end - else - result = attachments - end - result - end + end + else + result = attachments + end + result + end # 课程学生列表 def course_members params @@ -488,20 +512,20 @@ class CoursesService end def del_assitant_teacher params - member = Member.where("user_id = ? and course_id = ?",params[:user_id],params[:course_id]) - member.each do |m| - m.destroy - end - user_admin = CourseInfos.where("user_id = ? and course_id = ?",params[:user_id], params[:course_id]) - if user_admin.size > 0 - user_admin.each do |user| - user.destroy - end - end - joined = StudentsForCourse.where('student_id = ? and course_id = ?', params[:user_id],params[:course_id]) - joined.each do |join| - join.delete - end + member = Member.where("user_id = ? and course_id = ?",params[:user_id],params[:course_id]) + member.each do |m| + m.destroy + end + user_admin = CourseInfos.where("user_id = ? and course_id = ?",params[:user_id], params[:course_id]) + if user_admin.size > 0 + user_admin.each do |user| + user.destroy + end + end + joined = StudentsForCourse.where('student_id = ? and course_id = ?', params[:user_id],params[:course_id]) + joined.each do |join| + join.delete + end end def create_course_notice params ,current_user @@ -570,11 +594,11 @@ class CoursesService :open_anonymous_evaluation => open_anonymous_evaluation, #:homework_for_anonymous_comments => homework_for_anonymous_comments, :created_on => bid.created_at,:deadline => bid.end_time, - :homework_notsubmit_num => bid.course.members.count - bid.student_works.count, - :homework_submit_num => bid.student_works.count, - :homework_status_student => get_homework_status( bid),:homework_status_teacher => homework_status_desc( bid), - :student_evaluation_part => get_evaluation_part( bid ,3), - :ta_evaluation_part => get_evaluation_part( bid ,2),:homework_anony_type => bid.homework_type == 1 && !bid.homework_detail_manual.nil?} + :homework_notsubmit_num => bid.course.members.count - bid.student_works.count, + :homework_submit_num => bid.student_works.count, + :homework_status_student => get_homework_status( bid),:homework_status_teacher => homework_status_desc( bid), + :student_evaluation_part => get_evaluation_part( bid ,3), + :ta_evaluation_part => get_evaluation_part( bid ,2),:homework_anony_type => bid.homework_type == 1 && !bid.homework_detail_manual.nil?} end @@ -586,9 +610,9 @@ class CoursesService homework_count = bid.homeworks.count #已提交的作业数量 student_questions_count = bid.journals_for_messages.where('m_parent_id IS NULL').count description = bid.description - #if is_course_teacher(User.current, course) && @bid.open_anonymous_evaluation == 1 && @bid.homeworks.count >= 2 + #if is_course_teacher(User.current, course) && @bid.open_anonymous_evaluation == 1 && @bid.homeworks.count >= 2 state = bid.comment_status - #end + #end open_anonymous_evaluation = bid.open_anonymous_evaluation {:course_name => course.name,:id => bid.id, :course_teacher => author, :homework_times => many_times, :homework_name => name, :homework_count => homework_count,:student_questions_count => student_questions_count, :description => description, :homework_state => state,:open_anonymous_evaluation => open_anonymous_evaluation} @@ -685,12 +709,12 @@ class CoursesService latest_course_dynamics << {:time => latest_news.first.created_on } end # 课程讨论区 - latest_message = course.boards.first.topics.page(1).per(2) - unless latest_message.first.nil? - topic_count = course.boards.nil? ? 0 : course.boards.first.topics.count - topics = latest_message.all - latest_course_dynamics << {:time => latest_message.first.created_on} - end + latest_message = course.boards.first.topics.page(1).per(2) + unless latest_message.first.nil? + topic_count = course.boards.nil? ? 0 : course.boards.first.topics.count + topics = latest_message.all + latest_course_dynamics << {:time => latest_message.first.created_on} + end # 课程资源 # latest_attachment = course.attachments.order("created_on desc").page(1).per(2) # unless latest_attachment.first.nil? @@ -727,29 +751,29 @@ class CoursesService unless active_students.empty? latest_course_dynamics <<{:time=>"1970-01-01 0:0:0 +0800"} end - latest_course_dynamic = latest_course_dynamics.first - unless latest_course_dynamic.nil? - result << {:course_name => course.name, - :current_user_is_member => current_user.member_of_course?(course), - :current_user_is_teacher => is_course_teacher(current_user,course), - :course_id => course.id, - :course_img_url => url_to_avatar(course), - :course_time => course.time, - :course_term => course.term, - :news_count => notices_count, - :homework_count => homework_count, - :topic_count => topic_count, - :news => notices, - :homeworks => homeworkss, - :topics => topics, - :better_students => better_students, - :active_students => active_students, - :message => "", - :course_student_num=>course ? course.members.count : 0, - #:time_from_now=> distance_of_time_in_words(Time.now, latest_course_dynamic[:time].to_time) << "前", - :time_from_now=>time_from_now(latest_course_dynamic[:time].to_time), #.strftime('%Y-%m-%d %H:%M:%S').to_s, - :time=>latest_course_dynamic[:time].to_time} - end + latest_course_dynamic = latest_course_dynamics.first + unless latest_course_dynamic.nil? + result << {:course_name => course.name, + :current_user_is_member => current_user.member_of_course?(course), + :current_user_is_teacher => is_course_teacher(current_user,course), + :course_id => course.id, + :course_img_url => url_to_avatar(course), + :course_time => course.time, + :course_term => course.term, + :news_count => notices_count, + :homework_count => homework_count, + :topic_count => topic_count, + :news => notices, + :homeworks => homeworkss, + :topics => topics, + :better_students => better_students, + :active_students => active_students, + :message => "", + :course_student_num=>course ? course.members.count : 0, + #:time_from_now=> distance_of_time_in_words(Time.now, latest_course_dynamic[:time].to_time) << "前", + :time_from_now=>time_from_now(latest_course_dynamic[:time].to_time), #.strftime('%Y-%m-%d %H:%M:%S').to_s, + :time=>latest_course_dynamic[:time].to_time} + end end #返回数组集合 @@ -768,9 +792,9 @@ class CoursesService sql = "select users.*,ROUND(sum(student_works.final_score),2) 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 desc limit #{page*10},10" sql_count = " select count(distinct(student_works.user_id) ) " << - " 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]}) " + " 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]}) " max_size = ActiveRecord::Base.connection().select_value(sql_count) user_list = User.find_by_sql(sql) else diff --git a/app/views/courses/join.js.erb b/app/views/courses/join.js.erb index 64b1ffd4c..e2de705fe 100644 --- a/app/views/courses/join.js.erb +++ b/app/views/courses/join.js.erb @@ -1,25 +1,29 @@ -<% if @object_id && @state != 6%> +<% if @object_id && @state != 6 && @state !=4 %> $("#join_in_course_header").html("<%= escape_javascript(join_in_course_header(@course, @user)) %>"); <% end %> <% if @state %> <% if @state == 0 %> alert("加入成功"); hideModal($("#popbox02")); -$("#try_join_course_link").replaceWith(" 'index',:course=>course.id, :host=>Setting.host_course)%>' target='_blank' class='blue_n_btn fr mt20'>提交作品"); -window.location.href= "http://"+"<%= Setting.host_name%>"+"/courses/" + "<%= course.id%>" +$("#try_join_course_link").replaceWith(" 'index',:course=>@course.id, :host=>Setting.host_course)%>' target='_blank' class='blue_n_btn fr mt20'>提交作品"); +window.location.href= "http://"+"<%= Setting.host_name%>"+"/courses/" + "<%= @course.id%>" <% elsif @state == 1 %> alert("密码错误"); <% elsif @state == 2 %> alert("课程已过期\n请联系课程管理员重启课程。(在配置课程处)"); <% elsif @state == 3 %> alert("您已经加入了课程"); -window.location.href= "http://"+"<%= Setting.host_name%>"+"/courses/" + "<%= course.id%>" +window.location.href= "http://"+"<%= Setting.host_name%>"+"/courses/" + "<%= @course.id%>" <% elsif @state == 4 %> alert("您加入的课程不存在"); <% elsif @state == 5 %> alert("您还未登录"); <% elsif @state == 6 %> alert("申请成功,请等待审核") +hideModal($("#popbox02")); +<% elsif @state == 7%> + alert("您已经发送过申请了,请耐心等待") + hideModal($("#popbox02")); <% else %> alert("未知错误,请稍后再试"); <% end %> diff --git a/app/views/student_work/index.html.erb b/app/views/student_work/index.html.erb index 0ea5e7055..c8d3a2546 100644 --- a/app/views/student_work/index.html.erb +++ b/app/views/student_work/index.html.erb @@ -139,6 +139,10 @@
+
+ <%= render :partial => 'student_work/work_attachments', :locals => {:attachments => @homework.attachments} %> +
+
截止时间:<%= @homework.end_time %>
<% if @homework.homework_detail_manual%> diff --git a/app/views/users/_show_user_resource.html.erb b/app/views/users/_show_user_resource.html.erb index 6d985687c..6c3216f11 100644 --- a/app/views/users/_show_user_resource.html.erb +++ b/app/views/users/_show_user_resource.html.erb @@ -16,6 +16,19 @@ $(this).addClass("referenceTypeActive"); }); }); + +// 点击 checkbox选中引用的资源的时候,保存该资源的id到session里去 +function store_seleted_resource(dom){ + if(dom.attr('checked') == 'checked' ){ + $.get( + '<%= store_selected_resource_user_path %>'+'?save=y&res_id='+dom.val() + ) + }else { + $.get( + '<%= store_selected_resource_user_path %>'+'?save=n&res_id='+dom.val() + ) + } +}
diff --git a/app/views/users/import_resources_to_homework.js.erb b/app/views/users/import_resources_to_homework.js.erb index 61fcd294d..c929f48e5 100644 --- a/app/views/users/import_resources_to_homework.js.erb +++ b/app/views/users/import_resources_to_homework.js.erb @@ -1,13 +1,13 @@ <% unless @attachments.empty?%> - <% @attachments.each_with_index do |attachment, i| %> + <% @attachments.each do |attachment| %> $("#attachments_fields").append( - ''+ - '<%= 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;") %>'+ + ''+ + '<%= text_field_tag("attachments[p#{attachment.id}][filename]", attachment.filename, :class => "filename link_file", :readonly=>"readonly")%>'+ + '<%= text_field_tag("attachments[p#{attachment.id}][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}" %>'+ + '<%= check_box_tag("attachments[p#{attachment.id}][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#{attachment.id}", :format => "js"), :method => "delete", :remote => true, :class => "remove-upload") unless attachment.id.nil? %>'+ + '<%= hidden_field_tag "attachments[p#{attachment.id}][token]", "#{attachment.token}" %>'+ ''+ '
') diff --git a/public/stylesheets/courses.css b/public/stylesheets/courses.css index 41771eb6e..23a1a95ac 100644 --- a/public/stylesheets/courses.css +++ b/public/stylesheets/courses.css @@ -1045,6 +1045,8 @@ a.pro_mes_w{ height:20px; display:block; color:#999999;} .rside_work_con{ width:650px;} a.c_grey{ color:#999999;} a:hover.c_grey{ color:#333;} +a.link_file_a{ background:url(../images/pic_file.png) 0 2px no-repeat; padding-left:20px; } +a:hover.link_file_a{ background:url(../images/pic_file.png) 0 -25px no-repeat; color:#3ca5c6;} .link_file_a{ display:block; max-width:450px;overflow:hidden; white-space: nowrap; text-overflow:ellipsis;} .last_time{width:auto; text-align:right; margin-right:70px;} .link_file_box{ width:360px;}