boardBody.js 37 KB

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