mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-10 23:54:12 -08:00
922d6937ae
* There is no notes field on accessories. Fixes Importer Test. * Fix notification test. We should see a checkout not allowed exception when trying to check out to a location if the asset requires acceptance. * Fix Custom field import. Add a test for custom field import, and fix a few issues related to importing custom fields. This will restore v3 functionality. * Add UI support for mapping custom fields. This still requires the field mappings to be created/assigned in advance, but will fetch all custom field names and allow them to be selected when setting up custom field mappings. This commit also updates laravel-mix to v1.4.3 and other node dependencies to fix some build issues. * Fix some requestable asset page/assetloc issues. I'd love to know why laravel expections relationships to be in lower case... but thats a question for another day.
72 lines
1.8 KiB
PHP
72 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Transformers\CustomFieldsTransformer;
|
|
use App\Models\CustomField;
|
|
use App\Models\CustomFieldset;
|
|
use Illuminate\Http\Request;
|
|
|
|
class CustomFieldsController extends Controller
|
|
{
|
|
/**
|
|
* Reorder the custom fields within a fieldset
|
|
*
|
|
* @author [Brady Wetherington] [<uberbrady@gmail.com>]
|
|
* @param int $id
|
|
* @since [v3.0]
|
|
* @return Array
|
|
*/
|
|
|
|
public function index()
|
|
{
|
|
$this->authorize('index', CustomFields::class);
|
|
$fields = CustomField::get();
|
|
|
|
$total = count($fields);
|
|
return (new CustomFieldsTransformer)->transformCustomFields($fields, $total);
|
|
}
|
|
public function postReorder(Request $request, $id)
|
|
{
|
|
$fieldset = CustomFieldset::find($id);
|
|
$fields = array();
|
|
$order_array = array();
|
|
|
|
$items = $request->input('item');
|
|
|
|
foreach ($items as $order => $field_id) {
|
|
$order_array[$field_id] = $order;
|
|
}
|
|
|
|
foreach ($fieldset->fields as $field) {
|
|
$fields[$field->id] = ['required' => $field->pivot->required, 'order' => $order_array[$field->id]];
|
|
}
|
|
|
|
return $fieldset->fields()->sync($fields);
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* Delete a custom field.
|
|
*
|
|
* @author [Brady Wetherington] [<uberbrady@gmail.com>]
|
|
* @since [v1.8]
|
|
* @return Redirect
|
|
*/
|
|
public function destroy($field_id)
|
|
{
|
|
$field = CustomField::find($field_id);
|
|
|
|
if ($field->fieldset->count() >0) {
|
|
return response()->json(Helper::formatStandardApiResponse('error', null, 'Field is in use.'));
|
|
} else {
|
|
$field->delete();
|
|
return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/custom_fields/message.field.delete.success')));
|
|
|
|
}
|
|
}
|
|
|
|
}
|