This commit is contained in:
yuanke 2016-05-19 16:29:33 +08:00
commit 6e749f49e4
439 changed files with 48901 additions and 4323 deletions

1
.gitignore vendored
View File

@ -30,3 +30,4 @@ vendor/cache
/public/files
/tags
/config/initializers/gitlab_config.rb
1234567

1
1234567 Normal file
View File

@ -0,0 +1 @@
{"access_token":"bFlabz0uBcoIBfWL7nBJkgpl26aOWDy-dyCOvH_MjUo_hMOOKG83WV1cCL1MG6H-AE-6eMI0iyLoOoAMv9Y3pFFsLYD-GAGr3UH9fT8OqeHMDlFhXyRTvHv9l2QPHGpcARUcCGANEH","expires_in":7200,"got_token_at":1462934760}

14
Gemfile
View File

@ -1,5 +1,5 @@
source 'https://rubygems.org/'
#source 'http://ruby.sdutlinux.org/'
### 这里执行bundle config mirror.https://rubygems.org https://gems.ruby-china.org 切换到ruby-china源
unless RUBY_PLATFORM =~ /w32/
# unix-like only
@ -7,6 +7,8 @@ unless RUBY_PLATFORM =~ /w32/
end
gem 'certified'
gem 'wechat',path: 'lib/wechat'
gem 'grack', path:'lib/grack'
gem 'gitlab', path: 'lib/gitlab-cli'
gem 'rest-client'
@ -17,8 +19,9 @@ gem 'delayed_job_active_record'#, :group => :production
gem 'daemons'
gem 'grape', '~> 0.9.0'
gem 'grape-entity'
gem 'rack-cors', :require => 'rack/cors'
gem 'seems_rateable', '~> 1.0.13'
gem "rails", "~> 3.2.13"
gem 'rails', '~> 3.2'
gem "jquery-rails", "~> 2.0.2"
gem "i18n", "~> 0.6.0"
gem 'coderay', '~> 1.1.0'
@ -41,10 +44,15 @@ gem 'kaminari'
gem 'elasticsearch-model'
gem 'elasticsearch-rails'
### profile
#gem 'oneapm_rpm'
group :development do
gem 'grape-swagger'
gem 'better_errors', '~> 1.1.0'
gem 'rack-mini-profiler', '~> 0.9.3'
# gem "query_reviewer"
# gem 'rack-mini-profiler', '~> 0.9.3'
if RUBY_PLATFORM =~ /w32/
gem 'win32console'
end

View File

@ -7,6 +7,16 @@ module Mobile
require_relative 'apis/upgrade'
require_relative 'apis/homeworks'
require_relative 'apis/comments'
require_relative 'apis/issues'
require_relative 'apis/activities'
require_relative 'apis/whomeworks'
require_relative 'apis/newss'
require_relative 'apis/journal_for_messages'
require_relative 'apis/messages'
require_relative 'apis/blog_comments'
require_relative 'apis/new_comment'
require_relative 'apis/praise'
class API < Grape::API
version 'v1', using: :path
format :json
@ -39,6 +49,15 @@ module Mobile
mount Apis::Upgrade
mount Apis::Homeworks
mount Apis::Comments
mount Apis::Issues
mount Apis::Activities
mount Apis::Whomeworks
mount Apis::Newss
mount Apis::JournalForMessages
mount Apis::Messages
mount Apis::BlogComments
mount Apis::NewComment
mount Apis::Praise
#add_swagger_documentation ({api_version: 'v1', base_path: 'http://u06.shellinfo.cn/trustie/api'})
#add_swagger_documentation ({api_version: 'v1', base_path: '/api'}) if Rails.env.development?

View File

@ -0,0 +1,63 @@
#coding=utf-8
module Mobile
module Apis
class Activities< Grape::API
resources :activities do
desc "get user activities"
params do
requires :page, type: Integer
requires :openid, type: String
end
post do
user = UserWechat.find_by_openid(params[:openid]).user
=begin
shield_project_ids = ShieldActivity.where("container_type='User' and container_id=#{user.id} and shield_type='Project'").map(&:shield_id)
shield_course_ids = ShieldActivity.where("container_type='User' and container_id=#{user.id} and shield_type='Course'").map(&:shield_id)
page = params[:page] ? params[:page] : 0
user_project_ids = (user.projects.visible.map{|project| project.id}-shield_project_ids).empty? ? "(-1)" : "(" + (user.projects.visible.map{|project| project.id}-shield_project_ids).join(",") + ")"
user_course_ids = (user.courses.visible.map{|course| course.id}-shield_course_ids).empty? ? "(-1)" : "(" + (user.courses.visible.map{|course| course.id}-shield_course_ids).join(",") + ")"
course_types = "('Message','News','HomeworkCommon','Poll','Course')"
project_types = "('Message','Issue','ProjectCreateInfo')"
principal_types = "JournalsForMessage"
blog_ids = "("+user.blog.id.to_s+","+((User.watched_by(user.id).count == 0 )? '0' :User.watched_by(user.id).map{|u| u.blog.id}.join(','))+")"
activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types})" +
"or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}) "+
"or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{user.id}) " +
"or (container_type = 'Blog' and act_type= 'BlogComment' and container_id in #{blog_ids})").order('updated_at desc')
=end
shield_project_ids = ShieldActivity.select("shield_id").where("container_type='User' and container_id=#{user.id} and shield_type='Project'").map(&:shield_id)
shield_course_ids = ShieldActivity.select("shield_id").where("container_type='User' and container_id=#{user.id} and shield_type='Course'").map(&:shield_id)
page = params[:page] ? params[:page] : 0
user_project_ids = (user.projects.map{|project| project.id}-shield_project_ids).empty? ? "(-1)" : "(" + (user.projects.map{|project| project.id}-shield_project_ids).join(",") + ")"
user_course_ids = (user.courses.map{|course| course.id}-shield_course_ids).empty? ? "(-1)" : "(" + (user.courses.map{|course| course.id}-shield_course_ids).join(",") + ")"
course_types = "('Message','News','HomeworkCommon','Poll','Course')"
project_types = "('Message','Issue','ProjectCreateInfo')"
principal_types = "JournalsForMessage"
watched_user_ids = User.watched_by(user.id).count == 0 ? " " : ("," + User.watched_by(user.id).map{|u| u.id.to_s }.join(','))
user_ids = "(" + user.id.to_s + watched_user_ids + ")"
watched_user_blog_ids = Blog.select("id").where("author_id in #{user_ids}").map { |blog| blog.id}.join(",")
blog_ids = "(" + watched_user_blog_ids + ")"
activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types})" +
"or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}) "+
"or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{user.id}) " +
"or (container_type = 'Blog' and act_type= 'BlogComment' and container_id in #{blog_ids})").order('updated_at desc')
all_count = activities.count
activities = activities.limit(10).offset(page * 10)
count = activities.count
present :data, activities, with: Mobile::Entities::Activity,user: user
present :all_count, all_count
present :count, count
present :page, page
present :status, 0
end
end
end
end
end

View File

@ -0,0 +1,19 @@
#coding=utf-8
module Mobile
module Apis
class BlogComments< Grape::API
resources :blog_comments do
desc "get special topic"
get ':id' do
user = UserWechat.find_by_openid(params[:openid]).user
blog = BlogComment.find params[:id]
present :data, blog, with: Mobile::Entities::BlogComment,user: user
present :status, 0
end
end
end
end
end

View File

@ -115,7 +115,7 @@ module Mobile
desc '通知评论列表'
params do
requires :token, type: String
#requires :token, type: String
requires :notice_id,type:Integer,desc:'通知id'
optional :page,type:Integer,desc:'页码'
end

View File

@ -0,0 +1,19 @@
#coding=utf-8
module Mobile
module Apis
class Issues< Grape::API
resources :issues do
include IssuesHelper
desc "get special issuse"
get ':id' do
user = UserWechat.find_by_openid(params[:openid]).user
issue = Issue.find params[:id]
present :data, issue, with: Mobile::Entities::Issue,user: user
present :status, 0
end
end
end
end
end

View File

@ -0,0 +1,18 @@
#coding=utf-8
module Mobile
module Apis
class JournalForMessages< Grape::API
resources :journal_for_messages do
desc "get special journal"
get ':id' do
user = UserWechat.find_by_openid(params[:openid]).user
jour = JournalsForMessage.find params[:id]
present :data, jour, with: Mobile::Entities::Jours,user: user
present :status, 0
end
end
end
end
end

View File

@ -0,0 +1,18 @@
#coding=utf-8
module Mobile
module Apis
class Messages< Grape::API
resources :messages do
desc "get special topic"
get ':id' do
user = UserWechat.find_by_openid(params[:openid]).user
message = Message.find params[:id]
present :data, message, with: Mobile::Entities::Message,user: user
present :status, 0
end
end
end
end
end

View File

@ -0,0 +1,105 @@
#coding=utf-8
module Mobile
module Apis
class NewComment< Grape::API
include ApplicationHelper
include ApiHelper
resources :new_comment do
desc "add a new comment"
params do
requires :type, type: String
requires :content, type: String
requires :openid, type: String
end
post ':id' do
type = params[:type]
result = 1
current_user = UserWechat.find_by_openid(params[:openid]).user
if params[:content]!="" && current_user
case type
when "HomeworkCommon"
homework_common = HomeworkCommon.find(params[:id])
feedback = HomeworkCommon.add_homework_jour(current_user, params[:content], params[:id])
if (feedback.errors.empty?)
homework_common.update_column(:updated_at, Time.now)
result = 2
end
when "News"
news = News.find(params[:id])
comment = Comment.new
comment.comments = params[:content]
comment.author = current_user
if news.comments << comment
result = 2
end
when "Message"
message = Message.find(params[:id])
board = Board.find(message.board_id)
topic = message.root
reply = Message.new
reply.author = current_user
reply.board = board
reply.content = params[:content]
reply.parent_id = params[:id]
reply.subject = "RE: #{topic.subject}"
if topic.children << reply
result = 2
end
when "JournalsForMessage"
jour = JournalsForMessage.find params[:id]
parent_id = params[:id]
author_id = current_user.id
reply_user_id = jour.user_id
reply_id = params[:id]
content = params[:content]
options = {:user_id => author_id,
:status => true,
:m_parent_id => parent_id,
:m_reply_id => reply_id,
:reply_id => reply_user_id,
:notes => content,
:is_readed => false}
jfm = jour.user.add_jour(nil, nil, nil, options)
if jfm.errors.empty?
(JournalsForMessage.find parent_id).update_attribute(:updated_on,Time.now)
result = 2
end
when 'Issue'
issue = Issue.find params[:id]
is_jour = Journal.new
is_jour.user_id = current_user.id
is_jour.notes = params[:content]
is_jour.journalized = issue
if is_jour.save
result = 2
end
when 'BlogComment'
blog = BlogComment.find(params[:id]).root
blogComment = BlogComment.new
blogComment.author = current_user
blogComment.blog = blog.blog
blogComment.content = params[:content]
blogComment.title = "RE: #{blog.title}"
if blog.children << blogComment
result = 2
end
end
if result == 2
update_course_activity_api(type,params[:id])
update_user_activity_api(type,params[:id])
update_org_activity_api(type,params[:id])
update_forge_activity_api(type,params[:id])
update_principal_activity_api(type,params[:id])
end
else
result = 3
end
present :result, result
present :status, 0
end
end
end
end
end

View File

@ -0,0 +1,18 @@
#coding=utf-8
module Mobile
module Apis
class Newss< Grape::API
resources :newss do
desc "get special news"
get ':id' do
user = UserWechat.find_by_openid(params[:openid]).user
news = News.find params[:id]
present :data, news, with: Mobile::Entities::News,user: user
present :status, 0
end
end
end
end
end

View File

@ -0,0 +1,41 @@
#coding=utf-8
module Mobile
module Apis
class Praise< Grape::API
include ApiHelper
resources :praise do
desc "praise an activity"
params do
requires :type, type: String
requires :openid, type: String
end
post ':id' do
obj_id = params[:id]
obj_type = params[:type]
user = UserWechat.find_by_openid(params[:openid]).user
pts = PraiseTread.where("praise_tread_object_id=? and praise_tread_object_type=? and user_id=?",obj_id,obj_type.to_s,user.id).first
if pts.blank?
praise_or_cancel(obj_type,obj_id,user,1)
obj = PraiseTreadCache.where("object_id=? and object_type=?",obj_id,obj_type.to_s).first
num = get_activity_praise_num(obj) if !obj.blank?
else
pts.destroy if !pts.blank?
#再更新praise_tread_cache表 使相应的记录减1 当为0时删除
ptc = PraiseTreadCache.where("object_id=? and object_type=?",obj_id,obj_type.to_s).first
ptc.praise_minus(1) if !ptc.blank?
if ptc.praise_num == 0
ptc.delete
end
obj = PraiseTreadCache.where("object_id=? and object_type=?",obj_id,obj_type.to_s).first
num = !obj.blank? ? get_activity_praise_num(obj) : 0
end
present :data, num
present :status, 0
end
end
end
end
end

View File

@ -0,0 +1,18 @@
#coding=utf-8
module Mobile
module Apis
class Whomeworks< Grape::API
resources :whomeworks do
desc "get one homework"
get ':id' do
user = UserWechat.find_by_openid(params[:openid]).user
homework = HomeworkCommon.find params[:id]
present :data, homework, with: Mobile::Entities::Whomework,user: user
present :status, 0
end
end
end
end
end

View File

@ -0,0 +1,146 @@
# encoding: utf-8
module Mobile
module Entities
class Activity <Grape::Entity
include ApplicationHelper
include ApiHelper
def self.act_expose(f)
expose f do |ac,opt|
if ac.is_a?(Hash) && ac.key?(f)
ac[f]
elsif ac.is_a?(::UserActivity)
if ac.respond_to?(f)
ac.send(f)
else
case f
when :user_act
if ac.act_type == "ProjectCreateInfo"
ac unless ac.nil?
else
ac.act unless ac.nil? || ac.act.nil?
end
when :reply_count
if ac.act_type == "HomeworkCommon"
ac.nil? || ac.act.nil? ? 0 : ac.act.journals_for_messages.count
elsif ac.act_type == "News"
ac.nil? || ac.act.nil? ? 0 : ac.act.comments.count
elsif ac.act_type == "Message" || ac.act_type == "BlogComment" || ac.act_type == "JournalsForMessage"
ac.nil? || ac.act.nil? ? 0 : ac.act.children.count
elsif ac.act_type == "Issue"
ac.nil? || ac.act.nil? ? 0 : ac.act.journals.where("notes is not null and notes != ''").count
end
when :subject
if ac.act_type == "HomeworkCommon"
ac.act.name unless ac.nil? || ac.act.nil?
elsif ac.act_type == "News" || ac.act_type == "BlogComment"
ac.act.title unless ac.nil? || ac.act.nil?
elsif ac.act_type == "Message" || ac.act_type == "Issue"
ac.act.subject unless ac.nil? || ac.act.nil?
elsif ac.act_type == "JournalsForMessage"
ac.act.private == 0 ? "留言" : "私信" unless ac.nil? || ac.act.nil?
end
when :description
if ac.act_type == "HomeworkCommon" || ac.act_type == "Issue" || ac.act_type == "News"
ac.act.description unless ac.nil? || ac.act.nil?
elsif ac.act_type == "Message" || ac.act_type == "BlogComment"
ac.act.content unless ac.nil? || ac.act.nil?
elsif ac.act_type == "JournalsForMessage"
ac.act.notes unless ac.nil? || ac.act.nil?
end
when :latest_update
time_from_now ac.updated_at unless ac.nil?
when :praise_count
if ac.act_type == "HomeworkCommon" || ac.act_type == "News" || ac.act_type == "Message" || ac.act_type == "BlogComment" || ac.act_type == "JournalsForMessage" || ac.act_type == "Issue"
ac.nil? || ac.act.nil? ? 0 : get_activity_praise_num(ac.act)
end
#when :homework_common_detail_manual
# if ac.act_type == "HomeworkCommon"
# ac.act.homework_detail_manual unless ac.nil? || ac.act.nil? || ac.act.homework_detail_manual.nil?
# end
when :course_project_name
if ac.container_type == "Course"
name = (get_course(ac.container_id)).name
name
elsif ac.container_type == "Project"
name = (get_project(ac.container_id)).name
name
elsif ac.container_type == "Blog"
"发表博客"
end
when :activity_type_name
if ac.container_type == "Course"
case ac.act_type
when "HomeworkCommon"
"课程作业"
when "News"
"课程通知"
when "Message"
"课程问答区"
when "Poll"
"课程问卷"
when "Course"
"课程"
end
elsif ac.container_type == "Project"
case ac.act_type
when "Issue"
"项目缺陷"
when "Message"
"项目讨论区"
when "ProjectCreateInfo"
"项目"
end
end
end
end
end
end
end
expose :act_type #缺陷/作业/讨论区/留言等类型
expose :act_id
expose :container_type #课程/项目/博客/个人
expose :author, using: Mobile::Entities::User do |a, opt| #用户信息
if a.is_a? ::UserActivity
if a.act_type == "ProjectCreateInfo"
get_user(get_project(a.act_id).user_id)
elsif !a.act.nil?
if a.act_type == 'Issue' || a.act_type == 'News' || a.act_type == 'Message' || a.act_type == 'BlogComment'
a.act.author
elsif a.act_type == 'HomeworkCommon' || a.act_type == 'Poll' || a.act_type == 'JournalsForMessage'
a.act.user
elsif a.act_type == 'Course'
a.act.teacher
end
end
end
end
expose :homework_common_detail , using: Mobile::Entities::Whomework do |a, opt| #作业相关信息
if a.act_type == "HomeworkCommon"
a.act
end
end
expose :issue_detail, using: Mobile::Entities::Issue do |a, opt| #缺陷信息
if a.act_type == "Issue"
a.act
end
end
act_expose :reply_count #回复数
act_expose :praise_count #点赞数
#act_expose :user_act #某个动态
act_expose :subject #标题
act_expose :description #描述
act_expose :latest_update #最新更新时间
act_expose :course_project_name #课程/项目名字
act_expose :activity_type_name #课程问答区/项目缺陷等
expose :has_praise , if: lambda { |instance, options| options[:user] } do |instance, options|
if instance.act_type == "HomeworkCommon" || instance.act_type == "News" || instance.act_type == "Message" || instance.act_type == "BlogComment" || instance.act_type == "JournalsForMessage" || instance.act_type == "Issue"
has_praise = false
current_user = options[:user]
obj = PraiseTread.where("praise_tread_object_id=? and praise_tread_object_type=? and user_id=?",instance.act_id,instance.act_type.to_s,current_user.id)
has_praise = obj.empty? ? false : true
has_praise
end
end
end
end
end

View File

@ -0,0 +1,66 @@
module Mobile
module Entities
class BlogComment < Grape::Entity
include ApplicationHelper
include ApiHelper
def self.blog_comment_expose(f)
expose f do |u,opt|
if u.is_a?(Hash) && u.key?(f)
u[f]
elsif u.is_a?(::BlogComment)
if u.respond_to?(f)
if f == :created_at
format_time( u.send(f))
else
u.send(f)
end
else
case f
when :praise_count
get_activity_praise_num(u)
when :lasted_comment
time_from_now(u.created_at)
when :act_type
'BlogComment'
when :act_id
u.id
when :comment_count
u.children.count
end
end
end
end
end
expose :user, using: Mobile::Entities::User do |c, opt|
if c.is_a?(::BlogComment)
c.author
end
end
blog_comment_expose :act_type
blog_comment_expose :act_id
blog_comment_expose :blog_id
blog_comment_expose :title
blog_comment_expose :content
blog_comment_expose :comment_count
blog_comment_expose :created_at
blog_comment_expose :lasted_comment
blog_comment_expose :id
blog_comment_expose :locked
blog_comment_expose :praise_count
expose :blog_comment_children, using:Mobile::Entities::BlogComment do |c,opt|
if c.is_a? (::BlogComment)
c.children.reverse
end
end
expose :has_praise, if: lambda { |instance, options| options[:user] } do |instance, options|
has_praise = false
current_user = options[:user]
obj = PraiseTread.where("praise_tread_object_id=? and praise_tread_object_type=? and user_id=?",instance.id,instance.class.to_s,current_user.id)
has_praise = obj.empty? ? false : true
has_praise
end
end
end
end

View File

@ -9,7 +9,7 @@ module Mobile
elsif f.is_a?(::Comment)
if f.respond_to?(field)
if field == :created_on
format_time(f.send(field))
time_from_now(f.send(field))
else
f.send(field)
end

View File

@ -0,0 +1,67 @@
module Mobile
module Entities
class Issue <Grape::Entity
include ApiHelper
include Redmine::I18n
def self.issue_expose(f)
expose f do |issue, opt|
if issue.is_a?(Hash) && issue.key?(f)
issue[f]
elsif issue.is_a?(::Issue)
if issue.respond_to?(f)
if f == :created_on
format_time(issue.send(f))
else
issue.send(f)
end
else
case f
when :issue_priority
get_issue_priority_api issue.priority_id
when :issue_assigned_to
(get_user(issue.assigned_to_id)).login
when :issue_status
IssueStatus.find(issue.status_id).name
when :journals_count
issue.journals.where("notes is not null and notes != ''").count
when :project_name
issue.project.name
when :praise_count
get_activity_praise_num(issue)
when :act_type
'Issue'
when :act_id
issue.id
end
end
end
end
end
expose :subject
expose :description
expose :author, using: Mobile::Entities::User
expose :done_ratio
issue_expose :act_type
issue_expose :act_id
issue_expose :created_on
issue_expose :issue_priority
issue_expose :issue_assigned_to
issue_expose :issue_status
issue_expose :journals_count
issue_expose :project_name
issue_expose :praise_count
expose :issue_journals, using: Mobile::Entities::Journal do |f, opt|
if f.is_a?(::Issue)
f.journals.where("notes is not null and notes != ''").reverse
end
end
expose :has_praise , if: lambda { |instance, options| options[:user] } do |instance, options|
has_praise = false
current_user = options[:user]
obj = PraiseTread.where("praise_tread_object_id=? and praise_tread_object_type=? and user_id=?",instance.id,instance.class.to_s,current_user.id)
has_praise = obj.empty? ? false : true
has_praise
end
end
end
end

