Files
wekan/client/components/boards/timeView.js
T
Lauri Ojansivu 6d99ad73c4 Preserve time history and record reversible move reasons
Keep card and checklist activity after deletion, retain card snapshots for
flow reports, and show recorded hour adjustments by their actual author in
Time and its PDF/Excel exports. Record whole positions centrally, including
optional move reasons and direct REST edits. Append undo/redo checkpoints
so blocker intervals and time corrections follow reversals through time.

Audit the open time-related requests against existing features. Exact inline
activity timestamps requested in #1673 already exist in dateDisplay and the
activities template; add a browser regression for that existing behavior.

Reuse established locale terminology for the new compact labels. Labels
outside English and Finnish are low-confidence glossary combinations for
human review; existing translations remain untouched.

Validation: 43 focused Node suites pass. Fifteen Chromium scenarios pass
across flow analytics, time history and existing REST move coverage, including
real chart and Time PDF/Excel exports, undo/redo, retention and access denial.

Thanks to ladistrupl, zombah and xet7 !

Fixes #1598,
Fixes #1673,
2026-09-26 23:00:58 +03:00

84 lines
3.3 KiB
JavaScript

import { ReactiveVar } from 'meteor/reactive-var';
import { TAPi18n } from '/imports/i18n';
const { translateGroupLabel, formatRemainingTime } = require('/models/lib/chartCalculations');
// Board view "Time" - split out of "Statistics" so time tracking has its own
// place in the board-view menu. The summary counts come from the server
// `boardStatus` method, same subscription pattern as statsView.js. The
// by-assignee/by-card breakdown (#812: "reporting total hours by resource
// and task type") and PDF/Excel export reuse the same `boardChartData`
// method and `/api/boards/:boardId/charts/:chartKey/export*` routes every
// other board report chart already uses (chartKey 'time') - one export
// pipeline for every chart, not a second one just for this view.
Template.timeView.onCreated(function() {
this.status = new ReactiveVar(null);
this.breakdown = new ReactiveVar(null);
this.autorun(() => {
const boardId = Session.get('currentBoard');
if (boardId) {
Meteor.call('boardStatus', boardId, (err, res) => {
if (!err && res) this.status.set(res);
});
Meteor.call('boardChartData', boardId, 'time', (err, res) => {
if (!err && res) this.breakdown.set(res);
});
}
});
});
function statsNum(key) {
const s = Template.instance().status.get();
return s ? (s[key] || 0) : '…';
}
Template.timeView.events({
// See statsView.js: stop the board canvas's drag-to-scroll from swallowing
// the pointer/touch events that native text selection needs.
'mousedown .stats-view'(event) {
event.stopPropagation();
},
'touchstart .stats-view'(event) {
event.stopPropagation();
},
});
Template.timeView.helpers({
timeAdjustmentGroups() { return Template.instance().breakdown.get()?.adjustments?.groups || []; },
timeAdjustmentEntries() { return Template.instance().breakdown.get()?.adjustments?.entries || []; },
cardsWithTimeSpent() { return statsNum('cardsWithTimeSpent'); },
overtimeCards() { return statsNum('overtimeCards'); },
timeSpentTotal() {
const s = Template.instance().status.get();
if (!s) return '…';
const n = Number(s.timeSpentTotal) || 0;
return `${n} h`;
},
hasTimeBreakdown() {
const breakdown = Template.instance().breakdown.get();
return !!(breakdown && (breakdown.byAssignee.length || breakdown.byCard.length));
},
byAssignee() {
const breakdown = Template.instance().breakdown.get();
return breakdown ? breakdown.byAssignee : [];
},
byCard() {
const breakdown = Template.instance().breakdown.get();
return breakdown ? breakdown.byCard : [];
},
// #1121 ("show the SUM of remaining time until due date"): formatted the
// same "X days, Y hours" way the PDF/Excel export renders it.
remainingTimeTotal() {
const breakdown = Template.instance().breakdown.get();
if (!breakdown || !breakdown.remaining) return '…';
return formatRemainingTime(breakdown.remaining, key => TAPi18n.__(key));
},
// The "none" sentinel from models/lib/chartCalculations.js's
// NO_ASSIGNEE_GROUP - translated the same way the Dashboard view's own
// assignee breakdown already does (client/components/boards/charts/
// boardCharts.js), so a real assignee name always passes through
// unchanged and only the sentinel is ever translated.
assigneeLabel(label) {
return translateGroupLabel(label, key => TAPi18n.__(key));
},
});