processCtrl.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. 'use strict';
  2. /**
  3. * controllers for process
  4. */
  5. app.controller('processDefinedCtrl', ["$scope", "$stateParams", "$modal", "Restangular", "SweetAlert", "api_bpm", function($scope, $stateParams, $modal, Restangular, SweetAlert, api_bpm) {
  6. console.log($stateParams);
  7. if (angular.isString($stateParams.modelId) && $stateParams.modelId != "") {
  8. $scope.modelId = $stateParams.modelId;
  9. api_bpm.modelsource($stateParams.modelId).then(function(data) {
  10. if (data) {
  11. var myData = Restangular.stripRestangular(data);
  12. if (myData.data) {
  13. bpmnJS.openDiagram(myData.data);
  14. }
  15. }
  16. });
  17. }
  18. var bpmnJS = new window.BpmnJS({
  19. container: angular.element('#js-drop-zone'),
  20. canvas: angular.element('#js-canvas'),
  21. propertiesPanel: angular.element('#js-properties-panel')
  22. });
  23. $scope.createNewDiagram = function() {
  24. bpmnJS.createNewDiagram();
  25. }
  26. $scope.openDiagram = function(xml) {
  27. bpmnJS.openDiagram(xml);
  28. }
  29. var setEncoded = function(link, name, data) {
  30. var encodedData = encodeURIComponent(data);
  31. if (data) {
  32. link.addClass('active').attr({
  33. 'href': 'data:application/bpmn20-xml;charset=UTF-8,' + encodedData,
  34. 'download': name
  35. });
  36. } else {
  37. link.removeClass('active');
  38. }
  39. }
  40. $scope.downloadDiagram = function() {
  41. bpmnJS.saveDiagram(function(err, xml) {
  42. setEncoded(angular.element('#js-download-diagram'), 'diagram.bpmn', err ? null : xml);
  43. });
  44. }
  45. $scope.deploy = function() {
  46. bpmnJS.saveDiagram(function(err, xml) {
  47. if (err) {
  48. } else {
  49. var data = {
  50. 'json_xml': xml
  51. };
  52. if (angular.isDefined($scope.modelId)) {
  53. data.modelId = $scope.modelId;
  54. api_bpm.deploy(data).then(function(response) {
  55. console.log(response);
  56. });
  57. } else {
  58. var modalInstance = $modal.open({
  59. templateUrl: 'assets/views/process/tpl/modal_process.html',
  60. controller: function($scope, $modalInstance, title, Alert) {
  61. $scope.title = title;
  62. $scope.ok = function() {
  63. if (angular.isUndefined($scope.data.key) || $scope.data.key == "") {
  64. Alert.swal({
  65. title: "流程信息不能为空",
  66. text: "请将相关信息填写完全!",
  67. type: "error"
  68. });
  69. } else {
  70. $modalInstance.close($scope.data);
  71. }
  72. }
  73. $scope.cancel = function() {
  74. $modalInstance.dismiss('cancel');
  75. };
  76. },
  77. size: 'sm',
  78. resolve: {
  79. title: function() {
  80. return "配置流程属性";
  81. },
  82. Alert: function() {
  83. return SweetAlert;
  84. }
  85. }
  86. });
  87. modalInstance.result.then(function(processData) {
  88. if (processData) {
  89. angular.extend(processData, data);
  90. api_bpm.deploy(data).then(function(response) {
  91. console.log(response);
  92. });
  93. } else {
  94. }
  95. });
  96. }
  97. }
  98. });
  99. }
  100. $scope.save = function() {
  101. bpmnJS.saveDiagram(function(err, xml) {
  102. if (err) {
  103. } else {
  104. var data = {
  105. 'json_xml': xml
  106. };
  107. if (angular.isDefined($scope.modelId)) {
  108. var modelId = $scope.modelId;
  109. api_bpm.savemodel(modelId, data).then(function(response) {
  110. console.log(response);
  111. });
  112. } else {
  113. console.log()
  114. }
  115. }
  116. });
  117. }
  118. if (!window.FileList || !window.FileReader) {
  119. window.alert(
  120. 'Looks like you use an older browser that does not support drag and drop. ' +
  121. 'Try using Chrome, Firefox or the Internet Explorer > 10.');
  122. } else {
  123. bpmnJS.registerFileDrop(angular.element('#js-drop-zone'), bpmnJS.openDiagram);
  124. }
  125. }]);
  126. app.controller('processDefinedListCtrl', ["$scope", "$state", "$timeout", "$interval", "SweetAlert", "uiGridConstants", "uiGridGroupingConstants", "Restangular", "api_bpm", function($scope, $state, $timeout, $interval, SweetAlert, uiGridConstants, uiGridGroupingConstants, Restangular, api_bpm) {
  127. $scope.gridOptions = {};
  128. $scope.gridOptions.data = 'myData';
  129. $scope.gridOptions.enableColumnResizing = true;
  130. $scope.gridOptions.enableFiltering = true;
  131. $scope.gridOptions.enableGridMenu = true;
  132. $scope.gridOptions.showGridFooter = true;
  133. $scope.gridOptions.showColumnFooter = false;
  134. $scope.gridOptions.fastWatch = true;
  135. $scope.gridOptions.rowIdentity = function(row) {
  136. return row.id;
  137. };
  138. $scope.gridOptions.getRowIdentity = function(row) {
  139. return row.id;
  140. };
  141. $scope.gridOptions.columnDefs = [
  142. { name: 'id', width: 80, enableFiltering: false },
  143. { name: 'deploymentId', displayName: '部署Id', width: 100, enableFiltering: false },
  144. { name: 'name', displayName: '名称', width: 100 },
  145. { name: 'key', displayName: 'KEY', width: 150 },
  146. { name: 'version', displayName: '版本号', width: 100 },
  147. { name: '最后更新时间', field: 'lastUpdateTime', cellFilter: 'date', width: 150, type: 'date', enableFiltering: false },
  148. { name: '创建时间', field: 'createTime', cellFilter: 'date', width: 150, type: 'date', enableFiltering: false },
  149. {
  150. name: '操作',
  151. cellTemplate: '<div><div class="cl-effect-1 ui-grid-cell-contents pull-left" >' +
  152. '<a class="bianjifont" ng-click="grid.appScope.pdList.selectRowFunction(row.entity)">编辑</a><a class="fontcolor-seven" ng-click="grid.appScope.pdList.removeRowFunction(row.entity)">删除</a></div></div>',
  153. enableFiltering: false
  154. }
  155. ];
  156. $scope.gridOptions.importerDataAddCallback = function(grid, newObjects) {
  157. $scope.myData = $scope.myData.concat(newObjects);
  158. };
  159. $scope.gridOptions.onRegisterApi = function(gridApi) {
  160. $scope.gridApi = gridApi;
  161. //gridApi.selection.on.rowSelectionChanged($scope, selectRowFunction);
  162. };
  163. this.selectRowFunction = function(data) {
  164. console.log(data);
  165. $state.go('app.process.modeler', { modelId: data.id });
  166. };
  167. this.removeRowFunction = function(data) {
  168. //TODO $translate('key')
  169. SweetAlert.swal({
  170. title: "确认删除?",
  171. text: "删除以后,你将不能恢复该数据!",
  172. type: "warning",
  173. cancelButtonText: "取消",
  174. showCancelButton: true,
  175. confirmButtonColor: "#DD6B55",
  176. confirmButtonText: "确认删除!"
  177. }, function(isConfirm) {
  178. if (isConfirm) {
  179. api_bpm.removemodel(data.id).then(function(response) {
  180. if (response) {
  181. $scope.refreshData();
  182. SweetAlert.swal({
  183. title: "删除成功!",
  184. confirmButtonColor: "#007AFF"
  185. });
  186. }
  187. });
  188. } else {
  189. }
  190. });
  191. }
  192. $scope.callsPending = 0;
  193. var i = 0;
  194. $scope.refreshData = function() {
  195. $scope.myData = [];
  196. var start = new Date();
  197. var sec = $interval(function() {
  198. $scope.callsPending++;
  199. api_bpm.list().then(function(data) {
  200. $scope.callsPending--;
  201. var myData = Restangular.stripRestangular(data);
  202. $scope.myData = myData.data;
  203. });
  204. }, 200, 10);
  205. var timeout = $timeout(function() {
  206. $interval.cancel(sec);
  207. $scope.left = '';
  208. }, 2000);
  209. $scope.$on('$destroy', function() {
  210. $timeout.cancel(timeout);
  211. $interval.cancel(sec);
  212. });
  213. };
  214. $scope.refreshData();
  215. }]);