Skip to content

Commit

Permalink
fix quantity issues; disallow getting a character page for non-charac…
Browse files Browse the repository at this point in the history
…ter entity
  • Loading branch information
larrychristensen committed Jul 13, 2017
1 parent 54c3d11 commit d929cc8
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 27 deletions.
2 changes: 1 addition & 1 deletion resources/public/css/compiled/styles.css

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions src/clj/orcpub/routes.clj
Original file line number Diff line number Diff line change
Expand Up @@ -870,18 +870,18 @@
{:status 401 :body "You do not own this character"})))

(defn get-character-for-id [db id]
(let [{:keys [::se/type ::se/game ::se/game-version] :as character} (d/pull db '[*] id)
(let [{:keys [::se/owner] :as character} (d/pull db '[*] id)
problems [] #_(dnd-e5-char-type-problems character)]
(if (seq problems)
(if (or (not owner) (seq problems))
{:status 400 :body problems}
character)))
{:status 200 :body character})))

(defn character-summary-for-id [db id]
{:keys [::se/summary]} (d/pull db '[::se/summary {::se/values [::char5e/description ::char5e/image-url]}] id))

(defn get-character [{:keys [db] {:keys [:id]} :path-params}]
(let [parsed-id (Long/parseLong id)]
{:status 200 :body (get-character-for-id db parsed-id)}))
(get-character-for-id db parsed-id)))

(defn get-user [{:keys [db identity]}]
(let [username (:user identity)
Expand Down
2 changes: 0 additions & 2 deletions src/clj/orcpub/styles/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -1113,7 +1113,6 @@
:margin-top "5px"
:display :block
:padding "10px"
:width "100%"
:box-sizing :border-box
:font-size "14px"}]

Expand Down Expand Up @@ -1193,7 +1192,6 @@
:margin-top "5px"
:display :block
:padding "10px"
:width "100%"
:box-sizing :border-box
:font-size "14px"}]

Expand Down
13 changes: 13 additions & 0 deletions src/cljc/orcpub/components.cljc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
(ns orcpub.components
(:require [re-frame.core :refer [dispatch]]
[clojure.string :as s]
#?(:cljs [reagent.core :refer [atom]])))

(defn checkbox [selected? disable?]
Expand Down Expand Up @@ -43,3 +44,15 @@
(assoc s
:timeout (js/setTimeout (fn [] (on-change v)) 500)
:temp-val v))))))})])))

(defn int-field [value on-change attrs]
[input-field
:input
value
(fn [str-v]
#?(:cljs
(let [v (if (not (s/blank? str-v))
(js/parseInt str-v))]
(prn "V" v)
(on-change v))))
(assoc attrs :type :number)])
24 changes: 12 additions & 12 deletions src/cljc/orcpub/dnd/e5/character.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,16 @@
add-ability-namespaces
add-namespaces-to-values))

(defn fix-quantity [qty]
(if (string? qty)
(if (s/blank? qty)
0
#?(:cljs
(try
(js/parseInt qty)
(catch Object e 0))))
(int qty)))

(defn fix-quantities [raw-character]
(reduce
(fn [char equipment-key]
Expand All @@ -175,12 +185,7 @@
(update-in
equipment
[::entity/value ::equip/quantity]
(fn [qty]
(if (string? qty)
(if (s/blank? qty)
0
(read-string qty))
qty))))
fix-quantity))
equipment-vec)
(meta equipment-vec))))
char)))
Expand All @@ -201,12 +206,7 @@
(update
equipment
::equip/quantity
(fn [qty]
(if (string? qty)
(if (s/blank? qty)
0
(read-string qty))
qty))))
fix-quantity))
equipment-vec)
(meta equipment-vec))))
char)))
Expand Down
13 changes: 5 additions & 8 deletions src/cljs/orcpub/character_builder.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -267,11 +267,10 @@
{:class-name "input m-t-0"}]
[:div.flex-grow-1 item-name])
(if item-description [:div.w-60 [show-info-button expanded?]])
[:input.input.m-l-5.m-t-0
{:class-name (str "w-" (or qty-input-width 60))
:type :number
:value item-qty
:on-change qty-change-fn}]
[comps/int-field
item-qty
qty-change-fn
{:class-name (str "input m-l-5 m-t-0 w-" (or qty-input-width 60))}]
[:i.fa.fa-minus-circle.orange.f-s-16.m-l-5.pointer
{:on-click remove-fn}]]
(if @expanded? [:div.m-t-5 item-description])])))
Expand Down Expand Up @@ -319,9 +318,7 @@
:i i
:qty-input-width qty-input-width
:check-fn #(dispatch [:toggle-inventory-item-equipped key i])
:qty-change-fn (fn [e]
(let [qty (.. e -target -value)]
(dispatch [:change-inventory-item-quantity key i qty])))
:qty-change-fn #(dispatch [:change-inventory-item-quantity key i %])
:remove-fn (fn [_]
(dispatch [:remove-inventory-item key item-key]))}]))
selected-items))]
Expand Down

0 comments on commit d929cc8

Please sign in to comment.