This commit is contained in:
sw 2014-07-18 14:15:52 +08:00
commit 46c7a4bb9f
21 changed files with 1327 additions and 1296 deletions

View File

@ -1,3 +1,4 @@
# -*coding:utf-8 -*-
# Redmine - project management software # Redmine - project management software
# Copyright (C) 2006-2013 Jean-Philippe Lang # Copyright (C) 2006-2013 Jean-Philippe Lang
# #
@ -14,6 +15,7 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class MembersController < ApplicationController class MembersController < ApplicationController
model_object Member model_object Member
before_filter :find_model_object, :except => [:index, :create, :autocomplete] before_filter :find_model_object, :except => [:index, :create, :autocomplete]
@ -124,7 +126,13 @@ class MembersController < ApplicationController
attrs = params[:membership].dup attrs = params[:membership].dup
user_ids = attrs.delete(:user_ids) user_ids = attrs.delete(:user_ids)
user_ids.each do |user_id| 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) #user_grades << UserGrade.new(:user_id => user_id, :course_id => @course.id)
if (params[:membership][:role_ids]) if (params[:membership][:role_ids])
role = Role.find(params[:membership][:role_ids][0]) role = Role.find(params[:membership][:role_ids][0])
@ -201,6 +209,15 @@ class MembersController < ApplicationController
if (params[:membership][:role_ids]) if (params[:membership][:role_ids])
role = Role.find(params[:membership][:role_ids][0]) 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) if role.allowed_to?(:is_manager)
@courseInfo = CourseInfos.new(:user_id => @member.user_id, :course_id => @course.id) @courseInfo = CourseInfos.new(:user_id => @member.user_id, :course_id => @course.id)
@courseInfo.save @courseInfo.save
@ -271,6 +288,11 @@ class MembersController < ApplicationController
user.destroy user.destroy
end end
end end
joined = StudentsForCourse.where('student_id = ? and course_id = ?', @member.user_id,@course.id)
joined.each do |join|
join.delete
end
end end
respond_to do |format| respond_to do |format|
format.html { redirect_to_settings_in_courses } format.html { redirect_to_settings_in_courses }

View File

@ -642,9 +642,9 @@ class UsersController < ApplicationController
return return
end end
if @obj.save if @obj.save
## 执行成功的操作。 logger.debug "#{__FILE__}:#{__LINE__} ===> #{@obj.to_json}"
else else
#捕获异常 logger.error "#{__FILE__}:#{__LINE__} ===> #{@obj.errors.try(:full_messages)}"
end end
respond_to do |format| respond_to do |format|
format.js format.js

View File

@ -474,11 +474,16 @@ module ApplicationHelper
def principals_check_box_tags_ex(name, principals) def principals_check_box_tags_ex(name, principals)
s = '' s = ''
principals.each do |principal| principals.each do |principal|
if principal.has_attribute?(:userInfo)
s << "<label>#{ check_box_tag name, principal.id, false, :id => nil } #{h principal.userInfo }</label>\n" s << "<label>#{ check_box_tag name, principal.id, false, :id => nil } #{h principal.userInfo }</label>\n"
else
s << "<label>#{ check_box_tag name, principal.id, false, :id => nil } #{h principal}</label>\n"
end end
s.html_safe
end
#扩展的checkbox生成
def principals_radio_box_tags_ex(name, principals)
s = ''
principals.each do |principal|
s << "<label>#{ radio_button_tag name, principal.id, false, :id => nil } #{h principal.userInfo }</label>\n"
end end
s.html_safe s.html_safe
end end

View File

@ -104,10 +104,25 @@ module CoursesHelper
garble count garble count
end end
alias studentCountOrigin studentCount # 注意:此方法有问题,速度慢且结果不准
# alias studentCountOrigin studentCount
#def studentCount course
# count = studentCountOrigin course
#garble count
# end
# 学生人数计算
# add by nwb
def studentCount course def studentCount course
count = studentCountOrigin course count = course.student.count
garble 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 end
def eventToLanguageCourse event_type, course def eventToLanguageCourse event_type, course

View File

