originalPosition.js 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import { BlazeComponent } from 'meteor/peerlibrary:blaze-components';
  2. import { ReactiveVar } from 'meteor/reactive-var';
  3. import { Meteor } from 'meteor/meteor';
  4. import { Template } from 'meteor/templating';
  5. import './originalPosition.html';
  6. /**
  7. * Component to display original position information for swimlanes, lists, and cards
  8. */
  9. class OriginalPositionComponent extends BlazeComponent {
  10. onCreated() {
  11. super.onCreated();
  12. this.originalPosition = new ReactiveVar(null);
  13. this.isLoading = new ReactiveVar(false);
  14. this.hasMoved = new ReactiveVar(false);
  15. this.autorun(() => {
  16. const data = this.data();
  17. if (data && data.entityId && data.entityType) {
  18. this.loadOriginalPosition(data.entityId, data.entityType);
  19. }
  20. });
  21. }
  22. loadOriginalPosition(entityId, entityType) {
  23. this.isLoading.set(true);
  24. const methodName = `positionHistory.get${entityType.charAt(0).toUpperCase() + entityType.slice(1)}OriginalPosition`;
  25. Meteor.call(methodName, entityId, (error, result) => {
  26. this.isLoading.set(false);
  27. if (error) {
  28. console.error('Error loading original position:', error);
  29. this.originalPosition.set(null);
  30. } else {
  31. this.originalPosition.set(result);
  32. // Check if the entity has moved
  33. const movedMethodName = `positionHistory.has${entityType.charAt(0).toUpperCase() + entityType.slice(1)}Moved`;
  34. Meteor.call(movedMethodName, entityId, (movedError, movedResult) => {
  35. if (!movedError) {
  36. this.hasMoved.set(movedResult);
  37. }
  38. });
  39. }
  40. });
  41. }
  42. getOriginalPosition() {
  43. return this.originalPosition.get();
  44. }
  45. isLoading() {
  46. return this.isLoading.get();
  47. }
  48. hasMovedFromOriginal() {
  49. return this.hasMoved.get();
  50. }
  51. getOriginalPositionDescription() {
  52. const position = this.getOriginalPosition();
  53. if (!position) return 'No original position data';
  54. if (position.originalPosition) {
  55. const entityType = this.data().entityType;
  56. let description = `Original position: ${position.originalPosition.sort || 0}`;
  57. if (entityType === 'list' && position.originalSwimlaneId) {
  58. description += ` in swimlane ${position.originalSwimlaneId}`;
  59. } else if (entityType === 'card') {
  60. if (position.originalSwimlaneId) {
  61. description += ` in swimlane ${position.originalSwimlaneId}`;
  62. }
  63. if (position.originalListId) {
  64. description += ` in list ${position.originalListId}`;
  65. }
  66. }
  67. return description;
  68. }
  69. return 'No original position data';
  70. }
  71. getOriginalTitle() {
  72. const position = this.getOriginalPosition();
  73. return position ? position.originalTitle : '';
  74. }
  75. showOriginalPosition() {
  76. return this.getOriginalPosition() !== null;
  77. }
  78. }
  79. OriginalPositionComponent.register('originalPosition');
  80. export default OriginalPositionComponent;