diff --git a/server/client.js b/server/client.js index dcc778df2..bed2ba034 100644 --- a/server/client.js +++ b/server/client.js @@ -125,7 +125,7 @@ async function sendInfo(socket) { latestVersion: checkVersion.latestVersion, primaryBaseURL: await setting("primaryBaseURL"), serverTimezone: await server.getTimezone(), - serverTimezoneOffset: dayjs().format("Z"), + serverTimezoneOffset: server.getTimezoneOffset(), }); } diff --git a/server/model/maintenance.js b/server/model/maintenance.js index 2ab2a5bb4..4910d2a03 100644 --- a/server/model/maintenance.js +++ b/server/model/maintenance.js @@ -39,9 +39,15 @@ class Maintenance extends BeanModel { timeRange: timeRange, weekdays: (this.weekdays) ? JSON.parse(this.weekdays) : [], daysOfMonth: (this.days_of_month) ? JSON.parse(this.days_of_month) : [], - timeslotList: await this.getTimeslotList(), + timeslotList: [], }; + const timeslotList = await this.getTimeslotList(); + + for (let timeslot of timeslotList) { + obj.timeslotList.push(await timeslot.toPublicJSON()); + } + if (!isArray(obj.weekdays)) { obj.weekdays = []; } @@ -53,7 +59,9 @@ class Maintenance extends BeanModel { // Maintenance Status if (!obj.active) { obj.status = "inactive"; - } else if (obj.strategy === "manual" || obj.timeslotList.length > 0) { + } else if (obj.strategy === "manual") { + obj.status = "under-maintenance"; + } else if (obj.timeslotList.length > 0) { for (let timeslot of obj.timeslotList) { if (dayjs.utc(timeslot.start_date) <= dayjs.utc() && dayjs.utc(timeslot.end_date) >= dayjs.utc()) { obj.status = "under-maintenance"; @@ -78,7 +86,7 @@ class Maintenance extends BeanModel { * @returns {Promise<[]>} */ async getTimeslotList() { - return await R.getAll(` + return R.convertToBeans("maintenance_timeslot", await R.getAll(` SELECT maintenance_timeslot.* FROM maintenance_timeslot, maintenance WHERE maintenance_timeslot.maintenance_id = maintenance.id @@ -86,7 +94,7 @@ class Maintenance extends BeanModel { AND ${Maintenance.getActiveAndFutureMaintenanceSQLCondition()} `, [ this.id - ]); + ])); } /** @@ -156,10 +164,10 @@ class Maintenance extends BeanModel { */ static getActiveAndFutureMaintenanceSQLCondition() { return ` - (maintenance_timeslot.end_date >= DATETIME('now') + ((maintenance_timeslot.end_date >= DATETIME('now') AND maintenance.active = 1) OR - (maintenance.strategy = 'manual' AND active = 1) + (maintenance.strategy = 'manual' AND active = 1)) `; } } diff --git a/server/model/maintenance_timeslot.js b/server/model/maintenance_timeslot.js index 4db3a1dbb..f06806acb 100644 --- a/server/model/maintenance_timeslot.js +++ b/server/model/maintenance_timeslot.js @@ -1,16 +1,28 @@ const { BeanModel } = require("redbean-node/dist/bean-model"); const { R } = require("redbean-node"); const dayjs = require("dayjs"); -const { log } = require("../../src/util"); +const { log, utcToLocal, SQL_DATETIME_FORMAT_WITHOUT_SECOND } = require("../../src/util"); +const { UptimeKumaServer } = require("../uptime-kuma-server"); class MaintenanceTimeslot extends BeanModel { async toPublicJSON() { + const serverTimezoneOffset = await UptimeKumaServer.getInstance().getTimezoneOffset(); + const obj = { + id: this.id, + startDate: this.start_date, + endDate: this.end_date, + startDateServerTimezone: utcToLocal(this.start_date, SQL_DATETIME_FORMAT_WITHOUT_SECOND), + endDateServerTimezone: utcToLocal(this.end_date, SQL_DATETIME_FORMAT_WITHOUT_SECOND), + serverTimezoneOffset, + }; + + return obj; } async toJSON() { - + return await this.toPublicJSON(); } /** diff --git a/server/socket-handlers/maintenance-socket-handler.js b/server/socket-handlers/maintenance-socket-handler.js index 49527f23d..5294050ca 100644 --- a/server/socket-handlers/maintenance-socket-handler.js +++ b/server/socket-handlers/maintenance-socket-handler.js @@ -258,4 +258,54 @@ module.exports.maintenanceSocketHandler = (socket) => { }); } }); + + socket.on("pauseMaintenance", async (maintenanceID, callback) => { + try { + checkLogin(socket); + + log.debug("maintenance", `Pause Maintenance: ${maintenanceID} User ID: ${socket.userID}`); + + await R.exec("UPDATE maintenance SET active = 0 WHERE id = ? ", [ + maintenanceID, + ]); + + callback({ + ok: true, + msg: "Paused Successfully.", + }); + + await server.sendMaintenanceList(socket); + + } catch (e) { + callback({ + ok: false, + msg: e.message, + }); + } + }); + + socket.on("resumeMaintenance", async (maintenanceID, callback) => { + try { + checkLogin(socket); + + log.debug("maintenance", `Resume Maintenance: ${maintenanceID} User ID: ${socket.userID}`); + + await R.exec("UPDATE maintenance SET active = 1 WHERE id = ? ", [ + maintenanceID, + ]); + + callback({ + ok: true, + msg: "Resume Successfully", + }); + + await server.sendMaintenanceList(socket); + + } catch (e) { + callback({ + ok: false, + msg: e.message, + }); + } + }); }; diff --git a/server/uptime-kuma-server.js b/server/uptime-kuma-server.js index 155831592..667f6b6aa 100644 --- a/server/uptime-kuma-server.js +++ b/server/uptime-kuma-server.js @@ -204,6 +204,10 @@ class UptimeKumaServer { } } + async getTimezoneOffset() { + return dayjs().format("Z"); + } + async setTimezone(timezone) { await Settings.set("serverTimezone", timezone, "general"); process.env.TZ = timezone; diff --git a/src/assets/app.scss b/src/assets/app.scss index 7eb959315..7da76fff0 100644 --- a/src/assets/app.scss +++ b/src/assets/app.scss @@ -101,11 +101,6 @@ optgroup { } } -// Override Bootstrap -.btn-group > .btn:hover { - z-index: initial; -} - .btn { padding-left: 20px; padding-right: 20px; @@ -125,6 +120,19 @@ optgroup { } } +.btn-normal { + $bg-color: #F5F5F5; + + background-color: $bg-color; + border-color: $bg-color; + + &:hover { + $hover-color: darken($bg-color, 3%); + background-color: $hover-color; + border-color: $hover-color; + } +} + .btn-warning { color: white; diff --git a/src/languages/en.js b/src/languages/en.js index 835fa248d..a1c9b560c 100644 --- a/src/languages/en.js +++ b/src/languages/en.js @@ -631,4 +631,10 @@ export default { lastDay3: "3rd Last Day of Month", lastDay4: "4th Last Day of Month", "No Maintenance": "No Maintenance", + pauseMaintenanceMsg: "Are you sure want to pause?", + "maintenanceStatus-under-maintenance": "Under Maintenance", + "maintenanceStatus-inactive": "Inactive", + "maintenanceStatus-scheduled": "Scheduled", + "maintenanceStatus-ended": "Ended", + "maintenanceStatus-unknown": "Unknown", }; diff --git a/src/pages/ManageMaintenance.vue b/src/pages/ManageMaintenance.vue index 725e94b0f..af9c0ba5f 100644 --- a/src/pages/ManageMaintenance.vue +++ b/src/pages/ManageMaintenance.vue @@ -28,7 +28,18 @@ >