Commit | Line | Data |
---|---|---|
15bc66bd | 1 | (declaim (optimize (speed 0) (space 3) (safety 0))) |
5dea194e | 2 | (in-package :lisp-on-lines) |
687d5f1c | 3 | |
b8c89851 DC |
4 | |
5 | (defmethod render ((self mewa)) | |
6 | (lol::present self)) | |
7 | ||
7f16078d | 8 | (defaction edit-instance ((self mewa)) |
9 | (call-presentation (instance self) :type :editor)) | |
10 | ||
687d5f1c | 11 | ;;;one-line objects |
b8c89851 | 12 | (defcomponent mewa-one-line-presentation (mewa lol::one-line-presentation) |
687d5f1c | 13 | () |
d5e996b3 DC |
14 | (:default-initargs |
15 | :attributes-getter #'one-line-attributes-getter | |
16 | :global-properties '(:editablep nil))) | |
687d5f1c | 17 | |
18 | (defmethod one-line-attributes-getter ((self mewa)) | |
d5e996b3 DC |
19 | (or (meta-model::find-slots-of-type (instance self)) |
20 | (meta-model::list-keys (instance self)))) | |
687d5f1c | 21 | |
22 | ;;;objects | |
b8c89851 | 23 | (defcomponent mewa-object-presentation (mewa lol::object-presentation) |
38a016c7 | 24 | ((instance :accessor instance :initarg :instance :initform nil))) |
687d5f1c | 25 | |
d5e996b3 DC |
26 | (defcomponent mewa-viewer (mewa-object-presentation) |
27 | () | |
28 | (:default-initargs | |
29 | :global-properties '(:editablep nil))) | |
30 | ||
31 | (defcomponent mewa-editor (mewa-object-presentation) | |
32 | () | |
33 | (:default-initargs | |
34 | :global-properties '(:editablep t))) | |
35 | ||
36 | (defcomponent mewa-creator (mewa-editor) | |
37 | ()) | |
38 | ||
5f0b37e7 DC |
39 | (defmethod present ((pres mewa-object-presentation)) |
40 | (<:table :class (css-class pres) | |
41 | (dolist (slot (slots pres)) | |
42 | (<:tr :class "presentation-slot-row" | |
43 | (present-slot-as-row pres slot)))) | |
b8c89851 | 44 | (render-options pres (instance pres))) |
5f0b37e7 | 45 | |
38a016c7 | 46 | (defmethod present-slot-as-row ((pres mewa-object-presentation) (slot slot-presentation)) |
5f0b37e7 DC |
47 | (<:td :class "presentation-slot-label" (<:as-html (label slot))) |
48 | (<:td :class "presentation-slot-value" (present-slot slot (instance pres)))) | |
49 | ||
50 | ||
6460c439 | 51 | (defcomponent two-column-presentation (mewa-object-presentation) ()) |
52 | ||
53 | (defmethod present ((pres two-column-presentation)) | |
54 | ||
55 | (<:table :class (css-class pres) | |
56 | (loop for slot on (slots pres) by #'cddr | |
57 | do | |
58 | (<:tr :class "presentation-slot-row" | |
59 | (<:td :class "presentation-slot-label" | |
60 | (<:as-html (label (first slot)))) | |
61 | (<:td :class "presentation-slot-value" | |
62 | (present-slot (first slot) (instance pres))) | |
63 | (when (second slot) | |
64 | (<:td :class "presentation-slot-label" | |
65 | (<:as-html (label (second slot)))) | |
66 | (<:td :class "presentation-slot-value" | |
67 | (present-slot (second slot) (instance pres)))))) | |
68 | (render-options pres (instance pres)))) | |
69 | ||
70 | ||
687d5f1c | 71 | ;;;lists |
38a016c7 DC |
72 | (defcomponent mewa-list-presentation (mewa list-presentation) |
73 | ((instances :accessor instances :initarg :instances :initform nil) | |
687d5f1c | 74 | (instance :accessor instance) |
75 | (select-label :accessor select-label :initform "select" :initarg :select-label) | |
8e6e6b56 | 76 | (selectablep :accessor selectablep :initform t :initarg :selectablep) |
38a016c7 | 77 | (deleteablep :accessor deletablep :initarg :deletablep :initform nil) |
8e6e6b56 | 78 | (viewablep :accessor viewablep :initarg :viewablep :initform nil))) |
687d5f1c | 79 | |
80 | (defaction select-from-listing ((listing mewa-list-presentation) object index) | |
81 | (answer object)) | |
82 | ||
83 | (defmethod render-list-row ((listing mewa-list-presentation) object index) | |
84 | (<:tr :class "item-row" | |
85 | (<:td :align "center" :valign "top" | |
38a016c7 | 86 | (when (editablep listing) |
687d5f1c | 87 | (let ((object object)) |
88 | (<ucw:input :type "submit" | |
89 | :action (edit-from-listing listing object index) | |
38a016c7 | 90 | :value (edit-label listing)))) |
687d5f1c | 91 | (<:as-is " ") |
38a016c7 | 92 | (when (deleteablep listing) |
687d5f1c | 93 | (let ((index index)) |
94 | (<ucw:input :type "submit" | |
95 | :action (delete-from-listing listing object index) | |
38a016c7 | 96 | :value (delete-label listing)))) |
687d5f1c | 97 | (when (selectablep listing) |
98 | (let ((index index)) | |
99 | (<ucw:input :type "submit" | |
100 | :action (select-from-listing listing object index) | |
8e6e6b56 DC |
101 | :value (select-label listing)))) |
102 | (when (viewablep listing) | |
103 | (let ((index index)) | |
104 | (<ucw:input :type "submit" | |
105 | :action (call-component listing (make-presentation object)) | |
106 | :value "view")))) | |
687d5f1c | 107 | (dolist (slot (slots listing)) |
108 | (<:td :class "data-cell" (present-slot slot object))) | |
15bc66bd | 109 | (<:td :class "index-number-cell"))) |
687d5f1c | 110 | |
111 | (defmethod get-all-instances ((self mewa-list-presentation)) | |
112 | (instances self)) | |
aef3b247 | 113 | |
114 | ||
5f0b37e7 DC |
115 | ;;;; * Presentation Searches |
116 | ||
117 | ||
118 | ;;;; ** "search all fields" criteria | |
119 | ||
9d6c69fb DC |
120 | (defgeneric search-expr (criteria instance) |
121 | (:documentation "Return ready to apply criteria. | |
5dea194e | 122 | to do with What it is backend dependent.")) |
aef3b247 | 123 | |
9d6c69fb DC |
124 | (defmacro def-search-expr (((self criteria-type)) (model-expr &body body)) |
125 | `(defmethod search-expr ((,self ,criteria-type) instance) | |
126 | (,model-expr | |
127 | instance | |
38a016c7 | 128 | (slot-name (presentation ,self)) |
9d6c69fb DC |
129 | ,@body))) |
130 | ||
38a016c7 DC |
131 | (defmethod search-expr ((self negated-criteria) instance) |
132 | (when (criteria self) | |
9d6c69fb DC |
133 | (meta-model:expr-not |
134 | instance | |
38a016c7 | 135 | (search-expr (criteria self) instance)))) |
9d6c69fb | 136 | |
38a016c7 DC |
137 | (def-search-expr ((self string-starts-with)) |
138 | (meta-model:expr-starts-with (search-text self))) | |
9d6c69fb | 139 | |
38a016c7 DC |
140 | (def-search-expr ((self string-ends-with)) |
141 | (meta-model:expr-ends-with (search-text self))) | |
9d6c69fb | 142 | |
38a016c7 DC |
143 | (def-search-expr ((self string-contains)) |
144 | (meta-model:expr-contains (search-text self))) | |
9d6c69fb | 145 | |
38a016c7 DC |
146 | (def-search-expr ((self number-less-than)) |
147 | (meta-model:expr-< (number-input self))) | |
9d6c69fb | 148 | |
38a016c7 DC |
149 | (def-search-expr ((self number-greater-than)) |
150 | (meta-model:expr-> (number-input self))) | |
9d6c69fb | 151 | |
38a016c7 DC |
152 | (def-search-expr ((self number-equal-to)) |
153 | (meta-model:expr-= (number-input self))) | |
9d6c69fb | 154 | |
5f0b37e7 DC |
155 | |
156 | ||
38a016c7 | 157 | (defcomponent mewa-presentation-search (presentation-search) |
5f0b37e7 DC |
158 | ((display-results-p :accessor display-results-p :initarg :display-results-p :initform nil) |
159 | (criteria-input :accessor criteria-input :initform "") | |
160 | (new-criteria :accessor new-criteria :initform nil))) | |
9d6c69fb DC |
161 | |
162 | (defmethod instance ((self mewa:mewa-presentation-search)) | |
38a016c7 | 163 | (instance (search-presentation self))) |
9d6c69fb DC |
164 | |
165 | (defmethod search-expr ((self mewa:mewa-presentation-search) instance) | |
166 | (apply #'meta-model:expr-and instance | |
5f0b37e7 | 167 | (mapcan (lambda (c) (let ((e (search-expr c instance))) |
9d6c69fb | 168 | (if (listp e) e (list e)))) |
38a016c7 | 169 | (criteria self)))) |
9d6c69fb | 170 | |
9d6c69fb DC |
171 | (defmethod search-query ((self mewa:mewa-presentation-search)) |
172 | (search-expr self (instance self))) | |
173 | ||
174 | (defmethod valid-instances ((self mewa:mewa-presentation-search)) | |
175 | (meta-model:select-instances (instance self) (search-query self))) | |
176 | ||
177 | (defmethod get-all-instances ((self mewa-presentation-search)) | |
178 | (meta-model:select-instances (instance self))) | |
aef3b247 | 179 | |
180 | (defmethod ok ((self mewa-presentation-search) &optional arg) | |
181 | (declare (ignore arg)) | |
38a016c7 | 182 | (setf (instances (list-presentation self)) (valid-instances self)) |
aef3b247 | 183 | (setf (display-results-p self) t)) |
184 | ||
4e7631c9 | 185 | |
38a016c7 | 186 | (defmethod set-search-input-for-criteria ((criteria criteria) (input t)) |
5f0b37e7 DC |
187 | (error "No search-input-for-criteria method for ~A : ~A" criteria input)) |
188 | ||
38a016c7 DC |
189 | (defmethod set-search-input-for-criteria ((c string-criteria) input) |
190 | (setf (search-text c) input)) | |
5f0b37e7 | 191 | |
38a016c7 | 192 | (defmethod set-search-input-for-criteria ((c negated-criteria) i) |
5f0b37e7 DC |
193 | nil) |
194 | ||
195 | ||
38a016c7 | 196 | (defmethod mewa-add-criteria ((self component) (criteria criteria)) |
5f0b37e7 | 197 | (set-search-input-for-criteria criteria (criteria-input self)) |
38a016c7 | 198 | (add-criteria self criteria)) |
5f0b37e7 | 199 | |
38a016c7 DC |
200 | (defmethod find-default-criteria (c mewa-string-slot-presentation) |
201 | 'string-contains) | |
5f0b37e7 | 202 | |
5f0b37e7 DC |
203 | (defmethod render-criteria ((res response) (s mewa-presentation-search)) |
204 | (setf (criteria-input s) "") | |
205 | (<:ul | |
38a016c7 | 206 | (dolist (c (criteria s)) |
5f0b37e7 DC |
207 | (<:li (render-on res c) |
208 | (let ((c c)) | |
38a016c7 | 209 | (<ucw:input :action (drop-criteria s c) :type "submit" :value "eliminate")))) |
5f0b37e7 DC |
210 | (<:li |
211 | "Search For: " | |
212 | (<ucw:input :type "text" :accessor (criteria-input s)) | |
213 | " Using : " | |
214 | (<ucw:select :accessor (new-criteria s) | |
38a016c7 | 215 | (dolist (criteria (applicable-criteria s)) |
5f0b37e7 DC |
216 | (<ucw:option :value criteria (<:as-html (label criteria))))) |
217 | (<ucw:input :type "submit" :action (mewa-add-criteria s (new-criteria s)) | |
218 | :value "add")))) | |
219 | ||
220 | (defmethod submit-search ((s mewa-presentation-search)) | |
221 | (with-slots (criteria-input) s | |
222 | ||
223 | (unless (or (null criteria-input) | |
224 | (string-equal "" (remove #\Space criteria-input))) | |
225 | ||
226 | (mewa-add-criteria s (new-criteria s))) | |
227 | ||
228 | (ok s))) | |
229 | ||
aef3b247 | 230 | (defmethod render-on ((res response) (self mewa-presentation-search)) |
7c3aade7 | 231 | ;(<:as-html (search-query self)) |
5f0b37e7 DC |
232 | (render-criteria res self) |
233 | (<ucw:input :type "submit" :value "Search" :action (submit-search self)) | |
aef3b247 | 234 | (when (display-results-p self) |
38a016c7 | 235 | (let ((listing (list-presentation self))) |
9d6c69fb DC |
236 | (setf |
237 | (slot-value listing 'ucw::calling-component) (slot-value self 'ucw::calling-component) | |
238 | (slot-value listing 'ucw::place) (slot-value self 'ucw::place) | |
239 | (slot-value listing 'ucw::continuation) (slot-value self 'ucw::continuation)) | |
240 | ||
bbf64329 | 241 | (render-on res listing)))) |
242 | ||
5f0b37e7 DC |
243 | |
244 | ;;;; | |
bbf64329 | 245 | (defcomponent dont-show-unset-slots ()()) |
246 | ||
247 | (defmethod slots :around ((self dont-show-unset-slots)) | |
248 | (remove-if-not #'(lambda (s) (let ((s (presentation-slot-value s (instance self)))) | |
249 | (and s (not (equal "" s))))) | |
250 | (call-next-method))) |