Another fix for status label types

This is a little janky, as it breaks up the errors into multiple screens if you don't have a status label type AND don't have a name. This is because the model-level validation won't work since we transmogrify that dropdown list of status label types into  boolean values for the DB. Should eventually find a less clunky way to handle this, but needed to get a fix in now.
This commit is contained in:
snipe 2016-06-28 14:52:11 -07:00
parent 6633366b29
commit 6d5bc64b2b
3 changed files with 33 additions and 16 deletions

View file

@ -12,6 +12,7 @@ use Str;
use View;
use App\Helpers\Helper;
use Auth;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\JsonResponse;
@ -90,12 +91,17 @@ class StatuslabelsController extends Controller
*
* @return Redirect
*/
public function postCreate()
public function postCreate(Request $request)
{
// create a new model instance
$statuslabel = new Statuslabel();
$statustype = Statuslabel::getStatuslabelTypesForDB(Input::get('statuslabel_types'));
if (!$request->has('statuslabel_types')) {
return redirect()->back()->withInput()->withErrors(['statuslabel_types' => trans('validation.statuslabel_type')]);
}
$statustype = Statuslabel::getStatuslabelTypesForDB($request->input('statuslabel_types'));
// Save the Statuslabel data
$statuslabel->name = e(Input::get('name'));
@ -116,11 +122,14 @@ class StatuslabelsController extends Controller
}
public function store()
public function store(Request $request)
{
// create a new status label instance
$statuslabel = new Statuslabel();
if (!$request->has('statuslabel_types')) {
return JsonResponse::create(["error" => trans('validation.statuslabel_type')], 500);
}
$statustype = Statuslabel::getStatuslabelTypesForDB(Input::get('statuslabel_types'));
$statuslabel->name = e(Input::get('name'));
$statuslabel->user_id = Auth::user()->id;
@ -135,7 +144,7 @@ class StatuslabelsController extends Controller
// Redirect to the new Statuslabel page
return JsonResponse::create($statuslabel);
}
return JsonResponse::create(["error" => "Failed validation: ".print_r($statuslabel->getErrors()->first(), true)], 500);
return JsonResponse::create(["error" => $statuslabel->getErrors()->first()], 500);
}
@ -168,7 +177,7 @@ class StatuslabelsController extends Controller
* @param int $statuslabelId
* @return Redirect
*/
public function postEdit($statuslabelId = null)
public function postEdit(Request $request, $statuslabelId = null)
{
// Check if the Statuslabel exists
if (is_null($statuslabel = Statuslabel::find($statuslabelId))) {
@ -176,6 +185,10 @@ class StatuslabelsController extends Controller
return redirect()->to('admin/settings/statuslabels')->with('error', trans('admin/statuslabels/message.does_not_exist'));
}
if (!$request->has('statuslabel_types')) {
return redirect()->back()->withInput()->withErrors(['statuslabel_types' => trans('validation.statuslabel_type')]);
}
// Update the Statuslabel data
$statustype = Statuslabel::getStatuslabelTypesForDB(Input::get('statuslabel_types'));

View file

@ -17,8 +17,10 @@ class Statuslabel extends Model
protected $rules = array(
'name' => 'required|string|unique:status_labels,name,NULL,deleted_at',
//'statuslabel_types' => 'required|in:deployable,pending,archived,undeployable',
'notes' => 'string',
'deployable' => 'required',
'pending' => 'required',
'archived' => 'required',
);
protected $fillable = ['name'];
@ -47,14 +49,14 @@ class Statuslabel extends Model
public function getStatuslabelType()
{
if ($this->pending == 1) {
if (($this->pending == '1') && ($this->archived == '0') && ($this->deployable == '0')) {
return 'pending';
} elseif ($this->archived == 1) {
} elseif (($this->pending == '0') && ($this->archived == '1') && ($this->deployable == '0')) {
return 'archived';
} elseif ($this->deployable == 1) {
return 'deployable';
} else {
} elseif (($this->pending == '0') && ($this->archived == '0') && ($this->deployable == '0')) {
return 'undeployable';
} else {
return 'deployable';
}
}
@ -79,6 +81,7 @@ class Statuslabel extends Model
$statustype['pending'] = 0;
$statustype['deployable'] = 0;
$statustype['archived'] = 0;
}
return $statustype;

View file

@ -64,6 +64,7 @@ return array(
),
"unique" => "The :attribute has already been taken.",
"url" => "The :attribute format is invalid.",
"statuslabel_type" => "You must select a valid status label type",
/*