1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-01-26 18:58:21 +02:00

Allow databases with no existing folders

This commit is contained in:
Laurent Cozic 2017-07-01 16:07:17 +01:00
parent 2ccb00b147
commit 72bfda5152
4 changed files with 22 additions and 20 deletions

View File

@ -197,7 +197,7 @@ async function compareClientItems(clientItems) {
let missingItems = findMissingItems(clientItems[0], clientItems[1]); let missingItems = findMissingItems(clientItems[0], clientItems[1]);
if (missingItems[0].length || missingItems[1].length) { if (missingItems[0].length || missingItems[1].length) {
logger.error('Item count is different'); logger.error('Items are different');
logger.error(missingItems); logger.error(missingItems);
process.exit(1); process.exit(1);
} }

View File

@ -211,12 +211,14 @@ commands.push({
} }
} }
} else { // Handle it as a glob pattern } else { // Handle it as a glob pattern
let notes = await Note.previews(currentFolder.id, { titlePattern: pattern }); if (currentFolder) {
if (!notes.length) throw new Error(_('No note matches this pattern: "%s"', pattern)); let notes = await Note.previews(currentFolder.id, { titlePattern: pattern });
let ok = force ? true : await cmdPromptConfirm(this, _('%d notes match this pattern. Delete them?', notes.length)); if (!notes.length) throw new Error(_('No note matches this pattern: "%s"', pattern));
if (ok) { let ok = force ? true : await cmdPromptConfirm(this, _('%d notes match this pattern. Delete them?', notes.length));
for (let i = 0; i < notes.length; i++) { if (ok) {
await Note.delete(notes[i].id); for (let i = 0; i < notes.length; i++) {
await Note.delete(notes[i].id);
}
} }
} }
} }
@ -234,6 +236,8 @@ commands.push({
description: 'Moves the notes matching <pattern> to <notebook>.', description: 'Moves the notes matching <pattern> to <notebook>.',
action: async function(args, end) { action: async function(args, end) {
try { try {
if (!currentFolder) throw new Error(_('Please select a notebook first.'));
let pattern = args['pattern']; let pattern = args['pattern'];
let folder = await Folder.loadByField('title', args['notebook']); let folder = await Folder.loadByField('title', args['notebook']);
@ -309,10 +313,11 @@ commands.push({
} }
if (pattern) queryOptions.titlePattern = pattern; if (pattern) queryOptions.titlePattern = pattern;
if (pattern == '..') { if (pattern == '..' || !currentFolder) {
items = await Folder.all(queryOptions); items = await Folder.all(queryOptions);
suffix = '/'; suffix = '/';
} else { } else {
if (!currentFolder) throw new Error(_('Please select a notebook first.'));
items = await Note.previews(currentFolder.id, queryOptions); items = await Note.previews(currentFolder.id, queryOptions);
} }
@ -602,10 +607,8 @@ async function synchronizer(syncTarget) {
} }
function switchCurrentFolder(folder) { function switchCurrentFolder(folder) {
if (!folder) throw new Error(_('No active folder is defined.'));
currentFolder = folder; currentFolder = folder;
Setting.setValue('activeFolderId', folder.id); Setting.setValue('activeFolderId', folder ? folder.id : '');
updatePrompt(); updatePrompt();
} }
@ -799,11 +802,10 @@ async function main() {
let activeFolder = null; let activeFolder = null;
if (activeFolderId) activeFolder = await Folder.load(activeFolderId); if (activeFolderId) activeFolder = await Folder.load(activeFolderId);
if (!activeFolder) activeFolder = await Folder.defaultFolder(); if (!activeFolder) activeFolder = await Folder.defaultFolder();
if (!activeFolder) activeFolder = await Folder.createDefaultFolder(); //if (!activeFolder) throw new Error(_('No default notebook is defined and could not create a new one. The database might be corrupted, please delete it and try again.'));
if (!activeFolder) throw new Error(_('No default notebook is defined and could not create a new one. The database might be corrupted, please delete it and try again.')); Setting.setValue('activeFolderId', activeFolder ? activeFolder.id : '');
Setting.setValue('activeFolderId', activeFolder.id);
await execCommand('cd', { 'notebook': activeFolder.title }); // Use execCommand() so that no history entry is created if (activeFolder) await execCommand('cd', { 'notebook': activeFolder.title }); // Use execCommand() so that no history entry is created
// If we still have arguments, pass it to Vorpal and exit // If we still have arguments, pass it to Vorpal and exit
if (argv.length) { if (argv.length) {
@ -813,6 +815,9 @@ async function main() {
return; return;
} else { } else {
vorpal.delimiter(promptString()).show(); vorpal.delimiter(promptString()).show();
if (!activeFolder) {
vorpal.log(_('No notebook is defined. Create one with `mkbook <notebook>`.'));
}
} }
} }

View File

@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
set -e set -e
CLIENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" CLIENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
bash $CLIENT_DIR/build.sh && NODE_PATH="$CLIENT_DIR/build/" node build/main.js --profile ~/Temp/TestNotes2 bash $CLIENT_DIR/build.sh && NODE_PATH="$CLIENT_DIR/build/" node build/main.js --profile ~/Temp/TestNotes2 "$@"
#bash $CLIENT_DIR/build.sh && NODE_PATH="$CLIENT_DIR/build/" node build/main.js --profile ~/Temp/TestNotes import-enex --fuzzy-matching /home/laurent/Desktop/afaire.enex afaire #bash $CLIENT_DIR/build.sh && NODE_PATH="$CLIENT_DIR/build/" node build/main.js --profile ~/Temp/TestNotes import-enex --fuzzy-matching /home/laurent/Desktop/afaire.enex afaire
#bash $CLIENT_DIR/build.sh && NODE_PATH="$CLIENT_DIR/build/" node build/main.js --profile ~/Temp/TestNotes import-enex --fuzzy-matching /home/laurent/Desktop/Laurent.enex laurent #bash $CLIENT_DIR/build.sh && NODE_PATH="$CLIENT_DIR/build/" node build/main.js --profile ~/Temp/TestNotes import-enex --fuzzy-matching /home/laurent/Desktop/Laurent.enex laurent

View File

@ -54,10 +54,7 @@ class Folder extends BaseItem {
static async delete(folderId, options = null) { static async delete(folderId, options = null) {
let folder = await Folder.load(folderId); let folder = await Folder.load(folderId);
if (!folder) throw new Error('Trying to delete non-existing notebook: ' + folderId); if (!folder) throw new Error('Trying to delete non-existing notebook: ' + folderId);
let count = await Folder.count();
if (count <= 1) throw new Error(_('Cannot delete the last notebook'));
let noteIds = await Folder.noteIds(folderId); let noteIds = await Folder.noteIds(folderId);
for (let i = 0; i < noteIds.length; i++) { for (let i = 0; i < noteIds.length; i++) {
await Note.delete(noteIds[i]); await Note.delete(noteIds[i]);