Merge branch 'develop' of http://repository.trustie.net/xianbo/trustie2 into develop

This commit is contained in:
yanxd 2014-07-03 09:03:17 +08:00
commit 663634b9da
1025 changed files with 77272 additions and 2203 deletions

1
.gitignore vendored
View File

@ -13,3 +13,4 @@
/Gemfile.lock
/db/schema.rb
/Gemfile.lock
/lib/plugins/acts_as_versioned/test/debug.log

24
Gemfile
View File

@ -25,6 +25,16 @@ group :development do
end
end
group :test do
# shoulda的版本做了改动
#gem "shoulda", "~> 3.3.2"
gem "shoulda", "> 3.3.2"
gem "mocha", "~> 0.13.3"
gem 'capybara', '~> 2.0.0'
gem 'nokogiri', '< 1.6.0'
end
# Gems used only for assets and not required
# in production environments by default.
group :assets do
@ -32,7 +42,7 @@ group :assets do
gem 'coffee-rails', '~> 3.2.1'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', :platforms => :ruby
gem 'therubyracer', :platforms => :ruby
gem 'uglifier', '>= 1.0.3'
end
@ -42,6 +52,16 @@ group :ldap do
gem "net-ldap", "~> 0.3.1"
end
platforms :mri, :mingw do
group :rmagick do
# RMagick 2 supports ruby 1.9
# RMagick 1 would be fine for ruby 1.8 but Bundler does not support
# different requirements for the same gem on different platforms
gem "rmagick", ">= 2.0.0"
end
end
# Optional gem for OpenID authentication
group :openid do
gem "ruby-openid", "~> 2.1.4", :require => "openid"
@ -67,7 +87,7 @@ if File.exist?(database_file)
adapters.each do |adapter|
case adapter
when 'mysql2'
gem "mysql2", "~> 0.3.11", :platforms => [:mri, :mingw]
gem "mysql2", "= 0.3.11", :platforms => [:mri, :mingw]
gem "activerecord-jdbcmysql-adapter", :platforms => :jruby
when 'mysql'
gem "mysql", "~> 2.8.1", :platforms => [:mri, :mingw]

View File

@ -52,6 +52,15 @@ GEM
rails (>= 3, < 5)
arel (3.0.2)
builder (3.0.0)
capybara (2.0.3)
mime-types (>= 1.16)
nokogiri (>= 1.3.3)
rack (>= 1.0.0)
rack-test (>= 0.5.4)
selenium-webdriver (~> 2.0)
xpath (~> 1.0.0)
childprocess (0.5.3)
ffi (~> 1.0, >= 1.0.11)
coderay (1.0.9)
coffee-rails (3.2.2)
coffee-script (>= 2.2.0)
@ -59,11 +68,11 @@ GEM
coffee-script (2.2.0)
coffee-script-source
execjs
coffee-script-source (1.6.1)
coffee-script-source (1.7.0)
erubis (2.7.0)
execjs (1.4.0)
multi_json (~> 1.0)
execjs (2.0.2)
fastercsv (1.5.0)
ffi (1.9.3-x86-mingw32)
hike (1.2.3)
i18n (0.6.1)
journey (1.0.4)
@ -74,19 +83,15 @@ GEM
mail (2.5.4)
mime-types (~> 1.16)
treetop (~> 1.4.8)
method_source (0.8.2)
metaclass (0.0.4)
mime-types (1.23)
mocha (0.13.3)
metaclass (~> 0.0.1)
multi_json (1.7.6)
mysql2 (0.3.11-x86-mingw32)
net-ldap (0.3.1)
nokogiri (1.5.11-x86-mingw32)
polyglot (0.3.3)
pry (0.9.12.6-x86-mingw32)
coderay (~> 1.0)
method_source (~> 0.8)
slop (~> 3.4)
win32console (~> 1.3)
pry-nav (0.2.3)
pry (~> 0.9.10)
rack (1.4.5)
rack-cache (1.2)
rack (>= 0.4)
@ -112,16 +117,28 @@ GEM
rake (>= 0.8.7)
rdoc (~> 3.4)
thor (>= 0.14.6, < 2.0)
rake (10.0.4)
rake (10.3.2)
rdoc (3.12.2)
json (~> 1.4)
rmagick (2.13.2)
ruby-openid (2.1.8)
sass (3.2.7)
rubyzip (1.1.4)
sass (3.2.14)
sass-rails (3.2.6)
railties (~> 3.2.0)
sass (>= 3.1.10)
tilt (~> 1.3)
slop (3.5.0)
selenium-webdriver (2.42.0)
childprocess (>= 0.5.0)
multi_json (~> 1.0)
rubyzip (~> 1.0)
websocket (~> 1.0.4)
shoulda (3.5.0)
shoulda-context (~> 1.0, >= 1.0.1)
shoulda-matchers (>= 1.4.1, < 3.0)
shoulda-context (1.2.1)
shoulda-matchers (2.6.1)
activesupport (>= 3.0.0)
sprockets (2.2.2)
hike (~> 1.2)
multi_json (~> 1.0)
@ -133,10 +150,12 @@ GEM
polyglot
polyglot (>= 0.3.1)
tzinfo (0.3.37)
uglifier (1.0.3)
uglifier (2.4.0)
execjs (>= 0.3.0)
multi_json (>= 1.0.2)
win32console (1.3.2-x86-mingw32)
json (>= 1.8.0)
websocket (1.0.7)
xpath (1.0.0)
nokogiri (~> 1.3)
PLATFORMS
x86-mingw32
@ -147,19 +166,23 @@ DEPENDENCIES
acts-as-taggable-on (= 2.4.1)
better_errors!
builder (= 3.0.0)
capybara (~> 2.0.0)
coderay (~> 1.0.6)
coffee-rails (~> 3.2.1)
fastercsv (~> 1.5.0)
i18n (~> 0.6.0)
jquery-rails (~> 2.0.2)
mysql2 (~> 0.3.11)
mocha (~> 0.13.3)
mysql2 (= 0.3.11)
net-ldap (~> 0.3.1)
pry
pry-nav
nokogiri (< 1.6.0)
rack-mini-profiler!
rack-openid
rails (= 3.2.13)
rmagick (>= 2.0.0)
ruby-openid (~> 2.1.4)
sass-rails (~> 3.2.3)
seems_rateable!
shoulda (> 3.3.2)
therubyracer
uglifier (>= 1.0.3)

View File

@ -0,0 +1,2 @@
// Place all the behaviors and hooks related to the matching controller here.
// All this logic will automatically be available in application.js.

View File

@ -0,0 +1,2 @@
// Place all the behaviors and hooks related to the matching controller here.
// All this logic will automatically be available in application.js.

View File

@ -0,0 +1,4 @@
/*
Place all the styles related to the matching controller here.
They will automatically be included in application.css.
*/

View File

@ -0,0 +1,4 @@
/*
Place all the styles related to the matching controller here.
They will automatically be included in application.css.
*/

View File

@ -143,15 +143,18 @@ class AccountController < ApplicationController
end
#added by bai
unless @user.id.nil?
ue = UserExtensions.create(:identity => params[:identity].to_i,:technical_title => params[:technical_title], :gender => params[:gender].to_i, :user_id => @user.id, :student_id => params[:no])
unless params[:province].nil? || params[:city].nil?
ue.location = params[:province]
ue.location_city = params[:city]
if @user.id != nil
ue = @user.user_extensions ||= UserExtensions.new
#ue = UserExtensions.create(:identity => params[:identity].to_i,:technical_title => params[:technical_title], :gender => params[:gender].to_i, :user_id => @user.id, :student_id => )
ue.identity = params[:identity].to_i
ue.technical_title = params[:technical_title]
ue.gender = params[:gender].to_i
ue.user_id = @user.id
ue.student_id = params[:no]
ue.location = params[:province] if params[:province] != nil
ue.location_city = params[:city] if params[:city] != nil
ue.save
end
end
#end
end
end

View File

@ -233,7 +233,15 @@ class ApplicationController < ActionController::Base
# Authorize the user for the requested action
def authorize(ctrl = params[:controller], action = params[:action], global = false)
#modify by NWB
if @project
allowed = User.current.allowed_to?({:controller => ctrl, :action => action}, @project || @projects, :global => global)
elsif @course
allowed = User.current.allowed_to?({:controller => ctrl, :action => action}, @course || @courses, :global => global)
else
allowed = User.current.allowed_to?({:controller => ctrl, :action => action}, @project || @projects, :global => global)
end
if allowed
true
else
@ -245,6 +253,24 @@ class ApplicationController < ActionController::Base
end
end
def authorize_course(ctrl = params[:controller], action = params[:action], global = false)
allowed = User.current.allowed_to?({:controller => ctrl, :action => action}, @course || @course, :global => global)
if allowed
true
else
if @course && @course.archived?
render_403 :message => :notice_not_authorized_archived_project
else
deny_access
end
end
end
def authorize_course_global(ctrl = params[:controller], action = params[:action], global = true)
authorize_course(ctrl, action, global)
end
# Authorize the user for the requested action outside a project
def authorize_global(ctrl = params[:controller], action = params[:action], global = true)
authorize(ctrl, action, global)
@ -259,7 +285,11 @@ class ApplicationController < ActionController::Base
# Find project of id params[:project_id]
def find_project_by_project_id
if params[:project_id]
@project = Project.find(params[:project_id])
elsif params[:course_id]
@course = Course.find(params[:course_id])
end
rescue ActiveRecord::RecordNotFound
render_404
end
@ -301,6 +331,10 @@ class ApplicationController < ActionController::Base
render_404 unless @object.present?
@project = @object.project
if @project == nil && @object.has_attribute?('course_id')
@course = @object.course
end
end
def find_contest_from_association
@ -319,6 +353,14 @@ class ApplicationController < ActionController::Base
render_404
end
#added by nwb
#»ñÈ¡¿Î³Ì
def find_course
@course= Course.find(params[:id])
rescue ActiveRecord::RecordNotFound
render_404
end
# def find_model_object_contest
# model = self.class.model_object
# if model

View File

@ -59,6 +59,8 @@ class AttachmentsController < ApplicationController
:type => detect_content_type(@attachment),
:disposition => (@attachment.image? ? 'inline' : 'attachment')
end
rescue => e
redirect_to "http://forge.trustie.net/file_not_found.html"
end
#更新资源文件类型
@ -124,11 +126,20 @@ class AttachmentsController < ApplicationController
end
respond_to do |format|
# modify by nwb
if @attachment.container_type == 'Course'
if @course.nil?
format.html { redirect_to_referer_or forum_memo_path(@attachment.container.forum, @attachment.container) }
else
format.html { redirect_to_referer_or course_path(@course) }
end
else
if @project.nil?
format.html { redirect_to_referer_or forum_memo_path(@attachment.container.forum, @attachment.container) }
else
format.html { redirect_to_referer_or project_path(@project) }
end
end
format.js
end
@ -190,10 +201,15 @@ private
def find_project
@attachment = Attachment.find(params[:id])
# Show 404 if the filename in the url is wrong
# modify by nwb
raise ActiveRecord::RecordNotFound if params[:filename] && params[:filename] != @attachment.filename
if @attachment.container_type == 'Course'
@course = @attachment.course
else
unless @attachment.container_type == 'Bid' || @attachment.container_type == 'HomeworkAttach' || @attachment.container_type == 'Memo' || @attachment.container_type == 'Softapplication'
@project = @attachment.project
end
end
rescue ActiveRecord::RecordNotFound
render_404
end

View File

@ -3,12 +3,13 @@ class BidsController < ApplicationController
#Added by young
menu_item l(:label_homework), :only => [:edit, :udpate]
menu_item :respond
menu_item :course, :only => :show_courseEx
menu_item :project, :only => [:show_project,:show_results, :new_submit_homework]
menu_item :homework_respond, :only => :homework_respond
menu_item :homework_statistics, :only => :homework_statistics
#Ended by young
before_filter :find_bid, :only => [:show, :show_project, :create,:destroy,:more,:back,:add,:delete,:new,:show_results,:set_reward, :add_homework, :fork, :create_fork,
:show_course, :show_bid_project, :show_bid_user, :join_in_contest, :unjoin_in_contest, :new_join,:show_participator, :settings]
:show_course, :show_courseEx,:show_bid_project, :show_bid_user, :join_in_contest, :unjoin_in_contest, :new_join,:show_participator, :settings]
# added by fq
before_filter :require_login, :only => [:join_in_contest, :unjoin_in_contest]
# end
@ -189,7 +190,7 @@ class BidsController < ApplicationController
@homework.save_attachments(params[:attachments] || (params[:bid] && params[:bid][:uploads]))
# @bid.
if @homework.save
HomeworkForCourse.create(:project_id => params[:course], :bid_id => @homework.id)
HomeworkForCourse.create(:course_id => params[:course], :bid_id => @homework.id)
unless @bid.watched_by?(User.current)
if @bid.add_watcher(User.current)
flash[:notice] = l(:label_bid_succeed)
@ -199,11 +200,9 @@ class BidsController < ApplicationController
else
@bid.safe_attributes = params[:bid]
@courses = []
@membership = User.current.memberships.all(:conditions => Project.visible_condition(User.current))
@membership = User.current.coursememberships.all#(:conditions => Project.visible_condition(User.current))
@membership.each do |membership|
if membership.project.project_type == 1
@courses << membership.project
end
@courses << membership.course
end
render :action => 'fork'
end
@ -289,6 +288,7 @@ class BidsController < ApplicationController
end
#end
# 显示课程
def show_course
bids = Bid.where('parent_id = ?', @bid.id)
@courses = []
@ -448,6 +448,88 @@ class BidsController < ApplicationController
end
end
# 显示作业课程
# add by nwb
def show_courseEx
if (User.current.logged? && User.current.member_of_course?(@bid.courses.first))
# flash[:notice] = ""
@membership = User.current.coursememberships.all(:conditions => Course.visible_condition(User.current))
@option = []
@membership.each do |membership|
membership.member_roles.each{|role|
if(role.role_id == 3)
@option << membership.course
end
}
end
@user = @bid.author
@bidding_project = @bid.biding_projects.all
if params[:student_id].present?
@temp = []
@bidding_project.each do |pro|
if pro.project && pro.project.project_status
if /#{params[:student_id]}/ =~ pro.user.user_extensions.student_id
@temp << pro
end
end
@temp
end
@bidding_project = @temp
else
#added by nie
@temp = []
@bidding_project.each do |pro|
if pro.project && pro.project.project_status
@temp << pro
end
@temp
end
if @temp.size > 0
@bidding_project = @temp.sort {|a,b| b.project.project_status.grade <=> a.project.project_status.grade}
end
#ended
end
if @bid.homework_type == 1
@homework = HomeworkAttach.new
#@homework_list = @bid.homeworks
#增加作业按评分排序,
@homework_list = @bid.homeworks.eager_load(:rate_averages, :user, :attachments).order('seems_rateable_cached_ratings.avg DESC').order("#{HomeworkAttach.table_name}.created_at ASC")
if params[:student_id].present?
@temp = []
@homework_list.each do |pro|
if /#{params[:student_id]}/ =~ pro.user.user_extensions.student_id
@temp << pro
end
@temp
end
@homework_list = @temp
end
end
respond_to do |format|
if @bid.reward_type == 3
format.html {
render :layout => 'base_homework'
}
elsif @bid.reward_type == 1
format.html {
render :layout => 'base_bids'
}
else
format.html {
render :layout => 'base_contest'
}
end
format.api
end
else
render_403 :message => :notice_not_authorized
end
end
##### by huang
def show_project_homework
# flash[:notice] = ""
@ -711,7 +793,7 @@ class BidsController < ApplicationController
@bid.save_attachments(params[:attachments] || (params[:bid] && params[:bid][:uploads]))
# @bid.
if @bid.save
HomeworkForCourse.create(:project_id => params[:course_id], :bid_id => @bid.id)
HomeworkForCourse.create(:course_id => params[:course_id], :bid_id => @bid.id)
unless @bid.watched_by?(User.current)
if @bid.add_watcher(User.current)
flash[:notice] = l(:label_bid_succeed)
@ -721,19 +803,22 @@ class BidsController < ApplicationController
else
@bid.safe_attributes = params[:bid]
@homework = @bid
@project = Project.find_by_id(params[:course_id])
@project_id = @project.id
render file: 'projects/new_homework', layout: 'base_courses'
@course = Course.find_by_id(params[:course_id])
@course_id = @course.id
render file: 'courses/new_homework', layout: 'base_courses'
end
end
# modify by nwb\
# 编辑作业
def edit
@bid = Bid.find(params[:bid_id])
if (User.current.admin?||User.current.id==@bid.author_id)
@project_id = params[:project_id]
@course_id = params[:course_id]
respond_to do |format|
format.html {
@project = Project.find(params[:project_id])
@course = Course.find(params[:course_id])
@user= User.find(User.current.id)
render :layout => 'base_courses'
}
@ -745,11 +830,11 @@ class BidsController < ApplicationController
def update
@bid = Bid.find(params[:id])
@project = @bid.courses.first#Project.find(params[:course_id])
@course = @bid.courses.first#Project.find(params[:course_id])
@bid.save_attachments(params[:attachments] || (params[:bid] && params[:bid][:uploads]))
if @bid.update_attributes(params[:bid]) && @bid.save
flash[:notice] = l(:label_update_homework_succeed)
redirect_to project_homework_path(@project)
redirect_to course_homework_path(@course)
else
@bid.safe_attributes = params[:bid]
render :action => 'edit', :layout =>'base_courses'
@ -894,9 +979,9 @@ class BidsController < ApplicationController
def memberAccess
# 是课程,则判断当前用户是否参加了课程
return true if current_user.admin?
return 0 if @bid.courses.first.project_type == Project::ProjectType_project
#return 0 if @bid.courses.first.project_type == Project::ProjectType_project
currentUser = User.current
render_403 unless currentUser.member_of?(@bid.courses.first)
render_403 unless currentUser.member_of_cousrse?(@bid.courses.first)
end
end

View File

@ -28,17 +28,25 @@ class BoardsController < ApplicationController
helper :watchers
def index
#modify by nwb
if @project
@boards = @project.boards.includes(:last_message => :author).all
@boards = [] << @boards[0] if @boards.any?
if @boards.size == 1
@board = @boards.first
show and return
end
if @project.project_type == 1
render :layout => 'base_courses'
else
render :layout => false if request.xhr?
elsif @course
@boards = @course.boards.includes(:last_message => :author).all
@boards = [] << @boards[0] if @boards.any?
if @boards.size == 1
@board = @boards.first
show and return
end
render :layout => 'base_courses'
end
end
def show
@ -60,10 +68,11 @@ class BoardsController < ApplicationController
preload(:author, {:last_reply => :author}).
all
@message = Message.new(:board => @board)
if @project.project_type ==1
render :action => 'show', :layout => 'base_courses'
else
#modify by nwb
if @project
render :action => 'show', :layout => !request.xhr?
elsif @course
render :action => 'show', :layout => 'base_courses'
end
}
format.atom {
@ -72,7 +81,12 @@ class BoardsController < ApplicationController
includes(:author, :board).
limit(Setting.feeds_limit.to_i).
all
if @project
render_feed(@messages, :title => "#{@project}: #{@board}")
elsif @course
render_feed(@messages, :title => "#{@course}: #{@board}")
end
}
end
end

View File

@ -74,6 +74,25 @@ class ContestsController < ApplicationController
end
end
def homework
@offset, @limit = api_offset_and_limit({:limit => 10})
@bids = @course.homeworks.order('deadline DESC')
@bids = @bids.like(params[:name]) if params[:name].present?
@bid_count = @bids.count
@bid_pages = Paginator.new @bid_count, @limit, params['page']
@offset ||= @bid_pages.reverse_offset
unless @offset == 0
@bids = @bids.offset(@offset).limit(@limit).all.reverse
else
limit = @bid_count % @limit
@bids = @bids.offset(@offset).limit(limit).all.reverse
end
render :layout => 'base_courses'
end
def show_contest
@user = @contest.author
@jours = @contest.journals_for_messages.where('m_parent_id IS NULL').order('created_on DESC')

View File

