|
|
|
@ -11,6 +11,8 @@ Page({
|
|
|
|
|
student.objectId 该学生的主键,唯一
|
|
|
|
|
student.username 学生的用户名,是唯一,就像微信号一样
|
|
|
|
|
student.name 学生的姓名
|
|
|
|
|
student.present 是否出席
|
|
|
|
|
student.isasking :0:没有提问,1:提问,2:请回答
|
|
|
|
|
*/
|
|
|
|
|
presence: null,
|
|
|
|
|
students: [],
|
|
|
|
@ -18,15 +20,14 @@ Page({
|
|
|
|
|
class_id: null,
|
|
|
|
|
data: {
|
|
|
|
|
//以下数据的同步由该代码文件实现,数据的呈现由classroom.wxml实现
|
|
|
|
|
//命名可能有点混乱......
|
|
|
|
|
present_students: [],
|
|
|
|
|
// 出席的学生的用户名即上文提及的student.username,考虑弃用,建议替换为presen_stu_ids
|
|
|
|
|
present_stu_ids: [], //出席的学生的主键objectId
|
|
|
|
|
students: [], // 该课程所有的学生, 元素类型见上文中的student
|
|
|
|
|
present_stus: [], //出席的学生,元素类型与students中的一样
|
|
|
|
|
unpresent_students: [], //没有出席的学生的用户名,不建议使用该数据,弃用
|
|
|
|
|
class_name: "",//课程名称
|
|
|
|
|
class_id: "",//该课程的主键(编号)
|
|
|
|
|
current_user: null, //目前登陆的用户,类型为对象,属性有objectId,username, name
|
|
|
|
|
teacher: null,
|
|
|
|
|
//该课程教员,类型为对象
|
|
|
|
|
//请在进入界面时判断用户是否为教员以给与权限或更改界面
|
|
|
|
|
//属性如下:objectId, username, name
|
|
|
|
|
class_name: "", //课程名称
|
|
|
|
|
class_id: "", //该课程的主键(编号)
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
pull_present: function(){
|
|
|
|
@ -36,31 +37,32 @@ Page({
|
|
|
|
|
query.include("user");
|
|
|
|
|
set_present = this.set_present.bind(this);
|
|
|
|
|
return AV.Promise.all([query.find().then(set_present), query.subscribe()]).then(([presents, subscription])=>{
|
|
|
|
|
this.subscription = subscription;
|
|
|
|
|
if(this.presenceUnbind) this.unbind();
|
|
|
|
|
this.presenceUnbind = bind(subscription, presents, set_present);
|
|
|
|
|
this.PresentSubscription = subscription;
|
|
|
|
|
if(this.presentUnbind) this.presentUnbind();
|
|
|
|
|
this.presentUnbind = bind(subscription, presents, set_present);
|
|
|
|
|
}).catch(error=> console.error(error.message));
|
|
|
|
|
},
|
|
|
|
|
set_present: function(presents){
|
|
|
|
|
//console.log("set_present");
|
|
|
|
|
//console.log(presents);
|
|
|
|
|
var student_ids = presents.map((present)=>{
|
|
|
|
|
var is_asking={};
|
|
|
|
|
var present_stu_ids = presents.map((present)=>{
|
|
|
|
|
user = present.get("user");
|
|
|
|
|
//console.log(user);
|
|
|
|
|
//console.log(typeof user);
|
|
|
|
|
is_asking[user.id]=present.get("isasking");
|
|
|
|
|
return user.id;
|
|
|
|
|
//return user.get("username");
|
|
|
|
|
});
|
|
|
|
|
//console.log("student_ids:"+student_ids.toString());
|
|
|
|
|
//console.log("students:"+this.students);
|
|
|
|
|
present_stus = this.students.filter(student=> student_ids.indexOf(student.id)>-1)
|
|
|
|
|
//console.log(present_stus);
|
|
|
|
|
present_stu_usernames = present_stus.map(stu => stu.get("username"));
|
|
|
|
|
present_stu_ids = present_stus.map(stu=>stu.id)
|
|
|
|
|
this.setData({
|
|
|
|
|
present_stu_ids: present_stu_ids,
|
|
|
|
|
present_students: present_stu_usernames});
|
|
|
|
|
this.setData(jsonify({present_stus}));
|
|
|
|
|
students = this.students.map((student)=>{
|
|
|
|
|
if(present_stu_ids.indexOf(student.id)>-1){
|
|
|
|
|
student.set("ispresent",true);
|
|
|
|
|
student.set("isasking", is_asking[student.id]);
|
|
|
|
|
}else{
|
|
|
|
|
student.set("ispresent",false);
|
|
|
|
|
student.set("isasking", 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return student;
|
|
|
|
|
})
|
|
|
|
|
this.setData(jsonify({students}));
|
|
|
|
|
return presents;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
@ -119,6 +121,7 @@ Page({
|
|
|
|
|
onShow: function () {
|
|
|
|
|
console.log("onShow");
|
|
|
|
|
console.log("enter class when onShow");
|
|
|
|
|
console.log(AV.User.current());
|
|
|
|
|
this.class.enter();
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
@ -136,7 +139,8 @@ Page({
|
|
|
|
|
onUnload: function () {
|
|
|
|
|
this.class.leave();
|
|
|
|
|
console.log("onUnload");
|
|
|
|
|
|
|
|
|
|
this.PresentSubscription.unsubscribe();
|
|
|
|
|
this.presentUnbind();
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|