128 lines
3.6 KiB
JavaScript
128 lines
3.6 KiB
JavaScript
app.controller('MyClassController', ['$scope', 'config','$http', 'auth','$location','$routeParams', function($scope, config, $http, auth, $location, $routeParams){
|
|
|
|
var vm = $scope;
|
|
var courseid = $routeParams.id;
|
|
|
|
|
|
|
|
var getUsers = function(){
|
|
if(vm.teachers.length<=0){
|
|
$http.get(config.apiUrl + 'courses/teachers?token='+auth.token()+'&course_id='+courseid).then(
|
|
function(response) {
|
|
console.log(response.data);
|
|
vm.teachers = response.data.data;
|
|
}
|
|
)
|
|
}
|
|
|
|
if(vm.students.length<=0){
|
|
$http.get(config.apiUrl + 'courses/students?token='+auth.token()+'&course_id='+courseid).then(
|
|
function(response) {
|
|
console.log(response.data);
|
|
vm.students = response.data.data;
|
|
}
|
|
)
|
|
}
|
|
}
|
|
|
|
var getResources = function(){
|
|
if(vm.resources.length<=0){
|
|
$http.post(config.apiUrl + "courses/"+courseid+"/attachments",
|
|
{token: auth.token(), name: ''}
|
|
).then(function(response){
|
|
vm.resources = response.data.data;
|
|
});
|
|
}
|
|
}
|
|
|
|
var getHomeworks = function(){
|
|
if(vm.homeworks.length <=0){
|
|
$http.get(config.apiUrl + "courses/homeworks/"+courseid+"?token="+auth.token()).then(function(response){
|
|
vm.homeworks = response.data.data;
|
|
console.log(response.data);
|
|
});
|
|
}
|
|
}
|
|
|
|
var getExercises = function(){
|
|
if(vm.exercises.length <=0){
|
|
$http.get(config.apiUrl + "courses/"+courseid+"/exercises?token="+auth.token()).then(function(response){
|
|
vm.exercises = response.data.data;
|
|
console.log(response.data);
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
vm.isTeacher = false;
|
|
vm.currentTab = 1;
|
|
vm.tab = function(index){
|
|
vm.currentTab = index;
|
|
vm.searchText = '';
|
|
|
|
vm.showClassMate = false;
|
|
vm.showResources = false;
|
|
vm.showHomework = false;
|
|
vm.showTestcase = false;
|
|
|
|
if(vm.isTeacher){
|
|
if(index == 1){ //课件
|
|
getResources();
|
|
vm.showResources = true;
|
|
} else if(index==2){ //作业
|
|
getHomeworks();
|
|
vm.showHomework = true;
|
|
} else if(index==3){ //小测验
|
|
getExercises();
|
|
vm.showTestcase = true;
|
|
} else if(index==4){ //学生管理
|
|
getUsers();
|
|
vm.showClassMate = true;
|
|
}
|
|
|
|
} else {
|
|
if(index == 2){
|
|
getUsers();
|
|
vm.showClassMate = true;
|
|
} else if(index==1){
|
|
getResources();
|
|
vm.showResources = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
vm.course = {};
|
|
vm.students = [];
|
|
vm.teachers = [];
|
|
vm.resources = [];
|
|
vm.homeworks = [];
|
|
vm.exercises = [];
|
|
|
|
vm.invite = function(){
|
|
$location.path("/invite_code").search({id: courseid});
|
|
};
|
|
|
|
$http.get(config.apiUrl+ 'courses/'+courseid+"?token="+auth.token()).then(
|
|
function(response) {
|
|
console.log(response.data);
|
|
vm.course = response.data.data;
|
|
resetMenu(vm.course.current_user_is_teacher);
|
|
vm.tab(1);
|
|
}
|
|
);
|
|
|
|
|
|
var resetMenu = function(is_teacher){
|
|
vm.isTeacher = is_teacher;
|
|
if(is_teacher){
|
|
vm.menus = ["课件", "作业", "小测验", "学生管理"];
|
|
} else {
|
|
vm.menus = ['课堂资源', "我的同学"];
|
|
}
|
|
|
|
}
|
|
|
|
}]); |