inspectPlanCtrl.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686
  1. 'use strict';
  2. /**
  3. * controller for User Profile Example
  4. */
  5. app.controller('inspectPlanCtrl', ["$rootScope", "$scope", "$state", "$timeout", "$interval", "$modal", "SweetAlert", "i18nService", "uiGridConstants", "uiGridGroupingConstants", "Restangular", "api_bpm_schedule", "api_bpm_data", function($rootScope, $scope, $state, $timeout, $interval, $modal, SweetAlert, i18nService, uiGridConstants, uiGridGroupingConstants, Restangular, api_bpm_schedule, api_bpm_data) {
  6. $scope.langs = i18nService.getAllLangs();
  7. $scope.lang = 'zh-cn';
  8. i18nService.setCurrentLang($scope.lang);
  9. var loginUser = $rootScope.user;
  10. var defaultFilterData = {
  11. "idx": 0,
  12. "sum": 10
  13. };
  14. var inspectPlanParameter = {
  15. "idx": 0,
  16. "sum": 10,
  17. "operation": "",
  18. "status": "",
  19. "inspection": {
  20. "inspectionTypeDTO": {
  21. "id": ""
  22. }
  23. }
  24. };
  25. //本地存储
  26. sessionStorage.inspectPlanParameter = JSON.stringify(inspectPlanParameter);
  27. $scope.memoryfilterData = {
  28. "idx": 0,
  29. "sum": 10
  30. }
  31. // $scope.isMask = false;
  32. $scope.gridOptions = {};
  33. $scope.gridOptions.data = 'myData';
  34. $scope.gridOptions.enableColumnResizing = true;
  35. $scope.gridOptions.enableFiltering = false;
  36. $scope.gridOptions.enableGridMenu = false;
  37. $scope.gridOptions.enableRowSelection = true;
  38. $scope.gridOptions.showGridFooter = true;
  39. $scope.gridOptions.showColumnFooter = false;
  40. $scope.gridOptions.useExternalFiltering = false;
  41. $scope.gridOptions.useExternalPagination = true;
  42. $scope.gridOptions.paginationPageSizes = [10, 20, 50, 100];
  43. $scope.gridOptions.paginationPageSize = 10;
  44. $scope.gridOptions.multiSelect = true;
  45. $scope.gridOptions.enableSelectionBatchEvent = true; //使用批量使用事件
  46. //行鼠标悬浮变色功能
  47. // $scope.gridOptions.rowTemplate = '<div ng-repeat="(colRenderIndex, col) in colContainer.renderedColumns track by col.uid" ng-mouseover="grid.appScope.hoveredIndex = rowRenderIndex" ng-mouseleave="grid.appScope.hoveredIndex = null" ui-grid-one-bind-id-grid="rowRenderIndex + \'-\' + col.uid + \'-cell\'" class="ui-grid-cell" ng-class="{\'ui-grid-row-header-cell\': col.isRowHeader, \'your-hover-class\': grid.appScope.hoveredIndex === rowRenderIndex}" role="{{col.isRowHeader ? \'rowheader\' : \'gridcell\'}}" ui-grid-cell></div>';
  48. $scope.gridOptions.rowTemplate = "<div ng-dblclick=\"grid.appScope.onDblClick(row)\" ng-repeat=\"(colRenderIndex, col) in colContainer.renderedColumns track by col.uid\" ui-grid-one-bind-id-grid=\"rowRenderIndex + '-' + col.uid + '-cell'\" class=\"ui-grid-cell\" ng-class=\"{ 'ui-grid-row-header-cell': col.isRowHeader }\" role=\"{{col.isRowHeader ? 'rowheader' : 'gridcell'}}\" ui-grid-cell></div>";
  49. $scope.gridOptions.rowIdentity = function(row) {
  50. return row.id;
  51. };
  52. $scope.gridOptions.getRowIdentity = function(row) {
  53. return row.id;
  54. };
  55. $scope.transfer = function(status) {
  56. if (status === "正常") {
  57. return "执行中"
  58. } else if (status === "停止") {
  59. return "暂停中"
  60. }
  61. }
  62. $scope.gridOptions.columnDefs = [
  63. { name: 'item', displayName: '序号', width: 50, enableFiltering: false },
  64. { name: 'title', displayName: '计划主题', width: '10%', enableFiltering: true },
  65. { name: 'inspectionType.type', displayName: '巡检类型', width: '10%', enableFiltering: false },
  66. { name: 'status.name', displayName: '状态', width: '6%', enableFiltering: false },
  67. {
  68. name: 'executeUser.name',
  69. displayName: '执行人',
  70. width: '10%',
  71. enableFiltering: false,
  72. cellTemplate: '<div class="ui-grid-cell-contents">{{row.entity.executeUser.name || "当前值班人" }}</div>'
  73. },
  74. { name: 'planStrategy.name', displayName: '执行策略', width: '8%', enableFiltering: false },
  75. { name: 'excutionDate', displayName: '执行时间', width: '12%', enableFiltering: false },
  76. {
  77. name: 'executionTime',
  78. displayName: '执行时长',
  79. width: '6%',
  80. enableFiltering: false,
  81. cellTemplate: '<div class="ui-grid-cell-contents">{{row.entity.executionTime + "分钟"}}</div>'
  82. },
  83. { name: 'createUser.name', displayName: '创建人', width: '10%', enableFiltering: false },
  84. // { name: 'createTime', displayName: '创建时间', width: '12%', enableFiltering: false },
  85. {
  86. name: '操作',
  87. enableFiltering: false,
  88. cellTemplate: '<div class="cl-effect-1 ui-grid-cell-contents pull-left">' +
  89. // '<a ng-click="grid.appScope.selectRowFunction(row.entity)" tooltip="编辑" tooltip-placement="right"><i class="icon iconfont icon-bianji bianjifont"></i></a>' +
  90. '<a ng-click="grid.appScope.selectRowFunction(row.entity)" ng-show="{{row.entity.status.name==\'正常\'||row.entity.status.name==\'停止\'}}" class="bianjifont">编辑</a>' +
  91. // '<a ng-click="grid.appScope.runFunction(row.entity)" tooltip={{row.entity.runStatus}} tooltip-placement="left"><i class={{row.entity.style}}/></a>' +
  92. '<a ng-click="grid.appScope.runFunction(row.entity)" ng-show="{{row.entity.status.name==\'正常\'}}" class="handlefont">执行中</a>' +
  93. '<a ng-click="grid.appScope.runFunction(row.entity)" ng-show="{{row.entity.status.name==\'停止\'}}" class="handlefont">暂停中</a>' +
  94. '</div>'
  95. },
  96. // { name: 'planTime2', displayName: '截止时间', width: 160, enableFiltering: false },
  97. ];
  98. //新增数据
  99. $scope.addData = function() {
  100. $state.go('app.inspection.editor', {
  101. formKey: 'inspectionform',
  102. service: 'api_bpm_data',
  103. });
  104. }
  105. //跳转到编辑列表
  106. $scope.selectRowFunction = function(data) {
  107. var datas = delete data.item;
  108. datas = delete data.style;
  109. datas = delete data.runStatus;
  110. var filedata = {
  111. model: {
  112. inspection: data
  113. }
  114. };
  115. $state.go('app.inspection.editor', {
  116. formKey: 'inspectionform',
  117. service: 'api_bpm_data',
  118. model: JSON.stringify(filedata)
  119. });
  120. };
  121. //跳转到查看列表
  122. $scope.onDblClick = function(data) {
  123. var filedata = {
  124. model: {
  125. inspection: data.entity
  126. }
  127. };
  128. $state.go('app.inspection.form', {
  129. formKey: 'inspection__detailform',
  130. service: 'api_bpm_data',
  131. model: JSON.stringify(filedata)
  132. });
  133. };
  134. //跳转到查看列表
  135. $scope.lookFunction = function(data) {
  136. var filedata = {
  137. model: {
  138. inspection: data
  139. }
  140. };
  141. $state.go('app.inspection.form', {
  142. formKey: 'inspection__detailform',
  143. service: 'api_bpm_data',
  144. model: JSON.stringify(filedata)
  145. });
  146. };
  147. //巡检暂停/恢复
  148. $scope.runFunction = function(data) {
  149. var filterData = JSON.parse(sessionStorage.inspectPlanParameter);
  150. var upData = {};
  151. upData.id = data.id;
  152. upData.operation = 1;
  153. var modalInstance = $modal.open({
  154. // templateUrl: 'assets/views/inspect/changRun.html',
  155. templateUrl: 'assets/views/delete.html',
  156. // size: "sm",
  157. controller: function($scope, $modalInstance) {
  158. $scope.isRunFunction = true;
  159. var status = "";
  160. if (data.status == "正常") {
  161. $scope.title = '暂停巡检计划';
  162. $scope.connect = '确定要暂停该巡检计划?';
  163. // $scope.textLog = "是否暂停该巡检计划";
  164. } else if (data.status == "停止") {
  165. $scope.title = '开始巡检计划';
  166. $scope.connect = '确定要开始该巡检计划?';
  167. // $scope.textLog = "是否开始该巡检计划";
  168. }
  169. $scope.ok = function() {
  170. // var groupdata = "123";
  171. // $modalInstance.dismiss('cancel');
  172. if (data.status == "正常") {
  173. upData.status = "停止";
  174. // data.style = "fa fa-pause";
  175. } else if (data.status == "停止") {
  176. upData.status = "正常";
  177. // data.style = "fa fa-play";
  178. }
  179. sessionStorage.inspectPlanParameter = JSON.stringify(filterData);
  180. $modalInstance.close(upData);
  181. };
  182. $scope.cancel = function() {
  183. $modalInstance.dismiss('cancel');
  184. };
  185. },
  186. size: 'sm'
  187. })
  188. modalInstance.result.then(function(result) {
  189. if (result) {
  190. var upData = {
  191. "id": result.id,
  192. "operation": result.operation,
  193. "status": result.status
  194. };
  195. api_bpm_data.updData('inspection', upData).then(function(response) {
  196. var myData = Restangular.stripRestangular(response);
  197. if (myData.status == 200) {
  198. var showData = {
  199. "idx": filterData.idx,
  200. "sum": filterData.sum,
  201. "inspection": {
  202. "inspectionTypeDTO": {
  203. "id": ""
  204. }
  205. }
  206. }
  207. if (filterData.inspection && filterData.inspection.inspectionTypeDTO && filterData.inspection.inspectionTypeDTO.id) {
  208. showData.inspection.inspectionTypeDTO.id = filterData.inspection.inspectionTypeDTO.id
  209. } else {
  210. showData.inspection.inspectionTypeDTO.id = -1
  211. }
  212. $scope.refreshData('expand-right', showData);
  213. }
  214. }, function() {
  215. // $scope.ldloading[style.replace('-', '_')] = false;
  216. });
  217. }
  218. });
  219. };
  220. // $scope.newincident = function(data) {
  221. // $state.go('app.incident.editor', {});
  222. // };
  223. //行删除
  224. $scope.removeData = function() {
  225. console.log($scope.selected.items);
  226. var modalInstance = $modal.open({
  227. templateUrl: 'assets/views/delete.html',
  228. controller: function($scope, $modalInstance) {
  229. // $scope.textLog = "是否删除巡检计划";
  230. $scope.title = '巡检计划删除';
  231. $scope.connect = '确定要删除巡检计划?';
  232. $scope.ok = function() {
  233. $modalInstance.close("start");
  234. };
  235. $scope.cancel = function() {
  236. $modalInstance.dismiss('cancel');
  237. };
  238. },
  239. size: 'sm'
  240. })
  241. modalInstance.result.then(function(result) {
  242. if (result) {
  243. if ($scope.selected.items.length != 0) {
  244. $rootScope.isMask = true;
  245. }
  246. var rmvList = [];
  247. angular.forEach($scope.selected.items, function(item) {
  248. rmvList.push(item.id);
  249. });
  250. if (rmvList.length > 0) {
  251. api_bpm_data.rmvData('inspection', rmvList).then(function(response) {
  252. if (response.status == 200) {
  253. $rootScope.isMask = false;
  254. SweetAlert.swal({
  255. title: "删除成功!",
  256. type: "success",
  257. confirmButtonColor: "#007AFF"
  258. }, function() {
  259. $scope.myData = _.reject($scope.myData, function(o) { return _.includes(rmvList, o.id); });
  260. $scope.selected = {
  261. items: []
  262. };
  263. });
  264. $scope.gridApi.selection.clearSelectedRows();
  265. var filterData = JSON.parse(sessionStorage.inspectPlanParameter);
  266. var showData = {
  267. "idx": filterData.idx,
  268. "sum": filterData.sum,
  269. "inspection": {
  270. "inspectionTypeDTO": {
  271. "id": ""
  272. }
  273. }
  274. }
  275. if (filterData.inspection && filterData.inspection.inspectionTypeDTO && filterData.inspection.inspectionTypeDTO.id) {
  276. showData.inspection.inspectionTypeDTO.id = filterData.inspection.inspectionTypeDTO.id
  277. } else {
  278. showData.inspection.inspectionTypeDTO.id = -1
  279. }
  280. $scope.refreshData('expand-right', showData);
  281. //取消遮罩层
  282. // $scope.isMask = false;
  283. } else {
  284. $rootScope.isMask = false;
  285. SweetAlert.swal({
  286. title: "操作异常!",
  287. text: "系统异常,请稍后重试,或者联系管理员!",
  288. type: "error"
  289. });
  290. }
  291. })
  292. }
  293. }
  294. }, function() {
  295. // $scope.ldloading[style.replace('-', '_')] = false;
  296. });
  297. }
  298. $scope.selected = {
  299. items: []
  300. }
  301. $scope.editted = {
  302. items: []
  303. }
  304. $scope.testRow = [];
  305. $scope.gridOptions.onRegisterApi = function(gridApi) {
  306. //导入gridApi对象
  307. $scope.gridApi = gridApi;
  308. //分页选项
  309. gridApi.pagination.on.paginationChanged($scope, function(newPage, pageSize) {
  310. var filterData = JSON.parse(sessionStorage.inspectPlanParameter);
  311. var filtersData = {};
  312. filtersData.idx = newPage - 1;
  313. filtersData.sum = pageSize;
  314. $scope.pageNum = $scope.gridApi.pagination.getPage() - 1;
  315. // console.log(pp);
  316. filterData.idx = $scope.pageNum
  317. sessionStorage.inspectPlanParameter = JSON.stringify(filterData);
  318. $scope.refreshData('expand-right', filtersData);
  319. });
  320. //勾选行事件
  321. gridApi.selection.on.rowSelectionChanged($scope, function(data) {
  322. if (data.isSelected) {
  323. $scope.selected.items.push(data.entity);
  324. } else {
  325. //objs:需要遍历的集合 data:遍历时当前的数据 index:遍历时当前索引
  326. //array:需要遍历的集合,每次遍历时都会把objs原样的传一次。
  327. //angular.forEach(objs, function(data,index,array)
  328. angular.forEach($scope.selected.items, function(ObjIndex, index, destObj) {
  329. // console.log(ObjIndex);
  330. // console.log(index);
  331. // console.log(destObj);
  332. if (ObjIndex.id == data.entity.id) {
  333. destObj.splice(index, 1)
  334. }
  335. })
  336. }
  337. });
  338. //批量全选
  339. gridApi.selection.on.rowSelectionChangedBatch($scope, function(rows, event) {
  340. // if ($scope.selected.items.length != 0) {
  341. // $scope.selected.items = [];
  342. angular.forEach(rows, function(ObjIndex, index, destObj) {
  343. if (ObjIndex.isSelected) {
  344. $scope.selected.items.push(ObjIndex.entity);
  345. } else {
  346. $scope.selected.items = [];
  347. // $scope.selected.items.splice(index, 1);
  348. }
  349. });
  350. // } else {
  351. // }
  352. // $scope.mySelectedRows = $scope.gridApi.selection.getSelectedRows();
  353. // if ($scope.selected.items.length == 0) {
  354. // $scope.selected.items = $scope.mySelectedRows;
  355. // } else if ($scope.mySelectedRows.length == 0) {
  356. // for (var i = 0; i < $scope.selected.items.length; i++) {
  357. // for (var j = 0; j < rows.length; j++) {
  358. // if ($scope.selected.items[i].id == rows[j].entity.id) {
  359. // $scope.selected.items.splice(i, 1);
  360. // }
  361. // }
  362. // }
  363. // } else {
  364. // angular.forEach($scope.mySelectedRows, function(item) {
  365. // $scope.selected.items.push(item);
  366. // });
  367. // }
  368. });
  369. //列过滤事件
  370. gridApi.core.on.filterChanged($scope, function() {
  371. var grid = this.grid;
  372. var filterData = JSON.parse(sessionStorage.inspectPlanParameter);
  373. angular.forEach(grid.columns, function(item) {
  374. if (item.enableFiltering) {
  375. if (angular.isDefined(item.filters[0].term) && item.filters[0].term != '') {
  376. if (angular.isUndefined(filterData['inspection'])) {
  377. filterData['inspection'] = {};
  378. }
  379. filterData['inspection']['title'] = item.filters[0].term;
  380. }
  381. }
  382. });
  383. sessionStorage.inspectPlanParameter = JSON.stringify(filterData);
  384. $scope.refreshData('expand-right', filterData);
  385. });
  386. };
  387. //刷新按钮
  388. $scope.reload = function() {
  389. var filterData = JSON.parse(sessionStorage.inspectPlanParameter);
  390. var showData = {
  391. "idx": filterData.idx,
  392. "sum": filterData.sum,
  393. "inspection": {
  394. "inspectionTypeDTO": {
  395. "id": ""
  396. }
  397. }
  398. }
  399. if (filterData.inspection && filterData.inspection.inspectionTypeDTO && filterData.inspection.inspectionTypeDTO.id) {
  400. showData.inspection.inspectionTypeDTO.id = filterData.inspection.inspectionTypeDTO.id
  401. } else {
  402. showData.inspection.inspectionTypeDTO.id = -1
  403. }
  404. $scope.refreshData('expand-right', showData);
  405. }
  406. //数据刷新
  407. $scope.refreshData = function(style, filterData) {
  408. $scope.ldloading[style.replace('-', '_')] = true;
  409. if (angular.isUndefined(filterData)) {
  410. filterData = defaultFilterData;
  411. }
  412. $scope.myData = [];
  413. api_bpm_data.fetchDataList('inspection', filterData).then(function(data) {
  414. var myData = Restangular.stripRestangular(data);
  415. $scope.gridOptions.totalItems = myData.totalNum;
  416. if (angular.isArray(myData.list)) {
  417. $scope.myData = myData.list;
  418. for (var i = 0; i < $scope.myData.length; i++) {
  419. $scope.myData[i]['item'] = i + 1 + filterData.idx * filterData.sum
  420. }
  421. for (var i = 0; i < $scope.myData.length; i++) {
  422. if ($scope.myData[i].status == "正常") {
  423. $scope.myData[i].style = "fa fa-play";
  424. } else if ($scope.myData[i].status == "停止") {
  425. $scope.myData[i].style = "fa fa-pause";
  426. };
  427. $scope.myData[i].runStatus = $scope.transfer($scope.myData[i].status);
  428. }
  429. } else {
  430. SweetAlert.swal({
  431. title: "数据为空",
  432. text: myData.data,
  433. type: "warning"
  434. });
  435. }
  436. $scope.ldloading[style.replace('-', '_')] = false;
  437. }, function() {
  438. $scope.ldloading[style.replace('-', '_')] = false;
  439. });
  440. };
  441. $scope.ldloading = {};
  442. //树形控件点击事件
  443. $scope.my_tree_handler = function(branch) {
  444. var filterData = JSON.parse(sessionStorage.inspectPlanParameter);
  445. filterData.inspection.inspectionTypeDTO.id = branch.id;
  446. sessionStorage.inspectPlanParameter = JSON.stringify(filterData);
  447. var showData = {
  448. "idx": filterData.id,
  449. "sum": filterData.sum,
  450. "inspection": {
  451. "inspectionTypeDTO": {
  452. "id": branch.id
  453. }
  454. }
  455. }
  456. $scope.refreshData('expand-right', showData);
  457. }
  458. $scope.inspecttype = {};
  459. $scope.searchinspe = function(item) {
  460. var filedatas = defaultFilterData;
  461. filedatas.inspection = {};
  462. if (item.type) {
  463. angular.extend(filedatas.inspection, { 'inspectionTypeDTO': { 'id': item.type.id } });
  464. }
  465. if (item.title) {
  466. angular.extend(filedatas.inspection, { 'title': item.title });
  467. }
  468. $scope.refreshData('expand-right', filedatas);
  469. }
  470. //树形控件加载
  471. $scope.my_tree = {};
  472. $scope.try_async_load = function() {
  473. $scope.my_data = [];
  474. $scope.doing_async = true;
  475. api_bpm_data.fetchDataList('inspectionType', { "idx": 0, "sum": 1000 }).then(function(response) {
  476. if (response.status == 200) {
  477. var data = response.list;
  478. var objects = [];
  479. for (var i = 0; i < data.length; i++) {
  480. var object = {};
  481. object.id = data[i].id;
  482. if (data[i].parent && data[i].parent.id != 0) {
  483. object.parent = data[i].parent.id;
  484. }
  485. object.label = data[i].type;
  486. objects.push(object);
  487. }
  488. $scope.my_data = convertParentToChildList(objects);
  489. $scope.tree_data = angular.copy($scope.my_data);
  490. if ($scope.my_data.length > 0) {
  491. $scope.doing_async = false;
  492. }
  493. // return $scope.my_tree.expand_all()
  494. } else {
  495. SweetAlert.swal({
  496. title: "系统错误!",
  497. text: "请刷新重试!",
  498. type: "error"
  499. });
  500. }
  501. });
  502. };
  503. function convertListToTree(data, treeMap) {
  504. var idToNodeMap = {}; //Keeps track of nodes using id as key, for fast lookup
  505. var root = null; //Initially set our loop to null
  506. var parentNode = null;
  507. //loop over data
  508. for (var i = 0; i < data.length; i++) {
  509. var datum = data[i];
  510. //each node will have children, so let's give it a "children" poperty
  511. datum.children = [];
  512. //add an entry for this node to the map so that any future children can
  513. //lookup the parent
  514. idToNodeMap[datum.id] = datum;
  515. //Does this node have a parent?
  516. if (typeof datum.parent === "undefined" || datum.parent == null) {
  517. //Doesn't look like it, so this node is the root of the tree
  518. root = datum;
  519. treeMap[datum.id] = root;
  520. } else {
  521. //This node has a parent, so let's look it up using the id
  522. parentNode = idToNodeMap[datum.parent];
  523. //We don't need this property, so let's delete it.
  524. delete datum.parent;
  525. //Let's add the current node as a child of the parent node.
  526. parentNode.children.push(datum);
  527. }
  528. }
  529. return root;
  530. }
  531. function convertParentToChildList(data) {
  532. var treeMap = {};
  533. var list = [];
  534. convertListToTree(data, treeMap);
  535. angular.forEach(treeMap, function(item) {
  536. list.push(item);
  537. });
  538. return list;
  539. }
  540. $scope.try_async_load();
  541. $scope.refreshData('expand-right', defaultFilterData);
  542. }]);
  543. app.factory('inspectListMobileCtrlTree', ['api_bpm_data', function(api_bpm_data) {
  544. function convertListToTree(data, treeMap) {
  545. var idToNodeMap = {};
  546. var root = null;
  547. var parentNode = null;
  548. for (var i = 0; i < data.length; i++) {
  549. var datum = data[i];
  550. datum.children = [];
  551. idToNodeMap[datum.id] = datum;
  552. if (typeof datum.parent === "undefined" || datum.parent == null) {
  553. root = datum;
  554. treeMap[datum.id] = root;
  555. } else {
  556. parentNode = idToNodeMap[datum.parent];
  557. delete datum.parent;
  558. parentNode.children.push(datum);
  559. }
  560. }
  561. return root;
  562. };
  563. function convertParentToChildList(data) {
  564. var treeMap = {};
  565. var list = [];
  566. convertListToTree(data, treeMap);
  567. angular.forEach(treeMap, function(item) {
  568. list.push(item);
  569. });
  570. return list;
  571. };
  572. var forEachEelement = function forEachEelement(response) {
  573. var objects = [];
  574. angular.forEach(response.list, function(ObjIndex, index, destObj) {
  575. var object = {};
  576. object.id = ObjIndex.id;
  577. object.label = ObjIndex.type;
  578. if (ObjIndex.parent && ObjIndex.parent.id != 0) {
  579. object.parent = ObjIndex.parent.id;
  580. };
  581. if (ObjIndex.formUiEdit) {
  582. object.formUiEdit = ObjIndex.formUiEdit;
  583. };
  584. if (ObjIndex.formUiName) {
  585. object.formUiName = ObjIndex.formUiName;
  586. };
  587. if (ObjIndex.processKey) {
  588. object.processKey = ObjIndex.processKey;
  589. };
  590. if (ObjIndex.formUiStart) {
  591. object.formUiStart = ObjIndex.formUiStart;
  592. };
  593. objects.push(object);
  594. });
  595. var my_data = convertParentToChildList(objects);
  596. var tree_data = angular.copy(my_data);
  597. return {
  598. 'my_data': my_data,
  599. 'tree_data': tree_data
  600. }
  601. }
  602. return forEachEelement;
  603. }]);