1 (in-package :lisp-on-lines
)
6 ;;;; This file contains the high level functions and macros
7 ;;;; that are part of LoL proper, that is to say, not Mewa
10 ;;;; ** Initialisation
11 ;;;; The following macros are used to initialise a set of database tables as LoL objects.
13 (eval-when (:compile-toplevel
:load-toplevel
:execute
)
14 (defun generate-define-view-for-table (table)
16 Generates a form that, when evaluated, initialises the given table as an lol object.
17 This involves creating a meta-model, a clsql view-class, and the setting up the default attributes for a mewa presentation"
20 (def-view-class-from-table ,table
)
21 (set-default-attributes (quote ,(meta-model::sql-
>sym table
))))))
23 (defmacro define-view-for-table
(&rest tables
)
24 " expand to a form which initialises TABLES for use with LOL"
26 ,@(loop for tbl in tables collect
(generate-define-view-for-table tbl
))
29 (defmacro define-views-for-database
()
30 "expands to init-i-f-t using the listing of tables provided by meta-model"
31 `(define-view-for-table ,@(meta-model::list-tables
)))
33 (eval-when (:compile-toplevel
:load-toplevel
:execute
)
34 (defun %make-view
(object type attributes args
)
38 (cons `(:attributes
,attributes
) args
)))
39 `(mewa::make-presentation
44 '(,@ (mapcan #'identity args
)))))))
46 (defmethod make-view (object &rest args
&key
(type :viewer
)
49 ;(warn "~A ~A" args `(:type ,type :initargs ,@args))
50 (apply #'make-presentation object
`(:type
,type
,@ (when args
51 `(:initargs
,args
)))))
53 (defmacro present-view
((object &optional
(type :viewer
) (parent 'self
))
54 &body attributes-and-args
)
55 (arnesi:with-unique-names
(view)
56 `(let ((,view
(lol::make-view
,object
58 ,@(when (car attributes-and-args
)
59 `(:attributes
',(car attributes-and-args
)))
60 ,@ (cdr attributes-and-args
))))
61 (setf (ucw::parent
,view
) ,parent
)
62 (lol::present
,view
))))
65 (defmacro call-view
((object &optional
(type :viewer
) (component 'self component-supplied-p
))
66 &body attributes-and-args
)
69 ,(%make-view object type
(car attributes-and-args
) (cdr attributes-and-args
))))
71 (defmethod slot-view ((self mewa
) slot-name
)
72 (mewa::find-attribute-slot self slot-name
))
74 (defmethod present-slot-view ((self mewa
) slot-name
&optional
(instance (instance self
)))
75 (present-slot (slot-view self slot-name
) instance
))
78 (defmethod find-slots-of-type (model &key
(type 'string
)
79 (types '((string)) types-supplied-p
))
80 "returns a list of slots matching TYPE, or matching any of TYPES"
84 (setf ty
(list type
)))
85 (remove nil
(mapcar #'(lambda (st) (when (member (second st
) ty
)
87 (lisp-on-lines::list-slot-types model
)))))
94 (defmethod word-search (class-name slots search-terms
95 &key
(limit 10) (where (sql-and t
)))
99 (word-search-where class-name slots search-terms
:format-string
"~a%"))
104 (defmethod word-search (class-name slots
(s string
) &rest args
)
105 (apply #'word-search class-name slots
(list s
) args
))
107 (defmethod word-search-where (class-name slots search-terms
&key
(format-string "%~a%"))
109 (mapcar #'(lambda (term)
111 (mapcar #'(lambda (slot)
113 (sql-slot-value class-name slot
)
114 (format nil format-string term
)))