image to data tool added

This commit is contained in:
David Botton 2022-06-30 14:52:19 -04:00
parent 835e72e2ff
commit 5f4e18327b
4 changed files with 48 additions and 4 deletions

View file

@ -48,10 +48,11 @@
:components ((:file "clog-docs")))
(asdf:defsystem #:clog/tools
:depends-on (#:clog)
:depends-on (#:clog #:s-base64)
:pathname "tools/"
:components ((:file "clog-db-admin")
(:file "clog-builder-settings")
(:file "clog-templates")
(:file "clog-new-app")
(:file "clog-builder")))
(:file "clog-builder")
(:file "image-to-data")))

View file

@ -1248,7 +1248,8 @@ of controls and double click to select control."
(declare (ignore obj))
(setf redo-chain nil)
(push (panel-snap-shot content panel-id (bottom-panel box)) undo-chain)
(focus (get-placer (current-control app)))))
(when (current-control app)
(focus (get-placer (current-control app))))))
(set-on-click btn-redo (lambda (obj)
(declare (ignore obj))
(when redo-chain
@ -1530,7 +1531,9 @@ of controls and double click to select control."
(lambda (obj)
(declare (ignore obj))
(setf redo-chain nil)
(push (panel-snap-shot content panel-id (bottom-panel box)) undo-chain)))
(push (panel-snap-shot content panel-id (bottom-panel box)) undo-chain)
(when (current-control app)
(focus (get-placer (current-control app))))))
(set-on-click btn-redo (lambda (obj)
(declare (ignore obj))
(when redo-chain
@ -1712,6 +1715,13 @@ of controls and double click to select control."
(t
(window-close (win panel))))))))
(defun on-image-to-data (obj)
"Menu option to create new project from template"
(let* ((win (create-gui-window obj :title "Convert Images to Data"
:width 450 :height 200)))
(create-image-to-data (window-content win))
(window-center win)))
(defun on-new-builder (body)
"Launch instance of the CLOG Builder"
(set-html-on-close body "Connection Lost")
@ -1744,6 +1754,7 @@ of controls and double click to select control."
(declare (ignore obj))
(open-window (window body) "/dbadmin")))
(create-gui-menu-item tools :content "Control Events" :on-click 'on-show-control-events-win)
(create-gui-menu-item tools :content "Image to Data" :on-click 'on-image-to-data)
(create-gui-menu-item win :content "Maximize All" :on-click #'maximize-all-windows)
(create-gui-menu-item win :content "Normalize All" :on-click #'normalize-all-windows)
(create-gui-menu-window-select win)
@ -1785,6 +1796,22 @@ of controls and double click to select control."
(declare (ignore obj))
;; return empty string to prevent nav off page
""))))
(defun on-convert-image (body)
(let ((params (form-multipart-data body)))
(create-div body :content params)
(destructuring-bind (stream fname content-type)
(form-data-item params "filename")
(create-div body :content (format nil "filename = ~A - (contents printed in REPL)" fname))
(let ((s (flexi-streams:make-flexi-stream stream))
(b (make-string 1000))
(pic-data ""))
(setf pic-data (format nil "data:~A;base64,~A" content-type
(with-output-to-string (out)
(s-base64:encode-base64 s out))))
(create-img body :url-src pic-data)
(create-br body)
(create-div body :content "User the following as a url source:")
(set-geometry (create-text-area body :value pic-data) :width 500 :height 400)))))
(defun clog-builder (&key (port 8080) static-root system)
"Start clog-builder."
@ -1797,4 +1824,5 @@ of controls and double click to select control."
(set-on-new-window 'on-new-builder :path "/builder")
(set-on-new-window 'on-new-db-admin :path "/dbadmin")
(set-on-new-window 'on-attach-builder-page :path "/builder-page")
(set-on-new-window 'on-convert-image :path "/image-to-data")
(open-browser :url (format nil "http://127.0.0.1:~A/builder" port)))

1
tools/image-to-data.clog Normal file
View file

@ -0,0 +1 @@
<data id="I3865596306" data-in-package="clog-tools" data-custom-slots="" data-clog-next-id="9" data-clog-title="image-to-data"></data><form action="/image-to-data" onsubmit="return false;" enctype="multipart/form-data" target="_blank" data-clog-type="form" data-clog-name="form-7" style="box-sizing: content-box; position: static; width: 385px; height: 121px; left: 14px; top: 0px;" method="post"><input type="FILE" value="" data-clog-type="file" data-clog-name="file-2" style="box-sizing: content-box; position: absolute; left: 38px; top: 29px;" accept="image/*" class="" name="filename" size="20"><input type="SUBMIT" value="Convert Image to Data" data-clog-type="submit" data-clog-name="submit-8" style="box-sizing: content-box; position: absolute; left: 38px; top: 67px; width: 188.922px; height: 22.5px;" placeholder="" data-on-click="(submit (form-7 panel))"></form>

14
tools/image-to-data.lisp Normal file
View file

@ -0,0 +1,14 @@
(in-package "CLOG-TOOLS")
(defclass image-to-data (clog:clog-panel)
( (submit-8 :reader submit-8)
(file-2 :reader file-2)
(form-7 :reader form-7)
))
(defun create-image-to-data (clog-obj &key (hidden nil) (class nil) (html-id nil) (auto-place t))
(let ((panel (change-class (clog:create-div clog-obj :content "<form action=\"/image-to-data\" onsubmit=\"return false;\" enctype=\"multipart/form-data\" target=\"_blank\" style=\"box-sizing: content-box; position: static; width: 385px; height: 121px; left: 14px; top: 0px;\" method=\"post\" id=\"CLOGB3865596273\" data-clog-name=\"form-7\"><input type=\"FILE\" value=\"\" style=\"box-sizing: content-box; position: absolute; left: 38px; top: 29px;\" accept=\"image/*\" class=\"\" name=\"filename\" size=\"20\" id=\"CLOGB3865596274\" data-clog-name=\"file-2\"><input type=\"SUBMIT\" value=\"Convert Image to Data\" style=\"box-sizing: content-box; position: absolute; left: 38px; top: 67px; width: 188.922px; height: 22.5px;\" placeholder=\"\" id=\"CLOGB3865596275\" data-clog-name=\"submit-8\"></form>"
:hidden hidden :class class :html-id html-id :auto-place auto-place) 'image-to-data)))
(setf (slot-value panel 'submit-8) (attach-as-child clog-obj "CLOGB3865596275" :clog-type 'CLOG:CLOG-FORM-ELEMENT :new-id t))
(setf (slot-value panel 'file-2) (attach-as-child clog-obj "CLOGB3865596274" :clog-type 'CLOG:CLOG-FORM-ELEMENT :new-id t))
(setf (slot-value panel 'form-7) (attach-as-child clog-obj "CLOGB3865596273" :clog-type 'CLOG:CLOG-FORM :new-id t))
(clog:set-on-click (submit-8 panel) (lambda (target) (declare (ignorable target)) (submit (form-7 panel))))
panel))