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

328 lines
10 KiB

  1. /* Licensed under the Apache License, Version 2.0 (the "License");
  2. * you may not use this file except in compliance with the License.
  3. * You may obtain a copy of the License at
  4. *
  5. * http://www.apache.org/licenses/LICENSE-2.0
  6. *
  7. * Unless required by applicable law or agreed to in writing, software
  8. * distributed under the License is distributed on an "AS IS" BASIS,
  9. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. * See the License for the specific language governing permissions and
  11. * limitations under the License.
  12. */
  13. angular.module('flowableModeler')
  14. .controller('AppDefinitionCtrl', ['$rootScope', '$scope', '$translate', '$http', '$location', '$routeParams', '$modal', '$popover', '$timeout',
  15. function ($rootScope, $scope, $translate, $http, $location, $routeParams, $modal, $popover, $timeout) {
  16. // Main page (needed for visual indicator of current page)
  17. $rootScope.setMainPageById('apps');
  18. // Initialize model
  19. $scope.model = {
  20. // Store the main model id, this points to the current version of a model,
  21. // even when we're showing history
  22. latestModelId: $routeParams.modelId,
  23. activeTab: 'bpmn'
  24. };
  25. $scope.tabs = [
  26. {
  27. id: 'bpmn',
  28. title: 'BPMN models'
  29. },
  30. {
  31. id: 'cmmn',
  32. title: 'CMMN models'
  33. }
  34. ];
  35. $scope.loadApp = function() {
  36. var url;
  37. var definitionUrl;
  38. if ($routeParams.modelHistoryId) {
  39. url = FLOWABLE.APP_URL.getModelHistoryUrl($routeParams.modelId, $routeParams.modelHistoryId);
  40. definitionUrl = FLOWABLE.APP_URL.getAppDefinitionHistoryUrl($routeParams.modelId, $routeParams.modelHistoryId);
  41. } else {
  42. url = FLOWABLE.APP_URL.getModelUrl($routeParams.modelId);
  43. definitionUrl = FLOWABLE.APP_URL.getAppDefinitionUrl($routeParams.modelId);
  44. $scope.model.appExportUrl = FLOWABLE.APP_URL.getAppDefinitionExportUrl($routeParams.modelId);
  45. $scope.model.appBarExportUrl = FLOWABLE.APP_URL.getAppDefinitionBarExportUrl($routeParams.modelId);
  46. }
  47. $http({method: 'GET', url: url}).
  48. success(function(data, status, headers, config) {
  49. $scope.model.app = data;
  50. $scope.loadVersions();
  51. }).error(function(data, status, headers, config) {
  52. $scope.returnToList();
  53. });
  54. $http({method: 'GET', url: definitionUrl}).
  55. success(function(data, status, headers, config) {
  56. $scope.model.appDefinition = data;
  57. });
  58. };
  59. $scope.useAsNewVersion = function() {
  60. _internalCreateModal({
  61. template: 'views/popup/model-use-as-new-version.html',
  62. scope: $scope
  63. }, $modal, $scope);
  64. };
  65. $scope.loadVersions = function() {
  66. var params = {
  67. includeLatestVersion: !$scope.model.app.latestVersion
  68. };
  69. $http({method: 'GET', url: FLOWABLE.APP_URL.getModelHistoriesUrl($scope.model.latestModelId), params: params}).
  70. success(function(data, status, headers, config) {
  71. if ($scope.model.app.latestVersion) {
  72. if (!data.data) {
  73. data.data = [];
  74. }
  75. data.data.unshift($scope.model.app);
  76. }
  77. $scope.model.versions = data;
  78. });
  79. };
  80. $scope.showVersion = function(version) {
  81. if (version) {
  82. if (version.latestVersion) {
  83. $location.path("/apps/" + $scope.model.latestModelId);
  84. } else {
  85. // Show latest version, no history-suffix needed in URL
  86. $location.path("/apps/" + $scope.model.latestModelId + "/history/" + version.id);
  87. }
  88. }
  89. };
  90. $scope.returnToList = function() {
  91. $location.path("/apps/");
  92. };
  93. $scope.openEditor = function() {
  94. $location.path("/app-editor/" + $scope.model.latestModelId);
  95. };
  96. $scope.editApp = function() {
  97. _internalCreateModal({
  98. template: 'views/popup/model-edit.html',
  99. scope: $scope
  100. }, $modal, $scope);
  101. };
  102. $scope.duplicateApp = function () {
  103. var modalInstance = _internalCreateModal({
  104. template: 'views/popup/app-definition-duplicate.html?version=' + Date.now()
  105. }, $modal, $scope);
  106. modalInstance.$scope.originalModel = $scope.model;
  107. };
  108. $scope.deleteApp = function() {
  109. // User is owner of the app definition and the app definition is deployed
  110. /*_internalCreateModal({
  111. template: 'views/popup/app-definition-delete.html?version=' + Date.now(),
  112. scope: $scope
  113. }, $modal, $scope);*/
  114. _internalCreateModal({
  115. template: 'views/popup/model-delete.html?version=' + Date.now(),
  116. scope: $scope
  117. }, $modal, $scope);
  118. };
  119. $scope.publish = function() {
  120. _internalCreateModal({
  121. template: 'views/popup/app-definition-publish.html?version=' + Date.now(),
  122. scope: $scope
  123. }, $modal, $scope);
  124. };
  125. $scope.shareApp = function() {
  126. _internalCreateModal({
  127. template: 'views/popup/model-share.html?version=' + Date.now(),
  128. scope: $scope
  129. }, $modal, $scope);
  130. };
  131. $scope.importAppDefinition = function () {
  132. _internalCreateModal({
  133. template: 'views/popup/app-definition-import.html?version=' + Date.now(),
  134. scope: $scope
  135. }, $modal, $scope);
  136. };
  137. $scope.toggleHistory = function($event) {
  138. if(!$scope.historyState) {
  139. var state = {};
  140. $scope.historyState = state;
  141. // Create popover
  142. state.popover = $popover(angular.element($event.target), {
  143. template: 'views/popover/history.html',
  144. placement: 'bottom-right',
  145. show: true,
  146. scope: $scope,
  147. container: 'body'
  148. });
  149. var destroy = function() {
  150. state.popover.destroy();
  151. delete $scope.historyState;
  152. };
  153. // When popup is hidden or scope is destroyed, hide popup
  154. state.popover.$scope.$on('tooltip.hide', destroy);
  155. $scope.$on('$destroy', destroy);
  156. }
  157. };
  158. $scope.loadApp();
  159. }]);
  160. angular.module('flowableModeler')
  161. .controller('PublishAppDefinitionPopupCtrl', ['$rootScope', '$scope', '$http', '$route', '$translate', function ($rootScope, $scope, $http, $route, $translate) {
  162. $scope.popup = {
  163. loading: false,
  164. comment: ''
  165. };
  166. $scope.ok = function (force) {
  167. $scope.popup.loading = true;
  168. var data = {
  169. comment: $scope.popup.comment
  170. };
  171. if (force !== undefined && force !== null && force === true) {
  172. data.force = true;
  173. }
  174. delete $scope.popup.error;
  175. $http({method: 'POST', url: FLOWABLE.APP_URL.getAppDefinitionPublishUrl($scope.model.app.id), data: data}).
  176. success(function(data, status, headers, config) {
  177. $scope.$hide();
  178. if (data.error) {
  179. $scope.popup.loading = false;
  180. $scope.addAlert(data.errorDescription, 'error');
  181. } else {
  182. $scope.popup.loading = false;
  183. $route.reload();
  184. $scope.addAlertPromise($translate('APP.ALERT.PUBLISH-CONFIRM'), 'info');
  185. }
  186. }).
  187. error(function(data, status, headers, config) {
  188. $scope.popup.loading = false;
  189. $scope.$hide();
  190. $scope.addAlertPromise($translate('APP.ALERT.PUBLISH-ERROR'), 'error');
  191. });
  192. };
  193. $scope.cancel = function () {
  194. if (!$scope.popup.loading) {
  195. $scope.$hide();
  196. }
  197. };
  198. }]);
  199. angular.module('flowableModeler')
  200. .controller('DeleteAppDefinitionPopupCtrl', ['$rootScope', '$scope', '$http', '$translate', function ($rootScope, $scope, $http, $translate) {
  201. $scope.popup = {
  202. loading: false,
  203. cascade: 'false'
  204. };
  205. $scope.ok = function () {
  206. $scope.popup.loading = true;
  207. var params = {
  208. // Explicit string-check because radio-values cannot be js-booleans
  209. cascade : $scope.popup.cascade === 'true',
  210. deleteRuntimeApp: true
  211. };
  212. $http({method: 'DELETE', url: FLOWABLE.APP_URL.getModelUrl($scope.model.app.id), params: params}).
  213. success(function(data, status, headers, config) {
  214. $scope.$hide();
  215. $scope.popup.loading = false;
  216. $scope.addAlertPromise($translate('APP.ALERT.DELETE-CONFIRM'), 'info');
  217. $scope.returnToList();
  218. }).
  219. error(function(data, status, headers, config) {
  220. $scope.$hide();
  221. $scope.popup.loading = false;
  222. });
  223. };
  224. $scope.cancel = function () {
  225. if (!$scope.popup.loading) {
  226. $scope.$hide();
  227. }
  228. };
  229. }]);
  230. angular.module('flowableModeler')
  231. .controller('ImportNewVersionAppDefinitionCtrl', ['$rootScope', '$scope', '$http', 'Upload', '$route', function ($rootScope, $scope, $http, Upload, $route) {
  232. $scope.popup = {
  233. loading: false,
  234. renewIdmIds: false
  235. };
  236. $scope.onFileSelect = function($files, isIE) {
  237. $scope.popup.loading = true;
  238. for (var i = 0; i < $files.length; i++) {
  239. var file = $files[i];
  240. var url;
  241. if (isIE) {
  242. url = FLOWABLE.APP_URL.getAppDefinitionModelTextImportUrl($scope.model.app.id, $scope.popup.renewIdmIds);
  243. } else {
  244. url = FLOWABLE.APP_URL.getAppDefinitionModelImportUrl($scope.model.app.id, $scope.popup.renewIdmIds);
  245. }
  246. Upload.upload({
  247. url: url,
  248. method: 'POST',
  249. file: file
  250. }).progress(function(evt) {
  251. $scope.popup.uploadProgress = parseInt(100.0 * evt.loaded / evt.total);
  252. }).success(function(data, status, headers, config) {
  253. $scope.popup.loading = false;
  254. $route.reload();
  255. $scope.$hide();
  256. }).error(function(data, status, headers, config) {
  257. if (data && data.message) {
  258. $scope.popup.errorMessage = data.message;
  259. }
  260. $scope.popup.error = true;
  261. $scope.popup.loading = false;
  262. });
  263. }
  264. };
  265. $scope.cancel = function () {
  266. if (!$scope.popup.loading) {
  267. $scope.$hide();
  268. }
  269. };
  270. }]);