mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 20:45:00 -05:00
Reported directly: clicking a newly created label did not enlarge it or apply it to the card. The browser console showed "Exception in Template.cardFlowtime canControlFlow" and the same for Template.cardPomodoro canControlPomodoro - both call Utils.canModifyCard() but never import Utils (a plain ES export from client/lib/utils.js, not a Meteor global), so the helper threw a ReferenceError the moment either template's reactive computation ran, which broke the surrounding card render along with it. Searching the whole tree for the same shape (a client file calling Utils.<method>() or ReactiveCache.<method>() without importing it) found two more real, independent instances: - client/components/settings/notificationSettingsPopup.js's currentBoard() called Utils.getCurrentBoardId() unimported. - client/components/main/bookmarks.js's four helpers/events called ReactiveCache.getCurrentUser() unimported - the header bookmarks/Starred feature. - client/lib/tests/Utils.tests.js did `import '../utils';` (a bare side-effect import) and then used the bare `Utils` global throughout - never actually reached by the fast Node suite (a mocha/browser test), but would have thrown the same way if run. None of this is caught by rspack's build (it does not type-check or cross-check imports app-wide) or by tests/run-node-suites.cjs (nothing exercises these code paths with the name deliberately left undefined) - only the browser, live, the moment that render actually runs. tests/clientSingletonImports.test.cjs sweeps every client/**/*.js file for a call to Utils.<method>( or ReactiveCache.<method>( with no matching import, so this shape cannot reappear anywhere else undetected. Verified against a real Meteor boot (`meteor run`) in-sandbox. Thanks to xet7 !
103 lines
3.4 KiB
JavaScript
103 lines
3.4 KiB
JavaScript
// Flowtime (#3919): "better than Pomodoro" - a work session with no fixed
|
|
// interval. Unlike the manual time-entry popup in cardTime.js, this tracks a
|
|
// live, in-progress session server-side (so a page reload does not lose it),
|
|
// tallies interruptions without stopping the clock, and on Stop adds the
|
|
// session's duration into the SAME `spentTime` field the manual popup edits,
|
|
// via the existing card.setSpentTime()-based helper - it feeds the same
|
|
// total rather than keeping a separate one.
|
|
import { TAPi18n } from '/imports/i18n';
|
|
import Cards from '/models/cards';
|
|
import { getCurrentCardIdFromContext } from '/client/lib/currentCard';
|
|
import { Utils } from '/client/lib/utils';
|
|
|
|
function getCardId() {
|
|
return getCurrentCardIdFromContext();
|
|
}
|
|
|
|
// Anyone who may interact with the session: the user who started it, or
|
|
// anyone with general card-modify rights (a board admin taking over, e.g.).
|
|
// This is the simplest rule that still lets a teammate stop a session left
|
|
// running by someone who stepped away, without opening the buttons to
|
|
// read-only board members.
|
|
function canControlFlow(card) {
|
|
if (!card) return false;
|
|
if (!Utils.canModifyCard()) return false;
|
|
return true;
|
|
}
|
|
|
|
Template.cardFlowtime.onCreated(function () {
|
|
this.elapsed = new ReactiveVar(0);
|
|
this.timer = null;
|
|
|
|
const startTicking = startAt => {
|
|
if (this.timer) Meteor.clearInterval(this.timer);
|
|
const tick = () => {
|
|
this.elapsed.set(Math.max(0, Date.now() - new Date(startAt).getTime()));
|
|
};
|
|
tick();
|
|
this.timer = Meteor.setInterval(tick, 1000);
|
|
};
|
|
|
|
this.autorun(() => {
|
|
const card = Cards.findOne(getCardId());
|
|
if (card && card.isFlowActive && card.isFlowActive()) {
|
|
startTicking(card.flowStartAt);
|
|
} else if (this.timer) {
|
|
Meteor.clearInterval(this.timer);
|
|
this.timer = null;
|
|
this.elapsed.set(0);
|
|
}
|
|
});
|
|
});
|
|
|
|
Template.cardFlowtime.onDestroyed(function () {
|
|
if (this.timer) Meteor.clearInterval(this.timer);
|
|
});
|
|
|
|
Template.cardFlowtime.helpers({
|
|
card() {
|
|
return Cards.findOne(getCardId());
|
|
},
|
|
isFlowActive() {
|
|
const card = Cards.findOne(getCardId());
|
|
return card && card.isFlowActive && card.isFlowActive();
|
|
},
|
|
canControlFlow() {
|
|
return canControlFlow(Cards.findOne(getCardId()));
|
|
},
|
|
flowInterruptions() {
|
|
const card = Cards.findOne(getCardId());
|
|
return card && card.getFlowInterruptions ? card.getFlowInterruptions() : 0;
|
|
},
|
|
elapsedDisplay() {
|
|
const ms = Template.instance().elapsed.get();
|
|
const totalSeconds = Math.floor(ms / 1000);
|
|
const hours = Math.floor(totalSeconds / 3600);
|
|
const minutes = Math.floor((totalSeconds % 3600) / 60);
|
|
const seconds = totalSeconds % 60;
|
|
const pad = n => `${n}`.padStart(2, '0');
|
|
return `${pad(hours)}:${pad(minutes)}:${pad(seconds)}`;
|
|
},
|
|
});
|
|
|
|
Template.cardFlowtime.events({
|
|
'click .js-start-flow'(evt) {
|
|
evt.preventDefault();
|
|
const card = Cards.findOne(getCardId());
|
|
if (!card || !Utils.canModifyCard()) return;
|
|
card.startFlowSession(Meteor.userId());
|
|
},
|
|
'click .js-add-flow-interruption'(evt) {
|
|
evt.preventDefault();
|
|
const card = Cards.findOne(getCardId());
|
|
if (!card || !canControlFlow(card)) return;
|
|
card.addFlowInterruption();
|
|
},
|
|
'click .js-stop-flow'(evt) {
|
|
evt.preventDefault();
|
|
const card = Cards.findOne(getCardId());
|
|
if (!card || !canControlFlow(card)) return;
|
|
card.stopFlowSession();
|
|
},
|
|
});
|