@jd-data-limited/easy-fm 3.0.6 → 3.0.8

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/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@jd-data-limited/easy-fm",
3
- "version": "3.0.6",
3
+ "version": "3.0.8",
4
4
  "dependencies": {
5
5
  "@types/btoa": "^1.2.3",
6
6
  "@types/events": "^3.0.0",
7
7
  "moment": "^2.29.4",
8
8
  "node-fetch": "3.2.8",
9
- "typescript": "^4.9.4"
9
+ "typescript": "^4.9.4",
10
+ "ytdl-core": "^4.11.4"
10
11
  },
11
12
  "type": "module",
12
13
  "main": "src/index.js",
package/src/index.js CHANGED
@@ -1300,7 +1300,12 @@ export class Layout {
1300
1300
  })
1301
1301
  .then(res => {
1302
1302
  if (res.messages[0].code === "0") {
1303
- resolve(res.response);
1303
+ let error = parseInt(res.response.scriptError);
1304
+ let msg = {
1305
+ scriptError: error ? new FMError(error, 200, res, trace) : undefined,
1306
+ scriptResult: res.response.scriptResult
1307
+ };
1308
+ resolve(msg);
1304
1309
  }
1305
1310
  else {
1306
1311
  // console.log(res)
@@ -1390,7 +1395,7 @@ export class RecordBase extends EventEmitter {
1390
1395
  if (!!fieldData[item]) {
1391
1396
  if (_field.metadata.result === "timeStamp") {
1392
1397
  // @ts-ignore
1393
- let date = moment.default(fieldData[item], this.layout.database.host.metadata.productInfo.timeStampFormat)
1398
+ let date = moment.default(fieldData[item], this.layout.database.host.metadata.productInfo.timeStampFormat.replace("dd", "DD"))
1394
1399
  .utcOffset(this.layout.database.host.timezoneOffset, true)
1395
1400
  .local();
1396
1401
  _field.set(date.toDate());
@@ -1398,7 +1403,7 @@ export class RecordBase extends EventEmitter {
1398
1403
  }
1399
1404
  else if (_field.metadata.result === "time") {
1400
1405
  // @ts-ignore
1401
- let date = moment.default(fieldData[item], this.layout.database.host.metadata.productInfo.timeFormat)
1406
+ let date = moment.default(fieldData[item], this.layout.database.host.metadata.productInfo.timeFormat.replace("dd", "DD"))
1402
1407
  .utcOffset(this.layout.database.host.timezoneOffset, true)
1403
1408
  .local();
1404
1409
  _field.set(date.toDate());
@@ -1406,7 +1411,7 @@ export class RecordBase extends EventEmitter {
1406
1411
  }
1407
1412
  else if (_field.metadata.result === "date") {
1408
1413
  // @ts-ignore
1409
- let date = moment.default(fieldData[item], this.layout.database.host.metadata.productInfo.dateFormat)
1414
+ let date = moment.default(fieldData[item], this.layout.database.host.metadata.productInfo.dateFormat.replace("dd", "DD"))
1410
1415
  .utcOffset(this.layout.database.host.timezoneOffset, true)
1411
1416
  .local();
1412
1417
  _field.set(date.toDate());
package/src/index.ts CHANGED
@@ -1146,6 +1146,11 @@ interface FMHostMetadata {
1146
1146
  }
1147
1147
  }
1148
1148
 
1149
+ export interface ScriptResult {
1150
+ scriptError?: FMError,
1151
+ scriptResult?: string
1152
+ }
1153
+
1149
1154
  export interface ContainerBufferResult {
1150
1155
  buffer: Buffer,
1151
1156
  mime: string,
@@ -1441,9 +1446,9 @@ export class Layout {
1441
1446
  return this.records.find()
1442
1447
  }
1443
1448
 
1444
- runScript(script): Promise<string> {
1449
+ runScript(script): Promise<ScriptResult> {
1445
1450
  let trace = new Error()
1446
- return new Promise(async (resolve, reject) => {
1451
+ return new Promise(async (resolve, reject) => {
1447
1452
  let url = `${this.endpoint}/script/${encodeURIComponent(script.name)}`
1448
1453
  if (script.parameter) url += "?script.param=" + encodeURIComponent(script.parameter)
1449
1454
  this.database.apiRequest(url, {
@@ -1452,7 +1457,12 @@ export class Layout {
1452
1457
  })
1453
1458
  .then(res => {
1454
1459
  if (res.messages[0].code === "0") {
1455
- resolve(res.response)
1460
+ let error = parseInt(res.response.scriptError)
1461
+ let msg: ScriptResult = {
1462
+ scriptError: error ? new FMError(error, 200, res, trace) : undefined,
1463
+ scriptResult: res.response.scriptResult
1464
+ }
1465
+ resolve(msg)
1456
1466
  }
1457
1467
  else {
1458
1468
  // console.log(res)
@@ -1560,7 +1570,7 @@ export class RecordBase extends EventEmitter {
1560
1570
  if (!!fieldData[item]) {
1561
1571
  if (_field.metadata.result === "timeStamp") {
1562
1572
  // @ts-ignore
1563
- let date = moment.default(fieldData[item], this.layout.database.host.metadata.productInfo.timeStampFormat)
1573
+ let date = moment.default(fieldData[item], this.layout.database.host.metadata.productInfo.timeStampFormat.replace("dd", "DD"))
1564
1574
  .utcOffset(this.layout.database.host.timezoneOffset, true)
1565
1575
  .local()
1566
1576
  _field.set(date.toDate())
@@ -1569,7 +1579,7 @@ export class RecordBase extends EventEmitter {
1569
1579
  }
1570
1580
  else if (_field.metadata.result === "time") {
1571
1581
  // @ts-ignore
1572
- let date = moment.default(fieldData[item], this.layout.database.host.metadata.productInfo.timeFormat)
1582
+ let date = moment.default(fieldData[item], this.layout.database.host.metadata.productInfo.timeFormat.replace("dd", "DD"))
1573
1583
  .utcOffset(this.layout.database.host.timezoneOffset, true)
1574
1584
  .local()
1575
1585
  _field.set(date.toDate())
@@ -1577,7 +1587,7 @@ export class RecordBase extends EventEmitter {
1577
1587
  }
1578
1588
  else if (_field.metadata.result === "date") {
1579
1589
  // @ts-ignore
1580
- let date = moment.default(fieldData[item], this.layout.database.host.metadata.productInfo.dateFormat)
1590
+ let date = moment.default(fieldData[item], this.layout.database.host.metadata.productInfo.dateFormat.replace("dd", "DD"))
1581
1591
  .utcOffset(this.layout.database.host.timezoneOffset, true)
1582
1592
  .local()
1583
1593
  _field.set(date.toDate())
package/test2.cjs ADDED
@@ -0,0 +1,62 @@
1
+ const ytdl = require('ytdl-core');
2
+ const path = require('path');
3
+ const fs = require('fs');
4
+
5
+
6
+ // To get your YouTube cookie
7
+ // - navigate to YouTube in a web browser
8
+ // - open up dev tools (opt+cmd+j on mac)
9
+ // - go to the network tab
10
+ // - click on a request on the left
11
+ // - scroll down to "Request Headers"
12
+ // - find the "cookie" header and copy its entire contents
13
+ const videoID = 'WAw1g2tHN3s';
14
+
15
+ const outputName = 'video.mp4';
16
+ const outputPath = path.resolve(__dirname, outputName);
17
+ let last_pecent
18
+ async function run() {
19
+ await downloadVideo(videoID, "highestaudio", outputPath + ".audio.mp4")
20
+ }
21
+
22
+ function downloadVideo(id, format, file) {
23
+ return new Promise(async (resolve, reject) => {
24
+ const video = await ytdl(videoID, {filter: "audioandvideo"});
25
+ const save_stream = fs.createWriteStream(file)
26
+
27
+ video.on('info', info => {
28
+ console.log('title:', info.videoDetails.title);
29
+ console.log('rating:', info.player_response.videoDetails.averageRating);
30
+ console.log('uploaded by:', info.videoDetails.author.name);
31
+ });
32
+
33
+ video.on('progress', (chunkLength, downloaded, total) => {
34
+ const percent = Math.round((downloaded / total) * 100) / 100;
35
+ if (percent !== last_pecent) {
36
+ console.log(format + ' - downloading', `${(percent * 100)}%`);
37
+ last_pecent = percent
38
+ }
39
+ });
40
+
41
+ video.on('end', () => {
42
+ console.log('saved to', outputName);
43
+ });
44
+
45
+ video.on("error", (e) => {
46
+ console.log("ERROR:", e)
47
+ })
48
+
49
+ save_stream.on("close", (e) => {
50
+ console.log("Stream closed")
51
+ resolve()
52
+ })
53
+
54
+ video.pipe(save_stream);
55
+
56
+ setTimeout(() => {
57
+ console.log("HI!")
58
+ }, 600000000)
59
+ })
60
+ }
61
+
62
+ run()
package/test2.js DELETED
@@ -1,413 +0,0 @@
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
-