Skip to content

Commit

Permalink
better css survey support and show timestamps
Browse files Browse the repository at this point in the history
  • Loading branch information
vii committed Feb 25, 2010
1 parent 173ad3e commit 1d61a7c
Showing 1 changed file with 30 additions and 19 deletions.
49 changes: 30 additions & 19 deletions src/survey/survey.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,17 @@
(time :initform (get-universal-time))
(trace-details :initform (tpd2.http:servestate-origin*)))

(defun time-string (&optional (ut (get-universal-time)))
(multiple-value-bind
(second minute hour date month year)
(decode-universal-time ut 0)
(format nil "~4,'0D-~2,'0D-~2,'0D ~2,'0D:~2,'0D:~2,'0D GMT" year month date hour minute second)))

(my-defun response 'object-to-ml ()
(<tr :class "survey-response"
(loop for r in (my responses)
do (<td r))))
do (<td :class (byte-vector-cat "response-" r) r))
(<td :class "timestamp" (time-string (my time)))))

(my-defun survey-channel responses ()
(datastore-retrieve-indexed 'response 'survey-name (survey-name (my survey))))
Expand All @@ -32,7 +39,9 @@
(my-defun survey-channel 'simple-channel-body-ml ()
(<table :class "survey-channel"
(<thead
(loop for q in (my questions) do (<th (question-text q))))
(<tr
(loop for q in (my questions) do (<th (question-text q)))
(<th :class "timestamp" "Time")))
(loop for c in (my responses) repeat 50 do
(output-object-to-ml c))))

Expand All @@ -45,23 +54,25 @@
(let ((qvars (loop for i from 0 for q in (my questions) collect (intern (strcat 'q i)))))
`(with-compile-time-site ()
(defpage-lambda ,path
(lambda (,@qvars .javascript.)
(cond ((or ,@qvars)
(let ((chan (find-channel ,(my channel-name))))
(make-response :survey-name ,(my name)
:responses (list ,@qvars))
(channel-notify chan)
(cond (.javascript. (webapp-respond-ajax-body))
(t
(webapp "Thank you for responding"
(output-object-to-ml chan))))))
(t
(webapp ,(my name)
(<div :class "survey"
(html-action-form ("" :action-link ,path :async nil)
,(loop for q in (my questions)
for v in qvars
collect `(,v nil :label ,(question-text q) :type :select-one :options ,(question-choices q)))))))))
(lambda (,@qvars view)
(let ((chan (find-channel ,(my channel-name))))
(cond
(view
(webapp "Survey results"
(output-object-to-ml chan)))
((or ,@qvars)
(make-response :survey-name ,(my name)
:responses (list ,@qvars))
(channel-notify chan)
(webapp "Thank you for responding"
(output-object-to-ml chan)))
(t
(webapp ,(my name)
(<div :class "survey"
(html-action-form ("" :action-link ,path :async nil)
,(loop for q in (my questions)
for v in qvars
collect `(,v nil :label ,(question-text q) :type :select-one :options ,(question-choices q))))))))))
:create-frame nil))))

(my-defun survey register (path)
Expand Down

0 comments on commit 1d61a7c

Please sign in to comment.