Skip to content

Commit

Permalink
text-input with advanced deref values; workspace renaming working
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew committed Jun 6, 2016
1 parent 76ada48 commit c42868d
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 14 deletions.
44 changes: 35 additions & 9 deletions src/cljs/ulysses/components/basic.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,41 @@
[handler attr & body]
(into [:a (assoc attr :on-click (d-p handler))] body))

;; ----------------------------------------------------------------------------
;; forms
;; ----------------------------------------------------------------------------

(defn text-input []
"regular text field, with the special ability
to derefence a `forein` reference value,
as well as reset! it if an :on-change is not supplied
ex. [text-input :value my-atom]
ex. [text-input :value my-value :on-change #(dispatch ...)]"
(fn [& {:keys [placeholder value on-change]}]
(let [should-deref (satisfies? IDeref value)
;; if on-change is not present, then
;; check if value is reset!-able. if so,
;; then default to a reset!, else noop
ogc (partial (or on-change
(fn [v]
(if should-deref
(reset! value v)
#()))))]
[:input {:type :text
:class :form-control
:placeholder placeholder
:value (if should-deref @value value)
:on-change #(-> % .-target .-value ogc)}])))

(defn range-slider
[& {:keys [min max value on-change]}]
[:input {:class :range-slider
:type :range
:min min
:max max
:value value
:on-change #(-> % .-target .-value str->int on-change)}])

;; ----------------------------------------------------------------------------
;; bootstrap helpers
;; ----------------------------------------------------------------------------
Expand Down Expand Up @@ -104,15 +139,6 @@
;; misc
;; ----------------------------------------------------------------------------

(defn range-slider
[& {:keys [min max value on-change]}]
[:input {:class :range-slider
:type :range
:min min
:max max
:value value
:on-change #(on-change (-> % .-target .-value str->int))}])

(defn loading-or-no-results
"show a loading... message if loading, otherwise
show a not found message. message(s) can be customized:
Expand Down
2 changes: 1 addition & 1 deletion src/cljs/ulysses/components/misc.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
[:button {:type :button :class :close :on-click on-close}
[:span "×"]]
[:h4.modal-title title]]
(into [:div.modal-body] children)
[:div.modal-body children]
[:div.modal-footer
[:button
{:type :button
Expand Down
29 changes: 25 additions & 4 deletions src/cljs/ulysses/pages/builder.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
loading-or-no-results
fa
tabs
range-slider]]
range-slider
text-input]]
[ulysses.components.misc :refer [grant-op-meta]]
[ulysses.components.word-cloud :refer [word-cloud]]
[ulysses.utils :refer [map-subels map-lookup str->int classes-attr]]
Expand Down Expand Up @@ -157,9 +158,29 @@
[hink #(dispatch [:workspace-new-default]) btn-attrs "New from Default"]]]
[workspace-header-tabs workspaces workspace-current]]))

(defn workspace-rename [workspace-current]
(let [new-name (r/atom (str))]
(fn [workspace-current]
[hink
(fn []
(reset! new-name (:name workspace-current))
(dispatch
[:modal
{:title [:span "Rename Workspace " [:i (:name workspace-current)]]
:action-label "Rename"
:on-action #(dispatch [:workspace-rename @new-name])
:children
[:div
[text-input
:placeholder "Name"
:value new-name]]}]))
(classes-attr :btn :btn-sm :btn-default)
"Rename"])))

(defn workspace-footer [workspace-current]
[:div.workspace-footer
(when workspace-current
(when workspace-current
[:div.workspace-footer
[workspace-rename workspace-current]
[hink
(fn []
(dispatch
Expand All @@ -170,7 +191,7 @@
:on-action #(dispatch [:workspace-delete])
:children "Are you sure you want to delete this workspace?"}]))
(classes-attr :btn :btn-sm :btn-danger)
"Delete Current Workspace"])])
"Delete"]]))

(defn pool-row [fam]
(let [{:keys [faculty fundingCoverageScore]} fam
Expand Down
5 changes: 5 additions & 0 deletions src/sass/components/_builder-panel.scss
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@
text-align: right;

.btn {
margin-right: 3px;
margin-top: 15px;

&:last-of-type {
margin-right: 0;
}
}
}

0 comments on commit c42868d

Please sign in to comment.