From 96e77cbb566376a8de94f067e69a61155a121302 Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Sun, 25 Jun 2017 11:41:03 +0100 Subject: [PATCH] More CLI changes --- CliClient/app/main.js | 42 ++++++++++++++++++++++++------------------ lib/base-model.js | 4 ++++ lib/models/setting.js | 8 ++++---- 3 files changed, 32 insertions(+), 22 deletions(-) diff --git a/CliClient/app/main.js b/CliClient/app/main.js index cbf93e73ba..b2a33e419c 100644 --- a/CliClient/app/main.js +++ b/CliClient/app/main.js @@ -123,7 +123,10 @@ async function main() { // return; function switchCurrentFolder(folder) { + if (!folder) throw new Error(_('No active folder is defined.')); + currentFolder = folder; + Setting.setValue('activeFolderId', folder.id); updatePrompt(); } @@ -192,21 +195,6 @@ async function main() { } }); - commands.push({ - usage: 'use ', - aliases: ['cd'], - description: 'Switches to [notebook-title] - all further operations will happen within this notebook.', - action: async function(args, end) { - let folderTitle = args['notebook-title']; - - let folder = await Folder.loadByField('title', folderTitle); - if (!folder) return commandError(this, _('Invalid folder title: %s', folderTitle), end); - switchCurrentFolder(folder); - end(); - }, - autocomplete: autocompleteFolders, - }); - commands.push({ usage: 'mkbook ', aliases: ['mkdir'], @@ -244,6 +232,21 @@ async function main() { }, }); + commands.push({ + usage: 'use ', + aliases: ['cd'], + description: 'Switches to [notebook-title] - all further operations will happen within this notebook.', + action: async function(args, end) { + let folderTitle = args['notebook-title']; + + let folder = await Folder.loadByField('title', folderTitle); + if (!folder) return commandError(this, _('Invalid folder title: %s', folderTitle), end); + switchCurrentFolder(folder); + end(); + }, + autocomplete: autocompleteFolders, + }); + commands.push({ usage: 'set [prop-value]', description: 'Sets the given of the given item.', @@ -422,7 +425,7 @@ async function main() { commands.push({ usage: 'import-enex', - description: _('Imports a .enex file (Evernote export file).'), + description: _('Imports a .enex file (Evernote notebook file).'), action: function(args, end) { end(); @@ -478,8 +481,11 @@ async function main() { vorpal.history('net.cozic.joplin'); // Enables persistent history - let defaultFolder = await Folder.defaultFolder(); - if (defaultFolder) await execCommand('cd', { 'notebook-title': defaultFolder.title }); // Use execCommand() so that no history entry is created + let activeFolderId = Setting.value('activeFolderId'); + let activeFolder = null; + if (activeFolderId) activeFolder = await Folder.load(activeFolderId); + if (!activeFolder) activeFolder = await Folder.defaultFolder(); + if (activeFolder) await execCommand('cd', { 'notebook-title': activeFolder.title }); // Use execCommand() so that no history entry is created vorpal.delimiter(promptString()).show(); diff --git a/lib/base-model.js b/lib/base-model.js index 4395d0c1f0..3ba15ba27f 100644 --- a/lib/base-model.js +++ b/lib/base-model.js @@ -21,6 +21,10 @@ class BaseModel { } } + static logger() { + return this.db().logger(); + } + static tableName() { throw new Error('Must be overriden'); } diff --git a/lib/models/setting.js b/lib/models/setting.js index 8751f3fc43..e7f62f38ed 100644 --- a/lib/models/setting.js +++ b/lib/models/setting.js @@ -1,5 +1,4 @@ import { BaseModel } from 'lib/base-model.js'; -import { Log } from 'lib/log.js'; import { Database } from 'lib/database.js'; class Setting extends BaseModel { @@ -98,7 +97,7 @@ class Setting extends BaseModel { static saveAll() { if (!this.updateTimeoutId_) return Promise.resolve(); - Log.info('Saving settings...'); + this.logger().info('Saving settings...'); clearTimeout(this.updateTimeoutId_); this.updateTimeoutId_ = null; @@ -109,9 +108,9 @@ class Setting extends BaseModel { } return BaseModel.db().transactionExecBatch(queries).then(() => { - Log.info('Settings have been saved.'); + this.logger().info('Settings have been saved.'); }).catch((error) => { - Log.warn('Could not save settings', error); + this.logger().warn('Could not save settings', error); reject(error); }); } @@ -134,6 +133,7 @@ class Setting extends BaseModel { Setting.defaults_ = { 'clientId': { value: '', type: 'string' }, 'sessionId': { value: '', type: 'string' }, + 'activeFolderId': { value: '', type: 'string' }, 'user.email': { value: '', type: 'string' }, 'user.session': { value: '', type: 'string' }, 'sync.lastRevId': { value: 0, type: 'int' }, // DEPRECATED