懒羊羊
2023-08-30 71e81ed1d12e4d69f53c8ad9e066650ad4186293
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
/*
 * Activiti Modeler component part of the Activiti project
 * Copyright 2005-2014 Alfresco Software, Ltd. All rights reserved.
 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */
'use strict';
 
var activitiModeler = angular.module('activitiModeler', [
  'ngCookies',
  'ngResource',
  'ngSanitize',
  'ngRoute',
  'ngDragDrop',
  'mgcrea.ngStrap', 
  'ngGrid',
  'ngAnimate',
  'pascalprecht.translate',
  'duScroll'
]);
 
var activitiModule = activitiModeler;
 
activitiModeler
  // Initialize routes
  .config(['$selectProvider', '$translateProvider', function ($selectProvider, $translateProvider) {
 
      // Override caret for bs-select directive
      angular.extend($selectProvider.defaults, {
          caretHtml: '&nbsp;<i class="icon icon-caret-down"></i>'
      });
        
        // Initialize angular-translate
        $translateProvider.useStaticFilesLoader({
            prefix: './editor-app/i18n/',
            suffix: '.json'
        });
 
        $translateProvider.preferredLanguage('en');
 
        // remember language
        $translateProvider.useCookieStorage();
        
  }])
  .run(['$rootScope', '$timeout', '$modal', '$translate', '$location', '$window', '$http', '$q',
        function($rootScope, $timeout, $modal, $translate, $location, $window, $http, $q) {
      
              $rootScope.config = ACTIVITI.CONFIG;
              
              $rootScope.editorInitialized = false;
              
              $rootScope.editorFactory = $q.defer();
        
              $rootScope.forceSelectionRefresh = false;
        
              $rootScope.ignoreChanges = false; // by default never ignore changes
              
              $rootScope.validationErrors = [];
              
              $rootScope.staticIncludeVersion = Date.now();
 
              /**
               * A 'safer' apply that avoids concurrent updates (which $apply allows).
               */
              $rootScope.safeApply = function(fn) {
                  var phase = this.$root.$$phase;
                  if(phase == '$apply' || phase == '$digest') {
                      if(fn && (typeof(fn) === 'function')) {
                          fn();
                      }
                  } else {
                      this.$apply(fn);
                  }
              };
      
      
            /**
             * Initialize the event bus: couple all Oryx events with a dispatch of the
             * event of the event bus. This way, it gets much easier to attach custom logic
             * to any event.
             */
 
            /* Helper method to fetch model from server (always needed) */
            function fetchModel(modelId) {
 
                var modelUrl = KISBPM.URL.getModel(modelId);
 
                console.log(modelUrl);
 
                $http({method: 'GET', url: modelUrl}).
                    success(function (data, status, headers, config) {
                        $rootScope.editor = new ORYX.Editor(data);
                        $rootScope.modelData = angular.fromJson(data);
                        $rootScope.editorFactory.resolve();
                    }).
                    error(function (data, status, headers, config) {
                      console.log('Error loading model with id ' + modelId + ' ' + data);
                    });
            }
 
 
            function initScrollHandling() {
                var canvasSection = jQuery('#canvasSection');
                canvasSection.scroll(function() {
 
                    // Hides the resizer and quick menu items during scrolling
 
                    var selectedElements = $rootScope.editor.selection;
                    var subSelectionElements = $rootScope.editor._subSelection;
 
                    $rootScope.selectedElements = selectedElements;
                    $rootScope.subSelectionElements = subSelectionElements;
                    if (selectedElements && selectedElements.length > 0) {
                        $rootScope.selectedElementBeforeScrolling = selectedElements[0];
                    }
 
                    jQuery('.Oryx_button').each(function(i, obj) {
                        $rootScope.orginalOryxButtonStyle = obj.style.display;
                        obj.style.display = 'none';
                    });
                    
                    jQuery('.resizer_southeast').each(function(i, obj) {
                        $rootScope.orginalResizerSEStyle = obj.style.display;
                        obj.style.display = 'none';
                    });
                    jQuery('.resizer_northwest').each(function(i, obj) {
                        $rootScope.orginalResizerNWStyle = obj.style.display;
                        obj.style.display = 'none';
                    });
                    $rootScope.editor.handleEvents({type:ORYX.CONFIG.EVENT_CANVAS_SCROLL});
                });
 
                canvasSection.scrollStopped(function(){
 
                    // Puts the quick menu items and resizer back when scroll is stopped.
 
                    $rootScope.editor.setSelection([]); // needed cause it checks for element changes and does nothing if the elements are the same
                    $rootScope.editor.setSelection($rootScope.selectedElements, $rootScope.subSelectionElements);
                    $rootScope.selectedElements = undefined;
                    $rootScope.subSelectionElements = undefined;
 
                    function handleDisplayProperty(obj) {
                        if (jQuery(obj).position().top > 0) {
                            obj.style.display = 'block';
                        } else {
                            obj.style.display = 'none';
                        }
                    }
 
                    jQuery('.Oryx_button').each(function(i, obj) {
                        handleDisplayProperty(obj);
                    });
                    
                    jQuery('.resizer_southeast').each(function(i, obj) {
                        handleDisplayProperty(obj);
                    });
                    jQuery('.resizer_northwest').each(function(i, obj) {
                        handleDisplayProperty(obj);
                    });
 
                });
            }
 
            /**
             * Initialize the Oryx Editor when the content has been loaded
             */
            $rootScope.$on('$includeContentLoaded', function (event) {
                if (!$rootScope.editorInitialized) {
 
                    ORYX._loadPlugins();
    
                    var modelId = EDITOR.UTIL.getParameterByName('modelId');
                    fetchModel(modelId);
    
                    $rootScope.window = {};
                    var updateWindowSize = function() {
                        $rootScope.window.width = $window.innerWidth;
                        $rootScope.window.height  = $window.innerHeight;
                    };
    
                    // Window resize hook
                    angular.element($window).bind('resize', function() {
                        $rootScope.safeApply(updateWindowSize());
                    });
    
                    $rootScope.$watch('window.forceRefresh', function(newValue) {
                        if(newValue) {
                            $timeout(function() {
                                updateWindowSize();
                                $rootScope.window.forceRefresh = false;
                            });
                        }
                    });
    
                    updateWindowSize();
 
                    // Hook in resizing of main panels when window resizes
                    // TODO: perhaps move to a separate JS-file?
                    jQuery(window).resize(function () {
 
                        // Calculate the offset based on the bottom of the module header
                        var offset = jQuery("#editor-header").offset();
                        var propSectionHeight = jQuery('#propertySection').height();
                        var canvas = jQuery('#canvasSection');
                        var mainHeader = jQuery('#main-header');
 
                        if (offset == undefined || offset === null
                            || propSectionHeight === undefined || propSectionHeight === null
                            || canvas === undefined || canvas === null || mainHeader === null) {
                            return;
                        }
                        
                        if ($rootScope.editor)
                        {
                            var selectedElements = $rootScope.editor.selection;
                            var subSelectionElements = $rootScope.editor._subSelection;
                
                            $rootScope.selectedElements = selectedElements;
                            $rootScope.subSelectionElements = subSelectionElements;
                            if (selectedElements && selectedElements.length > 0)
                            {
                                $rootScope.selectedElementBeforeScrolling = selectedElements[0];
                                
                                $rootScope.editor.setSelection([]); // needed cause it checks for element changes and does nothing if the elements are the same
                                $rootScope.editor.setSelection($rootScope.selectedElements, $rootScope.subSelectionElements);
                                $rootScope.selectedElements = undefined;
                                $rootScope.subSelectionElements = undefined;
                            }
                        }
 
                        var totalAvailable = jQuery(window).height() - offset.top - mainHeader.height() - 21;
                        canvas.height(totalAvailable - propSectionHeight);
                        jQuery('#paletteSection').height(totalAvailable);
 
                        // Update positions of the resize-markers, according to the canvas
 
                        var actualCanvas = null;
                        if (canvas && canvas[0].children[1]) {
                            actualCanvas = canvas[0].children[1];
                        }
 
                        var canvasTop = canvas.position().top;
                        var canvasLeft = canvas.position().left;
                        var canvasHeight = canvas[0].clientHeight;
                        var canvasWidth = canvas[0].clientWidth;
                        var iconCenterOffset = 8;
                        var widthDiff = 0;
 
                        var actualWidth = 0;
                        if(actualCanvas) {
                            // In some browsers, the SVG-element clientwidth isn't available, so we revert to the parent
                            actualWidth = actualCanvas.clientWidth || actualCanvas.parentNode.clientWidth;
                        }
 
 
                        if(actualWidth < canvas[0].clientWidth) {
                            widthDiff = actualWidth - canvas[0].clientWidth;
                            // In case the canvas is smaller than the actual viewport, the resizers should be moved
                            canvasLeft -= widthDiff / 2;
                            canvasWidth += widthDiff;
                        }
 
                        var iconWidth = 17;
                        var iconOffset = 20;
 
                        var north = jQuery('#canvas-grow-N');
                        north.css('top', canvasTop + iconOffset + 'px');
                        north.css('left', canvasLeft - 10 + (canvasWidth - iconWidth) / 2 + 'px');
 
                        var south = jQuery('#canvas-grow-S');
                        south.css('top', (canvasTop + canvasHeight - iconOffset - iconCenterOffset) +  'px');
                        south.css('left', canvasLeft - 10 + (canvasWidth - iconWidth) / 2 + 'px');
 
                        var east = jQuery('#canvas-grow-E');
                        east.css('top', canvasTop - 10 + (canvasHeight - iconWidth) / 2 + 'px');
                        east.css('left', (canvasLeft + canvasWidth - iconOffset - iconCenterOffset) + 'px');
 
                        var west = jQuery('#canvas-grow-W');
                        west.css('top', canvasTop -10 + (canvasHeight - iconWidth) / 2 + 'px');
                        west.css('left', canvasLeft + iconOffset + 'px');
 
                        north = jQuery('#canvas-shrink-N');
                        north.css('top', canvasTop + iconOffset + 'px');
                        north.css('left', canvasLeft + 10 + (canvasWidth - iconWidth) / 2 + 'px');
 
                        south = jQuery('#canvas-shrink-S');
                        south.css('top', (canvasTop + canvasHeight - iconOffset - iconCenterOffset) +  'px');
                        south.css('left', canvasLeft +10 + (canvasWidth - iconWidth) / 2 + 'px');
 
                        east = jQuery('#canvas-shrink-E');
                        east.css('top', canvasTop + 10 + (canvasHeight - iconWidth) / 2 +  'px');
                        east.css('left', (canvasLeft + canvasWidth - iconOffset - iconCenterOffset) + 'px');
 
                        west = jQuery('#canvas-shrink-W');
                        west.css('top', canvasTop + 10 + (canvasHeight - iconWidth) / 2 + 'px');
                        west.css('left', canvasLeft + iconOffset + 'px');
                    });
 
                    jQuery(window).trigger('resize');
 
                    jQuery.fn.scrollStopped = function(callback) {
                        jQuery(this).scroll(function(){
                            var self = this, $this = jQuery(self);
                            if ($this.data('scrollTimeout')) {
                                clearTimeout($this.data('scrollTimeout'));
                            }
                            $this.data('scrollTimeout', setTimeout(callback,50,self));
                        });
                    };
                    
                    // Always needed, cause the DOM element on which the scroll event listeners are attached are changed for every new model
                    initScrollHandling();
                    
                    $rootScope.editorInitialized = true;
                }
            });
 
            /**
             * Initialize the event bus: couple all Oryx events with a dispatch of the
             * event of the event bus. This way, it gets much easier to attach custom logic
             * to any event.
             */
 
            $rootScope.editorFactory.promise.then(function() {
 
                KISBPM.eventBus.editor = $rootScope.editor;
 
                var eventMappings = [
                    { oryxType : ORYX.CONFIG.EVENT_SELECTION_CHANGED, kisBpmType : KISBPM.eventBus.EVENT_TYPE_SELECTION_CHANGE },
                    { oryxType : ORYX.CONFIG.EVENT_DBLCLICK, kisBpmType : KISBPM.eventBus.EVENT_TYPE_DOUBLE_CLICK },
                    { oryxType : ORYX.CONFIG.EVENT_MOUSEOUT, kisBpmType : KISBPM.eventBus.EVENT_TYPE_MOUSE_OUT },
                    { oryxType : ORYX.CONFIG.EVENT_MOUSEOVER, kisBpmType : KISBPM.eventBus.EVENT_TYPE_MOUSE_OVER }
 
                ];
 
                eventMappings.forEach(function(eventMapping) {
                    $rootScope.editor.registerOnEvent(eventMapping.oryxType, function(event) {
                        KISBPM.eventBus.dispatch(eventMapping.kisBpmType, event);
                    });
                });
                
                $rootScope.editor.registerOnEvent(ORYX.CONFIG.EVENT_SHAPEREMOVED, function (event) {
                    var validateButton = document.getElementById(event.shape.resourceId + "-validate-button");
                    if (validateButton)
                    {
                        validateButton.style.display = 'none';
                    }
                });
 
                // The Oryx canvas is ready (we know since we're in this promise callback) and the
                // event bus is ready. The editor is now ready for use
                KISBPM.eventBus.dispatch(KISBPM.eventBus.EVENT_TYPE_EDITOR_READY, {type : KISBPM.eventBus.EVENT_TYPE_EDITOR_READY});
 
            });
            
            // Alerts
            $rootScope.alerts = {
                queue: []
            };
          
            $rootScope.showAlert = function(alert) {
                if(alert.queue.length > 0) {
                    alert.current = alert.queue.shift();
                    // Start timout for message-pruning
                    alert.timeout = $timeout(function() {
                        if (alert.queue.length == 0) {
                            alert.current = undefined;
                            alert.timeout = undefined;
                        } else {
                            $rootScope.showAlert(alert);
                        }
                    }, (alert.current.type == 'error' ? 5000 : 1000));
                } else {
                    $rootScope.alerts.current = undefined;
                }
            };
          
            $rootScope.addAlert = function(message, type) {
                var newAlert = {message: message, type: type};
                if (!$rootScope.alerts.timeout) {
                    // Timeout for message queue is not running, start one
                    $rootScope.alerts.queue.push(newAlert);
                    $rootScope.showAlert($rootScope.alerts);
                } else {
                    $rootScope.alerts.queue.push(newAlert);
                }
            };
          
            $rootScope.dismissAlert = function() {
                if (!$rootScope.alerts.timeout) {
                    $rootScope.alerts.current = undefined;
                } else {
                    $timeout.cancel($rootScope.alerts.timeout);
                    $rootScope.alerts.timeout = undefined;
                    $rootScope.showAlert($rootScope.alerts);
                }
            };
          
            $rootScope.addAlertPromise = function(promise, type) {
                if (promise) {
                    promise.then(function(data) {
                        $rootScope.addAlert(data, type);
                    });
                }
            };
          
        }
  ])
 
    // Moment-JS date-formatting filter
    .filter('dateformat', function() {
        return function(date, format) {
            if (date) {
                if (format) {
                    return moment(date).format(format);
                } else {
                    return moment(date).calendar();
                }
            }
            return '';
        };
    });