@ -1,14 +1,31 @@
class CoursesController < ApplicationController
layout 'base_courses'
include CoursesHelper
helper :activities
helper :members
helper :words
menu_item :overview
menu_item :feedback, :only => :feedback
menu_item :homework, :only => :homework
menu_item l(:label_sort_by_time), :only => :index
menu_item l(:label_sort_by_active), :only => :index
menu_item l(:label_sort_by_influence), :only => :index
before_filter :find_course, :except => [ :index, :search,:list, :new,:join,:unjoin, :create, :copy, :statistics, :new_join, :course, :enterprise_course, :course_enterprise,:view_homework_attaches]
before_filter :authorize_course, :only => [:show, :settings, :edit, :update, :modules, :close, :reopen, :view_homework_attaches, :course]
before_filter :authorize_course_global, :only => [:view_homework_attaches, :new,:create]
before_filter :require_admin, :only => [:copy, :archive, :unarchive, :destroy, :calendar]
before_filter :toggleCourse, only: [:finishcourse, :restartcourse]
before_filter :require_login, :only => [:join, :unjoin]
before_filter :allow_join, :only => [:join]
def join
if User.current.logged?
course = Project.find(params[:object_id])
course_prefs = Course.find_by_extra(course.identifier)
if params[:course_password] == course_prefs.password
course = Course.find(params[:object_id])
if params[:course_password] == course.password
members = []
members << Member.new(:role_ids => [10], :user_id => User.current.id)
course.members << members
@ -21,14 +38,14 @@ class CoursesController < ApplicationController
end
respond_to do |format|
# format.html { redirect_to_referer_or {render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true}}
format.js { render :partial => 'set_join', :locals => {:user => User.current, :course => Project.find(params[:object_id]), :object_id => params[:object_id]} }
format.js { render :partial => 'set_join', :locals => {:user => User.current, :course => Course.find(params[:object_id]), :object_id => params[:object_id]} }
end
end
def unjoin
if User.current.logged?
@member = Member.where('project_id = ? and user_id = ?', params[:object_id], User.current.id)
@member = Member.where('course_id = ? and user_id = ?', params[:object_id], User.current.id)
@member.first.destroy
joined = StudentsForCourse.where('student_id = ? and course_id = ?', User.current.id, params[:object_id])
@ -38,20 +55,658 @@ class CoursesController < ApplicationController
end
respond_to do |format|
# format.html { redirect_to_referer_or {render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true}}
format.js { render :partial => 'set_join', :locals => {:user => User.current, :course => Project.find(params[:object_id]), :object_id => params[:object_id]} }
format.js { render :partial => 'set_join', :locals => {:user => User.current, :course => Course.find(params[:object_id]), :object_id => params[:object_id]} }
end
end
#更新课程信息
def update
@course.safe_attributes = params[:course]
@course.class_period = params[:class_period]
if @course.save
if params[:course][:is_public] == '0'
course_status = CourseStatus.find_by_course_id(@course.id)
course_status.destroy if course_status
elsif params[:course][:is_public] == '1'
course_status = CourseStatus.find_by_course_id(@course.id)
course_status.destroy if course_status
course_status = CourseStatus.create(:course_id => @course.id, :grade => 0)
end
respond_to do |format|
format.html {
flash[:notice] = l(:notice_successful_update)
redirect_to settings_course_path(@course)
}
format.api { render_api_ok }
end
else
respond_to do |format|
format.html {
settings
render :action => 'settings'
}
format.api { render_validation_errors(@course) }
end
end
end
def new_join
@course = Course.find(params[:object_id])
end
# 课程搜索
# add by nwb
def search
courses_all = Course.all_course
@courses = courses_all.visible
if params[:name].present?
@courses_all = @courses.like(params[:name])
else
@courses_all = @courses;
end
@course_count = @courses_all.count
@course_pages = Paginator.new @course_count, per_page_option, params['page']
# 课程的动态数
@course_activity_count=Hash.new
@courses_all.each do |course|
@course_activity_count[course.id]=0
end
case params[:course_sort_type]
when '0'
@courses = @courses_all.order("created_at desc")
@s_type = 0
@courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page)
@course_activity_count=get_course_activity @courses,@course_activity_count
when '1'
@courses = @courses_all.order("course_ac_para desc")
@s_type = 1
@courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page)
@course_activity_count=get_course_activity @courses,@course_activity_count
when '2'
@courses = @courses_all.order("watchers_count desc")
@s_type = 2
@courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page)
@course_activity_count=get_course_activity @courses,@course_activity_count
when '3'
@course_activity_count=get_course_activity @courses_all,@course_activity_count_array
@courses=handle_course @courses_all,@course_activity_count
@s_type = 3
@courses = @courses[@course_pages.offset, @course_pages.per_page]
else
@s_type = 0
@courses = @courses_all.order("created_at desc")
@courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page)
@course_activity_count=get_course_activity @courses,@course_activity_count
end
respond_to do |format|
format.html {
render :layout => 'base'
scope = Course
unless params[:closed]
scope = scope.active
end
}
format.atom {
courses = Course.visible.order('created_on DESC').limit(Setting.feeds_limit.to_i).all
render_feed(courses, :title => "#{Setting.app_title}: #{l(:label_course_latest)}")
}
end
end
def member
## 有角色参数的才是课程,没有的就是项目
@render_file = 'member_list'
@teachers= searchTeacherAndAssistant(@course)
@canShowCode = isCourseTeacher(User.current.id)
case params[:role]
when '1'
@subPage_title = l :label_teacher_list
@members = searchTeacherAndAssistant(@course)
when '2'
@subPage_title = l :label_student_list
@members = searchStudent(@course)
else
@subPage_title = ''
@members = @course.member_principals.includes(:roles, :principal).all.sort
end
@members = paginateHelper @members
render :layout => 'base_courses'
end
#判断指定用户是否为课程教师
def isCourseTeacher(id)
result = false
if @teachers.find_by_user_id(id) != nil
result = true
end
result
end
def handle_course courses, activities
course_activity_count_array=activities.values()
course_array=[]
i=0;
courses.each do |course|
course_array[i]=course
i=i+1
end
courses=desc_sort_course_by_avtivity(course_activity_count_array, course_array)
return courses
end
def settings
@issue_custom_fields = IssueCustomField.sorted.all
@issue_category ||= IssueCategory.new
@member ||= @course.members.new
@trackers = Tracker.sorted.all
end
def create
if User.current.user_extensions.identity
@course = Course.new
@course.extra='course' + DateTime.parse(Time.now.to_s).strftime('%Y-%m-%d_%H-%M-%S').to_s
@course.safe_attributes = params[:course]
@course.tea_id = User.current.id
# added by bai
@course.term = params[:term]
@course.time = params[:time]
#@course.school_id = params[:occupation]
@course.school_id = User.current.user_extensions.school_id
@course.setup_time = params[:setup_time]
@course.endup_time = params[:endup_time]
@course.class_period = params[:class_period]
end
@issue_custom_fields = IssueCustomField.sorted.all
@trackers = Tracker.sorted.all
if User.current.user_extensions.identity == 0
if @course.save
#unless User.current.admin?
r = Role.givable.find_by_id(Setting.new_project_user_role_id.to_i) || Role.givable.first
m = Member.new(:user => User.current, :roles => [r])
m.project_id = -1
course = CourseInfos.new(:user_id => User.current.id, :course_id => @course.id)
#user_grades = UserGrade.create(:user_id => User.current.id, :course_id => @course.id)
if params[:course][:is_public] == '1'
course_status = CourseStatus.create(:course_id => @course.id, :watchers_count => 0, :changesets_count => 0, :grade => 0, :course_type => @course_tag)
end
@course.members << m
@course.course_infos << course
#end
respond_to do |format|
format.html {
flash[:notice] = l(:notice_successful_create)
if params[:continue]
redirect_to new_course_path(attrs, :course => '0')
elsif params[:course_continue]
redirect_to new_course_path(:course => '1')
else
redirect_to settings_course_path(@course, :course_type => 1)
end
}
format.api { render :action => 'show', :status => :created, :location => url_for(:controller => 'courses', :action => 'show', :id => @course.id) }
end
else
@course.destroy
respond_to do |format|
format.html { render :action => 'new', :layout => 'base' } #Added by young
format.api { render_validation_errors(@course) }
end
end
end
end
def course
@school_id = params[:school_id]
per_page_option = 10
if @school_id == "0" or @school_id.nil?
@courses_all = Course.active.visible.
joins("LEFT JOIN #{CourseStatus.table_name} ON #{Course.table_name}.id = #{CourseStatus.table_name}.course_id").
where("#{Course.table_name}.course_type = ? ", Course::CourseType_course)
else
@courses_all = Course.active.visible.
joins("LEFT JOIN #{CourseStatus.table_name} ON #{Course.table_name}.id = #{CourseStatus.table_name}.course_id").
joins(:course_extra).
where("#{Course.table_name}.course_type = ? AND #{Course.table_name}.school_id = ?", Course::CourseType_course, @school_id)
end
@course_count = @courses_all.count
@course_pages = Paginator.new @course_count, per_page_option, params['page']
#gcm activity count
@course_activity_count=Hash.new
#count initialize
@courses_all.each do |course|
@course_activity_count[course.id]=0
end
#@course_activity_count=get_course_activity @courses_all,@course_activity_count
#gcm end
case params[:course_sort_type]
when '0'
@courses = @courses_all.order("created_on desc")
@s_type = 0
@courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page)
#gcm
@course_activity_count=get_course_activity @courses,@course_activity_count
#gcmend
when '1'
@courses = @courses_all.order("course_ac_para desc")
@s_type = 1
@courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page)
#gcm
@course_activity_count=get_course_activity @courses,@course_activity_count
#gcmend
when '2'
@courses = @courses_all.order("watchers_count desc")
@s_type = 2
@courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page)
#gcm
@course_activity_count=get_course_activity @courses,@course_activity_count
#gcmend
#gcm
when '3'
#gcm
@course_activity_count=get_course_activity @courses_all,@course_activity_count
#gcmend
@courses=handle_course @courses_all,@course_activity_count
@s_type = 3
@courses = @courses[@course_pages.offset, @course_pages.per_page]
else
@s_type = 0
@courses = @courses_all.order("created_on desc")
@courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page)
#gcm
@course_activity_count=get_course_activity @courses,@course_activity_count
#gcmend
end
respond_to do |format|
format.html {
render :layout => 'base'
}
format.api {
# @offset, @limit = api_offset_and_limit
# @course_count = Course.visible.count
# @courses = Course.visible.offset(@offset).limit(@limit).order('lft').all
}
format.atom {
courses = Course.visible.order('created_on DESC').limit(Setting.feeds_limit.to_i).all
render_feed(courses, :title => "#{Setting.app_title}: #{l(:label_course_latest)}")
}
end
end
def new
@course_type = params[:course_type] ||= params[:course]
@issue_custom_fields = IssueCustomField.sorted.all
@trackers = Tracker.sorted.all
@course = Course.new
@course.safe_attributes = params[:course]
render :layout => 'base'
end
def desc_sort_course_by_avtivity(activity_count, courses)
return courses if activity_count.size<2
(activity_count.size-2).downto(0) do |i|
(0..i).each do |j|
if activity_count[j]<activity_count[j+1]
courses[j], courses[j+1]=courses[j+1], courses[j]
activity_count[j], activity_count[j+1]=activity_count[j+1], activity_count[j]
end
end
end
return courses
end
def index
@course_type = params[:course_type]
@school_id = params[:school_id]
per_page_option = 10
if @school_id == "0" or @school_id.nil?
@courses_all = Course.active.visible.
joins("LEFT JOIN #{CourseStatus.table_name} ON #{Course.table_name}.id = #{CourseStatus.table_name}.course_id")
else
@courses_all = Course.active.visible.
joins("LEFT JOIN #{CourseStatus.table_name} ON #{Course.table_name}.id = #{CourseStatus.table_name}.course_id").
joins(:course_extra).
where("#{Course.table_name}.course_type = ? AND #{Course.table_name}.school_id = ?", Course::CourseType_course, @school_id)
end
@course_count = @courses_all.count
@course_pages = Paginator.new @course_count, per_page_option, params['page']
@course_activity_count=Hash.new
@courses_all.each do |course|
@course_activity_count[course.id]=0
end
case params[:course_sort_type]
when '0'
@courses = @courses_all.order("created_at desc")
@s_type = 0
@courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page)
@course_activity_count=get_course_activity @courses, @course_activity_count
when '1'
@courses = @courses_all.order("course_ac_para desc")
@s_type = 1
@courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page)
@course_activity_count=get_course_activity @courses, @course_activity_count
when '2'
@courses = @courses_all.order("watchers_count desc")
@s_type = 2
@courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page)
@course_activity_count=get_course_activity @courses, @course_activity_count
when '3'
@course_activity_count=get_course_activity @courses_all, @course_activity_count
@courses=handle_course @courses_all, @course_activity_count
@s_type = 3
@courses = @courses[@course_pages.offset, @course_pages.per_page]
else
@s_type = 0
@courses = @courses_all.order("created_at desc")
@courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page)
@course_activity_count=get_course_activity @courses, @course_activity_count
end
respond_to do |format|
format.html {
render :layout => 'base'
}
format.atom {
courses = Course.visible.order('created_on DESC').limit(Setting.feeds_limit.to_i).all
render_feed(courses, :title => "#{Setting.app_title}: #{l(:label_course_latest)}")
}
end
end
def homework
@offset, @limit = api_offset_and_limit({:limit => 10})
@bids = @course.homeworks.order('deadline DESC')
@bids = @bids.like(params[:name]) if params[:name].present?
@bid_count = @bids.count
@bid_pages = Paginator.new @bid_count, @limit, params['page']
@offset ||= @bid_pages.reverse_offset
unless @offset == 0
@bids = @bids.offset(@offset).limit(@limit).all.reverse
else
limit = @bid_count % @limit
if limit == 0
limit = 10
end
@bids = @bids.offset(@offset).limit(limit).all.reverse
end
render :layout => 'base_courses'
end
# 新建作业
def new_homework
if (User.current.logged? &&
(User.current.admin? ||
(
!Member.where('user_id = ? and course_id = ?', User.current.id, @course.id).first.nil? &&
(
Member.where('user_id = ? and course_id = ?', User.current.id, @course.id).first.roles &&
( Role.where(id: [3, 4, 7, 9]).size > 0 )
)
)
)
)
@homework = Bid.new
@homework.safe_attributes = params[:bid]
render :layout => 'base_courses'
else
render_404
end
end
def get_course_activity courses, activities
@course_ids=activities.keys()
days = Setting.activity_days_default.to_i
date_to ||= Date.today + 1
date_from = date_to - days-1.years
#file_count
Attachment.where(container_id: @course_ids, container_type: Course).where("created_on>?", date_from).each do |attachment|
activities[attachment.container_id]+=1
end
#message_count
Board.where(course_id: @course_ids).each do |board|
# activities[board.course_id]+=1
activities[board.course_id]+=board.messages.where("updated_on>?", date_from).count
end
#news
News.where(course_id: @course_ids).where("created_on>?",date_from).each do |news|
activities[news.course_id]+=1
end
#feedbackc_count
JournalsForMessage.where(jour_id: @course_ids, jour_type: Course).each do |jourformess|
activities[jourformess.jour_id]+=1
end
#activities!=0
i=0;
courses.each do |course|
id=course.id
if activities[id]==0
activities[id]=1
end
end
return activities
end
def toggleCourse
@course_prefs = Course.find_by_extra(@course.extra)
unless (@course_prefs.teacher == User.current || User.current.admin?)
render_403
end
end
def get_courses
@user = User.current
membership = @user.coursememberships.all
membership.sort! {|older, newer| newer.created_on <=> older.created_on }
@memberships = []
membership.collect { |e|
@memberships.push(e)
}
@memberships_doing = []
@memberships_done = []
now_time = Time.now.year
@memberships.map { |e|
end_time = e.course.get_time.year
isDone = course_endTime_timeout?(e.course)
if isDone
@memberships_done.push e
else
@memberships_doing.push e
end
}
end
def finishcourse
yesterday = Date.today.prev_day.to_time
@course_prefs.endup_time = yesterday
@save_flag = @course_prefs.save
get_courses
respond_to do |format|
format.js
end
end
def restartcourse
day = Time.parse("3000-01-01")
@course_prefs.endup_time = day
@save_flag = @course_prefs.save
get_courses
respond_to do |format|
format.js {
render action:'finishcourse'
}
end
end
def show
# try to redirect to the requested menu item
if params[:jump] && redirect_to_course_menu_item(@course, params[:jump])
return
end
@users_by_role = @course.users_by_role
if(User.find_by_id(CourseInfos.find_by_course_id(@course.id).try(:user_id)))
@user = User.find_by_id(CourseInfos.find_by_course_id(@course.id).user_id)
end
@key = User.current.rss_key
#新增内容
@days = Setting.activity_days_default.to_i
if params[:from]
begin; @date_to = params[:from].to_date + 1; rescue; end
end
has = {
"show_course_files" => true,
"show_course_news" => true,
"show_course_messages" => true,
"show_bids" => true,
"show_course_journals_for_messages" => true
}
@date_to ||= Date.today + 1
@date_from = @date_to - @days-1.years
@author = (params[:user_id].blank? ? nil : User.active.find(params[:user_id]))
# 决定显示所用用户或单个用户活动
@activity = Redmine::Activity::Fetcher.new(User.current, :course => @course,
:with_subprojects => false,
:author => @author)
@activity.scope_select {|t| has["show_#{t}"]}
events = @activity.events(@date_from, @date_to)
@offset, @limit = api_offset_and_limit({:limit => 10})
@events_count = events.count
@events_pages = Paginator.new @events_count, @limit, params['page']
@offset ||= @events_pages.offset
events = events.slice(@offset,@limit)
@events_by_day = events.group_by {|event| User.current.time_to_date(event.event_datetime)}
# documents
@sort_by = %w(category date title author).include?(params[:sort_by]) ? params[:sort_by] : 'category'
#
@teachers= searchTeacherAndAssistant(@course)
@canShowRealName = isCourseTeacher(User.current.id)
if(User.find_by_id(CourseInfos.find_by_course_id(@course.id).try(:user_id)))
@user = User.find_by_id(CourseInfos.find_by_course_id(@course.id).user_id)
end
respond_to do |format|
format.html{render :layout => 'base_courses'}
format.api
end
end
#判断指定用户是否为课程教师
def isCourseTeacher(id)
result = false
if @teachers && @teachers.find_by_user_id(id) != nil
result = true
end
result
end
def feedback
page = params[:page]
# Find the page of the requested reply
@jours = @course.journals_for_messages.where('m_parent_id IS NULL').order('created_on DESC')
@limit = 10
if params[:r] && page.nil?
offset = @jours.count(:conditions => ["#{JournalsForMessage.table_name}.id > ?", params[:r].to_i])
page = 1 + offset / @limit
end
@feedback_count = @jours.count
@feedback_pages = Paginator.new @feedback_count, @limit, page
@offset ||= @feedback_pages.offset
@jour = @jours[@offset, @limit]
@state = false
respond_to do |format|
format.html{render :layout => 'base_courses'}
format.api
end
end
private
def allow_join
if course_endTime_timeout? Project.find(params[:object_id])
if course_endTime_timeout? Course.find(params[:object_id])
respond_to do |format|
format.js {
@state = 2
render :partial => 'set_join',
:locals => {:user => User.current,
:course => Project.find(params[:object_id]),
:course => Course.find(params[:object_id]),
:object_id => params[:object_id]
}
}
@ -59,4 +714,8 @@ class CoursesController < ApplicationController
end
end
end

View File

@ -33,13 +33,15 @@ class FilesController < ApplicationController
'size' => "#{Attachment.table_name}.filesize",
'downloads' => "#{Attachment.table_name}.downloads"
@containers = [ Project.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").find(@project.id)] #modify by Long Jun
if params[:project_id]
@isproject = true
@containers = [ Project.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").find(@project.id)]
@containers += @project.versions.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").all.sort
if @project.project_type == 1
render :layout => 'base_courses'
else
render :layout => !request.xhr?
elsif params[:course_id]
@isproject = false
@containers = [ Course.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").find(@course.id)]
render :layout => 'base_courses'
end
end
@ -61,6 +63,8 @@ class FilesController < ApplicationController
format.js
end
else
#modify by nwb
if @project
@addTag=false
container = (params[:version_id].blank? ? @project : @project.versions.find_by_id(params[:version_id]))
attachments = Attachment.attach_filesex(container, params[:attachments], params[:attachment_type])
@ -89,6 +93,33 @@ class FilesController < ApplicationController
redirect_to project_files_path(@project)
}
end
elsif @course
@addTag=false
attachments = Attachment.attach_filesex(@course, params[:attachments], params[:attachment_type])
if !attachments.empty? && !attachments[:files].blank? && Setting.notified_events.include?('file_added')
Mailer.attachments_added(attachments[:files]).deliver
end
# TODO: 临时用 nyan
sort_init 'created_on', 'desc'
sort_update 'created_on' => "#{Attachment.table_name}.created_on",
'filename' => "#{Attachment.table_name}.filename",
'size' => "#{Attachment.table_name}.filesize",
'downloads' => "#{Attachment.table_name}.downloads"
@containers = [Course.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").find(@course.id)]
@attachtype = 0
@contenttype = 0
respond_to do |format|
format.js
format.html {
redirect_to course_files_path(@course)
}
end
end
end
end
@ -115,6 +146,8 @@ class FilesController < ApplicationController
@obj = Contest.find_by_id(@obj_id)
when '8'
@obj = OpenSourceProject.find_by_id(@obj_id)
when '9'
@obj = Course.find_by_id(@obj_id)
else
@obj = nil
end
@ -131,6 +164,7 @@ class FilesController < ApplicationController
end
# 返回制定资源类型的资源列表
# added by nwb
def getattachtype
sort_init 'created_on', 'desc'
sort_update 'created_on' => "#{Attachment.table_name}.created_on",
@ -138,8 +172,12 @@ class FilesController < ApplicationController
'size' => "#{Attachment.table_name}.filesize",
'downloads' => "#{Attachment.table_name}.downloads"
@containers = [ Project.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").find(@project.id)] #modify by Long Jun
if @project
@containers = [ Project.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").find(@project.id)]
@containers += @project.versions.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").all.sort
elsif @course
@containers = [ Course.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").find(@course.id)]
end
@attachtype = params[:type].to_i
@contenttype = params[:contentType].to_s

View File

@ -1,21 +1,22 @@
class HomeworkAttachController < ApplicationController
include CoursesHelper
###############################
#判断当前角色权限时需先找到当前操作的project
before_filter :find_project_by_bid_id, :only => [:new]
before_filter :find_project_by_hoemwork_id, :only => [:edit,:update,:destroy,:show,:add_homework_users,:destory_homework_users]
before_filter :find_course_by_bid_id, :only => [:new]
before_filter :find_course_by_hoemwork_id, :only => [:edit,:update,:destroy,:show,:add_homework_users,:destory_homework_users]
#判断当前角色是否有操作权限
#勿删 before_filter :authorize, :only => [:new,:edit,:update,:destroy]
def find_project_by_bid_id
def find_course_by_bid_id
@bid = Bid.find(params[:id])
@project = @bid.courses[0]
@course = @bid.courses[0]
rescue ActiveRecord::RecordNotFound
render_404
end
def find_project_by_hoemwork_id
def find_course_by_hoemwork_id
@homework = HomeworkAttach.find(params[:id])
@project = @homework.bid.courses[0]
@course = @homework.bid.courses[0]
end
#获取作业的成员
@ -35,7 +36,7 @@ class HomeworkAttachController < ApplicationController
#作业添加成员(参与人员)
def add_homework_users
if User.current.admin? || User.current.member_of?(@homework.bid.courses.first)
if User.current.admin? || User.current.member_of_course?(@homework.bid.courses.first)
#@homework = HomeworkAttach.find(params[:id])
if params[:membership]
if params[:membership][:user_ids]
@ -59,7 +60,7 @@ class HomeworkAttachController < ApplicationController
#作业删除成员(参与人员)
def destory_homework_users
#@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_course?(@homework.bid.courses.first)
homework_user = @homework.homework_users.where("user_id = #{params[:user_id]}").first
homework_user.destroy
get_homework_member @homework
@ -73,10 +74,19 @@ class HomeworkAttachController < ApplicationController
def create
bid = Bid.find params[:bid_id]
if User.current.admin? || User.current.member_of?(bid.courses.first)
if User.current.admin? || User.current.member_of_course?(bid.courses.first) # modify by nwb
if bid.homeworks.where("user_id = ?",User.current).count == 0
user_id = params[:user_id]
bid_id = params[:bid_id]
if params[:homework_attach]
if params[:homework_attach][:project_id]
project_id = params[:homework_attach][:project_id]
else
project_id = 0
end
else
project_id = 0
end
sta = 0
name = params[:new_form][:name]
description = params[:new_form][:description]
@ -85,7 +95,8 @@ class HomeworkAttachController < ApplicationController
:state => sta,
:name => name,
:description => description,
:bid_id => bid_id
:bid_id => bid_id,
:project_id => project_id
}
@ -97,7 +108,7 @@ class HomeworkAttachController < ApplicationController
if @homework.save
respond_to do |format|
format.html { redirect_to project_for_bid_path @homework.bid }
format.html { redirect_to course_for_bid_path @homework.bid }
format.json { head :no_content }
end
else
@ -113,7 +124,7 @@ class HomeworkAttachController < ApplicationController
def new
@bid = Bid.find(params[:id])
if User.current.admin? || User.current.member_of?(@bid.courses.first)
if User.current.admin? || User.current.member_of_course?(@bid.courses.first) #nwb
#该课程的学生的集合(新建不实现功能:添加成员)
#@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]})
@ -138,7 +149,7 @@ class HomeworkAttachController < ApplicationController
def get_homework_member_list
@homework = HomeworkAttach.find(params[:bid_id])
course = @homework.bid.courses.first
if User.current.admin? || User.current.member_of?(course)
if User.current.admin? || User.current.member_of_course?(course)
get_homework_member @homework
else
raise "error"
@ -163,7 +174,7 @@ class HomeworkAttachController < ApplicationController
def edit
#@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_course?(@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]})
get_homework_member @homework
else
@ -174,17 +185,27 @@ class HomeworkAttachController < ApplicationController
def update
#@homework = HomeworkAttach.find(params[:id])
course = @homework.bid.courses.first
if User.current.admin? || User.current.member_of?(course)
if User.current.admin? || User.current.member_of_course?(course)
name = params[:homework_name]
description = params[:homework_description]
if params[:homework_attach]
if params[:homework_attach][:project_id]
project_id = params[:homework_attach][:project_id]
else
project_id = 0
end
else
project_id = 0
end
@homework.name = name
@homework.description = description
@homework.project_id = project_id
if params[:attachments]
@homework.save_attachments(params[:attachments])
end
if @homework.save
respond_to do |format|
format.html { redirect_to project_for_bid_path @homework.bid }
format.html { redirect_to course_for_bid_path @homework.bid }
format.json { head :no_content }
end
else
@ -196,10 +217,10 @@ class HomeworkAttachController < ApplicationController
def destroy
#@homework = HomeworkAttach.find(params[:id])
if User.current.admin? || User.current == @homework
if User.current.admin? || User.current == @homework.user
if @homework.destroy
respond_to do |format|
format.html { redirect_to project_for_bid_path @homework.bid }
format.html { redirect_to course_for_bid_path @homework.bid }
format.json { head :no_content }
end
else
@ -212,7 +233,7 @@ class HomeworkAttachController < ApplicationController
#显示作业信息
def show
#@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_course?(@homework.bid.courses.first)
# 打分统计
stars_reates = @homework.
rates(:quality)
@ -237,6 +258,9 @@ class HomeworkAttachController < ApplicationController
@offset ||= @feedback_pages.offset
@jour = @jours[@offset, @limit]
@comprehensive_evaluation = @homework.journals_for_messages.where("is_comprehensive_evaluation is not null").order("created_on DESC")
@totle_score = score_for_homework @homework
@teaher_score = teacher_score_for_homework @homework
else
render_403 :message => :notice_not_authorized
end
@ -268,11 +292,24 @@ class HomeworkAttachController < ApplicationController
@offset ||= @feedback_pages.offset
@jour = @jours[@offset, @limit]
@comprehensive_evaluation = @homework.journals_for_messages.where("is_comprehensive_evaluation is not null").order("created_on DESC")
@totle_score = score_for_homework @homework
@teaher_score = teacher_score_for_homework @homework
respond_to do |format|
format.js
end
end
#教师综评
def comprehensive_evaluation_jour
@homework = HomeworkAttach.find(params[:jour_id])
@add_jour = @homework.addjours User.current.id, params[:new_form][:user_message],0,params[:is_comprehensive_evaluation]
respond_to do |format|
format.html { redirect_to homework_attach_path @homework }
format.json { head :no_content }
end
end
#获取指定作业的平均得分
def score
#stars_reates = @homework.rates(:quality)

View File

@ -22,6 +22,7 @@ class MembersController < ApplicationController
before_filter :find_project_by_project_id, :only => [:index, :create, :autocomplete]
before_filter :authorize
accept_api_auth :index, :show, :create, :update, :destroy
def index
@offset, @limit = api_offset_and_limit
@member_count = @project.member_principals.count
@ -60,10 +61,13 @@ class MembersController < ApplicationController
end
end
else
#modify by nwb
#更改课程成员逻辑
applied_members = false
members = []
project_info = []
user_grades = []
if @project
project_info = []
if params[:membership]
if params[:membership][:user_ids]
attrs = params[:membership].dup
@ -93,15 +97,11 @@ class MembersController < ApplicationController
@project.user_grades << user_grades
# end
end
end
if members.present? && members.all? { |m| m.valid? }
members.each do |member|
AppliedProject.deleteappiled(member.user_id, @project.id)
end
end
respond_to do |format|
format.html { redirect_to_settings_in_projects }
format.js { @members = members; @applied_members = applied_members; }
@ -114,9 +114,50 @@ class MembersController < ApplicationController
end
}
end
elsif @course
course_info = []
if params[:membership]
if params[:membership][:user_ids]
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)
user_grades << UserGrade.new(:user_id => user_id, :course_id => @course.id)
if (params[:membership][:role_ids] && params[:membership][:role_ids][0] == "3")
course_info << CourseInfo.new(:user_id => user_id, :course_id => @course.id)
end
end
else
members << Member.new(:role_ids => params[:membership][:role_ids], :user_id => params[:membership][:user_id])
if (params[:membership][:role_ids] && params[:membership][:role_ids][0] == "3")
course_info << CourseInfo.new(:course_id => @course.id, :user_id => params[:membership][:user_id])
end
end
@course.members << members
@course.course_infos << course_info
end
respond_to do |format|
format.html { redirect_to_settings_in_courses }
format.js { @members = members; @applied_members = applied_members; }
format.api {
@member = members.first
if @member.valid?
render :action => 'show', :status => :created, :location => membership_url(@member)
else
render_validation_errors(@member)
end
}
end
end # end of if @project
end # end of params[:refusal_button]
end
def update
#modify by nwb
#增加对课程成员修改的支持
if @project
if params[:membership]
@member.role_ids = params[:membership][:role_ids]
@ -146,9 +187,43 @@ class MembersController < ApplicationController
end
}
end
elsif @course
if params[:membership]
@member.role_ids = params[:membership][:role_ids]
if (params[:membership][:role_ids] && params[:membership][:role_ids][0] == "3")
@courseInfo = CourseInfos.new(:user_id => @member.user_id, :course_id => @course.id)
@courseInfo.save
else
user_admin = CourseInfos.where("user_id = ? and course_id = ?", @member.user_id, @course.id)
if user_admin.size > 0
user_admin.each do |user|
user.destroy
end
end
end
end
saved = @member.save
respond_to do |format|
format.html { redirect_to_settings_in_courses }
format.js
format.api {
if saved
render_api_ok
else
render_validation_errors(@member)
end
}
end
end
end
def destroy
#modify by nwb
#课程成员删除修改
if @project
if request.delete? && @member.deletable?
@member.destroy
# end
@ -176,6 +251,28 @@ class MembersController < ApplicationController
end
}
end
elsif @course
if request.delete? && @member.deletable?
@member.destroy
user_admin = CourseInfos.where("user_id = ? and course_id = ?", @member.user_id, @course.id)
if user_admin.size > 0
user_admin.each do |user|
user.destroy
end
end
end
respond_to do |format|
format.html { redirect_to_settings_in_courses }
format.js
format.api {
if @member.destroyed?
render_api_ok
else
head :unprocessable_entity
end
}
end
end
end
def autocomplete
@ -189,4 +286,8 @@ class MembersController < ApplicationController
def redirect_to_settings_in_projects
redirect_to settings_project_path(@project, :tab => 'members')
end
def redirect_to_settings_in_courses
redirect_to settings_course_path(@course, :tab => 'members')
end
end

View File

@ -49,7 +49,7 @@ class MessagesController < ApplicationController
all
@reply = Message.new(:subject => "RE: #{@message.subject}")
if @message.board.project.project_type ==1
if @course
render :action => "show", :layout => "base_courses"#by young
else
render :action => "show", :layout => "base_projects"#by young
@ -68,6 +68,9 @@ class MessagesController < ApplicationController
call_hook(:controller_messages_new_after_save, { :params => params, :message => @message})
render_attachment_warning_if_needed(@message)
redirect_to board_message_path(@board, @message)
else
layout_file = @project ? 'base_projects' : 'base_courses'
render :action => 'new', :layout => layout_file
end
end
end
@ -138,8 +141,14 @@ private
end
def find_board
@board = Board.find(params[:board_id], :include => :project)
#modify by nwb
@board = Board.find(params[:board_id])
if @board.project_id != -1 && @board.project_id != nil
@project = @board.project
elsif @board.course_id
@course = @board.course
end
rescue ActiveRecord::RecordNotFound
render_404
nil

View File

@ -61,7 +61,7 @@ class MyController < ApplicationController
end
end
@se = @user.user_extensions ||= UserExtensions.new
@se = @user.extensions
@se.school_id = params[:occupation] if params[:occupation]
@se.gender = params[:gender]
@se.location = params[:province] if params[:province]

View File

@ -38,6 +38,11 @@ class NewsController < ApplicationController
@limit = 10
end
# modify by nwb
if params[:course_id] && @course==nil
@course = Course.find(params[:course_id])
end
if @project
scope = @project ? @project.news.visible : News.visible
@news_count = scope.count
@ -53,24 +58,44 @@ class NewsController < ApplicationController
@news = News.new # for adding news inline
# huang
if @project.project_type == 1
render :layout => 'base_courses'
else
render :layout => false if request.xhr?
end
}
format.api
format.atom { render_feed(@newss, :title => (@project ? @project.name : Setting.app_title) + ": #{l(:label_news_plural)}") }
end
elsif @course
scope = @course ? @course.news.course_visible : News.course_visible
@news_count = scope.count
@news_pages = Paginator.new @news_count, @limit, params['page']
@offset ||= @news_pages.offset
@newss = scope.all(:include => [:author, :course],
:order => "#{News.table_name}.created_on DESC",
:offset => @offset,
:limit => @limit)
respond_to do |format|
format.html {
@news = News.new
render :layout => 'base_courses'
}
format.api
format.atom { render_feed(@newss, :title => (@course ? @course.name : Setting.app_title) + ": #{l(:label_news_plural)}") }
end
end
end
def show
@comments = @news.comments
@comments.reverse! if User.current.wants_comments_in_reverse_order?
if @project.project_type == 1
#modify by nwb
if @news.course_id
@course = Course.find(@news.course_id)
if @course
render :layout => 'base_courses'
end
end
end
def new
@news = News.new(:project => @project, :author => User.current)
@ -81,6 +106,8 @@ class NewsController < ApplicationController
end
def create
#modify by nwb
if @project
@news = News.new(:project => @project, :author => User.current)
@news.safe_attributes = params[:news]
@news.save_attachments(params[:attachments])
@ -89,9 +116,22 @@ class NewsController < ApplicationController
flash[:notice] = l(:notice_successful_create)
redirect_to project_news_index_path(@project)
else
layout_file = (@project.project_type == 1) ? 'base_courses' : 'base_projects'
layout_file = @project ? 'base_projects' : 'base_courses'
render :action => 'new', :layout => layout_file
end
elsif @course
@news = News.new(:course => @course, :author => User.current)
@news.safe_attributes = params[:news]
@news.save_attachments(params[:attachments])
if @news.save
render_attachment_warning_if_needed(@news)
flash[:notice] = l(:notice_successful_create)
redirect_to course_news_index_path(@course)
else
layout_file = 'base_courses'
render :action => 'new', :layout => layout_file
end
end
end
def edit
@ -111,7 +151,13 @@ class NewsController < ApplicationController
def destroy
@news.destroy
# modify by nwb
if @project
redirect_to project_news_index_path(@project)
elsif @course
redirect_to course_news_index_path(@course)
end
end
private

