diff --git a/main.ts b/main.ts index 1ff7e4b..bc5c00c 100644 --- a/main.ts +++ b/main.ts @@ -10,26 +10,27 @@ import { TextComponent, ToggleComponent } from 'obsidian'; +import { AsanaPluginSettings, DEFAULT_SETTINGS, AsanaSettingTab } from './settings/settings'; -/** - * Interface for plugin settings. - */ -interface AsanaPluginSettings { - asanaToken: string; - markTaskAsCompleted: boolean; - pinnedProjects: string[]; // Array of project IDs or names - enableMarkdownLink: boolean; -} +// /** +// * Interface for plugin settings. +// */ +// interface AsanaPluginSettings { +// asanaToken: string; +// markTaskAsCompleted: boolean; +// pinnedProjects: string[]; // Array of project IDs or names +// enableMarkdownLink: boolean; +// } -/** - * Default settings for the plugin. - */ -const DEFAULT_SETTINGS: AsanaPluginSettings = { - asanaToken: '', - markTaskAsCompleted: false, - pinnedProjects: [], - enableMarkdownLink: true, -}; +// /** +// * Default settings for the plugin. +// */ +// const DEFAULT_SETTINGS: AsanaPluginSettings = { +// asanaToken: '', +// markTaskAsCompleted: false, +// pinnedProjects: [], +// enableMarkdownLink: true, +// }; /** * Main plugin class. @@ -429,7 +430,7 @@ class FuzzySelectModal extends FuzzySuggestModal<{ name: string; gid: string; is super.onOpen(); this.setTitle('herer is the titme'); this.setPlaceholder(this.title); - this.setInstructions('here is the instruction'); + // this.setInstructions('here is the instruction'); } getItems(): Array<{ name: string; gid: string; isPinned?: boolean }> { @@ -451,76 +452,4 @@ class FuzzySelectModal extends FuzzySuggestModal<{ name: string; gid: string; is console.warn(`ITEM CHOSEN MULTIPLE TIMES - Ignoring extra selection: ${item.name}`); } } -} - -/** - * Plugin settings tab. - */ -class AsanaSettingTab extends PluginSettingTab { - plugin: AsanaPlugin; - - constructor(app: App, plugin: AsanaPlugin) { - super(app, plugin); - this.plugin = plugin; - } - - display(): void { - const { containerEl } = this; - - containerEl.empty(); - - containerEl.createEl('h2', { text: 'Asana Task Creator Settings' }); - - // Asana Personal Access Token Setting - new Setting(containerEl) - .setName('Asana Personal Access Token') - .setDesc( - 'Enter your Asana Personal Access Token. You can create one in your Asana account settings.' - ) - .addText((text: TextComponent) => { - text.setPlaceholder('Enter your token') // Correct usage of TextComponent - .setValue(this.plugin.settings.asanaToken) - .onChange(async (value: string) => { // Explicitly type `value` - this.plugin.settings.asanaToken = value.trim(); - await this.plugin.saveSettings(); - }); - }); - - // Mark Task as Completed Setting - new Setting(containerEl) - .setName('Mark Task as Completed') - .setDesc('Automatically mark the task as completed in Obsidian after creating it in Asana.') - .addToggle((toggle: ToggleComponent) => { - toggle.setValue(this.plugin.settings.markTaskAsCompleted) - .onChange(async (value: boolean) => { // Explicitly type `value` - this.plugin.settings.markTaskAsCompleted = value; - await this.plugin.saveSettings(); - }); - }); - - new Setting(containerEl) - .setName('Enable Markdown Link') - .setDesc('Insert a markdown link to the task record in the note after task creation.') - .addToggle((toggle) => - toggle.setValue(this.plugin.settings.enableMarkdownLink).onChange(async (value) => { - this.plugin.settings.enableMarkdownLink = value; - await this.plugin.saveSettings(); - }) - ); - - // Add pinned projects - new Setting(containerEl) - .setName('Pinned Projects') - .setDesc('Enter project names or IDs to pin them in the project selection modal.') - .addTextArea((textArea) => - textArea - .setPlaceholder('Enter project names/IDs, one per line') - .setValue(this.plugin.settings.pinnedProjects.join('\n')) - .onChange(async (value: string) => { - this.plugin.settings.pinnedProjects = value.split('\n').map((item) => item.trim()); - await this.plugin.saveSettings(); - }) - ); - - } } \ No newline at end of file diff --git a/settings/settings.ts b/settings/settings.ts new file mode 100644 index 0000000..ee8416d --- /dev/null +++ b/settings/settings.ts @@ -0,0 +1,102 @@ +import { App, PluginSettingTab, Setting, TextComponent, ToggleComponent } from 'obsidian'; +import AsanaPlugin from '../main'; + +/** + * Interface defining plugin settings. + */ +export interface AsanaPluginSettings { + asanaToken: string; + markTaskAsCompleted: boolean; + pinnedProjects: string[]; + enableMarkdownLink: boolean; +} + +/** + * Default settings for the plugin. + */ +export const DEFAULT_SETTINGS: AsanaPluginSettings = { + asanaToken: '', + markTaskAsCompleted: false, + pinnedProjects: [], + enableMarkdownLink: true, +}; + +/** + * Settings tab for configuring the plugin. + */ +export class AsanaSettingTab extends PluginSettingTab { + plugin: AsanaPlugin; + + constructor(app: App, plugin: AsanaPlugin) { + super(app, plugin); + this.plugin = plugin; + } + + display(): void { + const { containerEl } = this; + containerEl.empty(); + + containerEl.createEl('h2', { text: 'Asana Task Creator Settings' }); + + // Personal Access Token Setting + const patDesc = document.createDocumentFragment(); + patDesc.append( + "Enter your Asana Personal Access Token. You can create one in the ", + patDesc.createEl("a", { + href: "https://app.asana.com/0/my-apps", + text: "Asana My Apps", + }), + " section." + ); + + new Setting(containerEl) + .setName('Asana Personal Access Token') + .setDesc(patDesc) + .addText((text: TextComponent) => { + text.setPlaceholder('Enter your token') + .setValue(this.plugin.settings.asanaToken) + .onChange(async (value: string) => { + this.plugin.settings.asanaToken = value.trim(); + await this.plugin.saveSettings(); + }); + }); + + // Toggle: Mark Task as Completed + new Setting(containerEl) + .setName('Mark Task as Completed') + .setDesc('Automatically mark the task as completed in Obsidian after creating it in Asana.') + .addToggle((toggle: ToggleComponent) => { + toggle.setValue(this.plugin.settings.markTaskAsCompleted) + .onChange(async (value: boolean) => { + this.plugin.settings.markTaskAsCompleted = value; + await this.plugin.saveSettings(); + }); + }); + + // Toggle: Enable Markdown Link + new Setting(containerEl) + .setName('Enable Markdown Link') + .setDesc('Insert a markdown link to the task in the note after task creation.') + .addToggle((toggle: ToggleComponent) => { + toggle.setValue(this.plugin.settings.enableMarkdownLink) + .onChange(async (value: boolean) => { + this.plugin.settings.enableMarkdownLink = value; + await this.plugin.saveSettings(); + }); + }); + + // Pinned Projects Input + new Setting(containerEl) + .setName('Pinned Projects') + .setDesc('Enter project names or IDs to pin them in the project selection modal.') + .addTextArea((textArea) => + textArea + .setPlaceholder('Enter project names/IDs, one per line') + .setValue(this.plugin.settings.pinnedProjects.join('\n')) + .onChange(async (value: string) => { + this.plugin.settings.pinnedProjects = value.split('\n').map((item) => item.trim()); + await this.plugin.saveSettings(); + }) + ); + } +} \ No newline at end of file