Remove recipes

This commit is contained in:
Nicholas Kariniemi 2014-08-09 00:07:59 +03:00
parent 8ecc7e9ad4
commit d018bcf3cf
4 changed files with 17 additions and 1 deletions

View file

@ -66,6 +66,9 @@
{:_id (:id event)} {:_id (:id event)}
{mo/$set {:name (:name event) :grubs (:grubs event)}})) {mo/$set {:name (:name event) :grubs (:grubs event)}}))
(defmethod handle-event :remove-recipe [event]
(mc/remove-by-id @db recipe-collection (:id event)))
(defmethod handle-event :unknown-event [event] (defmethod handle-event :unknown-event [event]
(println "Cannot handle unknown event:" event)) (println "Cannot handle unknown event:" event))

View file

@ -62,6 +62,9 @@
(assoc-in [:recipes (:id event) :name] (:name event)) (assoc-in [:recipes (:id event) :name] (:name event))
(assoc-in [:recipes (:id event) :grubs] (:grubs event)))) (assoc-in [:recipes (:id event) :grubs] (:grubs event))))
(defmethod handle-event :remove-recipe [event state]
(assoc state :recipes (dissoc (:recipes state) (:id event))))
(defn update-state-and-render [remote] (defn update-state-and-render [remote]
(let [out (chan) (let [out (chan)
view-events (view/render-app app-state)] view-events (view/render-app app-state)]

View file

@ -33,8 +33,9 @@
recipe-add (chan) recipe-add (chan)
recipe-add-grubs (chan) recipe-add-grubs (chan)
recipe-update (chan) recipe-update (chan)
recipe-remove (chan)
out (a/merge [grub-add grub-update grub-clear-all grub-remove out (a/merge [grub-add grub-update grub-clear-all grub-remove
recipe-add recipe-add-grubs recipe-update]) recipe-add recipe-add-grubs recipe-update recipe-remove])
>events (chan) >events (chan)
<events (a/pub >events :type)] <events (a/pub >events :type)]
(om/root app-view (om/root app-view
@ -47,6 +48,7 @@
:recipe-add recipe-add :recipe-add recipe-add
:recipe-add-grubs recipe-add-grubs :recipe-add-grubs recipe-add-grubs
:recipe-update recipe-update :recipe-update recipe-update
:recipe-remove recipe-remove
:>events >events :>events >events
:<events <events}}) :<events <events}})
out)) out))

View file

@ -20,6 +20,10 @@
:name name :name name
:grubs grubs}) :grubs grubs})
(defn remove-event [id]
{:event :remove-recipe
:id id})
(defn parse-grubs-from-str [grubs-str] (defn parse-grubs-from-str [grubs-str]
(->> grubs-str (->> grubs-str
(clojure.string/split-lines) (clojure.string/split-lines)
@ -96,6 +100,10 @@
:rows (inc (num-newlines grubs)) :rows (inc (num-newlines grubs))
:value grubs :value grubs
:on-change #(om/set-state! owner :grubs (dom/event-val %))}] :on-change #(om/set-state! owner :grubs (dom/event-val %))}]
[:button.btn.btn-danger.pull-left.recipe-remove-btn
{:type "button"
:on-click #(put! (om/get-shared owner :recipe-remove) (remove-event id))}
"Delete"]
[:button.btn.btn-primary.pull-right.recipe-done-btn [:button.btn.btn-primary.pull-right.recipe-done-btn
{:type "button" {:type "button"
:ref :save-btn :ref :save-btn