You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							138 lines
						
					
					
						
							3.9 KiB
						
					
					
				
			
		
		
	
	
							138 lines
						
					
					
						
							3.9 KiB
						
					
					
				| app.controller('ClassController', ['$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;
 | |
|                 vm.resources_tag = true;
 | |
|             });
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     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);
 | |
|                 vm.homeworks_tag = true;
 | |
|             });
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     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.exercises_tag = true;
 | |
|             });
 | |
|         }
 | |
|     }
 | |
| 
 | |
| 
 | |
|     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;
 | |
|         vm.resources_tag = false;
 | |
|         vm.homeworks_tag = false;
 | |
|         vm.exercises_tag = 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}); 
 | |
|     };
 | |
| 
 | |
|     vm.sendFile = function(r){
 | |
|         $location.path("/send_class_list").search({id: r.id});
 | |
|     }
 | |
| 
 | |
|     $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 = ['课件', "我的同学"];
 | |
|         }
 | |
| 
 | |
|     }
 | |
| 
 | |
| }]); |