diff --git a/src/cljs/ulysses/components/basic.cljs b/src/cljs/ulysses/components/basic.cljs index 0452a53..0c6ccc3 100644 --- a/src/cljs/ulysses/components/basic.cljs +++ b/src/cljs/ulysses/components/basic.cljs @@ -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 ;; ---------------------------------------------------------------------------- @@ -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: diff --git a/src/cljs/ulysses/components/misc.cljs b/src/cljs/ulysses/components/misc.cljs index 20a0ef9..4986850 100644 --- a/src/cljs/ulysses/components/misc.cljs +++ b/src/cljs/ulysses/components/misc.cljs @@ -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 diff --git a/src/cljs/ulysses/pages/builder.cljs b/src/cljs/ulysses/pages/builder.cljs index 743da3c..29ebd2c 100644 --- a/src/cljs/ulysses/pages/builder.cljs +++ b/src/cljs/ulysses/pages/builder.cljs @@ -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]] @@ -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 @@ -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 diff --git a/src/sass/components/_builder-panel.scss b/src/sass/components/_builder-panel.scss index f1bedcc..82958ad 100644 --- a/src/sass/components/_builder-panel.scss +++ b/src/sass/components/_builder-panel.scss @@ -57,6 +57,11 @@ text-align: right; .btn { + margin-right: 3px; margin-top: 15px; + + &:last-of-type { + margin-right: 0; + } } }