|
|
@ -0,0 +1,50 @@
|
|
|
1
|
(ns shame
|
|
|
2
|
(:use [clojure.data.json :as json :only []]))
|
|
|
3
|
|
|
|
4
|
; roadmap:
|
|
|
5
|
; 1. implement add-item, resurrect-item, close-item
|
|
|
6
|
; 2. use refs
|
|
|
7
|
; 3. persist to disk
|
|
|
8
|
; 4. serve as local web-page
|
|
|
9
|
; caveats: client-side needed (add/close/resurrect, index, note)
|
|
|
10
|
; 5. publish
|
|
|
11
|
|
|
|
12
|
;; todo manipulation
|
|
|
13
|
|
|
|
14
|
(defn add-item [item shaming]
|
|
|
15
|
"Try adding an item to the shaming. If the maximum number of items is
|
|
|
16
|
exceeeded, return the original shaming."
|
|
|
17
|
(let [c (count (:current shaming))]
|
|
|
18
|
(if (< c (get-in shaming [:config :number-of-items]))
|
|
|
19
|
(assoc-in shaming [:current c] item)
|
|
|
20
|
shaming))) ; FIXME: is that the clojure way of doing it?
|
|
|
21
|
|
|
|
22
|
(defn get-by [map-coll k v]
|
|
|
23
|
(first (drop-while #(not= (k %) v) map-coll)))
|
|
|
24
|
|
|
|
25
|
(defn transplant [item association from to]
|
|
|
26
|
"Transplants an item in a map of vectors from one key to another."
|
|
|
27
|
(assoc association
|
|
|
28
|
from (vec (filter #(not= item %) (from association)))
|
|
|
29
|
to (conj (to association) item)))
|
|
|
30
|
|
|
|
31
|
(defn close-item [item-name status shaming]
|
|
|
32
|
(let [item (get-by (:current shaming) :name item-name)
|
|
|
33
|
item (assoc item :closed-at (java.util.Date.))]
|
|
|
34
|
(transplant item shaming :current :past)))
|
|
|
35
|
|
|
|
36
|
(defn resurrect-item [item-name shaming]
|
|
|
37
|
(let [item (get-by (:past shaming) :name item-name)
|
|
|
38
|
item (assoc item :started-at (java.util.Date.))]
|
|
|
39
|
(transplant item shaming :past :current)))
|
|
|
40
|
|
|
|
41
|
;; references (for "mutating" the todo-list)
|
|
|
42
|
|
|
|
43
|
(def ^:dynamic *shaming*
|
|
|
44
|
(ref nil))
|
|
|
45
|
|
|
|
46
|
(defn read-shame [filename]
|
|
|
47
|
(json/read-str (slurp filename) :key-fn keyword))
|
|
|
48
|
|
|
|
49
|
(defn write-shame [filename shaming]
|
|
|
50
|
(spit filename (json/write-str shaming)))
|