View File

@ -0,0 +1,44 @@
module Mobile
module Entities
class Journal <Grape::Entity
include Redmine::I18n
=begin
include Redmine::I18n
include ApplicationHelper
include ApiHelper
include IssuesHelper
include ActionView::Helpers::TagHelper
include ActionView::Helpers::UrlHelper
=end
def self.journal_expose(f)
expose f do |journal, opt|
if journal.is_a?(Hash) && journal.key?(f)
journal[f]
elsif journal.is_a?(::Journal)
if journal.respond_to?(f)
if f == :created_on
time_from_now(journal.send(f))
else
journal.send(f)
end
else
case f
when :detail_journal
if journal.details.any?
details_to_strings(journal.details)
end
end
end
end
end
end
expose :notes
journal_expose :created_on
expose :user,using: Mobile::Entities::User do |f, opt|
f.user
end
#journal_expose :detail_journal
end
end
end

View File

@ -3,7 +3,6 @@ module Mobile
#普通留言
class Jours < Grape::Entity
include Redmine::I18n
include WordsHelper
def self.jours_expose(field)
expose field do |f,opt|
if f.is_a?(Hash) && f.key?(field)
@ -15,13 +14,24 @@ module Mobile
f.send(field)
end
else
case f
when :course_name
f[:jour_type] == "Course" ? f.course.name : ""
case field
when :lasted_comment
time_from_now f.created_on
when :reply_count
f.children.count
when :praise_count
get_activity_praise_num(f)
when :act_type
'JournalsForMessage'
when :act_id
f.id
end
end
end
end
jours_expose :act_type
jours_expose :act_id
jours_expose :id
jours_expose :jour_type
jours_expose :jour_id
@ -29,9 +39,12 @@ module Mobile
f.user
end
jours_expose :created_on
jours_expose :lasted_comment
jours_expose :notes
jours_expose :m_reply_id
jours_expose :m_parent_id
jours_expose :reply_count
jours_expose :praise_count
expose :course,using:Mobile::Entities::Course do |f,opt|
if f.is_a?(::JournalsForMessage) && f[:jour_type] == "Course"
f.course
@ -42,9 +55,16 @@ module Mobile
end
expose :child_reply,using: Mobile::Entities::Jours do |f, opt|
if f.is_a?(::JournalsForMessage)
fetch_user_leaveWord_reply(f)
f.children.reverse
end
end
expose :has_praise , if: lambda { |instance, options| options[:user] } do |instance, options|
has_praise = false
current_user = options[:user]
obj = PraiseTread.where("praise_tread_object_id=? and praise_tread_object_type=? and user_id=?",instance.id,instance.class.to_s,current_user.id)
has_praise = obj.empty? ? false : true
has_praise
end
end
end
end

View File

@ -15,10 +15,22 @@ module Mobile
u.send(f)
end
else
# case f
# when :xx
# #
# end
case f
when :course_project_name
if u.board.project_id == -1
u.course.name
else
u.project.name
end
when :lasted_comment
time_from_now u.created_on
when :praise_count
get_activity_praise_num(u)
when :act_type
'Message'
when :act_id
u.id
end
end
end
@ -30,17 +42,30 @@ module Mobile
c.author
end
end
message_expose :act_type
message_expose :act_id
message_expose :course_project_name
message_expose :board_id
message_expose :subject
message_expose :content
message_expose :replies_count
message_expose :praise_count
message_expose :created_on
message_expose :locked
message_expose :id
message_expose :lasted_comment
expose :message_children,using:Mobile::Entities::Message do |c,opt|
if c.is_a? (::Message)
c.children
c.children.reverse
end
end
expose :has_praise , if: lambda { |instance, options| options[:user] } do |instance, options|
has_praise = false
current_user = options[:user]
obj = PraiseTread.where("praise_tread_object_id=? and praise_tread_object_type=? and user_id=?",instance.id,instance.class.to_s,current_user.id)
has_praise = obj.empty? ? false : true
has_praise
end
end
end
end

View File

@ -2,15 +2,29 @@ module Mobile
module Entities
class News < Grape::Entity
include Redmine::I18n
include ApiHelper
def self.news_expose(field)
expose field do |f,opt|
if f.is_a?(Hash) && f.key?(field)
f[field]
elsif f.is_a?(::News)
if field == :created_on
format_time(f.send(field)) if f.respond_to?(field)
if f.respond_to?(field)
if field == :created_on
format_time(f.send(field))
else
f.send(field)
end
else
f.send(field) if f.respond_to?(field)
case field
when :course_name
get_course(f.course_id).name unless f.course_id == nil
when :praise_count
get_activity_praise_num(f)
when :act_type
'News'
when :act_id
f.id
end
end
elsif f.is_a?(Hash) && !f.key?(field)
n = f[:news]
@ -40,6 +54,8 @@ module Mobile
end
obj
end
news_expose :act_type
news_expose :act_id
#作者id
news_expose :author_id
#作者名
@ -52,16 +68,24 @@ module Mobile
news_expose :created_on
#评论数量
news_expose :comments_count
news_expose :praise_count
#课程名字
news_expose :course_name
#评论
expose :comments, using: Mobile::Entities::Comment do |f, opt|
if f.is_a?(Hash) && f.key?(:comments)
f[:comments]
elsif f.is_a?(::News) && f.respond_to?(:comments)
f.send(:comments)
f.comments.reverse
end
end
expose :has_praise , if: lambda { |instance, options| options[:user] } do |instance, options|
has_praise = false
current_user = options[:user]
obj = PraiseTread.where("praise_tread_object_id=? and praise_tread_object_type=? and user_id=?",instance.id,instance.class.to_s,current_user.id)
has_praise = obj.empty? ? false : true
has_praise
end
end
end
end

View File

@ -32,14 +32,14 @@ module Mobile
end
end
student_work_expose :student_id
student_work_expose :id
student_work_expose :id
student_work_expose :name
student_work_expose :description
student_work_expose :final_score
student_work_expose :teacher_score
student_work_expose :student_score
student_work_expose :teacher_asistant_score
student_work_expose :created_at
student_work_expose :description
student_work_expose :final_score
student_work_expose :teacher_score
student_work_expose :student_score
student_work_expose :teacher_asistant_score
student_work_expose :created_at
end
end
end

View File

@ -13,7 +13,7 @@ module Mobile
else
case f
when :img_url
url_to_avatar(u)
"/images/#{url_to_avatar(u)}"
when :gender
u.nil? || u.user_extensions.nil? || u.user_extensions.gender.nil? ? 0 : u.user_extensions.gender
when :work_unit
@ -24,6 +24,8 @@ module Mobile
u.nil? || u.user_extensions.nil? ? "" : u.user_extensions.brief_introduction
when :student_num
u.nil? || u.user_extensions.nil? ? "" : u.user_extensions.student_id
when :realname
u.nil? ? "" : get_user_realname(u)
end
end
end
@ -37,7 +39,7 @@ module Mobile
#昵称
expose :nickname
#真名
expose :realname
user_expose :realname
#性别
user_expose :gender
#我的二维码

View File

@ -0,0 +1,85 @@
# encoding: utf-8
module Mobile
module Entities
class Whomework <Grape::Entity
include ApiHelper
include ApplicationHelper
include Redmine::I18n
def self.whomework_expose(f)
expose f do |wh, opt|
if wh.is_a?(Hash) && wh.key?(f)
wh[f]
elsif wh.is_a?(::HomeworkCommon)
if wh.respond_to?(f)
if f == :created_at
format_time(wh.send(f))
else
wh.send(f)
end
else
case f
when :absence_penalty
wh.nil? || wh.homework_detail_manual.nil? ? 0 : wh.homework_detail_manual.absence_penalty
when :evaluation_start
wh.nil? || wh.homework_detail_manual.nil? ? nil : convert_to_time(wh.homework_detail_manual.evaluation_start, 0)
when :evaluation_end
wh.nil? || wh.homework_detail_manual.nil? ? nil : convert_to_time(wh.homework_detail_manual.evaluation_end, 1)
when :praise_count
get_activity_praise_num(wh)
when :whomework_journal_count
wh.journals_for_messages.count
when :course_name
wh.course.name
when :act_type
'HomeworkCommon'
when :act_id
wh.id
end
end
end
end
end
expose :author, using: Mobile::Entities::User do |w, opt|
if w.is_a?(::HomeworkCommon)
w.user
end
end
expose :current_user, using: Mobile::Entities::User do |w, opt|
current_user
end
expose :name
expose :description
expose :publish_time
expose :end_time
expose :homework_type
expose :late_penalty
expose :course_id
expose :anonymous_comment
expose :quotes
expose :is_open
whomework_expose :act_type
whomework_expose :act_id
whomework_expose :course_name
whomework_expose :created_at
whomework_expose :absence_penalty
whomework_expose :evaluation_start
whomework_expose :evaluation_end
whomework_expose :praise_count
whomework_expose :whomework_journal_count
expose :journals_for_messages, using: Mobile::Entities::Jours do |f, opt|
#f[:journals_for_messages] if f.is_a?(Hash) && f.key?(:journals_for_messages)
if f.is_a?(::HomeworkCommon)
f.journals_for_messages.reverse
end
end
expose :has_praise , if: lambda { |instance, options| options[:user] } do |instance, options|
has_praise = false
current_user = options[:user]
obj = PraiseTread.where("praise_tread_object_id=? and praise_tread_object_type=? and user_id=?",instance.id,instance.class.to_s,current_user.id)
has_praise = obj.empty? ? false : true
has_praise
end
end
end
end

View File

@ -7,7 +7,8 @@ module Mobile
@app.call(@env)
rescue =>e
message = {status: 1, message: e.message }.to_json
puts(e.backtrace.join("\n")) if Rails.env.development?
Rails.logger.error e.inspect
Rails.logger.error e.backtrace.join("\n")
status = 200
headers = { 'Content-Type' => content_type }
Rack::Response.new([message], status, headers).finish

View File

@ -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/

View File

@ -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/

View File

@ -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/

View File

@ -0,0 +1,3 @@
// Place all the styles related to the ShieldWechatMessages controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

View File

@ -0,0 +1,3 @@
// Place all the styles related to the sub_document_comments controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

View File

@ -0,0 +1,3 @@
// Place all the styles related to the sub_domains controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

View File

@ -593,7 +593,7 @@ class AdminController < ApplicationController
end
end
#代码测试列表
#代码测试列表
def code_work_tests
#求出所有条数
tCount = CodeTests.count()
@ -644,4 +644,13 @@ class AdminController < ApplicationController
format.html
end
end
#分享作业申请
def apply_for_homework
homeworks = ApplyHomework.where("user_id != 0")
@homework = paginateHelper homeworks,30
@page = (params['page'] || 1).to_i - 1
respond_to do |format|
format.html
end
end
end

View File

@ -660,8 +660,8 @@ class AttachmentsController < ApplicationController
end
def has_login
unless @attachment && @attachment.container_type == "Organization"
unless @attachment && @attachment.container_type == "PhoneAppVersion"
unless (@attachment && @attachment.container_type == "Organization").nil?
unless (@attachment && @attachment.container_type == "PhoneAppVersion").nil?
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

View File

@ -187,7 +187,7 @@ class CoursesController < ApplicationController
end
@canShowCode = User.current.allowed_to?(:as_teacher,@course) && params[:role] != '1'
@is_remote = true
@members = student_homework_score(0,0, 10,"desc")
@course_groups = @course.course_groups
end
@ -209,7 +209,7 @@ class CoursesController < ApplicationController
end
@canShowCode = isCourseTeacher(User.current.id,@course) && params[:role] != '1'
@is_remote = true
@members = student_homework_score(0,0, 10,"desc")
@course_groups = @course.course_groups
end
@ -956,6 +956,7 @@ class CoursesController < ApplicationController
@student_works.each do |tmpwork|
@works_hash[tmpwork.id] = tmpwork
puts tmpwork.id
end
#respond_to do |format|

View File

@ -11,6 +11,9 @@ class HomeworkCommonController < ApplicationController
before_filter :member_of_course, :only => [:index]
def index
#unless params[:page]
# update_homework_time(@course.homework_commons)
#end
@new_homework = HomeworkCommon.new
@new_homework.homework_detail_manual = HomeworkDetailManual.new
@new_homework.course = @course
@ -73,16 +76,23 @@ class HomeworkCommonController < ApplicationController
else
@homework.publish_time = params[:homework_common][:publish_time]
end
homework_detail_manual = @homework.homework_detail_manual || HomeworkDetailManual.new
@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
anonymous = params[:homework_common][:anonymous_comment] ? params[:homework_common][:anonymous_comment].to_i : 0
if anonymous != @homework.anonymous_comment
if anonymous == 1
homework_detail_manual.ta_proportion = @homework.homework_type == 1 ? 1.0 : 0.4
else
homework_detail_manual.ta_proportion = @homework.homework_type == 1 ? 0.6 : 0.3
end
end
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
eval_start = homework_detail_manual.evaluation_start
if eval_start <= @homework.end_time && homework_detail_manual.comment_status <= 1
if eval_start.nil? || (eval_start <= @homework.end_time && homework_detail_manual.comment_status <= 1)
homework_detail_manual.evaluation_start = @homework.end_time + 7
homework_detail_manual.evaluation_end = homework_detail_manual.evaluation_start + 7
end
@ -94,6 +104,13 @@ class HomeworkCommonController < ApplicationController
@homework.homework_detail_programing ||= HomeworkDetailPrograming.new
@homework_detail_programing = @homework.homework_detail_programing
@homework_detail_programing.language = params[:language_type].to_i
if anonymous != @homework.anonymous_comment
if anonymous == 1
@homework_detail_programing.ta_proportion = 0.6
else
@homework_detail_programing.ta_proportion = 0.5
end
end
@homework.homework_tests.delete_all
inputs = params[:program][:input]
@ -116,8 +133,9 @@ class HomeworkCommonController < ApplicationController
@homework_detail_group.base_on_project = params[:base_on_project].to_i
end
@homework.anonymous_comment = params[:homework_common][:anonymous_comment] ? params[:homework_common][:anonymous_comment].to_i : 0
if @homework.save
@homework_detail_manual.save if @homework_detail_manual
homework_detail_manual.save if homework_detail_manual
@homework_detail_programing.save if @homework_detail_programing
@homework_detail_group.save if @homework_detail_group
@ -385,4 +403,47 @@ class HomeworkCommonController < ApplicationController
student_works += student_works
student_works[index + 1 .. index + n]
end
def update_homework_time homeworks
unless homeworks.nil?
homeworks.each do |h|
if h.homework_type == 3
student_works = h.student_work_projects.where("is_leader = 1")
time = h.updated_at
unless student_works.nil?
student_works.each do |s|
project = Project.find s.project_id
unless project.nil? && project.gpid.nil?
project_time=project.updated_on
project_time=ForgeActivity.where("project_id=?",project.id).last.updated_at if ForgeActivity.where("project_id=?",project.id).last
if format_time(time) < format_time(project_time)
time = project_time
end
begin
# gitlab端获取默认分支
g = Gitlab.client
default_branch = g.project(project.gpid).default_branch
changesets = g.commits(project.gpid, :ref_name => default_branch)
changesets_latest_coimmit = changesets[0]
unless changesets[0].blank?
if format_time(time) < format_time(changesets_latest_coimmit.created_at)
time = changesets_latest_coimmit.created_at
end
end
rescue
logger.error("############## ==> update homework project time")
end
end
end
end
puts h.updated_at
puts time
s_time = time
if format_time(time) > format_time(h.updated_at)
h.update_attribute(:updated_at, s_time)
end
end
end
end
end
end

View File

