updated route paths for creating systems

added TODO comments
removed empty javascript in /create

moved agetf to timecalc-logic
This commit is contained in:
a. fox 2023-07-13 18:27:05 -04:00
parent 70a52f32e4
commit 61c7741177
2 changed files with 18 additions and 13 deletions

View File

@ -5,6 +5,7 @@
:regex-replace-all)
(:export
:agetf
:load-models
:convert
:save-model
@ -18,6 +19,10 @@
"dummy model used for default values in other models")
(defvar *load-dir* nil)
(defun agetf (key alist &optional default)
(or (cdr (assoc key alist :test #'equal))
default))
(defun reload-models (&optional directory)
"reloads system definitions from *LOAD-DIR* (directory passed into binary with -l option)

View File

@ -1,7 +1,8 @@
(defpackage :timecalc-web
(:use :cl :with-user-abort :cl-markup)
(:import-from :timecalc-logic
:convert :save-model)
:convert :save-model
:agetf)
(:import-from :str
:blankp)
(:import-from :clack
@ -24,9 +25,10 @@
(setf (route *app* "/" :method :get) #'index
(route *app* "/result" :method :get) #'result
(route *app* "/calculate" :method :post) #'calculate
(route *app* "/loadModels" :method :post) #'load-or-reset-systems
(route *app* "/add" :method :get) #'create-system-page
(route *app* "/add" :method :post) #'create-system)
(route *app* "/loadModels" :method :post) #'load-or-reset-systems ;; old - DELETE
(route *app* "/create" :method :get) #'create-system-page
(route *app* "/create" :method :post) #'create-system
(route *app* "/add" :method :post) #'load-new-system)
(setf *handler* (clackup *app* :port port :debug nil))
@ -67,7 +69,8 @@ function asyncConvert() {
function loadModels(reset = false) {
var directory = document.getElementById('systemDirectory').files[0].webkitRelativePath;
fetch('/loadModels', {
// CHANGE THIS TO READ SELECTED FILE
fetch('/add', {
method: 'POST',
body: JSON.stringify({
'directory': directory,
@ -93,6 +96,7 @@ input { height: 42px; font-size: 1rem;}
(:p "Time Calculator")
(:br)
(:div :class "convert-container"
;; wrap this inside a disclosure group
(:p "Select System Directory:")
(:input :type "file" :id "systemDirectory" :name "systemDirectory" :class "needs-space" :webkitdirectory)
(:button :type "button" :onclick "loadModels()"
@ -130,10 +134,6 @@ input { height: 42px; font-size: 1rem;}
(:body
(:p (or *calculation-result* "")))))
(defun agetf (key alist &optional default)
(or (cdr (assoc key alist :test #'equal))
default))
(defun calculate (&optional args)
(setf *calculation-result*
(convert (agetf "time" args) (agetf "to" args) (agetf "to" args))))
@ -142,11 +142,9 @@ input { height: 42px; font-size: 1rem;}
(html5
;; define javascript to output
(:head
(:script :type "text/javascript" (raw "
")))
)
(:body
(:form :method "POST" :action "/add"
(:form :method "POST" :action "/create"
(create-label-and-input "key" "text" "Key")
(create-label-and-input "name" "text" "System Name")
(create-label-and-input "secondsInMinute" "text" "Seconds in Minute (leave blank for default)")
@ -181,6 +179,8 @@ input { height: 42px; font-size: 1rem;}
(:input :type ,type :name ,name ,@(unless (blankp value)
`(:value ,value)))))
;; TODO: change this to parse the POST'd JSON and add to the models hashtable
(defun load-or-reset-systems (&optional args)
(let* ((file (agetf "directory" args))
(dir (str:concat (namestring (uiop:getcwd)) (getf (pathname-directory file) :relative) "/")))