generated from pengx17/logseq-plugin-template-react
-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
TaskEntity.ts
107 lines (91 loc) · 2.37 KB
/
TaskEntity.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import { BlockEntity, PageEntity } from '@logseq/libs/dist/LSPlugin.user';
import { getBlockUUID } from '../utils';
export enum TaskMarker {
LATER = 'LATER',
NOW = 'NOW',
TODO = 'TODO',
DONE = 'DONE',
}
export enum TaskPriority {
HIGH = 'A',
MEDIUM = 'B',
LOW = 'C',
NONE = 'NONE'
}
export const TASK_PRIORITY_WEIGHT = {
[TaskPriority.HIGH]: 100,
[TaskPriority.MEDIUM]: 50,
[TaskPriority.LOW]: 10,
[TaskPriority.NONE]: 0,
};
export interface TaskEntityObject {
uuid: string;
content: string;
rawContent: string;
marker: TaskMarker;
priority: TaskPriority;
scheduled: number;
completed: boolean;
page: {
name: string;
uuid: string;
journalDay: number | undefined;
}
}
class TaskEntity {
private block: BlockEntity;
private page: PageEntity;
constructor(block: BlockEntity, page: PageEntity) {
this.block = block;
this.page = page;
}
public get uuid(): string {
return getBlockUUID(this.block);
}
public get content(): string {
let content = this.rawContent;
content = content.replace(this.block.marker, '');
content = content.replace(`[#${this.block.priority}]`, '');
content = content.replace(/SCHEDULED: <[^>]+>/, '');
content = content.replace(/DEADLINE: <[^>]+>/, '');
content = content.replace(/(:LOGBOOK:)|(\*\s.*)|(:END:)|(CLOCK:.*)/gm, '');
content = content.replace(/id::[^:]+/, '');
return content.trim();
}
public get rawContent(): string {
return this.block.content;
}
public get marker(): TaskMarker {
return this.block.marker;
}
public get priority(): TaskPriority {
return this.block.priority ?? TaskPriority.NONE;
}
public get scheduled(): number {
return this.block.scheduled ?? this.block.deadline ?? this.page.journalDay;
}
public get completed(): boolean {
return this.marker === TaskMarker.DONE;
}
public getPageProperty<T>(key: string): T {
// @ts-ignore
return this.page.properties?.[key];
}
public toObject(): TaskEntityObject {
return {
uuid: this.uuid,
content: this.content,
rawContent: this.rawContent,
marker: this.marker,
priority: this.priority,
scheduled: this.scheduled,
completed: this.completed,
page: {
name: this.page.name,
uuid: this.page.uuid,
journalDay: this.page['journalDay'],
},
};
}
}
export default TaskEntity;