View File

@ -9,9 +9,13 @@ class PraiseTreadController < ApplicationController
if request.get?
@obj_id = params[:obj_id]
@obj_type = params[:obj_type]
@horizontal = params[:horizontal].downcase == "false" ? false:true
@obj = find_object_by_type_and_id(@obj_type,@obj_id)
unless @obj.author_id == User.current.id
praise_tread_plus(@obj_type,@obj_id,1)
end
end
end
def praise_minus
@ -44,9 +48,13 @@ class PraiseTreadController < ApplicationController
if request.get?
@obj_id = params[:obj_id]
@obj_type = params[:obj_type]
@horizontal = params[:horizontal].downcase == "false" ? false:true
@obj = find_object_by_type_and_id(@obj_type,@obj_id)
unless @obj.author_id == User.current.id
praise_tread_plus(@obj_type,@obj_id,0)
end
end
end
def tread_minus

View File

@ -353,27 +353,13 @@ class ProjectsController < ApplicationController
#gcmend
# added by fq
def new_join
@course = Project.find(params[:object_id])
end
#Added by young
def homework
@offset, @limit = api_offset_and_limit({:limit => 10})
@bids = @project.homeworks.order('deadline DESC')
@bids = @project.homeworks.order('deadline')
@bids = @bids.like(params[:name]) if params[:name].present?
@bid_count = @bids.count
@bid_pages = Paginator.new @bid_count, @limit, params['page']
@offset ||= @bid_pages.reverse_offset
#@bids = @bids.offset(@offset).limit(@limit).all.reverse
unless @offset == 0
@bids = @bids.offset(@offset).limit(@limit).all.reverse
else
limit = @bid_count % @limit
@bids = @bids.offset(@offset).limit(limit).all.reverse
end
@bids = paginateHelper @bids
render :layout => 'base_courses'
end
@ -920,11 +906,13 @@ class ProjectsController < ApplicationController
# added by bai
def show_projects_score
render :layout => false
end
def issue_score_index
respond_to do |format|
format.js
end
end
def news_score_index

View File

@ -568,7 +568,7 @@ class RepositoriesController < ApplicationController
project = Project.find(params[:id])
if !User.current.member_of?(project)
if project.hidden_repo
render_403
#render_403
end
end
rescue ActiveRecord::RecordNotFound

View File

@ -5,6 +5,7 @@ class TagsController < ApplicationController
before_filter :require_admin,:only => :show
include CoursesHelper
include ProjectsHelper
include IssuesHelper
include UsersHelper
@ -14,6 +15,7 @@ class TagsController < ApplicationController
include ContestsHelper
include ActsAsTaggableOn::TagsHelper
helper :projects
helper :courses
include TagsHelper
helper :tags
include OpenSourceProjectsHelper
@ -64,6 +66,7 @@ class TagsController < ApplicationController
# 获取搜索结果
@obj,@obj_pages,@results_count,@users_results,
@projects_results,
@@courses_results,
@issues_results,
@bids_results,
@forums_results,
@ -96,6 +99,7 @@ class TagsController < ApplicationController
# 获取搜索结果
@obj,@obj_pages,@results_count,@users_results,
@projects_results,
@@courses_results,
@issues_results,
@bids_results,
@forums_results,
@ -114,6 +118,7 @@ class TagsController < ApplicationController
# 获取搜索结果
@obj,@obj_pages,@results_count,@users_results,
@projects_results,
@@courses_results,
@issues_results,
@bids_results,
@forums_results,
@ -188,6 +193,7 @@ class TagsController < ApplicationController
@obj_pages = nil
@obj = nil
@result = nil
@courses_results = nil
# 这里为了提高系统的响应速度 把搜索结果放到case中去了
case obj_flag
@ -219,6 +225,9 @@ class TagsController < ApplicationController
when '8'
@obj = OpenSourceProject.find_by_id(obj_id)
@obj_pages, @open_source_projects_results, @results_count = for_pagination(get_open_source_projects_by_tag(selected_tags))
when '9' then
@obj = Course.find_by_id(obj_id)
@obj_pages, @courses_results, @results_count = for_pagination(get_courses_by_tag(selected_tags))
else
@obj = nil
end
@ -232,6 +241,7 @@ class TagsController < ApplicationController
@forums_results,
attachments_results,
@contests_results,
@courses_results,
@open_source_projects_results]
end
@ -279,6 +289,8 @@ class TagsController < ApplicationController
return 'Contest'
when '8'
return 'OpenSourceProject'
when '9'
return 'Course'
else
render_error :message => e.message
return

View File

@ -32,12 +32,14 @@ class UsersController < ApplicationController
before_filter :require_admin, :except => [:show, :index, :search, :tag_save, :tag_saveEx,:user_projects, :user_newfeedback, :user_comments, :watch_bids, :watch_contests, :info,
:user_watchlist, :user_fanslist,:update, :user_courses, :user_homeworks, :watch_projects, :show_score, :topic_score_index, :project_score_index,
:activity_score_index, :influence_score_index, :score_index]
:activity_score_index, :influence_score_index, :score_index,:show_new_score, :topic_new_score_index, :project_new_score_index,
:activity_new_score_index, :influence_new_score_index, :score_new_index,:update_score]
#edit has been deleted by huang, 2013-9-23
before_filter :find_user, :only => [:user_fanslist, :user_watchlist, :show, :edit, :update, :destroy, :edit_membership, :user_courses,
:user_homeworks, :destroy_membership, :user_activities, :user_projects, :user_newfeedback, :user_comments,
:watch_bids, :watch_contests, :info, :watch_projects, :show_score, :topic_score_index, :project_score_index,
:activity_score_index, :influence_score_index, :score_index]
:activity_score_index, :influence_score_index, :score_index,:show_new_score, :topic_new_score_index, :project_new_score_index,
:activity_new_score_index, :influence_new_score_index, :score_new_index]
before_filter :auth_user_extension, only: :show
accept_api_auth :index, :show, :create, :update, :destroy,:tag_save , :tag_saveEx
@ -94,6 +96,10 @@ class UsersController < ApplicationController
def show_score
end
def show_new_score
render :layout => false
end
# end
##added by fq
@ -200,19 +206,19 @@ class UsersController < ApplicationController
end
end
membership = @user.memberships.all(:conditions => Project.visible_condition(User.current))
membership = @user.coursememberships.all#@user.coursememberships.all(:conditions => Course.visible_condition(User.current))
membership.sort! {|older, newer| newer.created_on <=> older.created_on }
@memberships = []
membership.collect { |e|
@memberships.push(e) if(e.project.project_type == 1)
@memberships.push(e)
}
## 判断课程是否过期 [需封装]
@memberships_doing = []
@memberships_done = []
now_time = Time.now.year
@memberships.map { |e|
end_time = e.project.course_extra.get_time.year
isDone = course_endTime_timeout?(e.project)
end_time = e.course.get_time.year
isDone = course_endTime_timeout?(e.course)
if isDone
@memberships_done.push e
else
@ -669,6 +675,8 @@ class UsersController < ApplicationController
@obj = Contest.find_by_id(@obj_id)
when '8'
@obj = OpenSourceProject.find_by_id(@obj_id)
when '9'
@obj = Course.find_by_id(@obj_id)
else
@obj = nil
end
@ -710,6 +718,8 @@ class UsersController < ApplicationController
@obj = Contest.find_by_id(@obj_id)
when '8'
@obj = OpenSourceProject.find_by_id(@obj_id)
when '9'
@obj = Course.find_by_id(@obj_id)
else
@obj = nil
end
@ -767,6 +777,29 @@ class UsersController < ApplicationController
end
# end
def topic_new_score_index
end
def project_new_score_index
end
def activity_new_score_index
end
def influence_new_score_index
end
def score_new_index
end
def update_score
@user = User.find(params[:id])
end
private

View File

@ -164,6 +164,20 @@ class WordsController < ApplicationController
end
# add by nwb
def leave_course_message
user = User.current
message = params[:new_form][:course_message]
feedback = Course.add_new_jour(user, message, params[:id])
if(feedback.errors.empty?)
redirect_to course_feedback_path(params[:id]), notice: l(:label_feedback_success)
else
flash[:error] = feedback.errors.full_messages[0]
redirect_to course_feedback_path(params[:id])
end
end
def add_brief_introdution
user = User.current
message = params[:new_form][:user_introduction]
@ -182,10 +196,14 @@ class WordsController < ApplicationController
end
def obj_distinguish_url_origin
#modify by nwb
#添加对课程留言的支持
referer = request.headers["Referer"]
obj_id = referer.match(%r(/([0-9]{1,})(/|$)))[1]
if referer.match(/project/)
obj = Project.find_by_id(obj_id)
elsif referer.match(/course/)
obj = Course.find_by_id(obj_id)
elsif referer.match(/user/)
obj = User.find_by_id(obj_id)
elsif ( referer.match(/bids/) || referer.match(/calls/) )
@ -203,11 +221,15 @@ class WordsController < ApplicationController
end
def add_reply_adapter options
#modify by nwb
#添加对课程留言的支持
obj = obj_distinguish_url_origin
if obj.kind_of? User
obj.add_jour(nil, nil, nil, options)
elsif obj.kind_of? Project
Project.add_new_jour(nil, nil, obj.id, options)
elsif obj.kind_of? Course
Course.add_new_jour(nil, nil, obj.id, options)
elsif obj.kind_of? Bid
obj.add_jour(nil, nil, nil, options)
elsif obj.kind_of? Contest

View File

@ -27,7 +27,7 @@ class ZipdownController < ApplicationController
else
logger.error "[ZipDown#assort] ===> #{obj.class.to_s.to_sym} unKown !!"
end
send_file zipfile, :filename => obj.name, :type => detect_content_type(zipfile) if zipfile
send_file zipfile, :filename => obj.name+".zip", :type => detect_content_type(zipfile) if zipfile
#rescue NameError, ActiveRecord::RecordNotFound => e
#logger.error "[ZipDown] ===> #{e}"
@ -37,9 +37,9 @@ class ZipdownController < ApplicationController
#下载某一学生的作业的所有文件
def download_user_homework
homework = HomeworkAttach.find params[:homework]
if homework != nil && (User.current.admin? || User.current.member_of?(homework.bid.courses.first))
if homework != nil && (User.current.admin? || User.current.member_of_course?(homework.bid.courses.first))
zipfile = zip_homework_by_user homework
send_file zipfile, :filename => homework.name, :type => detect_content_type(zipfile) if zipfile
send_file zipfile, :filename => homework.name+".zip", :type => detect_content_type(zipfile) if zipfile
else
render_403 :message => :notice_not_authorized
end
@ -88,7 +88,7 @@ class ZipdownController < ApplicationController
#length = attach.storage_path.length
homeworks_attach_path << attach.diskfile#.to_s.slice((length+1)..-1)
end
zipping "#{homeattach.user.name.to_s}.zip", homeworks_attach_path, OUTPUT_FOLDER, true
zipping "#{homeattach.user.name.to_s}_#{Time.now.to_i}.zip", homeworks_attach_path, OUTPUT_FOLDER, true
#user_attaches_paths
end

View File

@ -39,7 +39,9 @@ module ApplicationHelper
# REVIEW: 目测menu的机制貌似不是很需要转换再说
def link_class(label)
labels = label.is_a?(Array) ? label : ([] << label)
#a = current_menu_item
labels.include?(current_menu_item) ? 'selected' : ''
end
#Ended by young
# Return true if user is authorized for controller/action, otherwise false
@ -47,6 +49,11 @@ module ApplicationHelper
User.current.allowed_to?({:controller => controller, :action => action}, @project)
end
# add by nwb
def authorize_for_course(controller, action)
User.current.allowed_to?({:controller => controller, :action => action}, @course)
end
def authorize_for_contest(controller, action)
User.current.allowed_to?({:controller => controller, :action => action}, @contest)
end
@ -177,6 +184,18 @@ module ApplicationHelper
end
end
def link_to_course(course, options={}, html_options = nil)
if course.archived?
h(course.name)
elsif options.key?(:action)
ActiveSupport::Deprecation.warn "#link_to_course with :action option is deprecated and will be removed in Redmine 3.0."
url = {:controller => 'courses', :action => 'show', :id => project}.merge(options)
link_to course.name, url, html_options
else
link_to course.name, course_path(course, options), html_options
end
end
# Generates a link to a project settings if active
def link_to_project_settings(project, options={}, html_options=nil)
if project.active?
@ -304,6 +323,40 @@ module ApplicationHelper
end
s.html_safe
end
def render_course_nested_lists(courses)
s = ''
if courses.any?
ancestors = []
original_course = @course
#modified by nie
courses.each do |course|
# set the project environment to please macros.
@course = course
if (ancestors.empty? )#|| course.is_descendant_of?(ancestors.last))
s << "<ul class=courses'>\n"
else
ancestors.pop
s << "</li>"
while (ancestors.any? )#&& !course.is_descendant_of?(ancestors.last))
ancestors.pop
s << "</ul></li>\n"
end
end
classes = (ancestors.empty? ? 'root' : 'child')
s << "<li class='project-table'><div class='#{classes}'>"
s << (render :partial => 'courses/course', :locals => {:course => course}).to_s
s << "</div>\n"
ancestors << course
end
s << ("</li></ul>\n" * ancestors.size)
@course = original_course
end
s.html_safe
end
#added by young
def render_project_nested_lists_new(projects)
s = ''
@ -1645,9 +1698,9 @@ module ApplicationHelper
main_project_link = link_to l(:label_project_deposit), {:controller => 'welcome', :action => 'index', :host => Setting.project_domain}
main_contest_link = link_to l(:label_contest_innovate), {:controller => 'welcome', :action => 'index', :host => Setting.contest_domain}
course_all_course_link = link_to l(:label_course_all), {:controller => 'projects', :action => 'course', :project_type => 1, :host => Setting.course_domain}
course_all_course_link = link_to l(:label_course_all), {:controller => 'courses', :action => 'index'}
course_teacher_all_link = link_to l(:label_teacher_all), {:controller => 'users', :action => 'index', :role => 'teacher', :host => Setting.course_domain}
courses_link = link_to l(:label_course_practice), {:controller => 'projects', :action => 'course', :project_type => 1, :host => Setting.course_domain}
courses_link = link_to l(:label_course_practice), {:controller => 'courses', :action => 'index'}
projects_link = link_to l(:label_project_deposit), {:controller => 'projects', :action => 'index', :project_type => 0, :host => Setting.project_domain}
users_link = link_to l(:label_software_user), {:controller => 'users', :action => 'index', :host => Setting.user_domain}
contest_link = link_to l(:label_contest_innovate), {:controller => 'contests', :action => 'index'}

View File

@ -42,7 +42,7 @@ module AvatarHelper
end
def get_avatar?(source)
if File.exist?(disk_filename(source.class,source.id))
if source && File.exist?(disk_filename(source.class,source.id))
return true
else
return false

View File

@ -29,6 +29,19 @@ module BoardsHelper
breadcrumb links
end
# add by nwb
def course_board_breadcrumb(item)
board = item.is_a?(Message) ? item.board : item
links = [link_to(l(:label_board_plural), course_boards_path(item.course))]
boards = board.ancestors.reverse
if item.is_a?(Message)
boards << board
end
links += boards.map {|ancestor| link_to(h(ancestor.name), course_board_path(ancestor.course, ancestor))}
breadcrumb links
end
def boards_options_for_select(boards)
options = []
Board.board_tree(boards) do |board, level|

View File

@ -57,6 +57,7 @@ module ContestsHelper
#end
#huang
def sort_contest(state)
content = ''.html_safe

View File

@ -31,6 +31,39 @@ module CoursesHelper
# searchStudent(project).count
end
# 判断用户是否是课程的管理员
# add by nwb
def is_course_manager?(user_id,course_id)
@result = false
@user_id = CourseInfo.find_by_course_id(course_id)
if @user_id == user.id
@result = true
end
return @result
end
# 返回课程设置界面
def course_settings_tabs
tabs = [{:name => 'info', :action => :edit_course, :partial => 'courses/edit', :label => :label_information_plural},
{:name => 'members', :action => :manage_members, :partial => 'courses/settings/members', :label => :label_member_plural}
]
tabs.select { |tab| User.current.allowed_to?(tab[:action], @course) }
end
#是否启动互评下拉框
def is_evaluation_option
type = []
option1 = []
option2 = []
option1 << l(:lable_start_mutual_evaluation)
option1 << 1
option2 << l(:lable_close_mutual_evaluation)
option2 << 2
type << option1
type << option2
end
# garble count 混淆数量
# alias projectCountOrigin projectCount
# def projectCount project
@ -38,6 +71,19 @@ module CoursesHelper
# garble count
# end
def homework_type_option
type = []
option1 = []
option2 = []
option1 << l(:label_task_submit_form_accessory)
option1 << 1
option2 << l(:label_task_submit_form_project)
option2 << 2
type << option1
type << option2
end
alias teacherCountOrigin teacherCount
def teacherCount project
count = teacherCountOrigin project
@ -45,11 +91,26 @@ module CoursesHelper
end
alias studentCountOrigin studentCount
def studentCount project
count = studentCountOrigin project
def studentCount course
count = studentCountOrigin course
garble count
end
def eventToLanguageCourse event_type, course
case event_type
when "issue-note"
l :label_issue
when "issue"
l :label_issue
when "attachment"
l :label_attachment
when "news"
l :label_notification
else
""
end
end
def garble count
count = count.round( 1-count.to_s.size ).to_i
return count.to_s if count.to_s.size.eql?(1)
@ -82,6 +143,35 @@ module CoursesHelper
members
end
def sort_courses(state)
content = ''.html_safe
case state
when 0
content << content_tag('li', link_to(l(:label_sort_by_active), courses_path(:courses_sort_type => '1')))
content << content_tag('li', link_to(l(:label_sort_by_influence), courses_path(:courses_sort_type => '2')))
content << content_tag('li', link_to(l(:label_sort_by_time), courses_path(:courses_sort_type => '0'), :class=>"selected"), :class=>"selected")
when 1
content << content_tag('li', link_to(l(:label_sort_by_active), courses_path(:courses_sort_type => '1'), :class=>"selected"), :class=>"selected")
content << content_tag('li', link_to(l(:label_sort_by_influence), courses_path(:courses_sort_type => '2')))
content << content_tag('li', link_to(l(:label_sort_by_time), courses_path(:courses_sort_type => '0')))
when 2
content << content_tag('li', link_to(l(:label_sort_by_active), courses_path(:courses_sort_type => '1')))
content << content_tag('li', link_to(l(:label_sort_by_influence), courses_path(:courses_sort_type => '2'), :class=>"selected"), :class=>"selected")
content << content_tag('li', link_to(l(:label_sort_by_time), courses_path(:courses_sort_type => '0')))
end
content = content_tag('ul', content)
content_tag('div', content, :class => "tabs")
end
def render_course_hierarchy(courses)
render_course_nested_lists(courses) do |course|
s = link_to_course(course, {}, :class => "#{course.css_classes} #{User.current.member_of?(course) ? 'my-course' : nil}").html_safe
s
end
end
#useless
def searchMembersByRole project, role_id
members = []
@ -93,6 +183,36 @@ module CoursesHelper
members
end
def sort_course(state, school_id)
content = ''.html_safe
case state
when 0
content << content_tag('li', link_to(l(:label_sort_by_time), courses_path(:course_sort_type => '0'), :school_id => school_id, :class=>"selected"), :class=>"selected")
content << content_tag('li', link_to(l(:label_sort_by_active), courses_path(:course_sort_type => '1', :school_id => school_id)))
content << content_tag('li', link_to(l(:label_sort_by_activity), courses_path(:course_sort_type => '3', :school_id => school_id)))
when 1
content << content_tag('li', link_to(l(:label_sort_by_time), courses_path(:course_sort_type => '0', :school_id => school_id)))
content << content_tag('li', link_to(l(:label_sort_by_active), courses_path(:course_sort_type => '1', :school_id => school_id), :class=>"selected"), :class=>"selected")
content << content_tag('li', link_to(l(:label_sort_by_activity), courses_path(:course_sort_type => '3', :school_id => school_id)))
when 2
content << content_tag('li', link_to(l(:label_sort_by_time), courses_path(:course_sort_type => '0', :school_id => school_id)))
content << content_tag('li', link_to(l(:label_sort_by_active), courses_path(:course_sort_type => '1', :school_id => school_id)))
content << content_tag('li', link_to(l(:label_sort_by_activity), courses_path(:course_sort_type => '3', :school_id => school_id)))
#gcm
when 3
content << content_tag('li', link_to(l(:label_sort_by_time), courses_path(:course_sort_type => '0', :school_id => school_id)))
content << content_tag('li', link_to(l(:label_sort_by_active), courses_path(:course_sort_type => '1', :school_id => school_id)))
content << content_tag('li', link_to(l(:label_sort_by_activity), courses_path(:course_sort_type => '3', :school_id => school_id), :class=>"selected"), :class=>"selected")
end
#gcmend
content = content_tag('ul', content)
content_tag('div', content, :class => "tabs")
end
def findCourseTime project
str = ""
begin
@ -109,8 +229,9 @@ module CoursesHelper
str
end
def get_course_term project
str = ( project.try(:course_extra).try(:time).to_s << '.' << project.try(:course_extra).try(:term).to_s )
# added by nwb
def get_course_term course
str = ( course.try(:time).to_s << '.' << course.try(:term).to_s )
str[0..-4]
end
@ -123,7 +244,7 @@ module CoursesHelper
end
# 截至到2014-03-17 这个是最终的判断课程是否过期的方法
def course_endTime_timeout? project
end_time_str = Course.find_by_extra(project.try(:identifier)).try(:endup_time)
end_time_str = Course.find_by_extra(project.try(:extra)).try(:endup_time)
begin
cTime = Time.parse(end_time_str.to_s)
rescue TypeError,ArgumentError
@ -182,4 +303,71 @@ module CoursesHelper
def users_for_homework homework
homework.nil? ? [] : (homework.users + [homework.user])
end
#获取指定作业的最终评分
#最终评分 = 学生评分的平均分 * 0.4 +教师评分 * 0.6
def score_for_homework homework
if homework.bid.is_evaluation == 1 || homework.bid.is_evaluation == nil
return format("%.2f",(teacher_score_for_homework(homework).to_f * 0.6 + student_score_for_homework(homework).to_f * 0.4))
else
return teacher_score_for_homework homework
end
end
#获取作业的互评得分
def student_score_for_homework homework
member = searchPeopleByRoles(homework.bid.courses.first,TeacherRoles).first
student_stars = homework.rates(:quality).where("rater_id <> #{member.user_id}").select("stars")
student_stars_count = 0
student_stars.each do |star|
student_stars_count = student_stars_count + star.stars
end
return format("%.2f",student_stars_count / (student_stars.count == 0 ? 1 : student_stars.count))
end
#获取作业的教师评分
def teacher_score_for_homework homework
member = searchPeopleByRoles(homework.bid.courses.first,TeacherRoles).first
teacher_stars = homework.rates(:quality).where("rater_id = #{member.user_id}").select("stars").first
return format("%.2f",teacher_stars == nil ? 0 : teacher_stars.stars)
end
#获取指定作业的得分
def project_score project
issue_count = project.issues.count
issue_journal_count = project.issue_changes.count
issue_score = issue_count * 0.2
issue_journal_score = issue_journal_count * 0.1
finall_issue_score = issue_score + issue_journal_score
new_count = project.news.count
new_score = new_count * 0.1
finall_new_score = new_score
document_count = project.documents.count
file_score = document_count * 0.1
finall_file_score = file_score
changeset_count = project.changesets.count
code_submit_score = changeset_count * 0.3
finall_code_submit_score = code_submit_score
board_message_count = 0
project.boards.each do |board|
board_message_count += board.messages_count
end
topic_score = board_message_count * 0.1
#finall_topic_score = topic_score
finall_project_score = finall_issue_score + finall_new_score + finall_file_score + finall_code_submit_score + topic_score
format("%.2f",finall_project_score)
end
#获取指定作业的参与人员
#返回结果:张三、李四、王五
def homework_user_of_homework homework,is_teacher
homework_users = ""
homework.users.each do |user|
homework_users = homework_users + (is_teacher ? user.realname : user.name)
if user != homework.users.last
homework_users = homework_users + ""
end
end
return homework_users
end
end

View File

@ -54,4 +54,24 @@ module HomeworkAttachHelper
raise RuntimeError, 'unknow type, Please input you type into this helper.'
end
end
def user_projects_option
cond = Project.visible_condition(User.current) + " AND projects.project_type <> 1"
memberships = User.current.memberships.all(:conditions => cond)
projects = memberships.map(&:project)
not_have_project = []
not_have_project << "<<NULL>>"
not_have_project << 0
type = []
type << not_have_project
projects.each do |project|
if project != nil
option = []
option << project.name
option << project.id
type << option
end
end
type
end
end

View File

@ -70,7 +70,7 @@ module JournalsHelper
content << textilizable(journal, :notes)
css_classes = "wiki"
css_classes << " editable" if editable
content_tag('div', content.html_safe, :id => "journal-#{journal.id}-notes", :class => css_classes)
content_tag('div', content.html_safe, :id => "journal-#{journal.id}-notes", :class => css_classes ,:style => "width:580px")
end
def link_to_in_place_notes_editor(text, field_id, url, options={})

View File

@ -33,6 +33,24 @@ module MembersHelper
s + content_tag('div', content_tag('ul', links), :class => 'pagination_new')
end
# add by nwb
# 课程可添加的成员列表
def render_principals_for_new_course_members(course)
scope = Principal.active.sorted.not_member_of_course(course).like(params[:q])
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
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_course_memberships_path(course, parameters.merge(:q => params[:q], :format => 'js')), :remote => true
}
s + content_tag('div', content_tag('ul', links), :class => 'pagination_new')
end
# 当前申请加入的成员名单
def render_principals_for_applied_members(project)
scope = Principal.active.sorted.applied_members(project).like(params[:q])

