1.修改判断当前用户是否为指定课程成员、学生、老师的方法
2.新建作业时获取当前项目学生方法 3.增加checkbox生成方法
This commit is contained in:
parent
58bb6d269d
commit
e5fec207aa
|
@ -60,7 +60,15 @@ class HomeworkAttachController < ApplicationController
|
||||||
def new
|
def new
|
||||||
@bid = Bid.find(params[:id])
|
@bid = Bid.find(params[:id])
|
||||||
if User.current.admin? || User.current.member_of?(@bid.courses.first)
|
if User.current.admin? || User.current.member_of?(@bid.courses.first)
|
||||||
|
@members = @bid.courses.first.members.joins(:member_roles).where("member_roles.role_id IN (:role_id) and user_id <> #{User.current.id}", {:role_id => [5, 10]})
|
||||||
|
|
||||||
|
#@all_user = []
|
||||||
|
#@bid.courses.first.members.each do |member|
|
||||||
|
# @all_user << member.user
|
||||||
|
#end
|
||||||
@homework = HomeworkAttach.new
|
@homework = HomeworkAttach.new
|
||||||
|
#@homework_user = members_for_homework(@homework) + User.current
|
||||||
|
#@members = @all_user - @homework_user
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html # new.html.erb
|
format.html # new.html.erb
|
||||||
format.json { render json: @homework }
|
format.json { render json: @homework }
|
||||||
|
@ -70,6 +78,19 @@ class HomeworkAttachController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#获取指定作业的所有成员
|
||||||
|
def members_for_homework homework
|
||||||
|
people = []
|
||||||
|
if homework != nil
|
||||||
|
people << homework.user
|
||||||
|
homework.homework_users do |homework_user|
|
||||||
|
people << homework_user.user
|
||||||
|
end
|
||||||
|
else
|
||||||
|
end
|
||||||
|
people
|
||||||
|
end
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
@homework = HomeworkAttach.find(params[:id])
|
@homework = HomeworkAttach.find(params[:id])
|
||||||
if User.current.admin? || User.current.member_of?(@homework.bid.courses.first)
|
if User.current.admin? || User.current.member_of?(@homework.bid.courses.first)
|
||||||
|
|
|
@ -1,3 +1,14 @@
|
||||||
class HomeworkUsersController < ApplicationController
|
class HomeworkUsersController < ApplicationController
|
||||||
|
#新增数据
|
||||||
|
def create option
|
||||||
|
user = HomeworkUser.new option
|
||||||
|
user.save
|
||||||
|
user
|
||||||
|
end
|
||||||
|
#删除数据
|
||||||
|
def destory homework_user
|
||||||
|
user = HomeworkUser.find homework_user
|
||||||
|
user.destroy
|
||||||
|
user
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -138,24 +138,11 @@ module CoursesHelper
|
||||||
end
|
end
|
||||||
#判断制定用户是不是当前课程的老师
|
#判断制定用户是不是当前课程的老师
|
||||||
def is_course_teacher user,course
|
def is_course_teacher user,course
|
||||||
people = []
|
searchPeopleByRoles(course, TeacherRoles).include?(user)
|
||||||
course.members.each do |member|
|
|
||||||
role_id = member.roles.first.id
|
|
||||||
if TeacherRoles.include? role_id
|
|
||||||
people << member.user
|
|
||||||
end
|
|
||||||
end
|
|
||||||
people.include?(user)
|
|
||||||
end
|
end
|
||||||
#当前用户是不是指定课程的学生
|
#当前用户是不是指定课程的学生
|
||||||
def is_cur_course_student? course
|
def is_cur_course_student? course
|
||||||
people = []
|
searchPeopleByRoles(course, StudentRoles).include?(User.current)
|
||||||
course.members.each do |member|
|
|
||||||
if StudentRoles.include? member.roles.first.id
|
|
||||||
people << member.user
|
|
||||||
end
|
|
||||||
end
|
|
||||||
people.include?(User.current)
|
|
||||||
end
|
end
|
||||||
#获取当前用户在指定作业下提交的作业的集合
|
#获取当前用户在指定作业下提交的作业的集合
|
||||||
def cur_user_homework_for_bid bid
|
def cur_user_homework_for_bid bid
|
||||||
|
|
|
@ -9,7 +9,7 @@ module HomeworkAttachHelper
|
||||||
end
|
end
|
||||||
#作业添加、编辑界面的tab页
|
#作业添加、编辑界面的tab页
|
||||||
def homework_settings_tabs f
|
def homework_settings_tabs f
|
||||||
@project = Project.find 205
|
@project = Project.find 76
|
||||||
@f = f
|
@f = f
|
||||||
tabs = [{:name => 'info', :action => :edit_homework, :partial => 'homework_attach/edit_homework', :label => :label_information_plural},
|
tabs = [{:name => 'info', :action => :edit_homework, :partial => 'homework_attach/edit_homework', :label => :label_information_plural},
|
||||||
{:name => 'members', :action => :homework_member, :partial => 'homework_attach/homework_member', :label => :label_member_plural}
|
{:name => 'members', :action => :homework_member, :partial => 'homework_attach/homework_member', :label => :label_member_plural}
|
||||||
|
@ -17,18 +17,27 @@ module HomeworkAttachHelper
|
||||||
#tabs.select {|tab| User.current.allowed_to?(tab[:action], @homework)}
|
#tabs.select {|tab| User.current.allowed_to?(tab[:action], @homework)}
|
||||||
end
|
end
|
||||||
|
|
||||||
def render_principals_for_new_members(project)
|
#作业可选成员列表分页
|
||||||
scope = Principal.active.sorted.not_member_of(project).like(params[:q])
|
def render_new_members_for_homework members
|
||||||
principal_count = scope.count
|
#scope = Principal.active.sorted.not_member_of(project).like(params[:q])
|
||||||
principal_pages = Redmine::Pagination::Paginator.new principal_count, 10, params['page'] #by young
|
#scope = project.members
|
||||||
principals = scope.offset(principal_pages.offset).limit(principal_pages.per_page).all
|
principal_count = members.count
|
||||||
|
limit = 10
|
||||||
s = content_tag('div', principals_check_box_tags_ex('membership[user_ids][]', principals), :id => 'principals')
|
principal_pages = Redmine::Pagination::Paginator.new principal_count, limit, params['page'] #by young
|
||||||
|
offset ||= principal_pages.offset
|
||||||
links = pagination_links_full(principal_pages, principal_count, :per_page_links => false) {|text, parameters, options|
|
principals = members[offset, limit]
|
||||||
link_to text, autocomplete_project_memberships_path(project, parameters.merge(:q => params[:q], :format => 'js')), :remote => true
|
s = content_tag('div', member_check_box_tags_ex('membership[user_ids][]', principals), :id => 'principals')
|
||||||
}
|
links = pagination_links_full(principal_pages, principal_count, :per_page_links => false,:remote => true)
|
||||||
|
|
||||||
s + content_tag('div', content_tag('ul', links), :class => 'pagination_new')
|
s + content_tag('div', content_tag('ul', links), :class => 'pagination_new')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#扩展的checkbox生成
|
||||||
|
def member_check_box_tags_ex(name, principals)
|
||||||
|
s = ''
|
||||||
|
principals.each do |member|
|
||||||
|
s << "<label>#{ check_box_tag name, member.id, false, :id => nil } #{h member.user.name }</label>\n"
|
||||||
|
end
|
||||||
|
s.html_safe
|
||||||
|
end
|
||||||
end
|
end
|
Loading…
Reference in New Issue