c8e1dd454b52b1bbd4a5301172da6146aa82ce56
[lineal.git] / src / webui / calcupage.lisp
blobc8e1dd454b52b1bbd4a5301172da6146aa82ce56
2 (in-package :lineal.webui)
4 ;V URL: /process-infix
5 ;V Receive user's calculation, return result.V
6 (defun receive-and-process
7 (&optional (infixp t)
8 &aux (text (parameter "text"))
9 (log-calcs (load-time-value
10 (boundp 'lineal.devvars::log-calcs))))
11 (when log-calcs (log-message* "parser receives: ~%~A" text))
12 (setq
13 text
14 (if infixp
15 (with-output-to-string (strm)
16 (over-format
17 (process-infix-from-string text)
18 strm))
19 (process-input-from-string text)))
20 (when log-calcs (log-message* "parser replies: ~%~A" text))
21 text)
23 ;V URL: /process-prefix
24 (defun receive-and-process-prefix ()
25 (receive-and-process nil))
27 (defmacro htm-expand-known-if
28 (strm infixp s-expr)
29 `(princ
30 (if ,infixp
31 (load-time-value (,@s-expr t))
32 (load-time-value (,@s-expr nil)))
33 ,strm))
35 ;V URL: /calcupage-infix
36 (defun calcupage (&optional (infixp t))
37 (with-html-output-to-string
38 (s nil :prologue t)
39 (:html
40 (:head
41 (:title "Calculate things.")
42 (:link :rel "stylesheet" :href "calcupage.css")
43 (jsfile s "calcupage")
44 (jsfile s "connects"))
45 (:body
46 (:div (:a :href "/input_matrix" "Create and edit")
47 " vectors and matrices" :br
48 "Use "
49 (if infixp
50 (htm (:a :href "/calcupage-prefix" "prefix"))
51 (htm (:a :href "/calcupage-infix" "infix")))
52 " notation instead." :br
53 (:a :href "/" "Main") " Page")
54 (:table
55 :width "100%"
56 (:tr
57 (:th :rowspan "2" :class "linalg-buttons"
58 (htm-expand-known-if
59 s infixp (htm-linalg-buttons)))
60 (:th :rowspan "2" :class "stdmath-buttons"
61 ;V Show operator buttons on left.V
62 (htm-expand-known-if
63 s infixp (htm-standard-math-buttons)))
64 ;V Before variable names, show some easy-access buttons.V
65 (:td :class "quick-buttons"
66 (htm-expand-known-if
67 s infixp (memory-buttons))
68 (princ
69 (load-time-value
70 (concatenate
71 'string "<br/>"
72 (clear-button)
73 (htm-input-button
74 "&quot;" "fn1" "\\\"")
75 (ok-button)))
76 s))
77 ;V Show variables on the top.V
78 (:td
79 (do ((lvpairs-left
80 `(("Numbers: " ,*saved-numbers*)
81 ("Vectors: " ,*saved-tuples*)
82 ("Matrices: " ,*saved-matrices*))))
83 (nil)
84 (princ (caar lvpairs-left) s)
85 (dolist (k (cadar lvpairs-left))
86 (princ (simple-input-button k "varbutton") s))
87 (unless (setq lvpairs-left (cdr lvpairs-left))
88 (return (values)))
89 (princ "<br/>" s))))
90 ;V main textarea V
91 (:tr (:td :colspan "2"
92 (:textarea :id "calcIn" :spellcheck "false"))))
93 ;V Make a place to show results.V
94 (:pre :id "resultPre")
95 (if infixp (ps-tag s (setf process-loc "/process-infix"))
96 (ps-tag s (setf process-loc "/process-prefix")))
97 (ps-tag
98 s (setf calc-in (.get-element-by-id document "calcIn")))))))
100 ;V URL: /calcupage-prefix
101 (defun calcupage-prefix ()
102 (calcupage nil))