Skip to content

Commit

Permalink
Merge pull request #11224 from thanksameeelian/update_coach_routing
Browse files Browse the repository at this point in the history
update coach routing
  • Loading branch information
rtibbles authored Sep 14, 2023
2 parents b6cbe81 + 74d5725 commit 9a4b49b
Show file tree
Hide file tree
Showing 12 changed files with 84 additions and 31 deletions.
3 changes: 2 additions & 1 deletion kolibri/plugins/coach/assets/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ class CoachToolsModule extends KolibriApp {
to.name
)
) {
promises.push(this.store.dispatch('initClassInfo', to.params.classId));
if (to.params.classId)
promises.push(this.store.dispatch('initClassInfo', to.params.classId));
} else {
this.store.dispatch('coachNotifications/stopPolling');
}
Expand Down
8 changes: 4 additions & 4 deletions kolibri/plugins/coach/assets/src/routes/baseRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ export default {
},
classHome: {
name: PageNames.HOME_PAGE,
path: '/:classId/home',
path: '/:classId?/home',
},
plan: {
name: PageNames.PLAN_PAGE,
path: '/:classId/plan',
redirect: '/:classId/plan/lessons',
path: '/:classId?/plan',
redirect: '/:classId?/plan/lessons',
},
reports: {
name: PageNames.REPORTS_PAGE,
path: '/:classId/reports',
path: '/:classId?/reports',
},
};
24 changes: 15 additions & 9 deletions kolibri/plugins/coach/assets/src/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,37 @@ import { ClassesPageNames } from '../../../../learn/assets/src/constants';
import { PageNames } from '../constants';
import reportRoutes from './reportRoutes';
import planRoutes from './planRoutes';
import { classIdParamRequiredGuard } from './utils';

