Skip to content

Commit

Permalink
filterUniqueContacts was moved to course-import.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
barisgul15 committed Nov 20, 2023
1 parent a1a925f commit f4d61fe
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 20 deletions.
21 changes: 1 addition & 20 deletions web/template/admin/admin_tabs/course-import.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -76,26 +76,7 @@
</label>
<table>
<tbody>
<script>
/*
The data coming from TUMonline sometimes duplicates contacts of some courses.
course.contacts has 5 attributes:
first_name, last_name, email, main_contact, role.
All cases considered, the most distinctive among them is e-mail.
and that's why duplicates are eliminated accordingly.
*/
function filterUniqueContacts(contacts) {
const uniqueEmails = new Set();
return contacts.filter(contact => {
if (!uniqueEmails.has(contact.email)) {
uniqueEmails.add(contact.email);
return true;
}
return false;
});
}
</script>
<template x-for="contact in filterUniqueContacts(course.contacts)">
<template x-for="contact in admin.filterUniqueContacts(course.contacts)">
<tr class="pl-3" :class="contact.main_contact ? 'text-green-400' : 'text-3'">
<td class="px-2">
<label>
Expand Down
15 changes: 15 additions & 0 deletions web/ts/course-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,18 @@ export function addNotifyEventListeners() {
window.location.replace("/");
});
}


//The data coming from TUMonline sometimes duplicates contacts of some courses. course.contacts has 5 attributes:
//first_name, last_name, email, main_contact, role.
//All cases considered, the most distinctive among them is e-mail and duplicates are eliminated accordingly.
export function filterUniqueContacts(contacts: any[]) {
const uniqueEmails = new Set();
return contacts.filter(contact => {
if (!uniqueEmails.has(contact.email)) {
uniqueEmails.add(contact.email);
return true;
}
return false;
});
}

0 comments on commit f4d61fe

Please sign in to comment.