Webgui improve maintenance list and filter

This commit is contained in:
thooge committed 2026-10-21 20:06:15 +02:00
1 parent 06a9834688
commit c2df7e8013
3 files changed
+79 -22

No files matched your search

+39 -11
View File
@@ -853,30 +853,58 @@ function form_get_action() {
return strtolower($submit); return strtolower($submit);
} }
function form_create_numeric($fieldname, $label, $value=NULL, $float=NULL) { function form_create_numeric($fieldname, $label, $min=NULL, $max=NULL, $step=NULL, $value=NULL) {
// TODO WIP // TODO WIP
// step = any float
// step = 0.01 float
// step = 1 integer
echo '<div class="mb-3">', "\n"; echo '<div class="mb-3">', "\n";
echo '<input type="number"';
echo ">\n";
echo "</div>\n"; echo "</div>\n";
} }
function form_create_text($fieldname, $label, $value=NULL, $maxlen=NULL) { function form_create_text($fieldname, $label, $maxlen=NULL, $value=NULL) {
// create generic text entry with assigned label // create generic text entry with assigned label
// TODO maxlength, required, errortext // TODO required, errortext
echo '<div class="mb-3">', "\n"; echo '<div class="mb-3">', "\n";
echo '<label for="', $fieldname, '" class="form-label">', $label, "</label>\n"; echo '<label for="', $fieldname, '" class="form-label">', $label, "</label>\n";
echo '<input type="text" class="form-control" id="', $fieldname, '" name="', $fieldname; echo '<input type="text" class="form-control" id="', $fieldname, '" name="', $fieldname, '"';
if ($value !== NULL) { if ($maxlen !== NULL) {
echo ' value="', $value, '"'; echo ' maxlength="', $maxlen, '"';
} }
echo '">', "\n"; if ($value !== NULL) {
echo ' value="', h($value), '"';
}
echo ">\n";
echo "</div>\n"; echo "</div>\n";
} }
function form_create_textarea($fieldname, $label, $value) { function form_create_textarea($fieldname, $label, $rows=3, $maxlen=NULL, $value=NULL) {
// TBD
echo '<div class="mb-3">', "\n"; echo '<div class="mb-3">', "\n";
echo '<textarea>'; echo '<label for="', $fieldname, '" class="form-label">', $label, "</label>\n";
echo '</textarea>', "\n"; echo '<textarea class="form-control" id="', $fieldname, '" name="', $fieldname, '"';
echo ' rows="', $rows, '"';
if ($maxlen !== NULL) {
echo ' maxlength="', $maxlen, '"';
}
echo '>';
if ($value !== NULL) {
echo h($value);
}
echo "</textarea>\n";
echo "</div>\n";
}
function form_create_color($fieldname, $label, $value=NULL) {
// value has to be 6char hex
echo '<div class="mb-3">', "\n";
echo '<label for="', $fieldname, '" class="form-label">', $label, "</label>\n";
echo '<input type="color" class="form-control" id="', $fieldname, '" name="', $fieldname, '"';
if ($value !== NULL) {
echo ' value="#', $value, '"';
}
echo ">\n";
echo "</div>\n"; echo "</div>\n";
} }
+29 -4
View File
@@ -32,6 +32,8 @@ switch ($submit = form_get_action()) {
$flt = array(); $flt = array();
$flt['equip'] = gpc_get_int($_POST, 'flt_equip'); $flt['equip'] = gpc_get_int($_POST, 'flt_equip');
$flt['txt'] = gpc_get_string($_POST, 'flt_txt'); $flt['txt'] = gpc_get_string($_POST, 'flt_txt');
$allowed = db_load_enum('maintenance', 'maintstate');
$flt['status'] = gpc_get_set($_POST, 'flt_status', $allowed);
db_save_filter($flt, 204); db_save_filter($flt, 204);
$action = ACT_DEFAULT; $action = ACT_DEFAULT;
break; break;
@@ -112,6 +114,9 @@ foreach ($opt_special + $opt_equipment as $k => $v) {
<label for="flt_txt">Text</label> <label for="flt_txt">Text</label>
<input type="text" class="form-control" name="flt_txt" maxlength="30" value="<?=$flt->txt ?? ''?>"> <input type="text" class="form-control" name="flt_txt" maxlength="30" value="<?=$flt->txt ?? ''?>">
</div> </div>
<?php
filter_create_checks('flt_status', _('Status'), $opt_state, $flt->status ?? []);
?>
</div> </div>
<div class="card-footer"> <div class="card-footer">
<button name="submit[filter]" class="btn btn-sm btn-primary" title="<?=_('Apply')?>"><?=_('Go')?></button> <button name="submit[filter]" class="btn btn-sm btn-primary" title="<?=_('Apply')?>"><?=_('Go')?></button>
@@ -139,6 +144,19 @@ if (strlen($flt->txt) > 1) {
$w[] = '(m.activities LIKE :txt OR m.remarks LIKE :txt)'; $w[] = '(m.activities LIKE :txt OR m.remarks LIKE :txt)';
$p[':txt'] = '%'.$flt->txt.'%'; $p[':txt'] = '%'.$flt->txt.'%';
} }
// condition for multiple flags is OR
// $parts = ["maintstate=''", 'maintstate IS NULL'];
$parts = [];
foreach ($flt->status as $s) {
$parts[] = "maintstate='$s'";
}
if (!empty($parts)) {
if (count($parts) > 1) {
$w[] = '(' . join(' OR ', $parts) . ')';
} else {
$w[] = $parts[0];
}
}
$where = join(' AND ', $w); $where = join(' AND ', $w);
$order = ' ORDER BY m.maintid'; $order = ' ORDER BY m.maintid';
@@ -158,8 +176,10 @@ $page = gpc_get_int($_REQUEST, 'p', 1);
$rows_pp = gpc_get_int($_REQUEST, 'n', $user->rows_pp); $rows_pp = gpc_get_int($_REQUEST, 'n', $user->rows_pp);
$lastpage = ceil($numrows/$rows_pp); $lastpage = ceil($numrows/$rows_pp);
$sql = "SELECT m.maintid, m.activities, m.remarks, e.ename " $sql = "SELECT m.maintid, m.activities, m.plan_date, m.interval_hours, m.maintstate, e.ename, "
. " IF(CHAR_LENGTH(m.remarks)>40, CONCAT(LEFT(m.remarks, 40), '\u{2026}'), m.remarks) AS remarks "
. "FROM maintenance AS m LEFT OUTER JOIN equipment AS e USING (eid)"; . "FROM maintenance AS m LEFT OUTER JOIN equipment AS e USING (eid)";
$sql .= ' WHERE ' . $where; $sql .= ' WHERE ' . $where;
$sql .= $order; $sql .= $order;
@@ -180,6 +200,8 @@ echo "<tr>";
echo '<th>#</th>'; echo '<th>#</th>';
echo "<th>", _('Activities'), "</th>"; echo "<th>", _('Activities'), "</th>";
echo "<th>", _('Equipment'), "</th>"; echo "<th>", _('Equipment'), "</th>";
echo "<th>", _('Upcoming'), "</th>"; // Date ou Hours
echo "<th>", _('Status'), "</th>";
echo "<th>", _('Remarks'), "</th>"; echo "<th>", _('Remarks'), "</th>";
echo "</tr>\n"; echo "</tr>\n";
echo "</thead>\n"; echo "</thead>\n";
@@ -192,9 +214,12 @@ foreach ($res as $row) {
echo '<td>', $i; echo '<td>', $i;
echo '<a title="', _('View'), '" href="', $g_scriptname, '?f=view&id=', $row['maintid'], '"><i class="bi-eye ms-2"></i></a>', "\n"; echo '<a title="', _('View'), '" href="', $g_scriptname, '?f=view&id=', $row['maintid'], '"><i class="bi-eye ms-2"></i></a>', "\n";
echo "</td>\n"; echo "</td>\n";
echo "<td>". $row['activities'] ."</td>\n"; echo "<td>", h($row['activities']) ,"</td>\n";
echo "<td>". $row['ename'] ."</td>\n"; echo "<td>", $row['ename'] ,"</td>\n";
echo "<td>". $row['remarks'] ."</td>\n"; // next plan date or hours
echo "<td>", $row['plan_date'], "</td>\n";
echo "<td>", $row['maintstate'], "</td>\n";
echo "<td>", h($row['remarks']) ,"</td>\n";
echo "<td>"; echo "<td>";
// Edit current record button // Edit current record button
echo '<a title="', _('Edit'), '" href="', $g_scriptname, '?f=edit&id=', $row['maintid'], '"><i class="bi-pencil"></i></a>', "\n"; echo '<a title="', _('Edit'), '" href="', $g_scriptname, '?f=edit&id=', $row['maintid'], '"><i class="bi-pencil"></i></a>', "\n";
+11 -7
View File
@@ -203,20 +203,20 @@ elseif ($action == ACT_ADD):
echo '<h2>', _('Add Storage'), "</h2>\n"; echo '<h2>', _('Add Storage'), "</h2>\n";
?> ?>
<form method="post" action="<?=$g_scriptname?>"> <form method="post" action="<?=$g_scriptname?>">
<?php
/*
<div class="mb-3"> <div class="mb-3">
<label for="sname" class="form-label"><?=_('Name')?></label> <label for="sname" class="form-label"><?=_('Name')?></label>
<input type="text" class="form-control" id="sname" name="sname"> <input type="text" class="form-control" id="sname" name="sname">
</div> </div> */
<?php form_create_text('sname', _('Name'), 40);
form_create_select('stype', _('Type'), $opt_stype); form_create_select('stype', _('Type'), $opt_stype);
?> ?>
<button type="submit" name="submit[insert]" class="btn btn-primary"><?=_('Save')?></button> <button type="submit" name="submit[insert]" class="btn btn-primary"><?=_('Save')?></button>
<a href="<?=$g_scriptname?>" class="btn btn-secondary"><?=_('Back')?></a> <a href="<?=$g_scriptname?>" class="btn btn-secondary"><?=_('Back')?></a>
</form> </form>
<?php <?php
elseif ($action == ACT_VIEW): elseif ($action == ACT_VIEW):
@@ -363,15 +363,19 @@ form_create_select('stype', _('Type'), $opt_stype, $storage->stype);
<label for="capacity" class="form-label"><?=_('Capacity')?></label> <label for="capacity" class="form-label"><?=_('Capacity')?></label>
<input type="number" class="form-control" id="capacity" name="capacity" value="<?=$storage->capacity ?>"> <input type="number" class="form-control" id="capacity" name="capacity" value="<?=$storage->capacity ?>">
</div> </div>
<?php form_create_select('capaunit', _('Capacity Unit'), $opt_capaunit, $storage->capaunit); ?> <?php
<div class="mb-3"> form_create_select('capaunit', _('Capacity Unit'), $opt_capaunit, $storage->capaunit);
/* <div class="mb-3">
<label for="color"><?=_('Color')?></label> <label for="color"><?=_('Color')?></label>
<input type="color" class="form-control" id="color" name="color" value="#<?=$storage->color ?>"> <input type="color" class="form-control" id="color" name="color" value="#<?=$storage->color ?>">
</div> </div>
<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($storage->remarks)?></textarea> <textarea class="form-control" id="remarks" name="remarks" rows="3"><?=h($storage->remarks)?></textarea>
</div> </div> */
form_create_color('color', _('Color'), $storage->color);
form_create_textarea('remarks', _('Remarks'), 3, 150, $storage->remarks);
?>
<button type="submit" name="submit[update]" class="btn btn-primary"><?=_('Save')?></button> <button type="submit" name="submit[update]" class="btn btn-primary"><?=_('Save')?></button>
<a href="<?=$g_scriptname?>?f=view&id=<?=$id?>" class="btn btn-secondary"><?=_('Back')?></a> <a href="<?=$g_scriptname?>?f=view&id=<?=$id?>" class="btn btn-secondary"><?=_('Back')?></a>
</form> </form>