diff --git a/app/api/mobile/api.rb b/app/api/mobile/api.rb index 91cae64ef..690828b84 100644 --- a/app/api/mobile/api.rb +++ b/app/api/mobile/api.rb @@ -8,6 +8,8 @@ module Mobile require_relative 'apis/homeworks' require_relative 'apis/comments' require_relative 'apis/issues' + require_relative 'apis/activities' + require_relative 'apis/whomeworks' class API < Grape::API version 'v1', using: :path @@ -42,6 +44,8 @@ module Mobile mount Apis::Homeworks mount Apis::Comments mount Apis::Issues + mount Apis::Activities + mount Apis::Whomeworks #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? diff --git a/app/api/mobile/apis/activities.rb b/app/api/mobile/apis/activities.rb new file mode 100644 index 000000000..29cc3da8c --- /dev/null +++ b/app/api/mobile/apis/activities.rb @@ -0,0 +1,32 @@ +#coding=utf-8 + +module Mobile + module Apis + class Activities< Grape::API + resources :activities do + + desc "get user activities" + get ':id' do + #uw = UserWechat.find params[:openid] + user = User.find params[:id] + shield_project_ids = ShieldActivity.where("container_type='User' and container_id=#{user.id} and shield_type='Project'").map(&:shield_id) + shield_course_ids = ShieldActivity.where("container_type='User' and container_id=#{user.id} and shield_type='Course'").map(&:shield_id) + page = params[:page] ? params[:page].to_i + 1 : 0 + user_project_ids = (user.projects.visible.map{|project| project.id}-shield_project_ids).empty? ? "(-1)" : "(" + (user.projects.visible.map{|project| project.id}-shield_project_ids).join(",") + ")" + user_course_ids = (user.courses.visible.map{|course| course.id}-shield_course_ids).empty? ? "(-1)" : "(" + (user.courses.visible.map{|course| course.id}-shield_course_ids).join(",") + ")" + course_types = "('Message','News','HomeworkCommon','Poll','Course')" + project_types = "('Message','Issue','ProjectCreateInfo')" + principal_types = "JournalsForMessage" + + blog_ids = "("+user.blog.id.to_s+","+((User.watched_by(user.id).count == 0 )? '0' :User.watched_by(user.id).map{|u| u.blog.id}.join(','))+")" + activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types})" + + "or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}) "+ + "or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{user.id}) " + + "or (container_type = 'Blog' and act_type= 'BlogComment' and container_id in #{blog_ids})").order('updated_at desc').limit(10).offset(page * 10) + present :data, activities, with: Mobile::Entities::Activity + present :status, 0 + end + end + end + end +end \ No newline at end of file diff --git a/app/api/mobile/apis/whomeworks.rb b/app/api/mobile/apis/whomeworks.rb new file mode 100644 index 000000000..84e9e1fdf --- /dev/null +++ b/app/api/mobile/apis/whomeworks.rb @@ -0,0 +1,17 @@ +#coding=utf-8 + +module Mobile + module Apis + class Whomeworks< Grape::API + resources :whomeworks do + + desc "get one homework" + get ':id' do + homework = HomeworkCommon.find params[:id] + present :data, homework, with: Mobile::Entities::Whomework + present :status, 0 + end + end + end + end +end diff --git a/app/api/mobile/entities/activity.rb b/app/api/mobile/entities/activity.rb new file mode 100644 index 000000000..4d64a40d8 --- /dev/null +++ b/app/api/mobile/entities/activity.rb @@ -0,0 +1,102 @@ +# encoding: utf-8 +module Mobile + module Entities + class Activity news', will match and will got count as as parameter - on :text, with: /^(\d+) news$/ do |request, count| - # Wechat article can only contain max 10 items, large than 10 will dropped. - news = (1..count.to_i).each_with_object([]) { |n, memo| memo << { title: 'News title', content: "No. #{n} news content" } } - request.reply.news(news) do |article, n, index| # article is return object - article.item title: "#{index} #{n[:title]}", description: n[:content], pic_url: 'http://www.baidu.com/img/bdlogo.gif', url: 'http://www.baidu.com/' - end - end - - on :event, with: 'subscribe' do |request| - default_msg(request) - end - - # When unsubscribe user scan qrcode qrscene_xxxxxx to subscribe in public account - # notice user will subscribe public account at same time, so wechat won't trigger subscribe event any more - on :scan, with: 'qrscene_xxxxxx' do |request, ticket| - request.reply.text "Unsubscribe user #{request[:FromUserName]} Ticket #{ticket}" - end - - # When subscribe user scan scene_id in public account - on :scan, with: 'scene_id' do |request, ticket| - request.reply.text "Subscribe user #{request[:FromUserName]} Ticket #{ticket}" - end - - # When no any on :scan responder can match subscribe user scaned scene_id - on :event, with: 'scan' do |request| - if request[:EventKey].present? - request.reply.text "event scan got EventKey #{request[:EventKey]} Ticket #{request[:Ticket]}" - end - end - - # When enterprise user press menu BINDING_QR_CODE and success to scan bar code - on :scan, with: 'BINDING_QR_CODE' do |request, scan_result, scan_type| - request.reply.text "User #{request[:FromUserName]} ScanResult #{scan_result} ScanType #{scan_type}" - end - - # Except QR code, wechat can also scan CODE_39 bar code in enterprise account - on :scan, with: 'BINDING_BARCODE' do |message, scan_result| - if scan_result.start_with? 'CODE_39,' - message.reply.text "User: #{message[:FromUserName]} scan barcode, result is #{scan_result.split(',')[1]}" - end - end - - # When user click the menu button - on :click, with: 'BOOK_LUNCH' do |request, key| - request.reply.text "User: #{request[:FromUserName]} click #{key}" - end - - # When user view URL in the menu button - on :view, with: 'http://wechat.somewhere.com/view_url' do |request, view| - request.reply.text "#{request[:FromUserName]} view #{view}" - end - - # When user sent the imsage - on :image do |request| - request.reply.image(request[:MediaId]) # Echo the sent image to user - end - - # When user sent the voice - on :voice do |request| - request.reply.voice(request[:MediaId]) # Echo the sent voice to user - end - - # When user sent the video - on :video do |request| - nickname = wechat.user(request[:FromUserName])['nickname'] # Call wechat api to get sender nickname - request.reply.video(request[:MediaId], title: 'Echo', description: "Got #{nickname} sent video") # Echo the sent video to user - end - - # When user sent location - on :location do |request| - request.reply.text("Latitude: #{message[:Latitude]} Longitude: #{message[:Longitude]} Precision: #{message[:Precision]}") - end - - on :event, with: 'unsubscribe' do |request| - request.reply.success # user can not receive this message - end - - # When user enter the app / agent app - on :event, with: 'enter_agent' do |request| - request.reply.text "#{request[:FromUserName]} enter agent app now" - end - - # When batch job create/update user (incremental) finished. - on :batch_job, with: 'sync_user' do |request, batch_job| - request.reply.text "sync_user job #{batch_job[:JobId]} finished, return code #{batch_job[:ErrCode]}, return message #{batch_job[:ErrMsg]}" - end - - # When batch job replace user (full sync) finished. - on :batch_job, with: 'replace_user' do |request, batch_job| - request.reply.text "replace_user job #{batch_job[:JobId]} finished, return code #{batch_job[:ErrCode]}, return message #{batch_job[:ErrMsg]}" - end - - # When batch job invent user finished. - on :batch_job, with: 'invite_user' do |request, batch_job| - request.reply.text "invite_user job #{batch_job[:JobId]} finished, return code #{batch_job[:ErrCode]}, return message #{batch_job[:ErrMsg]}" - end - - # When batch job replace department (full sync) finished. - on :batch_job, with: 'replace_party' do |request, batch_job| - request.reply.text "replace_party job #{batch_job[:JobId]} finished, return code #{batch_job[:ErrCode]}, return message #{batch_job[:ErrMsg]}" - end - - # Any not match above will fail to below - on :fallback, respond: 'fallback message' - - on :click, with: 'FEEDBACK' do |request, key| - request.reply.text "如有反馈问题,请直接切入至输入框,发微信给我们即可" - end - - on :click, with: 'MY_NEWS' do |request, key| - default_msg(request) - end - - def default_msg(request) - uw = user_binded?(request[:FromUserName]) - if uw && uw.user - - ua = user_activity(uw.user) - logo = "http://wechat.trustie.net/images/trustie_logo2.png" - i = 0 - news =[] - ua.each do |a| - i += 1 - activity = process_activity(a) - if activity - news << {title: activity[0], - content: activity[1], - picurl: "#{i == 1 ? logo : 'https://www.trustie.net/'+activity[2]}", - url: activity[3] - } - end - - end - - request.reply.news(news) do |article, n, index| # article is return object - article.item title: "#{n[:content]}", - description: n[:title], - pic_url: "#{n[:picurl]}", - url: n[:url] - end - else - sendBind(request) - end - end - - def sendBind(request) - news = (1..1).each_with_object([]) { |n, memo| memo << { title: '绑定登录', content: "您还未绑定确实的用户,请先绑定." } } - request.reply.news(news) do |article, n, index| # article is return object - url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=#{Wechat.config.appid}&redirect_uri=#{login_wechat_url}&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect" - article.item title: "#{n[:title]}", - description: n[:content], - pic_url: 'http://wechat.trustie.net/images/trustie_logo2.png', - url: url - end - end - - - def get_open_id - begin - raise "非法操作, code不存在" unless params[:code] - openid = get_openid(params[:code]) - raise "无法获取到openid" unless openid - render :text => {status:0, openid: openid}.to_json - rescue Exception=>e - render :text => {status: -1, msg: e.message}.to_json - end - end - - def bind - begin - raise "非法操作, code不存在" unless params[:code] - openid = get_openid(params[:code]) - raise "无法获取到openid" unless openid - raise "此微信号已绑定用户, 不能得复绑定" if user_binded?(openid) - - user, last_login_on = User.try_to_login(params[:username], params[:password]) - raise "用户名或密码错误,请重新登录" unless user - #补全用户信息 - - raise "此用户已经绑定了公众号" if user.user_wechat - - UserWechat.create!( - openid: openid, - user: user - ) - render :text => {status:0, msg: "绑定成功"}.to_json - rescue Exception=>e - render :text => {status: -1, msg: e.message}.to_json - end - end - - def login - @code = params[:code] #TODO 安全性 - render 'wechats/login', layout: 'base_wechat' - end - - private - def get_openid(code) - url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=#{Wechat.config.appid}&secret=#{Wechat.config.secret}&code=#{code}&grant_type=authorization_code" - JSON.parse(URI.parse(url).read)["openid"] - end - - - def user_binded?(openid) - uw = UserWechat.where(openid: openid).first - end - - def user_activity(user) - @user = user - shield_project_ids = ShieldActivity.where("container_type='User' and container_id=#{@user.id} and shield_type='Project'").map(&:shield_id) - shield_course_ids = ShieldActivity.where("container_type='User' and container_id=#{@user.id} and shield_type='Course'").map(&:shield_id) - @page = params[:page] ? params[:page].to_i + 1 : 0 - user_project_ids = (@user.projects.visible.map{|project| project.id}-shield_project_ids).empty? ? "(-1)" : "(" + (@user.projects.visible.map{|project| project.id}-shield_project_ids).join(",") + ")" - user_course_ids = (@user.courses.visible.map{|course| course.id}-shield_course_ids).empty? ? "(-1)" : "(" + (@user.courses.visible.map{|course| course.id}-shield_course_ids).join(",") + ")" - course_types = "('Message','News','HomeworkCommon','Poll','Course')" - project_types = "('Message','Issue','ProjectCreateInfo')" - principal_types = "JournalsForMessage" - - blog_ids = "("+@user.blog.id.to_s+","+((User.watched_by(@user.id).count == 0 )? '0' :User.watched_by(@user.id).map{|u| u.blog.id}.join(','))+")" - @user_activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types})" + - "or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}) "+ - "or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{@user.id}) " + - "or (container_type = 'Blog' and act_type= 'BlogComment' and container_id in #{blog_ids})").order('updated_at desc').limit(10).offset(@page * 10) - - - end - - def process_activity(user_activity) - act= user_activity.act - case user_activity.container_type.to_s - when 'Course' - when 'Project' - case user_activity.act_type.to_s - when 'Issue' - [act.project.name.to_s+" | 项目问题", act.subject.to_s, url_to_avatar(act.author),"http://wechat.trustie.net/app.html#/issue/#{act.id}"] - end - end - end -end +#coding=utf-8 +class WechatsController < ActionController::Base + wechat_responder + + include ApplicationHelper + + # default text responder when no other match + on :text do |request, content| + request.reply.text "您的意见已收到" # Just echo + end + + # When receive 'help', will trigger this responder + on :text, with: 'help' do |request| + request.reply.text 'help content' + end + + # When receive 'news', will match and will got count as as parameter + on :text, with: /^(\d+) news$/ do |request, count| + # Wechat article can only contain max 10 items, large than 10 will dropped. + news = (1..count.to_i).each_with_object([]) { |n, memo| memo << { title: 'News title', content: "No. #{n} news content" } } + request.reply.news(news) do |article, n, index| # article is return object + article.item title: "#{index} #{n[:title]}", description: n[:content], pic_url: 'http://www.baidu.com/img/bdlogo.gif', url: 'http://www.baidu.com/' + end + end + + on :event, with: 'subscribe' do |request| + default_msg(request) + end + + # When unsubscribe user scan qrcode qrscene_xxxxxx to subscribe in public account + # notice user will subscribe public account at same time, so wechat won't trigger subscribe event any more + on :scan, with: 'qrscene_xxxxxx' do |request, ticket| + request.reply.text "Unsubscribe user #{request[:FromUserName]} Ticket #{ticket}" + end + + # When subscribe user scan scene_id in public account + on :scan, with: 'scene_id' do |request, ticket| + request.reply.text "Subscribe user #{request[:FromUserName]} Ticket #{ticket}" + end + + # When no any on :scan responder can match subscribe user scaned scene_id + on :event, with: 'scan' do |request| + if request[:EventKey].present? + request.reply.text "event scan got EventKey #{request[:EventKey]} Ticket #{request[:Ticket]}" + end + end + + # When enterprise user press menu BINDING_QR_CODE and success to scan bar code + on :scan, with: 'BINDING_QR_CODE' do |request, scan_result, scan_type| + request.reply.text "User #{request[:FromUserName]} ScanResult #{scan_result} ScanType #{scan_type}" + end + + # Except QR code, wechat can also scan CODE_39 bar code in enterprise account + on :scan, with: 'BINDING_BARCODE' do |message, scan_result| + if scan_result.start_with? 'CODE_39,' + message.reply.text "User: #{message[:FromUserName]} scan barcode, result is #{scan_result.split(',')[1]}" + end + end + + # When user click the menu button + on :click, with: 'BOOK_LUNCH' do |request, key| + request.reply.text "User: #{request[:FromUserName]} click #{key}" + end + + # When user view URL in the menu button + on :view, with: 'http://wechat.somewhere.com/view_url' do |request, view| + request.reply.text "#{request[:FromUserName]} view #{view}" + end + + # When user sent the imsage + on :image do |request| + request.reply.image(request[:MediaId]) # Echo the sent image to user + end + + # When user sent the voice + on :voice do |request| + request.reply.voice(request[:MediaId]) # Echo the sent voice to user + end + + # When user sent the video + on :video do |request| + nickname = wechat.user(request[:FromUserName])['nickname'] # Call wechat api to get sender nickname + request.reply.video(request[:MediaId], title: 'Echo', description: "Got #{nickname} sent video") # Echo the sent video to user + end + + # When user sent location + on :location do |request| + request.reply.text("Latitude: #{message[:Latitude]} Longitude: #{message[:Longitude]} Precision: #{message[:Precision]}") + end + + on :event, with: 'unsubscribe' do |request| + request.reply.success # user can not receive this message + end + + # When user enter the app / agent app + on :event, with: 'enter_agent' do |request| + request.reply.text "#{request[:FromUserName]} enter agent app now" + end + + # When batch job create/update user (incremental) finished. + on :batch_job, with: 'sync_user' do |request, batch_job| + request.reply.text "sync_user job #{batch_job[:JobId]} finished, return code #{batch_job[:ErrCode]}, return message #{batch_job[:ErrMsg]}" + end + + # When batch job replace user (full sync) finished. + on :batch_job, with: 'replace_user' do |request, batch_job| + request.reply.text "replace_user job #{batch_job[:JobId]} finished, return code #{batch_job[:ErrCode]}, return message #{batch_job[:ErrMsg]}" + end + + # When batch job invent user finished. + on :batch_job, with: 'invite_user' do |request, batch_job| + request.reply.text "invite_user job #{batch_job[:JobId]} finished, return code #{batch_job[:ErrCode]}, return message #{batch_job[:ErrMsg]}" + end + + # When batch job replace department (full sync) finished. + on :batch_job, with: 'replace_party' do |request, batch_job| + request.reply.text "replace_party job #{batch_job[:JobId]} finished, return code #{batch_job[:ErrCode]}, return message #{batch_job[:ErrMsg]}" + end + + # Any not match above will fail to below + on :fallback, respond: 'fallback message' + + on :click, with: 'FEEDBACK' do |request, key| + request.reply.text "如有反馈问题,请直接切入至输入框,发微信给我们即可" + end + + on :click, with: 'MY_NEWS' do |request, key| + default_msg(request) + end + + def default_msg(request) + uw = user_binded?(request[:FromUserName]) + if uw && uw.user + + ua = user_activity(uw.user) + logo = "http://wechat.trustie.net/images/trustie_logo2.png" + i = 0 + news =[] + ua.each do |a| + i += 1 + activity = process_activity(a) + if activity + news << {title: activity[0], + content: activity[1], + picurl: "#{i == 1 ? logo : 'https://www.trustie.net/'+activity[2]}", + url: activity[3] + } + end + + end + + request.reply.news(news) do |article, n, index| # article is return object + article.item title: "#{n[:content]}", + description: n[:title], + pic_url: "#{n[:picurl]}", + url: n[:url] + end + else + sendBind(request) + end + end + + def sendBind(request) + news = (1..1).each_with_object([]) { |n, memo| memo << { title: '绑定登录', content: "您还未绑定确实的用户,请先绑定." } } + request.reply.news(news) do |article, n, index| # article is return object + url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=#{Wechat.config.appid}&redirect_uri=#{login_wechat_url}&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect" + article.item title: "#{n[:title]}", + description: n[:content], + pic_url: 'http://wechat.trustie.net/images/trustie_logo2.png', + url: url + end + end + + + def get_open_id + begin + raise "非法操作, code不存在" unless params[:code] + openid = get_openid(params[:code]) + raise "无法获取到openid" unless openid + render :text => {status:0, openid: openid}.to_json + rescue Exception=>e + render :text => {status: -1, msg: e.message}.to_json + end + end + + def bind + begin + raise "非法操作, code不存在" unless params[:code] + openid = get_openid(params[:code]) + raise "无法获取到openid" unless openid + raise "此微信号已绑定用户, 不能得复绑定" if user_binded?(openid) + + user, last_login_on = User.try_to_login(params[:username], params[:password]) + raise "用户名或密码错误,请重新登录" unless user + #补全用户信息 + + raise "此用户已经绑定了公众号" if user.user_wechat + + UserWechat.create!( + openid: openid, + user: user + ) + render :text => {status:0, msg: "绑定成功"}.to_json + rescue Exception=>e + render :text => {status: -1, msg: e.message}.to_json + end + end + + def login + @code = params[:code] #TODO 安全性 + render 'wechats/login', layout: 'base_wechat' + end + + private + def get_openid(code) + url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=#{Wechat.config.appid}&secret=#{Wechat.config.secret}&code=#{code}&grant_type=authorization_code" + JSON.parse(URI.parse(url).read)["openid"] + end + + + def user_binded?(openid) + uw = UserWechat.where(openid: openid).first + end + + def user_activity(user) + @user = user + shield_project_ids = ShieldActivity.where("container_type='User' and container_id=#{@user.id} and shield_type='Project'").map(&:shield_id) + shield_course_ids = ShieldActivity.where("container_type='User' and container_id=#{@user.id} and shield_type='Course'").map(&:shield_id) + @page = params[:page] ? params[:page].to_i + 1 : 0 + user_project_ids = (@user.projects.visible.map{|project| project.id}-shield_project_ids).empty? ? "(-1)" : "(" + (@user.projects.visible.map{|project| project.id}-shield_project_ids).join(",") + ")" + user_course_ids = (@user.courses.visible.map{|course| course.id}-shield_course_ids).empty? ? "(-1)" : "(" + (@user.courses.visible.map{|course| course.id}-shield_course_ids).join(",") + ")" + course_types = "('Message','News','HomeworkCommon','Poll','Course')" + project_types = "('Message','Issue','ProjectCreateInfo')" + principal_types = "JournalsForMessage" + + blog_ids = "("+@user.blog.id.to_s+","+((User.watched_by(@user.id).count == 0 )? '0' :User.watched_by(@user.id).map{|u| u.blog.id}.join(','))+")" + @user_activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types})" + + "or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}) "+ + "or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{@user.id}) " + + "or (container_type = 'Blog' and act_type= 'BlogComment' and container_id in #{blog_ids})").order('updated_at desc').limit(10).offset(@page * 10) + + + end + + def process_activity(user_activity) + act= user_activity.act + case user_activity.container_type.to_s + when 'Course' + when 'Project' + case user_activity.act_type.to_s + when 'Issue' + [act.project.name.to_s+" | 项目问题", act.subject.to_s, url_to_avatar(act.author),"http://wechat.trustie.net/app.html#/issue/#{act.id}"] + end + end + end +end diff --git a/app/helpers/api_helper.rb b/app/helpers/api_helper.rb index 8324951f9..fd0157b67 100644 --- a/app/helpers/api_helper.rb +++ b/app/helpers/api_helper.rb @@ -201,5 +201,43 @@ module ApiHelper end + #日期转换为时间 + def convert_to_time date, num + if num == 0 + date = date.to_s + " 00:00" + elsif num == 1 + date = date.to_s + " 23:59" + end + return date + end + #获取用户 + def get_user user_id + user = User.find user_id + user + end + + #获取项目 + def get_project project_id + project = Project.find project_id + project + end + + #获取课程 + def get_course course_id + course = Course.find course_id + course + end + + #获取点赞数 + def get_activity_praise_num(object) + obj_type = object.class + obj_id = object.id + record = PraiseTreadCache.find_by_object_id_and_object_type(obj_id,obj_type) + if record + return ((record.praise_num.nil? ? 0 : record.praise_num.to_i)-(record.tread_num.nil? ? 0 : record.tread_num.to_i)) + else + return 0 + end + end end \ No newline at end of file diff --git a/config/application.rb b/config/application.rb index 9e6d41abe..aedb1a708 100644 --- a/config/application.rb +++ b/config/application.rb @@ -48,8 +48,10 @@ module RedmineApp # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] - config.i18n.default_locale = :zh + #config.i18n.default_locale = :zh + config.i18n.enforce_available_locales = true + I18n.config.enforce_available_locales = true # Configure the default encoding used in templates for Ruby 1.9. config.encoding = "utf-8" diff --git a/config/menu.yml b/config/menu.yml index 106bbfd07..4072f5793 100644 --- a/config/menu.yml +++ b/config/menu.yml @@ -1,20 +1,20 @@ -button: - - - type: "view" - name: "最新动态" - url: "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxc09454f171153c2d&redirect_uri=http://wechat.trustie.net/assets/wechat/issue.html&response_type=code&scope=snsapi_base&state=123#wechat_redirect" - - - type: "click" - name: "意见返馈" - key: "FEEDBACK" - - - name: "更多" - sub_button: - - - type: "view" - name: "进入网站" - url: "http://www.trustie.net/" - - - type: "view" - name: "使用手册" +button: + - + type: "view" + name: "最新动态" + url: "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxc09454f171153c2d&redirect_uri=http://wechat.trustie.net/assets/wechat/issue.html&response_type=code&scope=snsapi_base&state=123#wechat_redirect" + - + type: "click" + name: "意见返馈" + key: "FEEDBACK" + - + name: "更多" + sub_button: + - + type: "view" + name: "进入网站" + url: "http://www.trustie.net/" + - + type: "view" + name: "使用手册" url: "https://www.trustie.net/organizations/1/downloads" \ No newline at end of file diff --git a/db/schema.rb b/db/schema.rb index c9b53c6aa..75f316f06 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20160225024759) do +ActiveRecord::Schema.define(:version => 20160317090350) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -432,9 +432,11 @@ ActiveRecord::Schema.define(:version => 20160225024759) do t.integer "resource_num" t.integer "journal_num" t.integer "journal_reply_num" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false t.integer "total_score" + t.integer "homework_journal_num", :default => 0 + t.integer "news_num", :default => 0 end create_table "course_groups", :force => true do |t| @@ -506,6 +508,7 @@ ActiveRecord::Schema.define(:version => 20160225024759) do t.integer "is_excellent", :default => 0 t.integer "excellent_option", :default => 0 t.integer "is_copy", :default => 0 + t.integer "visits", :default => 0 end create_table "custom_fields", :force => true do |t| @@ -1282,6 +1285,7 @@ ActiveRecord::Schema.define(:version => 20160225024759) do t.datetime "created_at", :null => false t.datetime "updated_at", :null => false t.boolean "allow_guest_download", :default => true + t.integer "visits", :default => 0 end create_table "phone_app_versions", :force => true do |t| @@ -1441,6 +1445,7 @@ ActiveRecord::Schema.define(:version => 20160225024759) do t.integer "acts_count", :default => 0 t.integer "journals_count", :default => 0 t.integer "boards_reply_count", :default => 0 + t.integer "visits", :default => 0 end add_index "projects", ["lft"], :name => "index_projects_on_lft" @@ -1777,6 +1782,14 @@ ActiveRecord::Schema.define(:version => 20160225024759) do t.integer "fields_bits", :default => 0 end + create_table "user_actions", :force => true do |t| + t.integer "user_id" + t.string "action_type" + t.integer "action_id" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + create_table "user_activities", :force => true do |t| t.string "act_type" t.integer "act_id" @@ -1919,6 +1932,7 @@ ActiveRecord::Schema.define(:version => 20160225024759) do t.string "mail_notification", :default => "", :null => false t.string "salt", :limit => 64 t.integer "gid" + t.integer "visits", :default => 0 end add_index "users", ["auth_source_id"], :name => "index_users_on_auth_source_id" diff --git a/public/assets/wechat/activities.html b/public/assets/wechat/activities.html new file mode 100644 index 000000000..eb537363d --- /dev/null +++ b/public/assets/wechat/activities.html @@ -0,0 +1,221 @@ + + + + react js + + + + + + + + + + + +
+ + + + + + + + + + + + + \ No newline at end of file diff --git a/public/assets/wechat/issue.html b/public/assets/wechat/issue.html index f49dfdcfa..558496ef0 100644 --- a/public/assets/wechat/issue.html +++ b/public/assets/wechat/issue.html @@ -1,50 +1,50 @@ - - - - react js - - - - - - - - - - - -
- - - - - - - - - + + + + react js + + + + + + + + + + + +
+ + + + + + + + + \ No newline at end of file diff --git a/public/javascripts/wechat/auth.js b/public/javascripts/wechat/auth.js index 7ee274928..1d9682720 100644 --- a/public/javascripts/wechat/auth.js +++ b/public/javascripts/wechat/auth.js @@ -1,35 +1,35 @@ -$(function(){ - //获取url中的参数 - function getUrlParam(name) { - var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象 - var r = window.location.search.substr(1).match(reg); //匹配目标参数 - if (r != null) return unescape(r[2]); return null; //返回参数值 - } - - - var debug = false; - - var g_openid = ""; - if(debug){ - g_openid = "填写要调试的openid即可"; - } - - window.getOpenId = function(cb){ - if (g_openid.length>0){ - cb(g_openid); - } - var code = getUrlParam("code"); - $.ajax({ - url: '/wechat/get_open_id?code='+code, - type: 'get', - dataType: 'json', - success: function(data){ - g_openid = data.openid; - cb(g_openid); - }, - error: function(xhr,err){ - alert("认证失败: "+err); - } - }); - } +$(function(){ + //获取url中的参数 + function getUrlParam(name) { + var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象 + var r = window.location.search.substr(1).match(reg); //匹配目标参数 + if (r != null) return unescape(r[2]); return null; //返回参数值 + } + + + var debug = false; + + var g_openid = ""; + if(debug){ + g_openid = "填写要调试的openid即可"; + } + + window.getOpenId = function(cb){ + if (g_openid.length>0){ + cb(g_openid); + } + var code = getUrlParam("code"); + $.ajax({ + url: '/wechat/get_open_id?code='+code, + type: 'get', + dataType: 'json', + success: function(data){ + g_openid = data.openid; + cb(g_openid); + }, + error: function(xhr,err){ + alert("认证失败: "+err); + } + }); + } }); \ No newline at end of file diff --git a/public/javascripts/wechat/wechat-dev.js b/public/javascripts/wechat/wechat-dev.js index 78e4a55ff..ab9bdf17d 100644 --- a/public/javascripts/wechat/wechat-dev.js +++ b/public/javascripts/wechat/wechat-dev.js @@ -8,17 +8,19 @@ $(document).ready(function(){ bt.RIGHT_DELIMITER='!>'; - var apiUrl = '/api/v1/' + var apiUrl = '/api/v1/'; var setTemplate = function(data){ console.log(data); - var html=bt('t:result-list',{issues: data}); + var html=bt('t:result-list',{activities: data}); $('#container').prepend(html); - } + descToggle(); + + }; var loadDataFromServer = function(id){ - getOpenId(function(openid){ + //getOpenId(function(openid){ $.ajax({ - url: apiUrl + 'issues/' + id + "?openid="+openid, + url: apiUrl + 'activities/' + id, dataType: 'json', success: function(data){ setTemplate(data.data); @@ -27,30 +29,37 @@ $(document).ready(function(){ console.log(err); } }); - }) + //}) }; + loadDataFromServer(8686); + + var descToggle = function(){ + var postWidth = $(".post-wrapper").width(); + var titleWidth = postWidth - 80; + $(".post-title").css("maxWidth",titleWidth); + $(".post-all-content").each(function(){ + var postHeight = $(this).height(); + if (postHeight > 90){ + $(this).parent().next().css("display","block"); + $(this).parent().next().toggle(function(){ + $(this).text("点击隐藏"); + $(this).prev().css("height",postHeight); + },function(){ + $(this).text("点击展开"); + $(this).prev().css("height",90); + }); + } + }); + } + + var timeSpilt = function(){ + + } - loadDataFromServer(299); - var postWidth = $(".post-wrapper").width(); - var titleWidth = postWidth - 80; - $(".post-title").css("maxWidth",titleWidth); - $(".post-all-content").each(function(){ - var postHeight = $(this).height(); - if (postHeight > 90){ - $(this).parent().next().css("display","block"); - $(this).parent().next().toggle(function(){ - $(this).text("点击隐藏"); - $(this).prev().css("height",postHeight); - },function(){ - $(this).text("点击展开"); - $(this).prev().css("height",90); - }); - } - }); }); diff --git a/public/javascripts/wechat/wechat.jsx b/public/javascripts/wechat/wechat.jsx index 86d92318b..2c9f15363 100644 --- a/public/javascripts/wechat/wechat.jsx +++ b/public/javascripts/wechat/wechat.jsx @@ -1,6 +1,7 @@ /** * Created by guange on 16/3/21. - */ + *//* + var Index = React.createClass({ render: function(){ @@ -10,8 +11,6 @@ var Index = React.createClass({ var apiUrl = '/api/v1/'; -var converter = new Showdown.converter(); - var PostContainer = React.createClass({ loadDataFromServer: function(){ $.ajax({ @@ -34,7 +33,7 @@ var PostContainer = React.createClass({ render: function(){ return ( - )issues + ) } }); @@ -95,3 +94,4 @@ var routes = ( React.render(routes, document.getElementById("container")); +*/