@ -79,7 +79,7 @@ class OrgDocumentCommentsController < ApplicationController
def add_reply
@document = OrgDocumentComment.find(params[:id]).root
@act = OrgActivity.find(params[:id])
@act = OrgActivity.find(params[:act_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

View File

@ -15,6 +15,12 @@ class OrgSubfieldsController < ApplicationController
end
end
@subfield.update_attributes(:field_type => params[:field_type])
# 如果栏目是教师,不参入类型的配置,定义为右三模式
# 新增模块命名规则左边1开头右边2开头以前的不变
# eg23 右三
if params[:field_type] == "Comptec"
@subfield.update_attributes(:status => 23)
end
else
@res = false
end

View File

@ -28,7 +28,7 @@ class OrganizationsController < ApplicationController
helper :project_score
helper :issues
include UsersHelper
before_filter :find_organization, :only => [:show, :members, :apply_subdomain, :select_org_layout]
before_filter :find_organization, :only => [:show, :members, :apply_subdomain, :select_org_layout, :teachers]
layout 'base_org'
def index
@ -76,18 +76,14 @@ class OrganizationsController < ApplicationController
def show
# 组织新类型 show_mode判断标准 1为新类型0为旧
if @organization.show_mode == 1 && params[:org_subfield_id].nil? && params[:list] .nil?
if @organization.show_mode.to_i == 1 && params[:org_subfield_id].nil? && params[:list] .nil?
if @organization.is_public? || User.current.admin? || User.current.member_of_org?(@organization)
# REDO:时间紧,暂时先这样
@org_logo_attchment = Attachment.where("container_id =? and container_type =? and attachtype =?", @organization, "Organization", 0).order("created_on desc").first
@org_banner_attchment = Attachment.where("container_id =? and container_type =? and attachtype =?", @organization, "Organization", 1).order("created_on desc").first
@org_logo_attchment = Attachment.find_by_sql("SELECT * from attachments WHERE container_id = #{@organization.id} and container_type = 'Organization' and attachtype = 0 and filename REGEXP '(.jpg|.png|.bmp|.gif|.jpeg)' ORDER BY created_on desc limit 1").first
@org_banner_attchment = Attachment.find_by_sql("SELECT * from attachments WHERE container_id = #{@organization.id} and container_type = 'Organization' and attachtype = 1 and filename REGEXP '(.jpg|.png|.bmp|.gif|.jpeg)' ORDER BY created_on desc limit 1").first
@subfield_content = @organization.org_subfields.order("priority")
@organization = Organization.find(params[:id])
# @org_subfield = OrgSubfield.find(params[:org_subfield_id])
# @org_subfield_ids = @org_subfield.org_document_comments.map(&:id) << 0
# @org_acts = 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)
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
@ -95,35 +91,33 @@ class OrganizationsController < ApplicationController
course_types = "('Message','News','HomeworkCommon','Poll','Course')"
@project_acts = get_project_activities_org @organization, project_ids
@course_acts = get_course_activities_org @organization, course_ids
#@org_acts = OrgActivity.where("container_id =? and container_type =?",@organization.id, 'Organization').order('updated_at desc')
#@project_acts = OrgActivity.where("(container_id =? and container_type =?) " +
# "or (container_type ='Project' and org_act_type in ('Issue','Message') and container_id in (#{project_ids.join(',')})) ",
# @organization.id, 'Organization').order('updated_at desc').limit(8)
#@course_acts = OrgActivity.where("(container_id =? and container_type =?) " +
# "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').limit(8)
# 项目两种动态
#@project_acts = get_project_activities_org @organization
# 课程动态
#@project_acts_issues = get_project_activities_org @organization
#@course_acts = get_course_activities_org @organization
render :layout => 'base_org_newstyle'
render :layout => 'base_org2'
else
render_403
end
else
if @organization.is_public? || User.current.admin? || User.current.member_of_org?(@organization)
@organization = Organization.find(params[:id])
# params[:org_subfield_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)
if @org_subfield.field_type == "Comptec" || @org_subfield.field_type == "Compstu"
# @org_teachers = User.find_by_sql("select u.*, ue.technical_title, ue.school_id,( SELECT `courses`.* FROM `courses` INNER JOIN `members` ON `courses`.`id` = `members`.`course_id` WHERE `members`.`user_id` = u.id AND (courses.status<>9)) as course_count
# from users u, user_extensions ue where u.id = ue.user_id and ue.identity=0 order by course_count desc")
@org_teachers = User.find_by_sql("select u.*, ue.technical_title, ue.school_id,(select count(*) from courses where courses.tea_id = u.id) as course_count from users u, user_extensions ue where u.id = ue.user_id and ue.identity=0 order by course_count desc")
# @org_count = @org_teachers.count
# @limit = 25
# @is_remote = true
# @atta_count = @attachments.count
# @atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1
# @offset ||= @atta_pages.offset
# #@curse_attachments_all = @all_attachments[@offset, @limit]
# @attachments = paginateHelper @attachments,25
else
@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)
end
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)
@ -164,6 +158,57 @@ class OrganizationsController < ApplicationController
end
def teachers
unless @organization.allow_set_teachers
render_403
return
end
q = params[:search].nil? ? "" : "#{params[:search].strip}"
@field = OrgSubfield.find(params[:org_subfield_id])
@type = params[:type]
if @type == "courses" || @type.nil?
@org_teachers = User.find_by_sql("select u.*, ue.technical_title, ue.school_id,(select count(*) from courses where courses.tea_id = u.id) as course_count
from users u, user_extensions ue where u.id = ue.user_id and ue.identity=0 and concat(lastname,firstname,login) like '%#{q}%' order by course_count desc")
elsif @type == "students"
@org_teachers = User.find_by_sql("select u.*, ue.technical_title, ue.school_id,(select count(*) from courses where courses.tea_id = u.id) as course_count
from users u, user_extensions ue where u.id = ue.user_id and ue.identity=0 and concat(lastname,firstname,login) like '%#{q}%' order by course_count desc")
elsif @type == "resources"
@org_teachers = User.find_by_sql("select u.*, ue.technical_title, ue.school_id,(select count(*) from attachments where attachments.author_id = u.id) as course_count
from users u, user_extensions ue where u.id = ue.user_id and ue.identity=0 and concat(lastname,firstname,login) like '%#{q}%' order by course_count desc")
elsif @type == "famous"
@org_teachers = User.find_by_sql("select u.*, ue.technical_title, ue.school_id,(select count(*) from courses where courses.tea_id = u.id) as course_count
from users u, user_extensions ue where u.id = ue.user_id and ue.identity=0 and u.excellent_teacher =1 and concat(lastname,firstname,login) like '%#{q}%' order by course_count desc")
end
limit = 10
# @is_remote = true
@teachers_count = @org_teachers.count
@atta_pages = Paginator.new @teachers_count, limit, params['page'] || 1
@offset ||= @atta_pages.offset
#@curse_attachments_all = @all_attachments[@offset, @limit]
@org_teachers = paginateHelper @org_teachers, limit
respond_to do |format|
format.html
format.js
end
end
def searchmember_by_name members, name
#searchPeopleByRoles(project, StudentRoles)
mems = []
if name != ""
name = name.to_s.downcase
members.each do |m|
username = m.user[:lastname].to_s.downcase + m.user[:firstname].to_s.downcase
if(m.user[:login].to_s.downcase.include?(name) || m.user.user_extensions[:student_id].to_s.downcase.include?(name) || username.include?(name))
mems << m
end
end
else
mems = members
end
mems
end
def get_project_message_activities_org org
project_ids = org.projects.map{|project| project.id}.join(",")
unless project_ids.blank?
@ -187,7 +232,7 @@ class OrganizationsController < ApplicationController
def get_project_activities_org org, project_ids
unless project_ids.blank?
project_acts = OrgActivity.find_by_sql("SELECT * FROM org_activities where container_id in (#{project_ids.join(',')}) and container_type = 'project'
and org_act_type in ('Message', 'Issue') order by updated_at desc limit 8;")
and org_act_type in ('Message', 'Issue') order by updated_at desc limit 5;")
else
project_acts = nil
end
@ -198,7 +243,7 @@ class OrganizationsController < ApplicationController
def get_course_activities_org org, course_ids
unless course_ids.blank?
project_acts = OrgActivity.find_by_sql("SELECT * FROM org_activities where container_id in (#{course_ids.join(',')}) and container_type = 'course'
and org_act_type in ('HomeworkCommon', 'Poll', 'Message', 'News', 'Course') order by updated_at desc limit 8;")
and org_act_type in ('HomeworkCommon', 'Poll', 'Message', 'News', 'Course') order by updated_at desc limit 5;")
else
project_acts = nil
end
@ -243,6 +288,7 @@ class OrganizationsController < ApplicationController
# @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.allow_teacher = params[:organization][:allow_teacher] == 'on' ? 1 : 0
@organization.show_mode = params[:show_mode]
#@organization.name = params[:organization][:name]
@organization.save
@ -425,6 +471,18 @@ class OrganizationsController < ApplicationController
end
end
# 设置为名师
def set_excellent_teacher
@ex_teacher = User.find(params[:user])
@ex_teacher.update_column(:excellent_teacher, 1)
end
# 取消名师
def reset_excellent_teacher
@ex_teacher = User.find(params[:user])
@ex_teacher.update_column(:excellent_teacher, 0)
end
def hide_org_subfield
@org_subfield = OrgSubfield.find(params[:org_subfield_id])
@org_subfield.update_attribute(:hide, 1)

View File

@ -32,9 +32,9 @@ class RepositoriesController < ApplicationController
before_filter :find_project_by_project_id, :only => [:new, :create, :newrepo, :stats]
before_filter :find_repository, :only => [:edit, :update, :destroy, :committers]
before_filter :find_project_repository, :except => [:new, :create, :newcreate, :edit, :update, :destroy, :committers, :newrepo, :to_gitlab, :forked]
before_filter :find_project_repository, :except => [:new, :create, :newcreate, :edit, :update, :destroy, :committers, :newrepo, :to_gitlab, :forked, :project_archive]
before_filter :find_changeset, :only => [:revision, :add_related_issue, :remove_related_issue]
before_filter :authorize , :except => [:newrepo,:newcreate,:fork, :to_gitlab, :forked, :commit_diff]
before_filter :authorize , :except => [:newrepo,:newcreate,:fork, :to_gitlab, :forked, :commit_diff, :project_archive]
accept_rss_auth :revisions
# hidden repositories filter // 隐藏代码过滤器
before_filter :check_hidden_repo, :only => [:show, :stats, :revisions, :revision, :diff ]
@ -95,6 +95,13 @@ class RepositoriesController < ApplicationController
end
# 一键ZIP下载
def project_archive
g = Gitlab.client
g.get()
# g.project_archive(params[:gpid].to_i, params[:rev])
end
# 判断用户是否已经fork过该项目
def has_forked?(project, user)
projects = Project.where("user_id =?", user)

View File

@ -0,0 +1,36 @@
class ShieldWechatMessagesController < ApplicationController
def create
if params[:user_id]
@user = User.find params[:user_id]
if params[:project_id]
ShieldWechatMessage.create(:container_type => 'User', :container_id => params[:user_id].to_i, :shield_type => 'Project', :shield_id => params[:project_id].to_i)
#@cp = 1
#@projects = @user.projects.visible.select("projects.*, (SELECT MAX(updated_at) FROM `forge_activities` WHERE forge_activities.project_id = projects.id) AS a").order("a desc").limit(5)
elsif params[:course_id]
ShieldWechatMessage.create(:container_type => 'User', :container_id => params[:user_id].to_i, :shield_type => 'Course', :shield_id => params[:course_id].to_i)
#@cp = 0
#@courses = @user.courses.visible.where("is_delete =?", 0).select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS a").order("a desc").limit(5)
end
end
end
def show_messages
if params[:user_id]
@user = User.find params[:user_id]
if params[:project_id]
ShieldWechatMessage.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
#@cp = 1
#@projects = @user.projects.visible.select("projects.*, (SELECT MAX(updated_at) FROM `forge_activities` WHERE forge_activities.project_id = projects.id) AS a").order("a desc").limit(5)
# 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]
ShieldWechatMessage.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
#@cp = 0
#@courses = @user.courses.visible.where("is_delete =?", 0).select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS a").order("a desc").limit(5)
end
end
end
end

View File

@ -0,0 +1,71 @@
#coding=utf-8
require 'base64'
require 'json'
require 'openssl'
## 单点登录 <=> 北斗
class SsosController < ApplicationController
skip_before_filter :check_if_login_required
layout false
def show
begin
# suRh2nFEJd0Ai_TFbqZ-1yQXnGfIB-YD_f4KTA3O4dQGSBMiXfOMt-0mzizgXekWTjHKfn62nJ60iHM3_eY_KS0Qn8SF8vANfa46GhzZRt4T0iC5ZOSs4cWeK43OU0RoekQLZZAo5OyOVibxabmiPGzEFCnVVtdmRk9d7X_B0Is=
@auth = params[:auth]
@options = parse(params[:auth])
if params[:login].present?
@options["name"] = params[:login]
end
logger.debug @options
## 认证
sso = login(@options)
## 加入组织
@organization = Organization.find(82)
unless @organization.org_members.exists?(user_id: sso.user_id)
member = OrgMember.new(:user_id => sso.user_id)
@organization.org_members << member
end
## 选择性跳转
redirect_to @organization
rescue => e
logger.error e
if e.message == "exist user"
render 'ssos/show', :layout => false
else
raise e
end
end
end
## 改用户名
def create
show and return
end
private
def base64_safe(content)
content = content.gsub('-', '+')
content.gsub('_', '/')
end
def parse(auth)
crypted_str = Base64.decode64(base64_safe(auth))
pkey = OpenSSL::PKey::RSA.new(File.new(File.join(Rails.root,"config/private.key")))
content = pkey.private_decrypt(crypted_str,OpenSSL::PKey::RSA::PKCS1_PADDING)
# content = pkey.private_decrypt(crypted_str)
ActiveSupport::JSON.decode(content)
end
def login(opt)
sso = Sso.sync_user(opt)
start_user_session(sso.user)
sso
end
end

View File

@ -519,8 +519,8 @@ class StudentWorkController < ApplicationController
return
end
@student_work_count = (search_homework_member @homework.student_works.select("student_works.*,student_works.work_score as score").order("#{@order} #{@b_sort}"),@name).count
end
end
@score = @b_sort == "desc" ? "asc" : "desc"
@is_focus = params[:is_focus] ? params[:is_focus].to_i : 0
# 消息传过来的ID
@ -618,7 +618,7 @@ class StudentWorkController < ApplicationController
stu_project.save
end
end
@homework.update_attributes(:updated_at => Time.now)
@homework.update_column(:updated_at, Time.now)
update_course_activity(@homework.class,@homework.id)
update_user_activity(@homework.class,@homework.id)
update_org_activity(@homework.class,@homework.id)
@ -780,49 +780,64 @@ class StudentWorkController < ApplicationController
#老师、教辅可以随时评分,学生只能在匿评作业的匿评阶段进行评分
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] != ""
@score.score = params[:score] if params[:score]
if User.current.admin?
@score.reviewer_role = 1
else
role = User.current.members.where("course_id = ?",@course.id).first.roles.first.name
@score.reviewer_role = get_role_by_name(role)
end
@is_new = false
#@score.comment = params[:new_form][:user_message] if params[:new_form] && params[:new_form][:user_message] && params[:new_form][:user_message] != ""
#@score.score = params[:score] if params[:score]
#if User.current.admin?
# @score.reviewer_role = 1
#else
# role = User.current.members.where("course_id = ?",@course.id).first.roles.first.name
# @score.reviewer_role = get_role_by_name(role)
#end
#@is_new = false
@is_last_a = @work.student_works_scores.empty?
@new_score = StudentWorksScore.new
if @score && params[:score]
@new_score.score = params[:score].to_i == -1 ? @score.score : params[:score]
elsif @score.nil? && params[:score]
@new_score.score = params[:score].to_i == -1 ? nil : params[:score]
end
@new_score.comment = params[:new_form][:user_message] if params[:new_form] && params[:new_form][:user_message] && params[:new_form][:user_message] != ""
@new_score.user_id = User.current.id
@new_score.student_work_id = @work.id
if User.current.admin?
@new_score.reviewer_role = 1
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] != ""
@score.user_id = User.current.id
@score.student_work_id = @work.id
if User.current.admin?
@score.reviewer_role = 1
role = User.current.members.where("course_id = ?",@course.id).first.roles.first.name
@new_score.reviewer_role = get_role_by_name(role)
end
if @score
if @is_teacher
@is_new = true
@is_last_a = false
else
role = User.current.members.where("course_id = ?",@course.id).first.roles.first.name
@score.reviewer_role = get_role_by_name(role)
@is_new = false
end
else
@is_new = true
end
@score.save_attachments(params[:attachments])
render_attachment_warning_if_needed(@score)
@new_score.save_attachments(params[:attachments])
render_attachment_warning_if_needed(@new_score)
if @score.save
case @score.reviewer_role
if @new_score.save
case @new_score.reviewer_role
when 1 #教师评分:最后一个教师评分为最终评分
@work.teacher_score = @score.score
@work.teacher_score = @new_score.score
when 2 #教辅评分 教辅评分显示平均分
@work.teaching_asistant_score = @work.student_works_scores.where(:reviewer_role => 2).average(:score).try(:round, 2).to_f
#@work.teaching_asistant_score = @work.student_works_scores.where(:reviewer_role => 2).average(:score).try(:round, 2).to_f
ts_score = StudentWorksScore.find_by_sql("SELECT AVG(score) AS score FROM (SELECT * FROM (SELECT * FROM student_works_scores WHERE student_work_id = #{@work.id} AND reviewer_role = 2 AND score IS NOT NULL ORDER BY created_at DESC) AS t GROUP BY user_id) AS a")
@work.teaching_asistant_score = ts_score.first.score.nil? ? nil : ts_score.first.score.try(:round, 2).to_f
when 3 #学生评分 学生评分显示平均分
@work.student_score = @work.student_works_scores.where(:reviewer_role => 3).average(:score).try(:round, 2).to_f
#@work.student_score = @work.student_works_scores.where(:reviewer_role => 3).average(:score).try(:round, 2).to_f
stu_score = StudentWorksScore.find_by_sql("SELECT AVG(score) AS score FROM (SELECT * FROM (SELECT * FROM student_works_scores WHERE student_work_id = #{@work.id} AND reviewer_role = 3 ORDER BY created_at DESC) AS t GROUP BY user_id) AS a")
@work.student_score = stu_score.first.score.try(:round, 2).to_f
end
@homework.update_attributes(:updated_at => Time.now)
update_course_activity(@homework.class,@homework.id)
update_user_activity(@homework.class,@homework.id)
update_org_activity(@homework.class,@homework.id)
if @work.save
@work = @homework.student_works.select("student_works.*,student_works.work_score as score").where(:id => @work.id).first
respond_to do |format|
format.js
end
@ -855,6 +870,14 @@ class StudentWorkController < ApplicationController
end
end
#提交未评分的评语
def add_comments_to_work
@work = StudentWork.find params[:id]
respond_to do |format|
format.js
end
end
#为作品点赞
def praise_student_work
pt = PraiseTread.new
@ -959,7 +982,7 @@ class StudentWorkController < ApplicationController
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.update_column('teacher_priority', teacher_priority)
homework_detail_manual.save if homework_detail_manual
homework_detail_programing.save if homework_detail_programing
@ -1010,6 +1033,10 @@ class StudentWorkController < ApplicationController
end
attachment = @work.attachments.where("attachtype = 7").first
attachment.update_attributes(:description => params[:description])
if attachment.attachtype == 7
student_work = StudentWork.find attachment.container_id
CourseMessage.create(:user_id => student_work.homework_common.user_id, :course_id => student_work.homework_common.course_id, :viewed => false,:course_message_id=>attachment.container_id,:course_message_type=>'StudentWork',:status=>2)
end
respond_to do |format|
format.js
end
@ -1167,7 +1194,7 @@ class StudentWorkController < ApplicationController
blue = Spreadsheet::Format.new :color => :blue, :weight => :bold, :size => 10
sheet1.row(0).default_format = blue
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),
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_homework_des),
l(:excel_t_score),l(:excel_ta_score), l(:excel_n_score),l(:excel_f_score),l(:excel_commit_time)])
count_row = 1
items.each do |homework|
@ -1177,15 +1204,16 @@ class StudentWorkController < ApplicationController
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,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,6] = strip_html homework.description
sheet1[count_row,7] = homework.teacher_score.nil? ? l(:label_without_score) : homework.teacher_score.round(2)
sheet1[count_row,8] = homework.teaching_asistant_score.nil? ? l(:label_without_score) : homework.teaching_asistant_score.round(2)
sheet1[count_row,9] = homework.student_score.nil? ? l(:label_without_score) : homework.student_score.round(2)
sheet1[count_row,10] = homework.respond_to?("score") ? homework.score.nil? ? l(:label_without_score) : homework.score.round(2) : l(:label_without_score)
sheet1[count_row,11] = format_time(homework.created_at)
count_row += 1
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),
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_homework_des),
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|
@ -1195,12 +1223,13 @@ class StudentWorkController < ApplicationController
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.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)
sheet1[count_row,6] = homework.description
sheet1[count_row,7] = homework.teacher_score.nil? ? l(:label_without_score) : homework.teacher_score.round(2)
sheet1[count_row,8] = homework.teaching_asistant_score.nil? ? l(:label_without_score) : homework.teaching_asistant_score.round(2)
sheet1[count_row,9] = homework.system_score.nil? ? l(:label_without_score) : homework.system_score.round(2)
sheet1[count_row,10] = homework.student_score.nil? ? l(:label_without_score) : homework.student_score.round(2)
sheet1[count_row,11] = homework.respond_to?("score") ? homework.score.nil? ? l(:label_without_score) : homework.score.round(2) : l(:label_without_score)
sheet1[count_row,12] = format_time(homework.created_at)
count_row += 1
end
end
@ -1342,8 +1371,12 @@ class StudentWorkController < ApplicationController
final_score = final_ta_score + final_s_score
student_work.final_score = format("%.2f",final_score.to_f)
end
score = student_work.final_score - student_work.absence_penalty - student_work.late_penalty if student_work.final_score
student_work.work_score = format("%.2f",(score < 0 ? 0 : score).to_f) if score
if student_work.final_score
score = student_work.final_score - student_work.absence_penalty - student_work.late_penalty
student_work.work_score = format("%.2f",(score < 0 ? 0 : score).to_f) if score
else
student_work.work_score = nil
end
end
else #不考虑教师评分
if student_work.teaching_asistant_score.nil?
@ -1357,8 +1390,12 @@ class StudentWorkController < ApplicationController
final_score = final_ta_score + final_s_score
student_work.final_score = format("%.2f",final_score.to_f)
end
score = student_work.final_score - student_work.absence_penalty - student_work.late_penalty if student_work.final_score
student_work.work_score = format("%.2f",(score < 0 ? 0 : score).to_f) if score
if student_work.final_score
score = student_work.final_score - student_work.absence_penalty - student_work.late_penalty
student_work.work_score = format("%.2f",(score < 0 ? 0 : score).to_f) if score
else
student_work.work_score = nil
end
end
elsif homework.homework_type == 2 && homework.homework_detail_programing #编程作业-----设定:系统评分必定不为空
if homework.teacher_priority == 1 #教师优先
@ -1393,8 +1430,12 @@ class StudentWorkController < ApplicationController
final_score = final_sy_score + final_ts_score + final_st_score
student_work.final_score = format("%.2f",final_score.to_f)
end
score = student_work.final_score - student_work.absence_penalty - student_work.late_penalty if student_work.final_score
student_work.work_score = format("%.2f",(score < 0 ? 0 : score).to_f) if score
if student_work.final_score
score = student_work.final_score - student_work.absence_penalty - student_work.late_penalty
student_work.work_score = format("%.2f",(score < 0 ? 0 : score).to_f) if score
else
student_work.work_score = nil
end
end
else #不考虑教师评分
if student_work.teaching_asistant_score.nil? #教辅未评分
@ -1424,8 +1465,12 @@ class StudentWorkController < ApplicationController
final_score = final_sy_score + final_ts_score + final_st_score
student_work.final_score = format("%.2f",final_score.to_f)
end
score = student_work.final_score - student_work.absence_penalty - student_work.late_penalty if student_work.final_score
student_work.work_score = format("%.2f",(score < 0 ? 0 : score).to_f) if score
if student_work.final_score
score = student_work.final_score - student_work.absence_penalty - student_work.late_penalty
student_work.work_score = format("%.2f",(score < 0 ? 0 : score).to_f) if score
else
student_work.work_score = nil
end
end
end
end

View File

@ -0,0 +1,208 @@
class SubDocumentCommentsController < ApplicationController
before_filter :find_subdomain_and_subfield, :only => [:new, :create, :show, :index, :destroy, :edit]
before_filter :find_subfield_content, :only => [:show, :index]
helper :attachments,:organizations
layout 'base_sub_domain'
def new
@sub_document_comment = SubDocumentComment.new
end
def create
@sub_document_comment = SubDocumentComment.new(:sub_domain_id => params[:sub_domain_id], :creator_id => User.current.id, :org_subfield_id => params[:org_subfield_id])
@sub_document_comment.title = params[:sub_document_comment][:title]
@sub_document_comment.content = params[:sub_document_comment][:content]
# @sub_document_comment.save_attachments(params[:attachments])
if params[:field_id]
@sub_document_comment.org_subfield_id = params[:field_id].to_i
end
if @sub_document_comment.save
flash.keep[:notice] = l(:notice_successful_create)
redirect_to org_subfield_sub_domain_sub_document_comments_path(:org_subfield_id => @org_subfield.id, :sub_domain_id => @subdomain.id)
# EditorOfDocument.create(:editor_id => User.current.id, :org_document_comment_id => @sub_document_comment.id, :created_at => @sub_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
if @organization.is_public? || User.current.admin? || User.current.member_of_org?(@organization)
@document = SubDocumentComment.find(params[:id])
respond_to do |format|
format.html {render :layout => @organization.switch_type ? 'base_sub_domain' : 'base_org'}
end
else
render_403
end
end
def index
if @organization.is_public? || User.current.admin? || User.current.member_of_org?(@organization)
@documents = @subdomain.sub_document_comments.where("parent_id is null").order("created_at desc")
@is_remote = true
@limit = 20
@atta_count = @documents.count
@atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1
@offset ||= @atta_pages.offset
@documents = paginateHelper @documents,20
respond_to do |format|
format.html {render :layout => @organization.switch_type ? 'base_sub_domain' : 'base_org'}
end
else
render_403
end
end
def update
@sub_document = SubDocumentComment.find(params[:id])
@sub_document.update_attributes(:title => params[:sub_document_comment][:title], :content => params[:sub_document_comment][:content])
@organization = OrgSubfield.find(params[:org_subfield_id]).organization
# Attachment.attach_files(@org_document, params[:attachments])
# @org_document.save_attachments(params[:attachments])
if @sub_document.parent.nil?
act = OrgActivity.where("org_act_type='SubDocumentComment' and org_act_id =?", @sub_document.id).first
act.update_attributes(:updated_at => @sub_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
# render :action => 'index', :layout => @organization.switch_type ? 'base_sub_domain' : 'base_org'
redirect_to org_subfield_sub_domain_sub_document_comments_path(:org_subfield_id => params[:org_subfield_id], :sub_domain_id => params[:sub_domain_id])
# render :layout => @organization.switch_type ? 'base_sub_domain' : 'base_org'
# redirect_to organization_path(@organization)
else
redirect_to org_subfield_sub_domain_sub_document_comment_path(:org_subfield_id => params[:org_subfield_id], :sub_domain_id => params[:sub_domain_id])
end
}
end
end
def edit
@sub_document = SubDocumentComment.find(params[:id])
@flag = params[:flag]
render :layout => @organization.switch_type ? 'base_sub_domain' : 'base_org'
end
def add_reply
@document = SubDocumentComment.find(params[:id]).root
@subdomain = @document.sub_domain
@org_subfield = @subdomain.org_subfield
@organization = @org_subfield.organization
@act = OrgActivity.find(params[:id])
@comment = SubDocumentComment.new(:sub_domain_id => @document.sub_domain, :creator_id => User.current.id, :reply_id => params[:id])
@comment.content = params[:sub_content]
@document.children << @comment
@document.save
end
def add_reply_in_doc
@document = SubDocumentComment.find(params[:id]).root
@subdomain = @document.sub_domain
@org_subfield = @subdomain.org_subfield
@organization = @org_subfield.organization
@comment = SubDocumentComment.new(:sub_domain_id => @document.sub_domain_id, :creator_id => User.current.id, :reply_id => params[:id])
@comment.content = params[:flag] ? params[:sub_content] : params[:org_comment][:sub_content]
@document.children << @comment
@document.save
respond_to do |format|
format.html {redirect_to org_subfield_sub_domain_sub_document_comment_path(:id => @document.id, :org_subfield_id => @org_subfield.id, :sub_domain_id => @subdomain.id)}
end
end
def destroy
@sub_document_comment = SubDocumentComment.find(params[:id])
@sub_document_comment.destroy
rescue ActiveRecord::RecordNotFound
respond_to do |format|
# format.html{
# redirect_to org_subfield_sub_domain_sub_document_comments_path(:id => params[:sub_domain_id], :org_subfield_id => params[:org_subfield_id])
# }
format.js
end
end
def delete_reply
@sub_document_comment = OrgDocumentComment.find(params[:id])
@document = @sub_document_comment.root
org = @sub_document_comment.organization
@sub_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
private
def find_subdomain_and_subfield
@subdomain = SubDomain.find(params[:sub_domain_id])
@org_subfield = OrgSubfield.find(params[:org_subfield_id])
@organization = @org_subfield.organization
rescue ActiveRecord::RecordNotFound
# source_subdomain_subfield not found
render_404
end
def find_subfield_content
@subfield_content = @organization.org_subfields.order("priority")
end
end

