-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodule.xml
303 lines (267 loc) · 9.38 KB
/
module.xml
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
<?xml version="1.0" ?>
<!--@POSTPROC: ./postproc.sh-->
<module>
<Main f="nodata">
<Main>
<User_Name t="dropdown" f="user"/>
<Log_in t="button"/>
<Sign_up t="button"/>
</Main>
<search>
<!--Searching has been modified to include only local records using a-->
<!--combination of code in this file (ctrl+f: "LOCAL RECORDS") and-->
<!--@POSTPROC.-->
</search>
</Main>
<Field>
<Field>
<Crop_Type f="id nocertainty">
<str>
<fmt>{{if $1 then "$1 "}}{{if $2 then "($2) "}}{{if $3 then "$3"}}</fmt>
</str>
<opts>
<opt>Wheat</opt>
<opt>Barley</opt>
<opt>Oats</opt>
<opt>Tricicale</opt>
<opt>Rye</opt>
<opt>Canola</opt>
<opt>Lupins</opt>
<opt>Field Peas</opt>
<opt>Chickpeas</opt>
<opt>Fababeans</opt>
<opt>Lentils</opt>
<opt>Vetch</opt>
<opt>Sunflower</opt>
<opt>Sorghum</opt>
<opt>Cotton</opt>
<opt>Rice</opt>
<opt>Sown legume pasture</opt>
<opt>Volunteer pasture</opt>
<opt>Other</opt>
</opts>
</Crop_Type>
<Year b="decimal" f="id nocertainty"/>
<Month_of_Sowing b="date" f="nocertainty"/>
<Month_of_Harvest t="radio" f="nocertainty">
<opts>
<opt>March</opt>
<opt>April</opt>
<opt>May</opt>
</opts>
</Month_of_Harvest>
<Enterprise t="radio" f="nocertainty">
<opts>
<opt>Yes</opt>
<opt>No</opt>
</opts>
</Enterprise>
<Photo t="camera" f="nocertainty"/>
<Notes f="nocertainty"/>
</Field>
<Location>
<Centre_of_Paddock t="input" f="readonly nocertainty"/>
<Record_Centre_of_Paddock t="button"/>
<Hr_Tag t="webview" f="nolabel"/>
<cols>
<Corner_1 t="input" f="readonly nocertainty"/>
<Corner_2 t="input" f="readonly nocertainty"/>
</cols>
<cols>
<Corner_3 t="input" f="readonly nocertainty"/>
<Corner_4 t="input" f="readonly nocertainty"/>
</cols>
<cols>
<Record_Corner_1 t="button"/>
<Record_Corner_2 t="button"/>
</cols>
<cols>
<Record_Corner_3 t="button"/>
<Record_Corner_4 t="button"/>
</cols>
</Location>
</Field>
<logic><![CDATA[
/******************************* LOCAL RECORDS ********************************/
/* Keeps the list of records user-specific and improves performance. */
/******************************************************************************/
// Create a table in the database for the user-specific records if one doesn't
// exist yet.
String q = "";
q += "CREATE TABLE IF NOT EXISTS localRecord ";
q += "(uuid text primary key, response text);";
fetchOne(q);
// The saveFieldCallback and deleteFieldCallback functions are set as a
// callback to saveTabGroup("Field") and duplicateField() via the @POSTPROC
// script.
saveFieldCallback() {
// Determine/set currentUuid and archEntType
String tabgroup = "Field";
String archEntType = tabgroup.replaceAll("_", " ");
String currentUuid = getUuid(tabgroup);
// Make and execute query to update/insert local record data
String q = "";
q += "REPLACE INTO localRecord(uuid, response) ";
q += " SELECT uuid, response ";
q += " FROM latestNonDeletedArchEntFormattedIdentifiers ";
q += " WHERE uuid = '%s'; ";
q = q.replaceFirst("%s", currentUuid);
fetchOne(q);
}
deleteFieldCallback() {
// Determine/set currentUuid and archEntType
String tabgroup = "Field";
String archEntType = tabgroup.replaceAll("_", " ");
String currentUuid = getUuid(tabgroup);
// Make and execute deletion query
String q = "";
q += "DELETE FROM localRecord ";
q += "WHERE uuid='%s';";
q = q.replaceFirst("%s", currentUuid);
fetchOne(q);
}
addOnEvent("Field", "save", "saveFieldCallback()");
/************************ SAVING POSITIONS TO ARCHENT *************************/
/* Requirement source: Email, "Fwd: my contact details" */
/******************************************************************************/
String c = "click"; // I'm obsessive about an 80-character limit on line width
addOnEvent("Field/Location/Record_Centre_of_Paddock", c, "saveCentre()");
addOnEvent("Field/Location/Record_Corner_1", c, "savecorner1()");
addOnEvent("Field/Location/Record_Corner_2", c, "savecorner2()");
addOnEvent("Field/Location/Record_Corner_3", c, "savecorner3()");
addOnEvent("Field/Location/Record_Corner_4", c, "savecorner4()");
addOnEvent("Main", "show", "initialiseGeometry()");
initialiseGeometry() {
global.centre = null;
global.corner1 = null;
global.corner2 = null;
global.corner3 = null;
global.corner4 = null;
}
makePoint() {
String msgSuccess = "Point taken";
String msgFail = "No GPS signal is present";
Object pos = getGPSPosition();
if (pos == null) {
showToast(msgFail);
return null;
}
Double lat = pos.getLatitude();
Double lon = pos.getLongitude();
MapPos mapPos = new MapPos(lon, lat);
Point pt = new Point(mapPos, null, (PointStyle) null, null);
showToast(msgSuccess);
return pt;
}
saveCentre() { centre = makePoint(); displayGeometry(); saveGeometry(); }
savecorner1() { corner1 = makePoint(); displayGeometry(); saveGeometry(); }
savecorner2() { corner2 = makePoint(); displayGeometry(); saveGeometry(); }
savecorner3() { corner3 = makePoint(); displayGeometry(); saveGeometry(); }
savecorner4() { corner4 = makePoint(); displayGeometry(); saveGeometry(); }
displayGeometry() {
// Inputs to update
refCentre = "Field/Location/Centre_of_Paddock";
refCorner1 = "Field/Location/Corner_1";
refCorner2 = "Field/Location/Corner_2";
refCorner3 = "Field/Location/Corner_3";
refCorner4 = "Field/Location/Corner_4";
// Output geometry to inputs
setFieldValue(refCentre, toString(centre ));
setFieldValue(refCorner1, toString(corner1));
setFieldValue(refCorner2, toString(corner2));
setFieldValue(refCorner3, toString(corner3));
setFieldValue(refCorner4, toString(corner4));
}
String toString(MapPos mp) {
if (mp == null) return "";
double[] coords = mp.toArray();
String x = String.valueOf(coords[0]);
String y = String.valueOf(coords[1]);
String s = "Collected (%s, %s)";
s = s.replaceFirst("%s", x);
s = s.replaceFirst("%s", y);
return s;
}
String toString(Point pt) {
if (pt == null) return "";
return toString(pt.getMapPos());
}
// Puts the geometry into a list, ready for saving to an archent
packFieldGeometry() {
// Put geometry in a list
ArrayList geoList = new ArrayList();
geoList.add(centre );
geoList.add(corner1);
geoList.add(corner2);
geoList.add(corner3);
geoList.add(corner4);
return geoList;
}
// Unpacks geometry of a Field archent to globals. This is set as the callback
// to `loadFieldFrom(String uuid)` via @POSTPROC.
unpackFieldGeometry(geoList) {
valCentre = getFieldValue("Field/Location/Centre_of_Paddock");
valCorner1 = getFieldValue("Field/Location/Corner_1");
valCorner2 = getFieldValue("Field/Location/Corner_2");
valCorner3 = getFieldValue("Field/Location/Corner_3");
valCorner4 = getFieldValue("Field/Location/Corner_4");
// Load the list of points from `geoList` into the correct globals
Integer i = 0;
if (isNull(valCentre )) global.centre = null;
else global.centre = geoList.get(i++);
if (isNull(valCorner1)) global.corner1 = null;
else global.corner1 = geoList.get(i++);
if (isNull(valCorner2)) global.corner2 = null;
else global.corner2 = geoList.get(i++);
if (isNull(valCorner3)) global.corner3 = null;
else global.corner3 = geoList.get(i++);
if (isNull(valCorner4)) global.corner4 = null;
else global.corner4 = geoList.get(i++);
}
saveGeometry() {
// It's probably a good idea to ensure that this is effectively the same as
// the function `onShowField()` which is generated by the autogen.
String tabgroup = "Field";
String callback = "saveFieldCallback();";
saveTabGroup(tabgroup, callback);
}
/************************ DRAW A PRETTY HR TAG IN HTML ************************/
String ref = "Field/Location/Hr_Tag";
String html = "<hr/>";
populateWebViewHtml(ref, html);
/********************************* USER LOGIN *********************************/
// Overrides autogenerated definition
selectUser () {
String userVocabId = getFieldValue(userMenuPath);
if (isNull(userVocabId))
return;
String userQ = "SELECT userid,fname,lname,email,password FROM user " +
"WHERE userid='" + userVocabId + "';";
FetchCallback callback = new FetchCallback() {
onFetch(result) {
user = new User(
result.get(0),
result.get(1),
result.get(2),
result.get(3),
result.get(4)
);
setUser(user);
username = result.get(1) + " " + result.get(2);
}
};
fetchOne(userQ, callback);
}
onClickLogin () {
showVerifyUserDialog("doUserLogin()");
}
onClickSignup () {
showCreateUserDialog("populateListForUsers()");
}
doUserLogin () {
newTab("Field", true);
}
addOnEvent("Main/Main/Log_in", "click", "onClickLogin()");
addOnEvent("Main/Main/Sign_up", "click", "onClickSignup()");
]]></logic>
</module>