unserver-unify
Version:
240 lines (235 loc) • 7.2 kB
JavaScript
;
angular.module('bamboo').controller('gsxHomeCtrl', function($scope, $location, TopicApi, $state, CourseService, loginService, ApiService, $rootScope, deviceDetector, fullWidthService, teacherBizModel, companyBizModel, courseBizModel) {
$rootScope.fullwidthflag = true;
var self = this;
this.searchObj = {};
$scope.$on("$destroy", function() {
console.log('-- destroy --');
fullWidthService.listen();
});
this.country = {
selected: ""
};
$scope.resp = [{
breakpoint: 3000,
settings: {
slidesToShow: 10,
slidesToScroll: 10
}
}, {
breakpoint: 2000,
settings: {
arrows: true,
slidesToShow: 5,
slidesToScroll: 5
}
}, {
breakpoint: 1500,
settings: {
//arrows: true,
slidesToShow: 4,
slidesToScroll: 4
}
}, {
breakpoint: 1400,
settings: {
//arrows: true,
slidesToShow: 4,
slidesToScroll: 4
}
}, {
breakpoint: 1300,
settings: {
//arrows: true,
slidesToShow: 4,
slidesToScroll: 4
}
}, {
breakpoint: 1024,
settings: {
slidesToShow: 3,
slidesToScroll: 3
}
}, {
breakpoint: 700,
settings: {
slidesToShow: 2,
slidesToScroll: 2
}
}, {
breakpoint: 300,
settings: {
slidesToShow: 1,
slidesToScroll: 1
}
}
// You can unslick at a given breakpoint now by adding:
// settings: "unslick"
// instead of a settings object
];
loginService.school = loginService.school || {};
//console.log( $location.host())
if (loginService.school.themecolors) {
$scope.coursebtmStyle = {
"background-color": loginService.school.themecolors.coursewidgetbtmcolor
};
}
this.fields = courseBizModel.getFirstLevelCourseCategory() || [];
self.durationOpts = [{
text: "All",
value: 0
}, {
text: "0-3 hours",
value: 3
}, {
text: "3-6 hours",
value: 6
}, {
text: "6-9 hours",
value: 9
}, {
text: "More than 9 hours",
value: 10
}];
self.courseTypeOpts = [{
text: "Online",
value: "online"
}, {
text: "Offline",
value: "offline"
}, {
text: "Pre-Booked",
value: "pre-book"
}];
//self.searchObj.training_duration = self.durationOpts[1].value;
self.searchObj.type = self.courseTypeOpts[0].value;
this.searchCourses = function(q) {
console.log(q);
//q.name = q.name || undefined;
console.log(q);
$state.go('index.searchcourse', {
key: JSON.stringify(q),
type: q.type
});
}
//$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 mycourses = [];
this.topCourses = [];
this.featureCourses = [];
this.latestCourses = [];
function compareCourses(courseList) {
if (courseList && courseList.length > 0) {
angular.forEach(courseList, function(item, index) {
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.getTopCourses = function() {
var sortmethod = 'top';
var searchmethod = {
top: true,
}
var option = {
lang: $rootScope.currentLanguage
};
CourseService.getCoursesWithSorting(0, sortmethod, searchmethod, 10, option).then(function(result) {
console.log(result.data);
self.topCourses = result.data.data.items || [];
//compareMyCourses(courseList);
compareCourses(self.topCourses);
});
}
function getOfflineCourses() {
var info = {
action: "getenablecourses",
start: 0,
limit: 10,
search: {
top: true,
lang: $rootScope.currentLanguage
},
};
ApiService.post('/ofcourse', info).then(function(result) {
console.log(result.data.data);
var offlinePath = ApiService.SHOST + "/ofcourses/";
self.ofcourses = result.data.data.items;
angular.forEach(self.ofcourses, function(item, index) {
if (item.photo) {
item.photourl = offlinePath + item.photo;
} else {
item.photourl = self.defaultCoursePhoto;
}
})
});
}
/* this.getStarCourses = function() {
var sortmethod = 'star';
var searchmethod = {
star: true,
}
CourseService.getCoursesWithSorting(0, sortmethod, searchmethod, 10).then(function(result) {
self.featureCourses = result.data.data.items || [];
compareCourses(self.featureCourses);
});
} */
function getAllCourses() {
//self.getNewCourses();
self.getTopCourses();
getOfflineCourses();
//self.getStarCourses();
}
if (loginService.user) {
loginService.getMyProfile().then(function(result) {
mycourses = result.courses;
})
}
if (loginService.school.homepage == "genx" && $state.current.name == "index.home") {
return $state.go('index.home.genx');
}
$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();
teacherBizModel.getHomepageTeachers().then(function(tchers) {
console.log(tchers);
tchers && (self.instructorList = tchers);
});
companyBizModel.getHomepageCompany().then(function(coms) {
console.log(coms);
coms && (self.instituteList = coms);
});
if (loginService.school.companyFlag) {
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;
}
});
}
});