diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 45a3f981b..56176119c 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -292,30 +292,79 @@ class CoursesController < ApplicationController end def teacher_assign_group - member = Member.where(:course_id => @course.id, :user_id => params[:user_id]).first - member.course_group_id = params[:course_group_id].to_i - member.save - @course_groups = @course.course_groups - @no_group_count = @course.student.count - @course.members.where("course_group_id != 0").count - @canShowCode = isCourseTeacher(User.current.id,@course) && params[:role] != '1' + @member = Member.where(:course_id => @course.id, :user_id => params[:user_id]).first + @member.course_group_id = params[:course_group_id].to_i + @member.save + if params[:group_id] && params[:group_id] != "-1" + @group = CourseGroup.find params[:group_id] + results = student_homework_score(@group.id,0,0,"desc") + @limit = 50 + @page = params[:page].nil? ? 1 : params['page'].to_i + @members_count = results.count + @mem_pages = Paginator.new @members_count, @limit, @page + @results = paginateHelper results, @limit + else + @course_groups = @course.course_groups + @no_group_count = @course.student.count - @course.members.where("course_group_id != 0").count + end + @canShowCode = isCourseTeacher(User.current.id,@course) respond_to do |format| format.js end end def join_group - @subPage_title = l :label_student_list group = CourseGroup.find(params[:object_id]) member = Member.where(:course_id => @course.id, :user_id => User.current.id).first member.course_group_id = group.id member.save @group = group - @course_groups = @course.course_groups - @no_group_count = @course.student.count - @course.members.where("course_group_id != 0").count - - search_group_members group + #@course_groups = @course.course_groups + #@no_group_count = @course.student.count - @course.members.where("course_group_id != 0").count + redirect_to group_member_course_path(@course, :group_id => @group.id) + #search_group_members group end + + #查找未分班的学生 + def search_not_group_member + @group = CourseGroup.find params[:group_id] + @search = params[:search] + q = params[:search] ? "#{params[:search].strip}" : "" + @members = [] + if q.nil? || q == "" + @course.members.includes(:user =>[:user_extensions =>[]]).where("course_group_id = 0").each do |m| + if m && m.user && m.user.join_in?(@course) + @members << m + end + end + else + @course.members.includes(:user =>[:user_extensions =>[]]).where("course_group_id = 0").each do |m| + username = m.user[:lastname].to_s.downcase + m.user[:firstname].to_s.downcase + if m && m.user && m.user.join_in?(@course) && (m.user[:login].to_s.downcase.include?(q) || m.user.user_extensions[:student_id].to_s.downcase.include?(q) || username.include?(q)) + @members << m + end + end + end + @is_search = params[:is_search] ? 1 : 0 + respond_to do |format| + format.js + end + end + + def add_members + @group = CourseGroup.find params[:group_id] + if @group && params[:chooseStudent] + params[:chooseStudent].each do |mem| + member = Member.find mem + if member && member.course == @course + member.update_attribute('course_group_id', @group.id) + end + end + redirect_to group_member_course_path(@course, :group_id => @group.id) + end + end + def unjoin_group @subPage_title = l :label_student_list group = CourseGroup.find(params[:object_id]) @@ -353,6 +402,28 @@ class CoursesController < ApplicationController @results = paginateHelper @results, @limit end + def group_member + @canShowCode = isCourseTeacher(User.current.id,@course) + @sort_type = 'score' + @score_sort_by = "desc" + if params[:group_id] && params[:group_id] != "0" && params[:group_id] != "-1" + @group = CourseGroup.find(params[:group_id]) + @results = student_homework_score(@group.id,0, 0,"desc") + else + page_from = params[:page].nil? ? 0 : (params[:page].to_i - 1) + @results = student_homework_score(0,page_from, 10,"desc") + end + @limit = 50 + @page = params[:page].nil? ? 1 : params['page'].to_i + @members_count = @results.count + @mem_pages = Paginator.new @members_count, @limit, @page + @results = paginateHelper @results, @limit + respond_to do |format| + format.html {render :layout => 'base_courses'} + format.js + end + end + def member ## 有角色参数的才是课程,没有的就是项目 if (User.current.admin? || @course.is_public == 1 || (@course.is_public == 0 && User.current.member_of_course?(@course))) @@ -399,7 +470,14 @@ class CoursesController < ApplicationController end def export_course_member_excel - @all_members = student_homework_score(0,0,0,"desc") + if params[:group_id] + group = CourseGroup.find params[:group_id] + unless group.nil? + @all_members = student_homework_score(@group.id,0,0,"desc") + end + else + @all_members = student_homework_score(0,0,0,"desc") + end @homeworks = @course.homework_commons.where("publish_time <= '#{Date.today}'").order("created_at asc") filename="#{@course.teacher.lastname.to_s + @course.teacher.firstname.to_s }_#{@course.name}_#{@course.time.to_s + @course.term}#{l(:excel_member_list)}"; @@ -486,6 +564,7 @@ class CoursesController < ApplicationController #添加成员消息状态 join_course_messages = CourseMessage.where("user_id =? and course_message_type =? and course_id =? and status = ? and viewed =?", User.current.id, 'JoinCourse', @course.id, 1, 0) join_course_messages.update_all(:viewed => true) + @tab = params[:tab].to_i || 0 if User.current.allowed_to?(:as_teacher,@course) @select_tab = params[:tab] @issue_custom_fields = IssueCustomField.sorted.all @@ -1366,14 +1445,16 @@ class CoursesController < ApplicationController #当加入,退出分班时查询分班的学生 def search_group_members group - @subPage_title = l :label_student_list @render_file = 'new_member_list' - @canShowCode = isCourseTeacher(User.current.id,@course) && params[:role] != '1' + @canShowCode = isCourseTeacher(User.current.id,@course) @is_remote = true @score_sort_by = "desc" - page_from = params[:page].nil? ? 0 : (params[:page].to_i - 1) @results = student_homework_score(group.id,0,0, "desc") - + @limit = 50 + @page = params[:page].nil? ? 1 : params['page'].to_i + @members_count = @results.count + @mem_pages = Paginator.new @members_count, @limit, @page + @results = paginateHelper @results, @limit end def member_to_xls homeworks, course, members,groups diff --git a/app/helpers/watchers_helper.rb b/app/helpers/watchers_helper.rb index 7f027009a..e978ad6a9 100644 --- a/app/helpers/watchers_helper.rb +++ b/app/helpers/watchers_helper.rb @@ -149,34 +149,14 @@ module WatchersHelper link_to text, url, :remote => true, :method => method, :id => "#{course.id}", :class => []+options end end - def join_in_course_group(coursegroups,group, user, options=[]) - return '' unless user && user.logged? + def join_in_course_group(course, group, user, options=[]) + return '' unless user && user.logged? && user.member_of_course?(course) + joined = user.member_of_course_group?(group) - @isjoin = false - coursegroups.each do |g| - g.members.each do |mem| - if mem.user_id == user.id - @isjoin = true - end - end - end - url_t = join_group_path(:object_id => group.id) - url_f = join_group_path(:object_id => group.id) - if @isjoin == true - joined = user.member_of_course_group?(group) - text = l(:label_exit_group) - - if joined - link_to text, {:controller => "courses", :action => "join_group", :object_id => "#{group.id}"}, - :remote => true, :method => 'delete', - :id => "#{group.id}", :style => "padding: 2px 8px 2px; background-color:#15bccf; color:#fff; ", - :confirm => l(:text_are_you_sure_out_group), :class => 'group_in' - - end - else - text = l(:label_new_join_group) - form_tag({:controller => "courses", :action => "join_group", :object_id => "#{group.id}"}, :remote => true, :method => 'post') do - submit_tag text, class: "group_in", style: "width: 90px;height: 21px; background-color:#15bccf; color:#fff;" + unless joined + text = l(:label_join_group) + form_tag({:controller => "courses", :action => "join_group", :object_id => "#{group.id}"},:id => 'join_coursegroup_form', :method => 'post') do + link_to text, 'javascript:void(0)', :class => 'sy_btn_green fl mr10', :onclick => "$('#join_coursegroup_form').submit();" end end end diff --git a/app/views/boards/_course_show.html.erb b/app/views/boards/_course_show.html.erb index 55d4cca62..9b63dcc88 100644 --- a/app/views/boards/_course_show.html.erb +++ b/app/views/boards/_course_show.html.erb @@ -24,6 +24,11 @@
<%= @board.parent_id.nil? ? "班级讨论区" : "#{@board.name}" %>
+ + <% is_teacher = User.current.logged? && (User.current.admin? || User.current.allowed_to?(:as_teacher,@board.course)) %> + <% if is_teacher %> + <%= link_to "添加子栏目", settings_course_path(@board.course.id,4), :class => "link-blue fr mt5" %> + <% end %>
<% if User.current.logged? %> diff --git a/app/views/courses/_add_members.html.erb b/app/views/courses/_add_members.html.erb new file mode 100644 index 000000000..232587af8 --- /dev/null +++ b/app/views/courses/_add_members.html.erb @@ -0,0 +1,78 @@ +
选择成员加入分班
+
+ +
+ <%= form_tag(add_members_course_path(@course, :group_id => @group.id), method: 'post',:class => "f_l",:id => "add_group_members") do %> +
+ <%=render :partial => 'search_member_list', :locals => {:members => members} %> +
+ <% end %> +
+ +
+ + +
+
+
+ + \ No newline at end of file diff --git a/app/views/courses/_join_or_add.html.erb b/app/views/courses/_join_or_add.html.erb new file mode 100644 index 000000000..8b610672b --- /dev/null +++ b/app/views/courses/_join_or_add.html.erb @@ -0,0 +1,6 @@ +<% if @canShowCode %> + <%= link_to '添加成员', search_not_group_member_course_path(@course,:group_id => @group.id),:remote => true, :class => "sy_btn_green fl mr10" %> +<% else %> + <%= join_in_course_group(@course,@group, User.current) %> + +<% end %> \ No newline at end of file diff --git a/app/views/courses/_new_member_list.html.erb b/app/views/courses/_new_member_list.html.erb index ba4e1cba2..45a36486d 100644 --- a/app/views/courses/_new_member_list.html.erb +++ b/app/views/courses/_new_member_list.html.erb @@ -67,7 +67,7 @@ <% members.each_with_index do |member, i| %> - + <% user = member.user %> <% hw_score = member.score.nil? ? 0 : member.score %> <% ex_score = member.ex_score.nil? ? 0 : member.ex_score %> @@ -116,7 +116,7 @@ <% if @course.course_groups.empty? %> <%=member.course_group_id == 0 ? "暂无" : member.course_group.name %> <% else %> - <%= form_tag({:controller => 'courses', :action => 'teacher_assign_group', :id => @course.id,:user_id => member.user_id},:remote=>'true', :method => 'post', :id=>"join_group_form_#{member.id}", :class => 'query_form') do %> + <%= form_tag({:controller => 'courses', :action => 'teacher_assign_group', :id => @course.id,:user_id => member.user_id, :group_id => @group ? @group.id : -1},:remote=>'true', :method => 'post', :id=>"join_group_form_#{member.id}", :class => 'query_form') do %>
diff --git a/app/views/courses/_search_member_list.html.erb b/app/views/courses/_search_member_list.html.erb new file mode 100644 index 000000000..42196ccfa --- /dev/null +++ b/app/views/courses/_search_member_list.html.erb @@ -0,0 +1,21 @@ +
+
    +
  • + + +
  • +
