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);
if let Some(username) = &reminder.username {
if !username.is_empty() {
w.username(username);
}
}
if let Some(avatar) = &reminder.avatar {
w.avatar_url(avatar);

View File

@ -172,7 +172,7 @@ pub async fn import_reminders(
create_reminder(
ctx.inner(),
pool.inner(),
transaction,
GuildId(id),
UserId(user_id),
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!(
"INSERT INTO todos (value, channel_id, guild_id) VALUES {}",
vec![query_placeholder].repeat(query_params.len()).join(",")

View File

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

View File

@ -60,14 +60,15 @@ function update_select(sel) {
sel.closest("div.reminderContent").querySelector("img.discord-avatar").src =
sel.selectedOptions[0].dataset["webhookAvatar"];
} 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"]) {
sel.closest("div.reminderContent").querySelector("input.discord-username").value =
sel.selectedOptions[0].dataset["webhookName"];
} else {
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");
if (reminder.error) {
show_error(reminder.error);
$createReminderBtn.querySelector("span.icon > i").classList = ["fas fa-sparkles"];
return;
}

View File

@ -191,19 +191,8 @@
</label>
</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>
<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">
Please first read the <a href="/help/iemanager">support page</a>
</div>

View File

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