Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GSoC] Use KTable in Facility -> Classes #12571

Merged
merged 20 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,4 @@ If you have contributed to Kolibri, feel free to add your name and Github accoun
| Mazen Oweiss | moweiss |
| Eshaan Aggarwal | EshaanAgg |
| Nikhil Sharma | ThEditor |
| - | BabyElias |
146 changes: 79 additions & 67 deletions kolibri/plugins/facility/assets/src/views/ManageClassPage/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,70 +35,50 @@
</KGridItem>
</KGrid>

<CoreTable
:dataLoading="dataLoading"
<KTable
:headers="tableHeaders"
:rows="tableRows"
:caption="$tr('tableCaption')"
:emptyMessage="$tr('noClassesExist')"
:dataLoading="dataLoading"
sortable
>
<caption class="visuallyhidden">
{{
$tr('tableCaption')
}}
</caption>
<template #headers>
<th>{{ coreString('classNameLabel') }}</th>
<th>{{ coreString('coachesLabel') }}</th>
<th>{{ coreString('learnersLabel') }}</th>
<th>
<span class="visuallyhidden">
{{ coreString('userActionsColumnHeader') }}
</span>
</th>
<template #header="{ header, colIndex }">
<span :class="{ visuallyhidden: colIndex === 3 }">{{ header.label }}</span>
</template>
<template #tbody>
<transition-group
tag="tbody"
name="list"
>
<tr
v-for="classroom in sortedClassrooms"
:key="classroom.id"
<template #cell="{ content, colIndex, row }">
<span v-if="colIndex === 0">
<KRouterLink
:text="content"
:to="$store.getters.facilityPageLinks.ClassEditPage(row[3].id)"
icon="classes"
/>
</span>
<span v-else-if="colIndex === 1">
<KOptionalText :text="coachNames(row[3]).length ? formattedCoachNames(row[3]) : ''" />
<KTooltip
v-if="formattedCoachNamesTooltip(row[3])"
:reference="`coachNames${row[3].id}`"
:refs="$refs"
>
<td>
<KRouterLink
:text="classroom.name"
:to="$store.getters.facilityPageLinks.ClassEditPage(classroom.id)"
icon="classes"
/>
</td>
<td>
<span :ref="`coachNames${classroom.id}`">
<KOptionalText
:text="coachNames(classroom).length ? formattedCoachNames(classroom) : ''"
/>
</span>
<KTooltip
v-if="formattedCoachNamesTooltip(classroom)"
:reference="`coachNames${classroom.id}`"
:refs="$refs"
>
{{ formattedCoachNamesTooltip(classroom) }}
</KTooltip>
</td>

<td>
{{ $formatNumber(classroom.learner_count) }}
</td>
<td class="core-table-button-col">
<KButton
appearance="flat-button"
:text="$tr('deleteClass')"
@click="selectClassToDelete(classroom)"
/>
</td>
</tr>
</transition-group>
{{ formattedCoachNamesTooltip(row[3]) }}
</KTooltip>
</span>
<span v-else-if="colIndex === 2">
{{ content }}
</span>
<span
v-else-if="colIndex === 3"
class="core-table-button-col"
>
<KButton
appearance="flat-button"
:text="$tr('deleteClass')"
@click="selectClassToDelete(row[3])"
/>
</span>
</template>
</CoreTable>
</KTable>

<ClassDeleteModal
v-if="Boolean(classToDelete)"
Expand All @@ -108,7 +88,7 @@
/>
<ClassCreateModal
v-if="modalShown === Modals.CREATE_CLASS"
:classes="sortedClassrooms"
:classes="classes"
@cancel="closeModal"
@success="handleCreateSuccess()"
/>
Expand All @@ -121,8 +101,6 @@
<script>

import { mapState, mapActions, mapGetters } from 'vuex';
import CoreTable from 'kolibri.coreVue.components.CoreTable';
import orderBy from 'lodash/orderBy';
import commonCoreStrings from 'kolibri.coreVue.mixins.commonCoreStrings';
import useUser from 'kolibri.coreVue.composables.useUser';
import { Modals } from '../../constants';
Expand All @@ -140,7 +118,6 @@
},
components: {
FacilityAppBarPage,
CoreTable,
ClassCreateModal,
ClassDeleteModal,
},
Expand All @@ -158,9 +135,43 @@
computed: {
...mapState('classManagement', ['modalShown', 'classes', 'dataLoading']),
...mapGetters(['facilityPageLinks']),

Modals: () => Modals,
sortedClassrooms() {
return orderBy(this.classes, [classroom => classroom.name.toUpperCase()], ['asc']);
tableHeaders() {
return [
{
label: this.coreString('classNameLabel'),
dataType: 'string',
minWidth: '150px',
width: '20%',
},
{
label: this.coreString('coachesLabel'),
dataType: 'undefined',
minWidth: '150px',
width: '30%',
},
{
label: this.coreString('learnersLabel'),
dataType: 'number',
minWidth: '150px',
width: '20%',
},
{
label: this.coreString('userActionsColumnHeader'),
dataType: 'undefined',
minWidth: '150px',
width: '30%',
},
];
},
tableRows() {
return this.classes.map(classroom => [
classroom.name,
this.formattedCoachNames(classroom),
this.$formatNumber(classroom.learner_count),
classroom,
]);
},
},
methods: {
Expand All @@ -183,12 +194,13 @@
}
},
// Duplicated in class-list-page
coachNames(classroom) {
const { coaches } = classroom;
coachNames(classes) {
const { coaches } = classes;
return coaches.map(({ full_name }) => full_name);
},
formattedCoachNames(classroom) {
const coach_names = this.coachNames(classroom);

if (coach_names.length === 1) {
return coach_names[0];
}
Expand Down
Loading