summaryrefslogtreecommitdiff
path: root/main.ur
blob: 195389d0a7003385992a74986b7caef9df9b1ef0 (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
142
143
(* Copyright 2015 Google Inc.
Copyright 2016 Benjamin Barenblat

Licensed under the Apache License, Version 2.0 (the “License”); you may not use
this file except in compliance with the License.  You may obtain a copy of the
License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed
under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied.  See the License for the
specific language governing permissions and limitations under the License. *)

open Mdl.Classes

table nextAction : {
  Id : int,
  Nam : string,
  Done : bool,
} PRIMARY KEY Id

sequence nextActionId

(* Forces JavaScript to be enabled on the given page, so as to pull in external
scripts specified in the .urp file. *)
val forceJavaScript = <xml><script code={return ()} /></xml>

fun markNextActionStatus id done =
  dml (UPDATE nextAction SET Done = {[done]} WHERE Id = {[id]})

fun renderNextAction action =
  c <- fresh;
  done <- source action.Done;
  return <xml>
    <li class="mdl-list__item">
      <span class="mdl-list__item-primary-content">
        <span class="mdl-list__item-icon">
          <label class="mdl-checkbox" for={c}>
            <ccheckbox id={c} source={done} class="mdl-checkbox__input"
              onchange={
                b <- get done;
                rpc (markNextActionStatus action.Id b)
              } />
          </label>
        </span>
        {[action.Nam]}
      </span>
    </li>
  </xml>

val renderNextActions = queryX1' (SELECT * FROM nextAction) renderNextAction

fun newNextAction name =
  id <- nextval nextActionId;
  dml (INSERT INTO nextAction (Id, Nam, Done) VALUES ({[4 + id]}, {[name]}, FALSE));
  renderNextActions


style hidden
style visible

datatype mode = NextActions | NewNextAction

val main =
  actionItems <- bind renderNextActions source;
  mode <- source NextActions;
  newNextActionDescription <- Mdl.Textbox.make "Description";
  return <xml>
    <head>
      (* TODO(bbaren): Write a meta-description tag. *)
      <meta name="viewport" content="width=device-width, initial-scale=1.0" />
      <title>Next actions</title>

      (* Disable tap highlight on IE. *)
      <meta name="msapplication-tap-highlight" content="no" />

      (* TODO(bbaren): Support homescreen tiles for Chrome on Android, Safari on
      iOS, and Windows 8. *)

      (* Color the status bar on mobile devices. *)
      <meta name="theme-color" content="#9c27b0" />

      (* Material Design Lite *)
      <link rel="stylesheet" href="https://code.getmdl.io/1.1.3/material.purple-orange.min.css" />
      <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons" />
      {forceJavaScript}

      <link rel="stylesheet" href="/ugtd.css" />
    </head>
    <body>
      <div dynClass={
        currentMode <- signal mode;
        return (case currentMode of
                    NewNextAction => visible
                  | _ => hidden)
      }>
        <div class="mdl-layout mdl-js-layout mdl-layout--fixed-header">
          <header class="mdl-layout__header">
            <button class="mdl-layout__drawer-button" onclick={fn _ => set mode NextActions}>
              <i class="material-icons">close</i>
            </button>
            <div class="mdl-layout__header-row">
              <span class="mdl-layout-title">New action</span>
              <div class="mdl-layout-spacer" />
              <button class="mdl-button mdl-js-button" value="Save" onclick={fn _ =>
                name <- get newNextActionDescription.Source;
                bind (rpc (newNextAction name)) (set actionItems);
                sleep 0;
                set mode NextActions;
                set newNextActionDescription.Source ""
              } />
            </div>
          </header>
          <div class="mdl-layout__content">
            {newNextActionDescription.Xml}
          </div>
        </div>
      </div>
      <div dynClass={
        currentMode <- signal mode;
        return (case currentMode of
                    NextActions => visible
                  | _ => hidden)
      }>
        <div class="mdl-layout mdl-js-layout mdl-layout--fixed-header">
          <div class="mdl-layout__header mdl-layout__header--waterfall mdl-layout__header--waterfall-hide-top">
            <div class="mdl-layout__header-row">
              <span class="mdl-layout-title">Next actions</span>
            </div>
          </div>
          <div class="mdl-layout__content">
            <ul class="mdl-list">
              <dyn signal={signal actionItems} />
            </ul>
            <button class="mdl-button mdl-js-button mdl-button--fab mdl-button--colored" onclick={fn _ => set mode NewNextAction}>
              <i class="material-icons">add</i>
            </button>
          </div>
        </div>
      </div>
    </body>
  </xml>