Skip to content

Commit

Permalink
v1.6.0
Browse files Browse the repository at this point in the history
- fix the check between the pivot record and the parent because of incorrect dates “note that the audits_pivot_table has been updated along with the revision relation aggregator”

- combine the relation changes under the same model name instead of rendering them individually
  • Loading branch information
ctf0 committed Sep 5, 2018
1 parent 9c71fca commit ca9f6ac
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 23 deletions.
2 changes: 0 additions & 2 deletions logs/v1.4.2.txt

This file was deleted.

3 changes: 3 additions & 0 deletions logs/v1.6.0.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- fix the check between the pivot record and the parent because of incorrect dates “note that the audits_pivot_table has been updated along with the revision relation aggregator”

- combine the relation changes under the same model name instead of rendering them individually
30 changes: 16 additions & 14 deletions src/Traits/Revisions.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ public static function bootRevisions()
'Attached',
$model->getKey(),
get_class($model->$relationName()->getRelated()),
$pivotIds[0]
$pivotIds[0],
$model->updated_at
);
}
});
Expand All @@ -28,22 +29,22 @@ public static function bootRevisions()
'Detached',
$model->getKey(),
get_class($model->$relationName()->getRelated()),
$pivotIds[0]
$pivotIds[0],
$model->updated_at
);
}
});
}

private function savePivotAudit($eventName, $id, $relation, $pivotId)
private function savePivotAudit($eventName, $id, $relation, $pivotId, $date)
{
return app('db')->table('audits_pivot')->insert([
'event' => $eventName,
'auditable_id' => $id,
'relation_type' => $relation,
'relation_id' => $pivotId,
'auditable_type' => $this->getMorphClass(),
'created_at' => now(),
'updated_at' => now(),
'event' => $eventName,
'auditable_id' => $id,
'relation_type' => $relation,
'relation_id' => $pivotId,
'auditable_type' => $this->getMorphClass(),
'parent_updated_at'=> $date,
]);
}

Expand All @@ -52,7 +53,7 @@ private function getPivotAudits($type, $id, $date)
return app('db')->table('audits_pivot')
->where('auditable_id', $id)
->where('auditable_type', $type)
->where('updated_at', $date)
->where('parent_updated_at', $date)
->get();
}

Expand Down Expand Up @@ -83,12 +84,13 @@ public function getRevisionsAttribute()
public function getRevisionsWithRelationAttribute()
{
return $this->audits->load('user')->map(function ($item) {
$item['odin_relations'] = $this->getPivotAudits($item->auditable_type, $item->auditable_id, $item->updated_at)
->groupBy(['created_at', 'relation_id', 'relation_type'])
$item['odin_relations'] = $this
->getPivotAudits($item->auditable_type, $item->auditable_id, $item->updated_at)
->groupBy(['parent_updated_at', 'relation_id', 'relation_type'])
->flatten(2)
->reject(function ($item) {
return $item->count() == 2;
})->flatten()->reverse();
})->flatten()->reverse()->groupBy(['relation_type']);

return $item;
})->reverse();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function up()
$table->string('event');
$table->morphs('auditable');
$table->morphs('relation');
$table->timestamps();
$table->timestamp('parent_updated_at');
});
}

Expand Down
14 changes: 8 additions & 6 deletions src/resources/views/list.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,16 @@

{{-- relations --}}
@if($rev->odin_relations->count())
@foreach($rev->odin_relations as $item)
<p class="title">{{ class_basename($item->relation_type) }}</p>
@foreach($rev->odin_relations as $key => $val)
<p class="title">{{ class_basename($key) }}</p>
<table class="table is-fullwidth Differences DifferencesSideBySide">
<tbody class="ChangeReplace">
<tr>
<td class="Left">{{ $item->event == 'Detached' ? app($item->relation_type)->find($item->relation_id)->misc_title : '' }}</td>
<td class="Right">{{ $item->event == 'Attached' ? app($item->relation_type)->find($item->relation_id)->misc_title : '' }}</td>
</tr>
@foreach($val as $item)
<tr>
<td class="Left">{{ $item->event == 'Detached' ? app($key)->find($item->relation_id)->misc_title : '' }}</td>
<td class="Right">{{ $item->event == 'Attached' ? app($key)->find($item->relation_id)->misc_title : '' }}</td>
</tr>
@endforeach
</tbody>
</table>
@endforeach
Expand Down

0 comments on commit ca9f6ac

Please sign in to comment.