mirror of
https://github.com/h-sphere/sql-seal.git
synced 2026-07-22 10:10:28 +00:00
Merge pull request #128 from kDCYorke/feature/taskHeadings
feat: Add heading and heading_level to tasks table
This commit is contained in:
commit
cde5a4df65
2 changed files with 25 additions and 13 deletions
|
|
@ -13,6 +13,7 @@ LIMIT 10
|
|||
## Table Structure
|
||||
### `files` table
|
||||
Files table consists of the following columns:
|
||||
|
||||
| Column | Description | Introduced In |
|
||||
| ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------- |
|
||||
| `id` | File Path | |
|
||||
|
|
@ -27,6 +28,7 @@ Files table consists of the following columns:
|
|||
|
||||
### `tags` table
|
||||
Tags table consists of the following columns:
|
||||
|
||||
| Column | Description | Introduced In |
|
||||
| -------- | ------------------------------------------------------------------------------------------------------------------------ | ------------- |
|
||||
| `tag` | Full tag, including `#` symbol. For example `#todo` | |
|
||||
|
|
@ -37,14 +39,17 @@ Tags table consists of the following columns:
|
|||
|
||||
### `tasks` table
|
||||
Tasks table consists of the following columns:
|
||||
| Column | Description | Introduced In |
|
||||
| ----------- | ------------------------------------------------------------------------------------------------------------------------ | ------------- |
|
||||
| `task` | Content of the task (text) | |
|
||||
| `completed` | 0 if not completed, 1 if completed | |
|
||||
| `path` | Full path of the file the tag belongs to | 0.24.1 |
|
||||
| `filePath` | (deprecated) same like `path`. Name changed for compatibility with other tables. Will get removed in the future versions | |
|
||||
| `checkbox` | Interactive checkbox for the task that can be clicked to toggle completion state | 0.29.0 |
|
||||
| `position` | Line number where the task appears in the original file | 0.29.0 |
|
||||
|
||||
| Column | Description | Introduced In |
|
||||
| --------------- |--------------------------------------------------------------------------------------------------------------------------| ------------- |
|
||||
| `task` | Content of the task (text) | |
|
||||
| `completed` | 0 if not completed, 1 if completed | |
|
||||
| `path` | Full path of the file the tag belongs to | 0.24.1 |
|
||||
| `filePath` | (deprecated) same like `path`. Name changed for compatibility with other tables. Will get removed in the future versions | |
|
||||
| `checkbox` | Interactive checkbox for the task that can be clicked to toggle completion state | 0.29.0 |
|
||||
| `position` | Line number where the task appears in the original file | 0.29.0 |
|
||||
| `heading` | The name of the heading this task appears under (if any) | |
|
||||
| `heading_level` | The level of the heading this task appears under (if any), i.e., the number of # in the heading declaration | |
|
||||
|
||||
### `links` table
|
||||
Table containing all the links between files.
|
||||
|
|
|
|||
|
|
@ -14,17 +14,18 @@ export class TasksFileSyncTable extends AFileSyncTable {
|
|||
}
|
||||
|
||||
async onFileCreate(file: TFile): Promise<void> {
|
||||
const tasks = await this.getFileTags(file)
|
||||
const tasks = await this.getFileTasks(file)
|
||||
this.db.insertData('tasks', tasks)
|
||||
}
|
||||
|
||||
async getFileTags(file: TFile) {
|
||||
async getFileTasks(file: TFile) {
|
||||
const cache = this.app.metadataCache.getFileCache(file);
|
||||
|
||||
if (!cache || !cache.listItems) return [];
|
||||
|
||||
const content = await this.app.vault.read(file);
|
||||
const lines = content.split('\n');
|
||||
const headings = cache.headings;
|
||||
|
||||
return cache.listItems.map(listItem => {
|
||||
// Check if it's a task
|
||||
|
|
@ -52,6 +53,10 @@ export class TasksFileSyncTable extends AFileSyncTable {
|
|||
}
|
||||
}
|
||||
};
|
||||
|
||||
const heading = headings ?
|
||||
headings.filter(h => h.position.start.line < listItem.position.start.line)
|
||||
.last() : undefined;
|
||||
|
||||
return {
|
||||
filePath: file.path,
|
||||
|
|
@ -59,13 +64,15 @@ export class TasksFileSyncTable extends AFileSyncTable {
|
|||
task: taskContent,
|
||||
completed: status ? 1 : 0,
|
||||
position: listItem.position.start.line,
|
||||
checkbox: `SQLSEALCUSTOM(${JSON.stringify(checkboxData)})`
|
||||
checkbox: `SQLSEALCUSTOM(${JSON.stringify(checkboxData)})`,
|
||||
heading: heading ? heading.heading : undefined,
|
||||
heading_level: heading ? heading.level : undefined
|
||||
}
|
||||
}).filter(t => !!t)
|
||||
}
|
||||
|
||||
async onInit(): Promise<void> {
|
||||
await this.db.createTableNoTypes('tasks', ['checkbox', 'task', 'completed', 'filePath', 'path', 'position'])
|
||||
await this.db.createTableNoTypes('tasks', ['checkbox', 'task', 'completed', 'filePath', 'path', 'position', 'heading', 'heading_level'])
|
||||
|
||||
// Indexes
|
||||
const toIndex = ['filePath']
|
||||
|
|
@ -73,4 +80,4 @@ export class TasksFileSyncTable extends AFileSyncTable {
|
|||
this.db.createIndex(`tasks_${column}_idx`, this.tableName, [column])
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue