unserver-unify
Version:
270 lines (262 loc) • 9.1 kB
JavaScript
;
angular.module('bamboo.course').controller("CourseLandingCtrl", function($scope, $stateParams, ApiService, $rootScope, CommonService, CourseApi, $sce,AppConfig,$timeout,VideoService) {
this.id = $stateParams.cid;
var _self = this;
getInfo();
this.imgdefault = ApiService.SHOST + '/public/images/videos.png';
this.coursePhotoUrl = ApiService.SHOST + '/lcourse/' + _self._id + "/";
var colorlist = ['color-one', 'color-two', 'color-three', 'color-four', 'color-five', 'color-six', 'color-seven'];
this.teacherPicUrl = ApiService.SHOST + "/photo/" + ApiService.RES + "/teachers/";
//$scope.teacherPhotoUrl = self.teacherPicUrl + teacher._id + "/" + teacher.photo;
function getInfo() {
var info = {
action: "getcourseinfo",
id: _self.id,
}
console.log(info);
ApiService.post("/market", info).then(function(result) {
if (result.data.success) {
console.log(result.data.data);
_self.item = result.data.data.item;
_self.course = result.data.data.course;
if(_self.course){
_self._id = _self.course._id;
}
_self.coursePhotoUrl = ApiService.SHOST + '/lcourse/' + _self._id + "/";
//for bamboo
if (_self.course) {
if (!_self.course.description) _self.course.description = _self.item.advInfo && _self.item.advInfo.description;
if (!_self.course.outcome) _self.course.outcome = _self.item.advInfo && _self.item.advInfo.outcome;
if (!_self.course.designedfor) _self.course.designedfor = _self.item.advInfo && _self.item.advInfo.designedfor;
if (!_self.course.coverage) _self.course.coverage = _self.item.advInfo && _self.item.advInfo.coverage;
if (!_self.course.venue) _self.course.venue = _self.item.advInfo && _self.item.advInfo.venue;
}
_self.type = _self.item.type;
console.log(_self.course);
//for not bamboo
$scope.advinfo = _self.item.advInfo || {};
$scope.advinfo.overview = _self.item.description || $scope.advinfo.overview;
console.log($scope.advinfo);
if (_self.item.type == 'bamboo') {
if (_self.course.infoOnlyFlag) {
$scope.url = "//" + _self.item.schoolkey + "." + ApiService.BASEDOMAIN + "/#/courselist//infoonly/" + _self.item.id;
} else {
$scope.url = "//" + _self.item.schoolkey + "." + ApiService.BASEDOMAIN + "/#/courselist//info/" + _self.item.id;
}
} else {
$scope.url = _self.item.url;
}
$rootScope.lcoursename = _self.course && _self.course.name;
if (!_self.course) {
$rootScope.lcoursename = _self.item.name;
}
_self.editors = _self.item.teachers;
//_self.editornames = _self.course && _self.course.editors;
console.log("------***-----");
console.log(result.data.data);
//$scope.advinfo =
if (_self.course) {
_self.lcoursePicUrl = ApiService.SHOST + '/lcourse/' + _self.course._id + '/' + _self.course.photo;
}
if (_self.item.type == 'bamboo') {
_self.item.url = '//' + _self.item.schoolkey + "." + ApiService.BASEDOMAIN + '/#/courselist//info/' + _self.item.id;
}
console.log("-----_self.course-------");
console.log();
//_self.course.contents = result.data.sections;
if (_self.course) {
if (_self.course.singlesection) {
if (loginService.user) {
var mvid = result.data.sections[0].id;
CourseApi.getInfo(mvid, function(result) {
var _contents = result.contents;
getMvSubjects(_contents);
});
}
} else {
getMvSubjects(_self.course.contents);
}
}
// config for outline video if available
if (_self.course && _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);
console.log(_self.getPDFUrl(_self.course.video));
_self.outlinemp4config.sources[0].type = 'video/mp4';
}
if(_self.course){
$scope.youtubeUrl = VideoService.getTrustYoutobeUrl(_self.course.youtube);
}
getLatestTopics();
}
});
};
this.getPDFUrl = function(file) {
console.log(_self.coursePhotoUrl + file);
return $sce.trustAsResourceUrl(_self.coursePhotoUrl + encodeURI(file));
};
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 getLatestTopics() {
var info = {
action: 'getcoursecomments',
cid: _self.id,
}
console.log(info);
ApiService.post('/mvtopics', info).then(function(result) {
console.log(result);
if (result.data.success && result.data.data) {
console.log(result.data.data);
_self.coursetopics = result.data.data.topics;
_self.commentscount = result.data.data.count;
angular.forEach(_self.coursetopics, function(val, index) {
val.avatar_url = CommonService.getAvatarSrc(val.author);
})
// console.log(_self.coursetopics);
// $state.reload();
} else {
// CommonService.showError('Update Fail!');
console.log(result.data);
}
});
};
this.delete = function(id) {
CommonService.confirm({
message: 'Are you sure you want to delete it?'
}).then(function() {
var params = {
reply_id: id,
};
CourseApi.post('/reply/' + id + '/delete', params, function() {
CommonService.showNoBlockInfo('Delete Successful!');
// getMvsubjectInfo();
getLatestTopics();
});
});
};
this.getVideoUrl = function() {
//var newId = {};
console.log(_self.course);
var newId = _self.youtube_id_from_url(_self.course.youtube);
return _self.course.youtube;
};
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;
};
this.getlistcolor = function(index, level) {
var i = 5;
if (!level || level == 0) {
i = index % 2;
}
return colorlist[i];
};
function getMvSubjects(contents) {
if (!contents) return;
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 {
sindex++;
}
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,
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 = 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;
}
});