View File

@ -16,6 +16,8 @@ module TagsHelper
@obj = Attachment.find_by_id(obj_id)
when '7'
@obj= Contest.find_by_id(obj_id)
when '9'
@obj= Course.find_by_id(obj_id)
else
raise Exception, '[TagsHelper] ===> tag type unknow.'
end
@ -46,6 +48,8 @@ module TagsHelper
if user.id == obj_id
@result = true
end
when '9'
@result = is_course_manager?(user.id,obj_id)
end
return @result
end

View File

@ -71,7 +71,10 @@ module WatchersHelper
# Somebody may use option params
def join_in_course(course, user, options=[])
return '' unless user && user.logged?
joined = user.member_of?(course)
# modify by nwb
# 主讲教师不允许退出课程
return '' if user.id == course.tea_id
joined = user.member_of_course?(course)
text = joined ? l(:label_exit_course) : l(:label_join_course)
url_t = join_path(:object_id => course.id)
url_f = try_join_path(:object_id => course.id)
@ -83,9 +86,14 @@ module WatchersHelper
end
end
# 用户是否允许加入课程判断
# add by nwb
def join_in_course_for_list(course, user, options=[])
return '' unless user && user.logged?
joined = user.member_of?(course)
# modify by nwb
# 主讲教师不允许退出课程
return '' if user.id == course.tea_id
joined = user.member_of_course?(course)
text = joined ? l(:label_exit_course) : l(:label_join_course)
url_t = join_path(:object_id => course.id)
url_f = try_join_path(:object_id => course.id)

View File

@ -22,6 +22,33 @@ module WelcomeHelper
include CoursesHelper
include ProjectsHelper
def get_timestamp(obj)
if obj.respond_to? :updated_on
:updated_on
elsif obj.respond_to? :updated_at
:updated_at
elsif obj.respond_to? :created_on
:created_on
elsif obj.respond_to? :created_at
:created_at
else
Time.now.to_i.to_s.to_sym
end
end
def cache_key_for_project(obj)
timestamp = get_timestamp(obj)
"welcome_index_project_ul_#{obj.class}_li_#{obj.id}_#{obj.__send__ timestamp}"
end
def cache_key_for_event(obj)
timestamp = get_timestamp(obj)
"welcome_index_event_ul_#{obj.class}_li_#{obj.id}_#{obj.__send__ timestamp}"
end
def cache_key_for_topic(obj)
timestamp = get_timestamp(obj)
"welcome_index_topic_ul_#{obj.class}_li_#{obj.id}_#{obj.__send__ timestamp}"
end
def welcome_join_in_course(project, user)
if(user.logged? &&
!(course_endTime_timeout? project) &&
@ -131,10 +158,11 @@ module WelcomeHelper
end
def find_miracle_project(sum, max_rate)
max = sum*(max_rate.to_f/10)
c1 = find_new_project(sum).to_a.dup
c2 = find_all_hot_project(sum).to_a.dup
(c2.take(sum-max)+c1.take(max)).take(sum)
#max = sum*(max_rate.to_f/10)
#c1 = find_new_project(sum).to_a.dup
#c2 = find_all_hot_project(sum).to_a.dup
#(c2.take(sum-max)+c1.take(max)).take(sum)
find_all_hot_project(sum).to_a.dup
end
def find_new_course limit=15

View File

@ -21,6 +21,7 @@ require "fileutils"
class Attachment < ActiveRecord::Base
belongs_to :container, :polymorphic => true
belongs_to :project, foreign_key: 'container_id', conditions: "attachments.container_type = 'Project'"
belongs_to :course, foreign_key: 'container_id', conditions: "attachments.container_type = 'Course'"
belongs_to :softapplication, foreign_key: 'container_id', conditions: "attachments.container_type = 'Softapplication'"
belongs_to :author, :class_name => "User", :foreign_key => "author_id"
belongs_to :attachmentstype, :foreign_key => "attachtype",:primary_key => "id"
@ -30,11 +31,19 @@ class Attachment < ActiveRecord::Base
validates_length_of :disk_filename, :maximum => 255
validates_length_of :description, :maximum => 255
validate :validate_max_file_size
acts_as_taggable
acts_as_taggable
acts_as_event :title => :filename,
:url => Proc.new {|o| {:controller => 'attachments', :action => 'download', :id => o.id, :filename => o.filename}}
#课程资源文件
acts_as_activity_provider :type => 'course_files',
:permission => :view_files,
:author_key => :author_id,
:find_options => {:select => "#{Attachment.table_name}.*",
:joins => "LEFT JOIN #{Course.table_name} ON ( #{Attachment.table_name}.container_type='Course' AND #{Attachment.table_name}.container_id = #{Course.table_name}.id )"}
acts_as_activity_provider :type => 'files',
:permission => :view_files,
:author_key => :author_id,
@ -186,6 +195,10 @@ class Attachment < ActiveRecord::Base
container.try(:project)
end
def course
container
end
def visible?(user=User.current)
if container_id
container && container.attachments_visible?(user)
@ -370,7 +383,7 @@ class Attachment < ActiveRecord::Base
type = self.container_type
types = %w|Document News Version Project Issue Message WikiPage|
if types.include?(type)
UserScore.project(:push_file, User.current, { attachment_id: self.id })
UserScore.project(:push_file, User.current,self, { attachment_id: self.id })
end
end
end

View File

@ -22,11 +22,11 @@ class Bid < ActiveRecord::Base
belongs_to :course
has_many :biding_projects, :dependent => :destroy
has_many :projects, :through => :biding_projects
has_many :projects_member, :class_name => 'User', :through => :projects
has_many :courses_member, :class_name => 'User', :through => :courses
has_many :journals_for_messages, :as => :jour, :dependent => :destroy
has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy
has_many :homework_for_courses, :dependent => :destroy
has_many :courses, :through => :homework_for_courses, :source => :project
has_many :courses, :through => :homework_for_courses, :source => :course
has_many :homeworks, :class_name => 'HomeworkAttach', :dependent => :destroy
has_many :join_in_contests, :dependent => :destroy
has_many :praise_tread, as: :praise_tread_object, dependent: :destroy

View File

@ -18,6 +18,7 @@
class Board < ActiveRecord::Base
include Redmine::SafeAttributes
belongs_to :project
belongs_to :course
has_many :topics, :class_name => 'Message', :conditions => "#{Message.table_name}.parent_id IS NULL", :order => "#{Message.table_name}.created_on DESC"
has_many :messages, :dependent => :destroy, :order => "#{Message.table_name}.created_on DESC"
belongs_to :last_message, :class_name => 'Message', :foreign_key => :last_message_id

View File

@ -19,7 +19,7 @@ class Changeset < ActiveRecord::Base
belongs_to :repository
belongs_to :user
after_save :be_user_score # user_score
#after_save :be_user_score # user_score
has_many :filechanges, :class_name => 'Change', :dependent => :delete_all
# fq
@ -63,7 +63,7 @@ class Changeset < ActiveRecord::Base
includes(:repository => :project).where(Project.allowed_to_condition(args.shift || User.current, :view_changesets, *args))
}
after_create :scan_for_issues
after_create :scan_for_issues,:be_user_score # user_score
before_create :before_create_cs
# fq
@ -98,8 +98,10 @@ class Changeset < ActiveRecord::Base
end
def project
unless repository.nil?
repository.project
end
end
def author
user || committer.to_s.split('<').first
@ -300,9 +302,9 @@ class Changeset < ActiveRecord::Base
# update user score
def be_user_score
if self.new_record?
UserScore.project(:push_code, self.user, { changeset_id: self.id })
end
UserScore.project(:push_code, self.user,self, { changeset_id: self.id })
#更新用户等级
UserLevels.update_user_level(self.user)
end
end

View File

