mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-10-31 13:01:31 +08:00 
			
		
		
		
	chore(prettier): run prettier on time_selector related files
This commit is contained in:
		
							parent
							
								
									793b0c9fe8
								
							
						
					
					
						commit
						10ba467202
					
				| @ -18,7 +18,6 @@ const TPL2 = ` | ||||
| </div>`;
 | ||||
| 
 | ||||
| export default class AttachmentErasureTimeoutOptions extends TimeSelector { | ||||
| 
 | ||||
|     private $eraseUnusedAttachmentsNowButton!: JQuery<HTMLElement>; | ||||
| 
 | ||||
|     constructor() { | ||||
| @ -27,8 +26,8 @@ export default class AttachmentErasureTimeoutOptions extends TimeSelector { | ||||
|             widgetLabelId: "attachment_erasure_timeout.erase_attachments_after_x_seconds", | ||||
|             optionValueId: "eraseUnusedAttachmentsAfterSeconds", | ||||
|             optionTimeScaleId: "eraseUnusedAttachmentsAfterTimeScale" | ||||
|         }) | ||||
|       super.doRender() | ||||
|         }); | ||||
|         super.doRender(); | ||||
|     } | ||||
| 
 | ||||
|     doRender() { | ||||
| @ -41,5 +40,4 @@ export default class AttachmentErasureTimeoutOptions extends TimeSelector { | ||||
|             }); | ||||
|         }); | ||||
|     } | ||||
| 
 | ||||
| } | ||||
|  | ||||
| @ -17,22 +17,19 @@ const TPL2 = ` | ||||
| </div>`;
 | ||||
| 
 | ||||
| export default class NoteErasureTimeoutOptions extends TimeSelector { | ||||
| 
 | ||||
|     private $eraseDeletedNotesButton!: JQuery<HTMLButtonElement>; | ||||
| 
 | ||||
|     constructor() { | ||||
|         super( { | ||||
|         super({ | ||||
|             widgetId: "erase-entities-after", | ||||
|             widgetLabelId: "note_erasure_timeout.erase_notes_after", | ||||
|             optionValueId: "eraseEntitiesAfterTimeInSeconds", | ||||
|             optionTimeScaleId: "eraseEntitiesAfterTimeScale" | ||||
|         }) | ||||
|         }); | ||||
|         super.doRender(); | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     doRender() { | ||||
| 
 | ||||
|         this.$widget = $(TPL).append(this.$widget).append(TPL2); | ||||
| 
 | ||||
|         this.$eraseDeletedNotesButton = this.$widget.find("#erase-deleted-notes-now-button"); | ||||
| @ -43,5 +40,4 @@ export default class NoteErasureTimeoutOptions extends TimeSelector { | ||||
|             }); | ||||
|         }); | ||||
|     } | ||||
| 
 | ||||
| } | ||||
|  | ||||
| @ -3,7 +3,6 @@ import toastService from "../../../services/toast.js"; | ||||
| import { t } from "../../../services/i18n.js"; | ||||
| import type { OptionDefinitions, OptionMap } from "../../../../../services/options_interface.js"; | ||||
| 
 | ||||
| 
 | ||||
| type TimeSelectorConstructor = { | ||||
|     widgetId: string; | ||||
|     widgetLabelId: string; | ||||
| @ -14,7 +13,6 @@ type TimeSelectorConstructor = { | ||||
| 
 | ||||
| type TimeSelectorScale = "seconds" | "minutes" | "hours" | "days"; | ||||
| 
 | ||||
| 
 | ||||
| const TPL = (options: Omit<TimeSelectorConstructor, "optionValueId" | "optionTimeScaleId">) => ` | ||||
|     <div class="form-group"> | ||||
|         <label for="${options.widgetId}">${t(options.widgetLabelId)}</label> | ||||
| @ -37,7 +35,6 @@ const TPL = (options: Omit<TimeSelectorConstructor, "optionValueId" | "optionTim | ||||
| </style>`;
 | ||||
| 
 | ||||
| export default class TimeSelector extends OptionsWidget { | ||||
| 
 | ||||
|     private $timeValueInput!: JQuery<HTMLInputElement>; | ||||
|     private $timeScaleSelect!: JQuery<HTMLSelectElement>; | ||||
|     private internalTimeInSeconds!: string | number; | ||||
| @ -53,15 +50,17 @@ export default class TimeSelector extends OptionsWidget { | ||||
|         this.widgetLabelId = options.widgetLabelId; | ||||
|         this.optionValueId = options.optionValueId; | ||||
|         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() { | ||||
|         this.$widget = $(TPL({ | ||||
|         this.$widget = $( | ||||
|             TPL({ | ||||
|                 widgetId: this.widgetId, | ||||
|                 widgetLabelId: this.widgetLabelId, | ||||
|             includedTimeScales: this.includedTimeScales, | ||||
|         })); | ||||
|                 includedTimeScales: this.includedTimeScales | ||||
|             }) | ||||
|         ); | ||||
| 
 | ||||
|         this.$timeValueInput = this.$widget.find(`#${this.widgetId}`); | ||||
|         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.updateOption(this.optionValueId, this.internalTimeInSeconds); | ||||
| 
 | ||||
|         }); | ||||
| 
 | ||||
|         this.$timeScaleSelect.on("change", () => { | ||||
| 
 | ||||
|             const timeScale = this.$timeScaleSelect.val(); | ||||
| 
 | ||||
|             if (!this.handleTimeValidation() || typeof timeScale !== "string") return; | ||||
| @ -88,9 +85,7 @@ export default class TimeSelector extends OptionsWidget { | ||||
| 
 | ||||
|             this.updateOption(this.optionTimeScaleId, timeScale); | ||||
|             this.$timeValueInput.val(displayedTime).trigger("change"); | ||||
| 
 | ||||
|         }); | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     async optionsLoaded(options: OptionMap) { | ||||
| @ -100,9 +95,7 @@ export default class TimeSelector extends OptionsWidget { | ||||
|         this.$timeScaleSelect.val(options[this.optionTimeScaleId]); | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
|     convertTime(time: string | number, timeScale: string | number) { | ||||
| 
 | ||||
|         const value = typeof time === "number" ? time : parseInt(time); | ||||
|         if (Number.isNaN(value)) { | ||||
|             throw new Error(`Time needs to be a valid integer, but received: ${time}`); | ||||
| @ -115,17 +108,15 @@ export default class TimeSelector extends OptionsWidget { | ||||
| 
 | ||||
|         return { | ||||
|             toOption: () => Math.ceil(value * operand), | ||||
|             toDisplay: () => Math.ceil(value / operand), | ||||
|         } | ||||
| 
 | ||||
|             toDisplay: () => Math.ceil(value / operand) | ||||
|         }; | ||||
|     } | ||||
| 
 | ||||
|     handleTimeValidation() { | ||||
|         if (this.$timeValueInput.is(":invalid")) { | ||||
|             toastService.showMessage(t("time_selector.invalid_input")); | ||||
|             return false | ||||
|             return false; | ||||
|         } | ||||
|         return true; | ||||
|     } | ||||
| 
 | ||||
| } | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Panagiotis Papadopoulos
						Panagiotis Papadopoulos