You've already forked joplin
							
							
				mirror of
				https://github.com/laurent22/joplin.git
				synced 2025-10-31 00:07:48 +02:00 
			
		
		
		
	Allow setting single note field only to produce minimal changeset
This commit is contained in:
		| @@ -170,6 +170,7 @@ class BaseModel { | ||||
| 				} else { | ||||
| 					for (let n in o) { | ||||
| 						if (!o.hasOwnProperty(n)) continue; | ||||
| 						if (n == 'id') continue; | ||||
|  | ||||
| 						let change = Change.newChange(); | ||||
| 						change.type = Change.TYPE_UPDATE; | ||||
|   | ||||
| @@ -33,12 +33,14 @@ class ItemListComponent extends Component { | ||||
| 		}); | ||||
| 	} | ||||
|  | ||||
| 	todoCheckbox_change(itemId, checked) { | ||||
| 		Note.load(itemId).then((oldNote) => { | ||||
| 			let newNote = Object.assign({}, oldNote); | ||||
| 			newNote.todo_completed = checked; | ||||
| 			return NoteFolderService.save('note', newNote, oldNote); | ||||
| 		}); | ||||
| 	todoCheckbox_change(itemId, checked) {	 | ||||
| 		NoteFolderService.setField('note', itemId, 'todo_completed', checked); | ||||
| 		 | ||||
| 		// Note.load(itemId).then((oldNote) => { | ||||
| 		// 	let newNote = Object.assign({}, oldNote); | ||||
| 		// 	newNote.todo_completed = checked; | ||||
| 		// 	return NoteFolderService.save('note', newNote, oldNote); | ||||
| 		// }); | ||||
| 	} | ||||
|  | ||||
| 	listView_itemPress = (itemId) => {} | ||||
|   | ||||
| @@ -32,8 +32,12 @@ class Note extends BaseModel { | ||||
| 		return output; | ||||
| 	} | ||||
|  | ||||
| 	static previewFieldsSql() { | ||||
| 		return '`id`, `title`, `body`, `is_todo`, `todo_completed`, `parent_id`, `updated_time`' | ||||
| 	} | ||||
|  | ||||
| 	static previews(parentId) { | ||||
| 		return this.db().selectAll('SELECT id, title, body, is_todo, todo_completed, parent_id, updated_time FROM notes WHERE parent_id = ?', [parentId]).then((r) => { | ||||
| 		return this.db().selectAll('SELECT ' + this.previewFieldsSql() + ' FROM notes WHERE parent_id = ?', [parentId]).then((r) => { | ||||
| 			let output = []; | ||||
| 			for (let i = 0; i < r.rows.length; i++) { | ||||
| 				output.push(r.rows.item(i)); | ||||
| @@ -42,6 +46,10 @@ class Note extends BaseModel { | ||||
| 		}); | ||||
| 	} | ||||
|  | ||||
| 	static preview(noteId) { | ||||
| 		return this.db().selectOne('SELECT ' + this.previewFieldsSql() + ' FROM notes WHERE id = ?', [noteId]); | ||||
| 	} | ||||
|  | ||||
| 	static updateGeolocation(noteId) { | ||||
| 		Log.info('Updating lat/long of note ' + noteId); | ||||
|  | ||||
| @@ -62,7 +70,11 @@ class Note extends BaseModel { | ||||
| 	} | ||||
|  | ||||
| 	static save(o, options = null) { | ||||
| 		return super.save(o, options).then((note) => { | ||||
| 		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. | ||||
| 			return this.preview(result.id); | ||||
| 		}).then((note) => { | ||||
| 			this.dispatch({ | ||||
| 				type: 'NOTES_UPDATE_ONE', | ||||
| 				note: note, | ||||
|   | ||||
| @@ -36,16 +36,16 @@ class NoteFolderService extends BaseService { | ||||
| 		}); | ||||
| 	} | ||||
|  | ||||
| 	// static setField(type, itemId, fieldName, fieldValue, oldValue = undefined) { | ||||
| 	// 	// TODO: not really consistent as the promise will return 'null' while | ||||
| 	// 	// this.save will return the note or folder. Currently not used, and maybe not needed. | ||||
| 	// 	if (oldValue !== undefined && fieldValue === oldValue) return Promise.resolve(); | ||||
| 	static setField(type, itemId, fieldName, fieldValue, oldValue = undefined) { | ||||
| 		// TODO: not really consistent as the promise will return 'null' while | ||||
| 		// this.save will return the note or folder. Currently not used, and maybe not needed. | ||||
| 		if (oldValue !== undefined && fieldValue === oldValue) return Promise.resolve(); | ||||
|  | ||||
| 	// 	let item = { id: itemId }; | ||||
| 	// 	item[fieldName] = fieldValue; | ||||
| 	// 	let oldItem = { id: itemId }; | ||||
| 	// 	return this.save(type, item, oldItem); | ||||
| 	// } | ||||
| 		let item = { id: itemId }; | ||||
| 		item[fieldName] = fieldValue; | ||||
| 		let oldItem = { id: itemId }; | ||||
| 		return this.save(type, item, oldItem); | ||||
| 	} | ||||
|  | ||||
| 	static openNoteList(folderId) { | ||||
| 		return Note.previews(folderId).then((notes) => { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user