Did some work on searching, changed object presentation to specialise on each row...
authorDrew Crampsie <drewc@tech.coop>
Mon, 1 Aug 2005 23:45:25 +0000 (16:45 -0700)
committerDrew Crampsie <drewc@tech.coop>
Mon, 1 Aug 2005 23:45:25 +0000 (16:45 -0700)
darcs-hash:20050801234525-5417e-1d7ffc7570525650141333ca2c7ffd3d7a373db7.gz

src/mewa/presentations.lisp
src/mewa/slot-presentations.lisp

index 62e93d1..15f0e16 100644 (file)
 (defcomponent mewa-object-presentation (mewa ucw:object-presentation) 
   ((ucw::instance :accessor instance :initarg :instance :initform nil)))
 
 (defcomponent mewa-object-presentation (mewa ucw:object-presentation) 
   ((ucw::instance :accessor instance :initarg :instance :initform nil)))
 
+(defmethod present ((pres mewa-object-presentation))
+  (<:table :class (css-class pres)
+    (dolist (slot (slots pres))
+      (<:tr :class "presentation-slot-row"
+           (present-slot-as-row pres slot))))
+    (render-options pres (instance pres)))
+        
+(defmethod present-slot-as-row ((pres mewa-object-presentation) (slot ucw::slot-presentation))
+  (<:td :class "presentation-slot-label" (<:as-html (label slot)))
+  (<:td :class "presentation-slot-value" (present-slot slot (instance pres))))
+
+
 (defcomponent two-column-presentation (mewa-object-presentation) ())
 
 (defmethod present ((pres two-column-presentation))
 (defcomponent two-column-presentation (mewa-object-presentation) ())
 
 (defmethod present ((pres two-column-presentation))
   (instances self))
 
 
   (instances self))
 
 
