fix #139 增加过滤条件:时间或条数限制

This commit is contained in:
Wanxp 2025-02-25 16:01:05 +08:00 committed by wanxp
parent dc225f30f1
commit ea700e481e
8 changed files with 249 additions and 11 deletions

@ -452,3 +452,44 @@ export const PictureBedSetting_PicGo ={
export const PictureBedTypeRecords: { [key in PictureBedType]: string } = { export const PictureBedTypeRecords: { [key in PictureBedType]: string } = {
[PictureBedType.PicGo]: PictureBedType.PicGo [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'),
}

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

@ -1,13 +1,19 @@
import { import {
App, App,
ButtonComponent, ButtonComponent, DropdownComponent,
Modal, SearchComponent, Setting, Modal, SearchComponent, Setting, TextComponent, ValueComponent,
} from "obsidian"; } from "obsidian";
import DoubanPlugin from "../../main"; import DoubanPlugin from "../../main";
import {i18nHelper} from "src/org/wanxp/lang/helper"; import {i18nHelper} from "src/org/wanxp/lang/helper";
import HandleContext from "../data/model/HandleContext"; 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 { import {
ALL, ALL,
DoubanSubjectStateRecords_BOOK_SYNC, DoubanSubjectStateRecords_BOOK_SYNC,
@ -25,6 +31,11 @@ import {createFileSelectionSetting} from "../setting/TemplateSettingHelper";
import {FileSuggest} from "../setting/model/FileSuggest"; import {FileSuggest} from "../setting/model/FileSuggest";
import {getDefaultTemplateContent} from "../../constant/DefaultTemplateContent"; import {getDefaultTemplateContent} from "../../constant/DefaultTemplateContent";
import TimeUtil from "../../utils/TimeUtil"; 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 { export class DoubanSyncModal extends Modal {
plugin: DoubanPlugin; plugin: DoubanPlugin;
@ -122,6 +133,11 @@ ${syncStatus.getHandle() == 0? '...' : i18nHelper.getMessage('110042') + ':' + T
attachmentPath: (settings.attachmentPath == '' || settings.attachmentPath == null) ? DEFAULT_SETTINGS.attachmentPath : settings.attachmentPath, attachmentPath: (settings.attachmentPath == '' || settings.attachmentPath == null) ? DEFAULT_SETTINGS.attachmentPath : settings.attachmentPath,
templateFile: (settings.movieTemplateFile == '' || settings.movieTemplateFile == null) ? DEFAULT_SETTINGS.movieTemplateFile : settings.movieTemplateFile, templateFile: (settings.movieTemplateFile == '' || settings.movieTemplateFile == null) ? DEFAULT_SETTINGS.movieTemplateFile : settings.movieTemplateFile,
incrementalUpdate: true, incrementalUpdate: true,
syncConditionType: SyncConditionType.LAST_UPDATE,
syncConditionDateFromValue: null,
syncConditionDateToValue: null,
syncConditionCountFromValue: null,
syncConditionCountToValue: null
}; };
this.showConfigPan(contentEl.createDiv('config'), syncConfig, false); this.showConfigPan(contentEl.createDiv('config'), syncConfig, false);
const controls = contentEl.createDiv("controls"); const controls = contentEl.createDiv("controls");
@ -160,10 +176,10 @@ ${syncStatus.getHandle() == 0? '...' : i18nHelper.getMessage('110042') + ':' + T
private showConfigPan(contentEl: HTMLElement, config:SyncConfig, disable:boolean) { private showConfigPan(contentEl: HTMLElement, config:SyncConfig, disable:boolean) {
new Setting(contentEl); new Setting(contentEl);
this.showTypeDropdown(contentEl, config, disable); this.showTypeDropdown(contentEl, config, disable);
this.showCondition(contentEl, config, disable);
this.showOutputFolderSelections(contentEl, config, disable); // this.showOutputFolderSelections(contentEl, config, disable);
this.showOutiFleName(contentEl, config, disable); // this.showOutiFleName(contentEl, config, disable);
this.showAttachmentsFileConfig(contentEl, config, disable); // this.showAttachmentsFileConfig(contentEl, config, disable);
this.showUpdateAllConfig(contentEl, config, disable); this.showUpdateAllConfig(contentEl, config, disable);
this.showForceUpdateConfig(contentEl, config, disable); this.showForceUpdateConfig(contentEl, config, disable);
} }
@ -217,7 +233,7 @@ ${syncStatus.getHandle() == 0? '...' : i18nHelper.getMessage('110042') + ':' + T
}); });
}).setDisabled(disable); }).setDisabled(disable);
this.openScopeDropdown(scopeSelections, config, disable); this.openScopeDropdown(scopeSelections, config, disable);
this.showTemplateFileSelectionSetting(templateFile, config, disable); // this.showTemplateFileSelectionSetting(templateFile, config, disable);
} }
private getDefaultTemplatePath(value: string) { private getDefaultTemplatePath(value: string) {
@ -412,4 +428,106 @@ ${syncStatus.getHandle() == 0? '...' : i18nHelper.getMessage('110042') + ':' + T
.setDisabled(disable); .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);
} }

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

@ -1,5 +1,10 @@
export interface SyncConfig { export interface SyncConfig {
syncType: string, syncType: string,
syncConditionType: string,
syncConditionCountFromValue: string,
syncConditionCountToValue: string,
syncConditionDateFromValue: string,
syncConditionDateToValue: string,
scope: string, scope: string,
force: boolean, force: boolean,
dataFilePath: string; dataFilePath: string;

@ -33,7 +33,7 @@ export default {
PS: This file could be delete if you want to. PS: This file could be delete if you want to.
`, `,
'110038': `DoubanSyncResult`, '110038': `DoubanSyncResult`,
'110039': `SyncNotSync:`, '110039': `Incremental Sync:`,
'110040': `Only sync that haven't been synced yet. if not enabled, will sync all the subject'`, '110040': `Only sync that haven't been synced yet. if not enabled, will sync all the subject'`,
'110041': `IncrementalSync`, '110041': `IncrementalSync`,
'110042': `EstimateTime`, '110042': `EstimateTime`,
@ -44,6 +44,17 @@ PS: This file could be delete if you want to.
'110052': `Description`, '110052': `Description`,
'110152': `Confirm`, '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]`, 'exists':`[exists]`,
'unHandle':`[unHandle]`, 'unHandle':`[unHandle]`,

@ -17,14 +17,28 @@ export default {
'110010': `后台运行`, '110010': `后台运行`,
'110008': `已经存在同步任务: {0}-{1} 结束之后再重试`, '110008': `已经存在同步任务: {0}-{1} 结束之后再重试`,
'500002': `同步状态`, '500002': `同步状态`,
'110030': `类型:`, '110030': `选择类型:`,
'110031': `替换同名文档:`, '110031': `替换同名文档:`,
'110032': `范围:`, '110032': `选择状态:`,
'110033': `进度:`, '110033': `进度:`,
'110034': `输出文件夹:`, '110034': `输出文件夹:`,
'110035': `文档名: (提示:支持参数化以及多级路径, 可用参数见配置界面)`, '110035': `文档名: (提示:支持参数化以及多级路径, 可用参数见配置界面)`,
'110036': `完成`, '110036': `完成`,
'110152': `确认`, '110152': `确认`,
'110070': `同步范围:`,
'110071': `全部`,
'110072': `最新变动`,
'110075': `最近10条`,
'110074': `自定义时间`,
'110076': `自定义条数`,
'110077': ``,
'110078': ``,
'110079': ``,
'110073': ``,
'110080': `数字`,
'110037': ` '110037': `
### ###

@ -88,8 +88,13 @@ export default class TimeUtil {
} }
public static getLastMonth() {
const date = new Date();
date.setMonth(date.getMonth() - 1);
return date;
} }
}