diff --git a/src/ui/EditModal.ts b/src/ui/EditModal.ts index cc98c24..8f0dc17 100644 --- a/src/ui/EditModal.ts +++ b/src/ui/EditModal.ts @@ -3,8 +3,12 @@ import {SettingModal} from "./settingModal"; import ObsidianSyncNotionPlugin from "../main"; import {DatabaseDetails, ObsidianSettingTab} from "./settingTabs"; import {i18nConfig} from "../lang/I18n"; +import {customProperty} from "./settingModal"; export class EditModal extends SettingModal { + propertyLines: Setting[] = []; // Store all property line settings + properties: { customName: string, customType: string , index: number}[] = []; // Array to store property values and types + [key: string]: any; // Index signature dataTemp: Record = { databaseFormatTemp: '', // databaseFormatTempInd: false, @@ -245,19 +249,98 @@ export class EditModal extends SettingModal { .onClick(async () => { const customTabs = nextTabs.createDiv("custom-tabs"); this.createPropertyLine(customTabs); - // let customModal = new CustomModal(this.app); - // customModal.onClose = () => { - // this.renderCustomPreview(customModal.properties, nextTabs) - // this.dataTemp.customPropertiesTemp = customModal.properties; - // } - // customModal.open(); + + + }); } ); + const retrieveTabs = nextTabs.createDiv("retrieve-tabs"); + this.retrievePropertyLine(retrieveTabs, this.dataTemp.customPropertiesTemp) } - + } + retrievePropertyLine(containerEl: HTMLElement, properties: customProperty[]): void { + const propertyIndex = properties.length; + + console.log(propertyIndex, "have been created"); + + this.properties.forEach((property, index) => { + const propertyLine = new Setting(containerEl) + .setName(propertyIndex === 0 ? i18nConfig.CustomPropertyFirstColumn : `${i18nConfig.CustomProperty} ${propertyIndex}`) + .setDesc(propertyIndex === 0 ? i18nConfig.CustomPropertyFirstColumnDesc : ""); + propertyLine.addText(text => { + text.setPlaceholder(i18nConfig.CustomPropertyName) + .setValue("") + .onChange(value => { + let actualIndex = properties.findIndex(p => p.index === propertyIndex); + if (actualIndex !== -1) { + properties[actualIndex].customName = value; + } + }); + }); + + propertyLine.addDropdown((dropdown) => { + const options: Record = { + 'text': 'Text', + 'number': 'Number', + 'select': 'Select', + 'multi_select': 'Multi-Select', + 'date': 'Date', + 'files': 'Files & Media', + 'checkbox': 'Checkbox', + 'url': 'URL', + 'email': 'Email', + 'phone_number': 'Phone Number', + // 'formula': 'Formula', + // 'relation': 'Relation', + // 'rollup': 'Rollup', + // 'created_time': 'Created time', + // 'created_by': 'Created by', + // 'last_edited_time': 'Last Edited Time', + // 'last_edited_by': 'Last Edited By', + }; + + // Use a reference to the current property object + const currentProperty = properties[propertyIndex]; + + if (propertyIndex === 0) { + dropdown.addOption("title", "Title"); + } else { + Object.keys(options).forEach(key => { + dropdown.addOption(key, options[key]); + }); + } + dropdown.setValue("") + .onChange(value => { + if (currentProperty) { + currentProperty.customType = value; + // Retrieve the index of currentProperty from the properties array + const updatedIndex = properties.findIndex(p => p === currentProperty); + console.log(`Updated value at index ${updatedIndex}: ${value}`); + } else { + console.log("Property not found, may have been deleted."); + } + }); + }); + + + if (propertyIndex > 0) { + propertyLine.addButton(button => { + return button + .setTooltip("Delete") + .setIcon("trash") + .onClick(() => { + this.deleteProperty(propertyIndex); + }); + }); + } + }); + + } + + createStyleDiv(className: string, commandValue: boolean = false, parentEl: HTMLElement): HTMLDivElement {