Skip to content

Commit

Permalink
more work.
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremykross committed Mar 15, 2019
1 parent bb4316b commit d6a48e4
Show file tree
Hide file tree
Showing 4 changed files with 172 additions and 90 deletions.
81 changes: 47 additions & 34 deletions src/konstellate/components.cljs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns konstellate.components
(:require
recurrent.drivers.vdom
recurrent.drivers.rum
[recurrent.core :as recurrent :include-macros true]
[ulmus.keyboard :as keyboard]
[ulmus.signal :as ulmus]))
Expand All @@ -10,6 +10,7 @@
{:recurrent/dom-$
(ulmus/signal-of [:div {:class "title-bar"}
[:img {:src "images/logo.svg"}]
[:div {:class "import"} "Import"]
[:div {:class "more button"} "Export"
[:img {:src "images/down.svg"}]]])})

Expand All @@ -30,71 +31,83 @@

(recurrent/defcomponent WorkspaceLabel
[props sources]
(let [open?-$ (ulmus/reduce not true ((:recurrent/dom-$ sources) ".label-open-arrow" "click"))
resource-fn (fn [id selected? r] [:div {:attributes {:data-id (str (name id))}
(let [selected?-$ (ulmus/map (fn [selected-id] (= selected-id (:id props))) (:selected-$ sources))

open?-$ selected?-$

menu-open?-$
(ulmus/merge
(ulmus/reduce
(fn [v e] (.stopPropagation e) true)
false
((:recurrent/dom-$ sources) ".workspace-more" "click"))
(ulmus/map (constantly false) ((:recurrent/dom-$ sources) :root "click")))

resource-fn (fn [id selected? r] [:div {:data-id (str (name id))
:class (str "workspace-label-resource " (if selected? "selected"))
:draggable true}
[:div {:class "dot"}]
(str r)])

value-$ (ulmus/map
#(.-value (.-target %))
((:recurrent/dom-$ sources) "input" "keypress"))
(fn [e]
(println "Value:" (.-value (.-target e)))
(.-value (.-target e)))
((:recurrent/dom-$ sources) "input" "input"))


editing?-$
(ulmus/start-with! true
(ulmus/merge
(ulmus/map (constantly true)
((:recurrent/dom-$ sources) ".label-standard-content" "dblclick"))
((:recurrent/dom-$ sources) ".action-rename" "click"))
(ulmus/map (constantly false)
(keyboard/press 13))))]

; external
; name-$

; own
; confirm?-$

; out
; rename-$
; save-$
; remove-$

{:rename-$
(ulmus/map (fn [new-value] {:id (:id props)
:new-value new-value})
(ulmus/sample-on value-$ (ulmus/filter not editing?-$)))
(ulmus/map (fn [new-value]
(println "new-value:" new-value)
{:id (:id props)
:new-value new-value})
(ulmus/sample-on value-$ (ulmus/filter false? editing?-$)))
:recurrent/dom-$ (ulmus/map
(fn [[workspace selected-nodes open? selected? editing?]]
[:div {:attributes {:data-id (str (name (:id props)))}
(fn [[workspace open? menu-open? selected? editing?]]
[:div {:data-id (str (name (:id props)))
:class "workspace-label"
:draggable (not editing?)}
[:div {:class (str "workspace-label-content "
(if selected? "selected ")
(if open? "open"))}
[:div {:class "floating-menu"}
[:div {:class (str "floating-menu " (if menu-open? "open"))}
[:ol {}
[:li {:class "floating-menu-item"} "Rename"]
[:li {:class "floating-menu-item"} "Delete"]
[:li {:class "floating-menu-item"} "Clone"]]]
[:li {:class "floating-menu-item action-rename"} "Rename"]
[:li {:class "floating-menu-item action-delete"} "Delete"]]]
(if (not editing?)
[:div {:class "label-standard-content"}
[:div {:class "outer"}
[:img {:class "label-open-arrow" :src "images/down.svg"}]
[:div {:class "the-name"} (:name workspace)]]
[:div {:class "inner"}
[:div {:class "the-name"} (:name workspace)]
[:i {:class "material-icons workspace-more"} "more_vert"]]
[:div (assoc {:class "inner"}
:style (if open?
{:height (str (* 40 (count (:yaml workspace))) "px")}))
(map #(apply resource-fn %)
(map (fn [[id r]]
[id
(some #{id} selected-nodes)
(some #{id} (:selected-nodes workspace))
(get-in r [:metadata :name])])
(:yaml workspace)))]]
[:div {:class "label-edit-content text-input"}
[:input {:autofocus true :placeholder "Name Workspace" :type "text"}]])]])
[:div {:class "enter-to-continue"} "Enter"]
[:input {:autofocus true
:placeholder "Name Workspace"
:type "text"
:default-value (if (= (:name workspace) "New Workspace") "" (:name workspace))}]])]])
(ulmus/zip
(:workspace-$ sources)
(:selected-nodes-$ sources)
open?-$
(ulmus/map (fn [selected-id] (= selected-id (:id props))) (:selected-$ sources))
menu-open?-$
selected?-$
editing?-$))}))

; workspaces-$ {:gensym "Foo"}
Expand All @@ -107,6 +120,7 @@
(fn [e] (keyword (.getAttribute (.-currentTarget e) "data-id")))
((:recurrent/dom-$ sources) ".workspace-label" "click"))
labels-$ (ulmus/reduce (fn [acc [added removed]]
(println (keys acc))
(as-> acc a
(apply dissoc a (keys removed))
(merge
Expand All @@ -118,9 +132,8 @@
{:id k}
{:workspace-$ (ulmus/map #(get % k) (:workspaces-$ sources))
:selected-$ selected-$
:selected-nodes-$ (:selected-nodes-$ sources)
:recurrent/dom-$ (:recurrent/dom-$ sources)})]) added)))))
{}
(sorted-map)
(ulmus/changed-keys (:workspaces-$ sources)))
kw-id (fn [e]
(.stopPropagation e)
Expand Down
87 changes: 58 additions & 29 deletions src/konstellate/core.cljs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
(ns konstellate.core
(:require
recurrent.core
recurrent.drivers.vdom
recurrent.drivers.rum
[clojure.string :as string]
[konstellate.components :as components]
[konstellate.editor.core :as editor]
[konstellate.exporter :as exporter]
[konstellate.graffle.core :as graffle]
[konstellate.resource-desc :as desc]
[recurrent.state :as state]
[ulmus.signal :as ulmus]))

Expand All @@ -20,8 +21,8 @@
:yaml {:gensym-b {:foo "bar"}}}}
:gensym1 {:edited {:name "Bar"}}}})

