Skip to content

Commit

Permalink
Merge pull request #1 from ozer550/add-working-resource-pool-logic
Browse files Browse the repository at this point in the history
Add working resource pool logic
  • Loading branch information
AllanOXDi authored Jan 23, 2024
2 parents a44adac + c696280 commit bc0b264
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 20 deletions.
61 changes: 61 additions & 0 deletions kolibri/plugins/coach/assets/src/composables/useQuizCreation.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ export default function useQuizCreation(DEBUG = false) {
// Local state
// -----------

/** @type {ComputedRef<QuizExercise[]>} Currently selected resource_pool
* from the side_panel*/
const _working_resource_pool = ref([]);

/** @type {ref<Quiz>}
* The "source of truth" quiz object from which all reactive properties should derive */
const _quiz = ref(objectWithDefaults({}, Quiz));
Expand Down Expand Up @@ -265,6 +269,14 @@ export default function useQuizCreation(DEBUG = false) {
_fetchChannels();
}

// // 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);
}

/**
* @returns {Promise<Quiz>}
* @throws {Error} if quiz is not valid
Expand Down Expand Up @@ -337,6 +349,11 @@ export default function useQuizCreation(DEBUG = false) {
}
}

function resetWorkingResourcePool() {
// Set the WorkingResource to empty array again!
set(_working_resource_pool, []);
}

/**
* @affects _channels - Fetches all channels with exercises and sets them to _channels */
function _fetchChannels() {
Expand Down Expand Up @@ -408,6 +425,9 @@ export default function useQuizCreation(DEBUG = false) {
/** @type {ComputedRef<Array>} A list of all channels available which have exercises */
const channels = computed(() => get(_channels));

// /** @type {ComputedRef<QuizExercise[]>} The current value of _working_resource_pool */
const workingResourcePool = computed(() => get(_working_resource_pool));

/** Handling the Select All Checkbox
* See: remove/toggleQuestionFromSelection() & selectAllQuestions() for more */

Expand Down Expand Up @@ -445,12 +465,32 @@ export default function useQuizCreation(DEBUG = false) {
}
});

/**
* Adds resources to _working_resource_pool
*/
function addToWorkingResourcePool(resources = []) {
set(_working_resource_pool, [...get(_working_resource_pool), ...resources]);
}

