starwisp.scm 41.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
;; Starwisp Copyright (C) 2013 Dave Griffiths
;;
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU Affero General Public License as
;; published by the Free Software Foundation, either version 3 of the
;; License, or (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU Affero General Public License for more details.
;;
;; You should have received a copy of the GNU Affero General Public License
;; along with this program.  If not, see <http://www.gnu.org/licenses/>.

16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; strings

(define obs-gc "Group Composition")
(define obs-pf "Pup Focal")

(define (get-fragment-index name frag)
  (define (_ i l)
    (cond
     ((null? l) 0)
     ((equal? name (cadr (car l))) i)
     (else (_ (+ i 1) (cdr l)))))
  (_ 0 frag))

(define gc-fragments
  (list
   (list "Start" "gc-start")
   (list "Weights" "gc-weights")
   (list "Pregnant" "gc-preg")
35
   (list "Pup assoc" "gc-pup-assoc")
36 37 38 39
   (list "Oestrus" "gc-oestrus")
   (list "Babysit" "gc-babysitting")
   (list "End" "gc-end")))

40
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Dave Griffiths's avatar
Dave Griffiths committed
41
;; persistent database
42

Dave Griffiths's avatar
Dave Griffiths committed
43 44
(define db "/sdcard/test.db")
(db-open db)
45 46 47 48 49 50 51 52 53 54
(setup db "local")
(setup db "sync")
(setup db "stream")

(insert-entity-if-not-exists
 db "local" "app-settings" "null" 1
 (list
  (ktv "user-id" "varchar" "No name yet...")))

(display (db-all db "local" "app-settings"))(newline)
Dave Griffiths's avatar
Dave Griffiths committed
55

Dave Griffiths's avatar
Dave Griffiths committed
56 57
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; stuff in memory
Dave Griffiths's avatar
Dave Griffiths committed
58

Dave Griffiths's avatar
Dave Griffiths committed
59 60
(define (store-set store key value)
  (cond
61 62 63 64 65
   ((null? store) (list (list key value)))
   ((eq? key (car (car store)))
    (cons (list key value) (cdr store)))
   (else
    (cons (car store) (store-set (cdr store) key value)))))
Dave Griffiths's avatar
Dave Griffiths committed
66

Dave Griffiths's avatar
Dave Griffiths committed
67
(define (store-get store key default)
Dave Griffiths's avatar
Dave Griffiths committed
68
  (cond
69 70 71 72 73 74 75 76 77 78 79 80 81
   ((null? store) default)
   ((eq? key (car (car store)))
    (cadr (car store)))
   (else
    (store-get (cdr store) key default))))

(define (store-exists? store key)
  (cond
   ((null? store) #f)
   ((eq? key (car (car store)))
    #t)
   (else
    (store-exists? (cdr store) key))))
Dave Griffiths's avatar
Dave Griffiths committed
82 83


Dave Griffiths's avatar
Dave Griffiths committed
84
(define store '())
Dave Griffiths's avatar
Dave Griffiths committed
85

Dave Griffiths's avatar
Dave Griffiths committed
86 87
(define (set-current! key value)
  (set! store (store-set store key value)))
Dave Griffiths's avatar
Dave Griffiths committed
88

Dave Griffiths's avatar
Dave Griffiths committed
89 90
(define (get-current key default)
  (store-get store key default))
Dave Griffiths's avatar
Dave Griffiths committed
91

92 93 94
(define (current-exists? key)
  (store-exists? store key))

Dave Griffiths's avatar
Dave Griffiths committed
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; syncing code

(define url "http://192.168.2.1:8888/mongoose?")

(define (build-url-from-ktv ktv)
  (string-append "&" (ktv-key ktv) ":" (ktv-type ktv) "=" (stringify-value-url ktv)))

(define (build-url-from-ktvlist ktvlist)
  (foldl
   (lambda (ktv r)
     (string-append r (build-url-from-ktv ktv)))
   "" ktvlist))

(define (build-url-from-entity table e)
  (string-append
   url
   "fn=sync"
   "&table=" table
   "&entity-type=" (list-ref (car e) 0)
   "&unique-id=" (list-ref (car e) 1)
Dave Griffiths's avatar
Dave Griffiths committed
116 117
   "&dirty=" (number->string (list-ref (car e) 2))
   "&version=" (number->string (list-ref (car e) 3))
Dave Griffiths's avatar
Dave Griffiths committed
118 119 120 121 122 123 124 125 126 127 128 129
   (build-url-from-ktvlist (cadr e))))

;; spit all dirty entities to server
(define (spit-dirty db table)
  (map
   (lambda (e)
     (http-request
      (string-append "req-" (list-ref (car e) 1))
      (build-url-from-entity table e)
      (lambda (v)
        (display v)(newline)
        (if (equal? (car v) "inserted")
Dave Griffiths's avatar
Dave Griffiths committed
130 131 132 133
            (begin
              (update-entity-clean db table (cadr v))
              (toast "Uploaded " (ktv-get (cadr e) "name")))
            (toast "Problem uploading " (ktv-get (cadr e) "name"))))))
134
   (dirty-entities db table)))
Dave Griffiths's avatar
Dave Griffiths committed
135

136
(define (suck-entity-from-server db table unique-id exists)
Dave Griffiths's avatar
Dave Griffiths committed
137 138 139 140 141 142 143
  ;; ask for the current version
  (http-request
   (string-append unique-id "-update-new")
   (string-append url "fn=entity&table=" table "&unique-id=" unique-id)
   (lambda (data)
     (msg "data from server request" data)
     ;; check "sync-insert" in sync.ss raspberry pi-side for the contents of 'entity'
144 145
     (let ((entity (list-ref data 0))
           (ktvlist (list-ref data 1)))
Dave Griffiths's avatar
Dave Griffiths committed
146
       (if (not exists)
147 148 149 150 151 152 153 154
           (begin
             (insert-entity-wholesale
              db table
              (list-ref entity 0) ;; entity-type
              (list-ref entity 1) ;; unique-id
              0 ;; dirty
              (list-ref entity 2) ;; version
              ktvlist))
Dave Griffiths's avatar
Dave Griffiths committed
155 156
           (update-to-version
            db table (get-entity-id db table unique-id)
Dave Griffiths's avatar
Dave Griffiths committed
157 158 159 160
            (list-ref entity 4) ktvlist))
       (list
        (update-widget 'text-view (get-id "sync-dirty") 'text (build-dirty))
        (toast (string-append "Downloaded " (ktv-get ktvlist "name"))))))))
Dave Griffiths's avatar
Dave Griffiths committed
161

Dave Griffiths's avatar
Dave Griffiths committed
162
;; repeatedly read version and request updates
Dave Griffiths's avatar
Dave Griffiths committed
163
(define (suck-new db table)
Dave Griffiths's avatar
Dave Griffiths committed
164 165 166
  (list
   (http-request
    "new-entities-req"
167
    (string-append url "fn=entity-versions&table=" table)
Dave Griffiths's avatar
Dave Griffiths committed
168
    (lambda (data)
Dave Griffiths's avatar
Dave Griffiths committed
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
      (let ((r (foldl
                (lambda (i r)
                  (let* ((unique-id (car i))
                         (version (cadr i))
                         (exists (entity-exists? db table unique-id))
                         (old
                          (if exists
                              (> version (get-entity-version
                                          db table
                                          (get-entity-id db table unique-id)))
                              #f)))
                    ;; if we don't have this entity or the version on the server is newer
                    (if (or (not exists) old)
                        (cons (suck-entity-from-server db table unique-id exists) r)
                        r)))
                '()
                data)))
        (if (null? r)
            (cons (toast "All files up to date") r)
            (cons (toast "Requesting " (length r) " entities") r)))))))
Dave Griffiths's avatar
Dave Griffiths committed
189

190 191 192 193 194 195 196 197 198
(define (build-dirty)
  (let ((sync (get-dirty-stats db "sync"))
        (stream (get-dirty-stats db "stream")))
    (msg sync stream)
    (string-append
     "Pack data: " (number->string (car sync)) "/" (number->string (cadr sync)) " "
     "Focal data: " (number->string (car stream)) "/" (number->string (cadr stream)))))


Dave Griffiths's avatar
Dave Griffiths committed
199
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
200
;; user interface abstraction
Dave Griffiths's avatar
Dave Griffiths committed
201

Dave Griffiths's avatar
Dave Griffiths committed
202 203 204
(define (mbutton id title fn)
  (button (make-id id) title 20 fillwrap fn))

205
(define (mbutton2 id title fn)
206
  (button (make-id id) title 20 (layout 100 100 1 'centre) fn))
207

208 209 210
(define (mtoggle-button id title fn)
  (toggle-button (make-id id) title 20 fillwrap fn))

211 212 213
(define (mtoggle-button2 id title fn)
  (toggle-button (make-id id) title 20 (layout 100 100 1 'centre) fn))

Dave Griffiths's avatar
Dave Griffiths committed
214 215
(define (mtext id text)
  (text-view (make-id id) text 20 fillwrap))
216

217 218 219
(define (mtitle id text)
  (text-view (make-id id) text 40 fillwrap))

220 221
(define (medit-text id text type fn)
  (vert
222 223
   (mtext (string-append id "-title") text)
   (edit-text (make-id id) "" 20 type fillwrap fn)))
224 225 226 227 228 229 230

(define (mclear-toggles id-list)
  (map
   (lambda (id)
     (update-widget 'toggle-button (get-id id) 'checked 0))
   id-list))

231 232 233 234 235 236 237
(define (mclear-toggles-not-me me id-list)
  (foldl
   (lambda (id r)
     (if (equal? me id)
         r (cons (update-widget 'toggle-button (get-id id) 'checked 0) r)))
   '() id-list))

238 239 240 241 242 243 244 245 246 247
(define (xwise n l)
  (define (_ c l)
    (cond
      ((null? l) (if (null? c) '() (list c)))
      ((eqv? (length c) (- n 1))
       (cons (append c (list (car l))) (_ '() (cdr l))))
      (else
       (_ (append c (list (car l))) (cdr l)))))
  (_ '() l))

248
(define (build-grid-selector name type title)
249
  (vert
250
   (mtext "title" title)
251 252 253 254 255 256 257 258
   (horiz
    (image-view (make-id "im") "arrow_left" (layout 100 'fill-parent 1 'left))
    (scroll-view
     (make-id "scroller")
     (layout 'wrap-content 'wrap-content 1 'left)
     (list
      (linear-layout
       (make-id name) 'horizontal
259 260 261 262
       (layout 'wrap-content 'wrap-content 1 'centre)
       (list
        (button-grid (make-id name) type 3 20 (layout 100 40 1 'left)
                     (list) (lambda (v) '()))))))
263 264
    (image-view (make-id "im") "arrow_right" (layout 100 'fill-parent 1 'right)))))

265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286
(define (fast-get-name item)
  (list-ref (list-ref item 1) 2))

(define (populate-grid-selector name type items fn)
  (let ((id->items
         (map
          (lambda (item)
            (let ((item-name (fast-get-name item)))
              (list (make-id (string-append name item-name))
                           item
                           item-name)))
          items)))
    (update-widget
     'button-grid (get-id name) 'grid-buttons
     (list
      type 3 20 (layout 100 40 1 'left)
      (map
       (lambda (ii)
         (list (car ii) (caddr ii)))
       id->items)
      (lambda (v)
        (fn (cadr (findv v id->items))))))))
287 288 289

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
Dave Griffiths's avatar
Dave Griffiths committed
290

291 292
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; fragments
Dave Griffiths's avatar
Dave Griffiths committed
293 294 295

(define-fragment-list

296 297 298 299 300 301
  (fragment
   "pf-timer"
   (linear-layout
    (make-id "") 'vertical fillwrap
    (list
     (mtitle "title" "Time left: 20 mins")
302
     (mtitle "title" "Next scan: 60 secs")
303
     (mbutton "pft-trigger" "NN scan"
304
              (lambda () (list (replace-fragment (get-id "pf-top") "pf-scan1"))))))
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331
   (lambda (fragment arg)
     (activity-layout fragment))
   (lambda (fragment arg)
     (list))
   (lambda (fragment) '())
   (lambda (fragment) '())
   (lambda (fragment) '())
   (lambda (fragment) '()))


  (fragment
   "pf-events"
   (linear-layout
    (make-id "") 'vertical fillwrap
    (list
     (mtext "text" "Pup Focal Events")
     (horiz
      (mbutton2 "evb-pupfeed" "Pup Feed" (lambda () (list (replace-fragment (get-id "pf-bot") "ev-pupfeed"))))
      (mbutton2 "evb-pupfind" "Pup Find" (lambda () (list (replace-fragment (get-id "pf-bot") "ev-pupfind"))))
      (mbutton2 "evb-pupcare" "Pup Care" (lambda () (list (replace-fragment (get-id "pf-bot") "ev-pupcare"))))
      (mbutton2 "evb-pupagg" "Pup Aggression" (lambda () (list (replace-fragment (get-id "pf-bot") "ev-pupaggr")))))
     (mtext "text" "Group Events")
     (horiz
      (mbutton2 "evb-grpint" "Interaction" (lambda () (list (replace-fragment (get-id "pf-bot") "ev-grpint"))))
      (mbutton2 "evb-grpalarm" "Pup Find" (lambda () (list (replace-fragment (get-id "pf-bot") "ev-grpalarm"))))
      (mbutton2 "evb-grpmov" "Pup Care" (lambda () (list (replace-fragment (get-id "pf-bot") "ev-grpmov")))))
     ))
332 333 334 335 336 337 338 339
   (lambda (fragment arg)
     (activity-layout fragment))
   (lambda (fragment arg)
     (list))
   (lambda (fragment) '())
   (lambda (fragment) '())
   (lambda (fragment) '())
   (lambda (fragment) '()))
340

341 342 343 344 345 346 347 348
  (fragment
   "pf-scan1"
   (linear-layout
    (make-id "") 'vertical fillwrap
    (list
     (build-grid-selector "pf-scan-nearest" "single" "Nearest neighbour scan: Closest Mongoose")
     (build-grid-selector "pf-scan-close" "toggle" "Nearest neighbour scan: Mongooses within 2m")
     (mbutton "pf-scan-done" "Done" (lambda () (list (replace-fragment (get-id "pf-top") "pf-timer"))))))
349 350 351 352

   (lambda (fragment arg)
     (activity-layout fragment))
   (lambda (fragment arg)
353 354 355 356 357 358 359 360 361 362 363 364 365 366
     (list
      (populate-grid-selector
       "pf-scan-nearest" "single"
       (db-all-where db "sync" "mongoose"
                     (list "pack-id" (ktv-get (get-current 'pack '()) "unique_id")))
       (lambda (individual)
         (list)))
      (populate-grid-selector
       "pf-scan-close" "toggle"
       (db-all-where db "sync" "mongoose"
                     (list "pack-id" (ktv-get (get-current 'pack '()) "unique_id")))
       (lambda (individual)
         (list)))
      ))
367 368 369 370 371 372
   (lambda (fragment) '())
   (lambda (fragment) '())
   (lambda (fragment) '())
   (lambda (fragment) '()))


373 374 375 376 377
  (fragment
   "ev-pupfeed"
   (linear-layout
    (make-id "") 'vertical fillwrap
    (list
Dave Griffiths's avatar
Dave Griffiths committed
378
     (mtitle "title" "Pup is fed")
379 380 381 382
     (build-grid-selector "pf-pupfeed-who" "single" "Who fed the pup?")
     (mtext "text" "Food size")
     (horiz
      (spinner (make-id "pf-pupfeed-size") (list "Small" "Medium" "Large") fillwrap (lambda (v) '()))
Dave Griffiths's avatar
Dave Griffiths committed
383
      (mbutton "pf-pupfeed-done" "Done" (lambda () (list (replace-fragment (get-id "pf-bot") "pf-events")))))))
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400

   (lambda (fragment arg)
     (activity-layout fragment))
   (lambda (fragment arg)
     (list
      (populate-grid-selector
       "pf-pupfeed-who" "single"
       (db-all-where db "sync" "mongoose"
                     (list "pack-id" (ktv-get (get-current 'pack '()) "unique_id")))
       (lambda (individual)
         (list)))
      ))
   (lambda (fragment) '())
   (lambda (fragment) '())
   (lambda (fragment) '())
   (lambda (fragment) '()))

Dave Griffiths's avatar
Dave Griffiths committed
401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487
  (fragment
   "ev-pupfind"
   (linear-layout
    (make-id "") 'vertical fillwrap
    (list
     (mtitle "title" "Pup found food")
     (mtext "text" "Food size")
     (horiz
      (spinner (make-id "pf-pupfind-size") (list "Small" "Medium" "Large") fillwrap (lambda (v) '()))
      (mbutton "pf-pupfind-done" "Done" (lambda () (list (replace-fragment (get-id "pf-bot") "pf-events")))))))

   (lambda (fragment arg)
     (activity-layout fragment))
   (lambda (fragment arg)
     (list
      ))
   (lambda (fragment) '())
   (lambda (fragment) '())
   (lambda (fragment) '())
   (lambda (fragment) '()))


  (fragment
   "ev-pupcare"
   (linear-layout
    (make-id "") 'vertical fillwrap
    (list
     (mtitle "title" "Pup is cared for")
     (build-grid-selector "pf-pupcare-who" "single" "Who cared for the pup?")
     (mtext "text" "Type of care")
     (horiz
      (spinner (make-id "pf-pupcare-type") (list "Carry" "Lead" "Sniff" "Play" "Ano-genital sniff") fillwrap (lambda (v) '()))
      (mbutton "pf-scan-done" "Done" (lambda () (list (replace-fragment (get-id "pf-bot") "pf-events")))))))

   (lambda (fragment arg)
     (activity-layout fragment))
   (lambda (fragment arg)
     (list
      (populate-grid-selector
       "pf-pupcare-who" "single"
       (db-all-where db "sync" "mongoose"
                     (list "pack-id" (ktv-get (get-current 'pack '()) "unique_id")))
       (lambda (individual)
         (list)))
      ))
   (lambda (fragment) '())
   (lambda (fragment) '())
   (lambda (fragment) '())
   (lambda (fragment) '()))

  (fragment
   "ev-pupaggr"
   (linear-layout
    (make-id "") 'vertical fillwrap
    (list
     (mtitle "title" "Pup aggression")
     (build-grid-selector "pf-pupaggr-partner" "single" "Aggressive mongoose")

     (linear-layout
      (make-id "") 'horizontal (layout 'fill-parent 100 '1 'left)
      (list
       (vert
        (mtext "" "Fighting over")
        (spinner (make-id "pf-pupaggr-over") (list "Food" "Escort" "Nothing" "Other") fillwrap (lambda (v) '())))
       (vert
        (mtext "" "Level")
        (spinner (make-id "pf-pupaggr-level") (list "Block" "Snap" "Chase" "Push" "Fight") fillwrap (lambda (v) '())))
       (mtoggle-button "pf-pupaggr-in" "Initiate?" (lambda (v) '()))
       (mtoggle-button "pf-pupaggr-win" "Win?" (lambda (v) '()))))
     (mbutton "pf-scan-done" "Done" (lambda () (list (replace-fragment (get-id "pf-bot") "pf-events"))))))

   (lambda (fragment arg)
     (activity-layout fragment))
   (lambda (fragment arg)
     (list
      (populate-grid-selector
       "pf-pupaggr-partner" "single"
       (db-all-where db "sync" "mongoose"
                     (list "pack-id" (ktv-get (get-current 'pack '()) "unique_id")))
       (lambda (individual)
         (list)))
      ))
   (lambda (fragment) '())
   (lambda (fragment) '())
   (lambda (fragment) '())
   (lambda (fragment) '()))

488 489


490

Dave Griffiths's avatar
Dave Griffiths committed
491
  (fragment
492
   "gc-start"
493 494 495 496 497 498 499
   (linear-layout
    (make-id "") 'vertical fillwrap
    (list
     (mtitle "title" "Start")
     (mtoggle-button "gc-start-main-obs" "Main observer" (lambda (v) '()))
     (mtext "" "Code")
     (edit-text (make-id "gc-start-code") "" 20 "numeric" fillwrap (lambda (v) '()))
500
     (build-grid-selector "gc-start-present" "toggle" "Who's present?")))
501 502 503 504 505 506

   (lambda (fragment arg)
     (activity-layout fragment))
   (lambda (fragment arg)
     (list
      (populate-grid-selector
507
       "gc-start-present" "toggle"
508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523
       (db-all-where db "sync" "mongoose"
                     (list "pack-id" (ktv-get (get-current 'pack '()) "unique_id")))
       (lambda (individual)
         (list)))
      ))
   (lambda (fragment) '())
   (lambda (fragment) '())
   (lambda (fragment) '())
   (lambda (fragment) '()))

  (fragment
   "gc-weights"
   (linear-layout
    (make-id "") 'vertical fillwrap
    (list
     (mtitle "title" "Weights")
524
     (build-grid-selector "gc-weigh-choose" "toggle" "Choose mongoose")
525
     (edit-text (make-id "gc-weigh-weight") "" 20 "numeric" fillwrap (lambda (v) '()))
526
     (mtoggle-button "gc-weigh-accurate" "Accurate?" (lambda (v) '()))))
527 528 529 530 531 532

   (lambda (fragment arg)
     (activity-layout fragment))
   (lambda (fragment arg)
     (list
      (populate-grid-selector
533
       "gc-weigh-choose" "toggle"
534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550
       (db-all-where
        db "sync" "mongoose"
        (list "pack-id" (ktv-get (get-current 'pack '()) "unique_id")))
       (lambda (individual)
         (list)))
      ))
   (lambda (fragment) '())
   (lambda (fragment) '())
   (lambda (fragment) '())
   (lambda (fragment) '()))

  (fragment
   "gc-preg"
   (linear-layout
    (make-id "") 'vertical fillwrap
    (list
     (mtitle "title" "Pregnant females")
551
     (build-grid-selector "gc-preg-choose" "toggle" "Choose")))
552 553 554 555 556

   (lambda (fragment arg)
     (activity-layout fragment))
   (lambda (fragment arg)
     (list
557 558
      (populate-grid-selector
       "gc-preg-choose" "toggle"
559 560 561 562 563 564 565 566 567 568 569
       (db-all-where
        db "sync" "mongoose"
        (list "pack-id" (ktv-get (get-current 'pack '()) "unique_id")))
       (lambda (individual)
         (list)))
      ))
   (lambda (fragment) '())
   (lambda (fragment) '())
   (lambda (fragment) '())
   (lambda (fragment) '()))

570

571 572 573 574 575 576
  (fragment
   "gc-pup-assoc"
   (linear-layout
    (make-id "") 'vertical fillwrap
    (list
     (mtitle "title" "Pregnant females")
577 578
     (build-grid-selector "gc-pup-choose" "toggle" "Choose pup")
     (build-grid-selector "gc-pup-escort" "toggle" "Escort")))
579 580 581 582 583

   (lambda (fragment arg)
     (activity-layout fragment))
   (lambda (fragment arg)
     (list
584 585
      (populate-grid-selector
       "gc-pup-choose" "toggle"
586 587 588 589 590
       (db-all-where
        db "sync" "mongoose"
        (list "pack-id" (ktv-get (get-current 'pack '()) "unique_id")))
       (lambda (individual)
         (list)))
591 592
      (populate-grid-selector
       "gc-pup-escort" "toggle"
593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632
       (db-all-where
        db "sync" "mongoose"
        (list "pack-id" (ktv-get (get-current 'pack '()) "unique_id")))
       (lambda (individual)
         (list)))
      ))
   (lambda (fragment) '())
   (lambda (fragment) '())
   (lambda (fragment) '())
   (lambda (fragment) '()))

  (fragment
   "gc-oestrus"
   (linear-layout
    (make-id "") 'vertical fillwrap
    (list
     (mtext "" "Oestrus...")))
   (lambda (fragment arg)
     (activity-layout fragment))
   (lambda (fragment arg)
     (list))
   (lambda (fragment) '())
   (lambda (fragment) '())
   (lambda (fragment) '())
   (lambda (fragment) '()))

  (fragment
   "gc-babysitting"
   (linear-layout
    (make-id "") 'vertical fillwrap
    (list
     (mtext "" "Babysittings...")))
   (lambda (fragment arg)
     (activity-layout fragment))
   (lambda (fragment arg)
     (list))
   (lambda (fragment) '())
   (lambda (fragment) '())
   (lambda (fragment) '())
   (lambda (fragment) '()))
633

634 635 636 637 638 639
  (fragment
   "gc-end"
   (linear-layout
    (make-id "") 'vertical fillwrap
    (list
     (mtext "" "end!...")))
Dave Griffiths's avatar
Dave Griffiths committed
640 641
   (lambda (fragment arg)
     (activity-layout fragment))
642 643
   (lambda (fragment arg)
     (list))
Dave Griffiths's avatar
Dave Griffiths committed
644 645 646 647 648
   (lambda (fragment) '())
   (lambda (fragment) '())
   (lambda (fragment) '())
   (lambda (fragment) '()))

649 650


Dave Griffiths's avatar
Dave Griffiths committed
651 652
  )

653 654 655 656
(msg "one")

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; activities
Dave Griffiths's avatar
Dave Griffiths committed
657

658 659 660 661 662
(define-activity-list
  (activity
   "splash"
   (vert
    (text-view (make-id "splash-title") "Mongoose 2000" 40 fillwrap)
Dave Griffiths's avatar
Dave Griffiths committed
663
    (mtext "splash-about" "Advanced mongoose technology")
664
    (spacer 20)
665
    (mbutton "f2" "Get started!" (lambda () (list (start-activity-goto "main" 2 ""))))
666
    (button-grid (make-id "bg") "toggle" 3 20 (layout 100 40 1 'left)
667 668
                 (list) (lambda (v) (msg v) '()))
    )
Dave Griffiths's avatar
Dave Griffiths committed
669

670 671
   (lambda (activity arg)
     (activity-layout activity))
672 673 674 675 676
   (lambda (activity arg)
     (list
      (update-widget
       'button-grid (get-id "bg") 'grid-buttons
       (list
677
        "toggle" 3 20 (layout 100 40 1 'left)
678 679 680 681 682 683 684 685 686 687 688 689 690 691
        (list
         (list (make-id "1") "one")
         (list (make-id "2") "two")
         (list (make-id "3") "three")
         (list (make-id "4") "four")
         (list (make-id "5") "five")
         (list (make-id "6") "six")
         (list (make-id "7") "seven")
         (list (make-id "8") "eight")
         (list (make-id "9") "nine")
         (list (make-id "10") "ten")
         )
        (lambda (v) (msg "updated" v) '())))
     ))
692 693 694 695 696 697
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity requestcode resultcode) '()))

Dave Griffiths's avatar
Dave Griffiths committed
698

699 700 701
  (activity
   "main"
   (vert
Dave Griffiths's avatar
Dave Griffiths committed
702 703
    (text-view (make-id "main-title") "Mongoose 2000" 40 fillwrap)
    (text-view (make-id "main-about") "Advanced mongoose technology" 20 fillwrap)
704
    (spacer 10)
705 706 707 708
    (horiz
     (mbutton2 "main-observations" "Observations" (lambda () (list (start-activity "observations" 2 ""))))
     (mbutton2 "main-manage" "Manage Packs" (lambda () (list (start-activity "manage-packs" 2 ""))))
     (mbutton2 "main-tag" "Tag Location" (lambda () (list (start-activity "tag-location" 2 "")))))
709
    (mtext "foo" "Your ID")
Dave Griffiths's avatar
Dave Griffiths committed
710
    (edit-text (make-id "main-id-text") "" 30 "text" fillwrap
711 712 713 714
               (lambda (v)
                 (set-current! 'user-id v)
                 (update-entity
                  db "local" 1 (list (ktv "user-id" "varchar" v)))))
Dave Griffiths's avatar
Dave Griffiths committed
715 716
    (mtext "foo" "Database")
    (horiz
717 718
     (mbutton2 "main-send" "Email" (lambda () (list)))
     (mbutton2 "main-sync" "Sync" (lambda () (list (start-activity "sync" 0 ""))))))
Dave Griffiths's avatar
Dave Griffiths committed
719 720
   (lambda (activity arg)
     (activity-layout activity))
721 722 723 724 725
   (lambda (activity arg)
     (let ((user-id (ktv-get (get-entity db "local" 1) "user-id")))
       (set-current! 'user-id user-id)
       (list
        (update-widget 'edit-text (get-id "main-id-text") 'text user-id))))
Dave Griffiths's avatar
Dave Griffiths committed
726 727 728 729 730 731 732
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity requestcode resultcode) '()))

  (activity
733
   "observations"
Dave Griffiths's avatar
Dave Griffiths committed
734
   (vert
735 736 737
    (text-view (make-id "title") "Start Observation" 40 fillwrap)
    (vert
     (mtext "type" "Choose observation type")
738 739 740 741 742 743 744 745 746
     (horiz
      (mtoggle-button2 "choose-obs-gc" obs-gc
                       (lambda (v)
                         (set-current! 'observation obs-gc)
                         (mclear-toggles (list "choose-obs-pf"))))
      (mtoggle-button2 "choose-obs-pf" obs-pf
                       (lambda (v)
                         (set-current! 'observation obs-pf)
                         (mclear-toggles (list "choose-obs-gc"))))))
747
    (build-grid-selector "choose-obs-pack-selector" "single" "Choose pack")
748 749 750
    (mbutton
     "choose-obs-start" "Start"
     (lambda ()
751 752 753 754 755 756 757
       ;; set up the observation fragments
       (let ((obs (get-current 'observation "none")))
         (when (not (equal? obs "none"))
           (set-current!
            'observation-fragments
            (cond
             ((equal? obs obs-gc) gc-fragments)
758
             ((equal? obs obs-pf) '())))))
759 760

       ;; go to observation
761 762
       (if (and (current-exists? 'pack)
                (current-exists? 'observation))
763 764 765
           (if (eq? (get-current 'observation "none") obs-pf)
               (list (start-activity "individual-select" 2 ""))
               (list (start-activity "observation" 2 "")))
766 767 768 769 770
           (list
            (alert-dialog
             "choose-obs-finish"
             "Need to specify a pack and an observation"
             (lambda () '()))))))
Dave Griffiths's avatar
Dave Griffiths committed
771 772 773
    )
   (lambda (activity arg)
     (activity-layout activity))
774 775
   (lambda (activity arg)
     (list
776 777 778
      (populate-grid-selector
       "choose-obs-pack-selector" "single"
       (db-all db "sync" "pack")
779
       (lambda (pack)
780 781 782
         (msg "in selector" pack)
         (set-current! 'pack pack)
         '()))))
Dave Griffiths's avatar
Dave Griffiths committed
783 784 785 786 787 788
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity requestcode resultcode) '()))

789 790


Dave Griffiths's avatar
Dave Griffiths committed
791
  (activity
792
   "observation"
Dave Griffiths's avatar
Dave Griffiths committed
793
   (vert
794
    (text-view (make-id "obs-title") "" 40 fillwrap)
795 796 797 798 799
    (linear-layout
     (make-id "obs-buttons-bar") 'horizontal fillwrap '())
    (view-pager
     (make-id "obs-container") (layout 'wrap-content 700 1 'left) '())
    (mbutton "obs-done" "Done" (lambda () '())))
Dave Griffiths's avatar
Dave Griffiths committed
800 801 802

   (lambda (activity arg)
     (activity-layout activity))
803 804
   (lambda (activity arg)
     (list
805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824
      (update-widget 'linear-layout (get-id "obs-buttons-bar") 'contents
                     (let ((all-toggles
                            (map
                             (lambda (i) (string-append "obs-bar-" (cadr i)))
                             (get-current 'observation-fragments '()))))
                       (map
                        (lambda (frag)
                          (let ((id (string-append "obs-bar-" (cadr frag))))
                            (toggle-button
                             (make-id id) (car frag) 12 fillwrap
                             (lambda (v)
                               (append
                                (mclear-toggles-not-me id all-toggles)
                                (list
                                 (update-widget
                                  'view-pager (get-id "obs-container") 'switch
                                  (get-fragment-index
                                   (cadr frag)
                                   (get-current 'observation-fragments '())))))))))
                        (get-current 'observation-fragments '()))))
825 826 827 828
      (update-widget 'text-view (get-id "obs-title") 'text
                     (string-append
                      (get-current 'observation "No observation")
                      " with " (ktv-get (get-current 'pack '()) "name")))
829 830 831 832 833
      (update-widget 'view-pager (get-id "obs-container") 'contents
                     (map
                      (lambda (frag)
                        (cadr frag))
                      (get-current 'observation-fragments '())))
834
      ))
Dave Griffiths's avatar
Dave Griffiths committed
835 836 837 838 839 840 841
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity requestcode resultcode) '()))

  (activity
842
   "individual-select" ;; pup focal #1
Dave Griffiths's avatar
Dave Griffiths committed
843
   (vert
844 845 846 847 848 849 850 851 852 853
    (mtitle "" "Pup focal setup")
    (mtext "pf1-pack" "Pack")
    (build-grid-selector "pf1-grid" "single" "Select pup")
    (horiz
     (medit-text "pf1-width" "Pack width" 20 "numeric" (lambda (v) '()))
     (medit-text "pf1-height" "Pack height" 20 "numeric" (lambda (v) '())))
    (medit-text "pf1-count" "How many mongooses present?" 20 "numeric" (lambda (v) '()))
    (mbutton "pf1-done" "Done"
             (lambda ()
               (list (start-activity "pup-focal" 2 ""))))
Dave Griffiths's avatar
Dave Griffiths committed
854
    )
855

Dave Griffiths's avatar
Dave Griffiths committed
856 857
   (lambda (activity arg)
     (activity-layout activity))
858 859
   (lambda (activity arg)
     (list
860 861 862 863 864
      (populate-grid-selector
       "pf1-grid" "single"
       (db-all-where db "sync" "mongoose" (list "pack-id" (ktv-get (get-current 'pack '()) "unique_id")))
       (lambda (individual)
         '()))))
Dave Griffiths's avatar
Dave Griffiths committed
865 866 867 868 869 870 871
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity requestcode resultcode) '()))

  (activity
872
   "pup-focal" ;; pup focal #2
Dave Griffiths's avatar
Dave Griffiths committed
873
   (vert
874 875 876 877
    (horiz
     (mtitle "title" "Pup Focal")
     (mtext "pf-details" "")
     (mtoggle-button "pf-pause" "Pause" (lambda (v) '())))
878
    (build-fragment "pf-timer" (make-id "pf-top") (layout 580 400 1 'left))
879
    (mtitle "title" "Events")
880
    (build-fragment "pf-events" (make-id "pf-bot") (layout 580 400 1 'left))
881 882
    (mbutton "pf-done" "Done" (lambda () (list (start-activity-goto "observations" 2 "")))))

Dave Griffiths's avatar
Dave Griffiths committed
883 884
   (lambda (activity arg)
     (activity-layout activity))
885 886 887 888 889 890 891
   (lambda (activity arg)
     (list
      (update-widget 'text-view (get-id "pf-details") 'text
                     (string-append
                      "Pack: " (ktv-get (get-current 'pack '()) "name") " "
                      "Pup: " (ktv-get (get-current 'individual '()) "name")))
      ))
Dave Griffiths's avatar
Dave Griffiths committed
892 893 894 895 896 897
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity requestcode resultcode) '()))

898

Dave Griffiths's avatar
Dave Griffiths committed
899 900 901
  (activity
   "event-self"
   (vert
Dave Griffiths's avatar
Dave Griffiths committed
902
    (text-view (make-id "main-title") "Self feeding event" 40 fillwrap)
Dave Griffiths's avatar
Dave Griffiths committed
903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930
    (spacer 10)
    (toggle-button (make-id "event-self-found") "Found item?" 20 fillwrap
                   (lambda (v) '()))
    (toggle-button (make-id "event-self-kept") "Kept item?" 20 fillwrap
                   (lambda (v) '()))

    (text-view (make-id "event-self-type-text") "Food type" 20 fillwrap)
    (spinner (make-id "event-self-type") (list "Beetle" "Millipede") fillwrap (lambda (v) '()))

    (text-view (make-id "event-self-type-text") "Food size" 20 fillwrap)
    (spinner (make-id "event-self-type") (list "Small" "Medium" "Large") fillwrap (lambda (v) '()))
    (spacer 10)
    (horiz
     (button (make-id "event-self-cancel") "Cancel" 20 fillwrap (lambda () (list (finish-activity 0))))
     (button (make-id "event-self-done") "Done" 20 fillwrap (lambda () (list (finish-activity 0)))))
    )
   (lambda (activity arg)
     (activity-layout activity))
   (lambda (activity arg) (list))
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity requestcode resultcode) '()))

  (activity
   "event-fed"
   (vert
Dave Griffiths's avatar
Dave Griffiths committed
931
    (text-view (make-id "main-title") "Being fed event" 40 fillwrap)
Dave Griffiths's avatar
Dave Griffiths committed
932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962
    (spacer 10)
    (text-view (make-id "event-fed-who-text") "Who by" 20 fillwrap)
    (spinner (make-id "event-fed-who") (list "Mongoose 1" "Mongoose 2" "Mongoose 3") fillwrap (lambda (v) '()))
    (toggle-button (make-id "event-fed-closest") "Closest to feeder?" 20 fillwrap
                   (lambda (v) '()))

    (text-view (make-id "event-self-type-text") "Who moved?" 20 fillwrap)
    (spinner (make-id "event-self-type") (list "Pup" "Feeder") fillwrap (lambda (v) '()))

    (text-view (make-id "event-fed-type-text") "Food type" 20 fillwrap)
    (spinner (make-id "event-fed-type") (list "Beetle" "Millipede") fillwrap (lambda (v) '()))

    (text-view (make-id "event-fed-type-text") "Food size" 20 fillwrap)
    (spinner (make-id "event-fed-type") (list "Small" "Medium" "Large") fillwrap (lambda (v) '()))
    (spacer 10)
    (horiz
     (button (make-id "event-fed-cancel") "Cancel" 20 fillwrap (lambda () (list (finish-activity 0))))
     (button (make-id "event-fed-done") "Done" 20 fillwrap (lambda () (list (finish-activity 0)))))
    )
   (lambda (activity arg)
     (activity-layout activity))
   (lambda (activity arg) (list))
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity requestcode resultcode) '()))

  (activity
   "event-aggression"
   (vert
Dave Griffiths's avatar
Dave Griffiths committed
963
    (text-view (make-id "main-title") "Aggression event" 40 fillwrap)
Dave Griffiths's avatar
Dave Griffiths committed
964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989
    (spacer 10)
    (text-view (make-id "event-agg-who-text") "Other individual" 20 fillwrap)
    (spinner (make-id "event-agg-who") (list "Mongoose 1" "Mongoose 2" "Mongoose 3") fillwrap (lambda (v) '()))
    (text-view (make-id "event-agg-severity-text") "Severity" 20 fillwrap)
    (seek-bar (make-id "event-agg-severity") 100 fillwrap (lambda (v) '()))
    (spacer 10)
    (horiz
     (button (make-id "event-agg-cancel") "Cancel" 20 fillwrap (lambda () (list (finish-activity 0))))
     (button (make-id "event-agg-done") "Done" 20 fillwrap (lambda () (list (finish-activity 0)))))
    )
   (lambda (activity arg)
     (activity-layout activity))
   (lambda (activity arg) (list))
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity requestcode resultcode) '()))


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

  (activity
   "manage-packs"
   (vert
    (text-view (make-id "title") "Manage packs" 40 fillwrap)
990
    (build-grid-selector "manage-packs-list" "button" "Choose pack")
Dave Griffiths's avatar
Dave Griffiths committed
991
    (button (make-id "manage-packs-new") "New pack" 20 fillwrap (lambda () (list (start-activity "new-pack" 2 ""))))
Dave Griffiths's avatar
Dave Griffiths committed
992 993 994
    )
   (lambda (activity arg)
     (activity-layout activity))
Dave Griffiths's avatar
Dave Griffiths committed
995 996
   (lambda (activity arg)
     (list
997
      (populate-grid-selector
998
       "manage-packs-list" "button" (db-all db "sync" "pack")
999 1000 1001
       (lambda (pack)
         (set-current! 'pack pack)
         (list (start-activity "manage-individual" 2 ""))))
Dave Griffiths's avatar
Dave Griffiths committed
1002
      ))
Dave Griffiths's avatar
Dave Griffiths committed
1003 1004 1005 1006
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
1007
   (lambda (activity requestcode resultcode) '()))
Dave Griffiths's avatar
Dave Griffiths committed
1008 1009 1010 1011 1012 1013

  (activity
   "new-pack"
   (vert
    (text-view (make-id "title") "New pack" 40 fillwrap)
    (spacer 10)
Dave Griffiths's avatar
Dave Griffiths committed
1014
    (text-view (make-id "new-pack-name-text") "Pack name" 20 fillwrap)
Dave Griffiths's avatar
Dave Griffiths committed
1015
    (edit-text (make-id "new-pack-name") "" 30 "text" fillwrap
1016
               (lambda (v) (set-current! 'pack-name v) '()))
Dave Griffiths's avatar
Dave Griffiths committed
1017
    (spacer 10)
Dave Griffiths's avatar
Dave Griffiths committed
1018 1019 1020 1021 1022
    (horiz
     (button (make-id "new-pack-cancel") "Cancel" 20 fillwrap (lambda () (list (finish-activity 2))))
     (button (make-id "new-pack-done") "Done" 20 fillwrap
             (lambda ()
               (insert-entity
Dave Griffiths's avatar
Dave Griffiths committed
1023
                db "sync" "pack" (get-current 'user-id "no id")
1024
                (list
Dave Griffiths's avatar
Dave Griffiths committed
1025
                 (ktv "name" "varchar" (get-current 'pack-name "no name"))))
Dave Griffiths's avatar
Dave Griffiths committed
1026
               (list (finish-activity 2)))))
Dave Griffiths's avatar
Dave Griffiths committed
1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037
    )
   (lambda (activity arg)
     (activity-layout activity))
   (lambda (activity arg) (list))
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity requestcode resultcode) '()))

  (activity
Dave Griffiths's avatar
Dave Griffiths committed
1038
   "manage-individual"
Dave Griffiths's avatar
Dave Griffiths committed
1039 1040
   (vert
    (text-view (make-id "title") "Manage individuals" 40 fillwrap)
Dave Griffiths's avatar
Dave Griffiths committed
1041
    (text-view (make-id "manage-individual-pack-name") "Pack:" 20 fillwrap)
1042
    (build-grid-selector "manage-individuals-list" "button" "Choose individual")
Dave Griffiths's avatar
Dave Griffiths committed
1043
    (button (make-id "manage-individuals-new") "New individual" 20 fillwrap (lambda () (list (start-activity "new-individual" 2 ""))))
Dave Griffiths's avatar
Dave Griffiths committed
1044 1045 1046
    )
   (lambda (activity arg)
     (activity-layout activity))
Dave Griffiths's avatar
Dave Griffiths committed
1047 1048
   (lambda (activity arg)
     (list
1049
      (populate-grid-selector
1050
       "manage-individuals-list" "button"
1051 1052 1053
       (db-all-where db "sync" "mongoose" (list "pack-id" (ktv-get (get-current 'pack '()) "unique_id")))
       (lambda (individual)
         (list (start-activity "manage-individual" 2 ""))))
Dave Griffiths's avatar
Dave Griffiths committed
1054
      (update-widget 'text-view (get-id "manage-individual-pack-name") 'text
Dave Griffiths's avatar
Dave Griffiths committed
1055
                     (string-append "Pack: " (ktv-get (get-current 'pack '()) "name")))
Dave Griffiths's avatar
Dave Griffiths committed
1056
      ))
Dave Griffiths's avatar
Dave Griffiths committed
1057 1058 1059 1060
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
1061
   (lambda (activity requestcode resultcode) '()))
Dave Griffiths's avatar
Dave Griffiths committed
1062 1063 1064 1065 1066

  (activity
   "new-individual"
   (vert
    (text-view (make-id "title") "New Mongoose" 40 fillwrap)
Dave Griffiths's avatar
Dave Griffiths committed
1067
    (text-view (make-id "new-individual-pack-name") "Pack:" 20 fillwrap)
Dave Griffiths's avatar
Dave Griffiths committed
1068
    (text-view (make-id "new-individual-name-text") "Name" 20 fillwrap)
Dave Griffiths's avatar
Dave Griffiths committed
1069
    (edit-text (make-id "new-individual-name") "" 30 "text" fillwrap
Dave Griffiths's avatar
Dave Griffiths committed
1070
               (lambda (v) (set-current! 'individual-name v) '()))
Dave Griffiths's avatar
Dave Griffiths committed
1071
    (text-view (make-id "new-individual-name-text") "Gender" 20 fillwrap)
Dave Griffiths's avatar
Dave Griffiths committed
1072 1073
    (spinner (make-id "new-individual-gender") (list "Female" "Male") fillwrap
             (lambda (v) (set-current! 'individual-gender v) '()))
Dave Griffiths's avatar
Dave Griffiths committed
1074
    (text-view (make-id "new-individual-dob-text") "Date of Birth" 20 fillwrap)
Dave Griffiths's avatar
Dave Griffiths committed
1075 1076 1077
    (horiz
     (text-view (make-id "new-individual-dob") "00/00/00" 25 fillwrap)
     (button (make-id "date") "Set date" 20 fillwrap (lambda () '())))
Dave Griffiths's avatar
Dave Griffiths committed
1078
    (text-view (make-id "new-individual-litter-text") "Litter code" 20 fillwrap)
Dave Griffiths's avatar
Dave Griffiths committed
1079
    (edit-text (make-id "new-individual-litter-code") "" 30 "text" fillwrap
Dave Griffiths's avatar
Dave Griffiths committed
1080
               (lambda (v) (set-current! 'individual-litter-code v) '()))
Dave Griffiths's avatar
Dave Griffiths committed
1081
    (text-view (make-id "new-individual-chip-text") "Chip code" 20 fillwrap)
Dave Griffiths's avatar
Dave Griffiths committed
1082
    (edit-text (make-id "new-individual-chip-code") "" 30 "text" fillwrap
Dave Griffiths's avatar
Dave Griffiths committed
1083 1084 1085 1086 1087 1088
               (lambda (v) (set-current! 'individual-chip-code v) '()))
    (horiz
     (button (make-id "new-individual-cancel") "Cancel" 20 fillwrap (lambda () (list (finish-activity 2))))
     (button (make-id "new-individual-done") "Done" 20 fillwrap
             (lambda ()
               (insert-entity
Dave Griffiths's avatar
Dave Griffiths committed
1089
                db "sync" "mongoose" (get-current 'user-id "no id")
1090
                (list
Dave Griffiths's avatar
Dave Griffiths committed
1091 1092 1093 1094 1095
                 (ktv "name" "varchar" (get-current 'individual-name "no name"))
                 (ktv "gender" "varchar" (get-current 'individual-gender "Female"))
                 (ktv "litter-code" "varchar" (get-current 'individual-litter-code ""))
                 (ktv "chip-code" "varchar" (get-current 'individual-chip-code ""))
                 (ktv "pack-id" "varchar" (ktv-get (get-current 'pack '()) "unique_id"))
1096
                 ))
Dave Griffiths's avatar
Dave Griffiths committed
1097
               (list (finish-activity 2)))))
1098 1099 1100
    )
   (lambda (activity arg)
     (activity-layout activity))
Dave Griffiths's avatar
Dave Griffiths committed
1101 1102 1103
   (lambda (activity arg)
     (list
      (update-widget 'text-view (get-id "new-individual-pack-name") 'text
Dave Griffiths's avatar
Dave Griffiths committed
1104
                     (string-append "Pack: " (ktv-get (get-current 'pack '()) "name")))))
1105 1106 1107 1108
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
Dave Griffiths's avatar
Dave Griffiths committed
1109 1110 1111 1112 1113 1114 1115
   (lambda (activity requestcode resultcode) '()))

  (activity
   "update-individual"
   (vert
    (text-view (make-id "title") "Update Mongoose" 40 fillwrap)
    (spacer 10)
Dave Griffiths's avatar
Dave Griffiths committed
1116
    (text-view (make-id "update-individual-name-text") "Name" 20 fillwrap)
Dave Griffiths's avatar
Dave Griffiths committed
1117
    (edit-text (make-id "update-individual-name") "" 30 "text" fillwrap (lambda (v) '()))
Dave Griffiths's avatar
Dave Griffiths committed
1118
    (text-view (make-id "update-individual-name-text") "Gender" 20 fillwrap)
Dave Griffiths's avatar
Dave Griffiths committed
1119
    (spinner (make-id "update-individual-gender") (list "Female" "Male") fillwrap (lambda (v) '()))
Dave Griffiths's avatar
Dave Griffiths committed
1120
    (text-view (make-id "update-individual-dob-text") "Date of Birth" 20 fillwrap)
Dave Griffiths's avatar
Dave Griffiths committed
1121 1122 1123
    (horiz
     (text-view (make-id "update-individual-dob") "00/00/00" 25 fillwrap)
     (button (make-id "date") "Set date" 20 fillwrap (lambda () '())))
Dave Griffiths's avatar
Dave Griffiths committed
1124
    (text-view (make-id "update-individual-litter-text") "Litter code" 20 fillwrap)
Dave Griffiths's avatar
Dave Griffiths committed
1125
    (edit-text (make-id "update-individual-litter-code") "" 30 "text" fillwrap (lambda (v) '()))
Dave Griffiths's avatar
Dave Griffiths committed
1126
    (text-view (make-id "update-individual-chip-text") "Chip code" 20 fillwrap)
Dave Griffiths's avatar
Dave Griffiths committed
1127
    (edit-text (make-id "update-individual-chip-code") "" 30 "text" fillwrap (lambda (