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

This commit is contained in:
txz 2016-07-08 17:22:50 +08:00
commit ea5bd94e99
10 changed files with 184 additions and 22 deletions

View File

@ -403,12 +403,12 @@ module Mobile
post ':course_id/del' do
authenticate!
c = Course.find(params[:course_id])
if c.members.count > 1
{status: -1, message: '已经有成员加入,不能删除'}
else
# if c.members.count > 1
# {status: -1, message: '已经有成员加入,不能删除'}
# else
c.delete!
present :status,0
end
# end
end

View File

@ -25,11 +25,32 @@ module Mobile
get ':id' do
authenticate!
ss = SyllabusesService.new
sy = ::Syllabus.find(params[:id])
sy = ss.judge_can_setting(sy,current_user)
present :data, sy, with: Mobile::Entities::Syllabus
present :status, 0
end
desc "获取新建大纲的权限"
params do
requires :token, type: String
end
post 'auth' do
authenticate!
auth = 0
if (current_user.user_extensions && current_user.user_extensions.identity == 0 && current_user.allowed_to?(:add_course, nil, :global => true))
auth = 1
end
present :auth, auth
end
desc "新建大纲"
params do
requires :token, type: String
@ -53,12 +74,30 @@ module Mobile
end
desc '编辑大纲'
params do
requires :token, type: String
requires :title, type: String, desc: '大纲标题'
# requires :add_courses, type: Array[String], desc: '课程名'
# requires :modify_courses, type: Array[Integer,String], desc: '课程名'
end
post ':id/edit' do
authenticate!
ss = SyllabusesService.new
#修改课程大纲
status = ss.edit(current_user, params)
if status == -1
{status:status, message: '修改课程信息失败' }
else
present :status, status
end
end
end
end
end
end

View File

@ -52,6 +52,7 @@ module Mobile
course_expose :updated_at
course_expose :course_student_num
course_expose :member_count
course_expose :can_setting
expose :teacher, using: Mobile::Entities::User do |c, opt|
if c.is_a? ::Course
c.teacher

View File

@ -5,6 +5,7 @@ module Mobile
expose :title
expose :id
expose :can_setting
expose :courses, using: Mobile::Entities::Course
end

View File

@ -5,21 +5,72 @@ class SyllabusesService
include ApplicationHelper
include CoursesHelper
def judge_can_setting(sy,user)
sy[:can_setting] = sy[:user_id] == user.id ? true : false
sy[:can_setting] = false if sy[:id].nil?
sy.courses.each do |c|
c[:can_setting] = false
member = c.members.where("user_id=#{user.id} and course_id=#{c.id}")[0]
roleName = member.roles[0].name if member
if roleName && (roleName == "TeachingAsistant" || roleName == "Teacher" )
c[:can_setting] = true
end
if c.tea_id == user.id
c[:can_setting] = true
end
end
sy
end
#获取指定用户的课程大纲
def user_syllabus(user)
courses = CoursesService.new.user_courses_list(user)
other = Syllabus.new(title: '未命名课程')
other = Syllabus.new(title: '未命名课程',user_id: user.id)
courses.each do |c|
other.courses << c[:course] unless c[:course].syllabus
end
user.syllabuses.each do |syllabus|
syllabus.courses = syllabus.courses.not_deleted
# user.syllabuses.each do |syllabus|
# syllabus.courses = syllabus.courses.not_deleted
# end
#
# user.syllabuses.to_a << other
courses = user.courses.not_deleted
syllabus_ids = courses.empty? ? '(-1)' : "(" + courses.map{|course| !course.syllabus_id.nil? && course.syllabus_id}.join(",") + ")"
syllabuses = Syllabus.where("id in #{syllabus_ids} or user_id = #{user.id}").order("updated_at desc")
syllabuses.to_a << other
#管理权限 can_setting
syllabuses.each do |s|
s = judge_can_setting(s,user)
# s[:can_setting] = s.user_id == user.id ? true : false
# s.courses.each do |c|
# c[:can_setting] = false
#
# member = c.members.where("user_id=#{user.id} and course_id=#{c.id}")[0]
# roleName = member.roles[0].name if member
#
# if roleName && (roleName == "TeachingAsistant" || roleName == "Teacher" )
# c[:can_setting] = true
# end
#
# if c.tea_id == user.id
# c[:can_setting] = true
# end
# end
end
user.syllabuses.to_a << other
syllabuses
end
def after_create_course(course, user)
@ -56,9 +107,49 @@ class SyllabusesService
end
end
sy[:can_setting] = true
sy
end
#修改课程大纲的名称、班级名称、新增班级
def edit(user, option)
courses = []
status = -1
syllabus_id = option[:id]
sy = Syllabus.where("id=?",option[:id]).first
if sy && sy.user_id == user.id
syllabus_title = option[:title]
sy.title = syllabus_title
#修改班级名称
modify_courses = option[:modify_courses]
modify_courses.each do |c|
course = Course.where("id=?",c.id).first
if course && course.tea_id == user.id
course.name = c.name
!course.save
end
end
#新增班级
add_courses = option[:add_courses]
add_courses.each do |c|
course = ::Course.new(c)
course.name = add_courses
course.tea_id = user.id
course.syllabus_id = sy.id
course.update_default_value
course.is_public = 0
course.save!
after_create_course(course, user)
end
status = 0
end
status
end
end

View File

