diff --git a/client/forbidden-markers-configuration-map.html b/client/forbidden-markers-configuration-map.html
index 5d5369f8..fe0b0b1a 100644
--- a/client/forbidden-markers-configuration-map.html
+++ b/client/forbidden-markers-configuration-map.html
@@ -56,15 +56,14 @@
const persistentData = {virtual_walls: map.getLocations().virtualWalls, no_go_areas: map.getLocations().forbiddenZones};
loadingBarSaveMarkers.setAttribute("indeterminate", "indeterminate");
saveButton.setAttribute("disabled", "disabled");
- fn.requestWithPayload("api/persistent_data", JSON.stringify(persistentData), "PUT", function (err) {
+ fn.prequestWithPayload("api/persistent_data", JSON.stringify(persistentData), "PUT")
+ .then(() => {
+ ons.notification.toast("Successfully saved forbidden markers!", { buttonLabel: 'Dismiss', timeout: window.fn.toastOKTimeout });
+ fn.popPage();
+ }, (err) => ons.notification.toast(err, { buttonLabel: 'Dismiss', timeout: window.fn.toastErrorTimeout }))
+ .finally(() => {
loadingBarSaveMarkers.removeAttribute("indeterminate");
saveButton.removeAttribute("disabled");
- if (err) {
- ons.notification.toast(err, { buttonLabel: 'Dismiss', timeout: window.fn.toastErrorTimeout })
- } else {
- ons.notification.toast("Successfully saved forbidden markers!", { buttonLabel: 'Dismiss', timeout: window.fn.toastOKTimeout });
- fn.popPage();
- }
});
}
diff --git a/client/home.html b/client/home.html
index af20a096..dac8f760 100644
--- a/client/home.html
+++ b/client/home.html
@@ -1,4 +1,4 @@
-
+
\ No newline at end of file
diff --git a/client/settings-carpet-mode.html b/client/settings-carpet-mode.html
index 94b6bdc7..dc9c73a3 100644
--- a/client/settings-carpet-mode.html
+++ b/client/settings-carpet-mode.html
@@ -70,21 +70,18 @@
function updateSettingsCarpetModePage() {
loadingBarSettingsCarpetMode.setAttribute("indeterminate", "indeterminate");
- fn.request("api/get_carpet_mode", "GET", function (err, res) {
- loadingBarSettingsCarpetMode.removeAttribute("indeterminate");
- if (err) {
- ons.notification.toast(err, { buttonLabel: 'Dismiss', timeout: window.fn.toastErrorTimeout })
- } else {
- var carpetForm = document.getElementById('carpet-mode-form');
- var result = res[0];
- carpetForm.current_low.value = result.current_low;
- carpetForm.current_high.value = result.current_high;
- carpetForm.current_integral.value = result.current_integral;
- carpetForm.stall_time.value = result.stall_time;
- document.getElementById('carpet_mode_enabled').checked = (result.enable==1);
- }
- })
- }
+ fn.prequest("api/get_carpet_mode", "GET")
+ .then((res) => {
+ var carpetForm = document.getElementById('carpet-mode-form');
+ var result = res[0];
+ carpetForm.current_low.value = result.current_low;
+ carpetForm.current_high.value = result.current_high;
+ carpetForm.current_integral.value = result.current_integral;
+ carpetForm.stall_time.value = result.stall_time;
+ document.getElementById('carpet_mode_enabled').checked = (result.enable==1);
+ },(err) => ons.notification.toast(err, { buttonLabel: 'Dismiss', timeout: window.fn.toastErrorTimeout }))
+ .finally(() => loadingBarSettingsCarpetMode.removeAttribute("indeterminate"));
+ };
function saveCarpetMode() {
ons.notification.confirm('Do you really want to save the modifications made in the carpet mode?').then(function (answer) {
@@ -96,16 +93,14 @@
var current_integral = carpetForm.current_integral.value;
var stall_time = carpetForm.stall_time.value;
var enable = (document.getElementById('carpet_mode_enabled').checked == true);
- fn.requestWithPayload("api/set_carpet_mode", JSON.stringify({ enable, current_low, current_high, current_integral, stall_time }), "PUT", function (err, res) {
- if (err) {
- loadingBarSettingsCarpetMode.removeAttribute("indeterminate");
- ons.notification.toast(err, { buttonLabel: 'Dismiss', timeout: window.fn.toastErrorTimeout })
- } else {
- updateSettingsCarpetModePage();
- }
- })
+ fn.prequestWithPayload("api/set_carpet_mode", JSON.stringify({ enable, current_low, current_high, current_integral, stall_time }), "PUT")
+ .then(
+ (res) => updateSettingsCarpetModePage(),
+ (err) => ons.notification.toast(err, { buttonLabel: 'Dismiss', timeout: window.fn.toastErrorTimeout })
+ )
+ .finally(() => loadingBarSettingsCarpetMode.removeAttribute("indeterminate"));
}
});
- }
+ };
\ No newline at end of file
diff --git a/client/settings-cleaning-history.html b/client/settings-cleaning-history.html
index 30841dd0..16328fa9 100644
--- a/client/settings-cleaning-history.html
+++ b/client/settings-cleaning-history.html
@@ -38,25 +38,19 @@
while (settingsCleaningHistory.lastChild) {
settingsCleaningHistory.removeChild(settingsCleaningHistory.lastChild);
}
- fn.request("api/clean_summary", "GET", function (err, res) {
- if (!err) {
- //summary succeeded
- historyArray = res[3];
- // getting current timezone for properly showing local time
- fn.request("api/get_timezone", "GET", function (err, res) {
- loadingBarSettingsCleaningHistory.removeAttribute("indeterminate");
- if (!err) {
- timeZone = res;
- loadNextRemainingElements();
- } else {
- ons.notification.toast(err, { buttonLabel: 'Dismiss', timeout: window.fn.toastErrorTimeout })
- }
- });
- } else {
- loadingBarSettingsCleaningHistory.removeAttribute("indeterminate");
- ons.notification.toast(err, { buttonLabel: 'Dismiss', timeout: window.fn.toastErrorTimeout })
- }
+ const getSummary = fn.prequest("api/clean_summary", "GET")
+ .then((res) => {
+ historyArray = res[3];
+ });
+ const getTimezone = fn.prequest("api/get_timezone", "GET")
+ .then((res) => {
+ timeZone = res;
});
+ Promise.all([getSummary, getTimezone])
+ .then(() => {
+ loadNextRemainingElements();
+ }, (err) => ons.notification.toast(err, { buttonLabel: 'Dismiss', timeout: window.fn.toastErrorTimeout }))
+ .finally(() => loadingBarSettingsCleaningHistory.removeAttribute("indeterminate"));
}
function formatTwoDigitNumber(number) {
@@ -74,62 +68,59 @@
if (remainingShownCount>0) {
loadingBarSettingsCleaningHistory.setAttribute("indeterminate", "indeterminate");
var historyTimestamp = historyArray.shift(); //array is sorted with latest items in the beginning
- fn.requestWithPayload("api/clean_record", JSON.stringify({recordId : historyTimestamp}) , "PUT", function (err, res) {
- loadingBarSettingsCleaningHistory.removeAttribute("indeterminate");
- if (err) {
- ons.notification.toast(err, { buttonLabel: 'Dismiss', timeout: window.fn.toastErrorTimeout });
- } else {
- //adjust counters
- remainingShownCount--;
- //set variables
- var currentEntryId = historyArray.length+1;
- var fromTime = formatDate(new Date(new Date(res.startTime).toLocaleString("en-US", { timeZone: timeZone })));
- var durationTotalSeconds = res.duration;
- var durationHours = Math.floor(durationTotalSeconds / 3600);
- var remsecs = durationTotalSeconds % 3600;
- var durationMinutes = Math.floor(remsecs / 60);
- var durationSeconds = (remsecs % 60);
- var area = Math.round(res.area / 1000000);
- var errorCode = res.errorCode;
- var errorDescription = res.errorDescription;
- var completedFlag = res.finishedFlag;
- settingsCleaningHistory.appendChild(ons.createElement(
- "\n" +
- " " +
- " " +
- " #" + currentEntryId + " started on " + fromTime + "" +
- " " +
- " " +
- " " +
- " " +
- " Duration" +
- " " + durationHours + ":" + formatTwoDigitNumber(durationMinutes) + ":" + formatTwoDigitNumber(durationSeconds) + "" +
- " " +
- " "+
- " " +
- " " +
- " Area" +
- " " + area + " m2" +
- " " +
- " "+
- " " +
- " " +
- " Completed" +
- " " + (completedFlag?"":"") + "" +
- " " +
- " "+
- (errorCode>0?
- " " +
- " " +
- " " + errorDescription + " (Code: " + errorCode + ")" +
- " " +
- " "
- : "" ) +
- ""));
- //load next element
- loadNextRemainingElements();
- }
- });
+ fn.prequestWithPayload("api/clean_record", JSON.stringify({recordId : historyTimestamp}), "PUT")
+ .then((res) => {
+ //adjust counters
+ remainingShownCount--;
+ //set variables
+ var currentEntryId = historyArray.length+1;
+ var fromTime = formatDate(new Date(new Date(res.startTime).toLocaleString("en-US", { timeZone: timeZone })));
+ var durationTotalSeconds = res.duration;
+ var durationHours = Math.floor(durationTotalSeconds / 3600);
+ var remsecs = durationTotalSeconds % 3600;
+ var durationMinutes = Math.floor(remsecs / 60);
+ var durationSeconds = (remsecs % 60);
+ var area = Math.round(res.area / 1000000);
+ var errorCode = res.errorCode;
+ var errorDescription = res.errorDescription;
+ var completedFlag = res.finishedFlag;
+ settingsCleaningHistory.appendChild(ons.createElement(
+ "\n" +
+ " " +
+ " " +
+ " #" + currentEntryId + " started on " + fromTime + "" +
+ " " +
+ " " +
+ " " +
+ " " +
+ " Duration" +
+ " " + durationHours + ":" + formatTwoDigitNumber(durationMinutes) + ":" + formatTwoDigitNumber(durationSeconds) + "" +
+ " " +
+ " "+
+ " " +
+ " " +
+ " Area" +
+ " " + area + " m2" +
+ " " +
+ " "+
+ " " +
+ " " +
+ " Completed" +
+ " " + (completedFlag?"":"") + "" +
+ " " +
+ " "+
+ (errorCode>0?
+ " " +
+ " " +
+ " " + errorDescription + " (Code: " + errorCode + ")" +
+ " " +
+ " "
+ : "" ) +
+ ""));
+ //load next element
+ loadNextRemainingElements();
+ }, (err) => ons.notification.toast(err, { buttonLabel: 'Dismiss', timeout: window.fn.toastErrorTimeout }))
+ .finally(() => loadingBarSettingsCleaningHistory.removeAttribute("indeterminate"));
} else {
if (historyArray.length>0) {
//show link to load more
@@ -163,7 +154,7 @@
});
} else if (res && res[0] === "map_upload_handler") {
if (mapDataCached) {
- // the thing is when this is reply to the first request then map snapshot isn't actually being sent it seems
+ // the thing is when this reply is received after the first request then map snapshot isn't actually being sent it seems
fn.pushPage({
'id': 'settings-cleaning-history-map.html',
'title': 'Cleaning history map',
@@ -194,7 +185,9 @@
}
});
}, (err) => { throw err; })
- .catch((err) => ons.notification.toast(err, { buttonLabel: 'Dismiss', timeout: window.fn.toastErrorTimeout }))
+ .catch((err) => {
+ if (err !== "ok") ons.notification.toast(err, { buttonLabel: 'Dismiss', timeout: window.fn.toastErrorTimeout });
+ })
.finally(() => loadingBarSettingsCleaningHistory.removeAttribute("indeterminate"));
};
diff --git a/client/settings-consumables.html b/client/settings-consumables.html
index 8a90081e..2c28043a 100644
--- a/client/settings-consumables.html
+++ b/client/settings-consumables.html
@@ -105,37 +105,31 @@
ons.notification.confirm('Do you really want to reset this consumable?').then(function (answer) {
if (answer === 1) {
loadingBarSettingsConsumables.setAttribute("indeterminate", "indeterminate");
-
- fn.requestWithPayload("api/reset_consumable", JSON.stringify({ consumable: consumable }), "PUT", function (err, res) {
- if (err) {
- loadingBarSettingsConsumables.removeAttribute("indeterminate");
- ons.notification.toast(err, { buttonLabel: 'Dismiss', timeout: window.fn.toastErrorTimeout })
- } else {
- updateSettingsConsumablesPage();
- }
- })
+ fn.prequestWithPayload("api/reset_consumable", JSON.stringify({ consumable: consumable }), "PUT")
+ .then(
+ (res) => updateSettingsConsumablesPage(),
+ (err) => ons.notification.toast(err, { buttonLabel: 'Dismiss', timeout: window.fn.toastErrorTimeout })
+ )
+ .finally(() => loadingBarSettingsConsumables.removeAttribute("indeterminate"));
}
});
- }
+ };
function updateSettingsConsumablesPage() {
loadingBarSettingsConsumables.setAttribute("indeterminate", "indeterminate");
- fn.request("api/consumable_status", "GET", function (err, res) {
- loadingBarSettingsConsumables.removeAttribute("indeterminate");
- if (!err) {
- consumableMainBrushStatus.innerHTML = (Math.max(0, 300 - (res.consumables.main_brush_work_time / 60 / 60))).toFixed(1) + " hours left";
- consumableSideBrushStatus.innerHTML = (Math.max(0, 200 - (res.consumables.side_brush_work_time / 60 / 60))).toFixed(1) + " hours left";
- consumableFilterStatus.innerHTML = (Math.max(0, 150 - (res.consumables.filter_work_time / 60 / 60))).toFixed(1) + " hours left";
- consumableSensorStatus.innerHTML = (Math.max(0, 30 - (res.consumables.sensor_dirty_time / 60 / 60))).toFixed(1) + " hours left";
+ fn.prequest("api/consumable_status", "GET")
+ .then((res) => {
+ consumableMainBrushStatus.innerHTML = (Math.max(0, 300 - (res.consumables.main_brush_work_time / 60 / 60))).toFixed(1) + " hours left";
+ consumableSideBrushStatus.innerHTML = (Math.max(0, 200 - (res.consumables.side_brush_work_time / 60 / 60))).toFixed(1) + " hours left";
+ consumableFilterStatus.innerHTML = (Math.max(0, 150 - (res.consumables.filter_work_time / 60 / 60))).toFixed(1) + " hours left";
+ consumableSensorStatus.innerHTML = (Math.max(0, 30 - (res.consumables.sensor_dirty_time / 60 / 60))).toFixed(1) + " hours left";
- consumableStatisticsArea.innerHTML = (res.summary[1] / 1000000).toFixed(1) + " m²";
- consumableStatisticsHours.innerHTML = (res.summary[0] / 60 / 60).toFixed(1) + " hours";
- consumableStatisticsCount.innerHTML = res.summary[2];
- } else {
- ons.notification.toast(err, { buttonLabel: 'Dismiss', timeout: window.fn.toastErrorTimeout })
- }
- });
- }
+ consumableStatisticsArea.innerHTML = (res.summary[1] / 1000000).toFixed(1) + " m²";
+ consumableStatisticsHours.innerHTML = (res.summary[0] / 60 / 60).toFixed(1) + " hours";
+ consumableStatisticsCount.innerHTML = res.summary[2];
+ }, (err) => ons.notification.toast(err, { buttonLabel: 'Dismiss', timeout: window.fn.toastErrorTimeout }))
+ .finally(() => loadingBarSettingsConsumables.removeAttribute("indeterminate"));
+ };