From c472815245a410c8d19de036ad5f0f40649a6b08 Mon Sep 17 00:00:00 2001 From: Mara Date: Tue, 27 Feb 2024 18:29:04 +0100 Subject: [PATCH] fix: add pop-up for auto-clean information --- src/i18n/locales/en.json | 10 ++++++- src/i18n/locales/fr.json | 10 ++++++- src/settings.ts | 11 +++++-- src/settings/modals/popup.ts | 58 ++++++++++++++++++++++++++++++++++++ src/settings/style.ts | 24 +++++++-------- 5 files changed, 95 insertions(+), 18 deletions(-) create mode 100644 src/settings/modals/popup.ts diff --git a/src/i18n/locales/en.json b/src/i18n/locales/en.json index 48e7113e..5fc2b468 100644 --- a/src/i18n/locales/en.json +++ b/src/i18n/locales/en.json @@ -56,6 +56,7 @@ "files": "Files", "ghToken": "GitHub token", "here": "here", + "no": "No", "or": "or", "path": { "file": "File name", @@ -70,7 +71,8 @@ "save": "Save", "shared": "shared", "text": "text", - "warning": "Warning" + "warning": "Warning", + "yes": "Yes" }, "deletion": { "defaultFolder": "You need a default folder name in the settings to use this command.", @@ -357,6 +359,12 @@ "githubWorkflow": { "autoCleanUp": { "desc": "Remove depublished files (stopped sharing or deleted) from GitHub", + "popup": { + "desc": "Enabling the auto-clean when the name of the {{- what}} is empty can delete all files within your repository, including template, workflows, icons or README.", + "exclude": "Don't forget to exclude the files and folders you need for your repository. \nAdditionally, you can always revert files deleted by GitHub's pull-request system.", + "sure": "Are you sure you want to enable this feature?", + "title": "Enable autoclean" + }, "title": "Auto clean up" }, "excludedFiles": { diff --git a/src/i18n/locales/fr.json b/src/i18n/locales/fr.json index 12f65c08..320200d6 100644 --- a/src/i18n/locales/fr.json +++ b/src/i18n/locales/fr.json @@ -56,6 +56,7 @@ "files": "Fichiers", "ghToken": "Token GitHub", "here": "ici", + "no": "Non", "or": "ou", "path": { "file": "Nom du fichier", @@ -70,7 +71,8 @@ "save": "Sauvegarder", "shared": "partagées", "text": "texte", - "warning": "Attention" + "warning": "Attention", + "yes": "Oui" }, "deletion": { "defaultFolder": "Vous avez besoin d'un dossier par défaut dans les paramètres pour utiliser cette commande.", @@ -357,6 +359,12 @@ "githubWorkflow": { "autoCleanUp": { "desc": "Si le plugin doit supprimer de votre dépôt les fichiers dépubliés (arrêt du partage ou suppression).", + "popup": { + "desc": "L'activation du nettoyage automatique lorsque le nom du {{- what}} est vide peut supprimer tous les fichiers de votre dépôt, y compris les fichiers de votre template, les workflows, les icônes ou le README.", + "exclude": "N'oubliez pas d'exclure les fichiers et dossiers dont vous avez besoin pour votre dépôt. De plus, vous pouvez toujours rétablir les fichiers supprimés par le système de pull-request de GitHub.", + "sure": "Êtes-vous certain de vouloir activer cette fonctionnalité ?", + "title": "Activation de l'auto-nettoyage" + }, "title": "Auto-nettoyage" }, "excludedFiles": { diff --git a/src/settings.ts b/src/settings.ts index d8014cc9..26542412 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -15,6 +15,7 @@ import { import { migrateToken } from "./settings/migrate"; import { ExportModal, ImportLoadPreset, ImportModal, loadAllPresets } from "./settings/modals/import_export"; import { ModalAddingNewRepository } from "./settings/modals/manage_repo"; +import { AutoCleanPopup } from "./settings/modals/popup"; import { ModalRegexFilePathName, ModalRegexOnContents, OverrideAttachmentsModal } from "./settings/modals/regex_edition"; import { TokenEditPath } from "./settings/modals/token_path"; import { @@ -347,7 +348,7 @@ export class GithubPublisherSettingsTab extends PluginSettingTab { }) ).open(); })); - this.settingsPage.createEl("h3", { text: "Github Workflow" }); + this.settingsPage.createEl("h3", { text: "GitHub Workflow" }); new Setting(this.settingsPage) .setName(i18next.t("settings.githubWorkflow.prRequest.title")) .setDesc(i18next.t("settings.githubWorkflow.prRequest.desc")) @@ -615,7 +616,13 @@ export class GithubPublisherSettingsTab extends PluginSettingTab { toggle .setValue(uploadSettings.autoclean.enable) .onChange(async (value) => { - uploadSettings.autoclean.enable = value; + if (value && (this.settings.upload.behavior === "yaml" && this.settings.upload.defaultName.length === 0 || this.settings.upload.rootFolder.length === 0)) + new AutoCleanPopup(this.app, this.settings, (result => { + uploadSettings.autoclean.enable = result; + this.renderSettingsPage(EnumbSettingsTabId.upload); + })).open(); + else + uploadSettings.autoclean.enable = value; await this.plugin.saveSettings(); this.renderSettingsPage(EnumbSettingsTabId.upload); this.plugin.cleanOldCommands(); diff --git a/src/settings/modals/popup.ts b/src/settings/modals/popup.ts new file mode 100644 index 00000000..b202e594 --- /dev/null +++ b/src/settings/modals/popup.ts @@ -0,0 +1,58 @@ +import i18next from "i18next"; +import { App, Modal, Setting } from "obsidian"; + +import { GitHubPublisherSettings } from "../interface"; + + +export class AutoCleanPopup extends Modal { + settings: GitHubPublisherSettings; + onSubmit: (enable: boolean) => void; + constructor(app: App, settings: GitHubPublisherSettings, onSubmit: (enable: boolean) => void) { + super(app); + this.onSubmit = onSubmit; + this.settings = settings; + } + + whatIsEmpty() { + if (this.settings.upload.behavior === "yaml" && this.settings.upload.defaultName.length === 0) { + return i18next.t("common.defaultName"); + } else if (this.settings.upload.rootFolder.length === 0) { + return i18next.t("common.rootFolder"); + } + } + + onOpen() { + const { contentEl } = this; + contentEl.empty(); + contentEl.addClasses(["github-publisher", "modals", "popup"]); + contentEl.createEl("h2", { text: i18next.t("settings.githubWorkflow.autoCleanUp.popup.title") }); + contentEl.createEl("p", { text: i18next.t("settings.githubWorkflow.autoCleanUp.popup.desc", {what: this.whatIsEmpty()})}); + contentEl.createEl("p", { text: i18next.t("settings.githubWorkflow.autoCleanUp.popup.exclude")}); + contentEl.createEl("p", { text: i18next.t("settings.githubWorkflow.autoCleanUp.popup.sure") }); + + new Setting(contentEl) + .setClass("no-display") + .addButton((button) => { + button + .setButtonText(i18next.t("common.yes")) + .setWarning() + .onClick(() => { + this.onSubmit(true); + this.close(); + }); + }) + .addButton((button) => { + button + .setButtonText(i18next.t("common.no")) + .onClick(() => { + this.onSubmit(false); + this.close(); + }); + }); + } + + onClose() { + const { contentEl } = this; + contentEl.empty(); + } +} \ No newline at end of file diff --git a/src/settings/style.ts b/src/settings/style.ts index 4fe102c9..ddbfec6d 100644 --- a/src/settings/style.ts +++ b/src/settings/style.ts @@ -71,7 +71,6 @@ export async function autoCleanCondition( new Notice(i18next.t("error.autoClean", {what: translation})); settings.autoclean.enable = false; await plugin.saveSettings(); - autoCleanSetting.setDisabled(true); // @ts-ignore autoCleanSetting.components[0].toggleEl.classList.remove("is-enabled"); settingsTab.renderSettingsPage(EnumbSettingsTabId.upload); @@ -83,12 +82,10 @@ export async function autoCleanCondition( if (settings.autoclean.enable) new Notice(i18next.t("error.autoClean", {what: i18next.t("common.defaultName")}),); settings.autoclean.enable = false; - autoCleanSetting.setDisabled(true); // @ts-ignore autoCleanSetting.components[0].toggleEl.classList.remove("is-enabled"); settingsTab.renderSettingsPage(EnumbSettingsTabId.upload); } - autoCleanSetting.setDisabled(false); if (settings.autoclean.enable) { // @ts-ignore autoCleanSetting.components[0].toggleEl.classList.add("is-enabled"); @@ -121,14 +118,11 @@ export async function folderHideShowSettings( showSettings(rootFolderSettings); return; } - if (settings.defaultName.length > 0) { - autoCleanSetting.setDisabled(false); - if (settings.autoclean.enable) { - // @ts-ignore - autoCleanSetting.components[0].toggleEl.classList.add( - "is-enabled" - ); - } + if (settings.defaultName.length > 0 && settings.autoclean.enable) { + // @ts-ignore + autoCleanSetting.components[0].toggleEl.classList.add( + "is-enabled" + ); } hideSettings(frontmatterKeySettings); hideSettings(rootFolderSettings); @@ -148,14 +142,12 @@ export function autoCleanUpSettingsOnCondition( ) { const settings = plugin.settings.upload; if (condition) { - autoCleanSetting.setDisabled(true); // @ts-ignore autoCleanSetting.components[0].toggleEl.classList.remove("is-enabled"); settings.autoclean.enable = false; plugin.saveSettings().then(); return; } - autoCleanSetting.setDisabled(false); if (settings.autoclean.enable) { // @ts-ignore autoCleanSetting.components[0].toggleEl.classList.add("is-enabled"); @@ -172,5 +164,9 @@ export function shortcutsHideShow( condition: string | boolean, toDisplay: Setting ) { - condition ? showSettings(toDisplay) : hideSettings(toDisplay); + if (condition) { + showSettings(toDisplay); + } else { + hideSettings(toDisplay); + } }