You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-11-29 22:48:10 +02:00
All: Simplifying serialisation of base items
This commit is contained in:
@@ -236,7 +236,12 @@ class BaseItem extends BaseModel {
|
||||
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);
|
||||
|
||||
let output = {};
|
||||
|
||||
@@ -15,13 +15,6 @@ class Folder extends BaseItem {
|
||||
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() {
|
||||
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)');
|
||||
}
|
||||
|
||||
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) {
|
||||
return super.save(o, options).then((item) => {
|
||||
this.dispatch({
|
||||
|
||||
@@ -25,14 +25,8 @@ class Note extends BaseItem {
|
||||
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) {
|
||||
return super.serialize(note, 'note', ['title', 'body']);
|
||||
return super.serialize(note, ['title', 'body']);
|
||||
}
|
||||
|
||||
static async unserializeForEdit(content) {
|
||||
@@ -47,7 +41,7 @@ class Note extends BaseItem {
|
||||
let fieldNames = this.fieldNames();
|
||||
fieldNames.push('type_');
|
||||
lodash.pull(fieldNames, 'title', 'body');
|
||||
return super.serialize(note, 'note', fieldNames);
|
||||
return super.serialize(note, fieldNames);
|
||||
}
|
||||
|
||||
static minimalSerializeForDisplay(note) {
|
||||
@@ -75,7 +69,7 @@ class Note extends BaseItem {
|
||||
lodash.pull(fieldNames, 'updated_time');
|
||||
lodash.pull(fieldNames, 'order');
|
||||
|
||||
return super.serialize(n, 'note', fieldNames);
|
||||
return super.serialize(n, fieldNames);
|
||||
}
|
||||
|
||||
static defaultTitle(note) {
|
||||
|
||||
@@ -11,12 +11,6 @@ class NoteTag extends BaseItem {
|
||||
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) {
|
||||
if (!noteIds.length) return [];
|
||||
return this.modelSelectAll('SELECT * FROM note_tags WHERE note_id IN ("' + noteIds.join('","') + '")');
|
||||
|
||||
@@ -35,13 +35,6 @@ class Resource extends BaseItem {
|
||||
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) {
|
||||
let extension = encryptedBlob ? 'crypted' : resource.file_extension;
|
||||
if (!extension) extension = resource.mime ? mime.toFileExtension(resource.mime) : '';
|
||||
@@ -199,4 +192,9 @@ class Resource extends BaseItem {
|
||||
|
||||
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;
|
||||
@@ -15,12 +15,6 @@ class Tag extends BaseItem {
|
||||
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) {
|
||||
let rows = await this.db().selectAll('SELECT note_id FROM note_tags WHERE tag_id = ?', [tagId]);
|
||||
let output = [];
|
||||
|
||||
Reference in New Issue
Block a user