add sensor , sensorItemMapping create

This commit is contained in:
snoop 2017-06-09 20:02:39 +09:00
parent 7d80746c5b
commit 97e567bcd5
2 changed files with 56 additions and 4 deletions

View File

@ -13,7 +13,7 @@ export class OFRest {
"serviceName": serviceName,
"methodName": methodName,
"param": {
"model" : JSON.stringify(data)
"model": JSON.stringify(data)
}
};
@ -30,5 +30,25 @@ export class OFRest {
});
}
public CallWithCB(callback: Function) {
fetch(url, {
method: 'POST',
headers: {
'Accept': 'application/json',
},
body: JSON.stringify(this.obj)
}).then(function (res) {
return res.json();
}).then(function (json) {
if (json.error != undefined) {
console.log(json.error);
return;
}
callback(json);
}).catch(function (err) {
console.log(err);
});
}
}

View File

@ -54,8 +54,8 @@ export class SensorConfigPopup extends React.Component<any, any> {
handleCrawlerSelect = (c: any) => {
//getting items by target&crawler type
let os: OFRest = new OFRest("SensorItem", "List", JSON.stringify(c));
console.log("aaaaaaa");
let os: OFRest = new OFRest("SensorItem", "List", c);
var that: any = this;
os.Call().then(function (res) {
return res.json();
@ -201,11 +201,12 @@ export class CrawlerSelector extends React.Component<any, any> {
this.setState({
authOpen: false,
});
let os: OFRest = new OFRest("Crawlerinputitemmapping", "List", c);
let os: OFRest = new OFRest("CrawlerinputitemMapping", "List", c);
var that: any = this;
os.Call().then(function (res) {
return res.json();
}).then(function (json) {
var list = JSON.parse(json.resultStr);
that.setState({
authInputs: list,
@ -370,6 +371,37 @@ export class ConfirmPopup extends React.Component<any, any> {
alert("err");
return;
}
let sensor: any;
sensor = {
"target": this.props.target,
"notification": "",
"interval" : 10,
"crawler" : this.props.crawler,
}
let os: OFRest = new OFRest("Sensor", "Create", sensor);
var that: any = this;
os.CallWithCB(function (json: any) {
let retSensor = JSON.parse(json.resultStr);
let smlist :any[] = [];
that.props.items.map((data: any, index: number) => {
var sm :any;
sm = {
"sensor" : retSensor,
"sensorItem":data,
}
smlist.push(sm);
});
let os2: OFRest = new OFRest("SensorItemMapping", "CreateAll", smlist);
os2.CallWithCB(function(json2 :any) {
console.log(json2);
});
});
// this.props.items
// let os: OFRest = new OFRest("SensorItem", "List", JSON.stringify(c));
// var that: any = this;
// os.Call().then(function (res) {