boardBody.js 34 KB

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