generated from obsidianmd/obsidian-sample-plugin
-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from chhoumann/kanban-support
- Loading branch information
Showing
18 changed files
with
537 additions
and
60 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
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
104 changes: 104 additions & 0 deletions
104
src/Modals/KanbanHelperSetting/KanbanHelperSettingContent.svelte
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 |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<script lang="ts"> | ||
import {KanbanProperty} from "../../Types/kanbanProperty"; | ||
import {KanbanHelperSettingSuggester} from "./KanbanHelperSettingSuggester"; | ||
import type {App, TFile} from "obsidian"; | ||
import {onDestroy, onMount} from "svelte"; | ||
export let save: (kanbanProperties: KanbanProperty[]) => void; | ||
export let kanbanProperties: KanbanProperty[] = []; | ||
export let boards: TFile[]; | ||
export let app: App; | ||
let suggestEl: HTMLInputElement; | ||
let suggester: KanbanHelperSettingSuggester; | ||
let inputValue: string; | ||
onMount(() => { | ||
suggester = new KanbanHelperSettingSuggester(app, suggestEl, boards); | ||
}) | ||
function addNewProperty() { | ||
const board: TFile = boards.find(board => board.basename === inputValue); | ||
const exists: boolean = !!kanbanProperties.find(kp => kp.boardName === board.basename); | ||
if (!board || exists) return; | ||
kanbanProperties.push({ | ||
property: "", | ||
boardName: board.basename | ||
}); | ||
kanbanProperties = kanbanProperties; // Svelte | ||
save(kanbanProperties); | ||
} | ||
function removeProperty(i: number) { | ||
kanbanProperties.splice(i, 1); | ||
kanbanProperties = kanbanProperties; // Svelte | ||
save(kanbanProperties); | ||
} | ||
function getHeadingsInBoard(boardName: string): string { | ||
const file = boards.find(board => board.basename === boardName) | ||
const headings = app.metadataCache.getFileCache(file).headings; | ||
if (!headings) return ""; | ||
return headings.map(heading => heading.heading).join(", "); | ||
} | ||
</script> | ||
|
||
<div class="centerSettingContent"> | ||
<table style="width: 100%"> | ||
<thead> | ||
<tr> | ||
<th></th> | ||
<th>Board</th> | ||
<th>Property in link</th> | ||
<th>Possible values</th> | ||
</tr> | ||
</thead> | ||
{#each kanbanProperties as kanbanProperty, i} | ||
<tr> | ||
<td> | ||
<input type="button" value="❌" class="not-a-button" on:click={() => removeProperty(i)}/> | ||
</td> | ||
<td> | ||
{kanbanProperty.boardName} | ||
</td> | ||
<td> | ||
<input on:change={() => save(kanbanProperties)} type="text" placeholder="Property name" bind:value={kanbanProperty.property}> | ||
</td> | ||
<td> | ||
{getHeadingsInBoard(kanbanProperty.boardName)} | ||
</td> | ||
</tr> | ||
<br> | ||
{/each} | ||
</table> | ||
|
||
<input bind:this={suggestEl} bind:value={inputValue} type="text"> | ||
<div class="buttonContainer"> | ||
<button on:click={addNewProperty} class="mod-cta">Add</button> | ||
</div> | ||
</div> | ||
|
||
<style> | ||
.buttonContainer { | ||
display: flex; | ||
justify-content: center; | ||
margin-top: 1rem; | ||
} | ||
select { | ||
border-radius: 4px; | ||
width: 100%; | ||
height: 30px; | ||
border: 1px solid #dbdbdc; | ||
color: #383a42; | ||
background-color: #fff; | ||
padding: 3px; | ||
} | ||
button { | ||
margin-left: 5px; | ||
margin-right: 5px; | ||
font-size: 15px; | ||
} | ||
</style> |
35 changes: 35 additions & 0 deletions
35
src/Modals/KanbanHelperSetting/KanbanHelperSettingSuggester.ts
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import {TextInputSuggest} from "../../suggest"; | ||
import type {App} from "obsidian"; | ||
import type {TFile} from "obsidian"; | ||
|
||
export class KanbanHelperSettingSuggester extends TextInputSuggest<TFile> { | ||
public app: App; | ||
public inputEl: HTMLInputElement; | ||
private boards: TFile[]; | ||
|
||
constructor(app: App, inputEl: HTMLInputElement, boards: TFile[]) { | ||
super(app, inputEl); | ||
this.app = app; | ||
this.inputEl = inputEl; | ||
this.boards = boards; | ||
} | ||
|
||
getSuggestions(inputStr: string): TFile[] { | ||
const inputLowerCase: string = inputStr.toLowerCase(); | ||
return this.boards.map(board => { | ||
if (board.basename.toLowerCase().contains(inputLowerCase)) | ||
return board; | ||
}); | ||
} | ||
|
||
selectSuggestion(item: TFile): void { | ||
this.inputEl.value = item.basename; | ||
this.inputEl.trigger("input"); | ||
this.close(); | ||
} | ||
|
||
renderSuggestion(value: TFile, el: HTMLElement): void { | ||
if (value) | ||
el.setText(value.basename); | ||
} | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export interface KanbanProperty { | ||
boardName: string, | ||
property: string | ||
} |
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,3 +1,3 @@ | ||
export const ADD_FIRST_ELEMENT: string = "cmd:addfirst"; | ||
export const ADD_TO_BEGINNING: string = "cmd:beg"; | ||
export const ADD_TO_END: string = "cmd:beg"; | ||
export const ADD_TO_END: string = "cmd:end"; |
Oops, something went wrong.