diff --git a/frontend/pages/settings/admin/ledenlijst.vue b/frontend/pages/settings/admin/ledenlijst.vue index 81403c7..12224e1 100644 --- a/frontend/pages/settings/admin/ledenlijst.vue +++ b/frontend/pages/settings/admin/ledenlijst.vue @@ -36,114 +36,88 @@ const disableButtons = ref(false) const searchTerm = ref('') onMounted(async () => { - if (!ledenlijst.value.length) { - try { - const querySnapshot = await getDocs(collection(db, "ledenlijst")); - querySnapshot.forEach((doc) => { - ledenlijst.value.push(doc.data()) - }); - } catch (e) { - console.log(e) - } - - ledenlijst.value.sort((a, b) => a.fullName.localeCompare(b.fullName)) + if (!ledenlijst.value.length) { + try { + const querySnapshot = await getDocs(collection(db, "ledenlijst")); + querySnapshot.forEach((doc) => { + ledenlijst.value.push(doc.data()) + }); + } catch (e) { + console.log(e) } + + ledenlijst.value.sort((a, b) => a.fullName.localeCompare(b.fullName)) + } }) const filteredLedenlijst = computed(() => { - return ledenlijst.value.filter(lid => lid.fullName.toLowerCase().includes(searchTerm.value.toLowerCase())) + return ledenlijst.value.filter(lid => lid.fullName.toLowerCase().includes(searchTerm.value.toLowerCase())) }) const handleFileChanged = (event) => { - const target = event.target; + const target = event.target; - if (target && target.files) { - file.value = target.files[0]; - } + if (target && target.files) { + file.value = target.files[0]; + } } const submitLedenlijst = () => { - disableButtons.value = true + disableButtons.value = true - let reader = new FileReader() + let reader = new FileReader() - reader.onload = function() { - csvToJson(reader.result); - }; + reader.onload = function() { + csvToJson(reader.result); + }; - reader.onerror = function() { - console.log(reader.error); - }; + reader.onerror = function() { + console.log(reader.error); + }; - reader.readAsText(file.value) + reader.readAsText(file.value) } const csvToJson = (csv) => { - let arr = csv.split('\n'); + let arr = csv.split('\n'); - var result = []; - var headers = arr[0].split(';'); - for(var i = 1; i < arr.length; i++) { - var data = arr[i].split(';'); - var obj = {}; - for(var j = 0; j < data.length; j++) { - obj[headers[j].trim()] = data[j].trim(); - } - result.push(obj); + var result = []; + var headers = arr[0].split(';'); + for(var i = 1; i < arr.length; i++) { + var data = arr[i].split(';'); + var obj = {}; + for(var j = 0; j < data.length; j++) { + obj[headers[j].trim()] = data[j].trim(); } + result.push(obj); + } - /* - let array = csv.split("\n") - let result = []; + if (!Object.hasOwn(result[0], 'Relatiecode') || !Object.hasOwn(result[0], 'Volledige naam (1)') || !Object.hasOwn(result[0], 'E-mail') || !Object.hasOwn(result[0], '2e E-mail') || !Object.hasOwn(result[0], 'Verenigingssporten') || !Object.hasOwn(result[0], 'Diploma dropdown 1')) return toast.error('Missing properties') - let headers = array[0].split(",") + ledenlijst.value = [] - for (let i = 1; i < array.length - 1; i++) { - let obj = {} + for (let i in result) { + let groups = [] + let correctGroups = null + if (result[i].Verenigingssporten.includes(',')) correctGroups = result[i].Verenigingssporten.split(',') + else correctGroups = [result[i].Verenigingssporten] - let str = array[i] - let s = '' + correctGroups.forEach(group => { + const x = group.split(' - ') + + if (x[2] === 'Week') groups.push('Vrijdag') + else if (x[2] === 'Zaterdag' && x[1] !== 'Wedstrijd') groups.push('Zaterdag') + + groups.push(x[1]) + }) + + if (groups[2] === 'Week') groups[2] = 'Vrijdag' - let flag = 0 - for (let ch of str) { - if (ch === '"' && flag === 0) { - flag = 1 - } - else if (ch === '"' && flag == 1) flag = 0 - if (ch === ',' && flag === 0) ch = '|' - if (ch !== '"') s += ch - } - - let properties = s.split("|") - - for (let j in headers) { - if (properties[j].includes(",")) { - obj[headers[j]] = properties[j] - .split(",").map(item => item.trim()) - } - else obj[headers[j]] = properties[j] - } - result.push(obj) - } - */ - if (!Object.hasOwn(result[0], 'Relatiecode') || !Object.hasOwn(result[0], 'Volledige naam (1)') || !Object.hasOwn(result[0], 'E-mail') || !Object.hasOwn(result[0], '2e E-mail') || !Object.hasOwn(result[0], 'Verenigingssporten') || !Object.hasOwn(result[0], 'Diploma dropdown 1')) return toast.error('Missing properties') + groups = groups.filter((item) => item !== "Groep") - ledenlijst.value = [] - - for (let i in result) { - let groups = [] - const correctGroups = result[i].Verenigingssporten.replace(/,/g, " -") - - console.log(correctGroups) - groups = correctGroups.split(' - ') - if (groups[2] === 'Week') groups[2] = 'Vrijdag' - - groups = groups.filter((item) => item !== "Groep") - - ledenlijst.value.push({ relatiecode: result[i].Relatiecode, fullName: result[i]['Volledige naam (1)'], email: [result[i]['E-mail'], result[i]['2e E-mail']], groups: [...new Set(groups)], diploma: result[i]['Diploma dropdown 1'] }) - } - - uploadLedenlijst() + ledenlijst.value.push({ relatiecode: result[i].Relatiecode, fullName: result[i]['Volledige naam (1)'], email: [result[i]['E-mail'], result[i]['2e E-mail']], groups: [...new Set(groups)], diploma: result[i]['Diploma dropdown 1'] }) + } + uploadLedenlijst() } const uploadLedenlijst = async () => {