1 ! Copyright (c) 2008 Slava Pestov
2 ! See https://factorcode.org/license.txt for BSD license.
3 USING: accessors kernel sequences namespaces db db.types db.tuples validators
4 hashtables urls html.forms html.components html.templates.chloe http.server
5 http.server.dispatchers furnace furnace.boilerplate furnace.auth
6 furnace.actions furnace.redirection furnace.db furnace.auth.login
10 TUPLE: todo-list < dispatcher ;
12 TUPLE: todo uid id priority summary description ;
16 { "uid" "UID" { VARCHAR 256 } +not-null+ }
17 { "id" "ID" +db-assigned-id+ }
18 { "priority" "PRIORITY" INTEGER +not-null+ }
19 { "summary" "SUMMARY" { VARCHAR 256 } +not-null+ }
20 { "description" "DESCRIPTION" { VARCHAR 256 } }
23 : <todo> ( id -- todo )
28 : <view-action> ( -- action )
32 "id" value <todo> select-tuple from-object
35 { todo-list "view-todo" } >>template ;
37 : validate-todo ( -- )
39 { "summary" [ v-one-line ] }
40 { "priority" [ v-integer 0 v-min-value 10 v-max-value ] }
41 { "description" [ v-required ] }
44 : view-todo-url ( id -- url )
45 <url> "$todo-list/view" >>path swap "id" set-query-param ;
47 : <new-action> ( -- action )
49 [ 0 "priority" set-value ] >>init
51 { todo-list "new-todo" } >>template
53 [ validate-todo ] >>validate
57 dup { "summary" "priority" "description" } to-object
58 [ insert-tuple ] [ id>> view-todo-url <redirect> ] bi
61 : <edit-action> ( -- action )
65 "id" value <todo> select-tuple from-object
68 { todo-list "edit-todo" } >>template
77 dup { "id" "summary" "priority" "description" } to-object
78 [ update-tuple ] [ id>> view-todo-url <redirect> ] bi
81 : todo-list-url ( -- url )
82 URL" $todo-list/list" ;
84 : <delete-action> ( -- action )
86 [ validate-integer-id ] >>validate
89 "id" get <todo> delete-tuples
90 todo-list-url <redirect>
93 : <list-action> ( -- action )
95 [ f <todo> select-tuples "items" set-value ] >>init
96 { todo-list "todo-list" } >>template ;
98 : <todo-list> ( -- responder )
99 todo-list new-dispatcher
100 <list-action> "list" add-responder
101 URL" /list" <redirect-responder> "" add-responder
102 <view-action> "view" add-responder
103 <new-action> "new" add-responder
104 <edit-action> "edit" add-responder
105 <delete-action> "delete" add-responder
107 { todo-list "todo" } >>template
109 "view your todo list" >>description ;
111 USING: furnace.auth.features.registration
112 furnace.auth.features.edit-profile
113 furnace.auth.features.deactivate-user
116 : <login-config> ( responder -- responder' )
117 "Todo list" <login-realm>
123 "todo.db" <temp-sqlite-db> ;
125 : init-todo-db ( -- )
131 : <todo-app> ( -- responder )
138 <todo-app> main-responder set-global
139 todo-db start-expiring