+ <% unless members.nil? || members.empty? %> + <% members.each do |mem| %> +
    +
  • + + <% student_id = mem.user.user_extensions.student_id %> + +
  • +
+ <% end %> + <% end %> +
+ +
\ No newline at end of file diff --git a/app/views/courses/addgroups.js.erb b/app/views/courses/addgroups.js.erb index 494f26bae..22647e222 100644 --- a/app/views/courses/addgroups.js.erb +++ b/app/views/courses/addgroups.js.erb @@ -1,4 +1,5 @@ $("#st_groups").html("<%= escape_javascript( render :partial => 'new_groups_name', locals: {:course_groups => @course_groups})%>"); $("#member_content").html("<%= escape_javascript( render :partial => 'new_member_list', :locals => {:members => @members})%>"); +$("#group_children_list").html("<%= escape_javascript( render :partial => 'layouts/group_children_list', :locals => {:course => @course})%>"); $('#group_name').val(''); $('#new_group_name').hide(); \ No newline at end of file diff --git a/app/views/courses/group_member.html.erb b/app/views/courses/group_member.html.erb new file mode 100644 index 000000000..73aed1487 --- /dev/null +++ b/app/views/courses/group_member.html.erb @@ -0,0 +1,53 @@ +
+
+

学生列表(<%=@group.name %>)

