wip rework of html generation

This commit is contained in:
bom 2021-08-30 13:49:45 +02:00
parent 581336e803
commit 6cb74163fe
3 changed files with 81 additions and 65 deletions

View file

@ -22,66 +22,6 @@
::aws-access-key-id ::aws-secret-access-key
::restic-password]))
; START OF HTML EDIT REFACTOR
; TODO: Move this to somewhere in commons
(def htest (hz/hickory-zip (hc/as-hickory (hc/parse (clojure.core/slurp "public/index.html")))))
(defn-spec generate-feedback-tag map?
[id string?]
{:type :element :attrs {:class "invalid-feedback"} :tag :div :content [{:type :element :attrs {:id (str id "-validation")} :tag :pre :content "nil"}]})
(defn-spec generate-label map?
[id-for string?
label string?]
{:type :element :attrs {:for id-for :class "form-label"} :tag :label :content [label]})
(defn-spec generate-input-field vector?
[id string?
label string?
default-value string?]
[(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-spec generate-text-area vector?
[id string?
label string?
default-value string?
rows int?]
[(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)])
; TODO: add br tags
; TODO: add generate button
; TODO: add output text-area
(defn generate-content
[]
(conj (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-input-field "issuer" "(Optional) Your issuer prod/staging:" "")
(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)))
(defn find-map
[zipper]
(if (and (not (zip/end? zipper))
(map? (zip/node zipper))
(= (:class (:attrs (zip/node zipper))) "needs-validation"))
;replace instead of print later
(println (assoc (zip/node zipper) :content (generate-content)))
nil)
(find-map (zip/next zipper)))
; END REFACTOR
(defn k8s-objects [config]
(into
[]
@ -105,6 +45,82 @@
(yaml/to-string (backup/generate-secret config))
(yaml/to-string (backup/generate-cron))]))))
; START OF HTML EDIT REFACTOR
; TODO: Move this to somewhere in commons
(def htest (hz/hickory-zip (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]
[(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]
[(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-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 []})
; TODO: add br tags
; TODO: add generate button
; TODO: add output text-area
(defn generate-content
[]
(conj
(assoc (generate-needs-validation) :content
(conj (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-input-field "issuer" "(Optional) Your issuer prod/staging:" "")
(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-output "c4k-keycloak-output" "Your c4k deployment.yaml:" 25)))
(defn find-map
[zipper]
(if (not (zip/end? zipper))
(find-map (zip/next zipper))
(zip/node zipper))
(if (and (map? (zip/node zipper))
(= (:class (:attrs (zip/node zipper))) "container jumbotron"))
;replace instead of print later
(assoc (zip/node zipper) :content (generate-content))))
; END REFACTOR
(defn-spec generate any?
[my-config config?
my-auth auth?]

View file

@ -1,5 +1,5 @@
{: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"}
:aws-access-key-id "AKIA5GS5HGNWZYV7TH5N"
:aws-secret-access-key "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"
:restic-password ""}

View file

@ -1,4 +1,4 @@
{:fqdn "jira-neu.prod.meissa-gmbh.de"
{:fqdn "jira-neu.test.meissa-gmbh.de"
:jira-data-volume-path "/var/jira"
:postgres-data-volume-path "/var/postgres"
:restic-repository "restic-repository"}
:restic-repository "PiepoN0zmee4ejuHzooni8Pa"}