mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-24 10:27:10 +02:00
All: Simplifying serialisation of base items
This commit is contained in:
parent
127dce1cd6
commit
124a959c8d
@ -249,7 +249,7 @@ class JoplinDatabase extends Database {
|
|||||||
// default value and thus might cause problems. In that case, the default value
|
// default value and thus might cause problems. In that case, the default value
|
||||||
// must be set in the synchronizer too.
|
// must be set in the synchronizer too.
|
||||||
|
|
||||||
const existingDatabaseVersions = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
|
const existingDatabaseVersions = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13];
|
||||||
|
|
||||||
let currentVersionIndex = existingDatabaseVersions.indexOf(fromVersion);
|
let currentVersionIndex = existingDatabaseVersions.indexOf(fromVersion);
|
||||||
|
|
||||||
@ -395,6 +395,11 @@ class JoplinDatabase extends Database {
|
|||||||
queries.push('ALTER TABLE folders ADD COLUMN parent_id TEXT NOT NULL DEFAULT ""');
|
queries.push('ALTER TABLE folders ADD COLUMN parent_id TEXT NOT NULL DEFAULT ""');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (targetVersion == 13) {
|
||||||
|
queries.push('ALTER TABLE resources ADD COLUMN fetch_status INT NOT NULL DEFAULT "0"');
|
||||||
|
queries.push('ALTER TABLE resources ADD COLUMN fetch_error TEXT NOT NULL DEFAULT ""');
|
||||||
|
}
|
||||||
|
|
||||||
queries.push({ sql: 'UPDATE version SET version = ?', params: [targetVersion] });
|
queries.push({ sql: 'UPDATE version SET version = ?', params: [targetVersion] });
|
||||||
await this.transactionExecBatch(queries);
|
await this.transactionExecBatch(queries);
|
||||||
|
|
||||||
|
@ -236,7 +236,12 @@ class BaseItem extends BaseModel {
|
|||||||
return propValue;
|
return propValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
static async serialize(item, type = null, shownKeys = null) {
|
static async serialize(item, shownKeys = null) {
|
||||||
|
if (shownKeys === null) {
|
||||||
|
shownKeys = this.itemClass(item).fieldNames();
|
||||||
|
shownKeys.push('type_');
|
||||||
|
}
|
||||||
|
|
||||||
item = this.filter(item);
|
item = this.filter(item);
|
||||||
|
|
||||||
let output = {};
|
let output = {};
|
||||||
|
@ -15,13 +15,6 @@ class Folder extends BaseItem {
|
|||||||
return 'folders';
|
return 'folders';
|
||||||
}
|
}
|
||||||
|
|
||||||
static async serialize(folder) {
|
|
||||||
let fieldNames = this.fieldNames();
|
|
||||||
fieldNames.push('type_');
|
|
||||||
//lodash.pull(fieldNames, 'parent_id');
|
|
||||||
return super.serialize(folder, 'folder', fieldNames);
|
|
||||||
}
|
|
||||||
|
|
||||||
static modelType() {
|
static modelType() {
|
||||||
return BaseModel.TYPE_FOLDER;
|
return BaseModel.TYPE_FOLDER;
|
||||||
}
|
}
|
||||||
|
@ -19,12 +19,6 @@ class MasterKey extends BaseItem {
|
|||||||
return this.modelSelectOne('SELECT * FROM master_keys WHERE created_time >= (SELECT max(created_time) FROM master_keys)');
|
return this.modelSelectOne('SELECT * FROM master_keys WHERE created_time >= (SELECT max(created_time) FROM master_keys)');
|
||||||
}
|
}
|
||||||
|
|
||||||
static async serialize(item, type = null, shownKeys = null) {
|
|
||||||
let fieldNames = this.fieldNames();
|
|
||||||
fieldNames.push('type_');
|
|
||||||
return super.serialize(item, 'master_key', fieldNames);
|
|
||||||
}
|
|
||||||
|
|
||||||
static async save(o, options = null) {
|
static async save(o, options = null) {
|
||||||
return super.save(o, options).then((item) => {
|
return super.save(o, options).then((item) => {
|
||||||
this.dispatch({
|
this.dispatch({
|
||||||
|
@ -25,14 +25,8 @@ class Note extends BaseItem {
|
|||||||
return field in fieldsToLabels ? fieldsToLabels[field] : field;
|
return field in fieldsToLabels ? fieldsToLabels[field] : field;
|
||||||
}
|
}
|
||||||
|
|
||||||
static async serialize(note, type = null, shownKeys = null) {
|
|
||||||
let fieldNames = this.fieldNames();
|
|
||||||
fieldNames.push('type_');
|
|
||||||
return super.serialize(note, 'note', fieldNames);
|
|
||||||
}
|
|
||||||
|
|
||||||
static async serializeForEdit(note) {
|
static async serializeForEdit(note) {
|
||||||
return super.serialize(note, 'note', ['title', 'body']);
|
return super.serialize(note, ['title', 'body']);
|
||||||
}
|
}
|
||||||
|
|
||||||
static async unserializeForEdit(content) {
|
static async unserializeForEdit(content) {
|
||||||
@ -47,7 +41,7 @@ class Note extends BaseItem {
|
|||||||
let fieldNames = this.fieldNames();
|
let fieldNames = this.fieldNames();
|
||||||
fieldNames.push('type_');
|
fieldNames.push('type_');
|
||||||
lodash.pull(fieldNames, 'title', 'body');
|
lodash.pull(fieldNames, 'title', 'body');
|
||||||
return super.serialize(note, 'note', fieldNames);
|
return super.serialize(note, fieldNames);
|
||||||
}
|
}
|
||||||
|
|
||||||
static minimalSerializeForDisplay(note) {
|
static minimalSerializeForDisplay(note) {
|
||||||
@ -75,7 +69,7 @@ class Note extends BaseItem {
|
|||||||
lodash.pull(fieldNames, 'updated_time');
|
lodash.pull(fieldNames, 'updated_time');
|
||||||
lodash.pull(fieldNames, 'order');
|
lodash.pull(fieldNames, 'order');
|
||||||
|
|
||||||
return super.serialize(n, 'note', fieldNames);
|
return super.serialize(n, fieldNames);
|
||||||
}
|
}
|
||||||
|
|
||||||
static defaultTitle(note) {
|
static defaultTitle(note) {
|
||||||
|
@ -11,12 +11,6 @@ class NoteTag extends BaseItem {
|
|||||||
return BaseModel.TYPE_NOTE_TAG;
|
return BaseModel.TYPE_NOTE_TAG;
|
||||||
}
|
}
|
||||||
|
|
||||||
static async serialize(item, type = null, shownKeys = null) {
|
|
||||||
let fieldNames = this.fieldNames();
|
|
||||||
fieldNames.push('type_');
|
|
||||||
return super.serialize(item, 'note_tag', fieldNames);
|
|
||||||
}
|
|
||||||
|
|
||||||
static async byNoteIds(noteIds) {
|
static async byNoteIds(noteIds) {
|
||||||
if (!noteIds.length) return [];
|
if (!noteIds.length) return [];
|
||||||
return this.modelSelectAll('SELECT * FROM note_tags WHERE note_id IN ("' + noteIds.join('","') + '")');
|
return this.modelSelectAll('SELECT * FROM note_tags WHERE note_id IN ("' + noteIds.join('","') + '")');
|
||||||
|
@ -35,13 +35,6 @@ class Resource extends BaseItem {
|
|||||||
return Resource.fsDriver_;
|
return Resource.fsDriver_;
|
||||||
}
|
}
|
||||||
|
|
||||||
static async serialize(item, type = null, shownKeys = null) {
|
|
||||||
let fieldNames = this.fieldNames();
|
|
||||||
fieldNames.push('type_');
|
|
||||||
//fieldNames = ArrayUtils.removeElement(fieldNames, 'encryption_blob_encrypted');
|
|
||||||
return super.serialize(item, 'resource', fieldNames);
|
|
||||||
}
|
|
||||||
|
|
||||||
static filename(resource, encryptedBlob = false) {
|
static filename(resource, encryptedBlob = false) {
|
||||||
let extension = encryptedBlob ? 'crypted' : resource.file_extension;
|
let extension = encryptedBlob ? 'crypted' : resource.file_extension;
|
||||||
if (!extension) extension = resource.mime ? mime.toFileExtension(resource.mime) : '';
|
if (!extension) extension = resource.mime ? mime.toFileExtension(resource.mime) : '';
|
||||||
@ -199,4 +192,9 @@ class Resource extends BaseItem {
|
|||||||
|
|
||||||
Resource.IMAGE_MAX_DIMENSION = 1920;
|
Resource.IMAGE_MAX_DIMENSION = 1920;
|
||||||
|
|
||||||
|
Resource.FETCH_STATUS_IDLE = 0;
|
||||||
|
Resource.FETCH_STATUS_STARTED = 1;
|
||||||
|
Resource.FETCH_STATUS_DONE = 2;
|
||||||
|
Resource.FETCH_STATUS_ERROR = 3;
|
||||||
|
|
||||||
module.exports = Resource;
|
module.exports = Resource;
|
@ -15,12 +15,6 @@ class Tag extends BaseItem {
|
|||||||
return BaseModel.TYPE_TAG;
|
return BaseModel.TYPE_TAG;
|
||||||
}
|
}
|
||||||
|
|
||||||
static async serialize(item, type = null, shownKeys = null) {
|
|
||||||
let fieldNames = this.fieldNames();
|
|
||||||
fieldNames.push('type_');
|
|
||||||
return super.serialize(item, 'tag', fieldNames);
|
|
||||||
}
|
|
||||||
|
|
||||||
static async noteIds(tagId) {
|
static async noteIds(tagId) {
|
||||||
let rows = await this.db().selectAll('SELECT note_id FROM note_tags WHERE tag_id = ?', [tagId]);
|
let rows = await this.db().selectAll('SELECT note_id FROM note_tags WHERE tag_id = ?', [tagId]);
|
||||||
let output = [];
|
let output = [];
|
||||||
|
Loading…
Reference in New Issue
Block a user