change up the schema a little bit

This commit is contained in:
Michael Zhang 2021-08-29 02:59:56 -05:00
parent dded1c1c2d
commit b3917dc756
Signed by: michael
GPG key ID: BDA47A31A3C8EE6B
9 changed files with 63 additions and 11 deletions

View file

@ -11,8 +11,6 @@ exercises:
description: |
Which of the following can be described as a _function_?
graders:
ocaml:
style: multipleChoice
props:
foo: bar
choices:
- foo: bar

View file

@ -41,8 +41,6 @@ exercises:
concepts:
- fp-function
graders:
ocaml:
style: multipleChoice
props:
foo: bar
choices:
- foo: bar

View file

@ -22,6 +22,15 @@ export class Exercise extends Model {
@Column(DataType.STRING)
public name: string;
@Column(DataType.STRING)
public description: string;
@Column(DataType.STRING)
public style: string;
@Column(DataType.JSON)
public props: any;
@HasMany(() => Grader)
public graders: Grader[];
}

View file

@ -42,6 +42,9 @@ async function loadPageIntoDb(name: string): Promise<void> {
let exercise = new Exercise({
page_slug: slug,
name: ex_cfg.name,
style: ex_cfg.style,
props: ex_cfg.props,
description: ex_cfg.description,
});
await exercise.save();

View file

@ -9,7 +9,9 @@ export class Page {
export class Exercise {
public name: string;
public style: string;
public description: string;
public props: any;
public graders?: Grader[];
};

View file

@ -1,5 +1,20 @@
<script lang="ts">
import MultipleChoice from "$lib/exercise/MultipleChoice.svelte";
import Exercise from "$lib/exercise/Exercise.svelte";
let state = "loading";
let exercise = null;
(async function() {
let resp = await fetch("/api/recommendExercise");
let body = await resp.json();
exercise = body.exercise;
state = "finished";
})();
</script>
<MultipleChoice />
{#if state == "loading"}
loading...
{:else}
<Exercise exercise={exercise} />
{/if}

View file

@ -0,0 +1,14 @@
<script lang="ts">
import MultipleChoice from "./MultipleChoice.svelte";
export let exercise;
</script>
{JSON.stringify(exercise)}
{exercise.style}
{#if !exercise}
loading
{:else if exercise.style == "multipleChoice"}
<MultipleChoice />
{/if}

View file

@ -0,0 +1,9 @@
// mask the full exercise object to only the part that the client needs to see
// in order to present it to the user (so the user can't just peek into network
// transactions to see what the correct answer is)
import type { Exercise } from "materialdb/db";
export async function maskExercise(exercise: Exercise): Promise<any> {
return {};
}

View file

@ -60,6 +60,10 @@
.content-wrap {
border-top: 10px solid #c00;
padding-bottom: $footer-height;
> .container {
padding-bottom: 36px;
}
}
}