电子档案
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

507 lines
18 KiB

  1. /* Copyright 2005-2015 Alfresco Software, Ltd.
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. 'use strict';
  16. angular.module('flowableModeler')
  17. .controller('DecisionsController', ['$rootScope', '$scope', '$translate', '$http', '$timeout', '$location', '$modal', 'modelType', function ($rootScope, $scope, $translate, $http, $timeout, $location, $modal, modelType) {
  18. $rootScope.setMainPageById('decisions');
  19. $rootScope.decisionTableItems = undefined;
  20. // get latest thumbnails
  21. $scope.imageVersion = Date.now();
  22. $scope.model = {
  23. filters: [
  24. {id: 'decisionTables', labelKey: 'DECISION-TABLES', type: 'decision-tables'},
  25. {id: 'decisionServices', labelKey: 'DECISION-SERVICES', type: 'decision-services'}
  26. ],
  27. sorts: [
  28. {id: 'modifiedDesc', labelKey: 'MODIFIED-DESC'},
  29. {id: 'modifiedAsc', labelKey: 'MODIFIED-ASC'},
  30. {id: 'nameAsc', labelKey: 'NAME-ASC'},
  31. {id: 'nameDesc', labelKey: 'NAME-DESC'}
  32. ]
  33. };
  34. if (modelType && modelType === 6) {
  35. $scope.model.activeFilter = $scope.model.filters[1];
  36. $scope.model.activeSort = $scope.model.sorts[0];
  37. $rootScope.decisionFilter = $scope.model.activeFilter;
  38. } else {
  39. $scope.model.activeFilter = $scope.model.filters[0];
  40. $scope.model.activeSort = $scope.model.sorts[0];
  41. $rootScope.decisionFilter = $scope.model.activeFilter;
  42. }
  43. $scope.activateSort = function (sort) {
  44. $scope.model.activeSort = sort;
  45. };
  46. $scope.importDecisionTable = function () {
  47. _internalCreateModal({
  48. template: 'views/popup/decision-table-import.html?version=' + Date.now()
  49. }, $modal, $scope);
  50. };
  51. $scope.importDecisionService = function () {
  52. _internalCreateModal({
  53. template: 'views/popup/decision-service-import.html?version=' + Date.now()
  54. }, $modal, $scope);
  55. };
  56. $scope.loadDecisionTables = function () {
  57. $scope.model.loading = true;
  58. var params = {
  59. filter: $scope.model.activeFilter.id,
  60. sort: $scope.model.activeSort.id,
  61. modelType: 4
  62. };
  63. if ($scope.model.filterText && $scope.model.filterText != '') {
  64. params.filterText = $scope.model.filterText;
  65. }
  66. $http({method: 'GET', url: FLOWABLE.APP_URL.getModelsUrl(), params: params}).success(function (data, status, headers, config) {
  67. $scope.model.decisions = data;
  68. $scope.model.loading = false;
  69. }).error(function (data, status, headers, config) {
  70. $scope.model.loading = false;
  71. });
  72. };
  73. $scope.loadDecisionServices = function () {
  74. $scope.model.loading = true;
  75. var params = {
  76. filter: $scope.model.activeFilter.id,
  77. sort: $scope.model.activeSort.id,
  78. modelType: 6
  79. };
  80. if ($scope.model.filterText && $scope.model.filterText != '') {
  81. params.filterText = $scope.model.filterText;
  82. }
  83. $http({method: 'GET', url: FLOWABLE.APP_URL.getModelsUrl(), params: params}).success(function (data, status, headers, config) {
  84. $scope.model.decisions = data;
  85. $scope.model.loading = false;
  86. }).error(function (data, status, headers, config) {
  87. $scope.model.loading = false;
  88. });
  89. };
  90. var timeoutFilter = function () {
  91. $scope.model.isFilterDelayed = true;
  92. $timeout(function () {
  93. $scope.model.isFilterDelayed = false;
  94. if ($scope.model.isFilterUpdated) {
  95. $scope.model.isFilterUpdated = false;
  96. timeoutFilter();
  97. } else {
  98. $scope.model.filterText = $scope.model.pendingFilterText;
  99. $rootScope.decisionFilter.filterText = $scope.model.filterText;
  100. $scope.loadDecisionTables();
  101. }
  102. }, 500);
  103. };
  104. $scope.filterDelayed = function () {
  105. if ($scope.model.isFilterDelayed) {
  106. $scope.model.isFilterUpdated = true;
  107. } else {
  108. timeoutFilter();
  109. }
  110. };
  111. $scope.createDecision = function () {
  112. if ($scope.model.activeFilter.type === "decision-services") {
  113. return $scope.createDecisionService();
  114. } else {
  115. return $scope.createDecisionTable();
  116. }
  117. }
  118. $scope.createDecisionTable = function () {
  119. $rootScope.currentKickstartModel = undefined;
  120. $rootScope.currentDecisionTableModel = undefined;
  121. $scope.createDecisionTableCallback = function (result) {
  122. $rootScope.editorHistory = [];
  123. $location.url("/decision-table-editor/" + encodeURIComponent(result.id));
  124. };
  125. _internalCreateModal({
  126. template: 'views/popup/decision-table-create.html?version=' + Date.now(),
  127. scope: $scope
  128. }, $modal, $scope);
  129. };
  130. $scope.createDecisionService = function () {
  131. $rootScope.currentKickstartModel = undefined;
  132. $rootScope.currentDRDModel = undefined;
  133. $scope.createDecisionServiceCallback = function (result) {
  134. $rootScope.editorHistory = [];
  135. $location.url("/decision-service-editor/" + encodeURIComponent(result.id));
  136. };
  137. _internalCreateModal({
  138. template: 'views/popup/decision-service-create.html?version=' + Date.now(),
  139. scope: $scope
  140. }, $modal, $scope);
  141. };
  142. $scope.showDecisionDetails = function (decision) {
  143. if (decision) {
  144. $rootScope.editorHistory = [];
  145. $rootScope.currentKickstartModel = undefined;
  146. if (decision.modelType === 4) {
  147. $location.url("/decision-tables/" + encodeURIComponent(decision.id));
  148. } else if (decision.modelType === 6) {
  149. $location.url("/decision-services/" + encodeURIComponent(decision.id));
  150. }
  151. }
  152. };
  153. $scope.editDecisionDetails = function (decision) {
  154. if (decision) {
  155. $rootScope.editorHistory = [];
  156. if (decision.modelType === 4) {
  157. $location.url("/decision-table-editor/" + encodeURIComponent(decision.id));
  158. } else if (decision.modelType === 6) {
  159. $location.url("/decision-service-editor/" + encodeURIComponent(decision.id));
  160. }
  161. }
  162. };
  163. if ($rootScope.decisionFilter &&
  164. $rootScope.decisionFilter &&
  165. $rootScope.decisionFilter.id === 'decisionServices') {
  166. $scope.loadDecisionServices();
  167. } else {
  168. $scope.loadDecisionTables();
  169. }
  170. }]);
  171. angular.module('flowableModeler')
  172. .controller('CreateNewDecisionTableCtrl', ['$rootScope', '$scope', '$http', function ($rootScope, $scope, $http) {
  173. $scope.model = {
  174. loading: false,
  175. decisionTable: {
  176. name: '',
  177. key: '',
  178. description: '',
  179. modelType: 4
  180. }
  181. };
  182. $scope.ok = function () {
  183. if (!$scope.model.decisionTable.name || $scope.model.decisionTable.name.length == 0 ||
  184. !$scope.model.decisionTable.key || $scope.model.decisionTable.key.length == 0) {
  185. return;
  186. }
  187. $scope.model.loading = true;
  188. $http({method: 'POST', url: FLOWABLE.APP_URL.getModelsUrl(), data: $scope.model.decisionTable}).success(function (data, status, headers, config) {
  189. $scope.$hide();
  190. $scope.model.loading = false;
  191. if ($scope.createDecisionTableCallback) {
  192. $scope.createDecisionTableCallback(data);
  193. $scope.createDecisionTableCallback = undefined;
  194. }
  195. }).error(function (data, status, headers, config) {
  196. $scope.model.loading = false;
  197. $scope.model.errorMessage = data.message;
  198. });
  199. };
  200. $scope.cancel = function () {
  201. if (!$scope.model.loading) {
  202. $scope.$hide();
  203. }
  204. };
  205. }]);
  206. angular.module('flowableModeler')
  207. .controller('CreateNewDecisionServiceCtrl', ['$rootScope', '$scope', '$http', function ($rootScope, $scope, $http) {
  208. $scope.model = {
  209. loading: false,
  210. decisionService: {
  211. name: '',
  212. key: '',
  213. description: '',
  214. modelType: 6
  215. }
  216. };
  217. $scope.ok = function () {
  218. if (!$scope.model.decisionService.name || $scope.model.decisionService.name.length == 0 ||
  219. !$scope.model.decisionService.key || $scope.model.decisionService.key.length == 0) {
  220. return;
  221. }
  222. $scope.model.loading = true;
  223. $http({method: 'POST', url: FLOWABLE.APP_URL.getModelsUrl(), data: $scope.model.decisionService}).success(function (data, status, headers, config) {
  224. $scope.$hide();
  225. $scope.model.loading = false;
  226. if ($scope.createDecisionServiceCallback) {
  227. $scope.createDecisionServiceCallback(data);
  228. $scope.createDecisionServiceCallback = undefined;
  229. }
  230. }).error(function (data, status, headers, config) {
  231. $scope.model.loading = false;
  232. $scope.model.errorMessage = data.message;
  233. });
  234. };
  235. $scope.cancel = function () {
  236. if (!$scope.model.loading) {
  237. $scope.$hide();
  238. }
  239. };
  240. }]);
  241. angular.module('flowableModeler')
  242. .controller('DuplicateDecisionTableCtrl', ['$rootScope', '$scope', '$http',
  243. function ($rootScope, $scope, $http) {
  244. $scope.model = {
  245. loading: false,
  246. decisionTable: {
  247. id: '',
  248. name: '',
  249. description: '',
  250. modelType: null
  251. }
  252. };
  253. if ($scope.originalModel) {
  254. //clone the model
  255. $scope.model.decisionTable.name = $scope.originalModel.decisionTable.name;
  256. $scope.model.decisionTable.key = $scope.originalModel.decisionTable.key;
  257. $scope.model.decisionTable.description = $scope.originalModel.decisionTable.description;
  258. $scope.model.decisionTable.modelType = $scope.originalModel.decisionTable.modelType;
  259. $scope.model.decisionTable.id = $scope.originalModel.decisionTable.id;
  260. }
  261. $scope.ok = function () {
  262. if (!$scope.model.decisionTable.name || $scope.model.decisionTable.name.length == 0) {
  263. return;
  264. }
  265. $scope.model.loading = true;
  266. $http({
  267. method: 'POST',
  268. url: FLOWABLE.APP_URL.getCloneModelsUrl($scope.model.decisionTable.id),
  269. data: $scope.model.decisionTable
  270. }).success(function (data, status, headers, config) {
  271. $scope.$hide();
  272. $scope.model.loading = false;
  273. if ($scope.duplicateDecisionTableCallback) {
  274. $scope.duplicateDecisionTableCallback(data);
  275. $scope.duplicateDecisionTableCallback = undefined;
  276. }
  277. }).error(function (data, status, headers, config) {
  278. $scope.model.loading = false;
  279. $scope.model.errorMessage = data.message;
  280. });
  281. };
  282. $scope.cancel = function () {
  283. if (!$scope.model.loading) {
  284. $scope.$hide();
  285. }
  286. };
  287. }]);
  288. angular.module('flowableModeler')
  289. .controller('DuplicateDecisionServiceCtrl', ['$rootScope', '$scope', '$http',
  290. function ($rootScope, $scope, $http) {
  291. $scope.model = {
  292. loading: false,
  293. decisionService: {
  294. id: '',
  295. name: '',
  296. description: '',
  297. modelType: null
  298. }
  299. };
  300. if ($scope.originalModel) {
  301. //clone the model
  302. $scope.model.decisionService.name = $scope.originalModel.decisionService.name;
  303. $scope.model.decisionService.key = $scope.originalModel.decisionService.key;
  304. $scope.model.decisionService.description = $scope.originalModel.decisionService.description;
  305. $scope.model.decisionService.modelType = $scope.originalModel.decisionService.modelType;
  306. $scope.model.decisionService.id = $scope.originalModel.decisionService.id;
  307. }
  308. $scope.ok = function () {
  309. if (!$scope.model.decisionService.name || $scope.model.decisionService.name.length == 0) {
  310. return;
  311. }
  312. $scope.model.loading = true;
  313. $http({
  314. method: 'POST',
  315. url: FLOWABLE.APP_URL.getCloneModelsUrl($scope.model.decisionService.id),
  316. data: $scope.model.decisionService
  317. }).success(function (data, status, headers, config) {
  318. $scope.$hide();
  319. $scope.model.loading = false;
  320. if ($scope.duplicateDecisionServiceCallback) {
  321. $scope.duplicateDecisionServiceCallback(data);
  322. $scope.duplicateDecisionServiceCallback = undefined;
  323. }
  324. }).error(function (data, status, headers, config) {
  325. $scope.model.loading = false;
  326. $scope.model.errorMessage = data.message;
  327. });
  328. };
  329. $scope.cancel = function () {
  330. if (!$scope.model.loading) {
  331. $scope.$hide();
  332. }
  333. };
  334. }]);
  335. angular.module('flowableModeler')
  336. .controller('ImportDecisionTableModelCtrl', ['$rootScope', '$scope', '$http', 'Upload', '$location', function ($rootScope, $scope, $http, Upload, $location) {
  337. $scope.model = {
  338. loading: false
  339. };
  340. $scope.onFileSelect = function ($files, isIE) {
  341. for (var i = 0; i < $files.length; i++) {
  342. var file = $files[i];
  343. var url;
  344. if (isIE) {
  345. url = FLOWABLE.APP_URL.getDecisionTableTextImportUrl();
  346. } else {
  347. url = FLOWABLE.APP_URL.getDecisionTableImportUrl();
  348. }
  349. Upload.upload({
  350. url: url,
  351. method: 'POST',
  352. file: file
  353. }).progress(function (evt) {
  354. $scope.model.loading = true;
  355. $scope.model.uploadProgress = parseInt(100.0 * evt.loaded / evt.total);
  356. }).success(function (data, status, headers, config) {
  357. $scope.model.loading = false;
  358. $location.path("/decision-table-editor/" + data.id);
  359. $scope.$hide();
  360. }).error(function (data, status, headers, config) {
  361. if (data && data.message) {
  362. $scope.model.errorMessage = data.message;
  363. }
  364. $scope.model.error = true;
  365. $scope.model.loading = false;
  366. });
  367. }
  368. };
  369. $scope.cancel = function () {
  370. if (!$scope.model.loading) {
  371. $scope.$hide();
  372. }
  373. };
  374. }]);
  375. angular.module('flowableModeler')
  376. .controller('ImportDecisionServiceModelCtrl', ['$rootScope', '$scope', '$http', 'Upload', '$location', function ($rootScope, $scope, $http, Upload, $location) {
  377. $scope.model = {
  378. loading: false
  379. };
  380. $scope.onFileSelect = function ($files, isIE) {
  381. for (var i = 0; i < $files.length; i++) {
  382. var file = $files[i];
  383. var url;
  384. if (isIE) {
  385. url = FLOWABLE.APP_URL.getDecisionServiceTextImportUrl();
  386. } else {
  387. url = FLOWABLE.APP_URL.getDecisionServiceImportUrl();
  388. }
  389. Upload.upload({
  390. url: url,
  391. method: 'POST',
  392. file: file
  393. }).progress(function (evt) {
  394. $scope.model.loading = true;
  395. $scope.model.uploadProgress = parseInt(100.0 * evt.loaded / evt.total);
  396. }).success(function (data, status, headers, config) {
  397. $scope.model.loading = false;
  398. $location.path("/decision-service-editor/" + data.id);
  399. $scope.$hide();
  400. }).error(function (data, status, headers, config) {
  401. if (data && data.message) {
  402. $scope.model.errorMessage = data.message;
  403. }
  404. $scope.model.error = true;
  405. $scope.model.loading = false;
  406. });
  407. }
  408. };
  409. $scope.cancel = function () {
  410. if (!$scope.model.loading) {
  411. $scope.$hide();
  412. }
  413. };
  414. }]);