swimlanes.js 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114
  1. import { ReactiveCache } from '/imports/reactiveCache';
  2. import dragscroll from '@wekanteam/dragscroll';
  3. const { calculateIndex } = Utils;
  4. function currentListIsInThisSwimlane(swimlaneId) {
  5. const currentList = Utils.getCurrentList();
  6. return (
  7. currentList &&
  8. (currentList.swimlaneId === swimlaneId || currentList.swimlaneId === '')
  9. );
  10. }
  11. function currentCardIsInThisList(listId, swimlaneId) {
  12. const currentCard = Utils.getCurrentCard();
  13. //const currentUser = ReactiveCache.getCurrentUser();
  14. if (
  15. //currentUser &&
  16. //currentUser.profile &&
  17. Utils.boardView() === 'board-view-swimlanes'
  18. )
  19. return (
  20. currentCard &&
  21. currentCard.listId === listId &&
  22. currentCard.swimlaneId === swimlaneId
  23. );
  24. else if (
  25. //currentUser &&
  26. //currentUser.profile &&
  27. Utils.boardView() === 'board-view-lists'
  28. )
  29. return (
  30. currentCard &&
  31. currentCard.listId === listId
  32. );
  33. // https://github.com/wekan/wekan/issues/1623
  34. // https://github.com/ChronikEwok/wekan/commit/cad9b20451bb6149bfb527a99b5001873b06c3de
  35. // TODO: In public board, if you would like to switch between List/Swimlane view, you could
  36. // 1) If there is no view cookie, save to cookie board-view-lists
  37. // board-view-lists / board-view-swimlanes / board-view-cal
  38. // 2) If public user changes clicks board-view-lists then change view and
  39. // then change view and save cookie with view value
  40. // without using currentuser above, because currentuser is null.
  41. }
  42. function initSortable(boardComponent, $listsDom) {
  43. // Safety check: ensure we have valid DOM elements
  44. if (!$listsDom || $listsDom.length === 0) {
  45. console.error('initSortable: No valid DOM elements provided');
  46. return;
  47. }
  48. // Check if sortable is already initialized
  49. if ($listsDom.data('uiSortable') || $listsDom.data('sortable')) {
  50. $listsDom.sortable('destroy');
  51. }
  52. // We want to animate the card details window closing. We rely on CSS
  53. // transition for the actual animation.
  54. $listsDom._uihooks = {
  55. removeElement(node) {
  56. const removeNode = _.once(() => {
  57. node.parentNode.removeChild(node);
  58. });
  59. if ($(node).hasClass('js-card-details')) {
  60. $(node).css({
  61. flexBasis: 0,
  62. padding: 0,
  63. });
  64. $listsDom.one(CSSEvents.transitionend, removeNode);
  65. } else {
  66. removeNode();
  67. }
  68. },
  69. };
  70. // Add click debugging for drag handles
  71. $listsDom.on('mousedown', '.js-list-handle', function(e) {
  72. e.stopPropagation();
  73. });
  74. $listsDom.on('mousedown', '.js-list-header', function(e) {
  75. });
  76. // Add debugging for any mousedown on lists
  77. $listsDom.on('mousedown', '.js-list', function(e) {
  78. });
  79. // Add debugging for sortable events
  80. $listsDom.on('sortstart', function(e, ui) {
  81. });
  82. $listsDom.on('sortbeforestop', function(e, ui) {
  83. });
  84. $listsDom.on('sortstop', function(e, ui) {
  85. });
  86. try {
  87. $listsDom.sortable({
  88. connectWith: '.js-swimlane, .js-lists',
  89. tolerance: 'pointer',
  90. appendTo: '.board-canvas',
  91. helper(evt, item) {
  92. const helper = item.clone();
  93. helper.css('z-index', 1000);
  94. return helper;
  95. },
  96. items: '.js-list:not(.js-list-composer)',
  97. placeholder: 'list placeholder',
  98. distance: 3,
  99. forcePlaceholderSize: true,
  100. cursor: 'move',
  101. start(evt, ui) {
  102. ui.helper.css('z-index', 1000);
  103. ui.placeholder.height(ui.helper.height());
  104. ui.placeholder.width(ui.helper.width());
  105. EscapeActions.executeUpTo('popup-close');
  106. boardComponent.setIsDragging(true);
  107. // Add visual feedback for list being dragged
  108. ui.item.addClass('ui-sortable-helper');
  109. // Disable dragscroll during list dragging to prevent interference
  110. try {
  111. dragscroll.reset();
  112. } catch (e) {
  113. }
  114. // Also disable dragscroll on all swimlanes during list dragging
  115. $('.js-swimlane').each(function() {
  116. $(this).removeClass('dragscroll');
  117. });
  118. },
  119. beforeStop(evt, ui) {
  120. // Clean up visual feedback
  121. ui.item.removeClass('ui-sortable-helper');
  122. },
  123. stop(evt, ui) {
  124. // To attribute the new index number, we need to get the DOM element
  125. // of the previous and the following card -- if any.
  126. const prevListDom = ui.item.prev('.js-list').get(0);
  127. const nextListDom = ui.item.next('.js-list').get(0);
  128. const sortIndex = calculateIndex(prevListDom, nextListDom, 1);
  129. const listDomElement = ui.item.get(0);
  130. if (!listDomElement) {
  131. console.error('List DOM element not found during drag stop');
  132. return;
  133. }
  134. let list;
  135. try {
  136. list = Blaze.getData(listDomElement);
  137. } catch (error) {
  138. console.error('Error getting list data:', error);
  139. return;
  140. }
  141. if (!list) {
  142. console.error('List data not found for element:', listDomElement);
  143. return;
  144. }
  145. // Detect if the list was dropped in a different swimlane
  146. const targetSwimlaneDom = ui.item.closest('.js-swimlane');
  147. let targetSwimlaneId = null;
  148. if (targetSwimlaneDom.length > 0) {
  149. // List was dropped in a swimlane
  150. try {
  151. targetSwimlaneId = targetSwimlaneDom.attr('id').replace('swimlane-', '');
  152. } catch (error) {
  153. console.error('Error getting target swimlane ID:', error);
  154. return;
  155. }
  156. } else {
  157. // List was dropped in lists view (not swimlanes view)
  158. // In this case, assign to the default swimlane
  159. const currentBoard = ReactiveCache.getBoard(Session.get('currentBoard'));
  160. if (currentBoard) {
  161. const defaultSwimlane = currentBoard.getDefaultSwimline();
  162. if (defaultSwimlane) {
  163. targetSwimlaneId = defaultSwimlane._id;
  164. }
  165. }
  166. }
  167. // Get the original swimlane ID of the list (handle backward compatibility)
  168. const originalSwimlaneId = list.getEffectiveSwimlaneId ? list.getEffectiveSwimlaneId() : (list.swimlaneId || null);
  169. /*
  170. Reverted incomplete change list width,
  171. removed from below Lists.update:
  172. https://github.com/wekan/wekan/issues/4558
  173. $set: {
  174. width: list._id.width(),
  175. height: list._id.height(),
  176. */
  177. // Prepare update object
  178. const updateData = {
  179. sort: sortIndex.base,
  180. };
  181. // Check if the list was dropped in a different swimlane
  182. const isDifferentSwimlane = targetSwimlaneId && targetSwimlaneId !== originalSwimlaneId;
  183. // If the list was dropped in a different swimlane, update the swimlaneId
  184. if (isDifferentSwimlane) {
  185. updateData.swimlaneId = targetSwimlaneId;
  186. // Move all cards in the list to the new swimlane
  187. const cardsInList = ReactiveCache.getCards({
  188. listId: list._id,
  189. archived: false
  190. });
  191. cardsInList.forEach(card => {
  192. card.move(list.boardId, targetSwimlaneId, list._id);
  193. });
  194. // Don't cancel the sortable when moving to a different swimlane
  195. // The DOM move should be allowed to complete
  196. }
  197. // Allow reordering within the same swimlane by not canceling the sortable
  198. try {
  199. Lists.update(list._id, {
  200. $set: updateData,
  201. });
  202. } catch (error) {
  203. console.error('Error updating list:', error);
  204. return;
  205. }
  206. boardComponent.setIsDragging(false);
  207. // Re-enable dragscroll after list dragging is complete
  208. try {
  209. dragscroll.reset();
  210. } catch (e) {
  211. }
  212. // Re-enable dragscroll on all swimlanes
  213. $('.js-swimlane').each(function() {
  214. $(this).addClass('dragscroll');
  215. });
  216. },
  217. });
  218. } catch (error) {
  219. console.error('Error initializing list sortable:', error);
  220. return;
  221. }
  222. // Check if drag handles exist
  223. const dragHandles = $listsDom.find('.js-list-handle');
  224. // Check if lists exist
  225. const lists = $listsDom.find('.js-list');
  226. // Skip the complex autorun and options for now
  227. }
  228. BlazeComponent.extendComponent({
  229. onRendered() {
  230. const boardComponent = this.parentComponent();
  231. const $listsDom = this.$('.js-lists');
  232. if (!Utils.getCurrentCardId()) {
  233. boardComponent.scrollLeft();
  234. }
  235. // Try a simpler approach - initialize sortable directly like cards do
  236. // Wait for DOM to be ready
  237. setTimeout(() => {
  238. const $lists = this.$('.js-list');
  239. const $parent = $lists.parent();
  240. if ($lists.length > 0) {
  241. // Check for drag handles
  242. const $handles = $parent.find('.js-list-handle');
  243. // Test if drag handles are clickable
  244. $handles.on('click', function(e) {
  245. e.preventDefault();
  246. e.stopPropagation();
  247. });
  248. $parent.sortable({
  249. connectWith: '.js-swimlane, .js-lists',
  250. tolerance: 'pointer',
  251. appendTo: '.board-canvas',
  252. helper: 'clone',
  253. items: '.js-list:not(.js-list-composer)',
  254. placeholder: 'list placeholder',
  255. distance: 7,
  256. handle: '.js-list-handle',
  257. disabled: !Utils.canModifyBoard(),
  258. start(evt, ui) {
  259. ui.helper.css('z-index', 1000);
  260. ui.placeholder.height(ui.helper.height());
  261. ui.placeholder.width(ui.helper.width());
  262. EscapeActions.executeUpTo('popup-close');
  263. boardComponent.setIsDragging(true);
  264. },
  265. stop(evt, ui) {
  266. boardComponent.setIsDragging(false);
  267. }
  268. });
  269. } else {
  270. }
  271. }, 100);
  272. },
  273. onCreated() {
  274. this.draggingActive = new ReactiveVar(false);
  275. this._isDragging = false;
  276. this._lastDragPositionX = 0;
  277. },
  278. id() {
  279. return this._id;
  280. },
  281. currentCardIsInThisList(listId, swimlaneId) {
  282. return currentCardIsInThisList(listId, swimlaneId);
  283. },
  284. currentListIsInThisSwimlane(swimlaneId) {
  285. return currentListIsInThisSwimlane(swimlaneId);
  286. },
  287. visible(list) {
  288. if (list.archived) {
  289. // Show archived list only when filter archive is on
  290. if (!Filter.archive.isSelected()) {
  291. return false;
  292. }
  293. }
  294. if (Filter.lists._isActive()) {
  295. if (!list.title.match(Filter.lists.getRegexSelector())) {
  296. return false;
  297. }
  298. }
  299. if (Filter.hideEmpty.isSelected()) {
  300. // Check for cards in all swimlanes, not just the current one
  301. // This ensures lists with cards in other swimlanes are still visible
  302. const cards = list.cards();
  303. if (cards.length === 0) {
  304. return false;
  305. }
  306. }
  307. return true;
  308. },
  309. events() {
  310. return [
  311. {
  312. // Click-and-drag action
  313. 'mousedown .board-canvas'(evt) {
  314. // Translating the board canvas using the click-and-drag action can
  315. // conflict with the build-in browser mechanism to select text. We
  316. // define a list of elements in which we disable the dragging because
  317. // the user will legitimately expect to be able to select some text with
  318. // his mouse.
  319. const noDragInside = ['a', 'input', 'textarea', 'p'].concat(
  320. Utils.isTouchScreenOrShowDesktopDragHandles()
  321. ? ['.js-list-handle', '.js-swimlane-header-handle']
  322. : ['.js-list-header'],
  323. ).concat([
  324. '.js-list-resize-handle',
  325. '.js-swimlane-resize-handle'
  326. ]);
  327. const isResizeHandle = $(evt.target).closest('.js-list-resize-handle, .js-swimlane-resize-handle').length > 0;
  328. const isInNoDragArea = $(evt.target).closest(noDragInside.join(',')).length > 0;
  329. if (isResizeHandle) {
  330. return;
  331. }
  332. if (
  333. !isInNoDragArea &&
  334. this.$('.swimlane').prop('clientHeight') > evt.offsetY
  335. ) {
  336. this._isDragging = true;
  337. this._lastDragPositionX = evt.clientX;
  338. }
  339. },
  340. mouseup() {
  341. if (this._isDragging) {
  342. this._isDragging = false;
  343. }
  344. },
  345. mousemove(evt) {
  346. if (this._isDragging) {
  347. // Update the canvas position
  348. this.listsDom.scrollLeft -= evt.clientX - this._lastDragPositionX;
  349. this._lastDragPositionX = evt.clientX;
  350. // Disable browser text selection while dragging
  351. evt.stopPropagation();
  352. evt.preventDefault();
  353. // Don't close opened card or inlined form at the end of the
  354. // click-and-drag.
  355. EscapeActions.executeUpTo('popup-close');
  356. EscapeActions.preventNextClick();
  357. }
  358. },
  359. },
  360. ];
  361. },
  362. swimlaneHeight() {
  363. const user = ReactiveCache.getCurrentUser();
  364. const swimlane = Template.currentData();
  365. let height;
  366. if (user) {
  367. // For logged-in users, get from user profile
  368. height = user.getSwimlaneHeightFromStorage(swimlane.boardId, swimlane._id);
  369. } else {
  370. // For non-logged-in users, get from localStorage
  371. try {
  372. const stored = localStorage.getItem('wekan-swimlane-heights');
  373. if (stored) {
  374. const heights = JSON.parse(stored);
  375. if (heights[swimlane.boardId] && heights[swimlane.boardId][swimlane._id]) {
  376. height = heights[swimlane.boardId][swimlane._id];
  377. } else {
  378. height = -1;
  379. }
  380. } else {
  381. height = -1;
  382. }
  383. } catch (e) {
  384. console.warn('Error reading swimlane height from localStorage:', e);
  385. height = -1;
  386. }
  387. }
  388. return height == -1 ? "auto" : (height + 5 + "px");
  389. },
  390. onRendered() {
  391. // Initialize swimlane resize functionality immediately
  392. this.initializeSwimlaneResize();
  393. },
  394. initializeSwimlaneResize() {
  395. // Check if we're still in a valid template context
  396. if (!Template.currentData()) {
  397. console.warn('No current template data available for swimlane resize initialization');
  398. return;
  399. }
  400. const swimlane = Template.currentData();
  401. const $swimlane = $(`#swimlane-${swimlane._id}`);
  402. const $resizeHandle = $swimlane.find('.js-swimlane-resize-handle');
  403. // Check if elements exist
  404. if (!$swimlane.length || !$resizeHandle.length) {
  405. console.warn('Swimlane or resize handle not found, retrying in 100ms');
  406. Meteor.setTimeout(() => {
  407. if (!this.isDestroyed) {
  408. this.initializeSwimlaneResize();
  409. }
  410. }, 100);
  411. return;
  412. }
  413. if ($resizeHandle.length === 0) {
  414. return;
  415. }
  416. let isResizing = false;
  417. let startY = 0;
  418. let startHeight = 0;
  419. const minHeight = 100;
  420. const maxHeight = 2000;
  421. const startResize = (e) => {
  422. isResizing = true;
  423. startY = e.pageY || e.originalEvent.touches[0].pageY;
  424. startHeight = parseInt($swimlane.css('height')) || 300;
  425. $swimlane.addClass('swimlane-resizing');
  426. $('body').addClass('swimlane-resizing-active');
  427. $('body').css('user-select', 'none');
  428. e.preventDefault();
  429. e.stopPropagation();
  430. };
  431. const doResize = (e) => {
  432. if (!isResizing) {
  433. return;
  434. }
  435. const currentY = e.pageY || e.originalEvent.touches[0].pageY;
  436. const deltaY = currentY - startY;
  437. const newHeight = Math.max(minHeight, Math.min(maxHeight, startHeight + deltaY));
  438. // Apply the new height immediately for real-time feedback
  439. $swimlane[0].style.setProperty('--swimlane-height', `${newHeight}px`);
  440. $swimlane[0].style.setProperty('height', `${newHeight}px`);
  441. $swimlane[0].style.setProperty('min-height', `${newHeight}px`);
  442. $swimlane[0].style.setProperty('max-height', `${newHeight}px`);
  443. $swimlane[0].style.setProperty('flex', 'none');
  444. $swimlane[0].style.setProperty('flex-basis', 'auto');
  445. $swimlane[0].style.setProperty('flex-grow', '0');
  446. $swimlane[0].style.setProperty('flex-shrink', '0');
  447. e.preventDefault();
  448. e.stopPropagation();
  449. };
  450. const stopResize = (e) => {
  451. if (!isResizing) return;
  452. isResizing = false;
  453. // Calculate final height
  454. const currentY = e.pageY || e.originalEvent.touches[0].pageY;
  455. const deltaY = currentY - startY;
  456. const finalHeight = Math.max(minHeight, Math.min(maxHeight, startHeight + deltaY));
  457. // Ensure the final height is applied
  458. $swimlane[0].style.setProperty('--swimlane-height', `${finalHeight}px`);
  459. $swimlane[0].style.setProperty('height', `${finalHeight}px`);
  460. $swimlane[0].style.setProperty('min-height', `${finalHeight}px`);
  461. $swimlane[0].style.setProperty('max-height', `${finalHeight}px`);
  462. $swimlane[0].style.setProperty('flex', 'none');
  463. $swimlane[0].style.setProperty('flex-basis', 'auto');
  464. $swimlane[0].style.setProperty('flex-grow', '0');
  465. $swimlane[0].style.setProperty('flex-shrink', '0');
  466. // Remove visual feedback but keep the height
  467. $swimlane.removeClass('swimlane-resizing');
  468. $('body').removeClass('swimlane-resizing-active');
  469. $('body').css('user-select', '');
  470. // Save the new height using the existing system
  471. const boardId = swimlane.boardId;
  472. const swimlaneId = swimlane._id;
  473. if (process.env.DEBUG === 'true') {
  474. }
  475. const currentUser = ReactiveCache.getCurrentUser();
  476. if (currentUser) {
  477. // For logged-in users, use server method
  478. Meteor.call('applySwimlaneHeightToStorage', boardId, swimlaneId, finalHeight, (error, result) => {
  479. if (error) {
  480. console.error('Error saving swimlane height:', error);
  481. } else {
  482. if (process.env.DEBUG === 'true') {
  483. }
  484. }
  485. });
  486. } else {
  487. // For non-logged-in users, save to localStorage directly
  488. try {
  489. const stored = localStorage.getItem('wekan-swimlane-heights');
  490. let heights = stored ? JSON.parse(stored) : {};
  491. if (!heights[boardId]) {
  492. heights[boardId] = {};
  493. }
  494. heights[boardId][swimlaneId] = finalHeight;
  495. localStorage.setItem('wekan-swimlane-heights', JSON.stringify(heights));
  496. if (process.env.DEBUG === 'true') {
  497. }
  498. } catch (e) {
  499. console.warn('Error saving swimlane height to localStorage:', e);
  500. }
  501. }
  502. e.preventDefault();
  503. };
  504. // Mouse events
  505. $resizeHandle.on('mousedown', startResize);
  506. $(document).on('mousemove', doResize);
  507. $(document).on('mouseup', stopResize);
  508. // Touch events for mobile
  509. $resizeHandle.on('touchstart', startResize, { passive: false });
  510. $(document).on('touchmove', doResize, { passive: false });
  511. $(document).on('touchend', stopResize, { passive: false });
  512. // Prevent dragscroll interference
  513. $resizeHandle.on('mousedown', (e) => {
  514. e.stopPropagation();
  515. });
  516. },
  517. }).register('swimlane');
  518. BlazeComponent.extendComponent({
  519. onCreated() {
  520. this.currentBoard = Utils.getCurrentBoard();
  521. this.isListTemplatesSwimlane =
  522. this.currentBoard.isTemplatesBoard() &&
  523. this.currentData().isListTemplatesSwimlane();
  524. this.currentSwimlane = this.currentData();
  525. },
  526. // Proxy
  527. open() {
  528. this.childComponents('inlinedForm')[0].open();
  529. },
  530. events() {
  531. return [
  532. {
  533. submit(evt) {
  534. evt.preventDefault();
  535. const titleInput = this.find('.list-name-input');
  536. const title = titleInput?.value.trim();
  537. if (!title) return;
  538. let sortIndex = 0;
  539. const lastList = this.currentBoard.getLastList();
  540. const boardId = Utils.getCurrentBoardId();
  541. const positionInput = this.find('.list-position-input');
  542. if (positionInput) {
  543. const positionId = positionInput.value.trim();
  544. const selectedList = ReactiveCache.getList({ boardId, _id: positionId, archived: false });
  545. if (selectedList) {
  546. sortIndex = selectedList.sort + 1;
  547. } else {
  548. sortIndex = Utils.calculateIndexData(lastList, null).base;
  549. }
  550. } else {
  551. sortIndex = Utils.calculateIndexData(lastList, null).base;
  552. }
  553. Lists.insert({
  554. title,
  555. boardId: Session.get('currentBoard'),
  556. sort: sortIndex,
  557. type: this.isListTemplatesSwimlane ? 'template-list' : 'list',
  558. swimlaneId: this.currentSwimlane._id, // Always set swimlaneId for per-swimlane list titles
  559. });
  560. titleInput.value = '';
  561. titleInput.focus();
  562. }
  563. },
  564. {
  565. 'click .js-list-template': Popup.open('searchElement'),
  566. },
  567. ];
  568. },
  569. }).register('addListForm');
  570. Template.swimlane.helpers({
  571. canSeeAddList() {
  572. return ReactiveCache.getCurrentUser().isBoardAdmin();
  573. },
  574. lists() {
  575. // Return per-swimlane lists for this swimlane
  576. return this.myLists();
  577. }
  578. });
  579. // Initialize sortable on DOM elements
  580. setTimeout(() => {
  581. const $swimlaneElements = $('.swimlane');
  582. const $listsGroupElements = $('.list-group');
  583. // Initialize sortable on ALL swimlane elements (even empty ones)
  584. $swimlaneElements.each(function(index) {
  585. const $swimlane = $(this);
  586. const $lists = $swimlane.find('.js-list');
  587. // Only initialize on swimlanes that have the .js-lists class (the container for lists)
  588. if ($swimlane.hasClass('js-lists')) {
  589. $swimlane.sortable({
  590. connectWith: '.js-swimlane, .js-lists',
  591. tolerance: 'pointer',
  592. appendTo: '.board-canvas',
  593. helper: 'clone',
  594. items: '.js-list:not(.js-list-composer)',
  595. placeholder: 'list placeholder',
  596. distance: 7,
  597. handle: '.js-list-handle',
  598. disabled: !Utils.canModifyBoard(),
  599. start(evt, ui) {
  600. ui.helper.css('z-index', 1000);
  601. ui.placeholder.height(ui.helper.height());
  602. ui.placeholder.width(ui.helper.width());
  603. EscapeActions.executeUpTo('popup-close');
  604. // Try to get board component
  605. try {
  606. const boardComponent = BlazeComponent.getComponentForElement(ui.item[0]);
  607. if (boardComponent && boardComponent.setIsDragging) {
  608. boardComponent.setIsDragging(true);
  609. }
  610. } catch (e) {
  611. // Silent fail
  612. }
  613. },
  614. stop(evt, ui) {
  615. // To attribute the new index number, we need to get the DOM element
  616. // of the previous and the following list -- if any.
  617. const prevListDom = ui.item.prev('.js-list').get(0);
  618. const nextListDom = ui.item.next('.js-list').get(0);
  619. const sortIndex = calculateIndex(prevListDom, nextListDom, 1);
  620. const listDomElement = ui.item.get(0);
  621. if (!listDomElement) {
  622. return;
  623. }
  624. let list;
  625. try {
  626. list = Blaze.getData(listDomElement);
  627. } catch (error) {
  628. return;
  629. }
  630. if (!list) {
  631. return;
  632. }
  633. // Detect if the list was dropped in a different swimlane
  634. const targetSwimlaneDom = ui.item.closest('.js-swimlane');
  635. let targetSwimlaneId = null;
  636. if (targetSwimlaneDom.length > 0) {
  637. // List was dropped in a swimlane
  638. try {
  639. targetSwimlaneId = targetSwimlaneDom.attr('id').replace('swimlane-', '');
  640. } catch (error) {
  641. return;
  642. }
  643. } else {
  644. // List was dropped in lists view (not swimlanes view)
  645. // In this case, assign to the default swimlane
  646. const currentBoard = ReactiveCache.getBoard(Session.get('currentBoard'));
  647. if (currentBoard) {
  648. const defaultSwimlane = currentBoard.getDefaultSwimline();
  649. if (defaultSwimlane) {
  650. targetSwimlaneId = defaultSwimlane._id;
  651. }
  652. }
  653. }
  654. // Get the original swimlane ID of the list (handle backward compatibility)
  655. const originalSwimlaneId = list.getEffectiveSwimlaneId ? list.getEffectiveSwimlaneId() : (list.swimlaneId || null);
  656. // Prepare update object
  657. const updateData = {
  658. sort: sortIndex.base,
  659. };
  660. // Check if the list was dropped in a different swimlane
  661. const isDifferentSwimlane = targetSwimlaneId && targetSwimlaneId !== originalSwimlaneId;
  662. // If the list was dropped in a different swimlane, update the swimlaneId
  663. if (isDifferentSwimlane) {
  664. updateData.swimlaneId = targetSwimlaneId;
  665. // Move all cards in the list to the new swimlane
  666. const cardsInList = ReactiveCache.getCards({
  667. listId: list._id,
  668. archived: false
  669. });
  670. cardsInList.forEach(card => {
  671. card.move(list.boardId, targetSwimlaneId, list._id);
  672. });
  673. // Don't cancel the sortable when moving to a different swimlane
  674. // The DOM move should be allowed to complete
  675. }
  676. // Allow reordering within the same swimlane by not canceling the sortable
  677. try {
  678. Lists.update(list._id, {
  679. $set: updateData,
  680. });
  681. } catch (error) {
  682. return;
  683. }
  684. // Try to get board component
  685. try {
  686. const boardComponent = BlazeComponent.getComponentForElement(ui.item[0]);
  687. if (boardComponent && boardComponent.setIsDragging) {
  688. boardComponent.setIsDragging(false);
  689. }
  690. } catch (e) {
  691. // Silent fail
  692. }
  693. // Re-enable dragscroll after list dragging is complete
  694. try {
  695. dragscroll.reset();
  696. } catch (e) {
  697. // Silent fail
  698. }
  699. // Re-enable dragscroll on all swimlanes
  700. $('.js-swimlane').each(function() {
  701. $(this).addClass('dragscroll');
  702. });
  703. }
  704. });
  705. }
  706. });
  707. // Initialize sortable on ALL listsGroup elements (even empty ones)
  708. $listsGroupElements.each(function(index) {
  709. const $listsGroup = $(this);
  710. const $lists = $listsGroup.find('.js-list');
  711. // Only initialize on listsGroup elements that have the .js-lists class
  712. if ($listsGroup.hasClass('js-lists')) {
  713. $listsGroup.sortable({
  714. connectWith: '.js-swimlane, .js-lists',
  715. tolerance: 'pointer',
  716. appendTo: '.board-canvas',
  717. helper: 'clone',
  718. items: '.js-list:not(.js-list-composer)',
  719. placeholder: 'list placeholder',
  720. distance: 7,
  721. handle: '.js-list-handle',
  722. disabled: !Utils.canModifyBoard(),
  723. start(evt, ui) {
  724. ui.helper.css('z-index', 1000);
  725. ui.placeholder.height(ui.helper.height());
  726. ui.placeholder.width(ui.helper.width());
  727. EscapeActions.executeUpTo('popup-close');
  728. // Try to get board component
  729. try {
  730. const boardComponent = BlazeComponent.getComponentForElement(ui.item[0]);
  731. if (boardComponent && boardComponent.setIsDragging) {
  732. boardComponent.setIsDragging(true);
  733. }
  734. } catch (e) {
  735. // Silent fail
  736. }
  737. },
  738. stop(evt, ui) {
  739. // To attribute the new index number, we need to get the DOM element
  740. // of the previous and the following list -- if any.
  741. const prevListDom = ui.item.prev('.js-list').get(0);
  742. const nextListDom = ui.item.next('.js-list').get(0);
  743. const sortIndex = calculateIndex(prevListDom, nextListDom, 1);
  744. const listDomElement = ui.item.get(0);
  745. if (!listDomElement) {
  746. return;
  747. }
  748. let list;
  749. try {
  750. list = Blaze.getData(listDomElement);
  751. } catch (error) {
  752. return;
  753. }
  754. if (!list) {
  755. return;
  756. }
  757. // Detect if the list was dropped in a different swimlane
  758. const targetSwimlaneDom = ui.item.closest('.js-swimlane');
  759. let targetSwimlaneId = null;
  760. if (targetSwimlaneDom.length > 0) {
  761. // List was dropped in a swimlane
  762. try {
  763. targetSwimlaneId = targetSwimlaneDom.attr('id').replace('swimlane-', '');
  764. } catch (error) {
  765. return;
  766. }
  767. } else {
  768. // List was dropped in lists view (not swimlanes view)
  769. // In this case, assign to the default swimlane
  770. const currentBoard = ReactiveCache.getBoard(Session.get('currentBoard'));
  771. if (currentBoard) {
  772. const defaultSwimlane = currentBoard.getDefaultSwimline();
  773. if (defaultSwimlane) {
  774. targetSwimlaneId = defaultSwimlane._id;
  775. }
  776. }
  777. }
  778. // Get the original swimlane ID of the list (handle backward compatibility)
  779. const originalSwimlaneId = list.getEffectiveSwimlaneId ? list.getEffectiveSwimlaneId() : (list.swimlaneId || null);
  780. // Prepare update object
  781. const updateData = {
  782. sort: sortIndex.base,
  783. };
  784. // Check if the list was dropped in a different swimlane
  785. const isDifferentSwimlane = targetSwimlaneId && targetSwimlaneId !== originalSwimlaneId;
  786. // If the list was dropped in a different swimlane, update the swimlaneId
  787. if (isDifferentSwimlane) {
  788. updateData.swimlaneId = targetSwimlaneId;
  789. // Move all cards in the list to the new swimlane
  790. const cardsInList = ReactiveCache.getCards({
  791. listId: list._id,
  792. archived: false
  793. });
  794. cardsInList.forEach(card => {
  795. card.move(list.boardId, targetSwimlaneId, list._id);
  796. });
  797. // Don't cancel the sortable when moving to a different swimlane
  798. // The DOM move should be allowed to complete
  799. }
  800. // Allow reordering within the same swimlane by not canceling the sortable
  801. try {
  802. Lists.update(list._id, {
  803. $set: updateData,
  804. });
  805. } catch (error) {
  806. return;
  807. }
  808. // Try to get board component
  809. try {
  810. const boardComponent = BlazeComponent.getComponentForElement(ui.item[0]);
  811. if (boardComponent && boardComponent.setIsDragging) {
  812. boardComponent.setIsDragging(false);
  813. }
  814. } catch (e) {
  815. // Silent fail
  816. }
  817. // Re-enable dragscroll after list dragging is complete
  818. try {
  819. dragscroll.reset();
  820. } catch (e) {
  821. // Silent fail
  822. }
  823. // Re-enable dragscroll on all swimlanes
  824. $('.js-swimlane').each(function() {
  825. $(this).addClass('dragscroll');
  826. });
  827. }
  828. });
  829. }
  830. });
  831. }, 1000);
  832. BlazeComponent.extendComponent({
  833. currentCardIsInThisList(listId, swimlaneId) {
  834. return currentCardIsInThisList(listId, swimlaneId);
  835. },
  836. visible(list) {
  837. if (list.archived) {
  838. // Show archived list only when filter archive is on
  839. if (!Filter.archive.isSelected()) {
  840. return false;
  841. }
  842. }
  843. if (Filter.lists._isActive()) {
  844. if (!list.title.match(Filter.lists.getRegexSelector())) {
  845. return false;
  846. }
  847. }
  848. if (Filter.hideEmpty.isSelected()) {
  849. // Check for cards in all swimlanes, not just the current one
  850. // This ensures lists with cards in other swimlanes are still visible
  851. const cards = list.cards();
  852. if (cards.length === 0) {
  853. return false;
  854. }
  855. }
  856. return true;
  857. },
  858. onRendered() {
  859. const boardComponent = this.parentComponent();
  860. const $listsDom = this.$('.js-lists');
  861. if (!Utils.getCurrentCardId()) {
  862. boardComponent.scrollLeft();
  863. }
  864. // Try a simpler approach for listsGroup too
  865. // Wait for DOM to be ready
  866. setTimeout(() => {
  867. const $lists = this.$('.js-list');
  868. const $parent = $lists.parent();
  869. if ($lists.length > 0) {
  870. // Check for drag handles
  871. const $handles = $parent.find('.js-list-handle');
  872. // Test if drag handles are clickable
  873. $handles.on('click', function(e) {
  874. e.preventDefault();
  875. e.stopPropagation();
  876. });
  877. $parent.sortable({
  878. connectWith: '.js-swimlane, .js-lists',
  879. tolerance: 'pointer',
  880. appendTo: '.board-canvas',
  881. helper: 'clone',
  882. items: '.js-list:not(.js-list-composer)',
  883. placeholder: 'list placeholder',
  884. distance: 7,
  885. handle: '.js-list-handle',
  886. disabled: !Utils.canModifyBoard(),
  887. start(evt, ui) {
  888. ui.helper.css('z-index', 1000);
  889. ui.placeholder.height(ui.helper.height());
  890. ui.placeholder.width(ui.helper.width());
  891. EscapeActions.executeUpTo('popup-close');
  892. boardComponent.setIsDragging(true);
  893. },
  894. stop(evt, ui) {
  895. boardComponent.setIsDragging(false);
  896. }
  897. });
  898. } else {
  899. }
  900. }, 100);
  901. },
  902. }).register('listsGroup');
  903. class MoveSwimlaneComponent extends BlazeComponent {
  904. serverMethod = 'moveSwimlane';
  905. onCreated() {
  906. this.currentSwimlane = this.currentData();
  907. }
  908. board() {
  909. return Utils.getCurrentBoard();
  910. }
  911. toBoardsSelector() {
  912. return {
  913. archived: false,
  914. 'members.userId': Meteor.userId(),
  915. type: 'board',
  916. _id: { $ne: this.board()._id },
  917. };
  918. }
  919. toBoards() {
  920. const ret = ReactiveCache.getBoards(this.toBoardsSelector(), { sort: { title: 1 } });
  921. return ret;
  922. }
  923. events() {
  924. return [
  925. {
  926. 'click .js-done'() {
  927. const bSelect = $('.js-select-boards')[0];
  928. let boardId;
  929. if (bSelect) {
  930. boardId = bSelect.options[bSelect.selectedIndex].value;
  931. Meteor.call(this.serverMethod, this.currentSwimlane._id, boardId);
  932. }
  933. Popup.back();
  934. },
  935. },
  936. ];
  937. }
  938. }
  939. MoveSwimlaneComponent.register('moveSwimlanePopup');
  940. (class extends MoveSwimlaneComponent {
  941. serverMethod = 'copySwimlane';
  942. toBoardsSelector() {
  943. const selector = super.toBoardsSelector();
  944. delete selector._id;
  945. return selector;
  946. }
  947. }.register('copySwimlanePopup'));