Present Time Range in Grafana's Text Panel - grafana

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>

Related

How to replace deprecated jQuery functions?

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;
}
};
});

Ignoring blank email address input field Google Apps Script

I have an HTML form which contains email addresses from various suppliers. I am creating a kind of mail merge function so I can send all the contacts a personalised email when the form is submitted. Here is my .gs file:
function sendEmail(form) {
const sSheet = SpreadsheetApp.getActiveSpreadsheet();
const file = DriveApp.getFileById(sSheet.getId());
const documentUrl = file.getUrl();
/* var toEmail = form.toAddress;
var ccEmail = form.ccAddress;
var fromEmail = "****#*****.com";
var subject = form.subject;
var message = form.message; */
var toEmail = "";
var fromEmail = "****#*****.com";
var message = "";
var hotelAddresses = [
form.toAddress1,
form.toAddress2,
form.toAddress3,
form.toAddress4,
form.toAddress5,
form.toAddress6,
form.toAddress7,
form.toAddress8,
form.toAddress9,
form.toAddress10,
form.toAddress11,
form.toAddress12,
form.toAddress13,
form.toAddress14,
form.toAddress15,
form.toAddress16,
form.toAddress17,
form.toAddress18,
form.toAddress19,
form.toAddress20,
form.toAddress21,
form.toAddress22,
form.toAddress23,
form.toAddress24,
form.toAddress25,
form.toAddress26,
form.toAddress27,
form.toAddress28,
form.toAddress29,
form.toAddress30,
form.toAddress31,
form.toAddress32,
form.toAddress33,
];
var contactNames = [
form.contactName1,
form.contactName2,
form.contactName3,
form.contactName4,
form.contactName5,
form.contactName6,
form.contactName7,
form.contactName8,
form.contactName9,
form.contactName10,
form.contactName11,
form.contactName12,
form.contactName13,
form.contactName14,
form.contactName15,
form.contactName16,
form.contactName17,
form.contactName18,
form.contactName19,
form.contactName20,
form.contactName21,
form.contactName22,
form.contactName23,
form.contactName24,
form.contactName25,
form.contactName26,
form.contactName27,
form.contactName28,
form.contactName29,
form.contactName30,
form.contactName31,
form.contactName32,
form.contactName33,
];
var days = [
form.day1,
form.day2,
form.day3,
form.day4,
form.day5,
form.day6,
form.day7,
form.day8,
form.day9,
form.day10,
form.day11,
form.day12,
form.day13,
form.day14,
form.day15,
form.day16,
form.day17,
form.day18,
form.day19,
form.day20,
form.day21,
form.day22,
form.day23,
form.day24,
form.day25,
form.day26,
form.day27,
form.day28,
form.day29,
form.day30,
form.day31,
form.day32,
form.day33,
];
var dates = [
form.date1,
form.date2,
form.date3,
form.date4,
form.date5,
form.date6,
form.date7,
form.date8,
form.date9,
form.date10,
form.date11,
form.date12,
form.date13,
form.date14,
form.date15,
form.date16,
form.date17,
form.date18,
form.date19,
form.date20,
form.date21,
form.date22,
form.date23,
form.date24,
form.date25,
form.date26,
form.date27,
form.date28,
form.date29,
form.date30,
form.date31,
form.date32,
form.date33,
];
var times = [
form.time1,
form.time2,
form.time3,
form.time4,
form.time5,
form.time6,
form.time7,
form.time8,
form.time9,
form.time10,
form.time11,
form.time12,
form.time13,
form.time14,
form.time15,
form.time16,
form.time17,
form.time18,
form.time19,
form.time20,
form.time21,
form.time22,
form.time23,
form.time24,
form.time25,
form.time26,
form.time27,
form.time28,
form.time29,
form.time30,
form.time31,
form.time32,
form.time33,
];
var additionalInfo = [
form.additional1,
form.additional2,
form.additional3,
form.additional4,
form.additional5,
form.additional6,
form.additional7,
form.additional8,
form.additional9,
form.additional10,
form.additional11,
form.additional12,
form.additional3,
form.additional14,
form.additional15,
form.additional16,
form.additional17,
form.additional18,
form.additional19,
form.additional20,
form.additional21,
form.additional22,
form.additional23,
form.additional24,
form.additional25,
form.additional26,
form.additional27,
form.additional28,
form.additional29,
form.additional30,
form.additional31,
form.additional32,
form.additional33,
];
for(var i = 0; i<times.length; i++){
var subject = "Meeting - " + days[i] + ", " + dates[i] + " at " + times[i];
toEmail = hotelAddresses[i];
message = "Dear " + contactNames[i] + ","
+"<br><br>"+
"Please confirm the meeting on " + days[i] + " " + dates[i] + " at " + times[i] + "." + "<br>" + "<br>" +
additionalInfo[i] +
" If you could kindly let me know if you are able to confirm that would be great." + "<br>" + "<br>" +
"Many thanks and I look forward to hearing from you soon." + "<br>" + "<br>" +
"Yours sincerely," + "<br>" + "<br>" +
form.yourName + "<br>" + "<br>"
+ "<em><b>" + form.yourPosition + "</b></em> <br><br>" +
"<span style='color:#0e216d'><b> Company name. </b>" + "<br>" +
GmailApp.sendEmail(
toEmail, // recipient
subject, // subject
'test', { // body
htmlBody: message // advanced options
}
);
}
}
It works fine except that sometimes the input fields for email will be blank, in which case I need the script to ignore that supplier and continue to run. At the moment it is obviously hitting the empty input and stopping the execution.
I presume I need a conditional statement of sorts... something along the lines of if(hotelAddresses[i] != null) {}
But I cannot work out where to insert this...
Additional: 31 Aug 18
For the HTML I have a series of objects (33 in total) that are all set up like this:
<input type="checkbox" id="check1" class="check" checked>
<input type="text" id="name1" class="contactNameInput" name="toAddress1">
<input type="text" id="contactName1" class="contactNameInput mailName" name="contactName1">
<input type="text" id="time1" class="contactNameInput hidden mailTime" name="time1">
<input type="text" id="day1" class="contactNameInput hidden mailDay" name="day1">
<input type="text" id="date1" class="contactNameInput hidden mailDate" name="date1">
<textarea class="additional contactNameInput" id="additional1" name="additional1" placeholder="Additional requests..."></textarea>
<div class="preview1"></div>
You want to separate the cases with and without hotelAddresses[i] using a script like if(hotelAddresses[i] != null) {}. When my understanding is correct, how about this modification?
Modification points:
Do you want to add after "<span style='color:#0e216d'><b> Company name. </b>" + "<br>" +? In the current script, it's "<span style='color:#0e216d'><b> Company name. </b>" + "<br>" + GmailApp.sendEmail(...). If you want to add more strings, please put them. If you don't want to add, please remove the last +.
I think that the script of if(hotelAddresses[i] != null) {} can be used in the for loop.
The script which reflected above is as follows.
Modified script:
In this modified script, the script of for loop was modified.
for(var i = 0; i<times.length; i++) {
var toEmail = hotelAddresses[i];
if (toEmail) {
var subject = "subject";
var message = "messages";
GmailApp.sendEmail(toEmail, subject, 'test', {htmlBody: message});
} else {
// do something
}
}
Note:
In this modified script, subject and message are replaced by "subject" and "messages", respectively. So please modify them for your situation.
If you want to do something when hotelAddresses[i] is null, please modify // do something.
If you don't want to do something when hotelAddresses[i] is null, please remove else {}.
If I misunderstand your question, please tell me. I would like to modify it.

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);
});