(def initial-state {:selected-nodes #{}
:workspaces {}})
(def initial-state {:workspaces {}})


(defn Main
[props sources]
Expand All @@ -41,15 +42,14 @@
:open?-$ (ulmus/reduce not false ((:recurrent/dom-$ sources) ".more" "click"))
:items-$ (ulmus/signal-of ["Export To Yaml" "Export To Kustomize" "Export To Helm"])}))

selected-nodes-$ (ulmus/map :selected-nodes (:recurrent/state-$ sources))

workspaces-$
(ulmus/map
(fn [state]
(into {}
(into (sorted-map)
(map (fn [[id workspace]]
[id {:name (get-in workspace [:edited :name])
:yaml (get-in workspace [:edited :yaml])
:selected-nodes (get-in workspace [:edited :selected-nodes])
:dirty? (not= (get-in workspace [:canonical :yaml])
(get-in workspace [:edited :yaml]))}])
(:workspaces state))))
Expand All @@ -65,7 +65,16 @@
{}
(assoc
(select-keys sources [:recurrent/dom-$ :recurrent/state-$])
:selected-nodes-$ selected-nodes-$))]) gained))))
:selected-nodes-$
(ulmus/map
(fn [state]
(get-in state
[:workspaces
k
:edited
:selected-nodes]))
(:recurrent/state-$ sources))))])
gained))))
{}
(ulmus/distinct
(ulmus/map #(map keys %)
Expand All @@ -75,12 +84,16 @@
(components/WorkspaceList
{}
{:recurrent/dom-$ (:recurrent/dom-$ sources)
:selected-nodes-$ (ulmus/map :selected-nodes (:recurrent/state-$ sources))
:workspaces-$ workspaces-$})

selected-workspace-$ (ulmus/map
#(apply get %)
(ulmus/zip workspaces-$
(:selected-$ workspace-list)))
selected-graffle-$
(ulmus/map
#(apply get %) (ulmus/zip workspace-graffle-$ (:selected-$ workspace-list)))
(ulmus/distinct
(ulmus/map
#(apply get %) (ulmus/zip workspace-graffle-$ (:selected-$ workspace-list))))

kind-picker
(editor/KindPicker
Expand Down Expand Up @@ -139,8 +152,8 @@
(ulmus/sample-on
(ulmus/map
first
(ulmus/map :selected-nodes (:recurrent/state-$ sources)))
((:recurrent/dom-$ sources) ".button.edit-resource" "click"))))
(ulmus/pickmap :selected-nodes-$ selected-graffle-$))
((:recurrent/dom-$ sources) ".edit-resource" "click"))))

