Getting variable from webview to react native - react-native

I have a function in a webview which has response:
var respMsg = function(e)
{
var respData = eval("(" + e.data + ")");
document.getElementById("response").innerHTML = e.origin + " SENT " + " - " +
respData.responseCode + "-" + respData.dataKey + "-" + respData.errorMessage;
document.getElementById("response").style.display = 'none';
}
My question is: how to get for example respData.dataKey in a react native value so I can use it further (for example to get it and log its value)

Related

setting password on pdf in appscript while expert pdf with URL?

pdf which was created in google-apps-script need to set a password then this pdf will be attached with email service
Is there any parameter to set a password within an export "url" before it is exported to Google drive?
function createPDF(ssId, sheet, pdfName) {
const fr = 0, fc = 0, lc = 9, lr = 27;
const url = "https://docs.google.com/spreadsheets/d/" + ssId + "/export" +
"?format=pdf&" +
"size=8&" +
"fzr=true&" +
"portrait=false&" +
"fitw=true&" +
"gridlines=false&" +
"printtitle=false&" +
"top_margin=0.25&" +
"bottom_margin=0.25&" +
"left_margin=0.25&" +
"right_margin=0.25&" +
"sheetnames=false&" +
"pagenum=UNDEFINED&" +
"attachment=true&" +
"gid=" + sheet.getSheetId() + '&' +
"r1=" + fr + "&c1=" + fc + "&r2=" + lr + "&c2=" + lc;
const params = { method: "GET", headers: { "authorization": "Bearer " + ScriptApp.getOAuthToken() } };
const blob = UrlFetchApp.fetch(url, params).getBlob().setName(pdfName + '.pdf');
// Gets the folder in Drive where the PDFs are stored.
const folder = getFolderByName_(OUTPUT_FOLDER_NAME);
const pdfFile = folder.createFile(blob);
return pdfFile;
}
No.
Unfortunately, there is no way of setting a password of an exported Drive File, that is, by using the Files.export method. That is for pdf files as well as other MIME types.
So, the password protection would have to be added (either manually or programatically) after the export from Drive.

Python selenium close modal window after reading its content

