From 8753ad2906c8e5435169e19a8b77fab3206d5c1d Mon Sep 17 00:00:00 2001 From: Lapor Chen <31620109+laporchen@users.noreply.github.com> Date: Wed, 18 Sep 2024 11:43:28 +0800 Subject: [PATCH] feat: add toggle for standardizeUsername --- src/i18n/en.json | 3 ++- src/i18n/zh-tw.json | 3 ++- src/pages/course/[name]/members.vue | 16 ++++++++++++++-- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/i18n/en.json b/src/i18n/en.json index 0e6e3ca..2b636a0 100644 --- a/src/i18n/en.json +++ b/src/i18n/en.json @@ -160,7 +160,8 @@ "content": "From the second row, fill each member's data in each row", "caution": "Note that if we find a user with the same username or email in the database, the user will still be added into course, BUT other information will not be update UNLESS you check the checkbox below." }, - "forceUpdate": "Force update existing users' data" + "forceUpdate": "Force update existing users' data", + "standardizeUsername": "Standardize Username (uppercase)" } }, "courses": { diff --git a/src/i18n/zh-tw.json b/src/i18n/zh-tw.json index fc7cf60..9c58ef8 100644 --- a/src/i18n/zh-tw.json +++ b/src/i18n/zh-tw.json @@ -160,7 +160,8 @@ "content": "第二列開始每列為一個成員的資料", "caution": "請注意若系統已有使用者使用了 CSV 中的 username 或 email,則該學生依舊會被加入課程,但其他欄位的資訊不會更新, 若要強制更新他的資訊請勾選下方的選項。" }, - "forceUpdate": "強制更新已存在的使用者的資訊" + "forceUpdate": "強制更新已存在的使用者的資訊", + "standardizeUsername": "統一使用者名稱(字母大寫)" } }, "courses": { diff --git a/src/pages/course/[name]/members.vue b/src/pages/course/[name]/members.vue index 19cf961..a589805 100644 --- a/src/pages/course/[name]/members.vue +++ b/src/pages/course/[name]/members.vue @@ -43,6 +43,7 @@ const rolesCanCreateCourse = [UserRole.Admin, UserRole.Teacher]; const isOpen = ref(false); const newMembers = ref(); +const shouldStandardizeUsername = ref(true); const newMembersCSVString = ref(""); const forceUpdate = ref(false); const isProcessingSignup = ref(false); @@ -72,7 +73,7 @@ watch(newMembers, () => { const reader = new FileReader(); reader.onload = (evt) => { if (typeof evt.target?.result !== "string") return; - newMembersCSVString.value = standardizeUsername(evt.target?.result || ""); + newMembersCSVString.value = evt.target?.result; const rows = newMembersCSVString.value.split("\n"); previewCSV.value.headers = rows[0].split(","); @@ -83,9 +84,13 @@ watch(newMembers, () => { async function submit() { if (!newMembersCSVString.value) return; isProcessingSignup.value = true; + const csv = shouldStandardizeUsername.value + ? standardizeUsername(newMembersCSVString.value) + : newMembersCSVString.value; + try { await api.Auth.batchSignup({ - newUsers: newMembersCSVString.value, + newUsers: csv, force: forceUpdate.value, course: route.params.name as string, }); @@ -180,6 +185,13 @@ async function submit() {
+
+ +
+