Merge remote-tracking branch 'origin/develop'

This commit is contained in:
snipe 2022-11-14 22:53:39 +00:00
commit b4ff07ce9e
10 changed files with 127 additions and 57 deletions

View file

@ -86,14 +86,24 @@ class CustomFieldsController extends Controller
{
$this->authorize('create', CustomField::class);
$show_in_email = $request->get("show_in_email", 0);
$display_in_user_view = $request->get("display_in_user_view", 0);
// Override the display settings if the field is encrypted
if ($request->get("field_encrypted") == '1') {
$show_in_email = '0';
$display_in_user_view = '0';
}
$field = new CustomField([
"name" => trim($request->get("name")),
"element" => $request->get("element"),
"help_text" => $request->get("help_text"),
"field_values" => $request->get("field_values"),
"field_encrypted" => $request->get("field_encrypted", 0),
"show_in_email" => $request->get("show_in_email", 0),
"show_in_email" => $show_in_email,
"is_unique" => $request->get("is_unique", 0),
"display_in_user_view" => $display_in_user_view,
"user_id" => Auth::id()
]);
@ -221,13 +231,24 @@ class CustomFieldsController extends Controller
$this->authorize('update', $field);
$show_in_email = $request->get("show_in_email", 0);
$display_in_user_view = $request->get("display_in_user_view", 0);
// Override the display settings if the field is encrypted
if ($request->get("field_encrypted") == '1') {
$show_in_email = '0';
$display_in_user_view = '0';
}
$field->name = trim(e($request->get("name")));
$field->element = e($request->get("element"));
$field->field_values = e($request->get("field_values"));
$field->user_id = Auth::id();
$field->help_text = $request->get("help_text");
$field->show_in_email = $request->get("show_in_email", 0);
$field->show_in_email = $show_in_email;
$field->is_unique = $request->get("is_unique", 0);
$field->display_in_user_view = $display_in_user_view;
if ($request->get('format') == 'CUSTOM REGEX') {
$field->format = e($request->get('custom_format'));

View file

@ -8,6 +8,7 @@ use App\Models\AssetModel;
use App\Models\Company;
use App\Models\Setting;
use App\Models\User;
use App\Models\CustomField;
use App\Notifications\RequestAssetCancelation;
use App\Notifications\RequestAssetNotification;
use Illuminate\Http\Request;
@ -29,23 +30,32 @@ class ViewAssetsController extends Controller
public function getIndex()
{
$user = User::with(
'assets',
'assets.model',
'assets.model.fieldset.fields',
'consumables',
'accessories',
'licenses',
'userloc',
'userlog'
)->withTrashed()->find(Auth::user()->id);
)->find(Auth::user()->id);
$userlog = $user->userlog->load('item', 'user', 'target');
// Loop through all the custom fields that are applied to any model the user has assigned
foreach ($user->assets as $asset) {
foreach ($asset->model->fieldset->fields as $field) {
// check and make sure they're allowed to see the value of the custom field
if ($field->display_in_user_view == '1') {
$field_array[$field->db_column] = $field->name;
}
}
}
// Since some models may re-use the same fieldsets/fields, let's make the array unique so we don't repeat columns
array_unique($field_array);
if (isset($user->id)) {
return view('account/view-assets', compact('user', 'userlog'))
return view('account/view-assets', compact('user', 'field_array' ))
->with('settings', Setting::getSettings());
} else {
// Redirect to the user management page
return redirect()->route('users.index')->with('error', trans('admin/users/message.user_not_found', compact('id')));
}
// Redirect to the user management page
return redirect()->route('users.index')
->with('error', trans('admin/users/message.user_not_found', $user->id));

View file

@ -47,6 +47,7 @@ class CustomFieldsTransformer
'field_values_array' => ($field->field_values) ? explode("\r\n", e($field->field_values)) : null,
'type' => e($field->element),
'required' => (($field->pivot) && ($field->pivot->required=='1')) ? true : false,
'display_in_user_view' => ($field->display_in_user_view =='1') ? true : false,
'created_at' => Helper::getFormattedDateObject($field->created_at, 'datetime'),
'updated_at' => Helper::getFormattedDateObject($field->updated_at, 'datetime'),
];

View file

@ -64,6 +64,7 @@ class CustomField extends Model
'help_text',
'show_in_email',
'is_unique',
'display_in_user_view',
];
/**

View file

@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddDisplayToUserInCustomFields extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('custom_fields', function (Blueprint $table) {
$table->boolean('display_in_user_view')->nullable()->default(0);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('custom_fields', function (Blueprint $table) {
$table->dropColumn('display_in_user_view');
});
}
}

View file

@ -44,4 +44,6 @@ return [
'db_convert_warning' => 'WARNING. This field is in the custom fields table as <code>:db_column</code> but should be <code>:expected</code>.',
'is_unique' => 'This value must be unique across all assets',
'unique' => 'Unique',
'display_in_user_view' => 'Allow the checked out user to view these values in their View Assigned Assets page',
'display_in_user_view_table' => 'Visible to User',
];

View file

@ -129,7 +129,7 @@
<div class="col-md-12" style="padding-top: 5px;">
@if(!empty($user->email))
@if (!empty($user->email))
<form action="{{ route('profile.email_assets') }}" method="POST">
{{ csrf_field() }}
<button style="width: 100%;" class="btn btn-sm btn-primary hidden-print" rel="noopener">{{ trans('admin/users/general.email_assigned') }}</button>
@ -397,13 +397,18 @@
}'>
<thead>
<tr>
<th>#</th>
<th class="col-md-1">#</th>
<th class="col-md-1">{{ trans('general.image') }}</th>
<th class="col-md-2" data-switchable="true" data-visible="true">{{ trans('general.category') }}</th>
<th class="col-md-2" data-switchable="true" data-visible="true">{{ trans('admin/hardware/table.asset_tag') }}</th>
<th class="col-md-2" data-switchable="true" data-visible="true">{{ trans('general.name') }}</th>
<th class="col-md-2" data-switchable="true" data-visible="true">{{ trans('admin/hardware/table.asset_model') }}</th>
<th class="col-md-3" data-switchable="true" data-visible="true">{{ trans('admin/hardware/table.serial') }}</th>
@foreach ($field_array as $db_column => $field_name)
<th class="col-md-1" data-switchable="true" data-visible="true">{{ $field_name }}</th>
@endforeach
</tr>
</thead>
@ -434,37 +439,15 @@
@endif
</td>
<td>{{ $asset->serial }}</td>
</tr>
@if($settings->show_assigned_assets)
@php
$assignedCounter = 1
@endphp
@foreach ($asset->assignedAssets as $asset)
<tr>
<td>{{ $counter }}.{{ $assignedCounter }}</td>
<td>{{ $asset->model->category->name }}</td>
<td>{{ $asset->asset_tag }}</td>
<td>{{ $asset->name }}</td>
<td>
@if ($asset->physical=='1')
{{ $asset->model->name }}
@endif
</td>
<td>{{ $asset->serial }}</td>
<td>
@if (($asset->image) && ($asset->image!=''))
<img src="{{ Storage::disk('public')->url(app('assets_upload_path').e($asset->image)) }}" height="50" width="50">
@elseif (($asset->model) && ($asset->model->image!=''))
<img src="{{ Storage::disk('public')->url(app('models_upload_path').e($asset->model->image)) }}" height="50" width="50">
@endif
</td>
</tr>
@php
$assignedCounter++
@endphp
@foreach ($field_array as $db_column => $field_value)
<td>
{{ $asset->{$db_column} }}
</td>
@endforeach
@endif
</tr>
@php
$counter++
@endphp
@ -551,7 +534,7 @@
<tbody>
@foreach ($user->accessories as $accessory)
<tr>
<td>{!! $accessory->name !!}</td>
<td>{{ $accessory->name }}</td>
<td>
{!! Helper::formatCurrencyOutput($accessory->purchase_cost) !!}
</td>
@ -599,7 +582,7 @@
<tbody>
@foreach ($user->consumables as $consumable)
<tr>
<td>{!! $consumable->name !!}</td>
<td>{{ $consumable->name }}</td>
<td>
{!! Helper::formatCurrencyOutput($consumable->purchase_cost) !!}
</td>

View file

@ -116,6 +116,17 @@
</div>
<!-- Show in View All Assets profile view -->
<div class="form-group {{ $errors->has('display_in_user_view') ? ' has-error' : '' }}" id="display_in_user_view">
<div class="col-md-8 col-md-offset-4">
<label for="display_in_user_view">
<input type="checkbox" name="display_in_user_view" aria-label="display_in_user_view" value="1" class="minimal"{{ (old('display_in_user_view') || $field->display_in_user_view) ? ' checked="checked"' : '' }}>
{{ trans('admin/custom_fields/general.display_in_user_view') }}
</label>
</div>
</div>
<!-- Value Must be Unique -->
<div class="form-group {{ $errors->has('is_unique') ? ' has-error' : '' }}" id="is_unique">
<div class="col-md-8 col-md-offset-4">
@ -206,11 +217,13 @@
$('#field_encrypted').on('ifChecked', function(event){
$("#encrypt_warning").show();
$("#show_in_email").hide();
$("#display_in_user_view").hide();
});
$('#field_encrypted').on('ifUnchecked', function(event){
$("#encrypt_warning").hide();
$("#show_in_email").show();
$("#display_in_user_view").show();
});
</script>

View file

@ -126,16 +126,17 @@
}'>
<thead>
<tr>
<th data-searchable="true">{{ trans('general.name') }}</th>
<th data-searchable="true">{{ trans('admin/custom_fields/general.help_text')}}</th>
<th data-searchable="true">{{ trans('general.email') }}</th>
<th data-searchable="true">{{ trans('admin/custom_fields/general.unique') }}</th>
<th data-visible="false">{{ trans('admin/custom_fields/general.db_field') }}</th>
<th data-searchable="true">{{ trans('admin/custom_fields/general.field_format') }}</th>
<th><i class="fa fa-lock" aria-hidden="true"></i>
<th data-sortable="true" data-searchable="true">{{ trans('general.name') }}</th>
<th data-sortable="true" data-searchable="true">{{ trans('admin/custom_fields/general.help_text')}}</th>
<th data-sortable="true" data-searchable="true">{{ trans('admin/custom_fields/general.unique') }}</th>
<th data-sortable="true" data-visible="false">{{ trans('admin/custom_fields/general.db_field') }}</th>
<th data-sortable="true" data-searchable="true">{{ trans('admin/custom_fields/general.field_format') }}</th>
<th data-sortable="true"><i class="fa fa-lock" aria-hidden="true"></i>
<span class="hidden-xs hidden-sm hidden-md hidden-lg">{{ trans('admin/custom_fields/general.encrypted') }}</span>
</th>
<th data-searchable="true">{{ trans('admin/custom_fields/general.field_element_short') }}</th>
<th data-visible="false" data-sortable="true"><i class="fa fa-eye" aria-hidden="true"><span class="sr-only">Visible to User</span></i></th>
<th data-sortable="true" data-searchable="true"><i class="fa fa-envelope" aria-hidden="true"><span class="sr-only">Show in Email</span></i></th>
<th data-sortable="true" data-searchable="true">{{ trans('admin/custom_fields/general.field_element_short') }}</th>
<th data-searchable="true">{{ trans('admin/custom_fields/general.fieldsets') }}</th>
<th>{{ trans('button.actions') }}</th>
</tr>
@ -145,7 +146,7 @@
<tr>
<td>{{ $field->name }}</td>
<td>{{ $field->help_text }}</td>
<td class='text-center'>{!! ($field->show_in_email=='1') ? '<i class="fas fa-check text-success" aria-hidden="true"><span class="sr-only">'.trans('general.yes').'</span></i>' : '<i class="fas fa-times text-danger" aria-hidden="true"><span class="sr-only">'.trans('general.no').'</span></i>' !!}</td>
<td class='text-center'>{!! ($field->is_unique=='1') ? '<i class="fas fa-check text-success" aria-hidden="true"><span class="sr-only">'.trans('general.yes').'</span></i>' : '<i class="fas fa-times text-danger" aria-hidden="true"><span class="sr-only">'.trans('general.no').'</span></i>' !!}</td>
<td>
<code>{{ $field->convertUnicodeDbSlug() }}</code>
@ -156,6 +157,8 @@
</td>
<td>{{ $field->format }}</td>
<td>{!! ($field->field_encrypted=='1' ? '<i class="fa fa-check text-success"></i>' : '<i class="fa fa-times text-danger"></i>') !!}</td>
<td>{!! ($field->display_in_user_view=='1' ? '<i class="fa fa-check text-success"></i>' : '<i class="fa fa-times text-danger"></i>') !!}</td>
<td class='text-center'>{!! ($field->show_in_email=='1') ? '<i class="fas fa-check text-success" aria-hidden="true"><span class="sr-only">'.trans('general.yes').'</span></i>' : '<i class="fas fa-times text-danger" aria-hidden="true"><span class="sr-only">'.trans('general.no').'</span></i>' !!}</td>
<td>{{ $field->element }}</td>
<td>
@foreach($field->fieldset as $fieldset)

View file

@ -145,17 +145,21 @@
<tr>
<td><i class="{{ Helper::filetype_icon($file->filename) }} icon-med" aria-hidden="true"></i></td>
<td>
@if ( Helper::checkUploadIsImage($file->get_src('assetmodels')))
@if ((Storage::exists('private_uploads/assetmodels/'.$file->filename)) && ( Helper::checkUploadIsImage($file->get_src('assetmodels'))))
<a href="{{ route('show/modelfile', ['modelID' => $model->id, 'fileId' => $file->id]) }}" data-toggle="lightbox" data-type="image" data-title="{{ $file->filename }}">
<img src="{{ route('show/modelfile', ['modelID' => $model->id, 'fileId' =>$file->id]) }}" style="max-width: 50px;">
</a>
@endif
</td>
<td>
{{ $file->filename }}
@if (Storage::exists('private_uploads/assetmodels/'.$file->filename))
{{ $file->filename }}
@else
<del>{{ $file->filename }}</del>
@endif
</td>
<td data-value="{{ Storage::size('private_uploads/assetmodels/'.$file->filename) }}">
{{ Helper::formatFilesizeUnits(Storage::size('private_uploads/assetmodels/'.$file->filename)) }}
<td data-value="{{ (Storage::exists('private_uploads/assetmodels/'.$file->filename)) ? Storage::size('private_uploads/assetmodels/'.$file->filename) : '' }}">
{{ (Storage::exists('private_uploads/assetmodels/'.$file->filename)) ? Helper::formatFilesizeUnits(Storage::size('private_uploads/assetmodels/'.$file->filename)) : '' }}
</td>
<td>
@if ($file->note)
@ -163,7 +167,7 @@
@endif
</td>
<td>
@if ($file->filename)
@if (($file->filename) && (Storage::exists('private_uploads/assetmodels/'.$file->filename)))
<a href="{{ route('show/modelfile', [$model->id, $file->id]) }}" class="btn btn-default">
<i class="fas fa-download" aria-hidden="true"></i>
</a>