How to replace deprecated jQuery functions? - sapui5

I am trying to display a map in my UI5 app using a formatter.js where I need to put the address with the map URL together.
In the old world the code should look like the following:
formatMapUrl: function(sStreet, sZIP, sCity, sCountry) {
return "https://maps.googleapis.com/maps/api/staticmap?zoom=13&size=640x640&markers="
+ jQuery.sap.encodeURL(sStreet + ", " + sZIP + " " + sCity + ", " + sCountry);
},
How should I replace the deprecated function? Where should I add the new code?

If you look at the API documentation for jQuery.sap.encodeURL, you see it states to use the module sap/base/security/encodeURL now.
Usage example from documentation:
sap.ui.require(["sap/base/security/encodeURL"], function(encodeURL) {
var sEncoded = encodeURL("a/b?c=d&e");
console.log(sEncoded); // a%2fb%3fc%3dd%26e
});
Usage in the formatter.js:
sap.ui.define([
"sap/base/security/encodeURL"
], function (encodeURL) {
"use strict";
return {
formatMapUrl: function(sStreet, sZIP, sCity, sCountry) {
var sBaseUrl = "https://maps.googleapis.com/maps/api/staticmap?zoom=13&size=640x640&markers=";
var sEncodedString = encodeURL(sStreet + ", " + sZIP + " " + sCity + ", " + sCountry);
return sBaseUrl + sEncodedString;
}
};
});

Related

Present Time Range in Grafana's Text Panel

Is there a way to show timeRange.from and timeRange.to in Grafana's Text panel or may be in an another panel?
I tried text-panels with markdown mode:
# Time From: $__interval
with different variables but no one did work. Neither did it if I defined a variable in Settings. The interval or timestamp is not showing.
I'm currently working on an HTML solution, but wondering if there is a simplier/proper way to present the time ranges?
My HTML-solution, in case somebody faces the same issue
(got the main part from maxreb's solution from: https://github.com/grafana/grafana/issues/1909) :
<script type="text/javascript">
refreshTimeFrom();
refreshTimeTo();
angular.element('grafana-app').injector().get('timeSrv').$rootScope.$on('refresh', function(event, data) { refreshTimeFrom(); });
function refreshTimeFrom( )
{
var days = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];
var ts = new Date(angular.element('grafana-app').injector().get('timeSrv').timeRange().from);
document.getElementById("timeFrom").innerHTML = days[ts.getUTCDay() ] + " "
+ ts.getUTCDate() + "." + (ts.getUTCMonth()+1) + "."
+ ts.getUTCFullYear() + " " + ts.getUTCHours() + ":"
+ ts.getUTCMinutes() + ":" + ts.getUTCSeconds();
}
function refreshTimeTo( )
{
var days = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];
var ts = new Date(angular.element('grafana-app').injector().get('timeSrv').timeRange().to);
document.getElementById("timeTo").innerHTML = days[ts.getUTCDay() ] + " "
+ ts.getUTCDate() + "." + (ts.getUTCMonth()+1) + "."
+ ts.getUTCFullYear() + " " + ts.getUTCHours() + ":"
+ ts.getUTCMinutes() + ":" + ts.getUTCSeconds();
}
</script>
<font size = "3"><b> From:</b> <span id="timeFrom" /></br></font>
<font size = "3"><b> To: </b> <span id="timeTo" /> </font>

Bing map infobox on hover over a li not displaying

