Skip to content

Commit 962ba83

Browse files
authored
Update README.md
remove advanced example it tended to confuse users who thought they could just copy/paste and have it work
1 parent 8c1b7b9 commit 962ba83

File tree

1 file changed

+0
-131
lines changed

1 file changed

+0
-131
lines changed

README.md

Lines changed: 0 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -83,137 +83,6 @@ Make sure you add `scripts/coolString.js` to the settings page for CustomJS and
8383

8484
> ⚠️ CustomJS will initialize any class as a singleton instance. If you want to create an isolated instance use `create${className}Instance` instead, such as `createCoolStringInstance` for the above class.
8585
86-
## Advanced example
87-
88-
You can pass anything as parameters to your functions to allow for some incredible code reuse. A dataview example that I use to manage tasks:
89-
90-
#### Daily note
91-
92-
````
93-
```dataviewjs
94-
const {DvTasks} = await cJS()
95-
DvTasks.getOverdueTasks({app, dv, luxon, that:this, date:'2021-08-25'})
96-
```
97-
98-
```dataviewjs
99-
const {DvTasks} = await cJS()
100-
DvTasks.getTasksNoDueDate({app, dv, luxon, that:this})
101-
```
102-
103-
### Today's Tasks
104-
```dataviewjs
105-
const {DvTasks} = await cJS()
106-
DvTasks.getTodayTasks({app, dv, luxon, that:this, date:'2021-08-25'})
107-
```
108-
### Daily Journal
109-
````
110-
111-
#### scripts/dvTasks.js
112-
113-
```
114-
class DvTasks {
115-
relDateString(d, luxon) {
116-
if (!(d instanceof luxon.DateTime)) return '–'
117-
const now = luxon.DateTime.now()
118-
const days = Math.ceil(d.diff(now, 'days').days)
119-
if (days < 0) return 'Overdue ' + d.toFormat('L/d')
120-
if (days === 0) return 'Today'
121-
if (days === 1) return 'Tomorrow'
122-
if (days < 7) return d.toFormat('cccc')
123-
return d.toFormat('ccc L/d')
124-
}
125-
126-
getButtonStrings(status) {
127-
const completed = status === 'Completed'
128-
const btnStr = completed ? 'Undo' : 'Done'
129-
const updateStr = completed ? 'To-Do' : 'Completed'
130-
return { btnStr, updateStr }
131-
}
132-
133-
getCustomLink(name, target) {
134-
return `[[${target}|${name}]]`
135-
}
136-
137-
getTodayTasks(args) {
138-
const { luxon, dv, date, that } = args
139-
const finalDate = date ?? dv.current().file.name
140-
return this.getTasksTable({
141-
...args,
142-
filterFn: t => t.status != 'Completed' && t.dueDate && t.dueDate?.hasSame(luxon.DateTime.fromISO(finalDate), 'day')
143-
})
144-
}
145-
146-
getOverdueTasks(args) {
147-
const { luxon, dv, date, that } = args
148-
const finalDate = date ?? dv.current().file.name
149-
return this.getTasksTable({
150-
...args,
151-
prependText: 'Overdue',
152-
filterFn: t => t.dueDate && t.dueDate < luxon.DateTime.fromISO(finalDate) && t.status != 'Completed'
153-
})
154-
}
155-
156-
getTasksNoDueDate(args) {
157-
return this.getTasksTable({
158-
...args,
159-
prependText: 'No Due Date',
160-
filterFn: t => !t.dueDate
161-
})
162-
}
163-
164-
getTasksTable(args) {
165-
const {
166-
that,
167-
app,
168-
dv,
169-
luxon,
170-
getSortProp = t => t.dueDate,
171-
sortOrder = 'asc',
172-
filterFn = t => t.task,
173-
completedCol = false,
174-
prependHeaderLevel = 3,
175-
prependText
176-
} = args;
177-
const { metaedit, buttons } = app.plugins.plugins
178-
const { update } = metaedit.api
179-
const { createButton } = buttons
180-
181-
182-
const dueStr = completedCol ? 'Completed' : 'Due Date';
183-
const pages = dv.pages("#task").sort(getSortProp, sortOrder).where(filterFn)
184-
if (pages.length === 0) {
185-
// console.log('Empty dataview:', args)
186-
return
187-
}
188-
189-
if (prependText) {
190-
dv.header(prependHeaderLevel, prependText)
191-
}
192-
193-
dv.table(["Name", "Category", dueStr, "", ""], pages
194-
.map(t => {
195-
const { btnStr, updateStr } = this.getButtonStrings(t.status)
196-
return [
197-
this.getCustomLink(t.task, t.file.name),
198-
t.category,
199-
this.relDateString(t.dueDate, luxon),
200-
createButton({
201-
app,
202-
el: that.container,
203-
args: { name: btnStr },
204-
clickOverride: { click: update, params: ['Status', updateStr, t.file.path] }
205-
}),
206-
]
207-
})
208-
)
209-
}
210-
}
211-
```
212-
213-
#### Result
214-
215-
![Result](images/dvTasksExample.png)
216-
21786
---
21887

21988
## Advanced Docs

0 commit comments

Comments
 (0)