Replay.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. REPLAY_TOKEN_IMAGE = 'user.png';
  2. /**
  3. * @description use animation to replay the process progress.
  4. * @author <a href="mailto:lingosurf168@gmail.com">Lingo Surf168</a>
  5. *
  6. * @class
  7. * @param processDefintion all nodes
  8. * @param historyActivities history nodes
  9. * @param currentActivities currnet nodes
  10. */
  11. Replay = function(processDefinition, historyActivities, currentActivities) {
  12. this.processDefinition = processDefinition;
  13. this.historyActivities = historyActivities;
  14. this.currentActivities = currentActivities;
  15. this.tokens = [];
  16. this.map = {};
  17. this.initialize();
  18. this.jobExecutor = new JobExecutor(this);
  19. };
  20. Replay.prototype = {
  21. /**
  22. * @description initialize replay.
  23. */
  24. initialize: function() {
  25. for (var i = 0; i < this.processDefinition.length; i++) {
  26. var activity = this.processDefinition[i];
  27. if (activity.type === '开始事件') {
  28. var startNode = new Node(activity, this);
  29. this.init = startNode;
  30. this.tokens.push(new Token(startNode, this));
  31. break;
  32. }
  33. }
  34. },
  35. /**
  36. * @description notify to replay by future step.
  37. * @param {Number} future future step
  38. */
  39. notify: function(future) {
  40. if (future !== 0) {
  41. var tokens = Array.prototype.slice.call(this.tokens, 0);
  42. for (var i = 0; i < tokens.length; i++) {
  43. var token = tokens[i];
  44. if (token.startMove(future) === true) {
  45. this.jobExecutor.start();
  46. }
  47. }
  48. }
  49. },
  50. /**
  51. * @description move to previous step.
  52. */
  53. prev: function() {
  54. this.notify(-1);
  55. },
  56. /**
  57. * @description move to next step.
  58. */
  59. next: function() {
  60. this.notify(1);
  61. },
  62. /**
  63. * @description replay all steps from first node.
  64. */
  65. replay: function() {
  66. this.destoryToken();
  67. this.tokens = [new Token(this.init, this)];
  68. this.notify(this.processDefinition.length);
  69. },
  70. /**
  71. * @description destroy all tokens.
  72. */
  73. destoryToken: function() {
  74. this.jobExecutor.running = false;
  75. for (var i = 0; i < this.tokens.length; i++) {
  76. var token = this.tokens[i];
  77. token.destroy();
  78. }
  79. delete this.tokens;
  80. }
  81. };