@ -1,13 +1,45 @@
class Course < ActiveRecord::Base
include Redmine::SafeAttributes
attr_accessible :code, :extra, :name, :state, :tea_id, :time , :location, :state, :term, :password
belongs_to :project, :class_name => 'Project', :foreign_key => :extra, primary_key: :identifier
STATUS_ACTIVE = 1
STATUS_CLOSED = 5
STATUS_ARCHIVED = 9
attr_accessible :code, :extra, :name, :state, :tea_id, :time , :location, :state, :term, :password,:is_public,:description,:class_period
belongs_to :project, :class_name => 'Course', :foreign_key => :extra, primary_key: :identifier
belongs_to :teacher, :class_name => 'User', :foreign_key => :tea_id # 定义一个方法teacher该方法通过tea_id来调用User表
belongs_to :school, :class_name => 'School', :foreign_key => :school_id #定义一个方法school该方法通过school_id来调用School表
has_many :bid
validates_presence_of :password, :term
validates_format_of :class_period, :message => "class period can only digital!", :with =>/^[1-9]\d*$/
has_many :members, :include => [:principal, :roles], :conditions => "#{Principal.table_name}.type='User' AND #{Principal.table_name}.status=#{Principal::STATUS_ACTIVE}"
has_many :memberships, :class_name => 'Member'
has_many :member_principals, :class_name => 'Member',
:include => :principal,
:conditions => "#{Principal.table_name}.type='Group' OR (#{Principal.table_name}.type='User' AND #{Principal.table_name}.status=#{Principal::STATUS_ACTIVE})"
has_many :principals, :through => :member_principals, :source => :principal
has_many :users, :through => :members
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 :course_infos, :class_name => 'CourseInfos',:dependent => :destroy
has_many :enabled_modules, :dependent => :delete_all
has_many :boards, :dependent => :destroy, :order => "position ASC"
#has_many :course_journals_for_messages, :class_name => 'CourseJournalsForMessage', :as => :jour, :dependent => :destroy
has_many :news, :dependent => :destroy, :include => :author
acts_as_taggable
acts_as_nested_set :order => 'name', :dependent => :destroy
acts_as_attachable :view_permission => :view_files,
:delete_permission => :manage_files
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]+$/
after_save :create_board_sync
before_destroy :delete_all_members
safe_attributes 'extra',
'time',
'name',
@ -17,7 +49,120 @@ class Course < ActiveRecord::Base
'tea_id',
'password',
'term',
'password'
'is_public',
'description',
'class_period'
acts_as_customizable
scope :all_course
scope :active, lambda { where(:status => STATUS_ACTIVE) }
scope :status, lambda {|arg| where(arg.blank? ? nil : {:status => arg.to_i}) }
scope :all_public, lambda { where(:is_public => true) }
scope :visible, lambda {|*args| where(Course.visible_condition(args.shift || User.current, *args)) }
scope :allowed_to, lambda {|*args|
user = User.current
permission = nil
if args.first.is_a?(Symbol)
permission = args.shift
else
user = args.shift
permission = args.shift
end
where(Course.allowed_to_condition(user, permission, *args))
}
scope :like, lambda {|arg|
if arg.blank?
where(nil)
else
pattern = "%#{arg.to_s.strip.downcase}%"
where("LOWER(extra) LIKE :p OR LOWER(name) LIKE :p ", :p => pattern)
end
}
def visible?(user=User.current)
user.allowed_to?(:view_course, self)
end
def parent_id_changed?
false
end
# 课程的短描述信息
def short_description(length = 255)
description.gsub(/^(.{#{length}}[^\n\r]*).*$/m, '\1...').strip if description
end
def extra_frozen?
errors[:extra].blank? && !(new_record? || extra.blank?)
end
def archived?
self.status == STATUS_ARCHIVED
end
def self.visible_condition(user, options={})
allowed_to_condition(user, :view_course, options)
end
# 获取课程的资源类型列表
def attachmenttypes
@attachmenttypes = Attachmentstype.find(:all, :conditions => ["#{Attachmentstype.table_name}.typeId= ?",self.attachmenttype ])
end
# 获取资源后缀名列表
def contenttypes
attachmenttypes
if @attachmenttypes.length >0
@attachmenttypes.last().suffixArr
end
end
def active?
self.status == STATUS_ACTIVE
end
#课程权限判断
def allows_to?(action)
if archived?
# No action allowed on archived projects
return false
end
unless active? || Redmine::AccessControl.read_action?(action)
# No write action allowed on closed projects
return false
end
# No action allowed on disabled modules
if action.is_a? Hash
allowed_actions.include? "#{action[:controller]}/#{action[:action]}"
else
allowed_permissions.include? action
end
end
# 课程允许的权限集合
def allowed_permissions
@allowed_permissions ||= begin
module_names = enabled_modules.all(:select => :name).collect {|m| m.name}
Redmine::AccessControl.modules_permissions(module_names).collect {|p| p.name}
end
end
# 课程允许的动作集合
def allowed_actions
@actions_allowed ||= allowed_permissions.inject([]) { |actions, permission| actions += Redmine::AccessControl.allowed_actions(permission) }.flatten
end
# 返回用户组可以访问的课程
def users_by_role
members.includes(:user, :roles).all.inject({}) do |h, m|
m.roles.each do |r|
h[r] ||= []
h[r] << m.user
end
h
end
end
#自定义验证
def validate
@ -26,6 +171,42 @@ class Course < ActiveRecord::Base
end
end
# 创建课程讨论区
def create_board_sync
@board = self.boards.build
self.name=" #{l(:label_borad_course) }"
@board.name = self.name
@board.description = self.name.to_s
@board.project_id = -1
if @board.save
logger.debug "[Course Model] ===> #{@board.to_json}"
else
logger.error "[Course Model] ===> Auto create board when course saved, because #{@board.full_messages}"
end
end
# 新增课程留言
# add by nwb
def self.add_new_jour(user, notes, id, options={})
course = Course.find(id)
if options.count == 0
pjfm = course.journals_for_messages.build(:user_id => user.id, :notes => notes, :reply_id => 0)
else
pjfm = course.journals_for_messages.build(options)
end
pjfm.save
pjfm
end
# 删除课程所有成员
def delete_all_members
if self.members && self.members.count > 0
me, mr = Member.table_name, MemberRole.table_name
connection.delete("DELETE FROM #{mr} WHERE #{mr}.member_id IN (SELECT #{me}.id FROM #{me} WHERE #{me}.course_id = #{id})")
Member.delete_all(['course_id = ?', id])
end
end
def get_endup_time
begin
end_time = Time.parse(self.endup_time)
@ -47,4 +228,50 @@ class Course < ActiveRecord::Base
return time
end
end
def self.allowed_to_condition(user, permission, options={})
perm = Redmine::AccessControl.permission(permission)
base_statement = (perm && perm.read? ? "#{Course.table_name}.status <> #{Course::STATUS_ARCHIVED}" : "#{Course.table_name}.status = #{Course::STATUS_ACTIVE}")
if perm && perm.course_module
base_statement << " AND #{Course.table_name}.id IN (SELECT em.course_id FROM #{EnabledModule.table_name} em WHERE em.name='#{perm.course_module}')"
end
if options[:course]
course_statement = "#{Course.table_name}.id = #{options[:course].id}"
course_statement << " OR (#{Course.table_name}.lft > #{options[:course].lft} AND #{Course.table_name}.rgt < #{options[:course].rgt})" if options[:with_subcourses]
base_statement = "(#{course_statement}) AND (#{base_statement})"
end
if user.admin?
base_statement
else
statement_by_role = {}
unless options[:member]
role = user.logged? ? Role.non_member : Role.anonymous
if role.allowed_to?(permission)
statement_by_role[role] = "#{Course.table_name}.is_public = #{connection.quoted_true}"
end
end
if user.logged?
user.courses_by_role.each do |role, courses|
if role.allowed_to?(permission) && courses.any?
statement_by_role[role] = "#{Course.table_name}.id IN (#{courses.collect(&:id).join(',')})"
end
end
end
if statement_by_role.empty?
"1=0"
else
if block_given?
statement_by_role.each do |role, statement|
if s = yield(role, user)
statement_by_role[role] = "(#{statement} AND (#{s}))"
end
end
end
"((#{base_statement}) AND (#{statement_by_role.values.join(' OR ')}))"
end
end
end
end

View File

@ -0,0 +1,5 @@
class CourseInfos < ActiveRecord::Base
attr_accessible :user_id, :course_id
belongs_to :user
belongs_to :course
end

View File

@ -0,0 +1,3 @@
class CourseStatus < ActiveRecord::Base
attr_accessible :changesets_count, :course_ac_para, :course_id, :grade, :watchers_count
end

View File

@ -21,7 +21,7 @@ class Document < ActiveRecord::Base
belongs_to :user
belongs_to :category, :class_name => "DocumentCategory", :foreign_key => "category_id"
before_save :be_user_score # user_score
after_create :be_user_score # user_score
acts_as_attachable :delete_permission => :delete_documents
@ -62,8 +62,6 @@ class Document < ActiveRecord::Base
# update user score
def be_user_score
if self.new_record?
UserScore.project(:push_document, self.user, { document_id: self.id })
end
UserScore.project(:push_document, self.user,self,{ document_id: self.id })
end
end

View File

@ -9,6 +9,7 @@ class HomeworkAttach < ActiveRecord::Base
has_many :homework_users, :dependent => :destroy
has_many :users, :through => :homework_users
seems_rateable :allow_update => true, :dimensions => :quality
belongs_to :project
safe_attributes "bid_id",
"user_id"
@ -30,7 +31,7 @@ class HomeworkAttach < ActiveRecord::Base
result
end
def project
def project_for_homework
work = HomeworkForCourse.find_by_bid_id(self.bid_id)
if work
work.project

View File

@ -1,8 +1,8 @@
class HomeworkForCourse < ActiveRecord::Base
attr_accessible :bid_id, :project_id
attr_accessible :bid_id, :course_id
belongs_to :bid
belongs_to :project
belongs_to :course
end

View File

@ -76,8 +76,8 @@ class Issue < ActiveRecord::Base
attr_reader :current_journal
# fq
after_create :act_as_activity
before_save :be_user_score
after_create :act_as_activity,:be_user_score_new_issue
after_update :be_user_score
# after_create :be_user_score
# end
@ -1489,14 +1489,19 @@ class Issue < ActiveRecord::Base
# update user score
def be_user_score
if self.new_record?
UserScore.project(:post_issue, User.current, { issue_id: self.id })
elsif self.done_ratio_changed?
UserScore.project(:update_issue_ratio, User.current, { issue_id: self.id })
#缺陷完成度更新
if self.done_ratio_changed?
UserScore.project(:update_issue_ratio, User.current,self,{ issue_id: self.id })
end
#缺陷状态更改
elsif self.status_id_changed?
if self.status_id_changed?
#协同得分
UserScore.joint(:change_issue_status, User.current,nil, {issue_id: self.id})
UserScore.joint(:change_issue_status, User.current,nil,self, {issue_id: self.id})
end
end
#发布缺陷
def be_user_score_new_issue
UserScore.project(:post_issue, User.current,self, { issue_id: self.id })
end
end

View File

@ -45,10 +45,10 @@ class Journal < ActiveRecord::Base
before_create :split_private_notes
# fq
after_create :act_as_activity
after_create :act_as_activity,:be_user_score
# end
before_save :be_user_score
#before_save :be_user_score
#before_destroy :down_user_score
scope :visible, lambda {|*args|
@ -158,9 +158,9 @@ class Journal < ActiveRecord::Base
# 更新用户分数 -by zjc
def be_user_score
#新建了缺陷留言且留言不为空,不为空白
if self.new_record? && !self.notes.nil? && self.notes.gsub(' ','') != ''
if !self.notes.nil? && self.notes.gsub(' ','') != ''
#协同得分加分
UserScore.joint(:post_issue, User.current,self.issue.author, { message_id: self.id })
UserScore.joint(:post_issue_message, User.current,self.issue.author,self, { message_id: self.id })
end
end
# 减少用户分数 -by zjc
@ -168,7 +168,7 @@ class Journal < ActiveRecord::Base
#删除有效缺陷留言
if !self.notes.nil? && self.notes.gsub(' ','') != ''
#协同得分减分
UserScore.joint(:delete_issue, User.current,self.issue.author, { message_id: self.id })
UserScore.joint(:delete_issue_message, User.current,self.issue.author, { message_id: self.id })
end
end
end

View File

@ -18,6 +18,9 @@ class JournalsForMessage < ActiveRecord::Base
belongs_to :project,
:foreign_key => 'jour_id',
:conditions => "#{self.table_name}.jour_type = 'Project' "
belongs_to :course,
:foreign_key => 'jour_id',
:conditions => "#{self.table_name}.jour_type = 'Course' "
belongs_to :jour, :polymorphic => true
belongs_to :user
@ -30,19 +33,29 @@ class JournalsForMessage < ActiveRecord::Base
:description => Proc.new{|o| o.notes },
:type => Proc.new {|o| o.jour_type },
:url => Proc.new {|o|
(o.jour.kind_of? Project) ? {:controller => 'projects', :action => 'feedback', :id => o.jour, :r => o.id, :anchor => "word_li_#{o.id}"} : {}
}#{:controller => 'documents', :action => 'show', :id => o.id}}
if o.jour.kind_of? Project
{:controller => 'projects', :action => 'feedback', :id => o.jour, :r => o.id, :anchor => "word_li_#{o.id}"}
elsif o.jour.kind_of? Course
{:controller => 'courses', :action => 'feedback', :id => o.jour, :r => o.id, :anchor => "word_li_#{o.id}"}
end
}
acts_as_activity_provider :author_key => :user_id,
:timestamp => "#{self.table_name}.updated_on",
:find_options => {:include => :project }
acts_as_activity_provider :type => 'course_journals_for_messages',
:author_key => :user_id,
:timestamp => "#{self.table_name}.updated_on",
:find_options => {:include => :course }
has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy
validates :notes, presence: true
after_create :act_as_activity #huang
after_create :reset_counters!
after_create :reset_counters!,:be_user_score
after_destroy :reset_counters!
before_save :be_user_score
#before_save :be_user_score
#before_destroy :down_user_score
# default_scope { where('m_parent_id IS NULL') }
@ -89,6 +102,8 @@ class JournalsForMessage < ActiveRecord::Base
end
elsif self.jour_type == 'Project'
self.acts << Activity.new(:user_id => self.reply_id)
elsif self.jour_type == 'Course'
self.acts << Activity.new(:user_id => self.reply_id)
else
end
end
@ -105,9 +120,9 @@ class JournalsForMessage < ActiveRecord::Base
# 更新用户分数 -by zjc
def be_user_score
#新建了留言回复
if self.new_record? && self.reply_id != 0
if self.reply_id != 0
#协同得分加分
UserScore.joint(:reply_message, User.current,User.find(self.reply_id), { journals_for_messages_id: self.id })
UserScore.joint(:reply_message, User.current,User.find(self.reply_id),self, { journals_for_messages_id: self.id })
end
end
# 更新用户分数 -by zjc

View File

@ -75,6 +75,11 @@ class Mailer < ActionMailer::Base
return -1
end
mail :to => journals_for_message.jour.author.mail, :subject => @title
elsif journals_for_message.jour.class.to_s.to_sym == :Contest
if !journals_for_message.jour.author.notify_about? journals_for_message
return -1
end
mail :to => journals_for_message.jour.author.mail, :subject => @title
else
mail :to => @mail.mail, :subject => @title
end

View File

@ -22,9 +22,10 @@ class Member < ActiveRecord::Base
has_many :roles, :through => :member_roles
belongs_to :project
belongs_to :course
validates_presence_of :principal, :project
validates_uniqueness_of :user_id, :scope => :project_id
validates_presence_of :principal
validates_uniqueness_of :user_id, :scope => [:project_id,:course_id]
validate :validate_role
before_destroy :set_issue_category_nil
@ -85,7 +86,13 @@ class Member < ActiveRecord::Base
def set_issue_category_nil
if user
# remove category based auto assignments for this member
#modify by nwb
if project
IssueCategory.update_all "assigned_to_id = NULL", ["project_id = ? AND assigned_to_id = ?", project.id, user.id]
elsif course
#IssueCategory.update_all "assigned_to_id = NULL", ["course_id = ? AND assigned_to_id = ?", course.id, user.id]
end
end
end

View File

@ -54,6 +54,7 @@ class MemberRole < ActiveRecord::Base
end
def add_role_to_subprojects
if member.project
member.project.children.each do |subproject|
if subproject.inherit_members?
child_member = Member.find_or_new(subproject.id, member.user_id)
@ -62,6 +63,7 @@ class MemberRole < ActiveRecord::Base
end
end
end
end
def remove_inherited_roles
MemberRole.where(:inherited_from => id).all.group_by(&:member).each do |member, member_roles|

View File

@ -12,6 +12,7 @@ class Memo < ActiveRecord::Base
acts_as_tree :counter_cache => :replies_count, :order => "#{Memo.table_name}.created_at ASC"
acts_as_attachable
has_many :user_score_details, :class_name => 'UserScoreDetails',:as => :score_changeable_obj
belongs_to :last_reply, :class_name => 'Memo', :foreign_key => 'last_reply_id'
# acts_as_searchable :column => ['subject', 'content'],
# #:include => { :forum => :p}
@ -40,13 +41,13 @@ class Memo < ActiveRecord::Base
"parent_id",
"replies_count"
after_create :add_author_as_watcher, :reset_counters!
after_create :add_author_as_watcher, :reset_counters!,:be_user_score
# after_update :update_memos_forum
after_destroy :reset_counters!
# after_create :send_notification
# after_save :plusParentAndForum
# after_destroy :minusParentAndForum
before_save :be_user_score
#before_save :be_user_score
# scope :visible, lambda { |*args|
# includes(:forum => ).where()
# }
@ -145,11 +146,11 @@ class Memo < ActiveRecord::Base
#更新用户分数 -by zjc
def be_user_score
#新建memo且无parent的为发帖
if self.new_record? && self.parent_id.nil?
UserScore.joint(:post_message, User.current,nil, { memo_id: self.id })
if self.parent_id.nil?
UserScore.joint(:post_message, User.current,nil,self ,{ memo_id: self.id })
#新建memo且有parent的为回帖
elsif self.new_record? && !self.parent_id.nil?
UserScore.joint(:reply_posting, User.current,self.parent.author, { memo_id: self.id })
elsif !self.parent_id.nil?
UserScore.joint(:reply_posting, User.current,self.parent.author,self, { memo_id: self.id })
end
end

View File

@ -31,6 +31,10 @@ class Message < ActiveRecord::Base
:include => {:board => :project},
:project_key => "#{Board.table_name}.project_id",
:date_column => "#{table_name}.created_on"
acts_as_searchable :columns => ['subject', 'content'],
:include => {:board => :course},
:course_key => "#{Board.table_name}.course_id",
:date_column => "#{table_name}.created_at"
acts_as_event :title => Proc.new {|o| "#{o.board.name}: #{o.subject}"},
:description => :content,
:datetime => :updated_on,
@ -42,6 +46,9 @@ class Message < ActiveRecord::Base
acts_as_activity_provider :find_options => {:include => [{:board => :project}, :author]},
:author_key => :author_id
acts_as_activity_provider :find_options => {:include => [{:board => :course}, :author]},
:type => 'course_messages',
:author_key => :author_id
acts_as_watchable
validates_presence_of :board, :subject, :content
@ -53,8 +60,8 @@ class Message < ActiveRecord::Base
after_destroy :reset_counters!
# fq
after_create :act_as_activity
before_save :be_user_score
after_create :act_as_activity,:be_user_score
#before_save :be_user_score
#before_destroy :down_user_score
# end
@ -62,6 +69,11 @@ class Message < ActiveRecord::Base
includes(:board => :project).where(Project.allowed_to_condition(args.shift || User.current, :view_messages, *args))
}
scope :course_visible, lambda {|*args|
includes(:board => :course).where(Course.allowed_to_condition(args.shift || User.current, :view_course_messages, *args))
}
safe_attributes 'subject', 'content'
safe_attributes 'locked', 'sticky', 'board_id',
:if => lambda {|message, user|
@ -69,7 +81,11 @@ class Message < ActiveRecord::Base
}
def visible?(user=User.current)
if project
!user.nil? && user.allowed_to?(:view_messages, project)
elsif course
!user.nil? && user.allowed_to?(:view_messages, course)
end
end
def cannot_reply_to_locked_topic
@ -104,6 +120,10 @@ class Message < ActiveRecord::Base
board.project
end
def course
board.course
end
def editable_by?(usr)
usr && usr.logged? && (usr.allowed_to?(:edit_messages, project) || (self.author == usr && usr.allowed_to?(:edit_own_messages, project)))
end
@ -127,11 +147,11 @@ class Message < ActiveRecord::Base
#更新用户分数 -by zjc
def be_user_score
#新建message且无parent的为发帖
if self.new_record? && self.parent_id.nil?
UserScore.joint(:post_message, User.current,nil, { message_id: self.id })
if self.parent_id.nil?
UserScore.joint(:post_message, User.current,nil,self, { message_id: self.id })
#新建message且有parent的为回帖
elsif self.new_record? && !self.parent_id.nil?
UserScore.joint(:reply_posting, User.current,self.parent.author, { message_id: self.id })
elsif !self.parent_id.nil?
UserScore.joint(:reply_posting, User.current,self.parent.author,self, { message_id: self.id })
end
end
#减少用户分数

View File

@ -18,6 +18,8 @@
class News < ActiveRecord::Base
include Redmine::SafeAttributes
belongs_to :project
#added by nwb
belongs_to :course
belongs_to :author, :class_name => 'User', :foreign_key => 'author_id'
has_many :comments, :as => :commented, :dependent => :delete_all, :order => "created_on"
# fq
@ -33,6 +35,11 @@ class News < ActiveRecord::Base
acts_as_event :url => Proc.new {|o| {:controller => 'news', :action => 'show', :id => o.id}}
acts_as_activity_provider :find_options => {:include => [:project, :author]},
:author_key => :author_id
#added by nwb
#课程新闻独立于项目
acts_as_activity_provider :type => 'course_news',
:find_options => {:include => [:course, :author]},
:author_key => :author_id
acts_as_watchable
after_create :add_author_as_watcher
@ -44,6 +51,9 @@ class News < ActiveRecord::Base
includes(:project).where(Project.allowed_to_condition(args.shift || User.current, :view_news, *args))
}
scope :course_visible, lambda {|*args|
includes(:course).where(Course.allowed_to_condition(args.shift || User.current, :view_course_news, *args))
}
safe_attributes 'title', 'summary', 'description'
def visible?(user=User.current)

View File

@ -2,9 +2,9 @@ class PraiseTread < ActiveRecord::Base
attr_accessible :user_id,:praise_tread_object_id,:praise_tread_object_type,:praise_or_tread
belongs_to :user
belongs_to :praise_tread_object, polymorphic: true
before_save :be_user_score
after_create :be_user_score
def find_object_by_type_and_id(type,id)
def self.find_object_by_type_and_id(type,id)
@obj = nil
case type
when 'User'
@ -25,18 +25,30 @@ class PraiseTread < ActiveRecord::Base
return @obj
end
# 获取裁定对象为Message时Message所属的项目或课程
def project
project = nil
if self.praise_tread_object_type == 'Message'
obj = PraiseTread.find_object_by_type_and_id(self.praise_tread_object_type,praise_tread_object_id)
project = obj.project
end
project
end
#更新用户分数 - by zjc
def be_user_score
#踩贴吧或讨论区帖子
if self.new_record? && self.praise_or_tread == 0 && (self.praise_tread_object_type == 'Memo' || self.praise_tread_object_type == 'Message')
obj = find_object_by_type_and_id(self.praise_tread_object_type,praise_tread_object_id)
if self.praise_or_tread == 0 && (self.praise_tread_object_type == 'Memo' || self.praise_tread_object_type == 'Message')
obj = PraiseTread.find_object_by_type_and_id(self.praise_tread_object_type,praise_tread_object_id)
target_user = obj.author
UserScore.skill(:treaded_by_user, User.current,target_user, { praise_tread_id: self.id })
UserScore.skill(:treaded_by_user, User.current,target_user,self, { praise_tread_id: self.id })
#顶贴吧或讨论区帖子
elsif self.new_record? && self.praise_or_tread == 1 && (self.praise_tread_object_id == 'Memo' || self.praise_tread_object_type == 'Message')
obj = find_object_by_type_and_id(self.praise_tread_object_type,praise_tread_object_id)
elsif self.praise_or_tread == 1 && (self.praise_tread_object_type == 'Memo' || self.praise_tread_object_type == 'Message')
obj = PraiseTread.find_object_by_type_and_id(self.praise_tread_object_type,praise_tread_object_id)
target_user = obj.author
UserScore.skill(:praised_by_user, User.current,target_user,{ praise_tread_id: self.id })
UserScore.skill(:praised_by_user, User.current,target_user,self,{ praise_tread_id: self.id })
#更新用户等级
UserLevels.update_user_level(target_user)
end
end
end

View File

@ -26,7 +26,10 @@ class Principal < ActiveRecord::Base
has_many :members, :foreign_key => 'user_id', :dependent => :destroy
has_many :memberships, :class_name => 'Member', :foreign_key => 'user_id', :include => [ :project, :roles ], :conditions => "#{Project.table_name}.status<>#{Project::STATUS_ARCHIVED}", :order => "#{Project.table_name}.name"
has_many :coursememberships, :class_name => 'Member', :foreign_key => 'user_id', :include => [ :course, :roles ], :conditions => "#{Course.table_name}.status<>#{Course::STATUS_ARCHIVED}", :order => "#{Course.table_name}.name"
has_many :projects, :through => :memberships
#add by nwb
has_many :courses, :through => :coursememberships
has_many :issue_categories, :foreign_key => 'assigned_to_id', :dependent => :nullify
# Groups and active users
@ -70,6 +73,17 @@ class Principal < ActiveRecord::Base
where("#{Principal.table_name}.id NOT IN (SELECT DISTINCT user_id FROM #{Member.table_name} WHERE project_id IN (?))", ids)
end
}
scope :not_member_of_course, lambda {|courses|
courses = [courses] unless courses.is_a?(Array)
if courses.empty?
where("1=0")
else
ids = courses.map(&:id)
where("#{Principal.table_name}.id NOT IN (SELECT DISTINCT user_id FROM #{Member.table_name} WHERE course_id IN (?))", ids)
end
}
scope :sorted, lambda { order(*Principal.fields_for_order_statement)}
scope :applied_members, lambda {|project|

View File

@ -30,6 +30,7 @@ class Project < ActiveRecord::Base
# Specific overidden Activities
belongs_to :homework_attach
has_many :time_entry_activities
has_many :members, :include => [:principal, :roles], :conditions => "#{Principal.table_name}.type='User' AND #{Principal.table_name}.status=#{Principal::STATUS_ACTIVE}"
has_many :memberships, :class_name => 'Member'
@ -1129,17 +1130,13 @@ class Project < ActiveRecord::Base
# 创建项目后在项目下同步创建一个讨论区
def create_board_sync
@board = self.boards.build
if project_type == 1
self.name=" #{l(:label_borad_course) }"
else
self.name =" #{l(:label_borad_project) }"
end
@board.name = self.name
@board.description = self.name.to_s
if @board.save
logger.debug "[Project Model] ===> #{@board.to_json}"
logger.debug "[Course Model] ===> #{@board.to_json}"
else
logger.error "[Project Model] ===> Auto create board when project saved, because #{@board.full_messages}"
logger.error "[Course Model] ===> Auto create board when Course saved, because #{@board.full_messages}"
end
end

View File

@ -5,7 +5,7 @@ class ProjectInfo < ActiveRecord::Base
belongs_to :user
validates_presence_of :project_id, :user_id
validates_uniqueness_of :project_id, :scope => :user_id
after_save :update_user_level
def self.manager? (user_id, project)
for project_info in project.project_infos
if project_info.user_id == user_id
@ -14,4 +14,9 @@ class ProjectInfo < ActiveRecord::Base
end
return false
end
#更新用户等级
def update_user_level
UserLevels.update_user_level(self.user)
end
end

View File

@ -1,7 +1,8 @@
class StudentsForCourse < ActiveRecord::Base
attr_accessible :course_id, :student_id
belongs_to :course, :class_name => 'Project', :foreign_key => :course_id
belongs_to :course, :class_name => 'Course', :foreign_key => :course_id
belongs_to :student, :class_name => 'User', :foreign_key => :student_id
validates_presence_of :course_id, :student_id

View File

@ -101,7 +101,7 @@ class User < Principal
has_many :journal_replies, :dependent => :destroy
has_many :activities, :dependent => :destroy
has_many :students_for_courses
has_many :courses, :through => :students_for_courses, :source => :project
#has_many :courses, :through => :students_for_courses, :source => :project
has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy
has_many :file_commit, :class_name => 'Attachment', :foreign_key => 'author_id', :conditions => "container_type = 'Project' or container_type = 'Version'"
####
@ -343,6 +343,7 @@ class User < Principal
def reload(*args)
@name = nil
@projects_by_role = nil
@courses_by_role = nil
@membership_by_project_id = nil
base_reload(*args)
end
@ -658,6 +659,15 @@ class User < Principal
@membership_by_project_id[project_id]
end
def coursemembership(course)
course_id = course.is_a?(Course) ? course.id : course
@membership_by_course_id ||= Hash.new {|h, course_id|
h[course_id] = coursememberships.where(:course_id => course_id).first
}
@membership_by_course_id[course_id]
end
# Return user's roles for project
def roles_for_project(project)
roles = []
@ -679,11 +689,36 @@ class User < Principal
roles
end
# 用户课程权限判断
def roles_for_course(course)
roles = []
# No role on archived courses
return roles if course.nil? || course.archived?
if logged?
# Find course membership
membership = coursemembership(course)
if membership
roles = membership.roles
else
@role_non_member ||= Role.non_member
roles << @role_non_member
end
else
@role_anonymous ||= Role.anonymous
roles << @role_anonymous
end
roles
end
# Return true if the user is a member of project
def member_of?(project)
projects.to_a.include?(project)
end
def member_of_course?(course)
courses.to_a.include?(course)
end
# Returns a hash of user's projects grouped by roles
def projects_by_role
return @projects_by_role if @projects_by_role
@ -704,6 +739,25 @@ class User < Principal
@projects_by_role
end
# 课程的角色权限
def courses_by_role
return @courses_by_role if @courses_by_role
@courses_by_role = Hash.new([])
coursememberships.each do |membership|
if membership.course
membership.roles.each do |role|
@courses_by_role[role] = [] unless @courses_by_role.key?(role)
@courses_by_role[role] << membership.course
end
end
end
@courses_by_role.each do |role, courses|
courses.uniq!
end
@courses_by_role
end
# Returns true if user is arg or belongs to arg
def is_or_belongs_to?(arg)
if arg.is_a?(User)
@ -738,6 +792,19 @@ class User < Principal
role.allowed_to?(action) &&
(block_given? ? yield(role, self) : true)
}
#添加课程相关的权限判断
elsif context && context.is_a?(Course)
return false unless context.allows_to?(action)
# Admin users are authorized for anything else
return true if admin?
roles = roles_for_course(context)
return false unless roles
roles.any? {|role|
(context.is_public? || role.member?) &&
role.allowed_to?(action) &&
(block_given? ? yield(role, self) : true)
}
elsif context && context.is_a?(Array)
if context.empty?
false
@ -751,6 +818,9 @@ class User < Principal
# authorize if user has at least one role that has this permission
roles = memberships.collect {|m| m.roles}.flatten.uniq
if roles.count == 0
roles = coursememberships.collect {|m| m.roles}.flatten.uniq
end
roles << (self.logged? ? Role.non_member : Role.anonymous)
roles.any? {|role|
role.allowed_to?(action) &&
@ -885,63 +955,6 @@ class User < Principal
end
end
#获取user的等级 -by zjc
def get_level
if self.level.nil?
update_user_level
end
self.level.level
end
#更新用户等级 - by zjc
def update_user_level
user_level = UserLevels.new
user_level.user = self
#判断user的等级
pis = self.project_infos #ProjectInfo.find_all_by_user_id(self.id)
isManager = false;
pis.each do |pi|
#判断是否为项目管理员
if self.allowed_to?({:controller => "projects", :action => "edit"}, pi.project)
isManager = true;
end
end
has_effective_praise_count = false;
self.messages.each do |message|
if message.parent_id.nil?
ptcs = PraiseTreadCache.find_all_by_object_id(message.id)
ptcs.each do |ptc|
if ptc.object_type == 'Message' && ptc.praise_num.to_i > 5
has_effective_praise_count = true
end
end
end
end
if !has_effective_praise_count
self.memos do |memo|
if memo.parent_id.nil?
ptcs = PraiseTreadCache.find_all_by_object_id(memo.id)
ptcs.each do |ptc|
if ptc.object_type == 'Memo' && ptc.praise_num > 5
has_effective_praise_count = true
end
end
end
end
end
if isManager || self.changesets.count > 100
user_level.level = 3
elsif (self.changesets.count > 1 && self.changesets.count <= 100) || has_effective_praise_count
user_level.level = 2
else
user_level.level = 1
end
user_level.save
self.reload
end
protected
def validate_password_length

View File

@ -2,4 +2,67 @@
class UserLevels < ActiveRecord::Base
attr_accessible :user_id, :level
belongs_to :user
#获取user的等级 -by zjc
def self.get_level(user)
unless user.nil?
if user.level.nil?
UserLevels.update_user_level(user)
end
user.level.level
end
end
#更新用户的等级 -by zjc
def self.update_user_level(user)
unless user.nil?
user_level = user.level.nil? ? UserLevels.new : user.level
user_level.user = user
#判断user的等级
pis = user.project_infos #ProjectInfo.find_all_by_user_id(self.id)
isManager = false;
pis.each do |pi|
#判断是否为项目管理员
if user.allowed_to?({:controller => "projects", :action => "edit"}, pi.project)
isManager = true;
end
end
has_effective_praise_count = false;
user.messages.each do |message|
if message.parent_id.nil?
ptcs = PraiseTreadCache.find_all_by_object_id(message.id)
ptcs.each do |ptc|
if ptc.object_type == 'Message' && ptc.praise_num.to_i > 5
has_effective_praise_count = true
end
end
end
end
if !has_effective_praise_count
user.memos do |memo|
if memo.parent_id.nil?
ptcs = PraiseTreadCache.find_all_by_object_id(memo.id)
ptcs.each do |ptc|
if ptc.object_type == 'Memo' && ptc.praise_num > 5
has_effective_praise_count = true
end
end
end
end
end
if isManager || user.changesets.count > 100
user_level.level = 3
elsif (user.changesets.count > 1 && user.changesets.count <= 100) || has_effective_praise_count
user_level.level = 2
else
user_level.level = 1
end
user_level.save
user.reload
end
end
end

View File

@ -48,46 +48,79 @@ class UserScore < ActiveRecord::Base
# # => true #当前用户发帖计分操作成功
#
# Returns boolean. 返回积分保存结果
def self.joint(operate, current_user, target_user, options={})
def self.joint(operate, current_user, target_user,obj, options={})
current_user, target_user = get_users(current_user, target_user)
user_score = current_user.user_score_attr
user_grade = nil #项目个人得分
project = obj.project
unless project.nil?
user_grade = UserGrade.find_by_user_id_and_project_id(current_user.id, project.id)
if user_grade.nil?
user_grade = UserGrade.create(:user_id => current_user.id,:project_id => project.id)
end
end
case operate
when :post_message # current_user 发帖了 Add Message
user_score.collaboration = user_score.collaboration.to_i + 2
user_score.save
unless user_grade.nil?
user_grade.grade = user_grade.grade.to_i + 2
user_grade.save
end
create_score_changed_details({:current_user_id => current_user.id ,:score_type => "collaboration",:score_action => "post_message",:user_id => current_user.id,:old_score => user_score.collaboration - 2,:new_score => user_score.collaboration,:current_user_level => UserLevels.get_level(current_user),:score_changeable_obj_id=> obj.id,:score_changeable_obj_type => obj.class.to_s})
Rails.logger.info "[UserScore#joint] ===> User: #{current_user} posting a message. options => (#{options.to_s})"
when :delete_message # current_user 发帖了 Delete Message
user_score.collaboration = user_score.collaboration.to_i - 2
user_score.save
Rails.logger.info "[UserScore#joint] ===> User: #{current_user} deleting a message. options => (#{options.to_s})"
when :post_issue # current_user 对 target_user 的缺陷留言了 Add Journal
#when :delete_message # current_user 删帖了 Delete Message
# user_score.collaboration = user_score.collaboration.to_i - 2
# user_score.save
# Rails.logger.info "[UserScore#joint] ===> User: #{current_user} deleting a message. options => (#{options.to_s})"
when :post_issue_message # current_user 对 target_user 的缺陷留言了 Add Journal
user_score.collaboration = user_score.collaboration.to_i + 1
user_score.save
unless user_grade.nil?
user_grade.grade = user_grade.grade.to_i + 1
user_grade.save
end
create_score_changed_details({:current_user_id => current_user.id ,:target_user_id =>target_user.id, :score_type => "collaboration",:score_action => "post_issue_message",:user_id => current_user.id,:old_score => user_score.collaboration - 1,:new_score => user_score.collaboration,:current_user_level => UserLevels.get_level(current_user),:target_user_level => UserLevels.get_level(target_user),:score_changeable_obj_id=> obj.id,:score_changeable_obj_type => obj.class.to_s})
Rails.logger.info "[UserScore#joint] ===> User: #{current_user} posting a issue. options => (#{options.to_s})"
when :delete_issue # current_user 删除了 对 target_user 的缺陷留言了 Delete Journal
user_score.collaboration = user_score.collaboration.to_i - 1
user_score.save
Rails.logger.info "[UserScore#joint] ===> User: #{current_user} deleting a issue. options => (#{options.to_s})"
#when :delete_issue_message # current_user 删除了 对 target_user 的缺陷留言了 Delete Journal
# user_score.collaboration = user_score.collaboration.to_i - 1
# user_score.save
# Rails.logger.info "[UserScore#joint] ===> User: #{current_user} deleting a issue. options => (#{options.to_s})"
when :change_issue_status # current_user 更改了缺陷的状态 Changed Issue
user_score.collaboration = user_score.collaboration.to_i + 1
user_score.save
unless user_grade.nil?
user_grade.grade = user_grade.grade.to_i + 1
user_grade.save
end
create_score_changed_details({:current_user_id => current_user.id , :score_type => "collaboration",:score_action => "change_issue_status",:user_id => current_user.id,:old_score => user_score.collaboration - 1,:new_score => user_score.collaboration,:current_user_level => UserLevels.get_level(current_user),:score_changeable_obj_id=> obj.id,:score_changeable_obj_type => obj.class.to_s})
Rails.logger.info "[UserScore#joint] ===> User: #{current_user} change issue status. options => (#{options.to_s})"
when :reply_message # current_user 对 target_user 留言的回复 Add Journals_for_messages
user_score.collaboration = user_score.collaboration.to_i + 1
user_score.save
unless user_grade.nil?
user_grade.grade = user_grade.grade.to_i + 1
user_grade.save
end
create_score_changed_details({:current_user_id => current_user.id ,:target_user_id =>target_user.id, :score_type => "collaboration",:score_action => "reply_message",:user_id => current_user.id,:old_score => user_score.collaboration - 1,:new_score => user_score.collaboration,:current_user_level => UserLevels.get_level(current_user),:target_user_level => UserLevels.get_level(target_user),:score_changeable_obj_id=> obj.id,:score_changeable_obj_type => obj.class.to_s})
Rails.logger.info "[UserScore#joint] ===> User: #{current_user} reply message. options => (#{options.to_s})"
when :reply_message_delete # current_user 删除了对 target_user 留言的回复 delete Journals_for_messages
user_score.collaboration = user_score.collaboration.to_i - 1
user_score.save
Rails.logger.info "[UserScore#joint] ===> User: #{current_user} delete reply message. options => (#{options.to_s})"
#when :reply_message_delete # current_user 删除了对 target_user 留言的回复 delete Journals_for_messages
# user_score.collaboration = user_score.collaboration.to_i - 1
# user_score.save
# Rails.logger.info "[UserScore#joint] ===> User: #{current_user} delete reply message. options => (#{options.to_s})"
when :reply_posting # current_user 对 target_user 帖子的回复 Add Message
user_score.collaboration = user_score.collaboration.to_i + 1
user_score.save
unless user_grade.nil?
user_grade.grade = user_grade.grade.to_i + 1
user_grade.save
end
create_score_changed_details({:current_user_id => current_user.id ,:target_user_id =>target_user.id, :score_type => "collaboration",:score_action => "reply_posting",:user_id => current_user.id,:old_score => user_score.collaboration - 1,:new_score => user_score.collaboration,:current_user_level => UserLevels.get_level(current_user),:target_user_level => UserLevels.get_level(target_user),:score_changeable_obj_id=> obj.id,:score_changeable_obj_type => obj.class.to_s})
Rails.logger.info "[UserScore#joint] ===> User: #{current_user} reply posting. options => (#{options.to_s})"
when :reply_deleting # current_user 删除了 对 target_user 帖子的回复 Delete Message
user_score.collaboration = user_score.collaboration.to_i - 1
user_score.save
Rails.logger.info "[UserScore#joint] ===> User: #{current_user} reply deleting. options => (#{options.to_s})"
#when :reply_deleting # current_user 删除了 对 target_user 帖子的回复 Delete Message
# user_score.collaboration = user_score.collaboration.to_i - 1
# user_score.save
# Rails.logger.info "[UserScore#joint] ===> User: #{current_user} reply deleting. options => (#{options.to_s})"
else
Rails.logger.error "[UserScore#joint] ===> #{operate} is not define."
return false
@ -106,17 +139,19 @@ class UserScore < ActiveRecord::Base
# # => true #当前被关注用户记分成功
#
# Returns boolean. 返回积分保存结果
def self.influence(operate, current_user, target_user, options={})
def self.influence(operate, current_user, target_user,obj, options={})
current_user, target_user = get_users(current_user, target_user)
user_score = target_user.user_score_attr
case operate
when :followed_by # current_user 关注了target_user
when :followed_by # current_user 关注了target_user Add watcher
user_score.influence = user_score.influence.to_i + 2
user_score.save
create_score_changed_details({:current_user_id => current_user.id ,:target_user_id =>target_user.id, :score_type => "influence",:score_action => "followed_by",:user_id => target_user.id,:old_score => user_score.influence - 2,:new_score => user_score.influence,:current_user_level => UserLevels.get_level(current_user),:target_user_level => UserLevels.get_level(target_user),:score_changeable_obj_id=> obj.id,:score_changeable_obj_type => obj.class.to_s})
Rails.logger.info "[UserScore#influence] ===> User: #{current_user} be followed. options => (#{options.to_s})"
when :cancel_followed # current_uer 取消了对 target_user的关注
when :cancel_followed # current_uer 取消了对 target_user的关注 delete watcher
user_score.influence = user_score.influence.to_i - 2
user_score.save
create_score_changed_details({:current_user_id => current_user.id ,:target_user_id =>target_user.id, :score_type => "influence",:score_action => "cancel_followed",:user_id => target_user.id,:old_score => user_score.influence + 2,:new_score => user_score.influence,:current_user_level => UserLevels.get_level(current_user),:target_user_level => UserLevels.get_level(target_user),:score_changeable_obj_id=> obj.id,:score_changeable_obj_type => obj.class.to_s})
Rails.logger.info "[UserScore#influence] ===> User: #{current_user} canceled followed. options => (#{options.to_s})"
else
Rails.logger.error "[UserScore#influence] ===> #{operate} is not define."
@ -136,46 +171,96 @@ class UserScore < ActiveRecord::Base
# # => true #当前current_user对target_user用户帖子的记分成功
#
# Returns boolean. 返回积分保存结果
def self.skill(operate, current_user, target_user, options={})
def self.skill(operate, current_user, target_user,obj, options={})
current_user, target_user = get_users(current_user, target_user)
current_user_score = current_user.user_score_attr
target_user_score = target_user.user_score_attr
current_user_grade = nil #项目个人得分
target_user_grade = nil
project = obj.project
unless project.nil?
current_user_grade = UserGrade.find_by_user_id_and_project_id(current_user.id, project.id)
target_user_grade = UserGrade.find_by_user_id_and_project_id(target_user.id, project.id)
if current_user_grade.nil?
current_user_grade = UserGrade.create(:user_id => current_user.id,:project_id => project.id)
end
if target_user_grade.nil?
target_user_grade = UserGrade.create(:user_id => target_user.id,:project_id => project.id)
end
end
case operate
# when :treading # current_user 踩了 target_user 的帖子
# Rails.logger.info "[UserScore#skill] ===> User: #{current_user} treading #{target_user}'s posting. options => (#{options.to_s})"
when :treaded_by_user # current_user 踩了 target_user 的帖子
current_user_score.skill = current_user_score.skill.to_i - 2 #踩别人的帖子减2分
current_user_score.skill = current_user_score.skill.to_i - 2 #踩别人的帖子减2分 add praise_tread
current_user_score.save
unless current_user_grade.nil?
current_user_grade.grade = current_user_grade.grade - 2
current_user_grade.save
end
create_score_changed_details({:current_user_id => current_user.id ,:target_user_id =>target_user.id, :score_type => "skill",:score_action => "treaded_by_user",:user_id => current_user.id,:old_score => current_user_score.skill + 2,:new_score => current_user_score.skill,:current_user_level => UserLevels.get_level(current_user),:target_user_level => UserLevels.get_level(target_user),:score_changeable_obj_id=> obj.id,:score_changeable_obj_type => obj.class.to_s})
if current_user.id == target_user.id
target_user.reload
target_user_score = target_user.user_score_attr
unless target_user_grade.nil?
target_user_grade.reload
end
level = current_user.get_level
end
level = UserLevels.get_level(current_user)
if level == 1
target_user_score.skill = target_user_score.skill.to_i - 2 #帖子被一级会员踩-2分
target_user_score.skill = target_user_score.skill.to_i - 2 #帖子被一级会员踩-2分 add praise_tread
target_user_score.save
unless target_user_grade.nil?
target_user_grade.grade = target_user_grade.grade - 2
target_user_grade.save
end
create_score_changed_details({:current_user_id => current_user.id ,:target_user_id =>target_user.id, :score_type => "skill",:score_action => "treaded_by_user",:user_id => target_user.id,:old_score => target_user_score.skill + 2,:new_score => target_user_score.skill,:current_user_level => UserLevels.get_level(current_user),:target_user_level => UserLevels.get_level(target_user),:score_changeable_obj_id=> obj.id,:score_changeable_obj_type => obj.class.to_s})
elsif level == 2
target_user_score.skill = target_user_score.skill.to_i - 4 #帖子被二级会员踩-4分
target_user_score.skill = target_user_score.skill.to_i - 4 #帖子被二级会员踩-4分 add praise_tread
target_user_score.save
unless target_user_grade.nil?
target_user_grade.grade = target_user_grade.grade - 4
target_user_grade.save
end
create_score_changed_details({:current_user_id => current_user.id ,:target_user_id =>target_user.id, :score_type => "skill",:score_action => "treaded_by_user",:user_id => target_user.id,:old_score => target_user_score.skill + 4,:new_score => target_user_score.skill,:current_user_level => UserLevels.get_level(current_user),:target_user_level => UserLevels.get_level(target_user),:score_changeable_obj_id=> obj.id,:score_changeable_obj_type => obj.class.to_s})
elsif level == 3
target_user_score.skill = target_user_score.skill.to_i - 6 #帖子被三级会员踩-6分
target_user_score.skill = target_user_score.skill.to_i - 6 #帖子被三级会员踩-6分 add praise_tread
target_user_score.save
unless target_user_grade.nil?
target_user_grade.grade = target_user_grade.grade - 6
target_user_grade.save
end
create_score_changed_details({:current_user_id => current_user.id ,:target_user_id =>target_user.id, :score_type => "skill",:score_action => "treaded_by_user",:user_id => target_user.id,:old_score => target_user_score.skill + 6,:new_score => target_user_score.skill,:current_user_level => UserLevels.get_level(current_user),:target_user_level => UserLevels.get_level(target_user),:score_changeable_obj_id=> obj.id,:score_changeable_obj_type => obj.class.to_s})
end
Rails.logger.info "[UserScore#skill] ===> User: #{current_user} treaded_by #{target_user}. options => (#{options.to_s})"
when :praised_by_user # current_user 顶了 target_user 的帖子
level = current_user.get_level
level = UserLevels.get_level(current_user)
if level == 1
target_user_score.skill = target_user_score.skill.to_i + 4 #帖子被一级会员顶+4分
target_user_score.save
elsif level == 2
target_user_score.skill = target_user_score.skill.to_i + 6 #帖子被二级会员顶+6分
target_user_score.save
elsif level == 3
target_user_score.skill = target_user_score.skill.to_i + 8 #帖子被三级会员顶+8分
target_user_score.skill = target_user_score.skill.to_i + 4 #帖子被一级会员顶+4分 add praise_tread
target_user_score.save
unless target_user_grade.nil?
target_user_grade.grade = target_user_grade.grade + 4
target_user_grade.save
end
create_score_changed_details({:current_user_id => current_user.id ,:target_user_id =>target_user.id, :score_type => "skill",:score_action => "praised_by_user",:user_id => target_user.id,:old_score => target_user_score.skill - 4,:new_score => target_user_score.skill,:current_user_level => UserLevels.get_level(current_user),:target_user_level => UserLevels.get_level(target_user),:score_changeable_obj_id=> obj.id,:score_changeable_obj_type => obj.class.to_s})
elsif level == 2
target_user_score.skill = target_user_score.skill.to_i + 6 #帖子被二级会员顶+6分 add praise_tread
target_user_score.save
unless target_user_grade.nil?
target_user_grade.grade = target_user_grade.grade + 6
target_user_grade.save
end
create_score_changed_details({:current_user_id => current_user.id ,:target_user_id =>target_user.id, :score_type => "skill",:score_action => "praised_by_user",:user_id => target_user.id,:old_score => target_user_score.skill - 6,:new_score => target_user_score.skill,:current_user_level => UserLevels.get_level(current_user),:target_user_level => UserLevels.get_level(target_user),:score_changeable_obj_id=> obj.id,:score_changeable_obj_type => obj.class.to_s})
elsif level == 3
target_user_score.skill = target_user_score.skill.to_i + 8 #帖子被三级会员顶+8分 add praise_tread
target_user_score.save
unless target_user_grade.nil?
target_user_grade.grade = target_user_grade.grade + 8
target_user_grade.save
end
create_score_changed_details({:current_user_id => current_user.id ,:target_user_id =>target_user.id, :score_type => "skill",:score_action => "praised_by_user",:user_id => target_user.id,:old_score => target_user_score.skill - 8,:new_score => target_user_score.skill,:current_user_level => UserLevels.get_level(current_user),:target_user_level => UserLevels.get_level(target_user),:score_changeable_obj_id=> obj.id,:score_changeable_obj_type => obj.class.to_s})
end
Rails.logger.info "[UserScore#skill] ===> User: #{current_user} praised_by #{target_user}. options => (#{options.to_s})"
else
Rails.logger.error "[UserScore#skill] ===> #{operate} is not define."
@ -195,30 +280,63 @@ class UserScore < ActiveRecord::Base
# # => true #当前current_user对项目贡献积分成功
#
# Returns boolean. 返回积分保存结果
def self.project(operate, current_user, options={})
def self.project(operate, current_user,obj, options={})
current_user, target_user = get_users(current_user, nil)
user_score = current_user.try(:user_score_attr)
user_grade = nil #项目个人得分
project = obj.project
unless project.nil?
user_grade = UserGrade.find_by_user_id_and_project_id(current_user.id, project.id)
if user_grade.nil?
user_grade = UserGrade.create(:user_id => current_user.id,:project_id => project.id)
end
end
return false if current_user.nil?
case operate
when :push_code # current_user 提交了代码
when :push_code # current_user 提交了代码 changeset
user_score = user_score.active.to_i + 4
user_score.save
unless user_grade.nil?
user_grade.grade = user_grade.grade + 4
user_grade.save
end
create_score_changed_details({:current_user_id => current_user.id , :score_type => "active",:score_action => "push_code",:user_id => current_user.id,:old_score => user_score.active - 4,:new_score => user_score.active,:current_user_level => UserLevels.get_level(current_user),:score_changeable_obj_id=> obj.id,:score_changeable_obj_type => obj.class.to_s})
Rails.logger.debug "[UserScore#project] ===> User: [#{current_user.id},#{current_user.name}] pushed code one time. options => (#{options.to_s})"
when :push_document # current_user
when :push_document # current_user 提交了文档 document
user_score.active = user_score.active.to_i + 4
user_score.save
unless user_grade.nil?
user_grade.grade = user_grade.grade + 4
user_grade.save
end
create_score_changed_details({:current_user_id => current_user.id , :score_type => "active",:score_action => "push_document",:user_id => current_user.id,:old_score => user_score.active - 4,:new_score => user_score.active,:current_user_level => UserLevels.get_level(current_user),:score_changeable_obj_id=> obj.id,:score_changeable_obj_type => obj.class.to_s})
Rails.logger.debug "[UserScore#project] ===> User: [#{current_user.id},#{current_user.name}] pushed a document. options => (#{options.to_s})"
when :push_file # current_user
when :push_file # current_user 提交了附件 attachment
user_score.active = user_score.active.to_i + 4
user_score.save
unless user_grade.nil?
user_grade.grade = user_grade.grade + 4
user_grade.save
end
create_score_changed_details({:current_user_id => current_user.id , :score_type => "active",:score_action => "push_file",:user_id => current_user.id,:old_score => user_score.active - 4,:new_score => user_score.active,:current_user_level => UserLevels.get_level(current_user),:score_changeable_obj_id=> obj.id,:score_changeable_obj_type => obj.class.to_s})
Rails.logger.debug "[UserScore#project] ===> User: [#{current_user.id},#{current_user.name}] pushed a file. options => (#{options.to_s})"
when :update_issue_ratio # current_user
when :update_issue_ratio # current_user 更新了缺陷完成度 issue
user_score.active = user_score.active.to_i + 2
user_score.save
unless user_grade.nil?
user_grade.grade = user_grade.grade + 2
user_grade.save
end
create_score_changed_details({:current_user_id => current_user.id , :score_type => "active",:score_action => "update_issue_ratio",:user_id => current_user.id,:old_score => user_score.active - 2,:new_score => user_score.active,:current_user_level => UserLevels.get_level(current_user),:score_changeable_obj_id=> obj.id,:score_changeable_obj_type => obj.class.to_s})
Rails.logger.debug "[UserScore#project] ===> User: [#{current_user.id},#{current_user.name}] updated issue ratio. options => (#{options.to_s})"
when :post_issue # current_user
when :post_issue # current_user 发布了缺陷 issue
user_score.active = user_score.active.to_i + 4
user_score.save
unless user_grade.nil?
user_grade.grade = user_grade.grade + 4
user_grade.save
end
create_score_changed_details({:current_user_id => current_user.id , :score_type => "active",:score_action => "post_issue",:user_id => current_user.id,:old_score => user_score.active - 4,:new_score => user_score.active,:current_user_level => UserLevels.get_level(current_user),:score_changeable_obj_id=> obj.id,:score_changeable_obj_type => obj.class.to_s})
Rails.logger.debug "[UserScore#project] ===> User: [#{current_user.id},#{current_user.name}] posting issue. options => (#{options.to_s})"
else
Rails.logger.error "[UserScore#project] ===> #{operate} is not define."
@ -228,6 +346,44 @@ class UserScore < ActiveRecord::Base
Rails.logger.error "[UserScore#project] ===> Exception: #{e}."
end
#获取用户的user_score
def self.score(user)
if user.user_score.nil?
us = UserScore.new
us.user_id = user.id
us.save
us
else
user.user_score
end
end
#计算总得分
def total_score
score = self.influence.to_i + self.skill.to_i + self.collaboration.to_i + self.active.to_i
score
end
#创建分数改变记录 -by zjc
def self.create_score_changed_details(attributes)
if attributes.is_a? Hash
usd = UserScoreDetails.new
usd.current_user_id =attributes[:current_user_id]
usd.target_user_id = attributes[:target_user_id]
usd.score_type = attributes[:score_type]
usd.score_action = attributes[:score_action]
usd.user_id = attributes[:user_id]
usd.old_score = attributes[:old_score]
usd.new_score = attributes[:new_score]
usd.current_user_level = attributes[:current_user_level]
usd.target_user_level = attributes[:target_user_level]
#usd.score_changeable_obj = attributes[:score_changeable_obj]
usd.score_changeable_obj_id = attributes[:score_changeable_obj_id]
usd.score_changeable_obj_type = attributes[:score_changeable_obj_type]
usd.save
end
end
private
def self.get_users(current_user, target_user)

View File

@ -0,0 +1,4 @@
class UserScoreDetails < ActiveRecord::Base
attr_accessible :current_user_id, :current_user_level, :new_score, :old_score, :score_action, :score_changeable_obj_id, :score_changeable_obj_type, :score_type, :target_user_id, :target_user_level, :user_id
belongs_to :score_changeable_obj,:polymorphic => true
end

View File

@ -22,7 +22,7 @@ class Watcher < ActiveRecord::Base
has_one :project_status
has_one :users_status
#end
before_save :be_user_score
after_create :be_user_score
before_destroy :down_user_score
validates_presence_of :user
@ -76,9 +76,9 @@ class Watcher < ActiveRecord::Base
# 更新用户分数 -by zjc
def be_user_score
#添加了关注
if self.new_record? && self.watchable_type == 'Principal'
if self.watchable_type == 'Principal'
#影响力得分
UserScore.influence(:followed_by, self.user,self.watchable, { watcher_id: self.id })
UserScore.influence(:followed_by, self.user,self.watchable,self, { watcher_id: self.id })
end
end
@ -86,7 +86,7 @@ class Watcher < ActiveRecord::Base
def down_user_score
#取消关注
if self.watchable_type == 'Principal'
UserScore.influence(:cancel_followed, self.user,self.watchable, { watcher_id: self.id })
UserScore.influence(:cancel_followed, self.user,self.watchable,self, { watcher_id: self.id })
end
end

View File

@ -0,0 +1,14 @@
<% edit_allowed = User.current.allowed_to?(:manage_files, @course) %>
<% if attachmenttypes.any? %>
<div id="put-tag-form-<%=attachment.id%>" class="hidden">
<%= select_tag "attachment_type",
options_from_collection_for_select(attachmenttypes, "id",
"typeName",attachment.attachtype), :onchange=>"course_attachmenttypes_change("+attachment.id.to_s + ",this.value)"%>
</div>
<%= link_to(image_tag('edit/edit.png'), 'javascript:void(0);',:style=>"white-space:nowrap;", :id=>"edit_box"+attachment.id.to_s ,
:onclick =>"$('#put-tag-form-" +attachment.id.to_s+ "').show();
$('#attach_type_id_label" +attachment.id.to_s+ "').hide();
$('#edit_box" +attachment.id.to_s+ "').hide();") if edit_allowed %>
<% end %>

View File

@ -24,7 +24,8 @@
<% end %>
<% end %>
<% if options[:author] %>
<span class="author"><%= h(attachment.author) %>, <%= format_time(attachment.created_on) %></span>
<!-- modified by zjc author添加超链接 -->
<span class="author"><%= link_to h(attachment.author),user_path(attachment.author) %>, <%= format_time(attachment.created_on) %></span>
<% end %>
</p>
<% end %>

View File

@ -0,0 +1,3 @@
<div class="tags_area">
<%= render :partial => 'tags/tagEx', :locals => {:obj => file, :object_flag => "6"} %>
</div>

View File

@ -11,6 +11,6 @@ fileSpan.find('a.remove-upload')
"href": '<%= j attachment_path(@attachment, :attachment_id => params[:attachment_id], :format => 'js') %>'
})
.off('click');
var divattach = fileSpan.find('div.div_attachments');
divattach.html('<%= j(render :partial => 'tags/tagEx', :locals => {:obj => @attachment, :object_flag => "6"})%>');
//var divattach = fileSpan.find('div.div_attachments');
//divattach.html('<%= j(render :partial => 'tags/tagEx', :locals => {:obj => @attachment, :object_flag => "6"})%>');
<% end %>

