added a many-to-many slot type, and fixed the package errors due to cutting the MEWA...
authorDrew Crampsie <drewc@tech.coop>
Thu, 27 Oct 2005 22:28:57 +0000 (15:28 -0700)
committerDrew Crampsie <drewc@tech.coop>
Thu, 27 Oct 2005 22:28:57 +0000 (15:28 -0700)
darcs-hash:20051027222857-5417e-d8dcc95d3586c248297caff17825736a696ea848.gz

src/mewa.lisp
src/mewa/packages.lisp [deleted file]
src/packages.lisp
src/presentations.lisp
src/slot-presentations.lisp
src/static-presentations.lisp

index cf6ea00..c519396 100644 (file)
@@ -1,4 +1,4 @@
-(in-package :mewa)
+(in-package :lisp-on-lines)
  
 (defparameter *default-type* :ucw)
 
  
 (defparameter *default-type* :ucw)
 
@@ -335,8 +335,7 @@ attributes is an alist keyed on the attribute name."
     (setf (slot-value i 'initializedp) t)
     i))
 
     (setf (slot-value i 'initializedp) t)
     i))
 
-(defmethod make-presentation ((list list) &key (type :listing) (initargs nil))
-
+(defmethod make-presentation ((list list) &key (type :listing) (initargs nil))  
   (let ((args (append
               `(:type ,type) 
               `(:initargs 
   (let ((args (append
               `(:type ,type) 
               `(:initargs 
@@ -379,7 +378,7 @@ attributes is an alist keyed on the attribute name."
 
 (defaction cancel-save-instance ((self mewa))
   (cond  
 
 (defaction cancel-save-instance ((self mewa))
   (cond  
-    ((instance-is-stored-p (instance self))
+    ((meta-model::persistentp (instance self))
       (meta-model::update-instance-from-records (instance self))
       (answer self))
     (t (answer nil))))
       (meta-model::update-instance-from-records (instance self))
       (answer self))
     (t (answer nil))))
diff --git a/src/mewa/packages.lisp b/src/mewa/packages.lisp
deleted file mode 100644 (file)
index ebdf210..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-(defpackage :mewa 
-  (:use :ucw :common-lisp :arnesi :iterate)
-  (:export 
-   :mewa 
-   :editablep
-   
-   ;object presentations
-   :present
-   :foreign-key-slot-presentation
-   :mewa-object-presentation 
-   :mewa-one-line-presentation
-   :mewa-list-presentation
-   :mewa-presentation-search
-   
-   ;;Slot Presentations
-   :defslot-presentation
-   :slot-presentation
-   :mewa-slot-presentation
-
-   :present-slot
-   :presentation-slot-value
-   
-
-   :mewa-relation-slot-presentation
-   :has-a-slot-presentation
-   :has-a
-   :has-many-slot-presentation
-   :has-many
-   :has-very-many-slot-presentation
-   :has-very-many
-   :slot-name
-
-   ;attributes
-   :define-attributes
-   :with-default-attributes
-   :find-attribute
-   :find-attribute-slot
-   :set-default-attributes 
-   :make-presentation 
-   :call-presentation 
-   :label
-   :attributes
-   :set-attribute
-   :set-attribute-properties
-   :perform-set-attributes
-   :perform-set-attribute-properties
-   :find-class-attributes 
-   :default-attributes 
-   :ok
-   :instance
-   :edit-instance
-   :save-instance
-   :cancel-save-instance
-   :ensure-instance-sync
-   :instance-is-stored-p
-   :global-properties
-   :search-expr
-   :search-query))
-
index 1db3466..eb31876 100644 (file)
@@ -1,6 +1,14 @@
 (defpackage :lisp-on-lines
 (defpackage :lisp-on-lines
-  (:use :mewa :meta-model :common-lisp :it.bese.ucw :js :clsql)
-  (:nicknames :lol)
+  (:use :arnesi
+       :iterate
+       :meta-model
+       :common-lisp
+       :it.bese.ucw
+       :clsql)
+  (:shadowing-import-from
+   :iterate
+   :with)
+  (:nicknames :lol :mewa)
   (:export 
    ;;;; LoL 
    :define-view-for-table
   (:export 
    ;;;; LoL 
    :define-view-for-table
    :mewa-object-presentation
    :mewa-one-line-presentation
    :mewa-list-presentation
    :mewa-object-presentation
    :mewa-one-line-presentation
    :mewa-list-presentation
-
+   :mewa-search-presentation
+   :mewa-presentation-search
    ;; SLOT presentations
    :defslot-presentation
    :slot-name
    :mewa-relation-slot-presentation
    ;; SLOT presentations
    :defslot-presentation
    :slot-name
    :mewa-relation-slot-presentation
+   :mewa-string-slot-presentation
    :has-many-slot-presentation
    :present-slot
    ;; CRUD
    :has-many-slot-presentation
    :present-slot
    ;; CRUD
index 82f18e3..77510a8 100644 (file)
@@ -1,16 +1,6 @@
-(in-package :mewa)
+(in-package :lisp-on-lines)
 
 
 
 
-
- (defun split-list (n list)  
-  (loop for cons on list
-        by #'(lambda (x) (nthcdr n x))
-        if (< 0 n)
-        collect (loop for atom in cons
-                      repeat n
-                      collect atom)
-        else return nil))
-
 (defaction edit-instance ((self mewa))
   (call-presentation (instance self) :type :editor))
 
 (defaction edit-instance ((self mewa))
   (call-presentation (instance self) :type :editor))
 
 
 (defgeneric search-expr (criteria instance)
   (:documentation "Return ready to apply criteria.
 
 (defgeneric search-expr (criteria instance)
   (:documentation "Return ready to apply criteria.
-                   What to do with it is backend dependent."))
+                   to do with What it is backend dependent."))
 
 (defmacro def-search-expr (((self criteria-type)) (model-expr &body body))
   `(defmethod search-expr ((,self ,criteria-type) instance)
 
 (defmacro def-search-expr (((self criteria-type)) (model-expr &body body))
   `(defmethod search-expr ((,self ,criteria-type) instance)
index 952196f..3757ee3 100644 (file)
@@ -1,4 +1,4 @@
-(in-package :mewa)
+(in-package :lisp-on-lines)
 
 (defun multiple-value-funcall->list (function &rest args)
   "The function to be called by m-v-bf"
 
 (defun multiple-value-funcall->list (function &rest args)
   "The function to be called by m-v-bf"
@@ -194,6 +194,7 @@ Calendar.setup({
     (if (slot-boundp slot 'ucw::place)
         (cond 
           ((editablep slot)
     (if (slot-boundp slot 'ucw::place)
         (cond 
           ((editablep slot)
+          (render)
            (<ucw:submit :action  (search-records slot instance) :value "Search" :style "display:inline")
            (<ucw:submit :action  (create-record-on-foreign-key slot instance) :value "Add New" :style "display:inline"))
           ((linkedp slot)
            (<ucw:submit :action  (search-records slot instance) :value "Search" :style "display:inline")
            (<ucw:submit :action  (create-record-on-foreign-key slot instance) :value "Add New" :style "display:inline"))
           ((linkedp slot)
@@ -205,7 +206,15 @@ Calendar.setup({
         (render))))
 
 
         (render))))
 
 
+(defmethod find-foreign-instances ((slot foreign-key-slot-presentation))
+  (clsql:select (class-name (class-of (meta-model:explode-foreign-key (instance slot) (slot-name slot))))))
 
 
+(defslot-presentation has-a-slot-presentation (foreign-key-slot-presentation)
+  ()
+  (:type-name has-a))
+
+(defmethod present-slot ((slot has-a-slot-presentation) instance)
+  t)
 
 ;;;; HAS MANY 
 (defslot-presentation has-many-slot-presentation (mewa-relation-slot-presentation)
 
 ;;;; HAS MANY 
 (defslot-presentation has-many-slot-presentation (mewa-relation-slot-presentation)
@@ -214,7 +223,7 @@ Calendar.setup({
 
 (defaction add-to-has-many ((slot has-many-slot-presentation) instance)
   ;; if the instance is not stored we must make sure to mark it stored now!
 
 (defaction add-to-has-many ((slot has-many-slot-presentation) instance)
   ;; if the instance is not stored we must make sure to mark it stored now!
-  (unless (mewa::instance-is-stored-p instance)
+  (unless (meta-model::persistentp instance)
     (setf (mewa::modifiedp (ucw::parent self)) t))
   ;; sync up the instance
   ;;(mewa:ensure-instance-sync (parent slot))
     (setf (mewa::modifiedp (ucw::parent self)) t))
   ;; sync up the instance
   ;;(mewa:ensure-instance-sync (parent slot))
@@ -331,7 +340,49 @@ Calendar.setup({
            (present (presentation slot)))
          (<:as-html "--"))))
 
            (present (presentation slot)))
          (<:as-html "--"))))
 
+(defslot-presentation many-to-many-slot-presentation (mewa-relation-slot-presentation)
+  ((list-view :accessor list-view :initarg :list-view :initform :one-line)
+   (action-view :accessor action-view :initarg :action-view :initform :viewer)
+   (create-view :initform :creator))
+  (:type-name many-to-many)
+  (:default-initargs :label "many to many"))
 
 
+(defmethod present-slot ((slot many-to-many-slot-presentation) instance)
+  
+  (let ((instances (slot-value instance (slot-name slot))))
+    (<:ul
+     (<:li (<ucw:a :action (add-on-many-to-many slot instance)
+                  (<:as-html "Add New")))
+     (dolist* (i instances)
+       (<:li
+       (<ucw:a :action (call-view ((car i) (action-view slot) slot))
+               (<:as-html "(view) "))
+       (<ucw:a :action (delete-item (ucw::parent slot) (second i))
+               (<:as-html "(remove) "))
+       (present-view ((car i)  (list-view slot) (ucw::parent slot)))) ))))
+
+(defaction add-on-many-to-many ((slot many-to-many-slot-presentation) instance)
+  (let* (new
+        (imd (getf (meta-model::find-slot-metadata instance (slot-name slot))
+                   :db-info))
+        (jc (make-instance (getf imd :join-class)))
+        (jcmd (getf (meta-model::find-slot-metadata jc (getf imd :target-slot))
+                    :db-info))
+        (fc (make-instance (getf jcmd :join-class)))
+        (c (call-view (fc :creator (ucw::parent slot)))))
+
+    (when c
+      (sync-instance c)
+      (setf (slot-value jc (getf imd :foreign-key))
+           (slot-value instance (getf imd :home-key)))
+      (setf (slot-value jc (getf jcmd :home-key))
+           (slot-value c (getf jcmd :foreign-key)))
+      (sync-instance jc)
+      (sync-instance instance)
+      c)))
+        
+
+       
 
 
 
 
 
 
index 302444b..bdc0b5e 100644 (file)
@@ -1,6 +1,6 @@
 ;;;; -*- lisp -*-
 
 ;;;; -*- lisp -*-
 
-(in-package :mewa)
+(in-package :lisp-on-lines)
 
 (defcomponent presentation ()
   ((css-class :accessor css-class :initarg :css-class :initform nil))
 
 (defcomponent presentation ()
   ((css-class :accessor css-class :initarg :css-class :initform nil))
@@ -422,8 +422,7 @@ This method is also used by relation-slot-presentations for the same reason."))
   (:type-name boolean))
 
 (defmethod present-slot ((slot boolean-slot-presentation) instance)
   (:type-name boolean))
 
 (defmethod present-slot ((slot boolean-slot-presentation) instance)
-  (<ucw:input :type "checkbox" :accessor (presentation-slot-value slot instance))
-  (setf (presentation-slot-value slot instance) nil))
+  (<ucw:input :type "checkbox" :accessor (presentation-slot-value slot instance)))
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;;; strings
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;;; strings