mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-24 10:27:10 +02:00
Desktop: Create new notes with minimum set of properties to prevent a few minor bugs
This commit is contained in:
parent
e117b6f732
commit
dd557f66a5
@ -139,11 +139,15 @@ class MainScreenComponent extends React.Component {
|
||||
|
||||
const body = template ? TemplateUtils.render(template) : '';
|
||||
|
||||
const newNote = await Note.save({
|
||||
const defaultValues = Note.previewFieldsWithDefaultValues({ includeTimestamps: false });
|
||||
|
||||
let newNote = Object.assign({}, defaultValues, {
|
||||
parent_id: folderId,
|
||||
is_todo: isTodo ? 1 : 0,
|
||||
body: body,
|
||||
}, { provisional: true });
|
||||
});
|
||||
|
||||
newNote = await Note.save(newNote, { provisional: true });
|
||||
|
||||
this.props.dispatch({
|
||||
type: 'NOTE_SELECT',
|
||||
|
@ -47,6 +47,14 @@ class BaseModel {
|
||||
return null;
|
||||
}
|
||||
|
||||
static defaultValues(fieldNames) {
|
||||
const output = {};
|
||||
for (const n of fieldNames) {
|
||||
output[n] = this.db().fieldDefaultValue(this.tableName(), n);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
static modelIndexById(items, id) {
|
||||
for (let i = 0; i < items.length; i++) {
|
||||
if (items[i].id == id) return i;
|
||||
|
@ -215,6 +215,18 @@ class JoplinDatabase extends Database {
|
||||
return row;
|
||||
}
|
||||
|
||||
fieldByName(tableName, fieldName) {
|
||||
const fields = this.tableFields(tableName);
|
||||
for (const field of fields) {
|
||||
if (field.name === fieldName) return field;
|
||||
}
|
||||
throw new Error(`No such field: ${tableName}: ${fieldName}`);
|
||||
}
|
||||
|
||||
fieldDefaultValue(tableName, fieldName) {
|
||||
return this.fieldByName(tableName, fieldName).default;
|
||||
}
|
||||
|
||||
fieldDescription(tableName, fieldName) {
|
||||
const sp = sprintf;
|
||||
|
||||
|
@ -249,9 +249,24 @@ class Note extends BaseItem {
|
||||
});
|
||||
}
|
||||
|
||||
static previewFields() {
|
||||
// return ['id', 'title', 'body', 'is_todo', 'todo_completed', 'parent_id', 'updated_time', 'user_updated_time', 'user_created_time', 'encryption_applied'];
|
||||
return ['id', 'title', 'is_todo', 'todo_completed', 'parent_id', 'updated_time', 'user_updated_time', 'user_created_time', 'encryption_applied'];
|
||||
static previewFieldsWithDefaultValues(options = null) {
|
||||
return Note.defaultValues(this.previewFields(options));
|
||||
}
|
||||
|
||||
static previewFields(options = null) {
|
||||
options = Object.assign({
|
||||
includeTimestamps: true,
|
||||
}, options);
|
||||
|
||||
const output = ['id', 'title', 'is_todo', 'todo_completed', 'parent_id', 'encryption_applied'];
|
||||
|
||||
if (options.includeTimestamps) {
|
||||
output.push('updated_time');
|
||||
output.push('user_updated_time');
|
||||
output.push('user_created_time');
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
static previewFieldsSql(fields = null) {
|
||||
|
Loading…
Reference in New Issue
Block a user