mirror of
https://github.com/wekan/wekan.git
synced 2025-04-22 21:17:18 -04:00
Merge pull request #3128 from brymut/fix-export-csv-vote
Fix vote export & export/import currency custom field to CSV/TSV
This commit is contained in:
commit
e0f4758667
3 changed files with 40 additions and 24 deletions
|
@ -107,6 +107,13 @@ export class CsvCreator {
|
|||
options: headerRow[i].split('-')[3].split('/'),
|
||||
position: i,
|
||||
});
|
||||
} else if (headerRow[i].split('-')[2] === 'currency') {
|
||||
index.customFields.push({
|
||||
name: headerRow[i].split('-')[1],
|
||||
type: headerRow[i].split('-')[2],
|
||||
currencyCode: headerRow[i].split('-')[3],
|
||||
position: i,
|
||||
});
|
||||
} else {
|
||||
index.customFields.push({
|
||||
name: headerRow[i].split('-')[1],
|
||||
|
@ -127,6 +134,10 @@ export class CsvCreator {
|
|||
return { _id: Random.id(6), name: option };
|
||||
}),
|
||||
};
|
||||
} else if (customField.type === 'currency') {
|
||||
settings = {
|
||||
currencyCode: customField.currencyCode,
|
||||
};
|
||||
} else {
|
||||
settings = {};
|
||||
}
|
||||
|
|
|
@ -85,10 +85,10 @@ if (Meteor.isServer) {
|
|||
? exporter.buildCsv(params.query.delimiter)
|
||||
: exporter.buildCsv();
|
||||
res.writeHead(200, {
|
||||
'Content-Length': body[0].length,
|
||||
'Content-Length': body.length,
|
||||
'Content-Type': params.query.delimiter ? 'text/csv' : 'text/tsv',
|
||||
});
|
||||
res.write(body[0]);
|
||||
res.write(body);
|
||||
res.end();
|
||||
} else {
|
||||
res.writeHead(403);
|
||||
|
|
|
@ -37,7 +37,7 @@ export class Exporter {
|
|||
result.cards = Cards.find(byBoardNoLinked, noBoardId).fetch();
|
||||
result.swimlanes = Swimlanes.find(byBoard, noBoardId).fetch();
|
||||
result.customFields = CustomFields.find(
|
||||
{ boardIds: this.boardId },
|
||||
{ boardIds: this._boardId },
|
||||
{ fields: { boardIds: 0 } },
|
||||
).fetch();
|
||||
result.comments = CardComments.find(byBoard, noBoardId).fetch();
|
||||
|
@ -217,7 +217,6 @@ export class Exporter {
|
|||
const customFieldMap = {};
|
||||
let i = 0;
|
||||
result.customFields.forEach(customField => {
|
||||
customFieldMap[customField._id] = i;
|
||||
customFieldMap[customField._id] = {
|
||||
position: i,
|
||||
type: customField.type,
|
||||
|
@ -225,11 +224,15 @@ export class Exporter {
|
|||
if (customField.type === 'dropdown') {
|
||||
let options = '';
|
||||
customField.settings.dropdownItems.forEach(item => {
|
||||
options = options === '' ? item.name : `/${options + item.name}`;
|
||||
options = options === '' ? item.name : `${`${options}/${item.name}`}`;
|
||||
});
|
||||
columnHeaders.push(
|
||||
`CustomField-${customField.name}-${customField.type}-${options}`,
|
||||
);
|
||||
} else if (customField.type === 'currency') {
|
||||
columnHeaders.push(
|
||||
`CustomField-${customField.name}-${customField.type}-${customField.settings.currencyCode}`,
|
||||
);
|
||||
} else {
|
||||
columnHeaders.push(
|
||||
`CustomField-${customField.name}-${customField.type}`,
|
||||
|
@ -322,7 +325,7 @@ export class Exporter {
|
|||
currentRow.push(
|
||||
card.dateLastActivity ? moment(card.dateLastActivity).format() : ' ',
|
||||
);
|
||||
if (card.vote.question !== undefined) {
|
||||
if (card.vote && card.vote.question !== '') {
|
||||
let positiveVoters = '';
|
||||
let negativeVoters = '';
|
||||
card.vote.positive.forEach(userId => {
|
||||
|
@ -350,23 +353,25 @@ export class Exporter {
|
|||
//Custom fields
|
||||
const customFieldValuesToPush = new Array(result.customFields.length);
|
||||
card.customFields.forEach(field => {
|
||||
if (customFieldMap[field._id].type === 'date') {
|
||||
customFieldValuesToPush[customFieldMap[field._id].position] = moment(
|
||||
field.value,
|
||||
).format();
|
||||
} else if (customFieldMap[field._id].type === 'dropdown') {
|
||||
const dropdownOptions = result.customFields.find(
|
||||
({ _id }) => _id === field._id,
|
||||
).settings.dropdownItems;
|
||||
const fieldValue = dropdownOptions.find(
|
||||
({ _id }) => _id === field.value,
|
||||
).name;
|
||||
customFieldValuesToPush[
|
||||
customFieldMap[field._id].position
|
||||
] = fieldValue;
|
||||
} else {
|
||||
customFieldValuesToPush[customFieldMap[field._id].position] =
|
||||
field.value;
|
||||
if (field.value !== null) {
|
||||
if (customFieldMap[field._id].type === 'date') {
|
||||
customFieldValuesToPush[
|
||||
customFieldMap[field._id].position
|
||||
] = moment(field.value).format();
|
||||
} else if (customFieldMap[field._id].type === 'dropdown') {
|
||||
const dropdownOptions = result.customFields.find(
|
||||
({ _id }) => _id === field._id,
|
||||
).settings.dropdownItems;
|
||||
const fieldValue = dropdownOptions.find(
|
||||
({ _id }) => _id === field.value,
|
||||
).name;
|
||||
customFieldValuesToPush[
|
||||
customFieldMap[field._id].position
|
||||
] = fieldValue;
|
||||
} else {
|
||||
customFieldValuesToPush[customFieldMap[field._id].position] =
|
||||
field.value;
|
||||
}
|
||||
}
|
||||
});
|
||||
for (
|
||||
|
@ -383,7 +388,7 @@ export class Exporter {
|
|||
stringifier.write(currentRow);
|
||||
});
|
||||
stringifier.end();
|
||||
return cardRows;
|
||||
return cardRows[0];
|
||||
}
|
||||
|
||||
canExport(user) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue