+Calculator and code looks
[lineal.git] / src / webui / calcupage.lisp
bloba7d192164f07e7f0af83703f176cc6d0c35c92a0
2 (in-package :lineal.webui)
4 ;V URL: /process
5 ;V Receive user's calculation, return result.V
6 (defun receive-and-process
7 (&aux (text (parameter "text"))
8 (log-calcs (load-time-value
9 (boundp 'lineal.devvars::log-calcs))))
10 (when log-calcs (log-message* "parser receives: ~%~A" text))
11 (setq text (process-input-from-string text))
12 (when log-calcs (log-message* "parser replies: ~%~A" text))
13 text)
15 ;V URL: /calcupage
16 ;V Display the calculator page at server/calcupage V
17 (defun calcupage ()
18 (with-html-output-to-string
19 (s nil :prologue t)
20 (:html
21 (:head
22 (:title "Calculate things.")
23 (:style
24 :type "text/css"
25 (mapc (lambda (line)
26 (princ line s)
27 (terpri s))
28 '("<!--"
29 "button {"
30 " font-family: Serif;"
31 " font-size: 10px;"
32 "}"
33 "-->")))
34 (jsfile s "calcupage-buttons")
35 (jsfile s "connects"))
36 (:body
37 (:div (:a :href "/input_matrix" "Create and edit")
38 " vectors and matrices" :br
39 (:a :href "/" "Main") " Page")
40 (:table
41 :width "100%"
42 (:tr
43 (:th :rowspan "2" :width "110"
44 ;V Show operator buttons on left.V
45 (:div :id "opdiv"
46 (ps-tag s (show-standops (.get-element-by-id document "opdiv")))))
47 (:th :rowspan "2" :width "170"
48 (:div :id "linopdiv")
49 (ps-tag s (show-linops (.get-element-by-id document "linopdiv"))))
50 ;V Before variable names, show some easy-access buttons.V
51 (:td :width "100"
52 (:div :id "leftvardiv"
53 (ps-tag s (defvar leftvardiv (.get-element-by-id document "leftvardiv"))
54 (memory-buttons leftvardiv)
55 (.append-child leftvardiv (.create-element document "br"))
56 (clear-button leftvardiv)
57 (ok-button leftvardiv))))
58 ;V Show variables on the top.V
59 (:td (:div :id "vardiv"
60 (format
62 (concatenate
63 'string "~{~{~A: "
64 "~{<button onclick=\"uinput('~A')\">~:*~A</button>~}"
65 "~#[<br/>~:;~]~}~}")
66 `(("Numbers" ,*saved-numbers*)
67 ("Vectors" ,*saved-tuples*)
68 ("Matrices" ,*saved-matrices*))))))
69 ;V main textarea V
70 (:tr (:td :colspan "2"
71 (:textarea :style "font-family: monospace; width: 100%" :rows "12"
72 :wrap "hard" :id "calcIn" :spellcheck "false"))))
73 ;V Make a place to show results.V
74 (:pre :id "resultPre")
75 (ps-tag
76 s (setf calc-in (.get-element-by-id document "calcIn")))))))