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]);
if (missingItems[0].length || missingItems[1].length) {
logger.error('Item count is different');
logger.error('Items are different');
logger.error(missingItems);
process.exit(1);
}

View File

@ -211,12 +211,14 @@ commands.push({
}
}
} else { // Handle it as a glob pattern
let notes = await Note.previews(currentFolder.id, { titlePattern: pattern });
if (!notes.length) throw new Error(_('No note matches this pattern: "%s"', pattern));
let ok = force ? true : await cmdPromptConfirm(this, _('%d notes match this pattern. Delete them?', notes.length));
if (ok) {
for (let i = 0; i < notes.length; i++) {
await Note.delete(notes[i].id);
if (currentFolder) {
let notes = await Note.previews(currentFolder.id, { titlePattern: pattern });
if (!notes.length) throw new Error(_('No note matches this pattern: "%s"', pattern));
let ok = force ? true : await cmdPromptConfirm(this, _('%d notes match this pattern. Delete them?', notes.length));
if (ok) {
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>.',
action: async function(args, end) {
try {
if (!currentFolder) throw new Error(_('Please select a notebook first.'));
let pattern = args['pattern'];
let folder = await Folder.loadByField('title', args['notebook']);
@ -309,10 +313,11 @@ commands.push({
}
if (pattern) queryOptions.titlePattern = pattern;
if (pattern == '..') {
if (pattern == '..' || !currentFolder) {
items = await Folder.all(queryOptions);
suffix = '/';
} else {
if (!currentFolder) throw new Error(_('Please select a notebook first.'));
items = await Note.previews(currentFolder.id, queryOptions);
}
@ -602,10 +607,8 @@ async function synchronizer(syncTarget) {
}
function switchCurrentFolder(folder) {
if (!folder) throw new Error(_('No active folder is defined.'));
currentFolder = folder;
Setting.setValue('activeFolderId', folder.id);
Setting.setValue('activeFolderId', folder ? folder.id : '');
updatePrompt();
}
@ -799,11 +802,10 @@ async function main() {
let activeFolder = null;
if (activeFolderId) activeFolder = await Folder.load(activeFolderId);
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.'));
Setting.setValue('activeFolderId', activeFolder.id);
//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 : '');
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 (argv.length) {
@ -813,6 +815,9 @@ async function main() {
return;
} else {
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
set -e
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/Laurent.enex laurent

View File

@ -54,10 +54,7 @@ class Folder extends BaseItem {
static async delete(folderId, options = null) {
let folder = await Folder.load(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);
for (let i = 0; i < noteIds.length; i++) {
await Note.delete(noteIds[i]);