UNPKG

unserver-unify

Version:

399 lines (396 loc) 13 kB
'use strict'; angular.module('bamboo.course').service('CourseService', function($state, $q, ApiService, $translate, CommonService, $filter, loginService, $rootScope) { var categoryInfo = ApiService.categoryInfo; this.getCoursesWithSorting = function(page, sortmethod, searchmethod, pageSize, option) { var info = { id: ApiService.gid, action: "getcourselist", page: page, sort: { reverse: true, predicate: sortmethod }, start: page * pageSize, limit: pageSize, search: searchmethod, }; console.log(info); if (!info.search) { info.search = {}; } if (option) { angular.extend(info.search, option); } if(loginService.subDomain=='gsx'||loginService.subDomain=='cap') { info.search.lang = $rootScope.currentLanguage; } console.log(info); return ApiService.post('/lcourses', info); } /** * @ngdoc method * @name $course.service#getDepartmentCoursesWithSorting * @kind function * * @description Get courses based on the provided page, sorting method and page size. * * @param {int} the page number for backend to retrieve * @param {string} The sorting method. it can be the following values: * visitercounter: sort based on the visiter counts * position: sorting based on recommended by admin * score: sorting based on the score feedback by user * update: sorgint based on the updated date * created: sorting based on the created date * recommend: sorting based on the recommendations by user * @param {object} how many items to return for this page * @param {object} the department id that the courses belongs to * * @return {object} the list course objects. if failed to retrieve, it will return null */ /* this.getDepartmentCoursesWithSorting = function(page, sortmethod, pageSize, departmentId) { var info = { id: ApiService.gid, action: "getcourselist", page: page, sort: sortmethod, limit: pageSize, did: departmentId }; return ApiService.post('/lcourses', info); } */ /** * @ngdoc method * @name $course.service#getCoursesWithSorting * @kind function * * @description Get all the courses that belongs to logged in user. * * * @return {object} the list course objects. if failed to retrieve, it will return null */ this.getMyCourses = function(page, size) { var info = { action: "getrelaventcourses", page: page, limit: size, }; console.log(info); return ApiService.post('/lcourses', info); } this.editorInfo = []; this.setEditorInfo = function(value) { this.editorInfo = value; } this.getEditorInfo = function() { return this.editorInfo; } this.getPaperinfo = function(id, type, callback) { var _info = { id: id, action: 'getpaper' }; if (type == "Dynamic") { _info.action = "getdpaper"; } else if (type == "Smart") { _info.action = "getspaper"; } ApiService.post('/exam', _info).then(function(result) { if (result.data.success) { callback(result.data.data); } else { var _err = result.data.error || '' + result.data.info || ''; CommonService.showNoBlockErr('Get Item failed: ' + _err); } }) } // service to get info about exam by id this.getExamInfoById = function(id, callback) { // show error if no callback, as the data get below cannot passed to controller if (!callback) { console.log('Try to get exam(id:' + id + ') item without callback!'); } var _info = { id: id, action: 'getexamitem' }; ApiService.post('/exam', _info).then(function(result) { if (result.data.success) { callback(result.data.data); } else { var _err = result.data.error || '' + result.data.info || ''; CommonService.showNoBlockErr('Get user profile failed: ' + _err); } }) } // service to get test/quiz info by id this.getQuizInfoById = function(id, callback) { // log error if no callback, as the data get below cannot passed to controller if (!callback) { console.log('Try to get Quiz(id:' + id + ') item without callback'); } var _info = { id: id, action: 'gettestitem' }; ApiService.post('/exam', _info).then(function(result) { if (result.data.success) { callback(result.data.data); } else { var _err = result.data.error || '' + result.data.info || ''; CommonService.showNoBlockErr('Get user profile failed: ' + _err); } }) } // service to get assignment info by id this.getAssignmentById = function(id, callback) { //log error if no callback, as the data get below cannot passed to controller if (!callback) { console.log('Try to get Assignment(id:' + id + ') info without callback'); } var _info = { id: id, action: 'getassignment' }; ApiService.post('/exam', _info).then(function(result) { if (result.data.success) { callback(result.data.data); } else { var _err = result.data.error || '' + result.data.info || ''; CommonService.showNoBlockErr('Get user profile failed: ' + _err); } }) } // service to get chapter's notes by Course id/Courseware id/resource id this.getChapterNotesByIds = function(cid, mid, rid, callback) { //log warning if no callback, as the data get below cannot passed to controller if (!callback) { console.log('Try to get Chapter Notes without callback!'); } var info = { cid: cid, mid: mid, rid: rid, action: 'getmyresourcenote' }; ApiService.post('/notes', info).then(function(result) { if (result.data.success) { callback(result.data.data); } else { var _err = result.data.error || '' + result.data.info || ''; CommonService.showNoBlockErr('Get ChapterNotes failed: ' + _err); } }) } // service to post/save chapter's notes by Course id/Coursware id/resource id this.saveChapterNotesByIds = function(cid, mid, rid, content, callback) { var info = { cid: cid, mid: mid, rid: rid, content: content, action: 'updateresourcenote' }; ApiService.post('/notes', info).then(function(result) { if (result.data.success) { CommonService.showNoBlockInfo('Update Notes Success.'); if (!callback) { $state.reload(); } else { callback(result.data.data); } } else { var _err = result.data.error || '' + result.data.info || ''; CommonService.showNoBlockErr('Update ChapterNotes failed: ' + _err); } }) } // sercive to get courses info by ids this.getCoursesInfoByIds = function(cidsArray, callback) { if (!callback) { console.log('Try to get courses info without callback!'); return; } var info = { ids: cidsArray, action: 'getCourseByIds' }; ApiService.post('/lcourses', info).then(function(result) { if (result.data.success) { callback(result.data.data); } else { var _err = result.data.error || '' + result.data.info || ''; CommonService.showNoBlockErr('Get courses info failed: ' + _err); } }); } // service to get courseware info by ids this.getCoursewareInfoByIds = function(ids, callback) { if (!callback) { console.log('Try to get courseware info without callback!'); } var info = { ids: ids, action: 'getcoursesbyids' }; ApiService.post('/mvsubjects', info).then(function(result) { if (result.data.success) { callback(result.data.data); } else { var _err = result.data.error || '' + result.data.info || ''; CommonService.showNoBlockErr($filter('trans')({ eng: 'Get courseware info failed: ', chn: '无法获取课程章节信息: ' }) + _err); } }) } // service to get course info by id this.getCourseInfoById = function(cid, callback) { if (!callback) { console.log('try to get course info without callback!'); return; } ApiService.get('/course/' + cid).then(function(result) { if (result.data.success) { callback(result.data.data); } else { var _err = result.data.error || '' + result.data.info || ''; CommonService.showNoBlockErr($filter('trans')({ eng: 'Get Course info failed: ', chn: '无法获取课程信息: ' }) + _err); } }) } // service to get course rating records this.getCourseRatingRecords = function(cid, callback) { if (!callback) { console.log('try to get course rating records without callback!'); return; } if (!cid) { console.log('try to get course rating without course id!'); } var info = { id: cid, action: 'getcourseassessment', }; ApiService.post('/rating', info).then(function(result) { if (result.data.success) { callback(result.data.data); } else { var _err = result.data.error || '' + result.data.info || ''; CommonService.showNoBlockErr($filter('trans')({ eng: 'get course rating failed: ', chn: '读取课程评分信息错误: ' }) + _err); } }) } var chartData = { labels: [], datasets: [{ label: "", backgroundColor: "rgba(255,99,132,0.2)", borderColor: "rgba(255,99,132,1)", pointBackgroundColor: "rgba(255,99,132,1)", pointBorderColor: "#fff", pointHoverBackgroundColor: "#fff", pointHoverBorderColor: "rgba(255,99,132,1)", data: [] }] }; function getKnowledgeSourse(userknowledges) { var displayKnowledges = []; angular.forEach(userknowledges, function(value, key) { var childPerctg = []; var _k = { //child:childPerctg, value: value, key: key, score: value.correct * 100 / value.counter, } displayKnowledges.push(_k); // /console.log(value); for (var i = 0; i <= 5; i++) { if (value[i]) { displayKnowledges.push({ level: i, //counter:value[i].counter, //correct:value[i].correct, value: value[i], score: value[i].correct * 100 / value[i].counter, percentage: (value[i].correct * 100) / value[i].counter }); } } }); return displayKnowledges; } function prepareRadarChart(knowledgeSourse, flag) { var labels = []; var data = []; //var charDict = {}; angular.forEach(knowledgeSourse, function(nlg, idx) { if (nlg.key) { var _array = nlg.key.split(','); var len = _array.len; var pos = len - 2; if (pos < 0) { pos = 0; } var _array1 = _array.slice(pos); var key = _array1.join(','); if (_array1.length > 1 && _array1[1].length > 5) { key = _array1[1]; } // var key = nlg.key.split(',').shift(); var value = nlg.value; labels.push(key); if (value.counter) { var _result = value.correct * 100 / value.counter; // console.log(_result); if (flag && _result == 100) { labels.pop(); } else { data.push(_result); } // data.push(_result); } else { labels.pop(); } } }); chartData.labels = labels; chartData.datasets[0].data = data; $translate('Accuracy Rate(%)').then(function(data) { chartData.datasets[0].label = data; }); return chartData; } this.getRadarChartData = function(uid, lid, flag) { var info = { cid: lid, id: uid, action: "getusercourseknowledges", } var deferred = $q.defer(); var promise = deferred.promise; ApiService.post('/user', info).then(function(result) {; var userscores = []; if (result.data.success) { var userknowledges = result.data.data || []; var knowledgeSourse = getKnowledgeSourse(userknowledges); var radarChartData = prepareRadarChart(knowledgeSourse, flag); deferred.resolve(radarChartData); } else { deferred.reject(result); } }); return promise; } }).service('calendarEventService', function($filter) { this.checkEvent = function(event) { return '<i class="fa fa-check" ></i>'; } });