swimlanes.js 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115
  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. } else {
  197. // If staying in the same swimlane, cancel the sortable to prevent DOM manipulation issues
  198. $listsDom.sortable('cancel');
  199. }
  200. try {
  201. Lists.update(list._id, {
  202. $set: updateData,
  203. });
  204. } catch (error) {
  205. console.error('Error updating list:', error);
  206. return;
  207. }
  208. boardComponent.setIsDragging(false);
  209. // Re-enable dragscroll after list dragging is complete
  210. try {
  211. dragscroll.reset();
  212. } catch (e) {
  213. }
  214. // Re-enable dragscroll on all swimlanes
  215. $('.js-swimlane').each(function() {
  216. $(this).addClass('dragscroll');
  217. });
  218. },
  219. });
  220. } catch (error) {
  221. console.error('Error initializing list sortable:', error);
  222. return;
  223. }
  224. // Check if drag handles exist
  225. const dragHandles = $listsDom.find('.js-list-handle');
  226. // Check if lists exist
  227. const lists = $listsDom.find('.js-list');
  228. // Skip the complex autorun and options for now
  229. }
  230. BlazeComponent.extendComponent({
  231. onRendered() {
  232. const boardComponent = this.parentComponent();
  233. const $listsDom = this.$('.js-lists');
  234. if (!Utils.getCurrentCardId()) {
  235. boardComponent.scrollLeft();
  236. }
  237. // Try a simpler approach - initialize sortable directly like cards do
  238. // Wait for DOM to be ready
  239. setTimeout(() => {
  240. const $lists = this.$('.js-list');
  241. const $parent = $lists.parent();
  242. if ($lists.length > 0) {
  243. // Check for drag handles
  244. const $handles = $parent.find('.js-list-handle');
  245. // Test if drag handles are clickable
  246. $handles.on('click', function(e) {
  247. e.preventDefault();
  248. e.stopPropagation();
  249. });
  250. $parent.sortable({
  251. connectWith: '.js-swimlane, .js-lists',
  252. tolerance: 'pointer',
  253. appendTo: '.board-canvas',
  254. helper: 'clone',
  255. items: '.js-list:not(.js-list-composer)',
  256. placeholder: 'list placeholder',
  257. distance: 7,
  258. handle: '.js-list-handle',
  259. disabled: !Utils.canModifyBoard(),
  260. start(evt, ui) {
  261. ui.helper.css('z-index', 1000);
  262. ui.placeholder.height(ui.helper.height());
  263. ui.placeholder.width(ui.helper.width());
  264. EscapeActions.executeUpTo('popup-close');
  265. boardComponent.setIsDragging(true);
  266. },
  267. stop(evt, ui) {
  268. boardComponent.setIsDragging(false);
  269. }
  270. });
  271. } else {
  272. }
  273. }, 100);
  274. },
  275. onCreated() {
  276. this.draggingActive = new ReactiveVar(false);
  277. this._isDragging = false;
  278. this._lastDragPositionX = 0;
  279. },
  280. id() {
  281. return this._id;
  282. },
  283. currentCardIsInThisList(listId, swimlaneId) {
  284. return currentCardIsInThisList(listId, swimlaneId);
  285. },
  286. currentListIsInThisSwimlane(swimlaneId) {
  287. return currentListIsInThisSwimlane(swimlaneId);
  288. },
  289. visible(list) {
  290. if (list.archived) {
  291. // Show archived list only when filter archive is on
  292. if (!Filter.archive.isSelected()) {
  293. return false;
  294. }
  295. }
  296. if (Filter.lists._isActive()) {
  297. if (!list.title.match(Filter.lists.getRegexSelector())) {
  298. return false;
  299. }
  300. }
  301. if (Filter.hideEmpty.isSelected()) {
  302. // Check for cards in all swimlanes, not just the current one
  303. // This ensures lists with cards in other swimlanes are still visible
  304. const cards = list.cards();
  305. if (cards.length === 0) {
  306. return false;
  307. }
  308. }
  309. return true;
  310. },
  311. events() {
  312. return [
  313. {
  314. // Click-and-drag action
  315. 'mousedown .board-canvas'(evt) {
  316. // Translating the board canvas using the click-and-drag action can
  317. // conflict with the build-in browser mechanism to select text. We
  318. // define a list of elements in which we disable the dragging because
  319. // the user will legitimately expect to be able to select some text with
  320. // his mouse.
  321. const noDragInside = ['a', 'input', 'textarea', 'p'].concat(
  322. Utils.isTouchScreenOrShowDesktopDragHandles()
  323. ? ['.js-list-handle', '.js-swimlane-header-handle']
  324. : ['.js-list-header'],
  325. ).concat([
  326. '.js-list-resize-handle',
  327. '.js-swimlane-resize-handle'
  328. ]);
  329. const isResizeHandle = $(evt.target).closest('.js-list-resize-handle, .js-swimlane-resize-handle').length > 0;
  330. const isInNoDragArea = $(evt.target).closest(noDragInside.join(',')).length > 0;
  331. if (isResizeHandle) {
  332. return;
  333. }
  334. if (
  335. !isInNoDragArea &&
  336. this.$('.swimlane').prop('clientHeight') > evt.offsetY
  337. ) {
  338. this._isDragging = true;
  339. this._lastDragPositionX = evt.clientX;
  340. }
  341. },
  342. mouseup() {
  343. if (this._isDragging) {
  344. this._isDragging = false;
  345. }
  346. },
  347. mousemove(evt) {
  348. if (this._isDragging) {
  349. // Update the canvas position
  350. this.listsDom.scrollLeft -= evt.clientX - this._lastDragPositionX;
  351. this._lastDragPositionX = evt.clientX;
  352. // Disable browser text selection while dragging
  353. evt.stopPropagation();
  354. evt.preventDefault();
  355. // Don't close opened card or inlined form at the end of the
  356. // click-and-drag.
  357. EscapeActions.executeUpTo('popup-close');
  358. EscapeActions.preventNextClick();
  359. }
  360. },
  361. },
  362. ];
  363. },
  364. swimlaneHeight() {
  365. const user = ReactiveCache.getCurrentUser();
  366. const swimlane = Template.currentData();
  367. let height;
  368. if (user) {
  369. // For logged-in users, get from user profile
  370. height = user.getSwimlaneHeightFromStorage(swimlane.boardId, swimlane._id);
  371. } else {
  372. // For non-logged-in users, get from localStorage
  373. try {
  374. const stored = localStorage.getItem('wekan-swimlane-heights');
  375. if (stored) {
  376. const heights = JSON.parse(stored);
  377. if (heights[swimlane.boardId] && heights[swimlane.boardId][swimlane._id]) {
  378. height = heights[swimlane.boardId][swimlane._id];
  379. } else {
  380. height = -1;
  381. }
  382. } else {
  383. height = -1;
  384. }
  385. } catch (e) {
  386. console.warn('Error reading swimlane height from localStorage:', e);
  387. height = -1;
  388. }
  389. }
  390. return height == -1 ? "auto" : (height + 5 + "px");
  391. },
  392. onRendered() {
  393. // Initialize swimlane resize functionality immediately
  394. this.initializeSwimlaneResize();
  395. },
  396. initializeSwimlaneResize() {
  397. // Check if we're still in a valid template context
  398. if (!Template.currentData()) {
  399. console.warn('No current template data available for swimlane resize initialization');
  400. return;
  401. }
  402. const swimlane = Template.currentData();
  403. const $swimlane = $(`#swimlane-${swimlane._id}`);
  404. const $resizeHandle = $swimlane.find('.js-swimlane-resize-handle');
  405. // Check if elements exist
  406. if (!$swimlane.length || !$resizeHandle.length) {
  407. console.warn('Swimlane or resize handle not found, retrying in 100ms');
  408. Meteor.setTimeout(() => {
  409. if (!this.isDestroyed) {
  410. this.initializeSwimlaneResize();
  411. }
  412. }, 100);
  413. return;
  414. }
  415. if ($resizeHandle.length === 0) {
  416. return;
  417. }
  418. let isResizing = false;
  419. let startY = 0;
  420. let startHeight = 0;
  421. const minHeight = 100;
  422. const maxHeight = 2000;
  423. const startResize = (e) => {
  424. isResizing = true;
  425. startY = e.pageY || e.originalEvent.touches[0].pageY;
  426. startHeight = parseInt($swimlane.css('height')) || 300;
  427. $swimlane.addClass('swimlane-resizing');
  428. $('body').addClass('swimlane-resizing-active');
  429. $('body').css('user-select', 'none');
  430. e.preventDefault();
  431. e.stopPropagation();
  432. };
  433. const doResize = (e) => {
  434. if (!isResizing) {
  435. return;
  436. }
  437. const currentY = e.pageY || e.originalEvent.touches[0].pageY;
  438. const deltaY = currentY - startY;
  439. const newHeight = Math.max(minHeight, Math.min(maxHeight, startHeight + deltaY));
  440. // Apply the new height immediately for real-time feedback
  441. $swimlane[0].style.setProperty('--swimlane-height', `${newHeight}px`);
  442. $swimlane[0].style.setProperty('height', `${newHeight}px`);
  443. $swimlane[0].style.setProperty('min-height', `${newHeight}px`);
  444. $swimlane[0].style.setProperty('max-height', `${newHeight}px`);
  445. $swimlane[0].style.setProperty('flex', 'none');
  446. $swimlane[0].style.setProperty('flex-basis', 'auto');
  447. $swimlane[0].style.setProperty('flex-grow', '0');
  448. $swimlane[0].style.setProperty('flex-shrink', '0');
  449. e.preventDefault();
  450. e.stopPropagation();
  451. };
  452. const stopResize = (e) => {
  453. if (!isResizing) return;
  454. isResizing = false;
  455. // Calculate final height
  456. const currentY = e.pageY || e.originalEvent.touches[0].pageY;
  457. const deltaY = currentY - startY;
  458. const finalHeight = Math.max(minHeight, Math.min(maxHeight, startHeight + deltaY));
  459. // Ensure the final height is applied
  460. $swimlane[0].style.setProperty('--swimlane-height', `${finalHeight}px`);
  461. $swimlane[0].style.setProperty('height', `${finalHeight}px`);
  462. $swimlane[0].style.setProperty('min-height', `${finalHeight}px`);
  463. $swimlane[0].style.setProperty('max-height', `${finalHeight}px`);
  464. $swimlane[0].style.setProperty('flex', 'none');
  465. $swimlane[0].style.setProperty('flex-basis', 'auto');
  466. $swimlane[0].style.setProperty('flex-grow', '0');
  467. $swimlane[0].style.setProperty('flex-shrink', '0');
  468. // Remove visual feedback but keep the height
  469. $swimlane.removeClass('swimlane-resizing');
  470. $('body').removeClass('swimlane-resizing-active');
  471. $('body').css('user-select', '');
  472. // Save the new height using the existing system
  473. const boardId = swimlane.boardId;
  474. const swimlaneId = swimlane._id;
  475. if (process.env.DEBUG === 'true') {
  476. }
  477. const currentUser = ReactiveCache.getCurrentUser();
  478. if (currentUser) {
  479. // For logged-in users, use server method
  480. Meteor.call('applySwimlaneHeightToStorage', boardId, swimlaneId, finalHeight, (error, result) => {
  481. if (error) {
  482. console.error('Error saving swimlane height:', error);
  483. } else {
  484. if (process.env.DEBUG === 'true') {
  485. }
  486. }
  487. });
  488. } else {
  489. // For non-logged-in users, save to localStorage directly
  490. try {
  491. const stored = localStorage.getItem('wekan-swimlane-heights');
  492. let heights = stored ? JSON.parse(stored) : {};
  493. if (!heights[boardId]) {
  494. heights[boardId] = {};
  495. }
  496. heights[boardId][swimlaneId] = finalHeight;
  497. localStorage.setItem('wekan-swimlane-heights', JSON.stringify(heights));
  498. if (process.env.DEBUG === 'true') {
  499. }
  500. } catch (e) {
  501. console.warn('Error saving swimlane height to localStorage:', e);
  502. }
  503. }
  504. e.preventDefault();
  505. };
  506. // Mouse events
  507. $resizeHandle.on('mousedown', startResize);
  508. $(document).on('mousemove', doResize);
  509. $(document).on('mouseup', stopResize);
  510. // Touch events for mobile
  511. $resizeHandle.on('touchstart', startResize, { passive: false });
  512. $(document).on('touchmove', doResize, { passive: false });
  513. $(document).on('touchend', stopResize, { passive: false });
  514. // Prevent dragscroll interference
  515. $resizeHandle.on('mousedown', (e) => {
  516. e.stopPropagation();
  517. });
  518. },
  519. }).register('swimlane');
  520. BlazeComponent.extendComponent({
  521. onCreated() {
  522. this.currentBoard = Utils.getCurrentBoard();
  523. this.isListTemplatesSwimlane =
  524. this.currentBoard.isTemplatesBoard() &&
  525. this.currentData().isListTemplatesSwimlane();
  526. this.currentSwimlane = this.currentData();
  527. },
  528. // Proxy
  529. open() {
  530. this.childComponents('inlinedForm')[0].open();
  531. },
  532. events() {
  533. return [
  534. {
  535. submit(evt) {
  536. evt.preventDefault();
  537. const titleInput = this.find('.list-name-input');
  538. const title = titleInput?.value.trim();
  539. if (!title) return;
  540. let sortIndex = 0;
  541. const lastList = this.currentBoard.getLastList();
  542. const boardId = Utils.getCurrentBoardId();
  543. const positionInput = this.find('.list-position-input');
  544. if (positionInput) {
  545. const positionId = positionInput.value.trim();
  546. const selectedList = ReactiveCache.getList({ boardId, _id: positionId, archived: false });
  547. if (selectedList) {
  548. sortIndex = selectedList.sort + 1;
  549. } else {
  550. sortIndex = Utils.calculateIndexData(lastList, null).base;
  551. }
  552. } else {
  553. sortIndex = Utils.calculateIndexData(lastList, null).base;
  554. }
  555. Lists.insert({
  556. title,
  557. boardId: Session.get('currentBoard'),
  558. sort: sortIndex,
  559. type: this.isListTemplatesSwimlane ? 'template-list' : 'list',
  560. swimlaneId: this.currentSwimlane._id, // Always set swimlaneId for per-swimlane list titles
  561. });
  562. titleInput.value = '';
  563. titleInput.focus();
  564. }
  565. },
  566. {
  567. 'click .js-list-template': Popup.open('searchElement'),
  568. },
  569. ];
  570. },
  571. }).register('addListForm');
  572. Template.swimlane.helpers({
  573. canSeeAddList() {
  574. return ReactiveCache.getCurrentUser().isBoardAdmin();
  575. },
  576. });
  577. // Initialize sortable on DOM elements
  578. setTimeout(() => {
  579. const $swimlaneElements = $('.swimlane');
  580. const $listsGroupElements = $('.list-group');
  581. // Initialize sortable on ALL swimlane elements (even empty ones)
  582. $swimlaneElements.each(function(index) {
  583. const $swimlane = $(this);
  584. const $lists = $swimlane.find('.js-list');
  585. // Only initialize on swimlanes that have the .js-lists class (the container for lists)
  586. if ($swimlane.hasClass('js-lists')) {
  587. $swimlane.sortable({
  588. connectWith: '.js-swimlane, .js-lists',
  589. tolerance: 'pointer',
  590. appendTo: '.board-canvas',
  591. helper: 'clone',
  592. items: '.js-list:not(.js-list-composer)',
  593. placeholder: 'list placeholder',
  594. distance: 7,
  595. handle: '.js-list-handle',
  596. disabled: !Utils.canModifyBoard(),
  597. start(evt, ui) {
  598. ui.helper.css('z-index', 1000);
  599. ui.placeholder.height(ui.helper.height());
  600. ui.placeholder.width(ui.helper.width());
  601. EscapeActions.executeUpTo('popup-close');
  602. // Try to get board component
  603. try {
  604. const boardComponent = BlazeComponent.getComponentForElement(ui.item[0]);
  605. if (boardComponent && boardComponent.setIsDragging) {
  606. boardComponent.setIsDragging(true);
  607. }
  608. } catch (e) {
  609. // Silent fail
  610. }
  611. },
  612. stop(evt, ui) {
  613. // To attribute the new index number, we need to get the DOM element
  614. // of the previous and the following list -- if any.
  615. const prevListDom = ui.item.prev('.js-list').get(0);
  616. const nextListDom = ui.item.next('.js-list').get(0);
  617. const sortIndex = calculateIndex(prevListDom, nextListDom, 1);
  618. const listDomElement = ui.item.get(0);
  619. if (!listDomElement) {
  620. return;
  621. }
  622. let list;
  623. try {
  624. list = Blaze.getData(listDomElement);
  625. } catch (error) {
  626. return;
  627. }
  628. if (!list) {
  629. return;
  630. }
  631. // Detect if the list was dropped in a different swimlane
  632. const targetSwimlaneDom = ui.item.closest('.js-swimlane');
  633. let targetSwimlaneId = null;
  634. if (targetSwimlaneDom.length > 0) {
  635. // List was dropped in a swimlane
  636. try {
  637. targetSwimlaneId = targetSwimlaneDom.attr('id').replace('swimlane-', '');
  638. } catch (error) {
  639. return;
  640. }
  641. } else {
  642. // List was dropped in lists view (not swimlanes view)
  643. // In this case, assign to the default swimlane
  644. const currentBoard = ReactiveCache.getBoard(Session.get('currentBoard'));
  645. if (currentBoard) {
  646. const defaultSwimlane = currentBoard.getDefaultSwimline();
  647. if (defaultSwimlane) {
  648. targetSwimlaneId = defaultSwimlane._id;
  649. }
  650. }
  651. }
  652. // Get the original swimlane ID of the list (handle backward compatibility)
  653. const originalSwimlaneId = list.getEffectiveSwimlaneId ? list.getEffectiveSwimlaneId() : (list.swimlaneId || null);
  654. // Prepare update object
  655. const updateData = {
  656. sort: sortIndex.base,
  657. };
  658. // Check if the list was dropped in a different swimlane
  659. const isDifferentSwimlane = targetSwimlaneId && targetSwimlaneId !== originalSwimlaneId;
  660. // If the list was dropped in a different swimlane, update the swimlaneId
  661. if (isDifferentSwimlane) {
  662. updateData.swimlaneId = targetSwimlaneId;
  663. // Move all cards in the list to the new swimlane
  664. const cardsInList = ReactiveCache.getCards({
  665. listId: list._id,
  666. archived: false
  667. });
  668. cardsInList.forEach(card => {
  669. card.move(list.boardId, targetSwimlaneId, list._id);
  670. });
  671. // Don't cancel the sortable when moving to a different swimlane
  672. // The DOM move should be allowed to complete
  673. } else {
  674. // If staying in the same swimlane, cancel the sortable to prevent DOM manipulation issues
  675. $swimlane.sortable('cancel');
  676. }
  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. } else {
  800. // If staying in the same swimlane, cancel the sortable to prevent DOM manipulation issues
  801. $listsGroup.sortable('cancel');
  802. }
  803. try {
  804. Lists.update(list._id, {
  805. $set: updateData,
  806. });
  807. } catch (error) {
  808. return;
  809. }
  810. // Try to get board component
  811. try {
  812. const boardComponent = BlazeComponent.getComponentForElement(ui.item[0]);
  813. if (boardComponent && boardComponent.setIsDragging) {
  814. boardComponent.setIsDragging(false);
  815. }
  816. } catch (e) {
  817. // Silent fail
  818. }
  819. // Re-enable dragscroll after list dragging is complete
  820. try {
  821. dragscroll.reset();
  822. } catch (e) {
  823. // Silent fail
  824. }
  825. // Re-enable dragscroll on all swimlanes
  826. $('.js-swimlane').each(function() {
  827. $(this).addClass('dragscroll');
  828. });
  829. }
  830. });
  831. }
  832. });
  833. }, 1000);
  834. BlazeComponent.extendComponent({
  835. currentCardIsInThisList(listId, swimlaneId) {
  836. return currentCardIsInThisList(listId, swimlaneId);
  837. },
  838. visible(list) {
  839. if (list.archived) {
  840. // Show archived list only when filter archive is on
  841. if (!Filter.archive.isSelected()) {
  842. return false;
  843. }
  844. }
  845. if (Filter.lists._isActive()) {
  846. if (!list.title.match(Filter.lists.getRegexSelector())) {
  847. return false;
  848. }
  849. }
  850. if (Filter.hideEmpty.isSelected()) {
  851. // Check for cards in all swimlanes, not just the current one
  852. // This ensures lists with cards in other swimlanes are still visible
  853. const cards = list.cards();
  854. if (cards.length === 0) {
  855. return false;
  856. }
  857. }
  858. return true;
  859. },
  860. onRendered() {
  861. const boardComponent = this.parentComponent();
  862. const $listsDom = this.$('.js-lists');
  863. if (!Utils.getCurrentCardId()) {
  864. boardComponent.scrollLeft();
  865. }
  866. // Try a simpler approach for listsGroup too
  867. // Wait for DOM to be ready
  868. setTimeout(() => {
  869. const $lists = this.$('.js-list');
  870. const $parent = $lists.parent();
  871. if ($lists.length > 0) {
  872. // Check for drag handles
  873. const $handles = $parent.find('.js-list-handle');
  874. // Test if drag handles are clickable
  875. $handles.on('click', function(e) {
  876. e.preventDefault();
  877. e.stopPropagation();
  878. });
  879. $parent.sortable({
  880. connectWith: '.js-swimlane, .js-lists',
  881. tolerance: 'pointer',
  882. appendTo: '.board-canvas',
  883. helper: 'clone',
  884. items: '.js-list:not(.js-list-composer)',
  885. placeholder: 'list placeholder',
  886. distance: 7,
  887. handle: '.js-list-handle',
  888. disabled: !Utils.canModifyBoard(),
  889. start(evt, ui) {
  890. ui.helper.css('z-index', 1000);
  891. ui.placeholder.height(ui.helper.height());
  892. ui.placeholder.width(ui.helper.width());
  893. EscapeActions.executeUpTo('popup-close');
  894. boardComponent.setIsDragging(true);
  895. },
  896. stop(evt, ui) {
  897. boardComponent.setIsDragging(false);
  898. }
  899. });
  900. } else {
  901. }
  902. }, 100);
  903. },
  904. }).register('listsGroup');
  905. class MoveSwimlaneComponent extends BlazeComponent {
  906. serverMethod = 'moveSwimlane';
  907. onCreated() {
  908. this.currentSwimlane = this.currentData();
  909. }
  910. board() {
  911. return Utils.getCurrentBoard();
  912. }
  913. toBoardsSelector() {
  914. return {
  915. archived: false,
  916. 'members.userId': Meteor.userId(),
  917. type: 'board',
  918. _id: { $ne: this.board()._id },
  919. };
  920. }
  921. toBoards() {
  922. const ret = ReactiveCache.getBoards(this.toBoardsSelector(), { sort: { title: 1 } });
  923. return ret;
  924. }
  925. events() {
  926. return [
  927. {
  928. 'click .js-done'() {
  929. const bSelect = $('.js-select-boards')[0];
  930. let boardId;
  931. if (bSelect) {
  932. boardId = bSelect.options[bSelect.selectedIndex].value;
  933. Meteor.call(this.serverMethod, this.currentSwimlane._id, boardId);
  934. }
  935. Popup.back();
  936. },
  937. },
  938. ];
  939. }
  940. }
  941. MoveSwimlaneComponent.register('moveSwimlanePopup');
  942. (class extends MoveSwimlaneComponent {
  943. serverMethod = 'copySwimlane';
  944. toBoardsSelector() {
  945. const selector = super.toBoardsSelector();
  946. delete selector._id;
  947. return selector;
  948. }
  949. }.register('copySwimlanePopup'));