Skip to content

Commit

Permalink
refactor route terms
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexVelezLl committed Nov 7, 2024
1 parent c7e56c0 commit cfb1877
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 102 deletions.
2 changes: 1 addition & 1 deletion kolibri/plugins/coach/assets/src/constants/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const PageNames = {
/* Lessons */
LESSON_CREATION_ROOT: 'LESSON_CREATION_ROOT',
LESSON_CREATION_ROOT_BETTER: 'LESSON_CREATION_ROOT_BETTER',
SUMMARY: 'LESSON_SUMMARY',
LESSON_SUMMARY: 'LESSON_SUMMARY',
RESOURCE_USER_REPORT: 'RESOURCE_USER_REPORT',
RESOURCE_USER_REPORT_ROOT: 'RESOURCE_USER_REPORT_ROOT',
RESOURCE_CONTENT_PREVIEW: 'RESOURCE_CONTENT_PREVIEW', // exclusively a route name
Expand Down
31 changes: 11 additions & 20 deletions kolibri/plugins/coach/assets/src/routes/examRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,23 @@ import {
generateQuestionDetailHandler,
questionRootRedirectHandler,
} from '../modules/questionDetail/handlers';
import { useRouteTerms } from './utils';

const CLASS = '/:classId';
const QUIZ = '/quizzes/:quizId';
const ALL_QUIZZES = '/quizzes';
const OPTIONAL_GROUP = '/groups/:groupId?';
const LEARNER = '/learners/:learnerId';
const QUESTION = '/questions/:questionId';
const TRY = '/try/:tryIndex';
const INTERACTION = '/interactions/:interactionIndex';

function path(...args) {
return args.join('');
}
const { CLASS, QUIZ, ALL_QUIZZES, OPTIONAL_GROUP, LEARNER, QUESTION, TRY, INTERACTION } =
useRouteTerms();

export default [
{
name: PageNames.EXAMS_ROOT,
path: path(CLASS, ALL_QUIZZES),
path: CLASS + ALL_QUIZZES,
component: ExamsRootPage,
meta: {
titleParts: ['quizzesLabel', 'CLASS_NAME'],
},
},
{
name: PageNames.EXAM_CREATION_ROOT,
path: path(CLASS, QUIZ, '/edit/:sectionIndex'),
path: CLASS + QUIZ + '/edit/:sectionIndex',
component: CreateExamPage,
children: [
{
Expand Down Expand Up @@ -75,14 +66,14 @@ export default [
},
{
name: PageNames.EXAM_SUMMARY,
path: path(CLASS, QUIZ, '/:tabId?'),
path: CLASS + QUIZ + '/:tabId?',
component: QuizSummaryPage,
meta: {
titleParts: ['QUIZ_NAME', 'quizzesLabel', 'CLASS_NAME'],
},
},
{
path: path(CLASS, OPTIONAL_GROUP, QUIZ, LEARNER),
path: CLASS + OPTIONAL_GROUP + QUIZ + LEARNER,
name: PageNames.QUIZ_LEARNER_PAGE_ROOT,
redirect: to => {
const { params } = to;
Expand All @@ -99,7 +90,7 @@ export default [
},
{
name: PageNames.QUIZ_LEARNER_REPORT,
path: path(CLASS, OPTIONAL_GROUP, QUIZ, LEARNER, TRY, QUESTION, INTERACTION),
path: CLASS + OPTIONAL_GROUP + QUIZ + LEARNER + TRY + QUESTION + INTERACTION,
component: LearnerQuizPage,
handler: generateExamReportDetailHandler(['groupId', 'learnerId', 'quizId']),
meta: {
Expand All @@ -108,7 +99,7 @@ export default [
},
{
name: PageNames.QUIZ_PREVIEW,
path: path(CLASS, QUIZ, '/preview'),
path: CLASS + QUIZ + '/preview',
component: QuizPreviewPage,
handler() {
store.dispatch('notLoading');
Expand All @@ -119,15 +110,15 @@ export default [
},
{
name: PageNames.QUIZ_QUESTION_PAGE_ROOT,
path: path(CLASS, OPTIONAL_GROUP, QUIZ, QUESTION),
path: CLASS + OPTIONAL_GROUP + QUIZ + QUESTION,
beforeEnter: (to, from, next) => {
const { params } = to;
return questionRootRedirectHandler(params, PageNames.QUIZ_QUESTION_REPORT, next);
},
},
{
name: PageNames.QUIZ_QUESTION_REPORT,
path: path(CLASS, OPTIONAL_GROUP, QUIZ, QUESTION, LEARNER, INTERACTION),
path: CLASS + OPTIONAL_GROUP + QUIZ + QUESTION + LEARNER + INTERACTION,
component: QuestionLearnersPage,
handler: generateQuestionDetailHandler(['groupId', 'lessonId', 'exerciseId', 'questionId']),
meta: {
Expand Down
32 changes: 11 additions & 21 deletions kolibri/plugins/coach/assets/src/routes/groupsRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,10 @@ 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';

const CLASS = '/:classId';
const ALL_GROUPS = '/groups';
const GROUP = '/groups/:groupId';
const LESSON = '/lessons/:lessonId';
const LEARNER = '/learners/:learnerId';
const LEARNERS = '/learners';
const QUESTIONS = '/questions';
const EXERCISE = '/exercises/:exerciseId';
const QUIZ = '/quizzes/:quizId';

function path(...args) {
return args.join('');
}
const { CLASS, ALL_GROUPS, GROUP, LESSON, LEARNER, ALL_LEARNERS, QUESTIONS, EXERCISE, QUIZ } =
useRouteTerms();

const { showGroupsPage } = useGroups();

Expand All @@ -36,7 +26,7 @@ function defaultHandler() {
export default [
{
name: PageNames.GROUPS_ROOT,
path: path(CLASS, ALL_GROUPS),
path: CLASS + ALL_GROUPS,
component: GroupsRootPage,
handler(to) {
showGroupsPage(store, to.params.classId);
Expand All @@ -47,7 +37,7 @@ export default [
},
{
name: PageNames.GROUP_SUMMARY,
path: path(CLASS, GROUP),
path: CLASS + GROUP,
component: GroupMembersPage,
handler(to) {
showGroupsPage(store, to.params.classId);
Expand All @@ -58,15 +48,15 @@ export default [
},
{
name: PageNames.GROUP_ENROLL,
path: path(CLASS, GROUP, '/enroll'),
path: CLASS + GROUP + '/enroll',
component: GroupEnrollPage,
handler(to) {
showGroupsPage(store, to.params.classId);
},
},
{
name: PageNames.GROUP_LESSON_SUMMARY,
path: path(CLASS, GROUP, LESSON, '/:tabId?'),
path: CLASS + GROUP + LESSON + '/:tabId?',
component: LessonSummaryPage,
handler(toRoute, fromRoute) {
if (
Expand All @@ -86,7 +76,7 @@ export default [
},
{
name: PageNames.GROUP_LESSON_LEARNER,
path: path(CLASS, GROUP, LESSON, LEARNER),
path: CLASS + GROUP + LESSON + LEARNER,
component: LessonLearnerPage,
handler: defaultHandler,
meta: {
Expand All @@ -95,7 +85,7 @@ export default [
},
{
name: PageNames.GROUP_LESSON_EXERCISE_LEARNER_REPORT,
path: path(CLASS, GROUP, LESSON, EXERCISE, LEARNERS),
path: CLASS + GROUP + LESSON + EXERCISE + ALL_LEARNERS,
component: GroupLessonExerciseLearnersPage,
handler: generateResourceHandler(['exerciseId']),
meta: {
Expand All @@ -104,7 +94,7 @@ export default [
},
{
name: PageNames.GROUP_LESSON_EXERCISE_QUESTIONS_REPORT,
path: path(CLASS, GROUP, LESSON, EXERCISE, QUESTIONS),
path: CLASS + GROUP + LESSON + EXERCISE + QUESTIONS,
component: ExerciseQuestionListPage,
handler: generateQuestionListHandler(['groupId', 'lessonId', 'exerciseId']),
meta: {
Expand All @@ -113,7 +103,7 @@ export default [
},
{
name: PageNames.GROUP_EXAM_SUMMARY,
path: path(CLASS, GROUP, QUIZ, '/:tabId?'),
path: CLASS + GROUP + QUIZ + '/:tabId?',
component: QuizSummaryPage,
meta: {
titleParts: ['QUIZ_NAME', 'quizzesLabel', 'CLASS_NAME'],
Expand Down
18 changes: 6 additions & 12 deletions kolibri/plugins/coach/assets/src/routes/learnersRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +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';

const CLASS = '/:classId';
const ALL_LEARNERS = '/learners';
const LEARNER = '/learners/:learnerId';
const LESSON = '/lessons/:lessonId';

function path(...args) {
return args.join('');
}
const { CLASS, ALL_LEARNERS, LEARNER, LESSON } = useRouteTerms();

function defaultHandler() {
store.dispatch('notLoading');
Expand All @@ -21,7 +15,7 @@ function defaultHandler() {
export default [
{
name: PageNames.LEARNERS_ROOT,
path: path(CLASS, ALL_LEARNERS),
path: CLASS + ALL_LEARNERS,
component: LearnersRootPage,
handler: defaultHandler,
meta: {
Expand All @@ -30,7 +24,7 @@ export default [
},
{
name: PageNames.LEARNER_SUMMARY,
path: path(CLASS, LEARNER),
path: CLASS + LEARNER,
component: LearnerSummaryPage,
handler: defaultHandler,
meta: {
Expand All @@ -39,7 +33,7 @@ export default [
},
{
name: 'ReportsLearnerActivityPage', // Will be removed in #12733
path: path(CLASS, LEARNER, '/activity'),
path: CLASS + LEARNER + '/activity',
component: ReportsLearnerActivityPage,
handler: defaultHandler,
meta: {
Expand All @@ -48,7 +42,7 @@ export default [
},
{
name: PageNames.LEARNER_LESSON_REPORT,
path: path(CLASS, LEARNER, LESSON),
path: CLASS + LEARNER + LESSON,
component: LearnerLessonPage,
handler: defaultHandler,
meta: {
Expand Down
Loading

0 comments on commit cfb1877

Please sign in to comment.