Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 9x 9x 9x 9x 9x 9x 1x 1x 1x 1x 1x 1x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 2x 2x 2x 9x 1x 1x 1x 1x 1x 1x 1x 1x 21x 21x 21x 2x 21x 1x 1x 21x 21x 2x 21x 1x 1x 21x 21x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 13x 13x 13x 4x 4x 4x 4x 3x 4x 1x 1x 4x 12x 12x 13x 10x 10x 20x 2x 10x 10x 19x 19x 19x 19x 10x 10x 12x 12x 13x 11x 11x 11x 11x 12x 12x 13x 1x 1x 12x 12x 12x 21x 21x 12x 12x 12x 12x 13x 13x 13x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 13x 13x 13x 13x 13x 12x 13x 7x 7x 7x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 13x 1x 1x | const kanbn = require('./main');
const term = require('terminal-kit').terminal;
const formatDate = require('dateformat');
const utility = require('./utility');
module.exports = (() => {
const TASK_SEPARATOR = '\n\n';
/**
* Show only the selected fields for a task, as specified in the index options
* @param {object} index
* @param {object} task
* @return {string} The selected task fields
*/
function getTaskString(index, task) {
const taskTemplate = kanbn.getTaskTemplate(index);
const dateFormat = kanbn.getDateFormat(index);
// Get an object containing custom fields from the task
let customFields = {};
if ('customFields' in index.options) {
const customFieldNames = index.options.customFields.map(customField => customField.name);
customFields = Object.fromEntries(utility.zip(
customFieldNames,
customFieldNames.map(customFieldName => task.metadata[customFieldName] || '')
));
}
// Prepare task data for interpolation
const taskData = {
name: task.name,
description: task.name,
created: 'created' in task.metadata ? formatDate(task.metadata.created, dateFormat) : '',
updated: 'updated' in task.metadata ? formatDate(task.metadata.updated, dateFormat) : '',
started: 'started' in task.metadata ? formatDate(task.metadata.started, dateFormat) : '',
completed: 'completed' in task.metadata ? formatDate(task.metadata.completed, dateFormat) : '',
due: 'due' in task.metadata ? formatDate(task.metadata.due, dateFormat) : '',
assigned: 'assigned' in task.metadata ? task.metadata.assigned : '',
tags: 'tags' in task.metadata ? task.metadata.tags : [],
subTasks: task.subTasks,
relations: task.relations,
overdue: 'dueData' in task && 'overdue' in task.dueData ? task.dueData.overdue : null,
dueDelta: 'dueData' in task && 'dueDelta' in task.dueData ? task.dueData.dueDelta : 0,
dueMessage: 'dueData' in task && 'dueMessage' in task.dueData ? task.dueData.dueMessage : '',
column: task.column,
workload: task.workload,
progress: task.progress,
...customFields
};
try {
return new Function(...Object.keys(taskData), 'return `^:' + taskTemplate + '`;')(...Object.values(taskData));
} catch (e) {
utility.error(`Unable to build task template: ${e.message}`);
return;
}
}
/**
* Get a column heading with icons
* @param {object} index
* @param {string} columnName
* @return {string} The column heading
*/
function getColumnHeading(index, columnName) {
let heading = '^:';
if (
'completedColumns' in index.options &&
index.options.completedColumns.indexOf(columnName) !== -1
) {
heading += '^g\u2713^: ';
}
if (
'startedColumns' in index.options &&
index.options.startedColumns.indexOf(columnName) !== -1
) {
heading += '^c\u00bb^: ';
}
return heading + `^+${columnName}^:`;
}
return {
/**
* Show the kanbn board
* @param {object} index The index object
* @param {object[]} tasks An array of task objects
* @param {?string} [view=null] The view to show, or null to show the default view
* @param {boolean} [json=false] Show JSON output
*/
async show(index, tasks, view = null, json = false) {
const board = {};
let viewSettings = {};
if (view !== null) {
// Make sure the view exists
if (
!('views' in index.options) ||
(viewSettings = index.options.views.find(v => v.name === view)) === undefined
) {
throw new Error(`No view found with name "${view}"`);
}
}
// Check if there is a list of columns in the view settings
if (!('columns' in viewSettings)) {
viewSettings.columns = Object.keys(index.columns)
.filter(columnName => (
!('hiddenColumns' in index.options) ||
index.options.hiddenColumns.indexOf(columnName) === -1
))
.map(columnName => ({
name: columnName,
filters: {
column: columnName
}
}));
}
// Check if there is a list of lanes in the view settings
if (!('lanes' in viewSettings) || viewSettings.lanes.length === 0) {
viewSettings.lanes = [{
name: 'All tasks'
}];
}
// If a root-level filter is defined, apply it to the tasks
if ('filters' in viewSettings) {
tasks = kanbn.filterAndSortTasks(index, tasks, viewSettings.filters, []);
}
// Add columns
board.headings = viewSettings.columns.map(column => ({
name: column.name,
heading: getColumnHeading(index, column.name)
}));
// Add lanes and column contents
board.lanes = [];
for (let lane of viewSettings.lanes) {
const columns = [];
for (let column of viewSettings.columns) {
const cellTasks = kanbn.filterAndSortTasks(
index,
tasks,
{
...('filters' in column ? column.filters : {}),
...('filters' in lane ? lane.filters : {})
},
'sorters' in column ? column.sorters : []
);
columns.push(cellTasks);
}
board.lanes.push({
name: lane.name,
columns
});
}
if (json) {
console.log(JSON.stringify(board, null, 2));
return;
}
// Prepare table
const table = [];
table.push(board.headings.map(heading => heading.heading));
board.lanes.forEach(lane => table.push(
[lane.name],
lane.columns.map(column => column.map(task => getTaskString(index, task)).join(TASK_SEPARATOR))
));
// Display as a table
term.table(
table,
{
hasBorder: true,
contentHasMarkup: true,
borderChars: 'lightRounded',
borderAttr: { color: 'grey' },
textAttr: { color: 'white', bgColor: 'default' },
width: term.width,
fit: true
}
);
}
}
})();
|