From ff72c4fbaa510f71846eaf35e4795a3375449aa5 Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 26 Oct 2023 09:17:28 +0100 Subject: [PATCH] Added nicer formatting for fields in log meta Signed-off-by: snipe --- .../Transformers/ActionlogsTransformer.php | 8 +++++ .../views/partials/bootstrap-table.blade.php | 29 ++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/app/Http/Transformers/ActionlogsTransformer.php b/app/Http/Transformers/ActionlogsTransformer.php index d3af3bb753..61ae1af9a2 100644 --- a/app/Http/Transformers/ActionlogsTransformer.php +++ b/app/Http/Transformers/ActionlogsTransformer.php @@ -3,6 +3,7 @@ namespace App\Http\Transformers; use App\Helpers\Helper; use App\Models\Actionlog; +use App\Models\Asset; use App\Models\CustomField; use App\Models\Setting; use App\Models\Company; @@ -12,6 +13,7 @@ use App\Models\AssetModel; use Illuminate\Database\Eloquent\Collection; use Illuminate\Contracts\Encryption\DecryptException; use Illuminate\Support\Facades\Crypt; +use Illuminate\Support\Facades\Gate; class ActionlogsTransformer { @@ -98,6 +100,12 @@ class ActionlogsTransformer \Log::debug('custom fields do not match'); $clean_meta[$fieldname]['old'] = "************"; $clean_meta[$fieldname]['new'] = "************"; + + if (Gate::allows('admin')) { + $clean_meta[$fieldname]['old'] = unserialize($enc_old); + $clean_meta[$fieldname]['new'] = unserialize($enc_new); + } + } diff --git a/resources/views/partials/bootstrap-table.blade.php b/resources/views/partials/bootstrap-table.blade.php index 78f3d152d2..a7c2084adb 100644 --- a/resources/views/partials/bootstrap-table.blade.php +++ b/resources/views/partials/bootstrap-table.blade.php @@ -530,15 +530,42 @@ function changeLogFormatter(value) { + + console.dir(value); var result = ''; + var pretty_index = ''; + + console.error('first the formatter'); + for (var index in value) { - result += index + ': ' + value[index].old + ' ' + value[index].new + '
' + + + // Check if it's a custom field + if (index.startsWith('_snipeit_')) { + console.error('It is a custom field'); + pretty_index = index.replace("_snipeit_", "Custom:_"); + } else { + console.error('Not a custom field'); + pretty_index = index; + } + + extra_pretty_index = prettyLog(pretty_index); + + result += extra_pretty_index + ': ' + value[index].old + ' ' + value[index].new + '
' } return result; } + function prettyLog(str) { + let frags = str.split('_'); + for (let i = 0; i < frags.length; i++) { + frags[i] = frags[i].charAt(0).toUpperCase() + frags[i].slice(1); + } + return frags.join(' '); + } + // Create a linked phone number in the table list function phoneFormatter(value) {