UNPKG

unserver-unify

Version:

258 lines (256 loc) 8.76 kB
'use strict'; angular.module('bamboo.user').controller('TeacherInfoCtrl', function($scope, $state, loginService, $sce, UserService, $stateParams, CommonService, ApiService, $rootScope, $uibModal,fullWidthService,checksumHelper) { var _self = this; checksumHelper.check($stateParams.cs,$stateParams.teacherloginname); this.defaultpic = ApiService.SHOST + "/public/images/videos.png"; this.coursePhotoUrl = ApiService.SHOST + '/lcourse/'; this.subjectPicUrl = ApiService.SHOST + "/public/" + ApiService.RES; var _userloginname = $stateParams.teacherloginname; this.imagePicUrl = ApiService.PSURL + "/avatar/"; this.defaultPersonPhotoUrl = "assets/images/default-person-icon.png"; _self.teacherdefault = ApiService.SHOST + '/public/images/defaultteacher.png'; _self.teacherPicUrl = ApiService.SHOST + "/photo/" + ApiService.RES + "/teachers/"; var teacherinfoId; var mycourses = []; this.topics = []; $scope.activeTab = "EditorInfo"; this.teacher = {}; _self.page = 0; if ((loginService.school.homepage == "genx"|| loginService.subDomain == 'openlearning') && ($state.current.name == "index.teacher.detail" || $state.current.name == "index.teacher.detail.summary")) { console.log($state.current.name); return $state.go('index.teacher.detailgsx', { teacherloginname: _userloginname }); } else if ($state.current.name == 'index.teacher.detailgsx') { $rootScope.fullwidthflag = true; } $scope.$on("$destroy", function() { console.log('-- destroy --'); fullWidthService.listen(); }); $scope.activateTab = function(tab) { $scope.activeTab = tab; } this.reviewSubmit = function() { console.log(_self.ratings); console.log(_self.ratingcomment); var info = { action: "addteacherassessment", value: _self.ratings, object: { averageRating: _self.ratings, comments: _self.ratingcomment, date: new Date(), ratings: { Attraction: _self.ratings, Knowledge: _self.ratings, Content: _self.ratings, } }, id: teacherinfoId, } console.log(info); ApiService.post('/rating', info).then(function(result) { if (result.data.success) { console.log(result.data); _self.showassessment = false; getTeacherComments(); } }); } this.review = function() { $uibModal.open({ templateUrl: "components/dialog/rating-dlg.html", controller: "RatingDlgCtrl", controllerAs: 'ctrl', resolve: { title: function() { return _userloginname; }, types: function() { return ["Knowledge", "Attraction", "Content"]; } } }).result.then(function(result) { console.log(result); var info = { action: "addteacherassessment", value: result.averageRating, object: result, id: teacherinfoId, } ApiService.post('/rating', info).then(function(result) { if (result.data.success) { _self.showassessment = false; getTeacherComments(); } }); }); } this.comments = []; function getTeacherComments() { var info = { action: 'getlatestteacherassessment', id: teacherinfoId, } ApiService.post('/rating', info).then(function(result) { if (result.data.success) { console.log(result.data); _self.comments = result.data.data; angular.forEach(_self.comments, function(item) { item.avatar = CommonService.getAvatarSrc(item.user || {}); }) } }); } this.sendmessage = function() { //console.log(teacherinfoId, _self.teacherinfo); CommonService.sendmsgdlg({ "userid": _self.teacherinfo.userid, "name": _self.teacherinfo.name || _self.teacherinfo.fullname }); } this.teachercounter = {}; this.init = function() { var names = []; UserService.getTeacherInfoByLoginname(_userloginname, function(data) { console.log(data); _self.teacherinfo = data; // UserService.getUserProfileByLoginname(_userloginname, function(data) { $rootScope.teachername = _self.teacherinfo.name; console.log(_self.teacherinfo); // _self.teacherinfo.user = data; if (_self.teacherinfo.video) { _self.videoUrl = $sce.trustAsResourceUrl(_self.teacherPicUrl + _self.teacherinfo._id + '/' + encodeURI(_self.teacherinfo.video)); } if (_self.teacherinfo.photo) { _self.teacherinfo.avatarSrc = _self.teacherPicUrl + _self.teacherinfo._id + "/" + _self.teacherinfo.photo; } else { var user = { id: _self.teacherinfo.userid, avatar: _self.teacherinfo.avatar, } _self.teacherinfo.avatarSrc = CommonService.getAvatarSrc(user); } var id = _self.teacherinfo.userid; // }); teacherinfoId = _self.teacherinfo._id; getTeacherComments(); if(loginService.user){ getfollowing (); } if (data.rating) { $scope.averageRating = data.rating.toString().substring(0, 3); } if (loginService.school.teacherRatingFlag&&loginService.isLogged) { checkassessmentexit(); } }); if ($state.current.name != 'index.teacher.detailgsx') { var info = { action: 'getteachercounters', id: _userloginname, } console.log(info); ApiService.post('/user', info).then(function(result) { // console.log(result); if (result.data.success) { console.log(result.data.data); _self.teachercounter = result.data.data; } else { var _err = result.data.error || '' + result.data.info || ''; CommonService.showNoBlockErr('Get Teachersinfo failed: ' + _err); } }) } console.log($state.current.name); if ($state.current.name == 'index.teacher.detailgsx') { UserService.getTeacherCoursesByLoginname(_userloginname, function(data) { console.log(data); _self.items = data.items; _self.coursecounter = data.counter; compareMyCourses(); }) } } _self.init(); //init this controller function checkassessmentexit() { var info = { action: "checkteacherassessmentexist", id: teacherinfoId, }; ApiService.post('/rating', info).then(function(result) { console.log(result); if (result.data.success) { if (!result.data.data||result.data.data < 1) { _self.showassessment = true; } } }); } this.following = function() { var info={ action:'addfollowing', uid:_self.teacherinfo.userid, } console.log(info); CommonService.POST('/user',info); } this.unFollow = function() { var info={ action:'delfollowing', uid:_self.teacherinfo.userid, } CommonService.POST('/user',info); } function getfollowing () { var info={ action:'getflowings', // uid:self.user.id, } console.log(info); CommonService.POST('/user',info,function(result){ console.log(result); if(result&&result.indexOf(_self.teacherinfo.userid)>-1){ //console.log("existed"); _self.followed=true; } }) } function compareMyCourses() { if (loginService.user) { loginService.getMyProfile().then(function(result) { // console.log(result); mycourses = result.courses; // console.log("Mycourses", mycourses); // callback(mycourses); if (mycourses && mycourses.length > 0) { // console.log("-- check --"); // console.log("-- timeout --"); angular.forEach(_self.items, function(item, index) { var id = item._id; if (mycourses.indexOf(id) > -1) { item.mycourseFlag = true; } }) } angular.forEach(_self.items, 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"; } }) _self.coursesinfo = _self.items; console.log(_self.coursesinfo); }); }else{ angular.forEach(_self.items, function(item, index) { item.courseurl = "index.courses.info"; }) _self.coursesinfo=_self.items; } } })