Skip to content

Commit

Permalink
feat(shareAll): allow otherRepo to use the option too
Browse files Browse the repository at this point in the history
  • Loading branch information
Mara-Li committed Aug 26, 2023
1 parent 0b038d4 commit 056cde9
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/commands/file_menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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(),
Expand Down
28 changes: 23 additions & 5 deletions src/commands/suggest_other_repo_commands_modal.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -44,7 +45,7 @@ export class ChooseWhichRepoToRun extends FuzzySuggestModal<Repository> {
}
// 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();
}
}

Expand All @@ -55,21 +56,38 @@ export class ChooseRepoToRun extends FuzzySuggestModal<Repository> {
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;
Expand Down
5 changes: 4 additions & 1 deletion src/settings/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ export interface Repository {
}
createShortcuts: boolean;
shareKey: string;

shareAll?: {
enable: boolean;
excludedFileName: string;
}
copyLink: {
links: string;
removePart: string[];
Expand Down
47 changes: 37 additions & 10 deletions src/settings/modals/manage_repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down Expand Up @@ -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"))
Expand Down
15 changes: 13 additions & 2 deletions src/utils/data_validation_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 056cde9

Please sign in to comment.