unserver-unify
Version:
124 lines (119 loc) • 4.61 kB
JavaScript
;
angular.module('bamboo').controller('oplHomeCtrl', function($scope, $location, TopicApi, $state, CourseService, loginService, ApiService, $rootScope, deviceDetector,fullWidthService) {
$rootScope.fullwidthflag = true;
$scope.$on("$destroy", function() {
console.log('-- destroy --');
fullWidthService.listen();
});
loginService.school = loginService.school || {};
//console.log( $location.host())
if (loginService.school.themecolors) {
$scope.coursebtmStyle = {
"background-color": loginService.school.themecolors.coursewidgetbtmcolor
};
}
this.searchCourses = function(q) {
$state.go('index.searchcourse', {
key: q
});
}
//$scope.newsbtmStyle = {"background-color":loginService.school.themecolors.newswidgetbtmcolor};
this.hosturl = $location.host();
$scope._SHOST = ApiService.SHOST;
$scope._RES = ApiService.RES;
$scope.appUrl = ApiService.APPURL;
this.companypath = ApiService.SHOST + '/company/';
this.productpath = ApiService.SHOST + '/product/';
this.defaultProductPhoto = "assets/images/product.png";
this.schoolurl = $scope.schoolUrl = ApiService.SHOST + "/public/" + ApiService.RES + "/school/" + ApiService.gid + "/";
this.publicUrl = $scope.publicUrl = ApiService.SHOST + "/public/images/";
this.defaultCoursePhoto = ApiService.SHOST + "/public/images/videos.png";
if (loginService.school.coursephoto) {
this.defaultCoursePhoto = ApiService.SHOST + "/public/" + ApiService.RES + "/school/" + ApiService.gid + "/" + loginService.school.coursephoto;
}
this.defaultCompanyPhoto = "assets/images/company.png";
this.companypath = ApiService.SHOST + '/company/';
var self = this;
var mycourses = [];
this.topCourses = [];
this.featureCourses = [];
this.latestCourses = [];
function compareCourses(courseList) {
if (courseList && courseList.length > 0) {
angular.forEach(courseList, function(item) {
if (item.infoOnlyFlag) {
item.courseurl = "index.courses.infoonly";
} else if (mycourses.indexOf(item._id) > -1) {
item.courseurl = "index.courses.course";
} else {
item.courseurl = "index.courses.info";
}
})
}
}
this.sortmethod; //visitercounter, position,score,update,created,recommend,top
this.getNewCourses = function() {
var sortmethod = "update";
var weekago = new Date();
var searchmethod = null;
weekago.setDate(weekago.getDate() - 30);
//getCoursebyCondition(self.latestCourses,sortmethod,searchmethod,4);
CourseService.getCoursesWithSorting(0, sortmethod, searchmethod, 4).then(function(result) {
console.log(result.data);
//_courses = result.data.data.items;
self.latestCourses = result.data.data.items || [];
//compareMyCourses(courseList);
compareCourses(self.latestCourses);
});
}
this.getTopCourses = function() {
var sortmethod = 'top';
var searchmethod = {
top: true,
}
CourseService.getCoursesWithSorting(0, sortmethod, searchmethod, 4).then(function(result) {
console.log(result.data);
//_courses = result.data.data.items;
self.topCourses = result.data.data.items || [];
//compareMyCourses(courseList);
compareCourses(self.topCourses);
});
}
this.getStarCourses = function() {
var sortmethod = 'star';
var searchmethod = {
star: true,
}
CourseService.getCoursesWithSorting(0, sortmethod, searchmethod, 4).then(function(result) {
self.featureCourses = result.data.data.items || [];
compareCourses(self.featureCourses);
});
}
function getAllCourses() {
self.getNewCourses();
self.getTopCourses();
self.getStarCourses();
}
if(loginService.user) {
loginService.getMyProfile().then(function(result) {
mycourses = result.courses;
})
}
if (loginService.school.homepage == "opnl" && $state.current.name == "index.home") {
return $state.go('index.home.opernlearning');
}
$scope.slides = loginService.school.slides;
$scope.myInterval = 5000;
$scope.AppLogoUrl = ApiService.SHOST + "/public/" + ApiService.RES + "/schoolapp/" + loginService.school._id + "/";
$scope.urls = loginService.school.urls;
getAllCourses();
var info = {
action: "gethomecompanys",
}
ApiService.post("/business", info).then(function(result) {
if (result.data.success) {
console.log(result.data.data);
self.companys = result.data.data;
}
});
});