Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(time_selector): use time_selector in attachment_erasure_timeout
Panagiotis Papadopoulosf672054441bc
diff --git a/src/public/app/widgets/type_widgets/options/other/attachment_erasure_timeout.ts b/src/public/app/widgets/type_widgets/options/other/attachment_erasure_timeout.tsindex 48ce0cb0dd..c384dce107 100644--- a/src/public/app/widgets/type_widgets/options/other/attachment_erasure_timeout.ts+++ b/src/public/app/widgets/type_widgets/options/other/attachment_erasure_timeout.ts@@ -2,33 +2,37 @@ import OptionsWidget from "../options_widget.js";import server from "../../../../services/server.js";import toastService from "../../../../services/toast.js";import { t } from "../../../../services/i18n.js";-import type { OptionMap } from "../../../../../../services/options_interface.js";+import TimeSelector from "../time_selector.js";const TPL = `<div class="options-section"><h4>${t("attachment_erasure_timeout.attachment_erasure_timeout")}</h4><p>${t("attachment_erasure_timeout.attachment_auto_deletion_description")}</p>+`;- <div class="form-group">- <label>${t("attachment_erasure_timeout.erase_attachments_after_x_seconds")}</label>- <input class="erase-unused-attachments-after-time-in-seconds form-control options-number-input" type="number" min="0">- </div>-+const TPL2 = `<p>${t("attachment_erasure_timeout.manual_erasing_description")}</p><button class="erase-unused-attachments-now-button btn btn-secondary">${t("attachment_erasure_timeout.erase_unused_attachments_now")}</button></div>`;-export default class AttachmentErasureTimeoutOptions extends OptionsWidget {+export default class AttachmentErasureTimeoutOptions extends TimeSelector {- private $eraseUnusedAttachmentsAfterTimeInSeconds!: JQuery<HTMLElement>;private $eraseUnusedAttachmentsNowButton!: JQuery<HTMLElement>;+ constructor() {+ super({+ widgetId: "erase-unused-attachments-after",+ widgetLabelId: "attachment_erasure_timeout.erase_attachments_after_x_seconds",+ optionValueId: "eraseUnusedAttachmentsAfterSeconds",+ optionTimeScaleId: "eraseUnusedAttachmentsAfterTimeScale"+ })+ super.doRender()+ }+doRender() {- this.$widget = $(TPL);- this.$eraseUnusedAttachmentsAfterTimeInSeconds = this.$widget.find(".erase-unused-attachments-after-time-in-seconds");- this.$eraseUnusedAttachmentsAfterTimeInSeconds.on("change", () => this.updateOption("eraseUnusedAttachmentsAfterSeconds", this.$eraseUnusedAttachmentsAfterTimeInSeconds.val()));+ this.$widget = $(TPL).append(this.$widget).append(TPL2);this.$eraseUnusedAttachmentsNowButton = this.$widget.find(".erase-unused-attachments-now-button");this.$eraseUnusedAttachmentsNowButton.on("click", () => {@@ -38,7 +42,4 @@ export default class AttachmentErasureTimeoutOptions extends OptionsWidget {});}- async optionsLoaded(options: OptionMap) {- this.$eraseUnusedAttachmentsAfterTimeInSeconds.val(options.eraseUnusedAttachmentsAfterSeconds);- }}diff --git a/src/routes/api/options.ts b/src/routes/api/options.tsindex 14cb7ec425..33cd5fa8c4 100644--- a/src/routes/api/options.ts+++ b/src/routes/api/options.ts@@ -61,6 +61,7 @@ const ALLOWED_OPTIONS = new Set(["checkForUpdates","disableTray","eraseUnusedAttachmentsAfterSeconds",+ "eraseUnusedAttachmentsAfterTimeScale","disableTray","customSearchEngineName","customSearchEngineUrl",diff --git a/src/services/options_init.ts b/src/services/options_init.tsindex bb962835d5..3bb87703e1 100644--- a/src/services/options_init.ts+++ b/src/services/options_init.ts@@ -122,7 +122,8 @@ const defaultOptions: DefaultOption[] = [{ name: "highlightsList", value: '["bold","italic","underline","color","bgColor"]', isSynced: true },{ name: "checkForUpdates", value: "true", isSynced: true },{ name: "disableTray", value: "false", isSynced: false },- { name: "eraseUnusedAttachmentsAfterSeconds", value: "2592000", isSynced: true },+ { name: "eraseUnusedAttachmentsAfterSeconds", value: "2592000", isSynced: true }, // default 30 days+ { name: "eraseUnusedAttachmentsAfterTimeScale", value: "86400", isSynced: true }, // default 86400 seconds = Day{ name: "customSearchEngineName", value: "DuckDuckGo", isSynced: true },{ name: "customSearchEngineUrl", value: "https://duckduckgo.com/?q={keyword}", isSynced: true },{ name: "promotedAttributesOpenInRibbon", value: "true", isSynced: true },diff --git a/src/services/options_interface.ts b/src/services/options_interface.tsindex f3a92383bf..fb234240c6 100644--- a/src/services/options_interface.ts+++ b/src/services/options_interface.ts@@ -67,6 +67,7 @@ export interface OptionDefinitions extends KeyboardShortcutsOptions<KeyboardActimaxContentWidth: number;minTocHeadings: number;eraseUnusedAttachmentsAfterSeconds: number;+ eraseUnusedAttachmentsAfterTimeScale: number;firstDayOfWeek: number;initialized: boolean;