unserver-unify
Version:
218 lines (203 loc) • 7.21 kB
JavaScript
;
angular.module('bamboo').controller('SidebarCtrl', function($scope, $timeout, ApiService, loginService, siteConfigSvs, forumBizModel,HomeService,CourseService) {
var _self = this;
var homeConfig = siteConfigSvs.getConfig().homeConfig || {};
_self.HIDE_HOT_TOPIC = homeConfig.hideHotTopic;
this.schoolIconUrl = ApiService.SHOST + "/public/" + ApiService.RES + "/school/" + ApiService.gid + "/";
this.typeclassname = {
html: "fa fa-html5",
html5: "fa fa-object-group",
lms: "fa fa-newspaper-o",
lms2004: "fa fa-newspaper-o",
ppt: "fa fa-file-powerpoint-o",
ppts: "fa fa-file-powerpoint-o",
mp4: 'fa fa-video-camera',
youtube: 'fa fa-youtube-play',
poetry: 'fa fa-book',
youku: 'fa fa-chevron-circle-right',
flash: 'fa fa-line-chart',
test: 'fa fa-pencil-square',
pdf: 'fa fa-file-pdf-o',
doc: 'fa fa-file-word-o',
word: 'fa fa-gamepad',
eword: 'fa fa-cubes',
audioexp: 'fa fa-headphones',
docs: 'fa fa-file-word-o',
docx: 'fa fa-file-word-o',
xls: 'fa fa-file-excel-o',
xlsx: 'fa fa-file-excel-o',
reading: 'fa fa-volume-up',
mp3: 'fa fa-music',
mp3ppt: 'fa fa-file-audio-o',
chapterexam: 'fa fa-pencil-square-o',
exam: 'fa fa-pencil-square-o',
chooseans: 'fa fa-pencil-square-o',
quiz: 'fa fa-question',
article: 'fa fa-file-text-o',
assignment: 'fa fa-list',
vimeo: 'fa fa-vimeo',
mp4ppt: 'fa fa-file-video-o',
ebook: 'fa fa-book',
img: 'fa fa-picture-o',
mp4quiz: 'fa fa-question fa-video-camera',
onlinequizvimeo: 'fa fa-question fa-vimeo',
onlinequizyoutube: 'fa fa-question fa-youtube-play',
msoffice: 'fa fa-windows',
openoffice: 'fa fa-file',
bishun: "fa fa-strikethrough",
idiom: "fa fa-commenting-o",
dragfill: 'fa fa-pencil-square-o',
fillblank: "fa fa-pencil-square-o",
coursesurvey: "fa fa-check-square-o fa-fw"
};
$scope.image = 'assets/images/reel/DSCN1345.jpg';
$scope.images = "assets/images/reel/DSCN13##.jpg|45..50"
$scope.reel_control = {}
$scope.reel_id = "reel"
loginService.school = loginService.school || {};
if(!loginService.school.disableAdminStudy){
if (loginService.user && (loginService.user.is_admin || loginService.user.grole == 'admin' || loginService.user.grole == 'dinspector' || loginService.user.grole == 'sysinspector')) {
_self.inspectorFlag = true;
}
}
console.log(loginService.school);
var serviceFunctions = [];
var mycourses = [];
if (loginService.school.numberOfCourses) {
_self.limited_courses = loginService.school.numberOfCourses;
}
/*if (loginService.school.jobFlag) {
var info = {
action: "getrecents",
}
ApiService.post("/job", info).then(function(result) {
// console.log(result);
if (result.data.success) {
console.log(result.data.data);
_self.jobs = result.data.data;
}
});
}*/
this.aindex = 0;
var timer;
function rotateAnnoucement() {
//console.log(aindex);
_self.aindex++;
if (_self.aindex >= $scope.announcementnames.length) {
_self.aindex = 0;
}
$scope.announcement = $scope.announcementnames[_self.aindex];
timer = $timeout(rotateAnnoucement, 3000);
};
this.logincounter = loginService.school.logincounter || 0;
this.visitorcounter = loginService.school.visitercounter || 0;
$scope.$on("$destroy", function() {
if (timer) {
$timeout.cancel(timer);
}
});
var schoolUrl = ApiService.SHOST + "/public/" + ApiService.RES + "/school/" + ApiService.gid + "/";
if (loginService.school.sideadv) {
$scope.sideadv = schoolUrl + loginService.school.sideadv;
}
if (loginService.school.side) {
$scope.side = schoolUrl + loginService.school.side;
}
if (loginService.school.links) {
var links = [];
angular.forEach(loginService.school.links, function(link) {
if (link.enable) {
links.push(link)
}
})
$scope.links = links;
}
function getStatus(callback) {
HomeService.getSideBarInfo(function(err, value) {
var _result = value;
_self.notice = _result.notice;
$scope.resources = _result.resources;
$scope.surveys = _result.surveys;
$scope.announcementnames = _result.annoucements;
if ($scope.announcementnames && $scope.announcementnames.length) {
timer = $timeout(rotateAnnoucement, 3000);
}
$scope.hottopics = _result.topics;
console.log($scope.hottopics);
changeHotTopics();
return callback();
});
}
serviceFunctions.push(getStatus);
function changeHotTopics() {
// when subdomain is stec , then change the hot topics
var flag = (loginService.subDomain === 'stec');
flag && forumBizModel.getGeneralHotTopics().then(function(data) {
console.log(data);
$scope.hottopics = data;
});
}
function getTopUser(callback) {
HomeService.getTopGameScoreUsers(function(err, students) {
console.log(students);
_self.Topusers = students;
angular.forEach(_self.Topusers,function(user){
if(user.summary){
user.scores=user.summary.gameexp||0 + user.summary.gamemastery||0 + user.summary.gamectizship||0;
}
});
return callback();
});
}
function compareMyCourses(_courses) {
if (mycourses && mycourses.length > 0) {
angular.forEach(_courses, function(item, index) {
var id = item._id;
if (mycourses.indexOf(id) > -1) {
item.mycourseFlag = true;
}
})
}
angular.forEach(_courses, function(item, index) {
if (item.infoOnlyFlag) {
item.courseurl = "index.courses.infoonly";
} else if (self.inspectorFlag || item.mycourseFlag) {
item.courseurl = "index.courses.course";
} else {
item.courseurl = "index.courses.info";
}
})
return _courses;
}
function getHomeContent(callback) {
loginService.getMyProfile().then(function(result) {
mycourses = result.courses;
return callback();
},function(err){
return callback();
})
}
serviceFunctions.push(getHomeContent);
function getTopRatingCourse(callback) {
_self.sortmethod = 'rating';
var searchmethod = {rating:{$gt:0}};
CourseService.getCoursesWithSorting(0, _self.sortmethod, searchmethod, _self.limited_courses).then(function(result) {
var _courses = result.data.data.items;
$scope.ratingcourses = compareMyCourses(_courses);
console.log(_courses);
return callback();
});
}
if(loginService.subDomain === 'xiaofuzi')
{
serviceFunctions.push(getTopRatingCourse);
}
if(loginService.subDomain === 'math'||loginService.subDomain === 'bamboo'){
serviceFunctions.push(getTopUser);
}
console.log(serviceFunctions);
var waterfall=contra;
waterfall.waterfall(serviceFunctions,function(err){
console.log(err);
})
});