Merge branch 'develop' into daiao_dev

Conflicts:
	app/views/admin/excellent_all_courses.html.erb
dai_ao
daiao 9 years ago
commit cb11cac506

@ -0,0 +1 @@
{"access_token":"oEEf8ZKAB8Y2G0o_xnTPkPJHKKk8iHkLC-f5ptvQ2nCMj9IpC86ivLD2-p38GfOkuG-HuQp3pWZqhs3NJXUMdPLWsr5k67hPZYuqg4ozLccx0xdLswapj0mn8ovZhK1tKIKiAFAOMO","expires_in":7200,"got_token_at":1467012449}

1
.gitignore vendored

@ -34,3 +34,4 @@ vendor/cache
/config/initializers/gitlab_config.rb
1234567
public/javascripts/wechat/node_modules/
.ruby-version

@ -1,12 +1,15 @@
source 'https://ruby.taobao.org/'
### <20><><EFBFBD><EFBFBD>ִ<EFBFBD><D6B4>bundle config mirror.https://rubygems.org https://gems.ruby-china.org <20>л<EFBFBD><D0BB><EFBFBD>ruby-chinaԴ
unless RUBY_PLATFORM =~ /w32/
# unix-like only
gem 'iconv'
gem "rmagick", "= 2.13.1" ## centos yum install ImageMagick-devel
gem 'certified'
end
gem 'certified'
gem 'net-ssh', '2.9.1'
gem 'jenkins_api_client'
gem 'nokogiri'
gem 'wechat',path: 'lib/wechat'
gem 'grack', path:'lib/grack'
@ -31,7 +34,6 @@ gem 'acts-as-taggable-on', '2.4.1'
gem 'spreadsheet'
gem 'ruby-ole'
gem 'rails_kindeditor',path:'lib/rails_kindeditor'
#gem "rmagick", ">= 2.0.0"
gem 'binding_of_caller'
gem 'chinese_pinyin'
# gem 'sunspot_rails', '~> 1.3.3'
@ -81,7 +83,7 @@ group :assets do
gem 'coffee-rails', '~> 3.2.1'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
gem 'therubyracer', :platforms => :ruby
# gem 'therubyracer', :platforms => :ruby
gem 'uglifier', '>= 1.0.3'
end

@ -18,11 +18,13 @@ module Mobile
require_relative 'apis/blog_comments'
require_relative 'apis/new_comment'
require_relative 'apis/praise'
require_relative 'apis/resources'
class API < Grape::API
version 'v1', using: :path
format :json
content_type :json, "application/json;charset=UTF-8"
use ActionDispatch::Session::CookieStore
use Mobile::Middleware::ErrorHandler
helpers do
@ -34,6 +36,10 @@ module Mobile
raise('Unauthorized. 用户认证失败.') unless current_user
end
def session
env['rack.session']
end
def current_user
openid = params[:openid]
if openid
@ -66,9 +72,9 @@ module Mobile
mount Apis::BlogComments
mount Apis::NewComment
mount Apis::Praise
mount Apis::Resources
#add_swagger_documentation ({api_version: 'v1', base_path: 'http://u06.shellinfo.cn/trustie/api'})
#add_swagger_documentation ({api_version: 'v1', base_path: '/api'}) if Rails.env.development?
add_swagger_documentation ({api_version: 'v1', base_path: '/api'}) if Rails.env.development?
end
end

@ -9,7 +9,7 @@ module Mobile
params do
requires :page, type: Integer
requires :openid, type: String
requires :token, type: String
end
post do
authenticate!

