boardBody.js 35 KB

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