mirror of
https://github.com/snipe/snipe-it.git
synced 2025-02-02 08:21:09 -08:00
Allow date/time formatting selection in settings
This commit is contained in:
parent
161bd7acce
commit
dc38e575d9
|
@ -17,6 +17,7 @@ use App\Models\Component;
|
|||
use App\Models\Accessory;
|
||||
use App\Models\Consumable;
|
||||
use App\Models\Asset;
|
||||
use App\Models\Setting;
|
||||
use Crypt;
|
||||
use Illuminate\Contracts\Encryption\DecryptException;
|
||||
|
||||
|
@ -679,4 +680,31 @@ class Helper
|
|||
return preg_replace('/\s+/u', '_', trim($string));
|
||||
}
|
||||
|
||||
|
||||
public static function getFormattedDateObject($date, $type = 'datetime', $array = true) {
|
||||
|
||||
if ($date=='') {
|
||||
return null;
|
||||
}
|
||||
|
||||
$settings = Setting::getSettings();
|
||||
$tmp_date = new \Carbon($date);
|
||||
|
||||
if ($type == 'datetime') {
|
||||
$dt['datetime'] = $tmp_date->format('Y-m-d H:i:s');
|
||||
$dt['formatted'] = $tmp_date->format($settings->date_display_format .' '. $settings->time_display_format);
|
||||
} else {
|
||||
$dt['date'] = $tmp_date->format('Y-m-d');
|
||||
$dt['formatted'] = $tmp_date->format($settings->date_display_format);
|
||||
}
|
||||
|
||||
if ($array === 'true') {
|
||||
return $dt;
|
||||
}
|
||||
return $dt['formatted'];
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -306,7 +306,6 @@ class SettingsController extends Controller
|
|||
|
||||
if (!config('app.lock_passwords')) {
|
||||
$setting->site_name = e(Input::get('site_name'));
|
||||
|
||||
$setting->custom_css = e(Input::get('custom_css'));
|
||||
|
||||
if (Input::get('two_factor_enabled')=='') {
|
||||
|
@ -341,8 +340,6 @@ class SettingsController extends Controller
|
|||
$setting->email_format = e(Input::get('email_format'));
|
||||
$setting->username_format = e(Input::get('username_format'));
|
||||
$setting->require_accept_signature = e(Input::get('require_accept_signature'));
|
||||
|
||||
|
||||
$setting->labels_per_page = e(Input::get('labels_per_page'));
|
||||
$setting->labels_width = e(Input::get('labels_width'));
|
||||
$setting->labels_height = e(Input::get('labels_height'));
|
||||
|
@ -407,6 +404,9 @@ class SettingsController extends Controller
|
|||
$setting->ldap_tls = e(Input::get('ldap_tls', '0'));
|
||||
$setting->ldap_pw_sync = e(Input::get('ldap_pw_sync', '0'));
|
||||
|
||||
$setting->date_display_format = e(Input::get('date_display_format'));
|
||||
$setting->time_display_format = e(Input::get('time_display_format'));
|
||||
|
||||
|
||||
if ($request->input('clear_logo')=='1') {
|
||||
$setting->logo = null;
|
||||
|
|
|
@ -5,6 +5,8 @@ use App\Models\Asset;
|
|||
use Illuminate\Database\Eloquent\Collection;
|
||||
use App\Http\Transformers\UsersTransformer;
|
||||
use Gate;
|
||||
use App\Helpers\Helper;
|
||||
use App\Models\Setting;
|
||||
|
||||
|
||||
class AssetsTransformer
|
||||
|
@ -22,19 +24,18 @@ class AssetsTransformer
|
|||
|
||||
public function transformAsset (Asset $asset)
|
||||
{
|
||||
$settings = Setting::getSettings();
|
||||
$array = [
|
||||
'id' => $asset->id,
|
||||
'name' => e($asset->name),
|
||||
'asset_tag' => e($asset->asset_tag),
|
||||
'serial' => e($asset->serial),
|
||||
'model' => ($asset->model) ? ['id' => $asset->model->id,'name'=> e($asset->model->name)] : '',
|
||||
'model_number' => e($asset->model_number),
|
||||
'model_number' => ($asset->model_number) ? e($asset->model_number) : null,
|
||||
'status_label' => ($asset->assetstatus) ? ['id' => $asset->assetstatus->id,'name'=> e($asset->assetstatus->name)] : null,
|
||||
'last_checkout' => $asset->last_checkout,
|
||||
'category' => ($asset->model->category) ? ['id' => $asset->model->category->id,'name'=> e($asset->model->category->name)] : null,
|
||||
'manufacturer' => ($asset->model->manufacturer) ? ['id' => $asset->model->manufacturer->id,'name'=> e($asset->model->manufacturer->name)] : null,
|
||||
'notes' => $asset->notes,
|
||||
'expected_checkin' => $asset->expected_checkin,
|
||||
'order_number' => $asset->order_number,
|
||||
'company' => ($asset->company) ? ['id' => $asset->company->id,'name'=> e($asset->company->name)] : null,
|
||||
'location' => ($asset->assetLoc) ? ['id' => $asset->assetLoc->id,'name'=> e($asset->assetLoc->name)] : null,
|
||||
|
@ -43,9 +44,11 @@ class AssetsTransformer
|
|||
'assigned_to' => ($asset->assigneduser) ? ['id' => $asset->assigneduser->id, 'name' => $asset->assigneduser->getFullNameAttribute(), 'first_name'=> e( $asset->assigneduser->first_name), 'last_name'=> e( $asset->assigneduser->last_name)] : null,
|
||||
'warranty' => ($asset->warranty_months > 0) ? e($asset->warranty_months).' '.trans('admin/hardware/form.months') : null,
|
||||
'warranty_expires' => ($asset->warranty_months > 0) ? $asset->present()->warrantee_expires() : null,
|
||||
'created_at' => $asset->created_at->format('Y-m-d H:i:s'),
|
||||
'updated_at' => $asset->updated_at->format('Y-m-d H:i:s'),
|
||||
'purchase_date' => $asset->purchase_date,
|
||||
'created_at' => Helper::getFormattedDateObject($asset->created_at, 'datetime'),
|
||||
'updated_at' => Helper::getFormattedDateObject($asset->updated_at, 'datetime'),
|
||||
'purchase_date' => Helper::getFormattedDateObject($asset->purchase_date, 'date'),
|
||||
'last_checkout' => Helper::getFormattedDateObject($asset->last_checkout, 'datetime'),
|
||||
'expected_checkin' => Helper::getFormattedDateObject($asset->expected_checkin, 'date'),
|
||||
'purchase_cost' => $asset->purchase_cost,
|
||||
'can_checkout' => $asset->availableForCheckout(),
|
||||
|
||||
|
|
|
@ -127,6 +127,7 @@ class AssetPresenter extends Presenter
|
|||
"sortable" => true,
|
||||
"visible" => false,
|
||||
"title" => trans('general.purchase_date'),
|
||||
"formatter" => "dateDisplayFormatter"
|
||||
], [
|
||||
"field" => "purchase_cost",
|
||||
"searchable" => true,
|
||||
|
@ -151,13 +152,29 @@ class AssetPresenter extends Presenter
|
|||
"sortable" => true,
|
||||
"visible" => false,
|
||||
"title" => trans('general.created_at'),
|
||||
"formatter" => "dateDisplayFormatter"
|
||||
], [
|
||||
"field" => "updated_at",
|
||||
"searchable" => false,
|
||||
"sortable" => true,
|
||||
"visible" => false,
|
||||
"title" => trans('general.updated_at')
|
||||
]
|
||||
"title" => trans('general.updated_at'),
|
||||
"formatter" => "dateDisplayFormatter"
|
||||
], [
|
||||
"field" => "last_checkout",
|
||||
"searchable" => false,
|
||||
"sortable" => true,
|
||||
"visible" => false,
|
||||
"title" => trans('admin/hardware/table.checkout_date'),
|
||||
"formatter" => "dateDisplayFormatter"
|
||||
], [
|
||||
"field" => "expected_checkin",
|
||||
"searchable" => false,
|
||||
"sortable" => true,
|
||||
"visible" => false,
|
||||
"title" => trans('admin/hardware/form.expected_checkin'),
|
||||
"formatter" => "dateDisplayFormatter"
|
||||
],
|
||||
];
|
||||
|
||||
$fields = CustomField::all();
|
||||
|
|
|
@ -289,6 +289,7 @@ return [
|
|||
'Google2FA' => PragmaRX\Google2FA\Vendor\Laravel\Facade::class,
|
||||
'Debugbar' => Barryvdh\Debugbar\Facade::class,
|
||||
'Image' => Intervention\Image\ImageManagerStatic::class,
|
||||
'Carbon' => Carbon\Carbon::class,
|
||||
|
||||
|
||||
],
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class AddTimeDateDisplayToSettings extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('settings', function (Blueprint $table) {
|
||||
//
|
||||
$table->string('date_display_format')->default('Y-m-d');
|
||||
$table->string('time_display_format')->default('h:i A');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('settings', function ($table) {
|
||||
$table->dropColumn('date_display_format');
|
||||
$table->dropColumn('time_display_format');
|
||||
});
|
||||
}
|
||||
}
|
|
@ -162,6 +162,7 @@
|
|||
'sure_to_delete' => 'Are you sure you wish to delete',
|
||||
'submit' => 'Submit',
|
||||
'target' => 'Target',
|
||||
'time_and_date_display' => 'Time and Date Display',
|
||||
'total_assets' => 'total assets',
|
||||
'total_licenses' => 'total licenses',
|
||||
'total_accessories' => 'total accessories',
|
||||
|
|
|
@ -341,6 +341,55 @@ Form::macro('countries', function ($name = "country", $selected = null, $class =
|
|||
});
|
||||
|
||||
|
||||
|
||||
Form::macro('date_display_format', function ($name = "date_display_format", $selected = null, $class = null) {
|
||||
|
||||
$formats = [
|
||||
'Y-m-d',
|
||||
'Y-m-d',
|
||||
'D M d, Y',
|
||||
'M j, Y',
|
||||
'd M, Y',
|
||||
'm/d/Y',
|
||||
'n/d/y',
|
||||
'm/j/Y',
|
||||
];
|
||||
|
||||
foreach ($formats as $format) {
|
||||
$date_display_formats[$format] = Carbon::now()->format($format);
|
||||
}
|
||||
$select = '<select name="'.$name.'" class="'.$class.'" style="min-width:250px">';
|
||||
foreach ($date_display_formats as $format => $date_display_format) {
|
||||
$select .= '<option value="'.$format.'"'.($selected == $format ? ' selected="selected"' : '').'>'.$date_display_format.'</option> ';
|
||||
}
|
||||
|
||||
$select .= '</select>';
|
||||
return $select;
|
||||
|
||||
});
|
||||
|
||||
|
||||
Form::macro('time_display_format', function ($name = "time_display_format", $selected = null, $class = null) {
|
||||
|
||||
$formats = [
|
||||
'g:i A',
|
||||
'h:i A',
|
||||
'H:i',
|
||||
];
|
||||
|
||||
foreach ($formats as $format) {
|
||||
$time_display_formats[$format] = Carbon::now()->format($format);
|
||||
}
|
||||
$select = '<select name="'.$name.'" class="'.$class.'" style="min-width:150px">';
|
||||
foreach ($time_display_formats as $format => $time_display_format) {
|
||||
$select .= '<option value="'.$format.'"'.($selected == $format ? ' selected="selected"' : '').'>'.$time_display_format.'</option> ';
|
||||
}
|
||||
|
||||
$select .= '</select>';
|
||||
return $select;
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* Barcode macro
|
||||
* Generates the dropdown menu of available barcodes
|
||||
|
|
|
@ -95,7 +95,6 @@
|
|||
@include ('partials.bootstrap-table', [
|
||||
'exportFile' => 'assets-export',
|
||||
'search' => true,
|
||||
'multiSort' => true,
|
||||
'columns' => \App\Presenters\AssetPresenter::dataTableLayout()
|
||||
])
|
||||
|
||||
|
|
|
@ -75,7 +75,6 @@
|
|||
</span>
|
||||
@endif
|
||||
{{ $asset->present()->statusText() }}
|
||||
|
||||
({{ $asset->assetstatus->getStatuslabelType() }})
|
||||
</td>
|
||||
</tr>
|
||||
|
@ -174,7 +173,7 @@
|
|||
<tr>
|
||||
<td>{{ trans('admin/hardware/form.date') }}</td>
|
||||
<td>
|
||||
{{ date('M d, Y',strtotime($asset->purchase_date)) }}
|
||||
{{ \App\Helpers\Helper::getFormattedDateObject($asset->purchase_date, 'date', false) }}
|
||||
</td>
|
||||
</tr>
|
||||
@endif
|
||||
|
@ -284,7 +283,7 @@
|
|||
<tr>
|
||||
<td>{{ trans('admin/hardware/form.expected_checkin') }}</td>
|
||||
<td>
|
||||
{{ $asset->expected_checkin }}
|
||||
{{ \App\Helpers\Helper::getFormattedDateObject($asset->expected_checkin, 'date', false) }}
|
||||
</td>
|
||||
</tr>
|
||||
@endif
|
||||
|
@ -293,14 +292,6 @@
|
|||
<td>{{ trans('admin/hardware/form.notes') }}</td>
|
||||
<td> {!! nl2br(e($asset->notes)) !!}</td>
|
||||
</tr>
|
||||
@if ($asset->created_at!='')
|
||||
<tr>
|
||||
<td>{{ trans('general.created_at') }}</td>
|
||||
<td>
|
||||
{{ $asset->created_at->format('F j, Y h:iA') }}
|
||||
</td>
|
||||
</tr>
|
||||
@endif
|
||||
|
||||
@if ($asset->assetloc)
|
||||
<tr>
|
||||
|
@ -331,6 +322,24 @@
|
|||
</td>
|
||||
</tr>
|
||||
@endif
|
||||
|
||||
@if ($asset->created_at!='')
|
||||
<tr>
|
||||
<td>{{ trans('general.created_at') }}</td>
|
||||
<td>
|
||||
{{ \App\Helpers\Helper::getFormattedDateObject($asset->created_at, 'datetime', false) }}
|
||||
</td>
|
||||
</tr>
|
||||
@endif
|
||||
|
||||
@if ($asset->updated_at!='')
|
||||
<tr>
|
||||
<td>{{ trans('general.updated_at') }}</td>
|
||||
<td>
|
||||
{{ \App\Helpers\Helper::getFormattedDateObject($asset->updated_at, 'datetime', false) }}
|
||||
</td>
|
||||
</tr>
|
||||
@endif
|
||||
</tbody>
|
||||
</table>
|
||||
</div> <!-- /table-responsive -->
|
||||
|
|
|
@ -203,6 +203,12 @@ $('.snipe-table').bootstrapTable({
|
|||
}
|
||||
}
|
||||
|
||||
function dateDisplayFormatter(value, row) {
|
||||
if (value) {
|
||||
return value.formatted;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function emailFormatter(value, row) {
|
||||
if (value) {
|
||||
|
|
|
@ -83,6 +83,21 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Date format -->
|
||||
<div class="form-group {{ $errors->has('time_display_format') ? 'error' : '' }}">
|
||||
<div class="col-md-3">
|
||||
{{ Form::label('time_display_format', trans('general.time_and_date_display')) }}
|
||||
</div>
|
||||
<div class="col-md-9">
|
||||
{!! Form::date_display_format('date_display_format', Input::old('date_display_format', $setting->date_display_format), 'select2') !!}
|
||||
|
||||
{!! Form::time_display_format('time_display_format', Input::old('time_display_format', $setting->time_display_format), 'select2') !!}
|
||||
|
||||
{!! $errors->first('time_display_format', '<span class="alert-msg">:message</span>') !!}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- Languages -->
|
||||
<div class="form-group {{ $errors->has('site_name') ? 'error' : '' }}">
|
||||
<div class="col-md-3">
|
||||
|
@ -95,6 +110,7 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- Full Multiple Companies Support -->
|
||||
<div class="form-group {{ $errors->has('full_multiple_companies_support') ? 'error' : '' }}">
|
||||
<div class="col-md-3">
|
||||
|
|
Loading…
Reference in a new issue