side-panel
(components/SidePanel
Expand All @@ -166,13 +179,20 @@
(components/InfoPanel
{}
{:dom-$ (ulmus/map (fn [resource]
`[:div {}
[:div {:class "heading"}
[:h3 {} ~(get-in resource [:metadata :name])]
[:div {:class "edit"} "Edit"]]
[:div {:class "info"}
[:h4 {} "Kind"]
[:div {} ~(:kind resource)]]])
(let [description (desc/deployment resource)]
(println description)
`[:div {}
[:div {:class "heading"}
[:h3 {} ~(get-in resource [:metadata :name])]
[:div {:class "edit-resource"} "Edit"]]
[:div {:class "info"}
~(map (fn [{:keys [label value]}]
[[:h4 {} label]
[:div {}
(if (empty? (str value))
"--"
(str value))]])
description)]]))
(ulmus/map #(first (vals %))
(ulmus/pickmap :selected-resources-$ selected-graffle-$)))
:open?-$ info-panel-open?-$
Expand Down Expand Up @@ -211,23 +231,29 @@
(:workspaces
@(:recurrent/state-$ sources))))))


{:swagger-$ (ulmus/signal-of [:get])
:state-$ (:recurrent/state-$ sources)
:recurrent/state-$ (ulmus/merge
(ulmus/signal-of (fn [] initial-state))
(ulmus/pickmap :recurrent/state-$ editor-$)
(ulmus/map (fn [selected]
(fn [state]
(assoc state
:selected-nodes selected)))
(assoc-in state
[:workspaces
@(:selected-$ workspace-list)
:edited
:selected-nodes]
selected)))
(ulmus/distinct
(ulmus/pickmap :selected-nodes-$ selected-graffle-$)))
(ulmus/map (fn [e]
(fn [state]
(let [id (keyword (.getAttribute (.-currentTarget e) "data-id"))]
(assoc state
:selected-nodes
(assoc-in state
[:workspaces
@(:selected-$ workspace-list)
:edited
:selected-nodes]
#{id}))))
((:recurrent/dom-$ sources) ".workspace-label-resource" "click"))
(ulmus/map (fn [e]
Expand Down Expand Up @@ -282,27 +308,30 @@
((:recurrent/dom-$ sources) ".add-resource" "click"))
(ulmus/map (constantly :editor)
(ulmus/merge
((:recurrent/dom-$ sources) ".button.edit-resource" "click")
((:recurrent/dom-$ sources) ".edit-resource" "click")
(:selected-$ kind-picker)))
(ulmus/map (constantly :workspace)
(ulmus/pickmap :save-$ editor-$))))
{:workspace
(ulmus/map
(fn [[title-bar-dom side-panel-dom info-panel-dom menu-dom info-panel-open? graffle]]
(fn [[title-bar-dom side-panel-dom info-panel-dom menu-dom info-panel-open? workspace graffle]]
[:div {:class "main"}
[:div {:class (str "action-button add-resource " (if info-panel-open? "panel-open"))} "+"]
title-bar-dom
menu-dom
[:div {:class "main-content"}
side-panel-dom
[:div {:class "graffle"} graffle]
[:div {:class "graffle"}
[:h4 {:class "workspace-title"} (get workspace :name)]
graffle]
info-panel-dom]])
(ulmus/distinct
(ulmus/zip (:recurrent/dom-$ title-bar)
(:recurrent/dom-$ side-panel)
(:recurrent/dom-$ info-panel)
(:recurrent/dom-$ menu)
info-panel-open?-$
selected-workspace-$
(ulmus/pickmap :recurrent/dom-$ selected-graffle-$))))
:editor (ulmus/pickmap :recurrent/dom-$ editor-$)
:kind-picker (:recurrent/dom-$ kind-picker)})}))
Expand All @@ -314,8 +343,8 @@
(state/with-state Main)
{}
{:swagger-$ (recurrent.drivers.http/create! swagger-path {:with-credentials? false})
:recurrent/dom-$ (recurrent.drivers.vdom/for-id! "app")})))
:recurrent/dom-$ (recurrent.drivers.rum/create! "app")})))

(set! (.-onerror js/window) #(println %))


(.addEventListener js/document "DOMContentLoaded" start!)
19 changes: 19 additions & 0 deletions src/konstellate/resource_desc.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
(ns konstellate.resource-desc
(:require [clojure.string :as string]))

(defn general
[r]
[{:label "Kind"
:value (:kind r)}
{:label "Labels"
:value (string/join "\n"
(map (fn [[k v]]
(str (name k) " : " v))
(get-in r [:metadata :labels])))}])

(defn deployment
[r]
(into
(general r)
[{:label "Replicas"
:value (get-in r [:spec :replicas])}]))
Loading

0 comments on commit d6a48e4

Please sign in to comment.