Skip to content

Commit

Permalink
Merge branch 'SPSH-1533' of https://github.com/dBildungsplattform/sch…
Browse files Browse the repository at this point in the history
…ulportal-client into SPSH-1533
  • Loading branch information
AlexanderUngefug committed Nov 29, 2024
2 parents 74e85c1 + 2d98647 commit 713c0b1
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 40 deletions.
2 changes: 1 addition & 1 deletion src/components/admin/klassen/KlasseChange.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,6 @@ describe('KlasseChange', () => {
await klassenAutocomplete?.setValue(undefined);
await nextTick();

expect(organisationStore.getKlassenByOrganisationId).toHaveBeenCalledWith('1');
expect(organisationStore.getKlassenByOrganisationId).toHaveBeenCalledWith('1', { limit: 25 });
});
});
6 changes: 3 additions & 3 deletions src/components/admin/klassen/KlasseChange.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
watch(selectedNewKlasse, (newValue: string | undefined) => {
if (!selectedNewKlasse.value) {
organisationStore.getKlassenByOrganisationId(selectedSchule.value as string);
organisationStore.getKlassenByOrganisationId(selectedSchule.value as string, { limit: 25 });
}
selectedNewKlasse.value = newValue;
});
Expand All @@ -46,14 +46,14 @@
}
if (searchValue === '' && !selectedNewKlasse.value) {
timerId.value = setTimeout(() => {
organisationStore.getKlassenByOrganisationId(organisationId, { searchString: searchValue });
organisationStore.getKlassenByOrganisationId(organisationId, { searchString: searchValue, limit: 25 });
}, 500);
} else if (searchValue && searchValue !== selectedKlasseTitle.value) {
/* cancel pending call */
clearTimeout(timerId.value);
/* delay new call 500ms */
timerId.value = setTimeout(() => {
organisationStore.getKlassenByOrganisationId(organisationId, { searchString: searchValue });
organisationStore.getKlassenByOrganisationId(organisationId, { searchString: searchValue, limit: 25 });
}, 500);
}
}
Expand Down
20 changes: 11 additions & 9 deletions src/components/admin/personen/PersonenkontextCreate.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,17 @@ beforeEach(() => {
};

personStore.personenuebersicht = mockPersonenuebersicht;
organisationStore.klassen = [
{
id: '2',
name: '11b',
kennung: '9356494-11b',
namensergaenzung: 'Klasse',
kuerzel: '11b',
typ: OrganisationsTyp.Klasse,
administriertVon: '1',
},
];
});

