From 3c426c8d15f4d79e3c6deda13308ddc39ee9375e Mon Sep 17 00:00:00 2001 From: yuanke <249218296@qq.com> Date: Thu, 14 Jul 2016 09:52:02 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E4=B8=AD=E8=8B=B1?= =?UTF-8?q?=E6=96=87=E9=80=97=E5=8F=B7=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/wechat.yml | 13 +++++++++++++ public/assets/wechat/class.html | 12 ++++++------ public/assets/wechat/myresource.html | 12 ++++++------ 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/config/wechat.yml b/config/wechat.yml index 1992a332a..8b2caffc8 100644 --- a/config/wechat.yml +++ b/config/wechat.yml @@ -18,6 +18,19 @@ default: &default token: "123456" access_token: "1234567" encrypt_mode: false # if true must fill encoding_aes_key + + #production +# encoding_aes_key: "QGfP13YP4BbQGkkrlYuxpn4ZIDXpBJww4fxl8CObvNw" +# jsapi_ticket: "C:/Users/[user_name]/wechat_jsapi_ticket" +# +# #template +# binding_succ_notice: "jjpDrgFErnmkrE9tf2M3o0t31ZrJ7mr0YtuE_wyLaMc" +# journal_notice: "uC1zAw4F2q6HTA3Pcj8VUO6wKKKiYFwnPJB4iXxpdoM" +# homework_message_notice: "tCf7teCVqc2vl2LZ_hppIdWmpg8yLcrI8XifxYePjps" +# class_notice: "MQ_mFupbXP-9jWbeHT3C5xqNBvPo8EIlNv4ULakSpJA" +# create_class_notice: "2GtJJGzzNlNy2i0UrsjEDlvfSVIUXQfSo47stpcQAVw" + + #test encoding_aes_key: "QyocNOkRmrT5HzBpCG54EVPUQjk86nJapXNVDQm6Yy6" jsapi_ticket: "C:/Users/[user_name]/wechat_jsapi_ticket" diff --git a/public/assets/wechat/class.html b/public/assets/wechat/class.html index 85dd1c8de..da58003cc 100644 --- a/public/assets/wechat/class.html +++ b/public/assets/wechat/class.html @@ -24,8 +24,8 @@
{{r.filename}}发送
-

暂无课件,
- 请登录Trustie网站,在PC浏览器中上传课件。

+

暂无课件,
+ 请登录Trustie网站,在PC浏览器中上传课件。

授课老师
@@ -43,15 +43,15 @@
{{r.homework_name}}发送
-

暂无作业,
- 请登录Trustie网站,在PC浏览器中上传作业。

+

暂无作业,
+ 请登录Trustie网站,在PC浏览器中上传作业。

{{r.exercise_name}}发送
-

暂无小测验,
- 请登录Trustie网站,在PC浏览器中上传小测验。

+

暂无小测验,
+ 请登录Trustie网站,在PC浏览器中上传小测验。

diff --git a/public/assets/wechat/myresource.html b/public/assets/wechat/myresource.html index b1c55c0c0..53eb3a23e 100644 --- a/public/assets/wechat/myresource.html +++ b/public/assets/wechat/myresource.html @@ -15,22 +15,22 @@ {{r.filename}}发送
课件来源:{{r.coursename}}大小:{{r.attafile_size}}
-

暂无课件,
- 请登录Trustie网站,在PC浏览器中上传课件。

+

暂无课件,
+ 请登录Trustie网站,在PC浏览器中上传课件。

{{r.homework_name}}发送
作业来源:{{r.coursename}}
-

暂无作业,
- 请登录Trustie网站,在PC浏览器中创建作业。

+

暂无作业,
+ 请登录Trustie网站,在PC浏览器中创建作业。

{{r.exercise_name}}发送
题目来源:{{r.coursename}}
-

暂无测验,
- 请登录Trustie网站,在PC浏览器中创建测验。

+

暂无测验,
+ 请登录Trustie网站,在PC浏览器中创建测验。

