boardBody.js 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015
  1. import { ReactiveCache } from '/imports/reactiveCache';
  2. import { TAPi18n } from '/imports/i18n';
  3. import dragscroll from '@wekanteam/dragscroll';
  4. import { boardConverter } from '/client/lib/boardConverter';
  5. import { migrationManager } from '/client/lib/migrationManager';
  6. import { attachmentMigrationManager } from '/client/lib/attachmentMigrationManager';
  7. import { Swimlanes } from '/models/swimlanes';
  8. const subManager = new SubsManager();
  9. const { calculateIndex } = Utils;
  10. const swimlaneWhileSortingHeight = 150;
  11. BlazeComponent.extendComponent({
  12. onCreated() {
  13. this.isBoardReady = new ReactiveVar(false);
  14. this.isConverting = new ReactiveVar(false);
  15. this.isMigrating = new ReactiveVar(false);
  16. this._swimlaneCreated = new Set(); // Track boards where we've created swimlanes
  17. // The pattern we use to manually handle data loading is described here:
  18. // https://kadira.io/academy/meteor-routing-guide/content/subscriptions-and-data-management/using-subs-manager
  19. // XXX The boardId should be readed from some sort the component "props",
  20. // unfortunatly, Blaze doesn't have this notion.
  21. this.autorun(() => {
  22. const currentBoardId = Session.get('currentBoard');
  23. if (!currentBoardId) return;
  24. const handle = subManager.subscribe('board', currentBoardId, false);
  25. Tracker.nonreactive(() => {
  26. Tracker.autorun(() => {
  27. if (handle.ready()) {
  28. // Ensure default swimlane exists (only once per board)
  29. this.ensureDefaultSwimlane(currentBoardId);
  30. // Check if board needs conversion
  31. this.checkAndConvertBoard(currentBoardId);
  32. } else {
  33. this.isBoardReady.set(false);
  34. }
  35. });
  36. });
  37. });
  38. },
  39. ensureDefaultSwimlane(boardId) {
  40. // Only create swimlane once per board
  41. if (this._swimlaneCreated.has(boardId)) {
  42. return;
  43. }
  44. try {
  45. const board = ReactiveCache.getBoard(boardId);
  46. if (!board) return;
  47. const swimlanes = board.swimlanes();
  48. if (swimlanes.length === 0) {
  49. const swimlaneId = Swimlanes.insert({
  50. title: 'Default',
  51. boardId: boardId,
  52. });
  53. this._swimlaneCreated.add(boardId);
  54. } else {
  55. this._swimlaneCreated.add(boardId);
  56. }
  57. } catch (error) {
  58. console.error('Error creating default swimlane:', error);
  59. }
  60. },
  61. async checkAndConvertBoard(boardId) {
  62. try {
  63. const board = ReactiveCache.getBoard(boardId);
  64. if (!board) {
  65. this.isBoardReady.set(true);
  66. return;
  67. }
  68. // Check if board needs migration based on migration version
  69. const needsMigration = !board.migrationVersion || board.migrationVersion < 1;
  70. if (needsMigration) {
  71. // Start background migration for old boards
  72. this.isMigrating.set(true);
  73. await this.startBackgroundMigration(boardId);
  74. this.isMigrating.set(false);
  75. }
  76. // Check if board needs conversion (for old structure)
  77. if (boardConverter.isBoardConverted(boardId)) {
  78. console.log(`Board ${boardId} has already been converted, skipping conversion`);
  79. this.isBoardReady.set(true);
  80. } else {
  81. const needsConversion = boardConverter.needsConversion(boardId);
  82. if (needsConversion) {
  83. this.isConverting.set(true);
  84. const success = await boardConverter.convertBoard(boardId);
  85. this.isConverting.set(false);
  86. if (success) {
  87. this.isBoardReady.set(true);
  88. } else {
  89. console.error('Board conversion failed, setting ready to true anyway');
  90. this.isBoardReady.set(true); // Still show board even if conversion failed
  91. }
  92. } else {
  93. this.isBoardReady.set(true);
  94. }
  95. }
  96. // Start attachment migration in background if needed
  97. this.startAttachmentMigrationIfNeeded(boardId);
  98. } catch (error) {
  99. console.error('Error during board conversion check:', error);
  100. this.isConverting.set(false);
  101. this.isMigrating.set(false);
  102. this.isBoardReady.set(true); // Show board even if conversion check failed
  103. }
  104. },
  105. async startBackgroundMigration(boardId) {
  106. try {
  107. // Start background migration using the cron system
  108. Meteor.call('boardMigration.startBoardMigration', boardId, (error, result) => {
  109. if (error) {
  110. console.error('Failed to start background migration:', error);
  111. } else {
  112. console.log('Background migration started for board:', boardId);
  113. }
  114. });
  115. } catch (error) {
  116. console.error('Error starting background migration:', error);
  117. }
  118. },
  119. async startAttachmentMigrationIfNeeded(boardId) {
  120. try {
  121. // Check if board has already been migrated
  122. if (attachmentMigrationManager.isBoardMigrated(boardId)) {
  123. console.log(`Board ${boardId} has already been migrated, skipping`);
  124. return;
  125. }
  126. // Check if there are unconverted attachments
  127. const unconvertedAttachments = attachmentMigrationManager.getUnconvertedAttachments(boardId);
  128. if (unconvertedAttachments.length > 0) {
  129. console.log(`Starting attachment migration for ${unconvertedAttachments.length} attachments in board ${boardId}`);
  130. await attachmentMigrationManager.startAttachmentMigration(boardId);
  131. } else {
  132. // No attachments to migrate, mark board as migrated
  133. // This will be handled by the migration manager itself
  134. console.log(`Board ${boardId} has no attachments to migrate`);
  135. }
  136. } catch (error) {
  137. console.error('Error starting attachment migration:', error);
  138. }
  139. },
  140. onlyShowCurrentCard() {
  141. const isMiniScreen = Utils.isMiniScreen();
  142. const currentCardId = Utils.getCurrentCardId(true);
  143. return isMiniScreen && currentCardId;
  144. },
  145. goHome() {
  146. FlowRouter.go('home');
  147. },
  148. isConverting() {
  149. return this.isConverting.get();
  150. },
  151. isMigrating() {
  152. return this.isMigrating.get();
  153. },
  154. isBoardReady() {
  155. return this.isBoardReady.get();
  156. },
  157. currentBoard() {
  158. return Utils.getCurrentBoard();
  159. },
  160. }).register('board');
  161. BlazeComponent.extendComponent({
  162. onCreated() {
  163. Meteor.subscribe('tableVisibilityModeSettings');
  164. this.showOverlay = new ReactiveVar(false);
  165. this.draggingActive = new ReactiveVar(false);
  166. this._isDragging = false;
  167. // Used to set the overlay
  168. this.mouseHasEnterCardDetails = false;
  169. // fix swimlanes sort field if there are null values
  170. const currentBoardData = Utils.getCurrentBoard();
  171. if (currentBoardData && Swimlanes) {
  172. const nullSortSwimlanes = currentBoardData.nullSortSwimlanes();
  173. if (nullSortSwimlanes.length > 0) {
  174. const swimlanes = currentBoardData.swimlanes();
  175. let count = 0;
  176. swimlanes.forEach(s => {
  177. Swimlanes.update(s._id, {
  178. $set: {
  179. sort: count,
  180. },
  181. });
  182. count += 1;
  183. });
  184. }
  185. }
  186. // fix lists sort field if there are null values
  187. if (currentBoardData && Lists) {
  188. const nullSortLists = currentBoardData.nullSortLists();
  189. if (nullSortLists.length > 0) {
  190. const lists = currentBoardData.lists();
  191. let count = 0;
  192. lists.forEach(l => {
  193. Lists.update(l._id, {
  194. $set: {
  195. sort: count,
  196. },
  197. });
  198. count += 1;
  199. });
  200. }
  201. }
  202. },
  203. onRendered() {
  204. // Initialize user settings (zoom and mobile mode)
  205. Utils.initializeUserSettings();
  206. // Detect iPhone devices and add class for better CSS targeting
  207. const isIPhone = /iPhone|iPod/.test(navigator.userAgent);
  208. if (isIPhone) {
  209. document.body.classList.add('iphone-device');
  210. }
  211. // Accessibility: Focus management for popups and menus
  212. function focusFirstInteractive(container) {
  213. if (!container) return;
  214. // Find first focusable element
  215. const focusable = container.querySelectorAll('button, [role="button"], a[href], input, select, textarea, [tabindex]:not([tabindex="-1"])');
  216. for (let i = 0; i < focusable.length; i++) {
  217. if (!focusable[i].disabled && focusable[i].offsetParent !== null) {
  218. focusable[i].focus();
  219. break;
  220. }
  221. }
  222. }
  223. // Observe for new popups/menus and set focus (but exclude swimlane content)
  224. const popupObserver = new MutationObserver(function(mutations) {
  225. mutations.forEach(function(mutation) {
  226. mutation.addedNodes.forEach(function(node) {
  227. if (node.nodeType === 1 &&
  228. (node.classList.contains('popup') || node.classList.contains('modal') || node.classList.contains('menu')) &&
  229. !node.closest('.js-swimlanes') &&
  230. !node.closest('.swimlane') &&
  231. !node.closest('.list') &&
  232. !node.closest('.minicard')) {
  233. setTimeout(function() { focusFirstInteractive(node); }, 10);
  234. }
  235. });
  236. });
  237. });
  238. popupObserver.observe(document.body, { childList: true, subtree: true });
  239. // Remove tabindex from non-interactive elements (e.g., user abbreviations, labels)
  240. document.querySelectorAll('.user-abbreviation, .user-label, .card-header-label, .edit-label, .private-label').forEach(function(el) {
  241. if (el.hasAttribute('tabindex')) {
  242. el.removeAttribute('tabindex');
  243. }
  244. });
  245. /*
  246. // Add a toggle button for keyboard shortcuts accessibility
  247. if (!document.getElementById('wekan-shortcuts-toggle')) {
  248. const toggleContainer = document.createElement('div');
  249. toggleContainer.id = 'wekan-shortcuts-toggle';
  250. toggleContainer.style.position = 'fixed';
  251. toggleContainer.style.top = '10px';
  252. toggleContainer.style.right = '10px';
  253. toggleContainer.style.zIndex = '1000';
  254. toggleContainer.style.background = '#fff';
  255. toggleContainer.style.border = '2px solid #005fcc';
  256. toggleContainer.style.borderRadius = '6px';
  257. toggleContainer.style.padding = '8px 12px';
  258. toggleContainer.style.boxShadow = '0 2px 8px rgba(0,0,0,0.1)';
  259. toggleContainer.style.fontSize = '16px';
  260. toggleContainer.style.color = '#005fcc';
  261. toggleContainer.setAttribute('role', 'region');
  262. toggleContainer.setAttribute('aria-label', 'Keyboard Shortcuts Settings');
  263. toggleContainer.innerHTML = `
  264. <label for="shortcuts-toggle-checkbox" style="cursor:pointer;">
  265. <input type="checkbox" id="shortcuts-toggle-checkbox" ${window.wekanShortcutsEnabled ? 'checked' : ''} style="margin-right:8px;" />
  266. Enable keyboard shortcuts
  267. </label>
  268. `;
  269. document.body.appendChild(toggleContainer);
  270. const checkbox = document.getElementById('shortcuts-toggle-checkbox');
  271. checkbox.addEventListener('change', function(e) {
  272. window.toggleWekanShortcuts(e.target.checked);
  273. });
  274. }
  275. */
  276. // Ensure toggle-buttons, color choices, reactions, renaming, and calendar controls are focusable and have ARIA roles
  277. document.querySelectorAll('.js-toggle').forEach(function(el) {
  278. el.setAttribute('tabindex', '0');
  279. el.setAttribute('role', 'button');
  280. // Short, descriptive label for favorite/star toggle
  281. if (el.classList.contains('js-favorite-toggle')) {
  282. el.setAttribute('aria-label', TAPi18n.__('favorite-toggle-label'));
  283. } else {
  284. el.setAttribute('aria-label', 'Toggle');
  285. }
  286. });
  287. document.querySelectorAll('.js-color-choice').forEach(function(el) {
  288. el.setAttribute('tabindex', '0');
  289. el.setAttribute('role', 'button');
  290. el.setAttribute('aria-label', 'Choose color');
  291. });
  292. document.querySelectorAll('.js-reaction').forEach(function(el) {
  293. el.setAttribute('tabindex', '0');
  294. el.setAttribute('role', 'button');
  295. el.setAttribute('aria-label', 'React');
  296. });
  297. document.querySelectorAll('.js-rename-swimlane').forEach(function(el) {
  298. el.setAttribute('tabindex', '0');
  299. el.setAttribute('role', 'button');
  300. el.setAttribute('aria-label', 'Rename swimlane');
  301. });
  302. document.querySelectorAll('.js-rename-list').forEach(function(el) {
  303. el.setAttribute('tabindex', '0');
  304. el.setAttribute('role', 'button');
  305. el.setAttribute('aria-label', 'Rename list');
  306. });
  307. document.querySelectorAll('.fc-button').forEach(function(el) {
  308. el.setAttribute('tabindex', '0');
  309. el.setAttribute('role', 'button');
  310. });
  311. // Set the language attribute on the <html> element for accessibility
  312. document.documentElement.lang = TAPi18n.getLanguage();
  313. // Ensure the accessible name for the board view switcher matches the visible label "Swimlanes"
  314. // This fixes WCAG 2.5.3: Label in Name
  315. const swimlanesSwitcher = this.$('.js-board-view-swimlanes');
  316. if (swimlanesSwitcher.length) {
  317. swimlanesSwitcher.attr('aria-label', swimlanesSwitcher.text().trim() || 'Swimlanes');
  318. }
  319. // Add a highly visible focus indicator and improve contrast for interactive elements
  320. if (!document.getElementById('wekan-accessible-focus-style')) {
  321. const style = document.createElement('style');
  322. style.id = 'wekan-accessible-focus-style';
  323. style.innerHTML = `
  324. /* Focus indicator */
  325. button:focus, [role="button"]:focus, a:focus, input:focus, select:focus, textarea:focus, .dropdown-menu:focus, .js-board-view-swimlanes:focus, .js-add-card:focus {
  326. outline: 3px solid #005fcc !important;
  327. outline-offset: 2px !important;
  328. }
  329. /* Input borders */
  330. input, textarea, select {
  331. border: 2px solid #222 !important;
  332. }
  333. /* Plus icon for adding a new card */
  334. .js-add-card {
  335. color: #005fcc !important; /* dark blue for contrast */
  336. cursor: pointer;
  337. outline: none;
  338. }
  339. .js-add-card[tabindex] {
  340. outline: none;
  341. }
  342. /* Hamburger menu */
  343. .fa-bars, .icon-hamburger {
  344. color: #222 !important;
  345. }
  346. /* Grey icons in card detail header */
  347. .card-detail-header .fa, .card-detail-header .icon {
  348. color: #444 !important;
  349. }
  350. /* Grey operating elements in card detail */
  351. .card-detail .fa, .card-detail .icon {
  352. color: #444 !important;
  353. }
  354. /* Blue bar in checklists */
  355. .checklist-progress-bar {
  356. background-color: #005fcc !important;
  357. }
  358. /* Green checkmark in checklists */
  359. .checklist .fa-check {
  360. color: #007a33 !important;
  361. }
  362. /* X-Button and arrow button in menus */
  363. .close, .fa-arrow-left, .icon-arrow-left {
  364. color: #005fcc !important;
  365. }
  366. /* Cross icon to move boards */
  367. .js-move-board {
  368. color: #005fcc !important;
  369. }
  370. /* Current date background */
  371. .current-date {
  372. background-color: #005fcc !important;
  373. color: #fff !important;
  374. }
  375. `;
  376. document.head.appendChild(style);
  377. }
  378. // Ensure plus/add elements are focusable and have ARIA roles
  379. document.querySelectorAll('.js-add-card').forEach(function(el) {
  380. el.setAttribute('tabindex', '0');
  381. el.setAttribute('role', 'button');
  382. el.setAttribute('aria-label', 'Add new card');
  383. });
  384. const boardComponent = this;
  385. const $swimlanesDom = boardComponent.$('.js-swimlanes');
  386. $swimlanesDom.sortable({
  387. tolerance: 'pointer',
  388. appendTo: '.board-canvas',
  389. helper(evt, item) {
  390. const helper = $(`<div class="swimlane"
  391. style="flex-direction: column;
  392. height: ${swimlaneWhileSortingHeight}px;
  393. width: $(boardComponent.width)px;
  394. overflow: hidden;"/>`);
  395. helper.append(item.clone());
  396. // Also grab the list of lists of cards
  397. const list = item.next();
  398. helper.append(list.clone());
  399. return helper;
  400. },
  401. items: '.swimlane:not(.placeholder)',
  402. placeholder: 'swimlane placeholder',
  403. distance: 7,
  404. start(evt, ui) {
  405. const listDom = ui.placeholder.next('.js-swimlane');
  406. const parentOffset = ui.item.parent().offset();
  407. ui.placeholder.height(ui.helper.height());
  408. EscapeActions.executeUpTo('popup-close');
  409. listDom.addClass('moving-swimlane');
  410. boardComponent.setIsDragging(true);
  411. ui.placeholder.insertAfter(ui.placeholder.next());
  412. boardComponent.origPlaceholderIndex = ui.placeholder.index();
  413. // resize all swimlanes + headers to be a total of 150 px per row
  414. // this could be achieved by setIsDragging(true) but we want immediate
  415. // result
  416. ui.item
  417. .siblings('.js-swimlane')
  418. .css('height', `${swimlaneWhileSortingHeight - 26}px`);
  419. // set the new scroll height after the resize and insertion of
  420. // the placeholder. We want the element under the cursor to stay
  421. // at the same place on the screen
  422. ui.item.parent().get(0).scrollTop =
  423. ui.placeholder.get(0).offsetTop + parentOffset.top - evt.pageY;
  424. },
  425. beforeStop(evt, ui) {
  426. const parentOffset = ui.item.parent().offset();
  427. const siblings = ui.item.siblings('.js-swimlane');
  428. siblings.css('height', '');
  429. // compute the new scroll height after the resize and removal of
  430. // the placeholder
  431. const scrollTop =
  432. ui.placeholder.get(0).offsetTop + parentOffset.top - evt.pageY;
  433. // then reset the original view of the swimlane
  434. siblings.removeClass('moving-swimlane');
  435. // and apply the computed scrollheight
  436. ui.item.parent().get(0).scrollTop = scrollTop;
  437. },
  438. stop(evt, ui) {
  439. // To attribute the new index number, we need to get the DOM element
  440. // of the previous and the following card -- if any.
  441. const prevSwimlaneDom = ui.item.prevAll('.js-swimlane').get(0);
  442. const nextSwimlaneDom = ui.item.nextAll('.js-swimlane').get(0);
  443. const sortIndex = calculateIndex(prevSwimlaneDom, nextSwimlaneDom, 1);
  444. $swimlanesDom.sortable('cancel');
  445. const swimlaneDomElement = ui.item.get(0);
  446. const swimlane = Blaze.getData(swimlaneDomElement);
  447. Swimlanes.update(swimlane._id, {
  448. $set: {
  449. sort: sortIndex.base,
  450. },
  451. });
  452. boardComponent.setIsDragging(false);
  453. },
  454. sort(evt, ui) {
  455. // get the mouse position in the sortable
  456. const parentOffset = ui.item.parent().offset();
  457. const cursorY =
  458. evt.pageY - parentOffset.top + ui.item.parent().scrollTop();
  459. // compute the intended index of the placeholder (we need to skip the
  460. // slots between the headers and the list of cards)
  461. const newplaceholderIndex = Math.floor(
  462. cursorY / swimlaneWhileSortingHeight,
  463. );
  464. let destPlaceholderIndex = (newplaceholderIndex + 1) * 2;
  465. // if we are scrolling far away from the bottom of the list
  466. if (destPlaceholderIndex >= ui.item.parent().get(0).childElementCount) {
  467. destPlaceholderIndex = ui.item.parent().get(0).childElementCount - 1;
  468. }
  469. // update the placeholder position in the DOM tree
  470. if (destPlaceholderIndex !== ui.placeholder.index()) {
  471. if (destPlaceholderIndex < boardComponent.origPlaceholderIndex) {
  472. ui.placeholder.insertBefore(
  473. ui.placeholder
  474. .siblings()
  475. .slice(destPlaceholderIndex - 2, destPlaceholderIndex - 1),
  476. );
  477. } else {
  478. ui.placeholder.insertAfter(
  479. ui.placeholder
  480. .siblings()
  481. .slice(destPlaceholderIndex - 1, destPlaceholderIndex),
  482. );
  483. }
  484. }
  485. },
  486. });
  487. this.autorun(() => {
  488. // Always reset dragscroll on view switch
  489. dragscroll.reset();
  490. if (Utils.isTouchScreenOrShowDesktopDragHandles()) {
  491. $swimlanesDom.sortable({
  492. handle: '.js-swimlane-header-handle',
  493. });
  494. } else {
  495. $swimlanesDom.sortable({
  496. handle: '.swimlane-header',
  497. });
  498. }
  499. // Disable drag-dropping if the current user is not a board member
  500. $swimlanesDom.sortable(
  501. 'option',
  502. 'disabled',
  503. !ReactiveCache.getCurrentUser()?.isBoardAdmin(),
  504. );
  505. });
  506. // If there is no data in the board (ie, no lists) we autofocus the list
  507. // creation form by clicking on the corresponding element.
  508. const currentBoard = Utils.getCurrentBoard();
  509. if (Utils.canModifyBoard() && currentBoard.lists().length === 0) {
  510. boardComponent.openNewListForm();
  511. }
  512. dragscroll.reset();
  513. Utils.setBackgroundImage();
  514. },
  515. notDisplayThisBoard() {
  516. let allowPrivateVisibilityOnly = TableVisibilityModeSettings.findOne('tableVisibilityMode-allowPrivateOnly');
  517. let currentBoard = Utils.getCurrentBoard();
  518. return allowPrivateVisibilityOnly !== undefined && allowPrivateVisibilityOnly.booleanValue && currentBoard && currentBoard.permission == 'public';
  519. },
  520. isViewSwimlanes() {
  521. const currentUser = ReactiveCache.getCurrentUser();
  522. let boardView;
  523. if (currentUser) {
  524. boardView = (currentUser.profile || {}).boardView;
  525. } else {
  526. boardView = window.localStorage.getItem('boardView');
  527. }
  528. // If no board view is set, default to swimlanes
  529. if (!boardView) {
  530. boardView = 'board-view-swimlanes';
  531. }
  532. return boardView === 'board-view-swimlanes';
  533. },
  534. isViewLists() {
  535. const currentUser = ReactiveCache.getCurrentUser();
  536. let boardView;
  537. if (currentUser) {
  538. boardView = (currentUser.profile || {}).boardView;
  539. } else {
  540. boardView = window.localStorage.getItem('boardView');
  541. }
  542. return boardView === 'board-view-lists';
  543. },
  544. isViewCalendar() {
  545. const currentUser = ReactiveCache.getCurrentUser();
  546. let boardView;
  547. if (currentUser) {
  548. boardView = (currentUser.profile || {}).boardView;
  549. } else {
  550. boardView = window.localStorage.getItem('boardView');
  551. }
  552. return boardView === 'board-view-cal';
  553. },
  554. hasSwimlanes() {
  555. const currentBoard = Utils.getCurrentBoard();
  556. if (!currentBoard) {
  557. console.log('hasSwimlanes: No current board');
  558. return false;
  559. }
  560. try {
  561. const swimlanes = currentBoard.swimlanes();
  562. const hasSwimlanes = swimlanes && swimlanes.length > 0;
  563. console.log('hasSwimlanes: Board has', swimlanes ? swimlanes.length : 0, 'swimlanes');
  564. return hasSwimlanes;
  565. } catch (error) {
  566. console.error('hasSwimlanes: Error getting swimlanes:', error);
  567. return false;
  568. }
  569. },
  570. isVerticalScrollbars() {
  571. const user = ReactiveCache.getCurrentUser();
  572. return user && user.isVerticalScrollbars();
  573. },
  574. boardView() {
  575. return Utils.boardView();
  576. },
  577. debugBoardState() {
  578. // Enable debug mode by setting ?debug=1 in URL
  579. const urlParams = new URLSearchParams(window.location.search);
  580. return urlParams.get('debug') === '1';
  581. },
  582. debugBoardStateData() {
  583. const currentBoard = Utils.getCurrentBoard();
  584. const currentBoardId = Session.get('currentBoard');
  585. const isBoardReady = this.isBoardReady.get();
  586. const isConverting = this.isConverting.get();
  587. const isMigrating = this.isMigrating.get();
  588. const boardView = Utils.boardView();
  589. console.log('=== BOARD DEBUG STATE ===');
  590. console.log('currentBoardId:', currentBoardId);
  591. console.log('currentBoard:', !!currentBoard, currentBoard ? currentBoard.title : 'none');
  592. console.log('isBoardReady:', isBoardReady);
  593. console.log('isConverting:', isConverting);
  594. console.log('isMigrating:', isMigrating);
  595. console.log('boardView:', boardView);
  596. console.log('========================');
  597. return {
  598. currentBoardId,
  599. hasCurrentBoard: !!currentBoard,
  600. currentBoardTitle: currentBoard ? currentBoard.title : 'none',
  601. isBoardReady,
  602. isConverting,
  603. isMigrating,
  604. boardView
  605. };
  606. },
  607. openNewListForm() {
  608. if (this.isViewSwimlanes()) {
  609. // The form had been removed in 416b17062e57f215206e93a85b02ef9eb1ab4902
  610. // this.childComponents('swimlane')[0]
  611. // .childComponents('addListAndSwimlaneForm')[0]
  612. // .open();
  613. } else if (this.isViewLists()) {
  614. this.childComponents('listsGroup')[0]
  615. .childComponents('addListForm')[0]
  616. .open();
  617. }
  618. },
  619. events() {
  620. return [
  621. {
  622. // XXX The board-overlay div should probably be moved to the parent
  623. // component.
  624. mouseup() {
  625. if (this._isDragging) {
  626. this._isDragging = false;
  627. }
  628. },
  629. 'click .js-empty-board-add-swimlane': Popup.open('swimlaneAdd'),
  630. },
  631. ];
  632. },
  633. // XXX Flow components allow us to avoid creating these two setter methods by
  634. // exposing a public API to modify the component state. We need to investigate
  635. // best practices here.
  636. setIsDragging(bool) {
  637. this.draggingActive.set(bool);
  638. },
  639. scrollLeft(position = 0) {
  640. const swimlanes = this.$('.js-swimlanes');
  641. swimlanes &&
  642. swimlanes.animate({
  643. scrollLeft: position,
  644. });
  645. },
  646. scrollTop(position = 0) {
  647. const swimlanes = this.$('.js-swimlanes');
  648. swimlanes &&
  649. swimlanes.animate({
  650. scrollTop: position,
  651. });
  652. },
  653. }).register('boardBody');
  654. // Accessibility: Allow users to enable/disable keyboard shortcuts
  655. window.wekanShortcutsEnabled = true;
  656. window.toggleWekanShortcuts = function(enabled) {
  657. window.wekanShortcutsEnabled = !!enabled;
  658. };
  659. // Example: Wrap your character key shortcut handler like this
  660. document.addEventListener('keydown', function(e) {
  661. // Example: "W" key shortcut (replace with your actual shortcut logic)
  662. if (!window.wekanShortcutsEnabled) return;
  663. if (e.key === 'w' || e.key === 'W') {
  664. // ...existing shortcut logic...
  665. // e.g. open swimlanes view, etc.
  666. }
  667. });
  668. // Keyboard accessibility for card actions (favorite, archive, duplicate, etc.)
  669. document.addEventListener('keydown', function(e) {
  670. if (!window.wekanShortcutsEnabled) return;
  671. // Only proceed if focus is on a card action element
  672. const active = document.activeElement;
  673. if (active && active.classList.contains('js-card-action')) {
  674. if (e.key === 'Enter' || e.key === ' ') {
  675. e.preventDefault();
  676. active.click();
  677. }
  678. // Move card up/down with arrow keys
  679. if (e.key === 'ArrowUp') {
  680. e.preventDefault();
  681. if (active.dataset.cardId) {
  682. Meteor.call('moveCardUp', active.dataset.cardId);
  683. }
  684. }
  685. if (e.key === 'ArrowDown') {
  686. e.preventDefault();
  687. if (active.dataset.cardId) {
  688. Meteor.call('moveCardDown', active.dataset.cardId);
  689. }
  690. }
  691. }
  692. // Make plus/add elements keyboard accessible
  693. if (active && active.classList.contains('js-add-card')) {
  694. if (e.key === 'Enter' || e.key === ' ') {
  695. e.preventDefault();
  696. active.click();
  697. }
  698. }
  699. // Keyboard move for cards (alternative to drag & drop)
  700. if (active && active.classList.contains('js-move-card')) {
  701. if (e.key === 'ArrowUp') {
  702. e.preventDefault();
  703. if (active.dataset.cardId) {
  704. Meteor.call('moveCardUp', active.dataset.cardId);
  705. }
  706. }
  707. if (e.key === 'ArrowDown') {
  708. e.preventDefault();
  709. if (active.dataset.cardId) {
  710. Meteor.call('moveCardDown', active.dataset.cardId);
  711. }
  712. }
  713. }
  714. // Ensure move card buttons are focusable and have ARIA roles
  715. document.querySelectorAll('.js-move-card').forEach(function(el) {
  716. el.setAttribute('tabindex', '0');
  717. el.setAttribute('role', 'button');
  718. el.setAttribute('aria-label', 'Move card');
  719. });
  720. // Make toggle-buttons, color choices, reactions, and X-buttons keyboard accessible
  721. if (active && (active.classList.contains('js-toggle') || active.classList.contains('js-color-choice') || active.classList.contains('js-reaction') || active.classList.contains('close'))) {
  722. if (e.key === 'Enter' || e.key === ' ') {
  723. e.preventDefault();
  724. active.click();
  725. }
  726. }
  727. // Prevent scripts from removing focus when received
  728. if (active) {
  729. active.addEventListener('focus', function(e) {
  730. // Do not remove focus
  731. // No-op: This prevents F55 failure
  732. }, { once: true });
  733. }
  734. // Make swimlane/list renaming keyboard accessible
  735. if (active && (active.classList.contains('js-rename-swimlane') || active.classList.contains('js-rename-list'))) {
  736. if (e.key === 'Enter') {
  737. e.preventDefault();
  738. active.click();
  739. }
  740. }
  741. // Calendar navigation buttons
  742. if (active && active.classList.contains('fc-button')) {
  743. if (e.key === 'Enter' || e.key === ' ') {
  744. e.preventDefault();
  745. active.click();
  746. }
  747. }
  748. });
  749. BlazeComponent.extendComponent({
  750. onRendered() {
  751. // Set the language attribute on the <html> element for accessibility
  752. document.documentElement.lang = TAPi18n.getLanguage();
  753. this.autorun(function () {
  754. $('#calendar-view').fullCalendar('refetchEvents');
  755. });
  756. },
  757. calendarOptions() {
  758. return {
  759. id: 'calendar-view',
  760. defaultView: 'month',
  761. editable: true,
  762. selectable: true,
  763. timezone: 'local',
  764. weekNumbers: true,
  765. header: {
  766. left: 'title today prev,next',
  767. center:
  768. 'agendaDay,listDay,timelineDay agendaWeek,listWeek,timelineWeek month,listMonth',
  769. right: '',
  770. },
  771. buttonText: {
  772. prev: TAPi18n.__('calendar-previous-month-label'), // e.g. "Previous month"
  773. next: TAPi18n.__('calendar-next-month-label'), // e.g. "Next month"
  774. },
  775. ariaLabel: {
  776. prev: TAPi18n.__('calendar-previous-month-label'),
  777. next: TAPi18n.__('calendar-next-month-label'),
  778. },
  779. // height: 'parent', nope, doesn't work as the parent might be small
  780. height: 'auto',
  781. /* TODO: lists as resources: https://fullcalendar.io/docs/vertical-resource-view */
  782. navLinks: true,
  783. nowIndicator: true,
  784. businessHours: {
  785. // days of week. an array of zero-based day of week integers (0=Sunday)
  786. dow: [1, 2, 3, 4, 5], // Monday - Friday
  787. start: '8:00',
  788. end: '18:00',
  789. },
  790. locale: TAPi18n.getLanguage(),
  791. events(start, end, timezone, callback) {
  792. const currentBoard = Utils.getCurrentBoard();
  793. const events = [];
  794. const pushEvent = function (card, title, start, end, extraCls) {
  795. start = start || card.startAt;
  796. end = end || card.endAt;
  797. title = title || card.title;
  798. const className =
  799. (extraCls ? `${extraCls} ` : '') +
  800. (card.color ? `calendar-event-${card.color}` : '');
  801. events.push({
  802. id: card._id,
  803. title,
  804. start,
  805. end: end || card.endAt,
  806. allDay:
  807. Math.abs(end.getTime() - start.getTime()) / 1000 === 24 * 3600,
  808. url: FlowRouter.path('card', {
  809. boardId: currentBoard._id,
  810. slug: currentBoard.slug,
  811. cardId: card._id,
  812. }),
  813. className,
  814. });
  815. };
  816. currentBoard
  817. .cardsInInterval(start.toDate(), end.toDate())
  818. .forEach(function (card) {
  819. pushEvent(card);
  820. });
  821. currentBoard
  822. .cardsDueInBetween(start.toDate(), end.toDate())
  823. .forEach(function (card) {
  824. pushEvent(
  825. card,
  826. `${card.title} ${TAPi18n.__('card-due')}`,
  827. card.dueAt,
  828. new Date(card.dueAt.getTime() + 36e5),
  829. );
  830. });
  831. events.sort(function (first, second) {
  832. return first.id > second.id ? 1 : -1;
  833. });
  834. callback(events);
  835. },
  836. eventResize(event, delta, revertFunc) {
  837. let isOk = false;
  838. const card = ReactiveCache.getCard(event.id);
  839. if (card) {
  840. card.setEnd(event.end.toDate());
  841. isOk = true;
  842. }
  843. if (!isOk) {
  844. revertFunc();
  845. }
  846. },
  847. eventDrop(event, delta, revertFunc) {
  848. let isOk = false;
  849. const card = ReactiveCache.getCard(event.id);
  850. if (card) {
  851. // TODO: add a flag for allDay events
  852. if (!event.allDay) {
  853. // https://github.com/wekan/wekan/issues/2917#issuecomment-1236753962
  854. //card.setStart(event.start.toDate());
  855. //card.setEnd(event.end.toDate());
  856. card.setDue(event.start.toDate());
  857. isOk = true;
  858. }
  859. }
  860. if (!isOk) {
  861. revertFunc();
  862. }
  863. },
  864. select: function (startDate) {
  865. const currentBoard = Utils.getCurrentBoard();
  866. const currentUser = ReactiveCache.getCurrentUser();
  867. const modalElement = document.createElement('div');
  868. modalElement.classList.add('modal', 'fade');
  869. modalElement.setAttribute('tabindex', '-1');
  870. modalElement.setAttribute('role', 'dialog');
  871. modalElement.innerHTML = `
  872. <div class="modal-dialog justify-content-center align-items-center" role="document">
  873. <div class="modal-content">
  874. <div class="modal-header">
  875. <h5 class="modal-title">${TAPi18n.__('r-create-card')}</h5>
  876. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  877. <span aria-hidden="true">&times;</span>
  878. </button>
  879. </div>
  880. <div class="modal-body text-center">
  881. <input type="text" class="form-control" id="card-title-input" placeholder="">
  882. </div>
  883. <div class="modal-footer">
  884. <button type="button" class="btn btn-primary" id="create-card-button">${TAPi18n.__('add-card')}</button>
  885. </div>
  886. </div>
  887. </div>
  888. `;
  889. const createCardButton = modalElement.querySelector('#create-card-button');
  890. createCardButton.addEventListener('click', function () {
  891. const myTitle = modalElement.querySelector('#card-title-input').value;
  892. if (myTitle) {
  893. const firstList = currentBoard.draggableLists()[0];
  894. const firstSwimlane = currentBoard.swimlanes()[0];
  895. Meteor.call('createCardWithDueDate', currentBoard._id, firstList._id, myTitle, startDate.toDate(), firstSwimlane._id, function(error, result) {
  896. if (error) {
  897. console.log(error);
  898. } else {
  899. console.log("Card Created", result);
  900. }
  901. });
  902. closeModal();
  903. }
  904. });
  905. document.body.appendChild(modalElement);
  906. const openModal = function() {
  907. modalElement.style.display = 'flex';
  908. // Set focus to the input field for better keyboard accessibility
  909. const input = modalElement.querySelector('#card-title-input');
  910. if (input) input.focus();
  911. };
  912. const closeModal = function() {
  913. modalElement.style.display = 'none';
  914. };
  915. const closeButton = modalElement.querySelector('[data-dismiss="modal"]');
  916. closeButton.addEventListener('click', closeModal);
  917. openModal();
  918. }
  919. };
  920. },
  921. isViewCalendar() {
  922. const currentUser = ReactiveCache.getCurrentUser();
  923. if (currentUser) {
  924. return (currentUser.profile || {}).boardView === 'board-view-cal';
  925. } else {
  926. return window.localStorage.getItem('boardView') === 'board-view-cal';
  927. }
  928. },
  929. }).register('calendarView');