Box improvement and some experimental signalk code in webgui

This commit is contained in:
2026-09-15 08:42:56 +02:00
parent 57c42d1398
commit a76848e1da
6 changed files with 91 additions and 9 deletions
+1
View File
@@ -3,6 +3,7 @@ __pycache__/
*.txt *.txt
*.bak *.bak
*.pot *.pot
*.mo
compare_* compare_*
# Debian package build artifacts # Debian package build artifacts
+6 -3
View File
@@ -176,9 +176,11 @@ CREATE TABLE box (
color char(6) DEFAULT NULL, color char(6) DEFAULT NULL,
content varchar(60) DEFAULT NULL, content varchar(60) DEFAULT NULL,
weight float(5,2) UNSIGNED DEFAULT NULL, weight float(5,2) UNSIGNED DEFAULT NULL,
wx smallint(6) UNSIGNED NOT NULL DEFAULT 0, weight_net float(5,2) UNSIGNED DEFAULT NULL,
wy smallint(6) UNSIGNED NOT NULL DEFAULT 0, wx smallint(6) UNSIGNED NOT NULL DEFAULT 0, -- length
wz smallint(6) UNSIGNED NOT NULL DEFAULT 0, wy smallint(6) UNSIGNED NOT NULL DEFAULT 0, -- width
wz smallint(6) UNSIGNED NOT NULL DEFAULT 0, -- height
price decimal(12,2) DEFAULT NULL,
remarks varchar(150) DEFAULT NULL, remarks varchar(150) DEFAULT NULL,
PRIMARY KEY (boxid), PRIMARY KEY (boxid),
INDEX ix_label (label), INDEX ix_label (label),
@@ -303,6 +305,7 @@ CREATE table fuse (
) ENGINE=InnoDB; ) ENGINE=InnoDB;
-- change vals to decimal(12,4)? -- change vals to decimal(12,4)?
-- additional signalk id?
CREATE TABLE measurement ( CREATE TABLE measurement (
mid smallint(6) NOT NULL AUTO_INCREMENT, mid smallint(6) NOT NULL AUTO_INCREMENT,
mname varchar(80) NOT NULL, mname varchar(80) NOT NULL,
+3 -1
View File
@@ -17,7 +17,8 @@ INSERT INTO settings (userid, sno, valint, valstr) VALUES
(1, 1, 0), NULL, -- No vessel assignment to user "captain" (1, 1, 0), NULL, -- No vessel assignment to user "captain"
(0, 20, 1280, NULL), -- Image width limit (0, 20, 1280, NULL), -- Image width limit
(0, 21, 1024, NULL), -- Image height limit (0, 21, 1024, NULL), -- Image height limit
(0, 4, NULL, '€'); -- Currency symbol (0, 4, NULL, '€'), -- Currency symbol
(0, 5, 0, 'http://127.0.0.1:3000'); -- Signal K: to enable set valint=1
/* setting descriptions */ /* setting descriptions */
INSERT INTO settings (userid, sno, valstr) VALUES INSERT INTO settings (userid, sno, valstr) VALUES
@@ -26,6 +27,7 @@ INSERT INTO settings (userid, sno, valstr) VALUES
(-1, 2, 'date format'), (-1, 2, 'date format'),
(-1, 3, 'user menu'), (-1, 3, 'user menu'),
(-1, 4, 'currency symbol e.g. €, $, £, ¥'), (-1, 4, 'currency symbol e.g. €, $, £, ¥'),
(-1, 5, 'signalk connection'),
(-1, 10, 'rows in table'), (-1, 10, 'rows in table'),
(-1, 20, 'maximum image width'), (-1, 20, 'maximum image width'),
(-1, 21, 'maximum image height'), (-1, 21, 'maximum image height'),
+3 -1
View File
@@ -17,7 +17,8 @@ INSERT INTO settings (userid, sno, valint, valstr) VALUES
(1, 1, 0), NULL, -- No vessel assignment to user "captain" (1, 1, 0), NULL, -- No vessel assignment to user "captain"
(0, 20, 1280, NULL), -- Image width limit (0, 20, 1280, NULL), -- Image width limit
(0, 21, 1024, NULL), -- Image height limit (0, 21, 1024, NULL), -- Image height limit
(0, 4, NULL, '€'); -- Currency symbol (0, 4, NULL, '€'), -- Currency symbol
(0, 5, 0, 'http://127.0.0.1:3000'); -- Signal K: to enable set valint=1
/* setting descriptions */ /* setting descriptions */
INSERT INTO settings (userid, sno, valstr) VALUES INSERT INTO settings (userid, sno, valstr) VALUES
@@ -25,6 +26,7 @@ INSERT INTO settings (userid, sno, valstr) VALUES
(-1, 2, 'date format'), (-1, 2, 'date format'),
(-1, 3, 'user menu'), (-1, 3, 'user menu'),
(-1, 4, 'currency symbol e.g. €, $, £, ¥'), (-1, 4, 'currency symbol e.g. €, $, £, ¥'),
(-1, 5, 'signalk connection'),
(-1, 10, 'rows in table'), (-1, 10, 'rows in table'),
(-1, 20, 'maximum image width'), (-1, 20, 'maximum image width'),
(-1, 21, 'maximum image height'), (-1, 21, 'maximum image height'),
+42 -2
View File
@@ -60,7 +60,12 @@ switch ($submit = form_get_action()) {
$p[':label'] = gpc_get_string($_POST, 'label'); $p[':label'] = gpc_get_string($_POST, 'label');
$p[':content'] = gpc_get_string($_POST, 'content'); $p[':content'] = gpc_get_string($_POST, 'content');
$p[':color'] = gpc_get_color($_POST, 'color'); $p[':color'] = gpc_get_color($_POST, 'color');
$p[':wx'] = gpc_get_int($_POST, 'wx');
$p[':wy'] = gpc_get_int($_POST, 'wy');
$p[':wz'] = gpc_get_int($_POST, 'wz');
$p[':weight'] = min(gpc_get_float($_POST, 'weight'), 99.99); $p[':weight'] = min(gpc_get_float($_POST, 'weight'), 99.99);
$p[':weight_net'] = min(gpc_get_float($_POST, 'weight_net'), 99.99);
$p[':price'] = gpc_get_currency($_POST, 'price');
$p[':sid'] = gpc_get_uint($_POST, 'sid'); $p[':sid'] = gpc_get_uint($_POST, 'sid');
$p[':remarks'] = gpc_get_string($_POST, 'remarks', 150); $p[':remarks'] = gpc_get_string($_POST, 'remarks', 150);
db_exec_update('box', $p, 'boxid'); db_exec_update('box', $p, 'boxid');
@@ -163,7 +168,8 @@ foreach ($opt_storage as $k => $v) {
elseif ($action == ACT_VIEW): elseif ($action == ACT_VIEW):
// ========== VARIANT: view single record ===================================== // ========== VARIANT: view single record =====================================
$sql = "SELECT boxtype, label, content, box.color, weight, box.remarks, box.sid, sname " $sql = "SELECT boxtype, label, content, box.color, weight, weight_net, price, "
. "box.wx, box.wy, box.wz, box.sid, box.remarks, sname "
. "FROM box LEFT JOIN storage USING (sid) " . "FROM box LEFT JOIN storage USING (sid) "
. "WHERE boxid=?"; . "WHERE boxid=?";
$sth = $pdo->prepare($sql); $sth = $pdo->prepare($sql);
@@ -181,7 +187,10 @@ echo '<table class="table">', "\n";
echo '<tr><th style="width:20%">', _('Box type'),"</th><td>", ($opt_boxtype[$box->boxtype] ?? ''), "</td></tr>\n"; echo '<tr><th style="width:20%">', _('Box type'),"</th><td>", ($opt_boxtype[$box->boxtype] ?? ''), "</td></tr>\n";
echo '<tr><th>', _('Content'),"</th><td>", $box->content, "</td></tr>\n"; echo '<tr><th>', _('Content'),"</th><td>", $box->content, "</td></tr>\n";
echo '<tr><th>', _('Color'), '</th><td>', format_color($box->color), "</td></tr>\n"; echo '<tr><th>', _('Color'), '</th><td>', format_color($box->color), "</td></tr>\n";
# TODO also show sum of content weights for comparison
echo '<tr><th>', _('Weight'), '</th><td>', format_float($box->weight, 2, 'kg'), "</td></tr>\n"; echo '<tr><th>', _('Weight'), '</th><td>', format_float($box->weight, 2, 'kg'), "</td></tr>\n";
echo '<tr><th>', _('Empty&nbsp;Weight'), '</th><td>', format_float($box->weight_net, 2, 'kg'), "</td></tr>\n";
echo '<tr><th>', _('Price'),"</th><td>", format_currency($box->price), "</td></tr>\n";
echo '<tr><th>', _('Storage'),"</th><td>", $box->sname, '&nbsp;'; echo '<tr><th>', _('Storage'),"</th><td>", $box->sname, '&nbsp;';
echo '<a title="', _('View'), '" href="storage.php?f=view&id=', $box->sid, '"><i class="bi-eye"></i></a>'; echo '<a title="', _('View'), '" href="storage.php?f=view&id=', $box->sid, '"><i class="bi-eye"></i></a>';
echo "</td></tr>\n"; echo "</td></tr>\n";
@@ -276,10 +285,13 @@ if ($res) {
echo '<p>', _('Box is empty'), "</p>\n"; echo '<p>', _('Box is empty'), "</p>\n";
} }
# TODO provisions in box
elseif ($action == ACT_EDIT): elseif ($action == ACT_EDIT):
// ========== VARIANT: edit single record ===================================== // ========== VARIANT: edit single record =====================================
$sql = "SELECT boxtype, label, content, color, weight, sid, remarks " $sql = "SELECT boxtype, label, content, color, weight, weight_net, price, "
. "sid, wx, wy, wz, remarks "
. "FROM box " . "FROM box "
. "WHERE boxid=?"; . "WHERE boxid=?";
$sth = $pdo->prepare($sql); $sth = $pdo->prepare($sql);
@@ -305,10 +317,38 @@ echo '<h2>', _('Edit Box'), "</h2>\n";
<label for="color"><?=_('Color')?></label> <label for="color"><?=_('Color')?></label>
<input type="color" class="form-control" id="color" name="color" value="#<?=$box->color ?>"> <input type="color" class="form-control" id="color" name="color" value="#<?=$box->color ?>">
</div> </div>
<div class="mb-3">
<label class="form-label"><?=_('Dimensions (L × W × H)')?></label>
<div class="input-group">
<input type="number" class="form-control" name="wx"
value="<?=$box->wx;?>" min="0" step="1"
aria-label="<?=_('Length')?>">
<span class="input-group-text">×</span>
<input type="number" class="form-control" name="wy"
value="<?=$box->wy;?>" min="0" step="1"
aria-label="<?=_('Width')?>">
<span class="input-group-text">×</span>
<input type="number" class="form-control" name="wz"
value="<?=$box->wz;?>" min="0" step="1"
aria-label="<?=_('Height')?>">
<span class="input-group-text">mm</span>
</div>
<div class="form-text">
<?=_('Length × Width × Height')?>
</div>
</div>
<div class="mb-3"> <div class="mb-3">
<label for="weight" class="form-label"><?=_('Weight, kg')?></label> <label for="weight" class="form-label"><?=_('Weight, kg')?></label>
<input type="text" class="form-control" id="weight" name="weight" value="<?=format_float($box->weight); ?>"> <input type="text" class="form-control" id="weight" name="weight" value="<?=format_float($box->weight); ?>">
</div> </div>
<div class="mb-3">
<label for="weight_net" class="form-label"><?=_('Weight net, kg')?></label>
<input type="text" class="form-control" id="weight_net" name="weight_net" value="<?=format_float($box->weight_net); ?>">
</div>
<div class="mb-3">
<label for="price" class="form-label"><?=sprintf(_('Price, %s'), $g_lconv['currency_symbol']); ?></label>
<input type="text" class="form-control" id="price" name="price" value="<?=format_float($box->price) ?>">
</div>
<?php form_create_select('sid', _('Storage'), $opt_storage, $box->sid); ?> <?php form_create_select('sid', _('Storage'), $opt_storage, $box->sid); ?>
<div class="mb-3"> <div class="mb-3">
<label for="remarks" class="form-label"><?=_('Remarks')?></label> <label for="remarks" class="form-label"><?=_('Remarks')?></label>
+36 -2
View File
@@ -10,6 +10,7 @@ require 'globals.inc';
require 'lib/db.inc'; require 'lib/db.inc';
require 'lib/gpc.inc'; require 'lib/gpc.inc';
require 'lib/fileutils.inc'; require 'lib/fileutils.inc';
require 'lib/signalk.inc';
$pagetitle = _('Equipment'); $pagetitle = _('Equipment');
@@ -394,7 +395,7 @@ foreach ($res as $row) {
echo "<td>", $row['model'], "</td>\n"; echo "<td>", $row['model'], "</td>\n";
echo "<td>", $row['serial'], "</td>\n"; echo "<td>", $row['serial'], "</td>\n";
echo "<td>", $age, "</td>\n"; echo "<td>", $age, "</td>\n";
echo "<td>", $row['remarks'], "</td>\n"; echo "<td>", h($row['remarks'], br:true), "</td>\n";
// Edit current record button // Edit current record button
echo "<td>"; echo "<td>";
echo '<a title="', _('Edit'), '" href="', $g_scriptname, '?f=edit&id=', $row['eid'], '"><i class="bi-pencil"></i></a>', "\n"; echo '<a title="', _('Edit'), '" href="', $g_scriptname, '?f=edit&id=', $row['eid'], '"><i class="bi-pencil"></i></a>', "\n";
@@ -615,6 +616,39 @@ echo '<a href="measurement.php?f=add&id=', $id, '" class="btn btn-primary" role=
echo _('Add measurement'), "</a>\n"; echo _('Add measurement'), "</a>\n";
echo "</div>\n"; echo "</div>\n";
// Signal-K Integration
$res = $pdo->query("SELECT valint, valstr FROM settings WHERE userid=0 AND sno=5");
$sk_active = false;
$sk_url = NULL;
if ($res !== false) {
$row = $res->fetch(PDO::FETCH_ASSOC);
if ($row !== false && $row['valint'] == 1
&& !empty($row['valstr'])
&& filter_var($settings['valstr'], FILTER_VALIDATE_URL))
{
$sk_active = true;
$sk_url = rtrim($row['valstr'], '/');
}
}
if ($sk_active) {
// TODO this ist just experimental
$sql = "SELECT skpath FROM signalk WHERE vid=? AND objid=? AND objtype='equipment'";
$sth = $pdo->prepare($sql);
$sth->execute([$user->vid, $id]);
if ($sth->rowCount() > 0) {
echo '<h3>', _('Signal K data'), "</h3>";
$skpath = $sth->fetchColumn();
// REST Example:
// GET http://127.0.0.1:3000/signalk/v1/api/vessels/self/propulsion/mainEngine/runTime
try {
$data = signalk_get($url, $skpath);
print_r($data);
} catch (Exception $e) {
echo "<p>signalk-timeout!</p>\n";
}
}
}
// Spare parts // Spare parts
echo '<h3>', _('Spare parts'), "</h3>"; echo '<h3>', _('Spare parts'), "</h3>";
@@ -707,7 +741,7 @@ form_create_select('category', _('Category'), $g_opt_unknown + $opt_ecat, $equip
?> ?>
<div class="mb-3"> <div class="mb-3">
<label for="remarks" class="form-label"><?=_('Remarks')?></label> <label for="remarks" class="form-label"><?=_('Remarks')?></label>
<textarea class="form-control" id="remarks" name="remarks" rows="3"><?=h($equipment->remarks, br:true)?></textarea> <textarea class="form-control" id="remarks" name="remarks" rows="3"><?=h($equipment->remarks, br:false)?></textarea>
</div> </div>
<?php <?php
$opt_flags = db_load_enum('equipment', 'flags', true, true, false); $opt_flags = db_load_enum('equipment', 'flags', true, true, false);