swimlanes.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921
  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. // Try to get board component
  614. try {
  615. const boardComponent = BlazeComponent.getComponentForElement(ui.item[0]);
  616. if (boardComponent && boardComponent.setIsDragging) {
  617. boardComponent.setIsDragging(false);
  618. }
  619. } catch (e) {
  620. // Silent fail
  621. }
  622. }
  623. });
  624. }
  625. });
  626. // Initialize sortable on ALL listsGroup elements (even empty ones)
  627. $listsGroupElements.each(function(index) {
  628. const $listsGroup = $(this);
  629. const $lists = $listsGroup.find('.js-list');
  630. // Only initialize on listsGroup elements that have the .js-lists class
  631. if ($listsGroup.hasClass('js-lists')) {
  632. $listsGroup.sortable({
  633. connectWith: '.js-swimlane, .js-lists',
  634. tolerance: 'pointer',
  635. appendTo: '.board-canvas',
  636. helper: 'clone',
  637. items: '.js-list:not(.js-list-composer)',
  638. placeholder: 'list placeholder',
  639. distance: 7,
  640. handle: '.js-list-handle',
  641. disabled: !Utils.canModifyBoard(),
  642. start(evt, ui) {
  643. ui.helper.css('z-index', 1000);
  644. ui.placeholder.height(ui.helper.height());
  645. ui.placeholder.width(ui.helper.width());
  646. EscapeActions.executeUpTo('popup-close');
  647. // Try to get board component
  648. try {
  649. const boardComponent = BlazeComponent.getComponentForElement(ui.item[0]);
  650. if (boardComponent && boardComponent.setIsDragging) {
  651. boardComponent.setIsDragging(true);
  652. }
  653. } catch (e) {
  654. // Silent fail
  655. }
  656. },
  657. stop(evt, ui) {
  658. // Try to get board component
  659. try {
  660. const boardComponent = BlazeComponent.getComponentForElement(ui.item[0]);
  661. if (boardComponent && boardComponent.setIsDragging) {
  662. boardComponent.setIsDragging(false);
  663. }
  664. } catch (e) {
  665. // Silent fail
  666. }
  667. }
  668. });
  669. }
  670. });
  671. }, 1000);
  672. BlazeComponent.extendComponent({
  673. currentCardIsInThisList(listId, swimlaneId) {
  674. return currentCardIsInThisList(listId, swimlaneId);
  675. },
  676. visible(list) {
  677. if (list.archived) {
  678. // Show archived list only when filter archive is on
  679. if (!Filter.archive.isSelected()) {
  680. return false;
  681. }
  682. }
  683. if (Filter.lists._isActive()) {
  684. if (!list.title.match(Filter.lists.getRegexSelector())) {
  685. return false;
  686. }
  687. }
  688. if (Filter.hideEmpty.isSelected()) {
  689. // Check for cards in all swimlanes, not just the current one
  690. // This ensures lists with cards in other swimlanes are still visible
  691. const cards = list.cards();
  692. if (cards.length === 0) {
  693. return false;
  694. }
  695. }
  696. return true;
  697. },
  698. onRendered() {
  699. const boardComponent = this.parentComponent();
  700. const $listsDom = this.$('.js-lists');
  701. if (!Utils.getCurrentCardId()) {
  702. boardComponent.scrollLeft();
  703. }
  704. // Try a simpler approach for listsGroup too
  705. // Wait for DOM to be ready
  706. setTimeout(() => {
  707. const $lists = this.$('.js-list');
  708. const $parent = $lists.parent();
  709. if ($lists.length > 0) {
  710. // Check for drag handles
  711. const $handles = $parent.find('.js-list-handle');
  712. // Test if drag handles are clickable
  713. $handles.on('click', function(e) {
  714. e.preventDefault();
  715. e.stopPropagation();
  716. });
  717. $parent.sortable({
  718. connectWith: '.js-swimlane, .js-lists',
  719. tolerance: 'pointer',
  720. appendTo: '.board-canvas',
  721. helper: 'clone',
  722. items: '.js-list:not(.js-list-composer)',
  723. placeholder: 'list placeholder',
  724. distance: 7,
  725. handle: '.js-list-handle',
  726. disabled: !Utils.canModifyBoard(),
  727. start(evt, ui) {
  728. ui.helper.css('z-index', 1000);
  729. ui.placeholder.height(ui.helper.height());
  730. ui.placeholder.width(ui.helper.width());
  731. EscapeActions.executeUpTo('popup-close');
  732. boardComponent.setIsDragging(true);
  733. },
  734. stop(evt, ui) {
  735. boardComponent.setIsDragging(false);
  736. }
  737. });
  738. } else {
  739. }
  740. }, 100);
  741. },
  742. }).register('listsGroup');
  743. class MoveSwimlaneComponent extends BlazeComponent {
  744. serverMethod = 'moveSwimlane';
  745. onCreated() {
  746. this.currentSwimlane = this.currentData();
  747. }
  748. board() {
  749. return Utils.getCurrentBoard();
  750. }
  751. toBoardsSelector() {
  752. return {
  753. archived: false,
  754. 'members.userId': Meteor.userId(),
  755. type: 'board',
  756. _id: { $ne: this.board()._id },
  757. };
  758. }
  759. toBoards() {
  760. const ret = ReactiveCache.getBoards(this.toBoardsSelector(), { sort: { title: 1 } });
  761. return ret;
  762. }
  763. events() {
  764. return [
  765. {
  766. 'click .js-done'() {
  767. const bSelect = $('.js-select-boards')[0];
  768. let boardId;
  769. if (bSelect) {
  770. boardId = bSelect.options[bSelect.selectedIndex].value;
  771. Meteor.call(this.serverMethod, this.currentSwimlane._id, boardId);
  772. }
  773. Popup.back();
  774. },
  775. },
  776. ];
  777. }
  778. }
  779. MoveSwimlaneComponent.register('moveSwimlanePopup');
  780. (class extends MoveSwimlaneComponent {
  781. serverMethod = 'copySwimlane';
  782. toBoardsSelector() {
  783. const selector = super.toBoardsSelector();
  784. delete selector._id;
  785. return selector;
  786. }
  787. }.register('copySwimlanePopup'));