diff --git a/bin/upgrade/DEV/add_creation_date_for_existing_alerts.js b/bin/upgrade/DEV/add_creation_date_for_existing_alerts.js new file mode 100644 index 00000000000..7ad693b0331 --- /dev/null +++ b/bin/upgrade/DEV/add_creation_date_for_existing_alerts.js @@ -0,0 +1,25 @@ +// Script that adds creation date for existing alerts. + +const pluginManager = require('../../../plugins/pluginManager.js'); + +pluginManager.dbConnection().then(async(countlyDb) => { + try { + await countlyDb.collection('alerts').updateMany( + { createdAt: { $exists: false } }, + [ + { + $set: { + createdAt: { $toDouble: { $toDate: "$_id" } } + } + } + ] + ); + console.log("Finished adding creation date for existing alerts."); + } + catch (error) { + console.log(`Error adding creation date for existing alerts: ${error}`); + } + finally { + countlyDb.close(); + } +}); \ No newline at end of file diff --git a/plugins/alerts/api/api.js b/plugins/alerts/api/api.js index a691ee982c8..bc9242eab1d 100644 --- a/plugins/alerts/api/api.js +++ b/plugins/alerts/api/api.js @@ -225,6 +225,9 @@ const PERIOD_TO_TEXT_EXPRESSION_MAPPER = { } }); } + if (!alertConfig._id) { + alertConfig.createdAt = new Date().getTime(); + } alertConfig.createdBy = params.member._id; return common.db.collection("alerts").insert( alertConfig, diff --git a/plugins/alerts/frontend/public/javascripts/countly.models.js b/plugins/alerts/frontend/public/javascripts/countly.models.js index 73c63608af6..41e88ad55c9 100644 --- a/plugins/alerts/frontend/public/javascripts/countly.models.js +++ b/plugins/alerts/frontend/public/javascripts/countly.models.js @@ -503,6 +503,7 @@ enabled: alertsList[i].enabled || false, createdByUser: alertsList[i].createdByUser || "", + createdAt: alertsList[i].createdAt || "", _canUpdate: countlyAuth.validateUpdate( FEATURE_NAME, countlyGlobal.member, diff --git a/plugins/alerts/frontend/public/localization/alerts.properties b/plugins/alerts/frontend/public/localization/alerts.properties index 2601e3bdfe0..fd824d89af5 100644 --- a/plugins/alerts/frontend/public/localization/alerts.properties +++ b/plugins/alerts/frontend/public/localization/alerts.properties @@ -5,7 +5,7 @@ alert.plugin-title = Alerts alert.Add_New_Alert=Add New Alert alert.Edit_Your_Alert=Edit Your Alert -alert.Alert_Name=Alert Name +alerts.Alert_Name=Alert Name alert.Event=Events alert.View=Views alert.Session=Sessions @@ -59,9 +59,9 @@ alert.delete-confirm = Confirm to delete this alert? alert.yes-delete-alert = Yes, delete alert alert.email-place-holder=Enter emails alert.enter-alert-name = Enter alert name -alert.Application = Application -alert.Condition = Condition -alert.CreateBy = Created by +alerts.Application = Application +alerts.Condition = Condition +alerts.CreateBy = Created by alert.compare-remind = Metrics are compared on a daily basis. alert.add-number = Add Number alert.make-changes-remind = You made {0} changes. diff --git a/plugins/alerts/frontend/public/templates/vue-main.html b/plugins/alerts/frontend/public/templates/vue-main.html index bb5b2be9da8..c0bf438df19 100644 --- a/plugins/alerts/frontend/public/templates/vue-main.html +++ b/plugins/alerts/frontend/public/templates/vue-main.html @@ -44,7 +44,9 @@ class="cly-vue-alerts-table" :tracked-fields="localTableTrackedFields" :rows="tableRows" - :resizable="false"> + :resizable="false" + :default-sort="{prop: 'createdAt', order: 'descending'}" + >