+
+
    +
  • +
      +
    • <%= link_to l(:label_export_excel), export_course_member_excel_course_path(@course,:group_id => @group.id ,:format => 'xls'), :class => 'hw_more_li'%>
    • + <% if @canShowCode %> +
    • + <%=link_to "成员管理", {:controller => 'courses', :action => 'settings', :id => @course.id, :tab => 'member'}, :class => 'hw_more_li' %> +
    • + <% end %> +
    +
  • +
+
+
+ +
+
+
+
+ <%= render :partial => 'join_or_add'%> +
+ +
+
+
+ +
+ <%= render :partial => 'new_member_list', :locals => {:members => @results} %> +
+
+
+ + \ No newline at end of file diff --git a/app/views/courses/join_group.js.erb b/app/views/courses/join_group.js.erb deleted file mode 100644 index e0db2b440..000000000 --- a/app/views/courses/join_group.js.erb +++ /dev/null @@ -1,2 +0,0 @@ -$("#st_groups").html("<%= escape_javascript( render :partial => 'new_groups_name', locals: {:course_groups => @course_groups})%>"); -$("#member_content").html("<%= escape_javascript( render :partial => @render_file, :locals => {:members => @results})%>"); \ No newline at end of file diff --git a/app/views/courses/search_not_group_member.js.erb b/app/views/courses/search_not_group_member.js.erb new file mode 100644 index 000000000..6fa58ed11 --- /dev/null +++ b/app/views/courses/search_not_group_member.js.erb @@ -0,0 +1,6 @@ +<% if @is_search == 0 %> +var htmlvalue = "<%= escape_javascript( render :partial => 'courses/add_members', :locals => {:members => @members} )%>"; +pop_up_box(htmlvalue,400,30,50); +<% else %> +$("#search_member_list").html("<%= escape_javascript(render :partial => 'search_member_list', :locals => {:members => @members}) %>"); +<% end %> \ No newline at end of file diff --git a/app/views/courses/settings.html.erb b/app/views/courses/settings.html.erb index 654e9ac73..786087892 100644 --- a/app/views/courses/settings.html.erb +++ b/app/views/courses/settings.html.erb @@ -4,6 +4,10 @@