Files
wekan/models/lib/flowAnalyticsRows.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

58 lines
3.9 KiB
JavaScript

'use strict';
// Single source for screen, Excel and PDF. Null measurements are unknown,
// never coerced to zero; dates stay Dates for the existing locale exporters.
function flowAnalyticsRows(key, data, translate = (key, fallback) => fallback) {
const t = (key, fallback) => translate(key, fallback);
const number = value => value == null ? t('flow-unknown', 'Unknown') : Math.round(value * 100) / 100;
const card = t('card', 'Card');
const list = t('list', 'List');
const cycle = t('flow-cycle-days', 'Cycle time (days)');
if (key === 'agingWip') return {
headers: [card, list, t('flow-age-days', 'Age in stage (days)'), t('flow-p85', 'Stage 85th percentile (days)'), t('flow-samples', 'Samples'), t('flow-signal', 'Signal')],
rows: (data.points || []).map(p => [p.title, p.list, number(p.ageDays), number(p.threshold), p.samples,
p.unusual ? t('flow-unusual', 'Above limit') : '']),
};
if (key === 'blockerAnalysis') return {
headers: [t('flow-blocker', 'Blocker'), t('flow-episodes', 'Episodes'), t('flow-active', 'Open episodes'), t('flow-blocked-days', 'Blocked card-days'), t('flow-unknown-start', 'Unknown starts'), t('cards', 'Cards'), t('lists', 'Lists')],
rows: (data.groups || []).map(g => [g.title, g.count, g.active, number(g.days), g.unknown, g.cards, g.lists]),
};
if (key === 'monteCarlo') return {
headers: [t('flow-confidence', 'Confidence'), t('flow-target-count', 'Target cards'), t('flow-finish-days', 'Days to finish'), t('flow-finish-date', 'Finish date'), t('flow-target-date', 'Target date'), t('flow-capacity', 'At least this many cards'), t('flow-history-days', 'History days')],
rows: (data.forecasts || []).map(p => [`${p.probability}%`, data.options.targetCount,
number(p.days), p.date || t('flow-beyond-horizon', 'Beyond simulation horizon'),
data.options.targetDate, p.count, data.history.length]),
};
if (key === 'processBehavior') return {
headers: [card, t('completed', 'Completed'), cycle, t('flow-mean', 'Mean'), 'LCL', 'UCL', t('flow-moving-range', 'Moving range'), t('flow-mr-mean', 'Mean moving range'), 'MR UCL', t('flow-signal', 'Signal')],
rows: (data.points || []).map(p => [p.title, p.completedAt, number(p.cycleDays), number(data.limits.average),
number(data.limits.lower), number(data.limits.upper), number(p.movingRange), number(data.limits.mrAverage),
number(data.limits.mrUpper), p.signal ? t('flow-unusual', 'Above limit') : '']),
};
if (key === 'sizeCycleTime') return {
headers: [card, t('flow-size-source', 'Size field'), t('flow-size', 'Estimate'), cycle, t('completed', 'Completed')],
rows: (data.points || []).map(p => [p.title, data.options.sizeField === 'poker' ? t('poker-question', 'Planning Poker')
: data.sizeFields.find(f => f._id === data.options.sizeField)?.name, p.size, number(p.cycleDays), p.completedAt]),
};
return { headers: [], rows: [] };
}
function flowDetailRows(key, data, t = (key, fallback) => fallback) {
if (key === 'time') return {
headers: [t('date', 'Date'), t('card', 'Card'), t('username', 'Author'), `Δ ${t('hours', 'Hours')}`, t('hours', 'Hours')],
rows: (data.adjustments?.entries || []).map(row => [new Date(row.at), row.title, row.author, row.hours, row.total]),
};
if (key === 'blockerAnalysis') return {
headers: [t('flow-blocker', 'Blocker'), t('card', 'Card'), t('list', 'List'), t('card-start', 'Start'), t('card-end', 'End'), t('days', 'Days')],
rows: (data.episodes || []).map(p => [p.blocker, p.title, p.list || p.listId,
p.startAt || t('flow-unknown', 'Unknown'), p.endAt || t('flow-active', 'Open episodes'),
p.days == null ? t('flow-unknown', 'Unknown') : Math.round(p.days * 100) / 100]),
};
if (key === 'monteCarlo') return {
headers: [t('date', 'Date'), t('completed', 'Completed')],
rows: (data.history || []).map(row => [row.day, row.count]),
};
return { headers: [], rows: [] };
}
module.exports = { flowAnalyticsRows, flowDetailRows };