Skip to content

Commit

Permalink
feat: now the time line also shows audits from the properties table a…
Browse files Browse the repository at this point in the history
…s well
  • Loading branch information
sriramkanakam87 committed Sep 19, 2024
1 parent e2ecb4f commit b85f9d9
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions app/Livewire/MoleculeHistoryTimeline.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,24 @@ class MoleculeHistoryTimeline extends Component
public function getHistory()
{
$audit_data = [];
foreach ($this->mol->audits as $index => $audit) {
$audits_collection = $this->mol->audits->merge($this->mol->properties()->get()[0]->audits);
foreach ($audits_collection->sortByDesc('created_at') as $index => $audit) {
$audit_data[$index]['user_name'] = $audit->getMetadata()['user_name'];
$audit_data[$index]['event'] = $audit->getMetadata()['audit_event'];
$audit_data[$index]['created_at'] = date('Y/m/d', strtotime($audit->getMetadata()['audit_created_at']));
// foreach ($audit->getModified() as $key => $value) {
// $audit_data[$index]['affected_columns'][$key]['old_value'] = $value['old']??null;
// $audit_data[$index]['affected_columns'][$key]['new_value'] = $value['new']??null;
// }

$old_key = explode('.', array_keys($audit->old_values)[0]??null)[0]??'none';
$new_key = explode('.', array_keys($audit->new_values)[0]??null)[0]??'none';

$old_key = $old_key ?: $new_key;
$new_key = $new_key ?: $old_key;

$audit_data[$index]['affected_columns'][$old_key]['old_value'] = implode(', ', array_values($audit->old_values));
$audit_data[$index]['affected_columns'][$new_key]['new_value'] = implode(', ', array_values($audit->new_values));
if (str_contains('.', array_keys($audit->old_values)[0])) {
$old_key = $audit->old_values ? explode('.', array_keys($audit->old_values)[0])[0] : null;
$new_key = $audit->new_values ? explode('.', array_keys($audit->new_values)[0])[0] : null;

$old_key = $old_key ?: $new_key;
$new_key = $new_key ?: $old_key;
} else {
foreach ($audit->getModified() as $key => $value) {
$audit_data[$index]['affected_columns'][$key]['old_value'] = $value['old'] ?: null;
$audit_data[$index]['affected_columns'][$key]['new_value'] = $value['new'] ?: null;
}
}
}

$initial_audit = [];
Expand All @@ -41,6 +42,7 @@ public function getHistory()

array_push($audit_data, $initial_audit);
$this->audit_data = $audit_data;
// dd($audit_data);
}

public function render()
Expand Down

0 comments on commit b85f9d9

Please sign in to comment.