Merge branch 'develop' into cxt_course

cxt_course
cxt 9 years ago
commit 45fb2d0a3e

@ -6,10 +6,17 @@ module Mobile
resources :blog_comments do
desc "get special topic"
get ':id' do
post ':id' do
user = current_user
#0一级回复的更多 1 二级回复的更多
type = params[:type] || 0
page = params[:page] || 0
blog = BlogComment.find params[:id]
present :data, blog, with: Mobile::Entities::BlogComment,user: user
present :data, blog, with: Mobile::Entities::BlogComment,user: user,type: type,page: page
present :type, type
present :page, page
present :status, 0
end
end

@ -200,8 +200,13 @@ module Mobile
# course = Course.find(params[:id])
cs = CoursesService.new
course = cs.show_course(params,current_user)
present :data, course, with: Mobile::Entities::Course,user: current_user
{ status: 0}
if course[:course][:is_delete] == 1
{status:-1, message: '该班级不存在或已被删除啦' }
else
present :data, course, with: Mobile::Entities::Course,user: current_user
present :status, 0
end
end
end
@ -212,7 +217,7 @@ module Mobile
get "homeworks/:id" do
cs = CoursesService.new
homeworks = cs.homework_list params,current_user
present :data, homeworks, with: Mobile::Entities::Homework
present :data, homeworks, with: Mobile::Entities::Homework,user: current_user
present :status, 0
end
@ -259,7 +264,7 @@ module Mobile
post ":course_id/attachments" do
cs = CoursesService.new
count = cs.course_attachments params
present :data, count, with: Mobile::Entities::Attachment
present :data, count, with: Mobile::Entities::Attachment,user: current_user
present :status, 0
end
@ -392,8 +397,8 @@ module Mobile
authenticate!
course = Course.find(params[:course_id])
exercises = course.exercises.where("exercise_status <> 1").order("created_at desc")
present :data,exercises,with:Mobile::Entities::Exercise
exercises = course.exercises.where("exercise_status <> 1").reorder("created_at desc")
present :data,exercises,with:Mobile::Entities::Exercise,user: current_user
present :status,0
end

@ -7,11 +7,17 @@ module Mobile
include IssuesHelper
desc "get special issuse"
get ':id' do
post ':id' do
authenticate!
user = current_user
#0一级回复的更多 1 二级回复的更多
type = params[:type] || 0
page = params[:page] || 0
issue = Issue.find params[:id]
present :data, issue, with: Mobile::Entities::Issue,user: user
present :data, issue, with: Mobile::Entities::Issue,user: user,type: type,page: page
present :type, type
present :page, page
present :status, 0
end
end

@ -6,11 +6,18 @@ module Mobile
resources :journal_for_messages do
desc "get special journal"
get ':id' do
post ':id' do
authenticate!
user = current_user
#0一级回复的更多 1 二级回复的更多
type = params[:type] || 0
page = params[:page] || 0
jour = JournalsForMessage.find params[:id]
present :data, jour, with: Mobile::Entities::Jours,user: user
present :data, jour, with: Mobile::Entities::Jours,user: user,type: type,page: page
present :type, type
present :page, page
present :status, 0
end
end

@ -6,11 +6,17 @@ module Mobile
resources :messages do
desc "get special topic"
get ':id' do
post ':id' do
authenticate!
user = current_user
#0一级回复的更多 1 二级回复的更多
type = params[:type] || 0
page = params[:page] || 0
message = Message.find params[:id]
present :data, message, with: Mobile::Entities::Message,user: user
present :data, message, with: Mobile::Entities::Message,user: user,type: type,page: page
present :type, type
present :page, page
present :status, 0
end
end

@ -6,11 +6,17 @@ module Mobile
resources :newss do
desc "get special news"
get ':id' do
post ':id' do
authenticate!
user = current_user
#0一级回复的更多 1 二级回复的更多
type = params[:type] || 0
page = params[:page] || 0
news = News.find params[:id]
present :data, news, with: Mobile::Entities::News,user: user
present :data, news, with: Mobile::Entities::News,user: user,type: type,page: page
present :type, type
present :page, page
present :status, 0
end
end

