mirror of
https://github.com/snipe/snipe-it.git
synced 2025-01-11 13:57:41 -08:00
Make custom fields into their own JSON array
This commit is contained in:
parent
de5e7bd9ba
commit
9bcfe0748b
|
@ -88,25 +88,25 @@ class AssetsTransformer
|
||||||
$decrypted = \App\Helpers\Helper::gracefulDecrypt($field,$asset->{$field->convertUnicodeDbSlug()});
|
$decrypted = \App\Helpers\Helper::gracefulDecrypt($field,$asset->{$field->convertUnicodeDbSlug()});
|
||||||
$value = (Gate::allows('superadmin')) ? $decrypted : strtoupper(trans('admin/custom_fields/general.encrypted'));
|
$value = (Gate::allows('superadmin')) ? $decrypted : strtoupper(trans('admin/custom_fields/general.encrypted'));
|
||||||
|
|
||||||
$fields_array = [$field->convertUnicodeDbSlug() => $value];
|
// $fields_array = [$field->convertUnicodeDbSlug() => $value];
|
||||||
|
|
||||||
|
|
||||||
// $fields_array[$field->name] = [
|
$fields_array[$field->name] = [
|
||||||
// 'field' => $field->convertUnicodeDbSlug(),
|
'field' => $field->convertUnicodeDbSlug(),
|
||||||
// 'value' => $value
|
'value' => $value
|
||||||
// ];
|
];
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// $fields_array[$field->name] = [
|
$fields_array[$field->name] = [
|
||||||
// 'field' => $field->convertUnicodeDbSlug(),
|
'field' => $field->convertUnicodeDbSlug(),
|
||||||
// 'value' => $asset->{$field->convertUnicodeDbSlug()}
|
'value' => $asset->{$field->convertUnicodeDbSlug()}
|
||||||
// ];
|
];
|
||||||
$fields_array = [$field->convertUnicodeDbSlug() => $asset->{$field->convertUnicodeDbSlug()}];
|
//$fields_array = [$field->convertUnicodeDbSlug() => $asset->{$field->convertUnicodeDbSlug()}];
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
$array += $fields_array;
|
//array += $fields_array;
|
||||||
//$array['custom_fields'] = $fields_array;
|
$array['custom_fields'] = $fields_array;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -178,11 +178,13 @@ class AssetPresenter extends Presenter
|
||||||
|
|
||||||
$fields = CustomField::all();
|
$fields = CustomField::all();
|
||||||
foreach ($fields as $field) {
|
foreach ($fields as $field) {
|
||||||
$layout[] = ["field" => $field->convertUnicodeDbSlug(),
|
$layout[] = [
|
||||||
|
"field" => 'custom_fields.'.$field->convertUnicodeDbSlug(),
|
||||||
"searchable" => true,
|
"searchable" => true,
|
||||||
"sortable" => true,
|
"sortable" => true,
|
||||||
"switchable" => true,
|
"switchable" => true,
|
||||||
"title" => ($field->field_encrypted=='1') ?'<i class="fa fa-lock"></i> '.e($field->name) : e($field->name)
|
"title" => ($field->field_encrypted=='1') ?'<i class="fa fa-lock"></i> '.e($field->name) : e($field->name),
|
||||||
|
"formatter" => "customFieldsFormatter"
|
||||||
];
|
];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -247,8 +247,23 @@ $('.snipe-table').bootstrapTable({
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// This is gross, but necessary so that we can package the API response
|
||||||
|
// for custom fields in a more useful way.
|
||||||
|
function customFieldsFormatter(value, row) {
|
||||||
|
|
||||||
function createdAtFormatter(value, row) {
|
var field_column = this.title;
|
||||||
|
|
||||||
|
// Pull out any HTMl that might be passed via the presenter
|
||||||
|
// (for example, the locked icon for encrypted fields)
|
||||||
|
var field_column_plain = field_column.replace(/<(?:.|\n)*?> ?/gm, '');
|
||||||
|
if (row.custom_fields[field_column_plain]) {
|
||||||
|
return row.custom_fields[field_column_plain].value;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function createdAtFormatter(value) {
|
||||||
if ((value) && (value.date)) {
|
if ((value) && (value.date)) {
|
||||||
return value.date;
|
return value.date;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue