From 6811861729fbefafe6b2b74c485231fb4f4fadbb Mon Sep 17 00:00:00 2001 From: Benjamin Degenhart Date: Thu, 23 May 2024 22:09:45 +0200 Subject: [PATCH] Add user profile validation at start and at change --- public/index.html | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/public/index.html b/public/index.html index 2c9ca9a..7ccfcd0 100644 --- a/public/index.html +++ b/public/index.html @@ -336,12 +336,27 @@

Report

} async function finalizeProfileChanges() { - // profile validation / maybe materialization suggestions too? TODO + if (!await validateUserProfile()) return + + // materialization suggestions too? TODO + console.log("userProfile", userProfile) localStorage.setItem("userProfile", JSON.stringify(userProfile)) await update() } + async function validateUserProfile() { + let userProfileTurtle = await MatchingEngine.convertUserProfileToTurtle(userProfile) + let report = await MatchingEngine.validateUserProfile(userProfileTurtle, turtleMap.datafields) + if (!report.conforms) { + console.log("User profile validation violations:", report.violations) + // pretty print violations TODO + alert("Your profile is not valid: " + JSON.stringify(report.violations)) + return false + } + return true + } + function searchSubjectNodeRecursively(node, sKey, action) { if (node["@id"] === sKey) { action(node) @@ -418,14 +433,16 @@

Report

} async function run() { + latestRPsRepoCommit = await fetchAsset("latest-rps-repo-commit.txt") + setInterval(checkForNewRepoCommits, 60 * 1000) + await parseTurtleFiles() + if (localStorage.getItem("userProfile") === null) { localStorage.setItem("userProfile", JSON.stringify(EMPTY_PROFILE)) } userProfile = JSON.parse(localStorage.getItem("userProfile")) - latestRPsRepoCommit = await fetchAsset("latest-rps-repo-commit.txt") - await parseTurtleFiles() + if (!await validateUserProfile()) return await update() - setInterval(checkForNewRepoCommits, 60 * 1000) } run()