You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-07-13 00:10:37 +02:00
Desktop: Fix importing completed tasks (#10528)
This commit is contained in:
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
title: Not a task
|
||||||
|
---
|
||||||
|
|
||||||
|
This is a note.
|
@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
title: Task
|
||||||
|
completed?: yes
|
||||||
|
---
|
||||||
|
|
||||||
|
This is a test. This task should import as completed.
|
@ -184,4 +184,24 @@ describe('InteropService_Importer_Md_frontmatter: importMetadata', () => {
|
|||||||
const tags = (await Tag.tagsByNoteId(note.id)).map(tag => tag.title).sort();
|
const tags = (await Tag.tagsByNoteId(note.id)).map(tag => tag.title).sort();
|
||||||
expect(tags).toMatchObject(['tag1', 'tag2']);
|
expect(tags).toMatchObject(['tag1', 'tag2']);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should import completed tasks', async () => {
|
||||||
|
const note = await importTestFile('task_completed.md');
|
||||||
|
|
||||||
|
expect(note.title).toBe('Task');
|
||||||
|
expect(note.body).toBe('This is a test. This task should import as completed.\n');
|
||||||
|
expect(note.is_todo).toBe(1);
|
||||||
|
expect(note.todo_completed).toBeGreaterThan(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should import notes that are not tasks', async () => {
|
||||||
|
const note = await importTestFile('not_a_task.md');
|
||||||
|
|
||||||
|
expect(note).toMatchObject({
|
||||||
|
title: 'Not a task',
|
||||||
|
body: 'This is a note.',
|
||||||
|
is_todo: 0,
|
||||||
|
todo_completed: 0,
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -101,7 +101,7 @@ export const serialize = async (modNote: NoteEntity, tagTitles: string[]) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function isTruthy(str: string): boolean {
|
function isTruthy(str: string): boolean {
|
||||||
return str.toLowerCase() in ['true', 'yes'];
|
return ['true', 'yes'].includes(str.toLowerCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enforces exactly 2 spaces in front of list items
|
// Enforces exactly 2 spaces in front of list items
|
||||||
@ -227,7 +227,7 @@ export const parse = (note: string): ParsedMeta => {
|
|||||||
if (metadata.is_todo) {
|
if (metadata.is_todo) {
|
||||||
if (isTruthy(md['completed?'])) {
|
if (isTruthy(md['completed?'])) {
|
||||||
// Completed time isn't preserved, so we use a sane choice here
|
// Completed time isn't preserved, so we use a sane choice here
|
||||||
metadata['todo_completed'] = metadata['user_updated_time'];
|
metadata['todo_completed'] = metadata['user_updated_time'] ?? Date.now();
|
||||||
}
|
}
|
||||||
if ('due' in md) {
|
if ('due' in md) {
|
||||||
const due_date = time.anythingToMs(md['due'], null);
|
const due_date = time.anythingToMs(md['due'], null);
|
||||||
|
Reference in New Issue
Block a user