View File

@ -0,0 +1,63 @@
class SubDomainsController < ApplicationController
layout 'base_org'
before_filter :find_org_subfield_and_subdomain, :only => [:show, :index, :domain_update_priority, :destroy, :update, :hide_sub_domain, :show_sub_domain]
def new
@subdomain = SubDomain.new
@org_subfield = OrgSubfield.find(params[:org_subfield_id])
@organization = @org_subfield.organization
end
def create
if SubDomain.where("org_subfield_id=#{params[:org_subfield_id]} and name=?",params[:name]).count == 0
@res = true
@subfield = OrgSubfield.find(params[:org_subfield_id])
@organization = @subfield.organization
@subdomain = SubDomain.create(:name => params[:name], :org_subfield_id => params[:org_subfield_id], :priority => @subfield.sub_domains.blank? ? 1 : @subfield.sub_domains.order("priority").last.priority + 1)
@subdomain.update_column(:field_type, params[:field_type])
else
@res = false
end
end
def update
@subdomain.update_column(:name, params[:name])
end
def domain_update_priority
@subdomain.update_attribute(:priority, params[:priority].to_i)
end
def destroy
@subdomain.destroy
end
def show
render_404
# @subfield_content = @organization.org_subfields.order("priority")
# render layout: @organization.switch_type ? 'base_sub_domain' : 'base_org'
end
def index
end
def hide_sub_domain
@subdomain.update_attribute(:hide, 1)
end
def show_sub_domain
@subdomain.update_attribute(:hide, 0)
end
private
def find_org_subfield_and_subdomain
@subfield = OrgSubfield.find(params[:org_subfield_id])
@subdomain = SubDomain.find(params[:id])
@organization = @subfield.organization
rescue ActiveRecord::RecordNotFound
# source_subdomain not found
render_404
end
end

View File

@ -85,6 +85,29 @@ class UsersController < ApplicationController
helper :issues
include UsersHelper
#展开所有回复
def show_all_replies
@comment = JournalsForMessage.find params[:comment].to_i
end
#二级回复
def reply_to
case params[:type]
when 'HomeworkCommon'
@reply = JournalsForMessage.find params[:reply_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]
@course_activity = params[:course_activity].to_i
end
respond_to do |format|
format.js
end
end
def refresh_changests
if !(@user.nil?) && !(@user.memberships.nil?)
@user.memberships.each do |member|
@ -288,6 +311,30 @@ class UsersController < ApplicationController
end
end
#处理引用作业的请求
#status 1 同意 2 拒绝
def dealwith_apply_homework
@msg = CourseMessage.find(params[:msg_id])
ah = ApplyHomework.where("user_id = ? and homework_common_id = ?",@msg.apply_user_id, @msg.course_message_id)
case params[:agree]
when 'Y'
unless ah.empty?
ah.first.update_column('status', 2)
CourseMessage.create(:user_id => @msg.apply_user_id, :course_id => @msg.course_id, :viewed => false,:content=> @msg.content,:course_message_id=>@msg.course_message_id,:content=>@msg.content,:course_message_type=>'HomeworkCommon',:status=>6,:apply_result=>1)
@msg.update_attributes(:apply_result=>1,:viewed=>1)
end
when 'N'
unless ah.empty?
ah.first.update_column('status', 3)
CourseMessage.create(:user_id => @msg.apply_user_id, :course_id => @msg.course_id, :viewed => false,:content=> @msg.content,:course_message_id=>@msg.course_message_id,:content=>@msg.content,:course_message_type=>'HomeworkCommon',:status=>6,:apply_result=>2)
@msg.update_attributes(:apply_result=>2,:viewed=>1)
end
end
respond_to do |format|
format.js
end
end
# added by bai
def show_score
@ -372,13 +419,51 @@ class UsersController < ApplicationController
end
# end
#引用作业请求弹框
def apply_homework
if User.current.logged?
@homework = HomeworkCommon.find params[:homework_id]
@state = 2
else
@state = 1
end
respond_to do |format|
format.js
end
end
#申请引用非公开作业
def apply_for_homework
if User.current.logged?
homework = HomeworkCommon.find params[:homework_id]
unless homework.nil?
ah = ApplyHomework.where("user_id = ? and homework_common_id = ?", User.current.id, params[:homework_id].to_i)
if ah.empty?
ApplyHomework.create(:user_id => params[:id].to_i, :homework_common_id => params[:homework_id].to_i, :status => 1)
Mailer.run.apply_for_homework_request(homework, User.current)
CourseMessage.create(:user_id => homework.user_id, :course_id => homework.course.id, :viewed => false,:course_message_id=>params[:homework_id].to_i,:course_message_type=>'HomeworkCommon',:status=>5,:apply_user_id=>params[:id].to_i,:content=>params[:content])
@state = 2
@ah = ApplyHomework.where("user_id = ? and homework_common_id = ?", params[:id].to_i, params[:homework_id].to_i).first
@homework = homework
else
@state = 3
end
end
else
@state = 1
end
respond_to do |format|
format.js
end
end
#用户作业列表
def user_homeworks
@order,@b_sort = params[:order] || "created_at",params[:sort] || "desc"
@user = User.current
@r_sort = @b_sort == "desc" ? "asc" : "desc"
if(params[:type].blank? || params[:type] == "1") #公共题库
visible_course = Course.where("is_public = 1 && is_delete = 0")
if(params[:type].blank? || params[:type] == "1") #题库
visible_course = Course.where("is_delete = 0")
visible_course_ids = visible_course.empty? ? "(-1)" : "(" + visible_course.map{|course| course.id}.join(",") + ")"
@homeworks = HomeworkCommon.where("course_id in #{visible_course_ids} and publish_time <= '#{Date.today}'").order("#{@order} #{@b_sort}")
elsif params[:type] == "2" #我的题库
@ -403,7 +488,7 @@ class UsersController < ApplicationController
user_course_ids = @user.courses.empty? ? "(-1)" :"(" + @user.courses.visible.map{|course| course.id}.join(",") + ")"
#判断当前用户在当前课程的身份
visibleCourse = @user.courses.empty? ? [] : @user.courses.visible
visibleCourse = @user.courses.empty? ? [] : @user.courses.where("is_delete = 0").visible
homework_ids = []
visibleCourse.each do |course|
homeworks = HomeworkCommon.where("course_id = #{course.id} and publish_time <= '#{Date.today}'")
@ -424,6 +509,14 @@ class UsersController < ApplicationController
def choose_user_course
homework = HomeworkCommon.find params[:send_id].to_i
if homework.user != User.current && homework.course.is_public == 0 && !User.current.allowed_to?(:as_teacher,homework.course)
ah = ApplyHomework.where("user_id = ? and homework_common_id = ?", User.current.id, params[:send_id].to_i)
if ah.empty?
@status = 2
elsif ah.first.status != 2
@status = ah.first.status
end
end
if !params[:search].nil?
search = "%#{params[:search].to_s.strip.downcase}%"
@course = @user.courses.where("is_delete = 0 and #{Course.table_name}.id != #{homework.course_id} and #{Course.table_name}.id = #{params[:search].to_i } or #{Course.table_name}.name like :p",:p=>search).select { |course| @user.allowed_to?(:as_teacher,course)}
@ -528,19 +621,40 @@ class UsersController < ApplicationController
@order,@b_sort = params[:order] || "created_at",params[:sort] || "desc"
@r_sort = @b_sort == "desc" ? "asc" : "desc"
@user = User.current
if(params[:type].blank? || params[:type] == "1") #公共题库
visible_course = Course.where("is_public = 1 && is_delete = 0")
if(params[:type].blank? || params[:type] == "1") #题库
if params[:is_import].to_i == 1
visible_course = Course.where("is_public = 1 && is_delete = 0")
elsif params[:is_import].to_i == 0
visible_course = Course.where("is_delete = 0")
end
visible_course_ids = visible_course.empty? ? "(-1)" : "(" + visible_course.map{|course| course.id}.join(",") + ")"
@homeworks = HomeworkCommon.where("course_id in #{visible_course_ids} and publish_time <= '#{Date.today}'").order("#{@order} #{@b_sort}")
elsif params[:type] == "2" #我的题库
@homeworks = HomeworkCommon.where("user_id = #{@user.id} and publish_time <= '#{Date.today}'").order("#{@order} #{@b_sort}")
courses = @user.courses.where("is_delete = 1")
course_ids = courses.empty? ? "(-1)" : "(" + courses.map{|course| course.id}.join(",") + ")"
@homeworks = HomeworkCommon.where("user_id = #{@user.id} and publish_time <= '#{Date.today}' and course_id not in #{course_ids}").order("#{@order} #{@b_sort}")
elsif params[:type] == "3" #申请题库
none_visible_course = Course.where("is_delete = 1")
none_visible_course_ids = none_visible_course.empty? ? "(-1)" : "(" + none_visible_course.map{|course| course.id}.join(",") + ")"
#apply_homeworks = ApplyHomework.where("user_id = ?",@user.id).order('created_at desc')
#homework_ids = apply_homeworks.empty? ? "(-1)" : "(" + apply_homeworks.map{|ah| ah.homework_common_id}.join(",") + ")"
#@homeworks = HomeworkCommon.where("id in #{homework_ids} and course_id not in #{none_visible_course_ids}")
sql = "SELECT homework_commons.* FROM homework_commons INNER JOIN apply_homeworks as ah ON homework_commons.id = ah.homework_common_id where ah.user_id = #{@user.id} and homework_commons.course_id not in #{none_visible_course_ids} order by ah.created_at desc"
@homeworks = HomeworkCommon.find_by_sql(sql)
end
if params[:property] && params[:property] == "1"
@homeworks = @homeworks.where("homework_type = 1").reorder("#{@order} #{@b_sort}")
elsif params[:property] && params[:property] == "2"
@homeworks = @homeworks.where("homework_type = 2").reorder("#{@order} #{@b_sort}")
elsif params[:property] && params[:property] == "3"
@homeworks = @homeworks.where("homework_type = 3").reorder("#{@order} #{@b_sort}")
if params[:property]
all_homework_ids = @homeworks.empty? ? "(-1)" : "(" + @homeworks.map{|h| h.id}.join(",") + ")"
if params[:property] == "1"
@homeworks = HomeworkCommon.find_by_sql("select * from homework_commons where id in #{all_homework_ids} and homework_type = 1")
#@homeworks = @homeworks.where("homework_type = 1").reorder("#{@order} #{@b_sort}")
elsif params[:property] == "2"
@homeworks = HomeworkCommon.find_by_sql("select * from homework_commons where id in #{all_homework_ids} and homework_type = 2")
#@homeworks = @homeworks.where("homework_type = 2").reorder("#{@order} #{@b_sort}")
elsif params[:property] == "3"
@homeworks = HomeworkCommon.find_by_sql("select * from homework_commons where id in #{all_homework_ids} and homework_type = 3")
#@homeworks = @homeworks.where("homework_type = 3").reorder("#{@order} #{@b_sort}")
end
end
@type = params[:type]
@property = params[:property]
@ -557,7 +671,21 @@ class UsersController < ApplicationController
end
def show_homework_detail
@homework = HomeworkCommon.find params[:homework].to_i
homework = HomeworkCommon.find params[:homework].to_i
if homework.course.is_public == 0 && !User.current.allowed_to?(:as_teacher,homework.course) && User.current != homework.user
ah = ApplyHomework.where("user_id = ? and homework_common_id = ?", User.current.id, params[:homework].to_i)
if ah.empty?
@status = 2
@homework = nil
elsif ah.first.status != 2
@status = ah.first.status
@homework = nil
elsif ah.first.status == 2
@homework = homework
end
else
@homework = homework
end
@is_import = params[:is_import]
respond_to do |format|
format.js
@ -571,8 +699,12 @@ class UsersController < ApplicationController
@user = User.current
search = params[:name].to_s.strip.downcase
type_ids = params[:property]=="" || params[:property].nil? ? "(1, 2, 3)" : "(" + params[:property] + ")"
if(params[:type].blank? || params[:type] == "1") #全部
visible_course = Course.where("is_public = 1 && is_delete = 0")
if(params[:type].blank? || params[:type] == "1") #全部
if params[:is_import].to_i == 1
visible_course = Course.where("is_public = 1 && is_delete = 0")
elsif params[:is_import].to_i == 0
visible_course = Course.where("is_delete = 0")
end
visible_course_ids = visible_course.empty? ? "(-1)" : "(" + visible_course.map{|course| course.id}.join(",") + ")"
all_homeworks = HomeworkCommon.where("course_id in #{visible_course_ids} and publish_time <= '#{Date.today}'")
all_user_ids = all_homeworks.map{|hw| hw.user_id}
@ -586,14 +718,29 @@ class UsersController < ApplicationController
else
@homeworks = HomeworkCommon.where("course_id in #{visible_course_ids} and publish_time <= '#{Date.today}' and homework_type in #{type_ids} and (name like '%#{search}%' or user_id in #{user_ids})").order("#{@order} #{@b_sort}")
end
elsif params[:type] == "2" #课程资源
elsif params[:type] == "2" #我的题库
courses = @user.courses.where("is_delete = 1")
course_ids = courses.empty? ? "(-1)" : "(" + courses.map{|course| course.id}.join(",") + ")"
if @order == "course_name"
sql = "SELECT homework_commons.* FROM homework_commons INNER JOIN courses ON homework_commons.course_id = courses.id where homework_commons.user_id = #{@user.id} and homework_type in #{type_ids} and publish_time <= '#{Date.today}' and (homework_commons.name like '%#{search}%') order by CONVERT (courses.name USING gbk) COLLATE gbk_chinese_ci #{@b_sort}"
sql = "SELECT homework_commons.* FROM homework_commons INNER JOIN courses ON homework_commons.course_id = courses.id where homework_commons.course_id not in #{course_ids} and homework_commons.user_id = #{@user.id} and homework_type in #{type_ids} and publish_time <= '#{Date.today}' and (homework_commons.name like '%#{search}%') order by CONVERT (courses.name USING gbk) COLLATE gbk_chinese_ci #{@b_sort}"
@homeworks = HomeworkCommon.find_by_sql(sql)
elsif @order == "user_name"
@homeworks = HomeworkCommon.where("user_id = #{@user.id} and publish_time <= '#{Date.today}' and (name like '%#{search}%') and homework_type in #{type_ids}").joins(:user).order("CONVERT (lastname USING gbk) COLLATE gbk_chinese_ci #{@b_sort}, CONVERT (firstname USING gbk) COLLATE gbk_chinese_ci #{@b_sort},login #{@b_sort}")
@homeworks = HomeworkCommon.where("user_id = #{@user.id} and course_id not in #{course_ids} and publish_time <= '#{Date.today}' and (name like '%#{search}%') and homework_type in #{type_ids}").joins(:user).order("CONVERT (lastname USING gbk) COLLATE gbk_chinese_ci #{@b_sort}, CONVERT (firstname USING gbk) COLLATE gbk_chinese_ci #{@b_sort},login #{@b_sort}")
else
@homeworks = HomeworkCommon.where("user_id = #{@user.id} and publish_time <= '#{Date.today}' and (name like '%#{search}%') and homework_type in #{type_ids}").order("#{@order} #{@b_sort}")
@homeworks = HomeworkCommon.where("user_id = #{@user.id} and course_id not in #{course_ids} and publish_time <= '#{Date.today}' and (name like '%#{search}%') and homework_type in #{type_ids}").order("#{@order} #{@b_sort}")
end
elsif params[:type] == "3" #申请题库
apply_homeworks = ApplyHomework.where("user_id = ?",@user.id)
homework_ids = apply_homeworks.empty? ? "(-1)" : "(" + apply_homeworks.map{|ah| ah.homework_common_id}.join(",") + ")"
none_visible_course = Course.where("is_delete = 1")
none_visible_course_ids = none_visible_course.empty? ? "(-1)" : "(" + none_visible_course.map{|course| course.id}.join(",") + ")"
if @order == "course_name"
sql = "SELECT homework_commons.* FROM homework_commons INNER JOIN courses ON homework_commons.course_id = courses.id where courses.is_delete = 0 and homework_commons.id in #{homework_ids} and homework_type in #{type_ids} and publish_time <= '#{Date.today}' and (homework_commons.name like '%#{search}%') order by CONVERT (courses.name USING gbk) COLLATE gbk_chinese_ci #{@b_sort}"
@homeworks = HomeworkCommon.find_by_sql(sql)
elsif @order == "user_name"
@homeworks = HomeworkCommon.where("homework_commons.id in #{homework_ids} and course_id not in #{none_visible_course_ids} and (name like '%#{search}%') and homework_type in #{type_ids}").joins(:user).order("CONVERT (lastname USING gbk) COLLATE gbk_chinese_ci #{@b_sort}, CONVERT (firstname USING gbk) COLLATE gbk_chinese_ci #{@b_sort},login #{@b_sort}")
else
@homeworks = HomeworkCommon.where("id in #{homework_ids} and (name like '%#{search}%') and course_id not in #{none_visible_course_ids} and homework_type in #{type_ids}").order("#{@order} #{@b_sort}")
end
end
=begin
@ -750,7 +897,11 @@ class UsersController < ApplicationController
render_attachment_warning_if_needed(homework)
homework_detail_manual = HomeworkDetailManual.new
homework_detail_manual.ta_proportion = homework.homework_type == 1 ? 0.6 : 0.3
if homework.anonymous_comment == 1
homework_detail_manual.ta_proportion = homework.homework_type == 1 ? 1.0 : 0.4
else
homework_detail_manual.ta_proportion = homework.homework_type == 1 ? 0.6 : 0.3
end
if homework.publish_time > Date.today
homework_detail_manual.comment_status = 0
else
@ -766,7 +917,11 @@ class UsersController < ApplicationController
if homework.homework_type == 2
homework_detail_programing = HomeworkDetailPrograming.new
homework.homework_detail_programing = homework_detail_programing
homework_detail_programing.ta_proportion = 0.5
if homework.anonymous_comment == 1
homework_detail_programing.ta_proportion = 0.6
else
homework_detail_programing.ta_proportion = 0.5
end
homework_detail_programing.language = params[:language_type].to_i
inputs = params[:program][:input]
@ -1216,7 +1371,7 @@ class UsersController < ApplicationController
shield_course_ids = ShieldActivity.select("shield_id").where("container_type='User' and container_id=#{@user.id} and shield_type='Course'").map(&:shield_id)
@page = params[:page] ? params[:page].to_i + 1 : 0
user_project_ids = (@user.projects.visible.map{|project| project.id}-shield_project_ids).empty? ? "(-1)" : "(" + (@user.projects.visible.map{|project| project.id}-shield_project_ids).join(",") + ")"
user_course_ids = (@user.courses.visible.map{|course| course.id}-shield_course_ids).empty? ? "(-1)" : "(" + (@user.courses.visible.map{|course| course.id}-shield_course_ids).join(",") + ")"
user_course_ids = (@user.courses.visible.where("is_delete = 0").map{|course| course.id}-shield_course_ids).empty? ? "(-1)" : "(" + (@user.courses.visible.where("is_delete = 0").map{|course| course.id}-shield_course_ids).join(",") + ")"
course_types = "('Message','News','HomeworkCommon','Poll','Course','JournalsForMessage')"
project_types = "('Message','Issue','ProjectCreateInfo')"
principal_types = "JournalsForMessage"
@ -2463,6 +2618,9 @@ class UsersController < ApplicationController
# 获取我的资源
def get_my_resources author_id, user_course_ids, user_project_ids, order, score
unless author_id.to_i.to_s == author_id
author_id = User.find_by_login(author_id).id
end
attachments = Attachment.where("(author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type in('OrgSubfield','Principal','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) "+
"or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}) and is_publish = 1 and container_id is not null)" +
"or (container_type = 'Project' and container_id in (#{user_project_ids.empty? ? '0': user_project_ids.join(',')}) and is_publish = 1 and container_id is not null)" ).order("#{order.nil? ? 'created_on' : order} #{score}")
@ -2470,6 +2628,7 @@ class UsersController < ApplicationController
# 获取我的资源查询结果
def get_my_resources_search (author_id, user_course_ids, user_project_ids, order, score, search)
author_id = User.find_by_login(author_id).id
@attachments = Attachment.where("((author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) "+
"or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}) and is_publish = 1 and container_id is not null)" +
"or (container_type = 'Project' and container_id in (#{user_project_ids.empty? ? '0': user_project_ids.join(',')}) and is_publish = 1 and container_id is not null)) and (filename like :p)" ,:p => search).order("#{order.nil? ? 'created_on' : order} #{score}")
@ -2477,6 +2636,7 @@ class UsersController < ApplicationController
# 获取我的课程资源
def get_course_resources author_id, user_course_ids, order, score
author_id = User.find_by_login(author_id).id
attchments = Attachment.where("(author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type = 'Course')"+
"or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')})
and is_publish = 1 and container_id is not null)" ).order("#{order.nil? ? 'created_on' : order} #{score}")
@ -2484,6 +2644,7 @@ class UsersController < ApplicationController
# 获取我的课程资源中搜索结果
def get_course_resources_search author_id, user_course_ids, order, score, search
author_id = User.find_by_login(author_id).id
attchments = Attachment.where("((author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type = 'Course')"+
"or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')})
and is_publish = 1 and container_id is not null)) and (filename like :p)", :p => search ).order("#{order.nil? ? 'created_on' : order} #{score}")
@ -2501,6 +2662,7 @@ class UsersController < ApplicationController
# 获取我的项目资源
def get_project_resources author_id, user_project_ids, order, score
author_id = User.find_by_login(author_id).id
attchments = Attachment.where("(author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type = 'Project') "+
"or (container_type = 'Project' and container_id in (#{user_project_ids.empty? ? '0': user_project_ids.join(',')})
and is_publish = 1 and container_id is not null)").order("#{order.nil? ? 'created_on' : order} #{score}")
@ -2508,6 +2670,7 @@ class UsersController < ApplicationController
# 获取我的项目资源搜索
def get_project_resources_search author_id, user_project_ids, order, score, search
author_id = User.find_by_login(author_id).id
attchments = Attachment.where("((author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type = 'Project') "+
"or (container_type = 'Project' and container_id in (#{user_project_ids.empty? ? '0': user_project_ids.join(',')})
and is_publish = 1 and container_id is not null)) and (filename like :p)", :p => search ).order("#{order.nil? ? 'created_on' : order} #{score}")
@ -2525,12 +2688,14 @@ class UsersController < ApplicationController
# 获取我上传的附件
def get_attch_resources author_id, order, score
author_id = User.find_by_login(author_id).id
attchments = Attachment.where("(author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course','Issue',
'Document','Message','News','StudentWorkScore','HomewCommon'))").order("#{order.nil? ? 'created_on' : order} #{score}")
end
# 获取我上传的附件搜索结果
def get_attch_resources_search author_id, order, score, search
author_id = User.find_by_login(author_id).id
attchments = Attachment.where("(author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course','Issue',
'Document','Message','News','StudentWorkScore','HomewCommon')) and (filename like :p)", :p => search ).order("#{order.nil? ? 'created_on' : order} #{score}")
end
@ -2549,11 +2714,13 @@ class UsersController < ApplicationController
# 获取我的用户类型资源
def get_principal_resources author_id, order, score
author_id = User.find_by_login(author_id).id
attchments = Attachment.where("author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type = 'Principal'").order("#{order.nil? ? 'created_on' : order} #{score}")
end
# 获取我的用户类型资源搜索
def get_principal_resources_search author_id, order, score, search
author_id = User.find_by_login(author_id).id
attchments = Attachment.where("(author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type = 'Principal') and (filename like :p)", :p => search).order("#{order.nil? ? 'created_on' : order} #{score}")
end
@ -2570,7 +2737,7 @@ class UsersController < ApplicationController
# 资源库 分为全部 课程资源 项目资源 附件
def user_resource
# 别人的资源库是没有权限去看的
if User.current.id.to_i != params[:id].to_i
if User.current.id.to_i != @user.id.to_i
render_403
return
end
@ -2625,13 +2792,13 @@ class UsersController < ApplicationController
# 导入资源
def import_resources
# 别人的资源库是没有权限去看的
if User.current.id.to_i != params[:id].to_i
@user = User.find_by_login(params[:id])
if User.current != @user
render_403
return
end
@resource_id = params[:project_id].nil? ? (params[:course_id].nil? ? params[:subfield_file_id] : params[:course_id]) : params[:project_id]
@resource_type = params[:project_id].nil? ? (params[:course_id].nil? ? "SubfieldFile" : "Course") : "Project"
@user = User.find(params[:id])
@order, @b_sort = params[:order] || "created_on", params[:sort] || "asc"
@score = @b_sort == "desc" ? "asc" : "desc"
user_course_ids = User.current.courses.map { |c| c.is_delete == 0 && c.id}
@ -2731,6 +2898,10 @@ class UsersController < ApplicationController
attach_copied_obj.attachtype = 4
end
attach_copied_obj.save
# 附件保存成功后更新项目和课程的统计数
if params[:mul_type] == "Project"
mul_container.project_score.update_attribute(:attach_num, mul_container.project_score.attach_num + 1) unless mul_container.project_score.nil?
end
@save_message = attach_copied_obj.errors.full_messages
end
end

