unserver-unify
Version:
906 lines (888 loc) • 31 kB
JavaScript
;
angular.module('bamboo.course').controller('CourseHomeCtrl', function($scope, $document, $log, loginService, $rootScope, $state, $uibModal, $sce, ApiService, CourseApi, CommonService, $stateParams, CourseService, AppConfig, UserService, pdfViewService, deviceDetector, youtubeEmbedUtils, ExamService, $location, fullWidthService, checksumHelper, smoothScroll, $timeout) {
var _self = this;
this.id = $stateParams.cid;
_self.share = $stateParams.share;
checksumHelper.check($stateParams.cs, $stateParams.cid);
this.course = {};
if (deviceDetector.isMobile() && !deviceDetector.isTablet()) {
this.course.theme = 'mobile';
}
this.scrollToExam = function() {
smoothScroll(document.getElementById('exam'));
}
this.scrollToAssignment = function() {
smoothScroll(document.getElementById('assignment'));
}
this.scrollToInfo = function() {
smoothScroll(document.getElementById('info'));
}
this.practicePicUrl = ApiService.SHOST + '/lcourse/' + this.id + '/';
$scope.tab = 'summary';
if($state.current.name=='index.courses.course.contents'){
$scope.tab = 'contents';
} else if($state.current.name=='index.courses.course.teachers'){
$scope.tab = 'teachers';
} else if($state.current.name=='index.courses.course.courseinfo'){
$scope.tab = 'courseinfo';
} else if($state.current.name=='index.courses.course.relatedcourse'){
$scope.tab = 'relatedcourse';
} else if($state.current.name=='index.courses.course.progress'){
$scope.tab = 'progress';
}
// console.log(loginService);
if (loginService.subDomain === "arg") {
$rootScope.fullwidthflag = true;
}
// $rootScope.fullwidthflag = true;;
$scope.$on("$destroy", function() {
// console.log('-- destroy --');
fullWidthService.listen();
});
$scope.user = loginService.user;
$scope.tabs = 'info';
$scope.appUrl = ApiService.APPURL;
this.assessmentvalue = 6;
$scope.prevURL = null;
$scope.currTab = null;
$scope.prevTab = null; //True for main tab and false for sub tab
$scope.tabStatus = []
this.imagePicUrl = ApiService.PSURL + "/avatar/";
this.examPhotoUrl = ApiService.SHOST + '/examphoto/' + ApiService.gid + '/';
_self.tab = 'summary';
//// console.log(loginService.school.slides[0].img);
if (loginService.school.slides[0] && loginService.school.slides[0].img) {
var banner = loginService.school.slides[0].img;
this.bannerUrl = ApiService.SHOST + "/public/" + ApiService.RES + "/school/" + ApiService.gid + "/" + banner;
}
var serviceFunctions = [];
// console.log(this.bannerUrl);
if (!loginService.user) {
$state.go('index.courses.info', {
cid: _self.id
});
return;
}
// this.defaultPersonPhotoUrl = ApiService.SHOST + "/public/images/user_icon&48.png";
if (_self.imagePicUrl && loginService.user._id && loginService.user.avatar) {
_self.profileImg = _self.imagePicUrl + loginService.user._id + '/' + loginService.user.avatar
} else {
_self.profileImg = _self.defaultPersonPhotoUrl;
}
if (!loginService.school.disableAdminStudy) {
if (loginService.user.is_admin || loginService.user.grole == 'admin' || loginService.user.grole == 'sysmanager' || loginService.user.grole == 'sysinspector') {
_self.inspectorFlag = true;
}
}
$scope.scrollTo = function(id) {
var duration = 1000; //milliseconds
var offset = 100; //pixels; adjust for floating menu, context etc
//Scroll to #some-id with 30 px "padding"
//Note: Use this in a directive, not with document.getElementById
var someElement = angular.element(document.getElementById(id));
$document.scrollToElement(someElement, offset, duration);
};
this.editable = false;
this.teacherdefault = 'assets/images/default-person-icon.png';
this.defaultPersonPhotoUrl = "assets/images/default-person-icon.png";
this.PicUrl = ApiService.SHOST + '/public/' + ApiService.RES;
this.teacherPicUrl = ApiService.SHOST + "/photo/" + ApiService.RES + "/teachers/";
this.coursePhotoUrl = ApiService.SHOST + '/lcourse/' + _self.id + "/";
this.courseURL = ApiService.SHOST + '/lcourse/';
this.mvPhotoUrl = ApiService.SHOST + '/lcourse/' + _self.id + '/download/';
$scope.averageRating = 0;
var colorlist = ['color-one', 'color-two', 'color-three', 'color-four', 'color-five', 'color-six', 'color-seven'];
var servicecolor = ['service-block-yellow', 'service-block-blue', 'service-block-dark', 'service-block-aqua', 'service-block-red', 'service-block-green', 'service-block-sea', 'service-block-purple', 'service-block-dark-blue'];
this.getlistcolor = function(index, level) {
var i = 5;
if (!level || level == 0) {
i = index % 2;
}
return colorlist[i];
}
this.review = function() {
$uibModal.open({
templateUrl: "components/dialog/rating-dlg.html",
controller: "RatingDlgCtrl",
controllerAs: 'ctrl',
resolve: {
title: function() {
return _self.course.name;
},
types: function() {
return ["Knowledge", "Attraction", "Content"];
}
}
}).result.then(function(result) {
var info = {
action: "addcourseassessment",
value: result.averageRating,
object: result,
id: _self.id,
}
CourseApi.post('/rating', info, function(result) {
_self.showassessment = false;
});
});
}
this.getServiceColor = function(index) {
var i = index % 9;
return servicecolor[i];
}
var commentstart = 0;
this.sendComment = function() {
var params = {
r_content: _self.commentscontent,
lid: _self.id,
action: "addcoursecomments",
};
ApiService.post('/mvtopics', params).then(function(result) {
if (result.data.success) {
commentstart = 0;
_self.commentscontent = "";
getLatestTopics();
} else {
CommonService.showError('Update Fail!');
}
});
}
function checkassessmentexit(callback) {
var info = {
action: "checkcourseassessmentexist",
id: _self.id,
};
CourseApi.post('/rating', info, function(result) {
if (result < 1) {
_self.showassessment = true;
}
});
return callback();
}
function filterExam(arr) {
var completedCourse = [];
var uncompletedCourse = [];
angular.forEach(arr, function(val, idx) {
if (val.mycount) {
completedCourse.push(val);
} else {
uncompletedCourse.push(val);
}
});
_self.completedCourse = completedCourse;
_self.uncompletedCourse = uncompletedCourse;
//// console.log(_self.completedCourse);
// // console.log(_self.uncompletedCourse);
}
this.showTab1 = 'list';
this.showTab2 = 'pgrid';
this.coursetopics = [];
this.relatedcourses = [];
// this.imgdefault = ApiService.SHOST + '/public/images/videos.png';
this.dictionPicUrl = ApiService.SHOST + "/dictionary/";
this.delete = function(topic) {
CommonService.confirm({
message: 'Are you sure you want to delete it?'
}).then(function() {
var params = {
reply_id: topic._id,
};
var idx = _self.coursetopics.indexOf(topic);
if (idx > -1) {
_self.coursetopics.splice(idx, 1);
if (_self.commentscount > 0) {
_self.commentscount--;
}
CourseApi.post('/reply/' + topic._id + '/delete', params, function() {
CommonService.showNoBlockInfo('Delete Successful!');
// getMvsubjectInfo();
getLatestTopics();
});
}
});
};
function setFullWidth(theme) {
if (theme === "purple") {
$rootScope.fullwidthflag = true;
}
}
if (loginService.school.courseRatingFlag) {
serviceFunctions.push(checkassessmentexit);
}
function getInfo(callback) {
$scope.id = _self.id;
/*if (loginService.school.courseRatingFlag) {
checkassessmentexit();
}*/
ApiService.get('/lcourse/' + _self.id).then(function(result) {
if (result.data.success) {
// console.log(result.data);
$timeout(function() {
_self.course = result.data.data;
if (!_self.course.video&&!_self.course.youtube&&!_self.course.photo) {
_self.imgdefault = 'assets/images/videos.png';
if (loginService.school.coursephoto) {
_self.imgdefault = ApiService.SHOST + "/public/" + ApiService.RES + "/school/" + ApiService.gid + "/" + loginService.school.coursephoto;
}
}
if (_self.course.relatedcourses && _self.course.relatedcourses.length > 0) {
serviceFunctions.push(getRelatedCourses);
}
_self.kcount = 0;
for (var key in _self.course.knowledgeCat) {
_self.kcount++;
}
setFullWidth(_self.course.theme);
$scope.youtubeUrl = _self.course.youtube;
//getAnnoucements();
if (_self.course.rating) {
$scope.averageRating = _self.course.rating.toString().substring(0, 3);
}
if (_self.course.video) {
//config video player
_self.outlinemp4config = {
sources: [{}],
tracks: [{}],
theme: AppConfig.videogular_theme,
cuePoints: {}
};
_self.outlinemp4config.sources = [{}];
_self.outlinemp4config.sources[0].src = _self.getPDFUrl(_self.course.video);
_self.outlinemp4config.sources[0].type = 'video/mp4';
}
if (_self.course.visitercounter) {
_self.visitercounter = _self.course.visitercounter;
}
//Set up config for tabs
var count = 0;
if (_self.course.plans) {
count += _self.course.plans.length;
}
if (_self.course.plan) {
count++;
}
// _setActiveTab(count);
if (deviceDetector.isMobile() && !deviceDetector.isTablet()) {
$rootScope.lcoursename = "Courseware";
} else {
$rootScope.lcoursename = _self.course.name;
}
// // console.log(names);
_self.course.contents = result.data.sections;
if (_self.course.singlesection) {
_self.course.theme = 'red';
var mvid = result.data.sections[0].id;
CourseApi.getInfo(mvid, function(result) {
var _contents = result.contents;
if (_contents) {
getMvSubjects(_contents);
} else {
getMvSubjects(_self.course.contents);
}
});
} else {
getMvSubjects(_self.course.contents);
}
if (deviceDetector.isMobile() && !deviceDetector.isTablet()) {
_self.course.theme = 'mobile';
}
if (!_self.course.editors) {
_self.course.editors = [];
}
_self.course.editors.push(_self.course.creater);
_self.getVideoUrl();
if (_self.course.editors.indexOf(loginService.user.name) > -1 && (loginService.user.grole && loginService.user.grole != 'user')) {
_self.editable = true;
}
return callback();
}, 200);
} else {
$state.go('index.404');
}
});
}
serviceFunctions.push(getInfo);
function checkCourseCert(callback) {
var info = {
id: _self.id,
action: "checkCertExist",
}
// console.log(info);
ApiService.post("/user", info).then(function(result) {
// // console.log(result);
if (result.data.success && result.data.data && result.data.data.courseId && result.data.data.courseId == _self.id) {
_self.courseCert = true;
}
});
return callback();
}
serviceFunctions.push(checkCourseCert);
// function getEditorInfo(callback) {
// var editors = _self.course.editors;
// var names = [];
// names.push(_self.course.creater);
// angular.forEach(editors, function(val, idx) {
// names.push(val);
// });
// // get teacher info for all editors
// UserService.getTeachersInfoByLoginnames(names, function(data) {
// var teacherinfos = {};
// _self.editors = [];
// angular.forEach(data, function(teacher, index) {
// if (teacher.photo && !teacher.avatarflag) {
// teacher.photourl = _self.teacherPicUrl + teacher._id + "/" + teacher.photo;
// } else if (teacher.avatar) {
// var user = {
// id: teacher.userid,
// avatar: teacher.avatar,
// }
// teacher.photourl = CommonService.getAvatarSrc(user);
// } else {
// teacher.photourl = _self.defaultPersonPhotoUrl;
// }
// _self.editors.push(teacher);
// })
// CourseService.setEditorInfo(_self.editors);
// // // console.log(_self.editors);
// });
// return callback();
// }
// serviceFunctions.push(getEditorInfo);
function getAnnoucements(callback) {
var info = {
action: "getannouncements",
lid: _self.id
}
ApiService.post("/news", info).then(function(result) {
_self.showdocs = true;
if (result.data.success) {
_self.Annoucements = result.data.data.data;
// // console.log(_self.Annoucements);
if (_self.Annoucements && _self.Annoucements.length > 0) {
// console.log("-- nothing ---");
} else if (_self.course.plan) {
_self.pdfviewerUrlsave(_self.course.plan);
} else if (_self.course.outline) {
_self.pdfviewerUrlsave(_self.course.outline);
} else if (_self.course.program) {
_self.pdfviewerUrlsave(_self.course.program);
} else if (_self.course.referenceinfo) {
//_self.pdfviewerUrlsave(_self.course.outline);
} else if (_self.course.plans && _self.course.plans.length > 0) {
_self.pdfviewerUrlsave(_self.course.plans[0]);
}
return callback();
} else {
return callback();
}
});
}
serviceFunctions.push(getAnnoucements);
function getRelatedCourses(callback) {
var ids = [];
if (_self.course.relatedcourses && _self.course.relatedcourses.length > 0) {
ids = ids.concat(_self.course.relatedcourses);
}
var info = {
ids: ids,
action: "getPublishCourseByIds",
};
//// console.log(ids);
CourseApi.lcApi(info, function(data) {
// // console.log(data);
var _fcourses = {};
angular.forEach(data, function(value, key) {
var id = value._id;
_fcourses[id] = value;
});
angular.forEach(_self.course.relatedcourses, function(value, key) {
var _course = _fcourses[value];
if (_course) {
_self.relatedcourses.push(_course);
}
});
// // console.log(_self.relatedcourses);
});
return callback();
}
function getLatestTopics() {
var info = {
action: 'getcoursecomments',
cid: _self.id,
start: commentstart,
}
ApiService.post('/mvtopics', info).then(function(result) {
if (result.data.success && result.data.data) {
if (_self.coursetopics.length <= commentstart && _self.coursetopics.length > 0) {
_self.coursetopics = _self.coursetopics.concat(result.data.data.topics);
} else {
_self.coursetopics = result.data.data.topics;
}
commentstart = _self.coursetopics.length;
_self.commentscount = result.data.data.count;
angular.forEach(_self.coursetopics, function(val, index) {
val.avatar_url = CommonService.getAvatarSrc(val.author);
})
} else {}
});
}
function getLatestTopicsCall(callback) {
getLatestTopics();
return callback();
}
serviceFunctions.push(getLatestTopicsCall);
this.getexamitems = function(tableState) {
var limit = tableState.pagination.number;
var start = tableState.pagination.start;
var info = {
cid: _self.id,
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;
}
_self.displayedCollection = data.items;
filterExam(_self.displayedCollection);
// console.log(_self.displayedCollection);
tableState.pagination.numberOfPages = Math.ceil(data.counter / limit);
// // console.log(tableState.pagination.numberOfPages);
});
}
this.getassignments = function(tableState) {
var limit = tableState.pagination.number;
var start = tableState.pagination.start;
var info = {
cid: _self.id,
start: start,
limit: limit,
//sort: tableState.sort,
action: "getUserAssignmentsForCourse",
}
// console.log(info);
ExamService.examApi(info, function(data) {
// console.log(data);
$scope.assignmentitems = data.items;
// console.log($scope.assignmentitems);
if (!data.counter) {
_self.hideAssignment = true;
}
tableState.pagination.numberOfPages = Math.ceil(data.counter / limit);
});
}
function getExamItemCall(callback) {
_self.showexam = true;
return callback();
}
serviceFunctions.push(getExamItemCall);
function getDictionary(callback) {
var info = {
start: 0,
limit: 20,
action: "getpublishcourseglossaries",
cid: _self.id,
};
// console.log(info);
ApiService.post('/dictionary', info).then(function(data) {
if (data.data.success) {
$scope.displayedDictions = data.data.data.items;
// console.log($scope.displayedDictions);
angular.forEach($scope.displayedDictions, function(item) {
item.href = ApiService.APPURL + '/diction/glossary/' + item._id;
});
return callback();
} else {
return callback();
}
});
}
serviceFunctions.push(getDictionary);
function getMore(callback) {
_self.getMore = getLatestTopics;
return callback();
}
serviceFunctions.push(getMore);
function getMvSubjects(contents) {
//var _pages = _self.course.contents;
// console.log(contents);
var _pages = contents;
var _wk = [];
var _row = {};
var mindex = 0;
var sindex = 0;
var tablelist = [];
for (var i = 0; i < _pages.length; i++) {
var page = _pages[i];
if (!page.level || page.level == 0) {
if (_row.main) {
_wk.push(_row);
}
_row = {};
mindex++;
sindex = 0;
} else if (page.level == 1) {
sindex++;
} else { // page.level>1
continue;
}
var idx = '' + mindex;
if (sindex > 0) {
idx += '-' + sindex
}
var id = page.id;
var info = {
id: id,
mindex: mindex,
title: page.name,
level: page.level,
idx: idx,
description: page.description,
photo: page.photo,
taskFlag: page.taskFlag,
pass: page.pass,
disable: page.disable,
// defaultpage: page.defaultpage,
};
tablelist.push(info);
if (!page.level || page.level == 0) {
var _row = {
main: info,
};
} else {
if (mindex < 1) {
continue;
}
if (!_row.sub) {
_row.sub = [];
}
_row.sub.push(info);
}
}
if (tablelist.length > 0) {
var chapters = [];
var cidx = tablelist[0].mindex;
var cinfo = new Array();
for (var p = 0; p < tablelist.length; p++) {
if (tablelist[p].mindex != cidx) {
var sinf = {
cidx: cidx,
cinfo: cinfo,
};
chapters.push(sinf);
cidx = tablelist[p].mindex;
cinfo = new Array();
}
cinfo.push(tablelist[p]);
}
var sinf = {
cidx: cidx,
cinfo: cinfo,
};
chapters.push(sinf);
}
if (_row.main) {
_wk.push(_row);
}
$scope.tablelist = tablelist;
$scope.charpters = chapters;
$scope.coursesrow = _wk;
// console.log($scope.tablelist);
}
function getEditorInfo(callback) {
var editors = _self.course.editors;
var names = [];
names.push(_self.course.creater);
angular.forEach(editors, function(val, idx) {
names.push(val);
});
// get teacher info for all editors
UserService.getTeachersInfoByLoginnames(names, function(data) {
var teacherinfos = {};
_self.editors = [];
angular.forEach(data, function(teacher, index) {
if (teacher.photo && !teacher.avatarflag) {
teacher.photourl = _self.teacherPicUrl + teacher._id + "/" + teacher.photo;
} else if (teacher.avatar) {
var user = {
id: teacher.userid,
avatar: teacher.avatar,
}
teacher.photourl = CommonService.getAvatarSrc(user);
} else {
teacher.photourl = _self.defaultPersonPhotoUrl;
}
_self.editors.push(teacher);
})
CourseService.setEditorInfo(_self.editors);
// // console.log(_self.editors);
});
return callback();
}
//getInfo();
function _setActiveTab(size) {
$scope.tabStatus = new Array(size);
for (var i = 0; i < size; i++) {
$scope.tabStatus[i] = false;
}
$scope.tabStatus[0] = true;
}
_setActiveTab();
this.getPDFUrl = function(file) {
return $sce.trustAsResourceUrl(_self.coursePhotoUrl + encodeURI(file));
};
this.pdfviewerUrlsave = function(pdfurl, status) {
this.showpdf = true;
$scope.currTab = status;
if (pdfurl == $scope.prevURL || ($scope.currTab == 'main' && $scope.prevTab == 'sub')) {
return;
} else {
$scope.prevURL = pdfurl;
$scope.prevTab = $scope.currTab;
pdfViewService.setpdfUrl(_self.coursePhotoUrl + encodeURI(pdfurl));
}
}
this.hidepdfdoc = function() {
this.showpdf = false;
}
this.changeTab = function(tabId) {
for (var i = 0; i < $scope.tabStatus.length; i++) {
$scope.tabStatus[i] = false;
}
$scope.tabStatus[tabId] = true;
}
this.getAssessmentResult = function() {
var tplUrl = "app/course/rating-dlg.html"
if (deviceDetector.isMobile() && !deviceDetector.isTablet()) {
tplUrl = "app/course/rating-mbl-dlg.html";
}
$uibModal.open({
templateUrl: tplUrl,
size: 'lg',
controller: 'RatingsRecordsCtrl',
controllerAs: 'ctrl',
backdrop: 'static',
resolve: {
courseid: function() {
return _self.id;
}
}
}).result.then(undefined, undefined);
}
var _protocol = window.location.protocol;
this.getVideoUrl = function() {
// var newId = _self.youtube_id_from_url(_self.course.youtube);
// return $sce.trustAsResourceUrl("//www.youtube.com/embed/" + newId + '?&controls=1&showinfo=0');
$scope.youtubeID = _self.course.youtube && youtubeEmbedUtils.getIdFromURL(_self.course.youtube);
$scope.youtubeUrl = $sce.trustAsResourceUrl('//www.youtube.com/embed/' + $scope.youtubeID + '?&controls=1&showinfo=0');
};
this.youtube_id_from_url = function(url) {
var id = '';
url = url.replace(/(>|<)/gi, '').split(/(vi\/|v=|\/v\/|youtu.be\/|\/embed\/)/);
if (url[2] !== undefined) {
id = url[2].split(/[^0-9a-z_]/i);
id = id[0];
} else {
id = url;
}
return id;
}
function getVideoitems(callback) {
var info = {
start: 0,
limit: 5000,
cid: _self.id,
action: 'getcoursemeetings',
};
ApiService.post("/vmeeting", info).then(function(result) {
//// console.log(result);
if (result.data.success) {
$scope.videoItems = result.data.data.items;
$scope.videoTotal = result.data.data.counter;
console.log($scope.videoItems);
angular.forEach($scope.videoItems, function(item, idx) {
// if (item.broadcast) {
// item.href = ApiService.APPURL + '/mymeetings/broadcast/' + item._id;
// } else {
// item.href = ApiService.APPURL + '/mymeetings/vroom/' + item.type + '/' + item._id;
// }
// val.joinurl = $scope.appUrl+"/mymeetings/"+val.type+"/"+val._id;
if (item.mtype=='broadcast') {
item.href = ApiService.APPURL + '/mymeetings/broadcast/' + item._id;
} else if (item.mtype=='controlppt') {
item.href = ApiService.APPURL + '/mymeetings/controlppt/' + item._id;
} else if(item.mtype=='youtube'){
item.href = ApiService.APPURL + '/mymeetings/youtube/' + item._id;
} else if(item.mtype=='nimvideo'){
item.href = ApiService.APPURL + '/mymeetings/nimvideo/' + item._id;
} else if(item.mtype=='espx'){
item.href = ApiService.APPURL + '/mymeetings/espx/' + item._id;
} else if(item.mtype=='interview'){
item.href = ApiService.APPURL + '/mymeetings/interview/' + item.type + '/' + item._id;
} else {
item.href = ApiService.APPURL + '/mymeetings/vroom/' + item.type + '/' + item._id;
}
});
// console.log($scope.videoItems);
return callback();
} else {
return callback();
}
});
}
serviceFunctions.push(getVideoitems);
this.redirect2Uapp = function(id, type) {
ExamService.redirect2Uapp(id, type);
}
this.shareCourse = function() {
var options = {
//size: "md-lg vertical-align-center",
size: 'sm',
animation: true,
component: 'socialShareDlg',
resolve: {
url: function() {
//return ApiService.BASEDOMAIN+"/#/courselist//info/"+ _self.id;
return $location.host() + "/#/courselist//info/" + _self.id;
}
}
};
$uibModal.open(options);
}
function getPracticeInfo(callback) {
var info = {
action: "getCourseKnowledgeQuestionCounters",
lid: _self.id,
};
ExamService.examApi(info, function(result) {
// console.log(result);
_self.counters = result.counterinfo;
angular.forEach(_self.counters, function(val, key) {
_self.totalq += val;
})
var category = {};
angular.forEach(result.courses, function(course, index) {
if (course.knowledgeCat) {
category = angular.merge({}, category, course.knowledgeCat);
}
})
if (result.cat) {
category = angular.merge({}, category, result.cat);
}
var catList = [];
CommonService.getArray(category, catList, 0, '');
_self.Knowledges = catList;
// console.log(_self.Knowledges);
getKnowLedgeSummary();
return callback();
});
}
serviceFunctions.push(getPracticeInfo);
this.totalscore = 0;
this.totalq = 0;
function getKnowLedgeSummary() {
_self.knowledgesData = {};
var info = {
action: "getKnowledgeTestSummary",
cid: _self.id,
};
ExamService.examApi(info, function(result) {
// console.log(result);
if (result) {
angular.forEach(_self.Knowledges, function(item) {
var key = item.key;
if (result[key]) {
item.result = getcalresult(result[key], key);
_self.totalscore += result[key].score * 10;
item.score = result[key].score * 10;
}
if (item.items && item.items.length) {
angular.forEach(item.items, function(_item) {
var _key = _item.key;
if (result[_key]) {
_self.totalscore += result[_key].score * 10;
_item.result = getcalresult(result[_key], _key);
_item.score = result[_key].score * 10;
}
})
}
_self.knowledgesData[key] = item;
})
}
});
}
function getcalresult(val, key) {
var total = _self.counters[key];
if (total) {
var options = {
total: total,
counter: val.counter,
qs: val.qs,
completeRate: val.qs * 100 / total,
correctRate: val.correct * 100 / (val.total),
}
if (options.qs > total) {
options.qs = total;
}
return options;
}
return {};
}
function getPracticeList(callback) {
var info = {
id: _self.id,
action: "getKnowledgeGroups",
}
CourseApi.lcApi(info, function(data) {
$scope.practiceList = data;
angular.forEach($scope.practiceList, function(_item) {
_item.score = 0;
_item.question = 0;
if (_item.knowledges) {
angular.forEach(_item.knowledges, function(val) {
if (_self.knowledgesData[val] && _self.knowledgesData[val].score) {
_item.score += _self.knowledgesData[val].score;
}
if (_self.knowledgesData[val] && _self.knowledgesData[val].result && _self.knowledgesData[val].result['total']) {
_item.question += _self.knowledgesData[val].result['total'];
} else if (_self.counters[val]) {
_item.question += _self.counters[val];
}
});
}
});
// console.log($scope.practiceList);
// console.log(_self.knowledgesData);
// console.log(_self.counters);
});
return callback();
}
serviceFunctions.push(getPracticeList);
/*
function getCourseAssignments(callback)
{
var info = {
cid: _self.id,
action: "getcourseassignments",
}
// console.log(info);
CourseApi.lcApi(info, function(data) {
// console.log(data);
$scope.assignmentitems = data;
});
return callback();
}
serviceFunctions.push(getCourseAssignments);*/
// console.log(serviceFunctions);
var waterfall = contra;
waterfall.waterfall(serviceFunctions, function(err) {
// console.log(err);
});
this.gotoKnowledge = function(key) {
$rootScope.knowledgeKey = key;
$state.go('index.courses.course.knowledges');
}
});