mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
A CSV, TSV or Excel import now shows which column is which card field before importing, pre-filled from the header names - English names and WeKan's own export column names in every language - and asks for what is missing: a file with no list column gets one list, named on the page, instead of one list per row. Unused columns can be kept as text custom fields. The choice goes to the server as csvMapping, checked before anything is written, and the REST import and api.py take one too. The Owner column is applied, as are swimlane, received date, parent card, spent time, overtime and archived. A TSV value containing a comma stays one value. A dropdown custom field value that is not one of its items is skipped instead of failing the import. An Excel workbook is read sheet by sheet, its header found in row 1 or where WeKan's export puts it, in any language; formula cells are read as their results and rich text as text. WeKan's own Excel export imports, and a workbook with many boards - each on its own sheet, as Export all boards writes it - imports as many boards; the Activity sheet is skipped. Thanks to xet7 !
55 lines
1.9 KiB
JavaScript
55 lines
1.9 KiB
JavaScript
import { ReactiveCache } from '/imports/reactiveCache';
|
|
import { splitByField, splitPeople } from '/models/lib/csvImportMapping';
|
|
|
|
// The usernames to map. Without `columns`, the ones in a column named
|
|
// "Members"; with the columns the mapping step chose, the ones in every
|
|
// people column: owner, members, assignees, requested by and assigned by.
|
|
export function csvGetMembersToMap(data, columns) {
|
|
// we will work on the list itself (an ordered array of objects) when a
|
|
// mapping is done, we add a 'wekan' field to the object representing the
|
|
// imported member
|
|
|
|
const membersToMap = [];
|
|
const importedMembers = [];
|
|
const peopleColumns = [];
|
|
|
|
if (columns) {
|
|
['owner', 'members', 'assignees'].forEach(field => {
|
|
if (columns[field] !== undefined) peopleColumns.push({ index: columns[field], split: splitPeople });
|
|
});
|
|
['requestedBy', 'assignedBy'].forEach(field => {
|
|
if (columns[field] !== undefined) peopleColumns.push({ index: columns[field], split: splitByField });
|
|
});
|
|
} else {
|
|
for (let i = 0; i < data[0].length; i++) {
|
|
if (String(data[0][i] || '').toLowerCase() === 'members') {
|
|
peopleColumns.push({ index: i, split: cell => String(cell).split(' ') });
|
|
}
|
|
}
|
|
}
|
|
|
|
for (let i = 1; i < data.length; i++) {
|
|
for (const { index, split } of peopleColumns) {
|
|
if (data[i][index]) {
|
|
for (const importedMember of split(data[i][index])) {
|
|
if (importedMember && importedMembers.indexOf(importedMember) === -1) {
|
|
importedMembers.push(importedMember);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
for (let importedMember of importedMembers) {
|
|
importedMember = {
|
|
username: importedMember,
|
|
id: importedMember,
|
|
};
|
|
const wekanUser = ReactiveCache.getUser({ username: importedMember.username });
|
|
if (wekanUser) importedMember.wekanId = wekanUser._id;
|
|
membersToMap.push(importedMember);
|
|
}
|
|
|
|
return membersToMap;
|
|
}
|