describe('PersonenkontextCreate', () => {
Expand Down Expand Up @@ -423,13 +434,4 @@ describe('PersonenkontextCreate', () => {

expect(klassenAutocomplete?.text()).toBeFalsy();
});

test('Preselect the Klasse if the existing Zuordnungen have a Klasse', async () => {
const organisationAutocomplete: VueWrapper | undefined = wrapper?.findComponent({ ref: 'organisation-select' });
await organisationAutocomplete?.setValue('01');
await nextTick();

// Verify that the klasse ID is emitted
expect(wrapper?.emitted('update:selectedKlasse')).toBeTruthy();
});
});
25 changes: 17 additions & 8 deletions src/components/admin/personen/PersonenkontextCreate.vue
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@
limit: 25,
});
// Fetch all classes for the selected organization without any filter
await organisationStore.getKlassenByOrganisationId(newValue);
// Fetch all Klassen for the selected organization
await organisationStore.getKlassenByOrganisationId(newValue, { limit: 25 });
// Check for Klasse preselection
// Check that all the Klassen associated with the selectedOrga have the same Klasse for the same person.
const klassenZuordnungen: Zuordnung[] | undefined = personStore.personenuebersicht?.zuordnungen.filter(
(zuordnung: Zuordnung) => zuordnung.typ === OrganisationsTyp.Klasse && zuordnung.administriertVon === newValue,
);
Expand All @@ -109,12 +109,21 @@
);
if (sameSSK) {
await organisationStore.getKlassenByOrganisationId(newValue);
const klasse: Organisation | undefined = organisationStore.klassen.find(
(k: Organisation) => k.id === klassenZuordnungen[0]?.sskId,
);
selectedKlasse.value = klasse?.id;
emits('update:selectedKlasse', klasse?.id);
// If the klasse was found then add it to the 25 Klassen in the dropdown and preselect it
if (klasse) {
selectedKlasse.value = klasse.id;
emits('update:selectedKlasse', newValue);
// Another request to limit the Klassen because beforehand we made the same request with no limit to check all possible Klassen
await organisationStore.getKlassenByOrganisationId(newValue, { limit: 25 });
// Push the preselected Klasse to the array of klassen (dropdown) if its not there already (this is necessary if the Klasse isn't part of the initial 25)
if (!organisationStore.klassen.some((k: Organisation) => k.id === klasse.id)) {
organisationStore.klassen.push(klasse);
}
}
}
}
// Reset the selectedRolle field only if oldValue was not undefined
Expand Down Expand Up @@ -231,14 +240,14 @@
}
if (searchValue === '' && !selectedKlasse.value) {
timerId.value = setTimeout(() => {
organisationStore.getKlassenByOrganisationId(organisationId, { searchString: searchValue });
organisationStore.getKlassenByOrganisationId(organisationId, { searchString: searchValue, limit: 25 });
}, 500);
} else if (searchValue && searchValue !== selectedKlasseTitle.value) {
/* cancel pending call */
clearTimeout(timerId.value);
/* delay new call 500ms */
timerId.value = setTimeout(() => {
organisationStore.getKlassenByOrganisationId(organisationId, { searchString: searchValue });
organisationStore.getKlassenByOrganisationId(organisationId, { searchString: searchValue, limit: 25 });
}, 500);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/composables/useKlassen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function useKlassen(): ComputedRef<TranslatedObject[]> {
const organisationStore: OrganisationStore = useOrganisationStore();

return computed(() => {
return organisationStore.klassen.slice(0, 25).map((org: Organisation) => ({
return organisationStore.klassen.map((org: Organisation) => ({
value: org.id,
title: org.name,
}));
Expand Down
6 changes: 2 additions & 4 deletions src/stores/OrganisationStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,10 +347,8 @@ export const useOrganisationStore: StoreDefinition<
undefined,
[organisationId],
);
const getFilteredKlassen: Organisation[] = response.data.filter(
(orga: Organisation) => orga.typ === OrganisationsTyp.Klasse,
);
this.klassen = getFilteredKlassen;

this.klassen = response.data;
this.totalKlassen = +response.headers['x-paging-total'];
this.totalPaginatedKlassen = +response.headers['x-paging-pageTotal'];
await this.fetchSchuleDetailsForKlassen(true);
Expand Down
6 changes: 3 additions & 3 deletions src/views/admin/KlassenManagementView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@
includeTyp: OrganisationsTyp.Klasse,
systemrechte: ['KLASSEN_VERWALTEN'],
});
} else if (searchValue === '' && selectedSchule.value !== null) {
} else if (searchValue === '' && selectedSchule.value !== null && selectedKlassen.value.length === 0) {
// Fetch all Klassen for the selected Schule when the search string is cleared
await organisationStore.getAllOrganisationen({
searchString: searchValue,
Expand All @@ -262,7 +262,7 @@
includeTyp: OrganisationsTyp.Klasse,
systemrechte: ['KLASSEN_VERWALTEN'],
});
}
}
}
// Checks if the filter is active or not
Expand All @@ -286,7 +286,7 @@
// If the user has an autoselected Schule, do not reset it
if (hasAutoselectedSchule.value && selectedSchule.value !== null) {
// Fetch all Klassen for the selected Schule
organisationStore.getKlassenByOrganisationId(selectedSchule.value);
organisationStore.getKlassenByOrganisationId(selectedSchule.value, { limit: 25 });
organisationStore.allKlassen = organisationStore.klassen;
} else {
// Clear search input for Schulen
Expand Down
30 changes: 19 additions & 11 deletions src/views/admin/PersonDetailsView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -325,18 +325,21 @@
klassenZuordnungen?.forEach((klasseZuordnung: Zuordnung) => {
const schuleId: string = klasseZuordnung.administriertVon;
if (!schuleToKlasseMap.has(schuleId)) {
schuleToKlasseMap.set(schuleId, []);
const klasse: string = klasseZuordnung.sskName;
const rolle: string = klasseZuordnung.rolle;
if (!schuleToKlasseMap.has(schuleId + klasse + rolle)) {
schuleToKlasseMap.set(schuleId + klasse + rolle, []);
}
schuleToKlasseMap.get(schuleId)?.push(klasseZuordnung);
schuleToKlasseMap.get(schuleId + klasse + rolle)?.push(klasseZuordnung);
});
// Find Klassen that should be kept
const klassenToKeep: Zuordnung[] = [];
// For each remaining Zuordnung that is a Schule, keep its associated Klassen
remainingZuordnungen?.forEach((zuordnung: Zuordnung) => {
const associatedKlassen: Zuordnung[] = schuleToKlasseMap.get(zuordnung.sskId) || [];
const associatedKlassen: Zuordnung[] =
schuleToKlasseMap.get(zuordnung.sskId + zuordnung.klasse + zuordnung.rolle) || [];
klassenToKeep.push(...associatedKlassen);
});
Expand All @@ -345,7 +348,7 @@
// Update the personenkontexte with the filtered list
await personenkontextStore.updatePersonenkontexte(combinedZuordnungen, currentPersonId);
zuordnungenResult.value = combinedZuordnungen;
zuordnungenResult.value = remainingZuordnungen;
selectedZuordnungen.value = [];
// Filter out Zuordnungen with editable === false
Expand Down Expand Up @@ -691,10 +694,12 @@
administriertVon: [selectedZuordnungen.value[0]?.sskId],
includeTyp: OrganisationsTyp.Klasse,
systemrechte: ['KLASSEN_VERWALTEN'],
limit: 25
});
await organisationStore.getKlassenByOrganisationId(selectedZuordnungen.value[0]?.sskId, {
searchString: selectedZuordnungen.value[0].klasse,
limit: 25,
});
// Combine arrays and remove duplicates based on id
Expand Down Expand Up @@ -1000,18 +1005,21 @@
klassenZuordnungen?.forEach((klasseZuordnung: Zuordnung) => {
const schuleId: string = klasseZuordnung.administriertVon;
if (!schuleToKlasseMap.has(schuleId)) {
schuleToKlasseMap.set(schuleId, []);
const klasse: string = klasseZuordnung.sskName;
const rolle: string = klasseZuordnung.rolleId;
if (!schuleToKlasseMap.has(schuleId + klasse + rolle)) {
schuleToKlasseMap.set(schuleId + klasse + rolle, []);
}
schuleToKlasseMap.get(schuleId)?.push(klasseZuordnung);
schuleToKlasseMap.get(schuleId + klasse + rolle)?.push(klasseZuordnung);
});
// Find Klassen that should be kept
const klassenToKeep: Zuordnung[] = [];
// For each remaining Zuordnung that is a Schule, keep its associated Klassen
remainingZuordnungen?.forEach((zuordnung: Zuordnung) => {
const associatedKlassen: Zuordnung[] = schuleToKlasseMap.get(zuordnung.sskId) || [];
const associatedKlassen: Zuordnung[] =
schuleToKlasseMap.get(zuordnung.sskId + zuordnung.klasse + zuordnung.rolleId) || [];
klassenToKeep.push(...associatedKlassen);
});
Expand Down Expand Up @@ -2651,9 +2659,9 @@
>
<v-card-text>
<v-container>
<v-row class="text-body bold px-md-16">
<v-row class="text-body bold justify-center">
<v-col
offset="1"
class="text-center"
cols="10"
>
<span>{{ createZuordnungConfirmationDialogMessage }}</span>
Expand Down

0 comments on commit 713c0b1

Please sign in to comment.