starwisp.scm 38.1 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 35 36 37 38 39
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 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")
   (list "Pup Assoc" "gc-pup-assoc")
   (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 206 207
(define (mtoggle-button id title fn)
  (toggle-button (make-id id) title 20 fillwrap fn))

Dave Griffiths's avatar
Dave Griffiths committed
208 209
(define (mtext id text)
  (text-view (make-id id) text 20 fillwrap))
210

211 212 213
(define (mtitle id text)
  (text-view (make-id id) text 40 fillwrap))

214 215
(define (medit-text id text type fn)
  (vert
216 217
   (mtext (string-append id "-title") text)
   (edit-text (make-id id) "" 20 type fillwrap fn)))
218 219 220 221 222 223 224

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

225 226 227 228 229 230 231
(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))

232 233 234 235 236 237 238 239 240 241
(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))

242 243 244 245 246 247 248 249 250 251 252 253 254 255
(define (build-grid-selector name title)
  (vert
   (mtext "foo" title)
   (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
       (layout 'wrap-content 'wrap-content 1 'centre) (list))))
    (image-view (make-id "im") "arrow_right" (layout 100 'fill-parent 1 'right)))))

256 257 258
(define (populate-grid name items buildfn)
  (alog "populate-grid start")
  (let ((r (update-widget
259 260 261 262 263 264 265 266
   'linear-layout (get-id name) 'contents
   (map
    (lambda (items)
      ;; todo add space for empty parts
      (linear-layout
       (make-id "foo") 'vertical wrap
       (map
        (lambda (item)
267 268 269 270
          (alog "startttt")
          (let ((r (buildfn item)))
            (alog "endddd")
            r))
271
        items)))
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298
    (xwise 3 items)))))
    (alog "populate-grid end")
    r))

(define (populate-grid-selector name items fn)
  (populate-grid
   name items
   (lambda (item)
     (let ((item-name (ktv-get item "name")))
       (button
        (make-id (string-append name item-name))
        item-name 15 (layout 100 40 1 'left)
        (lambda ()
          (fn item)))))
   items))

(define (populate-grid-selector-toggle name items fn)
  (populate-grid
   name items
   (lambda (item)
     (let ((item-name (ktv-get item "name")))
       (toggle-button
        (make-id (string-append name item-name))
        item-name 15 (layout 100 40 1 'left)
        (lambda ()
          (fn item)))))
   items))
299 300

(define (populate-grid-selector-single name items fn)
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319
  (populate-grid
   name items
   (lambda (item)
     (let ((item-name (ktv-get item "name")))
       (toggle-button
        (make-id (string-append name item-name))
        item-name 15 (layout 100 40 1 'left)
        (lambda (v)
          (append
           ;; clear all the others except us
           (mclear-toggles
            (foldl
             (lambda (item r)
               (let ((tname (ktv-get item "name")))
                 (if (equal? tname item-name) r
                     (cons
                      (string-append name tname) r))))
             '() items))
           (fn item))))))))
320 321 322

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
Dave Griffiths's avatar
Dave Griffiths committed
323

324 325
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; fragments
Dave Griffiths's avatar
Dave Griffiths committed
326 327 328 329

(define-fragment-list

  (fragment
330
   "gc-start"
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 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
   (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) '()))
     (build-grid-selector "gc-start-present" "Who's present?")))

   (lambda (fragment arg)
     (activity-layout fragment))
   (lambda (fragment arg)
     (list
      (populate-grid-selector
       "gc-start-present"
       (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")
     (build-grid-selector "gc-weigh-choose" "Choose mongoose")
     (mtext "gc-weigh-current" "No mongoose yet...")
     (mtext "" "Weight")
     (edit-text (make-id "gc-weigh-weight") "" 20 "numeric" fillwrap (lambda (v) '()))
     (mtoggle-button "gc-weigh-accuracy" "Accurate?" (lambda (v) '()))))

   (lambda (fragment arg)
     (activity-layout fragment))
   (lambda (fragment arg)
     (list
      (populate-grid-selector
       "gc-weigh-choose"
       (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")
     (build-grid-selector "gc-preg-choose" "Choose mongoose")))

   (lambda (fragment arg)
     (activity-layout fragment))
   (lambda (fragment arg)
     (list
      (populate-grid-selector-toggle
       "gc-preg-choose"
       (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-pup-assoc"
   (linear-layout
    (make-id "") 'vertical fillwrap
    (list
     (mtitle "title" "Pregnant females")
     (build-grid-selector "gc-pup-choose" "Choose pup")
     (build-grid-selector "gc-pup-escort" "Escort")))

   (lambda (fragment arg)
     (activity-layout fragment))
   (lambda (fragment arg)
     (list
      (populate-grid-selector-single
       "gc-pup-choose"
       (db-all-where
        db "sync" "mongoose"
        (list "pack-id" (ktv-get (get-current 'pack '()) "unique_id")))
       (lambda (individual)
         (list)))
      (populate-grid-selector-single
       "gc-pup-escort"
       (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) '()))
472

473 474 475 476 477 478
  (fragment
   "gc-end"
   (linear-layout
    (make-id "") 'vertical fillwrap
    (list
     (mtext "" "end!...")))
Dave Griffiths's avatar
Dave Griffiths committed
479 480
   (lambda (fragment arg)
     (activity-layout fragment))
481 482
   (lambda (fragment arg)
     (list))
Dave Griffiths's avatar
Dave Griffiths committed
483 484 485 486 487
   (lambda (fragment) '())
   (lambda (fragment) '())
   (lambda (fragment) '())
   (lambda (fragment) '()))

488 489


Dave Griffiths's avatar
Dave Griffiths committed
490 491
  )

492 493 494 495
(msg "one")

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

497 498 499 500 501
(define-activity-list
  (activity
   "splash"
   (vert
    (text-view (make-id "splash-title") "Mongoose 2000" 40 fillwrap)
Dave Griffiths's avatar
Dave Griffiths committed
502
    (mtext "splash-about" "Advanced mongoose technology")
503
    (spacer 20)
504 505 506 507
    (mbutton "f2" "Get started!" (lambda () (list (start-activity-goto "main" 2 ""))))
    (button-grid (make-id "bg") 3 20 (layout 200 40 1 'left)
                 (list) (lambda (v) (msg v) '()))
    )
Dave Griffiths's avatar
Dave Griffiths committed
508

509 510
   (lambda (activity arg)
     (activity-layout activity))
511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530
   (lambda (activity arg)
     (list
      (update-widget
       'button-grid (get-id "bg") 'grid-buttons
       (list
        3 20 (layout 200 40 1 'left)
        (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) '())))
     ))
531 532 533 534 535 536
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity requestcode resultcode) '()))

Dave Griffiths's avatar
Dave Griffiths committed
537

538 539 540
  (activity
   "main"
   (vert
Dave Griffiths's avatar
Dave Griffiths committed
541 542
    (text-view (make-id "main-title") "Mongoose 2000" 40 fillwrap)
    (text-view (make-id "main-about") "Advanced mongoose technology" 20 fillwrap)
543
    (spacer 10)
544
    (mbutton "main-observations" "Observations" (lambda () (list (start-activity "observations" 2 ""))))
Dave Griffiths's avatar
Dave Griffiths committed
545 546
    (mbutton "main-manage" "Manage Packs" (lambda () (list (start-activity "manage-packs" 2 ""))))
    (mbutton "main-tag" "Tag Location" (lambda () (list (start-activity "tag-location" 2 ""))))
547
    (mtext "foo" "Your ID")
Dave Griffiths's avatar
Dave Griffiths committed
548
    (edit-text (make-id "main-id-text") "" 30 "text" fillwrap
549 550 551 552
               (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
553 554 555
    (mtext "foo" "Database")
    (horiz
     (mbutton "main-send" "Email" (lambda () (list)))
556
     (mbutton "main-sync" "Sync" (lambda () (list (start-activity "sync" 0 ""))))))
Dave Griffiths's avatar
Dave Griffiths committed
557 558
   (lambda (activity arg)
     (activity-layout activity))
559 560 561 562 563
   (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
564 565 566 567 568 569 570
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity requestcode resultcode) '()))

  (activity
571
   "observations"
Dave Griffiths's avatar
Dave Griffiths committed
572
   (vert
573 574 575
    (text-view (make-id "title") "Start Observation" 40 fillwrap)
    (vert
     (mtext "type" "Choose observation type")
576 577 578 579 580 581 582 583
     (mtoggle-button "choose-obs-gc" obs-gc
              (lambda (v)
                (set-current! 'observation obs-gc)
                (mclear-toggles (list "choose-obs-pf"))))
     (mtoggle-button "choose-obs-pf" obs-pf
              (lambda (v)
                (set-current! 'observation obs-gc)
                (mclear-toggles (list "choose-obs-gc")))))
584 585 586 587
    (build-grid-selector "choose-obs-pack-selector" "Choose pack")
    (mbutton
     "choose-obs-start" "Start"
     (lambda ()
588 589 590 591 592 593 594 595 596 597 598 599
       ;; 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)
             ((equal? obs obs-pf)
              (list
               (list "Start" "gc-start")))))))

       ;; go to observation
600 601 602 603 604 605 606 607
       (if (and (current-exists? 'pack)
                (current-exists? 'observation))
           (list (start-activity "observation" 2 ""))
           (list
            (alert-dialog
             "choose-obs-finish"
             "Need to specify a pack and an observation"
             (lambda () '()))))))
Dave Griffiths's avatar
Dave Griffiths committed
608 609 610
    )
   (lambda (activity arg)
     (activity-layout activity))
611 612 613 614 615
   (lambda (activity arg)
     (list
      (populate-grid-selector-single
       "choose-obs-pack-selector" (db-all db "sync" "pack")
       (lambda (pack)
616 617 618
         (msg "in selector" pack)
         (set-current! 'pack pack)
         '()))))
Dave Griffiths's avatar
Dave Griffiths committed
619 620 621 622 623 624
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity requestcode resultcode) '()))

625 626


Dave Griffiths's avatar
Dave Griffiths committed
627
  (activity
628
   "observation"
Dave Griffiths's avatar
Dave Griffiths committed
629
   (vert
630
    (text-view (make-id "obs-title") "" 40 fillwrap)
631 632 633 634 635
    (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
636 637 638

   (lambda (activity arg)
     (activity-layout activity))
639 640
   (lambda (activity arg)
     (list
641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660
      (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 '()))))
661 662 663 664
      (update-widget 'text-view (get-id "obs-title") 'text
                     (string-append
                      (get-current 'observation "No observation")
                      " with " (ktv-get (get-current 'pack '()) "name")))
665 666 667 668 669
      (update-widget 'view-pager (get-id "obs-container") 'contents
                     (map
                      (lambda (frag)
                        (cadr frag))
                      (get-current 'observation-fragments '())))
670
      ))
Dave Griffiths's avatar
Dave Griffiths committed
671 672 673 674 675 676
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity requestcode resultcode) '()))

677 678 679 680 681





Dave Griffiths's avatar
Dave Griffiths committed
682 683 684 685 686
  (activity
   "individual-select"
   (vert
    (text-view (make-id "title") "Select an individual" 40 fillwrap)
    (spacer 10)
687 688 689
    (linear-layout
     (make-id "individual-select-list")
     'vertical fill (list))
Dave Griffiths's avatar
Dave Griffiths committed
690 691 692
    )
   (lambda (activity arg)
     (activity-layout activity))
693 694 695 696 697 698 699 700
   (lambda (activity arg)
     (list
      (update-widget 'linear-layout (get-id "individual-select-list") 'contents
                     (build-individual-buttons
                      "ind-select"
                      (lambda (individual)
                        (set-current! 'individual individual)
                        (list (start-activity "pup-focal" 2 "")))))))
Dave Griffiths's avatar
Dave Griffiths committed
701 702 703 704 705 706 707
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity requestcode resultcode) '()))


Dave Griffiths's avatar
Dave Griffiths committed
708
  (let ((clear-focal-toggles
709
         (lambda (v but)
Dave Griffiths's avatar
Dave Griffiths committed
710
           (list
711 712 713 714 715 716 717
            (update-widget 'toggle-button (get-id "pup-focal-moving") 'checked
                           (if (equal? but "pup-focal-moving") 1 0))
            (update-widget 'toggle-button (get-id "pup-focal-foraging") 'checked
                           (if (equal? but "pup-focal-foraging") 1 0))
            (update-widget 'toggle-button (get-id "pup-focal-resting") 'checked
                           (if (equal? but "pup-focal-resting") 1 0)))
           )))
Dave Griffiths's avatar
Dave Griffiths committed
718

Dave Griffiths's avatar
Dave Griffiths committed
719 720 721 722 723 724 725 726
    (activity
     "pup-focal"
     (vert
      (horiz
       (text-view (make-id "pup-focal-title") "Pup Focal" 40 fillwrap)
       (vert
        (text-view (make-id "pup-focal-timer-text") "Time left" 20 fillwrap)
        (text-view (make-id "pup-focal-timer") "30" 40 fillwrap)))
727
      (text-view (make-id "pup-focal-name/pack") "" 25 fillwrap)
Dave Griffiths's avatar
Dave Griffiths committed
728 729
      (text-view (make-id "pup-focal") "Current Activity" 20 fillwrap)
      (horiz
730 731 732
       (toggle-button (make-id "pup-focal-moving") "Moving" 20 fillwrap (lambda (v) (clear-focal-toggles v "pup-focal-moving")))
       (toggle-button (make-id "pup-focal-foraging") "Foraging" 20 fillwrap (lambda (v) (clear-focal-toggles v "pup-focal-foraging")))
       (toggle-button (make-id "pup-focal-resting") "Resting" 20 fillwrap (lambda (v) (clear-focal-toggles v "pup-focal-resting"))))
Dave Griffiths's avatar
Dave Griffiths committed
733
      (text-view (make-id "pup-focal-escort-text") "Current Escort" 20 fillwrap)
734 735
      (spinner (make-id "pup-focal-escort") (list "mongoose1" "mongoose2")
                 fillwrap (lambda (v) '()))
Dave Griffiths's avatar
Dave Griffiths committed
736 737 738 739 740 741
      (horiz
       (button (make-id "pup-focal-event") "New event" 20 fillwrap (lambda () (list (start-activity "pup-focal-event" 2 ""))))
       (toggle-button (make-id "pup-focal-pause") "Pause" 20 fillwrap (lambda (v) '()))
       ))
     (lambda (activity arg)
       (activity-layout activity))
742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758
     (lambda (activity arg)
       (list
        (update-widget 'text-view (get-id "pup-focal-name/pack") 'text
                       (string-append
                        "Pack: " (ktv-get (get-current 'pack '()) "name") " "
                        "Pup: " (ktv-get (get-current 'individual '()) "name")))
        (update-widget 'spinner (get-id "pup-focal-escort") 'array
                 (foldl
                  (lambda (individual r)
                    (let ((name (ktv-get individual "name")))
                      (if (equal? name (ktv-get (get-current 'individual '()) "name"))
                          r (cons name r))))
                  '()
                  (dbg (db-all-where
                   db "sync" "mongoose"
                   (list "pack-id" (ktv-get (get-current 'pack '()) "unique_id"))))))
        ))
Dave Griffiths's avatar
Dave Griffiths committed
759 760 761 762 763
     (lambda (activity) '())
     (lambda (activity) '())
     (lambda (activity) '())
     (lambda (activity) '())
     (lambda (activity requestcode resultcode) '())))
Dave Griffiths's avatar
Dave Griffiths committed
764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791

  (activity
   "pup-focal-event"
   (vert
    (text-view (make-id "main-title") "Pup focal event" 40 fillwrap)
    (spacer 10)
    (button (make-id "event-self") "Self feeding" 20 fillwrap
            (lambda () (list (start-activity "event-self" 2 ""))))
    (button (make-id "event-fed") "Being fed" 20 fillwrap
            (lambda () (list (start-activity "event-fed" 2 ""))))
    (button (make-id "event-aggression") "Aggression" 20 fillwrap
            (lambda () (list (start-activity "event-aggression" 2 ""))))
    (spacer 10)
    (button (make-id "event-cancel") "Cancel" 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-self"
   (vert
Dave Griffiths's avatar
Dave Griffiths committed
792
    (text-view (make-id "main-title") "Self feeding event" 40 fillwrap)
Dave Griffiths's avatar
Dave Griffiths committed
793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820
    (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
821
    (text-view (make-id "main-title") "Being fed event" 40 fillwrap)
Dave Griffiths's avatar
Dave Griffiths committed
822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852
    (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
853
    (text-view (make-id "main-title") "Aggression event" 40 fillwrap)
Dave Griffiths's avatar
Dave Griffiths committed
854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879
    (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)
880
    (build-grid-selector "manage-packs-list" "Choose pack")
Dave Griffiths's avatar
Dave Griffiths committed
881
    (button (make-id "manage-packs-new") "New pack" 20 fillwrap (lambda () (list (start-activity "new-pack" 2 ""))))
Dave Griffiths's avatar
Dave Griffiths committed
882 883 884
    )
   (lambda (activity arg)
     (activity-layout activity))
Dave Griffiths's avatar
Dave Griffiths committed
885 886
   (lambda (activity arg)
     (list
887 888 889 890 891
      (populate-grid-selector
       "manage-packs-list" (db-all db "sync" "pack")
       (lambda (pack)
         (set-current! 'pack pack)
         (list (start-activity "manage-individual" 2 ""))))
Dave Griffiths's avatar
Dave Griffiths committed
892
      ))
Dave Griffiths's avatar
Dave Griffiths committed
893 894 895 896
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
897
   (lambda (activity requestcode resultcode) '()))
Dave Griffiths's avatar
Dave Griffiths committed
898 899 900 901 902 903

  (activity
   "new-pack"
   (vert
    (text-view (make-id "title") "New pack" 40 fillwrap)
    (spacer 10)
Dave Griffiths's avatar
Dave Griffiths committed
904
    (text-view (make-id "new-pack-name-text") "Pack name" 20 fillwrap)
Dave Griffiths's avatar
Dave Griffiths committed
905
    (edit-text (make-id "new-pack-name") "" 30 "text" fillwrap
906
               (lambda (v) (set-current! 'pack-name v) '()))
Dave Griffiths's avatar
Dave Griffiths committed
907
    (spacer 10)
Dave Griffiths's avatar
Dave Griffiths committed
908 909 910 911 912
    (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
913
                db "sync" "pack" (get-current 'user-id "no id")
914
                (list
Dave Griffiths's avatar
Dave Griffiths committed
915
                 (ktv "name" "varchar" (get-current 'pack-name "no name"))))
Dave Griffiths's avatar
Dave Griffiths committed
916
               (list (finish-activity 2)))))
Dave Griffiths's avatar
Dave Griffiths committed
917 918 919 920 921 922 923 924 925 926 927
    )
   (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
928
   "manage-individual"
Dave Griffiths's avatar
Dave Griffiths committed
929 930
   (vert
    (text-view (make-id "title") "Manage individuals" 40 fillwrap)
Dave Griffiths's avatar
Dave Griffiths committed
931
    (text-view (make-id "manage-individual-pack-name") "Pack:" 20 fillwrap)
932
    (build-grid-selector "manage-individuals-list" "Choose individual")
Dave Griffiths's avatar
Dave Griffiths committed
933
    (button (make-id "manage-individuals-new") "New individual" 20 fillwrap (lambda () (list (start-activity "new-individual" 2 ""))))
Dave Griffiths's avatar
Dave Griffiths committed
934 935 936
    )
   (lambda (activity arg)
     (activity-layout activity))
Dave Griffiths's avatar
Dave Griffiths committed
937 938
   (lambda (activity arg)
     (list
939 940 941 942 943
      (populate-grid-selector
       "manage-individuals-list"
       (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
944
      (update-widget 'text-view (get-id "manage-individual-pack-name") 'text
Dave Griffiths's avatar
Dave Griffiths committed
945
                     (string-append "Pack: " (ktv-get (get-current 'pack '()) "name")))
Dave Griffiths's avatar
Dave Griffiths committed
946
      ))
Dave Griffiths's avatar
Dave Griffiths committed
947 948 949 950
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
951
   (lambda (activity requestcode resultcode) '()))
Dave Griffiths's avatar
Dave Griffiths committed
952 953 954 955 956

  (activity
   "new-individual"
   (vert
    (text-view (make-id "title") "New Mongoose" 40 fillwrap)
Dave Griffiths's avatar
Dave Griffiths committed
957
    (text-view (make-id "new-individual-pack-name") "Pack:" 20 fillwrap)
Dave Griffiths's avatar
Dave Griffiths committed
958
    (text-view (make-id "new-individual-name-text") "Name" 20 fillwrap)
Dave Griffiths's avatar
Dave Griffiths committed
959
    (edit-text (make-id "new-individual-name") "" 30 "text" fillwrap
Dave Griffiths's avatar
Dave Griffiths committed
960
               (lambda (v) (set-current! 'individual-name v) '()))
Dave Griffiths's avatar
Dave Griffiths committed
961
    (text-view (make-id "new-individual-name-text") "Gender" 20 fillwrap)
Dave Griffiths's avatar
Dave Griffiths committed
962 963
    (spinner (make-id "new-individual-gender") (list "Female" "Male") fillwrap
             (lambda (v) (set-current! 'individual-gender v) '()))
Dave Griffiths's avatar
Dave Griffiths committed
964
    (text-view (make-id "new-individual-dob-text") "Date of Birth" 20 fillwrap)
Dave Griffiths's avatar
Dave Griffiths committed
965 966 967
    (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
968
    (text-view (make-id "new-individual-litter-text") "Litter code" 20 fillwrap)
Dave Griffiths's avatar
Dave Griffiths committed
969
    (edit-text (make-id "new-individual-litter-code") "" 30 "text" fillwrap
Dave Griffiths's avatar
Dave Griffiths committed
970
               (lambda (v) (set-current! 'individual-litter-code v) '()))
Dave Griffiths's avatar
Dave Griffiths committed
971
    (text-view (make-id "new-individual-chip-text") "Chip code" 20 fillwrap)
Dave Griffiths's avatar
Dave Griffiths committed
972
    (edit-text (make-id "new-individual-chip-code") "" 30 "text" fillwrap
Dave Griffiths's avatar
Dave Griffiths committed
973 974 975 976 977 978
               (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
979
                db "sync" "mongoose" (get-current 'user-id "no id")
980
                (list
Dave Griffiths's avatar
Dave Griffiths committed
981 982 983 984 985
                 (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"))
986
                 ))
Dave Griffiths's avatar
Dave Griffiths committed
987
               (list (finish-activity 2)))))
988 989 990
    )
   (lambda (activity arg)
     (activity-layout activity))
Dave Griffiths's avatar
Dave Griffiths committed
991 992 993
   (lambda (activity arg)
     (list
      (update-widget 'text-view (get-id "new-individual-pack-name") 'text
Dave Griffiths's avatar
Dave Griffiths committed
994
                     (string-append "Pack: " (ktv-get (get-current 'pack '()) "name")))))
995 996 997 998
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
Dave Griffiths's avatar
Dave Griffiths committed
999 1000 1001 1002 1003 1004 1005
   (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
1006
    (text-view (make-id "update-individual-name-text") "Name" 20 fillwrap)
Dave Griffiths's avatar
Dave Griffiths committed
1007
    (edit-text (make-id "update-individual-name") "" 30 "text" fillwrap (lambda (v) '()))
Dave Griffiths's avatar
Dave Griffiths committed
1008
    (text-view (make-id "update-individual-name-text") "Gender" 20 fillwrap)
Dave Griffiths's avatar
Dave Griffiths committed
1009
    (spinner (make-id "update-individual-gender") (list "Female" "Male") fillwrap (lambda (v) '()))
Dave Griffiths's avatar
Dave Griffiths committed
1010
    (text-view (make-id "update-individual-dob-text") "Date of Birth" 20 fillwrap)
Dave Griffiths's avatar
Dave Griffiths committed
1011 1012 1013
    (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
1014
    (text-view (make-id "update-individual-litter-text") "Litter code" 20 fillwrap)
Dave Griffiths's avatar
Dave Griffiths committed
1015
    (edit-text (make-id "update-individual-litter-code") "" 30 "text" fillwrap (lambda (v) '()))
Dave Griffiths's avatar
Dave Griffiths committed
1016
    (text-view (make-id "update-individual-chip-text") "Chip code" 20 fillwrap)
Dave Griffiths's avatar
Dave Griffiths committed
1017
    (edit-text (make-id "update-individual-chip-code") "" 30 "text" fillwrap (lambda (v) '()))
Dave Griffiths's avatar
Dave Griffiths committed
1018 1019
    (spacer 10)
    (horiz
Dave Griffiths's avatar
Dave Griffiths committed
1020 1021
     (button (make-id "update-individual-delete") "Delete" 20 fillwrap (lambda () (list (finish-activity 2))))
     (button (make-id "update-individual-died") "Died" 20 fillwrap (lambda () (list (finish-activity 2)))))
Dave Griffiths's avatar
Dave Griffiths committed
1022
    (horiz
Dave Griffiths's avatar
Dave Griffiths committed
1023 1024
     (button (make-id "update-individual-cancel") "Cancel" 20 fillwrap (lambda () (list (finish-activity 2))))
     (button (make-id "update-individual-done") "Done" 20 fillwrap (lambda () (list (finish-activity 2)))))
Dave Griffiths's avatar
Dave Griffiths committed
1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039
    )
   (lambda (activity arg)
     (activity-layout activity))
   (lambda (activity arg) (list))
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity requestcode resultcode) '()))


  (activity
   "tag-location"
   (vert
    (text-view (make-id "title") "Tag Location" 40 fillwrap)
Dave Griffiths's avatar
Dave Griffiths committed
1040
    (text-view (make-id "tag-location-gps-text") "GPS" 20 fillwrap)
Dave Griffiths's avatar
Dave Griffiths committed
1041
    (horiz
Dave Griffiths's avatar
Dave Griffiths committed
1042 1043
     (text-view (make-id "tag-location-gps-lat") "LAT" 20 fillwrap)
     (text-view (make-id "tag-location-gps-lng") "LNG" 20 fillwrap))
Dave Griffiths's avatar
Dave Griffiths committed
1044

Dave Griffiths's avatar
Dave Griffiths committed
1045
    (text-view (make-id "tag-location-name-text") "Name" 20 fillwrap)
Dave Griffiths's avatar
Dave Griffiths committed
1046
    (edit-text (make-id "tag-location-name") "" 30 "text" fillwrap (lambda (v) '()))
Dave Griffiths's avatar
Dave Griffiths committed
1047

Dave Griffiths's avatar
Dave Griffiths committed
1048
    (text-view (make-id "tag-location-pack-text") "Associated pack" 20 fillwrap)
Dave Griffiths's avatar
Dave Griffiths committed
1049 1050 1051 1052 1053 1054 1055
    (spinner (make-id "tag-location-pack") (list "Pack 1" "Pack 2") fillwrap (lambda (v) '()))

    (text-view (make-id "tag-location-radius-text") "Approx radius of area" 20 fillwrap)
    (seek-bar (make-id "tag-location-radius") 100 fillwrap (lambda (v) '()))
    (text-view (make-id "tag-location-radius-value") "10m" 20 fillwrap)

    (horiz
Dave Griffiths's avatar
Dave Griffiths committed
1056 1057
     (button (make-id "tag-location-cancel") "Cancel" 20 fillwrap (lambda () (list (finish-activity 2))))
     (button (make-id "tag-location-done") "Done" 20 fillwrap (lambda () (list (finish-activity 2)))))
Dave Griffiths's avatar
Dave Griffiths committed
1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069

    )
   (lambda (activity arg)
     (activity-layout activity))
   (lambda (activity arg) (list))
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity requestcode resultcode) '()))


Dave Griffiths's avatar
Dave Griffiths committed
1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082
  (activity
   "sync"
   (vert
    (text-view (make-id "sync-title") "Sync database" 40 fillwrap)
    (mtext "sync-dirty" "...")
    (horiz
     (mbutton "sync-connect" "Connect"
              (lambda ()
                (list
                 (network-connect
                  "network"
                  "mongoose-web"
                  (lambda (state)
1083 1084
                      (list
                       (update-widget 'text-view (get-id "sync-connect") 'text state)))))))
Dave Griffiths's avatar
Dave Griffiths committed
1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095
     (mbutton "sync-sync" "Push"
              (lambda ()
                (let ((r (spit-dirty db "sync")))
                  (cons (if (> (length r) 0)
                            (toast "Uploading data...")
                            (toast "No data changed to upload")) r))))
     (mbutton "sync-pull" "Pull"
              (lambda ()
                (cons (toast "Downloading data...") (suck-new db "sync")))))
    (text-view (make-id "sync-console") "..." 15 (layout 300 'wrap-content 1 'left))
    (mbutton "main-send" "Done" (lambda () (list (finish-activity 2)))))
Dave Griffiths's avatar
Dave Griffiths committed
1096

Dave Griffiths's avatar
Dave Griffiths committed
1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108
   (lambda (activity arg)
     (activity-layout activity))
   (lambda (activity arg)
     (list
      (update-widget 'text-view (get-id "sync-dirty") 'text (build-dirty))
      ;;(update-widget 'text-view (get-id "sync-console") 'text (build-sync-debug db "sync"))
      ))
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity requestcode resultcode) '()))
Dave Griffiths's avatar
Dave Griffiths committed
1109

1110
  )