Skip to content

Commit

Permalink
feat(ui): Bring back consumable monitoring & resetting for now
Browse files Browse the repository at this point in the history
* UI and API fix for comsumables

* fix(ui): Fix consumable reset for consumables with subType

Co-authored-by: bensweet86 <bensweet@outlook.com.au>
  • Loading branch information
Hypfer and bensweet86 committed Jan 18, 2021
1 parent 216c347 commit fde2ffd
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 23 deletions.
9 changes: 7 additions & 2 deletions client/services/api.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,13 @@ export class ApiService {
await this.fetch("PUT", "api/set_lab_status", {lab_status: labStatus});
}

static async resetConsumable(consumable) {
await this.fetch("PUT", "api/reset_consumable", {consumable: consumable});
static async resetConsumable(type, subType) {
var url = "api/v2/robot/capabilities/ConsumableMonitoringCapability/" + type;

if (subType) {
url += "/" + subType;
}
await this.fetch("PUT", url, {action: "reset"});
}

static async getConsumableStatus() {
Expand Down
12 changes: 6 additions & 6 deletions client/settings-consumables.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
??? hours left
</div>
<div class="right">
<ons-icon icon="fa-undo" class="list-item__icon" style="color: #eb5959;" onclick="handleConsumableResetButton('main_brush_work_time');"></ons-icon>
<ons-icon icon="fa-undo" class="list-item__icon" style="color: #eb5959;" onclick="handleConsumableResetButton('brush', 'main');"></ons-icon>
</div>
</ons-list-item>
<ons-list-item>
Expand All @@ -30,7 +30,7 @@
??? hours left
</div>
<div class="right">
<ons-icon icon="fa-undo" class="list-item__icon" style="color: #eb5959;" onclick="handleConsumableResetButton('side_brush_work_time');"></ons-icon>
<ons-icon icon="fa-undo" class="list-item__icon" style="color: #eb5959;" onclick="handleConsumableResetButton('brush', 'side_right');"></ons-icon>
</div>
</ons-list-item>
<ons-list-item>
Expand All @@ -41,18 +41,18 @@
??? hours left
</div>
<div class="right">
<ons-icon icon="fa-undo" class="list-item__icon" style="color: #eb5959;" onclick="handleConsumableResetButton('filter_work_time');"></ons-icon>
<ons-icon icon="fa-undo" class="list-item__icon" style="color: #eb5959;" onclick="handleConsumableResetButton('filter', 'main');"></ons-icon>
</div>
</ons-list-item>
<ons-list-item>
<div class="left consumables-list-item-title">
Sensor cleaning
Sensor Cleaning
</div>
<div class="center" id="settings-consumables-status-sensor" style="margin-left:5%">
??? hours left
</div>
<div class="right">
<ons-icon icon="fa-undo" class="list-item__icon" style="color: #eb5959;" onclick="handleConsumableResetButton('sensor_dirty_time');"></ons-icon>
<ons-icon icon="fa-undo" class="list-item__icon" style="color: #eb5959;" onclick="handleConsumableResetButton('sensor', 'all');"></ons-icon>
</div>
</ons-list-item>
</ons-list>
Expand Down Expand Up @@ -102,7 +102,7 @@
</script>
<style>
#consumables-list .consumables-list-item-title {
width: 130px;
width: 160px;
}
</style>
</ons-page>
20 changes: 10 additions & 10 deletions client/settings-consumables.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/*global ons */
import {ApiService} from "./services/api.service.js";

async function handleConsumableResetButton(consumable) {
async function handleConsumableResetButton(type, subType) {
var loadingBarSettingsConsumables = document.getElementById("loading-bar-settings-consumables");

let answer = await ons.notification.confirm("Do you really want to reset this consumable?");
if (answer === 1) {
loadingBarSettingsConsumables.setAttribute("indeterminate", "indeterminate");
try {
await ApiService.resetConsumable(consumable);
await ApiService.resetConsumable(type, subType);
updateSettingsConsumablesPage();
} catch (err) {
ons.notification.toast(err.message,
Expand All @@ -25,28 +25,28 @@ async function updateSettingsConsumablesPage() {
var consumableSideBrushStatus = document.getElementById("settings-consumables-status-side-brush");
var consumableFilterStatus = document.getElementById("settings-consumables-status-filter");
var consumableSensorStatus = document.getElementById("settings-consumables-status-sensor");
var consumableStatisticsArea =
/*var consumableStatisticsArea =
document.getElementById("settings-consumables-status-statistics-area");
var consumableStatisticsHours =
document.getElementById("settings-consumables-status-statistics-hours");
var consumableStatisticsCount =
document.getElementById("settings-consumables-status-statistics-count");
document.getElementById("settings-consumables-status-statistics-count");*/

loadingBarSettingsConsumables.setAttribute("indeterminate", "indeterminate");
try {
let res = await ApiService.getConsumableStatus();
consumableMainBrushStatus.innerHTML =
res.consumables.mainBrushLeftTime.toFixed(1) + " hours left";
(res.find(e => e.type === "brush" && e.subType === "main").remaining.value / 60).toFixed(1) + " hours left";
consumableSideBrushStatus.innerHTML =
res.consumables.sideBrushLeftTime.toFixed(1) + " hours left";
(res.find(e => e.type === "brush" && e.subType === "side_right").remaining.value / 60).toFixed(1) + " hours left";
consumableFilterStatus.innerHTML =
res.consumables.filterLeftTime.toFixed(1) + " hours left";
(res.find(e => e.type === "filter" && e.subType === "main").remaining.value / 60).toFixed(1) + " hours left";
consumableSensorStatus.innerHTML =
res.consumables.sensorLeftTime.toFixed(1) + " hours left";
(res.find(e => e.type === "sensor" && e.subType === "all").remaining.value / 60).toFixed(1) + " hours left";

consumableStatisticsArea.innerHTML = res.summary.cleanArea.toFixed(1) + " m²";
/*consumableStatisticsArea.innerHTML = res.summary.cleanArea.toFixed(1) + " m²";
consumableStatisticsHours.innerHTML = res.summary.cleanTime.toFixed(1) + " hours";
consumableStatisticsCount.innerHTML = res.summary.cleanCount;
consumableStatisticsCount.innerHTML = res.summary.cleanCount;*/
} catch (err) {
ons.notification.toast(err.message,
{buttonLabel: "Dismiss", timeout: window.fn.toastErrorTimeout});
Expand Down
4 changes: 2 additions & 2 deletions client/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
<div class="title"><ons-icon icon="fa-map"></ons-icon> Persistent Data</div>
<div class="content">Configure the lab mode for enabling virtual walls etc.</div>
</ons-card>
<!--

<ons-card onclick="fn.pushPage({'id': 'settings-consumables.html', 'title': 'Consumables'})">
<div class="title"><ons-icon icon="fa-wrench"></ons-icon> Consumables</div>
<div class="content">View and/or reset consumable usage counters</div>
</ons-card>
-->

<!--
<ons-card onclick="fn.pushPage({'id': 'settings-cleaning-history.html', 'title': 'Cleaning History'})">
<div class="title"><ons-icon icon="fa-history"></ons-icon> Cleaning History</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ class ConsumableMonitoringCapabilityRouter extends CapabilityRouter {
if (req.body && req.body.action) {
if (req.body.action === "reset") {
try {
await this.capability.resetConsumable(req.params.type, req.params.subType);
await this.capability.resetConsumable(req.params.type, req.params.sub_type);
res.sendStatus(200);
} catch (e) {
Logger.warn("Error while resetting consumable " + req.params.type + " " + req.params.subType, e);
Logger.warn("Error while resetting consumable " + req.params.type + " " + req.params.sub_type, e);
res.status(500).json(e.message);
}
} else {
Expand All @@ -29,4 +29,4 @@ class ConsumableMonitoringCapabilityRouter extends CapabilityRouter {
}
}

module.exports = ConsumableMonitoringCapabilityRouter;
module.exports = ConsumableMonitoringCapabilityRouter;

0 comments on commit fde2ffd

Please sign in to comment.