Skip to content
This repository has been archived by the owner on Sep 4, 2024. It is now read-only.

Commit

Permalink
Add user profile validation at start and at change
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminaaron committed May 23, 2024
1 parent 01e27ee commit 6811861
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -336,12 +336,27 @@ <h3>Report</h3>
}

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)
Expand Down Expand Up @@ -418,14 +433,16 @@ <h3>Report</h3>
}

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()
Expand Down

0 comments on commit 6811861

Please sign in to comment.