From c2fadc54ef38d4a4bc6e2ecfe30d19f08789d561 Mon Sep 17 00:00:00 2001 From: yuanke <249218296@qq.com> Date: Thu, 14 Jul 2016 11:16:45 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E9=80=9A=E7=9F=A5=E7=82=B9=E5=87=BB=E8=B7=B3=E8=BD=AC=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/mobile/apis/users.rb | 4 ++-- app/services/wechat_service.rb | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/api/mobile/apis/users.rb b/app/api/mobile/apis/users.rb index a6536e73e..e2ea8d35b 100644 --- a/app/api/mobile/apis/users.rb +++ b/app/api/mobile/apis/users.rb @@ -41,8 +41,8 @@ module Mobile openid: openid, user: user ) - # ws = WechatService.new - # ws.binding_succ_notice(user.id, "您已成功绑定Trustie平台", user.login, format_time(Time.now)) + ws = WechatService.new + ws.binding_succ_notice(user.id, "您已成功绑定Trustie平台", user.login, Time.now.strftime("%Y-%m-%d")) present status: 0, message: '您已成功绑定Trustie平台' end diff --git a/app/services/wechat_service.rb b/app/services/wechat_service.rb index 3097e1842..6bb93400d 100644 --- a/app/services/wechat_service.rb +++ b/app/services/wechat_service.rb @@ -115,7 +115,7 @@ class WechatService data = { touser:openid, template_id:template_id, - url:"#{Setting.protocol}://#{Setting.host_name}/assets/wechat/app.html#/#{type}/#{id}", + url:"#{Setting.protocol}://#{Setting.host_name}/assets/wechat/user_activities#/#{type}/#{id}",#user_activities 本来是app.html topcolor:"#FF0000", data:{ first: { @@ -143,7 +143,7 @@ class WechatService data = { touser:openid, template_id:template_id, - url:"#{Setting.protocol}://#{Setting.host_name}/assets/wechat/app.html#/#{type}/#{id}", + url:"#{Setting.protocol}://#{Setting.host_name}/assets/wechat/user_activities#/#{type}/#{id}",#user_activities 本来是app.html topcolor:"#FF0000", data:{ first: { @@ -175,7 +175,7 @@ class WechatService data = { touser:openid, template_id:template_id, - url:"#{Setting.protocol}://#{Setting.host_name}/assets/wechat/app.html#/#{type}/#{id}", + url:"#{Setting.protocol}://#{Setting.host_name}/assets/wechat/user_activities#/#{type}/#{id}", #user_activities 本来是app.html topcolor:"#FF0000", data:{ first: { From 5bd404322b9ddeb6c44f08bee11081c7ee9b3a68 Mon Sep 17 00:00:00 2001 From: yuanke <249218296@qq.com> Date: Thu, 14 Jul 2016 11:28:28 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=BE=AE=E4=BF=A1?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E9=80=9A=E7=9F=A5=E8=AF=A6=E6=83=85=E5=9C=B0?= =?UTF-8?q?=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/wechat_service.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/services/wechat_service.rb b/app/services/wechat_service.rb index 6bb93400d..2da942ea6 100644 --- a/app/services/wechat_service.rb +++ b/app/services/wechat_service.rb @@ -115,7 +115,7 @@ class WechatService data = { touser:openid, template_id:template_id, - url:"#{Setting.protocol}://#{Setting.host_name}/assets/wechat/user_activities#/#{type}/#{id}",#user_activities 本来是app.html + url:"#{Setting.protocol}://#{Setting.host_name}/wechat/user_activities#/#{type}/#{id}",#/assets/wechat/app.html#/#{type}/#{id} topcolor:"#FF0000", data:{ first: { @@ -143,7 +143,7 @@ class WechatService data = { touser:openid, template_id:template_id, - url:"#{Setting.protocol}://#{Setting.host_name}/assets/wechat/user_activities#/#{type}/#{id}",#user_activities 本来是app.html + url:"#{Setting.protocol}://#{Setting.host_name}/wechat/user_activities#/#{type}/#{id}",#/assets/wechat/app.html#/#{type}/#{id} topcolor:"#FF0000", data:{ first: { @@ -175,7 +175,7 @@ class WechatService data = { touser:openid, template_id:template_id, - url:"#{Setting.protocol}://#{Setting.host_name}/assets/wechat/user_activities#/#{type}/#{id}", #user_activities 本来是app.html + url:"#{Setting.protocol}://#{Setting.host_name}/wechat/user_activities#/#{type}/#{id}", #/assets/wechat/app.html#/#{type}/#{id} topcolor:"#FF0000", data:{ first: { From 9c560e56b69ef087de2e095909276f0a1e589e20 Mon Sep 17 00:00:00 2001 From: yuanke <249218296@qq.com> Date: Thu, 14 Jul 2016 16:54:43 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E4=BF=AE=E6=94=B9=20?= =?UTF-8?q?=E4=B8=8D=E8=83=BD=E7=9B=B4=E6=8E=A5=E7=BB=99=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93=E5=AF=B9=E8=B1=A1=E5=A2=9E=E5=8A=A0=E6=96=B0=E5=B1=9E?= =?UTF-8?q?=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/mobile/apis/courses.rb | 10 ++++----- app/api/mobile/apis/resources.rb | 6 ++--- app/api/mobile/apis/syllabuses.rb | 7 +++--- app/api/mobile/entities/attachment.rb | 5 +++++ app/api/mobile/entities/course.rb | 18 ++++++++++++++- app/api/mobile/entities/exercise.rb | 25 ++++++++++++++++++++- app/api/mobile/entities/homework.rb | 2 ++ app/api/mobile/entities/syllabus.rb | 10 +++++---- app/services/resources_service.rb | 27 +++++++++++------------ app/services/syllabuses_service.rb | 6 ++--- public/assets/wechat/myresource.html | 4 ++-- public/assets/wechat/send_class_list.html | 2 +- 12 files changed, 84 insertions(+), 38 deletions(-) diff --git a/app/api/mobile/apis/courses.rb b/app/api/mobile/apis/courses.rb index 1cde439b2..5908ef866 100644 --- a/app/api/mobile/apis/courses.rb +++ b/app/api/mobile/apis/courses.rb @@ -17,7 +17,7 @@ module Mobile authenticate! cs = CoursesService.new courses = cs.user_courses_list(current_user) - present :data, courses, with: Mobile::Entities::Course + present :data, courses, with: Mobile::Entities::Course,user: current_user present :status, 0 end @@ -56,7 +56,7 @@ module Mobile class_period: params[:class_period] } courses = cs.create_course(cs_params, current_user) - present :data, courses, with: Mobile::Entities::Course + present :data, courses, with: Mobile::Entities::Course,user: current_user present :status, 0 end @@ -90,7 +90,7 @@ module Mobile end cs.edit_course_authorize(current_user,course) course = cs.edit_course(cs_params, course,current_user) - present :data, course, with: Mobile::Entities::Course + present :data, course, with: Mobile::Entities::Course,user: current_user present :status, 0 end post do @@ -138,7 +138,7 @@ module Mobile get 'search' do cs = CoursesService.new courses = cs.search_course(params,current_user.nil? ? User.find(2):current_user) - present :data, courses, with: Mobile::Entities::Course + present :data, courses, with: Mobile::Entities::Course,user: current_user present :status, 0 end @@ -201,7 +201,7 @@ module Mobile cs = CoursesService.new course = cs.show_course(params,(current_user.nil? ? User.find(2):current_user)) #course = Course.find(params[:id]) - present :data, course, with: Mobile::Entities::Course + present :data, course, with: Mobile::Entities::Course,user: current_user { status: 0} end end diff --git a/app/api/mobile/apis/resources.rb b/app/api/mobile/apis/resources.rb index 9bd07a0d5..16531940f 100644 --- a/app/api/mobile/apis/resources.rb +++ b/app/api/mobile/apis/resources.rb @@ -14,7 +14,7 @@ module Mobile rs = ResourcesService.new # data = current_user.course_attachments data = rs.all_course_attachments current_user - present :data, data, with: Mobile::Entities::Attachment + present :data, data, with: Mobile::Entities::Attachment,user: current_user present :status, 0 end @@ -31,7 +31,7 @@ module Mobile rs = ResourcesService.new homeworks = rs.all_homework_commons current_user - present :data, homeworks, with: Mobile::Entities::Homework + present :data, homeworks, with: Mobile::Entities::Homework,user: current_user present :status, 0 end @@ -45,7 +45,7 @@ module Mobile rs = ResourcesService.new exercises = rs.all_exercises current_user - present :data, exercises, with: Mobile::Entities::Exercise + present :data, exercises, with: Mobile::Entities::Exercise,user: current_user present :status, 0 end diff --git a/app/api/mobile/apis/syllabuses.rb b/app/api/mobile/apis/syllabuses.rb index 57db4cb9e..8538fae99 100644 --- a/app/api/mobile/apis/syllabuses.rb +++ b/app/api/mobile/apis/syllabuses.rb @@ -14,7 +14,7 @@ module Mobile cs = SyllabusesService.new courses = cs.user_syllabus(current_user) - present :data, courses, with: Mobile::Entities::Syllabus + present :data, courses, with: Mobile::Entities::Syllabus,user: current_user present :status, 0 end @@ -29,9 +29,8 @@ module Mobile sy = ::Syllabus.find(params[:id]) sy.courses = sy.courses.not_deleted - sy = ss.judge_can_setting(sy,current_user) - present :data, sy, with: Mobile::Entities::Syllabus + present :data, sy, with: Mobile::Entities::Syllabus,user: current_user present :status, 0 end @@ -68,7 +67,7 @@ module Mobile if sy.new_record? {status:-1, message: '创建大纲失败' } else - present :data, sy, with: Mobile::Entities::Syllabus + present :data, sy, with: Mobile::Entities::Syllabus,user: current_user present :status, 0 end diff --git a/app/api/mobile/entities/attachment.rb b/app/api/mobile/entities/attachment.rb index ab6f6fd71..49cb6bd2b 100644 --- a/app/api/mobile/entities/attachment.rb +++ b/app/api/mobile/entities/attachment.rb @@ -2,6 +2,7 @@ module Mobile module Entities class Attachment < Grape::Entity include Redmine::I18n + include ActionView::Helpers::NumberHelper def self.attachment_expose(field) expose field do |f,opt| if f.is_a?(Hash) && f.key?(field) @@ -17,6 +18,10 @@ module Mobile case field when :file_dir "attachments/download/" << f.send(:id).to_s << '/' + when :attafile_size + (number_to_human_size(f.filesize)).gsub("ytes", "").to_s + when :coursename + f.course.nil? ? "" : f.course.name end end end diff --git a/app/api/mobile/entities/course.rb b/app/api/mobile/entities/course.rb index d44869a60..060f43614 100644 --- a/app/api/mobile/entities/course.rb +++ b/app/api/mobile/entities/course.rb @@ -2,6 +2,8 @@ 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 @@ -52,7 +54,21 @@ module Mobile course_expose :updated_at course_expose :course_student_num course_expose :member_count - course_expose :can_setting + expose :can_setting, if: lambda { |instance, options| options[:user] } do |instance, options| + current_user = options[:user] + can_setting = false + member = instance.members.where("user_id=#{current_user.id} and course_id=#{instance.id}")[0] + roleName = member.roles[0].name if member + + if roleName && (roleName == "TeachingAsistant" || roleName == "Teacher" ) + can_setting = true + end + + if instance.tea_id == current_user.id + can_setting = true + end + can_setting + end expose :teacher, using: Mobile::Entities::User do |c, opt| if c.is_a? ::Course c.teacher diff --git a/app/api/mobile/entities/exercise.rb b/app/api/mobile/entities/exercise.rb index 14c530a9b..05066f8a4 100644 --- a/app/api/mobile/entities/exercise.rb +++ b/app/api/mobile/entities/exercise.rb @@ -1,9 +1,32 @@ 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 + end + end + end + end + end expose :exercise_name expose :exercise_description - expose :coursename #所属班级名 + exercise_expose :coursename #所属班级名 end end end diff --git a/app/api/mobile/entities/homework.rb b/app/api/mobile/entities/homework.rb index 17127f0f2..3f1631c96 100644 --- a/app/api/mobile/entities/homework.rb +++ b/app/api/mobile/entities/homework.rb @@ -37,6 +37,8 @@ module Mobile when :homework_anony_type val = f.homework_type == 1 && !f.homework_detail_manual.nil? val + when :coursename + f.course.nil? ? "" : f.course.name end end end diff --git a/app/api/mobile/entities/syllabus.rb b/app/api/mobile/entities/syllabus.rb index 4f97dd868..e4dd2e07a 100644 --- a/app/api/mobile/entities/syllabus.rb +++ b/app/api/mobile/entities/syllabus.rb @@ -1,12 +1,14 @@ module Mobile module Entities class Syllabus < Grape::Entity - include ApplicationHelper - expose :title expose :id - expose :can_setting - + 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 diff --git a/app/services/resources_service.rb b/app/services/resources_service.rb index 41f57429e..bc97437e4 100644 --- a/app/services/resources_service.rb +++ b/app/services/resources_service.rb @@ -1,7 +1,6 @@ #coding=utf-8 class ResourcesService - include ActionView::Helpers::NumberHelper #发送资源到课程 def send_resource_to_course user,params send_id = params[:send_id] @@ -59,11 +58,11 @@ class ResourcesService attchments = Attachment.where("(author_id = #{user.id} and is_publish = 1 and container_id in #{courses_ids} and container_type = 'Course') or (container_type = 'Course' and is_publish = 1 and container_id in #{courses_ids})" ).order("created_on desc") - attchments.each do |v| - course = Course.where("id=?",v.container_id).first - v[:coursename] = course.nil? ? "未知" : course.name - v[:attafile_size] = (number_to_human_size(v[:filesize])).gsub("ytes", "").to_s - end + # attchments.each do |v| + # course = Course.where("id=?",v.container_id).first + # v[:coursename] = course.nil? ? "未知" : course.name + # v[:attafile_size] = (number_to_human_size(v[:filesize])).gsub("ytes", "").to_s + # end attchments end @@ -77,10 +76,10 @@ class ResourcesService homeworks = HomeworkCommon.where("course_id in #{courses_ids} and publish_time <= ?",Time.now.strftime("%Y-%m-%d")).order("created_at desc") - homeworks.each do |v| - course = Course.where("id=?",v.course_id).first - v[:coursename] = course.nil? ? "未知" : course.name - end + # homeworks.each do |v| + # course = Course.where("id=?",v.course_id).first + # v[:coursename] = course.nil? ? "未知" : course.name + # end homeworks end @@ -94,10 +93,10 @@ class ResourcesService exercises = Exercise.where("exercise_status <> 1 and course_id in #{courses_ids}").order("created_at desc") - exercises.each do |v| - course = Course.where("id=?",v.course_id).first - v[:coursename] = course.nil? ? "未知" : course.name - end + # exercises.each do |v| + # course = Course.where("id=?",v.course_id).first + # v[:coursename] = course.nil? ? "未知" : course.name + # end exercises end diff --git a/app/services/syllabuses_service.rb b/app/services/syllabuses_service.rb index 885dea975..d5dec9f88 100644 --- a/app/services/syllabuses_service.rb +++ b/app/services/syllabuses_service.rb @@ -49,9 +49,9 @@ class SyllabusesService syllabuses.to_a #管理权限 can_setting - syllabuses.each do |s| - s = judge_can_setting(s,user) - end + # syllabuses.each do |s| + # s = judge_can_setting(s,user) + # end syllabuses end diff --git a/public/assets/wechat/myresource.html b/public/assets/wechat/myresource.html index 53eb3a23e..6300240d3 100644 --- a/public/assets/wechat/myresource.html +++ b/public/assets/wechat/myresource.html @@ -19,14 +19,14 @@ 请登录Trustie网站,在PC浏览器中上传课件。

