Changed data import to add alongside rather than removing.

This commit is contained in:
jude 2023-03-24 19:41:34 +00:00
parent 4e0163f2cb
commit 314c72e132
6 changed files with 16 additions and 26 deletions

View File

@ -492,8 +492,10 @@ WHERE
w.content(&reminder.content).tts(reminder.tts); w.content(&reminder.content).tts(reminder.tts);
if let Some(username) = &reminder.username { if let Some(username) = &reminder.username {
if !username.is_empty() {
w.username(username); w.username(username);
} }
}
if let Some(avatar) = &reminder.avatar { if let Some(avatar) = &reminder.avatar {
w.avatar_url(avatar); w.avatar_url(avatar);

View File

@ -172,7 +172,7 @@ pub async fn import_reminders(
create_reminder( create_reminder(
ctx.inner(), ctx.inner(),
pool.inner(), transaction,
GuildId(id), GuildId(id),
UserId(user_id), UserId(user_id),
reminder, reminder,
@ -320,13 +320,6 @@ pub async fn import_todos(
} }
} }
let _ = sqlx::query!(
"DELETE FROM todos WHERE guild_id = (SELECT id FROM guilds WHERE guild = ?)",
id
)
.execute(pool.inner())
.await;
let query_str = format!( let query_str = format!(
"INSERT INTO todos (value, channel_id, guild_id) VALUES {}", "INSERT INTO todos (value, channel_id, guild_id) VALUES {}",
vec![query_placeholder].repeat(query_params.len()).join(",") vec![query_placeholder].repeat(query_params.len()).join(",")

View File

@ -353,7 +353,7 @@ pub struct TodoCsv {
pub async fn create_reminder( pub async fn create_reminder(
ctx: &Context, ctx: &Context,
pool: &Pool<MySql>, pool: impl sqlx::Executor<'_, Database = Database> + Copy,
guild_id: GuildId, guild_id: GuildId,
user_id: UserId, user_id: UserId,
reminder: Reminder, reminder: Reminder,
@ -450,6 +450,11 @@ pub async fn create_reminder(
// base64 decode error dropped here // base64 decode error dropped here
let attachment_data = reminder.attachment.as_ref().map(|s| base64::decode(s).ok()).flatten(); let attachment_data = reminder.attachment.as_ref().map(|s| base64::decode(s).ok()).flatten();
let name = if reminder.name.is_empty() { name_default() } else { reminder.name.clone() }; let name = if reminder.name.is_empty() { name_default() } else { reminder.name.clone() };
let username = if reminder.username.as_ref().map(|s| s.is_empty()).unwrap_or(true) {
None
} else {
reminder.username
};
let new_uid = generate_uid(); let new_uid = generate_uid();
@ -507,7 +512,7 @@ pub async fn create_reminder(
name, name,
reminder.restartable, reminder.restartable,
reminder.tts, reminder.tts,
reminder.username, username,
reminder.utc_time, reminder.utc_time,
) )
.execute(pool) .execute(pool)

View File

@ -60,14 +60,15 @@ function update_select(sel) {
sel.closest("div.reminderContent").querySelector("img.discord-avatar").src = sel.closest("div.reminderContent").querySelector("img.discord-avatar").src =
sel.selectedOptions[0].dataset["webhookAvatar"]; sel.selectedOptions[0].dataset["webhookAvatar"];
} else { } else {
sel.closest("div.reminderContent").querySelector("img.discord-avatar").src = ""; sel.closest("div.reminderContent").querySelector("img.discord-avatar").src =
"/static/img/icon.png";
} }
if (sel.selectedOptions[0].dataset["webhookName"]) { if (sel.selectedOptions[0].dataset["webhookName"]) {
sel.closest("div.reminderContent").querySelector("input.discord-username").value = sel.closest("div.reminderContent").querySelector("input.discord-username").value =
sel.selectedOptions[0].dataset["webhookName"]; sel.selectedOptions[0].dataset["webhookName"];
} else { } else {
sel.closest("div.reminderContent").querySelector("input.discord-username").value = sel.closest("div.reminderContent").querySelector("input.discord-username").value =
""; "Reminder";
} }
} }
@ -723,6 +724,7 @@ $createReminderBtn.addEventListener("click", async () => {
let reminder = await serialize_reminder($createReminder, "create"); let reminder = await serialize_reminder($createReminder, "create");
if (reminder.error) { if (reminder.error) {
show_error(reminder.error); show_error(reminder.error);
$createReminderBtn.querySelector("span.icon > i").classList = ["fas fa-sparkles"];
return; return;
} }

View File

@ -191,19 +191,8 @@
</label> </label>
</div> </div>
</div> </div>
<div class="control">
<div class="field">
<label>
<input type="radio" class="default-width" name="exportSelect" value="reminder_templates">
Reminder templates
</label>
</div>
</div>
<br> <br>
<div class="has-text-centered"> <div class="has-text-centered">
<div style="color: red; font-weight: bold;">
By selecting "Import", you understand that this will overwrite existing data.
</div>
<div style="color: red"> <div style="color: red">
Please first read the <a href="/help/iemanager">support page</a> Please first read the <a href="/help/iemanager">support page</a>
</div> </div>

View File

@ -26,8 +26,7 @@
<div class="container"> <div class="container">
<p class="title">Import data</p> <p class="title">Import data</p>
<p class="content"> <p class="content">
You can import previous exports or modified exports. When importing a file, <strong>existing data You can import previous exports or modified exports. When importing a file, the new data will be added alongside existing data.
will be overwritten</strong>.
</p> </p>
</div> </div>
</div> </div>