Files
wekan/client/components/cards/cardTime.js
T
Lauri Ojansivu 9f5ab97a3c Spent time: the formatter imported as cardTime.js's other dependencies are.
A require() line stayed in the script tests/acceptedFixesLogic.test.cjs
evaluates, which strips imports, and failed it.

Thanks to brlin-tw and xet7 !
2026-11-11 20:29:31 +02:00

89 lines
2.6 KiB
JavaScript

import { TAPi18n } from '/imports/i18n';
import Cards from '/models/cards';
import { getCurrentCardIdFromContext } from '/client/lib/currentCard';
import { backIfOwnPopup } from '/client/lib/popupBack';
// #6890: the badge shows a duration, the tooltip hours to two decimals.
import { formatSpentTime, roundedSpentHours } from '/models/lib/spentTimeFormat';
function getCardId() {
return getCurrentCardIdFromContext();
}
Template.editCardSpentTimePopup.onCreated(function () {
this.error = new ReactiveVar('');
this.card = Cards.findOne(getCardId());
this.overtime = new ReactiveVar(this.card?.getIsOvertime() || false);
});
Template.editCardSpentTimePopup.helpers({
error() {
return Template.instance().error;
},
card() {
return Cards.findOne(getCardId());
},
getIsOvertime() {
return Template.instance().overtime.get();
},
});
Template.editCardSpentTimePopup.events({
//TODO : need checking this portion
'submit .edit-time'(evt, tpl) {
evt.preventDefault();
const card = Cards.findOne(getCardId());
if (!card) return;
const spentTime = parseFloat(evt.target.time.value);
const isOvertime = tpl.overtime.get();
if (spentTime >= 0) {
card.setSpentTime(spentTime);
card.setIsOvertime(isOvertime);
backIfOwnPopup(evt, 'editCardSpentTimePopup');
} else {
tpl.error.set('invalid-time');
evt.target.time.focus();
}
},
'click .js-delete-time'(evt) {
evt.preventDefault();
const card = Cards.findOne(getCardId());
if (!card) return;
card.setSpentTime(null);
card.setIsOvertime(false);
backIfOwnPopup(evt, 'editCardSpentTimePopup');
},
'click a.js-toggle-overtime'(evt, tpl) {
evt.preventDefault();
tpl.overtime.set(!tpl.overtime.get());
},
});
Template.cardSpentTime.helpers({
showTitle() {
const card = Cards.findOne(this._id) || this;
if (card.getIsOvertime && card.getIsOvertime()) {
return `${TAPi18n.__(
'overtime',
)} ${roundedSpentHours(card.getSpentTime())} ${TAPi18n.__('hours')}`;
} else if (card.getSpentTime) {
return `${TAPi18n.__(
'card-spent',
)} ${roundedSpentHours(card.getSpentTime())} ${TAPi18n.__('hours')}`;
}
return '';
},
showTime() {
const card = Cards.findOne(this._id) || this;
return card.getSpentTime ? formatSpentTime(card.getSpentTime()) : '';
},
getIsOvertime() {
const card = Cards.findOne(this._id) || this;
return card.getIsOvertime ? card.getIsOvertime() : false;
},
});
Template.cardSpentTime.events({
'click .js-edit-time': Popup.open('editCardSpentTime'),
});