mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
Both views wrote out the same FullCalendar options - first day of the week and the week numbers that follow it, time formats, the one-row toolbar, translated button labels, height, locale and direction - about fifty lines each. models/lib/calendarBaseOptions.js builds them once, given the translation, the user's first day and the display options, and each view adds only what differs: dragging and selecting, navLinks, business hours and its events. The tests that read the toolbar or the direction from boardBody.js read the shared module, and the Multi Board Calendar runtime test runs it for real. Thanks to xet7 !
166 lines
6.3 KiB
JavaScript
166 lines
6.3 KiB
JavaScript
import { Filter } from '/client/lib/filter';
|
|
import { FlowRouter } from 'meteor/ostrio:flow-router-extra';
|
|
import { calendarDateDisplayOptions } from '/client/lib/dateDisplay';
|
|
import { ReactiveCache } from '/imports/reactiveCache';
|
|
import { TAPi18n } from '/imports/i18n';
|
|
import { ReactiveVar } from 'meteor/reactive-var';
|
|
import { toFullCalendarFirstDay } from '/client/lib/calendarFirstDay';
|
|
import { weekNumberByFirstDay } from '/models/lib/weekStart';
|
|
import { calendarBaseOptions } from '/models/lib/calendarBaseOptions';
|
|
const { notHelperBoardTitle } = require('/models/lib/helperBoards');
|
|
|
|
// #2469: "Multi Board Calendar" - reuses #4223 Bigboard's exact
|
|
// membership query (see bigboardView.js's bigboardQuery) so the card set is
|
|
// every non-archived, non-template, non-helper board the current user is a
|
|
// member of, and reuses the single-board Calendar view's FullCalendar
|
|
// options/rendering (boardBody.js's Template.calendarView.helpers
|
|
// calendarOptions) almost verbatim, except events() aggregates across all
|
|
// of those boards instead of Utils.getCurrentBoard() alone, and each event
|
|
// is prefixed with its board's title.
|
|
function multiboardCalendarQuery() {
|
|
return {
|
|
archived: false,
|
|
type: 'board',
|
|
'members.userId': Meteor.userId(),
|
|
title: notHelperBoardTitle(),
|
|
};
|
|
}
|
|
|
|
Template.multiboardCalendarView.onCreated(function () {
|
|
const instance = this;
|
|
instance.subsReady = new ReactiveVar(false);
|
|
// Same per-board subscription pattern as Bigboard (#4223): the metadata-
|
|
// only 'boards' subscription is already kept alive app-wide, but each
|
|
// board's lists/swimlanes/cards (needed for cardsInInterval et al.) are
|
|
// only subscribed to when that board is opened normally - so subscribe to
|
|
// each visible board's own 'board' composite here too.
|
|
instance.autorun(() => {
|
|
const boards = ReactiveCache.getBoards(multiboardCalendarQuery(), {
|
|
sort: { sort: 1 },
|
|
});
|
|
let allReady = true;
|
|
boards.forEach((board) => {
|
|
const handle = instance.subscribe('board', board._id, false);
|
|
if (!handle.ready()) allReady = false;
|
|
});
|
|
instance.subsReady.set(allReady);
|
|
});
|
|
});
|
|
|
|
Template.multiboardCalendarView.helpers({
|
|
isLoading() {
|
|
return !Template.instance().subsReady.get();
|
|
},
|
|
multiboardCalendarOptions() {
|
|
const currentUser = ReactiveCache.getCurrentUser();
|
|
const firstDay = toFullCalendarFirstDay(
|
|
currentUser ? currentUser.getStartDayOfWeek() : 1,
|
|
);
|
|
|
|
return {
|
|
...calendarBaseOptions({
|
|
id: 'multiboard-calendar-view',
|
|
displayOptions: calendarDateDisplayOptions('multiboard-calendar-view'),
|
|
firstDay,
|
|
weekNumberOf: weekNumberByFirstDay,
|
|
translate: key => TAPi18n.__(key),
|
|
locale: TAPi18n.getLanguage(),
|
|
rtl: TAPi18n.isRTL(),
|
|
}),
|
|
// #2469 scope: cross-board drag-to-reschedule is out of scope for
|
|
// this pass (a card's board isn't necessarily the one currently
|
|
// open, and moving it needs more care than a single setDue call) -
|
|
// the single-board Calendar view keeps its own editable/select
|
|
// behaviour unchanged, and is unaffected by this view.
|
|
editable: false,
|
|
selectable: false,
|
|
navLinks: false,
|
|
events(fetchInfo, callback) {
|
|
const filterSelector = Filter.isActive()
|
|
? Filter._getMongoSelector()
|
|
: undefined;
|
|
const events = [];
|
|
const pushEvent = function (board, card, title, start, end, extraCls) {
|
|
start = start || card.startAt;
|
|
end = end || card.endAt;
|
|
title = title || card.title;
|
|
// Prefix every entry with its board's title so entries from
|
|
// different boards stay distinguishable on the merged calendar.
|
|
const badgedTitle = `[${board.title}] ${title}`;
|
|
const className =
|
|
(extraCls ? `${extraCls} ` : '') +
|
|
(card.color ? `calendar-event-${card.color}` : '');
|
|
events.push({
|
|
id: `${board._id}-${card._id}-${events.length}`,
|
|
title: badgedTitle,
|
|
start,
|
|
end: end || card.endAt,
|
|
allDay:
|
|
Math.abs(end.getTime() - start.getTime()) / 1000 === 24 * 3600,
|
|
url: FlowRouter.path('card', {
|
|
boardId: board._id,
|
|
slug: board.slug,
|
|
cardId: card._id,
|
|
}),
|
|
className,
|
|
extendedProps: { boardTitle: board.title },
|
|
});
|
|
};
|
|
const boards = ReactiveCache.getBoards(multiboardCalendarQuery(), {});
|
|
boards.forEach((board) => {
|
|
board
|
|
.cardsInInterval(fetchInfo.start, fetchInfo.end, filterSelector)
|
|
.forEach((card) => pushEvent(board, card));
|
|
board
|
|
.cardsReceivedInBetween(
|
|
fetchInfo.start,
|
|
fetchInfo.end,
|
|
filterSelector,
|
|
)
|
|
.forEach((card) =>
|
|
pushEvent(
|
|
board,
|
|
card,
|
|
`${card.title} ${TAPi18n.__('card-received')}`,
|
|
card.receivedAt,
|
|
new Date(card.receivedAt.getTime() + 36e5),
|
|
'calendar-event-received',
|
|
),
|
|
);
|
|
board
|
|
.cardsDueInBetween(fetchInfo.start, fetchInfo.end, filterSelector)
|
|
.forEach((card) =>
|
|
pushEvent(
|
|
board,
|
|
card,
|
|
`${card.title} ${TAPi18n.__('card-due')}`,
|
|
card.dueAt,
|
|
new Date(card.dueAt.getTime() + 36e5),
|
|
'calendar-event-due',
|
|
),
|
|
);
|
|
board
|
|
.cardsEndInBetween(fetchInfo.start, fetchInfo.end, filterSelector)
|
|
.forEach((card) =>
|
|
pushEvent(
|
|
board,
|
|
card,
|
|
`${card.title} ${TAPi18n.__('card-end')}`,
|
|
card.endAt,
|
|
new Date(card.endAt.getTime() + 36e5),
|
|
'calendar-event-end',
|
|
),
|
|
);
|
|
});
|
|
events.sort(function (first, second) {
|
|
return first.id > second.id ? 1 : -1;
|
|
});
|
|
callback(events);
|
|
},
|
|
// No eventResize/eventDrop/select handlers - out of scope (see
|
|
// `editable`/`selectable` comment above): clicking an event still
|
|
// navigates via its `url`, same as the single-board Calendar view.
|
|
};
|
|
},
|
|
});
|