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)
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));
}
}
});
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!
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
I've just started discovering Windows StoreApps (that's what Microsoft calls it) and I'm following the sample code here about using the FolderPicker.
I want to Iterate through the folder and read all the sub-folders and files.
There are two functions I've looked at which I thought are what I need but I'm not able to do it properly after trying hours.
In the link above, the line which says:
WinJS.log && WinJS.log("Picked folder: " + folder.name, "sample", "status");
I tried to dig deeper in the folder with something like:
folder.getFoldersAsync().then(function (folderItem) {
document.getElementById('musicFolder').innerHTML += folderItem.length + " folders)<br/>";
folderItem.forEach(function (x) {
document.getElementById('musicFolder').innerHTML += "--" + x.name + "<br/>";
x.getFilesAsync().then(function (items) {
document.getElementById('musicFolder').innerHTML += items.length + " files"+"<br>";
});
});
});
UPDATE:
I have been struggling but can't get the stuff organized while iterating folders and sub-folders.
#Damir's code doesn't dig deepest folder. We need a recursive function. I could come up with the following function but as I said result is not organized
function scanFolder(folder) {
var isInc = false;
folder.getFoldersAsync().then(function (folderItem) {
if (folderItem.length > 0) {
folderItem.forEach(function (x) {
if (!isInc) {
isInc = true;
hyphen += "-";
}
document.getElementById('musicFolder').innerHTML += hyphen + x.name + "</br>";
x.getFilesAsync().then(function (items) {
items.forEach(function (item) {
allTracks.push({
name: item.name,
path: item.path
});
document.getElementById('musicFolder').innerHTML += hyphen +"-"+ item.name + "</br>";
});
}).done(function () {
scanFolder(x);
});
});
}
});
}
You want to read all the subfolders and the files inside them? Something like this should work:
folder.getFoldersAsync().then(function (folderItem) {
document.getElementById('musicFolder').innerHTML += "(" + folderItem.length + " folders)<br/>";
folderItem.forEach(function (x) {
x.getFilesAsync().then(function (items) {
document.getElementById('musicFolder').innerHTML += "--" + x.name + " (" + items.length + " files)<br>";
items.forEach(function(item) {
document.getElementById('musicFolder').innerHTML += "----" + item.name + "<br>";
});
});
});
});
EDIT:
There's actually no need for recursion to recursively scan a folder and its subfolders in WinRT. You can use StorageFolder.CreateFileQueryWithOptions() instead:
var options = new Windows.Storage.Search.QueryOptions(Windows.Storage.Search.CommonFileQuery.defaultQuery, ['*']);
options.folderDepth = Windows.Storage.Search.FolderDepth.deep;
folder.createFileQueryWithOptions(options).getFilesAsync().then(function (files) {
var paths = new Array();
files.forEach(function(file) {
paths.push(file.path);
});
paths.sort();
paths.forEach(function(path) {
document.getElementById('musicFolder').innerHTML += path + "<br>";
});
});
From here on you can transform the flat list of files to whatever you need instead of just printing out their path.