From 1f77840be966762fd861f03b12af4330f45f05cf Mon Sep 17 00:00:00 2001 From: bom Date: Mon, 9 Aug 2021 14:12:55 +0200 Subject: [PATCH] added hickory dep, started refactor for html --- project.clj | 3 +- shadow-cljs.edn | 3 +- src/main/cljc/dda/c4k_jira/core.cljc | 65 +++++++++++++++++++++++++++- 3 files changed, 68 insertions(+), 3 deletions(-) diff --git a/project.clj b/project.clj index 929e5ae..f9567d7 100644 --- a/project.clj +++ b/project.clj @@ -5,7 +5,8 @@ :url "https://www.apache.org/licenses/LICENSE-2.0.html"} :dependencies [[org.clojure/clojure "1.10.3"] [org.clojure/tools.reader "1.3.4"] - [org.domaindrivenarchitecture/c4k-common-clj "0.2.8"]] + [org.domaindrivenarchitecture/c4k-common-clj "0.2.8"] + [hickory "0.7.1"]] :target-path "target/%s/" :source-paths ["src/main/cljc" "src/main/clj"] diff --git a/shadow-cljs.edn b/shadow-cljs.edn index 6662142..7e72179 100644 --- a/shadow-cljs.edn +++ b/shadow-cljs.edn @@ -4,7 +4,8 @@ "src/test/cljc" "src/test/cljs" "src/test/resources"] - :dependencies [[org.domaindrivenarchitecture/c4k-common-cljs "0.2.8"]] + :dependencies [[org.domaindrivenarchitecture/c4k-common-cljs "0.2.8"] + [hickory "0.7.1"]] :builds {:frontend {:target :browser :modules {:main {:init-fn dda.c4k-jira.browser/init}} :release {} diff --git a/src/main/cljc/dda/c4k_jira/core.cljc b/src/main/cljc/dda/c4k_jira/core.cljc index df9454f..4f94ee1 100644 --- a/src/main/cljc/dda/c4k_jira/core.cljc +++ b/src/main/cljc/dda/c4k_jira/core.cljc @@ -7,7 +7,10 @@ [dda.c4k-common.yaml :as yaml] [dda.c4k-common.postgres :as postgres] [dda.c4k-jira.jira :as jira] - [dda.c4k-jira.backup :as backup])) + [dda.c4k-jira.backup :as backup] + [clojure.zip :as zip] + [hickory.core :as hc] + [hickory.zip :as hz])) (def config-defaults {:issuer :staging}) @@ -19,6 +22,66 @@ ::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 []