@ -3,7 +3,7 @@
<div class="blue-title">课程列表</div>
<div ng-repeat="syllabus in syllabuses">
<div ng-click="syllabus.show_plus = !syllabus.show_plus" class="course-list-row f13 c-grey3 mt10"><img src="/images/wechat/plus.png" ng-show="syllabus.show_plus" width="15" class="fl ml10 mt11 spread-btn" /><img src="/images/wechat/minus.png" ng-show="!syllabus.show_plus" width="15" class="fl ml10 mt11 retract-btn " /><span class="fl ml10">{{syllabus.title}}</span><img src="/images/wechat/setting.png" width="15" class="fr mr10 mt10" ng-click="onSetting(syllabus)" /></div>
<div ng-click="syllabus.show_plus = !syllabus.show_plus" class="course-list-row f13 c-grey3 mt10"><img src="/images/wechat/plus.png" ng-show="syllabus.show_plus" width="15" class="fl ml10 mt11 spread-btn" /><img src="/images/wechat/minus.png" ng-show="!syllabus.show_plus" width="15" class="fl ml10 mt11 retract-btn " /><span class="fl ml10">{{syllabus.title}}</span><img src="/images/wechat/setting.png" ng-show = "syllabus.can_setting" width="15" class="fr mr10 mt10" ng-click="onSetting(syllabus)" /></div>
<ul ng-show="!syllabus.show_plus" class="class-list f13 c-grey3">
<li ng-click="goClass(course.id)" ng-repeat="course in syllabus.courses" ng-class="{'border-bottom-none': $last}">
<img src="/images/wechat/dot.png" width="15px" class="class-list-dot" />

View File

@ -3,9 +3,9 @@
<div class="blue-title">管理课程</div>
<form novalidate name="classForm">
<div class="course-list-row f13 c-grey3 mt30"><span class="fl ml15 c-grey3">课程</span><input class="new-class-input ml25" ng-model="syllabus.title" required placeholder="请输入课程名" /></div>
<div class="course-list-row f13 c-grey3 mt30"><span class="fl ml15 c-grey3">课程</span><input class="new-class-input ml25 c-black" ng-model="syllabus.tmptitle" required placeholder="请输入课程名" /></div>
<div class="course-list-row f13 c-grey3 mt10" ng-repeat="course in syllabus.courses"><span class="fl ml15 c-grey3">班级</span><input required class="new-class-input ml25" ng-model="course.name" placeholder="请输入班级名" /><a ng-click="deleteClass($index)" class="fr mr10 c-grey6 delete-class-link">删除</a></div>
<div class="course-list-row f13 c-grey3 mt10" ng-repeat="course in syllabus.courses" ng-show="course.can_setting"><span class="fl ml15 c-grey3">班级</span><input required class="new-class-input ml25 c-black" ng-model="course.tmpname" placeholder="请输入班级名" /><a ng-click="deleteClass($index)" class="fr mr10 c-grey6 delete-class-link">删除</a></div>
<div class="tac"><a ng-click="addClass()" class="link-blue2 f13 mt15 inline-block add-class-link">+新增班级</a></div>
<a ng-click="newClass(classForm, syllabus)" ng-class="['finish-btn', {'btn-disabled':!classForm.$valid} ]" >完成</a>
</form>

View File

@ -31,7 +31,18 @@ app.controller('ClassListController', ['$scope', 'config', 'auth', '$http', '$lo
}
vm.newClass = function () {
$location.path("/new_class");
//先判断下权限
$http.post(config.apiUrl + "syllabuses/auth",{token: auth.token()} ).then(
function (response) {
console.log(response.data);
if (response.data.auth == 0) {
vm.alertService.showMessage('提示', '非教师身份不能创建课程哦~');
}
else{
$location.path("/new_class");
}
}
);
}
vm.goResource = function () {

View File

@ -14,6 +14,14 @@ app.controller('EditClassController', ['$scope', '$http', 'auth', 'config', 'ale
});
}
//名字用两份
for(var i in vm.syllabus.courses){
var course = vm.syllabus.courses[i];
course.tmpname = course.name;
}
vm.syllabus.tmptitle = vm.syllabus.title;
//单弹框
vm.alertService_1 = alertService.create();
@ -21,7 +29,7 @@ app.controller('EditClassController', ['$scope', '$http', 'auth', 'config', 'ale
vm.alertService_2 = alertService.create();
vm.addClass = function(){
vm.syllabus.courses.push({});
vm.syllabus.courses.push({can_setting:true});
};
vm.deleteClass = function(index){
@ -57,24 +65,34 @@ app.controller('EditClassController', ['$scope', '$http', 'auth', 'config', 'ale
return;
}
var courses = [];
var add_courses = [];
var modify_courses = [];
for(var i in vm.syllabus.courses){
var course = vm.syllabus.courses[i];
if(course.id>0){
courses.push(course.name);
if(!course.id){
add_courses.push(course.tmpname);
}
else if(course.tmpname != course.name){
modify_courses.push({id:course.id,name:course.tmpname});
}
}
$http.post(config.apiUrl+"syllabuses", {
$http.post(config.apiUrl+'syllabuses/'+syllabus_id+'/edit', {
token: auth.token(),
id: syllabus_id,
courses: courses
title:vm.syllabus.tmptitle,
add_courses: add_courses,
modify_courses: modify_courses
}).then(function(response){
if(response.data.status!=0){
vm.alertService_1.showMessage('出错了', response.data.message);
} else {
vm.alertService_1.showMessage('提示', '保存课程成功', function(){
window.history.back();
// window.history.back();
rms.save('syllabuses',[]);
$location.path("/class_list");
});
}
console.log(response.data.data);

View File

@ -49,6 +49,7 @@ blockquote {border:1px solid #d4d4d4; padding: 0.6em; margin-left: 1.4em; margin
.c-grey6 {color:#777777;}
.c-blue {color:#3b94d6;}
.c-white {color:#ffffff;}
.c-black {color:#333}
a {color:#707070;}
a.c-grey {color:#707070;}
a.c-grey2 {color:#9a9a9a;}