Possibly-working?
This commit is contained in:
parent
8771b905d4
commit
0d3efe1323
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -12,3 +12,7 @@ profiles.clj
|
||||||
/.env
|
/.env
|
||||||
.nrepl-port
|
.nrepl-port
|
||||||
/log
|
/log
|
||||||
|
|
||||||
|
\.rebel_readline_history
|
||||||
|
|
||||||
|
[0-9a-f]*-init\.clj
|
||||||
|
|
18
project.clj
18
project.clj
|
@ -4,6 +4,8 @@
|
||||||
:url "http://example.com/FIXME"
|
:url "http://example.com/FIXME"
|
||||||
|
|
||||||
:dependencies [[baking-soda "0.2.0" :exclusions [cljsjs/react-bootstrap]]
|
:dependencies [[baking-soda "0.2.0" :exclusions [cljsjs/react-bootstrap]]
|
||||||
|
[binaryage/devtools "0.9.10"]
|
||||||
|
[com.cemerick/url "0.1.1"]
|
||||||
[cheshire "5.8.1"]
|
[cheshire "5.8.1"]
|
||||||
[clj-commons/secretary "1.2.4"]
|
[clj-commons/secretary "1.2.4"]
|
||||||
[clj-oauth "1.5.5"]
|
[clj-oauth "1.5.5"]
|
||||||
|
@ -41,7 +43,7 @@
|
||||||
[selmer "1.12.6"]]
|
[selmer "1.12.6"]]
|
||||||
|
|
||||||
:min-lein-version "2.0.0"
|
:min-lein-version "2.0.0"
|
||||||
|
|
||||||
:source-paths ["src/clj" "src/cljs" "src/cljc"]
|
:source-paths ["src/clj" "src/cljs" "src/cljc"]
|
||||||
:test-paths ["test/clj"]
|
:test-paths ["test/clj"]
|
||||||
:resource-paths ["resources" "target/cljsbuild"]
|
:resource-paths ["resources" "target/cljsbuild"]
|
||||||
|
@ -58,7 +60,7 @@
|
||||||
:nrepl-port 7002
|
:nrepl-port 7002
|
||||||
:css-dirs ["resources/public/css"]
|
:css-dirs ["resources/public/css"]
|
||||||
:nrepl-middleware [cider.piggieback/wrap-cljs-repl]}
|
:nrepl-middleware [cider.piggieback/wrap-cljs-repl]}
|
||||||
|
|
||||||
|
|
||||||
:profiles
|
:profiles
|
||||||
{:uberjar {:omit-source true
|
{:uberjar {:omit-source true
|
||||||
|
@ -77,8 +79,8 @@
|
||||||
:closure-warnings
|
:closure-warnings
|
||||||
{:externs-validation :off :non-standard-jsdoc :off}
|
{:externs-validation :off :non-standard-jsdoc :off}
|
||||||
:externs ["react/externs/react.js"]}}}}
|
:externs ["react/externs/react.js"]}}}}
|
||||||
|
|
||||||
|
|
||||||
:aot :all
|
:aot :all
|
||||||
:uberjar-name "ireadit.jar"
|
:uberjar-name "ireadit.jar"
|
||||||
:source-paths ["env/prod/clj"]
|
:source-paths ["env/prod/clj"]
|
||||||
|
@ -116,9 +118,9 @@
|
||||||
:pretty-print true
|
:pretty-print true
|
||||||
:closure-defines {"re_frame.trace.trace_enabled_QMARK_" true}
|
:closure-defines {"re_frame.trace.trace_enabled_QMARK_" true}
|
||||||
:preloads [re-frisk.preload]}}}}
|
:preloads [re-frisk.preload]}}}}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
:doo {:build "test"}
|
:doo {:build "test"}
|
||||||
:source-paths ["env/dev/clj"]
|
:source-paths ["env/dev/clj"]
|
||||||
:resource-paths ["env/dev/resources"]
|
:resource-paths ["env/dev/resources"]
|
||||||
|
@ -136,7 +138,7 @@
|
||||||
:main "ireadit.doo-runner"
|
:main "ireadit.doo-runner"
|
||||||
:optimizations :whitespace
|
:optimizations :whitespace
|
||||||
:pretty-print true}}}}
|
:pretty-print true}}}}
|
||||||
|
|
||||||
}
|
}
|
||||||
:profiles/dev {}
|
:profiles/dev {}
|
||||||
:profiles/test {}})
|
:profiles/test {}})
|
||||||
|
|
|
@ -7,14 +7,14 @@
|
||||||
<link href="css/standard.css" rel="stylesheet" type="text/css">
|
<link href="css/standard.css" rel="stylesheet" type="text/css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<form action="http://loriner.journeyman.cc:8888/v1/tesseract/" method="post">
|
<form action="http://loriner.journeyman.cc:8888/v1/tesseract/" method="POST">
|
||||||
<p class="widget">
|
<p class="widget">
|
||||||
<label for="image-url" title="URL of the image you wish to transcribe">Image URL</label>
|
<label for="image-url" title="URL of the image you wish to transcribe">Image URL</label>
|
||||||
<input id="image-url" type="text"/>
|
<input id="image-url" type="text" size="80"/>
|
||||||
</p>
|
</p>
|
||||||
<p class="widget">
|
<p class="widget">
|
||||||
<label for="submit">{% i18n change-pass-prompt %}</label>
|
<label for="submit">To transcribe the text of this image</label>
|
||||||
<input name="action" id="action" type="submit" class="action" value="{% i18n change-pass-link %}!"/>
|
<input name="action" id="action" type="submit" class="action" value="Transcribe!"/>
|
||||||
</p>
|
</p>
|
||||||
</form>
|
</form>
|
||||||
</body>
|
</body>
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
[markdown.core :refer [md->html]]
|
[markdown.core :refer [md->html]]
|
||||||
[ireadit.ajax :as ajax]
|
[ireadit.ajax :as ajax]
|
||||||
[ireadit.events]
|
[ireadit.events]
|
||||||
|
[ireadit.views.form :as form]
|
||||||
[secretary.core :as secretary])
|
[secretary.core :as secretary])
|
||||||
(:import goog.History))
|
(:import goog.History))
|
||||||
|
|
||||||
|
@ -34,7 +35,8 @@
|
||||||
[b/Collapse {:is-open @expanded? :navbar true}
|
[b/Collapse {:is-open @expanded? :navbar true}
|
||||||
[b/Nav {:class-name "mr-auto" :navbar true}
|
[b/Nav {:class-name "mr-auto" :navbar true}
|
||||||
[nav-link "#/" "Home" :home]
|
[nav-link "#/" "Home" :home]
|
||||||
[nav-link "#/about" "About" :about]]]]))
|
[nav-link "#/about" "About" :about]
|
||||||
|
[nav-link "#/transcribe" "Transcribe" :transcribe]]]]))
|
||||||
|
|
||||||
(defn about-page []
|
(defn about-page []
|
||||||
[:div.container
|
[:div.container
|
||||||
|
@ -51,7 +53,8 @@
|
||||||
|
|
||||||
(def pages
|
(def pages
|
||||||
{:home #'home-page
|
{:home #'home-page
|
||||||
:about #'about-page})
|
:about #'about-page
|
||||||
|
:transcribe #'form/form-page})
|
||||||
|
|
||||||
(defn page []
|
(defn page []
|
||||||
[:div
|
[:div
|
||||||
|
@ -69,6 +72,9 @@
|
||||||
(secretary/defroute "/about" []
|
(secretary/defroute "/about" []
|
||||||
(rf/dispatch [:navigate :about]))
|
(rf/dispatch [:navigate :about]))
|
||||||
|
|
||||||
|
(secretary/defroute "/transcribe" []
|
||||||
|
(rf/dispatch [:navigate :transcribe]))
|
||||||
|
|
||||||
;; -------------------------
|
;; -------------------------
|
||||||
;; History
|
;; History
|
||||||
;; must be called after routes have been defined
|
;; must be called after routes have been defined
|
||||||
|
|
|
@ -1,9 +1,15 @@
|
||||||
(ns ireadit.events
|
(ns ireadit.events
|
||||||
(:require [re-frame.core :as rf]
|
(:require [re-frame.core :as rf]
|
||||||
[ajax.core :as ajax]))
|
[ajax.core :as ajax]
|
||||||
|
[cemerick.url :refer (url-encode)]))
|
||||||
|
|
||||||
;;dispatchers
|
;;dispatchers
|
||||||
|
|
||||||
|
(rf/reg-event-db
|
||||||
|
:set-url
|
||||||
|
(fn [db [_ url]]
|
||||||
|
(assoc db :url url)))
|
||||||
|
|
||||||
(rf/reg-event-db
|
(rf/reg-event-db
|
||||||
:navigate
|
:navigate
|
||||||
(fn [db [_ page]]
|
(fn [db [_ page]]
|
||||||
|
@ -14,6 +20,11 @@
|
||||||
(fn [db [_ docs]]
|
(fn [db [_ docs]]
|
||||||
(assoc db :docs docs)))
|
(assoc db :docs docs)))
|
||||||
|
|
||||||
|
(rf/reg-event-db
|
||||||
|
:set-transcription
|
||||||
|
(fn [db [_ transcription]]
|
||||||
|
(assoc db :transcription transcription)))
|
||||||
|
|
||||||
(rf/reg-event-fx
|
(rf/reg-event-fx
|
||||||
:fetch-docs
|
:fetch-docs
|
||||||
(fn [_ _]
|
(fn [_ _]
|
||||||
|
@ -22,6 +33,27 @@
|
||||||
:response-format (ajax/raw-response-format)
|
:response-format (ajax/raw-response-format)
|
||||||
:on-success [:set-docs]}}))
|
:on-success [:set-docs]}}))
|
||||||
|
|
||||||
|
(rf/reg-event-fx
|
||||||
|
:fetch-transcription
|
||||||
|
(fn [{db :db} _]
|
||||||
|
(let [uri (str "http://loriner.journeyman.cc:8888/v1/tesseract/" (url-encode (:url db)))]
|
||||||
|
(js/console.log
|
||||||
|
(str
|
||||||
|
"Fetching transcription data: " uri))
|
||||||
|
{:http-xhrio {:method :post
|
||||||
|
:uri uri
|
||||||
|
:format (ajax/json-request-format)
|
||||||
|
:response-format (ajax/json-response-format {:keywords? true})
|
||||||
|
:on-success [:set-transcription]
|
||||||
|
:on-failure [:bad-transcription]}})))
|
||||||
|
|
||||||
|
(rf/reg-event-fx
|
||||||
|
:bad-transcription
|
||||||
|
(fn
|
||||||
|
[{db :db} [_ response]]
|
||||||
|
;; TODO: signal something has failed? It doesn't matter very much, unless it keeps failing.
|
||||||
|
(js/console.log (str "Failed to fetch transcription data" response))))
|
||||||
|
|
||||||
(rf/reg-event-db
|
(rf/reg-event-db
|
||||||
:common/set-error
|
:common/set-error
|
||||||
(fn [db [_ error]]
|
(fn [db [_ error]]
|
||||||
|
@ -43,3 +75,14 @@
|
||||||
:common/error
|
:common/error
|
||||||
(fn [db _]
|
(fn [db _]
|
||||||
(:common/error db)))
|
(:common/error db)))
|
||||||
|
|
||||||
|
(rf/reg-sub
|
||||||
|
:url
|
||||||
|
(fn [db _]
|
||||||
|
(:url db)))
|
||||||
|
|
||||||
|
(rf/reg-sub
|
||||||
|
:transcription
|
||||||
|
(fn [db _]
|
||||||
|
(:transcription db)))
|
||||||
|
|
||||||
|
|
29
src/cljs/ireadit/views/form.cljs
Normal file
29
src/cljs/ireadit/views/form.cljs
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
(ns ireadit.views.form
|
||||||
|
(:require [baking-soda.core :as b]
|
||||||
|
[day8.re-frame.http-fx]
|
||||||
|
[reagent.core :as r]
|
||||||
|
[re-frame.core :as rf]
|
||||||
|
[goog.events :as events]
|
||||||
|
[goog.history.EventType :as HistoryEventType]
|
||||||
|
[markdown.core :refer [md->html]]
|
||||||
|
[ireadit.ajax :as ajax]
|
||||||
|
[ireadit.events]
|
||||||
|
[secretary.core :as secretary])
|
||||||
|
(:import goog.History))
|
||||||
|
|
||||||
|
|
||||||
|
(defn form-page []
|
||||||
|
[:div
|
||||||
|
[:h1 "Transcribe the text of an image"]
|
||||||
|
[:div.container {:id "main-container"}
|
||||||
|
[:div
|
||||||
|
[:p.widget
|
||||||
|
[b/Label {:for "image-url" :title "URL of the image you wish to transcribe"}"Image URL"]
|
||||||
|
[b/Input {:id "image-url" :type "text" :size "80"
|
||||||
|
:on-change #(rf/dispatch [:set-url (.-value (.-target %))])}]]
|
||||||
|
[:p.widget
|
||||||
|
[b/Label {:for "send"} "To transcribe the image"]
|
||||||
|
[b/Button {:id "send" :on-click #(rf/dispatch [:fetch-transcription])} "Transcribe!"]]]
|
||||||
|
[:div.transcription @(rf/subscribe [:transcription])]
|
||||||
|
]])
|
||||||
|
|
Loading…
Reference in a new issue