@ -14,8 +14,9 @@ module Mobile
optional :token, type: String
end
get do
authenticate!
cs = CoursesService.new
courses = cs.course_list(params,current_user.nil? ? User.find(2):current_user)
courses = cs.user_courses_list(current_user)
present :data, courses, with: Mobile::Entities::Course
present :status, 0
end
@ -97,25 +98,20 @@ module Mobile
desc "加入课程"
params do
requires :course_password, type: String
requires :token, type: String
requires :invite_code, type: String, desc: '邀请码'
end
post ":id" do
post "join" do
authenticate!
cs = CoursesService.new
status = cs.join_course({:object_id => params[:id],:course_password => params[:course_password]},current_user)
out = {status: status[:state]}
message = case status[:state]
when 0; "加入成功"
when 1; "密码错误"
when 2; "课程已过期 请联系课程管理员重启课程。(在配置课程处)"
when 3; "您已经加入了课程"
when 4; "您加入的课程不存在"
when 5; "您还未登录"
else; "未知错误,请稍后再试"
end
out.merge(message: message)
status = cs.join_course({role: "10", openid: params[:openid], invite_code: params[:invite_code]}, current_user)
{
status: status[:state],
messsge:CoursesService::JoinCourseError.message(status[:state])
}
end
desc "退出课程"
params do
requires :token, type: String
@ -201,6 +197,7 @@ module Mobile
end
route_param :id do
get do
authenticate!
cs = CoursesService.new
course = cs.show_course(params,(current_user.nil? ? User.find(2):current_user))
#course = Course.find(params[:id])
@ -388,7 +385,16 @@ module Mobile
end
desc '获取测验列表'
params do
requires :token, type:String
end
get ':course_id/exercises' do
authenticate!
exercises = Course.find(params[:course_id]).exercises
present :data,exercises,with:Mobile::Entities::Exercise
present :status,0
end
end
end

@ -8,7 +8,8 @@ module Mobile
desc "get special issuse"
get ':id' do
user = UserWechat.find_by_openid(params[:openid]).user
authenticate!
user = current_user
issue = Issue.find params[:id]
present :data, issue, with: Mobile::Entities::Issue,user: user
present :status, 0

@ -7,7 +7,8 @@ module Mobile
desc "get special journal"
get ':id' do
user = UserWechat.find_by_openid(params[:openid]).user
authenticate!
user = current_user
jour = JournalsForMessage.find params[:id]
present :data, jour, with: Mobile::Entities::Jours,user: user
present :status, 0

@ -7,7 +7,8 @@ module Mobile
desc "get special topic"
get ':id' do
user = UserWechat.find_by_openid(params[:openid]).user
authenticate!
user = current_user
message = Message.find params[:id]
present :data, message, with: Mobile::Entities::Message,user: user
present :status, 0

@ -11,12 +11,12 @@ module Mobile
params do
requires :type, type: String
requires :content, type: String
requires :openid, type: String
requires :token, type: String
end
post ':id' do
authenticate!
type = params[:type]
result = 1
current_user = UserWechat.find_by_openid(params[:openid]).user
if params[:content]!="" && current_user
case type
when "HomeworkCommon"

@ -7,7 +7,8 @@ module Mobile
desc "get special news"
get ':id' do
user = UserWechat.find_by_openid(params[:openid]).user
authenticate!
user = current_user
news = News.find params[:id]
present :data, news, with: Mobile::Entities::News,user: user
present :status, 0

@ -9,12 +9,13 @@ module Mobile
params do
requires :type, type: String
requires :openid, type: String
requires :token, type: String
end
post ':id' do
authenticate!
obj_id = params[:id]
obj_type = params[:type]
user = UserWechat.find_by_openid(params[:openid]).user
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)

@ -0,0 +1,55 @@
#coding=utf-8
module Mobile
module Apis
class Resources < Grape::API
resource :resources do
desc '获取所有课件'
params do
requires :token, type: String
end
get do
authenticate!
data = current_user.course_attachments
present :data, data, with: Mobile::Entities::Attachment
present :status, 0
end
desc '获取所有作业'
params do
requires :token, type: String
end
get 'homeworks' do
authenticate!
homeworks = current_user.homework_commons
present :data, homeworks, with: Mobile::Entities::Homework
present :status, 0
end
desc '获取所有测验'
params do
requires :token, type: String
end
get 'exercies' do
authenticate!
exercises = current_user.exercises
present :data, exercises, with: Mobile::Entities::Exercise
present :status, 0
end
end
end
end
end

