From d0dd6eb78151f4952252c655486983c7588cc323 Mon Sep 17 00:00:00 2001
From: sw <939547590@qq.com>
Date: Wed, 11 Jun 2014 15:28:13 +0800
Subject: [PATCH] =?UTF-8?q?1.=E4=BF=AE=E6=94=B9=E4=BD=9C=E4=B8=9A=E6=97=B6?=
=?UTF-8?q?=E5=AE=9E=E7=8E=B0=E4=BD=9C=E4=B8=9A=E6=B7=BB=E5=8A=A0=E5=8F=82?=
=?UTF-8?q?=E4=B8=8E=E4=BA=BA=E5=91=98=E4=B8=8E=E5=88=A0=E9=99=A4=E5=8F=82?=
=?UTF-8?q?=E4=B8=8E=E4=BA=BA=E5=91=98=202.homework=5Fattach=E3=80=81homew?=
=?UTF-8?q?ork=5Fuser=E3=80=81users=E5=85=B3=E7=B3=BB=E6=B7=BB=E5=8A=A0=20?=
=?UTF-8?q?3.=E4=BC=98=E5=8C=96=E9=A1=B5=E9=9D=A2=E6=98=BE=E7=A4=BA?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/controllers/homework_attach_controller.rb | 82 +++++++++++-----
app/helpers/homework_attach_helper.rb | 9 +-
app/models/homework_attach.rb | 1 +
app/models/homework_user.rb | 2 +-
app/models/user.rb | 3 +-
.../homework_attach/_homework_member.html.erb | 40 +++++---
.../homework_attach/add_homework_users.js.erb | 1 +
.../destory_homework_users.js.erb | 1 +
app/views/homework_attach/edit.html.erb | 94 ++++++++++++-------
app/views/homework_attach/new.html.erb | 57 +++++------
config/routes.rb | 5 +
11 files changed, 181 insertions(+), 114 deletions(-)
create mode 100644 app/views/homework_attach/add_homework_users.js.erb
create mode 100644 app/views/homework_attach/destory_homework_users.js.erb
diff --git a/app/controllers/homework_attach_controller.rb b/app/controllers/homework_attach_controller.rb
index cd7c0b81..a3a48407 100644
--- a/app/controllers/homework_attach_controller.rb
+++ b/app/controllers/homework_attach_controller.rb
@@ -26,13 +26,39 @@ class HomeworkAttachController < ApplicationController
end
end
- def add_users users
- if users != nil && users.count > 0
- users.each do |user|
- @homework.homework_users.build(:user_id => user.id)
- @homework.save
+ #作业添加成员(参与人员)
+ def add_homework_users
+ @homework = HomeworkAttach.find(params[:id])
+
+ if params[:membership]
+ if params[:membership][:user_ids]
+ attrs = params[:membership].dup
+ user_ids = attrs.delete(:user_ids)
+ user_ids.each do |user_id|
+ @homework.homework_users.build(:user_id => user_id)
+ end
end
end
+ @homework.save
+ @hoemwork_users = users_for_homework(@homework)
+ @members = members_for_homework(@homework,@hoemwork_users)
+ @members = paginateHelper @members,10
+ respond_to do |format|
+ format.js
+ end
+ end
+
+ #作业删除成员(参与人员)
+ def destory_homework_users
+ @homework = HomeworkAttach.find(params[:id])
+ homework_user = @homework.homework_users.where("user_id = #{params[:user_id]}").first
+ homework_user.destroy
+ @hoemwork_users = users_for_homework(@homework)
+ @members = members_for_homework(@homework,@hoemwork_users)
+ @members = paginateHelper @members,10
+ respond_to do |format|
+ format.js
+ end
end
def create
@@ -78,10 +104,10 @@ 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]})
+ #该课程的学生的集合(新建不实现功能:添加成员)
+ #@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]})
- @members = paginateHelper @members,10
+ #@members = paginateHelper @members,10
#@all_user = []
#@bid.courses.first.members.each do |member|
# @all_user << member.user
@@ -98,38 +124,43 @@ class HomeworkAttachController < ApplicationController
end
end
+ #获取作业成员的集合
def get_homework_member_list
- @bid = Bid.find(params[:bid_id])
- if User.current.admin? || User.current.member_of?(@bid.courses.first)
+ @homework = HomeworkAttach.includes(:homework_users).includes(:user).find(params[:bid_id])
+ course = @homework.bid.courses.first
+ if User.current.admin? || User.current.member_of?(course)
+ @hoemwork_users = users_for_homework(@homework)
+ @members = members_for_homework(@homework,@hoemwork_users)
#该课程的学生的集合
- @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]})
-
+ #@members = course.members.joins(:member_roles).where("member_roles.role_id IN (:role_id)", {:role_id => [5, 10]})
@members = paginateHelper @members,10
else
raise "error"
end
-
respond_to do |format|
format.js
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
+ def users_for_homework homework
+ homework.nil? ? [] : (homework.users + [homework.user])
+ end
+
+ #获取可选成员列表
+ #homework:作业
+ #users:该作业所有成员
+ def members_for_homework homework,users
+ homework.bid.courses.first.members.joins(:member_roles).where("member_roles.role_id IN (:role_id) and user_id not in (:users)", {:role_id => [5, 10],:users => users})
end
def edit
- @homework = HomeworkAttach.find(params[:id])
+ @homework = HomeworkAttach.includes(:homework_users).includes(:user).find(params[:id])
if User.current.admin? || User.current.member_of?(@homework.bid.courses.first)
+ #@members = @homework.bid.courses.first.members.joins(:member_roles).where("member_roles.role_id IN (:role_id)", {:role_id => [5, 10]})
+ @hoemwork_users = users_for_homework(@homework)
+ @members = members_for_homework(@homework,@hoemwork_users)
+ @members = paginateHelper @members,10
else
render_403 :message => :notice_not_authorized
end
@@ -137,7 +168,8 @@ class HomeworkAttachController < ApplicationController
def update
@homework = HomeworkAttach.find(params[:id])
- if User.current.admin? || User.current.member_of?(@homework.bid.courses.first)
+ course = @homework.bid.courses.first
+ if User.current.admin? || User.current.member_of?(course)
name = params[:homework_name]
description = params[:homework_description]
@homework.name = name
diff --git a/app/helpers/homework_attach_helper.rb b/app/helpers/homework_attach_helper.rb
index 0e34573e..28bb48d3 100644
--- a/app/helpers/homework_attach_helper.rb
+++ b/app/helpers/homework_attach_helper.rb
@@ -20,15 +20,16 @@ module HomeworkAttachHelper
#scope = Principal.active.sorted.not_member_of(project).like(params[:q])
#scope = project.members
#principals = paginateHelper members,10
- principals = members
+ #principals = 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')
+ users = members.map(&:user)
+ s = content_tag('div', member_check_box_tags_ex('membership[user_ids][]', users), :id => 'principals')
links = pagination_links_full(@obj_pages, @obj_count, :per_page_links => false) {|text, parameters, options|
- link_to text, get_homework_member_list_homework_attach_index_path( parameters.merge(:q => params[:q], bid_id: params[:id]||@bid)), :remote => true }
+ link_to text, get_homework_member_list_homework_attach_index_path( parameters.merge(:q => params[:q], bid_id: params[:id]||@homework)), :remote => true }
return s + content_tag('div', content_tag('ul', links), :class => 'pagination_new')
end
@@ -36,7 +37,7 @@ module HomeworkAttachHelper
def member_check_box_tags_ex(name, principals)
s = ''
principals.each do |member|
- s << "
"
+ s << "
"
end
s.html_safe
end
diff --git a/app/models/homework_attach.rb b/app/models/homework_attach.rb
index ad59d107..c801885b 100644
--- a/app/models/homework_attach.rb
+++ b/app/models/homework_attach.rb
@@ -7,6 +7,7 @@ class HomeworkAttach < ActiveRecord::Base
belongs_to :bid
has_many :journals_for_messages, :as => :jour, :dependent => :destroy
has_many :homework_users, :dependent => :destroy
+ has_many :users, :through => :homework_users
seems_rateable :allow_update => true, :dimensions => :quality
safe_attributes "bid_id",
diff --git a/app/models/homework_user.rb b/app/models/homework_user.rb
index 0adef62c..df75ef82 100644
--- a/app/models/homework_user.rb
+++ b/app/models/homework_user.rb
@@ -1,6 +1,6 @@
class HomeworkUser < ActiveRecord::Base
attr_accessible :homework_attach_id, :user_id
- belongs_to :homework_attach
+ belongs_to :homework_attach, :foreign_key => :homework_attach_id
belongs_to :user
end
diff --git a/app/models/user.rb b/app/models/user.rb
index 331ff699..c0b1ba24 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -73,7 +73,8 @@ class User < Principal
['none', :label_user_mail_option_none]
]
- belongs_to :homework_user
+ has_many :homework_users
+ has_many :homework_attaches, :through => :homework_users
has_and_belongs_to_many :groups, :after_add => Proc.new {|user, group| group.user_added(user)},
:after_remove => Proc.new {|user, group| group.user_removed(user)}
diff --git a/app/views/homework_attach/_homework_member.html.erb b/app/views/homework_attach/_homework_member.html.erb
index ff25064a..a372f105 100644
--- a/app/views/homework_attach/_homework_member.html.erb
+++ b/app/views/homework_attach/_homework_member.html.erb
@@ -1,5 +1,6 @@
<%= error_messages_for 'member' %>
-
<%= link_to_user User.current %> | + +|||
<%= link_to_user homework.user %> | 发布人员 | -删除 | +|
<%= link_to_user user %> | +开发人员 | +<%= link_to l(:button_delete),destory_homework_users_homework_attach_path(:user_id=>user),:remote => true, :method => :post %> | + <% end %> +
<%=raw l(:label_new_homework)%>
-<%=raw l(:label_edit_homework)%>
+- 标 题: - <%= f.text_field :name, :required => true, :name => "homework_name", :size => 60, :style => "width:490px;"%> -
-- 描 述: - - <%= f.text_area :description, :rows => 8, :name => "homework_description", :class => 'wiki-edit', :style => "font-size:small;width:490px;margin-left:10px;" %> - -
--
- -- - <%= submit_tag t(:label_button_ok), :sta => 0, :class => "enterprise"%> - -
++ 标 题: + <%= f.text_field :name, :required => true, :name => "homework_name", :size => 60, :style => "width:490px;"%> +
++ 描 述: + + <%= f.text_area :description, :rows => 8, :name => "homework_description", :class => 'wiki-edit', :style => "font-size:small;width:490px;margin-left:10px;" %> + +
++
+ ++ + <%= submit_tag t(:label_button_ok), :sta => 0, :class => "enterprise"%> + +
<% end %> -<%=h l(:label_new_homework)%>
+ 标 题: + <%= f.text_field "name", :required => true, :size => 60, :style => "width:490px;" %> +
++ 描 述: + + <%= f.text_area "description", :rows => 8, :class => 'wiki-edit', :style => "font-size:small;width:490px;margin-left:10px;" %> + +
++
+ -+
<%= submit_tag t(:label_button_ok), :sta => 0, :class => "enterprise"%>
<% end %> -