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.
12 (eval-when (:compile-toplevel
:load-toplevel
:execute
)
13 (defun generate-define-view-for-table (table)
15 Generates a form that, when evaluated, initialises the given table as an lol object.
16 This involves creating a meta-model, a clsql view-class, and the setting up the default attributes for a mewa presentation"
19 (def-view-class-from-table ,table
)
20 (set-default-attributes (quote ,(meta-model::sql-
>sym table
))))))
22 (defmacro define-view-for-table
(&rest tables
)
23 " expand to a form which initialises TABLES for use with LOL"
25 ,@(loop for tbl in tables collect
(generate-define-view-for-table tbl
))
28 (defmacro define-views-for-database
()
29 "expands to init-i-f-t using the listing of tables provided by meta-model"
30 `(define-view-for-table ,@(meta-model::list-tables
)))
32 (eval-when (:compile-toplevel
:load-toplevel
:execute
)
33 (defun %make-view
(object type attributes args
)
37 (cons `(:attributes
,attributes
) args
)))
38 `(mewa:make-presentation
43 '(,@ (mapcan #'identity args
)))))))
45 (defmethod make-view (object &rest args
&key
(type :viewer
)
48 ;(warn "~A ~A" args `(:type ,type :initargs ,@args))
49 (apply #'make-presentation object
`(:type
,type
,@ (when args
50 `(:initargs
,args
)))))
52 (defmacro present-view
((object &optional
(type :viewer
) (parent 'self
))
53 &body attributes-and-args
)
54 (arnesi:with-unique-names
(view)
55 `(let ((,view
(lol:make-view
,object
57 ,@(when (car attributes-and-args
)
58 `(:attributes
',(car attributes-and-args
)))
59 ,@ (cdr attributes-and-args
))))
60 (setf (ucw::parent
,view
) ,parent
)
61 (lol:present
,view
))))
64 (defmacro call-view
((object &optional
(type :viewer
) (component 'self component-supplied-p
))
65 &body attributes-and-args
)
68 ,(%make-view object type
(car attributes-and-args
) (cdr attributes-and-args
))))
70 (defmethod slot-view ((self mewa
) slot-name
)
71 (mewa::find-attribute-slot self slot-name
))
73 (defmethod present-slot-view ((self mewa
) slot-name
&optional
(instance (instance self
)))
74 (present-slot (slot-view self slot-name
) instance
))
77 (defmethod find-slots-of-type (model &key
(type 'string
)
78 (types '((string)) types-supplied-p
))
79 "returns a list of slots matching TYPE, or matching any of TYPES"
83 (setf ty
(list type
)))
84 (remove nil
(mapcar #'(lambda (st) (when (member (second st
) ty
)
86 (lisp-on-lines::list-slot-types model
)))))
93 (defmethod word-search (class-name slots search-terms
94 &key
(limit 10) (where (sql-and t
)))
98 (word-search-where class-name slots search-terms
:format-string
"~a%"))
103 (defmethod word-search (class-name slots
(s string
) &rest args
)
104 (apply #'word-search class-name slots
105 (split-sequence:split-sequence
#\Space 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
)))