export default [
...planRoutes,
...reportRoutes,
{
path: '/facilities',
name: 'AllFacilitiesPage',
path: '/facilities/:subtopicName?',
component: AllFacilitiesPage,
props: true,
handler() {
store.dispatch('notLoading');
},
},
{
path: '/classes',
path: '/:facility_id?/classes/:subtopicName?',
component: CoachClassListPage,
props: true,
handler(toRoute) {
// loading state is handled locally
store.dispatch('notLoading');
// if user only has access to one facility, facility_id will not be accessible from URL,
// but always defaulting to userFacilityId would cause problems for multi-facility admins
const facilityId = toRoute.query.facility_id || store.getters.userFacilityId;
const facilityId = toRoute.params.facility_id || store.getters.userFacilityId;
store.dispatch('setClassList', facilityId).then(
() => {
if (!store.getters.classListPageEnabled) {
// If no class list page, redirect to
// the first (and only) class.
// If no class list page, redirect to the first (and only) class and
// to the originally-selected subtopic, if available
router.replace({
name: HomePage.name,
name: toRoute.params.subtopicName || HomePage.name,
params: { classId: store.state.classList[0].id },
});
return;
Expand All @@ -52,9 +56,12 @@ export default [
},
{
name: PageNames.HOME_PAGE,
path: '/:classId/home',
path: '/:classId?/home',
component: HomePage,
handler() {
handler: toRoute => {
if (classIdParamRequiredGuard(toRoute, HomePage.name)) {
return;
}
store.dispatch('notLoading');
},
meta: {
Expand All @@ -71,7 +78,6 @@ export default [
titleParts: ['activityLabel', 'CLASS_NAME'],
},
},

{
name: ClassesPageNames.CLASS_LEARNERS_LIST_VIEWER,
path: '/:classId/learners',
Expand Down
6 changes: 5 additions & 1 deletion kolibri/plugins/coach/assets/src/routes/planLessonsRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ import LessonResourceSelectionPage from '../views/plan/LessonResourceSelectionPa
import PlanLessonSelectionContentPreview from '../views/plan/PlanLessonSelectionContentPreview';
import LessonEditDetailsPage from '../views/plan/LessonEditDetailsPage';
import LessonCreationPage from '../views/plan/LessonCreationPage';
import { classIdParamRequiredGuard } from './utils';

const CLASS = '/:classId/plan';
const CLASS = '/:classId?/plan';
const LESSON = '/lessons/:lessonId';
const ALL_LESSONS = '/lessons';
const SELECTION = '/selection';
Expand All @@ -40,6 +41,9 @@ export default [
path: path(CLASS, ALL_LESSONS),
component: LessonsRootPage,
handler(toRoute) {
if (classIdParamRequiredGuard(toRoute, 'PLAN_PAGE')) {
return;
}
showLessonsRootPage(store, toRoute.params.classId);
},
meta: {
Expand Down
4 changes: 2 additions & 2 deletions kolibri/plugins/coach/assets/src/routes/planRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export default [
...planExamRoutes,
{
name: PageNames.PLAN_PAGE,
path: '/:classId/plan',
redirect: '/:classId/plan/lessons',
path: '/:classId?/plan',
redirect: '/:classId?/plan/lessons',
},
{
name: GroupsPage.name,
Expand Down
11 changes: 9 additions & 2 deletions kolibri/plugins/coach/assets/src/routes/reportRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ import { generateQuestionListHandler } from '../modules/questionList/handlers';
import { generateResourceHandler } from '../modules/resourceDetail/handlers';
import LessonEditDetailsPage from '../views/plan/LessonEditDetailsPage';
import QuizEditDetailsPage from '../views/plan/QuizEditDetailsPage';
import { classIdParamRequiredGuard } from './utils';

const ACTIVITY = '/activity';
const CLASS = '/:classId/reports';
const CLASS = '/:classId?/reports';
const GROUPS = '/groups';
const GROUP = '/groups/:groupId';
const LEARNERS = '/learners';
Expand Down Expand Up @@ -445,7 +446,13 @@ export default [
{
path: path(CLASS, LESSONS),
component: pages.ReportsLessonListPage,
handler: defaultHandler,
handler: toRoute => {
if (classIdParamRequiredGuard(toRoute, 'ReportsLessonListPage')) {
return;
}
defaultHandler();
},

meta: {
titleParts: ['lessonsLabel', 'CLASS_NAME'],
},
Expand Down
16 changes: 16 additions & 0 deletions kolibri/plugins/coach/assets/src/routes/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import store from 'kolibri.coreVue.vuex.store';
import router from 'kolibri.coreVue.router';

export function classIdParamRequiredGuard(toRoute, subtopicName) {
if (!toRoute.params.classId) {
const redirectPage = store.getters.userIsMultiFacilityAdmin
? 'AllFacilitiesPage'
: 'CoachClassListPage';

router.replace({
name: redirectPage,
params: { subtopicName },
});
return true;
}
}
20 changes: 14 additions & 6 deletions kolibri/plugins/coach/assets/src/views/AllFacilitiesPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,27 +53,35 @@
CoreTable,
},
mixins: [commonCoach, commonCoreStrings],
props: {
subtopicName: {
type: String,
required: false,
default: null,
},
},
computed: {
facilities() {
return this.$store.state.core.facilities;
},
},
beforeMount() {
// Redirect to single-facility landing page if user/device isn't supposed
// to manage multiple facilities
if (!this.$store.getters.userIsMultiFacilityAdmin) {
this.$router.replace(this.coachClassListPageLink());
const singleFacility = { id: this.$store.getters.userFacilityId };
this.$router.replace(this.coachClassListPageLink(singleFacility));
}
},
methods: {
coachClassListPageLink(facility) {
const query = {};
const params = {};
if (facility) {
query.facility_id = facility.id;
params.facility_id = facility.id;
}
params.subtopicName = this.subtopicName;
return {
name: 'CoachClassListPage',
query,
params,
};
},
},
Expand Down
17 changes: 14 additions & 3 deletions kolibri/plugins/coach/assets/src/views/CoachClassListPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<td>
<KRouterLink
:text="classObj.name"
:to="$router.getRoute('HomePage', { classId: classObj.id })"
:to="$router.getRoute(getNextPageName, { classId: classObj.id })"
icon="classes"
/>
</td>
Expand Down Expand Up @@ -78,6 +78,13 @@
CoachAppBarPage,
},
mixins: [commonCoach, commonCoreStrings],
props: {
subtopicName: {
type: String,
required: false,
default: null,
},
},
computed: {
...mapGetters(['isAdmin', 'isClassCoach', 'isFacilityCoach', 'userIsMultiFacilityAdmin']),
...mapState(['classList', 'dataLoading']),
Expand All @@ -99,16 +106,20 @@
const facilityUrl = urls['kolibri:kolibri.plugins.facility:facility_management'];
if (facilityUrl) {
if (this.userIsMultiFacilityAdmin) {
return `${facilityUrl()}#/${this.$route.query.facility_id}/classes`;
return `${facilityUrl()}#/${this.$route.params.facility_id}/classes`;
}
return facilityUrl();
}
return '';
},
getNextPageName() {
return this.subtopicName || 'HomePage';
},
appBarTitle() {
let facilityName;
const { facility_id } = this.$route.query;
const { facility_id } = this.$route.params;
if (facility_id) {
const match = find(this.$store.state.core.facilities, { id: facility_id }) || {};
facilityName = match.name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
if (this.$store.getters.userIsMultiFacilityAdmin) {
facility_id = this.$store.state.classSummary.facility_id;
}
return this.$router.getRoute('CoachClassListPage', {}, { facility_id });
return this.$router.getRoute('CoachClassListPage', { facility_id });
},
classLearnersListRoute() {
const { query } = this.$route;
Expand Down
2 changes: 1 addition & 1 deletion kolibri/plugins/coach/assets/src/views/plan/PlanHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<p>
<BackLink
v-if="classListPageEnabled || userIsMultiFacilityAdmin"
:to="$router.getRoute('HomePage')"
:to="$router.getRoute('HomePage', { classId: this.$route.params.classId })"
:text="coreString('classHome')"
/>
</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<p>
<BackLink
v-if="classListPageEnabled || userIsMultiFacilityAdmin"
:to="$router.getRoute('HomePage')"
:to="$router.getRoute('HomePage', { classId: this.$route.params.classId })"
:text="coreString('classHome')"
/>
</p>
Expand Down

0 comments on commit 9a4b49b

Please sign in to comment.