Commit 554cf336 authored by Zhai Zirun's avatar Zhai Zirun

commented out new bits

parent f9ccf671
......@@ -2,38 +2,19 @@
var MOUSE_VISITED_CLASSNAME = 'crx_mouse_visited';
var srcName;
var dietNum;
var dietNum = 0;
// var currName;
//Querying database on heroku
const { Client } = require('pg');
const client = new Client({
connectionString: process.env.DATABASE_URL, //default name for main database is DATABASE_URL
ssl: {
rejectUnauthorized: false
}
});
function checkAllergens(srcName n) {
client.connect();
//TODO: find a way to connect to client at startup (le??) to remove the need to connect and disconnect repeatedly
//TODO: fill in names of columns of db
client.query('SELECT Containsgluten, Containsdairy, Containscorn, Containsmeat FROM productsIngredients WHERE Product = n;', (err, res) => {
if (err) throw err;
for (let col of res.cols) {
if (col) {
return col;
}
//returns true if any allergen is present.
//TODO: modify behaviour according to different allergens
}
client.end();
return false;
});
}
// import { Client } from 'pg';
// const client = new Client({
// connectionString: process.env.DATABASE_URL, //default name for main database is DATABASE_URL
// ssl: {
// rejectUnauthorized: false
// }
// });
//https://www.w3schools.com/nodejs/nodejs_mysql_select.asp
......@@ -58,10 +39,9 @@ document.addEventListener('mousemove', function (e) {
// if (srcName == "Waitrose coffee & walnut cake") {
// srcElement.classList.add(MOUSE_VISITED_CLASSNAME);
// }
if (checkAllergens(srcElement.srcName)) {
srcElement.classList.add(MOUSE_VISITED_CLASSNAME); //changes outline of pic
// currName = srcElement.srcName;
srcElement.classList.add(MOUSE_VISITED_CLASSNAME); //changes outline of pic
//TODO: modify behaviour according to different allergens
}
// The current element is now the previous. So we can remove the class
// during the next ieration.
//prevDOM = srcElement;
......@@ -83,5 +63,23 @@ function myFunction() {
var c = document.getElementById("Corn").checked;
var d = document.getElementById("Gluten").checked;
dietNum = a + (b << 1) + (c << 2) + (d << 3);
}
}
// function checkAllergens() {
// client.connect();
// //TODO: find a way to connect to client at startup (le??) to remove the need to connect and disconnect repeatedly
// //TODO: fill in names of columns of db
// client.query('SELECT Containsgluten, Containsdairy, Containscorn, Containsmeat FROM productsIngredients WHERE Product = currName;', (err, res) => {
// if (err) throw err;
// for (let col of res.cols) {
// if (col) {
// return col;
// }
// //returns true if any allergen is present.
// //TODO: modify behaviour according to different allergens
// }
// client.end();
// return false;
// });
// }
{
"_from": "pg",
"_from": "pg@^8.3.0",
"_id": "pg@8.3.0",
"_inBundle": false,
"_integrity": "sha512-jQPKWHWxbI09s/Z9aUvoTbvGgoj98AU7FDCcQ7kdejupn/TcNpx56v2gaOTzXkzOajmOEJEdi9eTh9cA2RVAjQ==",
"_location": "/pg",
"_phantomChildren": {},
"_requested": {
"type": "tag",
"type": "range",
"registry": true,
"raw": "pg",
"raw": "pg@^8.3.0",
"name": "pg",
"escapedName": "pg",
"rawSpec": "",
"rawSpec": "^8.3.0",
"saveSpec": null,
"fetchSpec": "latest"
"fetchSpec": "^8.3.0"
},
"_requiredBy": [
"#USER",
......@@ -21,7 +21,7 @@
],
"_resolved": "https://registry.npmjs.org/pg/-/pg-8.3.0.tgz",
"_shasum": "941383300d38eef51ecb88a0188cec441ab64d81",
"_spec": "pg",
"_spec": "pg@^8.3.0",
"_where": "/Users/zirun/Documents/chrome-groceries-extension",
"author": {
"name": "Brian Carlson",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment