Skip to content

Fixed action_date in action_logs #16469

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Jun 6, 2025
6 changes: 6 additions & 0 deletions app/Models/Actionlog.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,13 @@ public static function boot()
} elseif (auth()->user() && auth()->user()->company) {
$actionlog->company_id = auth()->user()->company_id;
}

if ($actionlog->action_date == '') {
$actionlog->action_date = Carbon::now();
}

});

}


Expand Down
3 changes: 0 additions & 3 deletions app/Models/Loggable.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,6 @@ public function logCheckout($note, $target, $action_date = null, $originalValues
$log->note = $note;
$log->action_date = $action_date;

if (! $log->action_date) {
$log->action_date = date('Y-m-d H:i:s');
}

$changed = [];
$array_to_flip = array_keys($fields_array);
Expand Down
172 changes: 172 additions & 0 deletions app/Presenters/HistoryPresenter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
<?php

namespace App\Presenters;

/**
* Class AccessoryPresenter
*/
class HistoryPresenter extends Presenter
{
/**
* Json Column Layout for bootstrap table
* @return string
*/
public static function dataTableLayout($serial = false)
{
$extra = [];
$layout_start = [
[
'id' => 'id',
'searchable' => false,
'sortable' => true,
'switchable' => true,
'title' => trans('general.id'),
'visible' => false,
'class' => 'hidden-xs',
],
[
'field' => 'icon',
'searchable' => false,
'sortable' => true,
'switchable' => true,
'title' => trans('admin/hardware/table.icon'),
'visible' => true,
'class' => 'hidden-xs',
'formatter' => 'iconFormatter',
],
[
'field' => 'created_at',
'searchable' => true,
'sortable' => true,
'switchable' => true,
'title' => trans('general.created_at'),
'visible' => false,
'formatter' => 'dateDisplayFormatter',
],
[
'field' => 'created_by',
'searchable' => false,
'sortable' => true,
'title' => trans('general.created_by'),
'visible' => false,
'formatter' => 'usersLinkObjFormatter',
],
[
'field' => 'action_date',
'searchable' => false,
'sortable' => true,
'title' => trans('general.action_date'),
'visible' => false,
'formatter' => 'dateDisplayFormatter',
],
[
'field' => 'action_type',
'searchable' => true,
'sortable' => true,
'switchable' => true,
'title' => trans('general.action'),
'visible' => false,
],
[
'field' => 'item',
'searchable' => true,
'sortable' => true,
'switchable' => true,
'title' => trans('general.item'),
'visible' => false,
'formatter' => 'polymorphicItemFormatter',
],
];


if ($serial) {
$extra = [
[
'field' => 'item.serial',
'title' => trans('admin/hardware/table.serial'),
'visible' => false,
]
];
}

$layout_end = [
[
'field' => 'target',
'searchable' => true,
'sortable' => true,
'switchable' => true,
'title' => trans('general.target'),
'visible' => false,
'formatter' => 'polymorphicItemFormatter',
],
[
'field' => 'file',
'searchable' => true,
'sortable' => true,
'switchable' => true,
'title' => trans('general.file_name'),
'visible' => false,
'formatter' => 'fileUploadNameFormatter',
],
[
'field' => 'file_download',
'searchable' => true,
'sortable' => true,
'switchable' => true,
'title' => trans('general.download'),
'visible' => false,
'formatter' => 'fileUploadFormatter',
],
[
'field' => 'note',
'searchable' => true,
'sortable' => true,
'visible' => false,
'title' => trans('general.notes'),
'formatter' => 'notesFormatter'
],
[
'field' => 'signature_file',
'searchable' => true,
'sortable' => true,
'switchable' => true,
'title' => trans('general.signature'),
'visible' => false,
'formatter' => 'imageFormatter',
],
[
'field' => 'log_meta',
'searchable' => false,
'sortable' => false,
'visible' => true,
'title' => trans('admin/hardware/table.changed'),
'formatter' => 'changeLogFormatter',
],
[
'field' => 'remote_ip',
'searchable' => false,
'sortable' => false,
'visible' => true,
'title' => trans('admin/settings/general.login_ip'),
],
[
'field' => 'user_agent',
'searchable' => false,
'sortable' => false,
'visible' => true,
'title' => trans('admin/settings/general.login_user_agent'),
],
[
'field' => 'action_source',
'searchable' => false,
'sortable' => false,
'visible' => true,
'title' => trans('general.action_source'),
],
];

$merged = array_merge($layout_start, $extra, $layout_end);
return json_encode($merged);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{

Schema::table('action_logs', function (Blueprint $table) {
$table->index(['action_date']);
});

DB::update('update '.DB::getTablePrefix().'action_logs set action_date = created_at where created_at IS NOT NULL and action_date IS NULL');

}

/**
* Reverse the migrations.
*/
public function down(): void
{

}
};
2 changes: 2 additions & 0 deletions resources/lang/en-US/general.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
'accessory' => 'Accessory',
'accessory_report' => 'Accessory Report',
'action' => 'Action',
'action_date' => 'Action Date',
'activity_report' => 'Activity Report',
'address' => 'Address',
'admin' => 'Admin Settings',
'admin_user' => 'Admin User',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this one is actually used?

'admin_tooltip' => 'This user has admin privileges',
'superuser' => 'Superuser',
'superuser_tooltip' => 'This user has superuser privileges',
Expand Down
19 changes: 2 additions & 17 deletions resources/views/accessories/view.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ class="table table-striped snipe-table"
<div class="row">
<div class="col-md-12">
<table
data-columns="{{ \App\Presenters\HistoryPresenter::dataTableLayout() }}"
class="table table-striped snipe-table"
data-cookie-id-table="AccessoryHistoryTable"
data-id-table="AccessoryHistoryTable"
Expand All @@ -125,23 +126,7 @@ class="table table-striped snipe-table"
"fileName": "export-{{ str_slug($accessory->name) }}-history-{{ date('Y-m-d') }}",
"ignoreColumn": ["actions","image","change","checkbox","checkincheckout","icon"]
}'
data-url="{{ route('api.activity.index', ['item_id' => $accessory->id, 'item_type' => 'accessory']) }}">

<thead>
<tr>
<th class="col-sm-2" data-visible="false" data-sortable="true" data-field="created_at" data-formatter="dateDisplayFormatter">{{ trans('general.record_created') }}</th>
<th class="col-sm-2"data-visible="true" data-sortable="true" data-field="admin" data-formatter="usersLinkObjFormatter">{{ trans('general.created_by') }}</th>
<th class="col-sm-2" data-sortable="true" data-visible="true" data-field="action_type">{{ trans('general.action') }}</th>
<th class="col-sm-2" data-field="file" data-visible="false" data-formatter="fileUploadNameFormatter">{{ trans('general.file_name') }}</th>
<th class="col-sm-2" data-sortable="true" data-visible="true" data-field="item" data-formatter="polymorphicItemFormatter">{{ trans('general.item') }}</th>
<th class="col-sm-2" data-visible="true" data-field="target" data-formatter="polymorphicItemFormatter">{{ trans('general.target') }}</th>
<th class="col-sm-2" data-sortable="true" data-visible="true" data-field="note">{{ trans('general.notes') }}</th>
<th class="col-sm-2" data-visible="true" data-field="action_date" data-formatter="dateDisplayFormatter">{{ trans('general.date') }}</th>
@if ($snipeSettings->require_accept_signature=='1')
<th class="col-md-3" data-field="signature_file" data-visible="false" data-formatter="imageFormatter">{{ trans('general.signature') }}</th>
@endif
</tr>
</thead>
data-url="{{ route('api.activity.index', ['item_id' => $accessory->id, 'item_type' => 'accessory']) }}">
</table>
</div> <!-- /.col-md-12-->
</div> <!-- /.row-->
Expand Down
2 changes: 1 addition & 1 deletion resources/views/blade/filestable.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class="table table-striped snipe-table"
@endif
</td>
<td>
{{ $file->created_at }}
{{ $file->created_at ? Helper::getFormattedDateObject($file->created_at, 'datetime', false) : '' }}
</td>
<td>
{{ ($file->adminuser) ? $file->adminuser->present()->getFullNameAttribute() : '' }}
Expand Down
39 changes: 39 additions & 0 deletions resources/views/components/view.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@
</a>
</li>

<li>
<a href="#history" data-toggle="tab">
<span class="hidden-lg hidden-md">
<i class="fas fa-history fa-2x" aria-hidden="true"></i>
</span>
<span class="hidden-xs hidden-sm">
{{ trans('general.history') }}
</span>
</a>
</li>

@can('components.files', $component)
<li>
Expand Down Expand Up @@ -139,6 +149,35 @@ class="table table-striped snipe-table"
</div>
</div> <!-- close tab-pane div -->

<div class="tab-pane" id="history">
<div class="table-responsive">

<table
data-columns="{{ \App\Presenters\HistoryPresenter::dataTableLayout() }}"
class="table table-striped snipe-table"
id="componentHistory"
data-pagination="true"
data-id-table="componentHistory"
data-search="true"
data-side-pagination="server"
data-show-columns="true"
data-show-fullscreen="true"
data-show-refresh="true"
data-sort-order="desc"
data-sort-name="created_at"
data-show-export="true"
data-export-options='{
"fileName": "export-component-{{ $component->id }}-history",
"ignoreColumn": ["actions","image","change","checkbox","checkincheckout","icon"]
}'

