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/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/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..88c8ba144 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,28 @@ 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 + + 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 course.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/app/services/wechat_service.rb b/app/services/wechat_service.rb index 3097e1842..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/app.html#/#{type}/#{id}", + 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/app.html#/#{type}/#{id}", + 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/app.html#/#{type}/#{id}", + url:"#{Setting.protocol}://#{Setting.host_name}/wechat/user_activities#/#{type}/#{id}", #/assets/wechat/app.html#/#{type}/#{id} topcolor:"#FF0000", data:{ first: { 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..6300240d3 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.homework_name}}发送
作业来源:{{r.coursename}}
-

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

+

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

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

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

+

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

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 @@
-
发送课程列表
+
请选择要发送的班级