@ -42,7 +42,6 @@ module StoresHelper
container = attachment.container container = attachment.container
case container.class.to_s case container.class.to_s
when 'Message' when 'Message'
# binding.pry
# '项目 > zzz > 论坛 > 帖子xxx' # '项目 > zzz > 论坛 > 帖子xxx'
# topic_str = container.project.project_type == 0 ? l(:label_board) : l(:label_new_course) # topic_str = container.project.project_type == 0 ? l(:label_board) : l(:label_new_course)

View File

@ -21,7 +21,7 @@ class Course < ActiveRecord::Base
has_many :homeworks, :through => :homework_for_courses, :source => :bid, :dependent => :destroy has_many :homeworks, :through => :homework_for_courses, :source => :bid, :dependent => :destroy
has_many :journals_for_messages, :as => :jour, :dependent => :destroy has_many :journals_for_messages, :as => :jour, :dependent => :destroy
has_many :homework_for_courses, :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 :course_infos, :class_name => 'CourseInfos',:dependent => :destroy
has_many :enabled_modules, :dependent => :delete_all has_many :enabled_modules, :dependent => :delete_all
has_many :boards, :dependent => :destroy, :order => "position ASC" has_many :boards, :dependent => :destroy, :order => "position ASC"
@ -36,10 +36,10 @@ class Course < ActiveRecord::Base
validates_presence_of :password, :term,:name validates_presence_of :password, :term,:name
validates_format_of :class_period, :with =>/^[1-9]\d*$/ 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 before_save :self_validate
after_save :create_board_sync after_create :create_board_sync
before_destroy :delete_all_members before_destroy :delete_all_members
safe_attributes 'extra', safe_attributes 'extra',

View File

