X-Git-Url: https://git.hcoop.net/clinton/lisp-on-lines.git/blobdiff_plain/6fc8733b376ef21d53863abcd6b5647e37da8041..12dcf3d4b06fd83b8c62c01a93dc26f94dc922ee:/src/mewa/presentations.lisp diff --git a/src/mewa/presentations.lisp b/src/mewa/presentations.lisp index 0ec34ee..39a6647 100644 --- a/src/mewa/presentations.lisp +++ b/src/mewa/presentations.lisp @@ -1,5 +1,8 @@ (in-package :mewa) +(defaction edit-instance ((self mewa)) + (call-presentation (instance self) :type :editor)) + ;;;one-line objects (defcomponent mewa-one-line-presentation (mewa one-line-presentation) () @@ -67,3 +70,87 @@ (defmethod get-all-instances ((self mewa-list-presentation)) (instances self)) + + +;;; searching +(defgeneric search-expr (criteria instance) + (:documentation "Return ready to apply criteria. + What to do with it is backend dependent.")) + +(defmacro def-search-expr (((self criteria-type)) (model-expr &body body)) + `(defmethod search-expr ((,self ,criteria-type) instance) + (,model-expr + instance + (ucw::slot-name (ucw::presentation ,self)) + ,@body))) + +(defmethod search-expr ((self ucw::negated-criteria) instance) + (when (ucw::criteria self) + (meta-model:expr-not + instance + (search-expr (ucw::criteria self) instance)))) + +(def-search-expr ((self ucw::string-starts-with)) + (meta-model:expr-starts-with (ucw::search-text self))) + +(def-search-expr ((self ucw::string-ends-with)) + (meta-model:expr-ends-with (ucw::search-text self))) + +(def-search-expr ((self ucw::string-contains)) + (meta-model:expr-contains (ucw::search-text self))) + +(def-search-expr ((self ucw::number-less-than)) + (meta-model:expr-< (ucw::number-input self))) + +(def-search-expr ((self ucw::number-greater-than)) + (meta-model:expr-> (ucw::number-input self))) + +(def-search-expr ((self ucw::number-equal-to)) + (meta-model:expr-= (ucw::number-input self))) + +(defcomponent mewa-presentation-search (ucw::presentation-search) + ((display-results-p :accessor display-results-p :initarg :display-results-p :initform nil))) + +(defmethod instance ((self mewa:mewa-presentation-search)) + (instance (ucw::search-presentation self))) + +(defmethod search-expr ((self mewa:mewa-presentation-search) instance) + (apply #'meta-model:expr-and instance + (mapcan (lambda (c) (let ((e (search-expr c instance))) + (if (listp e) e (list e)))) + (ucw::criteria self)))) + + +(defmethod search-query ((self mewa:mewa-presentation-search)) + (search-expr self (instance self))) + +(defmethod valid-instances ((self mewa:mewa-presentation-search)) + (meta-model:select-instances (instance self) (search-query self))) + +(defmethod get-all-instances ((self mewa-presentation-search)) + (meta-model:select-instances (instance self))) + +(defmethod ok ((self mewa-presentation-search) &optional arg) + (declare (ignore arg)) + (setf (ucw::list-presentation self) (valid-instances self)) + (setf (display-results-p self) t)) + +(defmethod render-on ((res response) (self mewa-presentation-search)) + (ucw::render-criteria res self) + (