@jd-data-limited/easy-fm 1.2.2-alpha6 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +38 -20
- package/package.json +2 -2
- package/prop1.toml +58 -0
- package/prop2.toml +58 -0
- package/src/index.ts +67 -35
- package/test.js +11 -8
- package/test2.js +413 -0
package/dist/index.js
CHANGED
|
@@ -12,6 +12,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
12
12
|
};
|
|
13
13
|
// const fetch = (...args) => import('node-fetch').then(({default: fetch}) => fetch(...args));
|
|
14
14
|
import fetch, { File, FormData } from 'node-fetch';
|
|
15
|
+
import 'node-fetch';
|
|
15
16
|
import { EventEmitter } from "events";
|
|
16
17
|
// @ts-ignore
|
|
17
18
|
import * as moment from "moment";
|
|
@@ -1182,7 +1183,7 @@ export class Database extends EventEmitter {
|
|
|
1182
1183
|
});
|
|
1183
1184
|
}
|
|
1184
1185
|
getLayout(name) {
|
|
1185
|
-
return new
|
|
1186
|
+
return new Layout(this, name);
|
|
1186
1187
|
}
|
|
1187
1188
|
setGlobals(globalFields) {
|
|
1188
1189
|
// console.log({globalFields})
|
|
@@ -1196,7 +1197,7 @@ export class Database extends EventEmitter {
|
|
|
1196
1197
|
resolve();
|
|
1197
1198
|
}
|
|
1198
1199
|
else {
|
|
1199
|
-
reject(
|
|
1200
|
+
reject((res.messages[0].code, res.status, res));
|
|
1200
1201
|
}
|
|
1201
1202
|
})
|
|
1202
1203
|
.catch(e => {
|
|
@@ -1211,9 +1212,9 @@ export class Database extends EventEmitter {
|
|
|
1211
1212
|
this.emit("token_expired");
|
|
1212
1213
|
}
|
|
1213
1214
|
}
|
|
1214
|
-
class
|
|
1215
|
+
export class Layout {
|
|
1215
1216
|
constructor(database, name) {
|
|
1216
|
-
this.records = new
|
|
1217
|
+
this.records = new LayourRecordManager(this);
|
|
1217
1218
|
this.database = database;
|
|
1218
1219
|
this.name = name;
|
|
1219
1220
|
}
|
|
@@ -1275,7 +1276,7 @@ class layout {
|
|
|
1275
1276
|
});
|
|
1276
1277
|
}
|
|
1277
1278
|
}
|
|
1278
|
-
class
|
|
1279
|
+
class LayourRecordManager {
|
|
1279
1280
|
constructor(layout) {
|
|
1280
1281
|
this.layout = layout;
|
|
1281
1282
|
}
|
|
@@ -1310,13 +1311,13 @@ class layoutRecordManager {
|
|
|
1310
1311
|
});
|
|
1311
1312
|
}
|
|
1312
1313
|
range() {
|
|
1313
|
-
return new
|
|
1314
|
+
return new RecordGetRange(this.layout);
|
|
1314
1315
|
}
|
|
1315
1316
|
find() {
|
|
1316
|
-
return new
|
|
1317
|
+
return new Find(this.layout);
|
|
1317
1318
|
}
|
|
1318
1319
|
}
|
|
1319
|
-
class RecordBase extends EventEmitter {
|
|
1320
|
+
export class RecordBase extends EventEmitter {
|
|
1320
1321
|
constructor(layout, recordId, modId = recordId) {
|
|
1321
1322
|
super();
|
|
1322
1323
|
this.portals = [];
|
|
@@ -1332,7 +1333,7 @@ class RecordBase extends EventEmitter {
|
|
|
1332
1333
|
}
|
|
1333
1334
|
processPortalData(portalData) {
|
|
1334
1335
|
for (let item of Object.keys(portalData)) {
|
|
1335
|
-
let _portal = new
|
|
1336
|
+
let _portal = new Portal(this, item);
|
|
1336
1337
|
_portal.records = portalData[item].map(item => {
|
|
1337
1338
|
let fieldData = item;
|
|
1338
1339
|
delete fieldData.recordId;
|
|
@@ -1344,7 +1345,7 @@ class RecordBase extends EventEmitter {
|
|
|
1344
1345
|
}
|
|
1345
1346
|
processFieldData(fieldData) {
|
|
1346
1347
|
return Object.keys(fieldData).map(item => {
|
|
1347
|
-
let _field = new
|
|
1348
|
+
let _field = new Field(this, item, fieldData[item]);
|
|
1348
1349
|
if (!!fieldData[item]) {
|
|
1349
1350
|
if (_field.metadata.result === "timeStamp") {
|
|
1350
1351
|
// @ts-ignore
|
|
@@ -1561,7 +1562,7 @@ class RecordBase extends EventEmitter {
|
|
|
1561
1562
|
return obj;
|
|
1562
1563
|
}
|
|
1563
1564
|
}
|
|
1564
|
-
class LayoutRecord extends RecordBase {
|
|
1565
|
+
export class LayoutRecord extends RecordBase {
|
|
1565
1566
|
constructor(layout, recordId, modId = recordId, fieldData = {}, portalData = null) {
|
|
1566
1567
|
super(layout, recordId, modId);
|
|
1567
1568
|
this.fields = this.processFieldData(fieldData);
|
|
@@ -1571,7 +1572,7 @@ class LayoutRecord extends RecordBase {
|
|
|
1571
1572
|
}
|
|
1572
1573
|
}
|
|
1573
1574
|
}
|
|
1574
|
-
class
|
|
1575
|
+
export class Field {
|
|
1575
1576
|
constructor(record, id, contents) {
|
|
1576
1577
|
this.record = record;
|
|
1577
1578
|
this.id = id;
|
|
@@ -1682,13 +1683,13 @@ class field {
|
|
|
1682
1683
|
});
|
|
1683
1684
|
}
|
|
1684
1685
|
}
|
|
1685
|
-
class
|
|
1686
|
+
export class Portal {
|
|
1686
1687
|
constructor(record, name) {
|
|
1687
1688
|
this.record = record;
|
|
1688
1689
|
this.name = name;
|
|
1689
1690
|
}
|
|
1690
1691
|
}
|
|
1691
|
-
class PortalRecord extends RecordBase {
|
|
1692
|
+
export class PortalRecord extends RecordBase {
|
|
1692
1693
|
constructor(record, portal, recordId, modId = recordId, fieldData = {}) {
|
|
1693
1694
|
super(record.layout, recordId, modId);
|
|
1694
1695
|
this.portal = portal;
|
|
@@ -1712,7 +1713,7 @@ class PortalRecord extends RecordBase {
|
|
|
1712
1713
|
return res;
|
|
1713
1714
|
}
|
|
1714
1715
|
}
|
|
1715
|
-
class
|
|
1716
|
+
export class RecordGetOperation {
|
|
1716
1717
|
constructor(layout) {
|
|
1717
1718
|
this.limit = 100;
|
|
1718
1719
|
this.limitPortals = [];
|
|
@@ -1752,11 +1753,11 @@ class recordGetOperation {
|
|
|
1752
1753
|
return this;
|
|
1753
1754
|
}
|
|
1754
1755
|
}
|
|
1755
|
-
class
|
|
1756
|
+
export class RecordGetRange extends RecordGetOperation {
|
|
1756
1757
|
constructor(layout) {
|
|
1757
1758
|
super(layout);
|
|
1758
1759
|
}
|
|
1759
|
-
generateQueryParams() {
|
|
1760
|
+
generateQueryParams(extraBody = {}) {
|
|
1760
1761
|
let params = [];
|
|
1761
1762
|
if (this.limit !== 100)
|
|
1762
1763
|
params.push("_limit=" + this.limit);
|
|
@@ -1773,15 +1774,32 @@ class recordGetRange extends recordGetOperation {
|
|
|
1773
1774
|
params.push("_limit." + item.portal.name.replace(/[^0-9A-z]/g, "") + "=" + item.limit);
|
|
1774
1775
|
}
|
|
1775
1776
|
}
|
|
1777
|
+
if (extraBody.scripts) {
|
|
1778
|
+
if (extraBody.scripts.prerequest) {
|
|
1779
|
+
params.push("script.prerequest=" + extraBody.scripts.prerequest.name);
|
|
1780
|
+
if (extraBody.scripts.prerequest.param)
|
|
1781
|
+
params.push("script.prerequest.param=" + extraBody.scripts.prerequest.param);
|
|
1782
|
+
}
|
|
1783
|
+
if (extraBody.scripts.presort) {
|
|
1784
|
+
params.push("script.presort=" + extraBody.scripts.presort.name);
|
|
1785
|
+
if (extraBody.scripts.presort.param)
|
|
1786
|
+
params.push("script.presort.param=" + extraBody.scripts.presort.param);
|
|
1787
|
+
}
|
|
1788
|
+
if (extraBody.scripts.after) {
|
|
1789
|
+
params.push("script=" + extraBody.scripts.after.name);
|
|
1790
|
+
if (extraBody.scripts.after.param)
|
|
1791
|
+
params.push("script.param=" + extraBody.scripts.after.param);
|
|
1792
|
+
}
|
|
1793
|
+
}
|
|
1776
1794
|
if (params.length === 0)
|
|
1777
1795
|
return "";
|
|
1778
1796
|
return "?" + params.join("&");
|
|
1779
1797
|
}
|
|
1780
|
-
run() {
|
|
1798
|
+
run(extraBody = {}) {
|
|
1781
1799
|
return new Promise((resolve, reject) => {
|
|
1782
1800
|
// console.log(this.#toObject())
|
|
1783
1801
|
this.layout.getLayoutMeta().then(() => {
|
|
1784
|
-
return this.layout.database.apiRequest(`${this.layout.endpoint}/records${this.generateQueryParams()}`, {
|
|
1802
|
+
return this.layout.database.apiRequest(`${this.layout.endpoint}/records${this.generateQueryParams(extraBody)}`, {
|
|
1785
1803
|
method: "GET"
|
|
1786
1804
|
});
|
|
1787
1805
|
})
|
|
@@ -1806,7 +1824,7 @@ class recordGetRange extends recordGetOperation {
|
|
|
1806
1824
|
});
|
|
1807
1825
|
}
|
|
1808
1826
|
}
|
|
1809
|
-
class
|
|
1827
|
+
export class Find extends RecordGetOperation {
|
|
1810
1828
|
constructor(layout) {
|
|
1811
1829
|
super(layout);
|
|
1812
1830
|
this.queries = [];
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jd-data-limited/easy-fm",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"dependencies": {
|
|
5
5
|
"@types/btoa": "^1.2.3",
|
|
6
6
|
"@types/events": "^3.0.0",
|
|
7
7
|
"moment": "^2.29.4",
|
|
8
|
-
"node-fetch": "
|
|
8
|
+
"node-fetch": "3.2.8",
|
|
9
9
|
"typescript": "^4.9.4"
|
|
10
10
|
},
|
|
11
11
|
"type": "module",
|
package/prop1.toml
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
#Minecraft server properties
|
|
2
|
+
#Wed May 03 20:32:16 AEST 2023
|
|
3
|
+
allow-flight=false
|
|
4
|
+
allow-nether=true
|
|
5
|
+
broadcast-console-to-ops=true
|
|
6
|
+
broadcast-rcon-to-ops=true
|
|
7
|
+
difficulty=easy
|
|
8
|
+
enable-command-block=false
|
|
9
|
+
enable-jmx-monitoring=false
|
|
10
|
+
enable-query=false
|
|
11
|
+
enable-rcon=false
|
|
12
|
+
enable-status=true
|
|
13
|
+
enforce-secure-profile=true
|
|
14
|
+
enforce-whitelist=false
|
|
15
|
+
entity-broadcast-range-percentage=100
|
|
16
|
+
force-gamemode=false
|
|
17
|
+
function-permission-level=2
|
|
18
|
+
gamemode=survival
|
|
19
|
+
generate-structures=true
|
|
20
|
+
generator-settings={}
|
|
21
|
+
hardcore=false
|
|
22
|
+
hide-online-players=false
|
|
23
|
+
level-name=world
|
|
24
|
+
level-seed=
|
|
25
|
+
level-type=minecraft\:normal
|
|
26
|
+
max-chained-neighbor-updates=1000000
|
|
27
|
+
max-players=20
|
|
28
|
+
max-threads=6
|
|
29
|
+
max-tick-time=-1
|
|
30
|
+
max-world-size=29999984
|
|
31
|
+
motd=A Minecraft Server
|
|
32
|
+
network-compression-threshold=256
|
|
33
|
+
online-mode=false
|
|
34
|
+
op-permission-level=4
|
|
35
|
+
player-idle-timeout=0
|
|
36
|
+
prevent-proxy-connections=false
|
|
37
|
+
previews-chat=false
|
|
38
|
+
pvp=true
|
|
39
|
+
query.port=25565
|
|
40
|
+
rate-limit=0
|
|
41
|
+
rcon.password=
|
|
42
|
+
rcon.port=25575
|
|
43
|
+
require-resource-pack=false
|
|
44
|
+
resource-pack=
|
|
45
|
+
resource-pack-prompt=
|
|
46
|
+
resource-pack-sha1=
|
|
47
|
+
server-ip=119.252.189.11
|
|
48
|
+
server-port=27002
|
|
49
|
+
simulation-distance=10
|
|
50
|
+
spawn-animals=true
|
|
51
|
+
spawn-monsters=true
|
|
52
|
+
spawn-npcs=true
|
|
53
|
+
spawn-protection=16
|
|
54
|
+
sync-chunk-writes=false
|
|
55
|
+
text-filtering-config=
|
|
56
|
+
use-native-transport=true
|
|
57
|
+
view-distance=10
|
|
58
|
+
white-list=false
|
package/prop2.toml
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
#Minecraft server properties
|
|
2
|
+
#Wed May 03 12:46:20 CEST 2023
|
|
3
|
+
allow-flight=false
|
|
4
|
+
allow-nether=true
|
|
5
|
+
broadcast-console-to-ops=true
|
|
6
|
+
broadcast-rcon-to-ops=true
|
|
7
|
+
difficulty=easy
|
|
8
|
+
enable-command-block=true
|
|
9
|
+
enable-jmx-monitoring=false
|
|
10
|
+
enable-query=true
|
|
11
|
+
enable-rcon=false
|
|
12
|
+
enable-status=true
|
|
13
|
+
enforce-secure-profile=true
|
|
14
|
+
enforce-whitelist=false
|
|
15
|
+
entity-broadcast-range-percentage=100
|
|
16
|
+
force-gamemode=false
|
|
17
|
+
function-permission-level=2
|
|
18
|
+
gamemode=survival
|
|
19
|
+
generate-structures=true
|
|
20
|
+
generator-settings={}
|
|
21
|
+
hardcore=false
|
|
22
|
+
hide-online-players=false
|
|
23
|
+
level-name=world
|
|
24
|
+
level-seed=
|
|
25
|
+
level-type=minecraft\:normal
|
|
26
|
+
max-chained-neighbor-updates=1000000
|
|
27
|
+
max-players=100
|
|
28
|
+
max-tick-time=60000
|
|
29
|
+
max-world-size=29999984
|
|
30
|
+
motd=4vNBdJ
|
|
31
|
+
network-compression-threshold=256
|
|
32
|
+
online-mode=true
|
|
33
|
+
op-permission-level=4
|
|
34
|
+
player-idle-timeout=0
|
|
35
|
+
prevent-proxy-connections=false
|
|
36
|
+
previews-chat=false
|
|
37
|
+
pvp=true
|
|
38
|
+
query.port=41305
|
|
39
|
+
rate-limit=0
|
|
40
|
+
rcon.password=
|
|
41
|
+
rcon.port=25575
|
|
42
|
+
require-resource-pack=false
|
|
43
|
+
resource-pack=
|
|
44
|
+
resource-pack-prompt=
|
|
45
|
+
resource-pack-sha1=
|
|
46
|
+
server-ip=
|
|
47
|
+
server-port=41305
|
|
48
|
+
simulation-distance=10
|
|
49
|
+
snooper-enabled=false
|
|
50
|
+
spawn-animals=true
|
|
51
|
+
spawn-monsters=true
|
|
52
|
+
spawn-npcs=true
|
|
53
|
+
spawn-protection=16
|
|
54
|
+
sync-chunk-writes=true
|
|
55
|
+
text-filtering-config=
|
|
56
|
+
use-native-transport=true
|
|
57
|
+
view-distance=10
|
|
58
|
+
white-list=false
|
package/src/index.ts
CHANGED
|
@@ -58,11 +58,28 @@ interface loginOptionsClaris {
|
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
interface limitPortalsInterface {
|
|
61
|
-
portal:
|
|
61
|
+
portal: Portal,
|
|
62
62
|
offset: number,
|
|
63
63
|
limit: number
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
+
interface extraBodyOptions {
|
|
67
|
+
scripts?: {
|
|
68
|
+
prerequest?: {
|
|
69
|
+
name: string,
|
|
70
|
+
param?: string
|
|
71
|
+
},
|
|
72
|
+
presort?: {
|
|
73
|
+
name: string,
|
|
74
|
+
param?: string
|
|
75
|
+
},
|
|
76
|
+
after?: {
|
|
77
|
+
name: string,
|
|
78
|
+
param?: string
|
|
79
|
+
},
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
66
83
|
// @ts-ignore
|
|
67
84
|
const errs = [
|
|
68
85
|
{
|
|
@@ -1290,8 +1307,8 @@ export class Database extends EventEmitter {
|
|
|
1290
1307
|
return (data as any)
|
|
1291
1308
|
}
|
|
1292
1309
|
|
|
1293
|
-
getLayout(name):
|
|
1294
|
-
return new
|
|
1310
|
+
getLayout(name): Layout {
|
|
1311
|
+
return new Layout(this, name)
|
|
1295
1312
|
}
|
|
1296
1313
|
|
|
1297
1314
|
setGlobals(globalFields): Promise<void> {
|
|
@@ -1305,7 +1322,8 @@ export class Database extends EventEmitter {
|
|
|
1305
1322
|
if (res.messages[0].code === "0") {
|
|
1306
1323
|
resolve()
|
|
1307
1324
|
} else {
|
|
1308
|
-
reject(
|
|
1325
|
+
reject(
|
|
1326
|
+
(res.messages[0].code, res.status, res))
|
|
1309
1327
|
}
|
|
1310
1328
|
})
|
|
1311
1329
|
.catch(e => {
|
|
@@ -1323,9 +1341,9 @@ export class Database extends EventEmitter {
|
|
|
1323
1341
|
}
|
|
1324
1342
|
}
|
|
1325
1343
|
|
|
1326
|
-
class
|
|
1344
|
+
export class Layout {
|
|
1327
1345
|
readonly database: Database;
|
|
1328
|
-
readonly records = new
|
|
1346
|
+
readonly records = new LayourRecordManager(this)
|
|
1329
1347
|
protected name: string;
|
|
1330
1348
|
metadata: any;
|
|
1331
1349
|
|
|
@@ -1355,7 +1373,7 @@ class layout {
|
|
|
1355
1373
|
/**
|
|
1356
1374
|
* @deprecated use layout.records.find() instead
|
|
1357
1375
|
*/
|
|
1358
|
-
newFind():
|
|
1376
|
+
newFind(): Find {
|
|
1359
1377
|
return this.records.find()
|
|
1360
1378
|
}
|
|
1361
1379
|
|
|
@@ -1381,7 +1399,7 @@ class layout {
|
|
|
1381
1399
|
})
|
|
1382
1400
|
}
|
|
1383
1401
|
|
|
1384
|
-
public getLayoutMeta(): Promise<
|
|
1402
|
+
public getLayoutMeta(): Promise<Layout | FMError> {
|
|
1385
1403
|
return new Promise((resolve, reject) => {
|
|
1386
1404
|
if (this.metadata) {
|
|
1387
1405
|
resolve(this.metadata)
|
|
@@ -1397,10 +1415,10 @@ class layout {
|
|
|
1397
1415
|
}
|
|
1398
1416
|
}
|
|
1399
1417
|
|
|
1400
|
-
class
|
|
1401
|
-
readonly layout:
|
|
1418
|
+
class LayourRecordManager {
|
|
1419
|
+
readonly layout: Layout
|
|
1402
1420
|
|
|
1403
|
-
constructor(layout:
|
|
1421
|
+
constructor(layout: Layout) {
|
|
1404
1422
|
this.layout = layout
|
|
1405
1423
|
}
|
|
1406
1424
|
|
|
@@ -1437,20 +1455,20 @@ class layoutRecordManager {
|
|
|
1437
1455
|
}
|
|
1438
1456
|
|
|
1439
1457
|
range() {
|
|
1440
|
-
return new
|
|
1458
|
+
return new RecordGetRange(this.layout)
|
|
1441
1459
|
}
|
|
1442
1460
|
|
|
1443
|
-
find():
|
|
1444
|
-
return new
|
|
1461
|
+
find(): Find {
|
|
1462
|
+
return new Find(this.layout)
|
|
1445
1463
|
}
|
|
1446
1464
|
}
|
|
1447
1465
|
|
|
1448
|
-
class RecordBase extends EventEmitter {
|
|
1449
|
-
readonly layout:
|
|
1466
|
+
export class RecordBase extends EventEmitter {
|
|
1467
|
+
readonly layout: Layout;
|
|
1450
1468
|
public recordId: number;
|
|
1451
1469
|
modId: number;
|
|
1452
|
-
fields:
|
|
1453
|
-
portals:
|
|
1470
|
+
fields: Field[];
|
|
1471
|
+
portals: Portal[] = [];
|
|
1454
1472
|
protected portalData: any[];
|
|
1455
1473
|
|
|
1456
1474
|
constructor(layout, recordId, modId = recordId) {
|
|
@@ -1470,7 +1488,7 @@ class RecordBase extends EventEmitter {
|
|
|
1470
1488
|
|
|
1471
1489
|
protected processPortalData(portalData): void {
|
|
1472
1490
|
for (let item of Object.keys(portalData)) {
|
|
1473
|
-
let _portal = new
|
|
1491
|
+
let _portal = new Portal(this, item)
|
|
1474
1492
|
_portal.records = portalData[item].map(item => {
|
|
1475
1493
|
let fieldData = item;
|
|
1476
1494
|
delete fieldData.recordId;
|
|
@@ -1481,9 +1499,9 @@ class RecordBase extends EventEmitter {
|
|
|
1481
1499
|
}
|
|
1482
1500
|
}
|
|
1483
1501
|
|
|
1484
|
-
processFieldData(fieldData):
|
|
1502
|
+
processFieldData(fieldData): Field[] {
|
|
1485
1503
|
return Object.keys(fieldData).map(item => {
|
|
1486
|
-
let _field = new
|
|
1504
|
+
let _field = new Field(this, item, fieldData[item])
|
|
1487
1505
|
if (!!fieldData[item]) {
|
|
1488
1506
|
if (_field.metadata.result === "timeStamp") {
|
|
1489
1507
|
// @ts-ignore
|
|
@@ -1708,8 +1726,8 @@ class RecordBase extends EventEmitter {
|
|
|
1708
1726
|
return obj
|
|
1709
1727
|
}
|
|
1710
1728
|
}
|
|
1711
|
-
class LayoutRecord extends RecordBase {
|
|
1712
|
-
portals:
|
|
1729
|
+
export class LayoutRecord extends RecordBase {
|
|
1730
|
+
portals: Portal[];
|
|
1713
1731
|
|
|
1714
1732
|
constructor(layout, recordId, modId = recordId, fieldData = {}, portalData = null) {
|
|
1715
1733
|
super(layout, recordId, modId);
|
|
@@ -1721,7 +1739,7 @@ class LayoutRecord extends RecordBase {
|
|
|
1721
1739
|
}
|
|
1722
1740
|
}
|
|
1723
1741
|
|
|
1724
|
-
class
|
|
1742
|
+
export class Field {
|
|
1725
1743
|
record: RecordBase;
|
|
1726
1744
|
id: number;
|
|
1727
1745
|
private _value: string | number | Date;
|
|
@@ -1842,7 +1860,7 @@ class field {
|
|
|
1842
1860
|
}
|
|
1843
1861
|
}
|
|
1844
1862
|
|
|
1845
|
-
class
|
|
1863
|
+
export class Portal {
|
|
1846
1864
|
readonly record: RecordBase;
|
|
1847
1865
|
readonly name: string;
|
|
1848
1866
|
public records: PortalRecord[];
|
|
@@ -1853,8 +1871,8 @@ class portal {
|
|
|
1853
1871
|
}
|
|
1854
1872
|
}
|
|
1855
1873
|
|
|
1856
|
-
class PortalRecord extends RecordBase {
|
|
1857
|
-
readonly portal:
|
|
1874
|
+
export class PortalRecord extends RecordBase {
|
|
1875
|
+
readonly portal: Portal;
|
|
1858
1876
|
|
|
1859
1877
|
constructor(record, portal, recordId, modId = recordId, fieldData = {}) {
|
|
1860
1878
|
super(record.layout, recordId, modId);
|
|
@@ -1883,8 +1901,8 @@ class PortalRecord extends RecordBase {
|
|
|
1883
1901
|
}
|
|
1884
1902
|
}
|
|
1885
1903
|
|
|
1886
|
-
class
|
|
1887
|
-
protected layout:
|
|
1904
|
+
export class RecordGetOperation {
|
|
1905
|
+
protected layout: Layout
|
|
1888
1906
|
protected limit: number = 100
|
|
1889
1907
|
protected scripts: object
|
|
1890
1908
|
protected sort: object[]
|
|
@@ -1905,7 +1923,7 @@ class recordGetOperation {
|
|
|
1905
1923
|
addToPortalLimit() will adjust the results of the get request so that if a layout has multiple portals in it,
|
|
1906
1924
|
only data from the specified ones will be read. This may help reduce load on your FileMaker API
|
|
1907
1925
|
*/
|
|
1908
|
-
addToPortalLimit(portal:
|
|
1926
|
+
addToPortalLimit(portal: Portal, offset = 0, limit = 100) {
|
|
1909
1927
|
if (offset < 0) throw "Portal offset cannot be less than 0"
|
|
1910
1928
|
this.limitPortals.push({portal, offset, limit})
|
|
1911
1929
|
return this
|
|
@@ -1929,12 +1947,12 @@ class recordGetOperation {
|
|
|
1929
1947
|
}
|
|
1930
1948
|
}
|
|
1931
1949
|
|
|
1932
|
-
class
|
|
1950
|
+
export class RecordGetRange extends RecordGetOperation {
|
|
1933
1951
|
constructor(layout) {
|
|
1934
1952
|
super(layout)
|
|
1935
1953
|
}
|
|
1936
1954
|
|
|
1937
|
-
private generateQueryParams() {
|
|
1955
|
+
private generateQueryParams(extraBody: extraBodyOptions = {}) {
|
|
1938
1956
|
let params = []
|
|
1939
1957
|
if (this.limit !== 100) params.push("_limit=" + this.limit)
|
|
1940
1958
|
if (this.offset !== 0) params.push("_offset=" + this.offset)
|
|
@@ -1946,16 +1964,30 @@ class recordGetRange extends recordGetOperation {
|
|
|
1946
1964
|
if (item.limit !== 100) params.push("_limit." + item.portal.name.replace(/[^0-9A-z]/g, "") + "=" + item.limit)
|
|
1947
1965
|
}
|
|
1948
1966
|
}
|
|
1967
|
+
if (extraBody.scripts) {
|
|
1968
|
+
if (extraBody.scripts.prerequest) {
|
|
1969
|
+
params.push("script.prerequest=" + extraBody.scripts.prerequest.name)
|
|
1970
|
+
if (extraBody.scripts.prerequest.param) params.push("script.prerequest.param=" + extraBody.scripts.prerequest.param)
|
|
1971
|
+
}
|
|
1972
|
+
if (extraBody.scripts.presort) {
|
|
1973
|
+
params.push("script.presort=" + extraBody.scripts.presort.name)
|
|
1974
|
+
if (extraBody.scripts.presort.param) params.push("script.presort.param=" + extraBody.scripts.presort.param)
|
|
1975
|
+
}
|
|
1976
|
+
if (extraBody.scripts.after) {
|
|
1977
|
+
params.push("script=" + extraBody.scripts.after.name)
|
|
1978
|
+
if (extraBody.scripts.after.param) params.push("script.param=" + extraBody.scripts.after.param)
|
|
1979
|
+
}
|
|
1980
|
+
}
|
|
1949
1981
|
|
|
1950
1982
|
if (params.length === 0) return ""
|
|
1951
1983
|
return "?" + params.join("&")
|
|
1952
1984
|
}
|
|
1953
1985
|
|
|
1954
|
-
run(): Promise<RecordBase[]> {
|
|
1986
|
+
run(extraBody: extraBodyOptions = {}): Promise<RecordBase[]> {
|
|
1955
1987
|
return new Promise((resolve, reject) => {
|
|
1956
1988
|
// console.log(this.#toObject())
|
|
1957
1989
|
this.layout.getLayoutMeta().then(() => {
|
|
1958
|
-
return this.layout.database.apiRequest(`${this.layout.endpoint}/records${this.generateQueryParams()}`, {
|
|
1990
|
+
return this.layout.database.apiRequest(`${this.layout.endpoint}/records${this.generateQueryParams(extraBody)}`, {
|
|
1959
1991
|
method: "GET"
|
|
1960
1992
|
})
|
|
1961
1993
|
})
|
|
@@ -1979,7 +2011,7 @@ class recordGetRange extends recordGetOperation {
|
|
|
1979
2011
|
}
|
|
1980
2012
|
}
|
|
1981
2013
|
|
|
1982
|
-
class
|
|
2014
|
+
export class Find extends RecordGetOperation {
|
|
1983
2015
|
protected queries: object[]
|
|
1984
2016
|
|
|
1985
2017
|
constructor(layout) {
|
package/test.js
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* Copyright (c) 2023. See LICENSE file for more information
|
|
3
3
|
*/
|
|
4
|
+
process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = 0;
|
|
4
5
|
|
|
5
|
-
import FileMakerHost from "./
|
|
6
|
+
import FileMakerHost from "./dist/index.js";
|
|
6
7
|
|
|
7
8
|
let host = new FileMakerHost("https://lab.farmmedix.com", 0, false)
|
|
8
9
|
let database = host.database({
|
|
9
10
|
database: "Snapshot_2",
|
|
10
11
|
credentials: {
|
|
11
12
|
method: "filemaker",
|
|
12
|
-
username: "
|
|
13
|
-
password: "
|
|
13
|
+
username: "Developer",
|
|
14
|
+
password: "1df e53 0tx"
|
|
14
15
|
},
|
|
15
16
|
externalSources: []
|
|
16
17
|
})
|
|
@@ -19,11 +20,13 @@ async function setup() {
|
|
|
19
20
|
// console.log(await host.getMetadata())
|
|
20
21
|
// console.log(host.timezoneOffset)
|
|
21
22
|
await database.login()
|
|
22
|
-
let layout = database.getLayout("
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
let layout = database.getLayout("Archive")
|
|
24
|
+
layout.records.find()
|
|
25
|
+
.addRequests({"__PrimaryKey": "=BAB9264A-38A5-4C6F-8CEE-3788931EC269"})
|
|
26
|
+
.run()
|
|
27
|
+
.then(records => {
|
|
28
|
+
console.log(records[0].getField("Container").value)
|
|
29
|
+
})
|
|
27
30
|
// await layout.getLayoutMeta()
|
|
28
31
|
// console.log(layout.metadata)
|
|
29
32
|
|
package/test2.js
ADDED
|
@@ -0,0 +1,413 @@
|
|
|
1
|
+
const date = new Date();
|
|
2
|
+
let [month, day, year] = [
|
|
3
|
+
date.getMonth() + 1,
|
|
4
|
+
date.getDate(),
|
|
5
|
+
date.getFullYear(),
|
|
6
|
+
];
|
|
7
|
+
|
|
8
|
+
if (day < 10) day = '0' + day;
|
|
9
|
+
if (month < 10) month = '0' + month;
|
|
10
|
+
|
|
11
|
+
console.log(window.location.href);
|
|
12
|
+
var currloc = window.location.href.split('&fname=');
|
|
13
|
+
var location_split = currloc[0].split('&location=');
|
|
14
|
+
console.log(decodeURIComponent(location_split[1]).replace('&', '& '));
|
|
15
|
+
|
|
16
|
+
var loc = location_split[0].replace('https://www.farmmedix.com/milk-sampling-consent/?location=', '');
|
|
17
|
+
console.log(decodeURIComponent(loc));
|
|
18
|
+
|
|
19
|
+
$('#date-today').html(day + '/' + month + '/' + year);
|
|
20
|
+
$('#owner_name').html(decodeURIComponent(urlParam("fname")) + ' ' + decodeURI(urlParam("lname")));
|
|
21
|
+
$('#farm-business-name').html('');
|
|
22
|
+
$('#owner-phone').html('');
|
|
23
|
+
$('#owner-email').html(decodeURIComponent(urlParam("email")))
|
|
24
|
+
|
|
25
|
+
$("input[name=hidden_2]").val(day + '/' + month + '/' + year);
|
|
26
|
+
$("input[name=hidden]").val(decodeURIComponent(urlParam("fname")));
|
|
27
|
+
$("input[name=hidden_11]").val(decodeURIComponent(urlParam("lname")));
|
|
28
|
+
$("input[name=hidden_1]").val(decodeURIComponent(urlParam("business_name")));
|
|
29
|
+
$("input[name=hidden_4]").val(decodeURIComponent(urlParam("email")));
|
|
30
|
+
$("input[name=hidden_3]").val(decodeURIComponent(urlParam("phone")));
|
|
31
|
+
$("input[name=hidden_10]").val(decodeURIComponent(loc));
|
|
32
|
+
$("input[name=hidden_12]").val(decodeURIComponent(urlParam("role")));
|
|
33
|
+
$("input[name=show_staph]").val(decodeURIComponent(urlParam("show_staph")));
|
|
34
|
+
|
|
35
|
+
$("input[name=show_staph]").trigger("change");
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
var html = '<strong>Farm/Business Name</strong>: ' + decodeURI(urlParam("business_name"));
|
|
39
|
+
html += '<br><strong>Location</strong>: ' + decodeURIComponent(loc);
|
|
40
|
+
html += '<br><strong>First Name</strong>: ' + decodeURI(urlParam("fname"));
|
|
41
|
+
html += '<br><strong>Last Name</strong>: ' + decodeURI(urlParam("lname"));
|
|
42
|
+
html += '<br><strong>Email</strong>: ' + decodeURI(urlParam("email"));
|
|
43
|
+
html += '<br><strong>Phone</strong>: ' + decodeURI(urlParam("phone"));
|
|
44
|
+
html += '<br><strong>Role</strong>: ' + decodeURI(urlParam("role"));
|
|
45
|
+
|
|
46
|
+
var allsuppliers = decodeURIComponent(urlParam("suppliers")).replace(' ', '').split(',');
|
|
47
|
+
//console.log(decodeURIComponent(allsuppliers));
|
|
48
|
+
|
|
49
|
+
var lis = '';
|
|
50
|
+
var list_num = 13;
|
|
51
|
+
var extralistnum = 1;
|
|
52
|
+
var suppliers_all = '';
|
|
53
|
+
var output = [];
|
|
54
|
+
var newsupp = [];
|
|
55
|
+
var suppliers_obj = {};
|
|
56
|
+
|
|
57
|
+
var extra_html = '';
|
|
58
|
+
|
|
59
|
+
$.each(allsuppliers, function( k, v ) {
|
|
60
|
+
//newsupp.push(v.split('-'));
|
|
61
|
+
var o = v.split('-');
|
|
62
|
+
suppliers_obj[o[0]] += decodeURIComponent(o[1]) + ', ';
|
|
63
|
+
|
|
64
|
+
extra_html += '<div style="width: 100%; display: inline-block; color: #000"><strong>'+v.replace('-', ' ')+'</strong></div><div style="width: 100%">';
|
|
65
|
+
extra_html += '<div><div style="float: left; margin-right: 10px;"><div class="ff-el-input--label ff-el-is-required asterisk-right"><label>Number of animals</label></div><input id="extra-list-animal" class="ff-el-form-control" required="" type="number" data-animal="'+extralistnum+'" aria-required="true" /></div>';
|
|
66
|
+
extra_html += '<div style="float: left; margin-right: 10px;"><div class="ff-el-input--label ff-el-is-required asterisk-right"><label>Number of Clinical Mastitis Cases</label></div><input id="extra-list-mastitis" class="ff-el-form-control" required="" type="number" data-mastitis="'+extralistnum+'" aria-required="true" /></div>';
|
|
67
|
+
extra_html += '<div style="float: left; margin-right: 10px;"><div class="ff-el-input--label ff-el-is-required asterisk-right"><label>Bulk tank SCC level</label></div><input id="extra-list-scc" class="ff-el-form-control" required="" type="number" data-scc="'+extralistnum+'" aria-required="true" /></div>';
|
|
68
|
+
extra_html += '<div style="float: left; margin-right: 10px;"><div class="ff-el-input--label"><label>Comment on SCC and Mastitis Cases</label></div><textarea id="extra-list-comment" class="ff-el-form-control" data-comment="'+extralistnum+'"></textarea></div>';
|
|
69
|
+
extra_html += '</div></div>';
|
|
70
|
+
|
|
71
|
+
extralistnum++;
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
$('#extra-fields').html(extra_html);
|
|
75
|
+
|
|
76
|
+
$.each(suppliers_obj, function( i, v ) {
|
|
77
|
+
//console.log(i, v)
|
|
78
|
+
//html += '<br><strong>Supplier '+(i+1)+'</strong>: ' + v.replace("-", " - ");
|
|
79
|
+
suppliers_all += '<span style="color: #000000;">- <b>'+ i + ' ' + v.replace('undefined', '').slice(0, -2) +'</b></span><br>';
|
|
80
|
+
$('input[name=hidden_'+list_num+']').val('- ' + i + ' ' + v.replace('undefined', '').slice(0, -2));
|
|
81
|
+
if(i != 'Fonterra'){
|
|
82
|
+
$('input[name="has_nonfonterra"').val('yes');
|
|
83
|
+
}
|
|
84
|
+
list_num++;
|
|
85
|
+
//extralistnum++;
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
$('#loc').html(decodeURIComponent(loc))
|
|
89
|
+
$('#suppliers-all').html('');
|
|
90
|
+
$('#total-samples').html('');
|
|
91
|
+
$('#role').html($("input[name=hidden_4]").val());
|
|
92
|
+
$('#user-full-name').html(decodeURIComponent(urlParam("fname")) + ' ' + decodeURIComponent(urlParam("lname")));
|
|
93
|
+
|
|
94
|
+
$(document).on('change', '#extra-list-animal', function(){
|
|
95
|
+
var data_id = $(this).data('animal');
|
|
96
|
+
$('[name="num_animals_'+data_id+'"]').val($(this).val());
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
$(document).on('change', '#extra-list-mastitis', function(){
|
|
100
|
+
var data_id = $(this).data('mastitis');
|
|
101
|
+
$('[name="num_clinical_mastisis_'+data_id+'"]').val($(this).val());
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
$(document).on('change', '#extra-list-scc', function(){
|
|
105
|
+
var data_id = $(this).data('scc');
|
|
106
|
+
$('[name="bulk_tank_scc_'+data_id+'"]').val($(this).val());
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
$(document).on('change', '#extra-list-comment', function(){
|
|
110
|
+
var data_id = $(this).data('rolomment');
|
|
111
|
+
$('[name="comment_scc_'+data_id+'"]').val($(this).val());
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
//$("input[name=hidden_6]").val(allsuppliers.length);
|
|
115
|
+
|
|
116
|
+
$('#preview').html(html)
|
|
117
|
+
|
|
118
|
+
function urlParam(name) {
|
|
119
|
+
var results = (new RegExp("[\\?&]" + name + "=([^&#]*)")).exec(window.location.href);
|
|
120
|
+
if (results == null) return null;
|
|
121
|
+
else return results[1] || 0;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
/*** added ***/
|
|
125
|
+
|
|
126
|
+
var settings = {
|
|
127
|
+
"url": "https://snapshot-2-testenv-snpgtklz4a-ts.a.run.app/api/v2/farms/simple",
|
|
128
|
+
"method": "GET",
|
|
129
|
+
"timeout": 0,
|
|
130
|
+
"headers": {
|
|
131
|
+
"Authorization": "Bot L9lrcc3z+MqZFq2QWfiAuvNkbWyjisIA2BehMuLcw9Q=",
|
|
132
|
+
"Content-Type": "application/json",
|
|
133
|
+
"Cookie": "GAESA=CoQBMDAxMjE3ODliM2MyNzI0MDMzZTE1Yjk2OTFmOWRiNWNlODliMjhmMWU3YTI2ZjFmYTJiNGE5OGE0ZDBlMjQ1NDhkY2U5MWI5NGM2NzgxOTFmZjBjMTk5NDU4MTgwMTBjYjMwMzNiOWFlYTdkMjk5Zjc3ZDUyYjI4M2UzNjE3OWRmYzYyEMS59cD3MA"
|
|
134
|
+
},
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
var allSuppliers = [];
|
|
138
|
+
var suppliersName = [];
|
|
139
|
+
|
|
140
|
+
$.ajax(settings).done(function (response) {
|
|
141
|
+
//console.log(response);
|
|
142
|
+
var ff_11_dropdown_2_val = '';
|
|
143
|
+
//allSuppliers.push(response);
|
|
144
|
+
var voidSuppliers = ["TEST SUPPLIER", "UNKNOWN SUPPLIER", ""];
|
|
145
|
+
$.map(response, function(val) {
|
|
146
|
+
allSuppliers.push({supplier_name: val.supplierName, id: val.supplierNumber, name: val.bussinessName});
|
|
147
|
+
if($.inArray(val.supplierName, suppliersName) === -1) {
|
|
148
|
+
if($.inArray(val.supplierName, voidSuppliers) === -1){
|
|
149
|
+
suppliersName.push(val.supplierName);
|
|
150
|
+
ff_11_dropdown_2_val += '<option value="'+val.supplierName+'">'+val.supplierName+'</option>';
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
$('#ff_11_dropdown_2').html(ff_11_dropdown_2_val);
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
//console.log(allSuppliers);
|
|
159
|
+
|
|
160
|
+
function urlParam(name) {
|
|
161
|
+
var results = (new RegExp("[\\?&]" + name + "=([^&#]*)")).exec(window.location.href);
|
|
162
|
+
if (results == null) return null;
|
|
163
|
+
else return results[1] || 0;
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
let location = decodeURI(urlParam("location"));
|
|
167
|
+
let formnum = 1;
|
|
168
|
+
|
|
169
|
+
$('.ff-el-form-check').eq(0).find('input').click();
|
|
170
|
+
$('#ff_11_input_text').val(decodeURI(urlParam("farm_name")) === 'null' ? '' : decodeURI(urlParam("farm_name")));
|
|
171
|
+
$('#ff_11_dropdown option[value="'+location+'"]').attr("selected","selected");
|
|
172
|
+
$('#ff_11_names_first_name_').val(decodeURI(urlParam("fname")) === 'null' ? '' : decodeURI(urlParam("fname")));
|
|
173
|
+
$('#ff_11_names_last_name_').val(decodeURI(urlParam("lname")) === 'null' ? '' : decodeURI(urlParam("lname")));
|
|
174
|
+
$('#ff_11_email').val(decodeURI(urlParam("email")) === 'null' ? '' : decodeURI(urlParam("email")));
|
|
175
|
+
|
|
176
|
+
$('#add-supplier').click(function(e){
|
|
177
|
+
e.preventDefault();
|
|
178
|
+
console.log('new supplier click');
|
|
179
|
+
formnum++;
|
|
180
|
+
var newfrm = '<div data-name="ff_cn_id_7" class="ff-t-container ff-column-container ff_columns_total_2 supplier_container"><div class="ff-t-cell ff-t-column-1" style="flex-basis: 50%;"><div class="ff-el-group"><div class="ff-el-input--label ff-el-is-required asterisk-right"><label for="ff_11_dropdown_2" aria-label="Supplier Name 1">Supplier Name '+formnum+'</label> </div><div class="ff-el-input--content"><select name="dropdown_2" id="ff_11_dropdown_2" class="ff-el-form-control" data-name="dropdown_2" data-calc_value="0" aria-invalid="false" aria-required="true"><option value="">– Select Supplier '+ formnum +' –</option><option value="Fonterra">Fonterra</option><option value="Arrabawn">Arrabawn</option><option value="Aurivo">Aurivo</option><option value="Carbery">Carbery</option><option value="Dairy Goat Coop">Dairy Goat Coop</option><option value="Dairygold">Dairygold</option><option value="Green Valley Dairies">Green Valley Dairies</option><option value="Mataura Valley Milk">Mataura Valley Milk</option><option value="Maui">Maui</option><option value="Miraka">Miraka</option><option value="Open Country">Open Country</option><option value="Organic Dairy Hub">Organic Dairy Hub</option><option value="Synlait">Synlait</option><option value="Tatua">Tatua</option><option value="Waiau">Waiau</option><option value="Westland">Westland</option></select></div></div></div><div class="ff-t-cell ff-t-column-2" style="flex-basis: 50%;"><div class="ff-el-group"><div class="ff-el-input--label ff-el-is-required asterisk-right"><label for="ff_11_numeric-field" aria-label="Supplier Number 1">Supplier Number '+formnum+'</label> <span id="remove-supplier">x remove</span></div><div class="ff-el-input--content"><input type="number" name="numeric-field" id="ff_11_numeric-field" class="ff-el-form-control" data-name="numeric-field" inputmode="numeric" step="any" aria-invalid="false" aria-required="true"><div id="res_dropdown"></div></div></div></div></div>';
|
|
181
|
+
if (decodeURIComponent(urlParam("show_staph")) !== "true") newfrm += "<div style='display:none;'>"
|
|
182
|
+
newfrm += '<div data-name="ff_cn_id_6" class="ff-t-container ff-column-container ff_columns_total_4 div4 "><div class="ff-t-cell ff-t-column-1" style="flex-basis: 25%;"><div class="ff-el-group"><div class="ff-el-input--label ff-el-is-required asterisk-right"><label for="number_of_animals_'+formnum+'" aria-label="Number of Animals">Number of Animals</label> </div><div class="ff-el-input--content"><input data-name="num_animals_'+formnum+'" type="number" name="number_of_animals_'+formnum+'" id="extra" class="ff-el-form-control" inputmode="numeric" step="any" aria-invalid="false" aria-required="true"><div id="res_dropdown2"></div></div></div></div><div class="ff-t-cell ff-t-column-2" style="flex-basis: 25%;"><div class="ff-el-group"><div class="ff-el-input--label ff-el-is-required asterisk-right"><label for="number_of_clinicalmastisis_'+formnum+'" aria-label="Number of Clinical Mastitis Cases">Number of Clinical Mastitis Cases</label> </div><div class="ff-el-input--content"><input type="number" name="number_of_clinicalmastisis_'+formnum+'" id="extra" class="ff-el-form-control" data-name="num_clinical_mastisis_'+formnum+'" inputmode="numeric" step="any" aria-invalid="false" aria-required="true"></div></div></div><div class="ff-t-cell ff-t-column-3" style="flex-basis: 25%;"><div class="ff-el-group"><div class="ff-el-input--label ff-el-is-required asterisk-right"><label for="bulk_tank_level'+formnum+'" aria-label="Bulk tank SCC level">Bulk tank SCC level</label> </div><div class="ff-el-input--content"><input type="number" name="bulk_tank_level'+formnum+'" id="extra" class="ff-el-form-control" data-name="bulk_tank_scc_'+formnum+'" inputmode="numeric" step="any" aria-invalid="false" aria-required="true"></div></div></div><div class="ff-t-cell ff-t-column-4" style="flex-basis: 25%;"><div class="ff-el-group"><div class="ff-el-input--label asterisk-right"><label for="comment_scc_mastisis'+formnum+'" aria-label="Comment on SCC and Mastitis Cases">Comment on SCC and Mastitis Cases</label> </div><div class="ff-el-input--content"><textarea aria-invalid="false" aria-required="false" name="comment_scc_mastisis'+formnum+'" id="extra" class="ff-el-form-control" rows="3" cols="2" data-name="comment_scc_'+formnum+'"></textarea></div></div></div></div>';
|
|
183
|
+
if (decodeURIComponent(urlParam("show_staph")) !== "true") newfrm += "</div>"
|
|
184
|
+
|
|
185
|
+
$('.div4:last').after('<div class="newdiv" id="form-container-'+formnum+'"></div>');
|
|
186
|
+
|
|
187
|
+
//$(this).prepend(newfrm)
|
|
188
|
+
$(document).find("#form-container-"+formnum).html(newfrm);
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
$(document).on('click', '#remove-supplier', function(){
|
|
192
|
+
var p = $(this).parent().parent().parent().parent().parent();
|
|
193
|
+
formnum -= 1;
|
|
194
|
+
p.remove();
|
|
195
|
+
console.log(p);
|
|
196
|
+
fill_suppliers();
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
//disabled
|
|
200
|
+
$(document).on('click', '#ff_11_numeric-field_disabled', function(){
|
|
201
|
+
var supplier_name = $(this).parent().parent().parent().parent().find('#ff_11_dropdown_2').val();
|
|
202
|
+
var result = [];
|
|
203
|
+
var res = '';
|
|
204
|
+
var el = $(this);
|
|
205
|
+
if(supplier_name !== ''){
|
|
206
|
+
console.log('here' + supplier_name);
|
|
207
|
+
|
|
208
|
+
$.map(allSuppliers, function(val) {
|
|
209
|
+
console.log(val.supplier_name);
|
|
210
|
+
if(supplier_name == val.supplier_name){
|
|
211
|
+
result.push({id: val.id, milk_supplier: val.name});
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
$.map(result, function(value) {
|
|
217
|
+
console.log(value)
|
|
218
|
+
res += '<div id="milk-supplier" data-id="'+value.id+'">'+value.id+'-'+value.milk_supplier+'</div>';
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
console.log(result);
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
el.next('#res_dropdown').html(res).css('display', 'block');
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
});
|
|
230
|
+
$('#ff_11_numeric-field').after('<div id="res_dropdown"></div>');
|
|
231
|
+
|
|
232
|
+
var result = {};
|
|
233
|
+
var result2 = {};
|
|
234
|
+
var allsuppliers = [];
|
|
235
|
+
|
|
236
|
+
function fill_suppliers(){
|
|
237
|
+
let suppliers_arr = [];
|
|
238
|
+
let supplier_arr2 = [{}];
|
|
239
|
+
$(".supplier_container").each(function() {
|
|
240
|
+
var supplier = $(this).find('#ff_11_dropdown_2').val();
|
|
241
|
+
var supplier_id = $(this).find('#ff_11_numeric-field').val();
|
|
242
|
+
suppliers_arr.push(supplier+'-'+supplier_id);
|
|
243
|
+
supplier_arr2.push({supplier: supplier, supplier_id: supplier_id});
|
|
244
|
+
});
|
|
245
|
+
allsuppliers = [];
|
|
246
|
+
allsuppliers.push([suppliers_arr]);
|
|
247
|
+
$('#total-samples').html(suppliers_arr.length);
|
|
248
|
+
$('[name="hidden_6"]').val(suppliers_arr.length);
|
|
249
|
+
|
|
250
|
+
//console.log(supplier_arr2)
|
|
251
|
+
grouped = [];
|
|
252
|
+
|
|
253
|
+
supplier_arr2.forEach(function (hash) {
|
|
254
|
+
return function (o) {
|
|
255
|
+
if (!hash[o.supplier]) {
|
|
256
|
+
hash[o.supplier] = { supplier: o.supplier, supplier_id: '' };
|
|
257
|
+
grouped.push(hash[o.supplier]);
|
|
258
|
+
}
|
|
259
|
+
if(o.supplier !== undefined){
|
|
260
|
+
hash[o.supplier].supplier_id += o.supplier_id + '|';
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
};
|
|
264
|
+
}(Object.create(null)));
|
|
265
|
+
|
|
266
|
+
var grouped_suppliers = '';
|
|
267
|
+
$('#suppliers-all').html('');
|
|
268
|
+
//console.log('grouped')
|
|
269
|
+
let groupnum = 13;
|
|
270
|
+
grouped.forEach(function (item, index) {
|
|
271
|
+
//console.log(item.supplier);
|
|
272
|
+
if(item.supplier !== undefined){
|
|
273
|
+
grouped_suppliers += '- ' + item.supplier + ' ' + item.supplier_id.substring(0, item.supplier_id.length-1).replace('|', ', ') + '\r\n<br>';
|
|
274
|
+
$('[name="hidden_'+groupnum+'"]').val(' - ' + item.supplier + ' ' + item.supplier_id.substring(0, item.supplier_id.length-1).replace('|', ', '));
|
|
275
|
+
groupnum++;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
//console.log(grouped_suppliers);
|
|
281
|
+
$('#suppliers-all').html(grouped_suppliers);
|
|
282
|
+
//$('[name="hidden_suppliers"]').val(allsuppliers);
|
|
283
|
+
//$('[name="suppliers_field"]').val(grouped_suppliers);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
$(document).on('blur', '#ff_11_numeric-field', function(){
|
|
287
|
+
fill_suppliers();
|
|
288
|
+
//console.log(allsuppliers)
|
|
289
|
+
$('[id=res_dropdown]').slideUp();
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
$(document).on('keyup', '#ff_11_numeric-field_disabled', function(){
|
|
293
|
+
res = '';
|
|
294
|
+
var i = $(this).val();
|
|
295
|
+
var supplier_name = $(this).parent().parent().parent().parent().find('#ff_11_dropdown_2').val();
|
|
296
|
+
result = [];
|
|
297
|
+
$.map(suppliers_json[supplier_name], function(val) {
|
|
298
|
+
result.push(val);
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
$.map(result, function(value) {
|
|
302
|
+
|
|
303
|
+
if(i != ''){
|
|
304
|
+
var varid = value.id;
|
|
305
|
+
var regex = new RegExp(this.value);
|
|
306
|
+
res += varid.includes(i) ? '<div id="milk-supplier" data-id="'+value.id+'">'+value.id+'-'+value.milk_supplier+'</div>' : "";
|
|
307
|
+
}
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
if(i !== ''){
|
|
311
|
+
$(this).next('#res_dropdown').show();
|
|
312
|
+
$(this).next('#res_dropdown').html(res);
|
|
313
|
+
}else{
|
|
314
|
+
$(this).next('#res_dropdown').hide();
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
res = '';
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
$(document).on('click', '#milk-supplier', function(){
|
|
321
|
+
console.log('supplier' + $(this).data('id'));
|
|
322
|
+
$(this).parent().parent().find('#ff_11_numeric-field').val($(this).data('id'));
|
|
323
|
+
$(this).parent().parent().find('#ff_11_numeric-field').focus();
|
|
324
|
+
$('[id=res_dropdown]').slideUp();
|
|
325
|
+
})
|
|
326
|
+
|
|
327
|
+
$('#ff_11_numeric-field_1').after('<div id="res_dropdown2"></div>');
|
|
328
|
+
|
|
329
|
+
$("#ff_11_dropdown_3").change(function(){
|
|
330
|
+
result2 = [];
|
|
331
|
+
$.map(suppliers_json[this.value], function(val) {
|
|
332
|
+
result2.push(val);
|
|
333
|
+
});
|
|
334
|
+
console.log(result2);
|
|
335
|
+
console.log(result2);
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
var all_suppliers = {};
|
|
339
|
+
|
|
340
|
+
$('#ff_11_numeric-field_1').on('keyup', function(){
|
|
341
|
+
res2 = '';
|
|
342
|
+
var i = $(this).val();
|
|
343
|
+
$.map(result2, function(value) {
|
|
344
|
+
//res += val.id +'-'+ val.milk_supplier + '\r\n';
|
|
345
|
+
//console.log(1);
|
|
346
|
+
if(i !== ''){
|
|
347
|
+
var varid = value.id;
|
|
348
|
+
var regex = new RegExp(this.value);
|
|
349
|
+
//console.log(varid);
|
|
350
|
+
//console.log(this.value);
|
|
351
|
+
|
|
352
|
+
res2 += varid.includes(i) ? '<div>'+value.id+'-'+value.milk_supplier+'</div>' : "";
|
|
353
|
+
$('#res_dropdown2').css('display', 'block');
|
|
354
|
+
|
|
355
|
+
var last_supplier = $(this).prev('#ff_11_dropdown_2').val();
|
|
356
|
+
//console.log(last_supplier);
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
|
|
360
|
+
});
|
|
361
|
+
if(i !== ''){
|
|
362
|
+
$('#res_dropdown2').html(res2);
|
|
363
|
+
}else{
|
|
364
|
+
$('#res_dropdown2').css('display', 'none');
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
res = ''
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
$('#ff_11_dropdown_2').change(function(){
|
|
371
|
+
$('#ff_11_numeric-field').val('');
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
$('#ff_11_phone_1').on('keyup', function(){
|
|
375
|
+
$('#owner-phone').html($(this).val());
|
|
376
|
+
$("input[name=hidden_3]").val($(this).val());
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
$('#ff_11_input_text').on('keyup', function(){
|
|
380
|
+
$('#farm-business-name').html($(this).val());
|
|
381
|
+
$("input[name=hidden_1]").val($(this).val());
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
// $('#ff_11_dropdown_1').change(function(){
|
|
385
|
+
// $('#role').html($(this).val());
|
|
386
|
+
// $("input[name=hidden_12]").val($(this).val());
|
|
387
|
+
// });
|
|
388
|
+
|
|
389
|
+
$(document).on('change', '#extra', function(){
|
|
390
|
+
var name = $(this).data('name');
|
|
391
|
+
var value = $(this).val();
|
|
392
|
+
console.log(name, value);
|
|
393
|
+
$('input[name="'+name+'"]').val(value);
|
|
394
|
+
});
|
|
395
|
+
|
|
396
|
+
$('#ff_11_number_of_animals_1').change(function(){
|
|
397
|
+
var value = $(this).val();
|
|
398
|
+
$('input[name="num_animals_1"]').val(value);
|
|
399
|
+
});
|
|
400
|
+
$('#ff_11_number_of_clinicalmastisis_1').change(function(){
|
|
401
|
+
var value = $(this).val();
|
|
402
|
+
$('input[name="num_clinical_mastisis_1"]').val(value);
|
|
403
|
+
});
|
|
404
|
+
$('#ff_11_bulk_tank_level2').change(function(){
|
|
405
|
+
var value = $(this).val();
|
|
406
|
+
$('input[name="bulk_tank_scc_1"]').val(value);
|
|
407
|
+
});
|
|
408
|
+
$('#ff_11_comment_scc_mastisis2').change(function(){
|
|
409
|
+
var value = $(this).val();
|
|
410
|
+
$('input[name="comment_scc_1"]').val(value);
|
|
411
|
+
});
|
|
412
|
+
|
|
413
|
+
|