@ -564,8 +564,10 @@ class Issue < ActiveRecord::Base
end end
# 缺陷的短描述信息 # 缺陷的短描述信息
def short_description(length = 255) 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.gsub(/^(.{#{length}}[^\n\r]*).*$/m, '\1...').strip if description
description
end end
private :workflow_rule_by_attribute private :workflow_rule_by_attribute

View File

@ -76,8 +76,10 @@ class News < ActiveRecord::Base
# 新闻的短描述信息 # 新闻的短描述信息
def short_description(length = 255) 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.gsub(/^(.{#{length}}[^\n\r]*).*$/m, '\1...').strip if description
# 不再使用短描述
description
end end
private private

View File

@ -85,7 +85,9 @@ class OpenSourceProject < ActiveRecord::Base
def short_description(length = 255) def short_description(length = 255)
#description.gsub(/^(.{#{length}}[^\n\r]*).*$/m, '\1...').strip if description #description.gsub(/^(.{#{length}}[^\n\r]*).*$/m, '\1...').strip if description
description.gsub(/<\/?.*?>/,"").html_safe if description #description.gsub(/<\/?.*?>/,"").html_safe if description
# 不再使用短描述
description
end end
def applied_by?(user) def applied_by?(user)

View File

@ -127,7 +127,7 @@ class Project < ActiveRecord::Base
after_save :update_position_under_parent, :if => Proc.new {|project| project.name_changed?} 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?} after_save :update_inherited_members, :if => Proc.new {|project| project.inherit_members_changed?}
# 创建project之后默认创建一个board之后的board去掉了board的概念 # 创建project之后默认创建一个board之后的board去掉了board的概念
after_save :create_board_sync after_create :create_board_sync
before_destroy :delete_all_members before_destroy :delete_all_members
def remove_references_before_destroy def remove_references_before_destroy
return if self.id.nil? return if self.id.nil?
@ -630,7 +630,9 @@ class Project < ActiveRecord::Base
# Returns a short description of the projects (first lines) # Returns a short description of the projects (first lines)
def short_description(length = 255) def short_description(length = 255)
#description.gsub(/^(.{#{length}}[^\n\r]*).*$/m, '\1...').strip if description #description.gsub(/^(.{#{length}}[^\n\r]*).*$/m, '\1...').strip if description
description.gsub(/<\/?.*?>/,"").html_safe if description # 不再使用短描述
# description.gsub(/<\/?.*?>/,"").html_safe if description
description
end end
def css_classes def css_classes

View File

@ -77,7 +77,7 @@
<%= stylesheet_link_tag 'scm' %> <%= stylesheet_link_tag 'scm' %>
<% end %> <% end %>
<% html_title(l(:label_news_plural)) -%> <% html_title(l(:label_contest_notification)) -%>
</div> </div>
<script type='text/javascript'> <script type='text/javascript'>

View File

@ -14,7 +14,7 @@
<% unless contest.author.nil? %> <% unless contest.author.nil? %>
<%= link_to(contest.author, user_path(contest.author), :class => 'bid_user') %>: <%= link_to(contest.author, user_path(contest.author), :class => 'bid_user') %>:
<% end %> <% end %>
&nbsp;<%= link_to(contest.name, show_contest_contest_path(contest), :class => 'bid_path', :target => "_blank") %></strong></td> &nbsp;<%= link_to(contest.name, contest_contestnotifications_path(contest), :class => 'bid_path', :target => "_blank") %></strong></td>
</tr> </tr>
<tr> <tr>
<td width="500"> <td width="500">

View File

@ -32,7 +32,7 @@
<p> <p>
<% roles.each do |role| %> <% roles.each do |role| %>
<label><%= check_box_tag 'membership[role_ids][]', role.id, member.roles.include?(role), <label><%= radio_button_tag 'membership[role_ids][]', role.id, member.roles.include?(role),
:disabled => member.member_roles.detect { |mr| mr.role_id == role.id && !mr.inherited_from.nil? } %> <%= h role %></label><br/> :disabled => member.member_roles.detect { |mr| mr.role_id == role.id && !mr.inherited_from.nil? } %> <%= h role %></label><br/>
<% end %></p> <% end %></p>
<%= hidden_field_tag 'membership[role_ids][]', '' %> <%= hidden_field_tag 'membership[role_ids][]', '' %>
@ -82,7 +82,7 @@
<p style="padding-top: 5px"><%= l(:label_role_plural) %>: <p style="padding-top: 5px"><%= l(:label_role_plural) %>:
<% roles.each do |role| %> <% roles.each do |role| %>
<label><%= check_box_tag 'membership[role_ids][]', role.id %> <%= h role %></label> <label><%= radio_button_tag 'membership[role_ids][]', role.id %> <%= h role %></label>
<% end %></p> <% end %></p>
<p><%= submit_tag l(:button_add), :id => 'member-add-submit' %></p> <p><%= submit_tag l(:button_add), :id => 'member-add-submit' %></p>

View File

@ -215,9 +215,9 @@
<% if display_main_menu?(@contest) %> <% if display_main_menu?(@contest) %>
<div class="tabs_new"> <div class="tabs_new">
<ul> <ul>
<li ><%= link_to l(:label_contest_userresponse), show_contest_contest_path(@contest), :class => link_class(:respond) %></li>
<li><%= link_to l(:label_contest_joincontest), show_attendingcontest_contest_path(@contest), :class => link_class(:attendingcontests) %></li>
<li><%= link_to l(:label_contest_notification), contest_contestnotifications_path(@contest), :class => link_class(:contestnotifications) %></li> <li><%= link_to l(:label_contest_notification), contest_contestnotifications_path(@contest), :class => link_class(:contestnotifications) %></li>
<li><%= link_to l(:label_contest_joincontest), show_attendingcontest_contest_path(@contest), :class => link_class(:attendingcontests) %></li>
<li><%= link_to l(:label_contest_userresponse), show_contest_contest_path(@contest), :class => link_class(:respond) %></li>
</ul> </ul>
</div> </div>
<% end %> <% end %>

View File

@ -97,7 +97,6 @@
<div class="pagination"> <div class="pagination">
<ul> <ul>
<%= pagination_links_full @events_pages %> <%= pagination_links_full @events_pages %>
<% #binding.pry %>
</ul> </ul>
</div> </div>

View File

@ -150,14 +150,14 @@
<div class="d-p-projectlist"> <div class="d-p-projectlist">
<% find_all_hot_contest.map do |contest| break if(contest == find_all_hot_contest[5]) %> <% find_all_hot_contest.map do |contest| break if(contest == find_all_hot_contest[5]) %>
<li style="position:relative;height:6em;" class='<%= cycle("odd", "even") %>'> <li style="overflow:auto;word-break:break-all;height:100%;" class='<%= cycle("odd", "even") %>'>
<div class="avatar-4" style="float: left; margin-top: 7px"> <div class="avatar-4" style="float: left; margin-top: 7px">
<%= image_tag('/images/contest1.png')%> <%= image_tag('/images/contest1.png')%>
</div> </div>
<div style="float: left; margin-left: 12px; margin-top: 10px; margin-bottom: -4px; width: 380px;"> <div style="float: left; margin-left: 12px; margin-top: 10px; margin-bottom: -4px; width: 380px;">
<!-- <%= link_to(contest.name, contest.event_url, :class => "d-g-blue d-p-project-name", :title => "#{contest.name}", :target => "_blank") %> --> <!-- <%= link_to(contest.name, contest.event_url, :class => "d-g-blue d-p-project-name", :title => "#{contest.name}", :target => "_blank") %> -->
<%= link_to(contest.name, show_contest_contest_path(contest.id), :class => "d-g-blue d-p-project-name", :title => "#{contest.name}", :target => "_blank") %> <%= link_to(contest.name, contest_contestnotifications_path(contest.id), :class => "d-g-blue d-p-project-name", :title => "#{contest.name}", :target => "_blank") %>
<% if contest.id == 2 or contest.id == 3 or contest.id == 6 %> <% if contest.id == 2 or contest.id == 3 or contest.id == 6 %>
<span class="font_lighter">(<span style="font-size: 13px"><%= link_to("#{contest.projects.where('is_public=1').count}"+l(:label_work_quantity), show_attendingcontest_contest_path(contest), :target => "_blank") %></span>)</span> <span class="font_lighter">(<span style="font-size: 13px"><%= link_to("#{contest.projects.where('is_public=1').count}"+l(:label_work_quantity), show_attendingcontest_contest_path(contest), :target => "_blank") %></span>)</span>
<% else %> <% else %>
@ -165,8 +165,8 @@
<% end %> <% end %>
</div> </div>
<div class='text_nowrap' style="float: left;margin:5px; margin-left: 12px; margin-bottom: 2px; width: 380px;"> <div style="float: left;margin:5px; margin-left: 12px; margin-bottom: 2px; width: 380px;">
<span class='font_lighter' title =<%=contest.description.to_s%>><%=contest.description.truncate(50, omission: '...')%></span> <span class='font_lighter' title =<%=contest.description.to_s%>><%=contest.description.to_s%></span>
</div><br /> </div><br />
<div style="padding-left: 57px; clear: left;"> <div style="padding-left: 57px; clear: left;">

View File

@ -63,7 +63,7 @@
<% #projects = find_miracle_project(10, 3) %> <% #projects = find_miracle_project(10, 3) %>
<% @projects.map do |project| %> <% @projects.map do |project| %>
<!--<%# cache cache_key_for_project(project) do %> --> <!--<%# cache cache_key_for_project(project) do %> -->
<li style="position:relative;height:6em;" class='<%= cycle("odd", "even") %>'> <li style="overflow:auto;word-break:break-all;height:100%;" class='<%= cycle("odd", "even") %>'>
<div style="float: left;"> <div style="float: left;">
<%= image_tag(get_project_avatar(project), :class => "avatar-4") %> <%= image_tag(get_project_avatar(project), :class => "avatar-4") %>
</div> </div>
@ -72,10 +72,10 @@
<%= link_to( project.name, project_path(project.id), :class => "d-g-blue d-p-project-name",:title => "#{project.name}" )%> <%= link_to( project.name, project_path(project.id), :class => "d-g-blue d-p-project-name",:title => "#{project.name}" )%>
(<%= link_to "#{projectCount(project)}人", project_member_path(project) ,:course =>'0' %>) (<%= link_to "#{projectCount(project)}人", project_member_path(project) ,:course =>'0' %>)
</div> </div>
<div class='text_nowrap' style="float: left;margin:5px; margin-left: 10px; width: 380px;"> <div style=" float: left;margin:5px; margin-left: 10px; width: 380px;">
<span class='font_lighter' title =<%=project.short_description.to_s%>><%=project.short_description.truncate(50, omission: '...')%></span> <span class='font_lighter' title =<%=project.description.to_s%>><%=project.description%></span>
</div> </div>
<div style="position:absolute; bottom:0;right:0;margin:5px 10px 5px 5px ;"> <div >
<%# issue_count = project.issues.count %> <%# issue_count = project.issues.count %>
<%# issue_journal_count = project.issue_changes.count %> <%# issue_journal_count = project.issue_changes.count %>
<%# issue_score = issue_count * 0.2 %> <%# issue_score = issue_count * 0.2 %>

View File

@ -1776,7 +1776,7 @@ zh:
label_fork_homework_new: 选为作业 label_fork_homework_new: 选为作业
#wang #wang
label_contest_userresponse: 用户留言 label_contest_userresponse: 用户留言
label_contest_joincontest: 竞赛 label_contest_joincontest: 竞赛
label_contest_notification: 竞赛通知 label_contest_notification: 竞赛通知
#end #end

View File

@ -2231,4 +2231,3 @@ ul.messages-for-user-reply li {
.footer_text_link{ .footer_text_link{
margin: 0px 5px; margin: 0px 5px;
} }
/*gcm*/

View File

@ -124,3 +124,29 @@ courses_061:
rgt: rgt:
is_public: 0 is_public: 0
inherit_members: 1 inherit_members: 1
course_trustie_074:
id: 74
tea_id: 698
name: 电路与电子学基础(软件工程专业)
state:
code:
time: 2014
extra: course2014-05-22_16-09-25
created_at: 2014-05-22 08:09:25.000000000 Z
updated_at: 2014-05-22 08:09:25.000000000 Z
location:
term: 春季学期
string:
password: '12345678'
setup_time:
endup_time:
class_period: '54'
school_id: 117
description: "电路与电子学基础,软件工程小班\\r\ 模拟电子技术部分\ "
status: 1
attachmenttype: 2
lft:
rgt:
is_public: 1
inherit_members: 1

View File

@ -1,68 +1,26 @@
# encoding: utf-8 # encoding: utf-8
# Redmine - project management software
# Copyright (C) 2006-2013 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# 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.
require File.expand_path('../../test_helper', __FILE__) require File.expand_path('../../test_helper', __FILE__)
class CourseTest < ActiveSupport::TestCase class CourseTest < ActiveSupport::TestCase
fixtures :courses, :roles, :member_roles, :members, :boards, :messages, :news
def setup def setup
@course_1 = Course.new
@course_1.id = 1
@course_1.tea_id = 1
@course_1.name = 'course1'
@course_1.state = 1234
@course_1.time = 2012
@course_1.term = '秋季学期'
@course_1.password = 1234
@course_1.class_period = 40
@course_2 = Course.new
@course_2.id = 2
@course_2.tea_id = 1
@course_2.name = 'course2'
@course_2.state = 1234
@course_2.time = 2013
@course_2.term = '秋季学期'
@course_2.password = 1234
@course_2.class_period = 40
@course_3 = Course.new
@course_3.id = 3
@course_3.tea_id = 1
@course_3.name = 'course3'
@course_3.state = 1234
@course_3.time = 2014
@course_3.term = '秋季学期'
@course_3.password = 1234
@course_3.class_period = 40
@course_now = Course.new
@course_now.id = 4
@course_now.tea_id = 1
@course_now.name = 'course4'
@course_now.state = 1234
@course_now.time = 2013
@course_now.term = '秋季学期'
@course_now.password = 1234
@course_now.class_period = 40
end end
test 'test course whether out of date.' do test 'name valid with CJK coding' do
true course = Course.find_by_id(74)
name_quirk = '电路与电子学基础(软件工程专业)'
course.name = "test_course"
assert course.valid?
course.name = name_quirk
assert course.valid?
end
test 'description too long must be valid.' do
course = Course.find_by_id(8)
course.description = course.description * 100
course.valid?
assert_equal course.errors.full_messages.count, 0
assert course.valid?
end end
def teardown def teardown