View File

@ -0,0 +1,237 @@
#coding=utf-8
class WechatsController < ActionController::Base
wechat_responder
include ApplicationHelper
# default text responder when no other match
on :text do |request, content|
request.reply.text "您的意见已收到" # Just echo
end
# When receive 'help', will trigger this responder
on :text, with: 'help' do |request|
request.reply.text 'help content'
end
# When receive '<n>news', will match and will got count as <n> as parameter
on :text, with: /^(\d+) news$/ do |request, count|
# Wechat article can only contain max 10 items, large than 10 will dropped.
news = (1..count.to_i).each_with_object([]) { |n, memo| memo << { title: 'News title', content: "No. #{n} news content" } }
request.reply.news(news) do |article, n, index| # article is return object
article.item title: "#{index} #{n[:title]}", description: n[:content], pic_url: 'http://www.baidu.com/img/bdlogo.gif', url: 'http://www.baidu.com/'
end
end
on :event, with: 'subscribe' do |request|
default_msg(request)
end
# When unsubscribe user scan qrcode qrscene_xxxxxx to subscribe in public account
# notice user will subscribe public account at same time, so wechat won't trigger subscribe event any more
on :scan, with: 'qrscene_xxxxxx' do |request, ticket|
request.reply.text "Unsubscribe user #{request[:FromUserName]} Ticket #{ticket}"
end
# When subscribe user scan scene_id in public account
on :scan, with: 'scene_id' do |request, ticket|
request.reply.text "Subscribe user #{request[:FromUserName]} Ticket #{ticket}"
end
# When no any on :scan responder can match subscribe user scaned scene_id
on :event, with: 'scan' do |request|
if request[:EventKey].present?
request.reply.text "event scan got EventKey #{request[:EventKey]} Ticket #{request[:Ticket]}"
end
end
# When enterprise user press menu BINDING_QR_CODE and success to scan bar code
on :scan, with: 'BINDING_QR_CODE' do |request, scan_result, scan_type|
request.reply.text "User #{request[:FromUserName]} ScanResult #{scan_result} ScanType #{scan_type}"
end
# Except QR code, wechat can also scan CODE_39 bar code in enterprise account
on :scan, with: 'BINDING_BARCODE' do |message, scan_result|
if scan_result.start_with? 'CODE_39,'
message.reply.text "User: #{message[:FromUserName]} scan barcode, result is #{scan_result.split(',')[1]}"
end
end
# When user click the menu button
on :click, with: 'BOOK_LUNCH' do |request, key|
request.reply.text "User: #{request[:FromUserName]} click #{key}"
end
# When user view URL in the menu button
on :view, with: 'http://wechat.somewhere.com/view_url' do |request, view|
request.reply.text "#{request[:FromUserName]} view #{view}"
end
# When user sent the imsage
on :image do |request|
request.reply.image(request[:MediaId]) # Echo the sent image to user
end
# When user sent the voice
on :voice do |request|
request.reply.voice(request[:MediaId]) # Echo the sent voice to user
end
# When user sent the video
on :video do |request|
nickname = wechat.user(request[:FromUserName])['nickname'] # Call wechat api to get sender nickname
request.reply.video(request[:MediaId], title: 'Echo', description: "Got #{nickname} sent video") # Echo the sent video to user
end
# When user sent location
on :location do |request|
request.reply.text("Latitude: #{message[:Latitude]} Longitude: #{message[:Longitude]} Precision: #{message[:Precision]}")
end
on :event, with: 'unsubscribe' do |request|
request.reply.success # user can not receive this message
end
# When user enter the app / agent app
on :event, with: 'enter_agent' do |request|
request.reply.text "#{request[:FromUserName]} enter agent app now"
end
# When batch job create/update user (incremental) finished.
on :batch_job, with: 'sync_user' do |request, batch_job|
request.reply.text "sync_user job #{batch_job[:JobId]} finished, return code #{batch_job[:ErrCode]}, return message #{batch_job[:ErrMsg]}"
end
# When batch job replace user (full sync) finished.
on :batch_job, with: 'replace_user' do |request, batch_job|
request.reply.text "replace_user job #{batch_job[:JobId]} finished, return code #{batch_job[:ErrCode]}, return message #{batch_job[:ErrMsg]}"
end
# When batch job invent user finished.
on :batch_job, with: 'invite_user' do |request, batch_job|
request.reply.text "invite_user job #{batch_job[:JobId]} finished, return code #{batch_job[:ErrCode]}, return message #{batch_job[:ErrMsg]}"
end
# When batch job replace department (full sync) finished.
on :batch_job, with: 'replace_party' do |request, batch_job|
request.reply.text "replace_party job #{batch_job[:JobId]} finished, return code #{batch_job[:ErrCode]}, return message #{batch_job[:ErrMsg]}"
end
# Any not match above will fail to below
on :fallback, respond: 'fallback message'
on :click, with: 'FEEDBACK' do |request, key|
request.reply.text "如有反馈问题,请直接切入至输入框,发微信给我们即可"
end
on :click, with: 'MY_NEWS' do |request, key|
default_msg(request)
end
def default_msg(request)
uw = user_binded?(request[:FromUserName])
if uw && uw.user
request.reply.text "欢迎回来, #{uw.user.show_name}"
else
request.reply.text "欢迎关注Trustie创新实践社区"
sendBind(request)
end
end
def sendBind(request)
news = (1..1).each_with_object([]) { |n, memo| memo << { title: '绑定登录', content: "您还未绑定确实的用户,请先绑定." } }
request.reply.news(news) do |article, n, index| # article is return object
url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=#{Wechat.config.appid}&redirect_uri=#{login_wechat_url}&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect"
article.item title: "#{n[:title]}",
description: n[:content],
pic_url: 'https://www.trustie.net/images/trustie_logo2.png',
url: url
end
end
def get_open_id
begin
raise "非法操作, code不存在" unless params[:code]
openid = get_openid_from_code(params[:code])
raise "无法获取到openid" unless openid
render :json => {status:0, openid: openid}
rescue Exception=>e
render :json => {status: -1, msg: e.message}
end
end
def bind
begin
raise "非法操作, code不存在" unless params[:code]
openid = get_openid_from_code(params[:code])
raise "无法获取到openid" unless openid
raise "此微信号已绑定用户, 不能得复绑定" if user_binded?(openid)
user, last_login_on = User.try_to_login(params[:username], params[:password])
raise "用户名或密码错误,请重新登录" unless user
#补全用户信息
raise "此用户已经绑定了公众号" if user.user_wechat
UserWechat.create!(
openid: openid,
user: user
)
request.reply.text "欢迎加入Trustie创新实践社区"
render :json => {status:0, msg: "绑定成功"}
rescue Exception=>e
render :json => {status: -1, msg: e.message}
end
end
def login
@code = params[:code] #TODO 安全性
render 'wechats/login', layout: 'base_wechat'
end
private
def get_openid_from_code(code)
url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=#{Wechat.config.appid}&secret=#{Wechat.config.secret}&code=#{code}&grant_type=authorization_code"
logger.debug url
body = URI.parse(url).read
logger.debug body
JSON.parse(body)["openid"]
end
def user_binded?(openid)
uw = UserWechat.where(openid: openid).first
end
def user_activity(user)
@user = user
shield_project_ids = ShieldActivity.where("container_type='User' and container_id=#{@user.id} and shield_type='Project'").map(&:shield_id)
shield_course_ids = ShieldActivity.where("container_type='User' and container_id=#{@user.id} and shield_type='Course'").map(&:shield_id)
@page = params[:page] ? params[:page].to_i + 1 : 0
user_project_ids = (@user.projects.visible.map{|project| project.id}-shield_project_ids).empty? ? "(-1)" : "(" + (@user.projects.visible.map{|project| project.id}-shield_project_ids).join(",") + ")"
user_course_ids = (@user.courses.visible.map{|course| course.id}-shield_course_ids).empty? ? "(-1)" : "(" + (@user.courses.visible.map{|course| course.id}-shield_course_ids).join(",") + ")"
course_types = "('Message','News','HomeworkCommon','Poll','Course')"
project_types = "('Message','Issue','ProjectCreateInfo')"
principal_types = "JournalsForMessage"
blog_ids = "("+@user.blog.id.to_s+","+((User.watched_by(@user.id).count == 0 )? '0' :User.watched_by(@user.id).map{|u| u.blog.id}.join(','))+")"
@user_activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types})" +
"or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}) "+
"or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{@user.id}) " +
"or (container_type = 'Blog' and act_type= 'BlogComment' and container_id in #{blog_ids})").order('updated_at desc').limit(10).offset(@page * 10)
end
def process_activity(user_activity)
act= user_activity.act
case user_activity.container_type.to_s
when 'Course'
when 'Project'
case user_activity.act_type.to_s
when 'Issue'
[act.project.name.to_s+" | 项目问题", act.subject.to_s, url_to_avatar(act.author),"http://wechat.trustie.net/app.html#/issue/#{act.id}"]
end
end
end
end

View File

@ -276,7 +276,7 @@ class WordsController < ApplicationController
ids = params[:asset_id].split(',')
update_kindeditor_assets_owner ids,feedback[:id],OwnerTypeHelper::JOURNALSFORMESSAGE
end
@homework_common.update_attributes(:updated_at => Time.now)
@homework_common.update_column('updated_at', Time.now)
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)
@ -296,6 +296,40 @@ class WordsController < ApplicationController
render_403
end
end
#作业的二级回复
def reply_to_homework
if User.current.logged?
@user = User.current
reply = JournalsForMessage.find params[:id].to_i
@homework_common = HomeworkCommon.find reply.jour_id
if params[:reply_message].size>0 && User.current.logged? && @user
options = {:notes => params[:reply_message], :reply_id => reply.user_id,:user_id => @user.id,:m_parent_id => params[:id].to_i,:m_reply_id => params[:id].to_i}
feedback = HomeworkCommon.add_homework_jour(@user, params[:reply_message], reply.jour_id, options)
if (feedback.errors.empty?)
if params[:asset_id]
ids = params[:asset_id].split(',')
update_kindeditor_assets_owner ids,feedback[:id],OwnerTypeHelper::JOURNALSFORMESSAGE
end
@homework_common.update_column('updated_at', Time.now)
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].to_i
@is_in_course = params[:is_in_course].to_i
@course_activity = params[:course_activity].to_i
}
end
else
flash[:error] = feedback.errors.full_messages[0]
end
end
else
render_403
end
end
def add_brief_introdution
user = User.current

View File

@ -27,6 +27,10 @@ module ApiHelper
location
end
def get_user_realname user
name = user.lastname + user.firstname
name.empty? || name.nil? || name == " " ? user.login : name
end
def get_assigned_homeworks(homeworks, n, index)
homeworks += homeworks
@ -201,5 +205,288 @@ module ApiHelper
end
#日期转换为时间
def convert_to_time date, num
if num == 0
date = date.to_s + " 00:00"
elsif num == 1
date = date.to_s + " 23:59"
end
return date
end
#获取用户
def get_user user_id
user = User.find user_id
user
end
#获取项目
def get_project project_id
project = Project.find project_id
project
end
#获取课程
def get_course course_id
course = Course.find course_id
course
end
#获取点赞数
def get_activity_praise_num(object)
obj_type = object.class
obj_id = object.id
record = PraiseTreadCache.find_by_object_id_and_object_type(obj_id,obj_type)
if record
return ((record.praise_num.nil? ? 0 : record.praise_num.to_i)-(record.tread_num.nil? ? 0 : record.tread_num.to_i))
else
return 0
end
end
#获取缺陷的优先级
def get_issue_priority_api value
issuetype = ""
if value == 4
issuetype = "紧急"
elsif value == 2
issuetype = "正常"
elsif value == 3
issuetype = ""
elsif value == 1
issuetype = ""
else
issuetype = "立刻"
end
end
def jdetails_to_strings(details, no_html=false, options={})
options[:only_path] = (options[:only_path] == false ? false : true)
options[:token] = options[:token] if options[:token]
strings = []
values_by_field = {}
details.each do |detail|
if detail.property == 'cf'
field_id = detail.prop_key
field = CustomField.find_by_id(field_id)
if field && field.multiple?
values_by_field[field_id] ||= {:added => [], :deleted => []}
if detail.old_value
values_by_field[field_id][:deleted] << detail.old_value
end
if detail.value
values_by_field[field_id][:added] << detail.value
end
next
end
end
strings << jshow_detail(detail, no_html, options)
end
values_by_field.each do |field_id, changes|
detail = JournalDetail.new(:property => 'cf', :prop_key => field_id)
if changes[:added].any?
detail.value = changes[:added]
strings << jshow_detail(detail, no_html, options)
elsif changes[:deleted].any?
detail.old_value = changes[:deleted]
strings << jshow_detail(detail, no_html, options)
end
end
strings
end
# Returns the textual representation of a single journal detail
def jshow_detail(detail, no_html=false, options={})
multiple = false
case detail.property
when 'attr'
field = detail.prop_key.to_s.gsub(/\_id$/, "")
label = l(("field_" + field).to_sym)
case detail.prop_key
when 'due_date', 'start_date'
value = format_date(detail.value.to_date) if detail.value
old_value = format_date(detail.old_value.to_date) if detail.old_value
when 'project_id', 'status_id', 'tracker_id', 'assigned_to_id',
'priority_id', 'category_id', 'fixed_version_id'
value = find_name_by_reflection(field, detail.value)
old_value = find_name_by_reflection(field, detail.old_value)
when 'estimated_hours'
value = "%0.02f" % detail.value.to_f unless detail.value.blank?
old_value = "%0.02f" % detail.old_value.to_f unless detail.old_value.blank?
when 'parent_id'
label = l(:field_parent_issue)
value = "##{detail.value}" unless detail.value.blank?
old_value = "##{detail.old_value}" unless detail.old_value.blank?
when 'is_private'
value = l(detail.value == "0" ? :general_text_No : :general_text_Yes) unless detail.value.blank?
old_value = l(detail.old_value == "0" ? :general_text_No : :general_text_Yes) unless detail.old_value.blank?
end
when 'cf'
custom_field = CustomField.find_by_id(detail.prop_key)
if custom_field
multiple = custom_field.multiple?
label = custom_field.name
value = format_value(detail.value, custom_field.field_format) if detail.value
old_value = format_value(detail.old_value, custom_field.field_format) if detail.old_value
end
when 'attachment'
label = l(:label_attachment)
end
call_hook(:helper_issues_show_detail_after_setting,
{:detail => detail, :label => label, :value => value, :old_value => old_value })
label ||= detail.prop_key
value ||= detail.value
old_value ||= detail.old_value
unless no_html
label = content_tag('strong', label)
old_value = content_tag("i", old_value) if detail.old_value
old_value = content_tag("del", old_value) if detail.old_value and detail.value.blank?
if detail.property == 'attachment' && !value.blank? && atta = Attachment.find_by_id(detail.prop_key)
# Link to the attachment if it has not been removed
if options[:token].nil?
value = atta.filename
else
value = atta.filename
end
# 放大镜搜索功能
# if options[:only_path] != false && atta.is_text?
# value += link_to(
# image_tag('magnifier.png'),
# :controller => 'attachments', :action => 'show',
# :id => atta, :filename => atta.filename
# )
# end
else
value = content_tag("i", value) if value
end
end
# 缺陷更新结果在消息中显示样式
if no_html == "message"
label = content_tag(:span, label, :class => "issue_update_message")
old_value = content_tag("span", old_value) if detail.old_value
old_value = content_tag("del", old_value) if detail.old_value and detail.value.blank?
if detail.property == 'attachment' && !value.blank? && atta = Attachment.find_by_id(detail.prop_key)
# Link to the attachment if it has not been removed
if options[:token].nil?
value = atta.filename
else
value = atta.filename
end
else
value = content_tag(:span, value, :class => "issue_update_message_value") if value
end
end
if detail.property == 'attr' && detail.prop_key == 'description'
s = l(:text_journal_changed_no_detail, :label => label)
unless no_html
diff_link = link_to l(:label_diff),
{:controller => 'journals', :action => 'diff', :id => detail.journal_id,
:detail_id => detail.id, :only_path => options[:only_path]},
:title => l(:label_view_diff)
s << " (#{ diff_link })"
end
s.html_safe
elsif detail.value.present?
case detail.property
when 'attr', 'cf'
if detail.old_value.present?
l(:text_journal_changed, :label => label, :old => old_value, :new => value).html_safe
elsif multiple
l(:text_journal_added, :label => label, :value => value).html_safe
else
l(:text_journal_set_to, :label => label, :value => value).html_safe
end
when 'attachment'
l(:text_journal_added, :label => label, :value => value).html_safe
end
else
l(:text_journal_deleted, :label => label, :old => old_value).html_safe
end
end
#课程动态的更新
def update_course_activity_api type, id
course_activity = CourseActivity.where("course_act_type=? and course_act_id =?", type.to_s, id.to_i).first
if course_activity
course_activity.updated_at = Time.now
course_activity.save
end
end
#首页动态更新
def update_user_activity_api type, id
user_activity = UserActivity.where("act_type=? and act_id =?", type.to_s, id.to_i).first
if user_activity
user_activity.updated_at = Time.now
user_activity.save
end
end
#项目动态更新
def update_forge_activity_api type, id
forge_activity = ForgeActivity.where("forge_act_type=? and forge_act_id=?", type.to_s, id.to_i).first
if forge_activity
forge_activity.updated_at = Time.now
forge_activity.save
end
end
#组织动态更新
def update_org_activity_api type , id
org_activity = OrgActivity.where("org_act_type=? and org_act_id =?", type.to_s, id.to_i).first
if org_activity
org_activity.updated_at = Time.now
org_activity.save
end
end
#个人动态更新
def update_principal_activity_api type, id
principal_activity = PrincipalActivity.where("principal_act_type=? and principal_act_id =?", type.to_s, id.to_i).first
if principal_activity
principal_activity.updated_at = Time.now
principal_activity.save
end
end
#赞/取消赞
def praise_or_cancel(type,id,user,flag)
unless id.nil? and type.nil?
#首先创建或更新praise_tread 表
pt = PraiseTread.new
pt.user_id = user.id
pt.praise_tread_object_id = id.to_i
pt.praise_tread_object_type = type
pt.praise_or_tread = flag
pt.save
# end
#再创建或更新praise_tread_cache表
#@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.praise_plus(flag,1)
end
end
def praise_plus(flag,num)
case flag
when 1
self.update_attribute(:praise_num, self.praise_num.to_i + num)
end
end
def praise_minus(num)
self.update_attribute(:praise_num, self.praise_num.to_i - num)
end
end

