UNPKG

unserver-unify

Version:

154 lines (149 loc) 5.6 kB
'use strict'; angular.module('bamboo').controller('MobileHomeCtrl', function($state, $scope, ApiService, loginService, CourseService) { // if (!loginService.isLogged ) { // $state.go('index.advertise'); // } var self = this; 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; } $scope.slides = loginService.school.slides; $scope.schoolUrl = ApiService.SHOST + "/public/" + ApiService.RES + "/school/" + ApiService.gid + "/"; $scope._SHOST = ApiService.SHOST; $scope._RES = ApiService.RES; $scope.showMobileLogo = true; ApiService.getSchoolInfo(self.subdomain).then(function() { console.log(ApiService.school) self.iconurl = ApiService.SHOST + "/public/" + ApiService.RES + "/school/" + ApiService.gid + "/"; if (ApiService.school.mobileadvs && ApiService.school.mobileadvs.length > 0) { self.mobileadvs = ApiService.school.mobileadvs; console.info(self.mobileadvs); } }); //self.mobileadvs = ApiService.school.mobileadvs; console.log($scope.showMobileLogo); this.limits = { courses: 8, news: 4, events: 4, teachers: 6, }; if (loginService.isLogged) { var info = { action: 'getschoolapps', } $scope.apps = []; $scope.appUrl = ApiService.APPURL; ApiService.post("/schools", info).then(function(result) { if (result.data.success) { var apps = result.data.data; $scope.apps = apps; } }); } var mycourses = []; 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 getHomeContent() { loginService.getMyProfile().then(function(result) { mycourses = result.courses; }) if (loginService.school.numberOfCourses) { self.limits.courses = loginService.school.numberOfCourses; } 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); getLatestCourses(); getRecommededCourses(); } }); // 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; // } // }); // } } 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 getRecommededCourses() { CourseService.getCoursesWithSorting(0, 'position', null, self.limits.courses).then(function(result) { var _courses = result.data.data.items; self.contentready = true; $scope.recommendedCourses = compareMyCourses(_courses); }); } console.info(loginService.school.bslides); if (loginService.school.homepage == "genx" && $state.current.name == "index.home") { return $state.go('index.home.genx'); } else if (loginService.school.homepage == "opnl" && $state.current.name == "index.home") { return $state.go('index.home.openlearning'); } else if (loginService.subDomain == "poiz" && $state.current.name == "index.home") { return $state.go('index.home.poiz'); } $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(); // } });