Adding deleting, closing/opening and diff-cole/open added

This commit is contained in:
Gregg8 2018-01-11 18:15:02 +11:00
parent 3c80acd9db
commit f0ce08c77d
2 changed files with 289 additions and 248 deletions

View File

@ -23,6 +23,35 @@
(def pod-gap common/gs-19s) ;; or 31? (def pod-gap common/gs-19s) ;; or 31?
(def pad-padding common/gs-7s) (def pad-padding common/gs-7s)
;; TODO: START ========== LOCAL DATA - REPLACE WITH SUBS AND EVENTS
(def *pods (r/atom [{:id (gensym) :path "[\"x\" \"y\"]" :open? true :diff? true}
{:id (gensym) :path "[:abc 123]" :open? true :diff? false}
{:id (gensym) :path "[:a :b :c]" :open? false :diff? true}
{:id (gensym) :path "[\"hello\"]" :open? false :diff? false}]
#_[]))
(defn add-pod []
(let [id (gensym)]
(println "Added pod" id)
(swap! *pods concat [{:id id :path "" :open? true :diff? false}])))
(defn delete-pod [id]
(println "Deleted pod" id)
(reset! *pods (filterv #(not= id (:id %)) @*pods)))
(defn update-pod-field
[id field new-val]
(let [f (fn [pod]
(if (= id (:id pod))
(do
;(println "Updated" field "in" (:id pod) "from" (get pod field) "to" new-val)
(assoc pod field new-val))
pod))]
(reset! *pods (mapv f @*pods))))
;; TODO: END ========== LOCAL DATA - REPLACE WITH SUBS AND EVENTS
(defn panel-header [] (defn panel-header []
[rc/h-box [rc/h-box
:justify :between :justify :between
@ -35,7 +64,7 @@
:label [rc/v-box :label [rc/v-box
:align :center :align :center
:children ["+ path inspector"]] :children ["+ path inspector"]]
:on-click #(println "Clicked [+ path inspector]")] :on-click #(add-pod)]
[rc/h-box [rc/h-box
:align :center :align :center
:gap common/gs-7s :gap common/gs-7s
@ -47,11 +76,11 @@
:children [[rc/label :label "reset app-db to:"] :children [[rc/label :label "reset app-db to:"]
[rc/button [rc/button
:class "bm-muted-button" :class "bm-muted-button"
:style {:width "79px" :style {:width "129px"
:padding "0px"} :padding "0px"}
:label [rc/v-box :label [rc/v-box
:align :center :align :center
:children ["initial state"]] :children ["initial epoch state"]]
:on-click #(println "Clicked [initial state]")] :on-click #(println "Clicked [initial state]")]
[rc/v-box [rc/v-box
:width common/gs-81s :width common/gs-81s
@ -66,21 +95,21 @@
:label "PROCESSING"]]] :label "PROCESSING"]]]
[rc/button [rc/button
:class "bm-muted-button" :class "bm-muted-button"
:style {:width "79px" :style {:width "129px"
:padding "0px"} :padding "0px"}
:label [rc/v-box :label [rc/v-box
:align :center :align :center
:children ["end state"]] :children ["end epoch state"]]
:on-click #(println "Clicked [end state]")]]]]]) :on-click #(println "Clicked [end state]")]]]]])
(defn path-header [path] (defn pod-header [{:keys [id path open? diff?]}]
(let [search-string (r/atom (when (some? path) (prn-str path))) ;;(rf/subscribe [:app-db/search-string])
*pod-open (r/atom true)]
(fn [path]
[rc/h-box [rc/h-box
:class "app-db-path--header" :class "app-db-path--header"
:style {:border-top-left-radius "3px" :style (merge {:border-top-left-radius "3px"
:border-top-right-radius "3px"} :border-top-right-radius "3px"}
(when-not open?
{:border-bottom-left-radius "3px"
:border-bottom-right-radius "3px"}))
:align :center :align :center
:height common/gs-31s :height common/gs-31s
:children [[rc/box :children [[rc/box
@ -88,25 +117,22 @@
:height common/gs-31s :height common/gs-31s
:class "noselect" :class "noselect"
:style {:cursor "pointer"} :style {:cursor "pointer"}
:attr {:title (str (if @*pod-open "Close" "Open") " the pod bay doors, HAL") :attr {:title (str (if open? "Close" "Open") " the pod bay doors, HAL")
:on-click (rc/handler-fn :on-click (rc/handler-fn (update-pod-field id :open? (not open?)))}
(swap! *pod-open not)
(println "Clicked [arrow]"))}
:child [rc/box :child [rc/box
:margin "auto" :margin "auto"
:child [:span.arrow (if @*pod-open "▼" "▶")]]] :child [:span.arrow (if open? "▼" "▶")]]]
[rc/h-box [rc/h-box
:size "auto" :size "auto"
:class "app-db-path--path-header" :class "app-db-path--path-header"
:children [[rc/input-text :children [[rc/input-text
;:class (str "app-db-path--path-text " (when (nil? path) "app-db-path--path-text__empty"))
:style {:height "25px" :style {:height "25px"
:padding (css-join "0px" common/gs-7s) :padding (css-join "0px" common/gs-7s)
:width "-webkit-fill-available"} ;; This took a bit of finding! :width "-webkit-fill-available"} ;; This took a bit of finding!
:width "100%" :width "100%"
:model search-string :model path
:on-change (fn [input-string] (rf/dispatch [:app-db/search-string input-string])) :on-change #(update-pod-field id :path %) ;;(fn [input-string] (rf/dispatch [:app-db/search-string input-string]))
:on-submit #(rf/dispatch [:app-db/add-path %]) :on-submit #() ;; #(rf/dispatch [:app-db/add-path %])
:change-on-blur? false :change-on-blur? false
:placeholder "Showing all of app-db. Try entering a path like [:todos 1]"]]] :placeholder "Showing all of app-db. Try entering a path like [:todos 1]"]]]
[rc/gap-f :size common/gs-12s] [rc/gap-f :size common/gs-12s]
@ -118,7 +144,7 @@
:border-radius "3px" :border-radius "3px"
:cursor "pointer"} :cursor "pointer"}
:attr {:title "Show diff" :attr {:title "Show diff"
:on-click (rc/handler-fn (println "Clicked [copy]"))} :on-click (rc/handler-fn (update-pod-field id :diff? (not diff?)))}
:child [:img :child [:img
{:src (str "data:image/svg+xml;utf8," copy) {:src (str "data:image/svg+xml;utf8," copy)
:style {:width "19px" :style {:width "19px"
@ -132,29 +158,28 @@
:border-radius "3px" :border-radius "3px"
:cursor "pointer"} :cursor "pointer"}
:attr {:title "Remove this pod" :attr {:title "Remove this pod"
:on-click (rc/handler-fn :on-click (rc/handler-fn (delete-pod id))}
;(rf/dispatch [:app-db/remove-path %])
(println "Clicked [delete]"))}
:child [:img :child [:img
{:src (str "data:image/svg+xml;utf8," trash) {:src (str "data:image/svg+xml;utf8," trash)
:style {:width "13px" :style {:width "13px"
:margin "0px 6px"}}]] :margin "0px 6px"}}]]
[rc/gap-f :size common/gs-12s]]]))) [rc/gap-f :size common/gs-12s]]])
(defn pod [path] (defn pod [{:keys [id path open? diff?] :as pod-info}]
[rc/v-box [rc/v-box
:class "app-db-path" :class "app-db-path"
:style {:border-bottom-left-radius "3px" :style {:border-bottom-left-radius "3px"
:border-bottom-right-radius "3px"} :border-bottom-right-radius "3px"}
:children [[path-header path] :children [[pod-header pod-info]
(when open?
[rc/v-box [rc/v-box
:height "90px" :height "90px"
:min-width "100px" :min-width "100px"
:style {:background-color cljs-dev-tools-background :style {:background-color cljs-dev-tools-background
:padding common/gs-7s :padding common/gs-7s
:margin (css-join pad-padding pad-padding "0px" pad-padding)} :margin (css-join pad-padding pad-padding "0px" pad-padding)}
:children ["---main-section---"]] :children ["---main-section---"]])
(when (and open? diff?)
[rc/v-box [rc/v-box
:height common/gs-19s :height common/gs-19s
:justify :end :justify :end
@ -162,15 +187,16 @@
:children [[rc/hyperlink :children [[rc/hyperlink
;:class "app-db-path--label" ;:class "app-db-path--label"
:label "ONLY BEFORE" :label "ONLY BEFORE"
:on-click #(println "Clicked [ONLY BEFORE]")]]] :on-click #(println "Clicked [ONLY BEFORE]")]]])
(when (and open? diff?)
[rc/v-box [rc/v-box
:height "60px" :height "60px"
:min-width "100px" :min-width "100px"
:style {:background-color cljs-dev-tools-background :style {:background-color cljs-dev-tools-background
:padding common/gs-7s :padding common/gs-7s
:margin (css-join "0px" pad-padding)} :margin (css-join "0px" pad-padding)}
:children ["---before-diff---"]] :children ["---before-diff---"]])
(when (and open? diff?)
[rc/v-box [rc/v-box
:height common/gs-19s :height common/gs-19s
:justify :end :justify :end
@ -178,15 +204,17 @@
:children [[rc/hyperlink :children [[rc/hyperlink
;:class "app-db-path--label" ;:class "app-db-path--label"
:label "ONLY AFTER" :label "ONLY AFTER"
:on-click #(println "Clicked [ONLY AFTER]")]]] :on-click #(println "Clicked [ONLY AFTER]")]]])
(when (and open? diff?)
[rc/v-box [rc/v-box
:height "60px" :height "60px"
:min-width "100px" :min-width "100px"
:style {:background-color cljs-dev-tools-background :style {:background-color cljs-dev-tools-background
:padding common/gs-7s :padding common/gs-7s
:margin (css-join "0px" pad-padding)} :margin (css-join "0px" pad-padding)}
:children ["---after-diff---"]] :children ["---after-diff---"]])
[rc/gap-f :size pad-padding]]]) (when open?
[rc/gap-f :size pad-padding])]])
(defn no-pods [] (defn no-pods []
[rc/h-box [rc/h-box
@ -201,18 +229,13 @@
:label "add inspectors to show what happened to app-db"]]]) :label "add inspectors to show what happened to app-db"]]])
(defn pod-section [] (defn pod-section []
(let [
pods [["x" "y"] [:abc 123] nil]
;pods nil
]
(fn []
[rc/v-box [rc/v-box
:gap pod-gap :gap pod-gap
:children (if (empty? pods) :children (if (empty? @*pods)
[[no-pods]] [[no-pods]]
(doall (for [p pods] (doall (for [p @*pods]
^{:key (str p)} ^{:key (:id @*pods)}
[pod p])))]))) [pod p])))])
;; TODO: OLD UI - REMOVE ;; TODO: OLD UI - REMOVE
(defn original-render [app-db] (defn original-render [app-db]
@ -222,7 +245,11 @@
input-error (r/atom false) input-error (r/atom false)
snapshot-ready? (rf/subscribe [:snapshot/snapshot-ready?])] snapshot-ready? (rf/subscribe [:snapshot/snapshot-ready?])]
(fn [] (fn []
[:div {:style {:flex "1 1 auto" :display "flex" :flex-direction "column" :border "1px solid lightgrey"}} [:div
{:style {:flex "1 1 auto"
:display "flex"
:flex-direction "column"
:border "1px solid lightgrey"}}
[:div.panel-content-scrollable [:div.panel-content-scrollable
[rc/input-text [rc/input-text
:model search-string :model search-string
@ -282,7 +309,6 @@
:children [[panel-header] :children [[panel-header]
[pod-section] [pod-section]
[rc/gap-f :size pod-gap] [rc/gap-f :size pod-gap]
[original-render app-db]]])
;; TODO: OLD UI - REMOVE
#_[original-render app-db]]])

View File

@ -21,6 +21,27 @@
(def pod-gap common/gs-19s) ;; or 31? (def pod-gap common/gs-19s) ;; or 31?
(def pad-padding common/gs-7s) (def pad-padding common/gs-7s)
;; TODO: START ========== LOCAL DATA - REPLACE WITH SUBS AND EVENTS
(def *pods (r/atom [{:type :destroyed :layer "3" :path [:todo/blah] :open? true :diff? true}
{:type :created :layer "3" :path [:todo/completed] :open? true :diff? true}
{:type :re-run :layer "3" :path [:todo/completed] :open? true :diff? true}
{:type :re-run :layer "2" :path [:todo/blah] :open? true :diff? true}
{:type :not-run :layer "3" :path [:todo/blah] :open? true :diff? true}]
#_[]))
(defn update-pod-field
[id field new-val]
(let [f (fn [pod]
(if (= id (:id pod))
(do
;(println "Updated" field "in" (:id pod) "from" (get pod field) "to" new-val)
(assoc pod field new-val))
pod))]
(reset! *pods (mapv f @*pods))))
;; TODO: END ========== LOCAL DATA - REPLACE WITH SUBS AND EVENTS
(defn tag-color [type] (defn tag-color [type]
(let [types {:created "#9b51e0" (let [types {:created "#9b51e0"
:destroyed "#f2994a" :destroyed "#f2994a"
@ -88,10 +109,7 @@
:style {:margin-top "6px"} :style {:margin-top "6px"}
:on-change #()]]]]]) :on-change #()]]]]])
(defn path-header [{:keys [type layer path]}] (defn pod-header [{:keys [id type layer path open? diff?]}]
(let [search-string (r/atom (when (some? path) (prn-str path))) ;;(rf/subscribe [:app-db/search-string])
*pod-open (r/atom true)]
(fn [{:keys [type layer path]}]
[rc/h-box [rc/h-box
:class "app-db-path--header" :class "app-db-path--header"
:style {:border-top-left-radius "3px" :style {:border-top-left-radius "3px"
@ -103,13 +121,13 @@
:height common/gs-31s :height common/gs-31s
:class "noselect" :class "noselect"
:style {:cursor "pointer"} :style {:cursor "pointer"}
:attr {:title (str (if @*pod-open "Close" "Open") " the pod bay doors, HAL") :attr {:title (str (if open? "Close" "Open") " the pod bay doors, HAL")
:on-click (rc/handler-fn :on-click (rc/handler-fn
(swap! *pod-open not) (swap! open? not)
(println "Clicked [arrow]"))} (println "Clicked [arrow]"))}
:child [rc/box :child [rc/box
:margin "auto" :margin "auto"
:child [:span.arrow (if @*pod-open "▼" "▶")]]] :child [:span.arrow (if open? "▼" "▶")]]]
[rc/box [rc/box
:width "64px" ;; (100-36)px from box above :width "64px" ;; (100-36)px from box above
:child [tag type (-> type tag-desc :short)]] :child [tag type (-> type tag-desc :short)]]
@ -117,15 +135,14 @@
:size "auto" :size "auto"
:class "app-db-path--path-header" :class "app-db-path--path-header"
:children [[rc/input-text :children [[rc/input-text
;:class (str "app-db-path--path-text " (when (nil? path) "app-db-path--path-text__empty"))
:style {:height "25px" :style {:height "25px"
:padding (css-join "0px" common/gs-7s) :padding (css-join "0px" common/gs-7s)
:width "-webkit-fill-available"} ;; This took a bit of finding! :width "-webkit-fill-available"} ;; This took a bit of finding!
:width "100%" :width "100%"
:model search-string :model path
:disabled? true :disabled? true
:on-change (fn [input-string] (rf/dispatch [:app-db/search-string input-string])) :on-change #(update-pod-field id :path %) ;;(fn [input-string] (rf/dispatch [:app-db/search-string input-string]))
:on-submit #(rf/dispatch [:app-db/add-path %]) :on-submit #() ;; #(rf/dispatch [:app-db/add-path %])
:change-on-blur? false :change-on-blur? false
:placeholder "Showing all of app-db. Try entering a path like [:todos 1]"]]] :placeholder "Showing all of app-db. Try entering a path like [:todos 1]"]]]
[rc/gap-f :size common/gs-12s] [rc/gap-f :size common/gs-12s]
@ -139,27 +156,28 @@
:border-radius "3px" :border-radius "3px"
:cursor "pointer"} :cursor "pointer"}
:attr {:title "Show diff" :attr {:title "Show diff"
:on-click (rc/handler-fn (println "Clicked [copy]"))} :on-click (rc/handler-fn (update-pod-field id :diff? (not diff?)))}
:child [:img :child [:img
{:src (str "data:image/svg+xml;utf8," copy) {:src (str "data:image/svg+xml;utf8," copy)
:style {:width "19px" :style {:width "19px"
:margin "0px 3px"}}]] :margin "0px 3px"}}]]
[rc/gap-f :size common/gs-12s]]]))) [rc/gap-f :size common/gs-12s]]])
(defn pod [pod-info] (defn pod [{:keys [id type layer path open? diff?] :as pod-info}]
[rc/v-box [rc/v-box
:class "app-db-path" :class "app-db-path"
:style {:border-bottom-left-radius "3px" :style {:border-bottom-left-radius "3px"
:border-bottom-right-radius "3px"} :border-bottom-right-radius "3px"}
:children [[path-header pod-info] :children [[pod-header pod-info]
(when open?
[rc/v-box [rc/v-box
:height "90px" :height "90px"
:min-width "100px" :min-width "100px"
:style {:background-color cljs-dev-tools-background :style {:background-color cljs-dev-tools-background
:padding common/gs-7s :padding common/gs-7s
:margin (css-join pad-padding pad-padding "0px" pad-padding)} :margin (css-join pad-padding pad-padding "0px" pad-padding)}
:children ["---main-section---"]] :children ["---main-section---"]])
(when (and open? diff?)
[rc/v-box [rc/v-box
:height common/gs-19s :height common/gs-19s
:justify :end :justify :end
@ -167,15 +185,16 @@
:children [[rc/hyperlink :children [[rc/hyperlink
;:class "app-db-path--label" ;:class "app-db-path--label"
:label "ONLY BEFORE" :label "ONLY BEFORE"
:on-click #(println "Clicked [ONLY BEFORE]")]]] :on-click #(println "Clicked [ONLY BEFORE]")]]])
(when (and open? diff?)
[rc/v-box [rc/v-box
:height "60px" :height "60px"
:min-width "100px" :min-width "100px"
:style {:background-color cljs-dev-tools-background :style {:background-color cljs-dev-tools-background
:padding common/gs-7s :padding common/gs-7s
:margin (css-join "0px" pad-padding)} :margin (css-join "0px" pad-padding)}
:children ["---before-diff---"]] :children ["---before-diff---"]])
(when (and open? diff?)
[rc/v-box [rc/v-box
:height common/gs-19s :height common/gs-19s
:justify :end :justify :end
@ -183,15 +202,17 @@
:children [[rc/hyperlink :children [[rc/hyperlink
;:class "app-db-path--label" ;:class "app-db-path--label"
:label "ONLY AFTER" :label "ONLY AFTER"
:on-click #(println "Clicked [ONLY AFTER]")]]] :on-click #(println "Clicked [ONLY AFTER]")]]])
(when (and open? diff?)
[rc/v-box [rc/v-box
:height "60px" :height "60px"
:min-width "100px" :min-width "100px"
:style {:background-color cljs-dev-tools-background :style {:background-color cljs-dev-tools-background
:padding common/gs-7s :padding common/gs-7s
:margin (css-join "0px" pad-padding)} :margin (css-join "0px" pad-padding)}
:children ["---after-diff---"]] :children ["---after-diff---"]])
[rc/gap-f :size pad-padding]]]) (when open?
[rc/gap-f :size pad-padding])]])
(defn no-pods [] (defn no-pods []
[rc/h-box [rc/h-box
@ -202,22 +223,13 @@
:children [[rc/label :label "There are no subscriptions to show"]]]) :children [[rc/label :label "There are no subscriptions to show"]]])
(defn pod-section [] (defn pod-section []
(let [
pods [{:type :destroyed :layer "3" :path [:todo/blah]}
{:type :created :layer "3" :path [:todo/completed]}
{:type :re-run :layer "3" :path [:todo/completed]}
{:type :re-run :layer "2" :path [:todo/blah]}
{:type :not-run :layer "3" :path [:todo/blah]}]
;pods nil
]
(fn []
[rc/v-box [rc/v-box
:gap pod-gap :gap pod-gap
:children (if (empty? pods) :children (if (empty? @*pods)
[[no-pods]] [[no-pods]]
(doall (for [p pods] (doall (for [p @*pods]
^{:key (str p)} ^{:key (str p)}
[pod p])))]))) [pod p])))])
(defn render [] (defn render []
[] []
@ -228,8 +240,11 @@
[rc/gap-f :size pod-gap] [rc/gap-f :size pod-gap]
;; TODO: OLD UI - REMOVE ;; TODO: OLD UI - REMOVE
[:div.panel-content-scrollable {:style {:border "1px solid lightgrey"}} #_[:div.panel-content-scrollable
[:div.subtrees {:style {:margin "20px 0"}} {:style {:border "1px solid lightgrey"
:margin "0px"}}
[:div.subtrees
{:style {:margin "20px 0"}}
(doall (doall
(->> @subs/query->reaction (->> @subs/query->reaction
(sort-by (fn [me] (ffirst (key me)))) (sort-by (fn [me] (ffirst (key me))))