mirror of
https://github.com/wekan/wekan.git
synced 2026-11-25 04:49:41 -05:00
Added after comparing WeKan's charts with the reports of Jira, Azure
DevOps, Nave, ActionableAgile and the Flow Framework: Created vs.
Resolved, Net Flow, Time in List, Average Age, Throughput Run Chart and
Due Date Performance under Kanban flow; Release Burndown and Epic
Progress under Scrum; Workload, Distribution, Dependency Map and Activity
Heatmap under Overview. Each opens like the other charts, with the export
bar at its top, a Chart.js chart and its data table, which is also what
its PDF and Excel export write.
The calculations are pure (models/lib/boardReports.js) and answer one
shape, { bars, table }, so the chart view and both exports read every
report the same way; the server loads only what a report reads. A member
who may see only their assigned cards gets none of them, as with the
other charts. The report names and table headings are translated into
every language.
Thanks to xet7 !
1550 lines
54 KiB
JavaScript
1550 lines
54 KiB
JavaScript
import { markBoardVisited } from '/client/lib/boardVisits';
|
|
import { ReactiveCache } from '/imports/reactiveCache';
|
|
import { setSortableOptions } from '/client/lib/sortableOptions';
|
|
import { FlowRouter } from 'meteor/ostrio:flow-router-extra';
|
|
import { TAPi18n } from '/imports/i18n';
|
|
import {
|
|
suspendBoardDragscroll,
|
|
resumeBoardDragscroll,
|
|
resetBoardDragscroll,
|
|
} from '/client/lib/boardDragscroll';
|
|
import '/client/lib/dragscrollTouch';
|
|
import '/client/lib/dragDropTouch';
|
|
import { boardConverter } from '/client/lib/boardConverter';
|
|
// Bring the swimlane or list a link named into view, once it has rendered.
|
|
import { watchBoardItemReveals } from '/client/lib/revealBoardItem';
|
|
import { formatDateByUserPreference } from '/imports/lib/dateUtils';
|
|
import { calendarDateDisplayOptions } from '/client/lib/dateDisplay';
|
|
import { toFullCalendarFirstDay } from '/client/lib/calendarFirstDay';
|
|
import { weekNumberByFirstDay } from '/models/lib/weekStart';
|
|
import { calendarBaseOptions } from '/models/lib/calendarBaseOptions';
|
|
import Swimlanes from '/models/swimlanes';
|
|
import Lists from '/models/lists';
|
|
import TableVisibilityModeSettings from '/models/tableVisibilityModeSettings';
|
|
import { EscapeActions } from '/client/lib/escapeActions';
|
|
import { Utils } from '/client/lib/utils';
|
|
import { Filter } from '/client/lib/filter';
|
|
import {
|
|
parseBoardFilterQueryParams,
|
|
buildBoardFilterQueryParams,
|
|
} from '/client/lib/filterQueryParams';
|
|
import { migrationProgressManager } from '/client/components/settings/migrationProgress';
|
|
import { focusFirstControl } from '/client/lib/accessibility';
|
|
|
|
// SubsManager removed for Meteor 3 migration
|
|
const { calculateIndex } = Utils;
|
|
const swimlaneWhileSortingHeight = 150;
|
|
|
|
// Global reference so child components (swimlanes, cards) can access boardBody instance
|
|
let BoardBody = null;
|
|
|
|
Template.board.onCreated(function () {
|
|
this.isBoardReady = new ReactiveVar(false);
|
|
// The board publication stopped with an error: say so instead of spinning
|
|
// forever (a board restored from an old WeKan whose data the publication
|
|
// could not read showed only the loading animation).
|
|
this.boardLoadError = new ReactiveVar(false);
|
|
// Kept for the template/jade which still references it; conversion is a no-op.
|
|
this.isConverting = new ReactiveVar(false);
|
|
this._swimlaneCreated = new Set(); // boards where a default swimlane was ensured
|
|
this._listRepairChecked = new Set(); // boards whose data-repair was checked
|
|
this._queryFiltersApplied = new Set(); // boards whose URL filter params were applied
|
|
|
|
// #4540: let a board's filter state be driven by URL query params, e.g.
|
|
// `?assignee=johndoe` or `?member=johndoe,janedoe&label=urgent`, so a link
|
|
// (for instance embedded in an iframe) opens the board already filtered.
|
|
// Reuses the existing `Filter` sidebar state/API - this only translates the
|
|
// query params into the same `Filter.assignees` / `Filter.members` /
|
|
// `Filter.labelIds` calls the sidebar UI would make. Applied once per board
|
|
// load (guarded by `_queryFiltersApplied`), reading the query params once
|
|
// rather than reactively - this is a one-time "open pre-filtered" bridge,
|
|
// not two-way URL sync.
|
|
this.applyQueryParamFilters = (boardId) => {
|
|
if (!boardId || this._queryFiltersApplied.has(boardId)) {
|
|
return;
|
|
}
|
|
this._queryFiltersApplied.add(boardId);
|
|
|
|
const assigneeParam = FlowRouter.getQueryParam('assignee');
|
|
const memberParam = FlowRouter.getQueryParam('member');
|
|
const labelParam = FlowRouter.getQueryParam('label');
|
|
if (!assigneeParam && !memberParam && !labelParam) {
|
|
return;
|
|
}
|
|
|
|
const board = ReactiveCache.getBoard(boardId);
|
|
if (!board) {
|
|
return;
|
|
}
|
|
|
|
// Collect candidate usernames from both params to look up in one query.
|
|
const usernames = new Set();
|
|
(assigneeParam || '')
|
|
.split(',')
|
|
.concat((memberParam || '').split(','))
|
|
.map(u => u.trim())
|
|
.filter(Boolean)
|
|
.forEach(u => usernames.add(u));
|
|
|
|
const users = ReactiveCache.getUsers(
|
|
{ username: { $in: Array.from(usernames) } },
|
|
{ fields: { _id: 1, username: 1 } },
|
|
) || [];
|
|
|
|
const { assigneeIds, memberIds, labelIds } = parseBoardFilterQueryParams(
|
|
{ assignee: assigneeParam, member: memberParam, label: labelParam },
|
|
users,
|
|
board.labels,
|
|
);
|
|
|
|
assigneeIds.forEach(id => Filter.assignees.add(id));
|
|
memberIds.forEach(id => Filter.members.add(id));
|
|
labelIds.forEach(id => Filter.labelIds.add(id));
|
|
};
|
|
|
|
// #319: the write direction of the two-way URL sync #4540 started. Mirrors
|
|
// the `Filter` sidebar's current assignee/member/label selection into the
|
|
// `?assignee=`/`?member=`/`?label=` query params (reusing
|
|
// `buildBoardFilterQueryParams`'s token format, the exact inverse of
|
|
// `parseBoardFilterQueryParams` above) so a manually filtered board is a
|
|
// bookmarkable/shareable URL without the user having to hand-type it.
|
|
// Reactive by design (unlike the one-time `applyQueryParamFilters`
|
|
// read): every `Filter.assignees`/`members`/`labelIds` change re-runs this
|
|
// and updates the URL. Uses `FlowRouter.withReplaceState` so toggling a
|
|
// filter replaces the current history entry instead of piling up a new one
|
|
// per click.
|
|
this.syncFilterQueryParams = (boardId) => {
|
|
if (!boardId) {
|
|
return;
|
|
}
|
|
const assigneeIds = Filter.assignees.list();
|
|
const memberIds = Filter.members.list();
|
|
const labelIds = Filter.labelIds.list();
|
|
|
|
const board = ReactiveCache.getBoard(boardId);
|
|
if (!board) {
|
|
return;
|
|
}
|
|
|
|
const userIds = new Set([...assigneeIds, ...memberIds]);
|
|
const users = ReactiveCache.getUsers(
|
|
{ _id: { $in: Array.from(userIds) } },
|
|
{ fields: { _id: 1, username: 1 } },
|
|
) || [];
|
|
|
|
const queryParams = buildBoardFilterQueryParams(
|
|
{ assigneeIds, memberIds, labelIds },
|
|
users,
|
|
board.labels,
|
|
);
|
|
|
|
FlowRouter.withReplaceState(() => {
|
|
FlowRouter.setQueryParams(queryParams);
|
|
});
|
|
};
|
|
|
|
// When a board opens, detect whether it needs the shared data-repairs (the same
|
|
// set run during the MongoDB <-> SQLite migration): #6484 lists wrongly bound to
|
|
// a swimlane (a list DISAPPEARS from the other swimlanes), cards with no
|
|
// swimlane, and orphaned cards whose swimlane was deleted (invisible cards). If
|
|
// anything needs fixing and the viewer is a board admin, repair it — showing the
|
|
// shared blue, Product-name-branded migration-progress dashboard. Checked once
|
|
// per board, fire-and-forget so it never blocks rendering.
|
|
this.maybeRepairBoard = (boardId) => {
|
|
if (!boardId || this._listRepairChecked.has(boardId)) {
|
|
return;
|
|
}
|
|
this._listRepairChecked.add(boardId);
|
|
Meteor.call('boardRepairNeeded', boardId, (err, res) => {
|
|
if (err || !res || !res.total || !res.canRepair) {
|
|
return; // nothing to fix, or the viewer is not a board admin
|
|
}
|
|
migrationProgressManager.startMigration();
|
|
migrationProgressManager.updateProgress({
|
|
overallProgress: 20,
|
|
currentStep: 1,
|
|
totalSteps: 1,
|
|
stepName: 'repair_board_data',
|
|
stepProgress: 20,
|
|
stepStatus: 'running',
|
|
stepDetails: {
|
|
lists: res.listsUnbound,
|
|
cards: res.cardsAssigned + res.cardsRescued,
|
|
},
|
|
boardId,
|
|
});
|
|
Meteor.call('repairBoardData', boardId, (err2) => {
|
|
if (err2) {
|
|
this._listRepairChecked.delete(boardId); // allow a retry
|
|
migrationProgressManager.failMigration(err2);
|
|
return;
|
|
}
|
|
migrationProgressManager.completeMigration();
|
|
});
|
|
});
|
|
};
|
|
|
|
// Ensure a board has at least one swimlane. Guarded to run once per board and
|
|
// fire-and-forget so it never blocks rendering. The board is marked
|
|
// immediately to avoid duplicate concurrent calls, and the mark is rolled
|
|
// back on failure so a later attempt can retry.
|
|
this.ensureDefaultSwimlane = async (boardId) => {
|
|
if (this._swimlaneCreated.has(boardId)) {
|
|
return;
|
|
}
|
|
this._swimlaneCreated.add(boardId);
|
|
try {
|
|
const board = ReactiveCache.getBoard(boardId);
|
|
if (!board) {
|
|
this._swimlaneCreated.delete(boardId);
|
|
return;
|
|
}
|
|
if (board.swimlanes().length === 0) {
|
|
const swimlaneId = await Meteor.callAsync('ensureDefaultSwimlane', boardId);
|
|
if (process.env.DEBUG === 'true' && swimlaneId) {
|
|
console.log(
|
|
`Ensured default swimlane ${swimlaneId} for board ${boardId}`,
|
|
);
|
|
}
|
|
}
|
|
} catch (error) {
|
|
this._swimlaneCreated.delete(boardId); // allow a later retry
|
|
console.error('Error creating default swimlane:', error);
|
|
}
|
|
};
|
|
|
|
// Single reactive computation that subscribes to the current board and tracks
|
|
// its ready state in one place. Previously a Tracker.autorun was created
|
|
// *inside* this autorun on every re-run without being stopped, leaking
|
|
// computations that raced on shared ready-state flags. When navigating
|
|
// between boards — e.g. opening a freshly created board — that race could
|
|
// leave swimlanes/lists unrendered until the board was re-selected. A single
|
|
// self-managed autorun (auto-stopped by Blaze on destroy) avoids both the
|
|
// leak and the race.
|
|
// Pattern: https://kadira.io/academy/meteor-routing-guide/content/subscriptions-and-data-management/using-subs-manager
|
|
this.autorun(() => {
|
|
const currentBoardId = Session.get('currentBoard');
|
|
// Creating a linked card changes the set of source cards, boards and field
|
|
// definitions that the composite publication must expose. Reading this
|
|
// generation lets the link dialog restart the subscription immediately;
|
|
// otherwise those child cursors are only recalculated after a page reload.
|
|
const subscriptionGeneration =
|
|
Session.get('boardSubscriptionGeneration') || 0;
|
|
// A same-board refresh must not tear down boardBody and its open card
|
|
// windows. Date saves refresh this publication to pick up stored values;
|
|
// toggling readiness off recreates each window at its default dock before
|
|
// anchoring it again. A different board still starts behind the spinner.
|
|
if (this.subscriptionBoardId !== currentBoardId) {
|
|
this.subscriptionBoardId = currentBoardId;
|
|
this.isBoardReady.set(false);
|
|
this.boardLoadError.set(false);
|
|
}
|
|
if (!currentBoardId) return;
|
|
|
|
const handle = Meteor.subscribe(
|
|
'board',
|
|
currentBoardId,
|
|
false,
|
|
subscriptionGeneration,
|
|
{
|
|
onStop: (error) => {
|
|
if (error && this.subscriptionBoardId === currentBoardId) {
|
|
console.error('[board] the board publication stopped:', error.reason || error.message || error.error);
|
|
this.boardLoadError.set(true);
|
|
}
|
|
},
|
|
},
|
|
);
|
|
// Learn this board's card-loading mode (lazy vs eager) so 'auto' can decide
|
|
// per board by size; the flag drives isLazyCards(boardId). #6480.
|
|
Meteor.subscribe('boardCardsLoadingMode', currentBoardId);
|
|
const ready = handle.ready();
|
|
if (ready) this.isBoardReady.set(true);
|
|
|
|
if (ready) {
|
|
// Run outside the computation so this autorun depends only on the board
|
|
// id and the subscription's ready state — not on the swimlane data that
|
|
// ensureDefaultSwimlane reads — which would otherwise cause extra re-runs.
|
|
Tracker.nonreactive(() => this.ensureDefaultSwimlane(currentBoardId));
|
|
// Also detect + run the shared board data-repairs once the board is ready.
|
|
Tracker.nonreactive(() => this.maybeRepairBoard(currentBoardId));
|
|
// #4540: apply any ?assignee=/?member=/?label= URL filter params now
|
|
// that the board and its members/labels are loaded.
|
|
Tracker.nonreactive(() => this.applyQueryParamFilters(currentBoardId));
|
|
}
|
|
});
|
|
|
|
// #319: keep the URL's ?assignee=/?member=/?label= in sync with the
|
|
// sidebar's Filter state as the user changes it, so a manually filtered
|
|
// board is bookmarkable/shareable - the write direction of #4540's
|
|
// read-on-load support. A separate autorun (rather than folding this into
|
|
// the subscription one above) so it reruns on every filter change without
|
|
// resubscribing to the board.
|
|
this.autorun(() => {
|
|
const currentBoardId = Session.get('currentBoard');
|
|
if (!currentBoardId || !this.isBoardReady.get()) {
|
|
return;
|
|
}
|
|
this.syncFilterQueryParams(currentBoardId);
|
|
});
|
|
});
|
|
|
|
Template.board.helpers({
|
|
onlyShowCurrentCard() {
|
|
const isMiniScreen = Utils.isMiniScreen();
|
|
const currentCardId = Utils.getCurrentCardId(true);
|
|
return isMiniScreen && currentCardId;
|
|
},
|
|
|
|
openCards() {
|
|
// In desktop mode, return array of all open cards
|
|
const isMobile = Utils.getMobileMode();
|
|
if (!isMobile) {
|
|
const openCardIds = Session.get('openCards') || [];
|
|
return openCardIds
|
|
.map((id) => ReactiveCache.getCard(id))
|
|
.filter((card) => card);
|
|
}
|
|
return [];
|
|
},
|
|
|
|
goHome() {
|
|
FlowRouter.go('home');
|
|
},
|
|
|
|
isConverting() {
|
|
return Template.instance().isConverting.get();
|
|
},
|
|
|
|
boardLoadError() {
|
|
return Template.instance().boardLoadError.get();
|
|
},
|
|
isBoardReady() {
|
|
return Template.instance().isBoardReady.get();
|
|
},
|
|
|
|
currentBoard() {
|
|
return Utils.getCurrentBoard();
|
|
},
|
|
});
|
|
|
|
Template.boardBody.onCreated(function () {
|
|
Meteor.subscribe('tableVisibilityModeSettings');
|
|
Meteor.subscribe('inviteToBoardRolesSettings');
|
|
this.showOverlay = new ReactiveVar(false);
|
|
this.draggingActive = new ReactiveVar(false);
|
|
this._isDragging = false;
|
|
// Used to set the overlay
|
|
this.mouseHasEnterCardDetails = false;
|
|
this._sortFieldsFixed = new Set(); // Track which boards have had sort fields fixed
|
|
|
|
// Store global reference for external access (swimlanes, cardDetails, etc.)
|
|
BoardBody = this;
|
|
|
|
// Remember this visit, once per board per page load, for Board menu ->
|
|
// Since your last visit (client/lib/boardVisits.js).
|
|
this.autorun(() => {
|
|
markBoardVisited(Session.get('currentBoard'));
|
|
});
|
|
|
|
// Methods on the template instance for programmatic access
|
|
this.setIsDragging = (bool) => {
|
|
this.draggingActive.set(bool);
|
|
};
|
|
|
|
this.scrollLeft = (position = 0) => {
|
|
const swimlanes = this.$('.js-swimlanes');
|
|
swimlanes &&
|
|
swimlanes.animate({
|
|
scrollLeft: position,
|
|
});
|
|
};
|
|
|
|
this.scrollTop = (position = 0) => {
|
|
const swimlanes = this.$('.js-swimlanes');
|
|
swimlanes &&
|
|
swimlanes.animate({
|
|
scrollTop: position,
|
|
});
|
|
};
|
|
|
|
this.isViewSwimlanes = () => {
|
|
return Utils.boardView() === 'board-view-swimlanes';
|
|
};
|
|
|
|
this.isViewLists = () => {
|
|
return Utils.boardView() === 'board-view-lists';
|
|
};
|
|
|
|
// fix swimlanes sort field if there are null values
|
|
const currentBoardData = Utils.getCurrentBoard();
|
|
if (currentBoardData && Swimlanes) {
|
|
const boardId = currentBoardData._id;
|
|
// Only fix sort fields once per board to prevent reactive loops
|
|
if (!this._sortFieldsFixed.has(`swimlanes-${boardId}`)) {
|
|
const nullSortSwimlanes = currentBoardData.nullSortSwimlanes();
|
|
if (nullSortSwimlanes.length > 0) {
|
|
const swimlanes = currentBoardData.swimlanes();
|
|
let count = 0;
|
|
swimlanes.forEach((s) => {
|
|
Swimlanes.update(s._id, {
|
|
$set: {
|
|
sort: count,
|
|
},
|
|
});
|
|
count += 1;
|
|
});
|
|
}
|
|
this._sortFieldsFixed.add(`swimlanes-${boardId}`);
|
|
}
|
|
}
|
|
|
|
// fix lists sort field if there are null values
|
|
if (currentBoardData && Lists) {
|
|
const boardId = currentBoardData._id;
|
|
// Only fix sort fields once per board to prevent reactive loops
|
|
if (!this._sortFieldsFixed.has(`lists-${boardId}`)) {
|
|
const nullSortLists = currentBoardData.nullSortLists();
|
|
if (nullSortLists.length > 0) {
|
|
const lists = currentBoardData.lists();
|
|
let count = 0;
|
|
lists.forEach((l) => {
|
|
Lists.update(l._id, {
|
|
$set: {
|
|
sort: count,
|
|
},
|
|
});
|
|
count += 1;
|
|
});
|
|
}
|
|
this._sortFieldsFixed.add(`lists-${boardId}`);
|
|
}
|
|
}
|
|
});
|
|
|
|
Template.boardBody.onRendered(function () {
|
|
// Initialize user settings (zoom and mobile mode)
|
|
Utils.initializeUserSettings();
|
|
|
|
// A link to a swimlane or a list has to end with that thing on screen. The
|
|
// route can only NAME it - it runs before this has rendered - so the reveal
|
|
// waits here for the element to exist. client/lib/revealBoardItem.js
|
|
this.boardItemReveals = watchBoardItemReveals();
|
|
|
|
// Detect iPhone devices and add class for better CSS targeting
|
|
const isIPhone = /iPhone|iPod/.test(navigator.userAgent);
|
|
if (isIPhone) {
|
|
document.body.classList.add('iphone-device');
|
|
}
|
|
|
|
// Popups and modals use their shared focus lifecycle. Board-only menus that
|
|
// are inserted outside that lifecycle still need their first control focused.
|
|
this._accessibilityMenuObserver = new MutationObserver(function (mutations) {
|
|
mutations.forEach(function (mutation) {
|
|
mutation.addedNodes.forEach(function (node) {
|
|
if (
|
|
node.nodeType === 1 &&
|
|
node.classList.contains('menu') &&
|
|
!node.closest('.js-swimlanes') &&
|
|
!node.closest('.swimlane') &&
|
|
!node.closest('.list') &&
|
|
!node.closest('.minicard')
|
|
) {
|
|
setTimeout(function () {
|
|
focusFirstControl(node);
|
|
}, 10);
|
|
}
|
|
});
|
|
});
|
|
});
|
|
this._accessibilityMenuObserver.observe(document.body, { childList: true, subtree: true });
|
|
|
|
// Remove tabindex from non-interactive elements (e.g., user abbreviations, labels)
|
|
document
|
|
.querySelectorAll(
|
|
'.user-abbreviation, .user-label, .card-header-label, .edit-label, .private-label',
|
|
)
|
|
.forEach(function (el) {
|
|
if (el.hasAttribute('tabindex')) {
|
|
el.removeAttribute('tabindex');
|
|
}
|
|
});
|
|
/*
|
|
// Add a toggle button for keyboard shortcuts accessibility
|
|
if (!document.getElementById('wekan-shortcuts-toggle')) {
|
|
const toggleContainer = document.createElement('div');
|
|
toggleContainer.id = 'wekan-shortcuts-toggle';
|
|
toggleContainer.style.position = 'fixed';
|
|
toggleContainer.style.top = '10px';
|
|
toggleContainer.style.right = '10px';
|
|
toggleContainer.style.zIndex = '1000';
|
|
toggleContainer.style.background = '#fff';
|
|
toggleContainer.style.border = '2px solid #005fcc';
|
|
toggleContainer.style.borderRadius = '6px';
|
|
toggleContainer.style.padding = '8px 12px';
|
|
toggleContainer.style.boxShadow = '0 2px 8px rgba(0,0,0,0.1)';
|
|
toggleContainer.style.fontSize = '16px';
|
|
toggleContainer.style.color = '#005fcc';
|
|
toggleContainer.setAttribute('role', 'region');
|
|
toggleContainer.setAttribute('aria-label', 'Keyboard Shortcuts Settings');
|
|
toggleContainer.innerHTML = `
|
|
<label for="shortcuts-toggle-checkbox" style="cursor:pointer;">
|
|
<input type="checkbox" id="shortcuts-toggle-checkbox" ${window.wekanShortcutsEnabled ? 'checked' : ''} style="margin-right:8px;" />
|
|
Enable keyboard shortcuts
|
|
</label>
|
|
`;
|
|
document.body.appendChild(toggleContainer);
|
|
const checkbox = document.getElementById('shortcuts-toggle-checkbox');
|
|
checkbox.addEventListener('change', function(e) {
|
|
window.toggleWekanShortcuts(e.target.checked);
|
|
});
|
|
}
|
|
*/
|
|
// Ensure toggle-buttons, color choices, reactions, renaming, and calendar controls are focusable and have ARIA roles
|
|
document.querySelectorAll('.js-toggle').forEach(function (el) {
|
|
el.setAttribute('tabindex', '0');
|
|
el.setAttribute('role', 'button');
|
|
// Short, descriptive label for favorite/star toggle
|
|
if (el.classList.contains('js-favorite-toggle')) {
|
|
el.setAttribute('aria-label', `${TAPi18n.__('star-item')} / ${TAPi18n.__('unstar-item')}`);
|
|
} else {
|
|
el.setAttribute('aria-label', 'Toggle');
|
|
}
|
|
});
|
|
document.querySelectorAll('.js-color-choice').forEach(function (el) {
|
|
el.setAttribute('tabindex', '0');
|
|
el.setAttribute('role', 'button');
|
|
el.setAttribute('aria-label', 'Choose color');
|
|
});
|
|
document.querySelectorAll('.js-reaction').forEach(function (el) {
|
|
el.setAttribute('tabindex', '0');
|
|
el.setAttribute('role', 'button');
|
|
el.setAttribute('aria-label', 'React');
|
|
});
|
|
document.querySelectorAll('.js-rename-swimlane').forEach(function (el) {
|
|
el.setAttribute('tabindex', '0');
|
|
el.setAttribute('role', 'button');
|
|
el.setAttribute('aria-label', 'Rename swimlane');
|
|
});
|
|
document.querySelectorAll('.js-rename-list').forEach(function (el) {
|
|
el.setAttribute('tabindex', '0');
|
|
el.setAttribute('role', 'button');
|
|
el.setAttribute('aria-label', 'Rename list');
|
|
});
|
|
document.querySelectorAll('.fc-button').forEach(function (el) {
|
|
el.setAttribute('tabindex', '0');
|
|
el.setAttribute('role', 'button');
|
|
});
|
|
// Set the language and direction attributes on the <html> element for
|
|
// accessibility and RTL layout.
|
|
document.documentElement.lang = TAPi18n.getLanguage();
|
|
document.documentElement.dir = TAPi18n.getLanguageDirection();
|
|
|
|
// Ensure the accessible name for the board view switcher matches the visible label "Swimlanes"
|
|
// This fixes WCAG 2.5.3: Label in Name
|
|
const swimlanesSwitcher = this.$('.js-board-view-swimlanes');
|
|
if (swimlanesSwitcher.length) {
|
|
swimlanesSwitcher.attr(
|
|
'aria-label',
|
|
swimlanesSwitcher.text().trim() || 'Swimlanes',
|
|
);
|
|
}
|
|
|
|
// Add a highly visible focus indicator and improve contrast for interactive elements
|
|
if (!document.getElementById('wekan-accessible-focus-style')) {
|
|
const style = document.createElement('style');
|
|
style.id = 'wekan-accessible-focus-style';
|
|
style.innerHTML = `
|
|
/* Focus indicator */
|
|
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 {
|
|
outline: 3px solid #005fcc !important;
|
|
outline-offset: 2px !important;
|
|
}
|
|
/* Input borders */
|
|
input, textarea, select {
|
|
border: 2px solid #222 !important;
|
|
}
|
|
/* Plus icon for adding a new card */
|
|
.js-add-card {
|
|
color: #005fcc !important; /* dark blue for contrast */
|
|
cursor: pointer;
|
|
outline: none;
|
|
}
|
|
.js-add-card[tabindex] {
|
|
outline: none;
|
|
}
|
|
/* Sidebar hamburger menu button in header. Renamed with the button when
|
|
it moved to the first top header bar: docs/Features/Header-Bar/Header.md */
|
|
.js-toggle-page-sidebar .fa-bars {
|
|
color: #fff !important;
|
|
}
|
|
/* Grey icons in card detail header */
|
|
.card-detail-header .fa, .card-detail-header .icon {
|
|
color: #444 !important;
|
|
}
|
|
/* Grey operating elements in card detail */
|
|
.card-detail .fa, .card-detail .icon {
|
|
color: #444 !important;
|
|
}
|
|
/* Blue bar in checklists */
|
|
.checklist-progress-bar {
|
|
background-color: #005fcc !important;
|
|
}
|
|
/* Green checkmark in checklists */
|
|
.checklist .fa-check {
|
|
color: #007a33 !important;
|
|
}
|
|
/* X-Button and arrow button in menus */
|
|
.close, .fa-arrow-left, .icon-arrow-left {
|
|
color: #005fcc !important;
|
|
}
|
|
/* Cross icon to move boards */
|
|
.js-move-board {
|
|
color: #005fcc !important;
|
|
}
|
|
/* Current date background */
|
|
.current-date {
|
|
background-color: #005fcc !important;
|
|
color: #fff !important;
|
|
}
|
|
`;
|
|
document.head.appendChild(style);
|
|
}
|
|
// Ensure plus/add elements are focusable and have ARIA roles
|
|
document.querySelectorAll('.js-add-card').forEach(function (el) {
|
|
el.setAttribute('tabindex', '0');
|
|
el.setAttribute('role', 'button');
|
|
el.setAttribute('aria-label', 'Add new card');
|
|
});
|
|
|
|
const tpl = this;
|
|
const $swimlanesDom = tpl.$('.js-swimlanes');
|
|
|
|
$swimlanesDom.sortable({
|
|
tolerance: 'pointer',
|
|
appendTo: '.board-canvas',
|
|
helper(evt, item) {
|
|
const helper = $(`<div class="swimlane"
|
|
style="flex-direction: column;
|
|
height: ${swimlaneWhileSortingHeight}px;
|
|
width: $(tpl.width)px;
|
|
overflow: hidden;"/>`);
|
|
helper.append(item.clone());
|
|
// Also grab the list of lists of cards
|
|
const list = item.next();
|
|
helper.append(list.clone());
|
|
return helper;
|
|
},
|
|
items: '.swimlane:not(.placeholder)',
|
|
placeholder: 'swimlane placeholder',
|
|
distance: 7,
|
|
start(evt, ui) {
|
|
const listDom = ui.placeholder.next('.js-swimlane');
|
|
const parentOffset = ui.item.parent().offset();
|
|
|
|
ui.placeholder.height(ui.helper.height());
|
|
EscapeActions.executeUpTo('popup-close');
|
|
listDom.addClass('moving-swimlane');
|
|
tpl.setIsDragging(true);
|
|
suspendBoardDragscroll(); // #6558
|
|
|
|
ui.placeholder.insertAfter(ui.placeholder.next());
|
|
tpl.origPlaceholderIndex = ui.placeholder.index();
|
|
|
|
// resize all swimlanes + headers to be a total of 150 px per row
|
|
// this could be achieved by setIsDragging(true) but we want immediate
|
|
// result
|
|
ui.item
|
|
.siblings('.js-swimlane')
|
|
.css('height', `${swimlaneWhileSortingHeight - 26}px`);
|
|
|
|
// set the new scroll height after the resize and insertion of
|
|
// the placeholder. We want the element under the cursor to stay
|
|
// at the same place on the screen
|
|
ui.item.parent().get(0).scrollTop =
|
|
ui.placeholder.get(0).offsetTop + parentOffset.top - evt.pageY;
|
|
},
|
|
beforeStop(evt, ui) {
|
|
const parentOffset = ui.item.parent().offset();
|
|
const siblings = ui.item.siblings('.js-swimlane');
|
|
siblings.css('height', '');
|
|
|
|
// compute the new scroll height after the resize and removal of
|
|
// the placeholder
|
|
const scrollTop =
|
|
ui.placeholder.get(0).offsetTop + parentOffset.top - evt.pageY;
|
|
|
|
// then reset the original view of the swimlane
|
|
siblings.removeClass('moving-swimlane');
|
|
|
|
// and apply the computed scrollheight
|
|
ui.item.parent().get(0).scrollTop = scrollTop;
|
|
},
|
|
stop(evt, ui) {
|
|
// To attribute the new index number, we need to get the DOM element
|
|
// of the previous and the following card -- if any.
|
|
const prevSwimlaneDom = ui.item.prevAll('.js-swimlane').get(0);
|
|
const nextSwimlaneDom = ui.item.nextAll('.js-swimlane').get(0);
|
|
const sortIndex = calculateIndex(prevSwimlaneDom, nextSwimlaneDom, 1);
|
|
|
|
resumeBoardDragscroll(); // #6558
|
|
$swimlanesDom.sortable('cancel');
|
|
const swimlaneDomElement = ui.item.get(0);
|
|
const swimlane = Blaze.getData(swimlaneDomElement);
|
|
|
|
Swimlanes.update(swimlane._id, {
|
|
$set: {
|
|
sort: sortIndex.base,
|
|
},
|
|
});
|
|
|
|
tpl.setIsDragging(false);
|
|
},
|
|
sort(evt, ui) {
|
|
// get the mouse position in the sortable
|
|
const parentOffset = ui.item.parent().offset();
|
|
const cursorY =
|
|
evt.pageY - parentOffset.top + ui.item.parent().scrollTop();
|
|
|
|
// compute the intended index of the placeholder (we need to skip the
|
|
// slots between the headers and the list of cards)
|
|
const newplaceholderIndex = Math.floor(
|
|
cursorY / swimlaneWhileSortingHeight,
|
|
);
|
|
let destPlaceholderIndex = (newplaceholderIndex + 1) * 2;
|
|
|
|
// if we are scrolling far away from the bottom of the list
|
|
if (destPlaceholderIndex >= ui.item.parent().get(0).childElementCount) {
|
|
destPlaceholderIndex = ui.item.parent().get(0).childElementCount - 1;
|
|
}
|
|
|
|
// update the placeholder position in the DOM tree
|
|
if (destPlaceholderIndex !== ui.placeholder.index()) {
|
|
if (destPlaceholderIndex < tpl.origPlaceholderIndex) {
|
|
ui.placeholder.insertBefore(
|
|
ui.placeholder
|
|
.siblings()
|
|
.slice(destPlaceholderIndex - 2, destPlaceholderIndex - 1),
|
|
);
|
|
} else {
|
|
ui.placeholder.insertAfter(
|
|
ui.placeholder
|
|
.siblings()
|
|
.slice(destPlaceholderIndex - 1, destPlaceholderIndex),
|
|
);
|
|
}
|
|
}
|
|
},
|
|
});
|
|
|
|
this.autorun(() => {
|
|
// Re-attach mouse dragscroll whenever the set of rendered `.dragscroll`
|
|
// containers can change. The @wekanteam/dragscroll mouse handler is attached
|
|
// PER element inside reset(), so it must be re-run after the DOM changes;
|
|
// only dragscrollTouch (delegated on `document`) covers reactively-added
|
|
// nodes, and that is touch-only. Previously this autorun's only reactive deps
|
|
// were the touch/permission reads below, so mouse drag-scrolling stayed dead
|
|
// when swimlanes/lists rendered AFTER onRendered — adaptive lazy card loading
|
|
// (#6480), the on-open data-repair adding a default swimlane (#6484), or a
|
|
// board switch that reuses this template instance without re-firing onRendered
|
|
// (see the #4978 note below) — leaving lower swimlanes unreachable by drag on
|
|
// touchpad/mouse. Reading the board view + swimlanes + lists here establishes
|
|
// those dependencies so reset() re-runs when the containers change. None of
|
|
// these reads write to the DB, so there is no autorun write loop.
|
|
const dragscrollBoard = Utils.getCurrentBoard();
|
|
if (dragscrollBoard) {
|
|
Utils.boardView();
|
|
dragscrollBoard.swimlanes();
|
|
dragscrollBoard.draggableLists();
|
|
}
|
|
resetBoardDragscroll();
|
|
|
|
if ($swimlanesDom.data('uiSortable') || $swimlanesDom.data('sortable')) {
|
|
|
|
// #6446: enable swimlane drag-drop — which also carries moving cards BETWEEN
|
|
// swimlanes — for any board member with write access, not only board admins.
|
|
// The old !isBoardAdmin() check disabled this sortable for every non-admin, so
|
|
// a normal member could still move a card WITHIN a swimlane but not BETWEEN
|
|
// swimlanes (a card crossing swimlanes is received across this sortable), and
|
|
// could not reorder swimlanes. Write access to the BOARD is the test
|
|
// (board member, not comment-only / worker / read-only), matching the
|
|
// server's allowIsBoardMemberWithWriteAccess.
|
|
//
|
|
// #6745: canModifyBoard(), not canModifyCard() with no argument - that one
|
|
// reads the OPEN card, so this whole autorun (dragscroll reset and all)
|
|
// re-ran on every card open and close. And only the options that changed.
|
|
setSortableOptions($swimlanesDom, {
|
|
handle: Utils.isTouchScreenOrShowDesktopDragHandles()
|
|
? '.js-swimlane-header-handle'
|
|
: '.swimlane-header',
|
|
items: Utils.canDragBoardObject('swimlane') ? '.swimlane:not(.placeholder)' : '.no-draggable-swimlanes',
|
|
disabled: !Utils.canModifyBoard(),
|
|
});
|
|
}
|
|
});
|
|
|
|
resetBoardDragscroll();
|
|
// #4978: apply the board background inside a reactive autorun instead of a
|
|
// one-shot call. Switching directly between boards (e.g. the favorites bar)
|
|
// reuses this template instance and never re-fires onRendered, so the
|
|
// background used to stay on the previously shown board. Reading the current
|
|
// board inside setBackgroundImage() tracks both board switches and background
|
|
// edits; it performs no DB writes, so there is no autorun write loop.
|
|
this.autorun(() => {
|
|
Utils.setBackgroundImage();
|
|
});
|
|
});
|
|
|
|
Template.boardBody.onDestroyed(function () {
|
|
this._accessibilityMenuObserver?.disconnect();
|
|
this._accessibilityMenuObserver = null;
|
|
// The reveal watcher owns a Tracker computation and a retry interval, and
|
|
// neither stops on its own when this template goes.
|
|
if (this.boardItemReveals) {
|
|
this.boardItemReveals.stop();
|
|
this.boardItemReveals = null;
|
|
}
|
|
if (BoardBody === this) {
|
|
BoardBody = null;
|
|
}
|
|
});
|
|
|
|
Template.boardBody.helpers({
|
|
openCards() {
|
|
const isMobile = Utils.getMobileMode();
|
|
if (!isMobile) {
|
|
const openCardIds = Session.get('openCards') || [];
|
|
return openCardIds
|
|
.map((id) => ReactiveCache.getCard(id))
|
|
.filter((card) => card);
|
|
}
|
|
return [];
|
|
},
|
|
|
|
draggingActive() {
|
|
return Template.instance().draggingActive.get();
|
|
},
|
|
showOverlay() {
|
|
return Template.instance().showOverlay.get();
|
|
},
|
|
notDisplayThisBoard() {
|
|
let allowPrivateVisibilityOnly = TableVisibilityModeSettings.findOne(
|
|
'tableVisibilityMode-allowPrivateOnly',
|
|
);
|
|
let currentBoard = Utils.getCurrentBoard();
|
|
return (
|
|
allowPrivateVisibilityOnly !== undefined &&
|
|
allowPrivateVisibilityOnly.booleanValue &&
|
|
currentBoard &&
|
|
// #3249: an 'instance' board is not private either.
|
|
(currentBoard.permission === 'public' || currentBoard.permission === 'instance')
|
|
);
|
|
},
|
|
|
|
isViewSwimlanes() {
|
|
return Utils.boardView() === 'board-view-swimlanes';
|
|
},
|
|
|
|
isViewLists() {
|
|
return Utils.boardView() === 'board-view-lists';
|
|
},
|
|
|
|
isViewCalendar() {
|
|
return Utils.boardView() === 'board-view-cal';
|
|
},
|
|
isViewCalendarMode() {
|
|
return Utils.boardView() === 'board-view-calendar-mode';
|
|
},
|
|
|
|
isViewMultiboardCalendar() {
|
|
return Utils.boardView() === 'board-view-multiboard-cal';
|
|
},
|
|
|
|
isViewGantt() {
|
|
return Utils.boardView() === 'board-view-gantt';
|
|
},
|
|
|
|
isViewGanttFrappe() {
|
|
return Utils.boardView() === 'board-view-gantt-frappe';
|
|
},
|
|
|
|
isViewGanttDhtmlx() {
|
|
return Utils.boardView() === 'board-view-gantt-dhtmlx';
|
|
},
|
|
|
|
isViewTable() {
|
|
return Utils.boardView() === 'board-view-table';
|
|
},
|
|
|
|
isViewStats() {
|
|
return Utils.boardView() === 'board-view-stats';
|
|
},
|
|
|
|
isViewTime() {
|
|
return Utils.boardView() === 'board-view-time';
|
|
},
|
|
|
|
isViewTimeline() {
|
|
return Utils.boardView() === 'board-view-timeline';
|
|
},
|
|
|
|
isViewGroupByAssignee() {
|
|
return Utils.boardView() === 'board-view-group-by-assignee';
|
|
},
|
|
|
|
isViewRoadmap() {
|
|
return Utils.boardView() === 'board-view-roadmap';
|
|
},
|
|
|
|
isViewDashboard() {
|
|
return Utils.boardView() === 'board-view-dashboard';
|
|
},
|
|
|
|
isViewBigboard() {
|
|
return Utils.boardView() === 'board-view-bigboard';
|
|
},
|
|
|
|
isViewBurndown() {
|
|
return Utils.boardView() === 'board-view-burndown';
|
|
},
|
|
|
|
isViewBurnup() {
|
|
return Utils.boardView() === 'board-view-burnup';
|
|
},
|
|
|
|
isViewCumulativeFlow() {
|
|
return Utils.boardView() === 'board-view-cumulative-flow';
|
|
},
|
|
|
|
isViewControlChart() {
|
|
return Utils.boardView() === 'board-view-control-chart';
|
|
},
|
|
|
|
isViewCycleTime() {
|
|
return Utils.boardView() === 'board-view-cycle-time';
|
|
},
|
|
|
|
isViewFlowEfficiency() {
|
|
return Utils.boardView() === 'board-view-flow-efficiency';
|
|
},
|
|
|
|
isViewLeadTime() {
|
|
return Utils.boardView() === 'board-view-lead-time';
|
|
},
|
|
|
|
isViewThroughputHistogram() {
|
|
return Utils.boardView() === 'board-view-throughput-histogram';
|
|
},
|
|
|
|
isViewWipRun() {
|
|
return Utils.boardView() === 'board-view-wip-run';
|
|
},
|
|
|
|
isViewScrum() {
|
|
return ['board-view-product-backlog', 'board-view-sprints', 'board-view-sprint-report', 'board-view-velocity'].includes(Utils.boardView());
|
|
},
|
|
|
|
isViewAgingWip() {
|
|
return Utils.boardView() === 'board-view-aging-wip';
|
|
},
|
|
|
|
isViewBlockerAnalysis() {
|
|
return Utils.boardView() === 'board-view-blocker-analysis';
|
|
},
|
|
|
|
isViewMonteCarlo() {
|
|
return Utils.boardView() === 'board-view-monte-carlo';
|
|
},
|
|
|
|
isViewProcessBehavior() {
|
|
return Utils.boardView() === 'board-view-process-behavior';
|
|
},
|
|
|
|
isViewSizeCycleTime() {
|
|
return Utils.boardView() === 'board-view-size-cycle-time';
|
|
},
|
|
|
|
// The reports of 2026-11-20 (models/lib/boardReports.js).
|
|
isViewCreatedResolved() {
|
|
return Utils.boardView() === 'board-view-created-resolved';
|
|
},
|
|
|
|
isViewNetFlow() {
|
|
return Utils.boardView() === 'board-view-net-flow';
|
|
},
|
|
|
|
isViewTimeInList() {
|
|
return Utils.boardView() === 'board-view-time-in-list';
|
|
},
|
|
|
|
isViewAverageAge() {
|
|
return Utils.boardView() === 'board-view-average-age';
|
|
},
|
|
|
|
isViewThroughputRun() {
|
|
return Utils.boardView() === 'board-view-throughput-run';
|
|
},
|
|
|
|
isViewDueDatePerformance() {
|
|
return Utils.boardView() === 'board-view-due-date-performance';
|
|
},
|
|
|
|
isViewReleaseBurndown() {
|
|
return Utils.boardView() === 'board-view-release-burndown';
|
|
},
|
|
|
|
isViewEpicProgress() {
|
|
return Utils.boardView() === 'board-view-epic-progress';
|
|
},
|
|
|
|
isViewWorkload() {
|
|
return Utils.boardView() === 'board-view-workload';
|
|
},
|
|
|
|
isViewDistribution() {
|
|
return Utils.boardView() === 'board-view-distribution';
|
|
},
|
|
|
|
isViewDependencyMap() {
|
|
return Utils.boardView() === 'board-view-dependency-map';
|
|
},
|
|
|
|
isViewActivityHeatmap() {
|
|
return Utils.boardView() === 'board-view-activity-heatmap';
|
|
},
|
|
|
|
isViewMap() {
|
|
return Utils.boardView() === 'board-view-map';
|
|
},
|
|
isViewEmail() {
|
|
return Utils.boardView() === 'board-view-email';
|
|
},
|
|
isViewChat() {
|
|
return Utils.boardView() === 'board-view-chat';
|
|
},
|
|
isViewColumnSets() {
|
|
return Utils.boardView() === 'board-view-column-sets';
|
|
},
|
|
isViewVersionControl() {
|
|
return Utils.boardView() === 'board-view-version-control';
|
|
},
|
|
|
|
isViewPulse() {
|
|
return Utils.boardView() === 'board-view-pulse';
|
|
},
|
|
|
|
hasSwimlanes() {
|
|
const currentBoard = Utils.getCurrentBoard();
|
|
if (!currentBoard) {
|
|
if (process.env.DEBUG === 'true') {
|
|
console.log('hasSwimlanes: No current board');
|
|
}
|
|
return false;
|
|
}
|
|
|
|
try {
|
|
const swimlanes = currentBoard.swimlanes();
|
|
const hasSwimlanes = swimlanes && swimlanes.length > 0;
|
|
if (process.env.DEBUG === 'true') {
|
|
console.log(
|
|
'hasSwimlanes: Board has',
|
|
swimlanes ? swimlanes.length : 0,
|
|
'swimlanes',
|
|
);
|
|
}
|
|
return hasSwimlanes;
|
|
} catch (error) {
|
|
console.error('hasSwimlanes: Error getting swimlanes:', error);
|
|
return false;
|
|
}
|
|
},
|
|
|
|
isVerticalScrollbars() {
|
|
const user = ReactiveCache.getCurrentUser();
|
|
return user && user.isVerticalScrollbars();
|
|
},
|
|
|
|
boardView() {
|
|
return Utils.boardView();
|
|
},
|
|
|
|
debugBoardState() {
|
|
// Enable debug mode by setting ?debug=1 in URL
|
|
const urlParams = new URLSearchParams(window.location.search);
|
|
return urlParams.get('debug') === '1';
|
|
},
|
|
|
|
debugBoardStateData() {
|
|
const currentBoard = Utils.getCurrentBoard();
|
|
const currentBoardId = Session.get('currentBoard');
|
|
const tpl = Template.instance();
|
|
const isBoardReady = tpl.isBoardReady.get();
|
|
const isConverting = tpl.isConverting.get();
|
|
const boardView = Utils.boardView();
|
|
|
|
if (process.env.DEBUG === 'true') {
|
|
console.log('=== BOARD DEBUG STATE ===');
|
|
console.log('currentBoardId:', currentBoardId);
|
|
console.log(
|
|
'currentBoard:',
|
|
!!currentBoard,
|
|
currentBoard ? currentBoard.title : 'none',
|
|
);
|
|
console.log('isBoardReady:', isBoardReady);
|
|
console.log('isConverting:', isConverting);
|
|
console.log('boardView:', boardView);
|
|
console.log('========================');
|
|
}
|
|
|
|
return {
|
|
currentBoardId,
|
|
hasCurrentBoard: !!currentBoard,
|
|
currentBoardTitle: currentBoard ? currentBoard.title : 'none',
|
|
isBoardReady,
|
|
isConverting,
|
|
boardView,
|
|
};
|
|
},
|
|
});
|
|
|
|
Template.boardBody.events({
|
|
// XXX The board-overlay div should probably be moved to the parent
|
|
// component.
|
|
mouseup(event, tpl) {
|
|
if (tpl._isDragging) {
|
|
tpl._isDragging = false;
|
|
}
|
|
},
|
|
'click .js-empty-board-add-swimlane': Popup.open('swimlaneAdd'),
|
|
// Global drag and drop file upload handlers for better visual feedback
|
|
'dragover .board-canvas'(event) {
|
|
const dataTransfer = event.originalEvent.dataTransfer;
|
|
if (
|
|
dataTransfer &&
|
|
dataTransfer.types &&
|
|
dataTransfer.types.includes('Files')
|
|
) {
|
|
event.preventDefault();
|
|
// Add visual indicator that files can be dropped
|
|
$('.board-canvas').addClass('file-drag-over');
|
|
}
|
|
},
|
|
'dragleave .board-canvas'(event) {
|
|
const dataTransfer = event.originalEvent.dataTransfer;
|
|
if (
|
|
dataTransfer &&
|
|
dataTransfer.types &&
|
|
dataTransfer.types.includes('Files')
|
|
) {
|
|
// Only remove class if we're leaving the board canvas entirely
|
|
if (!event.currentTarget.contains(event.relatedTarget)) {
|
|
$('.board-canvas').removeClass('file-drag-over');
|
|
}
|
|
}
|
|
},
|
|
'drop .board-canvas'(event) {
|
|
const dataTransfer = event.originalEvent.dataTransfer;
|
|
if (
|
|
dataTransfer &&
|
|
dataTransfer.types &&
|
|
dataTransfer.types.includes('Files')
|
|
) {
|
|
event.preventDefault();
|
|
$('.board-canvas').removeClass('file-drag-over');
|
|
}
|
|
},
|
|
});
|
|
|
|
// Accessibility: Allow users to enable/disable keyboard shortcuts
|
|
window.wekanShortcutsEnabled = true;
|
|
window.toggleWekanShortcuts = function (enabled) {
|
|
window.wekanShortcutsEnabled = !!enabled;
|
|
};
|
|
|
|
// Example: Wrap your character key shortcut handler like this
|
|
document.addEventListener('keydown', function (e) {
|
|
// Example: "W" key shortcut (replace with your actual shortcut logic)
|
|
if (!window.wekanShortcutsEnabled) return;
|
|
if (e.key === 'w' || e.key === 'W') {
|
|
// ...existing shortcut logic...
|
|
// e.g. open swimlanes view, etc.
|
|
}
|
|
});
|
|
|
|
// Keyboard accessibility for card actions (favorite, archive, duplicate, etc.)
|
|
document.addEventListener('keydown', function (e) {
|
|
if (!window.wekanShortcutsEnabled) return;
|
|
// Only proceed if focus is on a card action element
|
|
const active = document.activeElement;
|
|
if (active && active.classList.contains('js-card-action')) {
|
|
if (e.key === 'Enter' || e.key === ' ') {
|
|
e.preventDefault();
|
|
active.click();
|
|
}
|
|
// Move card up/down with arrow keys
|
|
if (e.key === 'ArrowUp') {
|
|
e.preventDefault();
|
|
if (active.dataset.cardId) {
|
|
Meteor.call('moveCardUp', active.dataset.cardId);
|
|
}
|
|
}
|
|
if (e.key === 'ArrowDown') {
|
|
e.preventDefault();
|
|
if (active.dataset.cardId) {
|
|
Meteor.call('moveCardDown', active.dataset.cardId);
|
|
}
|
|
}
|
|
}
|
|
// Make plus/add elements keyboard accessible
|
|
if (active && active.classList.contains('js-add-card')) {
|
|
if (e.key === 'Enter' || e.key === ' ') {
|
|
e.preventDefault();
|
|
active.click();
|
|
}
|
|
}
|
|
// Keyboard move for cards (alternative to drag & drop)
|
|
if (active && active.classList.contains('js-move-card')) {
|
|
if (e.key === 'ArrowUp') {
|
|
e.preventDefault();
|
|
if (active.dataset.cardId) {
|
|
Meteor.call('moveCardUp', active.dataset.cardId);
|
|
}
|
|
}
|
|
if (e.key === 'ArrowDown') {
|
|
e.preventDefault();
|
|
if (active.dataset.cardId) {
|
|
Meteor.call('moveCardDown', active.dataset.cardId);
|
|
}
|
|
}
|
|
}
|
|
// Ensure move card buttons are focusable and have ARIA roles
|
|
document.querySelectorAll('.js-move-card').forEach(function (el) {
|
|
el.setAttribute('tabindex', '0');
|
|
el.setAttribute('role', 'button');
|
|
el.setAttribute('aria-label', 'Move card');
|
|
});
|
|
// Make toggle-buttons, color choices, reactions, and X-buttons keyboard accessible
|
|
if (
|
|
active &&
|
|
(active.classList.contains('js-toggle') ||
|
|
active.classList.contains('js-color-choice') ||
|
|
active.classList.contains('js-reaction') ||
|
|
active.classList.contains('close'))
|
|
) {
|
|
if (e.key === 'Enter' || e.key === ' ') {
|
|
e.preventDefault();
|
|
active.click();
|
|
}
|
|
}
|
|
// Prevent scripts from removing focus when received
|
|
if (active) {
|
|
active.addEventListener(
|
|
'focus',
|
|
function (e) {
|
|
// Do not remove focus
|
|
// No-op: This prevents F55 failure
|
|
},
|
|
{ once: true },
|
|
);
|
|
}
|
|
// Make swimlane/list renaming keyboard accessible
|
|
if (
|
|
active &&
|
|
(active.classList.contains('js-rename-swimlane') ||
|
|
active.classList.contains('js-rename-list'))
|
|
) {
|
|
if (e.key === 'Enter') {
|
|
e.preventDefault();
|
|
active.click();
|
|
}
|
|
}
|
|
// Calendar navigation buttons
|
|
if (active && active.classList.contains('fc-button')) {
|
|
if (e.key === 'Enter' || e.key === ' ') {
|
|
e.preventDefault();
|
|
active.click();
|
|
}
|
|
}
|
|
});
|
|
|
|
Template.calendarView.onRendered(function () {
|
|
// Set the language and direction attributes on the <html> element for
|
|
// accessibility and RTL layout.
|
|
document.documentElement.lang = TAPi18n.getLanguage();
|
|
document.documentElement.dir = TAPi18n.getLanguageDirection();
|
|
|
|
this.autorun(function () {
|
|
// #5656: refetch calendar events whenever the active board Filter changes
|
|
// so the Calendar view stays in sync with the other views. Reading the
|
|
// Filter's reactive state here establishes the dependency; the events()
|
|
// callback below applies the actual selector.
|
|
Filter.isActive();
|
|
const calendarEl = document.getElementById('calendar-view');
|
|
if (calendarEl && calendarEl._wekanCalendar) {
|
|
calendarEl._wekanCalendar.refetchEvents();
|
|
}
|
|
});
|
|
});
|
|
|
|
Template.calendarView.helpers({
|
|
calendarOptions() {
|
|
// #5521: getStartDayOfWeek() returns a zero-based day index
|
|
// (0=Sunday..6=Saturday), the convention FullCalendar's firstDay uses;
|
|
// toFullCalendarFirstDay() validates it and falls back to Monday (1).
|
|
const currentUser = ReactiveCache.getCurrentUser();
|
|
const firstDay = toFullCalendarFirstDay(
|
|
currentUser ? currentUser.getStartDayOfWeek() : 1,
|
|
);
|
|
|
|
return {
|
|
...calendarBaseOptions({
|
|
id: 'calendar-view',
|
|
displayOptions: calendarDateDisplayOptions('calendar-view'),
|
|
firstDay,
|
|
weekNumberOf: weekNumberByFirstDay,
|
|
translate: key => TAPi18n.__(key),
|
|
locale: TAPi18n.getLanguage(),
|
|
rtl: TAPi18n.isRTL(),
|
|
}),
|
|
editable: true,
|
|
selectable: true,
|
|
/* TODO: lists as resources: https://fullcalendar.io/docs/vertical-resource-view */
|
|
navLinks: true,
|
|
businessHours: {
|
|
// days of week. an array of zero-based day of week integers (0=Sunday)
|
|
daysOfWeek: [1, 2, 3, 4, 5], // Monday - Friday
|
|
start: '8:00',
|
|
end: '18:00',
|
|
},
|
|
events(fetchInfo, callback) {
|
|
const currentBoard = Utils.getCurrentBoard();
|
|
// #5656: apply the active board Filter (member / assignee / due-date /
|
|
// label / custom-field) so the Calendar view shows the same scoped set
|
|
// of cards as the Board / Lists / Swimlanes views.
|
|
const filterSelector = Filter.isActive()
|
|
? Filter._getMongoSelector()
|
|
: undefined;
|
|
const events = [];
|
|
const pushEvent = function (card, title, start, end, extraCls) {
|
|
start = start || card.startAt;
|
|
end = end || card.endAt;
|
|
title = title || card.title;
|
|
const className =
|
|
(extraCls ? `${extraCls} ` : '') +
|
|
(card.color ? `calendar-event-${card.color}` : '');
|
|
events.push({
|
|
id: card._id,
|
|
title,
|
|
start,
|
|
end: end || card.endAt,
|
|
allDay:
|
|
Math.abs(end.getTime() - start.getTime()) / 1000 === 24 * 3600,
|
|
url: FlowRouter.path('card', {
|
|
boardId: currentBoard._id,
|
|
slug: currentBoard.slug,
|
|
cardId: card._id,
|
|
}),
|
|
className,
|
|
});
|
|
};
|
|
currentBoard
|
|
.cardsInInterval(fetchInfo.start, fetchInfo.end, filterSelector)
|
|
.forEach(function (card) {
|
|
pushEvent(card);
|
|
});
|
|
// #6712-adjacent: Received, Start, Due and End are all meant to be
|
|
// visible on the Calendar - the Start/End span above draws as one
|
|
// bar, but a card whose Start (or End) falls outside the visible
|
|
// range would otherwise show no marker for Received/End at all, and
|
|
// Due never had one. Received and End each get their own event the
|
|
// same way Due already does.
|
|
currentBoard
|
|
.cardsReceivedInBetween(fetchInfo.start, fetchInfo.end, filterSelector)
|
|
.forEach(function (card) {
|
|
pushEvent(
|
|
card,
|
|
`${card.title} ${TAPi18n.__('card-received')}`,
|
|
card.receivedAt,
|
|
new Date(card.receivedAt.getTime() + 36e5),
|
|
'calendar-event-received',
|
|
);
|
|
});
|
|
currentBoard
|
|
.cardsDueInBetween(fetchInfo.start, fetchInfo.end, filterSelector)
|
|
.forEach(function (card) {
|
|
pushEvent(
|
|
card,
|
|
`${card.title} ${TAPi18n.__('card-due')}`,
|
|
card.dueAt,
|
|
new Date(card.dueAt.getTime() + 36e5),
|
|
'calendar-event-due',
|
|
);
|
|
});
|
|
currentBoard
|
|
.cardsEndInBetween(fetchInfo.start, fetchInfo.end, filterSelector)
|
|
.forEach(function (card) {
|
|
pushEvent(
|
|
card,
|
|
`${card.title} ${TAPi18n.__('card-end')}`,
|
|
card.endAt,
|
|
new Date(card.endAt.getTime() + 36e5),
|
|
'calendar-event-end',
|
|
);
|
|
});
|
|
// #1618: dated checklist items, as "card: item", opening their card.
|
|
// Their `ci:` ids never match a card, so dragging one is reverted.
|
|
const { datedChecklistItems } = require('/models/lib/checklistItemSchedule');
|
|
datedChecklistItems(
|
|
ReactiveCache.getChecklistItems({ boardId: currentBoard._id, dueAt: { $exists: true } }),
|
|
id => ReactiveCache.getCard(id), { from: fetchInfo.start, to: fetchInfo.end },
|
|
).forEach(item => {
|
|
events.push({
|
|
id: item.id,
|
|
title: item.title,
|
|
start: item.dueAt,
|
|
end: new Date(item.dueAt.getTime() + 36e5),
|
|
allDay: false,
|
|
editable: false,
|
|
url: FlowRouter.path('card', { boardId: currentBoard._id, slug: currentBoard.slug, cardId: item.cardId }),
|
|
className: `calendar-event-checklist-item${item.isFinished ? ' is-finished' : ''}`,
|
|
});
|
|
});
|
|
events.sort(function (first, second) {
|
|
return first.id > second.id ? 1 : -1;
|
|
});
|
|
callback(events);
|
|
},
|
|
eventResize(info) {
|
|
let isOk = false;
|
|
const card = ReactiveCache.getCard(info.event.id);
|
|
|
|
if (card) {
|
|
card.setEnd(info.event.end);
|
|
isOk = true;
|
|
}
|
|
if (!isOk) {
|
|
info.revert();
|
|
}
|
|
},
|
|
eventDrop(info) {
|
|
let isOk = false;
|
|
const card = ReactiveCache.getCard(info.event.id);
|
|
if (card) {
|
|
// TODO: add a flag for allDay events
|
|
if (!info.event.allDay) {
|
|
// https://github.com/wekan/wekan/issues/2917#issuecomment-1236753962
|
|
//card.setStart(info.event.start);
|
|
//card.setEnd(info.event.end);
|
|
card.setDue(info.event.start);
|
|
isOk = true;
|
|
}
|
|
}
|
|
if (!isOk) {
|
|
info.revert();
|
|
}
|
|
},
|
|
select: function (selectionInfo) {
|
|
const currentBoard = Utils.getCurrentBoard();
|
|
const currentUser = ReactiveCache.getCurrentUser();
|
|
const modalElement = document.createElement('div');
|
|
modalElement.classList.add('modal', 'fade');
|
|
modalElement.setAttribute('tabindex', '-1');
|
|
modalElement.setAttribute('role', 'dialog');
|
|
modalElement.innerHTML = `
|
|
<div class="modal-dialog justify-content-center align-items-center" role="document">
|
|
<div class="modal-content" data-editor-scope>
|
|
<div class="modal-header">
|
|
<h5 class="modal-title">${TAPi18n.__('r-create-card')}</h5>
|
|
<button type="button" class="close calendar-create-close" data-dismiss="modal" aria-label="Close">
|
|
<span aria-hidden="true">×</span>
|
|
</button>
|
|
</div>
|
|
<div class="modal-body text-center">
|
|
<textarea rows="2" class="form-control" id="card-title-input" data-editor-submit="#create-card-button"></textarea>
|
|
</div>
|
|
<div class="modal-footer">
|
|
<button type="button" class="primary confirm" id="create-card-button">${TAPi18n.__('add-card')}</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
`;
|
|
const createCardButton = modalElement.querySelector(
|
|
'#create-card-button',
|
|
);
|
|
createCardButton.addEventListener('click', async function () {
|
|
const myTitle = modalElement.querySelector('#card-title-input').value;
|
|
if (myTitle) {
|
|
let firstSwimlane = currentBoard.swimlanes()[0];
|
|
if (!firstSwimlane) {
|
|
const swimlaneId = await Swimlanes.insertAsync({
|
|
title: 'Default',
|
|
boardId: currentBoard._id,
|
|
});
|
|
firstSwimlane = ReactiveCache.getSwimlane(swimlaneId);
|
|
}
|
|
|
|
let firstList = currentBoard.draggableLists()[0];
|
|
if (!firstList && firstSwimlane) {
|
|
const defaultTitle = TAPi18n.__('default');
|
|
const listId = await Lists.insertAsync({
|
|
title: typeof defaultTitle === 'string' ? defaultTitle : 'Default',
|
|
boardId: currentBoard._id,
|
|
swimlaneId: firstSwimlane._id,
|
|
});
|
|
firstList = ReactiveCache.getList(listId);
|
|
}
|
|
|
|
if (!firstList || !firstSwimlane) {
|
|
return;
|
|
}
|
|
|
|
Meteor.call(
|
|
'createCardWithDueDate',
|
|
currentBoard._id,
|
|
firstList._id,
|
|
myTitle,
|
|
selectionInfo.start,
|
|
firstSwimlane._id,
|
|
function (error, result) {
|
|
if (error) {
|
|
if (process.env.DEBUG === 'true') {
|
|
console.log(error);
|
|
}
|
|
} else {
|
|
if (process.env.DEBUG === 'true') {
|
|
console.log('Card Created', result);
|
|
}
|
|
}
|
|
},
|
|
);
|
|
closeModal();
|
|
}
|
|
});
|
|
document.body.appendChild(modalElement);
|
|
const openModal = function () {
|
|
modalElement.style.display = 'flex';
|
|
// Set focus to the input field for better keyboard accessibility
|
|
const input = modalElement.querySelector('#card-title-input');
|
|
if (input) input.focus();
|
|
};
|
|
const closeModal = function () {
|
|
modalElement.style.display = 'none';
|
|
};
|
|
const closeButton = modalElement.querySelector(
|
|
'[data-dismiss="modal"]',
|
|
);
|
|
closeButton.addEventListener('click', closeModal);
|
|
openModal();
|
|
},
|
|
};
|
|
},
|
|
isViewCalendar() {
|
|
return Utils.boardView() === 'board-view-cal';
|
|
},
|
|
});
|
|
|
|
/**
|
|
* Gantt View Component
|
|
* Displays cards as a Gantt chart with start/due dates
|
|
*/
|