updated UI and started work on regexRules that will move items around

This commit is contained in:
Al0cam 2024-10-09 11:10:43 +02:00
parent 608dded6b5
commit 11a527d7ff
5 changed files with 89 additions and 2 deletions

33
Models/MovingRule.ts Normal file
View file

@ -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;
}
}

View file

@ -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<AutoMoverSettings> = {
moveOnOpen: true,
moveOnSave: true,
moveOnClose: false,
moveOnCreate: false,
movingRules: [],
}
function loadSettings(AutoMoverPlugin: AutoMoverPlugin): Partial<AutoMoverSettings> {

View file

@ -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');
}
}

View file

@ -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());
}

View file

@ -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": "",