2
0

boardBody.js 34 KB

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