mirror of
https://github.com/snipe/snipe-it.git
synced 2025-02-21 03:15:45 -08:00
Added #2893 - track changes on asset edits
This commit is contained in:
parent
1d543f83d4
commit
612f23f6e0
|
@ -54,6 +54,7 @@ class ActionlogsTransformer
|
|||
|
||||
'note' => ($actionlog->note) ? e($actionlog->note): null,
|
||||
'signature_file' => ($actionlog->accept_signature) ? route('log.signature.view', ['filename' => $actionlog->accept_signature ]) : null,
|
||||
'log_meta' => ($actionlog->log_meta) ? json_decode($actionlog->log_meta): null,
|
||||
|
||||
|
||||
];
|
||||
|
|
|
@ -22,22 +22,32 @@ class AssetObserver
|
|||
// (Those other actions already create log entries.)
|
||||
if (($asset->getAttributes()['assigned_to'] == $asset->getOriginal()['assigned_to'])
|
||||
&& ($asset->getAttributes()['next_audit_date'] == $asset->getOriginal()['next_audit_date'])
|
||||
&& ($asset->getAttributes()['last_checkout'] == $asset->getOriginal()['last_checkout'])
|
||||
&& ($asset->getAttributes()['status_id'] == $asset->getOriginal()['status_id']))
|
||||
&& ($asset->getAttributes()['last_checkout'] == $asset->getOriginal()['last_checkout']))
|
||||
{
|
||||
$changed = [];
|
||||
|
||||
foreach ($asset->getOriginal() as $key => $value) {
|
||||
if ($asset->getOriginal()[$key] != $asset->getAttributes()[$key]) {
|
||||
$changed[$key]['old'] = $asset->getOriginal()[$key];
|
||||
$changed[$key]['new'] = $asset->getAttributes()[$key];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$logAction = new Actionlog();
|
||||
$logAction->item_type = Asset::class;
|
||||
$logAction->item_id = $asset->id;
|
||||
$logAction->created_at = date("Y-m-d H:i:s");
|
||||
$logAction->user_id = Auth::id();
|
||||
$logAction->log_meta = json_encode($changed);
|
||||
$logAction->logaction('update');
|
||||
|
||||
} else {
|
||||
|
||||
\Log::debug('Something else happened');
|
||||
\Log::debug($asset->getOriginal()['assigned_to'].' == '.$asset->getAttributes()['assigned_to']);
|
||||
\Log::debug($asset->getOriginal()['next_audit_date'].' == '.$asset->getAttributes()['next_audit_date']);
|
||||
\Log::debug($asset->getOriginal()['last_checkout'].' == '.$asset->getAttributes()['last_checkout']);
|
||||
\Log::debug($asset->getOriginal()['status_id'].' == '.$asset->getAttributes()['status_id']);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
32
database/migrations/2017_12_12_033618_add_actionlog_meta.php
Normal file
32
database/migrations/2017_12_12_033618_add_actionlog_meta.php
Normal file
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class AddActionlogMeta extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('action_logs', function (Blueprint $table) {
|
||||
$table->text('log_meta')->nullable()->default(null);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('action_logs', function (Blueprint $table) {
|
||||
$table->dropColumn('log_meta');
|
||||
});
|
||||
}
|
||||
}
|
|
@ -619,24 +619,28 @@
|
|||
class="table table-striped snipe-table"
|
||||
name="assetHistory"
|
||||
id="table"
|
||||
class="table table-striped snipe-table"
|
||||
data-sort-order="desc"
|
||||
data-height="400"
|
||||
data-show-columns="true"
|
||||
data-cookie-id-table="asset-history"
|
||||
data-url="{{ route('api.activity.index', ['item_id' => $asset->id, 'item_type' => 'asset']) }}">
|
||||
<thead>
|
||||
<tr>
|
||||
<th data-field="icon" style="width: 40px;" class="hidden-xs" data-formatter="iconFormatter"></th>
|
||||
<th class="col-sm-2" data-field="created_at" data-formatter="dateDisplayFormatter">{{ trans('general.date') }}</th>
|
||||
<th class="col-sm-2" data-field="admin" data-formatter="usersLinkObjFormatter">{{ trans('general.admin') }}</th>
|
||||
<th class="col-sm-2" data-field="action_type">{{ trans('general.action') }}</th>
|
||||
<th class="col-sm-1" data-field="admin" data-formatter="usersLinkObjFormatter">{{ trans('general.admin') }}</th>
|
||||
<th class="col-sm-1" data-field="action_type">{{ trans('general.action') }}</th>
|
||||
<th class="col-sm-2" data-field="item" data-formatter="polymorphicItemFormatter">{{ trans('general.item') }}</th>
|
||||
<th class="col-sm-2" data-field="target" data-formatter="polymorphicItemFormatter">{{ trans('general.target') }}</th>
|
||||
<th class="col-sm-2" data-field="note">{{ trans('general.notes') }}</th>
|
||||
@if ($snipeSettings->require_accept_signature=='1')
|
||||
<th class="col-md-3" data-field="signature_file" data-formatter="imageFormatter">{{ trans('general.signature') }}</th>
|
||||
<th class="col-md-3" data-field="signature_file" data-visible="false" data-formatter="imageFormatter">{{ trans('general.signature') }}</th>
|
||||
@endif
|
||||
<th class="col-sm-2" data-field="log_meta" data-visible="false" data-formatter="changeLogFormatter">Changed</th>
|
||||
</tr>
|
||||
</thead>
|
||||
</table>
|
||||
|
||||
</div>
|
||||
</div> <!-- /.row -->
|
||||
</div> <!-- /.tab-pane history -->
|
||||
|
@ -676,7 +680,7 @@
|
|||
<tr>
|
||||
<th class="col-md-4">{{ trans('general.notes') }}</th>
|
||||
<th class="col-md-2"></th>
|
||||
<th class="col-md-4"><span class="line"></span>{{ trans('general.file_name') }}</th>
|
||||
<th class="col-md-4">{{ trans('general.file_name') }}</th>
|
||||
<th class="col-md-2"></th>
|
||||
<th class="col-md-2"></th>
|
||||
</tr>
|
||||
|
|
|
@ -395,6 +395,19 @@
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function changeLogFormatter(value) {
|
||||
var result = '';
|
||||
for (var index in value) {
|
||||
result += index + ': <del>' + value[index].old + '</del> <i class="fa fa-long-arrow-right" aria-hidden="true"></i> ' + value[index].new + '<br>'
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
|
||||
function deployedLocationFormatter(row, value) {
|
||||
if ((row) && (row!=undefined)) {
|
||||
return '<a href="{{ url('/') }}/locations/' + row.id + '"> ' + row.name + '</a>';
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
<th class="col-sm-3" data-field="item" data-formatter="polymorphicItemFormatter">{{ trans('general.item') }}</th>
|
||||
<th class="col-sm-2" data-field="target" data-formatter="polymorphicItemFormatter">To</th>
|
||||
<th class="col-sm-1" data-field="note">{{ trans('general.notes') }}</th>
|
||||
<th class="col-sm-2" data-field="log_meta" data-visible="false" data-formatter="changeLogFormatter">Changed</th>
|
||||
</tr>
|
||||
</thead>
|
||||
</table>
|
||||
|
|
Loading…
Reference in a new issue