-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
158 lines (146 loc) · 3.61 KB
/
main.js
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import Plugin from 'imdone-api'
import {
Settings,
ArrayProperty,
StringProperty,
} from 'imdone-api/lib/settings'
export default class SamplePlugin extends Plugin {
constructor(project) {
super(project)
}
onTaskUpdate(task) {
task.interpretedContent = task.interpretedContent.replace(
/- \[x\] (.*)$/gm,
(match, p1) => {
return `- [x] ~~${p1}~~`
}
)
}
getCardProperties(task) {
const { source, line, totals } = task
return {
date: new Date().toDateString(),
time: new Date().toLocaleTimeString(),
timestamp: new Date().toISOString(),
sourceLink: source && `[${source.path}:${line}](${source.path}:${line})`,
}
}
getBoardActions() {
const project = this.project
return [
{
name: 'Filter for urgent cards',
action: () => {
project.setFilter('allTags = urgent')
},
},
{
name: 'Add a card in TODO',
action: () => {
project.newCard({ list: 'TODO' })
},
},
{
name: 'Test snackBar',
action: () => {
project.snackBar({ message: 'Testing snackBar' })
},
},
{
name: 'Test toast',
action: () => {
project.toast({ message: 'Testing toast' })
},
},
]
}
getCardActions(task) {
return [
...this.getTagActions(task),
...this.getMetaActions(task),
{
action: () => {
this.project.copyToClipboard(
task.desc.rawMarkdown,
'Markdown copied to clipboard!'
)
},
icon: 'markdown',
pack: 'fab',
title: 'Copy markdown',
},
{
action: () => {
this.project.copyToClipboard(
task.desc.html,
'HTML copied to clipboard!'
)
},
icon: 'copy',
pack: 'fas',
title: 'Copy html',
},
]
}
getMetaActions(task) {
return this.getMeta()
.filter(
({ key, value }) =>
!(task.allMeta[key] && task.allMeta[key].includes(value))
)
.map(({ key, value }) => {
return {
action: () => {
this.project.addMetadata(task, key, value)
},
icon: 'table',
pack: 'fas',
title: `Add metadata ${key} = ${value}`,
}
})
}
getTagActions(task) {
return this.getTags()
.filter(({ name }) => !task.allTags.includes(name))
.map(({ name }) => {
return {
action: () => {
this.project.addTag(task, name)
},
icon: 'tag',
pack: 'fas',
title: `Add ${name} tag`,
}
})
}
getTags() {
return this.getSettings().tags || []
}
getMeta() {
return this.getSettings().meta || []
}
getSettingsSchema() {
if (this.settingSchema) return this.settingSchema
this.settingSchema = new Settings()
.addProperty(
'tags',
new ArrayProperty()
.itemsDraggable(true)
.setTitle('Tags')
.setDescription('Quick add tags from card menu.')
.itemTitle('Tag')
.addItemProperty('name', new StringProperty().setTitle('Name'))
)
.addProperty(
'meta',
new ArrayProperty()
.itemsDraggable(true)
.setTitle('Metadata')
.setDescription('Quick set metadata from card menu.')
.itemTitle('Key, value pair')
.addItemProperty('key', new StringProperty().setTitle('Key'))
.addItemProperty('value', new StringProperty().setTitle('Value'))
)
return this.settingSchema
}
}