feat: opt-out option to show path instead of name for notifications

pull/5192/head
Peace 1 month ago
parent 16a41d53c1
commit 94af1d98d7
No known key found for this signature in database
GPG Key ID: 0EF6B46E172B739F

@ -0,0 +1,12 @@
exports.up = function (knex) {
return knex.schema
.alterTable("notification", function (table) {
table.boolean("use_path_as_name").notNullable().defaultTo(true);
});
};
exports.down = function (knex) {
return knex.schema.alterTable("notification", function (table) {
table.dropColumn("use_path_as_name");
});
};

@ -26,7 +26,15 @@ async function sendNotificationList(socket) {
for (let bean of list) {
let notificationObject = bean.export();
notificationObject.isDefault = (notificationObject.isDefault === 1);
notificationObject.usePathAsName = (notificationObject.usePathAsName === 1);
notificationObject.active = (notificationObject.active === 1);
const configObject = JSON.parse(notificationObject.config);
if ( !("usePathAsName" in configObject)) {
configObject.usePathAsName = notificationObject.usePathAsName;
notificationObject.config = JSON.stringify(configObject);
}
result.push(notificationObject);
}

@ -1336,8 +1336,10 @@ class Monitor extends BeanModel {
for (let notification of notificationList) {
try {
const heartbeatJSON = bean.toJSON();
const monitorData = [{ id: monitor.id,
active: monitor.active
const monitorData = [{
id: monitor.id,
name: monitor.name,
active: monitor.active,
}];
const preloadData = await Monitor.preparePreloadData(monitorData);
// Prevent if the msg is undefined, notifications such as Discord cannot send out.

@ -176,6 +176,9 @@ class Notification {
* @throws Error with fail msg
*/
static async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
if (notification.usePathAsName && monitorJSON) {
monitorJSON["name"] = monitorJSON["pathName"];
}
if (this.providerList[notification.type]) {
return this.providerList[notification.type].send(notification, msg, monitorJSON, heartbeatJSON);
} else {
@ -211,6 +214,8 @@ class Notification {
bean.user_id = userID;
bean.config = JSON.stringify(notification);
bean.is_default = notification.isDefault || false;
bean.use_path_as_name = notification.usePathAsName;
await R.store(bean);
if (notification.applyExisting) {

@ -41,6 +41,16 @@
<br>
<div class="form-check form-switch">
<input v-model="notification.usePathAsName" class="form-check-input" type="checkbox">
<label class="form-check-label">Use Monitor Path as Name</label>
</div>
<div class="form-text">
If your monitor is inside a group, the name will show the full path of the monitor. For example "Group A / Monitor 1".
</div>
<br>
<div class="form-check form-switch">
<input v-model="notification.applyExisting" class="form-check-input" type="checkbox">
<label class="form-check-label">{{ $t("Apply on all existing monitors") }}</label>
@ -95,6 +105,7 @@ export default {
/** @type { null | keyof NotificationFormList } */
type: null,
isDefault: false,
usePathAsName: false,
// Do not set default value here, please scroll to show()
}
};
@ -263,6 +274,7 @@ export default {
name: "",
type: "telegram",
isDefault: false,
usePathAsName: true,
};
}

Loading…
Cancel
Save