diff --git a/app/controllers/members_controller.rb b/app/controllers/members_controller.rb
index 5435a2d61..daf11b33f 100644
--- a/app/controllers/members_controller.rb
+++ b/app/controllers/members_controller.rb
@@ -1,3 +1,4 @@
+# -*coding:utf-8 -*-
# Redmine - project management software
# Copyright (C) 2006-2013 Jean-Philippe Lang
#
@@ -14,6 +15,7 @@
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
class MembersController < ApplicationController
model_object Member
before_filter :find_model_object, :except => [:index, :create, :autocomplete]
@@ -124,7 +126,13 @@ class MembersController < ApplicationController
attrs = params[:membership].dup
user_ids = attrs.delete(:user_ids)
user_ids.each do |user_id|
- members << Member.new(:role_ids => params[:membership][:role_ids], :user_id => user_id)
+ member = Member.new(:role_ids => params[:membership][:role_ids], :user_id => user_id)
+ role = Role.find_by_id(params[:membership][:role_ids])
+ # 这里的判断只能通过角色名,可以弄成常量
+ if role.name == "学生"
+ StudentsForCourse.create(:student_id => user_id, :course_id =>@course.id)
+ end
+ members << member
#user_grades << UserGrade.new(:user_id => user_id, :course_id => @course.id)
if (params[:membership][:role_ids])
role = Role.find(params[:membership][:role_ids][0])
@@ -201,6 +209,15 @@ class MembersController < ApplicationController
if (params[:membership][:role_ids])
role = Role.find(params[:membership][:role_ids][0])
+ # 这里的判断只能通过角色名,可以弄成常量
+ if role.name == "学生"
+ StudentsForCourse.create(:student_id => @member.user_id, :course_id =>@course.id)
+ else
+ joined = StudentsForCourse.where('student_id = ? and course_id = ?', @member.user_id,@course.id)
+ joined.each do |join|
+ join.delete
+ end
+ end
if role.allowed_to?(:is_manager)
@courseInfo = CourseInfos.new(:user_id => @member.user_id, :course_id => @course.id)
@courseInfo.save
@@ -271,6 +288,11 @@ class MembersController < ApplicationController
user.destroy
end
end
+ joined = StudentsForCourse.where('student_id = ? and course_id = ?', @member.user_id,@course.id)
+ joined.each do |join|
+ join.delete
+ end
+
end
respond_to do |format|
format.html { redirect_to_settings_in_courses }
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index e81355260..c074be37b 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -642,9 +642,9 @@ class UsersController < ApplicationController
return
end
if @obj.save
- ## 执行成功的操作。
+ logger.debug "#{__FILE__}:#{__LINE__} ===> #{@obj.to_json}"
else
- #捕获异常
+ logger.error "#{__FILE__}:#{__LINE__} ===> #{@obj.errors.try(:full_messages)}"
end
respond_to do |format|
format.js
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index bf125972b..e3b2df048 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -474,11 +474,16 @@ module ApplicationHelper
def principals_check_box_tags_ex(name, principals)
s = ''
principals.each do |principal|
- if principal.has_attribute?(:userInfo)
- s << "\n"
- else
- s << "\n"
- end
+ s << "\n"
+ end
+ s.html_safe
+ end
+
+ #扩展的checkbox生成
+ def principals_radio_box_tags_ex(name, principals)
+ s = ''
+ principals.each do |principal|
+ s << "\n"
end
s.html_safe
end
diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb
index b4b89bb0f..033b6405c 100644
--- a/app/helpers/courses_helper.rb
+++ b/app/helpers/courses_helper.rb
@@ -104,10 +104,25 @@ module CoursesHelper
garble count
end
- alias studentCountOrigin studentCount
+ # 注意:此方法有问题,速度慢且结果不准
+ # alias studentCountOrigin studentCount
+ #def studentCount course
+ # count = studentCountOrigin course
+ #garble count
+ # end
+
+ # 学生人数计算
+ # add by nwb
def studentCount course
- count = studentCountOrigin course
- garble count
+ count = course.student.count
+ if count <= 5
+ result = count.to_s
+ elsif count < 10 && count > 5
+ result = "5+"
+ else
+ result = (count-count % 10).to_s + "+"
+ end
+ result
end
def eventToLanguageCourse event_type, course
diff --git a/app/helpers/stores_helper.rb b/app/helpers/stores_helper.rb
index b4cd47eb1..5a161dc85 100644
--- a/app/helpers/stores_helper.rb
+++ b/app/helpers/stores_helper.rb
@@ -42,7 +42,6 @@ module StoresHelper
container = attachment.container
case container.class.to_s
when 'Message'
- # binding.pry
# '项目 > zzz > 论坛 > 帖子xxx'
# topic_str = container.project.project_type == 0 ? l(:label_board) : l(:label_new_course)
diff --git a/app/models/course.rb b/app/models/course.rb
index f68832476..45830c719 100644
--- a/app/models/course.rb
+++ b/app/models/course.rb
@@ -21,7 +21,7 @@ class Course < ActiveRecord::Base
has_many :homeworks, :through => :homework_for_courses, :source => :bid, :dependent => :destroy
has_many :journals_for_messages, :as => :jour, :dependent => :destroy
has_many :homework_for_courses, :dependent => :destroy
- has_many :student, :through => :students_for_courses, :source => :user
+ has_many :student, :class_name => 'StudentsForCourse', :source => :user
has_many :course_infos, :class_name => 'CourseInfos',:dependent => :destroy
has_many :enabled_modules, :dependent => :delete_all
has_many :boards, :dependent => :destroy, :order => "position ASC"
@@ -36,10 +36,10 @@ class Course < ActiveRecord::Base
validates_presence_of :password, :term,:name
validates_format_of :class_period, :with =>/^[1-9]\d*$/
- validates_format_of :name,:with =>/^[a-zA-Z0-9_\u4e00-\u9fa5]+$/
+ #validates_format_of :name,:with =>/^[a-zA-Z0-9_\u4e00-\u9fa5]+$/
before_save :self_validate
- after_save :create_board_sync
+ after_create :create_board_sync
before_destroy :delete_all_members
safe_attributes 'extra',
diff --git a/app/models/issue.rb b/app/models/issue.rb
index f47e1c6f9..4c5e77cb5 100644
--- a/app/models/issue.rb
+++ b/app/models/issue.rb
@@ -564,8 +564,10 @@ class Issue < ActiveRecord::Base
end
# 缺陷的短描述信息
def short_description(length = 255)
- description.gsub(/<\/?.*?>/,"").html_safe if description
+ # 不再使用短描述
+ #description.gsub(/<\/?.*?>/,"").html_safe if description
#description.gsub(/^(.{#{length}}[^\n\r]*).*$/m, '\1...').strip if description
+ description
end
private :workflow_rule_by_attribute
diff --git a/app/models/news.rb b/app/models/news.rb
index 66e339291..860dd0baa 100644
--- a/app/models/news.rb
+++ b/app/models/news.rb
@@ -76,8 +76,10 @@ class News < ActiveRecord::Base
# 新闻的短描述信息
def short_description(length = 255)
- description.gsub(/<\/?.*?>/,"").html_safe if description
+ #description.gsub(/<\/?.*?>/,"").html_safe if description
#description.gsub(/^(.{#{length}}[^\n\r]*).*$/m, '\1...').strip if description
+ # 不再使用短描述
+ description
end
private
diff --git a/app/models/open_source_project.rb b/app/models/open_source_project.rb
index 2de5966bb..4a657edb4 100644
--- a/app/models/open_source_project.rb
+++ b/app/models/open_source_project.rb
@@ -85,7 +85,9 @@ class OpenSourceProject < ActiveRecord::Base
def short_description(length = 255)
#description.gsub(/^(.{#{length}}[^\n\r]*).*$/m, '\1...').strip if description
- description.gsub(/<\/?.*?>/,"").html_safe if description
+ #description.gsub(/<\/?.*?>/,"").html_safe if description
+ # 不再使用短描述
+ description
end
def applied_by?(user)
diff --git a/app/models/project.rb b/app/models/project.rb
index b68fc6aa9..6c453baa9 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -127,7 +127,7 @@ class Project < ActiveRecord::Base
after_save :update_position_under_parent, :if => Proc.new {|project| project.name_changed?}
after_save :update_inherited_members, :if => Proc.new {|project| project.inherit_members_changed?}
# 创建project之后默认创建一个board,之后的board去掉了board的概念
- after_save :create_board_sync
+ after_create :create_board_sync
before_destroy :delete_all_members
def remove_references_before_destroy
return if self.id.nil?
@@ -630,7 +630,9 @@ class Project < ActiveRecord::Base
# Returns a short description of the projects (first lines)
def short_description(length = 255)
#description.gsub(/^(.{#{length}}[^\n\r]*).*$/m, '\1...').strip if description
- description.gsub(/<\/?.*?>/,"").html_safe if description
+ # 不再使用短描述
+ # description.gsub(/<\/?.*?>/,"").html_safe if description
+ description
end
def css_classes
diff --git a/app/views/contestnotifications/index.html.erb b/app/views/contestnotifications/index.html.erb
index fc71bc64a..0cf722851 100644
--- a/app/views/contestnotifications/index.html.erb
+++ b/app/views/contestnotifications/index.html.erb
@@ -77,7 +77,7 @@
<%= stylesheet_link_tag 'scm' %>
<% end %>
- <% html_title(l(:label_news_plural)) -%>
+ <% html_title(l(:label_contest_notification)) -%>