UNPKG

unserver-unify

Version:

118 lines (116 loc) 4.2 kB
'use strict'; angular.module('bamboo.mystudy').service('MystudyService', function(ApiService, CommonService, $q) { // service to get all classes info for current user var self = this; this.classApi = function(info, callback) { ApiService.post('/classes', info).then(function(result) { if (result.data.success) { callback(result.data.data); } else { var _err = result.data.error || '' + result.data.info || ''; CommonService.showNoBlockErr('Class Api Failed : ' + _err); } }) } this.getClassInfoForCurrentUser = function(callback) { // log warning if no callback if (!callback) { console.log('Try to get classes info for current user without callback!'); } var _info = { action: 'getstudentclasses' }; self.classApi(_info, callback); } // service to get one class detail by id this.getClassInfoById = function(classid, callback) { //log warning if no callback if (!callback) { console.log('Try to get class(id:' + classid + ') info without callback!'); } ApiService.get('/class/' + classid).then(function(result) { // console.log(result); if (result.data.success) { callback(result.data.data); } else { var _err = result.data.error || '' + result.data.info || ''; CommonService.showNoBlockErr('Get class info failed: ' + _err); } }) } // service to get all notes for current user this.getMyNotes = function(callback) { //log warning if no callback, as the data get below cannnot pass to controller if (!callback) { console.log('Try to get all notes for current user without callback!'); } var info = { action: 'getmynote' }; ApiService.post('/notes', info).then(function(result) { if (result.data.success) { if (!callback) { CommonService.showNoBlockInfo('Get user\'s notes success'); } else { callback(result.data.data); } } else { var _err = result.data.error || '' + result.data.info || ''; CommonService.showNoBlockErr('Update ChapterNotes failed: ' + _err); } }) } this.ExamApi = function(info, callback) { ApiService.post('/exam', info).then(function(result) { if (result.data.success) { if (!callback) { // since we are getting data, no need to interrupt/inform user } else { callback(result.data.data); } } else { var _err = result.data.error || '' + result.data.info || ''; CommonService.showNoBlockErr('Exam Api failed : ' + _err); } }) } // service to get the current user attent times for exams this.getExamAttentTimesForCurrentUserByIds = function(examidarray, callback) { var info = { ids: examidarray, action: 'getmyexamteststatus' }; self.ExamApi(info, callback); } // service to get the current user attent times for test this.getTestAttentTimesForCurrentUserByIds = function(testidarray, callback) { var info = { ids: testidarray, action: 'getmyexamteststatus' }; self.ExamApi(info, callback); } // service to get the current user submitted status for assignment this.getAssignmentSubmitStatusForCurrentUserByIds = function(assignmentidarray, callback) { var info = { ids: assignmentidarray, action: 'getmyassignmentstatus' }; self.ExamApi(info, callback); } this.getTeachersByClassId = function(id) { var deferred = $q.defer(); var promise = deferred.promise; ApiService.get("/class/" + id + "/teachers").then(function(result) { if (result.data.success) { var teachers = result.data.data.users; var teacherList = teachers.map(function(teacher) { teacher.avatarUrl = CommonService.getAvatarSrc(teacher); return teacher; }); deferred.resolve(teacherList); } }); return promise; } });