apps/habbits/templates/habit.html 5.3 K raw
1
<!doctype html>
2
<html lang="en">
3
  <head>
4
    <meta charset="UTF-8" />
5
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
    <meta name="theme-color" content="#121113" />
7
    <link rel="stylesheet" href="/assets/darkmatter.css" />
8
    <link rel="stylesheet" href="/static/styles.css" />
9
    <title>Habbits | {{.Habit.Name}}</title>
10
  </head>
11
  <body>
12
    <div class="header">
13
      <a href="/" class="logo">HABBITS</a>
14
      <nav class="links">
15
        <a href="/">dashboard</a>
16
        <a href="/new">new habit</a>
17
        <a href="/settings">settings</a>
18
        <a href="/logout">logout</a>
19
      </nav>
20
    </div>
21
22
    {{if .Success}}<p class="success">{{.Success}}</p>{{end}}
23
    {{if .Error}}<p class="error">{{.Error}}</p>{{end}}
24
25
    {{$habit := .Habit}}
26
27
    <section class="section">
28
      <div class="admin-toolbar">
29
        <h2>{{.Habit.Name}} <span class="tag">{{.Habit.ValueType}}</span>{{if .Habit.Unit}} <span class="tag">{{.Habit.Unit}}</span>{{end}}</h2>
30
        <a href="/settings">edit habit</a>
31
      </div>
32
      {{if .Habit.Description}}<p class="admin-list-meta">{{.Habit.Description}}</p>{{end}}
33
    </section>
34
35
    {{if .ChartType}}
36
    <section class="section">
37
      <h2>{{if eq .ChartType "bool"}}Streak{{else}}Trend{{end}}</h2>
38
      <div
39
        id="habit-chart"
40
        class="chart"
41
        data-type="{{.ChartType}}"
42
        data-unit="{{.Habit.Unit}}"
43
        data-points="{{.ChartPoints}}"
44
      ></div>
45
    </section>
46
    {{end}}
47
48
    <section class="section">
49
      <h2>New record</h2>
50
      <form class="form" method="POST" action="/records">
51
        <input type="hidden" name="return_to" value="/habits/{{.Habit.ShortID}}" />
52
        <input type="hidden" name="habit" value="{{.Habit.ShortID}}" />
53
        <div class="form-row">
54
          <div class="form-field">
55
            <label for="value">Value{{if .Habit.Unit}} ({{.Habit.Unit}}){{end}}</label>
56
            {{if eq .Habit.ValueType "bool"}}
57
            <select id="value" name="value" required>
58
              <option value="true">true</option>
59
              <option value="false">false</option>
60
            </select>
61
            {{else if eq .Habit.ValueType "int"}}
62
            <input type="number" step="1" id="value" name="value" required />
63
            {{else if eq .Habit.ValueType "float"}}
64
            <input type="number" step="any" id="value" name="value" required />
65
            {{else}}
66
            <input type="text" id="value" name="value" required />
67
            {{end}}
68
          </div>
69
          <div class="form-field">
70
            <label for="recorded_at">When</label>
71
            <input type="datetime-local" id="recorded_at" name="recorded_at" class="now-default" />
72
          </div>
73
        </div>
74
        <div class="form-actions">
75
          <button type="submit">Add record</button>
76
        </div>
77
      </form>
78
    </section>
79
80
    <section class="section">
81
      <div class="admin-toolbar">
82
        <h2>Records ({{.Habit.RecordCount}})</h2>
83
      </div>
84
      {{if not .Days}}
85
      <p class="empty">No records yet. Add one above.</p>
86
      {{else}}
87
      {{range .Days}}
88
      <div class="day-group">
89
        <h3 class="day-heading">{{.Date}}</h3>
90
        <ul class="admin-list">
91
          {{range .Records}}
92
          <li class="admin-list-item">
93
            <form class="form-row record-edit" method="POST" action="/records/{{.ShortID}}">
94
              <input type="hidden" name="return_to" value="/habits/{{$habit.ShortID}}" />
95
              <div class="form-field">
96
                {{if eq $habit.ValueType "bool"}}
97
                <select name="value" required>
98
                  <option value="true"{{if eq .Value "true"}} selected{{end}}>true</option>
99
                  <option value="false"{{if eq .Value "false"}} selected{{end}}>false</option>
100
                </select>
101
                {{else if eq $habit.ValueType "int"}}
102
                <input type="number" step="1" name="value" value="{{.Value}}" required />
103
                {{else if eq $habit.ValueType "float"}}
104
                <input type="number" step="any" name="value" value="{{.Value}}" required />
105
                {{else}}
106
                <input type="text" name="value" value="{{.Value}}" required />
107
                {{end}}
108
              </div>
109
              <div class="form-field">
110
                <input type="datetime-local" name="recorded_at" value="{{.RecordedAtInput}}" required />
111
              </div>
112
              <button type="submit" class="link-button">save</button>
113
            </form>
114
            <div class="admin-list-actions">
115
              <form method="POST" action="/records/{{.ShortID}}/delete" class="inline-form">
116
                <input type="hidden" name="return_to" value="/habits/{{$habit.ShortID}}" />
117
                <button type="submit" class="link-button danger">delete</button>
118
              </form>
119
            </div>
120
          </li>
121
          {{end}}
122
        </ul>
123
      </div>
124
      {{end}}
125
      {{end}}
126
    </section>
127
128
    <script>
129
      (function () {
130
        var now = new Date();
131
        now.setMinutes(now.getMinutes() - now.getTimezoneOffset());
132
        var stamp = now.toISOString().slice(0, 16);
133
        document.querySelectorAll("input.now-default").forEach(function (el) {
134
          if (!el.value) el.value = stamp;
135
        });
136
      })();
137
    </script>
138
    <script src="/static/chart.js"></script>
139
  </body>
140
</html>