remove some test after copying from hjq
This commit is contained in:
parent
c041275cdc
commit
9e642b8627
|
@ -1,3 +1,3 @@
|
|||
#safe table
|
||||
#Mon Jan 05 10:27:54 CST 2015
|
||||
connections=connections.15
|
||||
#safe table
|
||||
#Mon Jan 05 10:27:54 CST 2015
|
||||
connections=connections.15
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#safe table
|
||||
#Mon Jan 05 10:27:54 CST 2015
|
||||
defaultConnection=defaultConnection.15
|
||||
sites=sites.15
|
||||
#safe table
|
||||
#Mon Jan 05 10:27:54 CST 2015
|
||||
defaultConnection=defaultConnection.15
|
||||
sites=sites.15
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
#safe table
|
||||
#Mon Jan 05 10:27:28 CST 2015
|
||||
webservers=webservers.12
|
||||
#safe table
|
||||
#Mon Jan 05 10:27:28 CST 2015
|
||||
webservers=webservers.12
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<session version="1.0">
<refactoring comment="Delete resource 'trustie2'" deleteContents="false" description="Delete resource 'trustie2'" element1="/trustie2" flags="7" id="org.eclipse.ltk.core.refactoring.delete.resources" resources="1" stamp="1420424676858"/>
<refactoring comment="Delete resource 'trustie2'" deleteContents="false" description="Delete resource 'trustie2'" element1="/trustie2" flags="7" id="org.eclipse.ltk.core.refactoring.delete.resources" resources="1" stamp="1420424775104"/>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<session version="1.0">
<refactoring comment="Delete resource 'trustie2'" deleteContents="false" description="Delete resource 'trustie2'" element1="/trustie2" flags="7" id="org.eclipse.ltk.core.refactoring.delete.resources" resources="1" stamp="1420424676858"/>
<refactoring comment="Delete resource 'trustie2'" deleteContents="false" description="Delete resource 'trustie2'" element1="/trustie2" flags="7" id="org.eclipse.ltk.core.refactoring.delete.resources" resources="1" stamp="1420424775104"/>
|
||||
</session>
|
|
@ -1,2 +1,2 @@
|
|||
1420424676858 Delete resource 'trustie2'
|
||||
1420424775104 Delete resource 'trustie2'
|
||||
1420424676858 Delete resource 'trustie2'
|
||||
1420424775104 Delete resource 'trustie2'
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<section name="Workbench">
|
||||
<section name="RefactoringWizard.preview">
|
||||
<item value="400" key="height"/>
|
||||
<item value="600" key="width"/>
|
||||
</section>
|
||||
</section>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<section name="Workbench">
|
||||
<section name="RefactoringWizard.preview">
|
||||
<item value="400" key="height"/>
|
||||
<item value="600" key="width"/>
|
||||
</section>
|
||||
</section>
|
||||
|
|
80
Guardfile
80
Guardfile
|
@ -1,40 +1,40 @@
|
|||
# More info at https://github.com/guard/guard#readme
|
||||
|
||||
# guard 'rails' do
|
||||
# watch('Gemfile.lock')
|
||||
# watch(%r{^(config|lib)/.*})
|
||||
# end
|
||||
#
|
||||
guard 'spork', :test_unit => true, :test_unit_env => {'RAILS_ENV' => 'test'}, :wait => 60 do
|
||||
watch(%r{app/models/.+\.rb})
|
||||
watch('config/application.rb')
|
||||
watch('config/environment.rb')
|
||||
watch('config/environments/test.rb')
|
||||
watch(%r{^config/initializers/.+\.rb$})
|
||||
watch('Gemfile.lock')
|
||||
watch('spec/spec_helper.rb') { :rspec }
|
||||
watch('test/test_helper.rb') { :test_unit }
|
||||
watch(%r{features/support/}) { :cucumber }
|
||||
end
|
||||
|
||||
guard :test, :drb => true, :all_after_pass => false, :all_on_start => false do
|
||||
watch(%r{^test/.+_test\.rb$})
|
||||
watch('test/test_helper.rb') { 'test' }
|
||||
|
||||
# Non-rails
|
||||
watch(%r{^lib/(.+)\.rb$}) { |m| "test/#{m[1]}_test.rb" }
|
||||
|
||||
# Rails 4
|
||||
# watch(%r{^app/(.+)\.rb}) { |m| "test/#{m[1]}_test.rb" }
|
||||
# watch(%r{^app/controllers/application_controller\.rb}) { 'test/controllers' }
|
||||
# watch(%r{^app/controllers/(.+)_controller\.rb}) { |m| "test/integration/#{m[1]}_test.rb" }
|
||||
# watch(%r{^app/views/(.+)_mailer/.+}) { |m| "test/mailers/#{m[1]}_mailer_test.rb" }
|
||||
# watch(%r{^lib/(.+)\.rb}) { |m| "test/lib/#{m[1]}_test.rb" }
|
||||
|
||||
# Rails < 4
|
||||
watch(%r{^app/models/(.+)\.rb$}) { |m| "test/unit/#{m[1]}_test.rb" }
|
||||
watch(%r{^app/controllers/(.+)\.rb$}) { |m| "test/functional/#{m[1]}_test.rb" }
|
||||
watch(%r{^app/views/(.+)/.+\.erb$}) { |m| "test/functional/#{m[1]}_controller_test.rb" }
|
||||
watch(%r{^app/views/.+$}) { 'test/integration' }
|
||||
watch('app/controllers/application_controller.rb') { ['test/functional', 'test/integration'] }
|
||||
end
|
||||
# More info at https://github.com/guard/guard#readme
|
||||
|
||||
# guard 'rails' do
|
||||
# watch('Gemfile.lock')
|
||||
# watch(%r{^(config|lib)/.*})
|
||||
# end
|
||||
#
|
||||
guard 'spork', :test_unit => true, :test_unit_env => {'RAILS_ENV' => 'test'}, :wait => 60 do
|
||||
watch(%r{app/models/.+\.rb})
|
||||
watch('config/application.rb')
|
||||
watch('config/environment.rb')
|
||||
watch('config/environments/test.rb')
|
||||
watch(%r{^config/initializers/.+\.rb$})
|
||||
watch('Gemfile.lock')
|
||||
watch('spec/spec_helper.rb') { :rspec }
|
||||
watch('test/test_helper.rb') { :test_unit }
|
||||
watch(%r{features/support/}) { :cucumber }
|
||||
end
|
||||
|
||||
guard :test, :drb => true, :all_after_pass => false, :all_on_start => false do
|
||||
watch(%r{^test/.+_test\.rb$})
|
||||
watch('test/test_helper.rb') { 'test' }
|
||||
|
||||
# Non-rails
|
||||
watch(%r{^lib/(.+)\.rb$}) { |m| "test/#{m[1]}_test.rb" }
|
||||
|
||||
# Rails 4
|
||||
# watch(%r{^app/(.+)\.rb}) { |m| "test/#{m[1]}_test.rb" }
|
||||
# watch(%r{^app/controllers/application_controller\.rb}) { 'test/controllers' }
|
||||
# watch(%r{^app/controllers/(.+)_controller\.rb}) { |m| "test/integration/#{m[1]}_test.rb" }
|
||||
# watch(%r{^app/views/(.+)_mailer/.+}) { |m| "test/mailers/#{m[1]}_mailer_test.rb" }
|
||||
# watch(%r{^lib/(.+)\.rb}) { |m| "test/lib/#{m[1]}_test.rb" }
|
||||
|
||||
# Rails < 4
|
||||
watch(%r{^app/models/(.+)\.rb$}) { |m| "test/unit/#{m[1]}_test.rb" }
|
||||
watch(%r{^app/controllers/(.+)\.rb$}) { |m| "test/functional/#{m[1]}_test.rb" }
|
||||
watch(%r{^app/views/(.+)/.+\.erb$}) { |m| "test/functional/#{m[1]}_controller_test.rb" }
|
||||
watch(%r{^app/views/.+$}) { 'test/integration' }
|
||||
watch('app/controllers/application_controller.rb') { ['test/functional', 'test/integration'] }
|
||||
end
|
||||
|
|
10
README.rdoc
10
README.rdoc
|
@ -1,5 +1,5 @@
|
|||
= Redmine
|
||||
|
||||
Redmine is a flexible project management web application written using Ruby on Rails framework.
|
||||
|
||||
More details can be found in the doc directory or on the official website http://www.redmine.org
|
||||
= Redmine
|
||||
|
||||
Redmine is a flexible project management web application written using Ruby on Rails framework.
|
||||
|
||||
More details can be found in the doc directory or on the official website http://www.redmine.org
|
||||
|
|
14
Rakefile
14
Rakefile
|
@ -1,7 +1,7 @@
|
|||
#!/usr/bin/env rake
|
||||
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
||||
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
||||
|
||||
require File.expand_path('../config/application', __FILE__)
|
||||
|
||||
RedmineApp::Application.load_tasks
|
||||
#!/usr/bin/env rake
|
||||
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
||||
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
||||
|
||||
require File.expand_path('../config/application', __FILE__)
|
||||
|
||||
RedmineApp::Application.load_tasks
|
||||
|
|
|
@ -1,60 +1,60 @@
|
|||
#coding=utf-8
|
||||
|
||||
module Mobile
|
||||
|
||||
module Entities
|
||||
class Auth < Grape::Entity
|
||||
expose :token
|
||||
expose :user, using: User
|
||||
end
|
||||
end
|
||||
|
||||
module Apis
|
||||
class Auth < Grape::API
|
||||
resource :auth do
|
||||
desc "用户登录"
|
||||
params do
|
||||
requires :login, type: String, desc: 'Username or email'
|
||||
requires :password, type: String, desc: 'Password'
|
||||
end
|
||||
post do
|
||||
user,last_logon = ::User.try_to_login(params[:login], params[:password])
|
||||
if user
|
||||
::ApiKey.delete_all(user_id: user.id)
|
||||
key = ::ApiKey.create!(user_id: user.id)
|
||||
api_user = ::UsersService.new.show_user({id:user.id})
|
||||
present :data, {token: key.access_token, user: api_user}, using: Entities::Auth
|
||||
present :status, 0
|
||||
else
|
||||
present :message, "无效的用户名或密码"
|
||||
present :status,1
|
||||
end
|
||||
end
|
||||
|
||||
desc "用户登出"
|
||||
params do
|
||||
requires :token, type: String
|
||||
end
|
||||
delete do
|
||||
authenticate!
|
||||
::ApiKey.delete_all(user_id: current_user.id)
|
||||
{status: 0}
|
||||
end
|
||||
|
||||
desc "忘记密码"
|
||||
params do
|
||||
requires :mail,type: String
|
||||
end
|
||||
post 'lost_password' do
|
||||
us = UsersService.new
|
||||
message = us.lost_password params
|
||||
present :message, message
|
||||
present :status, 0
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
#coding=utf-8
|
||||
|
||||
module Mobile
|
||||
|
||||
module Entities
|
||||
class Auth < Grape::Entity
|
||||
expose :token
|
||||
expose :user, using: User
|
||||
end
|
||||
end
|
||||
|
||||
module Apis
|
||||
class Auth < Grape::API
|
||||
resource :auth do
|
||||
desc "用户登录"
|
||||
params do
|
||||
requires :login, type: String, desc: 'Username or email'
|
||||
requires :password, type: String, desc: 'Password'
|
||||
end
|
||||
post do
|
||||
user,last_logon = ::User.try_to_login(params[:login], params[:password])
|
||||
if user
|
||||
::ApiKey.delete_all(user_id: user.id)
|
||||
key = ::ApiKey.create!(user_id: user.id)
|
||||
api_user = ::UsersService.new.show_user({id:user.id})
|
||||
present :data, {token: key.access_token, user: api_user}, using: Entities::Auth
|
||||
present :status, 0
|
||||
else
|
||||
present :message, "无效的用户名或密码"
|
||||
present :status,1
|
||||
end
|
||||
end
|
||||
|
||||
desc "用户登出"
|
||||
params do
|
||||
requires :token, type: String
|
||||
end
|
||||
delete do
|
||||
authenticate!
|
||||
::ApiKey.delete_all(user_id: current_user.id)
|
||||
{status: 0}
|
||||
end
|
||||
|
||||
desc "忘记密码"
|
||||
params do
|
||||
requires :mail,type: String
|
||||
end
|
||||
post 'lost_password' do
|
||||
us = UsersService.new
|
||||
message = us.lost_password params
|
||||
present :message, message
|
||||
present :status, 0
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
|
|
@ -1,31 +1,31 @@
|
|||
#coding=utf-8
|
||||
|
||||
module Mobile
|
||||
module Apis
|
||||
class BlogComments< Grape::API
|
||||
resources :blog_comments do
|
||||
|
||||
desc "get special topic"
|
||||
post ':id' do
|
||||
begin
|
||||
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,type: type,page: page
|
||||
present :type, type
|
||||
present :page, page
|
||||
present :status, 0
|
||||
rescue Exception=>e
|
||||
present :status, -1
|
||||
present :message, e.message
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#coding=utf-8
|
||||
|
||||
module Mobile
|
||||
module Apis
|
||||
class BlogComments< Grape::API
|
||||
resources :blog_comments do
|
||||
|
||||
desc "get special topic"
|
||||
post ':id' do
|
||||
begin
|
||||
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,type: type,page: page
|
||||
present :type, type
|
||||
present :page, page
|
||||
present :status, 0
|
||||
rescue Exception=>e
|
||||
present :status, -1
|
||||
present :message, e.message
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,157 +1,157 @@
|
|||
#coding=utf-8
|
||||
|
||||
module Mobile
|
||||
module Apis
|
||||
class Homeworks < Grape::API
|
||||
|
||||
def self.get_service
|
||||
HomeworkService.new
|
||||
end
|
||||
|
||||
resources :homeworks do
|
||||
desc "作业详情"
|
||||
params do
|
||||
requires :id, type: Integer, desc: "作业ID"
|
||||
end
|
||||
route_param :id do
|
||||
get do
|
||||
homework = Homeworks.get_service.show_homework params
|
||||
present :data, homework, with: Mobile::Entities::Homework
|
||||
present :status, 0
|
||||
end
|
||||
end
|
||||
|
||||
desc "我的作品列表"
|
||||
params do
|
||||
requires :token, type: String
|
||||
end
|
||||
get ':user_id/homework_attachs' do
|
||||
ue = Homeworks.get_service.my_homework_list params,current_user.nil? ? User.find(2):current_user
|
||||
present :data, ue,with: Mobile::Entities::Course
|
||||
present :status, 0
|
||||
end
|
||||
|
||||
# desc "启动匿评"
|
||||
# params do
|
||||
# requires :token, type: String
|
||||
# end
|
||||
# post ':id/start_anonymous_comment' do
|
||||
# statue = Homeworks.get_service.start_anonymous_comment params,current_user.nil? ? User.find(2):current_user
|
||||
# messages = ""
|
||||
# case statue
|
||||
# when 1
|
||||
# messages = "启动成功"
|
||||
# when 2
|
||||
# messages = "启动失败,作业总数大于等于2份时才能启动匿评"
|
||||
# when 3
|
||||
# messages = "已开启匿评,请务重复开启"
|
||||
# end
|
||||
# present :data,messages
|
||||
# present :status, statue
|
||||
# end
|
||||
#
|
||||
# desc "关闭匿评"
|
||||
# params do
|
||||
# requires :token, type: String
|
||||
# end
|
||||
# post ':id/stop_anonymous_comment' do
|
||||
# Homeworks.get_service.stop_anonymous_comment params,current_user.nil? ? User.find(2):current_user
|
||||
# present :status, 0
|
||||
# end
|
||||
|
||||
desc "匿评作品详情"
|
||||
params do
|
||||
requires :token, type: String
|
||||
end
|
||||
get ':homework_id/anonymous_works_show' do
|
||||
works,par = Homeworks.get_service.anonymous_works_show params.merge(:id => params[:homework_id]),current_user.nil? ? User.find(2):current_user
|
||||
present :data, works ,with: Mobile::Entities::HomeworkAttach
|
||||
present :otherdata,par,with: Mobile::Entities::AnonymousWorksParams
|
||||
present :status, 0
|
||||
end
|
||||
|
||||
desc "作品打分"
|
||||
params do
|
||||
requires :token, type: String
|
||||
requires :is_teacher, type: String,desc: '是否为教师(匿评作品详情返回的结果中可获取此参数的值)'
|
||||
requires :is_anonymous_comments, type: String, desc: '是否为匿评(匿评作品详情返回的结果中可获取此参数的值)'
|
||||
optional :stars_value, type: Integer,desc: '用户给出的评分'
|
||||
optional :cur_page,type: Integer,desc: '匿评作品详情返回的结果中可获取此参数的值'
|
||||
optional :cur_type, type: Integer,desc: '匿评作品详情返回的结果中可获取此参数的值'
|
||||
optional :user_message, type: String, desc: '用户评论'
|
||||
end
|
||||
|
||||
post ':homework_id/scoring' do
|
||||
cs_params = {
|
||||
new_form: params.reject{|k,v| [:token,:is_teacher,:is_anonymous_comments,:stars_value,:cur_page,:cur_type,:homework_id].include?(k)},
|
||||
token: params[:token],
|
||||
is_teacher: params[:is_teacher],
|
||||
is_anonymous_comments: params[:is_anonymous_comments],
|
||||
stars_value: params[:stars_value],
|
||||
cur_page: params[:cur_page],
|
||||
cur_type: params[:cur_type],
|
||||
homework_id: params[:homework_id]
|
||||
}
|
||||
Homeworks.get_service.add_score_and_jour cs_params,current_user
|
||||
present :status, 0
|
||||
end
|
||||
|
||||
desc '创建作业'
|
||||
params do
|
||||
requires :token,type:String
|
||||
requires :work_name,type:String,desc:'作业名称'
|
||||
requires :work_desc,type:String,desc:'作业描述'
|
||||
requires :work_deadline,type:String,desc:'截止日期'
|
||||
requires :is_blind_appr,type:Integer,desc:'是否匿评'
|
||||
requires :blind_appr_num,type:Integer,desc:'匿评分配数'
|
||||
requires :course_id,type:Integer,desc: '课程id'
|
||||
end
|
||||
post 'create_home_work' do
|
||||
Homeworks.get_service.create_home_work params,current_user
|
||||
present :status, 0
|
||||
end
|
||||
|
||||
desc '开启匿评'
|
||||
params do
|
||||
requires :token,type:String
|
||||
requires :course_id,type:Integer,desc:'课程id'
|
||||
requires :homework_id,type:Integer,desc:'作业id'
|
||||
end
|
||||
post ':homework_id/start_anonymous_comment' do
|
||||
hs = Homeworks.get_service
|
||||
status = hs.start_anonymous_comment params,current_user
|
||||
messages = ""
|
||||
case status[:status]
|
||||
when 1
|
||||
messages = "启动成功"
|
||||
when 2
|
||||
messages = "启动失败,作业总数大于等于2份时才能启动匿评"
|
||||
when 3
|
||||
messages = "已开启匿评,请务重复开启"
|
||||
when 4
|
||||
messages = "没有开启匿评的权限"
|
||||
when 5
|
||||
messages = "截止日期之前不可启动匿评"
|
||||
end
|
||||
present :data,messages
|
||||
present :status,0
|
||||
end
|
||||
|
||||
desc '关闭匿评'
|
||||
params do
|
||||
requires :token,type:String
|
||||
requires :course_id,type:Integer,desc:'课程id'
|
||||
requires :homework_id,type:Integer,desc:'作业id'
|
||||
end
|
||||
post ':homework_id/stop_anonymous_comment' do
|
||||
hs = Homeworks.get_service
|
||||
hs.stop_anonymous_comment params,current_user
|
||||
message = "成功关闭"
|
||||
present :data, message
|
||||
present :status,0
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
#coding=utf-8
|
||||
|
||||
module Mobile
|
||||
module Apis
|
||||
class Homeworks < Grape::API
|
||||
|
||||
def self.get_service
|
||||
HomeworkService.new
|
||||
end
|
||||
|
||||
resources :homeworks do
|
||||
desc "作业详情"
|
||||
params do
|
||||
requires :id, type: Integer, desc: "作业ID"
|
||||
end
|
||||
route_param :id do
|
||||
get do
|
||||
homework = Homeworks.get_service.show_homework params
|
||||
present :data, homework, with: Mobile::Entities::Homework
|
||||
present :status, 0
|
||||
end
|
||||
end
|
||||
|
||||
desc "我的作品列表"
|
||||
params do
|
||||
requires :token, type: String
|
||||
end
|
||||
get ':user_id/homework_attachs' do
|
||||
ue = Homeworks.get_service.my_homework_list params,current_user.nil? ? User.find(2):current_user
|
||||
present :data, ue,with: Mobile::Entities::Course
|
||||
present :status, 0
|
||||
end
|
||||
|
||||
# desc "启动匿评"
|
||||
# params do
|
||||
# requires :token, type: String
|
||||
# end
|
||||
# post ':id/start_anonymous_comment' do
|
||||
# statue = Homeworks.get_service.start_anonymous_comment params,current_user.nil? ? User.find(2):current_user
|
||||
# messages = ""
|
||||
# case statue
|
||||
# when 1
|
||||
# messages = "启动成功"
|
||||
# when 2
|
||||
# messages = "启动失败,作业总数大于等于2份时才能启动匿评"
|
||||
# when 3
|
||||
# messages = "已开启匿评,请务重复开启"
|
||||
# end
|
||||
# present :data,messages
|
||||
# present :status, statue
|
||||
# end
|
||||
#
|
||||
# desc "关闭匿评"
|
||||
# params do
|
||||
# requires :token, type: String
|
||||
# end
|
||||
# post ':id/stop_anonymous_comment' do
|
||||
# Homeworks.get_service.stop_anonymous_comment params,current_user.nil? ? User.find(2):current_user
|
||||
# present :status, 0
|
||||
# end
|
||||
|
||||
desc "匿评作品详情"
|
||||
params do
|
||||
requires :token, type: String
|
||||
end
|
||||
get ':homework_id/anonymous_works_show' do
|
||||
works,par = Homeworks.get_service.anonymous_works_show params.merge(:id => params[:homework_id]),current_user.nil? ? User.find(2):current_user
|
||||
present :data, works ,with: Mobile::Entities::HomeworkAttach
|
||||
present :otherdata,par,with: Mobile::Entities::AnonymousWorksParams
|
||||
present :status, 0
|
||||
end
|
||||
|
||||
desc "作品打分"
|
||||
params do
|
||||
requires :token, type: String
|
||||
requires :is_teacher, type: String,desc: '是否为教师(匿评作品详情返回的结果中可获取此参数的值)'
|
||||
requires :is_anonymous_comments, type: String, desc: '是否为匿评(匿评作品详情返回的结果中可获取此参数的值)'
|
||||
optional :stars_value, type: Integer,desc: '用户给出的评分'
|
||||
optional :cur_page,type: Integer,desc: '匿评作品详情返回的结果中可获取此参数的值'
|
||||
optional :cur_type, type: Integer,desc: '匿评作品详情返回的结果中可获取此参数的值'
|
||||
optional :user_message, type: String, desc: '用户评论'
|
||||
end
|
||||
|
||||
post ':homework_id/scoring' do
|
||||
cs_params = {
|
||||
new_form: params.reject{|k,v| [:token,:is_teacher,:is_anonymous_comments,:stars_value,:cur_page,:cur_type,:homework_id].include?(k)},
|
||||
token: params[:token],
|
||||
is_teacher: params[:is_teacher],
|
||||
is_anonymous_comments: params[:is_anonymous_comments],
|
||||
stars_value: params[:stars_value],
|
||||
cur_page: params[:cur_page],
|
||||
cur_type: params[:cur_type],
|
||||
homework_id: params[:homework_id]
|
||||
}
|
||||
Homeworks.get_service.add_score_and_jour cs_params,current_user
|
||||
present :status, 0
|
||||
end
|
||||
|
||||
desc '创建作业'
|
||||
params do
|
||||
requires :token,type:String
|
||||
requires :work_name,type:String,desc:'作业名称'
|
||||
requires :work_desc,type:String,desc:'作业描述'
|
||||
requires :work_deadline,type:String,desc:'截止日期'
|
||||
requires :is_blind_appr,type:Integer,desc:'是否匿评'
|
||||
requires :blind_appr_num,type:Integer,desc:'匿评分配数'
|
||||
requires :course_id,type:Integer,desc: '课程id'
|
||||
end
|
||||
post 'create_home_work' do
|
||||
Homeworks.get_service.create_home_work params,current_user
|
||||
present :status, 0
|
||||
end
|
||||
|
||||
desc '开启匿评'
|
||||
params do
|
||||
requires :token,type:String
|
||||
requires :course_id,type:Integer,desc:'课程id'
|
||||
requires :homework_id,type:Integer,desc:'作业id'
|
||||
end
|
||||
post ':homework_id/start_anonymous_comment' do
|
||||
hs = Homeworks.get_service
|
||||
status = hs.start_anonymous_comment params,current_user
|
||||
messages = ""
|
||||
case status[:status]
|
||||
when 1
|
||||
messages = "启动成功"
|
||||
when 2
|
||||
messages = "启动失败,作业总数大于等于2份时才能启动匿评"
|
||||
when 3
|
||||
messages = "已开启匿评,请务重复开启"
|
||||
when 4
|
||||
messages = "没有开启匿评的权限"
|
||||
when 5
|
||||
messages = "截止日期之前不可启动匿评"
|
||||
end
|
||||
present :data,messages
|
||||
present :status,0
|
||||
end
|
||||
|
||||
desc '关闭匿评'
|
||||
params do
|
||||
requires :token,type:String
|
||||
requires :course_id,type:Integer,desc:'课程id'
|
||||
requires :homework_id,type:Integer,desc:'作业id'
|
||||
end
|
||||
post ':homework_id/stop_anonymous_comment' do
|
||||
hs = Homeworks.get_service
|
||||
hs.stop_anonymous_comment params,current_user
|
||||
message = "成功关闭"
|
||||
present :data, message
|
||||
present :status,0
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,321 +1,321 @@
|
|||
#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
|
||||
end
|
||||
post ':id' do
|
||||
unless current_user
|
||||
#如果当前用户不存在 则需要根据微信昵称注册一个帐号
|
||||
openid = session[:wechat_openid]
|
||||
raise "无法获取到openid,请在微信中打开本页面" unless openid
|
||||
us = UsersService.new
|
||||
|
||||
access_token = session[:access_token]
|
||||
refresh_token = session[:refresh_token]
|
||||
|
||||
if access_token.present? && refresh_token.present?
|
||||
begin
|
||||
refreshinfo = Wechat.api.web_refresh_access_token(refresh_token)
|
||||
rescue
|
||||
info = Wechat.api.web_access_token(session[:wechat_code])
|
||||
openid =info["openid"]
|
||||
access_token =info["access_token"]
|
||||
if access_token
|
||||
session[:access_token] = access_token
|
||||
end
|
||||
refresh_token = info["refresh_token"]
|
||||
if refresh_token
|
||||
session[:refresh_token] = refresh_token
|
||||
end
|
||||
refreshinfo = Wechat.api.web_refresh_access_token(refresh_token)
|
||||
end
|
||||
|
||||
access_token = refreshinfo["access_token"]
|
||||
refresh_token = refreshinfo["refresh_token"]
|
||||
session[:access_token] = access_token
|
||||
session[:refresh_token] = refresh_token
|
||||
|
||||
#获取用户信息
|
||||
userinfo = Wechat.api.web_userinfo(access_token,openid)
|
||||
Rails.logger.info "userinfo!!!!!!!!!"
|
||||
Rails.logger.info userinfo
|
||||
name = userinfo["nickname"]
|
||||
else
|
||||
name = openid[0..3]+"***"+openid.last
|
||||
end
|
||||
|
||||
user = us.register ({:login=>openid, :mail=>"#{openid}@163.com",
|
||||
:password=>"12345678", :password_confirmation=>"12345678",
|
||||
:should_confirmation_password => true})
|
||||
raise user.errors.full_messages.first if user.new_record?
|
||||
user.update_attributes(:lastname=>name)
|
||||
#自动激活
|
||||
if Setting.self_registration != '3'
|
||||
user.activate
|
||||
user.last_login_on = Time.now
|
||||
if user.save
|
||||
UserStatus.create(:user_id => user.id, :changsets_count => 0, :watchers_count => 0)
|
||||
end
|
||||
end
|
||||
UserWechat.create!(
|
||||
openid: openid,
|
||||
user: user,
|
||||
bindtype: 1
|
||||
)
|
||||
end
|
||||
|
||||
authenticate!
|
||||
|
||||
## 能进来的就是已关注
|
||||
## 因为取消订阅的记录被删除了
|
||||
subscribe = 1 #默认未关注
|
||||
|
||||
status = 0
|
||||
tip = 0 #0班级1项目
|
||||
type = params[:type]
|
||||
result = 1
|
||||
|
||||
#0回复 1回复的回复
|
||||
reply_type = params[:reply_type]
|
||||
|
||||
update_id = 0
|
||||
|
||||
if params[:content]!="" && current_user
|
||||
case type
|
||||
when "HomeworkCommon"
|
||||
#如果是私有的 并且不是成员则不能回复
|
||||
# is_public = homework_common.course.is_public
|
||||
# if is_public == 0 && !current_user.member_of_course?(homework_common.course)
|
||||
# status = -1
|
||||
# tip = 0
|
||||
# else
|
||||
# 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
|
||||
# end
|
||||
if reply_type == nil || reply_type == 0
|
||||
homework_common = HomeworkCommon.find(params[:id])
|
||||
feedback = HomeworkCommon.add_homework_jour(current_user, params[:content], params[:id], params[:id])
|
||||
if (feedback.errors.empty?)
|
||||
homework_common.update_column(:updated_at, Time.now)
|
||||
result = 2
|
||||
update_id = homework_common.id
|
||||
end
|
||||
else
|
||||
#二级回复
|
||||
reply = JournalsForMessage.find params[:id].to_i
|
||||
homework_common = HomeworkCommon.find reply.jour_id
|
||||
|
||||
options = {:notes => params[:content], :reply_id => reply.user_id,:user_id => current_user.id,:m_parent_id => params[:id].to_i,:m_reply_id => params[:id].to_i}
|
||||
feedback = HomeworkCommon.add_homework_jour(current_user, params[:content], reply.jour_id, reply.jour_id, options)
|
||||
if (feedback.errors.empty?)
|
||||
homework_common.update_column(:updated_at, Time.now)
|
||||
result = 2
|
||||
update_id = homework_common.id
|
||||
end
|
||||
end
|
||||
|
||||
when "News"
|
||||
# if news.project
|
||||
# if news.project.is_public == false && !current_user.member_of?(news.project)
|
||||
# status = -1
|
||||
# tip = 1
|
||||
# end
|
||||
# elsif news.course
|
||||
# if news.course.is_public == 0 && !current_user.member_of_course?(news.course)
|
||||
# status = -1
|
||||
# tip = 0
|
||||
# end
|
||||
# end
|
||||
if status == 0
|
||||
if reply_type == nil || reply_type == 0
|
||||
news = News.find(params[:id])
|
||||
comment = Comment.new
|
||||
comment.comments = params[:content]
|
||||
comment.author = current_user
|
||||
if news.comments << comment
|
||||
result = 2
|
||||
update_id = news.id
|
||||
end
|
||||
else
|
||||
#二级回复
|
||||
comment = Comment.find(params[:id])
|
||||
news = News.find comment.commented_id
|
||||
new_comment = news.comments.build(:author_id => current_user.id, :reply_id => params[:id], :comments => params[:content], :parent_id => comment.id)
|
||||
if new_comment.save
|
||||
result = 2
|
||||
update_id = news.id
|
||||
end
|
||||
end
|
||||
end
|
||||
when "Message"
|
||||
# if message.project
|
||||
# if message.project.is_public == false && !current_user.member_of?(message.project)
|
||||
# status = -1
|
||||
# tip = 1
|
||||
# end
|
||||
# elsif message.course
|
||||
# if message.course.is_public == 0 && !current_user.member_of_course?(message.course)
|
||||
# status = -1
|
||||
# tip = 0
|
||||
# end
|
||||
# end
|
||||
|
||||
if status == 0
|
||||
# if reply_type == nil || reply_type == 0
|
||||
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}"
|
||||
reply.root_id = topic.id
|
||||
if message.children << reply
|
||||
result = 2
|
||||
update_id = topic.id
|
||||
end
|
||||
# else
|
||||
#二级回复
|
||||
|
||||
# end
|
||||
end
|
||||
when "JournalsForMessage"
|
||||
# if jour.jour_type == "Project"
|
||||
# if jour.project.is_public == false && !current_user.member_of?(jour.project)
|
||||
# status = -1
|
||||
# tip = 1
|
||||
# end
|
||||
# elsif jour.jour_type == "Course"
|
||||
# if jour.course.is_public == 0 && !current_user.member_of_course?(jour.course)
|
||||
# status = -1
|
||||
# tip = 0
|
||||
# end
|
||||
# end
|
||||
|
||||
if status == 0
|
||||
# if reply_type == nil || reply_type == 0
|
||||
jour = JournalsForMessage.find(params[:id]).root
|
||||
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,
|
||||
:root_id => jour.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
|
||||
update_id = jour.id
|
||||
end
|
||||
# else
|
||||
#二级回复
|
||||
|
||||
# end
|
||||
end
|
||||
when 'Issue'
|
||||
# if issue.project.is_public == false && !current_user.member_of?(issue.project)
|
||||
# status = -1
|
||||
# tip = 1
|
||||
# end
|
||||
|
||||
if status == 0
|
||||
if reply_type == nil || reply_type == 0
|
||||
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
|
||||
update_id = issue.id
|
||||
end
|
||||
else
|
||||
#二级回复
|
||||
jour = Journal.find(params[:id])
|
||||
issue = jour.journalized
|
||||
is_jour = Journal.new
|
||||
is_jour.user_id = current_user.id
|
||||
is_jour.notes = params[:content]
|
||||
is_jour.reply_id = params[:id]
|
||||
is_jour.parent_id = params[:id]
|
||||
is_jour.journalized = issue
|
||||
if is_jour.save
|
||||
result = 2
|
||||
update_id = issue.id
|
||||
end
|
||||
end
|
||||
end
|
||||
when 'BlogComment'
|
||||
if reply_type == nil || reply_type == 0
|
||||
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}"
|
||||
blogComment.root_id = blog.id
|
||||
if blog.children << blogComment
|
||||
result = 2
|
||||
update_id = blog.id
|
||||
end
|
||||
else
|
||||
#二级回复
|
||||
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}"
|
||||
parent = BlogComment.find params[:id]
|
||||
blogComment.parent_id = params[:id] #被回复的回复
|
||||
blogComment.reply_id = parent.author.id #被回复者id
|
||||
blogComment.root_id = blog.id
|
||||
|
||||
if parent.children << blogComment
|
||||
result = 2
|
||||
update_id = blog.id
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
if result == 2
|
||||
update_course_activity_api(type,update_id)
|
||||
update_user_activity_api(type,update_id)
|
||||
update_org_activity_api(type,update_id)
|
||||
update_forge_activity_api(type,update_id)
|
||||
update_principal_activity_api(type,update_id)
|
||||
end
|
||||
else
|
||||
result = 3
|
||||
end
|
||||
present :result, result
|
||||
present :status, status
|
||||
present :act_id, update_id
|
||||
present :tip, tip
|
||||
present :subscribe,subscribe
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
#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
|
||||
end
|
||||
post ':id' do
|
||||
unless current_user
|
||||
#如果当前用户不存在 则需要根据微信昵称注册一个帐号
|
||||
openid = session[:wechat_openid]
|
||||
raise "无法获取到openid,请在微信中打开本页面" unless openid
|
||||
us = UsersService.new
|
||||
|
||||
access_token = session[:access_token]
|
||||
refresh_token = session[:refresh_token]
|
||||
|
||||
if access_token.present? && refresh_token.present?
|
||||
begin
|
||||
refreshinfo = Wechat.api.web_refresh_access_token(refresh_token)
|
||||
rescue
|
||||
info = Wechat.api.web_access_token(session[:wechat_code])
|
||||
openid =info["openid"]
|
||||
access_token =info["access_token"]
|
||||
if access_token
|
||||
session[:access_token] = access_token
|
||||
end
|
||||
refresh_token = info["refresh_token"]
|
||||
if refresh_token
|
||||
session[:refresh_token] = refresh_token
|
||||
end
|
||||
refreshinfo = Wechat.api.web_refresh_access_token(refresh_token)
|
||||
end
|
||||
|
||||
access_token = refreshinfo["access_token"]
|
||||
refresh_token = refreshinfo["refresh_token"]
|
||||
session[:access_token] = access_token
|
||||
session[:refresh_token] = refresh_token
|
||||
|
||||
#获取用户信息
|
||||
userinfo = Wechat.api.web_userinfo(access_token,openid)
|
||||
Rails.logger.info "userinfo!!!!!!!!!"
|
||||
Rails.logger.info userinfo
|
||||
name = userinfo["nickname"]
|
||||
else
|
||||
name = openid[0..3]+"***"+openid.last
|
||||
end
|
||||
|
||||
user = us.register ({:login=>openid, :mail=>"#{openid}@163.com",
|
||||
:password=>"12345678", :password_confirmation=>"12345678",
|
||||
:should_confirmation_password => true})
|
||||
raise user.errors.full_messages.first if user.new_record?
|
||||
user.update_attributes(:lastname=>name)
|
||||
#自动激活
|
||||
if Setting.self_registration != '3'
|
||||
user.activate
|
||||
user.last_login_on = Time.now
|
||||
if user.save
|
||||
UserStatus.create(:user_id => user.id, :changsets_count => 0, :watchers_count => 0)
|
||||
end
|
||||
end
|
||||
UserWechat.create!(
|
||||
openid: openid,
|
||||
user: user,
|
||||
bindtype: 1
|
||||
)
|
||||
end
|
||||
|
||||
authenticate!
|
||||
|
||||
## 能进来的就是已关注
|
||||
## 因为取消订阅的记录被删除了
|
||||
subscribe = 1 #默认未关注
|
||||
|
||||
status = 0
|
||||
tip = 0 #0班级1项目
|
||||
type = params[:type]
|
||||
result = 1
|
||||
|
||||
#0回复 1回复的回复
|
||||
reply_type = params[:reply_type]
|
||||
|
||||
update_id = 0
|
||||
|
||||
if params[:content]!="" && current_user
|
||||
case type
|
||||
when "HomeworkCommon"
|
||||
#如果是私有的 并且不是成员则不能回复
|
||||
# is_public = homework_common.course.is_public
|
||||
# if is_public == 0 && !current_user.member_of_course?(homework_common.course)
|
||||
# status = -1
|
||||
# tip = 0
|
||||
# else
|
||||
# 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
|
||||
# end
|
||||
if reply_type == nil || reply_type == 0
|
||||
homework_common = HomeworkCommon.find(params[:id])
|
||||
feedback = HomeworkCommon.add_homework_jour(current_user, params[:content], params[:id], params[:id])
|
||||
if (feedback.errors.empty?)
|
||||
homework_common.update_column(:updated_at, Time.now)
|
||||
result = 2
|
||||
update_id = homework_common.id
|
||||
end
|
||||
else
|
||||
#二级回复
|
||||
reply = JournalsForMessage.find params[:id].to_i
|
||||
homework_common = HomeworkCommon.find reply.jour_id
|
||||
|
||||
options = {:notes => params[:content], :reply_id => reply.user_id,:user_id => current_user.id,:m_parent_id => params[:id].to_i,:m_reply_id => params[:id].to_i}
|
||||
feedback = HomeworkCommon.add_homework_jour(current_user, params[:content], reply.jour_id, reply.jour_id, options)
|
||||
if (feedback.errors.empty?)
|
||||
homework_common.update_column(:updated_at, Time.now)
|
||||
result = 2
|
||||
update_id = homework_common.id
|
||||
end
|
||||
end
|
||||
|
||||
when "News"
|
||||
# if news.project
|
||||
# if news.project.is_public == false && !current_user.member_of?(news.project)
|
||||
# status = -1
|
||||
# tip = 1
|
||||
# end
|
||||
# elsif news.course
|
||||
# if news.course.is_public == 0 && !current_user.member_of_course?(news.course)
|
||||
# status = -1
|
||||
# tip = 0
|
||||
# end
|
||||
# end
|
||||
if status == 0
|
||||
if reply_type == nil || reply_type == 0
|
||||
news = News.find(params[:id])
|
||||
comment = Comment.new
|
||||
comment.comments = params[:content]
|
||||
comment.author = current_user
|
||||
if news.comments << comment
|
||||
result = 2
|
||||
update_id = news.id
|
||||
end
|
||||
else
|
||||
#二级回复
|
||||
comment = Comment.find(params[:id])
|
||||
news = News.find comment.commented_id
|
||||
new_comment = news.comments.build(:author_id => current_user.id, :reply_id => params[:id], :comments => params[:content], :parent_id => comment.id)
|
||||
if new_comment.save
|
||||
result = 2
|
||||
update_id = news.id
|
||||
end
|
||||
end
|
||||
end
|
||||
when "Message"
|
||||
# if message.project
|
||||
# if message.project.is_public == false && !current_user.member_of?(message.project)
|
||||
# status = -1
|
||||
# tip = 1
|
||||
# end
|
||||
# elsif message.course
|
||||
# if message.course.is_public == 0 && !current_user.member_of_course?(message.course)
|
||||
# status = -1
|
||||
# tip = 0
|
||||
# end
|
||||
# end
|
||||
|
||||
if status == 0
|
||||
# if reply_type == nil || reply_type == 0
|
||||
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}"
|
||||
reply.root_id = topic.id
|
||||
if message.children << reply
|
||||
result = 2
|
||||
update_id = topic.id
|
||||
end
|
||||
# else
|
||||
#二级回复
|
||||
|
||||
# end
|
||||
end
|
||||
when "JournalsForMessage"
|
||||
# if jour.jour_type == "Project"
|
||||
# if jour.project.is_public == false && !current_user.member_of?(jour.project)
|
||||
# status = -1
|
||||
# tip = 1
|
||||
# end
|
||||
# elsif jour.jour_type == "Course"
|
||||
# if jour.course.is_public == 0 && !current_user.member_of_course?(jour.course)
|
||||
# status = -1
|
||||
# tip = 0
|
||||
# end
|
||||
# end
|
||||
|
||||
if status == 0
|
||||
# if reply_type == nil || reply_type == 0
|
||||
jour = JournalsForMessage.find(params[:id]).root
|
||||
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,
|
||||
:root_id => jour.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
|
||||
update_id = jour.id
|
||||
end
|
||||
# else
|
||||
#二级回复
|
||||
|
||||
# end
|
||||
end
|
||||
when 'Issue'
|
||||
# if issue.project.is_public == false && !current_user.member_of?(issue.project)
|
||||
# status = -1
|
||||
# tip = 1
|
||||
# end
|
||||
|
||||
if status == 0
|
||||
if reply_type == nil || reply_type == 0
|
||||
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
|
||||
update_id = issue.id
|
||||
end
|
||||
else
|
||||
#二级回复
|
||||
jour = Journal.find(params[:id])
|
||||
issue = jour.journalized
|
||||
is_jour = Journal.new
|
||||
is_jour.user_id = current_user.id
|
||||
is_jour.notes = params[:content]
|
||||
is_jour.reply_id = params[:id]
|
||||
is_jour.parent_id = params[:id]
|
||||
is_jour.journalized = issue
|
||||
if is_jour.save
|
||||
result = 2
|
||||
update_id = issue.id
|
||||
end
|
||||
end
|
||||
end
|
||||
when 'BlogComment'
|
||||
if reply_type == nil || reply_type == 0
|
||||
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}"
|
||||
blogComment.root_id = blog.id
|
||||
if blog.children << blogComment
|
||||
result = 2
|
||||
update_id = blog.id
|
||||
end
|
||||
else
|
||||
#二级回复
|
||||
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}"
|
||||
parent = BlogComment.find params[:id]
|
||||
blogComment.parent_id = params[:id] #被回复的回复
|
||||
blogComment.reply_id = parent.author.id #被回复者id
|
||||
blogComment.root_id = blog.id
|
||||
|
||||
if parent.children << blogComment
|
||||
result = 2
|
||||
update_id = blog.id
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
if result == 2
|
||||
update_course_activity_api(type,update_id)
|
||||
update_user_activity_api(type,update_id)
|
||||
update_org_activity_api(type,update_id)
|
||||
update_forge_activity_api(type,update_id)
|
||||
update_principal_activity_api(type,update_id)
|
||||
end
|
||||
else
|
||||
result = 3
|
||||
end
|
||||
present :result, result
|
||||
present :status, status
|
||||
present :act_id, update_id
|
||||
present :tip, tip
|
||||
present :subscribe,subscribe
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,42 +1,42 @@
|
|||
#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 :token, type: String
|
||||
end
|
||||
post ':id' do
|
||||
authenticate!
|
||||
obj_id = params[:id]
|
||||
obj_type = params[:type]
|
||||
user = current_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
|
||||
#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 :token, type: String
|
||||
end
|
||||
post ':id' do
|
||||
authenticate!
|
||||
obj_id = params[:id]
|
||||
obj_type = params[:type]
|
||||
user = current_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
|
|
@ -1,350 +1,350 @@
|
|||
#coding=utf-8
|
||||
|
||||
module Mobile
|
||||
module Apis
|
||||
class Projects < Grape::API
|
||||
|
||||
resources :projects do
|
||||
desc "获取项目列表"
|
||||
params do
|
||||
requires :token, type: String
|
||||
end
|
||||
get do
|
||||
authenticate!
|
||||
|
||||
ps = ProjectsService.new
|
||||
projects = ps.user_projects(current_user)
|
||||
present :data, projects, with: Mobile::Entities::Project,user: current_user
|
||||
present :status, 0
|
||||
end
|
||||
|
||||
desc "返回单个项目"
|
||||
params do
|
||||
requires :id, type: Integer
|
||||
requires :token,type:String
|
||||
end
|
||||
route_param :id do
|
||||
get do
|
||||
# course = Course.find(params[:id])
|
||||
ps = ProjectsService.new
|
||||
project = ps.show_project(params,current_user)
|
||||
|
||||
if project[:status] == 9
|
||||
{status:-1, message: '该项目不存在或已被删除啦' }
|
||||
else
|
||||
present :data, project, with: Mobile::Entities::Project,user: current_user
|
||||
present :status, 0
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
desc "获取项目动态"
|
||||
params do
|
||||
requires :id, type: Integer
|
||||
requires :token, type: String
|
||||
end
|
||||
post 'activities' do
|
||||
authenticate!
|
||||
|
||||
user = current_user
|
||||
|
||||
project_types = "('Message','Issue','Project')"
|
||||
activities = UserActivity.where("(container_type = 'Project' and container_id = #{params[:id]} and act_type in #{project_types})").order('updated_at desc')
|
||||
|
||||
page = params[:page] ? params[:page] : 0
|
||||
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
|
||||
|
||||
desc "获取项目成员"
|
||||
params do
|
||||
requires :id, type: Integer
|
||||
requires :token, type: String
|
||||
end
|
||||
post 'members' do
|
||||
authenticate!
|
||||
|
||||
project = Project.find("#{params[:id]}")
|
||||
members = project.member_principals
|
||||
|
||||
master_members = project.member_principals.includes(:roles, :principal).where("member_roles.role_id=3").all.sort
|
||||
|
||||
master_members.each do |m|
|
||||
if m.user_id == project.user_id
|
||||
master_members.delete(m)
|
||||
master_members.insert(0,m)
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
develop_members = project.member_principals.includes(:roles, :principal).where("member_roles.role_id=4").all.sort
|
||||
report_members = project.member_principals.includes(:roles, :principal).where("member_roles.role_id=5").all.sort
|
||||
|
||||
review_master_members = []
|
||||
review_develop_members = []
|
||||
|
||||
my_member = project.member_principals.where("users.id=#{current_user.id}").first
|
||||
if my_member && my_member.roles[0] && my_member.roles[0].id == 3
|
||||
ps = ProjectsService.new
|
||||
|
||||
user = current_user
|
||||
review_master_members = ps.get_project_review_members(project,3,user)
|
||||
review_develop_members = ps.get_project_review_members(project,4,user)
|
||||
|
||||
end
|
||||
|
||||
present :master_members,master_members, with: Mobile::Entities::ProjectMember
|
||||
present :develop_members,develop_members, with: Mobile::Entities::ProjectMember
|
||||
present :report_members,report_members, with: Mobile::Entities::ProjectMember
|
||||
present :review_master_members,review_master_members
|
||||
present :review_develop_members,review_develop_members
|
||||
present :status, 0
|
||||
end
|
||||
|
||||
desc "获取项目某成员角色信息"
|
||||
params do
|
||||
requires :id, type: Integer
|
||||
requires :token, type: String
|
||||
requires :user_id, type: Integer
|
||||
end
|
||||
post 'get_member_info' do
|
||||
authenticate!
|
||||
|
||||
project = Project.find("#{params[:id]}")
|
||||
|
||||
my_member = project.member_principals.where("users.id=#{params[:user_id]}").first
|
||||
|
||||
if my_member && my_member.roles[0]
|
||||
present :project_id,params[:id]
|
||||
present :user_id,params[:user_id]
|
||||
present :member_info,my_member, with: Mobile::Entities::ProjectMember
|
||||
present :status, 0
|
||||
else
|
||||
present :status, -1
|
||||
present :message, "该用户已不在项目中"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
desc "修改项目某成员角色信息"
|
||||
params do
|
||||
requires :id, type: Integer
|
||||
requires :token, type: String
|
||||
requires :user_id, type: Integer
|
||||
requires :role_id, type: Integer
|
||||
end
|
||||
post 'edit_member_role' do
|
||||
authenticate!
|
||||
|
||||
project = Project.find("#{params[:id]}")
|
||||
|
||||
my_member = project.member_principals.where("users.id=#{current_user.id}").first
|
||||
|
||||
#3管理 4开发 5报告
|
||||
if !(my_member && my_member.roles[0] && my_member.roles[0].id == 3 ) || project.user_id == params[:user_id] || !(params[:role_id] == 3 || params[:role_id] == 4 || params[:role_id] == 5)
|
||||
present :status, -1
|
||||
else
|
||||
ps = ProjectsService.new
|
||||
|
||||
status = ps.modify_user_project_role params
|
||||
|
||||
present :status, status
|
||||
end
|
||||
end
|
||||
|
||||
desc "新建项目"
|
||||
params do
|
||||
requires :token, type: String
|
||||
requires :name, type: String, desc: '项目名称'
|
||||
end
|
||||
post 'create' do
|
||||
authenticate!
|
||||
|
||||
ps = ProjectsService.new
|
||||
|
||||
status = ps.createNewProject params,current_user
|
||||
|
||||
|
||||
present :status, 0
|
||||
|
||||
end
|
||||
|
||||
desc "加入项目"
|
||||
params do
|
||||
requires :token, type: String
|
||||
requires :invite_code, type: String, desc: '邀请码'
|
||||
requires :role_id, type: Integer, desc: '身份'
|
||||
end
|
||||
post "join_project" do
|
||||
authenticate!
|
||||
|
||||
role_id = params[:role_id]
|
||||
|
||||
if role_id != 3 && role_id != 4 && role_id != 5
|
||||
{status:-1,message:"请至少选择一个角色"}
|
||||
else
|
||||
ps = ProjectsService.new
|
||||
status = ps.join_project({role: role_id, openid: params[:openid], invite_code: params[:invite_code]}, current_user)
|
||||
|
||||
{status:status, message:ProjectsService::JoinProjectError.message(status)}
|
||||
end
|
||||
|
||||
# {status:-1, message: '该功能将在近日开放,敬请期待!' }
|
||||
end
|
||||
|
||||
desc "项目单个未审核用户信息"
|
||||
params do
|
||||
requires :token, type: String
|
||||
requires :project_id, type: Integer, desc: "项目id"
|
||||
requires :user_id, type: Integer, desc: "用户id"
|
||||
end
|
||||
post 'review_member_info' do
|
||||
authenticate!
|
||||
|
||||
ps = ProjectsService.new
|
||||
result = ps.get_reviewer_info(params,current_user)
|
||||
present :data, result[:reviewer], with: Mobile::Entities::User
|
||||
present :status, result[:status]
|
||||
end
|
||||
|
||||
desc "处理管理或开发的身份申请"
|
||||
params do
|
||||
requires :token, type: String
|
||||
requires :project_id, type: Integer, desc: "项目id"
|
||||
requires :user_id, type: Integer, desc: "用户id"
|
||||
requires :type, type: Integer, desc: "同意或拒绝"
|
||||
end
|
||||
post 'deal_join_apply' do
|
||||
authenticate!
|
||||
|
||||
ps = ProjectsService.new
|
||||
result = ps.deal_join_apply(params,current_user)
|
||||
|
||||
present :status, result[:status]
|
||||
present :message, result[:message]
|
||||
end
|
||||
|
||||
desc "发布项目帖子"
|
||||
params do
|
||||
requires :id, type: Integer
|
||||
requires :token, type: String
|
||||
requires :text, type: String
|
||||
end
|
||||
post ':id/publishnote' do
|
||||
authenticate!
|
||||
|
||||
project = Project.find("#{params[:id]}")
|
||||
|
||||
boards = project.boards.includes(:last_message => :author).all
|
||||
if project.boards.empty?
|
||||
board = project.boards.build
|
||||
board.name = "项目讨论区"
|
||||
board.description = project.name.to_s
|
||||
board.course_id = -1
|
||||
if board.save
|
||||
boards = project.boards.includes(:last_message => :author).all
|
||||
end
|
||||
end
|
||||
|
||||
board = boards.first
|
||||
|
||||
message = Message.new
|
||||
message.author = current_user
|
||||
message.board = board
|
||||
|
||||
tmpparams = {}
|
||||
tmpparams['subject'] = params[:title]
|
||||
tmpparams['content'] = params[:text]
|
||||
|
||||
message.safe_attributes = tmpparams
|
||||
|
||||
message.save!
|
||||
|
||||
present :status, 0
|
||||
|
||||
end
|
||||
|
||||
desc "删除项目成员"
|
||||
params do
|
||||
requires :id, type: Integer
|
||||
requires :token, type: String
|
||||
requires :user_id, type: Integer
|
||||
end
|
||||
post ':id/deletemember' do
|
||||
authenticate!
|
||||
|
||||
status = -1
|
||||
|
||||
if(current_user.id != params[:user_id].to_i)
|
||||
#权限
|
||||
project = Project.find("#{params[:id]}")
|
||||
if project.user_id != params[:user_id].to_i
|
||||
|
||||
my_member = project.member_principals.where("users.id=#{current_user.id}").first
|
||||
|
||||
roles_ids = []
|
||||
my_member.roles.each do |role|
|
||||
roles_ids << role.id
|
||||
end
|
||||
|
||||
if my_member && roles_ids.include?(3)
|
||||
#删除该成员
|
||||
ps = ProjectsService.new
|
||||
status = ps.project_delete_member(project,params[:user_id].to_i,current_user)
|
||||
else
|
||||
status = -2
|
||||
end
|
||||
else
|
||||
status = -3
|
||||
end
|
||||
else
|
||||
status = -4
|
||||
end
|
||||
|
||||
out = {status: status}
|
||||
message = case status
|
||||
when 0; "删除成功"
|
||||
when 1; "该用户不在该项目中"
|
||||
when -1; "您还未登录"
|
||||
when -2; "您没有权限"
|
||||
when -3; "不能删除项目创建者"
|
||||
when -4; "不能删除自己"
|
||||
else; "未知错误,请稍后再试"
|
||||
end
|
||||
out.merge(message: message)
|
||||
end
|
||||
|
||||
desc "退出项目"
|
||||
params do
|
||||
requires :id, type: Integer
|
||||
requires :token, type: String
|
||||
end
|
||||
post ':id/quit' do
|
||||
authenticate!
|
||||
|
||||
project = Project.find("#{params[:id]}")
|
||||
|
||||
ps = ProjectsService.new
|
||||
status = ps.exit_project(project,current_user)
|
||||
|
||||
out = {status: status}
|
||||
message = case status
|
||||
when 0; "退出项目成功"
|
||||
when -3; "您不是该项目成员"
|
||||
when -1; "您还未登录"
|
||||
when -2; "项目创建者不能退出项目"
|
||||
else; "未知错误,请稍后再试"
|
||||
end
|
||||
out.merge(message: message)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
#coding=utf-8
|
||||
|
||||
module Mobile
|
||||
module Apis
|
||||
class Projects < Grape::API
|
||||
|
||||
resources :projects do
|
||||
desc "获取项目列表"
|
||||
params do
|
||||
requires :token, type: String
|
||||
end
|
||||
get do
|
||||
authenticate!
|
||||
|
||||
ps = ProjectsService.new
|
||||
projects = ps.user_projects(current_user)
|
||||
present :data, projects, with: Mobile::Entities::Project,user: current_user
|
||||
present :status, 0
|
||||
end
|
||||
|
||||
desc "返回单个项目"
|
||||
params do
|
||||
requires :id, type: Integer
|
||||
requires :token,type:String
|
||||
end
|
||||
route_param :id do
|
||||
get do
|
||||
# course = Course.find(params[:id])
|
||||
ps = ProjectsService.new
|
||||
project = ps.show_project(params,current_user)
|
||||
|
||||
if project[:status] == 9
|
||||
{status:-1, message: '该项目不存在或已被删除啦' }
|
||||
else
|
||||
present :data, project, with: Mobile::Entities::Project,user: current_user
|
||||
present :status, 0
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
desc "获取项目动态"
|
||||
params do
|
||||
requires :id, type: Integer
|
||||
requires :token, type: String
|
||||
end
|
||||
post 'activities' do
|
||||
authenticate!
|
||||
|
||||
user = current_user
|
||||
|
||||
project_types = "('Message','Issue','Project')"
|
||||
activities = UserActivity.where("(container_type = 'Project' and container_id = #{params[:id]} and act_type in #{project_types})").order('updated_at desc')
|
||||
|
||||
page = params[:page] ? params[:page] : 0
|
||||
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
|
||||
|
||||
desc "获取项目成员"
|
||||
params do
|
||||
requires :id, type: Integer
|
||||
requires :token, type: String
|
||||
end
|
||||
post 'members' do
|
||||
authenticate!
|
||||
|
||||
project = Project.find("#{params[:id]}")
|
||||
members = project.member_principals
|
||||
|
||||
master_members = project.member_principals.includes(:roles, :principal).where("member_roles.role_id=3").all.sort
|
||||
|
||||
master_members.each do |m|
|
||||
if m.user_id == project.user_id
|
||||
master_members.delete(m)
|
||||
master_members.insert(0,m)
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
develop_members = project.member_principals.includes(:roles, :principal).where("member_roles.role_id=4").all.sort
|
||||
report_members = project.member_principals.includes(:roles, :principal).where("member_roles.role_id=5").all.sort
|
||||
|
||||
review_master_members = []
|
||||
review_develop_members = []
|
||||
|
||||
my_member = project.member_principals.where("users.id=#{current_user.id}").first
|
||||
if my_member && my_member.roles[0] && my_member.roles[0].id == 3
|
||||
ps = ProjectsService.new
|
||||
|
||||
user = current_user
|
||||
review_master_members = ps.get_project_review_members(project,3,user)
|
||||
review_develop_members = ps.get_project_review_members(project,4,user)
|
||||
|
||||
end
|
||||
|
||||
present :master_members,master_members, with: Mobile::Entities::ProjectMember
|
||||
present :develop_members,develop_members, with: Mobile::Entities::ProjectMember
|
||||
present :report_members,report_members, with: Mobile::Entities::ProjectMember
|
||||
present :review_master_members,review_master_members
|
||||
present :review_develop_members,review_develop_members
|
||||
present :status, 0
|
||||
end
|
||||
|
||||
desc "获取项目某成员角色信息"
|
||||
params do
|
||||
requires :id, type: Integer
|
||||
requires :token, type: String
|
||||
requires :user_id, type: Integer
|
||||
end
|
||||
post 'get_member_info' do
|
||||
authenticate!
|
||||
|
||||
project = Project.find("#{params[:id]}")
|
||||
|
||||
my_member = project.member_principals.where("users.id=#{params[:user_id]}").first
|
||||
|
||||
if my_member && my_member.roles[0]
|
||||
present :project_id,params[:id]
|
||||
present :user_id,params[:user_id]
|
||||
present :member_info,my_member, with: Mobile::Entities::ProjectMember
|
||||
present :status, 0
|
||||
else
|
||||
present :status, -1
|
||||
present :message, "该用户已不在项目中"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
desc "修改项目某成员角色信息"
|
||||
params do
|
||||
requires :id, type: Integer
|
||||
requires :token, type: String
|
||||
requires :user_id, type: Integer
|
||||
requires :role_id, type: Integer
|
||||
end
|
||||
post 'edit_member_role' do
|
||||
authenticate!
|
||||
|
||||
project = Project.find("#{params[:id]}")
|
||||
|
||||
my_member = project.member_principals.where("users.id=#{current_user.id}").first
|
||||
|
||||
#3管理 4开发 5报告
|
||||
if !(my_member && my_member.roles[0] && my_member.roles[0].id == 3 ) || project.user_id == params[:user_id] || !(params[:role_id] == 3 || params[:role_id] == 4 || params[:role_id] == 5)
|
||||
present :status, -1
|
||||
else
|
||||
ps = ProjectsService.new
|
||||
|
||||
status = ps.modify_user_project_role params
|
||||
|
||||
present :status, status
|
||||
end
|
||||
end
|
||||
|
||||
desc "新建项目"
|
||||
params do
|
||||
requires :token, type: String
|
||||
requires :name, type: String, desc: '项目名称'
|
||||
end
|
||||
post 'create' do
|
||||
authenticate!
|
||||
|
||||
ps = ProjectsService.new
|
||||
|
||||
status = ps.createNewProject params,current_user
|
||||
|
||||
|
||||
present :status, 0
|
||||
|
||||
end
|
||||
|
||||
desc "加入项目"
|
||||
params do
|
||||
requires :token, type: String
|
||||
requires :invite_code, type: String, desc: '邀请码'
|
||||
requires :role_id, type: Integer, desc: '身份'
|
||||
end
|
||||
post "join_project" do
|
||||
authenticate!
|
||||
|
||||
role_id = params[:role_id]
|
||||
|
||||
if role_id != 3 && role_id != 4 && role_id != 5
|
||||
{status:-1,message:"请至少选择一个角色"}
|
||||
else
|
||||
ps = ProjectsService.new
|
||||
status = ps.join_project({role: role_id, openid: params[:openid], invite_code: params[:invite_code]}, current_user)
|
||||
|
||||
{status:status, message:ProjectsService::JoinProjectError.message(status)}
|
||||
end
|
||||
|
||||
# {status:-1, message: '该功能将在近日开放,敬请期待!' }
|
||||
end
|
||||
|
||||
desc "项目单个未审核用户信息"
|
||||
params do
|
||||
requires :token, type: String
|
||||
requires :project_id, type: Integer, desc: "项目id"
|
||||
requires :user_id, type: Integer, desc: "用户id"
|
||||
end
|
||||
post 'review_member_info' do
|
||||
authenticate!
|
||||
|
||||
ps = ProjectsService.new
|
||||
result = ps.get_reviewer_info(params,current_user)
|
||||
present :data, result[:reviewer], with: Mobile::Entities::User
|
||||
present :status, result[:status]
|
||||
end
|
||||
|
||||
desc "处理管理或开发的身份申请"
|
||||
params do
|
||||
requires :token, type: String
|
||||
requires :project_id, type: Integer, desc: "项目id"
|
||||
requires :user_id, type: Integer, desc: "用户id"
|
||||
requires :type, type: Integer, desc: "同意或拒绝"
|
||||
end
|
||||
post 'deal_join_apply' do
|
||||
authenticate!
|
||||
|
||||
ps = ProjectsService.new
|
||||
result = ps.deal_join_apply(params,current_user)
|
||||
|
||||
present :status, result[:status]
|
||||
present :message, result[:message]
|
||||
end
|
||||
|
||||
desc "发布项目帖子"
|
||||
params do
|
||||
requires :id, type: Integer
|
||||
requires :token, type: String
|
||||
requires :text, type: String
|
||||
end
|
||||
post ':id/publishnote' do
|
||||
authenticate!
|
||||
|
||||
project = Project.find("#{params[:id]}")
|
||||
|
||||
boards = project.boards.includes(:last_message => :author).all
|
||||
if project.boards.empty?
|
||||
board = project.boards.build
|
||||
board.name = "项目讨论区"
|
||||
board.description = project.name.to_s
|
||||
board.course_id = -1
|
||||
if board.save
|
||||
boards = project.boards.includes(:last_message => :author).all
|
||||
end
|
||||
end
|
||||
|
||||
board = boards.first
|
||||
|
||||
message = Message.new
|
||||
message.author = current_user
|
||||
message.board = board
|
||||
|
||||
tmpparams = {}
|
||||
tmpparams['subject'] = params[:title]
|
||||
tmpparams['content'] = params[:text]
|
||||
|
||||
message.safe_attributes = tmpparams
|
||||
|
||||
message.save!
|
||||
|
||||
present :status, 0
|
||||
|
||||
end
|
||||
|
||||
desc "删除项目成员"
|
||||
params do
|
||||
requires :id, type: Integer
|
||||
requires :token, type: String
|
||||
requires :user_id, type: Integer
|
||||
end
|
||||
post ':id/deletemember' do
|
||||
authenticate!
|
||||
|
||||
status = -1
|
||||
|
||||
if(current_user.id != params[:user_id].to_i)
|
||||
#权限
|
||||
project = Project.find("#{params[:id]}")
|
||||
if project.user_id != params[:user_id].to_i
|
||||
|
||||
my_member = project.member_principals.where("users.id=#{current_user.id}").first
|
||||
|
||||
roles_ids = []
|
||||
my_member.roles.each do |role|
|
||||
roles_ids << role.id
|
||||
end
|
||||
|
||||
if my_member && roles_ids.include?(3)
|
||||
#删除该成员
|
||||
ps = ProjectsService.new
|
||||
status = ps.project_delete_member(project,params[:user_id].to_i,current_user)
|
||||
else
|
||||
status = -2
|
||||
end
|
||||
else
|
||||
status = -3
|
||||
end
|
||||
else
|
||||
status = -4
|
||||
end
|
||||
|
||||
out = {status: status}
|
||||
message = case status
|
||||
when 0; "删除成功"
|
||||
when 1; "该用户不在该项目中"
|
||||
when -1; "您还未登录"
|
||||
when -2; "您没有权限"
|
||||
when -3; "不能删除项目创建者"
|
||||
when -4; "不能删除自己"
|
||||
else; "未知错误,请稍后再试"
|
||||
end
|
||||
out.merge(message: message)
|
||||
end
|
||||
|
||||
desc "退出项目"
|
||||
params do
|
||||
requires :id, type: Integer
|
||||
requires :token, type: String
|
||||
end
|
||||
post ':id/quit' do
|
||||
authenticate!
|
||||
|
||||
project = Project.find("#{params[:id]}")
|
||||
|
||||
ps = ProjectsService.new
|
||||
status = ps.exit_project(project,current_user)
|
||||
|
||||
out = {status: status}
|
||||
message = case status
|
||||
when 0; "退出项目成功"
|
||||
when -3; "您不是该项目成员"
|
||||
when -1; "您还未登录"
|
||||
when -2; "项目创建者不能退出项目"
|
||||
else; "未知错误,请稍后再试"
|
||||
end
|
||||
out.merge(message: message)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,119 +1,119 @@
|
|||
#coding=utf-8
|
||||
module Mobile
|
||||
module Apis
|
||||
class Resources < Grape::API
|
||||
|
||||
resource :resources do
|
||||
|
||||
desc '获取所有课件'
|
||||
params do
|
||||
requires :token, type: String
|
||||
requires :page, type: Integer
|
||||
end
|
||||
post do
|
||||
authenticate!
|
||||
page = params[:page] ? params[:page] : 0
|
||||
|
||||
rs = ResourcesService.new
|
||||
# data = current_user.course_attachments
|
||||
data = rs.all_course_attachments current_user
|
||||
all_count = data.count
|
||||
data = data.limit(10).offset(page * 10)
|
||||
count = data.count
|
||||
|
||||
present :data, data, with: Mobile::Entities::Attachment,user: current_user
|
||||
present :all_count, all_count
|
||||
present :count, count
|
||||
present :page, page
|
||||
present :status, 0
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
desc '获取所有作业'
|
||||
params do
|
||||
requires :token, type: String
|
||||
requires :page, type: Integer
|
||||
end
|
||||
post 'homeworks' do
|
||||
authenticate!
|
||||
|
||||
page = params[:page] ? params[:page] : 0
|
||||
|
||||
rs = ResourcesService.new
|
||||
homeworks = rs.all_homework_commons current_user
|
||||
|
||||
all_count = homeworks.count
|
||||
homeworks = homeworks.limit(10).offset(page * 10)
|
||||
count = homeworks.count
|
||||
|
||||
present :data, homeworks, with: Mobile::Entities::Homework,user: current_user
|
||||
present :all_count, all_count
|
||||
present :count, count
|
||||
present :page, page
|
||||
present :status, 0
|
||||
|
||||
end
|
||||
|
||||
desc '获取所有测验'
|
||||
params do
|
||||
requires :token, type: String
|
||||
requires :page, type: Integer
|
||||
end
|
||||
post 'exercises' do
|
||||
authenticate!
|
||||
|
||||
page = params[:page] ? params[:page] : 0
|
||||
|
||||
rs = ResourcesService.new
|
||||
exercises = rs.all_exercises current_user
|
||||
all_count = exercises.count
|
||||
exercises = exercises.limit(10).offset(page * 10)
|
||||
count = exercises.count
|
||||
|
||||
present :data, exercises, with: Mobile::Entities::Exercise,user: current_user
|
||||
present :all_count, all_count
|
||||
present :count, count
|
||||
present :page, page
|
||||
present :status, 0
|
||||
end
|
||||
|
||||
|
||||
desc '发送资源'
|
||||
params do
|
||||
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 = 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
|
||||
{status: -1, message: save_message.first}
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
#coding=utf-8
|
||||
module Mobile
|
||||
module Apis
|
||||
class Resources < Grape::API
|
||||
|
||||
resource :resources do
|
||||
|
||||
desc '获取所有课件'
|
||||
params do
|
||||
requires :token, type: String
|
||||
requires :page, type: Integer
|
||||
end
|
||||
post do
|
||||
authenticate!
|
||||
page = params[:page] ? params[:page] : 0
|
||||
|
||||
rs = ResourcesService.new
|
||||
# data = current_user.course_attachments
|
||||
data = rs.all_course_attachments current_user
|
||||
all_count = data.count
|
||||
data = data.limit(10).offset(page * 10)
|
||||
count = data.count
|
||||
|
||||
present :data, data, with: Mobile::Entities::Attachment,user: current_user
|
||||
present :all_count, all_count
|
||||
present :count, count
|
||||
present :page, page
|
||||
present :status, 0
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
desc '获取所有作业'
|
||||
params do
|
||||
requires :token, type: String
|
||||
requires :page, type: Integer
|
||||
end
|
||||
post 'homeworks' do
|
||||
authenticate!
|
||||
|
||||
page = params[:page] ? params[:page] : 0
|
||||
|
||||
rs = ResourcesService.new
|
||||
homeworks = rs.all_homework_commons current_user
|
||||
|
||||
all_count = homeworks.count
|
||||
homeworks = homeworks.limit(10).offset(page * 10)
|
||||
count = homeworks.count
|
||||
|
||||
present :data, homeworks, with: Mobile::Entities::Homework,user: current_user
|
||||
present :all_count, all_count
|
||||
present :count, count
|
||||
present :page, page
|
||||
present :status, 0
|
||||
|
||||
end
|
||||
|
||||
desc '获取所有测验'
|
||||
params do
|
||||
requires :token, type: String
|
||||
requires :page, type: Integer
|
||||
end
|
||||
post 'exercises' do
|
||||
authenticate!
|
||||
|
||||
page = params[:page] ? params[:page] : 0
|
||||
|
||||
rs = ResourcesService.new
|
||||
exercises = rs.all_exercises current_user
|
||||
all_count = exercises.count
|
||||
exercises = exercises.limit(10).offset(page * 10)
|
||||
count = exercises.count
|
||||
|
||||
present :data, exercises, with: Mobile::Entities::Exercise,user: current_user
|
||||
present :all_count, all_count
|
||||
present :count, count
|
||||
present :page, page
|
||||
present :status, 0
|
||||
end
|
||||
|
||||
|
||||
desc '发送资源'
|
||||
params do
|
||||
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 = 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
|
||||
{status: -1, message: save_message.first}
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,103 +1,103 @@
|
|||
#coding=utf-8
|
||||
|
||||
module Mobile
|
||||
module Apis
|
||||
class Syllabuses < Grape::API
|
||||
|
||||
resources :syllabuses do
|
||||
desc "获取大纲列表"
|
||||
params do
|
||||
requires :token, type: String
|
||||
end
|
||||
get do
|
||||
authenticate!
|
||||
|
||||
cs = SyllabusesService.new
|
||||
courses = cs.user_syllabus(current_user)
|
||||
present :data, courses, with: Mobile::Entities::Syllabus,user: current_user
|
||||
present :status, 0
|
||||
end
|
||||
|
||||
desc "获取某个大纲"
|
||||
params do
|
||||
requires :token, type: String
|
||||
end
|
||||
get ':id' do
|
||||
authenticate!
|
||||
|
||||
ss = SyllabusesService.new
|
||||
|
||||
sy = ::Syllabus.find(params[:id])
|
||||
|
||||
result = {:title=>sy.title, :id=>sy.id , :user_id=>sy.user_id,:courses=>sy.courses.not_deleted}
|
||||
|
||||
present :data, result, with: Mobile::Entities::Syllabus,user: current_user
|
||||
present :status, 0
|
||||
end
|
||||
|
||||
desc "获取新建大纲的权限"
|
||||
params do
|
||||
requires :token, type: String
|
||||
end
|
||||
post 'auth' do
|
||||
authenticate!
|
||||
|
||||
auth = 0
|
||||
|
||||
if (current_user.user_extensions && current_user.user_extensions.identity == 0 && current_user.allowed_to?(:add_course, nil, :global => true))
|
||||
auth = 1
|
||||
end
|
||||
|
||||
present :auth, auth
|
||||
end
|
||||
|
||||
desc "新建大纲"
|
||||
params do
|
||||
requires :token, type: String
|
||||
requires :title, type: String, desc: '大纲标题'
|
||||
requires :courses, type: Array[String], desc: '课程名'
|
||||
end
|
||||
post do
|
||||
authenticate!
|
||||
|
||||
ss = SyllabusesService.new
|
||||
|
||||
sy = ss.create(current_user, params[:title],
|
||||
params[:courses].map{|c| {name: c} })
|
||||
|
||||
if sy.new_record?
|
||||
{status:-1, message: '创建大纲失败' }
|
||||
else
|
||||
present :data, sy, with: Mobile::Entities::Syllabus,user: current_user
|
||||
present :status, 0
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
desc '编辑大纲'
|
||||
params do
|
||||
requires :token, type: String
|
||||
requires :title, type: String, desc: '大纲标题'
|
||||
# requires :add_courses, type: Array[String], desc: '课程名'
|
||||
# requires :modify_courses, type: Array[Integer,String], desc: '课程名'
|
||||
end
|
||||
post ':id/edit' do
|
||||
|
||||
authenticate!
|
||||
|
||||
ss = SyllabusesService.new
|
||||
|
||||
#修改课程大纲
|
||||
status = ss.edit(current_user, params)
|
||||
|
||||
if status == -1
|
||||
{status:status, message: '修改课程信息失败' }
|
||||
else
|
||||
present :status, status
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
#coding=utf-8
|
||||
|
||||
module Mobile
|
||||
module Apis
|
||||
class Syllabuses < Grape::API
|
||||
|
||||
resources :syllabuses do
|
||||
desc "获取大纲列表"
|
||||
params do
|
||||
requires :token, type: String
|
||||
end
|
||||
get do
|
||||
authenticate!
|
||||
|
||||
cs = SyllabusesService.new
|
||||
courses = cs.user_syllabus(current_user)
|
||||
present :data, courses, with: Mobile::Entities::Syllabus,user: current_user
|
||||
present :status, 0
|
||||
end
|
||||
|
||||
desc "获取某个大纲"
|
||||
params do
|
||||
requires :token, type: String
|
||||
end
|
||||
get ':id' do
|
||||
authenticate!
|
||||
|
||||
ss = SyllabusesService.new
|
||||
|
||||
sy = ::Syllabus.find(params[:id])
|
||||
|
||||
result = {:title=>sy.title, :id=>sy.id , :user_id=>sy.user_id,:courses=>sy.courses.not_deleted}
|
||||
|
||||
present :data, result, with: Mobile::Entities::Syllabus,user: current_user
|
||||
present :status, 0
|
||||
end
|
||||
|
||||
desc "获取新建大纲的权限"
|
||||
params do
|
||||
requires :token, type: String
|
||||
end
|
||||
post 'auth' do
|
||||
authenticate!
|
||||
|
||||
auth = 0
|
||||
|
||||
if (current_user.user_extensions && current_user.user_extensions.identity == 0 && current_user.allowed_to?(:add_course, nil, :global => true))
|
||||
auth = 1
|
||||
end
|
||||
|
||||
present :auth, auth
|
||||
end
|
||||
|
||||
desc "新建大纲"
|
||||
params do
|
||||
requires :token, type: String
|
||||
requires :title, type: String, desc: '大纲标题'
|
||||
requires :courses, type: Array[String], desc: '课程名'
|
||||
end
|
||||
post do
|
||||
authenticate!
|
||||
|
||||
ss = SyllabusesService.new
|
||||
|
||||
sy = ss.create(current_user, params[:title],
|
||||
params[:courses].map{|c| {name: c} })
|
||||
|
||||
if sy.new_record?
|
||||
{status:-1, message: '创建大纲失败' }
|
||||
else
|
||||
present :data, sy, with: Mobile::Entities::Syllabus,user: current_user
|
||||
present :status, 0
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
desc '编辑大纲'
|
||||
params do
|
||||
requires :token, type: String
|
||||
requires :title, type: String, desc: '大纲标题'
|
||||
# requires :add_courses, type: Array[String], desc: '课程名'
|
||||
# requires :modify_courses, type: Array[Integer,String], desc: '课程名'
|
||||
end
|
||||
post ':id/edit' do
|
||||
|
||||
authenticate!
|
||||
|
||||
ss = SyllabusesService.new
|
||||
|
||||
#修改课程大纲
|
||||
status = ss.edit(current_user, params)
|
||||
|
||||
if status == -1
|
||||
{status:status, message: '修改课程信息失败' }
|
||||
else
|
||||
present :status, status
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,29 +1,29 @@
|
|||
#coding=utf-8
|
||||
|
||||
module Mobile
|
||||
module Apis
|
||||
class Upgrade < Grape::API
|
||||
include ApplicationHelper
|
||||
resource :upgrade do
|
||||
desc "get update info"
|
||||
params do
|
||||
requires :platform, type: String, desc: '平台名,android, ios'
|
||||
end
|
||||
get do
|
||||
@current_version = ::PhoneAppVersion.reorder('created_at desc').first
|
||||
attachment = @current_version.attachments.first
|
||||
if attachment.nil?
|
||||
raise '未发现客户端!'
|
||||
end
|
||||
url = "http://" + Setting.host_name + "/attachments/download/" + attachment.id.to_s + "/" + attachment.filename
|
||||
{
|
||||
version: @current_version.version,
|
||||
url: url,
|
||||
desc: @current_version.description
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
#coding=utf-8
|
||||
|
||||
module Mobile
|
||||
module Apis
|
||||
class Upgrade < Grape::API
|
||||
include ApplicationHelper
|
||||
resource :upgrade do
|
||||
desc "get update info"
|
||||
params do
|
||||
requires :platform, type: String, desc: '平台名,android, ios'
|
||||
end
|
||||
get do
|
||||
@current_version = ::PhoneAppVersion.reorder('created_at desc').first
|
||||
attachment = @current_version.attachments.first
|
||||
if attachment.nil?
|
||||
raise '未发现客户端!'
|
||||
end
|
||||
url = "http://" + Setting.host_name + "/attachments/download/" + attachment.id.to_s + "/" + attachment.filename
|
||||
{
|
||||
version: @current_version.version,
|
||||
url: url,
|
||||
desc: @current_version.description
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,320 +1,320 @@
|
|||
#coding=utf-8
|
||||
module Mobile
|
||||
module Apis
|
||||
class Users < Grape::API
|
||||
resource :users do
|
||||
|
||||
desc "我的资料"
|
||||
params do
|
||||
requires :token, type: String
|
||||
end
|
||||
|
||||
get 'get_userinfo' do
|
||||
authenticate!
|
||||
present :data, current_user, with: Mobile::Entities::User
|
||||
present :status, 0
|
||||
end
|
||||
|
||||
desc "上传头像"
|
||||
params do
|
||||
requires :token, type: String
|
||||
requires :imgdata, type: String
|
||||
end
|
||||
|
||||
post 'upload_head' do
|
||||
authenticate!
|
||||
#直接生成头像
|
||||
dirPath = "public/images/avatars/User"
|
||||
|
||||
fileDir = dirPath + "/"+current_user.id.to_s
|
||||
imgdata = Base64.decode64(params[:imgdata].split(",")[1])
|
||||
if imgdata.length > 1024*1024
|
||||
present :message,"上传图片不能超过1M"
|
||||
present :status, -1
|
||||
else
|
||||
begin
|
||||
File.open(fileDir,'wb'){ |f| f.write(imgdata) }
|
||||
present :status, 0
|
||||
rescue
|
||||
present :message,"上传失败"
|
||||
present :status, -1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
desc "解除绑定"
|
||||
params do
|
||||
requires :token, type: String
|
||||
end
|
||||
|
||||
post 'user_unbind' do
|
||||
authenticate!
|
||||
|
||||
user = current_user
|
||||
uw = user.user_wechat
|
||||
|
||||
us = UsersService.new
|
||||
us.wechat_unbind user.user_wechat
|
||||
|
||||
present :status, 0
|
||||
end
|
||||
|
||||
desc "查询是否已绑定"
|
||||
params do
|
||||
requires :openid, type: String, desc: 'wechat openid'
|
||||
end
|
||||
post 'isbind' do
|
||||
openid = params[:openid]
|
||||
uw = UserWechat.where(openid: openid).first
|
||||
raise "还未绑定trustie帐户" unless uw
|
||||
|
||||
user = uw.user
|
||||
::ApiKey.delete_all(user_id: user.id)
|
||||
key = ::ApiKey.create!(user_id: user.id)
|
||||
present status: 0, token: key.access_token
|
||||
end
|
||||
|
||||
desc "绑定微信用户"
|
||||
params do
|
||||
requires :login, type: String, desc: 'username'
|
||||
requires :password, type: String, desc: 'password'
|
||||
end
|
||||
post 'wxbind' do
|
||||
openid = session[:wechat_openid]
|
||||
logger.debug "openid ============== #{openid}"
|
||||
raise "无法获取到openid,请在微信中打开本页面" unless openid
|
||||
uw = UserWechat.where(openid: openid).first
|
||||
raise "此微信号已绑定用户(#{uw.user.login}), 不能重复绑定" if uw && uw.real?
|
||||
|
||||
user, last_login_on = User.try_to_login(params[:login], params[:password])
|
||||
raise "用户名或密码错误,请重新输入" unless user
|
||||
#补全用户信息
|
||||
|
||||
raise "此用户已经绑定过公众号, 请换一个帐户试试" if user.user_wechat
|
||||
|
||||
if uw && !uw.real?
|
||||
uw.migrate_user(user)
|
||||
else
|
||||
UserWechat.create!(
|
||||
openid: openid,
|
||||
user: user
|
||||
)
|
||||
end
|
||||
|
||||
ws = WechatService.new
|
||||
ws.binding_succ_notice(user.id, "您已成功绑定Trustie平台。", user.show_name+"("+user.login+")", Time.now.strftime("%Y-%m-%d"))
|
||||
present status: 0, message: '您已成功绑定Trustie平台'
|
||||
end
|
||||
|
||||
desc "注册用户"
|
||||
params do
|
||||
requires :login, type: String, desc: 'username'
|
||||
requires :mail, type: String, desc: 'mail'
|
||||
requires :password, type: String, desc: 'password'
|
||||
end
|
||||
post do
|
||||
openid = session[:wechat_openid]
|
||||
logger.debug "openid ============== #{openid}"
|
||||
raise "无法获取到openid,请在微信中打开本页面" unless openid
|
||||
|
||||
uw = UserWechat.where(openid: openid).first
|
||||
raise "此微信号已绑定用户(#{uw.user.login}), 不能重复绑定" if uw && uw.real?
|
||||
us = UsersService.new
|
||||
user = us.register params.merge(:password_confirmation => params[:password],
|
||||
:should_confirmation_password => true)
|
||||
raise user.errors.full_messages.first if user.new_record?
|
||||
#自动激活
|
||||
if Setting.self_registration != '3'
|
||||
# user = automatically_register(user)
|
||||
user.activate
|
||||
user.last_login_on = Time.now
|
||||
if user.save
|
||||
UserStatus.create(:user_id => user.id, :changsets_count => 0, :watchers_count => 0)
|
||||
end
|
||||
end
|
||||
|
||||
if uw && !uw.real?
|
||||
user.update_attributes(:lastname=>uw.user[:lastname])
|
||||
uw.migrate_user(user)
|
||||
else
|
||||
UserWechat.create!(
|
||||
openid: openid,
|
||||
user: user
|
||||
)
|
||||
end
|
||||
|
||||
ws = WechatService.new
|
||||
ws.binding_succ_notice(user.id, "您已成功绑定Trustie平台。", user.show_name+"("+user.login+")", Time.now.strftime("%Y-%m-%d"))
|
||||
present :data, user, with: Mobile::Entities::User
|
||||
present :status, 0
|
||||
end
|
||||
|
||||
desc "显示用户"
|
||||
params do
|
||||
requires :id, type: Integer
|
||||
end
|
||||
route_param :id do
|
||||
get do
|
||||
us = UsersService.new
|
||||
ue = us.show_user params
|
||||
present :data, ue,with: Mobile::Entities::User
|
||||
present :status, 0
|
||||
end
|
||||
end
|
||||
|
||||
desc "修改用户"
|
||||
params do
|
||||
requires :token, type: String
|
||||
#optional :file, type: File, desc: 'avatar'
|
||||
optional :occupation, type: String
|
||||
optional :brief_introduction, type: String
|
||||
optional :province, type: String
|
||||
optional :city, type: String
|
||||
optional :gender, type: Integer
|
||||
end
|
||||
put ':id' do
|
||||
authenticate!
|
||||
us = UsersService.new
|
||||
ue = us.edit_user params.merge(id: current_user.id)
|
||||
present :data, ue,with: Mobile::Entities::User
|
||||
present :status, 0
|
||||
end
|
||||
|
||||
desc '获取用户课程'
|
||||
params do
|
||||
optional :token, type: String
|
||||
end
|
||||
|
||||
get ':id/courses' do
|
||||
us = UsersService.new
|
||||
ue = us.user_courses_list params,current_user.nil? ? User.find(2):current_user
|
||||
present :data, ue,with: Mobile::Entities::Course
|
||||
present :status, 0
|
||||
end
|
||||
|
||||
|
||||
desc '修改密码'
|
||||
params do
|
||||
requires :token, type: String
|
||||
requires :password, type:String , desc: '原密码'
|
||||
requires :new_password, type: String, desc: '新密码'
|
||||
end
|
||||
post 'password' do
|
||||
authenticate!
|
||||
us = UsersService.new
|
||||
user = us.change_password params.merge(current_user_id: current_user.id,
|
||||
new_password_confirmation: params[:new_password])
|
||||
present :data, user, with: Mobile::Entities::User
|
||||
present :status, 0
|
||||
end
|
||||
|
||||
desc "用户搜索"
|
||||
params do
|
||||
requires :name, type: String, desc: '用户名关键字'
|
||||
requires :search_by, type: String,desc: '搜索依据:0 登录名,1 用户名,2 邮箱,3 登录名和姓名'
|
||||
optional :is_search_assitant,type:Integer,desc:'是否搜索注册用户来作为助教'
|
||||
optional :course_id,type:Integer,desc: '课程id,搜索注册用户不为该课程教师的其他用户'
|
||||
optional :user_id,type:Integer,desc:'用户id'
|
||||
end
|
||||
get 'search/search_user' do
|
||||
us = UsersService.new
|
||||
user = us.search_user params
|
||||
present :data, user, with: Mobile::Entities::User
|
||||
present :status, 0
|
||||
end
|
||||
|
||||
desc "用户留言"
|
||||
params do
|
||||
requires :token, type: String
|
||||
requires :user_id, type: Integer,desc: '被留言的用户id'
|
||||
requires :page,type:Integer,desc:'请求数据的页码'
|
||||
end
|
||||
get ':user_id/messages' do
|
||||
us = UsersService.new
|
||||
jours = us.get_all_messages params
|
||||
present :data,jours,with:Mobile::Entities::Jours
|
||||
present :status,0
|
||||
end
|
||||
|
||||
desc "回复用户留言"
|
||||
params do
|
||||
requires :token, type: String
|
||||
requires :user_id, type: Integer,desc: '被留言的用户id'
|
||||
requires :content,type:String,desc:'留言内容'
|
||||
requires :ref_user_id,type:Integer,desc:'被回复的用户id'
|
||||
requires :parent_id,type:Integer,desc:'留言父id'
|
||||
requires :ref_message_id,type:Integer,desc:'引用消息id'
|
||||
optional :type,type:Integer,desc:'回复类型'
|
||||
optional :course_id,type:Integer,desc:'课程id'
|
||||
end
|
||||
post ':user_id/reply_message' do
|
||||
us = UsersService.new
|
||||
jours = us.reply_user_messages params,current_user
|
||||
present :status,0
|
||||
end
|
||||
|
||||
desc "给用户留言"
|
||||
params do
|
||||
requires :token, type: String
|
||||
requires :user_id, type: Integer,desc:'被留言的用户id'
|
||||
requires :content, type: String,desc:'留言内容'
|
||||
end
|
||||
post ':user_id/leave_message' do
|
||||
us = UsersService.new
|
||||
us.leave_message params,current_user
|
||||
present :data,0
|
||||
end
|
||||
|
||||
desc "与我相关"
|
||||
params do
|
||||
requires :token, type: String
|
||||
requires :page,type:Integer,desc:'页码'
|
||||
end
|
||||
get ':user_id/all_my_dynamic' do
|
||||
us = UsersService.new
|
||||
my_jours = us.reply_my_messages params,current_user
|
||||
present :data,my_jours,with:Mobile::Entities::Jours
|
||||
present :status,0
|
||||
end
|
||||
|
||||
desc "修改我的资料"
|
||||
|
||||
params do
|
||||
requires :token, type: String
|
||||
requires :lastname, type: String
|
||||
requires :sex, type: Integer
|
||||
end
|
||||
|
||||
post 'edit_userinfo' do
|
||||
authenticate!
|
||||
user = current_user
|
||||
status = 0
|
||||
message = ""
|
||||
|
||||
#昵称 不能超过30个字符
|
||||
if params[:lastname].length > 30 then
|
||||
message = "姓名不能超过30个字符!"
|
||||
status = -1
|
||||
end
|
||||
|
||||
if status == 0
|
||||
user.lastname = params[:lastname]
|
||||
user.update_attribute(:lastname, params[:lastname])
|
||||
se = user.extensions
|
||||
se.update_attribute(:gender, params[:sex])
|
||||
end
|
||||
|
||||
if status == 0
|
||||
present :data, current_user, with: Mobile::Entities::User
|
||||
present :status, 0
|
||||
else
|
||||
present :status, -1
|
||||
present :message, message
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
#coding=utf-8
|
||||
module Mobile
|
||||
module Apis
|
||||
class Users < Grape::API
|
||||
resource :users do
|
||||
|
||||
desc "我的资料"
|
||||
params do
|
||||
requires :token, type: String
|
||||
end
|
||||
|
||||
get 'get_userinfo' do
|
||||
authenticate!
|
||||
present :data, current_user, with: Mobile::Entities::User
|
||||
present :status, 0
|
||||
end
|
||||
|
||||
desc "上传头像"
|
||||
params do
|
||||
requires :token, type: String
|
||||
requires :imgdata, type: String
|
||||
end
|
||||
|
||||
post 'upload_head' do
|
||||
authenticate!
|
||||
#直接生成头像
|
||||
dirPath = "public/images/avatars/User"
|
||||
|
||||
fileDir = dirPath + "/"+current_user.id.to_s
|
||||
imgdata = Base64.decode64(params[:imgdata].split(",")[1])
|
||||
if imgdata.length > 1024*1024
|
||||
present :message,"上传图片不能超过1M"
|
||||
present :status, -1
|
||||
else
|
||||
begin
|
||||
File.open(fileDir,'wb'){ |f| f.write(imgdata) }
|
||||
present :status, 0
|
||||
rescue
|
||||
present :message,"上传失败"
|
||||
present :status, -1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
desc "解除绑定"
|
||||
params do
|
||||
requires :token, type: String
|
||||
end
|
||||
|
||||
post 'user_unbind' do
|
||||
authenticate!
|
||||
|
||||
user = current_user
|
||||
uw = user.user_wechat
|
||||
|
||||
us = UsersService.new
|
||||
us.wechat_unbind user.user_wechat
|
||||
|
||||
present :status, 0
|
||||
end
|
||||
|
||||
desc "查询是否已绑定"
|
||||
params do
|
||||
requires :openid, type: String, desc: 'wechat openid'
|
||||
end
|
||||
post 'isbind' do
|
||||
openid = params[:openid]
|
||||
uw = UserWechat.where(openid: openid).first
|
||||
raise "还未绑定trustie帐户" unless uw
|
||||
|
||||
user = uw.user
|
||||
::ApiKey.delete_all(user_id: user.id)
|
||||
key = ::ApiKey.create!(user_id: user.id)
|
||||
present status: 0, token: key.access_token
|
||||
end
|
||||
|
||||
desc "绑定微信用户"
|
||||
params do
|
||||
requires :login, type: String, desc: 'username'
|
||||
requires :password, type: String, desc: 'password'
|
||||
end
|
||||
post 'wxbind' do
|
||||
openid = session[:wechat_openid]
|
||||
logger.debug "openid ============== #{openid}"
|
||||
raise "无法获取到openid,请在微信中打开本页面" unless openid
|
||||
uw = UserWechat.where(openid: openid).first
|
||||
raise "此微信号已绑定用户(#{uw.user.login}), 不能重复绑定" if uw && uw.real?
|
||||
|
||||
user, last_login_on = User.try_to_login(params[:login], params[:password])
|
||||
raise "用户名或密码错误,请重新输入" unless user
|
||||
#补全用户信息
|
||||
|
||||
raise "此用户已经绑定过公众号, 请换一个帐户试试" if user.user_wechat
|
||||
|
||||
if uw && !uw.real?
|
||||
uw.migrate_user(user)
|
||||
else
|
||||
UserWechat.create!(
|
||||
openid: openid,
|
||||
user: user
|
||||
)
|
||||
end
|
||||
|
||||
ws = WechatService.new
|
||||
ws.binding_succ_notice(user.id, "您已成功绑定Trustie平台。", user.show_name+"("+user.login+")", Time.now.strftime("%Y-%m-%d"))
|
||||
present status: 0, message: '您已成功绑定Trustie平台'
|
||||
end
|
||||
|
||||
desc "注册用户"
|
||||
params do
|
||||
requires :login, type: String, desc: 'username'
|
||||
requires :mail, type: String, desc: 'mail'
|
||||
requires :password, type: String, desc: 'password'
|
||||
end
|
||||
post do
|
||||
openid = session[:wechat_openid]
|
||||
logger.debug "openid ============== #{openid}"
|
||||
raise "无法获取到openid,请在微信中打开本页面" unless openid
|
||||
|
||||
uw = UserWechat.where(openid: openid).first
|
||||
raise "此微信号已绑定用户(#{uw.user.login}), 不能重复绑定" if uw && uw.real?
|
||||
us = UsersService.new
|
||||
user = us.register params.merge(:password_confirmation => params[:password],
|
||||
:should_confirmation_password => true)
|
||||
raise user.errors.full_messages.first if user.new_record?
|
||||
#自动激活
|
||||
if Setting.self_registration != '3'
|
||||
# user = automatically_register(user)
|
||||
user.activate
|
||||
user.last_login_on = Time.now
|
||||
if user.save
|
||||
UserStatus.create(:user_id => user.id, :changsets_count => 0, :watchers_count => 0)
|
||||
end
|
||||
end
|
||||
|
||||
if uw && !uw.real?
|
||||
user.update_attributes(:lastname=>uw.user[:lastname])
|
||||
uw.migrate_user(user)
|
||||
else
|
||||
UserWechat.create!(
|
||||
openid: openid,
|
||||
user: user
|
||||
)
|
||||
end
|
||||
|
||||
ws = WechatService.new
|
||||
ws.binding_succ_notice(user.id, "您已成功绑定Trustie平台。", user.show_name+"("+user.login+")", Time.now.strftime("%Y-%m-%d"))
|
||||
present :data, user, with: Mobile::Entities::User
|
||||
present :status, 0
|
||||
end
|
||||
|
||||
desc "显示用户"
|
||||
params do
|
||||
requires :id, type: Integer
|
||||
end
|
||||
route_param :id do
|
||||
get do
|
||||
us = UsersService.new
|
||||
ue = us.show_user params
|
||||
present :data, ue,with: Mobile::Entities::User
|
||||
present :status, 0
|
||||
end
|
||||
end
|
||||
|
||||
desc "修改用户"
|
||||
params do
|
||||
requires :token, type: String
|
||||
#optional :file, type: File, desc: 'avatar'
|
||||
optional :occupation, type: String
|
||||
optional :brief_introduction, type: String
|
||||
optional :province, type: String
|
||||
optional :city, type: String
|
||||
optional :gender, type: Integer
|
||||
end
|
||||
put ':id' do
|
||||
authenticate!
|
||||
us = UsersService.new
|
||||
ue = us.edit_user params.merge(id: current_user.id)
|
||||
present :data, ue,with: Mobile::Entities::User
|
||||
present :status, 0
|
||||
end
|
||||
|
||||
desc '获取用户课程'
|
||||
params do
|
||||
optional :token, type: String
|
||||
end
|
||||
|
||||
get ':id/courses' do
|
||||
us = UsersService.new
|
||||
ue = us.user_courses_list params,current_user.nil? ? User.find(2):current_user
|
||||
present :data, ue,with: Mobile::Entities::Course
|
||||
present :status, 0
|
||||
end
|
||||
|
||||
|
||||
desc '修改密码'
|
||||
params do
|
||||
requires :token, type: String
|
||||
requires :password, type:String , desc: '原密码'
|
||||
requires :new_password, type: String, desc: '新密码'
|
||||
end
|
||||
post 'password' do
|
||||
authenticate!
|
||||
us = UsersService.new
|
||||
user = us.change_password params.merge(current_user_id: current_user.id,
|
||||
new_password_confirmation: params[:new_password])
|
||||
present :data, user, with: Mobile::Entities::User
|
||||
present :status, 0
|
||||
end
|
||||
|
||||
desc "用户搜索"
|
||||
params do
|
||||
requires :name, type: String, desc: '用户名关键字'
|
||||
requires :search_by, type: String,desc: '搜索依据:0 登录名,1 用户名,2 邮箱,3 登录名和姓名'
|
||||
optional :is_search_assitant,type:Integer,desc:'是否搜索注册用户来作为助教'
|
||||
optional :course_id,type:Integer,desc: '课程id,搜索注册用户不为该课程教师的其他用户'
|
||||
optional :user_id,type:Integer,desc:'用户id'
|
||||
end
|
||||
get 'search/search_user' do
|
||||
us = UsersService.new
|
||||
user = us.search_user params
|
||||
present :data, user, with: Mobile::Entities::User
|
||||
present :status, 0
|
||||
end
|
||||
|
||||
desc "用户留言"
|
||||
params do
|
||||
requires :token, type: String
|
||||
requires :user_id, type: Integer,desc: '被留言的用户id'
|
||||
requires :page,type:Integer,desc:'请求数据的页码'
|
||||
end
|
||||
get ':user_id/messages' do
|
||||
us = UsersService.new
|
||||
jours = us.get_all_messages params
|
||||
present :data,jours,with:Mobile::Entities::Jours
|
||||
present :status,0
|
||||
end
|
||||
|
||||
desc "回复用户留言"
|
||||
params do
|
||||
requires :token, type: String
|
||||
requires :user_id, type: Integer,desc: '被留言的用户id'
|
||||
requires :content,type:String,desc:'留言内容'
|
||||
requires :ref_user_id,type:Integer,desc:'被回复的用户id'
|
||||
requires :parent_id,type:Integer,desc:'留言父id'
|
||||
requires :ref_message_id,type:Integer,desc:'引用消息id'
|
||||
optional :type,type:Integer,desc:'回复类型'
|
||||
optional :course_id,type:Integer,desc:'课程id'
|
||||
end
|
||||
post ':user_id/reply_message' do
|
||||
us = UsersService.new
|
||||
jours = us.reply_user_messages params,current_user
|
||||
present :status,0
|
||||
end
|
||||
|
||||
desc "给用户留言"
|
||||
params do
|
||||
requires :token, type: String
|
||||
requires :user_id, type: Integer,desc:'被留言的用户id'
|
||||
requires :content, type: String,desc:'留言内容'
|
||||
end
|
||||
post ':user_id/leave_message' do
|
||||
us = UsersService.new
|
||||
us.leave_message params,current_user
|
||||
present :data,0
|
||||
end
|
||||
|
||||
desc "与我相关"
|
||||
params do
|
||||
requires :token, type: String
|
||||
requires :page,type:Integer,desc:'页码'
|
||||
end
|
||||
get ':user_id/all_my_dynamic' do
|
||||
us = UsersService.new
|
||||
my_jours = us.reply_my_messages params,current_user
|
||||
present :data,my_jours,with:Mobile::Entities::Jours
|
||||
present :status,0
|
||||
end
|
||||
|
||||
desc "修改我的资料"
|
||||
|
||||
params do
|
||||
requires :token, type: String
|
||||
requires :lastname, type: String
|
||||
requires :sex, type: Integer
|
||||
end
|
||||
|
||||
post 'edit_userinfo' do
|
||||
authenticate!
|
||||
user = current_user
|
||||
status = 0
|
||||
message = ""
|
||||
|
||||
#昵称 不能超过30个字符
|
||||
if params[:lastname].length > 30 then
|
||||
message = "姓名不能超过30个字符!"
|
||||
status = -1
|
||||
end
|
||||
|
||||
if status == 0
|
||||
user.lastname = params[:lastname]
|
||||
user.update_attribute(:lastname, params[:lastname])
|
||||
se = user.extensions
|
||||
se.update_attribute(:gender, params[:sex])
|
||||
end
|
||||
|
||||
if status == 0
|
||||
present :data, current_user, with: Mobile::Entities::User
|
||||
present :status, 0
|
||||
else
|
||||
present :status, -1
|
||||
present :message, message
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
|
|
@ -1,49 +1,49 @@
|
|||
#coding=utf-8
|
||||
module Mobile
|
||||
module Apis
|
||||
class Watches < Grape::API
|
||||
resource :watches do
|
||||
|
||||
desc "获取所有关注"
|
||||
params do
|
||||
requires :token, type: String
|
||||
end
|
||||
get do
|
||||
authenticate!
|
||||
us = UsersService.new
|
||||
ws = us.user_watcher(id: current_user.id)
|
||||
present :data, ws, with: Mobile::Entities::User
|
||||
present :status, 0
|
||||
end
|
||||
|
||||
|
||||
desc "关注某人"
|
||||
params do
|
||||
requires :token, type: String
|
||||
requires :object_id, type: Integer, desc: '关注的用户的id'
|
||||
end
|
||||
post do
|
||||
authenticate!
|
||||
ws = WatchesService.new
|
||||
o = ws.watch(params.merge({current_user_id:current_user.id, object_type:'user' }) )
|
||||
present :data, o, with: Mobile::Entities::User
|
||||
present :status, 0
|
||||
end
|
||||
|
||||
|
||||
desc "取消关注"
|
||||
params do
|
||||
requires :token, type: String
|
||||
requires :object_id, type: Integer, desc: '取消关注的用户的id'
|
||||
end
|
||||
delete do
|
||||
authenticate!
|
||||
ws = WatchesService.new
|
||||
ws.unwatch(params.merge({current_user_id:current_user.id, object_type:'user' }) )
|
||||
{status: 0}
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
#coding=utf-8
|
||||
module Mobile
|
||||
module Apis
|
||||
class Watches < Grape::API
|
||||
resource :watches do
|
||||
|
||||
desc "获取所有关注"
|
||||
params do
|
||||
requires :token, type: String
|
||||
end
|
||||
get do
|
||||
authenticate!
|
||||
us = UsersService.new
|
||||
ws = us.user_watcher(id: current_user.id)
|
||||
present :data, ws, with: Mobile::Entities::User
|
||||
present :status, 0
|
||||
end
|
||||
|
||||
|
||||
desc "关注某人"
|
||||
params do
|
||||
requires :token, type: String
|
||||
requires :object_id, type: Integer, desc: '关注的用户的id'
|
||||
end
|
||||
post do
|
||||
authenticate!
|
||||
ws = WatchesService.new
|
||||
o = ws.watch(params.merge({current_user_id:current_user.id, object_type:'user' }) )
|
||||
present :data, o, with: Mobile::Entities::User
|
||||
present :status, 0
|
||||
end
|
||||
|
||||
|
||||
desc "取消关注"
|
||||
params do
|
||||
requires :token, type: String
|
||||
requires :object_id, type: Integer, desc: '取消关注的用户的id'
|
||||
end
|
||||
delete do
|
||||
authenticate!
|
||||
ws = WatchesService.new
|
||||
ws.unwatch(params.merge({current_user_id:current_user.id, object_type:'user' }) )
|
||||
{status: 0}
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,139 +1,139 @@
|
|||
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
|
||||
all_comments = []
|
||||
get_all_children(all_comments, u).count
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
expose :user, using: Mobile::Entities::User do |c, opt|
|
||||
if c.is_a?(::BlogComment)
|
||||
c.author
|
||||
end
|
||||
end
|
||||
blog_comment_expose :act_type
|
||||
blog_comment_expose :act_id
|
||||
blog_comment_expose :blog_id
|
||||
blog_comment_expose :title
|
||||
blog_comment_expose :content
|
||||
blog_comment_expose :comment_count
|
||||
blog_comment_expose :created_at
|
||||
blog_comment_expose :lasted_comment
|
||||
blog_comment_expose :id
|
||||
blog_comment_expose :locked
|
||||
blog_comment_expose :praise_count
|
||||
expose :all_children, using:Mobile::Entities::BlogComment do |c,opt|
|
||||
if c.is_a? (::BlogComment)
|
||||
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|
|
||||
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
|
||||
|
||||
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 > 2 && !opt[:top]
|
||||
if opt[:type] == 1
|
||||
opt[:top] = 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
|
||||
elsif parents_reply.count == 2 && !opt[:top]
|
||||
opt[:top] = true
|
||||
parents_reply = parents_reply.reverse[0..0]
|
||||
parents_reply.reverse
|
||||
else
|
||||
[]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
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
|
||||
all_comments = []
|
||||
get_all_children(all_comments, u).count
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
expose :user, using: Mobile::Entities::User do |c, opt|
|
||||
if c.is_a?(::BlogComment)
|
||||
c.author
|
||||
end
|
||||
end
|
||||
blog_comment_expose :act_type
|
||||
blog_comment_expose :act_id
|
||||
blog_comment_expose :blog_id
|
||||
blog_comment_expose :title
|
||||
blog_comment_expose :content
|
||||
blog_comment_expose :comment_count
|
||||
blog_comment_expose :created_at
|
||||
blog_comment_expose :lasted_comment
|
||||
blog_comment_expose :id
|
||||
blog_comment_expose :locked
|
||||
blog_comment_expose :praise_count
|
||||
expose :all_children, using:Mobile::Entities::BlogComment do |c,opt|
|
||||
if c.is_a? (::BlogComment)
|
||||
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|
|
||||
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
|
||||
|
||||
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 > 2 && !opt[:top]
|
||||
if opt[:type] == 1
|
||||
opt[:top] = 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
|
||||
elsif parents_reply.count == 2 && !opt[:top]
|
||||
opt[:top] = true
|
||||
parents_reply = parents_reply.reverse[0..0]
|
||||
parents_reply.reverse
|
||||
else
|
||||
[]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,114 +1,114 @@
|
|||
module Mobile
|
||||
module Entities
|
||||
class Course < Grape::Entity
|
||||
include Redmine::I18n
|
||||
include ApplicationHelper
|
||||
include ApiHelper
|
||||
def self.course_expose(field)
|
||||
expose field do |f,opt|
|
||||
c = nil
|
||||
if f.is_a? ::Course
|
||||
c = f
|
||||
else
|
||||
c = f[:course]
|
||||
end
|
||||
if f.is_a?(Hash) && f.key?(field)
|
||||
f[field] if f.is_a?(Hash) && f.key?(field)
|
||||
#f.img_url if f.respond_to?(:img_url)
|
||||
elsif field == :created_at || field == :updated_at
|
||||
(format_time(c[field]) if (c.is_a?(Hash) && c.key?(field))) || (format_time(c.send(field)) if c.respond_to?(field))
|
||||
elsif field == :member_count
|
||||
::Course===c ? c.members.count : 0
|
||||
else
|
||||
(c[field] if (c.is_a?(Hash) && c.key?(field))) || (c.send(field) if c.respond_to?(field))
|
||||
end
|
||||
end
|
||||
end
|
||||
course_expose :img_url
|
||||
course_expose :attachmenttype
|
||||
course_expose :class_period
|
||||
course_expose :code
|
||||
course_expose :created_at
|
||||
course_expose :description
|
||||
course_expose :endup_time
|
||||
course_expose :extra
|
||||
course_expose :id
|
||||
course_expose :inherit_members
|
||||
course_expose :is_public
|
||||
course_expose :lft
|
||||
course_expose :location
|
||||
course_expose :name
|
||||
course_expose :open_student
|
||||
# course_expose :password
|
||||
course_expose :rgt
|
||||
course_expose :school_id
|
||||
course_expose :setup_time
|
||||
course_expose :state
|
||||
course_expose :status
|
||||
course_expose :string
|
||||
course_expose :tea_id
|
||||
course_expose :term
|
||||
course_expose :time
|
||||
course_expose :invite_code
|
||||
course_expose :qrcode
|
||||
course_expose :updated_at
|
||||
course_expose :course_student_num
|
||||
course_expose :member_count
|
||||
course_expose :groupnum
|
||||
expose :can_setting, if: lambda { |instance, options| options[:user] } do |instance, options|
|
||||
current_user = options[:user]
|
||||
can_setting = false
|
||||
|
||||
if instance[:course]
|
||||
course = instance[:course]
|
||||
else
|
||||
course = instance
|
||||
end
|
||||
|
||||
member = course.members.where("user_id=#{current_user.id} and course_id=#{course.id}")[0]
|
||||
role_ids = member.role_ids if member
|
||||
|
||||
if role_ids && (role_ids.include?(7) || role_ids.include?(9) )
|
||||
can_setting = true
|
||||
end
|
||||
|
||||
if course.tea_id == current_user.id
|
||||
can_setting = true
|
||||
end
|
||||
can_setting
|
||||
end
|
||||
expose :is_member, if: lambda { |instance, options| options[:user] } do |instance, options|
|
||||
current_user = options[:user]
|
||||
if instance[:course]
|
||||
course = instance[:course]
|
||||
else
|
||||
course = instance
|
||||
end
|
||||
current_user.member_of_course?(course)
|
||||
end
|
||||
expose :teacher, using: Mobile::Entities::User do |c, opt|
|
||||
if c.is_a? ::Course
|
||||
c.teacher
|
||||
else
|
||||
c[:course].teacher
|
||||
end
|
||||
end
|
||||
expose :my_homework,using: Mobile::Entities::Homework do |f, opt|
|
||||
f[:my_homework] if f.is_a?(Hash) && f.key?(:my_homework)
|
||||
end
|
||||
expose :is_creator, if: lambda { |instance, options| options[:user] } do |instance, options|
|
||||
if instance[:course]
|
||||
course = instance[:course]
|
||||
else
|
||||
course = instance
|
||||
end
|
||||
current_user = options[:user]
|
||||
course.tea_id == current_user.id
|
||||
end
|
||||
course_expose :current_user_is_member
|
||||
course_expose :current_user_is_teacher
|
||||
course_expose :work_unit
|
||||
course_expose :syllabus_title
|
||||
end
|
||||
end
|
||||
end
|
||||
module Mobile
|
||||
module Entities
|
||||
class Course < Grape::Entity
|
||||
include Redmine::I18n
|
||||
include ApplicationHelper
|
||||
include ApiHelper
|
||||
def self.course_expose(field)
|
||||
expose field do |f,opt|
|
||||
c = nil
|
||||
if f.is_a? ::Course
|
||||
c = f
|
||||
else
|
||||
c = f[:course]
|
||||
end
|
||||
if f.is_a?(Hash) && f.key?(field)
|
||||
f[field] if f.is_a?(Hash) && f.key?(field)
|
||||
#f.img_url if f.respond_to?(:img_url)
|
||||
elsif field == :created_at || field == :updated_at
|
||||
(format_time(c[field]) if (c.is_a?(Hash) && c.key?(field))) || (format_time(c.send(field)) if c.respond_to?(field))
|
||||
elsif field == :member_count
|
||||
::Course===c ? c.members.count : 0
|
||||
else
|
||||
(c[field] if (c.is_a?(Hash) && c.key?(field))) || (c.send(field) if c.respond_to?(field))
|
||||
end
|
||||
end
|
||||
end
|
||||
course_expose :img_url
|
||||
course_expose :attachmenttype
|
||||
course_expose :class_period
|
||||
course_expose :code
|
||||
course_expose :created_at
|
||||
course_expose :description
|
||||
course_expose :endup_time
|
||||
course_expose :extra
|
||||
course_expose :id
|
||||
course_expose :inherit_members
|
||||
course_expose :is_public
|
||||
course_expose :lft
|
||||
course_expose :location
|
||||
course_expose :name
|
||||
course_expose :open_student
|
||||
# course_expose :password
|
||||
course_expose :rgt
|
||||
course_expose :school_id
|
||||
course_expose :setup_time
|
||||
course_expose :state
|
||||
course_expose :status
|
||||
course_expose :string
|
||||
course_expose :tea_id
|
||||
course_expose :term
|
||||
course_expose :time
|
||||
course_expose :invite_code
|
||||
course_expose :qrcode
|
||||
course_expose :updated_at
|
||||
course_expose :course_student_num
|
||||
course_expose :member_count
|
||||
course_expose :groupnum
|
||||
expose :can_setting, if: lambda { |instance, options| options[:user] } do |instance, options|
|
||||
current_user = options[:user]
|
||||
can_setting = false
|
||||
|
||||
if instance[:course]
|
||||
course = instance[:course]
|
||||
else
|
||||
course = instance
|
||||
end
|
||||
|
||||
member = course.members.where("user_id=#{current_user.id} and course_id=#{course.id}")[0]
|
||||
role_ids = member.role_ids if member
|
||||
|
||||
if role_ids && (role_ids.include?(7) || role_ids.include?(9) )
|
||||
can_setting = true
|
||||
end
|
||||
|
||||
if course.tea_id == current_user.id
|
||||
can_setting = true
|
||||
end
|
||||
can_setting
|
||||
end
|
||||
expose :is_member, if: lambda { |instance, options| options[:user] } do |instance, options|
|
||||
current_user = options[:user]
|
||||
if instance[:course]
|
||||
course = instance[:course]
|
||||
else
|
||||
course = instance
|
||||
end
|
||||
current_user.member_of_course?(course)
|
||||
end
|
||||
expose :teacher, using: Mobile::Entities::User do |c, opt|
|
||||
if c.is_a? ::Course
|
||||
c.teacher
|
||||
else
|
||||
c[:course].teacher
|
||||
end
|
||||
end
|
||||
expose :my_homework,using: Mobile::Entities::Homework do |f, opt|
|
||||
f[:my_homework] if f.is_a?(Hash) && f.key?(:my_homework)
|
||||
end
|
||||
expose :is_creator, if: lambda { |instance, options| options[:user] } do |instance, options|
|
||||
if instance[:course]
|
||||
course = instance[:course]
|
||||
else
|
||||
course = instance
|
||||
end
|
||||
current_user = options[:user]
|
||||
course.tea_id == current_user.id
|
||||
end
|
||||
course_expose :current_user_is_member
|
||||
course_expose :current_user_is_teacher
|
||||
course_expose :work_unit
|
||||
course_expose :syllabus_title
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,19 +1,19 @@
|
|||
module Mobile
|
||||
module Entities
|
||||
class CourseGroup < Grape::Entity
|
||||
include Redmine::I18n
|
||||
include ApplicationHelper
|
||||
include ApiHelper
|
||||
def self.course_group_expose(f)
|
||||
expose f do |u,opt|
|
||||
if u.is_a?(Hash) && u.key?(f)
|
||||
u[f]
|
||||
end
|
||||
end
|
||||
end
|
||||
expose :id
|
||||
expose :name
|
||||
expose :users, using: Mobile::Entities::User
|
||||
end
|
||||
end
|
||||
end
|
||||
module Mobile
|
||||
module Entities
|
||||
class CourseGroup < Grape::Entity
|
||||
include Redmine::I18n
|
||||
include ApplicationHelper
|
||||
include ApiHelper
|
||||
def self.course_group_expose(f)
|
||||
expose f do |u,opt|
|
||||
if u.is_a?(Hash) && u.key?(f)
|
||||
u[f]
|
||||
end
|
||||
end
|
||||
end
|
||||
expose :id
|
||||
expose :name
|
||||
expose :users, using: Mobile::Entities::User
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,43 +1,43 @@
|
|||
module Mobile
|
||||
module Entities
|
||||
class Exercise < Grape::Entity
|
||||
include Redmine::I18n
|
||||
include ApplicationHelper
|
||||
include ApiHelper
|
||||
def self.exercise_expose(field)
|
||||
expose field do |f,opt|
|
||||
if f.is_a?(Hash) && f.key?(field)
|
||||
if field == :created_on
|
||||
format_time(f[field])
|
||||
else
|
||||
f[field]
|
||||
end
|
||||
elsif f.is_a?(::Exercise)
|
||||
if f.respond_to?(field)
|
||||
f.send(field)
|
||||
else
|
||||
case field
|
||||
when :coursename
|
||||
f.course.nil? ? "" : f.course.name
|
||||
when :syllabus_title
|
||||
f.course.nil? ? "" : f.course.syllabus.nil? ? "" : f.course.syllabus.title
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
expose :exercise_name
|
||||
expose :exercise_description
|
||||
exercise_expose :coursename #所属班级名
|
||||
exercise_expose :syllabus_title
|
||||
|
||||
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
|
||||
module Mobile
|
||||
module Entities
|
||||
class Exercise < Grape::Entity
|
||||
include Redmine::I18n
|
||||
include ApplicationHelper
|
||||
include ApiHelper
|
||||
def self.exercise_expose(field)
|
||||
expose field do |f,opt|
|
||||
if f.is_a?(Hash) && f.key?(field)
|
||||
if field == :created_on
|
||||
format_time(f[field])
|
||||
else
|
||||
f[field]
|
||||
end
|
||||
elsif f.is_a?(::Exercise)
|
||||
if f.respond_to?(field)
|
||||
f.send(field)
|
||||
else
|
||||
case field
|
||||
when :coursename
|
||||
f.course.nil? ? "" : f.course.name
|
||||
when :syllabus_title
|
||||
f.course.nil? ? "" : f.course.syllabus.nil? ? "" : f.course.syllabus.title
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
expose :exercise_name
|
||||
expose :exercise_description
|
||||
exercise_expose :coursename #所属班级名
|
||||
exercise_expose :syllabus_title
|
||||
|
||||
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
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
module Mobile
|
||||
module Entities
|
||||
class Homeworkscore < Grape::Entity
|
||||
include Redmine::I18n
|
||||
include ApplicationHelper
|
||||
def self.homeworkscore_expose(field)
|
||||
expose field do |f,opt|
|
||||
if f.is_a?(Hash) && f.key?(field)
|
||||
f[field]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
homeworkscore_expose :name
|
||||
homeworkscore_expose :score
|
||||
end
|
||||
end
|
||||
module Mobile
|
||||
module Entities
|
||||
class Homeworkscore < Grape::Entity
|
||||
include Redmine::I18n
|
||||
include ApplicationHelper
|
||||
def self.homeworkscore_expose(field)
|
||||
expose field do |f,opt|
|
||||
if f.is_a?(Hash) && f.key?(field)
|
||||
f[field]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
homeworkscore_expose :name
|
||||
homeworkscore_expose :score
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,44 +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
|
||||
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
|
|
@ -1,34 +1,34 @@
|
|||
module Mobile
|
||||
module Entities
|
||||
class Member < Grape::Entity
|
||||
include ApplicationHelper
|
||||
include ApiHelper
|
||||
def self.member_expose(f)
|
||||
expose f do |u,opt|
|
||||
if u.is_a?(Hash) && u.key?(f)
|
||||
u[f]
|
||||
elsif u.is_a?(::Member)
|
||||
if u.respond_to?(f)
|
||||
u.send(f)
|
||||
else
|
||||
case f
|
||||
when :student_id
|
||||
u.user.user_extensions.student_id
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
expose :user, using: Mobile::Entities::User do |c, opt|
|
||||
if c.is_a?(::Member)
|
||||
c.user
|
||||
end
|
||||
end
|
||||
member_expose :student_id
|
||||
member_expose :score
|
||||
member_expose :id
|
||||
end
|
||||
end
|
||||
module Mobile
|
||||
module Entities
|
||||
class Member < Grape::Entity
|
||||
include ApplicationHelper
|
||||
include ApiHelper
|
||||
def self.member_expose(f)
|
||||
expose f do |u,opt|
|
||||
if u.is_a?(Hash) && u.key?(f)
|
||||
u[f]
|
||||
elsif u.is_a?(::Member)
|
||||
if u.respond_to?(f)
|
||||
u.send(f)
|
||||
else
|
||||
case f
|
||||
when :student_id
|
||||
u.user.user_extensions.student_id
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
expose :user, using: Mobile::Entities::User do |c, opt|
|
||||
if c.is_a?(::Member)
|
||||
c.user
|
||||
end
|
||||
end
|
||||
member_expose :student_id
|
||||
member_expose :score
|
||||
member_expose :id
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,154 +1,154 @@
|
|||
module Mobile
|
||||
module Entities
|
||||
class Message < Grape::Entity
|
||||
include ApplicationHelper
|
||||
include ApiHelper
|
||||
def self.message_expose(f)
|
||||
expose f do |u,opt|
|
||||
if u.is_a?(Hash) && u.key?(f)
|
||||
u[f]
|
||||
elsif u.is_a?(::Message)
|
||||
if u.respond_to?(f)
|
||||
if f == :created_on
|
||||
format_time( u.send(f))
|
||||
else
|
||||
u.send(f)
|
||||
end
|
||||
else
|
||||
case f
|
||||
when :course_project_name
|
||||
if u.board.project_id == -1
|
||||
u.course.name
|
||||
else
|
||||
u.project.name
|
||||
end
|
||||
when :syllabus_title
|
||||
if u.board.project_id == -1
|
||||
u.course.syllabus.nil? ? "" : u.course.syllabus.title
|
||||
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
|
||||
when :comment_count
|
||||
all_comments = []
|
||||
get_all_children(all_comments, u).count
|
||||
when :title
|
||||
u.subject
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
expose :user, using: Mobile::Entities::User do |c, opt|
|
||||
if c.is_a?(::Message)
|
||||
c.author
|
||||
end
|
||||
end
|
||||
message_expose :act_type
|
||||
message_expose :act_id
|
||||
message_expose :course_project_name
|
||||
message_expose :syllabus_title
|
||||
message_expose :board_id
|
||||
message_expose :subject
|
||||
message_expose :title
|
||||
message_expose :content
|
||||
message_expose :comment_count
|
||||
message_expose :praise_count
|
||||
message_expose :created_on
|
||||
message_expose :locked
|
||||
message_expose :id
|
||||
message_expose :lasted_comment
|
||||
expose :all_children,using:Mobile::Entities::Message do |c,opt|
|
||||
if c.is_a? (::Message)
|
||||
# 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|
|
||||
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
|
||||
|
||||
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::Message do |c,opt|
|
||||
if c.is_a? (::Message)
|
||||
#取二级回复的底楼层
|
||||
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::Message do |c,opt|
|
||||
if c.is_a? (::Message)
|
||||
#取二级回复的顶楼层
|
||||
parents_reply = []
|
||||
parents_reply = get_reply_parents_no_root(parents_reply, c)
|
||||
if parents_reply.count > 2 && !opt[:top]
|
||||
if opt[:type] == 1
|
||||
opt[:top] = 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
|
||||
elsif parents_reply.count == 2 && !opt[:top]
|
||||
opt[:top] = true
|
||||
parents_reply = parents_reply.reverse[0..0]
|
||||
parents_reply.reverse
|
||||
else
|
||||
[]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
module Mobile
|
||||
module Entities
|
||||
class Message < Grape::Entity
|
||||
include ApplicationHelper
|
||||
include ApiHelper
|
||||
def self.message_expose(f)
|
||||
expose f do |u,opt|
|
||||
if u.is_a?(Hash) && u.key?(f)
|
||||
u[f]
|
||||
elsif u.is_a?(::Message)
|
||||
if u.respond_to?(f)
|
||||
if f == :created_on
|
||||
format_time( u.send(f))
|
||||
else
|
||||
u.send(f)
|
||||
end
|
||||
else
|
||||
case f
|
||||
when :course_project_name
|
||||
if u.board.project_id == -1
|
||||
u.course.name
|
||||
else
|
||||
u.project.name
|
||||
end
|
||||
when :syllabus_title
|
||||
if u.board.project_id == -1
|
||||
u.course.syllabus.nil? ? "" : u.course.syllabus.title
|
||||
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
|
||||
when :comment_count
|
||||
all_comments = []
|
||||
get_all_children(all_comments, u).count
|
||||
when :title
|
||||
u.subject
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
expose :user, using: Mobile::Entities::User do |c, opt|
|
||||
if c.is_a?(::Message)
|
||||
c.author
|
||||
end
|
||||
end
|
||||
message_expose :act_type
|
||||
message_expose :act_id
|
||||
message_expose :course_project_name
|
||||
message_expose :syllabus_title
|
||||
message_expose :board_id
|
||||
message_expose :subject
|
||||
message_expose :title
|
||||
message_expose :content
|
||||
message_expose :comment_count
|
||||
message_expose :praise_count
|
||||
message_expose :created_on
|
||||
message_expose :locked
|
||||
message_expose :id
|
||||
message_expose :lasted_comment
|
||||
expose :all_children,using:Mobile::Entities::Message do |c,opt|
|
||||
if c.is_a? (::Message)
|
||||
# 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|
|
||||
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
|
||||
|
||||
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::Message do |c,opt|
|
||||
if c.is_a? (::Message)
|
||||
#取二级回复的底楼层
|
||||
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::Message do |c,opt|
|
||||
if c.is_a? (::Message)
|
||||
#取二级回复的顶楼层
|
||||
parents_reply = []
|
||||
parents_reply = get_reply_parents_no_root(parents_reply, c)
|
||||
if parents_reply.count > 2 && !opt[:top]
|
||||
if opt[:type] == 1
|
||||
opt[:top] = 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
|
||||
elsif parents_reply.count == 2 && !opt[:top]
|
||||
opt[:top] = true
|
||||
parents_reply = parents_reply.reverse[0..0]
|
||||
parents_reply.reverse
|
||||
else
|
||||
[]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,43 +1,43 @@
|
|||
module Mobile
|
||||
module Entities
|
||||
class Project < Grape::Entity
|
||||
expose :name
|
||||
expose :id
|
||||
expose :is_public
|
||||
expose :user_id
|
||||
expose :invite_code
|
||||
expose :qrcode
|
||||
expose :can_setting, if: lambda { |instance, options| options[:user] } do |instance, options|
|
||||
current_user = options[:user]
|
||||
|
||||
my_member = instance.member_principals.where("users.id=#{current_user.id}").first
|
||||
can_setting = false
|
||||
if my_member && my_member.roles[0] && my_member.roles[0].id == 3
|
||||
can_setting = true
|
||||
end
|
||||
can_setting
|
||||
end
|
||||
|
||||
expose :is_creator, if: lambda { |instance, options| options[:user] } do |instance, options|
|
||||
current_user = options[:user]
|
||||
|
||||
current_user.id == instance.user_id
|
||||
end
|
||||
|
||||
expose :is_member, if: lambda { |instance, options| options[:user] } do |instance, options|
|
||||
current_user = options[:user]
|
||||
if instance[:project]
|
||||
project = instance[:project]
|
||||
else
|
||||
project = instance
|
||||
end
|
||||
current_user.member_of?(project)
|
||||
end
|
||||
|
||||
|
||||
expose :member_count, if: lambda { |instance, options| options[:user] } do |instance, options|
|
||||
instance.members.count
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
module Mobile
|
||||
module Entities
|
||||
class Project < Grape::Entity
|
||||
expose :name
|
||||
expose :id
|
||||
expose :is_public
|
||||
expose :user_id
|
||||
expose :invite_code
|
||||
expose :qrcode
|
||||
expose :can_setting, if: lambda { |instance, options| options[:user] } do |instance, options|
|
||||
current_user = options[:user]
|
||||
|
||||
my_member = instance.member_principals.where("users.id=#{current_user.id}").first
|
||||
can_setting = false
|
||||
if my_member && my_member.roles[0] && my_member.roles[0].id == 3
|
||||
can_setting = true
|
||||
end
|
||||
can_setting
|
||||
end
|
||||
|
||||
expose :is_creator, if: lambda { |instance, options| options[:user] } do |instance, options|
|
||||
current_user = options[:user]
|
||||
|
||||
current_user.id == instance.user_id
|
||||
end
|
||||
|
||||
expose :is_member, if: lambda { |instance, options| options[:user] } do |instance, options|
|
||||
current_user = options[:user]
|
||||
if instance[:project]
|
||||
project = instance[:project]
|
||||
else
|
||||
project = instance
|
||||
end
|
||||
current_user.member_of?(project)
|
||||
end
|
||||
|
||||
|
||||
expose :member_count, if: lambda { |instance, options| options[:user] } do |instance, options|
|
||||
instance.members.count
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,35 +1,35 @@
|
|||
module Mobile
|
||||
module Entities
|
||||
class ProjectMember < Grape::Entity
|
||||
include Redmine::I18n
|
||||
include ApplicationHelper
|
||||
include ApiHelper
|
||||
def self.member_expose(f)
|
||||
expose f do |u,opt|
|
||||
if u.is_a?(Hash) && u.key?(f)
|
||||
u[f]
|
||||
elsif u.is_a?(::Member)
|
||||
if u.respond_to?(f)
|
||||
u.send(f)
|
||||
else
|
||||
case f
|
||||
when :roles_id
|
||||
# u.roles[0].id
|
||||
u.roles.map {|r| r.id}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
expose :user, using: Mobile::Entities::User do |c, opt|
|
||||
if c.is_a?(::Member)
|
||||
c.user
|
||||
end
|
||||
end
|
||||
|
||||
member_expose :roles_id
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
module Mobile
|
||||
module Entities
|
||||
class ProjectMember < Grape::Entity
|
||||
include Redmine::I18n
|
||||
include ApplicationHelper
|
||||
include ApiHelper
|
||||
def self.member_expose(f)
|
||||
expose f do |u,opt|
|
||||
if u.is_a?(Hash) && u.key?(f)
|
||||
u[f]
|
||||
elsif u.is_a?(::Member)
|
||||
if u.respond_to?(f)
|
||||
u.send(f)
|
||||
else
|
||||
case f
|
||||
when :roles_id
|
||||
# u.roles[0].id
|
||||
u.roles.map {|r| r.id}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
expose :user, using: Mobile::Entities::User do |c, opt|
|
||||
if c.is_a?(::Member)
|
||||
c.user
|
||||
end
|
||||
end
|
||||
|
||||
member_expose :roles_id
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,45 +1,45 @@
|
|||
module Mobile
|
||||
module Entities
|
||||
class StudentWork < Grape::Entity
|
||||
include ApplicationHelper
|
||||
include ApiHelper
|
||||
def self.student_work_expose(f)
|
||||
expose f do |u,opt|
|
||||
if u.is_a?(Hash) && u.key?(f)
|
||||
u[f]
|
||||
elsif u.is_a?(::StudentWork)
|
||||
if u.respond_to?(f)
|
||||
if f == :created_at
|
||||
format_time(u.send(:created_at))
|
||||
else
|
||||
u.send(f)
|
||||
end
|
||||
|
||||
else
|
||||
case f
|
||||
when :student_id
|
||||
u.user.user_extensions.student_id
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
expose :user, using: Mobile::Entities::User do |c, opt|
|
||||
if c.is_a?(::StudentWork)
|
||||
c.user
|
||||
end
|
||||
end
|
||||
student_work_expose :student_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
|
||||
end
|
||||
end
|
||||
module Mobile
|
||||
module Entities
|
||||
class StudentWork < Grape::Entity
|
||||
include ApplicationHelper
|
||||
include ApiHelper
|
||||
def self.student_work_expose(f)
|
||||
expose f do |u,opt|
|
||||
if u.is_a?(Hash) && u.key?(f)
|
||||
u[f]
|
||||
elsif u.is_a?(::StudentWork)
|
||||
if u.respond_to?(f)
|
||||
if f == :created_at
|
||||
format_time(u.send(:created_at))
|
||||
else
|
||||
u.send(f)
|
||||
end
|
||||
|
||||
else
|
||||
case f
|
||||
when :student_id
|
||||
u.user.user_extensions.student_id
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
expose :user, using: Mobile::Entities::User do |c, opt|
|
||||
if c.is_a?(::StudentWork)
|
||||
c.user
|
||||
end
|
||||
end
|
||||
student_work_expose :student_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
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,15 +1,15 @@
|
|||
module Mobile
|
||||
module Entities
|
||||
class Syllabus < Grape::Entity
|
||||
expose :title
|
||||
expose :id
|
||||
expose :can_setting, if: lambda { |instance, options| options[:user] } do |instance, options|
|
||||
current_user = options[:user]
|
||||
can_setting = instance[:user_id] == current_user.id ? true : false
|
||||
can_setting = false if instance[:id].nil?
|
||||
can_setting
|
||||
end
|
||||
expose :courses, using: Mobile::Entities::Course
|
||||
end
|
||||
end
|
||||
end
|
||||
module Mobile
|
||||
module Entities
|
||||
class Syllabus < Grape::Entity
|
||||
expose :title
|
||||
expose :id
|
||||
expose :can_setting, if: lambda { |instance, options| options[:user] } do |instance, options|
|
||||
current_user = options[:user]
|
||||
can_setting = instance[:user_id] == current_user.id ? true : false
|
||||
can_setting = false if instance[:id].nil?
|
||||
can_setting
|
||||
end
|
||||
expose :courses, using: Mobile::Entities::Course
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,87 +1,87 @@
|
|||
module Mobile
|
||||
module Entities
|
||||
class User < Grape::Entity
|
||||
include ApplicationHelper
|
||||
include ApiHelper
|
||||
def self.user_expose(f)
|
||||
expose f do |u,opt|
|
||||
if u.is_a?(Hash) && u.key?(f)
|
||||
u[f]
|
||||
elsif u.is_a?(::User)
|
||||
if u.respond_to?(f)
|
||||
u.send(f) unless u.user_extensions.nil?
|
||||
else
|
||||
case f
|
||||
when :img_url
|
||||
"/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
|
||||
get_user_work_unit u unless u.user_extensions.nil?
|
||||
when :location
|
||||
get_user_location u unless u.user_extensions.nil?
|
||||
when :brief_introduction
|
||||
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 :real_name
|
||||
u.nil? ? "" : get_user_realname(u).gsub(/\s*/,"");
|
||||
when :name
|
||||
u.nil? ? "" : u.show_name
|
||||
when :roles_id
|
||||
u[:roles_id].nil? ? nil : u.roles_id
|
||||
when :login
|
||||
u.login
|
||||
when :lastname
|
||||
u.lastname
|
||||
when :mail
|
||||
u.mail
|
||||
when :is_me
|
||||
defined? u.is_me ? u.is_me : 0
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
expose :id
|
||||
#头像
|
||||
user_expose :login
|
||||
user_expose :lastname
|
||||
#邮箱地址
|
||||
user_expose :mail
|
||||
expose :nickname
|
||||
#真名
|
||||
user_expose :img_url
|
||||
#昵称
|
||||
expose :realname
|
||||
#昵称
|
||||
user_expose :real_name
|
||||
#性别
|
||||
user_expose :gender
|
||||
#我的二维码
|
||||
#工作单位
|
||||
user_expose :work_unit
|
||||
#地区
|
||||
user_expose :location
|
||||
#签名
|
||||
user_expose :brief_introduction
|
||||
#总成绩
|
||||
user_expose :score
|
||||
#学号
|
||||
user_expose :student_num
|
||||
# 活跃值
|
||||
user_expose :active_count
|
||||
|
||||
user_expose :role_name
|
||||
|
||||
user_expose :roles_id
|
||||
|
||||
user_expose :name
|
||||
|
||||
user_expose :is_me
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
module Mobile
|
||||
module Entities
|
||||
class User < Grape::Entity
|
||||
include ApplicationHelper
|
||||
include ApiHelper
|
||||
def self.user_expose(f)
|
||||
expose f do |u,opt|
|
||||
if u.is_a?(Hash) && u.key?(f)
|
||||
u[f]
|
||||
elsif u.is_a?(::User)
|
||||
if u.respond_to?(f)
|
||||
u.send(f) unless u.user_extensions.nil?
|
||||
else
|
||||
case f
|
||||
when :img_url
|
||||
"/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
|
||||
get_user_work_unit u unless u.user_extensions.nil?
|
||||
when :location
|
||||
get_user_location u unless u.user_extensions.nil?
|
||||
when :brief_introduction
|
||||
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 :real_name
|
||||
u.nil? ? "" : get_user_realname(u).gsub(/\s*/,"");
|
||||
when :name
|
||||
u.nil? ? "" : u.show_name
|
||||
when :roles_id
|
||||
u[:roles_id].nil? ? nil : u.roles_id
|
||||
when :login
|
||||
u.login
|
||||
when :lastname
|
||||
u.lastname
|
||||
when :mail
|
||||
u.mail
|
||||
when :is_me
|
||||
defined? u.is_me ? u.is_me : 0
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
expose :id
|
||||
#头像
|
||||
user_expose :login
|
||||
user_expose :lastname
|
||||
#邮箱地址
|
||||
user_expose :mail
|
||||
expose :nickname
|
||||
#真名
|
||||
user_expose :img_url
|
||||
#昵称
|
||||
expose :realname
|
||||
#昵称
|
||||
user_expose :real_name
|
||||
#性别
|
||||
user_expose :gender
|
||||
#我的二维码
|
||||
#工作单位
|
||||
user_expose :work_unit
|
||||
#地区
|
||||
user_expose :location
|
||||
#签名
|
||||
user_expose :brief_introduction
|
||||
#总成绩
|
||||
user_expose :score
|
||||
#学号
|
||||
user_expose :student_num
|
||||
# 活跃值
|
||||
user_expose :active_count
|
||||
|
||||
user_expose :role_name
|
||||
|
||||
user_expose :roles_id
|
||||
|
||||
user_expose :name
|
||||
|
||||
user_expose :is_me
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -1,119 +1,119 @@
|
|||
# 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 :comment_count
|
||||
wh.journals_for_messages.count
|
||||
when :course_name
|
||||
wh.course.name
|
||||
when :syllabus_title
|
||||
wh.course.syllabus.nil? ? "" : wh.course.syllabus.title
|
||||
when :act_type
|
||||
'HomeworkCommon'
|
||||
when :act_id
|
||||
wh.id
|
||||
when :title
|
||||
wh.name
|
||||
when :homework_commit_count
|
||||
wh.student_works.has_committed.count
|
||||
when :last_commit_info
|
||||
if wh.student_works.has_committed.count > 0
|
||||
lc = wh.student_works.has_committed.reorder("commit_time desc").first
|
||||
{:lasttime=>time_from_now(lc.commit_time), :lastname=>lc.user.show_name}
|
||||
end
|
||||
when :last_score_info
|
||||
if wh.student_works.has_committed.count > 0
|
||||
sw_id = "("+wh.student_works.map{|sw| sw.id}.join(",")+")"
|
||||
student_work_scores = StudentWorksScore.where("student_work_id in #{sw_id} and score is not null").reorder("created_at desc")
|
||||
unless student_work_scores.empty?
|
||||
last_score = student_work_scores.first
|
||||
{:lasttime=>time_from_now(last_score.created_at), :lastname=>last_score.user.show_name}
|
||||
end
|
||||
end
|
||||
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
|
||||
expose :id
|
||||
whomework_expose :title
|
||||
whomework_expose :act_type
|
||||
whomework_expose :act_id
|
||||
whomework_expose :course_name
|
||||
whomework_expose :syllabus_title
|
||||
whomework_expose :created_at
|
||||
whomework_expose :absence_penalty
|
||||
whomework_expose :evaluation_start
|
||||
whomework_expose :evaluation_end
|
||||
whomework_expose :praise_count
|
||||
whomework_expose :comment_count
|
||||
whomework_expose :homework_commit_count #作品提交数
|
||||
whomework_expose :last_commit_info #最近提交信息
|
||||
whomework_expose :last_score_info #最近评阅信息
|
||||
expose :all_children, 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
|
||||
if !opt[:children] && opt[:type] == 0
|
||||
opt[:children] = true
|
||||
tStart = opt[:page]*5
|
||||
tEnd = (opt[:page]+1)*5 - 1
|
||||
|
||||
all_comments = f.journals_for_messages.reorder("created_on desc")
|
||||
all_comments[tStart..tEnd]
|
||||
end
|
||||
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
|
||||
# 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 :comment_count
|
||||
wh.journals_for_messages.count
|
||||
when :course_name
|
||||
wh.course.name
|
||||
when :syllabus_title
|
||||
wh.course.syllabus.nil? ? "" : wh.course.syllabus.title
|
||||
when :act_type
|
||||
'HomeworkCommon'
|
||||
when :act_id
|
||||
wh.id
|
||||
when :title
|
||||
wh.name
|
||||
when :homework_commit_count
|
||||
wh.student_works.has_committed.count
|
||||
when :last_commit_info
|
||||
if wh.student_works.has_committed.count > 0
|
||||
lc = wh.student_works.has_committed.reorder("commit_time desc").first
|
||||
{:lasttime=>time_from_now(lc.commit_time), :lastname=>lc.user.show_name}
|
||||
end
|
||||
when :last_score_info
|
||||
if wh.student_works.has_committed.count > 0
|
||||
sw_id = "("+wh.student_works.map{|sw| sw.id}.join(",")+")"
|
||||
student_work_scores = StudentWorksScore.where("student_work_id in #{sw_id} and score is not null").reorder("created_at desc")
|
||||
unless student_work_scores.empty?
|
||||
last_score = student_work_scores.first
|
||||
{:lasttime=>time_from_now(last_score.created_at), :lastname=>last_score.user.show_name}
|
||||
end
|
||||
end
|
||||
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
|
||||
expose :id
|
||||
whomework_expose :title
|
||||
whomework_expose :act_type
|
||||
whomework_expose :act_id
|
||||
whomework_expose :course_name
|
||||
whomework_expose :syllabus_title
|
||||
whomework_expose :created_at
|
||||
whomework_expose :absence_penalty
|
||||
whomework_expose :evaluation_start
|
||||
whomework_expose :evaluation_end
|
||||
whomework_expose :praise_count
|
||||
whomework_expose :comment_count
|
||||
whomework_expose :homework_commit_count #作品提交数
|
||||
whomework_expose :last_commit_info #最近提交信息
|
||||
whomework_expose :last_score_info #最近评阅信息
|
||||
expose :all_children, 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
|
||||
if !opt[:children] && opt[:type] == 0
|
||||
opt[:children] = true
|
||||
tStart = opt[:page]*5
|
||||
tEnd = (opt[:page]+1)*5 - 1
|
||||
|
||||
all_comments = f.journals_for_messages.reorder("created_on desc")
|
||||
all_comments[tStart..tEnd]
|
||||
end
|
||||
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
|
|
@ -1,13 +1,13 @@
|
|||
#coding=utf-8
|
||||
#
|
||||
module Mobile
|
||||
module Exceptions
|
||||
class AuthException < StandardError
|
||||
attr_reader :err_code, :msg
|
||||
def initialize(code, msg)
|
||||
@err_code = code
|
||||
@msg = msg
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
#coding=utf-8
|
||||
#
|
||||
module Mobile
|
||||
module Exceptions
|
||||
class AuthException < StandardError
|
||||
attr_reader :err_code, :msg
|
||||
def initialize(code, msg)
|
||||
@err_code = code
|
||||
@msg = msg
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,26 +1,26 @@
|
|||
#coding=utf-8
|
||||
|
||||
|
||||
module Mobile
|
||||
module Middleware
|
||||
class ErrorHandler < Grape::Middleware::Base
|
||||
def call!(env)
|
||||
@env = env
|
||||
begin
|
||||
@app.call(@env)
|
||||
rescue =>e
|
||||
code = 1
|
||||
|
||||
message = {status: code, message: e.message }.to_json
|
||||
|
||||
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
|
||||
# throw :error, :message => e.message || options[:default_message], :status => 500
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
#coding=utf-8
|
||||
|
||||
|
||||
module Mobile
|
||||
module Middleware
|
||||
class ErrorHandler < Grape::Middleware::Base
|
||||
def call!(env)
|
||||
@env = env
|
||||
begin
|
||||
@app.call(@env)
|
||||
rescue =>e
|
||||
code = 1
|
||||
|
||||
message = {status: code, message: e.message }.to_json
|
||||
|
||||
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
|
||||
# throw :error, :message => e.message || options[:default_message], :status => 500
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
// Place all the behaviors and hooks related to the matching controller here.
|
||||
// All this logic will automatically be available in application.js.
|
||||
// Place all the behaviors and hooks related to the matching controller here.
|
||||
// All this logic will automatically be available in application.js.
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
// Place all the behaviors and hooks related to the matching controller here.
|
||||
// All this logic will automatically be available in application.js.
|
||||
// Place all the behaviors and hooks related to the matching controller here.
|
||||
// All this logic will automatically be available in application.js.
|
||||
|
|
|
@ -1,3 +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/
|
||||
# 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/
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
// Place all the behaviors and hooks related to the matching controller here.
|
||||
// All this logic will automatically be available in application.js.
|
||||
// Place all the behaviors and hooks related to the matching controller here.
|
||||
// All this logic will automatically be available in application.js.
|
||||
|
|
|
@ -1,3 +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/
|
||||
# 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/
|
||||
|
|
|
@ -1,3 +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/
|
||||
# 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/
|
||||
|
|
|
@ -1,3 +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/
|
||||
# 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/
|
||||
|
|
|
@ -1,3 +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/
|
||||
# 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/
|
||||
|
|
|
@ -1,3 +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/
|
||||
# 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/
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
// Place all the behaviors and hooks related to the matching controller here.
|
||||
// All this logic will automatically be available in application.js.
|
||||
// Place all the behaviors and hooks related to the matching controller here.
|
||||
// All this logic will automatically be available in application.js.
|
||||
|
|
|
@ -1,3 +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/
|
||||
# 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/
|
||||
|
|
|
@ -1,3 +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/
|
||||
# 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/
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
// Place all the behaviors and hooks related to the matching controller here.
|
||||
// All this logic will automatically be available in application.js.
|
||||
// Place all the behaviors and hooks related to the matching controller here.
|
||||
// All this logic will automatically be available in application.js.
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
// Place all the behaviors and hooks related to the matching controller here.
|
||||
// All this logic will automatically be available in application.js.
|
||||
// Place all the behaviors and hooks related to the matching controller here.
|
||||
// All this logic will automatically be available in application.js.
|
||||
|
|
|
@ -1,3 +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/
|
||||
# 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/
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
// Place all the behaviors and hooks related to the matching controller here.
|
||||
// All this logic will automatically be available in application.js.
|
||||
// Place all the behaviors and hooks related to the matching controller here.
|
||||
// All this logic will automatically be available in application.js.
|
||||
|
|
|
@ -1,3 +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/
|
||||
# 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/
|
||||
|
|
|
@ -1,3 +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/
|
||||
# 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/
|
||||
|
|
|
@ -1,3 +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/
|
||||
# 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/
|
||||
|
|
|
@ -1,3 +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/
|
||||
# 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/
|
||||
|
|
|
@ -1,3 +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/
|
||||
# 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/
|
||||
|
|
|
@ -1,3 +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/
|
||||
# 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/
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
// Place all the behaviors and hooks related to the matching controller here.
|
||||
// All this logic will automatically be available in application.js.
|
||||
// Place all the behaviors and hooks related to the matching controller here.
|
||||
// All this logic will automatically be available in application.js.
|
||||
|
|
|
@ -1,3 +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/
|
||||
# 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/
|
||||
|
|
|
@ -1,3 +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/
|
||||
# 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/
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
// Place all the behaviors and hooks related to the matching controller here.
|
||||
// All this logic will automatically be available in application.js.
|
||||
// Place all the behaviors and hooks related to the matching controller here.
|
||||
// All this logic will automatically be available in application.js.
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
// Place all the behaviors and hooks related to the matching controller here.
|
||||
// All this logic will automatically be available in application.js.
|
||||
// Place all the behaviors and hooks related to the matching controller here.
|
||||
// All this logic will automatically be available in application.js.
|
||||
|
|
|
@ -1,3 +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/
|
||||
# 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/
|
||||
|
|
|
@ -1,3 +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/
|
||||
# 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/
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
// Place all the behaviors and hooks related to the matching controller here.
|
||||
// All this logic will automatically be available in application.js.
|
||||
// Place all the behaviors and hooks related to the matching controller here.
|
||||
// All this logic will automatically be available in application.js.
|
||||
|
|
|
@ -1,3 +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/
|
||||
# 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/
|
||||
|
|
|
@ -1,3 +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/
|
||||
# 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/
|
||||
|
|
|
@ -1,3 +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/
|
||||
# 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/
|
||||
|
|
|
@ -1,3 +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/
|
||||
# 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/
|
||||
|
|
|
@ -1,3 +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/
|
||||
# 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/
|
||||
|
|
|
@ -1,3 +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/
|
||||
# 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/
|
||||
|
|
|
@ -1,3 +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/
|
||||
# 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/
|
||||
|
|
|
@ -1,3 +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/
|
||||
# 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/
|
||||
|
|
|
@ -1,3 +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/
|
||||
# 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/
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
// Place all the behaviors and hooks related to the matching controller here.
|
||||
// All this logic will automatically be available in application.js.
|
||||
// Place all the behaviors and hooks related to the matching controller here.
|
||||
// All this logic will automatically be available in application.js.
|
||||
|
|
|
@ -1,3 +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/
|
||||
# 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/
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
// Place all the behaviors and hooks related to the matching controller here.
|
||||
// All this logic will automatically be available in application.js.
|
||||
// Place all the behaviors and hooks related to the matching controller here.
|
||||
// All this logic will automatically be available in application.js.
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
Place all the styles related to the matching controller here.
|
||||
They will automatically be included in application.css.
|
||||
*/
|
||||
/*
|
||||
Place all the styles related to the matching controller here.
|
||||
They will automatically be included in application.css.
|
||||
*/
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
Place all the styles related to the matching controller here.
|
||||
They will automatically be included in application.css.
|
||||
*/
|
||||
/*
|
||||
Place all the styles related to the matching controller here.
|
||||
They will automatically be included in application.css.
|
||||
*/
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
// Place all the styles related to the ArticleHomepages controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
||||
// Place all the styles related to the ArticleHomepages controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
Place all the styles related to the matching controller here.
|
||||
They will automatically be included in application.css.
|
||||
*/
|
||||
/*
|
||||
Place all the styles related to the matching controller here.
|
||||
They will automatically be included in application.css.
|
||||
*/
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
// Place all the styles related to the contest_members controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
||||
// Place all the styles related to the contest_members controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
// Place all the styles related to the contestant_works controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
||||
// Place all the styles related to the contestant_works controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
// Place all the styles related to the contests controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
||||
// Place all the styles related to the contests controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
// Place all the styles related to the cooperation controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
||||
// Place all the styles related to the cooperation controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
// Place all the styles related to the Enterprises controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
||||
// Place all the styles related to the Enterprises controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
Place all the styles related to the matching controller here.
|
||||
They will automatically be included in application.css.
|
||||
*/
|
||||
/*
|
||||
Place all the styles related to the matching controller here.
|
||||
They will automatically be included in application.css.
|
||||
*/
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
// Place all the styles related to the Homepages controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
||||
// Place all the styles related to the Homepages controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
// Place all the styles related to the main_categories controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
||||
// Place all the styles related to the main_categories controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
Place all the styles related to the matching controller here.
|
||||
They will automatically be included in application.css.
|
||||
*/
|
||||
/*
|
||||
Place all the styles related to the matching controller here.
|
||||
They will automatically be included in application.css.
|
||||
*/
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
Place all the styles related to the matching controller here.
|
||||
They will automatically be included in application.css.
|
||||
*/
|
||||
/*
|
||||
Place all the styles related to the matching controller here.
|
||||
They will automatically be included in application.css.
|
||||
*/
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
// Place all the styles related to the notificationcomments controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
||||
// Place all the styles related to the notificationcomments controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
Place all the styles related to the matching controller here.
|
||||
They will automatically be included in application.css.
|
||||
*/
|
||||
/*
|
||||
Place all the styles related to the matching controller here.
|
||||
They will automatically be included in application.css.
|
||||
*/
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
// Place all the styles related to the org_courses controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
||||
// Place all the styles related to the org_courses controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
// Place all the styles related to the org_document_comment controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
||||
// Place all the styles related to the org_document_comment controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
// Place all the styles related to the OrgMember controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
||||
// Place all the styles related to the OrgMember controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
// Place all the styles related to the org_projects controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
||||
// Place all the styles related to the org_projects controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue