5 (defun split-list (n list
)
7 by
#'(lambda (x) (nthcdr n x
))
9 collect
(loop for atom in cons
14 (defaction edit-instance
((self mewa
))
15 (call-presentation (instance self
) :type
:editor
))
18 (defcomponent mewa-one-line-presentation
(mewa one-line-presentation
)
21 :attributes-getter
#'one-line-attributes-getter
22 :global-properties
'(:editablep nil
)))
24 (defmethod one-line-attributes-getter ((self mewa
))
25 (or (meta-model::find-slots-of-type
(instance self
))
26 (meta-model::list-keys
(instance self
))))
29 (defcomponent mewa-object-presentation
(mewa object-presentation
)
30 ((instance :accessor instance
:initarg
:instance
:initform nil
)))
32 (defcomponent mewa-viewer
(mewa-object-presentation)
35 :global-properties
'(:editablep nil
)))
37 (defcomponent mewa-editor
(mewa-object-presentation)
40 :global-properties
'(:editablep t
)))
42 (defcomponent mewa-creator
(mewa-editor)
45 (defmethod present ((pres mewa-object-presentation
))
46 (<:table
:class
(css-class pres
)
47 (dolist (slot (slots pres
))
48 (<:tr
:class
"presentation-slot-row"
49 (present-slot-as-row pres slot
))))
50 (render-options pres
(instance pres
)))
52 (defmethod present-slot-as-row ((pres mewa-object-presentation
) (slot slot-presentation
))
53 (<:td
:class
"presentation-slot-label" (<:as-html
(label slot
)))
54 (<:td
:class
"presentation-slot-value" (present-slot slot
(instance pres
))))
57 (defcomponent two-column-presentation
(mewa-object-presentation) ())
59 (defmethod present ((pres two-column-presentation
))
61 (<:table
:class
(css-class pres
)
62 (loop for slot on
(slots pres
) by
#'cddr
64 (<:tr
:class
"presentation-slot-row"
65 (<:td
:class
"presentation-slot-label"
66 (<:as-html
(label (first slot
))))
67 (<:td
:class
"presentation-slot-value"
68 (present-slot (first slot
) (instance pres
)))
70 (<:td
:class
"presentation-slot-label"
71 (<:as-html
(label (second slot
))))
72 (<:td
:class
"presentation-slot-value"
73 (present-slot (second slot
) (instance pres
))))))
74 (render-options pres
(instance pres
))))
78 (defcomponent mewa-list-presentation
(mewa list-presentation
)
79 ((instances :accessor instances
:initarg
:instances
:initform nil
)
80 (instance :accessor instance
)
81 (select-label :accessor select-label
:initform
"select" :initarg
:select-label
)
82 (selectablep :accessor selectablep
:initform t
:initarg
:selectablep
)
83 (deleteablep :accessor deletablep
:initarg
:deletablep
:initform nil
)
84 (viewablep :accessor viewablep
:initarg
:viewablep
:initform nil
)))
86 (defaction select-from-listing
((listing mewa-list-presentation
) object index
)
89 (defmethod render-list-row ((listing mewa-list-presentation
) object index
)
90 (<:tr
:class
"item-row"
91 (<:td
:align
"center" :valign
"top"
92 (when (editablep listing
)
93 (let ((object object
))
94 (<ucw
:input
:type
"submit"
95 :action
(edit-from-listing listing object index
)
96 :value
(edit-label listing
))))
98 (when (deleteablep listing
)
100 (<ucw
:input
:type
"submit"
101 :action
(delete-from-listing listing object index
)
102 :value
(delete-label listing
))))
103 (when (selectablep listing
)
105 (<ucw
:input
:type
"submit"
106 :action
(select-from-listing listing object index
)
107 :value
(select-label listing
))))
108 (when (viewablep listing
)
110 (<ucw
:input
:type
"submit"
111 :action
(call-component listing
(make-presentation object
))
113 (dolist (slot (slots listing
))
114 (<:td
:class
"data-cell" (present-slot slot object
)))
115 (<:td
:class
"index-number-cell")
118 (defmethod get-all-instances ((self mewa-list-presentation
))
122 ;;;; * Presentation Searches
125 ;;;; ** "search all fields" criteria
127 (defgeneric search-expr
(criteria instance
)
128 (:documentation
"Return ready to apply criteria.
129 What to do with it is backend dependent."))
131 (defmacro def-search-expr
(((self criteria-type
)) (model-expr &body body
))
132 `(defmethod search-expr ((,self
,criteria-type
) instance
)
135 (slot-name (presentation ,self
))
138 (defmethod search-expr ((self negated-criteria
) instance
)
139 (when (criteria self
)
142 (search-expr (criteria self
) instance
))))
144 (def-search-expr ((self string-starts-with
))
145 (meta-model:expr-starts-with
(search-text self
)))
147 (def-search-expr ((self string-ends-with
))
148 (meta-model:expr-ends-with
(search-text self
)))
150 (def-search-expr ((self string-contains
))
151 (meta-model:expr-contains
(search-text self
)))
153 (def-search-expr ((self number-less-than
))
154 (meta-model:expr-
< (number-input self
)))
156 (def-search-expr ((self number-greater-than
))
157 (meta-model:expr-
> (number-input self
)))
159 (def-search-expr ((self number-equal-to
))
160 (meta-model:expr-
= (number-input self
)))
164 (defcomponent mewa-presentation-search
(presentation-search)
165 ((display-results-p :accessor display-results-p
:initarg
:display-results-p
:initform nil
)
166 (criteria-input :accessor criteria-input
:initform
"")
167 (new-criteria :accessor new-criteria
:initform nil
)))
169 (defmethod instance ((self mewa
:mewa-presentation-search
))
170 (instance (search-presentation self
)))
172 (defmethod search-expr ((self mewa
:mewa-presentation-search
) instance
)
173 (apply #'meta-model
:expr-and instance
174 (mapcan (lambda (c) (let ((e (search-expr c instance
)))
175 (if (listp e
) e
(list e
))))
178 (defmethod search-query ((self mewa
:mewa-presentation-search
))
179 (search-expr self
(instance self
)))
181 (defmethod valid-instances ((self mewa
:mewa-presentation-search
))
182 (meta-model:select-instances
(instance self
) (search-query self
)))
184 (defmethod get-all-instances ((self mewa-presentation-search
))
185 (meta-model:select-instances
(instance self
)))
187 (defmethod ok ((self mewa-presentation-search
) &optional arg
)
188 (declare (ignore arg
))
189 (setf (instances (list-presentation self
)) (valid-instances self
))
190 (setf (display-results-p self
) t
))
193 (defmethod set-search-input-for-criteria ((criteria criteria
) (input t
))
194 (error "No search-input-for-criteria method for ~A : ~A" criteria input
))
196 (defmethod set-search-input-for-criteria ((c string-criteria
) input
)
197 (setf (search-text c
) input
))
199 (defmethod set-search-input-for-criteria ((c negated-criteria
) i
)
203 (defmethod mewa-add-criteria ((self component
) (criteria criteria
))
204 (set-search-input-for-criteria criteria
(criteria-input self
))
205 (add-criteria self criteria
))
207 (defmethod find-default-criteria (c mewa-string-slot-presentation
)
212 (defmethod render-criteria ((res response
) (s mewa-presentation-search
))
213 (setf (criteria-input s
) "")
215 (dolist (c (criteria s
))
216 (<:li
(render-on res c
)
218 (<ucw
:input
:action
(drop-criteria s c
) :type
"submit" :value
"eliminate"))))
221 (<ucw
:input
:type
"text" :accessor
(criteria-input s
))
223 (<ucw
:select
:accessor
(new-criteria s
)
224 (dolist (criteria (applicable-criteria s
))
225 (<ucw
:option
:value criteria
(<:as-html
(label criteria
)))))
226 (<ucw
:input
:type
"submit" :action
(mewa-add-criteria s
(new-criteria s
))
229 (defmethod submit-search ((s mewa-presentation-search
))
230 (with-slots (criteria-input) s
232 (unless (or (null criteria-input
)
233 (string-equal "" (remove #\Space criteria-input
)))
235 (mewa-add-criteria s
(new-criteria s
)))
239 (defmethod render-on ((res response
) (self mewa-presentation-search
))
240 ;(<:as-html (search-query self))
241 (render-criteria res self
)
242 (<ucw
:input
:type
"submit" :value
"Search" :action
(submit-search self
))
243 (when (display-results-p self
)
244 (let ((listing (list-presentation self
)))
246 (slot-value listing
'ucw
::calling-component
) (slot-value self
'ucw
::calling-component
)
247 (slot-value listing
'ucw
::place
) (slot-value self
'ucw
::place
)
248 (slot-value listing
'ucw
::continuation
) (slot-value self
'ucw
::continuation
))
250 (render-on res listing
))))
254 (defcomponent dont-show-unset-slots
()())
256 (defmethod slots :around
((self dont-show-unset-slots
))
257 (remove-if-not #'(lambda (s) (let ((s (presentation-slot-value s
(instance self
))))
258 (and s
(not (equal "" s
)))))