From 6547e47394aaa37d95ae271e5f9ebe63de7c7412 Mon Sep 17 00:00:00 2001 From: Alex Velez Date: Thu, 15 Feb 2024 15:00:49 -0500 Subject: [PATCH 1/7] Add LessonsSearchBox --- .../plan/CreateExamPage/ResourceSelection.vue | 33 +++++++++++++++---- .../plan/CreateExamPage/SectionSidePanel.vue | 5 ++- .../SearchTools/LessonsSearchBox.vue | 8 +++-- 3 files changed, 36 insertions(+), 10 deletions(-) diff --git a/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/ResourceSelection.vue b/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/ResourceSelection.vue index 8f781d0d6d9..e6ff6a2a416 100644 --- a/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/ResourceSelection.vue +++ b/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/ResourceSelection.vue @@ -56,6 +56,12 @@ :channelsLink="channelsLink" :topicsLink="topicsLink" /> + + - - - + + + - - + + + + diff --git a/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/SectionSidePanel.vue b/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/SectionSidePanel.vue index 53bc6e0202d..3379acbf796 100644 --- a/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/SectionSidePanel.vue +++ b/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/SectionSidePanel.vue @@ -105,7 +105,10 @@ }, methods: { handleClosePanel() { - if (this.workingResourcePool.length > this.activeResourcePool.length) { + if ( + this.workingResourcePool && + this.workingResourcePool.length > this.activeResourcePool.length + ) { this.showConfirmationModal = true; } else { this.$router.replace(this.closePanelRoute); diff --git a/kolibri/plugins/coach/assets/src/views/plan/LessonResourceSelectionPage/SearchTools/LessonsSearchBox.vue b/kolibri/plugins/coach/assets/src/views/plan/LessonResourceSelectionPage/SearchTools/LessonsSearchBox.vue index 0b400bf56f8..397621a4a4b 100644 --- a/kolibri/plugins/coach/assets/src/views/plan/LessonResourceSelectionPage/SearchTools/LessonsSearchBox.vue +++ b/kolibri/plugins/coach/assets/src/views/plan/LessonResourceSelectionPage/SearchTools/LessonsSearchBox.vue @@ -65,13 +65,16 @@ name: 'LessonsSearchBox', mixins: [commonCoreStrings], data() { + const { params, query } = this.$route; return { - searchTerm: this.$route.params.searchTerm || '', + searchTerm: params.searchTerm || query.search || '', }; }, computed: { searchTermHasChanged() { - return this.searchTerm !== this.$route.params.searchTerm; + const { params, query } = this.$route; + const newSearchTerm = params.searchTerm || query.search; + return this.searchTerm !== newSearchTerm; }, inputPlaceHolderStyle() { return { @@ -85,6 +88,7 @@ clearSearchTerm() { this.searchTerm = ''; this.$refs.searchinput.focus(); + this.$emit('clear'); }, search() { if (this.searchTerm !== '' && this.searchTermHasChanged) { From 948da078b6b5c08902777b113ed16562223a187f Mon Sep 17 00:00:00 2001 From: Alex Velez Date: Thu, 15 Feb 2024 15:45:26 -0500 Subject: [PATCH 2/7] Add search results --- .../plan/CreateExamPage/ResourceSelection.vue | 59 +++++++++++++------ 1 file changed, 41 insertions(+), 18 deletions(-) diff --git a/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/ResourceSelection.vue b/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/ResourceSelection.vue index e6ff6a2a416..01d5e2b2172 100644 --- a/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/ResourceSelection.vue +++ b/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/ResourceSelection.vue @@ -26,7 +26,7 @@ -
+

{{ selectFromBookmarks$() }}

@@ -58,7 +58,7 @@ /> @@ -143,7 +143,7 @@ // or the actual exercises that are bookmarked and can be selected // to be added to Quiz Section. const showBookmarks = computed(() => route.value.query.showBookmarks); - const { searchQuery } = computed(() => (showBookmarks.value ? '' : route.value.query.search)); + const searchQuery = computed(() => route.value.query.search); const { updateSection, activeResourcePool, selectAllQuestions } = injectQuizCreation(); const { @@ -222,31 +222,49 @@ const channels = ref([]); const bookmarks = ref([]); + const searchResults = ref([]); // Load up the channels + if (!topicId.value) { const channelBookmarkPromises = [ - ChannelResource.fetchCollection({ - params: { has_exercises: true, available: true }, - }).then(response => { - setResources( - response.map(chnl => { - return { - ...chnl, - id: chnl.root, - title: chnl.name, - kind: ContentNodeKinds.CHANNEL, - is_leaf: false, - }; - }) - ); - }), ContentNodeResource.fetchBookmarks({ params: { limit: 25, available: true } }).then( data => { bookmarks.value = data.results ? data.results : []; } ), ]; + + if (searchQuery.value) { + const getParams = { + max_results: 25, + keywords: searchQuery.value, + kind: ContentNodeKinds.EXERCISE, + }; + channelBookmarkPromises.push( + ContentNodeResource.fetchCollection({ getParams }).then(response => { + searchResults.value = response.results; + }) + ); + } else { + channelBookmarkPromises.push( + ChannelResource.fetchCollection({ + params: { has_exercises: true, available: true }, + }).then(response => { + setResources( + response.map(chnl => { + return { + ...chnl, + id: chnl.root, + title: chnl.name, + kind: ContentNodeKinds.CHANNEL, + is_leaf: false, + }; + }) + ); + }) + ); + } Promise.all(channelBookmarkPromises).then(() => { // When we don't have a topicId we're setting the value of useQuizResources.resources @@ -281,6 +299,10 @@ .map(item => ({ ...item, is_leaf: true })); } + if (searchQuery.value) { + return searchResults.value; + } + return resources.value; }); @@ -301,6 +323,7 @@ loading, hasMore, loadingMore, + searchQuery, fetchMoreQuizResources, resetWorkingResourcePool, contentPresentInWorkingResourcePool, From bcb3cae038fdfca7df2ce36a56ed51f4e9cd5ba5 Mon Sep 17 00:00:00 2001 From: Alex Velez Date: Thu, 15 Feb 2024 16:06:04 -0500 Subject: [PATCH 3/7] add fetch more --- .../plan/CreateExamPage/ResourceSelection.vue | 45 ++++++++++++++----- 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/ResourceSelection.vue b/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/ResourceSelection.vue index 01d5e2b2172..95aff2f3900 100644 --- a/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/ResourceSelection.vue +++ b/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/ResourceSelection.vue @@ -158,7 +158,7 @@ // TODO let's not use text for this const viewMoreButtonState = computed(() => { - if (hasMore.value) { + if (hasMore.value || moreSearchResults.value) { return ViewMoreButtonStates.HAS_MORE; } else { return ViewMoreButtonStates.NO_MORE; @@ -205,6 +205,29 @@ return workingResourceIds.includes(content.id); } + function fetchSearchResults() { + const getParams = { + max_results: 25, + keywords: searchQuery.value, + kind: ContentNodeKinds.EXERCISE, + }; + return ContentNodeResource.fetchCollection({ getParams }).then(response => { + searchResults.value = response.results; + moreSearchResults.value = response.more; + }); + } + + function fetchMoreSearchResults() { + return ContentNodeResource.fetchCollection({ + getParams: moreSearchResults.value, + }).then( + response => { + searchResults.value = searchResults.value.concat(response.results); + moreSearchResults.value = response.more; + } + ); + } + const { hasCheckbox, topic, @@ -223,6 +246,7 @@ const channels = ref([]); const bookmarks = ref([]); const searchResults = ref([]); + const moreSearchResults = ref(null); // Load up the channels @@ -236,16 +260,7 @@ ]; if (searchQuery.value) { - const getParams = { - max_results: 25, - keywords: searchQuery.value, - kind: ContentNodeKinds.EXERCISE, - }; - channelBookmarkPromises.push( - ContentNodeResource.fetchCollection({ getParams }).then(response => { - searchResults.value = response.results; - }) - ); + channelBookmarkPromises.push(fetchSearchResults()); } else { channelBookmarkPromises.push( ChannelResource.fetchCollection({ @@ -314,6 +329,12 @@ } }); + watch(searchQuery, () => { + if (searchQuery.value) { + fetchSearchResults(); + } + }); + return { topic, topicId, @@ -324,7 +345,7 @@ hasMore, loadingMore, searchQuery, - fetchMoreQuizResources, + fetchMoreQuizResources: searchQuery ? fetchMoreSearchResults : fetchMoreQuizResources, resetWorkingResourcePool, contentPresentInWorkingResourcePool, //contentList, From 9a5e091809a14eeead9482dd9c9885a254b99431 Mon Sep 17 00:00:00 2001 From: Alex Velez Date: Thu, 15 Feb 2024 16:15:15 -0500 Subject: [PATCH 4/7] Lint files --- .../views/plan/CreateExamPage/ResourceSelection.vue | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/ResourceSelection.vue b/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/ResourceSelection.vue index 95aff2f3900..5919fada9f8 100644 --- a/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/ResourceSelection.vue +++ b/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/ResourceSelection.vue @@ -220,12 +220,10 @@ function fetchMoreSearchResults() { return ContentNodeResource.fetchCollection({ getParams: moreSearchResults.value, - }).then( - response => { - searchResults.value = searchResults.value.concat(response.results); - moreSearchResults.value = response.more; - } - ); + }).then(response => { + searchResults.value = searchResults.value.concat(response.results); + moreSearchResults.value = response.more; + }); } const { @@ -258,7 +256,7 @@ } ), ]; - + if (searchQuery.value) { channelBookmarkPromises.push(fetchSearchResults()); } else { From 7480e83bd4f0e6077eda7ea66c750fb09d9c391b Mon Sep 17 00:00:00 2001 From: Alex Velez Date: Thu, 15 Feb 2024 16:22:26 -0500 Subject: [PATCH 5/7] Fix clear search --- .../plan/CreateExamPage/ResourceSelection.vue | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/ResourceSelection.vue b/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/ResourceSelection.vue index 5919fada9f8..33c8dfb360d 100644 --- a/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/ResourceSelection.vue +++ b/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/ResourceSelection.vue @@ -26,7 +26,7 @@ -
+

{{ selectFromBookmarks$() }}

@@ -499,14 +499,18 @@ return ''; }, handleSearchTermChange(searchTerm) { - this.$router.push({ - query: { search: searchTerm }, - }); + const query = { + ...this.$route.query, + search: searchTerm, + }; + this.$router.push({ query }); }, clearSearchTerm() { - this.$router.push({ - query: { search: null }, - }); + const query = { + ...this.$route.query, + }; + delete query.search; + this.$router.push({ query }); }, }, }; From 9f6f91707943fa84070b375894508deaaab74c96 Mon Sep 17 00:00:00 2001 From: Alex Velez Date: Thu, 15 Feb 2024 16:26:23 -0500 Subject: [PATCH 6/7] Refactor --- .../assets/src/views/plan/CreateExamPage/ResourceSelection.vue | 1 - 1 file changed, 1 deletion(-) diff --git a/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/ResourceSelection.vue b/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/ResourceSelection.vue index 33c8dfb360d..c4a37f9add8 100644 --- a/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/ResourceSelection.vue +++ b/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/ResourceSelection.vue @@ -342,7 +342,6 @@ loading, hasMore, loadingMore, - searchQuery, fetchMoreQuizResources: searchQuery ? fetchMoreSearchResults : fetchMoreQuizResources, resetWorkingResourcePool, contentPresentInWorkingResourcePool, From 64d4556b403288ccd24ca46683cfaf64f1ed08db Mon Sep 17 00:00:00 2001 From: Alex Velez Date: Mon, 19 Feb 2024 15:55:35 -0500 Subject: [PATCH 7/7] Fix fech more resources condition --- .../views/plan/CreateExamPage/ResourceSelection.vue | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/ResourceSelection.vue b/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/ResourceSelection.vue index c4a37f9add8..8ac5bb5af59 100644 --- a/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/ResourceSelection.vue +++ b/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/ResourceSelection.vue @@ -75,7 +75,7 @@ :loadingMoreState="loadingMore" @changeselectall="toggleTopicInWorkingResources" @change_content_card="toggleSelected" - @moreresults="fetchMoreQuizResources" + @moreresults="fetchMoreResources" />
@@ -333,6 +333,13 @@ } }); + function fetchMoreResources() { + if (searchQuery.value) { + return fetchMoreSearchResults(); + } + return fetchMoreQuizResources(); + } + return { topic, topicId, @@ -342,7 +349,7 @@ loading, hasMore, loadingMore, - fetchMoreQuizResources: searchQuery ? fetchMoreSearchResults : fetchMoreQuizResources, + fetchMoreResources, resetWorkingResourcePool, contentPresentInWorkingResourcePool, //contentList,