Refer to server docs for Puzzle fields

This commit is contained in:
Neale Pickett 2023-09-07 17:29:21 -06:00
parent 47671b9a12
commit 8ff91e79ec
3 changed files with 59 additions and 87 deletions

View File

@ -37,23 +37,45 @@ type PuzzleDebug struct {
Summary string Summary string
} }
// Puzzle contains everything about a puzzle that a client would see. // Puzzle contains everything about a puzzle that a client will see.
type Puzzle struct { type Puzzle struct {
Debug PuzzleDebug // Debug contains debugging information, omitted in mothballs
Authors []string Debug PuzzleDebug
Attachments []string
Scripts []string // Authors names all authors of this puzzle
Body string Authors []string
// Attachments is a list of filenames used by this puzzle
Attachments []string
// Scripts is a list of EMCAScript files needed by the client for this puzzle
Scripts []string
// Body is the HTML rendering of this puzzle
Body string
// AnswerPattern contains the pattern (regular expression?) used to match valid answers
AnswerPattern string AnswerPattern string
AnswerHashes []string
Objective string // AnswerHashes contains hashes of all answers for this puzzle
KSAs []string AnswerHashes []string
Success struct {
// Objective is the learning objective for this puzzle
Objective string
// KSAs lists all KSAs achieved upon successfull completion of this puzzle
KSAs []string
// Success lists the criteria for successfully understanding this puzzle
Success struct {
// Acceptable describes the minimum work required to be considered successfully understanding this puzzle's concepts
Acceptable string Acceptable string
Mastery string
// Mastery describes the work required to be considered mastering this puzzle's conceptss
Mastery string
} }
// Answers will be empty in a mothball // Answers lists all acceptable answers, omitted in mothballs
Answers []string Answers []string
} }

View File

@ -26,11 +26,14 @@ class Award {
* A puzzle. * A puzzle.
* *
* A new Puzzle only knows its category and point value. * A new Puzzle only knows its category and point value.
* If you want to populate it with meta-information, you must call Get(). * If you want to populate it with meta-information, you must call Populate().
*
* Parameters created by Populate are described in the server source code:
* {@link https://pkg.go.dev/github.com/dirtbags/moth/v4/pkg/transpile#Puzzle}
*
*/ */
class Puzzle { class Puzzle {
/** /**
*
* @param {Server} server * @param {Server} server
* @param {String} category * @param {String} category
* @param {Number} points * @param {Number} points
@ -44,71 +47,22 @@ class Puzzle {
* @type {Server} * @type {Server}
*/ */
this.server = server this.server = server
/** Category this puzzle belongs to
* @type {String} /** Category this puzzle belongs to */
*/ this.Category = String(category)
this.Category = category
/** Point value of this puzzle /** Point value of this puzzle */
* @type {Number} this.Points = Number(points)
*/
this.Points = points
}
/** Error returned trying to fetch this puzzle */ /** Error returned trying to fetch this puzzle */
Error = { this.Error = {
/** Status code provided by server */ /** Status code provided by server */
Status: 0, Status: 0,
/** Status text provided by server */ /** Status text provided by server */
StatusText: "", StatusText: "",
/** Full text of server error */ /** Full text of server error */
Body: "", Body: "",
} }
/** Hashes of answers
* @type {String[]}
*/
AnswerHashes = []
/** Pattern that answer should match
* @type {String[]}
*/
AnswerPattern = ""
/** Accepted answers
* @type {String[]}
*/
Answers = []
/** Other files attached to this puzzles
* @type {String[]}
*/
Attachments = []
/** This puzzle's authors
* @type {String[]}
*/
Authors = []
/** HTML body of this puzzle */
Body = ""
/** Debugging information */
Debug = {
Errors: [],
Hints: [],
Log: [],
Notes: "",
Summary: "",
}
/** KSAs met by solving this puzzle
* @type {String[]}
*/
KSAs = []
/** Learning objective for this puzzle */
Objective = ""
/** ECMAScript scripts needed for this puzzle
* @type {String[]}
*/
Scripts = []
/** Criteria for succeeding at this puzzle */
Success = {
/** Acceptable Minimum criteria for success */
Minimum: "",
/** Criteria for demonstrating mastery of this puzzle */
Mastery: "",
} }
/** /**

View File

@ -20,19 +20,15 @@ async function init() {
let state = await server.GetState() let state = await server.GetState()
doing("Retrieving all puzzles") doing("Retrieving all puzzles")
let puzzles = state.Puzzles()
for (let p of puzzles) {
await p.Populate().catch(x => {})
}
doing("Filling table")
let puzzlerowTemplate = document.querySelector("template#puzzlerow") let puzzlerowTemplate = document.querySelector("template#puzzlerow")
for (let tbody of document.querySelectorAll("tbody")) { let puzzles = state.Puzzles()
for (let puzzle of puzzles) { for (let puzzle of puzzles) {
await puzzle.Populate().catch(x => {})
for (let tbody of document.querySelectorAll("tbody")) {
let row = puzzlerowTemplate.content.cloneNode(true) let row = puzzlerowTemplate.content.cloneNode(true)
row.querySelector(".category").textContent = puzzle.Category row.querySelector(".category").textContent = puzzle.Category
row.querySelector(".points").textContent = puzzle.Points row.querySelector(".points").textContent = puzzle.Points
row.querySelector(".ksas").textContent = puzzle.KSAs.join(" ") row.querySelector(".ksas").textContent = (puzzle.KSAs || []).join(" ")
row.querySelector(".error").textContent = puzzle.Error.Body row.querySelector(".error").textContent = puzzle.Error.Body
tbody.appendChild(row) tbody.appendChild(row)
} }