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

389 lines
13 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. 'use strict';
  14. var flowableModeler = angular.module('flowableModeler', [
  15. 'ngCookies',
  16. 'ngResource',
  17. 'ngSanitize',
  18. 'ngRoute',
  19. 'ngDragDrop',
  20. 'mgcrea.ngStrap',
  21. 'mgcrea.ngStrap.helpers.dimensions', // Needed for tooltips
  22. 'ui.grid',
  23. 'ui.grid.edit',
  24. 'ui.grid.selection',
  25. 'ui.grid.autoResize',
  26. 'ui.grid.moveColumns',
  27. 'ui.grid.cellNav',
  28. 'ngAnimate',
  29. 'pascalprecht.translate',
  30. 'ngFileUpload',
  31. 'angularSpectrumColorpicker',
  32. 'duScroll',
  33. 'dndLists',
  34. 'ngHandsontable'
  35. ]);
  36. var flowableModule = flowableModeler;
  37. var flowableApp = flowableModeler;
  38. flowableModeler
  39. // Initialize routes
  40. .config(['$provide', '$routeProvider', '$selectProvider', '$translateProvider', function ($provide, $routeProvider, $selectProvider, $translateProvider) {
  41. // Override caret for bs-select directive
  42. angular.extend($selectProvider.defaults, {
  43. caretHtml: '&nbsp;<i class="icon icon-caret-down"></i>'
  44. });
  45. $routeProvider
  46. .when('/processes', {
  47. templateUrl: 'views/processes.html',
  48. controller: 'ProcessesCtrl'
  49. })
  50. .when('/processes/:modelId', {
  51. templateUrl: 'views/process.html',
  52. controller: 'ProcessCtrl'
  53. })
  54. .when('/processes/:modelId/history/:modelHistoryId', {
  55. templateUrl: 'views/process.html',
  56. controller: 'ProcessCtrl'
  57. })
  58. .when('/casemodels', {
  59. templateUrl: 'views/casemodels.html',
  60. controller: 'CaseModelsCtrl'
  61. })
  62. .when('/casemodels/:modelId', {
  63. templateUrl: 'views/casemodel.html',
  64. controller: 'CaseModelCtrl'
  65. })
  66. .when('/forms', {
  67. templateUrl: 'views/forms.html',
  68. controller: 'FormsCtrl'
  69. })
  70. .when('/forms/:modelId', {
  71. templateUrl: 'views/form.html',
  72. controller: 'FormCtrl'
  73. })
  74. .when('/forms/:modelId/history/:modelHistoryId', {
  75. templateUrl: 'views/form.html',
  76. controller: 'FormCtrl'
  77. })
  78. .when('/decisions', {
  79. templateUrl: 'views/decisions.html',
  80. controller: 'DecisionsController',
  81. resolve: {
  82. modelType:()=>4
  83. }
  84. })
  85. .when('/decision-tables', {
  86. templateUrl: 'views/decisions.html',
  87. controller: 'DecisionsController',
  88. resolve: {
  89. modelType:()=>4
  90. }
  91. })
  92. .when('/decision-services', {
  93. templateUrl: 'views/decisions.html',
  94. controller: 'DecisionsController',
  95. resolve: {
  96. modelType:()=>6
  97. }
  98. })
  99. .when('/decision-tables/:modelId', {
  100. templateUrl: 'views/decision-table.html',
  101. controller: 'DecisionTableDetailsCtrl'
  102. })
  103. .when('/decision-tables/:modelId/history/:modelHistoryId', {
  104. templateUrl: 'views/decision-table.html',
  105. controller: 'DecisionTableDetailsCtrl'
  106. })
  107. .when('/apps', {
  108. templateUrl: 'views/app-definitions.html',
  109. controller: 'AppDefinitionsCtrl'
  110. })
  111. .when('/apps/:modelId', {
  112. templateUrl: 'views/app-definition.html',
  113. controller: 'AppDefinitionCtrl'
  114. })
  115. .when('/apps/:modelId/history/:modelHistoryId', {
  116. templateUrl: 'views/app-definition.html',
  117. controller: 'AppDefinitionCtrl'
  118. })
  119. .when('/editor/:modelId', {
  120. templateUrl: 'editor-app/editor.html',
  121. controller: 'EditorController'
  122. })
  123. .when('/form-editor/:modelId', {
  124. templateUrl: 'views/form-builder.html',
  125. controller: 'FormBuilderController'
  126. })
  127. .when('/case-editor/:modelId', {
  128. templateUrl: 'editor-app/editor.html',
  129. controller: 'EditorController'
  130. })
  131. .when('/decision-table-editor/:modelId', {
  132. templateUrl: 'views/decision-table-editor.html',
  133. controller: 'DecisionTableEditorController'
  134. })
  135. .when('/app-editor/:modelId', {
  136. templateUrl: 'views/app-definition-builder.html',
  137. controller: 'AppDefinitionBuilderController'
  138. })
  139. .when('/decision-service-editor/:modelId', {
  140. templateUrl: 'editor-app/editor.html',
  141. controller: 'EditorController'
  142. })
  143. .when('/decision-services/:modelId', {
  144. templateUrl: 'views/decision-service.html',
  145. controller: 'DecisionServiceDetailsCtrl'
  146. })
  147. .when('/decision-services/:modelId/history/:modelHistoryId', {
  148. templateUrl: 'views/decision-service.html',
  149. controller: 'DecisionServiceDetailsCtrl'
  150. });
  151. if (FLOWABLE.CONFIG.appDefaultRoute) {
  152. $routeProvider.when('/', {
  153. redirectTo: FLOWABLE.CONFIG.appDefaultRoute
  154. });
  155. } else {
  156. $routeProvider.when('/', {
  157. redirectTo: '/processes'
  158. })
  159. }
  160. // Initialize angular-translate
  161. $translateProvider.useStaticFilesLoader({
  162. prefix: './i18n/',
  163. suffix: '.json'
  164. })
  165. /*
  166. This can be used to map multiple browser language keys to a
  167. angular translate language key.
  168. */
  169. // .registerAvailableLanguageKeys(['en'], {
  170. // 'en-*': 'en'
  171. // })
  172. .useSanitizeValueStrategy('escapeParameters')
  173. .uniformLanguageTag('bcp47')
  174. .determinePreferredLanguage();
  175. }])
  176. .run(['$rootScope', '$timeout', '$modal', '$translate', '$location', '$http', '$window',
  177. function($rootScope, $timeout, $modal, $translate, $location, $http, $window) {
  178. // set angular translate fallback language
  179. $translate.fallbackLanguage(['en']);
  180. // setting Moment-JS (global) locale
  181. if (FLOWABLE.CONFIG.datesLocalization) {
  182. moment.locale($translate.proposedLanguage());
  183. }
  184. $rootScope.restRootUrl = function() {
  185. return FLOWABLE.CONFIG.contextRoot;
  186. };
  187. $rootScope.window = {};
  188. var updateWindowSize = function() {
  189. $rootScope.window.width = $window.innerWidth;
  190. $rootScope.window.height = $window.innerHeight;
  191. };
  192. // Window resize hook
  193. angular.element($window).bind('resize', function() {
  194. $rootScope.safeApply(updateWindowSize());
  195. });
  196. $rootScope.$watch('window.forceRefresh', function(newValue) {
  197. if(newValue) {
  198. $timeout(function() {
  199. updateWindowSize();
  200. $rootScope.window.forceRefresh = false;
  201. });
  202. }
  203. });
  204. updateWindowSize();
  205. // Main navigation
  206. $rootScope.mainNavigation = [
  207. {
  208. 'id': 'processes',
  209. 'title': 'GENERAL.NAVIGATION.PROCESSES',
  210. 'path': '/processes'
  211. },
  212. {
  213. 'id': 'casemodels',
  214. 'title': 'GENERAL.NAVIGATION.CASEMODELS',
  215. 'path': '/casemodels'
  216. },
  217. {
  218. 'id': 'forms',
  219. 'title': 'GENERAL.NAVIGATION.FORMS',
  220. 'path': '/forms'
  221. },
  222. {
  223. 'id': 'decisions',
  224. 'title': 'GENERAL.NAVIGATION.DECISIONS',
  225. 'path': '/decisions'
  226. },
  227. {
  228. 'id': 'apps',
  229. 'title': 'GENERAL.NAVIGATION.APPS',
  230. 'path': '/apps'
  231. }
  232. ];
  233. $rootScope.config = FLOWABLE.CONFIG;
  234. $rootScope.mainPage = $rootScope.mainNavigation[0];
  235. // Add url helpers to root scope:
  236. $rootScope.getModelThumbnailUrl = FLOWABLE.APP_URL.getModelThumbnailUrl;
  237. $rootScope.getImageUrl = FLOWABLE.APP_URL.getImageUrl;
  238. /*
  239. * History of process and form pages accessed by the editor.
  240. * This is needed because you can navigate to sub processes and forms
  241. */
  242. $rootScope.editorHistory = [];
  243. /*
  244. * Set the current main page, using the page object. If the page is already active,
  245. * this is a no-op.
  246. */
  247. $rootScope.setMainPage = function(mainPage) {
  248. $rootScope.mainPage = mainPage;
  249. $location.path($rootScope.mainPage.path);
  250. };
  251. /*
  252. * Set the current main page, using the page ID. If the page is already active,
  253. * this is a no-op.
  254. */
  255. $rootScope.setMainPageById = function(mainPageId) {
  256. for (var i=0; i<$rootScope.mainNavigation.length; i++) {
  257. if (mainPageId == $rootScope.mainNavigation[i].id) {
  258. $rootScope.mainPage = $rootScope.mainNavigation[i];
  259. break;
  260. }
  261. }
  262. };
  263. /**
  264. * A 'safer' apply that avoids concurrent updates (which $apply allows).
  265. */
  266. $rootScope.safeApply = function(fn) {
  267. var phase = this.$root.$$phase;
  268. if(phase == '$apply' || phase == '$digest') {
  269. if(fn && (typeof(fn) === 'function')) {
  270. fn();
  271. }
  272. } else {
  273. this.$apply(fn);
  274. }
  275. };
  276. // Alerts
  277. $rootScope.alerts = {
  278. queue: []
  279. };
  280. $rootScope.showAlert = function(alert) {
  281. if(alert.queue.length > 0) {
  282. alert.current = alert.queue.shift();
  283. // Start timout for message-pruning
  284. alert.timeout = $timeout(function() {
  285. if (alert.queue.length == 0) {
  286. alert.current = undefined;
  287. alert.timeout = undefined;
  288. } else {
  289. $rootScope.showAlert(alert);
  290. }
  291. }, (alert.current.type == 'error' ? 5000 : 1000));
  292. } else {
  293. $rootScope.alerts.current = undefined;
  294. }
  295. };
  296. $rootScope.addAlert = function(message, type) {
  297. var newAlert = {message: message, type: type};
  298. if (!$rootScope.alerts.timeout) {
  299. // Timeout for message queue is not running, start one
  300. $rootScope.alerts.queue.push(newAlert);
  301. $rootScope.showAlert($rootScope.alerts);
  302. } else {
  303. $rootScope.alerts.queue.push(newAlert);
  304. }
  305. };
  306. $rootScope.dismissAlert = function() {
  307. if (!$rootScope.alerts.timeout) {
  308. $rootScope.alerts.current = undefined;
  309. } else {
  310. $timeout.cancel($rootScope.alerts.timeout);
  311. $rootScope.alerts.timeout = undefined;
  312. $rootScope.showAlert($rootScope.alerts);
  313. }
  314. };
  315. $rootScope.addAlertPromise = function(promise, type) {
  316. if (promise) {
  317. promise.then(function(data) {
  318. $rootScope.addAlert(data, type);
  319. });
  320. }
  321. };
  322. $http.get(FLOWABLE.APP_URL.getAccountUrl())
  323. .success(function (data, status, headers, config) {
  324. $rootScope.account = data;
  325. $rootScope.invalidCredentials = false;
  326. $rootScope.authenticated = true;
  327. });
  328. $rootScope.logout = function () {
  329. $rootScope.authenticated = false;
  330. $rootScope.authenticationError = false;
  331. // Changing the href causes a reload, so no need to do a new reload again
  332. $window.location.href = FLOWABLE.CONFIG.contextRoot + '/app/logout';
  333. };
  334. }
  335. ])
  336. .run(['$rootScope', '$location', '$translate', '$window', '$modal',
  337. function($rootScope, $location, $translate, $window , $modal) {
  338. var fixedUrlPart = '/editor/';
  339. $rootScope.backToLanding = function() {
  340. $window.location.href = FLOWABLE.CONFIG.contextRoot;
  341. };
  342. }])
  343. // Moment-JS date-formatting filter
  344. .filter('dateformat', function() {
  345. return function(date, format) {
  346. if (date) {
  347. if (format) {
  348. return moment(date).format(format);
  349. } else {
  350. return moment(date).calendar();
  351. }
  352. }
  353. return '';
  354. };
  355. });