From 91b9f259d38073a9847ede172cdda1218f2c35fb Mon Sep 17 00:00:00 2001 From: drewc Date: Mon, 29 May 2006 18:12:59 -0700 Subject: [PATCH] Removed most of the old LoL stuff for good. darcs-hash:20060530011259-39164-cb6dd4434ba378f27e9352eacd48625811f642ad.gz --- lisp-on-lines.asd | 20 +- src/{ => attributes}/dojo-attributes.lisp | 0 src/attributes/numbers.lisp | 7 +- .../relational-attributes.lisp | 9 +- src/{ => attributes}/standard-attributes.lisp | 0 src/packages.lisp | 58 +- src/presentations.lisp | 250 ----- src/slot-presentations.lisp | 480 --------- src/slot-presentations/date.lisp | 246 ----- src/standard-display.lisp | 30 +- src/static-presentations.lisp | 944 ------------------ 11 files changed, 24 insertions(+), 2020 deletions(-) rename src/{ => attributes}/dojo-attributes.lisp (100%) rename src/{ => attributes}/relational-attributes.lisp (91%) rename src/{ => attributes}/standard-attributes.lisp (100%) delete mode 100644 src/presentations.lisp delete mode 100644 src/slot-presentations.lisp delete mode 100644 src/slot-presentations/date.lisp delete mode 100644 src/static-presentations.lisp diff --git a/lisp-on-lines.asd b/lisp-on-lines.asd index b0e6b99..2e4eb26 100644 --- a/lisp-on-lines.asd +++ b/lisp-on-lines.asd @@ -11,7 +11,8 @@ (defsystem :lisp-on-lines :components ((:static-file "lisp-on-lines.asd") (:module :patches - :components ((:file "yaclml"))) + :components ((:file "yaclml") + (:file "ucw"))) (:module :src :components ((:file "packages") (:file "special-initargs") @@ -23,17 +24,18 @@ (:file "defdisplay") (:file "standard-display") (:file "standard-occurence") - (:file "standard-attributes") - (:file "dojo-attributes") (:file "standard-wrappers") - (:file "relational-attributes") - (:file "lines") - - (:file "backwards-compat") + (:file "defdescription") (:module :attributes - - :components ((:file "numbers")))) + :components ( + (:file "standard-attributes") + (:file "numbers") + (:file "relational-attributes") + (:file "dojo-attributes")) + :serial t) + (:module :components + :components ((:file "crud")))) :serial t)) :serial t :depends-on (:arnesi :ucw :meta-model :split-sequence :contextl :cl-ppcre :cl-fad)) diff --git a/src/dojo-attributes.lisp b/src/attributes/dojo-attributes.lisp similarity index 100% rename from src/dojo-attributes.lisp rename to src/attributes/dojo-attributes.lisp diff --git a/src/attributes/numbers.lisp b/src/attributes/numbers.lisp index a2d4b8f..520e621 100644 --- a/src/attributes/numbers.lisp +++ b/src/attributes/numbers.lisp @@ -12,6 +12,9 @@ (defattribute integer-attribute (number-attribute integer-field) () (:in-layer editor) + (:default-initargs + :default-value "" + :default-value-predicate (complement #'numberp)) (:type-name integer)) @@ -41,10 +44,6 @@ () (:type-name currency)) -(defdisplay - ((currency currency-attribute) object) - (<:as-html "$") - (call-next-method)) (defdisplay :in-layer editor ((currency currency-attribute) object) diff --git a/src/relational-attributes.lisp b/src/attributes/relational-attributes.lisp similarity index 91% rename from src/relational-attributes.lisp rename to src/attributes/relational-attributes.lisp index 7e17d58..2b7cdbf 100644 --- a/src/relational-attributes.lisp +++ b/src/attributes/relational-attributes.lisp @@ -14,7 +14,14 @@ ;; (define-layered-method attribute-value (object (attribute has-a)) - (meta-model:explode-foreign-key object (slot-name attribute) :nilp t)) + (multiple-value-bind (obj key class) + (meta-model:explode-foreign-key object (slot-name attribute) :nilp t) + (if (persistentp object) + obj + (first (select class + :where [= [slot-value class key] (call-next-method)] + :flatp t + ))))) (define-layered-method (setf attribute-value) ((value standard-object) object (attribute has-a)) (let ((val (slot-value value (find-if (curry #'primary-key-p value) (list-keys value))))) diff --git a/src/standard-attributes.lisp b/src/attributes/standard-attributes.lisp similarity index 100% rename from src/standard-attributes.lisp rename to src/attributes/standard-attributes.lisp diff --git a/src/packages.lisp b/src/packages.lisp index 683edfe..ace541f 100644 --- a/src/packages.lisp +++ b/src/packages.lisp @@ -23,19 +23,6 @@ :time-element :time+ :date-element) - - (:shadow - :present - :present-slot - :presentation - :instance - :slot-presentation - :integer-slot-presentation - :string-slot-presentation - :object-presentation - :one-line-presentation - :presentation-slot-value - :get-foreign-instances) (:export ;;;; CLSQL meta-model/default attributes definers @@ -61,28 +48,11 @@ :as-table ;;;; "Lines", the newest creation. :defline - :line-in - :line-out - + ;;;; A macro shortcut for creating ucw actions :action - - - ;;;;a wrapper for calling make-presentation - :call-view - :present-view - :slot-view - :present-slot-view - :make-view - ;;;; Ajax - :auto-complete - :call-auto-complete ;;;; Mewa Exports - :mewa ;the superclass of all mewa-presentations - :make-presentation - :call-presentation - :find-occurence ;;attributes @@ -93,32 +63,6 @@ :set-default-attributes :set-attribute :find-attribute - :perform-set-attributes - ;; - :perform-set-attribute-properties - :define-attributes - - ;; presentation objects - :mewa-object-presentation - :mewa-one-line-presentation - :mewa-list-presentation - :mewa-search-presentation - :mewa-presentation-search - - :editablep - :global-properties - ;; SLOT presentations - - :mewa-relation-slot-presentation - :mewa-string-slot-presentation - :has-many-slot-presentation - :has-a - :has-many - :has-very-many - :many-to-many - - ;; CRUD - :instance-is-stored-p ;;;; Meta Model Exports)) :define-meta-model diff --git a/src/presentations.lisp b/src/presentations.lisp deleted file mode 100644 index b463210..0000000 --- a/src/presentations.lisp +++ /dev/null @@ -1,250 +0,0 @@ -(declaim (optimize (speed 0) (space 3) (safety 0))) -(in-package :lisp-on-lines) - - -(defmethod render ((self mewa)) - (lol::present self)) - -(defaction edit-instance ((self mewa)) - (call-presentation (instance self) :type :editor)) - -;;;one-line objects -(defcomponent mewa-one-line-presentation (mewa lol::one-line-presentation) - () - (:default-initargs - :attributes-getter #'one-line-attributes-getter - :global-properties '(:editablep nil))) - -(defmethod one-line-attributes-getter ((self mewa)) - (or (meta-model::find-slots-of-type (instance self)) - (meta-model::list-keys (instance self)))) - -;;;objects -(defcomponent mewa-object-presentation (mewa lol::object-presentation) - ((instance :accessor instance :initarg :instance :initform nil))) - -(defcomponent mewa-viewer (mewa-object-presentation) - () - (:default-initargs - :global-properties '(:editablep nil))) - -(defcomponent mewa-editor (mewa-object-presentation) - () - (:default-initargs - :global-properties '(:editablep t))) - -(defcomponent mewa-creator (mewa-editor) - ()) - -(defmethod present ((pres mewa-object-presentation)) - (<:table :class (css-class pres) - (dolist (slot (slots pres)) - (<:tr :class "presentation-slot-row" - (present-slot-as-row pres slot)))) - (render-options pres (instance pres))) - -(defmethod present-slot-as-row ((pres mewa-object-presentation) (slot slot-presentation)) - (<:td :class "presentation-slot-label" (<:as-html (label slot))) - (<:td :class "presentation-slot-value" (present-slot slot (instance pres)))) - - -(defcomponent two-column-presentation (mewa-object-presentation) ()) - -(defmethod present ((pres two-column-presentation)) - - (<:table :class (css-class pres) - (loop for slot on (slots pres) by #'cddr - do - (<:tr :class "presentation-slot-row" - (<:td :class "presentation-slot-label" - (<:as-html (label (first slot)))) - (<:td :class "presentation-slot-value" - (present-slot (first slot) (instance pres))) - (when (second slot) - (<:td :class "presentation-slot-label" - (<:as-html (label (second slot)))) - (<:td :class "presentation-slot-value" - (present-slot (second slot) (instance pres)))))) - (render-options pres (instance pres)))) - - -;;;lists -(defcomponent mewa-list-presentation (mewa list-presentation) - ((instances :accessor instances :initarg :instances :initform nil) - (instance :accessor instance) - (select-label :accessor select-label :initform "select" :initarg :select-label) - (selectablep :accessor selectablep :initform t :initarg :selectablep) - (deleteablep :accessor deletablep :initarg :deletablep :initform nil) - (viewablep :accessor viewablep :initarg :viewablep :initform nil))) - -(defaction select-from-listing ((listing mewa-list-presentation) object index) - (answer object)) - -(defmethod render-list-row ((listing mewa-list-presentation) object index) - (<:tr :class "item-row" - (<:td :align "center" :valign "top" - (when (editablep listing) - (let ((object object)) - ( (number-input self))) - -(def-search-expr ((self number-equal-to)) - (meta-model:expr-= (number-input self))) - - - -(defcomponent mewa-presentation-search (presentation-search) - ((display-results-p :accessor display-results-p :initarg :display-results-p :initform nil) - (criteria-input :accessor criteria-input :initform "") - (new-criteria :accessor new-criteria :initform nil))) - -(defmethod instance ((self mewa:mewa-presentation-search)) - (instance (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)))) - (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 (instances (list-presentation self)) (valid-instances self)) - (setf (display-results-p self) t)) - - -(defmethod set-search-input-for-criteria ((criteria criteria) (input t)) - (error "No search-input-for-criteria method for ~A : ~A" criteria input)) - -(defmethod set-search-input-for-criteria ((c string-criteria) input) - (setf (search-text c) input)) - -(defmethod set-search-input-for-criteria ((c negated-criteria) i) - nil) - - -(defmethod mewa-add-criteria ((self component) (criteria criteria)) - (set-search-input-for-criteria criteria (criteria-input self)) - (add-criteria self criteria)) - -(defmethod find-default-criteria (c mewa-string-slot-presentation) - 'string-contains) - -(defmethod render-criteria ((res response) (s mewa-presentation-search)) - (setf (criteria-input s) "") - (<:ul - (dolist (c (criteria s)) - (<:li (render-on res c) - (let ((c c)) - (list (function &rest args) - "The function to be called by m-v-bf" - (multiple-value-call #'list (apply function args))) - -(defmacro multiple-value-bindf (vars form &body body) - "Like M-V-B, only it works in actions. form must be a function call" - `(destructuring-bind ,vars - (multiple-value-funcall->list #',(car form) ,@(cdr form)) - ,@body)) - - -;;;; ** Textarea Slot Presentation - -(defslot-presentation text-slot-presentation () - ((rows :initarg :rows :accessor rows :initform 5) - (columns :initarg :columns :accessor columns :initform 40) - (escape-html-p :initarg :escape-html-p :accessor escape-html-p :initform nil) - (convert-newlines-p :initarg :convert-newlines-p :accessor convert-newlines-p :initform nil)) - (:type-name text)) - -(defmethod present-slot ((slot text-slot-presentation) instance) - (flet ((maybe-convert-newline-and-escape-html-then-print () - (let ((string (if (convert-newlines-p slot) - (with-output-to-string (new-string) - (with-input-from-string - (s (presentation-slot-value slot instance)) - (loop for line = (read-line s nil) - while line - do (format new-string "~A~A" line "
")))) - (presentation-slot-value slot instance)))) - (if (escape-html-p slot) - (<:as-html string) - (<:as-is string))))) - - (if (editablep slot) - ( " (foreign-instance slot) " from " instance ) - (let* ((i (foreign-instance slot)) - (pres (mewa::make-presentation - i - :type :one-line - :initargs (list - :global-properties - (list :editablep nil :linkedp nil))))) - (when (and (ucw::parent slot) (slot-boundp slot 'ucw::place)) - (setf (component.place pres) (component.place (ucw::parent slot)))) - (when i ( 0 (current slot)) - ;;what to do here is open to debate - (setf (current slot) (- (len slot)(number-to-display slot) )))) - - -(defmethod present-slot ((slot has-very-many-slot-presentation) instance) - ;;(<:as-html "isance: " instance) - (if (slot-boundp slot 'ucw::place) - (progn - (>")) - (call-next-method) - (<:as-html "total :" (len slot))) - (call-next-method))) - -(defmethod get-foreign-instances :around ((slot has-very-many-slot-presentation) instance) - (let ((f (call-next-method))) - (setf (len slot) (length f)) - (setf (instances slot) f) - (loop for cons on (nthcdr (current slot) f) - for i from 0 upto (number-to-display slot) - collect (car cons)))) - - -;;;; * Has-a -(defslot-presentation has-a-slot-presentation (mewa-relation-slot-presentation) - ((allow-nil-p :accessor allow-nil-p :initarg :allow-nil-p :initform t) - (attributes :accessor attributes :initarg :attributes :initform nil)) - (:type-name has-a)) - -(defmethod find-foreign-slot-value ((slot has-a-slot-presentation) (object t)) - (multiple-value-bind (c s) - (meta-model:explode-foreign-key (instance (ucw::parent slot)) (slot-name slot)) - (slot-value object s))) - -(defmethod get-foreign-instances ((slot mewa-relation-slot-presentation) instance) - (clsql:select (class-name (class-of - (meta-model:explode-foreign-key instance (slot-name slot)))) - :flatp t)) - -(defmethod present-slot ((slot has-a-slot-presentation) instance) -; (<:as-html (lol::presentation-slot-value slot instance)) - (if (editablep slot) - (progn ( slot-value number-input)) - :label "~A is greater than:" - :render-on-prefix "~A > ") - - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;;;; Integers - -(defslot-presentation integer-slot-presentation (number-slot-presentation) - () - (:type-name integer)) - -(defmethod presentation-slot-value ((slot integer-slot-presentation) instance) - (declare (ignore instance)) - (or (call-next-method) "")) - -(defmethod (setf presentation-slot-value) ((value string) (slot integer-slot-presentation) instance) - (unless (string= "" value) - (let ((i (parse-integer value :junk-allowed t))) - (when i - (setf (presentation-slot-value slot instance) i))))) - -(defmethod present-slot ((slot integer-slot-presentation) instance) - (if (editablep slot) - (