Merge remote-tracking branch 'origin/dev' into feat/endpoints-in-backend-om-eigen-leerpaden-en-leerobjecten-toe-te-voegen-aan-de-databank-#248
This commit is contained in:
commit
ebc4c16c89
7 changed files with 67 additions and 15 deletions
|
@ -4,7 +4,7 @@ import { getLearningPathRepository } from '../../data/repositories.js';
|
||||||
import learningObjectService from '../learning-objects/learning-object-service.js';
|
import learningObjectService from '../learning-objects/learning-object-service.js';
|
||||||
import { LearningPathNode } from '../../entities/content/learning-path-node.entity.js';
|
import { LearningPathNode } from '../../entities/content/learning-path-node.entity.js';
|
||||||
import { LearningPathTransition } from '../../entities/content/learning-path-transition.entity.js';
|
import { LearningPathTransition } from '../../entities/content/learning-path-transition.entity.js';
|
||||||
import { getLastSubmissionForGroup, isTransitionPossible } from './learning-path-personalization-util.js';
|
import { getLastSubmissionForGroup, idFromLearningPathNode, isTransitionPossible } from './learning-path-personalization-util.js';
|
||||||
import {
|
import {
|
||||||
FilteredLearningObject,
|
FilteredLearningObject,
|
||||||
LearningObjectNode,
|
LearningObjectNode,
|
||||||
|
@ -103,7 +103,7 @@ async function convertNode(
|
||||||
personalizedFor: Group | undefined,
|
personalizedFor: Group | undefined,
|
||||||
nodesToLearningObjects: Map<LearningPathNode, FilteredLearningObject>
|
nodesToLearningObjects: Map<LearningPathNode, FilteredLearningObject>
|
||||||
): Promise<LearningObjectNode> {
|
): Promise<LearningObjectNode> {
|
||||||
const lastSubmission = personalizedFor ? await getLastSubmissionForGroup(node, personalizedFor) : null;
|
const lastSubmission = personalizedFor ? await getLastSubmissionForGroup(idFromLearningPathNode(node), personalizedFor) : null;
|
||||||
const transitions = node.transitions
|
const transitions = node.transitions
|
||||||
.filter(
|
.filter(
|
||||||
(trans) =>
|
(trans) =>
|
||||||
|
|
|
@ -3,11 +3,33 @@ import { DWENGO_API_BASE } from '../../config.js';
|
||||||
import { LearningPathProvider } from './learning-path-provider.js';
|
import { LearningPathProvider } from './learning-path-provider.js';
|
||||||
import { getLogger, Logger } from '../../logging/initalize.js';
|
import { getLogger, Logger } from '../../logging/initalize.js';
|
||||||
import { LearningPath, LearningPathResponse } from '@dwengo-1/common/interfaces/learning-content';
|
import { LearningPath, LearningPathResponse } from '@dwengo-1/common/interfaces/learning-content';
|
||||||
|
import { Group } from '../../entities/assignments/group.entity.js';
|
||||||
|
import { getLastSubmissionForGroup, idFromLearningObjectNode } from './learning-path-personalization-util.js';
|
||||||
|
|
||||||
const logger: Logger = getLogger();
|
const logger: Logger = getLogger();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds progress information to the learning path. Modifies the learning path in-place.
|
||||||
|
* @param learningPath The learning path to add progress to.
|
||||||
|
* @param personalizedFor The group whose progress should be shown.
|
||||||
|
* @returns the modified learning path.
|
||||||
|
*/
|
||||||
|
async function addProgressToLearningPath(learningPath: LearningPath, personalizedFor: Group): Promise<LearningPath> {
|
||||||
|
await Promise.all(
|
||||||
|
learningPath.nodes.map(async (node) => {
|
||||||
|
const lastSubmission = personalizedFor ? await getLastSubmissionForGroup(idFromLearningObjectNode(node), personalizedFor) : null;
|
||||||
|
node.done = Boolean(lastSubmission);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
learningPath.num_nodes = learningPath.nodes.length;
|
||||||
|
learningPath.num_nodes_left = learningPath.nodes.filter((it) => !it.done).length;
|
||||||
|
|
||||||
|
return learningPath;
|
||||||
|
}
|
||||||
|
|
||||||
const dwengoApiLearningPathProvider: LearningPathProvider = {
|
const dwengoApiLearningPathProvider: LearningPathProvider = {
|
||||||
async fetchLearningPaths(hruids: string[], language: string, source: string): Promise<LearningPathResponse> {
|
async fetchLearningPaths(hruids: string[], language: string, source: string, personalizedFor: Group): Promise<LearningPathResponse> {
|
||||||
if (hruids.length === 0) {
|
if (hruids.length === 0) {
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
|
@ -32,17 +54,24 @@ const dwengoApiLearningPathProvider: LearningPathProvider = {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await Promise.all(learningPaths?.map(async (it) => addProgressToLearningPath(it, personalizedFor)));
|
||||||
|
|
||||||
return {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
source,
|
source,
|
||||||
data: learningPaths,
|
data: learningPaths,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
async searchLearningPaths(query: string, language: string): Promise<LearningPath[]> {
|
async searchLearningPaths(query: string, language: string, personalizedFor: Group): Promise<LearningPath[]> {
|
||||||
const apiUrl = `${DWENGO_API_BASE}/learningPath/search`;
|
const apiUrl = `${DWENGO_API_BASE}/learningPath/search`;
|
||||||
const params = { all: query, language };
|
const params = { all: query, language };
|
||||||
|
|
||||||
const searchResults = await fetchWithLogging<LearningPath[]>(apiUrl, `Search learning paths with query "${query}"`, { params });
|
const searchResults = await fetchWithLogging<LearningPath[]>(apiUrl, `Search learning paths with query "${query}"`, { params });
|
||||||
|
|
||||||
|
if (searchResults) {
|
||||||
|
await Promise.all(searchResults?.map(async (it) => addProgressToLearningPath(it, personalizedFor)));
|
||||||
|
}
|
||||||
|
|
||||||
return searchResults ?? [];
|
return searchResults ?? [];
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -5,18 +5,36 @@ import { getSubmissionRepository } from '../../data/repositories.js';
|
||||||
import { LearningObjectIdentifier } from '../../entities/content/learning-object-identifier.js';
|
import { LearningObjectIdentifier } from '../../entities/content/learning-object-identifier.js';
|
||||||
import { LearningPathTransition } from '../../entities/content/learning-path-transition.entity.js';
|
import { LearningPathTransition } from '../../entities/content/learning-path-transition.entity.js';
|
||||||
import { JSONPath } from 'jsonpath-plus';
|
import { JSONPath } from 'jsonpath-plus';
|
||||||
|
import { LearningObjectNode } from '@dwengo-1/common/interfaces/learning-content';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the last submission for the learning object associated with the given node and for the group
|
* Returns the last submission for the learning object associated with the given node and for the group
|
||||||
*/
|
*/
|
||||||
export async function getLastSubmissionForGroup(node: LearningPathNode, pathFor: Group): Promise<Submission | null> {
|
export async function getLastSubmissionForGroup(learningObjectId: LearningObjectIdentifier, pathFor: Group): Promise<Submission | null> {
|
||||||
const submissionRepo = getSubmissionRepository();
|
const submissionRepo = getSubmissionRepository();
|
||||||
const learningObjectId: LearningObjectIdentifier = {
|
return await submissionRepo.findMostRecentSubmissionForGroup(learningObjectId, pathFor);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a LearningObjectIdentifier describing the specified node.
|
||||||
|
*/
|
||||||
|
export function idFromLearningObjectNode(node: LearningObjectNode): LearningObjectIdentifier {
|
||||||
|
return {
|
||||||
|
hruid: node.learningobject_hruid,
|
||||||
|
language: node.language,
|
||||||
|
version: node.version,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a LearningObjectIdentifier describing the specified node.
|
||||||
|
*/
|
||||||
|
export function idFromLearningPathNode(node: LearningPathNode): LearningObjectIdentifier {
|
||||||
|
return {
|
||||||
hruid: node.learningObjectHruid,
|
hruid: node.learningObjectHruid,
|
||||||
language: node.language,
|
language: node.language,
|
||||||
version: node.version,
|
version: node.version,
|
||||||
};
|
};
|
||||||
return await submissionRepo.findMostRecentSubmissionForGroup(learningObjectId, pathFor);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -29,8 +29,8 @@ export class LearningPathController extends BaseController {
|
||||||
}
|
}
|
||||||
return LearningPath.fromDTO(dtos[0]);
|
return LearningPath.fromDTO(dtos[0]);
|
||||||
}
|
}
|
||||||
async getAllByTheme(theme: string): Promise<LearningPath[]> {
|
async getAllByThemeAndLanguage(theme: string, language: Language): Promise<LearningPath[]> {
|
||||||
const dtos = await this.get<LearningPathDTO[]>("/", { theme });
|
const dtos = await this.get<LearningPathDTO[]>("/", { theme, language });
|
||||||
return dtos.map((dto) => LearningPath.fromDTO(dto));
|
return dtos.map((dto) => LearningPath.fromDTO(dto));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,12 +30,13 @@ export function useGetLearningPathQuery(
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useGetAllLearningPathsByThemeQuery(
|
export function useGetAllLearningPathsByThemeAndLanguageQuery(
|
||||||
theme: MaybeRefOrGetter<string>,
|
theme: MaybeRefOrGetter<string>,
|
||||||
|
language: MaybeRefOrGetter<Language>,
|
||||||
): UseQueryReturnType<LearningPath[], Error> {
|
): UseQueryReturnType<LearningPath[], Error> {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: [LEARNING_PATH_KEY, "getAllByTheme", theme],
|
queryKey: [LEARNING_PATH_KEY, "getAllByTheme", theme, language],
|
||||||
queryFn: async () => learningPathController.getAllByTheme(toValue(theme)),
|
queryFn: async () => learningPathController.getAllByThemeAndLanguage(toValue(theme), toValue(language)),
|
||||||
enabled: () => Boolean(toValue(theme)),
|
enabled: () => Boolean(toValue(theme)),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,10 +2,11 @@
|
||||||
import type { LearningPath } from "@/data-objects/learning-paths/learning-path.ts";
|
import type { LearningPath } from "@/data-objects/learning-paths/learning-path.ts";
|
||||||
import LearningPathsGrid from "@/components/LearningPathsGrid.vue";
|
import LearningPathsGrid from "@/components/LearningPathsGrid.vue";
|
||||||
import UsingQueryResult from "@/components/UsingQueryResult.vue";
|
import UsingQueryResult from "@/components/UsingQueryResult.vue";
|
||||||
import { useGetAllLearningPathsByThemeQuery } from "@/queries/learning-paths.ts";
|
import { useGetAllLearningPathsByThemeAndLanguageQuery } from "@/queries/learning-paths.ts";
|
||||||
import { computed, ref } from "vue";
|
import { computed, ref } from "vue";
|
||||||
import { useI18n } from "vue-i18n";
|
import { useI18n } from "vue-i18n";
|
||||||
import { useThemeQuery } from "@/queries/themes.ts";
|
import { useThemeQuery } from "@/queries/themes.ts";
|
||||||
|
import type { Language } from "@/data-objects/language";
|
||||||
|
|
||||||
const props = defineProps<{ theme: string }>();
|
const props = defineProps<{ theme: string }>();
|
||||||
|
|
||||||
|
@ -16,7 +17,10 @@
|
||||||
|
|
||||||
const currentThemeInfo = computed(() => themeQueryResult.data.value?.find((it) => it.key === props.theme));
|
const currentThemeInfo = computed(() => themeQueryResult.data.value?.find((it) => it.key === props.theme));
|
||||||
|
|
||||||
const learningPathsForThemeQueryResult = useGetAllLearningPathsByThemeQuery(() => props.theme);
|
const learningPathsForThemeQueryResult = useGetAllLearningPathsByThemeAndLanguageQuery(
|
||||||
|
() => props.theme,
|
||||||
|
() => locale.value as Language,
|
||||||
|
);
|
||||||
|
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
const searchFilter = ref("");
|
const searchFilter = ref("");
|
||||||
|
|
|
@ -15,7 +15,7 @@ describe("Test controller learning paths", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Can get learning path by id", async () => {
|
it("Can get learning path by id", async () => {
|
||||||
const data = await controller.getAllByTheme("kiks");
|
const data = await controller.getAllByThemeAndLanguage("kiks", Language.Dutch);
|
||||||
expect(data).to.have.length.greaterThan(0);
|
expect(data).to.have.length.greaterThan(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue