mirror of
https://github.com/jxpeng98/obsidian-to-NotionNext
synced 2026-07-29 16:35:57 +08:00
complete the setting ui
This commit is contained in:
@@ -53,35 +53,13 @@ export class ObsidianSettingTab extends PluginSettingTab {
|
|||||||
// General Settings
|
// General Settings
|
||||||
containerEl.createEl('h2', { text: i18nConfig.GeneralSetting });
|
containerEl.createEl('h2', { text: i18nConfig.GeneralSetting });
|
||||||
|
|
||||||
new Setting(containerEl)
|
this.createSettingEl(containerEl, i18nConfig.BannerUrl, i18nConfig.BannerUrlDesc, 'text', i18nConfig.BannerUrlText, this.plugin.settings.bannerUrl)
|
||||||
.setName(i18nConfig.BannerUrl)
|
|
||||||
.setDesc(i18nConfig.BannerUrlDesc)
|
|
||||||
.addText((text) =>
|
|
||||||
text
|
|
||||||
.setPlaceholder(i18nConfig.BannerUrlText)
|
|
||||||
.setValue(this.plugin.settings.bannerUrl)
|
|
||||||
.onChange(async (value) => {
|
|
||||||
this.plugin.settings.bannerUrl = value;
|
|
||||||
await this.plugin.saveSettings();
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
|
this.createSettingEl(containerEl, i18nConfig.NotionUser, i18nConfig.NotionUserDesc, 'text', i18nConfig.NotionUserText, this.plugin.settings.notionUser)
|
||||||
new Setting(containerEl)
|
|
||||||
.setName(i18nConfig.NotionUser)
|
|
||||||
.setDesc(i18nConfig.NotionUserDesc)
|
|
||||||
.addText((text) =>
|
|
||||||
text
|
|
||||||
.setPlaceholder(i18nConfig.NotionUserText)
|
|
||||||
.setValue(this.plugin.settings.notionUser)
|
|
||||||
.onChange(async (value) => {
|
|
||||||
this.plugin.settings.notionUser = value;
|
|
||||||
await this.plugin.saveSettings();
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
containerEl.createEl('h2', { text: i18nConfig.NotionNextSettingHeader })
|
containerEl.createEl('h2', { text: i18nConfig.NotionNextSettingHeader })
|
||||||
|
|
||||||
|
|
||||||
new Setting(containerEl)
|
new Setting(containerEl)
|
||||||
.setName(i18nConfig.NotionNextButton)
|
.setName(i18nConfig.NotionNextButton)
|
||||||
.setDesc(i18nConfig.NotionNextButtonDesc)
|
.setDesc(i18nConfig.NotionNextButtonDesc)
|
||||||
@@ -90,61 +68,22 @@ export class ObsidianSettingTab extends PluginSettingTab {
|
|||||||
.setValue(this.plugin.settings.NextButton)
|
.setValue(this.plugin.settings.NextButton)
|
||||||
.onChange(async (value) => {
|
.onChange(async (value) => {
|
||||||
this.plugin.settings.NextButton = value;
|
this.plugin.settings.NextButton = value;
|
||||||
|
|
||||||
|
this.updateSettingEl(notionAPINextEl, value)
|
||||||
|
|
||||||
|
this.updateSettingEl(databaseIDNextEl, value)
|
||||||
|
|
||||||
await this.plugin.saveSettings();
|
await this.plugin.saveSettings();
|
||||||
await this.plugin.commands.updateCommand();
|
await this.plugin.commands.updateCommand();
|
||||||
|
|
||||||
// Clear existing components
|
|
||||||
notionAPINextEl.empty();
|
|
||||||
databaseIDNextEl.empty();
|
|
||||||
|
|
||||||
if (value) {
|
|
||||||
new Setting(notionAPINextEl)
|
|
||||||
.setName(i18nConfig.NotionAPI)
|
|
||||||
.setDesc(i18nConfig.NotionAPIDesc)
|
|
||||||
.addText((text) => {
|
|
||||||
text.inputEl.type = 'password';
|
|
||||||
return text
|
|
||||||
.setPlaceholder(i18nConfig.NotionAPIText)
|
|
||||||
.setValue(this.plugin.settings.notionAPINext)
|
|
||||||
.onChange(async (value) => {
|
|
||||||
this.plugin.settings.notionAPINext = value;
|
|
||||||
await this.plugin.saveSettings();
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
this.updateSettingEl(notionAPINextEl, value);
|
|
||||||
|
|
||||||
new Setting(databaseIDNextEl)
|
|
||||||
.setName(i18nConfig.DatabaseID)
|
|
||||||
.setDesc(i18nConfig.NotionAPIDesc)
|
|
||||||
.addText((text) => {
|
|
||||||
text.inputEl.type = 'password';
|
|
||||||
return text
|
|
||||||
.setPlaceholder(i18nConfig.DatabaseIDText)
|
|
||||||
.setValue(this.plugin.settings.databaseIDNext)
|
|
||||||
.onChange(async (value) => {
|
|
||||||
this.plugin.settings.databaseIDNext = value;
|
|
||||||
await this.plugin.saveSettings();
|
|
||||||
})
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
this.updateSettingEl(databaseIDNextEl, value)
|
|
||||||
|
|
||||||
} else {
|
|
||||||
this.updateSettingEl(notionAPINextEl, false)
|
|
||||||
this.updateSettingEl(databaseIDNextEl, false);
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
const notionAPINextEl = this.createStyleDiv('api-next')
|
|
||||||
|
|
||||||
const databaseIDNextEl = this.createStyleDiv('databaseID-next')
|
const notionAPINextEl = this.createStyleDiv('api-next', this.plugin.settings.NextButton)
|
||||||
|
this.createSettingEl(notionAPINextEl, i18nConfig.NotionAPI, i18nConfig.NotionAPIDesc, 'password', i18nConfig.NotionAPIText, this.plugin.settings.notionAPINext)
|
||||||
|
|
||||||
|
const databaseIDNextEl = this.createStyleDiv('databaseID-next', this.plugin.settings.NextButton)
|
||||||
|
this.createSettingEl(databaseIDNextEl, i18nConfig.DatabaseID, i18nConfig.NotionAPIDesc, 'password', i18nConfig.DatabaseIDText, this.plugin.settings.databaseIDNext)
|
||||||
// notionDatabaseID.controlEl.querySelector('input').type='password'
|
|
||||||
|
|
||||||
|
|
||||||
// General Database Settings
|
// General Database Settings
|
||||||
@@ -160,101 +99,37 @@ export class ObsidianSettingTab extends PluginSettingTab {
|
|||||||
.setValue(this.plugin.settings.GeneralButton)
|
.setValue(this.plugin.settings.GeneralButton)
|
||||||
.onChange(async (value) => {
|
.onChange(async (value) => {
|
||||||
this.plugin.settings.GeneralButton = value;
|
this.plugin.settings.GeneralButton = value;
|
||||||
|
|
||||||
|
this.updateSettingEl(CustomTitleEl, value)
|
||||||
|
this.updateSettingEl(notionAPIGeneralEl, value)
|
||||||
|
this.updateSettingEl(databaseIDGeneralEl, value)
|
||||||
|
|
||||||
|
|
||||||
await this.plugin.saveSettings();
|
await this.plugin.saveSettings();
|
||||||
await this.plugin.commands.updateCommand();
|
await this.plugin.commands.updateCommand();
|
||||||
|
|
||||||
// Clear existing components
|
|
||||||
CustomTitleEl.empty();
|
|
||||||
notionAPIGeneralEl.empty();
|
|
||||||
databaseIDGeneralEl.empty();
|
|
||||||
|
|
||||||
if (value) {
|
|
||||||
new Setting(CustomTitleEl)
|
|
||||||
.setName(i18nConfig.NotionCustomTitle)
|
|
||||||
.setDesc(i18nConfig.NotionCustomTitleDesc)
|
|
||||||
.addToggle((toggle) =>
|
|
||||||
toggle
|
|
||||||
.setValue(this.plugin.settings.CustomTitleButton)
|
|
||||||
.onChange(async (value) => {
|
|
||||||
this.plugin.settings.CustomTitleButton = value;
|
|
||||||
await this.plugin.saveSettings();
|
|
||||||
await this.plugin.commands.updateCommand();
|
|
||||||
|
|
||||||
// Clear existing components
|
|
||||||
CustomNameEl.empty();
|
|
||||||
|
|
||||||
// Add new components based on the toggle value
|
|
||||||
if (this.plugin.settings.CustomTitleButton) {
|
|
||||||
new Setting(CustomNameEl)
|
|
||||||
.setName(i18nConfig.NotionCustomTitleName)
|
|
||||||
.setDesc(i18nConfig.NotionCustomTitleNameDesc)
|
|
||||||
.addText((text) =>
|
|
||||||
text
|
|
||||||
.setPlaceholder(i18nConfig.NotionCustomTitleText)
|
|
||||||
.setValue(this.plugin.settings.CustomTitleName)
|
|
||||||
.onChange(async (value) => {
|
|
||||||
this.plugin.settings.CustomTitleName = value;
|
|
||||||
await this.plugin.saveSettings();
|
|
||||||
await this.plugin.commands.updateCommand();
|
|
||||||
|
|
||||||
// Clear existing components
|
|
||||||
CustomTitleEl.empty();
|
|
||||||
})
|
|
||||||
);
|
|
||||||
this.updateSettingEl(CustomNameEl, value)
|
|
||||||
} else {
|
|
||||||
this.updateSettingEl(CustomNameEl, false);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
this.updateSettingEl(CustomTitleEl, value);
|
|
||||||
|
|
||||||
new Setting(notionAPIGeneralEl)
|
|
||||||
.setName(i18nConfig.NotionAPI)
|
|
||||||
.setDesc(i18nConfig.NotionAPIDesc)
|
|
||||||
.addText((text) => {
|
|
||||||
text.inputEl.type = 'password';
|
|
||||||
return text
|
|
||||||
.setPlaceholder(i18nConfig.NotionAPIText)
|
|
||||||
.setValue(this.plugin.settings.notionAPIGeneral)
|
|
||||||
.onChange(async (value) => {
|
|
||||||
this.plugin.settings.notionAPIGeneral = value;
|
|
||||||
await this.plugin.saveSettings();
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
this.updateSettingEl(notionAPIGeneralEl, value);
|
|
||||||
|
|
||||||
|
|
||||||
new Setting(databaseIDGeneralEl)
|
|
||||||
.setName(i18nConfig.DatabaseID)
|
|
||||||
.setDesc(i18nConfig.NotionAPIDesc)
|
|
||||||
.addText((text) => {
|
|
||||||
text.inputEl.type = 'password';
|
|
||||||
return text
|
|
||||||
.setPlaceholder(i18nConfig.NotionIDText)
|
|
||||||
.setValue(this.plugin.settings.databaseIDGeneral)
|
|
||||||
.onChange(async (value) => {
|
|
||||||
this.plugin.settings.databaseIDGeneral = value;
|
|
||||||
await this.plugin.saveSettings();
|
|
||||||
})
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
this.updateSettingEl(databaseIDGeneralEl, value);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
this.updateSettingEl(CustomTitleEl, false);
|
|
||||||
this.updateSettingEl(notionAPIGeneralEl, false);
|
|
||||||
this.updateSettingEl(databaseIDGeneralEl, false);
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
const CustomTitleEl = this.createStyleDiv('custom-title');
|
const CustomTitleEl = this.createStyleDiv('custom-title', this.plugin.settings.GeneralButton);
|
||||||
|
new Setting(CustomTitleEl)
|
||||||
|
.setName(i18nConfig.NotionCustomTitle)
|
||||||
|
.setDesc(i18nConfig.NotionCustomTitleDesc)
|
||||||
|
.addToggle((toggle) =>
|
||||||
|
toggle
|
||||||
|
.setValue(this.plugin.settings.CustomTitleButton)
|
||||||
|
.onChange(async (value) => {
|
||||||
|
this.plugin.settings.CustomTitleButton = value;
|
||||||
|
|
||||||
const CustomNameEl = this.createStyleDiv('custom-name');
|
this.updateSettingEl(CustomNameEl, value)
|
||||||
|
|
||||||
|
await this.plugin.saveSettings();
|
||||||
|
await this.plugin.commands.updateCommand();
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
const CustomNameEl = this.createStyleDiv('custom-name', this.plugin.settings.CustomTitleButton);
|
||||||
|
this.createSettingEl(CustomNameEl, i18nConfig.NotionCustomTitleName, i18nConfig.NotionCustomTitleNameDesc, 'text', i18nConfig.NotionCustomTitleText, this.plugin.settings.CustomTitleName)
|
||||||
|
|
||||||
// new Setting(containerEl)
|
// new Setting(containerEl)
|
||||||
// .setName("Convert tags(optional)")
|
// .setName("Convert tags(optional)")
|
||||||
@@ -268,9 +143,12 @@ export class ObsidianSettingTab extends PluginSettingTab {
|
|||||||
// })
|
// })
|
||||||
// );
|
// );
|
||||||
|
|
||||||
const notionAPIGeneralEl = this.createStyleDiv('api-general');
|
const notionAPIGeneralEl = this.createStyleDiv('api-general', this.plugin.settings.GeneralButton);
|
||||||
|
this.createSettingEl(notionAPIGeneralEl, i18nConfig.NotionAPI, i18nConfig.NotionAPIDesc, 'password', i18nConfig.NotionAPIText, this.plugin.settings.notionAPIGeneral)
|
||||||
|
|
||||||
const databaseIDGeneralEl = this.createStyleDiv('databaseID-general');
|
|
||||||
|
const databaseIDGeneralEl = this.createStyleDiv('databaseID-general', this.plugin.settings.GeneralButton);
|
||||||
|
this.createSettingEl(databaseIDGeneralEl, i18nConfig.DatabaseID, i18nConfig.NotionAPIDesc, 'password', i18nConfig.DatabaseIDText, this.plugin.settings.databaseIDGeneral)
|
||||||
|
|
||||||
// Custom Database Settings
|
// Custom Database Settings
|
||||||
|
|
||||||
@@ -289,65 +167,65 @@ export class ObsidianSettingTab extends PluginSettingTab {
|
|||||||
// );
|
// );
|
||||||
}
|
}
|
||||||
|
|
||||||
// create a function to create a div with a style for pop over elements
|
// create a function to create a div with a style for pop over elements
|
||||||
private createStyleDiv(className: string | DomElementInfo) {
|
private createStyleDiv(className: string, commandValue: boolean = false) {
|
||||||
return this.containerEl.createDiv(className, (div) => {
|
return this.containerEl.createDiv(className, (div) => {
|
||||||
div.style.alignItems = "center";
|
this.updateSettingEl(div, commandValue);
|
||||||
div.style.borderTop = "none";
|
});
|
||||||
div.style.paddingBottom = "0";
|
}
|
||||||
});
|
// update the setting display style in the setting tab
|
||||||
|
private updateSettingEl(element: HTMLElement, commandValue: boolean) {
|
||||||
|
element.style.borderTop = commandValue ? "1px solid var(--background-modifier-border)" : "none";
|
||||||
|
element.style.paddingTop = commandValue ? "0.75em" : "0";
|
||||||
|
element.style.display = commandValue? "block" : "none";
|
||||||
|
element.style.alignItems = "center";
|
||||||
}
|
}
|
||||||
|
|
||||||
// function to add one setting element in the setting tab.
|
// function to add one setting element in the setting tab.
|
||||||
private createSettingEl(containerEl: HTMLElement, name: string, desc: string, type:string, placeholder: string, setvalue: any) {
|
private createSettingEl(containerEl: HTMLElement, name: string, desc: string, type: string, placeholder: string, holderValue: any) {
|
||||||
if (type === 'password') {
|
if (type === 'password') {
|
||||||
return new Setting(containerEl)
|
return new Setting(containerEl)
|
||||||
.setName(name)
|
.setName(name)
|
||||||
.setDesc(desc)
|
.setDesc(desc)
|
||||||
.addText((text) => {
|
.addText((text) => {
|
||||||
text.inputEl.type = type;
|
text.inputEl.type = type;
|
||||||
return text
|
return text
|
||||||
.setPlaceholder(placeholder)
|
.setPlaceholder(placeholder)
|
||||||
.setValue(setvalue)
|
.setValue(holderValue)
|
||||||
.onChange(async (value) => {
|
.onChange(async (value) => {
|
||||||
setvalue = value;
|
holderValue = value;
|
||||||
await this.plugin.saveSettings();
|
await this.plugin.saveSettings();
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
} else if (type === 'toggle') {
|
} else if (type === 'toggle') {
|
||||||
return new Setting(containerEl)
|
return new Setting(containerEl)
|
||||||
.setName(name)
|
.setName(name)
|
||||||
.setDesc(desc)
|
.setDesc(desc)
|
||||||
.addToggle((toggle) =>
|
.addToggle((toggle) =>
|
||||||
toggle
|
toggle
|
||||||
.setValue(setvalue)
|
.setValue(holderValue)
|
||||||
.onChange(async (value) => {
|
.onChange(async (value) => {
|
||||||
setvalue = value;
|
holderValue = value;
|
||||||
await this.plugin.saveSettings();
|
await this.plugin.saveSettings();
|
||||||
await this.plugin.commands.updateCommand();
|
await this.plugin.commands.updateCommand();
|
||||||
})
|
|
||||||
)
|
|
||||||
} else if (type === 'text') {
|
|
||||||
new Setting(containerEl)
|
|
||||||
.setName(name)
|
|
||||||
.setDesc(desc)
|
|
||||||
.addText((text) =>
|
|
||||||
text
|
|
||||||
.setPlaceholder(placeholder)
|
|
||||||
.setValue(setvalue)
|
|
||||||
.onChange(async (value) => {
|
|
||||||
setvalue = value;
|
|
||||||
await this.plugin.saveSettings();
|
|
||||||
await this.plugin.commands.updateCommand();
|
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
} else if (type === 'text') {
|
||||||
|
new Setting(containerEl)
|
||||||
|
.setName(name)
|
||||||
|
.setDesc(desc)
|
||||||
|
.addText((text) =>
|
||||||
|
text
|
||||||
|
.setPlaceholder(placeholder)
|
||||||
|
.setValue(holderValue)
|
||||||
|
.onChange(async (value) => {
|
||||||
|
holderValue = value;
|
||||||
|
await this.plugin.saveSettings();
|
||||||
|
await this.plugin.commands.updateCommand();
|
||||||
|
})
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// update the setting display style in the setting tab
|
|
||||||
private updateSettingEl(element: HTMLElement, value: boolean) {
|
|
||||||
element.style.borderTop = value ? "1px solid var(--background-modifier-border)" : "none";
|
|
||||||
element.style.paddingTop = value ? "0.75em" : "0";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ export class Upload2NotionGeneral extends UploadBaseGeneral {
|
|||||||
title: string,
|
title: string,
|
||||||
cover: string,
|
cover: string,
|
||||||
tags: string[],
|
tags: string[],
|
||||||
childArr: any
|
childArr: any,
|
||||||
) {
|
) {
|
||||||
const bodyString: any = {
|
const bodyString: any = {
|
||||||
parent: {
|
parent: {
|
||||||
|
|||||||
Reference in New Issue
Block a user