View File

@ -0,0 +1,24 @@
<table style="width: 200px;table-layout: fixed" >
<tr>
<% count = 0 %>
<% for attachment in attachments %>
<% if attachments.count == 1 %>
<td title="<%= attachment.filename%>" style="width: 200px;white-space: nowrap;overflow: hidden;text-overflow: ellipsis;">
<%= render :partial => 'attachment', :locals => {:attachment => attachment} %>
</td>
<% elsif attachments.count == 2 %>
<td title="<%= attachment.filename%>" style="width: 100px;white-space: nowrap;overflow: hidden;text-overflow: ellipsis;">
<%= render :partial => 'attachment', :locals => {:attachment => attachment} %>
</td>
<% else %>
<td title="<%= attachment.filename%>" style="width: 66px;white-space: nowrap;overflow: hidden;text-overflow: ellipsis;">
<% if count == 3 %>
<% break %>
<% end %>
<%= render :partial => 'attachment', :locals => {:attachment => attachment} %>
<% count = count +1 %>
</td>
<% end %>
<% end %>
</tr>
</table>

View File

@ -0,0 +1,6 @@
<%= link_to_attachment attachment, :class => 'icon icon-attachment', :download => true -%>
<% if attachment.is_text? %>
<%= link_to image_tag('magnifier.png'),
:controller => 'attachments', :action => 'show',
:id => attachment, :filename => attachment.filename,:style => "width:50px"%>
<% end %>

View File

@ -13,9 +13,9 @@
<span class="font_lighter"><%= l(:label_user_create_project_homework) %></span>
<span><%= link_to(bid.name, respond_path(bid), :class => 'bid_path') %></span>
<span style="float: right">
<% if(User.current.logged? && (!Member.where('user_id = ? and project_id = ?', User.current.id, bid.courses.first.id).first.nil? && (Member.where('user_id = ? and project_id = ?', User.current.id, bid.courses.first.id).first.roles&Role.where('id = ? or id = ? or id =?',5, 10, 7)).size >0)) %>
<% if(User.current.logged? && (!Member.where('user_id = ? and course_id = ?', User.current.id, bid.courses.first.id).first.nil? && (Member.where('user_id = ? and course_id = ?', User.current.id, bid.courses.first.id).first.roles&Role.where('id = ? or id = ? or id =?',5, 10, 7)).size >0)) %>
<%# 提交作业按钮 %>
<!--<%= link_to l(:label_commit_homework), '#OpenWindow', rel: 'leanModal', onclick: "showSubH(#{bid.id}, '#{bid.name}');" if User.current.member_of?(@project) %>-->
<!--<%= link_to l(:label_commit_homework), '#OpenWindow', rel: 'leanModal', onclick: "showSubH(#{bid.id}, '#{bid.name}');" if User.current.member_of?(@course) %>-->
<% cur_user_homework = cur_user_homework_for_bid(bid) %>
<% if cur_user_homework!= nil && cur_user_homework.count == 0 %>
<%= link_to l(:label_commit_homework),new_homework_attach_path(bid) %>
@ -26,7 +26,7 @@
<% if (User.current.admin?||User.current.id==bid.author_id) %>
<%= link_to(
l(:button_edit),
{:action => 'edit', :controller=>'bids', :project_id =>@project.id, :bid_id => bid.id},
{:action => 'edit', :controller=>'bids', :course_id =>@course.id, :bid_id => bid.id},
:class => 'icon icon-edit'
) %>
<%= link_to(
@ -51,9 +51,9 @@
end
%>
<% if bid.homework_type == 1%>
<%= l(:label_x_homework_project, :count => bid.homeworks.count) %>(<strong><%= link_to bid.homeworks.count, project_for_bid_path(bid.id) %></strong>)
<%= l(:label_x_homework_project, :count => bid.homeworks.count) %>(<strong><%= link_to bid.homeworks.count, course_for_bid_path(bid.id) %></strong>)
<% else %>
<%= l(:label_x_homework_project, :count => @temp.count) %>(<strong><%= link_to @temp.count, project_for_bid_path(bid.id) %></strong>)
<%= l(:label_x_homework_project, :count => @temp.count) %>(<strong><%= link_to @temp.count, course_for_bid_path(bid.id) %></strong>)
<% end %></span>
<span class="font_lighter"><%= l(:label_x_responses, :count => bid.commit) %>(<strong><%= link_to bid.commit, respond_path(bid) %></strong>)</span>
<span style="float: right">
@ -92,9 +92,6 @@
<% end %>
<% end %>
<div class="pagination">
<ul>
<%= pagination_links_full bid_pages %>
<ul>
<%= pagination_links_full @obj_pages, @obj_count, :per_page_links => false %>
</div>

View File

@ -21,22 +21,48 @@
$.globalEval(submit_homework());
return false;
}
function show()
{
$("#what_is_project_div").slideToggle();
}
</script>
</div>
<% if User.current.logged? && (!Member.where('user_id = ? and project_id = ?', User.current.id, @bid.courses.first.id).first.nil? &&
(Member.where('user_id = ? and project_id = ?', User.current.id,
@bid.courses.first.id).first.roles&Role.where('id = ? or id = ? or id =?',5, 10, 7)).size >0) && cur_user_homework_for_bid(@bid).count == 0 %>
<% if User.current.logged? && User.current.member_of_course?(@bid.courses.first) && cur_user_homework_for_bid(@bid).count == 0 && is_cur_course_student(@bid.courses.first) %>
<div class='icon icon-add'>
<!-- <%= link_to l(:label_commit_homework), new_submit_homework_path, :onclick => "$('#put-bid-form').slideToggle(); this.blur(); return false;" %> -->
<%= link_to l(:label_course_new_homework),new_homework_attach_path %>
<%#= link_to l(:label_commit_homework), new_submit_homework_path, :onclick => "$('#put-bid-form').slideToggle(); this.blur(); return false;" %>
<%= link_to l(:label_course_new_homework),new_homework_attach_path %><strong style="color: #a9a9a9">&nbsp;&nbsp;(每一个作业都可以是一个精美的作品)</strong>
</div>
<% end %>
<table style="width: 100%">
<tr>
<td style="width: 50%">
<% if @homework_list.empty? %>
<div class="font_lighter_sidebar" style="padding-left: 10px">
暂无学生提交作业!
<div class="font_lighter_sidebar" style="padding-left: 10px;">
<span>暂无学生提交作业!</span>
</div>
<% end %>
</td>
<td style="width: 50%">
<div class="font_lighter_sidebar" style="padding-left: 200px;">
<strong><a href="#" onclick="show()" style="color:#919294;">什么是项目?</a></strong>
</div>
</td>
</tr>
<tr>
<td style="width: 50%">
</td>
<td style="width: 50%">
<div id = "what_is_project_div" style="display: none">
<p>项目是一种由用户创建的基于网络的协作空间,能够为个人或小组提供分布式的协同交流和资料管理等方面的支持。</p>
<p>项目托管平台:<a href="http://forge.trustie.net/">http://forge.trustie.net/</a> </p>
<%= link_to "我要创建项目",new_project_path(course: 0, project_type: 0), :target => '_blank'%>
</div>
</td>
</tr>
</table>
<div id='bidding_project_list'>
<%= render :partial => 'homework_list', :locals => {:homework => @homework_list} %>

