fixed group system

This commit is contained in:
xeovalyte 2023-01-26 11:34:52 +01:00
parent eb8a80ce67
commit 91eee81084

View File

@ -36,114 +36,88 @@ const disableButtons = ref(false)
const searchTerm = ref('') const searchTerm = ref('')
onMounted(async () => { onMounted(async () => {
if (!ledenlijst.value.length) { if (!ledenlijst.value.length) {
try { try {
const querySnapshot = await getDocs(collection(db, "ledenlijst")); const querySnapshot = await getDocs(collection(db, "ledenlijst"));
querySnapshot.forEach((doc) => { querySnapshot.forEach((doc) => {
ledenlijst.value.push(doc.data()) ledenlijst.value.push(doc.data())
}); });
} catch (e) { } catch (e) {
console.log(e) console.log(e)
}
ledenlijst.value.sort((a, b) => a.fullName.localeCompare(b.fullName))
} }
ledenlijst.value.sort((a, b) => a.fullName.localeCompare(b.fullName))
}
}) })
const filteredLedenlijst = computed(() => { 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 handleFileChanged = (event) => {
const target = event.target; const target = event.target;
if (target && target.files) { if (target && target.files) {
file.value = target.files[0]; file.value = target.files[0];
} }
} }
const submitLedenlijst = () => { const submitLedenlijst = () => {
disableButtons.value = true disableButtons.value = true
let reader = new FileReader() let reader = new FileReader()
reader.onload = function() { reader.onload = function() {
csvToJson(reader.result); csvToJson(reader.result);
}; };
reader.onerror = function() { reader.onerror = function() {
console.log(reader.error); console.log(reader.error);
}; };
reader.readAsText(file.value) reader.readAsText(file.value)
} }
const csvToJson = (csv) => { const csvToJson = (csv) => {
let arr = csv.split('\n'); let arr = csv.split('\n');
var result = []; var result = [];
var headers = arr[0].split(';'); var headers = arr[0].split(';');
for(var i = 1; i < arr.length; i++) { for(var i = 1; i < arr.length; i++) {
var data = arr[i].split(';'); var data = arr[i].split(';');
var obj = {}; var obj = {};
for(var j = 0; j < data.length; j++) { for(var j = 0; j < data.length; j++) {
obj[headers[j].trim()] = data[j].trim(); obj[headers[j].trim()] = data[j].trim();
}
result.push(obj);
} }
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')
let array = csv.split("\n")
let result = [];
let headers = array[0].split(",") ledenlijst.value = []
for (let i = 1; i < array.length - 1; i++) { for (let i in result) {
let obj = {} let groups = []
let correctGroups = null
if (result[i].Verenigingssporten.includes(',')) correctGroups = result[i].Verenigingssporten.split(',')
else correctGroups = [result[i].Verenigingssporten]
let str = array[i] correctGroups.forEach(group => {
let s = '' 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 groups = groups.filter((item) => item !== "Groep")
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')
ledenlijst.value = [] 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'] })
}
for (let i in result) { uploadLedenlijst()
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()
} }
const uploadLedenlijst = async () => { const uploadLedenlijst = async () => {