Merge branch 'weixin_guange' of https://git.trustie.net/jacknudt/trustieforge into weixin_guange

This commit is contained in:
txz 2016-07-14 17:34:31 +08:00
commit 433f12f184
16 changed files with 121 additions and 55 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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: {

View File

@ -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"

View File

@ -24,8 +24,8 @@
<div ng-class="{'undis': !showResources}">
<div ng-repeat="r in resources|filter:searchText" ng-class="['class-detail-row', 'f13', 'c-grey3', {'border-top': $first}]"><img src="/images/wechat/courseware.png" width="15" class="ml10 fl" /><span class="fl ml10 resource-width">{{r.filename}}</span><a ng-show="isTeacher" herf="javascript:void(0);" class="fr mr10 link-blue2" ng-click="sendFile(r)">发送</a><div class="cl"></div></div>
<p ng-show="resources_tag == true && resources.length<=0" class="class-test-tip">暂无课件,<br />
请登录Trustie网站,在PC浏览器中上传课件。</p>
<p ng-show="resources_tag == true && resources.length<=0" class="class-test-tip">暂无课件<br />
请登录Trustie网站在PC浏览器中上传课件。</p>
</div>
<div ng-class="{'undis': !showClassMate}">
<div class="member-banner f13 c-grey3">授课老师</div>
@ -43,15 +43,15 @@
<div ng-class="{'undis': !showHomework}">
<div ng-repeat="r in homeworks|filter:searchText" ng-class="['class-detail-row', 'f13', 'c-grey3', {'border-top': $first}]"><img src="/images/wechat/homework.png" width="15" class="ml10 fl" /><span class="fl ml10 resource-width">{{r.homework_name}}</span><a ng-show="isTeacher" herf="javascript:void(0);" class="fr mr10 link-blue2" ng-click="sendFile(r)">发送</a><div class="cl"></div></div>
<p ng-show="homeworks_tag == true && homeworks.length<=0" class="class-test-tip">暂无作业,<br />
请登录Trustie网站,在PC浏览器中上传作业。</p>
<p ng-show="homeworks_tag == true && homeworks.length<=0" class="class-test-tip">暂无作业<br />
请登录Trustie网站在PC浏览器中上传作业。</p>
</div>
<div ng-class="{'undis': !showTestcase}">
<div ng-repeat="r in exercises|filter:searchText" ng-class="['class-detail-row', 'f13', 'c-grey3', {'border-top': $first}]"><img src="/images/wechat/test.png" width="15" class="ml10 fl" /><span class="fl ml10 resource-width">{{r.exercise_name}}</span><a ng-show="isTeacher" herf="javascript:void(0);" class="fr mr10 link-blue2" ng-click="sendFile(r)">发送</a><div class="cl"></div></div>
<p ng-show="exercises_tag == true && exercises.length<=0" class="class-test-tip">暂无小测验,<br />
请登录Trustie网站,在PC浏览器中上传小测验。</p>
<p ng-show="exercises_tag == true && exercises.length<=0" class="class-test-tip">暂无小测验<br />
请登录Trustie网站在PC浏览器中上传小测验。</p>
</div>

View File

@ -15,22 +15,22 @@
<img src="/images/wechat/courseware.png" width="15" class="ml10 fl" /> <span class="fl ml10 resource-width">{{r.filename}}</span><a ng-click="sendFile(r)" class="fr mr10 link-blue2">发送</a><div class="cl"></div>
<span class="f12 mt5 ml35 c-grey4">课件来源:{{r.coursename}}</span><span class="f12 ml10 mt5 c-grey4">大小:{{r.attafile_size}}</span>
</div>
<p ng-show="resources && resources.length<=0" class="class-test-tip">暂无课件,<br />
请登录Trustie网站,在PC浏览器中上传课件。</p>
<p ng-show="resources && resources.length<=0" class="class-test-tip">暂无课件<br />
请登录Trustie网站在PC浏览器中上传课件。</p>
</div>
<div ng-class="{'undis': currentTab!=2}">
<div ng-repeat="r in homeworks|filter:{homework_name: searchText}" ng-class="['class-detail-row', 'f13', 'c-grey3', {'border-top': $first}]"><img src="/images/wechat/homework.png" width="15" class="ml10 fl" /><span class="fl ml10 resource-width">{{r.homework_name}}</span><a ng-click="sendFile(r)" class="fr mr10 link-blue2">发送</a><div class="cl"></div>
<div ng-repeat="r in homeworks|filter:{homework_name: searchText}" ng-class="['class-detail-row', 'f13', 'c-grey3', {'border-top': $first}]"><img src="/images/wechat/homework.png" width="15" class="ml10 fl" /><span class="fl ml10 resource-width">{{r.homework_name}}</span><a ng-click="sendFile(r)" class="fr mr10 link-blue2 undis">发送</a><div class="cl"></div>
<span class="f12 mt5 ml35 c-grey4">作业来源:{{r.coursename}}</span>
</div>
<p ng-show="homeworks && homeworks.length<=0" class="class-test-tip">暂无作业,<br />
请登录Trustie网站,在PC浏览器中创建作业。</p>
<p ng-show="homeworks && homeworks.length<=0" class="class-test-tip">暂无作业<br />
请登录Trustie网站在PC浏览器中创建作业。</p>
</div>
<div ng-class="{'undis': currentTab!=3}">
<div ng-repeat="r in exercise|filter:{exercise_name: searchText}" ng-class="['class-detail-row', 'f13', 'c-grey3', {'border-top': $first}]"><img src="/images/wechat/test.png" width="15" class="ml10 fl" /><span class="fl ml10 resource-width">{{r.exercise_name}}</span><a ng-click="sendFile(r)" class="fr mr10 link-blue2">发送</a><div class="cl"></div>
<div ng-repeat="r in exercise|filter:{exercise_name: searchText}" ng-class="['class-detail-row', 'f13', 'c-grey3', {'border-top': $first}]"><img src="/images/wechat/test.png" width="15" class="ml10 fl" /><span class="fl ml10 resource-width">{{r.exercise_name}}</span><a ng-click="sendFile(r)" class="fr mr10 link-blue2 undis">发送</a><div class="cl"></div>
<span class="f12 mt5 ml35 c-grey4">题目来源:{{r.coursename}}</span>
</div>
<p ng-show="exercise && exercise.length<=0" class="class-test-tip">暂无测验,<br />
请登录Trustie网站,在PC浏览器中创建测验。</p>
<p ng-show="exercise && exercise.length<=0" class="class-test-tip">暂无测验<br />
请登录Trustie网站在PC浏览器中创建测验。</p>
</div>
</div>

View File

@ -2,7 +2,7 @@
<div class="post-container">
<div loading-spinner></div>
<div class="blue-title">发送课程列表</div>
<div class="blue-title">请选择要发送的班级</div>
<div ng-show="syllabus.can_setting" ng-repeat="syllabus in syllabuses">