diff --git a/src/org/wanxp/constant/Constsant.ts b/src/org/wanxp/constant/Constsant.ts index 3020006..4912e92 100644 --- a/src/org/wanxp/constant/Constsant.ts +++ b/src/org/wanxp/constant/Constsant.ts @@ -452,3 +452,44 @@ export const PictureBedSetting_PicGo ={ export const PictureBedTypeRecords: { [key in PictureBedType]: string } = { [PictureBedType.PicGo]: PictureBedType.PicGo } + + +export enum SyncConditionType { + /** + * 最近新变动 + */ + ALL = "all", + /** + * 最近新变动 + */ + LAST_UPDATE = "lastUpdate", + + /** + * 最近10条 + */ + LAST_TEN = "lastTen", + + /** + * 自定义时间 + */ + CUSTOM_TIME = "customTime", + + /** + * 自定义条数 + */ + CUSTOM_ITEM = "customItem", + +} + +/** + * 名称模式选项 + */ +// @ts-ignore +export const SyncConditionTypeRecords: { [key in SyncConditionType]: string } = { + [SyncConditionType.ALL]: i18nHelper.getMessage('110071'), + [SyncConditionType.LAST_UPDATE]: i18nHelper.getMessage('110072'), + [SyncConditionType.LAST_TEN]: i18nHelper.getMessage('110075'), + [SyncConditionType.CUSTOM_ITEM]: i18nHelper.getMessage('110076'), + [SyncConditionType.CUSTOM_TIME]: i18nHelper.getMessage('110074'), + +} \ No newline at end of file diff --git a/src/org/wanxp/douban/component/DatePickComponent.ts b/src/org/wanxp/douban/component/DatePickComponent.ts new file mode 100644 index 0000000..7b17f34 --- /dev/null +++ b/src/org/wanxp/douban/component/DatePickComponent.ts @@ -0,0 +1,18 @@ +/** + * 日期选择组件 + * 继承自 TextComponent + */ + +import {TextComponent} from 'obsidian'; + +export class DatePickComponent extends TextComponent { + constructor(container: HTMLElement, date: Date = new Date()) { + super(container); + this.inputEl.type = 'date'; + this.inputEl.value = date.toISOString().substring(0, 10); + } + + getValue(): string { + return this.inputEl.value; + } +} diff --git a/src/org/wanxp/douban/component/DoubanSyncModal.ts b/src/org/wanxp/douban/component/DoubanSyncModal.ts index 7e51bdd..abcbbab 100644 --- a/src/org/wanxp/douban/component/DoubanSyncModal.ts +++ b/src/org/wanxp/douban/component/DoubanSyncModal.ts @@ -1,13 +1,19 @@ import { App, - ButtonComponent, - Modal, SearchComponent, Setting, + ButtonComponent, DropdownComponent, + Modal, SearchComponent, Setting, TextComponent, ValueComponent, } from "obsidian"; import DoubanPlugin from "../../main"; import {i18nHelper} from "src/org/wanxp/lang/helper"; import HandleContext from "../data/model/HandleContext"; -import {SyncType, SyncTypeRecords} from "../../constant/Constsant"; +import { + DEFAULT_SETTINGS_ARRAY_INPUT_SIZE, + SupportType, SyncConditionType, + SyncConditionTypeRecords, + SyncType, + SyncTypeRecords +} from "../../constant/Constsant"; import { ALL, DoubanSubjectStateRecords_BOOK_SYNC, @@ -25,6 +31,11 @@ import {createFileSelectionSetting} from "../setting/TemplateSettingHelper"; import {FileSuggest} from "../setting/model/FileSuggest"; import {getDefaultTemplateContent} from "../../constant/DefaultTemplateContent"; import TimeUtil from "../../utils/TimeUtil"; +import SettingsManager from "../setting/SettingsManager"; +import {ArraySetting, DEFAULT_SETTINGS_ARRAY_NAME} from "../setting/model/ArraySetting"; +import {arraySettingDisplay} from "../setting/ArrayDisplayTypeSettingsHelper"; +import {DatePickComponent} from "./DatePickComponent"; +import {NumberComponent} from "./NumberComponent"; export class DoubanSyncModal extends Modal { plugin: DoubanPlugin; @@ -122,6 +133,11 @@ ${syncStatus.getHandle() == 0? '...' : i18nHelper.getMessage('110042') + ':' + T attachmentPath: (settings.attachmentPath == '' || settings.attachmentPath == null) ? DEFAULT_SETTINGS.attachmentPath : settings.attachmentPath, templateFile: (settings.movieTemplateFile == '' || settings.movieTemplateFile == null) ? DEFAULT_SETTINGS.movieTemplateFile : settings.movieTemplateFile, incrementalUpdate: true, + syncConditionType: SyncConditionType.LAST_UPDATE, + syncConditionDateFromValue: null, + syncConditionDateToValue: null, + syncConditionCountFromValue: null, + syncConditionCountToValue: null }; this.showConfigPan(contentEl.createDiv('config'), syncConfig, false); const controls = contentEl.createDiv("controls"); @@ -160,10 +176,10 @@ ${syncStatus.getHandle() == 0? '...' : i18nHelper.getMessage('110042') + ':' + T private showConfigPan(contentEl: HTMLElement, config:SyncConfig, disable:boolean) { new Setting(contentEl); this.showTypeDropdown(contentEl, config, disable); - - this.showOutputFolderSelections(contentEl, config, disable); - this.showOutiFleName(contentEl, config, disable); - this.showAttachmentsFileConfig(contentEl, config, disable); + this.showCondition(contentEl, config, disable); + // this.showOutputFolderSelections(contentEl, config, disable); + // this.showOutiFleName(contentEl, config, disable); + // this.showAttachmentsFileConfig(contentEl, config, disable); this.showUpdateAllConfig(contentEl, config, disable); this.showForceUpdateConfig(contentEl, config, disable); } @@ -217,7 +233,7 @@ ${syncStatus.getHandle() == 0? '...' : i18nHelper.getMessage('110042') + ':' + T }); }).setDisabled(disable); this.openScopeDropdown(scopeSelections, config, disable); - this.showTemplateFileSelectionSetting(templateFile, config, disable); + // this.showTemplateFileSelectionSetting(templateFile, config, disable); } private getDefaultTemplatePath(value: string) { @@ -412,4 +428,106 @@ ${syncStatus.getHandle() == 0? '...' : i18nHelper.getMessage('110042') + ':' + T .setDisabled(disable); } + private showCondition(contentEl: HTMLElement, config: SyncConfig, disable: boolean) { + showConditionItem(contentEl.createDiv("sync-douban-condition"), this.plugin.settingsManager, config, disable); + } } + +function showConditionItem(containerEl: HTMLElement, manager: SettingsManager, config: SyncConfig, disable: boolean) { + containerEl.empty(); + const condition = new Setting(containerEl).setName(i18nHelper.getMessage('110070')) + + const conditionDesc = condition.descEl.createDiv('sync-douban-condition-desc'); + new DropdownComponent(conditionDesc).addOptions(SyncConditionTypeRecords) + .setValue(config.syncConditionType) + .onChange((value) => { + config.syncConditionType = value; + showConditionItem(containerEl, manager, config, disable); + }).setDisabled(disable); + showConditionItemInput(conditionDesc, config, disable); +} + +function showConditionItemInput(containerEl: HTMLElement, config: SyncConfig, disable: boolean) { + if (config.syncConditionType == SyncConditionType.CUSTOM_ITEM) { + showCustomInputCount(containerEl, config, disable); + }else if (config.syncConditionType == SyncConditionType.CUSTOM_TIME) { + showCustomInputTime(containerEl, config, disable); + } +} + +function showCustomInputCount(containerEl: HTMLElement, config: SyncConfig, disable: boolean) { + containerEl.createEl('span', { text: ' ' }) + containerEl.createEl('span', { text: i18nHelper.getMessage('110077') }) + containerEl.createEl('span', { text: i18nHelper.getMessage('110078') }) + const fromField = new TextComponent(containerEl); + fromField.setPlaceholder(i18nHelper.getMessage('110080')) + .setValue(config.syncConditionCountFromValue) + .onChange(async (value) => { + if (!value) { + return; + } + config.syncConditionCountFromValue = value; + }).setDisabled(disable); + let fromEl = fromField.inputEl; + fromEl.addClass('obsidian_douban_settings_input') + fromEl.style.width ='20%'; + containerEl.appendChild(fromEl); + const lang = window.localStorage.getItem('language'); + if (lang == 'zh') { + containerEl.createEl('span', {text: i18nHelper.getMessage('110073')}) + } + + containerEl.createEl('span', { text: i18nHelper.getMessage('110079') }) + containerEl.createEl('span', { text: i18nHelper.getMessage('110078') }) + const toField = new TextComponent(containerEl); + toField.setPlaceholder(i18nHelper.getMessage('110080')) + .setValue(config.syncConditionCountToValue) + .onChange(async (value) => { + if (!value) { + return; + } + config.syncConditionCountToValue = value; + }).setDisabled(disable); + let toEl = toField.inputEl; + toEl.addClass('obsidian_douban_settings_input') + toEl.style.width ='20%'; + containerEl.appendChild(toEl); + if (lang == 'zh') { + containerEl.createEl('span', {text: i18nHelper.getMessage('110073')}) + } +} + +function showCustomInputTime(containerEl: HTMLElement, config: SyncConfig, disable: boolean) { + containerEl.createEl('span', { text: i18nHelper.getMessage('110077') }) + const fromDateField = new TextComponent(containerEl); + const fromDateEl = fromDateField.inputEl; + fromDateEl.type = 'date'; + fromDateEl.value = config.syncConditionDateFromValue??TimeUtil.getLastMonth().toISOString().substring(0, 10); + fromDateField.setPlaceholder(i18nHelper.getMessage('110075')) + .setValue(config.syncConditionDateFromValue) + .onChange(async (value) => { + if (!value) { + return; + } + config.syncConditionDateFromValue = value; + }).setDisabled(disable); + fromDateEl.addClass('obsidian_douban_settings_input') + containerEl.appendChild(fromDateEl); + + containerEl.createEl('span', { text: i18nHelper.getMessage('110079') }) + const toDateField = new TextComponent(containerEl); + let toDateEl = toDateField.inputEl; + toDateEl.type = 'date'; + toDateEl.value = config.syncConditionDateToValue??new Date().toISOString().substring(0, 10); + toDateField.setPlaceholder(i18nHelper.getMessage('110075')) + .setValue(config.syncConditionDateFromValue) + .onChange(async (value) => { + if (!value) { + return; + } + config.syncConditionDateFromValue = value; + }).setDisabled(disable); + toDateEl.addClass('obsidian_douban_settings_input') + containerEl.appendChild(toDateEl); + +} \ No newline at end of file diff --git a/src/org/wanxp/douban/component/NumberComponent.ts b/src/org/wanxp/douban/component/NumberComponent.ts new file mode 100644 index 0000000..f6b1b33 --- /dev/null +++ b/src/org/wanxp/douban/component/NumberComponent.ts @@ -0,0 +1,26 @@ +/** + * 日期选择组件 + * 继承自 TextComponent + */ + +import {TextComponent} from 'obsidian'; + +export class NumberComponent extends TextComponent { + constructor(container: HTMLElement, value: number = 0) { + super(container); + this.inputEl.type = 'date'; + this.inputEl.value = value.toString(); + } + + getValue(): string { + return this.inputEl.value; + } + + //当输入框输入的内容不是数字时,则回退到之前的值 + // onChanged() { + // if (isNaN(Number(this.inputEl.value))) { + // this.inputEl.value = this.inputEl.value.slice(0, -1); + // } + // } + +} diff --git a/src/org/wanxp/douban/sync/model/SyncConfig.ts b/src/org/wanxp/douban/sync/model/SyncConfig.ts index 0f6ae1d..03b89d6 100644 --- a/src/org/wanxp/douban/sync/model/SyncConfig.ts +++ b/src/org/wanxp/douban/sync/model/SyncConfig.ts @@ -1,5 +1,10 @@ export interface SyncConfig { syncType: string, + syncConditionType: string, + syncConditionCountFromValue: string, + syncConditionCountToValue: string, + syncConditionDateFromValue: string, + syncConditionDateToValue: string, scope: string, force: boolean, dataFilePath: string; diff --git a/src/org/wanxp/lang/locale/en.ts b/src/org/wanxp/lang/locale/en.ts index 452e990..78d3293 100644 --- a/src/org/wanxp/lang/locale/en.ts +++ b/src/org/wanxp/lang/locale/en.ts @@ -33,7 +33,7 @@ export default { PS: This file could be delete if you want to. `, '110038': `DoubanSyncResult`, - '110039': `SyncNotSync:`, + '110039': `Incremental Sync:`, '110040': `Only sync that haven't been synced yet. if not enabled, will sync all the subject'`, '110041': `IncrementalSync`, '110042': `EstimateTime`, @@ -44,6 +44,17 @@ PS: This file could be delete if you want to. '110052': `Description`, '110152': `Confirm`, + '110070': `Sync Scope:`, + '110071': `All`, + '110072': `Recent Changes`, + '110075': `Last 10 Items`, + '110074': `Custom Time`, + '110076': `Custom Count`, + '110077': `From`, + '110078': `No.`, + '110079': `To`, + '110073': `Items`, + '110080': `Number`, 'exists':`[exists]`, 'unHandle':`[unHandle]`, diff --git a/src/org/wanxp/lang/locale/zh-cn.ts b/src/org/wanxp/lang/locale/zh-cn.ts index f13577c..a3a3c24 100644 --- a/src/org/wanxp/lang/locale/zh-cn.ts +++ b/src/org/wanxp/lang/locale/zh-cn.ts @@ -17,14 +17,28 @@ export default { '110010': `后台运行`, '110008': `已经存在同步任务: {0}-{1}, 结束之后再重试`, '500002': `同步状态`, - '110030': `类型:`, + '110030': `选择类型:`, '110031': `替换同名文档:`, - '110032': `范围:`, + '110032': `选择状态:`, '110033': `进度:`, '110034': `输出文件夹:`, '110035': `文档名: (提示:支持参数化以及多级路径, 可用参数见配置界面)`, '110036': `完成`, '110152': `确认`, + '110070': `同步范围:`, + '110071': `全部`, + '110072': `最新变动`, + '110075': `最近10条`, + '110074': `自定义时间`, + '110076': `自定义条数`, + '110077': `从`, + '110078': `第`, + '110079': `到`, + '110073': `条`, + '110080': `数字`, + + + '110037': ` ### 同步结果汇总 diff --git a/src/org/wanxp/utils/TimeUtil.ts b/src/org/wanxp/utils/TimeUtil.ts index 348b04f..f9496dd 100644 --- a/src/org/wanxp/utils/TimeUtil.ts +++ b/src/org/wanxp/utils/TimeUtil.ts @@ -88,7 +88,12 @@ export default class TimeUtil { } + public static getLastMonth() { + const date = new Date(); + date.setMonth(date.getMonth() - 1); + return date; + } }