From b1a80f8ed8fae12d5a0ec9ccafbb983beb4e3f58 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 25 Jan 2017 04:34:11 -0800 Subject: [PATCH] Fixes #1684 - Allow editing of custom fields @uberbrady can finally get out of the sea --- .../Controllers/CustomFieldsController.php | 56 +++++++++++++------ app/Models/CustomField.php | 6 +- resources/views/custom_fields/index.blade.php | 4 ++ routes/api.php | 2 +- routes/web/fields.php | 7 ++- 5 files changed, 50 insertions(+), 25 deletions(-) diff --git a/app/Http/Controllers/CustomFieldsController.php b/app/Http/Controllers/CustomFieldsController.php index 4f19e86fc2..4e3d6df397 100644 --- a/app/Http/Controllers/CustomFieldsController.php +++ b/app/Http/Controllers/CustomFieldsController.php @@ -55,7 +55,8 @@ class CustomFieldsController extends Controller */ public function create() { - return View::make("custom_fields.create_field"); + + return View::make("custom_fields.fields.edit")->with('field', new CustomField()); } @@ -85,9 +86,8 @@ class CustomFieldsController extends Controller $field->format = e($request->get("format")); } + $validator = Validator::make(Input::all(), $field->rules); - - $validator=Validator::make(Input::all(), $field->rules); if ($validator->passes()) { $results = $field->save(); if ($results) { @@ -142,32 +142,56 @@ class CustomFieldsController extends Controller /** - * What the actual fuck, Brady? + * Return a view to edit a custom field * - * @todo Uhh, build this? - * @author [Brady Wetherington] [] + * @author [A. Gianotto] [] * @param int $id - * @since [v1.8] - * @return Fuckall + * @since [v4.0] + * @return View */ public function edit($id) { - // + $field = CustomField::find($id); + return View::make("custom_fields.fields.edit")->with('field', $field); } /** - * GET IN THE SEA BRADY. + * Store the updated field * - * @todo Uhh, build this too? - * @author [Brady Wetherington] [] + * @todo Allow encrypting/decrypting if encryption status changes + * + * @author [A. Gianotto] [] * @param int $id - * @since [v1.8] - * @return Fuckall + * @since [v4.0] + * @return Redirect */ - public function update($id) + public function update(Request $request, $id) { - // + $field = CustomField::find($id); + + $field->name = e($request->get("name")); + $field->element = e($request->get("element")); + $field->field_values = e($request->get("field_values")); + $field->field_encrypted = e($request->get("field_encrypted", 0)); + $field->user_id = Auth::user()->id; + + if (!in_array(Input::get('format'), array_keys(CustomField::$PredefinedFormats))) { + $field->format = e($request->get("custom_format")); + } else { + $field->format = e($request->get("format")); + } + + $validator = Validator::make(Input::all(), $field->rules); + + $validator = Validator::make(Input::all(), $field->rules); + + if ($validator->passes()) { + $field->save(); + return redirect()->route("fields.index")->with("success", trans('admin/custom_fields/message.field.update.success')); + } + + return redirect()->back()->withInput()->withErrors($validator); } diff --git a/app/Models/CustomField.php b/app/Models/CustomField.php index 8f7c7dbfce..6dfa86fdef 100644 --- a/app/Models/CustomField.php +++ b/app/Models/CustomField.php @@ -7,10 +7,6 @@ use Schema; class CustomField extends Model { public $guarded=["id"]; - - /** - - */ public static $PredefinedFormats=[ "ANY" => "", "ALPHA" => "alpha", @@ -22,7 +18,7 @@ class CustomField extends Model "IP" => "ip", ]; - public $rules=[ + public $rules = [ "name" => "required|unique:custom_fields" ]; diff --git a/resources/views/custom_fields/index.blade.php b/resources/views/custom_fields/index.blade.php index 055716bbd9..a540cc6f5d 100644 --- a/resources/views/custom_fields/index.blade.php +++ b/resources/views/custom_fields/index.blade.php @@ -103,6 +103,9 @@ {{ Form::open(array('route' => array('fields.destroy', $field->id), 'method' => 'delete')) }} + + + @if($field->fieldset->count()>0) @@ -110,6 +113,7 @@ @endif {{ Form::close() }} + @endforeach diff --git a/routes/api.php b/routes/api.php index 1543126f16..03c4d803b7 100644 --- a/routes/api.php +++ b/routes/api.php @@ -218,7 +218,7 @@ Route::group(['prefix' => 'v1','namespace' => 'Api'], function () { Route::group([ 'prefix' => 'accessories' ], function () { - Route::match(['DELETE'], '{id}', ['uses' => 'AccessoriessController@destroy','as' => 'api.accessories.destroy']); + Route::match(['DELETE'], '{id}', ['uses' => 'AccessoriesController@destroy','as' => 'api.accessories.destroy']); Route::get( '{id}/checkedout', [ 'as' => 'api.accessories.checkedout', 'uses' => 'AccessoriesController@checkedout' ] diff --git a/routes/web/fields.php b/routes/web/fields.php index f4b8565899..e878fe081c 100644 --- a/routes/web/fields.php +++ b/routes/web/fields.php @@ -4,9 +4,6 @@ */ -Route::resource('fields', 'CustomFieldsController', [ -'parameters' => ['field' => 'field_id', 'fieldset' => 'fieldset_id'] -]); Route::group([ 'prefix' => 'fields' ], function () { @@ -24,3 +21,7 @@ Route::group([ 'prefix' => 'fields' ], function () { 'parameters' => ['fieldset' => 'field_id', 'field' => 'field_id'] ]); }); + +Route::resource('fields', 'CustomFieldsController', [ + 'parameters' => ['field' => 'field_id', 'fieldset' => 'fieldset_id'] +]);