I am building a bot for food ordering. I have saved my food categories (i.e Starters, Meals, Fish, Meat, Pasta etc) in firebase and every food-category can have multiple food-items.
here is my food-item structure in firebase
{
"-KauXk2E4ma1u70X-h4g" : {
"food_category" : "fish",
"food_desc" : "Zander filets in pastry made with beer, tartar sauce",
"food_like" : true,
"food_name" : "Homemade fish sticks",
"food_price" : 45,
"food_url" : "https://i.scaley.io/768x687/lebijou.io/_jamesapp/food/airhomeCHZH3/FISH/Homemade fish sticks.jpg"
},
"-KauY4B0pQDgZ_sF92Df" : {
"food_category" : "meat",
"food_desc" : "Rindsfiletmedaillons (160 g), Balsamicosauce, fried potatoes",
"food_like" : true,
"food_name" : "Medallion of beef with balsamic-sauce",
"food_price" : 45,
"food_url" : "https://i.scaley.io/768x687/lebijou.io/_jamesapp/food/airhomeCHZH3/MEAT/Medallion of beef with balsamic-sauce.jpg"
},
"-KauYG4BcYT5EY36TQM7" : {
"food_category" : "fish",
"food_desc" : "",
"food_like" : true,
"food_name" : "Gilt head fillets",
"food_price" : 45,
"food_url" : "https://i.scaley.io/768x687/lebijou.io/_jamesapp/food/airhomeCHZH3/FISH/Gilt head fillets.jpg"
},
"-KauYHAaRDF6ZgAFy7U_" : {
"food_category" : "meat",
"food_desc" : "",
"food_like" : true,
"food_name" : "Münsterhof Food - Burger",
"food_price" : 45,
"food_url" : "https://i.scaley.io/768x687/lebijou.io/_jamesapp/food/airhomeCHZH3/MEAT/Münsterhof Food - Burger.jpg"
},
"-KaucBQaWncdZOc5kat2" : {
"food_category" : "pasta",
"food_desc" : "Rigatoni (type of pasta), tomato, pepper, garlic",
"food_like" : true,
"food_name" : "Arrabbiata",
"food_price" : 45,
"food_url" : "https://i.scaley.io/768x687/lebijou.io/_jamesapp/food/airhomeCHZH3/PASTA/Arrabbiata.jpg"
},
"-KaucGDalMgMRwfCGbvy" : {
"food_category" : "pasta",
"food_desc" : "Tagliatelle (type of pasta), tomato, beef",
"food_like" : true,
"food_name" : "Bolognese",
"food_price" : 45,
"food_url" : "https://i.scaley.io/768x687/lebijou.io/_jamesapp/food/airhomeCHZH3/PASTA/Bolognese.jpg"
},
"-KaucisapOUvgKF2xcjg" : {
"food_category" : "pasta",
"food_desc" : "Rigatoni (type of pasta), tomato, basil",
"food_like" : true,
"food_name" : "Napoli",
"food_price" : 45,
"food_url" : "https://i.scaley.io/768x687/lebijou.io/_jamesapp/food/airhomeCHZH3/PASTA/Napoli.jpg"
},
"-KaucsqbjLVKL3oAv4y3" : {
"food_category" : "pizza",
"food_desc" : "Homemade pizza dough, tomato sauce, mozzarella cheese, ham, free-range egg, pesto",
"food_like" : true,
"food_name" : "Calzone",
"food_price" : 45,
"food_url" : "https://i.scaley.io/768x687/lebijou.io/_jamesapp/food/airhomeCHZH3/PIZZA/Calzone.jpg"
},
"-KaucwQb6NNgkUCg8bZD" : {
"food_category" : "pizza",
"food_desc" : "Homemade pizza dough, tomato sauce, mozzarella cheese, basil",
"food_like" : true,
"food_name" : "Margherita",
"food_price" : 45,
"food_url" : "https://i.scaley.io/768x687/lebijou.io/_jamesapp/food/airhomeCHZH3/PIZZA/Margherita.jpg"
},
"-Kaud7xE6JmQtqhLiLQP" : {
"food_category" : "pizza",
"food_desc" : "Homemade pizza dough, tomato sauce, mozzarella cheese, artichokes, hot pepper, mushrooms, ham, olives, oregano",
"food_like" : true,
"food_name" : "Quattro stagioni",
"food_price" : 45,
"food_url" : "https://i.scaley.io/768x687/lebijou.io/_jamesapp/food/airhomeCHZH3/PIZZA/Quattro stagioni.jpg"
},
"-Kaue7Wzluk-wy9xys5n" : {
"food_category" : "starters",
"food_desc" : "beef-carpaccio, parmesan, olive oil",
"food_like" : true,
"food_name" : "Beef carpaccio",
"food_price" : 45,
"food_url" : "https://i.scaley.io/768x687/lebijou.io/_jamesapp/food/airhomeCHZH3/STARTERS/Beef carpaccio.jpg"
}
}
What I am trying to achieve is to sync my food-items (under food categories) from firebase to api.ai entities.
I have done it manually on api.ai like below
http://prntscr.com/fhpme6
Now want to do all this via code (nodejs)
I know there is api.ai provides apis to play with entities i.e https://docs.api.ai/docs/entities (I have used them)
I can extract food-items from firebase and sync data to api.ai entities. But there is a problem. I can't overwrite and/or delete the entities already used in my intents.
Here is the code I have tried so for FoodSync.js
var util = require('util');
var exec = require('child_process').exec;
var apiai_developer_access_code = "e764e24fa51e4d93bdc1e6bde92d07d8"
class FoodSync {
syncFood(firebaseRef, apiAiRef, callback){
//Retrieves a list of all entities for the agent.
var all_entities = 'curl -k -H "Authorization: Bearer '+apiai_developer_access_code+'" "https://api.api.ai/v1/entities?v=20150910"'
var food_category_id = "";
var all_entities_array = [];
var all_food_cat_names = [];
var all_food_cat_entities_id = [];
var that = this;
that.execCommand(all_entities, function(error, stdout, stderr){
var jsonResponse = JSON.parse(stdout)
all_entities_array = jsonResponse;
for(var i = 0; i < jsonResponse.length; i++) {
var entity = jsonResponse[i];
if(entity.name == "food-categories"){
food_category_id = entity.id;
break;
}
}
console.log('food_category_id: ' + food_category_id);
if(food_category_id == ""){
return;
}
var food_category_entity_url = that.getEntityUrlWithID(food_category_id);
console.log('food_category_entity_url: ' + food_category_entity_url);
that.execCommand(food_category_entity_url, function(error, stdout, stderr){
var jsonResponse = JSON.parse(stdout)
console.log('food_category_entity: ' + JSON.stringify(jsonResponse));
var food_cat_all_entities = jsonResponse.entries;
console.log("food_cat_all_entities : "+ food_cat_all_entities.length);
for(var i = 0; i < food_cat_all_entities.length; i++) {
var food_cat_entity = food_cat_all_entities[i];
var food_cat_entity_name = food_cat_entity.value.replace('#', '')
console.log("food_cat_entity_name : "+ food_cat_entity_name);
console.log("all_entities_array.length : "+ all_entities_array.length);
for(var j = 0; j < all_entities_array.length; j++){
var entity_check = all_entities_array[j];
if(entity_check.name == food_cat_entity_name){
all_food_cat_entities_id.push(entity_check.id);
}
}
// Here I got all food-entities id.
console.log('all_food_cat_entities_ids: ' + all_food_cat_entities_id);
// Here I am calling the DELETE entity first (then Recreate), Problem is my entity is used in My some of Intents, So upon delete I am getting the error,
// {
// "id": "09e2c21d-b4e3-4a34-a774-eab781c957e1",
// "timestamp": "2017-06-09T10:01:19.294Z",
// "lang": "en",
// "status": {
// "code": 400,
// "errorType": "bad_request",
// "errorDetails": "Some entity names are in use: food-cat-fish"
// }
// }
}
})
// if(error !== null){
// console.log('exec error: ' + error);
// callback()
// }
})
}
getEntityUrlWithID(entitiy_id){
// Retrieves the specified entity.
var entities = 'curl -k -H "Authorization: Bearer '+apiai_developer_access_code+'" "https://api.api.ai/v1/entities/'+entitiy_id+'?v=20150910"'
return entities;
}
execCommand(command, callback){
console.log('execCommand: called');
exec(command, function(error, stdout, stderr){
//console.log('stdout: ' + stdout);
//console.log('stderr: ' + stderr);
if(error !== null){
console.log('exec error: ' + error);
}
callback(error, stdout, stderr)
});
}
}
module.exports = FoodSync
Related
I have the following JSON scheme:
{
"CVE_data_type" : "CVE",
"CVE_data_format" : "MITRE",
"CVE_data_version" : "4.0",
"CVE_data_numberOfCVEs" : "19162",
"CVE_data_timestamp" : "2022-02-24T08:00Z",
"CVE_Items" : [ {
"cve" : {
"data_type" : "CVE",
"data_format" : "MITRE",
"data_version" : "4.0",
"CVE_data_meta" : {
"ID" : "CVE-2020-0597",
"ASSIGNER" : "secure#intel.com"
},
"problemtype" : {
"problemtype_data" : [ {
"description" : [ {
"lang" : "en",
"value" : "CWE-125"
} ]
} ]
},
"references" : {
"reference_data" : [ {
"url" : "https://www.intel.com/content/www/us/en/security-center/advisory/intel-sa-00295.html",
"name" : "https://www.intel.com/content/www/us/en/security-center/advisory/intel-sa-00295.html",
"refsource" : "MISC",
"tags" : [ "Vendor Advisory" ]
}, {
"url" : "https://www.synology.com/security/advisory/Synology_SA_20_15",
"name" : "https://www.synology.com/security/advisory/Synology_SA_20_15",
"refsource" : "CONFIRM",
"tags" : [ "Third Party Advisory" ]
}, {
"url" : "https://support.lenovo.com/de/en/product_security/len-30041",
"name" : "https://support.lenovo.com/de/en/product_security/len-30041",
"refsource" : "MISC",
"tags" : [ ]
}, {
"url" : "https://security.netapp.com/advisory/ntap-20200611-0007/",
"name" : "https://security.netapp.com/advisory/ntap-20200611-0007/",
"refsource" : "CONFIRM",
"tags" : [ ]
}, {
"url" : "https://www.kb.cert.org/vuls/id/257161",
"name" : "VU#257161",
"refsource" : "CERT-VN",
"tags" : [ ]
} ]
},
"description" : {
"description_data" : [ {
"lang" : "en",
"value" : "Out-of-bounds read in IPv6 subsystem in Intel(R) AMT and Intel(R) ISM versions before 14.0.33 may allow an unauthenticated user to potentially enable denial of service via network access."
} ]
}
},
"configurations" : {
"CVE_data_version" : "4.0",
"nodes" : [ {
"operator" : "OR",
"children" : [ ],
"cpe_match" : [ {
"vulnerable" : true,
"cpe23Uri" : "cpe:2.3:a:intel:active_management_technology:*:*:*:*:*:*:*:*",
"versionStartIncluding" : "11.0",
"versionEndIncluding" : "11.8.76",
"cpe_name" : [ ]
}, {
"vulnerable" : true,
"cpe23Uri" : "cpe:2.3:a:intel:active_management_technology:*:*:*:*:*:*:*:*",
"versionStartIncluding" : "11.10",
"versionEndIncluding" : "11.11.76",
"cpe_name" : [ ]
}, {
"vulnerable" : true,
"cpe23Uri" : "cpe:2.3:a:intel:active_management_technology:*:*:*:*:*:*:*:*",
"versionStartIncluding" : "11.20",
"versionEndIncluding" : "11.22.76",
"cpe_name" : [ ]
}, {
"vulnerable" : true,
"cpe23Uri" : "cpe:2.3:a:intel:active_management_technology:*:*:*:*:*:*:*:*",
"versionStartIncluding" : "12.0",
"versionEndIncluding" : "12.0.63",
"cpe_name" : [ ]
}, {
"vulnerable" : true,
"cpe23Uri" : "cpe:2.3:a:intel:active_management_technology:*:*:*:*:*:*:*:*",
"versionStartIncluding" : "13.0",
"versionEndIncluding" : "13.0.31",
"cpe_name" : [ ]
}, {
"vulnerable" : true,
"cpe23Uri" : "cpe:2.3:a:intel:active_management_technology:*:*:*:*:*:*:*:*",
"versionStartIncluding" : "14.0",
"versionEndIncluding" : "14.0.32",
"cpe_name" : [ ]
}, {
"vulnerable" : true,
"cpe23Uri" : "cpe:2.3:a:intel:software_manager:*:*:*:*:*:*:*:*",
"versionStartIncluding" : "11.0",
"versionEndIncluding" : "11.8.76",
"cpe_name" : [ ]
}, {
"vulnerable" : true,
"cpe23Uri" : "cpe:2.3:a:intel:software_manager:*:*:*:*:*:*:*:*",
"versionStartIncluding" : "11.10",
"versionEndIncluding" : "11.11.76",
"cpe_name" : [ ]
}, {
"vulnerable" : true,
"cpe23Uri" : "cpe:2.3:a:intel:software_manager:*:*:*:*:*:*:*:*",
"versionStartIncluding" : "11.20",
"versionEndIncluding" : "11.22.76",
"cpe_name" : [ ]
}, {
"vulnerable" : true,
"cpe23Uri" : "cpe:2.3:a:intel:software_manager:*:*:*:*:*:*:*:*",
"versionStartIncluding" : "12.0",
"versionEndIncluding" : "12.0.63",
"cpe_name" : [ ]
}, {
"vulnerable" : true,
"cpe23Uri" : "cpe:2.3:a:intel:software_manager:*:*:*:*:*:*:*:*",
"versionStartIncluding" : "13.0",
"versionEndIncluding" : "13.0.31",
"cpe_name" : [ ]
}, {
"vulnerable" : true,
"cpe23Uri" : "cpe:2.3:a:intel:software_manager:*:*:*:*:*:*:*:*",
"versionStartIncluding" : "14.0",
"versionEndIncluding" : "14.0.32",
"cpe_name" : [ ]
} ]
} ]
},
"impact" : {
"baseMetricV3" : {
"cvssV3" : {
"version" : "3.1",
"vectorString" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H",
"attackVector" : "NETWORK",
"attackComplexity" : "LOW",
"privilegesRequired" : "NONE",
"userInteraction" : "NONE",
"scope" : "UNCHANGED",
"confidentialityImpact" : "NONE",
"integrityImpact" : "NONE",
"availabilityImpact" : "HIGH",
"baseScore" : 7.5,
"baseSeverity" : "HIGH"
},
"exploitabilityScore" : 3.9,
"impactScore" : 3.6
},
"baseMetricV2" : {
"cvssV2" : {
"version" : "2.0",
"vectorString" : "AV:N/AC:L/Au:N/C:N/I:N/A:P",
"accessVector" : "NETWORK",
"accessComplexity" : "LOW",
"authentication" : "NONE",
"confidentialityImpact" : "NONE",
"integrityImpact" : "NONE",
"availabilityImpact" : "PARTIAL",
"baseScore" : 5.0
},
"severity" : "MEDIUM",
"exploitabilityScore" : 10.0,
"impactScore" : 2.9,
"acInsufInfo" : false,
"obtainAllPrivilege" : false,
"obtainUserPrivilege" : false,
"obtainOtherPrivilege" : false,
"userInteractionRequired" : false
}
},
"publishedDate" : "2020-06-15T14:15Z",
"lastModifiedDate" : "2021-03-18T13:15Z"
}, {
"cve" : {[...]
I need to get the following values from the schema if the ID value is CVE-2020-0597:
CWE-125
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H
7.5
I've never worked with this, so it's a little hard for me to understand how to do it in this structure. Can somebody show me an example for my case?
Without further details wrt conditions, array indices etc, I guess this is what you want:
jq -r '
.CVE_Items[] | select(.cve.CVE_data_meta.ID == "CVE-2020-0597")
| .cve.problemtype.problemtype_data[0].description[0].value,
(.impact.baseMetricV3.cvssV3 | .vectorString, .baseScore)
'
CWE-125
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H
7.5
Demo
I have a method called getNearByPlaces(), then I have for loop that iterates over each place_id, and send a request to google API, to get the name of the place_id,
so this operation takes around 15 seconds, how I can make it faster?
Future<void> getNearByPlaces(double latitude, double longitude) async {
List results = [];
List placesId = [];
List nearbyPlaces = [];
String nearbyUrl =
"https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=${latitude},${longitude}&radius=500&key=${mapKey}";
var nearbyResponse =
await RequestAssistant.getRequest(Uri.parse(nearbyUrl));
if (nearbyResponse == "Failed.") {
return;
}
results = nearbyResponse["results"];
for (int i = 0; i < results.length; i++) {
placesId.add(results[i]['place_id']);
String placeDetailsUrl =
"https://maps.googleapis.com/maps/api/place/details/json?place_id=${results[i]['place_id']}&key=$mapKey";
var response =
await RequestAssistant.getRequest(Uri.parse(placeDetailsUrl));
if (response == "Failed.") {
return;
}
if (response["status"] == "OK") {
await nearbyPlaces.add(response["result"]["name"]);
}
}
print(nearbyPlaces);
await FirebaseFirestore.instance
.collection("nearbyPlaces")
.doc(uid)
.set({'nearbyPlaces': nearbyPlaces});
}
If you just use only name in the detail result, you don't need to query again by 'place_id' because I found that there are more information in 'nearbysearch' API results.
For example, icon, name, photos and so on like below.
https://developers.google.com/maps/documentation/places/web-service/search
{
"html_attributions" : [],
"next_page_token" : "CpQCAgEAAFxg8o-eU7_uKn7Yqjana-HQIx1hr5BrT4zBaEko29ANsXtp9mrqN0yrKWhf-y2PUpHRLQb1GT-mtxNcXou8TwkXhi1Jbk-ReY7oulyuvKSQrw1lgJElggGlo0d6indiH1U-tDwquw4tU_UXoQ_sj8OBo8XBUuWjuuFShqmLMP-0W59Vr6CaXdLrF8M3wFR4dUUhSf5UC4QCLaOMVP92lyh0OdtF_m_9Dt7lz-Wniod9zDrHeDsz_by570K3jL1VuDKTl_U1cJ0mzz_zDHGfOUf7VU1kVIs1WnM9SGvnm8YZURLTtMLMWx8-doGUE56Af_VfKjGDYW361OOIj9GmkyCFtaoCmTMIr5kgyeUSnB-IEhDlzujVrV6O9Mt7N4DagR6RGhT3g1viYLS4kO5YindU6dm3GIof1Q",
"results" : [
{
"geometry" : {
"location" : {
"lat" : -33.867217,
"lng" : 151.195939
}
},
"icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/cafe-71.png",
"name" : "Biaggio Cafe - Pyrmont",
"opening_hours" : {
"open_now" : true
},
"photos" : [
{
"height" : 600,
"html_attributions" : [],
"photo_reference" : "CnRnAAAAmWmj0BqA0Jorm1_vjAvx1n6c7ZNBxyY-U9x99-oNyOxvMjDlo2npJzyIq7c3EK1YyoNXdMFDcRPzwLJtBzXAwCUFDGo_RtLRGBPJTA2CoerPdC5yvT2SjfDwH4bFf5MrznB0_YWa4Y2Qo7ABtAxgeBIQv46sGBwVNJQDI36Wd3PFYBoUTlVXa0wn-zRITjGp0zLEBh8oIBE",
"width" : 900
}
],
"place_id" : "ChIJIfBAsjeuEmsRdgu9Pl1Ps48",
"price_level" : 1,
"rating" : 3.4,
"reference" : "ChIJIfBAsjeuEmsRdgu9Pl1Ps48",
"types" : [ "cafe", "bar", "restaurant", "food", "establishment" ],
"vicinity" : "48 Pirrama Rd, Pyrmont"
},
So you just iterate 'nearbysearch' result and making 'nearbyPlaces' data.
...
results = nearbyResponse["results"];
for (int i = 0; i < results.length; i++) {
placesId.add(results[i]['place_id']);
nearbyPlaces.add(results[i]['name');
}
print(nearbyPlaces);
...
I am trying to get a rule set working to allow users to see there own data...
My current rule set is:
{
"rules": {
".read": "root.child('users').child(auth.uid).child('admin').val() === true",
".write": "root.child('users').child(auth.uid).child('admin').val() === true",
"users": {
".indexOn": ["active"],
"$user_id": {
".read": "$user_id === auth.uid",
".write": "$user_id === auth.uid"
}
},
"active_alerts": {
".indexOn": "alert_id"
},
"trips": {
".indexOn": "archive",
"$trip_id": {
".read": "data.child('who_called').child('key').val() === root.child('users').child(auth.uid).child('customer').child('key').val()",
"notes": {
"$note_id": {
".read": "data.child('display').val() === true"
}
}
}
}
}
}
The user path has data that looks like this:
{
"active" : true,
"admin" : false,
"customer" : {
"key" : "-Ldsu71CgIJxh1DVTTCP",
"name" : "Demo Customer"
},
"email" : "emai#email.com",
"last_login" : "2019-05-02T18:34:26.466Z",
"name" : "Demo",
"primary_phone" : "4197460180",
"typeahead" : "demo"
}
and the matching item in /trips:
{
"airline" : {
"key" : "195",
"name" : "AAL"
},
"archive" : false,
"arrival_airport" : {
"code" : "PHL",
"icao" : "KPHL",
"key" : "108",
"name" : "Philadelphia",
"timezone" : "America/New_York"
},
"bill_to" : {
"key" : "-LdqFpqAOm-dOl9xBtp2",
"name" : "AGT Global Logistics "
},
"consignee" : {
"key" : "-LdqHNMzPrP9epp_W-DS",
"name" : "Exelon Peach Bottom"
},
"customer_reference" : "124914",
"departure_airport" : {
"code" : "MKE",
"icao" : "KMKE",
"key" : "90",
"name" : "Milwaukee",
"timezone" : "America/Chicago"
},
"last_update" : "2019-05-02T18:02:57.274Z",
"level" : {
"key" : "-LWlODaCFUcejExn41Rr",
"name" : "Next Flight Out"
},
"milestones" : [ {
"airport" : {
"code" : "MKE",
"icao" : "KMKE",
"key" : "90",
"name" : "Milwaukee",
"timezone" : "America/Chicago"
},
"flight_time" : "2019-05-02T12:33:00.000Z",
"status" : {
"key" : "4",
"name" : "completed"
},
"type" : {
"key" : "0",
"name" : "Picked up"
}
}, {
"airport" : {
"code" : "MKE",
"icao" : "KMKE",
"key" : "90",
"name" : "Milwaukee",
"timezone" : "America/Chicago"
},
"flight_time" : "2019-05-02T13:51:00.000Z",
"status" : {
"key" : "4",
"name" : "completed"
},
"type" : {
"key" : "1",
"name" : "Dropped to departure airport"
}
}, {
"airline" : {
"key" : "195",
"name" : "AAL"
},
"airport" : {
"code" : "MKE",
"icao" : "KMKE",
"key" : "90",
"name" : "Milwaukee",
"timezone" : "America/Chicago"
},
"alert_id" : 29624287,
"flight_number" : "4883",
"flight_time" : "2019-05-02T16:28:03.000Z",
"ident" : "PDT4883-1556601968-airline-0144",
"img_url" : "....",
"note" : "arrival ~ PDT4883 arrived at PHL from MKE",
"status" : {
"key" : "4",
"name" : "completed"
},
"type" : {
"key" : "2",
"name" : "Departed Airport"
}
}, {
"airline" : {
"key" : "195",
"name" : "AAL"
},
"airport" : {
"code" : "PHL",
"icao" : "KPHL",
"key" : "108",
"name" : "Philadelphia",
"timezone" : "America/New_York"
},
"alert_id" : 29624287,
"flight_number" : "4883",
"flight_time" : "2019-05-02T18:02:00.000Z",
"note" : "arrival ~ PDT4883 arrived at PHL from MKE",
"status" : {
"key" : "4",
"name" : "completed"
},
"type" : {
"key" : "4",
"name" : "Arrived Airport"
}
}, {
"airport" : {
"code" : "PHL",
"icao" : "KPHL",
"key" : "108",
"name" : "Philadelphia",
"timezone" : "America/New_York"
},
"flight_time" : "2019-05-02T20:00:00.000Z",
"status" : {
"key" : 0,
"name" : "planned"
},
"type" : {
"key" : "6",
"name" : "Out for delivery"
}
}, {
"airport" : {
"code" : "PHL",
"icao" : "KPHL",
"key" : "108",
"name" : "Philadelphia",
"timezone" : "America/New_York"
},
"flight_time" : "2019-05-02T21:30:00.000Z",
"status" : {
"key" : 0,
"name" : "planned"
},
"type" : {
"key" : "7",
"name" : "Delivered"
}
} ],
"pieces" : [ {
"description" : "Valves",
"height" : "11",
"length" : "27",
"qty" : "1",
"units" : {
"key" : "2",
"name" : "IN"
},
"weight" : "50",
"weight_units" : {
"key" : "3",
"name" : "LBS"
},
"width" : "19"
} ],
"protect_time" : "2019-05-02T21:30:00.000Z",
"ready_time" : "2019-05-02T13:00:00.000Z",
"shipper" : {
"key" : "-LdqG3I48m662R7ABa5i",
"name" : "FAIRBANKS MORSE - MKE"
},
"trip_id" : "LFC-155676269",
"trip_notes" : [ {
"date_time" : "2019-05-02T10:29:43.892Z",
"display" : true,
"note" : "delay ~ Philadelphia Intl (PHL) is experiencing all inbound flights being held at their origin due to low clouds"
}, {
"date_time" : "2019-05-02T13:05:52.708Z",
"display" : true,
"note" : "filed ~ PDT4883 (E145) filed to depart MKE # Thu (02 May) 16:24 GMT for PHL # ETA 18:09 GMT (02 May) (UECKR5 SAMPL ADIME GERBS J146 CXR EWC JST BOJID2)"
}, {
"date_time" : "2019-05-02T14:51:00.000Z",
"display" : true,
"note" : "Shipment has been manifested onto flight AA4883 - TC"
}, {
"date_time" : "2019-05-02T16:28:31.325Z",
"display" : true,
"note" : "departure ~ PDT4883 (E145) departed MKE # 16:28 GMT for PHL ETA 18:13 GMT"
}, {
"date_time" : "2019-05-02T18:02:57.274Z",
"display" : true,
"note" : "arrival ~ PDT4883 arrived at PHL from MKE"
} ],
"who_called" : {
"key" : "-Ldsu71CgIJxh1DVTTCP",
"name" : "Demo Customer"
}
}
as you can see, the customer.key and who_called key match, but the user is still not able to see the data. Not sure what I am doing wrong here in the whole rule set. Your help is appreciated!
To allow users see trips added by them use the query-based rules like this;
"trips": {
".indexOn": "archive",
".read": "auth.uid != null && query.orderByChild == 'who_called/key' &&
query.equalTo == root.child('users/' + auth.uid + '/customer/key').val()",
"$trip_id": {
".read": "data.child('who_called').child('key').val() === root.child('users').child(auth.uid).child('customer').child('key').val()",
"notes": {
"$note_id": {
".read": "data.child('display').val() === true"
}
}
}
}
Only restriction with this is you cannot access the user's trips without using the query specified in the rule. That means you can't access the trips like this;
firebase.database().ref('users/USERID/customer/-Ldsu71CgIJxh1DVTTCP)
It has to be done like
firebase.database().ref('trips').orderByChild('who_called/key')
.equalTo('-Ldsu71CgIJxh1DVTTCP')
I've tried it and it works. Hope it helps
The below code gives invalid date
moment.locale('en');
var localLocale = moment('enero 22, 2017', 'MMMM DD, YYYY');
localLocale.locale('es');
alert(localLocale.format('L'));'
You will need to import that particular locale js from Moment.js repo.
I've imported this in below code and this code works perfectly:
https://raw.githubusercontent.com/moment/moment/develop/locale/es.js
//! moment.js locale configuration
//! locale : Spanish [es]
//! author : Julio Napurí : https://github.com/julionc
;(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined'
&& typeof require === 'function' ? factory(require('../moment')) :
typeof define === 'function' && define.amd ? define(['../moment'], factory) :
factory(global.moment)
}(this, (function (moment) { 'use strict';
var monthsShortDot = 'ene._feb._mar._abr._may._jun._jul._ago._sep._oct._nov._dic.'.split('_');
var monthsShort = 'ene_feb_mar_abr_may_jun_jul_ago_sep_oct_nov_dic'.split('_');
var monthsParse = [/^ene/i, /^feb/i, /^mar/i, /^abr/i, /^may/i, /^jun/i, /^jul/i, /^ago/i, /^sep/i, /^oct/i, /^nov/i, /^dic/i];
var monthsRegex = /^(enero|febrero|marzo|abril|mayo|junio|julio|agosto|septiembre|octubre|noviembre|diciembre|ene\.?|feb\.?|mar\.?|abr\.?|may\.?|jun\.?|jul\.?|ago\.?|sep\.?|oct\.?|nov\.?|dic\.?)/i;
var es = moment.defineLocale('es', {
months : 'enero_febrero_marzo_abril_mayo_junio_julio_agosto_septiembre_octubre_noviembre_diciembre'.split('_'),
monthsShort : function (m, format) {
if (!m) {
return monthsShortDot;
} else if (/-MMM-/.test(format)) {
return monthsShort[m.month()];
} else {
return monthsShortDot[m.month()];
}
},
monthsRegex : monthsRegex,
monthsShortRegex : monthsRegex,
monthsStrictRegex : /^(enero|febrero|marzo|abril|mayo|junio|julio|agosto|septiembre|octubre|noviembre|diciembre)/i,
monthsShortStrictRegex : /^(ene\.?|feb\.?|mar\.?|abr\.?|may\.?|jun\.?|jul\.?|ago\.?|sep\.?|oct\.?|nov\.?|dic\.?)/i,
monthsParse : monthsParse,
longMonthsParse : monthsParse,
shortMonthsParse : monthsParse,
weekdays : 'domingo_lunes_martes_miércoles_jueves_viernes_sábado'.split('_'),
weekdaysShort : 'dom._lun._mar._mié._jue._vie._sáb.'.split('_'),
weekdaysMin : 'do_lu_ma_mi_ju_vi_sá'.split('_'),
weekdaysParseExact : true,
longDateFormat : {
LT : 'H:mm',
LTS : 'H:mm:ss',
L : 'DD/MM/YYYY',
LL : 'D [de] MMMM [de] YYYY',
LLL : 'D [de] MMMM [de] YYYY H:mm',
LLLL : 'dddd, D [de] MMMM [de] YYYY H:mm'
},
calendar : {
sameDay : function () {
return '[hoy a la' + ((this.hours() !== 1) ? 's' : '') + '] LT';
},
nextDay : function () {
return '[mañana a la' + ((this.hours() !== 1) ? 's' : '') + '] LT';
},
nextWeek : function () {
return 'dddd [a la' + ((this.hours() !== 1) ? 's' : '') + '] LT';
},
lastDay : function () {
return '[ayer a la' + ((this.hours() !== 1) ? 's' : '') + '] LT';
},
lastWeek : function () {
return '[el] dddd [pasado a la' + ((this.hours() !== 1) ? 's' : '') + '] LT';
},
sameElse : 'L'
},
relativeTime : {
future : 'en %s',
past : 'hace %s',
s : 'unos segundos',
m : 'un minuto',
mm : '%d minutos',
h : 'una hora',
hh : '%d horas',
d : 'un día',
dd : '%d días',
M : 'un mes',
MM : '%d meses',
y : 'un año',
yy : '%d años'
},
dayOfMonthOrdinalParse : /\d{1,2}º/,
ordinal : '%dº',
week : {
dow : 1, // Monday is the first day of the week.
doy : 4 // The week that contains Jan 4th is the first week of the year.
}
});
return es;
})));
Your Code:
moment.updateLocale('es');
var localLocale = moment('enero 22, 2017', 'MMMM DD, YYYY');
alert(localLocale.format('L'));
Demo:
http://jsfiddle.net/6df2xf80/
My flot graph is rendering fine on firefox and chrome, however on ie11 it does not render. the graph appears with no datapoints.
var options = {
"xaxis" : {
"mode" : "time",
"timeformat" : "%d/%m",
//"tickSize" : [1, "day"]
},
"yaxes" : [{
"position" : "left",
//"tickSize" : 1,
"min" : min,
"max" : 100
}, {
"position" : "right",
"min" : 0,
"max" : max
}
],
"series" : {
"lines" : {
"show" : true
},
curvedLines: {
apply: true,
}
},
"colors" : ["#00ff00"],
"legend" : {
"show" : false
},
"grid" : {
hoverable: true,
clickable: true
}//,
//animator: { start: 100, steps: 99, duration: 2000, direction: "left" }
};
var data_ajax = [{
"color" : "#A8B400",
"label" : "R1 Graph",
"lines" : {
"show" : true,
"lineWidth" : 1
},
"points" : {
"show" : false
},
"yaxis" : 1,
"data" : arr
}
];
$('#network-graph').empty();
plot = $.plot("#network-graph", data_ajax, options);
Problem I found was with the data_ajax variable. it contained objects with wrong format. The time format i had to use for IE11 fix is as follows
var to_seconds = moment(data[i].TIMESTAMP, 'YYYY-MM-DD hh:mm A').unix() * 1000;
I wasn't specifying a format previously. Is there a universal date time format I can use for all browsers?