View File

@ -33,10 +33,29 @@ module ApplicationHelper
extend Forwardable
def_delegators :wiki_helper, :wikitoolbar_for, :heads_for_wiki_formatter
def user_path(resource, parameters = {})
if Fixnum === resource
resource = User.find(resource)
end
super
end
# def user_blogs_path(resource,parameters={})
# super
# end
def update_visiti_count container
container.update_column(:visits, container.visits + 1)
end
def if_hidden_subdomain field
domains = field.sub_domains.select{|domain| domain.hide.to_i == 0}
result = domains.length > 0 ? true : false
return result
end
# Time 2015-03-24 15:27:29
# Author lizanle
# Description 从硬盘上删除对应的资源文件
@ -2953,6 +2972,14 @@ int main(int argc, char** argv){
return sort_projects
end
end
def project_sort_first projects
unless projects.empty?
project_ids = '('+projects.map{|pro|pro.project_id}.join(',')+')'
sort_projects = ForgeActivity.find_by_sql("SELECT updated_at,user_id, project_id FROM forge_activities WHERE project_id IN #{project_ids} ORDER BY updated_at DESC limit 1")
return sort_projects
end
end
end
def user_url_in_org(user_id)
@ -2983,9 +3010,11 @@ def homework_common_index_url_in_org(course_id)
Setting.protocol + "://" + Setting.host_name + "/homework_common?course=" + course_id.to_s
end
def student_work_index_url_in_org(homework_id, is_focus = '')
def student_work_index_url_in_org(homework_id, is_focus = '', show_work_id = '')
if is_focus != ''
Setting.protocol + "://" + Setting.host_name + "/student_work?homework=" + homework_id.to_s + "&is_focus=" + is_focus.to_s
elsif show_work_id != ''
Setting.protocol + "://" + Setting.host_name + "/student_work?homework=" + homework_id.to_s + "&show_work_id=" + show_work_id.to_s
else
Setting.protocol + "://" + Setting.host_name + "/student_work?homework=" + homework_id.to_s
end
@ -3065,6 +3094,16 @@ def host_with_protocol
return Setting.protocol + "://" + Setting.host_name
end
#获取回复的所有父节点
def get_reply_parents parents_rely, comment
unless comment.parent.nil?
parents_rely << comment.parent
get_reply_parents parents_rely, comment.parent
end
parents_rely
end
#将有置顶属性的提到数组前面
def sort_by_sticky topics
tmpTopics = []
@ -3195,3 +3234,17 @@ def sortby_time_countcommon_nosticky topics,sortstr
return tmpTopics
end
def strip_html(text,len=0,endss="...")
ss = ""
if text.length>0
ss=text.gsub(/<\/?.*?>/, '').strip
if len > 0 && ss.length > len
ss = ss[0, len] + endss
elsif len > 0 && ss.length <= len
ss = ss
#ss = truncate(ss, :length => len)
end
end
return ss
end

View File

@ -19,7 +19,7 @@
module IssuesHelper
include ApplicationHelper
include TagsHelper
def issue_list(issues, &block)
ancestors = []
issues.each do |issue|

View File

@ -5,17 +5,17 @@ module OrganizationsHelper
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" )
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
@ -63,14 +63,128 @@ module OrganizationsHelper
def subfield_status_option
type = []
option1 = []
option1 << "列表"
option1 << "左一"
option1 << "1"
type << option1
option2 = []
option2 << "图片"
option2 << "0"
type << option2
# option2 = []
# option2 << "中一"
# option2 << "2"
# type << option2
option3 = []
option3 << "左二"
option3 << "3"
type << option3
option4 = []
option4 << "左三"
option4 << "4"
type << option4
option5 = []
option5 << "左四"
option5 << "5"
type << option5
option6 = []
option6 << "右一"
option6 << "6"
type << option6
option7 = []
option7 << "右二"
option7 << "7"
type << option7
option8 = []
option8 << "右三"
option8 << "8"
type << option8
type
end
# 课程和项目不参与某些模块的排列
def subfield_status_option_default
type = []
option1 = []
option1 << "左一"
option1 << "1"
type << option1
option3 = []
option3 << "左二"
option3 << "3"
type << option3
option4 = []
option4 << "左三"
option4 << "4"
type << option4
option6 = []
option6 << "右一"
option6 << "6"
type << option6
type
end
def subfield_list_type subfield
case subfield.to_i
when 1
resulet = "左一"
when 2
resulet = "左二"
when 3
resulet = "左二"
when 4
resulet = "左三"
when 5
resulet = "左四"
when 6
resulet = "右一"
when 7
resulet = "右二"
when 8
resulet = "右三"
end
end
def get_subfield_acts field
org_subfield = OrgSubfield.find(field.id)
org_subfield_ids = org_subfield.org_document_comments.map(&:id) << 0
org_acts = 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')
org_acts
end
def org_subfield_had_created?(org, type)
sub_field = org.org_subfields.select{|subfield| subfield.field_type == type}
result = sub_field.length > 0 ? true : false
result
end
def org_subfield_type(field)
case field.field_type
when "Post"
result = "帖子"
when "Resource"
result = "资源"
when "Compstu"
result = "学生"
when "Comptec"
result = "教师"
when "Complex"
result = "综合"
end
end
def org_teacher_resource_count user
results = Attachment.find_by_sql("SELECT * FROM attachments where author_id = #{user.id};").count
end
def org_teacher_course_count user
results = Course.find_by_sql("select * from courses where courses.tea_id = #{user.id}").count
end
def org_student_course_count user
course_ids = user.courses.map { |c| c.is_delete == 0 && c.id}
results = Member.find_by_sql("select id from courses where courses.tea_id = #{user.id}").count
end
def excellent_teachers
User.find_by_sql("select u.*, ue.technical_title, ue.school_id,(select count(*) from courses where courses.tea_id = u.id) as course_count
from users u, user_extensions ue where u.id = ue.user_id and ue.identity=0 and u.excellent_teacher =1 order by course_count desc").first(5)
end
end

View File

@ -0,0 +1,2 @@
module ShieldWechatMessagesHelper
end

View File

@ -23,7 +23,7 @@ module StudentWorkHelper
#获取指定用户对某一作业的评分结果
def student_work_score work,user
StudentWorksScore.where(:user_id => user.id,:student_work_id => work.id).first
StudentWorksScore.where(:user_id => user.id,:student_work_id => work.id).last
end
#获取指定评分的角色

View File

@ -0,0 +1,2 @@
module SubDocumentCommentsHelper
end

View File

@ -0,0 +1,5 @@
module SubDomainsHelper
include OrganizationsHelper
end

View File

@ -0,0 +1,6 @@
class ApplyHomework < ActiveRecord::Base
#status1. 等待回复 2.审核通过 3.已拒绝
belongs_to :user
belongs_to :homework_common
attr_accessible :status, :user_id, :homework_common_id
end

View File

@ -301,7 +301,7 @@ class Attachment < ActiveRecord::Base
nil
end
def filename=(arg)
def filename=(arg)
write_attribute :filename, sanitize_filename(arg.to_s)
filename
end

View File

@ -1,5 +1,8 @@
#encoding: utf-8
class BlogComment < ActiveRecord::Base
# attr_accessible :title, :body
require 'net/http'
require 'json'
include Redmine::SafeAttributes
belongs_to :blog
belongs_to :author, :class_name => 'User', :foreign_key => 'author_id'
@ -18,7 +21,7 @@ class BlogComment < ActiveRecord::Base
after_save :add_user_activity
after_update :update_activity
after_create :update_parent_time
after_create :update_parent_time, :blog_wechat_message
before_destroy :destroy_user_activity
scope :like, lambda {|arg|
@ -72,4 +75,18 @@ class BlogComment < ActiveRecord::Base
end
def project
end
#博客回复微信模板消息
def blog_wechat_message
ws = WechatService.new
if self.parent_id.nil?
self.author.watcher_users.each do |watcher|
content = strip_html self.author.try(:realname) + " 发表了博客:" + self.title.html_safe, 200
ws.message_update_template watcher.id, "blog_comment", self.id, "#{l(:label_new_blog_template)}", content, format_time(self.created_at)
end
else
content = strip_html self.content.html_safe, 200
ws.comment_template self.parent.author_id, "blog_comment", self.parent_id, "#{l(:label_blog_comment_template)}", self.author.try(:realname), format_time(self.created_at), content
end
end
end

View File

@ -16,6 +16,8 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class Comment < ActiveRecord::Base
require 'net/http'
require 'json'
include Redmine::SafeAttributes
include ApplicationHelper
has_many_kindeditor_assets :assets, :dependent => :destroy
@ -39,13 +41,21 @@ class Comment < ActiveRecord::Base
after_destroy :down_course_score
def act_as_system_message
ws = WechatService.new
if self.commented.course
if self.author_id != self.commented.author_id
self.course_messages << CourseMessage.new(:user_id => self.commented.author_id, :course_id => self.commented.course.id, :viewed => false)
count = ShieldWechatMessage.where("container_type='User' and container_id=#{self.commented.author_id} and shield_type='Course' and shield_id=#{self.commented.course.id}").count
if count == 0
content = strip_html self.comments.html_safe, 200
ws.comment_template self.commented.author_id, "course_notice", self.id, "#{l(:label_notice_comment_template)}", self.author.try(:realname), format_time(self.created_on), content
end
end
else # 项目相关
if self.author_id != self.commented.author_id
self.forge_messages << ForgeMessage.new(:user_id => self.commented.author_id, :project_id => self.commented.project.id, :viewed => false)
#content = strip_html self.comments.html_safe, 200
#ws.comment_template self.commented.author_id, "blog_comment", self.id, "#{l(:label_news_comment_template)}", self.author.try(:realname), format_time(self.created_on), content
end
end
end

View File

@ -1,8 +1,9 @@
class CourseMessage < ActiveRecord::Base
# status说明 status在课程不同的类型区分不同的功能 status = 9 作品的提交记录
# HomeworkCommonstatus
# nil发布了作业 1作业截止时间到了提醒2:开启匿评; 3关闭匿评 4匿评开始失败
attr_accessible :course_id, :course_message_id, :course_message_type, :user_id, :viewed, :content, :status
# nil发布了作业 1作业截止时间到了提醒2:开启匿评; 3关闭匿评 4匿评开始失败 5申请引用作业, 6:申请结果
# apply_user_id: 申请者的用户id
attr_accessible :course_id, :course_message_id, :course_message_type, :user_id, :viewed, :content, :status, :apply_user_id, :apply_result
# 多态 虚拟关联
belongs_to :course_message ,:polymorphic => true
@ -14,7 +15,7 @@ class CourseMessage < ActiveRecord::Base
validates :course_id,presence: true
validates :course_message_id,presence: true
validates :course_message_type, presence: true
validates_length_of :content, :maximum => 100
#validates_length_of :content, :maximum => 100
after_create :add_user_message
def add_user_message

View File

@ -1,7 +1,10 @@
#encoding: utf-8
#老师布置的作业表
#homework_type: 0:普通作业;1:匿评作业;2:编程作业
class HomeworkCommon < ActiveRecord::Base
# attr_accessible :name, :user_id, :description, :publish_time, :end_time, :homework_type, :late_penalty, :course_id,:simi_time
require 'net/http'
require 'json'
include Redmine::SafeAttributes
include ApplicationHelper
@ -15,6 +18,7 @@ class HomeworkCommon < ActiveRecord::Base
has_many :student_works, :dependent => :destroy, :conditions => "is_test=0"
has_many :student_works_evaluation_distributions, :through => :student_works #一个作业的分配的匿评列表
has_many :journals_for_messages, :as => :jour, :dependent => :destroy
has_many :apply_homeworks, :dependent => :destroy
has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy #用户活动
# 课程动态
has_many :course_acts, :class_name => 'CourseActivity',:as =>:course_act ,:dependent => :destroy
@ -26,7 +30,7 @@ class HomeworkCommon < ActiveRecord::Base
:author => :author,
:url => Proc.new {|o| {:controller => 'student_work', :action => 'index', :homework => o.id}}
after_create :act_as_activity, :send_mail, :act_as_course_message
after_update :update_activity
after_update :update_activity, :wechat_message
after_save :act_as_course_activity
after_destroy :delete_kindeditor_assets
@ -56,6 +60,11 @@ class HomeworkCommon < ActiveRecord::Base
self.course.members.each do |m|
# if m.user_id != self.user_id
self.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => self.course_id, :viewed => false)
count = ShieldWechatMessage.where("container_type='User' and container_id=#{m.user_id} and shield_type='Course' and shield_id=#{self.course_id}").count
if count == 0
ws = WechatService.new
ws.homework_template(m.user_id, "homework", self.id, "#{l(:label_new_homework_template)}", self.course.name, self.name.html_safe, self.end_time.to_s + " 23:59:59")
end
# end
end
end
@ -98,6 +107,17 @@ class HomeworkCommon < ActiveRecord::Base
jfm
end
#修改作业后发送微信模板消息
def wechat_message
self.course.members.each do |member|
count = ShieldWechatMessage.where("container_type='User' and container_id=#{member.user_id} and shield_type='Course' and shield_id=#{self.course_id}").count
if count == 0
ws = WechatService.new
ws.homework_template(member.user_id, "homework", self.id, "#{l(:label_update_homework_template)}", self.course.name, self.name.html_safe, self.end_time.to_s + " 23:59:59")
end
end
end
delegate :language_name, :language, :to => :homework_detail_programing
end

View File

@ -1,3 +1,4 @@
#encoding: utf-8
# Redmine - project management software
# Copyright (C) 2006-2013 Jean-Philippe Lang
#
@ -16,6 +17,8 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class Issue < ActiveRecord::Base
require 'net/http'
require 'json'
include Redmine::SafeAttributes
include Redmine::Utils::DateCalculation
include UserScoreHelper
@ -157,6 +160,14 @@ class Issue < ActiveRecord::Base
unless self.author_id == self.assigned_to_id
self.forge_messages << ForgeMessage.new(:user_id => self.assigned_to_id, :project_id => self.project_id, :viewed => false)
end
self.project.members.each do |m|
count = ShieldWechatMessage.where("container_type='User' and container_id=#{m.user_id} and shield_type='Project' and shield_id=#{self.project_id}").count
if m.user_id != self.author_id && count == 0
ws = WechatService.new
content = strip_html self.project.name + " 有新缺陷了:" + self.subject.html_safe, 200
ws.message_update_template m.user_id, "issues", self.id, "#{l(:label_new_issue_template)}", content, format_time(self.created_on)
end
end
if self.tracker_id == 5
self.project.members.each do |m|
if m.roles.first.to_s.include?("Manager") && m.user_id != self.author_id && m.user_id != self.assigned_to_id
@ -251,7 +262,7 @@ class Issue < ActiveRecord::Base
# set default values for new records only
self.status ||= IssueStatus.default
self.priority ||= IssuePriority.default
self.watcher_user_ids = []
# self.watcher_user_ids = []
end
end

View File

@ -1,3 +1,4 @@
#coding=utf-8
# Redmine - project management software
# Copyright (C) 2006-2013 Jean-Philippe Lang
#
@ -16,6 +17,8 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class Journal < ActiveRecord::Base
require 'net/http'
require 'json'
include UserScoreHelper
belongs_to :journalized, :polymorphic => true,:touch => true
# added as a quick fix to allow eager loading of the polymorphic association
@ -52,7 +55,7 @@ class Journal < ActiveRecord::Base
# fq
after_save :act_as_activity,:be_user_score, :act_as_forge_message, act_as_at_message(:notes, :user_id)
after_create :update_issue_time
after_create :issue_wechat_message
# end
#after_destroy :down_user_score
#before_save :be_user_score
@ -233,4 +236,11 @@ class Journal < ActiveRecord::Base
forge_activity.update_attribute(:created_at, self.created_on) unless forge_activity.nil?
end
end
#缺陷回复微信模板消息
def issue_wechat_message
ws = WechatService.new
content = strip_html self.notes.html_safe, 200
ws.comment_template self.issue.author_id, "issues", self.journalized_id, "#{l(:label_issue_comment_template)}", self.user.try(:realname), format_time(self.created_on), content
end
end

View File

@ -1,7 +1,9 @@
# fq
#coding=utf-8
# 数据库字段中带有m前缀和is_readed是二次开发添加之前的字段基本复用
# 注意reply_id 是提到人的id不是留言id, Base中叫做 at_user
class JournalsForMessage < ActiveRecord::Base
require 'net/http'
require 'json'
include Redmine::SafeAttributes
include UserScoreHelper
include ApplicationHelper
@ -253,17 +255,34 @@ class JournalsForMessage < ActiveRecord::Base
self.course_messages << CourseMessage.new(:user_id => r, :course_id => self.jour.id, :viewed => false)
end
end
if self.jour_type == 'HomeworkCommon'
if self.m_parent_id.nil?
if self.user_id != self.jour.user_id
self.course_messages << CourseMessage.new(:user_id => self.jour.user_id,:course_id => self.jour.course.id, :viewed => false)
end
end
count = ShieldWechatMessage.where("container_type='User' and container_id=#{self.jour.user_id} and shield_type='Course' and shield_id=#{self.jour.course_id}").count
if count == 0
ws = WechatService.new
#content = truncate(strip_tags(self.notes.to_s), length: 200)
content = strip_html self.notes.html_safe, 200
ws.comment_template self.jour.user_id, "homework", self.jour_id, "#{l(:label_homework_comment_template)}", self.user.try(:realname), format_time(self.created_on), content
end
end
end
# 用户留言消息通知
def act_as_user_feedback_message
# 主留言
ws = WechatService.new
if self.jour_type == 'Principal'
receivers = []
if self.reply_id == 0
if self.user_id != self.jour_id # 过滤自己给自己的留言消息
receivers << self.jour
content = strip_html self.notes, 200
ws.message_update_template self.jour_id, "journal_for_message", self.id, "#{l(:label_new_journals_template)}", content, format_time(self.created_on)
end
else # 留言回复
reply_to = User.find(self.reply_id)
@ -273,11 +292,12 @@ class JournalsForMessage < ActiveRecord::Base
if self.user_id != self.parent.jour_id && self.reply_id != self.parent.jour_id # 给东家发信息,如果回复的对象是东家则不发
receivers << self.parent.jour
end
content = strip_html self.notes, 200
ws.comment_template self.reply_id, "journal_for_message", self.parent.id, "#{l(:label_journals_comment_template)}", self.user.try(:realname), format_time(self.created_on), content
end
receivers.each do |r|
self.user_feedback_messages << UserFeedbackMessage.new(:user_id => r.id, :journals_for_message_id => self.id, :journals_for_message_type => "Principal", :viewed => false)
end
end
end
@ -298,5 +318,4 @@ class JournalsForMessage < ActiveRecord::Base
down_course_score_num(self.jour.course_id, self.user_id, "HomeworkCommon")
end
end
end

View File

@ -1,3 +1,4 @@
#encoding: utf-8
# Redmine - project management software
# Copyright (C) 2006-2013 Jean-Philippe Lang
#
@ -626,6 +627,7 @@ class Mailer < ActionMailer::Base
# attachments_added(attachments) => Mail::Message object
# Mailer.attachments_added(attachments).deliver => sends an email to the project's recipients
def homework_added(homework_common)
logger.info "homework added"
@homework_common = homework_common
@author = homework_common.user
@homework_common_url = url_for(:controller => "homework_common", :action =>"index", :homework => @homework_common.id)
@ -727,7 +729,7 @@ class Mailer < ActionMailer::Base
:cc => cc,
:subject => "[#{message.board.project.name} - #{message.board.name} - msg#{message.root.id}] #{message.subject}",
:filter => true
elsif message.course
elsif message.course
redmine_headers 'Course' => message.course.id,
'Topic-Id' => (message.parent_id || message.id)
@author = message.author
@ -742,7 +744,7 @@ class Mailer < ActionMailer::Base
:cc => cc,
:subject => "[#{message.board.course.name} - #{message.board.name} - msg#{message.root.id}] #{message.subject}",
:filter => true
end
end
end
# Builds a Mail::Message object used to email the recipients of a project of the specified wiki content was added.
@ -1039,7 +1041,13 @@ class Mailer < ActionMailer::Base
:subject => @subject
end
def apply_for_homework_request(homework, user)
@receive = User.find(homework.user_id)
@user = user
@subject = "#{@user.show_name} #{l(:label_apply_for_homework)} #{homework.name} "
mail :to => @receive.mail,
:subject => @subject
end
private
@ -1096,5 +1104,4 @@ class Mailer < ActionMailer::Base
1.upto(len) { |i| newpass << chars[rand(chars.size-1)] }
return newpass
end
end

View File

@ -1,3 +1,4 @@
#encoding: utf-8
# Redmine - project management software
# Copyright (C) 2006-2013 Jean-Philippe Lang
#
@ -16,6 +17,8 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class Message < ActiveRecord::Base
require 'net/http'
require 'json'
include Redmine::SafeAttributes
include UserScoreHelper
include ApplicationHelper
@ -80,7 +83,7 @@ class Message < ActiveRecord::Base
# after_create :add_author_as_watcher, :reset_counters!, :add_boards_count
after_update :update_messages_board, :update_activity
after_destroy :reset_counters!,:down_user_score,:delete_kindeditor_assets, :decrease_boards_count, :down_course_score
after_create :act_as_course_activity, :act_as_forge_activity, :act_as_system_message, :send_mail, :act_as_student_score, act_as_at_message(:content, :author_id), :add_author_as_watcher, :reset_counters!, :add_boards_count
after_create :act_as_course_activity, :act_as_forge_activity, :act_as_student_score, act_as_at_message(:content, :author_id), :add_author_as_watcher, :reset_counters!, :add_boards_count, :act_as_system_message
#before_save :be_user_score
scope :visible, lambda {|*args|
@ -255,17 +258,27 @@ class Message < ActiveRecord::Base
# 主贴项目成员都能收到
# 回帖:帖子的发布人收到
def act_as_system_message
ws = WechatService.new
if self.course
if self.parent_id.nil? # 主贴
self.course.members.includes(:user).each do |m|
if self.author.allowed_to?(:as_teacher, self.course) && m.user_id != self.author_id # 老师 自己的帖子不给自己发送消息
self.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => self.board.course_id, :viewed => false)
#self.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => self.board.course_id, :viewed => false)
count = ShieldWechatMessage.where("container_type='User' and container_id=#{m.user_id} and shield_type='Course' and shield_id=#{self.course.id}").count
if count == 0
content = strip_html self.subject, 200
ws.topic_publish_template m.user_id, "course_discussion", self.id, "#{l(:label_course_topic_template)}", content, self.author.try(:realname), format_time(self.created_on)
end
end
end
else # 回帖
self.course.members.includes(:user).each do |m|
if m.user_id == Message.find(self.parent_id).author_id && m.user_id != self.author_id # 只针对主贴回复,回复自己的帖子不发消息
self.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => self.board.course_id, :viewed => false)
parent_author_id = Message.find(self.parent_id).author_id
if parent_author_id != self.author_id # 只针对主贴回复,回复自己的帖子不发消息
#self.course_messages << CourseMessage.new(:user_id => parent_author_id, :course_id => self.board.course_id, :viewed => false)
count = ShieldWechatMessage.where("container_type='User' and container_id=#{parent_author_id} and shield_type='Course' and shield_id=#{self.board.course_id}").count
if count == 0
content = strip_html self.content.html_safe, 200
ws.comment_template parent_author_id, "course_discussion", self.parent_id, "#{l(:label_topic_comment_template)}", self.author.try(:realname), format_time(self.created_on), content
end
end
end
@ -273,13 +286,22 @@ class Message < ActiveRecord::Base
if self.parent_id.nil? # 主贴
self.project.members.includes(:user).each do |m|
if m.user_id != self.author_id
self.forge_messages << ForgeMessage.new(:user_id => m.user_id, :project_id => self.board.project_id, :viewed => false)
#self.forge_messages << ForgeMessage.new(:user_id => m.user_id, :project_id => self.board.project_id, :viewed => false)
count = ShieldWechatMessage.where("container_type='User' and container_id=#{m.user_id} and shield_type='Project' and shield_id=#{self.project.id}").count
if count == 0
content = strip_html self.subject, 200
ws.topic_publish_template m.user_id, "project_discussion", self.id, "#{l(:label_project_topic_template)}", content, self.author.try(:realname), format_time(self.created_on)
end
end
end
else # 回帖
self.project.members.includes(:user).each do |m|
if m.user_id == Message.find(self.parent_id).author_id && m.user_id != self.author_id # 只针对主贴回复,回复自己的帖子不发消息
self.forge_messages << ForgeMessage.new(:user_id => m.user_id, :project_id => self.board.project_id, :viewed => false)
parent_author_id = Message.find(self.parent_id).author_id
if parent_author_id != self.author_id # 只针对主贴回复,回复自己的帖子不发消息
#self.forge_messages << ForgeMessage.new(:user_id => parent_author_id, :project_id => self.board.project_id, :viewed => false)
count = ShieldWechatMessage.where("container_type='User' and container_id=#{parent_author_id} and shield_type='Project' and shield_id=#{self.board.project_id}").count
if count == 0
content = strip_html self.content.html_safe, 200
ws.comment_template parent_author_id, "project_discussion", self.parent_id, "#{l(:label_topic_comment_template)}", self.author.try(:realname), format_time(self.created_on), content
end
end
end

View File

@ -1,3 +1,4 @@
#encoding: utf-8
# Redmine - project management software
# Copyright (C) 2006-2013 Jean-Philippe Lang
#
@ -16,6 +17,8 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class News < ActiveRecord::Base
require 'net/http'
require 'json'
include Redmine::SafeAttributes
belongs_to :project,:touch => true
include ApplicationHelper
@ -59,7 +62,7 @@ class News < ActiveRecord::Base
:author_key => :author_id
acts_as_watchable
after_create :act_as_activity,:act_as_forge_activity, :act_as_course_activity,:act_as_system_message, :add_author_as_watcher, :send_mail, :add_news_count, :act_as_student_score
after_create :act_as_activity,:act_as_forge_activity, :act_as_course_activity, :add_author_as_watcher, :send_mail, :add_news_count, :act_as_student_score
after_update :update_activity
after_destroy :delete_kindeditor_assets, :decrease_news_count, :delete_org_activities, :down_course_score
@ -167,6 +170,12 @@ class News < ActiveRecord::Base
self.course.members.each do |m|
if m.user_id != self.author_id
self.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => self.course_id, :viewed => false)
count = ShieldWechatMessage.where("container_type='User' and container_id=#{m.user_id} and shield_type='Course' and shield_id=#{self.course_id}").count
if count == 0
ws = WechatService.new
content = strip_html self.author.try(:realname) + " 发布了通知:" + self.title.html_safe, 200
ws.message_update_template m.user_id, "course_notice", self.id, "#{l(:label_new_notice_template)}", self.author.try(:realname) + " 发布了通知:" + content, format_time(self.created_on)
end
end
end
else

