diff options
| author | Adam Malczewski <[email protected]> | 2026-03-24 13:18:50 +0900 |
|---|---|---|
| committer | Adam Malczewski <[email protected]> | 2026-03-24 13:18:50 +0900 |
| commit | bb543c3f7840f2a3fa1b7a1fb32245fa87a30f7b (patch) | |
| tree | d2a9db2741dfd9822c5f76dca278562220e9b064 /src/settings-modal.ts | |
| parent | e5583b836d4fe2f7f9806ed85a190254a6ea3990 (diff) | |
| download | ai-pulse-obsidian-plugin-bb543c3f7840f2a3fa1b7a1fb32245fa87a30f7b.tar.gz ai-pulse-obsidian-plugin-bb543c3f7840f2a3fa1b7a1fb32245fa87a30f7b.zip | |
initial prototype
Diffstat (limited to 'src/settings-modal.ts')
| -rw-r--r-- | src/settings-modal.ts | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/src/settings-modal.ts b/src/settings-modal.ts new file mode 100644 index 0000000..2daca89 --- /dev/null +++ b/src/settings-modal.ts @@ -0,0 +1,113 @@ +import { Modal, Setting } from "obsidian"; +import type AIOrganizer from "./main"; + +export class SettingsModal extends Modal { + private plugin: AIOrganizer; + + constructor(plugin: AIOrganizer) { + super(plugin.app); + this.plugin = plugin; + } + + onOpen(): void { + const { contentEl } = this; + contentEl.empty(); + contentEl.addClass("ai-organizer-settings-modal"); + + this.setTitle("AI Organizer Settings"); + + // Ollama URL setting + new Setting(contentEl) + .setName("Ollama URL") + .setDesc("Base URL of the Ollama server.") + .addText((text) => + text + .setValue(this.plugin.settings.ollamaUrl) + .onChange(async (value) => { + this.plugin.settings.ollamaUrl = value; + await this.plugin.saveSettings(); + }), + ); + + // Model dropdown + let modelDropdownSelectEl: HTMLSelectElement | null = null; + + const modelSetting = new Setting(contentEl) + .setName("Model") + .setDesc("Select the model to use.") + .addDropdown((dropdown) => { + this.populateModelDropdown(dropdown.selectEl); + dropdown.onChange(async (value) => { + this.plugin.settings.model = value; + await this.plugin.saveSettings(); + }); + modelDropdownSelectEl = dropdown.selectEl; + }); + + // Connect button + const connectSetting = new Setting(contentEl) + .setName("Connect") + .setDesc(this.plugin.connectionMessage); + + connectSetting.addButton((button) => + button.setButtonText("Connect").onClick(async () => { + const descEl = connectSetting.descEl; + descEl.setText("Connecting..."); + + await this.plugin.connect(); + + descEl.setText(this.plugin.connectionMessage); + + if (modelDropdownSelectEl !== null) { + this.populateModelDropdown(modelDropdownSelectEl); + } + }), + ); + + // Move connect above model in the DOM + contentEl.insertBefore(connectSetting.settingEl, modelSetting.settingEl); + } + + onClose(): void { + this.contentEl.empty(); + } + + private populateModelDropdown(selectEl: HTMLSelectElement): void { + const models = this.plugin.availableModels; + + selectEl.empty(); + + if (models.length === 0) { + const placeholderOpt = selectEl.createEl("option", { + text: "Connect first", + attr: { value: "" }, + }); + placeholderOpt.value = ""; + selectEl.disabled = true; + return; + } + + const placeholderOpt = selectEl.createEl("option", { + text: "Select a model...", + attr: { value: "" }, + }); + placeholderOpt.value = ""; + + for (const modelName of models) { + const opt = selectEl.createEl("option", { + text: modelName, + attr: { value: modelName }, + }); + opt.value = modelName; + } + + if ( + this.plugin.settings.model !== "" && + models.includes(this.plugin.settings.model) + ) { + selectEl.value = this.plugin.settings.model; + } + + selectEl.disabled = false; + } +} |
