From 16622c7fe0a6d732e04b42ab37ec32f36f003f0f Mon Sep 17 00:00:00 2001 From: Dudrie Date: Thu, 23 Jan 2020 18:30:53 +0100 Subject: [PATCH 1/3] Change getNameOfEntity to have firstNameFirst as option. This makes lastNameFirst the default. --- client/src/components/forms/StudentForm.tsx | 4 +++- .../enter-form/EnterScheinexamPoints.tsx | 20 +++++++++++++------ .../overview/components/TeamCard.tsx | 2 +- .../TutorStudentmanagement.tsx | 2 +- .../Studentoverview.helpers.ts | 2 +- .../tutorialmanagement/TutorialManagement.tsx | 4 +--- .../TutorialSubstituteManagement.tsx | 2 +- .../modules/AttendancePDFModule.ts | 6 ++---- .../modules/CredentialsPDFModule.ts | 2 +- shared/src/util/helpers.ts | 17 +++++++++------- 10 files changed, 35 insertions(+), 26 deletions(-) diff --git a/client/src/components/forms/StudentForm.tsx b/client/src/components/forms/StudentForm.tsx index a705409db..704b56cef 100644 --- a/client/src/components/forms/StudentForm.tsx +++ b/client/src/components/forms/StudentForm.tsx @@ -200,7 +200,9 @@ function StudentForm({ for (const s of otherStudents) { if (s.matriculationNo && value === s.matriculationNo) { - return `Matrikelnummer wird bereits von ${getNameOfEntity(s)} verwendet.`; + return `Matrikelnummer wird bereits von ${getNameOfEntity(s, { + firstNameFirst: true, + })} verwendet.`; } } diff --git a/client/src/view/points-scheinexam/enter-form/EnterScheinexamPoints.tsx b/client/src/view/points-scheinexam/enter-form/EnterScheinexamPoints.tsx index 221f9a567..abf6050a8 100644 --- a/client/src/view/points-scheinexam/enter-form/EnterScheinexamPoints.tsx +++ b/client/src/view/points-scheinexam/enter-form/EnterScheinexamPoints.tsx @@ -116,13 +116,21 @@ function EnterScheinexamPoints(): JSX.Element { setStudent(updatedStudent); resetForm({ values: { ...values } }); - enqueueSnackbar(`Punkte für ${getNameOfEntity(student)} erfolgreich eingetragen.`, { - variant: 'success', - }); + enqueueSnackbar( + `Punkte für ${getNameOfEntity(student, { firstNameFirst: true })} erfolgreich eingetragen.`, + { + variant: 'success', + } + ); } catch { - enqueueSnackbar(`Punkte für ${getNameOfEntity(student)} konnten nicht eingetragen werden.`, { - variant: 'error', - }); + enqueueSnackbar( + `Punkte für ${getNameOfEntity(student, { + firstNameFirst: true, + })} konnten nicht eingetragen werden.`, + { + variant: 'error', + } + ); } }; diff --git a/client/src/view/points-sheet/overview/components/TeamCard.tsx b/client/src/view/points-sheet/overview/components/TeamCard.tsx index ddb41ec25..84ae7802e 100644 --- a/client/src/view/points-sheet/overview/components/TeamCard.tsx +++ b/client/src/view/points-sheet/overview/components/TeamCard.tsx @@ -64,7 +64,7 @@ function TeamCard({ const studentsInTeam: string = team.students.length > 0 - ? team.students.map(student => getNameOfEntity(student)).join(', ') + ? team.students.map(student => getNameOfEntity(student, { firstNameFirst: true })).join(', ') : 'Keine Studierende in diesem Team.'; const handleEnterStudents = () => { diff --git a/client/src/view/studentmanagement/TutorStudentmanagement.tsx b/client/src/view/studentmanagement/TutorStudentmanagement.tsx index a8b2743b8..c12ce6b55 100644 --- a/client/src/view/studentmanagement/TutorStudentmanagement.tsx +++ b/client/src/view/studentmanagement/TutorStudentmanagement.tsx @@ -47,7 +47,7 @@ export function getFilteredStudents( } return students.filter(s => { - const name = getNameOfEntity(s, { lastNameFirst: false }); + const name = getNameOfEntity(s, { firstNameFirst: true }); return unifyFilterableText(name).includes(unifyFilterableText(filterText)); }); diff --git a/client/src/view/studentmanagement/student-overview/Studentoverview.helpers.ts b/client/src/view/studentmanagement/student-overview/Studentoverview.helpers.ts index 1b1d6595c..452ef7f1a 100644 --- a/client/src/view/studentmanagement/student-overview/Studentoverview.helpers.ts +++ b/client/src/view/studentmanagement/student-overview/Studentoverview.helpers.ts @@ -39,7 +39,7 @@ export function getFilteredStudents( return true; } - const name = getNameOfEntity(s, { lastNameFirst: false }); + const name = getNameOfEntity(s); return unifyFilterableText(name).includes(unifyFilterableText(filterText)); }) diff --git a/client/src/view/tutorialmanagement/TutorialManagement.tsx b/client/src/view/tutorialmanagement/TutorialManagement.tsx index 827e2f93a..bb58b42c2 100644 --- a/client/src/view/tutorialmanagement/TutorialManagement.tsx +++ b/client/src/view/tutorialmanagement/TutorialManagement.tsx @@ -213,9 +213,7 @@ function TutorialManagement({ enqueueSnackbar }: WithSnackbarProps): JSX.Element return { date: new Date(date), - name: tutor - ? getNameOfEntity(tutor, { lastNameFirst: true }) - : 'TUTOR_NOT_FOUND', + name: tutor ? getNameOfEntity(tutor) : 'TUTOR_NOT_FOUND', }; }) .sort((a, b) => compareAsc(a.date, b.date))} diff --git a/client/src/view/tutorialmanagement/TutorialSubstituteManagement.tsx b/client/src/view/tutorialmanagement/TutorialSubstituteManagement.tsx index 0c1a64fe8..a6ef6a202 100644 --- a/client/src/view/tutorialmanagement/TutorialSubstituteManagement.tsx +++ b/client/src/view/tutorialmanagement/TutorialSubstituteManagement.tsx @@ -206,7 +206,7 @@ function TutorialSubstituteManagement({ match: { params } }: Props): JSX.Element emptyPlaceholder='Keine Tutoren vorhanden.' nameOfNoneItem='Keine Vertretung' items={tutors} - itemToString={tutor => getNameOfEntity(tutor, { lastNameFirst: true })} + itemToString={tutor => getNameOfEntity(tutor)} itemToValue={t => t.id} /> diff --git a/server/src/services/pdf-service/modules/AttendancePDFModule.ts b/server/src/services/pdf-service/modules/AttendancePDFModule.ts index 2074204a7..9d28d734a 100644 --- a/server/src/services/pdf-service/modules/AttendancePDFModule.ts +++ b/server/src/services/pdf-service/modules/AttendancePDFModule.ts @@ -44,12 +44,10 @@ export class AttendancePDFModule extends PDFModule { students.sort(sortByName); - const tutorName = getNameOfEntity(tutor, { lastNameFirst: true }); + const tutorName = getNameOfEntity(tutor); const tableRows: string[] = students.map( student => - `${getNameOfEntity(student, { - lastNameFirst: true, - })}` + `${getNameOfEntity(student)}` ); const body = this.replacePlaceholdersInTemplate({ diff --git a/server/src/services/pdf-service/modules/CredentialsPDFModule.ts b/server/src/services/pdf-service/modules/CredentialsPDFModule.ts index c5b85b036..e3036a168 100644 --- a/server/src/services/pdf-service/modules/CredentialsPDFModule.ts +++ b/server/src/services/pdf-service/modules/CredentialsPDFModule.ts @@ -21,7 +21,7 @@ export class CredentialsPDFModule extends PDFModule { public generatePDF({ users }: GeneratorOptions): Promise { const tableRows: string[] = users.map(user => { const tempPwd = user.temporaryPassword || 'NO TMP PASSWORD'; - const nameOfUser = getNameOfEntity(user, { lastNameFirst: true }); + const nameOfUser = getNameOfEntity(user); return `${nameOfUser}${user.username}${tempPwd}`; }); diff --git a/shared/src/util/helpers.ts b/shared/src/util/helpers.ts index 51a57ed96..006ac97ac 100644 --- a/shared/src/util/helpers.ts +++ b/shared/src/util/helpers.ts @@ -1,20 +1,23 @@ import { NamedElement } from '../model/Common'; interface NameOptions { - lastNameFirst: boolean; + firstNameFirst: boolean; } -export function getNameOfEntity(entity: NamedElement, options: Partial = {}): string { - if (options.lastNameFirst) { - return `${entity.lastname}, ${entity.firstname} `; - } else { +export function getNameOfEntity( + entity: NamedElement, + { firstNameFirst }: Partial = {} +): string { + if (firstNameFirst) { return `${entity.firstname} ${entity.lastname}`; + } else { + return `${entity.lastname}, ${entity.firstname} `; } } export function sortByName(a: NamedElement, b: NamedElement): number { - const nameOfA = getNameOfEntity(a, { lastNameFirst: true }); - const nameOfB = getNameOfEntity(b, { lastNameFirst: true }); + const nameOfA = getNameOfEntity(a); + const nameOfB = getNameOfEntity(b); return nameOfA.localeCompare(nameOfB); } From f498dde5c3e476e0b79a2d75f46e79ce9112e75c Mon Sep 17 00:00:00 2001 From: Dudrie Date: Thu, 23 Jan 2020 18:30:53 +0100 Subject: [PATCH 2/3] Change getNameOfEntity to have firstNameFirst as option. This makes lastNameFirst the default. --- client/src/components/forms/StudentForm.tsx | 4 +++- .../enter-form/EnterScheinexamPoints.tsx | 20 +++++++++++++------ .../overview/components/TeamCard.tsx | 2 +- .../TutorStudentmanagement.tsx | 2 +- .../Studentoverview.helpers.ts | 2 +- .../tutorialmanagement/TutorialManagement.tsx | 4 +--- .../TutorialSubstituteManagement.tsx | 2 +- .../modules/AttendancePDFModule.ts | 6 ++---- .../modules/CredentialsPDFModule.ts | 2 +- shared/src/util/helpers.ts | 17 +++++++++------- 10 files changed, 35 insertions(+), 26 deletions(-) diff --git a/client/src/components/forms/StudentForm.tsx b/client/src/components/forms/StudentForm.tsx index a705409db..704b56cef 100644 --- a/client/src/components/forms/StudentForm.tsx +++ b/client/src/components/forms/StudentForm.tsx @@ -200,7 +200,9 @@ function StudentForm({ for (const s of otherStudents) { if (s.matriculationNo && value === s.matriculationNo) { - return `Matrikelnummer wird bereits von ${getNameOfEntity(s)} verwendet.`; + return `Matrikelnummer wird bereits von ${getNameOfEntity(s, { + firstNameFirst: true, + })} verwendet.`; } } diff --git a/client/src/view/points-scheinexam/enter-form/EnterScheinexamPoints.tsx b/client/src/view/points-scheinexam/enter-form/EnterScheinexamPoints.tsx index 221f9a567..abf6050a8 100644 --- a/client/src/view/points-scheinexam/enter-form/EnterScheinexamPoints.tsx +++ b/client/src/view/points-scheinexam/enter-form/EnterScheinexamPoints.tsx @@ -116,13 +116,21 @@ function EnterScheinexamPoints(): JSX.Element { setStudent(updatedStudent); resetForm({ values: { ...values } }); - enqueueSnackbar(`Punkte für ${getNameOfEntity(student)} erfolgreich eingetragen.`, { - variant: 'success', - }); + enqueueSnackbar( + `Punkte für ${getNameOfEntity(student, { firstNameFirst: true })} erfolgreich eingetragen.`, + { + variant: 'success', + } + ); } catch { - enqueueSnackbar(`Punkte für ${getNameOfEntity(student)} konnten nicht eingetragen werden.`, { - variant: 'error', - }); + enqueueSnackbar( + `Punkte für ${getNameOfEntity(student, { + firstNameFirst: true, + })} konnten nicht eingetragen werden.`, + { + variant: 'error', + } + ); } }; diff --git a/client/src/view/points-sheet/overview/components/TeamCard.tsx b/client/src/view/points-sheet/overview/components/TeamCard.tsx index ddb41ec25..84ae7802e 100644 --- a/client/src/view/points-sheet/overview/components/TeamCard.tsx +++ b/client/src/view/points-sheet/overview/components/TeamCard.tsx @@ -64,7 +64,7 @@ function TeamCard({ const studentsInTeam: string = team.students.length > 0 - ? team.students.map(student => getNameOfEntity(student)).join(', ') + ? team.students.map(student => getNameOfEntity(student, { firstNameFirst: true })).join(', ') : 'Keine Studierende in diesem Team.'; const handleEnterStudents = () => { diff --git a/client/src/view/studentmanagement/TutorStudentmanagement.tsx b/client/src/view/studentmanagement/TutorStudentmanagement.tsx index a8b2743b8..c12ce6b55 100644 --- a/client/src/view/studentmanagement/TutorStudentmanagement.tsx +++ b/client/src/view/studentmanagement/TutorStudentmanagement.tsx @@ -47,7 +47,7 @@ export function getFilteredStudents( } return students.filter(s => { - const name = getNameOfEntity(s, { lastNameFirst: false }); + const name = getNameOfEntity(s, { firstNameFirst: true }); return unifyFilterableText(name).includes(unifyFilterableText(filterText)); }); diff --git a/client/src/view/studentmanagement/student-overview/Studentoverview.helpers.ts b/client/src/view/studentmanagement/student-overview/Studentoverview.helpers.ts index 1b1d6595c..452ef7f1a 100644 --- a/client/src/view/studentmanagement/student-overview/Studentoverview.helpers.ts +++ b/client/src/view/studentmanagement/student-overview/Studentoverview.helpers.ts @@ -39,7 +39,7 @@ export function getFilteredStudents( return true; } - const name = getNameOfEntity(s, { lastNameFirst: false }); + const name = getNameOfEntity(s); return unifyFilterableText(name).includes(unifyFilterableText(filterText)); }) diff --git a/client/src/view/tutorialmanagement/TutorialManagement.tsx b/client/src/view/tutorialmanagement/TutorialManagement.tsx index 827e2f93a..bb58b42c2 100644 --- a/client/src/view/tutorialmanagement/TutorialManagement.tsx +++ b/client/src/view/tutorialmanagement/TutorialManagement.tsx @@ -213,9 +213,7 @@ function TutorialManagement({ enqueueSnackbar }: WithSnackbarProps): JSX.Element return { date: new Date(date), - name: tutor - ? getNameOfEntity(tutor, { lastNameFirst: true }) - : 'TUTOR_NOT_FOUND', + name: tutor ? getNameOfEntity(tutor) : 'TUTOR_NOT_FOUND', }; }) .sort((a, b) => compareAsc(a.date, b.date))} diff --git a/client/src/view/tutorialmanagement/TutorialSubstituteManagement.tsx b/client/src/view/tutorialmanagement/TutorialSubstituteManagement.tsx index 0c1a64fe8..a6ef6a202 100644 --- a/client/src/view/tutorialmanagement/TutorialSubstituteManagement.tsx +++ b/client/src/view/tutorialmanagement/TutorialSubstituteManagement.tsx @@ -206,7 +206,7 @@ function TutorialSubstituteManagement({ match: { params } }: Props): JSX.Element emptyPlaceholder='Keine Tutoren vorhanden.' nameOfNoneItem='Keine Vertretung' items={tutors} - itemToString={tutor => getNameOfEntity(tutor, { lastNameFirst: true })} + itemToString={tutor => getNameOfEntity(tutor)} itemToValue={t => t.id} /> diff --git a/server/src/services/pdf-service/modules/AttendancePDFModule.ts b/server/src/services/pdf-service/modules/AttendancePDFModule.ts index 2074204a7..9d28d734a 100644 --- a/server/src/services/pdf-service/modules/AttendancePDFModule.ts +++ b/server/src/services/pdf-service/modules/AttendancePDFModule.ts @@ -44,12 +44,10 @@ export class AttendancePDFModule extends PDFModule { students.sort(sortByName); - const tutorName = getNameOfEntity(tutor, { lastNameFirst: true }); + const tutorName = getNameOfEntity(tutor); const tableRows: string[] = students.map( student => - `${getNameOfEntity(student, { - lastNameFirst: true, - })}` + `${getNameOfEntity(student)}` ); const body = this.replacePlaceholdersInTemplate({ diff --git a/server/src/services/pdf-service/modules/CredentialsPDFModule.ts b/server/src/services/pdf-service/modules/CredentialsPDFModule.ts index c5b85b036..e3036a168 100644 --- a/server/src/services/pdf-service/modules/CredentialsPDFModule.ts +++ b/server/src/services/pdf-service/modules/CredentialsPDFModule.ts @@ -21,7 +21,7 @@ export class CredentialsPDFModule extends PDFModule { public generatePDF({ users }: GeneratorOptions): Promise { const tableRows: string[] = users.map(user => { const tempPwd = user.temporaryPassword || 'NO TMP PASSWORD'; - const nameOfUser = getNameOfEntity(user, { lastNameFirst: true }); + const nameOfUser = getNameOfEntity(user); return `${nameOfUser}${user.username}${tempPwd}`; }); diff --git a/shared/src/util/helpers.ts b/shared/src/util/helpers.ts index 51a57ed96..006ac97ac 100644 --- a/shared/src/util/helpers.ts +++ b/shared/src/util/helpers.ts @@ -1,20 +1,23 @@ import { NamedElement } from '../model/Common'; interface NameOptions { - lastNameFirst: boolean; + firstNameFirst: boolean; } -export function getNameOfEntity(entity: NamedElement, options: Partial = {}): string { - if (options.lastNameFirst) { - return `${entity.lastname}, ${entity.firstname} `; - } else { +export function getNameOfEntity( + entity: NamedElement, + { firstNameFirst }: Partial = {} +): string { + if (firstNameFirst) { return `${entity.firstname} ${entity.lastname}`; + } else { + return `${entity.lastname}, ${entity.firstname} `; } } export function sortByName(a: NamedElement, b: NamedElement): number { - const nameOfA = getNameOfEntity(a, { lastNameFirst: true }); - const nameOfB = getNameOfEntity(b, { lastNameFirst: true }); + const nameOfA = getNameOfEntity(a); + const nameOfB = getNameOfEntity(b); return nameOfA.localeCompare(nameOfB); } From 22ca49abf36df845d08e12da7696eb2442e82477 Mon Sep 17 00:00:00 2001 From: Dudrie Date: Thu, 23 Jan 2020 19:23:10 +0100 Subject: [PATCH 3/3] Run prettier. --- server/src/services/pdf-service/modules/AttendancePDFModule.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/server/src/services/pdf-service/modules/AttendancePDFModule.ts b/server/src/services/pdf-service/modules/AttendancePDFModule.ts index 9d28d734a..2d80a59c9 100644 --- a/server/src/services/pdf-service/modules/AttendancePDFModule.ts +++ b/server/src/services/pdf-service/modules/AttendancePDFModule.ts @@ -46,8 +46,7 @@ export class AttendancePDFModule extends PDFModule { const tutorName = getNameOfEntity(tutor); const tableRows: string[] = students.map( - student => - `${getNameOfEntity(student)}` + student => `${getNameOfEntity(student)}` ); const body = this.replacePlaceholdersInTemplate({