mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-11-03 22:51:34 +08:00
chore(client/ts): port options/other
This commit is contained in:
parent
03241a8967
commit
677760282c
@ -2,6 +2,7 @@ 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";
|
||||
|
||||
const TPL = `
|
||||
<div class="options-section">
|
||||
@ -20,6 +21,10 @@ const TPL = `
|
||||
</div>`;
|
||||
|
||||
export default class AttachmentErasureTimeoutOptions extends OptionsWidget {
|
||||
|
||||
private $eraseUnusedAttachmentsAfterTimeInSeconds!: JQuery<HTMLElement>;
|
||||
private $eraseUnusedAttachmentsNowButton!: JQuery<HTMLElement>;
|
||||
|
||||
doRender() {
|
||||
this.$widget = $(TPL);
|
||||
this.$eraseUnusedAttachmentsAfterTimeInSeconds = this.$widget.find(".erase-unused-attachments-after-time-in-seconds");
|
||||
@ -33,7 +38,7 @@ export default class AttachmentErasureTimeoutOptions extends OptionsWidget {
|
||||
});
|
||||
}
|
||||
|
||||
async optionsLoaded(options) {
|
||||
async optionsLoaded(options: OptionMap) {
|
||||
this.$eraseUnusedAttachmentsAfterTimeInSeconds.val(options.eraseUnusedAttachmentsAfterSeconds);
|
||||
}
|
||||
}
|
||||
@ -1,5 +1,6 @@
|
||||
import OptionsWidget from "../options_widget.js";
|
||||
import { t } from "../../../../services/i18n.js";
|
||||
import type { OptionMap } from "../../../../../../services/options_interface.js";
|
||||
|
||||
// TODO: Deduplicate with src/services/html_sanitizer once there is a commons project between client and server.
|
||||
export const DEFAULT_ALLOWED_TAGS = [
|
||||
@ -117,6 +118,10 @@ const TPL = `
|
||||
</div>`;
|
||||
|
||||
export default class HtmlImportTagsOptions extends OptionsWidget {
|
||||
|
||||
private $allowedTags!: JQuery<HTMLElement>;
|
||||
private $resetButton!: JQuery<HTMLElement>;
|
||||
|
||||
doRender() {
|
||||
this.$widget = $(TPL);
|
||||
this.contentSized();
|
||||
@ -131,7 +136,7 @@ export default class HtmlImportTagsOptions extends OptionsWidget {
|
||||
this.refresh();
|
||||
}
|
||||
|
||||
async optionsLoaded(options) {
|
||||
async optionsLoaded(options: OptionMap) {
|
||||
try {
|
||||
if (options.allowedHtmlTags) {
|
||||
const tags = JSON.parse(options.allowedHtmlTags);
|
||||
@ -148,7 +153,7 @@ export default class HtmlImportTagsOptions extends OptionsWidget {
|
||||
}
|
||||
|
||||
async saveTags() {
|
||||
const tagsText = this.$allowedTags.val();
|
||||
const tagsText = String(this.$allowedTags.val()) || "";
|
||||
const tags = tagsText
|
||||
.split(/[\n,\s]+/) // Split on newlines, commas, or spaces
|
||||
.map((tag) => tag.trim())
|
||||
@ -1,5 +1,6 @@
|
||||
import OptionsWidget from "../options_widget.js";
|
||||
import { t } from "../../../../services/i18n.js";
|
||||
import type { OptionMap } from "../../../../../../services/options_interface.js";
|
||||
|
||||
const TPL = `
|
||||
<div class="options-section">
|
||||
@ -12,13 +13,16 @@ const TPL = `
|
||||
</div>`;
|
||||
|
||||
export default class NetworkConnectionsOptions extends OptionsWidget {
|
||||
|
||||
private $checkForUpdates!: JQuery<HTMLElement>;
|
||||
|
||||
doRender() {
|
||||
this.$widget = $(TPL);
|
||||
this.$checkForUpdates = this.$widget.find(".check-for-updates");
|
||||
this.$checkForUpdates.on("change", () => this.updateCheckboxOption("checkForUpdates", this.$checkForUpdates));
|
||||
}
|
||||
|
||||
async optionsLoaded(options) {
|
||||
async optionsLoaded(options: OptionMap) {
|
||||
this.setCheckboxState(this.$checkForUpdates, options.checkForUpdates);
|
||||
}
|
||||
}
|
||||
@ -2,6 +2,7 @@ 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";
|
||||
|
||||
const TPL = `
|
||||
<div class="options-section">
|
||||
@ -20,6 +21,10 @@ const TPL = `
|
||||
</div>`;
|
||||
|
||||
export default class NoteErasureTimeoutOptions extends OptionsWidget {
|
||||
|
||||
private $eraseEntitiesAfterTimeInSeconds!: JQuery<HTMLElement>;
|
||||
private $eraseDeletedNotesButton!: JQuery<HTMLElement>;
|
||||
|
||||
doRender() {
|
||||
this.$widget = $(TPL);
|
||||
this.$eraseEntitiesAfterTimeInSeconds = this.$widget.find(".erase-entities-after-time-in-seconds");
|
||||
@ -33,7 +38,7 @@ export default class NoteErasureTimeoutOptions extends OptionsWidget {
|
||||
});
|
||||
}
|
||||
|
||||
async optionsLoaded(options) {
|
||||
async optionsLoaded(options: OptionMap) {
|
||||
this.$eraseEntitiesAfterTimeInSeconds.val(options.eraseEntitiesAfterTimeInSeconds);
|
||||
}
|
||||
}
|
||||
@ -2,6 +2,7 @@ import OptionsWidget from "../options_widget.js";
|
||||
import { t } from "../../../../services/i18n.js";
|
||||
import server from "../../../../services/server.js";
|
||||
import toastService from "../../../../services/toast.js";
|
||||
import type { OptionMap } from "../../../../../../services/options_interface.js";
|
||||
|
||||
const TPL = `
|
||||
<div class="options-section">
|
||||
@ -19,11 +20,15 @@ const TPL = `
|
||||
</div>`;
|
||||
|
||||
export default class RevisionSnapshotsLimitOptions extends OptionsWidget {
|
||||
|
||||
private $revisionSnapshotsNumberLimit!: JQuery<HTMLElement>;
|
||||
private $eraseExcessRevisionSnapshotsButton!: JQuery<HTMLElement>;
|
||||
|
||||
doRender() {
|
||||
this.$widget = $(TPL);
|
||||
this.$revisionSnapshotsNumberLimit = this.$widget.find(".revision-snapshot-number-limit");
|
||||
this.$revisionSnapshotsNumberLimit.on("change", () => {
|
||||
let revisionSnapshotNumberLimit = this.$revisionSnapshotsNumberLimit.val();
|
||||
let revisionSnapshotNumberLimit = parseInt(String(this.$revisionSnapshotsNumberLimit.val()), 10);
|
||||
if (!isNaN(revisionSnapshotNumberLimit) && revisionSnapshotNumberLimit >= -1) {
|
||||
this.updateOption("revisionSnapshotNumberLimit", revisionSnapshotNumberLimit);
|
||||
}
|
||||
@ -36,7 +41,7 @@ export default class RevisionSnapshotsLimitOptions extends OptionsWidget {
|
||||
});
|
||||
}
|
||||
|
||||
async optionsLoaded(options) {
|
||||
async optionsLoaded(options: OptionMap) {
|
||||
this.$revisionSnapshotsNumberLimit.val(options.revisionSnapshotNumberLimit);
|
||||
}
|
||||
}
|
||||
@ -1,5 +1,6 @@
|
||||
import OptionsWidget from "../options_widget.js";
|
||||
import { t } from "../../../../services/i18n.js";
|
||||
import type { OptionMap } from "../../../../../../services/options_interface.js";
|
||||
|
||||
const TPL = `
|
||||
<div class="options-section">
|
||||
@ -14,13 +15,16 @@ const TPL = `
|
||||
</div>`;
|
||||
|
||||
export default class RevisionsSnapshotIntervalOptions extends OptionsWidget {
|
||||
|
||||
private $revisionsTimeInterval!: JQuery<HTMLElement>;
|
||||
|
||||
doRender() {
|
||||
this.$widget = $(TPL);
|
||||
this.$revisionsTimeInterval = this.$widget.find(".revision-snapshot-time-interval-in-seconds");
|
||||
this.$revisionsTimeInterval.on("change", () => this.updateOption("revisionSnapshotTimeInterval", this.$revisionsTimeInterval.val()));
|
||||
}
|
||||
|
||||
async optionsLoaded(options) {
|
||||
async optionsLoaded(options: OptionMap) {
|
||||
this.$revisionsTimeInterval.val(options.revisionSnapshotTimeInterval);
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,7 @@
|
||||
import OptionsWidget from "../options_widget.js";
|
||||
import utils from "../../../../services/utils.js";
|
||||
import { t } from "../../../../services/i18n.js";
|
||||
import type { OptionMap } from "../../../../../../services/options_interface.js";
|
||||
|
||||
const TPL = `
|
||||
<div class="options-section">
|
||||
@ -35,7 +36,7 @@ const TPL = `
|
||||
</form>
|
||||
</div>`;
|
||||
|
||||
const SEARCH_ENGINES = {
|
||||
const SEARCH_ENGINES: Record<string, string> = {
|
||||
Bing: "https://www.bing.com/search?q={keyword}",
|
||||
Baidu: "https://www.baidu.com/s?wd={keyword}",
|
||||
DuckDuckGo: "https://duckduckgo.com/?q={keyword}",
|
||||
@ -43,6 +44,12 @@ const SEARCH_ENGINES = {
|
||||
};
|
||||
|
||||
export default class SearchEngineOptions extends OptionsWidget {
|
||||
|
||||
private $form!: JQuery<HTMLElement>;
|
||||
private $predefinedSearchEngineSelect!: JQuery<HTMLElement>;
|
||||
private $customSearchEngineName!: JQuery<HTMLInputElement>;
|
||||
private $customSearchEngineUrl!: JQuery<HTMLInputElement>;
|
||||
|
||||
isEnabled() {
|
||||
return super.isEnabled() && utils.isElectron();
|
||||
}
|
||||
@ -56,7 +63,7 @@ export default class SearchEngineOptions extends OptionsWidget {
|
||||
this.$customSearchEngineUrl = this.$widget.find(".custom-search-engine-url");
|
||||
|
||||
this.$predefinedSearchEngineSelect.on("change", () => {
|
||||
const predefinedSearchEngine = this.$predefinedSearchEngineSelect.val();
|
||||
const predefinedSearchEngine = String(this.$predefinedSearchEngineSelect.val());
|
||||
this.$customSearchEngineName[0].value = predefinedSearchEngine;
|
||||
this.$customSearchEngineUrl[0].value = SEARCH_ENGINES[predefinedSearchEngine];
|
||||
});
|
||||
@ -69,7 +76,7 @@ export default class SearchEngineOptions extends OptionsWidget {
|
||||
});
|
||||
}
|
||||
|
||||
async optionsLoaded(options) {
|
||||
async optionsLoaded(options: OptionMap) {
|
||||
this.$predefinedSearchEngineSelect.val("");
|
||||
this.$customSearchEngineName[0].value = options.customSearchEngineName;
|
||||
this.$customSearchEngineUrl[0].value = options.customSearchEngineUrl;
|
||||
@ -1,6 +1,7 @@
|
||||
import OptionsWidget from "../options_widget.js";
|
||||
import { t } from "../../../../services/i18n.js";
|
||||
import utils from "../../../../services/utils.js";
|
||||
import type { OptionMap } from "../../../../../../services/options_interface.js";
|
||||
|
||||
const TPL = `
|
||||
<div class="options-section">
|
||||
@ -13,6 +14,9 @@ const TPL = `
|
||||
</div>`;
|
||||
|
||||
export default class TrayOptions extends OptionsWidget {
|
||||
|
||||
private $trayEnabled!: JQuery<HTMLElement>;
|
||||
|
||||
doRender() {
|
||||
this.$widget = $(TPL);
|
||||
this.$trayEnabled = this.$widget.find(".tray-enabled");
|
||||
@ -23,7 +27,7 @@ export default class TrayOptions extends OptionsWidget {
|
||||
return utils.isElectron();
|
||||
}
|
||||
|
||||
async optionsLoaded(options) {
|
||||
async optionsLoaded(options: OptionMap) {
|
||||
this.$trayEnabled.prop("checked", options.disableTray !== "true");
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user