From 38a016c7ea89d37ea32cfeb8d1e30033c9e3d614 Mon Sep 17 00:00:00 2001 From: Drew Crampsie Date: Fri, 2 Sep 2005 15:00:14 -0700 Subject: [PATCH] extracted meta-model from LoL into its own archive darcs-hash:20050902220014-5417e-d65ebc454a83df914f4a1e70140b8fee8d7e2cf8.gz --- lisp-on-lines.asd | 35 ++-- src/backend/clsql.lisp | 278 ------------------------------- src/backend/ucw.lisp | 76 --------- src/lisp-on-lines.lisp | 44 ++++- src/meta-model.lisp | 246 --------------------------- src/mewa/mewa.lisp | 30 ++-- src/mewa/presentations.lisp | 84 +++++----- src/mewa/slot-presentations.lisp | 127 +++++--------- src/packages.lisp | 154 +++++------------ 9 files changed, 189 insertions(+), 885 deletions(-) delete mode 100644 src/backend/clsql.lisp delete mode 100644 src/backend/ucw.lisp delete mode 100644 src/meta-model.lisp rewrite src/packages.lisp (68%) diff --git a/lisp-on-lines.asd b/lisp-on-lines.asd index ebcdcfa..e4daa46 100644 --- a/lisp-on-lines.asd +++ b/lisp-on-lines.asd @@ -1,42 +1,33 @@ ;;; -*- lisp -*- (eval-when (:compile-toplevel :load-toplevel :execute) - (unless (find-package :coop.tech.lisp-on-lines.system) - (defpackage :coop.tech.lisp-on-lines.system + (unless (find-package :coop.tech.systems) + (defpackage :coop.tech.systems (:documentation "ASDF System package for meta-model.") (:use :common-lisp :asdf)))) -(in-package :coop.tech.lisp-on-lines.system) +(in-package :coop.tech.systems) -(defsystem :meta-model - :components ( - (:module :src - :components ((:file "packages") - (:file "meta-model" :depends-on ("packages")))) - (:module :backend - :depends-on (:src) - :pathname "src/backend/" - :components ((:file "clsql")))) - :depends-on (:clsql :clsql-pg-introspect)) - -;; this is no longer used -(defsystem :meta-model-clsql - :components () - :depends-on (:meta-model :clsql )) (defsystem :mewa :components ((:module :src :pathname "src/mewa/" :components - ((:file "mewa") - (:file "presentations" :depends-on ("mewa")) - (:file "slot-presentations" :depends-on ("presentations"))))) + ((:file "packages") + (:file "static-presentations") + (:file "mewa") + (:file "presentations" ) + (:file "slot-presentations")) + :serial t)) :depends-on (:ucw :meta-model)) (defsystem :lisp-on-lines :components ((:static-file "lisp-on-lines.asd") (:module :src - :components ((:file "lisp-on-lines"))) + :components ((:file "packages") + (:file "lisp-on-lines")) + :serial t) + (:module :components :pathname "src/components/" :components ((:file "range-list") diff --git a/src/backend/clsql.lisp b/src/backend/clsql.lisp deleted file mode 100644 index 0083efc..0000000 --- a/src/backend/clsql.lisp +++ /dev/null @@ -1,278 +0,0 @@ -(in-package :meta-model) - -(eval-when (:compile-toplevel :load-toplevel :execute) - (use-package :clsql)) - -(export 'def-meta-model-from-table) -(export 'def-meta-models) -(export 'def-view-class/meta) -(export 'list-base-classes) - - -(defmethod sync-instance ((view clsql:standard-db-object) &key (fill-gaps-only-p nil) (database *default-database*)) - (labels ((sym->sql (sym) (string-downcase (substitute #\_ #\- (string sym)))) - (get-def (slot) (caar (query - (format nil "SELECT DISTINCT adsrc from pg_attrdef join pg_attribute on attnum = adnum where adrelid = (select oid from pg_class where relname = '~A') and attname = '~A'" (sym->sql (class-name (class-of view))) (sym->sql slot))))) - (get-default-value (slot) - (let ((def (get-def slot))) - (if def - (caar (query (format nil "SELECT ~A" def))))))) - - (dolist (slot (list-slots view)) - (when (and (primary-key-p view slot) - (or (not (slot-boundp view slot)) - (equal (slot-value view slot) nil))) - (setf (slot-value view slot) (get-default-value slot)) - (when (and (primary-key-p view slot) - (not (slot-value view slot)) - (not fill-gaps-only-p)) - (error "No default value for primary key : ~A" slot)))) - (when fill-gaps-only-p - (update-objects-joins (list view)) - (return-from sync-instance)) - (update-records-from-instance view :database database) - (update-instance-from-records view :database database) - (update-objects-joins (list view))) - - ;; return the modified and hopefully now persistent object - view) - - - -(defparameter *clsql-base-classes* (list) ) - -(defmethod list-base-classes ((type (eql :clsql))) - *clsql-base-classes*) - -(defmethod generate-base-class-definition ((base-type (eql :clsql)) (model meta-model-class) (name t) (args t)) - `(def-view-class ,name () - ,(meta-model.metadata model))) - -(defmethod generate-base-class-definition :after ((base-type (eql :clsql)) (model meta-model-class) (name t) (args t)) - (unless (member name *clsql-base-classes*) - (setf *clsql-base-classes* (cons name *clsql-base-classes*)))) - -(defparameter *sql-type-map* '((:INT4 integer) (:BOOL boolean) (:TEXT string) (:VARCHAR string) (:TIMESTAMP clsql-sys::wall-time) (:NUMERIC number)(:BYTEA string))) - -(defun gen-type (table column) - (cadr (assoc - (cadr (assoc - column - (list-attribute-types table) - :test #'equalp )) - *sql-type-map*))) - -(defun sql->sym (name &optional (package nil)) - (flet ((xform (x) - (string-upcase (substitute #\- #\_ x)))) - (if package - (intern (xform (string name)) package) - (intern (xform (string name)))))) - -(defun table->slots (table pkey &optional (accesor-prefix table) (prefix-all-p nil)) - (mapcar - #'(lambda (col) - (flet ((accessor-name (col) - (let ((name (sql->sym col))) - (if (or prefix-all-p - (and (fboundp name) - (eq (type-of (symbol-function name)) 'function))) - (sql->sym (concatenate 'string - (string accesor-prefix) "-" col)) - name)))) - - `(,(sql->sym col) - :accessor ,(accessor-name col) - :initarg ,(sql->sym col "KEYWORD") - :type ,(gen-type table col) - :db-kind - ,(if (equalp col pkey) - `:key - `:base)))) - (list-attributes table))) - -(defun view-class-definition-list () - (mapcar #'(lambda (x) `(def-meta-model-from-table ,x)) - (list-tables))) - -(defmacro def-meta-models () - (let ((defs (view-class-definition-list))) - `(progn ,@defs))) - - -(defun get-pkeys () - (let ((keys '())) - (dolist (row (get-pkeys-query)) - (setf keys (acons (car row) (list (cadr row)) keys))) - keys)) - -(defun get-pkeys-query() - (query - "SELECT pg_class.relname, pg_attribute.attname, pg_catalog.quote_ident(conname) AS constraint_n - , pg_catalog.pg_get_indexdef(d.objid) AS constraint_definition - , CASE - WHEN contype = 'p' THEN - 'PRIMARY KEY' - ELSE - 'UNIQUE' - END as constraint_type - FROM - pg_class, pg_attribute, - pg_catalog.pg_constraint AS c - JOIN pg_catalog.pg_depend AS d ON (d.refobjid = c.oid) - WHERE contype IN ('p', 'u') - AND deptype = 'i' - and conrelid = pg_class.oid - and pg_attribute.attnum = ANY (c.conkey) - and pg_attribute.attrelid = pg_class.oid")) - -;;here is how this works -;;from the postgres system tables we get -;;list of all the has-a relationships. -;;the inverse of a has-a is an implicit has-many -;;and any relation having more than one foreign key -;;is a join table hosting a many-to-many relationship - -(defun get-fkey-explosions () - (let ((key-table (get-fkey-explosions-query)) - (keys '())) - (dolist (row key-table) - (setf row (mapcar #'(lambda (x) - (sql->sym x)) - row)) - ;;this one does the has-a - (setf keys (acons (car row) (gen-has-a row) - keys)) - ;;the inverse of the previous represents a has-many. - (setf keys - (acons (fourth row) (gen-has-many row) - keys)) - - ;;many-to-many - (dolist (mrow - (remove-if #'(lambda (r) (or (not (equal (car row) (car r))) - (equal (last row) (last r)))) - (mapcar #'(lambda (x) - (mapcar #'sql->sym x)) - key-table))) - (setf keys (acons (fourth row) - (gen-many-to-many mrow (third row) (second row)) - keys)))) - keys )) - - -(defun get-fkey-explosions-query () -;;these query's are a mess, i don't even know how they work :) - (query " -SELECT pg_class.relname, - pg_attribute.attname, - fa.attname , - f.relname -FROM pg_class, - pg_constraint, - pg_attribute, - pg_class as f , - pg_attribute as fa -WHERE pg_class.relname in (select tablename from pg_tables where schemaname = 'public') -AND pg_class.oid = pg_constraint.conrelid -AND pg_attribute.attnum = ANY (pg_constraint.conkey) -AND pg_attribute.attrelid = pg_class.oid -AND f.oid = confrelid -AND fa.attrelid = f.oid -AND fa.attnum = ANY (pg_constraint.confkey)")) - - -;; i chose keyword args here so as to make the code more understandable. -;; it didn't really work. -(defun gen-join-slot (&key name home-key foreign-key join-class (set nil)) - `(,(intern name) - :accessor ,(intern name) - :db-kind :join - :db-info (:join-class ,join-class - :home-key ,home-key - :foreign-key ,foreign-key - :set ,set))) - -(defun gen-has-a (row) - (gen-join-slot - :name - (format nil "~A->~A" (string (car row))(string (second row))) - :home-key (second row) - :foreign-key (third row) - :join-class (fourth row))) - -(defun gen-has-many (row) - (gen-join-slot - :name - (format nil "~A->~A" (string (car row))(string (second row))) - :home-key (third row) - :foreign-key (second row) - :join-class (car row) - :set t)) - -(defun gen-many-to-many (row home-key foreign-key) - (let ((name (sql->sym (string-upcase (format nil "~A<-~A->~A" (string (car row)) (string foreign-key) (string (second row))))))) - (setf row (mapcar #'sql->sym row)) - `(,name - :accessor ,name - :db-kind :join - :db-info (:join-class ,(car row) - :home-key ,home-key - :foreign-key ,foreign-key - :target-slot ,name - :set t)))) - -(defmethod update-records-from-instance :before ((view clsql::standard-db-object) &key database) - (declare (ignorable database)) - (labels ((sym->sql (sym) (string-downcase (substitute #\_ #\- (string sym)))) - (get-def (slot) (caar (query - (format nil "SELECT DISTINCT adsrc from pg_attrdef join pg_attribute on attnum = adnum where adrelid = (select oid from pg_class where relname = '~A') and attname = '~A'" (sym->sql (class-name (class-of view))) (sym->sql slot))))) - (get-default-value (slot) (caar (query (format nil "SELECT ~A" (get-def slot)))))) - - (dolist (slot (list-slots view)) - (when (and (primary-key-p view slot) - (or (not (slot-boundp view slot)) - (equal (slot-value view slot) nil))) - (setf (slot-value view slot) (get-default-value slot)))))) - -;;;; - -(defmacro def-view-class/meta (name supers slots &rest args) - "Create and instrument CLSQL view-class NAME and -appropriate meta-model class its default name is %NAME-meta-model." - - `(progn - (let* ((m (define-meta-model ,name ,supers ,slots ,args))) - (setf (meta-model.base-type m) :clsql) - (eval (generate-base-class-expander m ',name ',args))))) - -(defmacro def-view-class-from-table (table &optional - (name (clsql-pg-introspect::intern-normalize-for-lisp table))) - "takes the name of a table as a string and -creates a clsql view-class" - `(clsql-pg-introspect:gen-view-class ,table - :classname ,name - :generate-joins :all - :definer def-view-class/meta)) - - -(defmethod prepare-slot-name-for-select ((i standard-db-object) slot-name) - (clsql:sql-expression :attribute slot-name)) - -(def-compare-expr standard-db-object expr-= sql-=) -(def-compare-expr standard-db-object expr-< sql-<) -(def-compare-expr standard-db-object expr-> sql->) -(def-compare-expr standard-db-object expr-ends-with sql-uplike :value-format "%~A") -(def-compare-expr standard-db-object expr-starts-with sql-uplike :value-format "~A%") -(def-compare-expr standard-db-object expr-contains sql-uplike :value-format "%~A%") - -(def-logical-expr standard-db-object expr-and #'sql-and) - -(def-logical-expr standard-db-object expr-or #'sql-or) - -(def-logical-expr standard-db-object expr-not #'sql-not) - -(defmethod select-instances ((instance standard-db-object) &rest query) - (unless (keywordp (car query)) - (setf query (cons :where query))) - (apply #'select (class-name (class-of instance)) :flatp t query)) diff --git a/src/backend/ucw.lisp b/src/backend/ucw.lisp deleted file mode 100644 index a7bab90..0000000 --- a/src/backend/ucw.lisp +++ /dev/null @@ -1,76 +0,0 @@ -(in-package :it.bese.ucw) - -(defslot-presentation clsql-wall-time-slot-presentation () - () - (:type-name clsql-sys:wall-time)) - -(defmethod present-slot ((slot clsql-wall-time-slot-presentation) instance) - (<:as-html (presentation-slot-value slot instance))) - -(defslot-presentation mewa-relation-slot-presentation () - ((slot-name :accessor slot-name :initarg :slot-name) - (foreign-instance :accessor foreign-instance) - (editablep :initarg :editablep :accessor editablep :initform :inherit)) - (:type-name relation)) - -(defmethod present-relation (( slot mewa-relation-slot-presentation) instance) - (when (foreign-instance slot) - (when (eql (editablep slot) :inherit) - (setf (editablep slot) (editablep (parent slot)))) - (flet ((render-slot () - ( (instance slot-name value) - (:documentation "Create search expression for appropriate backend.")) - -(defgeneric expr-< (instance slot-name value) - (:documentation "Create search expression for appropriate backend.")) - -(defgeneric expr-ends-with (instance slot-name value) - (:documentation "Create search expression for appropriate backend.")) - -(defgeneric expr-starts-with (instance slot-name value) - (:documentation "Create search expression for appropriate backend.")) - -(defgeneric expr-contains (instance slot-name value) - (:documentation "Create search expression for appropriate backend.")) - -(defgeneric expr-and (instance &rest args) - (:documentation "Create search expression for appropriate backend.")) - -(defgeneric expr-or (instance &rest args) - (:documentation "Create search expression for appropriate backend.")) - -(defgeneric expr-not (instance &rest args) - (:documentation "Create search expression for appropriate backend.")) - -(defgeneric select-instances (instance &rest args) - (:documentation "Select instances in backend dependent way")) - -(defgeneric prepare-slot-name-for-select (instance slot-name) - (:method (i s) s)) - -(defmacro def-compare-expr (instance-type name expr &key value-format) - `(defmethod ,name ((instance ,instance-type) slot-name value) - (declare (ignore instance)) - (,expr (prepare-slot-name-for-select instance slot-name) ,(typecase value-format - (null 'value) - (string `(format nil ,value-format value)) - (t `(,value-format value)))))) - - -(defmacro def-logical-expr (instance-type name expr) - `(defmethod ,name ((instance ,instance-type) &rest args) - (declare (ignore instance)) - (apply ,expr args))) \ No newline at end of file diff --git a/src/mewa/mewa.lisp b/src/mewa/mewa.lisp index b09d594..af4ecbb 100644 --- a/src/mewa/mewa.lisp +++ b/src/mewa/mewa.lisp @@ -4,12 +4,11 @@ ;;; maps meta-model slot-types to slot-presentation (defparameter *slot-type-map* - '(boolean ucw::mewa-boolean - string ucw::mewa-string - number ucw::mewa-currency - integer ucw::mewa-integer - currency ucw::mewa-currency - )) + '(boolean mewa-boolean + string mewa-string + number mewa-currency + integer mewa-integer + currency mewa-currency)) ;;; an alist of model-class-name . attributes ;;; should really be a hash-table. @@ -113,12 +112,12 @@ attributes is an alist keyed on the attribute name." (cons (car s) (gen-pslot (if (meta-model:foreign-key-p model (car s)) - 'ucw::foreign-key + 'foreign-key (cadr s)) (string (car s)) (car s)))) (meta-model:list-slot-types model)) (mapcar #'(lambda (s) - (cons s (append (gen-pslot 'ucw::has-many (string s) s) + (cons s (append (gen-pslot 'has-many (string s) s) `(:presentation (make-presentation ,model @@ -140,7 +139,7 @@ attributes is an alist keyed on the attribute name." (defcomponent mewa () - ((ucw::instance :accessor instance :initarg :instance) + ((instance :accessor instance :initarg :instance) (attributes :initarg :attributes :accessor attributes @@ -238,13 +237,13 @@ attributes is an alist keyed on the attribute name." (let ((class-name (or (gethash (if (consp (second attribute)) (car (second attribute)) - (second attribute)) - ucw::*slot-type-mapping*) - (error "Can't find slot type for ~A" (second attribute))))) + (second attribute)) + *presentation-slot-type-mapping*) + (error "Can't find slot type for ~A in ~A but ~A" attribute *presentation-slot-type-mapping* (gethash 'mewa:has-very-many *presentation-slot-type-mapping*))))) - (cons (first attribute) (apply #'make-instance - class-name - (append (cddr attribute) (list :parent self :size 30)))))) + (cons (first attribute) (apply #'make-instance + class-name + (append (cddr attribute) (list :parent self :size 30)))))) (defmethod find-slot-presentations ((self mewa)) (mapcar #'(lambda (a) (find-slot-presentation-for-attribute self a)) @@ -267,7 +266,6 @@ attributes is an alist keyed on the attribute name." (a (progn (setf (slot-value p 'ucw::instance) object) (initialize-slots p) (assoc type (find-all-attributes p)))) - ;;;; TODO: this can be cleaned up, probably CHANGE-CLASS is better here (i (apply #'make-instance (or (second a) ;; if we didnt find the type, ;; use the symbol as a class. diff --git a/src/mewa/presentations.lisp b/src/mewa/presentations.lisp index 95e4977..ab7c27b 100644 --- a/src/mewa/presentations.lisp +++ b/src/mewa/presentations.lisp @@ -12,8 +12,8 @@ (or (meta-model:list-keys (instance self)))) ;;;objects -(defcomponent mewa-object-presentation (mewa ucw:object-presentation) - ((ucw::instance :accessor instance :initarg :instance :initform nil))) +(defcomponent mewa-object-presentation (mewa object-presentation) + ((instance :accessor instance :initarg :instance :initform nil))) (defmethod present ((pres mewa-object-presentation)) (<:table :class (css-class pres) @@ -22,7 +22,7 @@ (present-slot-as-row pres slot)))) (render-options pres (instance pres))) -(defmethod present-slot-as-row ((pres mewa-object-presentation) (slot ucw::slot-presentation)) +(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)))) @@ -48,12 +48,12 @@ ;;;lists -(defcomponent mewa-list-presentation (mewa ucw:list-presentation) - ((ucw::instances :accessor instances :initarg :instances :initform nil) +(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) - (ucw::deleteablep :accessor deletablep :initarg :deletablep :initform nil) + (deleteablep :accessor deletablep :initarg :deletablep :initform nil) (viewablep :accessor viewablep :initarg :viewablep :initform nil))) (defaction select-from-listing ((listing mewa-list-presentation) object index) @@ -62,17 +62,17 @@ (defmethod render-list-row ((listing mewa-list-presentation) object index) (<:tr :class "item-row" (<:td :align "center" :valign "top" - (when (ucw::editablep listing) + (when (editablep listing) (let ((object object)) ( (ucw::number-input self))) +(def-search-expr ((self number-greater-than)) + (meta-model:expr-> (number-input self))) -(def-search-expr ((self ucw::number-equal-to)) - (meta-model:expr-= (ucw::number-input self))) +(def-search-expr ((self number-equal-to)) + (meta-model:expr-= (number-input self))) -(defcomponent mewa-presentation-search (ucw::presentation-search) +(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 (ucw::search-presentation self))) + (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)))) - (ucw::criteria self)))) + (criteria self)))) (defmethod search-query ((self mewa:mewa-presentation-search)) (search-expr self (instance self))) @@ -159,42 +159,42 @@ (defmethod ok ((self mewa-presentation-search) &optional arg) (declare (ignore arg)) - (setf (ucw::instances (ucw::list-presentation self)) (valid-instances self)) + (setf (instances (list-presentation self)) (valid-instances self)) (setf (display-results-p self) t)) -(defmethod set-search-input-for-criteria ((criteria ucw::criteria) (input 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 ucw::string-criteria) input) - (setf (ucw::search-text c) input)) +(defmethod set-search-input-for-criteria ((c string-criteria) input) + (setf (search-text c) input)) -(defmethod set-search-input-for-criteria ((c ucw::negated-criteria) i) +(defmethod set-search-input-for-criteria ((c negated-criteria) i) nil) -(defmethod mewa-add-criteria ((self component) (criteria ucw::criteria)) +(defmethod mewa-add-criteria ((self component) (criteria criteria)) (set-search-input-for-criteria criteria (criteria-input self)) - (ucw::add-criteria self criteria)) + (add-criteria self criteria)) -(defmethod find-default-criteria (c ucw::mewa-string-slot-presentation) - 'ucw::string-contains) +(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 (ucw::criteria s)) + (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" @@ -12,7 +12,6 @@ ;;;; ** Textarea Slot Presentation -;;;; This should really be in UCW. (defslot-presentation text-slot-presentation () ((rows :initarg :rows :accessor rows :initform nil) @@ -105,32 +104,42 @@ When T, only the default value for primary keys and the joins are updated.") (defslot-presentation mewa-relation-slot-presentation (mewa-slot-presentation slot-presentation) ((foreign-instance :accessor foreign-instance) (linkedp :accessor linkedp :initarg :linkedp :initform t) - (creator :accessor creator :initarg :creator :initform :editor)) + (creator :accessor creator :initarg :creator :initform :editor) + (new-instance :accessor new-instance :initform nil)) (:type-name relation)) (defaction search-records ((slot mewa-relation-slot-presentation) instance) (multiple-value-bindf (finstance foreign-slot-name) (meta-model:explode-foreign-key instance (slot-name slot)) - (let ((new-instance - (call-component - (parent slot) - (make-instance (or (cadr (mewa:find-attribute finstance :presentation-search)) - 'mewa::mewa-presentation-search) - :search-presentation - (mewa:make-presentation finstance - :type :search-presentation) - :list-presentation - (mewa:make-presentation finstance - :type :listing))))) - (setf (slot-value instance (slot-name slot)) (slot-value new-instance foreign-slot-name)) - (meta-model:sync-instance instance :fill-gaps-only-p (fill-gaps-only-p self))))) - + (let ((new-instance (new-instance self))) + (unless new-instance + (setf (new-instance self) + (call-component + (ucw::parent slot) + (make-instance (or (cadr (mewa:find-attribute finstance :presentation-search)) + 'mewa::mewa-presentation-search) + :search-presentation + (mewa:make-presentation finstance + :type :search-presentation) + :list-presentation + (mewa:make-presentation finstance + :type :listing))))) + (sync-foreign-instance slot new-instance)))) + +(defmethod sync-foreign-instance ((slot mewa-relation-slot-presentation) foreign-instance) + (let ((instance (instance (ucw::parent slot)))) + (multiple-value-bind (foo f-slot-name) + (meta-model:explode-foreign-key instance (slot-name slot)) + (setf (slot-value instance (slot-name slot)) (slot-value foreign-instance f-slot-name)) + (meta-model:sync-instance instance :fill-gaps-only-p (fill-gaps-only-p slot))))) + + (defaction create-record-on-foreign-key ((slot mewa-relation-slot-presentation) instance) (multiple-value-bindf (finstance foreign-slot-name) (meta-model:explode-foreign-key instance (slot-name slot)) (let ((new-instance (call-component - (parent slot) + (ucw::parent slot) (mewa:make-presentation finstance :type (creator self))))) ;;;; TODO: this next bit is due to a bad design decision. @@ -172,9 +181,9 @@ When T, only the default value for primary keys and the joins are updated.") (:default-initargs)) (defaction view-instance ((self component) instance &rest initargs) - (call-component (parent self) (apply #'mewa:make-presentation instance initargs)) + (call-component (ucw::parent self) (apply #'mewa:make-presentation instance initargs)) ;; the viewed instance could have been changed/deleted, so we sync this instance - (meta-model:sync-instance (instance (parent self)))) + (meta-model:sync-instance (instance (ucw::parent self)))) (defmethod present-slot :around ((slot foreign-key-slot-presentation) instance) @@ -182,7 +191,7 @@ When T, only the default value for primary keys and the joins are updated.") (when (presentation-slot-value slot instance) (meta-model:explode-foreign-key instance (slot-name slot)))) (flet ((render () (when (foreign-instance slot)(call-next-method)))) - (if (slot-boundp slot 'place) + (if (slot-boundp slot 'ucw::place) (cond ((editablep slot) ( (length (last-name x)) 0) - (strcat (last-name x) ", ") - " ") - (first-name x)" " (company-name x))) - :as-value (lambda (x) x) - :submit-on-click-p nil))) - (:type-name ajax-foreign-key)) - - -(defmethod shared-initialize :after ((slot ajax-foreign-key-slot-presentation) slots &rest args) - ;; If no search-slots than use the any slots of type string - (unless (search-slots slot) - (setf (search-slots slot) t) - (let ((l (live-search slot))) - (setf (lisp-on-lines::values-generator l) t)))) - - -(defmethod present-slot :around ((slot ajax-foreign-key-slot-presentation) instance) - (setf (foreign-instance slot) - (when (presentation-slot-value slot instance) - (meta-model:explode-foreign-key instance (slot-name slot)))) - (flet ((render () (when (foreign-instance slot)(call-next-method)))) - (if (slot-boundp slot 'place) - (cond - ((editablep slot) - - (>")) diff --git a/src/packages.lisp b/src/packages.lisp dissimilarity index 68% index 234d6ec..70401a2 100644 --- a/src/packages.lisp +++ b/src/packages.lisp @@ -1,115 +1,39 @@ -(defpackage :meta-model - (:use :common-lisp :clsql :clsql-pg-introspect) - (:shadow :primary-key-p) - (:export - :meta-model-class - :meta-model.base-type - :meta-model.instance - :meta-model.metadata - :define-meta-model - :def-view-class-from-table - :def-view-class/meta - :view-class-metadata - :create-table-from-model - :list-slots - :list-slot-types - :slot-type - :display-slot - :list-joins - :list-join-attributes - :list-keys - :list-view-classes - :display-slot - :primary-key-p - :list-foreign-keys - :foreign-key-p - :explode-foreign-key - :find-join-class - :find-join-key - :find-default-value - :explode-foreign-key - :list-has-many - :list-many-to-many - :sync-instance - :explode-has-many - :expr-ends-with - :expr-starts-with - :expr-contains - :expr-= - :expr-< - :expr-> - :expr-and - :expr-or - :expr-not - :select-instances)) - - -(defpackage :mewa - (:use :ucw :common-lisp) - (:export - :mewa - :mewa-object-presentation - :mewa-one-line-presentation - :mewa-list-presentation - :mewa-presentation-search - :find-attribute - :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 - :edit-instance - :save-instance - :cancel-save-instance - :ensure-instance-sync - :instance-is-stored-p - :global-properties - :search-expr - :search-query)) - -(defpackage :lisp-on-lines - (:use :mewa :meta-model :common-lisp :it.bese.ucw :js) - (:nicknames :lol) - (:export - ;;;; LoL - :initialize-lol-for-table - :initialize-lol-for-database - - ;;;; Ajax - :auto-complete - :call-auto-complete - - ;;;; Mewa Exports - :mewa ;the superclass of all mewa-presentations - :make-presentation - :call-presentation - ;;attributes - :attributes - :set-default-attributes - :set-attribute - :find-attribute - :perform-set-attributes - ;; - :perform-set-attribute-properties - - ;; presentation objects - :mewa-object-presentation - :mewa-one-line-presentation - :mewa-list-presentation - - ;; CRUD - :instance-is-stored-p - - ;;;; Meta Model Exports)) - :define-meta-model - :def-view-class-from-table - :def-view-class/meta - :list-slot-types - )) \ No newline at end of file +(defpackage :lisp-on-lines + (:use :mewa :meta-model :common-lisp :it.bese.ucw :js :clsql) + (:nicknames :lol) + (:export + ;;;; LoL + :initialize-lol-for-table + :initialize-lol-for-database + + ;;;; Ajax + :auto-complete + :call-auto-complete + + ;;;; Mewa Exports + :mewa ;the superclass of all mewa-presentations + :make-presentation + :call-presentation + ;;attributes + :attributes + :set-default-attributes + :set-attribute + :find-attribute + :perform-set-attributes + ;; + :perform-set-attribute-properties + + ;; presentation objects + :mewa-object-presentation + :mewa-one-line-presentation + :mewa-list-presentation + + ;; CRUD + :instance-is-stored-p + + ;;;; Meta Model Exports)) + :define-meta-model + :def-view-class-from-table + :def-view-class/meta + :list-slot-types + )) \ No newline at end of file -- 2.20.1