From dc8289df12e8c30861a38a15e3a39d277b5c9178 Mon Sep 17 00:00:00 2001 From: Matthew Nickson Date: Thu, 5 Jan 2023 22:55:51 +0000 Subject: [PATCH] Added JSDoc for src/ Signed-off-by: Matthew Nickson --- src/components/DockerHostDialog.vue | 8 +++++ src/components/notifications/Telegram.vue | 7 +++++ src/components/settings/Security.vue | 1 + src/mixins/datetime.js | 10 +++++++ src/mixins/socket.js | 36 +++++++++++++++++++++++ src/pages/EditMaintenance.vue | 12 ++++++++ src/pages/MaintenanceDetails.vue | 3 ++ src/pages/ManageMaintenance.vue | 10 +++++++ src/util.js | 16 ++++++++++ src/util.ts | 17 ++++++++++- 10 files changed, 119 insertions(+), 1 deletion(-) diff --git a/src/components/DockerHostDialog.vue b/src/components/DockerHostDialog.vue index 50ffa49c..fc9aea49 100644 --- a/src/components/DockerHostDialog.vue +++ b/src/components/DockerHostDialog.vue @@ -91,11 +91,16 @@ export default { }, methods: { + /** Confirm deletion of docker host */ deleteConfirm() { this.modal.hide(); this.$refs.confirmDelete.show(); }, + /** + * Show specified docker host + * @param {number} dockerHostID + */ show(dockerHostID) { if (dockerHostID) { let found = false; @@ -126,6 +131,7 @@ export default { this.modal.show(); }, + /** Add docker host */ submit() { this.processing = true; this.$root.getSocket().emit("addDockerHost", this.dockerHost, this.id, (res) => { @@ -144,6 +150,7 @@ export default { }); }, + /** Test the docker host */ test() { this.processing = true; this.$root.getSocket().emit("testDockerHost", this.dockerHost, (res) => { @@ -152,6 +159,7 @@ export default { }); }, + /** Delete this docker host */ deleteDockerHost() { this.processing = true; this.$root.getSocket().emit("deleteDockerHost", this.id, (res) => { diff --git a/src/components/notifications/Telegram.vue b/src/components/notifications/Telegram.vue index 9daf31ac..723bd1be 100644 --- a/src/components/notifications/Telegram.vue +++ b/src/components/notifications/Telegram.vue @@ -42,6 +42,11 @@ export default { HiddenInput, }, methods: { + /** + * Get the URL for telegram updates + * @param {string} [mode=masked] Should the token be masked? + * @returns {string} formatted URL + */ telegramGetUpdatesURL(mode = "masked") { let token = `<${this.$t("YOUR BOT TOKEN HERE")}>`; @@ -55,6 +60,8 @@ export default { return `https://api.telegram.org/bot${token}/getUpdates`; }, + + /** Get the telegram chat ID */ async autoGetTelegramChatID() { try { let res = await axios.get(this.telegramGetUpdatesURL("withToken")); diff --git a/src/components/settings/Security.vue b/src/components/settings/Security.vue index 330fe9ca..7d13ea90 100644 --- a/src/components/settings/Security.vue +++ b/src/components/settings/Security.vue @@ -191,6 +191,7 @@ export default { location.reload(); }, + /** Show confirmation dialog for disable auth */ confirmDisableAuth() { this.$refs.confirmDisableAuth.show(); }, diff --git a/src/mixins/datetime.js b/src/mixins/datetime.js index 4fa2fa83..5a282ad0 100644 --- a/src/mixins/datetime.js +++ b/src/mixins/datetime.js @@ -12,6 +12,11 @@ export default { }, methods: { + /** + * Convert value to UTC + * @param {string | number | Date | dayjs.Dayjs} value + * @returns {dayjs.Dayjs} + */ toUTC(value) { return dayjs.tz(value, this.timezone).utc().format(); }, @@ -34,6 +39,11 @@ export default { return this.datetimeFormat(value, "YYYY-MM-DD HH:mm:ss"); }, + /** + * Get time for maintenance + * @param {string | number | Date | dayjs.Dayjs} value + * @returns {string} + */ datetimeMaintenance(value) { const inputDate = new Date(value); const now = new Date(Date.now()); diff --git a/src/mixins/socket.js b/src/mixins/socket.js index 378af06a..0121eb15 100644 --- a/src/mixins/socket.js +++ b/src/mixins/socket.js @@ -454,6 +454,10 @@ export default { socket.emit("getMonitorList", callback); }, + /** + * Get list of maintenances + * @param {socketCB} callback + */ getMaintenanceList(callback) { if (! callback) { callback = () => { }; @@ -470,22 +474,49 @@ export default { socket.emit("add", monitor, callback); }, + /** + * Adds a maintenace + * @param {Object} maintenance + * @param {socketCB} callback + */ addMaintenance(maintenance, callback) { socket.emit("addMaintenance", maintenance, callback); }, + /** + * Add monitors to maintenance + * @param {number} maintenanceID + * @param {number[]} monitors + * @param {socketCB} callback + */ addMonitorMaintenance(maintenanceID, monitors, callback) { socket.emit("addMonitorMaintenance", maintenanceID, monitors, callback); }, + /** + * Add status page to maintenance + * @param {number} maintenanceID + * @param {number} statusPages + * @param {socketCB} callback + */ addMaintenanceStatusPage(maintenanceID, statusPages, callback) { socket.emit("addMaintenanceStatusPage", maintenanceID, statusPages, callback); }, + /** + * Get monitors affected by maintenance + * @param {number} maintenanceID + * @param {socketCB} callback + */ getMonitorMaintenance(maintenanceID, callback) { socket.emit("getMonitorMaintenance", maintenanceID, callback); }, + /** + * Get status pages where maintenance is shown + * @param {number} maintenanceID + * @param {socketCB} callback + */ getMaintenanceStatusPage(maintenanceID, callback) { socket.emit("getMaintenanceStatusPage", maintenanceID, callback); }, @@ -499,6 +530,11 @@ export default { socket.emit("deleteMonitor", monitorID, callback); }, + /** + * Delete specified maintenance + * @param {number} maintenanceID + * @param {socketCB} callback + */ deleteMaintenance(maintenanceID, callback) { socket.emit("deleteMaintenance", maintenanceID, callback); }, diff --git a/src/pages/EditMaintenance.vue b/src/pages/EditMaintenance.vue index d668d1ad..f0d87fe5 100644 --- a/src/pages/EditMaintenance.vue +++ b/src/pages/EditMaintenance.vue @@ -356,6 +356,7 @@ export default { }); }, methods: { + /** Initialise page */ init() { this.affectedMonitors = []; this.selectedStatusPages = []; @@ -414,6 +415,7 @@ export default { } }, + /** Create new maintenance */ async submit() { this.processing = true; @@ -458,6 +460,11 @@ export default { } }, + /** + * Add monitor to maintenance + * @param {number} maintenanceID + * @param {socketCB} callback + */ async addMonitorMaintenance(maintenanceID, callback) { await this.$root.addMonitorMaintenance(maintenanceID, this.affectedMonitors, async (res) => { if (!res.ok) { @@ -470,6 +477,11 @@ export default { }); }, + /** + * Add status page to maintenance + * @param {number} maintenanceID + * @param {socketCB} callback + */ async addMaintenanceStatusPage(maintenanceID, callback) { await this.$root.addMaintenanceStatusPage(maintenanceID, (this.showOnAllPages) ? this.selectedStatusPagesOptions : this.selectedStatusPages, async (res) => { if (!res.ok) { diff --git a/src/pages/MaintenanceDetails.vue b/src/pages/MaintenanceDetails.vue index 04c21691..0cf9283d 100644 --- a/src/pages/MaintenanceDetails.vue +++ b/src/pages/MaintenanceDetails.vue @@ -65,6 +65,7 @@ export default { this.init(); }, methods: { + /** Initialise page */ init() { this.$root.getSocket().emit("getMonitorMaintenance", this.$route.params.id, (res) => { if (res.ok) { @@ -83,10 +84,12 @@ export default { }); }, + /** Confirm deletion */ deleteDialog() { this.$refs.confirmDelete.show(); }, + /** Delete maintenance after showing confirmation */ deleteMaintenance() { this.$root.deleteMaintenance(this.maintenance.id, (res) => { if (res.ok) { diff --git a/src/pages/ManageMaintenance.vue b/src/pages/ManageMaintenance.vue index dd36c950..aaffbbf9 100644 --- a/src/pages/ManageMaintenance.vue +++ b/src/pages/ManageMaintenance.vue @@ -133,15 +133,25 @@ export default { } }, + /** + * Get maintenance URL + * @param {number} id + * @returns {string} Relative URL + */ maintenanceURL(id) { return getMaintenanceRelativeURL(id); }, + /** + * Show delete confirmation + * @param {number} maintenanceID + */ deleteDialog(maintenanceID) { this.selectedMaintenanceID = maintenanceID; this.$refs.confirmDelete.show(); }, + /** Delete maintenance after showing confirmation dialog */ deleteMaintenance() { this.$root.deleteMaintenance(this.selectedMaintenanceID, (res) => { if (res.ok) { diff --git a/src/util.js b/src/util.js index 09e6d0ee..6b8f8f37 100644 --- a/src/util.js +++ b/src/util.js @@ -315,6 +315,11 @@ function getMonitorRelativeURL(id) { return "/dashboard/" + id; } exports.getMonitorRelativeURL = getMonitorRelativeURL; +/** + * Get relative path for maintenance + * @param id ID of maintenance + * @returns Formatted relative path + */ function getMaintenanceRelativeURL(id) { return "/maintenance/" + id; } @@ -361,6 +366,11 @@ function parseTimeFromTimeObject(obj) { return result; } exports.parseTimeFromTimeObject = parseTimeFromTimeObject; +/** + * Convert ISO date to UTC + * @param input Date + * @returns ISO Date time + */ function isoToUTCDateTime(input) { return dayjs(input).utc().format(exports.SQL_DATETIME_FORMAT); } @@ -379,6 +389,12 @@ function utcToLocal(input, format = exports.SQL_DATETIME_FORMAT) { return dayjs.utc(input).local().format(format); } exports.utcToLocal = utcToLocal; +/** + * Convert local datetime to UTC + * @param input Local date + * @param format Format to return + * @returns Date in requested format + */ function localToUTC(input, format = exports.SQL_DATETIME_FORMAT) { return dayjs(input).utc().format(format); } diff --git a/src/util.ts b/src/util.ts index 99038c8d..e8a2706e 100644 --- a/src/util.ts +++ b/src/util.ts @@ -352,6 +352,11 @@ export function getMonitorRelativeURL(id: string) { return "/dashboard/" + id; } +/** + * Get relative path for maintenance + * @param id ID of maintenance + * @returns Formatted relative path + */ export function getMaintenanceRelativeURL(id: string) { return "/maintenance/" + id; } @@ -405,7 +410,11 @@ export function parseTimeFromTimeObject(obj : any) { return result; } - +/** + * Convert ISO date to UTC + * @param input Date + * @returns ISO Date time + */ export function isoToUTCDateTime(input : string) { return dayjs(input).utc().format(SQL_DATETIME_FORMAT); } @@ -424,6 +433,12 @@ export function utcToLocal(input : string, format = SQL_DATETIME_FORMAT) { return dayjs.utc(input).local().format(format); } +/** + * Convert local datetime to UTC + * @param input Local date + * @param format Format to return + * @returns Date in requested format + */ export function localToUTC(input : string, format = SQL_DATETIME_FORMAT) { return dayjs(input).utc().format(format); }