diff --git a/kolibri/plugins/coach/assets/src/composables/useQuizCreation.js b/kolibri/plugins/coach/assets/src/composables/useQuizCreation.js index 82173e617d4..7690124e38d 100644 --- a/kolibri/plugins/coach/assets/src/composables/useQuizCreation.js +++ b/kolibri/plugins/coach/assets/src/composables/useQuizCreation.js @@ -1,5 +1,6 @@ -import { v4 as uuidv4 } from 'uuid'; +import { v4 } from 'uuid'; import isEqual from 'lodash/isEqual'; +import uniqWith from 'lodash/uniqWith'; import range from 'lodash/range'; import shuffle from 'lodash/shuffle'; import { enhancedQuizManagementStrings } from 'kolibri-common/strings/enhancedQuizManagementStrings'; @@ -16,6 +17,10 @@ import { Quiz, QuizSection, QuizQuestion, QuizExercise } from './quizCreationSpe const logger = logging.getLogger(__filename); +function uuidv4() { + return v4().replace(/-/g, ''); +} + /** Validators **/ /* objectSpecs expects every property to be available -- but we don't want to have to make an * object with every property just to validate it. So we use these functions to validate subsets @@ -271,10 +276,8 @@ export default function useQuizCreation(DEBUG = false) { // // Method to initialize the working resource pool function initializeWorkingResourcePool() { - // Get the active section - const currentActiveResourcePool = get(activeResourcePool); // Set the value of _working_resource_pool to the resource_pool of the active section - set(_working_resource_pool, currentActiveResourcePool); + set(_working_resource_pool, get(activeResourcePool)); } /** @@ -466,28 +469,33 @@ export default function useQuizCreation(DEBUG = false) { }); /** - * Adds resources to _working_resource_pool + * @param {QuizExercise[]} resources + * @affects _working_resource_pool -- Updates it with the given resources and is ensured to have + * a list of unique resources to avoid unnecessary duplication */ function addToWorkingResourcePool(resources = []) { - set(_working_resource_pool, [...get(_working_resource_pool), ...resources]); + set(_working_resource_pool, uniqWith([...get(_working_resource_pool), ...resources], isEqual)); } /** + * @param {QuizExercise} content + * @affects _working_resource_pool - Remove given quiz exercise from _working_resource_pool + */ + function removeFromWorkingResourcePool(content) { + set( + _working_resource_pool, + _working_resource_pool.value.filter(obj => obj.id !== content.id) + ); + } + + /** + * @param {QuizExercise} content * Check if the content is present in working_resource_pool */ function contentPresentInWorkingResourcePool(content) { const workingResourceIds = get(workingResourcePool).map(wr => wr.id); return workingResourceIds.includes(content.id); } - /** - * Remove resource with the given id from _working_resource_pool - */ - function removeFromWorkingResourcePool(id) { - set( - _working_resource_pool, - _working_resource_pool.value.filter(obj => obj.id !== id) - ); - } /** @type {ComputedRef} Whether the select all checkbox should be indeterminate */ const selectAllIsIndeterminate = computed(() => { 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 424747122d3..c382bf84824 100644 --- a/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/ResourceSelection.vue +++ b/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/ResourceSelection.vue @@ -114,7 +114,6 @@ const route = computed(() => store.state.route); const topicId = computed(() => route.value.params.topic_id); const { - saveQuiz, updateSection, activeSection, selectAllQuestions, @@ -251,7 +250,6 @@ viewMoreButtonState, updateSection, activeSection, - saveQuiz, selectAllQuestions, workingResourcePool, addToWorkingResourcePool, @@ -269,12 +267,13 @@ return this.$route.params.topic_id; }, isSelectAllChecked() { - //if all the reosurces in contentList are present in working_resource_pool - // Then return true else false + // Returns true if all the resources in the topic are in the working resource pool const workingResourceIds = this.workingResourcePool.map(wr => wr.id); return this.contentList.every(content => workingResourceIds.includes(content.id)); }, selectAllIndeterminate() { + // Returns true if some, but not all, of the resources in the topic are in the working + // resource const workingResourceIds = this.workingResourcePool.map(wr => wr.id); return ( !this.isSelectAllChecked && @@ -305,17 +304,6 @@ // }; }, - // contentIsInLesson() { - // return ({ id }) => Boolean(this.channels); - // }, - // addableContent() { - // // Content in the topic that can be added if 'Select All' is clicked - // const list = this.contentList.value ? this.contentList.value : this.bookmarksList; - // return list.filter( - // content => !this.contentIsDirectoryKind(content) && !this.contentIsInLesson(content) - // ); - // }, - getBookmarksLink() { return { name: PageNames.BOOK_MARKED_RESOURCES, @@ -359,22 +347,16 @@ return {}; // or return {} if you prefer an empty object }, - // saveResources() { - // this.saveQuiz(); - // }, toggleSelected({ content, checked }) { if (checked) { this.addToSelectedResources(content); } else { - this.removeFromSelectedResources(content.id); + this.removeFromWorkingResourcePool(content); } }, addToSelectedResources(content) { this.addToWorkingResourcePool([content]); }, - removeFromSelectedResources(id) { - this.removeFromWorkingResourcePool(id); - }, toggleTopicInWorkingResources(isChecked) { if (isChecked) { this.isSelectAllChecked = true; @@ -421,40 +403,6 @@ // } // return ''; // }, - /* - handleSearchTerm(searchTerm) { - const query = { - last_id: this.$route.query.last_id || this.$route.params.topicId, - }; - const lastPage = this.$route.query.last; - if (lastPage) { - query.last = lastPage; - } - this.$router.push({ - name: LessonsPageNames.SELECTION_SEARCH, - params: { - searchTerm, - }, - query, - }); - }, - handleMoreResults() { - this.moreResultsState = 'waiting'; - this.fetchAdditionalSearchResults({ - searchTerm: this.searchTerm, - kind: this.filters.kind, - channelId: this.filters.channel, - currentResults: this.searchResults.results, - }) - .then(() => { - this.moreResultsState = null; - this.moreResultsState; - }) - .catch(() => { - this.moreResultsState = 'error'; - }); - }, - */ }, }; 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 f9ca65cfc88..53bc6e0202d 100644 --- a/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/SectionSidePanel.vue +++ b/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/SectionSidePanel.vue @@ -15,6 +15,7 @@ diff --git a/kolibri/plugins/coach/assets/src/views/plan/LessonResourceSelectionPage/ContentCardList.vue b/kolibri/plugins/coach/assets/src/views/plan/LessonResourceSelectionPage/ContentCardList.vue index 398e7471c2c..fe321cfb272 100644 --- a/kolibri/plugins/coach/assets/src/views/plan/LessonResourceSelectionPage/ContentCardList.vue +++ b/kolibri/plugins/coach/assets/src/views/plan/LessonResourceSelectionPage/ContentCardList.vue @@ -65,7 +65,6 @@