-;;; searching
+;;;; * Presentation Searches
+
+
+;;;; ** "search all fields" criteria
+
 (defgeneric search-expr (criteria instance)
   (:documentation "Return ready to apply criteria.
                    What to do with it is backend dependent."))
 (defgeneric search-expr (criteria instance)
   (:documentation "Return ready to apply criteria.
                    What to do with it is backend dependent."))
 (def-search-expr ((self ucw::number-equal-to))
     (meta-model:expr-= (ucw::number-input self)))
 
 (def-search-expr ((self ucw::number-equal-to))
     (meta-model:expr-= (ucw::number-input self)))
 
+
+
 (defcomponent mewa-presentation-search (ucw::presentation-search)
 (defcomponent mewa-presentation-search (ucw::presentation-search)
-  ((display-results-p :accessor display-results-p :initarg :display-results-p :initform nil)))
+  ((display-results-p :accessor display-results-p :initarg :display-results-p :initform nil)
+   (criteria-input :accessor criteria-input :initform "")
+   (new-criteria :accessor new-criteria :initform nil)))
 
 (defmethod instance ((self mewa:mewa-presentation-search))
   (instance (ucw::search-presentation self)))
 
 (defmethod search-expr ((self mewa:mewa-presentation-search) instance)
   (apply #'meta-model:expr-and instance
 
 (defmethod instance ((self mewa:mewa-presentation-search))
   (instance (ucw::search-presentation self)))
 
 (defmethod search-expr ((self mewa:mewa-presentation-search) instance)
   (apply #'meta-model:expr-and instance
-         (mapcan (lambda (c) (let ((e (search-expr c instance)))
+         (mapcan (lambda (c) (let ((e  (search-expr c instance)))
                                (if (listp e) e (list e))))
                  (ucw::criteria self))))
 
                                (if (listp e) e (list e))))
                  (ucw::criteria self))))
 
   (setf (display-results-p self) t))
 
 
   (setf (display-results-p self) t))
 
 
+(defmethod set-search-input-for-criteria ((criteria ucw::criteria) (input t))
+  (error "No search-input-for-criteria method for ~A : ~A" criteria input))
+
+(defmethod set-search-input-for-criteria ((c ucw::string-criteria) input)
+  (setf (ucw::search-text c) input))
+
+(defmethod set-search-input-for-criteria ((c ucw::negated-criteria) i)
+  nil)
+
+
+(defmethod mewa-add-criteria ((self component) (criteria ucw::criteria))
+  (set-search-input-for-criteria criteria (criteria-input self))
+  (ucw::add-criteria self criteria))
+
+(defmethod find-default-criteria (c ucw::mewa-string-slot-presentation)
+  'ucw::string-contains)
+
+
+
+(defmethod render-criteria ((res response) (s mewa-presentation-search))
+  (setf (criteria-input s) "")
+  (<:ul
+   (dolist (c (criteria s))
+     (<:li (render-on res c)
+          (let ((c c))
+            (<ucw:input :action (ucw::drop-criteria s c) :type "submit" :value "eliminate"))))
+     (<:li 
+      "Search For: "
+      (<ucw:input :type "text" :accessor (criteria-input s))
+      " Using : "
+       (<ucw:select :accessor (new-criteria s) 
+         (dolist (criteria (ucw::applicable-criteria s))
+          (<ucw:option :value criteria (<:as-html (label criteria)))))
+       (<ucw:input :type "submit" :action (mewa-add-criteria s (new-criteria s))
+                  :value "add"))))
+
+(defmethod submit-search ((s mewa-presentation-search))
+  (with-slots (criteria-input) s
+    
+    (unless (or (null criteria-input)
+               (string-equal "" (remove #\Space criteria-input)))
+      
+      (mewa-add-criteria s (new-criteria s)))
+              
+    (ok s)))
+
 (defmethod render-on ((res response) (self mewa-presentation-search))
   ;(<:as-html (search-query self))
 (defmethod render-on ((res response) (self mewa-presentation-search))
   ;(<:as-html (search-query self))
-  (ucw::render-criteria res self)
-  (<ucw:input :type "submit" :value "Search" :action (ok self))
+  (render-criteria res self)
+  (<ucw:input :type "submit" :value "Search" :action (submit-search self))
   (when (display-results-p self)
     (let ((listing (ucw::list-presentation self)))
       (setf 
   (when (display-results-p self)
     (let ((listing (ucw::list-presentation self)))
       (setf 
       
       (render-on res listing))))
 
       
       (render-on res listing))))
 
-;;;;
+
+;;;; 
 (defcomponent dont-show-unset-slots ()())
 
 (defmethod slots :around ((self dont-show-unset-slots))
 (defcomponent dont-show-unset-slots ()())
 
 (defmethod slots :around ((self dont-show-unset-slots))
index 4a746d3..cbd2525 100644 (file)
@@ -82,6 +82,8 @@ When T, only the default value for primary keys and the joins are updated."))
         ifFormat       :    \"%m/%d/%Y\",
       });" input-id))))))
 
         ifFormat       :    \"%m/%d/%Y\",
       });" input-id))))))
 
+
+
 (defslot-presentation  mewa-relation-slot-presentation (mewa-slot-presentation slot-presentation)
   ((foreign-instance :accessor foreign-instance)
    (linkedp :accessor linkedp :initarg :linkedp :initform t)
 (defslot-presentation  mewa-relation-slot-presentation (mewa-slot-presentation slot-presentation)
   ((foreign-instance :accessor foreign-instance)
    (linkedp :accessor linkedp :initarg :linkedp :initform t)
@@ -93,7 +95,7 @@ When T, only the default value for primary keys and the joins are updated."))
       (meta-model:explode-foreign-key instance (slot-name slot))
     (let ((new-instance
             (call-component 
       (meta-model:explode-foreign-key instance (slot-name slot))
     (let ((new-instance
             (call-component 
-             (parent slot) 
+             (parent slot)
              (make-instance (or (cadr (mewa:find-attribute finstance :presentation-search))
                                 'mewa::mewa-presentation-search)
                             :search-presentation
              (make-instance (or (cadr (mewa:find-attribute finstance :presentation-search))
                                 'mewa::mewa-presentation-search)
                             :search-presentation
@@ -186,7 +188,6 @@ When T, only the default value for primary keys and the joins are updated."))
   ((add-new-label :accessor add-new-label :initarg :add-new-label :initform "Add New"))
   (:type-name has-many))
 
   ((add-new-label :accessor add-new-label :initarg :add-new-label :initform "Add New"))
   (:type-name has-many))
 
-
 (defaction add-to-has-many ((slot has-many-slot-presentation) instance)
   ;; if the instance is not stored we must make sure to mark it stored now!
   (unless (mewa::instance-is-stored-p instance)
 (defaction add-to-has-many ((slot has-many-slot-presentation) instance)
   ;; if the instance is not stored we must make sure to mark it stored now!
   (unless (mewa::instance-is-stored-p instance)
@@ -285,3 +286,16 @@ When T, only the default value for primary keys and the joins are updated."))
            (setf (instance (presentation slot)) (presentation-slot-value slot instance))
            (present (presentation slot)))
          (<:as-html "--"))))
            (setf (instance (presentation slot)) (presentation-slot-value slot instance))
            (present (presentation slot)))
          (<:as-html "--"))))
+
+(defslot-presentation inline-slot-presentation (mewa-relation-slot-presentation)
+  ()
+  (:type-name inline))
+
+(defmethod present-slot ((slot inline-slot-presentation) instance)
+  (<:fieldset 
+   (<:legend (<:as-html (label slot)))
+  (<ucw:render-component :component (mewa:make-presentation (meta-model::explode-foreign-key instance (slot-name slot)) :type :editor))))
+
+(defmethod mewa::present-slot-as-row ((self mewa::mewa-object-presentation) (slot inline-slot-presentation))
+  (<:td :colspan 2
+       (present-slot slot (instance self))))
\ No newline at end of file