@ -85,12 +85,26 @@ module Mobile
requires :token, type: String
requires :course_ids, type: Array[Integer]
requires :send_id, type: Integer
requires :send_type, type: Integer
end
post 'send' do
authenticate!
rs = ResourcesService.new
ori, flag, save_message = rs.send_resource_to_course(current_user,params)
ori = nil
flag = false
save_message = nil
case params[:send_type]
when 1
ori, flag, save_message = rs.send_resource_to_course(current_user,params)
when 2
ori, flag, save_message = rs.send_homework_to_course(current_user,params)
when 3
ori, flag, save_message = rs.send_exercise_to_course(current_user,params)
end
if flag
present :status, 0
else

@ -6,11 +6,17 @@ module Mobile
resources :whomeworks do
desc "get one homework"
get ':id' do
post ':id' do
authenticate!
user = current_user
#0一级回复的更多 1 二级回复的更多
type = params[:type] || 0
page = params[:page] || 0
homework = HomeworkCommon.find params[:id]
present :data, homework, with: Mobile::Entities::Whomework,user: user
present :data, homework, with: Mobile::Entities::Whomework,user: user,type: type,page: page
present :type, type
present :page, page
present :status, 0
end
end

@ -25,10 +25,12 @@ module Mobile
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
all_comments = []
ac.nil? || ac.act.nil? ? 0 : get_all_children(all_comments, ac.act).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?

@ -3,6 +3,7 @@ module Mobile
class Attachment < Grape::Entity
include Redmine::I18n
include ActionView::Helpers::NumberHelper
include ApplicationHelper
def self.attachment_expose(field)
expose field do |f,opt|
if f.is_a?(Hash) && f.key?(field)
@ -22,6 +23,7 @@ module Mobile
(number_to_human_size(f.filesize)).gsub("ytes", "").to_s
when :coursename
f.course.nil? ? "" : f.course.name
end
end
end
@ -36,6 +38,12 @@ module Mobile
attachment_expose :file_dir
attachment_expose :attafile_size
attachment_expose :coursename #所属班级名
expose :current_user_is_teacher, if: lambda { |instance, options| options[:user] } do |instance, options|
current_user = options[:user]
current_user_is_teacher = false
current_user_is_teacher = is_course_teacher(current_user,instance.course)
current_user_is_teacher
end
end
end
end

@ -25,7 +25,9 @@ module Mobile
when :act_id
u.id
when :comment_count
u.children.count
# u.children.count
all_comments = []
get_all_children(all_comments, u).count
end
end
end
@ -51,7 +53,18 @@ module Mobile
blog_comment_expose :praise_count
expose :blog_comment_children, using:Mobile::Entities::BlogComment do |c,opt|
if c.is_a? (::BlogComment)
c.children.reverse
##自己的父回复为空 才有子回复
if !opt[:children]
if c.parent.nil? && opt[:type] == 0
opt[:children] = true
all_comments = []
tStart = opt[:page]*5
tEnd = (opt[:page]+1)*5 - 1
all_comments = get_all_children(all_comments, c)[tStart..tEnd]
all_comments
end
end
end
end
expose :has_praise, if: lambda { |instance, options| options[:user] } do |instance, options|
@ -61,6 +74,63 @@ module Mobile
has_praise = obj.empty? ? false : true
has_praise
end
expose :parents_count, if: lambda { |instance, options| options[:user] } do |instance, options|
parents_reply = []
parents_reply = get_reply_parents_no_root(parents_reply, instance)
parents_reply.count
end
expose :parents_reply_bottom, using:Mobile::Entities::BlogComment do |c,opt|
if c.is_a? (::BlogComment)
#取二级回复的底楼层
parents_reply = []
parents_reply = get_reply_parents_no_root(parents_reply, c)
if parents_reply.count > 0 && !opt[:bottom]
if opt[:type] == 1
# opt[:bottom] = true
# parents_reply[opt[:page]..opt[:page]]
else
opt[:bottom] = true
parents_reply[0..0]
end
else
[]
end
end
end
expose :parents_reply_top, using:Mobile::Entities::BlogComment do |c,opt|
if c.is_a? (::BlogComment)
#取二级回复的顶楼层
parents_reply = []
parents_reply = get_reply_parents_no_root(parents_reply, c)
if parents_reply.count > 0 && !opt[:top]
if opt[:type] == 1
opt[:bottom] = true
tStart = (opt[:page]-1)*5+2
tEnd = (opt[:page])*5+2 - 1
if tEnd >= parents_reply.count - 1
tEnd = parents_reply.count - 2
end
if tStart <= parents_reply.count - 2
parents_reply = parents_reply.reverse[tStart..tEnd]
parents_reply.reverse
else
[]
end
else
opt[:top] = true
parents_reply = parents_reply.reverse[0..1]
parents_reply.reverse
end
else
[]
end
end
end
end
end
end

