Commit 8dcd42fa authored by Dave Griffiths's avatar Dave Griffiths
Browse files

added dob and updates now insert new values in eavdb

parent e63ac83a
......@@ -143,12 +143,22 @@
ktvlist)
id))
;; update the value given an entity type, a attribute type and it's key (= attriute_id)
;; creates the value if it doesn't already exist, updates it otherwise
(define (update-value db table entity-id ktv)
(db-exec
db (string-append "update " table "_value_" (ktv-type ktv)
" set value=? where entity_id = ? and attribute_id = ?")
(ktv-value ktv) entity-id (ktv-key ktv)))
(msg "update-value")
(if (null? (dbg (select-first
db (string-append
"select * from " table "_value_" (ktv-type ktv) " where entity_id = ? and attribute_id = ?")
entity-id (ktv-key ktv))))
(begin
(msg "could't find " (ktv-key ktv))
(insert-value db table entity-id ktv))
(db-exec
db (string-append "update " table "_value_" (ktv-type ktv)
" set value=? where entity_id = ? and attribute_id = ?")
(ktv-value ktv) entity-id (ktv-key ktv))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; getting data out
......@@ -270,9 +280,16 @@
(cond
((null? entity-type) (msg "entity" entity-id "not found!") '())
(else
;; todo - do we want to create new attributes here???
;; update main entity type
(for-each
(lambda (ktv)
(when (not (equal? (ktv-key ktv) "unique_id"))
(find/add-attribute-type db table entity-type (ktv-key ktv) (ktv-type ktv))))
ktvlist)
(for-each
(lambda (ktv)
(msg "updating" (ktv-key ktv) "with" (ktv-value ktv))
(update-value db table entity-id ktv))
ktvlist)))))
......
......@@ -788,7 +788,7 @@
r))
(define (top-callback type activity-name activity args)
(display "activity-callback ")(display type)(display " ")(display args)(newline)
;;(display "activity-callback ")(display type)(display " ")(display args)(newline)
(if (not activity)
(begin (display "no activity/fragment called ")(display activity-name)(newline))
(let ((ret (cond
......@@ -807,11 +807,8 @@
((eq? type 'on-create)
(update-callbacks! (list ret)))
(else
(msg "updating dialogs")
(update-dialogs! ret)
(msg "updating callbacks" ret)
(update-callbacks-from-update! ret)
(msg "done")))
(update-callbacks-from-update! ret)))
(send (scheme->json ret)))))
(define (find-activity-or-fragment name)
......
......@@ -1344,8 +1344,18 @@
(lambda (v) (entity-add-value! "gender" "varchar" v) '()))
(text-view (make-id "new-individual-dob-text") "Date of Birth" 20 fillwrap)
(horiz
(text-view (make-id "new-individual-dob") "00/00/00" 25 fillwrap)
(button (make-id "date") "Set date" 20 fillwrap (lambda () '())))
(text-view (make-id "new-individual-dob") (date->string (list date-day date-month date-year)) 25 fillwrap)
(button (make-id "date") "Set date" 20 fillwrap
(lambda ()
(list (date-picker-dialog
"new-individual-date"
(lambda (day month year)
(let ((datestring (date->string (list day (+ month 1) year))))
(entity-add-value! "dob" "varchar" datestring)
(list
(update-widget
'text-view
(get-id "new-individual-dob") 'text datestring)))))))))
(text-view (make-id "new-individual-litter-text") "Litter code" 20 fillwrap)
(edit-text (make-id "new-individual-litter-code") "" 30 "text" fillwrap
(lambda (v) (entity-add-value! "litter-code" "varchar" v) '()))
......@@ -1364,6 +1374,12 @@
(lambda (activity arg)
(activity-layout activity))
(lambda (activity arg)
;; make sure all fields exist
(entity-add-value! "name" "varchar" "noname")
(entity-add-value! "gender" "varchar" "Female")
(entity-add-value! "dob" "varchar" "00/00/00")
(entity-add-value! "litter-code" "varchar" "123")
(entity-add-value! "chip-code" "varchar" "123")
(list
(update-widget 'text-view (get-id "new-individual-pack-name") 'text
(string-append "Pack: " (ktv-get (get-current 'pack '()) "name")))))
......@@ -1387,7 +1403,18 @@
(text-view (make-id "update-individual-dob-text") "Date of Birth" 20 fillwrap)
(horiz
(text-view (make-id "update-individual-dob") "00/00/00" 25 fillwrap)
(button (make-id "date") "Set date" 20 fillwrap (lambda () '())))
(button (make-id "date") "Set date" 20 fillwrap
(lambda ()
(list (date-picker-dialog
"update-individual-date"
(lambda (day month year)
(let ((datestring (date->string (list day (+ month 1) year))))
(entity-add-value! "dob" "varchar" datestring)
(list
(update-widget
'text-view
(get-id "update-individual-dob") 'text datestring)))))))))
(text-view (make-id "update-individual-litter-text") "Litter code" 20 fillwrap)
(edit-text (make-id "update-individual-litter-code") "" 30 "text" fillwrap
(lambda (v) (entity-add-value! "litter-code" "varchar" v) '()))
......@@ -1396,15 +1423,15 @@
(lambda (v) (entity-add-value! "chip-code" "varchar" v) '()))
(spacer 10)
(horiz
(button (make-id "update-individual-delete") "Delete" 20 fillwrap (lambda () (list (finish-activity 2))))
(button (make-id "update-individual-died") "Died" 20 fillwrap (lambda () (list (finish-activity 2)))))
(mbutton2 "update-individual-delete" "Delete" (lambda () (list (finish-activity 2))))
(mbutton2 "update-individual-died" "Died" (lambda () (list (finish-activity 2)))))
(horiz
(button (make-id "update-individual-cancel") "Cancel" 20 fillwrap
(lambda () (entity-reset!) (list (finish-activity 2))))
(button (make-id "update-individual-done") "Done" 20 fillwrap
(lambda ()
(entity-update-values db "sync")
(list (finish-activity 2)))))
(mbutton2 "update-individual-cancel" "Cancel"
(lambda () (entity-reset!) (list (finish-activity 2))))
(mbutton2 "update-individual-done" "Done"
(lambda ()
(entity-update-values db "sync")
(list (finish-activity 2)))))
)
(lambda (activity arg)
(activity-layout activity))
......@@ -1414,6 +1441,8 @@
(list
(update-widget 'edit-text (get-id "update-individual-name") 'text
(ktv-get individual "name"))
(update-widget 'text-view (get-id "update-individual-dob") 'text
(ktv-get individual "dob"))
(update-widget 'spinner (get-id "update-individual-gender") 'selection
(if (equal? (ktv-get individual "gender") "Female") 0 1))
(update-widget 'edit-text (get-id "update-individual-litter-code") 'text
......
......@@ -61,16 +61,10 @@ public class starwisp extends StarwispActivity
ActivityManager.RegisterActivity("observations",ObservationsActivity.class);
ActivityManager.RegisterActivity("group-composition",GroupCompositionActivity.class);
ActivityManager.RegisterActivity("pup-focal-start",PupFocalStartActivity.class);
ActivityManager.RegisterActivity("pup-focal",PupFocalActivity.class);
ActivityManager.RegisterActivity("pup-focal-event",PupFocalEventActivity.class);
ActivityManager.RegisterActivity("group-events",GroupEventsActivity.class);
ActivityManager.RegisterActivity("event-fed",EventFedActivity.class);
ActivityManager.RegisterActivity("event-aggression",EventAggressionActivity.class);
ActivityManager.RegisterActivity("manage-packs",ManagePacksActivity.class);
ActivityManager.RegisterActivity("new-pack",NewPackActivity.class);
ActivityManager.RegisterActivity("manage-individual",ManageIndividualActivity.class);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment