The isearch feature is IMHO one of the most awesome aspects of weblocks. Even before an efficient interface to the underlying store is made, it would be really nice to have it.
Here's a version of nunb's great filtered grid (http://paste.lisp.org/display/81353) which (a) compiles, (b) doesn't depend on sbcl, and (c) moves the isearch box to the top of the grid. A lot of other changes were made. What do you think about it? Perhaps it should be a mixin instead as nunb suggested? I think MSI might be willing to do a bit of work to get it tidy enough to be included. I guess there is this worrying comment ;(send-script (ps* `(.activate ($ ,sym)))) ;why the hell does this not work? what is the webloxy way of doing focus? (in-package :weblocks) (defwidget filtered-grid (gridedit) ((filters :initform nil :accessor grid-filters :documentation "a regex string to search for"))) (defmethod dataseq-render-pagination-widget ((obj filtered-grid) &rest args) (with-html (:div :class "pagination-side" (dataseq-render-pagination-widget-default obj args)))) (defmethod render-widget-body :before ((obj filtered-grid) &rest args) (with-html (:div :class "search-side" :id "search_ui_id" (fg-render-search-ui obj)))) (defmethod render-dataseq-body ((obj filtered-grid) &rest args) (let* ((data-sequence (dataseq-data obj))) (when (and (grid-filters obj) (text-input-present-p (grid-filters obj))) (setf data-sequence (fg-filter-sequence obj data-sequence))) (setf (slot-value obj 'rendered-data-sequence) nil) ;Can this be used to cache? Why is it here (did it have something to do with the old isearch?) (with-html (:div :class "datagrid-body" (apply #'render-object-view data-sequence (dataseq-view obj) :widget obj :summary (if (dataseq-sort obj) (format nil "Ordered by ~A, ~A." (string-downcase (humanize-name (dataseq-sort-slot obj))) (string-downcase (humanize-sort-direction (dataseq-sort-direction obj)))) nil) :custom-fields (append-custom-fields (remove nil (list (when (dataseq-allow-select-p obj) (cons 0 (weblocks::make-select-field obj))) (when (and (dataseq-allow-drilldown-p obj) (dataseq-on-drilldown obj)) (weblocks::make-drilldown-field obj)))) args) args)) (setf (slot-value obj 'rendered-data-sequence) data-sequence)))) (defmacro closure (&body body) (with-unique-names (args) `(lambda (&rest ,args) (declare (ignore ,args)) ,@body))) (defmethod fg-render-reset ((obj filtered-grid)) (with-html (:span :class "reset" (render-link (closure (fg-reset-filters obj)) "reset")))) (defmethod fg-reset-filters ((obj filtered-grid)) (setf (grid-filters obj) nil) (mark-dirty obj)) (defmethod fg-render-search-ui ((obj filtered-grid) &rest args) (let ((sym (gensym "search"))) (render-isearch "filter" (f (&rest args &key filter &allow-other-keys) (setf (grid-filters obj) filter) (mark-dirty obj)) :class (if (grid-filters obj) "grid_search filtered" "grid_search empty") :value (grid-filters obj) :input-id sym) ;(send-script (ps* `(.activate ($ ,sym)))) ;why the hell does this not work? (send-script (format nil "$('~A').focus();" sym)) )) (defmethod fg-filter-sequence ((obj filtered-grid) seq) (let* ((filters (grid-filters obj)) (scanner (cl-ppcre:create-scanner filters :case-insensitive-mode (notany #'upper-case-p filters)))) (with-standard-io-syntax (remove-if-not (lambda (item) (let ((obj-as-string (format nil "~{~A~}" (fg-render-object-view-body-row (dataseq-view obj) item obj)))) (cl-ppcre:all-matches scanner obj-as-string))) seq)))) ;;; Getting a table-view like view of this thingie (in fg-filter-sequence) ;;; instead of (format nil "~{~A~}" (loop for slot in slots collect (slot-value item (sb-mop:slot-definition-name slot)))) (defmethod fg-render-object-view-body-row (view obj widget &rest args) "Render a string representation of a data object for full-text search" (apply #'map-view-fields (lambda (field-info) (let ((field (field-info-field field-info)) (obj (field-info-object field-info))) (apply #'fg-render-view-field field view widget (view-field-presentation field) (obtain-view-field-value field obj) obj args))) view obj args)) (defmethod fg-render-view-field (field view widget presentation value obj &rest args) (apply #'print-view-field-value value presentation field view widget obj args)) ; or use #'render-view-field-value? [...] --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "weblocks" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/weblocks?hl=en -~----------~----~----~----~------~----~------~--~---