@ -27,6 +27,14 @@ module Mobile
expose :exercise_name
expose :exercise_description
exercise_expose :coursename #所属班级名
expose :current_user_is_teacher, if: lambda { |instance, options| options[:user] } do |instance, options|
current_user = options[:user]
current_user_is_teacher = false
current_user_is_teacher = is_course_teacher(current_user,instance.course)
current_user_is_teacher
end
end
end
end

@ -98,6 +98,14 @@ module Mobile
homework_expose :coursename #所属班级名
expose :current_user_is_teacher, if: lambda { |instance, options| options[:user] } do |instance, options|
if instance[:current_user_is_teacher].nil?
current_user = options[:user]
current_user_is_teacher = false
current_user_is_teacher = is_course_teacher(current_user,instance.course)
current_user_is_teacher
end
end
end
end
end

@ -23,7 +23,9 @@ module Mobile
when :issue_status
IssueStatus.find(issue.status_id).name
when :journals_count
issue.journals.where("notes is not null and notes != ''").count
# issue.journals.where("notes is not null and notes != ''").count
all_comments = []
get_all_children(all_comments, f).count
when :project_name
issue.project.name
when :praise_count

@ -18,7 +18,9 @@ module Mobile
when :lasted_comment
time_from_now f.created_on
when :reply_count
f.children.count
# f.children.count
all_comments = []
get_all_children(all_comments, f).count
when :praise_count
get_activity_praise_num(f)
when :act_type

@ -30,6 +30,9 @@ module Mobile
'Message'
when :act_id
u.id
when :replies_count
all_comments = []
get_all_children(all_comments, u).count
end
end
end

@ -24,6 +24,9 @@ module Mobile
'News'
when :act_id
f.id
when :comments_count
all_comments = []
get_all_children(all_comments, f).count
end
end
elsif f.is_a?(Hash) && !f.key?(field)

@ -1,6 +1,6 @@
class OrgDocumentCommentsController < ApplicationController
before_filter :find_organization, :only => [:new, :create, :show, :index]
before_filter :authorize_allowed, :only => [:create, :add_reply]
before_filter :authorize_allowed, :only => [:create, :add_reply, :add_reply_in_doc]
helper :attachments,:organizations
layout 'base_org'

