Ability to export sheets from tracker
This commit is contained in:
@@ -1241,11 +1241,127 @@ module.exports = function (options) {
|
||||
}
|
||||
]
|
||||
}).then(translationChapters => {
|
||||
response.display("project-tracker", {
|
||||
user: request.user,
|
||||
project: project,
|
||||
translationChapters: translationChapters
|
||||
})
|
||||
if (request.query.sheets) {
|
||||
// Return sheets
|
||||
const workbook = new XL.Workbook();
|
||||
const cellWidth = 45
|
||||
const cellHeight = 25
|
||||
|
||||
translationChapters.sort((a, b) => a.index - b.index).forEach((translationChapter, index) => {
|
||||
const worksheet_name = `${index+1}-${translationChapter.translationArtifactVersion.dialect.countryId}-${translationChapter.translationArtifactVersion.dialect.languageId} - ${translationChapter.translationArtifactVersion.artifactVersion.artifact.name}`.substring(0, 30);
|
||||
|
||||
// Don't have [ ] * ? : / \
|
||||
const worksheet = workbook.addWorksheet(worksheet_name.replace(/[`*?:'\[\]\\\/]/gi, ""))
|
||||
|
||||
worksheet.cell(2,2,2,3,true)
|
||||
.string(translationChapter.translationArtifactVersion.artifactVersion.artifact.name)
|
||||
.style({
|
||||
font: {
|
||||
bold: true,
|
||||
},
|
||||
alignment: {
|
||||
horizontal: 'center',
|
||||
wrapText: true
|
||||
}
|
||||
})
|
||||
|
||||
worksheet.cell(4,2)
|
||||
.string(translationChapter.translationArtifactVersion.artifactVersion.artifact.dialect.name)
|
||||
.style({
|
||||
font: {
|
||||
bold: true,
|
||||
},
|
||||
alignment: {
|
||||
horizontal: 'center',
|
||||
wrapText: true
|
||||
}
|
||||
})
|
||||
|
||||
worksheet.cell(4,3)
|
||||
.string(translationChapter.translationArtifactVersion.dialect.name)
|
||||
.style({
|
||||
font: {
|
||||
bold: true,
|
||||
},
|
||||
alignment: {
|
||||
horizontal: 'center',
|
||||
wrapText: true
|
||||
}
|
||||
})
|
||||
// Meta data for the translation and artifact
|
||||
worksheet.cell(4,4)
|
||||
.string(translationChapter.translationArtifactVersion.artifactVersion.id)
|
||||
worksheet.cell(4,5)
|
||||
.string(translationChapter.translationArtifactVersion.id)
|
||||
|
||||
var cellIndex = 6
|
||||
const translationChunks = translationChapter.translationChunks.sort((a,b) => a.index - b.index)
|
||||
for (const j in translationChunks) {
|
||||
const translationChunk = translationChunks[j]
|
||||
|
||||
worksheet.cell(cellIndex,2)
|
||||
.string(translationChunk.text)
|
||||
.style({
|
||||
alignment: {
|
||||
wrapText: true,
|
||||
vertical: 'justify'
|
||||
}
|
||||
})
|
||||
|
||||
const translationCell = worksheet.cell(cellIndex,3)
|
||||
.style({
|
||||
alignment: {
|
||||
wrapText: true,
|
||||
vertical: 'justify'
|
||||
}
|
||||
})
|
||||
|
||||
if (translationChunk.translation) {
|
||||
translationCell.string(translationChunk.translation.text)
|
||||
}
|
||||
|
||||
const textLength = translationChunk.text.length
|
||||
worksheet.row(cellIndex).setHeight(
|
||||
Math.ceil(Math.max(textLength/cellWidth, 1)*cellHeight)
|
||||
)
|
||||
|
||||
// Meta data...
|
||||
// ID for translationChunk
|
||||
worksheet.cell(cellIndex,4)
|
||||
.string(translationChunk.id)
|
||||
// ID for translation
|
||||
worksheet.cell(cellIndex,5)
|
||||
.string(translationChunk.translation?.id ?? "")
|
||||
|
||||
cellIndex++
|
||||
}
|
||||
|
||||
|
||||
// Format Columns
|
||||
worksheet.column(2).setWidth(cellWidth);
|
||||
worksheet.column(3).setWidth(cellWidth);
|
||||
worksheet.column(4).hide();
|
||||
worksheet.column(5).hide();
|
||||
|
||||
// Format Rows...
|
||||
worksheet.row(5).freeze()
|
||||
worksheet.row(1).setHeight(5)
|
||||
worksheet.row(3).setHeight(5)
|
||||
worksheet.row(5).setHeight(5)
|
||||
})
|
||||
if (translationChapters.length > 0) {
|
||||
workbook.write(`${project.name}.xlsx`, response);
|
||||
} else {
|
||||
response.redirect(`/projects/${request.params.id}`)
|
||||
}
|
||||
} else {
|
||||
response.display("project-tracker", {
|
||||
user: request.user,
|
||||
project: project,
|
||||
translationChapters: translationChapters
|
||||
})
|
||||
}
|
||||
|
||||
}).catch(error => {
|
||||
next(error)
|
||||
})
|
||||
|
||||
@@ -46,6 +46,7 @@ module.exports = function () {
|
||||
response.display = (view, options) => {
|
||||
options.domain = config.get("server.domain");
|
||||
options.urlEndpoint = request.originalUrl;
|
||||
options.query = request.query;
|
||||
// Set a default pageTitle...
|
||||
options.pageTitle = options.pageTitle ? options.pageTitle : "Mantra";
|
||||
options.errorMessage = (error) => {
|
||||
|
||||
@@ -22,6 +22,14 @@ block content
|
||||
.col.s12
|
||||
a.btn.black(href=`/projects/${project.id}/tracker/trail`) audit trail
|
||||
|
||||
.row
|
||||
.col.s12
|
||||
form(action=urlEndpoint, method="get")
|
||||
input(type="hidden", name="sheets", value="true")
|
||||
each val, key in query
|
||||
if key != "sheets"
|
||||
input(type="hidden", name=key, value=val)
|
||||
button.btn.black(type="submit") export to spreadsheets
|
||||
.divider
|
||||
|
||||
table.highlight
|
||||
|
||||
Reference in New Issue
Block a user