View File

@ -3,12 +3,12 @@
<% is_teacher = is_course_teacher User.current,@bid.courses.first %>
<!-- 当is_evaluation为1或者null(null主要是为了兼容前面数据)时代表启用互评功能2表示未启用 -->
<% is_evaluation = @bid.is_evaluation == 1 || @bid.is_evaluation == nil %>
<%= form_tag(:controller => 'bids', :action => "show_project", :method => :get) do %>
<%= form_tag(:controller => 'bids', :action => "show_courseEx", :method => :get) do %>
<div class="project-search-block">
<table width="100%" valign="center">
<tr>
<td ><span style="margin-left:0px"><%= l(:label_task_plural)%>(<%= @homework_list.count%>)</span>
<%= link_to "作业打包下载", zipdown_assort_path(obj_class: @bid.class, obj_id: @bid), remote: false, class: "button_submit button_submit_font_white", style: "margin: 5px 10px;line-height: 20px;height: 20px;display: inline-block;" if(
<%#= link_to "作业打包下载", zipdown_assort_path(obj_class: @bid.class, obj_id: @bid), remote: false, class: "button_submit button_submit_font_white", style: "margin: 5px 10px;line-height: 20px;height: 20px;display: inline-block;" if(
User.current.admin? ||
!(User.current.roles_for_project(@bid.courses.first).map(&:id) & ([7,9])).empty? ) ||
(Rails.env.development?) %>
@ -19,7 +19,9 @@
<%= text_field_tag 'student_id', params[:student_id], :size => 30 %>
<%= submit_tag l(:label_search_by_student_id), :class => "small", :name => nil %>
<% end %>
</div></td>
</div>
</td>
</tr>
</table>
</div>
@ -28,67 +30,19 @@
<% @homework_list.each do |homework|%>
<table width="660px" border="0" align="center" id="homework_attach_<%= homework.id %>" >
<tr>
<td colspan="2" valign="top" width="50" ><%= image_tag(url_to_avatar(homework.user), :class => "avatar")%></td>
<td>
<table width="580px" border="0">
<td style="vertical-align: top;width: 70px" >
<table style="text-align: center;width: 100%;table-layout: fixed">
<tr>
<td style="width: 300px;">
&nbsp;&nbsp;<strong>作业&nbsp;&nbsp; :</strong>&nbsp;
<% if homework.name == nil || homework.name == "" %>
<% attachments = homework.attachments.map %>
<% for attachment in attachments %>
<% if attachments.count > 1 %>
<% homework_filename = attachment.filename + "等" + attachments.count.to_s + "个文件" %>
<% else %>
<% homework_filename = attachment.filename %>
<% end %>
<% end %>
<% else %>
<% homework_filename = homework.name %>
<% end %>
<strong>
<% if is_evaluation || is_teacher%>
<%= link_to homework_filename, :controller => "zipdown", :action => "download_user_homework",:homework => homework%>
<% else %>
<%= homework_filename %>
<% end %>
</strong>
</td>
<td style="vertical-align: top">
<% if is_student %>
<% if is_evaluation %>
<%= link_to "互评>>" , homework_attach_path(homework)%>
<% else %>
<%= link_to "查看详细" , homework_attach_path(homework)%>
<% end %>
<% else %>
<% if is_teacher %>
<%= link_to "综评>>" , homework_attach_path(homework)%>
<% end %>
<% end %>
<td title="<%= homework.user.name %>"><%= image_tag(url_to_avatar(homework.user), :class => "avatar")%></td>
</tr>
<tr>
<td title="<%= homework.user.name %>">
<p style="width: 100%;white-space: nowrap;overflow: hidden;text-overflow: ellipsis;"><strong>
<%= link_to (is_teacher ? homework.user.realname : homework.user ), user_path(homework.user),{:style => "color:#727272"} %>
</strong></p>
</td>
</tr>
<tr>
<td colspan="1" valign="top" style="width: 300px">&nbsp;
<strong>发布人:&nbsp; <%= link_to ( is_teacher ? homework.user.realname : homework.user ), user_path(homework.user)%></strong>
</td>
<td>
<strong>作业评分:</strong>
<%= format("%.2f", homework.rate_averages.first.try(:avg).to_f ) %>
</td>
<td valign="top" align="right">
<% if Time.parse(@bid.deadline.to_s) < Time.parse(homework.created_at.to_s) %>
<span class="required">迟交</span>
<% end %>
</td>
</tr>
<tr>
<td valign="top">&nbsp;
<% if User.current.member_of?(@bid.courses.first) %>
<strong><%= l(:label_bidding_user_studentcode) %>&nbsp; &nbsp;<%= homework.user.student_id%></strong>
<% end %>
</td>
<td>
<% if (users_for_homework(homework).include?(User.current) || is_teacher) %>
<%= link_to l(:button_edit), edit_homework_attach_path(homework) %>
@ -97,6 +51,99 @@
method: :delete, :confirm => l(:text_are_you_sure)) %>
<% end %>
<% end %>
</td>
</tr>
</table>
<span></span>
</td>
<td colspan="2">
<table width="580px" border="0" style="table-layout: fixed">
<tr>
<td style="width: 300px;white-space: nowrap;overflow: hidden;text-overflow: ellipsis;">
<strong>作品名称:</strong>&nbsp;
<% if homework.name == nil || homework.name == "" %>
<% homework_filename = homework.user.name + "提交的作业" %>
<% else %>
<% homework_filename = homework.name %>
<% end %>
<strong title="<%=homework_filename%>">
<%= link_to homework_filename , homework_attach_path(homework)%>
</strong>
</td>
<td style="vertical-align: top;width: 200px;white-space: nowrap;overflow: hidden;text-overflow: ellipsis;">
<strong>合作成员:&nbsp;</strong>
<% homework_users = homework_user_of_homework(homework,is_teacher) %>
<% if homework.users.count == 0 %>
<% else %>
<span title="<%= homework_users%>"><%= homework_users %></span>
<% end %>
</td>
<td rowspan="4" style="text-align: center;vertical-align: middle;width: 30px">
<% if Time.parse(@bid.deadline.to_s) < Time.parse(homework.created_at.to_s) %>
<span class="required">迟交</span>
<% end %>
</td>
</tr>
<tr>
<td>
<strong>开发项目</strong>:&nbsp;
<% if homework.project != nil %>
<%= link_to homework.project.name,project_path(homework.project.id)%>
<% else %>
暂无
<% end %>
</td>
<td>
<strong>项目得分:&nbsp;
<span style="color: <%= homework.project.nil? ? "#727272" : "#EC6300"%>;">
<%= homework.project.nil? ? "N/A" : project_score(homework.project) %>
</span>
</strong>
</td>
</tr>
<tr>
<td>
<strong>提交文件:&nbsp;
<% if is_evaluation || is_teacher%>
<%= link_to "打包下载", :controller => "zipdown", :action => "download_user_homework",:homework => homework%>
<% else %>
<span class="required">未开启互评功能作业不允许下载</span>
<% end %>
</strong>
</td>
<td>
<strong>互评得分:&nbsp;
<% student_homework_score = student_score_for_homework(homework) %>
<span style="color:<%= student_homework_score == "0.00"? "#727272" : "#EC6300"%>;">
<% score = student_homework_score == "0.00"? "N/A" : student_homework_score %>
<%= score %>
</span>&nbsp;&nbsp;
<% if is_evaluation && is_student && (!users_for_homework(homework).include? User.current)%>
<%= link_to "学生互评>>",homework_attach_path(homework) %>
<% end %>
</strong>
</td>
</tr>
<tr>
<td style="vertical-align: top;width: 200px;">
<% if is_evaluation || is_teacher%>
<%= render :partial => 'app_link', :locals => {:attachments => homework.attachments} %>
<% end %>
</td>
<td>
<strong>终评得分:&nbsp;
<% totle_homework_score = score_for_homework(homework) %>
<span style="color:<%= totle_homework_score == "0.00"? "#727272" : "#EC6300"%> ;">
<% score = totle_homework_score == "0.00"? "N/A" : totle_homework_score %>
<%= score %>
</span>&nbsp;&nbsp;
<% if is_teacher %>
<%= link_to "教师评分>>",homework_attach_path(homework) %>
<% end %>
</strong>
</td>
</tr>
</table>

View File

@ -2,7 +2,7 @@
<div style="margin-left: 20px;">
<span class="portrait"><%= image_tag(url_to_avatar(@bid.author), :class => "avatar")%></span>
<span class="body">
<h3><%= link_to(@bid.author.lastname+@bid.author.firstname, user_path(@bid.author))%><%= @bid.name %></h3>
<h3><%= link_to(@bid.author.lastname+@bid.author.firstname, user_path(@bid.author))%><%= link_to(@bid.name,respond_path(@bid)) %></h3>
<% if @bid.reward_type.nil? or @bid.reward_type == 1%>
<p>
<strong><%= l(:label_bids_reward_method) %><span class="bonus"><%= l(:label_call_bonus) %>&nbsp; <%= l(:label_RMB_sign) %><%= @bid.budget %></span></strong>

View File

@ -8,10 +8,10 @@
<td>
<table width="580" border="0">
<tr>
<td colspan="2" valign="top"><span><%= link_to_project(course) %></span>
<span style="float: right"><%= l(:label_homework) %> (<span class=""><%= link_to (course.homeworks.count), {:controller => 'projects', :action => 'homework', :id => course.identifier} %></span>)
<td colspan="2" valign="top"><span><%= link_to_course(course) %></span>
<span style="float: right"><%= l(:label_homework) %> (<span class=""><%= link_to (course.homeworks.count), {:controller => 'courses', :action => 'homework', :id => course.id} %></span>)
&nbsp;&nbsp;&nbsp;
<%= l(:label_course_news)%> (<span style="color: #ed8924"><%= link_to (course.news.count), {:controller => 'news', :action => 'index', :project_id => course.identifier} %></span>)
<%= l(:label_course_news)%> (<span style="color: #ed8924"><%= link_to (course.news.count), {:controller => 'news', :action => 'index', :course_id => course.id} %></span>)
</span>
</td>
</tr>
@ -22,10 +22,9 @@
</p></td>
</tr>
<tr>
<td align="left"><span class="font_lighter"> <%= format_time(course.created_on) %></span></td><!-- modified by ming -->
<td align="left"><span class="font_lighter"> <%= format_time(course.created_at) %></span></td><!-- modified by ming -->
<td align="right" >
<% t_course = Course.find_by_extra(course.identifier) %>
教师:<%= link_to(t_course.teacher.lastname+t_course.teacher.firstname, user_path(t_course.teacher)) %>
教师:<%= link_to(course.teacher.lastname+course.teacher.firstname, user_path(course.teacher)) %>
</td>
</tr>
</table></td>

View File

@ -0,0 +1,72 @@
<% if @bid.homework_type == Bid::HomeworkFile %>
<!-- 提交文件类型 -->
<%= render :partial => 'homework' %>
<% else %>
<!-- 提交引用项目 -->
<script type="text/javascript" language="javascript">
function clearInfo(id, content) {
var text = $('#' + id);
if (text.val() == content) {
$('#' + id).val('');
}
}
function showInfo(id, content) {
var text = $('#' + id);
if (text.val() == '') {
$('#' + id).val(content);
}
}
function cancel() {
$("#put-bid-form").hide();
}
</script>
<% if User.current.logged? %>
<!--我要竞标弹出框-->
<div id='flash' style="float:left; width: 100%; display: none"></div>
<div id="put-bid-form" style="display: none">
<%= form_for "bid_for_save", :remote => true, :url => {:controller => 'bids', :action => 'add'},
:update => "bidding_project_list",
:complete => '$("#put-bid-form").hide();' do |f| %>
<table id="bidding_table" border="0" width="100%" style="margin-left: 40px;">
<tr>
<td><%= select_tag 'bid', options_for_select(select_option_helper(@option)), :name => 'bid', :class => 'grayline' %></td>
<div id="prompt_create_pro">
<td>
<div class="font_lighter" style="font-size: 13px;">
<%= link_to '创建项目', new_project_path(course: 0, project_type: 0), :target => '_blank' %>
</div>
</td>
</div>
</tr>
<% if @bid.reward_type == Bid::Homework %>
<tr>
<td><%= f.text_area :bid_message, :id => "bid_message", :required => true, :rows => 4, :cols => 40, :placeholder => l(:label_bid_reason_homework), :style => "resize: none;", :class => 'noline' %></td>
</tr>
<% else %>
<tr>
<td><%= f.text_area :bid_message, :id => "bid_message", :required => true, :rows => 4, :cols => 40, :placeholder => l(:label_bid_reason), :style => "resize: none;", :class => 'noline' %></td>
</tr>
<% end %>
<tr>
<td align="right">
<%= submit_tag l(:button_add), :name => nil, :class => "enterprise",
:onmouseout => "this.style.backgroundPosition = 'left top'",
:onmouseover => "this.style.backgroundPosition = 'left -30px'" %>
<%= submit_tag l(:button_cancel), :name => nil, :onclick => "cancel();",
:type => 'button', :class => "enterprise", :onmouseout => "this.style.backgroundPosition = 'left top'",
:onmouseover => "this.style.backgroundPosition = 'left -30px'" %>
</td>
</tr>
</table>
<% end %>
</div>
<% end %>
<div id='bidding_project_list'>
<%= render :partial => 'project_list', :locals => {:bidding_project => @bidding_project, :bid => @bid} %>
</div>
<% end %>

View File

@ -0,0 +1,106 @@
<!-- <%= course_board_breadcrumb(@board) %> -->
<!--new and follow-->
<!-- <div class="content-title-top">
<%= link_to l(:label_message_new),
new_board_message_path(@board),
:class => 'icon icon-add',
:onclick => 'showAndScrollTo("add-message", "message_subject"); return false;' if User.current.logged? %> -->
<!-- <%= watcher_link(@board, User.current) %> -->
<!-- </div> -->
<div id="add-message" class="add_frame" style="display:none;">
<% if User.current.logged? %>
<h3><%= link_to h(@board.name), course_board_path(@course, @board) %> &#187; <%= l(:label_message_new) %></h3>
<div class="add_frame_header" >
<%= l(:label_message_new) %>
</div>
<%= form_for @message, :url => new_board_message_path(@board), :html => {:multipart => true, :id => 'message-form'} do |f| %>
<%= render :partial => 'messages/form', :locals => {:f => f} %>
<p><%= submit_tag l(:button_create), :class => "whiteButton m3p10 h30" %>
<%= preview_link(preview_board_message_path(@board), 'message-form' ,target='preview',{:class => 'whiteButton m3p10'} )%> |
<%= link_to l(:button_cancel), "#", :onclick => '$("#add-message").hide(); return false;' ,:class => 'whiteButton m3p10' %></p>
<% end %>
<div id="preview" class="wiki"></div>
<% end %>
</div>
<!--display the board-->
<div class="borad-title"><%=h @board.name %></div>
<% if !User.current.logged?%>
<div style="font-size: 14px;margin:20px;">
<%= l(:label_user_login_course_board) %>
<%= link_to l(:label_user_login_new), signin_path %>
<hr/>
</div>
<% end %>
<!-- <div class="borad-description"><%=h @board.description %></div> -->
<div class="borad-setitle">
<span class="borad-topic-count">共有 <%=link_to @topics.count %> 个贴子</span>
<span>
<%= link_to l(:label_message_new),
new_board_message_path(@board),
:class => 'icon icon-add',
:onclick => 'showAndScrollTo("add-message", "message_subject"); return false;' if User.current.logged? %>
</span>
</div>
<div style="padding-top: 10px">
<% if @topics.any? %>
<!-- <table class="list messages">
<thead><tr>
<th><%= l(:field_subject) %></th>
<th><%= l(:field_author) %></th>
<%= sort_header_tag('created_on', :caption => l(:field_created_on)) %>
<%= sort_header_tag('replies', :caption => l(:label_reply_plural)) %>
<%= sort_header_tag('updated_on', :caption => l(:label_message_last)) %>
</tr></thead>
<tbody> -->
<% @topics.each do |topic| %>
<table class="content-text-list">
<tr>
<td colspan="2" valign="top" width="50" ><%= link_to image_tag(url_to_avatar(topic.author), :class => "avatar"), user_path(topic.author) %></td>
<td>
<table width="640px" border="0">
<tr>
<td valign="top" width="500px" class=" <%= topic.sticky? ? 'sticky' : '' %> <%= topic.locked? ? 'locked' : '' %>"><%= link_to h(topic.subject), board_message_path(@board, topic) %></td>
<td align="right" rowspan="3"><table class="borad-count"><tr><td align="center" class="borad-count-digit"><%=link_to (topic.replies_count), board_message_path(@board, topic) %></td></tr>
<tr><td align="center">回答</td></tr>
</table></td>
</tr>
<!-- <tr><td colspan="2" ><span class="font_description">标签</span></td></tr> -->
<tr><td align="left" colspan="2" ><span class="font_lighter"><%= authoring topic.created_on, topic.author %><br /></span></td></tr>
</table></td>
</tr>
</table>
<!-- <tr class="message <%= cycle 'odd', 'even' %> <%= topic.sticky? ? 'sticky' : '' %> <%= topic.locked? ? 'locked' : '' %>">
<td class="subject"><%= link_to h(topic.subject), board_message_path(@board, topic) %></td>
<td class="author"><%= link_to_user(topic.author) %></td>
<td class="created_on"><%= format_time(topic.created_on) %></td>
<td class="reply-count"><%= topic.replies_count %></td>
<td class="last_message">
<% if topic.last_reply %>
<%= authoring topic.last_reply.created_on, topic.last_reply.author %><br />
<%= link_to_message topic.last_reply %>
<% end %>
</td>
</tr> -->
<% end %>
<!-- </tbody>
</table> -->
<div class="pagination"><%= pagination_links_full @topic_pages, @topic_count %></div>
<% else %>
<p class="nodata"><%= l(:label_no_data) %></p>
<% end %>
</div>
<% other_formats_links do |f| %>
<%= f.link_to 'Atom', :url => {:key => User.current.rss_key} %>
<% end %>
<% html_title @board.name %>
<% content_for :header_tags do %>
<%= auto_discovery_link_tag(:atom, {:format => 'atom', :key => User.current.rss_key}, :title => "#{@course}: #{@board}") %>
<% end %>

View File

@ -0,0 +1,110 @@
<!-- <%= board_breadcrumb(@board) %> -->
<!--new and follow-->
<!-- <div class="content-title-top">
<%= link_to l(:label_message_new),
new_board_message_path(@board),
:class => 'icon icon-add',
:onclick => 'showAndScrollTo("add-message", "message_subject"); return false;' if User.current.logged? %> -->
<!-- <%= watcher_link(@board, User.current) %> -->
<!-- </div> -->
<div id="add-message" class="add_frame" style="display:none;">
<% if User.current.logged? %>
<h3><%= link_to h(@board.name), project_board_path(@project, @board) %> &#187; <%= l(:label_message_new) %></h3>
<div class="add_frame_header" >
<%= l(:label_message_new) %>
</div>
<%= form_for @message, :url => new_board_message_path(@board), :html => {:multipart => true, :id => 'message-form'} do |f| %>
<%= render :partial => 'messages/form', :locals => {:f => f} %>
<p><%= submit_tag l(:button_create), :class => "whiteButton m3p10 h30" %>
<%= preview_link(preview_board_message_path(@board), 'message-form' ,target='preview',{:class => 'whiteButton m3p10'} )%> |
<%= link_to l(:button_cancel), "#", :onclick => '$("#add-message").hide(); return false;' ,:class => 'whiteButton m3p10' %></p>
<% end %>
<div id="preview" class="wiki"></div>
<% end %>
</div>
<!--display the board-->
<div class="borad-title"><%=h @board.name %></div>
<% if !User.current.logged?%>
<div style="font-size: 14px;margin:20px;">
<% if @project.project_type == 1 %>
<%= l(:label_user_login_course_board) %>
<% else %>
<%= l(:label_user_login_project_board) %>
<% end %>
<%= link_to l(:label_user_login_new), signin_path %>
<hr/>
</div>
<% end %>
<!-- <div class="borad-description"><%=h @board.description %></div> -->
<div class="borad-setitle">
<span class="borad-topic-count">共有 <%=link_to @topics.count %> 个贴子</span>
<span>
<%= link_to l(:label_message_new),
new_board_message_path(@board),
:class => 'icon icon-add',
:onclick => 'showAndScrollTo("add-message", "message_subject"); return false;' if User.current.logged? %>
</span>
</div>
<div style="padding-top: 10px">
<% if @topics.any? %>
<!-- <table class="list messages">
<thead><tr>
<th><%= l(:field_subject) %></th>
<th><%= l(:field_author) %></th>
<%= sort_header_tag('created_on', :caption => l(:field_created_on)) %>
<%= sort_header_tag('replies', :caption => l(:label_reply_plural)) %>
<%= sort_header_tag('updated_on', :caption => l(:label_message_last)) %>
</tr></thead>
<tbody> -->
<% @topics.each do |topic| %>
<table class="content-text-list">
<tr>
<td colspan="2" valign="top" width="50" ><%= link_to image_tag(url_to_avatar(topic.author), :class => "avatar"), user_path(topic.author) %></td>
<td>
<table width="640px" border="0">
<tr>
<td valign="top" width="500px" class=" <%= topic.sticky? ? 'sticky' : '' %> <%= topic.locked? ? 'locked' : '' %>"><%= link_to h(topic.subject), board_message_path(@board, topic) %></td>
<td align="right" rowspan="3"><table class="borad-count"><tr><td align="center" class="borad-count-digit"><%=link_to (topic.replies_count), board_message_path(@board, topic) %></td></tr>
<tr><td align="center">回答</td></tr>
</table></td>
</tr>
<!-- <tr><td colspan="2" ><span class="font_description">标签</span></td></tr> -->
<tr><td align="left" colspan="2" ><span class="font_lighter"><%= authoring topic.created_on, topic.author %><br /></span></td></tr>
</table></td>
</tr>
</table>
<!-- <tr class="message <%= cycle 'odd', 'even' %> <%= topic.sticky? ? 'sticky' : '' %> <%= topic.locked? ? 'locked' : '' %>">
<td class="subject"><%= link_to h(topic.subject), board_message_path(@board, topic) %></td>
<td class="author"><%= link_to_user(topic.author) %></td>
<td class="created_on"><%= format_time(topic.created_on) %></td>
<td class="reply-count"><%= topic.replies_count %></td>
<td class="last_message">
<% if topic.last_reply %>
<%= authoring topic.last_reply.created_on, topic.last_reply.author %><br />
<%= link_to_message topic.last_reply %>
<% end %>
</td>
</tr> -->
<% end %>
<!-- </tbody>
</table> -->
<div class="pagination"><%= pagination_links_full @topic_pages, @topic_count %></div>
<% else %>
<p class="nodata"><%= l(:label_no_data) %></p>
<% end %>
</div>
<% other_formats_links do |f| %>
<%= f.link_to 'Atom', :url => {:key => User.current.rss_key} %>
<% end %>
<% html_title @board.name %>
<% content_for :header_tags do %>
<%= auto_discovery_link_tag(:atom, {:format => 'atom', :key => User.current.rss_key}, :title => "#{@project}: #{@board}") %>
<% end %>

View File

@ -1,110 +1,5 @@
<!-- <%= board_breadcrumb(@board) %> -->
<!--new and follow-->
<!-- <div class="content-title-top">
<%= link_to l(:label_message_new),
new_board_message_path(@board),
:class => 'icon icon-add',
:onclick => 'showAndScrollTo("add-message", "message_subject"); return false;' if User.current.logged? %> -->
<!-- <%= watcher_link(@board, User.current) %> -->
<!-- </div> -->
<div id="add-message" class="add_frame" style="display:none;">
<% if User.current.logged? %>
<h3><%= link_to h(@board.name), project_board_path(@project, @board) %> &#187; <%= l(:label_message_new) %></h3>
<div class="add_frame_header" >
<%= l(:label_message_new) %>
</div>
<%= form_for @message, :url => new_board_message_path(@board), :html => {:multipart => true, :id => 'message-form'} do |f| %>
<%= render :partial => 'messages/form', :locals => {:f => f} %>
<p><%= submit_tag l(:button_create), :class => "whiteButton m3p10 h30" %>
<%= preview_link(preview_board_message_path(@board), 'message-form' ,target='preview',{:class => 'whiteButton m3p10'} )%> |
<%= link_to l(:button_cancel), "#", :onclick => '$("#add-message").hide(); return false;' ,:class => 'whiteButton m3p10' %></p>
<% end %>
<div id="preview" class="wiki"></div>
<% end %>
</div>
<!--display the board-->
<div class="borad-title"><%=h @board.name %></div>
<% if !User.current.logged?%>
<div style="font-size: 14px;margin:20px;">
<% if @project.project_type == 1 %>
<%= l(:label_user_login_course_board) %>
<% else %>
<%= l(:label_user_login_project_board) %>
<% end %>
<%= link_to l(:label_user_login_new), signin_path %>
<hr/>
</div>
<% end %>
<!-- <div class="borad-description"><%=h @board.description %></div> -->
<div class="borad-setitle">
<span class="borad-topic-count">共有 <%=link_to @topics.count %> 个贴子</span>
<span>
<%= link_to l(:label_message_new),
new_board_message_path(@board),
:class => 'icon icon-add',
:onclick => 'showAndScrollTo("add-message", "message_subject"); return false;' if User.current.logged? %>
</span>
</div>
<div style="padding-top: 10px">
<% if @topics.any? %>
<!-- <table class="list messages">
<thead><tr>
<th><%= l(:field_subject) %></th>
<th><%= l(:field_author) %></th>
<%= sort_header_tag('created_on', :caption => l(:field_created_on)) %>
<%= sort_header_tag('replies', :caption => l(:label_reply_plural)) %>
<%= sort_header_tag('updated_on', :caption => l(:label_message_last)) %>
</tr></thead>
<tbody> -->
<% @topics.each do |topic| %>
<table class="content-text-list">
<tr>
<td colspan="2" valign="top" width="50" ><%= link_to image_tag(url_to_avatar(topic.author), :class => "avatar"), user_path(topic.author) %></td>
<td>
<table width="640px" border="0">
<tr>
<td valign="top" width="500px" class=" <%= topic.sticky? ? 'sticky' : '' %> <%= topic.locked? ? 'locked' : '' %>"><%= link_to h(topic.subject), board_message_path(@board, topic) %></td>
<td align="right" rowspan="3"><table class="borad-count"><tr><td align="center" class="borad-count-digit"><%=link_to (topic.replies_count), board_message_path(@board, topic) %></td></tr>
<tr><td align="center">回答</td></tr>
</table></td>
</tr>
<!-- <tr><td colspan="2" ><span class="font_description">标签</span></td></tr> -->
<tr><td align="left" colspan="2" ><span class="font_lighter"><%= authoring topic.created_on, topic.author %><br /></span></td></tr>
</table></td>
</tr>
</table>
<!-- <tr class="message <%= cycle 'odd', 'even' %> <%= topic.sticky? ? 'sticky' : '' %> <%= topic.locked? ? 'locked' : '' %>">
<td class="subject"><%= link_to h(topic.subject), board_message_path(@board, topic) %></td>
<td class="author"><%= link_to_user(topic.author) %></td>
<td class="created_on"><%= format_time(topic.created_on) %></td>
<td class="reply-count"><%= topic.replies_count %></td>
<td class="last_message">
<% if topic.last_reply %>
<%= authoring topic.last_reply.created_on, topic.last_reply.author %><br />
<%= link_to_message topic.last_reply %>
<% end %>
</td>
</tr> -->
<% end %>
<!-- </tbody>
</table> -->
<div class="pagination"><%= pagination_links_full @topic_pages, @topic_count %></div>
<% else %>
<p class="nodata"><%= l(:label_no_data) %></p>
<% end %>
</div>
<% other_formats_links do |f| %>
<%= f.link_to 'Atom', :url => {:key => User.current.rss_key} %>
<% end %>
<% html_title @board.name %>
<% content_for :header_tags do %>
<%= auto_discovery_link_tag(:atom, {:format => 'atom', :key => User.current.rss_key}, :title => "#{@project}: #{@board}") %>
<% if @project %>
<%= render :partial => 'project_show', locals: {project: @project} %>
<% elsif @course %>
<%= render :partial => 'course_show', locals: {course: @course} %>
<% end %>

