first error message

This commit is contained in:
jem 2021-03-19 14:16:08 +01:00
parent 9a5071ac6a
commit 122a7ddee7
3 changed files with 51 additions and 12 deletions

View file

@ -8,13 +8,14 @@
"license": "APACHE2",
"main": "k8s-mastodon-bot.js",
"bin": {
"mastodon-bot": "./k8s-mastodon-bot.js"
"k8s-mastodon-bot": "./k8s-mastodon-bot.js"
},
"keywords": [
"cljs",
"mastodon-bot",
"k8s",
"deplyoment"
"deplyoment",
"yaml"
],
"bugs": {
"url": "https://gitlab.com/domaindrivenarchitecture/k8s-mastodon-bot/issues"

View file

@ -11,6 +11,7 @@
<body>
<div class="container jumbotron">
<form class="needs-validation" id="form">
<label for="config" class="form-label">Your config.edn:</label>
<textarea name="config" id="config" class="form-control" rows="15">
{:transform [{:source {:source-type :twitter
@ -40,7 +41,9 @@
:signature "#newsbot"}
}]
:auth {}}}
</textarea><br><br>
</textarea>
<div class="invalid-feedback"><pre id="config-validation"></pre></div>
<br><br>
<label for="auth" class="form-label">Your auth.edn:</label>
<textarea name="auth" id="auth" class="form-control" rows="15">
@ -67,6 +70,7 @@
<textarea name="output" id="output" class="form-control" rows="15">
</textarea>
</div>
</form>
</div>
<script src="js/main.js"></script>
</body>

View file

@ -1,12 +1,31 @@
(ns dda.k8s-mastodon-bot.browser
(:require
[clojure.string :as st]
[clojure.tools.reader.edn :as edn]
[expound.alpha :as expound]
[dda.k8s-mastodon-bot.core :as core]))
(defn config-from-document []
(defn print-debug [sth]
(print "debug " sth)
sth)
(defn config []
(-> js/document
(.getElementById "config")))
(defn set-config-validation! [input]
(print-debug input)
(-> js/document
(.getElementById "config")
(.getElementById "config-validation")
(.-innerHTML)
(set! input)))
(defn form []
(-> js/document
(.getElementById "form")))
(defn config-from-document []
(-> (config)
(.-value)))
(defn auth-from-document []
@ -14,7 +33,7 @@
(.getElementById "auth")
(.-value)))
(defn render-output-to-document
(defn set-output!
[input]
(-> js/document
(.getElementById "output")
@ -23,19 +42,34 @@
(defn expound-config
[config]
(expound/expound ::core/config config))
(st/replace
(expound/expound-str ::core/config config {:print-specs? false})
#"\n" "<br>"))
(defn render-validation-result-to-config
[validation-result]
(print-debug validation-result)
(set-config-validation! validation-result)
(-> (config)
(.setCustomValidity validation-result))
(-> (form)
(.-classList)
(.add "was-validated"))
validation-result)
(defn init []
(-> js/document
(.getElementById "generate-button")
(.addEventListener "click"
#(-> (core/generate (config-from-document) (auth-from-document))
(render-output-to-document))))
(-> js/document
(.getElementById "config")
(set-output!))))
(-> (config)
(.addEventListener "blur"
#(-> (config-from-document)
(edn/read-string)
(expound-config)
(print))))
(print-debug)
(render-validation-result-to-config))))
)