Spaces:
Build error
Build error
edit spinner etc
Browse files- static/frontend.js +64 -16
static/frontend.js
CHANGED
@@ -1,3 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
//display the pop up with more information
|
2 |
function onClickMore(string){
|
3 |
document.getElementById(string).style.display ='block';
|
@@ -7,18 +57,17 @@
|
|
7 |
function onOut(string){
|
8 |
document.getElementById(string).style.display ='none';
|
9 |
}
|
10 |
-
|
11 |
async function getResponse(url, user_query){
|
12 |
try {
|
13 |
-
//let predictions = await fetch(url,{
|
14 |
-
// method: 'GET',
|
15 |
-
// body: JSON.stringify({'user_query': user_query})
|
16 |
-
//});
|
17 |
let final_url = url + '?user_query=' + user_query
|
18 |
console.log(final_url)
|
|
|
19 |
let predictions = await fetch(final_url);
|
20 |
console.log(predictions)
|
|
|
21 |
return predictions.json()
|
|
|
22 |
} catch (error) {
|
23 |
console.log(error)
|
24 |
}
|
@@ -26,32 +75,28 @@
|
|
26 |
|
27 |
//when retrieve is clicked
|
28 |
async function onSubmit(){
|
29 |
-
|
30 |
-
|
|
|
31 |
|
32 |
let user_query = document.getElementById("exampleFormControlInput1").value
|
33 |
-
console.log(user_query)
|
34 |
// let url_query = "http://10.27.32.183:8111/predict"
|
35 |
-
|
36 |
if (user_query != ''){
|
37 |
document.getElementById("spinner").style.display = 'block';
|
38 |
|
39 |
-
console.log("making predictions")
|
40 |
let url_query = "/predict"
|
41 |
let predictions = await getResponse(url_query, user_query)
|
42 |
-
console.log("displaying predictions")
|
43 |
|
44 |
document.getElementById("spinner").style.display = 'none';
|
45 |
-
document.getElementById("grey-container").className = 'album py-5 bg-light';
|
46 |
|
47 |
let response = predictions['predictions']
|
48 |
-
console.log(response)
|
49 |
-
|
50 |
//loop through number of results
|
51 |
html = ''
|
52 |
var w = 0
|
53 |
for(let i=0; i < response.length; i++){
|
54 |
-
|
55 |
html += '<div class="row g-4 m-2" id="predictions">';
|
56 |
html += '<div class="col-6">';
|
57 |
html += '<div class="card border-primary mb-3">';
|
@@ -151,7 +196,7 @@
|
|
151 |
html += '<div style="margin-bottom: 15px" class="accordion" id="accordionPanelsStayOpenExample"' + response[i]["id"] + key + '>'; //1
|
152 |
|
153 |
for (let x=0; x < usages_arr.length; x++){
|
154 |
-
let pattern = usages_arr[x].split("
|
155 |
html += '<div data-bs-toggle="collapse" data-bs-target="#patternCollapse' + response[i]["id"] + key + x + '">'; //2
|
156 |
html += '<div class="accordion-item">'; //3
|
157 |
html += '<h2 class="accordion-header" id="panelsStayOpen-heading' + response[i]["id"] + key +'">';
|
@@ -221,4 +266,7 @@
|
|
221 |
//append footer to allow going back to the top
|
222 |
document.getElementById("footer").innerHTML = (html2);
|
223 |
}
|
|
|
|
|
|
|
224 |
}
|
|
|
1 |
+
// const response = [
|
2 |
+
// {
|
3 |
+
// "id": 446929723,
|
4 |
+
// "library_name": "DHT20",
|
5 |
+
// "hw_config": {
|
6 |
+
// "protocol": "I2C",
|
7 |
+
// "pin_connection_from_hw_to_arduino": {
|
8 |
+
// "arduino_mega": [["SDA", "21"], ["SCL", "21"]],
|
9 |
+
// "arduino_uno": [["SDA", "A4"], ["SCL", "A5"]],
|
10 |
+
// }
|
11 |
+
// },
|
12 |
+
// "usage_patterns": {
|
13 |
+
// "DHT20": [
|
14 |
+
// "DHT20.begin DHT20.lastRead DHT20.read DHT20.getHumidity DHT20.getTemperature",
|
15 |
+
// "DHT20.begin DHT20.read DHT20.getHumidity DHT20.getTemperature",
|
16 |
+
// "DHT20.begin DHT20.read DHT20.getHumidity"
|
17 |
+
// ],
|
18 |
+
// "DHT12": [
|
19 |
+
// "DHT12.begin",
|
20 |
+
// "DHT12.begin DHT12.lastRead DHT12.read DHT12.getHumidity DHT12.getTemperature",
|
21 |
+
// "DHT12.begin DHT12.read DHT12.getHumidity DHT12.getTemperature"
|
22 |
+
// ]
|
23 |
+
// },
|
24 |
+
// "Sensor Type": "Sensors",
|
25 |
+
// "Github URL": "https://github.com/RobTillaart/DHT20",
|
26 |
+
// "Description": "Arduino library for I2C DHT20 temperature and humidity sensor."
|
27 |
+
// },
|
28 |
+
// {
|
29 |
+
// "id": 255120181,
|
30 |
+
// "library_name": "DHT12",
|
31 |
+
// "hw_config": {
|
32 |
+
// "protocol": "I2C",
|
33 |
+
// "pin_connection_from_hw_to_arduino": {
|
34 |
+
// "arduino_mega": [["SDA", "20"], ["SCL", "21"]],
|
35 |
+
// "arduino_uno": [["SDA", "A4"], ["SCL", "A5"]],
|
36 |
+
// }
|
37 |
+
// },
|
38 |
+
// "usage_patterns": {
|
39 |
+
// "DHT12": [
|
40 |
+
// "DHT12.begin",
|
41 |
+
// "DHT12.begin DHT12.lastRead DHT12.read DHT12.getHumidity DHT12.getTemperature",
|
42 |
+
// "DHT12.begin DHT12.read DHT12.getHumidity DHT12.getTemperature"
|
43 |
+
// ]
|
44 |
+
// },
|
45 |
+
// "Sensor Type": "Sensors",
|
46 |
+
// "Github URL": "https://github.com/RobTillaart/DHT12",
|
47 |
+
// "Description": "Arduino library for I2C DHT12 temperature and humidity sensor."
|
48 |
+
// }
|
49 |
+
// ];
|
50 |
+
|
51 |
//display the pop up with more information
|
52 |
function onClickMore(string){
|
53 |
document.getElementById(string).style.display ='block';
|
|
|
57 |
function onOut(string){
|
58 |
document.getElementById(string).style.display ='none';
|
59 |
}
|
60 |
+
|
61 |
async function getResponse(url, user_query){
|
62 |
try {
|
|
|
|
|
|
|
|
|
63 |
let final_url = url + '?user_query=' + user_query
|
64 |
console.log(final_url)
|
65 |
+
|
66 |
let predictions = await fetch(final_url);
|
67 |
console.log(predictions)
|
68 |
+
|
69 |
return predictions.json()
|
70 |
+
|
71 |
} catch (error) {
|
72 |
console.log(error)
|
73 |
}
|
|
|
75 |
|
76 |
//when retrieve is clicked
|
77 |
async function onSubmit(){
|
78 |
+
document.getElementById("spinner").style.display = 'none';
|
79 |
+
document.getElementById("spinner").style.display = 'block';
|
80 |
+
document.getElementById("main-parent").innerHTML = '';
|
81 |
|
82 |
let user_query = document.getElementById("exampleFormControlInput1").value
|
|
|
83 |
// let url_query = "http://10.27.32.183:8111/predict"
|
84 |
+
|
85 |
if (user_query != ''){
|
86 |
document.getElementById("spinner").style.display = 'block';
|
87 |
|
|
|
88 |
let url_query = "/predict"
|
89 |
let predictions = await getResponse(url_query, user_query)
|
|
|
90 |
|
91 |
document.getElementById("spinner").style.display = 'none';
|
92 |
+
// document.getElementById("grey-container").className = 'album py-5 bg-light';
|
93 |
|
94 |
let response = predictions['predictions']
|
|
|
|
|
95 |
//loop through number of results
|
96 |
html = ''
|
97 |
var w = 0
|
98 |
for(let i=0; i < response.length; i++){
|
99 |
+
|
100 |
html += '<div class="row g-4 m-2" id="predictions">';
|
101 |
html += '<div class="col-6">';
|
102 |
html += '<div class="card border-primary mb-3">';
|
|
|
196 |
html += '<div style="margin-bottom: 15px" class="accordion" id="accordionPanelsStayOpenExample"' + response[i]["id"] + key + '>'; //1
|
197 |
|
198 |
for (let x=0; x < usages_arr.length; x++){
|
199 |
+
let pattern = usages_arr[x].split("[API-SEP]")
|
200 |
html += '<div data-bs-toggle="collapse" data-bs-target="#patternCollapse' + response[i]["id"] + key + x + '">'; //2
|
201 |
html += '<div class="accordion-item">'; //3
|
202 |
html += '<h2 class="accordion-header" id="panelsStayOpen-heading' + response[i]["id"] + key +'">';
|
|
|
266 |
//append footer to allow going back to the top
|
267 |
document.getElementById("footer").innerHTML = (html2);
|
268 |
}
|
269 |
+
else {
|
270 |
+
document.getElementById("spinner").style.display = 'none';
|
271 |
+
}
|
272 |
}
|