mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 18:10:06 -05:00
A new page in the user menu, Workload and capacity (/workload), shows week
by week how much work each person has against the hours they have, across
every board the viewer is an active member of
(docs/Features/Workload/Workload.md):
- Load: a card's new Estimated hours, set in the Time popup beside the time
spent, less that time; story points from the board's Scrum estimate. A
card's work is spread from its start to its due date over the days the
person works; overdue work counts today; undated and unestimated cards are
counted apart, and work nobody carries is shown once as unassigned.
- Capacity: each person's hours per week (default 37.5), work time percent
(part-time 60 % is 22.5 h) and working days. Absences (vacation, sick
leave, day off, training, other) and public holidays set by an
administrator take their days away, and the work moves to the days the
person is there.
- A week over 100 % - more work than hours, allocations over 100 %, or work
in a week with no hours - is red; under half full is grey-blue. Clicking a
week lists its cards.
- Allocations: a board's admins give a member a share of their time on the
board for a period ("A on board X 50 % in April"), or name a role with no
person yet ("Developer x 1, 100 %, next month"), drawn as a placeholder
row with the hours it needs.
The server computes the report (models/lib/workload.js, server/workload.js);
cards are not published for it. Public boards and boards where the viewer
sees only their assigned cards are not included, inactive members are not
reported, and somebody else's absence is dates only: its type and note are
shown to that person and to administrators. Capacity and absences are a
person's own to change (an administrator's for anyone), allocations a board
admin's, holidays an administrator's. The four collections take no client
writes and have no publication; a deleted user's workload data goes with
them. Admin Panel / Features / Workload turns the page and its methods off.
The board's own Workload chart, a count of open cards per person, links to
the page. estimatedHours is copied by WeKan export/import.
tests/workload.test.cjs runs the rules as arithmetic, including the cases of
the request (37.5 h, 60 %, an overloaded week, a vacation, a holiday, 50 %
of April, the placeholder roles); tests/workloadAccess.test.cjs runs the real
methods as each kind of user; tests/playwright/specs/workload-capacity.e2e.js
drives the page. The new strings are translated into every language; low
confidence for the smallest ones (e.g. Tigre, Klingon, Wolaytta, Venda,
Vepsian, Cherokee, Dzongkha, Inuktitut, Nahuatl). In several locales the
eleven still-English enrollment/registration/auth strings were translated
too. The hour symbol h is language-independent in fill-translations.mjs.
Thanks to xet7 !
57 lines
2.0 KiB
JavaScript
57 lines
2.0 KiB
JavaScript
'use strict';
|
|
|
|
// How the Workload page draws one week of one person (client/components/main/
|
|
// workload.js): the colour, the bar and the text, from the numbers the server
|
|
// computed (models/lib/workload.js). Pure, so tests/workload.test.cjs checks
|
|
// that an overloaded week is red whatever the unit shown.
|
|
|
|
function round(n, digits = 1) {
|
|
const f = 10 ** digits;
|
|
return Math.round((Number(n) || 0) * f) / f;
|
|
}
|
|
|
|
function hoursLabel(hours, hoursWord = 'h') {
|
|
return `${round(hours)} ${hoursWord}`;
|
|
}
|
|
|
|
// The ISO week number of a 'YYYY-MM-DD' Monday.
|
|
function isoWeekNumber(day) {
|
|
const date = new Date(`${day}T00:00:00Z`);
|
|
const thursday = new Date(date.getTime() + (4 - (date.getUTCDay() || 7)) * 86400000);
|
|
const yearStart = Date.UTC(thursday.getUTCFullYear(), 0, 1);
|
|
return Math.ceil(((thursday.getTime() - yearStart) / 86400000 + 1) / 7);
|
|
}
|
|
|
|
/**
|
|
* @param {Object} week one entry of report.people[].weeks
|
|
* @param {string} unit 'hours' or 'points'
|
|
* @param {Object} words { hours: 'h', points: 'pt' }
|
|
*/
|
|
function workloadCell(week, unit = 'hours', words = {}) {
|
|
const hoursWord = words.hours || 'h';
|
|
const pointsWord = words.points || 'pt';
|
|
const state = week.overloaded ? 'is-over' : (week.underloaded ? 'is-under' : 'is-ok');
|
|
let barWidth = 0;
|
|
if (week.capacityHours > 0) barWidth = Math.min(100, Math.round(week.loadHours / week.capacityHours * 100));
|
|
else if (week.loadHours > 0) barWidth = 100;
|
|
const value = unit === 'points'
|
|
? `${round(week.loadPoints)} ${pointsWord}`
|
|
: `${round(week.loadHours)} / ${round(week.capacityHours)} ${hoursWord}`;
|
|
let percentLabel = '';
|
|
if (unit !== 'points') {
|
|
if (week.utilization === null) percentLabel = '∞ %';
|
|
else if (week.capacityHours > 0 || week.loadHours > 0) percentLabel = `${week.utilization} %`;
|
|
}
|
|
return {
|
|
state,
|
|
barWidth,
|
|
value,
|
|
percentLabel,
|
|
allocationPercent: week.allocationPercent || 0,
|
|
absentDays: week.absentDays || 0,
|
|
holidayDays: week.holidayDays || 0,
|
|
};
|
|
}
|
|
|
|
module.exports = { workloadCell, hoursLabel, isoWeekNumber, round };
|