@ -4,6 +4,48 @@ module Mobile
class Users < Grape::API
resource :users do
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
user, last_login_on = User.try_to_login(params[:login], params[:password])
raise "用户名或密码错误,请重新输入" unless user
#补全用户信息
raise "此用户已经绑定过公众号, 请换一个帐户试试" if user.user_wechat
UserWechat.create!(
openid: openid,
user: user
)
# ws = WechatService.new
# ws.binding_succ_notice(user.id, "您已成功绑定Trustie平台", user.login, format_time(Time.now))
present status: 0, message: '您已成功绑定Trustie平台'
end
desc "注册用户"
params do
requires :login, type: String, desc: 'username'

@ -7,7 +7,8 @@ module Mobile
desc "get one homework"
get ':id' do
user = UserWechat.find_by_openid(params[:openid]).user
authenticate!
user = current_user
homework = HomeworkCommon.find params[:id]
present :data, homework, with: Mobile::Entities::Whomework,user: user
present :status, 0

@ -45,6 +45,8 @@ module Mobile
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
expose :teacher, using: Mobile::Entities::User do |c, opt|

@ -0,0 +1,8 @@
module Mobile
module Entities
class Exercise < Grape::Entity
expose :exercise_name
expose :exercise_description
end
end
end

@ -26,6 +26,8 @@ module Mobile
u.nil? || u.user_extensions.nil? ? "" : u.user_extensions.student_id
when :realname
u.nil? ? "" : get_user_realname(u)
when :name
u.nil? ? "" : u.show_name
end
end
end
@ -57,6 +59,11 @@ module Mobile
user_expose :student_num
# 活跃值
user_expose :active_count
user_expose :role_name
user_expose :name
end
end

@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/

@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/

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

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

@ -67,12 +67,15 @@ class AdminController < ApplicationController
def excellent_all_courses
name = params[:name]
@order = ""
if params[:order] == 'asc'
courses = Course.find_by_sql("SELECT c.*,count(c.id) FROM courses c,course_activities ca WHERE c.id = ca.course_id AND c.name like '%#{name}%' GROUP BY c.id ORDER BY count(c.id) asc, c.id desc")
@sort = ""
if params[:sort] && (params[:order] == 'act')
courses = Course.find_by_sql("SELECT c.*,count(c.id) FROM courses c,course_activities ca WHERE c.id = ca.course_id AND c.name like '%#{name}%' GROUP BY c.id ORDER BY count(c.id) #{params[:sort]}, c.id desc")
@order = params[:order]
elsif params[:order] == 'desc'
courses = Course.find_by_sql("SELECT c.*,count(c.id) FROM courses c,course_activities ca WHERE c.id = ca.course_id AND c.name like '%#{name}%' GROUP BY c.id ORDER BY count(c.id) DESC, c.id desc")
@sort = params[:sort]
elsif params[:sort] && (params[:order] == 'time')
courses = Course.find_by_sql("SELECT * FROM courses WHERE name like '%#{name}%' ORDER BY time #{params[:sort]},id desc")
@order = params[:order]
@sort = params[:sort]
else
courses = Course.like(name).order('created_at desc')
end
@ -99,6 +102,22 @@ class AdminController < ApplicationController
end
end
#取消精品
def cancel_excellent_course
@course = Course.find params[:id]
unless @course.nil?
if @course.is_excellent == 1 || @course.excellent_option == 1
@course.update_column('is_excellent', 0)
@course.update_column('excellent_option', 0)
end
end
respond_to do |format|
format.html{
redirect_to excellent_courses_url
}
end
end
#管理员界面课程资源列表
def course_resource_list

@ -916,4 +916,11 @@ class ApplicationController < ActionController::Base
call_hook(:controller_account_success_authentication_after, {:user => user })
end
def user_unlogged_check
if !User.current.logged?
render(:partial => 'organizations/unlogged_tip')
return false
end
true
end
end

@ -265,6 +265,10 @@ class AttachmentsController < ApplicationController
@history.save #历史记录保存完毕
#将最新保存的记录 数据替换到 需要修改的文件记录
@old_attachment.attributes = @attachment.attributes.dup.except("id","container_id","container_type","is_public","downloads", "quotes")
# 如果附件描述被修改,则保存附件
unless params[:description] == @attachment.description
@old_attachment.description = params[:description]
end
@old_attachment.save
#删除当前记录
@attachment.delete

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

Loading…
Cancel
Save