X-Git-Url: https://git.hcoop.net/clinton/lisp-on-lines.git/blobdiff_plain/e8f6e0863079dba4ba5b6ec8537a8888dcd357f6..6f63d3a4f93eb311344748b5698a63ce42dd1813:/src/lisp-on-lines.lisp diff --git a/src/lisp-on-lines.lisp b/src/lisp-on-lines.lisp index bcd20e5..c58c938 100644 --- a/src/lisp-on-lines.lisp +++ b/src/lisp-on-lines.lisp @@ -8,7 +8,42 @@ ;;;; or Meta-Model. ;;;; ** Initialisation +(defmethod find-default-attributes ((object t)) + "return the default attributes for a given object using the meta-model's meta-data" + (append (mapcar #'(lambda (s) + (cons (car s) + (gen-pslot + (if (meta-model:foreign-key-p object (car s)) + 'foreign-key + (cadr s)) + (string (car s)) (car s)))) + (meta-model:list-slot-types object)) + (mapcar #'(lambda (s) + (cons s (append (gen-pslot 'has-many (string s) s) + `(:presentation + (make-presentation + ,object + :type :one-line))))) + (meta-model:list-has-many object)) + (find-default-presentation-attribute-definitions))) + +(defmethod set-default-attributes ((object t)) + "Set the default attributes for MODEL" + (clear-attributes object) + (mapcar #'(lambda (x) + (setf (find-attribute object (car x)) (cdr x))) + (find-default-attributes object))) + +;;;; This automagically initialises any meta model + +(eval-when (:compile-toplevel :load-toplevel :execute) + (defmethod meta-model::generate-base-class-expander :after (meta-model name args) + (set-default-attributes name))) + ;;;; The following macros are used to initialise a set of database tables as LoL objects. + + + (eval-when (:compile-toplevel :load-toplevel :execute) (defun generate-define-view-for-table (table) " @@ -35,29 +70,30 @@ This involves creating a meta-model, a clsql view-class, and the setting up the (when attributes (setf args (cons `(:attributes ,attributes) args))) - `(mewa:make-presentation + `(mewa::make-presentation ,object :type ,type ,@(when args `(:initargs '(,@ (mapcan #'identity args))))))) -(defmethod make-view (object &rest args &key (type :viewer) (attributes nil) +(defmethod make-view (object &rest args &key (type :viewer) &allow-other-keys ) - (warn "~A ~A ~A" attributes type object) - (remf args :type ) - (remf args :attributes) - (apply #'make-presentation object (cddr (%make-view object type attributes args)))) + (remf args :type) + ;(warn "~A ~A" args `(:type ,type :initargs ,@args)) + (apply #'make-presentation object `(:type ,type ,@ (when args + `(:initargs ,args))))) (defmacro present-view ((object &optional (type :viewer) (parent 'self)) &body attributes-and-args) (arnesi:with-unique-names (view) - `(let ((,view (lol:make-view ,object + `(let ((,view (lol::make-view ,object :type ,type - :attributes ,(car attributes-and-args) + ,@(when (car attributes-and-args) + `(:attributes ',(car attributes-and-args))) ,@ (cdr attributes-and-args)))) (setf (ucw::parent ,view) ,parent) - (lol:present ,view)))) + (lol::present ,view)))) (defmacro call-view ((object &optional (type :viewer) (component 'self component-supplied-p)) @@ -100,8 +136,7 @@ This involves creating a meta-model, a clsql view-class, and the setting up the (defmethod word-search (class-name slots (s string) &rest args) - (apply #'word-search class-name slots - (split-sequence:split-sequence #\Space s) args)) + (apply #'word-search class-name slots (list s) args)) (defmethod word-search-where (class-name slots search-terms &key (format-string "%~a%")) (sql-or