From 56ffc436160e7e2235b9836432cad3533cb6a1ca Mon Sep 17 00:00:00 2001 From: jude Date: Sat, 23 Sep 2023 22:47:21 +0100 Subject: [PATCH] Store intervals in templates --- ...0230923210620_reminder_template_intervals.sql | 3 +++ web/src/routes/dashboard/export.rs | 3 +++ web/src/routes/dashboard/guild.rs | 16 +++++++++++----- web/src/routes/dashboard/mod.rs | 6 ++++++ web/static/js/main.js | 15 +++++++-------- 5 files changed, 30 insertions(+), 13 deletions(-) create mode 100644 migrations/20230923210620_reminder_template_intervals.sql diff --git a/migrations/20230923210620_reminder_template_intervals.sql b/migrations/20230923210620_reminder_template_intervals.sql new file mode 100644 index 0000000..1c26efd --- /dev/null +++ b/migrations/20230923210620_reminder_template_intervals.sql @@ -0,0 +1,3 @@ +ALTER TABLE `reminder_template` ADD COLUMN `interval_seconds` INT UNSIGNED; +ALTER TABLE `reminder_template` ADD COLUMN `interval_days` INT UNSIGNED; +ALTER TABLE `reminder_template` ADD COLUMN `interval_months` INT UNSIGNED; diff --git a/web/src/routes/dashboard/export.rs b/web/src/routes/dashboard/export.rs index d1f33c1..cb5c065 100644 --- a/web/src/routes/dashboard/export.rs +++ b/web/src/routes/dashboard/export.rs @@ -388,6 +388,9 @@ pub async fn export_reminder_templates( embed_thumbnail_url, embed_title, embed_fields, + interval_seconds, + interval_days, + interval_months, tts, username FROM reminder_template WHERE guild_id = (SELECT id FROM guilds WHERE guild = ?)", diff --git a/web/src/routes/dashboard/guild.rs b/web/src/routes/dashboard/guild.rs index 1f89aca..6cbdb9e 100644 --- a/web/src/routes/dashboard/guild.rs +++ b/web/src/routes/dashboard/guild.rs @@ -232,10 +232,15 @@ pub async fn create_reminder_template( embed_thumbnail_url, embed_title, embed_fields, + interval_seconds, + interval_days, + interval_months, tts, username - ) VALUES ((SELECT id FROM guilds WHERE guild = ?), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", - id, name, + ) VALUES ((SELECT id FROM guilds WHERE guild = ?), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?)", + id, + name, reminder_template.attachment, reminder_template.attachment_name, reminder_template.avatar, @@ -250,15 +255,16 @@ pub async fn create_reminder_template( reminder_template.embed_thumbnail_url, reminder_template.embed_title, reminder_template.embed_fields, + reminder_template.interval_seconds, + reminder_template.interval_days, + reminder_template.interval_months, reminder_template.tts, reminder_template.username, ) .fetch_all(pool.inner()) .await { - Ok(_) => { - Ok(json!({})) - } + Ok(_) => Ok(json!({})), Err(e) => { warn!("Could not create template for {}: {:?}", id, e); diff --git a/web/src/routes/dashboard/mod.rs b/web/src/routes/dashboard/mod.rs index 4168a4a..40069e8 100644 --- a/web/src/routes/dashboard/mod.rs +++ b/web/src/routes/dashboard/mod.rs @@ -80,6 +80,9 @@ pub struct ReminderTemplate { embed_thumbnail_url: Option, embed_title: String, embed_fields: Option>>, + interval_seconds: Option, + interval_days: Option, + interval_months: Option, tts: bool, username: Option, } @@ -102,6 +105,9 @@ pub struct ReminderTemplateCsv { embed_thumbnail_url: Option, embed_title: String, embed_fields: Option, + interval_seconds: Option, + interval_days: Option, + interval_months: Option, tts: bool, username: Option, } diff --git a/web/static/js/main.js b/web/static/js/main.js index b79ce7d..cbd6f79 100644 --- a/web/static/js/main.js +++ b/web/static/js/main.js @@ -223,11 +223,10 @@ async function fetch_reminders(guild_id) { } async function serialize_reminder(node, mode) { - let interval, utc_time, expiration_time; + let utc_time, expiration_time; + let interval = get_interval(node); if (mode !== "template") { - interval = get_interval(node); - utc_time = luxon.DateTime.fromISO( node.querySelector('input[name="time"]').value ).setZone("UTC"); @@ -356,9 +355,9 @@ async function serialize_reminder(node, mode) { embed_title: embed_title, embed_fields: fields, expires: expiration_time, - interval_seconds: mode !== "template" ? interval.seconds : null, - interval_days: mode !== "template" ? interval.days : null, - interval_months: mode !== "template" ? interval.months : null, + interval_seconds: interval.seconds, + interval_days: interval.days, + interval_months: interval.months, name: node.querySelector('input[name="name"]').value, tts: node.querySelector('input[name="tts"]').checked, username: node.querySelector('input[name="username"]').value, @@ -420,9 +419,9 @@ function deserialize_reminder(reminder, frame, mode) { .insertBefore(embed_field, lastChild); } - if (mode !== "template") { - if (reminder["interval_seconds"]) update_interval(frame); + if (reminder["interval_seconds"]) update_interval(frame); + if (mode !== "template") { let $enableBtn = frame.querySelector(".disable-enable"); $enableBtn.dataset["action"] = reminder["enabled"] ? "disable" : "enable";