Clear all button
This commit is contained in:
parent
6ff138ade0
commit
d754955694
6 changed files with 60 additions and 6 deletions
|
@ -2,6 +2,10 @@ h3 {
|
|||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.hidden {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.grub-close {
|
||||
display: none;
|
||||
}
|
||||
|
@ -12,6 +16,7 @@ tr:hover .grub-close {
|
|||
|
||||
#grub-list {
|
||||
margin-top: 10px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.grub-item {
|
||||
|
@ -31,3 +36,7 @@ tr:hover .grub-close {
|
|||
text-decoration: line-through;
|
||||
color: #a9a9a9;
|
||||
}
|
||||
|
||||
#clear-all-btn {
|
||||
float: right;
|
||||
}
|
||||
|
|
|
@ -59,4 +59,14 @@
|
|||
(short-delay)
|
||||
(should=
|
||||
nil
|
||||
(mc/find-one-as-map db/grub-collection {:_id (:_id test-grub)}))))))
|
||||
(mc/find-one-as-map db/grub-collection {:_id (:_id test-grub)})))))
|
||||
|
||||
(describe "Clear all"
|
||||
(it "should delete all grubs"
|
||||
(let [test-grub {:_id 123456 :completed true}]
|
||||
(mc/insert db/grub-collection test-grub)
|
||||
(>!! @db/incoming-events {:event :clear-all})
|
||||
(short-delay)
|
||||
(should
|
||||
(empty?
|
||||
(mc/find-maps db/grub-collection)))))))
|
||||
|
|
|
@ -48,6 +48,14 @@
|
|||
delete-event {:_id (:_id test-grub) :event :delete}]
|
||||
(reset! state/grubs [test-grub])
|
||||
(state/handle-event delete-event)
|
||||
(should= [] @state/grubs))))
|
||||
|
||||
(describe "Clear all"
|
||||
(it "should delete all grubs"
|
||||
(let [test-grub {:_id 234243 :grub "testgrub" :completed true}
|
||||
clear-all-event {:event :clear-all}]
|
||||
(reset! state/grubs [test-grub])
|
||||
(state/handle-event clear-all-event)
|
||||
(should= [] @state/grubs)))))
|
||||
|
||||
(describe
|
||||
|
|
|
@ -7,6 +7,9 @@
|
|||
|
||||
(def grub-collection "grubs")
|
||||
|
||||
(defn clear-grubs []
|
||||
(mc/drop grub-collection))
|
||||
|
||||
(def incoming-events (atom nil))
|
||||
|
||||
(defmulti handle-event :event :default :unknown-event)
|
||||
|
@ -29,6 +32,9 @@
|
|||
(defmethod handle-event :delete [event]
|
||||
(mc/remove grub-collection {:_id (:_id event)}))
|
||||
|
||||
(defmethod handle-event :clear-all [event]
|
||||
(clear-grubs))
|
||||
|
||||
(defmethod handle-event :unknown-event [event]
|
||||
(println "Cannot handle unknown event:" event))
|
||||
|
||||
|
@ -48,9 +54,6 @@
|
|||
(>! out grub-event))))
|
||||
out))
|
||||
|
||||
(defn clear-grubs []
|
||||
(mc/drop grub-collection))
|
||||
|
||||
(def default-db "grub")
|
||||
|
||||
(defn connect-and-handle-events
|
||||
|
|
|
@ -43,6 +43,9 @@
|
|||
(fn [current]
|
||||
(vec (remove #(= (:_id %) (:_id event)) current)))))
|
||||
|
||||
(defmethod handle-event :clear-all [event]
|
||||
(reset! grubs []))
|
||||
|
||||
(defmethod handle-event :unknown-event [event]
|
||||
(logs "Cannot handle unknown event:" event))
|
||||
|
||||
|
|
|
@ -26,7 +26,8 @@
|
|||
add-grub-text
|
||||
[:span.input-group-btn
|
||||
add-grub-btn]]
|
||||
[:ul#grub-list.list-group]]
|
||||
[:ul#grub-list.list-group]
|
||||
[:button.btn.hidden {:id "clear-all-btn" :type "button"} "Clear all"]]
|
||||
[:div.col-lg-4]
|
||||
[:div.col-lg-2]]])
|
||||
|
||||
|
@ -42,6 +43,17 @@
|
|||
(defn render-body []
|
||||
(dommy/prepend! (sel1 :body) (main-template)))
|
||||
|
||||
(defprotocol IHideable
|
||||
(-hide! [view])
|
||||
(-show! [view]))
|
||||
|
||||
(extend-type js/HTMLElement
|
||||
IHideable
|
||||
(-hide! [view]
|
||||
(dommy/add-class! view :hidden))
|
||||
(-show! [view]
|
||||
(dommy/remove-class! view :hidden)))
|
||||
|
||||
(defn get-add-grub-text []
|
||||
(let [text (dommy/value add-grub-text)]
|
||||
(dommy/set-value! add-grub-text "")
|
||||
|
@ -86,6 +98,11 @@
|
|||
grub-events (map-chan (fn [id] {:event :delete :_id id}) ids)]
|
||||
grub-events)))
|
||||
|
||||
(defn get-clear-all-events []
|
||||
(let [events (chan)]
|
||||
(dommy/listen! (sel1 :#clear-all-btn) :click #(go (>! events {:event :clear-all})))
|
||||
events))
|
||||
|
||||
|
||||
(defn render-grub-list [grubs]
|
||||
(let [grub-list (sel1 :#grub-list)
|
||||
|
@ -98,12 +115,16 @@
|
|||
|
||||
(defn push-outgoing-events []
|
||||
(fan-in outgoing-events [(get-added-events)
|
||||
(get-deleted-events)]))
|
||||
(get-deleted-events)
|
||||
(get-clear-all-events)]))
|
||||
|
||||
(defn watch-for-state-changes []
|
||||
(add-watch state/grubs
|
||||
:grub-add-watch
|
||||
(fn [key ref old new]
|
||||
(if (empty? new)
|
||||
(-hide! (sel1 :#clear-all-btn))
|
||||
(-show! (sel1 :#clear-all-btn)))
|
||||
(render-grub-list new))))
|
||||
|
||||
(defn init []
|
||||
|
|
Loading…
Reference in a new issue