working on editing reminders
This commit is contained in:
parent
a56f84f659
commit
3b6e02e16e
@ -19,7 +19,8 @@ use crate::{
|
|||||||
MAX_URL_LENGTH, MAX_USERNAME_LENGTH, MIN_INTERVAL,
|
MAX_URL_LENGTH, MAX_USERNAME_LENGTH, MIN_INTERVAL,
|
||||||
},
|
},
|
||||||
routes::dashboard::{
|
routes::dashboard::{
|
||||||
create_database_channel, generate_uid, name_default, DeleteReminder, Reminder,
|
create_database_channel, generate_uid, name_default, DeleteReminder, PatchReminder,
|
||||||
|
Reminder,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -351,11 +352,17 @@ WHERE
|
|||||||
#[patch("/api/guild/<id>/reminders", data = "<reminder>")]
|
#[patch("/api/guild/<id>/reminders", data = "<reminder>")]
|
||||||
pub async fn edit_reminder(
|
pub async fn edit_reminder(
|
||||||
id: u64,
|
id: u64,
|
||||||
reminder: Json<Reminder>,
|
reminder: Json<PatchReminder>,
|
||||||
serenity_context: &State<Context>,
|
serenity_context: &State<Context>,
|
||||||
pool: &State<Pool<MySql>>,
|
pool: &State<Pool<MySql>>,
|
||||||
) -> JsonValue {
|
) -> JsonValue {
|
||||||
json!({"error": "Not implemented"})
|
if let Some(enabled) = reminder.enabled {
|
||||||
|
sqlx::query!("UPDATE reminders SET enabled = ? WHERE uid = ?", enabled, reminder.uid)
|
||||||
|
.execute(pool.inner())
|
||||||
|
.await;
|
||||||
|
}
|
||||||
|
|
||||||
|
json!({})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[delete("/api/guild/<id>/reminders", data = "<reminder>")]
|
#[delete("/api/guild/<id>/reminders", data = "<reminder>")]
|
||||||
|
@ -16,6 +16,8 @@ use crate::{
|
|||||||
pub mod guild;
|
pub mod guild;
|
||||||
pub mod user;
|
pub mod user;
|
||||||
|
|
||||||
|
type Unset<T> = Option<T>;
|
||||||
|
|
||||||
fn name_default() -> String {
|
fn name_default() -> String {
|
||||||
"Reminder".to_string()
|
"Reminder".to_string()
|
||||||
}
|
}
|
||||||
@ -52,6 +54,57 @@ pub struct Reminder {
|
|||||||
utc_time: NaiveDateTime,
|
utc_time: NaiveDateTime,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
pub struct PatchReminder {
|
||||||
|
uid: String,
|
||||||
|
#[serde(default)]
|
||||||
|
attachment: Unset<Option<Vec<u8>>>,
|
||||||
|
#[serde(default)]
|
||||||
|
attachment_name: Unset<Option<String>>,
|
||||||
|
#[serde(default)]
|
||||||
|
avatar: Unset<Option<String>>,
|
||||||
|
#[serde(default)]
|
||||||
|
content: Unset<String>,
|
||||||
|
#[serde(default)]
|
||||||
|
embed_author: Unset<String>,
|
||||||
|
#[serde(default)]
|
||||||
|
embed_author_url: Unset<Option<String>>,
|
||||||
|
#[serde(default)]
|
||||||
|
embed_color: Unset<u32>,
|
||||||
|
#[serde(default)]
|
||||||
|
embed_description: Unset<String>,
|
||||||
|
#[serde(default)]
|
||||||
|
embed_footer: Unset<String>,
|
||||||
|
#[serde(default)]
|
||||||
|
embed_footer_url: Unset<Option<String>>,
|
||||||
|
#[serde(default)]
|
||||||
|
embed_image_url: Unset<Option<String>>,
|
||||||
|
#[serde(default)]
|
||||||
|
embed_thumbnail_url: Unset<Option<String>>,
|
||||||
|
#[serde(default)]
|
||||||
|
embed_title: Unset<String>,
|
||||||
|
#[serde(default)]
|
||||||
|
enabled: Unset<bool>,
|
||||||
|
#[serde(default)]
|
||||||
|
expires: Unset<Option<NaiveDateTime>>,
|
||||||
|
#[serde(default)]
|
||||||
|
interval_seconds: Unset<Option<u32>>,
|
||||||
|
#[serde(default)]
|
||||||
|
interval_months: Unset<Option<u32>>,
|
||||||
|
#[serde(default)]
|
||||||
|
name: Unset<String>,
|
||||||
|
#[serde(default)]
|
||||||
|
pin: Unset<bool>,
|
||||||
|
#[serde(default)]
|
||||||
|
restartable: Unset<bool>,
|
||||||
|
#[serde(default)]
|
||||||
|
tts: Unset<bool>,
|
||||||
|
#[serde(default)]
|
||||||
|
username: Unset<Option<String>>,
|
||||||
|
#[serde(default)]
|
||||||
|
utc_time: Unset<NaiveDateTime>,
|
||||||
|
}
|
||||||
|
|
||||||
pub fn generate_uid() -> String {
|
pub fn generate_uid() -> String {
|
||||||
let mut generator: OsRng = Default::default();
|
let mut generator: OsRng = Default::default();
|
||||||
|
|
||||||
|
@ -138,6 +138,8 @@ async function fetch_reminders(guild_id) {
|
|||||||
for (let reminder of data) {
|
for (let reminder of data) {
|
||||||
let newFrame = $template.content.cloneNode(true);
|
let newFrame = $template.content.cloneNode(true);
|
||||||
|
|
||||||
|
newFrame.querySelector('.reminderContent').dataset.uid = reminder['uid'];
|
||||||
|
|
||||||
// populate channels
|
// populate channels
|
||||||
set_channels(newFrame.querySelector('select.channel-selector'))
|
set_channels(newFrame.querySelector('select.channel-selector'))
|
||||||
|
|
||||||
@ -155,6 +157,21 @@ async function fetch_reminders(guild_id) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let guild = document.querySelector('.guildList a.is-active').dataset['guild'];
|
||||||
|
|
||||||
|
let $enableBtn = newFrame.querySelector('.disable-enable');
|
||||||
|
|
||||||
|
$enableBtn.textContent = reminder['enabled'] ? 'Disable' : 'Enable';
|
||||||
|
$enableBtn.addEventListener('click', () => {
|
||||||
|
fetch(`/dashboard/api/guild/${guild}/reminders`, {
|
||||||
|
method: 'PATCH',
|
||||||
|
body: JSON.stringify({
|
||||||
|
uid: reminder['uid'],
|
||||||
|
enabled: false
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
let timeInput = newFrame.querySelector('input[name="time"]');
|
let timeInput = newFrame.querySelector('input[name="time"]');
|
||||||
let localTime = luxon.DateTime.fromISO(reminder["utc_time"]).setZone(timezone);
|
let localTime = luxon.DateTime.fromISO(reminder["utc_time"]).setZone(timezone);
|
||||||
timeInput.value = localTime.toFormat("yyyy-LL-dd'T'HH:mm:ss");
|
timeInput.value = localTime.toFormat("yyyy-LL-dd'T'HH:mm:ss");
|
||||||
|
@ -204,7 +204,7 @@
|
|||||||
<button class="button is-primary" disabled>
|
<button class="button is-primary" disabled>
|
||||||
Saved!
|
Saved!
|
||||||
</button>
|
</button>
|
||||||
<button class="button is-warning">
|
<button class="button is-warning disable-enable">
|
||||||
Disable
|
Disable
|
||||||
</button>
|
</button>
|
||||||
<button class="button is-danger">
|
<button class="button is-danger">
|
||||||
|
Loading…
Reference in New Issue
Block a user