Skip to content

Commit

Permalink
Fix fields editing on devicesRead template.
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-unwin committed Nov 5, 2024
1 parent 6a924d9 commit ccea2e8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
10 changes: 6 additions & 4 deletions app/Models/DevicesModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -917,7 +917,9 @@ public function update($id = null, $data = null): bool
}
$update = $this->updateFieldData('devices', $update_device);
$this->builder->where('id', intval($id));
$this->builder->update($update);
if (count((array)$update_device) > 0) {
$this->builder->update($update_device);
}
if ($this->sqlError($this->db->error())) {
return false;
}
Expand Down Expand Up @@ -988,11 +990,11 @@ public function update($id = null, $data = null): bool
$updated = false;
if (!empty($deviceFields)) {
foreach ($deviceFields as $deviceField) {
if (intval($field->id) === intval($deviceField->fields_id)) {
if (intval($field->id) === intval($deviceField->field_id)) {
$previous_value = (!empty($deviceField->value)) ? $deviceField->value : '';
$update = true;
$updated = true;
$sql = "UPDATE field SET value = ?, `timestamp` = NOW() WHERE id = ?";
$this->db->query($sql, [$deviceField->id, $value]);
$this->db->query($sql, [$value, $deviceField->id]);
$sql = "INSERT INTO edit_log VALUES (null, ?, ?, 'Field data was updated', ?, ?, 'field', ?, NOW(), ?, ?)";
$this->db->query($sql, [$user_id, $id, $source, 1000, $field->name, $value, $previous_value]);
}
Expand Down
6 changes: 3 additions & 3 deletions app/Views/devicesRead.php
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@
}
echo "<div class=\"col-4\">\n";
if ($field->{'type'} == 'varchar') {
echo read_field($field->{'name'}, '', '', $update);
echo read_field($field->{'name'}, $field->{'field.value'}, '', $update);
}

if ($field->{'type'} == 'list') {
Expand All @@ -634,11 +634,11 @@
$item->attributes->name = $value;
$values[] = $item;
}
echo read_select($field->name, '', '', $update, '', $values);
echo read_select($field->name, $field->{'field.value'}, '', $update, '', $values);
}

if ($field->{'type'} == 'date') {
echo read_field($field->{'name'}, '', '', $update, '', '', '', 'date') ;
echo read_field($field->{'name'}, $field->{'field.value'}, '', $update, '', '', '', 'date') ;
}
echo "</div>\n";
}
Expand Down

0 comments on commit ccea2e8

Please sign in to comment.