电子档案
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.

170 lines
6.8 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. // Decision Table service
  17. angular.module('flowableModeler').service('DecisionTableService', [ '$rootScope', '$http', '$q', '$timeout', '$translate',
  18. function ($rootScope, $http, $q, $timeout, $translate) {
  19. var httpAsPromise = function(options) {
  20. var deferred = $q.defer();
  21. $http(options).
  22. success(function (response, status, headers, config) {
  23. deferred.resolve(response);
  24. })
  25. .error(function (response, status, headers, config) {
  26. console.log('Something went wrong during http call:' + response);
  27. deferred.reject(response);
  28. });
  29. return deferred.promise;
  30. };
  31. this.filterDecisionTables = function(filter) {
  32. return httpAsPromise(
  33. {
  34. method: 'GET',
  35. url: FLOWABLE.APP_URL.getDecisionTableModelsUrl(),
  36. params: {filter: filter}
  37. }
  38. );
  39. };
  40. /**
  41. * Fetches the details of a decision table.
  42. */
  43. this.fetchDecisionTableDetails = function(modelId, historyModelId) {
  44. var url = historyModelId ?
  45. FLOWABLE.APP_URL.getDecisionTableModelHistoryUrl(encodeURIComponent(modelId), encodeURIComponent(historyModelId)) :
  46. FLOWABLE.APP_URL.getDecisionTableModelUrl(encodeURIComponent(modelId));
  47. return httpAsPromise({ method: 'GET', url: url });
  48. };
  49. function cleanUpModel (decisionTableDefinition) {
  50. delete decisionTableDefinition.isEmbeddedTable;
  51. var expressions = (decisionTableDefinition.inputExpressions || []).concat(decisionTableDefinition.outputExpressions || []);
  52. if (decisionTableDefinition.rules && decisionTableDefinition.rules.length > 0) {
  53. decisionTableDefinition.rules.forEach(function (rule) {
  54. var headerExpressionIds = [];
  55. expressions.forEach(function(def){
  56. headerExpressionIds.push(def.id);
  57. });
  58. // Make sure that the rule has all header ids defined as attribtues
  59. headerExpressionIds.forEach(function(id){
  60. if (!rule.hasOwnProperty(id)) {
  61. rule[id] = "";
  62. }
  63. });
  64. // Make sure that the rule does not have an attribute that is not a header id
  65. delete rule.$$hashKey;
  66. for (var id in rule) {
  67. if (headerExpressionIds.indexOf(id) === -1) {
  68. delete rule[id];
  69. delete rule.validationErrorMessages;
  70. }
  71. }
  72. });
  73. }
  74. }
  75. this.saveDecisionTable = function (data, name, key, description, saveCallback, errorCallback) {
  76. data.decisionTableRepresentation = {
  77. name: name,
  78. key: key
  79. };
  80. if (description && description.length > 0) {
  81. data.decisionTableRepresentation.description = description;
  82. }
  83. var decisionTableDefinition = angular.copy($rootScope.currentDecisionTable);
  84. data.decisionTableRepresentation.decisionTableDefinition = decisionTableDefinition;
  85. decisionTableDefinition.key = key;
  86. decisionTableDefinition.rules = angular.copy($rootScope.currentDecisionTableRules);
  87. decisionTableDefinition.forceDMN11 = data.forceDMN11;
  88. html2canvas(jQuery('#decision-table-editor'), {
  89. onrendered: function (canvas) {
  90. var scale = canvas.width / 300.0;
  91. var extra_canvas = document.createElement('canvas');
  92. extra_canvas.setAttribute('width', 300);
  93. extra_canvas.setAttribute('height', canvas.height / scale);
  94. var ctx = extra_canvas.getContext('2d');
  95. ctx.drawImage(canvas, 0, 0, canvas.width, canvas.height, 0, 0, 300, canvas.height / scale);
  96. data.decisionTableImageBase64 = extra_canvas.toDataURL('image/png');
  97. $http({
  98. method: 'PUT',
  99. url: FLOWABLE.APP_URL.getDecisionTableModelUrl($rootScope.currentDecisionTable.id),
  100. data: data}).
  101. success(function (response, status, headers, config) {
  102. if (saveCallback) {
  103. saveCallback();
  104. }
  105. }).
  106. error(function (response, status, headers, config) {
  107. if (errorCallback) {
  108. errorCallback(response);
  109. }
  110. });
  111. }
  112. });
  113. };
  114. this.getDecisionTables = function (decisionTableIds, callback) {
  115. if (decisionTableIds.length > 0) {
  116. var decisionTableIdParams = '';
  117. for (var i = 0; i < decisionTableIds.length; i++) {
  118. if (decisionTableIdParams.length > 0) {
  119. decisionTableIdParams += '&';
  120. }
  121. decisionTableIdParams += 'decisionTableId=' + decisionTableIds[i];
  122. }
  123. if (decisionTableIdParams.length > 0) {
  124. decisionTableIdParams += '&';
  125. }
  126. decisionTableIdParams += 'version=' + Date.now();
  127. $http({method: 'GET', url: FLOWABLE.APP_URL.getDecisionTableModelValuesUrl(decisionTableIdParams)}).
  128. success(function (data) {
  129. if (callback) {
  130. callback(data);
  131. }
  132. }).
  133. error(function (data) {
  134. console.log('Something went wrong when fetching decision table(s):' + JSON.stringify(data));
  135. });
  136. } else {
  137. if (callback) {
  138. callback();
  139. }
  140. }
  141. };
  142. }]);