/**
* 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(() => {
return !get(allQuestionsSelected) && !get(noQuestionsSelected);
});

provide('saveQuiz', saveQuiz);
provide('initializeWorkingResourcePool', initializeWorkingResourcePool);
provide('addToWorkingResourcePool', addToWorkingResourcePool);
provide('removeFromWorkingResourcePool', removeFromWorkingResourcePool);
provide('updateSection', updateSection);
provide('replaceSelectedQuestions', replaceSelectedQuestions);
provide('addSection', addSection);
Expand All @@ -460,11 +500,14 @@ export default function useQuizCreation(DEBUG = false) {
provide('updateQuiz', updateQuiz);
provide('addQuestionToSelection', addQuestionToSelection);
provide('removeQuestionFromSelection', removeQuestionFromSelection);
provide('resetWorkingResourcePool', resetWorkingResourcePool);
provide('channels', channels);
provide('quiz', quiz);
provide('allSections', allSections);
provide('activeSection', activeSection);
provide('inactiveSections', inactiveSections);
provide('activeResourcePool', activeResourcePool);
provide('workingResourcePool', workingResourcePool);
provide('activeExercisePool', activeExercisePool);
provide('activeQuestionsPool', activeQuestionsPool);
provide('activeQuestions', activeQuestions);
Expand All @@ -477,8 +520,12 @@ export default function useQuizCreation(DEBUG = false) {
return {
// Methods
saveQuiz,
initializeWorkingResourcePool,
removeFromWorkingResourcePool,
addToWorkingResourcePool,
updateSection,
replaceSelectedQuestions,
resetWorkingResourcePool,
addSection,
removeSection,
setActiveSection,
Expand All @@ -493,6 +540,8 @@ export default function useQuizCreation(DEBUG = false) {
allSections,
activeSection,
inactiveSections,
workingResourcePool,
activeResourcePool,
activeExercisePool,
activeQuestionsPool,
activeQuestions,
Expand All @@ -516,9 +565,13 @@ export default function useQuizCreation(DEBUG = false) {

export function injectQuizCreation() {
const saveQuiz = inject('saveQuiz');
const initializeWorkingResourcePool = inject('initializeWorkingResourcePool');
const removeFromWorkingResourcePool = inject('removeFromWorkingResourcePool');
const addToWorkingResourcePool = inject('addToWorkingResourcePool');
const updateSection = inject('updateSection');
const replaceSelectedQuestions = inject('replaceSelectedQuestions');
const addSection = inject('addSection');
const resetWorkingResourcePool = inject('resetWorkingResourcePool');
const removeSection = inject('removeSection');
const setActiveSection = inject('setActiveSection');
const initializeQuiz = inject('initializeQuiz');
Expand All @@ -530,6 +583,8 @@ export function injectQuizCreation() {
const allSections = inject('allSections');
const activeSection = inject('activeSection');
const inactiveSections = inject('inactiveSections');
const activeResourcePool = inject('activeResourcePool');
const workingResourcePool = inject('workingResourcePool');
const activeExercisePool = inject('activeExercisePool');
const activeQuestionsPool = inject('activeQuestionsPool');
const activeQuestions = inject('activeQuestions');
Expand All @@ -542,9 +597,13 @@ export function injectQuizCreation() {
return {
// Methods
saveQuiz,
initializeWorkingResourcePool,
addToWorkingResourcePool,
removeFromWorkingResourcePool,
deleteActiveSelectedQuestions,
selectAllQuestions,
updateSection,
resetWorkingResourcePool,
replaceSelectedQuestions,
addSection,
removeSection,
Expand All @@ -561,6 +620,8 @@ export function injectQuizCreation() {
allSections,
activeSection,
inactiveSections,
workingResourcePool,
activeResourcePool,
activeExercisePool,
activeQuestionsPool,
activeQuestions,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<template>

<div>
<KModal
title="Are you sure you want to exit ?"
Expand Down Expand Up @@ -29,24 +30,38 @@
appearance="raised-button"
style="width:100%;"
primary
@click="resetWorkingResourcePool"
/>
</KGridItem>
</KGrid>
</template>
</KModal>
</div>

</template>
<script>
import commonCoreStrings from 'kolibri.coreVue.mixins.commonCoreStrings';
import commonCoreStrings from 'kolibri.coreVue.mixins.commonCoreStrings';
import { injectQuizCreation } from '../../../composables/useQuizCreation';
export default {
name:"ConfirmCancellationModal",
export default {
name: 'ConfirmCancellationModal',
mixins: [commonCoreStrings],
setup() {
const {
//Computed
resetWorkingResourcePool,
} = injectQuizCreation();
return {
resetWorkingResourcePool,
};
},
methods: {
closeModal() {
this.$emit('cancel');
},
closeModal() {
this.$emit('cancel');
},
},
}
};
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@
addSection,
removeSection,
setActiveSection,
initializeWorkingResourcePool,
initializeQuiz,
updateQuiz,
addQuestionToSelection,
Expand All @@ -382,6 +383,8 @@
allSections,
activeSection,
inactiveSections,
activeResourcePool,
workingResourcePool,
activeExercisePool,
activeQuestionsPool,
activeQuestions,
Expand Down Expand Up @@ -420,6 +423,7 @@
addSection,
removeSection,
setActiveSection,
initializeWorkingResourcePool,
initializeQuiz,
updateQuiz,
addQuestionToSelection,
Expand All @@ -431,6 +435,8 @@
allSections,
activeSection,
inactiveSections,
workingResourcePool,
activeResourcePool,
activeExercisePool,
activeQuestionsPool,
activeQuestions,
Expand Down Expand Up @@ -558,6 +564,9 @@
set(this.dragActive, true);
},
openSelectResources(section_id) {
//initialize workingResourcePool
this.initializeWorkingResourcePool();
this.$router.replace({ path: 'new/' + section_id + '/select-resources' });
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
:text="coreString('saveChangesAction')"
:primary="true"
:disabled="!hasTopicId()"
@click="isSavingChanges = true"
@click="isSavingChanges = false"
/>
</KGridItem>
</KGrid>
Expand Down Expand Up @@ -118,9 +118,7 @@
const store = getCurrentInstance().proxy.$store;
const route = computed(() => store.state.route);
const topicId = computed(() => route.value.params.topic_id);
const {
saveQuiz
} = injectQuizCreation();
const { saveQuiz } = injectQuizCreation();
const {
sectionSettings$,
Expand Down Expand Up @@ -244,13 +242,13 @@
bookmarks,
channels,
viewMoreButtonState,
saveQuiz
saveQuiz,
};
},
data() {
return {
isSavingChanges:false
}
isSavingChanges: false,
};
},
computed: {
isTopicIdSet() {
Expand Down Expand Up @@ -334,8 +332,8 @@
return {}; // or return {} if you prefer an empty object
},
saveResources(){
this.saveQuiz();
saveResources() {
this.saveQuiz();
},
toggleSelected({ content, checked }) {
if (checked) {
Expand Down Expand Up @@ -366,9 +364,9 @@
topicsLink(topicId) {
return this.topicListingLink({ ...this.$route.params, topicId });
},
hasTopicId(){
hasTopicId() {
return Boolean(this.$route.params.topic_id);
}
},
// selectionMetadata(content) {
// if (content.kind === ContentNodeKinds.TOPIC) {
// const count = content.exercises.filter(exercise =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import SidePanelModal from 'kolibri-common/components/SidePanelModal';
import { PageNames } from '../../../constants';
import ResourceSelectionBreadcrumbs from '../../plan/LessonResourceSelectionPage/SearchTools/ResourceSelectionBreadcrumbs';
import { injectQuizCreation } from '../../../composables/useQuizCreation';
import SectionEditor from './SectionEditor';
import ReplaceQuestions from './ReplaceQuestions';
import ResourceSelection from './ResourceSelection';
Expand All @@ -44,6 +45,16 @@
ResourceSelectionBreadcrumbs,
//ShowBookMarkedResources,
},
setup() {
const {
//Computed
resetWorkingResourcePool,
} = injectQuizCreation();
return {
resetWorkingResourcePool,
};
},
data() {
return {
prevRoute: { name: PageNames.EXAM_CREATION_ROOT },
Expand Down Expand Up @@ -81,6 +92,8 @@
},
methods: {
handleClosePanel() {
this.resetWorkingResourcePool();
this.$emit('closePanel');
this.$router.replace(this.closePanelRoute);
},
Expand All @@ -90,9 +103,9 @@
findFirstEl() {
this.$refs.resourcePanel.focusFirstEl();
},
closingPanel(e){
closingPanel(e) {
console.log(e);
}
},
},
};
Expand Down
Loading

0 comments on commit bc0b264

Please sign in to comment.