chore(prettier): run prettier on time_selector related files

This commit is contained in:
Panagiotis Papadopoulos 2025-02-16 18:13:52 +01:00
parent 793b0c9fe8
commit 10ba467202
3 changed files with 17 additions and 32 deletions

View File

@ -18,7 +18,6 @@ const TPL2 = `
</div>`; </div>`;
export default class AttachmentErasureTimeoutOptions extends TimeSelector { export default class AttachmentErasureTimeoutOptions extends TimeSelector {
private $eraseUnusedAttachmentsNowButton!: JQuery<HTMLElement>; private $eraseUnusedAttachmentsNowButton!: JQuery<HTMLElement>;
constructor() { constructor() {
@ -27,8 +26,8 @@ export default class AttachmentErasureTimeoutOptions extends TimeSelector {
widgetLabelId: "attachment_erasure_timeout.erase_attachments_after_x_seconds", widgetLabelId: "attachment_erasure_timeout.erase_attachments_after_x_seconds",
optionValueId: "eraseUnusedAttachmentsAfterSeconds", optionValueId: "eraseUnusedAttachmentsAfterSeconds",
optionTimeScaleId: "eraseUnusedAttachmentsAfterTimeScale" optionTimeScaleId: "eraseUnusedAttachmentsAfterTimeScale"
}) });
super.doRender() super.doRender();
} }
doRender() { doRender() {
@ -41,5 +40,4 @@ export default class AttachmentErasureTimeoutOptions extends TimeSelector {
}); });
}); });
} }
} }

View File

@ -17,22 +17,19 @@ const TPL2 = `
</div>`; </div>`;
export default class NoteErasureTimeoutOptions extends TimeSelector { export default class NoteErasureTimeoutOptions extends TimeSelector {
private $eraseDeletedNotesButton!: JQuery<HTMLButtonElement>; private $eraseDeletedNotesButton!: JQuery<HTMLButtonElement>;
constructor() { constructor() {
super( { super({
widgetId: "erase-entities-after", widgetId: "erase-entities-after",
widgetLabelId: "note_erasure_timeout.erase_notes_after", widgetLabelId: "note_erasure_timeout.erase_notes_after",
optionValueId: "eraseEntitiesAfterTimeInSeconds", optionValueId: "eraseEntitiesAfterTimeInSeconds",
optionTimeScaleId: "eraseEntitiesAfterTimeScale" optionTimeScaleId: "eraseEntitiesAfterTimeScale"
}) });
super.doRender(); super.doRender();
} }
doRender() { doRender() {
this.$widget = $(TPL).append(this.$widget).append(TPL2); this.$widget = $(TPL).append(this.$widget).append(TPL2);
this.$eraseDeletedNotesButton = this.$widget.find("#erase-deleted-notes-now-button"); this.$eraseDeletedNotesButton = this.$widget.find("#erase-deleted-notes-now-button");
@ -43,5 +40,4 @@ export default class NoteErasureTimeoutOptions extends TimeSelector {
}); });
}); });
} }
} }

View File

