diff --git a/.gitignore b/.gitignore index 7c55f4e..e478823 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ pom.xml.asc /resources/public/css .idea *.iml +figwheel_server.log diff --git a/project.clj b/project.clj index c122724..86418a6 100644 --- a/project.clj +++ b/project.clj @@ -2,23 +2,30 @@ :description "FIXME: write description" :url "http://example.com/FIXME" :min-lein-version "2.0.0" + :dependencies [[org.clojure/clojure "1.9.0"] + [org.clojure/clojurescript "1.9.521"] + [compojure "1.6.1"] [ring/ring-defaults "0.3.2"] + [hiccup "1.0.5"] + [gorillalabs/neo4j-clj "1.1.0" :exclusions [org.bouncycastle/bcprov-jdk15on org.bouncycastle/bcpkix-jdk15on com.github.ben-manes.caffeine/caffeine]] - [hiccup "1.0.5"] [buddy/buddy-hashers "1.3.0" :exclusions [commons-codec]] [clj-time "0.14.4"]] - :plugins [[lein-ring "0.9.7"]] - :ring {:handler wanijo.handler/app} + :profiles {:dev {:dependencies [[javax.servlet/servlet-api "2.5"] [ring/ring-mock "0.3.2"]] - :plugins [[lein-less "1.7.5"] - [joshavg/lein-neo4j "0.3.0"]]}} + :plugins [[joshavg/lein-neo4j "0.3.0"] + [lein-less "1.7.5"] + [lein-ring "0.9.7"]]} + :uberjar {:aot :all}} + + :ring {:handler wanijo.handler/app} :less {:source-paths ["resources/app/stylesheets"] :target-path "resources/public/css"} :hiera {:cluster-depth 2}) diff --git a/resources/app/stylesheets/app.less b/resources/app/stylesheets/app.less index f05fa81..3aba3dc 100644 --- a/resources/app/stylesheets/app.less +++ b/resources/app/stylesheets/app.less @@ -176,6 +176,10 @@ form { font-family: monospace; } } + + .delete-btn.__on-countdown { + font-weight: bold; + } } form.inline { diff --git a/resources/public/js/frontend.js b/resources/public/js/frontend.js new file mode 100644 index 0000000..72c3f26 --- /dev/null +++ b/resources/public/js/frontend.js @@ -0,0 +1,44 @@ +document.addEventListener('DOMContentLoaded', function() { + function label(element, value) { + if(element.hasAttribute('value')) { + if(value !== undefined) { + element.setAttribute('value', value) + } else { + return element.getAttribute('value') + } + } else { + if(value !== undefined) { + element.textContent = value + } else { + return element.textContent + } + } + } + + function countdownDeleteButton(event) { + const btn = event.target + const countdown = btn.getAttribute('data-countdown') + + if(countdown != 0) { + event.preventDefault() + btn.classList.add('__on-countdown') + + const hasCountdown = countdown !== null + const newCountdown = hasCountdown ? countdown - 1 : 3 + + if(!hasCountdown) { + btn.setAttribute('data-label', label(btn)) + } + + label(btn, newCountdown) + btn.setAttribute('data-countdown', newCountdown) + setTimeout(countdownDeleteButton, 1000, event) + } else { + label(btn, btn.getAttribute('data-label')) + } + } + + document.querySelectorAll('.delete-btn').forEach(function(btn) { + btn.addEventListener('click', countdownDeleteButton) + }) +}) diff --git a/src/wanijo/framework/view.clj b/src/wanijo/framework/view.clj index 87d7a4f..6bb61fc 100644 --- a/src/wanijo/framework/view.clj +++ b/src/wanijo/framework/view.clj @@ -1,6 +1,6 @@ (ns wanijo.framework.view (:require [hiccup.page :refer - [html5 include-css]] + [html5 include-css include-js]] [wanijo.framework.routing :refer [path]])) (defn btnlink @@ -26,7 +26,8 @@ :content "width=device-width,initial-scale=1,shrink-to-fit=no"}] [:title (str "wan ijo" (when title (str " - " title)))] (include-css "/css/app.css") - (when devmode? (include-css "/css/devmode.css"))] + (when devmode? (include-css "/css/devmode.css")) + (include-js "/js/frontend.js")] [:body [:section.grid [:header diff --git a/src/wanijo/schema/view.clj b/src/wanijo/schema/view.clj index 9839cc8..e552733 100644 --- a/src/wanijo/schema/view.clj +++ b/src/wanijo/schema/view.clj @@ -52,7 +52,7 @@ (prettify-dt (:created_at schema))]])]] [:h1 "New schema"] (hform/form-to [:post (path :schema-new)] - (form/render-form form {} req) + (form/render-widgets form {} req) (hform/submit-button "Create"))]))) (defn show-schema! [schema attrs req] @@ -77,7 +77,7 @@ (hform/form-to [:delete (path :attribute-delete attr)] (anti-forgery-field) (hform/hidden-field "schema" (:uuid schema)) - (hform/submit-button "Delete!") + (hform/submit-button {:class "delete-btn"} "Delete!") [:label "Created at " [:em (prettify-dt (:created_at attr))]])])] [:h3 "New attribute"] (hform/form-to [:post (path :attribute-new)] @@ -88,4 +88,4 @@ (hform/form-to {:class "inline"} [:delete (path :schema-delete schema)] (anti-forgery-field) - (hform/submit-button "Delete!"))])) + (hform/submit-button {:class "delete-btn"} "Delete!"))]))