-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
413 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,139 @@ | ||
<template> | ||
<div> | ||
<button @click="searchHandle">查询</button> | ||
<div id="resultContainer"></div> | ||
<!-- <Teleport to="body" disable="false"> | ||
<div v-html="mdText"></div> | ||
</Teleport> --> | ||
<div v-for="task in taskList" :key="task.blockId" @mouseenter="previewTask(task)" @click="completeTask(task)"> | ||
{{ task.text }} | ||
<div class="taskListContainer"> | ||
<div | ||
v-for="task in taskList" | ||
:key="task.blockId" | ||
@mouseenter="previewTask($event, task)" | ||
@click="onClicked($event, task)" | ||
> | ||
<input type="checkbox" :checked="task.status !== ' '" @click="onChecked($event, task)" /> | ||
{{ task.text }} | ||
</div> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { Component, MarkdownPreviewView, MarkdownView } from 'obsidian'; | ||
import { STask, getAPI as getDataviewApi } from 'obsidian-dataview'; | ||
import { Component, MarkdownPreviewView, MarkdownView, Platform } from 'obsidian'; | ||
import { type SListItem, STask, getAPI as getDataviewApi } from 'obsidian-dataview'; | ||
import { type Ref, ref } from 'vue'; | ||
import { listTasks, queryAll, queryImportantTasks } from '@/utils/dataview'; | ||
import { | ||
concentrateTasks, | ||
importantTasks, | ||
listTasks, | ||
queryAll, | ||
queryImportantTasks, | ||
rewriteTask, | ||
setTaskCompletion, | ||
} from '@/utils/dataview'; | ||
const keyword = ref(''); | ||
let mdText = ref(''); | ||
const taskList: Ref<STask[]> = ref([]); | ||
const DataviewAPI = getDataviewApi(); | ||
const searchHandle = async () => { | ||
const DataviewAPI = getDataviewApi(); | ||
// query | ||
mdText.value = (await DataviewAPI.queryMarkdown(listTasks)).value; | ||
// mdText.value = (await DataviewAPI.queryMarkdown(listTasks)).value; | ||
// taskList.value | ||
const res = await DataviewAPI.query(listTasks); | ||
const res = await DataviewAPI.query(concentrateTasks); | ||
taskList.value = res.value.values; | ||
console.log(taskList.value); | ||
const component = new Component(); | ||
const container = document.querySelector('#resultContainer'); | ||
// console.log(taskList.value); | ||
// const component = new Component(); | ||
// const container = document.querySelector('#resultContainer'); | ||
// executeJs | ||
// const res = await DataviewAPI.execute(queryImportantTasks, container, component, ''); | ||
// console.log(res); | ||
}; | ||
const previewTask = async (task: STask) => { | ||
// xxx | ||
console.log('previewTask', task); | ||
searchHandle(); | ||
// DataviewAPI.index.revision | ||
const refreshOperation = async () => { | ||
searchHandle(); | ||
}; | ||
// DataviewAPI.index.onChange(refreshOperation); | ||
app.workspace.on('dataview:refresh-views', refreshOperation); | ||
const previewTask = async (event, item: STask) => { | ||
// 延迟触发,鼠标移出后取消触发 | ||
// console.log('previewTask', item); | ||
}; | ||
const completeTask = async (task: STask) => { | ||
console.log('completeTask', task); | ||
const onClicked = async (evt, item: STask) => { | ||
const selectionState = { | ||
eState: { | ||
cursor: { | ||
from: { line: item.line, ch: item.position.start.col }, | ||
to: { line: item.line + item.lineCount - 1, ch: item.position.end.col }, | ||
}, | ||
line: item.line, | ||
}, | ||
}; | ||
app.workspace.openLinkText( | ||
item.link.toFile().obsidianLink(), | ||
item.path, | ||
evt.ctrlKey || (evt.metaKey && Platform.isMacOS), | ||
selectionState as any, | ||
); | ||
}; | ||
const onChecked = async (evt, item: STask) => { | ||
evt.stopPropagation(); | ||
const completed = evt.currentTarget.checked; | ||
const status = completed ? 'x' : ' '; | ||
// Update data-task on the parent element (css style) | ||
const parent = evt.currentTarget.parentElement; | ||
parent?.setAttribute('data-task', status); | ||
let flatted: STask[] = [item]; | ||
const recursiveSubTaskCompletion = true; | ||
const taskCompletionTracking = true; | ||
const taskCompletionUseEmojiShorthand = true; | ||
const taskCompletionText = 'completion'; | ||
const taskCompletionDateFormat = 'yyyy-MM-dd'; | ||
function flatter(iitem: STask | SListItem) { | ||
flatted.push(iitem as STask); | ||
iitem.children.forEach(flatter); | ||
} | ||
if (recursiveSubTaskCompletion) { | ||
item.children.forEach(flatter); | ||
flatted = flatted.flat(Infinity); | ||
} | ||
async function effectFn() { | ||
for (let i = 0; i < flatted.length; i++) { | ||
const _item = flatted[i]; | ||
let updatedText: string = _item.text; | ||
if (taskCompletionTracking) { | ||
updatedText = setTaskCompletion( | ||
_item.text, | ||
taskCompletionUseEmojiShorthand, | ||
taskCompletionText, | ||
taskCompletionDateFormat, | ||
completed, | ||
); | ||
} | ||
await rewriteTask(app.vault, _item, status, updatedText); | ||
} | ||
app.workspace.trigger('dataview:refresh-views'); | ||
} | ||
effectFn(); | ||
}; | ||
</script> | ||
|
||
<style lang="scss" scoped></style> | ||
<style lang="scss" scoped> | ||
.taskListContainer { | ||
margin: 8px 0; | ||
} | ||
</style> |
Oops, something went wrong.