mirror of
https://github.com/wekan/wekan.git
synced 2026-11-25 04:49:41 -05:00
The Board View menu's Dashboard, Burndown, Burnup, Cumulative Flow, Control Chart, Lead/Cycle Time, Flow Efficiency, Throughput Histogram and WIP Run entries opened a plain "not implemented yet" page. Each now computes and renders its chart from this board's own Cards/Lists/Activities, per docs/Features/Reports/charts.tsv's calculation descriptions - plain HTML/CSS bars and a data table, no new charting dependency. Every chart page, and the Gantt view, gets "Export to PDF" / "Export to Excel" buttons that reuse the existing card/board export renderers (pdfDocument's line/bar builder, createWorkbook's Excel styling) through the same public-board / authToken / logged-in-user auth gate every other export route already uses. Completion date is card.endAt || card.archivedAt (WeKan has no dedicated "Done" list flag); WIP Run's limit line only draws when a list's own WIP limit is enabled (no invented board-level schema); Flow Efficiency's "active" time is card.spentTime (WeKan does not track per-list queue time). Each deviation from charts.tsv is documented where the calculation is. models/lib/chartCalculations.js (20 tests), models/lib/chartExportRows.js (8 tests) and the export routes' auth shape (10 tests) are covered by tests/chartCalculations.test.cjs, tests/chartExportRows.test.cjs and tests/chartExportRoutesAuth.test.cjs; tests/boardViewMenu.test.cjs is updated for the now-real views. Not verified here: actual Blaze rendering and generated PDF/XLSX bytes (no browser/Meteor runtime in this environment) - matched syntactically against statsView/timeView and the existing exporters.
93 lines
3.4 KiB
JavaScript
93 lines
3.4 KiB
JavaScript
import { ReactiveCache } from '/imports/reactiveCache';
|
|
import { TAPi18n } from '/imports/i18n';
|
|
import { createWorkbook } from './createWorkbook';
|
|
import { attachmentDisposition, exportFilename } from '/models/lib/exportFilename';
|
|
import { loadBoardChartData } from '/server/lib/boardChartData';
|
|
const { chartExportRows } = require('/models/lib/chartExportRows');
|
|
|
|
// A board report chart as an .xlsx sheet - same createWorkbook() the board/
|
|
// card Excel exports use (models/server/ExporterExcelBoard.js), a bold header
|
|
// row, one row of data per line.
|
|
class ExporterChartExcel {
|
|
constructor(boardId, chartKey, userLanguage) {
|
|
this._boardId = boardId;
|
|
this._chartKey = chartKey;
|
|
this.userLanguage = userLanguage || 'en';
|
|
}
|
|
|
|
__(key, fallback) {
|
|
try {
|
|
const translated = TAPi18n.__(key, '', this.userLanguage);
|
|
if (translated && translated !== key) return translated;
|
|
} catch (error) { /* a missing bundle is not a reason to fail an export */ }
|
|
return fallback;
|
|
}
|
|
|
|
async canExport(user) {
|
|
const board = await ReactiveCache.getBoard(this._boardId);
|
|
return board && board.isVisibleBy(user);
|
|
}
|
|
|
|
async build(res) {
|
|
const board = await ReactiveCache.getBoard(this._boardId);
|
|
if (!board) {
|
|
res.writeHead(404, { 'Content-Type': 'text/plain; charset=utf-8' });
|
|
res.end('Board not found');
|
|
return;
|
|
}
|
|
const data = await loadBoardChartData(this._boardId, this._chartKey);
|
|
const { title, headers, rows } = chartExportRows(
|
|
this._chartKey, data || {}, (key, fallback) => this.__(key, fallback));
|
|
|
|
const workbook = createWorkbook();
|
|
workbook.creator = board.title;
|
|
workbook.created = new Date();
|
|
workbook.modified = new Date();
|
|
const sheetName = title.replace(/[\\/?*[\]:]/g, ' ').slice(0, 31) || 'Chart';
|
|
const ws = workbook.addWorksheet(sheetName, {
|
|
pageSetup: { paperSize: 9, orientation: 'landscape', fitToPage: true, fitToWidth: 1 },
|
|
});
|
|
ws.columns = (headers.length ? headers : ['']).map(() => ({ width: 20 }));
|
|
ws.mergeCells(1, 1, 1, Math.max(headers.length, 1));
|
|
const titleCell = ws.getCell(1, 1);
|
|
titleCell.value = `${board.title} - ${title}`;
|
|
titleCell.font = { size: 16, bold: true };
|
|
ws.getRow(1).height = 30;
|
|
|
|
if (headers.length) {
|
|
const headerRow = ws.getRow(2);
|
|
headers.forEach((header, index) => {
|
|
const cell = headerRow.getCell(index + 1);
|
|
cell.value = header;
|
|
cell.font = { bold: true };
|
|
cell.fill = { type: 'pattern', pattern: 'solid', fgColor: { argb: 'FFD9D9D9' } };
|
|
cell.border = {
|
|
top: { style: 'thin' }, left: { style: 'thin' },
|
|
bottom: { style: 'thin' }, right: { style: 'thin' },
|
|
};
|
|
});
|
|
headerRow.commit();
|
|
}
|
|
|
|
rows.forEach((row, rowIndex) => {
|
|
const sheetRow = ws.getRow(3 + rowIndex);
|
|
row.forEach((cell, cellIndex) => {
|
|
sheetRow.getCell(cellIndex + 1).value = cell instanceof Date ? cell.toISOString() : cell;
|
|
});
|
|
sheetRow.commit();
|
|
});
|
|
|
|
if (typeof ws.commit === 'function') ws.commit();
|
|
|
|
res.writeHead(200, {
|
|
'Content-Type': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
'Content-Disposition': attachmentDisposition(exportFilename(
|
|
this._chartKey, key => this.__(key, key), board.title, 'xlsx')),
|
|
});
|
|
await workbook.xlsx.write(res);
|
|
res.end();
|
|
}
|
|
}
|
|
|
|
export { ExporterChartExcel };
|