Skip to content

Commit

Permalink
Changed data import to add alongside rather than removing.
Browse files Browse the repository at this point in the history
  • Loading branch information
JellyWX committed Mar 24, 2023
1 parent 4e0163f commit 314c72e
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 26 deletions.
4 changes: 3 additions & 1 deletion postman/src/sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,9 @@ WHERE
w.content(&reminder.content).tts(reminder.tts);

if let Some(username) = &reminder.username {
w.username(username);
if !username.is_empty() {
w.username(username);
}
}

if let Some(avatar) = &reminder.avatar {
Expand Down
9 changes: 1 addition & 8 deletions web/src/routes/dashboard/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ pub async fn import_reminders(

create_reminder(
ctx.inner(),
pool.inner(),
transaction,
GuildId(id),
UserId(user_id),
reminder,
Expand Down Expand Up @@ -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(",")
Expand Down
9 changes: 7 additions & 2 deletions web/src/routes/dashboard/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -507,7 +512,7 @@ pub async fn create_reminder(
name,
reminder.restartable,
reminder.tts,
reminder.username,
username,
reminder.utc_time,
)
.execute(pool)
Expand Down
6 changes: 4 additions & 2 deletions web/static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
}

Expand Down Expand Up @@ -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;
}

Expand Down
11 changes: 0 additions & 11 deletions web/templates/dashboard.html.tera
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
3 changes: 1 addition & 2 deletions web/templates/support/iemanager.html.tera
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit 314c72e

Please sign in to comment.