Skip to content

Commit

Permalink
Merge pull request #229 from Dudrie/issue-223-Fix_names_being_display…
Browse files Browse the repository at this point in the history
…ed_firstname_lastname_instead_of_lastname_firstname

Fix names being displayed "firstname lastname" instead of "lastname, firstname"
  • Loading branch information
Dudrie authored Jan 23, 2020
2 parents ece705b + 22ca49a commit ef83d25
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 27 deletions.
4 changes: 3 additions & 1 deletion client/src/components/forms/StudentForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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.`;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}
);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
})
Expand Down
4 changes: 1 addition & 3 deletions client/src/view/tutorialmanagement/TutorialManagement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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))}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
/>
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,9 @@ export class AttendancePDFModule extends PDFModule<GeneratorOptions> {

students.sort(sortByName);

const tutorName = getNameOfEntity(tutor, { lastNameFirst: true });
const tutorName = getNameOfEntity(tutor);
const tableRows: string[] = students.map(
student =>
`<tr><td>${getNameOfEntity(student, {
lastNameFirst: true,
})}</td><td width="50%"></td></tr>`
student => `<tr><td>${getNameOfEntity(student)}</td><td width="50%"></td></tr>`
);

const body = this.replacePlaceholdersInTemplate({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class CredentialsPDFModule extends PDFModule<GeneratorOptions> {
public generatePDF({ users }: GeneratorOptions): Promise<Buffer> {
const tableRows: string[] = users.map(user => {
const tempPwd = user.temporaryPassword || 'NO TMP PASSWORD';
const nameOfUser = getNameOfEntity(user, { lastNameFirst: true });
const nameOfUser = getNameOfEntity(user);

return `<tr><td>${nameOfUser}</td><td>${user.username}</td><td>${tempPwd}</td></tr>`;
});
Expand Down
17 changes: 10 additions & 7 deletions shared/src/util/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
import { NamedElement } from '../model/Common';

interface NameOptions {
lastNameFirst: boolean;
firstNameFirst: boolean;
}

export function getNameOfEntity(entity: NamedElement, options: Partial<NameOptions> = {}): string {
if (options.lastNameFirst) {
return `${entity.lastname}, ${entity.firstname} `;
} else {
export function getNameOfEntity(
entity: NamedElement,
{ firstNameFirst }: Partial<NameOptions> = {}
): 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);
}

0 comments on commit ef83d25

Please sign in to comment.