starwisp.scm 36.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 21 22 23 24 25 26 27 28 29 30 31 32 33 34
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; strings

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

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

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

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

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

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

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

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

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

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

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


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

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

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

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

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

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

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

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

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

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

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

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

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


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

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

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

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

Dave Griffiths's avatar
Dave Griffiths committed
211 212
(define (mtext id text)
  (text-view (make-id id) text 20 fillwrap))
213

214 215 216
(define (mtitle id text)
  (text-view (make-id id) text 40 fillwrap))

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

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

228 229 230 231 232 233 234
(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))

235 236 237 238 239 240 241 242 243 244
(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))

245
(define (build-grid-selector name type title)
246
  (vert
247
   (mtext "title" title)
248 249 250 251 252 253 254 255
   (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
256 257 258 259
       (layout 'wrap-content 'wrap-content 1 'centre)
       (list
        (button-grid (make-id name) type 3 20 (layout 100 40 1 'left)
                     (list) (lambda (v) '()))))))
260 261
    (image-view (make-id "im") "arrow_right" (layout 100 'fill-parent 1 'right)))))

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

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

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
Dave Griffiths's avatar
Dave Griffiths committed
287

288 289
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; fragments
Dave Griffiths's avatar
Dave Griffiths committed
290 291 292

(define-fragment-list

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


  (fragment
   "pf-events"
   (linear-layout
    (make-id "") 'vertical fillwrap
    (list
     (mtext "text" "Pup Focal Events")
     (horiz
      (mbutton2 "evb-pupfeed" "Pup Feed" (lambda () (list (replace-fragment (get-id "pf-bot") "ev-pupfeed"))))
      (mbutton2 "evb-pupfind" "Pup Find" (lambda () (list (replace-fragment (get-id "pf-bot") "ev-pupfind"))))
      (mbutton2 "evb-pupcare" "Pup Care" (lambda () (list (replace-fragment (get-id "pf-bot") "ev-pupcare"))))
      (mbutton2 "evb-pupagg" "Pup Aggression" (lambda () (list (replace-fragment (get-id "pf-bot") "ev-pupaggr")))))
     (mtext "text" "Group Events")
     (horiz
      (mbutton2 "evb-grpint" "Interaction" (lambda () (list (replace-fragment (get-id "pf-bot") "ev-grpint"))))
      (mbutton2 "evb-grpalarm" "Pup Find" (lambda () (list (replace-fragment (get-id "pf-bot") "ev-grpalarm"))))
      (mbutton2 "evb-grpmov" "Pup Care" (lambda () (list (replace-fragment (get-id "pf-bot") "ev-grpmov")))))
     ))


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



Dave Griffiths's avatar
Dave Griffiths committed
342
  (fragment
343
   "gc-start"
344 345 346 347 348 349 350
   (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) '()))
351
     (build-grid-selector "gc-start-present" "toggle" "Who's present?")))
352 353 354 355 356 357

   (lambda (fragment arg)
     (activity-layout fragment))
   (lambda (fragment arg)
     (list
      (populate-grid-selector
358
       "gc-start-present" "toggle"
359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374
       (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")
375
     (build-grid-selector "gc-weigh-choose" "toggle" "Choose mongoose")
376
     (edit-text (make-id "gc-weigh-weight") "" 20 "numeric" fillwrap (lambda (v) '()))
377
     (mtoggle-button "gc-weigh-accurate" "Accurate?" (lambda (v) '()))))
378 379 380 381 382 383

   (lambda (fragment arg)
     (activity-layout fragment))
   (lambda (fragment arg)
     (list
      (populate-grid-selector
384
       "gc-weigh-choose" "toggle"
385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401
       (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")
402
     (build-grid-selector "gc-preg-choose" "toggle" "Choose")))
403 404 405 406 407

   (lambda (fragment arg)
     (activity-layout fragment))
   (lambda (fragment arg)
     (list
408 409
      (populate-grid-selector
       "gc-preg-choose" "toggle"
410 411 412 413 414 415 416 417 418 419 420
       (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) '()))

421

422 423 424 425 426 427
  (fragment
   "gc-pup-assoc"
   (linear-layout
    (make-id "") 'vertical fillwrap
    (list
     (mtitle "title" "Pregnant females")
428 429
     (build-grid-selector "gc-pup-choose" "toggle" "Choose pup")
     (build-grid-selector "gc-pup-escort" "toggle" "Escort")))
430 431 432 433 434

   (lambda (fragment arg)
     (activity-layout fragment))
   (lambda (fragment arg)
     (list
435 436
      (populate-grid-selector
       "gc-pup-choose" "toggle"
437 438 439 440 441
       (db-all-where
        db "sync" "mongoose"
        (list "pack-id" (ktv-get (get-current 'pack '()) "unique_id")))
       (lambda (individual)
         (list)))
442 443
      (populate-grid-selector
       "gc-pup-escort" "toggle"
444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483
       (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) '()))
484

485 486 487 488 489 490
  (fragment
   "gc-end"
   (linear-layout
    (make-id "") 'vertical fillwrap
    (list
     (mtext "" "end!...")))
Dave Griffiths's avatar
Dave Griffiths committed
491 492
   (lambda (fragment arg)
     (activity-layout fragment))
493 494
   (lambda (fragment arg)
     (list))
Dave Griffiths's avatar
Dave Griffiths committed
495 496 497 498 499
   (lambda (fragment) '())
   (lambda (fragment) '())
   (lambda (fragment) '())
   (lambda (fragment) '()))

500 501


Dave Griffiths's avatar
Dave Griffiths committed
502 503
  )

504 505 506 507
(msg "one")

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

509 510 511 512 513
(define-activity-list
  (activity
   "splash"
   (vert
    (text-view (make-id "splash-title") "Mongoose 2000" 40 fillwrap)
Dave Griffiths's avatar
Dave Griffiths committed
514
    (mtext "splash-about" "Advanced mongoose technology")
515
    (spacer 20)
516
    (mbutton "f2" "Get started!" (lambda () (list (start-activity-goto "main" 2 ""))))
517
    (button-grid (make-id "bg") "toggle" 3 20 (layout 100 40 1 'left)
518 519
                 (list) (lambda (v) (msg v) '()))
    )
Dave Griffiths's avatar
Dave Griffiths committed
520

521 522
   (lambda (activity arg)
     (activity-layout activity))
523 524 525 526 527
   (lambda (activity arg)
     (list
      (update-widget
       'button-grid (get-id "bg") 'grid-buttons
       (list
528
        "toggle" 3 20 (layout 100 40 1 'left)
529 530 531 532 533 534 535 536 537 538 539 540 541 542
        (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) '())))
     ))
543 544 545 546 547 548
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity requestcode resultcode) '()))

Dave Griffiths's avatar
Dave Griffiths committed
549

550 551 552
  (activity
   "main"
   (vert
Dave Griffiths's avatar
Dave Griffiths committed
553 554
    (text-view (make-id "main-title") "Mongoose 2000" 40 fillwrap)
    (text-view (make-id "main-about") "Advanced mongoose technology" 20 fillwrap)
555
    (spacer 10)
556
    (mbutton "main-observations" "Observations" (lambda () (list (start-activity "observations" 2 ""))))
Dave Griffiths's avatar
Dave Griffiths committed
557 558
    (mbutton "main-manage" "Manage Packs" (lambda () (list (start-activity "manage-packs" 2 ""))))
    (mbutton "main-tag" "Tag Location" (lambda () (list (start-activity "tag-location" 2 ""))))
559
    (mtext "foo" "Your ID")
Dave Griffiths's avatar
Dave Griffiths committed
560
    (edit-text (make-id "main-id-text") "" 30 "text" fillwrap
561 562 563 564
               (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
565 566 567
    (mtext "foo" "Database")
    (horiz
     (mbutton "main-send" "Email" (lambda () (list)))
568
     (mbutton "main-sync" "Sync" (lambda () (list (start-activity "sync" 0 ""))))))
Dave Griffiths's avatar
Dave Griffiths committed
569 570
   (lambda (activity arg)
     (activity-layout activity))
571 572 573 574 575
   (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
576 577 578 579 580 581 582
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity requestcode resultcode) '()))

  (activity
583
   "observations"
Dave Griffiths's avatar
Dave Griffiths committed
584
   (vert
585 586 587
    (text-view (make-id "title") "Start Observation" 40 fillwrap)
    (vert
     (mtext "type" "Choose observation type")
588 589 590 591 592 593
     (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)
594
                (set-current! 'observation obs-pf)
595
                (mclear-toggles (list "choose-obs-gc")))))
596
    (build-grid-selector "choose-obs-pack-selector" "single" "Choose pack")
597 598 599
    (mbutton
     "choose-obs-start" "Start"
     (lambda ()
600 601 602 603 604 605 606
       ;; 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)
607
             ((equal? obs obs-pf) '())))))
608 609

       ;; go to observation
610 611
       (if (and (current-exists? 'pack)
                (current-exists? 'observation))
612 613 614
           (if (eq? (get-current 'observation "none") obs-pf)
               (list (start-activity "individual-select" 2 ""))
               (list (start-activity "observation" 2 "")))
615 616 617 618 619
           (list
            (alert-dialog
             "choose-obs-finish"
             "Need to specify a pack and an observation"
             (lambda () '()))))))
Dave Griffiths's avatar
Dave Griffiths committed
620 621 622
    )
   (lambda (activity arg)
     (activity-layout activity))
623 624
   (lambda (activity arg)
     (list
625 626 627
      (populate-grid-selector
       "choose-obs-pack-selector" "single"
       (db-all db "sync" "pack")
628
       (lambda (pack)
629 630 631
         (msg "in selector" pack)
         (set-current! 'pack pack)
         '()))))
Dave Griffiths's avatar
Dave Griffiths committed
632 633 634 635 636 637
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity requestcode resultcode) '()))

638 639


Dave Griffiths's avatar
Dave Griffiths committed
640
  (activity
641
   "observation"
Dave Griffiths's avatar
Dave Griffiths committed
642
   (vert
643
    (text-view (make-id "obs-title") "" 40 fillwrap)
644 645 646 647 648
    (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
649 650 651

   (lambda (activity arg)
     (activity-layout activity))
652 653
   (lambda (activity arg)
     (list
654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673
      (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 '()))))
674 675 676 677
      (update-widget 'text-view (get-id "obs-title") 'text
                     (string-append
                      (get-current 'observation "No observation")
                      " with " (ktv-get (get-current 'pack '()) "name")))
678 679 680 681 682
      (update-widget 'view-pager (get-id "obs-container") 'contents
                     (map
                      (lambda (frag)
                        (cadr frag))
                      (get-current 'observation-fragments '())))
683
      ))
Dave Griffiths's avatar
Dave Griffiths committed
684 685 686 687 688 689 690
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity requestcode resultcode) '()))

  (activity
691
   "individual-select" ;; pup focal #1
Dave Griffiths's avatar
Dave Griffiths committed
692
   (vert
693 694 695 696 697 698 699 700 701 702
    (mtitle "" "Pup focal setup")
    (mtext "pf1-pack" "Pack")
    (build-grid-selector "pf1-grid" "single" "Select pup")
    (horiz
     (medit-text "pf1-width" "Pack width" 20 "numeric" (lambda (v) '()))
     (medit-text "pf1-height" "Pack height" 20 "numeric" (lambda (v) '())))
    (medit-text "pf1-count" "How many mongooses present?" 20 "numeric" (lambda (v) '()))
    (mbutton "pf1-done" "Done"
             (lambda ()
               (list (start-activity "pup-focal" 2 ""))))
Dave Griffiths's avatar
Dave Griffiths committed
703
    )
704

Dave Griffiths's avatar
Dave Griffiths committed
705 706
   (lambda (activity arg)
     (activity-layout activity))
707 708
   (lambda (activity arg)
     (list
709 710 711 712 713
      (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
714 715 716 717 718 719 720
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity requestcode resultcode) '()))

  (activity
721
   "pup-focal" ;; pup focal #2
Dave Griffiths's avatar
Dave Griffiths committed
722
   (vert
723 724 725 726 727 728 729 730 731
    (horiz
     (mtitle "title" "Pup Focal")
     (mtext "pf-details" "")
     (mtoggle-button "pf-pause" "Pause" (lambda (v) '())))
    (build-fragment "pf-timer" (make-id "pf-top") (layout 550 350 1 'left))
    (mtitle "title" "Events")
    (build-fragment "pf-events" (make-id "pf-bot") (layout 550 350 1 'left))
    (mbutton "pf-done" "Done" (lambda () (list (start-activity-goto "observations" 2 "")))))

Dave Griffiths's avatar
Dave Griffiths committed
732 733
   (lambda (activity arg)
     (activity-layout activity))
734 735 736 737 738 739 740
   (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
741 742 743 744 745 746
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity requestcode resultcode) '()))

747

Dave Griffiths's avatar
Dave Griffiths committed
748 749 750
  (activity
   "event-self"
   (vert
Dave Griffiths's avatar
Dave Griffiths committed
751
    (text-view (make-id "main-title") "Self feeding event" 40 fillwrap)
Dave Griffiths's avatar
Dave Griffiths committed
752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779
    (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
780
    (text-view (make-id "main-title") "Being fed event" 40 fillwrap)
Dave Griffiths's avatar
Dave Griffiths committed
781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811
    (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
812
    (text-view (make-id "main-title") "Aggression event" 40 fillwrap)
Dave Griffiths's avatar
Dave Griffiths committed
813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838
    (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)
839
    (build-grid-selector "manage-packs-list" "button" "Choose pack")
Dave Griffiths's avatar
Dave Griffiths committed
840
    (button (make-id "manage-packs-new") "New pack" 20 fillwrap (lambda () (list (start-activity "new-pack" 2 ""))))
Dave Griffiths's avatar
Dave Griffiths committed
841 842 843
    )
   (lambda (activity arg)
     (activity-layout activity))
Dave Griffiths's avatar
Dave Griffiths committed
844 845
   (lambda (activity arg)
     (list
846
      (populate-grid-selector
847
       "manage-packs-list" "button" (db-all db "sync" "pack")
848 849 850
       (lambda (pack)
         (set-current! 'pack pack)
         (list (start-activity "manage-individual" 2 ""))))
Dave Griffiths's avatar
Dave Griffiths committed
851
      ))
Dave Griffiths's avatar
Dave Griffiths committed
852 853 854 855
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
856
   (lambda (activity requestcode resultcode) '()))
Dave Griffiths's avatar
Dave Griffiths committed
857 858 859 860 861 862

  (activity
   "new-pack"
   (vert
    (text-view (make-id "title") "New pack" 40 fillwrap)
    (spacer 10)
Dave Griffiths's avatar
Dave Griffiths committed
863
    (text-view (make-id "new-pack-name-text") "Pack name" 20 fillwrap)
Dave Griffiths's avatar
Dave Griffiths committed
864
    (edit-text (make-id "new-pack-name") "" 30 "text" fillwrap
865
               (lambda (v) (set-current! 'pack-name v) '()))
Dave Griffiths's avatar
Dave Griffiths committed
866
    (spacer 10)
Dave Griffiths's avatar
Dave Griffiths committed
867 868 869 870 871
    (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
872
                db "sync" "pack" (get-current 'user-id "no id")
873
                (list
Dave Griffiths's avatar
Dave Griffiths committed
874
                 (ktv "name" "varchar" (get-current 'pack-name "no name"))))
Dave Griffiths's avatar
Dave Griffiths committed
875
               (list (finish-activity 2)))))
Dave Griffiths's avatar
Dave Griffiths committed
876 877 878 879 880 881 882 883 884 885 886
    )
   (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
887
   "manage-individual"
Dave Griffiths's avatar
Dave Griffiths committed
888 889
   (vert
    (text-view (make-id "title") "Manage individuals" 40 fillwrap)
Dave Griffiths's avatar
Dave Griffiths committed
890
    (text-view (make-id "manage-individual-pack-name") "Pack:" 20 fillwrap)
891
    (build-grid-selector "manage-individuals-list" "button" "Choose individual")
Dave Griffiths's avatar
Dave Griffiths committed
892
    (button (make-id "manage-individuals-new") "New individual" 20 fillwrap (lambda () (list (start-activity "new-individual" 2 ""))))
Dave Griffiths's avatar
Dave Griffiths committed
893 894 895
    )
   (lambda (activity arg)
     (activity-layout activity))
Dave Griffiths's avatar
Dave Griffiths committed
896 897
   (lambda (activity arg)
     (list
898
      (populate-grid-selector
899
       "manage-individuals-list" "button"
900 901 902
       (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
903
      (update-widget 'text-view (get-id "manage-individual-pack-name") 'text
Dave Griffiths's avatar
Dave Griffiths committed
904
                     (string-append "Pack: " (ktv-get (get-current 'pack '()) "name")))
Dave Griffiths's avatar
Dave Griffiths committed
905
      ))
Dave Griffiths's avatar
Dave Griffiths committed
906 907 908 909
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
910
   (lambda (activity requestcode resultcode) '()))
Dave Griffiths's avatar
Dave Griffiths committed
911 912 913 914 915

  (activity
   "new-individual"
   (vert
    (text-view (make-id "title") "New Mongoose" 40 fillwrap)
Dave Griffiths's avatar
Dave Griffiths committed
916
    (text-view (make-id "new-individual-pack-name") "Pack:" 20 fillwrap)
Dave Griffiths's avatar
Dave Griffiths committed
917
    (text-view (make-id "new-individual-name-text") "Name" 20 fillwrap)
Dave Griffiths's avatar
Dave Griffiths committed
918
    (edit-text (make-id "new-individual-name") "" 30 "text" fillwrap
Dave Griffiths's avatar
Dave Griffiths committed
919
               (lambda (v) (set-current! 'individual-name v) '()))
Dave Griffiths's avatar
Dave Griffiths committed
920
    (text-view (make-id "new-individual-name-text") "Gender" 20 fillwrap)
Dave Griffiths's avatar
Dave Griffiths committed
921 922
    (spinner (make-id "new-individual-gender") (list "Female" "Male") fillwrap
             (lambda (v) (set-current! 'individual-gender v) '()))
Dave Griffiths's avatar
Dave Griffiths committed
923
    (text-view (make-id "new-individual-dob-text") "Date of Birth" 20 fillwrap)
Dave Griffiths's avatar
Dave Griffiths committed
924 925 926
    (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
927
    (text-view (make-id "new-individual-litter-text") "Litter code" 20 fillwrap)
Dave Griffiths's avatar
Dave Griffiths committed
928
    (edit-text (make-id "new-individual-litter-code") "" 30 "text" fillwrap
Dave Griffiths's avatar
Dave Griffiths committed
929
               (lambda (v) (set-current! 'individual-litter-code v) '()))
Dave Griffiths's avatar
Dave Griffiths committed
930
    (text-view (make-id "new-individual-chip-text") "Chip code" 20 fillwrap)
Dave Griffiths's avatar
Dave Griffiths committed
931
    (edit-text (make-id "new-individual-chip-code") "" 30 "text" fillwrap
Dave Griffiths's avatar
Dave Griffiths committed
932 933 934 935 936 937
               (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
938
                db "sync" "mongoose" (get-current 'user-id "no id")
939
                (list
Dave Griffiths's avatar
Dave Griffiths committed
940 941 942 943 944
                 (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"))
945
                 ))
Dave Griffiths's avatar
Dave Griffiths committed
946
               (list (finish-activity 2)))))
947 948 949
    )
   (lambda (activity arg)
     (activity-layout activity))
Dave Griffiths's avatar
Dave Griffiths committed
950 951 952
   (lambda (activity arg)
     (list
      (update-widget 'text-view (get-id "new-individual-pack-name") 'text
Dave Griffiths's avatar
Dave Griffiths committed
953
                     (string-append "Pack: " (ktv-get (get-current 'pack '()) "name")))))
954 955 956 957
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
Dave Griffiths's avatar
Dave Griffiths committed
958 959 960 961 962 963 964
   (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
965
    (text-view (make-id "update-individual-name-text") "Name" 20 fillwrap)
Dave Griffiths's avatar
Dave Griffiths committed
966
    (edit-text (make-id "update-individual-name") "" 30 "text" fillwrap (lambda (v) '()))
Dave Griffiths's avatar
Dave Griffiths committed
967
    (text-view (make-id "update-individual-name-text") "Gender" 20 fillwrap)
Dave Griffiths's avatar
Dave Griffiths committed
968
    (spinner (make-id "update-individual-gender") (list "Female" "Male") fillwrap (lambda (v) '()))
Dave Griffiths's avatar
Dave Griffiths committed
969
    (text-view (make-id "update-individual-dob-text") "Date of Birth" 20 fillwrap)
Dave Griffiths's avatar
Dave Griffiths committed
970 971 972
    (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
973
    (text-view (make-id "update-individual-litter-text") "Litter code" 20 fillwrap)
Dave Griffiths's avatar
Dave Griffiths committed
974
    (edit-text (make-id "update-individual-litter-code") "" 30 "text" fillwrap (lambda (v) '()))
Dave Griffiths's avatar
Dave Griffiths committed
975
    (text-view (make-id "update-individual-chip-text") "Chip code" 20 fillwrap)
Dave Griffiths's avatar
Dave Griffiths committed
976
    (edit-text (make-id "update-individual-chip-code") "" 30 "text" fillwrap (lambda (v) '()))
Dave Griffiths's avatar
Dave Griffiths committed
977 978
    (spacer 10)
    (horiz
Dave Griffiths's avatar
Dave Griffiths committed
979 980
     (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
981
    (horiz
Dave Griffiths's avatar
Dave Griffiths committed
982 983
     (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
984 985 986 987 988 989 990 991 992 993 994 995 996 997 998
    )
   (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
999
    (text-view (make-id "tag-location-gps-text") "GPS" 20 fillwrap)
Dave Griffiths's avatar
Dave Griffiths committed
1000
    (horiz
Dave Griffiths's avatar
Dave Griffiths committed
1001 1002
     (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
1003

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

Dave Griffiths's avatar
Dave Griffiths committed
1007
    (text-view (make-id "tag-location-pack-text") "Associated pack" 20 fillwrap)
Dave Griffiths's avatar
Dave Griffiths committed
1008 1009 1010 1011 1012 1013 1014
    (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
1015 1016
     (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
1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028

    )
   (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
1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041
  (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)
1042 1043
                      (list
                       (update-widget 'text-view (get-id "sync-connect") 'text state)))))))
Dave Griffiths's avatar
Dave Griffiths committed
1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054
     (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
1055

Dave Griffiths's avatar
Dave Griffiths committed
1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067
   (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
1068

1069
  )