@ -300,15 +300,13 @@ class ProjectsController < ApplicationController
return
end
logger.debug "111111111"*100
# over
@author = params[:user_id].blank? ? nil : User.active.find(params[:user_id])
@page = params[:page] ? params[:page].to_i + 1 : 0
# 根据私密性,取出符合条件的所有数据
if User.current.member_of?(@project) || User.current.admin?
case params[:type]
when nil
@events_pages = ForgeActivity.where("project_id = ? and forge_act_type in ('Issue', 'Message','News', 'Project', 'Attachment')", @project).includes(:forge_act).order("updated_at desc").limit(10).offset(@page * 10)
@events_pages = ForgeActivity.where("project_id = ? and forge_act_type in ('Issue', 'Message','News', 'Project', 'Attachment','Commit')", @project).includes(:forge_act).order("updated_at desc").limit(10).offset(@page * 10)
when 'issue'
@events_pages = ForgeActivity.where("project_id = ? and forge_act_type = 'Issue'", @project).includes(:forge_act).order("updated_at desc").limit(10).offset(@page * 10)
when 'news'
@ -321,8 +319,8 @@ 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
logger.debug "2"*100
# 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")
@ -335,20 +333,14 @@ class ProjectsController < ApplicationController
@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
logger.debug "3"*100
begin
gid = @project.gpid
logger.debug "31"*100
g_branch = g.project(gid)
logger.debug "4"*100
g_branch = g_branch.default_branch.to_s
logger.debug "5"*100
g_project = g.project(gid)
g_branch = g_project.default_branch.to_s
rescue =>e
logger.error("get gitlab project failed: " + e)
logger.error("get default branch failed: " + e)
end
logger.debug "6"*100
@rev = g_branch.nil? ? "master" : g_branch
logger.debug "7"*100
end
# 根据对应的请求,返回对应的数据
respond_to do |format|

@ -165,7 +165,7 @@ class QualityAnalysisController < ApplicationController
logger.info("result: delete job ###################==>#{d_job}")
qa.delete
respond_to do |format|
format.html{redirect_to project_quality_analysis_path(:project_id => @project.id)}
format.html{redirect_to :controller => 'repositories', :action => 'show', :id => @project, :repository_id => gitlab_repository(@project).identifier}
end
rescue Exception => e
puts e
@ -199,9 +199,6 @@ class QualityAnalysisController < ApplicationController
# update成功则返回 200
jenkins_job = @client.job.update("#{job_name}", @doc.to_xml)
get_current_build_status = @client.job.get_current_build_status("Hjqreturn-1280")
logger.error("Failed to update job: ==> #{jenkins_job}") unless jenkins_job == '200'
# 数据更新到Trustie数据
if jenkins_job == '200'
logger.info("quality_ananlysis will be updated: ==> #{jenkins_job}")

@ -48,7 +48,7 @@ class RepositoriesController < ApplicationController
include RepositoriesHelper
helper :project_score
#@root_path = RepositoriesHelper::ROOT_PATH
require 'net/ssh'
# require 'net/ssh'
rescue_from Redmine::Scm::Adapters::CommandFailed, :with => :show_error_command_failed
def new

@ -78,12 +78,7 @@ class WechatsController < ActionController::Base
end
# When user view URL in the menu button
on :view, with: 'http://wechat.somewhere.com/view_url' do |request, view|
uw = user_binded?(request[:FromUserName])
unless uw
sendBind(request)
else
request.reply.text "#{request[:FromUserName]} view #{view}"
end
request.reply.text "#{request[:FromUserName]} view #{view}"
end
# When user sent the imsage
@ -147,6 +142,14 @@ class WechatsController < ActionController::Base
default_msg(request)
end
on :click, with: 'PROJECT' do |request, key|
request.reply.text "此功能正在开发中,很快就会上线,谢谢!"
end
on :click, with: 'JOIN_PROJECT' do |request, key|
request.reply.text "此功能正在开发中,很快就会上线,谢谢!"
end
on :click, with: 'JOIN_CLASS' do |request, key|
uw = user_binded?(request[:FromUserName])
unless uw
@ -218,8 +221,8 @@ class WechatsController < ActionController::Base
raise CoursesService::JoinCourseError.message(status[:state])
end
news = (1..1).each_with_object([]) { |n, memo| memo << { title: '恭喜您成功加入班级,开始学习吧!',
content: "课程名称: #{course.name}\n班级名称: #{course.name}\n任课老师: #{course.teacher.show_name}\n进入班级,和小伙伴愉快的学习吧!"} }
news = (1..1).each_with_object([]) { |n, memo| memo << { title: '恭喜您成功加入班级,开始学习吧!',
content: "课程名称#{course.name}\n班级名称:#{course.name}\n任课老师:#{course.teacher.show_name}\n进入班级,和小伙伴愉快的学习吧!"} }
return 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=#{ROOT_URL+'/wechat/user_activities#/class?id='+course.id.to_s}&response_type=code&scope=snsapi_base&state=myclass#wechat_redirect"
pic_url = "#{ROOT_URL}/images/wechat/class.jpg"
@ -274,7 +277,7 @@ class WechatsController < ActionController::Base
user: user
)
ws = WechatService.new
ws.binding_succ_notice(user.id, "您已成功绑定Trustie平台", user.login, format_time(Time.now))
ws.binding_succ_notice(user.id, "您已成功绑定Trustie平台", user.login, format_time(Time.now))
render :json => {status:0, msg: "绑定成功"}
rescue Exception=>e
render :json => {status: -1, msg: e.message}

