1.修改判断当前用户是否为指定课程成员、学生、老师的方法
2.新建作业时获取当前项目学生方法 3.增加checkbox生成方法
This commit is contained in:
parent
58bb6d269d
commit
e5fec207aa
|
@ -60,7 +60,15 @@ class HomeworkAttachController < ApplicationController
|
|||
def new
|
||||
@bid = Bid.find(params[:id])
|
||||
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_user = members_for_homework(@homework) + User.current
|
||||
#@members = @all_user - @homework_user
|
||||
respond_to do |format|
|
||||
format.html # new.html.erb
|
||||
format.json { render json: @homework }
|
||||
|
@ -70,6 +78,19 @@ class HomeworkAttachController < ApplicationController
|
|||
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
|
||||
@homework = HomeworkAttach.find(params[:id])
|
||||
if User.current.admin? || User.current.member_of?(@homework.bid.courses.first)
|
||||
|
|
|
@ -1,3 +1,14 @@
|
|||
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
|
||||
|
|
|
@ -138,24 +138,11 @@ module CoursesHelper
|
|||
end
|
||||
#判断制定用户是不是当前课程的老师
|
||||
def is_course_teacher user,course
|
||||
people = []
|
||||
course.members.each do |member|
|
||||
role_id = member.roles.first.id
|
||||
if TeacherRoles.include? role_id
|
||||
people << member.user
|
||||
end
|
||||
end
|
||||
people.include?(user)
|
||||
searchPeopleByRoles(course, TeacherRoles).include?(user)
|
||||
end
|
||||
#当前用户是不是指定课程的学生
|
||||
def is_cur_course_student? course
|
||||
people = []
|
||||
course.members.each do |member|
|
||||
if StudentRoles.include? member.roles.first.id
|
||||
people << member.user
|
||||
end
|
||||
end
|
||||
people.include?(User.current)
|
||||
searchPeopleByRoles(course, StudentRoles).include?(User.current)
|
||||
end
|
||||
#获取当前用户在指定作业下提交的作业的集合
|
||||
def cur_user_homework_for_bid bid
|
||||
|
|
|
@ -9,7 +9,7 @@ module HomeworkAttachHelper
|
|||
end
|
||||
#作业添加、编辑界面的tab页
|
||||
def homework_settings_tabs f
|
||||
@project = Project.find 205
|
||||
@project = Project.find 76
|
||||
@f = f
|
||||
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}
|
||||
|
@ -17,18 +17,27 @@ module HomeworkAttachHelper
|
|||
#tabs.select {|tab| User.current.allowed_to?(tab[:action], @homework)}
|
||||
end
|
||||
|
||||
def render_principals_for_new_members(project)
|
||||
scope = Principal.active.sorted.not_member_of(project).like(params[:q])
|
||||
principal_count = scope.count
|
||||
principal_pages = Redmine::Pagination::Paginator.new principal_count, 10, params['page'] #by young
|
||||
principals = scope.offset(principal_pages.offset).limit(principal_pages.per_page).all
|
||||
|
||||
s = content_tag('div', principals_check_box_tags_ex('membership[user_ids][]', principals), :id => 'principals')
|
||||
|
||||
links = pagination_links_full(principal_pages, principal_count, :per_page_links => false) {|text, parameters, options|
|
||||
link_to text, autocomplete_project_memberships_path(project, parameters.merge(:q => params[:q], :format => 'js')), :remote => true
|
||||
}
|
||||
#作业可选成员列表分页
|
||||
def render_new_members_for_homework members
|
||||
#scope = Principal.active.sorted.not_member_of(project).like(params[:q])
|
||||
#scope = project.members
|
||||
principal_count = members.count
|
||||
limit = 10
|
||||
principal_pages = Redmine::Pagination::Paginator.new principal_count, limit, params['page'] #by young
|
||||
offset ||= principal_pages.offset
|
||||
principals = members[offset, limit]
|
||||
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')
|
||||
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
|
|
@ -36,7 +36,7 @@ module MembersHelper
|
|||
# 当前申请加入的成员名单
|
||||
def render_principals_for_applied_members(project)
|
||||
scope = Principal.active.sorted.applied_members(project).like(params[:q])
|
||||
principal_count = scope.count
|
||||
principal_count = scope.count
|
||||
principal_pages = Redmine::Pagination::Paginator.new principal_count, 10, params['page']
|
||||
principals = scope.offset(principal_pages.offset).limit(principal_pages.per_page).all
|
||||
|
||||
|
|
Loading…
Reference in New Issue