Merge branch 'develop' into cxt_course
Conflicts: app/controllers/admin_controller.rb config/routes.rb lib/redmine.rb
This commit is contained in:
commit
7481d96166
|
@ -30,3 +30,4 @@ vendor/cache
|
|||
/public/files
|
||||
/tags
|
||||
/config/initializers/gitlab_config.rb
|
||||
1234567
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
{"access_token":"bFlabz0uBcoIBfWL7nBJkgpl26aOWDy-dyCOvH_MjUo_hMOOKG83WV1cCL1MG6H-AE-6eMI0iyLoOoAMv9Y3pFFsLYD-GAGr3UH9fT8OqeHMDlFhXyRTvHv9l2QPHGpcARUcCGANEH","expires_in":7200,"got_token_at":1462934760}
|
15
Gemfile
15
Gemfile
|
@ -1,11 +1,12 @@
|
|||
source 'https://ruby.taobao.org'
|
||||
#source 'http://ruby.sdutlinux.org/'
|
||||
source 'https://rubygems.org/'
|
||||
### 这里执行bundle config mirror.https://rubygems.org https://gems.ruby-china.org 切换到ruby-china源
|
||||
|
||||
unless RUBY_PLATFORM =~ /w32/
|
||||
# unix-like only
|
||||
gem 'iconv'
|
||||
end
|
||||
|
||||
gem 'wechat',path: 'lib/wechat'
|
||||
gem 'grack', path:'lib/grack'
|
||||
gem 'gitlab', path: 'lib/gitlab-cli'
|
||||
gem 'rest-client'
|
||||
|
@ -16,8 +17,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'
|
||||
|
@ -40,10 +42,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
|
||||
|
|
|
@ -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?
|
||||
|
|
|
@ -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
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -0,0 +1,65 @@
|
|||
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 :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
|
|
@ -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
|
||||
|
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
||||
|
|
|
@ -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,29 @@ 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 :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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
||||
#我的二维码
|
||||
|
|
|
@ -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
|
|
@ -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
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
# Place all the behaviors and hooks related to the matching controller here.
|
||||
# All this logic will automatically be available in application.js.
|
||||
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
|
|
@ -0,0 +1,3 @@
|
|||
# Place all the behaviors and hooks related to the matching controller here.
|
||||
# All this logic will automatically be available in application.js.
|
||||
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
|
|
@ -0,0 +1,3 @@
|
|||
# Place all the behaviors and hooks related to the matching controller here.
|
||||
# All this logic will automatically be available in application.js.
|
||||
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
|
|
@ -0,0 +1,3 @@
|
|||
// Place all the styles related to the ShieldWechatMessages controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
|
@ -0,0 +1,3 @@
|
|||
// Place all the styles related to the sub_document_comments controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
|
@ -0,0 +1,3 @@
|
|||
// Place all the styles related to the sub_domains controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
|
@ -593,6 +593,57 @@ class AdminController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
#代码测试列表
|
||||
def code_work_tests
|
||||
#求出所有条数
|
||||
tCount = CodeTests.count()
|
||||
|
||||
#设置个空的数组 以便paginateHelper来分页
|
||||
@code_work_tests = []
|
||||
if tCount >= 1
|
||||
@code_work_tests[tCount-1] = {}
|
||||
end
|
||||
@code_work_tests = paginateHelper @code_work_tests,30
|
||||
@page = (params['page'] || 1).to_i - 1
|
||||
|
||||
#取出需要的那一页数据
|
||||
tStart = @page*30
|
||||
@code_work_tests = CodeTests.find_by_sql("select * from code_tests order by id desc limit #{tStart},30 ")
|
||||
|
||||
#取出各个作品是否是模拟答题的
|
||||
is_test = {}
|
||||
#作品是否存在
|
||||
link_swork = {}
|
||||
#作业是否存在
|
||||
link_hwork = {}
|
||||
@code_work_tests.each do |test|
|
||||
#作品是否存在
|
||||
if is_test[test['student_work_id']] != nil
|
||||
test['link_swork'] = link_swork[test['student_work_id']]
|
||||
test['is_test'] = is_test[test['student_work_id']]
|
||||
else
|
||||
work = StudentWork.where("id=?",test['student_work_id']).first
|
||||
test['link_swork'] = !work.nil?
|
||||
test['is_test'] = work.nil? ? false : work.is_test
|
||||
#test['is_test'] = CodeTests.find_by_sql("select is_test from student_works where id = #{test['student_work_id']}").first['is_test']
|
||||
is_test[test['student_work_id']] = test['is_test']
|
||||
link_swork[test['student_work_id']] = test['link_swork']
|
||||
end
|
||||
|
||||
#作业是否存在
|
||||
if link_hwork[test['homework_id']] != nil
|
||||
test['link_hwork'] = link_hwork[test['homework_id']]
|
||||
else
|
||||
hwork = HomeworkCommon.where("id=?",test['homework_id']).first
|
||||
test['link_hwork'] = !hwork.nil?
|
||||
link_hwork[test['homework_id']] = test['link_hwork']
|
||||
end
|
||||
end
|
||||
|
||||
respond_to do |format|
|
||||
format.html
|
||||
end
|
||||
end
|
||||
#分享作业申请
|
||||
def apply_for_homework
|
||||
homeworks = ApplyHomework.where("user_id != 0")
|
||||
|
@ -601,6 +652,4 @@ class AdminController < ApplicationController
|
|||
respond_to do |format|
|
||||
format.html
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
endend
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,9 +1,55 @@
|
|||
class BlogsController < ApplicationController
|
||||
before_filter :find_blog,:except => [:index,:create,:new,:set_homepage, :cancel_homepage]
|
||||
before_filter :find_user
|
||||
include PraiseTreadHelper
|
||||
|
||||
def index
|
||||
@article = BlogComment.new
|
||||
|
||||
@order, @b_sort,@type = params[:order] || 1, params[:sort] || 1, params[:type] || 1
|
||||
|
||||
#确定 sort_type 1升序 2 降序
|
||||
if @order.to_i == @type.to_i
|
||||
@b_sort = @b_sort.to_i == 1 ? 2 : 1
|
||||
else
|
||||
@b_sort = 2
|
||||
end
|
||||
|
||||
sort_name = "updated_at"
|
||||
|
||||
sort_type = @b_sort == 1 ? "asc" : "desc"
|
||||
|
||||
@topics = @user.blog.articles.reorder("#{BlogComment.table_name}.sticky desc,#{BlogComment.table_name}.#{sort_name} #{sort_type}")
|
||||
|
||||
#根据 赞+回复数排序
|
||||
if @order.to_i == 2
|
||||
@type = 2
|
||||
|
||||
@topics.each do |topic|
|
||||
topic[:infocount] = get_praise_num(topic) + (topic.parent ? topic.parent.children.count : topic.children.count)
|
||||
if topic[:infocount] < 0
|
||||
topic[:infocount] = 0
|
||||
end
|
||||
end
|
||||
|
||||
@b_sort == 1 ? @topics = @topics.sort{|x,y| x[:infocount] <=> y[:infocount] } : @topics = @topics.sort{|x,y| y[:infocount] <=> x[:infocount] }
|
||||
|
||||
@topics = sort_by_sticky @topics
|
||||
@topics = sortby_time_countcommon_hassticky @topics,sort_name
|
||||
else
|
||||
@type = 1
|
||||
end
|
||||
|
||||
#分页
|
||||
@limit = 10
|
||||
@is_remote = true
|
||||
@atta_count = @topics.count
|
||||
@atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1
|
||||
@offset ||= @atta_pages.offset
|
||||
@topics = paginateHelper @topics,@limit
|
||||
|
||||
respond_to do |format|
|
||||
format.js
|
||||
format.html {render :layout=>'new_base_user'}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -28,6 +28,7 @@ class BoardsController < ApplicationController
|
|||
helper :watchers
|
||||
helper :project_score
|
||||
helper :attachments
|
||||
include PraiseTreadHelper
|
||||
def index
|
||||
#modify by nwb
|
||||
@flag = params[:flag] || false
|
||||
|
@ -62,13 +63,24 @@ class BoardsController < ApplicationController
|
|||
else
|
||||
render_403
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def show
|
||||
# 讨论区消息状态更新(已读和未读)
|
||||
@order, @b_sort,@type = params[:order] || 1, params[:sort] || 1, params[:type] || 1
|
||||
|
||||
#确定 sort_type 1升序 2 降序
|
||||
if @order.to_i == @type.to_i
|
||||
@b_sort = @b_sort.to_i == 1 ? 2 : 1
|
||||
else
|
||||
@b_sort = 2
|
||||
end
|
||||
|
||||
sort_name = "updated_on"
|
||||
|
||||
sort_type = @b_sort == 1 ? "asc" : "desc"
|
||||
|
||||
if @project
|
||||
ForgeMessage.where("user_id =? and project_id =? and viewed =?", User.current.id, @project.id, 0).update_all(:viewed => true)
|
||||
# 更新@消息为已读
|
||||
|
@ -82,63 +94,88 @@ class BoardsController < ApplicationController
|
|||
CourseMessage.where("user_id =? and course_id =? and viewed =?", User.current.id, @course.id, 0).update_all(:viewed => true)
|
||||
end
|
||||
|
||||
sort_init 'updated_on', 'desc'
|
||||
sort_update 'created_on' => "#{Message.table_name}.created_on",
|
||||
'replies' => "#{Message.table_name}.replies_count",
|
||||
'updated_on' => "COALESCE(last_replies_messages.created_on, #{Message.table_name}.created_on)"
|
||||
# sort_init 'updated_on', 'desc'
|
||||
# sort_update 'created_on' => "#{Message.table_name}.created_on",
|
||||
# 'replies' => "#{Message.table_name}.replies_count",
|
||||
# 'updated_on' => "COALESCE(last_replies_messages.created_on, #{Message.table_name}.created_on)"
|
||||
|
||||
@is_new = params[:is_new]
|
||||
@topic_count = @board ? @board.topics.count : 0
|
||||
if @project
|
||||
if @board
|
||||
limit = 10;
|
||||
@topic_count = @board.topics.count();
|
||||
@topic_pages = (params[:page] ? params[:page].to_i + 1 : 0) *10
|
||||
@topics = @board.topics.reorder("#{Message.table_name}.sticky DESC, COALESCE(last_replies_messages.created_on, #{Message.table_name}.created_on) desc").
|
||||
limit(limit).offset(@topic_pages).includes(:last_reply).
|
||||
@topic_pages = 0#(params[:page] ? params[:page].to_i + 1 : 0) *10
|
||||
@topics = @board.topics.reorder("#{Message.table_name}.sticky DESC, COALESCE(last_replies_messages.created_on, #{Message.table_name}.created_on) #{sort_type}").
|
||||
offset(@topic_pages).includes(:last_reply).
|
||||
preload(:author, {:last_reply => :author}).all();
|
||||
else
|
||||
@topics = [];
|
||||
end
|
||||
elsif @course
|
||||
if (@board)
|
||||
limit = 10;
|
||||
@topic_count = @board.topics.count();
|
||||
@topic_pages = (params[:page] ? params[:page].to_i + 1 : 0) *10
|
||||
@topics = @board.topics.reorder("#{Message.table_name}.sticky DESC, COALESCE(last_replies_messages.created_on, #{Message.table_name}.created_on) desc").
|
||||
limit(limit).offset(@topic_pages).includes(:last_reply).
|
||||
preload(:author, {:last_reply => :author}).all();
|
||||
@topic_pages = 0 #(params[:page] ? params[:page].to_i + 1 : 0) *10
|
||||
@topics = @board.topics.reorder("#{Message.table_name}.sticky DESC, COALESCE(last_replies_messages.created_on, #{Message.table_name}.created_on) #{sort_type}").offset(@topic_pages).includes(:last_reply).preload(:author, {:last_reply => :author}).all();
|
||||
else
|
||||
@topics = [];
|
||||
end
|
||||
end
|
||||
|
||||
#根据 赞+回复数排序
|
||||
if @order.to_i == 2
|
||||
@type = 2
|
||||
@topics.each do |topic|
|
||||
topic[:infocount] = get_praise_num(topic) + (topic.parent ? topic.parent.children.count : topic.children.count)
|
||||
if topic[:infocount] < 0
|
||||
topic[:infocount] = 0
|
||||
end
|
||||
end
|
||||
@b_sort == 1 ? @topics = @topics.sort{|x,y| x[:infocount] <=> y[:infocount] } : @topics = @topics.sort{|x,y| y[:infocount] <=> x[:infocount] }
|
||||
@topics = sort_by_sticky @topics
|
||||
@topics = sortby_time_countcommon_hassticky @topics,sort_name
|
||||
else
|
||||
@type = 1
|
||||
end
|
||||
|
||||
#分页
|
||||
@limit = 15
|
||||
@is_remote = true
|
||||
@atta_count = @topics.count
|
||||
@atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1
|
||||
@offset ||= @atta_pages.offset
|
||||
@topics = paginateHelper @topics,@limit
|
||||
|
||||
@page = params[:page] ? params[:page].to_i + 1 : 0
|
||||
@message = Message.new(:board => @board)
|
||||
#modify by nwb
|
||||
respond_to do |format|
|
||||
format.js
|
||||
format.html {
|
||||
if @project
|
||||
render :action => 'show', :layout => 'base_projects'
|
||||
elsif @course
|
||||
@params=params
|
||||
render :action => 'show', :layout => 'base_courses'
|
||||
end
|
||||
}
|
||||
format.atom {
|
||||
@messages = @board.messages.
|
||||
reorder('created_on DESC').
|
||||
includes(:author, :board).
|
||||
limit(Setting.feeds_limit.to_i).
|
||||
all
|
||||
if @project
|
||||
render_feed(@messages, :title => "#{@project}: #{@board}")
|
||||
elsif @course
|
||||
render_feed(@messages, :title => "#{@course}: #{@board}")
|
||||
end
|
||||
|
||||
}
|
||||
if (params[:page] || params[:order])
|
||||
respond_to do |format|
|
||||
format.js{render "show.js.erb"}
|
||||
end
|
||||
else
|
||||
respond_to do |format|
|
||||
format.js
|
||||
format.html {
|
||||
if @project
|
||||
render :action => 'show', :layout => 'base_projects'
|
||||
elsif @course
|
||||
@params=params
|
||||
render :action => 'show', :layout => 'base_courses'
|
||||
end
|
||||
}
|
||||
format.atom {
|
||||
@messages = @board.messages.
|
||||
reorder('created_on DESC').
|
||||
includes(:author, :board).
|
||||
limit(Setting.feeds_limit.to_i).
|
||||
all
|
||||
if @project
|
||||
render_feed(@messages, :title => "#{@project}: #{@board}")
|
||||
elsif @course
|
||||
render_feed(@messages, :title => "#{@course}: #{@board}")
|
||||
end
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
@ -883,6 +883,7 @@ class CoursesController < ApplicationController
|
|||
@course_activities = course_activities.order('updated_at desc').limit(10).offset(@page * 10)
|
||||
end
|
||||
@type = params[:type]
|
||||
|
||||
respond_to do |format|
|
||||
format.js
|
||||
format.html{render :layout => 'base_courses'}
|
||||
|
@ -923,6 +924,82 @@ class CoursesController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def search_homework_member homeworks,name
|
||||
if name == ""
|
||||
select_homework = homeworks
|
||||
else
|
||||
name = name.downcase
|
||||
select_homework = homeworks.select{ |homework|
|
||||
homework.user[:login].to_s.downcase.include?(name) || homework.user.user_extensions[:student_id].to_s.downcase.include?(name) || (homework.user[:lastname].to_s.downcase + homework.user[:firstname].to_s.downcase).include?(name)
|
||||
}
|
||||
end
|
||||
select_homework
|
||||
end
|
||||
|
||||
# 作业查重
|
||||
def code_repeat
|
||||
#代码查重新加的
|
||||
@order,@b_sort,@name,@group = params[:order] || "score",params[:sort] || "desc",params[:name] || "",params[:group]
|
||||
|
||||
@is_teacher = User.current.allowed_to?(:as_teacher,@course) || User.current.admin?
|
||||
|
||||
if !@is_teacher
|
||||
render_403
|
||||
return
|
||||
end
|
||||
|
||||
@homework = HomeworkCommon.find params[:homework]
|
||||
#order("#{@order} #{@b_sort}"
|
||||
@student_works = search_homework_member @homework.student_works.select("student_works.*,IF(final_score is null,null,IF(final_score = 0, 0, final_score - absence_penalty - late_penalty)) as score").order("simi_value desc"),@name
|
||||
|
||||
@works_hash = {}
|
||||
|
||||
@student_works.each do |tmpwork|
|
||||
@works_hash[tmpwork.id] = tmpwork
|
||||
puts tmpwork.id
|
||||
end
|
||||
|
||||
#respond_to do |format|
|
||||
#format.html {render :layout => 'base_courses'}
|
||||
#end
|
||||
end
|
||||
|
||||
def show_comparecode
|
||||
|
||||
src_id = params[:src_id]
|
||||
dst_id = params[:dst_id]
|
||||
|
||||
@is_teacher = User.current.allowed_to?(:as_teacher,@course) || User.current.admin?
|
||||
|
||||
if !@is_teacher
|
||||
render_403
|
||||
return
|
||||
end
|
||||
|
||||
src_work = StudentWork.where("id =?", src_id).first
|
||||
|
||||
@homework = HomeworkCommon.find params[:homework_id]
|
||||
|
||||
@simi_value = src_work.simi_value.to_i
|
||||
|
||||
@src_code = src_work.description
|
||||
src_user = User.where("id =?", src_work.user_id).first
|
||||
|
||||
@src_username = src_user.try(:realname) != " " ? src_user.lastname + src_user.firstname : src_user.try(:login)
|
||||
|
||||
#descriotion user name
|
||||
|
||||
dst_work = StudentWork.where("id =?", dst_id).first
|
||||
@dst_code = dst_work.description
|
||||
dst_user = User.where("id =?", dst_work.user_id).first
|
||||
|
||||
@dst_username = dst_user.try(:realname) != " " ? dst_user.lastname + dst_user.firstname : dst_user.try(:login)
|
||||
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
#根据已有课程复制课程
|
||||
#param id:已有课程ID
|
||||
def copy_course
|
||||
|
|
|
@ -76,11 +76,18 @@ 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
|
||||
|
@ -97,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]
|
||||
|
@ -119,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
|
||||
|
||||
|
@ -401,7 +416,7 @@ class HomeworkCommonController < ApplicationController
|
|||
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 time < project_time
|
||||
if format_time(time) < format_time(project_time)
|
||||
time = project_time
|
||||
end
|
||||
begin
|
||||
|
@ -411,7 +426,7 @@ class HomeworkCommonController < ApplicationController
|
|||
changesets = g.commits(project.gpid, :ref_name => default_branch)
|
||||
changesets_latest_coimmit = changesets[0]
|
||||
unless changesets[0].blank?
|
||||
if time < changesets_latest_coimmit.created_at
|
||||
if format_time(time) < format_time(changesets_latest_coimmit.created_at)
|
||||
time = changesets_latest_coimmit.created_at
|
||||
end
|
||||
end
|
||||
|
|
|
@ -70,25 +70,71 @@ class NewsController < ApplicationController
|
|||
end
|
||||
elsif @course
|
||||
if (User.current.admin? || @course.is_public == 1 || (@course.is_public == 0 && User.current.member_of_course?(@course)))
|
||||
@order, @b_sort,@type = params[:order] || 1, params[:sort] || 1, params[:type] || 1
|
||||
|
||||
#确定 sort_type 1升序 2 降序
|
||||
if @order.to_i == @type.to_i
|
||||
@b_sort = @b_sort.to_i == 1 ? 2 : 1
|
||||
else
|
||||
@b_sort = 2
|
||||
end
|
||||
|
||||
sort_name = "updated_at"
|
||||
|
||||
sort_type = @b_sort == 1 ? "asc" : "desc"
|
||||
|
||||
#scope = News.find_by_sql("select a.*,b.updated_at from news a, course_activities b where a.course_id = 532 and a.course_id = b.course_id and b.course_act_id = a.id ) ")
|
||||
|
||||
scope = @course ? @course.news.course_visible : News.course_visible
|
||||
news_arr = scope.map{|news| news.id}
|
||||
|
||||
|
||||
@page = params[:page] ? params[:page].to_i + 1 : 0
|
||||
news_page = @page *10
|
||||
news_page = 0 #@page *10
|
||||
@news_count = scope.count
|
||||
@is_new = params[:is_new]
|
||||
@q = params[:subject]
|
||||
if params[:subject].nil? || params[:subject].blank?
|
||||
scope_order = scope.reorder("#{News.table_name}.sticky DESC, #{News.table_name}.created_on DESC").limit(10).offset(news_page).includes(:author,:course).all()
|
||||
scope_order = scope.reorder("#{News.table_name}.sticky DESC, #{News.table_name}.created_on #{sort_type}").offset(news_page).includes(:author,:course).all()
|
||||
#all(:include => [:author, :course],
|
||||
#:order => "#{News.table_name}.sticky DESC, #{News.table_name}.created_on DESC").limit(10).offset(news_page)
|
||||
else
|
||||
scope_order = scope.where("#{News.table_name}.title like '#{'%' << params[:subject].to_s << '%'}'").reorder("#{News.table_name}.sticky DESC, #{News.table_name}.created_on DESC").limit(10).offset(news_page).includes(:author,:course).all()
|
||||
scope_order = scope.where("#{News.table_name}.title like '#{'%' << params[:subject].to_s << '%'}'").reorder("#{News.table_name}.sticky DESC, #{News.table_name}.#{sort_name} #{sort_type}").offset(news_page).includes(:author,:course).all()
|
||||
#.all(:include => [:author, :course],:order => "#{News.table_name}.sticky DESC, #{News.table_name}.created_on DESC")
|
||||
end
|
||||
|
||||
scope_order.each do |topic|
|
||||
topic[:updated_at] = topic.course_acts.first.updated_at
|
||||
#topic[:updated_at] = CourseActivity.where("course_act_type='#{topic.class}' and course_act_id =#{topic.id}").first.updated_at
|
||||
end
|
||||
|
||||
#根据 赞+回复数排序
|
||||
if @order.to_i == 2
|
||||
@type = 2
|
||||
scope_order.each do |topic|
|
||||
topic[:infocount] = get_praise_num(topic) + topic.comments.count
|
||||
if topic[:infocount] < 0
|
||||
topic[:infocount] = 0
|
||||
end
|
||||
end
|
||||
@b_sort == 1 ? scope_order = scope_order.sort{|x,y| x[:infocount] <=> y[:infocount] } : scope_order = scope_order.sort{|x,y| y[:infocount] <=> x[:infocount] }
|
||||
scope_order = sort_by_sticky scope_order
|
||||
scope_order = sortby_time_countcommon_hassticky scope_order,sort_name
|
||||
else
|
||||
@type = 1
|
||||
@b_sort == 1 ? scope_order = scope_order.sort{|x,y| x[:updated_at] <=> y[:updated_at] } : scope_order = scope_order.sort{|x,y| y[:updated_at] <=> x[:updated_at] }
|
||||
scope_order = sort_by_sticky scope_order
|
||||
end
|
||||
|
||||
@newss = scope_order
|
||||
|
||||
#分页
|
||||
@limit = 15
|
||||
@is_remote = true
|
||||
@atta_count = @newss.count
|
||||
@atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1
|
||||
@offset ||= @atta_pages.offset
|
||||
@newss = paginateHelper @newss,@limit
|
||||
|
||||
#@newss = paginateHelper scope_order,10
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
|
|
|
@ -76,21 +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])
|
||||
# 统计访问量
|
||||
@organization.update_column(:visits, @organization.visits.to_i + 1)
|
||||
|
||||
# @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
|
||||
|
@ -98,33 +91,13 @@ 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])
|
||||
# 统计访问量
|
||||
@organization.update_column(:visits, @organization.visits.to_i + 1)
|
||||
if params[:org_subfield_id]
|
||||
@org_subfield = OrgSubfield.find(params[:org_subfield_id])
|
||||
@org_subfield_ids = @org_subfield.org_document_comments.map(&:id) << 0
|
||||
|
@ -192,7 +165,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
|
||||
|
@ -203,7 +176,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
|
||||
|
|
|
@ -319,9 +319,25 @@ class ProjectsController < ApplicationController
|
|||
else
|
||||
@events_pages = ForgeActivity.includes(:project).where("forge_activities.project_id = ? and projects.is_public = ? and forge_act_type != ? ",@project,1, "Document").order("created_at desc").page(params['page'|| 1]).per(10);
|
||||
end
|
||||
g = Gitlab.client
|
||||
unless @project.gpid.nil?
|
||||
@static_total_per_user = g.rep_stats(@project.gpid)
|
||||
# g = Gitlab.client
|
||||
unless @project.gpid.nil? || @project.project_score.changeset_num == 0
|
||||
# rep_statics_commit = @project.rep_statics.order("commits_num desc")
|
||||
rep_statics_commit = RepStatics.find_by_sql("SELECT * FROM `rep_statics` where project_id = #{@project.id} order by commits_num desc limit 10")
|
||||
rep_statics_code = RepStatics.find_by_sql("SELECT * FROM `rep_statics` where project_id = #{@project.id} order by changeset desc limit 10")
|
||||
# rep_statics_code = @project.rep_statics.sort_by {|u| u.changeset}.reverse
|
||||
@a_uname = rep_statics_commit.map {|s| s.uname }
|
||||
@a_uname_code = rep_statics_code.map {|s| s.uname }
|
||||
@a_commits_num = rep_statics_commit.map {|s| s.commits_num.to_i }
|
||||
@a_commits_add = rep_statics_code.map {|s| s.add.to_i }
|
||||
@a_commits_del = rep_statics_code.map {|s| s.del.to_i }
|
||||
@a_commits_changeset = rep_statics_code.map {|s| s.changeset.to_i }
|
||||
g = Gitlab.client
|
||||
begin
|
||||
g_branch = g.project(@project.gpid).default_branch.to_s
|
||||
rescue
|
||||
logger.error("get gitlab project failed!")
|
||||
end
|
||||
@rev = g_branch.nil? ? "master" : g_branch
|
||||
end
|
||||
# 根据对应的请求,返回对应的数据
|
||||
respond_to do |format|
|
||||
|
|
|
@ -325,31 +325,17 @@ update
|
|||
end
|
||||
end
|
||||
|
||||
# unless @repository.gitlab?
|
||||
# # redirect_to to_gitlab_project_repository_path(@project, @repository)
|
||||
# render :to_gitlab
|
||||
# return
|
||||
# end
|
||||
|
||||
#if( !User.current.member_of?(@project) || @project.hidden_repo)
|
||||
# @repository.fetch_changesets if Setting.autofetch_changesets? && @path.empty?
|
||||
|
||||
# :name, :path, :kind, :size, :lastrev, :changeset
|
||||
@entries = @repository.entries(@path, @rev)
|
||||
# @trees = g.trees(project, @path)
|
||||
@changeset = @repository.find_changeset_by_name(@rev)
|
||||
#@project_path_cut = RepositoriesHelper::PROJECT_PATH_CUT
|
||||
#@ip = RepositoriesHelper::REPO_IP_ADDRESS
|
||||
|
||||
if request.xhr?
|
||||
@entries ? render(:partial => 'dir_list_content') : render(:nothing => true)
|
||||
else
|
||||
#Modified by young
|
||||
# (show_error_not_found; return) unless @entries
|
||||
g = Gitlab.client
|
||||
@changesets = g.commits(@project.gpid, :ref_name => @rev)
|
||||
g_project = g.project(@project.gpid)
|
||||
# 总的提交数
|
||||
@changesets_all_count = @project.gpid.nil? ? 0 : g.project(@project.gpid).commit_count
|
||||
@changesets_all_count = @project.gpid.nil? ? 0 : g_project.commit_count
|
||||
@g_default_branch = g_project.default_branch.nil? ? "master" : g_project.default_branch
|
||||
# 访问该页面的是会后则刷新
|
||||
if @project.project_score.nil?
|
||||
ProjectScore.create(:project_id => @project.id, :score => false)
|
||||
|
@ -358,17 +344,16 @@ update
|
|||
if @changesets_all_count != @project.project_score.changeset_num && @changesets_all_count != 0
|
||||
update_commits_count(@project, @changesets_all_count)
|
||||
end
|
||||
# end
|
||||
# 最近一次提交
|
||||
@changesets_latest_coimmit = @changesets[0]
|
||||
unless @changesets[0].blank?
|
||||
update_commits_date(@project, @changesets_latest_coimmit)
|
||||
end
|
||||
@creator = User.where("id =?", @project.user_id).first.try(:login)
|
||||
@properties = @repository.properties(@path, @rev)
|
||||
@repositories = @project.repositories
|
||||
project_path_cut = RepositoriesHelper::PROJECT_PATH_CUT
|
||||
ip = RepositoriesHelper::REPO_IP_ADDRESS
|
||||
# @properties = @repository.properties(@path, @rev)
|
||||
# @repositories = @project.repositories
|
||||
# project_path_cut = RepositoriesHelper::PROJECT_PATH_CUT
|
||||
# ip = RepositoriesHelper::REPO_IP_ADDRESS
|
||||
gitlab_address = Redmine::Configuration['gitlab_address']
|
||||
if @repository.type.to_s == "Repository::Gitlab"
|
||||
@repos_url = gitlab_address.to_s+"/"+@project.owner.to_s+"/"+@repository.identifier+"."+"git"
|
||||
|
@ -573,9 +558,17 @@ update
|
|||
g = Gitlab.client
|
||||
begin
|
||||
@static_total_per_user = g.rep_stats(project_id, :rev => rev)
|
||||
@static_total_per_user
|
||||
# @static_month__per_user = g.rep_stats(project_id, :rev => rev, :creator => creator, :period => 2)
|
||||
# @static_week_per_user = g.rep_stats(project_id, :rev => rev, :creator => creator, :period => 3)
|
||||
# 更新rep_statics统计数
|
||||
@static_total_per_user.each do |static|
|
||||
rep_static = RepStatics.where("project_id =? and email =?", @project.id, static.email.to_s).first
|
||||
if rep_static.nil?
|
||||
RepStatics.create(:project_id => @project.id, :uname => static.uname, :commits_num => static.commits_num, :email => static.email, :add => static.add, :del => static.del, :changeset => static.changes)
|
||||
else
|
||||
if @rev == params[:default_branch]
|
||||
rep_static.update_attributes(:uname => static.uname, :commits_num => static.commits_num, :email => static.email, :add => static.add, :del => static.del, :changeset => static.changes)
|
||||
end
|
||||
end
|
||||
end
|
||||
rescue
|
||||
render_404
|
||||
return
|
||||
|
|
|
@ -32,6 +32,10 @@ class SettingsController < ApplicationController
|
|||
hidden_non_project = Setting.find_by_name("hidden_non_project")
|
||||
@text = (hidden_non_project && hidden_non_project.value == "0") ? l(:label_show_non_project) : l(:label_hidden_non_project)
|
||||
|
||||
#1隐藏了课程信息 0显示了课程信息
|
||||
hidden_courses = Setting.find_by_name("hidden_courses")
|
||||
@text_1 = (hidden_courses && hidden_courses.value == "1") ? l(:label_show_courses) : l(:label_hidden_courses)
|
||||
|
||||
@notifiables = Redmine::Notifiable.all
|
||||
if request.post? && params[:settings] && params[:settings].is_a?(Hash)
|
||||
settings = (params[:settings] || {}).dup.symbolize_keys
|
||||
|
@ -89,4 +93,22 @@ class SettingsController < ApplicationController
|
|||
|
||||
redirect_to settings_url
|
||||
end
|
||||
|
||||
#隐藏/显示课程信息
|
||||
def hidden_courses
|
||||
@notifiable = Setting.find_by_name("hidden_courses")
|
||||
if @notifiable
|
||||
@notifiable.value == "1" ? @notifiable.value = 0 : @notifiable.value = 1
|
||||
@notifiable.save
|
||||
else
|
||||
@notifiable = Setting.new()
|
||||
@notifiable.name = "hidden_courses"
|
||||
@notifiable.value = 1
|
||||
@notifiable.save
|
||||
end
|
||||
|
||||
redirect_to settings_url
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
|
|
@ -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
|
|
@ -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
|
|
@ -5,7 +5,7 @@ class StudentWorkController < ApplicationController
|
|||
include ApplicationHelper
|
||||
require 'bigdecimal'
|
||||
require "base64"
|
||||
before_filter :find_homework, :only => [:new, :index, :create, :student_work_absence_penalty, :absence_penalty_list, :evaluation_list, :program_test,:program_test_ex,:set_score_rule,:forbidden_anonymous_comment,:delete_work,:new_student_work_project,:student_work_project,:cancel_relate_project,:search_course_students]
|
||||
before_filter :find_homework, :only => [:new, :index, :create, :student_work_absence_penalty, :absence_penalty_list, :evaluation_list, :program_test,:program_test_ex,:set_score_rule,:forbidden_anonymous_comment,:delete_work,:new_student_work_project,:student_work_project,:cancel_relate_project,:search_course_students,:work_canrepeat]
|
||||
before_filter :find_work, :only => [:edit, :update, :show, :destroy, :add_score, :praise_student_work,:retry_work,:revise_attachment]
|
||||
before_filter :member_of_course, :only => [:new, :create, :show, :add_score, :praise_student_work]
|
||||
before_filter :author_of_work, :only => [:edit, :update, :destroy]
|
||||
|
@ -17,41 +17,41 @@ class StudentWorkController < ApplicationController
|
|||
is_test = params[:is_test] == 'true'
|
||||
resultObj = {status: 0, results: [], error_msg: '', time: Time.now.strftime('%Y-%m-%d %T')}
|
||||
|
||||
student_work = find_or_save_student_work(is_test)
|
||||
student_work = find_or_save_student_work(is_test)
|
||||
|
||||
unless student_work
|
||||
resultObj[:status] = 100
|
||||
else
|
||||
if @homework.homework_type == 2 && @homework.homework_detail_programing
|
||||
result = test_realtime(student_work, params[:src])
|
||||
logger.debug result
|
||||
resultObj[:status] = result["status"]
|
||||
resultObj[:results] = result["results"]
|
||||
resultObj[:error_msg] = result["error_msg"]
|
||||
results = result["results"]
|
||||
if result["status"].to_i == -2 #编译错误
|
||||
results = [result["error_msg"]]
|
||||
end
|
||||
student_work_test = student_work.student_work_tests.build(status: result["status"], results: results,
|
||||
src: params[:src])
|
||||
unless student_work.save
|
||||
resultObj[:status] = 200
|
||||
unless student_work
|
||||
resultObj[:status] = 100
|
||||
else
|
||||
if @homework.homework_type == 2 && @homework.homework_detail_programing
|
||||
result = test_realtime(student_work, params[:src])
|
||||
logger.debug result
|
||||
resultObj[:status] = result["status"]
|
||||
resultObj[:results] = result["results"]
|
||||
resultObj[:error_msg] = result["error_msg"]
|
||||
results = result["results"]
|
||||
if result["status"].to_i == -2 #编译错误
|
||||
results = [result["error_msg"]]
|
||||
end
|
||||
student_work_test = student_work.student_work_tests.build(status: result["status"], results: results,
|
||||
src: params[:src])
|
||||
unless student_work.save
|
||||
resultObj[:status] = 200
|
||||
else
|
||||
student_work.name = params[:title]
|
||||
student_work.description = params[:src]
|
||||
if Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") < Time.parse(Time.now.to_s).strftime("%Y-%m-%d")
|
||||
student_work.late_penalty = @homework.late_penalty
|
||||
else
|
||||
student_work.name = params[:title]
|
||||
student_work.description = params[:src]
|
||||
if Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") < Time.parse(Time.now.to_s).strftime("%Y-%m-%d")
|
||||
student_work.late_penalty = @homework.late_penalty
|
||||
else
|
||||
student_work.late_penalty = 0
|
||||
end
|
||||
student_work.save
|
||||
resultObj[:status] = result["status"].to_i
|
||||
resultObj[:time] = student_work_test.created_at.to_s(:db)
|
||||
resultObj[:index] = student_work.student_work_tests.count
|
||||
student_work.late_penalty = 0
|
||||
end
|
||||
student_work.save
|
||||
resultObj[:status] = result["status"].to_i
|
||||
resultObj[:time] = student_work_test.created_at.to_s(:db)
|
||||
resultObj[:index] = student_work.student_work_tests.count
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
render :json => resultObj
|
||||
end
|
||||
|
||||
|
@ -81,6 +81,8 @@ class StudentWorkController < ApplicationController
|
|||
#根据传入的tIndex确定是第几次测试
|
||||
#之后如果觉得很卡 可以改成将结果传回JS再以参数形式传回来
|
||||
def program_test_ex
|
||||
tStarttime = Time.now
|
||||
|
||||
is_test = params[:is_test] == 'true'
|
||||
resultObj = {status: 0, results: [], error_msg: '', time: Time.now.strftime('%Y-%m-%d %T'),tseq:1,tcount:1,testid:1} #保存每测试一次返回的结果
|
||||
|
||||
|
@ -92,83 +94,229 @@ class StudentWorkController < ApplicationController
|
|||
resultObj[:status] = 100
|
||||
else
|
||||
if @homework.homework_type == 2 && @homework.homework_detail_programing
|
||||
#找到第index个测试的输入输出
|
||||
index = params[:tIndex].to_i
|
||||
resultObj[:tseq] = index
|
||||
test = @homework.homework_tests[index - 1]
|
||||
#找到第index个测试的输入输出
|
||||
index = params[:tIndex].to_i
|
||||
resultObj[:tseq] = index
|
||||
test = @homework.homework_tests[index - 1]
|
||||
|
||||
#请求测试
|
||||
#请求测试
|
||||
begin
|
||||
result = test_realtime_ex(test, params[:src])
|
||||
rescue Timeout::Error
|
||||
tEndtime = Time.now
|
||||
tUsedtime = (tEndtime.to_i-tStarttime.to_i)*1000+(tEndtime.usec - tStarttime.usec)/1000
|
||||
logger.debug "program_test_ex user wait time = #{tUsedtime} 毫秒"
|
||||
|
||||
if result["status"].to_i != -2
|
||||
#result["results"].first['output'] = result["results"].first['output'].gsub(" ","□")
|
||||
#result["results"].first['result'] = result["results"].first['result'].gsub(" ","□")
|
||||
space_replace_1(result["results"].first['output'])
|
||||
space_replace_1(result["results"].first['result'])
|
||||
end
|
||||
#status 0:答案正确 -3http超时 -2:编译错误 -1:答案错误 2:程序运行超时
|
||||
CodeTests.create(:homework_id=>@homework.id,:language=>@homework.homework_detail_programing.language,:status=>-3,:wait_time=>tUsedtime,:student_work_id=>student_work.id)
|
||||
|
||||
logger.debug result
|
||||
end
|
||||
if result["status"].to_i != -2
|
||||
#result["results"].first['output'] = result["results"].first['output'].gsub(" ","□")
|
||||
#result["results"].first['result'] = result["results"].first['result'].gsub(" ","□")
|
||||
space_replace_1(result["results"].first['output'])
|
||||
space_replace_1(result["results"].first['result'])
|
||||
end
|
||||
|
||||
#-1 默认值 0全部正确并结束 2 超时 -2 编译错误
|
||||
resultObj[:status] = -1
|
||||
resultObj[:results] = result["results"].first #本次测试结果
|
||||
resultObj[:error_msg] = result["error_msg"] #编译错误时的信息
|
||||
logger.debug result
|
||||
|
||||
if result["status"].to_i == -2 #编译错误
|
||||
resultObj[:results] = result["error_msg"]
|
||||
resultObj[:status] = -2
|
||||
elsif result["results"][0]["status"].to_i == 2
|
||||
resultObj[:status] = 2
|
||||
end
|
||||
#-1 默认值 0全部正确并结束 2 超时 -2 编译错误
|
||||
resultObj[:status] = -1
|
||||
resultObj[:results] = result["results"].first #本次测试结果
|
||||
resultObj[:error_msg] = result["error_msg"] #编译错误时的信息
|
||||
|
||||
unless student_work.save
|
||||
resultObj[:status] = 200
|
||||
#该状态用于存入CodeTests
|
||||
tmpstatus = -1
|
||||
if result["status"].to_i == -2 #编译错误
|
||||
resultObj[:results] = result["error_msg"]
|
||||
resultObj[:status] = -2
|
||||
tmpstatus = -2
|
||||
elsif result["results"][0]["status"].to_i == 2
|
||||
resultObj[:status] = 2
|
||||
tmpstatus = 2
|
||||
end
|
||||
|
||||
if result["status"] == 0
|
||||
tmpstatus = 0
|
||||
end
|
||||
|
||||
unless student_work.save
|
||||
resultObj[:status] = 200
|
||||
else
|
||||
student_work.name = params[:title]
|
||||
student_work.description = params[:src]
|
||||
|
||||
if Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") < Time.parse(Time.now.to_s).strftime("%Y-%m-%d")
|
||||
student_work.late_penalty = @homework.late_penalty
|
||||
else
|
||||
student_work.name = params[:title]
|
||||
student_work.description = params[:src]
|
||||
|
||||
if Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") < Time.parse(Time.now.to_s).strftime("%Y-%m-%d")
|
||||
student_work.late_penalty = @homework.late_penalty
|
||||
else
|
||||
student_work.late_penalty = 0
|
||||
end
|
||||
|
||||
#每次从数据库取出上次的结果加上本次的结果再存入数据库
|
||||
status = result["status"]
|
||||
if index == 1
|
||||
student_work_test = student_work.student_work_tests.build(status: status,
|
||||
results: [resultObj[:results]],src: params[:src])
|
||||
student_work_test.save!
|
||||
resultObj[:testid] = student_work_test.id
|
||||
else
|
||||
#先从数据库取出result
|
||||
student_work_test = StudentWorkTest.find(params[:testid])
|
||||
results = student_work_test.results
|
||||
results << resultObj[:results]
|
||||
student_work_test.results = results
|
||||
student_work_test.status = (result["status"] != 0 ? result["status"] : student_work_test.status)
|
||||
student_work_test.save!
|
||||
status = student_work_test.status
|
||||
resultObj[:testid] = student_work_test.id
|
||||
end
|
||||
|
||||
#超时或编译错误则直接返回了并存入数据库
|
||||
if resultObj[:status] == 2 || resultObj[:status] == -2 || index == @homework.homework_tests.size
|
||||
if status == 0
|
||||
resultObj[:status] = 0
|
||||
end
|
||||
student_work.save!
|
||||
resultObj[:time] = student_work_test.created_at.to_s(:db)
|
||||
resultObj[:index] = student_work.student_work_tests.count
|
||||
end
|
||||
|
||||
#渲染返回结果
|
||||
render :json => resultObj
|
||||
student_work.late_penalty = 0
|
||||
end
|
||||
|
||||
#每次从数据库取出上次的结果加上本次的结果再存入数据库
|
||||
if result["status"].to_i != -2
|
||||
result["results"].first['user_wait'] = tUsedtime
|
||||
|
||||
if result["results"][0]["status"].to_i == 2
|
||||
result["status"] = 2
|
||||
end
|
||||
end
|
||||
|
||||
status = result["status"]
|
||||
if index == 1
|
||||
student_work_test = student_work.student_work_tests.build(status: status,
|
||||
results: [resultObj[:results]],src: params[:src])
|
||||
student_work_test.save!
|
||||
resultObj[:testid] = student_work_test.id
|
||||
else
|
||||
#先从数据库取出result
|
||||
student_work_test = StudentWorkTest.find(params[:testid])
|
||||
results = student_work_test.results
|
||||
results << resultObj[:results]
|
||||
student_work_test.results = results
|
||||
student_work_test.status = (result["status"] != 0 ? result["status"] : student_work_test.status)
|
||||
student_work_test.save!
|
||||
status = student_work_test.status
|
||||
resultObj[:testid] = student_work_test.id
|
||||
end
|
||||
|
||||
#超时或编译错误则直接返回了并存入数据库
|
||||
if resultObj[:status] == 2 || resultObj[:status] == -2 || index == @homework.homework_tests.size
|
||||
if status == 0
|
||||
resultObj[:status] = 0
|
||||
end
|
||||
student_work.save!
|
||||
resultObj[:time] = student_work_test.created_at.to_s(:db)
|
||||
resultObj[:index] = student_work.student_work_tests.count
|
||||
end
|
||||
|
||||
#将每次用户等待时间都存起来以便管理界面显示用
|
||||
tEndtime = Time.now
|
||||
tUsedtime = (tEndtime.to_i-tStarttime.to_i)*1000+(tEndtime.usec - tStarttime.usec)/1000
|
||||
logger.debug "program_test_ex user wait time = #{tUsedtime} 毫秒"
|
||||
|
||||
time_used = 0
|
||||
if result["status"].to_i != -2
|
||||
#至少一毫秒
|
||||
time_used = result["results"].first['time_used'] == 0 ? 1:result["results"].first['time_used']
|
||||
end
|
||||
#0:答案正确 -3http超时 -2:编译错误 -1:答案错误 2:程序运行超时
|
||||
CodeTests.create(:homework_id=>@homework.id,:language=>@homework.homework_detail_programing.language,:status=>tmpstatus,:time_used=>time_used,:wait_time=>tUsedtime,:student_work_id=>student_work.id)
|
||||
|
||||
#渲染返回结果
|
||||
render :json => resultObj
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#找出该作业的所有提交作业
|
||||
def find_all_student_work_by_homeid()
|
||||
all_studentwork = StudentWork.where("homework_common_id = #{@homework.id} and is_test = 0 ")
|
||||
|
||||
all_studentwork
|
||||
end
|
||||
|
||||
def request_code_repeattest(src)
|
||||
url = "#{Redmine::Configuration['jplag_server']}api/realtime_test.json"
|
||||
|
||||
factor = []
|
||||
src.each do |test|
|
||||
factor << {work_id: test.id, des: test.description,created_at:test.created_at.to_i}
|
||||
end
|
||||
|
||||
solutions = {
|
||||
homeid:@homework.id,
|
||||
language:@homework.homework_detail_programing.language,
|
||||
factor: factor
|
||||
}
|
||||
uri = URI(url)
|
||||
body = solutions.to_json
|
||||
|
||||
logger.debug "send body"
|
||||
logger.debug body
|
||||
|
||||
res = Net::HTTP.new(uri.host, uri.port).start do |client|
|
||||
request = Net::HTTP::Post.new(uri.path)
|
||||
request.body = body
|
||||
request["Content-Type"] = "application/json"
|
||||
client.request(request)
|
||||
end
|
||||
|
||||
JSON.parse(res.body)
|
||||
end
|
||||
|
||||
#点击代码查重按钮
|
||||
def work_canrepeat
|
||||
@homework_id = params[:homework]
|
||||
@course_id = params[:course_id]
|
||||
|
||||
all_studentwork = find_all_student_work_by_homeid()
|
||||
|
||||
@work_count = all_studentwork.count
|
||||
end
|
||||
|
||||
#代码查重 status: 0完成 -2不需要查重 -1查重失败不支持该语言
|
||||
def code_repeattest
|
||||
tStarttime = Time.now
|
||||
logger.debug "code_repeattest start is #{tStarttime}}"
|
||||
resultObj = {status: -2}
|
||||
|
||||
@homework = HomeworkCommon.find params[:homework]
|
||||
|
||||
all_studentwork = find_all_student_work_by_homeid()
|
||||
|
||||
if all_studentwork == nil
|
||||
resultObj[:status] = -2
|
||||
elsif all_studentwork.count <= 1
|
||||
resultObj[:status] = -2
|
||||
else
|
||||
|
||||
#@homework.homework_detail_programing.language、id、description
|
||||
logger.debug "time1 is #{Time.now.usec} "
|
||||
result = request_code_repeattest(all_studentwork)
|
||||
logger.debug "time2 is #{Time.now.usec} "
|
||||
|
||||
resultObj[:status] = result['status'].to_i
|
||||
# resultObj[:results] = result['results']
|
||||
|
||||
#Time.now, simi_id = simiworkid , simi_value = simivalue
|
||||
if resultObj[:status] == 0
|
||||
@homework.simi_time = Time.now
|
||||
resultObj[:comparetime] = @homework.simi_time
|
||||
@homework.update_column('simi_time', @homework.simi_time)
|
||||
|
||||
logger.debug "time3 is #{Time.now.usec} "
|
||||
result['results'].each do |key,value|
|
||||
@student_work = StudentWork.where("id =?", key.to_i).first
|
||||
@student_work.update_column('simi_id', value['simiworkid'].to_i)
|
||||
@student_work.update_column('simi_value', value['simivalue'].to_i)
|
||||
# sqlstr = "update student_works set simi_id=#{value['simiworkid']},simi_value=#{value['simivalue']} where id=#{key.to_i} "
|
||||
# dbh.execute(sqlstr)
|
||||
end
|
||||
logger.debug "time4 is #{Time.now.usec} "
|
||||
end
|
||||
end
|
||||
tEndtime = Time.now
|
||||
logger.debug "code_repeattest end is #{tEndtime}}"
|
||||
tUsedtime = (tEndtime.to_i-tStarttime.to_i)*1000000+(tEndtime.usec - tStarttime.usec)
|
||||
logger.debug "code_repeattest userd utime is #{tUsedtime}"
|
||||
render :json => resultObj
|
||||
end
|
||||
|
||||
#上次代码查重时间
|
||||
def last_codecomparetime
|
||||
resultObj = {status: 0}
|
||||
@homework = HomeworkCommon.find params[:homework]
|
||||
|
||||
#转换一下
|
||||
if @homework.simi_time != nil
|
||||
resultObj[:comparetime] = Time.parse(@homework.simi_time.to_s).strftime("%Y-%m-%d %H:%M:%S")
|
||||
else
|
||||
resultObj[:comparetime] = 0
|
||||
end
|
||||
|
||||
render :json => resultObj
|
||||
end
|
||||
|
||||
def index
|
||||
# 作业消息状态更新
|
||||
|
@ -351,9 +499,8 @@ class StudentWorkController < ApplicationController
|
|||
render_403
|
||||
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
|
||||
|
@ -451,7 +598,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)
|
||||
|
@ -505,7 +652,7 @@ class StudentWorkController < ApplicationController
|
|||
if @homework.homework_detail_group.base_on_project == 1
|
||||
stu_project.project_id = @student_work_project.project_id
|
||||
else @homework.homework_detail_group.base_on_project == 0
|
||||
stu_project.project_id = -1
|
||||
stu_project.project_id = -1
|
||||
end
|
||||
stu_project.user_id = members[i].to_i
|
||||
stu_project.is_leader = 0
|
||||
|
@ -825,7 +972,7 @@ class StudentWorkController < ApplicationController
|
|||
student_work.save
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@homework.save
|
||||
if params[:student_path]
|
||||
redirect_to student_work_index_url(:homework => @homework.id)
|
||||
|
@ -1038,10 +1185,10 @@ class StudentWorkController < ApplicationController
|
|||
sheet1[count_row,4] = homework.user.mail
|
||||
sheet1[count_row,5] = homework.name
|
||||
sheet1[count_row,6] = strip_html homework.description
|
||||
sheet1[count_row,7] = homework.teacher_score.nil? ? l(:label_without_score) : format("%.2f",homework.teacher_score)
|
||||
sheet1[count_row,8] = homework.teaching_asistant_score.nil? ? l(:label_without_score) : format("%.2f",homework.teaching_asistant_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,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
|
||||
|
@ -1057,11 +1204,11 @@ class StudentWorkController < ApplicationController
|
|||
sheet1[count_row,4] = homework.user.mail
|
||||
sheet1[count_row,5] = homework.name
|
||||
sheet1[count_row,6] = homework.description
|
||||
sheet1[count_row,7] = homework.teacher_score.nil? ? l(:label_without_score) : format("%.2f",homework.teacher_score)
|
||||
sheet1[count_row,8] = homework.teaching_asistant_score.nil? ? l(:label_without_score) : format("%.2f",homework.teaching_asistant_score)
|
||||
sheet1[count_row,9] = homework.system_score.nil? ? l(:label_without_score) : format("%.2f",homework.system_score)
|
||||
sheet1[count_row,10] = homework.student_score.nil? ? l(:label_without_score) : format("%.2f",homework.student_score)
|
||||
sheet1[count_row,11] = homework.respond_to?("score") ? homework.score.nil? ? l(:label_without_score) : format("%.2f",homework.score) : l(:label_without_score)
|
||||
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
|
||||
|
@ -1125,11 +1272,11 @@ class StudentWorkController < ApplicationController
|
|||
student_work = StudentWork.where(homework_common_id: @homework.id, user_id: User.current.id).first
|
||||
if student_work.nil?
|
||||
@homework.student_works.build(
|
||||
name: params[:title],
|
||||
description: params[:src],
|
||||
user_id: User.current.id,
|
||||
is_test: is_test
|
||||
)
|
||||
name: params[:title],
|
||||
description: params[:src],
|
||||
user_id: User.current.id,
|
||||
is_test: is_test
|
||||
)
|
||||
unless @homework.save
|
||||
logger.debug @homework.errors.full_messages
|
||||
else
|
||||
|
@ -1150,7 +1297,7 @@ class StudentWorkController < ApplicationController
|
|||
src:src,
|
||||
language:@homework.homework_detail_programing.language,
|
||||
factor: factor
|
||||
}
|
||||
}
|
||||
uri = URI(url)
|
||||
body = solutions.to_json
|
||||
res = Net::HTTP.new(uri.host, uri.port).start do |client|
|
||||
|
|
|
@ -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
|
|
@ -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
|
|
@ -41,7 +41,7 @@ class UsersController < ApplicationController
|
|||
:activity_score_index, :influence_score_index, :score_index,:show_new_score, :topic_new_score_index, :project_new_score_index,
|
||||
:activity_new_score_index, :influence_new_score_index, :score_new_index,:user_projects_index,:user_resource,
|
||||
:user_courses4show,:user_projects4show,:user_course_activities,:user_project_activities,:user_feedback4show,:user_visitorlist,:user_messages,:edit_brief_introduction,
|
||||
:user_import_homeworks,:user_search_homeworks,:user_import_resource, :user_system_messages,:choose_user_course]
|
||||
:user_import_homeworks,:user_search_homeworks,:user_import_resource, :user_system_messages,:choose_user_course,:user_courselist,:user_projectlist]
|
||||
before_filter :auth_user_extension, only: :show
|
||||
#before_filter :rest_user_score, only: :show
|
||||
#before_filter :select_entry, only: :user_projects
|
||||
|
@ -630,7 +630,9 @@ class UsersController < ApplicationController
|
|||
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 = 0")
|
||||
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 in #{course_ids}").order("#{@order} #{@b_sort}")
|
||||
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(",") + ")"
|
||||
|
@ -708,13 +710,15 @@ class UsersController < ApplicationController
|
|||
@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" #我的题库
|
||||
courses = @user.courses.where("is_delete = 0")
|
||||
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 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 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 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)
|
||||
|
@ -882,7 +886,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
|
||||
|
@ -898,7 +906,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]
|
||||
|
@ -2863,6 +2875,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
|
||||
|
@ -2977,6 +2993,96 @@ class UsersController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def user_courselist
|
||||
@order, @c_sort,@type = params[:order] || 1, params[:sort] || 1, params[:type] || 1
|
||||
|
||||
#确定 sort_type
|
||||
if @order.to_i == @type.to_i
|
||||
@c_sort = @c_sort.to_i == 1 ? 2 : 1 #1升序 2降序
|
||||
else
|
||||
@c_sort = 2
|
||||
end
|
||||
|
||||
sort_name = "updated_on"
|
||||
sort_type = @c_sort == 1 ? "asc" : "desc"
|
||||
|
||||
# @courses = @user.courses.visible.where("is_delete =?", 0).order("#{sort_name} #{sort_type}")
|
||||
@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 #{sort_name}").order("#{sort_name} #{sort_type}")
|
||||
|
||||
#根据 作业+资源数排序
|
||||
if @order.to_i == 2
|
||||
@type = 2
|
||||
@courses.each do |course|
|
||||
course[:infocount] = (User.current.admin? || User.current.allowed_to?(:as_teacher,course)) ? (course.homework_commons.count + visable_attachemnts_incourse(course).count) : (course.homework_commons.where("publish_time <= '#{Date.today}'").count + visable_attachemnts_incourse(course).count)
|
||||
if course[:infocount] < 0
|
||||
course[:infocount] = 0
|
||||
end
|
||||
end
|
||||
@c_sort == 1 ? (@courses = @courses.sort{|x,y| x[:infocount] <=> y[:infocount] }) : (@courses = @courses.sort{|x,y| y[:infocount] <=> x[:infocount]})
|
||||
@courses = sortby_time_countcommon_nosticky @courses,sort_name
|
||||
else
|
||||
@type = 1
|
||||
end
|
||||
|
||||
#分页
|
||||
@limit = 10
|
||||
@is_remote = true
|
||||
@atta_count = @courses.count
|
||||
@atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1
|
||||
@offset ||= @atta_pages.offset
|
||||
@courses = paginateHelper @courses,@limit
|
||||
|
||||
respond_to do |format|
|
||||
format.js
|
||||
format.html {render :layout => 'new_base_user'}
|
||||
end
|
||||
end
|
||||
|
||||
def user_projectlist
|
||||
@order, @c_sort,@type = params[:order] || 1, params[:sort] || 1, params[:type] || 1
|
||||
|
||||
#确定 sort_type
|
||||
if @order.to_i == @type.to_i
|
||||
@c_sort = @c_sort.to_i == 1 ? 2 : 1 #1升序 2降序
|
||||
else
|
||||
@c_sort = 2
|
||||
end
|
||||
|
||||
sort_name = "updated_at"
|
||||
sort_type = @c_sort == 1 ? "asc" : "desc"
|
||||
|
||||
#@projects = @user.projects.visible.order("#{sort_name} #{sort_type}")
|
||||
@projects = @user.projects.visible.select("projects.*,(SELECT MAX(updated_at) FROM `forge_activities` WHERE forge_activities.project_id = projects.id) AS #{sort_name} ").order("#{sort_name} #{sort_type}")
|
||||
|
||||
#根据 问题+资源数排序 @project.project_score.issue_num @project.project_score.attach_num
|
||||
if @order.to_i == 2
|
||||
@type = 2
|
||||
@projects.each do |project|
|
||||
project[:infocount] = project.project_score.issue_num+project.project_score.attach_num
|
||||
if project[:infocount] < 0
|
||||
project[:infocount] = 0
|
||||
end
|
||||
end
|
||||
@c_sort == 1 ? (@projects = @projects.sort{|x,y| x[:infocount] <=> y[:infocount] }) : (@projects = @projects.sort{|x,y| y[:infocount] <=> x[:infocount] })
|
||||
@projects = sortby_time_countcommon_nosticky @projects,sort_name
|
||||
else
|
||||
@type = 1
|
||||
end
|
||||
|
||||
#分页
|
||||
@limit = 10
|
||||
@is_remote = true
|
||||
@atta_count = @projects.count
|
||||
@atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1
|
||||
@offset ||= @atta_pages.offset
|
||||
@projects = paginateHelper @projects,@limit
|
||||
|
||||
respond_to do |format|
|
||||
format.js
|
||||
format.html {render :layout => 'new_base_user'}
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def find_user
|
||||
|
|
|
@ -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
|
|
@ -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
|
|
@ -37,6 +37,12 @@ module ApplicationHelper
|
|||
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 从硬盘上删除对应的资源文件
|
||||
|
@ -120,60 +126,53 @@ module ApplicationHelper
|
|||
case type
|
||||
when "HomeworkCommon"
|
||||
if course_contributor_score.nil?
|
||||
CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_num => 0, :message_reply_num => 0,
|
||||
:news_reply_num => 0, :resource_num => 0, :journal_num => 0, :journal_reply_num => 0, :homework_journal_num => 1)
|
||||
CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :homework_journal_num => 1)
|
||||
else
|
||||
score = course_contributor_score.homework_journal_num + 1
|
||||
course_contributor_score.update_attributes(:homework_journal_num => score)
|
||||
score = course_contributor_score.homework_journal_num.to_i + 1
|
||||
course_contributor_score.update_column(:homework_journal_num, score)
|
||||
end
|
||||
# 课程留言
|
||||
when "Course"
|
||||
if course_contributor_score.nil?
|
||||
CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_num => 0, :message_reply_num => 0,
|
||||
:news_reply_num => 0, :resource_num => 0, :journal_num => 1, :journal_reply_num => 0)
|
||||
CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :journal_num => 1)
|
||||
else
|
||||
score = course_contributor_score.journal_num + 1
|
||||
course_contributor_score.update_attributes(:journal_num => score)
|
||||
score = course_contributor_score.journal_num.to_i + 1
|
||||
course_contributor_score.update_column(:journal_num, score)
|
||||
end
|
||||
when "Message"
|
||||
if course_contributor_score.nil?
|
||||
CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_num => 1, :message_reply_num => 0,
|
||||
:news_reply_num => 0, :resource_num => 0, :journal_num => 0, :journal_reply_num => 0)
|
||||
CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_num => 1)
|
||||
else
|
||||
score = course_contributor_score.message_num + 1
|
||||
course_contributor_score.update_attributes(:message_num => score)
|
||||
score = course_contributor_score.message_num.to_i + 1
|
||||
course_contributor_score.update_column(:message_num, score)
|
||||
end
|
||||
when "MessageReply"
|
||||
if course_contributor_score.nil?
|
||||
CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_num => 0, :message_reply_num => 1,
|
||||
:news_reply_num => 0, :resource_num => 0, :journal_num => 0, :journal_reply_num => 0)
|
||||
CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_reply_num => 1)
|
||||
else
|
||||
score = course_contributor_score.message_reply_num + 1
|
||||
course_contributor_score.update_attributes(:message_reply_num => score)
|
||||
score = course_contributor_score.message_reply_num.to_i + 1
|
||||
course_contributor_score.update_column(:message_reply_num, score)
|
||||
end
|
||||
when "NewReply"
|
||||
if course_contributor_score.nil?
|
||||
CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_num => 0, :message_reply_num => 0,
|
||||
:news_reply_num => 1, :resource_num => 0, :journal_num => 0, :journal_reply_num => 0)
|
||||
CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :news_reply_num => 1)
|
||||
else
|
||||
score = course_contributor_score.news_reply_num + 1
|
||||
course_contributor_score.update_attributes(:news_reply_num => score)
|
||||
score = course_contributor_score.news_reply_num.to_i + 1
|
||||
course_contributor_score.update_column(:news_reply_num, score)
|
||||
end
|
||||
when "News"
|
||||
if course_contributor_score.nil?
|
||||
CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_num => 0, :message_reply_num => 0,
|
||||
:news_reply_num => 0, :news_num => 1, :resource_num => 0, :journal_num => 0, :journal_reply_num => 0)
|
||||
CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :news_num => 1)
|
||||
else
|
||||
score = course_contributor_score.news_num + 1
|
||||
course_contributor_score.update_attributes(:news_num => score)
|
||||
score = course_contributor_score.news_num.to_i + 1
|
||||
course_contributor_score.update_column(:news_num, score)
|
||||
end
|
||||
when "Attachment"
|
||||
if course_contributor_score.nil?
|
||||
CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_num => 0, :message_reply_num => 0,
|
||||
:news_reply_num => 0, :news_num => 0, :resource_num => 1, :journal_num => 0, :journal_reply_num => 0)
|
||||
CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :resource_num => 1)
|
||||
else
|
||||
score = course_contributor_score.resource_num + 1
|
||||
course_contributor_score.update_attributes(:resource_num => score)
|
||||
score = course_contributor_score.resource_num.to_i + 1
|
||||
course_contributor_score.update_column(:resource_num, score)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -184,39 +183,39 @@ module ApplicationHelper
|
|||
case type
|
||||
when "HomeworkCommon"
|
||||
unless course_contributor_score.nil?
|
||||
score = course_contributor_score.homework_journal_num - 1
|
||||
course_contributor_score.update_attribute(:homework_journal_num, score < 0 ? 0 : score)
|
||||
score = course_contributor_score.homework_journal_num.to_i - 1
|
||||
course_contributor_score.update_column(:homework_journal_num, score < 0 ? 0 : score)
|
||||
end
|
||||
# 课程留言
|
||||
when "Course"
|
||||
unless course_contributor_score.nil?
|
||||
score = course_contributor_score.journal_num - 1
|
||||
course_contributor_score.update_attribute(:journal_num, score < 0 ? 0 : score)
|
||||
score = course_contributor_score.journal_num.to_i - 1
|
||||
course_contributor_score.update_column(:journal_num, score < 0 ? 0 : score)
|
||||
end
|
||||
when "Message"
|
||||
unless course_contributor_score.nil?
|
||||
score = course_contributor_score.message_num - 1
|
||||
course_contributor_score.update_attribute(:message_num, score < 0 ? 0 : score)
|
||||
score = course_contributor_score.message_num.to_i - 1
|
||||
course_contributor_score.update_column(:message_num, score < 0 ? 0 : score)
|
||||
end
|
||||
when "MessageReply"
|
||||
unless course_contributor_score.nil?
|
||||
score = course_contributor_score.message_reply_num - 1
|
||||
course_contributor_score.update_attribute(:message_reply_num, score < 0 ? 0 : score)
|
||||
score = course_contributor_score.message_reply_num.to_i - 1
|
||||
course_contributor_score.update_column(:message_reply_num, score < 0 ? 0 : score)
|
||||
end
|
||||
when "NewReply"
|
||||
unless course_contributor_score.nil?
|
||||
score = course_contributor_score.news_reply_num - 1
|
||||
course_contributor_score.update_attribute(:news_reply_num, score < 0 ? 0 : score)
|
||||
score = course_contributor_score.news_reply_num.to_i - 1
|
||||
course_contributor_score.update_column(:news_reply_num, score < 0 ? 0 : score)
|
||||
end
|
||||
when "News"
|
||||
unless course_contributor_score.nil?
|
||||
score = course_contributor_score.news_num - 1
|
||||
course_contributor_score.update_attribute(:news_num, score < 0 ? 0 : score)
|
||||
score = course_contributor_score.news_num.to_i - 1
|
||||
course_contributor_score.update_column(:news_num, score < 0 ? 0 : score)
|
||||
end
|
||||
when "Attachment"
|
||||
unless course_contributor_score.nil?
|
||||
score = course_contributor_score.resource_num - 1
|
||||
course_contributor_score.update_attribute(:resource_num, score < 0 ? 0 : score)
|
||||
score = course_contributor_score.resource_num.to_i - 1
|
||||
course_contributor_score.update_column(:resource_num, score < 0 ? 0 : score)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -3090,3 +3089,147 @@ def get_reply_parents parents_rely, comment
|
|||
parents_rely
|
||||
end
|
||||
|
||||
#将有置顶属性的提到数组前面
|
||||
def sort_by_sticky topics
|
||||
tmpTopics = []
|
||||
tmpIndex = 0
|
||||
topics.each do |topic|
|
||||
if topic.sticky == 1
|
||||
tmpTopics[tmpIndex] = topic
|
||||
tmpIndex = tmpIndex + 1
|
||||
end
|
||||
end
|
||||
|
||||
topics.each do |topic|
|
||||
if topic.sticky == 0
|
||||
tmpTopics[tmpIndex] = topic
|
||||
tmpIndex = tmpIndex + 1
|
||||
end
|
||||
end
|
||||
return tmpTopics
|
||||
end
|
||||
|
||||
#按人气排序的时候 相同的人气必须按某种时间顺序排序 有置顶属性
|
||||
def sortby_time_countcommon_hassticky topics,sortstr
|
||||
tmpTopics = []
|
||||
tmpTopics = topics
|
||||
tStart = -1
|
||||
tEnd = -1
|
||||
|
||||
tmpTopics_1 = []
|
||||
tmpIndex = 0
|
||||
|
||||
tmpTopics.each_with_index do |topic,index|
|
||||
if topic.sticky == 0
|
||||
if tStart == -1
|
||||
if (index != tmpTopics.count-1) && (topic[:infocount] == tmpTopics[index+1][:infocount])
|
||||
tStart = index
|
||||
end
|
||||
else
|
||||
if ((topic[:infocount] == tmpTopics[index-1][:infocount]) && ((index != tmpTopics.count-1) && (topic[:infocount] == tmpTopics[index+1][:infocount])))
|
||||
tEnd = index
|
||||
else
|
||||
if (topic[:infocount] == tmpTopics[index-1][:infocount])
|
||||
tEnd = index
|
||||
end
|
||||
if tEnd > tStart
|
||||
for i in tStart..tEnd
|
||||
tmpTopics_1[tmpIndex] = tmpTopics[i]
|
||||
tmpIndex = tmpIndex + 1
|
||||
end
|
||||
|
||||
if sortstr == "created_at"
|
||||
tmpTopics_1 = tmpTopics_1.sort{|x,y| y[:created_at].to_i <=> x[:created_at].to_i }
|
||||
elsif sortstr == "created_on"
|
||||
tmpTopics_1 = tmpTopics_1.sort{|x,y| y[:created_on].to_i <=> x[:created_on].to_i }
|
||||
elsif sortstr == "updated_at"
|
||||
tmpTopics_1 = tmpTopics_1.sort{|x,y| y[:updated_at].to_i <=> x[:updated_at].to_i }
|
||||
elsif sortstr == "updated_on"
|
||||
tmpTopics_1 = tmpTopics_1.sort{|x,y| y[:updated_on].to_i <=> x[:updated_on].to_i }
|
||||
end
|
||||
|
||||
tmpIndex = 0
|
||||
for i in tStart..tEnd
|
||||
tmpTopics[i] = tmpTopics_1[tmpIndex]
|
||||
tmpIndex = tmpIndex + 1
|
||||
end
|
||||
end
|
||||
tStart = -1
|
||||
tEnd = -1
|
||||
tmpTopics_1 = []
|
||||
tmpIndex = 0
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return tmpTopics
|
||||
end
|
||||
|
||||
#按人气排序的时候 相同的人气必须按某种时间顺序排序 无置顶属性
|
||||
def sortby_time_countcommon_nosticky topics,sortstr
|
||||
tmpTopics = []
|
||||
tmpTopics = topics
|
||||
tStart = -1
|
||||
tEnd = -1
|
||||
|
||||
tmpTopics_1 = []
|
||||
tmpIndex = 0
|
||||
|
||||
tmpTopics.each_with_index do |topic,index|
|
||||
if tStart == -1
|
||||
if (index != tmpTopics.count-1) && (topic[:infocount] == tmpTopics[index+1][:infocount])
|
||||
tStart = index
|
||||
end
|
||||
else
|
||||
if ((topic[:infocount] == tmpTopics[index-1][:infocount]) && ((index != tmpTopics.count-1) && (topic[:infocount] == tmpTopics[index+1][:infocount])))
|
||||
tEnd = index
|
||||
else
|
||||
if (topic[:infocount] == tmpTopics[index-1][:infocount])
|
||||
tEnd = index
|
||||
end
|
||||
if tEnd > tStart
|
||||
for i in tStart..tEnd
|
||||
tmpTopics_1[tmpIndex] = tmpTopics[i]
|
||||
tmpIndex = tmpIndex + 1
|
||||
end
|
||||
|
||||
if sortstr == "created_at"
|
||||
tmpTopics_1 = tmpTopics_1.sort{|x,y| y[:created_at].to_i <=> x[:created_at].to_i }
|
||||
elsif sortstr == "created_on"
|
||||
tmpTopics_1 = tmpTopics_1.sort{|x,y| y[:created_on].to_i <=> x[:created_on].to_i }
|
||||
elsif sortstr == "updated_at"
|
||||
tmpTopics_1 = tmpTopics_1.sort{|x,y| y[:updated_at].to_i <=> x[:updated_at].to_i }
|
||||
elsif sortstr == "updated_on"
|
||||
tmpTopics_1 = tmpTopics_1.sort{|x,y| y[:updated_on].to_i <=> x[:updated_on].to_i }
|
||||
end
|
||||
|
||||
tmpIndex = 0
|
||||
for i in tStart..tEnd
|
||||
tmpTopics[i] = tmpTopics_1[tmpIndex]
|
||||
tmpIndex = tmpIndex + 1
|
||||
end
|
||||
end
|
||||
tStart = -1
|
||||
tEnd = -1
|
||||
tmpTopics_1 = []
|
||||
tmpIndex = 0
|
||||
end
|
||||
end
|
||||
end
|
||||
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
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
module IssuesHelper
|
||||
include ApplicationHelper
|
||||
|
||||
include TagsHelper
|
||||
def issue_list(issues, &block)
|
||||
ancestors = []
|
||||
issues.each do |issue|
|
||||
|
|
|
@ -63,14 +63,89 @@ 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
|
||||
|
||||
end
|
||||
|
|
|
@ -41,6 +41,23 @@ module RepositoriesHelper
|
|||
identifiers.include?(iden) ? false :true
|
||||
end
|
||||
|
||||
# 获取文件目录的最新动态
|
||||
def get_trees_last_changes(project_id, rev, ent_name)
|
||||
g = Gitlab.client
|
||||
begin
|
||||
tree_changes = g.rep_last_changes(project_id, :rev => rev, :path => ent_name)
|
||||
tree_changes
|
||||
rescue
|
||||
logger.error("faile to get tress activities!")
|
||||
end
|
||||
end
|
||||
|
||||
def translate_time time
|
||||
case time
|
||||
when time.include("")
|
||||
end
|
||||
end
|
||||
|
||||
# 获取diff内容行号
|
||||
def diff_line_num content
|
||||
content.scan(/@@ -(\d+),\d+ \+\d+,\d+ @@/).first.join("").to_i
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
module ShieldWechatMessagesHelper
|
||||
end
|
|
@ -0,0 +1,2 @@
|
|||
module SubDocumentCommentsHelper
|
||||
end
|
|
@ -0,0 +1,5 @@
|
|||
module SubDomainsHelper
|
||||
include OrganizationsHelper
|
||||
|
||||
|
||||
end
|
|
@ -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
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
class CodeTests < ActiveRecord::Base
|
||||
attr_accessible :homework_id, :language, :status, :time_used, :wait_time, :student_work_id
|
||||
end
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
# 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
|
||||
|
||||
|
@ -27,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
|
||||
|
||||
|
@ -57,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
|
||||
|
@ -99,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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,29 @@ 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'
|
||||
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 +287,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 +313,4 @@ class JournalsForMessage < ActiveRecord::Base
|
|||
down_course_score_num(self.jour.course_id, self.user_id, "HomeworkCommon")
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -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.
|
||||
|
@ -1102,5 +1104,4 @@ class Mailer < ActionMailer::Base
|
|||
1.upto(len) { |i| newpass << chars[rand(chars.size-1)] }
|
||||
return newpass
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -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
|
||||
|
@ -77,12 +80,10 @@ class Message < ActiveRecord::Base
|
|||
validates_length_of :subject, :maximum => 255
|
||||
validate :cannot_reply_to_locked_topic, :on => :create
|
||||
|
||||
after_create :add_author_as_watcher, :reset_counters!, :add_boards_count
|
||||
# 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_activity,:act_as_course_activity,:be_user_score,:act_as_forge_activity,
|
||||
:act_as_system_message, :send_mail, :act_as_student_score, act_as_at_message(:content, :author_id)
|
||||
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|
|
||||
|
@ -134,11 +135,11 @@ class Message < ActiveRecord::Base
|
|||
if self.project && !project.project_score.nil?
|
||||
# 讨论区
|
||||
if self.parent_id.nil?
|
||||
count = self.project.project_score.board_num + 1
|
||||
self.project.project_score.update_attribute(:board_num, count)
|
||||
count = self.project.project_score.board_num.to_i + 1
|
||||
self.project.project_score.update_column(:board_num, count)
|
||||
else # 回复
|
||||
count = self.project.project_score.board_message_num + 1
|
||||
self.project.project_score.update_attribute(:board_message_num, count)
|
||||
count = self.project.project_score.board_message_num.to_i + 1
|
||||
self.project.project_score.update_column(:board_message_num, count)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -257,31 +258,50 @@ class Message < ActiveRecord::Base
|
|||
# 主贴项目成员都能收到
|
||||
# 回帖:帖子的发布人收到
|
||||
def act_as_system_message
|
||||
ws = WechatService.new
|
||||
if self.course
|
||||
if self.parent_id.nil? # 主贴
|
||||
self.course.members.each do |m|
|
||||
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.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
|
||||
elsif self.project # 项目相关
|
||||
if self.parent_id.nil? # 主贴
|
||||
self.project.members.each do |m|
|
||||
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.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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -22,4 +22,8 @@ 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
|
||||
end
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -115,6 +115,7 @@ class Project < ActiveRecord::Base
|
|||
|
||||
has_many :org_projects,:dependent => :destroy
|
||||
has_many :organization,:through => :org_projects
|
||||
has_many :rep_statics, :class_name => 'RepStatics'
|
||||
|
||||
# has_many :journals
|
||||
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
class RepStatics < ActiveRecord::Base
|
||||
belongs_to :project
|
||||
attr_accessible :add, :commits_num, :del, :email, :project_id, :uname, :changeset
|
||||
end
|
|
@ -44,7 +44,7 @@ class Repository < ActiveRecord::Base
|
|||
# validates_uniqueness_of :identifier, :allow_blank => true
|
||||
validates_exclusion_of :identifier, :in => %w(show entry raw changes annotate diff show stats graph)
|
||||
# donwcase letters, digits, dashes, underscores but not digits only
|
||||
validates_format_of :identifier, :with => /^[a-z0-9_\-]+$/, :allow_blank => true
|
||||
validates_format_of :identifier, :with => /^[a-zA-Z0-9_\-]*[a-zA-Z_\-]+[a-zA-Z0-9_\-]*$/, :allow_blank => true
|
||||
# Checks if the SCM is enabled when creating a repository
|
||||
validate :repo_create_validation, :on => :create
|
||||
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
class ShieldWechatMessage < ActiveRecord::Base
|
||||
attr_accessible :container_id, :container_type, :shield_id, :shield_type
|
||||
end
|
|
@ -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
|
|
@ -1,6 +1,6 @@
|
|||
#学生提交作品表
|
||||
class StudentWork < ActiveRecord::Base
|
||||
attr_accessible :name, :description, :homework_common_id, :user_id, :final_score, :teacher_score, :student_score, :teaching_asistant_score, :project_id, :is_test
|
||||
attr_accessible :name, :description, :homework_common_id, :user_id, :final_score, :teacher_score, :student_score, :teaching_asistant_score, :project_id, :is_test, :simi_id, :simi_value
|
||||
|
||||
belongs_to :homework_common
|
||||
belongs_to :user
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# encoding: utf-8
|
||||
class StudentWorkTest < ActiveRecord::Base
|
||||
attr_accessible :student_work_id, :results, :status, :src
|
||||
attr_accessible :student_work_id, :results, :status, :src, :uwait_time
|
||||
belongs_to :student_work
|
||||
|
||||
serialize :results, Array
|
||||
|
|
|
@ -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
|
|
@ -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
|
|
@ -180,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
|
||||
|
@ -1182,17 +1185,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
|
||||
|
||||
|
|
|
@ -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
|
|
@ -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
|
|
@ -0,0 +1,99 @@
|
|||
<h3>
|
||||
<%=l(:label_code_work_tests)%>
|
||||
</h3>
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="autoscroll">
|
||||
<table class="list" style="width: 100%;table-layout: fixed">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="width: 50px;">
|
||||
<span style="float:left; margin-left:20px;">作业id</span>
|
||||
</th>
|
||||
<th style="width: 50px;">
|
||||
<span style="float:left; margin-left:20px;">作品id</span>
|
||||
</th>
|
||||
<th style="width: 60px;">
|
||||
用户等待时间
|
||||
</th>
|
||||
<th style="width: 50px;">
|
||||
<span style="float:left; margin-left:20px;">语言</span>
|
||||
</th>
|
||||
<th style="width: 100px;">
|
||||
测试完成时间
|
||||
</th>
|
||||
<th style="width: 60px;">
|
||||
<span style="float:left; margin-left:20px;">答题状态</span>
|
||||
</th>
|
||||
<th style="width: 50px;">
|
||||
<span style="float:left; margin-left:20px;">耗时</span>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% @code_work_tests.each do |test| %>
|
||||
<% if test['homework_id'] != nil %>
|
||||
<tr class="<%= cycle("odd", "even") %>">
|
||||
<td style="text-align: center; " title='<%=test['homework_id']%>'>
|
||||
<% if test['link_hwork'] %>
|
||||
<%=link_to(test['homework_id'], student_work_index_path(:homework => test['homework_id']))%>
|
||||
<% else %>
|
||||
<%= test['homework_id'] %>
|
||||
<% end %>
|
||||
</td>
|
||||
<td style="text-align: center; " title='<%=test['student_work_id']%>'>
|
||||
<% if test['link_swork'] && test['link_hwork'] %>
|
||||
<% if !test['is_test'] %>
|
||||
<%=link_to(test['student_work_id'], student_work_index_path(:homework => test['homework_id'],:student_work_id=>test['student_work_id']))%>
|
||||
<% else %>
|
||||
<%=link_to(test['student_work_id'], new_user_commit_homework_users_path(homework_id: test['homework_id'], is_test: true))%>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<%= test['student_work_id'] %>
|
||||
<% end %>
|
||||
</td>
|
||||
<td style="text-align: center;">
|
||||
<% if test.wait_time != 0 %>
|
||||
<%=test.wait_time.to_s+"毫秒" %>
|
||||
<% else %>
|
||||
<%="未记录"%>
|
||||
<% end %>
|
||||
</td>
|
||||
<td align="center">
|
||||
<%=%W(C C++ Python Java).at(test['language'].to_i - 1)%>
|
||||
</td>
|
||||
<td align="center">
|
||||
<%=Time.parse(test.created_at.to_s).strftime("%Y-%m-%d %H:%M:%S")%>
|
||||
</td>
|
||||
<td align="center">
|
||||
<% if test.status == 0 %>
|
||||
<%= "答题正确" %>
|
||||
<% elsif test.status == -2 %>
|
||||
<%= "编译错误" %>
|
||||
<% elsif test.status == 2 %>
|
||||
<%= "代码超时" %>
|
||||
<% elsif test.status == -3 %>
|
||||
<%= "请求超时" %>
|
||||
<% else %>
|
||||
<%= "答题错误" %>
|
||||
<% end %>
|
||||
</td>
|
||||
<td class="center">
|
||||
<% if test.time_used > 0 %>
|
||||
<%=test.time_used.to_s+"毫秒"%>
|
||||
<% end %>
|
||||
</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_code_work_tests)) -%>
|
|
@ -1,226 +1,82 @@
|
|||
<div class="resources mt10" id="user_activity_<%= user_activity_id%>" >
|
||||
<div class="homepagePostBrief" onmouseover="$('#message_setting_<%=activity.id%>').show();" onmouseout="$('#message_setting_<%= activity.id%>').hide();">
|
||||
<div class="homepagePostPortrait">
|
||||
<%= link_to image_tag(url_to_avatar(activity.author), :width => "50", :height => "50"), user_path(activity.author_id,:host=>Setting.host_user), :alt => "用户头像" %>
|
||||
</div>
|
||||
<div class="homepagePostDes">
|
||||
<% if activity.author.id == User.current.id || User.current.admin? %>
|
||||
<div class="homepagePostSetting" id="message_setting_<%= activity.id%>" style="display: none">
|
||||
<ul>
|
||||
<li class="homepagePostSettingIcon">
|
||||
<ul class="homepagePostSettiongText">
|
||||
<li>
|
||||
<%= link_to(
|
||||
l(:button_edit),
|
||||
{:controller => 'blog_comments',:action => 'edit',:user_id=>activity.author_id,:blog_id=>activity.blog_id, :id => activity.id},
|
||||
:class => 'postOptionLink'
|
||||
) if User.current.admin? || User.current.id == activity.author.id %>
|
||||
</li>
|
||||
<li>
|
||||
<%= link_to(
|
||||
l(:button_delete),
|
||||
{:controller => 'blog_comments',:action => 'destroy',:user_id=>activity.author_id,:blog_id=>activity.blog_id, :id => activity.id},
|
||||
:method => :delete,
|
||||
:data => {:confirm => l(:text_are_you_sure)},
|
||||
:class => 'postOptionLink'
|
||||
) if User.current.admin? || User.current.id == activity.author.id %>
|
||||
</li>
|
||||
<li>
|
||||
<% if activity.id == activity.blog.homepage_id %>
|
||||
<%= link_to(
|
||||
l(:button_cancel_homepage),
|
||||
{:controller => 'blogs',:action => 'cancel_homepage',:user_id=>activity.author_id,:id=>activity.blog_id, :article_id => activity.id},
|
||||
:method => :post,
|
||||
:class => 'postOptionLink'
|
||||
) if User.current && User.current.id == activity.blog.author_id %>
|
||||
<% else %>
|
||||
<%= link_to(
|
||||
l(:button_set_homepage),
|
||||
{:controller => 'blogs',:action => 'set_homepage',:user_id=>activity.author_id,:id=>activity.blog_id, :article_id => activity.id},
|
||||
:method => :post,
|
||||
:class => 'postOptionLink'
|
||||
) if User.current && User.current.id == activity.blog.author_id %>
|
||||
<% end %>
|
||||
</li>
|
||||
</ul>
|
||||
<div class = "cl"> </div>
|
||||
<div id="blog-list">
|
||||
<div class="listbox mt10" >
|
||||
<h2 class="list-h2">博客列表</h2>
|
||||
<div class="category">
|
||||
<span class="grayTxt ">排序:</span>
|
||||
<%= link_to "时间", {:controller => 'blogs', :action => 'index', :id =>@user, :type => @type, :sort => @b_sort, :order => 1 }, :class => "sortTxt", :remote => true %>
|
||||
<% if @type.to_i == 1 %>
|
||||
<%= link_to "", {:controller => 'blogs', :action => 'index', :id =>@user, :type => @type, :sort => @b_sort, :order => 1 }, :class => "#{@b_sort.to_i == 1 ? 'sortupbtn' : 'sortdownbtn'} ", :remote => true %>
|
||||
<% end %>
|
||||
<%= link_to "人气", {:controller => 'blogs', :action => 'index', :id =>@user, :type => @type, :sort => @b_sort, :order => 2 }, :class => "sortTxt", :remote => true %>
|
||||
<% if @type.to_i == 2 %>
|
||||
<%= link_to "", {:controller => 'blogs', :action => 'index', :id =>@user, :type => @type, :sort => @b_sort, :order => 2 }, :class => "#{@b_sort.to_i == 1 ? 'sortupbtn' : 'sortdownbtn'} ", :remote => true %>
|
||||
<% end %>
|
||||
|
||||
<div class="cl"></div>
|
||||
</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="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>
|
||||
</ul>
|
||||
</div>
|
||||
<%end%>
|
||||
<div class="homepagePostTo mt-4 fl">
|
||||
<% if activity.try(:author).try(:realname) == ' ' %>
|
||||
<%= link_to activity.try(:author), user_path(activity.author_id,:host=>Setting.host_user), :class => "newsBlue mr15" %>
|
||||
<% else %>
|
||||
<%= link_to activity.try(:author).try(:realname), user_path(activity.author_id,:host=>Setting.host_user), :class => "newsBlue mr15" %>
|
||||
<% end %>
|
||||
TO
|
||||
<%= link_to activity.blog.name+" | 博客", user_blogs_path(:user_id=>activity.author_id,:host=>Setting.host_user), :class => "newsBlue ml15 mr5"%>
|
||||
<% if activity.blog.homepage_id and activity.id == activity.blog.homepage_id %>
|
||||
<span class="red_homework_btn_cir ml5">已设为首页</span>
|
||||
<% end %>
|
||||
</div>
|
||||
<div class="cl"></div>
|
||||
<div class="homepagePostTitle hidden m_w530 fl">
|
||||
<% 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=> "postGrey" %>
|
||||
<% 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=> "postGrey"%>
|
||||
<% end %>
|
||||
</div>
|
||||
<% if activity.sticky == 1%>
|
||||
<span class="sticky_btn_cir ml10">置顶</span>
|
||||
<% end%>
|
||||
<% if activity.locked%>
|
||||
<span class="locked_btn_cir ml10 fl" title="已锁定"> </span>
|
||||
<% end%>
|
||||
<div class="cl"></div>
|
||||
<div class="homepagePostDate fl">
|
||||
发帖时间:<%= format_time(activity.created_on) %>
|
||||
</div>
|
||||
<div class="homepagePostDate fl ml15">
|
||||
更新时间:<%= format_time(activity.updated_on) %>
|
||||
</div>
|
||||
<div class="cl"></div>
|
||||
<% if activity.parent_id.nil? %>
|
||||
<% content= activity.content%>
|
||||
<% else %>
|
||||
<% content= activity.parent.content%>
|
||||
<% end %>
|
||||
<%=render :partial =>"users/intro_content", :locals=>{:user_activity_id =>user_activity_id, :content=>content} %>
|
||||
|
||||
<div class="cl"></div>
|
||||
<!--<div class=" fl" style="width: 600px">
|
||||
<%# if activity.attachments.any?%>
|
||||
<%# options = {:author => true, :deletable => false } %>
|
||||
<%#= render :partial => 'blog_comments/attachments_links', :locals => {:attachments => activity.attachments, :options => options, :is_float => true} %>
|
||||
<%# end %>
|
||||
</div>
|
||||
<div class="cl"></div>-->
|
||||
<div id="intro_content_show_<%= user_activity_id%>" class="fr" style="display:none;"><a href="javascript:void(0);" class="linkBlue">[展开]</a></div>
|
||||
<div id="intro_content_hide_<%= user_activity_id%>" class="fr" style="display:none;"><a href="javascript:void(0);" class="linkBlue">[收起]</a></div>
|
||||
<div class="cl"></div>
|
||||
<div class="mt10" style="font-weight:normal;">
|
||||
<%= render :partial=>"attachments/activity_attach", :locals=>{:activity => activity} %>
|
||||
</div>
|
||||
<div class="homepagePostSetting" id="act-<%= user_activity_id %>" style="visibility: hidden">
|
||||
<ul>
|
||||
<li class="homepagePostSettingIcon">
|
||||
<ul class="homepagePostSettiongText">
|
||||
<li><a href="javascript:void(0);" class="postOptionLink">编辑</a></li>
|
||||
<li><a href="javascript:void(0);" class="postOptionLink">复制</a></li>
|
||||
<li><a href="javascript:void(0);" class="postOptionLink">删除</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div class="cl"></div>
|
||||
</div>
|
||||
<% count=0 %>
|
||||
<% if activity.parent %>
|
||||
<% count=activity.parent.children.count%>
|
||||
<% else %>
|
||||
<% count=activity.children.count%>
|
||||
<% end %>
|
||||
<div class="homepagePostReply">
|
||||
<div class="homepagePostReplyBanner">
|
||||
<div class="homepagePostReplyBannerCount">回复
|
||||
<sapn class="mr15"><%= count>0 ? "(#{count})" : "" %></sapn><span style="color: #cecece;">▪</span>
|
||||
<span id="praise_count_<%=user_activity_id %>">
|
||||
<% if activity.author == User.current %>
|
||||
<span class="ml15 likeButton" title="不能自己赞自己哦!"> <span class="likeText">赞</span><span class="likeNum"><%= get_praise_num(activity) > 0 ? "(#{get_praise_num(activity)})" : "" %></span></span>
|
||||
<% else %>
|
||||
<%=render :partial=> "praise_tread/praise", :locals => {:activity=>activity, :user_activity_id=>user_activity_id,:type=>"activity"}%>
|
||||
<% end %>
|
||||
</span>
|
||||
</div>
|
||||
<div class="homepagePostReplyBannerTime"><%#=format_date(activity.updated_on)%></div>
|
||||
<%if count > 3 %>
|
||||
<div class="homepagePostReplyBannerMore">
|
||||
<a id="reply_btn_<%=user_activity_id%>" onclick="expand_reply('#reply_div_<%= user_activity_id %> li','#reply_btn_<%=user_activity_id%>')" data-count="<%= count %>" data-init="0" class=" replyGrey" href="javascript:void(0)" value="show_help" >
|
||||
展开更多
|
||||
</a>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<% activity= activity.parent ? activity.parent : activity%>
|
||||
<% replies_all_i = 0 %>
|
||||
<% if count > 0 %>
|
||||
<div class="" id="reply_div_<%= user_activity_id %>">
|
||||
<ul>
|
||||
<% activity.children.reorder("created_on desc").each do |reply|%>
|
||||
<script type="text/javascript">
|
||||
$(function(){
|
||||
showNormalImage('reply_content_<%= reply.id %>');
|
||||
});
|
||||
</script>
|
||||
<% replies_all_i=replies_all_i+1 %>
|
||||
<li class="homepagePostReplyContainer" nhname="reply_rec" style="display:<%= replies_all_i>3 ? 'none' : '' %>">
|
||||
<div class="homepagePostReplyPortrait">
|
||||
<%= link_to image_tag(url_to_avatar(reply.author), :width => "33", :height => "33"), user_path(reply.author_id,:host=>Setting.host_user), :alt => "用户头像" %>
|
||||
</div>
|
||||
<div class="homepagePostReplyDes">
|
||||
<div class="homepagePostReplyPublisher mt-4">
|
||||
<% if reply.try(:author).try(:realname) == ' ' %>
|
||||
<%= link_to reply.try(:author), user_path(reply.author_id,:host=>Setting.host_user), :class => "newsBlue mr10 f14" %>
|
||||
<% else %>
|
||||
<%= link_to reply.try(:author).try(:realname), user_path(reply.author_id,:host=>Setting.host_user), :class => "newsBlue mr10 f14" %>
|
||||
<% end %>
|
||||
<%= format_time(reply.created_on) %>
|
||||
<span id="reply_praise_count_<%=reply.id %>">
|
||||
<% if reply.author == User.current %>
|
||||
<span class="fr likeButton" title="不能自己赞自己哦!"> <span class="likeText">赞</span><span class="likeNum"><%= get_praise_num(reply) > 0 ? "(#{get_praise_num(reply)})" : "" %></span></span>
|
||||
<% else %>
|
||||
<%=render :partial=> "praise_tread/praise", :locals => {:activity=>reply, :user_activity_id=>reply.id,:type=>"reply"}%>
|
||||
<% end %>
|
||||
</span>
|
||||
</div>
|
||||
<div class="homepagePostReplyContent break_word list_style upload_img" id="reply_content_<%= reply.id %>">
|
||||
<%= reply.content.html_safe %>
|
||||
</div>
|
||||
</div>
|
||||
<div class="cl"></div>
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<% if !activity.locked? %>
|
||||
<div class="homepagePostReplyContainer borderBottomNone minHeight48">
|
||||
<div class="homepagePostReplyPortrait mr15 imageFuzzy" id="reply_image_<%= user_activity_id%>"><%= link_to image_tag(url_to_avatar(User.current), :width => "33", :height => "33"), user_path(activity.author_id), :alt => "用户头像" %></div>
|
||||
<div class="homepagePostReplyInputContainer mb10">
|
||||
<div nhname='new_message_<%= user_activity_id%>' style="display:none;">
|
||||
<%= form_for('new_form',:url => {:controller=>'blog_comments',:action => 'reply', :id => activity.id, :blog_id => activity.blog.id, :user_id => activity.author_id},:method => "post",:remote=>true) do |f|%>
|
||||
<input type="hidden" name="quote[quote]" value="">
|
||||
<input type="hidden" name="blog_comment[sticky]" value="0">
|
||||
<input type="hidden" name="blog_comment[locked]" value="0">
|
||||
<input type="hidden" name="blog_comment[title]" value="RE:<%= activity.title%>">
|
||||
<input type="hidden" name="user_activity_id" value="<%=user_activity_id%>">
|
||||
<div nhname='toolbar_container_<%= user_activity_id%>'></div>
|
||||
<textarea placeholder="有问题或有建议,请直接给我留言吧!" style="display: none" nhname='new_message_textarea_<%= user_activity_id%>' name="blog_comment[content]"></textarea>
|
||||
<a id="new_message_submit_btn_<%= user_activity_id%>" href="javascript:void(0)" onclick="this.style.display='none'" class="blue_n_btn fr" style="display:none;margin-top:6px;">发送</a>
|
||||
<div class="cl"></div>
|
||||
<p nhname='contentmsg_<%= user_activity_id%>'></p>
|
||||
<% end%>
|
||||
<div class="cl"></div>
|
||||
</div>
|
||||
<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>
|
||||
<% end %>
|
||||
</div>
|
||||
<% else %>
|
||||
<p class="nodata"><%= l(:label_no_data) %></p>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
$("#moreProject_<%=user_activity_id %>").click(function(){
|
||||
$("#relatePWrap_<%=user_activity_id %>").toggleClass('relatePWrap');
|
||||
$("#relatePWrap_<%=user_activity_id %>").css("height","auto");
|
||||
$(this).hide();
|
||||
//如果右边的博客列表比左边的高度低则将右边的高度设为与左边对齐
|
||||
$(function() {
|
||||
var leftHeight = $("#LSide").height() - $(".fontGrey5").height() - 10;
|
||||
var rightHeight = $(".homepageRight").height();
|
||||
if (rightHeight < leftHeight) {
|
||||
var diffHeight = leftHeight - rightHeight;
|
||||
var tmpHeight = $(".listbox").height() + diffHeight;
|
||||
$(".listbox").css("height", tmpHeight);
|
||||
}
|
||||
});
|
||||
$("#hideProject_<%=user_activity_id %>").click(function(){
|
||||
$("#relatePWrap_<%=user_activity_id %>").toggleClass('relatePWrap');
|
||||
$("#moreProject_<%=user_activity_id %>").show();
|
||||
});
|
||||
</script>
|
||||
</script>
|
|
@ -38,7 +38,7 @@
|
|||
|
||||
<div class="homepageRight mt0">
|
||||
<div class="homepageRightBanner">
|
||||
<div class="NewsBannerName">
|
||||
<div class="f16 fl fontGrey3">
|
||||
<%= @user.name%>的博客
|
||||
</div>
|
||||
</div>
|
||||
|
@ -51,44 +51,9 @@
|
|||
<% end %>
|
||||
|
||||
<% if topics%>
|
||||
<% topics.each do |topic| %>
|
||||
<script>
|
||||
function expand_reply(container, btnid) {
|
||||
var target = $(container);
|
||||
var btn = $(btnid);
|
||||
if (btn.data('init') == '0') {
|
||||
btn.data('init', 1);
|
||||
btn.html('收起回复');
|
||||
target.show();
|
||||
} else {
|
||||
btn.data('init', 0);
|
||||
btn.html('展开更多');
|
||||
target.hide();
|
||||
target.eq(0).show();
|
||||
target.eq(1).show();
|
||||
target.eq(2).show();
|
||||
}
|
||||
}
|
||||
|
||||
function expand_reply_input(id) {
|
||||
$(id).toggle();
|
||||
}
|
||||
|
||||
$(function () {
|
||||
sd_create_editor_from_data(<%= topic.id%>, null, "100%", "<%=topic.class.to_s%>");
|
||||
});
|
||||
</script>
|
||||
<% if topic %>
|
||||
<%= render :partial => 'blogs/article', :locals => {:activity => topic, :user_activity_id => topic.id} %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<%# if topics.count == 10 %>
|
||||
<!--<div id="show_more_course_topic" class="loadMore mt10 f_grey">展开更多<%#= link_to "", boards_topic_path(@board, :course_id => @board.course.id ,:page => page), :id => "more_topic_link", :remote => "true", :class => "none" %></div>-->
|
||||
<%# end %>
|
||||
<%= render :partial => 'blogs/article', :locals => {:topics => topics} %>
|
||||
<% end%>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
$("#show_more_course_topic").mouseover(function () {
|
||||
$("#more_topic_link").click();
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
<%= import_ke(enable_at: false, prettify: false) %>
|
||||
|
||||
|
||||
<%= render :partial => 'blogs/article_list', :locals => {:blog=>@user.blog,:topics => @user.blog.articles.reorder("#{BlogComment.table_name}.sticky desc,#{BlogComment.table_name}.updated_on desc"), :page => 0, :user => @user} %>
|
||||
<%= render :partial => 'blogs/article_list', :locals => {:blog=>@user.blog,:topics => @topics, :page => 0, :user => @user} %>
|
||||
|
||||
|
||||
<script type="text/javascript">//侧导航
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
$("#blog-list").replaceWith('<%= escape_javascript( render :partial => 'blogs/article', :locals => {:topics => @topics} ) %>');
|
|
@ -2,41 +2,7 @@
|
|||
<%= import_ke(enable_at: false, prettify: false) %>
|
||||
<%= javascript_include_tag "create_kindeditor" %>
|
||||
<% end %>
|
||||
<% if topics %>
|
||||
<% topics.each do |topic| %>
|
||||
<script>
|
||||
function expand_reply(container, btnid) {
|
||||
var target = $(container);
|
||||
var btn = $(btnid);
|
||||
if (btn.data('init') == '0') {
|
||||
btn.data('init', 1);
|
||||
btn.html('收起回复');
|
||||
target.show();
|
||||
} else {
|
||||
btn.data('init', 0);
|
||||
btn.html('展开更多');
|
||||
target.hide();
|
||||
target.eq(0).show();
|
||||
target.eq(1).show();
|
||||
target.eq(2).show();
|
||||
}
|
||||
}
|
||||
|
||||
function expand_reply_input(id) {
|
||||
$(id).toggle();
|
||||
}
|
||||
|
||||
$(function () {
|
||||
sd_create_editor_from_data(<%= topic.id%>, null, "100%", "<%=topic.class.to_s%>");
|
||||
});
|
||||
</script>
|
||||
<% if topic %>
|
||||
<%= render :partial => 'users/course_message', :locals => {:activity => topic, :user_activity_id => topic.id, :is_course => 1, :is_board=>1} %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<% if topics.count == 10 %>
|
||||
<%= link_to "点击展开更多",boards_topic_path(@board, :course_id => @board.course.id ,:page => page),:id => "show_more_course_topic",:remote => "true",:class => "loadMore mt10 f_grey"%>
|
||||
<% end %>
|
||||
<% end%>
|
||||
|
||||
<% if @topics || topics %>
|
||||
<%= render :partial => 'users/course_boardlist', :locals => {:topics => @topics ? @topics: topics , :is_course => 1, :is_board=>1} %>
|
||||
<% end %>
|
|
@ -2,60 +2,7 @@
|
|||
<%= import_ke(enable_at: false, prettify: false) %>
|
||||
<%= javascript_include_tag "create_kindeditor" %>
|
||||
<% end %>
|
||||
<style type="text/css">
|
||||
/*回复框*/
|
||||
/*.homepagePostReplyInputContainer .ke-toolbar {display: none; width: 400px; border: none; background: none; padding: 0px 0px;}*/
|
||||
/*.homepagePostReplyInputContainer .ke-toolbar-icon {line-height: 26px; font-size: 14px; padding-left: 26px;}*/
|
||||
/*.homepagePostReplyInputContainer .ke-toolbar-icon-url {background-image: url(/images/public_icon.png)}*/
|
||||
/*.homepagePostReplyInputContainer .ke-outline {padding: 0px 0px; line-height: 26px; font-size: 14px;}*/
|
||||
/*.homepagePostReplyInputContainer .ke-icon-emoticons {background-position: 0px -671px; width: 50px; height: 26px;}*/
|
||||
/*.homepagePostReplyInputContainer .ke-icon-emoticons:hover {background-position: -79px -671px; width: 50px; height: 26px;}*/
|
||||
/*.homepagePostReplyInputContainer .ke-outline {border: none;}*/
|
||||
/*.homepagePostReplyInputContainer .ke-inline-block {display: none;}*/
|
||||
/*.homepagePostReplyInputContainer .ke-container {float: left;}*/
|
||||
</style>
|
||||
<% if topics%>
|
||||
<% topics.each do |topic| %>
|
||||
<script>
|
||||
function expand_reply(container, btnid) {
|
||||
var target = $(container);
|
||||
var btn = $(btnid);
|
||||
if (btn.data('init') == '0') {
|
||||
btn.data('init', 1);
|
||||
btn.html('收起回复');
|
||||
target.show();
|
||||
} else {
|
||||
btn.data('init', 0);
|
||||
btn.html('展开更多');
|
||||
target.hide();
|
||||
target.eq(0).show();
|
||||
target.eq(1).show();
|
||||
target.eq(2).show();
|
||||
}
|
||||
}
|
||||
|
||||
function expand_reply_input(id) {
|
||||
$(id).toggle();
|
||||
}
|
||||
|
||||
$(function () {
|
||||
sd_create_editor_from_data(<%= topic.id%>, null, "100%");
|
||||
});
|
||||
</script>
|
||||
<% if topic %>
|
||||
<%= render :partial => 'users/project_message', :locals => {:activity => topic, :user_activity_id => topic.id,:is_course=>1,:is_board=>1} %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<% if topics.count == 10 %>
|
||||
<!--<div id="show_more_course_topic" class="loadMore mt10 f_grey">展开更多<%#= link_to "", boards_topic_path(@board, :course_id => @board.course.id ,:page => page), :id => "more_topic_link", :remote => "true", :class => "none" %></div>-->
|
||||
<%= link_to "点击展开更多", boards_topic_path(@board, :project_id => @board.project.id ,:page => page), :id => "show_more_project_topic",:remote => "true",:class => "loadMore mt10 f_grey"%>
|
||||
<% end %>
|
||||
<% end%>
|
||||
|
||||
<!--
|
||||
<script type="text/javascript">
|
||||
$("#show_more_course_topic").mouseover(function () {
|
||||
$("#more_topic_link").click();
|
||||
});
|
||||
</script>-->
|
||||
<%if @topics || topics %>
|
||||
<%= render :partial => 'users/project_boardlist', :locals => {:topics => @topics ? @topics: topics , :is_course => 1, :is_board=>1} %>
|
||||
<% end %>
|
|
@ -1,5 +1,5 @@
|
|||
<% if @course %>
|
||||
$("#show_more_course_topic").replaceWith("<%= escape_javascript( render :partial => 'boards/course_show_detail',:locals => {:topics => @topics, :page => @page} )%>");
|
||||
$("#course-boardlist").replaceWith('<%= escape_javascript( render :partial => 'users/course_boardlist', :locals => {:topics => @topics, :is_course => 1, :is_board=>1}) %>');
|
||||
<% else %>
|
||||
$("#show_more_project_topic").replaceWith("<%= escape_javascript( render :partial => 'boards/project_show_detail',:locals => {:topics => @topics, :page => @page} )%>");
|
||||
$("#project-boardlist").replaceWith('<%= escape_javascript( render :partial => 'users/project_boardlist', :locals => {:topics => @topics, :is_course => 1, :is_board=>1}) %>');
|
||||
<% end %>
|
|
@ -0,0 +1,100 @@
|
|||
<div class="blue-border-box">
|
||||
<div class="box-con">
|
||||
<h4 id = "compare-tips-1"></h4>
|
||||
<div class="box-con-a">
|
||||
<a href="javascript:void(0);" class="Blue-btn fl " onclick = "compare_code_btn(<%=homework.id%>,<%=courseid%>)">重新查重</a>
|
||||
<a href="javascript:void(0);" class="Blue-btn fl " onclick = "see_last_compare_code(<%=courseid%>,<%=homework.id%>)">查看结果</a>
|
||||
</div>
|
||||
<div class="cl"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
//请求重新查重
|
||||
function compare_code_btn(homeworkid,courseid)
|
||||
{
|
||||
hideModal($(".blue-border-box"));
|
||||
test_repeat(homeworkid,courseid);
|
||||
|
||||
}
|
||||
//查看结果
|
||||
function see_last_compare_code(courseid,homeworkid)
|
||||
{
|
||||
hideModal($(".blue-border-box"));
|
||||
var rootpath = getRootPath();
|
||||
var code_repeatpath = rootpath+"/courses/"+courseid+"/code_repeat?homework="+homeworkid;
|
||||
//新打开页面
|
||||
window.open(code_repeatpath);
|
||||
}
|
||||
|
||||
var test_repeat = function(homeworkid,courseid){
|
||||
$.post(
|
||||
'/student_work/code_repeattest',
|
||||
{homework: homeworkid},
|
||||
function(data,status){
|
||||
console.log("result = ");
|
||||
console.log(data);
|
||||
|
||||
if (data.status == 0) {
|
||||
$("#ajax-modal").html('<%= escape_javascript( render :partial => 'courses/compare_code_tips_2',:locals => {:des=>"查重完成,是否立即查看结果?",:status=>1, :homework=> homework,:courseid=> courseid})%>');
|
||||
showModal('ajax-modal', '580px');
|
||||
$('#ajax-modal').siblings().remove();
|
||||
$('#ajax-modal').before("<a href='javascript:void(0)' onclick='hideModal();' style='margin-left: 565px; margin-top:-10px;' class='resourceClose'></a>");
|
||||
//$('#ajax-modal').parent().css("top","40%").css("left","50%");
|
||||
$('#ajax-modal').parent().css("top","30%").css("left","50%").css("padding-top","10px").css("position","fixed");
|
||||
$('#ajax-modal').parent().addClass("resourceUploadPopup");
|
||||
$('#ajax-modal').css("padding-left","16px").css("padding-bottom","16px");
|
||||
|
||||
function closeModal(){
|
||||
hideModal($(".blue-border-box"));
|
||||
}
|
||||
}
|
||||
else if (data.status == -1){
|
||||
// confirm("对不起只支持java/c/c++的代码查重!");
|
||||
$("#ajax-modal").html('<%= escape_javascript( render :partial => 'courses/compare_code_tips_2',:locals => {:des=>"对不起目前只支持java/c/c++的代码查重!",:status=>0, :homework=> homework,:courseid=> courseid})%>');
|
||||
showModal('ajax-modal', '580px');
|
||||
$('#ajax-modal').siblings().remove();
|
||||
$('#ajax-modal').before("<a href='javascript:void(0)' onclick='hideModal();' style='margin-left: 565px; margin-top:-10px;' class='resourceClose'></a>");
|
||||
$('#ajax-modal').parent().css("top","30%").css("left","50%").css("padding-top","10px").css("position","fixed");
|
||||
$('#ajax-modal').parent().addClass("resourceUploadPopup");
|
||||
$('#ajax-modal').css("padding-left","16px").css("padding-bottom","16px");
|
||||
|
||||
function closeModal(){
|
||||
hideModal($(".blue-border-box"));
|
||||
}
|
||||
|
||||
}
|
||||
else if (data.status == -2){
|
||||
// confirm("对不起该作业的作品过少不能查重!");
|
||||
$("#ajax-modal").html('<%= escape_javascript( render :partial => 'courses/compare_code_tips_2',:locals => {:des=>"对不起该作业的作品过少不能查重!",:status=>0, :homework=> homework,:courseid=> courseid})%>');
|
||||
showModal('ajax-modal', '580px');
|
||||
$('#ajax-modal').siblings().remove();
|
||||
$('#ajax-modal').before("<a href='javascript:void(0)' onclick='hideModal();' style='margin-left: 565px; margin-top:-10px;' class='resourceClose'></a>");
|
||||
$('#ajax-modal').parent().css("top","30%").css("left","50%").css("padding-top","10px").css("position","fixed");
|
||||
$('#ajax-modal').parent().addClass("resourceUploadPopup");
|
||||
$('#ajax-modal').css("padding-left","16px").css("padding-bottom","16px");
|
||||
|
||||
function closeModal(){
|
||||
hideModal($(".blue-border-box"));
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
).fail(function(xhr, status){
|
||||
// confirm("对不起,服务器繁忙请稍后再试!");
|
||||
$("#ajax-modal").html('<%= escape_javascript( render :partial => 'courses/compare_code_tips_2',:locals => {:des=>"对不起,服务器繁忙请稍后再试!",:status=>0, :homework=> homework,:courseid=> courseid})%>');
|
||||
showModal('ajax-modal', '580px');
|
||||
$('#ajax-modal').siblings().remove();
|
||||
$('#ajax-modal').before("<a href='javascript:void(0)' onclick='hideModal();' style='margin-left: 565px; margin-top:-10px;' class='resourceClose'></a>");
|
||||
$('#ajax-modal').parent().css("top","30%").css("left","50%").css("padding-top","10px").css("position","fixed");
|
||||
$('#ajax-modal').parent().addClass("resourceUploadPopup");
|
||||
$('#ajax-modal').css("padding-left","16px").css("padding-bottom","16px");
|
||||
|
||||
function closeModal(){
|
||||
hideModal($(".blue-border-box"));
|
||||
}
|
||||
return;
|
||||
});
|
||||
};
|
||||
</script>
|
|
@ -0,0 +1,22 @@
|
|||
<div class="blue-border-box">
|
||||
<div class="box-con">
|
||||
<h4><%=des%></h4>
|
||||
<div class="box-con-a">
|
||||
<a href="javascript:void(0);" class="Blue-btn " style="width:67px; margin:25px auto 0px auto;" onclick = "yes_btn(<%=status%>,<%=courseid%>,<%=homework.id%>)">确定</a>
|
||||
</div>
|
||||
<div class="cl"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
function yes_btn(status,courseid,homeworkid)
|
||||
{
|
||||
hideModal($(".blue-border-box"));
|
||||
if(status == 1) {
|
||||
var rootpath = getRootPath();
|
||||
var code_repeatpath = rootpath+"/courses/"+courseid+"/code_repeat?homework="+homeworkid;
|
||||
window.open(code_repeatpath);
|
||||
}
|
||||
}
|
||||
</script>
|
|
@ -0,0 +1,21 @@
|
|||
|
||||
<% content_for :header_tags do %>
|
||||
<%= javascript_include_tag "/assets/codemirror/codemirror_python_ruby_c" %>
|
||||
<%= stylesheet_link_tag "/assets/codemirror/codemirror" %>
|
||||
<%= stylesheet_link_tag "/assets/codemirror/merge" %>
|
||||
<%= javascript_include_tag "https://cdnjs.cloudflare.com/ajax/libs/diff_match_patch/20121119/diff_match_patch.js"%>
|
||||
<%= javascript_include_tag "/assets/codemirror/merge" %>
|
||||
<% end %>
|
||||
|
||||
<article>
|
||||
<h3 style="float:left; width:47%; text-align:center;"><%=src_name%></h3>
|
||||
<% if @simi_value.to_i >= 90 %>
|
||||
<h6 style="color:red;float:left; width:6%; text-align:center;">相似度<%=@simi_value.to_i%>%</h3>
|
||||
<% else %>
|
||||
<h6 style="float:left; width:6%; text-align:center;">相似度<%=@simi_value.to_i%>%</h3>
|
||||
<% end %>
|
||||
<h3 style="float:left; width:47%; text-align:center;"><%=dst_name%></h3><div class="cl"></div>
|
||||
<pre id = "program-src_1" style = "display: none" ><%= src_code if src_code%></pre>
|
||||
<pre id = "program-src_2" style = "display: none" ><%= dst_code if dst_code%></pre>
|
||||
<div class = "program-compare-code" id=program-compare-code></div>
|
||||
</article>
|
|
@ -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})%>");
|
|
@ -0,0 +1,81 @@
|
|||
<div class="conbox">
|
||||
<h2 class="conbox-h2">查重结果</h2>
|
||||
<div class="chabox">
|
||||
<ul class="chabox-header">
|
||||
<li class="chabox-w-500" style = "width:437px" >被查作品</li>
|
||||
<li class="chabox-w-500" style = "width:561px" >疑被抄袭作品</li>
|
||||
<div class="cl"></div>
|
||||
</ul>
|
||||
<ul class="chabox-top">
|
||||
<li class="chabox-w-40 " >序号</li>
|
||||
<li class="chabox-w-401" >作品名称</li>
|
||||
<li>姓名</li>
|
||||
<li>学号 </li>
|
||||
<li class="chabox-r-line">时间 </li>
|
||||
<li class="chabox-w-401">作品名称</li>
|
||||
<li>姓名</li>
|
||||
<li>学号 </li>
|
||||
<li class="chabox-r-line">时间 </li>
|
||||
<li >相似度 </li>
|
||||
<li >对比 </li>
|
||||
</ul>
|
||||
|
||||
<%if @homework.homework_type == 2 %>
|
||||
<% @student_works.each_with_index do |student_work,index|%>
|
||||
<ul class="chabox-con" id = "chabox-con-<%=student_work.id%>" >
|
||||
<li class="chabox-w-40 chabox-txt-left" ><%=index+1%></li>
|
||||
<% student_work_name = student_work.name.nil? || student_work.name.empty? ? student_work.user.show_name + '的作品' : student_work.name%>
|
||||
<li class="chabox-w-401 chabox-txt-left" style =" text-align:left; text-indent:1em; " ><%=student_work_name%></li>
|
||||
<li><%=student_work.user.show_name%></li>
|
||||
<li><%= student_work.user.user_extensions.nil? ? "--" : student_work.user.user_extensions.student_id%> </li>
|
||||
<li class="chabox-r-line"><%= Time.parse(format_time(student_work.created_at)).strftime("%m-%d %H:%M")%></li>
|
||||
<% if student_work.simi_id.to_i > 0 && @works_hash[student_work.simi_id.to_i] %>
|
||||
<% simi_student_work = @works_hash[student_work.simi_id.to_i] %>
|
||||
<% simi_student_work_name = simi_student_work.name.nil? || simi_student_work.name.empty? ? simi_student_work.user.show_name + '的作品' : simi_student_work.name%>
|
||||
<li class="chabox-w-401 chabox-txt-left" style =" text-align:left; text-indent:1em; " ><%=simi_student_work_name%></li>
|
||||
<li><%=simi_student_work.user.show_name%></li>
|
||||
<li><%= simi_student_work.user.user_extensions.nil? ? "--" : simi_student_work.user.user_extensions.student_id%></li>
|
||||
<li class="chabox-r-line"><%= Time.parse(format_time(simi_student_work.created_at)).strftime("%m-%d %H:%M")%></li>
|
||||
<% if student_work.simi_value.to_i >= 90 %>
|
||||
<li style = "color:red" ><%=student_work.simi_value.to_i%>%</li>
|
||||
<% else %>
|
||||
<li ><%=student_work.simi_value.to_i%>%</li>
|
||||
<% end %>
|
||||
|
||||
<!--@works_hash[student_work.id].description -->
|
||||
<!--<li ><a href="javascript:void(0);" target="_blank" class="cha-btn" onclick = "show_code_compare()">查看</a>-->
|
||||
<li >
|
||||
<%= link_to("查看", show_comparecode_course_path(:homework_id => @homework.id,:src_id => student_work.id,:dst_id => student_work.simi_id.to_i),:class => "cha-btn",:remote => true ) %>
|
||||
</li>
|
||||
<%else%>
|
||||
<li class="chabox-w-401">--</li>
|
||||
<li>--</li>
|
||||
<li>--</li>
|
||||
<li class="chabox-r-line">--</li>
|
||||
<li >--</li>
|
||||
<li > </li>
|
||||
<% end %>
|
||||
</ul>
|
||||
<%end%>
|
||||
<%end%>
|
||||
</div>
|
||||
<div class="cl"></div>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
function show_code_compare() {
|
||||
|
||||
// $("#ajax-modal").html('<%= escape_javascript( render :partial => 'courses/show_compare_code' ,:locals => {:src_code=> 1,:src_name=> 2,:dst_name=> 3, :dst_code=> 4,:language=> 5,})%>');
|
||||
// showModal('ajax-modal', '950px');
|
||||
// $('#ajax-modal').siblings().remove();
|
||||
// $('#ajax-modal').before("<a href='javascript:void(0)' onclick='closeModal();' style='margin-left: 935px;' class='resourceClose'></a>");
|
||||
// $('#ajax-modal').parent().css("top", "20%").css("left", "26.5%").css("position", "absolute");
|
||||
// $('#ajax-modal').parent().addClass("resourceUploadPopup");
|
||||
// $('#ajax-modal').css("padding-left", "16px").css("padding-bottom", "16px");
|
||||
//
|
||||
// function closeModal() {
|
||||
// hideModal($(".contrast-box"));
|
||||
// }
|
||||
}
|
||||
|
||||
</script>
|
|
@ -9,7 +9,7 @@
|
|||
<input type="password" style="display: none"/> <!--阻止表单自动填充 -->
|
||||
<label><span class="c_red">*</span> <%= l(:label_tags_course_name)%> :</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">
|
||||
|
|
|
@ -0,0 +1,101 @@
|
|||
$("#ajax-modal").html('<%= escape_javascript( render :partial => 'courses/show_compare_code' ,:locals => {:src_code=> @src_code,:src_name=> @src_username,:dst_name=> @dst_username, :dst_code=> @dst_code, :simivalue=> @simi_value })%>');
|
||||
showModal('ajax-modal', '1250px');
|
||||
$('#ajax-modal').siblings().remove();
|
||||
$('#ajax-modal').before("<a href='javascript:void(0)' onclick='closeModal();' style='margin-left: 1235px; margin-top:-18px;' class='resourceClose'></a>");
|
||||
$('#ajax-modal').parent().css("top","30%").css("left","20%").css("padding-top","20px").css("position","fixed");
|
||||
//$('#ajax-modal').parent().addClass("resourceUploadPopup");
|
||||
$('#ajax-modal').css("padding-left","16px").css("padding-bottom","16px");
|
||||
|
||||
function closeModal(){
|
||||
hideModal($(".program-compare-code"));
|
||||
}
|
||||
|
||||
var program_name = "text/x-csrc";
|
||||
var language = <%= @homework.language.to_i %>;
|
||||
if (language == 1) {
|
||||
program_name = 'text/x-csrc';
|
||||
} else if(language==2){
|
||||
program_name = 'text/x-c++src';
|
||||
}else if(language==3){
|
||||
program_name = 'text/x-cython';
|
||||
} else if(language==4){
|
||||
program_name = 'text/x-java';
|
||||
}
|
||||
//
|
||||
//var editor_1 = CodeMirror(document.getElementById("program-code_1"), {
|
||||
// mode: {name: program_name,
|
||||
// version: 2,
|
||||
// singleLineStringErrors: false},
|
||||
// lineNumbers: true,
|
||||
// indentUnit: 2,
|
||||
// matchBrackets: true,
|
||||
// readOnly: true,
|
||||
// value: $("#program-src_1").text()
|
||||
// }
|
||||
//);
|
||||
//
|
||||
//var editor_2 = CodeMirror(document.getElementById("program-code_2"), {
|
||||
// mode: {name: program_name,
|
||||
// version: 2,
|
||||
// singleLineStringErrors: false},
|
||||
// lineNumbers: true,
|
||||
// indentUnit: 2,
|
||||
// matchBrackets: true,
|
||||
// readOnly: true,
|
||||
// value: $("#program-src_2").text()
|
||||
// }
|
||||
//);
|
||||
|
||||
var value, orig1, orig2, dv, panes = 2, highlight = true, connect = null, collapse = false;
|
||||
function initUI() {
|
||||
if (value == null) return;
|
||||
var target = document.getElementById("program-compare-code");
|
||||
target.innerHTML = "";
|
||||
dv = CodeMirror.MergeView(target, {
|
||||
value: value,
|
||||
origLeft: panes == 3 ? orig1 : null,
|
||||
orig: orig2,
|
||||
lineNumbers: true,
|
||||
mode: program_name,
|
||||
highlightDifferences: highlight,
|
||||
connect: connect,
|
||||
collapseIdentical: collapse
|
||||
});
|
||||
}
|
||||
|
||||
function toggleDifferences() {
|
||||
dv.setShowDifferences(highlight = !highlight);
|
||||
}
|
||||
|
||||
|
||||
value = $("#program-src_1").text();
|
||||
orig1 = $("#program-src_1").text();
|
||||
orig2 = $("#program-src_2").text();
|
||||
initUI();
|
||||
|
||||
|
||||
function mergeViewHeight(mergeView) {
|
||||
function editorHeight(editor) {
|
||||
if (!editor) return 0;
|
||||
return editor.getScrollInfo().height;
|
||||
}
|
||||
return Math.max(editorHeight(mergeView.leftOriginal()),
|
||||
editorHeight(mergeView.editor()),
|
||||
editorHeight(mergeView.rightOriginal()));
|
||||
}
|
||||
|
||||
function resize(mergeView) {
|
||||
var height = mergeViewHeight(mergeView);
|
||||
for(;;) {
|
||||
if (mergeView.leftOriginal())
|
||||
mergeView.leftOriginal().setSize(null, height);
|
||||
mergeView.editor().setSize(null, height);
|
||||
if (mergeView.rightOriginal())
|
||||
mergeView.rightOriginal().setSize(null, height);
|
||||
|
||||
var newHeight = mergeViewHeight(mergeView);
|
||||
if (newHeight >= height) break;
|
||||
else height = newHeight;
|
||||
}
|
||||
mergeView.wrap.style.height = height + "px";
|
||||
}
|
|
@ -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})%>");
|
|
@ -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("发 送".html_safe, 'javascript:void(0)',:class => "postOptionLink",:onclick=>"show_send('#{file.id}','#{User.current.id}','file')") %></li>
|
||||
|
@ -66,8 +66,8 @@
|
|||
<li><%= link_to("发 送".html_safe, 'javascript:void(0)',:class => "postOptionLink2",:onclick=>"show_send('#{file.id}','#{User.current.id}','file')") %></li>
|
||||
</ul>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue