From 80873784fcb9e6b52712caff124b20f85c1e8a4b Mon Sep 17 00:00:00 2001 From: wanxp <977741432@qq.com> Date: Sun, 20 Nov 2022 02:16:41 +0800 Subject: [PATCH] add function: sync personal movie/book/music info --- src/org/wanxp/constant/DoubanUserState.ts | 8 +++ .../wanxp/douban/component/DoubanSyncModal.ts | 64 ++++++++++++++++--- .../data/handler/DoubanAbstractLoadHandler.ts | 3 + .../wanxp/douban/data/model/HandleContext.ts | 3 +- .../wanxp/douban/model/GlobalStatusHolder.ts | 13 ++-- .../sync/model/GlobalSyncStatusHolder.ts | 6 +- src/org/wanxp/douban/sync/model/SyncConfig.ts | 1 + src/org/wanxp/lang/locale/en.ts | 4 +- src/org/wanxp/lang/locale/zh-cn.ts | 4 +- src/org/wanxp/main.ts | 28 +++++--- styles.css | 7 ++ 11 files changed, 112 insertions(+), 29 deletions(-) diff --git a/src/org/wanxp/constant/DoubanUserState.ts b/src/org/wanxp/constant/DoubanUserState.ts index aec5da6..7182dee 100644 --- a/src/org/wanxp/constant/DoubanUserState.ts +++ b/src/org/wanxp/constant/DoubanUserState.ts @@ -97,6 +97,14 @@ export const DoubanSubjectStateRecords_NOTE_SYNC: { [key :string]: string } = { [ALL]: i18nHelper.getMessage('500004'), } +// @ts-ignore +export const DoubanSubjectStateRecords_MUSIC_SYNC: { [key in DoubanSubjectState]: string } = { + // @ts-ignore + [ALL]: i18nHelper.getMessage('500004'), + [DoubanSubjectState.wish]: i18nHelper.getMessage('500402'), + [DoubanSubjectState.do]: i18nHelper.getMessage('500403'), + [DoubanSubjectState.collect]: i18nHelper.getMessage('500404'), +} diff --git a/src/org/wanxp/douban/component/DoubanSyncModal.ts b/src/org/wanxp/douban/component/DoubanSyncModal.ts index 8a31651..fa4b7bc 100644 --- a/src/org/wanxp/douban/component/DoubanSyncModal.ts +++ b/src/org/wanxp/douban/component/DoubanSyncModal.ts @@ -3,6 +3,7 @@ import { ButtonComponent, DropdownComponent, Modal, SearchComponent, Setting, + TextComponent, ToggleComponent } from "obsidian"; @@ -13,13 +14,15 @@ import {SyncType, SyncTypeRecords} from "../../constant/Constsant"; import { ALL, DoubanSubjectStateRecords_BOOK_SYNC, DoubanSubjectStateRecords_BROADCAST_SYNC, - DoubanSubjectStateRecords_MOVIE_SYNC, DoubanSubjectStateRecords_NOTE_SYNC + DoubanSubjectStateRecords_MOVIE_SYNC, DoubanSubjectStateRecords_MUSIC_SYNC, DoubanSubjectStateRecords_NOTE_SYNC } from "../../constant/DoubanUserState"; import {SyncConfig} from "../sync/model/SyncConfig"; import {clearInterval} from "timers"; import {statSync} from "fs"; import {CreateTemplateSelectParams} from "../setting/model/CreateTemplateSelectParams"; import {FolderSuggest} from "../setting/model/FolderSuggest"; +import SettingsManager from "../setting/SettingsManager"; +import {DEFAULT_SETTINGS} from "../../constant/DefaultSettings"; export class DoubanSyncModal extends Modal { plugin: DoubanPlugin; @@ -55,7 +58,6 @@ export class DoubanSyncModal extends Modal { const sliderDiv = contentEl.createEl('div'); sliderDiv.addClass('obsidian_douban_sync_slider'); - this.showProgress(sliderDiv); const controls = contentEl.createDiv("controls"); const syncButton = new ButtonComponent(controls) @@ -72,16 +74,22 @@ export class DoubanSyncModal extends Modal { }); cancelButton.setClass("obsidian_douban_search_button"); syncButton.setClass("obsidian_douban_search_button"); + this.showProgress(sliderDiv, syncButton); this.timer = setInterval(() => { - this.showProgress(sliderDiv); + this.showProgress(sliderDiv,syncButton); }, 1000); } - private showProgress(sliderDiv: HTMLDivElement) { + private showProgress(sliderDiv: HTMLDivElement, button:ButtonComponent) { const {syncStatus} = this.plugin.statusHolder; - if (!syncStatus) { + if (!this.plugin.statusHolder.syncStarted) { + sliderDiv.innerHTML = `
+ + ${syncStatus.getHandle()}/${syncStatus.getTotal()}:${i18nHelper.getMessage('110036')} +
` + button.setDisabled(true); return; } sliderDiv.innerHTML = `
@@ -94,8 +102,11 @@ export class DoubanSyncModal extends Modal {
clearInterval(this.timer)
}
contentEl.createEl("h3", {text: i18nHelper.getMessage('500001')});
-
- let syncConfig:SyncConfig = {syncType: SyncType.movie, scope: ALL, force: false, outputFolder: this.plugin.settings.dataFilePath};
+ const {settings} = this.plugin;
+ let syncConfig:SyncConfig = {syncType: SyncType.movie, scope: ALL,
+ force: false,
+ outputFolder: (settings.dataFilePath == '' || settings.dataFilePath == null) ? DEFAULT_SETTINGS.dataFilePath : settings.dataFilePath,
+ dataFileNamePath: (settings.dataFileNamePath == '' || settings.dataFileNamePath == null) ? DEFAULT_SETTINGS.dataFileNamePath : settings.dataFileNamePath};
this.showConfigPan(contentEl, syncConfig, false);
const controls = contentEl.createDiv("controls");
@@ -157,6 +168,16 @@ export class DoubanSyncModal extends Modal {
folderLabel.addClass('obsidian_douban_sync_config_text');
this.createFolderSetting(folderSelections, config, disable);
+ const fileName = contentEl.createDiv('fileName-item');
+ let fileNameLabel = fileName.createEl('label');
+ fileNameLabel.setText(i18nHelper.getMessage('110035'));
+ fileNameLabel.addClass('obsidian_douban_settings_text');
+ fileNameLabel.addClass('obsidian_douban_sync_config_text');
+ fileNameLabel.addClass('obsidian_douban_sync_config');
+ this.constructOutiFleName(fileName, config, disable);
+
+ fileName.addClass('obsidian_douban_sync_config');
+ folderSelections.addClass('obsidian_douban_sync_config');
typeSelections.addClass('obsidian_douban_sync_config');
scopeSelections.addClass('obsidian_douban_sync_config');
forceSelections.addClass('obsidian_douban_sync_config');
@@ -188,6 +209,9 @@ export class DoubanSyncModal extends Modal {
case SyncType.note:
this.showScopeDropdown(contentEl, DoubanSubjectStateRecords_NOTE_SYNC, config, disable);
break;
+ case SyncType.music:
+ this.showScopeDropdown(contentEl, DoubanSubjectStateRecords_MUSIC_SYNC, config, disable);
+ break;
}
}
@@ -204,14 +228,16 @@ export class DoubanSyncModal extends Modal {
}
private createFolderSetting(contentEl:HTMLDivElement, config: SyncConfig, disable:boolean) {
- let outputFolder = this.plugin.settings.dataFilePath;
+ const {settings} = this.plugin;
+ const placeHolder = (settings.dataFilePath == '' || settings.dataFilePath == null) ? DEFAULT_SETTINGS.dataFilePath : settings.dataFilePath;
+ let outputFolder = placeHolder;
if (config.outputFolder) {
outputFolder = config.outputFolder;
}
- const search = new SearchComponent(contentEl);
+ const search = new TextComponent(contentEl);
new FolderSuggest(this.plugin.app, search.inputEl);
search.setValue(outputFolder)
- .setPlaceholder(i18nHelper.getMessage('121503'))
+ .setPlaceholder(placeHolder)
.onChange(async (value:string) => {
config.outputFolder = value;
})
@@ -220,4 +246,22 @@ export class DoubanSyncModal extends Modal {
}
}
+ private constructOutiFleName(containerEl: HTMLElement, config: SyncConfig, disable:boolean) {
+ const {settings} = this.plugin;
+ const placeHolder =(settings.dataFileNamePath == '' || settings.dataFileNamePath == null) ? DEFAULT_SETTINGS.dataFileNamePath : settings.dataFileNamePath;
+ let dataFileNamePath = placeHolder;
+ if (config.dataFileNamePath) {
+ dataFileNamePath = config.dataFileNamePath;
+ }
+ const textComponent = new TextComponent(containerEl);
+ textComponent.setPlaceholder(placeHolder)
+ .setValue(dataFileNamePath)
+ .onChange(async (value) => {
+ config.dataFileNamePath = value;
+ });
+ if (disable) {
+ textComponent.setDisabled(true);
+ }
+ }
+
}
diff --git a/src/org/wanxp/douban/data/handler/DoubanAbstractLoadHandler.ts b/src/org/wanxp/douban/data/handler/DoubanAbstractLoadHandler.ts
index f946953..7dc8bc7 100644
--- a/src/org/wanxp/douban/data/handler/DoubanAbstractLoadHandler.ts
+++ b/src/org/wanxp/douban/data/handler/DoubanAbstractLoadHandler.ts
@@ -68,6 +68,9 @@ export default abstract class DoubanAbstractLoadHandler