UNPKG

unserver-unify

Version:

172 lines (167 loc) 4.81 kB
'use strict'; angular.module('bamboo.topic').controller('CourseTopicsCtrl', function($scope, $timeout, loginService, ApiService, CommonService, $state, smoothScroll) { var _self = this; this.dep = null; this.key = null; this.cid = null; this.industries = []; this.category = ApiService.category; // console.log(this.category); this.Departments = ApiService.school.departments; //var categoryInfo = ApiService.categoryInfo; //this.pageSize = 10; this.pageSize = 10; if (loginService.user && !loginService.user.is_admin && (!loginService.user.grole || loginService.user.grole == 'user')) { $state.go('index.myforums'); } // $scope.isCollapsed = true; $scope.getText = function(string) { return string.replace(/<[^>]*>/g, "") } var departmentnames = {}; this.departmentlist = []; function getalldepartments() { var info = { action: 'getdepartmentsinfo', }; ApiService.post('/departments', info).then(function(result) { if (result.data.success) { var _departmentnames = result.data.data; for (var id in _departmentnames) { var name = _departmentnames[id]; departmentnames[name] = id; } for (var i = 0; i < _self.Departments.length; i++) { var name = _self.Departments[i]; var id = departmentnames[name]; var info = { id: id, name: name, }; _self.departmentlist.push(info); } console.log(_self.departmentlist); } }); }; this.categorylist = []; function getcategory() { angular.forEach(_self.category, function(val, key) { _self.categorylist.push(key); }) } if (loginService.school.coursebyDepartment) { getalldepartments() } else { getcategory(); } function getDepCourses(did) { var info = { action: "getcourselist", page: 0, start:0, limit: 50, did: did }; console.log(info); ApiService.post('/lcourses', info).then(function(result) { if (result.data.success) { console.log(result.data); $timeout(function() { _self.courses = result.data.data.items; }, 200) } }); } function getKeyCourses(key) { var info = { action: "getcourselist", page: 0, start:0, limit: 50, search: { industry: key } }; console.log(info); ApiService.post('/lcourses', info).then(function(result) { if (result.data.success) { console.log(result.data); $timeout(function() { _self.courses = result.data.data.items; }, 200) } }); } this.selectAll = function() { _self.cid = null; _self.dep = null; _self.key = null; _self.courses = []; _oldState.pagination.start = 0; _self.getTopics(_oldState); } this.selectDep = function(did) { console.log(did); _self.cid = null; _self.dep = did; _self.key = null; _oldState.pagination.start = 0; _self.getTopics(_oldState); getDepCourses(did); } this.selectKey = function(key) { console.log(key); _self.cid = null; _self.dep = null; _self.key = key; _oldState.pagination.start = 0; _self.getTopics(_oldState); getKeyCourses(key); // getDepCourses(did); } this.selectCourse = function(cid) { console.log(cid); _self.cid = cid; //_self.dep=null; //_self.key=null; _oldState.pagination.start = 0; _self.getTopics(_oldState); // getDepCourses(did); } var _oldState; this.getTopics = function(tableState) { if (tableState) { _oldState = tableState; } var limit = tableState.pagination.number || _self.pageSize; var start = tableState.pagination.start; var info = { action: "getCoursesTopics", start: start, limit: limit, sort: tableState.sort, search: tableState.search.predicateObject, }; //console.log(search) if (_self.cid) { info.cid = _self.cid; } else if (_self.dep) { info.dep = _self.dep; } else if (_self.key) { info.key = _self.key; } console.log(info); ApiService.post("/mvtopics", info).then(function(result) { console.log(result); if (result.data.success && result.data.data) { console.log(result.data.data.items); $scope.displayedTopics = result.data.data.items; tableState.pagination.numberOfPages = Math.ceil(result.data.data.counter / limit); $scope.totalcounter = result.data.data.counter; } else { $scope.displayedTopics = []; } }); } });