fix Show forms for new workouts

Render outstanding effort forms independently from recorded efforts so newly started workouts can be logged from Overview.

Commit
9a8008164c60bd606b6501ad2aba9631dac5aedc
Author
Marius Peter <dev@marius-peter.com>
Author date
Committer
Marius Peter <dev@marius-peter.com>
Committer date
Changed files
lib/web/pages.ml
index 36eb09cb..36b5d374 100644..100644
@@ -327,18 +327,7 @@
327 327 tag "div" [ class_ "warn" ] [ txt "Begun before recovery finished." ];
328 328 ]
329 329 in
330 Removed: html_page
331 Removed: (Prescription.Workout.name prescription)
332 Removed: (override_note
333 Removed: @ [
334 Removed: tag "h2" [] [ txt "%s" (Prescription.Workout.name prescription) ];
335 Removed: tag "p" []
336 Removed: [
337 Removed: txt "%d of %d recorded." (List.length performed)
338 Removed: (List.length (Prescription.Workout.stimuli prescription));
339 Removed: ];
340 Removed: ]
341 Removed: @
330 Added: let recorded_section =
342 331 if performed = [] then []
343 332 else
344 333 [
@@ -349,30 +338,45 @@
349 338 tag "li" [] [ txt "%s" (describe_stimulus stimulus) ])
350 339 performed);
351 340 ]
352 Removed: @
353 Removed: if outstanding = [] then
354 Removed: [ tag "p" [] [ txt "Everything prescribed has been recorded." ] ]
355 Removed: else
356 Removed: tag "h2" [] [ txt "Still to do" ]
357 Removed: :: List.map
358 Removed: (fun (slot, prescription) ->
359 Removed: form_for_stimulus ~action_path:(form_action slot) ~prescription
360 Removed: ~errors)
361 Removed: outstanding
362 Removed: @
363 Removed: match record_id with
364 Removed: | Some _ -> []
365 Removed: | None ->
341 Added: in
342 Added: let outstanding_section =
343 Added: if outstanding = [] then
344 Added: [ tag "p" [] [ txt "Everything prescribed has been recorded." ] ]
345 Added: else
346 Added: tag "h2" [] [ txt "Still to do" ]
347 Added: :: List.map
348 Added: (fun (slot, prescription) ->
349 Added: form_for_stimulus ~action_path:(form_action slot) ~prescription
350 Added: ~errors)
351 Added: outstanding
352 Added: in
353 Added: let finish_section =
354 Added: match record_id with
355 Added: | Some _ -> []
356 Added: | None ->
357 Added: [
358 Added: tag "form"
366 359 [
367 Removed: tag "form"
368 Removed: [
369 Removed: Dream_html.path_attr
370 Removed: (Dream_html.uri_attr "action")
371 Removed: Routes.finish_workout;
372 Removed: Dream_html.string_attr "method" "post";
373 Removed: ]
374 Removed: [ void "input" [ type_ "submit"; value "Finish workout" ] ];
375 Removed: ])
360 Added: Dream_html.path_attr
361 Added: (Dream_html.uri_attr "action")
362 Added: Routes.finish_workout;
363 Added: Dream_html.string_attr "method" "post";
364 Added: ]
365 Added: [ void "input" [ type_ "submit"; value "Finish workout" ] ];
366 Added: ]
367 Added: in
368 Added: html_page
369 Added: (Prescription.Workout.name prescription)
370 Added: (override_note
371 Added: @ [
372 Added: tag "h2" [] [ txt "%s" (Prescription.Workout.name prescription) ];
373 Added: tag "p" []
374 Added: [
375 Added: txt "%d of %d recorded." (List.length performed)
376 Added: (List.length (Prescription.Workout.stimuli prescription));
377 Added: ];
378 Added: ]
379 Added: @ recorded_section @ outstanding_section @ finish_section)
376 380
377 381 let history records =
378 382 html_page "History"
test/test_web.ml
index 84c6efdf..1be4dc85 100644..100644
@@ -1,6 +1,24 @@
1 1 let app () =
2 2 Hito_web.Handlers.create () |> Hito_web.Handlers.routes |> Dream.router
3 3
4 Added: let status response = Dream.status response |> Dream.status_to_int
5 Added: let body response = Lwt_main.run (Dream.body response)
6 Added:
7 Added: let contains ~substring string =
8 Added: let substring_length = String.length substring in
9 Added: let rec at index =
10 Added: if index + substring_length > String.length string then false
11 Added: else if String.sub string index substring_length = substring then true
12 Added: else at (index + 1)
13 Added: in
14 Added: at 0
15 Added:
16 Added: let post app target body =
17 Added: Dream.test app
18 Added: (Dream.request ~method_:`POST ~target
19 Added: ~headers:[ ("Content-Type", "application/x-www-form-urlencoded") ]
20 Added: body)
21 Added:
4 22 let route_tests =
5 23 [
6 24 ( "web",
@@ -9,9 +27,24 @@
9 27 `Quick,
10 28 fun () ->
11 29 let response = Dream.test (app ()) (Dream.request "") in
12 Removed: Alcotest.(check int)
13 Removed: "status" 200
14 Removed: (Dream.status response |> Dream.status_to_int) );
30 Added: Alcotest.(check int) "status" 200 (status response) );
31 Added: ( "a new workout exposes outstanding effort forms on Overview",
32 Added: `Quick,
33 Added: fun () ->
34 Added: let application = app () in
35 Added: let selection = post application "/routines/ideal/select" "" in
36 Added: Alcotest.(check int) "routine selected" 303 (status selection);
37 Added: let started = post application "/workout" "override=false" in
38 Added: Alcotest.(check int) "workout started" 303 (status started);
39 Added: let overview = Dream.test application (Dream.request "") in
40 Added: Alcotest.(check int) "overview" 200 (status overview);
41 Added: let page = body overview in
42 Added: Alcotest.(check bool)
43 Added: "outstanding heading" true
44 Added: (contains ~substring:"Still to do" page);
45 Added: Alcotest.(check bool)
46 Added: "first effort form" true
47 Added: (contains ~substring:"/workout/slots/0" page) );
15 48 ] );
16 49 ]
17 50