summaryrefslogtreecommitdiff
path: root/static/timer.html
blob: ecaf966d7e1208d76ddf39bb98772e836eebfee2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<html>
  <head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <style>
      p {
        #margin-top: 0;
        #margin-bottom: 0;
      }
      label.number, label.text {
        margin-right: 1rem;
      }
      label.multi-label {
        padding: 1rem;
        border: 1px solid #3366ff;
      }
      input[type="checkbox"].multi-checkbox {
        display: none;
      }
      input[type="checkbox"] {
        height: 2rem;
        width: 2rem;
      }
      input:checked + label{
        background-color: #99ccff;
      }
      input[type="number"] {
        height: 3rem;
      }
      input[type="range"] {
        width: 60%;
      }
      input[type="text"] {
        height: 3rem;
      }
      .prompt {
        margin-bottom: 2rem;
      }
      textarea {
        width: 80ch;
        height: 5rem;
      }
      button, select {
        padding: 1rem;
        border: 1px solid #3366ff;
      }
      .main>div {
        margin: 1rem;
      }
    </style>
  </head>
  <body>
    <nav></nav>
    <div class="main">

      <div id="stopwatch">0 minutes 0 seconds</div>
      <div>
        <button onclick="start()" id="start">Start</button>
      </div>
      <div>
        <button onclick="pause()" id="pause">Pause</button>
      </div>
      <div>
        <button onclick="reset()" id="reset">Reset</button>
      </div>

      <div>
        <select id="select_el" name="type">
        </select>
      </div>

      <div>
        <button onclick="on_submit()">Submit</button>
      </div>


      <script>
        var seconds = 0;
        var timeoutId;
        let stopwatch = document.getElementById("stopwatch")
        let start_button = document.getElementById("start")
        let pause_button = document.getElementById("pause")
        let reset_button = document.getElementById("reset")
        function start(){
            start_button.disabled = true
            pause_button.disabled = false
            reset_button.disabled = false
            timeoutId = setTimeout(function() {
              seconds++
              let disp_seconds = seconds % 60
              let minutes = Math.trunc(seconds/60)
              stopwatch.innerHTML = minutes + ' minutes ' + disp_seconds + " seconds"
              start();
            }, 1000); // setTimeout delay time 10 milliseconds
        }
        function pause(){
            clearTimeout(timeoutId)
            start_button.disabled = false
            pause_button.disabled = true
            reset_button.disabled = false
        }
        function reset(){
            start_button.disabled = false
            pause_button.disabled = true
            reset_button.disabled = true
            seconds = 0
            stopwatch.innerHTML = '0 minutes 0 seconds'
        }
        async function enqueue_data(path, payload, do_alert=false){
          payload["timestamp"] =  Date.now()
          await fetch(path, {method: "POST", body: JSON.stringify(payload)})
          if(do_alert){
            alert("saved!")
          }
        }
        function on_submit(){
          let payload = {
            "type": document.getElementById("select_el").value,
            "seconds": seconds,
          }
          console.log(payload)
          enqueue_data("/submit_task_time", payload, do_alert=true)
        }
        window.onload = function(){
          start_button.disabled = false
          pause_button.disabled = true
          reset_button.disabled = true
          fetch("/tasks").then(res => res.json()).then(data => {
            let el = document.getElementById("select_el")
            data.forEach(i => {
              let option = document.createElement("option")
              option.setAttribute("value", i)
              option.innerHTML = i

              el.appendChild(option)
            })
          })
        }
      </script>
    </div>
  </body>
</html>