View File

@ -76,7 +76,8 @@
<strong>
<%= l(:label_contest_user) %>
<% unless c_project.user.nil? %>
<%= c_project.user.lastname %><%= c_project.user.firstname %>
<!-- modified by zjc 添加超链接 -->
<%= link_to c_project.user.lastname + c_project.user.firstname,user_path(c_project.user) %>
<% end %>
</strong>

View File

@ -259,7 +259,10 @@
<span><strong><%= l(:label_attendingcontest_time) %>
</strong><%= format_time c_project.created_at %></span>
<span style="padding-left: 240px"><strong><%= l(:label_attendingcontest_spoksman) %>
</strong><%= c_project.user.name %></span>
<!-- modified by zjc 添加超链接 -->
<% unless c_project.nil? || c_project.user.nil? %>
</strong><%= link_to c_project.user.name,user_path(c_project.user) %></span>
<% end %>
</div>
<div style="padding-left: 68px">
@ -293,7 +296,10 @@
<span><strong><%= l(:label_attendingcontest_time) %>
</strong><%= format_time c_softapplication.created_at %></span>
<span style="padding-left: 240px"><strong><%= l(:label_attendingcontest_spoksman) %>
</strong><%= c_softapplication.softapplication.user.name %></span>
<!-- modified by zjc 添加超链接 -->
<% unless c_softapplication.nil? || c_softapplication.softapplication.nil? || c_softapplication.softapplication.user.nil? %>
</strong><%= link_to c_softapplication.softapplication.user.name,user_path(c_softapplication.softapplication.user) %></span>
<% end %>
</div>
<!--获奖及教师评奖-->

View File

@ -15,7 +15,7 @@
</div>
<span id="praise_tread" style="float: right">
<%= render :partial => "/praise_tread/praise_tread",
:locals => {:obj => @contest,:show_flag => true,:user_id =>User.current.id}%>
:locals => {:obj => @contest,:show_flag => true,:user_id =>User.current.id,:horizontal => false}%>
</span>
</span>
</div>

View File

@ -0,0 +1,87 @@
<div class="project-block">
<div class="img-tag-2">
<% if get_avatar?(course)%>
<%= image_tag(url_to_avatar(course), :class => "avatar2") %>
<% else %>
<%= image_tag('../images/avatars/course/course.jpg', :class => "avatar2") %>
<% end %>
</div>
<div class="wiki-description">
<p >
<%= content_tag('span',"#{l(:label_bid_show_course_name)}:", :class => "course-font")%>
<%= content_tag('span', link_to("#{@course.name}", course_path(@course), :class => "info"))%>
</p>
<p >
<%= content_tag('span', "#{l(:label_institution_name)}:", :class => "course-font")%>
<% @admin = @course.course_infos%>
<%if @admin&&@admin.first&&@admin.first.user&&@admin.first.user.user_extensions%>
<!-- <%= @admin.first.user.user_extensions.occupation %> -->
<%# unless @course.course_extra.school.nil? %>
<%= @course.teacher.user_extensions.school.try(:name) %>
<%# end %>
<% end %>
</p>
<p >
<%= content_tag('div', "#{l(:field_teacher_name)}:", :class => "info course-font teacher") %>
<% if @admin.size > 0 %>
<%= content_tag('a', @admin.collect{|u| link_to(u.user.lastname+u.user.firstname, user_path(u.user_id))}.join(", ").html_safe) %>
<% end %>
</p>
</div>
<div class="information_for_course" >
<p class="stats">
<%= content_tag('span', link_to("#{@course.homeworks.count}", homework_course_path(@course)), :class => "info") %>
<%= content_tag('span', l(:label_x_task, :count => @course.homeworks.count)) %>
</p>
<p class="stats">
<% files_count = @course.attachments.count %>
<%= content_tag('span', link_to(files_count, course_files_path(@course)), :class => "info") %>
<%= content_tag('span', l(:label_x_data,:count => files_count)) %>
</p>
<p class="stats">
<%= content_tag('span', "#{garble @course.members.count}", :class => "info") %>
<%= content_tag('span', l(:label_x_member, :count => @course.members.count)) %>
</p>
<!--gcm-->
<p class="stats">
<%= content_tag('span', link_to("#{@course_activity_count[@course.id]}", course_path(@course)), :class => "info") %>
<%= content_tag('span', l(:label_x_activity, :count => @course_activity_count[@course.id])) %>
</p>
<!--gcm-->
<div class="buttons_for_course" style="margin-top:30px;margin-left:144px">
<span class="info"></span>
<% if(course_endTime_timeout? @course) %>
<span class="font_lighter">
课程学期已结束
</span>
<% else %>
<%= join_in_course_for_list(@course, User.current,['regular'])%>
<% end -%>
</div>
</div>
</div>
<div class="add-info">
<div class="main-language" style="margin-left: 30px;margin-top:-10px">
<%= content_tag "span","#{l(:label_duration_time)}:", :class => "course-font"%>
<%= get_course_term @course %>
</div>
</div>
<div class="add-info" style="margin-left: 30px; margin-top: -20px">
<%= content_tag "span", "#{l(:label_course_brief_introduction)}:", :class => "course-font" %>
<%= content_tag "div", course.short_description, :class => "brief_introduction", :title => course.short_description %>
</div>
<div class="tags">
<div id="tags">
<%= image_tag( "/images/sidebar/tags.png") %>
<%= render :partial => 'tags/tag_name', :locals => {:obj => @course,:object_flag => "9",:non_list_all => true }%>
</div>
</div>

View File

@ -17,21 +17,20 @@
<% object = [] %>
<% object << 'project' %>
<% object << 'course' %>
<%= error_messages_for object %>
<!--[form:project]-->
<% unless @project.new_record? %>
<p><%= render :partial=>"avatar/avatar_form",:locals=> {source:@project} %></p>
<!--[form:course]-->
<% unless @course.new_record? %>
<p><%= render :partial=>"avatar/avatar_form",:locals=> {source:@course} %></p>
<% end %>
<!-- <p><%= f.text_field :name, :required => true, :size => 60, :style => "width:490px;" %></p> -->
<p><label for="project_name" style="font-size: 13px;" ><%=l(:label_tags_course_name)%><span class="required", > *&nbsp;&nbsp;</span></label><input id="project_name" type="text" value="<%=@project.name%>" style="width:490px;" size="60" name="project[name]"></p>
<p><label for="course_name" style="font-size: 13px;" ><%=l(:label_tags_course_name)%><span class="required" > *&nbsp;&nbsp;</span></label><input id="course_name" type="text" value="<%=@course.name%>" style="width:490px;" size="60" name="course[name]"></p>
<!-- <p><%= f.text_field :identifier, :required => true, :size => 60, :style => "width:488px;", :disabled => @project.identifier_frozen?, :maxlength => Project::IDENTIFIER_MAX_LENGTH %>
<% unless @project.identifier_frozen? %>
<em class="info"><%= l(:text_length_between, :min => 1, :max => Project::IDENTIFIER_MAX_LENGTH) %> <%= l(:text_project_identifier_info).html_safe %></em>
<!-- <p><%= f.text_field :extra, :required => true, :size => 60, :style => "width:488px;", :disabled => @course.extra_frozen?, :maxlength => Project::IDENTIFIER_MAX_LENGTH %>
<% unless @course.extra_frozen? %>
<em class="info"><%= l(:text_length_between, :min => 1, :max => Project::IDENTIFIER_MAX_LENGTH) %> <%= l(:text_course_identifier_info).html_safe %></em>
<% end %></p> -->
<!-- added by bai 新增开课时间、结课时间、课时 -->
@ -292,48 +291,33 @@
<!-- added by huang -->
<!-- <p style="margin-left:-10px;"><%= m.text_field :password, :required => true, :size => 60, :style => "width:488px;margin-left: 10px;" %></p> -->
<p style="margin-left:-10px;"><label for="project[course]_password" style="font-size: 13px;" ><%=l(:label_new_course_password)%><span class="required"> *</span></label><input id="project_course_password" type="text" style="width:488px;margin-left: 10px;" value="<%=@project.course_extra.password if @project.course_extra %>" size="60" name="project[course][password]"></p>
<p style="margin-left:-10px;"><label for="course[course]_password" style="font-size: 13px;" ><%=l(:label_new_course_password)%><span class="required"> *</span></label><input id="course_course_password" type="text" style="width:488px;margin-left: 10px;" value="<%=@course.password %>" size="60" name="course[password]"></p>
<em class="info" style="margin-left:95px;"><%= l(:text_command) %></em>
<% end %>
<!-- <p style="margin-left:-10px;padding-right: 20px;"><%= f.text_area :description, :rows => 8, :class => 'wiki-edit', :style => "font-size:small;width:490px;margin-left:10px;" %></p> -->
<!--new added -->
<p style="margin-left:-20px;padding-right: 20px;"><label for="project_description" style="font-size: 13px;"><%=l(:label_new_course_description)%></label><span class="jstEditor"><textarea id="project_description" class="wiki-edit" style="font-size:small;width:490px;margin-left:10px;" rows="8" name="project[description]" cols="40" ><%=@project.description%></textarea></span></p>
<p style="margin-left:-20px;padding-right: 20px;"><label for="course_description" style="font-size: 13px;"><%=l(:label_new_course_description)%></label><span class="jstEditor"><textarea id="course_description" class="wiki-edit" style="font-size:small;width:490px;margin-left:10px;" rows="8" name="course[description]" cols="40" ><%=@course.description%></textarea></span></p>
<p style="margin-left:-10px;"><em style ="color: #888888;display: block;font-size: 90%;font-style: normal;"><%= f.check_box :is_public, :style => "margin-left:10px;" %><%= l(:label_public_info) %></em></p><!-- modified by bai -->
<p style="display:none;"><%= f.text_field :project_type, :value => 1 %></p>
<p style="margin-left:-10px;"><em style ="color: #888888;display: block;font-size: 90%;font-style: normal;"><%= f.check_box :is_public, :style => "margin-left:10px;" %><%= l(:label_course_public_info) %></em></p><!-- modified by bai -->
<p style="display:none;"><%= f.text_field :course_type, :value => 1 %></p>
<%= wikitoolbar_for 'project_description' %>
<%= wikitoolbar_for 'course_description' %>
<% @project.custom_field_values.each do |value| %>
<p><%= custom_field_tag_with_label :project, value %></p>
<% @course.custom_field_values.each do |value| %>
<p><%= custom_field_tag_with_label :course, value %></p>
<% end %>
<%= call_hook(:view_projects_form, :project => @project, :form => f) %>
<%= call_hook(:view_courses_form, :course => @course, :form => f) %>
<!--[eoform:project]-->
<!--[eoform:course]-->
<% unless @project.identifier_frozen? %>
<% unless @course.extra_frozen? %>
<% content_for :header_tags do %>
<%= javascript_include_tag 'project_identifier' %>
<%= javascript_include_tag 'course_identifier' %>
<% end %>
<% end %>
<% if !User.current.admin? && @project.inherit_members? && @project.parent && User.current.member_of?(@project.parent) %>
<%= javascript_tag do %>
$(document).ready(function() {
$("#project_inherit_members").change(function(){
if (!$(this).is(':checked')) {
if (!confirm("<%= escape_javascript(l(:text_own_membership_delete_confirmation)) %>")) {
$("#project_inherit_members").attr("checked", true);
}
}
});
});
<% end %>
<% end %>

View File

@ -0,0 +1,6 @@
<div class="box tabular" style="margin-right:10px;" >
<%= labelled_form_for @course do |f| %>
<%= render :partial => 'course_form', :locals => { :f => f } %>
<%= submit_tag l(:button_save) %>
<% end %>
</div>

View File

@ -21,7 +21,6 @@
</script>
<%= error_messages_for 'bid' %>
<!--[form:project]-->
<p><%= l(:label_homeworks_form_new_description) %></p>
<p><%= f.text_field :name, :required => true, :size => 60, :style => "width:490px;", :maxlength => Bid::NAME_LENGTH_LIMIT %></p>
@ -34,7 +33,7 @@
</p>
<p><%= f.select :is_evaluation, is_evaluation_option %>
</p>
<p><%= hidden_field_tag 'course_id', @project.id %>
<p><%= hidden_field_tag 'course_id', @course.id %>
</p>
<fieldset><legend><%= l(:label_attachment_plural) %></legend>
<p><%= render :partial => 'attachments/form', :locals => {:container => @homework} %></p>

View File

@ -0,0 +1,35 @@
<% if members.any? %>
<% members.each do |member| %>
<div class="well">
<% next if member.new_record? %>
<% unless member.created_on.nil? %>
<%= content_tag "p", "#{format_date(member.created_on)}#{l(:label_member_since)}", :class => "float_right member_since" %>
<% end %>
<%= member.user.nil? ? '' : (image_tag(url_to_avatar(member.user), :class => 'avatar')) %>
<% if @canShowCode %>
<%= content_tag "div", link_to(member.user.show_name, user_path(member.user)), :class => "nomargin avatar_name" %>
<% else %>
<%= content_tag "div", link_to(member.user.name, user_path(member.user)), :class => "nomargin avatar_name" %>
<% end %>
<!--teacher's code disapeared moified by huang-->
<% unless member.user.user_extensions.identity ==0 %>
<!-- added by bai 加学号 -->
<%if @canShowCode%>
<%= content_tag "p", "#{l(:label_bidding_user_studentcode)}#{' : '}#{member.user.user_extensions.student_id}", :class => "nomargin avatar_name" %>
<% end %>
<% end %>
<div class ="clear avatar_name"> &nbsp;
<p>
</p>
</div>
<%= call_hook(:view_projects_settings_members_table_row, { :course => @course, :member => member}) %>
</div>
<% end; reset_cycle %>
<div class="pagination"><%= pagination_links_full @obj_pages, @obj_count, :per_page_links => false %></div>
<% else %>
<p class="nodata">
<%= l(:label_no_data) %>
</p>
<% end %>

View File

@ -1,11 +1,11 @@
<%
id = "finish_course_#{project.id}"
display = (project.course_extra.teacher.id == User.current.id || User.current.admin?)
id = "finish_course_#{course.id}"
display = (course.teacher.id == User.current.id || User.current.admin?)
%>
<% if display #如果课程已结束%>
<% linkPath = course_endTime_timeout?(project) ? restartcourse_project_path(project) : finishcourse_project_path(project, format: :js) %>
<% desc = course_endTime_timeout?(project) ? '重启' : '关闭' %>
<% linkPath = course_endTime_timeout?(course) ? restartcourse_course_path(course) : finishcourse_course_path(course, format: :js) %>
<% desc = course_endTime_timeout?(course) ? '重启' : '关闭' %>
<%= link_to "#{desc}课程", linkPath, :remote => true, :method => :post, :id => id, :confirm => ("确定要#{desc}课程?") %>
<% else %>

View File

@ -0,0 +1,102 @@
<script>
var W3CDOM = document.createElement && document.getElementsByTagName;
window.onload = setMaxLength;
function setMaxLength() {
if (!W3CDOM) return;
var textareas = document.getElementsByTagName('textarea');
for (var i=0;i<textareas.length;i++) {
var textarea = textareas[i];
setMaxLengthItem(textareas[i]);
}
}
function setMaxLengthItem(textarea){
if (textarea.getAttribute('maxlength')) {
var counter = document.createElement('div');
counter.className = 'counter';
var counterClone = counter.cloneNode(true);
counterClone.innerHTML = '<span>0</span>/'+textarea.getAttribute('maxlength');
textarea.parentNode.insertBefore(counterClone,textarea.nextSibling);
textarea.relatedElement = counterClone.getElementsByTagName('span')[0];
textarea.onkeyup = textarea.onchange = checkMaxLength;
textarea.onkeyup();
}
}
function checkMaxLength() {
var maxLength = this.getAttribute('maxlength');
var currentLength = this.value.length;
if (currentLength > maxLength)
this.relatedElement.className = 'toomuch';
else
this.relatedElement.className = '';
this.relatedElement.firstChild.nodeValue = currentLength;
}
</script>
<!-- fq -->
<% reply_allow = JournalsForMessage.create_by_user? User.current %>
<h3><%= l(:label_user_response) %></h3>
<% if !User.current.logged?%>
<div style="font-size: 14px;margin:20px;">
<%= l(:label_user_login_tips) %>
<%= link_to l(:label_user_login_new), signin_path %>
<hr/>
</div>
<% else %>
<div style="width: 80%; margin-left:10%;">
<%= form_for('new_form', :method => :post,
:url => {:controller => 'words', :action => 'leave_course_message'}) do |f|%>
<%= f.text_area 'course_message', :rows => 3, :cols => 65,
:placeholder => "#{l(:label_welcome_my_respond)}",
:style => "resize: none; width: 98%",
:class => 'noline'%>
<%= submit_tag l(:button_leave_meassge), :name => nil , :class => "enterprise" , :style => "display: block; float: right; margin-right: 1%; margin-top: 1px;"%>
<% end %>
</div>
<% end %>
<div style="clear: both;"></div>
<% if @jour.size >0 %>
<ul class="message-for-user">
<% for journal in @jour%>
<li id='word_li_<%=journal.id.to_s%>' class="outer-message-for-user">
<span class="portrait"><%= image_tag(url_to_avatar(journal.user), :class => "avatar") %></span>
<span class="body">
<span class="user"><%= link_to journal.user, user_path(journal.user)%></span>
<%= textilizable journal.notes%>
<span class="font_lighter"> <%= l :label_update_time %>: <%= format_time journal.created_on %></span>
<% id = 'course_respond_form_'+journal.id.to_s%>
<span>
<% if reply_allow %>
<%= link_to l(:label_projects_feedback_respond),'#',
{:focus => 'course_respond',
:onclick => "toggleAndSettingWordsVal($('##{id}'),
$('##{id} textarea'),
'#{l(:label_reply_plural)} #{journal.user.name}: ');
return false;"} %>
<% end %>
</span>
</span>
<div style="clear: both;"></div>
<% if reply_allow %>
<div id='<%= id %>' class="respond-form">
<%= render :partial => 'words/new_respond', :locals => {:journal => journal, :m_reply_id => journal} %>
</div>
<% end %>
<div style="clear: both;"></div>
<div>
<%= render :partial => "words/journal_reply", :locals => {:journal => journal } %>
</div>
</li>
<% end %>
</ul>
<% end %>
<div class="pagination" style="float:left;">
<ul>
<%= pagination_links_full @feedback_pages %>
</ul>
</div>

View File

@ -0,0 +1 @@
<h3>文件列表</h3>

View File

@ -0,0 +1,12 @@
<% if @save_flag %>
<% if Rails.env.development? %>
console.debug('课程修改成功:结束时间改为<%=Course.find_by_extra(@course.extra).try(:endup_time)%>');
<% end %>
$('#content-title-top-div').html("<%= j(render partial: 'users/my_course_ex', :locals => {:memberships => @memberships,:user=>@user,
:memberships_doing=>@memberships_doing,:memberships_done=>@memberships_done} )%>")
//$('#finish_course_ <%=@course.id%>').replaceWith("<%= j(render partial: 'courses/set_course_time', :locals => {:course => @course} )%>")
<% else %>
alert('权限不足,设置失败,请在论坛提交问题,等待管理员处理。');
<% end %>

View File

@ -7,8 +7,8 @@
<!-- fq -->
<!--modified by huang-->
<div class="content-title-top">
<% if User.current.logged? && (User.current.admin? || (!Member.where('user_id = ? and project_id = ?', User.current.id, @project.id).first.nil? && (Member.where('user_id = ? and project_id = ?', User.current.id, @project.id).first.roles&Role.where(id: [3, 4, 7, 9] )).size >0))%>
<%= link_to(l(:label_course_homework_new), {:controller => 'projects', :action => 'new_homework'}, :class => 'icon icon-add') %>
<% if User.current.logged? && (User.current.admin? || (!Member.where('user_id = ? and course_id = ?', User.current.id, @course.id).first.nil? && (Member.where('user_id = ? and course_id = ?', User.current.id, @course.id).first.roles&Role.where(id: [3, 4, 7, 9] )).size >0))%>
<%= link_to(l(:label_course_homework_new), {:controller => 'courses', :action => 'new_homework'}, :class => 'icon icon-add') %>
<% end %>
</div>
<div id="bid-show">
@ -18,7 +18,7 @@
<div id="OpenWindow">
<div id="signup-ct">
<div id="OpenWindow-header">
<h1> 课程: <%= @project.name%> </h1>
<h1> 课程: <%= @course.name%> </h1>
<p id='bid-desc'> 上传作业 </p>
<a href="javascript:void(0);" class="modal_close"></a>
</div>

View File

@ -0,0 +1,67 @@
<% content_for :header_tags do %>
<%= auto_discovery_link_tag(:atom, {:action => 'index', :format => 'atom', :key => User.current.rss_key}) %>
<% end %>
<div class="top-content">
<%= form_tag(:controller => 'courses', :action => 'search', :method => :get) do %>
<table width="940px">
<tr>
<td class="info_font" style="width: 220px; color: #15bccf"><%= l(:label_course_practice) %></td>
<td class="location-list"><strong><%= l(:label_user_location) %> :</strong></td>
<td rowspan="2">
<% if User.current.logged?%>
<% if User.current.user_extensions.identity == 0 %>
<%= link_to(l(:label_course_new), {:controller => 'courses', :action => 'new'},
:class => 'icon icon-add') if User.current.allowed_to?(:add_course,nil, :global => true) %></td>
<% end %>
<% end %>
</td>
<td rowspan="2" >
<div class="course-search" style="float: right">
<%= text_field_tag 'name', params[:name], :size => 30 %>
<%= submit_tag l(:label_search), :class => "enterprise", :name => nil %>
</div>
</td>
</tr>
<tr>
<td style="padding-left: 8px"><a><%= link_to request.host()+"/course", :controller => 'courses', :action => 'index', :course_type => 1 %> </a></td>
<td ><%=link_to l(:field_homepage), home_path %> > <%=link_to l(:label_course_practice), :controller => 'courses', :action => 'index', :course_type => 1 %></td>
</tr>
</table>
<% end %>
</div>
<%= sort_course(@s_type, @school_id)%>
<div id="courses-index">
<%if @courses%>
<%= render_course_hierarchy(@courses)%>
<%end%>
</div>
<div class="pagination">
<ul>
<%= pagination_links_full @course_pages, @course_count %>
</ul>
</div>
<% if User.current.logged? %>
<p style="text-align:right;">
<span class="my-course"><%= l(:label_my_course) %></span>
</p>
<% end %>
<% other_formats_links do |f| %>
<%= f.link_to 'Atom', :url => {:key => User.current.rss_key} %>
<% end %>
<% content_for :sidebar do %>
<%= form_tag({}, :method => :get) do %>
<h3><%= l(:label_project_plural) %></h3>
<label for="closed"><%= check_box_tag 'closed', 1, params[:closed] %> <%= l(:label_show_closed_projects) %></label>
<p>
<%= submit_tag l(:button_apply), :class => 'button-small', :name => nil %>
</p>
<% end %>
<% end %>
<% html_title(l(:label_new_course)) -%>

View File

@ -0,0 +1,10 @@
<div class="member_header">
<p>
<%= @subPage_title %>
</p>
</div>
<div class="member_content">
<%= error_messages_for 'member' %>
<%= render :partial => @render_file, :locals => {:members => @members} %>
</div>

View File

@ -0,0 +1,9 @@
<%= labelled_form_for @course do |f| %>
<h3><%=l(:label_course_new)%></h3>
<div class="box tabular">
<%= render :partial => 'course_form', :locals => { :f => f } %>
<span style="padding-left: 60px"><%= submit_tag l(:button_create), :class => "enterprise"%></span>
<!-- <%= submit_tag l(:button_create_and_continue), :name => 'course_continue' %> -->
<%= javascript_tag "$('#course_name').focus();" %>
</div>
<% end %>

View File

@ -1,6 +1,6 @@
<h3><%=l(:label_course_new_homework)%></h3>
<%= labelled_form_for @homework, :url => {:controller => 'bids', :action => 'create_homework'} do |f| %>
<%= labelled_form_for @homework, :url => {:controller => 'bids', :action => 'create_homework',:course_id=>@course.id} do |f| %>
<div class="box tabular">
<%= render :partial => 'homework_form', :locals => { :f => f } %>
<%= submit_tag l(:button_create), :class => "enterprise" %>

Some files were not shown because too many files have changed in this diff Show More