mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-24 21:24:13 -08:00
Updated resources, named routes, tests for Locations
This commit is contained in:
parent
3e4be6671e
commit
c308fbce0d
|
@ -33,7 +33,7 @@ class LocationsController extends Controller
|
|||
* @since [v1.0]
|
||||
* @return View
|
||||
*/
|
||||
public function getIndex()
|
||||
public function index()
|
||||
{
|
||||
// Grab all the locations
|
||||
$locations = Location::orderBy('created_at', 'DESC')->with('parent', 'assets', 'assignedassets')->get();
|
||||
|
@ -51,7 +51,7 @@ class LocationsController extends Controller
|
|||
* @since [v1.0]
|
||||
* @return View
|
||||
*/
|
||||
public function getCreate()
|
||||
public function create()
|
||||
{
|
||||
$locations = Location::orderBy('name', 'ASC')->get();
|
||||
|
||||
|
@ -74,14 +74,11 @@ class LocationsController extends Controller
|
|||
* @since [v1.0]
|
||||
* @return Redirect
|
||||
*/
|
||||
public function postCreate()
|
||||
public function store()
|
||||
{
|
||||
|
||||
// create a new location instance
|
||||
$location = new Location();
|
||||
|
||||
|
||||
// Save the location data
|
||||
$location->name = e(Input::get('name'));
|
||||
if (Input::get('parent_id')=='') {
|
||||
$location->parent_id = null;
|
||||
|
@ -98,10 +95,8 @@ class LocationsController extends Controller
|
|||
$location->user_id = Auth::user()->id;
|
||||
|
||||
if ($location->save()) {
|
||||
// Redirect to the new location page
|
||||
return redirect()->to("admin/settings/locations")->with('success', trans('admin/locations/message.create.success'));
|
||||
return redirect()->route("locations.index")->with('success', trans('admin/locations/message.create.success'));
|
||||
}
|
||||
|
||||
return redirect()->back()->withInput()->withErrors($location->getErrors());
|
||||
|
||||
}
|
||||
|
@ -115,7 +110,7 @@ class LocationsController extends Controller
|
|||
* @since [v1.0]
|
||||
* @return String JSON
|
||||
*/
|
||||
public function store()
|
||||
public function apiStore()
|
||||
{
|
||||
|
||||
$new['currency']=Setting::first()->default_currency;
|
||||
|
@ -156,7 +151,7 @@ class LocationsController extends Controller
|
|||
* @since [v1.0]
|
||||
* @return View
|
||||
*/
|
||||
public function getEdit($locationId = null)
|
||||
public function edit($locationId = null)
|
||||
{
|
||||
// Check if the location exists
|
||||
if (is_null($item = Location::find($locationId))) {
|
||||
|
@ -182,7 +177,7 @@ class LocationsController extends Controller
|
|||
* @since [v1.0]
|
||||
* @return Redirect
|
||||
*/
|
||||
public function postEdit($locationId = null)
|
||||
public function update($locationId = null)
|
||||
{
|
||||
// Check if the location exists
|
||||
if (is_null($location = Location::find($locationId))) {
|
||||
|
@ -224,7 +219,7 @@ class LocationsController extends Controller
|
|||
* @since [v1.0]
|
||||
* @return Redirect
|
||||
*/
|
||||
public function getDelete($locationId)
|
||||
public function destroy($locationId)
|
||||
{
|
||||
// Check if the location exists
|
||||
if (is_null($location = Location::find($locationId))) {
|
||||
|
@ -262,7 +257,7 @@ class LocationsController extends Controller
|
|||
* @since [v1.0]
|
||||
* @return View
|
||||
*/
|
||||
public function getView($locationId = null)
|
||||
public function show($locationId = null)
|
||||
{
|
||||
$location = Location::find($locationId);
|
||||
|
||||
|
@ -332,11 +327,11 @@ class LocationsController extends Controller
|
|||
$rows = array();
|
||||
|
||||
foreach ($locations as $location) {
|
||||
$actions = '<nobr><a href="'.route('update/location', $location->id).'" class="btn btn-warning btn-sm" style="margin-right:5px;"><i class="fa fa-pencil icon-white"></i></a><a data-html="false" class="btn delete-asset btn-danger btn-sm" data-toggle="modal" href="'.route('delete/location', $location->id).'" data-content="'.trans('admin/locations/message.delete.confirm').'" data-title="'.trans('general.delete').' '.htmlspecialchars($location->name).'?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a></nobr>';
|
||||
$actions = '<nobr><a href="'.route('locations.edit', ['location' => $location->id]).'" class="btn btn-warning btn-sm" style="margin-right:5px;"><i class="fa fa-pencil icon-white"></i></a><a data-html="false" class="btn delete-asset btn-danger btn-sm" data-toggle="modal" href="'.route('locations.destroy', ['location' => $location->id]).'" data-content="'.trans('admin/locations/message.delete.confirm').'" data-title="'.trans('general.delete').' '.htmlspecialchars($location->name).'?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a></nobr>';
|
||||
|
||||
$rows[] = array(
|
||||
'id' => $location->id,
|
||||
'name' => (string)link_to('admin/settings/locations/'.$location->id.'/view', e($location->name)),
|
||||
'name' => (string)link_to_route('locations.show', e($location->name), ['location' => $location->id]),
|
||||
'parent' => ($location->parent) ? e($location->parent->name) : '',
|
||||
// 'assets' => ($location->assets->count() + $location->assignedassets->count()),
|
||||
'assets_default' => $location->assignedassets->count(),
|
||||
|
|
|
@ -352,7 +352,7 @@
|
|||
</a>
|
||||
</li>
|
||||
<li {!! (Request::is('settings/locations*') ? ' class="active"' : '') !!}>
|
||||
<a href="{{ url('admin/settings/locations') }}">
|
||||
<a href="{{ route('locations.index') }}">
|
||||
<i class="fa fa-globe fa-fw"></i> @lang('general.locations')
|
||||
</a>
|
||||
</li>
|
||||
|
|
|
@ -2,7 +2,8 @@
|
|||
'createText' => trans('admin/locations/table.create') ,
|
||||
'updateText' => trans('admin/locations/table.update'),
|
||||
'helpTitle' => trans('admin/locations/table.about_locations_title'),
|
||||
'helpText' => trans('admin/locations/table.about_locations')
|
||||
'helpText' => trans('admin/locations/table.about_locations'),
|
||||
'formAction' => ($item) ? route('locations.update', ['location' => $item->id]) : route('locations.store'),
|
||||
])
|
||||
|
||||
{{-- Page content --}}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
@stop
|
||||
|
||||
@section('header_right')
|
||||
<a href="{{ route('create/location') }}" class="btn btn-primary pull-right">
|
||||
<a href="{{ route('locations.create') }}" class="btn btn-primary pull-right">
|
||||
{{ trans('general.create') }}</a>
|
||||
@stop
|
||||
{{-- Page content --}}
|
||||
|
|
|
@ -27,6 +27,14 @@ Route::resource('companies', 'CompaniesController', [
|
|||
'parameters' => ['category' => 'category_id']
|
||||
]);
|
||||
|
||||
/*
|
||||
* Locations
|
||||
*/
|
||||
Route::resource('locations', 'LocationsController', [
|
||||
'parameters' => ['location' => 'location_id']
|
||||
]);
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
|
@ -222,23 +230,7 @@ Route::group([ 'prefix' => 'admin','middleware' => ['web','auth']], function ()
|
|||
);
|
||||
});
|
||||
|
||||
# Locations
|
||||
Route::group([ 'prefix' => 'locations' ], function () {
|
||||
|
||||
Route::get('/', [ 'as' => 'locations', 'uses' => 'LocationsController@getIndex' ]);
|
||||
Route::get('create', [ 'as' => 'create/location', 'uses' => 'LocationsController@getCreate' ]);
|
||||
Route::post('create', 'LocationsController@postCreate');
|
||||
Route::get(
|
||||
'{locationId}/edit',
|
||||
[ 'as' => 'update/location', 'uses' => 'LocationsController@getEdit' ]
|
||||
);
|
||||
Route::post('{locationId}/edit', 'LocationsController@postEdit');
|
||||
Route::get('{locationId}/view', [ 'as' => 'view/location', 'uses' => 'LocationsController@getView' ]);
|
||||
Route::get(
|
||||
'{locationId}/delete',
|
||||
[ 'as' => 'delete/location', 'uses' => 'LocationsController@getDelete' ]
|
||||
);
|
||||
});
|
||||
|
||||
# Status Labels
|
||||
Route::group([ 'prefix' => 'statuslabels' ], function () {
|
||||
|
|
|
@ -20,7 +20,7 @@ class LocationsCest
|
|||
/* Create Form */
|
||||
$I->wantTo('Test Location Creation');
|
||||
$I->lookForwardTo('Finding no Failures');
|
||||
$I->amOnPage(route('create/location'));
|
||||
$I->amOnPage(route('locations.create'));
|
||||
$I->dontSee('Create Location', '.page-header');
|
||||
$I->see('Create Location', 'h1.pull-left');
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ class LocationsCest
|
|||
public function failsEmptyValidation(FunctionalTester $I)
|
||||
{
|
||||
$I->wantTo("Test Validation Fails with blank elements");
|
||||
$I->amOnPage(route('create/location'));
|
||||
$I->amOnPage(route('locations.create'));
|
||||
$I->click('Save');
|
||||
$I->seeElement('.alert-danger');
|
||||
$I->see('The name field is required.', '.alert-msg');
|
||||
|
@ -37,7 +37,7 @@ class LocationsCest
|
|||
public function failsShortValidation(FunctionalTester $I)
|
||||
{
|
||||
$I->wantTo("Test Validation Fails with short values");
|
||||
$I->amOnPage(route('create/location'));
|
||||
$I->amOnPage(route('locations.create'));
|
||||
$I->fillField('name', 't');
|
||||
$I->click('Save');
|
||||
$I->seeElement('.alert-danger');
|
||||
|
@ -58,7 +58,7 @@ class LocationsCest
|
|||
'zip' => $location->zip,
|
||||
];
|
||||
$I->wantTo("Test Validation Succeeds");
|
||||
$I->amOnPage(route('create/location'));
|
||||
$I->amOnPage(route('locations.create'));
|
||||
$I->submitForm('form#create-form', $values);
|
||||
$I->seeRecord('locations', $values);
|
||||
$I->seeElement('.alert-success');
|
||||
|
@ -67,7 +67,7 @@ class LocationsCest
|
|||
public function allowsDelete(FunctionalTester $I)
|
||||
{
|
||||
$I->wantTo('Ensure I can delete a location');
|
||||
$I->amOnPage(route('delete/location', Location::doesntHave('assets')->doesntHave('assignedAssets')->first()->id));
|
||||
$I->amOnPage(route('locations.destroy', Location::doesntHave('assets')->doesntHave('assignedAssets')->first()->id));
|
||||
$I->seeElement('.alert-success');
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue