about summary refs log tree commit diff stats
path: root/app/views
diff options
context:
space:
mode:
authorStar Rauchenberger <fefferburbia@gmail.com>2023-10-29 14:46:27 -0400
committerStar Rauchenberger <fefferburbia@gmail.com>2023-10-29 14:46:27 -0400
commit862cb4e3f9b9864bc1b5a20cd7ebd7c4d6cccb77 (patch)
treeb3e80c19d9c5725178279c69cb1ee660901f9a66 /app/views
parentd672465c2be3dc54463a92a3f1c4aa23447bc5c8 (diff)
downloadwittle-862cb4e3f9b9864bc1b5a20cd7ebd7c4d6cccb77.tar.gz
wittle-862cb4e3f9b9864bc1b5a20cd7ebd7c4d6cccb77.tar.bz2
wittle-862cb4e3f9b9864bc1b5a20cd7ebd7c4d6cccb77.zip
added timer
Diffstat (limited to 'app/views')
-rw-r--r--app/views/wittle/puzzles/_handle_puzzle.html.erb32
-rw-r--r--app/views/wittle/puzzles/_submission.html.haml2
-rw-r--r--app/views/wittle/puzzles/show.html.haml14
3 files changed, 40 insertions, 8 deletions
diff --git a/app/views/wittle/puzzles/_handle_puzzle.html.erb b/app/views/wittle/puzzles/_handle_puzzle.html.erb index 3ac868e..3d593a4 100644 --- a/app/views/wittle/puzzles/_handle_puzzle.html.erb +++ b/app/views/wittle/puzzles/_handle_puzzle.html.erb
@@ -1,6 +1,23 @@
1<script type="text/javascript"> 1<script type="text/javascript">
2var totalSeconds = 0
3var timerInterval
4
2window.onload = function() { 5window.onload = function() {
3 <% if @playable %> 6 <% if @playable %>
7 function pad(val) {
8 var valString = val + ""
9 if (valString.length < 2)
10 {
11 return "0" + valString
12 } else {
13 return valString
14 }
15 }
16 function setTime() {
17 ++totalSeconds
18 $("#seconds").text(pad(totalSeconds%60))
19 $("#minutes").text(pad(parseInt(totalSeconds/60)))
20 }
4 $("#sens").val(window.settings.sensitivity) 21 $("#sens").val(window.settings.sensitivity)
5 $("#sens").on("change", function() { 22 $("#sens").on("change", function() {
6 window.settings.sensitivity = this.value 23 window.settings.sensitivity = this.value
@@ -9,12 +26,17 @@ window.onload = function() {
9 $("#volume").on("change", function() { 26 $("#volume").on("change", function() {
10 window.settings.volume = this.value 27 window.settings.volume = this.value
11 }) 28 })
12 <% end %> 29 $("#activation-button button").on("click", function() {
30 var puzzle = window.deserializePuzzle("<%= @puzzle.data %>")
31 draw(puzzle)
32
33 $("#activation-button").hide()
13 34
35 timerInterval = setInterval(setTime, 1000);
36 })
37 <% else %>
14 var puzzle = window.deserializePuzzle("<%= @puzzle.data %>") 38 var puzzle = window.deserializePuzzle("<%= @puzzle.data %>")
15 draw(puzzle) 39 draw(puzzle)
16
17 <% unless @playable %>
18 drawPath(puzzle, JSON.parse("<%= escape_javascript(sanitize @puzzle.solved_data) %>")) 40 drawPath(puzzle, JSON.parse("<%= escape_javascript(sanitize @puzzle.solved_data) %>"))
19 window.trace = function() {} 41 window.trace = function() {}
20 <% end %> 42 <% end %>
@@ -22,10 +44,12 @@ window.onload = function() {
22 44
23<% if @playable %> 45<% if @playable %>
24window.TRACE_COMPLETION_FUNC = function(puzzle, rawPath) { 46window.TRACE_COMPLETION_FUNC = function(puzzle, rawPath) {
47 clearInterval(timerInterval)
48
25 $.ajax({ 49 $.ajax({
26 type: "POST", 50 type: "POST",
27 url: "<%= solve_puzzle_path(@puzzle, format: :js) %>", 51 url: "<%= solve_puzzle_path(@puzzle, format: :js) %>",
28 data: { solved: JSON.stringify(rawPath) } 52 data: { solved: JSON.stringify(rawPath), time: totalSeconds }
29 }) 53 })
30} 54}
31 55
diff --git a/app/views/wittle/puzzles/_submission.html.haml b/app/views/wittle/puzzles/_submission.html.haml index 744372a..a3d0740 100644 --- a/app/views/wittle/puzzles/_submission.html.haml +++ b/app/views/wittle/puzzles/_submission.html.haml
@@ -1,6 +1,8 @@
1%h3 Congrats! 1%h3 Congrats!
2%p Would you like to submit your time? 2%p Would you like to submit your time?
3= form_with url: submit_puzzle_path(@puzzle) do |form| 3= form_with url: submit_puzzle_path(@puzzle) do |form|
4 - unless @time.nil?
5 = form.hidden_field :time, value: @time
4 %p 6 %p
5 = form.label :name, "Name:" 7 = form.label :name, "Name:"
6 = form.text_field :name 8 = form.text_field :name
diff --git a/app/views/wittle/puzzles/show.html.haml b/app/views/wittle/puzzles/show.html.haml index 75ae288..deda344 100644 --- a/app/views/wittle/puzzles/show.html.haml +++ b/app/views/wittle/puzzles/show.html.haml
@@ -3,6 +3,12 @@
3 %svg#puzzle{ style: "pointer-events: auto"} 3 %svg#puzzle{ style: "pointer-events: auto"}
4#submission-form 4#submission-form
5- if @playable 5- if @playable
6 #activation-button
7 %button{ type: "button" } Reveal Puzzle
8 #timer
9 %label#minutes 00
10 %label#colon :
11 %label#seconds 00
6 %details#trace-settings 12 %details#trace-settings
7 %summary Settings 13 %summary Settings
8 .things 14 .things
@@ -15,17 +21,17 @@
15 #by-time 21 #by-time
16 %h2 Fastest Solves 22 %h2 Fastest Solves
17 %table 23 %table
18 - @puzzle.scores.where("seconds_taken IS NOT NULL").order(seconds_taken: :asc).each do |score| 24 - @puzzle.scores.where("seconds_taken IS NOT NULL").order(seconds_taken: :asc).limit(20).each_with_index do |score, i|
19 %tr 25 %tr
20 %td #{(i + 1)}. 26 %td #{(i + 1)}.
21 %td= score.name 27 %td= score.name
22 %td 28 %td.score-field= humanize_interval(score.seconds_taken)
23 #by-when 29 #by-when
24 %h2 Completion Order 30 %h2 Completion Order
25 %table 31 %table
26 - @puzzle.scores.order(created_at: :asc).each_with_index do |score, i| 32 - @puzzle.scores.order(created_at: :asc).limit(20).each_with_index do |score, i|
27 %tr 33 %tr
28 %td #{(i + 1)}. 34 %td #{(i + 1)}.
29 %td= score.name 35 %td= score.name
30 %td= score.created_at.getlocal().strftime("%-I:%M:%S%P") 36 %td.score-field= score.created_at.getlocal().strftime("%-I:%M:%S%P")
31= render partial: "handle_puzzle" 37= render partial: "handle_puzzle"