unserver-unify
Version:
350 lines (316 loc) • 12 kB
JavaScript
;
angular.module('bamboo').controller('HomeV1Ctrl', function($scope, $location, CommonService, TopicApi, $state, CourseService, loginService, ApiService, $rootScope, deviceDetector, fullWidthService, $localStorage, schoolModel, SchoolAdvService,courseBizModel) {
console.log('-- detected OS / browser / device infos as below');
console.log('os: ' + deviceDetector.os);
console.log('browser: ' + deviceDetector.browser);
console.log('device: ' + deviceDetector.device);
console.log('Desktop:' + deviceDetector.isDesktop());
console.log('Mobile:' + deviceDetector.isMobile());
console.log('Tablet:' + deviceDetector.isTablet());
var self = this;
//console.log( $location.host())
this.hosturl = $location.host();
$scope._SHOST = ApiService.SHOST;
$scope._RES = ApiService.RES;
$scope.appUrl = ApiService.APPURL;
this.school=loginService.school;
//console.log(this.school);
this.defaultProductPhoto = "assets/images/product.png";
this.jobUrl = ApiService.SHOST + '/job/';
this.defaultJobPhoto = "/assets/images/jobs.png";
if (loginService.school.newsphoto) {
this.defaultJobPhoto = ApiService.SHOST + "/public/" + ApiService.RES + "/school/" + ApiService.gid + "/" + loginService.school.newsphoto;
}
$rootScope.fullwidthflag = true;
if (!loginService.isLogged && loginService.school.advPageFlag) {
$state.go('index.advertise');
return;
}
$scope.$on("$destroy", function() {
console.log('-- destroy --');
console.log($state.current.name);
fullWidthService.listen();
$rootScope.home_argbg_highlight_flag = undefined;
});
$rootScope.home_argbg_highlight_flag = ($state.current.name === "index.home");
if (loginService.school.themecolors) {
$scope.coursebtmStyle = {
"background-color": loginService.school.themecolors.coursewidgetbtmcolor
};
}
$scope.advType = loginService.school.homepageAdvType;
// console.log(loginService.school);
this.searchCourses = function(q) {
$state.go('index.searchcourse', {
key: JSON.stringify(q)
});
}
this.searchCoursesByCate = function(key){
$rootScope.courseCat = (key)?key:'';
$state.go('index.courses');
}
//Category starts
this.defultCatphoto = "assets/images/category.jpg";
self.catBannerUrl = ApiService.SHOST + '/wiki/';
console.log(self.bannerUrl);
$scope.bannerUrl = ApiService.SHOST + "/public/" + ApiService.RES + "/school/" + ApiService.gid + "/";
// var category = ApiService.category;
//console.log(category);
// self.categoryKeys = _.keys(category);
courseBizModel.getCategoryInfo().then(function(data) {
console.log(data);
self.catMap = data;
});
//Category Ends
this.schoolurl = ApiService.SHOST + "/public/" + ApiService.RES + "/school/" + ApiService.gid + "/";
this.publicUrl = $scope.publicUrl = ApiService.SHOST + "/public/images/";
this.schoolIconUrl = $scope.schoolUrl = ApiService.SHOST + "/public/" + ApiService.RES + "/school/" + ApiService.gid + "/";
this.teacherPicUrl = ApiService.SHOST + "/photo/" + ApiService.RES + "/teachers/";
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.defaultNewsPhoto = ApiService.SHOST + "/public/images/details.png";
if (loginService.school.newsphoto) {
this.defaultNewsPhoto = ApiService.SHOST + "/public/" + ApiService.RES + "/school/" + ApiService.gid + "/" + loginService.school.newsphoto;
}
this.defaultEventPhoto = ApiService.SHOST + "/public/images/details.png";
if (loginService.school.eventphoto) {
this.defaultEventPhoto = ApiService.SHOST + "/public/" + ApiService.RES + "/school/" + ApiService.gid + "/" + loginService.school.eventphoto;
}
if(!loginService.school.disableAdminStudy){
if (loginService.user && (loginService.user.is_admin || loginService.user.grole == 'admin' || loginService.user.grole == 'sysmanager' || loginService.user.grole == 'dinspector' || loginService.user.grole == 'sysinspector')) {
self.inspectorFlag = true;
}
}
if (loginService.school.theme == 't8') {
this.limits = {
courses: 5,
news: 3,
events: 5,
teachers: 5,
numberOfCourseCat: 5,
};
} else {
this.limits = {
courses: 8,
news: 4,
events: 4,
teachers: 4,
numberOfCourseCat:4,
};
}
$scope.getText = function(string) {
return string.replace(/<[^>]*>/g, "")
}
var mycourses = [];
if (loginService.school.videoFlag) {
ApiService.get("/homemeeting").then(function(result) {
if (result.data.success) {
var reftime = new Date(result.time)
self.vmeetings = result.data.data.items;
var systemtime = new Date(result.data.data.time).getTime() + 1000 * 60 * 10; // grace 10 minutes
angular.forEach(self.vmeetings, function(item) {
var type = item.type;
var start = new Date(item.start).getTime();
if (start < systemtime + 3000000) {
item.now = true;
} else {
var len = parseInt((start - systemtime) / (60000));
if (len < 120) {
item.minutes = len;
} else {
item.hours = parseInt(len / 60);
}
}
if (item.createUser) {
item.createUser.avatarurl = CommonService.getAvatarSrc(item.createUser);
}
if (item.hostUser) {
item.hostUser.avatarurl = CommonService.getAvatarSrc(item.hostUser);
}
console.log(item.mtype);
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 {
item.href = ApiService.APPURL + '/mymeetings/vroom/' + item.type + '/' + item._id;
}
})
}
});
}
function compareMyCourses(_courses) {
console.info(self.inspectorFlag);
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;
// $scope.lcourses = _courses;
}
function getLatestCourses() {
CourseService.getCoursesWithSorting(0, 'update', null, self.limits.courses).then(function(result) {
var _courses = result.data.data.items;
self.contentready = true;
$scope.latestCourses = compareMyCourses(_courses);
});
}
function getCoursebyCondition() {
}
this.changeapp = function(name) {
ApiService.changeToState(name);
var url = ApiService.APPURL + '/' + name.toLowerCase();
console.log(url);
window.open(url, '_blank');
}
/*this.changeurl = function(url) {
if (url.indexOf('/app/#/') == 0) {
ApiService.changeToState(url.substring(7));
window.open(url);;
};
}*/
function getHomeContent() {
loginService.getMyProfile().then(function(result) {
mycourses = result.courses;
})
if (loginService.school.numberOfCourses) {
self.limits.courses = loginService.school.numberOfCourses;
}
if (loginService.school.numberOfNews) {
self.limits.news = loginService.school.numberOfNews;
}
if (loginService.school.numberOfCourseCat) {
self.limits.numberOfCourseCat = loginService.school.numberOfCourseCat;
}
var info = {
action: "gethomenewses",
}
ApiService.post("/site", info).then(function(result) {
if (result.data.success) {
var homedata = result.data.data;
self.contentready = true;
$scope._newses = homedata.newses;
if ($state.current.name == "index.home.cmec") {
var text = "";
angular.forEach($scope._newses, function(value, key) {
text += " " + value.name + " " + value.created.substring(0, 10) + " " + value.description;
});
}
$scope.scrolltext = text;
// $scope.events = homedata.events;
$scope._topics = homedata.blogs;
$scope.lcourses = compareMyCourses(homedata.courses);
if ($scope._newses.length > 0) {
$scope.first_news = $scope._newses[0];
}
console.log($scope.first_news);
console.log($scope.events);
console.log($scope._newses);
getLatestCourses();
}
});
if (loginService.user && loginService.school.homepage != "fmas") {
var info = {
action: "gethomepageinfo",
}
ApiService.post("/site", info).then(function(result) {
if (result.data.success) {
console.log(result.data);
var homedata = result.data.data;
self.contentready = true;
$scope.apps = homedata.apps;
}
});
}
if (loginService.school.teachersFlag) {
var info = {
action: "gethometeachers",
}
ApiService.post("/site", info).then(function(result) {
if (result.data.success) {
$scope.teachers = result.data.data;
}
});
}
}
if (loginService.school.jobFlag) {
var info = {
action: "gethomejobs",
}
ApiService.post("/job", info).then(function(result) {
if (result.data.success) {
self.jobs = result.data.data;
}
});
}
$scope.slides = loginService.school.slides;
$scope.myInterval = 5000;
$scope.AppLogoUrl = ApiService.SHOST + "/public/" + ApiService.RES + "/schoolapp/" + loginService.school._id + "/";
$scope.urls = loginService.school.urls;
getHomeContent();
schoolModel.getSchool3Announcements().then(function(data) {
console.log(data);
self.schoolAnnous = data.data;
});
function getSchoolDoc() {
console.log(ApiService.school);
if (ApiService.school.homepageFeatureDoc) {
ApiService.get("/schooldoc/" + ApiService.school.homepageFeatureDoc).then(function(result) {
console.log(result);
if (result.data.success) {
var value = result.data.data;
$scope.advContent = value.content;
$scope.advContent2 = value.content2;
// _self.about = value.detail;
// _self.aboutCN = value.chinese;
$scope.advSlides = value.arrays;
$scope.learningAdvSlides = value.arrays2;
}
})
}
}
getSchoolDoc();
this.partnerPhotoPath = ApiService.SHOST + '/advinfo/';
function getPartner() {
var info = {
start: 0,
limit: Number.MAX_SAFE_INTEGER,
type: 'school',
action: "getpartners"
};
SchoolAdvService.advApi(info, function(result) {
console.log(result);
self.partnerItems = result.items;
$scope.total = result.counter;
});
}
getPartner();
function getEvents() {
var info = {
start: 0,
limit: self.limits.events,
action: "getvalidevents"
};
ApiService.post("/event", info).then(function(result) {
if (result.data.success) {
$scope.events = result.data.data.items;
}
});
}
getEvents();
});