diff --git a/sysutils/dec-hw/src/opnsense/mvc/app/controllers/OPNsense/dechw/Api/InfoController.php b/sysutils/dec-hw/src/opnsense/mvc/app/controllers/OPNsense/dechw/Api/InfoController.php index ad0393ba4..66b819c93 100644 --- a/sysutils/dec-hw/src/opnsense/mvc/app/controllers/OPNsense/dechw/Api/InfoController.php +++ b/sysutils/dec-hw/src/opnsense/mvc/app/controllers/OPNsense/dechw/Api/InfoController.php @@ -35,20 +35,11 @@ class InfoController extends ApiControllerBase { public function powerStatusAction() { - $result = [ - "status" => "failed", - "status_translated" => gettext("Power status could not be fetched. - This widget is only applicable to Deciso hardware with dual power supplies.") - ]; + $result = ["status" => "failed"]; $status = parse_ini_string((new Backend())->configdRun('dechw power')); if (!empty($status)) { $result["status"] = "OK"; - unset($result["status_translated"]); - - foreach (['pwr1', 'pwr2'] as $key) { - $result[$key . '_translated'] = $status[$key] === '1' ? gettext('On') : gettext('Off'); - } $result = array_merge($result, $status); } diff --git a/sysutils/dec-hw/src/opnsense/www/js/widgets/DecHW.js b/sysutils/dec-hw/src/opnsense/www/js/widgets/DecHW.js new file mode 100644 index 000000000..a5657599b --- /dev/null +++ b/sysutils/dec-hw/src/opnsense/www/js/widgets/DecHW.js @@ -0,0 +1,100 @@ +/* + * Copyright (C) 2024 Deciso B.V. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +import BaseWidget from "./BaseWidget.js"; + +export default class DecHW extends BaseWidget { + constructor() { + super(); + } + + getMarkup() { + const styles = ` + #status { + margin: 10px; + } + .power { + margin: 5px; + float: right; + } + .power:hover { + opacity: 0.5; + } + .pwr-container { + margin: 5px; + display: flex; + justify-content: center; + align-items: center; + } + .data-item { + padding: 10px; + border: 1px solid #ddd; + margin: 5px; + width: 50%; + display: inline-block; + } + `; + + const styleSheet = document.createElement("style"); + styleSheet.innerText = styles; + document.head.appendChild(styleSheet); + + return $(` +
+
+
+ ${this.translations.powersupply} 1 +
+
+ ${this.translations.powersupply} 2 +
+
+ `); + } + + async onWidgetTick() { + $('.power').tooltip('hide'); + let data = await this.ajaxCall('/api/dechw/info/powerStatus'); + + if (!data || data.status === 'failed') { + $('#status').html(`
${this.translations.nopower}
`); + $('.pwr-container').hide(); + return; + } + + $('.power').remove(); + ['pwr1', 'pwr2'].forEach((key) => { + let status = data[key]; + + let $power = $(``); + $power.css('color', status === '1' ? 'blue' : 'red'); + $power.attr('title', status === '1' ? this.translations.poweron : this.translations.poweroff); + $(`#${key}`).append($power); + }); + + $('.power').tooltip({container: 'body'}); + } +} \ No newline at end of file diff --git a/sysutils/dec-hw/src/opnsense/www/js/widgets/Metadata/DecHW.xml b/sysutils/dec-hw/src/opnsense/www/js/widgets/Metadata/DecHW.xml new file mode 100644 index 000000000..a059d6edb --- /dev/null +++ b/sysutils/dec-hw/src/opnsense/www/js/widgets/Metadata/DecHW.xml @@ -0,0 +1,15 @@ + + + DecHW.js + + /api/dechw/info/powerStatus + + + Deciso Hardware Information + Power status could not be fetched. This widget is only applicable to Deciso hardware with dual power supplies. + Power is on + Power is off + Power Supply + + + \ No newline at end of file diff --git a/sysutils/dec-hw/src/www/widgets/include/dechw.inc b/sysutils/dec-hw/src/www/widgets/include/dechw.inc deleted file mode 100644 index 64b611402..000000000 --- a/sysutils/dec-hw/src/www/widgets/include/dechw.inc +++ /dev/null @@ -1,3 +0,0 @@ - - - - - - -
-
-
- -
-
- -
-