1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-11-27 08:21:03 +02:00

Better handling of default folder

This commit is contained in:
Laurent Cozic 2017-06-27 20:16:03 +00:00
parent 0e93a70556
commit 32b7207ea1
8 changed files with 50 additions and 15 deletions

View File

@ -305,7 +305,7 @@ commands.push({
line += item.title + suffix;
this.log(line);
}
} catch (Error) {
} catch (error) {
this.log(error);
}
@ -659,6 +659,9 @@ 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.'));
if (activeFolder) await execCommand('cd', { 'notebook': activeFolder.title }); // Use execCommand() so that no history entry is created
vorpal.delimiter(promptString()).show();

8
CliClient/build.sh Normal file → Executable file
View File

@ -1,7 +1,11 @@
#!/bin/bash
CLIENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
mkdir -p "$CLIENT_DIR/build"
rm -f "$CLIENT_DIR/app/lib"
ln -s "$CLIENT_DIR/../lib" "$CLIENT_DIR/app"
npm run build
cp "$CLIENT_DIR/package.json" "$CLIENT_DIR/build"
cp "$CLIENT_DIR/package.json" "$CLIENT_DIR/build"
# Always keep this as the last line so that the exist
# code of build.sh is the same as the build command:
npm run build

0
CliClient/install.sh Normal file → Executable file
View File

View File

@ -1,5 +1,4 @@
#!/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/TestNotes --sync-target local
bash $CLIENT_DIR/build.sh && NODE_PATH="$CLIENT_DIR/build/" node build/main.js --profile ~/Temp/TestNotes

View File

@ -13,6 +13,7 @@
"CliClient/build",
"CliClient/tests-build",
"CliClient/app/src",
"CliClient/app/lib",
"CliClient/tests/src",
"ReactNativeClient/node_modules",
"ReactNativeClient/android/app/build",

View File

@ -425,6 +425,22 @@ class Database {
});
}
static defaultFolderData() {
let now = time.unixMs();
return {
id: uuid.create(),
title: _('Notebook'),
created_time: now,
updated_time: now,
};
}
static defaultFolderQuery() {
return Database.insertQuery('folders', this.defaultFolderData());
}
initialize() {
this.logger().info('Checking for database schema update...');
@ -461,10 +477,9 @@ class Database {
this.logger().info('Database is new - creating the schema...');
let now = time.unixMs();
let queries = this.wrapQueries(this.sqlStringToLines(structureSql));
queries.push(this.wrapQuery('INSERT INTO settings (`key`, `value`, `type`) VALUES ("clientId", "' + uuid.create() + '", "' + Database.enumId('settings', 'string') + '")'));
queries.push(this.wrapQuery('INSERT INTO folders (`id`, `title`, `created_time`, `updated_time`) VALUES ("' + uuid.create() + '", "' + _('Notebook') + '", ' + now + ', ' + now + ')'));
queries.push(Database.defaultFolderQuery());
return this.transactionExecBatch(queries).then(() => {
this.logger().info('Database schema created successfully');

View File

@ -89,10 +89,15 @@ class Folder extends BaseItem {
return folders.concat(notes);
}
static async defaultFolder() {
static defaultFolder() {
return this.modelSelectOne('SELECT * FROM folders ORDER BY created_time DESC LIMIT 1');
}
static createDefaultFolder() {
let folder = Database.defaultFolderData();
return Folder.save(folder, { isNew: true });
}
static save(o, options = null) {
return Folder.loadByField('title', o.title).then((existingFolder) => {
if (existingFolder && existingFolder.id != o.id) throw new Error(_('A notebook with title "%s" already exists', o.title));

View File

@ -28,6 +28,15 @@ class Setting extends BaseModel {
return this.keys_;
}
static publicKeys() {
let output = [];
for (let n in this.defaults_) {
if (!this.defaults_.hasOwnProperty(n)) continue;
if (this.defaults_[n].public) output.push(n);
}
return output;
}
static load() {
this.cancelScheduleUpdate();
this.cache_ = [];
@ -110,8 +119,8 @@ class Setting extends BaseModel {
return BaseModel.db().transactionExecBatch(queries).then(() => {
this.logger().info('Settings have been saved.');
}).catch((error) => {
this.logger().warn('Could not save settings', error);
reject(error);
this.logger().error('Could not save settings');
this.logger().error(error);
});
}
@ -131,11 +140,10 @@ class Setting extends BaseModel {
}
Setting.defaults_ = {
'clientId': { value: '', type: 'string' },
'sessionId': { value: '', type: 'string' },
'activeFolderId': { value: '', type: 'string' },
'sync.onedrive.auth': { value: '', type: 'string' },
'sync.target': { value: 'onedrive', type: 'string' },
'clientId': { value: '', type: 'string', public: false },
'activeFolderId': { value: '', type: 'string', public: false },
'sync.onedrive.auth': { value: '', type: 'string', public: false },
'sync.target': { value: 'onedrive', type: 'string', public: true },
};
// Contains constants that are set by the application and