moved html refactor
This commit is contained in:
parent
bc5950cc38
commit
561f8fade6
4 changed files with 38 additions and 119 deletions
|
@ -7,10 +7,7 @@
|
||||||
[dda.c4k-common.yaml :as yaml]
|
[dda.c4k-common.yaml :as yaml]
|
||||||
[dda.c4k-common.postgres :as postgres]
|
[dda.c4k-common.postgres :as postgres]
|
||||||
[dda.c4k-jira.jira :as jira]
|
[dda.c4k-jira.jira :as jira]
|
||||||
[dda.c4k-jira.backup :as backup]
|
[dda.c4k-jira.backup :as backup]))
|
||||||
[clojure.walk :refer [postwalk]]
|
|
||||||
[hickory.core :as hc]
|
|
||||||
[hickory.render :as hr]))
|
|
||||||
|
|
||||||
(def config-defaults {:issuer :staging})
|
(def config-defaults {:issuer :staging})
|
||||||
|
|
||||||
|
@ -45,99 +42,6 @@
|
||||||
(yaml/to-string (backup/generate-secret config))
|
(yaml/to-string (backup/generate-secret config))
|
||||||
(yaml/to-string (backup/generate-cron))]))))
|
(yaml/to-string (backup/generate-cron))]))))
|
||||||
|
|
||||||
; START OF HTML EDIT REFACTOR
|
|
||||||
; TODO: Move this to somewhere in commons
|
|
||||||
|
|
||||||
(def htest (hc/as-hickory (hc/parse (clojure.core/slurp "public/index.html"))))
|
|
||||||
|
|
||||||
(defn generate-feedback-tag
|
|
||||||
[id]
|
|
||||||
[{:type :element :attrs {:class "invalid-feedback"} :tag :div :content [{:type :element :attrs {:id (str id "-validation")} :tag :pre :content nil}]}])
|
|
||||||
|
|
||||||
(defn generate-label
|
|
||||||
[id-for
|
|
||||||
label]
|
|
||||||
[{:type :element :attrs {:for id-for :class "form-label"} :tag :label :content [label]}])
|
|
||||||
|
|
||||||
(defn generate-input-field
|
|
||||||
[id
|
|
||||||
label
|
|
||||||
default-value]
|
|
||||||
(concat (generate-label id label)
|
|
||||||
[{:type :element :attrs {:class "form-control" :type "text" :name id :value default-value} :tag :input :content nil}]
|
|
||||||
(generate-feedback-tag id)))
|
|
||||||
|
|
||||||
(defn generate-text-area
|
|
||||||
[id
|
|
||||||
label
|
|
||||||
default-value
|
|
||||||
rows]
|
|
||||||
(concat (generate-label id label)
|
|
||||||
[{:type :element :attrs {:name id :id id :class "form-control" :rows rows} :tag :textarea :content [default-value]}]
|
|
||||||
(generate-feedback-tag id)))
|
|
||||||
|
|
||||||
(defn generate-button
|
|
||||||
[id
|
|
||||||
label]
|
|
||||||
[{:type :element
|
|
||||||
:attrs {:type "button", :id id, :class "btn btn-primary"}
|
|
||||||
:tag :button
|
|
||||||
:content [label]}])
|
|
||||||
|
|
||||||
(defn generate-br
|
|
||||||
[]
|
|
||||||
[{:type :element, :attrs nil, :tag :br, :content nil}])
|
|
||||||
|
|
||||||
(defn generate-output
|
|
||||||
[id
|
|
||||||
label
|
|
||||||
rows]
|
|
||||||
[{:type :element, :attrs {:id id}, :tag :div, :content [{:type :element, :attrs {:for "output", :class "form-label"}, :tag :label, :content [label]}
|
|
||||||
{:type :element, :attrs {:name "output", :id "output", :class "form-control", :rows rows}, :tag :textarea, :content []}]}])
|
|
||||||
|
|
||||||
(defn generate-needs-validation
|
|
||||||
[]
|
|
||||||
{:type :element, :attrs {:class "needs-validation", :id "form"}, :tag :form, :content []})
|
|
||||||
|
|
||||||
(defn generate-content
|
|
||||||
[]
|
|
||||||
(into [] (concat [(assoc (generate-needs-validation) :content
|
|
||||||
(into [] (concat (generate-input-field "fqdn" "Your fqdn:" "jira-neu.prod.meissa-gmbh.de")
|
|
||||||
(generate-input-field "jira-data-volume-path" "(Optional) Your jira-data-volume-path:" "/var/jira")
|
|
||||||
(generate-input-field "postgres-data-volume-path" "(Optional) Your postgres-data-volume-path:" "/var/postgres")
|
|
||||||
(generate-input-field "restic-repository" "(Optional) Your restic-repository:" "restic-repository")
|
|
||||||
(generate-br)
|
|
||||||
(generate-input-field "issuer" "(Optional) Your issuer prod/staging:" "")
|
|
||||||
(generate-br)
|
|
||||||
(generate-br)
|
|
||||||
(generate-text-area "auth" "Your auth.edn:" "{:postgres-db-user \" jira \"
|
|
||||||
:postgres-db-password \" jira-db-password \"
|
|
||||||
:aws-access-key-id \" aws-id \"
|
|
||||||
:aws-secret-access-key \" aws-secret \"
|
|
||||||
:restic-password \" restic-password \"}"
|
|
||||||
"5")
|
|
||||||
(generate-br)
|
|
||||||
(generate-br)
|
|
||||||
(generate-button "generate-button" "Generate c4k yaml"))))]
|
|
||||||
(generate-br)
|
|
||||||
(generate-br)
|
|
||||||
(generate-output "c4k-keycloak-output" "Your c4k deployment.yaml:" "25"))))
|
|
||||||
|
|
||||||
(defn find-map
|
|
||||||
[coll]
|
|
||||||
(postwalk #(if (and (map? %)
|
|
||||||
(= (:class (:attrs %)) "container jumbotron"))
|
|
||||||
{:type :element
|
|
||||||
:attrs {:class "container jumbotron"}
|
|
||||||
:tag :div
|
|
||||||
:content (generate-content)}
|
|
||||||
%)
|
|
||||||
coll))
|
|
||||||
|
|
||||||
(def htest2 (hr/hickory-to-html (find-map htest)))
|
|
||||||
|
|
||||||
; END REFACTOR
|
|
||||||
|
|
||||||
(defn-spec generate any?
|
(defn-spec generate any?
|
||||||
[my-config config?
|
[my-config config?
|
||||||
my-auth auth?]
|
my-auth auth?]
|
||||||
|
|
|
@ -6,6 +6,30 @@
|
||||||
[dda.c4k-common.browser :as br]
|
[dda.c4k-common.browser :as br]
|
||||||
[dda.c4k-common.postgres :as pgc]))
|
[dda.c4k-common.postgres :as pgc]))
|
||||||
|
|
||||||
|
(defn generate-content
|
||||||
|
[]
|
||||||
|
(into [] (concat [(assoc (generate-needs-validation) :content
|
||||||
|
(into [] (concat (generate-input-field "fqdn" "Your fqdn:" "jira-neu.prod.meissa-gmbh.de")
|
||||||
|
(generate-input-field "jira-data-volume-path" "(Optional) Your jira-data-volume-path:" "/var/jira")
|
||||||
|
(generate-input-field "postgres-data-volume-path" "(Optional) Your postgres-data-volume-path:" "/var/postgres")
|
||||||
|
(generate-input-field "restic-repository" "(Optional) Your restic-repository:" "restic-repository")
|
||||||
|
(generate-br)
|
||||||
|
(generate-input-field "issuer" "(Optional) Your issuer prod/staging:" "")
|
||||||
|
(generate-br)
|
||||||
|
(generate-br)
|
||||||
|
(generate-text-area "auth" "Your auth.edn:" "{:postgres-db-user \" jira \"
|
||||||
|
:postgres-db-password \" jira-db-password \"
|
||||||
|
:aws-access-key-id \" aws-id \"
|
||||||
|
:aws-secret-access-key \" aws-secret \"
|
||||||
|
:restic-password \" restic-password \"}"
|
||||||
|
"5")
|
||||||
|
(generate-br)
|
||||||
|
(generate-br)
|
||||||
|
(generate-button "generate-button" "Generate c4k yaml"))))]
|
||||||
|
(generate-br)
|
||||||
|
(generate-br)
|
||||||
|
(generate-output "c4k-keycloak-output" "Your c4k deployment.yaml:" "25"))))
|
||||||
|
|
||||||
(defn config-from-document []
|
(defn config-from-document []
|
||||||
(let [jira-data-volume-path (br/get-content-from-element "jira-data-volume-path" :optional true)
|
(let [jira-data-volume-path (br/get-content-from-element "jira-data-volume-path" :optional true)
|
||||||
postgres-data-volume-path (br/get-content-from-element "postgres-data-volume-path" :optional true)
|
postgres-data-volume-path (br/get-content-from-element "postgres-data-volume-path" :optional true)
|
||||||
|
@ -32,6 +56,10 @@
|
||||||
(br/validate! "auth" core/auth? :deserializer edn/read-string)
|
(br/validate! "auth" core/auth? :deserializer edn/read-string)
|
||||||
(br/set-validated!))
|
(br/set-validated!))
|
||||||
|
|
||||||
|
(defn add-validate-listener [name]
|
||||||
|
(-> (br/get-element-by-id name)
|
||||||
|
(.addEventListener "blur" #(do (validate-all!)))))
|
||||||
|
|
||||||
(defn init []
|
(defn init []
|
||||||
(-> js/document
|
(-> js/document
|
||||||
(.getElementById "generate-button")
|
(.getElementById "generate-button")
|
||||||
|
@ -41,22 +69,9 @@
|
||||||
(config-from-document)
|
(config-from-document)
|
||||||
(br/get-content-from-element "auth" :deserializer edn/read-string))
|
(br/get-content-from-element "auth" :deserializer edn/read-string))
|
||||||
(br/set-output!)))))
|
(br/set-output!)))))
|
||||||
(-> (br/get-element-by-id "fqdn")
|
(add-validate-listener "fqdn")
|
||||||
(.addEventListener "blur"
|
(add-validate-listener "jira-data-volume-path")
|
||||||
#(do (validate-all!))))
|
(add-validate-listener "postgres-data-volume-path")
|
||||||
(-> (br/get-element-by-id "jira-data-volume-path")
|
(add-validate-listener "restic-repository")
|
||||||
(.addEventListener "blur"
|
(add-validate-listener "issuer")
|
||||||
#(do (validate-all!))))
|
(add-validate-listener "auth"))
|
||||||
(-> (br/get-element-by-id "postgres-data-volume-path")
|
|
||||||
(.addEventListener "blur"
|
|
||||||
#(do (validate-all!))))
|
|
||||||
(-> (br/get-element-by-id "restic-repository")
|
|
||||||
(.addEventListener "blur"
|
|
||||||
#(do (validate-all!))))
|
|
||||||
(-> (br/get-element-by-id "issuer")
|
|
||||||
(.addEventListener "blur"
|
|
||||||
#(do (validate-all!))))
|
|
||||||
(-> (br/get-element-by-id "auth")
|
|
||||||
(.addEventListener "blur"
|
|
||||||
#(do (validate-all!))))
|
|
||||||
)
|
|
|
@ -1,5 +1,5 @@
|
||||||
{:postgres-db-user "jira"
|
{:postgres-db-user "jira"
|
||||||
:postgres-db-password "jira-db-password"
|
:postgres-db-password "jira-db-password"
|
||||||
:aws-access-key-id "AKIA5GS5HGNWZYV7TH5N"
|
:aws-access-key-id ""
|
||||||
:aws-secret-access-key "UW3ongIEVcr8DSAwVI5BoEhvrJXfOQPhMJf/rvns"
|
:aws-secret-access-key ""
|
||||||
:restic-password ""}
|
:restic-password ""}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
{:fqdn "jira-neu.test.meissa-gmbh.de"
|
{:fqdn "jira-neu.test.meissa-gmbh.de"
|
||||||
:jira-data-volume-path "/var/jira"
|
:jira-data-volume-path "/var/jira"
|
||||||
:postgres-data-volume-path "/var/postgres"
|
:postgres-data-volume-path "/var/postgres"
|
||||||
:restic-repository "PiepoN0zmee4ejuHzooni8Pa"}
|
:restic-repository ""}
|
||||||
|
|
Reference in a new issue