mirror of
https://github.com/sismics/docs.git
synced 2024-12-25 12:43:49 +01:00
Closes #210: choose a tag applied on documents
This commit is contained in:
parent
83b065180f
commit
0409c2ef79
@ -6,6 +6,7 @@ import com.sismics.docs.core.dao.jpa.DocumentDao;
|
||||
import com.sismics.docs.core.dao.lucene.LuceneDao;
|
||||
import com.sismics.docs.core.event.DocumentUpdatedAsyncEvent;
|
||||
import com.sismics.docs.core.model.jpa.Contributor;
|
||||
import com.sismics.docs.core.model.jpa.Document;
|
||||
import com.sismics.docs.core.util.TransactionUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -38,7 +39,12 @@ public class DocumentUpdatedAsyncListener {
|
||||
// Update Lucene index
|
||||
DocumentDao documentDao = new DocumentDao();
|
||||
LuceneDao luceneDao = new LuceneDao();
|
||||
luceneDao.updateDocument(documentDao.getById(event.getDocumentId()));
|
||||
Document document = documentDao.getById(event.getDocumentId());
|
||||
if (document == null) {
|
||||
// Document deleted since event fired
|
||||
return;
|
||||
}
|
||||
luceneDao.updateDocument(document);
|
||||
|
||||
// Update contributors list
|
||||
ContributorDao contributorDao = new ContributorDao();
|
||||
|
@ -6,6 +6,7 @@ const inquirer = require('inquirer');
|
||||
const preferences = require('preferences');
|
||||
const fs = require('fs');
|
||||
const argv = require('minimist')(process.argv);
|
||||
const _ = require('underscore');
|
||||
const request = require('request').defaults({
|
||||
jar: true
|
||||
});
|
||||
@ -140,13 +141,54 @@ const askPath = () => {
|
||||
|
||||
recursive(answers.path, function (error, files) {
|
||||
spinner.succeed(files.length + ' files in this directory');
|
||||
askDaemon();
|
||||
askTag();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
// Ask for the tag to add
|
||||
const askTag = () => {
|
||||
console.log('');
|
||||
|
||||
// Load tags
|
||||
const spinner = ora({
|
||||
text: 'Loading tags',
|
||||
spinner: 'flips'
|
||||
}).start();
|
||||
|
||||
request.get({
|
||||
url: prefs.importer.baseUrl + '/api/tag/list',
|
||||
}, function (error, response, body) {
|
||||
if (error || !response || response.statusCode !== 200) {
|
||||
spinner.fail('Error loading tags');
|
||||
askTag();
|
||||
return;
|
||||
}
|
||||
|
||||
spinner.succeed('Tags loaded');
|
||||
const tags = JSON.parse(body).tags;
|
||||
const defaultTag = _.findWhere(tags, { id: prefs.importer.tag });
|
||||
const defaultTagName = defaultTag ? defaultTag.name : 'No tag';
|
||||
|
||||
inquirer.prompt([
|
||||
{
|
||||
type: 'list',
|
||||
name: 'tag',
|
||||
message: 'Which tag to add on imported documents?',
|
||||
default: defaultTagName,
|
||||
choices: [ 'No tag' ].concat(_.pluck(tags, 'name'))
|
||||
}
|
||||
]).then(answers => {
|
||||
// Save tag
|
||||
prefs.importer.tag = answers.tag === 'No tag' ?
|
||||
'' : _.findWhere(tags, { name: answers.tag }).id;
|
||||
askDaemon();
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
// Ask for daemon mode
|
||||
const askDaemon = () => {
|
||||
console.log('');
|
||||
@ -232,7 +274,8 @@ const importFile = (file, remove, resolve) => {
|
||||
url: prefs.importer.baseUrl + '/api/document',
|
||||
form: {
|
||||
title: file.replace(/^.*[\\\/]/, ''),
|
||||
language: 'eng'
|
||||
language: 'eng',
|
||||
tags: prefs.importer.tag === '' ? undefined : prefs.importer.tag
|
||||
}
|
||||
}, function (error, response, body) {
|
||||
if (error || !response || response.statusCode !== 200) {
|
||||
@ -266,8 +309,9 @@ const importFile = (file, remove, resolve) => {
|
||||
if (argv.hasOwnProperty('d')) {
|
||||
console.log('Starting in quiet mode with the following configuration:\n' +
|
||||
'Base URL: ' + prefs.importer.baseUrl + '\n' +
|
||||
'Username: ' + prefs.importer.username + '\n' +
|
||||
'Username: ' + prefs.importer.username + '\n' +
|
||||
'Password: ***********\n' +
|
||||
'Tag: ' + prefs.importer.tag + '\n' +
|
||||
'Daemon mode: ' + prefs.importer.daemon);
|
||||
start();
|
||||
} else {
|
||||
|
5
docs-importer/package-lock.json
generated
5
docs-importer/package-lock.json
generated
@ -738,6 +738,11 @@
|
||||
"integrity": "sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q=",
|
||||
"optional": true
|
||||
},
|
||||
"underscore": {
|
||||
"version": "1.8.3",
|
||||
"resolved": "https://registry.npmjs.org/underscore/-/underscore-1.8.3.tgz",
|
||||
"integrity": "sha1-Tz+1OxBuYJf8+ctBCfKl6b36UCI="
|
||||
},
|
||||
"uuid": {
|
||||
"version": "3.2.1",
|
||||
"resolved": "https://registry.npmjs.org/uuid/-/uuid-3.2.1.tgz",
|
||||
|
@ -22,6 +22,7 @@
|
||||
"ora": "^2.0.0",
|
||||
"preferences": "^1.0.2",
|
||||
"recursive-readdir": "^2.2.2",
|
||||
"request": "^2.83.0"
|
||||
"request": "^2.83.0",
|
||||
"underscore": "^1.8.3"
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user