View File

@ -7,6 +7,7 @@ class OrgSubfield < ActiveRecord::Base
has_many :messages, :through => :org_subfield_messages
has_many :boards, :dependent => :destroy
has_many :news, :dependent => :destroy
has_many :sub_domains, :dependent => :destroy
acts_as_attachable
after_create :create_board_sync
after_destroy :update_priority

View File

@ -22,4 +22,12 @@ class Organization < ActiveRecord::Base
OrgSubfield.create(:organization_id => self.id, :name => 'course', :field_type => 'default', :priority => 2)
OrgSubfield.create(:organization_id => self.id, :name => 'project', :field_type => 'default', :priority => 3)
end
def switch_type
self.show_mode.to_i == 1 ? true : false
end
def allow_set_teachers
self.allow_teacher.to_i == 1 ? true : false
end
end

View File

@ -88,4 +88,11 @@ class PraiseTread < ActiveRecord::Base
UserLevels.update_user_level(target_user)
end
end
def self.praised(activity)
self.where(praise_tread_object_id: activity.id,
praise_tread_object_type: activity.class.to_s,
user_id: User.current.id).empty?
end
end

View File

@ -5,4 +5,5 @@ class School < ActiveRecord::Base
def to_s
self.name.to_s
end
end

View File

@ -0,0 +1,3 @@
class ShieldWechatMessage < ActiveRecord::Base
attr_accessible :container_id, :container_type, :shield_id, :shield_type
end

56
app/models/sso.rb Normal file
View File

@ -0,0 +1,56 @@
class Sso < ActiveRecord::Base
belongs_to :user
attr_accessible :email, :name, :openid, :password, :school, :sex, :user, :user_id
validates :user_id, :user, :email, :openid, :presence => true
def self.sync_user(opt)
sso = Sso.where(openid: opt["openid"]).first
return sso if sso
sso = Sso.new
sso.name = opt["name"]
sso.openid = opt["openid"]
sso.email = opt["email"]
sso.password = opt["password"]
sso.school = opt["school"]
sso.sex = opt["sex"]
# 查邮箱
user = User.where(mail: opt["email"]).first
unless user
# 查用户名
user = User.where(login: opt["name"]).first
if user
# 跳到修改用户名
raise "exist user"
end
password = opt["password"]
if password.size < 8
password = random_pwd
end
us = UsersService.new
user = us.register(login: opt["name"], mail: opt["email"],
password: password,
:should_confirmation_password => false)
if user.new_record?
raise user.errors.full_messages.first
end
end
sso.user = user
sso.save!
return sso
end
private
def self.random_pwd
('a'..'z').to_a.shuffle[0..7].join
end
end

View File

@ -63,11 +63,17 @@ class StudentWork < ActiveRecord::Base
final_score = final_ta_score + final_s_score
student_work.final_score = format("%.2f",final_score.to_f)
end
score = student_work.final_score - student_work.absence_penalty - student_work.late_penalty if student_work.final_score
student_work.work_score = format("%.2f",(score < 0 ? 0 : score).to_f) if score
if student_work.final_score
score = student_work.final_score - student_work.absence_penalty - student_work.late_penalty
student_work.work_score = format("%.2f",(score < 0 ? 0 : score).to_f) if score
else
student_work.work_score = nil
end
end
else #不考虑教师评分
if student_work.teaching_asistant_score.nil?
if student_work.student_score.nil? && student_work.teaching_asistant_score.nil?
student_work.final_score = student_work.teacher_score
elsif 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
@ -78,8 +84,12 @@ class StudentWork < ActiveRecord::Base
final_score = final_ta_score + final_s_score
student_work.final_score = format("%.2f",final_score.to_f)
end
score = student_work.final_score - student_work.absence_penalty - student_work.late_penalty if student_work.final_score
student_work.work_score = format("%.2f",(score < 0 ? 0 : score).to_f) if score
if student_work.final_score
score = student_work.final_score - student_work.absence_penalty - student_work.late_penalty
student_work.work_score = format("%.2f",(score < 0 ? 0 : score).to_f) if score
else
student_work.work_score = nil
end
end
elsif homework.homework_type == 2 && homework.homework_detail_programing #编程作业-----设定:系统评分必定不为空
if homework.teacher_priority == 1 #教师优先
@ -114,9 +124,13 @@ class StudentWork < ActiveRecord::Base
final_score = final_sy_score + final_ts_score + final_st_score
student_work.final_score = format("%.2f",final_score.to_f)
end
score = student_work.final_score - student_work.absence_penalty - student_work.late_penalty if student_work.final_score
student_work.work_score = format("%.2f",(score < 0 ? 0 : score).to_f) if score
end
if student_work.final_score
score = student_work.final_score - student_work.absence_penalty - student_work.late_penalty
student_work.work_score = format("%.2f",(score < 0 ? 0 : score).to_f) if score
else
student_work.work_score = nil
end
end
else #不考虑教师评分
if student_work.teaching_asistant_score.nil? #教辅未评分
if student_work.student_score.nil?
@ -145,8 +159,12 @@ class StudentWork < ActiveRecord::Base
final_score = final_sy_score + final_ts_score + final_st_score
student_work.final_score = format("%.2f",final_score.to_f)
end
score = student_work.final_score - student_work.absence_penalty - student_work.late_penalty if student_work.final_score
student_work.work_score = format("%.2f",(score < 0 ? 0 : score).to_f) if score
if student_work.final_score
score = student_work.final_score - student_work.absence_penalty - student_work.late_penalty
student_work.work_score = format("%.2f",(score < 0 ? 0 : score).to_f) if score
else
student_work.work_score = nil
end
end
end
end

View File

@ -18,17 +18,29 @@ class StudentWorksScore < ActiveRecord::Base
receiver = self.student_work.user
# 判断是第一次评阅还是更新 status:0 新建1 更新
if self.created_at == self.updated_at
if self.comment.nil?
if self.comment.nil? && self.score
self.course_messages << CourseMessage.new(:user_id => receiver.id, :course_id => self.student_work.homework_common.course.id,
:viewed => false, :content => "作业评分:#{self.score}", :status=> false)
elsif self.score.nil? && self.comment
self.course_messages << CourseMessage.new(:user_id => receiver.id, :course_id => self.student_work.homework_common.course.id,
:viewed => false, :content => "评语:#{self.comment}", :status=> false)
elsif self.comment.nil? && self.score.nil?
self.course_messages << CourseMessage.new(:user_id => receiver.id, :course_id => self.student_work.homework_common.course.id,
:viewed => false, :content => "上传了批阅附件", :status=> false)
else
self.course_messages << CourseMessage.new(:user_id => receiver.id, :course_id => self.student_work.homework_common.course.id,
:viewed => false, :content => "作业评分:#{self.score}&nbsp;&nbsp;&nbsp; 评语:#{self.comment}", :status=> false)
end
else # 更新
if self.comment.nil?
if self.comment.nil? && self.score
self.course_messages << CourseMessage.new(:user_id => receiver.id, :course_id => self.student_work.homework_common.course.id,
:viewed => false, :content => "作业评分:#{self.score}", :status=> true)
elsif self.score.nil? && self.comment
self.course_messages << CourseMessage.new(:user_id => receiver.id, :course_id => self.student_work.homework_common.course.id,
:viewed => false, :content => "评语:#{self.comment}", :status=> true)
elsif self.comment.nil? && self.score.nil?
self.course_messages << CourseMessage.new(:user_id => receiver.id, :course_id => self.student_work.homework_common.course.id,
:viewed => false, :content => "上传了批阅附件", :status=> true)
else
self.course_messages << CourseMessage.new(:user_id => receiver.id, :course_id => self.student_work.homework_common.course.id,
:viewed => false, :content => "作业评分:#{self.score}&nbsp;&nbsp;&nbsp; 评语:#{self.comment}", :status=> true)

View File

@ -0,0 +1,33 @@
class SubDocumentComment < ActiveRecord::Base
attr_accessible :content, :creator_id, :locked, :org_subfield_id, :parent_id, :reply_id, :sticky, :sub_domain_id, :title
include Redmine::SafeAttributes
include ApplicationHelper
belongs_to :sub_domain
belongs_to :creator, :class_name => 'User', :foreign_key => 'creator_id'
acts_as_tree :order => "#{SubDocumentComment.table_name}.sticky asc, #{SubDocumentComment.table_name}.created_at desc"
acts_as_attachable
has_many :org_acts, :class_name => 'OrgActivity',:as =>:org_act ,:dependent => :destroy
after_create :document_save_as_sub_activity
after_update :update_activity
validates_presence_of :content
#动态的更新
private
def update_activity
org_activity = OrgActivity.where("org_act_type='SubDocumentComment' and org_act_id =?", id).first
if org_activity
org_activity.updated_at = Time.now
org_activity.save
end
end
def document_save_as_sub_activity
if(self.parent().nil?)
self.org_acts << OrgActivity.new(:user_id => User.current.id, :container_id => self.sub_domain.id, :container_type => 'SubDomain')
else
act = OrgActivity.where("org_act_type='SubDocumentComment' and org_act_id =?", self.root.id).first
act.update_attributes(:updated_at => self.updated_at)
end
end
end

5
app/models/sub_domain.rb Normal file
View File

@ -0,0 +1,5 @@
class SubDomain < ActiveRecord::Base
attr_accessible :field_type, :hide, :name, :org_subfield_id, :priority, :status
belongs_to :org_subfield, :foreign_key => :org_subfield_id
has_many :sub_document_comments, :dependent => :destroy
end

View File