I am working with integration of bing maps into the application. When the search button is clicked after entering the zip code information, the div below will display a list of available stores and a map with pushpin on that. Showing an infobox is working when I hover over the pushpin. But my requirement is that, I have to show the particular infobox to the user, when the user hovers over the list in the left of the maps.
For example here, when I hover over the first result on the left, the corresponding infobox should show in the map. I am unable to figure out why it not working. Appreciate your help in advance. Thank you. Please find below what I have tried so far.
for (var i = 0; i < data.length; i++) {
if (storeLoc && (data[i].metadata.LocationTypeSort == "ja")) {
console.log(counter);
console.log(data);
innerTablecontent += "<tr><td><h4 class='h4-mapDetails-storeName'>" + '<div style="display: inline-block; vertical-align: middle"><svg xmlns="http://www.w3.org/2000/svg" width="25" height="25"><circle cx="12.5" cy="12.5" r="12.5"/><text x="50%" y="17" text-anchor="middle" fill="white" font-size="14" font-weight="bold">' + (+counter) + '</text></svg></div>' +
" " + "<b><span style='margin-top:-20px;display:block;margin-left:45px;'>" + data[i].metadata.LocationName + "</span></b>" + "</h4><p class='p-mapDetails'>" + data[i].metadata.AddressLine + "," + data[i].metadata.Locality + "," + data[i].metadata.AdminDistrict + " " + data[i].metadata.PostalCode + "</p>"
+ "<p class='p-mapDetails'>" + data[i].metadata.Phone + "<span><span class='index hidden'>" + i + "</span> | " + '<a style=" font-family:Helvetica Neue LT Pro Roman,sans-serif;color:#00A7CE" href="">View details</a>' + "</span></p>"+ "<span class='miles-mapDetails'>" +(data[i].metadata.__Distance* 0.6214).toFixed(2)+"mi</span></td></tr>"
locations.push(data[i].getLocation());
var pin1 = createCirclePushpin(data[i].getLocation(), 12.5, 'rgb(0, 0, 0)', 'black', 1, counter);
pin1.metadata = {
//title: counter + "." + " " + data[i].metadata.LocationName,
title: " ",
description: '<div style="display: inline-block; vertical-align: middle; margin-right:10px;"><svg xmlns="http://www.w3.org/2000/svg" width="25" height="25"><circle cx="12.5" cy="12.5" r="12.5"/><text font-weight="bold" x="50%" y="17" text-anchor="middle" fill="white" font-size="14">' + (+counter) + '</text></svg></div>' + "<span class='h4-mapDetails-storeName'>" + data[i].metadata.LocationName + "</span><p style='margin-bottom:-3px;font-family:Helvetica Neue LT Pro Roman,Helvetica,sans-serif;font-style:normal !important;color:#000;font-size:14px;'>" + data[i].metadata.AddressLine + ", " + data[i].metadata.Locality + "," + data[i].metadata.AdminDistrict + " " +
data[i].metadata.PostalCode + "<br>" + data[i].metadata.Phone + "</p>" + "<a>" + '<a style="font-size:14px;font-family:Helvetica Neue LT Pro Roman,Helvetica,sans-serif;color:#00A7CE" href="">View details</a>' + "</a>"
};
Microsoft.Maps.Events.addHandler(pin1, 'mouseover', pushpinClicked);
map.entities.push(pin1);
counter++;
}
Function to call when the list is hovered:
$("#mapDetails").on("mouseover", "table td", function() {
sideTabHoverEvent(hoverdata[$(this)[0].getElementsByClassName('index')[0].innerText]);
})
function sideTabHoverEvent(e) {
if (e) {
//Set the infobox options with the metadata of the pushpin.
infobox.setOptions({
location: e.getLocation(),
//title: e.metadata.title,
description: e.metadata.description,
visible: true
});
}
}
In you sideTabHoverEnt function you are assuming e is the pushpin the user interacted with, but that's not what you are passing in. You are passing in a string (index as a string). Try doing the following:
function sideTabHoverEvent(e) {
if (e) {
//Turn the index string value into a number.
var idx = parseInt(e);
var shape = map.entities.get(idx);
//Set the infobox options with the metadata of the pushpin.
infobox.setOptions({
location: shape.getLocation(),
//title: shape.metadata.title,
description: shape.metadata.description,
visible: true
});
}
}

Creating a geojson-vt and displaying in Leaflet 0.7

I have a GEOJSON that I am loading up and displaying on a map using Leaflet it is, colour coding them depending on the abundance of the animal in an area and able to display a popup with more information.
What I have been trying to do is turn this into a vectorTile using geojson-vt and display this. This polygon geojson is one of the smaller and takes a long time to load and some others crash the browser.
I have tired to work through the example here http://bl.ocks.org/Sumbera/c67e5551b21c68dc8299 but I cannot understand what is happening.
I am definitely open to other ideas on how to display this data, I am very much a newbie.
If you wish to see what I have so far please look at http://huntingspots.co.nz/gareth/leaflet_layering.html.
Thank you very much for your time.
//Pig Layer
var pigLayer = new L.LayerGroup();
$.getJSON("feralpig.geojson",function(hoodData){
L.geoJson( hoodData, {
style: function(feature){
var fillColour,
abundance = feature.properties.Abundance;
if (abundance == "H") fillColour = "#194866";
else if ( abundance == "M" ) fillColour = "#2c7eb2";
else if ( abundance == "L" ) fillColour = "#40b5ff";
else fillColour = "#f7f7f7"; // no data
return { color: "#999", weight: 1, fillColor: fillColour, fillOpacity: .4 };
},
onEachFeature: function( feature, layer ){
layer.bindPopup( "<strong>" + "Species: " + "</strong>" + feature.properties.Scientific
+ "<br/>" + "<strong>" + "Common Name: " + "</strong>" + feature.properties.CommonName
+ "<br/>" + "<strong>" + "Abundance: " + "</strong>" + feature.properties.Abundance
+ "<br/>" + "<strong>" + "Data collection method: " + "</strong>" + feature.properties.AbundRelia
+ "<br/>" + "<strong>" + "Notes: " + "</strong>" + feature.properties.AbundNotes);
}
}).addTo(pigLayer);
});

NodeRed Function Node Crashes - [red] Uncaught Exception:

I am having a hard time understanding why my Node-Red Flow keeps crashing with an [RED] Uncaught Exception. It almost seems like the function node is crashing and my code inside of the function node never has a chance to catch it.
I have a very simple Node-Red flow that executes a IBMDB node.js library to insert data into my database. In order to use the IBMDB library, I had to add the package to the list of packages in my packages.json file. I also had to setup a global context variable inside the Bluemix-setings.js file. I named this global context variable IBMDB, which is the equivalent to the require statement. Once that was done, I am able to make use of the library inside a function node.
** Here is the Node.js IBMDB library, I am using.
https://github.com/ibmdb/node-ibm_db
** Here is the Flow
** Here is the code inside the function.
try {
context.global.ibmdb.open("DATABASE=database;HOSTNAME=hostname;PORT=port;PROTOCOL=TCPIP;UID=username;PWD=password;", function (err,conn) {
conn.beginTransaction(function (err) {
if (err) {
//could not begin a transaction for some reason.
console.log(err);
return conn.closeSync();
}
for (i = 0; i < msg.payload.Readings.length; i++)
{
var result = conn.querySync("INSERT INTO db2.table (" +
"I_ID," +
"D_ID," +
"field1," +
"field2," +
"field3," +
"field4," +
"field5," +
"field6," +
"field7," +
"field8," +
"field9," +
"field10)" +
"values (" +
"1A," +
"'"+ msg.payload.field1 + "',"+
"'" + JSON.stringify(msg.payload.Readings[i].field2) + "'," +
msg.payload.Readings[i].field3 + ","+
msg.payload.Readings[i].field4 + ","+
msg.payload.Readings[i].field5 + ","+
msg.payload.Readings[i].field6 + ","+
msg.payload.Readings[i].field7 + ","+
msg.payload.Readings[i].field8 + ","+
msg.payload.Readings[i].field9 + ","+
msg.payload.Readings[i].field10 + ","+
"'2016-05-31 22:28:51.000000'" +
");");
}
conn.commitTransaction(function (err) {
if (err) {
//error during commit
console.log("****ERROR: " + err);
node.error("**** ERROR: ", err);
//return conn.closeSync();
}
//Close the connection
conn.closeSync();
});
});
});
} catch (e) {
node.error("**** ERROR: ", err);
}
When I run this with a valid SQL statement and all the data types are correctly sent, I get no errors. Everything works!!
*** The issue: When I did some testing to force a SQL error, the Node-Red instance crashes. I forced the error by sending a valid SQL statement, but the data elements in one of the fields is a non-numeric value where the table definition is expecting numeric only. I see in the error logs (console out) two lines..
The error SQL error message displayed is exactly what I was expecting to catch in my application. Instead the application just crashes.
[red] Uncaught Exception: Error: [IBM][CLI Driver][DB2/LINUXX8664]
SQL0103N The numeric literal "1A" is not valid. SQLSTATE=42604
Any insight on what is really happening would be greatly appreciated. I am wondering if I put this code inside a custom built node would I be able to catch the error. Could this be a limitation of using the function node as a wrapper to my code. ????
*
Try wrapping the conn.querySync call in it's own try/catch block. The current block is out of scope because the call happens in another function (the one passed into beginTransaction).
e.g.
try {
context.global.ibmdb.open("DATABASE=database;HOSTNAME=hostname;PORT=port;PROTOCOL=TCPIP;UID=username;PWD=password;", function (err,conn) {
conn.beginTransaction(function (err) {
if (err) {
//could not begin a transaction for some reason.
console.log(err);
return conn.closeSync();
}
for (i = 0; i < msg.payload.Readings.length; i++)
{
try {
var result = conn.querySync("INSERT INTO db2.table (" +
"I_ID," +
"D_ID," +
"field1," +
"field2," +
"field3," +
"field4," +
"field5," +
"field6," +
"field7," +
"field8," +
"field9," +
"field10)" +
"values (" +
"1A," +
"'"+ msg.payload.field1 + "',"+
"'" + JSON.stringify(msg.payload.Readings[i].field2) + "'," +
msg.payload.Readings[i].field3 + ","+
msg.payload.Readings[i].field4 + ","+
msg.payload.Readings[i].field5 + ","+
msg.payload.Readings[i].field6 + ","+
msg.payload.Readings[i].field7 + ","+
msg.payload.Readings[i].field8 + ","+
msg.payload.Readings[i].field9 + ","+
msg.payload.Readings[i].field10 + ","+
"'2016-05-31 22:28:51.000000'" +
");");
} catch (excp) {
//do stuff
}
}
conn.commitTransaction(function (err) {
if (err) {
//error during commit
console.log("****ERROR: " + err);
node.error("**** ERROR: ", err);
//return conn.closeSync();
}
//Close the connection
conn.closeSync();
});
});
});
} catch (e) {
node.error("**** ERROR: ", e);
}

Getting null value while displaying contacts in iphone phonegap application

I am working on Phonegap application and trying to get the contacts of the device.
What I have done from this reference is as follows :
function onDeviceReady() {
var options = new ContactFindOptions();
options.filter=""; // empty search string returns all contacts
options.multiple=true; // return multiple results
filter = ["displayName"];
navigator.contacts.find(filter, onSuccess, onError, options);
}
// contacts Methods
function onSuccess(contacts) {
for (var i=0; i<contacts.length; i++) {
for (var j=0; j<contacts[i].addresses.length; j++) {
alert("Pref: " + contacts[i].addresses[j].pref + "\n" +
"Type: " + contacts[i].addresses[j].type + "\n" +
"Formatted: " + contacts[i].addresses[j].formatted + "\n" +
"Street Address: " + contacts[i].addresses[j].streetAddress + "\n" +
"Locality: " + contacts[i].addresses[j].locality + "\n" +
"Region: " + contacts[i].addresses[j].region + "\n" +
"Postal Code: " + contacts[i].addresses[j].postalCode + "\n" +
"Country: " + contacts[i].addresses[j].country);
}
}
};
// onError: Failed to get the contacts
function onError(contactError){
alert('onError!');
}
In console while printing the contacts I am getting this error-
[INFO] Error in success callback: Contacts1 = TypeError: 'null' is not an object
There are contacts in my simulator and contact information is not null still I am getting null. Not sure about the reason.
Please help me.
EDIT : same thing is happening when I am playing audio files ..
Any one have idea why this is happening ??