-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathui_logic.bsh
1819 lines (1600 loc) · 69.6 KB
/
ui_logic.bsh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
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
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
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
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
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
780
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
812
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
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
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
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Clients originally specified in an SRID of 32736.
*
*/
import java.util.concurrent.Callable;
/*** 'Editable' - you can edit the code below based on the needs ***/
User user; // don't touch
String userid;
Boolean transectEnabled = false;
String tracklogStatus = "Tracklog is Stopped";
String tracklogState = "Stop";
addActionBarItem("sync", new ToggleActionButtonCallback() {
actionOnLabel() {
"Disable Sync";
}
actionOn() {
setSyncEnabled(false);
setFileSyncEnabled(false);
showToast("Sync disabled.");
}
isActionOff() {
isSyncEnabled();
}
actionOffLabel() {
"Enable Sync";
}
actionOff() {
setSyncEnabled(true);
setFileSyncEnabled(true);
showToast("Sync enabled.");
}
});
addActionBarItem("internal_gps", new ToggleActionButtonCallback() {
actionOnLabel() {
"Disable Internal GPS";
}
actionOn() {
stopGPS();
showToast("GPS disabled.");
}
isActionOff() {
isInternalGPSOn();
}
actionOffLabel() {
"Enable Internal GPS";
}
actionOff() {
if(isExternalGPSOn()) {
stopGPS();
}
startInternalGPS();
showToast("GPS enabled. GPS refresh rate set to " + getFieldValue("control/Control/refreshText") + ". You can change it in the Control tab.");
}
});
addActionBarItem("external_gps", new ToggleActionButtonCallback() {
actionOnLabel() {
"Disable External GPS";
}
actionOn() {
stopGPS();
showToast("GPS disabled.");
}
isActionOff() {
isExternalGPSOn();
}
actionOffLabel() {
"Enable External GPS";
}
actionOff() {
if(isInternalGPSOn()) {
stopGPS();
}
startExternalGPS();
if(isBluetoothConnected()) {
showToast("GPS enabled. GPS refresh rate set to " + getFieldValue("control/Control/refreshText") + ". You can change it in the Control tab.");
} else {
showToast("Please enable bluetooth.");
this.isActionOff();
}
}
});
addActionBarItem("time_tracklog", new ToggleActionButtonCallback() {
actionOnLabel() {
"Disable Time Tracklog";
}
actionOn() {
stopTrack();
showToast("Tracklog disabled.");
}
isActionOff() {
tracklogState.equals("Time");
}
actionOffLabel() {
"Enable Time Tracklog";
}
actionOff() {
if(isInternalGPSOn() || isInternalGPSOn()) {
startTimeTrack();
showToast("Tracklog enabled. Tracklog time interval set to " + getFieldValue("control/Control/tracktimeText") + " seconds. You can change it in the Control tab.");
} else {
showToast("GPS is not turned on.");
this.isActionOff();
}
}
});
addActionBarItem("distance_tracklog", new ToggleActionButtonCallback() {
actionOnLabel() {
"Disable Distance Tracklog";
}
actionOn() {
stopTrack();
showToast("Tracklog disabled.");
}
isActionOff() {
tracklogState.equals("Distance");
}
actionOffLabel() {
"Enable Distance Tracklog";
}
actionOff() {
if(isInternalGPSOn() || isInternalGPSOn()) {
startDistTrack();
showToast("Tracklog enabled. Tracklog distance interval set to " + getFieldValue("control/Control/trackdistText") + " metres. You can change it in the Control tab.");
} else {
showToast("GPS is not turned on.");
this.isActionOff();
}
}
});
addActionBarItem("compute_transect_lines", new ActionButtonCallback() {
actionOnLabel() {
"Compute Transect Lines";
}
actionOn() {
computeTransectLines();
}
});
computeTransectLines() {
Dialog dialog = showBusy("Please Wait", "Computing transect lines...");
q = " insert into archentity(uuid, userid, aenttypeid, geospatialcolumn)";
q += " select parentuuid, '"+userid+"', parentaenttypeid, casttoGeometryCollection(MakeLine(geospatialcolumn))";
q += " from (SELECT parent.uuid as parentuuid, parent.aenttypeid as parentaenttypeid, child.uuid as childuuid, parent.aenttypename as parentaenttypename, geospatialcolumn";
q += " FROM (SELECT uuid, participatesverb, aenttypename, relationshipid, aenttypeid";
q += " FROM latestnondeletedaentreln";
q += " JOIN relationship USING (relationshipid)";
q += " JOIN latestnondeletedarchent USING (uuid)";
q += " JOIN aenttype USING (aenttypeid)) parent";
q += " JOIN (SELECT uuid, relationshipid, participatesverb, aenttypename, geometryn(latestnondeletedarchent.geospatialcolumn,1) as geospatialcolumn, aenttimestamp";
q += " FROM latestnondeletedaentreln";
q += " JOIN relationship USING (relationshipid)";
q += " JOIN latestnondeletedarchent USING (uuid)";
q += " JOIN aenttype USING (aenttypeid)) child";
q += " ON (parent.relationshipid = child.relationshipid AND parent.uuid != child.uuid)";
q += " where parentaenttypename = 'Transect'";
q += " order by child.aenttimestamp";
q += " )";
q += " group by parentuuid;";
fetchOne(q);
dialog.dismiss();
}
makeLocalID() {
fetchOne("CREATE TABLE IF NOT EXISTS localSettings (key text primary key, value text);", null);
fetchOne("drop view if exists identifierAsSpreadsheet;", null);
fetchOne("create view identifierAsSpreadsheet as select uuid, group_concat(coalesce(measure || ' ' || vocabname || '(' ||freetext||')', measure || ' (' || freetext ||')', vocabname || ' (' || freetext ||')', measure || ' ' || vocabname , vocabname || ' (' || freetext || ')', measure || ' (' || freetext || ')', measure, vocabname, freetext, measure, vocabname, freetext), ' ') as response from (select * from latestNonDeletedArchentIdentifiers order by attributename) group by uuid;", null);
}
makeLocalID();
showWarning("Transect Survey with Artefact recording Demo", "This module was created by the FAIMS team for the needs of the MEMSAP project led by Jessica Thompson of UQ. It was funded by Australian Research Council LIEF grant and is available for Demonstration purposes. You can customise the module yourself or we can help you. Contact info@fedarch.org for help. ");
onEvent("control", "show", "resetGlobals();");
onEvent("control/Start/newSurveyUnit", "delayclick", "newSurveyUnit();");
onEvent("control/Start/newPOI", "delayclick", "newPOI();");
onEvent("control/Start/newArtefact", "delayclick", "newArtefact();");
onEvent("control/Start/newSite", "delayclick", "newSite();");
onEvent("control/Start/finishSU", "click", "finishSurveyUnit();");
onEvent("control/Start/currentSurveyUnit", "click", "loadSurveyUnit();");
onEvent("control/Start/archentsList", "click", "showRecords();");
onEvent("control/Start", "load", "setFieldValue(\"control/Start/archentsList\",\"SUID\");showRecords();");
onEvent("control/Start", "show", "showRecords();updateCurrentTransect();");
onEvent("control/Start/listOfLast", "click", "loadRecord();");
onEvent("control/Control/startGPSButton", "click", "startGPS();");
onEvent("control/Control/stopGPSButton", "click", "stopGPSLogic();");
/*********************************** SEARCH ***********************************/
onEvent("control/Search" , "show" , "search();");
onEvent("control/Search/Entity_List" , "click" , "loadEntity();");
onEvent("control/Search/Search_Button" , "click" , "search()");
onEvent("control/Search/Search_Term" , "click" , "clearSearch()");
onEvent("control/Search/Entity_Types" , "click" , "search()");
entityTypes = new ArrayList();
entityTypes.add(new NameValuePair("{All}", "'Total Recording', 'Transect Object', 'Site', 'Transect'"));
entityTypes.add(new NameValuePair("{Artefact}", "'Total Recording' "));
entityTypes.add(new NameValuePair("{POI}", "'Transect Object' "));
entityTypes.add(new NameValuePair("{Site}", "'Site' "));
entityTypes.add(new NameValuePair("{Survey_Unit}", "'Transect' "));
populateDropDown("control/Search/Entity_Types", entityTypes);
clearSearch(){
setFieldValue("control/Search/Search_Term","");
}
search(){
String tabgroup = "control";
String refEntityList = tabgroup + "/Search/Entity_List";
String refSearchTerm = tabgroup + "/Search/Search_Term";
String refEntityTypes = tabgroup + "/Search/Entity_Types";
String type = getFieldValue(refEntityTypes);
String term = getFieldValue(refSearchTerm);
String searchQuery = "SELECT uuid, response "+
" FROM latestNonDeletedArchEntFormattedIdentifiers "+
" WHERE uuid in (SELECT uuid "+
" FROM latestNonDeletedArchEntIdentifiers "+
" WHERE measure LIKE '"+term+"'||'%' "+
" AND ( aenttypename IN ("+type+")) "+
" ) "+
" ORDER BY response "+
" LIMIT ? "+
"OFFSET ? ";
populateCursorList(refEntityList, searchQuery, 25);
}
loadEntity() {
loadEntity(false);
}
loadEntity(Boolean isDropdown) {
if (isDropdown) {
loadEntityFrom(getDropdownItemValue());
} else {
loadEntityFrom(getListItemValue());
}
}
loadEntityFrom(String entityID) {
if (isNull(entityID)) {
return;
}
String getEntTypeNameQ = "SELECT aenttypename " +
" FROM latestnondeletedarchent " +
" JOIN aenttype " +
" USING (aenttypeid) " +
" WHERE uuid = '" + entityID + "'";
fetchAll(getEntTypeNameQ, new FetchCallback() {
onFetch(result) {
String archEntName = result.get(0).get(0);
String loadFunction = "load" + archEntName.replaceAll(" ", "") + "From(entityID)"; // Typical value: loadContextFrom(entityID)
eval(loadFunction);
}
});
}
/************************** STUFF WHICH ISN'T SEARCH **************************/
showRecords() {
type = getFieldValue("control/Start/archentsList");
query = " SELECT uuid, response";
query += " FROM latestNonDeletedArchEntFormattedIdentifiers";
query += " JOIN latestnondeletedArchEnt USING (uuid)";
query += " WHERE aenttypename = '"+type+"'";
query += " ORDER BY aenttimestamp desc";
fetchAll(query, new FetchCallback() {
onFetch(result) {
if (!isNull(result)) {
populateCursorList(
"control/Start/listOfLast",
query + " limit ? offset ?",
5
);
} else {
ArrayList none = new ArrayList();
none.add("No entries found");
populateList("control/Start/listOfLast", none);
}
}
});
}
updateCurrentTransect() {
if(transectEnabled) {
fetchAll("SELECT uuid, response FROM latestNonDeletedArchEntFormattedIdentifiers WHERE uuid = "+survey_unit_id+"", new FetchCallback() {
onFetch(result) {
populateList("control/Start/currentSurveyUnit", result);
}
});
} else {
populateList("control/Start/currentSurveyUnit", new ArrayList());
fetchOne("select group_concat(response) from " +
"(select surveyUnit.uuid " +
"from " +
"(select uuid, relationshipid " +
"from (select aenttypeid from aenttype where aenttypename = 'Transect') " +
" join latestnondeletedarchent using (aenttypeid) " +
" join latestnondeletedaentreln using (uuid)) surveyUnit " +
"join ((select aenttypeid from aenttype where aenttypename = 'Transect Point') " +
" join latestnondeletedarchent using (aenttypeid) " +
" join latestnondeletedaentreln using (uuid)) transect using (relationshipid) " +
"join (select uuid, measure " +
"from (select aenttypeid from aenttype where aenttypename = 'Transect Point') " +
"join latestnondeletedarchent using (aenttypeid) " +
"join latestnondeletedaentvalue using (uuid) join attributekey using (attributeid) " +
"where attributename = 'State') state on (transect.uuid = state.uuid) " +
"group by surveyUnit.uuid " +
"having min(measure) != 'End') join latestNonDeletedArchEntFormattedIdentifiers using (uuid);", new FetchCallback() {
onFetch(result) {
unfinished = result.get(0);
if(!isNull(unfinished)) showWarning("Warning", "The following Transects have not been finished: " +unfinished+". To finish, load the Transect below as this will make it the current Transect.");
}
});
}
}
loadRecord() {
if (getListItemValue() != "" && !getListItemValue().equals("No entries found")) {
if (getFieldValue("control/Start/archentsList").equals("Transect")) {
loadSurveyUnit();
} else if (getFieldValue("control/Start/archentsList").equals("Transect Object")) {
loadPOI();
} else if (getFieldValue("control/Start/archentsList").equals("Total Recording")) {
loadArtefact();
} else if (getFieldValue("control/Start/archentsList").equals("Site")) {
loadSite();
}
}
}
resetGlobals() {
removeNavigationButton("duplicate");
removeNavigationButton("new");
removeNavigationButton("close");
removeNavigationButton("delete");
}
startGPS() {
Object intext = getFieldValue("control/Control/internalExternalGPS");
if(isNull(intext)) {
showWarning("Warning", "Please choose whether you would like to connect to internal or external GPS.");
return;
}
setGPSUpdateInterval(Integer.parseInt(getFieldValue("control/Control/refreshText")));
showToast("GPS enabled. GPS refresh rate set to " + getFieldValue("control/Control/refreshText") + ".");
if(intext.equals("I")) {
if(isExternalGPSOn()) stopGPS();
startInternalGPS();
}
if(intext.equals("E")) {
if(isInternalGPSOn()) stopGPS();
startExternalGPS();
}
}
stopGPSLogic() {
if(!isInternalGPSOn() && !isExternalGPSOn()) {
showToast("GPS disabled.");
stopGPS();
} else {
showToast("GPS is not turned on.");
}
}
list = new ArrayList();
list.add(new NameValuePair("{Survey_Unit}", "Transect"));
list.add(new NameValuePair("{Site}", "Site"));
list.add(new NameValuePair("{POI}", "Transect Object"));
list.add(new NameValuePair("{Artefact}", "Total Recording"));
populateDropDown("control/Start/archentsList", list);
//Tracklog
onEvent("control/Control/tracktimeButton", "click", "startTimeTrack()");
onEvent("control/Control/trackdistButton", "click", "startDistTrack()");
onEvent("control/Control/trackOffButton", "click", "stopTrack()");
setFieldValue("control/Control/refreshText","10");
setFieldValue("control/Control/trackdistText", "20");
setFieldValue("control/Control/tracktimeText", "30");
setFieldValue("control/Control/internalExternalGPS","I");
numTracklogPoints = 0;
tracklogCurrentStatus = "";
numTransectPoints = 0;
startTimeTrack() {
stopTrack();
if(isInternalGPSOn() || isExternalGPSOn()) {
tracklogState = "Time";
showToast("Tracklog enabled. Tracklog time interval set to " + getFieldValue("control/Control/tracktimeText") + " seconds.");
startTrackingGPS("time", Integer.parseInt(getFieldValue("control/Control/tracktimeText")), "saveGPSTrack(\"\")");
updateTrackStatus();
} else {
showToast("GPS is not turned on.");
}
}
startDistTrack() {
stopTrack();
if(isInternalGPSOn() || isExternalGPSOn()) {
tracklogState = "Distance";
showToast("Tracklog enabled. Tracklog distance interval set to " + getFieldValue("control/Control/trackdistText") + " metres.");
startTrackingGPS("distance", Integer.parseInt(getFieldValue("control/Control/trackdistText")), "saveGPSTrack(\"\")");
updateTrackStatus();
} else {
showToast("GPS is not turned on.");
}
}
stopTrack() {
stopTrackingGPS();
numTracklogPoints = 0;
numTransectPoints = 0;
tracklogState = "Stopped";
showToast("Tracklog disabled.");
updateTrackStatus();
}
updateTrackStatus() {
if (tracklogState.equals("Time"))
tracklogStatus = "Tracklog Started - Time: "+getFieldValue("control/Control/tracktimeText")+"s";
else if (tracklogState.equals("Distance"))
tracklogStatus = "Tracklog Started - Distance: "+getFieldValue("control/Control/trackdistText")+"m";
else
tracklogStatus = "Tracklog is "+tracklogState;
if (numTracklogPoints > 0)
tracklogStatus += "\nNumber Tracklog Points collected: "+numTracklogPoints;
if (numTransectPoints > 0)
tracklogStatus += "\nNumber current transect Points collected: "+numTransectPoints;
tracklogStatus += "\nCurrent GPS Estimated Accuracy: "+ getGPSEstimatedAccuracy();
setFieldValue("control/Control/trackStatus", tracklogStatus);
setFieldValue("Survey_Unit/Survey_Unit/trackStatus", tracklogStatus);
}
saveGPSTrack(String stateAppend) {
fetchOne("select vocabname from vocabulary where vocabid = "+getFieldValue("user/usertab/Team"), new FetchCallback() {
onFetch(teamQuery) {
position = getGPSPosition();
if (!isGPSOn() || position == null) {
tracklogState = "Bad GPS Fix";
return;
}
numTracklogPoints++;
List attributes = createAttributeList();
attributes.add(createEntityAttribute("Longitude", null, null, "" + position.getLongitude(), null));
attributes.add(createEntityAttribute("Latitude", null, null, "" + position.getLatitude(), null ));
attributes.add(createEntityAttribute("Heading", null, null, "" + getGPSHeading(), null));
attributes.add(createEntityAttribute("Accuracy", null, null, "" + getGPSEstimatedAccuracy(), null));
String date = new java.text.SimpleDateFormat("d-MMM-yy HH:MM:ss z").format(new Date());
attributes.add(createEntityAttribute("Timestamp", null, null, "" + date, null));
attributes.add(createEntityAttribute("TracklogTeam", teamQuery.get(0), null, null, null));
positionProj = getGPSPositionProjected();
Point p = new Point(new MapPos(positionProj.getLongitude(), positionProj.getLatitude()), null, (PointStyle) null, null);
ArrayList l = new ArrayList();
l.add(p);
saveArchEnt(null, "Tracklog", l, attributes, new SaveCallback() {
onSave(uuid, newRecord) {
if (transectEnabled) {
numTransectPoints++;
attributes.add(createEntityAttribute("SUID", null, null, getFieldValue("Survey_Unit/Survey_Unit/Survey_Unit_ID"), null));
attributes.add(createEntityAttribute("Width", null, null, getFieldValue("Survey_Unit/Survey_Unit/Total_Transect_Width"), null));
Boolean end = false;
if(stateAppend.equals("End")) {
end = true;
transectEnabled = false;
}
if (!stateAppend.equals("")) {
attributes.add(createEntityAttribute("State", null, null, stateAppend, null));
stateAppend = "";
}
p = new Point(new MapPos(positionProj.getLongitude(), positionProj.getLatitude()), null, (PointStyle) null, null);
l = new ArrayList();
l.add(p);
saveArchEnt(null, "Transect Point", l, attributes, new SaveCallback() {
onSave(uuid, newRecord) {
transect_id = uuid;
Callable callback = new Callable() {
call() {
if(end) updateCurrentTransect();
}
};
saveEntitiesToRel("TransectSUI", transect_id, survey_unit_id, callback);
}
});
}
updateTrackStatus();
}
});
}
});
}
//Survey Unit Logic
onEvent("Survey_Unit", "show", "addSurveyUnitNavigation();");
onEvent("Survey_Unit/Survey_Unit/Return", "delayclick", "cancelTabGroup(\"Survey_Unit\", false);showTab(\"control/Start\");");
onEvent("Survey_Unit/Survey_Unit/Attach_Photo", "click", "attachPictureTo(\"Survey_Unit/Survey_Unit/Photo\")");
String survey_unit_id = null;
newSurveyUnit() {
if (transectEnabled) {
showWarning("Already tracking!", "You're already in a Transect! Loading it now.");
loadSurveyUnitFrom(survey_unit_id);
return;
}
position = getGPSPosition();
if (!isGPSOn() || position == null) {
showWarning("Warning", "Your GPS is not initialized, you cannot create a Transect until the GPS icon is blue.");
return;
}
newTabGroup("Survey_Unit");
survey_unit_id = null;
numTransectPoints = 0;
fetchOne("select datetime('now', 'localtime');", new FetchCallback() {
onFetch(result) {
setFieldValue("Survey_Unit/Survey_Unit/Timestamp", result.get(0));
}
});
setFieldValue("Survey_Unit/Survey_Unit/Recorded_by", username);
setFieldValue("Survey_Unit/Survey_Unit/Participants", getFieldValue("control/Start/TeamMember"));
setFieldValue("Survey_Unit/Survey_Unit/Number_of_Walkers", getFieldValue("control/Start/Walker"));
setFieldValue("Survey_Unit/Survey_Unit/Survey_Line", getFieldValue("control/Start/SurveyLine"));
setFieldValue("Survey_Unit/Vars/Team", getFieldValue("user/usertab/Team"));
autoNumSurveyUnit();
}
loadTransectFrom(archentid) {
loadSurveyUnitFrom(archentid);
}
loadSurveyUnit() {
survey_unit_id = getListItemValue();
loadSurveyUnitFrom(survey_unit_id);
}
loadSurveyUnitFrom(archentid) {
if (isNull(archentid)) {
showToast("No Transect selected");
return;
}
showTabGroup("Survey_Unit", archentid, new FetchCallback() {
onFetch(result) {
survey_unit_id = archentid;
fetchOne("select surveyUnit.uuid "+
"from " +
"(select uuid, relationshipid " +
"from (select aenttypeid from aenttype where aenttypename = 'Transect') " +
" join latestnondeletedarchent using (aenttypeid) " +
" join latestnondeletedaentreln using (uuid)) surveyUnit " +
"join ((select aenttypeid from aenttype where aenttypename = 'Transect Point') " +
" join latestnondeletedarchent using (aenttypeid) " +
" join latestnondeletedaentreln using (uuid)) transect using (relationshipid) " +
"join (select uuid, measure " +
"from (select aenttypeid from aenttype where aenttypename = 'Transect Point') " +
"join latestnondeletedarchent using (aenttypeid) " +
"join latestnondeletedaentvalue using (uuid) join attributekey using (attributeid) " +
"where attributename = 'State') state on (transect.uuid = state.uuid) " +
"where surveyUnit.uuid = "+survey_unit_id +" "+
"group by surveyUnit.uuid " +
"having min(measure) != 'End' ",
new FetchCallback() {
onFetch(result) {
if(isNull(result)) {
transectEnabled = false;
} else {
transectEnabled = true;
}
}
});
fetchOne("select fname || ' ' || lname from user join archentity using (userid) where uuid = '"+survey_unit_id+"' group by uuid having min(aenttimestamp)",
new FetchCallback() {
onFetch(result) {
setFieldValue("Survey_Unit/Survey_Unit/Recorded_by", result.get(0));
}
});
fetchOne("select datetime(aentTimestamp, 'localtime') from archentity where uuid = '"+survey_unit_id+"' group by uuid having min(aenttimestamp);",
new FetchCallback() {
onFetch(result) {
setFieldValue("Survey_Unit/Survey_Unit/Timestamp", result.get(0));
}
});
saveTabGroup("Survey_Unit", survey_unit_id, null, null, new SaveCallback() {
onSave(uuid, newRecord) {
survey_unit_id = uuid;
}
}, true);
updateTrackStatus();
}
});
}
saveSurveyUnit(Callable callback) {
if (isNull(getFieldValue("Survey_Unit/Survey_Unit/Survey_Unit_ID"))) {
showWarning("Validation Error", "Cannot save Transect without Transect number");
return;
}
positionProj = getGPSPositionProjected();
l = new ArrayList();
if (positionProj != null) {
Point p = new Point(new MapPos(positionProj.getLongitude(), positionProj.getLatitude()), null, (PointStyle) null, null);
l.add(p);
} else {
l = null;
}
saveTabGroup("Survey_Unit", survey_unit_id, l, null, new SaveCallback() {
onSave(uuid, newRecord) {
survey_unit_id = uuid;
if(callback != null) callback.call();
}
});
}
finishSurveyUnit() {
if(!transectEnabled) {
showWarning("Warning","There is no currently active Transect.");
return;
}
position = getGPSPosition();
if (!isGPSOn() || position == null) {
showWarning("Warning", "You have lost your GPS signal, please wait until the GPS icon is blue before you finish you Transect.");
return;
}
saveGPSTrack("End");
}
deleteSurveyUnit() {
if (!isNull(survey_unit_id)) {
showAlert("Confirm Deletion", "Press OK to Delete this Transect!", "reallyDeleteSurveyUnit()", "doNotDelete()");
} else {
cancelTabGroup("Survey_Unit", true);
transectEnabled = false;
}
}
reallyDeleteSurveyUnit() {
fetchAll("select transect.uuid " +
"from " +
"(select uuid, relationshipid " +
"from (select aenttypeid from aenttype where aenttypename = 'Transect') " +
"join latestnondeletedarchent using (aenttypeid) " +
"join latestnondeletedaentreln using (uuid)) surveyUnit " +
"join ((select aenttypeid from aenttype where aenttypename = 'Transect Point') " +
"join latestnondeletedarchent using (aenttypeid) " +
"join latestnondeletedaentreln using (uuid)) transect using (relationshipid) " +
"where surveyUnit.uuid = " + survey_unit_id + ";", new FetchCallback() {
onFetch(transects) {
if(!isNull(transects)) {
for(transect:transects) {
deleteArchEnt(transect.get(0));
}
}
}
});
deleteArchEnt(survey_unit_id, new DeleteCallback() {
onDelete(uuid) {
cancelTabGroup("Survey_Unit", false);
transectEnabled = false;
showTab("control/Start");
}
});
}
addSurveyUnitNavigation() {
removeNavigationButton("duplicate");
removeNavigationButton("new");
removeNavigationButton("close");
removeNavigationButton("delete");
addNavigationButton("duplicate", new ActionButtonCallback() {
actionOnLabel() {
"Duplicate {Survey_Unit}";
}
actionOn() {
if (transectEnabled) {
msgHead = "Unable to Duplicate {Survey_Unit}";
msgBody = "Please complete this {Survey_Unit} before ";
msgBody += "duplicating it.";
showWarning(msgHead, msgBody);
return;
}
showTabGroup("Survey_Unit", survey_unit_id, new FetchCallback() {
onFetch(result) {
disableAutoSave("Survey_Unit");
survey_unit_id = null;
populateCameraPictureGallery("Survey_Unit/Survey_Unit/Photo", new ArrayList());
autoNumSurveyUnit();
msgHead = "Entity Duplicated";
msgBody = "This entity has been duplicated.";
showWarning(msgHead, msgBody);
}
});
}
}, "success");
addNavigationButton("new", new ActionButtonCallback() {
actionOnLabel() {
"New {Survey_Unit}";
}
actionOn() {
newSurveyUnit();
}
}, "success");
addNavigationButton("close", new ActionButtonCallback() {
actionOnLabel() {
"Close {Survey_Unit}";
}
actionOn() {
cancelTabGroup("Survey_Unit", false);
showTab("control/Start");
}
}, "success");
addNavigationButton("delete", new ActionButtonCallback() {
actionOnLabel() {
"Delete {Survey_Unit}";
}
actionOn() {
deleteSurveyUnit();
}
}, "danger");
}
loadSurveyUnitAttributes() {
makeVocab("DropDown", "Survey_Unit/Survey_Unit/Landform", "Landform");
makeVocab("DropDown", "Survey_Unit/Survey_Unit/Average_percentage_of_visibility_of_surface_of_the_landform_area", "Average percentage of visibility of surface of the landform area");
makeVocab("DropDown", "Survey_Unit/Survey_Unit/Average_percentage_of_exposure_of_artefacts", "Average percentage of exposure of artefacts");
makeVocab("DropDown", "Survey_Unit/Survey_Unit/Basic_geomorphic_summary", "Basic geomorphic summary");
makeVocab("DropDown", "Survey_Unit/Survey_Unit/Cobble_distribution", "Cobble distribution");
makeVocab("CheckBoxGroup", "Survey_Unit/Survey_Unit/Sediment_size", "Sediment size");
makeVocab("RadioGroup", "Survey_Unit/Survey_Unit/Sediment_thickness", "Sediment thickness");
makeVocab("DropDown", "Survey_Unit/Vars/Team", "Team");
}
autoNumSurveyUnit() {
fetchOne("select 'T' ||foo as foo " +
"from (select max(cast(substr(measure,2) as integer))+1 as foo " +
"from latestnondeletedaentvalue join attributekey using (attributeid) " +
"where uuid in (select uuid " +
"from latestnondeletedaentvalue ae " +
"join latestnondeletedarchent using (uuid) join aenttype using (aenttypeid) " +
"where aenttypename = 'Transect') " +
"and attributename = 'Transect ID');", new FetchCallback() {
onFetch(result) {
print(result);
if(isNull(result.get(0))) {
setFieldValue("Survey_Unit/Survey_Unit/Survey_Unit_ID", "T1");
} else {
setFieldValue("Survey_Unit/Survey_Unit/Survey_Unit_ID", result.get(0));
}
transectEnabled = true;
saveSurveyUnit(new Callable() {
call() {
saveGPSTrack("Start");
saveTabGroup("Survey_Unit", survey_unit_id, null, null, new SaveCallback() {
onSave(uuid, newRecord) {
survey_unit_id = uuid;
}
}, true);
}
});
}
});
}
//Point of Interest Logic
onEvent("POI", "show", "addPOINavigation();");
onEvent("POI/POI/Take_GPS", "click", "fillInGPS(\"POI/POI/\")");
onEvent("POI/Cobble", "show", "setFieldValue(\"POI/Cobble/POI_ID\", getFieldValue(\"POI/POI/POI_ID\"));");
onEvent("POI/Core", "show", "setFieldValue(\"POI/Core/POI_ID\", getFieldValue(\"POI/POI/POI_ID\"));");
onEvent("POI/POI/Next", "delayclick", "showPOITabs(false);");
onEvent("POI/POI/Attach_Photo", "click", "attachPictureTo(\"POI/POI/Photo\");");
onEvent("POI/Cobble/Return", "delayclick", "cancelTabGroup(\"POI\", false);showTab(\"control/Start\");");
onEvent("POI/Core/Return", "delayclick", "cancelTabGroup(\"POI\", false);showTab(\"control/Start\");");
String poi_id = null;
newPOI() {
newTabGroup("POI");
poi_id = null;
setFieldValue("POI/POI/Recorded_by", username);
fetchOne("select datetime('now', 'localtime');", new FetchCallback() {
onFetch(result) {
setFieldValue("POI/POI/Timestamp", result.get(0));
}
});
fillInGPS("POI/POI/");
setFieldValue("POI/Vars/Team", getFieldValue("user/usertab/Team"));
autoNumPOI();
}
loadTransectObjectFrom(archentid) {
loadPOIFrom(archentid);
}
loadPOI() {
poi_id = getListItemValue();
loadPOIFrom(poi_id);
}
loadPOIFrom(archentid) {
poi_id = archentid;
if (isNull(poi_id)) {
showToast("No Transect Object selected");
return;
}
showTabGroup("POI", poi_id, new FetchCallback() {
onFetch(result) {
fetchOne("select fname || ' ' || lname from user join archentity using (userid) where uuid = '"+poi_id+"' group by uuid having min(aenttimestamp)",
new FetchCallback() {
onFetch(result) {
setFieldValue("POI/POI/Recorded_by", result.get(0));
}
});
fetchOne("select datetime(aentTimestamp, 'localtime') from archentity where uuid = '"+poi_id+"' group by uuid having min(aenttimestamp);",
new FetchCallback() {
onFetch(result) {
setFieldValue("POI/POI/Timestamp", result.get(0));
}
});
showPOITabs(true);
saveTabGroup("POI", poi_id, null, null, new SaveCallback() {
onSave(uuid, newRecord) {
poi_id = uuid;
}
}, true);
}
});
}
savePOI(Callable callback) {
if (isNull(getFieldValue("POI/POI/POI_ID"))) {
showWarning("Validation Error", "Cannot save Transect Object without Transect Object ID");
return;
}
positionProj = getGPSPositionProjected();
l = new ArrayList();
if (positionProj != null) {
Point p = new Point(new MapPos(positionProj.getLongitude(), positionProj.getLatitude()), null, (PointStyle) null, null);
l.add(p);
} else {
l = null;
}
saveTabGroup("POI", poi_id, l, null, new SaveCallback() {
onSave(uuid, newRecord) {
poi_id = uuid;
if(callback != null) callback.call();
}
});
}
deletePOI() {
if (!isNull(poi_id)) {
showAlert("Confirm Deletion", "Press OK to Delete this Transect Object!", "reallyDeletePOI()", "doNotDelete()");
} else {
cancelTabGroup("POI", true);
showTab("control/Start");
}
}
reallyDeletePOI() {
deleteArchEnt(poi_id, new DeleteCallback() {
onDelete(uuid) {
cancelTabGroup("POI", false);
showTab("control/Start");
}
});
}
loadPOIAttributes() {
makeVocab("RadioGroup", "POI/POI/Object", "Object");
makeVocab("DropDown", "POI/POI/Raw_material", "Raw material");
makeVocab("DropDown", "POI/POI/Crystal_Size", "Crystal Size");
makeVocab("DropDown", "POI/POI/Abundance_of_Flaws", "Abundance of Flaws");
makeVocab("DropDown", "POI/Cobble/Angularity", "Angularity");
makeVocab("RadioGroup", "POI/Core/Completeness", "Completeness");
makeVocab("DropDown", "POI/Core/Core_Weathering_stage", "Core Weathering stage");
makeVocab("DropDown", "POI/Core/Flaking_on_Core_Perimeter", "Flaking on Core Perimeter");
makeVocab("DropDown", "POI/Core/Outer_Surface_on_Whole_Core", "Outer Surface (Cortex) on Whole Core");
makeVocab("DropDown", "POI/Core/Outer_Surface_on_Upper_Hemisphere", "Outer Surface (Cortex) on Upper Hemisphere");
makeVocab("DropDown", "POI/Core/Outer_Surface_on_Lower_Hemisphere", "Outer Surface (Cortex) on Lower Hemisphere");
makeVocab("DropDown", "POI/Core/Typology", "Core Typology");
makeVocab("DropDown", "POI/Vars/Team", "Team");
}
addPOINavigation() {
removeNavigationButton("duplicate");
removeNavigationButton("new");
removeNavigationButton("close");
removeNavigationButton("delete");
addNavigationButton("duplicate", new ActionButtonCallback() {
actionOnLabel() {
"Duplicate {POI}";
}
actionOn() {
showTabGroup("POI", poi_id, new FetchCallback() {
onFetch(result) {
disableAutoSave("POI");
poi_id = null;
clearGPS("POI/POI/");
populateCameraPictureGallery("POI/POI/Photo", new ArrayList());
autoNumPOI();
msgHead = "Entity Duplicated";
msgBody = "This entity has been duplicated.";
showWarning(msgHead, msgBody);
}
});
}
}, "success");
addNavigationButton("new", new ActionButtonCallback() {
actionOnLabel() {
"New {POI}";
}
actionOn() {
newPOI();
}
}, "success");
addNavigationButton("close", new ActionButtonCallback() {
actionOnLabel() {
"Close {POI}";
}
actionOn() {
cancelTabGroup("POI", false);
showTab("control/Start");
}
}, "success");
addNavigationButton("delete", new ActionButtonCallback() {
actionOnLabel() {
"Delete {POI}";
}
actionOn() {
deletePOI();
}
}, "danger");
}
showPOITabs(Boolean onLoad) {
fetchOne("select vocabName from vocabulary where vocabid = '"+getFieldValue("POI/POI/Object")+"';", new FetchCallback() {
onFetch(name) {
if (!isNull(name)) {
String vocab = name.get(0);
if (vocab.equals("{Cobble}")) {
cancelTab("POI/Core", false);
showTab("POI/Cobble");