Skip to content

Commit

Permalink
can open search results page on the quiz side panel
Browse files Browse the repository at this point in the history
  • Loading branch information
AllanOXDi committed Feb 19, 2025
1 parent cc3d91e commit bbffa9c
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 48 deletions.
2 changes: 1 addition & 1 deletion kolibri/plugins/coach/assets/src/routes/examRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import SelectionIndex from '../views/common/resourceSelection/subPages/Selection
import SelectFromChannels from '../views/common/resourceSelection/subPages/SelectFromTopicTree.vue';
import SelectFromBookmarks from '../views/common/resourceSelection/subPages/SelectFromBookmarks.vue';
import ManageSelectedResources from '../views/common/resourceSelection/subPages/ManageSelectedResources.vue';
import { SelectFromSearchResults } from '../views/common/SelectFromSearchResults.vue';
import SelectFromSearchResults from '../views/common/SelectFromSearchResults.vue';
import PreviewSelectedResources from '../views/common/resourceSelection/subPages/PreviewSelectedResources/index.vue';
import {
generateQuestionDetailHandler,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
import { PageNames } from '../../constants';
import { coachStrings } from './commonCoachStrings';
import UpdatedResourceSelection from './resourceSelection/UpdatedResourceSelection.vue';
import { SelectionTarget } from './resourceSelection/contants';
/**
* @typedef {import('../../../../../../composables/useFetch').FetchObject} FetchObject
*/
Expand All @@ -68,7 +68,10 @@
const { topicId } = instance.proxy.$route.query;
if (topicId) {
instance.proxy.$router.push({
name: PageNames.LESSON_SELECT_RESOURCES_TOPIC_TREE,
name:
this.target === SelectionTarget.LESSON
? PageNames.LESSON_SELECT_RESOURCES_TOPIC_TREE
: PageNames.QUIZ_SELECT_RESOURCES,
query: {
topicId,
},
Expand Down Expand Up @@ -146,6 +149,10 @@
type: Function,
required: true,
},
target: {
type: String,
required: true,
},
},
computed: {
resultsCountMessage() {
Expand All @@ -169,10 +176,17 @@
},
methods: {
onSearchClick() {
this.$router.push({
name: PageNames.LESSON_SELECT_RESOURCES_SEARCH,
query: this.$route.query,
});
if (this.target === SelectionTarget.LESSON) {
this.$router.push({
name: PageNames.LESSON_SELECT_RESOURCES_SEARCH,
query: this.$route.query,
});
} else {
this.$router.push({
name: PageNames.QUIZ_SEARCH_PANEL,
query: this.$route.query.topicId,
});
}
},
onClearSearch() {
this.$emit('clearSearch');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
:selectedResources="workingResourcePool"
:topic="topic"
:treeFetch="treeFetch"
:searchTerms="searchTerms"
:searchTerms.sync="searchTerms"
:searchFetch="searchFetch"
:channelsFetch="channelsFetch"
:bookmarksFetch="bookmarksFetch"
Expand All @@ -55,6 +55,7 @@
:target="SelectionTarget.QUIZ"
:contentCardMessage="contentCardMessage"
:getResourceLink="getResourceLink"
:displayingSearchResults="displayingSearchResults"
@selectResources="addToWorkingResourcePool"
@deselectResources="removeFromWorkingResourcePool"
@setSelectedResources="setWorkingResourcePool"
Expand Down Expand Up @@ -251,39 +252,47 @@
const isPracticeQuiz = item =>
!selectPracticeQuiz || get(item, ['options', 'modality'], false) === 'QUIZ';
const { topic, loading, treeFetch, channelsFetch, bookmarksFetch, searchTerms, searchFetch } =
useResourceSelection({
searchResultsRouteName: PageNames.QUIZ_SEARCH_RESULTS,
bookmarks: {
filters: { kind: ContentNodeKinds.EXERCISE },
annotator: results => results.filter(isPracticeQuiz),
},
channels: {
filters: {
contains_exercise: true,
contains_quiz: selectPracticeQuiz ? true : null,
},
annotator: results =>
annotateTopicsWithDescendantCounts(
results.map(channel => {
return {
...channel,
id: channel.root,
title: channel.name,
kind: ContentNodeKinds.CHANNEL,
is_leaf: false,
};
}),
),
const {
topic,
loading,
treeFetch,
channelsFetch,
bookmarksFetch,
searchTerms,
searchFetch,
displayingSearchResults,
} = useResourceSelection({
searchResultsRouteName: PageNames.QUIZ_SEARCH_RESULTS,
bookmarks: {
filters: { kind: ContentNodeKinds.EXERCISE },
annotator: results => results.filter(isPracticeQuiz),
},
channels: {
filters: {
contains_exercise: true,
contains_quiz: selectPracticeQuiz ? true : null,
},
topicTree: {
filters: {
kind_in: [ContentNodeKinds.EXERCISE, ContentNodeKinds.TOPIC],
contains_quiz: selectPracticeQuiz ? true : null,
},
annotator: annotateTopicsWithDescendantCounts,
annotator: results =>
annotateTopicsWithDescendantCounts(
results.map(channel => {
return {
...channel,
id: channel.root,
title: channel.name,
kind: ContentNodeKinds.CHANNEL,
is_leaf: false,
};
}),
),
},
topicTree: {
filters: {
kind_in: [ContentNodeKinds.EXERCISE, ContentNodeKinds.TOPIC],
contains_quiz: selectPracticeQuiz ? true : null,
},
});
annotator: annotateTopicsWithDescendantCounts,
},
});
function handleCancelClose() {
showCloseConfirmation.value = false;
Expand Down Expand Up @@ -397,6 +406,7 @@
selectQuiz$,
addNumberOfQuestions$,
numberOfSelectedResources$,
displayingSearchResults,
};
},
beforeRouteLeave(_, __, next) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,76 @@
<template>

<SearchFilters
<SearchFiltersPanel
ref="searchFiltersPanel"
v-model="searchTermsComputed"
:topic="topic"
:searchTerms="searchTerms"
:searchFetch="searchFetch"
:setTitle="setTitle"
:setGoBack="setGoBack"
:target="target"
accordion
showChannels
:showActivities="!isQuiz"
:title="topic && searchInFolder$({ folder: topic.title })"
@categorySearchOpen="handleCategorySearchOpen"
/>

</template>


<script>
import SearchFilters from '../../../../../common/SearchFilters.vue';
import SearchFiltersPanel from 'kolibri-common/components/SearchFiltersPanel/index.vue';
import { getCurrentInstance, onMounted, ref } from 'vue';
import { searchAndFilterStrings } from 'kolibri-common/strings/searchAndFilterStrings';
import { coreStrings } from 'kolibri/uiText/commonCoreStrings';
import { PageNames } from '../../../../../../constants';
import { SelectionTarget } from '../../../../../common/resourceSelection/contants';
export default {
name: 'QuizSearchPanel',
components: {
SearchFilters,
SearchFiltersPanel,
},
setup(props) {
const prevRoute = ref(null);
const instance = getCurrentInstance();
const goBack = () => {
const backRoute = prevRoute.value?.name
? prevRoute.value
: {
name: PageNames.QUIZ_SELECT_RESOURCES_INDEX,
};
instance.proxy.$router.push(backRoute);
};
const { searchLabel$ } = coreStrings;
const { chooseACategory$ } = searchAndFilterStrings;
const title = searchLabel$();
onMounted(() => {
props.setTitle(title);
props.setGoBack(goBack);
});
function handleCategorySearchOpen(isOpen) {
if (isOpen) {
props.setTitle(chooseACategory$());
props.setGoBack(() => {
const searchFiltersPanelRef = instance.proxy.$refs.searchFiltersPanel;
searchFiltersPanelRef.closeCategorySearch();
});
} else {
props.setTitle(title);
props.setGoBack(goBack);
}
}
// Fetch first available labels of the selected topic
props.searchFetch.fetchData();
const { searchInFolder$ } = searchAndFilterStrings;
return {
// eslint-disable-next-line vue/no-unused-properties
prevRoute,
searchInFolder$,
handleCategorySearchOpen,
};
},
props: {
searchTerms: {
Expand Down Expand Up @@ -59,6 +109,9 @@
this.$emit('update:searchTerms', value);
},
},
isQuiz() {
return this.target === SelectionTarget.QUIZ;
},
},
};
Expand Down

0 comments on commit bbffa9c

Please sign in to comment.