CJVT updates August and September 2026
This commit is contained in:
@@ -15,7 +15,10 @@ const { getExportFilesPath } = require('../models/helpers/dictionary')
|
||||
const { DEFAULT_HITS_PER_PAGE, DATA_FILES_PATH } = require('../config/settings')
|
||||
const {
|
||||
statusChangeCheckAndAct,
|
||||
determineNewStatus
|
||||
determineNewStatus,
|
||||
resolveDictionarySort,
|
||||
parseDictionaryListFilters,
|
||||
DICTIONARY_STATUSES
|
||||
} = require('./helpers/dictionary')
|
||||
const SFDSuggestionImporter = require('./helpers/search-filter-data-suggestion-importer')
|
||||
const Extraction = require('../models/extraction')
|
||||
@@ -26,7 +29,7 @@ const importFileBodyParser = multer({
|
||||
dest: `${DATA_FILES_PATH}/dict_import_temp`,
|
||||
limits: {
|
||||
fieldNameSize: 21,
|
||||
fieldSize: 9,
|
||||
fieldSize: 64,
|
||||
fields: 3,
|
||||
fileSize: 1000 * 1000 * 1000, // 1GB
|
||||
headerPairs: 500
|
||||
@@ -99,11 +102,9 @@ dictionary.updateDescription = async (req, res) => {
|
||||
const { dictionaryId } = req.params
|
||||
const { body } = req
|
||||
|
||||
// TODO Consider using a transaction.
|
||||
await Promise.all([
|
||||
Dictionary.updateDescription(dictionaryId, body),
|
||||
Dictionary.deleteSecondaryDomains(dictionaryId, body),
|
||||
Dictionary.updateSecondaryDomains(dictionaryId, body)
|
||||
Dictionary.updateSecondaryDomainAssociations(dictionaryId, body)
|
||||
])
|
||||
|
||||
res.redirect(303, 'back')
|
||||
@@ -205,11 +206,9 @@ dictionary.updateStructure = async (req, res) => {
|
||||
const { body } = req
|
||||
const { dictionaryId } = req.params
|
||||
|
||||
// TODO Consider using a transaction.
|
||||
await Promise.all([
|
||||
Dictionary.updateStructure(dictionaryId, body),
|
||||
Dictionary.deleteLanguages(dictionaryId),
|
||||
Dictionary.updateLanguages(dictionaryId, body)
|
||||
Dictionary.updateLanguageAssociations(dictionaryId, body)
|
||||
])
|
||||
res.redirect(303, 'back')
|
||||
}
|
||||
@@ -294,18 +293,57 @@ dictionary.showImportFromFileForm = async (req, res) => {
|
||||
|
||||
dictionary.listAdminDictionaries = async (req, res) => {
|
||||
const resultsPerPage = req.user?.hitsPerPage || DEFAULT_HITS_PER_PAGE
|
||||
const page = +req.query.p > 0 ? +req.query.p : 1
|
||||
const { sortBy, sortDir } = resolveDictionarySort(
|
||||
req.query.sort,
|
||||
req.query.dir
|
||||
)
|
||||
const filters = parseDictionaryListFilters(req.query)
|
||||
const statusLabels = {
|
||||
closed: req.t('zaprt'),
|
||||
reviewed: req.t('v predogledu'),
|
||||
published: req.t('odprt')
|
||||
}
|
||||
|
||||
const { pages_total: numberOfAllPages, results } =
|
||||
await Dictionary.fetchAllAdminDictionaries(
|
||||
const [
|
||||
{ pages_total: numberOfAllPages, results },
|
||||
allPrimaryDomains,
|
||||
allSecondaryDomains,
|
||||
allLanguages
|
||||
] = await Promise.all([
|
||||
Dictionary.fetchAllAdminDictionaries(
|
||||
req.determinedLanguage,
|
||||
resultsPerPage,
|
||||
1
|
||||
)
|
||||
page,
|
||||
sortBy,
|
||||
sortDir,
|
||||
filters
|
||||
),
|
||||
Dictionary.fetchAllPrimaryDomains(req.determinedLanguage),
|
||||
Dictionary.fetchAllSecondaryDomainsUnfiltered(req.determinedLanguage),
|
||||
Dictionary.fetchAllLanguages(req.determinedLanguage, false)
|
||||
])
|
||||
const allStatuses = DICTIONARY_STATUSES.map(value => ({
|
||||
value,
|
||||
label: statusLabels[value]
|
||||
}))
|
||||
|
||||
res.render('pages/admin/dictionaries-list', {
|
||||
title: req.t('Seznam slovarjev'),
|
||||
numberOfAllPages,
|
||||
results
|
||||
results,
|
||||
page,
|
||||
sortBy,
|
||||
sortDir,
|
||||
q: filters.nameQuery,
|
||||
pd: filters.primaryDomainIds || [],
|
||||
sd: filters.secondaryDomainIds || [],
|
||||
lang: filters.languageIds || [],
|
||||
status: filters.statuses || [],
|
||||
allPrimaryDomains,
|
||||
allSecondaryDomains,
|
||||
allLanguages,
|
||||
allStatuses
|
||||
})
|
||||
}
|
||||
|
||||
@@ -335,6 +373,85 @@ dictionary.adminEditDescription = async (req, res) => {
|
||||
})
|
||||
}
|
||||
|
||||
dictionary.listViewableDictionaries = async (req, res) => {
|
||||
const resultsPerPage = req.user?.hitsPerPage || DEFAULT_HITS_PER_PAGE
|
||||
const page = +req.query.p > 0 ? +req.query.p : 1
|
||||
const { sortBy, sortDir } = resolveDictionarySort(
|
||||
req.query.sort,
|
||||
req.query.dir
|
||||
)
|
||||
const filters = parseDictionaryListFilters(req.query)
|
||||
const statusLabels = {
|
||||
closed: req.t('zaprt'),
|
||||
reviewed: req.t('v predogledu'),
|
||||
published: req.t('odprt')
|
||||
}
|
||||
|
||||
const [
|
||||
{ pages_total: numberOfAllPages, results },
|
||||
allPrimaryDomains,
|
||||
allSecondaryDomains,
|
||||
allLanguages
|
||||
] = await Promise.all([
|
||||
Dictionary.fetchAllAdminDictionaries(
|
||||
req.determinedLanguage,
|
||||
resultsPerPage,
|
||||
page,
|
||||
sortBy,
|
||||
sortDir,
|
||||
filters
|
||||
),
|
||||
Dictionary.fetchAllPrimaryDomains(req.determinedLanguage),
|
||||
Dictionary.fetchAllSecondaryDomainsUnfiltered(req.determinedLanguage),
|
||||
Dictionary.fetchAllLanguages(req.determinedLanguage, false)
|
||||
])
|
||||
const allStatuses = DICTIONARY_STATUSES.map(value => ({
|
||||
value,
|
||||
label: statusLabels[value]
|
||||
}))
|
||||
|
||||
res.render('pages/view-resources/list', {
|
||||
title: req.t('Seznam slovarjev'),
|
||||
numberOfAllPages,
|
||||
results,
|
||||
page,
|
||||
sortBy,
|
||||
sortDir,
|
||||
q: filters.nameQuery,
|
||||
pd: filters.primaryDomainIds || [],
|
||||
sd: filters.secondaryDomainIds || [],
|
||||
lang: filters.languageIds || [],
|
||||
status: filters.statuses || [],
|
||||
allPrimaryDomains,
|
||||
allSecondaryDomains,
|
||||
allLanguages,
|
||||
allStatuses
|
||||
})
|
||||
}
|
||||
|
||||
dictionary.viewDictionaryDetails = async (req, res) => {
|
||||
const { dictionaryId } = req.params
|
||||
const [
|
||||
allPrimaryDomains,
|
||||
dictionaryData,
|
||||
associatedSecondaryDomains,
|
||||
status
|
||||
] = await Promise.all([
|
||||
Dictionary.fetchAllPrimaryDomains(req.determinedLanguage),
|
||||
Dictionary.fetchEditDescription(dictionaryId),
|
||||
Dictionary.fetchSecondaryDomains(dictionaryId),
|
||||
Dictionary.fetchStatus(dictionaryId)
|
||||
])
|
||||
|
||||
res.render('pages/view-resources/dictionary-details', {
|
||||
title: req.t('Osnovni podatki'),
|
||||
allPrimaryDomains,
|
||||
dictionary: dictionaryData,
|
||||
associatedSecondaryDomains,
|
||||
status
|
||||
})
|
||||
}
|
||||
|
||||
dictionary.updateAdminDescription = async (req, res) => {
|
||||
// TODO Due to reindexing of all of dictionary entries on status change, this operation might take a while.
|
||||
// TODO Stress test and consider either a notification to user or alteast a progress indicator while they wait.
|
||||
@@ -344,11 +461,9 @@ dictionary.updateAdminDescription = async (req, res) => {
|
||||
|
||||
const oldDictStatus = await Dictionary.fetchStatus(dictionaryId)
|
||||
|
||||
// TODO Consider using a transaction.
|
||||
await Promise.all([
|
||||
Dictionary.updateDescription(dictionaryId, body),
|
||||
Dictionary.deleteSecondaryDomains(dictionaryId, body),
|
||||
Dictionary.updateSecondaryDomains(dictionaryId, body),
|
||||
Dictionary.updateSecondaryDomainAssociations(dictionaryId, body),
|
||||
Dictionary.updateStatus(dictionaryId, body)
|
||||
])
|
||||
|
||||
@@ -674,6 +789,7 @@ dictionary.dictionaryDetails = async (req, res) => {
|
||||
}
|
||||
|
||||
dictionary.importFromFile = async (req, res) => {
|
||||
let jobId
|
||||
try {
|
||||
await parseImportFileBody(req, res)
|
||||
// TODO return JSON error response rather then delegate to express.
|
||||
@@ -684,7 +800,7 @@ dictionary.importFromFile = async (req, res) => {
|
||||
const importFilePath = req.file.path
|
||||
const { deleteExistingEntries, entryStatus, importFileFormat } = req.body
|
||||
|
||||
await Dictionary.openImportFileJob(
|
||||
jobId = await Dictionary.openImportFileJob(
|
||||
dictionaryId,
|
||||
deleteExistingEntries,
|
||||
importFileFormat
|
||||
@@ -695,26 +811,41 @@ dictionary.importFromFile = async (req, res) => {
|
||||
await Entry.deleteAll(dictionaryId)
|
||||
}
|
||||
|
||||
await Dictionary.importFromFile(
|
||||
const { totalCount, validCount } = await Dictionary.importFromFile(
|
||||
req.user.id,
|
||||
dictionaryId,
|
||||
importFilePath,
|
||||
entryStatus
|
||||
entryStatus,
|
||||
importFileFormat
|
||||
)
|
||||
// TODO Rather then waiting for success/failure, return immediately and continue processing in the background.
|
||||
// TODO Also add API endpoint for getting progress.
|
||||
|
||||
await Dictionary.closeImportFileJob(
|
||||
jobId,
|
||||
'done',
|
||||
validCount,
|
||||
totalCount - validCount
|
||||
)
|
||||
|
||||
await Dictionary.indexIntoSearchEngine(dictionaryId)
|
||||
// TODO Error --> import job status: (indexing) error --> User manually triggers reindex.
|
||||
|
||||
debug('IMPORT SUCCESSFUL')
|
||||
|
||||
const importProcessId = 'DUMMY ID' // TODO You'll get it from DB.
|
||||
res.status(202).send(importProcessId)
|
||||
res.status(202).send({ jobId })
|
||||
} catch (error) {
|
||||
// TODO Consider writing a property on req and add an extra error handler for API errors.
|
||||
debug('IMPORT FAILED')
|
||||
debug(error)
|
||||
if (jobId) {
|
||||
try {
|
||||
await Dictionary.closeImportFileJob(jobId, 'error', 0, 0)
|
||||
} catch (closeError) {
|
||||
debug('ERROR CLOSING IMPORT FILE JOB:')
|
||||
debug(closeError)
|
||||
}
|
||||
}
|
||||
res.status(400).send(error)
|
||||
} finally {
|
||||
try {
|
||||
@@ -756,7 +887,7 @@ dictionary.exportDownload = [
|
||||
]
|
||||
|
||||
function importFileFilter(req, file, cb) {
|
||||
if (file.mimetype !== 'text/xml') {
|
||||
if (!['text/xml', 'application/json'].includes(file.mimetype)) {
|
||||
const customError = Error('Invalid file type')
|
||||
customError.displayInProd = true
|
||||
return cb(customError)
|
||||
|
||||
Reference in New Issue
Block a user