mirror of
https://github.com/laurent22/joplin.git
synced 2025-01-11 18:24:43 +02:00
Electron: Resolves #751: Allow switching between todo and note when multiple notes are selected
This commit is contained in:
parent
79b6f64bd0
commit
f6c5620682
@ -42,4 +42,25 @@ describe('models_Note', function() {
|
||||
expect(items.length).toBe(4);
|
||||
}));
|
||||
|
||||
it('should change the type of notes', asyncTest(async () => {
|
||||
let folder1 = await Folder.save({ title: "folder1" });
|
||||
let note1 = await Note.save({ title: 'ma note', parent_id: folder1.id });
|
||||
note1 = await Note.load(note1.id);
|
||||
|
||||
let changedNote = Note.changeNoteType(note1, 'todo');
|
||||
expect(changedNote === note1).toBe(false);
|
||||
expect(!!changedNote.is_todo).toBe(true);
|
||||
await Note.save(changedNote);
|
||||
|
||||
note1 = await Note.load(note1.id);
|
||||
changedNote = Note.changeNoteType(note1, 'todo');
|
||||
expect(changedNote === note1).toBe(true);
|
||||
expect(!!changedNote.is_todo).toBe(true);
|
||||
|
||||
note1 = await Note.load(note1.id);
|
||||
changedNote = Note.changeNoteType(note1, 'note');
|
||||
expect(changedNote === note1).toBe(false);
|
||||
expect(!!changedNote.is_todo).toBe(false);
|
||||
}));
|
||||
|
||||
});
|
@ -97,13 +97,33 @@ class NoteListComponent extends React.Component {
|
||||
}
|
||||
}}));
|
||||
|
||||
menu.append(new MenuItem({label: _('Switch between note and to-do type'), click: async () => {
|
||||
for (let i = 0; i < noteIds.length; i++) {
|
||||
const note = await Note.load(noteIds[i]);
|
||||
await Note.save(Note.toggleIsTodo(note), { userSideValidation: true });
|
||||
eventManager.emit('noteTypeToggle', { noteId: note.id });
|
||||
if (noteIds.length <= 1) {
|
||||
menu.append(new MenuItem({label: _('Switch between note and to-do type'), click: async () => {
|
||||
for (let i = 0; i < noteIds.length; i++) {
|
||||
const note = await Note.load(noteIds[i]);
|
||||
await Note.save(Note.toggleIsTodo(note), { userSideValidation: true });
|
||||
eventManager.emit('noteTypeToggle', { noteId: note.id });
|
||||
}
|
||||
}}));
|
||||
} else {
|
||||
const switchNoteType = async (noteIds, type) => {
|
||||
for (let i = 0; i < noteIds.length; i++) {
|
||||
const note = await Note.load(noteIds[i]);
|
||||
const newNote = Note.changeNoteType(note, type);
|
||||
if (newNote === note) continue;
|
||||
await Note.save(newNote, { userSideValidation: true });
|
||||
eventManager.emit('noteTypeToggle', { noteId: note.id });
|
||||
}
|
||||
}
|
||||
}}));
|
||||
|
||||
menu.append(new MenuItem({label: _('Switch to note type'), click: async () => {
|
||||
await switchNoteType(noteIds, 'note');
|
||||
}}));
|
||||
|
||||
menu.append(new MenuItem({label: _('Switch to to-do type'), click: async () => {
|
||||
await switchNoteType(noteIds, 'todo');
|
||||
}}));
|
||||
}
|
||||
|
||||
menu.append(new MenuItem({label: _('Copy Markdown link'), click: async () => {
|
||||
const { clipboard } = require('electron');
|
||||
|
@ -424,17 +424,25 @@ class Note extends BaseItem {
|
||||
return Note.save(modifiedNote, { autoTimestamp: false });
|
||||
}
|
||||
|
||||
static toggleIsTodo(note) {
|
||||
static changeNoteType(note, type) {
|
||||
if (!('is_todo' in note)) throw new Error('Missing "is_todo" property');
|
||||
|
||||
let output = Object.assign({}, note);
|
||||
output.is_todo = output.is_todo ? 0 : 1;
|
||||
const newIsTodo = type === 'todo' ? 1 : 0;
|
||||
|
||||
if (Number(note.is_todo) === newIsTodo) return note;
|
||||
|
||||
const output = Object.assign({}, note);
|
||||
output.is_todo = newIsTodo;
|
||||
output.todo_due = 0;
|
||||
output.todo_completed = 0;
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
static toggleIsTodo(note) {
|
||||
return this.changeNoteType(note, !!note.is_todo ? 'note' : 'todo');
|
||||
}
|
||||
|
||||
static async duplicate(noteId, options = null) {
|
||||
const changes = options && options.changes;
|
||||
const uniqueTitle = options && options.uniqueTitle;
|
||||
|
Loading…
Reference in New Issue
Block a user