UNPKG

unserver-unify

Version:

471 lines (461 loc) 16.2 kB
'use strict'; angular.module('bamboo.course').controller('CourseUserResultCtrl', function($scope, ApiService, CourseService, loginService, AppConfig, CommonService, CourseApi, $stateParams, $state, $rootScope, $timeout, CertService, $filter, certBizModel, courseBizModel, siteConfigSvs, UserService,ExamService, CertificateModel, deviceDetector) { var self = this; self.id = ApiService.gid; this.lid = this.courseId = $stateParams.cid; // save the current course id console.log($stateParams); this.uid = loginService.user._id; console.log(loginService.user); $scope.appUrl = ApiService.APPURL; this.gotoCourse = function() { $state.go('index.courses.course', { cid: self.lid, cs: ApiService.getCheckSum(self.lid) }); } this.history = {}; this.score = {}; this.additions = []; // this.course = $stateParams.courseParam; this.school = loginService.school; this.user = loginService.user; this.isQualified = false; $scope.haveCERT = false; this.schoolIconUrl = ApiService.PSURL + "/school/" + self.id + "/"; $scope.appUrl = ApiService.APPURL; $scope.showTab = "dashboard"; //if self.course from stateparams is null , then retrive from api if (!self.course) { ApiService.get('/course/' + self.courseId).then(function(result) { if (result.data.success) { self.course = result.data.data; $rootScope.lcoursename = self.course.name; if (deviceDetector.isMobile() && !deviceDetector.isTablet()) { $rootScope.lcoursename = null; } console.log(self.course); console.log("------course-------"); // console.log(self.course); } }); } this.reCalResult = function() { var info = { action: 'recaluserscores', userid: self.uid, cid: self.lid, } CourseApi.lcApi(info); } function getCourseResult() { var info = { cid: self.lid, uid: self.uid, action: "getcourseresult", }; console.log(info); ApiService.post('/user', info).then(function(result) { // console.log(result); if (result.data.success) { console.log("-------success---------"); // console.log(result.data.data); self.user = result.data.data.user; self.history = result.data.data.history; self.score = result.data.data.score; console.log(result); console.log(self.score); console.log(self.history); if (self.score) { self.additions.push(self.score.addition1 || {}); self.additions.push(self.score.addition2 || {}); self.additions.push(self.score.addition3 || {}); } if (self.history && self.history.progress && self.score) { if (self.history.progress.tasks && self.gradeSetting.totalMilestone) { self.milestoneresult = parseInt((self.history.progress.tasks * 100 / self.gradeSetting.totalMilestone)); } if (self.history.progress.chapters && self.gradeSetting.totalResources) { self.chapterresult = parseInt((self.history.progress.chapters * 100 / self.gradeSetting.totalResources)); } /* if (self.history.progress.chapters && self.history.progress.resources) { self.chapterresult = parseInt(self.history.progress.chapters * 100 / self.history.progress.resources); }*/ if (self.history.progress.topicpoints) { self.topicresult = parseInt(self.history.progress.topicpoints * 100 / self.score.topicMax || 10); } if (self.history.progress.replypoints) { self.replyresult = parseInt(self.history.progress.replypoints * 100 / self.score.replyMax || 10); } if (self.history.progress.timescores) { self.timeresult = parseInt(self.history.progress.timescores * 100 / self.gradeSetting.time || 10); } if (self.history.progress.examscores && self.score.examMax) { self.examresult = parseInt(self.history.progress.examscores * 100 / self.score.examMax); } if (self.history.progress.scormscores && self.score.scormMax) { self.scormresult = parseInt(self.history.progress.scormscores * 100 / self.score.scormMax); } if (self.history.progress.assginmentscores && self.score.assignmentMax) { self.assignmentresult = parseInt(self.history.progress.assginmentscores * 100 / self.score.assignmentMax); } if (self.history.progress.scores) { self.activityresult = parseInt(self.history.progress.scores * 100 / (self.score.activityMax || 10)); } if (!self.history.addition) { self.history.addition = {}; } var chapters = (self.history.progress.chapters)?self.history.progress.chapters:0; var totalRes = (self.gradeSetting&&self.gradeSetting.totalResources)?self.gradeSetting.totalResources:0; self.progress = parseInt(chapters * 100 / totalRes); } if (self.history && self.history.lmsRecords) { // console.log(self.history.lmsRecords); } if (self.score) { var examcounter = 0; angular.forEach(self.score.exams, function(item, key) { examcounter++; }) self.examcounter = examcounter; var assignmentcounter = 0; angular.forEach(self.score.assignments, function(item, key) { assignmentcounter++; }) self.assignmentcounter = assignmentcounter; } self.user.avatar_url = CommonService.getAvatarSrc(self.user); calTotalScore(); } else { //CommonService.showNoBlockErr('Get failed: ' + result.data.error); } }); } this.lmsResult = []; /* var _info = { action: 'getcoursescorms', cid: self.lid, }; console.log(_info); CourseApi.lcApi(_info, function(result) { console.log(result); });*/ var info = { cid: self.lid, action: "getcourselms", } CourseApi.mvApi(info, function(result) { // console.log(result); if (result.data) { console.log(result.data); // var records = result.data.records; var lmsinfo = {}; angular.forEach(result.data.resources, function(item) { lmsinfo[item._id] = item; }) self.thirdPartyScore = 0; angular.forEach(result.data.records, function(_value, key) { console.log(key); var val = JSON.parse(_value); console.log(val); if (val.cmi) { // 2004 var info = { name: lmsinfo[key].name, status: (val.cmi && val.cmi.completion_status), max: (val.cmi && val.cmi.score.max), raw: (val.cmi && val.cmi.score.raw), scaled: (val.cmi && val.cmi.score.scaled), time: (val.cmi && val.cmi.session_time), } if(info.time){ info.time=info.time.replace('PT',"").replace('M',":").replace('S',""); } self.thirdPartyScore += info.raw; self.lmsResult.push(info); } else { // v1.2 var info = { name: lmsinfo[key].name, status: val['cmi.core.lesson_status'] , max: val['cmi.core.score.max'] , raw: val['cmi.core.score.raw'] , time: val['cmi.core.session_time'] , } self.thirdPartyScore += info.raw; self.lmsResult.push(info); } }) console.log(self.lmsResult); } }) $scope.chartOptions = { scale: { pointLabels: { fontSize: 12 } } }; this.showKnowledge = function() { CourseService.getRadarChartData(self.uid, self.lid, self.onlyweak).then(function(data) { console.log(data); self.chartData = data; if (data && data.labels && data.labels.length > 0) { if (self.user) { self.chartData.datasets[0].label = self.user.fullname; } console.log("--- show here"); self.showChart = true; } }); $scope.showTab = 'knowledgechart'; } this.showexam = true; this.getexamitems = function(tableState) { var limit = tableState.pagination.number; var start = tableState.pagination.start; var info = { cid: self.lid, start: start, limit: limit, sort: tableState.sort, action: "getuserpublishexamsforcourse", } console.log(info); CourseApi.lcApi(info, function(data) { // console.log(data); if (!data || !data.counter) { self.showexam = false; } $scope.examitems = data.items; console.log($scope.examitems); tableState.pagination.numberOfPages = Math.ceil(data.counter / limit); }); } this.getassignments = function(tableState) { var limit = tableState.pagination.number; var start = tableState.pagination.start; var info = { cid: self.lid, start: start, limit: limit, sort: tableState.sort, action: "getUserAssignmentsForCourse", } console.log(info); ExamService.examApi(info, function(data) { $scope.assignmentitems = data.items; console.log($scope.assignmentitems); tableState.pagination.numberOfPages = Math.ceil(data.counter / limit); }); } /* var info = { cid: self.lid, action: "getcourseexamlist", } console.log(info); CourseApi.lcApi(info, function(data) { console.log(data); $scope.examitems = data.exams; $scope.testitems = data.tests; }); */ /* var info = { cid: self.lid, action: "getUserAssignmentsForCourse", } console.log(info); ExamService.examApi(info, function(data) { console.log(data); $scope.assignmentitems = data; // $scope.testitems = data.tests; });*/ var info = { action: 'getCourseTopUserTasks', lid: self.lid, } UserService.UserApi(info, function(data) { console.log(data); self.topTasks = data; // $scope.assignmentitems = data; // $scope.testitems = data.tests; }); this.DownloadCertificate = function() { //var certConfig = siteConfigSvs.getConfig().certConfig || {}; var conf = { courseId: self.courseId }; console.log(conf); certBizModel.downloadCERT('certificate.pdf', 'canvas', conf); }; function getDate() { var d = new Date(self.CERT && self.CERT.time); var datestring = d.getDate() + " / " + (d.getMonth() + 1) + " / " + d.getFullYear(); return datestring; } /* *params *totalScore :self.history.progress.course_score *passScore : self.score.pass */ function judgeQualified(totalScore, passScore) { switch (self.score.completionType) { case 'milestone': if (self.history.progress.tasks >= self.history.progress.milestones) { return true; } break; case 'score': if (self.history.progress && (self.history.progress.course_score >= self.score.pass)) { return true; } break; } /*if (!passScore || !totalScore) { return false; } if (totalScore >= passScore) { return true; }*/ return false; } function courseHaveCert(items, courseID) { for (var i = 0; i < items.length; i++) { if (items[i].courseId == courseID) { self.CERT = items[i]; return items[i]._id; } } return false; } var certinfo = { action: 'getmycerts', }; function loadSchoolInfo() { ApiService.getSchoolInfo().then(function(school) { $scope.school = self.school = school; $scope.certificate = school.certificate; var info = { id: self.courseId, action: "checkCertExist", } console.log(info); ApiService.post("/user", info).then(function(result) { console.log(result); if(result.data.success&&result.data.data){ $scope.haveCERT = true; $scope.showTab = "task"; self.cert = result.data.data; self.certId = result.data.data._id; draw(); } else { $scope.haveCERT = false; } }); // CertListApi(certinfo, function(data) { // console.info(data.items); // var haveCert = courseHaveCert(data.items, self.courseId) // // console.info(haveCert); // if (data.items.length > 0 && haveCert) { // $scope.haveCERT = true; // $scope.showTab = "task"; // self.cert = data; // // console.info(self.cert); // //$timeout(draw, 100); // self.certId = haveCert; // // console.log(haveCert); // draw(); // //getCertTpl(self.courseId, haveCert); // } else { // $scope.haveCERT = false; // } // }); }); }; loadSchoolInfo(); function draw() { var certData = { ElementId: "canvas", paddingtop: 150, schoolname: self.school.name, schoolIconUrl: self.schoolIconUrl, courseId: self.courseId, certId: self.certId, lang: $rootScope.currentLanguage //orientation:self.school.certOrientation }; console.log(certData); //certBizModel.drawCERT(certData); var model = CertificateModel.createCertModel(certData).getCertTemplate().then(function(data) { console.log(data); certBizModel.renderCERT(data); }); } function CertListApi(info, callback) { ApiService.post('/user', info).then(function(result) { if (result.data.success) { if (!callback) { CommonService.showNoBlockSuccess('Update Successful!'); } else { callback(result.data.data); } } }); } //console.info(certinfo); gradeSetting(); function calTotalScore() { console.info(self.history.progress); self.history.progress = self.history.progress || {}; $scope.totalScore = 0; $scope.totalScore += self.thirdPartyScore || 0; $scope.totalScore += self.history.progress.topicpoints || 0; $scope.totalScore += self.history.progress.replypoints || 0; $scope.totalScore += self.history.progress.additional || 0; $scope.totalScore += self.history.progress.assginmentscores || 0; $scope.totalScore += self.history.progress.examscores || 0; } function gradeSetting() { var info = { id: self.lid, action: "getcoursescoresconfig", } //get grade setting data CourseApi.lcApi(info, function(result) { console.log(result); self.score = result; if (!self.score.topicMax && self.score.topicMax != 0) { self.score.topicMax = 10; } if (!self.score.replyMax && self.score.replyMax != 0) { self.score.replyMax = 10; } if (!self.score.timeMax && self.score.timeMax != 0) { self.score.timeMax = 10; } self.additions.push(self.score.addition1 || {}); self.additions.push(self.score.addition2 || {}); self.additions.push(self.score.addition3 || {}); self.gradeSetting = result; self.additionTotalWeitage = 0; angular.forEach(self.additions, function(val, idx) { self.additionTotalWeitage += val.points || 0; }); console.log(self.gradeSetting); console.log(self.score); console.log(self.additionTotalWeitage); getCourseResult(); }) } if (loginService.school.errPaperFlag) { courseBizModel.isErrTestAvbl(self.lid).then(function(res) { self.isErrTestAvbl = res; }, function(res) { self.isErrTestAvbl = res; }); courseBizModel.isTargetTestAvbl(self.lid).then(function(res) { self.isTargetTestAvbl = res; }, function(res) { self.isTargetTestAvbl = res; }); } $scope.changeTab = function(tab) { $scope.showTab = tab; } });