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