starwisp.scm 43.5 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
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; strings

(define obs-gc "Group Composition")
(define obs-pf "Pup Focal")
21 22 23 24 25 26 27 28 29 30 31 32 33
(define obs-gp "Group Events")

;; colours

(define pf-col (list  22  19 178  96))
(define gp-col (list 255 236   0  96))
(define gc-col (list 255  97   0  96))

;(define gc-col (list   0 176  96 64))
;(define pf-col (list 226   0  72 64))
;(define gp-col (list 255 144   0 64))

(define trans-col (list 0 0 0 0))
34 35 36 37 38 39 40 41 42 43 44 45 46 47

(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")
48
   (list "Pup assoc" "gc-pup-assoc")
49 50 51 52
   (list "Oestrus" "gc-oestrus")
   (list "Babysit" "gc-babysitting")
   (list "End" "gc-end")))

53
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Dave Griffiths's avatar
Dave Griffiths committed
54
;; persistent database
55

Dave Griffiths's avatar
Dave Griffiths committed
56 57
(define db "/sdcard/test.db")
(db-open db)
58 59 60 61 62 63 64 65 66 67
(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
68

Dave Griffiths's avatar
Dave Griffiths committed
69 70
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; stuff in memory
Dave Griffiths's avatar
Dave Griffiths committed
71

Dave Griffiths's avatar
Dave Griffiths committed
72 73
(define (store-set store key value)
  (cond
74 75 76 77 78
   ((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
79

Dave Griffiths's avatar
Dave Griffiths committed
80
(define (store-get store key default)
Dave Griffiths's avatar
Dave Griffiths committed
81
  (cond
82 83 84 85 86 87 88 89 90 91 92 93 94
   ((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
95 96


Dave Griffiths's avatar
Dave Griffiths committed
97
(define store '())
Dave Griffiths's avatar
Dave Griffiths committed
98

Dave Griffiths's avatar
Dave Griffiths committed
99 100
(define (set-current! key value)
  (set! store (store-set store key value)))
Dave Griffiths's avatar
Dave Griffiths committed
101

Dave Griffiths's avatar
Dave Griffiths committed
102 103
(define (get-current key default)
  (store-get store key default))
Dave Griffiths's avatar
Dave Griffiths committed
104

105 106 107
(define (current-exists? key)
  (store-exists? store key))

Dave Griffiths's avatar
Dave Griffiths committed
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 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
129 130
   "&dirty=" (number->string (list-ref (car e) 2))
   "&version=" (number->string (list-ref (car e) 3))
Dave Griffiths's avatar
Dave Griffiths committed
131 132 133 134 135 136 137 138 139 140 141 142
   (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
143 144 145 146
            (begin
              (update-entity-clean db table (cadr v))
              (toast "Uploaded " (ktv-get (cadr e) "name")))
            (toast "Problem uploading " (ktv-get (cadr e) "name"))))))
147
   (dirty-entities db table)))
Dave Griffiths's avatar
Dave Griffiths committed
148

149
(define (suck-entity-from-server db table unique-id exists)
Dave Griffiths's avatar
Dave Griffiths committed
150 151 152 153 154 155 156
  ;; 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'
157 158
     (let ((entity (list-ref data 0))
           (ktvlist (list-ref data 1)))
Dave Griffiths's avatar
Dave Griffiths committed
159
       (if (not exists)
160 161 162 163 164 165 166 167
           (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
168 169
           (update-to-version
            db table (get-entity-id db table unique-id)
Dave Griffiths's avatar
Dave Griffiths committed
170 171 172 173
            (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
174

Dave Griffiths's avatar
Dave Griffiths committed
175
;; repeatedly read version and request updates
Dave Griffiths's avatar
Dave Griffiths committed
176
(define (suck-new db table)
Dave Griffiths's avatar
Dave Griffiths committed
177 178 179
  (list
   (http-request
    "new-entities-req"
180
    (string-append url "fn=entity-versions&table=" table)
Dave Griffiths's avatar
Dave Griffiths committed
181
    (lambda (data)
Dave Griffiths's avatar
Dave Griffiths committed
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
      (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
202

203 204 205 206 207 208 209 210 211
(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
212
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
213
;; user interface abstraction
Dave Griffiths's avatar
Dave Griffiths committed
214

Dave Griffiths's avatar
Dave Griffiths committed
215 216 217
(define (mbutton id title fn)
  (button (make-id id) title 20 fillwrap fn))

218
(define (mbutton2 id title fn)
219
  (button (make-id id) title 20 (layout 150 100 1 'centre) fn))
220

221 222 223
(define (mtoggle-button id title fn)
  (toggle-button (make-id id) title 20 fillwrap fn))

224
(define (mtoggle-button2 id title fn)
225
  (toggle-button (make-id id) title 20 (layout 150 100 1 'centre) fn))
226

Dave Griffiths's avatar
Dave Griffiths committed
227 228
(define (mtext id text)
  (text-view (make-id id) text 20 fillwrap))
229

230 231 232
(define (mtitle id text)
  (text-view (make-id id) text 40 fillwrap))

233 234
(define (medit-text id text type fn)
  (vert
235 236
   (mtext (string-append id "-title") text)
   (edit-text (make-id id) "" 20 type fillwrap fn)))
237 238 239 240 241 242 243

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

244 245 246 247 248 249 250
(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))

251 252 253 254 255 256 257 258 259 260
(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))

261
(define (build-grid-selector name type title)
262
  (vert
263
   (mtext "title" title)
264 265 266 267 268 269 270 271
   (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
272
       (layout 'wrap-content 'wrap-content 1 'centre) trans-col
273 274 275
       (list
        (button-grid (make-id name) type 3 20 (layout 100 40 1 'left)
                     (list) (lambda (v) '()))))))
276 277
    (image-view (make-id "im") "arrow_right" (layout 100 'fill-parent 1 'right)))))

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))
287
                    item
288 289 290 291 292 293 294 295 296 297 298 299
                           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))))))))
300 301 302

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
Dave Griffiths's avatar
Dave Griffiths committed
303

304 305
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; fragments
Dave Griffiths's avatar
Dave Griffiths committed
306 307 308

(define-fragment-list

309 310 311
  (fragment
   "pf-timer"
   (linear-layout
312
    (make-id "") 'vertical fillwrap pf-col
313 314
    (list
     (mtitle "title" "Time left: 20 mins")
315
     (mtitle "title" "Next scan: 60 secs")
316
     (mbutton "pft-trigger" "NN scan"
317
              (lambda () (list (replace-fragment (get-id "pf-top") "pf-scan1"))))))
318 319 320 321 322 323 324 325 326 327 328
   (lambda (fragment arg)
     (activity-layout fragment))
   (lambda (fragment arg)
     (list))
   (lambda (fragment) '())
   (lambda (fragment) '())
   (lambda (fragment) '())
   (lambda (fragment) '()))


  (fragment
329
   "events"
330
   (linear-layout
331
    0 'vertical fillwrap trans-col
332
    (list
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347
     (mtitle "ev-pf-text" "Pup Focal Events")
     (linear-layout
      (make-id "ev-pf") 'horizontal fill pf-col
      (list
       (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"))))))
     (mtitle "text" "Group Events")
     (linear-layout
      0 'horizontal fill gp-col
      (list
       (mbutton2 "evb-grpint" "Interaction" (lambda () (list (replace-fragment (get-id "pf-bot") "ev-grpint"))))
       (mbutton2 "evb-grpalarm" "Alarm" (lambda () (list (replace-fragment (get-id "pf-bot") "ev-grpalarm"))))
       (mbutton2 "evb-grpmov" "Movement" (lambda () (list (replace-fragment (get-id "pf-bot") "ev-grpmov"))))))))
348 349 350
   (lambda (fragment arg)
     (activity-layout fragment))
   (lambda (fragment arg)
351 352 353 354 355 356 357
     (if (equal? (get-current 'observation "none") obs-gp)
         (list
          (update-widget 'text-view (get-id "ev-pf-text") 'hide 0)
          (update-widget 'linear-layout (get-id "ev-pf") 'hide 0))
         (list
          (update-widget 'text-view (get-id "ev-pf-text") 'show 0)
          (update-widget 'linear-layout (get-id "ev-pf") 'show 0))))
358 359 360 361
   (lambda (fragment) '())
   (lambda (fragment) '())
   (lambda (fragment) '())
   (lambda (fragment) '()))
362

363 364 365
  (fragment
   "pf-scan1"
   (linear-layout
366
    (make-id "") 'vertical fillwrap pf-col
367
    (list
368 369 370
     (mtext "title" "Nearest Neighbour Scan")
     (build-grid-selector "pf-scan-nearest" "single" "Closest Mongoose")
     (build-grid-selector "pf-scan-close" "toggle" "Mongooses within 2m")
371
     (mbutton "pf-scan-done" "Done" (lambda () (list (replace-fragment (get-id "pf-top") "pf-timer"))))))
372 373 374 375

   (lambda (fragment arg)
     (activity-layout fragment))
   (lambda (fragment arg)
376 377 378 379 380 381 382 383 384 385 386 387 388 389
     (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)))
      ))
390 391 392 393 394 395
   (lambda (fragment) '())
   (lambda (fragment) '())
   (lambda (fragment) '())
   (lambda (fragment) '()))


396 397 398
  (fragment
   "ev-pupfeed"
   (linear-layout
399
    (make-id "") 'vertical fillwrap pf-col
400
    (list
401
     (mtitle "title" "Event: Pup is fed")
402 403 404 405
     (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) '()))
406
      (mbutton "pf-pupfeed-done" "Done" (lambda () (list (replace-fragment (get-id "pf-bot") "events")))))))
407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423

   (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
424 425 426
  (fragment
   "ev-pupfind"
   (linear-layout
427
    (make-id "") 'vertical fillwrap pf-col
Dave Griffiths's avatar
Dave Griffiths committed
428
    (list
429
     (mtitle "title" "Event: Pup found food")
Dave Griffiths's avatar
Dave Griffiths committed
430 431 432
     (mtext "text" "Food size")
     (horiz
      (spinner (make-id "pf-pupfind-size") (list "Small" "Medium" "Large") fillwrap (lambda (v) '()))
433
      (mbutton "pf-pupfind-done" "Done" (lambda () (list (replace-fragment (get-id "pf-bot") "events")))))))
Dave Griffiths's avatar
Dave Griffiths committed
434 435 436 437 438 439 440 441 442 443 444 445 446 447 448

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


  (fragment
   "ev-pupcare"
   (linear-layout
449
    (make-id "") 'vertical fillwrap pf-col
Dave Griffiths's avatar
Dave Griffiths committed
450
    (list
451
     (mtitle "title" "Event: Pup is cared for")
Dave Griffiths's avatar
Dave Griffiths committed
452 453 454 455
     (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) '()))
456
      (mbutton "pf-pupcare-done" "Done" (lambda () (list (replace-fragment (get-id "pf-bot") "events")))))))
Dave Griffiths's avatar
Dave Griffiths committed
457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476

   (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
477
    (make-id "") 'vertical fillwrap pf-col
Dave Griffiths's avatar
Dave Griffiths committed
478
    (list
479
     (mtitle "title" "Event: Pup aggression")
Dave Griffiths's avatar
Dave Griffiths committed
480 481 482
     (build-grid-selector "pf-pupaggr-partner" "single" "Aggressive mongoose")

     (linear-layout
483
      (make-id "") 'horizontal (layout 'fill-parent 100 '1 'left) trans-col
Dave Griffiths's avatar
Dave Griffiths committed
484 485 486 487 488 489 490 491 492
      (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) '()))))
493
     (mbutton "pf-pupaggr-done" "Done" (lambda () (list (replace-fragment (get-id "pf-bot") "events"))))))
Dave Griffiths's avatar
Dave Griffiths committed
494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510

   (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) '()))

511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 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
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

  (fragment
   "ev-grpint"
   (linear-layout
    (make-id "") 'vertical fillwrap gp-col
    (list
     (mtitle "title" "Event: Group Interaction")
     (build-grid-selector "gp-int-pack" "single" "Inter-group interaction: Other pack identity")
     (build-grid-selector "gp-int-leader" "single" "Leader")
     (linear-layout
      (make-id "") 'horizontal (layout 'fill-parent 80 '1 'left) trans-col
      (list
       (vert
        (mtext "text" "Outcome")
        (spinner (make-id "gp-int-out") (list "Retreat" "Advance" "Fight & retreat" "Fight & win") fillwrap (lambda (v) '())))
       (vert
        (mtext "text" "Duration")
        (edit-text (make-id "gp-int-dur") "" 20 "numeric" fillwrap (lambda (v) '())))
       (mbutton "pf-grpint-done" "Done" (lambda () (list (replace-fragment (get-id "pf-bot") "events"))))))))

   (lambda (fragment arg)
     (activity-layout fragment))
   (lambda (fragment arg)
     (list
      (populate-grid-selector
       "gp-int-pack" "single"
       (db-all db "sync" "pack")
       (lambda (individual)
         (list)))
      (populate-grid-selector
       "gp-int-leader" "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-grpalarm"
   (linear-layout
    (make-id "") 'vertical fillwrap gp-col
    (list
     (mtitle "title" "Event: Group alarm")
     (build-grid-selector "gp-alarm-caller" "single" "Alarm caller")
     (mtext "text" "Cause")
     (horiz
      (spinner (make-id "gp-alarm-cause") (list "Predator" "Other mongoose pack" "Humans" "Other" "Unknown") fillwrap (lambda (v) '()))
      (mtoggle-button "gp-alarm-join" "Did the others join in?" (lambda (v) '())))
     (mbutton "pf-grpalarm-done" "Done" (lambda () (list (replace-fragment (get-id "pf-bot") "events"))))))

   (lambda (fragment arg)
     (activity-layout fragment))
   (lambda (fragment arg)
     (list
      (populate-grid-selector
       "gp-alarm-caller" "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-grpmov"
   (linear-layout
    (make-id "") 'vertical fillwrap gp-col
    (list
     (mtitle "title" "Event: Group movement")
     (build-grid-selector "gp-mov-leader" "single" "Leader")
     (linear-layout
      (make-id "") 'horizontal (layout 'fill-parent 90 '1 'left) trans-col
      (list
       (medit-text "gp-mov-w" "Width" "numeric" (lambda (v) '()))
       (medit-text "gp-mov-l" "Length" "numeric" (lambda (v) '()))
       (medit-text "gp-mov-l" "How many" "numeric" (lambda (v) '()))))
     (linear-layout
      (make-id "") 'horizontal (layout 'fill-parent 90 '1 'left) trans-col
      (list
       (vert
        (mtext "" "Where to")
        (spinner (make-id "gp-mov-to") (list "Latrine" "Water" "Food" "Nothing" "Unknown") fillwrap (lambda (v) '())))
       (mbutton "pf-grpmov-done" "Done" (lambda () (list (replace-fragment (get-id "pf-bot") "events"))))))))

   (lambda (fragment arg)
     (activity-layout fragment))
   (lambda (fragment arg)
     (list
      (populate-grid-selector
       "gp-mov-leader" "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) '()))



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

624 625


626

Dave Griffiths's avatar
Dave Griffiths committed
627
  (fragment
628
   "gc-start"
629
   (linear-layout
630
    (make-id "") 'vertical fillwrap gc-col
631 632 633 634 635
    (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) '()))
636
     (build-grid-selector "gc-start-present" "toggle" "Who's present?")))
637 638 639 640 641 642

   (lambda (fragment arg)
     (activity-layout fragment))
   (lambda (fragment arg)
     (list
      (populate-grid-selector
643
       "gc-start-present" "toggle"
644 645 646 647 648 649 650 651 652 653 654 655 656
       (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
657
    (make-id "") 'vertical fillwrap gc-col
658 659
    (list
     (mtitle "title" "Weights")
660
     (build-grid-selector "gc-weigh-choose" "toggle" "Choose mongoose")
661
     (edit-text (make-id "gc-weigh-weight") "" 20 "numeric" fillwrap (lambda (v) '()))
662
     (mtoggle-button "gc-weigh-accurate" "Accurate?" (lambda (v) '()))))
663 664 665 666 667 668

   (lambda (fragment arg)
     (activity-layout fragment))
   (lambda (fragment arg)
     (list
      (populate-grid-selector
669
       "gc-weigh-choose" "toggle"
670 671 672 673 674 675 676 677 678 679 680 681 682 683
       (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
684
    (make-id "") 'vertical fillwrap gc-col
685 686
    (list
     (mtitle "title" "Pregnant females")
687
     (build-grid-selector "gc-preg-choose" "toggle" "Choose")))
688 689 690 691 692

   (lambda (fragment arg)
     (activity-layout fragment))
   (lambda (fragment arg)
     (list
693 694
      (populate-grid-selector
       "gc-preg-choose" "toggle"
695 696 697 698 699 700 701 702 703 704 705
       (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) '()))

706

707 708 709
  (fragment
   "gc-pup-assoc"
   (linear-layout
710
    (make-id "") 'vertical fillwrap gc-col
711
    (list
712
     (mtitle "title" "Pup Associations")
713 714
     (build-grid-selector "gc-pup-choose" "toggle" "Choose pup")
     (build-grid-selector "gc-pup-escort" "toggle" "Escort")))
715 716 717 718 719

   (lambda (fragment arg)
     (activity-layout fragment))
   (lambda (fragment arg)
     (list
720 721
      (populate-grid-selector
       "gc-pup-choose" "toggle"
722 723 724 725 726
       (db-all-where
        db "sync" "mongoose"
        (list "pack-id" (ktv-get (get-current 'pack '()) "unique_id")))
       (lambda (individual)
         (list)))
727 728
      (populate-grid-selector
       "gc-pup-escort" "toggle"
729 730 731 732 733 734 735 736 737 738 739 740 741 742
       (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
743
    (make-id "") 'vertical fillwrap gc-col
744 745 746 747 748 749 750 751 752 753 754 755 756 757
    (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
758
    (make-id "") 'vertical fillwrap gc-col
759 760 761 762 763 764 765 766 767 768
    (list
     (mtext "" "Babysittings...")))
   (lambda (fragment arg)
     (activity-layout fragment))
   (lambda (fragment arg)
     (list))
   (lambda (fragment) '())
   (lambda (fragment) '())
   (lambda (fragment) '())
   (lambda (fragment) '()))
769

770 771 772
  (fragment
   "gc-end"
   (linear-layout
773
    (make-id "") 'vertical fillwrap gc-col
774 775
    (list
     (mtext "" "end!...")))
Dave Griffiths's avatar
Dave Griffiths committed
776 777
   (lambda (fragment arg)
     (activity-layout fragment))
778 779
   (lambda (fragment arg)
     (list))
Dave Griffiths's avatar
Dave Griffiths committed
780 781 782 783 784
   (lambda (fragment) '())
   (lambda (fragment) '())
   (lambda (fragment) '())
   (lambda (fragment) '()))

785 786


Dave Griffiths's avatar
Dave Griffiths committed
787 788
  )

789 790 791 792
(msg "one")

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

794
(define-activity-list
795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812
;  (activity
;   "splash"
;   (vert
;    (text-view (make-id "splash-title") "Mongoose 2000" 40 fillwrap)
;    (mtext "splash-about" "Advanced mongoose technology")
;    (spacer 20)
;    (mbutton2 "f2" "Get started!" (lambda () (list (start-activity-goto "main" 2 ""))))
;    )
;
;   (lambda (activity arg)
;     (activity-layout activity))
;   (lambda (activity arg)
;     (list))
;   (lambda (activity) '())
;   (lambda (activity) '())
;   (lambda (activity) '())
;   (lambda (activity) '())
;   (lambda (activity requestcode resultcode) '()))
813

Dave Griffiths's avatar
Dave Griffiths committed
814

815 816 817
  (activity
   "main"
   (vert
Dave Griffiths's avatar
Dave Griffiths committed
818 819
    (text-view (make-id "main-title") "Mongoose 2000" 40 fillwrap)
    (text-view (make-id "main-about") "Advanced mongoose technology" 20 fillwrap)
820
    (spacer 10)
821 822 823 824
    (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 "")))))
825
    (mtext "foo" "Your ID")
Dave Griffiths's avatar
Dave Griffiths committed
826
    (edit-text (make-id "main-id-text") "" 30 "text" fillwrap
827 828 829 830
               (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
831 832
    (mtext "foo" "Database")
    (horiz
833 834
     (mbutton2 "main-send" "Email" (lambda () (list)))
     (mbutton2 "main-sync" "Sync" (lambda () (list (start-activity "sync" 0 ""))))))
Dave Griffiths's avatar
Dave Griffiths committed
835 836
   (lambda (activity arg)
     (activity-layout activity))
837 838 839 840 841
   (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
842 843 844 845 846 847 848
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity requestcode resultcode) '()))

  (activity
849
   "observations"
Dave Griffiths's avatar
Dave Griffiths committed
850
   (vert
851 852 853
    (text-view (make-id "title") "Start Observation" 40 fillwrap)
    (vert
     (mtext "type" "Choose observation type")
854
     (horiz
855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875
      (linear-layout
       0 'vertical wrap gc-col
       (list
        (mtoggle-button2 "choose-obs-gc" obs-gc
                         (lambda (v)
                           (set-current! 'observation obs-gc)
                           (mclear-toggles (list "choose-obs-pf" "choose-obs-gp"))))))
      (linear-layout
       0 'vertical wrap pf-col
       (list
        (mtoggle-button2 "choose-obs-pf" obs-pf
                         (lambda (v)
                           (set-current! 'observation obs-pf)
                           (mclear-toggles (list "choose-obs-gc" "choose-obs-gp"))))))
      (linear-layout
       0 'vertical wrap gp-col
       (list
        (mtoggle-button2 "choose-obs-gp" obs-gp
                         (lambda (v)
                           (set-current! 'observation obs-gp)
                           (mclear-toggles (list "choose-obs-pf" "choose-obs-gc"))))))))
876
    (build-grid-selector "choose-obs-pack-selector" "single" "Choose pack")
877 878 879
    (mbutton
     "choose-obs-start" "Start"
     (lambda ()
880 881 882 883 884 885 886
       ;; 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)
887
             (else '())))))
888 889

       ;; go to observation
890 891
       (if (and (current-exists? 'pack)
                (current-exists? 'observation))
892 893 894 895 896 897 898
           (cond
            ((eq? (get-current 'observation "none") obs-pf)
             (list (start-activity-goto "individual-select" 2 "")))
            ((eq? (get-current 'observation "none") obs-gp)
             (list (start-activity-goto "event-self" 2 "")))
            (else
             (list (start-activity-goto "observation" 2 ""))))
899 900 901 902 903
           (list
            (alert-dialog
             "choose-obs-finish"
             "Need to specify a pack and an observation"
             (lambda () '()))))))
Dave Griffiths's avatar
Dave Griffiths committed
904 905 906
    )
   (lambda (activity arg)
     (activity-layout activity))
907 908
   (lambda (activity arg)
     (list
909 910 911
      (populate-grid-selector
       "choose-obs-pack-selector" "single"
       (db-all db "sync" "pack")
912
       (lambda (pack)
913 914 915
         (msg "in selector" pack)
         (set-current! 'pack pack)
         '()))))
Dave Griffiths's avatar
Dave Griffiths committed
916 917 918 919 920 921
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity requestcode resultcode) '()))

922

Dave Griffiths's avatar
Dave Griffiths committed
923
  (activity
924 925 926 927 928 929 930 931 932 933
   "observation" ;; group-composition
   (linear-layout
    0 'vertical fillwrap gc-col
    (list
     (text-view (make-id "obs-title") "" 40 fillwrap)
     (linear-layout
      (make-id "obs-buttons-bar") 'horizontal fillwrap trans-col '())
     (view-pager
      (make-id "obs-container") (layout 'wrap-content 700 1 'left) '())
     (mbutton "obs-done" "Done" (lambda () (list (finish-activity 0))))))
Dave Griffiths's avatar
Dave Griffiths committed
934 935 936

   (lambda (activity arg)
     (activity-layout activity))
937 938
   (lambda (activity arg)
     (list
939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958
      (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 '()))))
959 960 961 962
      (update-widget 'text-view (get-id "obs-title") 'text
                     (string-append
                      (get-current 'observation "No observation")
                      " with " (ktv-get (get-current 'pack '()) "name")))
963 964 965 966 967
      (update-widget 'view-pager (get-id "obs-container") 'contents
                     (map
                      (lambda (frag)
                        (cadr frag))
                      (get-current 'observation-fragments '())))
968
      ))
Dave Griffiths's avatar
Dave Griffiths committed
969 970 971 972 973 974 975
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity requestcode resultcode) '()))

  (activity
976
   "individual-select" ;; pup focal #1
977 978 979 980 981 982 983 984 985 986 987 988 989 990 991
   (linear-layout
    0 'vertical fillwrap pf-col
    (list
     (vert
      (mtitle "" "Pup focal setup")
      (mtext "pf1-pack" "Pack")
      (build-grid-selector "pf1-grid" "single" "Select pup")
      (horiz
       (medit-text "pf1-width" "Pack width" "numeric" (lambda (v) '()))
       (medit-text "pf1-height" "Pack height" "numeric" (lambda (v) '())))
      (medit-text "pf1-count" "How many mongooses present?" "numeric" (lambda (v) '()))
      (mbutton "pf1-done" "Done"
               (lambda ()
                 (list (start-activity-goto "pup-focal" 2 ""))))
      )))
Dave Griffiths's avatar
Dave Griffiths committed
992 993
   (lambda (activity arg)
     (activity-layout activity))
994 995
   (lambda (activity arg)
     (list
996 997 998 999 1000
      (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
1001 1002 1003 1004 1005 1006 1007
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity requestcode resultcode) '()))

  (activity
1008
   "pup-focal" ;; pup focal #2
Dave Griffiths's avatar
Dave Griffiths committed
1009
   (vert
1010 1011 1012 1013 1014 1015 1016 1017 1018
    (linear-layout
     0 'horizontal fillwrap pf-col
     (list
      (mtitle "title" "Pup Focal")
      (mtext "pf-details" "")
      (mtoggle-button "pf-pause" "Pause" (lambda (v) '()))))
    (build-fragment "pf-timer" (make-id "pf-top") (layout 595 400 1 'left))
    (build-fragment "events" (make-id "pf-bot") (layout 595 450 1 'left))
    (mbutton "pf-done" "Done" (lambda () (list (finish-activity 0)))))
1019

Dave Griffiths's avatar
Dave Griffiths committed
1020 1021
   (lambda (activity arg)
     (activity-layout activity))
1022 1023 1024 1025 1026 1027 1028
   (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
1029 1030 1031 1032 1033 1034
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity requestcode resultcode) '()))

1035

Dave Griffiths's avatar
Dave Griffiths committed
1036
  (activity
1037 1038 1039 1040 1041 1042 1043 1044
   "event-self" ;; group-event
   (linear-layout
    0 'vertical wrap gp-col
    (list
     (build-fragment "events" (make-id "pf-bot") (layout 580 450 1 'left))
     (horiz
      (mbutton "gpe-save" "Save" (lambda () (list)))
      (mbutton "gpe-done" "Done" (lambda () (list (finish-activity 0)))))))
Dave Griffiths's avatar
Dave Griffiths committed
1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060
   (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)
1061
    (build-grid-selector "manage-packs-list" "button" "Choose pack")
Dave Griffiths's avatar
Dave Griffiths committed
1062
    (button (make-id "manage-packs-new") "New pack" 20 fillwrap (lambda () (list (start-activity "new-pack" 2 ""))))
Dave Griffiths's avatar
Dave Griffiths committed
1063 1064 1065
    )
   (lambda (activity arg)
     (activity-layout activity))
Dave Griffiths's avatar
Dave Griffiths committed
1066 1067
   (lambda (activity arg)
     (list
1068
      (populate-grid-selector
1069
       "manage-packs-list" "button" (db-all db "sync" "pack")
1070 1071 1072
       (lambda (pack)
         (set-current! 'pack pack)
         (list (start-activity "manage-individual" 2 ""))))
Dave Griffiths's avatar
Dave Griffiths committed
1073
      ))
Dave Griffiths's avatar
Dave Griffiths committed
1074 1075 1076 1077
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
1078
   (lambda (activity requestcode resultcode) '()))
Dave Griffiths's avatar
Dave Griffiths committed
1079 1080 1081 1082 1083 1084

  (activity
   "new-pack"
   (vert
    (text-view (make-id "title") "New pack" 40 fillwrap)
    (spacer 10)
Dave Griffiths's avatar
Dave Griffiths committed
1085
    (text-view (make-id "new-pack-name-text") "Pack name" 20 fillwrap)
Dave Griffiths's avatar
Dave Griffiths committed
1086
    (edit-text (make-id "new-pack-name") "" 30 "text" fillwrap
1087
               (lambda (v) (set-current! 'pack-name v) '()))
Dave Griffiths's avatar
Dave Griffiths committed
1088
    (spacer 10)
Dave Griffiths's avatar
Dave Griffiths committed
1089 1090 1091 1092 1093
    (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
1094
                db "sync" "pack" (get-current 'user-id "no id")
1095
                (list
Dave Griffiths's avatar
Dave Griffiths committed
1096
                 (ktv "name" "varchar" (get-current 'pack-name "no name"))))
Dave Griffiths's avatar
Dave Griffiths committed
1097
               (list (finish-activity 2)))))
Dave Griffiths's avatar
Dave Griffiths committed
1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108
    )
   (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
1109
   "manage-individual"
Dave Griffiths's avatar
Dave Griffiths committed
1110 1111
   (vert
    (text-view (make-id "title") "Manage individuals" 40 fillwrap)
Dave Griffiths's avatar
Dave Griffiths committed
1112
    (text-view (make-id "manage-individual-pack-name") "Pack:" 20 fillwrap)
1113
    (build-grid-selector "manage-individuals-list" "button" "Choose individual")
Dave Griffiths's avatar
Dave Griffiths committed
1114
    (button (make-id "manage-individuals-new") "New individual" 20 fillwrap (lambda () (list (start-activity "new-individual" 2 ""))))
Dave Griffiths's avatar
Dave Griffiths committed
1115 1116 1117
    )
   (lambda (activity arg)
     (activity-layout activity))
Dave Griffiths's avatar
Dave Griffiths committed
1118 1119
   (lambda (activity arg)
     (list
1120
      (populate-grid-selector
1121
       "manage-individuals-list" "button"
1122 1123 1124
       (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
1125
      (update-widget 'text-view (get-id "manage-individual-pack-name") 'text
Dave Griffiths's avatar
Dave Griffiths committed
1126
                     (string-append "Pack: " (ktv-get (get-current 'pack '()) "name")))
Dave Griffiths's avatar
Dave Griffiths committed
1127
      ))
Dave Griffiths's avatar
Dave Griffiths committed
1128 1129 1130 1131
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
1132
   (lambda (activity requestcode resultcode) '()))
Dave Griffiths's avatar
Dave Griffiths committed
1133 1134 1135 1136 1137

  (activity
   "new-individual"
   (vert
    (text-view (make-id "title") "New Mongoose" 40 fillwrap)