Workflow for Google Apps script approving correct row via email

I am creating a workflow process with Google Apps script. I have looked at this video for most of the layout.
I built a form in Google Apps script that takes input data from a user. The data is then submitted into rows with e.parameter values. That data is then emailed to an approver. The approver has an approve button that they press to change the "Status" column to approved.
Issue:
I cant get the data to approve the correct row. I am passing a row parameter that is supposed to correspond to the correct row but it isnt working.
Here is my code that submits data to the spreadsheet and once the data has been approved via email. The DoPost function runs and approves the row. Can someone Please help! I've been trying to find solutions all day.
function sendEmail_(e) {
var sheet = SpreadsheetApp.openById("0AuCblud0Ss7BdHA1bXZjYXA0Y0IyekhUQm5vWG02MVE").getActiveSheet();
var range = sheet.getRange(sheet.getLastRow() + 1, 1, 1, 13);
range.setValues([
[e.parameter.LastName, e.parameter.FirstName, e.parameter.DivisionName, e.parameter.EffectiveDate,
e.parameter.Network, e.parameter.EmployeeNewPosition, e.parameter.DivisionFolder, e.parameter.SpecificIndividual,
e.parameter.Email, e.parameter.username, e.parameter.who, e.parameter.Banner, "Unapproved"]
]);
var row = sheet.getLastRow() + 1;
//"https://script.google.com/a/macros/wichitafallstx.gov/s/AKfycbwOgTTGqNsVwnqs-xfqa7TEJWGc_lJZdoyoEoixngKdDemVQuo/exec
var body = '<form action= <form action = " https://sites.google.com/a/macros/wichitafallstx.gov/s/AKfycbxAOGO6q9ofauf34xlDA9sLG8sUXeZsuvQkDKATOQ/exec" method ="post">' +
"<b>Last Name:</b>" + e.parameter.LastName + '<br><br>' +
"<b>First Name:</b>" + e.parameter.FirstName + '<br><br>' +
"<b>Division Name:</b>" + e.parameter.DivisionName + '<br><br>' +
"<b>Effective Date:</b>" + e.parameter.EffectiveDate + '<br><br>' +
"<b>Network:</b>" + e.parameter.Network + '<br><br>' +
"<b>Employee New Position:</b>" + e.parameter.EmployeeNewPosition + '<br><br>' +
"<b>Division Folder:</b>" + e.parameter.DivisionFolder + '<br><br>' +
"<b>Specific Individual:</b>" + e.parameter.SpecificIndividual + '<br><br>' +
"<b>Email:</b>" + e.parameter.Email + '<br><br>' +
"<b>Username:</b>" + e.parameter.username + '<br><br>' +
"<b>who:</b>" + e.parameter.who + '<br><br>' +
"<b>Banner:</b>" + e.parameter.Banner +
'<br />' +
'<br />' +
'<input type="hidden" name="row" value=" ' + row + ' "/>' +
'<input type="submit" value="Approve" onclick="approve()" />' +
'</form>';
var owners = SitesApp.getSite("wichitafallstx.gov", "information-systems").getOwners();
var mail = MailApp.sendEmail(owners.join(","), "test", '', {
htmlBody: body
});
}
//handles the payload that is posted back to appscript..from the form that is passed from the form created in send email.
function doPost(e) {
var r = e.parameter["row"];
var sheet = SpreadsheetApp.openById("0AuCblud0Ss7BdHA1bXZjYXA0Y0IyekhUQm5vWG02MVE").getActiveSheet();
var values = sheet.getRange(r, 1, 1, 13).getValues();
sheet.getRange(r, 13).setValue("Approved");
}
I am passing a row parameter that is supposed to correspond to the correct row but it isnt working.
It appears that you are passing the row below the one intended.
var range = sheet.getRange(sheet.getLastRow() + 1, 1, 1, 13);
range.setValues([
[e.parameter.LastName, e.parameter.FirstName, e.parameter.DivisionName, e.parameter.EffectiveDate,
e.parameter.Network, e.parameter.EmployeeNewPosition, e.parameter.DivisionFolder, e.parameter.SpecificIndividual,
e.parameter.Email, e.parameter.username, e.parameter.who, e.parameter.Banner, "Unapproved"]
]);
// In assignment below 'new' lastRow is the row you just filled
// in with above and should not include + 1
var row = sheet.getLastRow() // no + 1;