processCtrl.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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: '8%', enableFiltering: false },
  143. { name: 'deploymentId', displayName: '部署Id', width: '10%', enableFiltering: false },
  144. { name: 'name', displayName: '名称', width: '15%' },
  145. { name: 'key', displayName: 'KEY', width: '15%' },
  146. { name: 'version', displayName: '版本号', width: '8%' },
  147. { name: '最后更新时间', field: 'lastUpdateTime', cellFilter: 'date', width: '15%', type: 'date', enableFiltering: false },
  148. { name: '创建时间', field: 'createTime', cellFilter: 'date', width: '15%', type: 'date', enableFiltering: false },
  149. {
  150. name: '操作',
  151. // width:'200',
  152. cellTemplate: '<div><div class="cl-effect-1 ui-grid-cell-contents pull-left" >' +
  153. '<a class="bianjifont" ng-click="grid.appScope.pdList.selectRowFunction(row.entity)">编辑</a><a class="bianjifont" ng-click="grid.appScope.pdList.removeRowFunction(row.entity)">删除</a></div></div>',
  154. enableFiltering: false
  155. }
  156. ];
  157. $scope.gridOptions.importerDataAddCallback = function(grid, newObjects) {
  158. $scope.myData = $scope.myData.concat(newObjects);
  159. };
  160. $scope.gridOptions.onRegisterApi = function(gridApi) {
  161. $scope.gridApi = gridApi;
  162. //gridApi.selection.on.rowSelectionChanged($scope, selectRowFunction);
  163. };
  164. this.selectRowFunction = function(data) {
  165. console.log(data);
  166. $state.go('app.process.modeler', { modelId: data.id });
  167. };
  168. this.removeRowFunction = function(data) {
  169. //TODO $translate('key')
  170. SweetAlert.swal({
  171. title: "确认删除?",
  172. text: "删除以后,你将不能恢复该数据!",
  173. type: "warning",
  174. cancelButtonText: "取消",
  175. showCancelButton: true,
  176. confirmButtonColor: "#DD6B55",
  177. confirmButtonText: "确认删除!"
  178. }, function(isConfirm) {
  179. if (isConfirm) {
  180. api_bpm.removemodel(data.id).then(function(response) {
  181. if (response) {
  182. $scope.refreshData();
  183. SweetAlert.swal({
  184. title: "删除成功!",
  185. confirmButtonColor: "#007AFF"
  186. });
  187. }
  188. });
  189. } else {
  190. }
  191. });
  192. }
  193. $scope.callsPending = 0;
  194. var i = 0;
  195. $scope.refreshData = function() {
  196. $scope.myData = [];
  197. var start = new Date();
  198. var sec = $interval(function() {
  199. $scope.callsPending++;
  200. api_bpm.list().then(function(data) {
  201. $scope.callsPending--;
  202. var myData = Restangular.stripRestangular(data);
  203. $scope.myData = myData.data;
  204. });
  205. }, 200, 10);
  206. var timeout = $timeout(function() {
  207. $interval.cancel(sec);
  208. $scope.left = '';
  209. }, 2000);
  210. $scope.$on('$destroy', function() {
  211. $timeout.cancel(timeout);
  212. $interval.cancel(sec);
  213. });
  214. };
  215. $scope.refreshData();
  216. }]);