boardBody.js 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055
  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 ($swimlanesDom.data('uiSortable') || $swimlanesDom.data('sortable')) {
  502. if (Utils.isTouchScreenOrShowDesktopDragHandles()) {
  503. $swimlanesDom.sortable('option', 'handle', '.js-swimlane-header-handle');
  504. } else {
  505. $swimlanesDom.sortable('option', 'handle', '.swimlane-header');
  506. }
  507. // Disable drag-dropping if the current user is not a board member
  508. $swimlanesDom.sortable(
  509. 'option',
  510. 'disabled',
  511. !ReactiveCache.getCurrentUser()?.isBoardAdmin(),
  512. );
  513. }
  514. });
  515. // If there is no data in the board (ie, no lists) we autofocus the list
  516. // creation form by clicking on the corresponding element.
  517. const currentBoard = Utils.getCurrentBoard();
  518. if (Utils.canModifyBoard() && currentBoard.lists().length === 0) {
  519. boardComponent.openNewListForm();
  520. }
  521. dragscroll.reset();
  522. Utils.setBackgroundImage();
  523. },
  524. notDisplayThisBoard() {
  525. let allowPrivateVisibilityOnly = TableVisibilityModeSettings.findOne('tableVisibilityMode-allowPrivateOnly');
  526. let currentBoard = Utils.getCurrentBoard();
  527. return allowPrivateVisibilityOnly !== undefined && allowPrivateVisibilityOnly.booleanValue && currentBoard && currentBoard.permission == 'public';
  528. },
  529. isViewSwimlanes() {
  530. const currentUser = ReactiveCache.getCurrentUser();
  531. let boardView;
  532. if (currentUser) {
  533. boardView = (currentUser.profile || {}).boardView;
  534. } else {
  535. boardView = window.localStorage.getItem('boardView');
  536. }
  537. // If no board view is set, default to swimlanes
  538. if (!boardView) {
  539. boardView = 'board-view-swimlanes';
  540. }
  541. return boardView === 'board-view-swimlanes';
  542. },
  543. isViewLists() {
  544. const currentUser = ReactiveCache.getCurrentUser();
  545. let boardView;
  546. if (currentUser) {
  547. boardView = (currentUser.profile || {}).boardView;
  548. } else {
  549. boardView = window.localStorage.getItem('boardView');
  550. }
  551. return boardView === 'board-view-lists';
  552. },
  553. isViewCalendar() {
  554. const currentUser = ReactiveCache.getCurrentUser();
  555. let boardView;
  556. if (currentUser) {
  557. boardView = (currentUser.profile || {}).boardView;
  558. } else {
  559. boardView = window.localStorage.getItem('boardView');
  560. }
  561. return boardView === 'board-view-cal';
  562. },
  563. hasSwimlanes() {
  564. const currentBoard = Utils.getCurrentBoard();
  565. if (!currentBoard) {
  566. if (process.env.DEBUG === 'true') {
  567. console.log('hasSwimlanes: No current board');
  568. }
  569. return false;
  570. }
  571. try {
  572. const swimlanes = currentBoard.swimlanes();
  573. const hasSwimlanes = swimlanes && swimlanes.length > 0;
  574. if (process.env.DEBUG === 'true') {
  575. console.log('hasSwimlanes: Board has', swimlanes ? swimlanes.length : 0, 'swimlanes');
  576. }
  577. return hasSwimlanes;
  578. } catch (error) {
  579. console.error('hasSwimlanes: Error getting swimlanes:', error);
  580. return false;
  581. }
  582. },
  583. isVerticalScrollbars() {
  584. const user = ReactiveCache.getCurrentUser();
  585. return user && user.isVerticalScrollbars();
  586. },
  587. boardView() {
  588. return Utils.boardView();
  589. },
  590. debugBoardState() {
  591. // Enable debug mode by setting ?debug=1 in URL
  592. const urlParams = new URLSearchParams(window.location.search);
  593. return urlParams.get('debug') === '1';
  594. },
  595. debugBoardStateData() {
  596. const currentBoard = Utils.getCurrentBoard();
  597. const currentBoardId = Session.get('currentBoard');
  598. const isBoardReady = this.isBoardReady.get();
  599. const isConverting = this.isConverting.get();
  600. const isMigrating = this.isMigrating.get();
  601. const boardView = Utils.boardView();
  602. if (process.env.DEBUG === 'true') {
  603. console.log('=== BOARD DEBUG STATE ===');
  604. console.log('currentBoardId:', currentBoardId);
  605. console.log('currentBoard:', !!currentBoard, currentBoard ? currentBoard.title : 'none');
  606. console.log('isBoardReady:', isBoardReady);
  607. console.log('isConverting:', isConverting);
  608. console.log('isMigrating:', isMigrating);
  609. console.log('boardView:', boardView);
  610. console.log('========================');
  611. }
  612. return {
  613. currentBoardId,
  614. hasCurrentBoard: !!currentBoard,
  615. currentBoardTitle: currentBoard ? currentBoard.title : 'none',
  616. isBoardReady,
  617. isConverting,
  618. isMigrating,
  619. boardView
  620. };
  621. },
  622. openNewListForm() {
  623. if (this.isViewSwimlanes()) {
  624. // The form had been removed in 416b17062e57f215206e93a85b02ef9eb1ab4902
  625. // this.childComponents('swimlane')[0]
  626. // .childComponents('addListAndSwimlaneForm')[0]
  627. // .open();
  628. } else if (this.isViewLists()) {
  629. this.childComponents('listsGroup')[0]
  630. .childComponents('addListForm')[0]
  631. .open();
  632. }
  633. },
  634. events() {
  635. return [
  636. {
  637. // XXX The board-overlay div should probably be moved to the parent
  638. // component.
  639. mouseup() {
  640. if (this._isDragging) {
  641. this._isDragging = false;
  642. }
  643. },
  644. 'click .js-empty-board-add-swimlane': Popup.open('swimlaneAdd'),
  645. // Global drag and drop file upload handlers for better visual feedback
  646. 'dragover .board-canvas'(event) {
  647. const dataTransfer = event.originalEvent.dataTransfer;
  648. if (dataTransfer && dataTransfer.types && dataTransfer.types.includes('Files')) {
  649. event.preventDefault();
  650. // Add visual indicator that files can be dropped
  651. $('.board-canvas').addClass('file-drag-over');
  652. }
  653. },
  654. 'dragleave .board-canvas'(event) {
  655. const dataTransfer = event.originalEvent.dataTransfer;
  656. if (dataTransfer && dataTransfer.types && dataTransfer.types.includes('Files')) {
  657. // Only remove class if we're leaving the board canvas entirely
  658. if (!event.currentTarget.contains(event.relatedTarget)) {
  659. $('.board-canvas').removeClass('file-drag-over');
  660. }
  661. }
  662. },
  663. 'drop .board-canvas'(event) {
  664. const dataTransfer = event.originalEvent.dataTransfer;
  665. if (dataTransfer && dataTransfer.types && dataTransfer.types.includes('Files')) {
  666. event.preventDefault();
  667. $('.board-canvas').removeClass('file-drag-over');
  668. }
  669. },
  670. },
  671. ];
  672. },
  673. // XXX Flow components allow us to avoid creating these two setter methods by
  674. // exposing a public API to modify the component state. We need to investigate
  675. // best practices here.
  676. setIsDragging(bool) {
  677. this.draggingActive.set(bool);
  678. },
  679. scrollLeft(position = 0) {
  680. const swimlanes = this.$('.js-swimlanes');
  681. swimlanes &&
  682. swimlanes.animate({
  683. scrollLeft: position,
  684. });
  685. },
  686. scrollTop(position = 0) {
  687. const swimlanes = this.$('.js-swimlanes');
  688. swimlanes &&
  689. swimlanes.animate({
  690. scrollTop: position,
  691. });
  692. },
  693. }).register('boardBody');
  694. // Accessibility: Allow users to enable/disable keyboard shortcuts
  695. window.wekanShortcutsEnabled = true;
  696. window.toggleWekanShortcuts = function(enabled) {
  697. window.wekanShortcutsEnabled = !!enabled;
  698. };
  699. // Example: Wrap your character key shortcut handler like this
  700. document.addEventListener('keydown', function(e) {
  701. // Example: "W" key shortcut (replace with your actual shortcut logic)
  702. if (!window.wekanShortcutsEnabled) return;
  703. if (e.key === 'w' || e.key === 'W') {
  704. // ...existing shortcut logic...
  705. // e.g. open swimlanes view, etc.
  706. }
  707. });
  708. // Keyboard accessibility for card actions (favorite, archive, duplicate, etc.)
  709. document.addEventListener('keydown', function(e) {
  710. if (!window.wekanShortcutsEnabled) return;
  711. // Only proceed if focus is on a card action element
  712. const active = document.activeElement;
  713. if (active && active.classList.contains('js-card-action')) {
  714. if (e.key === 'Enter' || e.key === ' ') {
  715. e.preventDefault();
  716. active.click();
  717. }
  718. // Move card up/down with arrow keys
  719. if (e.key === 'ArrowUp') {
  720. e.preventDefault();
  721. if (active.dataset.cardId) {
  722. Meteor.call('moveCardUp', active.dataset.cardId);
  723. }
  724. }
  725. if (e.key === 'ArrowDown') {
  726. e.preventDefault();
  727. if (active.dataset.cardId) {
  728. Meteor.call('moveCardDown', active.dataset.cardId);
  729. }
  730. }
  731. }
  732. // Make plus/add elements keyboard accessible
  733. if (active && active.classList.contains('js-add-card')) {
  734. if (e.key === 'Enter' || e.key === ' ') {
  735. e.preventDefault();
  736. active.click();
  737. }
  738. }
  739. // Keyboard move for cards (alternative to drag & drop)
  740. if (active && active.classList.contains('js-move-card')) {
  741. if (e.key === 'ArrowUp') {
  742. e.preventDefault();
  743. if (active.dataset.cardId) {
  744. Meteor.call('moveCardUp', active.dataset.cardId);
  745. }
  746. }
  747. if (e.key === 'ArrowDown') {
  748. e.preventDefault();
  749. if (active.dataset.cardId) {
  750. Meteor.call('moveCardDown', active.dataset.cardId);
  751. }
  752. }
  753. }
  754. // Ensure move card buttons are focusable and have ARIA roles
  755. document.querySelectorAll('.js-move-card').forEach(function(el) {
  756. el.setAttribute('tabindex', '0');
  757. el.setAttribute('role', 'button');
  758. el.setAttribute('aria-label', 'Move card');
  759. });
  760. // Make toggle-buttons, color choices, reactions, and X-buttons keyboard accessible
  761. if (active && (active.classList.contains('js-toggle') || active.classList.contains('js-color-choice') || active.classList.contains('js-reaction') || active.classList.contains('close'))) {
  762. if (e.key === 'Enter' || e.key === ' ') {
  763. e.preventDefault();
  764. active.click();
  765. }
  766. }
  767. // Prevent scripts from removing focus when received
  768. if (active) {
  769. active.addEventListener('focus', function(e) {
  770. // Do not remove focus
  771. // No-op: This prevents F55 failure
  772. }, { once: true });
  773. }
  774. // Make swimlane/list renaming keyboard accessible
  775. if (active && (active.classList.contains('js-rename-swimlane') || active.classList.contains('js-rename-list'))) {
  776. if (e.key === 'Enter') {
  777. e.preventDefault();
  778. active.click();
  779. }
  780. }
  781. // Calendar navigation buttons
  782. if (active && active.classList.contains('fc-button')) {
  783. if (e.key === 'Enter' || e.key === ' ') {
  784. e.preventDefault();
  785. active.click();
  786. }
  787. }
  788. });
  789. BlazeComponent.extendComponent({
  790. onRendered() {
  791. // Set the language attribute on the <html> element for accessibility
  792. document.documentElement.lang = TAPi18n.getLanguage();
  793. this.autorun(function () {
  794. $('#calendar-view').fullCalendar('refetchEvents');
  795. });
  796. },
  797. calendarOptions() {
  798. return {
  799. id: 'calendar-view',
  800. defaultView: 'month',
  801. editable: true,
  802. selectable: true,
  803. timezone: 'local',
  804. weekNumbers: true,
  805. header: {
  806. left: 'title today prev,next',
  807. center:
  808. 'agendaDay,listDay,timelineDay agendaWeek,listWeek,timelineWeek month,listMonth',
  809. right: '',
  810. },
  811. buttonText: {
  812. prev: TAPi18n.__('calendar-previous-month-label'), // e.g. "Previous month"
  813. next: TAPi18n.__('calendar-next-month-label'), // e.g. "Next month"
  814. },
  815. ariaLabel: {
  816. prev: TAPi18n.__('calendar-previous-month-label'),
  817. next: TAPi18n.__('calendar-next-month-label'),
  818. },
  819. // height: 'parent', nope, doesn't work as the parent might be small
  820. height: 'auto',
  821. /* TODO: lists as resources: https://fullcalendar.io/docs/vertical-resource-view */
  822. navLinks: true,
  823. nowIndicator: true,
  824. businessHours: {
  825. // days of week. an array of zero-based day of week integers (0=Sunday)
  826. dow: [1, 2, 3, 4, 5], // Monday - Friday
  827. start: '8:00',
  828. end: '18:00',
  829. },
  830. locale: TAPi18n.getLanguage(),
  831. events(start, end, timezone, callback) {
  832. const currentBoard = Utils.getCurrentBoard();
  833. const events = [];
  834. const pushEvent = function (card, title, start, end, extraCls) {
  835. start = start || card.startAt;
  836. end = end || card.endAt;
  837. title = title || card.title;
  838. const className =
  839. (extraCls ? `${extraCls} ` : '') +
  840. (card.color ? `calendar-event-${card.color}` : '');
  841. events.push({
  842. id: card._id,
  843. title,
  844. start,
  845. end: end || card.endAt,
  846. allDay:
  847. Math.abs(end.getTime() - start.getTime()) / 1000 === 24 * 3600,
  848. url: FlowRouter.path('card', {
  849. boardId: currentBoard._id,
  850. slug: currentBoard.slug,
  851. cardId: card._id,
  852. }),
  853. className,
  854. });
  855. };
  856. currentBoard
  857. .cardsInInterval(start.toDate(), end.toDate())
  858. .forEach(function (card) {
  859. pushEvent(card);
  860. });
  861. currentBoard
  862. .cardsDueInBetween(start.toDate(), end.toDate())
  863. .forEach(function (card) {
  864. pushEvent(
  865. card,
  866. `${card.title} ${TAPi18n.__('card-due')}`,
  867. card.dueAt,
  868. new Date(card.dueAt.getTime() + 36e5),
  869. );
  870. });
  871. events.sort(function (first, second) {
  872. return first.id > second.id ? 1 : -1;
  873. });
  874. callback(events);
  875. },
  876. eventResize(event, delta, revertFunc) {
  877. let isOk = false;
  878. const card = ReactiveCache.getCard(event.id);
  879. if (card) {
  880. card.setEnd(event.end.toDate());
  881. isOk = true;
  882. }
  883. if (!isOk) {
  884. revertFunc();
  885. }
  886. },
  887. eventDrop(event, delta, revertFunc) {
  888. let isOk = false;
  889. const card = ReactiveCache.getCard(event.id);
  890. if (card) {
  891. // TODO: add a flag for allDay events
  892. if (!event.allDay) {
  893. // https://github.com/wekan/wekan/issues/2917#issuecomment-1236753962
  894. //card.setStart(event.start.toDate());
  895. //card.setEnd(event.end.toDate());
  896. card.setDue(event.start.toDate());
  897. isOk = true;
  898. }
  899. }
  900. if (!isOk) {
  901. revertFunc();
  902. }
  903. },
  904. select: function (startDate) {
  905. const currentBoard = Utils.getCurrentBoard();
  906. const currentUser = ReactiveCache.getCurrentUser();
  907. const modalElement = document.createElement('div');
  908. modalElement.classList.add('modal', 'fade');
  909. modalElement.setAttribute('tabindex', '-1');
  910. modalElement.setAttribute('role', 'dialog');
  911. modalElement.innerHTML = `
  912. <div class="modal-dialog justify-content-center align-items-center" role="document">
  913. <div class="modal-content">
  914. <div class="modal-header">
  915. <h5 class="modal-title">${TAPi18n.__('r-create-card')}</h5>
  916. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  917. <span aria-hidden="true">&times;</span>
  918. </button>
  919. </div>
  920. <div class="modal-body text-center">
  921. <input type="text" class="form-control" id="card-title-input" placeholder="">
  922. </div>
  923. <div class="modal-footer">
  924. <button type="button" class="btn btn-primary" id="create-card-button">${TAPi18n.__('add-card')}</button>
  925. </div>
  926. </div>
  927. </div>
  928. `;
  929. const createCardButton = modalElement.querySelector('#create-card-button');
  930. createCardButton.addEventListener('click', function () {
  931. const myTitle = modalElement.querySelector('#card-title-input').value;
  932. if (myTitle) {
  933. const firstList = currentBoard.draggableLists()[0];
  934. const firstSwimlane = currentBoard.swimlanes()[0];
  935. Meteor.call('createCardWithDueDate', currentBoard._id, firstList._id, myTitle, startDate.toDate(), firstSwimlane._id, function(error, result) {
  936. if (error) {
  937. console.log(error);
  938. } else {
  939. console.log("Card Created", result);
  940. }
  941. });
  942. closeModal();
  943. }
  944. });
  945. document.body.appendChild(modalElement);
  946. const openModal = function() {
  947. modalElement.style.display = 'flex';
  948. // Set focus to the input field for better keyboard accessibility
  949. const input = modalElement.querySelector('#card-title-input');
  950. if (input) input.focus();
  951. };
  952. const closeModal = function() {
  953. modalElement.style.display = 'none';
  954. };
  955. const closeButton = modalElement.querySelector('[data-dismiss="modal"]');
  956. closeButton.addEventListener('click', closeModal);
  957. openModal();
  958. }
  959. };
  960. },
  961. isViewCalendar() {
  962. const currentUser = ReactiveCache.getCurrentUser();
  963. if (currentUser) {
  964. return (currentUser.profile || {}).boardView === 'board-view-cal';
  965. } else {
  966. return window.localStorage.getItem('boardView') === 'board-view-cal';
  967. }
  968. },
  969. }).register('calendarView');