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

Better handling of source

This commit is contained in:
Laurent Cozic 2017-06-29 21:52:52 +01:00
parent 9060ed489c
commit 5f6db113cf
11 changed files with 57 additions and 27 deletions

View File

@ -301,7 +301,6 @@ function importEnex(parentFolderId, filePath, importOptions = null) {
note.todo_completed = dateToTimestamp(noteAttributes['reminder-done-time'], true);
note.order = dateToTimestamp(noteAttributes['reminder-order'], true);
note.source = !!noteAttributes.source ? 'evernote.' + noteAttributes.source : 'evernote';
note.source_application = 'joplin.cli';
// if (noteAttributes['reminder-time']) {
// console.info('======================================================');

View File

@ -34,6 +34,8 @@ let initArgs = {
profileDir: null,
}
Setting.setConstant('appId', 'net.cozic.joplin-cli');
let currentFolder = null;
let commands = [];
let database_ = null;
@ -339,7 +341,7 @@ commands.push({
commands.push({
usage: 'import-enex <file> [notebook]',
description: _('Imports en Evernote notebook file (.enex file).'),
description: _('Imports an Evernote notebook file (.enex file).'),
options: [
['--fuzzy-matching', 'For debugging purposes. Do not use.'],
],
@ -699,7 +701,7 @@ async function main() {
o.action(c.action);
}
vorpal.history('net.cozic.joplin'); // Enables persistent history
vorpal.history(Setting.value('appId')); // Enables persistent history
let argv = process.argv;
argv = await handleStartFlags(argv);

View File

@ -1,16 +1,23 @@
{
"name": "joplin-cli",
"description": "CLI client for Joplin",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/laurent22/joplin"
},
"url": "git://github.com/laurent22/joplin.git",
"version": "0.8.14",
"bin": {
"joplin": "./main.sh"
},
"dependencies": {
"babel-plugin-transform-runtime": "^6.23.0",
"source-map-support": "^0.4.15",
"app-module-path": "^2.2.0",
"babel-plugin-transform-runtime": "^6.23.0",
"form-data": "^2.1.4",
"fs-extra": "^3.0.1",
"jssha": "^2.3.0",
"lodash": "^4.17.4",
"mkdirp": "^0.5.1",
"moment": "^2.18.1",
"moment-timezone": "^0.5.13",
@ -19,6 +26,7 @@
"query-string": "4.3.4",
"sax": "^1.2.2",
"server-destroy": "^1.0.1",
"source-map-support": "^0.4.15",
"sprintf-js": "^1.1.1",
"sqlite3": "^3.1.8",
"string-to-stream": "^1.1.0",

View File

@ -11,6 +11,8 @@ process.on('unhandledRejection', (reason, p) => {
console.log('Unhandled Rejection at: Promise', p, 'reason:', reason);
});
jasmine.DEFAULT_TIMEOUT_INTERVAL = 9000; // The first test is slow because the database needs to be built
async function allItems() {
let folders = await Folder.all();
let notes = await Note.all();

View File

@ -223,14 +223,12 @@ class BaseModel {
query.id = modelId;
// Log.info('Saving', JSON.stringify(o));
return query;
}
static save(o, options = null) {
options = this.modOptions(options);
options.isNew = options.isNew == 'auto' ? !o.id : options.isNew;
options.isNew = this.isNew(o, options);
o = this.filter(o);
@ -254,6 +252,16 @@ class BaseModel {
});
}
static isNew(object, options) {
if (options && ('isNew' in options)) {
// options.isNew can be "auto" too
if (options.isNew === true) return true;
if (options.isNew === false) return false;
}
return !object.id;
}
static deletedItems() {
return this.db().selectAll('SELECT * FROM deleted_items');
}
@ -295,17 +303,6 @@ class BaseModel {
if (trackDeleted) {
return this.db().exec('INSERT INTO deleted_items (item_type, item_id, deleted_time) VALUES (?, ?, ?)', [this.itemType(), id, time.unixMs()]);
}
// if (options.trackChanges && this.trackChanges()) {
// const { Change } = require('src/models/change.js');
// let change = Change.newChange();
// change.type = Change.TYPE_DELETE;
// change.item_id = id;
// change.item_type = this.itemType();
// return Change.save(change);
// }
});
}

View File

@ -15,6 +15,10 @@ CREATE TABLE folders (
sync_time INT NOT NULL DEFAULT 0
);
CREATE INDEX folders_title ON folders (title);
CREATE INDEX folders_updated_time ON folders (updated_time);
CREATE INDEX folders_sync_time ON folders (sync_time);
CREATE TABLE notes (
id TEXT PRIMARY KEY,
parent_id TEXT NOT NULL DEFAULT "",
@ -38,6 +42,13 @@ CREATE TABLE notes (
\`order\` INT NOT NULL DEFAULT 0
);
CREATE INDEX notes_title ON notes (title);
CREATE INDEX notes_updated_time ON notes (updated_time);
CREATE INDEX notes_sync_time ON notes (sync_time);
CREATE INDEX notes_is_conflict ON notes (is_conflict);
CREATE INDEX notes_is_todo ON notes (is_todo);
CREATE INDEX notes_order ON notes (\`order\`);
CREATE TABLE deleted_items (
id INTEGER PRIMARY KEY,
item_type INT NOT NULL,

View File

@ -76,7 +76,7 @@ class FileApiDriverLocal {
return promiseChain(chain).then((results) => {
if (!results) results = [];
resolve({
items: results
items: results,
hasMore: false,
context: null,
});

View File

@ -85,6 +85,8 @@ class BaseItem extends BaseModel {
}
static serialize(item, type = null, shownKeys = null) {
item = this.filter(item);
let output = [];
output.push(item.title);

View File

@ -6,6 +6,7 @@ import { Setting } from 'lib/models/setting.js';
import { _ } from 'lib/locale.js';
import moment from 'moment';
import { BaseItem } from 'lib/models/base-item.js';
import lodash from 'lodash';
class Folder extends BaseItem {
@ -14,7 +15,10 @@ class Folder extends BaseItem {
}
static serialize(folder) {
return super.serialize(folder, 'folder', ['id', 'created_time', 'updated_time', 'type_']);
let fieldNames = this.fieldNames();
fieldNames.push('type_');
lodash.pull(fieldNames, 'parent_id', 'sync_time');
return super.serialize(folder, 'folder', fieldNames);
}
static itemType() {

View File

@ -3,7 +3,9 @@ import { Log } from 'lib/log.js';
import { Folder } from 'lib/models/folder.js';
import { GeolocationReact } from 'lib/geolocation-react.js';
import { BaseItem } from 'lib/models/base-item.js';
import { Setting } from 'lib/models/setting.js';
import moment from 'moment';
import lodash from 'lodash';
class Note extends BaseItem {
@ -12,7 +14,10 @@ class Note extends BaseItem {
}
static serialize(note, type = null, shownKeys = null) {
return super.serialize(note, 'note', ["author", "longitude", "latitude", "is_todo", "todo_due", "todo_completed", 'created_time', 'updated_time', 'id', 'parent_id', 'type_']);
let fieldNames = this.fieldNames();
fieldNames.push('type_');
lodash.pull(fieldNames, 'is_conflict', 'sync_time');
return super.serialize(note, 'note', fieldNames);
}
static itemType() {
@ -116,12 +121,11 @@ class Note extends BaseItem {
return output;
}
// static all(options = null) {
// let q = this.applySqlOptions(options, 'SELECT * FROM notes WHERE is_conflict = 0 AND parent_id = ?', [parentId]);
// return this.modelSelectAll(q.sql, q.params);
// }
static save(o, options = null) {
let isNew = this.isNew(o, options);
if (isNew && !o.source) o.source = Setting.value('appName');
if (isNew && !o.source_application) o.source_application = Setting.value('appId');
return super.save(o, options).then((result) => {
// 'result' could be a partial one at this point (if, for example, only one property of it was saved)
// so call this.preview() so that the right fields are populated.

View File

@ -149,6 +149,7 @@ Setting.defaults_ = {
// cannot be modified by the user:
Setting.constants_ = {
'appName': 'joplin',
'appId': 'SET_ME', // Each app should set this identifier
}
export { Setting };