originalPositionHelpers.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /**
  2. * Helper functions for integrating original position tracking into existing Wekan templates
  3. */
  4. /**
  5. * Add original position tracking to swimlane templates
  6. */
  7. export function addOriginalPositionToSwimlane(swimlaneId) {
  8. if (!swimlaneId) return;
  9. // Track original position when swimlane is created or first accessed
  10. Meteor.call('positionHistory.trackSwimlane', swimlaneId, (error) => {
  11. if (error) {
  12. console.warn('Failed to track original position for swimlane:', error);
  13. }
  14. });
  15. }
  16. /**
  17. * Add original position tracking to list templates
  18. */
  19. export function addOriginalPositionToList(listId) {
  20. if (!listId) return;
  21. // Track original position when list is created or first accessed
  22. Meteor.call('positionHistory.trackList', listId, (error) => {
  23. if (error) {
  24. console.warn('Failed to track original position for list:', error);
  25. }
  26. });
  27. }
  28. /**
  29. * Add original position tracking to card templates
  30. */
  31. export function addOriginalPositionToCard(cardId) {
  32. if (!cardId) return;
  33. // Track original position when card is created or first accessed
  34. Meteor.call('positionHistory.trackCard', cardId, (error) => {
  35. if (error) {
  36. console.warn('Failed to track original position for card:', error);
  37. }
  38. });
  39. }
  40. /**
  41. * Get original position description for display in templates
  42. */
  43. export function getOriginalPositionDescription(entityId, entityType) {
  44. return new Promise((resolve, reject) => {
  45. const methodName = `positionHistory.get${entityType.charAt(0).toUpperCase() + entityType.slice(1)}Description`;
  46. Meteor.call(methodName, entityId, (error, result) => {
  47. if (error) {
  48. reject(error);
  49. } else {
  50. resolve(result);
  51. }
  52. });
  53. });
  54. }
  55. /**
  56. * Check if an entity has moved from its original position
  57. */
  58. export function hasEntityMoved(entityId, entityType) {
  59. return new Promise((resolve, reject) => {
  60. const methodName = `positionHistory.has${entityType.charAt(0).toUpperCase() + entityType.slice(1)}Moved`;
  61. Meteor.call(methodName, entityId, (error, result) => {
  62. if (error) {
  63. reject(error);
  64. } else {
  65. resolve(result);
  66. }
  67. });
  68. });
  69. }
  70. /**
  71. * Template helper for displaying original position info
  72. */
  73. Template.registerHelper('originalPositionInfo', function(entityId, entityType) {
  74. if (!entityId || !entityType) return null;
  75. const description = getOriginalPositionDescription(entityId, entityType);
  76. const hasMoved = hasEntityMoved(entityId, entityType);
  77. return {
  78. description: description,
  79. hasMoved: hasMoved,
  80. entityId: entityId,
  81. entityType: entityType
  82. };
  83. });
  84. /**
  85. * Template helper for checking if entity has moved
  86. */
  87. Template.registerHelper('hasEntityMoved', function(entityId, entityType) {
  88. if (!entityId || !entityType) return false;
  89. return hasEntityMoved(entityId, entityType);
  90. });
  91. /**
  92. * Template helper for getting original position description
  93. */
  94. Template.registerHelper('getOriginalPositionDescription', function(entityId, entityType) {
  95. if (!entityId || !entityType) return 'No original position data';
  96. return getOriginalPositionDescription(entityId, entityType);
  97. });