From 11a527d7ffe2ab082800f4cc0956df7ffa8141c1 Mon Sep 17 00:00:00 2001 From: Al0cam Date: Wed, 9 Oct 2024 11:10:43 +0200 Subject: [PATCH] updated UI and started work on regexRules that will move items around --- Models/MovingRule.ts | 33 +++++++++++++++++++++++++++++++++ Settings/Settings.ts | 16 ++++++++++++++++ Settings/SettingsTab.ts | 38 ++++++++++++++++++++++++++++++++++++++ main.ts | 2 +- package.json | 2 +- 5 files changed, 89 insertions(+), 2 deletions(-) create mode 100644 Models/MovingRule.ts diff --git a/Models/MovingRule.ts b/Models/MovingRule.ts new file mode 100644 index 0000000..afa295b --- /dev/null +++ b/Models/MovingRule.ts @@ -0,0 +1,33 @@ + +class MovingRule { + /** + * This filed is used for defining the regex with its group matchers + * TODO: Maybe it should be turned into a RegExp object + */ + private _regex: string; + /** + * This field is used for defining the folder to which the files will be moved + * It can use the previously defined groups to create folders with the same name + */ + private _folder: string; + + constructor(regex: string, folder: string) { + this._regex = regex; + this._folder = folder; + } + public get regex(): string { + return this._regex; + } + + public set regex(value: string) { + this._regex = value; + } + + public get folder(): string { + return this._folder; + } + + public set folder(value: string) { + this._folder = value; + } +} \ No newline at end of file diff --git a/Settings/Settings.ts b/Settings/Settings.ts index 91ce820..25ec937 100644 --- a/Settings/Settings.ts +++ b/Settings/Settings.ts @@ -5,13 +5,29 @@ export interface AutoMoverSettings { moveOnSave: boolean, moveOnClose: boolean, moveOnCreate: boolean, + movingRules: MovingRule[], } +// TODO: Define a value which accepts a regex that will be used to manage files +// the matcher group should accept an argument which will be the name of the folder to which the files will be moved +// e.g. if the file is a daily note like 14.09.2021.md, then the folder structure should be YYYY/MM/DD + + +// there should be a button in the settings to sort all the files according to given criteria +// the button should be disabled if the regex is invalid -> there are no matches + +// regex that should be accepted: +// YYYY -> year +// MM -> month +// DD -> day +// some string -> the string should be the name of the folder + export const DEFAULT_SETTINGS: Partial = { moveOnOpen: true, moveOnSave: true, moveOnClose: false, moveOnCreate: false, + movingRules: [], } function loadSettings(AutoMoverPlugin: AutoMoverPlugin): Partial { diff --git a/Settings/SettingsTab.ts b/Settings/SettingsTab.ts index f3d94f5..98f78e7 100644 --- a/Settings/SettingsTab.ts +++ b/Settings/SettingsTab.ts @@ -12,6 +12,7 @@ export class SettingsTab extends PluginSettingTab{ display(): void { let { containerEl } = this; + // maybe not required containerEl.empty(); new Setting(containerEl) @@ -23,6 +24,43 @@ export class SettingsTab extends PluginSettingTab{ this.plugin.settings.moveOnOpen = value; await this.plugin.saveData(this.plugin.settings); })); + + new Setting(containerEl) + .setName("Move on save") + .setDesc("Should the file be moved when it is saved?") + .addToggle(cb => cb + .setValue(this.plugin.settings.moveOnSave) + .onChange(async (value) => { + this.plugin.settings.moveOnSave = value; + await this.plugin.saveData(this.plugin.settings); + })); + + new Setting(containerEl) + .setName("Move on close") + .setDesc("Should the file be moved when it is closed?") + .addToggle(cb => cb + .setValue(this.plugin.settings.moveOnClose) + .onChange(async (value) => { + this.plugin.settings.moveOnClose = value; + await this.plugin.saveData(this.plugin.settings); + })); + + new Setting(containerEl) + .setName("Move on create") + .setDesc("Should the file be moved when it is created?") + .addToggle(cb => cb + .setValue(this.plugin.settings.moveOnCreate) + .onChange(async (value) => { + this.plugin.settings.moveOnCreate = value; + await this.plugin.saveData(this.plugin.settings); + })); + + // custom definition of settings list + // list of items which should be dynamic + let movingRules = containerEl.createEl('div', {cls: 'setting-item'}); + movingRules.createEl('h2', {text: 'Regex moving rules',}); + movingRules.createEl('div'); + } } \ No newline at end of file diff --git a/main.ts b/main.ts index 08c7112..c31332c 100644 --- a/main.ts +++ b/main.ts @@ -24,7 +24,7 @@ export default class AutoMoverPlugin extends Plugin { console.log(this.settings); } - asyncloadSettings() { + async asyncloadSettings() { this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData()); } diff --git a/package.json b/package.json index 25d8465..fbaee84 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "scripts": { "dev": "node esbuild.config.mjs", "build": "tsc -noEmit -skipLibCheck && node esbuild.config.mjs production", - "version": "node version-bump.mjs && git add manifest.json versions.json", + "version": "node version-bump.mjs && git add manifest.json versions.json" }, "keywords": [], "author": "",