diff --git a/src/commands/file_menu.ts b/src/commands/file_menu.ts index 569a950c..2b366a79 100644 --- a/src/commands/file_menu.ts +++ b/src/commands/file_menu.ts @@ -76,7 +76,7 @@ export function addSubMenuCommandsFolder(plugin: GithubPublisher, item: MenuItem .setTitle(i18next.t("commands.shareViewFiles.multiple.other")) .setIcon("folder-symlink") .onClick(async () => { - new ChooseRepoToRun(plugin.app, plugin, null, branchName, async (item: Repository) => { + new ChooseRepoToRun(plugin.app, plugin, null, branchName, "folder", async (item: Repository) => { await shareFolderRepo(plugin, folder, branchName, item); }).open(); @@ -230,7 +230,7 @@ export function subMenuCommandsFile(plugin: GithubPublisher, item: MenuItem, fil .setTitle(i18next.t("commands.shareViewFiles.multiple.other")) .setIcon("file-input") .onClick(async () => { - new ChooseRepoToRun(plugin.app, plugin, repo?.shareKey, branchName, async (item: Repository) => { + new ChooseRepoToRun(plugin.app, plugin, repo?.shareKey, branchName, "file", async (item: Repository) => { await shareOneNote( branchName, await plugin.reloadOctokit(), diff --git a/src/commands/suggest_other_repo_commands_modal.ts b/src/commands/suggest_other_repo_commands_modal.ts index 2b8af5f0..b098dfb5 100644 --- a/src/commands/suggest_other_repo_commands_modal.ts +++ b/src/commands/suggest_other_repo_commands_modal.ts @@ -1,5 +1,6 @@ import i18next from "i18next"; import {App, FuzzySuggestModal } from "obsidian"; +import { defaultRepo } from "src/utils/data_validation_test"; import GithubPublisherPlugin from "../main"; import {FolderSettings, Repository} from "../settings/interface"; @@ -44,7 +45,7 @@ export class ChooseWhichRepoToRun extends FuzzySuggestModal { } // eslint-disable-next-line @typescript-eslint/no-unused-vars onChooseItem(item: Repository, evt: MouseEvent | KeyboardEvent): void { - new SuggestOtherRepoCommandsModal(app, this.plugin, this.branchName, item).open(); + new SuggestOtherRepoCommandsModal(this.plugin.app, this.plugin, this.branchName, item).open(); } } @@ -55,21 +56,38 @@ export class ChooseRepoToRun extends FuzzySuggestModal { plugin: GithubPublisherPlugin; branchName: string; keyToFind: string | null; + type: "folder" | "file"; onSubmit: (item: Repository) => void; - constructor(app: App, plugin: GithubPublisherPlugin, keyToFind: null|string = null, branchName: string, onSubmit: (item: Repository) => void) { + constructor(app: App, plugin: GithubPublisherPlugin, keyToFind: null|string = null, branchName: string, type:"folder"|"file", onSubmit: (item: Repository) => void) { super(app); this.plugin = plugin; this.branchName = branchName; this.keyToFind = keyToFind; this.onSubmit = onSubmit; + this.type = type; } getItems(): Repository[] { - if (this.keyToFind) { - return this.plugin.settings.github.otherRepo.filter((repo: Repository) => repo.shareKey == this.keyToFind); + let repoFound: Repository[] = []; + const defRepo = defaultRepo(this.plugin.settings); + if (this.type === "file") { + if (this.plugin.settings.plugin.shareAll?.enable) { + repoFound.push(defRepo); + } + if (this.keyToFind) { + repoFound=repoFound.concat(this.plugin.settings.github.otherRepo.filter((repo: Repository) => repo.shareKey == this.keyToFind)); + if (this.keyToFind === defRepo.shareKey) { + repoFound.push(defRepo); + } + } } - return this.plugin.settings.github.otherRepo; + repoFound=repoFound.concat(this.plugin.settings.github.otherRepo.filter((repo: Repository) => repo.shareAll?.enable)); + repoFound.push(defRepo); + repoFound=[...new Set(repoFound)]; + if (repoFound.length === 0) + return this.plugin.settings.github.otherRepo; + return repoFound; } getItemText(item: Repository): string { return item.smartKey; diff --git a/src/settings/interface.ts b/src/settings/interface.ts index ef327a14..93068885 100644 --- a/src/settings/interface.ts +++ b/src/settings/interface.ts @@ -39,7 +39,10 @@ export interface Repository { } createShortcuts: boolean; shareKey: string; - + shareAll?: { + enable: boolean; + excludedFileName: string; + } copyLink: { links: string; removePart: string[]; diff --git a/src/settings/modals/manage_repo.ts b/src/settings/modals/manage_repo.ts index b7dfafe5..7dd43b5e 100644 --- a/src/settings/modals/manage_repo.ts +++ b/src/settings/modals/manage_repo.ts @@ -275,7 +275,7 @@ class ModalEditingRepository extends Modal { }) ); - contentEl.createEl("h3", { text: "Github Workflow" }); + contentEl.createEl("h3", { text: "GitHub Workflow" }); new Setting(contentEl) .setName(i18next.t("settings.githubWorkflow.prRequest.title")) .setDesc(i18next.t("settings.githubWorkflow.prRequest.desc")) @@ -314,18 +314,45 @@ class ModalEditingRepository extends Modal { contentEl.createEl("h3", { text: i18next.t("settings.github.smartRepo.modals.otherConfig") }); new Setting(contentEl) - .setName(i18next.t("settings.plugin.shareKey.title")) - .setDesc(i18next.t("settings.plugin.shareKey.desc")) - .addText((text) => - text - .setPlaceholder("share") - .setValue(this.repository.shareKey) + .setName(i18next.t("settings.plugin.shareKey.all.title")) + .setDesc(i18next.t("settings.plugin.shareKey.all.desc")) + .addToggle((toggle) => + toggle + .setValue(this.repository.shareAll?.enable ?? false) .onChange(async (value) => { - this.repository.shareKey = value.trim(); - await this.plugin.saveSettings(); + this.repository.shareAll = { + enable: value, + excludedFileName: this.plugin.settings.plugin.shareAll?.excludedFileName ?? "DRAFT" + }; + this.onOpen(); }) ); - + if (!this.repository.shareAll || !this.repository.shareAll.enable) { + new Setting(contentEl) + .setName(i18next.t("settings.plugin.shareKey.title")) + .setDesc(i18next.t("settings.plugin.shareKey.desc")) + .addText((text) => + text + .setPlaceholder("share") + .setValue(this.repository.shareKey) + .onChange(async (value) => { + this.repository.shareKey = value.trim(); + await this.plugin.saveSettings(); + }) + ); + } else { + new Setting(contentEl) + .setName(i18next.t("settings.plugin.shareKey.excludedFileName.title")) + .addText((text) => + text + .setPlaceholder("DRAFT") + .setValue(this.repository.shareAll?.excludedFileName ?? this.plugin.settings.plugin.shareAll?.excludedFileName ?? "DRAFT") + .onChange(async (value) => { + this.repository.shareAll!.excludedFileName = value.trim(); + }) + ); + } + if (this.plugin.settings.plugin.copyLink.enable) { new Setting(contentEl) .setName(i18next.t("settings.plugin.copyLink.baselink.title")) diff --git a/src/utils/data_validation_test.ts b/src/utils/data_validation_test.ts index fe04cf27..57b077f8 100644 --- a/src/utils/data_validation_test.ts +++ b/src/utils/data_validation_test.ts @@ -95,15 +95,26 @@ function isExcludedPath(settings: GitHubPublisherSettings, file: TFile):boolean * Allow to get all sharedKey from one file to count them */ export function multipleSharedKey(frontmatter: FrontMatterCache | undefined, settings: GitHubPublisherSettings) { - if (!frontmatter) return []; + const keysInFile: string[] = []; + if (settings.plugin.shareAll?.enable) + keysInFile.push("share"); //add a key to count the shareAll + + const otherRepoWithShareAll = settings.github.otherRepo.filter((repo) => repo.shareAll); + if (otherRepoWithShareAll.length > 0) { + for (const repo of otherRepoWithShareAll) { + keysInFile.push(repo.smartKey); + } + } + if (!frontmatter) return keysInFile; const allKey = settings.github.otherRepo.map((repo) => repo.shareKey); allKey.push(settings.plugin.shareKey); - const keysInFile: string[] = []; + for (const key of allKey) { if (frontmatter[key]) { keysInFile.push(key); } } + return keysInFile; }