From a9fd79ec633a877ed7aa68edb26cbf2b18532904 Mon Sep 17 00:00:00 2001 From: Tim Date: Mon, 28 Mar 2016 14:45:11 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E5=8A=A8=E6=80=81?= =?UTF-8?q?=E7=AD=9B=E9=80=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/assets/wechat/acitivities.html | 220 ++++++++++++++++++++++++ public/javascripts/wechat/wechat-dev.js | 48 ++++-- 2 files changed, 249 insertions(+), 19 deletions(-) create mode 100644 public/assets/wechat/acitivities.html diff --git a/public/assets/wechat/acitivities.html b/public/assets/wechat/acitivities.html new file mode 100644 index 000000000..87c697aba --- /dev/null +++ b/public/assets/wechat/acitivities.html @@ -0,0 +1,220 @@ + + + + react js + + + + + + + + + + + +
+ + + + + + + + + + + + \ No newline at end of file diff --git a/public/javascripts/wechat/wechat-dev.js b/public/javascripts/wechat/wechat-dev.js index 9c5704b8c..56a95ac72 100644 --- a/public/javascripts/wechat/wechat-dev.js +++ b/public/javascripts/wechat/wechat-dev.js @@ -15,11 +15,13 @@ $(document).ready(function(){ var html=bt('t:result-list',{issues: data}); $('#container').prepend(html); + descToggle(); + } - var loadDataFromServer = function(id){ + var loadDataFromServer = function(page){ $.ajax({ - url: apiUrl + 'issues/' + id, + url: apiUrl + 'activities/' + page + "?openid=", dataType: 'json', success: function(data){ setTemplate(data.data); @@ -31,24 +33,32 @@ $(document).ready(function(){ }; - loadDataFromServer(299); + loadDataFromServer(0); + + 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(){ + + } + - 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); - }); - } - }); }); From 4de598873fb6b623751fa6d16c2af206084de352 Mon Sep 17 00:00:00 2001 From: Yiang Gan Date: Wed, 30 Mar 2016 10:32:45 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=8A=A8=E6=80=81=E5=92=8C=E4=BD=9C?= =?UTF-8?q?=E4=B8=9A=E7=9A=84api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/mobile/api.rb | 4 + app/api/mobile/apis/activities.rb | 32 ++++++ app/api/mobile/apis/whomeworks.rb | 17 +++ app/api/mobile/entities/activity.rb | 102 ++++++++++++++++++ app/api/mobile/entities/whomework.rb | 53 +++++++++ app/helpers/api_helper.rb | 38 +++++++ config/application.rb | 4 +- db/schema.rb | 20 +++- .../{acitivities.html => activities.html} | 1 + public/assets/wechat/issue.html | 2 +- public/javascripts/wechat/wechat-dev.js | 17 ++- public/javascripts/wechat/wechat.jsx | 8 +- 12 files changed, 280 insertions(+), 18 deletions(-) create mode 100644 app/api/mobile/apis/activities.rb create mode 100644 app/api/mobile/apis/whomeworks.rb create mode 100644 app/api/mobile/entities/activity.rb create mode 100644 app/api/mobile/entities/whomework.rb rename public/assets/wechat/{acitivities.html => activities.html} (97%) 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 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/acitivities.html b/public/assets/wechat/activities.html similarity index 97% rename from public/assets/wechat/acitivities.html rename to public/assets/wechat/activities.html index 87c697aba..eb537363d 100644 --- a/public/assets/wechat/acitivities.html +++ b/public/assets/wechat/activities.html @@ -216,5 +216,6 @@ + \ No newline at end of file diff --git a/public/assets/wechat/issue.html b/public/assets/wechat/issue.html index 4c26551b1..558496ef0 100644 --- a/public/assets/wechat/issue.html +++ b/public/assets/wechat/issue.html @@ -18,7 +18,7 @@