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

update coach routing #11224

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
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 @@ -41,7 +41,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,32 +11,36 @@ 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: '/:subtopicName?/facilities',
component: AllFacilitiesPage,
props: true,
handler() {
store.dispatch('notLoading');
},
},
{
path: '/classes',
path: '/:facility_id?/classes',
thanksameeelian marked this conversation as resolved.
Show resolved Hide resolved
component: CoachClassListPage,
props: true,
handler(toRoute) {
store.dispatch('loading');
// 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
19 changes: 19 additions & 0 deletions kolibri/plugins/coach/assets/src/routes/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import store from 'kolibri.coreVue.vuex.store';
import router from 'kolibri.coreVue.router';

export function classIdParamRequiredGuard(toRoute, subtopicName) {
if (!toRoute.params.classId) {
if (store.getters.userIsMultiFacilityAdmin) {
router.replace({
name: 'AllFacilitiesPage',
params: { subtopicName },
});
return true;
} else {
router.replace({
name: 'CoachClassListPage',
params: { subtopicName },
});
}
}
}
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