add button for adding new zone infos to device
This commit is contained in:
parent
fa16d1206b
commit
7f62fc9bec
@ -30,7 +30,6 @@ public class DeviceRequest extends PostRequest {
|
|||||||
try {
|
try {
|
||||||
setconfigured.last();
|
setconfigured.last();
|
||||||
int configsize = setconfigured.getRow();
|
int configsize = setconfigured.getRow();
|
||||||
System.out.println(configsize);
|
|
||||||
setconfigured.first();
|
setconfigured.first();
|
||||||
setconfigured.previous();
|
setconfigured.previous();
|
||||||
|
|
||||||
@ -40,30 +39,29 @@ public class DeviceRequest extends PostRequest {
|
|||||||
|
|
||||||
sb.append("{\"deviceid\":\"" + deviceid + "\",\"cityid\":\"" + cityid + "\"}");
|
sb.append("{\"deviceid\":\"" + deviceid + "\",\"cityid\":\"" + cityid + "\"}");
|
||||||
|
|
||||||
if (!(setunconfigured.isLast() && configsize==0)) {
|
if (!(setunconfigured.isLast() && configsize == 0)) {
|
||||||
sb.append(",");
|
sb.append(",");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
while (setconfigured.next()) {
|
while (setconfigured.next()) {
|
||||||
int deviceid = setconfigured.getInt("DeviceID");
|
int deviceid = setconfigured.getInt("DeviceID");
|
||||||
int cityid = setconfigured.getInt("CityID");
|
int cityid = setconfigured.getInt("CityID");
|
||||||
|
|
||||||
String devicename = setconfigured.getString("DeviceName");
|
String devicename = setconfigured.getString("DeviceName");
|
||||||
String devicelocation = setconfigured.getString("DeviceLocation");
|
String devicelocation = setconfigured.getString("DeviceLocation");
|
||||||
|
|
||||||
String cityname = setconfigured.getString("name");
|
String cityname = setconfigured.getString("name");
|
||||||
String wastetype = setconfigured.getString("wastetype");
|
String wastetype = setconfigured.getString("wastetype");
|
||||||
String zone = setconfigured.getString("zone");
|
String zone = setconfigured.getString("zone");
|
||||||
|
|
||||||
sb.append("{\"deviceid\":\"" + deviceid + "\",\"cityid\":\"" + cityid + "\",\"devicename\":\"" + devicename + "\",\"devicelocation\":\"" + devicelocation + "\",\"cityname\":\"" + cityname + "\",\"wastetype\":\"" + wastetype + "\",\"zone\":\"" + zone + "\"}");
|
sb.append("{\"deviceid\":\"" + deviceid + "\",\"cityid\":\"" + cityid + "\",\"devicename\":\"" + devicename + "\",\"devicelocation\":\"" + devicelocation + "\",\"cityname\":\"" + cityname + "\",\"wastetype\":\"" + wastetype + "\",\"zone\":\"" + zone + "\"}");
|
||||||
|
|
||||||
if (!setconfigured.isLast()) {
|
if (!setconfigured.isLast()) {
|
||||||
sb.append(",");
|
sb.append(",");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
sb.append("]}");
|
sb.append("]}");
|
||||||
System.out.println(sb.toString());
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -159,6 +157,26 @@ public class DeviceRequest extends PostRequest {
|
|||||||
}
|
}
|
||||||
sb.append("{\"status\":\"success\"}");
|
sb.append("{\"status\":\"success\"}");
|
||||||
break;
|
break;
|
||||||
|
case "getDeviceNumber":
|
||||||
|
// TODO: 18.01.20
|
||||||
|
break;
|
||||||
|
case "addtodb":
|
||||||
|
// TODO: 18.01.20
|
||||||
|
|
||||||
|
setunconfigured = jdbc.executeQuery("select * from cities WHERE `name`='" + params.get("cityname") + "' AND `zone`='" + params.get("zonename") + "' AND `wastetype`='" + params.get("wastetype") + "'");
|
||||||
|
try {
|
||||||
|
setunconfigured.last();
|
||||||
|
if (setunconfigured.getRow() != 1) {
|
||||||
|
// TODO: 17.01.20 error handling
|
||||||
|
} else {
|
||||||
|
int id = setunconfigured.getInt("id");
|
||||||
|
jdbc.executeUpdate("UPDATE devices SET `CityID`='" + id + "',`DeviceName`='" + params.get("devicename") + "',`DeviceLocation`='" + params.get("devicelocation") + "' WHERE `DeviceID`='" + params.get("deviceid") + "'");
|
||||||
|
sb.append("{\"success\":\"true\"}");
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
@ -189,8 +189,8 @@
|
|||||||
<th>Device ID</th>
|
<th>Device ID</th>
|
||||||
<th>Devicename</th>
|
<th>Devicename</th>
|
||||||
<th>Devicelocation</th>
|
<th>Devicelocation</th>
|
||||||
<th>Zone</th>
|
<th>WasteType</th>
|
||||||
<th>X</th>
|
<th>Action</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody id="devices-tablebody">
|
<tbody id="devices-tablebody">
|
||||||
@ -200,8 +200,8 @@
|
|||||||
<th>Device ID</th>
|
<th>Device ID</th>
|
||||||
<th>Devicename</th>
|
<th>Devicename</th>
|
||||||
<th>Devicelocation</th>
|
<th>Devicelocation</th>
|
||||||
<th>Zone</th>
|
<th>WasteType</th>
|
||||||
<th>X</th>
|
<th>Action</th>
|
||||||
</tr>
|
</tr>
|
||||||
</tfoot>
|
</tfoot>
|
||||||
</table>
|
</table>
|
||||||
|
@ -28,18 +28,108 @@ $(document).ready(function () {
|
|||||||
var cityzone = data.data[i].zone;
|
var cityzone = data.data[i].zone;
|
||||||
var wastetype = data.data[i].wastetype;
|
var wastetype = data.data[i].wastetype;
|
||||||
|
|
||||||
//todo load right names from db
|
$("#devices-tablebody").append("<tr><td>" + id + "</td><td>" + devicename + "</td><td>" + devicelocation + "</td><td>" + cityname + "/" + wastetype + "/" + cityzone + "</td><td><button dataid='" + id + "' type='button' class='delbtn btn btn-danger'>X</button><button dataid='" + id + "' type='button' class='addbtn btn btn-success'>ADD</button></td></tr>");
|
||||||
$("#devices-tablebody").append("<tr><td>" + id + "</td><td>" + devicename + "</td><td>" + devicelocation + "</td><td>" + cityname + "/" + wastetype + "/" + cityzone + "</td><td><button dataid='" + id + "' type='button' class='delbtn btn btn-danger'>X</button></td></tr>");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
addDeleteButton();
|
addDeleteButton();
|
||||||
|
addAddButton();
|
||||||
addConfigDialog();
|
addConfigDialog();
|
||||||
devicetable = $('#table-devices').DataTable();
|
devicetable = $('#table-devices').DataTable();
|
||||||
}, 'json');
|
}, 'json');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function addAddButton() {
|
||||||
|
$('.addbtn').click(function (event) {
|
||||||
|
var id = event.target.getAttribute("deviceid");
|
||||||
|
var cityname;
|
||||||
|
var zone;
|
||||||
|
var wastetype;
|
||||||
|
var devicename;
|
||||||
|
var devicelocation;
|
||||||
|
|
||||||
|
$.post('/senddata/Devicedata', 'action=getCitynames', function (data) {
|
||||||
|
Swal.mixin({
|
||||||
|
input: 'text',
|
||||||
|
confirmButtonText: 'Next →',
|
||||||
|
showCancelButton: true,
|
||||||
|
progressSteps: ['1']
|
||||||
|
}).queue([{
|
||||||
|
title: 'City',
|
||||||
|
text: 'Select your City',
|
||||||
|
input: 'select',
|
||||||
|
inputOptions: data
|
||||||
|
}
|
||||||
|
]).then((result) => {
|
||||||
|
if (result.value) {
|
||||||
|
console.log(result.value);
|
||||||
|
const answers = JSON.stringify(result.value);
|
||||||
|
cityname = result.value[0];
|
||||||
|
|
||||||
|
console.log("cityname=" + cityname);
|
||||||
|
$.post('/senddata/Devicedata', 'action=getzones&cityname=' + cityname, function (data) {
|
||||||
|
Swal.mixin({
|
||||||
|
input: 'text',
|
||||||
|
confirmButtonText: 'Next →',
|
||||||
|
showCancelButton: true,
|
||||||
|
progressSteps: ['1']
|
||||||
|
}).queue([
|
||||||
|
{
|
||||||
|
title: 'City',
|
||||||
|
text: 'Select your City',
|
||||||
|
input: 'select',
|
||||||
|
inputOptions: data
|
||||||
|
}
|
||||||
|
]).then((result) => {
|
||||||
|
if (result.value) {
|
||||||
|
console.log(result.value);
|
||||||
|
zone = result.value[0];
|
||||||
|
$.post('/senddata/Devicedata', 'action=gettypes&cityname=' + cityname + '&zonename=' + zone, function (data) {
|
||||||
|
Swal.mixin({
|
||||||
|
input: 'text',
|
||||||
|
confirmButtonText: 'Next →',
|
||||||
|
showCancelButton: true,
|
||||||
|
progressSteps: ['1']
|
||||||
|
}).queue([
|
||||||
|
{
|
||||||
|
title: 'City',
|
||||||
|
text: 'Select your City',
|
||||||
|
input: 'select',
|
||||||
|
inputOptions: data
|
||||||
|
}
|
||||||
|
]).then((result) => {
|
||||||
|
if (result.value) {
|
||||||
|
console.log(result.value);
|
||||||
|
wastetype = result.value[0];
|
||||||
|
|
||||||
|
|
||||||
|
//todo add to db
|
||||||
|
$.post('/senddata/Devicedata', 'action=addtodb&deviceid=' + id + '&cityname=' + cityname + '&zonename=' + zone + '&wastetype=' + wastetype, function (data) {
|
||||||
|
if (data.success) {
|
||||||
|
Swal.fire({
|
||||||
|
type: "success",
|
||||||
|
title: 'Successfully configured!',
|
||||||
|
html: 'This alert closes automatically.',
|
||||||
|
timer: 1000,
|
||||||
|
}).then((result) => {
|
||||||
|
console.log('Popup closed. ');
|
||||||
|
reloadDevices();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function addDeleteButton() {
|
function addDeleteButton() {
|
||||||
$(".delbtn").click(function (event) {
|
$(".delbtn").click(function (event) {
|
||||||
var id = event.target.getAttribute("dataid");
|
var id = event.target.getAttribute("dataid");
|
||||||
|
Loading…
Reference in New Issue
Block a user