Box improvement and some experimental signalk code in webgui
This commit is contained in:
+42
-2
@@ -60,7 +60,12 @@ switch ($submit = form_get_action()) {
|
||||
$p[':label'] = gpc_get_string($_POST, 'label');
|
||||
$p[':content'] = gpc_get_string($_POST, 'content');
|
||||
$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_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[':remarks'] = gpc_get_string($_POST, 'remarks', 150);
|
||||
db_exec_update('box', $p, 'boxid');
|
||||
@@ -163,7 +168,8 @@ foreach ($opt_storage as $k => $v) {
|
||||
elseif ($action == ACT_VIEW):
|
||||
// ========== 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) "
|
||||
. "WHERE boxid=?";
|
||||
$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>', _('Content'),"</th><td>", $box->content, "</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>', _('Empty 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, ' ';
|
||||
echo '<a title="', _('View'), '" href="storage.php?f=view&id=', $box->sid, '"><i class="bi-eye"></i></a>';
|
||||
echo "</td></tr>\n";
|
||||
@@ -276,10 +285,13 @@ if ($res) {
|
||||
echo '<p>', _('Box is empty'), "</p>\n";
|
||||
}
|
||||
|
||||
# TODO provisions in box
|
||||
|
||||
elseif ($action == ACT_EDIT):
|
||||
// ========== 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 "
|
||||
. "WHERE boxid=?";
|
||||
$sth = $pdo->prepare($sql);
|
||||
@@ -305,10 +317,38 @@ echo '<h2>', _('Edit Box'), "</h2>\n";
|
||||
<label for="color"><?=_('Color')?></label>
|
||||
<input type="color" class="form-control" id="color" name="color" value="#<?=$box->color ?>">
|
||||
</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">
|
||||
<label for="weight" class="form-label"><?=_('Weight, kg')?></label>
|
||||
<input type="text" class="form-control" id="weight" name="weight" value="<?=format_float($box->weight); ?>">
|
||||
</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); ?>
|
||||
<div class="mb-3">
|
||||
<label for="remarks" class="form-label"><?=_('Remarks')?></label>
|
||||
|
||||
+36
-2
@@ -10,6 +10,7 @@ require 'globals.inc';
|
||||
require 'lib/db.inc';
|
||||
require 'lib/gpc.inc';
|
||||
require 'lib/fileutils.inc';
|
||||
require 'lib/signalk.inc';
|
||||
|
||||
$pagetitle = _('Equipment');
|
||||
|
||||
@@ -394,7 +395,7 @@ foreach ($res as $row) {
|
||||
echo "<td>", $row['model'], "</td>\n";
|
||||
echo "<td>", $row['serial'], "</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
|
||||
echo "<td>";
|
||||
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 "</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
|
||||
echo '<h3>', _('Spare parts'), "</h3>";
|
||||
|
||||
@@ -707,7 +741,7 @@ form_create_select('category', _('Category'), $g_opt_unknown + $opt_ecat, $equip
|
||||
?>
|
||||
<div class="mb-3">
|
||||
<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>
|
||||
<?php
|
||||
$opt_flags = db_load_enum('equipment', 'flags', true, true, false);
|
||||
|
||||
Reference in New Issue
Block a user