@ -108,6 +108,7 @@ class User < Principal
has_many :student_works_evaluation_distributions, :dependent => :destroy
has_many :student_works_scores, :dependent => :destroy
has_many :student_work_projects, :dependent => :destroy
has_many :apply_homeworks, :dependent => :destroy
#end
has_and_belongs_to_many :groups, :after_add => Proc.new {|user, group| group.user_added(user)},
@ -179,6 +180,9 @@ class User < Principal
#####
has_many :shares ,:dependent => :destroy
has_one :user_wechat
has_one :sso
# add by zjc
has_one :level, :class_name => 'UserLevels', :dependent => :destroy
@ -305,6 +309,20 @@ class User < Principal
end
# ======================================================================
def my_workplace
self.user_extensions.try(:occupation).to_s
end
def my_blogs_count
self.blog.blog_comments.where("#{BlogComment.table_name}.parent_id is null").count
end
def my_students
my_students=StudentsForCourse.find_by_sql("SELECT SUM(student_count) as students_count, c.tea_id FROM courses c, (SELECT course_id , COUNT(id) AS student_count FROM students_for_courses GROUP BY course_id) AS ct
WHERE c.id= ct.course_id and c.tea_id = #{self.id} GROUP BY c.tea_id").first
results = my_students.blank? ? 0 : my_students.students_count
results
end
# 查询用户未读过的记录
# 用户留言记录
@ -1069,16 +1087,25 @@ class User < Principal
anonymous_user
end
def self.is_id?(id)
Fixnum===id || id.to_i.to_s == id
end
# refactor User model find function,
# return anonymous user when can not find user id = user_id
def self.find (*args, &block)
begin
return find_by_login(args.first) if args.size==1 && !is_id?(args.first)
super
rescue
self.anonymous
end
# super
end
def to_param
login
end
# Salts all existing unsalted passwords
# It changes password storage scheme from SHA1(password) to SHA1(salt + SHA1(password))
# This method is used in the SaltPasswords migration and is to be kept as is
@ -1181,17 +1208,17 @@ class User < Principal
def create_user_ealasticsearch_index
if self.id != 2 && self.id != 4
self.__elasticsearch__.index_document
self.__elasticsearch__.index_document if Rails.env.production?
end
end
def update_user_ealasticsearch_index
if self.id != 2 && self.id != 4
self.__elasticsearch__.update_document
self.__elasticsearch__.update_document if Rails.env.production?
end
end
def delete_user_ealasticsearch_index
if self.id != 2 && self.id != 4
self.__elasticsearch__.delete_document
self.__elasticsearch__.delete_document if Rails.env.production?
end
end

View File

@ -0,0 +1,6 @@
class UserWechat < ActiveRecord::Base
attr_accessible :subscribe, :openid, :nickname, :sex, :language, :city, :province, :country,
:headimgurl, :subscribe_time, :unionid, :remark, :groupid, :user, :user_id
belongs_to :user
end

View File

@ -0,0 +1,117 @@
#encoding: utf-8
class WechatService
def template_data(openid, template_id, type, id, first, key1, key2, key3, remark="")
data = {
touser:openid,
template_id:template_id,
url:"https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxc09454f171153c2d&redirect_uri=https://www.trustie.net/assets/wechat/app.html#/#{type}/#{id}?response_type=code&scope=snsapi_base&state=123#wechat_redirect",
topcolor:"#FF0000",
data:{
first: {
value:first,
color:"#707070"
},
keyword1:{
value:key1,
color:"#707070"
},
keyword2:{
value:key2,
color:"#707070"
},
keyword3:{
value:key3,
color:"#707070"
},
remark:{
value:remark,
color:"#707070"
}
}
}
data
end
def homework_template(user_id, type, id, first, key1, key2, key3, remark="")
uw = UserWechat.where(user_id: user_id).first
unless uw.nil?
data = template_data uw.openid,"3e5Dj2GIx8MOcMyRKpTUEQnM7Tg0ASSCNc01NS9HCGI", type, id, first, key1, key2, key3, remark
begin
req = Wechat.api.template_message_send Wechat::Message.to(uw.openid).template(data)
rescue Exception => e
Rails.logger.error "[homework] ===> #{e}"
end
Rails.logger.info "send over. #{req}"
end
Rails.logger.info "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxc09454f171153c2d&redirect_uri=https://www.trustie.net/assets/wechat/app.html#/#{type}/#{id}?response_type=code&scope=snsapi_base&state=123#wechat_redirect"
end
def topic_publish_template(user_id, type, id, first, key1, key2, key3, remark="")
uw = UserWechat.where(user_id: user_id).first
unless uw.nil?
data = template_data uw.openid,"oKzFCdk7bsIHnGbscA__N8LPQrBkUShvpjV3-kuwWDQ", type, id,first, key1, key2, key3, remark
Rails.logger.info "start send template message: #{data}"
begin
req = Wechat.api.template_message_send Wechat::Message.to(uw.openid).template(data)
rescue Exception => e
Rails.logger.error "[topic_publish] ===> #{e}"
end
Rails.logger.info "send over. #{req}"
end
Rails.logger.info "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxc09454f171153c2d&redirect_uri=https://www.trustie.net/assets/wechat/app.html#/#{type}/#{id}?response_type=code&scope=snsapi_base&state=123#wechat_redirect"
end
def comment_template(user_id,type, id, first, key1, key2, key3, remark="")
uw = UserWechat.where(user_id: user_id).first
unless uw.nil?
data = template_data uw.openid,"A_3f5v90-zK73V9Kijm-paDkl9S-NuM8Cf-1UJi92_c",type, id,first, key1, key2, key3, remark
Rails.logger.info "start send template message: #{data}"
begin
req = Wechat.api.template_message_send Wechat::Message.to(uw.openid).template(data)
rescue Exception => e
Rails.logger.error "[comment] ===> #{e}"
end
Rails.logger.info "send over. #{req}"
end
Rails.logger.info "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxc09454f171153c2d&redirect_uri=https://www.trustie.net/assets/wechat/app.html#/#{type}/#{id}?response_type=code&scope=snsapi_base&state=123#wechat_redirect"
end
def message_update_template(user_id, type, id, first, key1, key2, remark="")
uw = UserWechat.where(user_id: user_id).first
unless uw.nil?
data = {
touser:uw.openid,
template_id:"YTyNPZnQD8uZFBFq-Q6cCOWaq5LA9vL6RFlF2JuD5Cg",
url:"https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxc09454f171153c2d&redirect_uri=https://www.trustie.net/assets/wechat/app.html#/#{type}/#{id}?response_type=code&scope=snsapi_base&state=123#wechat_redirect",
topcolor:"#FF0000",
data:{
first: {
value:first,
color:"#707070"
},
keyword1:{
value:key1,
color:"#707070"
},
keyword2:{
value:key2,
color:"#707070"
},
remark:{
value:remark,
color:"#707070"
}
}
}
Rails.logger.info "start send template message: #{data}"
begin
req = Wechat.api.template_message_send Wechat::Message.to(uw.openid).template(data)
rescue Exception => e
Rails.logger.error "[message_update] ===> #{e}"
end
Rails.logger.info "send over. #{req}"
end
Rails.logger.info "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxc09454f171153c2d&redirect_uri=https://www.trustie.net/assets/wechat/app.html#/#{type}/#{id}?response_type=code&scope=snsapi_base&state=123#wechat_redirect"
end
end

View File

@ -0,0 +1,89 @@
<h3>
<%=l(:label_apply_homework)%>
</h3>
<div class="autoscroll">
<table class="list" style="width: 100%;table-layout: fixed">
<thead>
<tr>
<th style="width: 30px;">
序号
</th>
<th style="width: 120px;">
作业名称
</th>
<th style="width: 120px;">
课程名称
</th>
<th style="width: 50px;">
作者
</th>
<th style="width: 50px;">
申请者
</th>
<th style="width: 50px;">
申请状态
</th>
<th style="width: 70px;">
申请日期
</th>
</tr>
</thead>
<tbody>
<%@count=@page*30 %>
<% for homework in @homework do %>
<% unless homework.nil? %>
<% @count+=1 %>
<tr>
<td align="center">
<%=@count %>
</td>
<% c_h = HomeworkCommon.find homework.homework_common_id %>
<% if c_h %>
<td style="white-space: nowrap;overflow: hidden;text-overflow: ellipsis;" class="name" title='<%=c_h.name%>'>
<%=link_to(c_h.try(:name), student_work_index_path(:homework => c_h.id))%>
</td>
<% if c_h.course %>
<td style="white-space: nowrap;overflow: hidden;text-overflow: ellipsis;" class="name" title='<%=c_h.course.name%>'>
<%= link_to(c_h.course.name, course_path(c_h.course.id)) %>
</td>
<% end %>
<td align="center" style="white-space: nowrap;overflow: hidden;text-overflow: ellipsis;" class="name" title='<% if c_h.try(:user).try(:realname) == ' '%><%= c_h.try(:user)%><% else %><%=c_h.try(:user).try(:realname) %><% end %>'>
<% if c_h.try(:user).try(:realname) == ' '%>
<%= link_to(c_h.try(:user), user_path(c_h.user_id)) %>
<% else %>
<%= link_to(c_h.try(:user).try(:realname), user_path(c_h.user_id)) %>
<% end %>
</td>
<% end %>
<td align="center" style="white-space: nowrap;overflow: hidden;text-overflow: ellipsis;" class="name" title='<% if homework.try(:user).try(:realname) == ' '%><%= homework.try(:user)%><% else %><%=homework.try(:user).try(:realname) %><% end %>'>
<% if homework.try(:user).try(:realname) == ' '%>
<%= link_to(homework.try(:user), user_path(homework.user_id)) %>
<% else %>
<%= link_to(homework.try(:user).try(:realname), user_path(homework.user_id)) %>
<% end %>
</td>
<td align="center">
<% if homework.status == 1 %>
等待回复
<% elsif homework.status == 2 %>
已通过
<% else %>
已拒绝
<% end %>
</td>
<td align="center">
<%=format_date( homework.created_at ) %>
</td>
</tr>
<% end %>
<% end %>
</tbody>
</table>
</div>
<div class="pagination">
<%= pagination_links_full @obj_pages, @obj_count, :per_page_links => false %>
</div>
<% html_title(l(:label_apply_homework)) -%>

View File

@ -17,51 +17,51 @@
</div>
<div class="bloglistbox">
<% if topics.any? %>
<% topics.each do |activity| %>
<ul class="list-file">
<li><span class="item_list fl"></span>
<% if activity.parent_id.nil? %> <!--+"(帖子标题)"-->
<%= link_to activity.title.to_s.html_safe, user_blog_blog_comment_path(:user_id=>activity.author_id, :blog_id=>activity.blog.id,:id=>activity), :class=> "list-title fl" %>
<% else %>
<%= link_to activity.title.subject.to_s.html_safe, user_blog_blog_comment_path(:user_id=>activity.author_id, :blog_id=>activity.blog.id,:id=>activity), :class=> "list-title fl"%>
<% end %>
<% if activity.blog.homepage_id and activity.id == activity.blog.homepage_id %>
<span class="c_red ml10 fr">[已设为首页]</span>
<% end %>
<% if activity.sticky == 1 %>
<span class="fl ml10 red-cir-btn">顶</span>
<% end%>
<% if activity.locked %>
<span class="fl ml10 green-cir-btn" title="已锁定">锁</span>
<% end %>
<div class="cl"></div>
</li>
<% count=0 %>
<% if activity.parent %>
<% count=activity.parent.children.count%>
<% else %>
<% count=activity.children.count%>
<% end %>
<li class="ml15">
<% topics.each do |activity| %>
<ul class="list-file">
<li><span class="item_list fl"></span>
<% if activity.parent_id.nil? %> <!--+"(帖子标题)"-->
<%= link_to activity.title.to_s.html_safe, user_blog_blog_comment_path(:user_id=>activity.author_id, :blog_id=>activity.blog.id,:id=>activity), :class=> "list-title fl" %>
<% else %>
<%= link_to activity.title.subject.to_s.html_safe, user_blog_blog_comment_path(:user_id=>activity.author_id, :blog_id=>activity.blog.id,:id=>activity), :class=> "list-title fl"%>
<% end %>
<% if activity.blog.homepage_id and activity.id == activity.blog.homepage_id %>
<span class="font_normal ml10 fr">[已设为首页]</span>
<% end %>
<% if activity.sticky == 1 %>
<span class="fl ml10 red-cir-btn">顶</span>
<% end%>
<% if activity.locked %>
<span class="fl ml10 green-cir-btn" title="已锁定">锁</span>
<% end %>
<div class="cl"></div>
</li>
<% count=0 %>
<% if activity.parent %>
<% count=activity.parent.children.count%>
<% else %>
<% count=activity.children.count%>
<% end %>
<li class="ml15">
<span class="grayTxt">发布:<%= format_time(activity.created_on) %></span>
<span class="grayTxt">更新:<%= format_time(activity.updated_on) %></span>
<p class="list-info fr grayTxt">
<span><%= count>0 ? "#{count}" :"0" %></span>
<span>回复</span>
<span>|</span>
<span><%= get_praise_num(activity) > 0 ? "#{get_praise_num(activity)}" :"0" %></span>
<span>赞</span>
</p>
</li>
<div class="cl"></div>
</ul>
<% end %>
<div>
<ul class="wlist" id="pages" >
<%= pagination_links_full @atta_pages, @atta_count, :per_page_links => false, :remote => @is_remote, :flag => true %>
</ul>
<p class="list-info fr grayTxt">
<span><%= count>0 ? "#{count}" :"0" %></span>
<span>回复</span>
<span>|</span>
<span><%= get_praise_num(activity) > 0 ? "#{get_praise_num(activity)}" :"0" %></span>
<span>赞</span>
</p>
</li>
<div class="cl"></div>
</div>
</ul>
<% end %>
<div>
<ul class="wlist" id="pages" >
<%= pagination_links_full @atta_pages, @atta_count, :per_page_links => false, :remote => @is_remote, :flag => true %>
</ul>
<div class="cl"></div>
</div>
<% else %>
<p class="nodata"><%= l(:label_no_data) %></p>
<% end %>

View File

@ -2,6 +2,7 @@
<%= import_ke(enable_at: true, prettify: false, init_activity: false) %>
<% end %>
<script type="text/javascript">
var first_click = true;
function nh_check_field(params){
var result=true;
if(!regexTopicSubject()) {
@ -49,10 +50,12 @@
contentmsg:params.contentmsg,
textarea:params.textarea
});
if(is_checked){
if(first_click && is_checked){
if(flag){
first_click = false;
return true;
}else{
first_click = false;
$(this)[0].submit();
return false;
}

View File

@ -18,7 +18,7 @@
<li class="fl">
<input name="outline_id" type="radio" value="<%= article.id%>" class="courseSendCheckbox"/>
</li>
<li class="blogTitle fl"><%= article.title%></li>
<li class="blogTitle fl mw220"><%= article.title%></li>
</ul>
<div class="homeworkPublishTime">发布时间:<%= format_date(article.created_at)%></div>
<% end %>

View File

@ -36,7 +36,7 @@
<textarea placeholder="有问题或有建议,请直接给我留言吧!" nhname='new_message_textarea_' name="new_form[course_message]"></textarea>
<p nhname='contentmsg_'></p>
<a id="new_message_cancel_btn_" href="javascript:void(0)" class="grey_btn fr mt10">取消</a>
<a href="javascript:void(0);" class="blue_btn fr ml10 mt10" id="submit_feedback_course" >留言</a>
<a href="javascript:void(0);" class="blue_btn fr ml10 mt10" id="new_message_submit_btn_" >留言</a>
<% end %>
</div>
<% end %>
@ -55,9 +55,6 @@
<script type="text/javascript">
$(function(){
$("#submit_feedback_course").one('click',function() {
$("#course_feedback_new").submit();
});
KindEditor.ready(function(K){
$("a[nhname='reply_btn']").live('click',function(){
var params = {};
@ -68,6 +65,7 @@
params.textarea = $("textarea[name='user_notes']",params.div_form);
params.contentmsg = $("p[nhname='contentmsg']",params.div_form);
params.toolbar_container = $("div[nhname='toolbar_container']",params.div_form);
params.submit_btn = $("input[nhname='submit_btn']",params.div_form);
params.cancel_btn = $("input[nhname='cancel_btn']",params.div_form);
params.height = 55;
if(params.textarea.data('init') == undefined){
@ -76,6 +74,9 @@
params.cancel_btn.click(function(){
nh_reset_form(params);
});
params.submit_btn.one('click', function () {
params.form.submit();
});
}
params.cancel_btn.click();
toggleAndSettingWordsVal(params.div_form, params.textarea);

View File

@ -1 +1,2 @@
$("#st_groups").html("<%= escape_javascript( render :partial => 'new_groups_name', locals: {:course_groups => @course_groups})%>");
$("#st_groups").html("<%= escape_javascript( render :partial => 'new_groups_name', locals: {:course_groups => @course_groups})%>");
$("#member_content").html("<%= escape_javascript( render :partial => 'new_member_list', :locals => {:members => @members})%>");

View File

@ -9,7 +9,7 @@
<input type="password" style="display: none"/> <!--阻止表单自动填充 -->
<label><span class="c_red">*</span>&nbsp;<%= l(:label_tags_course_name)%>&nbsp;&nbsp;</label>
<input type="text" name="course[name]" id="course_name" class="courses_input" maxlength="100" onkeyup="regex_course_name();">
<span class="c_red" id="course_name_notice" style="display: none;">课程名称不能为空</span>
<span class="c_red" id="course_name_notice" style="display: none;">课程名称不能为空且至少有两个字符</span>
</li>
<div class="cl"></div>
<li class="ml45">

View File

@ -1,4 +1,5 @@
/**
* Created by Administrator on 2014/12/3.
*/
$("#st_groups").html("<%= escape_javascript( render :partial => 'new_groups_name', locals: {:course_groups => @course_groups})%>");
$("#st_groups").html("<%= escape_javascript( render :partial => 'new_groups_name', locals: {:course_groups => @course_groups})%>");
$("#member_content").html("<%= escape_javascript( render :partial => 'new_member_list', :locals => {:members => @members})%>");

View File

@ -87,10 +87,19 @@
var standard_ans = $.trim($("#question_standard_ans").val());
if(title.length == 0 || score.length == 0){
alert("题目标题/分数不能为空");
doc.one('click', function(){
add_poll_question($(this),quest_type);
});
}else if(!/^[1-9][0-9]*$/.test(score)) {
alert("分数必须是非零开头的数字");
doc.one('click', function(){
add_poll_question($(this),quest_type);
});
}else if(quest_type !=3 && standard_ans.length == 0) {
alert("标准答案不能为空");
doc.one('click', function(){
add_poll_question($(this),quest_type);
});
}else{
doc.parent().parent().parent().submit();}
}

View File

@ -54,9 +54,16 @@
</ul>
</div>
<div class="ur_editor_footer">
<a class="btn btn_dark btn_submit c_white" data-button="ok" onclick="add_poll_question($(this),1);"> 保存 </a>
<a class="btn btn_dark btn_submit c_white" data-button="ok" id="add_new_question"> 保存 </a>
<a class="btn btn_light btn_cancel" data-button="cancel" onclick="$(this).parent().parent().parent().remove();"> 取消 </a>
</div>
<div class="cl"></div>
</div>
<% end %>
<% end %>
<script type="text/javascript">
$(function(){
$("#add_new_question").one('click', function(){
add_poll_question($(this),1);
});
});
</script>

View File

@ -54,9 +54,16 @@
</ul>
</div>
<div class="ur_editor_footer">
<a class="btn btn_dark btn_submit c_white" data-button="ok" onclick="add_poll_question($(this),2);"> 保存 </a>
<a class="btn btn_dark btn_submit c_white" data-button="ok" id="add_new_question"> 保存 </a>
<a class="btn btn_light btn_cancel" data-button="cancel" onclick="$(this).parent().parent().parent().remove();"> 取消 </a>
</div>
<div class="cl"></div>
</div>
<% end %>
<% end %>
<script type="text/javascript">
$(function(){
$("#add_new_question").one('click', function(){
add_poll_question($(this),2);
});
});
</script>

View File

@ -42,9 +42,16 @@
</ul>
</div>
<div class="ur_editor_footer">
<a class="btn btn_dark btn_submit c_white" data-button="ok" onclick="add_poll_question($(this),3);"> 保存 </a>
<a class="btn btn_dark btn_submit c_white" data-button="ok" id="add_new_question"> 保存 </a>
<a class="btn btn_light btn_cancel" data-button="cancel" onclick="$(this).parent().parent().parent().remove();"> 取消 </a>
</div>
<div class="cl"></div>
</div>
<% end %>
<% end %>
<script type="text/javascript">
$(function(){
$("#add_new_question").one('click', function(){
add_poll_question($(this),3);
});
});
</script>

View File

@ -90,7 +90,7 @@
'</ul>'+
'</div>'+
'<div class="ur_editor_footer">'+
'<a class="btn btn_dark btn_submit c_white" data-button="ok" onclick="add_poll_question($(this),1);">'+
'<a class="btn btn_dark btn_submit c_white" data-button="ok" id="add_new_question">'+
'保存'+
'</a>'+
'<a class="btn btn_light btn_cancel" data-button="cancel" onclick="$(this).parent().parent().parent().remove();">'+
@ -102,6 +102,9 @@
'<% end%>'
);
$("#poll_questions_title").focus();
$("#add_new_question").one('click', function(){
add_poll_question($(this),1);
});
}
}
else {

View File

@ -89,7 +89,7 @@
'</ul>'+
'</div>'+
'<div class="ur_editor_footer">'+
'<a class="btn btn_dark btn_submit c_white" data-button="ok" onclick="add_poll_question($(this),2);">'+
'<a class="btn btn_dark btn_submit c_white" data-button="ok" id="add_new_question">'+
'保存'+
'</a>'+
'<a class="btn btn_light btn_cancel" data-button="cancel" onclick="$(this).parent().parent().parent().remove();">'+
@ -101,6 +101,9 @@
'<% end%>'
);
$("#poll_questions_title").focus();
$("#add_new_question").one('click', function(){
add_poll_question($(this),2);
});
}
}else {
$("#insert_new_poll_question_"+quest_type+"_"+quest_id).html("");

View File

@ -65,7 +65,7 @@
'</ul>'+
'</div>'+
'<div class="ur_editor_footer">'+
'<a class="btn btn_dark btn_submit c_white" data-button="ok" onclick="add_poll_question($(this),3);">'+
'<a class="btn btn_dark btn_submit c_white" data-button="ok" id="add_new_question">'+
'保存'+
'</a>'+
'<a class="btn btn_light btn_cancel" data-button="cancel" onclick="$(this).parent().parent().parent().remove();">'+
@ -77,6 +77,9 @@
'<% end%>'
);
$("#poll_questions_title").focus();
$("#add_new_question").one('click', function(){
add_poll_question($(this),3);
});
}
} else {
$("#insert_new_poll_question_"+quest_type+"_"+quest_id).html("");

View File

@ -50,29 +50,19 @@
}*/
</script>
<ul class="hworkListRow" id="student_work_<%= exercise.id%>">
<li class="hworkList340 width530">
<ul>
<li class="hworkPortrait mt15 mr10">
<%= link_to(image_tag(url_to_avatar(exercise.user),:width =>"40",:height => "40"),user_activities_path(exercise.user)) %>
</li>
<div id="show_student_result_div_<%= exercise.id%>" style="cursor: pointer;" class="student_work_<%= exercise.id%>">
<li>
<ul class="mt10 fl">
<li class="hworkStName mr15 mt16" title="姓名" id="student_name_<%= exercise.id%>">
<%=exercise.user.show_name %>
</li>
<li class="hworkStID mr10 mt16" title="学号" id="student_id_<%= exercise.id%>">
<%= exercise.user.user_extensions.nil? ? "--" : exercise.user.user_extensions.student_id%>
</li>
<li class="hworkStID mt16" title="班级" id="student_class_<%= exercise.id%>">
--
</li>
</ul>
</li>
</div>
</ul>
<li class="ml5 mr5" style="width:28px; text-align:center;">1</li>
<li class="hworkPortrait mt15 mr10">
<%= link_to(image_tag(url_to_avatar(exercise.user),:width =>"40",:height => "40",:style => "display:block;"),user_activities_path(exercise.user)) %>
</li>
<li class="hworkList130 c_grey student_work_<%= exercise.id%>">
<li class="hworkStName" title="姓名" id="student_name_<%= exercise.id%>" style="cursor:pointer;">
<%=exercise.user.show_name %>
</li><li class="hworkStID pl15 pr10" title="学号" id="student_id_<%= exercise.id%>" style="cursor:pointer;">
<%= exercise.user.user_extensions.nil? ? "--" : exercise.user.user_extensions.student_id%>
</li>
<li class="hworkStID" title="班级" id="student_class_<%= exercise.id%>" style="cursor:pointer;">
--
</li>
<li class="hworkList130 ml200 c_grey student_work_<%= exercise.id%>">
<% if exercise.created_at%>
<%= Time.parse(format_time(exercise.created_at)).strftime("%m-%d %H:%M")%>&nbsp;
<% if @exercise.end_time <= exercise.created_at %>

View File

@ -1,5 +1,6 @@
<ul class="hworkUl">
<li class="hworkList340 hworkH30 width530">
<span class="c_dark f14 fb fl mr5">序号</span>
<span class="c_dark f14 fb fl mr55">&nbsp;&nbsp;</span>
<span class="c_dark f14 fb fl mr60">姓名</span>
<span class="c_dark f14 fb fl mr60">学号</span>

View File

@ -43,8 +43,8 @@
</div>
<div class="homepagePostSetting">
<ul>
<% if User.current.logged? %>
<li class="homepagePostSettingIcon">
<% if User.current.logged? %>
<% if (delete_allowed || User.current.id == file.author_id) && file.container_id == org_subfield.id && file.container_type == "OrgSubfield" %>
<ul class="homepagePostSettiongText">
<li><%= link_to("发&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;送".html_safe, 'javascript:void(0)',:class => "postOptionLink",:onclick=>"show_send('#{file.id}','#{User.current.id}','file')") %></li>
@ -66,8 +66,8 @@
<li><%= link_to("发&nbsp;&nbsp;送".html_safe, 'javascript:void(0)',:class => "postOptionLink2",:onclick=>"show_send('#{file.id}','#{User.current.id}','file')") %></li>
</ul>
<% end %>
<% end %>
</li>
<% end %>
</ul>
</div>

View File

@ -23,7 +23,7 @@
<!--<input type="submit" name="" value="上传文件" class="f_l ml10" style="width:80px; height:26px;">-->
<span id="upload_file_count<%=container.id %>">
建议上传 长度为1452px/高度为304px 的图片
建议上传 长度:1920px 高度:313px 的图片
</span>
<div class="cl"></div>
<div>

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