@ -3,7 +3,6 @@ import toastService from "../../../services/toast.js";
import { t } from "../../../services/i18n.js"; import { t } from "../../../services/i18n.js";
import type { OptionDefinitions, OptionMap } from "../../../../../services/options_interface.js"; import type { OptionDefinitions, OptionMap } from "../../../../../services/options_interface.js";
type TimeSelectorConstructor = { type TimeSelectorConstructor = {
widgetId: string; widgetId: string;
widgetLabelId: string; widgetLabelId: string;
@ -14,7 +13,6 @@ type TimeSelectorConstructor = {
type TimeSelectorScale = "seconds" | "minutes" | "hours" | "days"; type TimeSelectorScale = "seconds" | "minutes" | "hours" | "days";
const TPL = (options: Omit<TimeSelectorConstructor, "optionValueId" | "optionTimeScaleId">) => ` const TPL = (options: Omit<TimeSelectorConstructor, "optionValueId" | "optionTimeScaleId">) => `
<div class="form-group"> <div class="form-group">
<label for="${options.widgetId}">${t(options.widgetLabelId)}</label> <label for="${options.widgetId}">${t(options.widgetLabelId)}</label>
@ -37,7 +35,6 @@ const TPL = (options: Omit<TimeSelectorConstructor, "optionValueId" | "optionTim
</style>`; </style>`;
export default class TimeSelector extends OptionsWidget { export default class TimeSelector extends OptionsWidget {
private $timeValueInput!: JQuery<HTMLInputElement>; private $timeValueInput!: JQuery<HTMLInputElement>;
private $timeScaleSelect!: JQuery<HTMLSelectElement>; private $timeScaleSelect!: JQuery<HTMLSelectElement>;
private internalTimeInSeconds!: string | number; private internalTimeInSeconds!: string | number;
@ -53,15 +50,17 @@ export default class TimeSelector extends OptionsWidget {
this.widgetLabelId = options.widgetLabelId; this.widgetLabelId = options.widgetLabelId;
this.optionValueId = options.optionValueId; this.optionValueId = options.optionValueId;
this.optionTimeScaleId = options.optionTimeScaleId; this.optionTimeScaleId = options.optionTimeScaleId;
this.includedTimeScales = (!options.includedTimeScales) ? new Set(["seconds", "minutes", "hours", "days"]) : options.includedTimeScales; this.includedTimeScales = !options.includedTimeScales ? new Set(["seconds", "minutes", "hours", "days"]) : options.includedTimeScales;
} }
doRender() { doRender() {
this.$widget = $(TPL({ this.$widget = $(
TPL({
widgetId: this.widgetId, widgetId: this.widgetId,
widgetLabelId: this.widgetLabelId, widgetLabelId: this.widgetLabelId,
includedTimeScales: this.includedTimeScales, includedTimeScales: this.includedTimeScales
})); })
);
this.$timeValueInput = this.$widget.find(`#${this.widgetId}`); this.$timeValueInput = this.$widget.find(`#${this.widgetId}`);
this.$timeScaleSelect = this.$widget.find(`#${this.widgetId}-time-scale`); this.$timeScaleSelect = this.$widget.find(`#${this.widgetId}-time-scale`);
@ -74,11 +73,9 @@ export default class TimeSelector extends OptionsWidget {
this.internalTimeInSeconds = this.convertTime(time, timeScale).toOption(); this.internalTimeInSeconds = this.convertTime(time, timeScale).toOption();
this.updateOption(this.optionValueId, this.internalTimeInSeconds); this.updateOption(this.optionValueId, this.internalTimeInSeconds);
}); });
this.$timeScaleSelect.on("change", () => { this.$timeScaleSelect.on("change", () => {
const timeScale = this.$timeScaleSelect.val(); const timeScale = this.$timeScaleSelect.val();
if (!this.handleTimeValidation() || typeof timeScale !== "string") return; if (!this.handleTimeValidation() || typeof timeScale !== "string") return;
@ -88,9 +85,7 @@ export default class TimeSelector extends OptionsWidget {
this.updateOption(this.optionTimeScaleId, timeScale); this.updateOption(this.optionTimeScaleId, timeScale);
this.$timeValueInput.val(displayedTime).trigger("change"); this.$timeValueInput.val(displayedTime).trigger("change");
}); });
} }
async optionsLoaded(options: OptionMap) { async optionsLoaded(options: OptionMap) {
@ -100,9 +95,7 @@ export default class TimeSelector extends OptionsWidget {
this.$timeScaleSelect.val(options[this.optionTimeScaleId]); this.$timeScaleSelect.val(options[this.optionTimeScaleId]);
} }
convertTime(time: string | number, timeScale: string | number) { convertTime(time: string | number, timeScale: string | number) {
const value = typeof time === "number" ? time : parseInt(time); const value = typeof time === "number" ? time : parseInt(time);
if (Number.isNaN(value)) { if (Number.isNaN(value)) {
throw new Error(`Time needs to be a valid integer, but received: ${time}`); throw new Error(`Time needs to be a valid integer, but received: ${time}`);
@ -115,17 +108,15 @@ export default class TimeSelector extends OptionsWidget {
return { return {
toOption: () => Math.ceil(value * operand), toOption: () => Math.ceil(value * operand),
toDisplay: () => Math.ceil(value / operand), toDisplay: () => Math.ceil(value / operand)
} };
} }
handleTimeValidation() { handleTimeValidation() {
if (this.$timeValueInput.is(":invalid")) { if (this.$timeValueInput.is(":invalid")) {
toastService.showMessage(t("time_selector.invalid_input")); toastService.showMessage(t("time_selector.invalid_input"));
return false return false;
} }
return true; return true;
} }
} }