Merge branch 'develop' into Branch_szzh
Conflicts: app/controllers/users_controller.rb app/models/course_activity.rb app/views/users/show.html.erb db/schema.rb
This commit is contained in:
commit
4b5cd6db9d
|
|
@ -29,3 +29,4 @@ vendor/cache
|
|||
/public/images/avatars
|
||||
/public/files
|
||||
/tags
|
||||
/config/initializers/gitlab_config.rb
|
||||
|
|
|
|||
22
Gemfile
22
Gemfile
|
|
@ -1,4 +1,4 @@
|
|||
source 'http://ruby.taobao.org'
|
||||
source 'https://ruby.taobao.org'
|
||||
#source 'http://ruby.sdutlinux.org/'
|
||||
|
||||
unless RUBY_PLATFORM =~ /w32/
|
||||
|
|
@ -6,7 +6,8 @@ unless RUBY_PLATFORM =~ /w32/
|
|||
gem 'iconv'
|
||||
end
|
||||
|
||||
gem 'grack', path:'./lib/grack'
|
||||
gem 'grack', path:'lib/grack'
|
||||
gem 'gitlab', path: 'lib/gitlab-cli'
|
||||
gem 'rest-client'
|
||||
gem "mysql2", "= 0.3.18"
|
||||
gem 'redis-rails'
|
||||
|
|
@ -28,14 +29,27 @@ gem 'ruby-ole'
|
|||
gem 'rails_kindeditor',path:'lib/rails_kindeditor'
|
||||
#gem "rmagick", ">= 2.0.0"
|
||||
gem 'binding_of_caller'
|
||||
gem 'chinese_pinyin'
|
||||
# gem 'sunspot_rails', '~> 1.3.3'
|
||||
# gem 'sunspot_solr'
|
||||
# gem 'sunspot'
|
||||
# gem 'progress_bar'
|
||||
gem 'ansi'
|
||||
|
||||
gem 'kaminari'
|
||||
gem 'elasticsearch-model'
|
||||
gem 'elasticsearch-rails'
|
||||
|
||||
group :development do
|
||||
gem 'grape-swagger'
|
||||
gem 'better_errors', '~> 1.1.0'
|
||||
gem 'rack-mini-profiler', '~> 0.9.3'
|
||||
if RUBY_PLATFORM =~ /w32/
|
||||
gem 'win32console'
|
||||
end
|
||||
end
|
||||
|
||||
group :development, :test do
|
||||
group :development, :test do
|
||||
unless RUBY_PLATFORM =~ /w32/
|
||||
gem 'pry-rails'
|
||||
if RUBY_VERSION >= '2.0.0'
|
||||
|
|
@ -58,7 +72,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
|
||||
|
|
|
|||
|
|
@ -272,7 +272,7 @@ module Mobile
|
|||
params do
|
||||
requires :token,type:String
|
||||
requires :course_id,type:Integer,desc: '课程id'
|
||||
optional :name,type:String,desc:'学生的姓名或者昵称或者学号可能包含的字符'
|
||||
optional :name,type:String,desc:'学生的姓名或者登录名或者学号可能包含的字符'
|
||||
end
|
||||
get ":course_id/members" do
|
||||
cs = CoursesService.new
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ module Mobile
|
|||
desc "用户搜索"
|
||||
params do
|
||||
requires :name, type: String, desc: '用户名关键字'
|
||||
requires :search_by, type: String,desc: '搜索依据:0 昵称,1 用户名,2 邮箱,3 昵称和姓名'
|
||||
requires :search_by, type: String,desc: '搜索依据:0 登录名,1 用户名,2 邮箱,3 登录名和姓名'
|
||||
optional :is_search_assitant,type:Integer,desc:'是否搜索注册用户来作为助教'
|
||||
optional :course_id,type:Integer,desc: '课程id,搜索注册用户不为该课程教师的其他用户'
|
||||
optional :user_id,type:Integer,desc:'用户id'
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
# Place all the behaviors and hooks related to the matching controller here.
|
||||
# All this logic will automatically be available in application.js.
|
||||
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
# Place all the behaviors and hooks related to the matching controller here.
|
||||
# All this logic will automatically be available in application.js.
|
||||
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
# Place all the behaviors and hooks related to the matching controller here.
|
||||
# All this logic will automatically be available in application.js.
|
||||
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
# Place all the behaviors and hooks related to the matching controller here.
|
||||
# All this logic will automatically be available in application.js.
|
||||
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
# Place all the behaviors and hooks related to the matching controller here.
|
||||
# All this logic will automatically be available in application.js.
|
||||
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
# Place all the behaviors and hooks related to the matching controller here.
|
||||
# All this logic will automatically be available in application.js.
|
||||
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
# Place all the behaviors and hooks related to the matching controller here.
|
||||
# All this logic will automatically be available in application.js.
|
||||
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
# Place all the behaviors and hooks related to the matching controller here.
|
||||
# All this logic will automatically be available in application.js.
|
||||
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
# Place all the behaviors and hooks related to the matching controller here.
|
||||
# All this logic will automatically be available in application.js.
|
||||
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
// Place all the styles related to the org_courses controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
// Place all the styles related to the org_document_comment controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
// Place all the styles related to the OrgMember controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
// Place all the styles related to the org_projects controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
// Place all the styles related to the org_subfields controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
// Place all the styles related to the organizations controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
// Place all the styles related to the shield_activities controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
// Place all the styles related to the subfield_subdomain_dirs controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
// Place all the styles related to the SystemMessages controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
||||
|
|
@ -21,7 +21,6 @@ class AccountController < ApplicationController
|
|||
|
||||
# prevents login action to be filtered by check_if_login_required application scope filter
|
||||
skip_before_filter :check_if_login_required
|
||||
|
||||
# Login request and validation
|
||||
def login
|
||||
if request.get?
|
||||
|
|
|
|||
|
|
@ -79,6 +79,11 @@ class AdminController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
# 系统消息
|
||||
def messages
|
||||
@admin_messages = SystemMessage.new
|
||||
end
|
||||
|
||||
def plugins
|
||||
@plugins = Redmine::Plugin.all
|
||||
end
|
||||
|
|
@ -341,11 +346,16 @@ class AdminController < ApplicationController
|
|||
#学校列表
|
||||
def schools
|
||||
@school_name = params[:school_name]
|
||||
if @school_name
|
||||
if @school_name && @school_name != ''
|
||||
@schools = School.where("name like '%#{@school_name}%'")
|
||||
else
|
||||
@schools = School.all
|
||||
elsif @school_name.nil?
|
||||
@schools = []
|
||||
else @school_name && @school_name == ' '
|
||||
@schools = School.where('1=1')
|
||||
end
|
||||
@school_count = @schools.count
|
||||
@school_pages = Paginator.new @school_count, 100, params['page'] || 1
|
||||
@schools = paginateHelper @schools,100
|
||||
respond_to do |format|
|
||||
format.html
|
||||
end
|
||||
|
|
|
|||
|
|
@ -38,7 +38,8 @@ class ApplicationController < ActionController::Base
|
|||
protect_from_forgery
|
||||
def handle_unverified_request
|
||||
super
|
||||
cookies.delete(autologin_cookie_name)
|
||||
raise(ActionController::InvalidAuthenticityToken)
|
||||
# cookies.delete(autologin_cookie_name)
|
||||
end
|
||||
|
||||
before_filter :find_first_page
|
||||
|
|
@ -311,7 +312,8 @@ class ApplicationController < ActionController::Base
|
|||
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)
|
||||
# allowed = User.current.allowed_to?({:controller => ctrl, :action => action}, @project || @projects, :global => global)
|
||||
allowed = true
|
||||
end
|
||||
allowed
|
||||
end
|
||||
|
|
@ -381,6 +383,11 @@ class ApplicationController < ActionController::Base
|
|||
if allowed
|
||||
true
|
||||
else
|
||||
if params[:action] == 'show'
|
||||
#更新申请结果反馈消息的状态
|
||||
messages = CourseMessage.where("course_message_type =? and course_id =? and user_id =? and viewed =?", 'CourseRequestDealResult', @course.id, User.current.id, false)
|
||||
messages.update_all(:viewed => true)
|
||||
end
|
||||
if @course && @course.archived?
|
||||
render_403 :message => :notice_not_authorized_archived_project
|
||||
else
|
||||
|
|
@ -412,6 +419,8 @@ class ApplicationController < ActionController::Base
|
|||
@project = Project.find(params[:project_id])
|
||||
elsif params[:course_id]
|
||||
@course = Course.find(params[:course_id])
|
||||
elsif params[:org_subfield_id]
|
||||
@org_subfield = OrgSubfield.find(params[:org_subfield_id])
|
||||
end
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
|
|
@ -657,7 +666,8 @@ class ApplicationController < ActionController::Base
|
|||
if api_request?
|
||||
logger.error "Form authenticity token is missing or is invalid. API calls must include a proper Content-type header (text/xml or text/json)."
|
||||
end
|
||||
render_error "Invalid form authenticity token."
|
||||
#render_error "Invalid form authenticity token."
|
||||
redirect_to signin_path(:login=>true)
|
||||
end
|
||||
|
||||
def render_feed(items, options={})
|
||||
|
|
@ -756,7 +766,7 @@ class ApplicationController < ActionController::Base
|
|||
|
||||
# Returns a string that can be used as filename value in Content-Disposition header
|
||||
def filename_for_content_disposition(name)
|
||||
request.env['HTTP_USER_AGENT'] =~ %r{MSIE} ? ERB::Util.url_encode(name) : name
|
||||
request.env['HTTP_USER_AGENT'] =~ %r{MSIE|Trident} ? ERB::Util.url_encode(name) : name
|
||||
end
|
||||
|
||||
def api_request?
|
||||
|
|
|
|||
|
|
@ -0,0 +1,157 @@
|
|||
#coding=utf-8
|
||||
|
||||
class AtController < ApplicationController
|
||||
respond_to :json
|
||||
|
||||
def show
|
||||
@logger = Logger.new(Rails.root.join('log', 'at.log').to_s)
|
||||
users = find_at_users(params[:type], params[:id])
|
||||
@users = users
|
||||
@users = users.uniq { |u| u.id }.delete_if { |u| u.id == User.current.id }.sort{|x,y| to_pinyin(x.show_name) <=> to_pinyin(y.show_name)} if users
|
||||
end
|
||||
|
||||
private
|
||||
def to_pinyin(s)
|
||||
Pinyin.t(s).downcase
|
||||
end
|
||||
|
||||
def find_at_users(type, id)
|
||||
@logger.info("#{type}, #{id}")
|
||||
case type
|
||||
when "Issue"
|
||||
find_issue(id)
|
||||
when 'Project'
|
||||
find_project(id)
|
||||
when 'Course'
|
||||
find_course(id)
|
||||
when 'Activity', 'CourseActivity', 'ForgeActivity','UserActivity', 'OrgActivity','PrincipalActivity'
|
||||
find_activity(id, type)
|
||||
when 'Attachment'
|
||||
find_attachment(id)
|
||||
when 'Message'
|
||||
find_message(id)
|
||||
when 'HomeworkCommon'
|
||||
find_homework(id)
|
||||
when 'Topic'
|
||||
find_topic(id)
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
def find_topic(id)
|
||||
|
||||
end
|
||||
|
||||
def find_issue(id)
|
||||
#1. issues list persons
|
||||
#2. project persons
|
||||
issue = Issue.find(id)
|
||||
journals = issue.journals
|
||||
at_persons = journals.map(&:user) + issue.project.users
|
||||
at_persons.uniq { |u| u.id }.delete_if { |u| u.id == User.current.id }
|
||||
end
|
||||
|
||||
def find_project(id)
|
||||
return [] if id<0
|
||||
at_persons = Project.find(id).users
|
||||
at_persons.delete_if { |u| u.id == User.current.id }
|
||||
end
|
||||
|
||||
def find_course(id)
|
||||
at_persons = Course.find(id).users
|
||||
at_persons.delete_if { |u| u.id == User.current.id }
|
||||
end
|
||||
|
||||
def find_activity(id, type)
|
||||
|
||||
## 基本上是本类型中的 加上所属类型的用户
|
||||
case type
|
||||
when 'Activity'
|
||||
activity = Activity.find(id)
|
||||
(find_at_users(activity.act_type, activity.act_id) ||[]) +
|
||||
(find_at_users(activity.activity_container_type, activity.activity_container_id) || [])
|
||||
when 'CourseActivity'
|
||||
activity = CourseActivity.find(id)
|
||||
(find_at_users(activity.course_act_type, activity.course_act_id) || []) + (find_course(activity.course.id) || [])
|
||||
when 'ForgeActivity'
|
||||
activity = ForgeActivity.find(id)
|
||||
(find_at_users(activity.forge_act_type, activity.forge_act_id) ||[]) +
|
||||
(find_project(activity.project_id) || [])
|
||||
when 'UserActivity'
|
||||
activity = UserActivity.find(id)
|
||||
(find_at_users(activity.act_type, activity.act_id) || []) +
|
||||
(find_at_users(activity.container_type, activity.container_id) || [])
|
||||
when 'OrgActivity'
|
||||
activity = OrgActivity.find(id)
|
||||
(find_at_users(activity.org_act_type, activity.org_act_id) || []) +
|
||||
(find_at_users(activity.container_type, activity.container_id) || [])
|
||||
when 'PrincipalActivity'
|
||||
activity = PrincipalActivity.find(id)
|
||||
find_at_users(activity.principal_act_type, activity.principal_act_id)
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
#作业应该是关联课程,取课程的用户列表
|
||||
def find_homework(id)
|
||||
homework = HomeworkCommon.find(id)
|
||||
find_course(homework.course_id)
|
||||
end
|
||||
|
||||
def find_attachment(id)
|
||||
attachment = Attachment.find(id)
|
||||
find_at_users(attachment.container_type, attachment.container_id)
|
||||
end
|
||||
|
||||
#Message
|
||||
def find_message(id)
|
||||
message = Message.find(id)
|
||||
at_persons = message.board.messages.map(&:author)
|
||||
(at_persons || []) + (find_project(message.board.project_id)||[])
|
||||
end
|
||||
|
||||
#News
|
||||
def find_news(id)
|
||||
find_project(News.find(id).project_id)
|
||||
end
|
||||
|
||||
#JournalsForMessage
|
||||
def find_journals_for_message(id)
|
||||
jounrnal = JournalsForMessage.find(id)
|
||||
find_at_users(jounrnal.jour_type, jounrnal.jour_id)
|
||||
end
|
||||
|
||||
#Poll
|
||||
def find_poll(id)
|
||||
end
|
||||
|
||||
#Journal
|
||||
def find_journal(id)
|
||||
journal = Journal.find(id)
|
||||
find_at_users(journal.journalized_type, journal.journalized_id)
|
||||
end
|
||||
|
||||
#Document
|
||||
def find_document(id)
|
||||
find_project(Document.find(id).project_id)
|
||||
end
|
||||
|
||||
#ProjectCreateInfo
|
||||
def find_project_create_info(id)
|
||||
|
||||
end
|
||||
|
||||
#Principal
|
||||
def find_principal(id)
|
||||
|
||||
end
|
||||
|
||||
#BlogComment
|
||||
def find_blog_comment(id)
|
||||
blog = BlogComment.find(id).blog
|
||||
blog.users
|
||||
end
|
||||
|
||||
end
|
||||
|
|
@ -185,7 +185,6 @@ class AttachmentsController < ApplicationController
|
|||
end
|
||||
@attachment.filename = params[:filename].presence || Redmine::Utils.random_hex(16)
|
||||
saved = @attachment.save
|
||||
|
||||
respond_to do |format|
|
||||
format.js
|
||||
format.api {
|
||||
|
|
@ -198,12 +197,43 @@ class AttachmentsController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def upload_attachment_version
|
||||
@flag = false
|
||||
Attachment.transaction do
|
||||
@old_attachment = Attachment.find params[:old_attachment_id]
|
||||
#取出当前上传的文件
|
||||
@attachment = Attachment.find(params[:attachments ].first[1][:attachment_id])
|
||||
#将需要修改的记录保存到历史记录
|
||||
@history = AttachmentHistory.new
|
||||
@history.attributes = @old_attachment.attributes.dup.except("id")
|
||||
@history.attachment_id = params[:old_attachment_id]
|
||||
#需要更新版本号,需要拿到原来该文件最大的历史版本号
|
||||
@old_history = @old_attachment.attachment_histories.reorder('version desc').first
|
||||
@history.version = @old_history.nil? ? 1 : @old_history.version + 1
|
||||
@history.save #历史记录保存完毕
|
||||
#将最新保存的记录 数据替换到 需要修改的文件记录
|
||||
@old_attachment.attributes = @attachment.attributes.dup.except("id","container_id","container_type","is_public")
|
||||
@old_attachment.save
|
||||
#删除当前记录
|
||||
@attachment.delete
|
||||
@flag = true
|
||||
end
|
||||
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
if @attachment.container.respond_to?(:init_journal)
|
||||
@attachment.container.init_journal(User.current)
|
||||
end
|
||||
if @attachment.container
|
||||
@attachment.container.attachments.delete(@attachment)
|
||||
if @attachment.container_type == "Issue"
|
||||
@attachment.destroy
|
||||
else
|
||||
@attachment.container.attachments.delete(@attachment)
|
||||
end
|
||||
else
|
||||
@attachment.destroy
|
||||
end
|
||||
|
|
@ -227,6 +257,8 @@ class AttachmentsController < ApplicationController
|
|||
format.js
|
||||
elsif @attachment.container.is_a?(Message)
|
||||
format.html { redirect_to_referer_or new_board_message_path(@attachment.container) }
|
||||
elsif @attachment.container.is_a?(BlogComment)
|
||||
format.html { redirect_to_referer_or user_blog_blog_comment_path(:user_id=>@attachment.container.author.id,:blog_id=>@attachment.container.blog_id,:id=>@attachment.container.id)}
|
||||
elsif @course.nil?
|
||||
format.html { redirect_to_referer_or forum_memo_path(@attachment.container.forum, @attachment.container) }
|
||||
else
|
||||
|
|
@ -238,6 +270,10 @@ class AttachmentsController < ApplicationController
|
|||
format.html { redirect_to_referer_or respond_path(@attachment.container) }
|
||||
elsif !@attachment.container.nil? && @attachment.container.is_a?(PhoneAppVersion)
|
||||
format.html { redirect_to_referer_or mobile_version_path }
|
||||
elsif !@attachment.container.nil? && @attachment.container.is_a?(OrgSubfield)
|
||||
format.html {redirect_to_referer_or org_subfield_files_path(@attachment.container)}
|
||||
elsif !@attachment.container.nil? && @attachment.container.is_a?(OrgDocumentComment)
|
||||
format.html {redirect_to_referer_or org_document_comment_path(@attachment.container)}
|
||||
else
|
||||
if @project.nil?
|
||||
format.html { redirect_to_referer_or forum_memo_path(@attachment.container.forum, @attachment.container) }
|
||||
|
|
@ -249,7 +285,7 @@ class AttachmentsController < ApplicationController
|
|||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def delete_homework
|
||||
@bid = @attachment.container.bid
|
||||
# Make sure association callbacks are called
|
||||
|
|
@ -312,13 +348,13 @@ class AttachmentsController < ApplicationController
|
|||
end
|
||||
|
||||
respond_to do |format|
|
||||
format.js
|
||||
format.js
|
||||
end
|
||||
rescue NoMethodError
|
||||
@save_flag = false
|
||||
@save_message = [] << l(:error_attachment_empty)
|
||||
respond_to do |format|
|
||||
format.js
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -434,6 +470,46 @@ class AttachmentsController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def add_exist_file_to_org_subfield
|
||||
file = Attachment.find(params[:file_id])
|
||||
org_subfields = params[:org_subfields][:org_subfield]
|
||||
@message = ""
|
||||
org_subfields.each do |org_subfield|
|
||||
s = OrgSubfield.find(org_subfield)
|
||||
if s.attachments.include?file
|
||||
if @message && @message == ""
|
||||
@message += l(:label_resource_subfield_prompt) + c.name + l(:label_contain_resource) + file.filename + l(:label_quote_resource_failed)
|
||||
next
|
||||
else
|
||||
@message += "<br/>" + l(:label_resource_subfield_prompt) + c.name + l(:label_contain_resource) + file.filename + l(:label_quote_resource_failed)
|
||||
next
|
||||
end
|
||||
end
|
||||
attach_copied_obj = file.copy
|
||||
attach_copied_obj.tag_list.add(file.tag_list) # tag关联
|
||||
attach_copied_obj.container = s
|
||||
attach_copied_obj.created_on = Time.now
|
||||
attach_copied_obj.author_id = User.current.id
|
||||
attach_copied_obj.copy_from = file.copy_from.nil? ? file.id : file.copy_from
|
||||
if attach_copied_obj.attachtype == nil
|
||||
attach_copied_obj.attachtype = 4
|
||||
end
|
||||
@obj = s
|
||||
@save_flag = attach_copied_obj.save
|
||||
@save_message = attach_copied_obj.errors.full_messages
|
||||
update_quotes attach_copied_obj
|
||||
end
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
rescue NoMethodError
|
||||
@save_flag = false
|
||||
@save_message = [] << l(:label_resource_subfield_empty_select)
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def update_quotes attachment
|
||||
if attachment.copy_from
|
||||
attachments = Attachment.find_by_sql("select * from attachments where copy_from = #{attachment.copy_from} or id = #{attachment.copy_from}")
|
||||
|
|
@ -448,6 +524,15 @@ class AttachmentsController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
#找到文件的所有的历史版本
|
||||
def attachment_versions
|
||||
@attachment = Attachment.find(params[:id])
|
||||
@attachment_histories = @attachment.attachment_histories
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def find_project
|
||||
@attachment = Attachment.find(params[:id])
|
||||
|
|
@ -515,7 +600,7 @@ private
|
|||
|
||||
def has_login
|
||||
unless @attachment && @attachment.container_type == "PhoneAppVersion"
|
||||
render_403 unless User.current.logged?
|
||||
render_403 if !User.current.logged? && !(@attachment.container_type == 'OrgSubfield' && @attachment.container.organization.allow_guest_download) && !(@attachment.container_type == 'OrgDocumentComment' && @attachment.container.organization.allow_guest_download)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ class AvatarController < ApplicationController
|
|||
unless request.content_type == 'application/octet-stream'
|
||||
@source_type = params[:source_type]
|
||||
@source_id = params[:source_id]
|
||||
@temp_file = params[:avatar][:image]
|
||||
@temp_file = params[:avatar][:image]
|
||||
@image_file = @temp_file.original_filename
|
||||
else
|
||||
unless request.raw_post.nil?
|
||||
|
|
@ -23,7 +23,7 @@ class AvatarController < ApplicationController
|
|||
#image_file.force_encoding("UTF-8") if filename.respond_to?(:force_encoding)
|
||||
else
|
||||
@image_file=params[:filename]
|
||||
end
|
||||
end
|
||||
@temp_file = StringIO.new(@temp_file)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -0,0 +1,160 @@
|
|||
class BlogCommentsController < ApplicationController
|
||||
include ApplicationHelper
|
||||
before_filter :find_user
|
||||
def index
|
||||
|
||||
end
|
||||
def create
|
||||
if User.current.logged?
|
||||
@article = BlogComment.new
|
||||
@article.author = User.current
|
||||
@article.blog_id = params[:blog_id]
|
||||
@article.safe_attributes = params[:blog_comment]
|
||||
if request.post?
|
||||
@article.save_attachments(params[:attachments])
|
||||
if @article.save
|
||||
# 更新kindeditor上传的图片资源所有者
|
||||
# if params[:asset_id]
|
||||
# ids = params[:asset_id].split(',')
|
||||
# update_kindeditor_assets_owner ids,@article.id,OwnerTypeHelper::BLOGCOMMENT
|
||||
# end
|
||||
render_attachment_warning_if_needed(@article)
|
||||
else
|
||||
end
|
||||
redirect_to user_blogs_path(:user_id=>params[:user_id])
|
||||
else
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
render :layout => 'new_base_user'
|
||||
}
|
||||
end
|
||||
end
|
||||
else
|
||||
redirect_to signin_path
|
||||
end
|
||||
end
|
||||
def new
|
||||
respond_to do |format|
|
||||
format.html {render :layout=>'new_base_user'}
|
||||
end
|
||||
end
|
||||
def show
|
||||
@article = BlogComment.find(params[:id])
|
||||
respond_to do |format|
|
||||
format.html {render :layout=>'new_base_user'}
|
||||
end
|
||||
end
|
||||
def update
|
||||
@article = BlogComment.find(params[:id])
|
||||
@article.safe_attributes = params[:blog_comment]
|
||||
@article.save_attachments(params[:attachments])
|
||||
if @article.save
|
||||
render_attachment_warning_if_needed(@article)
|
||||
else
|
||||
end
|
||||
if params[:in_act]
|
||||
redirect_to user_path(params[:user_id])
|
||||
else
|
||||
if params[:is_homepage]
|
||||
redirect_to user_blogs_path(params[:user_id])
|
||||
else
|
||||
redirect_to user_blog_blog_comment_path(:user_id=>params[:user_id],:blog_id=>params[:blog_id],:id=>params[:id])
|
||||
end
|
||||
end
|
||||
end
|
||||
def destroy
|
||||
@article = BlogComment.find(params[:id])
|
||||
if @article.parent_id.nil? #如果是文章被删,那么跳转到用户博客界面,如果带了course_id过来,那么就要跳转到课程首页
|
||||
if params[:course_id] #如果带了课程id过来,说明这是课程大纲,不要删除,只需取消课程大纲就ok了
|
||||
@course = Course.find(params[:course_id])
|
||||
@course.outline = 0
|
||||
@course.save
|
||||
redirect_to course_path(:id=>params[:course_id])
|
||||
else
|
||||
@article.children.delete
|
||||
@article.delete
|
||||
redirect_to user_blogs_path(:user_id=>User.current)
|
||||
end
|
||||
|
||||
else#如果是回复被删,
|
||||
if params[:course_id] #如果带了course_id过来了,那么这是要跳到课程大纲去的
|
||||
@article.delete
|
||||
redirect_to syllabus_course_path(:id=>params[:course_id])
|
||||
else
|
||||
root = @article.root
|
||||
@article.delete
|
||||
redirect_to user_blog_blog_comment_path(:user_id=>root.author_id,:blog_id=>root.blog_id,:id=>root.id)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
@article = BlogComment.find(params[:id])
|
||||
respond_to do |format|
|
||||
format.html {render :layout=>'new_base_user'}
|
||||
end
|
||||
end
|
||||
|
||||
def quote
|
||||
@blogComment = BlogComment.find(params[:id])
|
||||
@subject = @blogComment.title
|
||||
@subject = "RE: #{@subject}" unless @subject.starts_with?('RE:')
|
||||
|
||||
@content = "> #{ll(Setting.default_language, :text_user_wrote, @blogComment.author.realname)}\n> "
|
||||
@temp = BlogComment.new
|
||||
@course_id = params[:course_id]
|
||||
@temp.content = "<blockquote>#{ll(Setting.default_language, :text_user_wrote, @blogComment.author.realname)} <br/>#{@blogComment.content.html_safe}</blockquote>".html_safe
|
||||
respond_to do | format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
#回复
|
||||
def reply
|
||||
if params[:in_user_center]
|
||||
@in_user_center = true
|
||||
end
|
||||
@article = BlogComment.find(params[:id]).root
|
||||
@quote = params[:quote][:quote]
|
||||
@blogComment = BlogComment.new
|
||||
@blogComment.author = User.current
|
||||
@blogComment.blog = Blog.find(params[:blog_id])
|
||||
params[:blog_comment][:sticky] = params[:blog_comment][:sticky] || 0
|
||||
params[:blog_comment][:locked] = params[:blog_comment][:locked] || 0
|
||||
@blogComment.safe_attributes = params[:blog_comment]
|
||||
@blogComment.content = @quote + @blogComment.content
|
||||
@blogComment.title = "RE: #{@article.title}" unless params[:blog_comment][:title]
|
||||
@article.children << @blogComment
|
||||
@article.save
|
||||
# @article.update_attribute(:updated_on, @blogComment.updated_on)
|
||||
@user_activity_id = params[:user_activity_id]
|
||||
user_activity = UserActivity.where("act_type='BlogComment' and act_id =#{@article.id}").first
|
||||
if user_activity
|
||||
user_activity.updated_at = Time.now
|
||||
user_activity.save
|
||||
end
|
||||
attachments = Attachment.attach_files(@blogComment, params[:attachments])
|
||||
render_attachment_warning_if_needed(@blogComment)
|
||||
#@article.save
|
||||
# redirect_to user_blogs_path(:user_id=>params[:user_id])
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
if params[:course_id] #如果呆了course_id过来了,那么这是要跳到课程大纲去的
|
||||
redirect_to syllabus_course_path(:id=>params[:course_id])
|
||||
else
|
||||
redirect_to user_blog_blog_comment_path(:user_id=>@article.author_id,:blog_id=>@article.blog_id,:id=>@article)
|
||||
end
|
||||
|
||||
}
|
||||
format.js
|
||||
end
|
||||
rescue Exception => e #如果上面的代码执行发生异常就捕获
|
||||
flash[:notice] = e.message
|
||||
end
|
||||
|
||||
private
|
||||
def find_user
|
||||
@user = User.find(params[:user_id])
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
class BlogsController < ApplicationController
|
||||
before_filter :find_blog,:except => [:index,:create,:new,:set_homepage, :cancel_homepage]
|
||||
before_filter :find_user
|
||||
def index
|
||||
@article = BlogComment.new
|
||||
respond_to do |format|
|
||||
format.html {render :layout=>'new_base_user'}
|
||||
end
|
||||
end
|
||||
def create
|
||||
|
||||
end
|
||||
def new
|
||||
|
||||
end
|
||||
def show
|
||||
|
||||
end
|
||||
def update
|
||||
|
||||
end
|
||||
def destory
|
||||
|
||||
end
|
||||
def edit
|
||||
|
||||
end
|
||||
|
||||
def set_homepage
|
||||
@blog = Blog.find(params[:id])
|
||||
@blog.update_attribute(:homepage_id, params[:article_id])
|
||||
redirect_to user_blogs_path(params[:user_id])
|
||||
end
|
||||
|
||||
def cancel_homepage
|
||||
@blog = Blog.find(params[:id])
|
||||
@blog.update_attribute(:homepage_id, nil)
|
||||
redirect_to user_blogs_path(params[:user_id])
|
||||
end
|
||||
private
|
||||
def find_blog
|
||||
if params[:blog_id]
|
||||
@blog = Blog.find(params[:blog_id])
|
||||
else
|
||||
render_404
|
||||
end
|
||||
if @blog.nil?
|
||||
#如果某个user的blog不存在,那么就创建一条
|
||||
@blog = Blog.create(:name=>User.find(params[:id]).realname ,
|
||||
:description=>'',
|
||||
:author_id=>params[:id])
|
||||
end
|
||||
end
|
||||
|
||||
def find_user
|
||||
@user = User.find(params[:user_id])
|
||||
end
|
||||
end
|
||||
|
|
@ -18,8 +18,8 @@
|
|||
class BoardsController < ApplicationController
|
||||
layout 'base_projects'#by young
|
||||
default_search_scope :messages
|
||||
before_filter :find_project_by_project_id, :find_board_if_available
|
||||
before_filter :authorize, :except => [:new, :show, :create, :index]
|
||||
before_filter :find_project_by_project_id, :find_board_if_available, :except => [:join_to_org_subfields]
|
||||
before_filter :authorize, :except => [:new, :show, :create, :index, :join_to_org_subfields]
|
||||
accept_rss_auth :index, :show
|
||||
|
||||
|
||||
|
|
@ -79,6 +79,12 @@ class BoardsController < ApplicationController
|
|||
end
|
||||
end
|
||||
end
|
||||
# 更新@消息为已读
|
||||
@project.boards.each do |board|
|
||||
board.messages.each do |m|
|
||||
User.current.at_messages.unviewed('Message', m.id).each {|x| x.viewed!}
|
||||
end
|
||||
end
|
||||
elsif @course
|
||||
query_course_messages = @board.messages
|
||||
query_course_messages.each do |query_course_message|
|
||||
|
|
@ -90,64 +96,44 @@ class BoardsController < ApplicationController
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
sort_init 'updated_on', 'desc'
|
||||
sort_update 'created_on' => "#{Message.table_name}.created_on",
|
||||
'replies' => "#{Message.table_name}.replies_count",
|
||||
'updated_on' => "COALESCE(last_replies_messages.created_on, #{Message.table_name}.created_on)"
|
||||
|
||||
@is_new = params[:is_new]
|
||||
@topic_count = @board ? @board.topics.count : 0
|
||||
if @project
|
||||
if @board
|
||||
limit = 10;
|
||||
@topic_count = @board.topics.count();
|
||||
@topic_pages = (params[:page] ? params[:page].to_i + 1 : 0) *10
|
||||
@topics = @board.topics.reorder("#{Message.table_name}.sticky DESC, COALESCE(last_replies_messages.created_on, #{Message.table_name}.created_on) desc").
|
||||
limit(limit).offset(@topic_pages).includes(:last_reply).
|
||||
preload(:author, {:last_reply => :author}).all();
|
||||
else
|
||||
@topics = [];
|
||||
end
|
||||
elsif @course
|
||||
if (@board)
|
||||
limit = 10;
|
||||
@topic_count = @board.topics.count();
|
||||
@topic_pages = (params[:page] ? params[:page].to_i + 1 : 0) *10
|
||||
@topics = @board.topics.reorder("#{Message.table_name}.sticky DESC, COALESCE(last_replies_messages.created_on, #{Message.table_name}.created_on) desc").
|
||||
limit(limit).offset(@topic_pages).includes(:last_reply).
|
||||
preload(:author, {:last_reply => :author}).all();
|
||||
else
|
||||
@topics = [];
|
||||
end
|
||||
end
|
||||
|
||||
@page = params[:page] ? params[:page].to_i + 1 : 0
|
||||
@message = Message.new(:board => @board)
|
||||
#modify by nwb
|
||||
respond_to do |format|
|
||||
format.js
|
||||
format.html {
|
||||
sort_init 'updated_on', 'desc'
|
||||
sort_update 'created_on' => "#{Message.table_name}.created_on",
|
||||
'replies' => "#{Message.table_name}.replies_count",
|
||||
'updated_on' => "COALESCE(last_replies_messages.created_on, #{Message.table_name}.created_on)"
|
||||
|
||||
@topic_count = @board ? @board.topics.count : 0
|
||||
if @project
|
||||
@topic_pages = Paginator.new @topic_count, per_page_option, params['page']
|
||||
@topics = @board.topics.
|
||||
reorder("#{Message.table_name}.sticky DESC, #{Message.table_name}.created_on desc").
|
||||
includes(:last_reply).
|
||||
limit(@topic_pages.per_page).
|
||||
offset(@topic_pages.offset).
|
||||
|
||||
preload(:author, {:last_reply => :author}).
|
||||
all
|
||||
elsif @course
|
||||
#
|
||||
# board_topics = @board ? @board.topics.reorder("#{Message.table_name}.sticky DESC, #{Message.table_name}.created_on desc").
|
||||
# includes(:last_reply).
|
||||
# # limit(@topic_pages.per_page).
|
||||
# # offset(@topic_pages.offset).
|
||||
#
|
||||
# preload(:author, {:last_reply => :author}).
|
||||
# all : []
|
||||
# @topics = paginateHelper board_topics,10
|
||||
if( @board )
|
||||
limit = 10;
|
||||
pageno = params[:page];
|
||||
if(pageno == nil || pageno=='')
|
||||
dw_topic = nil;
|
||||
if( params[:parent_id]!=nil && params[:parent_id]!='' )
|
||||
dw_topic = @board.topics.where(id:params[:parent_id]).first();
|
||||
end
|
||||
if( dw_topic != nil )
|
||||
dw_count = @board.topics.where('(sticky>?) or (sticky=? and created_on>?)',dw_topic.sticky,dw_topic.sticky,dw_topic.created_on).count();
|
||||
dw_count = dw_count+1;
|
||||
pageno = dw_count%10==0 ? (dw_count/limit) : (dw_count/limit+1)
|
||||
end
|
||||
end
|
||||
if(pageno == nil || pageno=='')
|
||||
pageno=1;
|
||||
end
|
||||
@topic_count = @board.topics.count();
|
||||
@topic_pages = Paginator.new @topic_count, limit, pageno
|
||||
@topics = @board.topics.reorder("#{Message.table_name}.sticky DESC, #{Message.table_name}.created_on desc").
|
||||
limit(limit).offset(@topic_pages.offset).includes(:last_reply).
|
||||
preload(:author, {:last_reply => :author}).all();
|
||||
else
|
||||
@topics = [];
|
||||
end
|
||||
end
|
||||
|
||||
@message = Message.new(:board => @board)
|
||||
#modify by nwb
|
||||
if @project
|
||||
render :action => 'show', :layout => 'base_projects'
|
||||
elsif @course
|
||||
|
|
@ -157,10 +143,10 @@ class BoardsController < ApplicationController
|
|||
}
|
||||
format.atom {
|
||||
@messages = @board.messages.
|
||||
reorder('created_on DESC').
|
||||
includes(:author, :board).
|
||||
limit(Setting.feeds_limit.to_i).
|
||||
all
|
||||
reorder('created_on DESC').
|
||||
includes(:author, :board).
|
||||
limit(Setting.feeds_limit.to_i).
|
||||
all
|
||||
if @project
|
||||
render_feed(@messages, :title => "#{@project}: #{@board}")
|
||||
elsif @course
|
||||
|
|
@ -214,6 +200,16 @@ class BoardsController < ApplicationController
|
|||
redirect_to_settings_in_projects
|
||||
end
|
||||
|
||||
def join_to_org_subfields
|
||||
if params[:id]
|
||||
@board = Board.find(params[:id])
|
||||
@org_subfield_ids = params[:org_subfield_ids]
|
||||
@org_subfield_ids.each do |id|
|
||||
OrgSubfieldBoard.create(:org_subfield_id => id.to_i, :board_id => params[:id].to_i)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def redirect_to_settings_in_projects
|
||||
redirect_to settings_project_url(@project, :tab => 'boards')
|
||||
|
|
|
|||
|
|
@ -25,9 +25,16 @@ class CommentsController < ApplicationController
|
|||
|
||||
def create
|
||||
raise Unauthorized unless @news.commentable?
|
||||
|
||||
if !@news.org_subfield_id.nil?
|
||||
@org_subfield = OrgSubfield.find(@news.org_subfield_id)
|
||||
end
|
||||
@comment = Comment.new
|
||||
@project ? @comment.comments = params[:comment][:comments] : @comment.comments = params[:comment]
|
||||
#@project ? @comment.comments = params[:comment][:comments] : @comment.comments = params[:comment]
|
||||
if params[:user_activity_id]
|
||||
@comment.comments = params[:comment]
|
||||
else
|
||||
@comment.comments = params[:comment][:comments]
|
||||
end
|
||||
@comment.author = User.current
|
||||
if @news.comments << @comment
|
||||
if params[:asset_id]
|
||||
|
|
@ -48,7 +55,10 @@ class CommentsController < ApplicationController
|
|||
# end
|
||||
# end
|
||||
# # <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ض<EFBFBD>̬<EFBFBD>ļ<EFBFBD>¼add end
|
||||
flash[:notice] = l(:label_comment_added)
|
||||
#flash[:notice] = l(:label_comment_added)
|
||||
update_course_activity(@news.class,@news.id)
|
||||
update_user_activity(@news.class,@news.id)
|
||||
update_org_activity(@news.class,@news.id)
|
||||
end
|
||||
|
||||
if params[:user_activity_id]
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
#encoding: utf-8
|
||||
class CoursesController < ApplicationController
|
||||
# layout 'base_courses'
|
||||
include CoursesHelper
|
||||
|
|
@ -8,7 +9,7 @@ class CoursesController < ApplicationController
|
|||
helper :attachments
|
||||
helper :activity_notifys
|
||||
|
||||
before_filter :auth_login1, :only => [:show, :feedback]
|
||||
before_filter :auth_login1, :only => [:show, :course_activity, :feedback]
|
||||
menu_item :overview
|
||||
menu_item :feedback, :only => :feedback
|
||||
menu_item :homework, :only => :homework
|
||||
|
|
@ -25,33 +26,58 @@ class CoursesController < ApplicationController
|
|||
before_filter :authorize_course, :only => [:show, :settings, :update, :course]
|
||||
before_filter :authorize_course_global, :only => [:new,:create]
|
||||
before_filter :toggleCourse, :only => [:finishcourse, :restartcourse]
|
||||
before_filter :is_deleted, :only => [:show, :settings]
|
||||
|
||||
before_filter :require_login, :only => [:join, :unjoin]
|
||||
#before_filter :allow_join, :only => [:join]
|
||||
|
||||
#查找组织
|
||||
def search_public_orgs_not_in_course
|
||||
condition = '%%'
|
||||
if !params[:name].nil?
|
||||
condition = "%#{params[:name].strip}%".gsub(" ","")
|
||||
end
|
||||
limit = 15
|
||||
course_org_ids = OrgCourse.find_by_sql("select distinct organization_id from org_courses where course_id = #{params[:id]}").map(&:organization_id)
|
||||
#@orgs_not_in_course = User.current.organizations.where("organizations.id not in (#{course_org_ids.join(',')}) and organizations.name like ?", condition).page(params[:page].to_i || 1).per(limit)
|
||||
#@org_count = User.current.organizations.where("organizations.id not in (#{course_org_ids.join(',')}) and organizations.name like ?", condition).count
|
||||
if course_org_ids.empty?
|
||||
@orgs_not_in_course = User.current.organizations.where("name like ?",condition).page((params[:page].to_i || 1)).per(limit)
|
||||
@org_count = @orgs_not_in_course.count
|
||||
else
|
||||
course_org_ids = "(" + course_org_ids.join(',') + ")"
|
||||
@orgs_not_in_course = User.current.organizations.where("organizations.id not in #{course_org_ids} and organizations.name like ?", condition).page((params[:page].to_i || 1)).per(limit)
|
||||
@org_count = @orgs_not_in_course.empty? ? 0 : @orgs_not_in_course.count
|
||||
end
|
||||
@course_count = Project.course_entities.visible.like(params[:name]).page(params[:page]).count
|
||||
@orgs_page = Paginator.new @org_count, limit,params[:page]
|
||||
@hint_flag = params[:hint_flag]
|
||||
#render :json => {:orgs => @orgs_not_in_course, :count => @org_count}.to_json
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def join
|
||||
if User.current.logged?
|
||||
cs = CoursesService.new
|
||||
user = User.current
|
||||
join = cs.join_course params,user
|
||||
@user = User.current
|
||||
join = cs.join_course params,@user
|
||||
@state = join[:state]
|
||||
course = join[:course]
|
||||
@course = join[:course]
|
||||
# else
|
||||
# @course = Course.find_by_id params[:object_id]
|
||||
# CourseMessage.create(:user_id => @course.tea_id, :course_id => @course.id, :viewed => false,:content=> params[:role],:course_message_id=>User.current.id,:course_message_type=>'JoinCourseRequest')
|
||||
# @state = 6
|
||||
# end
|
||||
else
|
||||
@state = 5 #未登录
|
||||
end
|
||||
# if @state == 1 || @state == 3
|
||||
# respond_to course_path(course.id)
|
||||
# else
|
||||
respond_to do |format|
|
||||
format.js { render :partial => 'set_join', :locals => {:user => user, :course => course, :object_id => params[:object_id]} }
|
||||
end
|
||||
#end
|
||||
|
||||
rescue Exception => e
|
||||
@state = 4 #已经加入了课程
|
||||
@object_id = params[:object_id]
|
||||
respond_to do |format|
|
||||
format.js { render :partial => 'set_join', :locals => {:user => User.current, :course => nil, :object_id => nil} }
|
||||
format.js #{ render :partial => 'set_join', :locals => {:user => @user, :course => @course, :object_id => params[:object_id]} }
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def unjoin
|
||||
|
|
@ -64,7 +90,7 @@ class CoursesController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
def join_private_courses
|
||||
respond_to do |format|
|
||||
format.js
|
||||
|
|
@ -77,14 +103,14 @@ class CoursesController < ApplicationController
|
|||
c = cs.edit_course params,@course,User.current
|
||||
@course = c[:course]
|
||||
if @course.errors.full_messages.count <= 0
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
# render :layout => 'base_courses'
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
redirect_to settings_course_url(@course)
|
||||
}
|
||||
format.api { render_api_ok }
|
||||
end
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
# render :layout => 'base_courses'
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
redirect_to settings_course_url(@course)
|
||||
}
|
||||
format.api { render_api_ok }
|
||||
end
|
||||
else
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
|
|
@ -110,11 +136,11 @@ class CoursesController < ApplicationController
|
|||
courses = Course.visible
|
||||
@courses = paginateHelper courses,10
|
||||
else
|
||||
courses = Course.visible.where("LOWER(name) like '%#{params[:name].to_s.downcase}%'")
|
||||
courses = Course.visible.where("LOWER(name) like '%#{params[:name].to_s.downcase}%'").order("time desc, created_at desc")
|
||||
@courses = paginateHelper courses,10
|
||||
end
|
||||
@name = params[:name]
|
||||
@type = 'courses'
|
||||
@name = params[:name]
|
||||
@type = 'courses'
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
render :layout => 'course_base'
|
||||
|
|
@ -256,7 +282,7 @@ class CoursesController < ApplicationController
|
|||
def member
|
||||
## 有角色参数的才是课程,没有的就是项目
|
||||
if (User.current.admin? || @course.is_public == 1 || (@course.is_public == 0 && User.current.member_of_course?(@course)))
|
||||
|
||||
|
||||
@render_file = 'new_member_list'
|
||||
@score_sort_by = "desc"
|
||||
@canShowCode = User.current.allowed_to?(:as_teacher,@course) && params[:role] != '1'
|
||||
|
|
@ -270,10 +296,15 @@ class CoursesController < ApplicationController
|
|||
@all_members = searchTeacherAndAssistant(@course)
|
||||
@members = @all_members
|
||||
when '2'
|
||||
@subPage_title = l :label_student_list
|
||||
page = params[:page].nil? ? 0 : (params['page'].to_i - 1)
|
||||
@all_members = student_homework_score(0,page, 10,"desc")
|
||||
@members = @all_members
|
||||
if @course.open_student == 1 || User.current.member_of_course?(@course)
|
||||
@subPage_title = l :label_student_list
|
||||
page = params[:page].nil? ? 0 : (params['page'].to_i - 1)
|
||||
@all_members = student_homework_score(0,page, 10,"desc")
|
||||
@members = @all_members
|
||||
else
|
||||
render_403
|
||||
return
|
||||
end
|
||||
end
|
||||
respond_to do |format|
|
||||
if params[:page]
|
||||
|
|
@ -291,14 +322,11 @@ class CoursesController < ApplicationController
|
|||
def export_course_member_excel
|
||||
@all_members = student_homework_score(0,0,0,"desc")
|
||||
filename="#{@course.teacher.lastname.to_s + @course.teacher.firstname.to_s }_#{@course.name}_#{@course.time.to_s + @course.term}#{l(:excel_member_list)}";
|
||||
# 如果是ie 需要转码
|
||||
if(/trident/.match(request.env["HTTP_USER_AGENT"]) != nil)
|
||||
filename= URI::encode(filename)
|
||||
end
|
||||
|
||||
respond_to do |format|
|
||||
format.xls {
|
||||
send_data(member_to_xls(@all_members,@course.course_groups), :type => "text/excel;charset=utf-8; header=present",
|
||||
:filename => "#{filename}.xls")
|
||||
:filename => filename_for_content_disposition("#{filename}.xls"))
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
@ -356,6 +384,7 @@ class CoursesController < ApplicationController
|
|||
|
||||
def settings
|
||||
if User.current.allowed_to?(:as_teacher,@course)
|
||||
@select_tab = params[:tab]
|
||||
@issue_custom_fields = IssueCustomField.sorted.all
|
||||
@issue_category ||= IssueCategory.new
|
||||
@member ||= @course.members.new
|
||||
|
|
@ -373,6 +402,25 @@ class CoursesController < ApplicationController
|
|||
|
||||
end
|
||||
|
||||
def private_or_public
|
||||
if @course.is_public == 0
|
||||
@course.update_attributes(:is_public => 1)
|
||||
else
|
||||
@course.update_attributes(:is_public => 0)
|
||||
end
|
||||
if @course.is_public == 0
|
||||
course_status = CourseStatus.find_by_course_id(@course.id)
|
||||
course_status.destroy if course_status
|
||||
elsif @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.js
|
||||
end
|
||||
end
|
||||
|
||||
def search_member
|
||||
if User.current.allowed_to?(:as_teacher,@course) || User.current.admin
|
||||
q = "#{params[:name].strip}"
|
||||
|
|
@ -391,10 +439,77 @@ class CoursesController < ApplicationController
|
|||
def create
|
||||
cs = CoursesService.new
|
||||
@course = cs.create_course(params,User.current)[:course]
|
||||
if params[:copy_course]
|
||||
copy_course = Course.find params[:copy_course].to_i
|
||||
@course.update_attributes(:open_student => copy_course.open_student, :publish_resource => copy_course.publish_resource)
|
||||
if params[:checkAll]
|
||||
attachments = copy_course.attachments
|
||||
attachments.each do |attachment|
|
||||
attach_copied_obj = attachment.copy
|
||||
attach_copied_obj.tag_list.add(attachment.tag_list) # tag关联
|
||||
attach_copied_obj.container = @course
|
||||
attach_copied_obj.created_on = Time.now
|
||||
attach_copied_obj.author_id = User.current.id
|
||||
attach_copied_obj.copy_from = attachment.copy_from.nil? ? attachment.id : attachment.copy_from
|
||||
if attach_copied_obj.attachtype == nil
|
||||
attach_copied_obj.attachtype = 4
|
||||
end
|
||||
attach_copied_obj.save
|
||||
update_quotes attach_copied_obj
|
||||
end
|
||||
elsif params[:course_attachment_type]
|
||||
copy_attachments = []
|
||||
params[:course_attachment_type].each do |type|
|
||||
case type
|
||||
when "1"
|
||||
tag_name = l(:label_courseware)
|
||||
when "2"
|
||||
tag_name = l(:label_software)
|
||||
when "3"
|
||||
tag_name = l(:label_media)
|
||||
when "4"
|
||||
tag_name = l(:label_code)
|
||||
when "6"
|
||||
tag_name = "论文"
|
||||
else
|
||||
tag_name = ""
|
||||
end
|
||||
if tag_name == ""
|
||||
tag_attachments = copy_course.attachments.select{|attachment|
|
||||
!attachment.tag_list.include?('课件') &&
|
||||
!attachment.tag_list.include?('软件') &&
|
||||
!attachment.tag_list.include?('媒体') &&
|
||||
!attachment.tag_list.include?('代码') &&
|
||||
!attachment.tag_list.include?('论文') }
|
||||
else
|
||||
tag_attachments = copy_course.attachments.select{|attachment| attachment.tag_list.include?(tag_name)}
|
||||
end
|
||||
tag_attachments.each do |attach|
|
||||
next if copy_attachments.include?(attach)
|
||||
copy_attachments << attach
|
||||
end
|
||||
end
|
||||
unless copy_attachments.blank?
|
||||
copy_attachments.each do |c_attach|
|
||||
attach_copied_obj = c_attach.copy
|
||||
attach_copied_obj.tag_list.add(c_attach.tag_list) # tag关联
|
||||
attach_copied_obj.container = @course
|
||||
attach_copied_obj.created_on = Time.now
|
||||
attach_copied_obj.author_id = User.current.id
|
||||
attach_copied_obj.copy_from = c_attach.copy_from.nil? ? c_attach.id : c_attach.copy_from
|
||||
if attach_copied_obj.attachtype == nil
|
||||
attach_copied_obj.attachtype = 4
|
||||
end
|
||||
attach_copied_obj.save
|
||||
update_quotes attach_copied_obj
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if @course
|
||||
respond_to do |format|
|
||||
flash[:notice] = l(:notice_successful_create)
|
||||
format.html {redirect_to settings_course_url(@course, :course_type => 1)}
|
||||
format.html {redirect_to course_url(@course)}
|
||||
format.api { render :action => 'show', :status => :created, :location => url_for(:controller => 'courses', :action => 'show', :id => @course.id) }
|
||||
end
|
||||
else
|
||||
|
|
@ -408,7 +523,7 @@ class CoursesController < ApplicationController
|
|||
end
|
||||
|
||||
def course
|
||||
@school_id = params[:school_id]
|
||||
@school_id = params[:school_id]
|
||||
per_page_option = 10
|
||||
if @school_id == "0" or @school_id.nil?
|
||||
@courses_all = Course.active.visible.
|
||||
|
|
@ -468,13 +583,17 @@ class CoursesController < ApplicationController
|
|||
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]
|
||||
# month = Time.now.month
|
||||
render :layout => 'new_base'
|
||||
if User.current.login?
|
||||
@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]
|
||||
# month = Time.now.month
|
||||
render :layout => 'new_base'
|
||||
else
|
||||
redirect_to signin_url
|
||||
end
|
||||
end
|
||||
|
||||
def desc_sort_course_by_avtivity(activity_count, courses)
|
||||
|
|
@ -492,8 +611,8 @@ class CoursesController < ApplicationController
|
|||
|
||||
def index
|
||||
if !User.current.admin?
|
||||
render_404
|
||||
return
|
||||
render_404
|
||||
return
|
||||
end
|
||||
@course_type = params[:course_type]
|
||||
@school_id = params[:school_id]
|
||||
|
|
@ -542,7 +661,7 @@ class CoursesController < ApplicationController
|
|||
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
render :layout => 'base'
|
||||
render :layout => 'base'
|
||||
}
|
||||
format.atom {
|
||||
courses = Course.visible.order('created_on DESC').limit(Setting.feeds_limit.to_i).all
|
||||
|
|
@ -558,6 +677,13 @@ class CoursesController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def is_deleted
|
||||
if @course.is_delete == 1 and !User.current.admin?
|
||||
render_404
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
def get_courses
|
||||
@user = User.current
|
||||
membership = @user.coursememberships.all
|
||||
|
|
@ -606,11 +732,50 @@ class CoursesController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def course_activity
|
||||
redirect_to course_url(@course, type: params[:type], page: params[:page])
|
||||
end
|
||||
|
||||
def show
|
||||
course_activities = @course.course_activities.order("created_at desc")
|
||||
# 被删除的课程只有超级管理员才能看到,is_delete为1的时候,标记课程被删除
|
||||
# if @course.is_delete == 1 && !User.current.admin?
|
||||
# render_403
|
||||
# return
|
||||
# end
|
||||
#更新创建课程消息状态
|
||||
create_course_messages = @course.course_messages.where("user_id =? and course_message_type =? and course_id =? and viewed =?", User.current.id, 'Course', @course.id, 0)
|
||||
create_course_messages.update_all(:viewed => true)
|
||||
|
||||
#更新申请结果反馈消息的状态
|
||||
course_request_messages = CourseMessage.where("user_id =? and course_id =? and course_message_type =? and viewed =?", User.current.id, @course.id, 'CourseRequestDealResult', false)
|
||||
course_request_messages.update_all(:viewed => true)
|
||||
|
||||
course_activities = @course.course_activities
|
||||
@canShowRealName = User.current.member_of_course? @course
|
||||
@course_activities = paginateHelper course_activities,10
|
||||
@page = params[:page] ? params[:page].to_i + 1 : 0
|
||||
if params[:type].present?
|
||||
case params[:type]
|
||||
when "homework"
|
||||
@course_activities = course_activities.where("course_act_type = 'HomeworkCommon'").order('updated_at desc').limit(10).offset(@page * 10)
|
||||
when "news"
|
||||
@course_activities = course_activities.where("course_act_type = 'News'").order('updated_at desc').limit(10).offset(@page * 10)
|
||||
when "message"
|
||||
@course_activities = course_activities.where("course_act_type = 'Message'").order('updated_at desc').limit(10).offset(@page * 10)
|
||||
when "poll"
|
||||
@course_activities = course_activities.where("course_act_type = 'Poll'").order('updated_at desc').limit(10).offset(@page * 10)
|
||||
when "attachment"
|
||||
@course_activities = course_activities.where("course_act_type = 'Attachment'").order('updated_at desc').limit(10).offset(@page * 10)
|
||||
when "journalsForMessage"
|
||||
@course_activities = course_activities.where("course_act_type = 'JournalsForMessage'").order('updated_at desc').limit(10).offset(@page * 10)
|
||||
else
|
||||
@course_activities = course_activities.order('updated_at desc').limit(10).offset(@page * 10)
|
||||
end
|
||||
else
|
||||
@course_activities = course_activities.order('updated_at desc').limit(10).offset(@page * 10)
|
||||
end
|
||||
@type = params[:type]
|
||||
respond_to do |format|
|
||||
format.js
|
||||
format.html{render :layout => 'base_courses'}
|
||||
format.api
|
||||
end
|
||||
|
|
@ -627,6 +792,11 @@ class CoursesController < ApplicationController
|
|||
end
|
||||
|
||||
def feedback
|
||||
@course.journals_for_messages.each do |messages|
|
||||
query = messages.course_messages.where("user_id = ?", User.current.id)
|
||||
query.update_all(:viewed => true);
|
||||
end
|
||||
|
||||
if (User.current.admin? || @course.is_public == 1 || (@course.is_public == 0 && User.current.member_of_course?(@course)))
|
||||
page = params[:page]
|
||||
# Find the page of the requested reply
|
||||
|
|
@ -651,6 +821,11 @@ class CoursesController < ApplicationController
|
|||
#param id:已有课程ID
|
||||
def copy_course
|
||||
if @course
|
||||
@new_course = Course.new
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
=begin
|
||||
@new_course = Course.new @course.attributes
|
||||
@new_course.tea_id = User.current.id
|
||||
@new_course.created_at = DateTime.now
|
||||
|
|
@ -669,18 +844,94 @@ class CoursesController < ApplicationController
|
|||
@new_course.course_infos << course
|
||||
redirect_to settings_course_url @new_course
|
||||
end
|
||||
=end
|
||||
else
|
||||
render_404
|
||||
end
|
||||
end
|
||||
|
||||
#删除课程
|
||||
#删除课程只是将课程的is_delete状态改为false,is_delete为false状态的课程只有管理员可以看到
|
||||
def destroy
|
||||
#从课程创建的老师那里选择课程大纲
|
||||
def course_outline
|
||||
@teacher = User.find(@course.tea_id)
|
||||
@blog_articles = @teacher.blog.articles
|
||||
@is_in_show_outline_page = params[:is_in_show_outline_page]
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
#根据关键字搜索,查找方法一样的,但返回内容不一样
|
||||
def search_course_outline
|
||||
@article_title = params[:title]
|
||||
@teacher = User.find(@course.tea_id)
|
||||
@blog_articles = @teacher.blog.articles.like(@article_title)
|
||||
render :json=>@blog_articles.to_json
|
||||
end
|
||||
|
||||
#设置或者更改课程的大纲
|
||||
def set_course_outline
|
||||
@course.outline = params[:outline_id]
|
||||
@course.save
|
||||
@is_in_show_outline_page = params[:is_in_show_outline_page]
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
#显示课程大纲
|
||||
def syllabus
|
||||
@article = BlogComment.find(@course.outline)
|
||||
respond_to do |format|
|
||||
format.html {render :layout => 'base_courses'}
|
||||
end
|
||||
end
|
||||
|
||||
#删除课程
|
||||
#删除课程只是将课程的is_deleted状态改为false,is_deleted为false状态的课程只有管理员可以看到
|
||||
def destroy
|
||||
@course.update_attributes(:is_delete => true)
|
||||
@course = nil
|
||||
redirect_to user_url(User.current)
|
||||
end
|
||||
|
||||
# 恢复已删除的课程
|
||||
def renew
|
||||
if User.current.admin?
|
||||
@course.update_attributes(:is_delete => false)
|
||||
redirect_to course_path(@course)
|
||||
else
|
||||
return 404
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def update_quotes attachment
|
||||
if attachment.copy_from
|
||||
attachments = Attachment.find_by_sql("select * from attachments where copy_from = #{attachment.copy_from} or id = #{attachment.copy_from}")
|
||||
else
|
||||
attachments = Attachment.find_by_sql("select * from attachments where copy_from = #{attachment.id} or id = #{attachment.copy_from}")
|
||||
end
|
||||
attachment.quotes = get_qute_number attachment
|
||||
attachment.save
|
||||
attachments.each do |att|
|
||||
att.quotes = attachment.quotes
|
||||
att.save
|
||||
end
|
||||
end
|
||||
|
||||
def get_qute_number attachment
|
||||
if attachment.copy_from
|
||||
result = Attachment.find_by_sql("select count(*) as number from attachments where copy_from = #{attachment.copy_from}")
|
||||
else
|
||||
result = Attachment.find_by_sql("select count(*) as number from attachments where copy_from = #{attachment.id}")
|
||||
end
|
||||
if result.nil? || result.count <= 0
|
||||
return 0
|
||||
else
|
||||
return result[0].number
|
||||
end
|
||||
end
|
||||
|
||||
def allow_join course
|
||||
if course_endTime_timeout? course
|
||||
respond_to do |format|
|
||||
|
|
@ -700,7 +951,7 @@ class CoursesController < ApplicationController
|
|||
def can_show_course
|
||||
@first_page = FirstPage.find_by_page_type('project')
|
||||
if @first_page.try(:show_course) == 2
|
||||
render_404
|
||||
render_404
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,709 @@
|
|||
class ExerciseController < ApplicationController
|
||||
layout "base_courses"
|
||||
|
||||
before_filter :find_exercise_and_course, :only => [:create_exercise_question, :edit, :update, :show, :destroy,
|
||||
:commit_exercise, :commit_answer,:publish_exercise,:republish_exercise,
|
||||
:show_student_result,:student_exercise_list]
|
||||
before_filter :find_course, :only => [:index,:new,:create]
|
||||
include ExerciseHelper
|
||||
|
||||
def index
|
||||
publish_exercises = Exercise.where("publish_time is not null and exercise_status = 1 and publish_time <=?",Time.now)
|
||||
publish_exercises.each do |exercise|
|
||||
exercise.update_column('exercise_status', 2)
|
||||
course = exercise.course
|
||||
course.members.each do |m|
|
||||
exercise.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => course.id, :viewed => false, :status => 2)
|
||||
end
|
||||
end
|
||||
|
||||
if @course.is_public == 0 && !(User.current.member_of_course?(@course)||User.current.admin?)
|
||||
render_403
|
||||
return
|
||||
end
|
||||
remove_invalid_exercise(@course)
|
||||
@is_teacher = User.current.allowed_to?(:as_teacher,@course)
|
||||
if @is_teacher || User.current.admin?
|
||||
exercises = @course.exercises.order("created_at asc")
|
||||
else
|
||||
exercises = @course.exercises.where("exercise_status <> 1").order("created_at asc")
|
||||
end
|
||||
@exercises = paginateHelper exercises,20 #分页
|
||||
respond_to do |format|
|
||||
format.html
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
publish_exercises = Exercise.where("publish_time is not null and exercise_status = 1 and publish_time <=?",Time.now)
|
||||
publish_exercises.each do |exercise|
|
||||
exercise.update_column('exercise_status', 2)
|
||||
course = exercise.course
|
||||
course.members.each do |m|
|
||||
exercise.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => course.id, :viewed => false, :status => 2)
|
||||
end
|
||||
end
|
||||
|
||||
unless User.current.member_of_course?(@course) || User.current.admin?
|
||||
render_403
|
||||
return
|
||||
end
|
||||
@exercise = Exercise.find params[:id]
|
||||
@is_teacher = User.current.allowed_to?(:as_teacher,@course) || User.current.admin?
|
||||
exercise_end = @exercise.end_time > Time.now
|
||||
if @exercise.time == -1
|
||||
@can_edit_excercise = exercise_end
|
||||
else
|
||||
@can_edit_excercise = !has_commit_exercise?(@exercise.id,User.current.id)&& exercise_end
|
||||
end
|
||||
unless @is_teacher
|
||||
@exercise_user = ExerciseUser.where("user_id=? and exercise_id=?", User.current.id, @exercise.id).first
|
||||
if @exercise_user.nil?
|
||||
eu = ExerciseUser.create(:user_id => User.current.id, :exercise_id => @exercise.id, :start_at => Time.now, :status => false)
|
||||
@exercise_user = ExerciseUser.where("user_id=? and exercise_id=?", User.current.id, @exercise.id).first
|
||||
end
|
||||
score = calculate_student_score(@exercise, User.current)
|
||||
@exercise_user.update_attributes(:score => score)
|
||||
end
|
||||
# @percent = get_percent(@exercise,User.current)
|
||||
@exercise_questions = @exercise.exercise_questions
|
||||
respond_to do |format|
|
||||
format.html {render :layout => 'base_courses'}
|
||||
end
|
||||
#end
|
||||
end
|
||||
|
||||
def new
|
||||
option = {
|
||||
:exercise_name => "",
|
||||
:course_id => @course.id,
|
||||
:exercise_status => 1,
|
||||
:user_id => User.current.id,
|
||||
:time => "",
|
||||
:end_time => "",
|
||||
:publish_time => "",
|
||||
:exercise_description => "",
|
||||
:show_result => 1
|
||||
}
|
||||
@exercise = Exercise.create option
|
||||
if @exercise
|
||||
redirect_to edit_exercise_url @exercise.id
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
if params[:exercise]
|
||||
exercise = Exercise.find(params[:exercise_id]) if params[:exercise_id]
|
||||
exercise ||= Exercise.new
|
||||
exercise.exercise_name = params[:exercise][:exercise_name]
|
||||
exercise.exercise_description = params[:exercise][:exercise_description]
|
||||
exercise.end_time = Time.at(params[:exercise][:end_time].to_time.to_i + 16*60*60 -1)
|
||||
exercise.publish_time = params[:exercise][:publish_time]
|
||||
exercise.user_id = User.current.id
|
||||
exercise.time = params[:exercise][:time]
|
||||
exercise.course_id = params[:course_id]
|
||||
exercise.exercise_status = 1
|
||||
if exercise.save
|
||||
@exercise = exercise
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
respond_to do |format|
|
||||
format.html{render :layout => 'base_courses'}
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
@exercise.exercise_name = params[:exercise][:exercise_name]
|
||||
@exercise.exercise_description = params[:exercise][:exercise_description]
|
||||
@exercise.time = params[:exercise][:time].blank? ? -1 : params[:exercise][:time]
|
||||
@exercise.end_time = Time.at(params[:exercise][:end_time].to_time.to_i + 16*60*60 -1)
|
||||
@exercise.publish_time = params[:exercise][:publish_time]
|
||||
@exercise.show_result = params[:exercise][:show_result].blank? ? 1 : params[:exercise][:show_result]
|
||||
if @exercise.save
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
else
|
||||
render_404
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@is_teacher = User.current.allowed_to?(:as_teacher,@course) || User.current.admin?
|
||||
if @exercise && @exercise.destroy
|
||||
if @is_teacher
|
||||
exercises = Exercise.where("course_id =?", @course.id)
|
||||
else
|
||||
exercises = Exercise.where("course_id =? and exercise_status =?", @course.id, 2)
|
||||
end
|
||||
@exercises = paginateHelper exercises,20 #分页
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# 统计结果
|
||||
def statistics_result
|
||||
@exercise = Exercise.find(params[:id])
|
||||
exercise_questions = @exercise.exercise_questions
|
||||
@exercise_questions = paginateHelper exercise_questions, 5
|
||||
respond_to do |format|
|
||||
format.html{render :layout => 'base_courses'}
|
||||
end
|
||||
end
|
||||
|
||||
# 添加题目
|
||||
# question_type 1:单选 2:多选 3:填空题
|
||||
def create_exercise_question
|
||||
question_title = params[:question_title].nil? || params[:question_title].empty? ? l(:label_enter_single_title) : params[:question_title]
|
||||
option = {
|
||||
:question_title => question_title,
|
||||
:question_type => params[:question_type] || 1,
|
||||
:question_number => params[:question_type] == "1"? @exercise.exercise_questions.where("question_type = 1").count + 1 :
|
||||
(params[:question_type] == "2" ? (@exercise.exercise_questions.where("question_type = 2").count + 1) :
|
||||
@exercise.exercise_questions.where("question_type = 3").count + 1),
|
||||
:question_score => params[:question_score]
|
||||
}
|
||||
@exercise_questions = @exercise.exercise_questions.new option
|
||||
# params[:question_answer] 题目选项
|
||||
if params[:question_answer]
|
||||
for i in 1..params[:question_answer].count
|
||||
answer = (params[:question_answer].values[i-1].nil? || params[:question_answer].values[i-1].empty?) ? l(:label_new_answer) : params[:question_answer].values[i-1]
|
||||
question_option = {
|
||||
:choice_position => i,
|
||||
:choice_text => answer
|
||||
}
|
||||
@exercise_questions.exercise_choices.new question_option
|
||||
end
|
||||
end
|
||||
# 如果是插入的话,那么从插入的这个id以后的question_num都将要+1
|
||||
if params[:quest_id]
|
||||
@is_insert = true
|
||||
if @exercise_questions.question_type == 1
|
||||
ExerciseQuestion.where("question_number>? and question_type=?",params[:quest_num].to_i, 1).update_all(" question_number = question_number + 1")
|
||||
#@exercise.exercise_questions.where("question_number > #{params[:quest_num].to_i} and question_type == 1").update_all(" question_number = question_number + 1")
|
||||
elsif @exercise_questions.question_type == 2
|
||||
ExerciseQuestion.where("question_number>? and question_type=?",params[:quest_num].to_i, 2).update_all(" question_number = question_number + 1")
|
||||
else
|
||||
ExerciseQuestion.where("question_number>? and question_type=?",params[:quest_num].to_i, 3).update_all(" question_number = question_number + 1")
|
||||
end
|
||||
# @exercise_question_num = params[:quest_num].to_i
|
||||
@exercise_questions.question_number = params[:quest_num].to_i + 1
|
||||
end
|
||||
if @exercise_questions.save
|
||||
# params[:exercise_choice] 标准答案参数
|
||||
# 问答题标准答案有三个,单独处理
|
||||
if @exercise_questions.question_type == 3
|
||||
for i in 1..params[:exercise_choice].count
|
||||
standart_answer = ExerciseStandardAnswer.new
|
||||
standart_answer.exercise_question_id = @exercise_questions.id
|
||||
standart_answer.answer_text = params[:exercise_choice].values[i-1]
|
||||
standart_answer.save
|
||||
end
|
||||
else
|
||||
standart_answer = ExerciseStandardAnswer.new
|
||||
standart_answer.exercise_question_id = @exercise_questions.id
|
||||
if @exercise_questions.question_type == 1
|
||||
standart_answer.exercise_choice_id = sigle_selection_standard_answer(params[:exercise_choice])
|
||||
else
|
||||
standart_answer.exercise_choice_id = multiselect_standard_answer(params[:exercise_choice])
|
||||
end
|
||||
standart_answer.save
|
||||
end
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# 修改题目
|
||||
# params[:exercise_question] The id of exercise_question
|
||||
# params[:question_answer] eg:A、B、C选项
|
||||
def update_exercise_question
|
||||
@exercise_question = ExerciseQuestion.find params[:exercise_question]
|
||||
@exercise_question.question_title = params[:question_title].nil? || params[:question_title].empty? ? l(:label_enter_single_title) : params[:question_title]
|
||||
@exercise_question.question_score = params[:question_score]
|
||||
# 处理选项:如果选了某个选项,那么则要删除之前的选项
|
||||
if params[:question_answer]
|
||||
@exercise_question.exercise_choices.each do |answer|
|
||||
answer.destroy unless params[:question_answer].keys.include? answer.id.to_s
|
||||
end
|
||||
for i in 1..params[:question_answer].count
|
||||
question = @exercise_question.exercise_choices.find_by_id params[:question_answer].keys[i-1]
|
||||
answer = (params[:question_answer].values[i-1].nil? || params[:question_answer].values[i-1].empty?) ? l(:label_new_answer) : params[:question_answer].values[i-1]
|
||||
if question
|
||||
question.choice_position = i
|
||||
question.choice_text = answer
|
||||
question.save
|
||||
else
|
||||
question_option = {
|
||||
:choice_position => i,
|
||||
:choice_text => answer
|
||||
}
|
||||
@exercise_question.exercise_choices.new question_option
|
||||
end
|
||||
end
|
||||
end
|
||||
# 更新标准答案
|
||||
if params[:exercise_choice]
|
||||
if @exercise_question.question_type == 3
|
||||
# 删除不合理的选项
|
||||
@exercise_question.exercise_standard_answers.each do |answer|
|
||||
answer.destroy unless params[:exercise_choice].keys.include? answer.id.to_s
|
||||
end
|
||||
for i in 1..params[:exercise_choice].count
|
||||
# 找到对应的标准答案
|
||||
question_standart = @exercise_question.exercise_standard_answers.find_by_id params[:exercise_choice].keys[i-1]
|
||||
# 标准答案值
|
||||
answer_standart = (params[:exercise_choice].values[i-1].nil? || params[:exercise_choice].values[i-1].empty?) ? l(:label_new_answer) : params[:exercise_choice].values[i-1]
|
||||
if question_standart
|
||||
question_standart.answer_text = answer_standart
|
||||
question_standart.save
|
||||
else
|
||||
standart_answer_option = {
|
||||
:answer_text => answer_standart
|
||||
}
|
||||
@exercise_question.exercise_standard_answers.new standart_answer_option
|
||||
end
|
||||
end
|
||||
else
|
||||
answer_standart = @exercise_question.exercise_standard_answers.first
|
||||
answer_standart.exercise_choice_id = @exercise_question.question_type == 1 ? sigle_selection_standard_answer(params[:exercise_choice]) : multiselect_standard_answer(params[:exercise_choice])
|
||||
answer_standart.save
|
||||
end
|
||||
@exercise_question.save
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# 删除题目
|
||||
def delete_exercise_question
|
||||
@exercise_question = ExerciseQuestion.find params[:exercise_question]
|
||||
@exercise = @exercise_question.exercise
|
||||
|
||||
if @exercise_question.question_type == 1
|
||||
ExerciseQuestion.where("question_number>? and question_type=?",params[:quest_num].to_i, 1).update_all(" question_number = question_number - 1")
|
||||
#@exercise.exercise_questions.where("question_number > #{params[:quest_num].to_i} and question_type == 1").update_all(" question_number = question_number + 1")
|
||||
elsif @exercise_question.question_type == 2
|
||||
ExerciseQuestion.where("question_number>? and question_type=?",params[:quest_num].to_i, 2).update_all(" question_number = question_number - 1")
|
||||
else
|
||||
ExerciseQuestion.where("question_number>? and question_type=?",params[:quest_num].to_i, 3).update_all(" question_number = question_number - 1")
|
||||
end
|
||||
# @exercise_question_num = params[:quest_num].to_i
|
||||
# @exercise_questions.question_number = params[:quest_num].to_i - 1
|
||||
#
|
||||
# exercise_questions = @exercise.exercise_questions.where("question_number > #{@exercise_question.question_number}")
|
||||
# exercise_questions.each do |question|
|
||||
# question.question_number -= 1
|
||||
# question.save
|
||||
# end
|
||||
if @exercise_question && @exercise_question.destroy
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# 发布试卷
|
||||
def publish_exercise
|
||||
@is_teacher = User.current.allowed_to?(:as_teacher,@course)
|
||||
@index = params[:index]
|
||||
@exercise.exercise_status = 2
|
||||
@exercise.publish_time = Time.now
|
||||
if @exercise.save
|
||||
@exercise.course.members.each do |m|
|
||||
@exercise.course_messages << CourseMessage.create(:user_id =>m.user_id, :course_id => @exercise.course.id, :viewed => false,:status=>2)
|
||||
end
|
||||
#redirect_to exercise_index_url(:course_id=> @course.id)
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# 重新发布试卷
|
||||
# 重新发布的时候会删除所有的答题
|
||||
def republish_exercise
|
||||
@is_teacher = User.current.allowed_to?(:as_teacher,@course)
|
||||
@index = params[:index]
|
||||
@exercise.exercise_questions.each do |exercise_question|
|
||||
exercise_question.exercise_answers.destroy_all
|
||||
end
|
||||
@exercise.course_messages.destroy_all
|
||||
@exercise.exercise_users.destroy_all
|
||||
@exercise.exercise_status = 1
|
||||
@exercise.publish_time = nil
|
||||
@exercise.save
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def student_exercise_list
|
||||
=begin
|
||||
if @exercise.end_time <= Time.now
|
||||
@course.student.each do |student|
|
||||
if ExerciseUser.where("user_id = ? && exercise_id = ?",student.student_id,@exercise.id).empty?
|
||||
ExerciseUser.create(:user_id => student.student_id, :exercise_id => @exercise.id, :start_at => @exercise.end_time, :status => true,:score=>0)
|
||||
end
|
||||
|
||||
s_score = calculate_student_score(@exercise, student.student)
|
||||
exercise_user = ExerciseUser.where("user_id =? and exercise_id=?", student.student_id, @exercise.id).first
|
||||
exercise_user.update_attributes(:score => s_score)
|
||||
end
|
||||
end
|
||||
=end
|
||||
@is_teacher = User.current.allowed_to?(:as_teacher,@course) || User.current.admin?
|
||||
@all_exercises = @course.exercises.where("exercise_status > 1").order("created_at desc")
|
||||
@exercise_count = @exercise.exercise_users.where('score is not NULL').count
|
||||
if @is_teacher || (!@exercise.exercise_users.where(:user_id => User.current.id).empty? && @exercise.end_time <= Time.now)
|
||||
@exercise_users_list = @exercise.exercise_users.where('score is not NULL')
|
||||
@show_all = true;
|
||||
elsif !@exercise.exercise_users.where(:user_id => User.current.id).empty? && @exercise.end_time > Time.now
|
||||
@exercise_users_list = @exercise.exercise_users.where("user_id = ? and score is not NULL",User.current.id)
|
||||
else
|
||||
@exercise_users_list = []
|
||||
end
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.xls {
|
||||
filename = "#{@course.teacher.lastname.to_s + @course.teacher.firstname}_#{@course.name}_#{@course.time.to_s + @course.term}_#{@exercise.exercise_name}#{l(:excel_exercise_list)}.xls"
|
||||
send_data(exercise_to_xls(@exercise_users_list), :type => "text/excel;charset=utf-8; header=present",
|
||||
:filename => filename_for_content_disposition(filename))
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
# 学生提交答卷,选中答案的过程中提交
|
||||
def commit_answer
|
||||
eq = ExerciseQuestion.find(params[:exercise_question_id])
|
||||
# 已提交过的且是限时的则不允许答题
|
||||
if (has_commit_exercise?(@exercise.id,User.current.id) && (!User.current.admin?) && @exercise.time != -1) || @exercise.end_time < Time.now
|
||||
render :json => {:text => "failure"}
|
||||
return
|
||||
end
|
||||
if eq.question_type == 1
|
||||
# 单选题
|
||||
ea = ExerciseAnswer.find_by_exercise_question_id_and_user_id(params[:exercise_question_id],User.current.id)
|
||||
if ea.nil?
|
||||
# 尚未答该题,添加答案
|
||||
ea = ExerciseAnswer.new
|
||||
ea.user_id = User.current.id
|
||||
ea.exercise_question_id = params[:exercise_question_id]
|
||||
end
|
||||
#修改该题对应答案
|
||||
ea.exercise_choice_id = params[:exercise_choice_id]
|
||||
if ea.save
|
||||
# 保存成功返回成功信息及当前以答题百分比
|
||||
uncomplete_question = get_uncomplete_question(@exercise, User.current)
|
||||
if uncomplete_question.count < 1
|
||||
complete = 1;
|
||||
else
|
||||
complete = 0;
|
||||
end
|
||||
@percent = get_percent(@exercise,User.current)
|
||||
render :json => {:text => "ok" ,:complete => complete,:percent => format("%.2f" ,@percent)}
|
||||
else
|
||||
#返回失败信息
|
||||
render :json => {:text => "failure"}
|
||||
end
|
||||
elsif eq.question_type == 2
|
||||
#多选题
|
||||
ea = ExerciseAnswer.find_by_exercise_choice_id_and_user_id(params[:exercise_choice_id],User.current.id)
|
||||
if ea.nil?
|
||||
#尚未答该题,添加答案
|
||||
ea = ExerciseAnswer.new
|
||||
ea.user_id = User.current.id
|
||||
ea.exercise_question_id = params[:exercise_question_id]
|
||||
ea.exercise_choice_id = params[:exercise_choice_id]
|
||||
if ea.save
|
||||
uncomplete_question = get_uncomplete_question(@exercise, User.current)
|
||||
if uncomplete_question.count < 1
|
||||
complete = 1;
|
||||
else
|
||||
complete = 0;
|
||||
end
|
||||
@percent = get_percent(@exercise,User.current)
|
||||
render :json => {:text => "ok",:complete => complete,:percent => format("%.2f" ,@percent)}
|
||||
else
|
||||
render :json => {:text => "failure"}
|
||||
end
|
||||
else
|
||||
#pv不为空,则当前选项之前已被选择,再次点击则是不再选择该项,故删除该答案
|
||||
if ea.delete
|
||||
@percent = get_percent(@exercise, User.current)
|
||||
render :json => {:text => "false" ,:percent => format("%.2f" , @percent)}
|
||||
else
|
||||
render :json => {:text => "failure"}
|
||||
end
|
||||
end
|
||||
elsif eq.question_type == 3
|
||||
#单行文本,多行文本题
|
||||
ea = ExerciseAnswer.find_by_exercise_question_id_and_user_id(params[:exercise_question_id], User.current.id)
|
||||
if ea.nil?
|
||||
# ea为空之前尚未答题,添加答案
|
||||
if params[:answer_text].nil? || params[:answer_text].blank?
|
||||
#用户提交空答案,视作不作答
|
||||
@percent = get_percent(@exercise,User.current)
|
||||
render :json => {:text => "",:percent => format("%.2f", @percent)}
|
||||
else
|
||||
#添加答案
|
||||
ea = ExerciseAnswer.new
|
||||
ea.user_id = User.current.id
|
||||
ea.exercise_question_id = params[:exercise_question_id]
|
||||
ea.answer_text = params[:answer_text]
|
||||
if ea.save
|
||||
uncomplete_question = get_uncomplete_question(@exercise, User.current)
|
||||
if uncomplete_question.count < 1
|
||||
complete = 1;
|
||||
else
|
||||
complete = 0;
|
||||
end
|
||||
@percent = get_percent(@exercise,User.current)
|
||||
render :json => {:text => ea.answer_text,:complete => complete,:percent => format("%.2f",@percent)}
|
||||
else
|
||||
render :json => {:text => "failure"}
|
||||
end
|
||||
end
|
||||
else
|
||||
# ea不为空说明用户之前已作答
|
||||
if params[:answer_text].nil? || params[:answer_text].blank?
|
||||
# 用户提交空答案,视为删除答案
|
||||
if ea.delete
|
||||
@percent = get_percent(@exercise,User.current)
|
||||
render :json => {:text => "",:percent => format("%.2f", @percent)}
|
||||
else
|
||||
render :json => {:text => "failure"}
|
||||
end
|
||||
else
|
||||
#用户修改答案
|
||||
ea.answer_text = params[:answer_text]
|
||||
if ea.save
|
||||
@percent = get_percent(@exercise,User.current)
|
||||
render :json => {:text => ea.answer_text,:percent => format("%.2f", @percent)}
|
||||
else
|
||||
render :json => {:text => "failure"}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
else
|
||||
render :json => {:text => "failure"}
|
||||
end
|
||||
end
|
||||
|
||||
# 提交问卷
|
||||
def commit_exercise
|
||||
# 老师不需要提交
|
||||
if User.current.allowed_to?(:as_teacher,@course)
|
||||
if @exercise.publish_time.nil?
|
||||
@exercise.update_attributes(:show_result => params[:show_result])
|
||||
@exercise.update_attributes(:exercise_status => 2)
|
||||
@exercise.update_attributes(:publish_time => Time.now)
|
||||
course = @exercise.course
|
||||
course.members.each do |m|
|
||||
@exercise.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => course.id, :viewed => false, :status => 2)
|
||||
end
|
||||
redirect_to exercise_url(@exercise)
|
||||
return
|
||||
elsif @exercise.publish_time > Time.now
|
||||
@exercise.update_attributes(:show_result => params[:show_result])
|
||||
redirect_to exercise_url(@exercise)
|
||||
return
|
||||
end
|
||||
@exercise.update_attributes(:show_result => params[:show_result])
|
||||
redirect_to exercise_url(@exercise)
|
||||
# REDO: 提示提交成功
|
||||
else
|
||||
# 更新提交状态
|
||||
cur_exercise_user = ExerciseUser.where("user_id =? and exercise_id=?", User.current, @exercise.id).first
|
||||
cur_exercise_user.update_attributes(:status => 1)
|
||||
# 答题过程中需要统计完成量
|
||||
@uncomplete_question = get_uncomplete_question(@exercise, User.current)
|
||||
# 获取改学生的考试得分
|
||||
@score = calculate_student_score(@exercise, User.current)
|
||||
# @score = 100
|
||||
if @uncomplete_question.count < 1
|
||||
# 查看是否有已提交记录
|
||||
cur_exercise_user.score = @score
|
||||
if cur_exercise_user.save
|
||||
#redirect_to poll_index_path(:polls_group_id => @course.id,:polls_type => 'Course')
|
||||
@status = 0 #提交成功
|
||||
else
|
||||
@status = 2 #未知错误
|
||||
end
|
||||
else
|
||||
@status = 1 #有未做得必答题
|
||||
end
|
||||
@save = params[:save].to_i if params[:save]
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#查看学生的答卷情况
|
||||
def show_student_result
|
||||
@user = User.find params[:user_id]
|
||||
@can_edit_excercise = false
|
||||
@exercise_questions = @exercise.exercise_questions
|
||||
score = calculate_student_score(@exercise, @user)
|
||||
eu = get_exercise_user(@exercise.id, @user.id)
|
||||
eu.update_attributes(:score => score)
|
||||
@exercise_user = ExerciseUser.where("user_id =? and exercise_id=?", @user.id, @exercise.id).first
|
||||
respond_to do |format|
|
||||
format.html {render :layout => 'base_courses'}
|
||||
end
|
||||
end
|
||||
|
||||
# 计算学生得分
|
||||
def calculate_student_score(exercise, user)
|
||||
score = 0
|
||||
score1 = 0
|
||||
score2 = 0
|
||||
score3 = 0
|
||||
exercise_qustions = exercise.exercise_questions
|
||||
exercise_qustions.each do |question|
|
||||
answer = get_user_answer(question, user)
|
||||
standard_answer = get_user_standard_answer(question, user)
|
||||
unless answer.empty?
|
||||
# 问答题有多个答案
|
||||
if question.question_type == 3 && !standard_answer.empty?
|
||||
if standard_answer.include?(answer.first.answer_text)
|
||||
score1 = score1+ question.question_score unless question.question_score.nil?
|
||||
end
|
||||
elsif question.question_type == 1 && !standard_answer.nil?
|
||||
if answer.first.exercise_choice.choice_position == standard_answer.exercise_choice_id
|
||||
score2 = score2 + question.question_score unless question.question_score.nil?
|
||||
end
|
||||
elsif question.question_type == 2 && !standard_answer.nil?
|
||||
arr = get_mulscore(question, user)
|
||||
if arr.to_i == standard_answer.exercise_choice_id
|
||||
score3 = score3 + question.question_score unless question.question_score.nil?
|
||||
end
|
||||
# ecs = ExerciseAnswer.where("user_id =? and exercise_question_id =?", user.id, question.id)
|
||||
# arr = []
|
||||
# ecs.each do |ec|
|
||||
# arr << ec.exercise_choice.choice_position
|
||||
# end
|
||||
# arr.sort
|
||||
# arr = arr.join("")
|
||||
# if arr.to_i == standard_answer.exercise_choice_id
|
||||
# score3 = score + question.question_score unless question.question_score.nil?
|
||||
# end
|
||||
end
|
||||
end
|
||||
end
|
||||
score = score1 + score2 + score3
|
||||
end
|
||||
|
||||
private
|
||||
#测验列表转换为excel
|
||||
def exercise_to_xls items
|
||||
xls_report = StringIO.new
|
||||
book = Spreadsheet::Workbook.new
|
||||
sheet1 = book.create_worksheet :name => "exercise"
|
||||
blue = Spreadsheet::Format.new :color => :blue, :weight => :bold, :size => 10
|
||||
sheet1.row(0).default_format = blue
|
||||
sheet1.row(0).concat([l(:excel_user_id),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_mail),l(:excel_class),l(:excel_f_score),l(:excel_commit_time)])
|
||||
count_row = 1
|
||||
items.each do |exercise|
|
||||
sheet1[count_row,0]=exercise.user.id
|
||||
sheet1[count_row,1] = exercise.user.lastname.to_s + exercise.user.firstname.to_s
|
||||
sheet1[count_row,2] = exercise.user.login
|
||||
sheet1[count_row,3] = exercise.user.user_extensions.student_id
|
||||
sheet1[count_row,4] = exercise.user.mail
|
||||
sheet1[count_row,5] = ""
|
||||
sheet1[count_row,6] = exercise.score
|
||||
sheet1[count_row,7] = format_time(exercise.created_at)
|
||||
count_row += 1
|
||||
end
|
||||
book.write xls_report
|
||||
xls_report.string
|
||||
end
|
||||
|
||||
# ExerciseUser记录用户是否已提交问卷有对应的记录则已提交,没有则新建一个
|
||||
def get_exercise_user exercise_id,user_id
|
||||
eu = ExerciseUser.find_by_exercise_id_and_user_id(exercise_id,user_id)
|
||||
if eu.nil?
|
||||
eu = ExerciseUser.new
|
||||
end
|
||||
eu
|
||||
end
|
||||
|
||||
# 获取当前学生回答问题的答案
|
||||
def get_user_answer(question,user)
|
||||
# user_answer = ExerciseAnswer.where("user_id=? and exercise_question_id=?", user.id, question.id).first
|
||||
user_answer = question.exercise_answers.where("#{ExerciseAnswer.table_name}.user_id = #{user.id}")
|
||||
user_answer
|
||||
end
|
||||
|
||||
# 获取问题的标准答案
|
||||
def get_user_standard_answer(question,user)
|
||||
if question.question_type == 3
|
||||
standard_answer =[]
|
||||
question.exercise_standard_answers.each do |answer|
|
||||
standard_answer << answer.answer_text
|
||||
end
|
||||
else
|
||||
standard_answer = question.exercise_standard_answers.first
|
||||
end
|
||||
standard_answer
|
||||
end
|
||||
# 是否完成了答题
|
||||
def get_complete_question(exercise,user)
|
||||
questions = exercise.exercise_questions
|
||||
complete_question = []
|
||||
questions.each do |question|
|
||||
answers = get_user_answer(question,user)
|
||||
if !(answers.nil? || answers.count < 1)
|
||||
complete_question << question
|
||||
end
|
||||
end
|
||||
complete_question
|
||||
end
|
||||
|
||||
# 获取答题百分比
|
||||
def get_percent exercise,user
|
||||
complete_count = get_complete_question(exercise,user).count
|
||||
if exercise.exercise_questions.count == 0
|
||||
return 0
|
||||
else
|
||||
return (complete_count.to_f / exercise.exercise_questions.count.to_f)*100
|
||||
end
|
||||
end
|
||||
|
||||
def remove_invalid_exercise(course)
|
||||
exercises = course.exercises.where("exercise_name=?","")
|
||||
unless exercises.empty?
|
||||
exercises.each do |exercise|
|
||||
if exercise.exercise_questions.empty?
|
||||
exercise.destroy
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def find_exercise_and_course
|
||||
@exercise = Exercise.find params[:id]
|
||||
@course = Course.find @exercise.course_id
|
||||
rescue Exception => e
|
||||
render_404
|
||||
end
|
||||
|
||||
def find_course
|
||||
@course = Course.find params[:course_id]
|
||||
rescue Exception => e
|
||||
render_404
|
||||
end
|
||||
end
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
#encoding: utf-8
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||
#
|
||||
|
|
@ -16,14 +17,16 @@
|
|||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class FilesController < ApplicationController
|
||||
|
||||
layout 'base_projects' #by young
|
||||
layout 'base_projects' #by young
|
||||
|
||||
menu_item :files
|
||||
before_filter :auth_login1, :only => [:index]
|
||||
before_filter :logged_user_by_apptoken,:only => [:index]
|
||||
before_filter :find_project_by_project_id#, :except => [:getattachtype]
|
||||
before_filter :authorize, :except => [:getattachtype,:quote_resource_show,:search,:searchone4reload,:search_project,:quote_resource_show_project,:search_tag_attachment]
|
||||
before_filter :authorize, :except => [:create,:getattachtype,:quote_resource_show,:search,:searchone4reload,:search_project,:quote_resource_show_project,
|
||||
:search_tag_attachment,:subfield_upload_file,:search_org_subfield_tag_attachment,
|
||||
:search_tag_attachment,:quote_resource_show_org_subfield,:find_org_subfield_attache,
|
||||
:search_files_in_subfield,:upload_files_menu]
|
||||
|
||||
helper :sort
|
||||
include SortHelper
|
||||
|
|
@ -98,6 +101,7 @@ class FilesController < ApplicationController
|
|||
@sort = ""
|
||||
@order = ""
|
||||
@is_remote = true
|
||||
@q = params[:name].strip
|
||||
if params[:sort]
|
||||
order_by = params[:sort].split(":")
|
||||
@sort = order_by[0]
|
||||
|
|
@ -106,36 +110,94 @@ class FilesController < ApplicationController
|
|||
end
|
||||
sort = "#{@sort} #{@order}"
|
||||
end
|
||||
# show_attachments [@course]
|
||||
begin
|
||||
q = "%#{params[:name].strip}%"
|
||||
#(redirect_to stores_url, :notice => l(:label_sumbit_empty);return) if params[:name].blank?
|
||||
if params[:insite]
|
||||
if q == "%%"
|
||||
@result = []
|
||||
@searched_attach = paginateHelper @result,10
|
||||
@project_attachment_result = []
|
||||
@searched_attach = paginateHelper @project_attachment_result, 10
|
||||
else
|
||||
@result = find_public_attache q,sort
|
||||
@result = visable_attachemnts_insite @result,@project
|
||||
@searched_attach = paginateHelper @result,10
|
||||
@project_attachment_result = find_public_attache q,sort
|
||||
@project_attachment_result = visable_attachemnts_insite @project_attachment_result, @project
|
||||
@searched_attach = paginateHelper @project_attachment_result, 10
|
||||
end
|
||||
else
|
||||
@result = find_project_attache q,@project,sort
|
||||
@result = visable_attachemnts @result
|
||||
@searched_attach = paginateHelper @result,10
|
||||
@project_attachment_result = find_project_attache q, @project,sort
|
||||
@project_attachment_result = visable_attachemnts @project_attachment_result
|
||||
@searched_attach = paginateHelper @project_attachment_result,10
|
||||
@tag_list = get_project_tag_list @project
|
||||
end
|
||||
|
||||
#rescue Exception => e
|
||||
# #render 'stores'
|
||||
# redirect_to search_course_files_url
|
||||
end
|
||||
end
|
||||
|
||||
def search_files_in_subfield
|
||||
sort = ""
|
||||
@sort = ""
|
||||
@order = ""
|
||||
@is_remote = true
|
||||
@q = params[:name].strip
|
||||
if params[:sort]
|
||||
order_by = params[:sort].split(":")
|
||||
@sort = order_by[0]
|
||||
if order_by.count > 1
|
||||
@order = order_by[1]
|
||||
end
|
||||
sort = "#{@sort} #{@order}"
|
||||
end
|
||||
# show_attachments [@course]
|
||||
begin
|
||||
q = "%#{params[:name].strip}%"
|
||||
#(redirect_to stores_url, :notice => l(:label_sumbit_empty);return) if params[:name].blank?
|
||||
if params[:insite]
|
||||
if q == "%%"
|
||||
@result = []
|
||||
@searched_attach = paginateHelper @result,10
|
||||
else
|
||||
@result = find_public_attache q,sort
|
||||
@result = visable_attachemnts_insite @result,@org_subfield
|
||||
@searched_attach = paginateHelper @result,10
|
||||
end
|
||||
else
|
||||
@result = find_org_subfield_attache q,@org_subfield,sort
|
||||
@result = visable_attachemnts @result
|
||||
@searched_attach = paginateHelper @result,10
|
||||
@tag_list = attachment_tag_list @result
|
||||
end
|
||||
#rescue Exception => e
|
||||
# #render 'stores'
|
||||
# redirect_to search_course_files_url
|
||||
end
|
||||
@page = params[:page] || 1
|
||||
end
|
||||
|
||||
def find_course_attache keywords,course,sort = ""
|
||||
if sort == ""
|
||||
sort = "created_on DESC"
|
||||
end
|
||||
if keywords != "%%"
|
||||
resultSet = Attachment.where("attachments.container_type = 'Course' And attachments.container_id = '#{course.id}' AND filename LIKE :like ", like: "%#{keywords}%").
|
||||
reorder(sort)
|
||||
else
|
||||
resultSet = Attachment.where("attachments.container_type = 'Course' And attachments.container_id = '#{course.id}' "). reorder(sort)
|
||||
end
|
||||
#resultSet = Attachment.find_by_sql("SELECT `attachments`.* FROM `attachments` LEFT OUTER JOIN `homework_attaches` ON `attachments`.container_type = 'HomeworkAttach' AND `attachments`.container_id = `homework_attaches`.id LEFT OUTER JOIN `homework_for_courses` ON `homework_attaches`.bid_id = `homework_for_courses`.bid_id LEFT OUTER JOIN `homework_for_courses` AS H_C ON `attachments`.container_type = 'Bid' AND `attachments`.container_id = H_C.bid_id WHERE (`homework_for_courses`.course_id = 117 OR H_C.course_id = 117 OR (`attachments`.container_type = 'Course' AND `attachments`.container_id = 117)) AND `attachments`.filename LIKE '%#{keywords}%'").reorder("created_on DESC")
|
||||
end
|
||||
|
||||
def find_org_subfield_attache keywords,org_subfield,sort = ""
|
||||
if sort == ""
|
||||
sort = "created_on DESC"
|
||||
end
|
||||
if keywords != "%%"
|
||||
resultSet = Attachment.where("attachments.container_type = 'OrgSubfield' And attachments.container_id = '#{org_subfield.id}' AND filename LIKE :like ", like: "%#{keywords}%").
|
||||
reorder(sort)
|
||||
else
|
||||
resultSet = Attachment.where("attachments.container_type = 'OrgSubfield' And attachments.container_id = '#{org_subfield.id}' "). reorder(sort)
|
||||
end
|
||||
#resultSet = Attachment.find_by_sql("SELECT `attachments`.* FROM `attachments` LEFT OUTER JOIN `homework_attaches` ON `attachments`.container_type = 'HomeworkAttach' AND `attachments`.container_id = `homework_attaches`.id LEFT OUTER JOIN `homework_for_courses` ON `homework_attaches`.bid_id = `homework_for_courses`.bid_id LEFT OUTER JOIN `homework_for_courses` AS H_C ON `attachments`.container_type = 'Bid' AND `attachments`.container_id = H_C.bid_id WHERE (`homework_for_courses`.course_id = 117 OR H_C.course_id = 117 OR (`attachments`.container_type = 'Course' AND `attachments`.container_id = 117)) AND `attachments`.filename LIKE '%#{keywords}%'").reorder("created_on DESC")
|
||||
end
|
||||
|
||||
|
|
@ -143,23 +205,10 @@ class FilesController < ApplicationController
|
|||
if sort == ""
|
||||
sort = "created_on DESC"
|
||||
end
|
||||
ids = ""
|
||||
len = 0
|
||||
count = project.versions.count
|
||||
project.versions.each do |version|
|
||||
len = len + 1
|
||||
if len != count
|
||||
ids += version.id.to_s + ','
|
||||
else
|
||||
ids += version.id.to_s
|
||||
end
|
||||
end
|
||||
if ids.blank?
|
||||
resultSet = Attachment.where("attachments.container_type = 'Project' And attachments.container_id = '#{project.id}' AND filename LIKE :like ", like: "%#{keywords}%").
|
||||
reorder(sort)
|
||||
if keywords != "%%"
|
||||
resultSet = Attachment.where("attachments.container_type = 'Project' And attachments.container_id = '#{project.id}' AND filename LIKE :like ", like: "%#{keywords}%").reorder(sort)
|
||||
else
|
||||
resultSet = Attachment.where("((attachments.container_type = 'Project' And attachments.container_id = '#{project.id}') OR (container_type = 'Version' AND container_id IN (#{ids}))) AND filename LIKE :like ", like: "%#{keywords}%").
|
||||
reorder(sort)
|
||||
resultSet = Attachment.where("attachments.container_type = 'Project' And attachments.container_id = '#{project.id}' "). reorder(sort)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -176,23 +225,16 @@ class FilesController < ApplicationController
|
|||
|
||||
def index
|
||||
@flag = params[:flag] || false
|
||||
#sort_init 'filename', 'asc'
|
||||
# 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"
|
||||
sort = ""
|
||||
@sort = ""
|
||||
@order = ""
|
||||
@is_remote = false
|
||||
if params[:project_id]
|
||||
@isproject = true
|
||||
|
||||
@page = params[:page] ? params[:page].to_i + 1 : 2
|
||||
@container_type = 0
|
||||
if params[:sort]
|
||||
params[:sort].split(",").each do |sort_type|
|
||||
order_by = sort_type.split(":")
|
||||
|
||||
case order_by[0]
|
||||
when "filename"
|
||||
attribute = "filename"
|
||||
|
|
@ -230,25 +272,19 @@ class FilesController < ApplicationController
|
|||
else
|
||||
sort = "#{Attachment.table_name}.created_on desc"
|
||||
end
|
||||
# @containers = [ Project.includes(:attachments).find(@project.id)]
|
||||
# @containers += @project.versions.includes(:attachments).all
|
||||
|
||||
@containers = [ Project.includes(:attachments).find(@project.id)]
|
||||
@containers += @project.versions.includes(:attachments).all
|
||||
|
||||
ids = []
|
||||
@containers.each do |c|
|
||||
ids += c.attachments.pluck(:id)
|
||||
end
|
||||
@containers = [Struct.new(:attachments).new(Attachment.where('id in (?)',ids).reorder(sort))]
|
||||
@containers = [ Project.includes(:attachments).reorder(sort).find(@project.id)]
|
||||
|
||||
show_attachments @containers
|
||||
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.js
|
||||
end
|
||||
elsif params[:course_id]
|
||||
@isproject = false
|
||||
@tag_list = attachment_tag_list @all_attachments
|
||||
|
||||
render :layout => 'base_projects'
|
||||
elsif params[:course_id]
|
||||
@container_type = 1
|
||||
@page = params[:page] ? params[:page].to_i + 1 : 2
|
||||
if params[:sort]
|
||||
params[:sort].split(",").each do |sort_type|
|
||||
order_by = sort_type.split(":")
|
||||
|
|
@ -298,6 +334,56 @@ class FilesController < ApplicationController
|
|||
@tag_list = attachment_tag_list @all_attachments
|
||||
|
||||
render :layout => 'base_courses'
|
||||
elsif params[:org_subfield_id]
|
||||
if params[:sort]
|
||||
params[:sort].split(",").each do |sort_type|
|
||||
order_by = sort_type.split(":")
|
||||
|
||||
case order_by[0]
|
||||
when "filename"
|
||||
attribute = "filename"
|
||||
when "size"
|
||||
attribute = "filesize"
|
||||
when "attach_type"
|
||||
attribute = "attachtype"
|
||||
when "content_type"
|
||||
attribute = "created_on"
|
||||
when "field_file_dense"
|
||||
attribute = "is_public"
|
||||
when "downloads"
|
||||
attribute = "downloads"
|
||||
when "created_on"
|
||||
attribute = "created_on"
|
||||
when "quotes"
|
||||
attribute = "quotes"
|
||||
else
|
||||
attribute = "created_on"
|
||||
end
|
||||
@sort = order_by[0]
|
||||
@order = order_by[1]
|
||||
if order_by.count == 1 && attribute
|
||||
sort += "#{Attachment.table_name}.#{attribute} asc "
|
||||
if sort_type != params[:sort].split(",").last
|
||||
sort += ","
|
||||
end
|
||||
elsif order_by.count == 2 && order_by[1]
|
||||
sort += "#{Attachment.table_name}.#{attribute} #{order_by[1]} "
|
||||
if sort_type != params[:sort].split(",").last
|
||||
sort += ","
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
sort = "#{Attachment.table_name}.created_on desc"
|
||||
end
|
||||
@container_type = 2
|
||||
@containers = [ OrgSubfield.includes(:attachments).reorder(sort).find(@org_subfield.id)]
|
||||
@organization = Organization.find(@containers.first.organization_id)
|
||||
show_attachments @containers
|
||||
@tag_list = attachment_tag_list @all_attachments
|
||||
@page = params[:page] || 1
|
||||
render :layout => 'base_org'
|
||||
# @subfield = params[:org_subfield_id]
|
||||
end
|
||||
|
||||
end
|
||||
|
|
@ -312,6 +398,12 @@ class FilesController < ApplicationController
|
|||
@can_quote = attachment_candown @file
|
||||
end
|
||||
|
||||
def quote_resource_show_org_subfield
|
||||
@file = Attachment.find(params[:id])
|
||||
@org_subfield = OrgSubfield.find(params[:org_subfield_id])
|
||||
@can_quote = attachment_candown @file
|
||||
end
|
||||
|
||||
def new
|
||||
@versions = @project.versions.sort
|
||||
@course_tag = @project.project_type
|
||||
|
|
@ -333,14 +425,41 @@ class FilesController < ApplicationController
|
|||
#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])
|
||||
render_attachment_warning_if_needed(container)
|
||||
|
||||
if params[:in_project_toolbar]
|
||||
@in_project_toolbar = params[:in_project_toolbar]
|
||||
end
|
||||
# 发送邮件
|
||||
attachments = Attachment.attach_filesex(@project, params[:attachments], params[:attachment_type])
|
||||
if !attachments.empty? && !attachments[:files].blank? && Setting.notified_events.include?('file_added')
|
||||
Mailer.run.attachments_added(attachments[:files])
|
||||
end
|
||||
|
||||
# end
|
||||
if params[:project_attachment_type] && params[:project_attachment_type].is_a?(Array)
|
||||
params[:project_attachment_type].each do |type|
|
||||
tag_name = get_project_tag_name_by_type_nmuber type
|
||||
if !attachments.empty? && attachments[:files] && tag_name != ""
|
||||
attachments[:files].each do |attachment|
|
||||
attachment.tag_list.add(tag_name)
|
||||
attachment.save
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
if params[:project_attachment_type] && params[:project_attachment_type] != "6"
|
||||
tag_name = get_project_tag_name_by_type_nmuber params[:project_attachment_type]
|
||||
if !attachments.empty? && attachments[:files] && tag_name != ""
|
||||
attachments[:files].each do |attachment|
|
||||
attachment.tag_list.add(tag_name)
|
||||
attachment.save
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
# 更新资源总数, 根据上传的附件数累加
|
||||
unless @project.project_score.nil?
|
||||
@project.project_score.update_attribute(:attach_num, @project.project_score.attach_num + attachments[:files].count)
|
||||
end
|
||||
# end
|
||||
# TODO: 临时用 nyan
|
||||
sort_init 'created_on', 'desc'
|
||||
sort_update 'created_on' => "#{Attachment.table_name}.created_on",
|
||||
|
|
@ -348,14 +467,11 @@ 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
|
||||
@containers += @project.versions.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").all.sort
|
||||
|
||||
@containers = [Project.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").find(@project.id)]
|
||||
show_attachments @containers
|
||||
|
||||
@tag_list = attachment_tag_list @all_attachments
|
||||
@attachtype = 0
|
||||
@contenttype = 0
|
||||
|
||||
respond_to do |format|
|
||||
format.js
|
||||
format.html {
|
||||
|
|
@ -364,33 +480,38 @@ class FilesController < ApplicationController
|
|||
end
|
||||
elsif @course
|
||||
@addTag=false
|
||||
if params[:in_course_toolbar]
|
||||
@in_course_toolbar = params[:in_course_toolbar]
|
||||
end
|
||||
attachments = Attachment.attach_filesex(@course, params[:attachments], params[:attachment_type])
|
||||
|
||||
if !attachments.empty? && !attachments[:files].blank? && Setting.notified_events.include?('file_added')
|
||||
Mailer.run.attachments_added(attachments[:files])
|
||||
end
|
||||
|
||||
if params[:course_attachment_type] && params[:course_attachment_type] != "5"
|
||||
case params[:course_attachment_type]
|
||||
when "1"
|
||||
tag_name = l(:label_courseware)
|
||||
when "2"
|
||||
tag_name = l(:label_software)
|
||||
when "3"
|
||||
tag_name = l(:label_media)
|
||||
when "4"
|
||||
tag_name = l(:label_code)
|
||||
else
|
||||
tag_name = ""
|
||||
if params[:course_attachment_type] && params[:course_attachment_type].is_a?(Array)
|
||||
params[:course_attachment_type].each do |type|
|
||||
tag_name = get_tag_name_by_type_number type
|
||||
if !attachments.empty? && attachments[:files] && tag_name != ""
|
||||
attachments[:files].each do |attachment|
|
||||
attachment.tag_list.add(tag_name)
|
||||
attachment.save
|
||||
end
|
||||
end
|
||||
end
|
||||
if !attachments.empty? && attachments[:files] && tag_name != ""
|
||||
attachments[:files].each do |attachment|
|
||||
attachment.tag_list.add(tag_name)
|
||||
attachment.save
|
||||
else
|
||||
if params[:course_attachment_type] && params[:course_attachment_type] != "5"
|
||||
tag_name = get_tag_name_by_type_number params[:course_attachment_type]
|
||||
if !attachments.empty? && attachments[:files] && tag_name != ""
|
||||
attachments[:files].each do |attachment|
|
||||
attachment.tag_list.add(tag_name)
|
||||
attachment.save
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# 更新课程英雄榜得分
|
||||
update_contributor_score(@course, attachments[:files].first)
|
||||
# end
|
||||
# TODO: 临时用 nyan
|
||||
sort_init 'created_on', 'desc'
|
||||
sort_update 'created_on' => "#{Attachment.table_name}.created_on",
|
||||
|
|
@ -412,11 +533,106 @@ class FilesController < ApplicationController
|
|||
redirect_to course_files_url(@course)
|
||||
}
|
||||
end
|
||||
end
|
||||
elsif @org_subfield
|
||||
@addTag=false
|
||||
attachments = Attachment.attach_filesex(@org_subfield, params[:attachments], params[:org_subfield_attachment_type])
|
||||
|
||||
if params[:org_subfield_attachment_type] && params[:org_subfield_attachment_type].is_a?(Array)
|
||||
params[:org_subfield_attachment_type].each do |type|
|
||||
tag_name = get_tag_name_by_type_number type
|
||||
if !attachments.empty? && attachments[:files] && tag_name != ""
|
||||
attachments[:files].each do |attachment|
|
||||
attachment.tag_list.add(tag_name)
|
||||
attachment.save
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
if params[:org_subfield_attachment_type] && params[:org_subfield_attachment_type] != "5"
|
||||
tag_name = get_tag_name_by_type_number params[:org_subfield_attachment_type]
|
||||
if !attachments.empty? && attachments[:files] && tag_name != ""
|
||||
attachments[:files].each do |attachment|
|
||||
attachment.tag_list.add(tag_name)
|
||||
attachment.save
|
||||
end
|
||||
end
|
||||
end
|
||||
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 = [OrgSubfield.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").find(@org_subfield.id)]
|
||||
|
||||
show_attachments @containers
|
||||
@tag_list = attachment_tag_list @all_attachments
|
||||
@attachtype = 0
|
||||
@contenttype = 0
|
||||
|
||||
respond_to do |format|
|
||||
format.js
|
||||
# format.html {
|
||||
# redirect_to org_subfield_files_url(@org_subfield)
|
||||
# }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def update_contributor_score(course, file )
|
||||
unless file.author.allowed_to?(:as_teacher, course)
|
||||
course_contributor_score = CourseContributorScore.where("course_id =? and user_id =?", course.id, file.author.id).first
|
||||
if course_contributor_score.nil?
|
||||
CourseContributorScore.create(:course_id => course.id, :user_id => file.author.id, :message_num => 0, :message_reply_num => 0,
|
||||
:news_reply_num => 0, :resource_num => 5, :journal_num => 0, :journal_reply_num => 0, :total_score => 5)
|
||||
else
|
||||
score = course_contributor_score.resource_num + 5
|
||||
total_score = course_contributor_score.total_score + 5
|
||||
course_contributor_score.update_attributes(:resource_num => score, :total_score => total_score)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def get_project_tag_name_by_type_nmuber type
|
||||
case type
|
||||
when "1"
|
||||
tag_name = "软件版本"
|
||||
when "2"
|
||||
tag_name = "文档"
|
||||
when "3"
|
||||
tag_name = "代码"
|
||||
when "4"
|
||||
tag_name = "媒体"
|
||||
when "5"
|
||||
tag_name = "论文"
|
||||
when "6"
|
||||
tag_name = "其它"
|
||||
else
|
||||
tag_name = ""
|
||||
end
|
||||
end
|
||||
|
||||
def get_tag_name_by_type_number type
|
||||
case type
|
||||
when "1"
|
||||
tag_name = l(:label_courseware)
|
||||
when "2"
|
||||
tag_name = l(:label_software)
|
||||
when "3"
|
||||
tag_name = l(:label_media)
|
||||
when "4"
|
||||
tag_name = l(:label_code)
|
||||
when "6"
|
||||
tag_name = "论文"
|
||||
else
|
||||
tag_name = ""
|
||||
end
|
||||
end
|
||||
|
||||
def tag_saveEx
|
||||
@tags = params[:tag_name][:name]
|
||||
@obj_id = params[:object_id]
|
||||
|
|
@ -551,15 +767,70 @@ class FilesController < ApplicationController
|
|||
end
|
||||
|
||||
q = "%#{@q.strip}%"
|
||||
@result = find_course_attache q,@course,sort
|
||||
if @project
|
||||
@result = find_project_attache q, @project,sort
|
||||
else
|
||||
@result = find_course_attache q,@course,sort
|
||||
end
|
||||
@result = visable_attachemnts @result
|
||||
@result = @result.select{|attachment| attachment.tag_list.include?(@tag_name)}
|
||||
if params[:other]
|
||||
if @project
|
||||
@result = @result.select{|attachment| !attachment.tag_list.include?('软件版本') && !attachment.tag_list.include?('文档') && !attachment.tag_list.include?('代码') && !attachment.tag_list.include?('媒体') && !attachment.tag_list.include?('论文') }
|
||||
else
|
||||
@result = @result.select{|attachment|
|
||||
!attachment.tag_list.include?('课件') &&
|
||||
!attachment.tag_list.include?('软件') &&
|
||||
!attachment.tag_list.include?('媒体') &&
|
||||
!attachment.tag_list.include?('代码') &&
|
||||
!attachment.tag_list.include?('论文') }
|
||||
end
|
||||
else
|
||||
@result = @result.select{|attachment| attachment.tag_list.include?(@tag_name)} unless @tag_name.blank?
|
||||
end
|
||||
@searched_attach = paginateHelper @result,10
|
||||
@tag_list = get_course_tag_list @course
|
||||
if @project
|
||||
@tag_list = get_project_tag_list @project
|
||||
@result_search_project = @result
|
||||
else
|
||||
@tag_list = get_course_tag_list @course
|
||||
end
|
||||
respond_to do |format|
|
||||
format.js
|
||||
# format.html
|
||||
end
|
||||
end
|
||||
|
||||
#搜索资源栏目的指定TAG的资源列表
|
||||
def search_org_subfield_tag_attachment
|
||||
@q,@tag_name,@order = params[:q],params[:tag_name]
|
||||
@is_remote = true
|
||||
if params[:sort]
|
||||
order_by = params[:sort].split(":")
|
||||
@sort = order_by[0]
|
||||
if order_by.count > 1
|
||||
@order = order_by[1]
|
||||
end
|
||||
sort = "#{@sort} #{@order}"
|
||||
end
|
||||
|
||||
q = "%#{@q.strip}%"
|
||||
@result = find_org_subfield_attache q,@org_subfield,sort
|
||||
@result = visable_attachemnts @result
|
||||
@result = @result.select{|attachment| attachment.tag_list.include?(@tag_name)} unless @tag_name.blank?
|
||||
@searched_attach = paginateHelper @result,10
|
||||
@tag_list = get_org_subfield_tag_list @org_subfield
|
||||
|
||||
respond_to do |format|
|
||||
format.js
|
||||
# format.html
|
||||
end
|
||||
end
|
||||
|
||||
def subfield_upload_file
|
||||
@org_subfield = OrgSubfield.find(params[:org_subfield_id])
|
||||
end
|
||||
|
||||
def upload_files_menu
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ class ForumsController < ApplicationController
|
|||
before_filter :find_forum_if_available
|
||||
before_filter :authenticate_user_edit, :only => [:edit, :update]
|
||||
before_filter :authenticate_user_destroy, :only => [:destroy]
|
||||
before_filter :require_login, :only => [:new, :create]
|
||||
before_filter :require_login, :only => [:new, :create,:destroy,:update,:edit]
|
||||
|
||||
helper :sort
|
||||
include SortHelper
|
||||
|
|
@ -97,7 +97,24 @@ class ForumsController < ApplicationController
|
|||
|
||||
def index
|
||||
@offset, @limit = api_offset_and_limit({:limit => 10})
|
||||
@forums_all = Forum.reorder("sticky DESC")
|
||||
if(params[:reorder_complex])
|
||||
@type="reorder_complex"
|
||||
@str=params[:reorder_complex]
|
||||
@forums_all = Forum.reorder("topic_count #{params[:reorder_complex]},updated_at #{params[:reorder_complex]}")
|
||||
elsif(params[:reorder_popu])
|
||||
@type="reorder_popu"
|
||||
@str=params[:reorder_popu]
|
||||
@forums_all = Forum.reorder("topic_count #{params[:reorder_popu]}")
|
||||
elsif(params[:reorder_time])
|
||||
@type="reorder_time"
|
||||
@str=params[:reorder_time]
|
||||
@forums_all = Forum.reorder("updated_at #{params[:reorder_time]}")
|
||||
else
|
||||
params[:reorder_complex] = "desc"
|
||||
@type="reorder_complex"
|
||||
@str=params[:reorder_complex]
|
||||
@forums_all = Forum.reorder("topic_count desc,updated_at desc")
|
||||
end
|
||||
@forums_count = @forums_all.count
|
||||
@forums_pages = Paginator.new @forums_count, @limit, params['page']
|
||||
|
||||
|
|
@ -106,6 +123,7 @@ class ForumsController < ApplicationController
|
|||
#@forums = Forum.all
|
||||
respond_to do |format|
|
||||
format.html # index.html.erb
|
||||
format.js
|
||||
format.json { render json: @forums }
|
||||
end
|
||||
end
|
||||
|
|
@ -113,11 +131,25 @@ class ForumsController < ApplicationController
|
|||
# GET /forums/1
|
||||
# GET /forums/1.json
|
||||
def show
|
||||
sort_init 'updated_at', 'desc'
|
||||
sort_update 'created_at' => "#{Memo.table_name}.created_at",
|
||||
'replies' => "#{Memo.table_name}.replies_count",
|
||||
'updated_at' => "COALESCE (last_replies_memos.created_at, #{Memo.table_name}.created_at)"
|
||||
|
||||
# sort_init 'updated_at', 'desc'
|
||||
# sort_update 'created_at' => "#{Memo.table_name}.created_at",
|
||||
# 'replies' => "#{Memo.table_name}.replies_count",
|
||||
# 'updated_at' => "COALESCE (last_replies_memos.created_at, #{Memo.table_name}.created_at)"
|
||||
order = ""
|
||||
@order_str = ""
|
||||
if(params[:reorder_complex])
|
||||
order = " last_replies_memos.created_at #{params[:reorder_complex]}, #{Memo.table_name}.created_at #{params[:reorder_complex]}"
|
||||
@order_str = "reorder_complex="+params[:reorder_complex]
|
||||
elsif(params[:reorder_popu])
|
||||
order = "replies_count #{params[:reorder_popu]}"
|
||||
@order_str = "reorder_popu="+params[:reorder_popu]
|
||||
elsif(params[:reorder_time])
|
||||
order = "#{Memo.table_name}.updated_at #{params[:reorder_time]}"
|
||||
@order_str = "reorder_time="+params[:reorder_time]
|
||||
else
|
||||
order = "#{Memo.table_name}.updated_at desc"
|
||||
@order_str = "reorder_time=desc"
|
||||
end
|
||||
@memo = Memo.new(:forum => @forum)
|
||||
@topic_count = @forum.topics.count
|
||||
@topic_pages = Paginator.new @topic_count, per_page_option, params['page']
|
||||
|
|
@ -126,19 +158,15 @@ class ForumsController < ApplicationController
|
|||
includes(:last_reply).
|
||||
limit(@topic_pages.per_page).
|
||||
offset(@topic_pages.offset).
|
||||
order(sort_clause).
|
||||
reorder(order).
|
||||
preload(:author, {:last_reply => :author}).
|
||||
all
|
||||
@memos
|
||||
# @offset, @limit = api_offset_and_limit({:limit => 10})
|
||||
# @forum = Forum.find(params[:id])
|
||||
# @memos_all = @forum.topics
|
||||
# @topic_count = @memos_all.count
|
||||
# @topic_pages = Paginator.new @topic_count, @limit, params['page']
|
||||
|
||||
# @offset ||= @topic_pages.offset
|
||||
# @memos = @memos_all.offset(@offset).limit(@limit).all
|
||||
@my_topic_count = Memo.where("forum_id = #{@forum.id} and author_id = #{User.current.id} and parent_id is null").count
|
||||
@my_replies_count = Memo.where("forum_id = #{@forum.id} and author_id = #{User.current.id} and parent_id is not null").count
|
||||
@errors = params[:errors]
|
||||
respond_to do |format|
|
||||
format.js
|
||||
format.html {
|
||||
render :layout => 'base_forums'
|
||||
}# show.html.erb
|
||||
|
|
@ -172,20 +200,23 @@ class ForumsController < ApplicationController
|
|||
# Author lizanle
|
||||
# Description after save后需要进行资源记录的更新
|
||||
# owner_type = 2 对应的是 forum
|
||||
@save_flag=true
|
||||
if params[:asset_id]
|
||||
ids = params[:asset_id].split(',')
|
||||
update_kindeditor_assets_owner ids ,@forum.id,OwnerTypeHelper::FORUM
|
||||
end
|
||||
#end
|
||||
respond_to do |format|
|
||||
|
||||
format.js
|
||||
format.html { redirect_to @forum, notice: l(:label_forum_create_succ) }
|
||||
format.json { render json: @forum, status: :created, location: @forum }
|
||||
end
|
||||
|
||||
else
|
||||
@save_flag=false
|
||||
respond_to do |format|
|
||||
flash.now[:error] = "#{l :label_forum_create_fail}: #{@forum.errors.full_messages[0]}"
|
||||
format.js
|
||||
format.html { render action: "new" }
|
||||
format.json { render json: @forum.errors, status: :unprocessable_entity }
|
||||
end
|
||||
|
|
@ -199,10 +230,12 @@ class ForumsController < ApplicationController
|
|||
|
||||
respond_to do |format|
|
||||
if @forum.update_attributes(params[:forum])
|
||||
format.js {render :text=> true}
|
||||
format.html { redirect_to @forum, notice: l(:label_forum_update_succ) }
|
||||
format.json { head :no_content }
|
||||
else
|
||||
flash.now[:error] = "#{l :label_forum_update_fail}: #{@forum.errors.full_messages[0]}"
|
||||
format.js { render :text=> false}
|
||||
format.html { render action: "edit" }
|
||||
format.json { render json: @forum.errors, status: :unprocessable_entity }
|
||||
end
|
||||
|
|
@ -261,6 +294,52 @@ class ForumsController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
#检查forum的名字
|
||||
def check_forum_name
|
||||
forum_name_exist = true
|
||||
if params[:forum_id]
|
||||
forum_name_exist = Forum.where("name = '#{params[:forum_name]}' and id != #{params[:forum_id]}").count >= 1 ? true : false
|
||||
else
|
||||
forum_name_exist = Forum.where("name = '#{params[:forum_name]}' ").count >= 1 ? true : false
|
||||
end
|
||||
render :text => forum_name_exist
|
||||
end
|
||||
|
||||
#添加论坛tag
|
||||
def add_forum_tag
|
||||
@forum = Forum.find(params[:id])
|
||||
unless @forum.nil?
|
||||
@forum.tag_list.add(params[:tag_str].split(','))
|
||||
@forum.save
|
||||
end
|
||||
respond_to do |format|
|
||||
format.js {render :delete_forum_tag}
|
||||
end
|
||||
end
|
||||
|
||||
#删除forum的tag
|
||||
def delete_forum_tag
|
||||
@tag_id = (ActsAsTaggableOn::Tag.find_by_name(params[:tag_name])).id
|
||||
#forum的taggable_type = 5
|
||||
@taggings = ActsAsTaggableOn::Tagging.find_by_tag_id_and_taggable_id_and_taggable_type(@tag_id,params[:id],'Forum')
|
||||
|
||||
unless @taggings.nil?
|
||||
@taggings.delete
|
||||
end
|
||||
|
||||
# 是否还有其他记录 引用了 tag_id
|
||||
@tagging = ActsAsTaggableOn::Tagging.find_by_tag_id(@tag_id)
|
||||
# 如果taggings表中记录已经不存在 ,那么检查tags表 作删除动作
|
||||
if @tagging.nil?
|
||||
@tag = ActsAsTaggableOn::Tag.find_by_id(@tag_id)
|
||||
@tag.delete unless @tag.nil?
|
||||
end
|
||||
@forum = Forum.find(params[:id])
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def find_forum_if_available
|
||||
|
|
|
|||
|
|
@ -42,8 +42,8 @@ class GanttsController < ApplicationController
|
|||
|
||||
respond_to do |format|
|
||||
format.html { render :action => "show", :layout => 'base_projects' }#by young
|
||||
format.png { send_data(@gantt.to_image, :disposition => 'inline', :type => 'image/png', :filename => "#{basename}.png") } if @gantt.respond_to?('to_image')
|
||||
format.pdf { send_data(@gantt.to_pdf, :type => 'application/pdf', :filename => "#{basename}.pdf") }
|
||||
format.png { send_data(@gantt.to_image, :disposition => 'inline', :type => 'image/png', :filename => filename_for_content_disposition("#{basename}.png")) } if @gantt.respond_to?('to_image')
|
||||
format.pdf { send_data(@gantt.to_pdf, :type => 'application/pdf', :filename => filename_for_content_disposition("#{basename}.pdf") ) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,12 +0,0 @@
|
|||
#added by baiyu
|
||||
class GitUsageController < ApplicationController
|
||||
layout "new_base"
|
||||
def ch_usage
|
||||
|
||||
end
|
||||
|
||||
def en_usage
|
||||
|
||||
end
|
||||
end
|
||||
#end
|
||||
|
|
@ -33,7 +33,7 @@ class HomeworkAttachController < ApplicationController
|
|||
format.js
|
||||
format.xls {
|
||||
send_data(homework_to_xls(@all_homework_list), :type => "text/excel;charset=utf-8; header=present",
|
||||
:filename => "#{@course.teacher.lastname.to_s + @course.teacher.firstname}_#{@course.name}_#{@course.time.to_s + @course.term}_#{@bid.name}#{l(:excel_homework_list)}(#{l(:excel_not_rated)}).xls")
|
||||
:filename => filename_for_content_disposition("#{@course.teacher.lastname.to_s + @course.teacher.firstname}_#{@course.name}_#{@course.time.to_s + @course.term}_#{@bid.name}#{l(:excel_homework_list)}(#{l(:excel_not_rated)}).xls") )
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
@ -66,7 +66,7 @@ class HomeworkAttachController < ApplicationController
|
|||
format.js
|
||||
format.xls {
|
||||
send_data(homework_to_xls(all_homework_list), :type => "text/excel;charset=utf-8; header=present",
|
||||
:filename => "#{@course.teacher.lastname.to_s + @course.teacher.firstname}_#{@course.name}_#{@course.time.to_s + @course.term}_#{@bid.name}#{l(:excel_homework_list)}(#{l(:excel_been_rated)}).xls")
|
||||
:filename => filename_for_content_disposition("#{@course.teacher.lastname.to_s + @course.teacher.firstname}_#{@course.name}_#{@course.time.to_s + @course.term}_#{@bid.name}#{l(:excel_homework_list)}(#{l(:excel_been_rated)}).xls") )
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
@ -101,7 +101,7 @@ class HomeworkAttachController < ApplicationController
|
|||
format.js
|
||||
format.xls {
|
||||
send_data(homework_to_xls(all_homework_list), :type => "text/excel;charset=utf-8; header=present",
|
||||
:filename => "#{@course.teacher.lastname.to_s + @course.teacher.firstname}_#{@course.name}_#{@course.time.to_s + @course.term}_#{@bid.name}#{l(:excel_homework_list)}.xls")
|
||||
:filename => filename_for_content_disposition("#{@course.teacher.lastname.to_s + @course.teacher.firstname}_#{@course.name}_#{@course.time.to_s + @course.term}_#{@bid.name}#{l(:excel_homework_list)}.xls") )
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -3,280 +3,119 @@ class HomeworkCommonController < ApplicationController
|
|||
require 'json'
|
||||
require "base64"
|
||||
layout "base_courses"
|
||||
before_filter :find_course, :only => [:index,:new,:create,:next_step]
|
||||
before_filter :find_homework, :only => [:edit,:update,:alert_anonymous_comment,:start_anonymous_comment,:stop_anonymous_comment,:destroy]
|
||||
before_filter :teacher_of_course, :only => [:new, :create, :edit, :update, :destroy, :start_anonymous_comment, :stop_anonymous_comment, :alert_anonymous_comment]
|
||||
|
||||
include StudentWorkHelper
|
||||
before_filter :find_course, :only => [:index,:new,:create]
|
||||
before_filter :find_homework, :only => [:edit,:update,:alert_anonymous_comment,:start_anonymous_comment,:stop_anonymous_comment,:destroy,:start_evaluation_set,:set_evaluation_attr,:score_rule_set,:alert_forbidden_anonymous_comment]
|
||||
before_filter :teacher_of_course, :only => [:new, :create, :edit, :update, :destroy, :start_anonymous_comment, :stop_anonymous_comment, :alert_anonymous_comment,:start_evaluation_set,:set_evaluation_attr,:score_rule_set,:alert_forbidden_anonymous_comment]
|
||||
before_filter :member_of_course, :only => [:index]
|
||||
|
||||
def index
|
||||
homeworks = @course.homework_commons.order("created_at desc")
|
||||
@new_homework = HomeworkCommon.new
|
||||
@new_homework.homework_detail_manual = HomeworkDetailManual.new
|
||||
@new_homework.course = @course
|
||||
@page = params[:page] ? params[:page].to_i + 1 : 0
|
||||
@homeworks = @course.homework_commons.order("created_at desc").limit(10).offset(@page * 10)
|
||||
@is_teacher = User.current.logged? && (User.current.admin? || User.current.allowed_to?(:as_teacher,@course))
|
||||
@is_student = User.current.logged? && (User.current.admin? || (User.current.member_of_course?(@course) && !@is_teacher))
|
||||
@homeworks = paginateHelper homeworks,20
|
||||
@is_new = params[:is_new]
|
||||
|
||||
#设置at已读
|
||||
@homeworks.each do |homework|
|
||||
homework.journals_for_messages.each do |j|
|
||||
User.current.at_messages.unviewed('JournalsForMessage', j.id).each {|x| x.viewed!}
|
||||
end
|
||||
end
|
||||
|
||||
respond_to do |format|
|
||||
format.js
|
||||
format.html
|
||||
end
|
||||
end
|
||||
|
||||
#新建作业,在个人作业列表创建作业
|
||||
def new
|
||||
@homework_type = "1"
|
||||
|
||||
@homework = HomeworkCommon.new
|
||||
@homework.safe_attributes = params[:homework_common]
|
||||
@homework.late_penalty = 2
|
||||
@homework.end_time = (Time.now + 3600 * 24).strftime('%Y-%m-%d')
|
||||
@homework.publish_time = Time.now.strftime('%Y-%m-%d')
|
||||
|
||||
if @homework_type == "1"
|
||||
#匿评作业相关属性
|
||||
@homework_detail_manual = HomeworkDetailManual.new
|
||||
@homework_detail_manual.ta_proportion = 0.6
|
||||
@homework_detail_manual.absence_penalty = 2
|
||||
@homework_detail_manual.evaluation_num = 3
|
||||
@homework_detail_manual.evaluation_start = Time.now.strftime('%Y-%m-%d')
|
||||
@homework_detail_manual.evaluation_end = (Time.now + 3600 * 24).strftime('%Y-%m-%d')
|
||||
@homework.homework_detail_manual = @homework_detail_manual
|
||||
elsif @homework_type == "2"
|
||||
#编程作业相关属性
|
||||
@homework_detail_programing = HomeworkDetailPrograming.new
|
||||
@homework.homework_detail_programing = @homework_detail_programing
|
||||
end
|
||||
respond_to do |format|
|
||||
format.html
|
||||
end
|
||||
end
|
||||
|
||||
#新建作业下一步
|
||||
def next_step
|
||||
@homework_type = params[:homework_common_type]
|
||||
|
||||
@homework = HomeworkCommon.new
|
||||
@homework.safe_attributes = params[:homework_common]
|
||||
@homework.late_penalty = 2
|
||||
@homework.end_time = (Time.now + 3600 * 24).strftime('%Y-%m-%d')
|
||||
@homework.publish_time = Time.now.strftime('%Y-%m-%d')
|
||||
|
||||
if @homework_type == "1"
|
||||
#匿评作业相关属性
|
||||
@homework_detail_manual = HomeworkDetailManual.new
|
||||
@homework_detail_manual.ta_proportion = 0.6
|
||||
@homework_detail_manual.absence_penalty = 2
|
||||
@homework_detail_manual.evaluation_num = 3
|
||||
@homework_detail_manual.evaluation_start = Time.now.strftime('%Y-%m-%d')
|
||||
@homework_detail_manual.evaluation_end = (Time.now + 3600 * 24).strftime('%Y-%m-%d')
|
||||
@homework.homework_detail_manual = @homework_detail_manual
|
||||
elsif @homework_type == "2"
|
||||
#编程作业相关属性
|
||||
@homework_detail_programing = HomeworkDetailPrograming.new
|
||||
@homework.homework_detail_programing = @homework_detail_programing
|
||||
end
|
||||
|
||||
|
||||
respond_to do |format|
|
||||
format.html
|
||||
end
|
||||
render_404
|
||||
end
|
||||
|
||||
#新建作业,在个人作业列表创建作业
|
||||
def create
|
||||
if params[:homework_common]
|
||||
homework = HomeworkCommon.new
|
||||
homework.name = params[:homework_common][:name]
|
||||
homework.description = params[:homework_common][:description]
|
||||
homework.end_time = params[:homework_common][:end_time]
|
||||
homework.publish_time = params[:homework_common][:publish_time]
|
||||
homework.homework_type = params[:homework_common][:homework_type]
|
||||
homework.late_penalty = params[:late_penalty]
|
||||
homework.user_id = User.current.id
|
||||
homework.course_id = @course.id
|
||||
|
||||
homework.save_attachments(params[:attachments])
|
||||
render_attachment_warning_if_needed(homework)
|
||||
|
||||
if homework.homework_type == 2
|
||||
homework_detail_programing = HomeworkDetailPrograming.new
|
||||
homework_detail_programing.language = params[:language]
|
||||
homework_detail_programing.standard_code = params[:standard_code]
|
||||
homework_detail_programing.ta_proportion = params[:ta_proportion] || 0.6
|
||||
question = {title:homework.name,content:homework.description}
|
||||
question[:input] = []
|
||||
question[:output] = []
|
||||
if params[:input] && params[:output] && params[:result]
|
||||
params[:input].each do |k,v|
|
||||
if params[:output].include? k
|
||||
homework_test = HomeworkTest.new
|
||||
homework_test.input = v
|
||||
homework_test.output = params[:output][k]
|
||||
homework_test.result = params[:result][k]
|
||||
homework_test.error_msg = params[:error_msg]
|
||||
homework.homework_tests << homework_test
|
||||
question[:input] << homework_test.input
|
||||
question[:output] << homework_test.output
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# uri = URI('http://192.168.80.21:8080/api/questions.json')
|
||||
# body = question.to_json
|
||||
# res = Net::HTTP.new(uri.host, uri.port).start do |client|
|
||||
# request = Net::HTTP::Post.new(uri.path)
|
||||
# request.body = body
|
||||
# request["Content-Type"] = "application/json"
|
||||
# client.request(request)
|
||||
# end
|
||||
# result = JSON.parse(res.body)
|
||||
# homework_detail_programing.question_id = result["id"] if result["status"] && result["status"] == 0
|
||||
|
||||
homework.homework_detail_programing = homework_detail_programing
|
||||
else
|
||||
#匿评作业相关属性
|
||||
homework_detail_manual = HomeworkDetailManual.new
|
||||
homework_detail_manual.ta_proportion = params[:ta_proportion] || 0.6
|
||||
homework_detail_manual.comment_status = 1
|
||||
homework_detail_manual.evaluation_start = params[:evaluation_start]
|
||||
homework_detail_manual.evaluation_end = params[:evaluation_end]
|
||||
homework_detail_manual.evaluation_num = params[:evaluation_num]
|
||||
homework_detail_manual.absence_penalty = params[:absence_penalty]
|
||||
homework.homework_detail_manual = homework_detail_manual
|
||||
end
|
||||
|
||||
if homework.save
|
||||
homework_detail_programing.save if homework_detail_programing
|
||||
homework_detail_manual.save if homework_detail_manual
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
flash[:notice] = l(:notice_successful_create)
|
||||
redirect_to homework_common_index_path(:course => @course.id)
|
||||
}
|
||||
end
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
flash[:notice] = l(:notice_failed_create)
|
||||
redirect_to new_homework_common_path(:course => @course.id)
|
||||
}
|
||||
end
|
||||
redirect_to user_homeworks_user_path(User.current.id)
|
||||
end
|
||||
|
||||
def edit
|
||||
@user = User.current
|
||||
@is_in_course = params[:is_in_course].to_i
|
||||
@course_activity = params[:course_activity].to_i
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.html{render :layout => 'new_base_user'}
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
@homework.name = params[:homework_common][:name]
|
||||
@homework.description = params[:homework_common][:description]
|
||||
@homework.end_time = params[:homework_common][:end_time]
|
||||
@homework.publish_time = params[:homework_common][:publish_time]
|
||||
@homework.homework_type = params[:homework_common][:homework_type] if params[:homework_common][:homework_type]
|
||||
unless @homework.late_penalty == params[:late_penalty]
|
||||
@homework.student_works.where("created_at > '#{@homework.end_time} 23:59:59'").each do |student_work|
|
||||
student_work.late_penalty = params[:late_penalty]
|
||||
student_work.save
|
||||
if params[:homework_common]
|
||||
@homework.name = params[:homework_common][:name]
|
||||
@homework.description = params[:homework_common][:description]
|
||||
if params[:homework_common][:publish_time] == ""
|
||||
@homework.publish_time = Date.today
|
||||
else
|
||||
@homework.publish_time = params[:homework_common][:publish_time]
|
||||
end
|
||||
@homework.late_penalty = params[:late_penalty]
|
||||
end
|
||||
# @homework.course_id = @course.id
|
||||
@homework.end_time = params[:homework_common][:end_time] || Time.now
|
||||
@homework.course_id = params[:course_id]
|
||||
@homework.anonymous_comment = params[:homework_common][:anonymous_comment] ? params[:homework_common][:anonymous_comment] : 0
|
||||
|
||||
#匿评作业相关属性
|
||||
if @homework.homework_type == 1 && @homework_detail_manual
|
||||
@homework_detail_manual.ta_proportion = params[:ta_proportion] || 0.6
|
||||
@homework_detail_manual.evaluation_start = params[:evaluation_start]
|
||||
@homework_detail_manual.evaluation_end = params[:evaluation_end]
|
||||
@homework_detail_manual.evaluation_num = params[:evaluation_num]
|
||||
unless @homework_detail_manual.absence_penalty == params[:absence_penalty]
|
||||
if @homework_detail_manual.comment_status == 3 #当前作业处于匿评结束状态,修改缺评扣分才会修改每个作品应扣分的值
|
||||
work_ids = "(" + @homework.student_works.map(&:id).join(",") + ")"
|
||||
@homework.student_works.each do |student_work|
|
||||
absence_penalty_count = student_work.user.student_works_evaluation_distributions.where("student_work_id IN #{work_ids}").count - student_work.user.student_works_scores.where("student_work_id IN #{work_ids}").count
|
||||
student_work.absence_penalty = absence_penalty_count > 0 ? absence_penalty_count * @homework_detail_manual.absence_penalty : 0
|
||||
student_work.save
|
||||
end
|
||||
end
|
||||
@homework_detail_manual.absence_penalty = params[:absence_penalty]
|
||||
homework_detail_manual = @homework.homework_detail_manual || HomeworkDetailManual.new
|
||||
if @homework.publish_time <= Date.today && homework_detail_manual.comment_status == 0
|
||||
homework_detail_manual.comment_status = 1
|
||||
end
|
||||
elsif @homework.homework_type == 0 #普通作业,缺评扣分为0分,每个作品的缺评扣分改为0分,防止某些作业在结束匿评之后改为普通作业
|
||||
@homework.student_works.where("absence_penalty != 0").each do |student_work|
|
||||
student_work.late_penalty = 0
|
||||
student_work.save
|
||||
end
|
||||
@homework_detail_manual.absence_penalty = 0 if @homework_detail_manual
|
||||
end
|
||||
homework_detail_manual.evaluation_start = params[:evaluation_start].blank? ? @homework.end_time + 7 : params[:evaluation_start]
|
||||
homework_detail_manual.evaluation_end = params[:evaluation_end].blank? ? homework_detail_manual.evaluation_start + 7 : params[:evaluation_end]
|
||||
|
||||
if @homework.homework_type == 2 && @homework_detail_programing #编程作业
|
||||
@homework_detail_programing.language = params[:language]
|
||||
@homework_detail_programing.standard_code = params[:standard_code]
|
||||
@homework_detail_programing.ta_proportion = params[:ta_proportion] || 0.6
|
||||
homework_tests = @homework.homework_tests
|
||||
#需要删除的测试
|
||||
ids = homework_tests.map(&:id) - params[:input].keys.map(&:to_i)
|
||||
ids.each do |id|
|
||||
homework_test = HomeworkTest.find id
|
||||
homework_test.destroy if homework_test
|
||||
end
|
||||
if params[:input] && params[:output] && params[:result]
|
||||
params[:input].each do |k,v|
|
||||
if params[:output].include? k
|
||||
homework_test = HomeworkTest.find_by_id k
|
||||
if homework_test #已存在的测试,修改
|
||||
homework_test.input = v
|
||||
homework_test.output = params[:output][k]
|
||||
homework_test.result = params[:result][k]
|
||||
homework_test.error_msg = params[:error_msg]
|
||||
else #不存在的测试,增加
|
||||
homework_test = HomeworkTest.new
|
||||
homework_test.input = v
|
||||
homework_test.output = params[:output][k]
|
||||
homework_test.result = params[:result][k]
|
||||
homework_test.error_msg = params[:error_msg]
|
||||
homework_test.homework_common = @homework
|
||||
@homework.save_attachments(params[:attachments])
|
||||
render_attachment_warning_if_needed(@homework)
|
||||
|
||||
#编程作业相关属性
|
||||
if @homework.homework_type == 2
|
||||
@homework.homework_detail_programing ||= HomeworkDetailPrograming.new
|
||||
@homework_detail_programing = @homework.homework_detail_programing
|
||||
@homework_detail_programing.language = params[:language_type].to_i
|
||||
|
||||
@homework.homework_tests.delete_all
|
||||
inputs = params[:program][:input]
|
||||
if Array === inputs
|
||||
inputs.each_with_index do |val, i|
|
||||
@homework.homework_tests << HomeworkTest.new(
|
||||
input: val,
|
||||
output: params[:program][:output][i]
|
||||
)
|
||||
end
|
||||
homework_test.save
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#发送修改作业的请求
|
||||
question = {title:@homework.name,content:@homework.description}
|
||||
question[:input] = []
|
||||
question[:output] = []
|
||||
@homework.homework_tests.each do |test|
|
||||
question[:input] << test.input
|
||||
question[:output] << test.output
|
||||
#分组作业
|
||||
if @homework.homework_type == 3
|
||||
@homework.homework_detail_group ||= HomeworkDetailGroup.new
|
||||
@homework_detail_group = @homework.homework_detail_group
|
||||
@homework_detail_group.min_num = params[:min_num].to_i
|
||||
@homework_detail_group.max_num = params[:max_num].to_i
|
||||
@homework_detail_group.base_on_project = params[:base_on_project].to_i
|
||||
end
|
||||
# uri = URI("http://192.168.80.21:8080/api/questions/#{@homework_detail_programing.question_id}.json")
|
||||
# body = question.to_json
|
||||
# res = Net::HTTP.new(uri.host, uri.port).start do |client|
|
||||
# request = Net::HTTP::Put.new(uri.path)
|
||||
# request.body = body
|
||||
# request["Content-Type"] = "application/json"
|
||||
# client.request(request)
|
||||
# end
|
||||
# result = JSON.parse(res.body)
|
||||
end
|
||||
|
||||
@homework.save_attachments(params[:attachments])
|
||||
render_attachment_warning_if_needed(@homework)
|
||||
if @homework.save
|
||||
@homework_detail_manual.save if @homework_detail_manual
|
||||
@homework_detail_programing.save if @homework_detail_programing
|
||||
@homework_detail_group.save if @homework_detail_group
|
||||
|
||||
if @homework.save
|
||||
@homework_detail_manual.save if @homework_detail_manual
|
||||
@homework_detail_programing.save if @homework_detail_programing
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
flash[:notice] = l(:notice_successful_edit)
|
||||
if params[:is_in_course] == "1"
|
||||
redirect_to homework_common_index_path(:course => @course.id)
|
||||
}
|
||||
end
|
||||
return
|
||||
else
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
flash[:notice] = l(:notice_failed_edit)
|
||||
redirect_to edit_homework_common_path(@homework)
|
||||
}
|
||||
elsif params[:is_in_course] == "0"
|
||||
redirect_to user_homeworks_user_path(User.current.id)
|
||||
elsif params[:is_in_course] == "-1" && params[:course_activity] == "0"
|
||||
redirect_to user_path(User.current.id)
|
||||
elsif params[:is_in_course] == "-1" && params[:course_activity] == "1"
|
||||
redirect_to course_path(@course.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -284,7 +123,17 @@ class HomeworkCommonController < ApplicationController
|
|||
def destroy
|
||||
if @homework.destroy
|
||||
respond_to do |format|
|
||||
format.html {redirect_to homework_common_index_path(:course => @course.id)}
|
||||
format.html {
|
||||
if params[:is_in_course] == "1"
|
||||
redirect_to homework_common_index_path(:course => @course.id)
|
||||
elsif params[:is_in_course] == "0"
|
||||
redirect_to user_homeworks_user_path(User.current.id)
|
||||
elsif params[:is_in_course] == "-1" && params[:course_activity] == "0"
|
||||
redirect_to user_path(User.current.id)
|
||||
elsif params[:is_in_course] == "-1" && params[:course_activity] == "1"
|
||||
redirect_to course_path(@course.id)
|
||||
end
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -292,47 +141,88 @@ class HomeworkCommonController < ApplicationController
|
|||
#开启匿评
|
||||
#statue 1:启动成功,2:启动失败,作业总数大于等于2份时才能启动匿评,3:已开启匿评,请务重复开启,4:没有开启匿评的权限
|
||||
def start_anonymous_comment
|
||||
@statue =4 and return unless User.current.admin? || User.current.allowed_to?(:as_teacher,@course)
|
||||
@statue = 4 and return unless User.current.admin? || User.current.allowed_to?(:as_teacher,@course)
|
||||
@statue = 5 and return if Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") >= Time.now.strftime("%Y-%m-%d")
|
||||
if @homework_detail_manual.comment_status == 1
|
||||
student_works = @homework.student_works
|
||||
if student_works && student_works.size >=2
|
||||
student_works.each_with_index do |work, index|
|
||||
user = work.user
|
||||
n = @homework_detail_manual.evaluation_num
|
||||
n = n < student_works.size ? n : student_works.size - 1
|
||||
assigned_homeworks = get_assigned_homeworks(student_works, n, index)
|
||||
assigned_homeworks.each do |h|
|
||||
student_works_evaluation_distributions = StudentWorksEvaluationDistribution.new(user_id: user.id, student_work_id: h.id)
|
||||
student_works_evaluation_distributions.save
|
||||
if student_works && student_works.size >= 2
|
||||
if @homework.homework_type == 3
|
||||
student_work_projects = @homework.student_work_projects.where("student_work_id is not null")
|
||||
student_work_projects.each_with_index do |pro_work, pro_index|
|
||||
n = @homework_detail_manual.evaluation_num
|
||||
n = n < student_works.size ? n : student_works.size - 1
|
||||
work_index = -1
|
||||
student_works.each_with_index do |stu_work, stu_index|
|
||||
if stu_work.id.to_i == pro_work.student_work_id.to_i
|
||||
work_index = stu_index
|
||||
end
|
||||
end
|
||||
assigned_homeworks = get_assigned_homeworks(student_works, n, work_index)
|
||||
assigned_homeworks.each do |h|
|
||||
student_works_evaluation_distributions = StudentWorksEvaluationDistribution.new(user_id: pro_work.user_id, student_work_id: h.id)
|
||||
student_works_evaluation_distributions.save
|
||||
end
|
||||
end
|
||||
else
|
||||
student_works.each_with_index do |work, index|
|
||||
user = work.user
|
||||
n = @homework_detail_manual.evaluation_num
|
||||
n = n < student_works.size ? n : student_works.size - 1
|
||||
assigned_homeworks = get_assigned_homeworks(student_works, n, index)
|
||||
assigned_homeworks.each do |h|
|
||||
student_works_evaluation_distributions = StudentWorksEvaluationDistribution.new(user_id: user.id, student_work_id: h.id)
|
||||
student_works_evaluation_distributions.save
|
||||
end
|
||||
end
|
||||
end
|
||||
@homework_detail_manual.update_column('comment_status', 2)
|
||||
@homework_detail_manual.update_column('evaluation_start', Date.today)
|
||||
@statue = 1
|
||||
# 匿评开启消息邮件通知
|
||||
send_message_anonymous_comment(@homework, m_status = 2)
|
||||
Mailer.send_mail_anonymous_comment_open(@homework).deliver
|
||||
else
|
||||
@statue = 2
|
||||
end
|
||||
|
||||
end
|
||||
else
|
||||
@statue = 3
|
||||
end
|
||||
@user_activity_id = params[:user_activity_id].to_i
|
||||
@is_in_course = params[:is_in_course].to_i
|
||||
@course_activity = params[:course_activity].to_i
|
||||
end
|
||||
|
||||
#关闭匿评
|
||||
def stop_anonymous_comment
|
||||
@homework_detail_manual.update_column('comment_status', 3)
|
||||
|
||||
@homework_detail_manual.update_column('evaluation_end', Date.today)
|
||||
#计算缺评扣分
|
||||
work_ids = "(" + @homework.student_works.map(&:id).join(",") + ")"
|
||||
@homework.student_works.each do |student_work|
|
||||
absence_penalty_count = student_work.user.student_works_evaluation_distributions.where("student_work_id IN #{work_ids}").count - student_work.user.student_works_scores.where("student_work_id IN #{work_ids}").count
|
||||
student_work.absence_penalty = absence_penalty_count > 0 ? absence_penalty_count * @homework_detail_manual.absence_penalty : 0
|
||||
student_work.save
|
||||
end
|
||||
|
||||
# 匿评关闭消息邮件通知
|
||||
send_message_anonymous_comment(@homework, m_status = 3)
|
||||
Mailer.send_mail_anonymous_comment_close(@homework).deliver
|
||||
@user_activity_id = params[:user_activity_id].to_i
|
||||
@is_in_course = params[:is_in_course].to_i
|
||||
@course_activity = params[:course_activity].to_i
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
# 开启/关闭匿评消息通知
|
||||
def send_message_anonymous_comment(homework, m_status )
|
||||
# status 标记匿评状态 1为关闭 0为开启
|
||||
course = homework.course
|
||||
course.members.each do |m|
|
||||
@homework.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => course.id, :viewed => false, :status => m_status)
|
||||
end
|
||||
end
|
||||
#提示
|
||||
def alert_anonymous_comment
|
||||
@cur_size = 0
|
||||
|
|
@ -346,6 +236,22 @@ class HomeworkCommonController < ApplicationController
|
|||
@homework.student_works.map { |work| @cur_size += work.student_works_scores.where(:reviewer_role => 3).count}
|
||||
end
|
||||
@percent = format("%.2f",(@cur_size.to_f / ( @totle_size == 0 ? 1 : @totle_size)) * 100)
|
||||
@user_activity_id = params[:user_activity_id].to_i
|
||||
@is_in_course = params[:is_in_course].to_i
|
||||
@course_activity = params[:course_activity].to_i
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def alert_forbidden_anonymous_comment
|
||||
if params[:user_activity_id]
|
||||
@user_activity_id = params[:user_activity_id]
|
||||
else
|
||||
@user_activity_id = -1
|
||||
end
|
||||
@is_in_course = params[:is_in_course] if params[:is_in_course]
|
||||
@course_activity = params[:course_activity] if params[:course_Activity]
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
|
|
@ -369,6 +275,47 @@ class HomeworkCommonController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
#启动匿评参数设置
|
||||
def start_evaluation_set
|
||||
if params[:user_activity_id]
|
||||
@user_activity_id = params[:user_activity_id]
|
||||
else
|
||||
@user_activity_id = -1
|
||||
end
|
||||
@is_in_course = params[:is_in_course]
|
||||
@course_activity = params[:course_activity].to_i
|
||||
end
|
||||
|
||||
#设置匿评参数
|
||||
def set_evaluation_attr
|
||||
if @homework_detail_manual
|
||||
unless params[:evaluation_start].to_s == @homework_detail_manual.evaluation_start.to_s
|
||||
@homework_detail_manual.evaluation_start = params[:evaluation_start]
|
||||
end
|
||||
|
||||
unless @homework_detail_manual.evaluation_end.to_s == params[:evaluation_end].to_s
|
||||
@homework_detail_manual.evaluation_end = params[:evaluation_end]
|
||||
end
|
||||
|
||||
@homework_detail_manual.evaluation_num = params[:evaluation_num]
|
||||
@homework_detail_manual.save
|
||||
@user_activity_id = params[:user_activity_id].to_i
|
||||
@is_in_course = params[:is_in_course].to_i
|
||||
@course_activity = params[:course_activity].to_i
|
||||
end
|
||||
end
|
||||
|
||||
#评分设置
|
||||
def score_rule_set
|
||||
if params[:user_activity_id]
|
||||
@user_activity_id = params[:user_activity_id]
|
||||
else
|
||||
@user_activity_id = -1
|
||||
end
|
||||
@is_in_course = params[:is_in_course]
|
||||
@course_activity = params[:course_activity].to_i
|
||||
end
|
||||
|
||||
private
|
||||
#获取课程
|
||||
def find_course
|
||||
|
|
@ -381,6 +328,7 @@ class HomeworkCommonController < ApplicationController
|
|||
@homework = HomeworkCommon.find params[:id]
|
||||
@homework_detail_manual = @homework.homework_detail_manual
|
||||
@homework_detail_programing = @homework.homework_detail_programing
|
||||
@homework_detail_group = @homework.homework_detail_group
|
||||
@course = @homework.course
|
||||
rescue
|
||||
render_404
|
||||
|
|
|
|||
|
|
@ -20,11 +20,11 @@ class IssuesController < ApplicationController
|
|||
default_search_scope :issues
|
||||
|
||||
before_filter :authorize1, :only => [:show]
|
||||
before_filter :find_issue, :only => [:show, :edit, :update,:add_journal]
|
||||
before_filter :find_issue, :only => [:show, :edit, :update,:add_journal, :add_journal_in_org]
|
||||
before_filter :find_issues, :only => [:bulk_edit, :bulk_update, :destroy]
|
||||
before_filter :find_project, :only => [:new, :create, :update_form]
|
||||
#before_filter :authorize, :except => [:index, :show]
|
||||
before_filter :authorize, :except => [:index,:add_journal]
|
||||
before_filter :authorize, :except => [:index,:add_journal, :add_journal_in_org,:delete_journal,:reply,:add_reply]
|
||||
|
||||
before_filter :find_optional_project, :only => [:index]
|
||||
before_filter :check_for_default_issue_status, :only => [:new, :create]
|
||||
|
|
@ -55,6 +55,7 @@ class IssuesController < ApplicationController
|
|||
helper :timelog
|
||||
include Redmine::Export::PDF
|
||||
helper :project_score
|
||||
include ApplicationHelper
|
||||
|
||||
def index
|
||||
retrieve_query
|
||||
|
|
@ -80,13 +81,18 @@ class IssuesController < ApplicationController
|
|||
@priority_id = params[:priority_id]
|
||||
@status_id = params[:status_id]
|
||||
@subject = params[:subject]
|
||||
@done_ratio = params[:done_ratio]
|
||||
@issue_count = @query.issue_count
|
||||
@issue_pages = Paginator.new @issue_count, @limit, params['page']
|
||||
params[:page] = (params[:page] || 1).to_i + 1 #页码需要加1
|
||||
@offset ||= @issue_pages.offset
|
||||
@issues = @query.issues(:include => [:assigned_to, :tracker, :priority, :category, :fixed_version],
|
||||
:order => sort_clause,
|
||||
:order => 'issues.updated_on desc',
|
||||
:offset => @offset,
|
||||
:limit => @limit)
|
||||
if params[:set_filter]
|
||||
@set_filter = params[:set_filter]
|
||||
end
|
||||
@issue_count_by_group = @query.issue_count_by_group
|
||||
respond_to do |format|
|
||||
format.js
|
||||
|
|
@ -113,10 +119,16 @@ class IssuesController < ApplicationController
|
|||
|
||||
def show
|
||||
# 当前用户查看指派给他的缺陷消息,则设置消息为已读
|
||||
query = @issue.forge_messages
|
||||
if User.current.id == @issue.assigned_to_id
|
||||
query.update_all(:viewed => true)
|
||||
query = ForgeMessage.where("forge_message_type =? and user_id =? and forge_message_id =?", "Issue", User.current, @issue).first
|
||||
query.update_attribute(:viewed, true) unless query.nil?
|
||||
|
||||
# issue 新建的at消息
|
||||
User.current.at_messages.unviewed('Issue', @issue.id).each {|x| x.viewed!}
|
||||
# 回复的at消息
|
||||
@issue.journals.each do |j|
|
||||
User.current.at_messages.unviewed('Journal', j.id).each {|x| x.viewed!}
|
||||
end
|
||||
|
||||
# 缺陷状态更新
|
||||
query_journals = @issue.journals
|
||||
query_journals.each do |query_journal|
|
||||
|
|
@ -127,6 +139,7 @@ class IssuesController < ApplicationController
|
|||
end
|
||||
end
|
||||
# end
|
||||
@jour_reply = Journal.new
|
||||
@journals = @issue.journals.includes(:user, :details).reorder("#{Journal.table_name}.id ASC").all
|
||||
@journals.each_with_index {|j,i| j.indice = i+1}
|
||||
@journals.reject!(&:private_notes?) unless User.current.allowed_to?(:view_private_notes, @issue.project)
|
||||
|
|
@ -143,18 +156,19 @@ class IssuesController < ApplicationController
|
|||
|
||||
@project_base_tag = (params[:project_id] || @issue.project) ? 'base_projects':'base'#by young
|
||||
@available_watchers = (@issue.project.users.sort + @issue.watcher_users).uniq
|
||||
@journal = Journal.new(:journalized => @issue)
|
||||
|
||||
respond_to do |format|``
|
||||
format.html {
|
||||
retrieve_previous_and_next_issue_ids
|
||||
render :template => 'issues/show', :layout => @project_base_tag#by young
|
||||
}
|
||||
format.api
|
||||
format.atom { render :template => 'journals/index', :layout => false, :content_type => 'application/atom+xml' }
|
||||
format.pdf {
|
||||
pdf = issue_to_pdf(@issue, :journals => @journals)
|
||||
send_data(pdf, :type => 'application/pdf', :filename => "#{@project.identifier}-#{@issue.id}.pdf")
|
||||
}
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
retrieve_previous_and_next_issue_ids
|
||||
render :template => 'issues/show', :layout => @project_base_tag#by young
|
||||
}
|
||||
format.api
|
||||
format.atom { render :template => 'journals/index', :layout => false, :content_type => 'application/atom+xml' }
|
||||
format.pdf {
|
||||
pdf = issue_to_pdf(@issue, :journals => @journals)
|
||||
send_data(pdf, :type => 'application/pdf', :filename => filename_for_content_disposition("#{@project.identifier}-#{@issue.id}.pdf") )
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -176,7 +190,7 @@ class IssuesController < ApplicationController
|
|||
respond_to do |format|
|
||||
format.html {
|
||||
render_attachment_warning_if_needed(@issue)
|
||||
flash[:notice] = l(:label_successful_create)
|
||||
#flash[:notice] = l(:label_successful_create)
|
||||
#flash[:notice] = l(:notice_issue_successful_create, :id => view_context.link_to("#{@issue.subject}", issue_path(@issue), :title => @issue.subject))
|
||||
#flash[:notice] = l(:notice_issue_successful_create, :id => view_context.link_to("##{@issue.id}", issue_path(@issue), :title => @issue.subject))
|
||||
if params[:continue]
|
||||
|
|
@ -207,21 +221,28 @@ class IssuesController < ApplicationController
|
|||
end
|
||||
|
||||
def update
|
||||
return unless update_issue_from_params
|
||||
@issue.save_attachments(params[:attachments] || (params[:issue] && params[:issue][:uploads]))
|
||||
saved = false
|
||||
begin
|
||||
saved = @issue.save_issue_with_child_records(params, @time_entry)
|
||||
rescue ActiveRecord::StaleObjectError
|
||||
@conflict = true
|
||||
if params[:last_journal_id]
|
||||
@conflict_journals = @issue.journals_after(params[:last_journal_id]).all
|
||||
@conflict_journals.reject!(&:private_notes?) unless User.current.allowed_to?(:view_private_notes, @issue.project)
|
||||
if params[:issue_detail]
|
||||
issue = Issue.find(params[:id])
|
||||
issue = update_user_issue_detail(issue, params)
|
||||
@saved = update_user_issue_detail(issue, params)
|
||||
return
|
||||
else
|
||||
return unless update_issue_from_params
|
||||
@issue.save_attachments(params[:attachments] || (params[:issue] && params[:issue][:uploads]))
|
||||
saved = false
|
||||
begin
|
||||
@saved = @issue.save_issue_with_child_records(params, @time_entry)
|
||||
rescue ActiveRecord::StaleObjectError
|
||||
@conflict = true
|
||||
if params[:last_journal_id]
|
||||
@conflict_journals = @issue.journals_after(params[:last_journal_id]).all
|
||||
@conflict_journals.reject!(&:private_notes?) unless User.current.allowed_to?(:view_private_notes, @issue.project)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if saved
|
||||
|
||||
if @saved
|
||||
#修改界面增加跟踪者
|
||||
watcherlist = @issue.watcher_users
|
||||
select_users = []
|
||||
|
|
@ -250,21 +271,35 @@ class IssuesController < ApplicationController
|
|||
if reply_id > 0
|
||||
JournalReply.add_reply(@issue.current_journal.id, reply_id, User.current.id)
|
||||
end
|
||||
flash[:notice] = l(:notice_successful_update) unless @issue.current_journal.new_record?
|
||||
|
||||
#flash[:notice] = l(:notice_successful_update) unless @issue.current_journal.new_record? 去掉这个notice,因为现在更新都是ajax操作
|
||||
respond_to do |format|
|
||||
|
||||
format.js
|
||||
format.html { redirect_to issue_url(@issue.id) }
|
||||
format.api { render_api_ok }
|
||||
end
|
||||
else
|
||||
respond_to do |format|
|
||||
|
||||
format.js
|
||||
format.html { render :action => 'edit' }
|
||||
format.api { render_validation_errors(@issue) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def update_user_issue_detail(issue, params)
|
||||
case params[:type]
|
||||
when "status"
|
||||
issue.update_attribute(:status_id, params[:status_id])
|
||||
when "assigned"
|
||||
issue.update_attribute(:assigned_to_id, params[:assigned_to_id])
|
||||
when "ratio"
|
||||
issue.update_attribute(:done_ratio, params[:done_ratio])
|
||||
when "prior"
|
||||
issue.update_attribute(:priority_id, params[:priority_id])
|
||||
end
|
||||
end
|
||||
|
||||
# Updates the issue form when changing the project, status or tracker
|
||||
# on issue creation/update
|
||||
def update_form
|
||||
|
|
@ -391,7 +426,32 @@ class IssuesController < ApplicationController
|
|||
jour.user_id = User.current.id
|
||||
jour.notes = params[:notes]
|
||||
jour.journalized = @issue
|
||||
jour.save_attachments(params[:attachments])
|
||||
jour.save
|
||||
update_user_activity(@issue.class,@issue.id)
|
||||
update_forge_activity(@issue.class,@issue.id)
|
||||
|
||||
@user_activity_id = params[:user_activity_id]
|
||||
if params[:issue_id]
|
||||
@issue_id = params[:issue_id]
|
||||
end
|
||||
@priorities = IssuePriority.active
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def add_journal_in_org
|
||||
if User.current.logged?
|
||||
jour = Journal.new
|
||||
jour.user_id = User.current.id
|
||||
jour.notes = params[:notes]
|
||||
jour.journalized = @issue
|
||||
jour.save
|
||||
org_activity = OrgActivity.where("org_act_type='Issue' and org_act_id =#{@issue.id}").first
|
||||
org_activity.updated_at = jour.created_on
|
||||
org_activity.save
|
||||
@user_activity_id = params[:user_activity_id]
|
||||
respond_to do |format|
|
||||
format.js
|
||||
|
|
@ -399,6 +459,43 @@ class IssuesController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
#对某个journ回复,显示回复框
|
||||
def reply
|
||||
@issue = Issue.find(params[:id])
|
||||
@jour = Journal.find(params[:journal_id])
|
||||
@tempContent = "<blockquote>#{ll(Setting.default_language, :text_user_wrote, @jour.user.realname.blank? ? @jour.user.login: @jour.user.realname)} <br/>#{@jour.notes.html_safe}</blockquote>".html_safe
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
#给issue添加journ。回复内容包含 对某个被回复的journ的内容
|
||||
def add_reply
|
||||
if User.current.logged?
|
||||
jour = Journal.new
|
||||
jour.user_id = User.current.id
|
||||
jour.notes = params[:quote]+params[:notes]
|
||||
@issue = Issue.find params[:id]
|
||||
jour.journalized = @issue
|
||||
jour.save
|
||||
update_user_activity(@issue.class,@issue.id)
|
||||
update_forge_activity(@issue.class,@issue.id)
|
||||
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#
|
||||
def delete_journal
|
||||
@issue = Issue.find(params[:id])
|
||||
Journal.destroy(params[:journal_id])
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def find_project
|
||||
|
|
|
|||
|
|
@ -36,8 +36,7 @@ class JournalsController < ApplicationController
|
|||
sort_update(@query.sortable_columns)
|
||||
|
||||
if @query.valid?
|
||||
@journals = @query.journals(:order => "#{Journal.table_name}.created_on DESC",
|
||||
:limit => 25)
|
||||
@journals = @query.journals(:order => "#{Journal.table_name}.created_on DESC", :limit => 25)
|
||||
end
|
||||
@title = (@project ? @project.name : Setting.app_title) + ": " + (@query.new_record? ? l(:label_changes_details) : @query.name)
|
||||
render :layout => false, :content_type => 'application/atom+xml'
|
||||
|
|
@ -72,9 +71,9 @@ class JournalsController < ApplicationController
|
|||
end
|
||||
# Replaces pre blocks with [...]
|
||||
text = text.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]')
|
||||
@content = "> #{ll(Setting.default_language, :text_user_wrote, user)}\n> "
|
||||
@content << text.gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n"
|
||||
# @content = "<blockquote style='word-break: break-all;word-wrap: break-word;'>" << @content
|
||||
@content = "#{ll(Setting.default_language, :text_user_wrote, user)}\n"
|
||||
@content << text.gsub(/(\r?\n|\r\n?)/, "\n ") + "\n"
|
||||
@content = "<blockquote style='padding-left:0px;margin-left:0px;'>" << @content << "</blockquote>\n\n<br/>"
|
||||
@id = user.id
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
|
|
|
|||
|
|
@ -81,8 +81,12 @@ class MembersController < ApplicationController
|
|||
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, :project_id => @project.id)
|
||||
## added by nie
|
||||
|
||||
#给新成员发送加入项目的消息,发送者id放在ForgeMessage的forge_message_id字段中,
|
||||
#forge_message_type设置为JoinProject
|
||||
forge_join = ForgeMessage.new(:user_id =>user_id, :forge_message_id=>User.current.id,:project_id => @project.id,:forge_message_type=>"JoinProject", :viewed => false)
|
||||
forge_join.save
|
||||
## added by nie
|
||||
if (params[:membership][:role_ids])
|
||||
role = Role.find(params[:membership][:role_ids][0])
|
||||
project_info << ProjectInfo.new(:user_id => user_id, :project_id => @project.id) if role.allowed_to?(:is_manager)
|
||||
|
|
@ -155,6 +159,14 @@ class MembersController < ApplicationController
|
|||
if role && (role.name == "学生" || role.name == "Student")
|
||||
StudentsForCourse.create(:student_id => user_id, :course_id =>@course.id)
|
||||
end
|
||||
|
||||
#给新成员和老师发送加入课程的消息,发送者id放在CourseMessage的course_message_id字段中
|
||||
#course_message_type设置为JoinCourse
|
||||
#status = 0 表示给学生发,status = 1表示给老师发
|
||||
course_join = CourseMessage.new(:user_id =>user_id, :course_message_id=>User.current.id,:course_id => @course.id,:course_message_type=>"JoinCourse", :content => role, :viewed => false, :status => 0)
|
||||
course_join.save
|
||||
CourseMessage.create(:user_id => User.current.id, :course_message_id => user_id, :course_id => @course.id, :course_message_type => "JoinCourse",:content => role, :viewed => false, :status => 1)
|
||||
|
||||
members << member
|
||||
#user_grades << UserGrade.new(:user_id => user_id, :course_id => @course.id)
|
||||
if (params[:membership][:role_ids])
|
||||
|
|
@ -301,6 +313,8 @@ class MembersController < ApplicationController
|
|||
grade.destroy
|
||||
end
|
||||
end
|
||||
#移出项目发送消息
|
||||
ForgeMessage.create(:user_id => @member.user_id, :project_id => @project.id, :forge_message_type => "RemoveFromProject", :viewed => false, :forge_message_id => User.current.id)
|
||||
end
|
||||
respond_to do |format|
|
||||
format.html { redirect_to_settings_in_projects }
|
||||
|
|
@ -328,6 +342,8 @@ class MembersController < ApplicationController
|
|||
end
|
||||
@roles = Role.givable.all[3..5]
|
||||
@members = @course.member_principals.includes(:roles, :principal).all.sort
|
||||
#移出课程发送消息
|
||||
CourseMessage.create(:user_id => @member.user_id, :course_id => @course.id, :course_message_type => "RemoveFromCourse", :viewed => false, :course_message_id => User.current.id)
|
||||
end
|
||||
respond_to do |format|
|
||||
format.html { redirect_to_settings_in_courses }
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ class MemosController < ApplicationController
|
|||
include AttachmentsHelper
|
||||
include ApplicationHelper
|
||||
|
||||
layout 'base_memos'
|
||||
# layout 'base_memos'
|
||||
|
||||
def quote
|
||||
@subject = @memo.subject
|
||||
|
|
@ -73,41 +73,15 @@ class MemosController < ApplicationController
|
|||
end
|
||||
end
|
||||
#end
|
||||
format.html { redirect_to back_memo_url, notice: "#{l :label_memo_create_succ}" }
|
||||
format.json { render json: @memo, status: :created, location: @memo }
|
||||
format.js
|
||||
format.html { redirect_to back_memo_url, notice: "#{l :label_memo_create_succ}" }
|
||||
format.json { render json: @memo, status: :created, location: @memo }
|
||||
else
|
||||
flash.now[:error] = "#{l :label_memo_create_fail}: #{@memo.errors.full_messages[0]}"
|
||||
# back_error_page = @memo.parent_id.nil? ? forum_path(@forum) : forum_memo_path(@forum, @memo.parent_id)
|
||||
pre_count = REPLIES_PER_PAGE
|
||||
|
||||
@memo_new = @memo.dup
|
||||
@memo = @memo.root # 取出楼主,防止输入帖子id让回复作为主贴显示
|
||||
unless @memo.new_record?
|
||||
@memo.update_column(:viewed_count, (@memo.viewed_count.to_i + 1))
|
||||
end
|
||||
|
||||
|
||||
page = params[:page]
|
||||
if params[:r] && page.nil?
|
||||
offset = @memo.children.where("#{Memo.table_name}.id < ?", params[:r].to_i).count
|
||||
page = 1 + offset / pre_count
|
||||
else
|
||||
|
||||
end
|
||||
@reply_count = @memo.children.count
|
||||
@reply_pages = Paginator.new @reply_count, pre_count, page
|
||||
@replies = @memo.children.
|
||||
includes(:author, :attachments).
|
||||
reorder("#{Memo.table_name}.created_at DESC").
|
||||
limit(@reply_pages.per_page).
|
||||
offset(@reply_pages.offset).
|
||||
all
|
||||
if @memo.new_record?
|
||||
format.html { render :new,:layout=>'base'}
|
||||
else
|
||||
format.html { render action: :show }
|
||||
format.js
|
||||
format.html { redirect_to( forum_path(Forum.find(params[:forum_id]),:errors=>@memo.errors.full_messages[0])) }
|
||||
format.json { render json: @memo.errors, status: :unprocessable_entity }
|
||||
end
|
||||
#end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
@ -115,6 +89,7 @@ class MemosController < ApplicationController
|
|||
|
||||
REPLIES_PER_PAGE = 20 unless const_defined?(:REPLIES_PER_PAGE)
|
||||
def show
|
||||
|
||||
# 更新贴吧帖子留言对应的memo_messages的viewed字段
|
||||
unless @memo.children.blank?
|
||||
@memo.children.each do |child|
|
||||
|
|
@ -154,34 +129,45 @@ class MemosController < ApplicationController
|
|||
|
||||
@memo_new = Memo.new
|
||||
|
||||
|
||||
@my_topic_count = Memo.where("forum_id = #{@memo.forum_id} and author_id = #{User.current.id} and parent_id is null").count
|
||||
@my_replies_count = Memo.where("forum_id = #{@memo.forum_id} and author_id = #{User.current.id} and parent_id is not null").count
|
||||
# @memo = Memo.find_by_id(params[:id])
|
||||
# @forum = Forum.find(params[:forum_id])
|
||||
# @replies = @memo.replies
|
||||
# @mome_new = Memo.new
|
||||
|
||||
respond_to do |format|
|
||||
format.html # show.html.erb
|
||||
format.html {render :layout=> 'base_forums'}#:layout=> 'base_forums',
|
||||
format.json { render json: @memo }
|
||||
format.xml { render xml: @memo }
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
@my_topic_count = Memo.where("forum_id = #{@memo.forum_id} and author_id = #{User.current.id} and parent_id is null").count
|
||||
@my_replies_count = Memo.where("forum_id = #{@memo.forum_id} and author_id = #{User.current.id} and parent_id is not null").count
|
||||
@replying = false
|
||||
respond_to do |format|
|
||||
format.html {render :layout=>'base_forums'}
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
@flag = false
|
||||
respond_to do |format|
|
||||
if( #@memo.update_column(:subject, params[:memo][:subject]) &&
|
||||
@memo.update_column(:content, params[:memo][:content]) &&
|
||||
@memo.update_column(:sticky, params[:memo][:sticky]) &&
|
||||
@memo.update_column(:lock, params[:memo][:lock]))
|
||||
@memo.update_column(:lock, params[:memo][:lock]) &&
|
||||
@memo.update_column(:subject,params[:memo][:subject]) &&
|
||||
@memo.update_column(:updated_at,Time.now))
|
||||
@memo.save_attachments(params[:attachments] || (params[:memo] && params[:memo][:uploads]))
|
||||
@memo.save
|
||||
@flag = @memo.save
|
||||
# @memo.root.update_attribute(:updated_at, @memo.updated_at)
|
||||
format.js
|
||||
format.html {redirect_to back_memo_url, notice: "#{l :label_memo_create_succ}"}
|
||||
else
|
||||
format.js
|
||||
format.html { render action: "edit" }
|
||||
format.json { render json: @person.errors, status: :unprocessable_entity }
|
||||
end
|
||||
|
|
@ -227,7 +213,7 @@ class MemosController < ApplicationController
|
|||
end
|
||||
|
||||
def back_memo_url
|
||||
forum_memo_path(@forum, (@memo.parent_id.nil? ? @memo : @memo.parent_id))
|
||||
forum_memo_path(@forum, (@memo.root.nil? ? @memo : @memo.root))
|
||||
end
|
||||
|
||||
def back_memo_or_forum_url
|
||||
|
|
|
|||
|
|
@ -22,8 +22,8 @@ class MessagesController < ApplicationController
|
|||
default_search_scope :messages
|
||||
before_filter :find_board, :only => [:new, :preview,:edit]
|
||||
before_filter :find_attachments, :only => [:preview]
|
||||
before_filter :find_message, :except => [:new, :preview]
|
||||
before_filter :authorize, :except => [:preview, :edit, :destroy, :new]
|
||||
before_filter :find_message, :except => [:new, :preview, :join_org_subfield, :get_subfield_on_click_org, :join_org_subfields]
|
||||
before_filter :authorize, :except => [:preview, :edit, :destroy, :new,:join_org_subfield, :get_subfield_on_click_org, :join_org_subfields]
|
||||
|
||||
helper :boards
|
||||
helper :watchers
|
||||
|
|
@ -37,6 +37,7 @@ class MessagesController < ApplicationController
|
|||
|
||||
# Show a topic and its replies
|
||||
def show
|
||||
=begin
|
||||
if @course
|
||||
topic_id = params[:r]?params[:r]:params[:id]
|
||||
parent_id = params[:id]
|
||||
|
|
@ -44,6 +45,7 @@ class MessagesController < ApplicationController
|
|||
redirect_to url
|
||||
return;
|
||||
end
|
||||
=end
|
||||
|
||||
@isReply = true
|
||||
page = params[:page]
|
||||
|
|
@ -73,7 +75,7 @@ class MessagesController < ApplicationController
|
|||
@replies = paginateHelper messages_replies,10
|
||||
@reply = Message.new(:subject => "RE: #{@message.subject}")
|
||||
render :action => "show", :layout => "base_courses"#by young
|
||||
else
|
||||
elsif @project
|
||||
@reply_pages = Paginator.new @reply_count, REPLIES_PER_PAGE, page
|
||||
@replies = @topic.children.
|
||||
includes(:author, :attachments, {:board => :project}).
|
||||
|
|
@ -84,77 +86,71 @@ class MessagesController < ApplicationController
|
|||
|
||||
@reply = Message.new(:subject => "RE: #{@message.subject}")
|
||||
render :action => "show", :layout => "base_projects"#by young
|
||||
else
|
||||
@reply_pages = Paginator.new @reply_count, REPLIES_PER_PAGE, page
|
||||
@replies = @topic.children.
|
||||
includes(:author, :attachments, {:board => :project}).
|
||||
reorder("#{Message.table_name}.created_on DESC").
|
||||
limit(@reply_pages.per_page).
|
||||
offset(@reply_pages.offset).
|
||||
all
|
||||
|
||||
@reply = Message.new(:subject => "RE: #{@message.subject}")
|
||||
@organization = @org_subfield.organization
|
||||
render :action => "show", :layout => "base_org"#by young
|
||||
end
|
||||
end
|
||||
|
||||
# Create a new topic
|
||||
def new
|
||||
@message = Message.new
|
||||
@message.author = User.current
|
||||
@message.board = @board
|
||||
@message.safe_attributes = params[:message]
|
||||
if request.post?
|
||||
@message.save_attachments(params[:attachments])
|
||||
if @message.save
|
||||
# 更新kindeditor上传的图片资源所有者
|
||||
if params[:asset_id]
|
||||
ids = params[:asset_id].split(',')
|
||||
update_kindeditor_assets_owner ids,@message.id,OwnerTypeHelper::MESSAGE
|
||||
end
|
||||
# # 与我相关动态的记录add start
|
||||
# if(@board && @board.course) #项目的先不管
|
||||
# teachers = searchTeacherAndAssistant(@board.course)
|
||||
# for teacher in teachers
|
||||
# if(teacher.user_id != User.current.id)
|
||||
# notify = ActivityNotify.new()
|
||||
# if(@board.course)
|
||||
# notify.activity_container_id = @board.course_id
|
||||
# notify.activity_container_type = 'Course'
|
||||
# else
|
||||
# notify.activity_container_id = @board.project_id
|
||||
# notify.activity_container_type = 'Project'
|
||||
# end
|
||||
# notify.activity_id = @message.id
|
||||
# notify.activity_type = 'Message'
|
||||
# notify.notify_to = teacher.user_id
|
||||
# notify.is_read = 0
|
||||
# notify.save()
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
# 与我相关动态的记录add end
|
||||
if User.current.logged?
|
||||
@message = Message.new
|
||||
@message.author = User.current
|
||||
@message.board = @board
|
||||
@message.safe_attributes = params[:message]
|
||||
if request.post?
|
||||
@message.save_attachments(params[:attachments])
|
||||
if @message.save
|
||||
# 更新kindeditor上传的图片资源所有者
|
||||
if params[:asset_id]
|
||||
ids = params[:asset_id].split(',')
|
||||
update_kindeditor_assets_owner ids,@message.id,OwnerTypeHelper::MESSAGE
|
||||
end
|
||||
|
||||
call_hook(:controller_messages_new_after_save, { :params => params, :message => @message})
|
||||
render_attachment_warning_if_needed(@message)
|
||||
if params[:is_board]
|
||||
if @project
|
||||
redirect_to project_boards_path(@project)
|
||||
elsif @course
|
||||
redirect_to course_boards_path(@course)
|
||||
call_hook(:controller_messages_new_after_save, { :params => params, :message => @message})
|
||||
render_attachment_warning_if_needed(@message)
|
||||
if params[:is_board]
|
||||
if @project
|
||||
redirect_to project_boards_path(@project)
|
||||
elsif @course
|
||||
redirect_to course_boards_path(@course)
|
||||
end
|
||||
else
|
||||
redirect_to board_message_url(@board, @message)
|
||||
end
|
||||
else
|
||||
redirect_to board_message_url(@board, @message)
|
||||
if params[:is_board]
|
||||
if @project
|
||||
redirect_to project_boards_path(@project, :flag => true)
|
||||
elsif @course
|
||||
redirect_to course_boards_path(@course, :flag => true)
|
||||
end
|
||||
else
|
||||
layout_file = @project ? 'base_projects' : 'base_courses'
|
||||
render :action => 'new', :layout => layout_file
|
||||
end
|
||||
|
||||
end
|
||||
else
|
||||
if params[:is_board]
|
||||
if @project
|
||||
redirect_to project_boards_path(@project, :flag => true)
|
||||
elsif @course
|
||||
redirect_to course_boards_path(@course, :flag => true)
|
||||
end
|
||||
else
|
||||
layout_file = @project ? 'base_projects' : 'base_courses'
|
||||
render :action => 'new', :layout => layout_file
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
layout_file = @project ? 'base_projects' : 'base_courses'
|
||||
render :layout => layout_file
|
||||
}
|
||||
end
|
||||
|
||||
end
|
||||
else
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
layout_file = @project ? 'base_projects' : 'base_courses'
|
||||
render :layout => layout_file
|
||||
}
|
||||
end
|
||||
redirect_to signin_path
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -178,7 +174,13 @@ class MessagesController < ApplicationController
|
|||
@reply.safe_attributes = params[:reply]
|
||||
@reply.content = @quote + @reply.content
|
||||
@reply.subject = "RE: #{@topic.subject}" unless params[:reply][:subject]
|
||||
# @reply.reply_id = params[:id]
|
||||
@topic.children << @reply
|
||||
update_course_activity(@topic.class,@topic.id)
|
||||
update_user_activity(@topic.class,@topic.id)
|
||||
update_forge_activity(@topic.class,@topic.id)
|
||||
update_org_activity(@topic.class,@topic.id)
|
||||
|
||||
#@topic.update_attribute(:updated_on, Time.now)
|
||||
if !@reply.new_record?
|
||||
if params[:asset_id]
|
||||
|
|
@ -194,6 +196,8 @@ class MessagesController < ApplicationController
|
|||
end
|
||||
if params[:user_activity_id]
|
||||
@user_activity_id = params[:user_activity_id]
|
||||
@is_course = params[:is_course]
|
||||
@is_board = params[:is_board]
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
|
|
@ -214,17 +218,27 @@ class MessagesController < ApplicationController
|
|||
@isReply = false
|
||||
if @project
|
||||
(render_403; return false) unless @message.editable_by?(User.current)
|
||||
else
|
||||
elsif @course
|
||||
(render_403; return false) unless @message.course_editable_by?(User.current)
|
||||
else
|
||||
(render_403; return false) unless @message.org_subfield_editable_by?(User.current)
|
||||
end
|
||||
|
||||
@message.safe_attributes = params[:message]
|
||||
if request.post? && @message.save
|
||||
attachments = Attachment.attach_files(@message, params[:attachments])
|
||||
render_attachment_warning_if_needed(@message)
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
#flash[:notice] = l(:notice_successful_update)
|
||||
@message.reload
|
||||
if params[:is_board]
|
||||
if params[:is_course] && params[:is_course].to_i == 0
|
||||
redirect_to user_activities_path(User.current.id)
|
||||
elsif params[:is_course] && params[:is_course].to_i == 1 && params[:is_board] && params[:is_board].to_i == 0
|
||||
if @project
|
||||
redirect_to project_path(@project)
|
||||
elsif @course
|
||||
redirect_to course_activity_path(@course)
|
||||
end
|
||||
elsif params[:is_course] && params[:is_course].to_i == 1 && params[:is_board] && params[:is_board].to_i == 1
|
||||
if @project
|
||||
redirect_to project_boards_path(@project)
|
||||
elsif @course
|
||||
|
|
@ -234,19 +248,22 @@ class MessagesController < ApplicationController
|
|||
redirect_to board_message_url(@message.board, @message.root, :r => (@message.parent_id && @message.id))
|
||||
end
|
||||
elsif request.get? || request.post?
|
||||
if params[:is_board]
|
||||
if @project
|
||||
redirect_to project_boards_path(@project)
|
||||
elsif @course
|
||||
redirect_to course_boards_path(@course)
|
||||
end
|
||||
else
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
layout_file = @project ? 'base_projects' : 'base_courses'
|
||||
render :layout => layout_file
|
||||
}
|
||||
end
|
||||
if params[:is_course] && params[:is_board]
|
||||
@is_course = params[:is_course]
|
||||
@is_board = params[:is_board]
|
||||
end
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
if @project
|
||||
layout_file = 'base_projects'
|
||||
elsif @course
|
||||
layout_file = 'base_courses'
|
||||
elsif @org_subfield
|
||||
@organization = @org_subfield.organization
|
||||
layout_file = 'base_org'
|
||||
end
|
||||
render :layout => layout_file
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -255,26 +272,46 @@ class MessagesController < ApplicationController
|
|||
def destroy
|
||||
if @project
|
||||
(render_403; return false) unless @message.destroyable_by?(User.current)
|
||||
else
|
||||
elsif @course
|
||||
(render_403; return false) unless @message.course_destroyable_by?(User.current)
|
||||
else
|
||||
(render_403; return false) unless @message.org_subfield_editable_by?(User.current)
|
||||
end
|
||||
r = @message.to_param
|
||||
@message.destroy
|
||||
# modify by nwb
|
||||
if @project
|
||||
if params[:is_board]
|
||||
redirect_to project_boards_url(@project)
|
||||
if params[:is_course] && params[:is_course].to_i == 0
|
||||
redirect_to user_activities_path(User.current.id)
|
||||
elsif params[:is_course] && params[:is_course].to_i == 1 && params[:is_board] && params[:is_board].to_i == 0
|
||||
redirect_to project_path(@project)
|
||||
elsif params[:is_course] && params[:is_course].to_i == 1 && params[:is_board] && params[:is_board].to_i == 1
|
||||
redirect_to project_boards_path(@project)
|
||||
elsif @message.parent
|
||||
redirect_to board_message_url(@board, @message.parent, :r => r)
|
||||
else
|
||||
redirect_to board_message_url(@board, @topic, :r => @reply)
|
||||
redirect_to project_board_url(@project, @board)
|
||||
end
|
||||
elsif @course
|
||||
if params[:is_course] && params[:is_course].to_i == 0
|
||||
redirect_to user_activities_path(User.current.id)
|
||||
elsif params[:is_course] && params[:is_course].to_i == 1 && params[:is_board] && params[:is_board].to_i == 0
|
||||
redirect_to course_activity_path(@course)
|
||||
elsif params[:is_course] && params[:is_course].to_i == 1 && params[:is_board] && params[:is_board].to_i == 1
|
||||
redirect_to course_boards_path(@course)
|
||||
elsif @message.parent
|
||||
redirect_to board_message_url(@board, @message.parent, :r => r)
|
||||
else
|
||||
redirect_to course_boards_path(@course)
|
||||
end
|
||||
elsif @org_subfield
|
||||
if params[:is_board]
|
||||
redirect_to course_boards_url(@course)
|
||||
redirect_to organization_path(:id => @org_subfield.organization_id, :org_subfield_id => @org_subfield.id)
|
||||
else
|
||||
if @message.parent
|
||||
redirect_to board_message_url(@board, @message.parent, :r => r)
|
||||
else
|
||||
redirect_to course_board_url(@course, @board)
|
||||
redirect_to organization_path(:id => @org_subfield.organization_id, :org_subfield_id => @org_subfield.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -296,6 +333,41 @@ class MessagesController < ApplicationController
|
|||
render :partial => 'common/preview'
|
||||
end
|
||||
|
||||
def join_org_subfield
|
||||
@message = Message.find(params[:message_id])
|
||||
@organizations = User.current.organizations
|
||||
end
|
||||
|
||||
def get_subfield_on_click_org
|
||||
@org = Organization.find(params[:organization_id])
|
||||
end
|
||||
|
||||
def join_org_subfields
|
||||
org_subfield_ids = params[:org_subfields]
|
||||
@message = Message.find(params[:id])
|
||||
# @message.update_attribute(:updated_on, Time.now)
|
||||
# type = @message.board.course_id.nil? ? "Project":"Course"
|
||||
org_subfield_ids.each do |field_id|
|
||||
@message.quotes = @message.quotes.nil? ? 1 : (@message.quotes + 1)
|
||||
@message.save
|
||||
board = OrgSubfield.find(field_id).boards.first
|
||||
mes = Message.create(:board_id => board.id, :subject => @message.subject, :content => @message.content, :author_id => User.current.id,
|
||||
:created_on => Time.now, :updated_on => Time.now, :locked => @message.locked, :sticky => @message.sticky)
|
||||
@message.attachments.each do |attach|
|
||||
mes.attachments << Attachment.new(:filename => attach.filename, :disk_filename => attach.disk_filename, :filesize => attach.filesize, :content_type => attach.content_type, :digest => attach.digest,
|
||||
:downloads => 0, :author_id => User.current.id, :created_on => Time.now, :description => attach.description, :disk_directory => attach.disk_directory, :attachtype => attach.attachtype,
|
||||
:is_public => attach.is_public, :quotes => 0)
|
||||
end
|
||||
# OrgSubfieldMessage.create(:org_subfield_id => field_id.to_i, :message_id => mes.id, :message_type => type)
|
||||
# org_acts = OrgActivity.where("container_type='OrgSubfield' and container_id=? and org_act_type='Message' and org_act_id=?", field_id.to_i, @message.id)
|
||||
# if org_acts.all.size() > 0
|
||||
# org_acts.first.update_attribute(:updated_at, Time.now)
|
||||
# else
|
||||
OrgActivity.create(:container_type => 'OrgSubfield', :container_id => field_id.to_i, :org_act_type=>'Message', :org_act_id => mes.id, :user_id => User.current.id)
|
||||
# end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def find_message
|
||||
return unless find_board
|
||||
|
|
@ -312,6 +384,9 @@ class MessagesController < ApplicationController
|
|||
@project = @board.project
|
||||
elsif @board.course_id
|
||||
@course = @board.course
|
||||
else
|
||||
@org_subfield = @board.org_subfield
|
||||
@organization = @org_subfield
|
||||
end
|
||||
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ class MyController < ApplicationController
|
|||
flash[:notice] = l(:notice_mail_notification_updated)
|
||||
redirect_to my_account_url
|
||||
else
|
||||
redirect_to signin_url
|
||||
redirect_to signin_url
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -109,16 +109,27 @@ class MyController < ApplicationController
|
|||
# Edit user's account
|
||||
def account
|
||||
@user = User.current
|
||||
|
||||
lg=@user.login
|
||||
@pref = @user.pref
|
||||
diskfile = disk_filename('User', @user.id)
|
||||
diskfile1 = diskfile + 'temp'
|
||||
begin
|
||||
if request.post?
|
||||
# 修改邮箱的时候同步修改到gitlab
|
||||
if @user.mail != params[:user][:mail]
|
||||
g = Gitlab.client
|
||||
begin
|
||||
g.edit_user(@user.gid, :email => params[:user][:mail])
|
||||
rescue
|
||||
logger.error "sync user's email of gitlab failed!"
|
||||
end
|
||||
end
|
||||
|
||||
@user.safe_attributes = params[:user]
|
||||
@user.pref.attributes = params[:pref]
|
||||
@user.pref[:no_self_notified] = (params[:no_self_notified] == '1')
|
||||
@user.login = params[:login]
|
||||
#@user.login = params[:login]
|
||||
unless @user.user_extensions.nil?
|
||||
if @user.user_extensions.identity == 2
|
||||
@user.firstname = params[:enterprise_name]
|
||||
|
|
@ -126,11 +137,13 @@ class MyController < ApplicationController
|
|||
end
|
||||
|
||||
@se = @user.extensions
|
||||
if params[:occupation].to_i.to_s == params[:occupation]
|
||||
@se.school_id = params[:occupation]
|
||||
else
|
||||
@se.occupation = params[:occupation]
|
||||
end
|
||||
# if params[:occupation].to_i.to_s == params[:occupation]
|
||||
# @se.school_id = params[:occupation]
|
||||
# else
|
||||
# @se.occupation = params[:occupation]
|
||||
# end
|
||||
@se.school_id = params[:occupation]
|
||||
|
||||
@se.gender = params[:gender]
|
||||
@se.location = params[:province] if params[:province]
|
||||
@se.location_city = params[:city] if params[:city]
|
||||
|
|
@ -210,7 +223,7 @@ class MyController < ApplicationController
|
|||
end
|
||||
flash.now[:error] = l(:notice_account_old_wrong_password)
|
||||
end
|
||||
render :template => 'my/account',:layout=>'base_users_new'
|
||||
render :template => 'my/account',:layout=>'new_base_user'
|
||||
end
|
||||
|
||||
# Create a new feeds key
|
||||
|
|
|
|||
|
|
@ -46,15 +46,16 @@ class NewsController < ApplicationController
|
|||
@course = Course.find(params[:course_id])
|
||||
end
|
||||
if @project
|
||||
@page = params[:page] ? params[:page].to_i + 1 : 0
|
||||
scope = @project ? @project.news.visible : News.visible
|
||||
|
||||
@news_count = scope.count
|
||||
@news_pages = Paginator.new @news_count, @limit, params['page']
|
||||
@offset ||= @news_pages.offset
|
||||
#@news_pages = Paginator.new @news_count, @limit, params['page']
|
||||
#@offset ||= @news_pages.offset
|
||||
@newss = scope.all(:include => [:author, :project],
|
||||
:order => "#{News.table_name}.created_on DESC",
|
||||
:offset => @offset,
|
||||
:limit => @limit)
|
||||
:offset => @page * 10,
|
||||
:limit => 10)
|
||||
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
|
|
@ -63,26 +64,32 @@ class NewsController < ApplicationController
|
|||
|
||||
render :layout => false if request.xhr?
|
||||
}
|
||||
format.js
|
||||
format.api
|
||||
format.atom { render_feed(@newss, :title => (@project ? @project.name : Setting.app_title) + ": #{l(:label_news_plural)}") }
|
||||
end
|
||||
elsif @course
|
||||
if (User.current.admin? || @course.is_public == 1 || (@course.is_public == 0 && User.current.member_of_course?(@course)))
|
||||
scope = @course ? @course.news.course_visible : News.course_visible
|
||||
news_arr = scope.map{|news| news.id}
|
||||
|
||||
|
||||
@page = params[:page] ? params[:page].to_i + 1 : 0
|
||||
news_page = @page *10
|
||||
@news_count = scope.count
|
||||
@is_new = params[:is_new]
|
||||
@q = params[:subject]
|
||||
if params[:subject].nil? || params[:subject].blank?
|
||||
scope_order = scope.all(:include => [:author, :course],
|
||||
:order => "#{News.table_name}.created_on DESC")
|
||||
scope_order = scope.reorder("#{News.table_name}.sticky DESC, #{News.table_name}.created_on DESC").limit(10).offset(news_page).includes(:author,:course).all()
|
||||
#all(:include => [:author, :course],
|
||||
#:order => "#{News.table_name}.sticky DESC, #{News.table_name}.created_on DESC").limit(10).offset(news_page)
|
||||
else
|
||||
scope_order = scope.where("#{News.table_name}.title like '#{'%' << params[:subject].to_s << '%'}'").all(:include => [:author, :course],
|
||||
:order => "#{News.table_name}.created_on DESC")
|
||||
scope_order = scope.where("#{News.table_name}.title like '#{'%' << params[:subject].to_s << '%'}'").reorder("#{News.table_name}.sticky DESC, #{News.table_name}.created_on DESC").limit(10).offset(news_page).includes(:author,:course).all()
|
||||
#.all(:include => [:author, :course],:order => "#{News.table_name}.sticky DESC, #{News.table_name}.created_on DESC")
|
||||
end
|
||||
|
||||
# :offset => @offset,
|
||||
# :limit => @limit)
|
||||
@newss = paginateHelper scope_order,10
|
||||
@newss = scope_order
|
||||
#@newss = paginateHelper scope_order,10
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
@news = News.new
|
||||
|
|
@ -130,6 +137,7 @@ class NewsController < ApplicationController
|
|||
result = cs.show_course_news params,User.current
|
||||
@news = result[:news]
|
||||
@comments = result[:comments]
|
||||
@comment = Comment.new
|
||||
#@comments = @news.comments
|
||||
#@comments.reverse! if User.current.wants_comments_in_reverse_order?
|
||||
#modify by nwb
|
||||
|
|
@ -138,6 +146,10 @@ class NewsController < ApplicationController
|
|||
if @course
|
||||
render :layout => 'base_courses'
|
||||
end
|
||||
elsif @news.org_subfield_id
|
||||
@org_subfield = OrgSubfield.find(@news.org_subfield_id)
|
||||
@organization = @org_subfield.organization
|
||||
render :layout => 'base_org'
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -145,9 +157,39 @@ class NewsController < ApplicationController
|
|||
#modify by nwb
|
||||
if @project
|
||||
@news = News.new(:project => @project, :author => User.current)
|
||||
@news.safe_attributes = params[:news]
|
||||
@news.save_attachments(params[:attachments])
|
||||
if @news.save
|
||||
if params[:asset_id]
|
||||
ids = params[:asset_id].split(',')
|
||||
update_kindeditor_assets_owner ids,@news.id,OwnerTypeHelper::NEWS
|
||||
end
|
||||
render_attachment_warning_if_needed(@news)
|
||||
#flash[:notice] = l(:notice_successful_create)
|
||||
redirect_to project_news_index_url(@project)
|
||||
else
|
||||
redirect_to project_news_index_url(@project)
|
||||
#layout_file = 'base_courses'
|
||||
#render :action => 'new', :layout => layout_file
|
||||
end
|
||||
elsif @course
|
||||
@news = News.new(:course => @course, :author => User.current)
|
||||
render :layout => 'base_courses'
|
||||
#render :layout => 'base_courses'
|
||||
@news.safe_attributes = params[:news]
|
||||
@news.save_attachments(params[:attachments])
|
||||
if @news.save
|
||||
if params[:asset_id]
|
||||
ids = params[:asset_id].split(',')
|
||||
update_kindeditor_assets_owner ids,@news.id,OwnerTypeHelper::NEWS
|
||||
end
|
||||
render_attachment_warning_if_needed(@news)
|
||||
#flash[:notice] = l(:notice_successful_create)
|
||||
redirect_to course_news_index_url(@course)
|
||||
else
|
||||
redirect_to course_news_index_url(@course)
|
||||
#layout_file = 'base_courses'
|
||||
#render :action => 'new', :layout => layout_file
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -175,19 +217,19 @@ class NewsController < ApplicationController
|
|||
update_kindeditor_assets_owner ids,@news.id,OwnerTypeHelper::NEWS
|
||||
end
|
||||
# <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ض<EFBFBD>̬<EFBFBD>ļ<EFBFBD>¼add start
|
||||
teachers = searchTeacherAndAssistant(@course)
|
||||
for teacher in teachers
|
||||
if(teacher.user_id != User.current.id)
|
||||
notify = ActivityNotify.new()
|
||||
notify.activity_container_id = @course.id
|
||||
notify.activity_container_type = 'Course'
|
||||
notify.activity_id = @news.id
|
||||
notify.activity_type = 'News'
|
||||
notify.notify_to = teacher.user_id
|
||||
notify.is_read = 0
|
||||
notify.save()
|
||||
end
|
||||
end
|
||||
# teachers = searchTeacherAndAssistant(@course)
|
||||
# for teacher in teachers
|
||||
# if(teacher.user_id != User.current.id)
|
||||
# notify = ActivityNotify.new()
|
||||
# notify.activity_container_id = @course.id
|
||||
# notify.activity_container_type = 'Course'
|
||||
# notify.activity_id = @news.id
|
||||
# notify.activity_type = 'News'
|
||||
# notify.notify_to = teacher.user_id
|
||||
# notify.is_read = 0
|
||||
# notify.save()
|
||||
# end
|
||||
# end
|
||||
# <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ض<EFBFBD>̬<EFBFBD>ļ<EFBFBD>¼add end
|
||||
render_attachment_warning_if_needed(@news)
|
||||
flash[:notice] = l(:notice_successful_create)
|
||||
|
|
@ -200,8 +242,14 @@ class NewsController < ApplicationController
|
|||
end
|
||||
|
||||
def edit
|
||||
if @news.org_subfield_id
|
||||
@org_subfield = OrgSubfield.find(@news.org_subfield_id)
|
||||
@organization = @org_subfield.organization
|
||||
end
|
||||
if @course
|
||||
render :layout => "base_courses"
|
||||
elsif @org_subfield
|
||||
render :layout => 'base_org'
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -210,7 +258,7 @@ class NewsController < ApplicationController
|
|||
@news.save_attachments(params[:attachments])
|
||||
if @news.save
|
||||
render_attachment_warning_if_needed(@news)
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
#flash[:notice] = l(:notice_successful_update)
|
||||
redirect_to news_url(@news)
|
||||
else
|
||||
#flash[:error] = l(:notice_successful_update)
|
||||
|
|
@ -219,12 +267,17 @@ class NewsController < ApplicationController
|
|||
end
|
||||
|
||||
def destroy
|
||||
if @news.org_subfield_id
|
||||
@org_subfield = OrgSubfield.find(@news.org_subfield_id)
|
||||
end
|
||||
@news.destroy
|
||||
# modify by nwb
|
||||
if @project
|
||||
redirect_to project_news_index_url(@project)
|
||||
elsif @course
|
||||
redirect_to course_news_index_url(@course)
|
||||
elsif @org_subfield
|
||||
redirect_to organization_path(@org_subfield.organization, :org_subfield_id => @org_subfield.id)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -0,0 +1,20 @@
|
|||
class OrgCoursesController < ApplicationController
|
||||
def create
|
||||
org_ids = params[:orgNames]
|
||||
@course = Course.find(params[:course_id])
|
||||
org_ids.each do |org_id|
|
||||
if OrgCourse.where("organization_id =? and course_id =?", org_id.to_i, params[:course_id].to_i).count == 0
|
||||
OrgCourse.create(:organization_id => org_id.to_i, :course_id => params[:course_id].to_i, :created_at => Time.now)
|
||||
end
|
||||
end
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@course = Course.find(params[:course_id])
|
||||
@org_course = OrgCourse.find(params[:id])
|
||||
@org_course.destroy
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,174 @@
|
|||
class OrgDocumentCommentsController < ApplicationController
|
||||
before_filter :find_organization, :only => [:new, :create, :show, :index]
|
||||
helper :attachments
|
||||
layout 'base_org'
|
||||
|
||||
def new
|
||||
@org_document_comment = OrgDocumentComment.new
|
||||
end
|
||||
|
||||
|
||||
def create
|
||||
@org_document_comment = OrgDocumentComment.new(:organization_id => @organization.id, :creator_id => User.current.id)
|
||||
@org_document_comment.title = params[:org_document_comment][:title]
|
||||
@org_document_comment.content = params[:org_document_comment][:content]
|
||||
@org_document_comment.save_attachments(params[:attachments])
|
||||
if params[:field_id]
|
||||
@org_document_comment.org_subfield_id = params[:field_id].to_i
|
||||
end
|
||||
if @org_document_comment.save
|
||||
flash.keep[:notice] = l(:notice_successful_create)
|
||||
EditorOfDocument.create(:editor_id => User.current.id, :org_document_comment_id => @org_document_comment.id, :created_at => @org_document_comment.updated_at)
|
||||
if params[:field_id]
|
||||
@org_subfield = OrgSubfield.find(params[:field_id])
|
||||
if @org_subfield.subfield_subdomain_dir.nil?
|
||||
redirect_to organization_path(@organization, :org_subfield_id => params[:field_id])
|
||||
else
|
||||
redirect_to show_org_subfield_organization_path(:id => @organization.id, :sub_dir_name => @org_subfield.subfield_subdomain_dir.name)
|
||||
end
|
||||
else
|
||||
redirect_to organization_org_document_comments_path(@organization)
|
||||
end
|
||||
else
|
||||
redirect_to new_org_document_comment_path(:organization_id => @organization.id)
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
@document = OrgDocumentComment.find(params[:id])
|
||||
end
|
||||
|
||||
def index
|
||||
if @organization.is_public? || User.current.admin? || User.current.member_of_org?(@organization)
|
||||
@documents = @organization.org_document_comments.where("parent_id is null").order("created_at desc")
|
||||
else
|
||||
render_403
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
@org_document = OrgDocumentComment.find(params[:id])
|
||||
@org_document.update_attributes(:title => params[:org_document_comment][:title], :content => params[:org_document_comment][:content])
|
||||
Attachment.attach_files(@org_document, params[:attachments])
|
||||
# @org_document.save_attachments(params[:attachments])
|
||||
if @org_document.parent.nil?
|
||||
act = OrgActivity.where("org_act_type='OrgDocumentComment' and org_act_id =?", @org_document.id).first
|
||||
act.update_attributes(:updated_at => @org_document.updated_at)
|
||||
EditorOfDocument.create(:editor_id => User.current.id, :org_document_comment_id => @org_document.id, :created_at => Time.now)
|
||||
end
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
if params[:flag].to_i == 0
|
||||
redirect_to organization_org_document_comments_path(:organization_id => @org_document.organization.id)
|
||||
else
|
||||
if params[:flag].to_i == 1
|
||||
redirect_to org_document_comment_path(@org_document.root.id, :organization_id => @org_document.organization.id)
|
||||
else
|
||||
redirect_to organization_path(@org_document.organization.id, :org_subfield_id => params[:org_subfield_id])
|
||||
end
|
||||
end
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
@org_document = OrgDocumentComment.find(params[:id])
|
||||
@flag = params[:flag]
|
||||
@organization = Organization.find(params[:organization_id])
|
||||
end
|
||||
|
||||
def add_reply
|
||||
@document = OrgDocumentComment.find(params[:id]).root
|
||||
@act = OrgActivity.find(params[:id])
|
||||
@comment = OrgDocumentComment.new(:organization_id => @document.organization_id, :creator_id => User.current.id, :reply_id => params[:id])
|
||||
@comment.content = params[:org_content]
|
||||
@document.children << @comment
|
||||
@document.save
|
||||
end
|
||||
|
||||
def add_reply_in_doc
|
||||
@document = OrgDocumentComment.find(params[:id]).root
|
||||
@comment = OrgDocumentComment.new(:organization_id => @document.organization_id, :creator_id => User.current.id, :reply_id => params[:id])
|
||||
@comment.content = params[:org_comment][:org_content]
|
||||
@document.children << @comment
|
||||
@document.save
|
||||
respond_to do |format|
|
||||
format.html {redirect_to org_document_comment_path(:id => @document.id, :organization_id => @document.organization_id)}
|
||||
end
|
||||
end
|
||||
|
||||
def find_organization
|
||||
@organization = Organization.find(params[:organization_id])
|
||||
end
|
||||
|
||||
def destroy
|
||||
@org_document_comment = OrgDocumentComment.find(params[:id])
|
||||
org = @org_document_comment.organization
|
||||
if @org_document_comment.id == org.home_id
|
||||
org.update_attributes(:home_id => nil)
|
||||
end
|
||||
if @org_document_comment.destroy
|
||||
end
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def delete_reply
|
||||
@org_document_comment = OrgDocumentComment.find(params[:id])
|
||||
@document = @org_document_comment.root
|
||||
org = @org_document_comment.organization
|
||||
@org_document_comment.destroy
|
||||
respond_to do |format|
|
||||
format.html {redirect_to org_document_comment_path(:id => @document.id, :organization_id => @document.organization_id)}
|
||||
end
|
||||
end
|
||||
def quote
|
||||
@org_comment = OrgDocumentComment.find(params[:id])
|
||||
@subject = @org_comment.content
|
||||
@subject = "RE: #{@subject}" unless @subject.starts_with?('RE:')
|
||||
|
||||
@content = "> #{ll(Setting.default_language, :text_user_wrote, User.find(@org_comment.creator_id).realname)}\n> "
|
||||
@temp = OrgDocumentComment.new
|
||||
#@course_id = params[:course_id]
|
||||
@temp.content = "<blockquote>#{ll(Setting.default_language, :text_user_wrote, User.find(@org_comment.creator_id).realname)} <br/>#{@org_comment.content.html_safe}</blockquote>".html_safe
|
||||
respond_to do | format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def reply
|
||||
@document = OrgDocumentComment.find(params[:id]).root
|
||||
@quote = params[:quote][:quote]
|
||||
@org_document = OrgDocumentComment.new(:creator_id => User.current.id, :reply_id => params[:id])
|
||||
|
||||
# params[:blog_comment][:sticky] = params[:blog_comment][:sticky] || 0
|
||||
# params[:blog_comment][:locked] = params[:blog_comment][:locked] || 0
|
||||
@org_document.title = params[:org_document_comment][:title]
|
||||
@org_document.content = params[:org_document_comment][:content]
|
||||
@org_document.content = @quote + @org_document.content
|
||||
#@org_document.title = "RE: #{@article.title}" unless params[:blog_comment][:title]
|
||||
@document.children << @org_document
|
||||
# @user_activity_id = params[:user_activity_id]
|
||||
# user_activity = UserActivity.where("act_type='BlogComment' and act_id =#{@article.id}").first
|
||||
# if user_activity
|
||||
# user_activity.updated_at = Time.now
|
||||
# user_activity.save
|
||||
# end
|
||||
# attachments = Attachment.attach_files(@org_document, params[:attachments])
|
||||
# render_attachment_warning_if_needed(@org_document)
|
||||
#@article.save
|
||||
# redirect_to user_blogs_path(:user_id=>params[:user_id])
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
# if params[:course_id] #如果呆了course_id过来了,那么这是要跳到课程大纲去的
|
||||
# redirect_to syllabus_course_path(:id=>params[:course_id])
|
||||
# else
|
||||
redirect_to org_document_comment_path(:id => @document.id, :organization_id => @document.organization_id)
|
||||
# end
|
||||
|
||||
}
|
||||
format.js
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
class OrgMemberController < ApplicationController
|
||||
|
||||
def org_member_autocomplete
|
||||
@org = Organization.find(params[:org])
|
||||
@flag = params[:flag] || false
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
@org = Organization.find(params[:org])
|
||||
if params[:membership].nil?
|
||||
@fail_hint = l(:label_blank_user_lists_for_org)
|
||||
else
|
||||
member_ids = params[:membership][:user_ids]
|
||||
role_id = params[:orgRole]
|
||||
member_ids.each do |user_id|
|
||||
member = OrgMember.create(:user_id=>user_id, :created_at => Time.now)
|
||||
@org.org_members << member
|
||||
OrgMemberRole.create(:org_member_id => member.id, :role_id => role_id)
|
||||
end
|
||||
end
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
@member = OrgMember.find(params[:id])
|
||||
#@member.change_role params[:org_member][:role_ids]
|
||||
@member_role = @member.org_member_roles[0]
|
||||
@member_role.role_id = params[:org_member][:role_ids][0]
|
||||
@member_role.save
|
||||
@org = @member.organization
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def new
|
||||
|
||||
end
|
||||
|
||||
def destroy
|
||||
member = OrgMember.find(params[:id])
|
||||
@org = member.organization
|
||||
member.destroy
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def index
|
||||
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
class OrgProjectsController < ApplicationController
|
||||
def create
|
||||
org_ids = params[:orgNames]
|
||||
@project = Project.find(params[:project_id])
|
||||
org_ids.each do |org_id|
|
||||
if OrgProject.where("organization_id =? and project_id =?", org_id.to_i, @project.id).count == 0
|
||||
OrgProject.create(:organization_id => org_id.to_i, :project_id => params[:project_id].to_i, :created_at => Time.now)
|
||||
end
|
||||
end
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
def destroy
|
||||
@project = Project.find(params[:project_id])
|
||||
@org_project = OrgProject.find(params[:id])
|
||||
@org_project.destroy
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,144 @@
|
|||
class OrgSubfieldsController < ApplicationController
|
||||
helper :attachments
|
||||
include FilesHelper
|
||||
layout 'base_org'
|
||||
def create
|
||||
if OrgSubfield.where("organization_id=#{params[:organization_id]} and name=?",params[:name]).count == 0
|
||||
@res = true
|
||||
@subfield = OrgSubfield.create(:name => params[:name])
|
||||
@organization = Organization.find(params[:organization_id])
|
||||
@organization.org_subfields << @subfield
|
||||
if !params[:sub_dir].blank?
|
||||
sql = "select subfield_subdomain_dirs.* from subfield_subdomain_dirs, org_subfields where subfield_subdomain_dirs.org_subfield_id = org_subfields.id "+
|
||||
"and org_subfields.organization_id=#{@organization.id} and subfield_subdomain_dirs.name='#{params[:sub_dir]}'"
|
||||
if SubfieldSubdomainDir.find_by_sql(sql).count == 0
|
||||
SubfieldSubdomainDir.create(:org_subfield_id => @subfield.id, :name => params[:sub_dir])
|
||||
end
|
||||
end
|
||||
@subfield.update_attributes(:priority => @subfield.id, :field_type => params[:field_type])
|
||||
else
|
||||
@res = false
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
@flag = params[:flag] || false
|
||||
sort = ""
|
||||
@sort = ""
|
||||
@order = ""
|
||||
@is_remote = false
|
||||
if params[:id]
|
||||
@organization = Organization.find(params[:id])
|
||||
else
|
||||
@organization = Organization.where("domain=?",request.subdomain).first
|
||||
end
|
||||
@org_subfield = OrgSubfield.find_by_sql("select distinct org_subfields.* from org_subfields,"+
|
||||
"subfield_subdomain_dirs where org_subfields.id = subfield_subdomain_dirs.org_subfield_id and "+
|
||||
" org_subfields.organization_id=#{@organization.id} and subfield_subdomain_dirs.name='#{params[:sub_dir_name]}'").first
|
||||
if @org_subfield.field_type == 'Post'
|
||||
@org_subfield_ids = @org_subfield.org_document_comments.map(&:id) << 0
|
||||
@org_activities = OrgActivity.where("(org_act_type='OrgDocumentComment'and org_act_id in (#{@org_subfield_ids.join(",")})) || (container_type='OrgSubfield' and container_id=#{@org_subfield.id})").order('updated_at desc').page(params[:page] || 1).per(10)
|
||||
#redirect_to organization_path(@organization, :org_subfield_id => @org_subfield.id)
|
||||
else
|
||||
if params[:sort]
|
||||
params[:sort].split(",").each do |sort_type|
|
||||
order_by = sort_type.split(":")
|
||||
case order_by[0]
|
||||
when "filename"
|
||||
attribute = "filename"
|
||||
when "size"
|
||||
attribute = "filesize"
|
||||
when "attach_type"
|
||||
attribute = "attachtype"
|
||||
when "content_type"
|
||||
attribute = "created_on"
|
||||
when "field_file_dense"
|
||||
attribute = "is_public"
|
||||
when "downloads"
|
||||
attribute = "downloads"
|
||||
when "created_on"
|
||||
attribute = "created_on"
|
||||
when "quotes"
|
||||
attribute = "quotes"
|
||||
else
|
||||
attribute = "created_on"
|
||||
end
|
||||
@sort = order_by[0]
|
||||
@order = order_by[1]
|
||||
if order_by.count == 1 && attribute
|
||||
sort += "#{Attachment.table_name}.#{attribute} asc "
|
||||
if sort_type != params[:sort].split(",").last
|
||||
sort += ","
|
||||
end
|
||||
elsif order_by.count == 2 && order_by[1]
|
||||
sort += "#{Attachment.table_name}.#{attribute} #{order_by[1]} "
|
||||
if sort_type != params[:sort].split(",").last
|
||||
sort += ","
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
sort = "#{Attachment.table_name}.created_on desc"
|
||||
end
|
||||
@container_type = 2
|
||||
@containers = [ OrgSubfield.includes(:attachments).reorder(sort).find(@org_subfield.id)]
|
||||
@organization = Organization.find(@containers.first.organization_id)
|
||||
show_attachments @containers
|
||||
@tag_list = attachment_tag_list @all_attachments
|
||||
end
|
||||
@page = params[:page] || 1
|
||||
#render :layout => 'base_org'
|
||||
end
|
||||
|
||||
def destroy
|
||||
@subfield = OrgSubfield.find(params[:id])
|
||||
@organization = Organization.find(@subfield.organization_id)
|
||||
@subfield.destroy
|
||||
end
|
||||
|
||||
def update
|
||||
@subfield = OrgSubfield.find(params[:id])
|
||||
@organization = Organization.find(@subfield.organization_id)
|
||||
@subfield.update_attributes(:name => params[:name])
|
||||
end
|
||||
|
||||
def update_sub_dir
|
||||
@org_subfield = OrgSubfield.find(params[:id])
|
||||
sql = "select subfield_subdomain_dirs.* from subfield_subdomain_dirs, org_subfields where subfield_subdomain_dirs.org_subfield_id = org_subfields.id "+
|
||||
"and org_subfields.organization_id=#{@org_subfield.organization.id} and subfield_subdomain_dirs.name='#{params[:sub_dir_name]}'"
|
||||
if SubfieldSubdomainDir.find_by_sql(sql).count == 0
|
||||
if @org_subfield.subfield_subdomain_dir
|
||||
@sub_dir = @org_subfield.subfield_subdomain_dir
|
||||
@sub_dir.update_attribute(:name, params[:sub_dir_name])
|
||||
else
|
||||
@sub_dir = SubfieldSubdomainDir.create(:org_subfield_id => @org_subfield.id, :name => params[:sub_dir_name])
|
||||
end
|
||||
@exist = false
|
||||
else
|
||||
@exist = true
|
||||
end
|
||||
end
|
||||
|
||||
def show_attachments obj
|
||||
@attachments = []
|
||||
obj.each do |container|
|
||||
@attachments += container.attachments
|
||||
end
|
||||
@all_attachments = User.current.admin? ? @attachments : visable_attachemnts(@attachments)
|
||||
@limit = 10
|
||||
@feedback_count = @all_attachments.count
|
||||
@feedback_pages = Paginator.new @feedback_count, @limit, params['page']
|
||||
@offset ||= @feedback_pages.offset
|
||||
#@curse_attachments_all = @all_attachments[@offset, @limit]
|
||||
@obj_attachments = paginateHelper @all_attachments,10
|
||||
end
|
||||
|
||||
#获取指定资源列表的TAG的集合以及每个TAG的数量,降序排序
|
||||
def attachment_tag_list attachments
|
||||
tag_list = Hash.new
|
||||
attachments.each do |attachment|
|
||||
attachment.tag_list.map{|tag| tag_list.has_key?(tag) ? tag_list[tag] = tag_list[tag] + 1 : tag_list[tag] = 1}
|
||||
end
|
||||
tag_list.sort {|a,b| b[1]<=>a[1]}
|
||||
end
|
||||
end
|
||||
|
|
@ -1,55 +0,0 @@
|
|||
class OrganizationController < ApplicationController
|
||||
# layout 'base_projects'
|
||||
before_filter :require_admin, :except => [:index]
|
||||
|
||||
def index
|
||||
#@projects = Project.find_by_sql("SELECT * FROM projects WHERE id IN (select MAX(id) from projects GROUP BY enterprise_name)")
|
||||
@organizations = Organization.all
|
||||
respond_to do |format|
|
||||
format.html
|
||||
end
|
||||
end
|
||||
|
||||
def new
|
||||
@organizations = Organization.new
|
||||
respond_to do |format|
|
||||
format.html
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
@organizations = Organization.new
|
||||
@organizations.name = params[:organization][:name]
|
||||
if @organizations.save
|
||||
redirect_to admin_organization_url
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
@organization = Organization.find params[:id]
|
||||
respond_to do |format|
|
||||
format.html
|
||||
end
|
||||
rescue Exception => e
|
||||
render_404
|
||||
end
|
||||
|
||||
def update
|
||||
@organization = Organization.find params[:id]
|
||||
@organization.name = params[:organization][:name]
|
||||
if @organization.save
|
||||
redirect_to admin_organization_url
|
||||
end
|
||||
rescue Exception => e
|
||||
render_404
|
||||
end
|
||||
|
||||
def destroy
|
||||
@organization = Organization.find params[:id]
|
||||
if @organization.destroy
|
||||
redirect_to admin_organization_url
|
||||
end
|
||||
rescue Exception => e
|
||||
render_404
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,330 @@
|
|||
# encoding: utf-8
|
||||
class OrganizationsController < ApplicationController
|
||||
|
||||
|
||||
helper :sort
|
||||
include SortHelper
|
||||
helper :custom_fields
|
||||
include CustomFieldsHelper
|
||||
include AvatarHelper
|
||||
include WordsHelper
|
||||
include GitlabHelper
|
||||
include UserScoreHelper
|
||||
|
||||
include PollHelper
|
||||
helper :user_score
|
||||
helper :journals
|
||||
helper :attachments
|
||||
# added by liuping 关注
|
||||
|
||||
helper :watchers
|
||||
helper :activities
|
||||
|
||||
### added by william
|
||||
include ActsAsTaggableOn::TagsHelper
|
||||
|
||||
# fq
|
||||
helper :words
|
||||
helper :project_score
|
||||
helper :issues
|
||||
include UsersHelper
|
||||
before_filter :find_organization, :only => [:show, :members, :apply_subdomain]
|
||||
layout 'base_org'
|
||||
def index
|
||||
|
||||
end
|
||||
def new
|
||||
@organization = Organization.new
|
||||
render :layout => 'new_base'
|
||||
end
|
||||
|
||||
def edit
|
||||
@organization = Organization.find(params[:id])
|
||||
end
|
||||
|
||||
def destroy
|
||||
@organization = Organization.find(params[:id])
|
||||
@organization.destroy
|
||||
respond_to do |format|
|
||||
format.html{ redirect_to admin_organization_path }
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
@organization = Organization.new
|
||||
@organization.name = params[:organization][:name]
|
||||
@organization.description = params[:organization][:description]
|
||||
@organization.is_public = params[:organization][:is_public]
|
||||
@organization.allow_guest_download = params[:organization][:allow_guest_download] == '1' ? 1 : 0
|
||||
@organization.creator_id = User.current.id
|
||||
member = OrgMember.new(:user_id => User.current.id)
|
||||
|
||||
@organization.org_members << member
|
||||
if @organization.save
|
||||
OrgMemberRole.create(:org_member_id => member.id, :role_id => 11)
|
||||
redirect_to organization_path(@organization)
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
if @organization.is_public? || User.current.admin? || User.current.member_of_org?(@organization)
|
||||
@organization = Organization.find(params[:id])
|
||||
if params[:org_subfield_id]
|
||||
@org_subfield = OrgSubfield.find(params[:org_subfield_id])
|
||||
@org_subfield_ids = @org_subfield.org_document_comments.map(&:id) << 0
|
||||
@org_activities = OrgActivity.where("(org_act_type='OrgDocumentComment'and org_act_id in (#{@org_subfield_ids.join(",")})) || (container_type='OrgSubfield' and container_id=#{@org_subfield.id})").order('updated_at desc').page(params[:page] || 1).per(10)
|
||||
else
|
||||
shield_project_ids = ShieldActivity.where("container_type='Organization' and container_id=#{@organization.id} and shield_type='Project'").map(&:shield_id)
|
||||
shield_course_ids = ShieldActivity.where("container_type='Organization' and container_id=#{@organization.id} and shield_type='Course'").map(&:shield_id)
|
||||
project_ids = (@organization.projects.map(&:id)-shield_project_ids) << 0
|
||||
course_ids = (@organization.courses.map(&:id)-shield_course_ids) << 0
|
||||
course_types = "('Message','News','HomeworkCommon','Poll','Course')"
|
||||
case params[:type]
|
||||
when nil
|
||||
@org_activities = OrgActivity.where("(container_id =? and container_type =?) " +
|
||||
"or (container_type ='Project' and org_act_type in ('Issue','Message','ProjectCreateInfo') and container_id in (#{project_ids.join(',')})) "+
|
||||
"or (container_type ='Course' and org_act_type in #{course_types} and container_id in (#{course_ids.join(',')}))",
|
||||
@organization.id, 'Organization').order('updated_at desc').page(params[:page] || 1).per(10)
|
||||
when 'project_issue'
|
||||
@org_activities = OrgActivity.where("container_type = 'Project' and org_act_type = 'Issue' and container_id in (#{project_ids.join(',')})").order('updated_at desc').page(params[:page] || 1).per(10)
|
||||
when 'project_message'
|
||||
@org_activities = OrgActivity.where("container_type = 'Project' and org_act_type = 'Message' and container_id in (#{project_ids.join(',')})").order('updated_at desc').page(params[:page] || 1).per(10)
|
||||
when 'org'
|
||||
@org_activities = OrgActivity.where("container_id =? and container_type =?",@organization.id, 'Organization').order('updated_at desc').page(params[:page] || 1).per(10)
|
||||
when 'course_homework'
|
||||
@org_activities = OrgActivity.where("container_type = 'Course' and org_act_type = 'HomeworkCommon' and container_id in (#{course_ids.join(',')})").order('updated_at desc').page(params[:page] || 1).per(10)
|
||||
when 'course_news'
|
||||
@org_activities = OrgActivity.where("container_type = 'Course' and org_act_type = 'News' and container_id in (#{course_ids.join(',')})").order('updated_at desc').page(params[:page] || 1).per(10)
|
||||
when 'course_message'
|
||||
@org_activities = OrgActivity.where("container_type = 'Course' and org_act_type = 'Message' and container_id in (#{course_ids.join(',')})").order('updated_at desc').page(params[:page] || 1).per(10)
|
||||
when 'course_poll'
|
||||
@org_activities = OrgActivity.where("container_type = 'Course' and org_act_type = 'Poll' and container_id in (#{course_ids.join(',')})").order('updated_at desc').page(params[:page] || 1).per(10)
|
||||
end
|
||||
end
|
||||
@page = params[:page] ? params[:page].to_i : 1
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.js
|
||||
end
|
||||
else
|
||||
render_403
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
@organization = Organization.find(params[:id])
|
||||
@organization.name = params[:organization][:name]
|
||||
@organization.description = params[:organization][:description]
|
||||
# @organization.domain = params[:organization][:domain]
|
||||
@organization.is_public = params[:organization][:is_public] == 'on' ? 1 : 0
|
||||
@organization.allow_guest_download = params[:organization][:allow_guest_download] == 'on' ? 1 : 0
|
||||
#@organization.name = params[:organization][:name]
|
||||
@organization.save
|
||||
respond_to do |format|
|
||||
format.html { redirect_to setting_organization_path(@organization)}
|
||||
end
|
||||
end
|
||||
|
||||
def check_uniq
|
||||
@check = false;
|
||||
@org_name = params[:org_name].strip
|
||||
@config_page = params[:config_page]
|
||||
sameName = @config_page ? Organization.where('name = ? and id != ?',params[:org_name],params[:org_id].to_i).count == 0 : Organization.where('name = ?',params[:org_name]).count == 0
|
||||
if sameName == true
|
||||
@check = true
|
||||
end
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def check_uniq_domain
|
||||
@is_exist = (Organization.where("domain=?", params[:org_domain]).count > 0)
|
||||
end
|
||||
|
||||
def find_organization
|
||||
@organization = Organization.find(params[:id])
|
||||
end
|
||||
|
||||
def setting
|
||||
@organization = Organization.find(params[:id])
|
||||
|
||||
if User.current.admin? || User.current.admin_of_org?(@organization)
|
||||
else
|
||||
render_403
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def clear_org_avatar_temp
|
||||
|
||||
end
|
||||
|
||||
def set_homepage
|
||||
@org = Organization.find(params[:id])
|
||||
@org.home_id = params[:home_id]
|
||||
@org.save
|
||||
# respond_to do |format|
|
||||
# format.html {redirect_to organization_path(org)}
|
||||
# end
|
||||
end
|
||||
|
||||
def cancel_homepage
|
||||
@org = Organization.find(params[:id])
|
||||
@org.home_id = nil
|
||||
@org.save
|
||||
end
|
||||
|
||||
def autocomplete_search
|
||||
@project = Project.find(params[:project_id])
|
||||
#@flag = params[:flag] || false
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def members
|
||||
if @organization.is_public? || User.current.admin? || User.current.member_of_org?(@organization)
|
||||
@members = OrgMember.where("organization_id =?", @organization.id)
|
||||
else
|
||||
render_403
|
||||
end
|
||||
end
|
||||
|
||||
def more_org_projects
|
||||
@organization = Organization.find params[:id]
|
||||
@page = params[:page]
|
||||
@org_projects = @organization.projects.reorder('created_at').uniq.page((params[:page].to_i || 1) +1).per(5)
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def more_org_courses
|
||||
@organization = Organization.find(params[:id])
|
||||
@page = params[:page]
|
||||
@org_courses = @organization.courses.reorder('created_at').uniq.page((params[:page].to_i || 1) + 1 ).per(5)
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def join_course_menu
|
||||
@organization = Organization.find(params[:id])
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def search_courses
|
||||
@organization = Organization.find(params[:id])
|
||||
condition = '%%'
|
||||
if !params[:name].nil?
|
||||
condition = "%#{params[:name].strip}%".gsub(" ","")
|
||||
end
|
||||
sql = "select courses.* from courses inner join members on courses.id = members.course_id where members.user_id = #{User.current.id} and courses.name like '#{condition}'"+
|
||||
"and courses.id not in (select distinct org_courses.course_id from org_courses where org_courses.organization_id = #{@organization.id})"
|
||||
#user_courses = Course.find_by_sql(sql)
|
||||
@courses = Course.find_by_sql(sql)
|
||||
# @added_course_ids = @organization.courses.map(&:id)
|
||||
# @courses = []
|
||||
# user_courses.each do |course|
|
||||
# if !@added_course_ids.include?(course.id)
|
||||
# @courses << course
|
||||
# end
|
||||
# end
|
||||
end
|
||||
|
||||
def join_courses
|
||||
@organization = Organization.find(params[:id])
|
||||
course_ids = params[:courseNames]
|
||||
course_ids.each do |id|
|
||||
OrgCourse.create(:organization_id => @organization.id, :course_id => id.to_i, :created_at => Time.now)
|
||||
end
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def join_project_menu
|
||||
@organization = Organization.find(params[:id])
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def logout
|
||||
logout_user
|
||||
respond_to do |format|
|
||||
format.html {redirect_to organization_path(params[:id])}
|
||||
end
|
||||
end
|
||||
|
||||
def search_projects
|
||||
@organization = Organization.find(params[:id])
|
||||
condition = '%%'
|
||||
if !params[:name].nil?
|
||||
condition = "%#{params[:name].strip}%".gsub(" ","")
|
||||
end
|
||||
sql = "select projects.* from projects inner join members on projects.id = members.project_id where members.user_id = #{User.current.id} and projects.status != 9 and projects.name like '#{condition}'" +
|
||||
" and projects.id not in (select org_projects.project_id from org_projects where organization_id = #{@organization.id})"
|
||||
#user_projects = Course.find_by_sql(sql)
|
||||
@projects = Course.find_by_sql(sql)
|
||||
# @added_course_ids = @organization.projects.map(&:id)
|
||||
# @projects = []
|
||||
# user_projects.each do |project|
|
||||
# if !@added_course_ids.include?(project.id)
|
||||
# @projects << project
|
||||
# end
|
||||
# end
|
||||
end
|
||||
|
||||
def join_projects
|
||||
@organization = Organization.find(params[:id])
|
||||
project_ids = params[:projectNames]
|
||||
project_ids.each do |id|
|
||||
OrgProject.create(:organization_id => @organization.id, :project_id => id.to_i, :created_at => Time.now)
|
||||
end
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def hide_org_subfield
|
||||
@org_subfield = OrgSubfield.find(params[:org_subfield_id])
|
||||
@org_subfield.update_attribute(:hide, 1)
|
||||
end
|
||||
|
||||
def show_org_subfield
|
||||
@org_subfield = OrgSubfield.find(params[:org_subfield_id])
|
||||
@org_subfield.update_attribute(:hide, 0)
|
||||
end
|
||||
|
||||
def org_resources_subfield
|
||||
@org = Organization.find(params[:id])
|
||||
if params[:send_type].present? and params[:send_type] == 'news'
|
||||
@subfield = @org.org_subfields.where("field_type = 'Post'")
|
||||
else
|
||||
@subfield = @org.org_subfields.where('field_type = "Resource" ')
|
||||
end
|
||||
respond_to do | format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
def apply_subdomain
|
||||
@organization = Organization.find(params[:id])
|
||||
admins = User.where("admin=1")
|
||||
admins.each do |admin|
|
||||
OrgMessage.create(:user_id => admin.id, :organization_id => @organization.id, :message_type => 'ApplySubdomain', :message_id => @organization.id, :sender_id => User.current.id, :viewed => 0, :content => params[:domain])
|
||||
end
|
||||
end
|
||||
|
||||
def agree_apply_subdomain
|
||||
@organization = Organization.find(params[:organization_id])
|
||||
OrgMessage.find(params[:act_id]).update_attribute(:viewed, 1)
|
||||
@organization.update_attribute(:domain, params[:org_domain])
|
||||
if OrgMessage.where("message_type='AgreeApplySubdomain' and organization_id=#{@organization.id} and content=?",params[:org_domain]).count == 0
|
||||
OrgMessage.create(:user_id => params[:user_id], :organization_id => @organization.id, :message_type => 'AgreeApplySubdomain', :message_id => @organization.id, :sender_id => User.current.id, :viewed => 0, :content => params[:org_domain])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -2,6 +2,7 @@
|
|||
class PollController < ApplicationController
|
||||
before_filter :find_poll_and_course, :only => [:edit,:update,:destroy,:show,:statistics_result,:create_poll_question,:commit_poll,:commit_answer,:publish_poll,:republish_poll,:poll_result,:close_poll,:export_poll]
|
||||
before_filter :find_container, :only => [:new,:create, :index]
|
||||
before_filter :is_logged, :only => [:index, :show, :poll_result,:new,:create,:edit,:update,:destroy,:publish_poll,:republish_poll,:close_poll,:export_poll,:commit_answer,:commit_poll,:statistics_result]
|
||||
before_filter :is_member_of_course, :only => [:index,:show,:poll_result]
|
||||
before_filter :is_course_teacher, :only => [:new,:create,:edit,:update,:destroy,:publish_poll,:republish_poll,:close_poll,:export_poll]
|
||||
include PollHelper
|
||||
|
|
@ -413,7 +414,7 @@ class PollController < ApplicationController
|
|||
respond_to do |format|
|
||||
format.xls {
|
||||
send_data(poll_to_xls(poll_questions), :type => "text/excel;charset=utf-8; header=present",
|
||||
:filename => "#{@poll.polls_name}.xls")
|
||||
:filename => filename_for_content_disposition("#{@poll.polls_name}.xls") )
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
@ -503,6 +504,10 @@ class PollController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def is_logged
|
||||
redirect_to signin_path unless User.current.logged?
|
||||
end
|
||||
|
||||
def is_member_of_course
|
||||
render_403 unless(@course && (User.current.member_of_course?(@course) || User.current.admin?))
|
||||
end
|
||||
|
|
|
|||
|
|
@ -5,39 +5,73 @@ class PraiseTreadController < ApplicationController
|
|||
|
||||
def praise_plus
|
||||
@obj = nil
|
||||
# @is_in_list = nil
|
||||
@activity = false
|
||||
|
||||
if request.get?
|
||||
@obj_id = params[:obj_id]
|
||||
@obj_type = params[:obj_type]
|
||||
@horizontal = params[:horizontal].downcase == "false" ? false:true
|
||||
if !params[:user_activity_id].nil? && !params[:type].nil?
|
||||
@user_activity_id = params[:user_activity_id]
|
||||
@type = params[:type]
|
||||
@activity = true
|
||||
end
|
||||
# @is_in_list = nil
|
||||
@obj = find_object_by_type_and_id(@obj_type,@obj_id)
|
||||
unless @obj.author_id == User.current.id
|
||||
pts = PraiseTread.where("praise_tread_object_id=? and praise_tread_object_type=? and user_id=?",@obj_id,@obj_type.to_s,User.current.id)
|
||||
unless pts.empty?
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
return
|
||||
end
|
||||
@horizontal = params[:horizontal].downcase == "false" ? false:true if params[:horizontal]
|
||||
if @obj.respond_to?("author_id")
|
||||
author_id = @obj.author_id
|
||||
elsif @obj.respond_to?("user_id")
|
||||
author_id = @obj.user_id
|
||||
end
|
||||
unless author_id == User.current.id
|
||||
praise_tread_plus(@obj_type,@obj_id,1)
|
||||
end
|
||||
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def praise_minus
|
||||
@obj = nil
|
||||
@activity = false
|
||||
if request.get?
|
||||
@obj = params[:obj] # 传的是对象,最后变成id了
|
||||
|
||||
#@obj = params[:obj] # 传的是对象,最后变成id了
|
||||
#首先更新praise_tread 表 删除关注记录
|
||||
@pt = PraiseTread.find_by_user_id_and_praise_tread_object_id_and_praise_tread_object_type(User.current.id,@obj,"user")
|
||||
@pt.delete
|
||||
|
||||
#@pt = PraiseTread.find_by_user_id_and_praise_tread_object_id_and_praise_tread_object_type(User.current.id,@obj,"user")
|
||||
@obj_id = params[:obj_id]
|
||||
@obj_type = params[:obj_type]
|
||||
if !params[:user_activity_id].nil? && !params[:type].nil?
|
||||
@user_activity_id = params[:user_activity_id]
|
||||
@type = params[:type]
|
||||
@activity = true
|
||||
end
|
||||
@obj = find_object_by_type_and_id(@obj_type,@obj_id)
|
||||
@pt = PraiseTread.where("praise_tread_object_id=? and praise_tread_object_type=? and user_id=?",@obj_id,@obj_type.to_s,User.current.id).first
|
||||
if @pt.nil?
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
return
|
||||
end
|
||||
@pt.delete if !@pt.nil?
|
||||
#再更新praise_tread_cache表 使相应的记录减1 当为0时删除
|
||||
@ptc = PraiseTreadCache.find_by_object_id(@obj)
|
||||
@ptc.minus(1)
|
||||
@ptc = PraiseTreadCache.where("object_id=? and object_type=?",@obj_id,@obj_type.to_s).first
|
||||
@ptc.minus(1) if !@ptc.nil?
|
||||
if @ptc.praise_num == 0
|
||||
@ptc.delete
|
||||
@ptc.delete
|
||||
end
|
||||
|
||||
end
|
||||
@obj = User.find_by_id(@obj)
|
||||
#@obj = User.find_by_id(@obj)
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
|
@ -48,7 +82,7 @@ class PraiseTreadController < ApplicationController
|
|||
if request.get?
|
||||
@obj_id = params[:obj_id]
|
||||
@obj_type = params[:obj_type]
|
||||
@horizontal = params[:horizontal].downcase == "false" ? false:true
|
||||
#@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)
|
||||
|
|
@ -69,20 +103,36 @@ class PraiseTreadController < ApplicationController
|
|||
def find_object_by_type_and_id(type,id)
|
||||
@obj = nil
|
||||
case type
|
||||
when 'User'
|
||||
@obj = User.find_by_id(id)
|
||||
when 'Issue'
|
||||
@obj = Issue.find_by_id(id)
|
||||
when 'Project'
|
||||
@obj = Project.find_by_id(id)
|
||||
when 'Bid'
|
||||
@obj = Bid.find_by_id(id)
|
||||
when 'Contest'
|
||||
@obj = Contest.find_by_id(id)
|
||||
when 'Memo'
|
||||
@obj = Memo.find_by_id(id)
|
||||
when 'Message'
|
||||
@obj = Message.find_by_id(id)
|
||||
when 'Memo'
|
||||
@obj = Memo.find_by_id(id)
|
||||
when 'Message'
|
||||
@obj = Message.find_by_id(id)
|
||||
when 'HomeworkCommon'
|
||||
@obj = HomeworkCommon.find_by_id(id)
|
||||
when 'JournalsForMessage'
|
||||
@obj = JournalsForMessage.find_by_id(id)
|
||||
when 'News'
|
||||
@obj = News.find_by_id(id)
|
||||
when 'Comment'
|
||||
@obj = Comment.find_by_id(id)
|
||||
when 'Journal'
|
||||
@obj = Journal.find_by_id(id)
|
||||
when 'BlogComment'
|
||||
@obj = BlogComment.find_by_id(id)
|
||||
when 'OrgDocumentComment'
|
||||
@obj = OrgDocumentComment.find_by_id(id)
|
||||
when 'User'
|
||||
@obj = User.find_by_id(id)
|
||||
when 'Issue'
|
||||
@obj = Issue.find_by_id(id)
|
||||
when 'Project'
|
||||
@obj = Project.find_by_id(id)
|
||||
when 'Bid'
|
||||
@obj = Bid.find_by_id(id)
|
||||
when 'Contest'
|
||||
@obj = Contest.find_by_id(id)
|
||||
else
|
||||
@obj = nil
|
||||
end
|
||||
return @obj
|
||||
end
|
||||
|
|
@ -99,17 +149,14 @@ class PraiseTreadController < ApplicationController
|
|||
# end
|
||||
|
||||
#再创建或更新praise_tread_cache表
|
||||
@ptc = PraiseTreadCache.find_by_object_id_and_object_type(id,type)
|
||||
#@ptc = PraiseTreadCache.find_by_object_id_and_object_type(id,type)
|
||||
@ptc = PraiseTreadCache.where("object_id = ? and object_type = ?",id.to_i,type).first
|
||||
@ptc = @ptc.nil? ? PraiseTreadCache.new : @ptc
|
||||
@ptc.object_id = id.to_i
|
||||
@ptc.object_type = type
|
||||
@ptc.save
|
||||
@ptc.plus(flag,1)
|
||||
end
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -30,10 +30,10 @@ class ProjectsController < ApplicationController
|
|||
before_filter :find_project, :except => [ :index, :search,:list, :new, :create, :copy, :statistics, :new_join, :course, :enterprise_course, :course_enterprise,:view_homework_attaches,:join_project]
|
||||
before_filter :authorize, :only => [:show, :settings, :edit, :sort_project_members, :update, :modules, :close, :reopen,:view_homework_attaches,:course]
|
||||
before_filter :authorize_global, :only => [:new, :create,:view_homework_attaches]
|
||||
before_filter :require_admin, :only => [ :copy, :archive, :unarchive, :destroy, :calendar]
|
||||
before_filter :require_admin, :only => [ :copy, :unarchive, :destroy, :calendar]
|
||||
before_filter :file, :statistics #:watcherlist
|
||||
# 除非项目内人员,不可查看成员, TODO: 完了写报表里去
|
||||
before_filter :memberAccess, only: :member
|
||||
# before_filter :memberAccess, only: :member
|
||||
|
||||
# accept_rss_auth :index
|
||||
accept_api_auth :index, :show, :create, :update, :destroy
|
||||
|
|
@ -69,6 +69,32 @@ class ProjectsController < ApplicationController
|
|||
### added by william
|
||||
include ActsAsTaggableOn::TagsHelper
|
||||
|
||||
#查找组织
|
||||
def search_public_orgs_not_in_project
|
||||
condition = '%%'
|
||||
if !params[:name].nil?
|
||||
condition = "%#{params[:name].strip}%".gsub(" ","")
|
||||
end
|
||||
limit = 15
|
||||
project_org_ids = OrgProject.find_by_sql("select distinct organization_id from org_projects where project_id = #{params[:id]}").map(&:organization_id) << 0
|
||||
@orgs_not_in_project = User.current.organizations.where("organizations.id not in (#{project_org_ids.join(',')}) and organizations.name like ?", condition).page(params[:page].to_i || 1).per(limit)
|
||||
@org_count = User.current.organizations.where("organizations.id not in (#{project_org_ids.join(',')}) and organizations.name like '#{condition}'").count
|
||||
# if project_org_ids.empty?
|
||||
# @orgs_not_in_project = Organization.where("(is_public or creator_id =?) = 1 and name like ?",User.current.id, condition).page((params[:page].to_i || 1)).per(limit)
|
||||
# @org_count = Organization.where("is_public = 1 or creator_id =?", User.current.id).where("name like ?", condition).count
|
||||
# else
|
||||
# project_org_ids = "(" + project_org_ids.join(',') + ")"
|
||||
# @orgs_not_in_project = Organization.where("id not in #{project_org_ids} and (is_public = 1 or creator_id =?) and name like ?", User.current.id, condition).page((params[:page].to_i || 1)).per(limit)
|
||||
# @org_count = Organization.where("id not in #{project_org_ids} and (is_public = 1 or creator_id =?)", User.current.id).where("name like ?", condition).count
|
||||
# end
|
||||
@orgs_page = Paginator.new @org_count, limit,params[:page]
|
||||
@no_roll_hint = params[:hint_flag]
|
||||
#render :json => {:orgs => @orgs_not_in_project, :count => @org_count}.to_json
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def index
|
||||
render_404
|
||||
end
|
||||
|
|
@ -162,7 +188,7 @@ class ProjectsController < ApplicationController
|
|||
@trackers = Tracker.sorted.all
|
||||
@project = Project.new
|
||||
@project.safe_attributes = params[:project]
|
||||
render :layout => 'base'
|
||||
render :layout => 'new_base'
|
||||
else
|
||||
redirect_to signin_url
|
||||
end
|
||||
|
|
@ -177,6 +203,8 @@ class ProjectsController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
# 注意:修改该方法的时候注意同步修改forked方法
|
||||
# forked方法也会创建项目
|
||||
def create
|
||||
unless User.current.login?
|
||||
redirect_to signin_url
|
||||
|
|
@ -188,13 +216,19 @@ class ProjectsController < ApplicationController
|
|||
@project.safe_attributes = params[:project]
|
||||
@project.organization_id = params[:organization_id]
|
||||
@project.user_id = User.current.id
|
||||
@project.project_new_type = 1
|
||||
@project.project_new_type = params[:project_new_type]
|
||||
params[:project][:is_public] ? @project.is_public = 1 : @project.is_public = 0
|
||||
if validate_parent_id && @project.save
|
||||
@project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id')
|
||||
# Add current user as a project member if he is not admin
|
||||
#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])
|
||||
# project's score
|
||||
if ProjectScore.where("project_id=?", @project.id).first.nil?
|
||||
ProjectScore.create(:project_id => @project.id, :score => false)
|
||||
end
|
||||
# end
|
||||
project_info = ProjectInfo.new(:user_id => User.current.id, :project_id => @project.id)
|
||||
user_grades = UserGrade.create(:user_id => User.current.id, :project_id => @project.id)
|
||||
Rails.logger.debug "UserGrade created: #{user_grades.to_json}"
|
||||
|
|
@ -216,10 +250,11 @@ class ProjectsController < ApplicationController
|
|||
end
|
||||
}
|
||||
format.api { render :action => 'show', :status => :created, :location => url_for(:controller => 'projects', :action => 'show', :id => @project.id) }
|
||||
format.js
|
||||
end
|
||||
else
|
||||
respond_to do |format|
|
||||
format.html { render :action => 'new', :layout => 'base'}#Added by young
|
||||
format.html { render :action => 'new', :layout => 'new_base'}#Added by young
|
||||
format.api { render_validation_errors(@project) }
|
||||
end
|
||||
end
|
||||
|
|
@ -258,7 +293,8 @@ class ProjectsController < ApplicationController
|
|||
# Author lizanle
|
||||
# Description 项目动态展示方法,删除了不必要的代码
|
||||
def show
|
||||
|
||||
# 更新消息为已读
|
||||
update_message_status(User.current, @project)
|
||||
if params[:jump] && redirect_to_project_menu_item(@project, params[:jump])
|
||||
return
|
||||
end
|
||||
|
|
@ -293,9 +329,20 @@ class ProjectsController < ApplicationController
|
|||
@activity.scope_select {|t| !has["show_#{t}"].nil?}
|
||||
=end
|
||||
|
||||
@page = params[:page] ? params[:page].to_i + 1 : 0
|
||||
# 根据私密性,取出符合条件的所有数据
|
||||
if User.current.member_of?(@project) || User.current.admin?
|
||||
@events_pages = ForgeActivity.where("project_id = ? and forge_act_type != ?",@project, "Document" ).order("created_at desc").page(params['page'|| 1]).per(20);
|
||||
case params[:type]
|
||||
when nil
|
||||
@events_pages = ForgeActivity.where("project_id = ? and forge_act_type in ('Issue', 'Message','News', 'ProjectCreateInfo')",@project).order("updated_at desc").limit(10).offset(@page * 10)
|
||||
when 'issue'
|
||||
@events_pages = ForgeActivity.where("project_id = ? and forge_act_type = 'Issue'",@project).order("updated_at desc").limit(10).offset(@page * 10)
|
||||
when 'news'
|
||||
@events_pages = ForgeActivity.where("project_id = ? and forge_act_type = 'News'",@project).order("updated_at desc").limit(10).offset(@page * 10)
|
||||
when 'message'
|
||||
@events_pages = ForgeActivity.where("project_id = ? and forge_act_type = 'Message'",@project).order("updated_at desc").limit(10).offset(@page * 10)
|
||||
end
|
||||
|
||||
#events = @activity.events(@date_from, @date_to)
|
||||
else
|
||||
@events_pages = ForgeActivity.includes(:project).where("forge_activities.project_id = ? and projects.is_public
|
||||
|
|
@ -322,6 +369,12 @@ class ProjectsController < ApplicationController
|
|||
end
|
||||
|
||||
def settings
|
||||
# 修改查看消息状态
|
||||
applied_messages = ForgeMessage.where("user_id =? and project_id =? and forge_message_type =? and viewed =?", User.current.id, @project, "AppliedProject", 0)
|
||||
applied_messages.each do |applied_message|
|
||||
applied_message.update_attributes(:viewed => true)
|
||||
end
|
||||
# end
|
||||
@issue_custom_fields = IssueCustomField.sorted.all
|
||||
@issue_category ||= IssueCategory.new
|
||||
@member ||= @project.members.new
|
||||
|
|
@ -329,6 +382,15 @@ class ProjectsController < ApplicationController
|
|||
@wiki ||= @project.wiki
|
||||
@select_tab = params[:tab]
|
||||
|
||||
#找出所有不属于项目的公共组织
|
||||
project_org_ids = OrgProject.find_by_sql("select distinct organization_id from org_projects where project_id = #{@project.id}")
|
||||
if project_org_ids.empty?
|
||||
@orgs_not_in_project = Organization.where("is_public = 1")
|
||||
else
|
||||
project_org_ids = "(" + project_org_ids.join(',') + ")"
|
||||
@orgs_not_in_project = Organization.where("id not in #{project_org_ids} and is_public = 1")
|
||||
end
|
||||
|
||||
# 处理从新建版本库返回来的错误信息
|
||||
if !params[:repository_error_message].to_s.blank?
|
||||
html = ""
|
||||
|
|
@ -342,7 +404,7 @@ class ProjectsController < ApplicationController
|
|||
if params[:repository] == "pswd_is_null"
|
||||
html << l(:label_password_not_null)
|
||||
end
|
||||
flash[:error] = html if !html.to_s.blank?
|
||||
flash.now[:error] = html if !html.to_s.blank?
|
||||
end
|
||||
scm = params[:repository_scm] || (Redmine::Scm::Base.all & Setting.enabled_scm).first
|
||||
@repository = Repository.factory(scm)
|
||||
|
|
@ -351,24 +413,60 @@ class ProjectsController < ApplicationController
|
|||
|
||||
end
|
||||
|
||||
# 项目邀请用户加入实现过程
|
||||
# 两种情况:1、系统外用户;2、系统内用户 (通过邮件判定)
|
||||
def send_mail_to_member
|
||||
# 该邮箱未注册过
|
||||
if !params[:mail].blank? && User.find_by_mail(params[:mail].to_s).nil?
|
||||
email = params[:mail]
|
||||
Mailer.run.send_invite_in_project(email, @project, User.current)
|
||||
@is_zhuce = false
|
||||
flash[:notice] = l(:notice_email_sent, :value => email)
|
||||
if !User.where("login =?", params[:mail]).first.nil?
|
||||
# 用户名唯一,用户修改邮箱,未修改用户名,用户名等同邮箱的情况,默认改用户已经注册
|
||||
user = User.find_by_login(params[:mail].to_s)
|
||||
if !user.member_of?(@project)
|
||||
# 如果已经邀请过该用户,则不重复发送
|
||||
if InviteList.where("project_id =? and mail =?", @project.id, params[:mail].to_s).first.nil?
|
||||
email = params[:mail]
|
||||
Mailer.request_member_to_project(email, @project, User.current).deliver
|
||||
flash[:notice] = l(:notice_email_sent, :value => email)
|
||||
else
|
||||
flash[:error] = l(:notice_email_invited)
|
||||
end
|
||||
else
|
||||
flash[:error] = l(:label_member_of_project, :value => email)
|
||||
end
|
||||
else
|
||||
email = params[:mail]
|
||||
first_name = params[:first_name]
|
||||
last_name = params[:last_name]
|
||||
gender = params[:gender]
|
||||
Mailer.send_invite_in_project(email, @project, User.current, first_name, last_name, gender).deliver
|
||||
@is_zhuce = false
|
||||
flash[:notice] = l(:notice_email_sent, :value => email)
|
||||
end
|
||||
|
||||
# 邮箱地址已被注册
|
||||
elsif !User.find_by_mail(params[:mail].to_s).nil?
|
||||
user = User.find_by_mail(params[:mail].to_s)
|
||||
if !user.member_of?(@project)
|
||||
email = params[:mail]
|
||||
Mailer.run.request_member_to_project(email, @project, User.current)
|
||||
flash[:notice] = l(:notice_email_sent, :value => email)
|
||||
# 如果已经邀请过该用户,则不重复发送
|
||||
invite_list = InviteList.where("project_id =? and mail =?", @project.id, params[:mail].to_s).first
|
||||
if invite_list.nil?
|
||||
email = params[:mail]
|
||||
Mailer.request_member_to_project(email, @project, User.current).deliver
|
||||
flash[:notice] = l(:notice_email_sent, :value => email)
|
||||
else
|
||||
# 已经发送过了,则隔3小时才能再次发送
|
||||
if Time.now - invite_list.created_at > 10800
|
||||
email = params[:mail]
|
||||
Mailer.request_member_to_project(email, @project, User.current).deliver
|
||||
flash[:notice] = l(:notice_email_sent, :value => email)
|
||||
else
|
||||
flash[:error] = l(:notice_email_invited)
|
||||
end
|
||||
end
|
||||
else
|
||||
flash[:error] = l(:label_member_of_project, :value => email)
|
||||
end
|
||||
else
|
||||
flash[:error] = l(:notice_registed_error, :value => email)
|
||||
@is_zhuce = true
|
||||
end
|
||||
respond_to do |format|
|
||||
|
|
@ -376,25 +474,26 @@ class ProjectsController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
#发送邮件邀请新用户
|
||||
# 发送邮件邀请新用户页面对应方法
|
||||
def invite_members_by_mail
|
||||
if User.current.member_of?(@project) || User.current.admin?
|
||||
@inviter_lists = InviteList.where(project_id:@project.id).all
|
||||
@inviters = []
|
||||
@waiters = []
|
||||
unless @inviter_lists.blank?
|
||||
@inviter_lists.each do|inviter_list|
|
||||
unless inviter_list.user.nil?
|
||||
if inviter_list.user.member_of?(@project)
|
||||
@inviters << inviter_list.user
|
||||
@inviters_count = @inviters.size
|
||||
else
|
||||
@waiters << inviter_list.user
|
||||
@waiters_count = @waiters.size
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@inviter_lists = InviteList.where(project_id:@project.id).order("created_at desc")
|
||||
|
||||
# @inviters = []
|
||||
# @waiters = []
|
||||
# unless @inviter_lists.blank?
|
||||
# @inviter_lists.each do|inviter_list|
|
||||
# unless inviter_list.user.nil?
|
||||
# if inviter_list.user.member_of?(@project)
|
||||
# @inviters << inviter_list.user
|
||||
# @inviters_count = @inviters.size
|
||||
# else
|
||||
# @waiters << inviter_list.user
|
||||
# @waiters_count = @waiters.size
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
@is_zhuce = false
|
||||
respond_to do |format|
|
||||
format.html
|
||||
|
|
@ -406,23 +505,36 @@ class ProjectsController < ApplicationController
|
|||
end
|
||||
|
||||
# 邀请Trustie注册用户
|
||||
def invite_members
|
||||
if User.current.member_of?(@project) || User.current.admin?
|
||||
@member ||= @project.members.new
|
||||
respond_to do |format|
|
||||
format.html
|
||||
end
|
||||
else
|
||||
render_403
|
||||
end
|
||||
end
|
||||
# def invite_members
|
||||
# if User.current.member_of?(@project) || User.current.admin?
|
||||
# @member ||= @project.members.new
|
||||
# respond_to do |format|
|
||||
# format.html
|
||||
# end
|
||||
# else
|
||||
# render_403
|
||||
# end
|
||||
# end
|
||||
|
||||
def edit
|
||||
end
|
||||
|
||||
def set_public_or_private
|
||||
@project = Project.find(params[:id])
|
||||
if @project.is_public?
|
||||
@project.update_attribute(:is_public, 0)
|
||||
else
|
||||
@project.update_attribute(:is_public, 1)
|
||||
end
|
||||
end
|
||||
# by young
|
||||
# include CoursesHelper
|
||||
def member
|
||||
# 消息"同意加入项目"
|
||||
if params[:message_id]
|
||||
message_invite(params[:message_id], params[:key])
|
||||
end
|
||||
update_message_status(User.current, @project)
|
||||
# params[:login]为邮箱邀请用户加入,主要功能:
|
||||
# 1、自动注册
|
||||
# 2、加入项目、创建角色
|
||||
|
|
@ -444,6 +556,10 @@ class ProjectsController < ApplicationController
|
|||
flash[:notice] = l(:label_mail_invite_success)
|
||||
end
|
||||
end
|
||||
# 私有项目非项目成员无法访问成员列表
|
||||
unless @project.is_public?
|
||||
return render_403 unless User.current.member_of?(@project)
|
||||
end
|
||||
## 有角色参数的才是课程,没有的就是项目
|
||||
@render_file = 'project_member_list'
|
||||
# 判断是否课程
|
||||
|
|
@ -474,6 +590,32 @@ class ProjectsController < ApplicationController
|
|||
@members = paginateHelper @members
|
||||
end
|
||||
|
||||
def update_message_status(user, project)
|
||||
project_invite_messages = ForgeMessage.where("user_id =? and project_id =? and forge_message_type =?", user, project, "ProjectInvite")
|
||||
project_invite_messages.each do |project_invite_message|
|
||||
project_invite_message.update_attribute(:viewed, true)
|
||||
end
|
||||
#更新被加入项目消息的viewed字段
|
||||
join_project_messages = ForgeMessage.where("user_id =? and project_id =? and forge_message_type=?", user, project, "JoinProject")
|
||||
join_project_messages.each do |join_project|
|
||||
join_project.update_attribute(:viewed, true)
|
||||
end
|
||||
#更新被移出项目消息的viewed字段
|
||||
remove_project_messages = ForgeMessage.where("user_id =? and project_id =? and forge_message_type=?", user, project, "RemoveFromProject")
|
||||
remove_project_messages.update_all(:viewed => true)
|
||||
end
|
||||
|
||||
def message_invite(message_id, key)
|
||||
forge_message = ForgeMessage.find(message_id)
|
||||
if key == forge_message.secret_key
|
||||
# 情况:用户收到邀请邮件还没看,但是管理员已经把该用户添加进项目
|
||||
if Member.where("user_id =? and project_id =?",forge_message.user_id, forge_message.project_id).first.nil?
|
||||
Member.create(:role_ids => [4], :user_id => forge_message.user_id, :project_id => forge_message.project_id)
|
||||
UserGrade.create(:user_id => forge_message.user_id, :project_id => forge_message.project_id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#判断指定用户是否为课程教师
|
||||
def isCourseTeacher(id)
|
||||
result = false
|
||||
|
|
@ -526,6 +668,13 @@ class ProjectsController < ApplicationController
|
|||
@project.organization_id = params[:organization_id]
|
||||
params[:project][:is_public] ? @project.is_public = 1 : @project.is_public = 0
|
||||
params[:project][:hidden_repo] ? @project.hidden_repo = 1 : @project.hidden_repo = 0
|
||||
# 更新公开私有时同步gitlab公开私有
|
||||
unless @project.gpid.nil?
|
||||
g = Gitlab.client
|
||||
gproject = g.project(@project.gpid)
|
||||
params[:project][:is_public] ? g.edit_project(gproject.id, 20) : g.edit_project(gproject.id, 0)
|
||||
end
|
||||
# end
|
||||
if validate_parent_id && @project.save
|
||||
@project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id')
|
||||
if params[:project][:is_public] == '0'
|
||||
|
|
@ -565,7 +714,11 @@ class ProjectsController < ApplicationController
|
|||
flash[:error] = l(:error_can_not_archive_project)
|
||||
end
|
||||
end
|
||||
redirect_to admin_projects_url(:status => params[:status])
|
||||
if params[:type] == "project"
|
||||
redirect_to user_path(User.current)
|
||||
else
|
||||
redirect_to admin_projects_url(:status => params[:status])
|
||||
end
|
||||
end
|
||||
|
||||
def unarchive
|
||||
|
|
@ -586,14 +739,10 @@ class ProjectsController < ApplicationController
|
|||
# Delete @project
|
||||
def destroy
|
||||
@project_to_destroy = @project
|
||||
if api_request? || params[:confirm]
|
||||
@project_to_destroy.destroy
|
||||
respond_to do |format|
|
||||
format.html { redirect_to admin_projects_url }
|
||||
format.api { render_api_ok }
|
||||
end
|
||||
else
|
||||
render :layout => "base_projects"
|
||||
@project_to_destroy.destroy
|
||||
respond_to do |format|
|
||||
format.html { redirect_to admin_projects_url }
|
||||
format.api { render_api_ok }
|
||||
end
|
||||
# hide project in layout
|
||||
@project = nil
|
||||
|
|
@ -749,5 +898,4 @@ class ProjectsController < ApplicationController
|
|||
end
|
||||
#gcmend
|
||||
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -29,12 +29,12 @@ class RepositoriesController < ApplicationController
|
|||
menu_item :repository
|
||||
menu_item :settings, :only => [:new, :create, :edit, :update, :destroy, :committers]
|
||||
default_search_scope :changesets
|
||||
|
||||
|
||||
before_filter :find_project_by_project_id, :only => [:new, :create, :newrepo]
|
||||
before_filter :find_repository, :only => [:edit, :update, :destroy, :committers]
|
||||
before_filter :find_project_repository, :except => [:new, :create, :newcreate, :edit, :update, :destroy, :committers, :newrepo]
|
||||
before_filter :find_project_repository, :except => [:new, :create, :newcreate, :edit, :update, :destroy, :committers, :newrepo, :to_gitlab, :forked]
|
||||
before_filter :find_changeset, :only => [:revision, :add_related_issue, :remove_related_issue]
|
||||
before_filter :authorize , :except => [:newrepo,:newcreate,:fork]
|
||||
before_filter :authorize , :except => [:newrepo,:newcreate,:fork, :to_gitlab, :forked]
|
||||
accept_rss_auth :revisions
|
||||
# hidden repositories filter // 隐藏代码过滤器
|
||||
before_filter :check_hidden_repo, :only => [:show, :stats, :revisions, :revision, :diff ]
|
||||
|
|
@ -42,23 +42,132 @@ class RepositoriesController < ApplicationController
|
|||
include RepositoriesHelper
|
||||
helper :project_score
|
||||
#@root_path = RepositoriesHelper::ROOT_PATH
|
||||
|
||||
$g=Gitlab.client
|
||||
|
||||
rescue_from Redmine::Scm::Adapters::CommandFailed, :with => :show_error_command_failed
|
||||
def new
|
||||
scm = params[:repository_scm] || (Redmine::Scm::Base.all & Setting.enabled_scm).first
|
||||
@repository = Repository.factory(scm)
|
||||
@repository.is_default = @project.repository.nil?
|
||||
@repository.project = @project
|
||||
@course_tag = params[:course]
|
||||
if @course_tag == 1
|
||||
render :layout => 'base_courses'
|
||||
if @project.repositories.count == 0
|
||||
scm = params[:repository_scm] || (Redmine::Scm::Base.all & Setting.enabled_scm).first
|
||||
@repository = Repository.factory(scm)
|
||||
@repository.is_default = @project.repository.nil?
|
||||
@repository.project = @project
|
||||
@course_tag = params[:course]
|
||||
if @course_tag == 1
|
||||
render :layout => 'base_courses'
|
||||
else
|
||||
render :layout => 'base_projects'
|
||||
end
|
||||
else
|
||||
render :layout => 'base_projects'
|
||||
render_403
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def forked
|
||||
@project = Project.find(params[:id])
|
||||
@repository = Repository.where("project_id =? and type =?", @project.id, "Repository::Gitlab")
|
||||
# 如果当前用户已经fork过该项目,不会新fork项目,则跳至已fork的项
|
||||
unless has_forked?(@project, User.current)
|
||||
project = project_from_current_project(@project.id, User.current.id)
|
||||
redirect_to project_path(project)
|
||||
else
|
||||
# 自己不能fork自己的项目
|
||||
if User.current.id == @project.user_id
|
||||
flash[:notice] = l(:project_gitlab_fork_own)
|
||||
redirect_to repository_url(@repository)
|
||||
else
|
||||
g = Gitlab.client
|
||||
if User.current.gid.nil?
|
||||
begin
|
||||
g.sync_user(User.current)
|
||||
ensure
|
||||
logger.error "Synv user failed ==>#{User.current.id}"
|
||||
end
|
||||
end
|
||||
gproject = g.fork(@project.gpid, User.current.gid)
|
||||
if gproject
|
||||
copy_project(@project, gproject)
|
||||
forked_count = @project.forked_count.to_i + 1
|
||||
@project.update_attributes(:forked_count => forked_count)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# 判断用户是否已经fork过该项目
|
||||
def has_forked?(project, user)
|
||||
projects = Project.where("user_id =?", user)
|
||||
projects.map(&:forked_from_project_id).detect{|s| s == @project.id}.nil? ? true : false
|
||||
end
|
||||
|
||||
# 获取当前用户fork过的项目
|
||||
def project_from_current_project(project, user)
|
||||
project = Project.where("user_id =? and forked_from_project_id =?",user, project).first
|
||||
end
|
||||
|
||||
# copy a project for fork
|
||||
def copy_project(tproject, gproject)
|
||||
project = Project.new
|
||||
project.name = tproject.name
|
||||
project.is_public = tproject.is_public
|
||||
project.status = tproject.status
|
||||
project.description = tproject.description
|
||||
project.hidden_repo = tproject.hidden_repo
|
||||
project.user_id = User.current.id
|
||||
project.project_type = 0
|
||||
project.project_new_type = tproject.project_new_type
|
||||
project.gpid = gproject.id
|
||||
project.forked_from_project_id = tproject.id
|
||||
if project.save
|
||||
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])
|
||||
if ProjectScore.where("project_id=?", project.id).first.nil?
|
||||
ProjectScore.create(:project_id => project.id, :score => false)
|
||||
end
|
||||
project_info = ProjectInfo.new(:user_id => User.current.id, :project_id => project.id)
|
||||
user_grades = UserGrade.create(:user_id => User.current.id, :project_id => project.id)
|
||||
Rails.logger.debug "UserGrade created: #{user_grades.to_json}"
|
||||
project_status = ProjectStatus.create(:project_id => @project.id, :watchers_count => 0, :changesets_count => 0, :project_type => @project.project_type,:grade => 0)
|
||||
Rails.logger.debug "ProjectStatus created: #{project_status.to_json}"
|
||||
project.members << m
|
||||
project.project_infos << project_info
|
||||
copy_repository(project, gproject)
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
flash[:notice] = l(:notice_successful_create)
|
||||
if params[:continue]
|
||||
attrs = {:parent_id => project.parent_id}.reject {|k,v| v.nil?}
|
||||
redirect_to new_project_url(attrs, :course => '0')
|
||||
else
|
||||
redirect_to settings_project_url(project)
|
||||
end
|
||||
}
|
||||
format.api { render :action => 'show', :status => :created, :location => url_for(:controller => 'projects', :action => 'show', :id => project.id) }
|
||||
format.js
|
||||
end
|
||||
else
|
||||
respond_to do |format|
|
||||
format.html { render :action => 'forked', :layout => 'base_projects'}
|
||||
format.api { render_validation_errors(@project) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
def copy_repository(project, gproject)
|
||||
# 避免
|
||||
# if is_sigle_identifier?(project.user_id, gproject.name)
|
||||
repository = Repository.factory('Git')
|
||||
repository.project_id = project.id
|
||||
repository.type = 'Repository::Gitlab'
|
||||
repository.url = gproject.name
|
||||
repository.identifier = gproject.name
|
||||
repository = repository.save
|
||||
# else
|
||||
# flash[:notice] = l(:project_gitlab_create_double_message)
|
||||
# end
|
||||
end
|
||||
|
||||
def newrepo
|
||||
scm = params[:repository_scm] || (Redmine::Scm::Base.all & Setting.enabled_scm).first
|
||||
@repository = Repository.factory(scm)
|
||||
|
|
@ -71,23 +180,23 @@ class RepositoriesController < ApplicationController
|
|||
render :layout => 'base_projects'
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def fork
|
||||
@repository_url = params[:repository_url]
|
||||
|
||||
|
||||
# @repository.url
|
||||
# system "htpasswd -mb "+@root_path+"user.passwd "+params[:repository][:identifier]+" "+@upasswd
|
||||
# system "echo -e '"+params[:project_id]+"-"+params[:repository][:identifier]+"-write:"+
|
||||
# " "+params[:repository][:identifier]+"' >> "+@root_path+"group.passwd"
|
||||
system "git clone --bare "+@repository_url
|
||||
# " "+params[:repository][:identifier]+"' >> "+@root_path+"group.passwd"
|
||||
system "git clone --bare "+@repository_url
|
||||
# system "mv "+@project_path+"/hooks/post-update{.sample,}"
|
||||
# system "chmod a+x "+@project_path+"/hooks/post-update"
|
||||
# system "."+@project_path+"/hooks/post-update"
|
||||
# system "echo -e 'Allow from all \n Order Deny,Allow \n "+
|
||||
# "<Limit PUT POST DELETE PROPPATCH MKCOL COPY MOVE LOCK UNLOCK> \n"+
|
||||
# "Require group "+params[:project_id]+"-"+params[:repository][:identifier]+"-write \n "+
|
||||
# "</Limit> \n ' >>"+
|
||||
# @project_path+"/.htaccess"
|
||||
# "<Limit PUT POST DELETE PROPPATCH MKCOL COPY MOVE LOCK UNLOCK> \n"+
|
||||
# "Require group "+params[:project_id]+"-"+params[:repository][:identifier]+"-write \n "+
|
||||
# "</Limit> \n ' >>"+
|
||||
# @project_path+"/.htaccess"
|
||||
flash[:notice] = l(:label_notice_fork_successed)
|
||||
@repositories = @project.repositories
|
||||
render :action => 'show', :layout => 'base_projects'
|
||||
|
|
@ -110,9 +219,11 @@ update
|
|||
}
|
||||
|
||||
def create
|
||||
if params[:repository_scm].to_s == 'Gitlab'
|
||||
# add by nwb
|
||||
# 增加对gitlab版本库的支持
|
||||
# 判断版本库创建者是否有同名版本库,避免版本库路径一致问题
|
||||
unless is_sigle_identifier?(@project.user_id, params[:repository].first[1])
|
||||
flash[:notice] = l(:project_gitlab_create_double_message)
|
||||
redirect_to settings_project_url(@project, :tab => 'repositories')
|
||||
else
|
||||
attrs = pickup_extra_info
|
||||
@repository = Repository.factory('Git')
|
||||
@repository.safe_attributes = params[:repository]
|
||||
|
|
@ -120,67 +231,18 @@ update
|
|||
@repository.merge_extra_info(attrs[:attrs_extra])
|
||||
end
|
||||
@repository.project = @project
|
||||
@repository.type = 'Repository::Gitlab'
|
||||
@repository.url = @repository.identifier
|
||||
if request.post? && @repository.save
|
||||
s = Trustie::Gitlab::Sync.new
|
||||
s.create_project(@project, @repository)
|
||||
redirect_to settings_project_url(@project, :tab => 'repositories')
|
||||
else
|
||||
redirect_to settings_project_url(@project, :tab => 'repositories')
|
||||
end
|
||||
else # 原逻辑
|
||||
##xianbo
|
||||
@root_path=RepositoriesHelper::ROOT_PATH
|
||||
@repository_name=User.current.login.to_s+"/"+params[:repository][:identifier]+".git"
|
||||
@project_path=@root_path+"htdocs/"+@repository_name
|
||||
@repository_tag=params[:repository][:upassword] || params[:repository][:password]
|
||||
@repo_name=User.current.login.to_s+"_"+params[:repository][:identifier]
|
||||
logger.info "htpasswd -mb "+@root_path+"htdocs/user.passwd "+@repo_name+": "+@repository_tag
|
||||
logger.info "the value of create repository"+@root_path+": "+@repository_name+": "+@project_path+": "+@repo_name
|
||||
attrs = pickup_extra_info
|
||||
if((@repository_tag!="")&¶ms[:repository_scm]=="Git")
|
||||
params[:repository][:url]=@project_path
|
||||
end
|
||||
###xianbo
|
||||
@repository = Repository.factory(params[:repository_scm])
|
||||
@repository.safe_attributes = params[:repository]
|
||||
if attrs[:attrs_extra].keys.any?
|
||||
@repository.merge_extra_info(attrs[:attrs_extra])
|
||||
end
|
||||
|
||||
@repository.project = @project
|
||||
if request.post? && @repository.save
|
||||
if(params[:repository_scm]=="Git")
|
||||
system "htpasswd -mb "+@root_path+"htdocs/user.passwd "+@repo_name+" "+@repository_tag
|
||||
system "echo -e '"+@repo_name+"-write:"+
|
||||
" "+@repo_name+"' >> "+@root_path+"htdocs/group.passwd"
|
||||
system "mkdir "+@root_path+"htdocs/"+User.current.login.to_s
|
||||
system "git init --bare "+@project_path
|
||||
system "mv "+@project_path+"/hooks/post-update{.sample,}"
|
||||
system "chmod a+x "+@project_path+"/hooks/post-update"
|
||||
system "echo -e 'Allow from all \n Order Deny,Allow \n "+
|
||||
"<Limit PUT POST DELETE PROPPATCH MKCOL COPY MOVE LOCK UNLOCK> \n"+
|
||||
"Require group "+@repo_name+"-write \n "+
|
||||
"</Limit> \n ' >> "+
|
||||
@root_path+"htdocs/"+ @repository_name+"/.htaccess"
|
||||
system "cd "+@project_path+" ;git update-server-info"
|
||||
|
||||
File.open(@project_path+"/hooks/post-update", "w+") do |f|
|
||||
f.write(HOOK_TEMPLATE)
|
||||
end
|
||||
|
||||
@repository.update_attributes(:login => User.current.login.to_s)
|
||||
end
|
||||
redirect_to settings_project_url(@project, :tab => 'repositories',:repository_error_message=>@repository.errors.full_messages)
|
||||
else if(@repository_tag.blank?)
|
||||
#render :action => 'newrepo', :layout =>'base_projects'
|
||||
redirect_to settings_project_url(@project, :tab => 'repositories',:repository => "pswd_is_null",:repository_error_message=>@repository.errors.full_messages)
|
||||
else
|
||||
redirect_to settings_project_url(@project, :tab => 'repositories',:repository => @repository,:repository_error_message=>@repository.errors.full_messages)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def edit
|
||||
end
|
||||
|
||||
|
|
@ -223,15 +285,17 @@ update
|
|||
# Build a hash with repository usernames as keys and corresponding user ids as values
|
||||
@repository.committer_ids = params[:committers].values.inject({}) {|h, c| h[c.first] = c.last; h}
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
redirect_to settings_project_url(@project, :tab => 'repositories')
|
||||
respond_to do |format|
|
||||
format.html{
|
||||
render :layout => "base_projects"
|
||||
}
|
||||
end
|
||||
elsif request.get?
|
||||
respond_to do |format|
|
||||
format.html{
|
||||
render :layout => "base_projects"
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
respond_to do |format|
|
||||
format.html{
|
||||
render :layout => "base_projects"
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -242,6 +306,16 @@ update
|
|||
redirect_to settings_project_url(@project, :tab => 'repositories')
|
||||
end
|
||||
|
||||
def to_gitlab
|
||||
@project = Project.find(params[:project_id])
|
||||
@repository = Repository.find(params[:id])
|
||||
s = Trustie::Gitlab::Sync.new
|
||||
s.sync_project(@project, path: params[:repo_name], import_url: @repository.url)
|
||||
@repository.type = 'Repository::Gitlab'
|
||||
@repository.save
|
||||
redirect_to :controller => 'repositories', :action => 'show', :id => @project.id, to: 'gitlab'
|
||||
end
|
||||
|
||||
def show
|
||||
## TODO: the below will move to filter, done.
|
||||
if !User.current.member_of?(@project)
|
||||
|
|
@ -251,19 +325,19 @@ update
|
|||
end
|
||||
end
|
||||
|
||||
if params[:to] == 'gitlab'
|
||||
g = Gitlab.client
|
||||
g.post('/session', body: {email: User.current.mail, password: User.current.hashed_password})
|
||||
redirect_to "http://192.168.41.130:3000/gitlab-org/gitlab-shell/tree/master"
|
||||
return
|
||||
end
|
||||
# unless @repository.gitlab?
|
||||
# # redirect_to to_gitlab_project_repository_path(@project, @repository)
|
||||
# render :to_gitlab
|
||||
# return
|
||||
# end
|
||||
|
||||
#if( !User.current.member_of?(@project) || @project.hidden_repo)
|
||||
@repository.fetch_changesets if Setting.autofetch_changesets? && @path.empty?
|
||||
|
||||
# :name, :path, :kind, :size, :lastrev, :changeset
|
||||
@entries = @repository.entries(@path, @rev)
|
||||
# @trees = g.trees(project, @path)
|
||||
@changeset = @repository.find_changeset_by_name(@rev)
|
||||
|
||||
#@project_path_cut = RepositoriesHelper::PROJECT_PATH_CUT
|
||||
#@ip = RepositoriesHelper::REPO_IP_ADDRESS
|
||||
|
||||
|
|
@ -271,15 +345,35 @@ update
|
|||
@entries ? render(:partial => 'dir_list_content') : render(:nothing => true)
|
||||
else
|
||||
#Modified by young
|
||||
# (show_error_not_found; return) unless @entries
|
||||
@changesets = @repository.latest_changesets(@path, @rev)
|
||||
# (show_error_not_found; return) unless @entries
|
||||
g = Gitlab.client
|
||||
@changesets = g.commits(@project.gpid, :ref_name => @rev)
|
||||
# @changesets = @repository.latest_changesets(@path, @rev)
|
||||
# @changesets_count = @repository.latest_changesets(@path, @rev).count
|
||||
@changesets_all_count = @project.gpid.nil? ? 0 : g.project(@project.gpid).commit_count
|
||||
# 访问该页面的是会后则刷新
|
||||
if @project.project_score.nil?
|
||||
ProjectScore.create(:project_id => @project.id, :score => false)
|
||||
end
|
||||
if @changesets_all_count != @project.project_score.changeset_num && @changesets_all_count != 0
|
||||
update_commits_count(@project, @changesets_all_count)
|
||||
end
|
||||
# end
|
||||
@changesets_latest_coimmit = @changesets[0]
|
||||
unless @changesets[0].blank?
|
||||
update_commits_date(@project, @changesets_latest_coimmit)
|
||||
end
|
||||
@properties = @repository.properties(@path, @rev)
|
||||
@repositories = @project.repositories
|
||||
@course_tag = params[:course]
|
||||
project_path_cut = RepositoriesHelper::PROJECT_PATH_CUT
|
||||
ip = RepositoriesHelper::REPO_IP_ADDRESS
|
||||
@repos_url = "http://"+@repository.login.to_s+"_"+@repository.identifier.to_s+"@"+ip.to_s+
|
||||
@repository.url.slice(project_path_cut, @repository.url.length).to_s
|
||||
gitlab_address = Redmine::Configuration['gitlab_address']
|
||||
if @repository.type.to_s == "Repository::Gitlab"
|
||||
@repos_url = gitlab_address.to_s+"/"+@project.owner.to_s+"/"+@repository.identifier+"."+"git"
|
||||
else
|
||||
@repos_url = "http://"+@repository.login.to_s+"_"+@repository.identifier.to_s+"@"+ip.to_s + @repository.url.slice(project_path_cut, @repository.url.length).to_s
|
||||
end
|
||||
if @course_tag == 1
|
||||
render :action => 'show', :layout => 'base_courses'
|
||||
else
|
||||
|
|
@ -293,22 +387,37 @@ update
|
|||
def changes
|
||||
@entry = @repository.entry(@path, @rev)
|
||||
(show_error_not_found; return) unless @entry
|
||||
@changesets = @repository.latest_changesets(@path, @rev, Setting.repository_log_display_limit.to_i)
|
||||
g = Gitlab.client
|
||||
limit = 20
|
||||
#每次页面的换回值从1开始,但是gitlab的页面查询是从0开始,所以先改变page的类型减一在改回来
|
||||
@commits = g.commits(@project.gpid, page:(params[:page].to_i - 1).to_s)
|
||||
|
||||
#add by hx
|
||||
#rep_count = commit_count(@project)
|
||||
|
||||
#页面传递必须要str类型,但是Paginator的初始化必须要num类型,需要类型转化
|
||||
@commits_count = params[:commit_count].to_i
|
||||
@commits_pages = Redmine::Pagination::Paginator.new @commits_count,limit,params[:page]
|
||||
|
||||
@commit = g.commit(@project.gpid,@rev)
|
||||
# @changesets = g.get ("/projects/#{@project.gpid}/repository/commits?#{@rev}")
|
||||
#@changesets = @repository.latest_changesets(@path, @rev, Setting.repository_log_display_limit.to_i)
|
||||
@properties = @repository.properties(@path, @rev)
|
||||
@changeset = @repository.find_changeset_by_name(@rev)
|
||||
render :layout => 'base_projects'
|
||||
end
|
||||
|
||||
|
||||
def revisions
|
||||
@changeset_count = @repository.changesets.count
|
||||
@changeset_pages = Paginator.new @changeset_count,
|
||||
per_page_option,
|
||||
params['page']
|
||||
@changesets = @repository.changesets.
|
||||
limit(@changeset_pages.per_page).
|
||||
offset(@changeset_pages.offset).
|
||||
includes(:user, :repository, :parents).
|
||||
all
|
||||
limit(@changeset_pages.per_page).
|
||||
offset(@changeset_pages.offset).
|
||||
includes(:user, :repository, :parents).
|
||||
all
|
||||
|
||||
respond_to do |format|
|
||||
format.html { render :layout => 'base_projects' }
|
||||
|
|
@ -322,6 +431,7 @@ update
|
|||
|
||||
def entry
|
||||
entry_and_raw(false)
|
||||
render :layout => 'base_projects'
|
||||
end
|
||||
|
||||
def entry_and_raw(is_raw)
|
||||
|
|
@ -334,8 +444,8 @@ update
|
|||
@content = @repository.cat(@path, @rev)
|
||||
(show_error_not_found; return) unless @content
|
||||
if is_raw ||
|
||||
(@content.size && @content.size > Setting.file_max_size_displayed.to_i.kilobyte) ||
|
||||
! is_entry_text_data?(@content, @path)
|
||||
(@content.size && @content.size > Setting.file_max_size_displayed.to_i.kilobyte) ||
|
||||
! is_entry_text_data?(@content, @path)
|
||||
# Force the download
|
||||
send_opt = { :filename => filename_for_content_disposition(@path.split('/').last) }
|
||||
send_type = Redmine::MimeType.of(@path)
|
||||
|
|
@ -418,8 +528,8 @@ update
|
|||
filename = "changeset_r#{@rev}"
|
||||
filename << "_r#{@rev_to}" if @rev_to
|
||||
send_data @diff.join, :filename => "#{filename}.diff",
|
||||
:type => 'text/x-patch',
|
||||
:disposition => 'attachment'
|
||||
:type => 'text/x-patch',
|
||||
:disposition => 'attachment'
|
||||
else
|
||||
@diff_type = params[:type] || User.current.pref[:diff_type] || 'inline'
|
||||
@diff_type = 'inline' unless %w(inline sbs).include?(@diff_type)
|
||||
|
|
@ -430,7 +540,7 @@ update
|
|||
User.current.preference.save
|
||||
end
|
||||
@cache_key = "repositories/diff/#{@repository.id}/" +
|
||||
Digest::MD5.hexdigest("#{@path}-#{@rev}-#{@rev_to}-#{@diff_type}-#{current_language}")
|
||||
Digest::MD5.hexdigest("#{@path}-#{@rev}-#{@rev_to}-#{@diff_type}-#{current_language}")
|
||||
unless read_fragment(@cache_key)
|
||||
@diff = @repository.diff(@path, @rev, @rev_to)
|
||||
unless @diff
|
||||
|
|
@ -457,16 +567,16 @@ update
|
|||
def graph
|
||||
data = nil
|
||||
case params[:graph]
|
||||
when "commits_per_month"
|
||||
data = graph_commits_per_month(@repository)
|
||||
when "commits_per_author"
|
||||
data = graph_commits_per_author(@repository)
|
||||
when "author_commits_per_month"
|
||||
data = graph_author_commits_per_month(@repository)
|
||||
when "author_commits_six_month"
|
||||
data = author_commits_six_month(@repository)
|
||||
when "author_code_six_months"
|
||||
data = author_code_six_month(@repository)
|
||||
when "commits_per_month"
|
||||
data = graph_commits_per_month(@repository)
|
||||
when "commits_per_author"
|
||||
data = graph_commits_per_author(@repository)
|
||||
when "author_commits_per_month"
|
||||
data = graph_author_commits_per_month(@repository)
|
||||
when "author_commits_six_month"
|
||||
data = author_commits_six_month(@repository)
|
||||
when "author_code_six_months"
|
||||
data = author_code_six_month(@repository)
|
||||
end
|
||||
if data
|
||||
headers["Content-Type"] = "image/svg+xml"
|
||||
|
|
@ -477,12 +587,21 @@ update
|
|||
end
|
||||
|
||||
private
|
||||
# 更新项目统计数
|
||||
def update_commits_count project, count
|
||||
project.project_score.update_attribute(:changeset_num, count)
|
||||
end
|
||||
|
||||
# 更新项目提交次数时间
|
||||
def update_commits_date project, date
|
||||
project.project_score.update_attribute(:commit_time, date.created_at)
|
||||
end
|
||||
|
||||
def find_repository
|
||||
@repository = Repository.find(params[:id])
|
||||
@project = @repository.project
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
REV_PARAM_RE = %r{\A[a-f0-9]*\Z}i
|
||||
|
|
@ -546,14 +665,14 @@ update
|
|||
@date_from = @date_to << 11
|
||||
@date_from = Date.civil(@date_from.year, @date_from.month, 1)
|
||||
commits_by_day = Changeset.count(
|
||||
:all, :group => :commit_date,
|
||||
:conditions => ["repository_id = ? AND commit_date BETWEEN ? AND ?", repository.id, @date_from, @date_to])
|
||||
:all, :group => :commit_date,
|
||||
:conditions => ["repository_id = ? AND commit_date BETWEEN ? AND ?", repository.id, @date_from, @date_to])
|
||||
commits_by_month = [0] * 12
|
||||
commits_by_day.each {|c| commits_by_month[(@date_to.month - c.first.to_date.month) % 12] += c.last }
|
||||
|
||||
changes_by_day = Change.count(
|
||||
:all, :group => :commit_date, :include => :changeset,
|
||||
:conditions => ["#{Changeset.table_name}.repository_id = ? AND #{Changeset.table_name}.commit_date BETWEEN ? AND ?", repository.id, @date_from, @date_to])
|
||||
:all, :group => :commit_date, :include => :changeset,
|
||||
:conditions => ["#{Changeset.table_name}.repository_id = ? AND #{Changeset.table_name}.commit_date BETWEEN ? AND ?", repository.id, @date_from, @date_to])
|
||||
changes_by_month = [0] * 12
|
||||
changes_by_day.each {|c| changes_by_month[(@date_to.month - c.first.to_date.month) % 12] += c.last }
|
||||
|
||||
|
|
@ -561,26 +680,26 @@ update
|
|||
12.times {|m| fields << month_name(((Date.today.month - 1 - m) % 12) + 1)}
|
||||
|
||||
graph = SVG::Graph::Bar.new(
|
||||
:height => 300,
|
||||
:width => 600,
|
||||
:fields => fields.reverse,
|
||||
:stack => :side,
|
||||
:scale_integers => true,
|
||||
:step_x_labels => 2,
|
||||
:show_data_values => true,
|
||||
:graph_title => l(:label_commits_per_month),
|
||||
:show_graph_title => true
|
||||
:height => 300,
|
||||
:width => 600,
|
||||
:fields => fields.reverse,
|
||||
:stack => :side,
|
||||
:scale_integers => true,
|
||||
:step_x_labels => 2,
|
||||
:show_data_values => true,
|
||||
:graph_title => l(:label_commits_per_month),
|
||||
:show_graph_title => true
|
||||
)
|
||||
|
||||
# 具状图
|
||||
graph.add_data(
|
||||
:data => commits_by_month[0..11].reverse,
|
||||
:title => l(:label_revision_plural)
|
||||
:data => commits_by_month[0..11].reverse,
|
||||
:title => l(:label_revision_plural)
|
||||
)
|
||||
|
||||
graph.add_data(
|
||||
:data => changes_by_month[0..11].reverse,
|
||||
:title => l(:label_change_plural)
|
||||
:data => changes_by_month[0..11].reverse,
|
||||
:title => l(:label_change_plural)
|
||||
)
|
||||
|
||||
graph.burn
|
||||
|
|
@ -605,23 +724,23 @@ update
|
|||
fields = fields.collect {|c| c.gsub(%r{<.+@.+>}, '') }
|
||||
|
||||
graph = SVG::Graph::BarHorizontal.new(
|
||||
:height => 400,
|
||||
:width => 600,
|
||||
:fields => fields,
|
||||
:stack => :side,
|
||||
:scale_integers => true,
|
||||
:show_data_values => true,
|
||||
:rotate_y_labels => false,
|
||||
:graph_title => l(:label_commits_per_author),
|
||||
:show_graph_title => true
|
||||
:height => 400,
|
||||
:width => 600,
|
||||
:fields => fields,
|
||||
:stack => :side,
|
||||
:scale_integers => true,
|
||||
:show_data_values => true,
|
||||
:rotate_y_labels => false,
|
||||
:graph_title => l(:label_commits_per_author),
|
||||
:show_graph_title => true
|
||||
)
|
||||
graph.add_data(
|
||||
:data => commits_data,
|
||||
:title => l(:label_revision_plural)
|
||||
:data => commits_data,
|
||||
:title => l(:label_revision_plural)
|
||||
)
|
||||
graph.add_data(
|
||||
:data => changes_data,
|
||||
:title => l(:label_change_plural)
|
||||
:data => changes_data,
|
||||
:title => l(:label_change_plural)
|
||||
)
|
||||
graph.burn
|
||||
end
|
||||
|
|
@ -632,7 +751,7 @@ update
|
|||
@date_from = @date_to << 12
|
||||
@date_from = Date.civil(@date_from.year, @date_from.month, @date_from.day)
|
||||
commits_by_author = Changeset.count(:all, :group => :committer,
|
||||
:conditions => ["#{Changeset.table_name}.repository_id = ? AND #{Changeset.table_name}.commit_date BETWEEN ? AND ?", repository.id, @date_from, @date_to])
|
||||
:conditions => ["#{Changeset.table_name}.repository_id = ? AND #{Changeset.table_name}.commit_date BETWEEN ? AND ?", repository.id, @date_from, @date_to])
|
||||
commits_by_author = commits_by_author.to_a.sort! {|x, y| x.last <=> y.last}.last(25)
|
||||
|
||||
fields = commits_by_author.collect {|r| r.first}
|
||||
|
|
|
|||
|
|
@ -5,14 +5,18 @@ class SchoolController < ApplicationController
|
|||
def upload
|
||||
uploaded_io = params[:logo]
|
||||
school_id ||= params[:id]
|
||||
s1 = School.find(school_id)
|
||||
unless uploaded_io.nil?
|
||||
File.open(Rails.root.join('public', 'images', 'school', school_id.to_s+'.png'), 'wb') do |file|
|
||||
file.write(uploaded_io.read)
|
||||
end
|
||||
s1 = School.find(school_id)
|
||||
|
||||
s1.logo_link = '/images/school/'+school_id.to_s+'.png'
|
||||
s1.save
|
||||
|
||||
end
|
||||
s1.name = params[:name] unless params[:name].blank?
|
||||
s1.province = params[:province] unless params[:province].blank?
|
||||
s1.save
|
||||
redirect_to admin_schools_url(:school_name => params[:school_name])
|
||||
end
|
||||
|
||||
|
|
@ -105,4 +109,45 @@ class SchoolController < ApplicationController
|
|||
|
||||
render :text => options
|
||||
end
|
||||
|
||||
#根据学校名字或者拼音来查询
|
||||
def on_search
|
||||
condition = "#{params[:name].strip}".gsub(" ","")
|
||||
#将条件截断为汉字和拼音(全汉字 或者 全拼音 或者 汉字和拼音),
|
||||
#获取拼音的第一次出现的位置
|
||||
chinese = []
|
||||
pinyin = []
|
||||
condition.scan(/./).each_with_index do |char,index|
|
||||
if char =~ /[a-zA-Z0-9]/
|
||||
pinyin << char
|
||||
elsif char =~ /\'/
|
||||
else
|
||||
chinese << char
|
||||
end
|
||||
end
|
||||
if(condition == '')
|
||||
@school = School.reorder('pinyin').page((params[:page].to_i || 1) - 1).per(100)
|
||||
@school_count = School.count
|
||||
else
|
||||
@school = School.where("name like '%#{chinese.join("")}%' and pinyin like '%#{pinyin.join("")}%'").reorder('pinyin').page((params[:page].to_i || 1) - 1).per(100)
|
||||
@school_count = School.where("name like '%#{chinese.join("")}%' and pinyin like '%#{pinyin.join("")}%'").count
|
||||
end
|
||||
|
||||
result = []
|
||||
# @school.each do |sc|
|
||||
# result << {:value=>sc.name,:data=>sc.id}
|
||||
# end
|
||||
render :json =>{ :schools => @school,:count=>@school_count}.to_json
|
||||
end
|
||||
|
||||
#添加学校
|
||||
def add_school
|
||||
@school = School.new
|
||||
@school.name = params[:name].strip
|
||||
@school.pinyin = Pinyin.t(params[:name].strip, splitter: '')
|
||||
@school.save
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -0,0 +1,43 @@
|
|||
class ShieldActivitiesController < ApplicationController
|
||||
def create
|
||||
if params[:org_id]
|
||||
if params[:project_id]
|
||||
ShieldActivity.create(:container_type => 'Organization', :container_id => params[:org_id].to_i, :shield_type => 'Project', :shield_id => params[:project_id].to_i)
|
||||
elsif params[:course_id]
|
||||
ShieldActivity.create(:container_type => 'Organization', :container_id => params[:org_id].to_i, :shield_type => 'Course', :shield_id => params[:course_id].to_i)
|
||||
end
|
||||
elsif params[:user_id]
|
||||
if params[:project_id]
|
||||
ShieldActivity.create(:container_type => 'User', :container_id => params[:user_id].to_i, :shield_type => 'Project', :shield_id => params[:project_id].to_i)
|
||||
elsif params[:course_id]
|
||||
ShieldActivity.create(:container_type => 'User', :container_id => params[:user_id].to_i, :shield_type => 'Course', :shield_id => params[:course_id].to_i)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def show_acts
|
||||
if params[:org_id]
|
||||
if params[:project_id]
|
||||
ShieldActivity.where("container_type='Organization' and container_id=#{params[:org_id].to_i} and shield_type='Project' and shield_id=#{params[:project_id]}").each do |act|
|
||||
act.destroy
|
||||
end
|
||||
# ShieldActivity.create(:container_type => 'Organization', :container_id => params[:org_id].to_i, :shield_type => 'Project', :shield_id => params[:project_id].to_i)
|
||||
elsif params[:course_id]
|
||||
ShieldActivity.where("container_type='Organization' and container_id=#{params[:org_id].to_i} and shield_type='Course' and shield_id=#{params[:course_id]}").each do |act|
|
||||
act.destroy
|
||||
end
|
||||
end
|
||||
elsif params[:user_id]
|
||||
if params[:project_id]
|
||||
ShieldActivity.where("container_type='User' and container_id=#{params[:user_id].to_i} and shield_type='Project' and shield_id=#{params[:project_id]}").each do |act|
|
||||
act.destroy
|
||||
end
|
||||
# ShieldActivity.create(:container_type => 'Organization', :container_id => params[:org_id].to_i, :shield_type => 'Project', :shield_id => params[:project_id].to_i)
|
||||
elsif params[:course_id]
|
||||
ShieldActivity.where("container_type='User' and container_id=#{params[:user_id].to_i} and shield_type='Course' and shield_id=#{params[:course_id]}").each do |act|
|
||||
act.destroy
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -84,7 +84,7 @@ class StoresController < ApplicationController
|
|||
respond_to do |format|
|
||||
format.xls {
|
||||
send_data(homework_to_xls(attachments), :type => "text/excel;charset=utf-8; header=present",
|
||||
:filename => "#{l(:label_file_lost_list)}.xls")
|
||||
:filename => filename_for_content_disposition("#{l(:label_file_lost_list)}.xls") )
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,21 +1,21 @@
|
|||
class StudentWorkController < ApplicationController
|
||||
layout "base_courses"
|
||||
include StudentWorkHelper
|
||||
include ApplicationHelper
|
||||
require 'bigdecimal'
|
||||
require "base64"
|
||||
before_filter :find_homework, :only => [:new, :index, :create, :student_work_absence_penalty, :absence_penalty_list, :evaluation_list, :program_test]
|
||||
before_filter :find_work, :only => [:edit, :update, :show, :destroy, :add_score, :praise_student_work]
|
||||
before_filter :find_homework, :only => [:new, :index, :create, :student_work_absence_penalty, :absence_penalty_list, :evaluation_list, :program_test,:set_score_rule,:forbidden_anonymous_comment,:delete_work,:new_student_work_project,:student_work_project,:cancel_relate_project,:search_course_students]
|
||||
before_filter :find_work, :only => [:edit, :update, :show, :destroy, :add_score, :praise_student_work,:retry_work,:revise_attachment]
|
||||
before_filter :member_of_course, :only => [:index, :new, :create, :show, :add_score, :praise_student_work]
|
||||
before_filter :author_of_work, :only => [:edit, :update, :destroy]
|
||||
before_filter :teacher_of_course, :only => [:student_work_absence_penalty, :absence_penalty_list, :evaluation_list]
|
||||
protect_from_forgery :except => :set_program_score
|
||||
before_filter :teacher_of_course, :only => [:student_work_absence_penalty, :absence_penalty_list, :evaluation_list, :set_score_rule, :forbidden_anonymous_comment]
|
||||
|
||||
###
|
||||
def program_test
|
||||
is_test = params[:is_test] == 'true'
|
||||
resultObj = {status: 0, results: [], error_msg: '', time: Time.now.strftime('%Y-%m-%d %T')}
|
||||
unless is_test
|
||||
student_work = find_or_save_student_work
|
||||
|
||||
student_work = find_or_save_student_work(is_test)
|
||||
|
||||
unless student_work
|
||||
resultObj[:status] = 100
|
||||
|
|
@ -42,38 +42,31 @@ class StudentWorkController < ApplicationController
|
|||
|
||||
end
|
||||
end
|
||||
|
||||
else
|
||||
if @homework.homework_type == 2 && @homework.homework_detail_programing
|
||||
result = test_realtime(student_work, params[:src])
|
||||
logger.debug result
|
||||
resultObj[:status] = result["status"]
|
||||
resultObj[:results] = result["results"]
|
||||
resultObj[:error_msg] = result["error_msg"]
|
||||
results = result["results"]
|
||||
if result["status"].to_i == -2 #编译错误
|
||||
results = [result["error_msg"]]
|
||||
end
|
||||
|
||||
resultObj[:status] = result["status"].to_i
|
||||
resultObj[:time] = Time.now.strftime('%Y-%m-%d %T')
|
||||
resultObj[:index] = 0
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
render :json => resultObj
|
||||
end
|
||||
|
||||
def index
|
||||
# 消息状态更新
|
||||
# 作业消息状态更新
|
||||
@homework.course_messages.each do |homework_message|
|
||||
if User.current.id == homework_message.user_id
|
||||
homework_message.update_attributes(:viewed => true)
|
||||
if User.current.id == homework_message.user_id && homework_message.viewed == 0
|
||||
homework_message.update_attributes(:viewed => true) if homework_message.viewed == 0
|
||||
end
|
||||
end
|
||||
|
||||
# 作品打分消息状态更新
|
||||
studentworks_scores = CourseMessage.where("user_id =? and course_id =? and course_message_type =? and viewed =?", User.current.id, @homework.course, "StudentWorksScore", 0)
|
||||
studentworks_scores.each do |studentworks_score|
|
||||
studentworks_score.update_attributes(:viewed => true) if studentworks_score.viewed == 0
|
||||
end
|
||||
# 作品评论消息状态更新
|
||||
journals_for_teacher = CourseMessage.where("user_id =? and course_id =? and course_message_type =? and viewed =?", User.current.id, @homework.course, "JournalsForMessage", 0)
|
||||
journals_for_teacher.each do |journal_for_teacher|
|
||||
journal_for_teacher.update_attributes(:viewed => true)
|
||||
end
|
||||
#不能参与作业匿评消息状态更新
|
||||
no_evaluation = CourseMessage.where("user_id =? and course_id =? and course_message_type =? and viewed =? and status =?", User.current.id, @homework.course, "StudentWork", 0, 0)
|
||||
no_evaluation.update_all(:viewed => true)
|
||||
# 作品留言
|
||||
# 消息end
|
||||
#设置作业对应的forge_messages表的viewed字段
|
||||
query_student_work = @homework.course_messages
|
||||
|
|
@ -82,8 +75,13 @@ class StudentWorkController < ApplicationController
|
|||
query.update_attributes(:viewed => true)
|
||||
end
|
||||
end
|
||||
##################################################################################################################
|
||||
@order,@b_sort,@name,@group = params[:order] || "score",params[:sort] || "desc",params[:name] || "",params[:group]
|
||||
@is_teacher = User.current.allowed_to?(:as_teacher,@course)
|
||||
@homework_commons = @course.homework_commons.where("publish_time <= ?",Time.now.strftime("%Y-%m-%d")).order("created_at desc")
|
||||
@is_teacher = User.current.allowed_to?(:as_teacher,@course) || User.current.admin?
|
||||
@is_evaluation = @homework.homework_detail_manual && @homework.homework_detail_manual.comment_status == 2 && !@is_teacher #是不是匿评
|
||||
@show_all = false
|
||||
|
||||
course_group = CourseGroup.find_by_id(@group) if @group
|
||||
if course_group
|
||||
group_students = course_group.users
|
||||
|
|
@ -92,80 +90,99 @@ class StudentWorkController < ApplicationController
|
|||
else
|
||||
student_in_group = '(' + group_students.map{|user| user.id}.join(',') + ')'
|
||||
end
|
||||
#老师 || 非匿评作业 || 匿评结束 显示所有的作品
|
||||
@show_all = @is_teacher || @homework.homework_type != 1 || @homework.homework_detail_manual.comment_status == 3 || User.current.admin?
|
||||
if @show_all
|
||||
if @homework.homework_type == 1 || @is_teacher || User.current.admin? #超级管理员 || 老师 || 匿评结束 显示所有的作品
|
||||
if @order == "name"
|
||||
@stundet_works = search_homework_member @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").joins(:user).where("users.id in #{student_in_group}").order("users.lastname #{@b_sort}, users.firstname #{@b_sort}"),@name
|
||||
else
|
||||
@stundet_works = search_homework_member @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").joins(:user).where("users.id in #{student_in_group}").order("#{@order} #{@b_sort}"),@name
|
||||
end
|
||||
else #剩余情况: 学生 && 非匿评作业 如果未提交作品,只能看到自己的,提交了作品,能看到所有作品
|
||||
my_work = @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").where(:user_id => User.current.id)
|
||||
if my_work.empty?
|
||||
@stundet_works = []
|
||||
else
|
||||
if @order == "name"
|
||||
@stundet_works = search_homework_member @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").joins(:user).where("users.id in #{student_in_group}").order("users.lastname #{@b_sort}, users.firstname #{@b_sort}"),@name
|
||||
else
|
||||
@stundet_works = search_homework_member @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").joins(:user).where("users.id in #{student_in_group}").order("#{@order} #{@b_sort}"),@name
|
||||
end
|
||||
end
|
||||
end
|
||||
else #学生
|
||||
if @homework.homework_detail_manual.comment_status == 1 #未开启匿评,只显示我的作品
|
||||
#老师 || 超级管理员 || 禁用匿评&&作业截止&&已提交作品 显示所有列表
|
||||
if @is_teacher || @homework.homework_detail_manual.nil? ||
|
||||
(@homework.anonymous_comment == 1 && Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") < Time.now.strftime("%Y-%m-%d") && !@homework.student_works.where(:user_id => User.current.id).empty?)
|
||||
@stundet_works = search_homework_member @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").joins(:user).where("users.id in #{student_in_group}").order("#{@order} #{@b_sort}"),@name
|
||||
@show_all = true
|
||||
elsif @homework.homework_detail_manual.comment_status == 1 #学生 && 未开启匿评 只看到自己的
|
||||
if @homework.homework_type == 3
|
||||
pro = @homework.student_work_projects.where(:user_id => User.current.id).first
|
||||
@stundet_works = @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").where(:id => pro.student_work_id)
|
||||
else
|
||||
@stundet_works = @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").where(:user_id => User.current.id)
|
||||
elsif @homework.homework_detail_manual.comment_status == 2 #匿评列表,显示匿评作品和我的作品
|
||||
@is_evaluation = true
|
||||
my_work = @homework.student_works.where(:user_id => User.current.id)
|
||||
@stundet_works = my_work + User.current.student_works_evaluation_distributions.map(&:student_work).select { |work| work.homework_common_id == @homework.id}
|
||||
end
|
||||
elsif @homework.homework_detail_manual.comment_status == 2 #学生 && 开启匿评 看到匿评列表
|
||||
if @homework.homework_type == 3
|
||||
pro = @homework.student_work_projects.where(:user_id => User.current.id).first
|
||||
my_work = @homework.student_works.where(:id => pro.student_work_id)
|
||||
else
|
||||
my_work = @homework.student_works.where(:user_id => User.current.id)
|
||||
end
|
||||
@stundet_works = my_work + User.current.student_works_evaluation_distributions.map(&:student_work).select { |work| work.homework_common_id == @homework.id}
|
||||
elsif @homework.homework_detail_manual.comment_status == 3 #学生 && 关闭匿评 未提交作品之前列表为空,提交了作品看到所有的
|
||||
if @homework.homework_type == 3
|
||||
pro = @homework.student_work_projects.where(:user_id => User.current.id).first
|
||||
my_work = @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").where(:id => pro.student_work_id)
|
||||
else
|
||||
my_work = @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").where(:user_id => User.current.id)
|
||||
end
|
||||
if my_work.empty?
|
||||
@stundet_works = []
|
||||
else
|
||||
@stundet_works = search_homework_member @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").joins(:user).where("users.id in #{student_in_group}").order("#{@order} #{@b_sort}"),@name
|
||||
@show_all = true
|
||||
end
|
||||
else
|
||||
@stundet_works = []
|
||||
end
|
||||
@student_work_count = (search_homework_member @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").joins(:user).where("users.id in #{student_in_group}").order("#{@order} #{@b_sort}"),@name).count
|
||||
else
|
||||
#老师 || 非匿评作业 || 匿评结束 显示所有的作品
|
||||
@show_all = @is_teacher || @homework.homework_type != 1 || @homework.homework_detail_manual.comment_status == 3 || User.current.admin?
|
||||
if @show_all
|
||||
if @homework.homework_type == 1 || @is_teacher || User.current.admin? #超级管理员 || 老师 || 匿评结束 显示所有的作品
|
||||
if @order == "name"
|
||||
@stundet_works = search_homework_member @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").joins(:user).order("users.lastname #{@b_sort}, users.firstname #{@b_sort}"),@name
|
||||
else
|
||||
@stundet_works = search_homework_member @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").order("#{@order} #{@b_sort}"),@name
|
||||
end
|
||||
else #剩余情况: 学生 && 非匿评作业 如果未提交作品,只能看到自己的,提交了作品,能看到所有作品
|
||||
my_work = @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").where(:user_id => User.current.id)
|
||||
if my_work.empty?
|
||||
@stundet_works = []
|
||||
else
|
||||
if @order == "name"
|
||||
@stundet_works = search_homework_member @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").joins(:user).order("users.lastname #{@b_sort}, users.firstname #{@b_sort}"),@name
|
||||
else
|
||||
@stundet_works = search_homework_member @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").order("#{@order} #{@b_sort}"),@name
|
||||
end
|
||||
end
|
||||
end
|
||||
else #学生
|
||||
if @homework.homework_detail_manual.comment_status == 1 #未开启匿评,只显示我的作品
|
||||
if @is_teacher || @homework.homework_detail_manual.nil? || (@homework.anonymous_comment == 1 && Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") < Time.now.strftime("%Y-%m-%d") && !@homework.student_works.where(:user_id => User.current.id).empty?) #老师 || 超级管理员 显示所有列表
|
||||
@stundet_works = search_homework_member @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").order("#{@order} #{@b_sort}"),@name
|
||||
@show_all = true
|
||||
elsif @homework.homework_detail_manual.comment_status == 1 #学生 && 未开启匿评 只看到自己的
|
||||
if @homework.homework_type == 3
|
||||
pro = @homework.student_work_projects.where(:user_id => User.current.id).first
|
||||
@stundet_works = @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").where(:id => pro.student_work_id)
|
||||
else
|
||||
@stundet_works = @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").where(:user_id => User.current.id)
|
||||
elsif @homework.homework_detail_manual.comment_status == 2 #匿评列表,显示匿评作品和我的作品
|
||||
@is_evaluation = true
|
||||
my_work = @homework.student_works.where(:user_id => User.current.id)
|
||||
@stundet_works = my_work + User.current.student_works_evaluation_distributions.map(&:student_work).select { |work| work.homework_common_id == @homework.id}
|
||||
end
|
||||
elsif @homework.homework_detail_manual.comment_status == 2 #学生 && 开启匿评 看到匿评列表
|
||||
if @homework.homework_type == 3
|
||||
pro = @homework.student_work_projects.where(:user_id => User.current.id).first
|
||||
my_work = @homework.student_works.where(:id => pro.student_work_id)
|
||||
else
|
||||
my_work = @homework.student_works.where(:user_id => User.current.id)
|
||||
end
|
||||
@stundet_works = my_work + User.current.student_works_evaluation_distributions.map(&:student_work).select { |work| work.homework_common_id == @homework.id}
|
||||
elsif @homework.homework_detail_manual.comment_status == 3 #学生 && 关闭匿评 未提交作品之前列表为空,提交了作品看到所有的
|
||||
if @homework.homework_type == 3
|
||||
pro = @homework.student_work_projects.where(:user_id => User.current.id).first
|
||||
my_work = @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").where(:id => pro.student_work_id)
|
||||
else
|
||||
my_work = @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").where(:user_id => User.current.id)
|
||||
end
|
||||
if my_work.empty?
|
||||
@stundet_works = []
|
||||
else
|
||||
@stundet_works = search_homework_member @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").order("#{@order} #{@b_sort}"),@name
|
||||
@show_all = true
|
||||
end
|
||||
else
|
||||
@stundet_works = []
|
||||
end
|
||||
@student_work_count = (search_homework_member @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").order("#{@order} #{@b_sort}"),@name).count
|
||||
end
|
||||
@homework_commons = @course.homework_commons.order("created_at desc")
|
||||
|
||||
@score = @b_sort == "desc" ? "asc" : "desc"
|
||||
|
||||
respond_to do |format|
|
||||
format.js
|
||||
format.html
|
||||
format.xls {
|
||||
filename = "#{@course.teacher.lastname.to_s + @course.teacher.firstname}_#{@course.name}_#{@course.time.to_s + @course.term}_#{@homework.name}#{l(:excel_homework_list)}.xls"
|
||||
send_data(homework_to_xls(@stundet_works), :type => "text/excel;charset=utf-8; header=present",
|
||||
:filename => "#{@course.teacher.lastname.to_s + @course.teacher.firstname}_#{@course.name}_#{@course.time.to_s + @course.term}_#{@homework.name}#{l(:excel_homework_list)}.xls")
|
||||
:filename => filename_for_content_disposition(filename))
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def new
|
||||
#更新消息
|
||||
noEvaluation = @homework.course_messages.where("user_id =? and viewed =?", User.current.id, 0)
|
||||
noEvaluation.update_all(:viewed => true)
|
||||
|
||||
if @homework.homework_type==2
|
||||
redirect_to new_user_commit_homework_users_path(homework_id: @homework.id)
|
||||
return
|
||||
|
|
@ -181,45 +198,91 @@ class StudentWorkController < ApplicationController
|
|||
end
|
||||
|
||||
def create
|
||||
if params[:student_work]
|
||||
stundet_work = StudentWork.find(params[:student_work_id]) if params[:student_work_id]
|
||||
stundet_work ||= StudentWork.new
|
||||
stundet_work.name = params[:student_work][:name]
|
||||
stundet_work.description = params[:student_work][:description]
|
||||
stundet_work.project_id = params[:student_work][:project_id]
|
||||
stundet_work.homework_common_id = @homework.id
|
||||
stundet_work.user_id = User.current.id
|
||||
stundet_work.save_attachments(params[:attachments])
|
||||
if Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") < Time.parse(Time.now.to_s).strftime("%Y-%m-%d")
|
||||
stundet_work.late_penalty = @homework.late_penalty
|
||||
else
|
||||
stundet_work.late_penalty = 0
|
||||
# 提交作品前先判断是否已经提交
|
||||
@has_commit = false;
|
||||
if hsd_committed_work?(User.current.id, @homework.id)
|
||||
@work = StudentWork.where("user_id =? and homework_common_id =?", User.current.id, @homework.id).first
|
||||
@has_commit = true;
|
||||
#flash[:notice] = l(:notice_successful_create)
|
||||
#redirect_to edit_student_work_url(params[:student_work])
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
render_attachment_warning_if_needed(stundet_work)
|
||||
if stundet_work.save
|
||||
if @homework.homework_type == 2 && @homework.homework_detail_programing #编程作业,学生提交作品后计算系统得分
|
||||
|
||||
return
|
||||
end
|
||||
if params[:student_work]
|
||||
@submit_result = true
|
||||
student_work = StudentWork.find(params[:student_work_id]) if params[:student_work_id]
|
||||
student_work ||= StudentWork.new
|
||||
student_work.name = params[:student_work][:name]
|
||||
student_work.description = params[:student_work][:description]
|
||||
student_work.homework_common_id = @homework.id
|
||||
student_work.user_id = User.current.id
|
||||
student_work.save_attachments(params[:attachments])
|
||||
render_attachment_warning_if_needed(student_work)
|
||||
if @homework.homework_type == 3 && @homework.homework_detail_group.base_on_project == 1
|
||||
@student_work_project = @homework.student_work_projects.where("user_id = #{User.current.id}").first
|
||||
student_work.project_id = @student_work_project.project_id
|
||||
end
|
||||
#提交作品时,计算是否迟交
|
||||
if Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") < Time.parse(Time.now.to_s).strftime("%Y-%m-%d")
|
||||
student_work.late_penalty = @homework.late_penalty
|
||||
else
|
||||
student_work.late_penalty = 0
|
||||
end
|
||||
if student_work.save
|
||||
if @homework.homework_type == 3 && @homework.homework_detail_group.base_on_project == 1
|
||||
@student_work_project.student_work_id = student_work.id
|
||||
@student_work_project.save
|
||||
members = params[:group_member_ids].split(',')
|
||||
for i in 1 .. members.count-1
|
||||
stu_project = StudentWorkProject.new
|
||||
stu_project.homework_common_id = @homework.id
|
||||
stu_project.student_work_id = student_work.id
|
||||
stu_project.project_id = @student_work_project.project_id
|
||||
stu_project.user_id = members[i].to_i
|
||||
stu_project.is_leader = 0
|
||||
stu_project.save
|
||||
end
|
||||
elsif @homework.homework_type == 3 && @homework.homework_detail_group.base_on_project == 0
|
||||
members = params[:group_member_ids].split(',')
|
||||
for i in 0 .. members.count-1
|
||||
stu_project = StudentWorkProject.new
|
||||
stu_project.homework_common_id = @homework.id
|
||||
stu_project.student_work_id = student_work.id
|
||||
stu_project.project_id = -1
|
||||
stu_project.user_id = members[i].to_i
|
||||
if i == 0
|
||||
stu_project.is_leader = 1
|
||||
else
|
||||
stu_project.is_leader = 0
|
||||
end
|
||||
stu_project.save
|
||||
end
|
||||
end
|
||||
update_course_activity(@homework.class,@homework.id)
|
||||
update_user_activity(@homework.class,@homework.id)
|
||||
update_org_activity(@homework.class,@homework.id)
|
||||
|
||||
course_message = CourseMessage.new(:user_id =>User.current.id,:content=>"new",:course_message_id=>student_work.id,:course_id => @course.id,:course_message_type=>"StudentWork", :status => 9) #作品提交记录
|
||||
course_message.save
|
||||
|
||||
@student_work = StudentWork.where(homework_common_id: @homework.id, user_id: User.current.id).first
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
flash[:notice] = l(:notice_successful_create)
|
||||
redirect_to student_work_index_url(:homework => @homework.id)
|
||||
}
|
||||
format.js
|
||||
end
|
||||
return
|
||||
end
|
||||
end
|
||||
@submit_result = false
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
flash[:notice] = l(:notice_failed_create)
|
||||
redirect_to new_student_work_url(:homework => @homework.id)
|
||||
}
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
@user = User.current
|
||||
if !User.current.admin? && @homework.homework_type == 2 #编程作业不能修改作业
|
||||
if (!User.current.admin? && @homework.homework_type == 2) || Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") < Time.now.strftime("%Y-%m-%d") #编程作业不能修改作业|| 截止日期已到不能修改作业
|
||||
render_403
|
||||
else
|
||||
respond_to do |format|
|
||||
|
|
@ -230,38 +293,75 @@ class StudentWorkController < ApplicationController
|
|||
|
||||
def update
|
||||
if params[:student_work]
|
||||
@submit_result = true
|
||||
@work.name = params[:student_work][:name]
|
||||
@work.description = params[:student_work][:description]
|
||||
@work.project_id = params[:student_work][:project]
|
||||
@work.save_attachments(params[:attachments])
|
||||
render_attachment_warning_if_needed(@work)
|
||||
if @work.save
|
||||
if @homework.homework_type == 3
|
||||
@student_work_project = @homework.student_work_projects.where("user_id=?",User.current.id).first
|
||||
student_work_projects = @homework.student_work_projects.where("student_work_id=? and is_leader =?",@work.id,0)
|
||||
student_work_projects.delete_all
|
||||
members = params[:group_member_ids].split(',')
|
||||
for i in 1 .. members.count-1
|
||||
stu_project = StudentWorkProject.new
|
||||
stu_project.homework_common_id = @homework.id
|
||||
stu_project.student_work_id = @work.id
|
||||
if @homework.homework_detail_group.base_on_project == 1
|
||||
stu_project.project_id = @student_work_project.project_id
|
||||
else @homework.homework_detail_group.base_on_project == 0
|
||||
stu_project.project_id = -1
|
||||
end
|
||||
stu_project.user_id = members[i].to_i
|
||||
stu_project.is_leader = 0
|
||||
stu_project.save
|
||||
end
|
||||
end
|
||||
|
||||
course_message = CourseMessage.new(:user_id =>User.current.id,:content=>"edit",:course_message_id=>@work.id,:course_id => @course.id,:course_message_type=>"StudentWork", :status => 9) #作品提交记录
|
||||
course_message.save
|
||||
@student_work = @work
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
flash[:notice] = l(:notice_successful_edit)
|
||||
redirect_to student_work_index_url(:homework => @homework.id)
|
||||
}
|
||||
format.js
|
||||
end
|
||||
return
|
||||
end
|
||||
end
|
||||
=begin
|
||||
respond_to do |format|
|
||||
format.html{redirect_to edit_student_work_url(@work)}
|
||||
end
|
||||
=end
|
||||
@submit_result = false
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
@score = student_work_score @work,User.current
|
||||
@is_teacher = User.current.allowed_to?(:as_teacher,@course)
|
||||
@is_teacher = User.current.allowed_to?(:as_teacher,@course) || User.current.admin?
|
||||
@student_work_scores = @work.student_works_scores.order("updated_at desc")
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
if @homework.homework_type == 2 #编程作业,作品提交后不可以删除
|
||||
render_403
|
||||
elsif @work.destroy
|
||||
if @work.destroy
|
||||
if @homework.homework_type == 3 && @homework.homework_detail_group.base_on_project == 1
|
||||
pros = @work.student_work_projects.where("is_leader = 0")
|
||||
pros.each do |pro|
|
||||
pro.destroy
|
||||
end
|
||||
project = @work.student_work_projects.where("is_leader = 1").first
|
||||
project.update_attributes(:student_work_id => nil)
|
||||
elsif @homework.homework_type == 3 && @homework.homework_detail_group.base_on_project == 0
|
||||
@work.student_work_projects.each do |pro2|
|
||||
pro2.destroy
|
||||
end
|
||||
end
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
redirect_to student_work_index_url(:homework => @homework.id)
|
||||
|
|
@ -270,12 +370,54 @@ class StudentWorkController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def delete_work
|
||||
@work = StudentWork.where("user_id =? and homework_common_id =?", User.current.id, @homework.id).first
|
||||
if @work
|
||||
@work.destroy
|
||||
if @homework.homework_type == 3 && @homework.homework_detail_group.base_on_project == 1
|
||||
pros = @work.student_work_projects.where("is_leader = 0")
|
||||
pros.each do |pro|
|
||||
pro.destroy
|
||||
end
|
||||
project = @work.student_work_projects.where("is_leader = 1").first
|
||||
project.update_attributes(:student_work_id => nil)
|
||||
elsif @homework.homework_type == 3 && @homework.homework_detail_group.base_on_project == 0
|
||||
@work.student_work_projects.each do |pro2|
|
||||
pro2.destroy
|
||||
end
|
||||
end
|
||||
end
|
||||
redirect_to user_homeworks_user_path(User.current.id)
|
||||
end
|
||||
|
||||
def retry_work
|
||||
if @work.destroy
|
||||
if @homework.homework_type == 3 && @homework.homework_detail_group.base_on_project == 1
|
||||
pros = @work.student_work_projects.where("is_leader = 0")
|
||||
pros.each do |pro|
|
||||
pro.destroy
|
||||
end
|
||||
project = @work.student_work_projects.where("is_leader = 1").first
|
||||
project.update_attributes(:student_work_id => nil)
|
||||
elsif @homework.homework_type == 3 && @homework.homework_detail_group.base_on_project == 0
|
||||
@work.student_work_projects.each do |pro2|
|
||||
pro2.destroy
|
||||
end
|
||||
end
|
||||
@student_work = StudentWork.new
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#添加评分,已评分则为修改评分
|
||||
def add_score
|
||||
@is_last = params[:is_last] == "true"
|
||||
render_403 and return if User.current == @work.user #不可以匿评自己的作品
|
||||
@is_teacher = User.current.allowed_to?(:as_teacher,@course)
|
||||
@is_teacher = User.current.allowed_to?(:as_teacher,@course) || User.current.admin?
|
||||
#老师、教辅可以随时评分,学生只能在匿评作业的匿评阶段进行评分
|
||||
render_403 and return unless @is_teacher || (@homework.homework_type == 1 && @homework.homework_detail_manual.comment_status == 2)
|
||||
render_403 and return unless @is_teacher || @homework.homework_detail_manual.comment_status == 2
|
||||
@score = student_work_score @work,User.current
|
||||
if @score
|
||||
@score.comment = params[:new_form][:user_message] if params[:new_form] && params[:new_form][:user_message] && params[:new_form][:user_message] != ""
|
||||
|
|
@ -288,6 +430,7 @@ class StudentWorkController < ApplicationController
|
|||
end
|
||||
@is_new = false
|
||||
else
|
||||
@is_last_a = @work.student_works_scores.empty?
|
||||
@score = StudentWorksScore.new
|
||||
@score.score = params[:score] if params[:score]
|
||||
@score.comment = params[:new_form][:user_message] if params[:new_form] && params[:new_form][:user_message] && params[:new_form][:user_message] != ""
|
||||
|
|
@ -309,35 +452,11 @@ class StudentWorkController < ApplicationController
|
|||
case @score.reviewer_role
|
||||
when 1 #教师评分:最后一个教师评分为最终评分
|
||||
@work.teacher_score = @score.score
|
||||
@work.final_score = @score.score
|
||||
when 2 #教辅评分 教辅评分显示平均分
|
||||
@work.teaching_asistant_score = @work.student_works_scores.where(:reviewer_role => 2).average(:score).try(:round, 2).to_f
|
||||
if @work.teacher_score.nil?
|
||||
if @work.student_score.nil?
|
||||
@work.final_score = @work.teaching_asistant_score
|
||||
else
|
||||
ta_proportion = @homework.homework_detail_manual.ta_proportion if @homework.homework_detail_manual
|
||||
ta_proportion = @homework.homework_detail_programing.ta_proportion if @homework.homework_detail_programing
|
||||
final_ta_score = BigDecimal.new("#{@work.teaching_asistant_score}") * BigDecimal.new("#{ta_proportion}")
|
||||
final_s_score = BigDecimal.new("#{@work.student_score}") * (BigDecimal.new('1.0') - BigDecimal.new("#{ta_proportion}"))
|
||||
final_score = final_ta_score + final_s_score
|
||||
@work.final_score = format("%.2f",final_score.to_f)
|
||||
end
|
||||
end
|
||||
when 3 #学生评分 学生评分显示平均分
|
||||
@work.student_score = @work.student_works_scores.where(:reviewer_role => 3).average(:score).try(:round, 2).to_f
|
||||
if @work.teacher_score.nil?
|
||||
if @work.teaching_asistant_score.nil?
|
||||
@work.final_score = @work.student_score
|
||||
else
|
||||
final_ta_score = BigDecimal.new("#{@work.teaching_asistant_score}") * BigDecimal.new("#{@homework.homework_detail_manual.ta_proportion}")
|
||||
final_s_score = BigDecimal.new("#{@work.student_score}") * (BigDecimal.new('1.0') - BigDecimal.new("#{@homework.homework_detail_manual.ta_proportion}"))
|
||||
final_score = final_ta_score + final_s_score
|
||||
@work.final_score = format("%.2f",final_score.to_f)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if @work.save
|
||||
respond_to do |format|
|
||||
format.js
|
||||
|
|
@ -349,6 +468,7 @@ class StudentWorkController < ApplicationController
|
|||
#添加评分的回复
|
||||
def add_score_reply
|
||||
@score = StudentWorksScore.find params[:score_id]
|
||||
@is_last = params[:is_last] == "true"
|
||||
@jour = @score.journals_for_messages.new(:user_id => User.current.id,:notes =>params[:message], :reply_id => 0)
|
||||
if @jour.save
|
||||
@status = 1
|
||||
|
|
@ -425,8 +545,9 @@ class StudentWorkController < ApplicationController
|
|||
end
|
||||
respond_to do |format|
|
||||
format.xls {
|
||||
filename = "#{@course.teacher.lastname.to_s + @course.teacher.firstname}_#{@course.name}_#{@course.time.to_s + @course.term}_#{@homework.name}#{l(:excel_absence_list)}.xls"
|
||||
send_data(absence_penalty_list_xls(@stundet_works), :type => "text/excel;charset=utf-8; header=present",
|
||||
:filename => "#{@course.teacher.lastname.to_s + @course.teacher.firstname}_#{@course.name}_#{@course.time.to_s + @course.term}_#{@homework.name}#{l(:excel_absence_list)}.xls")
|
||||
:filename => filename_for_content_disposition(filename))
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
@ -435,53 +556,196 @@ class StudentWorkController < ApplicationController
|
|||
def evaluation_list
|
||||
respond_to do |format|
|
||||
format.xls {
|
||||
filename = "#{@course.teacher.lastname.to_s + @course.teacher.firstname}_#{@course.name}_#{@course.time.to_s + @course.term}_#{@homework.name}#{l(:excel_evaluation_list)}.xls"
|
||||
send_data(evaluation_list_xls(@homework.student_works), :type => "text/excel;charset=utf-8; header=present",
|
||||
:filename => "#{@course.teacher.lastname.to_s + @course.teacher.firstname}_#{@course.name}_#{@course.time.to_s + @course.term}_#{@homework.name}#{l(:excel_evaluation_list)}.xls")
|
||||
:filename => filename_for_content_disposition(filename))
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
#设置编程作业得分
|
||||
def set_program_score
|
||||
stundet_work = StudentWork.find_by_id params[:student_work_id]
|
||||
@course = stundet_work.homework_common.course
|
||||
student_score_count = 0
|
||||
if stundet_work && params[:results] && params[:results].class.to_s == "Array"
|
||||
homework_common = stundet_work.homework_common
|
||||
params[:results].each do |result|
|
||||
homework_tests = homework_common.homework_tests.where("input = '#{result[:input]}' AND output = '#{result[:output]}'")
|
||||
homework_tests.each do |homework_test|
|
||||
student_work_test = StudentWorkTest.new
|
||||
student_work_test.student_work = stundet_work
|
||||
student_work_test.homework_test = homework_test
|
||||
student_work_test.result = result[:status]
|
||||
if student_work_test.result == 0
|
||||
student_score_count += 1
|
||||
end
|
||||
student_work_test.error_msg = params[:compile_error_msg]
|
||||
student_work_test.save!
|
||||
#设置评分规则
|
||||
def set_score_rule
|
||||
homework_detail_manual = @homework.homework_detail_manual
|
||||
homework_detail_programing = @homework.homework_detail_programing
|
||||
|
||||
unless @homework.late_penalty.to_s == params[:late_penalty].to_s
|
||||
@homework.late_penalty = params[:late_penalty]
|
||||
@homework.student_works.where("created_at > '#{@homework.end_time} 23:59:59'").each do |student_work|
|
||||
student_work.late_penalty = @homework.late_penalty
|
||||
student_work.save
|
||||
end
|
||||
|
||||
@homework.save
|
||||
end
|
||||
|
||||
unless homework_detail_manual.absence_penalty.to_s == params[:absence_penalty].to_s
|
||||
homework_detail_manual.absence_penalty = params[:absence_penalty]
|
||||
if homework_detail_manual.comment_status == 3 #当前作业处于匿评结束状态,修改缺评扣分才会修改每个作品应扣分的值
|
||||
work_ids = "(" + @homework.student_works.map(&:id).join(",") + ")"
|
||||
@homework.student_works.each do |student_work|
|
||||
absence_penalty_count = student_work.user.student_works_evaluation_distributions.where("student_work_id IN #{work_ids}").count - student_work.user.student_works_scores.where("student_work_id IN #{work_ids}").count
|
||||
student_work.absence_penalty = absence_penalty_count > 0 ? absence_penalty_count * homework_detail_manual.absence_penalty : 0
|
||||
student_work.save
|
||||
end
|
||||
end
|
||||
unless homework_common.homework_tests.empty?
|
||||
stundet_work.student_score = student_score_count * 100.0 / homework_common.homework_tests.count
|
||||
|
||||
if stundet_work.teacher_score.nil?
|
||||
if stundet_work.teaching_asistant_score.nil?
|
||||
stundet_work.final_score = stundet_work.student_score
|
||||
else
|
||||
final_ta_score = BigDecimal.new("#{stundet_work.teaching_asistant_score}") * BigDecimal.new("#{homework_common.homework_detail_programing.ta_proportion}")
|
||||
final_s_score = BigDecimal.new("#{stundet_work.student_score}") * (BigDecimal.new('1.0') - BigDecimal.new("#{homework_common.homework_detail_programing.ta_proportion}"))
|
||||
final_score = final_ta_score + final_s_score
|
||||
stundet_work.final_score = format("%.1f",final_score.to_f)
|
||||
end
|
||||
end
|
||||
homework_detail_manual.save if homework_detail_manual
|
||||
end
|
||||
|
||||
stundet_work.save!
|
||||
teacher_priority = params[:teacher_priority] ? 1 : 0
|
||||
if homework_detail_manual.ta_proportion.to_s != params[:ta_proportion].to_s || @homework.teacher_priority.to_s != teacher_priority.to_s || (homework_detail_programing && homework_detail_programing.ta_proportion.to_s != params[:sy_proportion].to_s)
|
||||
homework_detail_manual.ta_proportion = params[:ta_proportion]
|
||||
homework_detail_programing.ta_proportion = params[:sy_proportion] if homework_detail_programing
|
||||
@homework.teacher_priority = teacher_priority
|
||||
|
||||
@homework.save
|
||||
homework_detail_manual.save if homework_detail_manual
|
||||
homework_detail_programing.save if homework_detail_programing
|
||||
|
||||
@homework.student_works.each do |student_work|
|
||||
set_final_score @homework,student_work
|
||||
student_work.save
|
||||
end
|
||||
end
|
||||
if params[:student_path]
|
||||
redirect_to student_work_index_url(:homework => @homework.id)
|
||||
else
|
||||
@user_activity_id = params[:user_activity_id].to_i
|
||||
@is_in_course = params[:is_in_course].to_i
|
||||
@course_activity = params[:course_activity].to_i
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def forbidden_anonymous_comment
|
||||
@homework.update_column('anonymous_comment', 1)
|
||||
homework_detail_manual = @homework.homework_detail_manual
|
||||
homework_detail_programing = @homework.homework_detail_programing
|
||||
if homework_detail_programing
|
||||
homework_detail_manual.update_column('ta_proportion', 0.4)
|
||||
homework_detail_programing.update_column('ta_proportion', 0.6)
|
||||
else
|
||||
homework_detail_manual.update_column('ta_proportion', 1.0)
|
||||
end
|
||||
@homework.student_works.each do |student_work|
|
||||
set_final_score @homework,student_work
|
||||
student_work.save
|
||||
end
|
||||
@user_activity_id = params[:user_activity_id].to_i
|
||||
@is_in_course = params[:is_in_course].to_i
|
||||
@course_activity = params[:course_activity].to_i
|
||||
end
|
||||
|
||||
def revise_attachment
|
||||
Attachment.attach_filesex(@work, params[:attachments], params[:attachment_type])
|
||||
revise_attachments = @work.attachments.where("attachtype = 7").reorder("created_on desc")
|
||||
if revise_attachments.count == 2
|
||||
revise_attachments.last.destroy
|
||||
end
|
||||
attachment = @work.attachments.where("attachtype = 7").first
|
||||
attachment.update_attributes(:description => params[:description])
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def new_student_work_project
|
||||
@user_activity_id = params[:user_activity_id].to_i
|
||||
@is_in_course = params[:is_in_course].to_i
|
||||
@course_activity = params[:course_activity].to_i
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
#创建作业的关联项目
|
||||
def student_work_project
|
||||
@project = StudentWorkProject.new
|
||||
@project.homework_common_id = @homework.id
|
||||
@project.project_id = (Project.find params[:projectName].to_i).id
|
||||
@project.user_id = User.current.id
|
||||
@project.is_leader = 1
|
||||
if @project.save
|
||||
@user_activity_id = params[:user_activity_id].to_i
|
||||
@is_in_course = params[:is_in_course].to_i
|
||||
@course_activity = params[:course_activity].to_i
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
#查找学生创建的项目列表
|
||||
def search_user_projects
|
||||
condition = '%%'
|
||||
if !params[:name].nil?
|
||||
condition = "%#{params[:name].strip}%".gsub(" ","")
|
||||
end
|
||||
@project_ids = Project.visible.where("user_id = #{User.current.id} and name like '#{condition}'")
|
||||
@first = params[:first].to_i
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
#查找课程的学生
|
||||
def search_course_students
|
||||
name = ""
|
||||
unless params[:name].nil?
|
||||
name = params[:name]
|
||||
end
|
||||
if @homework.homework_detail_group.base_on_project == 0
|
||||
all_student_ids = "(" + @homework.course.student.map{|student| student.student_id}.join(",") + ")"
|
||||
else
|
||||
pro = Project.find @homework.student_work_projects.where("user_id=?",User.current.id).first.project_id
|
||||
all_student_ids = "(" + pro.members.map{|member| member.user_id}.join(",") + ")"
|
||||
end
|
||||
all_students = User.where("id in #{all_student_ids}")
|
||||
@commit_student_ids = @homework.student_work_projects.map{|student| student.user_id}
|
||||
@users = searchstudent_by_name all_students,name
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def cancel_relate_project
|
||||
relate_pro = StudentWorkProject.where("user_id = #{User.current.id} and homework_common_id = #{@homework.id}").first
|
||||
if relate_pro.destroy
|
||||
@user_activity_id = params[:user_activity_id].to_i
|
||||
@is_in_course = params[:is_in_course].to_i
|
||||
@course_activity = params[:course_activity].to_i
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def searchstudent_by_name users, name
|
||||
mems = []
|
||||
if name != ""
|
||||
name = name.to_s.downcase
|
||||
users.each do |m|
|
||||
username = m.lastname.to_s.downcase + m.firstname.to_s.downcase
|
||||
if(m.login.to_s.downcase.include?(name) || m.user_extensions[:student_id].to_s.downcase.include?(name) || username.include?(name))
|
||||
mems << m
|
||||
end
|
||||
end
|
||||
else
|
||||
mems = users
|
||||
end
|
||||
mems
|
||||
end
|
||||
|
||||
def hsd_committed_work?(user, homework)
|
||||
sw = StudentWork.where("user_id =? and homework_common_id =?", user, homework).first
|
||||
sw.nil? ? result = false : result = true
|
||||
result
|
||||
end
|
||||
|
||||
#获取作业
|
||||
def find_homework
|
||||
@homework = HomeworkCommon.find params[:homework]
|
||||
|
|
@ -511,15 +775,19 @@ class StudentWorkController < ApplicationController
|
|||
end
|
||||
|
||||
def teacher_of_course
|
||||
render_403 unless User.current.allowed_to?(:as_teacher,@course)
|
||||
render_403 unless User.current.allowed_to?(:as_teacher,@course) || User.current.admin?
|
||||
end
|
||||
|
||||
#根据条件过滤作业结果
|
||||
def search_homework_member homeworks,name
|
||||
name = name.downcase
|
||||
select_homework = homeworks.select{ |homework|
|
||||
homework.user[:login].to_s.downcase.include?(name) || homework.user.user_extensions[:student_id].to_s.downcase.include?(name) || (homework.user[:lastname].to_s.downcase + homework.user[:firstname].to_s.downcase).include?(name)
|
||||
}
|
||||
if name == ""
|
||||
select_homework = homeworks
|
||||
else
|
||||
name = name.downcase
|
||||
select_homework = homeworks.select{ |homework|
|
||||
homework.user[:login].to_s.downcase.include?(name) || homework.user.user_extensions[:student_id].to_s.downcase.include?(name) || (homework.user[:lastname].to_s.downcase + homework.user[:firstname].to_s.downcase).include?(name)
|
||||
}
|
||||
end
|
||||
select_homework
|
||||
end
|
||||
|
||||
|
|
@ -530,25 +798,7 @@ class StudentWorkController < ApplicationController
|
|||
sheet1 = book.create_worksheet :name => "homework"
|
||||
blue = Spreadsheet::Format.new :color => :blue, :weight => :bold, :size => 10
|
||||
sheet1.row(0).default_format = blue
|
||||
if @homework.homework_type == 0 #普通作业
|
||||
sheet1.row(0).concat([l(:excel_user_id),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_mail),l(:excel_homework_name),
|
||||
l(:excel_t_score),l(:excel_ta_score),l(:excel_f_score),l(:excel_commit_time)])
|
||||
count_row = 1
|
||||
items.each do |homework|
|
||||
sheet1[count_row,0]=homework.user.id
|
||||
sheet1[count_row,1] = homework.user.lastname.to_s + homework.user.firstname.to_s
|
||||
sheet1[count_row,2] = homework.user.login
|
||||
sheet1[count_row,3] = homework.user.user_extensions.student_id
|
||||
sheet1[count_row,4] = homework.user.mail
|
||||
sheet1[count_row,5] = homework.name
|
||||
sheet1[count_row,6] = homework.teacher_score.nil? ? l(:label_without_score) : format("%.2f",homework.teacher_score)
|
||||
sheet1[count_row,7] = homework.teaching_asistant_score.nil? ? l(:label_without_score) : format("%.2f",homework.teaching_asistant_score)
|
||||
# sheet1[count_row,8] = homework.student_score.nil? ? l(:label_without_score) : format("%.2f",homework.student_score)
|
||||
sheet1[count_row,8] = homework.respond_to?("score") ? homework.score.nil? ? l(:label_without_score) : format("%.2f",homework.score) : l(:label_without_score)
|
||||
sheet1[count_row,9] = format_time(homework.created_at)
|
||||
count_row += 1
|
||||
end
|
||||
elsif @homework.homework_type == 1 #匿评作业
|
||||
if @homework.homework_type == 1 #匿评作业
|
||||
sheet1.row(0).concat([l(:excel_user_id),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_mail),l(:excel_homework_name),
|
||||
l(:excel_t_score),l(:excel_ta_score), l(:excel_n_score),l(:excel_f_score),l(:excel_commit_time)])
|
||||
count_row = 1
|
||||
|
|
@ -568,7 +818,7 @@ class StudentWorkController < ApplicationController
|
|||
end
|
||||
elsif @homework.homework_type == 2 #编程作业
|
||||
sheet1.row(0).concat([l(:excel_user_id),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_mail),l(:excel_homework_name),
|
||||
l(:excel_t_score),l(:excel_ta_score), l(:excel_s_score),l(:excel_f_score),l(:excel_commit_time)])
|
||||
l(:excel_t_score),l(:excel_ta_score), l(:excel_s_score),l(:excel_n_score),l(:excel_f_score),l(:excel_commit_time)])
|
||||
count_row = 1
|
||||
items.each do |homework|
|
||||
sheet1[count_row,0]=homework.user.id
|
||||
|
|
@ -579,9 +829,10 @@ class StudentWorkController < ApplicationController
|
|||
sheet1[count_row,5] = homework.name
|
||||
sheet1[count_row,6] = homework.teacher_score.nil? ? l(:label_without_score) : format("%.2f",homework.teacher_score)
|
||||
sheet1[count_row,7] = homework.teaching_asistant_score.nil? ? l(:label_without_score) : format("%.2f",homework.teaching_asistant_score)
|
||||
sheet1[count_row,8] = homework.student_score.nil? ? l(:label_without_score) : format("%.2f",homework.student_score)
|
||||
sheet1[count_row,9] = homework.respond_to?("score") ? homework.score.nil? ? l(:label_without_score) : format("%.2f",homework.score) : l(:label_without_score)
|
||||
sheet1[count_row,10] = format_time(homework.created_at)
|
||||
sheet1[count_row,8] = homework.system_score.nil? ? l(:label_without_score) : format("%.2f",homework.system_score)
|
||||
sheet1[count_row,9] = homework.student_score.nil? ? l(:label_without_score) : format("%.2f",homework.student_score)
|
||||
sheet1[count_row,10] = homework.respond_to?("score") ? homework.score.nil? ? l(:label_without_score) : format("%.2f",homework.score) : l(:label_without_score)
|
||||
sheet1[count_row,11] = format_time(homework.created_at)
|
||||
count_row += 1
|
||||
end
|
||||
end
|
||||
|
|
@ -640,17 +891,19 @@ class StudentWorkController < ApplicationController
|
|||
xls_report.string
|
||||
end
|
||||
|
||||
def find_or_save_student_work
|
||||
student_work = @homework.student_works.where(user_id: User.current.id).first
|
||||
def find_or_save_student_work(is_test)
|
||||
student_work = StudentWork.where(homework_common_id: @homework.id, user_id: User.current.id).first
|
||||
if student_work.nil?
|
||||
@homework.student_works.build(
|
||||
name: params[:title],
|
||||
description: params[:src],
|
||||
user_id: User.current.id
|
||||
user_id: User.current.id,
|
||||
is_test: is_test
|
||||
)
|
||||
unless @homework.save
|
||||
logger.debug @homework.errors.full_messages
|
||||
else
|
||||
student_work = @homework.student_works.where(user_id: User.current.id).first
|
||||
student_work = StudentWork.where(homework_common_id: @homework.id, user_id: User.current.id).first
|
||||
end
|
||||
end
|
||||
student_work
|
||||
|
|
@ -679,4 +932,103 @@ class StudentWorkController < ApplicationController
|
|||
end
|
||||
JSON.parse(res.body)
|
||||
end
|
||||
|
||||
#成绩计算
|
||||
def set_final_score homework,student_work
|
||||
if homework && homework.homework_detail_manual
|
||||
if homework.homework_type != 2 #匿评作业
|
||||
if homework.teacher_priority == 1 #教师优先
|
||||
if student_work.teacher_score
|
||||
student_work.final_score = student_work.teacher_score
|
||||
else
|
||||
if student_work.teaching_asistant_score.nil?
|
||||
student_work.final_score = student_work.student_score
|
||||
elsif student_work.student_score.nil?
|
||||
student_work.final_score = student_work.teaching_asistant_score
|
||||
else
|
||||
ta_proportion = homework.homework_detail_manual.ta_proportion
|
||||
final_ta_score = BigDecimal.new("#{student_work.teaching_asistant_score}") * BigDecimal.new("#{ta_proportion}")
|
||||
final_s_score = BigDecimal.new("#{student_work.student_score}") * (BigDecimal.new('1.0') - BigDecimal.new("#{ta_proportion}"))
|
||||
final_score = final_ta_score + final_s_score
|
||||
student_work.final_score = format("%.2f",final_score.to_f)
|
||||
end
|
||||
end
|
||||
else #不考虑教师评分
|
||||
if student_work.teaching_asistant_score.nil?
|
||||
student_work.final_score = student_work.student_score
|
||||
elsif student_work.student_score.nil?
|
||||
student_work.final_score = student_work.teaching_asistant_score
|
||||
else
|
||||
ta_proportion = homework.homework_detail_manual.ta_proportion
|
||||
final_ta_score = BigDecimal.new("#{student_work.teaching_asistant_score}") * BigDecimal.new("#{ta_proportion}")
|
||||
final_s_score = BigDecimal.new("#{student_work.student_score}") * (BigDecimal.new('1.0') - BigDecimal.new("#{ta_proportion}"))
|
||||
final_score = final_ta_score + final_s_score
|
||||
student_work.final_score = format("%.2f",final_score.to_f)
|
||||
end
|
||||
end
|
||||
elsif homework.homework_type == 2 && homework.homework_detail_programing #编程作业-----设定:系统评分必定不为空
|
||||
if homework.teacher_priority == 1 #教师优先
|
||||
if student_work.teacher_score
|
||||
student_work.final_score = student_work.teacher_score
|
||||
else
|
||||
if student_work.teaching_asistant_score.nil? #教辅未评分
|
||||
if student_work.student_score.nil?
|
||||
student_work.final_score = student_work.system_score
|
||||
else
|
||||
ta_proportion = homework.homework_detail_programing.ta_proportion + homework.homework_detail_manual.ta_proportion / 2
|
||||
final_sy_score = BigDecimal.new("#{student_work.system_score || 0}") * BigDecimal.new("#{ta_proportion}")
|
||||
final_st_score = BigDecimal.new("#{student_work.student_score}") * (BigDecimal.new('1.0') - BigDecimal.new("#{ta_proportion}"))
|
||||
final_score = final_sy_score + final_st_score
|
||||
student_work.final_score = format("%.2f",final_score.to_f)
|
||||
end
|
||||
elsif student_work.student_score.nil? #学生未评分
|
||||
if student_work.teaching_asistant_score.nil?
|
||||
student_work.final_score = student_work.system_score
|
||||
else
|
||||
ta_proportion = homework.homework_detail_programing.ta_proportion + (1.0 - homework.homework_detail_manual.ta_proportion - homework.homework_detail_programing.ta_proportion) / 2
|
||||
final_sy_score = BigDecimal.new("#{student_work.system_score || 0}") * BigDecimal.new("#{ta_proportion}")
|
||||
final_ts_score = BigDecimal.new("#{student_work.teaching_asistant_score}") * (BigDecimal.new('1.0') - BigDecimal.new("#{ta_proportion}"))
|
||||
final_score = final_sy_score + final_ts_score
|
||||
student_work.final_score = format("%.2f",final_score.to_f)
|
||||
end
|
||||
else
|
||||
final_sy_score = BigDecimal.new("#{student_work.system_score || 0}") * BigDecimal.new("#{homework.homework_detail_programing.ta_proportion}")
|
||||
final_ts_score = BigDecimal.new("#{student_work.teaching_asistant_score}") * BigDecimal.new("#{homework.homework_detail_manual.ta_proportion}")
|
||||
final_st_score = BigDecimal.new("#{student_work.student_score}") * (BigDecimal.new('1.0') - BigDecimal.new("#{homework.homework_detail_programing.ta_proportion}") - BigDecimal.new("#{homework.homework_detail_manual.ta_proportion}"))
|
||||
final_score = final_sy_score + final_ts_score + final_st_score
|
||||
student_work.final_score = format("%.2f",final_score.to_f)
|
||||
end
|
||||
end
|
||||
else #不考虑教师评分
|
||||
if student_work.teaching_asistant_score.nil? #教辅未评分
|
||||
if student_work.student_score.nil?
|
||||
student_work.final_score = student_work.system_score
|
||||
else
|
||||
ta_proportion = homework.homework_detail_programing.ta_proportion + homework.homework_detail_manual.ta_proportion / 2
|
||||
final_sy_score = BigDecimal.new("#{student_work.system_score || 0}") * BigDecimal.new("#{ta_proportion}")
|
||||
final_st_score = BigDecimal.new("#{student_work.student_score}") * (BigDecimal.new('1.0') - BigDecimal.new("#{ta_proportion}"))
|
||||
final_score = final_sy_score + final_st_score
|
||||
student_work.final_score = format("%.2f",final_score.to_f)
|
||||
end
|
||||
elsif student_work.student_score.nil? #学生未评分
|
||||
if student_work.teaching_asistant_score.nil?
|
||||
student_work.final_score = student_work.system_score
|
||||
else
|
||||
ta_proportion = homework.homework_detail_programing.ta_proportion + (1.0 - homework.homework_detail_manual.ta_proportion - homework.homework_detail_programing.ta_proportion) / 2
|
||||
final_sy_score = BigDecimal.new("#{student_work.system_score || 0}") * BigDecimal.new("#{ta_proportion}")
|
||||
final_ts_score = BigDecimal.new("#{student_work.teaching_asistant_score}") * (BigDecimal.new('1.0') - BigDecimal.new("#{ta_proportion}"))
|
||||
final_score = final_sy_score + final_ts_score
|
||||
student_work.final_score = format("%.2f",final_score.to_f)
|
||||
end
|
||||
else
|
||||
final_sy_score = BigDecimal.new("#{student_work.system_score || 0}") * BigDecimal.new("#{homework.homework_detail_programing.ta_proportion}")
|
||||
final_ts_score = BigDecimal.new("#{student_work.teaching_asistant_score}") * BigDecimal.new("#{homework.homework_detail_manual.ta_proportion}")
|
||||
final_st_score = BigDecimal.new("#{student_work.student_score}") * (BigDecimal.new('1.0') - BigDecimal.new("#{homework.homework_detail_programing.ta_proportion}") - BigDecimal.new("#{homework.homework_detail_manual.ta_proportion}"))
|
||||
final_score = final_sy_score + final_ts_score + final_st_score
|
||||
student_work.final_score = format("%.2f",final_score.to_f)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
class SubfieldSubdomainDirsController < ApplicationController
|
||||
def update
|
||||
@org_subfield = OrgSubfield.find(params[:org_subfield_id])
|
||||
if @org_subfield.subfield_subdomain_dir
|
||||
@org_subfield.subfield_subdomain_dir.update_attribute(:name, :params[:sub_dir_name])
|
||||
else
|
||||
SubfieldSubdomainDir.create(:org_subfield_id => @org_subfield.id, :name => params[:sub_dir_name])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,97 @@
|
|||
class SystemMessagesController < ApplicationController
|
||||
|
||||
# before_filter :message_author, :only => [:show]
|
||||
#
|
||||
# def message_author
|
||||
# if(!User.current.logged? && !token.nil?)
|
||||
#
|
||||
# User.current =try_to_autologin1
|
||||
# end
|
||||
# if @system_messages
|
||||
# render_403 :message => :notice_not_authorized_message
|
||||
# else
|
||||
# deny_access
|
||||
# end
|
||||
# end
|
||||
|
||||
def index
|
||||
@system_messages = SystemMessage.all
|
||||
end
|
||||
|
||||
# def show
|
||||
# @system_messages = SystemMessage.find(params[:id])
|
||||
# end
|
||||
|
||||
# GET /products/new
|
||||
# def new
|
||||
# @product = Product.new
|
||||
# end
|
||||
|
||||
# GET /products/1/edit
|
||||
# def edit
|
||||
# end
|
||||
|
||||
# POST /products
|
||||
# POST /products.json
|
||||
def create
|
||||
unless User.current.admin?
|
||||
render_403
|
||||
return
|
||||
end
|
||||
@system_messages = SystemMessage.new
|
||||
@system_messages.description = params[:system_message][:description]
|
||||
@system_messages.subject = params[:system_message][:subject]
|
||||
@system_messages.user_id = User.current.id
|
||||
# @system_messages.save_attachments(params[:attachments])
|
||||
respond_to do |format|
|
||||
if @system_messages.save
|
||||
format.html {redirect_to user_system_messages_path(User.current)}
|
||||
flash[:notice] = l(:notice_successful_message)
|
||||
else
|
||||
if params[:system_messages][:description].empty?
|
||||
flash[:error] = l(:label_content_blank_fail)
|
||||
else
|
||||
flash[:error] = l(:label_admin_message_fail)
|
||||
end
|
||||
format.html {redirect_to admin_messages_path}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# PATCH/PUT /products/1
|
||||
# PATCH/PUT /products/1.json
|
||||
# def update
|
||||
# respond_to do |format|
|
||||
# if @product.update(product_params)
|
||||
# format.html { redirect_to @product, notice: 'Product was successfully updated.' }
|
||||
# format.json { render :show, status: :ok, location: @product }
|
||||
# else
|
||||
# format.html { render :edit }
|
||||
# format.json { render json: @product.errors, status: :unprocessable_entity }
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
|
||||
# DELETE /products/1
|
||||
# DELETE /products/1.json
|
||||
# def destroy
|
||||
# @system_messages.destroy
|
||||
# respond_to do |format|
|
||||
# format.html { redirect_to products_url, notice: 'Product was successfully destroyed.' }
|
||||
# format.json { head :no_content }
|
||||
# end
|
||||
# end
|
||||
|
||||
# private
|
||||
# # Use callbacks to share common setup or constraints between actions.
|
||||
# def set_product
|
||||
# @product = Product.find(params[:id])
|
||||
# end
|
||||
#
|
||||
# # Never trust parameters from the scary internet, only allow the white list through.
|
||||
# def message_params
|
||||
# params.require(:admin_system_messages).permit(:content)
|
||||
# end
|
||||
|
||||
|
||||
end
|
||||
|
|
@ -15,6 +15,7 @@ class TagsController < ApplicationController
|
|||
include ContestsHelper
|
||||
include ActsAsTaggableOn::TagsHelper
|
||||
include TagsHelper
|
||||
include FilesHelper
|
||||
helper :projects
|
||||
helper :courses
|
||||
helper :tags
|
||||
|
|
@ -226,10 +227,281 @@ class TagsController < ApplicationController
|
|||
@tag_list = get_course_tag_list @course
|
||||
@select_tag_name = params[:select_tag_name]
|
||||
end
|
||||
|
||||
if @obj && @object_flag == '6' && @obj.container.kind_of?(Project)
|
||||
@project = @obj.container
|
||||
@tag_list = get_course_tag_list @project
|
||||
@select_tag_name = params[:select_tag_name]
|
||||
end
|
||||
|
||||
if @obj && @object_flag == '6' && @obj.container.kind_of?(OrgSubfield)
|
||||
@org_subfield = @obj.container
|
||||
@tag_list = get_org_subfield_tag_list @org_subfield
|
||||
@select_tag_name = params[:select_tag_name]
|
||||
end
|
||||
# end
|
||||
end
|
||||
end
|
||||
|
||||
#更新某个tag名称
|
||||
def update_tag_name
|
||||
@tag_name = params[:tagName]
|
||||
@rename_tag_name = params[:renameName]
|
||||
@taggable_id = params[:taggableId]
|
||||
@taggable_type = numbers_to_object_type(params[:taggableType])
|
||||
@course_id = params[:courseId]
|
||||
|
||||
@rename_tag = (ActsAsTaggableOn::Tag.find_by_name(@rename_tag_name)) #查找重命名后的tag
|
||||
@tag_id = (ActsAsTaggableOn::Tag.find_by_name(@tag_name)).id #重命名前的tag_id
|
||||
@taggings = ActsAsTaggableOn::Tagging.find_by_tag_id_and_taggable_id_and_taggable_type(@tag_id,@taggable_id,@taggable_type) unless @taggable_id.blank?
|
||||
@obj = get_object(@taggable_id,params[:taggableType]) unless @taggable_id.blank?
|
||||
if @taggable_id.blank? #如果没有传tag_id,那么直接更新tag_name就好了。但是要防止 重命名后的tag存在。
|
||||
if @course_id
|
||||
course = Course.find @course_id
|
||||
if course
|
||||
course.attachments.each do |attachment|
|
||||
taggings = ActsAsTaggableOn::Tagging.find_by_tag_id_and_taggable_id_and_taggable_type(@tag_id,attachment.id,attachment.class)
|
||||
if taggings
|
||||
taggings.delete
|
||||
attachment.tag_list.add(@rename_tag_name.split(","))
|
||||
attachment.save
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
if(@rename_tag.nil?) #这次命名的是新的tag
|
||||
|
||||
# 是否还有其他记录 引用了 tag_id
|
||||
@tagging = ActsAsTaggableOn::Tagging.where("tag_id = #{@tag_id}")
|
||||
# 如果taggings表中记录为 1 ,那么改变@tag_id对应的tag的名字
|
||||
if @tagging.count == 1
|
||||
@tag = ActsAsTaggableOn::Tag.find_by_id(@tag_id)
|
||||
@tag.update_attributes({:name=>@rename_tag_name})
|
||||
else #如果tagging表中的记录大于1,那么就要新增tag记录
|
||||
|
||||
unless @obj.nil?
|
||||
@obj.tag_list.add(@rename_tag_name.split(","))
|
||||
@obj.save
|
||||
end
|
||||
#删除原来的对应的taggings的记录
|
||||
unless @taggings.nil?
|
||||
@taggings.delete
|
||||
end
|
||||
end
|
||||
else #这是已有的tag
|
||||
# 更改taggings记录里的tag_id
|
||||
unless @taggings.nil?
|
||||
@taggings.update_attributes({:tag_id=>@rename_tag.id})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@obj_flag = params[:taggableType]
|
||||
if @obj && @obj_flag == '6' && @obj.container.kind_of?(Course)
|
||||
@course = @obj.container
|
||||
@tag_list = @tag_list = get_course_tag_list @course
|
||||
elsif @course_id
|
||||
@course = Course.find(@course_id)
|
||||
@tag_list = get_course_tag_list @course
|
||||
|
||||
#这里要引用FilesController里的逻辑了。将资源库当前的文件列表刷新一遍。
|
||||
@flag = params[:flag] || false
|
||||
sort = ""
|
||||
@sort = ""
|
||||
@order = ""
|
||||
@is_remote = false
|
||||
@isproject = false
|
||||
|
||||
sort = "#{Attachment.table_name}.created_on desc"
|
||||
|
||||
@containers = [ Course.includes(:attachments).reorder(sort).find(@course.id)]
|
||||
|
||||
show_attachments @containers
|
||||
elsif @obj && @obj_flag == '5'
|
||||
@forum = @obj
|
||||
end
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def update_project_tag_name
|
||||
@tag_name = params[:tagName]
|
||||
@rename_tag_name = params[:renameName]
|
||||
@taggable_id = params[:taggableId]
|
||||
@taggable_type = numbers_to_object_type(params[:taggableType])
|
||||
@project_id = params[:projectId]
|
||||
|
||||
@rename_tag = (ActsAsTaggableOn::Tag.find_by_name(@rename_tag_name)) #查找重命名后的tag
|
||||
@tag_id = (ActsAsTaggableOn::Tag.find_by_name(@tag_name)).id #重命名前的tag_id
|
||||
@taggings = ActsAsTaggableOn::Tagging.find_by_tag_id_and_taggable_id_and_taggable_type(@tag_id,@taggable_id,@taggable_type) unless @taggable_id.blank?
|
||||
@obj = get_object(@taggable_id,params[:taggableType]) unless @taggable_id.blank?
|
||||
if @taggable_id.blank? #如果没有传tag_id,那么直接更新tag_name就好了。但是要防止 重命名后的tag存在。
|
||||
if @project_id
|
||||
project = Project.find @project_id
|
||||
if project
|
||||
project.attachments.each do |attachment|
|
||||
taggings = ActsAsTaggableOn::Tagging.find_by_tag_id_and_taggable_id_and_taggable_type(@tag_id,attachment.id,attachment.class)
|
||||
if taggings
|
||||
taggings.delete
|
||||
attachment.tag_list.add(@rename_tag_name.split(","))
|
||||
attachment.save
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
if(@rename_tag.nil?) #这次命名的是新的tag
|
||||
|
||||
# 是否还有其他记录 引用了 tag_id
|
||||
@tagging = ActsAsTaggableOn::Tagging.where("tag_id = #{@tag_id}")
|
||||
# 如果taggings表中记录为 1 ,那么改变@tag_id对应的tag的名字
|
||||
if @tagging.count == 1
|
||||
@tag = ActsAsTaggableOn::Tag.find_by_id(@tag_id)
|
||||
@tag.update_attributes({:name=>@rename_tag_name})
|
||||
else #如果tagging表中的记录大于1,那么就要新增tag记录
|
||||
|
||||
unless @obj.nil?
|
||||
@obj.tag_list.add(@rename_tag_name.split(","))
|
||||
@obj.save
|
||||
end
|
||||
#删除原来的对应的taggings的记录
|
||||
unless @taggings.nil?
|
||||
@taggings.delete
|
||||
end
|
||||
end
|
||||
else #这是已有的tag
|
||||
# 更改taggings记录里的tag_id
|
||||
unless @taggings.nil?
|
||||
@taggings.update_attributes({:tag_id=>@rename_tag.id})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@obj_flag = params[:taggableType]
|
||||
if @obj && @obj_flag == '6' && @obj.container.kind_of?(Project)
|
||||
@project = @obj.container
|
||||
@tag_list = @tag_list = get_course_tag_list @project
|
||||
elsif @project_id
|
||||
@project = Project.find(@project_id)
|
||||
@tag_list = get_project_tag_list @project
|
||||
|
||||
#这里要引用FilesController里的逻辑了。将资源库当前的文件列表刷新一遍。
|
||||
@flag = params[:flag] || false
|
||||
sort = ""
|
||||
@sort = ""
|
||||
@order = ""
|
||||
@is_remote = false
|
||||
@isproject = false
|
||||
|
||||
sort = "#{Attachment.table_name}.created_on desc"
|
||||
|
||||
@containers = [ Project.includes(:attachments).reorder(sort).find(@project.id)]
|
||||
|
||||
show_attachments @containers
|
||||
elsif @obj && @obj_flag == '5'
|
||||
@forum = @obj
|
||||
end
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def update_org_subfield_tag_name
|
||||
@tag_name = params[:tagName]
|
||||
@rename_tag_name = params[:renameName]
|
||||
@taggable_id = params[:taggableId]
|
||||
@taggable_type = numbers_to_object_type(params[:taggableType])
|
||||
@rename_tag = (ActsAsTaggableOn::Tag.find_by_name(@rename_tag_name)) #查找重命名后的tag
|
||||
@tag_id = (ActsAsTaggableOn::Tag.find_by_name(@tag_name)).id #重命名前的tag_id
|
||||
@taggings = ActsAsTaggableOn::Tagging.find_by_tag_id_and_taggable_id_and_taggable_type(@tag_id,@taggable_id,@taggable_type) unless @taggable_id.blank?
|
||||
@obj = get_object(@taggable_id,params[:taggableType]) unless @taggable_id.blank?
|
||||
if @taggable_id.blank? #如果没有传tag_id,那么直接更新tag_name就好了。但是要防止 重命名后的tag存在。
|
||||
if params[:org_subfield_id]
|
||||
org_subfield = OrgSubfield.find params[:org_subfield_id]
|
||||
if org_subfield
|
||||
org_subfield.attachments.each do |attachment|
|
||||
taggings = ActsAsTaggableOn::Tagging.find_by_tag_id_and_taggable_id_and_taggable_type(@tag_id,attachment.id,attachment.class)
|
||||
if taggings
|
||||
taggings.delete
|
||||
attachment.tag_list.add(@rename_tag_name.split(","))
|
||||
attachment.save
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
if(@rename_tag.nil?) #这次命名的是新的tag
|
||||
|
||||
# 是否还有其他记录 引用了 tag_id
|
||||
@tagging = ActsAsTaggableOn::Tagging.where("tag_id = #{@tag_id}")
|
||||
# 如果taggings表中记录为 1 ,那么改变@tag_id对应的tag的名字
|
||||
if @tagging.count == 1
|
||||
@tag = ActsAsTaggableOn::Tag.find_by_id(@tag_id)
|
||||
@tag.update_attributes({:name=>@rename_tag_name})
|
||||
else #如果tagging表中的记录大于1,那么就要新增tag记录
|
||||
|
||||
unless @obj.nil?
|
||||
@obj.tag_list.add(@rename_tag_name.split(","))
|
||||
@obj.save
|
||||
end
|
||||
#删除原来的对应的taggings的记录
|
||||
unless @taggings.nil?
|
||||
@taggings.delete
|
||||
end
|
||||
end
|
||||
else #这是已有的tag
|
||||
# 更改taggings记录里的tag_id
|
||||
unless @taggings.nil?
|
||||
@taggings.update_attributes({:tag_id=>@rename_tag.id})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@obj_flag = params[:taggableType]
|
||||
if @obj && @obj_flag == '6' && @obj.container.kind_of?(OrgSubfield)
|
||||
@org_subfield = @obj.container
|
||||
@tag_list = @tag_list = get_org_subfield_tag_list @org_subfield
|
||||
elsif params[:org_subfield_id]
|
||||
@org_subfield = OrgSubfield.find(params[:org_subfield_id])
|
||||
@tag_list = get_org_subfield_tag_list @org_subfield
|
||||
|
||||
#这里要引用FilesController里的逻辑了。将资源库当前的文件列表刷新一遍。
|
||||
@flag = params[:flag] || false
|
||||
sort = ""
|
||||
@sort = ""
|
||||
@order = ""
|
||||
@is_remote = false
|
||||
@isproject = false
|
||||
|
||||
sort = "#{Attachment.table_name}.created_on desc"
|
||||
|
||||
@containers = [ OrgSubfield.includes(:attachments).reorder(sort).find(@org_subfield.id)]
|
||||
|
||||
show_attachments @containers
|
||||
elsif @obj && @obj_flag == '5'
|
||||
@forum = @obj
|
||||
end
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def show_attachments obj
|
||||
@attachments = []
|
||||
obj.each do |container|
|
||||
@attachments += container.attachments
|
||||
end
|
||||
@all_attachments = User.current.admin? ? @attachments : visable_attachemnts(@attachments)
|
||||
@limit = 10
|
||||
@feedback_count = @all_attachments.count
|
||||
@feedback_pages = Paginator.new @feedback_count, @limit, params['page']
|
||||
@offset ||= @feedback_pages.offset
|
||||
#@curse_attachments_all = @all_attachments[@offset, @limit]
|
||||
@obj_attachments = paginateHelper @all_attachments,10
|
||||
end
|
||||
|
||||
def tag_save
|
||||
@select_tag_name = params[:tag_for_save][:tag_name]
|
||||
@tags = params[:tag_for_save][:name]
|
||||
|
|
@ -274,6 +546,14 @@ class TagsController < ApplicationController
|
|||
@course = @obj.container
|
||||
@tag_list = @tag_list = get_course_tag_list @course
|
||||
end
|
||||
if @obj && @obj_flag == '6' && @obj.container.kind_of?(Project)
|
||||
@project = @obj.container
|
||||
@tag_list = @tag_list = get_project_tag_list @project
|
||||
end
|
||||
if @obj && @obj_flag == '6' && @obj.container.kind_of?(OrgSubfield)
|
||||
@org_subfield = @obj.container
|
||||
@tag_list = @tag_list = get_org_subfield_tag_list @org_subfield
|
||||
end
|
||||
respond_to do |format|
|
||||
format.js
|
||||
format.html
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -151,36 +151,113 @@ class WelcomeController < ApplicationController
|
|||
end
|
||||
|
||||
def search
|
||||
search_condition = params[:q]
|
||||
search_type = params[:search_type].to_sym unless search_condition.blank?
|
||||
search_by = params[:search_by]
|
||||
@name = params[:q]
|
||||
@search_type = params[:search_type]
|
||||
case params[:search_type]
|
||||
when 'all'
|
||||
@alls = Elasticsearch::Model.search({
|
||||
query: {
|
||||
multi_match: {
|
||||
query: @name,
|
||||
type:"most_fields",
|
||||
operator: "or",
|
||||
fields: ['login', 'firstname','lastname','name','description^0.5','filename','subject','content^0.5']
|
||||
}
|
||||
},
|
||||
highlight: {
|
||||
pre_tags: ['<span class="c_red">'],
|
||||
post_tags: ['</span>'],
|
||||
fields: {
|
||||
login: {},
|
||||
firstname: {},
|
||||
lastname: {},
|
||||
name:{},
|
||||
description:{},
|
||||
filename:{},
|
||||
subject:{},
|
||||
content:{}
|
||||
}
|
||||
}
|
||||
},[User,Course,Attachment,Project,Memo] ).page(params[:page] || 1).per(20).results
|
||||
when 'user'
|
||||
@users = User.search(@name).page(params[:page] || 1).per(20)
|
||||
when 'project'
|
||||
@projects = Project.search(@name).page(params[:page] || 1).per(20).results
|
||||
when 'course'
|
||||
@courses = Course.search(@name).page(params[:page] || 1).per(20).results
|
||||
when 'attachment'
|
||||
@attachments = Attachment.search(@name).page(params[:page] || 1).per(20).results
|
||||
when 'memo'
|
||||
@memos = Memo.search(@name).page(params[:page] || 1).per(20).results
|
||||
else
|
||||
@alls = Elasticsearch::Model.search({
|
||||
query: {
|
||||
multi_match: {
|
||||
query: @name,
|
||||
type:"most_fields",
|
||||
operator: "or",
|
||||
fields: ['login', 'firstname','lastname','name','description^0.5','filename','subject','content^0.5']
|
||||
}
|
||||
},
|
||||
highlight: {
|
||||
pre_tags: ['<span class="c_red">'],
|
||||
post_tags: ['</span>'],
|
||||
fields: {
|
||||
login: {},
|
||||
firstname: {},
|
||||
lastname: {},
|
||||
name:{},
|
||||
description:{},
|
||||
filename:{},
|
||||
subject:{},
|
||||
content:{}
|
||||
}
|
||||
}
|
||||
},[User,Course,Attachment,Project,Memo] ).page(params[:page] || 1).per(20).results
|
||||
|
||||
if search_type.nil? && params[:contests_search] && params[:name] != ""
|
||||
search_type = :contests
|
||||
search_condition = params[:name]
|
||||
end
|
||||
|
||||
@users_count = User.search(@name).results.total
|
||||
|
||||
@course_count = Course.search(@name).results.total
|
||||
@attach_count = Attachment.search(@name).results.total
|
||||
@project_count = Project.search(@name).results.total
|
||||
@memo_count = Memo.search(@name).results.total
|
||||
@total_count = Elasticsearch::Model.search({
|
||||
query: {
|
||||
multi_match: {
|
||||
query: @name,
|
||||
type:"most_fields",
|
||||
operator: "or",
|
||||
fields: ['login', 'firstname','lastname','name','description^0.5','filename','subject','content^0.5']
|
||||
}
|
||||
},
|
||||
highlight: {
|
||||
pre_tags: ['<span class="c_red">'],
|
||||
post_tags: ['</span>'],
|
||||
fields: {
|
||||
login: {},
|
||||
firstname: {},
|
||||
lastname: {},
|
||||
name:{},
|
||||
description:{},
|
||||
filename:{},
|
||||
subject:{},
|
||||
content:{}
|
||||
}
|
||||
}
|
||||
},[User,Course,Attachment,Project,Memo] ).results.total
|
||||
# search_type = params[:search_type].to_sym unless search_condition.blank?
|
||||
# search_by = params[:search_by]
|
||||
#
|
||||
# if search_type.nil? && params[:contests_search] && params[:name] != ""
|
||||
# search_type = :contests
|
||||
# search_condition = params[:name]
|
||||
# end
|
||||
|
||||
respond_to do |format|
|
||||
format.html{
|
||||
case search_type
|
||||
when :projects
|
||||
redirect_to projects_search_url(:name => search_condition,
|
||||
:project_type => Project::ProjectType_project)
|
||||
when :courses
|
||||
redirect_to courses_search_url(:name => search_condition)
|
||||
when :contests
|
||||
redirect_to contests_url(:name => search_condition)
|
||||
when :users
|
||||
redirect_to users_search_url(:name => search_condition,:search_by => search_by)
|
||||
when :users_teacher
|
||||
redirect_to users_search_url(:name => search_condition, :search_by => search_by, :role => :teacher)
|
||||
when :users_student
|
||||
redirect_to users_search_url(:name => search_condition, :search_by => search_by, :role => :student)
|
||||
else
|
||||
#redirect_to home_path, :alert => l(:label_sumbit_empty)
|
||||
(redirect_to signin_path, :notice => l(:label_sumbit_empty);return) #if params[:name].blank?
|
||||
end
|
||||
}
|
||||
format.js
|
||||
format.html{ render :layout=>'users_base'}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -82,14 +82,14 @@ class WikiController < ApplicationController
|
|||
@content = @page.content_for_version(params[:version])
|
||||
if User.current.allowed_to?(:export_wiki_pages, @project)
|
||||
if params[:format] == 'pdf'
|
||||
send_data(wiki_page_to_pdf(@page, @project), :type => 'application/pdf', :filename => "#{@page.title}.pdf")
|
||||
send_data(wiki_page_to_pdf(@page, @project), :type => 'application/pdf', :filename => filename_for_content_disposition("#{@page.title}.pdf") )
|
||||
return
|
||||
elsif params[:format] == 'html'
|
||||
export = render_to_string :action => 'export', :layout => false
|
||||
send_data(export, :type => 'text/html', :filename => "#{@page.title}.html")
|
||||
send_data(export, :type => 'text/html', :filename => filename_for_content_disposition("#{@page.title}.html"))
|
||||
return
|
||||
elsif params[:format] == 'txt'
|
||||
send_data(@content.text, :type => 'text/plain', :filename => "#{@page.title}.txt")
|
||||
send_data(@content.text, :type => 'text/plain', :filename => filename_for_content_disposition("#{@page.title}.txt") )
|
||||
return
|
||||
end
|
||||
end
|
||||
|
|
@ -264,7 +264,7 @@ class WikiController < ApplicationController
|
|||
end
|
||||
@page.destroy
|
||||
respond_to do |format|
|
||||
format.html { redirect_to project_wiki_index_url(@project) }
|
||||
format.html {redirect_to edit_project_wiki_page_url @project, @page.title}
|
||||
format.api { render_api_ok }
|
||||
end
|
||||
end
|
||||
|
|
@ -286,7 +286,7 @@ class WikiController < ApplicationController
|
|||
send_data(export, :type => 'text/html', :filename => "wiki.html")
|
||||
}
|
||||
format.pdf {
|
||||
send_data(wiki_pages_to_pdf(@pages, @project), :type => 'application/pdf', :filename => "#{@project.identifier}.pdf")
|
||||
send_data(wiki_pages_to_pdf(@pages, @project), :type => 'application/pdf', :filename => filename_for_content_disposition("#{@project.identifier}.pdf") )
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@
|
|||
class WordsController < ApplicationController
|
||||
include ApplicationHelper
|
||||
before_filter :find_user, :only => [:new, :create, :destroy, :more, :back]
|
||||
before_filter :require_login, :only => [:create_reply]
|
||||
|
||||
def create
|
||||
if params[:new_form][:user_message].size>0 && User.current.logged?
|
||||
unless params[:user_id].nil?
|
||||
|
|
@ -53,7 +55,14 @@ class WordsController < ApplicationController
|
|||
:notes => content,
|
||||
:is_readed => false}
|
||||
@jfm = add_reply_adapter options
|
||||
|
||||
@save_succ = true if @jfm.errors.empty?
|
||||
if @save_succ
|
||||
update_course_activity('JournalsForMessage',parent_id)
|
||||
update_user_activity('JournalsForMessage',parent_id)
|
||||
update_forge_activity('JournalsForMessage',parent_id)
|
||||
update_org_activity('JournalsForMessage',parent_id)
|
||||
update_principal_activity('JournalsForMessage',parent_id)
|
||||
end
|
||||
respond_to do |format|
|
||||
# format.html {
|
||||
# if @jfm.errors.empty?
|
||||
|
|
@ -63,10 +72,14 @@ class WordsController < ApplicationController
|
|||
# end
|
||||
# render 'test/index'
|
||||
# }
|
||||
format.js{
|
||||
@save_succ = true if @jfm.errors.empty?
|
||||
format.js {
|
||||
@reply_type = params[:reply_type]
|
||||
@user_activity_id = params[:user_activity_id]
|
||||
@activity = JournalsForMessage.find(parent_id)
|
||||
@is_activity = params[:is_activity]
|
||||
}
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def destroy
|
||||
|
|
@ -82,6 +95,15 @@ class WordsController < ApplicationController
|
|||
@user = User.find(@journal_destroyed.jour_id)
|
||||
@jours_count = @user.journals_for_messages.where('m_parent_id IS NULL').count
|
||||
@is_user = true
|
||||
elsif @journal_destroyed.jour_type == 'HomeworkCommon'
|
||||
@homework = HomeworkCommon.find @journal_destroyed.jour_id
|
||||
if params[:user_activity_id]
|
||||
@user_activity_id = params[:user_activity_id]
|
||||
else
|
||||
@user_activity_id = -1
|
||||
end
|
||||
@is_in_course = params[:is_in_course].to_i
|
||||
@course_activity = params[:course_activity].to_i
|
||||
end
|
||||
respond_to do |format|
|
||||
format.js
|
||||
|
|
@ -202,11 +224,19 @@ class WordsController < ApplicationController
|
|||
|
||||
#给用户留言
|
||||
def leave_user_message
|
||||
@user = User.find(params[:id])
|
||||
if params[:new_form][:user_message].size>0 && User.current.logged? && @user
|
||||
@user.add_jour(User.current, params[:new_form][:user_message])
|
||||
if User.current.logged?
|
||||
@user = User.find(params[:id])
|
||||
if params[:new_form][:content].size>0 && User.current.logged? && @user
|
||||
if params[:private] && params[:private] == '1'
|
||||
@user.journals_for_messages << JournalsForMessage.new(:user_id => User.current.id, :notes => params[:new_form][:content], :reply_id => 0, :status => true, :is_readed => false, :private => 1)
|
||||
else
|
||||
@user.add_jour(User.current, params[:new_form][:content])
|
||||
end
|
||||
end
|
||||
redirect_to feedback_path(@user)
|
||||
else
|
||||
render_403
|
||||
end
|
||||
redirect_to feedback_path(@user)
|
||||
end
|
||||
|
||||
# add by nwb
|
||||
|
|
@ -224,7 +254,39 @@ class WordsController < ApplicationController
|
|||
flash[:error] = feedback.errors.full_messages[0]
|
||||
redirect_to course_feedback_url(params[:id])
|
||||
end
|
||||
end
|
||||
|
||||
#作业的回复
|
||||
def leave_homework_message
|
||||
if User.current.logged?
|
||||
@user = User.current
|
||||
@homework_common = HomeworkCommon.find(params[:id]);
|
||||
if params[:homework_message].size>0 && User.current.logged? && @user
|
||||
feedback = HomeworkCommon.add_homework_jour(@user, params[:homework_message], params[:id])
|
||||
if (feedback.errors.empty?)
|
||||
if params[:asset_id]
|
||||
ids = params[:asset_id].split(',')
|
||||
update_kindeditor_assets_owner ids,feedback[:id],OwnerTypeHelper::JOURNALSFORMESSAGE
|
||||
end
|
||||
|
||||
update_course_activity(@homework_common.class,@homework_common.id)
|
||||
update_user_activity(@homework_common.class,@homework_common.id)
|
||||
update_org_activity(@homework_common.class,@homework_common.id)
|
||||
respond_to do |format|
|
||||
format.js{
|
||||
@user_activity_id = params[:user_activity_id]
|
||||
@is_in_course = params[:is_in_course]
|
||||
@course_activity = params[:course_activity]
|
||||
@homework_common_id = params[:homework_common_id]
|
||||
}
|
||||
end
|
||||
else
|
||||
flash[:error] = feedback.errors.full_messages[0]
|
||||
end
|
||||
end
|
||||
else
|
||||
render_403
|
||||
end
|
||||
end
|
||||
|
||||
def add_brief_introdution
|
||||
|
|
|
|||
|
|
@ -1,4 +1,8 @@
|
|||
#coding=utf-8
|
||||
|
||||
require "base64"
|
||||
require 'zip'
|
||||
|
||||
class ZipdownController < ApplicationController
|
||||
#查找项目(课程)
|
||||
before_filter :find_project_by_bid_id, :only => [:assort]
|
||||
|
|
@ -7,11 +11,17 @@ class ZipdownController < ApplicationController
|
|||
SAVE_FOLDER = "#{Rails.root}/files"
|
||||
OUTPUT_FOLDER = "#{Rails.root}/files/archiveZip"
|
||||
|
||||
#统一下载功能
|
||||
#统一下载功能
|
||||
def download
|
||||
if User.current.logged?
|
||||
begin
|
||||
send_file "#{OUTPUT_FOLDER}/#{params[:file]}", :filename => filename_for_content_disposition(params[:filename]), :type => detect_content_type(params[:file])
|
||||
if params[:base64file]
|
||||
file = Base64.decode64(params[:base64file])
|
||||
file = file.sub('*', '+')
|
||||
send_file "#{OUTPUT_FOLDER}/#{file}", :filename => filename_for_content_disposition(file), :type => detect_content_type(file)
|
||||
else
|
||||
send_file "#{OUTPUT_FOLDER}/#{params[:file]}", :filename => filename_for_content_disposition(params[:filename]), :type => detect_content_type(params[:file])
|
||||
end
|
||||
rescue => e
|
||||
render file: 'public/no_file_found.html'
|
||||
end
|
||||
|
|
@ -107,11 +117,17 @@ class ZipdownController < ApplicationController
|
|||
bid_homework_path, OUTPUT_FOLDER)
|
||||
}
|
||||
[{files:[out_file.file_path], count: 1, index: 1,
|
||||
real_file: out_file.file_path, file: File.basename(out_file.file_path),
|
||||
real_file: out_file.file_path,
|
||||
file: File.basename(out_file.file_path),
|
||||
base64file: encode64(File.basename(out_file.file_path)),
|
||||
size:(out_file.pack_size / 1024.0 / 1024.0).round(2)
|
||||
}]
|
||||
end
|
||||
|
||||
def encode64(str)
|
||||
Base64.encode64(str).sub('+', '*')
|
||||
end
|
||||
|
||||
def zip_homework_common homework_common
|
||||
bid_homework_path = []
|
||||
digests = []
|
||||
|
|
@ -129,7 +145,9 @@ class ZipdownController < ApplicationController
|
|||
bid_homework_path, OUTPUT_FOLDER)
|
||||
}
|
||||
[{files:[out_file.file_path], count: 1, index: 1,
|
||||
real_file: out_file.file_path, file: File.basename(out_file.file_path),
|
||||
real_file: out_file.file_path,
|
||||
file: File.basename(out_file.file_path),
|
||||
base64file: encode64(File.basename(out_file.file_path)),
|
||||
size:(out_file.pack_size / 1024.0 / 1024.0).round(2)
|
||||
}]
|
||||
end
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ module ApiHelper
|
|||
# 学生获取课程作业的状态
|
||||
def get_homework_status homework
|
||||
homework_status = ""
|
||||
if !homework.nil?
|
||||
if homework
|
||||
if homework.homework_type == 1 && homework.homework_detail_manual
|
||||
case homework.homework_detail_manual.comment_status
|
||||
when 1
|
||||
|
|
@ -180,7 +180,7 @@ module ApiHelper
|
|||
if timePassed < 0
|
||||
updateAtValue = "时间有问题"
|
||||
elsif timePassed < ONE_MINUTE
|
||||
updateAtValue = "一分钟前"
|
||||
updateAtValue = "1分钟前"
|
||||
elsif timePassed < ONE_HOUR
|
||||
timeIntoFormat = timePassed / ONE_MINUTE
|
||||
updateAtValue = timeIntoFormat.to_s + "分钟前"
|
||||
|
|
|
|||
|
|
@ -49,6 +49,50 @@ module ApplicationHelper
|
|||
end
|
||||
end
|
||||
|
||||
def link_to_user_version(version, options = {})
|
||||
return '' unless version && version.is_a?(Version)
|
||||
link_to_if version.visible?, format_version_name(version), { :controller => 'versions', :action => 'show', :id => version }, :class => " f16 fb c_dblue "
|
||||
end
|
||||
|
||||
# 判断课程是否为精品课程
|
||||
def is_excellent_course course
|
||||
(course.is_excellent? or course.excellent_option?) ? true : false
|
||||
end
|
||||
|
||||
# 判断课程对成员是否可见
|
||||
def visible_course?(course)
|
||||
(course.is_delete? or (!course.is_public? && !User.current.member_of_course?(course))) ? false : true
|
||||
end
|
||||
|
||||
# 获取项目/课程总分
|
||||
# 发布缺陷 4分 回复缺陷 1分 提交一次 4分 讨论帖子 2分 回复帖子 1分 发布新闻 1分
|
||||
def static_project_score obj
|
||||
score = obj.issue_num * 4 + obj.issue_journal_num + obj.changeset_num * 4 + obj.board_num * 2 + obj.board_message_num + obj.news_num + obj.attach_num * 5
|
||||
end
|
||||
|
||||
# 获取组织成员中文名字
|
||||
def get_org_member_role_name member
|
||||
case member.roles[0].name
|
||||
when 'orgManager'
|
||||
'管理人员'
|
||||
when 'orgMember'
|
||||
'组织成员'
|
||||
end
|
||||
end
|
||||
|
||||
# 判断组织左侧展开或者隐藏
|
||||
def is_hide_org_left obj
|
||||
if obj.nil?
|
||||
return true
|
||||
else
|
||||
if obj.hide == 0
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Time 2015-03-24 16:38:05
|
||||
# Author lizanle
|
||||
# Description after save后需要进行资源记录的更新
|
||||
|
|
@ -66,6 +110,50 @@ module ApplicationHelper
|
|||
end
|
||||
end
|
||||
|
||||
# 更新课程英雄榜得分
|
||||
# user传过来必须是学生
|
||||
def course_member_score(course_id,user_id,type)
|
||||
course_contributor_score = CourseContributorScore.where("course_id =? and user_id =?", course_id, user_id).first
|
||||
case type
|
||||
when "JournalForMessage"
|
||||
if course_contributor_score.nil?
|
||||
CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_num => 0, :message_reply_num => 0,
|
||||
:news_reply_num => 0, :resource_num => 0, :journal_num => 1, :journal_reply_num => 0, :total_score => 1)
|
||||
else
|
||||
score = course_contributor_score.journal_num + 1
|
||||
total_score = course_contributor_score.total_score + 1
|
||||
course_contributor_score.update_attributes(:journal_num => score, :total_score => total_score)
|
||||
end
|
||||
when "Message"
|
||||
if course_contributor_score.nil?
|
||||
CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_num => 2, :message_reply_num => 0,
|
||||
:news_reply_num => 0, :resource_num => 0, :journal_num => 0, :journal_reply_num => 0, :total_score => 2)
|
||||
else
|
||||
score = course_contributor_score.message_num + 2
|
||||
total_score = course_contributor_score.total_score + 2
|
||||
course_contributor_score.update_attributes(:message_num => score, :total_score => total_score)
|
||||
end
|
||||
when "MessageReply"
|
||||
if course_contributor_score.nil?
|
||||
CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_num => 0, :message_reply_num => 1,
|
||||
:news_reply_num => 0, :resource_num => 0, :journal_num => 0, :journal_reply_num => 0, :total_score => 1)
|
||||
else
|
||||
score = course_contributor_score.message_reply_num + 1
|
||||
total_score = course_contributor_score.total_score + 1
|
||||
course_contributor_score.update_attributes(:message_reply_num => score, :total_score => total_score)
|
||||
end
|
||||
when "NewReply"
|
||||
if course_contributor_score.nil?
|
||||
CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_num => 0, :message_reply_num => 0,
|
||||
:news_reply_num => 1, :resource_num => 0, :journal_num => 0, :journal_reply_num => 0, :total_score => 1)
|
||||
else
|
||||
score = course_contributor_score.news_reply_num + 1
|
||||
total_score = course_contributor_score.total_score + 1
|
||||
course_contributor_score.update_attributes(:news_reply_num => score, :total_score => total_score)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Added by young
|
||||
# Define the course menu's link class
|
||||
# 不是数组的转化成数组,然后判断当前menu_item是否在给定的列表
|
||||
|
|
@ -200,8 +288,10 @@ module ApplicationHelper
|
|||
subject = truncate(subject, :length => 60)
|
||||
end
|
||||
end
|
||||
if issue.status_id == 5
|
||||
if issue.status_id == 3
|
||||
s = link_to text, issue_path(issue), :class => "text_line_s", :title => title
|
||||
elsif issue.status_id == 5
|
||||
s = link_to text, issue_path(issue), :class => "text_line_s del_line", :title => title
|
||||
else
|
||||
s = link_to text, issue_path(issue), :class => "c_blue", :title => title
|
||||
end
|
||||
|
|
@ -609,6 +699,53 @@ module ApplicationHelper
|
|||
return @result
|
||||
end
|
||||
|
||||
# 判断版本库是否初始为gitlab
|
||||
def rep_is_gitlab?(project)
|
||||
rep = Repository.where("project_id =? and type =?", project, "Repository::Gitlab")
|
||||
return rep.blank? ? true :false
|
||||
end
|
||||
|
||||
# 获取Gitlab版本库提交总数
|
||||
def commit_count(project)
|
||||
g = Gitlab.client
|
||||
#add by hx
|
||||
if g.commits(project.gpid , :page=>200).count > 0
|
||||
count = 4020
|
||||
elsif g.commits(project.gpid , :page=>25).count==0
|
||||
count = count_commits(project.gpid , 0 , 25)
|
||||
elsif g.commits(project.gpid , :page=>50).count ==0
|
||||
count = count_commits(project.gpid , 25 , 50)+ 25 * 20
|
||||
elsif g.commits(project.gpid , :page=>75).count ==0
|
||||
count = count_commits(project.gpid , 50 , 75)+ 50 * 20
|
||||
elsif g.commits(project.gpid , :page=>100).count== 0
|
||||
count = count_commits(project.gpid , 75 , 100) + 75 * 20
|
||||
elsif g.commits(project.gpid , :page=>125).count==0
|
||||
count = count_commits(project.gpid , 100 , 125) + 100 * 20
|
||||
elsif g.commits(project.gpid , :page=>150).count==0
|
||||
count = count_commits(project.gpid , 125 , 150) + 125 * 20
|
||||
else
|
||||
count = count_commits(project.gpid , 150 ,200) + 150 * 20
|
||||
end
|
||||
end
|
||||
|
||||
#add by hx
|
||||
def count_commits(project_id , left , right)
|
||||
count = 0
|
||||
(left..right).each do |page|
|
||||
if $g.commits(project_id,:page => page).count == 0
|
||||
break
|
||||
else
|
||||
count = count + $g.commits(project_id,:page => page).count
|
||||
end
|
||||
end
|
||||
return count
|
||||
end
|
||||
|
||||
# 获取单一gitlab项目
|
||||
def gitlab_repository(project)
|
||||
rep = Repository.where("project_id =? and type =?", project.id,"Repository::Gitlab" ).first
|
||||
end
|
||||
|
||||
# 判断当前用户是否为项目管理员
|
||||
def is_project_manager?(user_id, project_id)
|
||||
@result = false
|
||||
|
|
@ -837,7 +974,17 @@ module ApplicationHelper
|
|||
first_page = FirstPage.find_by_page_type('project')
|
||||
if args.empty?
|
||||
title = @html_title || []
|
||||
title << @project.name if @project
|
||||
if @project
|
||||
title << @project.name
|
||||
elsif @course
|
||||
title << @course.name
|
||||
elsif @organization
|
||||
title << @organization.name
|
||||
elsif @user
|
||||
title << @user.login
|
||||
else
|
||||
title << User.current.login
|
||||
end
|
||||
if first_page.nil? || first_page.web_title.nil?
|
||||
title << Setting.app_title unless Setting.app_title == title.last
|
||||
else
|
||||
|
|
@ -1652,6 +1799,13 @@ module ApplicationHelper
|
|||
#
|
||||
def javascript_include_tag(*sources)
|
||||
options = sources.last.is_a?(Hash) ? sources.pop : {}
|
||||
|
||||
@sources ||= []
|
||||
sources = sources.delete_if do|source|
|
||||
@sources.include?(source)
|
||||
end
|
||||
@sources += sources
|
||||
|
||||
if plugin = options.delete(:plugin)
|
||||
sources = sources.map do |source|
|
||||
if plugin
|
||||
|
|
@ -1661,7 +1815,12 @@ module ApplicationHelper
|
|||
end
|
||||
end
|
||||
end
|
||||
super sources, options
|
||||
|
||||
if sources && !sources.empty?
|
||||
super(sources, options)
|
||||
else
|
||||
''
|
||||
end
|
||||
end
|
||||
|
||||
def content_for(name, content = nil, &block)
|
||||
|
|
@ -1805,6 +1964,23 @@ module ApplicationHelper
|
|||
s
|
||||
end
|
||||
|
||||
def get_user_identity identity
|
||||
s = ""
|
||||
case identity
|
||||
when 0
|
||||
s = '教师'
|
||||
when 1
|
||||
s = '学生'
|
||||
when 2
|
||||
s = '组织'
|
||||
when 3
|
||||
s= '开发者'
|
||||
else
|
||||
s = '学生'
|
||||
end
|
||||
s
|
||||
end
|
||||
|
||||
def get_memo
|
||||
@new_memo = Memo.new
|
||||
@public_forum = Forum.find(1) rescue ActiveRecord::RecordNotFound
|
||||
|
|
@ -1843,6 +2019,10 @@ module ApplicationHelper
|
|||
elsif attachment.container.is_a?(Course)
|
||||
course = attachment.container
|
||||
candown= User.current.member_of_course?(course) || (course.is_public==1 && attachment.is_public == 1)
|
||||
elsif attachment.container.is_a?(OrgSubfield)
|
||||
candown = true
|
||||
elsif attachment.container.is_a?(OrgDocumentComment)
|
||||
candown = true
|
||||
elsif (attachment.container.has_attribute?(:board) || attachment.container.has_attribute?(:board_id)) && attachment.container.board &&
|
||||
attachment.container.board.course
|
||||
course = attachment.container.board.course
|
||||
|
|
@ -1853,6 +2033,10 @@ module ApplicationHelper
|
|||
candown = true
|
||||
elsif attachment.container.class.to_s=="StudentWork"
|
||||
candown = true
|
||||
elsif attachment.container.class.to_s=="BlogComment" #博客资源允许下载
|
||||
candown = true
|
||||
elsif attachment.container.class.to_s=="Memo" #论坛资源允许下载
|
||||
candown = true
|
||||
elsif attachment.container.class.to_s == "User"
|
||||
candown = (attachment.is_public == 1 || attachment.is_public == true || attachment.author_id == User.current.id)
|
||||
elsif attachment.container_type == "Bid" && attachment.container && attachment.container.courses
|
||||
|
|
@ -2295,27 +2479,40 @@ module ApplicationHelper
|
|||
tag_list
|
||||
end
|
||||
|
||||
# 获取项目资源的Tag云
|
||||
def get_project_tag_list project
|
||||
all_attachments = project.attachments.select{|attachment| attachment.is_public? ||
|
||||
(attachment.container_type == "Project" && User.current.member_of?(project))||
|
||||
attachment.author_id == User.current.id
|
||||
}
|
||||
tag_list = attachment_tag_list all_attachments
|
||||
tag_list
|
||||
end
|
||||
|
||||
def get_org_subfield_tag_list org_subfield
|
||||
all_attachments = org_subfield.attachments.select{|attachment| attachment.is_public? ||
|
||||
(attachment.container_type == "OrgSubfield" && User.current.member_of_org?(org_subfield.organization))||
|
||||
attachment.author_id == User.current.id
|
||||
}
|
||||
tag_list = attachment_tag_list all_attachments
|
||||
tag_list
|
||||
end
|
||||
|
||||
#获取匿评相关连接代码
|
||||
def homework_anonymous_comment homework
|
||||
if homework.homework_type == 1 && homework.homework_detail_manual #匿评作业
|
||||
if Time.parse(homework.end_time.to_s).strftime("%Y-%m-%d") >= Time.now.strftime("%Y-%m-%d")
|
||||
link = "<span class='fr mr10 pr_join_span ' title='作业截止日期之前不可以启动匿评'>启动匿评</span>".html_safe
|
||||
elsif homework.student_works.count >= 2 #作业份数大于2
|
||||
case homework.homework_detail_manual.comment_status
|
||||
when 1
|
||||
link = link_to '启动匿评', alert_anonymous_comment_homework_common_path(homework), id: "#{homework.id}_start_anonymous_comment", remote: true, disable_with: '加载中...',:class => 'fr mr10 work_edit'
|
||||
when 2
|
||||
link = link_to '关闭匿评', alert_anonymous_comment_homework_common_path(homework), id: "#{homework.id}_stop_anonymous_comment", remote: true,:class => 'fr mr10 work_edit'
|
||||
when 3
|
||||
link = "<span class='fr pr_join_span mr10' title='匿评结束'>匿评结束</span>".html_safe
|
||||
end
|
||||
else
|
||||
link = "<span class='fr mr10 pr_join_span ' title='学生提交作业数大于2时才可以启动匿评'>启动匿评</span>".html_safe
|
||||
def homework_anonymous_comment (homework, is_in_course, user_activity_id = -1, course_activity = -1)
|
||||
if Time.parse(homework.end_time.to_s).strftime("%Y-%m-%d") >= Time.now.strftime("%Y-%m-%d")
|
||||
link = link_to "启动匿评","javascript:void(0)", :class => "postOptionLink", :title => "作业截止日期之前不可以启动匿评"
|
||||
elsif homework.student_works.count >= 2 && homework.homework_detail_manual#作业份数大于2
|
||||
case homework.homework_detail_manual.comment_status
|
||||
when 1
|
||||
link = link_to '启动匿评', alert_anonymous_comment_homework_common_path(homework,:is_in_course=>is_in_course,:user_activity_id=>user_activity_id,:course_activity=>course_activity), id: "#{homework.id}_start_anonymous_comment", remote: true, disable_with: '加载中...',:class => 'postOptionLink'
|
||||
when 2
|
||||
link = link_to '关闭匿评', alert_anonymous_comment_homework_common_path(homework,:is_in_course=>is_in_course,:user_activity_id=>user_activity_id,:course_activity=>course_activity), id: "#{homework.id}_stop_anonymous_comment", remote: true,:class => 'postOptionLink'
|
||||
when 3
|
||||
# link = link_to "匿评结束","javascript:void(0)", :class => "postOptionLink", :title => "匿评结束"
|
||||
end
|
||||
elsif homework.homework_type == 2 && homework.homework_detail_programing #编程作业作业
|
||||
link = "<span class='fr mr10 pr_join_span ' title='编程作业'>编程作业</span>".html_safe
|
||||
else
|
||||
link = "<span class='fr mr10 pr_join_span ' title='未开启匿评作业不可以启动匿评'>启动匿评</span>".html_safe
|
||||
link = link_to "启动匿评","javascript:void(0)", :class => "postOptionLink", :title => "学生提交作业数大于等于2时才可以启动匿评"
|
||||
end
|
||||
link
|
||||
end
|
||||
|
|
@ -2323,14 +2520,18 @@ module ApplicationHelper
|
|||
def student_new_homework homework
|
||||
work = cur_user_works_for_homework homework
|
||||
if work.nil?
|
||||
link_to l(:label_commit_homework), new_student_work_path(:homework => homework.id),:class => 'fr mr10 work_edit'
|
||||
link_to "提交作品", new_student_work_path(:homework => homework.id),:class => 'fr mr10 work_edit'
|
||||
else
|
||||
if homework.homework_type == 1 && homework.homework_detail_manual && homework.homework_detail_manual.comment_status != 1 #匿评作业,且作业状态不是在开启匿评之前
|
||||
"<span class='fr mr10 pr_join_span '>#{l(:label_edit_homework)}</span>".html_safe
|
||||
elsif homework.homework_type == 2 #编程作业不能修改作品
|
||||
"<span class='fr mr10 pr_join_span ' title='编程作业不可修改作品'>作品已交</span>".html_safe
|
||||
link_to "作品已交", "javascript:void(0);", :class => 'fr mr10 pr_join_span c_white', :title => "开启匿评后不可修改作品"
|
||||
elsif homework.homework_type == 2 #编程作业修改作品
|
||||
if homework.homework_detail_manual && homework.homework_detail_manual.comment_status != 1
|
||||
link_to "作品已交", "javascript:void(0);", :class => 'fr mr10 pr_join_span c_white', :title => "开启匿评后不可修改作品"
|
||||
else
|
||||
link_to "修改作品", new_student_work_path(:homework => homework.id),:class => 'fr mr10 work_edit'
|
||||
end
|
||||
else
|
||||
link_to l(:label_edit_homework), edit_student_work_path(work.id),:class => 'fr mr10 work_edit c_blue'
|
||||
link_to "修改作品", edit_student_work_path(work.id),:class => 'fr mr10 work_edit'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -2343,34 +2544,72 @@ module ApplicationHelper
|
|||
homework = default_opt[:homework]
|
||||
work = cur_user_works_for_homework homework
|
||||
if work.nil? && !is_teacher
|
||||
link_to "提交("+homework.student_works.count.to_s+")", new_student_work_path(:homework => homework.id), :class=> default_opt[:class]
|
||||
link_to "提交("+homework.student_works.count.to_s+")", new_student_work_path(:homework => homework.id,:host=> Setting.host_course), :class=> default_opt[:class]
|
||||
else
|
||||
link_to "提交("+homework.student_works.count.to_s+")", student_work_index_path(:homework => homework.id), :class=> default_opt[:class]
|
||||
link_to "提交("+homework.student_works.count.to_s+")", student_work_index_path(:homework => homework.id,:host=> Setting.host_course), :class=> default_opt[:class]
|
||||
end
|
||||
end
|
||||
|
||||
#根据传入作业确定显示为编辑作品还是新建作品,或者显示作品数量
|
||||
def user_for_homework_common homework,is_teacher
|
||||
if is_teacher #老师显示作品数量
|
||||
link_to "提交(#{homework.student_works.count})",student_work_index_path(:homework => homework.id),:class => "c_blue"
|
||||
else #学生显示提交作品、修改作品等按钮
|
||||
work = cur_user_works_for_homework homework
|
||||
if work.nil?
|
||||
link_to "提交作品", new_student_work_path(:homework => homework.id),:class => 'c_blue'
|
||||
else
|
||||
if homework.homework_type == 1 && homework.homework_detail_manual && homework.homework_detail_manual.comment_status != 1 #匿评作业,且作业状态不是在开启匿评之前
|
||||
link_to "修改作品", "", :class => 'c_blue', :title => "开启匿评后不可修改作品"
|
||||
elsif homework.homework_type == 2 #编程作业不能修改作品
|
||||
link_to "作品已交", student_work_index_path(:homework => homework.id),:class => 'c_blue',:title => "编程作业不可修改作品"
|
||||
if User.current.member_of_course?(homework.course)
|
||||
if is_teacher #老师显示作品数量
|
||||
link_to "作品(#{homework.student_works.count})",student_work_index_path(:homework => homework.id),:class => "c_blue"
|
||||
else #学生显示提交作品、修改作品等按钮
|
||||
work = cur_user_works_for_homework homework
|
||||
project = cur_user_projects_for_homework homework
|
||||
if work.nil? && Time.parse(homework.end_time.to_s).strftime("%Y-%m-%d") >= Time.now.strftime("%Y-%m-%d")
|
||||
if homework.homework_type ==3 && project.nil? && homework.homework_detail_group.base_on_project == 1
|
||||
link_to "提交作品(#{homework.student_works.count})","javascript:void(0)", :class => 'c_grey',:style=>"cursor:not-allowed",:title => '请先关联项目再提交作品'
|
||||
else
|
||||
link_to "提交作品(#{homework.student_works.count})", new_student_work_path(:homework => homework.id),:class => 'c_blue'
|
||||
end
|
||||
elsif work.nil? && Time.parse(homework.end_time.to_s).strftime("%Y-%m-%d") < Time.now.strftime("%Y-%m-%d")
|
||||
if homework.homework_type ==3 && project.nil? && homework.homework_detail_group.base_on_project == 1
|
||||
link_to "补交作品(#{homework.student_works.count})","javascript:void(0)", :class => 'c_grey',:style=>"cursor:not-allowed",:title => '请先关联项目再补交作品'
|
||||
else
|
||||
link_to "补交作品(#{homework.student_works.count})", new_student_work_path(:homework => homework.id),:class => 'c_red'
|
||||
end
|
||||
else
|
||||
link_to "修改作品", edit_student_work_path(work.id),:class => 'c_blue'
|
||||
if homework.homework_detail_manual && homework.homework_detail_manual.comment_status == 2 #匿评作业,且作业状态不是在开启匿评之前
|
||||
link_to "作品匿评", student_work_index_path(:homework => homework.id), :class => 'c_blue', :title => "开启匿评后不可修改作品"
|
||||
elsif homework.homework_detail_manual && homework.homework_detail_manual.comment_status == 3
|
||||
link_to "查看作品(#{homework.student_works.count})", student_work_index_path(:homework => homework.id), :class => 'c_blue', :title => "匿评已结束"
|
||||
elsif homework.homework_type == 2 && Time.parse(homework.end_time.to_s).strftime("%Y-%m-%d") >= Time.now.strftime("%Y-%m-%d")#编程作业不能修改作品
|
||||
link_to "修改作品(#{homework.student_works.count})", new_student_work_path(:homework => homework.id),:class => 'c_blue'
|
||||
elsif Time.parse(homework.end_time.to_s).strftime("%Y-%m-%d") >= Time.now.strftime("%Y-%m-%d") && work.user_id == User.current.id
|
||||
link_to "修改作品(#{homework.student_works.count})", edit_student_work_path(work.id),:class => 'c_blue'
|
||||
else
|
||||
link_to "查看作品(#{homework.student_works.count})", student_work_index_path(:homework => homework.id), :class => 'c_blue', :title => "作业截止后不可修改作品"
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
link_to "作品(#{homework.student_works.count})",student_work_index_path(:homework => homework.id),:class => "c_blue"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def relate_project homework,is_teacher,is_in_course,user_activity_id,course_activity
|
||||
if User.current.member_of_course?(homework.course)
|
||||
if is_teacher
|
||||
#link_to "已关联(#{homework.student_work_projects.count})",student_work_index_path(:homework => homework.id),:class => "c_blue"
|
||||
else
|
||||
projects = cur_user_projects_for_homework homework
|
||||
works = cur_user_works_for_homework homework
|
||||
if works.nil? && projects.nil?
|
||||
link_to "关联项目",new_student_work_project_student_work_index_path(:homework => homework.id,:is_in_course=>is_in_course,:user_activity_id=>user_activity_id,:course_activity=>course_activity),remote: true,:class=> 'c_blue', :title=> '请选择分组作业关联的项目'
|
||||
elsif works.nil?
|
||||
link_to "取消关联",cancel_relate_project_student_work_index_path(:homework => homework.id,:is_in_course=>is_in_course,:user_activity_id=>user_activity_id,:course_activity=>course_activity), :confirm => "您确定要取消关联吗?", remote: true,:class => "c_blue", :title=> '取消关联项目'
|
||||
else
|
||||
#link_to "已关联(#{homework.student_work_projects.count})",student_work_index_path(:homework => homework.id),:class => "c_blue"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def student_anonymous_comment homework
|
||||
if homework.homework_type == 1 && homework.homework_detail_manual
|
||||
if homework.homework_detail_manual
|
||||
case homework.homework_detail_manual.comment_status
|
||||
when 1
|
||||
"<span class='fr mr10 pr_join_span '>未开启匿评</span>".html_safe
|
||||
|
|
@ -2379,16 +2618,25 @@ module ApplicationHelper
|
|||
when 3
|
||||
"<span class='fr mr10 pr_join_span '>匿评已结束</span>".html_safe
|
||||
end
|
||||
elsif homework.homework_type == 0
|
||||
"<span class='fr mr10 pr_join_span '>未启用匿评</span>".html_safe
|
||||
elsif homework.homework_type == 2
|
||||
"<span class='fr mr10 pr_join_span '> 编程作业 </span>".html_safe
|
||||
end
|
||||
end
|
||||
|
||||
#获取当前用户在指定作业下提交的作业的集合
|
||||
def cur_user_works_for_homework homework
|
||||
homework.student_works.where("user_id = ?",User.current).first
|
||||
work = homework.student_works.where("user_id = ?",User.current).first
|
||||
if homework.homework_type == 3
|
||||
pro = homework.student_work_projects.where("user_id = #{User.current.id}").first
|
||||
if pro.nil? || pro.student_work_id == "" || pro.student_work_id.nil?
|
||||
work = nil
|
||||
else
|
||||
work = StudentWork.find pro.student_work_id
|
||||
end
|
||||
end
|
||||
work
|
||||
end
|
||||
#获取当前用户在指定作业下关联的项目的集合
|
||||
def cur_user_projects_for_homework homework
|
||||
homework.student_work_projects.where("user_id = ?",User.current).first
|
||||
end
|
||||
|
||||
def file_preview_tag(file, html_options={})
|
||||
|
|
@ -2397,6 +2645,12 @@ module ApplicationHelper
|
|||
end
|
||||
end
|
||||
|
||||
def file_preview_eye(file, html_options={})
|
||||
if %w(pdf pptx doc docx xls xlsx).any?{|x| file.filename.downcase.end_with?(x)}
|
||||
link_to '', download_named_attachment_path(file.id, file.filename, preview: true),html_options
|
||||
end
|
||||
end
|
||||
|
||||
#将文本内的/n转换为<br>
|
||||
def text_format text
|
||||
text.gsub("&","&").gsub("<","<").gsub(">",">").gsub("\n","<br/>").html_safe
|
||||
|
|
@ -2533,4 +2787,80 @@ int main(int argc, char** argv){
|
|||
true
|
||||
end
|
||||
end
|
||||
|
||||
def import_ke(default_opt={})
|
||||
opt = {enable_at: false, prettify: false, init_activity: false}.merge default_opt
|
||||
ss = ''
|
||||
|
||||
unless Setting.at_enabled?
|
||||
opt[:enable_at] = false
|
||||
end
|
||||
|
||||
ss += javascript_include_tag("/assets/kindeditor/kindeditor",'/assets/kindeditor/pasteimg')
|
||||
if opt[:enable_at]
|
||||
ss += javascript_include_tag('/assets/kindeditor/at/jquery.caret.min.js', '/assets/kindeditor/at/jquery.atwho.js', '/assets/kindeditor/at/config.js')
|
||||
ss += stylesheet_link_tag("/assets/kindeditor/at/jquery.atwho.css")
|
||||
end
|
||||
|
||||
if opt[:prettify]
|
||||
ss += javascript_include_tag 'prettify'
|
||||
ss += stylesheet_link_tag 'prettify'
|
||||
end
|
||||
|
||||
if opt[:init_activity]
|
||||
ss += javascript_include_tag "init_activity_KindEditor"
|
||||
end
|
||||
|
||||
ss.html_safe
|
||||
end
|
||||
|
||||
#课程动态的更新
|
||||
def update_course_activity type, id
|
||||
course_activity = CourseActivity.where("course_act_type=? and course_act_id =?", type.to_s, id).first
|
||||
if course_activity
|
||||
course_activity.updated_at = Time.now
|
||||
course_activity.save
|
||||
end
|
||||
end
|
||||
#首页动态更新
|
||||
def update_user_activity type, id
|
||||
user_activity = UserActivity.where("act_type=? and act_id =?", type.to_s, id).first
|
||||
if user_activity
|
||||
user_activity.updated_at = Time.now
|
||||
user_activity.save
|
||||
end
|
||||
end
|
||||
#项目动态更新
|
||||
def update_forge_activity type, id
|
||||
forge_activity = ForgeActivity.where("forge_act_type=? and forge_act_id=?", type.to_s, id).first
|
||||
if forge_activity
|
||||
forge_activity.updated_at = Time.now
|
||||
forge_activity.save
|
||||
end
|
||||
end
|
||||
#组织动态更新
|
||||
def update_org_activity type , id
|
||||
org_activity = OrgActivity.where("org_act_type=? and org_act_id =?", type.to_s, id).first
|
||||
if org_activity
|
||||
org_activity.updated_at = Time.now
|
||||
org_activity.save
|
||||
end
|
||||
end
|
||||
#个人动态更新
|
||||
def update_principal_activity type, id
|
||||
principal_activity = PrincipalActivity.where("principal_act_type=? and principal_act_id =?", type.to_s, id).first
|
||||
if principal_activity
|
||||
principal_activity.updated_at = Time.now
|
||||
principal_activity.save
|
||||
end
|
||||
end
|
||||
|
||||
#项目按更新时间排序
|
||||
def project_sort_update projects
|
||||
unless projects.empty?
|
||||
project_ids = '('+projects.map{|pro|pro.project_id}.join(',')+')'
|
||||
sort_projects = ForgeActivity.find_by_sql("SELECT MAX(updated_at) AS updated_at,user_id, project_id FROM forge_activities WHERE project_id IN #{project_ids} GROUP BY project_id ORDER BY MAX(updated_at) DESC")
|
||||
return sort_projects
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -96,6 +96,7 @@ module AttachmentsHelper
|
|||
end
|
||||
false
|
||||
end
|
||||
|
||||
#判断项目project中是否包含课件attachment,project中引用了attachment也算作包含
|
||||
def project_contains_attachment? project,attachment
|
||||
project.attachments.each do |att|
|
||||
|
|
|
|||
|
|
@ -0,0 +1,2 @@
|
|||
module BlogCommentsHelper
|
||||
end
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
module BlogsHelper
|
||||
end
|
||||
|
|
@ -11,6 +11,59 @@ module CoursesHelper
|
|||
#StudentRoles = [5, 10]
|
||||
#AllPeople = StudentRoles+TeacherRoles
|
||||
## return people count
|
||||
|
||||
|
||||
# 推荐的精品课程
|
||||
def excellent_course_recommend new_course
|
||||
q = "%#{new_course.name.strip}%"
|
||||
result = find_excelletn_course(q, new_course)
|
||||
end
|
||||
|
||||
# 查询符合条件的精品课程
|
||||
# 用新课程名去匹配精品课程中按课程名和Tag名
|
||||
def find_excelletn_course keywords, current_course
|
||||
# 获取tag匹配结果ID
|
||||
a_tags = []
|
||||
# kc = keywords.to_a
|
||||
Course.visible.where("is_excellent =?", 1).each do |ec|
|
||||
if ec.tags.any?{|value| current_course.name.include?(value.to_s)}
|
||||
a_tags << ec.id
|
||||
end
|
||||
end
|
||||
# sql = "SELECT distinct c.* FROM `courses` c, tags t, taggings ts where t.id = ts.tag_id and ts.taggable_id = c.id and c.is_excellent = 1 and is_delete = 0 and
|
||||
# ts.taggable_type = 'Course' and t.name like '%#{keywords}%'"
|
||||
# a_tags = Course.find_by_sql(sql).select{|course| course.is_public ==1 unless User.current.member_of_course?(course)}
|
||||
# 通过elastic结果获取精品课程
|
||||
a_courses = []
|
||||
#courses = Course.search(keywords)
|
||||
#courses.each do |c|
|
||||
# a_courses << c.id
|
||||
#end
|
||||
a_courses << a_tags unless a_tags.length == 0
|
||||
# 课程本身不能搜索显示自己
|
||||
excellent_ids = a_courses.flatten.uniq.delete_if{|i| i == current_course.id}
|
||||
limit = 5 - excellent_ids.length.to_i
|
||||
sql = "SELECT distinct c.id FROM course_activities cs, courses c where cs.course_id = c.id
|
||||
and c.is_excellent =1 and c.id != #{current_course.id} order by cs.updated_at desc;"
|
||||
default_ecourse_ids = Course.find_by_sql(sql).flatten
|
||||
# REDO:时间紧,待优化
|
||||
default_ids =[]
|
||||
default_ecourse_ids.each do |de|
|
||||
default_ids << de.id
|
||||
end
|
||||
default_ids = default_ids - excellent_ids
|
||||
#default_ecourse = Course.where("id is not in (?)", ids).find_by_sql(sql).flatten.delete_if{|i| i == current_course.id}.flatten
|
||||
arr_result = excellent_ids << default_ids
|
||||
arr_result = arr_result.flatten.first(5)
|
||||
return arr_result
|
||||
# 过滤条件:精品课程、本身不在搜索范围
|
||||
#e_courses = Course.where("is_excellent =? and id in (?)",1, arr_result).where("id !=?", current_course.id)
|
||||
end
|
||||
|
||||
# 判断精品课程是否可见,非课程成员无法查看私有课程
|
||||
def visible_excellent_course obj
|
||||
# if course.is_pu
|
||||
end
|
||||
|
||||
# 返回x项目成员数量,即roles表中定义的所有成员
|
||||
def projectCount project
|
||||
|
|
@ -25,6 +78,10 @@ module CoursesHelper
|
|||
# searchTeacherAndAssistant(project).count
|
||||
end
|
||||
|
||||
def show_nav?(count)
|
||||
count == 0 ? true : false
|
||||
end
|
||||
|
||||
#课程模块需要展示的模块
|
||||
def course_model
|
||||
@nav_dispaly_course_all_label = 1
|
||||
|
|
@ -36,7 +93,7 @@ module CoursesHelper
|
|||
#生成课程老师成员链接
|
||||
def course_teacher_link teacher_num
|
||||
if User.current.member_of_course?(@course) || User.current.admin?
|
||||
link_to "#{teacher_num}", course_member_path(@course, :role => 1), :class => 'info_foot_num c_blue'
|
||||
link_to "#{teacher_num}", course_member_path(@course, :role => 1), :class => 'info_foot_num c_blue', :id => 'teacher_number'
|
||||
else
|
||||
content_tag 'span',teacher_num, :class => 'info_foot_num c_blue'
|
||||
end
|
||||
|
|
@ -45,7 +102,7 @@ module CoursesHelper
|
|||
#生成课程学生列表连接
|
||||
def course_student_link student_num
|
||||
if (User.current.logged? && @course.open_student == 1) || (User.current.member_of_course?(@course)) || User.current.admin?
|
||||
link_to "#{student_num}", course_member_path(@course, :role => 2), :class => 'info_foot_num c_blue'
|
||||
link_to "#{student_num}", course_member_path(@course, :role => 2), :class => 'info_foot_num c_blue', :id => "student_number"
|
||||
else
|
||||
content_tag 'span',student_num, :class => 'info_foot_num c_blue'
|
||||
end
|
||||
|
|
@ -503,8 +560,10 @@ module CoursesHelper
|
|||
#课程实践年份下拉框
|
||||
def course_time_option year
|
||||
type = []
|
||||
month = Time.now.month
|
||||
now_year = year.nil? ? Time.now.year : (Time.now.year <= year ? Time.now.year : year)
|
||||
for i in (now_year..now_year + 10)
|
||||
year = month < 3 && now_year >=Time.now.year ? now_year - 1 : now_year
|
||||
for i in (year..year + 10)
|
||||
option = []
|
||||
option << i
|
||||
option << i
|
||||
|
|
@ -628,10 +687,10 @@ module CoursesHelper
|
|||
|
||||
#重启、关闭课程按钮
|
||||
def set_course_time course
|
||||
id = "finish_course_#{course.id}"
|
||||
linkPath = course_endTime_timeout?(course) ? restartcourse_course_path(course) : finishcourse_course_path(course, format: :js)
|
||||
desc = course_endTime_timeout?(course) ? l(:label_course_reload) : l(:label_course_closed)
|
||||
link_to "<span class='pr_close'></span>#{desc}".html_safe, linkPath, :remote => true, :method => :post, :id => id, :confirm => l(:label_course_closed_tips, :desc => desc), :class => "pr_join_a"
|
||||
# id = "finish_course_#{course.id}"
|
||||
# linkPath = course_endTime_timeout?(course) ? restartcourse_course_path(course) : finishcourse_course_path(course, format: :js)
|
||||
# desc = course_endTime_timeout?(course) ? l(:label_course_reload) : l(:label_course_closed)
|
||||
# link_to "<span class='pr_close'></span>#{desc}".html_safe, linkPath, :remote => true, :method => :post, :id => id, :confirm => l(:label_course_closed_tips, :desc => desc), :class => "pr_join_a"
|
||||
end
|
||||
|
||||
#加入课程、退出课程按钮
|
||||
|
|
@ -733,4 +792,26 @@ module CoursesHelper
|
|||
end
|
||||
desc.html_safe
|
||||
end
|
||||
|
||||
# 学生按作业总分排序,取前8个
|
||||
def hero_homework_score(course, score_sort_by)
|
||||
sql_select = "SELECT members.*,(
|
||||
SELECT SUM(student_works.final_score)
|
||||
FROM student_works,homework_commons
|
||||
WHERE student_works.homework_common_id = homework_commons.id
|
||||
AND homework_commons.course_id = #{course.id}
|
||||
AND student_works.user_id = members.user_id
|
||||
) AS score
|
||||
FROM members
|
||||
JOIN students_for_courses
|
||||
ON students_for_courses.student_id = members.user_id AND students_for_courses.course_id = members.course_id
|
||||
WHERE members.course_id = #{course.id} ORDER BY score #{score_sort_by} limit 9"
|
||||
homework_scores = Member.find_by_sql(sql_select)
|
||||
end
|
||||
|
||||
def contributor_course_scor(course_id)
|
||||
ccs = CourseContributorScore.where("course_id =?", course_id).order("total_score desc") .limit(9)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,153 @@
|
|||
# encoding: utf-8
|
||||
module ExerciseHelper
|
||||
|
||||
# 单选
|
||||
def sigle_selection_standard_answer(params)
|
||||
size = params.ord - 96
|
||||
if size > 0 # 小写字母答案
|
||||
answer = params.ord - 96
|
||||
else
|
||||
answer = params.ord - 64
|
||||
end
|
||||
end
|
||||
|
||||
# 多选
|
||||
def multiselect_standard_answer(params)
|
||||
size = params.ord - 96
|
||||
answer = []
|
||||
if size > 0 # 小写字母答案
|
||||
for i in 0..(params.length-1)
|
||||
answer << (params[i].ord - 96).to_s
|
||||
end
|
||||
else
|
||||
for i in 0..(params.length-1)
|
||||
answer << (params[i].ord - 64)
|
||||
end
|
||||
end
|
||||
answer = answer.sort
|
||||
answer.join("")
|
||||
end
|
||||
|
||||
#
|
||||
def fill_standart_answer(params, standart_answer)
|
||||
params.each do |param|
|
||||
standart_answer.answer_text = param.value
|
||||
standart_answer.save
|
||||
end
|
||||
end
|
||||
|
||||
# 获取多选的得分
|
||||
def get_mulscore(question, user)
|
||||
ecs = ExerciseAnswer.where("user_id =? and exercise_question_id =?", user.id, question.id)
|
||||
arr = []
|
||||
ecs.each do |ec|
|
||||
arr << ec.exercise_choice.choice_position
|
||||
end
|
||||
#arr = arr.sort
|
||||
str = arr.sort.join("")
|
||||
return str
|
||||
end
|
||||
|
||||
# 判断用户是否已经提交了问卷
|
||||
# status 为0的时候是用户点击试卷。为1表示用户已经提交
|
||||
def has_commit_exercise?(exercise_id, user_id)
|
||||
pu = ExerciseUser.where("exercise_id=? and user_id=? and status=?",exercise_id, user_id, true)
|
||||
if pu.empty?
|
||||
false
|
||||
else
|
||||
true
|
||||
end
|
||||
end
|
||||
|
||||
# 判断学生是否点击过问卷,点击则为他保存一个记录,记录start_at
|
||||
def has_click_exercise?(exercise_id, user_id)
|
||||
pu = ExerciseUser.where("exercise_id=? and user_id=? and status=?",exercise_id, user_id, false)
|
||||
if pu.empty?
|
||||
false
|
||||
else
|
||||
true
|
||||
end
|
||||
end
|
||||
|
||||
def convert_to_char(str)
|
||||
result = ""
|
||||
length = str.length
|
||||
unless str.nil?
|
||||
if length === 1
|
||||
result += (str.to_i + 64).chr
|
||||
return result
|
||||
elsif length > 1
|
||||
for i in 0...length
|
||||
result += (str[i].to_i + 64).chr
|
||||
end
|
||||
return result
|
||||
end
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
||||
def get_current_score exercise
|
||||
score = 0
|
||||
unless exercise.nil?
|
||||
exercise.exercise_questions.each do |exercise_question|
|
||||
unless exercise_question.question_score.nil?
|
||||
score += exercise_question.question_score
|
||||
end
|
||||
end
|
||||
return score
|
||||
end
|
||||
return score
|
||||
end
|
||||
|
||||
def answer_be_selected?(answer,user)
|
||||
pv = answer.exercise_answers.where("#{ExerciseAnswer.table_name}.user_id = #{user.id} ")
|
||||
if !pv.nil? && pv.count > 0
|
||||
true
|
||||
else
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
#获取未完成的题目
|
||||
def get_uncomplete_question exercise,user
|
||||
all_questions = exercise.exercise_questions
|
||||
uncomplete_question = []
|
||||
all_questions.each do |question|
|
||||
answers = get_user_answer(question, user)
|
||||
if answers.empty?
|
||||
uncomplete_question << question
|
||||
end
|
||||
end
|
||||
uncomplete_question
|
||||
end
|
||||
|
||||
#获取文本题答案
|
||||
def get_anwser_vote_text(question_id,user_id)
|
||||
pv = ExerciseAnswer.find_by_exercise_question_id_and_user_id(question_id,user_id)
|
||||
if pv.nil?
|
||||
''
|
||||
else
|
||||
pv.answer_text
|
||||
end
|
||||
end
|
||||
|
||||
# 获取当前学生回答问题的答案
|
||||
def get_user_answer(question,user)
|
||||
user_answer = question.exercise_answers.where("#{ExerciseAnswer.table_name}.user_id = #{user.id}")
|
||||
user_answer
|
||||
end
|
||||
|
||||
# 获取问题的标准答案
|
||||
def get_user_standard_answer(question,user)
|
||||
if question.question_type == 3
|
||||
standard_answer =[]
|
||||
question.exercise_standard_answers.each do |answer|
|
||||
standard_answer << answer.answer_text
|
||||
end
|
||||
else
|
||||
standard_answer = question.exercise_standard_answers
|
||||
end
|
||||
standard_answer
|
||||
end
|
||||
|
||||
end
|
||||
|
|
@ -67,6 +67,17 @@ module FilesHelper
|
|||
s.html_safe
|
||||
end
|
||||
|
||||
#带勾选框的组织资源栏目列表
|
||||
def org_subfields_check_box_tags(name,org_subfields,attachment)
|
||||
s = ''
|
||||
org_subfields.each do |org_subfield|
|
||||
if !org_subfield.attachments.include?attachment
|
||||
s << "<label>#{ check_box_tag name, org_subfield.id, false, :id => nil } #{h org_subfield.name}</label><br/>"
|
||||
end
|
||||
end
|
||||
s.html_safe
|
||||
end
|
||||
|
||||
#判断用户是否拥有不包含当前资源的课程,需用户在该课程中角色为教师且该课程属于当前学期或下一学期
|
||||
def has_course? user,file
|
||||
result = false
|
||||
|
|
@ -113,7 +124,8 @@ module FilesHelper
|
|||
if attachment.is_public? ||
|
||||
(attachment.container_type == "Project" && User.current.member_of?(attachment.project)) ||
|
||||
(attachment.container_type == "Course" && User.current.member_of_course?(Course.find(attachment.container_id)))||
|
||||
attachment.author_id == User.current.id
|
||||
attachment.author_id == User.current.id ||
|
||||
attachment.container_type == "OrgSubfield"
|
||||
result << attachment
|
||||
end
|
||||
end
|
||||
|
|
@ -140,6 +152,12 @@ module FilesHelper
|
|||
result << attachment
|
||||
end
|
||||
end
|
||||
elsif obj.is_a?(OrgSubfield)
|
||||
attachments.each do |attachment|
|
||||
if attachment.is_public? || (attachment.container_type == "OrgSubfield" && attachment.container_id == obj.id )|| attachment.author_id == User.current.id
|
||||
result << attachment
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
result
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
# encoding: utf-8
|
||||
include UsersHelper
|
||||
module HomeworkCommonHelper
|
||||
#迟交扣分下拉框
|
||||
def late_penalty_option
|
||||
|
|
@ -56,12 +57,12 @@ module HomeworkCommonHelper
|
|||
end
|
||||
|
||||
#根据传入作业确定跳转到开启匿评还是关闭匿评功能
|
||||
def alert_anonyoms_path homework,homework_detail_manual
|
||||
def alert_anonyoms_path homework,homework_detail_manual,user_activity_id,is_in_course,course_activity
|
||||
link = ""
|
||||
if homework_detail_manual.comment_status == 1
|
||||
link = start_anonymous_comment_homework_common_url homework.id
|
||||
link = start_anonymous_comment_homework_common_url homework.id,:user_activity_id=>user_activity_id,:is_in_course=>is_in_course,:course_activity=>course_activity
|
||||
elsif homework_detail_manual.comment_status == 2
|
||||
link = stop_anonymous_comment_homework_common_url homework.id
|
||||
link = stop_anonymous_comment_homework_common_url homework.id,:user_activity_id=>user_activity_id,:is_in_course=>is_in_course,:course_activity=>course_activity
|
||||
end
|
||||
link
|
||||
end
|
||||
|
|
|
|||
|
|
@ -119,7 +119,7 @@ module JournalsHelper
|
|||
content << textAreailizable(journal, :notes)
|
||||
css_classes = "wiki"
|
||||
css_classes << " editable" if editable
|
||||
content_tag('div', content.html_safe, :id => "journal-#{journal.id}-notes", :class => css_classes ,:style => "width:510px")
|
||||
content_tag('div', content.html_safe, :id => "journal-#{journal.id}-notes", :class => css_classes)
|
||||
end
|
||||
|
||||
def link_to_in_place_notes_editor(text, field_id, url, options={})
|
||||
|
|
|
|||
|
|
@ -0,0 +1,2 @@
|
|||
module OrgCoursesHelper
|
||||
end
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
module OrgDocumentCommentHelper
|
||||
end
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
module OrgMemberHelper
|
||||
include ApplicationHelper
|
||||
def find_user_not_in_current_org_by_name org
|
||||
if params[:q] && params[:q].lstrip.rstrip != ""
|
||||
scope = Principal.active.sorted.not_member_of_org(org).like(params[:q])
|
||||
else
|
||||
scope = []
|
||||
end
|
||||
principals = paginateHelper scope,10
|
||||
s = content_tag('ul', project_member_check_box_tags_ex('membership[user_ids][]', principals), :class => 'mb5', :id => 'principals')
|
||||
links = pagination_links_full(@obj_pages, @obj_count, :per_page_links => false, :remote => false, :flag => true){|text, parameters, options|
|
||||
link_to text, org_member_autocomplete_org_member_index_path(parameters.merge(:q => params[:q],:flag => true,:org=> org, :format => 'js')), :remote => true
|
||||
}
|
||||
s + content_tag('ul', links,:class => 'wlist',:style=>'float:left !important', :id => "org_member_pagination_links" )
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
module OrgProjectsHelper
|
||||
end
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
module OrgSubfieldsHelper
|
||||
include OrganizationsHelper
|
||||
end
|
||||
|
|
@ -1,2 +1,31 @@
|
|||
module EnterprisesHelper
|
||||
# encoding: utf-8
|
||||
module OrganizationsHelper
|
||||
include ApplicationHelper
|
||||
|
||||
|
||||
def find_user_not_in_current_org_by_name org
|
||||
if params[:q] && params[:q].lstrip.rstrip != ""
|
||||
scope = Principal.active.sorted.not_member_of_org(org).like(params[:q])
|
||||
else
|
||||
scope = []
|
||||
end
|
||||
principals = paginateHelper scope,10
|
||||
s = content_tag('ul', project_member_check_box_tags_ex('membership[user_ids][]', principals), :class => 'mb5', :id => 'principals')
|
||||
links = pagination_links_full(@obj_pages, @obj_count, :per_page_links => false, :remote => false, :flag => true){|text, parameters, options|
|
||||
link_to text, org_member_autocomplete_org_member_index_path( parameters.merge(:q => params[:q],:flag => true,:org=>org, :format => 'js')), :remote => true
|
||||
}
|
||||
s + content_tag('ul', links,:class => 'wlist',:style=>'float:left !important', :id => "org_member_pagination_links" )
|
||||
end
|
||||
|
||||
def get_default_name field
|
||||
case field.name
|
||||
when 'activity' then
|
||||
return '动态'
|
||||
when 'course' then
|
||||
return '课程'
|
||||
when 'project' then
|
||||
return '项目'
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -7,4 +7,5 @@ module OwnerTypeHelper
|
|||
BID = 6
|
||||
JOURNALSFORMESSAGE = 7
|
||||
HOMEWORKCOMMON = 8
|
||||
BLOGCOMMENT=9
|
||||
end
|
||||
|
|
@ -20,11 +20,6 @@ module ProjectScoreHelper
|
|||
project.documents.count
|
||||
end
|
||||
|
||||
#代码提交数量
|
||||
def changesets_num project
|
||||
project.changesets.count
|
||||
end
|
||||
|
||||
#讨论区帖子数量
|
||||
def board_message_num project
|
||||
board_message_count = 0
|
||||
|
|
|
|||
|
|
@ -18,6 +18,8 @@
|
|||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
include AvatarHelper
|
||||
include StudentWorkHelper
|
||||
include ApiHelper
|
||||
module ProjectsHelper
|
||||
def link_to_version(version, options = {})
|
||||
return '' unless version && version.is_a?(Version)
|
||||
|
|
@ -75,6 +77,63 @@ module ProjectsHelper
|
|||
return result
|
||||
end
|
||||
|
||||
# 项目类型
|
||||
def project_type_select
|
||||
type = []
|
||||
option1 = []
|
||||
option1 << l(:label_development_team)
|
||||
option1 << l(:label_development_team)
|
||||
option2 = []
|
||||
option2 << l(:label_research_group)
|
||||
option2 << l(:label_research_group)
|
||||
option3 = []
|
||||
option3 << l(:label_friend_organization)
|
||||
option3 << l(:label_friend_organization)
|
||||
type << option1
|
||||
type << option2
|
||||
type << option3
|
||||
type
|
||||
end
|
||||
|
||||
# 项目类型描述
|
||||
def project_newtype_descrption
|
||||
case params
|
||||
when 1
|
||||
value = l(:label_type_des_development)
|
||||
when 2
|
||||
value = l(:label_type_des_research)
|
||||
when 3
|
||||
value = l(:label_type_des_friend)
|
||||
end
|
||||
end
|
||||
|
||||
# 被邀请成员的状态
|
||||
def status_for_ivitied(ivite_list, project)
|
||||
if ivite_list.user.member_of?(project)
|
||||
value = "已经加入了项目!"
|
||||
elsif ivite_list.user.active?
|
||||
value = "邀请已发送,等待用户加入!"
|
||||
else
|
||||
value = "邀请已发送,等待用户激活账号!"
|
||||
end
|
||||
end
|
||||
|
||||
# 获取新增gitlab版本库
|
||||
def rep_gitlab(project)
|
||||
rep = Repository.where("project_id =? and type =?", project, "Repository::Gitlab")
|
||||
end
|
||||
|
||||
# 获取新项目的版本库地址
|
||||
def rep_gitlab_url(project)
|
||||
gitlab_address = Redmine::Configuration['gitlab_address']
|
||||
url = gitlab_address.to_s+"/"+project.owner.to_s+"/"+ rep_gitlab(project).first.identifier+"."+"git"
|
||||
end
|
||||
|
||||
# # 获取Forge历史版本库
|
||||
def rep_forge(project)
|
||||
rep = Repository.where("project_id =? and type =?", project, "Repository::Git")
|
||||
end
|
||||
|
||||
# Added by young
|
||||
def course_settings_tabs
|
||||
tabs = [{:name => 'info', :action => :edit_project, :partial => 'projects/edit', :label => :label_information_plural, :course=>'1'},
|
||||
|
|
|
|||
|
|
@ -25,6 +25,21 @@ module RepositoriesHelper
|
|||
end
|
||||
PROJECT_PATH_CUT = 40
|
||||
REPO_IP_ADDRESS = Setting.host_repository
|
||||
REPO_GITLAB_ADDRESS = "git.trustie.net"
|
||||
|
||||
# 某个成员不能拥有同名版本库,不同的成员可以创建同名版本库
|
||||
def is_sigle_identifier?(user_id, iden)
|
||||
projects = Project.where("user_id =?",user_id)
|
||||
identifiers = []
|
||||
projects.each do |project|
|
||||
# 只针对gitlab类型的,git类型的后期清掉
|
||||
repository = Repository.where("project_id =? and type =?", project.id, "Repository::Gitlab").first
|
||||
if repository
|
||||
identifiers << repository.identifier
|
||||
end
|
||||
end
|
||||
identifiers.include?(iden) ? false :true
|
||||
end
|
||||
|
||||
def format_revision(revision)
|
||||
if revision.respond_to? :format_identifier
|
||||
|
|
@ -34,12 +49,21 @@ module RepositoriesHelper
|
|||
end
|
||||
end
|
||||
|
||||
def repository_creater rep
|
||||
repository_creater = User.find_by_login(rep.login) unless rep.login.nil?
|
||||
end
|
||||
|
||||
def truncate_at_line_break(text, length = 255)
|
||||
if text
|
||||
text.gsub(%r{^(.{#{length}}[^\n]*)\n.+$}m, '\\1...')
|
||||
end
|
||||
end
|
||||
|
||||
def user_commit_rep(mail)
|
||||
user = User.find_by_mail(mail)
|
||||
#user.nil? ? User.find(2) : User.find_by_mail(mail)
|
||||
end
|
||||
|
||||
def render_properties(properties)
|
||||
unless properties.nil? || properties.empty?
|
||||
content = ''
|
||||
|
|
|
|||
|
|
@ -0,0 +1,2 @@
|
|||
module ShieldActivitiesHelper
|
||||
end
|
||||
|
|
@ -2,17 +2,16 @@
|
|||
include UserScoreHelper
|
||||
|
||||
module StudentWorkHelper
|
||||
#获取当前用户的项目列表
|
||||
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)
|
||||
projects = User.current.projects.visible
|
||||
not_have_project = []
|
||||
not_have_project << Setting.please_chose
|
||||
not_have_project << "请选择关联项目"
|
||||
not_have_project << 0
|
||||
type = []
|
||||
type << not_have_project
|
||||
projects.each do |project|
|
||||
if project != nil
|
||||
if project
|
||||
option = []
|
||||
option << project.name
|
||||
option << project.id
|
||||
|
|
@ -100,4 +99,42 @@ module StudentWorkHelper
|
|||
end
|
||||
result
|
||||
end
|
||||
|
||||
#教辅评分比例下拉框
|
||||
def ta_proportion_option
|
||||
type = []
|
||||
i = 0
|
||||
while i <= 100
|
||||
option = []
|
||||
option << i.to_s + "%"
|
||||
option << i.to_f / 100
|
||||
type << option
|
||||
i += 10
|
||||
end
|
||||
type
|
||||
end
|
||||
|
||||
def ta_proportion_option_to num
|
||||
type = []
|
||||
i = 0
|
||||
while i <= num
|
||||
option = []
|
||||
option << i.to_s + "%"
|
||||
option << i.to_f / 100
|
||||
type << option
|
||||
i += 10
|
||||
end
|
||||
type
|
||||
end
|
||||
|
||||
def revise_attachment_status homework, attach
|
||||
date = Time.parse(format_time(attach.created_on.to_s)).strftime("%Y-%m-%d")
|
||||
status = ""
|
||||
if homework.homework_detail_manual && ((homework.anonymous_comment == 0 &&homework.homework_detail_manual.evaluation_start.to_s <= date) || (homework.anonymous_comment == 1 && homework.end_time < date))
|
||||
status = "此时其他同学作品已公开"
|
||||
else
|
||||
status = "此时其他同学作品尚未公开"
|
||||
end
|
||||
return status
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
module SubfieldSubdomainDirsHelper
|
||||
end
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
module SystemMessagesHelper
|
||||
end
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
module TagsHelper
|
||||
include StoresHelper
|
||||
include CoursesHelper
|
||||
# 通过 id和type获取对象
|
||||
def get_object(obj_id,obj_type)
|
||||
@obj = nil
|
||||
|
|
@ -62,6 +63,37 @@ module TagsHelper
|
|||
|
||||
end
|
||||
|
||||
#判断课程course中是否包含课件attachment,course中引用了attachment也算作包含
|
||||
def course_contains_attachment? course,attachment
|
||||
course.attachments.each do |att|
|
||||
if att.id == attachment.id || (!att.copy_from.nil? && !attachment.copy_from.nil? && att.copy_from == attachment.copy_from) || att.copy_from == attachment.id || att.id == attachment.copy_from
|
||||
return true
|
||||
end
|
||||
end
|
||||
false
|
||||
end
|
||||
|
||||
#判断项目project中是否包含课件attachment,project中引用了attachment也算作包含
|
||||
def project_contains_attachment? project,attachment
|
||||
project.attachments.each do |att|
|
||||
if att.id == attachment.id || (!att.copy_from.nil? && !attachment.copy_from.nil? && att.copy_from == attachment.copy_from) || att.copy_from == attachment.id || att.id == attachment.copy_from
|
||||
return true
|
||||
end
|
||||
end
|
||||
false
|
||||
end
|
||||
|
||||
#判断用户是否拥有不包含当前资源的课程,需用户在该课程中角色为教师且该课程属于当前学期或下一学期
|
||||
def has_course? user,file
|
||||
result = false
|
||||
user.courses.each do |course|
|
||||
if !course_contains_attachment?(course,file) && is_course_teacher(User.current,course) && course_in_current_or_next_term(course)
|
||||
return true
|
||||
end
|
||||
end
|
||||
result
|
||||
end
|
||||
|
||||
# 判断用户是否是贴吧的管理员
|
||||
# add by chenmin
|
||||
def is_forum_manager?(user_id,forum_id)
|
||||
|
|
|
|||
|
|
@ -49,9 +49,52 @@ module UsersHelper
|
|||
'批改附件'
|
||||
when 'Principal'
|
||||
'用户资源'
|
||||
when 'OrgSubfield'
|
||||
'组织资源'
|
||||
end
|
||||
end
|
||||
|
||||
def title_for_message type
|
||||
case type
|
||||
when nil
|
||||
'消息'
|
||||
when 'unviewed'
|
||||
'未读消息'
|
||||
when 'apply'
|
||||
'用户申请'
|
||||
when 'system_messages'
|
||||
'系统消息'
|
||||
when 'homework'
|
||||
'作业消息'
|
||||
when 'course_message'
|
||||
'课程讨论'
|
||||
when 'course_news'
|
||||
'课程通知'
|
||||
when 'poll'
|
||||
'课程问卷'
|
||||
when 'issue'
|
||||
'项目任务'
|
||||
when 'forge_message'
|
||||
'项目讨论'
|
||||
when 'forge_news'
|
||||
'项目新闻'
|
||||
when 'forum'
|
||||
'贴吧帖子'
|
||||
when 'user_feedback'
|
||||
'用户留言'
|
||||
end
|
||||
end
|
||||
|
||||
# 统计未读消息数
|
||||
def unviewed_message(user)
|
||||
course_count = CourseMessage.where("user_id =? and viewed =?", user, 0).count
|
||||
forge_count = ForgeMessage.where("user_id =? and viewed =?", user, 0).count
|
||||
user_feedback_count = UserFeedbackMessage.where("user_id =? and viewed =?", user, 0).count
|
||||
user_memo_count = MemoMessage.where("user_id =? and viewed =?", user, 0).count
|
||||
at_count = user.at_messages.where(viewed: false).count
|
||||
messages_count = course_count + forge_count + user_feedback_count + user_memo_count + at_count
|
||||
end
|
||||
|
||||
def user_mail_notification_options(user)
|
||||
user.valid_notification_options.collect {|o| [l(o.last), o.first]}
|
||||
end
|
||||
|
|
@ -429,8 +472,8 @@ module UsersHelper
|
|||
def get_issue_des_update(journal)
|
||||
no_html = "message"
|
||||
arr = details_to_strings(journal.details, no_html)
|
||||
unless journal.notes.empty?
|
||||
arr << "留言内容:" + journal.notes
|
||||
unless journal.notes.blank?
|
||||
arr << journal.notes
|
||||
end
|
||||
str = ''
|
||||
arr.each { |item| str = str+item }
|
||||
|
|
@ -548,7 +591,7 @@ module UsersHelper
|
|||
option << "请选择发布作业的课程"
|
||||
option << -1
|
||||
type << option
|
||||
user.courses.select{|c| user.allowed_to?(:as_teacher,c)}.each do |course|
|
||||
user.courses.visible.where("is_delete =?", 0).select("courses.*,(SELECT MAX(created_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS a").order("a desc").select{|c| user.allowed_to?(:as_teacher,c)}.each do |course|
|
||||
option = []
|
||||
option << course.name+"("+course.time.to_s+course.term+")"
|
||||
option << course.id
|
||||
|
|
|
|||
|
|
@ -1,8 +1,21 @@
|
|||
class AppliedProject < ActiveRecord::Base
|
||||
attr_accessible :project_id, :user_id
|
||||
|
||||
belongs_to :user
|
||||
belongs_to :project
|
||||
belongs_to :user
|
||||
belongs_to :project
|
||||
has_many :forge_messages, :class_name => 'ForgeMessage', :as => :forge_message, :dependent => :destroy
|
||||
|
||||
after_create :send_appliled_message
|
||||
|
||||
def send_appliled_message
|
||||
# if MessageAll.where("message_type = '#{self.class.to_s}' and message_id = '#{self.id}'").first.nil?
|
||||
self.project.members.each do |m|
|
||||
if m.roles.first.to_s.include?("Manager")
|
||||
self.forge_messages << ForgeMessage.new(:user_id => m.user_id, :project_id => self.project_id, :viewed => false)
|
||||
end
|
||||
end
|
||||
# end
|
||||
end
|
||||
|
||||
#删除用户申请
|
||||
def self.deleteappiled(userid, projectid)
|
||||
|
|
@ -11,5 +24,4 @@ class AppliedProject < ActiveRecord::Base
|
|||
applied.destroy
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -0,0 +1,102 @@
|
|||
#coding=utf-8
|
||||
|
||||
class AtMessage < ActiveRecord::Base
|
||||
belongs_to :user
|
||||
belongs_to :sender, class_name: "User", foreign_key: "sender_id"
|
||||
attr_accessible :at_message, :container, :viewed, :user_id, :sender_id
|
||||
belongs_to :at_message, polymorphic: true
|
||||
belongs_to :container, polymorphic: true
|
||||
|
||||
has_many :message_alls, :class_name => 'MessageAll',:as =>:message, :dependent => :destroy
|
||||
validates :user_id, :sender_id, :at_message_id, :at_message_type, presence: true
|
||||
|
||||
after_create :add_user_message
|
||||
|
||||
scope :unviewed, ->(type, id){
|
||||
where(at_message_type: type, at_message_id:id, viewed: false)
|
||||
}
|
||||
|
||||
def viewed!
|
||||
update_attribute :viewed, true
|
||||
end
|
||||
|
||||
def at_valid?
|
||||
return true if at_message_type == 'Issue'
|
||||
return true if 'Journal' == at_message_type
|
||||
return true if 'JournalsForMessage' == at_message_type
|
||||
return true if 'Message' == at_message_type
|
||||
false
|
||||
end
|
||||
|
||||
def add_user_message
|
||||
if MessageAll.where(message_type: self.class.name,message_id: self.id).empty?
|
||||
self.message_alls << MessageAll.new(:user_id => self.user_id)
|
||||
end
|
||||
end
|
||||
|
||||
def subject
|
||||
case at_message_type
|
||||
when "Issue"
|
||||
"新建问题: " + at_message.subject
|
||||
when "Journal"
|
||||
"问题留言: " + at_message.journalized.subject
|
||||
when 'Message'
|
||||
if(at_message.topic?)
|
||||
"发布新帖: "
|
||||
else
|
||||
"回复帖子: "
|
||||
end + at_message.subject
|
||||
when 'JournalsForMessage'
|
||||
"作业: #{at_message.jour.name} 中留言"
|
||||
else
|
||||
logger.error "error type: #{at_message_type}"
|
||||
end
|
||||
end
|
||||
|
||||
def description
|
||||
case at_message_type
|
||||
when "Issue"
|
||||
at_message.description
|
||||
when "Journal"
|
||||
at_message.notes
|
||||
when 'Message'
|
||||
at_message.content
|
||||
when "JournalsForMessage"
|
||||
at_message.notes
|
||||
else
|
||||
logger.error "error type: #{at_message_type}"
|
||||
end
|
||||
end
|
||||
|
||||
def author
|
||||
case at_message_type
|
||||
when "Issue"
|
||||
at_message.author
|
||||
when "Journal"
|
||||
at_message.user
|
||||
when 'Message'
|
||||
at_message.author
|
||||
when 'JournalsForMessage'
|
||||
at_message.user
|
||||
else
|
||||
logger.error "error type: #{at_message_type}"
|
||||
end
|
||||
end
|
||||
|
||||
def url
|
||||
case at_message_type
|
||||
when "Issue"
|
||||
{controller: :issues, action: :show, id: at_message}
|
||||
when "Journal"
|
||||
{controller: :issues, action: :show, id: at_message.journalized}
|
||||
when 'Message'
|
||||
{controller: :boards, action: :show, project_id: at_message.board.project, id: at_message.board}
|
||||
when 'JournalsForMessage'
|
||||
{controller: :homework_common, action: :index, course: at_message.jour.course_id}
|
||||
else
|
||||
logger.error "error type: #{at_message_type}"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
@ -17,11 +17,12 @@
|
|||
|
||||
require "digest/md5"
|
||||
require "fileutils"
|
||||
|
||||
require 'elasticsearch/model'
|
||||
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 :org_subfield, foreign_key: 'container_id', conditions: "attachements.container_type = 'OrgSubfield'"
|
||||
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"
|
||||
|
|
@ -31,6 +32,7 @@ class Attachment < ActiveRecord::Base
|
|||
has_many :course_acts, :class_name => 'CourseActivity',:as =>:course_act ,:dependent => :destroy
|
||||
# end
|
||||
include UserScoreHelper
|
||||
has_many :attachment_histories
|
||||
|
||||
validates :filename, presence: true, length: {maximum: 254}
|
||||
validates :author, presence: true
|
||||
|
|
@ -38,6 +40,18 @@ class Attachment < ActiveRecord::Base
|
|||
validates :description, length: {maximum: 254}
|
||||
validate :validate_max_file_size
|
||||
|
||||
#elasticsearch
|
||||
include Elasticsearch::Model
|
||||
#elasticsearch kaminari init
|
||||
Kaminari::Hooks.init
|
||||
Elasticsearch::Model::Response::Response.__send__ :include, Elasticsearch::Model::Response::Pagination::Kaminari
|
||||
settings index: { number_of_shards: 5 } do
|
||||
mappings dynamic: 'false' do
|
||||
indexes :filename, analyzer: 'smartcn',index_options: 'offsets'
|
||||
indexes :downloads, index:"not_analyzed",index_options: 'offsets'
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
acts_as_taggable
|
||||
acts_as_event :title => :filename,
|
||||
|
|
@ -73,10 +87,10 @@ class Attachment < ActiveRecord::Base
|
|||
cattr_accessor :thumbnails_storage_path
|
||||
@@thumbnails_storage_path = File.join(Rails.root, "tmp", "thumbnails")
|
||||
|
||||
before_save :files_to_final_location,:act_as_course_activity,:act_as_forge_activity
|
||||
after_create :office_conver, :be_user_score,:act_as_forge_activity
|
||||
after_update :office_conver, :be_user_score
|
||||
after_destroy :delete_from_disk,:down_user_score
|
||||
before_save :files_to_final_location,:act_as_course_activity
|
||||
after_create :office_conver, :be_user_score,:act_as_forge_activity,:create_attachment_ealasticsearch_index
|
||||
after_update :office_conver, :be_user_score,:update_attachment_ealasticsearch_index
|
||||
after_destroy :delete_from_disk,:down_user_score,:delete_attachment_ealasticsearch_index, :decrease_attchments_count
|
||||
|
||||
# add by nwb
|
||||
# 获取所有可公开的资源文件列表
|
||||
|
|
@ -92,7 +106,35 @@ class Attachment < ActiveRecord::Base
|
|||
" LEFT JOIN #{News.table_name} ON #{Attachment.table_name}.container_type='News' AND (#{News.table_name}.project_id in "+self.public_project_id + " OR #{News.table_name}.course_id in " + self.public_course_id + ")" +
|
||||
" LEFT JOIN #{HomeworkAttach.table_name} ON #{Attachment.table_name}.container_type='HomeworkAttach' AND #{HomeworkAttach.table_name}.bid_id in "+self.public_bid_id)
|
||||
}
|
||||
scope :indexable,lambda { where('is_public = 1 and ((container_type in ("Principal")) ' +
|
||||
'or (container_type = "Course" and container_id in( SELECT `courses`.id FROM `courses` WHERE (courses.status <> 9 AND courses.is_public = 1)) )'+
|
||||
'or (container_type = "Project" and container_id in(SELECT `projects`.id FROM `projects` WHERE (projects.status <> 9 AND projects.is_public = 1) ))' +')')} #用于elastic建索引的scope
|
||||
def self.search(query)
|
||||
__elasticsearch__.search(
|
||||
{
|
||||
query: {
|
||||
multi_match: {
|
||||
query: query,
|
||||
type:"most_fields",
|
||||
operator: "or",
|
||||
fields: ['filename']
|
||||
}
|
||||
},
|
||||
sort:{
|
||||
_score:{order:"desc"},
|
||||
downloads: {order:"desc"}
|
||||
|
||||
},
|
||||
highlight: {
|
||||
pre_tags: ['<span class="c_red">'],
|
||||
post_tags: ['</span>'],
|
||||
fields: {
|
||||
filename: {}
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
end
|
||||
# add by nwb
|
||||
# 公开的项目id列表
|
||||
def self.public_project_id
|
||||
|
|
@ -307,11 +349,18 @@ class Attachment < ActiveRecord::Base
|
|||
|
||||
# Deletes the file from the file system if it's not referenced by other attachments
|
||||
def delete_from_disk
|
||||
if Attachment.where("disk_filename = ? AND id <> ?", disk_filename, id).empty?
|
||||
#资源存在,且历史记录为0 且 该资源没有存在任何拷贝才能删除资源
|
||||
if Attachment.where("disk_filename = ? AND id <> ?", disk_filename, id).empty? && self.attachment_histories.count == 0 && Attachment.where('copy_from = ?',self.id) .count == 0
|
||||
delete_from_disk!
|
||||
end
|
||||
end
|
||||
|
||||
#有了历史记录的数据记录是不能被删除的。
|
||||
#true 能被删除 false 不能被删除
|
||||
def destroyable
|
||||
self.attachment_histories.count == 0
|
||||
end
|
||||
|
||||
# Returns file's location on disk
|
||||
def diskfile
|
||||
File.join(self.class.storage_path, disk_directory.to_s, disk_filename.to_s)
|
||||
|
|
@ -560,4 +609,56 @@ class Attachment < ActiveRecord::Base
|
|||
self.course_acts << CourseActivity.new(:user_id => self.author_id,:course_id => self.container_id)
|
||||
end
|
||||
end
|
||||
|
||||
def create_attachment_ealasticsearch_index
|
||||
if self.is_public == 1 && ( (self.container_type == 'Project' && Project.find(self.container_id).is_public == 1) ||
|
||||
( self.container_type == 'Course' && Course.find(self.container_id).is_public == 1) ||
|
||||
self.container_type == 'Principal')
|
||||
self.__elasticsearch__.index_document
|
||||
end
|
||||
end
|
||||
|
||||
def update_attachment_ealasticsearch_index
|
||||
if self.is_public == 1 && ( ((self.container_type == 'Project' or self.container_type == 'Version') && Project.find(self.container_id).is_public == 1) ||
|
||||
( self.container_type == 'Course' && Course.find(self.container_id).is_public == 1) ||
|
||||
self.container_type == 'Principal')
|
||||
begin
|
||||
self.__elasticsearch__.update_document
|
||||
rescue => e
|
||||
end
|
||||
else
|
||||
begin
|
||||
self.__elasticsearch__.delete_document
|
||||
rescue => e
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def delete_attachment_ealasticsearch_index
|
||||
begin
|
||||
self.__elasticsearch__.delete_document
|
||||
rescue => e
|
||||
end
|
||||
end
|
||||
|
||||
def decrease_attchments_count
|
||||
if self.container_type == "Project" && !self.project.project_score.nil?
|
||||
aatach_count = self.container.project_score.attach_num - 1
|
||||
self.container.project_score.update_attribute(:attach_num, aatach_count)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Delete the previous articles index in Elasticsearch
|
||||
# Attachment.__elasticsearch__.client.indices.delete index: Attachment.index_name rescue nil
|
||||
#
|
||||
# # Create the new index with the new mapping
|
||||
# Attachment.__elasticsearch__.client.indices.create \
|
||||
# index: Attachment.index_name,
|
||||
# body: { settings: Attachment.settings.to_hash, mappings: Attachment.mappings.to_hash }
|
||||
|
||||
# Index all article records from the DB to Elasticsearch
|
||||
#暂时只做公开课程/项目里的公开资源 和其他的公开资源
|
||||
#Attachment.where('is_public = 1 and ((container_type in ("Principal")) ' +
|
||||
# 'or (container_type = "Course" and container_id in( SELECT `courses`.id FROM `courses` WHERE (courses.status <> 9 AND courses.is_public = 1)) )'+
|
||||
# 'or (container_type = "Project" and container_id in(SELECT `projects`.id FROM `projects` WHERE (projects.status <> 9 AND projects.is_public = 1) ))' +')').import :force=>true
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
class AttachmentHistory < ActiveRecord::Base
|
||||
belongs_to :attachment,foreign_key: 'attachment_id'
|
||||
end
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue