From a01015cc440e4468292e37e7d3e325c57264756d Mon Sep 17 00:00:00 2001 From: interp Date: Wed, 2 Oct 2002 13:39:55 +0000 Subject: [PATCH] + internal restructuring + nicer interface --- .../root/surflets/admin-servlets.scm | 424 +++++++++++------- 1 file changed, 251 insertions(+), 173 deletions(-) diff --git a/scheme/httpd/surflets/web-server/root/surflets/admin-servlets.scm b/scheme/httpd/surflets/web-server/root/surflets/admin-servlets.scm index 0030bd9..3c76b56 100644 --- a/scheme/httpd/surflets/web-server/root/surflets/admin-servlets.scm +++ b/scheme/httpd/surflets/web-server/root/surflets/admin-servlets.scm @@ -4,6 +4,9 @@ servlets servlet-handler/admin httpd-responses + handle-fatal-error + let-opt + srfi-1 ;filter-map sort ) (begin @@ -16,61 +19,127 @@ (if match (match:substring match 1) file-name))))) - + + ;; returns two values: an action to perform out of ACTIONS and a + ;; list of selected elements out of TABLE-ELEMENTS. + (define (select-table title header header-row + table-elements selector actions footer) + (let* ((checkboxes (map (lambda (_) + (make-checkbox-input-field)) + table-elements)) + (action-title "Choose an action") + (select (make-select-input-field (cons action-title actions) + '(@ (size 1)))) + (req + (send-html/suspend + (lambda (new-url) + `(html + (title ,title) + (body + ,header + (servlet-form + ,new-url + (table + ,@(cons '(th) header-row) + ,@(map (lambda (checkbox table-element) + `(tr + (td ,checkbox) + ,@(selector table-element))) + checkboxes + table-elements)) + (p ,select + ,(make-submit-button "Do it"))) + ,footer))))) + (bindings (get-bindings req)) + (action (input-field-value select bindings))) + + (if (string=? action action-title) + (select-table title header header-row table-elements selector actions footer) + (values + action + (filter-map (lambda (checkbox table-element) + (if(with-fatal-error-handler + (lambda (condition more) + #f) + (input-field-value checkbox bindings)) + table-element + #f)) + checkboxes + table-elements))))) (define (unload-servlets outdated? servlet-names) - (lambda (req) - (if-outdated outdated? - (show-outdated (make-callback servlets)) - (begin - (for-each unload-servlet servlet-names) - (servlets req))))) + (if-outdated outdated? + (show-outdated (make-callback servlets)) + (for-each unload-servlet servlet-names))) (define (no-servlets) `(p "Currently, there are no servlets loaded " (URL ,(make-callback servlets) "(reload)."))) - (define (show-servlets loaded-servlets outdated?) - `((p "This is a list of all loaded servlets:") - (table - (@ (border 1)) - (tr (th "Name") (th "Action")) - ,@(map - (lambda (servlet-name) - `(servlet-form - ,(make-callback (unload-servlets outdated? (list servlet-name))) - (tr (td ,(remove-servlet-path servlet-name)) - (td ,(make-submit-button '(@ ((value "unload")))))))) - loaded-servlets)) - (servlet-form - ,(make-callback (unload-servlets outdated? loaded-servlets)) - ,(make-submit-button "unload all")) - (p "Note that unloading the servlets does not imply " - "the unloading of instances of this servlet." - (br) - "This can be done on the " - (URL ,(make-callback instances) - "instances adminstration page.")))) + (define (servlets req . maybe-update-text) + (let* ((update-text (:optional maybe-update-text "")) + (loaded-servlets (sort-list! (get-loaded-servlets) string? entry1 entry2) (instance-id? entry1 entry2) @@ -84,141 +153,150 @@ ;; Can't use callback here, as there are no valid instances left. (URL "admin.scm" "Go back to main page."))) - (define (show-current-instances current-instances outdated?) - (let ((instances-callback (make-callback instances))) - `((p "This is a list of all current instances") - (table - (@ (border 1)) - (tr (th "Servlet Name") (th "Instance-Id") (th "Action")) - ,@(map - (lambda (instance-pair) - (let ((instance-id (car instance-pair)) - (instance-entry (cdr instance-pair))) - `(tr - (td ,(instance-servlet-name instance-entry)) - (td ,instance-id) - (td - (table - (tr - (td - (servlet-form - ,(make-callback - (lambda (req) - (if-outdated outdated? - (show-outdated instances-callback) - (begin - (delete-instance! instance-id) - (instances req))))) - ,(make-submit-button "kill"))) - (td - (servlet-form - ,(make-callback - (lambda (req) - (if-outdated outdated? - (show-outdated instances-callback) - (begin - (format #t "adjusting ~a~%" instance-id) - (instance-adjust-timeout! instance-id) - (instances req))))) - ,(make-submit-button "adjust timeout"))) - (td - (URL - ,(make-callback - (lambda (req) - (if-outdated outdated? - (show-outdated instances-callback) - (continuations instance-id instance-entry)))) - "view continuations")))))))) - current-instances)) - (servlet-form - ,(make-callback - (lambda (req) - (if-outdated outdated? - (show-outdated instances-callback) - (begin - (for-each delete-instance! (map car current-instances)) - (instances req))))) - ,(make-submit-button "kill all")) - (p "Note that killing an instance implies the killing of all associated continuations. Furthermore, killing all instances implies the killing of instances of this adminstration servlet, i.e. you must restart the servlet from the " - (URL ,(make-callback return-to-main-page) "main page") ".")))) + (define (instances req . maybe-update-text) + (let* ((update-text (:optional maybe-update-text "")) + (current-instances (sort-list! (get-instances) instance-servlet-name