From 37420b2b1f2d125164ce7a6d8a89767932cd6328 Mon Sep 17 00:00:00 2001 From: jude Date: Fri, 11 Feb 2022 20:03:53 +0000 Subject: [PATCH] ..... --- Rocket.toml | 4 +-- migration/04-reminder_templates.sql | 31 +++++++++++++++++++ web/src/routes/dashboard/mod.rs | 26 ++++++++++++++++ web/templates/dashboard.html.tera | 13 ++++---- .../guild_reminder.html.tera | 2 +- 5 files changed, 67 insertions(+), 9 deletions(-) create mode 100644 migration/04-reminder_templates.sql diff --git a/Rocket.toml b/Rocket.toml index 666f089..eef8409 100644 --- a/Rocket.toml +++ b/Rocket.toml @@ -1,12 +1,12 @@ [default] -address = "0.0.0.0" +address = "127.0.0.1" port = 5000 template_dir = "web/templates" [debug] secret_key = "tR8krio5FXTnnyIZNiJDXPondz0kI1v6X6BXZcBGIRY=" -[default.tls] +[debug.tls] certs = "web/private/rsa_sha256_cert.pem" key = "web/private/rsa_sha256_key.pem" diff --git a/migration/04-reminder_templates.sql b/migration/04-reminder_templates.sql new file mode 100644 index 0000000..e6a4208 --- /dev/null +++ b/migration/04-reminder_templates.sql @@ -0,0 +1,31 @@ +USE reminders; + +CREATE TABLE reminder_template ( + `id` INT UNSIGNED NOT NULL AUTO_INCREMENT, + + `name` VARCHAR(24) NOT NULL DEFAULT 'Reminder', + + `guild_id` INT UNSIGNED NOT NULL, + + `username` VARCHAR(32) DEFAULT NULL, + `avatar` VARCHAR(512) DEFAULT NULL, + + `content` VARCHAR(2048) NOT NULL DEFAULT '', + `tts` BOOL NOT NULL DEFAULT 0, + `attachment` MEDIUMBLOB, + `attachment_name` VARCHAR(260), + + `embed_title` VARCHAR(256) NOT NULL DEFAULT '', + `embed_description` VARCHAR(2048) NOT NULL DEFAULT '', + `embed_image_url` VARCHAR(512), + `embed_thumbnail_url` VARCHAR(512), + `embed_footer` VARCHAR(2048) NOT NULL DEFAULT '', + `embed_footer_url` VARCHAR(512), + `embed_author` VARCHAR(256) NOT NULL DEFAULT '', + `embed_author_url` VARCHAR(512), + `embed_color` INT UNSIGNED NOT NULL DEFAULT 0x0, + + PRIMARY KEY (id), + + FOREIGN KEY (`guild_id`) REFERENCES channels (`id`) ON DELETE CASCADE, +); diff --git a/web/src/routes/dashboard/mod.rs b/web/src/routes/dashboard/mod.rs index 7801d38..8276b51 100644 --- a/web/src/routes/dashboard/mod.rs +++ b/web/src/routes/dashboard/mod.rs @@ -17,6 +17,7 @@ pub struct Reminder { attachment: Option>, attachment_name: Option, avatar: Option, + #[serde(with = "string")] channel: u64, content: String, embed_author: String, @@ -43,6 +44,31 @@ pub struct Reminder { utc_time: NaiveDateTime, } +// https://github.com/serde-rs/json/issues/329#issuecomment-305608405 +mod string { + use std::fmt::Display; + use std::str::FromStr; + + use serde::{de, Deserialize, Deserializer, Serializer}; + + pub fn serialize(value: &T, serializer: S) -> Result + where + T: Display, + S: Serializer, + { + serializer.collect_str(value) + } + + pub fn deserialize<'de, T, D>(deserializer: D) -> Result + where + T: FromStr, + T::Err: Display, + D: Deserializer<'de>, + { + String::deserialize(deserializer)?.parse().map_err(de::Error::custom) + } +} + #[derive(Deserialize)] pub struct DeleteReminder { uid: String, diff --git a/web/templates/dashboard.html.tera b/web/templates/dashboard.html.tera index 19c95dc..fb3dbb0 100644 --- a/web/templates/dashboard.html.tera +++ b/web/templates/dashboard.html.tera @@ -404,11 +404,16 @@ if (data.error) { show_error(data.error); } else { - const $template = document.querySelector('template#personalReminder'); + console.log(data); + + const $template = document.querySelector('template#guildReminder'); for (let reminder of data) { let newFrame = $template.content.cloneNode(true); + // populate channels + newFrame.querySelector('select.channel-selector'); + for (let prop in reminder) { if (reminder.hasOwnProperty(prop) && reminder[prop] !== null) { let $input = newFrame.querySelector(`*[name="${prop}"]`); @@ -642,11 +647,7 @@ } }); - fetch(`/dashboard/api/guild/${$anchor.dataset['guild']}/reminders`) - .then(response => response.json()) - .then(data => { - - }) + fetch_reminders($anchor.dataset['guild']); document.querySelectorAll('p.pageTitle').forEach((el) => { el.textContent = $anchor.dataset['name'] + ' Reminders'; diff --git a/web/templates/reminder_dashboard/guild_reminder.html.tera b/web/templates/reminder_dashboard/guild_reminder.html.tera index 5307c7d..94f3ff0 100644 --- a/web/templates/reminder_dashboard/guild_reminder.html.tera +++ b/web/templates/reminder_dashboard/guild_reminder.html.tera @@ -111,7 +111,7 @@
- +