Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for 11783 #1

Merged
38 changes: 23 additions & 15 deletions kolibri/plugins/coach/assets/src/composables/useQuizCreation.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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
Expand Down Expand Up @@ -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));
}

/**
Expand Down Expand Up @@ -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<Boolean>} Whether the select all checkbox should be indeterminate */
const selectAllIsIndeterminate = computed(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@
const route = computed(() => store.state.route);
const topicId = computed(() => route.value.params.topic_id);
const {
saveQuiz,
updateSection,
activeSection,
selectAllQuestions,
Expand Down Expand Up @@ -251,7 +250,6 @@
viewMoreButtonState,
updateSection,
activeSection,
saveQuiz,
selectAllQuestions,
workingResourcePool,
addToWorkingResourcePool,
Expand All @@ -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 &&
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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';
});
},
*/
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<ConfirmCancellationModal
v-if="showConfirmationModal"
:closePanelRoute="closePanelRoute"
@cancel="showConfirmationModal = false"
/>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
<script>

import commonCoreStrings from 'kolibri.coreVue.mixins.commonCoreStrings';
import { injectQuizCreation } from '../../../composables/useQuizCreation';
import LessonContentCard from './LessonContentCard';

export default {
Expand All @@ -74,18 +73,6 @@
LessonContentCard,
},
mixins: [commonCoreStrings],
setup() {
const {
//Computed
addToWorkingResourcePool,
removeFromWorkingResourcePool,
} = injectQuizCreation();

return {
addToWorkingResourcePool,
removeFromWorkingResourcePool,
};
},
props: {
showSelectAll: {
type: Boolean,
Expand All @@ -112,7 +99,6 @@
type: Function, // ContentNode => Boolean
required: true,
},

// Function that returns true if content item checkbox is indeterminate
contentIsIndeterminate: {
type: Function, // ContentNode => Boolean
Expand Down