@ -38,6 +38,24 @@ module ApplicationHelper
# super
# end
# 通过系统外部邮箱查找用户,如果用户不存在则用邮箱替换
def get_user_by_mail mail
user = User.find_by_mail(mail)
user.nil? ? User.find(2) : user
end
# 历史数据(老版本库数据)处理完则可以修改该放放
def get_rep_identifier_by_project project
identifier = Repository.where(:project_id => project.id, :type => "Repository::Gitlab").first.try(:identifier)
result = identifier.nil? ? Repository.where(:project_id => project.id).first.try(:identifier) : identifier
result
end
# 获取用户单位
# 优先获取高校信息如果改信息不存在则获取occupation
def get_occupation_from_user user
School.where("id=?",user.user_extensions.school_id).first.try(:name).nil? ? user.user_extensions.occupation : School.where("id=?",user.user_extensions.school_id).first.try(:name)
end
def update_visiti_count container
container.update_column(:visits, container.visits + 1)

@ -0,0 +1,20 @@
#coding=utf-8
#
module WechatsHelper
def include_wechat_jsfile
if Rails.env.production?
javascript_include_tag '/javascripts/wechat/build/app.min.js'
else
wechat_path = File.join(Rails.root, "public", "javascripts", "wechat")
srcs = Rails.application.config.wechat_srcs
paths = []
srcs.each do |src|
Dir.glob(wechat_path+ "/#{src}" ) do |path|
paths << path[File.join(Rails.root, "public").to_s.size, path.size]
end
end
javascript_include_tag *paths
end
end
end

@ -22,9 +22,7 @@ class Changeset < ActiveRecord::Base
#after_save :be_user_score # user_score
has_many :filechanges, :class_name => 'Change', :dependent => :delete_all
# fq
has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy
# end
has_many :forge_acts, :class_name => 'ForgeActivity',:as =>:forge_act ,:dependent => :destroy
#Added by nie
has_one :project_status, :dependent => :destroy
@ -59,7 +57,6 @@ class Changeset < ActiveRecord::Base
validates :committed_on, presence: true
validates :commit_date, presence: true
validates :scmid, uniqueness: {scope: :repository_id, allow_nil: true}
scope :visible, lambda {|*args|
includes(:repository => :project).where(Project.allowed_to_condition(args.shift || User.current, :view_changesets, *args))
}
@ -68,7 +65,7 @@ class Changeset < ActiveRecord::Base
# after_update :be_user_score
after_destroy :down_user_score
# before_create :before_create_cs
after_create :act_as_forge_activity
# after_create :act_as_forge_activity
def revision=(r)
@ -118,7 +115,7 @@ class Changeset < ActiveRecord::Base
# 项目中提交动态类型Changeset
# type0 为老版本即Trsutie数据 1为gitlab中获取的动态
def act_as_forge_activity
self.acts << ForgeActivity.new(:user_id => self.user_id, :project_id => self.project_id, :type => true)
self.forge_acts << ForgeActivity.new(:user_id => self.user_id, :project_id => self.project_id, :type => true)
end
def scan_for_issues

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

Loading…
Cancel
Save