data-url="{{ route('api.activity.index', ['item_id' => $component->id, 'item_type' => 'component']) }}"
data-cookie-id-table="componentHistory"
data-cookie="true">
</table>
</div>
</div><!-- /.tab-pane -->


@can('components.files', $component)
<div class="tab-pane" id="files">
Expand Down
21 changes: 2 additions & 19 deletions resources/views/consumables/view.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@ class="table table-striped snipe-table"
<div class="table-responsive">

<table
data-columns="{{ \App\Presenters\HistoryPresenter::dataTableLayout() }}"
class="table table-striped snipe-table"
id="consumableHistory"
data-pagination="true"
Expand All @@ -469,26 +470,8 @@ class="table table-striped snipe-table"
}'

data-url="{{ route('api.activity.index', ['item_id' => $consumable->id, 'item_type' => 'consumable']) }}"
data-cookie-id-table="assetHistory"
data-cookie-id-table="consumableHistory"
data-cookie="true">
<thead>
<tr>
<th data-visible="true" data-field="icon" style="width: 40px;" class="hidden-xs" data-formatter="iconFormatter">{{ trans('admin/hardware/table.icon') }}</th>
<th data-visible="true" data-field="action_date" data-sortable="true" data-formatter="dateDisplayFormatter">{{ trans('general.date') }}</th>
<th data-visible="true" data-field="admin" data-formatter="usersLinkObjFormatter">{{ trans('general.created_by') }}</th>
<th data-visible="true" data-field="action_type">{{ trans('general.action') }}</th>
<th class="col-sm-2" data-field="file" data-visible="false" data-formatter="fileUploadNameFormatter">{{ trans('general.file_name') }}</th>
<th data-visible="true" data-field="item" data-formatter="polymorphicItemFormatter">{{ trans('general.item') }}</th>
<th data-visible="true" data-field="target" data-formatter="polymorphicItemFormatter">{{ trans('general.target') }}</th>
<th data-field="note">{{ trans('general.notes') }}</th>
<th data-field="signature_file" data-visible="false" data-formatter="imageFormatter">{{ trans('general.signature') }}</th>
<th data-visible="false" data-field="file" data-visible="false" data-formatter="fileUploadFormatter">{{ trans('general.download') }}</th>
<th data-field="log_meta" data-visible="true" data-formatter="changeLogFormatter">{{ trans('admin/hardware/table.changed')}}</th>
<th data-field="remote_ip" data-visible="false" data-sortable="true">{{ trans('admin/settings/general.login_ip') }}</th>
<th data-field="user_agent" data-visible="false" data-sortable="true">{{ trans('admin/settings/general.login_user_agent') }}</th>
<th data-field="action_source" data-visible="false" data-sortable="true">{{ trans('general.action_source') }}</th>
</tr>
</thead>
</table>
</div>
</div><!-- /.tab-pane -->
Expand Down
Loading
Loading