I have the HTML as following:
function showModal(msg) {
var content = document.getElementById("modal-content");
content.innerHTML = msg;
modal.style.display = "block";
}
showModal(msg + "<br>Job started, check status on the project jobs page.");
After all is said and done, I get the following window:
How do I read the content of the box and if there is "Success" I can click the close on top right to go back to the previous page.
I don't have a clue how to approach this.
Edit: Extended HTML looks as following:
function makeInputScenario(ids,params,has_extra = false) {
var sd = gete("sdate").value;
var ed = gete("edate").value;
var sdt = new Date(sd);
var edt = new Date(ed);
if (sdt > edt) {
showModal("Start date is after end date, please fix!");
return;
}
var p = gete("pool").value;
var dzr = gete("dzr").value;
var pfd = gete("pfd").value;
var udb = gete("udb").value;
var uds = gete("uds").value;
if (uds == "None") uds = "";
var rop = gete("rop-text").value;
var fuds = gete("fuds").value;
if (fuds == "None") fuds = "";
var xhr = new XMLHttpRequest();
xhr.addEventListener("load", function() {
hideProgress();
if (!params) setInteraction(false);
if (xhr.status == 200) {
var msg = "<strong>SUCCESS:</strong><br><pre>" + xhr.responseText + "</pre>"
showModal(msg);
if (params) {
if (has_extra) {
showProgress("Processing, please wait...");
doAction("run-params","POST","/scenario/run","user=PJMRTO LONG RUN AUCTION" + params + "&cir=" + getCir(),function (ret) {
setInteraction(false);
clearTimeout(updProgrs);
showModal(msg + "<p>" + ret + "</p>");
});
} else {
var ods = gete("ods").value;
showProgress("Adding new job, please wait...");
doAction("run-params","POST","/job","user=PJMRTO LONG RUN AUCTION&sdate=" + sd + "&edate=" + ed + "&ids=" + ids + "&ods=" + ods + "&rops=" + encode(rop) + "&post=" + encode("") + "&std=" + encode("") + "&cir=" + getCir(),function (job) {
showProgress("Starting job " + job + ", please wait...");
doAction("run-params","POST","/run","id=" + job + params,function (x) {
setInteraction(false);
clearTimeout(updProgrs);
showModal(msg + "<br>Job started, check status on the project jobs page.");
});
});
}
}
} else if (xhr.status == 500) {
setInteraction(false);
clearTimeout(updProgrs);
var logurl = "/idblog?q=host&name=" + encode(ids) + "&pool=" + encode(p) + "&sd=" + encode(sd) + "&ed=" + encode(ed);
showModal(wrapError("<pre>" + xhr.responseText + "</pre><br><button onclick=\"getIDBlog('" + logurl + "');\" class=\"btn btn-primary\">Download Log</button>"));
}
},false);
setInteraction(true);
if (params) {
gete("start-job").style.display = "none";
gete("host-status").style.display = "none";
}
var sparams = "user=PJMRTO LONG RUN AUCTION&pool=" + p + "&dzr=" + dzr + "&pfd=" + pfd + "&ids=" + ids + "&sdate=" + sd + "&edate=" + ed + "&udb=" + udb + "&uds=" + uds + "&rop=" + encode(rop);
if (fuds != "") {
sparams += "&fuds=" + fuds + "&ius=" + gete("ods").value;
showProgress("Creating base and fixed UC input scenarios, please wait...");
} else {
showProgress("Creating input scenario, please wait...");
}
updProgrs = setTimeout(updateProgress, 300000);
xhr.open("POST","/scenario",true);
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr.setRequestHeader("x-csrf-token","NhISQUB1eCANGh46HwsgTnsAISkCAAAATeFn4B0myInXzZc7+8QJMA==");
xhr.send(sparams);
}
So here variable "msg" is storing the value "SUCCESS". It would be better to get the variable "msg" usin javascript.
So that would be :-
from selenium import webdriver
driver = webdriver.Firefox()
driver.get("http://Reachyourpage")
message = driver.execute_script("return msg")
print ("SUCCESS" in message)
It should return true in case of success. I am no expert in Python but just a beginner so mind my coding.. !!
C# equivalant here would be :-
IJavaScriptExecutor js = (IJavaScriptExecutor)_driver;
string title = js.ExecuteScript("return msg");
Here, title will have the complete message.
The algorithm is to get the value of "msg" var using javascript.
For Closing the message, have u tried using SendKeys(Keys.Esc) ??
Hope it Helps!!

web3 - event.watch spits out events in random order

I am watching an event:
var events = EthProj.Message({}, { fromBlock: 0, toBlock: 'latest'});
events.watch((error, results) => {
Inside the event I do this tempString = ((messages.split(":")[1].split(",")[0] + " (From: " + messages.split(":")[2].split("}")[0]) + ")").replace(/"/g, ''); Which, long story short, makes a string from the event giving the event from the block (i.e. It gives the event made at block 173).
I then set a <h2> element's text from each event. When this happens it sets them in a seemingly random order. What can be going on, it sets them from block 0 to the latest block, so how can this happen.
Here is the full code: https://pastebin.com/wGt5kL1Y
var events = EthProj.Message({}, { fromBlock: 0, toBlock: 'latest'});
events.watch((error, results) => {
i++;
messages = "";
messages = JSON.stringify(results.args);
if(i === messageToGet) {
if(messages.split(":")[1].split(",")[0] != '""') {
console.log(messages.split(":")[1].split(",")[0] + " (From: " + messages.split(":")[2].split(",")[0].split("}")[0].split("}")[0] + ")");
tempString = ((messages.split(":")[1].split(",")[0] + " (From: " + messages.split(":")[2].split("}")[0]) + ")").replace(/"/g, '');
} else {
console.log("(No included text)" + "(From: " + messages.split(":")[2].split(",")[0].split("}")[0] + ")");
tempString = (("(no included text) " + " (From: " + messages.split(":")[2].split("}")[0]) + ")").replace(/"/g, '');
}
if((messages.split(":")[1].split(",")[0] === undefined) || (messages.split(":")[2].split(")")[0] === undefined)) {
return;
}
if(document.getElementById("Message" + placeToSet) != null) {
document.getElementById("Message" + placeToSet).remove();
if(document.getElementById("hr" + placeToSet) != null) {
document.getElementById("hr" + placeToSet).remove();
}
}
if(document.getElementById("Message" + placeToSet) === null) {
var newh2 = document.createElement('h2');
newh2.setAttribute("id", ("Message" + placeToSet));
var text = document.createTextNode(tempString);
newh2.appendChild(text);
document.body.appendChild(newh2);
var newHR = document.createElement('hr');
newHR.setAttribute("id", ("hr" + placeToSet));
}
}
});

openui5 FileUploader not working

I am trying to upload a file with a simple form. I can choose a file but when I click on "upload" nothing happens.
My FileUploader.view.xml is like:
<mvc:View
controllerName="sap.ui.unified.sample.FileUploaderBasic.Controller"
xmlns:l="sap.ui.layout"
xmlns:u="sap.ui.unified"
xmlns:mvc="sap.ui.core.mvc"
xmlns="sap.m"
class="viewPadding">
<l:VerticalLayout>
<u:FileUploader
id="fileUploader"
name="myFileUpload"
uploadUrl="upload/"
width="400px"
tooltip="Upload your file to the local server"
uploadComplete="handleUploadComplete"/>
<Button
text="Upload File"
press="handleUploadPress"/>
</l:VerticalLayout>
My Contoller.controller.js
sap.ui.define(['sap/m/MessageToast','sap/ui/core/mvc/Controller'],
function(MessageToast, Controller) {
"use strict";
var ControllerController = Controller.extend("sap.ui.unified.sample.FileUploaderBasic.Controller", {
handleUploadComplete: function(oEvent) {
var sResponse = oEvent.getParameter("response");
if (sResponse) {
var sMsg = "";
var m = /^\[(\d\d\d)\]:(.*)$/.exec(sResponse);
if (m[1] == "200") {
sMsg = "Return Code: " + m[1] + "\n" + m[2] + "(Upload Success)";
oEvent.getSource().setValue("");
} else {
sMsg = "Return Code: " + m[1] + "\n" + m[2] + "(Upload Error)";
}
MessageToast.show(sMsg);
}
},
handleUploadPress: function(oEvent) {
var oFileUploader = this.getView().byId("fileUploader");
oFileUploader.upload();
}
});
return ControllerController;
});
When I run this in the debugger I get an Uncaught TypeError:
Uncaught TypeError: Cannot read property '1' of null
at f.handleUploadComplete (FileUploader.controller.js?eval:11)
at f.a.fireEvent (EventProvider-dbg.js:229)
at f.a.fireEvent (Element-dbg.js:427)
at f.fireUploadComplete (ManagedObjectMetadata-dbg.js:426)
at HTMLIFrameElement.eval (FileUploader.js?eval:6)
at HTMLIFrameElement.dispatch (jquery-dbg.js:4737)
at HTMLIFrameElement.c3.handle (jquery-dbg.js:4549)
if (m[1] == "200") {
sMsg = "Return Code: " + m[1] + "\n" + m[2] + "(Upload Success)";
oEvent.getSource().setValue("");
I searched for sample code and it seems my code is ok, but I don't know why I can't upload a file by click on the button.
I solved this problem ! :)
So, instead of using this
var m = /^[(\d\d\d)]:(.)$/.exec(sResponse);
use this in view FileUploader :
sendXHR="true"
After, on controller js you can use for status :
oEvent.getParameter("status")
and for getting answer as a json file :
var jsonfile = JSON.parse(oEvent.getParameter("responseRaw"));
Then access your sent object attributes from server (only when use dataType: 'json')
jsonfile.attribute
I hope this helps a lot!

Angular, PieChart, NodeJS and multiple queries

I'm trying set my second query to the pie chart datasource in angular and nodejs using multiple queries to get the results at same time
Someone have some idea to solve it.
Server Side
var url = require('url');
//Require express,
var express = require('express');
//and create an app
var app = express();
var mysql = require('mysql');
var connection = mysql.createConnection({
multipleStatements: true,
host: 'localhost',
user: 'hello',
password: 'passw',
database: 'db',
port: 330333
});
//var connection = mysql.createConnection({multipleStatements: true});
app.get('/home', function (req, res) {
res.send('Hello World!');
});
app.get('/sts', function (req, res) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Credentials", true);
res.header("Access-Control-Allow-Headers",
"Origin, X-Requested-With, Content-Type, Accept");
// res.header('Access-Control-Allow-Methods', 'POST, \n\
// GET, PUT, DELETE, OPTIONS');
connection.query(
" SELECT ST.manufacturer, ST.name, ST.model, ST.os, ST.status, " +
" SI.Coord, ST.Last_Update_Date_Time FROM " +
" ( " +
" select s.manufacturer, s.name, s.model, s.os, s. status, " +
" concat(DATE(s.last_update_date),' ',TIME(s.last_update_time)) as Last_Update_Date_Time " +
" from sts s " +
" order by Last_Update_Date_Time DESC " +
" ) AS ST JOIN " +
" ( " +
" select DISTINCT CONCAT(si.latitude, ', ', si.longitude) as Coord, " +
" concat(DATE(update_date),' ',TIME(update_time)) as Update_Date_Time " +
" from sts_info si " +
" order by Update_Date_Time DESC " +
" ) AS SI ON ST.Last_Update_Date_Time = SI.Update_Date_Time; " +
" " +
" \n\ " +
" SELECT ST.manufacturer, ST.name, ST.model, ST.os, ST.status, " +
" count(status) as CountStatus, " +
" SI.Coord, ST.Last_Update_Date_Time FROM " +
" ( " +
" select s.manufacturer, s.name, s.model, s.os, s. status, " +
" concat(DATE(s.last_update_date),' ',TIME(s.last_update_time)) as Last_Update_Date_Time " +
" from sts s " +
" order by Last_Update_Date_Time DESC " +
" ) AS ST JOIN " +
" ( " +
" select DISTINCT CONCAT(si.latitude, ', ', si.longitude) as Coord, " +
" concat(DATE(update_date),' ',TIME(update_time)) as Update_Date_Time " +
" from sts_info si " +
" order by Update_Date_Time DESC " +
" ) AS SI ON ST.Last_Update_Date_Time = SI.Update_Date_Time " +
" group by status; "
, function (err, rows) {
if (!err) {
console.log("Database is connected... \n");
console.log('The solution is: ', rows[0]);
console.log('The solution is: ', rows[1]);
} else {
console.log("Error connecting database... \n");
console.log('Error while performing Query.');
}
console.log(rows[0]);
console.log(rows[1]);
res.end(JSON.stringify(rows[0]));
res.end(JSON.stringify(rows[1]));
});
});
var server = app.listen(8000, function () {
var port = server.address().port;
var host = server.address().address;
console.log('Example app listening at http://' + host + ':' + port);
});
AngularJs
**$scope.chartOpt1 = {
bindingOptions: {
dataSource: "sts"
},**
//Exposes the current URL in the browser address bar
//Maintains synchronization between itself and the browser's URL
//Represents the URL object as a set of methods
myApp.config(function ($routeProvider) {
$routeProvider
// route for the home page
.when('/', {
templateUrl: 'pages/home.html',
controller: 'mainController'
})
// route for the about page
.when('/about', {
templateUrl: 'pages/about.html',
controller: 'aboutController'
})
// route for the contact page
.when('/contact', {
templateUrl: 'pages/contact.html',
controller: 'contactController'
})
.when('/devicessts', {
templateUrl: 'pages/devicessts.html',
controller: 'devicesController'
})
.when('/sts', {
templateUrl: 'pages/sts.html',
controller: 'stsController'
});
// $locationProvider.html5Mode(true);
});
The result of the page:
Look at the data grid and pie chart aren't being showed in the page.
How do I retrieve the results from query to the angular?
Thank you
If you want get 2 responses you should :
post 2 request
OR
replace this
res.end(JSON.stringify(rows[0]));
res.end(JSON.stringify(rows[1]));
by this
res.end(JSON.stringify([rows[0],rows[1]]));
But a single http request can't send 2 responses