-
{{r.homework_name}}发送
+
{{r.homework_name}}发送
作业来源:{{r.coursename}}

暂无作业,
请登录Trustie网站,在PC浏览器中创建作业。

-
{{r.exercise_name}}发送
+
{{r.exercise_name}}发送
题目来源:{{r.coursename}}

暂无测验,
diff --git a/public/assets/wechat/send_class_list.html b/public/assets/wechat/send_class_list.html index 6d1860e0c..b66b5008d 100644 --- a/public/assets/wechat/send_class_list.html +++ b/public/assets/wechat/send_class_list.html @@ -2,7 +2,7 @@

-
发送课程列表
+
请选择要发送的班级
From c524409e4af2ecd851b4a348b9898d2929ab56ee Mon Sep 17 00:00:00 2001 From: yuanke <249218296@qq.com> Date: Thu, 14 Jul 2016 17:15:49 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=BF=9B=E5=85=A5?= =?UTF-8?q?=E6=9F=90=E4=B8=AA=E7=8F=AD=E7=BA=A7=E6=8A=A5=E9=94=99=E7=9A=84?= =?UTF-8?q?BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/mobile/entities/course.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/app/api/mobile/entities/course.rb b/app/api/mobile/entities/course.rb index 060f43614..88c8ba144 100644 --- a/app/api/mobile/entities/course.rb +++ b/app/api/mobile/entities/course.rb @@ -57,14 +57,21 @@ module Mobile expose :can_setting, if: lambda { |instance, options| options[:user] } do |instance, options| current_user = options[:user] can_setting = false - member = instance.members.where("user_id=#{current_user.id} and course_id=#{instance.id}")[0] + + 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] roleName = member.roles[0].name if member if roleName && (roleName == "TeachingAsistant" || roleName == "Teacher" ) can_setting = true end - if instance.tea_id == current_user.id + if course.tea_id == current_user.id can_setting = true end can_setting