From 755532b0a692b6428e0ddfd45ed1d877b4f2c140 Mon Sep 17 00:00:00 2001 From: Alex Velez Date: Thu, 7 Nov 2024 09:52:53 -0500 Subject: [PATCH] Light base routes --- .../coachNotifications/gettersUtils.js | 4 +- .../coach/assets/src/routes/baseRoutes.js | 40 ++++++++++--------- .../coach/assets/src/routes/examRoutes.js | 22 ++++++++-- .../coach/assets/src/routes/groupsRoutes.js | 25 +++++++++--- .../plugins/coach/assets/src/routes/index.js | 2 +- .../coach/assets/src/routes/learnersRoutes.js | 13 ++++-- .../coach/assets/src/routes/lessonsRoutes.js | 8 ---- 7 files changed, 70 insertions(+), 44 deletions(-) diff --git a/kolibri/plugins/coach/assets/src/modules/coachNotifications/gettersUtils.js b/kolibri/plugins/coach/assets/src/modules/coachNotifications/gettersUtils.js index 9bf5860433e..014a5ee2275 100644 --- a/kolibri/plugins/coach/assets/src/modules/coachNotifications/gettersUtils.js +++ b/kolibri/plugins/coach/assets/src/modules/coachNotifications/gettersUtils.js @@ -84,7 +84,7 @@ const pageNameToNotificationPropsMap = [ isMultiple: false, isWholeClass: false, }, - value: PageNames.LESSON_LEARNER_REPORT, + value: PageNames.LEARNER_LESSON_REPORT, }, { key: { @@ -108,7 +108,7 @@ const pageNameToNotificationPropsMap = [ isMultiple: false, isWholeClass: true, }, - value: PageNames.LESSON_LEARNER_REPORT, + value: PageNames.LEARNER_LESSON_REPORT, }, { key: { diff --git a/kolibri/plugins/coach/assets/src/routes/baseRoutes.js b/kolibri/plugins/coach/assets/src/routes/baseRoutes.js index 470084c1123..ccf5d181fb7 100644 --- a/kolibri/plugins/coach/assets/src/routes/baseRoutes.js +++ b/kolibri/plugins/coach/assets/src/routes/baseRoutes.js @@ -1,22 +1,24 @@ import { PageNames } from '../constants'; -import routes from '.'; -const baseRouteNames = { - classHome: PageNames.HOME_PAGE, - lessons: PageNames.LESSONS_ROOT, - quizzes: PageNames.EXAMS_ROOT, - learners: PageNames.LEARNERS_ROOT, - groups: PageNames.GROUPS_ROOT, +export default { + classHome: { + name: PageNames.HOME_PAGE, + path: '/:classId?/home', + }, + lessons: { + name: PageNames.LESSONS_ROOT, + path: '/:classId?/lessons', + }, + quizzes: { + name: PageNames.EXAMS_ROOT, + path: '/:classId?/quizzes', + }, + learners: { + name: PageNames.LEARNERS_ROOT, + path: '/:classId?/learners', + }, + groups: { + name: PageNames.GROUPS_ROOT, + path: '/:classId?/groups', + }, }; - -const baseRoutes = Object.entries(baseRouteNames).reduce((curr, baseRouteName) => { - const [key, value] = baseRouteName; - const route = routes.find(({ name }) => name === value); - curr[key] = { - name: route.name, - path: route.path, - }; - return curr; -}, {}); - -export default baseRoutes; diff --git a/kolibri/plugins/coach/assets/src/routes/examRoutes.js b/kolibri/plugins/coach/assets/src/routes/examRoutes.js index bce5c84eaed..3e5b8acec86 100644 --- a/kolibri/plugins/coach/assets/src/routes/examRoutes.js +++ b/kolibri/plugins/coach/assets/src/routes/examRoutes.js @@ -15,16 +15,30 @@ import { generateQuestionDetailHandler, questionRootRedirectHandler, } from '../modules/questionDetail/handlers'; -import { useRouteTerms } from './utils'; +import { classIdParamRequiredGuard, useRouteTerms } from './utils'; -const { CLASS, QUIZ, ALL_QUIZZES, OPTIONAL_GROUP, LEARNER, QUESTION, TRY, INTERACTION } = - useRouteTerms(); +const { + CLASS, + OPTIONAL_CLASS, + QUIZ, + ALL_QUIZZES, + OPTIONAL_GROUP, + LEARNER, + QUESTION, + TRY, + INTERACTION, +} = useRouteTerms(); export default [ { name: PageNames.EXAMS_ROOT, - path: CLASS + ALL_QUIZZES, + path: OPTIONAL_CLASS + ALL_QUIZZES, component: ExamsRootPage, + handler(toRoute, fromRoute, next) { + if (classIdParamRequiredGuard(toRoute, PageNames.EXAMS_ROOT, next)) { + return; + } + }, meta: { titleParts: ['quizzesLabel', 'CLASS_NAME'], }, diff --git a/kolibri/plugins/coach/assets/src/routes/groupsRoutes.js b/kolibri/plugins/coach/assets/src/routes/groupsRoutes.js index 3ec77e74853..737dbf6a8f5 100644 --- a/kolibri/plugins/coach/assets/src/routes/groupsRoutes.js +++ b/kolibri/plugins/coach/assets/src/routes/groupsRoutes.js @@ -12,10 +12,20 @@ import GroupLessonExerciseLearnersPage from '../views/groups/reports/GroupLesson import { showLessonSummaryPage } from '../modules/lessonSummary/handlers'; import { generateResourceHandler } from '../modules/resourceDetail/handlers'; import QuizSummaryPage from '../views/quizzes/QuizSummaryPage'; -import { useRouteTerms } from './utils'; +import { classIdParamRequiredGuard, useRouteTerms } from './utils'; -const { CLASS, ALL_GROUPS, GROUP, LESSON, LEARNER, ALL_LEARNERS, QUESTIONS, EXERCISE, QUIZ } = - useRouteTerms(); +const { + CLASS, + OPTIONAL_CLASS, + ALL_GROUPS, + GROUP, + LESSON, + LEARNER, + ALL_LEARNERS, + QUESTIONS, + EXERCISE, + QUIZ, +} = useRouteTerms(); const { showGroupsPage } = useGroups(); @@ -26,10 +36,13 @@ function defaultHandler() { export default [ { name: PageNames.GROUPS_ROOT, - path: CLASS + ALL_GROUPS, + path: OPTIONAL_CLASS + ALL_GROUPS, component: GroupsRootPage, - handler(to) { - showGroupsPage(store, to.params.classId); + handler(toRoute, fromRoute, next) { + if (classIdParamRequiredGuard(toRoute, PageNames.GROUPS_ROOT, next)) { + return; + } + showGroupsPage(store, toRoute.params.classId); }, meta: { titleParts: ['groupsLabel', 'CLASS_NAME'], diff --git a/kolibri/plugins/coach/assets/src/routes/index.js b/kolibri/plugins/coach/assets/src/routes/index.js index 48b792848d0..acd65b08de4 100644 --- a/kolibri/plugins/coach/assets/src/routes/index.js +++ b/kolibri/plugins/coach/assets/src/routes/index.js @@ -100,7 +100,7 @@ export default [ }, { name: ClassesPageNames.CLASS_LEARNERS_LIST_VIEWER, - path: '/:classId/learners', + path: '/:classId/learners/devices', component: ClassLearnersListPage, handler() { store.dispatch('notLoading'); diff --git a/kolibri/plugins/coach/assets/src/routes/learnersRoutes.js b/kolibri/plugins/coach/assets/src/routes/learnersRoutes.js index c680f190dd2..844f40af067 100644 --- a/kolibri/plugins/coach/assets/src/routes/learnersRoutes.js +++ b/kolibri/plugins/coach/assets/src/routes/learnersRoutes.js @@ -4,9 +4,9 @@ import LearnersRootPage from '../views/learners/LearnersRootPage'; import LearnerSummaryPage from '../views/learners/LearnerSummaryPage'; import ReportsLearnerActivityPage from '../views/learners/LearnerSummaryPage/ReportsLearnerActivityPage.vue'; import LearnerLessonPage from '../views/learners/reports/LearnerLessonPage.vue'; -import { useRouteTerms } from './utils'; +import { classIdParamRequiredGuard, useRouteTerms } from './utils'; -const { CLASS, ALL_LEARNERS, LEARNER, LESSON } = useRouteTerms(); +const { CLASS, OPTIONAL_CLASS, ALL_LEARNERS, LEARNER, LESSON } = useRouteTerms(); function defaultHandler() { store.dispatch('notLoading'); @@ -15,9 +15,14 @@ function defaultHandler() { export default [ { name: PageNames.LEARNERS_ROOT, - path: CLASS + ALL_LEARNERS, + path: OPTIONAL_CLASS + ALL_LEARNERS, component: LearnersRootPage, - handler: defaultHandler, + handler(toRoute, fromRoute, next) { + if (classIdParamRequiredGuard(toRoute, PageNames.LEARNERS_ROOT, next)) { + return; + } + defaultHandler(); + }, meta: { titleParts: ['learnersLabel', 'CLASS_NAME'], }, diff --git a/kolibri/plugins/coach/assets/src/routes/lessonsRoutes.js b/kolibri/plugins/coach/assets/src/routes/lessonsRoutes.js index efdb5c8e88e..93c20fc9ca9 100644 --- a/kolibri/plugins/coach/assets/src/routes/lessonsRoutes.js +++ b/kolibri/plugins/coach/assets/src/routes/lessonsRoutes.js @@ -316,14 +316,6 @@ export default [ titleParts: ['questionsLabel', 'EXERCISE_NAME', 'LESSON_NAME', 'CLASS_NAME'], }, }, - { - path: CLASS + LESSON + EXERCISE + QUESTION, - name: PageNames.LESSON_EXERCISE_QUESTION_PAGE_ROOT, - beforeEnter: (to, from, next) => { - const { params } = to; - return questionRootRedirectHandler(params, PageNames.LESSON_EXERCISE_QUESTION_REPORT, next); - }, - }, { path: CLASS + LESSON + LEARNER + EXERCISE, name: PageNames.LESSON_LEARNER_EXERCISE_PAGE_ROOT,