knowledgebaseCtrl.js 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. app.controller('knowledgebaseCtrl', ["$rootScope","$scope", "$state", "$timeout", "$interval", "SweetAlert", "$modal", "FileUploader", "i18nService", "uiGridConstants", "uiGridGroupingConstants", "Restangular","api_user_data","api_solution", function ($rootScope, $scope, $state, $timeout, $interval, SweetAlert, $modal, FileUploader, i18nService, uiGridConstants, uiGridGroupingConstants, Restangular, api_user_data, api_solution) {
  2. $scope.langs=i18nService.getAllLangs();
  3. $scope.lang = 'zh-cn';
  4. var loginUser = $rootScope.user;
  5. $scope.gridOptions = {};
  6. $scope.gridOptions.data = 'myData';
  7. $scope.gridOptions.enableColumnResizing = true;
  8. $scope.gridOptions.enableFiltering = false;
  9. $scope.gridOptions.enableGridMenu = false;
  10. $scope.gridOptions.enableRowSelection = true;
  11. $scope.gridOptions.showGridFooter = true;
  12. $scope.gridOptions.showColumnFooter = false;
  13. $scope.gridOptions.fastWatch = true;
  14. $scope.gridOptions.useExternalPagination = true;
  15. $scope.gridOptions.paginationPageSizes = [10];
  16. $scope.gridOptions.paginationPageSize = 10;
  17. $scope.gridOptions.multiSelect = true;
  18. $scope.filterUserData = function(key){
  19. var data ={"idx":"0","sum":"5","user":{"roledata":{"rolecode":"user"}}};
  20. if(key){
  21. data['user']={
  22. 'name':key
  23. };
  24. }
  25. api_user_data.fetchDataList('user',data).then(function(response){
  26. if(response){
  27. if(response.status=200){
  28. $scope.approvalusers = response.list;
  29. }
  30. }
  31. })
  32. };
  33. $scope.addApprovalUser = function(item, model){
  34. var existUser = false;
  35. angular.forEach($scope.userdata,function(user){
  36. if(user.userid==item.id) existUser = true;
  37. });
  38. if(existUser){
  39. }else{
  40. $scope.userdata.push({userid:item.id,username:item.name});
  41. }
  42. }
  43. $scope.refreshListData = function(style,filterData){
  44. $scope.ldloading[style.replace('-', '_')] = true;
  45. if(angular.isUndefined(filterData)){
  46. filterData = defaultFilterData;
  47. }
  48. if(angular.isDefined($scope.searchTypes)){
  49. filterData['searchType'] = $scope.searchTypes;
  50. }
  51. $scope.myData = [];
  52. console.log("filterData="+filterData)
  53. }
  54. $scope.classifyClick = function(event, item){
  55. console.log(event);
  56. console.log(item);
  57. }
  58. var apple_selected, tree, treedata_avm, treedata_geography;
  59. //$scope.selectedTreeNode = {};ssss
  60. var i=0;
  61. $scope.out=[];
  62. $scope.outdata=[];
  63. var systemtype=[];
  64. $scope.my_tree_handler = function (branch) {
  65. filterData.treeIds = branch.id;
  66. $scope.selectedTreeNode = branch;
  67. $scope.output = branch ;
  68. var eqflag = false;
  69. angular.forEach($scope.outdata,function(item){
  70. if(item.id==$scope.output.id) eqflag = true;
  71. });
  72. if(eqflag){
  73. }else{
  74. $scope.outdata.push({
  75. 'name': $scope.output.label,
  76. 'id' : $scope.output.id
  77. });
  78. var postData = {
  79. typeList:[]
  80. };
  81. if($scope.outdata.length>0){
  82. angular.forEach($scope.outdata, function(data){
  83. postData.typeList.push({id:data.id});
  84. })
  85. }
  86. api_solution.findSolutionTypesUser(postData).then(function(response){
  87. //Restangular.
  88. $scope.userdata = response.data;
  89. angular.forEach($scope.userdata,function(item,index){
  90. $scope.userdata[index]['username']=item.name;
  91. $scope.userdata[index]['userid']=item.id;
  92. })
  93. });
  94. }
  95. };
  96. $scope.remove = function(element){
  97. var removeEl = -1;
  98. angular.forEach($scope.outdata,function(item, index){
  99. if(element.id==item.id) removeEl = index;
  100. });
  101. if(removeEl!=-1){
  102. $scope.outdata.splice(removeEl, 1);
  103. var postData = {
  104. typeList:[]
  105. };
  106. if($scope.outdata.length>0){
  107. angular.forEach($scope.outdata, function(data){
  108. postData.typeList.push({id:data.id});
  109. })
  110. }
  111. api_solution.findSolutionTypesUser(postData).then(function(response){
  112. //Restangular.
  113. $scope.userdata = response.data;
  114. angular.forEach($scope.userdata,function(item,index){
  115. $scope.userdata[index]['username']=item.name;
  116. $scope.userdata[index]['userid']=item.id;
  117. })
  118. });
  119. }
  120. }
  121. $scope.removeUser = function(element){
  122. var removeEl = -1;
  123. angular.forEach($scope.userdata,function(item, index){
  124. if(element.userid==item.userid) removeEl = index;
  125. });
  126. if(removeEl!=-1){
  127. $scope.userdata.splice(removeEl, 1);
  128. }
  129. }
  130. function convertListToTree(data, treeMap){
  131. var idToNodeMap = {}; //Keeps track of nodes using id as key, for fast lookup
  132. var root = null; //Initially set our loop to null
  133. var parentNode = null;
  134. //loop over data
  135. for(var i = 0; i < data.length; i++) {
  136. var datum = data[i];
  137. //each node will have children, so let's give it a "children" poperty
  138. datum.children = [];
  139. //add an entry for this node to the map so that any future children can
  140. //lookup the parent
  141. idToNodeMap[datum.id] = datum;
  142. //Does this node have a parent?
  143. if(typeof datum.parent === "undefined" || datum.parent == null) {
  144. //Doesn't look like it, so this node is the root of the tree
  145. root = datum;
  146. treeMap[datum.id] = root;
  147. } else {
  148. //This node has a parent, so let's look it up using the id
  149. parentNode = idToNodeMap[datum.parent];
  150. //We don't need this property, so let's delete it.
  151. delete datum.parent;
  152. //Let's add the current node as a child of the parent node.
  153. parentNode.children.push(datum);
  154. }
  155. }
  156. return root;
  157. }
  158. function convertParentToChildList(data){
  159. var treeMap = {};
  160. var list=[];
  161. convertListToTree(data, treeMap);
  162. angular.forEach(treeMap,function(item){
  163. list.push(item);
  164. });
  165. return list;
  166. }
  167. $scope.try_async_load = function () {
  168. $scope.my_data = [];
  169. $scope.doing_async = true;
  170. api_solution.findSolutionTypeActions(loginUser.id).then(function(response){
  171. var data = response.data;
  172. // console.log('data='+JSON.stringify(data));
  173. var objects = [];
  174. for (var i = 0; i < data.length; i++) {
  175. var object = {};
  176. object.id = data[i].id;
  177. if(data[i].pid != 0){
  178. object.parent = data[i].pid;
  179. }
  180. // if (object.parent == 0) {
  181. // object.parent = "#";
  182. // }
  183. object.label = data[i].typeName;
  184. object.actions = data[i].actions; //权限部分
  185. object.group = "1";
  186. object.user = "2";
  187. object.state = {
  188. "opened": true
  189. };
  190. object.typeName = "type";
  191. // if()
  192. // if (object.actions.indexOf("2") >= 0) { //知识库类型 具有增加权限--系统管理员
  193. // $scope.showAddSolutionType = true;
  194. // }
  195. // if (object.actions.indexOf("5") >= 0) { //知识库类型 具有授权权限--系统管理员
  196. // $scope.showReviewKnowledgeType = true;
  197. // }
  198. objects.push(object);
  199. }
  200. $scope.my_data = convertParentToChildList(objects);
  201. $scope.tree_data = angular.copy($scope.my_data);
  202. if($scope.my_data.length>0){
  203. $scope.doing_async = false;
  204. }
  205. });
  206. };
  207. $scope.cancel = function() {
  208. $scope.userdata=[];
  209. $scope.outdata=[];
  210. };
  211. $scope.reset = function() {
  212. $scope.userdata=[];
  213. $scope.outdata=[];
  214. };
  215. $scope.ok = function() {
  216. if($scope.outdata.length>0){
  217. var postData = {
  218. userList:[],
  219. typeList:[]
  220. };
  221. angular.forEach($scope.outdata, function(data){
  222. postData.typeList.push({id:data.id});
  223. });
  224. angular.forEach($scope.userdata, function(data){
  225. postData.userList.push({id:data.userid});
  226. });
  227. api_solution.addTypeUserAll(postData).then(function(response){
  228. if(response){
  229. if(response.status==200){
  230. $scope.userdata=[];
  231. $scope.outdata=[];
  232. SweetAlert.swal({
  233. title:"保存成功!",
  234. type:"success"
  235. })
  236. }else{
  237. SweetAlert.swal({
  238. title:"保存失败!",
  239. type:"error"
  240. })
  241. }
  242. }
  243. });
  244. }else{
  245. SweetAlert.swal({
  246. title:"请选择分类!",
  247. type:"error"
  248. })
  249. }
  250. };
  251. $scope.try_async_load();
  252. // $scope.ldloading={};
  253. var filterData = {
  254. key:'null',
  255. status:0,
  256. pageIndex:0,
  257. pageSum:10,
  258. //treeIds:'[]',
  259. userId:loginUser.id
  260. }
  261. }]);