-
Notifications
You must be signed in to change notification settings - Fork 0
/
model_custom.go
252 lines (214 loc) · 4.51 KB
/
model_custom.go
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
package minidoc
import (
"fmt"
"github.com/gdamore/tcell"
"strings"
)
var doctypes = []string{"url", "note", "todo", "shortcut"}
var indexedFields = map[string][]string{
"url": {"title", "description", "tags"},
"note": {"title", "note", "tags"},
"todo": {"task", "done", "tags"},
}
var excludedFields = map[string][]string{
"url": {"url"},
"note": {},
"todo": {"detail"},
}
// --------------------------------------------------------------------------------
// URL Doc
// --------------------------------------------------------------------------------
type URLDoc struct {
BaseDoc
URL string `json:"url"`
WatchLater bool `json:"watch_later"`
}
func (d *URLDoc) GetJSON() interface{} {
return JsonMapFrom(d)
}
func (d *URLDoc) HandleEvent(event *tcell.EventKey) {
eventKey := event.Key()
switch eventKey {
case tcell.KeyRune:
switch event.Rune() {
case 'o':
log.Debugf("opening url %s in the browser", d.URL)
_, err := Execute(strings.Split("open "+d.URL, " "))
if err != nil {
log.Errorf("urldoc exection: %v", err)
return
}
}
}
}
func (d *URLDoc) GetAvailableActions() string {
return "o <- open url in browser | t <- toggle watch later"
}
func (d *URLDoc) GetMarkdown() string {
return fmt.Sprintf(`[%s](%s)`, d.Title, d.URL)
}
func (d *URLDoc) GetDisplayFields() []string {
return []string{
"id",
"type",
"url",
"watch_later",
"title",
"description",
"tags",
"created_date",
}
}
func (d *URLDoc) GetEditFields() []string {
return []string{
"url",
"watch_later",
"title",
"description",
"tags",
}
}
func (d *URLDoc) GetToggleValueAsString() string {
if d.WatchLater {
return "✓️"
}
return " "
}
func (d *URLDoc) SetToggle(toggle bool) {
d.WatchLater = toggle
}
func (d *URLDoc) GetToggle() bool {
return d.WatchLater
}
// --------------------------------------------------------------------------------
// Note Doc
// --------------------------------------------------------------------------------
type NoteDoc struct {
BaseDoc
Note string `json:"note"`
}
func (d *NoteDoc) GetJSON() interface{} {
return JsonMapFrom(d)
}
func (d *NoteDoc) GetDisplayFields() []string {
return []string{
"id",
"type",
"title",
"note",
"tags",
"created_date",
}
}
func (d *NoteDoc) GetAvailableActions() string {
return "*"
}
func (d *NoteDoc) GetEditFields() []string {
return []string{
"title",
"note",
"tags",
}
}
func (d *NoteDoc) GetViEditFields() []string {
return []string{"note"}
}
func (d *NoteDoc) GetMarkdown() string {
return fmt.Sprintf(`## %s
%s
%s
%s`, d.Title, "```", d.Note, "```")
}
// --------------------------------------------------------------------------------
// TODO Doc
// --------------------------------------------------------------------------------
type ToDoDoc struct {
BaseDoc
Task string `json:"task"`
Detail string `json:"detail"`
Done bool `json:"done"`
}
func (d *ToDoDoc) GetJSON() interface{} {
return JsonMapFrom(d)
}
func (d *ToDoDoc) GetDisplayFields() []string {
return []string{
"id",
"type",
"task",
"detail",
"done",
"tags",
"created_date",
}
}
func (d *ToDoDoc) GetEditFields() []string {
return []string{
"task",
"done",
"tags",
}
}
func (d *ToDoDoc) GetViEditFields() []string {
return []string{"detail"}
}
func (d *ToDoDoc) HandleEvent(event *tcell.EventKey) {
//eventKey := event.Key()
//
//switch eventKey {
//case tcell.KeyRune:
// switch event.Rune() {
// case 'd':
// log.Debugf("marking %s as done or undone")
// }
//}
}
func (d *ToDoDoc) GetAvailableActions() string {
return "t <- toggle done"
}
func (d *ToDoDoc) GetMarkdown() string {
return fmt.Sprintf(`###%s
%s`, d.Title, d.Task)
}
func (d *ToDoDoc) GetTitle() string {
return d.Task
}
func (d *ToDoDoc) GetToggleValueAsString() string {
if d.Done {
return "✓️"
}
return " "
}
func (d *ToDoDoc) SetToggle(toggle bool) {
d.Done = toggle
}
func (d *ToDoDoc) GetToggle() bool {
return d.Done
}
// --------------------------------------------------------------------------------
// ShortcutKey Doc
// --------------------------------------------------------------------------------
type ShortcutKeyDoc struct {
BaseDoc
ShortCutKey string `json:"shortcut"`
}
func (d *ShortcutKeyDoc) GetJSON() interface{} {
return JsonMapFrom(d)
}
func (d *ShortcutKeyDoc) GetDisplayFields() []string {
return []string{
"id",
"type",
"title",
"shortcut",
"tags",
"created_date",
}
}
func (d *ShortcutKeyDoc) GetEditFields() []string {
return []string{
"title",
"shortcut",
"tags",
}
}