Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/app/learnocaml_partition_view.ml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ open Js_utils
open Lwt
open Learnocaml_data
open Learnocaml_common
open Learnocaml_config

module H = Tyxml_js.Html5
module React = Lwt_react
Expand All @@ -35,7 +36,8 @@ let anon_id_map = ref Token.Map.empty
let partition = ref None

let open_tok tok =
let _win = window_open ("/student-view.html?token="^tok) "_blank" in
let _win = window_open (Learnocaml_config.api_server^"/student-view.html?token="^tok) "_blank"
in
false

let rec render_tree =
Expand Down
21 changes: 13 additions & 8 deletions src/state/learnocaml_api.ml
Original file line number Diff line number Diff line change
Expand Up @@ -278,11 +278,13 @@ module Conversions (Json: JSON_CODEC) = struct
let to_http_request
: type resp. resp request -> http_request
=
let get ?token path = {
let get ?(e_arg = []) ?token path = {
meth = `GET;
path;
args = match token with None -> [] | Some t -> ["token", Token.to_string t];
} in
args = match token with
None-> []
|Some t -> [("token", Token.to_string t)] @ e_arg
} in
let post ~token path body = {
meth = `POST body;
path;
Expand Down Expand Up @@ -368,8 +370,8 @@ module Conversions (Json: JSON_CODEC) = struct
status)

| Partition (token, eid, fid, prof) ->
get ~token
["partition"; eid; fid; string_of_int prof]
get ~token ~e_arg:[("exercise_id", eid)]
["partition"; fid; string_of_int prof]

| Invalid_request s ->
failwith ("Error request "^s)
Expand Down Expand Up @@ -497,9 +499,12 @@ module Server (Json: JSON_CODEC) (Rh: REQUEST_HANDLER) = struct
| `GET, ["playgrounds"; f], _ when Filename.check_suffix f ".json" ->
Playground (Filename.chop_suffix f ".json") |> k

| `GET, ["partition"; eid; fid; prof], Some token
when Token.is_teacher token ->
Partition (token, eid, fid, int_of_string prof) |> k
| `GET, ["partition"; fid; prof], Some token
when Token.is_teacher token ->
(match List.assoc_opt "exercise_id" request.args with
| None -> Invalid_request ("Exercise_id missing") |> k
| Some eid ->
Partition (token, eid, fid, int_of_string prof) |> k)

| `GET, ["teacher"; "exercise-status.json"], Some token
when Token.is_teacher token ->
Expand Down