123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480 |
- app.controller('knowledgeMobileCtrl', ["$rootScope", "$scope", "i18nService", "$state", "$timeout", "$interval", "SweetAlert", "$modal", "FileUploader", "uiGridConstants", "uiGridGroupingConstants", "Restangular", "api_user_data", "api_solution", "api_bpm_domain", "$aside", function($rootScope, $scope, i18nService, $state, $timeout, $interval, SweetAlert, $modal, FileUploader, uiGridConstants, uiGridGroupingConstants, Restangular, api_user_data, api_solution, api_bpm_domain, $aside) {
- $scope.langs = i18nService.getAllLangs();
- $scope.lang = 'zh-cn';
- i18nService.setCurrentLang($scope.lang);
- var loginUser = $rootScope.user;
- $scope.allfilterData = {
- key: 'null',
- status: 0,
- pageIndex: 0,
- pageSum: 10,
- //treeIds:'[]',
- userId: loginUser.id
- }
- $scope.paginationList = {
- 'count': 0,
- 'idx': 0,
- 'sum': 10,
- 'currentPage': 1,
- 'endPage': 0,
- 'pages': []
- }
- var filterData = {
- key: 'null',
- status: 0,
- pageIndex: 0,
- pageSum: 10,
- //treeIds:'[]',
- userId: loginUser.id
- }
- var knowledgeMobileCtrlParameter = {
- ' key': "null",
- 'pageIndex': 0,
- 'pageSum': 10,
- 'status': 0,
- 'userId': loginUser.id
- }
- sessionStorage.knowledgeMobileCtrlParameter = JSON.stringify(knowledgeMobileCtrlParameter);
- $scope.transferStatus = function(status) {
- var statusLabel = "不合法的状态";
- if (status == 1) {
- statusLabel = "待审核";
- } else if (status == 2) {
- statusLabel = "已批准";
- } else if (status == 3) {
- statusLabel = "已发布";
- } else if (status == 4) {
- statusLabel = "已取消";
- } else if (status == 5) {
- statusLabel = "已驳回";
- } else if (status == 6) {
- statusLabel = "已拒绝";
- }
- return statusLabel;
- }
- $scope.openAside = function(position) {
- var asideOpen = $aside.open({
- templateUrl: 'assets/views/knowledge/asideContent.html',
- placement: position,
- size: 'sm',
- backdrop: true,
- controller: function($scope, $modalInstance, api_user_data, api_solution) {
- $scope.ok = function(e) {
- $modalInstance.close("asideOpen");
- // e.stopPropagation();
- };
- $scope.cancel = function(e) {
- $modalInstance.dismiss();
- // e.stopPropagation();
- };
- $scope.statuses = [
- { status: 1, label: '待审核', idName: 'a' },
- { status: 2, label: '已批准', idName: 'b' },
- { status: 3, label: '已发布', idName: 'c' },
- { status: 4, label: '已取消', idName: 'd' },
- { status: 5, label: '已驳回', idName: 'e' },
- { status: 6, label: '已拒绝', idName: 'f' }
- ];
- $scope.onChange = function(searchType) {
- var filterData = JSON.parse(sessionStorage.knowledgeMobileCtrlParameter);
- filterData.searchType = searchType;
- sessionStorage.knowledgeMobileCtrlParameter = JSON.stringify(filterData);
- }
- $scope.my_tree_handler = function(branch) {
- var filterData = JSON.parse(sessionStorage.knowledgeMobileCtrlParameter);
- filterData.status = branch.id;
- sessionStorage.knowledgeMobileCtrlParameter = JSON.stringify(filterData);
- };
- function convertListToTree(data, treeMap) {
- var idToNodeMap = {};
- var root = null;
- var parentNode = null;
- for (var i = 0; i < data.length; i++) {
- var datum = data[i];
- datum.children = [];
- idToNodeMap[datum.id] = datum;
- if (typeof datum.parent === "undefined" || datum.parent == null) {
- root = datum;
- treeMap[datum.id] = root;
- } else {
- parentNode = idToNodeMap[datum.parent];
- delete datum.parent;
- parentNode.children.push(datum);
- }
- }
- return root;
- };
- function convertParentToChildList(data) {
- var treeMap = {};
- var list = [];
- convertListToTree(data, treeMap);
- angular.forEach(treeMap, function(item) {
- list.push(item);
- });
- return list;
- };
- $scope.my_tree = tree = {};
- $scope.try_async_load = function() {
- $scope.my_data = [];
- $scope.doing_async = true;
- api_solution.findSolutionTypeActions(loginUser.id).then(function(response) {
- if (response.status == 200) {
- var data = response.data;
- // console.log('data='+JSON.stringify(data));
- var objects = [];
- for (var i = 0; i < data.length; i++) {
- var object = {};
- object.id = data[i].id;
- if (data[i].pid != 0) {
- object.parent = data[i].pid;
- }
- // if (object.parent == 0) {
- // object.parent = "#";
- // }
- object.label = data[i].typeName;
- object.actions = data[i].actions; //权限部分
- object.group = "1";
- object.user = "2";
- object.state = {
- "opened": true
- };
- object.typeName = "type";
- objects.push(object);
- }
- $scope.my_data = convertParentToChildList(objects);
- $scope.tree_data = angular.copy($scope.my_data);
- if ($scope.my_data.length > 0) {
- $scope.doing_async = false;
- }
- } else {
- SweetAlert.swal({
- title: "系统错误!",
- text: "请刷新重试!",
- type: "error"
- });
- }
- });
- };
- $scope.try_async_load();
- }
- });
- asideOpen.result.then(function(result) {
- var filterData = JSON.parse(sessionStorage.knowledgeMobileCtrlParameter);
- $scope.refreshListData('expand-right', filterData);
- });
- };
- //前往第一页按钮
- $scope.paginationList.fristPage = function() {
- filterData.pageIndex = 0;
- $scope.refreshListData('expand-right', filterData);
- }
- //前往最后一页按钮
- $scope.paginationList.lastPage = function() {
- filterData.pageIndex = $scope.paginationList.endPage - 1;
- $scope.refreshListData('expand-right', filterData);
- }
- //加载某一页
- $scope.paginationList.loadPage = function(page) {
- $scope.allfilterData.pageIndex = page - 1;
- filterData.pageIndex = page - 1;
- $scope.refreshListData('expand-right', filterData);
- }
- //初始化分页栏
- var reloadPno = function() {
- $scope.paginationList.pages = calculateIndexes($scope.paginationList.currentPage, $scope.paginationList.endPage, 3);
- };
- //分页算法
- var calculateIndexes = function(current, length, displayLength) {
- var indexes = [];
- var start = Math.round(current - displayLength / 2);
- var end = Math.round(current + displayLength / 2);
- if (start <= 1) {
- start = 1;
- end = start + displayLength - 1;
- if (end >= length - 1) {
- end = length - 1;
- }
- }
- if (end >= length - 1) {
- end = length;
- start = end - displayLength + 1;
- if (start <= 1) {
- start = 1;
- }
- }
- for (var i = start; i <= end; i++) {
- indexes.push(i);
- }
- return indexes;
- };
- $scope.refreshListData = function(style, filterData) {
- $scope.ldloading[style.replace('-', '_')] = true;
- if (angular.isUndefined(filterData)) {
- filterData = defaultFilterData;
- }
- if (angular.isDefined($scope.searchTypes)) {
- filterData['searchType'] = $scope.searchTypes;
- }
- $scope.myData = [];
- api_solution.findSolutionByKeys(filterData).then(function(data) {
- var myData = Restangular.stripRestangular(data);
- if (angular.isArray(myData.list)) {
- $scope.myData = myData.list;
- if (angular.isDefined($scope.paginationList)) {
- $scope.paginationList.count = myData.totalNum;
- $scope.paginationList.endPage = Math.ceil($scope.paginationList.count / $scope.paginationList.sum);
- $scope.paginationList.currentPage = filterData.pageIndex + 1;
- reloadPno();
- }
- } else {
- SweetAlert.swal({
- title: "数据为空",
- text: myData.list,
- type: "warning"
- });
- }
- $scope.ldloading[style.replace('-', '_')] = false;
- }, function() {
- $scope.ldloading[style.replace('-', '_')] = false;
- });
- }
- $scope.createKnowledge = function() {
- var data = { model: { knowledge: { createUserId: loginUser.id, status: 1 } } };
- $state.go('app.knowledge.create', { formKey: 'knowledge_create', service: 'api_solution', 'model': JSON.stringify(data) })
- }
- $scope.detailSolution = function(id) {
- api_solution.findSolutionById(id).then(function(response) {
- var data = { model: { knowledge: response.data } };
- if (!isNaN(data.model.knowledge.vision)) {
- data.model.knowledge.vision = 'V' + String(data.model.knowledge.vision);
- }
- $state.go('app.knowledge.detail', { formKey: 'knowledge_detail', service: 'api_solution', 'model': JSON.stringify(data) })
- })
- }
- $scope.editSolution = function(id) {
- api_solution.findSolutionById(id).then(function(response) {
- var data = { model: { knowledge: response.data } };
- if (!isNaN(data.model.knowledge.vision)) {
- data.model.knowledge.vision = 'V' + String(data.model.knowledge.vision);
- }
- $state.go('app.knowledge.editor', { formKey: 'knowledge_editor', service: 'api_solution', 'model': JSON.stringify(data) })
- })
- }
- var apple_selected, tree, treedata_avm, treedata_geography;
- //$scope.selectedTreeNode = {};
- $scope.my_tree_handler = function(branch) {
- filterData.treeIds = branch.id;
- $scope.selectedTreeNode = branch;
- $scope.refreshListData('expand-right', filterData);
- };
- $scope.my_data = [];
- $scope.tree_data = [];
- $scope.my_tree = tree = {};
- function convertListToTree(data, treeMap) {
- var idToNodeMap = {}; //Keeps track of nodes using id as key, for fast lookup
- var root = null; //Initially set our loop to null
- var parentNode = null;
- //loop over data
- for (var i = 0; i < data.length; i++) {
- var datum = data[i];
- //each node will have children, so let's give it a "children" poperty
- datum.children = [];
- //add an entry for this node to the map so that any future children can
- //lookup the parent
- idToNodeMap[datum.id] = datum;
- //Does this node have a parent?
- if (typeof datum.parent === "undefined" || datum.parent == null) {
- //Doesn't look like it, so this node is the root of the tree
- root = datum;
- treeMap[datum.id] = root;
- } else {
- //This node has a parent, so let's look it up using the id
- parentNode = idToNodeMap[datum.parent];
- //We don't need this property, so let's delete it.
- delete datum.parent;
- //Let's add the current node as a child of the parent node.
- parentNode.children.push(datum);
- }
- }
- return root;
- }
- function convertParentToChildList(data) {
- var treeMap = {};
- var list = [];
- convertListToTree(data, treeMap);
- angular.forEach(treeMap, function(item) {
- list.push(item);
- });
- return list;
- }
- var uploader = $scope.uploader = new FileUploader({
- url: api_solution.upload().getRequestedUrl(),
- alias: "file",
- removeAfterUpload: true,
- queueLimit: 10
- // headers : {
- // }
- });
- $scope.my_tree = tree = {};
- $scope.try_async_load = function() {
- $scope.my_data = [];
- $scope.doing_async = true;
- api_user_data.fetchDataList('group', { "idx": 0, "sum": 1000 }).then(function(response) {
- var myData = Restangular.stripRestangular(response);
- var list = myData.list;
- var objects = [];
- for (var i = 0; i < list.length; i++) {
- var object = {};
- object.id = list[i].id;
- if (list[i].parent == 0) {
- object.parent = "#";
- } else {
- object.parent = list[i].parent;
- }
- object.text = list[i].groupName;
- object.typeName = "group";
- object.state = {
- "opened": true
- };
- objects.push(object);
- }
- $scope.groups = objects;
- });
- api_solution.findSolutionTypeActions(loginUser.id).then(function(response) {
- if (response.status == 200) {
- var data = response.data;
- // console.log('data='+JSON.stringify(data));
- var objects = [];
- for (var i = 0; i < data.length; i++) {
- var object = {};
- object.id = data[i].id;
- if (data[i].pid != 0) {
- object.parent = data[i].pid;
- }
- // if (object.parent == 0) {
- // object.parent = "#";
- // }
- object.label = data[i].typeName;
- object.actions = data[i].actions; //权限部分
- object.group = "1";
- object.user = "2";
- object.state = {
- "opened": true
- };
- object.typeName = "type";
- objects.push(object);
- }
- $scope.my_data = convertParentToChildList(objects);
- $scope.tree_data = angular.copy($scope.my_data);
- if ($scope.my_data.length > 0) {
- $scope.doing_async = false;
- }
- } else {
- SweetAlert.swal({
- title: "系统错误!",
- text: "请刷新重试!",
- type: "error"
- });
- }
- });
- $scope.showAddSolutionType = false; //添加知识类型 按钮
- $scope.showReviewKnowledgeType = false; //审核知识类型 按钮
- };
- $scope.try_async_load();
- $scope.ldloading = {};
- $scope.statuses = [
- { status: 1, label: '待审核' },
- { status: 2, label: '已批准' },
- { status: 3, label: '已发布' },
- { status: 4, label: '已取消' },
- { status: 5, label: '已驳回' },
- { status: 6, label: '已拒绝' }
- ];
- $scope.$watch('searchSolutionInput', function(oldvalue, newvalue) {
- // console.log(' oldvalue='+JSON.stringify( oldvalue));
- // console.log(' newvalue='+JSON.stringify( newvalue));
- // if(oldvalue==newvalue) return;
- if (angular.isUndefined(oldvalue) || oldvalue == '') {
- filterData.key = 'null';
- } else {
- filterData.key = oldvalue;
- }
- });
- $scope.searchSolution = function() {
- $scope.refreshListData('expand-right', filterData);
- }
- $scope.reload = function() {
- if ($rootScope.searchknowledge) { filterData = $rootScope.searchknowledge; }
- $scope.refreshListData('expand-right', filterData);
- }
- $scope.reload();
- }]);
|