Skip to content

Commit

Permalink
Show number of unused questions in exercises
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexVelezLl committed Jan 30, 2025
1 parent 1442ad9 commit c0a33a3
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
:contentHasCheckbox="showCheckbox"
:contentCheckboxDisabled="contentCheckboxDisabled"
:contentCardLink="contentLink"
:contentCardMessage="contentCardMessage"
:showRadioButtons="!multi"
@changeselectall="handleSelectAll"
@change_content_card="toggleSelected"
Expand Down Expand Up @@ -105,6 +106,15 @@
type: Boolean,
default: false,
},
/**
* Function that returns a message to be displayed based in the content
* passed as argument.
*/
contentCardMessage: {
type: Function,
required: false,
default: () => '',
},
},
computed: {
selectAllIndeterminate() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
:selectionRules="selectionRules"
:selectAllRules="selectAllRules"
:selectedResources="selectedResources"
:contentCardMessage="contentCardMessage"
:noSelectableResourcesIds="noSelectableResourcesIds"
@selectResources="$emit('selectResources', $event)"
@deselectResources="$emit('deselectResources', $event)"
Expand All @@ -30,6 +31,7 @@
<script>
import { getCurrentInstance } from 'vue';
import { now } from 'kolibri/utils/serverClock';
import { coreStrings } from 'kolibri/uiText/commonCoreStrings';
import UpdatedResourceSelection from '../UpdatedResourceSelection.vue';
import { PageNames } from '../../../../constants';
Expand All @@ -47,7 +49,7 @@
QuizResourceSelectionHeader,
},
setup(props) {
const { selectFromBookmarks$ } = coreStrings;
const { selectFromBookmarks$, bookmarkedTimeAgoLabel$ } = coreStrings;
const instance = getCurrentInstance();
props.setTitle(selectFromBookmarks$());
Expand All @@ -70,12 +72,24 @@
};
const { data, hasMore, fetchMore, loadingMore } = props.bookmarksFetch;
const contentCardMessage = content => {
if (!content.bookmark?.created) {
return null;
}
const createdDate = new Date(content.bookmark.created);
const time = instance.proxy.$formatRelative(createdDate, { now: now() });
return bookmarkedTimeAgoLabel$({ time });
};
return {
channelsLink,
contentList: data,
hasMore,
fetchMore,
loadingMore,
contentCardMessage,
SelectionTarget,
};
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
:selectionRules="selectionRules"
:selectAllRules="selectAllRules"
:selectedResources="selectedResources"
:contentCardMessage="contentCardMessage"
:unselectableResourceIds="unselectableResourceIds"
@selectResources="$emit('selectResources', $event)"
@deselectResources="$emit('deselectResources', $event)"
Expand Down Expand Up @@ -192,6 +193,15 @@
required: false,
default: null,
},
/**
* Function that returns a message to be displayed based in the content
* passed as argument.
*/
contentCardMessage: {
type: Function,
required: false,
default: () => '',
},
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
:selectionRules="selectionRules"
:settings.sync="settings"
:target="SelectionTarget.QUIZ"
:getUnusedQuestionsMessage="getUnusedQuestionsMessage"
:contentCardMessage="contentCardMessage"
@selectResources="addToWorkingResourcePool"
@deselectResources="removeFromWorkingResourcePool"
@setSelectedResources="setWorkingResourcePool"
Expand All @@ -72,8 +72,9 @@
<div class="bottom-nav-container">
<KButton
v-if="continueAction"
:disabled="continueAction.disabled"
:text="coreString('continueAction')"
@click="continueAction"
@click="continueAction.handler"
/>
<template v-else>
<div v-if="!selectPracticeQuiz">
Expand Down Expand Up @@ -339,7 +340,7 @@
const selectionRules = computed(() => [() => remainingSelectableContent.value > 0]);
const maximumContentSelectedWarning = computed(() => {
if (remainingSelectableContent.value > 0) {
if (settings.value.questionCount <= 0 || remainingSelectableContent.value > 0) {
return null;
}
if (settings.value.isChoosingManually) {
Expand Down Expand Up @@ -442,10 +443,13 @@
});
},
// The message put onto the content's card when listed
getUnusedQuestionsMessage(content) {
contentCardMessage(content) {
if (this.selectPracticeQuiz) {
return;
}
if (content.kind !== ContentNodeKinds.EXERCISE) {
return;
}
const count = this.unusedQuestionsCount(content);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@

<script>
import { ref, computed, getCurrentInstance, onMounted, onUnmounted } from 'vue';
import { ref, computed, getCurrentInstance, onMounted, onUnmounted, watch } from 'vue';
import {
displaySectionTitle,
enhancedQuizManagementStrings,
Expand Down Expand Up @@ -81,6 +81,12 @@
} = enhancedQuizManagementStrings;
const { activeSection, activeSectionIndex } = injectQuizCreation();
const invalidSettings = computed(
() =>
props.settings.questionCount > props.settings.maxQuestions ||
props.settings.questionCount < 1,
);
const questionCount = computed({
get: () => props.settings.questionCount,
set: value => {
Expand All @@ -97,17 +103,30 @@
}),
);
props.setGoBack(null);
const continueHandler = () => {
if (!props.isLanding && prevRoute.value) {
instance.proxy.$router.push(prevRoute.value);
return;
}
instance.proxy.$router.push({
name: PageNames.QUIZ_SELECT_RESOURCES_INDEX,
});
};
onMounted(() => {
props.setContinueAction(() => {
if (!props.isLanding && prevRoute.value) {
instance.proxy.$router.push(prevRoute.value);
return;
}
instance.proxy.$router.push({
name: PageNames.QUIZ_SELECT_RESOURCES_INDEX,
});
props.setContinueAction({
handler: continueHandler,
});
});
watch(
() => props.settings,
() => {
props.setContinueAction({
handler: continueHandler,
disabled: invalidSettings.value,
});
},
);
onUnmounted(() => {
props.setContinueAction(null);
});
Expand Down

0 comments on commit c0a33a3

Please sign in to comment.